Commit 1a74ef2ff828aca7c377a1cd66f355dd31aee0a3

Authored by isisadmin
2 parents b9c8df01 cc819354

client refactoring

js/deepClient_old.js deleted
1   -/**
2   - * Created by Luigi Serra on 10/06/2015.
3   - */
4   -
5   -var ComponentService =
6   -{
7   - deep_url:"",
8   -
9   - getComponent: function(params){//params = {component, data, fields, placeHolder}
10   - var request = this.getXMLHttpRequest();
11   - var component = params.component;
12   -
13   - request.onreadystatechange = function(){
14   - if(request.readyState == 4){
15   - try {
16   - var resp = JSON.parse(request.response);
17   - var link = '<link rel="import" href="' + resp.bridge_link + resp.component_link +'">';
18   - //Build jsonPath query string
19   - var query = "";
20   - for(var i=0;i < params.fields.length;i++){
21   - var query_elements = params.fields[i].split(',');
22   - query += "$";
23   - for(var j=0; j < query_elements.length - 1;j++){
24   - query += "['" + query_elements[j] + "']";
25   - }
26   - query += "[*]" + "['" + query_elements[query_elements.length - 1] + "']";
27   - query += "###";
28   - }
29   - query = query.substring(0, query.length - 3);
30   -
31   - //Build datalet injecting html code
32   - var datalet_code = link + '<' + params.component;
33   - var keys = Object.keys(params.params);
34   - for(var i = 0; i < keys.length; i++){
35   - datalet_code += ' ' + keys[i] + '="' + params.params[keys[i]] +'"';
36   - }
37   - datalet_code += ' query="' + query + '"></' + params.component + '>';
38   -
39   - (params.placeHolder.constructor == HTMLElement || params.placeHolder.constructor == HTMLDivElement) ? $(params.placeHolder).html(datalet_code) :/*Injection from Web Component*/
40   - $("#" + params.placeHolder).html(datalet_code);/*Injection from a static web page*/
41   -
42   - } catch (e){
43   - var resp = {
44   - status: 'error',
45   - data: 'Unknown error occurred: [' + request.response + ']'
46   - };
47   - }
48   - }};
49   -
50   - request.open('GET', this.deep_url + component);
51   - request.send();
52   - },
53   -
54   - getXMLHttpRequest: function ()
55   - {
56   - if (window.XMLHttpRequest) {
57   - return new XMLHttpRequest();
58   - }
59   - else {
60   - try {
61   - return new ActiveXObject("MSXML2.XMLHTTP.3.0");
62   - }
63   - catch(ex) {
64   - return null;
65   - }
66   - }
67   - }
68   -}
js/webcomponents.js deleted
Changes suppressed. Click to show
1   -/**
2   - * @license
3   - * Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4   - * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5   - * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6   - * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7   - * Code distributed by Google as part of the polymer project is also
8   - * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9   - */
10   -// @version 0.5.5
11   -window.WebComponents = window.WebComponents || {};
12   -
13   -(function(scope) {
14   - var flags = scope.flags || {};
15   - var file = "webcomponents.js";
16   - var script = document.querySelector('script[src*="' + file + '"]');
17   - if (!flags.noOpts) {
18   - location.search.slice(1).split("&").forEach(function(o) {
19   - o = o.split("=");
20   - o[0] && (flags[o[0]] = o[1] || true);
21   - });
22   - if (script) {
23   - for (var i = 0, a; a = script.attributes[i]; i++) {
24   - if (a.name !== "src") {
25   - flags[a.name] = a.value || true;
26   - }
27   - }
28   - }
29   - if (flags.log) {
30   - var parts = flags.log.split(",");
31   - flags.log = {};
32   - parts.forEach(function(f) {
33   - flags.log[f] = true;
34   - });
35   - } else {
36   - flags.log = {};
37   - }
38   - }
39   - flags.shadow = flags.shadow || flags.shadowdom || flags.polyfill;
40   - if (flags.shadow === "native") {
41   - flags.shadow = false;
42   - } else {
43   - flags.shadow = flags.shadow || !HTMLElement.prototype.createShadowRoot;
44   - }
45   - if (flags.register) {
46   - window.CustomElements = window.CustomElements || {
47   - flags: {}
48   - };
49   - window.CustomElements.flags.register = flags.register;
50   - }
51   - scope.flags = flags;
52   -})(WebComponents);
53   -
54   -if (WebComponents.flags.shadow) {
55   - if (typeof WeakMap === "undefined") {
56   - (function() {
57   - var defineProperty = Object.defineProperty;
58   - var counter = Date.now() % 1e9;
59   - var WeakMap = function() {
60   - this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__");
61   - };
62   - WeakMap.prototype = {
63   - set: function(key, value) {
64   - var entry = key[this.name];
65   - if (entry && entry[0] === key) entry[1] = value; else defineProperty(key, this.name, {
66   - value: [ key, value ],
67   - writable: true
68   - });
69   - return this;
70   - },
71   - get: function(key) {
72   - var entry;
73   - return (entry = key[this.name]) && entry[0] === key ? entry[1] : undefined;
74   - },
75   - "delete": function(key) {
76   - var entry = key[this.name];
77   - if (!entry || entry[0] !== key) return false;
78   - entry[0] = entry[1] = undefined;
79   - return true;
80   - },
81   - has: function(key) {
82   - var entry = key[this.name];
83   - if (!entry) return false;
84   - return entry[0] === key;
85   - }
86   - };
87   - window.WeakMap = WeakMap;
88   - })();
89   - }
90   - window.ShadowDOMPolyfill = {};
91   - (function(scope) {
92   - "use strict";
93   - var constructorTable = new WeakMap();
94   - var nativePrototypeTable = new WeakMap();
95   - var wrappers = Object.create(null);
96   - function detectEval() {
97   - if (typeof chrome !== "undefined" && chrome.app && chrome.app.runtime) {
98   - return false;
99   - }
100   - if (navigator.getDeviceStorage) {
101   - return false;
102   - }
103   - try {
104   - var f = new Function("return true;");
105   - return f();
106   - } catch (ex) {
107   - return false;
108   - }
109   - }
110   - var hasEval = detectEval();
111   - function assert(b) {
112   - if (!b) throw new Error("Assertion failed");
113   - }
114   - var defineProperty = Object.defineProperty;
115   - var getOwnPropertyNames = Object.getOwnPropertyNames;
116   - var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
117   - function mixin(to, from) {
118   - var names = getOwnPropertyNames(from);
119   - for (var i = 0; i < names.length; i++) {
120   - var name = names[i];
121   - defineProperty(to, name, getOwnPropertyDescriptor(from, name));
122   - }
123   - return to;
124   - }
125   - function mixinStatics(to, from) {
126   - var names = getOwnPropertyNames(from);
127   - for (var i = 0; i < names.length; i++) {
128   - var name = names[i];
129   - switch (name) {
130   - case "arguments":
131   - case "caller":
132   - case "length":
133   - case "name":
134   - case "prototype":
135   - case "toString":
136   - continue;
137   - }
138   - defineProperty(to, name, getOwnPropertyDescriptor(from, name));
139   - }
140   - return to;
141   - }
142   - function oneOf(object, propertyNames) {
143   - for (var i = 0; i < propertyNames.length; i++) {
144   - if (propertyNames[i] in object) return propertyNames[i];
145   - }
146   - }
147   - var nonEnumerableDataDescriptor = {
148   - value: undefined,
149   - configurable: true,
150   - enumerable: false,
151   - writable: true
152   - };
153   - function defineNonEnumerableDataProperty(object, name, value) {
154   - nonEnumerableDataDescriptor.value = value;
155   - defineProperty(object, name, nonEnumerableDataDescriptor);
156   - }
157   - getOwnPropertyNames(window);
158   - function getWrapperConstructor(node) {
159   - var nativePrototype = node.__proto__ || Object.getPrototypeOf(node);
160   - if (isFirefox) {
161   - try {
162   - getOwnPropertyNames(nativePrototype);
163   - } catch (error) {
164   - nativePrototype = nativePrototype.__proto__;
165   - }
166   - }
167   - var wrapperConstructor = constructorTable.get(nativePrototype);
168   - if (wrapperConstructor) return wrapperConstructor;
169   - var parentWrapperConstructor = getWrapperConstructor(nativePrototype);
170   - var GeneratedWrapper = createWrapperConstructor(parentWrapperConstructor);
171   - registerInternal(nativePrototype, GeneratedWrapper, node);
172   - return GeneratedWrapper;
173   - }
174   - function addForwardingProperties(nativePrototype, wrapperPrototype) {
175   - installProperty(nativePrototype, wrapperPrototype, true);
176   - }
177   - function registerInstanceProperties(wrapperPrototype, instanceObject) {
178   - installProperty(instanceObject, wrapperPrototype, false);
179   - }
180   - var isFirefox = /Firefox/.test(navigator.userAgent);
181   - var dummyDescriptor = {
182   - get: function() {},
183   - set: function(v) {},
184   - configurable: true,
185   - enumerable: true
186   - };
187   - function isEventHandlerName(name) {
188   - return /^on[a-z]+$/.test(name);
189   - }
190   - function isIdentifierName(name) {
191   - return /^\w[a-zA-Z_0-9]*$/.test(name);
192   - }
193   - function getGetter(name) {
194   - return hasEval && isIdentifierName(name) ? new Function("return this.__impl4cf1e782hg__." + name) : function() {
195   - return this.__impl4cf1e782hg__[name];
196   - };
197   - }
198   - function getSetter(name) {
199   - return hasEval && isIdentifierName(name) ? new Function("v", "this.__impl4cf1e782hg__." + name + " = v") : function(v) {
200   - this.__impl4cf1e782hg__[name] = v;
201   - };
202   - }
203   - function getMethod(name) {
204   - return hasEval && isIdentifierName(name) ? new Function("return this.__impl4cf1e782hg__." + name + ".apply(this.__impl4cf1e782hg__, arguments)") : function() {
205   - return this.__impl4cf1e782hg__[name].apply(this.__impl4cf1e782hg__, arguments);
206   - };
207   - }
208   - function getDescriptor(source, name) {
209   - try {
210   - return Object.getOwnPropertyDescriptor(source, name);
211   - } catch (ex) {
212   - return dummyDescriptor;
213   - }
214   - }
215   - var isBrokenSafari = function() {
216   - var descr = Object.getOwnPropertyDescriptor(Node.prototype, "nodeType");
217   - return descr && !descr.get && !descr.set;
218   - }();
219   - function installProperty(source, target, allowMethod, opt_blacklist) {
220   - var names = getOwnPropertyNames(source);
221   - for (var i = 0; i < names.length; i++) {
222   - var name = names[i];
223   - if (name === "polymerBlackList_") continue;
224   - if (name in target) continue;
225   - if (source.polymerBlackList_ && source.polymerBlackList_[name]) continue;
226   - if (isFirefox) {
227   - source.__lookupGetter__(name);
228   - }
229   - var descriptor = getDescriptor(source, name);
230   - var getter, setter;
231   - if (allowMethod && typeof descriptor.value === "function") {
232   - target[name] = getMethod(name);
233   - continue;
234   - }
235   - var isEvent = isEventHandlerName(name);
236   - if (isEvent) getter = scope.getEventHandlerGetter(name); else getter = getGetter(name);
237   - if (descriptor.writable || descriptor.set || isBrokenSafari) {
238   - if (isEvent) setter = scope.getEventHandlerSetter(name); else setter = getSetter(name);
239   - }
240   - var configurable = isBrokenSafari || descriptor.configurable;
241   - defineProperty(target, name, {
242   - get: getter,
243   - set: setter,
244   - configurable: configurable,
245   - enumerable: descriptor.enumerable
246   - });
247   - }
248   - }
249   - function register(nativeConstructor, wrapperConstructor, opt_instance) {
250   - var nativePrototype = nativeConstructor.prototype;
251   - registerInternal(nativePrototype, wrapperConstructor, opt_instance);
252   - mixinStatics(wrapperConstructor, nativeConstructor);
253   - }
254   - function registerInternal(nativePrototype, wrapperConstructor, opt_instance) {
255   - var wrapperPrototype = wrapperConstructor.prototype;
256   - assert(constructorTable.get(nativePrototype) === undefined);
257   - constructorTable.set(nativePrototype, wrapperConstructor);
258   - nativePrototypeTable.set(wrapperPrototype, nativePrototype);
259   - addForwardingProperties(nativePrototype, wrapperPrototype);
260   - if (opt_instance) registerInstanceProperties(wrapperPrototype, opt_instance);
261   - defineNonEnumerableDataProperty(wrapperPrototype, "constructor", wrapperConstructor);
262   - wrapperConstructor.prototype = wrapperPrototype;
263   - }
264   - function isWrapperFor(wrapperConstructor, nativeConstructor) {
265   - return constructorTable.get(nativeConstructor.prototype) === wrapperConstructor;
266   - }
267   - function registerObject(object) {
268   - var nativePrototype = Object.getPrototypeOf(object);
269   - var superWrapperConstructor = getWrapperConstructor(nativePrototype);
270   - var GeneratedWrapper = createWrapperConstructor(superWrapperConstructor);
271   - registerInternal(nativePrototype, GeneratedWrapper, object);
272   - return GeneratedWrapper;
273   - }
274   - function createWrapperConstructor(superWrapperConstructor) {
275   - function GeneratedWrapper(node) {
276   - superWrapperConstructor.call(this, node);
277   - }
278   - var p = Object.create(superWrapperConstructor.prototype);
279   - p.constructor = GeneratedWrapper;
280   - GeneratedWrapper.prototype = p;
281   - return GeneratedWrapper;
282   - }
283   - function isWrapper(object) {
284   - return object && object.__impl4cf1e782hg__;
285   - }
286   - function isNative(object) {
287   - return !isWrapper(object);
288   - }
289   - function wrap(impl) {
290   - if (impl === null) return null;
291   - assert(isNative(impl));
292   - return impl.__wrapper8e3dd93a60__ || (impl.__wrapper8e3dd93a60__ = new (getWrapperConstructor(impl))(impl));
293   - }
294   - function unwrap(wrapper) {
295   - if (wrapper === null) return null;
296   - assert(isWrapper(wrapper));
297   - return wrapper.__impl4cf1e782hg__;
298   - }
299   - function unsafeUnwrap(wrapper) {
300   - return wrapper.__impl4cf1e782hg__;
301   - }
302   - function setWrapper(impl, wrapper) {
303   - wrapper.__impl4cf1e782hg__ = impl;
304   - impl.__wrapper8e3dd93a60__ = wrapper;
305   - }
306   - function unwrapIfNeeded(object) {
307   - return object && isWrapper(object) ? unwrap(object) : object;
308   - }
309   - function wrapIfNeeded(object) {
310   - return object && !isWrapper(object) ? wrap(object) : object;
311   - }
312   - function rewrap(node, wrapper) {
313   - if (wrapper === null) return;
314   - assert(isNative(node));
315   - assert(wrapper === undefined || isWrapper(wrapper));
316   - node.__wrapper8e3dd93a60__ = wrapper;
317   - }
318   - var getterDescriptor = {
319   - get: undefined,
320   - configurable: true,
321   - enumerable: true
322   - };
323   - function defineGetter(constructor, name, getter) {
324   - getterDescriptor.get = getter;
325   - defineProperty(constructor.prototype, name, getterDescriptor);
326   - }
327   - function defineWrapGetter(constructor, name) {
328   - defineGetter(constructor, name, function() {
329   - return wrap(this.__impl4cf1e782hg__[name]);
330   - });
331   - }
332   - function forwardMethodsToWrapper(constructors, names) {
333   - constructors.forEach(function(constructor) {
334   - names.forEach(function(name) {
335   - constructor.prototype[name] = function() {
336   - var w = wrapIfNeeded(this);
337   - return w[name].apply(w, arguments);
338   - };
339   - });
340   - });
341   - }
342   - scope.assert = assert;
343   - scope.constructorTable = constructorTable;
344   - scope.defineGetter = defineGetter;
345   - scope.defineWrapGetter = defineWrapGetter;
346   - scope.forwardMethodsToWrapper = forwardMethodsToWrapper;
347   - scope.isWrapper = isWrapper;
348   - scope.isWrapperFor = isWrapperFor;
349   - scope.mixin = mixin;
350   - scope.nativePrototypeTable = nativePrototypeTable;
351   - scope.oneOf = oneOf;
352   - scope.registerObject = registerObject;
353   - scope.registerWrapper = register;
354   - scope.rewrap = rewrap;
355   - scope.setWrapper = setWrapper;
356   - scope.unsafeUnwrap = unsafeUnwrap;
357   - scope.unwrap = unwrap;
358   - scope.unwrapIfNeeded = unwrapIfNeeded;
359   - scope.wrap = wrap;
360   - scope.wrapIfNeeded = wrapIfNeeded;
361   - scope.wrappers = wrappers;
362   - })(window.ShadowDOMPolyfill);
363   - (function(scope) {
364   - "use strict";
365   - function newSplice(index, removed, addedCount) {
366   - return {
367   - index: index,
368   - removed: removed,
369   - addedCount: addedCount
370   - };
371   - }
372   - var EDIT_LEAVE = 0;
373   - var EDIT_UPDATE = 1;
374   - var EDIT_ADD = 2;
375   - var EDIT_DELETE = 3;
376   - function ArraySplice() {}
377   - ArraySplice.prototype = {
378   - calcEditDistances: function(current, currentStart, currentEnd, old, oldStart, oldEnd) {
379   - var rowCount = oldEnd - oldStart + 1;
380   - var columnCount = currentEnd - currentStart + 1;
381   - var distances = new Array(rowCount);
382   - for (var i = 0; i < rowCount; i++) {
383   - distances[i] = new Array(columnCount);
384   - distances[i][0] = i;
385   - }
386   - for (var j = 0; j < columnCount; j++) distances[0][j] = j;
387   - for (var i = 1; i < rowCount; i++) {
388   - for (var j = 1; j < columnCount; j++) {
389   - if (this.equals(current[currentStart + j - 1], old[oldStart + i - 1])) distances[i][j] = distances[i - 1][j - 1]; else {
390   - var north = distances[i - 1][j] + 1;
391   - var west = distances[i][j - 1] + 1;
392   - distances[i][j] = north < west ? north : west;
393   - }
394   - }
395   - }
396   - return distances;
397   - },
398   - spliceOperationsFromEditDistances: function(distances) {
399   - var i = distances.length - 1;
400   - var j = distances[0].length - 1;
401   - var current = distances[i][j];
402   - var edits = [];
403   - while (i > 0 || j > 0) {
404   - if (i == 0) {
405   - edits.push(EDIT_ADD);
406   - j--;
407   - continue;
408   - }
409   - if (j == 0) {
410   - edits.push(EDIT_DELETE);
411   - i--;
412   - continue;
413   - }
414   - var northWest = distances[i - 1][j - 1];
415   - var west = distances[i - 1][j];
416   - var north = distances[i][j - 1];
417   - var min;
418   - if (west < north) min = west < northWest ? west : northWest; else min = north < northWest ? north : northWest;
419   - if (min == northWest) {
420   - if (northWest == current) {
421   - edits.push(EDIT_LEAVE);
422   - } else {
423   - edits.push(EDIT_UPDATE);
424   - current = northWest;
425   - }
426   - i--;
427   - j--;
428   - } else if (min == west) {
429   - edits.push(EDIT_DELETE);
430   - i--;
431   - current = west;
432   - } else {
433   - edits.push(EDIT_ADD);
434   - j--;
435   - current = north;
436   - }
437   - }
438   - edits.reverse();
439   - return edits;
440   - },
441   - calcSplices: function(current, currentStart, currentEnd, old, oldStart, oldEnd) {
442   - var prefixCount = 0;
443   - var suffixCount = 0;
444   - var minLength = Math.min(currentEnd - currentStart, oldEnd - oldStart);
445   - if (currentStart == 0 && oldStart == 0) prefixCount = this.sharedPrefix(current, old, minLength);
446   - if (currentEnd == current.length && oldEnd == old.length) suffixCount = this.sharedSuffix(current, old, minLength - prefixCount);
447   - currentStart += prefixCount;
448   - oldStart += prefixCount;
449   - currentEnd -= suffixCount;
450   - oldEnd -= suffixCount;
451   - if (currentEnd - currentStart == 0 && oldEnd - oldStart == 0) return [];
452   - if (currentStart == currentEnd) {
453   - var splice = newSplice(currentStart, [], 0);
454   - while (oldStart < oldEnd) splice.removed.push(old[oldStart++]);
455   - return [ splice ];
456   - } else if (oldStart == oldEnd) return [ newSplice(currentStart, [], currentEnd - currentStart) ];
457   - var ops = this.spliceOperationsFromEditDistances(this.calcEditDistances(current, currentStart, currentEnd, old, oldStart, oldEnd));
458   - var splice = undefined;
459   - var splices = [];
460   - var index = currentStart;
461   - var oldIndex = oldStart;
462   - for (var i = 0; i < ops.length; i++) {
463   - switch (ops[i]) {
464   - case EDIT_LEAVE:
465   - if (splice) {
466   - splices.push(splice);
467   - splice = undefined;
468   - }
469   - index++;
470   - oldIndex++;
471   - break;
472   -
473   - case EDIT_UPDATE:
474   - if (!splice) splice = newSplice(index, [], 0);
475   - splice.addedCount++;
476   - index++;
477   - splice.removed.push(old[oldIndex]);
478   - oldIndex++;
479   - break;
480   -
481   - case EDIT_ADD:
482   - if (!splice) splice = newSplice(index, [], 0);
483   - splice.addedCount++;
484   - index++;
485   - break;
486   -
487   - case EDIT_DELETE:
488   - if (!splice) splice = newSplice(index, [], 0);
489   - splice.removed.push(old[oldIndex]);
490   - oldIndex++;
491   - break;
492   - }
493   - }
494   - if (splice) {
495   - splices.push(splice);
496   - }
497   - return splices;
498   - },
499   - sharedPrefix: function(current, old, searchLength) {
500   - for (var i = 0; i < searchLength; i++) if (!this.equals(current[i], old[i])) return i;
501   - return searchLength;
502   - },
503   - sharedSuffix: function(current, old, searchLength) {
504   - var index1 = current.length;
505   - var index2 = old.length;
506   - var count = 0;
507   - while (count < searchLength && this.equals(current[--index1], old[--index2])) count++;
508   - return count;
509   - },
510   - calculateSplices: function(current, previous) {
511   - return this.calcSplices(current, 0, current.length, previous, 0, previous.length);
512   - },
513   - equals: function(currentValue, previousValue) {
514   - return currentValue === previousValue;
515   - }
516   - };
517   - scope.ArraySplice = ArraySplice;
518   - })(window.ShadowDOMPolyfill);
519   - (function(context) {
520   - "use strict";
521   - var OriginalMutationObserver = window.MutationObserver;
522   - var callbacks = [];
523   - var pending = false;
524   - var timerFunc;
525   - function handle() {
526   - pending = false;
527   - var copies = callbacks.slice(0);
528   - callbacks = [];
529   - for (var i = 0; i < copies.length; i++) {
530   - (0, copies[i])();
531   - }
532   - }
533   - if (OriginalMutationObserver) {
534   - var counter = 1;
535   - var observer = new OriginalMutationObserver(handle);
536   - var textNode = document.createTextNode(counter);
537   - observer.observe(textNode, {
538   - characterData: true
539   - });
540   - timerFunc = function() {
541   - counter = (counter + 1) % 2;
542   - textNode.data = counter;
543   - };
544   - } else {
545   - timerFunc = window.setTimeout;
546   - }
547   - function setEndOfMicrotask(func) {
548   - callbacks.push(func);
549   - if (pending) return;
550   - pending = true;
551   - timerFunc(handle, 0);
552   - }
553   - context.setEndOfMicrotask = setEndOfMicrotask;
554   - })(window.ShadowDOMPolyfill);
555   - (function(scope) {
556   - "use strict";
557   - var setEndOfMicrotask = scope.setEndOfMicrotask;
558   - var wrapIfNeeded = scope.wrapIfNeeded;
559   - var wrappers = scope.wrappers;
560   - var registrationsTable = new WeakMap();
561   - var globalMutationObservers = [];
562   - var isScheduled = false;
563   - function scheduleCallback(observer) {
564   - if (observer.scheduled_) return;
565   - observer.scheduled_ = true;
566   - globalMutationObservers.push(observer);
567   - if (isScheduled) return;
568   - setEndOfMicrotask(notifyObservers);
569   - isScheduled = true;
570   - }
571   - function notifyObservers() {
572   - isScheduled = false;
573   - while (globalMutationObservers.length) {
574   - var notifyList = globalMutationObservers;
575   - globalMutationObservers = [];
576   - notifyList.sort(function(x, y) {
577   - return x.uid_ - y.uid_;
578   - });
579   - for (var i = 0; i < notifyList.length; i++) {
580   - var mo = notifyList[i];
581   - mo.scheduled_ = false;
582   - var queue = mo.takeRecords();
583   - removeTransientObserversFor(mo);
584   - if (queue.length) {
585   - mo.callback_(queue, mo);
586   - }
587   - }
588   - }
589   - }
590   - function MutationRecord(type, target) {
591   - this.type = type;
592   - this.target = target;
593   - this.addedNodes = new wrappers.NodeList();
594   - this.removedNodes = new wrappers.NodeList();
595   - this.previousSibling = null;
596   - this.nextSibling = null;
597   - this.attributeName = null;
598   - this.attributeNamespace = null;
599   - this.oldValue = null;
600   - }
601   - function registerTransientObservers(ancestor, node) {
602   - for (;ancestor; ancestor = ancestor.parentNode) {
603   - var registrations = registrationsTable.get(ancestor);
604   - if (!registrations) continue;
605   - for (var i = 0; i < registrations.length; i++) {
606   - var registration = registrations[i];
607   - if (registration.options.subtree) registration.addTransientObserver(node);
608   - }
609   - }
610   - }
611   - function removeTransientObserversFor(observer) {
612   - for (var i = 0; i < observer.nodes_.length; i++) {
613   - var node = observer.nodes_[i];
614   - var registrations = registrationsTable.get(node);
615   - if (!registrations) return;
616   - for (var j = 0; j < registrations.length; j++) {
617   - var registration = registrations[j];
618   - if (registration.observer === observer) registration.removeTransientObservers();
619   - }
620   - }
621   - }
622   - function enqueueMutation(target, type, data) {
623   - var interestedObservers = Object.create(null);
624   - var associatedStrings = Object.create(null);
625   - for (var node = target; node; node = node.parentNode) {
626   - var registrations = registrationsTable.get(node);
627   - if (!registrations) continue;
628   - for (var j = 0; j < registrations.length; j++) {
629   - var registration = registrations[j];
630   - var options = registration.options;
631   - if (node !== target && !options.subtree) continue;
632   - if (type === "attributes" && !options.attributes) continue;
633   - if (type === "attributes" && options.attributeFilter && (data.namespace !== null || options.attributeFilter.indexOf(data.name) === -1)) {
634   - continue;
635   - }
636   - if (type === "characterData" && !options.characterData) continue;
637   - if (type === "childList" && !options.childList) continue;
638   - var observer = registration.observer;
639   - interestedObservers[observer.uid_] = observer;
640   - if (type === "attributes" && options.attributeOldValue || type === "characterData" && options.characterDataOldValue) {
641   - associatedStrings[observer.uid_] = data.oldValue;
642   - }
643   - }
644   - }
645   - for (var uid in interestedObservers) {
646   - var observer = interestedObservers[uid];
647   - var record = new MutationRecord(type, target);
648   - if ("name" in data && "namespace" in data) {
649   - record.attributeName = data.name;
650   - record.attributeNamespace = data.namespace;
651   - }
652   - if (data.addedNodes) record.addedNodes = data.addedNodes;
653   - if (data.removedNodes) record.removedNodes = data.removedNodes;
654   - if (data.previousSibling) record.previousSibling = data.previousSibling;
655   - if (data.nextSibling) record.nextSibling = data.nextSibling;
656   - if (associatedStrings[uid] !== undefined) record.oldValue = associatedStrings[uid];
657   - scheduleCallback(observer);
658   - observer.records_.push(record);
659   - }
660   - }
661   - var slice = Array.prototype.slice;
662   - function MutationObserverOptions(options) {
663   - this.childList = !!options.childList;
664   - this.subtree = !!options.subtree;
665   - if (!("attributes" in options) && ("attributeOldValue" in options || "attributeFilter" in options)) {
666   - this.attributes = true;
667   - } else {
668   - this.attributes = !!options.attributes;
669   - }
670   - if ("characterDataOldValue" in options && !("characterData" in options)) this.characterData = true; else this.characterData = !!options.characterData;
671   - if (!this.attributes && (options.attributeOldValue || "attributeFilter" in options) || !this.characterData && options.characterDataOldValue) {
672   - throw new TypeError();
673   - }
674   - this.characterData = !!options.characterData;
675   - this.attributeOldValue = !!options.attributeOldValue;
676   - this.characterDataOldValue = !!options.characterDataOldValue;
677   - if ("attributeFilter" in options) {
678   - if (options.attributeFilter == null || typeof options.attributeFilter !== "object") {
679   - throw new TypeError();
680   - }
681   - this.attributeFilter = slice.call(options.attributeFilter);
682   - } else {
683   - this.attributeFilter = null;
684   - }
685   - }
686   - var uidCounter = 0;
687   - function MutationObserver(callback) {
688   - this.callback_ = callback;
689   - this.nodes_ = [];
690   - this.records_ = [];
691   - this.uid_ = ++uidCounter;
692   - this.scheduled_ = false;
693   - }
694   - MutationObserver.prototype = {
695   - constructor: MutationObserver,
696   - observe: function(target, options) {
697   - target = wrapIfNeeded(target);
698   - var newOptions = new MutationObserverOptions(options);
699   - var registration;
700   - var registrations = registrationsTable.get(target);
701   - if (!registrations) registrationsTable.set(target, registrations = []);
702   - for (var i = 0; i < registrations.length; i++) {
703   - if (registrations[i].observer === this) {
704   - registration = registrations[i];
705   - registration.removeTransientObservers();
706   - registration.options = newOptions;
707   - }
708   - }
709   - if (!registration) {
710   - registration = new Registration(this, target, newOptions);
711   - registrations.push(registration);
712   - this.nodes_.push(target);
713   - }
714   - },
715   - disconnect: function() {
716   - this.nodes_.forEach(function(node) {
717   - var registrations = registrationsTable.get(node);
718   - for (var i = 0; i < registrations.length; i++) {
719   - var registration = registrations[i];
720   - if (registration.observer === this) {
721   - registrations.splice(i, 1);
722   - break;
723   - }
724   - }
725   - }, this);
726   - this.records_ = [];
727   - },
728   - takeRecords: function() {
729   - var copyOfRecords = this.records_;
730   - this.records_ = [];
731   - return copyOfRecords;
732   - }
733   - };
734   - function Registration(observer, target, options) {
735   - this.observer = observer;
736   - this.target = target;
737   - this.options = options;
738   - this.transientObservedNodes = [];
739   - }
740   - Registration.prototype = {
741   - addTransientObserver: function(node) {
742   - if (node === this.target) return;
743   - scheduleCallback(this.observer);
744   - this.transientObservedNodes.push(node);
745   - var registrations = registrationsTable.get(node);
746   - if (!registrations) registrationsTable.set(node, registrations = []);
747   - registrations.push(this);
748   - },
749   - removeTransientObservers: function() {
750   - var transientObservedNodes = this.transientObservedNodes;
751   - this.transientObservedNodes = [];
752   - for (var i = 0; i < transientObservedNodes.length; i++) {
753   - var node = transientObservedNodes[i];
754   - var registrations = registrationsTable.get(node);
755   - for (var j = 0; j < registrations.length; j++) {
756   - if (registrations[j] === this) {
757   - registrations.splice(j, 1);
758   - break;
759   - }
760   - }
761   - }
762   - }
763   - };
764   - scope.enqueueMutation = enqueueMutation;
765   - scope.registerTransientObservers = registerTransientObservers;
766   - scope.wrappers.MutationObserver = MutationObserver;
767   - scope.wrappers.MutationRecord = MutationRecord;
768   - })(window.ShadowDOMPolyfill);
769   - (function(scope) {
770   - "use strict";
771   - function TreeScope(root, parent) {
772   - this.root = root;
773   - this.parent = parent;
774   - }
775   - TreeScope.prototype = {
776   - get renderer() {
777   - if (this.root instanceof scope.wrappers.ShadowRoot) {
778   - return scope.getRendererForHost(this.root.host);
779   - }
780   - return null;
781   - },
782   - contains: function(treeScope) {
783   - for (;treeScope; treeScope = treeScope.parent) {
784   - if (treeScope === this) return true;
785   - }
786   - return false;
787   - }
788   - };
789   - function setTreeScope(node, treeScope) {
790   - if (node.treeScope_ !== treeScope) {
791   - node.treeScope_ = treeScope;
792   - for (var sr = node.shadowRoot; sr; sr = sr.olderShadowRoot) {
793   - sr.treeScope_.parent = treeScope;
794   - }
795   - for (var child = node.firstChild; child; child = child.nextSibling) {
796   - setTreeScope(child, treeScope);
797   - }
798   - }
799   - }
800   - function getTreeScope(node) {
801   - if (node instanceof scope.wrappers.Window) {
802   - debugger;
803   - }
804   - if (node.treeScope_) return node.treeScope_;
805   - var parent = node.parentNode;
806   - var treeScope;
807   - if (parent) treeScope = getTreeScope(parent); else treeScope = new TreeScope(node, null);
808   - return node.treeScope_ = treeScope;
809   - }
810   - scope.TreeScope = TreeScope;
811   - scope.getTreeScope = getTreeScope;
812   - scope.setTreeScope = setTreeScope;
813   - })(window.ShadowDOMPolyfill);
814   - (function(scope) {
815   - "use strict";
816   - var forwardMethodsToWrapper = scope.forwardMethodsToWrapper;
817   - var getTreeScope = scope.getTreeScope;
818   - var mixin = scope.mixin;
819   - var registerWrapper = scope.registerWrapper;
820   - var setWrapper = scope.setWrapper;
821   - var unsafeUnwrap = scope.unsafeUnwrap;
822   - var unwrap = scope.unwrap;
823   - var wrap = scope.wrap;
824   - var wrappers = scope.wrappers;
825   - var wrappedFuns = new WeakMap();
826   - var listenersTable = new WeakMap();
827   - var handledEventsTable = new WeakMap();
828   - var currentlyDispatchingEvents = new WeakMap();
829   - var targetTable = new WeakMap();
830   - var currentTargetTable = new WeakMap();
831   - var relatedTargetTable = new WeakMap();
832   - var eventPhaseTable = new WeakMap();
833   - var stopPropagationTable = new WeakMap();
834   - var stopImmediatePropagationTable = new WeakMap();
835   - var eventHandlersTable = new WeakMap();
836   - var eventPathTable = new WeakMap();
837   - function isShadowRoot(node) {
838   - return node instanceof wrappers.ShadowRoot;
839   - }
840   - function rootOfNode(node) {
841   - return getTreeScope(node).root;
842   - }
843   - function getEventPath(node, event) {
844   - var path = [];
845   - var current = node;
846   - path.push(current);
847   - while (current) {
848   - var destinationInsertionPoints = getDestinationInsertionPoints(current);
849   - if (destinationInsertionPoints && destinationInsertionPoints.length > 0) {
850   - for (var i = 0; i < destinationInsertionPoints.length; i++) {
851   - var insertionPoint = destinationInsertionPoints[i];
852   - if (isShadowInsertionPoint(insertionPoint)) {
853   - var shadowRoot = rootOfNode(insertionPoint);
854   - var olderShadowRoot = shadowRoot.olderShadowRoot;
855   - if (olderShadowRoot) path.push(olderShadowRoot);
856   - }
857   - path.push(insertionPoint);
858   - }
859   - current = destinationInsertionPoints[destinationInsertionPoints.length - 1];
860   - } else {
861   - if (isShadowRoot(current)) {
862   - if (inSameTree(node, current) && eventMustBeStopped(event)) {
863   - break;
864   - }
865   - current = current.host;
866   - path.push(current);
867   - } else {
868   - current = current.parentNode;
869   - if (current) path.push(current);
870   - }
871   - }
872   - }
873   - return path;
874   - }
875   - function eventMustBeStopped(event) {
876   - if (!event) return false;
877   - switch (event.type) {
878   - case "abort":
879   - case "error":
880   - case "select":
881   - case "change":
882   - case "load":
883   - case "reset":
884   - case "resize":
885   - case "scroll":
886   - case "selectstart":
887   - return true;
888   - }
889   - return false;
890   - }
891   - function isShadowInsertionPoint(node) {
892   - return node instanceof HTMLShadowElement;
893   - }
894   - function getDestinationInsertionPoints(node) {
895   - return scope.getDestinationInsertionPoints(node);
896   - }
897   - function eventRetargetting(path, currentTarget) {
898   - if (path.length === 0) return currentTarget;
899   - if (currentTarget instanceof wrappers.Window) currentTarget = currentTarget.document;
900   - var currentTargetTree = getTreeScope(currentTarget);
901   - var originalTarget = path[0];
902   - var originalTargetTree = getTreeScope(originalTarget);
903   - var relativeTargetTree = lowestCommonInclusiveAncestor(currentTargetTree, originalTargetTree);
904   - for (var i = 0; i < path.length; i++) {
905   - var node = path[i];
906   - if (getTreeScope(node) === relativeTargetTree) return node;
907   - }
908   - return path[path.length - 1];
909   - }
910   - function getTreeScopeAncestors(treeScope) {
911   - var ancestors = [];
912   - for (;treeScope; treeScope = treeScope.parent) {
913   - ancestors.push(treeScope);
914   - }
915   - return ancestors;
916   - }
917   - function lowestCommonInclusiveAncestor(tsA, tsB) {
918   - var ancestorsA = getTreeScopeAncestors(tsA);
919   - var ancestorsB = getTreeScopeAncestors(tsB);
920   - var result = null;
921   - while (ancestorsA.length > 0 && ancestorsB.length > 0) {
922   - var a = ancestorsA.pop();
923   - var b = ancestorsB.pop();
924   - if (a === b) result = a; else break;
925   - }
926   - return result;
927   - }
928   - function getTreeScopeRoot(ts) {
929   - if (!ts.parent) return ts;
930   - return getTreeScopeRoot(ts.parent);
931   - }
932   - function relatedTargetResolution(event, currentTarget, relatedTarget) {
933   - if (currentTarget instanceof wrappers.Window) currentTarget = currentTarget.document;
934   - var currentTargetTree = getTreeScope(currentTarget);
935   - var relatedTargetTree = getTreeScope(relatedTarget);
936   - var relatedTargetEventPath = getEventPath(relatedTarget, event);
937   - var lowestCommonAncestorTree;
938   - var lowestCommonAncestorTree = lowestCommonInclusiveAncestor(currentTargetTree, relatedTargetTree);
939   - if (!lowestCommonAncestorTree) lowestCommonAncestorTree = relatedTargetTree.root;
940   - for (var commonAncestorTree = lowestCommonAncestorTree; commonAncestorTree; commonAncestorTree = commonAncestorTree.parent) {
941   - var adjustedRelatedTarget;
942   - for (var i = 0; i < relatedTargetEventPath.length; i++) {
943   - var node = relatedTargetEventPath[i];
944   - if (getTreeScope(node) === commonAncestorTree) return node;
945   - }
946   - }
947   - return null;
948   - }
949   - function inSameTree(a, b) {
950   - return getTreeScope(a) === getTreeScope(b);
951   - }
952   - var NONE = 0;
953   - var CAPTURING_PHASE = 1;
954   - var AT_TARGET = 2;
955   - var BUBBLING_PHASE = 3;
956   - var pendingError;
957   - function dispatchOriginalEvent(originalEvent) {
958   - if (handledEventsTable.get(originalEvent)) return;
959   - handledEventsTable.set(originalEvent, true);
960   - dispatchEvent(wrap(originalEvent), wrap(originalEvent.target));
961   - if (pendingError) {
962   - var err = pendingError;
963   - pendingError = null;
964   - throw err;
965   - }
966   - }
967   - function isLoadLikeEvent(event) {
968   - switch (event.type) {
969   - case "load":
970   - case "beforeunload":
971   - case "unload":
972   - return true;
973   - }
974   - return false;
975   - }
976   - function dispatchEvent(event, originalWrapperTarget) {
977   - if (currentlyDispatchingEvents.get(event)) throw new Error("InvalidStateError");
978   - currentlyDispatchingEvents.set(event, true);
979   - scope.renderAllPending();
980   - var eventPath;
981   - var overrideTarget;
982   - var win;
983   - if (isLoadLikeEvent(event) && !event.bubbles) {
984   - var doc = originalWrapperTarget;
985   - if (doc instanceof wrappers.Document && (win = doc.defaultView)) {
986   - overrideTarget = doc;
987   - eventPath = [];
988   - }
989   - }
990   - if (!eventPath) {
991   - if (originalWrapperTarget instanceof wrappers.Window) {
992   - win = originalWrapperTarget;
993   - eventPath = [];
994   - } else {
995   - eventPath = getEventPath(originalWrapperTarget, event);
996   - if (!isLoadLikeEvent(event)) {
997   - var doc = eventPath[eventPath.length - 1];
998   - if (doc instanceof wrappers.Document) win = doc.defaultView;
999   - }
1000   - }
1001   - }
1002   - eventPathTable.set(event, eventPath);
1003   - if (dispatchCapturing(event, eventPath, win, overrideTarget)) {
1004   - if (dispatchAtTarget(event, eventPath, win, overrideTarget)) {
1005   - dispatchBubbling(event, eventPath, win, overrideTarget);
1006   - }
1007   - }
1008   - eventPhaseTable.set(event, NONE);
1009   - currentTargetTable.delete(event, null);
1010   - currentlyDispatchingEvents.delete(event);
1011   - return event.defaultPrevented;
1012   - }
1013   - function dispatchCapturing(event, eventPath, win, overrideTarget) {
1014   - var phase = CAPTURING_PHASE;
1015   - if (win) {
1016   - if (!invoke(win, event, phase, eventPath, overrideTarget)) return false;
1017   - }
1018   - for (var i = eventPath.length - 1; i > 0; i--) {
1019   - if (!invoke(eventPath[i], event, phase, eventPath, overrideTarget)) return false;
1020   - }
1021   - return true;
1022   - }
1023   - function dispatchAtTarget(event, eventPath, win, overrideTarget) {
1024   - var phase = AT_TARGET;
1025   - var currentTarget = eventPath[0] || win;
1026   - return invoke(currentTarget, event, phase, eventPath, overrideTarget);
1027   - }
1028   - function dispatchBubbling(event, eventPath, win, overrideTarget) {
1029   - var phase = BUBBLING_PHASE;
1030   - for (var i = 1; i < eventPath.length; i++) {
1031   - if (!invoke(eventPath[i], event, phase, eventPath, overrideTarget)) return;
1032   - }
1033   - if (win && eventPath.length > 0) {
1034   - invoke(win, event, phase, eventPath, overrideTarget);
1035   - }
1036   - }
1037   - function invoke(currentTarget, event, phase, eventPath, overrideTarget) {
1038   - var listeners = listenersTable.get(currentTarget);
1039   - if (!listeners) return true;
1040   - var target = overrideTarget || eventRetargetting(eventPath, currentTarget);
1041   - if (target === currentTarget) {
1042   - if (phase === CAPTURING_PHASE) return true;
1043   - if (phase === BUBBLING_PHASE) phase = AT_TARGET;
1044   - } else if (phase === BUBBLING_PHASE && !event.bubbles) {
1045   - return true;
1046   - }
1047   - if ("relatedTarget" in event) {
1048   - var originalEvent = unwrap(event);
1049   - var unwrappedRelatedTarget = originalEvent.relatedTarget;
1050   - if (unwrappedRelatedTarget) {
1051   - if (unwrappedRelatedTarget instanceof Object && unwrappedRelatedTarget.addEventListener) {
1052   - var relatedTarget = wrap(unwrappedRelatedTarget);
1053   - var adjusted = relatedTargetResolution(event, currentTarget, relatedTarget);
1054   - if (adjusted === target) return true;
1055   - } else {
1056   - adjusted = null;
1057   - }
1058   - relatedTargetTable.set(event, adjusted);
1059   - }
1060   - }
1061   - eventPhaseTable.set(event, phase);
1062   - var type = event.type;
1063   - var anyRemoved = false;
1064   - targetTable.set(event, target);
1065   - currentTargetTable.set(event, currentTarget);
1066   - listeners.depth++;
1067   - for (var i = 0, len = listeners.length; i < len; i++) {
1068   - var listener = listeners[i];
1069   - if (listener.removed) {
1070   - anyRemoved = true;
1071   - continue;
1072   - }
1073   - if (listener.type !== type || !listener.capture && phase === CAPTURING_PHASE || listener.capture && phase === BUBBLING_PHASE) {
1074   - continue;
1075   - }
1076   - try {
1077   - if (typeof listener.handler === "function") listener.handler.call(currentTarget, event); else listener.handler.handleEvent(event);
1078   - if (stopImmediatePropagationTable.get(event)) return false;
1079   - } catch (ex) {
1080   - if (!pendingError) pendingError = ex;
1081   - }
1082   - }
1083   - listeners.depth--;
1084   - if (anyRemoved && listeners.depth === 0) {
1085   - var copy = listeners.slice();
1086   - listeners.length = 0;
1087   - for (var i = 0; i < copy.length; i++) {
1088   - if (!copy[i].removed) listeners.push(copy[i]);
1089   - }
1090   - }
1091   - return !stopPropagationTable.get(event);
1092   - }
1093   - function Listener(type, handler, capture) {
1094   - this.type = type;
1095   - this.handler = handler;
1096   - this.capture = Boolean(capture);
1097   - }
1098   - Listener.prototype = {
1099   - equals: function(that) {
1100   - return this.handler === that.handler && this.type === that.type && this.capture === that.capture;
1101   - },
1102   - get removed() {
1103   - return this.handler === null;
1104   - },
1105   - remove: function() {
1106   - this.handler = null;
1107   - }
1108   - };
1109   - var OriginalEvent = window.Event;
1110   - OriginalEvent.prototype.polymerBlackList_ = {
1111   - returnValue: true,
1112   - keyLocation: true
1113   - };
1114   - function Event(type, options) {
1115   - if (type instanceof OriginalEvent) {
1116   - var impl = type;
1117   - if (!OriginalBeforeUnloadEvent && impl.type === "beforeunload" && !(this instanceof BeforeUnloadEvent)) {
1118   - return new BeforeUnloadEvent(impl);
1119   - }
1120   - setWrapper(impl, this);
1121   - } else {
1122   - return wrap(constructEvent(OriginalEvent, "Event", type, options));
1123   - }
1124   - }
1125   - Event.prototype = {
1126   - get target() {
1127   - return targetTable.get(this);
1128   - },
1129   - get currentTarget() {
1130   - return currentTargetTable.get(this);
1131   - },
1132   - get eventPhase() {
1133   - return eventPhaseTable.get(this);
1134   - },
1135   - get path() {
1136   - var eventPath = eventPathTable.get(this);
1137   - if (!eventPath) return [];
1138   - return eventPath.slice();
1139   - },
1140   - stopPropagation: function() {
1141   - stopPropagationTable.set(this, true);
1142   - },
1143   - stopImmediatePropagation: function() {
1144   - stopPropagationTable.set(this, true);
1145   - stopImmediatePropagationTable.set(this, true);
1146   - }
1147   - };
1148   - registerWrapper(OriginalEvent, Event, document.createEvent("Event"));
1149   - function unwrapOptions(options) {
1150   - if (!options || !options.relatedTarget) return options;
1151   - return Object.create(options, {
1152   - relatedTarget: {
1153   - value: unwrap(options.relatedTarget)
1154   - }
1155   - });
1156   - }
1157   - function registerGenericEvent(name, SuperEvent, prototype) {
1158   - var OriginalEvent = window[name];
1159   - var GenericEvent = function(type, options) {
1160   - if (type instanceof OriginalEvent) setWrapper(type, this); else return wrap(constructEvent(OriginalEvent, name, type, options));
1161   - };
1162   - GenericEvent.prototype = Object.create(SuperEvent.prototype);
1163   - if (prototype) mixin(GenericEvent.prototype, prototype);
1164   - if (OriginalEvent) {
1165   - try {
1166   - registerWrapper(OriginalEvent, GenericEvent, new OriginalEvent("temp"));
1167   - } catch (ex) {
1168   - registerWrapper(OriginalEvent, GenericEvent, document.createEvent(name));
1169   - }
1170   - }
1171   - return GenericEvent;
1172   - }
1173   - var UIEvent = registerGenericEvent("UIEvent", Event);
1174   - var CustomEvent = registerGenericEvent("CustomEvent", Event);
1175   - var relatedTargetProto = {
1176   - get relatedTarget() {
1177   - var relatedTarget = relatedTargetTable.get(this);
1178   - if (relatedTarget !== undefined) return relatedTarget;
1179   - return wrap(unwrap(this).relatedTarget);
1180   - }
1181   - };
1182   - function getInitFunction(name, relatedTargetIndex) {
1183   - return function() {
1184   - arguments[relatedTargetIndex] = unwrap(arguments[relatedTargetIndex]);
1185   - var impl = unwrap(this);
1186   - impl[name].apply(impl, arguments);
1187   - };
1188   - }
1189   - var mouseEventProto = mixin({
1190   - initMouseEvent: getInitFunction("initMouseEvent", 14)
1191   - }, relatedTargetProto);
1192   - var focusEventProto = mixin({
1193   - initFocusEvent: getInitFunction("initFocusEvent", 5)
1194   - }, relatedTargetProto);
1195   - var MouseEvent = registerGenericEvent("MouseEvent", UIEvent, mouseEventProto);
1196   - var FocusEvent = registerGenericEvent("FocusEvent", UIEvent, focusEventProto);
1197   - var defaultInitDicts = Object.create(null);
1198   - var supportsEventConstructors = function() {
1199   - try {
1200   - new window.FocusEvent("focus");
1201   - } catch (ex) {
1202   - return false;
1203   - }
1204   - return true;
1205   - }();
1206   - function constructEvent(OriginalEvent, name, type, options) {
1207   - if (supportsEventConstructors) return new OriginalEvent(type, unwrapOptions(options));
1208   - var event = unwrap(document.createEvent(name));
1209   - var defaultDict = defaultInitDicts[name];
1210   - var args = [ type ];
1211   - Object.keys(defaultDict).forEach(function(key) {
1212   - var v = options != null && key in options ? options[key] : defaultDict[key];
1213   - if (key === "relatedTarget") v = unwrap(v);
1214   - args.push(v);
1215   - });
1216   - event["init" + name].apply(event, args);
1217   - return event;
1218   - }
1219   - if (!supportsEventConstructors) {
1220   - var configureEventConstructor = function(name, initDict, superName) {
1221   - if (superName) {
1222   - var superDict = defaultInitDicts[superName];
1223   - initDict = mixin(mixin({}, superDict), initDict);
1224   - }
1225   - defaultInitDicts[name] = initDict;
1226   - };
1227   - configureEventConstructor("Event", {
1228   - bubbles: false,
1229   - cancelable: false
1230   - });
1231   - configureEventConstructor("CustomEvent", {
1232   - detail: null
1233   - }, "Event");
1234   - configureEventConstructor("UIEvent", {
1235   - view: null,
1236   - detail: 0
1237   - }, "Event");
1238   - configureEventConstructor("MouseEvent", {
1239   - screenX: 0,
1240   - screenY: 0,
1241   - clientX: 0,
1242   - clientY: 0,
1243   - ctrlKey: false,
1244   - altKey: false,
1245   - shiftKey: false,
1246   - metaKey: false,
1247   - button: 0,
1248   - relatedTarget: null
1249   - }, "UIEvent");
1250   - configureEventConstructor("FocusEvent", {
1251   - relatedTarget: null
1252   - }, "UIEvent");
1253   - }
1254   - var OriginalBeforeUnloadEvent = window.BeforeUnloadEvent;
1255   - function BeforeUnloadEvent(impl) {
1256   - Event.call(this, impl);
1257   - }
1258   - BeforeUnloadEvent.prototype = Object.create(Event.prototype);
1259   - mixin(BeforeUnloadEvent.prototype, {
1260   - get returnValue() {
1261   - return unsafeUnwrap(this).returnValue;
1262   - },
1263   - set returnValue(v) {
1264   - unsafeUnwrap(this).returnValue = v;
1265   - }
1266   - });
1267   - if (OriginalBeforeUnloadEvent) registerWrapper(OriginalBeforeUnloadEvent, BeforeUnloadEvent);
1268   - function isValidListener(fun) {
1269   - if (typeof fun === "function") return true;
1270   - return fun && fun.handleEvent;
1271   - }
1272   - function isMutationEvent(type) {
1273   - switch (type) {
1274   - case "DOMAttrModified":
1275   - case "DOMAttributeNameChanged":
1276   - case "DOMCharacterDataModified":
1277   - case "DOMElementNameChanged":
1278   - case "DOMNodeInserted":
1279   - case "DOMNodeInsertedIntoDocument":
1280   - case "DOMNodeRemoved":
1281   - case "DOMNodeRemovedFromDocument":
1282   - case "DOMSubtreeModified":
1283   - return true;
1284   - }
1285   - return false;
1286   - }
1287   - var OriginalEventTarget = window.EventTarget;
1288   - function EventTarget(impl) {
1289   - setWrapper(impl, this);
1290   - }
1291   - var methodNames = [ "addEventListener", "removeEventListener", "dispatchEvent" ];
1292   - [ Node, Window ].forEach(function(constructor) {
1293   - var p = constructor.prototype;
1294   - methodNames.forEach(function(name) {
1295   - Object.defineProperty(p, name + "_", {
1296   - value: p[name]
1297   - });
1298   - });
1299   - });
1300   - function getTargetToListenAt(wrapper) {
1301   - if (wrapper instanceof wrappers.ShadowRoot) wrapper = wrapper.host;
1302   - return unwrap(wrapper);
1303   - }
1304   - EventTarget.prototype = {
1305   - addEventListener: function(type, fun, capture) {
1306   - if (!isValidListener(fun) || isMutationEvent(type)) return;
1307   - var listener = new Listener(type, fun, capture);
1308   - var listeners = listenersTable.get(this);
1309   - if (!listeners) {
1310   - listeners = [];
1311   - listeners.depth = 0;
1312   - listenersTable.set(this, listeners);
1313   - } else {
1314   - for (var i = 0; i < listeners.length; i++) {
1315   - if (listener.equals(listeners[i])) return;
1316   - }
1317   - }
1318   - listeners.push(listener);
1319   - var target = getTargetToListenAt(this);
1320   - target.addEventListener_(type, dispatchOriginalEvent, true);
1321   - },
1322   - removeEventListener: function(type, fun, capture) {
1323   - capture = Boolean(capture);
1324   - var listeners = listenersTable.get(this);
1325   - if (!listeners) return;
1326   - var count = 0, found = false;
1327   - for (var i = 0; i < listeners.length; i++) {
1328   - if (listeners[i].type === type && listeners[i].capture === capture) {
1329   - count++;
1330   - if (listeners[i].handler === fun) {
1331   - found = true;
1332   - listeners[i].remove();
1333   - }
1334   - }
1335   - }
1336   - if (found && count === 1) {
1337   - var target = getTargetToListenAt(this);
1338   - target.removeEventListener_(type, dispatchOriginalEvent, true);
1339   - }
1340   - },
1341   - dispatchEvent: function(event) {
1342   - var nativeEvent = unwrap(event);
1343   - var eventType = nativeEvent.type;
1344   - handledEventsTable.set(nativeEvent, false);
1345   - scope.renderAllPending();
1346   - var tempListener;
1347   - if (!hasListenerInAncestors(this, eventType)) {
1348   - tempListener = function() {};
1349   - this.addEventListener(eventType, tempListener, true);
1350   - }
1351   - try {
1352   - return unwrap(this).dispatchEvent_(nativeEvent);
1353   - } finally {
1354   - if (tempListener) this.removeEventListener(eventType, tempListener, true);
1355   - }
1356   - }
1357   - };
1358   - function hasListener(node, type) {
1359   - var listeners = listenersTable.get(node);
1360   - if (listeners) {
1361   - for (var i = 0; i < listeners.length; i++) {
1362   - if (!listeners[i].removed && listeners[i].type === type) return true;
1363   - }
1364   - }
1365   - return false;
1366   - }
1367   - function hasListenerInAncestors(target, type) {
1368   - for (var node = unwrap(target); node; node = node.parentNode) {
1369   - if (hasListener(wrap(node), type)) return true;
1370   - }
1371   - return false;
1372   - }
1373   - if (OriginalEventTarget) registerWrapper(OriginalEventTarget, EventTarget);
1374   - function wrapEventTargetMethods(constructors) {
1375   - forwardMethodsToWrapper(constructors, methodNames);
1376   - }
1377   - var originalElementFromPoint = document.elementFromPoint;
1378   - function elementFromPoint(self, document, x, y) {
1379   - scope.renderAllPending();
1380   - var element = wrap(originalElementFromPoint.call(unsafeUnwrap(document), x, y));
1381   - if (!element) return null;
1382   - var path = getEventPath(element, null);
1383   - var idx = path.lastIndexOf(self);
1384   - if (idx == -1) return null; else path = path.slice(0, idx);
1385   - return eventRetargetting(path, self);
1386   - }
1387   - function getEventHandlerGetter(name) {
1388   - return function() {
1389   - var inlineEventHandlers = eventHandlersTable.get(this);
1390   - return inlineEventHandlers && inlineEventHandlers[name] && inlineEventHandlers[name].value || null;
1391   - };
1392   - }
1393   - function getEventHandlerSetter(name) {
1394   - var eventType = name.slice(2);
1395   - return function(value) {
1396   - var inlineEventHandlers = eventHandlersTable.get(this);
1397   - if (!inlineEventHandlers) {
1398   - inlineEventHandlers = Object.create(null);
1399   - eventHandlersTable.set(this, inlineEventHandlers);
1400   - }
1401   - var old = inlineEventHandlers[name];
1402   - if (old) this.removeEventListener(eventType, old.wrapped, false);
1403   - if (typeof value === "function") {
1404   - var wrapped = function(e) {
1405   - var rv = value.call(this, e);
1406   - if (rv === false) e.preventDefault(); else if (name === "onbeforeunload" && typeof rv === "string") e.returnValue = rv;
1407   - };
1408   - this.addEventListener(eventType, wrapped, false);
1409   - inlineEventHandlers[name] = {
1410   - value: value,
1411   - wrapped: wrapped
1412   - };
1413   - }
1414   - };
1415   - }
1416   - scope.elementFromPoint = elementFromPoint;
1417   - scope.getEventHandlerGetter = getEventHandlerGetter;
1418   - scope.getEventHandlerSetter = getEventHandlerSetter;
1419   - scope.wrapEventTargetMethods = wrapEventTargetMethods;
1420   - scope.wrappers.BeforeUnloadEvent = BeforeUnloadEvent;
1421   - scope.wrappers.CustomEvent = CustomEvent;
1422   - scope.wrappers.Event = Event;
1423   - scope.wrappers.EventTarget = EventTarget;
1424   - scope.wrappers.FocusEvent = FocusEvent;
1425   - scope.wrappers.MouseEvent = MouseEvent;
1426   - scope.wrappers.UIEvent = UIEvent;
1427   - })(window.ShadowDOMPolyfill);
1428   - (function(scope) {
1429   - "use strict";
1430   - var UIEvent = scope.wrappers.UIEvent;
1431   - var mixin = scope.mixin;
1432   - var registerWrapper = scope.registerWrapper;
1433   - var setWrapper = scope.setWrapper;
1434   - var unsafeUnwrap = scope.unsafeUnwrap;
1435   - var wrap = scope.wrap;
1436   - var OriginalTouchEvent = window.TouchEvent;
1437   - if (!OriginalTouchEvent) return;
1438   - var nativeEvent;
1439   - try {
1440   - nativeEvent = document.createEvent("TouchEvent");
1441   - } catch (ex) {
1442   - return;
1443   - }
1444   - var nonEnumDescriptor = {
1445   - enumerable: false
1446   - };
1447   - function nonEnum(obj, prop) {
1448   - Object.defineProperty(obj, prop, nonEnumDescriptor);
1449   - }
1450   - function Touch(impl) {
1451   - setWrapper(impl, this);
1452   - }
1453   - Touch.prototype = {
1454   - get target() {
1455   - return wrap(unsafeUnwrap(this).target);
1456   - }
1457   - };
1458   - var descr = {
1459   - configurable: true,
1460   - enumerable: true,
1461   - get: null
1462   - };
1463   - [ "clientX", "clientY", "screenX", "screenY", "pageX", "pageY", "identifier", "webkitRadiusX", "webkitRadiusY", "webkitRotationAngle", "webkitForce" ].forEach(function(name) {
1464   - descr.get = function() {
1465   - return unsafeUnwrap(this)[name];
1466   - };
1467   - Object.defineProperty(Touch.prototype, name, descr);
1468   - });
1469   - function TouchList() {
1470   - this.length = 0;
1471   - nonEnum(this, "length");
1472   - }
1473   - TouchList.prototype = {
1474   - item: function(index) {
1475   - return this[index];
1476   - }
1477   - };
1478   - function wrapTouchList(nativeTouchList) {
1479   - var list = new TouchList();
1480   - for (var i = 0; i < nativeTouchList.length; i++) {
1481   - list[i] = new Touch(nativeTouchList[i]);
1482   - }
1483   - list.length = i;
1484   - return list;
1485   - }
1486   - function TouchEvent(impl) {
1487   - UIEvent.call(this, impl);
1488   - }
1489   - TouchEvent.prototype = Object.create(UIEvent.prototype);
1490   - mixin(TouchEvent.prototype, {
1491   - get touches() {
1492   - return wrapTouchList(unsafeUnwrap(this).touches);
1493   - },
1494   - get targetTouches() {
1495   - return wrapTouchList(unsafeUnwrap(this).targetTouches);
1496   - },
1497   - get changedTouches() {
1498   - return wrapTouchList(unsafeUnwrap(this).changedTouches);
1499   - },
1500   - initTouchEvent: function() {
1501   - throw new Error("Not implemented");
1502   - }
1503   - });
1504   - registerWrapper(OriginalTouchEvent, TouchEvent, nativeEvent);
1505   - scope.wrappers.Touch = Touch;
1506   - scope.wrappers.TouchEvent = TouchEvent;
1507   - scope.wrappers.TouchList = TouchList;
1508   - })(window.ShadowDOMPolyfill);
1509   - (function(scope) {
1510   - "use strict";
1511   - var unsafeUnwrap = scope.unsafeUnwrap;
1512   - var wrap = scope.wrap;
1513   - var nonEnumDescriptor = {
1514   - enumerable: false
1515   - };
1516   - function nonEnum(obj, prop) {
1517   - Object.defineProperty(obj, prop, nonEnumDescriptor);
1518   - }
1519   - function NodeList() {
1520   - this.length = 0;
1521   - nonEnum(this, "length");
1522   - }
1523   - NodeList.prototype = {
1524   - item: function(index) {
1525   - return this[index];
1526   - }
1527   - };
1528   - nonEnum(NodeList.prototype, "item");
1529   - function wrapNodeList(list) {
1530   - if (list == null) return list;
1531   - var wrapperList = new NodeList();
1532   - for (var i = 0, length = list.length; i < length; i++) {
1533   - wrapperList[i] = wrap(list[i]);
1534   - }
1535   - wrapperList.length = length;
1536   - return wrapperList;
1537   - }
1538   - function addWrapNodeListMethod(wrapperConstructor, name) {
1539   - wrapperConstructor.prototype[name] = function() {
1540   - return wrapNodeList(unsafeUnwrap(this)[name].apply(unsafeUnwrap(this), arguments));
1541   - };
1542   - }
1543   - scope.wrappers.NodeList = NodeList;
1544   - scope.addWrapNodeListMethod = addWrapNodeListMethod;
1545   - scope.wrapNodeList = wrapNodeList;
1546   - })(window.ShadowDOMPolyfill);
1547   - (function(scope) {
1548   - "use strict";
1549   - scope.wrapHTMLCollection = scope.wrapNodeList;
1550   - scope.wrappers.HTMLCollection = scope.wrappers.NodeList;
1551   - })(window.ShadowDOMPolyfill);
1552   - (function(scope) {
1553   - "use strict";
1554   - var EventTarget = scope.wrappers.EventTarget;
1555   - var NodeList = scope.wrappers.NodeList;
1556   - var TreeScope = scope.TreeScope;
1557   - var assert = scope.assert;
1558   - var defineWrapGetter = scope.defineWrapGetter;
1559   - var enqueueMutation = scope.enqueueMutation;
1560   - var getTreeScope = scope.getTreeScope;
1561   - var isWrapper = scope.isWrapper;
1562   - var mixin = scope.mixin;
1563   - var registerTransientObservers = scope.registerTransientObservers;
1564   - var registerWrapper = scope.registerWrapper;
1565   - var setTreeScope = scope.setTreeScope;
1566   - var unsafeUnwrap = scope.unsafeUnwrap;
1567   - var unwrap = scope.unwrap;
1568   - var unwrapIfNeeded = scope.unwrapIfNeeded;
1569   - var wrap = scope.wrap;
1570   - var wrapIfNeeded = scope.wrapIfNeeded;
1571   - var wrappers = scope.wrappers;
1572   - function assertIsNodeWrapper(node) {
1573   - assert(node instanceof Node);
1574   - }
1575   - function createOneElementNodeList(node) {
1576   - var nodes = new NodeList();
1577   - nodes[0] = node;
1578   - nodes.length = 1;
1579   - return nodes;
1580   - }
1581   - var surpressMutations = false;
1582   - function enqueueRemovalForInsertedNodes(node, parent, nodes) {
1583   - enqueueMutation(parent, "childList", {
1584   - removedNodes: nodes,
1585   - previousSibling: node.previousSibling,
1586   - nextSibling: node.nextSibling
1587   - });
1588   - }
1589   - function enqueueRemovalForInsertedDocumentFragment(df, nodes) {
1590   - enqueueMutation(df, "childList", {
1591   - removedNodes: nodes
1592   - });
1593   - }
1594   - function collectNodes(node, parentNode, previousNode, nextNode) {
1595   - if (node instanceof DocumentFragment) {
1596   - var nodes = collectNodesForDocumentFragment(node);
1597   - surpressMutations = true;
1598   - for (var i = nodes.length - 1; i >= 0; i--) {
1599   - node.removeChild(nodes[i]);
1600   - nodes[i].parentNode_ = parentNode;
1601   - }
1602   - surpressMutations = false;
1603   - for (var i = 0; i < nodes.length; i++) {
1604   - nodes[i].previousSibling_ = nodes[i - 1] || previousNode;
1605   - nodes[i].nextSibling_ = nodes[i + 1] || nextNode;
1606   - }
1607   - if (previousNode) previousNode.nextSibling_ = nodes[0];
1608   - if (nextNode) nextNode.previousSibling_ = nodes[nodes.length - 1];
1609   - return nodes;
1610   - }
1611   - var nodes = createOneElementNodeList(node);
1612   - var oldParent = node.parentNode;
1613   - if (oldParent) {
1614   - oldParent.removeChild(node);
1615   - }
1616   - node.parentNode_ = parentNode;
1617   - node.previousSibling_ = previousNode;
1618   - node.nextSibling_ = nextNode;
1619   - if (previousNode) previousNode.nextSibling_ = node;
1620   - if (nextNode) nextNode.previousSibling_ = node;
1621   - return nodes;
1622   - }
1623   - function collectNodesNative(node) {
1624   - if (node instanceof DocumentFragment) return collectNodesForDocumentFragment(node);
1625   - var nodes = createOneElementNodeList(node);
1626   - var oldParent = node.parentNode;
1627   - if (oldParent) enqueueRemovalForInsertedNodes(node, oldParent, nodes);
1628   - return nodes;
1629   - }
1630   - function collectNodesForDocumentFragment(node) {
1631   - var nodes = new NodeList();
1632   - var i = 0;
1633   - for (var child = node.firstChild; child; child = child.nextSibling) {
1634   - nodes[i++] = child;
1635   - }
1636   - nodes.length = i;
1637   - enqueueRemovalForInsertedDocumentFragment(node, nodes);
1638   - return nodes;
1639   - }
1640   - function snapshotNodeList(nodeList) {
1641   - return nodeList;
1642   - }
1643   - function nodeWasAdded(node, treeScope) {
1644   - setTreeScope(node, treeScope);
1645   - node.nodeIsInserted_();
1646   - }
1647   - function nodesWereAdded(nodes, parent) {
1648   - var treeScope = getTreeScope(parent);
1649   - for (var i = 0; i < nodes.length; i++) {
1650   - nodeWasAdded(nodes[i], treeScope);
1651   - }
1652   - }
1653   - function nodeWasRemoved(node) {
1654   - setTreeScope(node, new TreeScope(node, null));
1655   - }
1656   - function nodesWereRemoved(nodes) {
1657   - for (var i = 0; i < nodes.length; i++) {
1658   - nodeWasRemoved(nodes[i]);
1659   - }
1660   - }
1661   - function ensureSameOwnerDocument(parent, child) {
1662   - var ownerDoc = parent.nodeType === Node.DOCUMENT_NODE ? parent : parent.ownerDocument;
1663   - if (ownerDoc !== child.ownerDocument) ownerDoc.adoptNode(child);
1664   - }
1665   - function adoptNodesIfNeeded(owner, nodes) {
1666   - if (!nodes.length) return;
1667   - var ownerDoc = owner.ownerDocument;
1668   - if (ownerDoc === nodes[0].ownerDocument) return;
1669   - for (var i = 0; i < nodes.length; i++) {
1670   - scope.adoptNodeNoRemove(nodes[i], ownerDoc);
1671   - }
1672   - }
1673   - function unwrapNodesForInsertion(owner, nodes) {
1674   - adoptNodesIfNeeded(owner, nodes);
1675   - var length = nodes.length;
1676   - if (length === 1) return unwrap(nodes[0]);
1677   - var df = unwrap(owner.ownerDocument.createDocumentFragment());
1678   - for (var i = 0; i < length; i++) {
1679   - df.appendChild(unwrap(nodes[i]));
1680   - }
1681   - return df;
1682   - }
1683   - function clearChildNodes(wrapper) {
1684   - if (wrapper.firstChild_ !== undefined) {
1685   - var child = wrapper.firstChild_;
1686   - while (child) {
1687   - var tmp = child;
1688   - child = child.nextSibling_;
1689   - tmp.parentNode_ = tmp.previousSibling_ = tmp.nextSibling_ = undefined;
1690   - }
1691   - }
1692   - wrapper.firstChild_ = wrapper.lastChild_ = undefined;
1693   - }
1694   - function removeAllChildNodes(wrapper) {
1695   - if (wrapper.invalidateShadowRenderer()) {
1696   - var childWrapper = wrapper.firstChild;
1697   - while (childWrapper) {
1698   - assert(childWrapper.parentNode === wrapper);
1699   - var nextSibling = childWrapper.nextSibling;
1700   - var childNode = unwrap(childWrapper);
1701   - var parentNode = childNode.parentNode;
1702   - if (parentNode) originalRemoveChild.call(parentNode, childNode);
1703   - childWrapper.previousSibling_ = childWrapper.nextSibling_ = childWrapper.parentNode_ = null;
1704   - childWrapper = nextSibling;
1705   - }
1706   - wrapper.firstChild_ = wrapper.lastChild_ = null;
1707   - } else {
1708   - var node = unwrap(wrapper);
1709   - var child = node.firstChild;
1710   - var nextSibling;
1711   - while (child) {
1712   - nextSibling = child.nextSibling;
1713   - originalRemoveChild.call(node, child);
1714   - child = nextSibling;
1715   - }
1716   - }
1717   - }
1718   - function invalidateParent(node) {
1719   - var p = node.parentNode;
1720   - return p && p.invalidateShadowRenderer();
1721   - }
1722   - function cleanupNodes(nodes) {
1723   - for (var i = 0, n; i < nodes.length; i++) {
1724   - n = nodes[i];
1725   - n.parentNode.removeChild(n);
1726   - }
1727   - }
1728   - var originalImportNode = document.importNode;
1729   - var originalCloneNode = window.Node.prototype.cloneNode;
1730   - function cloneNode(node, deep, opt_doc) {
1731   - var clone;
1732   - if (opt_doc) clone = wrap(originalImportNode.call(opt_doc, unsafeUnwrap(node), false)); else clone = wrap(originalCloneNode.call(unsafeUnwrap(node), false));
1733   - if (deep) {
1734   - for (var child = node.firstChild; child; child = child.nextSibling) {
1735   - clone.appendChild(cloneNode(child, true, opt_doc));
1736   - }
1737   - if (node instanceof wrappers.HTMLTemplateElement) {
1738   - var cloneContent = clone.content;
1739   - for (var child = node.content.firstChild; child; child = child.nextSibling) {
1740   - cloneContent.appendChild(cloneNode(child, true, opt_doc));
1741   - }
1742   - }
1743   - }
1744   - return clone;
1745   - }
1746   - function contains(self, child) {
1747   - if (!child || getTreeScope(self) !== getTreeScope(child)) return false;
1748   - for (var node = child; node; node = node.parentNode) {
1749   - if (node === self) return true;
1750   - }
1751   - return false;
1752   - }
1753   - var OriginalNode = window.Node;
1754   - function Node(original) {
1755   - assert(original instanceof OriginalNode);
1756   - EventTarget.call(this, original);
1757   - this.parentNode_ = undefined;
1758   - this.firstChild_ = undefined;
1759   - this.lastChild_ = undefined;
1760   - this.nextSibling_ = undefined;
1761   - this.previousSibling_ = undefined;
1762   - this.treeScope_ = undefined;
1763   - }
1764   - var OriginalDocumentFragment = window.DocumentFragment;
1765   - var originalAppendChild = OriginalNode.prototype.appendChild;
1766   - var originalCompareDocumentPosition = OriginalNode.prototype.compareDocumentPosition;
1767   - var originalInsertBefore = OriginalNode.prototype.insertBefore;
1768   - var originalRemoveChild = OriginalNode.prototype.removeChild;
1769   - var originalReplaceChild = OriginalNode.prototype.replaceChild;
1770   - var isIe = /Trident|Edge/.test(navigator.userAgent);
1771   - var removeChildOriginalHelper = isIe ? function(parent, child) {
1772   - try {
1773   - originalRemoveChild.call(parent, child);
1774   - } catch (ex) {
1775   - if (!(parent instanceof OriginalDocumentFragment)) throw ex;
1776   - }
1777   - } : function(parent, child) {
1778   - originalRemoveChild.call(parent, child);
1779   - };
1780   - Node.prototype = Object.create(EventTarget.prototype);
1781   - mixin(Node.prototype, {
1782   - appendChild: function(childWrapper) {
1783   - return this.insertBefore(childWrapper, null);
1784   - },
1785   - insertBefore: function(childWrapper, refWrapper) {
1786   - assertIsNodeWrapper(childWrapper);
1787   - var refNode;
1788   - if (refWrapper) {
1789   - if (isWrapper(refWrapper)) {
1790   - refNode = unwrap(refWrapper);
1791   - } else {
1792   - refNode = refWrapper;
1793   - refWrapper = wrap(refNode);
1794   - }
1795   - } else {
1796   - refWrapper = null;
1797   - refNode = null;
1798   - }
1799   - refWrapper && assert(refWrapper.parentNode === this);
1800   - var nodes;
1801   - var previousNode = refWrapper ? refWrapper.previousSibling : this.lastChild;
1802   - var useNative = !this.invalidateShadowRenderer() && !invalidateParent(childWrapper);
1803   - if (useNative) nodes = collectNodesNative(childWrapper); else nodes = collectNodes(childWrapper, this, previousNode, refWrapper);
1804   - if (useNative) {
1805   - ensureSameOwnerDocument(this, childWrapper);
1806   - clearChildNodes(this);
1807   - originalInsertBefore.call(unsafeUnwrap(this), unwrap(childWrapper), refNode);
1808   - } else {
1809   - if (!previousNode) this.firstChild_ = nodes[0];
1810   - if (!refWrapper) {
1811   - this.lastChild_ = nodes[nodes.length - 1];
1812   - if (this.firstChild_ === undefined) this.firstChild_ = this.firstChild;
1813   - }
1814   - var parentNode = refNode ? refNode.parentNode : unsafeUnwrap(this);
1815   - if (parentNode) {
1816   - originalInsertBefore.call(parentNode, unwrapNodesForInsertion(this, nodes), refNode);
1817   - } else {
1818   - adoptNodesIfNeeded(this, nodes);
1819   - }
1820   - }
1821   - enqueueMutation(this, "childList", {
1822   - addedNodes: nodes,
1823   - nextSibling: refWrapper,
1824   - previousSibling: previousNode
1825   - });
1826   - nodesWereAdded(nodes, this);
1827   - return childWrapper;
1828   - },
1829   - removeChild: function(childWrapper) {
1830   - assertIsNodeWrapper(childWrapper);
1831   - if (childWrapper.parentNode !== this) {
1832   - var found = false;
1833   - var childNodes = this.childNodes;
1834   - for (var ieChild = this.firstChild; ieChild; ieChild = ieChild.nextSibling) {
1835   - if (ieChild === childWrapper) {
1836   - found = true;
1837   - break;
1838   - }
1839   - }
1840   - if (!found) {
1841   - throw new Error("NotFoundError");
1842   - }
1843   - }
1844   - var childNode = unwrap(childWrapper);
1845   - var childWrapperNextSibling = childWrapper.nextSibling;
1846   - var childWrapperPreviousSibling = childWrapper.previousSibling;
1847   - if (this.invalidateShadowRenderer()) {
1848   - var thisFirstChild = this.firstChild;
1849   - var thisLastChild = this.lastChild;
1850   - var parentNode = childNode.parentNode;
1851   - if (parentNode) removeChildOriginalHelper(parentNode, childNode);
1852   - if (thisFirstChild === childWrapper) this.firstChild_ = childWrapperNextSibling;
1853   - if (thisLastChild === childWrapper) this.lastChild_ = childWrapperPreviousSibling;
1854   - if (childWrapperPreviousSibling) childWrapperPreviousSibling.nextSibling_ = childWrapperNextSibling;
1855   - if (childWrapperNextSibling) {
1856   - childWrapperNextSibling.previousSibling_ = childWrapperPreviousSibling;
1857   - }
1858   - childWrapper.previousSibling_ = childWrapper.nextSibling_ = childWrapper.parentNode_ = undefined;
1859   - } else {
1860   - clearChildNodes(this);
1861   - removeChildOriginalHelper(unsafeUnwrap(this), childNode);
1862   - }
1863   - if (!surpressMutations) {
1864   - enqueueMutation(this, "childList", {
1865   - removedNodes: createOneElementNodeList(childWrapper),
1866   - nextSibling: childWrapperNextSibling,
1867   - previousSibling: childWrapperPreviousSibling
1868   - });
1869   - }
1870   - registerTransientObservers(this, childWrapper);
1871   - return childWrapper;
1872   - },
1873   - replaceChild: function(newChildWrapper, oldChildWrapper) {
1874   - assertIsNodeWrapper(newChildWrapper);
1875   - var oldChildNode;
1876   - if (isWrapper(oldChildWrapper)) {
1877   - oldChildNode = unwrap(oldChildWrapper);
1878   - } else {
1879   - oldChildNode = oldChildWrapper;
1880   - oldChildWrapper = wrap(oldChildNode);
1881   - }
1882   - if (oldChildWrapper.parentNode !== this) {
1883   - throw new Error("NotFoundError");
1884   - }
1885   - var nextNode = oldChildWrapper.nextSibling;
1886   - var previousNode = oldChildWrapper.previousSibling;
1887   - var nodes;
1888   - var useNative = !this.invalidateShadowRenderer() && !invalidateParent(newChildWrapper);
1889   - if (useNative) {
1890   - nodes = collectNodesNative(newChildWrapper);
1891   - } else {
1892   - if (nextNode === newChildWrapper) nextNode = newChildWrapper.nextSibling;
1893   - nodes = collectNodes(newChildWrapper, this, previousNode, nextNode);
1894   - }
1895   - if (!useNative) {
1896   - if (this.firstChild === oldChildWrapper) this.firstChild_ = nodes[0];
1897   - if (this.lastChild === oldChildWrapper) this.lastChild_ = nodes[nodes.length - 1];
1898   - oldChildWrapper.previousSibling_ = oldChildWrapper.nextSibling_ = oldChildWrapper.parentNode_ = undefined;
1899   - if (oldChildNode.parentNode) {
1900   - originalReplaceChild.call(oldChildNode.parentNode, unwrapNodesForInsertion(this, nodes), oldChildNode);
1901   - }
1902   - } else {
1903   - ensureSameOwnerDocument(this, newChildWrapper);
1904   - clearChildNodes(this);
1905   - originalReplaceChild.call(unsafeUnwrap(this), unwrap(newChildWrapper), oldChildNode);
1906   - }
1907   - enqueueMutation(this, "childList", {
1908   - addedNodes: nodes,
1909   - removedNodes: createOneElementNodeList(oldChildWrapper),
1910   - nextSibling: nextNode,
1911   - previousSibling: previousNode
1912   - });
1913   - nodeWasRemoved(oldChildWrapper);
1914   - nodesWereAdded(nodes, this);
1915   - return oldChildWrapper;
1916   - },
1917   - nodeIsInserted_: function() {
1918   - for (var child = this.firstChild; child; child = child.nextSibling) {
1919   - child.nodeIsInserted_();
1920   - }
1921   - },
1922   - hasChildNodes: function() {
1923   - return this.firstChild !== null;
1924   - },
1925   - get parentNode() {
1926   - return this.parentNode_ !== undefined ? this.parentNode_ : wrap(unsafeUnwrap(this).parentNode);
1927   - },
1928   - get firstChild() {
1929   - return this.firstChild_ !== undefined ? this.firstChild_ : wrap(unsafeUnwrap(this).firstChild);
1930   - },
1931   - get lastChild() {
1932   - return this.lastChild_ !== undefined ? this.lastChild_ : wrap(unsafeUnwrap(this).lastChild);
1933   - },
1934   - get nextSibling() {
1935   - return this.nextSibling_ !== undefined ? this.nextSibling_ : wrap(unsafeUnwrap(this).nextSibling);
1936   - },
1937   - get previousSibling() {
1938   - return this.previousSibling_ !== undefined ? this.previousSibling_ : wrap(unsafeUnwrap(this).previousSibling);
1939   - },
1940   - get parentElement() {
1941   - var p = this.parentNode;
1942   - while (p && p.nodeType !== Node.ELEMENT_NODE) {
1943   - p = p.parentNode;
1944   - }
1945   - return p;
1946   - },
1947   - get textContent() {
1948   - var s = "";
1949   - for (var child = this.firstChild; child; child = child.nextSibling) {
1950   - if (child.nodeType != Node.COMMENT_NODE) {
1951   - s += child.textContent;
1952   - }
1953   - }
1954   - return s;
1955   - },
1956   - set textContent(textContent) {
1957   - if (textContent == null) textContent = "";
1958   - var removedNodes = snapshotNodeList(this.childNodes);
1959   - if (this.invalidateShadowRenderer()) {
1960   - removeAllChildNodes(this);
1961   - if (textContent !== "") {
1962   - var textNode = unsafeUnwrap(this).ownerDocument.createTextNode(textContent);
1963   - this.appendChild(textNode);
1964   - }
1965   - } else {
1966   - clearChildNodes(this);
1967   - unsafeUnwrap(this).textContent = textContent;
1968   - }
1969   - var addedNodes = snapshotNodeList(this.childNodes);
1970   - enqueueMutation(this, "childList", {
1971   - addedNodes: addedNodes,
1972   - removedNodes: removedNodes
1973   - });
1974   - nodesWereRemoved(removedNodes);
1975   - nodesWereAdded(addedNodes, this);
1976   - },
1977   - get childNodes() {
1978   - var wrapperList = new NodeList();
1979   - var i = 0;
1980   - for (var child = this.firstChild; child; child = child.nextSibling) {
1981   - wrapperList[i++] = child;
1982   - }
1983   - wrapperList.length = i;
1984   - return wrapperList;
1985   - },
1986   - cloneNode: function(deep) {
1987   - return cloneNode(this, deep);
1988   - },
1989   - contains: function(child) {
1990   - return contains(this, wrapIfNeeded(child));
1991   - },
1992   - compareDocumentPosition: function(otherNode) {
1993   - return originalCompareDocumentPosition.call(unsafeUnwrap(this), unwrapIfNeeded(otherNode));
1994   - },
1995   - normalize: function() {
1996   - var nodes = snapshotNodeList(this.childNodes);
1997   - var remNodes = [];
1998   - var s = "";
1999   - var modNode;
2000   - for (var i = 0, n; i < nodes.length; i++) {
2001   - n = nodes[i];
2002   - if (n.nodeType === Node.TEXT_NODE) {
2003   - if (!modNode && !n.data.length) this.removeChild(n); else if (!modNode) modNode = n; else {
2004   - s += n.data;
2005   - remNodes.push(n);
2006   - }
2007   - } else {
2008   - if (modNode && remNodes.length) {
2009   - modNode.data += s;
2010   - cleanupNodes(remNodes);
2011   - }
2012   - remNodes = [];
2013   - s = "";
2014   - modNode = null;
2015   - if (n.childNodes.length) n.normalize();
2016   - }
2017   - }
2018   - if (modNode && remNodes.length) {
2019   - modNode.data += s;
2020   - cleanupNodes(remNodes);
2021   - }
2022   - }
2023   - });
2024   - defineWrapGetter(Node, "ownerDocument");
2025   - registerWrapper(OriginalNode, Node, document.createDocumentFragment());
2026   - delete Node.prototype.querySelector;
2027   - delete Node.prototype.querySelectorAll;
2028   - Node.prototype = mixin(Object.create(EventTarget.prototype), Node.prototype);
2029   - scope.cloneNode = cloneNode;
2030   - scope.nodeWasAdded = nodeWasAdded;
2031   - scope.nodeWasRemoved = nodeWasRemoved;
2032   - scope.nodesWereAdded = nodesWereAdded;
2033   - scope.nodesWereRemoved = nodesWereRemoved;
2034   - scope.originalInsertBefore = originalInsertBefore;
2035   - scope.originalRemoveChild = originalRemoveChild;
2036   - scope.snapshotNodeList = snapshotNodeList;
2037   - scope.wrappers.Node = Node;
2038   - })(window.ShadowDOMPolyfill);
2039   - (function(scope) {
2040   - "use strict";
2041   - var HTMLCollection = scope.wrappers.HTMLCollection;
2042   - var NodeList = scope.wrappers.NodeList;
2043   - var getTreeScope = scope.getTreeScope;
2044   - var unsafeUnwrap = scope.unsafeUnwrap;
2045   - var wrap = scope.wrap;
2046   - var originalDocumentQuerySelector = document.querySelector;
2047   - var originalElementQuerySelector = document.documentElement.querySelector;
2048   - var originalDocumentQuerySelectorAll = document.querySelectorAll;
2049   - var originalElementQuerySelectorAll = document.documentElement.querySelectorAll;
2050   - var originalDocumentGetElementsByTagName = document.getElementsByTagName;
2051   - var originalElementGetElementsByTagName = document.documentElement.getElementsByTagName;
2052   - var originalDocumentGetElementsByTagNameNS = document.getElementsByTagNameNS;
2053   - var originalElementGetElementsByTagNameNS = document.documentElement.getElementsByTagNameNS;
2054   - var OriginalElement = window.Element;
2055   - var OriginalDocument = window.HTMLDocument || window.Document;
2056   - function filterNodeList(list, index, result, deep) {
2057   - var wrappedItem = null;
2058   - var root = null;
2059   - for (var i = 0, length = list.length; i < length; i++) {
2060   - wrappedItem = wrap(list[i]);
2061   - if (!deep && (root = getTreeScope(wrappedItem).root)) {
2062   - if (root instanceof scope.wrappers.ShadowRoot) {
2063   - continue;
2064   - }
2065   - }
2066   - result[index++] = wrappedItem;
2067   - }
2068   - return index;
2069   - }
2070   - function shimSelector(selector) {
2071   - return String(selector).replace(/\/deep\/|::shadow/g, " ");
2072   - }
2073   - function shimMatchesSelector(selector) {
2074   - return String(selector).replace(/:host\(([^\s]+)\)/g, "$1").replace(/([^\s]):host/g, "$1").replace(":host", "*").replace(/\^|\/shadow\/|\/shadow-deep\/|::shadow|\/deep\/|::content/g, " ");
2075   - }
2076   - function findOne(node, selector) {
2077   - var m, el = node.firstElementChild;
2078   - while (el) {
2079   - if (el.matches(selector)) return el;
2080   - m = findOne(el, selector);
2081   - if (m) return m;
2082   - el = el.nextElementSibling;
2083   - }
2084   - return null;
2085   - }
2086   - function matchesSelector(el, selector) {
2087   - return el.matches(selector);
2088   - }
2089   - var XHTML_NS = "http://www.w3.org/1999/xhtml";
2090   - function matchesTagName(el, localName, localNameLowerCase) {
2091   - var ln = el.localName;
2092   - return ln === localName || ln === localNameLowerCase && el.namespaceURI === XHTML_NS;
2093   - }
2094   - function matchesEveryThing() {
2095   - return true;
2096   - }
2097   - function matchesLocalNameOnly(el, ns, localName) {
2098   - return el.localName === localName;
2099   - }
2100   - function matchesNameSpace(el, ns) {
2101   - return el.namespaceURI === ns;
2102   - }
2103   - function matchesLocalNameNS(el, ns, localName) {
2104   - return el.namespaceURI === ns && el.localName === localName;
2105   - }
2106   - function findElements(node, index, result, p, arg0, arg1) {
2107   - var el = node.firstElementChild;
2108   - while (el) {
2109   - if (p(el, arg0, arg1)) result[index++] = el;
2110   - index = findElements(el, index, result, p, arg0, arg1);
2111   - el = el.nextElementSibling;
2112   - }
2113   - return index;
2114   - }
2115   - function querySelectorAllFiltered(p, index, result, selector, deep) {
2116   - var target = unsafeUnwrap(this);
2117   - var list;
2118   - var root = getTreeScope(this).root;
2119   - if (root instanceof scope.wrappers.ShadowRoot) {
2120   - return findElements(this, index, result, p, selector, null);
2121   - } else if (target instanceof OriginalElement) {
2122   - list = originalElementQuerySelectorAll.call(target, selector);
2123   - } else if (target instanceof OriginalDocument) {
2124   - list = originalDocumentQuerySelectorAll.call(target, selector);
2125   - } else {
2126   - return findElements(this, index, result, p, selector, null);
2127   - }
2128   - return filterNodeList(list, index, result, deep);
2129   - }
2130   - var SelectorsInterface = {
2131   - querySelector: function(selector) {
2132   - var shimmed = shimSelector(selector);
2133   - var deep = shimmed !== selector;
2134   - selector = shimmed;
2135   - var target = unsafeUnwrap(this);
2136   - var wrappedItem;
2137   - var root = getTreeScope(this).root;
2138   - if (root instanceof scope.wrappers.ShadowRoot) {
2139   - return findOne(this, selector);
2140   - } else if (target instanceof OriginalElement) {
2141   - wrappedItem = wrap(originalElementQuerySelector.call(target, selector));
2142   - } else if (target instanceof OriginalDocument) {
2143   - wrappedItem = wrap(originalDocumentQuerySelector.call(target, selector));
2144   - } else {
2145   - return findOne(this, selector);
2146   - }
2147   - if (!wrappedItem) {
2148   - return wrappedItem;
2149   - } else if (!deep && (root = getTreeScope(wrappedItem).root)) {
2150   - if (root instanceof scope.wrappers.ShadowRoot) {
2151   - return findOne(this, selector);
2152   - }
2153   - }
2154   - return wrappedItem;
2155   - },
2156   - querySelectorAll: function(selector) {
2157   - var shimmed = shimSelector(selector);
2158   - var deep = shimmed !== selector;
2159   - selector = shimmed;
2160   - var result = new NodeList();
2161   - result.length = querySelectorAllFiltered.call(this, matchesSelector, 0, result, selector, deep);
2162   - return result;
2163   - }
2164   - };
2165   - var MatchesInterface = {
2166   - matches: function(selector) {
2167   - selector = shimMatchesSelector(selector);
2168   - return scope.originalMatches.call(unsafeUnwrap(this), selector);
2169   - }
2170   - };
2171   - function getElementsByTagNameFiltered(p, index, result, localName, lowercase) {
2172   - var target = unsafeUnwrap(this);
2173   - var list;
2174   - var root = getTreeScope(this).root;
2175   - if (root instanceof scope.wrappers.ShadowRoot) {
2176   - return findElements(this, index, result, p, localName, lowercase);
2177   - } else if (target instanceof OriginalElement) {
2178   - list = originalElementGetElementsByTagName.call(target, localName, lowercase);
2179   - } else if (target instanceof OriginalDocument) {
2180   - list = originalDocumentGetElementsByTagName.call(target, localName, lowercase);
2181   - } else {
2182   - return findElements(this, index, result, p, localName, lowercase);
2183   - }
2184   - return filterNodeList(list, index, result, false);
2185   - }
2186   - function getElementsByTagNameNSFiltered(p, index, result, ns, localName) {
2187   - var target = unsafeUnwrap(this);
2188   - var list;
2189   - var root = getTreeScope(this).root;
2190   - if (root instanceof scope.wrappers.ShadowRoot) {
2191   - return findElements(this, index, result, p, ns, localName);
2192   - } else if (target instanceof OriginalElement) {
2193   - list = originalElementGetElementsByTagNameNS.call(target, ns, localName);
2194   - } else if (target instanceof OriginalDocument) {
2195   - list = originalDocumentGetElementsByTagNameNS.call(target, ns, localName);
2196   - } else {
2197   - return findElements(this, index, result, p, ns, localName);
2198   - }
2199   - return filterNodeList(list, index, result, false);
2200   - }
2201   - var GetElementsByInterface = {
2202   - getElementsByTagName: function(localName) {
2203   - var result = new HTMLCollection();
2204   - var match = localName === "*" ? matchesEveryThing : matchesTagName;
2205   - result.length = getElementsByTagNameFiltered.call(this, match, 0, result, localName, localName.toLowerCase());
2206   - return result;
2207   - },
2208   - getElementsByClassName: function(className) {
2209   - return this.querySelectorAll("." + className);
2210   - },
2211   - getElementsByTagNameNS: function(ns, localName) {
2212   - var result = new HTMLCollection();
2213   - var match = null;
2214   - if (ns === "*") {
2215   - match = localName === "*" ? matchesEveryThing : matchesLocalNameOnly;
2216   - } else {
2217   - match = localName === "*" ? matchesNameSpace : matchesLocalNameNS;
2218   - }
2219   - result.length = getElementsByTagNameNSFiltered.call(this, match, 0, result, ns || null, localName);
2220   - return result;
2221   - }
2222   - };
2223   - scope.GetElementsByInterface = GetElementsByInterface;
2224   - scope.SelectorsInterface = SelectorsInterface;
2225   - scope.MatchesInterface = MatchesInterface;
2226   - })(window.ShadowDOMPolyfill);
2227   - (function(scope) {
2228   - "use strict";
2229   - var NodeList = scope.wrappers.NodeList;
2230   - function forwardElement(node) {
2231   - while (node && node.nodeType !== Node.ELEMENT_NODE) {
2232   - node = node.nextSibling;
2233   - }
2234   - return node;
2235   - }
2236   - function backwardsElement(node) {
2237   - while (node && node.nodeType !== Node.ELEMENT_NODE) {
2238   - node = node.previousSibling;
2239   - }
2240   - return node;
2241   - }
2242   - var ParentNodeInterface = {
2243   - get firstElementChild() {
2244   - return forwardElement(this.firstChild);
2245   - },
2246   - get lastElementChild() {
2247   - return backwardsElement(this.lastChild);
2248   - },
2249   - get childElementCount() {
2250   - var count = 0;
2251   - for (var child = this.firstElementChild; child; child = child.nextElementSibling) {
2252   - count++;
2253   - }
2254   - return count;
2255   - },
2256   - get children() {
2257   - var wrapperList = new NodeList();
2258   - var i = 0;
2259   - for (var child = this.firstElementChild; child; child = child.nextElementSibling) {
2260   - wrapperList[i++] = child;
2261   - }
2262   - wrapperList.length = i;
2263   - return wrapperList;
2264   - },
2265   - remove: function() {
2266   - var p = this.parentNode;
2267   - if (p) p.removeChild(this);
2268   - }
2269   - };
2270   - var ChildNodeInterface = {
2271   - get nextElementSibling() {
2272   - return forwardElement(this.nextSibling);
2273   - },
2274   - get previousElementSibling() {
2275   - return backwardsElement(this.previousSibling);
2276   - }
2277   - };
2278   - scope.ChildNodeInterface = ChildNodeInterface;
2279   - scope.ParentNodeInterface = ParentNodeInterface;
2280   - })(window.ShadowDOMPolyfill);
2281   - (function(scope) {
2282   - "use strict";
2283   - var ChildNodeInterface = scope.ChildNodeInterface;
2284   - var Node = scope.wrappers.Node;
2285   - var enqueueMutation = scope.enqueueMutation;
2286   - var mixin = scope.mixin;
2287   - var registerWrapper = scope.registerWrapper;
2288   - var unsafeUnwrap = scope.unsafeUnwrap;
2289   - var OriginalCharacterData = window.CharacterData;
2290   - function CharacterData(node) {
2291   - Node.call(this, node);
2292   - }
2293   - CharacterData.prototype = Object.create(Node.prototype);
2294   - mixin(CharacterData.prototype, {
2295   - get textContent() {
2296   - return this.data;
2297   - },
2298   - set textContent(value) {
2299   - this.data = value;
2300   - },
2301   - get data() {
2302   - return unsafeUnwrap(this).data;
2303   - },
2304   - set data(value) {
2305   - var oldValue = unsafeUnwrap(this).data;
2306   - enqueueMutation(this, "characterData", {
2307   - oldValue: oldValue
2308   - });
2309   - unsafeUnwrap(this).data = value;
2310   - }
2311   - });
2312   - mixin(CharacterData.prototype, ChildNodeInterface);
2313   - registerWrapper(OriginalCharacterData, CharacterData, document.createTextNode(""));
2314   - scope.wrappers.CharacterData = CharacterData;
2315   - })(window.ShadowDOMPolyfill);
2316   - (function(scope) {
2317   - "use strict";
2318   - var CharacterData = scope.wrappers.CharacterData;
2319   - var enqueueMutation = scope.enqueueMutation;
2320   - var mixin = scope.mixin;
2321   - var registerWrapper = scope.registerWrapper;
2322   - function toUInt32(x) {
2323   - return x >>> 0;
2324   - }
2325   - var OriginalText = window.Text;
2326   - function Text(node) {
2327   - CharacterData.call(this, node);
2328   - }
2329   - Text.prototype = Object.create(CharacterData.prototype);
2330   - mixin(Text.prototype, {
2331   - splitText: function(offset) {
2332   - offset = toUInt32(offset);
2333   - var s = this.data;
2334   - if (offset > s.length) throw new Error("IndexSizeError");
2335   - var head = s.slice(0, offset);
2336   - var tail = s.slice(offset);
2337   - this.data = head;
2338   - var newTextNode = this.ownerDocument.createTextNode(tail);
2339   - if (this.parentNode) this.parentNode.insertBefore(newTextNode, this.nextSibling);
2340   - return newTextNode;
2341   - }
2342   - });
2343   - registerWrapper(OriginalText, Text, document.createTextNode(""));
2344   - scope.wrappers.Text = Text;
2345   - })(window.ShadowDOMPolyfill);
2346   - (function(scope) {
2347   - "use strict";
2348   - if (!window.DOMTokenList) {
2349   - console.warn("Missing DOMTokenList prototype, please include a " + "compatible classList polyfill such as http://goo.gl/uTcepH.");
2350   - return;
2351   - }
2352   - var unsafeUnwrap = scope.unsafeUnwrap;
2353   - var enqueueMutation = scope.enqueueMutation;
2354   - function getClass(el) {
2355   - return unsafeUnwrap(el).getAttribute("class");
2356   - }
2357   - function enqueueClassAttributeChange(el, oldValue) {
2358   - enqueueMutation(el, "attributes", {
2359   - name: "class",
2360   - namespace: null,
2361   - oldValue: oldValue
2362   - });
2363   - }
2364   - function invalidateClass(el) {
2365   - scope.invalidateRendererBasedOnAttribute(el, "class");
2366   - }
2367   - function changeClass(tokenList, method, args) {
2368   - var ownerElement = tokenList.ownerElement_;
2369   - if (ownerElement == null) {
2370   - return method.apply(tokenList, args);
2371   - }
2372   - var oldValue = getClass(ownerElement);
2373   - var retv = method.apply(tokenList, args);
2374   - if (getClass(ownerElement) !== oldValue) {
2375   - enqueueClassAttributeChange(ownerElement, oldValue);
2376   - invalidateClass(ownerElement);
2377   - }
2378   - return retv;
2379   - }
2380   - var oldAdd = DOMTokenList.prototype.add;
2381   - DOMTokenList.prototype.add = function() {
2382   - changeClass(this, oldAdd, arguments);
2383   - };
2384   - var oldRemove = DOMTokenList.prototype.remove;
2385   - DOMTokenList.prototype.remove = function() {
2386   - changeClass(this, oldRemove, arguments);
2387   - };
2388   - var oldToggle = DOMTokenList.prototype.toggle;
2389   - DOMTokenList.prototype.toggle = function() {
2390   - return changeClass(this, oldToggle, arguments);
2391   - };
2392   - })(window.ShadowDOMPolyfill);
2393   - (function(scope) {
2394   - "use strict";
2395   - var ChildNodeInterface = scope.ChildNodeInterface;
2396   - var GetElementsByInterface = scope.GetElementsByInterface;
2397   - var Node = scope.wrappers.Node;
2398   - var ParentNodeInterface = scope.ParentNodeInterface;
2399   - var SelectorsInterface = scope.SelectorsInterface;
2400   - var MatchesInterface = scope.MatchesInterface;
2401   - var addWrapNodeListMethod = scope.addWrapNodeListMethod;
2402   - var enqueueMutation = scope.enqueueMutation;
2403   - var mixin = scope.mixin;
2404   - var oneOf = scope.oneOf;
2405   - var registerWrapper = scope.registerWrapper;
2406   - var unsafeUnwrap = scope.unsafeUnwrap;
2407   - var wrappers = scope.wrappers;
2408   - var OriginalElement = window.Element;
2409   - var matchesNames = [ "matches", "mozMatchesSelector", "msMatchesSelector", "webkitMatchesSelector" ].filter(function(name) {
2410   - return OriginalElement.prototype[name];
2411   - });
2412   - var matchesName = matchesNames[0];
2413   - var originalMatches = OriginalElement.prototype[matchesName];
2414   - function invalidateRendererBasedOnAttribute(element, name) {
2415   - var p = element.parentNode;
2416   - if (!p || !p.shadowRoot) return;
2417   - var renderer = scope.getRendererForHost(p);
2418   - if (renderer.dependsOnAttribute(name)) renderer.invalidate();
2419   - }
2420   - function enqueAttributeChange(element, name, oldValue) {
2421   - enqueueMutation(element, "attributes", {
2422   - name: name,
2423   - namespace: null,
2424   - oldValue: oldValue
2425   - });
2426   - }
2427   - var classListTable = new WeakMap();
2428   - function Element(node) {
2429   - Node.call(this, node);
2430   - }
2431   - Element.prototype = Object.create(Node.prototype);
2432   - mixin(Element.prototype, {
2433   - createShadowRoot: function() {
2434   - var newShadowRoot = new wrappers.ShadowRoot(this);
2435   - unsafeUnwrap(this).polymerShadowRoot_ = newShadowRoot;
2436   - var renderer = scope.getRendererForHost(this);
2437   - renderer.invalidate();
2438   - return newShadowRoot;
2439   - },
2440   - get shadowRoot() {
2441   - return unsafeUnwrap(this).polymerShadowRoot_ || null;
2442   - },
2443   - setAttribute: function(name, value) {
2444   - var oldValue = unsafeUnwrap(this).getAttribute(name);
2445   - unsafeUnwrap(this).setAttribute(name, value);
2446   - enqueAttributeChange(this, name, oldValue);
2447   - invalidateRendererBasedOnAttribute(this, name);
2448   - },
2449   - removeAttribute: function(name) {
2450   - var oldValue = unsafeUnwrap(this).getAttribute(name);
2451   - unsafeUnwrap(this).removeAttribute(name);
2452   - enqueAttributeChange(this, name, oldValue);
2453   - invalidateRendererBasedOnAttribute(this, name);
2454   - },
2455   - get classList() {
2456   - var list = classListTable.get(this);
2457   - if (!list) {
2458   - list = unsafeUnwrap(this).classList;
2459   - if (!list) return;
2460   - list.ownerElement_ = this;
2461   - classListTable.set(this, list);
2462   - }
2463   - return list;
2464   - },
2465   - get className() {
2466   - return unsafeUnwrap(this).className;
2467   - },
2468   - set className(v) {
2469   - this.setAttribute("class", v);
2470   - },
2471   - get id() {
2472   - return unsafeUnwrap(this).id;
2473   - },
2474   - set id(v) {
2475   - this.setAttribute("id", v);
2476   - }
2477   - });
2478   - matchesNames.forEach(function(name) {
2479   - if (name !== "matches") {
2480   - Element.prototype[name] = function(selector) {
2481   - return this.matches(selector);
2482   - };
2483   - }
2484   - });
2485   - if (OriginalElement.prototype.webkitCreateShadowRoot) {
2486   - Element.prototype.webkitCreateShadowRoot = Element.prototype.createShadowRoot;
2487   - }
2488   - mixin(Element.prototype, ChildNodeInterface);
2489   - mixin(Element.prototype, GetElementsByInterface);
2490   - mixin(Element.prototype, ParentNodeInterface);
2491   - mixin(Element.prototype, SelectorsInterface);
2492   - mixin(Element.prototype, MatchesInterface);
2493   - registerWrapper(OriginalElement, Element, document.createElementNS(null, "x"));
2494   - scope.invalidateRendererBasedOnAttribute = invalidateRendererBasedOnAttribute;
2495   - scope.matchesNames = matchesNames;
2496   - scope.originalMatches = originalMatches;
2497   - scope.wrappers.Element = Element;
2498   - })(window.ShadowDOMPolyfill);
2499   - (function(scope) {
2500   - "use strict";
2501   - var Element = scope.wrappers.Element;
2502   - var defineGetter = scope.defineGetter;
2503   - var enqueueMutation = scope.enqueueMutation;
2504   - var mixin = scope.mixin;
2505   - var nodesWereAdded = scope.nodesWereAdded;
2506   - var nodesWereRemoved = scope.nodesWereRemoved;
2507   - var registerWrapper = scope.registerWrapper;
2508   - var snapshotNodeList = scope.snapshotNodeList;
2509   - var unsafeUnwrap = scope.unsafeUnwrap;
2510   - var unwrap = scope.unwrap;
2511   - var wrap = scope.wrap;
2512   - var wrappers = scope.wrappers;
2513   - var escapeAttrRegExp = /[&\u00A0"]/g;
2514   - var escapeDataRegExp = /[&\u00A0<>]/g;
2515   - function escapeReplace(c) {
2516   - switch (c) {
2517   - case "&":
2518   - return "&amp;";
2519   -
2520   - case "<":
2521   - return "&lt;";
2522   -
2523   - case ">":
2524   - return "&gt;";
2525   -
2526   - case '"':
2527   - return "&quot;";
2528   -
2529   - case "ย ":
2530   - return "&nbsp;";
2531   - }
2532   - }
2533   - function escapeAttr(s) {
2534   - return s.replace(escapeAttrRegExp, escapeReplace);
2535   - }
2536   - function escapeData(s) {
2537   - return s.replace(escapeDataRegExp, escapeReplace);
2538   - }
2539   - function makeSet(arr) {
2540   - var set = {};
2541   - for (var i = 0; i < arr.length; i++) {
2542   - set[arr[i]] = true;
2543   - }
2544   - return set;
2545   - }
2546   - var voidElements = makeSet([ "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr" ]);
2547   - var plaintextParents = makeSet([ "style", "script", "xmp", "iframe", "noembed", "noframes", "plaintext", "noscript" ]);
2548   - function getOuterHTML(node, parentNode) {
2549   - switch (node.nodeType) {
2550   - case Node.ELEMENT_NODE:
2551   - var tagName = node.tagName.toLowerCase();
2552   - var s = "<" + tagName;
2553   - var attrs = node.attributes;
2554   - for (var i = 0, attr; attr = attrs[i]; i++) {
2555   - s += " " + attr.name + '="' + escapeAttr(attr.value) + '"';
2556   - }
2557   - s += ">";
2558   - if (voidElements[tagName]) return s;
2559   - return s + getInnerHTML(node) + "</" + tagName + ">";
2560   -
2561   - case Node.TEXT_NODE:
2562   - var data = node.data;
2563   - if (parentNode && plaintextParents[parentNode.localName]) return data;
2564   - return escapeData(data);
2565   -
2566   - case Node.COMMENT_NODE:
2567   - return "<!--" + node.data + "-->";
2568   -
2569   - default:
2570   - console.error(node);
2571   - throw new Error("not implemented");
2572   - }
2573   - }
2574   - function getInnerHTML(node) {
2575   - if (node instanceof wrappers.HTMLTemplateElement) node = node.content;
2576   - var s = "";
2577   - for (var child = node.firstChild; child; child = child.nextSibling) {
2578   - s += getOuterHTML(child, node);
2579   - }
2580   - return s;
2581   - }
2582   - function setInnerHTML(node, value, opt_tagName) {
2583   - var tagName = opt_tagName || "div";
2584   - node.textContent = "";
2585   - var tempElement = unwrap(node.ownerDocument.createElement(tagName));
2586   - tempElement.innerHTML = value;
2587   - var firstChild;
2588   - while (firstChild = tempElement.firstChild) {
2589   - node.appendChild(wrap(firstChild));
2590   - }
2591   - }
2592   - var oldIe = /MSIE/.test(navigator.userAgent);
2593   - var OriginalHTMLElement = window.HTMLElement;
2594   - var OriginalHTMLTemplateElement = window.HTMLTemplateElement;
2595   - function HTMLElement(node) {
2596   - Element.call(this, node);
2597   - }
2598   - HTMLElement.prototype = Object.create(Element.prototype);
2599   - mixin(HTMLElement.prototype, {
2600   - get innerHTML() {
2601   - return getInnerHTML(this);
2602   - },
2603   - set innerHTML(value) {
2604   - if (oldIe && plaintextParents[this.localName]) {
2605   - this.textContent = value;
2606   - return;
2607   - }
2608   - var removedNodes = snapshotNodeList(this.childNodes);
2609   - if (this.invalidateShadowRenderer()) {
2610   - if (this instanceof wrappers.HTMLTemplateElement) setInnerHTML(this.content, value); else setInnerHTML(this, value, this.tagName);
2611   - } else if (!OriginalHTMLTemplateElement && this instanceof wrappers.HTMLTemplateElement) {
2612   - setInnerHTML(this.content, value);
2613   - } else {
2614   - unsafeUnwrap(this).innerHTML = value;
2615   - }
2616   - var addedNodes = snapshotNodeList(this.childNodes);
2617   - enqueueMutation(this, "childList", {
2618   - addedNodes: addedNodes,
2619   - removedNodes: removedNodes
2620   - });
2621   - nodesWereRemoved(removedNodes);
2622   - nodesWereAdded(addedNodes, this);
2623   - },
2624   - get outerHTML() {
2625   - return getOuterHTML(this, this.parentNode);
2626   - },
2627   - set outerHTML(value) {
2628   - var p = this.parentNode;
2629   - if (p) {
2630   - p.invalidateShadowRenderer();
2631   - var df = frag(p, value);
2632   - p.replaceChild(df, this);
2633   - }
2634   - },
2635   - insertAdjacentHTML: function(position, text) {
2636   - var contextElement, refNode;
2637   - switch (String(position).toLowerCase()) {
2638   - case "beforebegin":
2639   - contextElement = this.parentNode;
2640   - refNode = this;
2641   - break;
2642   -
2643   - case "afterend":
2644   - contextElement = this.parentNode;
2645   - refNode = this.nextSibling;
2646   - break;
2647   -
2648   - case "afterbegin":
2649   - contextElement = this;
2650   - refNode = this.firstChild;
2651   - break;
2652   -
2653   - case "beforeend":
2654   - contextElement = this;
2655   - refNode = null;
2656   - break;
2657   -
2658   - default:
2659   - return;
2660   - }
2661   - var df = frag(contextElement, text);
2662   - contextElement.insertBefore(df, refNode);
2663   - },
2664   - get hidden() {
2665   - return this.hasAttribute("hidden");
2666   - },
2667   - set hidden(v) {
2668   - if (v) {
2669   - this.setAttribute("hidden", "");
2670   - } else {
2671   - this.removeAttribute("hidden");
2672   - }
2673   - }
2674   - });
2675   - function frag(contextElement, html) {
2676   - var p = unwrap(contextElement.cloneNode(false));
2677   - p.innerHTML = html;
2678   - var df = unwrap(document.createDocumentFragment());
2679   - var c;
2680   - while (c = p.firstChild) {
2681   - df.appendChild(c);
2682   - }
2683   - return wrap(df);
2684   - }
2685   - function getter(name) {
2686   - return function() {
2687   - scope.renderAllPending();
2688   - return unsafeUnwrap(this)[name];
2689   - };
2690   - }
2691   - function getterRequiresRendering(name) {
2692   - defineGetter(HTMLElement, name, getter(name));
2693   - }
2694   - [ "clientHeight", "clientLeft", "clientTop", "clientWidth", "offsetHeight", "offsetLeft", "offsetTop", "offsetWidth", "scrollHeight", "scrollWidth" ].forEach(getterRequiresRendering);
2695   - function getterAndSetterRequiresRendering(name) {
2696   - Object.defineProperty(HTMLElement.prototype, name, {
2697   - get: getter(name),
2698   - set: function(v) {
2699   - scope.renderAllPending();
2700   - unsafeUnwrap(this)[name] = v;
2701   - },
2702   - configurable: true,
2703   - enumerable: true
2704   - });
2705   - }
2706   - [ "scrollLeft", "scrollTop" ].forEach(getterAndSetterRequiresRendering);
2707   - function methodRequiresRendering(name) {
2708   - Object.defineProperty(HTMLElement.prototype, name, {
2709   - value: function() {
2710   - scope.renderAllPending();
2711   - return unsafeUnwrap(this)[name].apply(unsafeUnwrap(this), arguments);
2712   - },
2713   - configurable: true,
2714   - enumerable: true
2715   - });
2716   - }
2717   - [ "getBoundingClientRect", "getClientRects", "scrollIntoView" ].forEach(methodRequiresRendering);
2718   - registerWrapper(OriginalHTMLElement, HTMLElement, document.createElement("b"));
2719   - scope.wrappers.HTMLElement = HTMLElement;
2720   - scope.getInnerHTML = getInnerHTML;
2721   - scope.setInnerHTML = setInnerHTML;
2722   - })(window.ShadowDOMPolyfill);
2723   - (function(scope) {
2724   - "use strict";
2725   - var HTMLElement = scope.wrappers.HTMLElement;
2726   - var mixin = scope.mixin;
2727   - var registerWrapper = scope.registerWrapper;
2728   - var unsafeUnwrap = scope.unsafeUnwrap;
2729   - var wrap = scope.wrap;
2730   - var OriginalHTMLCanvasElement = window.HTMLCanvasElement;
2731   - function HTMLCanvasElement(node) {
2732   - HTMLElement.call(this, node);
2733   - }
2734   - HTMLCanvasElement.prototype = Object.create(HTMLElement.prototype);
2735   - mixin(HTMLCanvasElement.prototype, {
2736   - getContext: function() {
2737   - var context = unsafeUnwrap(this).getContext.apply(unsafeUnwrap(this), arguments);
2738   - return context && wrap(context);
2739   - }
2740   - });
2741   - registerWrapper(OriginalHTMLCanvasElement, HTMLCanvasElement, document.createElement("canvas"));
2742   - scope.wrappers.HTMLCanvasElement = HTMLCanvasElement;
2743   - })(window.ShadowDOMPolyfill);
2744   - (function(scope) {
2745   - "use strict";
2746   - var HTMLElement = scope.wrappers.HTMLElement;
2747   - var mixin = scope.mixin;
2748   - var registerWrapper = scope.registerWrapper;
2749   - var OriginalHTMLContentElement = window.HTMLContentElement;
2750   - function HTMLContentElement(node) {
2751   - HTMLElement.call(this, node);
2752   - }
2753   - HTMLContentElement.prototype = Object.create(HTMLElement.prototype);
2754   - mixin(HTMLContentElement.prototype, {
2755   - constructor: HTMLContentElement,
2756   - get select() {
2757   - return this.getAttribute("select");
2758   - },
2759   - set select(value) {
2760   - this.setAttribute("select", value);
2761   - },
2762   - setAttribute: function(n, v) {
2763   - HTMLElement.prototype.setAttribute.call(this, n, v);
2764   - if (String(n).toLowerCase() === "select") this.invalidateShadowRenderer(true);
2765   - }
2766   - });
2767   - if (OriginalHTMLContentElement) registerWrapper(OriginalHTMLContentElement, HTMLContentElement);
2768   - scope.wrappers.HTMLContentElement = HTMLContentElement;
2769   - })(window.ShadowDOMPolyfill);
2770   - (function(scope) {
2771   - "use strict";
2772   - var HTMLElement = scope.wrappers.HTMLElement;
2773   - var mixin = scope.mixin;
2774   - var registerWrapper = scope.registerWrapper;
2775   - var wrapHTMLCollection = scope.wrapHTMLCollection;
2776   - var unwrap = scope.unwrap;
2777   - var OriginalHTMLFormElement = window.HTMLFormElement;
2778   - function HTMLFormElement(node) {
2779   - HTMLElement.call(this, node);
2780   - }
2781   - HTMLFormElement.prototype = Object.create(HTMLElement.prototype);
2782   - mixin(HTMLFormElement.prototype, {
2783   - get elements() {
2784   - return wrapHTMLCollection(unwrap(this).elements);
2785   - }
2786   - });
2787   - registerWrapper(OriginalHTMLFormElement, HTMLFormElement, document.createElement("form"));
2788   - scope.wrappers.HTMLFormElement = HTMLFormElement;
2789   - })(window.ShadowDOMPolyfill);
2790   - (function(scope) {
2791   - "use strict";
2792   - var HTMLElement = scope.wrappers.HTMLElement;
2793   - var registerWrapper = scope.registerWrapper;
2794   - var unwrap = scope.unwrap;
2795   - var rewrap = scope.rewrap;
2796   - var OriginalHTMLImageElement = window.HTMLImageElement;
2797   - function HTMLImageElement(node) {
2798   - HTMLElement.call(this, node);
2799   - }
2800   - HTMLImageElement.prototype = Object.create(HTMLElement.prototype);
2801   - registerWrapper(OriginalHTMLImageElement, HTMLImageElement, document.createElement("img"));
2802   - function Image(width, height) {
2803   - if (!(this instanceof Image)) {
2804   - throw new TypeError("DOM object constructor cannot be called as a function.");
2805   - }
2806   - var node = unwrap(document.createElement("img"));
2807   - HTMLElement.call(this, node);
2808   - rewrap(node, this);
2809   - if (width !== undefined) node.width = width;
2810   - if (height !== undefined) node.height = height;
2811   - }
2812   - Image.prototype = HTMLImageElement.prototype;
2813   - scope.wrappers.HTMLImageElement = HTMLImageElement;
2814   - scope.wrappers.Image = Image;
2815   - })(window.ShadowDOMPolyfill);
2816   - (function(scope) {
2817   - "use strict";
2818   - var HTMLElement = scope.wrappers.HTMLElement;
2819   - var mixin = scope.mixin;
2820   - var NodeList = scope.wrappers.NodeList;
2821   - var registerWrapper = scope.registerWrapper;
2822   - var OriginalHTMLShadowElement = window.HTMLShadowElement;
2823   - function HTMLShadowElement(node) {
2824   - HTMLElement.call(this, node);
2825   - }
2826   - HTMLShadowElement.prototype = Object.create(HTMLElement.prototype);
2827   - HTMLShadowElement.prototype.constructor = HTMLShadowElement;
2828   - if (OriginalHTMLShadowElement) registerWrapper(OriginalHTMLShadowElement, HTMLShadowElement);
2829   - scope.wrappers.HTMLShadowElement = HTMLShadowElement;
2830   - })(window.ShadowDOMPolyfill);
2831   - (function(scope) {
2832   - "use strict";
2833   - var HTMLElement = scope.wrappers.HTMLElement;
2834   - var mixin = scope.mixin;
2835   - var registerWrapper = scope.registerWrapper;
2836   - var unsafeUnwrap = scope.unsafeUnwrap;
2837   - var unwrap = scope.unwrap;
2838   - var wrap = scope.wrap;
2839   - var contentTable = new WeakMap();
2840   - var templateContentsOwnerTable = new WeakMap();
2841   - function getTemplateContentsOwner(doc) {
2842   - if (!doc.defaultView) return doc;
2843   - var d = templateContentsOwnerTable.get(doc);
2844   - if (!d) {
2845   - d = doc.implementation.createHTMLDocument("");
2846   - while (d.lastChild) {
2847   - d.removeChild(d.lastChild);
2848   - }
2849   - templateContentsOwnerTable.set(doc, d);
2850   - }
2851   - return d;
2852   - }
2853   - function extractContent(templateElement) {
2854   - var doc = getTemplateContentsOwner(templateElement.ownerDocument);
2855   - var df = unwrap(doc.createDocumentFragment());
2856   - var child;
2857   - while (child = templateElement.firstChild) {
2858   - df.appendChild(child);
2859   - }
2860   - return df;
2861   - }
2862   - var OriginalHTMLTemplateElement = window.HTMLTemplateElement;
2863   - function HTMLTemplateElement(node) {
2864   - HTMLElement.call(this, node);
2865   - if (!OriginalHTMLTemplateElement) {
2866   - var content = extractContent(node);
2867   - contentTable.set(this, wrap(content));
2868   - }
2869   - }
2870   - HTMLTemplateElement.prototype = Object.create(HTMLElement.prototype);
2871   - mixin(HTMLTemplateElement.prototype, {
2872   - constructor: HTMLTemplateElement,
2873   - get content() {
2874   - if (OriginalHTMLTemplateElement) return wrap(unsafeUnwrap(this).content);
2875   - return contentTable.get(this);
2876   - }
2877   - });
2878   - if (OriginalHTMLTemplateElement) registerWrapper(OriginalHTMLTemplateElement, HTMLTemplateElement);
2879   - scope.wrappers.HTMLTemplateElement = HTMLTemplateElement;
2880   - })(window.ShadowDOMPolyfill);
2881   - (function(scope) {
2882   - "use strict";
2883   - var HTMLElement = scope.wrappers.HTMLElement;
2884   - var registerWrapper = scope.registerWrapper;
2885   - var OriginalHTMLMediaElement = window.HTMLMediaElement;
2886   - if (!OriginalHTMLMediaElement) return;
2887   - function HTMLMediaElement(node) {
2888   - HTMLElement.call(this, node);
2889   - }
2890   - HTMLMediaElement.prototype = Object.create(HTMLElement.prototype);
2891   - registerWrapper(OriginalHTMLMediaElement, HTMLMediaElement, document.createElement("audio"));
2892   - scope.wrappers.HTMLMediaElement = HTMLMediaElement;
2893   - })(window.ShadowDOMPolyfill);
2894   - (function(scope) {
2895   - "use strict";
2896   - var HTMLMediaElement = scope.wrappers.HTMLMediaElement;
2897   - var registerWrapper = scope.registerWrapper;
2898   - var unwrap = scope.unwrap;
2899   - var rewrap = scope.rewrap;
2900   - var OriginalHTMLAudioElement = window.HTMLAudioElement;
2901   - if (!OriginalHTMLAudioElement) return;
2902   - function HTMLAudioElement(node) {
2903   - HTMLMediaElement.call(this, node);
2904   - }
2905   - HTMLAudioElement.prototype = Object.create(HTMLMediaElement.prototype);
2906   - registerWrapper(OriginalHTMLAudioElement, HTMLAudioElement, document.createElement("audio"));
2907   - function Audio(src) {
2908   - if (!(this instanceof Audio)) {
2909   - throw new TypeError("DOM object constructor cannot be called as a function.");
2910   - }
2911   - var node = unwrap(document.createElement("audio"));
2912   - HTMLMediaElement.call(this, node);
2913   - rewrap(node, this);
2914   - node.setAttribute("preload", "auto");
2915   - if (src !== undefined) node.setAttribute("src", src);
2916   - }
2917   - Audio.prototype = HTMLAudioElement.prototype;
2918   - scope.wrappers.HTMLAudioElement = HTMLAudioElement;
2919   - scope.wrappers.Audio = Audio;
2920   - })(window.ShadowDOMPolyfill);
2921   - (function(scope) {
2922   - "use strict";
2923   - var HTMLElement = scope.wrappers.HTMLElement;
2924   - var mixin = scope.mixin;
2925   - var registerWrapper = scope.registerWrapper;
2926   - var rewrap = scope.rewrap;
2927   - var unwrap = scope.unwrap;
2928   - var wrap = scope.wrap;
2929   - var OriginalHTMLOptionElement = window.HTMLOptionElement;
2930   - function trimText(s) {
2931   - return s.replace(/\s+/g, " ").trim();
2932   - }
2933   - function HTMLOptionElement(node) {
2934   - HTMLElement.call(this, node);
2935   - }
2936   - HTMLOptionElement.prototype = Object.create(HTMLElement.prototype);
2937   - mixin(HTMLOptionElement.prototype, {
2938   - get text() {
2939   - return trimText(this.textContent);
2940   - },
2941   - set text(value) {
2942   - this.textContent = trimText(String(value));
2943   - },
2944   - get form() {
2945   - return wrap(unwrap(this).form);
2946   - }
2947   - });
2948   - registerWrapper(OriginalHTMLOptionElement, HTMLOptionElement, document.createElement("option"));
2949   - function Option(text, value, defaultSelected, selected) {
2950   - if (!(this instanceof Option)) {
2951   - throw new TypeError("DOM object constructor cannot be called as a function.");
2952   - }
2953   - var node = unwrap(document.createElement("option"));
2954   - HTMLElement.call(this, node);
2955   - rewrap(node, this);
2956   - if (text !== undefined) node.text = text;
2957   - if (value !== undefined) node.setAttribute("value", value);
2958   - if (defaultSelected === true) node.setAttribute("selected", "");
2959   - node.selected = selected === true;
2960   - }
2961   - Option.prototype = HTMLOptionElement.prototype;
2962   - scope.wrappers.HTMLOptionElement = HTMLOptionElement;
2963   - scope.wrappers.Option = Option;
2964   - })(window.ShadowDOMPolyfill);
2965   - (function(scope) {
2966   - "use strict";
2967   - var HTMLElement = scope.wrappers.HTMLElement;
2968   - var mixin = scope.mixin;
2969   - var registerWrapper = scope.registerWrapper;
2970   - var unwrap = scope.unwrap;
2971   - var wrap = scope.wrap;
2972   - var OriginalHTMLSelectElement = window.HTMLSelectElement;
2973   - function HTMLSelectElement(node) {
2974   - HTMLElement.call(this, node);
2975   - }
2976   - HTMLSelectElement.prototype = Object.create(HTMLElement.prototype);
2977   - mixin(HTMLSelectElement.prototype, {
2978   - add: function(element, before) {
2979   - if (typeof before === "object") before = unwrap(before);
2980   - unwrap(this).add(unwrap(element), before);
2981   - },
2982   - remove: function(indexOrNode) {
2983   - if (indexOrNode === undefined) {
2984   - HTMLElement.prototype.remove.call(this);
2985   - return;
2986   - }
2987   - if (typeof indexOrNode === "object") indexOrNode = unwrap(indexOrNode);
2988   - unwrap(this).remove(indexOrNode);
2989   - },
2990   - get form() {
2991   - return wrap(unwrap(this).form);
2992   - }
2993   - });
2994   - registerWrapper(OriginalHTMLSelectElement, HTMLSelectElement, document.createElement("select"));
2995   - scope.wrappers.HTMLSelectElement = HTMLSelectElement;
2996   - })(window.ShadowDOMPolyfill);
2997   - (function(scope) {
2998   - "use strict";
2999   - var HTMLElement = scope.wrappers.HTMLElement;
3000   - var mixin = scope.mixin;
3001   - var registerWrapper = scope.registerWrapper;
3002   - var unwrap = scope.unwrap;
3003   - var wrap = scope.wrap;
3004   - var wrapHTMLCollection = scope.wrapHTMLCollection;
3005   - var OriginalHTMLTableElement = window.HTMLTableElement;
3006   - function HTMLTableElement(node) {
3007   - HTMLElement.call(this, node);
3008   - }
3009   - HTMLTableElement.prototype = Object.create(HTMLElement.prototype);
3010   - mixin(HTMLTableElement.prototype, {
3011   - get caption() {
3012   - return wrap(unwrap(this).caption);
3013   - },
3014   - createCaption: function() {
3015   - return wrap(unwrap(this).createCaption());
3016   - },
3017   - get tHead() {
3018   - return wrap(unwrap(this).tHead);
3019   - },
3020   - createTHead: function() {
3021   - return wrap(unwrap(this).createTHead());
3022   - },
3023   - createTFoot: function() {
3024   - return wrap(unwrap(this).createTFoot());
3025   - },
3026   - get tFoot() {
3027   - return wrap(unwrap(this).tFoot);
3028   - },
3029   - get tBodies() {
3030   - return wrapHTMLCollection(unwrap(this).tBodies);
3031   - },
3032   - createTBody: function() {
3033   - return wrap(unwrap(this).createTBody());
3034   - },
3035   - get rows() {
3036   - return wrapHTMLCollection(unwrap(this).rows);
3037   - },
3038   - insertRow: function(index) {
3039   - return wrap(unwrap(this).insertRow(index));
3040   - }
3041   - });
3042   - registerWrapper(OriginalHTMLTableElement, HTMLTableElement, document.createElement("table"));
3043   - scope.wrappers.HTMLTableElement = HTMLTableElement;
3044   - })(window.ShadowDOMPolyfill);
3045   - (function(scope) {
3046   - "use strict";
3047   - var HTMLElement = scope.wrappers.HTMLElement;
3048   - var mixin = scope.mixin;
3049   - var registerWrapper = scope.registerWrapper;
3050   - var wrapHTMLCollection = scope.wrapHTMLCollection;
3051   - var unwrap = scope.unwrap;
3052   - var wrap = scope.wrap;
3053   - var OriginalHTMLTableSectionElement = window.HTMLTableSectionElement;
3054   - function HTMLTableSectionElement(node) {
3055   - HTMLElement.call(this, node);
3056   - }
3057   - HTMLTableSectionElement.prototype = Object.create(HTMLElement.prototype);
3058   - mixin(HTMLTableSectionElement.prototype, {
3059   - constructor: HTMLTableSectionElement,
3060   - get rows() {
3061   - return wrapHTMLCollection(unwrap(this).rows);
3062   - },
3063   - insertRow: function(index) {
3064   - return wrap(unwrap(this).insertRow(index));
3065   - }
3066   - });
3067   - registerWrapper(OriginalHTMLTableSectionElement, HTMLTableSectionElement, document.createElement("thead"));
3068   - scope.wrappers.HTMLTableSectionElement = HTMLTableSectionElement;
3069   - })(window.ShadowDOMPolyfill);
3070   - (function(scope) {
3071   - "use strict";
3072   - var HTMLElement = scope.wrappers.HTMLElement;
3073   - var mixin = scope.mixin;
3074   - var registerWrapper = scope.registerWrapper;
3075   - var wrapHTMLCollection = scope.wrapHTMLCollection;
3076   - var unwrap = scope.unwrap;
3077   - var wrap = scope.wrap;
3078   - var OriginalHTMLTableRowElement = window.HTMLTableRowElement;
3079   - function HTMLTableRowElement(node) {
3080   - HTMLElement.call(this, node);
3081   - }
3082   - HTMLTableRowElement.prototype = Object.create(HTMLElement.prototype);
3083   - mixin(HTMLTableRowElement.prototype, {
3084   - get cells() {
3085   - return wrapHTMLCollection(unwrap(this).cells);
3086   - },
3087   - insertCell: function(index) {
3088   - return wrap(unwrap(this).insertCell(index));
3089   - }
3090   - });
3091   - registerWrapper(OriginalHTMLTableRowElement, HTMLTableRowElement, document.createElement("tr"));
3092   - scope.wrappers.HTMLTableRowElement = HTMLTableRowElement;
3093   - })(window.ShadowDOMPolyfill);
3094   - (function(scope) {
3095   - "use strict";
3096   - var HTMLContentElement = scope.wrappers.HTMLContentElement;
3097   - var HTMLElement = scope.wrappers.HTMLElement;
3098   - var HTMLShadowElement = scope.wrappers.HTMLShadowElement;
3099   - var HTMLTemplateElement = scope.wrappers.HTMLTemplateElement;
3100   - var mixin = scope.mixin;
3101   - var registerWrapper = scope.registerWrapper;
3102   - var OriginalHTMLUnknownElement = window.HTMLUnknownElement;
3103   - function HTMLUnknownElement(node) {
3104   - switch (node.localName) {
3105   - case "content":
3106   - return new HTMLContentElement(node);
3107   -
3108   - case "shadow":
3109   - return new HTMLShadowElement(node);
3110   -
3111   - case "template":
3112   - return new HTMLTemplateElement(node);
3113   - }
3114   - HTMLElement.call(this, node);
3115   - }
3116   - HTMLUnknownElement.prototype = Object.create(HTMLElement.prototype);
3117   - registerWrapper(OriginalHTMLUnknownElement, HTMLUnknownElement);
3118   - scope.wrappers.HTMLUnknownElement = HTMLUnknownElement;
3119   - })(window.ShadowDOMPolyfill);
3120   - (function(scope) {
3121   - "use strict";
3122   - var Element = scope.wrappers.Element;
3123   - var HTMLElement = scope.wrappers.HTMLElement;
3124   - var registerObject = scope.registerObject;
3125   - var defineWrapGetter = scope.defineWrapGetter;
3126   - var SVG_NS = "http://www.w3.org/2000/svg";
3127   - var svgTitleElement = document.createElementNS(SVG_NS, "title");
3128   - var SVGTitleElement = registerObject(svgTitleElement);
3129   - var SVGElement = Object.getPrototypeOf(SVGTitleElement.prototype).constructor;
3130   - if (!("classList" in svgTitleElement)) {
3131   - var descr = Object.getOwnPropertyDescriptor(Element.prototype, "classList");
3132   - Object.defineProperty(HTMLElement.prototype, "classList", descr);
3133   - delete Element.prototype.classList;
3134   - }
3135   - defineWrapGetter(SVGElement, "ownerSVGElement");
3136   - scope.wrappers.SVGElement = SVGElement;
3137   - })(window.ShadowDOMPolyfill);
3138   - (function(scope) {
3139   - "use strict";
3140   - var mixin = scope.mixin;
3141   - var registerWrapper = scope.registerWrapper;
3142   - var unwrap = scope.unwrap;
3143   - var wrap = scope.wrap;
3144   - var OriginalSVGUseElement = window.SVGUseElement;
3145   - var SVG_NS = "http://www.w3.org/2000/svg";
3146   - var gWrapper = wrap(document.createElementNS(SVG_NS, "g"));
3147   - var useElement = document.createElementNS(SVG_NS, "use");
3148   - var SVGGElement = gWrapper.constructor;
3149   - var parentInterfacePrototype = Object.getPrototypeOf(SVGGElement.prototype);
3150   - var parentInterface = parentInterfacePrototype.constructor;
3151   - function SVGUseElement(impl) {
3152   - parentInterface.call(this, impl);
3153   - }
3154   - SVGUseElement.prototype = Object.create(parentInterfacePrototype);
3155   - if ("instanceRoot" in useElement) {
3156   - mixin(SVGUseElement.prototype, {
3157   - get instanceRoot() {
3158   - return wrap(unwrap(this).instanceRoot);
3159   - },
3160   - get animatedInstanceRoot() {
3161   - return wrap(unwrap(this).animatedInstanceRoot);
3162   - }
3163   - });
3164   - }
3165   - registerWrapper(OriginalSVGUseElement, SVGUseElement, useElement);
3166   - scope.wrappers.SVGUseElement = SVGUseElement;
3167   - })(window.ShadowDOMPolyfill);
3168   - (function(scope) {
3169   - "use strict";
3170   - var EventTarget = scope.wrappers.EventTarget;
3171   - var mixin = scope.mixin;
3172   - var registerWrapper = scope.registerWrapper;
3173   - var unsafeUnwrap = scope.unsafeUnwrap;
3174   - var wrap = scope.wrap;
3175   - var OriginalSVGElementInstance = window.SVGElementInstance;
3176   - if (!OriginalSVGElementInstance) return;
3177   - function SVGElementInstance(impl) {
3178   - EventTarget.call(this, impl);
3179   - }
3180   - SVGElementInstance.prototype = Object.create(EventTarget.prototype);
3181   - mixin(SVGElementInstance.prototype, {
3182   - get correspondingElement() {
3183   - return wrap(unsafeUnwrap(this).correspondingElement);
3184   - },
3185   - get correspondingUseElement() {
3186   - return wrap(unsafeUnwrap(this).correspondingUseElement);
3187   - },
3188   - get parentNode() {
3189   - return wrap(unsafeUnwrap(this).parentNode);
3190   - },
3191   - get childNodes() {
3192   - throw new Error("Not implemented");
3193   - },
3194   - get firstChild() {
3195   - return wrap(unsafeUnwrap(this).firstChild);
3196   - },
3197   - get lastChild() {
3198   - return wrap(unsafeUnwrap(this).lastChild);
3199   - },
3200   - get previousSibling() {
3201   - return wrap(unsafeUnwrap(this).previousSibling);
3202   - },
3203   - get nextSibling() {
3204   - return wrap(unsafeUnwrap(this).nextSibling);
3205   - }
3206   - });
3207   - registerWrapper(OriginalSVGElementInstance, SVGElementInstance);
3208   - scope.wrappers.SVGElementInstance = SVGElementInstance;
3209   - })(window.ShadowDOMPolyfill);
3210   - (function(scope) {
3211   - "use strict";
3212   - var mixin = scope.mixin;
3213   - var registerWrapper = scope.registerWrapper;
3214   - var setWrapper = scope.setWrapper;
3215   - var unsafeUnwrap = scope.unsafeUnwrap;
3216   - var unwrap = scope.unwrap;
3217   - var unwrapIfNeeded = scope.unwrapIfNeeded;
3218   - var wrap = scope.wrap;
3219   - var OriginalCanvasRenderingContext2D = window.CanvasRenderingContext2D;
3220   - function CanvasRenderingContext2D(impl) {
3221   - setWrapper(impl, this);
3222   - }
3223   - mixin(CanvasRenderingContext2D.prototype, {
3224   - get canvas() {
3225   - return wrap(unsafeUnwrap(this).canvas);
3226   - },
3227   - drawImage: function() {
3228   - arguments[0] = unwrapIfNeeded(arguments[0]);
3229   - unsafeUnwrap(this).drawImage.apply(unsafeUnwrap(this), arguments);
3230   - },
3231   - createPattern: function() {
3232   - arguments[0] = unwrap(arguments[0]);
3233   - return unsafeUnwrap(this).createPattern.apply(unsafeUnwrap(this), arguments);
3234   - }
3235   - });
3236   - registerWrapper(OriginalCanvasRenderingContext2D, CanvasRenderingContext2D, document.createElement("canvas").getContext("2d"));
3237   - scope.wrappers.CanvasRenderingContext2D = CanvasRenderingContext2D;
3238   - })(window.ShadowDOMPolyfill);
3239   - (function(scope) {
3240   - "use strict";
3241   - var mixin = scope.mixin;
3242   - var registerWrapper = scope.registerWrapper;
3243   - var setWrapper = scope.setWrapper;
3244   - var unsafeUnwrap = scope.unsafeUnwrap;
3245   - var unwrapIfNeeded = scope.unwrapIfNeeded;
3246   - var wrap = scope.wrap;
3247   - var OriginalWebGLRenderingContext = window.WebGLRenderingContext;
3248   - if (!OriginalWebGLRenderingContext) return;
3249   - function WebGLRenderingContext(impl) {
3250   - setWrapper(impl, this);
3251   - }
3252   - mixin(WebGLRenderingContext.prototype, {
3253   - get canvas() {
3254   - return wrap(unsafeUnwrap(this).canvas);
3255   - },
3256   - texImage2D: function() {
3257   - arguments[5] = unwrapIfNeeded(arguments[5]);
3258   - unsafeUnwrap(this).texImage2D.apply(unsafeUnwrap(this), arguments);
3259   - },
3260   - texSubImage2D: function() {
3261   - arguments[6] = unwrapIfNeeded(arguments[6]);
3262   - unsafeUnwrap(this).texSubImage2D.apply(unsafeUnwrap(this), arguments);
3263   - }
3264   - });
3265   - var instanceProperties = /WebKit/.test(navigator.userAgent) ? {
3266   - drawingBufferHeight: null,
3267   - drawingBufferWidth: null
3268   - } : {};
3269   - registerWrapper(OriginalWebGLRenderingContext, WebGLRenderingContext, instanceProperties);
3270   - scope.wrappers.WebGLRenderingContext = WebGLRenderingContext;
3271   - })(window.ShadowDOMPolyfill);
3272   - (function(scope) {
3273   - "use strict";
3274   - var registerWrapper = scope.registerWrapper;
3275   - var setWrapper = scope.setWrapper;
3276   - var unsafeUnwrap = scope.unsafeUnwrap;
3277   - var unwrap = scope.unwrap;
3278   - var unwrapIfNeeded = scope.unwrapIfNeeded;
3279   - var wrap = scope.wrap;
3280   - var OriginalRange = window.Range;
3281   - function Range(impl) {
3282   - setWrapper(impl, this);
3283   - }
3284   - Range.prototype = {
3285   - get startContainer() {
3286   - return wrap(unsafeUnwrap(this).startContainer);
3287   - },
3288   - get endContainer() {
3289   - return wrap(unsafeUnwrap(this).endContainer);
3290   - },
3291   - get commonAncestorContainer() {
3292   - return wrap(unsafeUnwrap(this).commonAncestorContainer);
3293   - },
3294   - setStart: function(refNode, offset) {
3295   - unsafeUnwrap(this).setStart(unwrapIfNeeded(refNode), offset);
3296   - },
3297   - setEnd: function(refNode, offset) {
3298   - unsafeUnwrap(this).setEnd(unwrapIfNeeded(refNode), offset);
3299   - },
3300   - setStartBefore: function(refNode) {
3301   - unsafeUnwrap(this).setStartBefore(unwrapIfNeeded(refNode));
3302   - },
3303   - setStartAfter: function(refNode) {
3304   - unsafeUnwrap(this).setStartAfter(unwrapIfNeeded(refNode));
3305   - },
3306   - setEndBefore: function(refNode) {
3307   - unsafeUnwrap(this).setEndBefore(unwrapIfNeeded(refNode));
3308   - },
3309   - setEndAfter: function(refNode) {
3310   - unsafeUnwrap(this).setEndAfter(unwrapIfNeeded(refNode));
3311   - },
3312   - selectNode: function(refNode) {
3313   - unsafeUnwrap(this).selectNode(unwrapIfNeeded(refNode));
3314   - },
3315   - selectNodeContents: function(refNode) {
3316   - unsafeUnwrap(this).selectNodeContents(unwrapIfNeeded(refNode));
3317   - },
3318   - compareBoundaryPoints: function(how, sourceRange) {
3319   - return unsafeUnwrap(this).compareBoundaryPoints(how, unwrap(sourceRange));
3320   - },
3321   - extractContents: function() {
3322   - return wrap(unsafeUnwrap(this).extractContents());
3323   - },
3324   - cloneContents: function() {
3325   - return wrap(unsafeUnwrap(this).cloneContents());
3326   - },
3327   - insertNode: function(node) {
3328   - unsafeUnwrap(this).insertNode(unwrapIfNeeded(node));
3329   - },
3330   - surroundContents: function(newParent) {
3331   - unsafeUnwrap(this).surroundContents(unwrapIfNeeded(newParent));
3332   - },
3333   - cloneRange: function() {
3334   - return wrap(unsafeUnwrap(this).cloneRange());
3335   - },
3336   - isPointInRange: function(node, offset) {
3337   - return unsafeUnwrap(this).isPointInRange(unwrapIfNeeded(node), offset);
3338   - },
3339   - comparePoint: function(node, offset) {
3340   - return unsafeUnwrap(this).comparePoint(unwrapIfNeeded(node), offset);
3341   - },
3342   - intersectsNode: function(node) {
3343   - return unsafeUnwrap(this).intersectsNode(unwrapIfNeeded(node));
3344   - },
3345   - toString: function() {
3346   - return unsafeUnwrap(this).toString();
3347   - }
3348   - };
3349   - if (OriginalRange.prototype.createContextualFragment) {
3350   - Range.prototype.createContextualFragment = function(html) {
3351   - return wrap(unsafeUnwrap(this).createContextualFragment(html));
3352   - };
3353   - }
3354   - registerWrapper(window.Range, Range, document.createRange());
3355   - scope.wrappers.Range = Range;
3356   - })(window.ShadowDOMPolyfill);
3357   - (function(scope) {
3358   - "use strict";
3359   - var GetElementsByInterface = scope.GetElementsByInterface;
3360   - var ParentNodeInterface = scope.ParentNodeInterface;
3361   - var SelectorsInterface = scope.SelectorsInterface;
3362   - var mixin = scope.mixin;
3363   - var registerObject = scope.registerObject;
3364   - var DocumentFragment = registerObject(document.createDocumentFragment());
3365   - mixin(DocumentFragment.prototype, ParentNodeInterface);
3366   - mixin(DocumentFragment.prototype, SelectorsInterface);
3367   - mixin(DocumentFragment.prototype, GetElementsByInterface);
3368   - var Comment = registerObject(document.createComment(""));
3369   - scope.wrappers.Comment = Comment;
3370   - scope.wrappers.DocumentFragment = DocumentFragment;
3371   - })(window.ShadowDOMPolyfill);
3372   - (function(scope) {
3373   - "use strict";
3374   - var DocumentFragment = scope.wrappers.DocumentFragment;
3375   - var TreeScope = scope.TreeScope;
3376   - var elementFromPoint = scope.elementFromPoint;
3377   - var getInnerHTML = scope.getInnerHTML;
3378   - var getTreeScope = scope.getTreeScope;
3379   - var mixin = scope.mixin;
3380   - var rewrap = scope.rewrap;
3381   - var setInnerHTML = scope.setInnerHTML;
3382   - var unsafeUnwrap = scope.unsafeUnwrap;
3383   - var unwrap = scope.unwrap;
3384   - var shadowHostTable = new WeakMap();
3385   - var nextOlderShadowTreeTable = new WeakMap();
3386   - var spaceCharRe = /[ \t\n\r\f]/;
3387   - function ShadowRoot(hostWrapper) {
3388   - var node = unwrap(unsafeUnwrap(hostWrapper).ownerDocument.createDocumentFragment());
3389   - DocumentFragment.call(this, node);
3390   - rewrap(node, this);
3391   - var oldShadowRoot = hostWrapper.shadowRoot;
3392   - nextOlderShadowTreeTable.set(this, oldShadowRoot);
3393   - this.treeScope_ = new TreeScope(this, getTreeScope(oldShadowRoot || hostWrapper));
3394   - shadowHostTable.set(this, hostWrapper);
3395   - }
3396   - ShadowRoot.prototype = Object.create(DocumentFragment.prototype);
3397   - mixin(ShadowRoot.prototype, {
3398   - constructor: ShadowRoot,
3399   - get innerHTML() {
3400   - return getInnerHTML(this);
3401   - },
3402   - set innerHTML(value) {
3403   - setInnerHTML(this, value);
3404   - this.invalidateShadowRenderer();
3405   - },
3406   - get olderShadowRoot() {
3407   - return nextOlderShadowTreeTable.get(this) || null;
3408   - },
3409   - get host() {
3410   - return shadowHostTable.get(this) || null;
3411   - },
3412   - invalidateShadowRenderer: function() {
3413   - return shadowHostTable.get(this).invalidateShadowRenderer();
3414   - },
3415   - elementFromPoint: function(x, y) {
3416   - return elementFromPoint(this, this.ownerDocument, x, y);
3417   - },
3418   - getElementById: function(id) {
3419   - if (spaceCharRe.test(id)) return null;
3420   - return this.querySelector('[id="' + id + '"]');
3421   - }
3422   - });
3423   - scope.wrappers.ShadowRoot = ShadowRoot;
3424   - })(window.ShadowDOMPolyfill);
3425   - (function(scope) {
3426   - "use strict";
3427   - var Element = scope.wrappers.Element;
3428   - var HTMLContentElement = scope.wrappers.HTMLContentElement;
3429   - var HTMLShadowElement = scope.wrappers.HTMLShadowElement;
3430   - var Node = scope.wrappers.Node;
3431   - var ShadowRoot = scope.wrappers.ShadowRoot;
3432   - var assert = scope.assert;
3433   - var getTreeScope = scope.getTreeScope;
3434   - var mixin = scope.mixin;
3435   - var oneOf = scope.oneOf;
3436   - var unsafeUnwrap = scope.unsafeUnwrap;
3437   - var unwrap = scope.unwrap;
3438   - var wrap = scope.wrap;
3439   - var ArraySplice = scope.ArraySplice;
3440   - function updateWrapperUpAndSideways(wrapper) {
3441   - wrapper.previousSibling_ = wrapper.previousSibling;
3442   - wrapper.nextSibling_ = wrapper.nextSibling;
3443   - wrapper.parentNode_ = wrapper.parentNode;
3444   - }
3445   - function updateWrapperDown(wrapper) {
3446   - wrapper.firstChild_ = wrapper.firstChild;
3447   - wrapper.lastChild_ = wrapper.lastChild;
3448   - }
3449   - function updateAllChildNodes(parentNodeWrapper) {
3450   - assert(parentNodeWrapper instanceof Node);
3451   - for (var childWrapper = parentNodeWrapper.firstChild; childWrapper; childWrapper = childWrapper.nextSibling) {
3452   - updateWrapperUpAndSideways(childWrapper);
3453   - }
3454   - updateWrapperDown(parentNodeWrapper);
3455   - }
3456   - function insertBefore(parentNodeWrapper, newChildWrapper, refChildWrapper) {
3457   - var parentNode = unwrap(parentNodeWrapper);
3458   - var newChild = unwrap(newChildWrapper);
3459   - var refChild = refChildWrapper ? unwrap(refChildWrapper) : null;
3460   - remove(newChildWrapper);
3461   - updateWrapperUpAndSideways(newChildWrapper);
3462   - if (!refChildWrapper) {
3463   - parentNodeWrapper.lastChild_ = parentNodeWrapper.lastChild;
3464   - if (parentNodeWrapper.lastChild === parentNodeWrapper.firstChild) parentNodeWrapper.firstChild_ = parentNodeWrapper.firstChild;
3465   - var lastChildWrapper = wrap(parentNode.lastChild);
3466   - if (lastChildWrapper) lastChildWrapper.nextSibling_ = lastChildWrapper.nextSibling;
3467   - } else {
3468   - if (parentNodeWrapper.firstChild === refChildWrapper) parentNodeWrapper.firstChild_ = refChildWrapper;
3469   - refChildWrapper.previousSibling_ = refChildWrapper.previousSibling;
3470   - }
3471   - scope.originalInsertBefore.call(parentNode, newChild, refChild);
3472   - }
3473   - function remove(nodeWrapper) {
3474   - var node = unwrap(nodeWrapper);
3475   - var parentNode = node.parentNode;
3476   - if (!parentNode) return;
3477   - var parentNodeWrapper = wrap(parentNode);
3478   - updateWrapperUpAndSideways(nodeWrapper);
3479   - if (nodeWrapper.previousSibling) nodeWrapper.previousSibling.nextSibling_ = nodeWrapper;
3480   - if (nodeWrapper.nextSibling) nodeWrapper.nextSibling.previousSibling_ = nodeWrapper;
3481   - if (parentNodeWrapper.lastChild === nodeWrapper) parentNodeWrapper.lastChild_ = nodeWrapper;
3482   - if (parentNodeWrapper.firstChild === nodeWrapper) parentNodeWrapper.firstChild_ = nodeWrapper;
3483   - scope.originalRemoveChild.call(parentNode, node);
3484   - }
3485   - var distributedNodesTable = new WeakMap();
3486   - var destinationInsertionPointsTable = new WeakMap();
3487   - var rendererForHostTable = new WeakMap();
3488   - function resetDistributedNodes(insertionPoint) {
3489   - distributedNodesTable.set(insertionPoint, []);
3490   - }
3491   - function getDistributedNodes(insertionPoint) {
3492   - var rv = distributedNodesTable.get(insertionPoint);
3493   - if (!rv) distributedNodesTable.set(insertionPoint, rv = []);
3494   - return rv;
3495   - }
3496   - function getChildNodesSnapshot(node) {
3497   - var result = [], i = 0;
3498   - for (var child = node.firstChild; child; child = child.nextSibling) {
3499   - result[i++] = child;
3500   - }
3501   - return result;
3502   - }
3503   - var request = oneOf(window, [ "requestAnimationFrame", "mozRequestAnimationFrame", "webkitRequestAnimationFrame", "setTimeout" ]);
3504   - var pendingDirtyRenderers = [];
3505   - var renderTimer;
3506   - function renderAllPending() {
3507   - for (var i = 0; i < pendingDirtyRenderers.length; i++) {
3508   - var renderer = pendingDirtyRenderers[i];
3509   - var parentRenderer = renderer.parentRenderer;
3510   - if (parentRenderer && parentRenderer.dirty) continue;
3511   - renderer.render();
3512   - }
3513   - pendingDirtyRenderers = [];
3514   - }
3515   - function handleRequestAnimationFrame() {
3516   - renderTimer = null;
3517   - renderAllPending();
3518   - }
3519   - function getRendererForHost(host) {
3520   - var renderer = rendererForHostTable.get(host);
3521   - if (!renderer) {
3522   - renderer = new ShadowRenderer(host);
3523   - rendererForHostTable.set(host, renderer);
3524   - }
3525   - return renderer;
3526   - }
3527   - function getShadowRootAncestor(node) {
3528   - var root = getTreeScope(node).root;
3529   - if (root instanceof ShadowRoot) return root;
3530   - return null;
3531   - }
3532   - function getRendererForShadowRoot(shadowRoot) {
3533   - return getRendererForHost(shadowRoot.host);
3534   - }
3535   - var spliceDiff = new ArraySplice();
3536   - spliceDiff.equals = function(renderNode, rawNode) {
3537   - return unwrap(renderNode.node) === rawNode;
3538   - };
3539   - function RenderNode(node) {
3540   - this.skip = false;
3541   - this.node = node;
3542   - this.childNodes = [];
3543   - }
3544   - RenderNode.prototype = {
3545   - append: function(node) {
3546   - var rv = new RenderNode(node);
3547   - this.childNodes.push(rv);
3548   - return rv;
3549   - },
3550   - sync: function(opt_added) {
3551   - if (this.skip) return;
3552   - var nodeWrapper = this.node;
3553   - var newChildren = this.childNodes;
3554   - var oldChildren = getChildNodesSnapshot(unwrap(nodeWrapper));
3555   - var added = opt_added || new WeakMap();
3556   - var splices = spliceDiff.calculateSplices(newChildren, oldChildren);
3557   - var newIndex = 0, oldIndex = 0;
3558   - var lastIndex = 0;
3559   - for (var i = 0; i < splices.length; i++) {
3560   - var splice = splices[i];
3561   - for (;lastIndex < splice.index; lastIndex++) {
3562   - oldIndex++;
3563   - newChildren[newIndex++].sync(added);
3564   - }
3565   - var removedCount = splice.removed.length;
3566   - for (var j = 0; j < removedCount; j++) {
3567   - var wrapper = wrap(oldChildren[oldIndex++]);
3568   - if (!added.get(wrapper)) remove(wrapper);
3569   - }
3570   - var addedCount = splice.addedCount;
3571   - var refNode = oldChildren[oldIndex] && wrap(oldChildren[oldIndex]);
3572   - for (var j = 0; j < addedCount; j++) {
3573   - var newChildRenderNode = newChildren[newIndex++];
3574   - var newChildWrapper = newChildRenderNode.node;
3575   - insertBefore(nodeWrapper, newChildWrapper, refNode);
3576   - added.set(newChildWrapper, true);
3577   - newChildRenderNode.sync(added);
3578   - }
3579   - lastIndex += addedCount;
3580   - }
3581   - for (var i = lastIndex; i < newChildren.length; i++) {
3582   - newChildren[i].sync(added);
3583   - }
3584   - }
3585   - };
3586   - function ShadowRenderer(host) {
3587   - this.host = host;
3588   - this.dirty = false;
3589   - this.invalidateAttributes();
3590   - this.associateNode(host);
3591   - }
3592   - ShadowRenderer.prototype = {
3593   - render: function(opt_renderNode) {
3594   - if (!this.dirty) return;
3595   - this.invalidateAttributes();
3596   - var host = this.host;
3597   - this.distribution(host);
3598   - var renderNode = opt_renderNode || new RenderNode(host);
3599   - this.buildRenderTree(renderNode, host);
3600   - var topMostRenderer = !opt_renderNode;
3601   - if (topMostRenderer) renderNode.sync();
3602   - this.dirty = false;
3603   - },
3604   - get parentRenderer() {
3605   - return getTreeScope(this.host).renderer;
3606   - },
3607   - invalidate: function() {
3608   - if (!this.dirty) {
3609   - this.dirty = true;
3610   - var parentRenderer = this.parentRenderer;
3611   - if (parentRenderer) parentRenderer.invalidate();
3612   - pendingDirtyRenderers.push(this);
3613   - if (renderTimer) return;
3614   - renderTimer = window[request](handleRequestAnimationFrame, 0);
3615   - }
3616   - },
3617   - distribution: function(root) {
3618   - this.resetAllSubtrees(root);
3619   - this.distributionResolution(root);
3620   - },
3621   - resetAll: function(node) {
3622   - if (isInsertionPoint(node)) resetDistributedNodes(node); else resetDestinationInsertionPoints(node);
3623   - this.resetAllSubtrees(node);
3624   - },
3625   - resetAllSubtrees: function(node) {
3626   - for (var child = node.firstChild; child; child = child.nextSibling) {
3627   - this.resetAll(child);
3628   - }
3629   - if (node.shadowRoot) this.resetAll(node.shadowRoot);
3630   - if (node.olderShadowRoot) this.resetAll(node.olderShadowRoot);
3631   - },
3632   - distributionResolution: function(node) {
3633   - if (isShadowHost(node)) {
3634   - var shadowHost = node;
3635   - var pool = poolPopulation(shadowHost);
3636   - var shadowTrees = getShadowTrees(shadowHost);
3637   - for (var i = 0; i < shadowTrees.length; i++) {
3638   - this.poolDistribution(shadowTrees[i], pool);
3639   - }
3640   - for (var i = shadowTrees.length - 1; i >= 0; i--) {
3641   - var shadowTree = shadowTrees[i];
3642   - var shadow = getShadowInsertionPoint(shadowTree);
3643   - if (shadow) {
3644   - var olderShadowRoot = shadowTree.olderShadowRoot;
3645   - if (olderShadowRoot) {
3646   - pool = poolPopulation(olderShadowRoot);
3647   - }
3648   - for (var j = 0; j < pool.length; j++) {
3649   - destributeNodeInto(pool[j], shadow);
3650   - }
3651   - }
3652   - this.distributionResolution(shadowTree);
3653   - }
3654   - }
3655   - for (var child = node.firstChild; child; child = child.nextSibling) {
3656   - this.distributionResolution(child);
3657   - }
3658   - },
3659   - poolDistribution: function(node, pool) {
3660   - if (node instanceof HTMLShadowElement) return;
3661   - if (node instanceof HTMLContentElement) {
3662   - var content = node;
3663   - this.updateDependentAttributes(content.getAttribute("select"));
3664   - var anyDistributed = false;
3665   - for (var i = 0; i < pool.length; i++) {
3666   - var node = pool[i];
3667   - if (!node) continue;
3668   - if (matches(node, content)) {
3669   - destributeNodeInto(node, content);
3670   - pool[i] = undefined;
3671   - anyDistributed = true;
3672   - }
3673   - }
3674   - if (!anyDistributed) {
3675   - for (var child = content.firstChild; child; child = child.nextSibling) {
3676   - destributeNodeInto(child, content);
3677   - }
3678   - }
3679   - return;
3680   - }
3681   - for (var child = node.firstChild; child; child = child.nextSibling) {
3682   - this.poolDistribution(child, pool);
3683   - }
3684   - },
3685   - buildRenderTree: function(renderNode, node) {
3686   - var children = this.compose(node);
3687   - for (var i = 0; i < children.length; i++) {
3688   - var child = children[i];
3689   - var childRenderNode = renderNode.append(child);
3690   - this.buildRenderTree(childRenderNode, child);
3691   - }
3692   - if (isShadowHost(node)) {
3693   - var renderer = getRendererForHost(node);
3694   - renderer.dirty = false;
3695   - }
3696   - },
3697   - compose: function(node) {
3698   - var children = [];
3699   - var p = node.shadowRoot || node;
3700   - for (var child = p.firstChild; child; child = child.nextSibling) {
3701   - if (isInsertionPoint(child)) {
3702   - this.associateNode(p);
3703   - var distributedNodes = getDistributedNodes(child);
3704   - for (var j = 0; j < distributedNodes.length; j++) {
3705   - var distributedNode = distributedNodes[j];
3706   - if (isFinalDestination(child, distributedNode)) children.push(distributedNode);
3707   - }
3708   - } else {
3709   - children.push(child);
3710   - }
3711   - }
3712   - return children;
3713   - },
3714   - invalidateAttributes: function() {
3715   - this.attributes = Object.create(null);
3716   - },
3717   - updateDependentAttributes: function(selector) {
3718   - if (!selector) return;
3719   - var attributes = this.attributes;
3720   - if (/\.\w+/.test(selector)) attributes["class"] = true;
3721   - if (/#\w+/.test(selector)) attributes["id"] = true;
3722   - selector.replace(/\[\s*([^\s=\|~\]]+)/g, function(_, name) {
3723   - attributes[name] = true;
3724   - });
3725   - },
3726   - dependsOnAttribute: function(name) {
3727   - return this.attributes[name];
3728   - },
3729   - associateNode: function(node) {
3730   - unsafeUnwrap(node).polymerShadowRenderer_ = this;
3731   - }
3732   - };
3733   - function poolPopulation(node) {
3734   - var pool = [];
3735   - for (var child = node.firstChild; child; child = child.nextSibling) {
3736   - if (isInsertionPoint(child)) {
3737   - pool.push.apply(pool, getDistributedNodes(child));
3738   - } else {
3739   - pool.push(child);
3740   - }
3741   - }
3742   - return pool;
3743   - }
3744   - function getShadowInsertionPoint(node) {
3745   - if (node instanceof HTMLShadowElement) return node;
3746   - if (node instanceof HTMLContentElement) return null;
3747   - for (var child = node.firstChild; child; child = child.nextSibling) {
3748   - var res = getShadowInsertionPoint(child);
3749   - if (res) return res;
3750   - }
3751   - return null;
3752   - }
3753   - function destributeNodeInto(child, insertionPoint) {
3754   - getDistributedNodes(insertionPoint).push(child);
3755   - var points = destinationInsertionPointsTable.get(child);
3756   - if (!points) destinationInsertionPointsTable.set(child, [ insertionPoint ]); else points.push(insertionPoint);
3757   - }
3758   - function getDestinationInsertionPoints(node) {
3759   - return destinationInsertionPointsTable.get(node);
3760   - }
3761   - function resetDestinationInsertionPoints(node) {
3762   - destinationInsertionPointsTable.set(node, undefined);
3763   - }
3764   - var selectorStartCharRe = /^(:not\()?[*.#[a-zA-Z_|]/;
3765   - function matches(node, contentElement) {
3766   - var select = contentElement.getAttribute("select");
3767   - if (!select) return true;
3768   - select = select.trim();
3769   - if (!select) return true;
3770   - if (!(node instanceof Element)) return false;
3771   - if (!selectorStartCharRe.test(select)) return false;
3772   - try {
3773   - return node.matches(select);
3774   - } catch (ex) {
3775   - return false;
3776   - }
3777   - }
3778   - function isFinalDestination(insertionPoint, node) {
3779   - var points = getDestinationInsertionPoints(node);
3780   - return points && points[points.length - 1] === insertionPoint;
3781   - }
3782   - function isInsertionPoint(node) {
3783   - return node instanceof HTMLContentElement || node instanceof HTMLShadowElement;
3784   - }
3785   - function isShadowHost(shadowHost) {
3786   - return shadowHost.shadowRoot;
3787   - }
3788   - function getShadowTrees(host) {
3789   - var trees = [];
3790   - for (var tree = host.shadowRoot; tree; tree = tree.olderShadowRoot) {
3791   - trees.push(tree);
3792   - }
3793   - return trees;
3794   - }
3795   - function render(host) {
3796   - new ShadowRenderer(host).render();
3797   - }
3798   - Node.prototype.invalidateShadowRenderer = function(force) {
3799   - var renderer = unsafeUnwrap(this).polymerShadowRenderer_;
3800   - if (renderer) {
3801   - renderer.invalidate();
3802   - return true;
3803   - }
3804   - return false;
3805   - };
3806   - HTMLContentElement.prototype.getDistributedNodes = HTMLShadowElement.prototype.getDistributedNodes = function() {
3807   - renderAllPending();
3808   - return getDistributedNodes(this);
3809   - };
3810   - Element.prototype.getDestinationInsertionPoints = function() {
3811   - renderAllPending();
3812   - return getDestinationInsertionPoints(this) || [];
3813   - };
3814   - HTMLContentElement.prototype.nodeIsInserted_ = HTMLShadowElement.prototype.nodeIsInserted_ = function() {
3815   - this.invalidateShadowRenderer();
3816   - var shadowRoot = getShadowRootAncestor(this);
3817   - var renderer;
3818   - if (shadowRoot) renderer = getRendererForShadowRoot(shadowRoot);
3819   - unsafeUnwrap(this).polymerShadowRenderer_ = renderer;
3820   - if (renderer) renderer.invalidate();
3821   - };
3822   - scope.getRendererForHost = getRendererForHost;
3823   - scope.getShadowTrees = getShadowTrees;
3824   - scope.renderAllPending = renderAllPending;
3825   - scope.getDestinationInsertionPoints = getDestinationInsertionPoints;
3826   - scope.visual = {
3827   - insertBefore: insertBefore,
3828   - remove: remove
3829   - };
3830   - })(window.ShadowDOMPolyfill);
3831   - (function(scope) {
3832   - "use strict";
3833   - var HTMLElement = scope.wrappers.HTMLElement;
3834   - var assert = scope.assert;
3835   - var mixin = scope.mixin;
3836   - var registerWrapper = scope.registerWrapper;
3837   - var unwrap = scope.unwrap;
3838   - var wrap = scope.wrap;
3839   - var elementsWithFormProperty = [ "HTMLButtonElement", "HTMLFieldSetElement", "HTMLInputElement", "HTMLKeygenElement", "HTMLLabelElement", "HTMLLegendElement", "HTMLObjectElement", "HTMLOutputElement", "HTMLTextAreaElement" ];
3840   - function createWrapperConstructor(name) {
3841   - if (!window[name]) return;
3842   - assert(!scope.wrappers[name]);
3843   - var GeneratedWrapper = function(node) {
3844   - HTMLElement.call(this, node);
3845   - };
3846   - GeneratedWrapper.prototype = Object.create(HTMLElement.prototype);
3847   - mixin(GeneratedWrapper.prototype, {
3848   - get form() {
3849   - return wrap(unwrap(this).form);
3850   - }
3851   - });
3852   - registerWrapper(window[name], GeneratedWrapper, document.createElement(name.slice(4, -7)));
3853   - scope.wrappers[name] = GeneratedWrapper;
3854   - }
3855   - elementsWithFormProperty.forEach(createWrapperConstructor);
3856   - })(window.ShadowDOMPolyfill);
3857   - (function(scope) {
3858   - "use strict";
3859   - var registerWrapper = scope.registerWrapper;
3860   - var setWrapper = scope.setWrapper;
3861   - var unsafeUnwrap = scope.unsafeUnwrap;
3862   - var unwrap = scope.unwrap;
3863   - var unwrapIfNeeded = scope.unwrapIfNeeded;
3864   - var wrap = scope.wrap;
3865   - var OriginalSelection = window.Selection;
3866   - function Selection(impl) {
3867   - setWrapper(impl, this);
3868   - }
3869   - Selection.prototype = {
3870   - get anchorNode() {
3871   - return wrap(unsafeUnwrap(this).anchorNode);
3872   - },
3873   - get focusNode() {
3874   - return wrap(unsafeUnwrap(this).focusNode);
3875   - },
3876   - addRange: function(range) {
3877   - unsafeUnwrap(this).addRange(unwrap(range));
3878   - },
3879   - collapse: function(node, index) {
3880   - unsafeUnwrap(this).collapse(unwrapIfNeeded(node), index);
3881   - },
3882   - containsNode: function(node, allowPartial) {
3883   - return unsafeUnwrap(this).containsNode(unwrapIfNeeded(node), allowPartial);
3884   - },
3885   - extend: function(node, offset) {
3886   - unsafeUnwrap(this).extend(unwrapIfNeeded(node), offset);
3887   - },
3888   - getRangeAt: function(index) {
3889   - return wrap(unsafeUnwrap(this).getRangeAt(index));
3890   - },
3891   - removeRange: function(range) {
3892   - unsafeUnwrap(this).removeRange(unwrap(range));
3893   - },
3894   - selectAllChildren: function(node) {
3895   - unsafeUnwrap(this).selectAllChildren(unwrapIfNeeded(node));
3896   - },
3897   - toString: function() {
3898   - return unsafeUnwrap(this).toString();
3899   - }
3900   - };
3901   - registerWrapper(window.Selection, Selection, window.getSelection());
3902   - scope.wrappers.Selection = Selection;
3903   - })(window.ShadowDOMPolyfill);
3904   - (function(scope) {
3905   - "use strict";
3906   - var GetElementsByInterface = scope.GetElementsByInterface;
3907   - var Node = scope.wrappers.Node;
3908   - var ParentNodeInterface = scope.ParentNodeInterface;
3909   - var Selection = scope.wrappers.Selection;
3910   - var SelectorsInterface = scope.SelectorsInterface;
3911   - var ShadowRoot = scope.wrappers.ShadowRoot;
3912   - var TreeScope = scope.TreeScope;
3913   - var cloneNode = scope.cloneNode;
3914   - var defineWrapGetter = scope.defineWrapGetter;
3915   - var elementFromPoint = scope.elementFromPoint;
3916   - var forwardMethodsToWrapper = scope.forwardMethodsToWrapper;
3917   - var matchesNames = scope.matchesNames;
3918   - var mixin = scope.mixin;
3919   - var registerWrapper = scope.registerWrapper;
3920   - var renderAllPending = scope.renderAllPending;
3921   - var rewrap = scope.rewrap;
3922   - var setWrapper = scope.setWrapper;
3923   - var unsafeUnwrap = scope.unsafeUnwrap;
3924   - var unwrap = scope.unwrap;
3925   - var wrap = scope.wrap;
3926   - var wrapEventTargetMethods = scope.wrapEventTargetMethods;
3927   - var wrapNodeList = scope.wrapNodeList;
3928   - var implementationTable = new WeakMap();
3929   - function Document(node) {
3930   - Node.call(this, node);
3931   - this.treeScope_ = new TreeScope(this, null);
3932   - }
3933   - Document.prototype = Object.create(Node.prototype);
3934   - defineWrapGetter(Document, "documentElement");
3935   - defineWrapGetter(Document, "body");
3936   - defineWrapGetter(Document, "head");
3937   - function wrapMethod(name) {
3938   - var original = document[name];
3939   - Document.prototype[name] = function() {
3940   - return wrap(original.apply(unsafeUnwrap(this), arguments));
3941   - };
3942   - }
3943   - [ "createComment", "createDocumentFragment", "createElement", "createElementNS", "createEvent", "createEventNS", "createRange", "createTextNode", "getElementById" ].forEach(wrapMethod);
3944   - var originalAdoptNode = document.adoptNode;
3945   - function adoptNodeNoRemove(node, doc) {
3946   - originalAdoptNode.call(unsafeUnwrap(doc), unwrap(node));
3947   - adoptSubtree(node, doc);
3948   - }
3949   - function adoptSubtree(node, doc) {
3950   - if (node.shadowRoot) doc.adoptNode(node.shadowRoot);
3951   - if (node instanceof ShadowRoot) adoptOlderShadowRoots(node, doc);
3952   - for (var child = node.firstChild; child; child = child.nextSibling) {
3953   - adoptSubtree(child, doc);
3954   - }
3955   - }
3956   - function adoptOlderShadowRoots(shadowRoot, doc) {
3957   - var oldShadowRoot = shadowRoot.olderShadowRoot;
3958   - if (oldShadowRoot) doc.adoptNode(oldShadowRoot);
3959   - }
3960   - var originalGetSelection = document.getSelection;
3961   - mixin(Document.prototype, {
3962   - adoptNode: function(node) {
3963   - if (node.parentNode) node.parentNode.removeChild(node);
3964   - adoptNodeNoRemove(node, this);
3965   - return node;
3966   - },
3967   - elementFromPoint: function(x, y) {
3968   - return elementFromPoint(this, this, x, y);
3969   - },
3970   - importNode: function(node, deep) {
3971   - return cloneNode(node, deep, unsafeUnwrap(this));
3972   - },
3973   - getSelection: function() {
3974   - renderAllPending();
3975   - return new Selection(originalGetSelection.call(unwrap(this)));
3976   - },
3977   - getElementsByName: function(name) {
3978   - return SelectorsInterface.querySelectorAll.call(this, "[name=" + JSON.stringify(String(name)) + "]");
3979   - }
3980   - });
3981   - if (document.registerElement) {
3982   - var originalRegisterElement = document.registerElement;
3983   - Document.prototype.registerElement = function(tagName, object) {
3984   - var prototype, extendsOption;
3985   - if (object !== undefined) {
3986   - prototype = object.prototype;
3987   - extendsOption = object.extends;
3988   - }
3989   - if (!prototype) prototype = Object.create(HTMLElement.prototype);
3990   - if (scope.nativePrototypeTable.get(prototype)) {
3991   - throw new Error("NotSupportedError");
3992   - }
3993   - var proto = Object.getPrototypeOf(prototype);
3994   - var nativePrototype;
3995   - var prototypes = [];
3996   - while (proto) {
3997   - nativePrototype = scope.nativePrototypeTable.get(proto);
3998   - if (nativePrototype) break;
3999   - prototypes.push(proto);
4000   - proto = Object.getPrototypeOf(proto);
4001   - }
4002   - if (!nativePrototype) {
4003   - throw new Error("NotSupportedError");
4004   - }
4005   - var newPrototype = Object.create(nativePrototype);
4006   - for (var i = prototypes.length - 1; i >= 0; i--) {
4007   - newPrototype = Object.create(newPrototype);
4008   - }
4009   - [ "createdCallback", "attachedCallback", "detachedCallback", "attributeChangedCallback" ].forEach(function(name) {
4010   - var f = prototype[name];
4011   - if (!f) return;
4012   - newPrototype[name] = function() {
4013   - if (!(wrap(this) instanceof CustomElementConstructor)) {
4014   - rewrap(this);
4015   - }
4016   - f.apply(wrap(this), arguments);
4017   - };
4018   - });
4019   - var p = {
4020   - prototype: newPrototype
4021   - };
4022   - if (extendsOption) p.extends = extendsOption;
4023   - function CustomElementConstructor(node) {
4024   - if (!node) {
4025   - if (extendsOption) {
4026   - return document.createElement(extendsOption, tagName);
4027   - } else {
4028   - return document.createElement(tagName);
4029   - }
4030   - }
4031   - setWrapper(node, this);
4032   - }
4033   - CustomElementConstructor.prototype = prototype;
4034   - CustomElementConstructor.prototype.constructor = CustomElementConstructor;
4035   - scope.constructorTable.set(newPrototype, CustomElementConstructor);
4036   - scope.nativePrototypeTable.set(prototype, newPrototype);
4037   - var nativeConstructor = originalRegisterElement.call(unwrap(this), tagName, p);
4038   - return CustomElementConstructor;
4039   - };
4040   - forwardMethodsToWrapper([ window.HTMLDocument || window.Document ], [ "registerElement" ]);
4041   - }
4042   - forwardMethodsToWrapper([ window.HTMLBodyElement, window.HTMLDocument || window.Document, window.HTMLHeadElement, window.HTMLHtmlElement ], [ "appendChild", "compareDocumentPosition", "contains", "getElementsByClassName", "getElementsByTagName", "getElementsByTagNameNS", "insertBefore", "querySelector", "querySelectorAll", "removeChild", "replaceChild" ]);
4043   - forwardMethodsToWrapper([ window.HTMLBodyElement, window.HTMLHeadElement, window.HTMLHtmlElement ], matchesNames);
4044   - forwardMethodsToWrapper([ window.HTMLDocument || window.Document ], [ "adoptNode", "importNode", "contains", "createComment", "createDocumentFragment", "createElement", "createElementNS", "createEvent", "createEventNS", "createRange", "createTextNode", "elementFromPoint", "getElementById", "getElementsByName", "getSelection" ]);
4045   - mixin(Document.prototype, GetElementsByInterface);
4046   - mixin(Document.prototype, ParentNodeInterface);
4047   - mixin(Document.prototype, SelectorsInterface);
4048   - mixin(Document.prototype, {
4049   - get implementation() {
4050   - var implementation = implementationTable.get(this);
4051   - if (implementation) return implementation;
4052   - implementation = new DOMImplementation(unwrap(this).implementation);
4053   - implementationTable.set(this, implementation);
4054   - return implementation;
4055   - },
4056   - get defaultView() {
4057   - return wrap(unwrap(this).defaultView);
4058   - }
4059   - });
4060   - registerWrapper(window.Document, Document, document.implementation.createHTMLDocument(""));
4061   - if (window.HTMLDocument) registerWrapper(window.HTMLDocument, Document);
4062   - wrapEventTargetMethods([ window.HTMLBodyElement, window.HTMLDocument || window.Document, window.HTMLHeadElement ]);
4063   - function DOMImplementation(impl) {
4064   - setWrapper(impl, this);
4065   - }
4066   - function wrapImplMethod(constructor, name) {
4067   - var original = document.implementation[name];
4068   - constructor.prototype[name] = function() {
4069   - return wrap(original.apply(unsafeUnwrap(this), arguments));
4070   - };
4071   - }
4072   - function forwardImplMethod(constructor, name) {
4073   - var original = document.implementation[name];
4074   - constructor.prototype[name] = function() {
4075   - return original.apply(unsafeUnwrap(this), arguments);
4076   - };
4077   - }
4078   - wrapImplMethod(DOMImplementation, "createDocumentType");
4079   - wrapImplMethod(DOMImplementation, "createDocument");
4080   - wrapImplMethod(DOMImplementation, "createHTMLDocument");
4081   - forwardImplMethod(DOMImplementation, "hasFeature");
4082   - registerWrapper(window.DOMImplementation, DOMImplementation);
4083   - forwardMethodsToWrapper([ window.DOMImplementation ], [ "createDocumentType", "createDocument", "createHTMLDocument", "hasFeature" ]);
4084   - scope.adoptNodeNoRemove = adoptNodeNoRemove;
4085   - scope.wrappers.DOMImplementation = DOMImplementation;
4086   - scope.wrappers.Document = Document;
4087   - })(window.ShadowDOMPolyfill);
4088   - (function(scope) {
4089   - "use strict";
4090   - var EventTarget = scope.wrappers.EventTarget;
4091   - var Selection = scope.wrappers.Selection;
4092   - var mixin = scope.mixin;
4093   - var registerWrapper = scope.registerWrapper;
4094   - var renderAllPending = scope.renderAllPending;
4095   - var unwrap = scope.unwrap;
4096   - var unwrapIfNeeded = scope.unwrapIfNeeded;
4097   - var wrap = scope.wrap;
4098   - var OriginalWindow = window.Window;
4099   - var originalGetComputedStyle = window.getComputedStyle;
4100   - var originalGetDefaultComputedStyle = window.getDefaultComputedStyle;
4101   - var originalGetSelection = window.getSelection;
4102   - function Window(impl) {
4103   - EventTarget.call(this, impl);
4104   - }
4105   - Window.prototype = Object.create(EventTarget.prototype);
4106   - OriginalWindow.prototype.getComputedStyle = function(el, pseudo) {
4107   - return wrap(this || window).getComputedStyle(unwrapIfNeeded(el), pseudo);
4108   - };
4109   - if (originalGetDefaultComputedStyle) {
4110   - OriginalWindow.prototype.getDefaultComputedStyle = function(el, pseudo) {
4111   - return wrap(this || window).getDefaultComputedStyle(unwrapIfNeeded(el), pseudo);
4112   - };
4113   - }
4114   - OriginalWindow.prototype.getSelection = function() {
4115   - return wrap(this || window).getSelection();
4116   - };
4117   - delete window.getComputedStyle;
4118   - delete window.getDefaultComputedStyle;
4119   - delete window.getSelection;
4120   - [ "addEventListener", "removeEventListener", "dispatchEvent" ].forEach(function(name) {
4121   - OriginalWindow.prototype[name] = function() {
4122   - var w = wrap(this || window);
4123   - return w[name].apply(w, arguments);
4124   - };
4125   - delete window[name];
4126   - });
4127   - mixin(Window.prototype, {
4128   - getComputedStyle: function(el, pseudo) {
4129   - renderAllPending();
4130   - return originalGetComputedStyle.call(unwrap(this), unwrapIfNeeded(el), pseudo);
4131   - },
4132   - getSelection: function() {
4133   - renderAllPending();
4134   - return new Selection(originalGetSelection.call(unwrap(this)));
4135   - },
4136   - get document() {
4137   - return wrap(unwrap(this).document);
4138   - }
4139   - });
4140   - if (originalGetDefaultComputedStyle) {
4141   - Window.prototype.getDefaultComputedStyle = function(el, pseudo) {
4142   - renderAllPending();
4143   - return originalGetDefaultComputedStyle.call(unwrap(this), unwrapIfNeeded(el), pseudo);
4144   - };
4145   - }
4146   - registerWrapper(OriginalWindow, Window, window);
4147   - scope.wrappers.Window = Window;
4148   - })(window.ShadowDOMPolyfill);
4149   - (function(scope) {
4150   - "use strict";
4151   - var unwrap = scope.unwrap;
4152   - var OriginalDataTransfer = window.DataTransfer || window.Clipboard;
4153   - var OriginalDataTransferSetDragImage = OriginalDataTransfer.prototype.setDragImage;
4154   - if (OriginalDataTransferSetDragImage) {
4155   - OriginalDataTransfer.prototype.setDragImage = function(image, x, y) {
4156   - OriginalDataTransferSetDragImage.call(this, unwrap(image), x, y);
4157   - };
4158   - }
4159   - })(window.ShadowDOMPolyfill);
4160   - (function(scope) {
4161   - "use strict";
4162   - var registerWrapper = scope.registerWrapper;
4163   - var setWrapper = scope.setWrapper;
4164   - var unwrap = scope.unwrap;
4165   - var OriginalFormData = window.FormData;
4166   - if (!OriginalFormData) return;
4167   - function FormData(formElement) {
4168   - var impl;
4169   - if (formElement instanceof OriginalFormData) {
4170   - impl = formElement;
4171   - } else {
4172   - impl = new OriginalFormData(formElement && unwrap(formElement));
4173   - }
4174   - setWrapper(impl, this);
4175   - }
4176   - registerWrapper(OriginalFormData, FormData, new OriginalFormData());
4177   - scope.wrappers.FormData = FormData;
4178   - })(window.ShadowDOMPolyfill);
4179   - (function(scope) {
4180   - "use strict";
4181   - var unwrapIfNeeded = scope.unwrapIfNeeded;
4182   - var originalSend = XMLHttpRequest.prototype.send;
4183   - XMLHttpRequest.prototype.send = function(obj) {
4184   - return originalSend.call(this, unwrapIfNeeded(obj));
4185   - };
4186   - })(window.ShadowDOMPolyfill);
4187   - (function(scope) {
4188   - "use strict";
4189   - var isWrapperFor = scope.isWrapperFor;
4190   - var elements = {
4191   - a: "HTMLAnchorElement",
4192   - area: "HTMLAreaElement",
4193   - audio: "HTMLAudioElement",
4194   - base: "HTMLBaseElement",
4195   - body: "HTMLBodyElement",
4196   - br: "HTMLBRElement",
4197   - button: "HTMLButtonElement",
4198   - canvas: "HTMLCanvasElement",
4199   - caption: "HTMLTableCaptionElement",
4200   - col: "HTMLTableColElement",
4201   - content: "HTMLContentElement",
4202   - data: "HTMLDataElement",
4203   - datalist: "HTMLDataListElement",
4204   - del: "HTMLModElement",
4205   - dir: "HTMLDirectoryElement",
4206   - div: "HTMLDivElement",
4207   - dl: "HTMLDListElement",
4208   - embed: "HTMLEmbedElement",
4209   - fieldset: "HTMLFieldSetElement",
4210   - font: "HTMLFontElement",
4211   - form: "HTMLFormElement",
4212   - frame: "HTMLFrameElement",
4213   - frameset: "HTMLFrameSetElement",
4214   - h1: "HTMLHeadingElement",
4215   - head: "HTMLHeadElement",
4216   - hr: "HTMLHRElement",
4217   - html: "HTMLHtmlElement",
4218   - iframe: "HTMLIFrameElement",
4219   - img: "HTMLImageElement",
4220   - input: "HTMLInputElement",
4221   - keygen: "HTMLKeygenElement",
4222   - label: "HTMLLabelElement",
4223   - legend: "HTMLLegendElement",
4224   - li: "HTMLLIElement",
4225   - link: "HTMLLinkElement",
4226   - map: "HTMLMapElement",
4227   - marquee: "HTMLMarqueeElement",
4228   - menu: "HTMLMenuElement",
4229   - menuitem: "HTMLMenuItemElement",
4230   - meta: "HTMLMetaElement",
4231   - meter: "HTMLMeterElement",
4232   - object: "HTMLObjectElement",
4233   - ol: "HTMLOListElement",
4234   - optgroup: "HTMLOptGroupElement",
4235   - option: "HTMLOptionElement",
4236   - output: "HTMLOutputElement",
4237   - p: "HTMLParagraphElement",
4238   - param: "HTMLParamElement",
4239   - pre: "HTMLPreElement",
4240   - progress: "HTMLProgressElement",
4241   - q: "HTMLQuoteElement",
4242   - script: "HTMLScriptElement",
4243   - select: "HTMLSelectElement",
4244   - shadow: "HTMLShadowElement",
4245   - source: "HTMLSourceElement",
4246   - span: "HTMLSpanElement",
4247   - style: "HTMLStyleElement",
4248   - table: "HTMLTableElement",
4249   - tbody: "HTMLTableSectionElement",
4250   - template: "HTMLTemplateElement",
4251   - textarea: "HTMLTextAreaElement",
4252   - thead: "HTMLTableSectionElement",
4253   - time: "HTMLTimeElement",
4254   - title: "HTMLTitleElement",
4255   - tr: "HTMLTableRowElement",
4256   - track: "HTMLTrackElement",
4257   - ul: "HTMLUListElement",
4258   - video: "HTMLVideoElement"
4259   - };
4260   - function overrideConstructor(tagName) {
4261   - var nativeConstructorName = elements[tagName];
4262   - var nativeConstructor = window[nativeConstructorName];
4263   - if (!nativeConstructor) return;
4264   - var element = document.createElement(tagName);
4265   - var wrapperConstructor = element.constructor;
4266   - window[nativeConstructorName] = wrapperConstructor;
4267   - }
4268   - Object.keys(elements).forEach(overrideConstructor);
4269   - Object.getOwnPropertyNames(scope.wrappers).forEach(function(name) {
4270   - window[name] = scope.wrappers[name];
4271   - });
4272   - })(window.ShadowDOMPolyfill);
4273   - (function(scope) {
4274   - var ShadowCSS = {
4275   - strictStyling: false,
4276   - registry: {},
4277   - shimStyling: function(root, name, extendsName) {
4278   - var scopeStyles = this.prepareRoot(root, name, extendsName);
4279   - var typeExtension = this.isTypeExtension(extendsName);
4280   - var scopeSelector = this.makeScopeSelector(name, typeExtension);
4281   - var cssText = stylesToCssText(scopeStyles, true);
4282   - cssText = this.scopeCssText(cssText, scopeSelector);
4283   - if (root) {
4284   - root.shimmedStyle = cssText;
4285   - }
4286   - this.addCssToDocument(cssText, name);
4287   - },
4288   - shimStyle: function(style, selector) {
4289   - return this.shimCssText(style.textContent, selector);
4290   - },
4291   - shimCssText: function(cssText, selector) {
4292   - cssText = this.insertDirectives(cssText);
4293   - return this.scopeCssText(cssText, selector);
4294   - },
4295   - makeScopeSelector: function(name, typeExtension) {
4296   - if (name) {
4297   - return typeExtension ? "[is=" + name + "]" : name;
4298   - }
4299   - return "";
4300   - },
4301   - isTypeExtension: function(extendsName) {
4302   - return extendsName && extendsName.indexOf("-") < 0;
4303   - },
4304   - prepareRoot: function(root, name, extendsName) {
4305   - var def = this.registerRoot(root, name, extendsName);
4306   - this.replaceTextInStyles(def.rootStyles, this.insertDirectives);
4307   - this.removeStyles(root, def.rootStyles);
4308   - if (this.strictStyling) {
4309   - this.applyScopeToContent(root, name);
4310   - }
4311   - return def.scopeStyles;
4312   - },
4313   - removeStyles: function(root, styles) {
4314   - for (var i = 0, l = styles.length, s; i < l && (s = styles[i]); i++) {
4315   - s.parentNode.removeChild(s);
4316   - }
4317   - },
4318   - registerRoot: function(root, name, extendsName) {
4319   - var def = this.registry[name] = {
4320   - root: root,
4321   - name: name,
4322   - extendsName: extendsName
4323   - };
4324   - var styles = this.findStyles(root);
4325   - def.rootStyles = styles;
4326   - def.scopeStyles = def.rootStyles;
4327   - var extendee = this.registry[def.extendsName];
4328   - if (extendee) {
4329   - def.scopeStyles = extendee.scopeStyles.concat(def.scopeStyles);
4330   - }
4331   - return def;
4332   - },
4333   - findStyles: function(root) {
4334   - if (!root) {
4335   - return [];
4336   - }
4337   - var styles = root.querySelectorAll("style");
4338   - return Array.prototype.filter.call(styles, function(s) {
4339   - return !s.hasAttribute(NO_SHIM_ATTRIBUTE);
4340   - });
4341   - },
4342   - applyScopeToContent: function(root, name) {
4343   - if (root) {
4344   - Array.prototype.forEach.call(root.querySelectorAll("*"), function(node) {
4345   - node.setAttribute(name, "");
4346   - });
4347   - Array.prototype.forEach.call(root.querySelectorAll("template"), function(template) {
4348   - this.applyScopeToContent(template.content, name);
4349   - }, this);
4350   - }
4351   - },
4352   - insertDirectives: function(cssText) {
4353   - cssText = this.insertPolyfillDirectivesInCssText(cssText);
4354   - return this.insertPolyfillRulesInCssText(cssText);
4355   - },
4356   - insertPolyfillDirectivesInCssText: function(cssText) {
4357   - cssText = cssText.replace(cssCommentNextSelectorRe, function(match, p1) {
4358   - return p1.slice(0, -2) + "{";
4359   - });
4360   - return cssText.replace(cssContentNextSelectorRe, function(match, p1) {
4361   - return p1 + " {";
4362   - });
4363   - },
4364   - insertPolyfillRulesInCssText: function(cssText) {
4365   - cssText = cssText.replace(cssCommentRuleRe, function(match, p1) {
4366   - return p1.slice(0, -1);
4367   - });
4368   - return cssText.replace(cssContentRuleRe, function(match, p1, p2, p3) {
4369   - var rule = match.replace(p1, "").replace(p2, "");
4370   - return p3 + rule;
4371   - });
4372   - },
4373   - scopeCssText: function(cssText, scopeSelector) {
4374   - var unscoped = this.extractUnscopedRulesFromCssText(cssText);
4375   - cssText = this.insertPolyfillHostInCssText(cssText);
4376   - cssText = this.convertColonHost(cssText);
4377   - cssText = this.convertColonHostContext(cssText);
4378   - cssText = this.convertShadowDOMSelectors(cssText);
4379   - if (scopeSelector) {
4380   - var self = this, cssText;
4381   - withCssRules(cssText, function(rules) {
4382   - cssText = self.scopeRules(rules, scopeSelector);
4383   - });
4384   - }
4385   - cssText = cssText + "\n" + unscoped;
4386   - return cssText.trim();
4387   - },
4388   - extractUnscopedRulesFromCssText: function(cssText) {
4389   - var r = "", m;
4390   - while (m = cssCommentUnscopedRuleRe.exec(cssText)) {
4391   - r += m[1].slice(0, -1) + "\n\n";
4392   - }
4393   - while (m = cssContentUnscopedRuleRe.exec(cssText)) {
4394   - r += m[0].replace(m[2], "").replace(m[1], m[3]) + "\n\n";
4395   - }
4396   - return r;
4397   - },
4398   - convertColonHost: function(cssText) {
4399   - return this.convertColonRule(cssText, cssColonHostRe, this.colonHostPartReplacer);
4400   - },
4401   - convertColonHostContext: function(cssText) {
4402   - return this.convertColonRule(cssText, cssColonHostContextRe, this.colonHostContextPartReplacer);
4403   - },
4404   - convertColonRule: function(cssText, regExp, partReplacer) {
4405   - return cssText.replace(regExp, function(m, p1, p2, p3) {
4406   - p1 = polyfillHostNoCombinator;
4407   - if (p2) {
4408   - var parts = p2.split(","), r = [];
4409   - for (var i = 0, l = parts.length, p; i < l && (p = parts[i]); i++) {
4410   - p = p.trim();
4411   - r.push(partReplacer(p1, p, p3));
4412   - }
4413   - return r.join(",");
4414   - } else {
4415   - return p1 + p3;
4416   - }
4417   - });
4418   - },
4419   - colonHostContextPartReplacer: function(host, part, suffix) {
4420   - if (part.match(polyfillHost)) {
4421   - return this.colonHostPartReplacer(host, part, suffix);
4422   - } else {
4423   - return host + part + suffix + ", " + part + " " + host + suffix;
4424   - }
4425   - },
4426   - colonHostPartReplacer: function(host, part, suffix) {
4427   - return host + part.replace(polyfillHost, "") + suffix;
4428   - },
4429   - convertShadowDOMSelectors: function(cssText) {
4430   - for (var i = 0; i < shadowDOMSelectorsRe.length; i++) {
4431   - cssText = cssText.replace(shadowDOMSelectorsRe[i], " ");
4432   - }
4433   - return cssText;
4434   - },
4435   - scopeRules: function(cssRules, scopeSelector) {
4436   - var cssText = "";
4437   - if (cssRules) {
4438   - Array.prototype.forEach.call(cssRules, function(rule) {
4439   - if (rule.selectorText && (rule.style && rule.style.cssText !== undefined)) {
4440   - cssText += this.scopeSelector(rule.selectorText, scopeSelector, this.strictStyling) + " {\n ";
4441   - cssText += this.propertiesFromRule(rule) + "\n}\n\n";
4442   - } else if (rule.type === CSSRule.MEDIA_RULE) {
4443   - cssText += "@media " + rule.media.mediaText + " {\n";
4444   - cssText += this.scopeRules(rule.cssRules, scopeSelector);
4445   - cssText += "\n}\n\n";
4446   - } else {
4447   - try {
4448   - if (rule.cssText) {
4449   - cssText += rule.cssText + "\n\n";
4450   - }
4451   - } catch (x) {
4452   - if (rule.type === CSSRule.KEYFRAMES_RULE && rule.cssRules) {
4453   - cssText += this.ieSafeCssTextFromKeyFrameRule(rule);
4454   - }
4455   - }
4456   - }
4457   - }, this);
4458   - }
4459   - return cssText;
4460   - },
4461   - ieSafeCssTextFromKeyFrameRule: function(rule) {
4462   - var cssText = "@keyframes " + rule.name + " {";
4463   - Array.prototype.forEach.call(rule.cssRules, function(rule) {
4464   - cssText += " " + rule.keyText + " {" + rule.style.cssText + "}";
4465   - });
4466   - cssText += " }";
4467   - return cssText;
4468   - },
4469   - scopeSelector: function(selector, scopeSelector, strict) {
4470   - var r = [], parts = selector.split(",");
4471   - parts.forEach(function(p) {
4472   - p = p.trim();
4473   - if (this.selectorNeedsScoping(p, scopeSelector)) {
4474   - p = strict && !p.match(polyfillHostNoCombinator) ? this.applyStrictSelectorScope(p, scopeSelector) : this.applySelectorScope(p, scopeSelector);
4475   - }
4476   - r.push(p);
4477   - }, this);
4478   - return r.join(", ");
4479   - },
4480   - selectorNeedsScoping: function(selector, scopeSelector) {
4481   - if (Array.isArray(scopeSelector)) {
4482   - return true;
4483   - }
4484   - var re = this.makeScopeMatcher(scopeSelector);
4485   - return !selector.match(re);
4486   - },
4487   - makeScopeMatcher: function(scopeSelector) {
4488   - scopeSelector = scopeSelector.replace(/\[/g, "\\[").replace(/\]/g, "\\]");
4489   - return new RegExp("^(" + scopeSelector + ")" + selectorReSuffix, "m");
4490   - },
4491   - applySelectorScope: function(selector, selectorScope) {
4492   - return Array.isArray(selectorScope) ? this.applySelectorScopeList(selector, selectorScope) : this.applySimpleSelectorScope(selector, selectorScope);
4493   - },
4494   - applySelectorScopeList: function(selector, scopeSelectorList) {
4495   - var r = [];
4496   - for (var i = 0, s; s = scopeSelectorList[i]; i++) {
4497   - r.push(this.applySimpleSelectorScope(selector, s));
4498   - }
4499   - return r.join(", ");
4500   - },
4501   - applySimpleSelectorScope: function(selector, scopeSelector) {
4502   - if (selector.match(polyfillHostRe)) {
4503   - selector = selector.replace(polyfillHostNoCombinator, scopeSelector);
4504   - return selector.replace(polyfillHostRe, scopeSelector + " ");
4505   - } else {
4506   - return scopeSelector + " " + selector;
4507   - }
4508   - },
4509   - applyStrictSelectorScope: function(selector, scopeSelector) {
4510   - scopeSelector = scopeSelector.replace(/\[is=([^\]]*)\]/g, "$1");
4511   - var splits = [ " ", ">", "+", "~" ], scoped = selector, attrName = "[" + scopeSelector + "]";
4512   - splits.forEach(function(sep) {
4513   - var parts = scoped.split(sep);
4514   - scoped = parts.map(function(p) {
4515   - var t = p.trim().replace(polyfillHostRe, "");
4516   - if (t && splits.indexOf(t) < 0 && t.indexOf(attrName) < 0) {
4517   - p = t.replace(/([^:]*)(:*)(.*)/, "$1" + attrName + "$2$3");
4518   - }
4519   - return p;
4520   - }).join(sep);
4521   - });
4522   - return scoped;
4523   - },
4524   - insertPolyfillHostInCssText: function(selector) {
4525   - return selector.replace(colonHostContextRe, polyfillHostContext).replace(colonHostRe, polyfillHost);
4526   - },
4527   - propertiesFromRule: function(rule) {
4528   - var cssText = rule.style.cssText;
4529   - if (rule.style.content && !rule.style.content.match(/['"]+|attr/)) {
4530   - cssText = cssText.replace(/content:[^;]*;/g, "content: '" + rule.style.content + "';");
4531   - }
4532   - var style = rule.style;
4533   - for (var i in style) {
4534   - if (style[i] === "initial") {
4535   - cssText += i + ": initial; ";
4536   - }
4537   - }
4538   - return cssText;
4539   - },
4540   - replaceTextInStyles: function(styles, action) {
4541   - if (styles && action) {
4542   - if (!(styles instanceof Array)) {
4543   - styles = [ styles ];
4544   - }
4545   - Array.prototype.forEach.call(styles, function(s) {
4546   - s.textContent = action.call(this, s.textContent);
4547   - }, this);
4548   - }
4549   - },
4550   - addCssToDocument: function(cssText, name) {
4551   - if (cssText.match("@import")) {
4552   - addOwnSheet(cssText, name);
4553   - } else {
4554   - addCssToDocument(cssText);
4555   - }
4556   - }
4557   - };
4558   - var selectorRe = /([^{]*)({[\s\S]*?})/gim, cssCommentRe = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//gim, cssCommentNextSelectorRe = /\/\*\s*@polyfill ([^*]*\*+([^/*][^*]*\*+)*\/)([^{]*?){/gim, cssContentNextSelectorRe = /polyfill-next-selector[^}]*content\:[\s]*?['"](.*?)['"][;\s]*}([^{]*?){/gim, cssCommentRuleRe = /\/\*\s@polyfill-rule([^*]*\*+([^/*][^*]*\*+)*)\//gim, cssContentRuleRe = /(polyfill-rule)[^}]*(content\:[\s]*['"](.*?)['"])[;\s]*[^}]*}/gim, cssCommentUnscopedRuleRe = /\/\*\s@polyfill-unscoped-rule([^*]*\*+([^/*][^*]*\*+)*)\//gim, cssContentUnscopedRuleRe = /(polyfill-unscoped-rule)[^}]*(content\:[\s]*['"](.*?)['"])[;\s]*[^}]*}/gim, cssPseudoRe = /::(x-[^\s{,(]*)/gim, cssPartRe = /::part\(([^)]*)\)/gim, polyfillHost = "-shadowcsshost", polyfillHostContext = "-shadowcsscontext", parenSuffix = ")(?:\\((" + "(?:\\([^)(]*\\)|[^)(]*)+?" + ")\\))?([^,{]*)";
4559   - var cssColonHostRe = new RegExp("(" + polyfillHost + parenSuffix, "gim"), cssColonHostContextRe = new RegExp("(" + polyfillHostContext + parenSuffix, "gim"), selectorReSuffix = "([>\\s~+[.,{:][\\s\\S]*)?$", colonHostRe = /\:host/gim, colonHostContextRe = /\:host-context/gim, polyfillHostNoCombinator = polyfillHost + "-no-combinator", polyfillHostRe = new RegExp(polyfillHost, "gim"), polyfillHostContextRe = new RegExp(polyfillHostContext, "gim"), shadowDOMSelectorsRe = [ /\^\^/g, /\^/g, /\/shadow\//g, /\/shadow-deep\//g, /::shadow/g, /\/deep\//g, /::content/g ];
4560   - function stylesToCssText(styles, preserveComments) {
4561   - var cssText = "";
4562   - Array.prototype.forEach.call(styles, function(s) {
4563   - cssText += s.textContent + "\n\n";
4564   - });
4565   - if (!preserveComments) {
4566   - cssText = cssText.replace(cssCommentRe, "");
4567   - }
4568   - return cssText;
4569   - }
4570   - function cssTextToStyle(cssText) {
4571   - var style = document.createElement("style");
4572   - style.textContent = cssText;
4573   - return style;
4574   - }
4575   - function cssToRules(cssText) {
4576   - var style = cssTextToStyle(cssText);
4577   - document.head.appendChild(style);
4578   - var rules = [];
4579   - if (style.sheet) {
4580   - try {
4581   - rules = style.sheet.cssRules;
4582   - } catch (e) {}
4583   - } else {
4584   - console.warn("sheet not found", style);
4585   - }
4586   - style.parentNode.removeChild(style);
4587   - return rules;
4588   - }
4589   - var frame = document.createElement("iframe");
4590   - frame.style.display = "none";
4591   - function initFrame() {
4592   - frame.initialized = true;
4593   - document.body.appendChild(frame);
4594   - var doc = frame.contentDocument;
4595   - var base = doc.createElement("base");
4596   - base.href = document.baseURI;
4597   - doc.head.appendChild(base);
4598   - }
4599   - function inFrame(fn) {
4600   - if (!frame.initialized) {
4601   - initFrame();
4602   - }
4603   - document.body.appendChild(frame);
4604   - fn(frame.contentDocument);
4605   - document.body.removeChild(frame);
4606   - }
4607   - var isChrome = navigator.userAgent.match("Chrome");
4608   - function withCssRules(cssText, callback) {
4609   - if (!callback) {
4610   - return;
4611   - }
4612   - var rules;
4613   - if (cssText.match("@import") && isChrome) {
4614   - var style = cssTextToStyle(cssText);
4615   - inFrame(function(doc) {
4616   - doc.head.appendChild(style.impl);
4617   - rules = Array.prototype.slice.call(style.sheet.cssRules, 0);
4618   - callback(rules);
4619   - });
4620   - } else {
4621   - rules = cssToRules(cssText);
4622   - callback(rules);
4623   - }
4624   - }
4625   - function rulesToCss(cssRules) {
4626   - for (var i = 0, css = []; i < cssRules.length; i++) {
4627   - css.push(cssRules[i].cssText);
4628   - }
4629   - return css.join("\n\n");
4630   - }
4631   - function addCssToDocument(cssText) {
4632   - if (cssText) {
4633   - getSheet().appendChild(document.createTextNode(cssText));
4634   - }
4635   - }
4636   - function addOwnSheet(cssText, name) {
4637   - var style = cssTextToStyle(cssText);
4638   - style.setAttribute(name, "");
4639   - style.setAttribute(SHIMMED_ATTRIBUTE, "");
4640   - document.head.appendChild(style);
4641   - }
4642   - var SHIM_ATTRIBUTE = "shim-shadowdom";
4643   - var SHIMMED_ATTRIBUTE = "shim-shadowdom-css";
4644   - var NO_SHIM_ATTRIBUTE = "no-shim";
4645   - var sheet;
4646   - function getSheet() {
4647   - if (!sheet) {
4648   - sheet = document.createElement("style");
4649   - sheet.setAttribute(SHIMMED_ATTRIBUTE, "");
4650   - sheet[SHIMMED_ATTRIBUTE] = true;
4651   - }
4652   - return sheet;
4653   - }
4654   - if (window.ShadowDOMPolyfill) {
4655   - addCssToDocument("style { display: none !important; }\n");
4656   - var doc = ShadowDOMPolyfill.wrap(document);
4657   - var head = doc.querySelector("head");
4658   - head.insertBefore(getSheet(), head.childNodes[0]);
4659   - document.addEventListener("DOMContentLoaded", function() {
4660   - var urlResolver = scope.urlResolver;
4661   - if (window.HTMLImports && !HTMLImports.useNative) {
4662   - var SHIM_SHEET_SELECTOR = "link[rel=stylesheet]" + "[" + SHIM_ATTRIBUTE + "]";
4663   - var SHIM_STYLE_SELECTOR = "style[" + SHIM_ATTRIBUTE + "]";
4664   - HTMLImports.importer.documentPreloadSelectors += "," + SHIM_SHEET_SELECTOR;
4665   - HTMLImports.importer.importsPreloadSelectors += "," + SHIM_SHEET_SELECTOR;
4666   - HTMLImports.parser.documentSelectors = [ HTMLImports.parser.documentSelectors, SHIM_SHEET_SELECTOR, SHIM_STYLE_SELECTOR ].join(",");
4667   - var originalParseGeneric = HTMLImports.parser.parseGeneric;
4668   - HTMLImports.parser.parseGeneric = function(elt) {
4669   - if (elt[SHIMMED_ATTRIBUTE]) {
4670   - return;
4671   - }
4672   - var style = elt.__importElement || elt;
4673   - if (!style.hasAttribute(SHIM_ATTRIBUTE)) {
4674   - originalParseGeneric.call(this, elt);
4675   - return;
4676   - }
4677   - if (elt.__resource) {
4678   - style = elt.ownerDocument.createElement("style");
4679   - style.textContent = elt.__resource;
4680   - }
4681   - HTMLImports.path.resolveUrlsInStyle(style);
4682   - style.textContent = ShadowCSS.shimStyle(style);
4683   - style.removeAttribute(SHIM_ATTRIBUTE, "");
4684   - style.setAttribute(SHIMMED_ATTRIBUTE, "");
4685   - style[SHIMMED_ATTRIBUTE] = true;
4686   - if (style.parentNode !== head) {
4687   - if (elt.parentNode === head) {
4688   - head.replaceChild(style, elt);
4689   - } else {
4690   - this.addElementToDocument(style);
4691   - }
4692   - }
4693   - style.__importParsed = true;
4694   - this.markParsingComplete(elt);
4695   - this.parseNext();
4696   - };
4697   - var hasResource = HTMLImports.parser.hasResource;
4698   - HTMLImports.parser.hasResource = function(node) {
4699   - if (node.localName === "link" && node.rel === "stylesheet" && node.hasAttribute(SHIM_ATTRIBUTE)) {
4700   - return node.__resource;
4701   - } else {
4702   - return hasResource.call(this, node);
4703   - }
4704   - };
4705   - }
4706   - });
4707   - }
4708   - scope.ShadowCSS = ShadowCSS;
4709   - })(window.WebComponents);
4710   -}
4711   -
4712   -(function(scope) {
4713   - if (window.ShadowDOMPolyfill) {
4714   - window.wrap = ShadowDOMPolyfill.wrapIfNeeded;
4715   - window.unwrap = ShadowDOMPolyfill.unwrapIfNeeded;
4716   - } else {
4717   - window.wrap = window.unwrap = function(n) {
4718   - return n;
4719   - };
4720   - }
4721   -})(window.WebComponents);
4722   -
4723   -window.HTMLImports = window.HTMLImports || {
4724   - flags: {}
4725   -};
4726   -
4727   -(function(scope) {
4728   - var IMPORT_LINK_TYPE = "import";
4729   - var useNative = Boolean(IMPORT_LINK_TYPE in document.createElement("link"));
4730   - var hasShadowDOMPolyfill = Boolean(window.ShadowDOMPolyfill);
4731   - var wrap = function(node) {
4732   - return hasShadowDOMPolyfill ? ShadowDOMPolyfill.wrapIfNeeded(node) : node;
4733   - };
4734   - var rootDocument = wrap(document);
4735   - var currentScriptDescriptor = {
4736   - get: function() {
4737   - var script = HTMLImports.currentScript || document.currentScript || (document.readyState !== "complete" ? document.scripts[document.scripts.length - 1] : null);
4738   - return wrap(script);
4739   - },
4740   - configurable: true
4741   - };
4742   - Object.defineProperty(document, "_currentScript", currentScriptDescriptor);
4743   - Object.defineProperty(rootDocument, "_currentScript", currentScriptDescriptor);
4744   - var isIE = /Trident|Edge/.test(navigator.userAgent);
4745   - function whenReady(callback, doc) {
4746   - doc = doc || rootDocument;
4747   - whenDocumentReady(function() {
4748   - watchImportsLoad(callback, doc);
4749   - }, doc);
4750   - }
4751   - var requiredReadyState = isIE ? "complete" : "interactive";
4752   - var READY_EVENT = "readystatechange";
4753   - function isDocumentReady(doc) {
4754   - return doc.readyState === "complete" || doc.readyState === requiredReadyState;
4755   - }
4756   - function whenDocumentReady(callback, doc) {
4757   - if (!isDocumentReady(doc)) {
4758   - var checkReady = function() {
4759   - if (doc.readyState === "complete" || doc.readyState === requiredReadyState) {
4760   - doc.removeEventListener(READY_EVENT, checkReady);
4761   - whenDocumentReady(callback, doc);
4762   - }
4763   - };
4764   - doc.addEventListener(READY_EVENT, checkReady);
4765   - } else if (callback) {
4766   - callback();
4767   - }
4768   - }
4769   - function markTargetLoaded(event) {
4770   - event.target.__loaded = true;
4771   - }
4772   - function watchImportsLoad(callback, doc) {
4773   - var imports = doc.querySelectorAll("link[rel=import]");
4774   - var loaded = 0, l = imports.length;
4775   - function checkDone(d) {
4776   - if (loaded == l && callback) {
4777   - callback();
4778   - }
4779   - }
4780   - function loadedImport(e) {
4781   - markTargetLoaded(e);
4782   - loaded++;
4783   - checkDone();
4784   - }
4785   - if (l) {
4786   - for (var i = 0, imp; i < l && (imp = imports[i]); i++) {
4787   - if (isImportLoaded(imp)) {
4788   - loadedImport.call(imp, {
4789   - target: imp
4790   - });
4791   - } else {
4792   - imp.addEventListener("load", loadedImport);
4793   - imp.addEventListener("error", loadedImport);
4794   - }
4795   - }
4796   - } else {
4797   - checkDone();
4798   - }
4799   - }
4800   - function isImportLoaded(link) {
4801   - return useNative ? link.__loaded || link.import && link.import.readyState !== "loading" : link.__importParsed;
4802   - }
4803   - if (useNative) {
4804   - new MutationObserver(function(mxns) {
4805   - for (var i = 0, l = mxns.length, m; i < l && (m = mxns[i]); i++) {
4806   - if (m.addedNodes) {
4807   - handleImports(m.addedNodes);
4808   - }
4809   - }
4810   - }).observe(document.head, {
4811   - childList: true
4812   - });
4813   - function handleImports(nodes) {
4814   - for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
4815   - if (isImport(n)) {
4816   - handleImport(n);
4817   - }
4818   - }
4819   - }
4820   - function isImport(element) {
4821   - return element.localName === "link" && element.rel === "import";
4822   - }
4823   - function handleImport(element) {
4824   - var loaded = element.import;
4825   - if (loaded) {
4826   - markTargetLoaded({
4827   - target: element
4828   - });
4829   - } else {
4830   - element.addEventListener("load", markTargetLoaded);
4831   - element.addEventListener("error", markTargetLoaded);
4832   - }
4833   - }
4834   - (function() {
4835   - if (document.readyState === "loading") {
4836   - var imports = document.querySelectorAll("link[rel=import]");
4837   - for (var i = 0, l = imports.length, imp; i < l && (imp = imports[i]); i++) {
4838   - handleImport(imp);
4839   - }
4840   - }
4841   - })();
4842   - }
4843   - whenReady(function() {
4844   - HTMLImports.ready = true;
4845   - HTMLImports.readyTime = new Date().getTime();
4846   - var evt = rootDocument.createEvent("CustomEvent");
4847   - evt.initCustomEvent("HTMLImportsLoaded", true, true, {});
4848   - rootDocument.dispatchEvent(evt);
4849   - });
4850   - scope.IMPORT_LINK_TYPE = IMPORT_LINK_TYPE;
4851   - scope.useNative = useNative;
4852   - scope.rootDocument = rootDocument;
4853   - scope.whenReady = whenReady;
4854   - scope.isIE = isIE;
4855   -})(HTMLImports);
4856   -
4857   -(function(scope) {
4858   - var modules = [];
4859   - var addModule = function(module) {
4860   - modules.push(module);
4861   - };
4862   - var initializeModules = function() {
4863   - modules.forEach(function(module) {
4864   - module(scope);
4865   - });
4866   - };
4867   - scope.addModule = addModule;
4868   - scope.initializeModules = initializeModules;
4869   -})(HTMLImports);
4870   -
4871   -HTMLImports.addModule(function(scope) {
4872   - var CSS_URL_REGEXP = /(url\()([^)]*)(\))/g;
4873   - var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g;
4874   - var path = {
4875   - resolveUrlsInStyle: function(style) {
4876   - var doc = style.ownerDocument;
4877   - var resolver = doc.createElement("a");
4878   - style.textContent = this.resolveUrlsInCssText(style.textContent, resolver);
4879   - return style;
4880   - },
4881   - resolveUrlsInCssText: function(cssText, urlObj) {
4882   - var r = this.replaceUrls(cssText, urlObj, CSS_URL_REGEXP);
4883   - r = this.replaceUrls(r, urlObj, CSS_IMPORT_REGEXP);
4884   - return r;
4885   - },
4886   - replaceUrls: function(text, urlObj, regexp) {
4887   - return text.replace(regexp, function(m, pre, url, post) {
4888   - var urlPath = url.replace(/["']/g, "");
4889   - urlObj.href = urlPath;
4890   - urlPath = urlObj.href;
4891   - return pre + "'" + urlPath + "'" + post;
4892   - });
4893   - }
4894   - };
4895   - scope.path = path;
4896   -});
4897   -
4898   -HTMLImports.addModule(function(scope) {
4899   - var xhr = {
4900   - async: true,
4901   - ok: function(request) {
4902   - return request.status >= 200 && request.status < 300 || request.status === 304 || request.status === 0;
4903   - },
4904   - load: function(url, next, nextContext) {
4905   - var request = new XMLHttpRequest();
4906   - if (scope.flags.debug || scope.flags.bust) {
4907   - url += "?" + Math.random();
4908   - }
4909   - request.open("GET", url, xhr.async);
4910   - request.addEventListener("readystatechange", function(e) {
4911   - if (request.readyState === 4) {
4912   - var locationHeader = request.getResponseHeader("Location");
4913   - var redirectedUrl = null;
4914   - if (locationHeader) {
4915   - var redirectedUrl = locationHeader.substr(0, 1) === "/" ? location.origin + locationHeader : locationHeader;
4916   - }
4917   - next.call(nextContext, !xhr.ok(request) && request, request.response || request.responseText, redirectedUrl);
4918   - }
4919   - });
4920   - request.send();
4921   - return request;
4922   - },
4923   - loadDocument: function(url, next, nextContext) {
4924   - this.load(url, next, nextContext).responseType = "document";
4925   - }
4926   - };
4927   - scope.xhr = xhr;
4928   -});
4929   -
4930   -HTMLImports.addModule(function(scope) {
4931   - var xhr = scope.xhr;
4932   - var flags = scope.flags;
4933   - var Loader = function(onLoad, onComplete) {
4934   - this.cache = {};
4935   - this.onload = onLoad;
4936   - this.oncomplete = onComplete;
4937   - this.inflight = 0;
4938   - this.pending = {};
4939   - };
4940   - Loader.prototype = {
4941   - addNodes: function(nodes) {
4942   - this.inflight += nodes.length;
4943   - for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
4944   - this.require(n);
4945   - }
4946   - this.checkDone();
4947   - },
4948   - addNode: function(node) {
4949   - this.inflight++;
4950   - this.require(node);
4951   - this.checkDone();
4952   - },
4953   - require: function(elt) {
4954   - var url = elt.src || elt.href;
4955   - elt.__nodeUrl = url;
4956   - if (!this.dedupe(url, elt)) {
4957   - this.fetch(url, elt);
4958   - }
4959   - },
4960   - dedupe: function(url, elt) {
4961   - if (this.pending[url]) {
4962   - this.pending[url].push(elt);
4963   - return true;
4964   - }
4965   - var resource;
4966   - if (this.cache[url]) {
4967   - this.onload(url, elt, this.cache[url]);
4968   - this.tail();
4969   - return true;
4970   - }
4971   - this.pending[url] = [ elt ];
4972   - return false;
4973   - },
4974   - fetch: function(url, elt) {
4975   - flags.load && console.log("fetch", url, elt);
4976   - if (!url) {
4977   - setTimeout(function() {
4978   - this.receive(url, elt, {
4979   - error: "href must be specified"
4980   - }, null);
4981   - }.bind(this), 0);
4982   - } else if (url.match(/^data:/)) {
4983   - var pieces = url.split(",");
4984   - var header = pieces[0];
4985   - var body = pieces[1];
4986   - if (header.indexOf(";base64") > -1) {
4987   - body = atob(body);
4988   - } else {
4989   - body = decodeURIComponent(body);
4990   - }
4991   - setTimeout(function() {
4992   - this.receive(url, elt, null, body);
4993   - }.bind(this), 0);
4994   - } else {
4995   - var receiveXhr = function(err, resource, redirectedUrl) {
4996   - this.receive(url, elt, err, resource, redirectedUrl);
4997   - }.bind(this);
4998   - xhr.load(url, receiveXhr);
4999   - }
5000   - },
5001   - receive: function(url, elt, err, resource, redirectedUrl) {
5002   - this.cache[url] = resource;
5003   - var $p = this.pending[url];
5004   - for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) {
5005   - this.onload(url, p, resource, err, redirectedUrl);
5006   - this.tail();
5007   - }
5008   - this.pending[url] = null;
5009   - },
5010   - tail: function() {
5011   - --this.inflight;
5012   - this.checkDone();
5013   - },
5014   - checkDone: function() {
5015   - if (!this.inflight) {
5016   - this.oncomplete();
5017   - }
5018   - }
5019   - };
5020   - scope.Loader = Loader;
5021   -});
5022   -
5023   -HTMLImports.addModule(function(scope) {
5024   - var Observer = function(addCallback) {
5025   - this.addCallback = addCallback;
5026   - this.mo = new MutationObserver(this.handler.bind(this));
5027   - };
5028   - Observer.prototype = {
5029   - handler: function(mutations) {
5030   - for (var i = 0, l = mutations.length, m; i < l && (m = mutations[i]); i++) {
5031   - if (m.type === "childList" && m.addedNodes.length) {
5032   - this.addedNodes(m.addedNodes);
5033   - }
5034   - }
5035   - },
5036   - addedNodes: function(nodes) {
5037   - if (this.addCallback) {
5038   - this.addCallback(nodes);
5039   - }
5040   - for (var i = 0, l = nodes.length, n, loading; i < l && (n = nodes[i]); i++) {
5041   - if (n.children && n.children.length) {
5042   - this.addedNodes(n.children);
5043   - }
5044   - }
5045   - },
5046   - observe: function(root) {
5047   - this.mo.observe(root, {
5048   - childList: true,
5049   - subtree: true
5050   - });
5051   - }
5052   - };
5053   - scope.Observer = Observer;
5054   -});
5055   -
5056   -HTMLImports.addModule(function(scope) {
5057   - var path = scope.path;
5058   - var rootDocument = scope.rootDocument;
5059   - var flags = scope.flags;
5060   - var isIE = scope.isIE;
5061   - var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE;
5062   - var IMPORT_SELECTOR = "link[rel=" + IMPORT_LINK_TYPE + "]";
5063   - var importParser = {
5064   - documentSelectors: IMPORT_SELECTOR,
5065   - importsSelectors: [ IMPORT_SELECTOR, "link[rel=stylesheet]", "style", "script:not([type])", 'script[type="text/javascript"]' ].join(","),
5066   - map: {
5067   - link: "parseLink",
5068   - script: "parseScript",
5069   - style: "parseStyle"
5070   - },
5071   - dynamicElements: [],
5072   - parseNext: function() {
5073   - var next = this.nextToParse();
5074   - if (next) {
5075   - this.parse(next);
5076   - }
5077   - },
5078   - parse: function(elt) {
5079   - if (this.isParsed(elt)) {
5080   - flags.parse && console.log("[%s] is already parsed", elt.localName);
5081   - return;
5082   - }
5083   - var fn = this[this.map[elt.localName]];
5084   - if (fn) {
5085   - this.markParsing(elt);
5086   - fn.call(this, elt);
5087   - }
5088   - },
5089   - parseDynamic: function(elt, quiet) {
5090   - this.dynamicElements.push(elt);
5091   - if (!quiet) {
5092   - this.parseNext();
5093   - }
5094   - },
5095   - markParsing: function(elt) {
5096   - flags.parse && console.log("parsing", elt);
5097   - this.parsingElement = elt;
5098   - },
5099   - markParsingComplete: function(elt) {
5100   - elt.__importParsed = true;
5101   - this.markDynamicParsingComplete(elt);
5102   - if (elt.__importElement) {
5103   - elt.__importElement.__importParsed = true;
5104   - this.markDynamicParsingComplete(elt.__importElement);
5105   - }
5106   - this.parsingElement = null;
5107   - flags.parse && console.log("completed", elt);
5108   - },
5109   - markDynamicParsingComplete: function(elt) {
5110   - var i = this.dynamicElements.indexOf(elt);
5111   - if (i >= 0) {
5112   - this.dynamicElements.splice(i, 1);
5113   - }
5114   - },
5115   - parseImport: function(elt) {
5116   - if (HTMLImports.__importsParsingHook) {
5117   - HTMLImports.__importsParsingHook(elt);
5118   - }
5119   - if (elt.import) {
5120   - elt.import.__importParsed = true;
5121   - }
5122   - this.markParsingComplete(elt);
5123   - if (elt.__resource && !elt.__error) {
5124   - elt.dispatchEvent(new CustomEvent("load", {
5125   - bubbles: false
5126   - }));
5127   - } else {
5128   - elt.dispatchEvent(new CustomEvent("error", {
5129   - bubbles: false
5130   - }));
5131   - }
5132   - if (elt.__pending) {
5133   - var fn;
5134   - while (elt.__pending.length) {
5135   - fn = elt.__pending.shift();
5136   - if (fn) {
5137   - fn({
5138   - target: elt
5139   - });
5140   - }
5141   - }
5142   - }
5143   - this.parseNext();
5144   - },
5145   - parseLink: function(linkElt) {
5146   - if (nodeIsImport(linkElt)) {
5147   - this.parseImport(linkElt);
5148   - } else {
5149   - linkElt.href = linkElt.href;
5150   - this.parseGeneric(linkElt);
5151   - }
5152   - },
5153   - parseStyle: function(elt) {
5154   - var src = elt;
5155   - elt = cloneStyle(elt);
5156   - elt.__importElement = src;
5157   - this.parseGeneric(elt);
5158   - },
5159   - parseGeneric: function(elt) {
5160   - this.trackElement(elt);
5161   - this.addElementToDocument(elt);
5162   - },
5163   - rootImportForElement: function(elt) {
5164   - var n = elt;
5165   - while (n.ownerDocument.__importLink) {
5166   - n = n.ownerDocument.__importLink;
5167   - }
5168   - return n;
5169   - },
5170   - addElementToDocument: function(elt) {
5171   - var port = this.rootImportForElement(elt.__importElement || elt);
5172   - port.parentNode.insertBefore(elt, port);
5173   - },
5174   - trackElement: function(elt, callback) {
5175   - var self = this;
5176   - var done = function(e) {
5177   - if (callback) {
5178   - callback(e);
5179   - }
5180   - self.markParsingComplete(elt);
5181   - self.parseNext();
5182   - };
5183   - elt.addEventListener("load", done);
5184   - elt.addEventListener("error", done);
5185   - if (isIE && elt.localName === "style") {
5186   - var fakeLoad = false;
5187   - if (elt.textContent.indexOf("@import") == -1) {
5188   - fakeLoad = true;
5189   - } else if (elt.sheet) {
5190   - fakeLoad = true;
5191   - var csr = elt.sheet.cssRules;
5192   - var len = csr ? csr.length : 0;
5193   - for (var i = 0, r; i < len && (r = csr[i]); i++) {
5194   - if (r.type === CSSRule.IMPORT_RULE) {
5195   - fakeLoad = fakeLoad && Boolean(r.styleSheet);
5196   - }
5197   - }
5198   - }
5199   - if (fakeLoad) {
5200   - elt.dispatchEvent(new CustomEvent("load", {
5201   - bubbles: false
5202   - }));
5203   - }
5204   - }
5205   - },
5206   - parseScript: function(scriptElt) {
5207   - var script = document.createElement("script");
5208   - script.__importElement = scriptElt;
5209   - script.src = scriptElt.src ? scriptElt.src : generateScriptDataUrl(scriptElt);
5210   - scope.currentScript = scriptElt;
5211   - this.trackElement(script, function(e) {
5212   - script.parentNode.removeChild(script);
5213   - scope.currentScript = null;
5214   - });
5215   - this.addElementToDocument(script);
5216   - },
5217   - nextToParse: function() {
5218   - this._mayParse = [];
5219   - return !this.parsingElement && (this.nextToParseInDoc(rootDocument) || this.nextToParseDynamic());
5220   - },
5221   - nextToParseInDoc: function(doc, link) {
5222   - if (doc && this._mayParse.indexOf(doc) < 0) {
5223   - this._mayParse.push(doc);
5224   - var nodes = doc.querySelectorAll(this.parseSelectorsForNode(doc));
5225   - for (var i = 0, l = nodes.length, p = 0, n; i < l && (n = nodes[i]); i++) {
5226   - if (!this.isParsed(n)) {
5227   - if (this.hasResource(n)) {
5228   - return nodeIsImport(n) ? this.nextToParseInDoc(n.import, n) : n;
5229   - } else {
5230   - return;
5231   - }
5232   - }
5233   - }
5234   - }
5235   - return link;
5236   - },
5237   - nextToParseDynamic: function() {
5238   - return this.dynamicElements[0];
5239   - },
5240   - parseSelectorsForNode: function(node) {
5241   - var doc = node.ownerDocument || node;
5242   - return doc === rootDocument ? this.documentSelectors : this.importsSelectors;
5243   - },
5244   - isParsed: function(node) {
5245   - return node.__importParsed;
5246   - },
5247   - needsDynamicParsing: function(elt) {
5248   - return this.dynamicElements.indexOf(elt) >= 0;
5249   - },
5250   - hasResource: function(node) {
5251   - if (nodeIsImport(node) && node.import === undefined) {
5252   - return false;
5253   - }
5254   - return true;
5255   - }
5256   - };
5257   - function nodeIsImport(elt) {
5258   - return elt.localName === "link" && elt.rel === IMPORT_LINK_TYPE;
5259   - }
5260   - function generateScriptDataUrl(script) {
5261   - var scriptContent = generateScriptContent(script);
5262   - return "data:text/javascript;charset=utf-8," + encodeURIComponent(scriptContent);
5263   - }
5264   - function generateScriptContent(script) {
5265   - return script.textContent + generateSourceMapHint(script);
5266   - }
5267   - function generateSourceMapHint(script) {
5268   - var owner = script.ownerDocument;
5269   - owner.__importedScripts = owner.__importedScripts || 0;
5270   - var moniker = script.ownerDocument.baseURI;
5271   - var num = owner.__importedScripts ? "-" + owner.__importedScripts : "";
5272   - owner.__importedScripts++;
5273   - return "\n//# sourceURL=" + moniker + num + ".js\n";
5274   - }
5275   - function cloneStyle(style) {
5276   - var clone = style.ownerDocument.createElement("style");
5277   - clone.textContent = style.textContent;
5278   - path.resolveUrlsInStyle(clone);
5279   - return clone;
5280   - }
5281   - scope.parser = importParser;
5282   - scope.IMPORT_SELECTOR = IMPORT_SELECTOR;
5283   -});
5284   -
5285   -HTMLImports.addModule(function(scope) {
5286   - var flags = scope.flags;
5287   - var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE;
5288   - var IMPORT_SELECTOR = scope.IMPORT_SELECTOR;
5289   - var rootDocument = scope.rootDocument;
5290   - var Loader = scope.Loader;
5291   - var Observer = scope.Observer;
5292   - var parser = scope.parser;
5293   - var importer = {
5294   - documents: {},
5295   - documentPreloadSelectors: IMPORT_SELECTOR,
5296   - importsPreloadSelectors: [ IMPORT_SELECTOR ].join(","),
5297   - loadNode: function(node) {
5298   - importLoader.addNode(node);
5299   - },
5300   - loadSubtree: function(parent) {
5301   - var nodes = this.marshalNodes(parent);
5302   - importLoader.addNodes(nodes);
5303   - },
5304   - marshalNodes: function(parent) {
5305   - return parent.querySelectorAll(this.loadSelectorsForNode(parent));
5306   - },
5307   - loadSelectorsForNode: function(node) {
5308   - var doc = node.ownerDocument || node;
5309   - return doc === rootDocument ? this.documentPreloadSelectors : this.importsPreloadSelectors;
5310   - },
5311   - loaded: function(url, elt, resource, err, redirectedUrl) {
5312   - flags.load && console.log("loaded", url, elt);
5313   - elt.__resource = resource;
5314   - elt.__error = err;
5315   - if (isImportLink(elt)) {
5316   - var doc = this.documents[url];
5317   - if (doc === undefined) {
5318   - doc = err ? null : makeDocument(resource, redirectedUrl || url);
5319   - if (doc) {
5320   - doc.__importLink = elt;
5321   - this.bootDocument(doc);
5322   - }
5323   - this.documents[url] = doc;
5324   - }
5325   - elt.import = doc;
5326   - }
5327   - parser.parseNext();
5328   - },
5329   - bootDocument: function(doc) {
5330   - this.loadSubtree(doc);
5331   - this.observer.observe(doc);
5332   - parser.parseNext();
5333   - },
5334   - loadedAll: function() {
5335   - parser.parseNext();
5336   - }
5337   - };
5338   - var importLoader = new Loader(importer.loaded.bind(importer), importer.loadedAll.bind(importer));
5339   - importer.observer = new Observer();
5340   - function isImportLink(elt) {
5341   - return isLinkRel(elt, IMPORT_LINK_TYPE);
5342   - }
5343   - function isLinkRel(elt, rel) {
5344   - return elt.localName === "link" && elt.getAttribute("rel") === rel;
5345   - }
5346   - function hasBaseURIAccessor(doc) {
5347   - return !!Object.getOwnPropertyDescriptor(doc, "baseURI");
5348   - }
5349   - function makeDocument(resource, url) {
5350   - var doc = document.implementation.createHTMLDocument(IMPORT_LINK_TYPE);
5351   - doc._URL = url;
5352   - var base = doc.createElement("base");
5353   - base.setAttribute("href", url);
5354   - if (!doc.baseURI && !hasBaseURIAccessor(doc)) {
5355   - Object.defineProperty(doc, "baseURI", {
5356   - value: url
5357   - });
5358   - }
5359   - var meta = doc.createElement("meta");
5360   - meta.setAttribute("charset", "utf-8");
5361   - doc.head.appendChild(meta);
5362   - doc.head.appendChild(base);
5363   - doc.body.innerHTML = resource;
5364   - if (window.HTMLTemplateElement && HTMLTemplateElement.bootstrap) {
5365   - HTMLTemplateElement.bootstrap(doc);
5366   - }
5367   - return doc;
5368   - }
5369   - if (!document.baseURI) {
5370   - var baseURIDescriptor = {
5371   - get: function() {
5372   - var base = document.querySelector("base");
5373   - return base ? base.href : window.location.href;
5374   - },
5375   - configurable: true
5376   - };
5377   - Object.defineProperty(document, "baseURI", baseURIDescriptor);
5378   - Object.defineProperty(rootDocument, "baseURI", baseURIDescriptor);
5379   - }
5380   - scope.importer = importer;
5381   - scope.importLoader = importLoader;
5382   -});
5383   -
5384   -HTMLImports.addModule(function(scope) {
5385   - var parser = scope.parser;
5386   - var importer = scope.importer;
5387   - var dynamic = {
5388   - added: function(nodes) {
5389   - var owner, parsed, loading;
5390   - for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
5391   - if (!owner) {
5392   - owner = n.ownerDocument;
5393   - parsed = parser.isParsed(owner);
5394   - }
5395   - loading = this.shouldLoadNode(n);
5396   - if (loading) {
5397   - importer.loadNode(n);
5398   - }
5399   - if (this.shouldParseNode(n) && parsed) {
5400   - parser.parseDynamic(n, loading);
5401   - }
5402   - }
5403   - },
5404   - shouldLoadNode: function(node) {
5405   - return node.nodeType === 1 && matches.call(node, importer.loadSelectorsForNode(node));
5406   - },
5407   - shouldParseNode: function(node) {
5408   - return node.nodeType === 1 && matches.call(node, parser.parseSelectorsForNode(node));
5409   - }
5410   - };
5411   - importer.observer.addCallback = dynamic.added.bind(dynamic);
5412   - var matches = HTMLElement.prototype.matches || HTMLElement.prototype.matchesSelector || HTMLElement.prototype.webkitMatchesSelector || HTMLElement.prototype.mozMatchesSelector || HTMLElement.prototype.msMatchesSelector;
5413   -});
5414   -
5415   -(function(scope) {
5416   - var initializeModules = scope.initializeModules;
5417   - var isIE = scope.isIE;
5418   - if (scope.useNative) {
5419   - return;
5420   - }
5421   - if (isIE && typeof window.CustomEvent !== "function") {
5422   - window.CustomEvent = function(inType, params) {
5423   - params = params || {};
5424   - var e = document.createEvent("CustomEvent");
5425   - e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable), params.detail);
5426   - return e;
5427   - };
5428   - window.CustomEvent.prototype = window.Event.prototype;
5429   - }
5430   - initializeModules();
5431   - var rootDocument = scope.rootDocument;
5432   - function bootstrap() {
5433   - HTMLImports.importer.bootDocument(rootDocument);
5434   - }
5435   - if (document.readyState === "complete" || document.readyState === "interactive" && !window.attachEvent) {
5436   - bootstrap();
5437   - } else {
5438   - document.addEventListener("DOMContentLoaded", bootstrap);
5439   - }
5440   -})(HTMLImports);
5441   -
5442   -window.CustomElements = window.CustomElements || {
5443   - flags: {}
5444   -};
5445   -
5446   -(function(scope) {
5447   - var flags = scope.flags;
5448   - var modules = [];
5449   - var addModule = function(module) {
5450   - modules.push(module);
5451   - };
5452   - var initializeModules = function() {
5453   - modules.forEach(function(module) {
5454   - module(scope);
5455   - });
5456   - };
5457   - scope.addModule = addModule;
5458   - scope.initializeModules = initializeModules;
5459   - scope.hasNative = Boolean(document.registerElement);
5460   - scope.useNative = !flags.register && scope.hasNative && !window.ShadowDOMPolyfill && (!window.HTMLImports || HTMLImports.useNative);
5461   -})(CustomElements);
5462   -
5463   -CustomElements.addModule(function(scope) {
5464   - var IMPORT_LINK_TYPE = window.HTMLImports ? HTMLImports.IMPORT_LINK_TYPE : "none";
5465   - function forSubtree(node, cb) {
5466   - findAllElements(node, function(e) {
5467   - if (cb(e)) {
5468   - return true;
5469   - }
5470   - forRoots(e, cb);
5471   - });
5472   - forRoots(node, cb);
5473   - }
5474   - function findAllElements(node, find, data) {
5475   - var e = node.firstElementChild;
5476   - if (!e) {
5477   - e = node.firstChild;
5478   - while (e && e.nodeType !== Node.ELEMENT_NODE) {
5479   - e = e.nextSibling;
5480   - }
5481   - }
5482   - while (e) {
5483   - if (find(e, data) !== true) {
5484   - findAllElements(e, find, data);
5485   - }
5486   - e = e.nextElementSibling;
5487   - }
5488   - return null;
5489   - }
5490   - function forRoots(node, cb) {
5491   - var root = node.shadowRoot;
5492   - while (root) {
5493   - forSubtree(root, cb);
5494   - root = root.olderShadowRoot;
5495   - }
5496   - }
5497   - var processingDocuments;
5498   - function forDocumentTree(doc, cb) {
5499   - processingDocuments = [];
5500   - _forDocumentTree(doc, cb);
5501   - processingDocuments = null;
5502   - }
5503   - function _forDocumentTree(doc, cb) {
5504   - doc = wrap(doc);
5505   - if (processingDocuments.indexOf(doc) >= 0) {
5506   - return;
5507   - }
5508   - processingDocuments.push(doc);
5509   - var imports = doc.querySelectorAll("link[rel=" + IMPORT_LINK_TYPE + "]");
5510   - for (var i = 0, l = imports.length, n; i < l && (n = imports[i]); i++) {
5511   - if (n.import) {
5512   - _forDocumentTree(n.import, cb);
5513   - }
5514   - }
5515   - cb(doc);
5516   - }
5517   - scope.forDocumentTree = forDocumentTree;
5518   - scope.forSubtree = forSubtree;
5519   -});
5520   -
5521   -CustomElements.addModule(function(scope) {
5522   - var flags = scope.flags;
5523   - var forSubtree = scope.forSubtree;
5524   - var forDocumentTree = scope.forDocumentTree;
5525   - function addedNode(node) {
5526   - return added(node) || addedSubtree(node);
5527   - }
5528   - function added(node) {
5529   - if (scope.upgrade(node)) {
5530   - return true;
5531   - }
5532   - attached(node);
5533   - }
5534   - function addedSubtree(node) {
5535   - forSubtree(node, function(e) {
5536   - if (added(e)) {
5537   - return true;
5538   - }
5539   - });
5540   - }
5541   - function attachedNode(node) {
5542   - attached(node);
5543   - if (inDocument(node)) {
5544   - forSubtree(node, function(e) {
5545   - attached(e);
5546   - });
5547   - }
5548   - }
5549   - var hasPolyfillMutations = !window.MutationObserver || window.MutationObserver === window.JsMutationObserver;
5550   - scope.hasPolyfillMutations = hasPolyfillMutations;
5551   - var isPendingMutations = false;
5552   - var pendingMutations = [];
5553   - function deferMutation(fn) {
5554   - pendingMutations.push(fn);
5555   - if (!isPendingMutations) {
5556   - isPendingMutations = true;
5557   - setTimeout(takeMutations);
5558   - }
5559   - }
5560   - function takeMutations() {
5561   - isPendingMutations = false;
5562   - var $p = pendingMutations;
5563   - for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) {
5564   - p();
5565   - }
5566   - pendingMutations = [];
5567   - }
5568   - function attached(element) {
5569   - if (hasPolyfillMutations) {
5570   - deferMutation(function() {
5571   - _attached(element);
5572   - });
5573   - } else {
5574   - _attached(element);
5575   - }
5576   - }
5577   - function _attached(element) {
5578   - if (element.__upgraded__ && (element.attachedCallback || element.detachedCallback)) {
5579   - if (!element.__attached && inDocument(element)) {
5580   - element.__attached = true;
5581   - if (element.attachedCallback) {
5582   - element.attachedCallback();
5583   - }
5584   - }
5585   - }
5586   - }
5587   - function detachedNode(node) {
5588   - detached(node);
5589   - forSubtree(node, function(e) {
5590   - detached(e);
5591   - });
5592   - }
5593   - function detached(element) {
5594   - if (hasPolyfillMutations) {
5595   - deferMutation(function() {
5596   - _detached(element);
5597   - });
5598   - } else {
5599   - _detached(element);
5600   - }
5601   - }
5602   - function _detached(element) {
5603   - if (element.__upgraded__ && (element.attachedCallback || element.detachedCallback)) {
5604   - if (element.__attached && !inDocument(element)) {
5605   - element.__attached = false;
5606   - if (element.detachedCallback) {
5607   - element.detachedCallback();
5608   - }
5609   - }
5610   - }
5611   - }
5612   - function inDocument(element) {
5613   - var p = element;
5614   - var doc = wrap(document);
5615   - while (p) {
5616   - if (p == doc) {
5617   - return true;
5618   - }
5619   - p = p.parentNode || p.host;
5620   - }
5621   - }
5622   - function watchShadow(node) {
5623   - if (node.shadowRoot && !node.shadowRoot.__watched) {
5624   - flags.dom && console.log("watching shadow-root for: ", node.localName);
5625   - var root = node.shadowRoot;
5626   - while (root) {
5627   - observe(root);
5628   - root = root.olderShadowRoot;
5629   - }
5630   - }
5631   - }
5632   - function handler(mutations) {
5633   - if (flags.dom) {
5634   - var mx = mutations[0];
5635   - if (mx && mx.type === "childList" && mx.addedNodes) {
5636   - if (mx.addedNodes) {
5637   - var d = mx.addedNodes[0];
5638   - while (d && d !== document && !d.host) {
5639   - d = d.parentNode;
5640   - }
5641   - var u = d && (d.URL || d._URL || d.host && d.host.localName) || "";
5642   - u = u.split("/?").shift().split("/").pop();
5643   - }
5644   - }
5645   - console.group("mutations (%d) [%s]", mutations.length, u || "");
5646   - }
5647   - mutations.forEach(function(mx) {
5648   - if (mx.type === "childList") {
5649   - forEach(mx.addedNodes, function(n) {
5650   - if (!n.localName) {
5651   - return;
5652   - }
5653   - addedNode(n);
5654   - });
5655   - forEach(mx.removedNodes, function(n) {
5656   - if (!n.localName) {
5657   - return;
5658   - }
5659   - detachedNode(n);
5660   - });
5661   - }
5662   - });
5663   - flags.dom && console.groupEnd();
5664   - }
5665   - function takeRecords(node) {
5666   - node = wrap(node);
5667   - if (!node) {
5668   - node = wrap(document);
5669   - }
5670   - while (node.parentNode) {
5671   - node = node.parentNode;
5672   - }
5673   - var observer = node.__observer;
5674   - if (observer) {
5675   - handler(observer.takeRecords());
5676   - takeMutations();
5677   - }
5678   - }
5679   - var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach);
5680   - function observe(inRoot) {
5681   - if (inRoot.__observer) {
5682   - return;
5683   - }
5684   - var observer = new MutationObserver(handler);
5685   - observer.observe(inRoot, {
5686   - childList: true,
5687   - subtree: true
5688   - });
5689   - inRoot.__observer = observer;
5690   - }
5691   - function upgradeDocument(doc) {
5692   - doc = wrap(doc);
5693   - flags.dom && console.group("upgradeDocument: ", doc.baseURI.split("/").pop());
5694   - addedNode(doc);
5695   - observe(doc);
5696   - flags.dom && console.groupEnd();
5697   - }
5698   - function upgradeDocumentTree(doc) {
5699   - forDocumentTree(doc, upgradeDocument);
5700   - }
5701   - var originalCreateShadowRoot = Element.prototype.createShadowRoot;
5702   - if (originalCreateShadowRoot) {
5703   - Element.prototype.createShadowRoot = function() {
5704   - var root = originalCreateShadowRoot.call(this);
5705   - CustomElements.watchShadow(this);
5706   - return root;
5707   - };
5708   - }
5709   - scope.watchShadow = watchShadow;
5710   - scope.upgradeDocumentTree = upgradeDocumentTree;
5711   - scope.upgradeSubtree = addedSubtree;
5712   - scope.upgradeAll = addedNode;
5713   - scope.attachedNode = attachedNode;
5714   - scope.takeRecords = takeRecords;
5715   -});
5716   -
5717   -CustomElements.addModule(function(scope) {
5718   - var flags = scope.flags;
5719   - function upgrade(node) {
5720   - if (!node.__upgraded__ && node.nodeType === Node.ELEMENT_NODE) {
5721   - var is = node.getAttribute("is");
5722   - var definition = scope.getRegisteredDefinition(is || node.localName);
5723   - if (definition) {
5724   - if (is && definition.tag == node.localName) {
5725   - return upgradeWithDefinition(node, definition);
5726   - } else if (!is && !definition.extends) {
5727   - return upgradeWithDefinition(node, definition);
5728   - }
5729   - }
5730   - }
5731   - }
5732   - function upgradeWithDefinition(element, definition) {
5733   - flags.upgrade && console.group("upgrade:", element.localName);
5734   - if (definition.is) {
5735   - element.setAttribute("is", definition.is);
5736   - }
5737   - implementPrototype(element, definition);
5738   - element.__upgraded__ = true;
5739   - created(element);
5740   - scope.attachedNode(element);
5741   - scope.upgradeSubtree(element);
5742   - flags.upgrade && console.groupEnd();
5743   - return element;
5744   - }
5745   - function implementPrototype(element, definition) {
5746   - if (Object.__proto__) {
5747   - element.__proto__ = definition.prototype;
5748   - } else {
5749   - customMixin(element, definition.prototype, definition.native);
5750   - element.__proto__ = definition.prototype;
5751   - }
5752   - }
5753   - function customMixin(inTarget, inSrc, inNative) {
5754   - var used = {};
5755   - var p = inSrc;
5756   - while (p !== inNative && p !== HTMLElement.prototype) {
5757   - var keys = Object.getOwnPropertyNames(p);
5758   - for (var i = 0, k; k = keys[i]; i++) {
5759   - if (!used[k]) {
5760   - Object.defineProperty(inTarget, k, Object.getOwnPropertyDescriptor(p, k));
5761   - used[k] = 1;
5762   - }
5763   - }
5764   - p = Object.getPrototypeOf(p);
5765   - }
5766   - }
5767   - function created(element) {
5768   - if (element.createdCallback) {
5769   - element.createdCallback();
5770   - }
5771   - }
5772   - scope.upgrade = upgrade;
5773   - scope.upgradeWithDefinition = upgradeWithDefinition;
5774   - scope.implementPrototype = implementPrototype;
5775   -});
5776   -
5777   -CustomElements.addModule(function(scope) {
5778   - var upgradeDocumentTree = scope.upgradeDocumentTree;
5779   - var upgrade = scope.upgrade;
5780   - var upgradeWithDefinition = scope.upgradeWithDefinition;
5781   - var implementPrototype = scope.implementPrototype;
5782   - var useNative = scope.useNative;
5783   - function register(name, options) {
5784   - var definition = options || {};
5785   - if (!name) {
5786   - throw new Error("document.registerElement: first argument `name` must not be empty");
5787   - }
5788   - if (name.indexOf("-") < 0) {
5789   - throw new Error("document.registerElement: first argument ('name') must contain a dash ('-'). Argument provided was '" + String(name) + "'.");
5790   - }
5791   - if (isReservedTag(name)) {
5792   - throw new Error("Failed to execute 'registerElement' on 'Document': Registration failed for type '" + String(name) + "'. The type name is invalid.");
5793   - }
5794   - if (getRegisteredDefinition(name)) {
5795   - throw new Error("DuplicateDefinitionError: a type with name '" + String(name) + "' is already registered");
5796   - }
5797   - if (!definition.prototype) {
5798   - definition.prototype = Object.create(HTMLElement.prototype);
5799   - }
5800   - definition.__name = name.toLowerCase();
5801   - definition.lifecycle = definition.lifecycle || {};
5802   - definition.ancestry = ancestry(definition.extends);
5803   - resolveTagName(definition);
5804   - resolvePrototypeChain(definition);
5805   - overrideAttributeApi(definition.prototype);
5806   - registerDefinition(definition.__name, definition);
5807   - definition.ctor = generateConstructor(definition);
5808   - definition.ctor.prototype = definition.prototype;
5809   - definition.prototype.constructor = definition.ctor;
5810   - if (scope.ready) {
5811   - upgradeDocumentTree(document);
5812   - }
5813   - return definition.ctor;
5814   - }
5815   - function overrideAttributeApi(prototype) {
5816   - if (prototype.setAttribute._polyfilled) {
5817   - return;
5818   - }
5819   - var setAttribute = prototype.setAttribute;
5820   - prototype.setAttribute = function(name, value) {
5821   - changeAttribute.call(this, name, value, setAttribute);
5822   - };
5823   - var removeAttribute = prototype.removeAttribute;
5824   - prototype.removeAttribute = function(name) {
5825   - changeAttribute.call(this, name, null, removeAttribute);
5826   - };
5827   - prototype.setAttribute._polyfilled = true;
5828   - }
5829   - function changeAttribute(name, value, operation) {
5830   - name = name.toLowerCase();
5831   - var oldValue = this.getAttribute(name);
5832   - operation.apply(this, arguments);
5833   - var newValue = this.getAttribute(name);
5834   - if (this.attributeChangedCallback && newValue !== oldValue) {
5835   - this.attributeChangedCallback(name, oldValue, newValue);
5836   - }
5837   - }
5838   - function isReservedTag(name) {
5839   - for (var i = 0; i < reservedTagList.length; i++) {
5840   - if (name === reservedTagList[i]) {
5841   - return true;
5842   - }
5843   - }
5844   - }
5845   - var reservedTagList = [ "annotation-xml", "color-profile", "font-face", "font-face-src", "font-face-uri", "font-face-format", "font-face-name", "missing-glyph" ];
5846   - function ancestry(extnds) {
5847   - var extendee = getRegisteredDefinition(extnds);
5848   - if (extendee) {
5849   - return ancestry(extendee.extends).concat([ extendee ]);
5850   - }
5851   - return [];
5852   - }
5853   - function resolveTagName(definition) {
5854   - var baseTag = definition.extends;
5855   - for (var i = 0, a; a = definition.ancestry[i]; i++) {
5856   - baseTag = a.is && a.tag;
5857   - }
5858   - definition.tag = baseTag || definition.__name;
5859   - if (baseTag) {
5860   - definition.is = definition.__name;
5861   - }
5862   - }
5863   - function resolvePrototypeChain(definition) {
5864   - if (!Object.__proto__) {
5865   - var nativePrototype = HTMLElement.prototype;
5866   - if (definition.is) {
5867   - var inst = document.createElement(definition.tag);
5868   - var expectedPrototype = Object.getPrototypeOf(inst);
5869   - if (expectedPrototype === definition.prototype) {
5870   - nativePrototype = expectedPrototype;
5871   - }
5872   - }
5873   - var proto = definition.prototype, ancestor;
5874   - while (proto && proto !== nativePrototype) {
5875   - ancestor = Object.getPrototypeOf(proto);
5876   - proto.__proto__ = ancestor;
5877   - proto = ancestor;
5878   - }
5879   - definition.native = nativePrototype;
5880   - }
5881   - }
5882   - function instantiate(definition) {
5883   - return upgradeWithDefinition(domCreateElement(definition.tag), definition);
5884   - }
5885   - var registry = {};
5886   - function getRegisteredDefinition(name) {
5887   - if (name) {
5888   - return registry[name.toLowerCase()];
5889   - }
5890   - }
5891   - function registerDefinition(name, definition) {
5892   - registry[name] = definition;
5893   - }
5894   - function generateConstructor(definition) {
5895   - return function() {
5896   - return instantiate(definition);
5897   - };
5898   - }
5899   - var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
5900   - function createElementNS(namespace, tag, typeExtension) {
5901   - if (namespace === HTML_NAMESPACE) {
5902   - return createElement(tag, typeExtension);
5903   - } else {
5904   - return domCreateElementNS(namespace, tag);
5905   - }
5906   - }
5907   - function createElement(tag, typeExtension) {
5908   - var definition = getRegisteredDefinition(typeExtension || tag);
5909   - if (definition) {
5910   - if (tag == definition.tag && typeExtension == definition.is) {
5911   - return new definition.ctor();
5912   - }
5913   - if (!typeExtension && !definition.is) {
5914   - return new definition.ctor();
5915   - }
5916   - }
5917   - var element;
5918   - if (typeExtension) {
5919   - element = createElement(tag);
5920   - element.setAttribute("is", typeExtension);
5921   - return element;
5922   - }
5923   - element = domCreateElement(tag);
5924   - if (tag.indexOf("-") >= 0) {
5925   - implementPrototype(element, HTMLElement);
5926   - }
5927   - return element;
5928   - }
5929   - function cloneNode(deep) {
5930   - var n = domCloneNode.call(this, deep);
5931   - upgrade(n);
5932   - return n;
5933   - }
5934   - var domCreateElement = document.createElement.bind(document);
5935   - var domCreateElementNS = document.createElementNS.bind(document);
5936   - var domCloneNode = Node.prototype.cloneNode;
5937   - var isInstance;
5938   - if (!Object.__proto__ && !useNative) {
5939   - isInstance = function(obj, ctor) {
5940   - var p = obj;
5941   - while (p) {
5942   - if (p === ctor.prototype) {
5943   - return true;
5944   - }
5945   - p = p.__proto__;
5946   - }
5947   - return false;
5948   - };
5949   - } else {
5950   - isInstance = function(obj, base) {
5951   - return obj instanceof base;
5952   - };
5953   - }
5954   - document.registerElement = register;
5955   - document.createElement = createElement;
5956   - document.createElementNS = createElementNS;
5957   - Node.prototype.cloneNode = cloneNode;
5958   - scope.registry = registry;
5959   - scope.instanceof = isInstance;
5960   - scope.reservedTagList = reservedTagList;
5961   - scope.getRegisteredDefinition = getRegisteredDefinition;
5962   - document.register = document.registerElement;
5963   -});
5964   -
5965   -(function(scope) {
5966   - var useNative = scope.useNative;
5967   - var initializeModules = scope.initializeModules;
5968   - var isIE11OrOlder = /Trident/.test(navigator.userAgent);
5969   - if (useNative) {
5970   - var nop = function() {};
5971   - scope.watchShadow = nop;
5972   - scope.upgrade = nop;
5973   - scope.upgradeAll = nop;
5974   - scope.upgradeDocumentTree = nop;
5975   - scope.upgradeSubtree = nop;
5976   - scope.takeRecords = nop;
5977   - scope.instanceof = function(obj, base) {
5978   - return obj instanceof base;
5979   - };
5980   - } else {
5981   - initializeModules();
5982   - }
5983   - var upgradeDocumentTree = scope.upgradeDocumentTree;
5984   - if (!window.wrap) {
5985   - if (window.ShadowDOMPolyfill) {
5986   - window.wrap = ShadowDOMPolyfill.wrapIfNeeded;
5987   - window.unwrap = ShadowDOMPolyfill.unwrapIfNeeded;
5988   - } else {
5989   - window.wrap = window.unwrap = function(node) {
5990   - return node;
5991   - };
5992   - }
5993   - }
5994   - function bootstrap() {
5995   - upgradeDocumentTree(wrap(document));
5996   - if (window.HTMLImports) {
5997   - HTMLImports.__importsParsingHook = function(elt) {
5998   - upgradeDocumentTree(wrap(elt.import));
5999   - };
6000   - }
6001   - CustomElements.ready = true;
6002   - setTimeout(function() {
6003   - CustomElements.readyTime = Date.now();
6004   - if (window.HTMLImports) {
6005   - CustomElements.elapsed = CustomElements.readyTime - HTMLImports.readyTime;
6006   - }
6007   - document.dispatchEvent(new CustomEvent("WebComponentsReady", {
6008   - bubbles: true
6009   - }));
6010   - });
6011   - }
6012   - if (isIE11OrOlder && typeof window.CustomEvent !== "function") {
6013   - window.CustomEvent = function(inType, params) {
6014   - params = params || {};
6015   - var e = document.createEvent("CustomEvent");
6016   - e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable), params.detail);
6017   - return e;
6018   - };
6019   - window.CustomEvent.prototype = window.Event.prototype;
6020   - }
6021   - if (document.readyState === "complete" || scope.flags.eager) {
6022   - bootstrap();
6023   - } else if (document.readyState === "interactive" && !window.attachEvent && (!window.HTMLImports || window.HTMLImports.ready)) {
6024   - bootstrap();
6025   - } else {
6026   - var loadEvent = window.HTMLImports && !HTMLImports.ready ? "HTMLImportsLoaded" : "DOMContentLoaded";
6027   - window.addEventListener(loadEvent, bootstrap);
6028   - }
6029   -})(window.CustomElements);
6030   -
6031   -(function(scope) {
6032   - if (!Function.prototype.bind) {
6033   - Function.prototype.bind = function(scope) {
6034   - var self = this;
6035   - var args = Array.prototype.slice.call(arguments, 1);
6036   - return function() {
6037   - var args2 = args.slice();
6038   - args2.push.apply(args2, arguments);
6039   - return self.apply(scope, args2);
6040   - };
6041   - };
6042   - }
6043   -})(window.WebComponents);
6044   -
6045   -(function(scope) {
6046   - "use strict";
6047   - if (!window.performance) {
6048   - var start = Date.now();
6049   - window.performance = {
6050   - now: function() {
6051   - return Date.now() - start;
6052   - }
6053   - };
6054   - }
6055   - if (!window.requestAnimationFrame) {
6056   - window.requestAnimationFrame = function() {
6057   - var nativeRaf = window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame;
6058   - return nativeRaf ? function(callback) {
6059   - return nativeRaf(function() {
6060   - callback(performance.now());
6061   - });
6062   - } : function(callback) {
6063   - return window.setTimeout(callback, 1e3 / 60);
6064   - };
6065   - }();
6066   - }
6067   - if (!window.cancelAnimationFrame) {
6068   - window.cancelAnimationFrame = function() {
6069   - return window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || function(id) {
6070   - clearTimeout(id);
6071   - };
6072   - }();
6073   - }
6074   - var elementDeclarations = [];
6075   - var polymerStub = function(name, dictionary) {
6076   - if (typeof name !== "string" && arguments.length === 1) {
6077   - Array.prototype.push.call(arguments, document._currentScript);
6078   - }
6079   - elementDeclarations.push(arguments);
6080   - };
6081   - window.Polymer = polymerStub;
6082   - scope.consumeDeclarations = function(callback) {
6083   - scope.consumeDeclarations = function() {
6084   - throw "Possible attempt to load Polymer twice";
6085   - };
6086   - if (callback) {
6087   - callback(elementDeclarations);
6088   - }
6089   - elementDeclarations = null;
6090   - };
6091   - function installPolymerWarning() {
6092   - if (window.Polymer === polymerStub) {
6093   - window.Polymer = function() {
6094   - throw new Error("You tried to use polymer without loading it first. To " + 'load polymer, <link rel="import" href="' + 'components/polymer/polymer.html">');
6095   - };
6096   - }
6097   - }
6098   - if (HTMLImports.useNative) {
6099   - installPolymerWarning();
6100   - } else {
6101   - addEventListener("DOMContentLoaded", installPolymerWarning);
6102   - }
6103   -})(window.WebComponents);
6104   -
6105   -(function(scope) {
6106   - var style = document.createElement("style");
6107   - style.textContent = "" + "body {" + "transition: opacity ease-in 0.2s;" + " } \n" + "body[unresolved] {" + "opacity: 0; display: block; overflow: hidden; position: relative;" + " } \n";
6108   - var head = document.querySelector("head");
6109   - head.insertBefore(style, head.firstChild);
6110   -})(window.WebComponents);
6111   -
6112   -(function(scope) {
6113   - window.Platform = scope;
6114   -})(window.WebComponents);
6115 0 \ No newline at end of file
sevc.html
1 1 <!DOCTYPE html>
2   -<html>
  2 +<html lang="en">
3 3 <head>
4   - <!-- style -->
5   - <link rel="stylesheet" href="js/bootstrap-3.3.4-dist/css/bootstrap.css">
6   - <!-- Js imports -->
  4 + <meta charset="UTF-8">
  5 + <title></title>
  6 +
  7 + <script type="text/javascript" src="../COMPONENTS/bower_components/webcomponentsjs/webcomponents-lite.js"></script>
7 8 <script type="text/javascript" src="js/jquery-2.1.0.min.js"></script>
8   - <script type="text/javascript" src="../COMPONENTS/bower_components/webcomponentsjs/webcomponents.js"></script>
9 9 <script type="text/javascript" src="js/deepClient.js"></script>
10   - <script src="js/bootstrap-3.3.4-dist/js/bootstrap.min.js"></script>
11   - <script type="text/javascript">
12 10  
13   - jQuery(document).ready(function($) {
14   - var ds_params ={
15   - component : "data-sevc-controllet",
16   - params :{
17   - 'data-url' : "http://dati.lazio.it/catalog/api/action/datastore_search?resource_id=722b6cbd-28d3-4151-ac50-9c4261298168&limit=500",
18   - 'deep-url' : "http://192.168.214.128/DEEalerProvider/DEEP/",
19   - 'datalets-list-url' : "http://192.168.214.128/DEEalerProvider/DEEP/datalets-list"
20   - },
21   - fields : Array(),
22   - placeHolder : "ds_component_place_holder"
23   - };
24   - ComponentService.deep_url = 'http://192.168.214.128/DEEalerProvider/DEEP/';
25   - ComponentService.getComponent(ds_params);
  11 + <script>
  12 +
  13 + ComponentService.deep_url = parent.ODE.deep_url;
  14 + ComponentService.getComponent({
  15 + component : "data-sevc-controllet",
  16 + params :
  17 + {
  18 + 'deep-url' : parent.ODE.deep_url,
  19 + 'datalets-list-url' : parent.ODE.deep_datalet_list,
  20 + 'organization' : parent.ODE.organization
  21 + },
  22 + fields : Array(),
  23 + placeHolder : "ode_controllet_placeholder_float"
26 24 });
  25 +
27 26 </script>
  27 +
28 28 </head>
29 29 <body>
30   -<div class="jumbotron">
31   - <div class="container">
32   - <h2>Open Data Datalets</h2>
33   - <p class="small text-info">In this page you can see several containers with opendata Datalets. To do this the page uses the DEEPCLIENT js library.
34   - The only things you have to know is the data source url, the fields that component need to visualize the chart, the componet you want to use and the place holder in witch the component will be
35   - injected.
36   - </p><button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button></p>
37   - </div>
38   -</div>
39   -<div class="container">
40   - <div class="row">
41   - <div class="col-md-12">
42   - <div class="panel panel-default">
43   - <div class="panel-heading">
44   - <h3 class="panel-title">Data Selection Exploration Visualization Customization Controllet</h3>
45   - </div>
46   - <div class="panel-body">
47   - </div>
48   - </div>
49   - <div id="ds_component_place_holder" style="height:500px;width:1000px;border:1px;"></div>
50   - </div>
51   - </div>
52   - <div class="row">
53   - <div class="col-md-12">
54   - </div>
55   - </div>
56   -</div>
  30 +
  31 +<div id="ode_controllet_placeholder_float"></div>
57 32  
58 33 </body>
59 34 </html>
60 35 \ No newline at end of file
... ...