Added webcomponents.js and a simple unit test verifying a document fragment as a valid React container.
Jim committed
Feb 17, 2015 at 16:32 UTC
12059299f32d6f8c1cfc359597e95939e5b7948f
2 files changed
+6408
src/browser/ui/__tests__/ReactMount-test.js
+31
@@ -17,6 +17,13 @@ describe('ReactMount', function() {
17
var React = require('React');
18
var ReactMount = require('ReactMount');
19
var ReactTestUtils = require('ReactTestUtils');
20
+ var WebComponents = undefined;
21
+
22
+ try {
23
+ WebComponents = require('WebComponents');
24
+ } catch(e) {
25
+ /* leave WebComponents undefined */
26
+ }
27
28
describe('constructAndRenderComponentByID', function() {
29
it('throws if given an id for a component that doesn\'t exist', function() {
@@ -157,4 +164,28 @@ describe('ReactMount', function() {
164
'Rendering components directly into document.body is discouraged'
165
);
166
});
167
+
168
+ (WebComponents === undefined ? xit : it)
169
+ ('should allow mounting/unmounting to document fragment container', function() {
170
+ var shadowRoot;
171
+ var proto = Object.create(HTMLElement.prototype, {
172
+ createdCallback: {
173
+ value: function() {
174
+ var query = encodeURIComponent(this.innerHTML);
175
+ var url = "https://www.google.com/search?q=" + query + "&btnI";
176
+ shadowRoot = this.createShadowRoot();
177
+ React.render(<div>Hi, from within a WC!</div>, shadowRoot);
178
+ expect(shadowRoot.firstChild.tagName).toBe('DIV')
179
+ React.render(<span>Hi, from within a WC!</span>, shadowRoot);
180
+ expect(shadowRoot.firstChild.tagName).toBe('SPAN')
181
+ }
182
+ }
183
+ });
184
+ proto.unmount = function() {
185
+ React.unmountComponentAtNode(shadowRoot);
186
+ }
187
+ document.registerElement('x-foo', {prototype: proto});
188
+ var element = document.createElement('x-foo');
189
+ element.unmount();
190
+ });
191
});
src/vendor/third_party/webcomponents.js
new
+6377
@@ -0,0 +1,6377 @@
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
+ * @providesModule WebComponents
10
+ */
11
+// @version 0.5.1
12
+window.WebComponents = window.WebComponents || {};
13
+
14
+(function(scope) {
15
+ var flags = scope.flags || {};
16
+ var file = "webcomponents.js";
17
+ var script = document.querySelector('script[src*="' + file + '"]');
18
+ var flags = {};
19
+ if (!flags.noOpts) {
20
+ location.search.slice(1).split("&").forEach(function(o) {
21
+ o = o.split("=");
22
+ o[0] && (flags[o[0]] = o[1] || true);
23
+ });
24
+ if (script) {
25
+ for (var i = 0, a; a = script.attributes[i]; i++) {
26
+ if (a.name !== "src") {
27
+ flags[a.name] = a.value || true;
28
+ }
29
+ }
30
+ }
31
+ if (flags.log) {
32
+ var parts = flags.log.split(",");
33
+ flags.log = {};
34
+ parts.forEach(function(f) {
35
+ flags.log[f] = true;
36
+ });
37
+ } else {
38
+ flags.log = {};
39
+ }
40
+ }
41
+ flags.shadow = flags.shadow || flags.shadowdom || flags.polyfill;
42
+ if (flags.shadow === "native") {
43
+ flags.shadow = false;
44
+ } else {
45
+ flags.shadow = flags.shadow || !HTMLElement.prototype.createShadowRoot;
46
+ }
47
+ if (flags.register) {
48
+ window.CustomElements = window.CustomElements || {
49
+ flags: {}
50
+ };
51
+ window.CustomElements.flags.register = flags.register;
52
+ }
53
+ scope.flags = flags;
54
+})(WebComponents);
55
+
56
+if (WebComponents.flags.shadow) {
57
+ if (typeof WeakMap === "undefined") {
58
+ (function() {
59
+ var defineProperty = Object.defineProperty;
60
+ var counter = Date.now() % 1e9;
61
+ var WeakMap = function() {
62
+ this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__");
63
+ };
64
+ WeakMap.prototype = {
65
+ set: function(key, value) {
66
+ var entry = key[this.name];
67
+ if (entry && entry[0] === key) entry[1] = value; else defineProperty(key, this.name, {
68
+ value: [ key, value ],
69
+ writable: true
70
+ });
71
+ return this;
72
+ },
73
+ get: function(key) {
74
+ var entry;
75
+ return (entry = key[this.name]) && entry[0] === key ? entry[1] : undefined;
76
+ },
77
+ "delete": function(key) {
78
+ var entry = key[this.name];
79
+ if (!entry || entry[0] !== key) return false;
80
+ entry[0] = entry[1] = undefined;
81
+ return true;
82
+ },
83
+ has: function(key) {
84
+ var entry = key[this.name];
85
+ if (!entry) return false;
86
+ return entry[0] === key;
87
+ }
88
+ };
89
+ window.WeakMap = WeakMap;
90
+ })();
91
+ }
92
+ window.ShadowDOMPolyfill = {};
93
+ (function(scope) {
94
+ "use strict";
95
+ var constructorTable = new WeakMap();
96
+ var nativePrototypeTable = new WeakMap();
97
+ var wrappers = Object.create(null);
98
+ function detectEval() {
99
+ if (typeof chrome !== "undefined" && chrome.app && chrome.app.runtime) {
100
+ return false;
101
+ }
102
+ if (navigator.getDeviceStorage) {
103
+ return false;
104
+ }
105
+ try {
106
+ var f = new Function("return true;");
107
+ return f();
108
+ } catch (ex) {
109
+ return false;
110
+ }
111
+ }
112
+ var hasEval = detectEval();
113
+ function assert(b) {
114
+ if (!b) throw new Error("Assertion failed");
115
+ }
116
+ var defineProperty = Object.defineProperty;
117
+ var getOwnPropertyNames = Object.getOwnPropertyNames;
118
+ var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
119
+ function mixin(to, from) {
120
+ var names = getOwnPropertyNames(from);
121
+ for (var i = 0; i < names.length; i++) {
122
+ var name = names[i];
123
+ defineProperty(to, name, getOwnPropertyDescriptor(from, name));
124
+ }
125
+ return to;
126
+ }
127
+ function mixinStatics(to, from) {
128
+ var names = getOwnPropertyNames(from);
129
+ for (var i = 0; i < names.length; i++) {
130
+ var name = names[i];
131
+ switch (name) {
132
+ case "arguments":
133
+ case "caller":
134
+ case "length":
135
+ case "name":
136
+ case "prototype":
137
+ case "toString":
138
+ continue;
139
+ }
140
+ defineProperty(to, name, getOwnPropertyDescriptor(from, name));
141
+ }
142
+ return to;
143
+ }
144
+ function oneOf(object, propertyNames) {
145
+ for (var i = 0; i < propertyNames.length; i++) {
146
+ if (propertyNames[i] in object) return propertyNames[i];
147
+ }
148
+ }
149
+ var nonEnumerableDataDescriptor = {
150
+ value: undefined,
151
+ configurable: true,
152
+ enumerable: false,
153
+ writable: true
154
+ };
155
+ function defineNonEnumerableDataProperty(object, name, value) {
156
+ nonEnumerableDataDescriptor.value = value;
157
+ defineProperty(object, name, nonEnumerableDataDescriptor);
158
+ }
159
+ getOwnPropertyNames(window);
160
+ function getWrapperConstructor(node) {
161
+ var nativePrototype = node.__proto__ || Object.getPrototypeOf(node);
162
+ var wrapperConstructor = constructorTable.get(nativePrototype);
163
+ if (wrapperConstructor) return wrapperConstructor;
164
+ var parentWrapperConstructor = getWrapperConstructor(nativePrototype);
165
+ var GeneratedWrapper = createWrapperConstructor(parentWrapperConstructor);
166
+ registerInternal(nativePrototype, GeneratedWrapper, node);
167
+ return GeneratedWrapper;
168
+ }
169
+ function addForwardingProperties(nativePrototype, wrapperPrototype) {
170
+ installProperty(nativePrototype, wrapperPrototype, true);
171
+ }
172
+ function registerInstanceProperties(wrapperPrototype, instanceObject) {
173
+ installProperty(instanceObject, wrapperPrototype, false);
174
+ }
175
+ var isFirefox = /Firefox/.test(navigator.userAgent);
176
+ var dummyDescriptor = {
177
+ get: function() {},
178
+ set: function(v) {},
179
+ configurable: true,
180
+ enumerable: true
181
+ };
182
+ function isEventHandlerName(name) {
183
+ return /^on[a-z]+$/.test(name);
184
+ }
185
+ function isIdentifierName(name) {
186
+ return /^\w[a-zA-Z_0-9]*$/.test(name);
187
+ }
188
+ function getGetter(name) {
189
+ return hasEval && isIdentifierName(name) ? new Function("return this.__impl4cf1e782hg__." + name) : function() {
190
+ return this.__impl4cf1e782hg__[name];
191
+ };
192
+ }
193
+ function getSetter(name) {
194
+ return hasEval && isIdentifierName(name) ? new Function("v", "this.__impl4cf1e782hg__." + name + " = v") : function(v) {
195
+ this.__impl4cf1e782hg__[name] = v;
196
+ };
197
+ }
198
+ function getMethod(name) {
199
+ return hasEval && isIdentifierName(name) ? new Function("return this.__impl4cf1e782hg__." + name + ".apply(this.__impl4cf1e782hg__, arguments)") : function() {
200
+ return this.__impl4cf1e782hg__[name].apply(this.__impl4cf1e782hg__, arguments);
201
+ };
202
+ }
203
+ function getDescriptor(source, name) {
204
+ try {
205
+ return Object.getOwnPropertyDescriptor(source, name);
206
+ } catch (ex) {
207
+ return dummyDescriptor;
208
+ }
209
+ }
210
+ var isBrokenSafari = function() {
211
+ var descr = Object.getOwnPropertyDescriptor(Node.prototype, "nodeType");
212
+ return descr && !descr.get && !descr.set;
213
+ }();
214
+ function installProperty(source, target, allowMethod, opt_blacklist) {
215
+ var names = getOwnPropertyNames(source);
216
+ for (var i = 0; i < names.length; i++) {
217
+ var name = names[i];
218
+ if (name === "polymerBlackList_") continue;
219
+ if (name in target) continue;
220
+ if (source.polymerBlackList_ && source.polymerBlackList_[name]) continue;
221
+ if (isFirefox) {
222
+ source.__lookupGetter__(name);
223
+ }
224
+ var descriptor = getDescriptor(source, name);
225
+ var getter, setter;
226
+ if (allowMethod && typeof descriptor.value === "function") {
227
+ target[name] = getMethod(name);
228
+ continue;
229
+ }
230
+ var isEvent = isEventHandlerName(name);
231
+ if (isEvent) getter = scope.getEventHandlerGetter(name); else getter = getGetter(name);
232
+ if (descriptor.writable || descriptor.set || isBrokenSafari) {
233
+ if (isEvent) setter = scope.getEventHandlerSetter(name); else setter = getSetter(name);
234
+ }
235
+ defineProperty(target, name, {
236
+ get: getter,
237
+ set: setter,
238
+ configurable: descriptor.configurable,
239
+ enumerable: descriptor.enumerable
240
+ });
241
+ }
242
+ }
243
+ function register(nativeConstructor, wrapperConstructor, opt_instance) {
244
+ var nativePrototype = nativeConstructor.prototype;
245
+ registerInternal(nativePrototype, wrapperConstructor, opt_instance);
246
+ mixinStatics(wrapperConstructor, nativeConstructor);
247
+ }
248
+ function registerInternal(nativePrototype, wrapperConstructor, opt_instance) {
249
+ var wrapperPrototype = wrapperConstructor.prototype;
250
+ assert(constructorTable.get(nativePrototype) === undefined);
251
+ constructorTable.set(nativePrototype, wrapperConstructor);
252
+ nativePrototypeTable.set(wrapperPrototype, nativePrototype);
253
+ addForwardingProperties(nativePrototype, wrapperPrototype);
254
+ if (opt_instance) registerInstanceProperties(wrapperPrototype, opt_instance);
255
+ defineNonEnumerableDataProperty(wrapperPrototype, "constructor", wrapperConstructor);
256
+ wrapperConstructor.prototype = wrapperPrototype;
257
+ }
258
+ function isWrapperFor(wrapperConstructor, nativeConstructor) {
259
+ return constructorTable.get(nativeConstructor.prototype) === wrapperConstructor;
260
+ }
261
+ function registerObject(object) {
262
+ var nativePrototype = Object.getPrototypeOf(object);
263
+ var superWrapperConstructor = getWrapperConstructor(nativePrototype);
264
+ var GeneratedWrapper = createWrapperConstructor(superWrapperConstructor);
265
+ registerInternal(nativePrototype, GeneratedWrapper, object);
266
+ return GeneratedWrapper;
267
+ }
268
+ function createWrapperConstructor(superWrapperConstructor) {
269
+ function GeneratedWrapper(node) {
270
+ superWrapperConstructor.call(this, node);
271
+ }
272
+ var p = Object.create(superWrapperConstructor.prototype);
273
+ p.constructor = GeneratedWrapper;
274
+ GeneratedWrapper.prototype = p;
275
+ return GeneratedWrapper;
276
+ }
277
+ function isWrapper(object) {
278
+ return object && object.__impl4cf1e782hg__;
279
+ }
280
+ function isNative(object) {
281
+ return !isWrapper(object);
282
+ }
283
+ function wrap(impl) {
284
+ if (impl === null) return null;
285
+ assert(isNative(impl));
286
+ return impl.__wrapper8e3dd93a60__ || (impl.__wrapper8e3dd93a60__ = new (getWrapperConstructor(impl))(impl));
287
+ }
288
+ function unwrap(wrapper) {
289
+ if (wrapper === null) return null;
290
+ assert(isWrapper(wrapper));
291
+ return wrapper.__impl4cf1e782hg__;
292
+ }
293
+ function unsafeUnwrap(wrapper) {
294
+ return wrapper.__impl4cf1e782hg__;
295
+ }
296
+ function setWrapper(impl, wrapper) {
297
+ wrapper.__impl4cf1e782hg__ = impl;
298
+ impl.__wrapper8e3dd93a60__ = wrapper;
299
+ }
300
+ function unwrapIfNeeded(object) {
301
+ return object && isWrapper(object) ? unwrap(object) : object;
302
+ }
303
+ function wrapIfNeeded(object) {
304
+ return object && !isWrapper(object) ? wrap(object) : object;
305
+ }
306
+ function rewrap(node, wrapper) {
307
+ if (wrapper === null) return;
308
+ assert(isNative(node));
309
+ assert(wrapper === undefined || isWrapper(wrapper));
310
+ node.__wrapper8e3dd93a60__ = wrapper;
311
+ }
312
+ var getterDescriptor = {
313
+ get: undefined,
314
+ configurable: true,
315
+ enumerable: true
316
+ };
317
+ function defineGetter(constructor, name, getter) {
318
+ getterDescriptor.get = getter;
319
+ defineProperty(constructor.prototype, name, getterDescriptor);
320
+ }
321
+ function defineWrapGetter(constructor, name) {
322
+ defineGetter(constructor, name, function() {
323
+ return wrap(this.__impl4cf1e782hg__[name]);
324
+ });
325
+ }
326
+ function forwardMethodsToWrapper(constructors, names) {
327
+ constructors.forEach(function(constructor) {
328
+ names.forEach(function(name) {
329
+ constructor.prototype[name] = function() {
330
+ var w = wrapIfNeeded(this);
331
+ return w[name].apply(w, arguments);
332
+ };
333
+ });
334
+ });
335
+ }
336
+ scope.assert = assert;
337
+ scope.constructorTable = constructorTable;
338
+ scope.defineGetter = defineGetter;
339
+ scope.defineWrapGetter = defineWrapGetter;
340
+ scope.forwardMethodsToWrapper = forwardMethodsToWrapper;
341
+ scope.isWrapper = isWrapper;
342
+ scope.isWrapperFor = isWrapperFor;
343
+ scope.mixin = mixin;
344
+ scope.nativePrototypeTable = nativePrototypeTable;
345
+ scope.oneOf = oneOf;
346
+ scope.registerObject = registerObject;
347
+ scope.registerWrapper = register;
348
+ scope.rewrap = rewrap;
349
+ scope.setWrapper = setWrapper;
350
+ scope.unsafeUnwrap = unsafeUnwrap;
351
+ scope.unwrap = unwrap;
352
+ scope.unwrapIfNeeded = unwrapIfNeeded;
353
+ scope.wrap = wrap;
354
+ scope.wrapIfNeeded = wrapIfNeeded;
355
+ scope.wrappers = wrappers;
356
+ })(window.ShadowDOMPolyfill);
357
+ (function(scope) {
358
+ "use strict";
359
+ function newSplice(index, removed, addedCount) {
360
+ return {
361
+ index: index,
362
+ removed: removed,
363
+ addedCount: addedCount
364
+ };
365
+ }
366
+ var EDIT_LEAVE = 0;
367
+ var EDIT_UPDATE = 1;
368
+ var EDIT_ADD = 2;
369
+ var EDIT_DELETE = 3;
370
+ function ArraySplice() {}
371
+ ArraySplice.prototype = {
372
+ calcEditDistances: function(current, currentStart, currentEnd, old, oldStart, oldEnd) {
373
+ var rowCount = oldEnd - oldStart + 1;
374
+ var columnCount = currentEnd - currentStart + 1;
375
+ var distances = new Array(rowCount);
376
+ for (var i = 0; i < rowCount; i++) {
377
+ distances[i] = new Array(columnCount);
378
+ distances[i][0] = i;
379
+ }
380
+ for (var j = 0; j < columnCount; j++) distances[0][j] = j;
381
+ for (var i = 1; i < rowCount; i++) {
382
+ for (var j = 1; j < columnCount; j++) {
383
+ if (this.equals(current[currentStart + j - 1], old[oldStart + i - 1])) distances[i][j] = distances[i - 1][j - 1]; else {
384
+ var north = distances[i - 1][j] + 1;
385
+ var west = distances[i][j - 1] + 1;
386
+ distances[i][j] = north < west ? north : west;
387
+ }
388
+ }
389
+ }
390
+ return distances;
391
+ },
392
+ spliceOperationsFromEditDistances: function(distances) {
393
+ var i = distances.length - 1;
394
+ var j = distances[0].length - 1;
395
+ var current = distances[i][j];
396
+ var edits = [];
397
+ while (i > 0 || j > 0) {
398
+ if (i == 0) {
399
+ edits.push(EDIT_ADD);
400
+ j--;
401
+ continue;
402
+ }
403
+ if (j == 0) {
404
+ edits.push(EDIT_DELETE);
405
+ i--;
406
+ continue;
407
+ }
408
+ var northWest = distances[i - 1][j - 1];
409
+ var west = distances[i - 1][j];
410
+ var north = distances[i][j - 1];
411
+ var min;
412
+ if (west < north) min = west < northWest ? west : northWest; else min = north < northWest ? north : northWest;
413
+ if (min == northWest) {
414
+ if (northWest == current) {
415
+ edits.push(EDIT_LEAVE);
416
+ } else {
417
+ edits.push(EDIT_UPDATE);
418
+ current = northWest;
419
+ }
420
+ i--;
421
+ j--;
422
+ } else if (min == west) {
423
+ edits.push(EDIT_DELETE);
424
+ i--;
425
+ current = west;
426
+ } else {
427
+ edits.push(EDIT_ADD);
428
+ j--;
429
+ current = north;
430
+ }
431
+ }
432
+ edits.reverse();
433
+ return edits;
434
+ },
435
+ calcSplices: function(current, currentStart, currentEnd, old, oldStart, oldEnd) {
436
+ var prefixCount = 0;
437
+ var suffixCount = 0;
438
+ var minLength = Math.min(currentEnd - currentStart, oldEnd - oldStart);
439
+ if (currentStart == 0 && oldStart == 0) prefixCount = this.sharedPrefix(current, old, minLength);
440
+ if (currentEnd == current.length && oldEnd == old.length) suffixCount = this.sharedSuffix(current, old, minLength - prefixCount);
441
+ currentStart += prefixCount;
442
+ oldStart += prefixCount;
443
+ currentEnd -= suffixCount;
444
+ oldEnd -= suffixCount;
445
+ if (currentEnd - currentStart == 0 && oldEnd - oldStart == 0) return [];
446
+ if (currentStart == currentEnd) {
447
+ var splice = newSplice(currentStart, [], 0);
448
+ while (oldStart < oldEnd) splice.removed.push(old[oldStart++]);
449
+ return [ splice ];
450
+ } else if (oldStart == oldEnd) return [ newSplice(currentStart, [], currentEnd - currentStart) ];
451
+ var ops = this.spliceOperationsFromEditDistances(this.calcEditDistances(current, currentStart, currentEnd, old, oldStart, oldEnd));
452
+ var splice = undefined;
453
+ var splices = [];
454
+ var index = currentStart;
455
+ var oldIndex = oldStart;
456
+ for (var i = 0; i < ops.length; i++) {
457
+ switch (ops[i]) {
458
+ case EDIT_LEAVE:
459
+ if (splice) {
460
+ splices.push(splice);
461
+ splice = undefined;
462
+ }
463
+ index++;
464
+ oldIndex++;
465
+ break;
466
+
467
+ case EDIT_UPDATE:
468
+ if (!splice) splice = newSplice(index, [], 0);
469
+ splice.addedCount++;
470
+ index++;
471
+ splice.removed.push(old[oldIndex]);
472
+ oldIndex++;
473
+ break;
474
+
475
+ case EDIT_ADD:
476
+ if (!splice) splice = newSplice(index, [], 0);
477
+ splice.addedCount++;
478
+ index++;
479
+ break;
480
+
481
+ case EDIT_DELETE:
482
+ if (!splice) splice = newSplice(index, [], 0);
483
+ splice.removed.push(old[oldIndex]);
484
+ oldIndex++;
485
+ break;
486
+ }
487
+ }
488
+ if (splice) {
489
+ splices.push(splice);
490
+ }
491
+ return splices;
492
+ },
493
+ sharedPrefix: function(current, old, searchLength) {
494
+ for (var i = 0; i < searchLength; i++) if (!this.equals(current[i], old[i])) return i;
495
+ return searchLength;
496
+ },
497
+ sharedSuffix: function(current, old, searchLength) {
498
+ var index1 = current.length;
499
+ var index2 = old.length;
500
+ var count = 0;
501
+ while (count < searchLength && this.equals(current[--index1], old[--index2])) count++;
502
+ return count;
503
+ },
504
+ calculateSplices: function(current, previous) {
505
+ return this.calcSplices(current, 0, current.length, previous, 0, previous.length);
506
+ },
507
+ equals: function(currentValue, previousValue) {
508
+ return currentValue === previousValue;
509
+ }
510
+ };
511
+ scope.ArraySplice = ArraySplice;
512
+ })(window.ShadowDOMPolyfill);
513
+ (function(context) {
514
+ "use strict";
515
+ var OriginalMutationObserver = window.MutationObserver;
516
+ var callbacks = [];
517
+ var pending = false;
518
+ var timerFunc;
519
+ function handle() {
520
+ pending = false;
521
+ var copies = callbacks.slice(0);
522
+ callbacks = [];
523
+ for (var i = 0; i < copies.length; i++) {
524
+ (0, copies[i])();
525
+ }
526
+ }
527
+ if (OriginalMutationObserver) {
528
+ var counter = 1;
529
+ var observer = new OriginalMutationObserver(handle);
530
+ var textNode = document.createTextNode(counter);
531
+ observer.observe(textNode, {
532
+ characterData: true
533
+ });
534
+ timerFunc = function() {
535
+ counter = (counter + 1) % 2;
536
+ textNode.data = counter;
537
+ };
538
+ } else {
539
+ timerFunc = window.setTimeout;
540
+ }
541
+ function setEndOfMicrotask(func) {
542
+ callbacks.push(func);
543
+ if (pending) return;
544
+ pending = true;
545
+ timerFunc(handle, 0);
546
+ }
547
+ context.setEndOfMicrotask = setEndOfMicrotask;
548
+ })(window.ShadowDOMPolyfill);
549
+ (function(scope) {
550
+ "use strict";
551
+ var setEndOfMicrotask = scope.setEndOfMicrotask;
552
+ var wrapIfNeeded = scope.wrapIfNeeded;
553
+ var wrappers = scope.wrappers;
554
+ var registrationsTable = new WeakMap();
555
+ var globalMutationObservers = [];
556
+ var isScheduled = false;
557
+ function scheduleCallback(observer) {
558
+ if (observer.scheduled_) return;
559
+ observer.scheduled_ = true;
560
+ globalMutationObservers.push(observer);
561
+ if (isScheduled) return;
562
+ setEndOfMicrotask(notifyObservers);
563
+ isScheduled = true;
564
+ }
565
+ function notifyObservers() {
566
+ isScheduled = false;
567
+ while (globalMutationObservers.length) {
568
+ var notifyList = globalMutationObservers;
569
+ globalMutationObservers = [];
570
+ notifyList.sort(function(x, y) {
571
+ return x.uid_ - y.uid_;
572
+ });
573
+ for (var i = 0; i < notifyList.length; i++) {
574
+ var mo = notifyList[i];
575
+ mo.scheduled_ = false;
576
+ var queue = mo.takeRecords();
577
+ removeTransientObserversFor(mo);
578
+ if (queue.length) {
579
+ mo.callback_(queue, mo);
580
+ }
581
+ }
582
+ }
583
+ }
584
+ function MutationRecord(type, target) {
585
+ this.type = type;
586
+ this.target = target;
587
+ this.addedNodes = new wrappers.NodeList();
588
+ this.removedNodes = new wrappers.NodeList();
589
+ this.previousSibling = null;
590
+ this.nextSibling = null;
591
+ this.attributeName = null;
592
+ this.attributeNamespace = null;
593
+ this.oldValue = null;
594
+ }
595
+ function registerTransientObservers(ancestor, node) {
596
+ for (;ancestor; ancestor = ancestor.parentNode) {
597
+ var registrations = registrationsTable.get(ancestor);
598
+ if (!registrations) continue;
599
+ for (var i = 0; i < registrations.length; i++) {
600
+ var registration = registrations[i];
601
+ if (registration.options.subtree) registration.addTransientObserver(node);
602
+ }
603
+ }
604
+ }
605
+ function removeTransientObserversFor(observer) {
606
+ for (var i = 0; i < observer.nodes_.length; i++) {
607
+ var node = observer.nodes_[i];
608
+ var registrations = registrationsTable.get(node);
609
+ if (!registrations) return;
610
+ for (var j = 0; j < registrations.length; j++) {
611
+ var registration = registrations[j];
612
+ if (registration.observer === observer) registration.removeTransientObservers();
613
+ }
614
+ }
615
+ }
616
+ function enqueueMutation(target, type, data) {
617
+ var interestedObservers = Object.create(null);
618
+ var associatedStrings = Object.create(null);
619
+ for (var node = target; node; node = node.parentNode) {
620
+ var registrations = registrationsTable.get(node);
621
+ if (!registrations) continue;
622
+ for (var j = 0; j < registrations.length; j++) {
623
+ var registration = registrations[j];
624
+ var options = registration.options;
625
+ if (node !== target && !options.subtree) continue;
626
+ if (type === "attributes" && !options.attributes) continue;
627
+ if (type === "attributes" && options.attributeFilter && (data.namespace !== null || options.attributeFilter.indexOf(data.name) === -1)) {
628
+ continue;
629
+ }
630
+ if (type === "characterData" && !options.characterData) continue;
631
+ if (type === "childList" && !options.childList) continue;
632
+ var observer = registration.observer;
633
+ interestedObservers[observer.uid_] = observer;
634
+ if (type === "attributes" && options.attributeOldValue || type === "characterData" && options.characterDataOldValue) {
635
+ associatedStrings[observer.uid_] = data.oldValue;
636
+ }
637
+ }
638
+ }
639
+ for (var uid in interestedObservers) {
640
+ var observer = interestedObservers[uid];
641
+ var record = new MutationRecord(type, target);
642
+ if ("name" in data && "namespace" in data) {
643
+ record.attributeName = data.name;
644
+ record.attributeNamespace = data.namespace;
645
+ }
646
+ if (data.addedNodes) record.addedNodes = data.addedNodes;
647
+ if (data.removedNodes) record.removedNodes = data.removedNodes;
648
+ if (data.previousSibling) record.previousSibling = data.previousSibling;
649
+ if (data.nextSibling) record.nextSibling = data.nextSibling;
650
+ if (associatedStrings[uid] !== undefined) record.oldValue = associatedStrings[uid];
651
+ scheduleCallback(observer);
652
+ observer.records_.push(record);
653
+ }
654
+ }
655
+ var slice = Array.prototype.slice;
656
+ function MutationObserverOptions(options) {
657
+ this.childList = !!options.childList;
658
+ this.subtree = !!options.subtree;
659
+ if (!("attributes" in options) && ("attributeOldValue" in options || "attributeFilter" in options)) {
660
+ this.attributes = true;
661
+ } else {
662
+ this.attributes = !!options.attributes;
663
+ }
664
+ if ("characterDataOldValue" in options && !("characterData" in options)) this.characterData = true; else this.characterData = !!options.characterData;
665
+ if (!this.attributes && (options.attributeOldValue || "attributeFilter" in options) || !this.characterData && options.characterDataOldValue) {
666
+ throw new TypeError();
667
+ }
668
+ this.characterData = !!options.characterData;
669
+ this.attributeOldValue = !!options.attributeOldValue;
670
+ this.characterDataOldValue = !!options.characterDataOldValue;
671
+ if ("attributeFilter" in options) {
672
+ if (options.attributeFilter == null || typeof options.attributeFilter !== "object") {
673
+ throw new TypeError();
674
+ }
675
+ this.attributeFilter = slice.call(options.attributeFilter);
676
+ } else {
677
+ this.attributeFilter = null;
678
+ }
679
+ }
680
+ var uidCounter = 0;
681
+ function MutationObserver(callback) {
682
+ this.callback_ = callback;
683
+ this.nodes_ = [];
684
+ this.records_ = [];
685
+ this.uid_ = ++uidCounter;
686
+ this.scheduled_ = false;
687
+ }
688
+ MutationObserver.prototype = {
689
+ constructor: MutationObserver,
690
+ observe: function(target, options) {
691
+ target = wrapIfNeeded(target);
692
+ var newOptions = new MutationObserverOptions(options);
693
+ var registration;
694
+ var registrations = registrationsTable.get(target);
695
+ if (!registrations) registrationsTable.set(target, registrations = []);
696
+ for (var i = 0; i < registrations.length; i++) {
697
+ if (registrations[i].observer === this) {
698
+ registration = registrations[i];
699
+ registration.removeTransientObservers();
700
+ registration.options = newOptions;
701
+ }
702
+ }
703
+ if (!registration) {
704
+ registration = new Registration(this, target, newOptions);
705
+ registrations.push(registration);
706
+ this.nodes_.push(target);
707
+ }
708
+ },
709
+ disconnect: function() {
710
+ this.nodes_.forEach(function(node) {
711
+ var registrations = registrationsTable.get(node);
712
+ for (var i = 0; i < registrations.length; i++) {
713
+ var registration = registrations[i];
714
+ if (registration.observer === this) {
715
+ registrations.splice(i, 1);
716
+ break;
717
+ }
718
+ }
719
+ }, this);
720
+ this.records_ = [];
721
+ },
722
+ takeRecords: function() {
723
+ var copyOfRecords = this.records_;
724
+ this.records_ = [];
725
+ return copyOfRecords;
726
+ }
727
+ };
728
+ function Registration(observer, target, options) {
729
+ this.observer = observer;
730
+ this.target = target;
731
+ this.options = options;
732
+ this.transientObservedNodes = [];
733
+ }
734
+ Registration.prototype = {
735
+ addTransientObserver: function(node) {
736
+ if (node === this.target) return;
737
+ scheduleCallback(this.observer);
738
+ this.transientObservedNodes.push(node);
739
+ var registrations = registrationsTable.get(node);
740
+ if (!registrations) registrationsTable.set(node, registrations = []);
741
+ registrations.push(this);
742
+ },
743
+ removeTransientObservers: function() {
744
+ var transientObservedNodes = this.transientObservedNodes;
745
+ this.transientObservedNodes = [];
746
+ for (var i = 0; i < transientObservedNodes.length; i++) {
747
+ var node = transientObservedNodes[i];
748
+ var registrations = registrationsTable.get(node);
749
+ for (var j = 0; j < registrations.length; j++) {
750
+ if (registrations[j] === this) {
751
+ registrations.splice(j, 1);
752
+ break;
753
+ }
754
+ }
755
+ }
756
+ }
757
+ };
758
+ scope.enqueueMutation = enqueueMutation;
759
+ scope.registerTransientObservers = registerTransientObservers;
760
+ scope.wrappers.MutationObserver = MutationObserver;
761
+ scope.wrappers.MutationRecord = MutationRecord;
762
+ })(window.ShadowDOMPolyfill);
763
+ (function(scope) {
764
+ "use strict";
765
+ function TreeScope(root, parent) {
766
+ this.root = root;
767
+ this.parent = parent;
768
+ }
769
+ TreeScope.prototype = {
770
+ get renderer() {
771
+ if (this.root instanceof scope.wrappers.ShadowRoot) {
772
+ return scope.getRendererForHost(this.root.host);
773
+ }
774
+ return null;
775
+ },
776
+ contains: function(treeScope) {
777
+ for (;treeScope; treeScope = treeScope.parent) {
778
+ if (treeScope === this) return true;
779
+ }
780
+ return false;
781
+ }
782
+ };
783
+ function setTreeScope(node, treeScope) {
784
+ if (node.treeScope_ !== treeScope) {
785
+ node.treeScope_ = treeScope;
786
+ for (var sr = node.shadowRoot; sr; sr = sr.olderShadowRoot) {
787
+ sr.treeScope_.parent = treeScope;
788
+ }
789
+ for (var child = node.firstChild; child; child = child.nextSibling) {
790
+ setTreeScope(child, treeScope);
791
+ }
792
+ }
793
+ }
794
+ function getTreeScope(node) {
795
+ if (node instanceof scope.wrappers.Window) {
796
+ debugger;
797
+ }
798
+ if (node.treeScope_) return node.treeScope_;
799
+ var parent = node.parentNode;
800
+ var treeScope;
801
+ if (parent) treeScope = getTreeScope(parent); else treeScope = new TreeScope(node, null);
802
+ return node.treeScope_ = treeScope;
803
+ }
804
+ scope.TreeScope = TreeScope;
805
+ scope.getTreeScope = getTreeScope;
806
+ scope.setTreeScope = setTreeScope;
807
+ })(window.ShadowDOMPolyfill);
808
+ (function(scope) {
809
+ "use strict";
810
+ var forwardMethodsToWrapper = scope.forwardMethodsToWrapper;
811
+ var getTreeScope = scope.getTreeScope;
812
+ var mixin = scope.mixin;
813
+ var registerWrapper = scope.registerWrapper;
814
+ var setWrapper = scope.setWrapper;
815
+ var unsafeUnwrap = scope.unsafeUnwrap;
816
+ var unwrap = scope.unwrap;
817
+ var wrap = scope.wrap;
818
+ var wrappers = scope.wrappers;
819
+ var wrappedFuns = new WeakMap();
820
+ var listenersTable = new WeakMap();
821
+ var handledEventsTable = new WeakMap();
822
+ var currentlyDispatchingEvents = new WeakMap();
823
+ var targetTable = new WeakMap();
824
+ var currentTargetTable = new WeakMap();
825
+ var relatedTargetTable = new WeakMap();
826
+ var eventPhaseTable = new WeakMap();
827
+ var stopPropagationTable = new WeakMap();
828
+ var stopImmediatePropagationTable = new WeakMap();
829
+ var eventHandlersTable = new WeakMap();
830
+ var eventPathTable = new WeakMap();
831
+ function isShadowRoot(node) {
832
+ return node instanceof wrappers.ShadowRoot;
833
+ }
834
+ function rootOfNode(node) {
835
+ return getTreeScope(node).root;
836
+ }
837
+ function getEventPath(node, event) {
838
+ var path = [];
839
+ var current = node;
840
+ path.push(current);
841
+ while (current) {
842
+ var destinationInsertionPoints = getDestinationInsertionPoints(current);
843
+ if (destinationInsertionPoints && destinationInsertionPoints.length > 0) {
844
+ for (var i = 0; i < destinationInsertionPoints.length; i++) {
845
+ var insertionPoint = destinationInsertionPoints[i];
846
+ if (isShadowInsertionPoint(insertionPoint)) {
847
+ var shadowRoot = rootOfNode(insertionPoint);
848
+ var olderShadowRoot = shadowRoot.olderShadowRoot;
849
+ if (olderShadowRoot) path.push(olderShadowRoot);
850
+ }
851
+ path.push(insertionPoint);
852
+ }
853
+ current = destinationInsertionPoints[destinationInsertionPoints.length - 1];
854
+ } else {
855
+ if (isShadowRoot(current)) {
856
+ if (inSameTree(node, current) && eventMustBeStopped(event)) {
857
+ break;
858
+ }
859
+ current = current.host;
860
+ path.push(current);
861
+ } else {
862
+ current = current.parentNode;
863
+ if (current) path.push(current);
864
+ }
865
+ }
866
+ }
867
+ return path;
868
+ }
869
+ function eventMustBeStopped(event) {
870
+ if (!event) return false;
871
+ switch (event.type) {
872
+ case "abort":
873
+ case "error":
874
+ case "select":
875
+ case "change":
876
+ case "load":
877
+ case "reset":
878
+ case "resize":
879
+ case "scroll":
880
+ case "selectstart":
881
+ return true;
882
+ }
883
+ return false;
884
+ }
885
+ function isShadowInsertionPoint(node) {
886
+ return node instanceof HTMLShadowElement;
887
+ }
888
+ function getDestinationInsertionPoints(node) {
889
+ return scope.getDestinationInsertionPoints(node);
890
+ }
891
+ function eventRetargetting(path, currentTarget) {
892
+ if (path.length === 0) return currentTarget;
893
+ if (currentTarget instanceof wrappers.Window) currentTarget = currentTarget.document;
894
+ var currentTargetTree = getTreeScope(currentTarget);
895
+ var originalTarget = path[0];
896
+ var originalTargetTree = getTreeScope(originalTarget);
897
+ var relativeTargetTree = lowestCommonInclusiveAncestor(currentTargetTree, originalTargetTree);
898
+ for (var i = 0; i < path.length; i++) {
899
+ var node = path[i];
900
+ if (getTreeScope(node) === relativeTargetTree) return node;
901
+ }
902
+ return path[path.length - 1];
903
+ }
904
+ function getTreeScopeAncestors(treeScope) {
905
+ var ancestors = [];
906
+ for (;treeScope; treeScope = treeScope.parent) {
907
+ ancestors.push(treeScope);
908
+ }
909
+ return ancestors;
910
+ }
911
+ function lowestCommonInclusiveAncestor(tsA, tsB) {
912
+ var ancestorsA = getTreeScopeAncestors(tsA);
913
+ var ancestorsB = getTreeScopeAncestors(tsB);
914
+ var result = null;
915
+ while (ancestorsA.length > 0 && ancestorsB.length > 0) {
916
+ var a = ancestorsA.pop();
917
+ var b = ancestorsB.pop();
918
+ if (a === b) result = a; else break;
919
+ }
920
+ return result;
921
+ }
922
+ function getTreeScopeRoot(ts) {
923
+ if (!ts.parent) return ts;
924
+ return getTreeScopeRoot(ts.parent);
925
+ }
926
+ function relatedTargetResolution(event, currentTarget, relatedTarget) {
927
+ if (currentTarget instanceof wrappers.Window) currentTarget = currentTarget.document;
928
+ var currentTargetTree = getTreeScope(currentTarget);
929
+ var relatedTargetTree = getTreeScope(relatedTarget);
930
+ var relatedTargetEventPath = getEventPath(relatedTarget, event);
931
+ var lowestCommonAncestorTree;
932
+ var lowestCommonAncestorTree = lowestCommonInclusiveAncestor(currentTargetTree, relatedTargetTree);
933
+ if (!lowestCommonAncestorTree) lowestCommonAncestorTree = relatedTargetTree.root;
934
+ for (var commonAncestorTree = lowestCommonAncestorTree; commonAncestorTree; commonAncestorTree = commonAncestorTree.parent) {
935
+ var adjustedRelatedTarget;
936
+ for (var i = 0; i < relatedTargetEventPath.length; i++) {
937
+ var node = relatedTargetEventPath[i];
938
+ if (getTreeScope(node) === commonAncestorTree) return node;
939
+ }
940
+ }
941
+ return null;
942
+ }
943
+ function inSameTree(a, b) {
944
+ return getTreeScope(a) === getTreeScope(b);
945
+ }
946
+ var NONE = 0;
947
+ var CAPTURING_PHASE = 1;
948
+ var AT_TARGET = 2;
949
+ var BUBBLING_PHASE = 3;
950
+ var pendingError;
951
+ function dispatchOriginalEvent(originalEvent) {
952
+ if (handledEventsTable.get(originalEvent)) return;
953
+ handledEventsTable.set(originalEvent, true);
954
+ dispatchEvent(wrap(originalEvent), wrap(originalEvent.target));
955
+ if (pendingError) {
956
+ var err = pendingError;
957
+ pendingError = null;
958
+ throw err;
959
+ }
960
+ }
961
+ function isLoadLikeEvent(event) {
962
+ switch (event.type) {
963
+ case "load":
964
+ case "beforeunload":
965
+ case "unload":
966
+ return true;
967
+ }
968
+ return false;
969
+ }
970
+ function dispatchEvent(event, originalWrapperTarget) {
971
+ if (currentlyDispatchingEvents.get(event)) throw new Error("InvalidStateError");
972
+ currentlyDispatchingEvents.set(event, true);
973
+ scope.renderAllPending();
974
+ var eventPath;
975
+ var overrideTarget;
976
+ var win;
977
+ if (isLoadLikeEvent(event) && !event.bubbles) {
978
+ var doc = originalWrapperTarget;
979
+ if (doc instanceof wrappers.Document && (win = doc.defaultView)) {
980
+ overrideTarget = doc;
981
+ eventPath = [];
982
+ }
983
+ }
984
+ if (!eventPath) {
985
+ if (originalWrapperTarget instanceof wrappers.Window) {
986
+ win = originalWrapperTarget;
987
+ eventPath = [];
988
+ } else {
989
+ eventPath = getEventPath(originalWrapperTarget, event);
990
+ if (!isLoadLikeEvent(event)) {
991
+ var doc = eventPath[eventPath.length - 1];
992
+ if (doc instanceof wrappers.Document) win = doc.defaultView;
993
+ }
994
+ }
995
+ }
996
+ eventPathTable.set(event, eventPath);
997
+ if (dispatchCapturing(event, eventPath, win, overrideTarget)) {
998
+ if (dispatchAtTarget(event, eventPath, win, overrideTarget)) {
999
+ dispatchBubbling(event, eventPath, win, overrideTarget);
1000
+ }
1001
+ }
1002
+ eventPhaseTable.set(event, NONE);
1003
+ currentTargetTable.delete(event, null);
1004
+ currentlyDispatchingEvents.delete(event);
1005
+ return event.defaultPrevented;
1006
+ }
1007
+ function dispatchCapturing(event, eventPath, win, overrideTarget) {
1008
+ var phase = CAPTURING_PHASE;
1009
+ if (win) {
1010
+ if (!invoke(win, event, phase, eventPath, overrideTarget)) return false;
1011
+ }
1012
+ for (var i = eventPath.length - 1; i > 0; i--) {
1013
+ if (!invoke(eventPath[i], event, phase, eventPath, overrideTarget)) return false;
1014
+ }
1015
+ return true;
1016
+ }
1017
+ function dispatchAtTarget(event, eventPath, win, overrideTarget) {
1018
+ var phase = AT_TARGET;
1019
+ var currentTarget = eventPath[0] || win;
1020
+ return invoke(currentTarget, event, phase, eventPath, overrideTarget);
1021
+ }
1022
+ function dispatchBubbling(event, eventPath, win, overrideTarget) {
1023
+ var phase = BUBBLING_PHASE;
1024
+ for (var i = 1; i < eventPath.length; i++) {
1025
+ if (!invoke(eventPath[i], event, phase, eventPath, overrideTarget)) return;
1026
+ }
1027
+ if (win && eventPath.length > 0) {
1028
+ invoke(win, event, phase, eventPath, overrideTarget);
1029
+ }
1030
+ }
1031
+ function invoke(currentTarget, event, phase, eventPath, overrideTarget) {
1032
+ var listeners = listenersTable.get(currentTarget);
1033
+ if (!listeners) return true;
1034
+ var target = overrideTarget || eventRetargetting(eventPath, currentTarget);
1035
+ if (target === currentTarget) {
1036
+ if (phase === CAPTURING_PHASE) return true;
1037
+ if (phase === BUBBLING_PHASE) phase = AT_TARGET;
1038
+ } else if (phase === BUBBLING_PHASE && !event.bubbles) {
1039
+ return true;
1040
+ }
1041
+ if ("relatedTarget" in event) {
1042
+ var originalEvent = unwrap(event);
1043
+ var unwrappedRelatedTarget = originalEvent.relatedTarget;
1044
+ if (unwrappedRelatedTarget) {
1045
+ if (unwrappedRelatedTarget instanceof Object && unwrappedRelatedTarget.addEventListener) {
1046
+ var relatedTarget = wrap(unwrappedRelatedTarget);
1047
+ var adjusted = relatedTargetResolution(event, currentTarget, relatedTarget);
1048
+ if (adjusted === target) return true;
1049
+ } else {
1050
+ adjusted = null;
1051
+ }
1052
+ relatedTargetTable.set(event, adjusted);
1053
+ }
1054
+ }
1055
+ eventPhaseTable.set(event, phase);
1056
+ var type = event.type;
1057
+ var anyRemoved = false;
1058
+ targetTable.set(event, target);
1059
+ currentTargetTable.set(event, currentTarget);
1060
+ listeners.depth++;
1061
+ for (var i = 0, len = listeners.length; i < len; i++) {
1062
+ var listener = listeners[i];
1063
+ if (listener.removed) {
1064
+ anyRemoved = true;
1065
+ continue;
1066
+ }
1067
+ if (listener.type !== type || !listener.capture && phase === CAPTURING_PHASE || listener.capture && phase === BUBBLING_PHASE) {
1068
+ continue;
1069
+ }
1070
+ try {
1071
+ if (typeof listener.handler === "function") listener.handler.call(currentTarget, event); else listener.handler.handleEvent(event);
1072
+ if (stopImmediatePropagationTable.get(event)) return false;
1073
+ } catch (ex) {
1074
+ if (!pendingError) pendingError = ex;
1075
+ }
1076
+ }
1077
+ listeners.depth--;
1078
+ if (anyRemoved && listeners.depth === 0) {
1079
+ var copy = listeners.slice();
1080
+ listeners.length = 0;
1081
+ for (var i = 0; i < copy.length; i++) {
1082
+ if (!copy[i].removed) listeners.push(copy[i]);
1083
+ }
1084
+ }
1085
+ return !stopPropagationTable.get(event);
1086
+ }
1087
+ function Listener(type, handler, capture) {
1088
+ this.type = type;
1089
+ this.handler = handler;
1090
+ this.capture = Boolean(capture);
1091
+ }
1092
+ Listener.prototype = {
1093
+ equals: function(that) {
1094
+ return this.handler === that.handler && this.type === that.type && this.capture === that.capture;
1095
+ },
1096
+ get removed() {
1097
+ return this.handler === null;
1098
+ },
1099
+ remove: function() {
1100
+ this.handler = null;
1101
+ }
1102
+ };
1103
+ var OriginalEvent = window.Event;
1104
+ OriginalEvent.prototype.polymerBlackList_ = {
1105
+ returnValue: true,
1106
+ keyLocation: true
1107
+ };
1108
+ function Event(type, options) {
1109
+ if (type instanceof OriginalEvent) {
1110
+ var impl = type;
1111
+ if (!OriginalBeforeUnloadEvent && impl.type === "beforeunload" && !(this instanceof BeforeUnloadEvent)) {
1112
+ return new BeforeUnloadEvent(impl);
1113
+ }
1114
+ setWrapper(impl, this);
1115
+ } else {
1116
+ return wrap(constructEvent(OriginalEvent, "Event", type, options));
1117
+ }
1118
+ }
1119
+ Event.prototype = {
1120
+ get target() {
1121
+ return targetTable.get(this);
1122
+ },
1123
+ get currentTarget() {
1124
+ return currentTargetTable.get(this);
1125
+ },
1126
+ get eventPhase() {
1127
+ return eventPhaseTable.get(this);
1128
+ },
1129
+ get path() {
1130
+ var eventPath = eventPathTable.get(this);
1131
+ if (!eventPath) return [];
1132
+ return eventPath.slice();
1133
+ },
1134
+ stopPropagation: function() {
1135
+ stopPropagationTable.set(this, true);
1136
+ },
1137
+ stopImmediatePropagation: function() {
1138
+ stopPropagationTable.set(this, true);
1139
+ stopImmediatePropagationTable.set(this, true);
1140
+ }
1141
+ };
1142
+ registerWrapper(OriginalEvent, Event, document.createEvent("Event"));
1143
+ function unwrapOptions(options) {
1144
+ if (!options || !options.relatedTarget) return options;
1145
+ return Object.create(options, {
1146
+ relatedTarget: {
1147
+ value: unwrap(options.relatedTarget)
1148
+ }
1149
+ });
1150
+ }
1151
+ function registerGenericEvent(name, SuperEvent, prototype) {
1152
+ var OriginalEvent = window[name];
1153
+ var GenericEvent = function(type, options) {
1154
+ if (type instanceof OriginalEvent) setWrapper(type, this); else return wrap(constructEvent(OriginalEvent, name, type, options));
1155
+ };
1156
+ GenericEvent.prototype = Object.create(SuperEvent.prototype);
1157
+ if (prototype) mixin(GenericEvent.prototype, prototype);
1158
+ if (OriginalEvent) {
1159
+ try {
1160
+ registerWrapper(OriginalEvent, GenericEvent, new OriginalEvent("temp"));
1161
+ } catch (ex) {
1162
+ registerWrapper(OriginalEvent, GenericEvent, document.createEvent(name));
1163
+ }
1164
+ }
1165
+ return GenericEvent;
1166
+ }
1167
+ var UIEvent = registerGenericEvent("UIEvent", Event);
1168
+ var CustomEvent = registerGenericEvent("CustomEvent", Event);
1169
+ var relatedTargetProto = {
1170
+ get relatedTarget() {
1171
+ var relatedTarget = relatedTargetTable.get(this);
1172
+ if (relatedTarget !== undefined) return relatedTarget;
1173
+ return wrap(unwrap(this).relatedTarget);
1174
+ }
1175
+ };
1176
+ function getInitFunction(name, relatedTargetIndex) {
1177
+ return function() {
1178
+ arguments[relatedTargetIndex] = unwrap(arguments[relatedTargetIndex]);
1179
+ var impl = unwrap(this);
1180
+ impl[name].apply(impl, arguments);
1181
+ };
1182
+ }
1183
+ var mouseEventProto = mixin({
1184
+ initMouseEvent: getInitFunction("initMouseEvent", 14)
1185
+ }, relatedTargetProto);
1186
+ var focusEventProto = mixin({
1187
+ initFocusEvent: getInitFunction("initFocusEvent", 5)
1188
+ }, relatedTargetProto);
1189
+ var MouseEvent = registerGenericEvent("MouseEvent", UIEvent, mouseEventProto);
1190
+ var FocusEvent = registerGenericEvent("FocusEvent", UIEvent, focusEventProto);
1191
+ var defaultInitDicts = Object.create(null);
1192
+ var supportsEventConstructors = function() {
1193
+ try {
1194
+ new window.FocusEvent("focus");
1195
+ } catch (ex) {
1196
+ return false;
1197
+ }
1198
+ return true;
1199
+ }();
1200
+ function constructEvent(OriginalEvent, name, type, options) {
1201
+ if (supportsEventConstructors) return new OriginalEvent(type, unwrapOptions(options));
1202
+ var event = unwrap(document.createEvent(name));
1203
+ var defaultDict = defaultInitDicts[name];
1204
+ var args = [ type ];
1205
+ Object.keys(defaultDict).forEach(function(key) {
1206
+ var v = options != null && key in options ? options[key] : defaultDict[key];
1207
+ if (key === "relatedTarget") v = unwrap(v);
1208
+ args.push(v);
1209
+ });
1210
+ event["init" + name].apply(event, args);
1211
+ return event;
1212
+ }
1213
+ if (!supportsEventConstructors) {
1214
+ var configureEventConstructor = function(name, initDict, superName) {
1215
+ if (superName) {
1216
+ var superDict = defaultInitDicts[superName];
1217
+ initDict = mixin(mixin({}, superDict), initDict);
1218
+ }
1219
+ defaultInitDicts[name] = initDict;
1220
+ };
1221
+ configureEventConstructor("Event", {
1222
+ bubbles: false,
1223
+ cancelable: false
1224
+ });
1225
+ configureEventConstructor("CustomEvent", {
1226
+ detail: null
1227
+ }, "Event");
1228
+ configureEventConstructor("UIEvent", {
1229
+ view: null,
1230
+ detail: 0
1231
+ }, "Event");
1232
+ configureEventConstructor("MouseEvent", {
1233
+ screenX: 0,
1234
+ screenY: 0,
1235
+ clientX: 0,
1236
+ clientY: 0,
1237
+ ctrlKey: false,
1238
+ altKey: false,
1239
+ shiftKey: false,
1240
+ metaKey: false,
1241
+ button: 0,
1242
+ relatedTarget: null
1243
+ }, "UIEvent");
1244
+ configureEventConstructor("FocusEvent", {
1245
+ relatedTarget: null
1246
+ }, "UIEvent");
1247
+ }
1248
+ var OriginalBeforeUnloadEvent = window.BeforeUnloadEvent;
1249
+ function BeforeUnloadEvent(impl) {
1250
+ Event.call(this, impl);
1251
+ }
1252
+ BeforeUnloadEvent.prototype = Object.create(Event.prototype);
1253
+ mixin(BeforeUnloadEvent.prototype, {
1254
+ get returnValue() {
1255
+ return unsafeUnwrap(this).returnValue;
1256
+ },
1257
+ set returnValue(v) {
1258
+ unsafeUnwrap(this).returnValue = v;
1259
+ }
1260
+ });
1261
+ if (OriginalBeforeUnloadEvent) registerWrapper(OriginalBeforeUnloadEvent, BeforeUnloadEvent);
1262
+ function isValidListener(fun) {
1263
+ if (typeof fun === "function") return true;
1264
+ return fun && fun.handleEvent;
1265
+ }
1266
+ function isMutationEvent(type) {
1267
+ switch (type) {
1268
+ case "DOMAttrModified":
1269
+ case "DOMAttributeNameChanged":
1270
+ case "DOMCharacterDataModified":
1271
+ case "DOMElementNameChanged":
1272
+ case "DOMNodeInserted":
1273
+ case "DOMNodeInsertedIntoDocument":
1274
+ case "DOMNodeRemoved":
1275
+ case "DOMNodeRemovedFromDocument":
1276
+ case "DOMSubtreeModified":
1277
+ return true;
1278
+ }
1279
+ return false;
1280
+ }
1281
+ var OriginalEventTarget = window.EventTarget;
1282
+ function EventTarget(impl) {
1283
+ setWrapper(impl, this);
1284
+ }
1285
+ var methodNames = [ "addEventListener", "removeEventListener", "dispatchEvent" ];
1286
+ [ Node, Window ].forEach(function(constructor) {
1287
+ var p = constructor.prototype;
1288
+ methodNames.forEach(function(name) {
1289
+ Object.defineProperty(p, name + "_", {
1290
+ value: p[name]
1291
+ });
1292
+ });
1293
+ });
1294
+ function getTargetToListenAt(wrapper) {
1295
+ if (wrapper instanceof wrappers.ShadowRoot) wrapper = wrapper.host;
1296
+ return unwrap(wrapper);
1297
+ }
1298
+ EventTarget.prototype = {
1299
+ addEventListener: function(type, fun, capture) {
1300
+ if (!isValidListener(fun) || isMutationEvent(type)) return;
1301
+ var listener = new Listener(type, fun, capture);
1302
+ var listeners = listenersTable.get(this);
1303
+ if (!listeners) {
1304
+ listeners = [];
1305
+ listeners.depth = 0;
1306
+ listenersTable.set(this, listeners);
1307
+ } else {
1308
+ for (var i = 0; i < listeners.length; i++) {
1309
+ if (listener.equals(listeners[i])) return;
1310
+ }
1311
+ }
1312
+ listeners.push(listener);
1313
+ var target = getTargetToListenAt(this);
1314
+ target.addEventListener_(type, dispatchOriginalEvent, true);
1315
+ },
1316
+ removeEventListener: function(type, fun, capture) {
1317
+ capture = Boolean(capture);
1318
+ var listeners = listenersTable.get(this);
1319
+ if (!listeners) return;
1320
+ var count = 0, found = false;
1321
+ for (var i = 0; i < listeners.length; i++) {
1322
+ if (listeners[i].type === type && listeners[i].capture === capture) {
1323
+ count++;
1324
+ if (listeners[i].handler === fun) {
1325
+ found = true;
1326
+ listeners[i].remove();
1327
+ }
1328
+ }
1329
+ }
1330
+ if (found && count === 1) {
1331
+ var target = getTargetToListenAt(this);
1332
+ target.removeEventListener_(type, dispatchOriginalEvent, true);
1333
+ }
1334
+ },
1335
+ dispatchEvent: function(event) {
1336
+ var nativeEvent = unwrap(event);
1337
+ var eventType = nativeEvent.type;
1338
+ handledEventsTable.set(nativeEvent, false);
1339
+ scope.renderAllPending();
1340
+ var tempListener;
1341
+ if (!hasListenerInAncestors(this, eventType)) {
1342
+ tempListener = function() {};
1343
+ this.addEventListener(eventType, tempListener, true);
1344
+ }
1345
+ try {
1346
+ return unwrap(this).dispatchEvent_(nativeEvent);
1347
+ } finally {
1348
+ if (tempListener) this.removeEventListener(eventType, tempListener, true);
1349
+ }
1350
+ }
1351
+ };
1352
+ function hasListener(node, type) {
1353
+ var listeners = listenersTable.get(node);
1354
+ if (listeners) {
1355
+ for (var i = 0; i < listeners.length; i++) {
1356
+ if (!listeners[i].removed && listeners[i].type === type) return true;
1357
+ }
1358
+ }
1359
+ return false;
1360
+ }
1361
+ function hasListenerInAncestors(target, type) {
1362
+ for (var node = unwrap(target); node; node = node.parentNode) {
1363
+ if (hasListener(wrap(node), type)) return true;
1364
+ }
1365
+ return false;
1366
+ }
1367
+ if (OriginalEventTarget) registerWrapper(OriginalEventTarget, EventTarget);
1368
+ function wrapEventTargetMethods(constructors) {
1369
+ forwardMethodsToWrapper(constructors, methodNames);
1370
+ }
1371
+ var originalElementFromPoint = document.elementFromPoint;
1372
+ function elementFromPoint(self, document, x, y) {
1373
+ scope.renderAllPending();
1374
+ var element = wrap(originalElementFromPoint.call(unsafeUnwrap(document), x, y));
1375
+ if (!element) return null;
1376
+ var path = getEventPath(element, null);
1377
+ var idx = path.lastIndexOf(self);
1378
+ if (idx == -1) return null; else path = path.slice(0, idx);
1379
+ return eventRetargetting(path, self);
1380
+ }
1381
+ function getEventHandlerGetter(name) {
1382
+ return function() {
1383
+ var inlineEventHandlers = eventHandlersTable.get(this);
1384
+ return inlineEventHandlers && inlineEventHandlers[name] && inlineEventHandlers[name].value || null;
1385
+ };
1386
+ }
1387
+ function getEventHandlerSetter(name) {
1388
+ var eventType = name.slice(2);
1389
+ return function(value) {
1390
+ var inlineEventHandlers = eventHandlersTable.get(this);
1391
+ if (!inlineEventHandlers) {
1392
+ inlineEventHandlers = Object.create(null);
1393
+ eventHandlersTable.set(this, inlineEventHandlers);
1394
+ }
1395
+ var old = inlineEventHandlers[name];
1396
+ if (old) this.removeEventListener(eventType, old.wrapped, false);
1397
+ if (typeof value === "function") {
1398
+ var wrapped = function(e) {
1399
+ var rv = value.call(this, e);
1400
+ if (rv === false) e.preventDefault(); else if (name === "onbeforeunload" && typeof rv === "string") e.returnValue = rv;
1401
+ };
1402
+ this.addEventListener(eventType, wrapped, false);
1403
+ inlineEventHandlers[name] = {
1404
+ value: value,
1405
+ wrapped: wrapped
1406
+ };
1407
+ }
1408
+ };
1409
+ }
1410
+ scope.elementFromPoint = elementFromPoint;
1411
+ scope.getEventHandlerGetter = getEventHandlerGetter;
1412
+ scope.getEventHandlerSetter = getEventHandlerSetter;
1413
+ scope.wrapEventTargetMethods = wrapEventTargetMethods;
1414
+ scope.wrappers.BeforeUnloadEvent = BeforeUnloadEvent;
1415
+ scope.wrappers.CustomEvent = CustomEvent;
1416
+ scope.wrappers.Event = Event;
1417
+ scope.wrappers.EventTarget = EventTarget;
1418
+ scope.wrappers.FocusEvent = FocusEvent;
1419
+ scope.wrappers.MouseEvent = MouseEvent;
1420
+ scope.wrappers.UIEvent = UIEvent;
1421
+ })(window.ShadowDOMPolyfill);
1422
+ (function(scope) {
1423
+ "use strict";
1424
+ var UIEvent = scope.wrappers.UIEvent;
1425
+ var mixin = scope.mixin;
1426
+ var registerWrapper = scope.registerWrapper;
1427
+ var setWrapper = scope.setWrapper;
1428
+ var unsafeUnwrap = scope.unsafeUnwrap;
1429
+ var wrap = scope.wrap;
1430
+ var OriginalTouchEvent = window.TouchEvent;
1431
+ if (!OriginalTouchEvent) return;
1432
+ var nativeEvent;
1433
+ try {
1434
+ nativeEvent = document.createEvent("TouchEvent");
1435
+ } catch (ex) {
1436
+ return;
1437
+ }
1438
+ var nonEnumDescriptor = {
1439
+ enumerable: false
1440
+ };
1441
+ function nonEnum(obj, prop) {
1442
+ Object.defineProperty(obj, prop, nonEnumDescriptor);
1443
+ }
1444
+ function Touch(impl) {
1445
+ setWrapper(impl, this);
1446
+ }
1447
+ Touch.prototype = {
1448
+ get target() {
1449
+ return wrap(unsafeUnwrap(this).target);
1450
+ }
1451
+ };
1452
+ var descr = {
1453
+ configurable: true,
1454
+ enumerable: true,
1455
+ get: null
1456
+ };
1457
+ [ "clientX", "clientY", "screenX", "screenY", "pageX", "pageY", "identifier", "webkitRadiusX", "webkitRadiusY", "webkitRotationAngle", "webkitForce" ].forEach(function(name) {
1458
+ descr.get = function() {
1459
+ return unsafeUnwrap(this)[name];
1460
+ };
1461
+ Object.defineProperty(Touch.prototype, name, descr);
1462
+ });
1463
+ function TouchList() {
1464
+ this.length = 0;
1465
+ nonEnum(this, "length");
1466
+ }
1467
+ TouchList.prototype = {
1468
+ item: function(index) {
1469
+ return this[index];
1470
+ }
1471
+ };
1472
+ function wrapTouchList(nativeTouchList) {
1473
+ var list = new TouchList();
1474
+ for (var i = 0; i < nativeTouchList.length; i++) {
1475
+ list[i] = new Touch(nativeTouchList[i]);
1476
+ }
1477
+ list.length = i;
1478
+ return list;
1479
+ }
1480
+ function TouchEvent(impl) {
1481
+ UIEvent.call(this, impl);
1482
+ }
1483
+ TouchEvent.prototype = Object.create(UIEvent.prototype);
1484
+ mixin(TouchEvent.prototype, {
1485
+ get touches() {
1486
+ return wrapTouchList(unsafeUnwrap(this).touches);
1487
+ },
1488
+ get targetTouches() {
1489
+ return wrapTouchList(unsafeUnwrap(this).targetTouches);
1490
+ },
1491
+ get changedTouches() {
1492
+ return wrapTouchList(unsafeUnwrap(this).changedTouches);
1493
+ },
1494
+ initTouchEvent: function() {
1495
+ throw new Error("Not implemented");
1496
+ }
1497
+ });
1498
+ registerWrapper(OriginalTouchEvent, TouchEvent, nativeEvent);
1499
+ scope.wrappers.Touch = Touch;
1500
+ scope.wrappers.TouchEvent = TouchEvent;
1501
+ scope.wrappers.TouchList = TouchList;
1502
+ })(window.ShadowDOMPolyfill);
1503
+ (function(scope) {
1504
+ "use strict";
1505
+ var unsafeUnwrap = scope.unsafeUnwrap;
1506
+ var wrap = scope.wrap;
1507
+ var nonEnumDescriptor = {
1508
+ enumerable: false
1509
+ };
1510
+ function nonEnum(obj, prop) {
1511
+ Object.defineProperty(obj, prop, nonEnumDescriptor);
1512
+ }
1513
+ function NodeList() {
1514
+ this.length = 0;
1515
+ nonEnum(this, "length");
1516
+ }
1517
+ NodeList.prototype = {
1518
+ item: function(index) {
1519
+ return this[index];
1520
+ }
1521
+ };
1522
+ nonEnum(NodeList.prototype, "item");
1523
+ function wrapNodeList(list) {
1524
+ if (list == null) return list;
1525
+ var wrapperList = new NodeList();
1526
+ for (var i = 0, length = list.length; i < length; i++) {
1527
+ wrapperList[i] = wrap(list[i]);
1528
+ }
1529
+ wrapperList.length = length;
1530
+ return wrapperList;
1531
+ }
1532
+ function addWrapNodeListMethod(wrapperConstructor, name) {
1533
+ wrapperConstructor.prototype[name] = function() {
1534
+ return wrapNodeList(unsafeUnwrap(this)[name].apply(unsafeUnwrap(this), arguments));
1535
+ };
1536
+ }
1537
+ scope.wrappers.NodeList = NodeList;
1538
+ scope.addWrapNodeListMethod = addWrapNodeListMethod;
1539
+ scope.wrapNodeList = wrapNodeList;
1540
+ })(window.ShadowDOMPolyfill);
1541
+ (function(scope) {
1542
+ "use strict";
1543
+ scope.wrapHTMLCollection = scope.wrapNodeList;
1544
+ scope.wrappers.HTMLCollection = scope.wrappers.NodeList;
1545
+ })(window.ShadowDOMPolyfill);
1546
+ (function(scope) {
1547
+ "use strict";
1548
+ var EventTarget = scope.wrappers.EventTarget;
1549
+ var NodeList = scope.wrappers.NodeList;
1550
+ var TreeScope = scope.TreeScope;
1551
+ var assert = scope.assert;
1552
+ var defineWrapGetter = scope.defineWrapGetter;
1553
+ var enqueueMutation = scope.enqueueMutation;
1554
+ var getTreeScope = scope.getTreeScope;
1555
+ var isWrapper = scope.isWrapper;
1556
+ var mixin = scope.mixin;
1557
+ var registerTransientObservers = scope.registerTransientObservers;
1558
+ var registerWrapper = scope.registerWrapper;
1559
+ var setTreeScope = scope.setTreeScope;
1560
+ var unsafeUnwrap = scope.unsafeUnwrap;
1561
+ var unwrap = scope.unwrap;
1562
+ var unwrapIfNeeded = scope.unwrapIfNeeded;
1563
+ var wrap = scope.wrap;
1564
+ var wrapIfNeeded = scope.wrapIfNeeded;
1565
+ var wrappers = scope.wrappers;
1566
+ function assertIsNodeWrapper(node) {
1567
+ assert(node instanceof Node);
1568
+ }
1569
+ function createOneElementNodeList(node) {
1570
+ var nodes = new NodeList();
1571
+ nodes[0] = node;
1572
+ nodes.length = 1;
1573
+ return nodes;
1574
+ }
1575
+ var surpressMutations = false;
1576
+ function enqueueRemovalForInsertedNodes(node, parent, nodes) {
1577
+ enqueueMutation(parent, "childList", {
1578
+ removedNodes: nodes,
1579
+ previousSibling: node.previousSibling,
1580
+ nextSibling: node.nextSibling
1581
+ });
1582
+ }
1583
+ function enqueueRemovalForInsertedDocumentFragment(df, nodes) {
1584
+ enqueueMutation(df, "childList", {
1585
+ removedNodes: nodes
1586
+ });
1587
+ }
1588
+ function collectNodes(node, parentNode, previousNode, nextNode) {
1589
+ if (node instanceof DocumentFragment) {
1590
+ var nodes = collectNodesForDocumentFragment(node);
1591
+ surpressMutations = true;
1592
+ for (var i = nodes.length - 1; i >= 0; i--) {
1593
+ node.removeChild(nodes[i]);
1594
+ nodes[i].parentNode_ = parentNode;
1595
+ }
1596
+ surpressMutations = false;
1597
+ for (var i = 0; i < nodes.length; i++) {
1598
+ nodes[i].previousSibling_ = nodes[i - 1] || previousNode;
1599
+ nodes[i].nextSibling_ = nodes[i + 1] || nextNode;
1600
+ }
1601
+ if (previousNode) previousNode.nextSibling_ = nodes[0];
1602
+ if (nextNode) nextNode.previousSibling_ = nodes[nodes.length - 1];
1603
+ return nodes;
1604
+ }
1605
+ var nodes = createOneElementNodeList(node);
1606
+ var oldParent = node.parentNode;
1607
+ if (oldParent) {
1608
+ oldParent.removeChild(node);
1609
+ }
1610
+ node.parentNode_ = parentNode;
1611
+ node.previousSibling_ = previousNode;
1612
+ node.nextSibling_ = nextNode;
1613
+ if (previousNode) previousNode.nextSibling_ = node;
1614
+ if (nextNode) nextNode.previousSibling_ = node;
1615
+ return nodes;
1616
+ }
1617
+ function collectNodesNative(node) {
1618
+ if (node instanceof DocumentFragment) return collectNodesForDocumentFragment(node);
1619
+ var nodes = createOneElementNodeList(node);
1620
+ var oldParent = node.parentNode;
1621
+ if (oldParent) enqueueRemovalForInsertedNodes(node, oldParent, nodes);
1622
+ return nodes;
1623
+ }
1624
+ function collectNodesForDocumentFragment(node) {
1625
+ var nodes = new NodeList();
1626
+ var i = 0;
1627
+ for (var child = node.firstChild; child; child = child.nextSibling) {
1628
+ nodes[i++] = child;
1629
+ }
1630
+ nodes.length = i;
1631
+ enqueueRemovalForInsertedDocumentFragment(node, nodes);
1632
+ return nodes;
1633
+ }
1634
+ function snapshotNodeList(nodeList) {
1635
+ return nodeList;
1636
+ }
1637
+ function nodeWasAdded(node, treeScope) {
1638
+ setTreeScope(node, treeScope);
1639
+ node.nodeIsInserted_();
1640
+ }
1641
+ function nodesWereAdded(nodes, parent) {
1642
+ var treeScope = getTreeScope(parent);
1643
+ for (var i = 0; i < nodes.length; i++) {
1644
+ nodeWasAdded(nodes[i], treeScope);
1645
+ }
1646
+ }
1647
+ function nodeWasRemoved(node) {
1648
+ setTreeScope(node, new TreeScope(node, null));
1649
+ }
1650
+ function nodesWereRemoved(nodes) {
1651
+ for (var i = 0; i < nodes.length; i++) {
1652
+ nodeWasRemoved(nodes[i]);
1653
+ }
1654
+ }
1655
+ function ensureSameOwnerDocument(parent, child) {
1656
+ var ownerDoc = parent.nodeType === Node.DOCUMENT_NODE ? parent : parent.ownerDocument;
1657
+ if (ownerDoc !== child.ownerDocument) ownerDoc.adoptNode(child);
1658
+ }
1659
+ function adoptNodesIfNeeded(owner, nodes) {
1660
+ if (!nodes.length) return;
1661
+ var ownerDoc = owner.ownerDocument;
1662
+ if (ownerDoc === nodes[0].ownerDocument) return;
1663
+ for (var i = 0; i < nodes.length; i++) {
1664
+ scope.adoptNodeNoRemove(nodes[i], ownerDoc);
1665
+ }
1666
+ }
1667
+ function unwrapNodesForInsertion(owner, nodes) {
1668
+ adoptNodesIfNeeded(owner, nodes);
1669
+ var length = nodes.length;
1670
+ if (length === 1) return unwrap(nodes[0]);
1671
+ var df = unwrap(owner.ownerDocument.createDocumentFragment());
1672
+ for (var i = 0; i < length; i++) {
1673
+ df.appendChild(unwrap(nodes[i]));
1674
+ }
1675
+ return df;
1676
+ }
1677
+ function clearChildNodes(wrapper) {
1678
+ if (wrapper.firstChild_ !== undefined) {
1679
+ var child = wrapper.firstChild_;
1680
+ while (child) {
1681
+ var tmp = child;
1682
+ child = child.nextSibling_;
1683
+ tmp.parentNode_ = tmp.previousSibling_ = tmp.nextSibling_ = undefined;
1684
+ }
1685
+ }
1686
+ wrapper.firstChild_ = wrapper.lastChild_ = undefined;
1687
+ }
1688
+ function removeAllChildNodes(wrapper) {
1689
+ if (wrapper.invalidateShadowRenderer()) {
1690
+ var childWrapper = wrapper.firstChild;
1691
+ while (childWrapper) {
1692
+ assert(childWrapper.parentNode === wrapper);
1693
+ var nextSibling = childWrapper.nextSibling;
1694
+ var childNode = unwrap(childWrapper);
1695
+ var parentNode = childNode.parentNode;
1696
+ if (parentNode) originalRemoveChild.call(parentNode, childNode);
1697
+ childWrapper.previousSibling_ = childWrapper.nextSibling_ = childWrapper.parentNode_ = null;
1698
+ childWrapper = nextSibling;
1699
+ }
1700
+ wrapper.firstChild_ = wrapper.lastChild_ = null;
1701
+ } else {
1702
+ var node = unwrap(wrapper);
1703
+ var child = node.firstChild;
1704
+ var nextSibling;
1705
+ while (child) {
1706
+ nextSibling = child.nextSibling;
1707
+ originalRemoveChild.call(node, child);
1708
+ child = nextSibling;
1709
+ }
1710
+ }
1711
+ }
1712
+ function invalidateParent(node) {
1713
+ var p = node.parentNode;
1714
+ return p && p.invalidateShadowRenderer();
1715
+ }
1716
+ function cleanupNodes(nodes) {
1717
+ for (var i = 0, n; i < nodes.length; i++) {
1718
+ n = nodes[i];
1719
+ n.parentNode.removeChild(n);
1720
+ }
1721
+ }
1722
+ var originalImportNode = document.importNode;
1723
+ var originalCloneNode = window.Node.prototype.cloneNode;
1724
+ function cloneNode(node, deep, opt_doc) {
1725
+ var clone;
1726
+ if (opt_doc) clone = wrap(originalImportNode.call(opt_doc, unsafeUnwrap(node), false)); else clone = wrap(originalCloneNode.call(unsafeUnwrap(node), false));
1727
+ if (deep) {
1728
+ for (var child = node.firstChild; child; child = child.nextSibling) {
1729
+ clone.appendChild(cloneNode(child, true, opt_doc));
1730
+ }
1731
+ if (node instanceof wrappers.HTMLTemplateElement) {
1732
+ var cloneContent = clone.content;
1733
+ for (var child = node.content.firstChild; child; child = child.nextSibling) {
1734
+ cloneContent.appendChild(cloneNode(child, true, opt_doc));
1735
+ }
1736
+ }
1737
+ }
1738
+ return clone;
1739
+ }
1740
+ function contains(self, child) {
1741
+ if (!child || getTreeScope(self) !== getTreeScope(child)) return false;
1742
+ for (var node = child; node; node = node.parentNode) {
1743
+ if (node === self) return true;
1744
+ }
1745
+ return false;
1746
+ }
1747
+ var OriginalNode = window.Node;
1748
+ function Node(original) {
1749
+ assert(original instanceof OriginalNode);
1750
+ EventTarget.call(this, original);
1751
+ this.parentNode_ = undefined;
1752
+ this.firstChild_ = undefined;
1753
+ this.lastChild_ = undefined;
1754
+ this.nextSibling_ = undefined;
1755
+ this.previousSibling_ = undefined;
1756
+ this.treeScope_ = undefined;
1757
+ }
1758
+ var OriginalDocumentFragment = window.DocumentFragment;
1759
+ var originalAppendChild = OriginalNode.prototype.appendChild;
1760
+ var originalCompareDocumentPosition = OriginalNode.prototype.compareDocumentPosition;
1761
+ var originalInsertBefore = OriginalNode.prototype.insertBefore;
1762
+ var originalRemoveChild = OriginalNode.prototype.removeChild;
1763
+ var originalReplaceChild = OriginalNode.prototype.replaceChild;
1764
+ var isIe = /Trident/.test(navigator.userAgent);
1765
+ var removeChildOriginalHelper = isIe ? function(parent, child) {
1766
+ try {
1767
+ originalRemoveChild.call(parent, child);
1768
+ } catch (ex) {
1769
+ if (!(parent instanceof OriginalDocumentFragment)) throw ex;
1770
+ }
1771
+ } : function(parent, child) {
1772
+ originalRemoveChild.call(parent, child);
1773
+ };
1774
+ Node.prototype = Object.create(EventTarget.prototype);
1775
+ mixin(Node.prototype, {
1776
+ appendChild: function(childWrapper) {
1777
+ return this.insertBefore(childWrapper, null);
1778
+ },
1779
+ insertBefore: function(childWrapper, refWrapper) {
1780
+ assertIsNodeWrapper(childWrapper);
1781
+ var refNode;
1782
+ if (refWrapper) {
1783
+ if (isWrapper(refWrapper)) {
1784
+ refNode = unwrap(refWrapper);
1785
+ } else {
1786
+ refNode = refWrapper;
1787
+ refWrapper = wrap(refNode);
1788
+ }
1789
+ } else {
1790
+ refWrapper = null;
1791
+ refNode = null;
1792
+ }
1793
+ refWrapper && assert(refWrapper.parentNode === this);
1794
+ var nodes;
1795
+ var previousNode = refWrapper ? refWrapper.previousSibling : this.lastChild;
1796
+ var useNative = !this.invalidateShadowRenderer() && !invalidateParent(childWrapper);
1797
+ if (useNative) nodes = collectNodesNative(childWrapper); else nodes = collectNodes(childWrapper, this, previousNode, refWrapper);
1798
+ if (useNative) {
1799
+ ensureSameOwnerDocument(this, childWrapper);
1800
+ clearChildNodes(this);
1801
+ originalInsertBefore.call(unsafeUnwrap(this), unwrap(childWrapper), refNode);
1802
+ } else {
1803
+ if (!previousNode) this.firstChild_ = nodes[0];
1804
+ if (!refWrapper) {
1805
+ this.lastChild_ = nodes[nodes.length - 1];
1806
+ if (this.firstChild_ === undefined) this.firstChild_ = this.firstChild;
1807
+ }
1808
+ var parentNode = refNode ? refNode.parentNode : unsafeUnwrap(this);
1809
+ if (parentNode) {
1810
+ originalInsertBefore.call(parentNode, unwrapNodesForInsertion(this, nodes), refNode);
1811
+ } else {
1812
+ adoptNodesIfNeeded(this, nodes);
1813
+ }
1814
+ }
1815
+ enqueueMutation(this, "childList", {
1816
+ addedNodes: nodes,
1817
+ nextSibling: refWrapper,
1818
+ previousSibling: previousNode
1819
+ });
1820
+ nodesWereAdded(nodes, this);
1821
+ return childWrapper;
1822
+ },
1823
+ removeChild: function(childWrapper) {
1824
+ assertIsNodeWrapper(childWrapper);
1825
+ if (childWrapper.parentNode !== this) {
1826
+ var found = false;
1827
+ var childNodes = this.childNodes;
1828
+ for (var ieChild = this.firstChild; ieChild; ieChild = ieChild.nextSibling) {
1829
+ if (ieChild === childWrapper) {
1830
+ found = true;
1831
+ break;
1832
+ }
1833
+ }
1834
+ if (!found) {
1835
+ throw new Error("NotFoundError");
1836
+ }
1837
+ }
1838
+ var childNode = unwrap(childWrapper);
1839
+ var childWrapperNextSibling = childWrapper.nextSibling;
1840
+ var childWrapperPreviousSibling = childWrapper.previousSibling;
1841
+ if (this.invalidateShadowRenderer()) {
1842
+ var thisFirstChild = this.firstChild;
1843
+ var thisLastChild = this.lastChild;
1844
+ var parentNode = childNode.parentNode;
1845
+ if (parentNode) removeChildOriginalHelper(parentNode, childNode);
1846
+ if (thisFirstChild === childWrapper) this.firstChild_ = childWrapperNextSibling;
1847
+ if (thisLastChild === childWrapper) this.lastChild_ = childWrapperPreviousSibling;
1848
+ if (childWrapperPreviousSibling) childWrapperPreviousSibling.nextSibling_ = childWrapperNextSibling;
1849
+ if (childWrapperNextSibling) {
1850
+ childWrapperNextSibling.previousSibling_ = childWrapperPreviousSibling;
1851
+ }
1852
+ childWrapper.previousSibling_ = childWrapper.nextSibling_ = childWrapper.parentNode_ = undefined;
1853
+ } else {
1854
+ clearChildNodes(this);
1855
+ removeChildOriginalHelper(unsafeUnwrap(this), childNode);
1856
+ }
1857
+ if (!surpressMutations) {
1858
+ enqueueMutation(this, "childList", {
1859
+ removedNodes: createOneElementNodeList(childWrapper),
1860
+ nextSibling: childWrapperNextSibling,
1861
+ previousSibling: childWrapperPreviousSibling
1862
+ });
1863
+ }
1864
+ registerTransientObservers(this, childWrapper);
1865
+ return childWrapper;
1866
+ },
1867
+ replaceChild: function(newChildWrapper, oldChildWrapper) {
1868
+ assertIsNodeWrapper(newChildWrapper);
1869
+ var oldChildNode;
1870
+ if (isWrapper(oldChildWrapper)) {
1871
+ oldChildNode = unwrap(oldChildWrapper);
1872
+ } else {
1873
+ oldChildNode = oldChildWrapper;
1874
+ oldChildWrapper = wrap(oldChildNode);
1875
+ }
1876
+ if (oldChildWrapper.parentNode !== this) {
1877
+ throw new Error("NotFoundError");
1878
+ }
1879
+ var nextNode = oldChildWrapper.nextSibling;
1880
+ var previousNode = oldChildWrapper.previousSibling;
1881
+ var nodes;
1882
+ var useNative = !this.invalidateShadowRenderer() && !invalidateParent(newChildWrapper);
1883
+ if (useNative) {
1884
+ nodes = collectNodesNative(newChildWrapper);
1885
+ } else {
1886
+ if (nextNode === newChildWrapper) nextNode = newChildWrapper.nextSibling;
1887
+ nodes = collectNodes(newChildWrapper, this, previousNode, nextNode);
1888
+ }
1889
+ if (!useNative) {
1890
+ if (this.firstChild === oldChildWrapper) this.firstChild_ = nodes[0];
1891
+ if (this.lastChild === oldChildWrapper) this.lastChild_ = nodes[nodes.length - 1];
1892
+ oldChildWrapper.previousSibling_ = oldChildWrapper.nextSibling_ = oldChildWrapper.parentNode_ = undefined;
1893
+ if (oldChildNode.parentNode) {
1894
+ originalReplaceChild.call(oldChildNode.parentNode, unwrapNodesForInsertion(this, nodes), oldChildNode);
1895
+ }
1896
+ } else {
1897
+ ensureSameOwnerDocument(this, newChildWrapper);
1898
+ clearChildNodes(this);
1899
+ originalReplaceChild.call(unsafeUnwrap(this), unwrap(newChildWrapper), oldChildNode);
1900
+ }
1901
+ enqueueMutation(this, "childList", {
1902
+ addedNodes: nodes,
1903
+ removedNodes: createOneElementNodeList(oldChildWrapper),
1904
+ nextSibling: nextNode,
1905
+ previousSibling: previousNode
1906
+ });
1907
+ nodeWasRemoved(oldChildWrapper);
1908
+ nodesWereAdded(nodes, this);
1909
+ return oldChildWrapper;
1910
+ },
1911
+ nodeIsInserted_: function() {
1912
+ for (var child = this.firstChild; child; child = child.nextSibling) {
1913
+ child.nodeIsInserted_();
1914
+ }
1915
+ },
1916
+ hasChildNodes: function() {
1917
+ return this.firstChild !== null;
1918
+ },
1919
+ get parentNode() {
1920
+ return this.parentNode_ !== undefined ? this.parentNode_ : wrap(unsafeUnwrap(this).parentNode);
1921
+ },
1922
+ get firstChild() {
1923
+ return this.firstChild_ !== undefined ? this.firstChild_ : wrap(unsafeUnwrap(this).firstChild);
1924
+ },
1925
+ get lastChild() {
1926
+ return this.lastChild_ !== undefined ? this.lastChild_ : wrap(unsafeUnwrap(this).lastChild);
1927
+ },
1928
+ get nextSibling() {
1929
+ return this.nextSibling_ !== undefined ? this.nextSibling_ : wrap(unsafeUnwrap(this).nextSibling);
1930
+ },
1931
+ get previousSibling() {
1932
+ return this.previousSibling_ !== undefined ? this.previousSibling_ : wrap(unsafeUnwrap(this).previousSibling);
1933
+ },
1934
+ get parentElement() {
1935
+ var p = this.parentNode;
1936
+ while (p && p.nodeType !== Node.ELEMENT_NODE) {
1937
+ p = p.parentNode;
1938
+ }
1939
+ return p;
1940
+ },
1941
+ get textContent() {
1942
+ var s = "";
1943
+ for (var child = this.firstChild; child; child = child.nextSibling) {
1944
+ if (child.nodeType != Node.COMMENT_NODE) {
1945
+ s += child.textContent;
1946
+ }
1947
+ }
1948
+ return s;
1949
+ },
1950
+ set textContent(textContent) {
1951
+ if (textContent == null) textContent = "";
1952
+ var removedNodes = snapshotNodeList(this.childNodes);
1953
+ if (this.invalidateShadowRenderer()) {
1954
+ removeAllChildNodes(this);
1955
+ if (textContent !== "") {
1956
+ var textNode = unsafeUnwrap(this).ownerDocument.createTextNode(textContent);
1957
+ this.appendChild(textNode);
1958
+ }
1959
+ } else {
1960
+ clearChildNodes(this);
1961
+ unsafeUnwrap(this).textContent = textContent;
1962
+ }
1963
+ var addedNodes = snapshotNodeList(this.childNodes);
1964
+ enqueueMutation(this, "childList", {
1965
+ addedNodes: addedNodes,
1966
+ removedNodes: removedNodes
1967
+ });
1968
+ nodesWereRemoved(removedNodes);
1969
+ nodesWereAdded(addedNodes, this);
1970
+ },
1971
+ get childNodes() {
1972
+ var wrapperList = new NodeList();
1973
+ var i = 0;
1974
+ for (var child = this.firstChild; child; child = child.nextSibling) {
1975
+ wrapperList[i++] = child;
1976
+ }
1977
+ wrapperList.length = i;
1978
+ return wrapperList;
1979
+ },
1980
+ cloneNode: function(deep) {
1981
+ return cloneNode(this, deep);
1982
+ },
1983
+ contains: function(child) {
1984
+ return contains(this, wrapIfNeeded(child));
1985
+ },
1986
+ compareDocumentPosition: function(otherNode) {
1987
+ return originalCompareDocumentPosition.call(unsafeUnwrap(this), unwrapIfNeeded(otherNode));
1988
+ },
1989
+ normalize: function() {
1990
+ var nodes = snapshotNodeList(this.childNodes);
1991
+ var remNodes = [];
1992
+ var s = "";
1993
+ var modNode;
1994
+ for (var i = 0, n; i < nodes.length; i++) {
1995
+ n = nodes[i];
1996
+ if (n.nodeType === Node.TEXT_NODE) {
1997
+ if (!modNode && !n.data.length) this.removeNode(n); else if (!modNode) modNode = n; else {
1998
+ s += n.data;
1999
+ remNodes.push(n);
2000
+ }
2001
+ } else {
2002
+ if (modNode && remNodes.length) {
2003
+ modNode.data += s;
2004
+ cleanupNodes(remNodes);
2005
+ }
2006
+ remNodes = [];
2007
+ s = "";
2008
+ modNode = null;
2009
+ if (n.childNodes.length) n.normalize();
2010
+ }
2011
+ }
2012
+ if (modNode && remNodes.length) {
2013
+ modNode.data += s;
2014
+ cleanupNodes(remNodes);
2015
+ }
2016
+ }
2017
+ });
2018
+ defineWrapGetter(Node, "ownerDocument");
2019
+ registerWrapper(OriginalNode, Node, document.createDocumentFragment());
2020
+ delete Node.prototype.querySelector;
2021
+ delete Node.prototype.querySelectorAll;
2022
+ Node.prototype = mixin(Object.create(EventTarget.prototype), Node.prototype);
2023
+ scope.cloneNode = cloneNode;
2024
+ scope.nodeWasAdded = nodeWasAdded;
2025
+ scope.nodeWasRemoved = nodeWasRemoved;
2026
+ scope.nodesWereAdded = nodesWereAdded;
2027
+ scope.nodesWereRemoved = nodesWereRemoved;
2028
+ scope.originalInsertBefore = originalInsertBefore;
2029
+ scope.originalRemoveChild = originalRemoveChild;
2030
+ scope.snapshotNodeList = snapshotNodeList;
2031
+ scope.wrappers.Node = Node;
2032
+ })(window.ShadowDOMPolyfill);
2033
+ (function(scope) {
2034
+ "use strict";
2035
+ var HTMLCollection = scope.wrappers.HTMLCollection;
2036
+ var NodeList = scope.wrappers.NodeList;
2037
+ var getTreeScope = scope.getTreeScope;
2038
+ var unsafeUnwrap = scope.unsafeUnwrap;
2039
+ var wrap = scope.wrap;
2040
+ var originalDocumentQuerySelector = document.querySelector;
2041
+ var originalElementQuerySelector = document.documentElement.querySelector;
2042
+ var originalDocumentQuerySelectorAll = document.querySelectorAll;
2043
+ var originalElementQuerySelectorAll = document.documentElement.querySelectorAll;
2044
+ var originalDocumentGetElementsByTagName = document.getElementsByTagName;
2045
+ var originalElementGetElementsByTagName = document.documentElement.getElementsByTagName;
2046
+ var originalDocumentGetElementsByTagNameNS = document.getElementsByTagNameNS;
2047
+ var originalElementGetElementsByTagNameNS = document.documentElement.getElementsByTagNameNS;
2048
+ var OriginalElement = window.Element;
2049
+ var OriginalDocument = window.HTMLDocument || window.Document;
2050
+ function filterNodeList(list, index, result, deep) {
2051
+ var wrappedItem = null;
2052
+ var root = null;
2053
+ for (var i = 0, length = list.length; i < length; i++) {
2054
+ wrappedItem = wrap(list[i]);
2055
+ if (!deep && (root = getTreeScope(wrappedItem).root)) {
2056
+ if (root instanceof scope.wrappers.ShadowRoot) {
2057
+ continue;
2058
+ }
2059
+ }
2060
+ result[index++] = wrappedItem;
2061
+ }
2062
+ return index;
2063
+ }
2064
+ function shimSelector(selector) {
2065
+ return String(selector).replace(/\/deep\//g, " ");
2066
+ }
2067
+ function findOne(node, selector) {
2068
+ var m, el = node.firstElementChild;
2069
+ while (el) {
2070
+ if (el.matches(selector)) return el;
2071
+ m = findOne(el, selector);
2072
+ if (m) return m;
2073
+ el = el.nextElementSibling;
2074
+ }
2075
+ return null;
2076
+ }
2077
+ function matchesSelector(el, selector) {
2078
+ return el.matches(selector);
2079
+ }
2080
+ var XHTML_NS = "http://www.w3.org/1999/xhtml";
2081
+ function matchesTagName(el, localName, localNameLowerCase) {
2082
+ var ln = el.localName;
2083
+ return ln === localName || ln === localNameLowerCase && el.namespaceURI === XHTML_NS;
2084
+ }
2085
+ function matchesEveryThing() {
2086
+ return true;
2087
+ }
2088
+ function matchesLocalNameOnly(el, ns, localName) {
2089
+ return el.localName === localName;
2090
+ }
2091
+ function matchesNameSpace(el, ns) {
2092
+ return el.namespaceURI === ns;
2093
+ }
2094
+ function matchesLocalNameNS(el, ns, localName) {
2095
+ return el.namespaceURI === ns && el.localName === localName;
2096
+ }
2097
+ function findElements(node, index, result, p, arg0, arg1) {
2098
+ var el = node.firstElementChild;
2099
+ while (el) {
2100
+ if (p(el, arg0, arg1)) result[index++] = el;
2101
+ index = findElements(el, index, result, p, arg0, arg1);
2102
+ el = el.nextElementSibling;
2103
+ }
2104
+ return index;
2105
+ }
2106
+ function querySelectorAllFiltered(p, index, result, selector, deep) {
2107
+ var target = unsafeUnwrap(this);
2108
+ var list;
2109
+ var root = getTreeScope(this).root;
2110
+ if (root instanceof scope.wrappers.ShadowRoot) {
2111
+ return findElements(this, index, result, p, selector, null);
2112
+ } else if (target instanceof OriginalElement) {
2113
+ list = originalElementQuerySelectorAll.call(target, selector);
2114
+ } else if (target instanceof OriginalDocument) {
2115
+ list = originalDocumentQuerySelectorAll.call(target, selector);
2116
+ } else {
2117
+ return findElements(this, index, result, p, selector, null);
2118
+ }
2119
+ return filterNodeList(list, index, result, deep);
2120
+ }
2121
+ var SelectorsInterface = {
2122
+ querySelector: function(selector) {
2123
+ var shimmed = shimSelector(selector);
2124
+ var deep = shimmed !== selector;
2125
+ selector = shimmed;
2126
+ var target = unsafeUnwrap(this);
2127
+ var wrappedItem;
2128
+ var root = getTreeScope(this).root;
2129
+ if (root instanceof scope.wrappers.ShadowRoot) {
2130
+ return findOne(this, selector);
2131
+ } else if (target instanceof OriginalElement) {
2132
+ wrappedItem = wrap(originalElementQuerySelector.call(target, selector));
2133
+ } else if (target instanceof OriginalDocument) {
2134
+ wrappedItem = wrap(originalDocumentQuerySelector.call(target, selector));
2135
+ } else {
2136
+ return findOne(this, selector);
2137
+ }
2138
+ if (!wrappedItem) {
2139
+ return wrappedItem;
2140
+ } else if (!deep && (root = getTreeScope(wrappedItem).root)) {
2141
+ if (root instanceof scope.wrappers.ShadowRoot) {
2142
+ return findOne(this, selector);
2143
+ }
2144
+ }
2145
+ return wrappedItem;
2146
+ },
2147
+ querySelectorAll: function(selector) {
2148
+ var shimmed = shimSelector(selector);
2149
+ var deep = shimmed !== selector;
2150
+ selector = shimmed;
2151
+ var result = new NodeList();
2152
+ result.length = querySelectorAllFiltered.call(this, matchesSelector, 0, result, selector, deep);
2153
+ return result;
2154
+ }
2155
+ };
2156
+ function getElementsByTagNameFiltered(p, index, result, localName, lowercase) {
2157
+ var target = unsafeUnwrap(this);
2158
+ var list;
2159
+ var root = getTreeScope(this).root;
2160
+ if (root instanceof scope.wrappers.ShadowRoot) {
2161
+ return findElements(this, index, result, p, localName, lowercase);
2162
+ } else if (target instanceof OriginalElement) {
2163
+ list = originalElementGetElementsByTagName.call(target, localName, lowercase);
2164
+ } else if (target instanceof OriginalDocument) {
2165
+ list = originalDocumentGetElementsByTagName.call(target, localName, lowercase);
2166
+ } else {
2167
+ return findElements(this, index, result, p, localName, lowercase);
2168
+ }
2169
+ return filterNodeList(list, index, result, false);
2170
+ }
2171
+ function getElementsByTagNameNSFiltered(p, index, result, ns, localName) {
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, ns, localName);
2177
+ } else if (target instanceof OriginalElement) {
2178
+ list = originalElementGetElementsByTagNameNS.call(target, ns, localName);
2179
+ } else if (target instanceof OriginalDocument) {
2180
+ list = originalDocumentGetElementsByTagNameNS.call(target, ns, localName);
2181
+ } else {
2182
+ return findElements(this, index, result, p, ns, localName);
2183
+ }
2184
+ return filterNodeList(list, index, result, false);
2185
+ }
2186
+ var GetElementsByInterface = {
2187
+ getElementsByTagName: function(localName) {
2188
+ var result = new HTMLCollection();
2189
+ var match = localName === "*" ? matchesEveryThing : matchesTagName;
2190
+ result.length = getElementsByTagNameFiltered.call(this, match, 0, result, localName, localName.toLowerCase());
2191
+ return result;
2192
+ },
2193
+ getElementsByClassName: function(className) {
2194
+ return this.querySelectorAll("." + className);
2195
+ },
2196
+ getElementsByTagNameNS: function(ns, localName) {
2197
+ var result = new HTMLCollection();
2198
+ var match = null;
2199
+ if (ns === "*") {
2200
+ match = localName === "*" ? matchesEveryThing : matchesLocalNameOnly;
2201
+ } else {
2202
+ match = localName === "*" ? matchesNameSpace : matchesLocalNameNS;
2203
+ }
2204
+ result.length = getElementsByTagNameNSFiltered.call(this, match, 0, result, ns || null, localName);
2205
+ return result;
2206
+ }
2207
+ };
2208
+ scope.GetElementsByInterface = GetElementsByInterface;
2209
+ scope.SelectorsInterface = SelectorsInterface;
2210
+ })(window.ShadowDOMPolyfill);
2211
+ (function(scope) {
2212
+ "use strict";
2213
+ var NodeList = scope.wrappers.NodeList;
2214
+ function forwardElement(node) {
2215
+ while (node && node.nodeType !== Node.ELEMENT_NODE) {
2216
+ node = node.nextSibling;
2217
+ }
2218
+ return node;
2219
+ }
2220
+ function backwardsElement(node) {
2221
+ while (node && node.nodeType !== Node.ELEMENT_NODE) {
2222
+ node = node.previousSibling;
2223
+ }
2224
+ return node;
2225
+ }
2226
+ var ParentNodeInterface = {
2227
+ get firstElementChild() {
2228
+ return forwardElement(this.firstChild);
2229
+ },
2230
+ get lastElementChild() {
2231
+ return backwardsElement(this.lastChild);
2232
+ },
2233
+ get childElementCount() {
2234
+ var count = 0;
2235
+ for (var child = this.firstElementChild; child; child = child.nextElementSibling) {
2236
+ count++;
2237
+ }
2238
+ return count;
2239
+ },
2240
+ get children() {
2241
+ var wrapperList = new NodeList();
2242
+ var i = 0;
2243
+ for (var child = this.firstElementChild; child; child = child.nextElementSibling) {
2244
+ wrapperList[i++] = child;
2245
+ }
2246
+ wrapperList.length = i;
2247
+ return wrapperList;
2248
+ },
2249
+ remove: function() {
2250
+ var p = this.parentNode;
2251
+ if (p) p.removeChild(this);
2252
+ }
2253
+ };
2254
+ var ChildNodeInterface = {
2255
+ get nextElementSibling() {
2256
+ return forwardElement(this.nextSibling);
2257
+ },
2258
+ get previousElementSibling() {
2259
+ return backwardsElement(this.previousSibling);
2260
+ }
2261
+ };
2262
+ scope.ChildNodeInterface = ChildNodeInterface;
2263
+ scope.ParentNodeInterface = ParentNodeInterface;
2264
+ })(window.ShadowDOMPolyfill);
2265
+ (function(scope) {
2266
+ "use strict";
2267
+ var ChildNodeInterface = scope.ChildNodeInterface;
2268
+ var Node = scope.wrappers.Node;
2269
+ var enqueueMutation = scope.enqueueMutation;
2270
+ var mixin = scope.mixin;
2271
+ var registerWrapper = scope.registerWrapper;
2272
+ var unsafeUnwrap = scope.unsafeUnwrap;
2273
+ var OriginalCharacterData = window.CharacterData;
2274
+ function CharacterData(node) {
2275
+ Node.call(this, node);
2276
+ }
2277
+ CharacterData.prototype = Object.create(Node.prototype);
2278
+ mixin(CharacterData.prototype, {
2279
+ get textContent() {
2280
+ return this.data;
2281
+ },
2282
+ set textContent(value) {
2283
+ this.data = value;
2284
+ },
2285
+ get data() {
2286
+ return unsafeUnwrap(this).data;
2287
+ },
2288
+ set data(value) {
2289
+ var oldValue = unsafeUnwrap(this).data;
2290
+ enqueueMutation(this, "characterData", {
2291
+ oldValue: oldValue
2292
+ });
2293
+ unsafeUnwrap(this).data = value;
2294
+ }
2295
+ });
2296
+ mixin(CharacterData.prototype, ChildNodeInterface);
2297
+ registerWrapper(OriginalCharacterData, CharacterData, document.createTextNode(""));
2298
+ scope.wrappers.CharacterData = CharacterData;
2299
+ })(window.ShadowDOMPolyfill);
2300
+ (function(scope) {
2301
+ "use strict";
2302
+ var CharacterData = scope.wrappers.CharacterData;
2303
+ var enqueueMutation = scope.enqueueMutation;
2304
+ var mixin = scope.mixin;
2305
+ var registerWrapper = scope.registerWrapper;
2306
+ function toUInt32(x) {
2307
+ return x >>> 0;
2308
+ }
2309
+ var OriginalText = window.Text;
2310
+ function Text(node) {
2311
+ CharacterData.call(this, node);
2312
+ }
2313
+ Text.prototype = Object.create(CharacterData.prototype);
2314
+ mixin(Text.prototype, {
2315
+ splitText: function(offset) {
2316
+ offset = toUInt32(offset);
2317
+ var s = this.data;
2318
+ if (offset > s.length) throw new Error("IndexSizeError");
2319
+ var head = s.slice(0, offset);
2320
+ var tail = s.slice(offset);
2321
+ this.data = head;
2322
+ var newTextNode = this.ownerDocument.createTextNode(tail);
2323
+ if (this.parentNode) this.parentNode.insertBefore(newTextNode, this.nextSibling);
2324
+ return newTextNode;
2325
+ }
2326
+ });
2327
+ registerWrapper(OriginalText, Text, document.createTextNode(""));
2328
+ scope.wrappers.Text = Text;
2329
+ })(window.ShadowDOMPolyfill);
2330
+ (function(scope) {
2331
+ "use strict";
2332
+ var setWrapper = scope.setWrapper;
2333
+ var unsafeUnwrap = scope.unsafeUnwrap;
2334
+ function invalidateClass(el) {
2335
+ scope.invalidateRendererBasedOnAttribute(el, "class");
2336
+ }
2337
+ function DOMTokenList(impl, ownerElement) {
2338
+ setWrapper(impl, this);
2339
+ this.ownerElement_ = ownerElement;
2340
+ }
2341
+ DOMTokenList.prototype = {
2342
+ constructor: DOMTokenList,
2343
+ get length() {
2344
+ return unsafeUnwrap(this).length;
2345
+ },
2346
+ item: function(index) {
2347
+ return unsafeUnwrap(this).item(index);
2348
+ },
2349
+ contains: function(token) {
2350
+ return unsafeUnwrap(this).contains(token);
2351
+ },
2352
+ add: function() {
2353
+ unsafeUnwrap(this).add.apply(unsafeUnwrap(this), arguments);
2354
+ invalidateClass(this.ownerElement_);
2355
+ },
2356
+ remove: function() {
2357
+ unsafeUnwrap(this).remove.apply(unsafeUnwrap(this), arguments);
2358
+ invalidateClass(this.ownerElement_);
2359
+ },
2360
+ toggle: function(token) {
2361
+ var rv = unsafeUnwrap(this).toggle.apply(unsafeUnwrap(this), arguments);
2362
+ invalidateClass(this.ownerElement_);
2363
+ return rv;
2364
+ },
2365
+ toString: function() {
2366
+ return unsafeUnwrap(this).toString();
2367
+ }
2368
+ };
2369
+ scope.wrappers.DOMTokenList = DOMTokenList;
2370
+ })(window.ShadowDOMPolyfill);
2371
+ (function(scope) {
2372
+ "use strict";
2373
+ var ChildNodeInterface = scope.ChildNodeInterface;
2374
+ var GetElementsByInterface = scope.GetElementsByInterface;
2375
+ var Node = scope.wrappers.Node;
2376
+ var DOMTokenList = scope.wrappers.DOMTokenList;
2377
+ var ParentNodeInterface = scope.ParentNodeInterface;
2378
+ var SelectorsInterface = scope.SelectorsInterface;
2379
+ var addWrapNodeListMethod = scope.addWrapNodeListMethod;
2380
+ var enqueueMutation = scope.enqueueMutation;
2381
+ var mixin = scope.mixin;
2382
+ var oneOf = scope.oneOf;
2383
+ var registerWrapper = scope.registerWrapper;
2384
+ var unsafeUnwrap = scope.unsafeUnwrap;
2385
+ var wrappers = scope.wrappers;
2386
+ var OriginalElement = window.Element;
2387
+ var matchesNames = [ "matches", "mozMatchesSelector", "msMatchesSelector", "webkitMatchesSelector" ].filter(function(name) {
2388
+ return OriginalElement.prototype[name];
2389
+ });
2390
+ var matchesName = matchesNames[0];
2391
+ var originalMatches = OriginalElement.prototype[matchesName];
2392
+ function invalidateRendererBasedOnAttribute(element, name) {
2393
+ var p = element.parentNode;
2394
+ if (!p || !p.shadowRoot) return;
2395
+ var renderer = scope.getRendererForHost(p);
2396
+ if (renderer.dependsOnAttribute(name)) renderer.invalidate();
2397
+ }
2398
+ function enqueAttributeChange(element, name, oldValue) {
2399
+ enqueueMutation(element, "attributes", {
2400
+ name: name,
2401
+ namespace: null,
2402
+ oldValue: oldValue
2403
+ });
2404
+ }
2405
+ var classListTable = new WeakMap();
2406
+ function Element(node) {
2407
+ Node.call(this, node);
2408
+ }
2409
+ Element.prototype = Object.create(Node.prototype);
2410
+ mixin(Element.prototype, {
2411
+ createShadowRoot: function() {
2412
+ var newShadowRoot = new wrappers.ShadowRoot(this);
2413
+ unsafeUnwrap(this).polymerShadowRoot_ = newShadowRoot;
2414
+ var renderer = scope.getRendererForHost(this);
2415
+ renderer.invalidate();
2416
+ return newShadowRoot;
2417
+ },
2418
+ get shadowRoot() {
2419
+ return unsafeUnwrap(this).polymerShadowRoot_ || null;
2420
+ },
2421
+ setAttribute: function(name, value) {
2422
+ var oldValue = unsafeUnwrap(this).getAttribute(name);
2423
+ unsafeUnwrap(this).setAttribute(name, value);
2424
+ enqueAttributeChange(this, name, oldValue);
2425
+ invalidateRendererBasedOnAttribute(this, name);
2426
+ },
2427
+ removeAttribute: function(name) {
2428
+ var oldValue = unsafeUnwrap(this).getAttribute(name);
2429
+ unsafeUnwrap(this).removeAttribute(name);
2430
+ enqueAttributeChange(this, name, oldValue);
2431
+ invalidateRendererBasedOnAttribute(this, name);
2432
+ },
2433
+ matches: function(selector) {
2434
+ return originalMatches.call(unsafeUnwrap(this), selector);
2435
+ },
2436
+ get classList() {
2437
+ var list = classListTable.get(this);
2438
+ if (!list) {
2439
+ classListTable.set(this, list = new DOMTokenList(unsafeUnwrap(this).classList, this));
2440
+ }
2441
+ return list;
2442
+ },
2443
+ get className() {
2444
+ return unsafeUnwrap(this).className;
2445
+ },
2446
+ set className(v) {
2447
+ this.setAttribute("class", v);
2448
+ },
2449
+ get id() {
2450
+ return unsafeUnwrap(this).id;
2451
+ },
2452
+ set id(v) {
2453
+ this.setAttribute("id", v);
2454
+ }
2455
+ });
2456
+ matchesNames.forEach(function(name) {
2457
+ if (name !== "matches") {
2458
+ Element.prototype[name] = function(selector) {
2459
+ return this.matches(selector);
2460
+ };
2461
+ }
2462
+ });
2463
+ if (OriginalElement.prototype.webkitCreateShadowRoot) {
2464
+ Element.prototype.webkitCreateShadowRoot = Element.prototype.createShadowRoot;
2465
+ }
2466
+ mixin(Element.prototype, ChildNodeInterface);
2467
+ mixin(Element.prototype, GetElementsByInterface);
2468
+ mixin(Element.prototype, ParentNodeInterface);
2469
+ mixin(Element.prototype, SelectorsInterface);
2470
+ registerWrapper(OriginalElement, Element, document.createElementNS(null, "x"));
2471
+ scope.invalidateRendererBasedOnAttribute = invalidateRendererBasedOnAttribute;
2472
+ scope.matchesNames = matchesNames;
2473
+ scope.wrappers.Element = Element;
2474
+ })(window.ShadowDOMPolyfill);
2475
+ (function(scope) {
2476
+ "use strict";
2477
+ var Element = scope.wrappers.Element;
2478
+ var defineGetter = scope.defineGetter;
2479
+ var enqueueMutation = scope.enqueueMutation;
2480
+ var mixin = scope.mixin;
2481
+ var nodesWereAdded = scope.nodesWereAdded;
2482
+ var nodesWereRemoved = scope.nodesWereRemoved;
2483
+ var registerWrapper = scope.registerWrapper;
2484
+ var snapshotNodeList = scope.snapshotNodeList;
2485
+ var unsafeUnwrap = scope.unsafeUnwrap;
2486
+ var unwrap = scope.unwrap;
2487
+ var wrap = scope.wrap;
2488
+ var wrappers = scope.wrappers;
2489
+ var escapeAttrRegExp = /[&\u00A0"]/g;
2490
+ var escapeDataRegExp = /[&\u00A0<>]/g;
2491
+ function escapeReplace(c) {
2492
+ switch (c) {
2493
+ case "&":
2494
+ return "&";
2495
+
2496
+ case "<":
2497
+ return "<";
2498
+
2499
+ case ">":
2500
+ return ">";
2501
+
2502
+ case '"':
2503
+ return """;
2504
+
2505
+ case " ":
2506
+ return " ";
2507
+ }
2508
+ }
2509
+ function escapeAttr(s) {
2510
+ return s.replace(escapeAttrRegExp, escapeReplace);
2511
+ }
2512
+ function escapeData(s) {
2513
+ return s.replace(escapeDataRegExp, escapeReplace);
2514
+ }
2515
+ function makeSet(arr) {
2516
+ var set = {};
2517
+ for (var i = 0; i < arr.length; i++) {
2518
+ set[arr[i]] = true;
2519
+ }
2520
+ return set;
2521
+ }
2522
+ var voidElements = makeSet([ "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr" ]);
2523
+ var plaintextParents = makeSet([ "style", "script", "xmp", "iframe", "noembed", "noframes", "plaintext", "noscript" ]);
2524
+ function getOuterHTML(node, parentNode) {
2525
+ switch (node.nodeType) {
2526
+ case Node.ELEMENT_NODE:
2527
+ var tagName = node.tagName.toLowerCase();
2528
+ var s = "<" + tagName;
2529
+ var attrs = node.attributes;
2530
+ for (var i = 0, attr; attr = attrs[i]; i++) {
2531
+ s += " " + attr.name + '="' + escapeAttr(attr.value) + '"';
2532
+ }
2533
+ s += ">";
2534
+ if (voidElements[tagName]) return s;
2535
+ return s + getInnerHTML(node) + "</" + tagName + ">";
2536
+
2537
+ case Node.TEXT_NODE:
2538
+ var data = node.data;
2539
+ if (parentNode && plaintextParents[parentNode.localName]) return data;
2540
+ return escapeData(data);
2541
+
2542
+ case Node.COMMENT_NODE:
2543
+ return "<!--" + node.data + "-->";
2544
+
2545
+ default:
2546
+ console.error(node);
2547
+ throw new Error("not implemented");
2548
+ }
2549
+ }
2550
+ function getInnerHTML(node) {
2551
+ if (node instanceof wrappers.HTMLTemplateElement) node = node.content;
2552
+ var s = "";
2553
+ for (var child = node.firstChild; child; child = child.nextSibling) {
2554
+ s += getOuterHTML(child, node);
2555
+ }
2556
+ return s;
2557
+ }
2558
+ function setInnerHTML(node, value, opt_tagName) {
2559
+ var tagName = opt_tagName || "div";
2560
+ node.textContent = "";
2561
+ var tempElement = unwrap(node.ownerDocument.createElement(tagName));
2562
+ tempElement.innerHTML = value;
2563
+ var firstChild;
2564
+ while (firstChild = tempElement.firstChild) {
2565
+ node.appendChild(wrap(firstChild));
2566
+ }
2567
+ }
2568
+ var oldIe = /MSIE/.test(navigator.userAgent);
2569
+ var OriginalHTMLElement = window.HTMLElement;
2570
+ var OriginalHTMLTemplateElement = window.HTMLTemplateElement;
2571
+ function HTMLElement(node) {
2572
+ Element.call(this, node);
2573
+ }
2574
+ HTMLElement.prototype = Object.create(Element.prototype);
2575
+ mixin(HTMLElement.prototype, {
2576
+ get innerHTML() {
2577
+ return getInnerHTML(this);
2578
+ },
2579
+ set innerHTML(value) {
2580
+ if (oldIe && plaintextParents[this.localName]) {
2581
+ this.textContent = value;
2582
+ return;
2583
+ }
2584
+ var removedNodes = snapshotNodeList(this.childNodes);
2585
+ if (this.invalidateShadowRenderer()) {
2586
+ if (this instanceof wrappers.HTMLTemplateElement) setInnerHTML(this.content, value); else setInnerHTML(this, value, this.tagName);
2587
+ } else if (!OriginalHTMLTemplateElement && this instanceof wrappers.HTMLTemplateElement) {
2588
+ setInnerHTML(this.content, value);
2589
+ } else {
2590
+ unsafeUnwrap(this).innerHTML = value;
2591
+ }
2592
+ var addedNodes = snapshotNodeList(this.childNodes);
2593
+ enqueueMutation(this, "childList", {
2594
+ addedNodes: addedNodes,
2595
+ removedNodes: removedNodes
2596
+ });
2597
+ nodesWereRemoved(removedNodes);
2598
+ nodesWereAdded(addedNodes, this);
2599
+ },
2600
+ get outerHTML() {
2601
+ return getOuterHTML(this, this.parentNode);
2602
+ },
2603
+ set outerHTML(value) {
2604
+ var p = this.parentNode;
2605
+ if (p) {
2606
+ p.invalidateShadowRenderer();
2607
+ var df = frag(p, value);
2608
+ p.replaceChild(df, this);
2609
+ }
2610
+ },
2611
+ insertAdjacentHTML: function(position, text) {
2612
+ var contextElement, refNode;
2613
+ switch (String(position).toLowerCase()) {
2614
+ case "beforebegin":
2615
+ contextElement = this.parentNode;
2616
+ refNode = this;
2617
+ break;
2618
+
2619
+ case "afterend":
2620
+ contextElement = this.parentNode;
2621
+ refNode = this.nextSibling;
2622
+ break;
2623
+
2624
+ case "afterbegin":
2625
+ contextElement = this;
2626
+ refNode = this.firstChild;
2627
+ break;
2628
+
2629
+ case "beforeend":
2630
+ contextElement = this;
2631
+ refNode = null;
2632
+ break;
2633
+
2634
+ default:
2635
+ return;
2636
+ }
2637
+ var df = frag(contextElement, text);
2638
+ contextElement.insertBefore(df, refNode);
2639
+ },
2640
+ get hidden() {
2641
+ return this.hasAttribute("hidden");
2642
+ },
2643
+ set hidden(v) {
2644
+ if (v) {
2645
+ this.setAttribute("hidden", "");
2646
+ } else {
2647
+ this.removeAttribute("hidden");
2648
+ }
2649
+ }
2650
+ });
2651
+ function frag(contextElement, html) {
2652
+ var p = unwrap(contextElement.cloneNode(false));
2653
+ p.innerHTML = html;
2654
+ var df = unwrap(document.createDocumentFragment());
2655
+ var c;
2656
+ while (c = p.firstChild) {
2657
+ df.appendChild(c);
2658
+ }
2659
+ return wrap(df);
2660
+ }
2661
+ function getter(name) {
2662
+ return function() {
2663
+ scope.renderAllPending();
2664
+ return unsafeUnwrap(this)[name];
2665
+ };
2666
+ }
2667
+ function getterRequiresRendering(name) {
2668
+ defineGetter(HTMLElement, name, getter(name));
2669
+ }
2670
+ [ "clientHeight", "clientLeft", "clientTop", "clientWidth", "offsetHeight", "offsetLeft", "offsetTop", "offsetWidth", "scrollHeight", "scrollWidth" ].forEach(getterRequiresRendering);
2671
+ function getterAndSetterRequiresRendering(name) {
2672
+ Object.defineProperty(HTMLElement.prototype, name, {
2673
+ get: getter(name),
2674
+ set: function(v) {
2675
+ scope.renderAllPending();
2676
+ unsafeUnwrap(this)[name] = v;
2677
+ },
2678
+ configurable: true,
2679
+ enumerable: true
2680
+ });
2681
+ }
2682
+ [ "scrollLeft", "scrollTop" ].forEach(getterAndSetterRequiresRendering);
2683
+ function methodRequiresRendering(name) {
2684
+ Object.defineProperty(HTMLElement.prototype, name, {
2685
+ value: function() {
2686
+ scope.renderAllPending();
2687
+ return unsafeUnwrap(this)[name].apply(unsafeUnwrap(this), arguments);
2688
+ },
2689
+ configurable: true,
2690
+ enumerable: true
2691
+ });
2692
+ }
2693
+ [ "getBoundingClientRect", "getClientRects", "scrollIntoView" ].forEach(methodRequiresRendering);
2694
+ registerWrapper(OriginalHTMLElement, HTMLElement, document.createElement("b"));
2695
+ scope.wrappers.HTMLElement = HTMLElement;
2696
+ scope.getInnerHTML = getInnerHTML;
2697
+ scope.setInnerHTML = setInnerHTML;
2698
+ })(window.ShadowDOMPolyfill);
2699
+ (function(scope) {
2700
+ "use strict";
2701
+ var HTMLElement = scope.wrappers.HTMLElement;
2702
+ var mixin = scope.mixin;
2703
+ var registerWrapper = scope.registerWrapper;
2704
+ var unsafeUnwrap = scope.unsafeUnwrap;
2705
+ var wrap = scope.wrap;
2706
+ var OriginalHTMLCanvasElement = window.HTMLCanvasElement;
2707
+ function HTMLCanvasElement(node) {
2708
+ HTMLElement.call(this, node);
2709
+ }
2710
+ HTMLCanvasElement.prototype = Object.create(HTMLElement.prototype);
2711
+ mixin(HTMLCanvasElement.prototype, {
2712
+ getContext: function() {
2713
+ var context = unsafeUnwrap(this).getContext.apply(unsafeUnwrap(this), arguments);
2714
+ return context && wrap(context);
2715
+ }
2716
+ });
2717
+ registerWrapper(OriginalHTMLCanvasElement, HTMLCanvasElement, document.createElement("canvas"));
2718
+ scope.wrappers.HTMLCanvasElement = HTMLCanvasElement;
2719
+ })(window.ShadowDOMPolyfill);
2720
+ (function(scope) {
2721
+ "use strict";
2722
+ var HTMLElement = scope.wrappers.HTMLElement;
2723
+ var mixin = scope.mixin;
2724
+ var registerWrapper = scope.registerWrapper;
2725
+ var OriginalHTMLContentElement = window.HTMLContentElement;
2726
+ function HTMLContentElement(node) {
2727
+ HTMLElement.call(this, node);
2728
+ }
2729
+ HTMLContentElement.prototype = Object.create(HTMLElement.prototype);
2730
+ mixin(HTMLContentElement.prototype, {
2731
+ constructor: HTMLContentElement,
2732
+ get select() {
2733
+ return this.getAttribute("select");
2734
+ },
2735
+ set select(value) {
2736
+ this.setAttribute("select", value);
2737
+ },
2738
+ setAttribute: function(n, v) {
2739
+ HTMLElement.prototype.setAttribute.call(this, n, v);
2740
+ if (String(n).toLowerCase() === "select") this.invalidateShadowRenderer(true);
2741
+ }
2742
+ });
2743
+ if (OriginalHTMLContentElement) registerWrapper(OriginalHTMLContentElement, HTMLContentElement);
2744
+ scope.wrappers.HTMLContentElement = HTMLContentElement;
2745
+ })(window.ShadowDOMPolyfill);
2746
+ (function(scope) {
2747
+ "use strict";
2748
+ var HTMLElement = scope.wrappers.HTMLElement;
2749
+ var mixin = scope.mixin;
2750
+ var registerWrapper = scope.registerWrapper;
2751
+ var wrapHTMLCollection = scope.wrapHTMLCollection;
2752
+ var unwrap = scope.unwrap;
2753
+ var OriginalHTMLFormElement = window.HTMLFormElement;
2754
+ function HTMLFormElement(node) {
2755
+ HTMLElement.call(this, node);
2756
+ }
2757
+ HTMLFormElement.prototype = Object.create(HTMLElement.prototype);
2758
+ mixin(HTMLFormElement.prototype, {
2759
+ get elements() {
2760
+ return wrapHTMLCollection(unwrap(this).elements);
2761
+ }
2762
+ });
2763
+ registerWrapper(OriginalHTMLFormElement, HTMLFormElement, document.createElement("form"));
2764
+ scope.wrappers.HTMLFormElement = HTMLFormElement;
2765
+ })(window.ShadowDOMPolyfill);
2766
+ (function(scope) {
2767
+ "use strict";
2768
+ var HTMLElement = scope.wrappers.HTMLElement;
2769
+ var registerWrapper = scope.registerWrapper;
2770
+ var unwrap = scope.unwrap;
2771
+ var rewrap = scope.rewrap;
2772
+ var OriginalHTMLImageElement = window.HTMLImageElement;
2773
+ function HTMLImageElement(node) {
2774
+ HTMLElement.call(this, node);
2775
+ }
2776
+ HTMLImageElement.prototype = Object.create(HTMLElement.prototype);
2777
+ registerWrapper(OriginalHTMLImageElement, HTMLImageElement, document.createElement("img"));
2778
+ function Image(width, height) {
2779
+ if (!(this instanceof Image)) {
2780
+ throw new TypeError("DOM object constructor cannot be called as a function.");
2781
+ }
2782
+ var node = unwrap(document.createElement("img"));
2783
+ HTMLElement.call(this, node);
2784
+ rewrap(node, this);
2785
+ if (width !== undefined) node.width = width;
2786
+ if (height !== undefined) node.height = height;
2787
+ }
2788
+ Image.prototype = HTMLImageElement.prototype;
2789
+ scope.wrappers.HTMLImageElement = HTMLImageElement;
2790
+ scope.wrappers.Image = Image;
2791
+ })(window.ShadowDOMPolyfill);
2792
+ (function(scope) {
2793
+ "use strict";
2794
+ var HTMLElement = scope.wrappers.HTMLElement;
2795
+ var mixin = scope.mixin;
2796
+ var NodeList = scope.wrappers.NodeList;
2797
+ var registerWrapper = scope.registerWrapper;
2798
+ var OriginalHTMLShadowElement = window.HTMLShadowElement;
2799
+ function HTMLShadowElement(node) {
2800
+ HTMLElement.call(this, node);
2801
+ }
2802
+ HTMLShadowElement.prototype = Object.create(HTMLElement.prototype);
2803
+ HTMLShadowElement.prototype.constructor = HTMLShadowElement;
2804
+ if (OriginalHTMLShadowElement) registerWrapper(OriginalHTMLShadowElement, HTMLShadowElement);
2805
+ scope.wrappers.HTMLShadowElement = HTMLShadowElement;
2806
+ })(window.ShadowDOMPolyfill);
2807
+ (function(scope) {
2808
+ "use strict";
2809
+ var HTMLElement = scope.wrappers.HTMLElement;
2810
+ var mixin = scope.mixin;
2811
+ var registerWrapper = scope.registerWrapper;
2812
+ var unsafeUnwrap = scope.unsafeUnwrap;
2813
+ var unwrap = scope.unwrap;
2814
+ var wrap = scope.wrap;
2815
+ var contentTable = new WeakMap();
2816
+ var templateContentsOwnerTable = new WeakMap();
2817
+ function getTemplateContentsOwner(doc) {
2818
+ if (!doc.defaultView) return doc;
2819
+ var d = templateContentsOwnerTable.get(doc);
2820
+ if (!d) {
2821
+ d = doc.implementation.createHTMLDocument("");
2822
+ while (d.lastChild) {
2823
+ d.removeChild(d.lastChild);
2824
+ }
2825
+ templateContentsOwnerTable.set(doc, d);
2826
+ }
2827
+ return d;
2828
+ }
2829
+ function extractContent(templateElement) {
2830
+ var doc = getTemplateContentsOwner(templateElement.ownerDocument);
2831
+ var df = unwrap(doc.createDocumentFragment());
2832
+ var child;
2833
+ while (child = templateElement.firstChild) {
2834
+ df.appendChild(child);
2835
+ }
2836
+ return df;
2837
+ }
2838
+ var OriginalHTMLTemplateElement = window.HTMLTemplateElement;
2839
+ function HTMLTemplateElement(node) {
2840
+ HTMLElement.call(this, node);
2841
+ if (!OriginalHTMLTemplateElement) {
2842
+ var content = extractContent(node);
2843
+ contentTable.set(this, wrap(content));
2844
+ }
2845
+ }
2846
+ HTMLTemplateElement.prototype = Object.create(HTMLElement.prototype);
2847
+ mixin(HTMLTemplateElement.prototype, {
2848
+ constructor: HTMLTemplateElement,
2849
+ get content() {
2850
+ if (OriginalHTMLTemplateElement) return wrap(unsafeUnwrap(this).content);
2851
+ return contentTable.get(this);
2852
+ }
2853
+ });
2854
+ if (OriginalHTMLTemplateElement) registerWrapper(OriginalHTMLTemplateElement, HTMLTemplateElement);
2855
+ scope.wrappers.HTMLTemplateElement = HTMLTemplateElement;
2856
+ })(window.ShadowDOMPolyfill);
2857
+ (function(scope) {
2858
+ "use strict";
2859
+ var HTMLElement = scope.wrappers.HTMLElement;
2860
+ var registerWrapper = scope.registerWrapper;
2861
+ var OriginalHTMLMediaElement = window.HTMLMediaElement;
2862
+ if (!OriginalHTMLMediaElement) return;
2863
+ function HTMLMediaElement(node) {
2864
+ HTMLElement.call(this, node);
2865
+ }
2866
+ HTMLMediaElement.prototype = Object.create(HTMLElement.prototype);
2867
+ registerWrapper(OriginalHTMLMediaElement, HTMLMediaElement, document.createElement("audio"));
2868
+ scope.wrappers.HTMLMediaElement = HTMLMediaElement;
2869
+ })(window.ShadowDOMPolyfill);
2870
+ (function(scope) {
2871
+ "use strict";
2872
+ var HTMLMediaElement = scope.wrappers.HTMLMediaElement;
2873
+ var registerWrapper = scope.registerWrapper;
2874
+ var unwrap = scope.unwrap;
2875
+ var rewrap = scope.rewrap;
2876
+ var OriginalHTMLAudioElement = window.HTMLAudioElement;
2877
+ if (!OriginalHTMLAudioElement) return;
2878
+ function HTMLAudioElement(node) {
2879
+ HTMLMediaElement.call(this, node);
2880
+ }
2881
+ HTMLAudioElement.prototype = Object.create(HTMLMediaElement.prototype);
2882
+ registerWrapper(OriginalHTMLAudioElement, HTMLAudioElement, document.createElement("audio"));
2883
+ function Audio(src) {
2884
+ if (!(this instanceof Audio)) {
2885
+ throw new TypeError("DOM object constructor cannot be called as a function.");
2886
+ }
2887
+ var node = unwrap(document.createElement("audio"));
2888
+ HTMLMediaElement.call(this, node);
2889
+ rewrap(node, this);
2890
+ node.setAttribute("preload", "auto");
2891
+ if (src !== undefined) node.setAttribute("src", src);
2892
+ }
2893
+ Audio.prototype = HTMLAudioElement.prototype;
2894
+ scope.wrappers.HTMLAudioElement = HTMLAudioElement;
2895
+ scope.wrappers.Audio = Audio;
2896
+ })(window.ShadowDOMPolyfill);
2897
+ (function(scope) {
2898
+ "use strict";
2899
+ var HTMLElement = scope.wrappers.HTMLElement;
2900
+ var mixin = scope.mixin;
2901
+ var registerWrapper = scope.registerWrapper;
2902
+ var rewrap = scope.rewrap;
2903
+ var unwrap = scope.unwrap;
2904
+ var wrap = scope.wrap;
2905
+ var OriginalHTMLOptionElement = window.HTMLOptionElement;
2906
+ function trimText(s) {
2907
+ return s.replace(/\s+/g, " ").trim();
2908
+ }
2909
+ function HTMLOptionElement(node) {
2910
+ HTMLElement.call(this, node);
2911
+ }
2912
+ HTMLOptionElement.prototype = Object.create(HTMLElement.prototype);
2913
+ mixin(HTMLOptionElement.prototype, {
2914
+ get text() {
2915
+ return trimText(this.textContent);
2916
+ },
2917
+ set text(value) {
2918
+ this.textContent = trimText(String(value));
2919
+ },
2920
+ get form() {
2921
+ return wrap(unwrap(this).form);
2922
+ }
2923
+ });
2924
+ registerWrapper(OriginalHTMLOptionElement, HTMLOptionElement, document.createElement("option"));
2925
+ function Option(text, value, defaultSelected, selected) {
2926
+ if (!(this instanceof Option)) {
2927
+ throw new TypeError("DOM object constructor cannot be called as a function.");
2928
+ }
2929
+ var node = unwrap(document.createElement("option"));
2930
+ HTMLElement.call(this, node);
2931
+ rewrap(node, this);
2932
+ if (text !== undefined) node.text = text;
2933
+ if (value !== undefined) node.setAttribute("value", value);
2934
+ if (defaultSelected === true) node.setAttribute("selected", "");
2935
+ node.selected = selected === true;
2936
+ }
2937
+ Option.prototype = HTMLOptionElement.prototype;
2938
+ scope.wrappers.HTMLOptionElement = HTMLOptionElement;
2939
+ scope.wrappers.Option = Option;
2940
+ })(window.ShadowDOMPolyfill);
2941
+ (function(scope) {
2942
+ "use strict";
2943
+ var HTMLElement = scope.wrappers.HTMLElement;
2944
+ var mixin = scope.mixin;
2945
+ var registerWrapper = scope.registerWrapper;
2946
+ var unwrap = scope.unwrap;
2947
+ var wrap = scope.wrap;
2948
+ var OriginalHTMLSelectElement = window.HTMLSelectElement;
2949
+ function HTMLSelectElement(node) {
2950
+ HTMLElement.call(this, node);
2951
+ }
2952
+ HTMLSelectElement.prototype = Object.create(HTMLElement.prototype);
2953
+ mixin(HTMLSelectElement.prototype, {
2954
+ add: function(element, before) {
2955
+ if (typeof before === "object") before = unwrap(before);
2956
+ unwrap(this).add(unwrap(element), before);
2957
+ },
2958
+ remove: function(indexOrNode) {
2959
+ if (indexOrNode === undefined) {
2960
+ HTMLElement.prototype.remove.call(this);
2961
+ return;
2962
+ }
2963
+ if (typeof indexOrNode === "object") indexOrNode = unwrap(indexOrNode);
2964
+ unwrap(this).remove(indexOrNode);
2965
+ },
2966
+ get form() {
2967
+ return wrap(unwrap(this).form);
2968
+ }
2969
+ });
2970
+ registerWrapper(OriginalHTMLSelectElement, HTMLSelectElement, document.createElement("select"));
2971
+ scope.wrappers.HTMLSelectElement = HTMLSelectElement;
2972
+ })(window.ShadowDOMPolyfill);
2973
+ (function(scope) {
2974
+ "use strict";
2975
+ var HTMLElement = scope.wrappers.HTMLElement;
2976
+ var mixin = scope.mixin;
2977
+ var registerWrapper = scope.registerWrapper;
2978
+ var unwrap = scope.unwrap;
2979
+ var wrap = scope.wrap;
2980
+ var wrapHTMLCollection = scope.wrapHTMLCollection;
2981
+ var OriginalHTMLTableElement = window.HTMLTableElement;
2982
+ function HTMLTableElement(node) {
2983
+ HTMLElement.call(this, node);
2984
+ }
2985
+ HTMLTableElement.prototype = Object.create(HTMLElement.prototype);
2986
+ mixin(HTMLTableElement.prototype, {
2987
+ get caption() {
2988
+ return wrap(unwrap(this).caption);
2989
+ },
2990
+ createCaption: function() {
2991
+ return wrap(unwrap(this).createCaption());
2992
+ },
2993
+ get tHead() {
2994
+ return wrap(unwrap(this).tHead);
2995
+ },
2996
+ createTHead: function() {
2997
+ return wrap(unwrap(this).createTHead());
2998
+ },
2999
+ createTFoot: function() {
3000
+ return wrap(unwrap(this).createTFoot());
3001
+ },
3002
+ get tFoot() {
3003
+ return wrap(unwrap(this).tFoot);
3004
+ },
3005
+ get tBodies() {
3006
+ return wrapHTMLCollection(unwrap(this).tBodies);
3007
+ },
3008
+ createTBody: function() {
3009
+ return wrap(unwrap(this).createTBody());
3010
+ },
3011
+ get rows() {
3012
+ return wrapHTMLCollection(unwrap(this).rows);
3013
+ },
3014
+ insertRow: function(index) {
3015
+ return wrap(unwrap(this).insertRow(index));
3016
+ }
3017
+ });
3018
+ registerWrapper(OriginalHTMLTableElement, HTMLTableElement, document.createElement("table"));
3019
+ scope.wrappers.HTMLTableElement = HTMLTableElement;
3020
+ })(window.ShadowDOMPolyfill);
3021
+ (function(scope) {
3022
+ "use strict";
3023
+ var HTMLElement = scope.wrappers.HTMLElement;
3024
+ var mixin = scope.mixin;
3025
+ var registerWrapper = scope.registerWrapper;
3026
+ var wrapHTMLCollection = scope.wrapHTMLCollection;
3027
+ var unwrap = scope.unwrap;
3028
+ var wrap = scope.wrap;
3029
+ var OriginalHTMLTableSectionElement = window.HTMLTableSectionElement;
3030
+ function HTMLTableSectionElement(node) {
3031
+ HTMLElement.call(this, node);
3032
+ }
3033
+ HTMLTableSectionElement.prototype = Object.create(HTMLElement.prototype);
3034
+ mixin(HTMLTableSectionElement.prototype, {
3035
+ constructor: HTMLTableSectionElement,
3036
+ get rows() {
3037
+ return wrapHTMLCollection(unwrap(this).rows);
3038
+ },
3039
+ insertRow: function(index) {
3040
+ return wrap(unwrap(this).insertRow(index));
3041
+ }
3042
+ });
3043
+ registerWrapper(OriginalHTMLTableSectionElement, HTMLTableSectionElement, document.createElement("thead"));
3044
+ scope.wrappers.HTMLTableSectionElement = HTMLTableSectionElement;
3045
+ })(window.ShadowDOMPolyfill);
3046
+ (function(scope) {
3047
+ "use strict";
3048
+ var HTMLElement = scope.wrappers.HTMLElement;
3049
+ var mixin = scope.mixin;
3050
+ var registerWrapper = scope.registerWrapper;
3051
+ var wrapHTMLCollection = scope.wrapHTMLCollection;
3052
+ var unwrap = scope.unwrap;
3053
+ var wrap = scope.wrap;
3054
+ var OriginalHTMLTableRowElement = window.HTMLTableRowElement;
3055
+ function HTMLTableRowElement(node) {
3056
+ HTMLElement.call(this, node);
3057
+ }
3058
+ HTMLTableRowElement.prototype = Object.create(HTMLElement.prototype);
3059
+ mixin(HTMLTableRowElement.prototype, {
3060
+ get cells() {
3061
+ return wrapHTMLCollection(unwrap(this).cells);
3062
+ },
3063
+ insertCell: function(index) {
3064
+ return wrap(unwrap(this).insertCell(index));
3065
+ }
3066
+ });
3067
+ registerWrapper(OriginalHTMLTableRowElement, HTMLTableRowElement, document.createElement("tr"));
3068
+ scope.wrappers.HTMLTableRowElement = HTMLTableRowElement;
3069
+ })(window.ShadowDOMPolyfill);
3070
+ (function(scope) {
3071
+ "use strict";
3072
+ var HTMLContentElement = scope.wrappers.HTMLContentElement;
3073
+ var HTMLElement = scope.wrappers.HTMLElement;
3074
+ var HTMLShadowElement = scope.wrappers.HTMLShadowElement;
3075
+ var HTMLTemplateElement = scope.wrappers.HTMLTemplateElement;
3076
+ var mixin = scope.mixin;
3077
+ var registerWrapper = scope.registerWrapper;
3078
+ var OriginalHTMLUnknownElement = window.HTMLUnknownElement;
3079
+ function HTMLUnknownElement(node) {
3080
+ switch (node.localName) {
3081
+ case "content":
3082
+ return new HTMLContentElement(node);
3083
+
3084
+ case "shadow":
3085
+ return new HTMLShadowElement(node);
3086
+
3087
+ case "template":
3088
+ return new HTMLTemplateElement(node);
3089
+ }
3090
+ HTMLElement.call(this, node);
3091
+ }
3092
+ HTMLUnknownElement.prototype = Object.create(HTMLElement.prototype);
3093
+ registerWrapper(OriginalHTMLUnknownElement, HTMLUnknownElement);
3094
+ scope.wrappers.HTMLUnknownElement = HTMLUnknownElement;
3095
+ })(window.ShadowDOMPolyfill);
3096
+ (function(scope) {
3097
+ "use strict";
3098
+ var Element = scope.wrappers.Element;
3099
+ var HTMLElement = scope.wrappers.HTMLElement;
3100
+ var registerObject = scope.registerObject;
3101
+ var SVG_NS = "http://www.w3.org/2000/svg";
3102
+ var svgTitleElement = document.createElementNS(SVG_NS, "title");
3103
+ var SVGTitleElement = registerObject(svgTitleElement);
3104
+ var SVGElement = Object.getPrototypeOf(SVGTitleElement.prototype).constructor;
3105
+ if (!("classList" in svgTitleElement)) {
3106
+ var descr = Object.getOwnPropertyDescriptor(Element.prototype, "classList");
3107
+ Object.defineProperty(HTMLElement.prototype, "classList", descr);
3108
+ delete Element.prototype.classList;
3109
+ }
3110
+ scope.wrappers.SVGElement = SVGElement;
3111
+ })(window.ShadowDOMPolyfill);
3112
+ (function(scope) {
3113
+ "use strict";
3114
+ var mixin = scope.mixin;
3115
+ var registerWrapper = scope.registerWrapper;
3116
+ var unwrap = scope.unwrap;
3117
+ var wrap = scope.wrap;
3118
+ var OriginalSVGUseElement = window.SVGUseElement;
3119
+ var SVG_NS = "http://www.w3.org/2000/svg";
3120
+ var gWrapper = wrap(document.createElementNS(SVG_NS, "g"));
3121
+ var useElement = document.createElementNS(SVG_NS, "use");
3122
+ var SVGGElement = gWrapper.constructor;
3123
+ var parentInterfacePrototype = Object.getPrototypeOf(SVGGElement.prototype);
3124
+ var parentInterface = parentInterfacePrototype.constructor;
3125
+ function SVGUseElement(impl) {
3126
+ parentInterface.call(this, impl);
3127
+ }
3128
+ SVGUseElement.prototype = Object.create(parentInterfacePrototype);
3129
+ if ("instanceRoot" in useElement) {
3130
+ mixin(SVGUseElement.prototype, {
3131
+ get instanceRoot() {
3132
+ return wrap(unwrap(this).instanceRoot);
3133
+ },
3134
+ get animatedInstanceRoot() {
3135
+ return wrap(unwrap(this).animatedInstanceRoot);
3136
+ }
3137
+ });
3138
+ }
3139
+ registerWrapper(OriginalSVGUseElement, SVGUseElement, useElement);
3140
+ scope.wrappers.SVGUseElement = SVGUseElement;
3141
+ })(window.ShadowDOMPolyfill);
3142
+ (function(scope) {
3143
+ "use strict";
3144
+ var EventTarget = scope.wrappers.EventTarget;
3145
+ var mixin = scope.mixin;
3146
+ var registerWrapper = scope.registerWrapper;
3147
+ var unsafeUnwrap = scope.unsafeUnwrap;
3148
+ var wrap = scope.wrap;
3149
+ var OriginalSVGElementInstance = window.SVGElementInstance;
3150
+ if (!OriginalSVGElementInstance) return;
3151
+ function SVGElementInstance(impl) {
3152
+ EventTarget.call(this, impl);
3153
+ }
3154
+ SVGElementInstance.prototype = Object.create(EventTarget.prototype);
3155
+ mixin(SVGElementInstance.prototype, {
3156
+ get correspondingElement() {
3157
+ return wrap(unsafeUnwrap(this).correspondingElement);
3158
+ },
3159
+ get correspondingUseElement() {
3160
+ return wrap(unsafeUnwrap(this).correspondingUseElement);
3161
+ },
3162
+ get parentNode() {
3163
+ return wrap(unsafeUnwrap(this).parentNode);
3164
+ },
3165
+ get childNodes() {
3166
+ throw new Error("Not implemented");
3167
+ },
3168
+ get firstChild() {
3169
+ return wrap(unsafeUnwrap(this).firstChild);
3170
+ },
3171
+ get lastChild() {
3172
+ return wrap(unsafeUnwrap(this).lastChild);
3173
+ },
3174
+ get previousSibling() {
3175
+ return wrap(unsafeUnwrap(this).previousSibling);
3176
+ },
3177
+ get nextSibling() {
3178
+ return wrap(unsafeUnwrap(this).nextSibling);
3179
+ }
3180
+ });
3181
+ registerWrapper(OriginalSVGElementInstance, SVGElementInstance);
3182
+ scope.wrappers.SVGElementInstance = SVGElementInstance;
3183
+ })(window.ShadowDOMPolyfill);
3184
+ (function(scope) {
3185
+ "use strict";
3186
+ var mixin = scope.mixin;
3187
+ var registerWrapper = scope.registerWrapper;
3188
+ var setWrapper = scope.setWrapper;
3189
+ var unsafeUnwrap = scope.unsafeUnwrap;
3190
+ var unwrap = scope.unwrap;
3191
+ var unwrapIfNeeded = scope.unwrapIfNeeded;
3192
+ var wrap = scope.wrap;
3193
+ var OriginalCanvasRenderingContext2D = window.CanvasRenderingContext2D;
3194
+ function CanvasRenderingContext2D(impl) {
3195
+ setWrapper(impl, this);
3196
+ }
3197
+ mixin(CanvasRenderingContext2D.prototype, {
3198
+ get canvas() {
3199
+ return wrap(unsafeUnwrap(this).canvas);
3200
+ },
3201
+ drawImage: function() {
3202
+ arguments[0] = unwrapIfNeeded(arguments[0]);
3203
+ unsafeUnwrap(this).drawImage.apply(unsafeUnwrap(this), arguments);
3204
+ },
3205
+ createPattern: function() {
3206
+ arguments[0] = unwrap(arguments[0]);
3207
+ return unsafeUnwrap(this).createPattern.apply(unsafeUnwrap(this), arguments);
3208
+ }
3209
+ });
3210
+ registerWrapper(OriginalCanvasRenderingContext2D, CanvasRenderingContext2D, document.createElement("canvas").getContext("2d"));
3211
+ scope.wrappers.CanvasRenderingContext2D = CanvasRenderingContext2D;
3212
+ })(window.ShadowDOMPolyfill);
3213
+ (function(scope) {
3214
+ "use strict";
3215
+ var mixin = scope.mixin;
3216
+ var registerWrapper = scope.registerWrapper;
3217
+ var setWrapper = scope.setWrapper;
3218
+ var unsafeUnwrap = scope.unsafeUnwrap;
3219
+ var unwrapIfNeeded = scope.unwrapIfNeeded;
3220
+ var wrap = scope.wrap;
3221
+ var OriginalWebGLRenderingContext = window.WebGLRenderingContext;
3222
+ if (!OriginalWebGLRenderingContext) return;
3223
+ function WebGLRenderingContext(impl) {
3224
+ setWrapper(impl, this);
3225
+ }
3226
+ mixin(WebGLRenderingContext.prototype, {
3227
+ get canvas() {
3228
+ return wrap(unsafeUnwrap(this).canvas);
3229
+ },
3230
+ texImage2D: function() {
3231
+ arguments[5] = unwrapIfNeeded(arguments[5]);
3232
+ unsafeUnwrap(this).texImage2D.apply(unsafeUnwrap(this), arguments);
3233
+ },
3234
+ texSubImage2D: function() {
3235
+ arguments[6] = unwrapIfNeeded(arguments[6]);
3236
+ unsafeUnwrap(this).texSubImage2D.apply(unsafeUnwrap(this), arguments);
3237
+ }
3238
+ });
3239
+ var instanceProperties = /WebKit/.test(navigator.userAgent) ? {
3240
+ drawingBufferHeight: null,
3241
+ drawingBufferWidth: null
3242
+ } : {};
3243
+ registerWrapper(OriginalWebGLRenderingContext, WebGLRenderingContext, instanceProperties);
3244
+ scope.wrappers.WebGLRenderingContext = WebGLRenderingContext;
3245
+ })(window.ShadowDOMPolyfill);
3246
+ (function(scope) {
3247
+ "use strict";
3248
+ var registerWrapper = scope.registerWrapper;
3249
+ var setWrapper = scope.setWrapper;
3250
+ var unsafeUnwrap = scope.unsafeUnwrap;
3251
+ var unwrap = scope.unwrap;
3252
+ var unwrapIfNeeded = scope.unwrapIfNeeded;
3253
+ var wrap = scope.wrap;
3254
+ var OriginalRange = window.Range;
3255
+ function Range(impl) {
3256
+ setWrapper(impl, this);
3257
+ }
3258
+ Range.prototype = {
3259
+ get startContainer() {
3260
+ return wrap(unsafeUnwrap(this).startContainer);
3261
+ },
3262
+ get endContainer() {
3263
+ return wrap(unsafeUnwrap(this).endContainer);
3264
+ },
3265
+ get commonAncestorContainer() {
3266
+ return wrap(unsafeUnwrap(this).commonAncestorContainer);
3267
+ },
3268
+ setStart: function(refNode, offset) {
3269
+ unsafeUnwrap(this).setStart(unwrapIfNeeded(refNode), offset);
3270
+ },
3271
+ setEnd: function(refNode, offset) {
3272
+ unsafeUnwrap(this).setEnd(unwrapIfNeeded(refNode), offset);
3273
+ },
3274
+ setStartBefore: function(refNode) {
3275
+ unsafeUnwrap(this).setStartBefore(unwrapIfNeeded(refNode));
3276
+ },
3277
+ setStartAfter: function(refNode) {
3278
+ unsafeUnwrap(this).setStartAfter(unwrapIfNeeded(refNode));
3279
+ },
3280
+ setEndBefore: function(refNode) {
3281
+ unsafeUnwrap(this).setEndBefore(unwrapIfNeeded(refNode));
3282
+ },
3283
+ setEndAfter: function(refNode) {
3284
+ unsafeUnwrap(this).setEndAfter(unwrapIfNeeded(refNode));
3285
+ },
3286
+ selectNode: function(refNode) {
3287
+ unsafeUnwrap(this).selectNode(unwrapIfNeeded(refNode));
3288
+ },
3289
+ selectNodeContents: function(refNode) {
3290
+ unsafeUnwrap(this).selectNodeContents(unwrapIfNeeded(refNode));
3291
+ },
3292
+ compareBoundaryPoints: function(how, sourceRange) {
3293
+ return unsafeUnwrap(this).compareBoundaryPoints(how, unwrap(sourceRange));
3294
+ },
3295
+ extractContents: function() {
3296
+ return wrap(unsafeUnwrap(this).extractContents());
3297
+ },
3298
+ cloneContents: function() {
3299
+ return wrap(unsafeUnwrap(this).cloneContents());
3300
+ },
3301
+ insertNode: function(node) {
3302
+ unsafeUnwrap(this).insertNode(unwrapIfNeeded(node));
3303
+ },
3304
+ surroundContents: function(newParent) {
3305
+ unsafeUnwrap(this).surroundContents(unwrapIfNeeded(newParent));
3306
+ },
3307
+ cloneRange: function() {
3308
+ return wrap(unsafeUnwrap(this).cloneRange());
3309
+ },
3310
+ isPointInRange: function(node, offset) {
3311
+ return unsafeUnwrap(this).isPointInRange(unwrapIfNeeded(node), offset);
3312
+ },
3313
+ comparePoint: function(node, offset) {
3314
+ return unsafeUnwrap(this).comparePoint(unwrapIfNeeded(node), offset);
3315
+ },
3316
+ intersectsNode: function(node) {
3317
+ return unsafeUnwrap(this).intersectsNode(unwrapIfNeeded(node));
3318
+ },
3319
+ toString: function() {
3320
+ return unsafeUnwrap(this).toString();
3321
+ }
3322
+ };
3323
+ if (OriginalRange.prototype.createContextualFragment) {
3324
+ Range.prototype.createContextualFragment = function(html) {
3325
+ return wrap(unsafeUnwrap(this).createContextualFragment(html));
3326
+ };
3327
+ }
3328
+ registerWrapper(window.Range, Range, document.createRange());
3329
+ scope.wrappers.Range = Range;
3330
+ })(window.ShadowDOMPolyfill);
3331
+ (function(scope) {
3332
+ "use strict";
3333
+ var GetElementsByInterface = scope.GetElementsByInterface;
3334
+ var ParentNodeInterface = scope.ParentNodeInterface;
3335
+ var SelectorsInterface = scope.SelectorsInterface;
3336
+ var mixin = scope.mixin;
3337
+ var registerObject = scope.registerObject;
3338
+ var DocumentFragment = registerObject(document.createDocumentFragment());
3339
+ mixin(DocumentFragment.prototype, ParentNodeInterface);
3340
+ mixin(DocumentFragment.prototype, SelectorsInterface);
3341
+ mixin(DocumentFragment.prototype, GetElementsByInterface);
3342
+ var Comment = registerObject(document.createComment(""));
3343
+ scope.wrappers.Comment = Comment;
3344
+ scope.wrappers.DocumentFragment = DocumentFragment;
3345
+ })(window.ShadowDOMPolyfill);
3346
+ (function(scope) {
3347
+ "use strict";
3348
+ var DocumentFragment = scope.wrappers.DocumentFragment;
3349
+ var TreeScope = scope.TreeScope;
3350
+ var elementFromPoint = scope.elementFromPoint;
3351
+ var getInnerHTML = scope.getInnerHTML;
3352
+ var getTreeScope = scope.getTreeScope;
3353
+ var mixin = scope.mixin;
3354
+ var rewrap = scope.rewrap;
3355
+ var setInnerHTML = scope.setInnerHTML;
3356
+ var unsafeUnwrap = scope.unsafeUnwrap;
3357
+ var unwrap = scope.unwrap;
3358
+ var shadowHostTable = new WeakMap();
3359
+ var nextOlderShadowTreeTable = new WeakMap();
3360
+ var spaceCharRe = /[ \t\n\r\f]/;
3361
+ function ShadowRoot(hostWrapper) {
3362
+ var node = unwrap(unsafeUnwrap(hostWrapper).ownerDocument.createDocumentFragment());
3363
+ DocumentFragment.call(this, node);
3364
+ rewrap(node, this);
3365
+ var oldShadowRoot = hostWrapper.shadowRoot;
3366
+ nextOlderShadowTreeTable.set(this, oldShadowRoot);
3367
+ this.treeScope_ = new TreeScope(this, getTreeScope(oldShadowRoot || hostWrapper));
3368
+ shadowHostTable.set(this, hostWrapper);
3369
+ }
3370
+ ShadowRoot.prototype = Object.create(DocumentFragment.prototype);
3371
+ mixin(ShadowRoot.prototype, {
3372
+ constructor: ShadowRoot,
3373
+ get innerHTML() {
3374
+ return getInnerHTML(this);
3375
+ },
3376
+ set innerHTML(value) {
3377
+ setInnerHTML(this, value);
3378
+ this.invalidateShadowRenderer();
3379
+ },
3380
+ get olderShadowRoot() {
3381
+ return nextOlderShadowTreeTable.get(this) || null;
3382
+ },
3383
+ get host() {
3384
+ return shadowHostTable.get(this) || null;
3385
+ },
3386
+ invalidateShadowRenderer: function() {
3387
+ return shadowHostTable.get(this).invalidateShadowRenderer();
3388
+ },
3389
+ elementFromPoint: function(x, y) {
3390
+ return elementFromPoint(this, this.ownerDocument, x, y);
3391
+ },
3392
+ getElementById: function(id) {
3393
+ if (spaceCharRe.test(id)) return null;
3394
+ return this.querySelector('[id="' + id + '"]');
3395
+ }
3396
+ });
3397
+ scope.wrappers.ShadowRoot = ShadowRoot;
3398
+ })(window.ShadowDOMPolyfill);
3399
+ (function(scope) {
3400
+ "use strict";
3401
+ var Element = scope.wrappers.Element;
3402
+ var HTMLContentElement = scope.wrappers.HTMLContentElement;
3403
+ var HTMLShadowElement = scope.wrappers.HTMLShadowElement;
3404
+ var Node = scope.wrappers.Node;
3405
+ var ShadowRoot = scope.wrappers.ShadowRoot;
3406
+ var assert = scope.assert;
3407
+ var getTreeScope = scope.getTreeScope;
3408
+ var mixin = scope.mixin;
3409
+ var oneOf = scope.oneOf;
3410
+ var unsafeUnwrap = scope.unsafeUnwrap;
3411
+ var unwrap = scope.unwrap;
3412
+ var wrap = scope.wrap;
3413
+ var ArraySplice = scope.ArraySplice;
3414
+ function updateWrapperUpAndSideways(wrapper) {
3415
+ wrapper.previousSibling_ = wrapper.previousSibling;
3416
+ wrapper.nextSibling_ = wrapper.nextSibling;
3417
+ wrapper.parentNode_ = wrapper.parentNode;
3418
+ }
3419
+ function updateWrapperDown(wrapper) {
3420
+ wrapper.firstChild_ = wrapper.firstChild;
3421
+ wrapper.lastChild_ = wrapper.lastChild;
3422
+ }
3423
+ function updateAllChildNodes(parentNodeWrapper) {
3424
+ assert(parentNodeWrapper instanceof Node);
3425
+ for (var childWrapper = parentNodeWrapper.firstChild; childWrapper; childWrapper = childWrapper.nextSibling) {
3426
+ updateWrapperUpAndSideways(childWrapper);
3427
+ }
3428
+ updateWrapperDown(parentNodeWrapper);
3429
+ }
3430
+ function insertBefore(parentNodeWrapper, newChildWrapper, refChildWrapper) {
3431
+ var parentNode = unwrap(parentNodeWrapper);
3432
+ var newChild = unwrap(newChildWrapper);
3433
+ var refChild = refChildWrapper ? unwrap(refChildWrapper) : null;
3434
+ remove(newChildWrapper);
3435
+ updateWrapperUpAndSideways(newChildWrapper);
3436
+ if (!refChildWrapper) {
3437
+ parentNodeWrapper.lastChild_ = parentNodeWrapper.lastChild;
3438
+ if (parentNodeWrapper.lastChild === parentNodeWrapper.firstChild) parentNodeWrapper.firstChild_ = parentNodeWrapper.firstChild;
3439
+ var lastChildWrapper = wrap(parentNode.lastChild);
3440
+ if (lastChildWrapper) lastChildWrapper.nextSibling_ = lastChildWrapper.nextSibling;
3441
+ } else {
3442
+ if (parentNodeWrapper.firstChild === refChildWrapper) parentNodeWrapper.firstChild_ = refChildWrapper;
3443
+ refChildWrapper.previousSibling_ = refChildWrapper.previousSibling;
3444
+ }
3445
+ scope.originalInsertBefore.call(parentNode, newChild, refChild);
3446
+ }
3447
+ function remove(nodeWrapper) {
3448
+ var node = unwrap(nodeWrapper);
3449
+ var parentNode = node.parentNode;
3450
+ if (!parentNode) return;
3451
+ var parentNodeWrapper = wrap(parentNode);
3452
+ updateWrapperUpAndSideways(nodeWrapper);
3453
+ if (nodeWrapper.previousSibling) nodeWrapper.previousSibling.nextSibling_ = nodeWrapper;
3454
+ if (nodeWrapper.nextSibling) nodeWrapper.nextSibling.previousSibling_ = nodeWrapper;
3455
+ if (parentNodeWrapper.lastChild === nodeWrapper) parentNodeWrapper.lastChild_ = nodeWrapper;
3456
+ if (parentNodeWrapper.firstChild === nodeWrapper) parentNodeWrapper.firstChild_ = nodeWrapper;
3457
+ scope.originalRemoveChild.call(parentNode, node);
3458
+ }
3459
+ var distributedNodesTable = new WeakMap();
3460
+ var destinationInsertionPointsTable = new WeakMap();
3461
+ var rendererForHostTable = new WeakMap();
3462
+ function resetDistributedNodes(insertionPoint) {
3463
+ distributedNodesTable.set(insertionPoint, []);
3464
+ }
3465
+ function getDistributedNodes(insertionPoint) {
3466
+ var rv = distributedNodesTable.get(insertionPoint);
3467
+ if (!rv) distributedNodesTable.set(insertionPoint, rv = []);
3468
+ return rv;
3469
+ }
3470
+ function getChildNodesSnapshot(node) {
3471
+ var result = [], i = 0;
3472
+ for (var child = node.firstChild; child; child = child.nextSibling) {
3473
+ result[i++] = child;
3474
+ }
3475
+ return result;
3476
+ }
3477
+ var request = oneOf(window, [ "requestAnimationFrame", "mozRequestAnimationFrame", "webkitRequestAnimationFrame", "setTimeout" ]);
3478
+ var pendingDirtyRenderers = [];
3479
+ var renderTimer;
3480
+ function renderAllPending() {
3481
+ for (var i = 0; i < pendingDirtyRenderers.length; i++) {
3482
+ var renderer = pendingDirtyRenderers[i];
3483
+ var parentRenderer = renderer.parentRenderer;
3484
+ if (parentRenderer && parentRenderer.dirty) continue;
3485
+ renderer.render();
3486
+ }
3487
+ pendingDirtyRenderers = [];
3488
+ }
3489
+ function handleRequestAnimationFrame() {
3490
+ renderTimer = null;
3491
+ renderAllPending();
3492
+ }
3493
+ function getRendererForHost(host) {
3494
+ var renderer = rendererForHostTable.get(host);
3495
+ if (!renderer) {
3496
+ renderer = new ShadowRenderer(host);
3497
+ rendererForHostTable.set(host, renderer);
3498
+ }
3499
+ return renderer;
3500
+ }
3501
+ function getShadowRootAncestor(node) {
3502
+ var root = getTreeScope(node).root;
3503
+ if (root instanceof ShadowRoot) return root;
3504
+ return null;
3505
+ }
3506
+ function getRendererForShadowRoot(shadowRoot) {
3507
+ return getRendererForHost(shadowRoot.host);
3508
+ }
3509
+ var spliceDiff = new ArraySplice();
3510
+ spliceDiff.equals = function(renderNode, rawNode) {
3511
+ return unwrap(renderNode.node) === rawNode;
3512
+ };
3513
+ function RenderNode(node) {
3514
+ this.skip = false;
3515
+ this.node = node;
3516
+ this.childNodes = [];
3517
+ }
3518
+ RenderNode.prototype = {
3519
+ append: function(node) {
3520
+ var rv = new RenderNode(node);
3521
+ this.childNodes.push(rv);
3522
+ return rv;
3523
+ },
3524
+ sync: function(opt_added) {
3525
+ if (this.skip) return;
3526
+ var nodeWrapper = this.node;
3527
+ var newChildren = this.childNodes;
3528
+ var oldChildren = getChildNodesSnapshot(unwrap(nodeWrapper));
3529
+ var added = opt_added || new WeakMap();
3530
+ var splices = spliceDiff.calculateSplices(newChildren, oldChildren);
3531
+ var newIndex = 0, oldIndex = 0;
3532
+ var lastIndex = 0;
3533
+ for (var i = 0; i < splices.length; i++) {
3534
+ var splice = splices[i];
3535
+ for (;lastIndex < splice.index; lastIndex++) {
3536
+ oldIndex++;
3537
+ newChildren[newIndex++].sync(added);
3538
+ }
3539
+ var removedCount = splice.removed.length;
3540
+ for (var j = 0; j < removedCount; j++) {
3541
+ var wrapper = wrap(oldChildren[oldIndex++]);
3542
+ if (!added.get(wrapper)) remove(wrapper);
3543
+ }
3544
+ var addedCount = splice.addedCount;
3545
+ var refNode = oldChildren[oldIndex] && wrap(oldChildren[oldIndex]);
3546
+ for (var j = 0; j < addedCount; j++) {
3547
+ var newChildRenderNode = newChildren[newIndex++];
3548
+ var newChildWrapper = newChildRenderNode.node;
3549
+ insertBefore(nodeWrapper, newChildWrapper, refNode);
3550
+ added.set(newChildWrapper, true);
3551
+ newChildRenderNode.sync(added);
3552
+ }
3553
+ lastIndex += addedCount;
3554
+ }
3555
+ for (var i = lastIndex; i < newChildren.length; i++) {
3556
+ newChildren[i].sync(added);
3557
+ }
3558
+ }
3559
+ };
3560
+ function ShadowRenderer(host) {
3561
+ this.host = host;
3562
+ this.dirty = false;
3563
+ this.invalidateAttributes();
3564
+ this.associateNode(host);
3565
+ }
3566
+ ShadowRenderer.prototype = {
3567
+ render: function(opt_renderNode) {
3568
+ if (!this.dirty) return;
3569
+ this.invalidateAttributes();
3570
+ var host = this.host;
3571
+ this.distribution(host);
3572
+ var renderNode = opt_renderNode || new RenderNode(host);
3573
+ this.buildRenderTree(renderNode, host);
3574
+ var topMostRenderer = !opt_renderNode;
3575
+ if (topMostRenderer) renderNode.sync();
3576
+ this.dirty = false;
3577
+ },
3578
+ get parentRenderer() {
3579
+ return getTreeScope(this.host).renderer;
3580
+ },
3581
+ invalidate: function() {
3582
+ if (!this.dirty) {
3583
+ this.dirty = true;
3584
+ var parentRenderer = this.parentRenderer;
3585
+ if (parentRenderer) parentRenderer.invalidate();
3586
+ pendingDirtyRenderers.push(this);
3587
+ if (renderTimer) return;
3588
+ renderTimer = window[request](handleRequestAnimationFrame, 0);
3589
+ }
3590
+ },
3591
+ distribution: function(root) {
3592
+ this.resetAllSubtrees(root);
3593
+ this.distributionResolution(root);
3594
+ },
3595
+ resetAll: function(node) {
3596
+ if (isInsertionPoint(node)) resetDistributedNodes(node); else resetDestinationInsertionPoints(node);
3597
+ this.resetAllSubtrees(node);
3598
+ },
3599
+ resetAllSubtrees: function(node) {
3600
+ for (var child = node.firstChild; child; child = child.nextSibling) {
3601
+ this.resetAll(child);
3602
+ }
3603
+ if (node.shadowRoot) this.resetAll(node.shadowRoot);
3604
+ if (node.olderShadowRoot) this.resetAll(node.olderShadowRoot);
3605
+ },
3606
+ distributionResolution: function(node) {
3607
+ if (isShadowHost(node)) {
3608
+ var shadowHost = node;
3609
+ var pool = poolPopulation(shadowHost);
3610
+ var shadowTrees = getShadowTrees(shadowHost);
3611
+ for (var i = 0; i < shadowTrees.length; i++) {
3612
+ this.poolDistribution(shadowTrees[i], pool);
3613
+ }
3614
+ for (var i = shadowTrees.length - 1; i >= 0; i--) {
3615
+ var shadowTree = shadowTrees[i];
3616
+ var shadow = getShadowInsertionPoint(shadowTree);
3617
+ if (shadow) {
3618
+ var olderShadowRoot = shadowTree.olderShadowRoot;
3619
+ if (olderShadowRoot) {
3620
+ pool = poolPopulation(olderShadowRoot);
3621
+ }
3622
+ for (var j = 0; j < pool.length; j++) {
3623
+ destributeNodeInto(pool[j], shadow);
3624
+ }
3625
+ }
3626
+ this.distributionResolution(shadowTree);
3627
+ }
3628
+ }
3629
+ for (var child = node.firstChild; child; child = child.nextSibling) {
3630
+ this.distributionResolution(child);
3631
+ }
3632
+ },
3633
+ poolDistribution: function(node, pool) {
3634
+ if (node instanceof HTMLShadowElement) return;
3635
+ if (node instanceof HTMLContentElement) {
3636
+ var content = node;
3637
+ this.updateDependentAttributes(content.getAttribute("select"));
3638
+ var anyDistributed = false;
3639
+ for (var i = 0; i < pool.length; i++) {
3640
+ var node = pool[i];
3641
+ if (!node) continue;
3642
+ if (matches(node, content)) {
3643
+ destributeNodeInto(node, content);
3644
+ pool[i] = undefined;
3645
+ anyDistributed = true;
3646
+ }
3647
+ }
3648
+ if (!anyDistributed) {
3649
+ for (var child = content.firstChild; child; child = child.nextSibling) {
3650
+ destributeNodeInto(child, content);
3651
+ }
3652
+ }
3653
+ return;
3654
+ }
3655
+ for (var child = node.firstChild; child; child = child.nextSibling) {
3656
+ this.poolDistribution(child, pool);
3657
+ }
3658
+ },
3659
+ buildRenderTree: function(renderNode, node) {
3660
+ var children = this.compose(node);
3661
+ for (var i = 0; i < children.length; i++) {
3662
+ var child = children[i];
3663
+ var childRenderNode = renderNode.append(child);
3664
+ this.buildRenderTree(childRenderNode, child);
3665
+ }
3666
+ if (isShadowHost(node)) {
3667
+ var renderer = getRendererForHost(node);
3668
+ renderer.dirty = false;
3669
+ }
3670
+ },
3671
+ compose: function(node) {
3672
+ var children = [];
3673
+ var p = node.shadowRoot || node;
3674
+ for (var child = p.firstChild; child; child = child.nextSibling) {
3675
+ if (isInsertionPoint(child)) {
3676
+ this.associateNode(p);
3677
+ var distributedNodes = getDistributedNodes(child);
3678
+ for (var j = 0; j < distributedNodes.length; j++) {
3679
+ var distributedNode = distributedNodes[j];
3680
+ if (isFinalDestination(child, distributedNode)) children.push(distributedNode);
3681
+ }
3682
+ } else {
3683
+ children.push(child);
3684
+ }
3685
+ }
3686
+ return children;
3687
+ },
3688
+ invalidateAttributes: function() {
3689
+ this.attributes = Object.create(null);
3690
+ },
3691
+ updateDependentAttributes: function(selector) {
3692
+ if (!selector) return;
3693
+ var attributes = this.attributes;
3694
+ if (/\.\w+/.test(selector)) attributes["class"] = true;
3695
+ if (/#\w+/.test(selector)) attributes["id"] = true;
3696
+ selector.replace(/\[\s*([^\s=\|~\]]+)/g, function(_, name) {
3697
+ attributes[name] = true;
3698
+ });
3699
+ },
3700
+ dependsOnAttribute: function(name) {
3701
+ return this.attributes[name];
3702
+ },
3703
+ associateNode: function(node) {
3704
+ unsafeUnwrap(node).polymerShadowRenderer_ = this;
3705
+ }
3706
+ };
3707
+ function poolPopulation(node) {
3708
+ var pool = [];
3709
+ for (var child = node.firstChild; child; child = child.nextSibling) {
3710
+ if (isInsertionPoint(child)) {
3711
+ pool.push.apply(pool, getDistributedNodes(child));
3712
+ } else {
3713
+ pool.push(child);
3714
+ }
3715
+ }
3716
+ return pool;
3717
+ }
3718
+ function getShadowInsertionPoint(node) {
3719
+ if (node instanceof HTMLShadowElement) return node;
3720
+ if (node instanceof HTMLContentElement) return null;
3721
+ for (var child = node.firstChild; child; child = child.nextSibling) {
3722
+ var res = getShadowInsertionPoint(child);
3723
+ if (res) return res;
3724
+ }
3725
+ return null;
3726
+ }
3727
+ function destributeNodeInto(child, insertionPoint) {
3728
+ getDistributedNodes(insertionPoint).push(child);
3729
+ var points = destinationInsertionPointsTable.get(child);
3730
+ if (!points) destinationInsertionPointsTable.set(child, [ insertionPoint ]); else points.push(insertionPoint);
3731
+ }
3732
+ function getDestinationInsertionPoints(node) {
3733
+ return destinationInsertionPointsTable.get(node);
3734
+ }
3735
+ function resetDestinationInsertionPoints(node) {
3736
+ destinationInsertionPointsTable.set(node, undefined);
3737
+ }
3738
+ var selectorStartCharRe = /^(:not\()?[*.#[a-zA-Z_|]/;
3739
+ function matches(node, contentElement) {
3740
+ var select = contentElement.getAttribute("select");
3741
+ if (!select) return true;
3742
+ select = select.trim();
3743
+ if (!select) return true;
3744
+ if (!(node instanceof Element)) return false;
3745
+ if (!selectorStartCharRe.test(select)) return false;
3746
+ try {
3747
+ return node.matches(select);
3748
+ } catch (ex) {
3749
+ return false;
3750
+ }
3751
+ }
3752
+ function isFinalDestination(insertionPoint, node) {
3753
+ var points = getDestinationInsertionPoints(node);
3754
+ return points && points[points.length - 1] === insertionPoint;
3755
+ }
3756
+ function isInsertionPoint(node) {
3757
+ return node instanceof HTMLContentElement || node instanceof HTMLShadowElement;
3758
+ }
3759
+ function isShadowHost(shadowHost) {
3760
+ return shadowHost.shadowRoot;
3761
+ }
3762
+ function getShadowTrees(host) {
3763
+ var trees = [];
3764
+ for (var tree = host.shadowRoot; tree; tree = tree.olderShadowRoot) {
3765
+ trees.push(tree);
3766
+ }
3767
+ return trees;
3768
+ }
3769
+ function render(host) {
3770
+ new ShadowRenderer(host).render();
3771
+ }
3772
+ Node.prototype.invalidateShadowRenderer = function(force) {
3773
+ var renderer = unsafeUnwrap(this).polymerShadowRenderer_;
3774
+ if (renderer) {
3775
+ renderer.invalidate();
3776
+ return true;
3777
+ }
3778
+ return false;
3779
+ };
3780
+ HTMLContentElement.prototype.getDistributedNodes = HTMLShadowElement.prototype.getDistributedNodes = function() {
3781
+ renderAllPending();
3782
+ return getDistributedNodes(this);
3783
+ };
3784
+ Element.prototype.getDestinationInsertionPoints = function() {
3785
+ renderAllPending();
3786
+ return getDestinationInsertionPoints(this) || [];
3787
+ };
3788
+ HTMLContentElement.prototype.nodeIsInserted_ = HTMLShadowElement.prototype.nodeIsInserted_ = function() {
3789
+ this.invalidateShadowRenderer();
3790
+ var shadowRoot = getShadowRootAncestor(this);
3791
+ var renderer;
3792
+ if (shadowRoot) renderer = getRendererForShadowRoot(shadowRoot);
3793
+ unsafeUnwrap(this).polymerShadowRenderer_ = renderer;
3794
+ if (renderer) renderer.invalidate();
3795
+ };
3796
+ scope.getRendererForHost = getRendererForHost;
3797
+ scope.getShadowTrees = getShadowTrees;
3798
+ scope.renderAllPending = renderAllPending;
3799
+ scope.getDestinationInsertionPoints = getDestinationInsertionPoints;
3800
+ scope.visual = {
3801
+ insertBefore: insertBefore,
3802
+ remove: remove
3803
+ };
3804
+ })(window.ShadowDOMPolyfill);
3805
+ (function(scope) {
3806
+ "use strict";
3807
+ var HTMLElement = scope.wrappers.HTMLElement;
3808
+ var assert = scope.assert;
3809
+ var mixin = scope.mixin;
3810
+ var registerWrapper = scope.registerWrapper;
3811
+ var unwrap = scope.unwrap;
3812
+ var wrap = scope.wrap;
3813
+ var elementsWithFormProperty = [ "HTMLButtonElement", "HTMLFieldSetElement", "HTMLInputElement", "HTMLKeygenElement", "HTMLLabelElement", "HTMLLegendElement", "HTMLObjectElement", "HTMLOutputElement", "HTMLTextAreaElement" ];
3814
+ function createWrapperConstructor(name) {
3815
+ if (!window[name]) return;
3816
+ assert(!scope.wrappers[name]);
3817
+ var GeneratedWrapper = function(node) {
3818
+ HTMLElement.call(this, node);
3819
+ };
3820
+ GeneratedWrapper.prototype = Object.create(HTMLElement.prototype);
3821
+ mixin(GeneratedWrapper.prototype, {
3822
+ get form() {
3823
+ return wrap(unwrap(this).form);
3824
+ }
3825
+ });
3826
+ registerWrapper(window[name], GeneratedWrapper, document.createElement(name.slice(4, -7)));
3827
+ scope.wrappers[name] = GeneratedWrapper;
3828
+ }
3829
+ elementsWithFormProperty.forEach(createWrapperConstructor);
3830
+ })(window.ShadowDOMPolyfill);
3831
+ (function(scope) {
3832
+ "use strict";
3833
+ var registerWrapper = scope.registerWrapper;
3834
+ var setWrapper = scope.setWrapper;
3835
+ var unsafeUnwrap = scope.unsafeUnwrap;
3836
+ var unwrap = scope.unwrap;
3837
+ var unwrapIfNeeded = scope.unwrapIfNeeded;
3838
+ var wrap = scope.wrap;
3839
+ var OriginalSelection = window.Selection;
3840
+ function Selection(impl) {
3841
+ setWrapper(impl, this);
3842
+ }
3843
+ Selection.prototype = {
3844
+ get anchorNode() {
3845
+ return wrap(unsafeUnwrap(this).anchorNode);
3846
+ },
3847
+ get focusNode() {
3848
+ return wrap(unsafeUnwrap(this).focusNode);
3849
+ },
3850
+ addRange: function(range) {
3851
+ unsafeUnwrap(this).addRange(unwrap(range));
3852
+ },
3853
+ collapse: function(node, index) {
3854
+ unsafeUnwrap(this).collapse(unwrapIfNeeded(node), index);
3855
+ },
3856
+ containsNode: function(node, allowPartial) {
3857
+ return unsafeUnwrap(this).containsNode(unwrapIfNeeded(node), allowPartial);
3858
+ },
3859
+ extend: function(node, offset) {
3860
+ unsafeUnwrap(this).extend(unwrapIfNeeded(node), offset);
3861
+ },
3862
+ getRangeAt: function(index) {
3863
+ return wrap(unsafeUnwrap(this).getRangeAt(index));
3864
+ },
3865
+ removeRange: function(range) {
3866
+ unsafeUnwrap(this).removeRange(unwrap(range));
3867
+ },
3868
+ selectAllChildren: function(node) {
3869
+ unsafeUnwrap(this).selectAllChildren(unwrapIfNeeded(node));
3870
+ },
3871
+ toString: function() {
3872
+ return unsafeUnwrap(this).toString();
3873
+ }
3874
+ };
3875
+ registerWrapper(window.Selection, Selection, window.getSelection());
3876
+ scope.wrappers.Selection = Selection;
3877
+ })(window.ShadowDOMPolyfill);
3878
+ (function(scope) {
3879
+ "use strict";
3880
+ var GetElementsByInterface = scope.GetElementsByInterface;
3881
+ var Node = scope.wrappers.Node;
3882
+ var ParentNodeInterface = scope.ParentNodeInterface;
3883
+ var Selection = scope.wrappers.Selection;
3884
+ var SelectorsInterface = scope.SelectorsInterface;
3885
+ var ShadowRoot = scope.wrappers.ShadowRoot;
3886
+ var TreeScope = scope.TreeScope;
3887
+ var cloneNode = scope.cloneNode;
3888
+ var defineWrapGetter = scope.defineWrapGetter;
3889
+ var elementFromPoint = scope.elementFromPoint;
3890
+ var forwardMethodsToWrapper = scope.forwardMethodsToWrapper;
3891
+ var matchesNames = scope.matchesNames;
3892
+ var mixin = scope.mixin;
3893
+ var registerWrapper = scope.registerWrapper;
3894
+ var renderAllPending = scope.renderAllPending;
3895
+ var rewrap = scope.rewrap;
3896
+ var setWrapper = scope.setWrapper;
3897
+ var unsafeUnwrap = scope.unsafeUnwrap;
3898
+ var unwrap = scope.unwrap;
3899
+ var wrap = scope.wrap;
3900
+ var wrapEventTargetMethods = scope.wrapEventTargetMethods;
3901
+ var wrapNodeList = scope.wrapNodeList;
3902
+ var implementationTable = new WeakMap();
3903
+ function Document(node) {
3904
+ Node.call(this, node);
3905
+ this.treeScope_ = new TreeScope(this, null);
3906
+ }
3907
+ Document.prototype = Object.create(Node.prototype);
3908
+ defineWrapGetter(Document, "documentElement");
3909
+ defineWrapGetter(Document, "body");
3910
+ defineWrapGetter(Document, "head");
3911
+ function wrapMethod(name) {
3912
+ var original = document[name];
3913
+ Document.prototype[name] = function() {
3914
+ return wrap(original.apply(unsafeUnwrap(this), arguments));
3915
+ };
3916
+ }
3917
+ [ "createComment", "createDocumentFragment", "createElement", "createElementNS", "createEvent", "createEventNS", "createRange", "createTextNode", "getElementById" ].forEach(wrapMethod);
3918
+ var originalAdoptNode = document.adoptNode;
3919
+ function adoptNodeNoRemove(node, doc) {
3920
+ originalAdoptNode.call(unsafeUnwrap(doc), unwrap(node));
3921
+ adoptSubtree(node, doc);
3922
+ }
3923
+ function adoptSubtree(node, doc) {
3924
+ if (node.shadowRoot) doc.adoptNode(node.shadowRoot);
3925
+ if (node instanceof ShadowRoot) adoptOlderShadowRoots(node, doc);
3926
+ for (var child = node.firstChild; child; child = child.nextSibling) {
3927
+ adoptSubtree(child, doc);
3928
+ }
3929
+ }
3930
+ function adoptOlderShadowRoots(shadowRoot, doc) {
3931
+ var oldShadowRoot = shadowRoot.olderShadowRoot;
3932
+ if (oldShadowRoot) doc.adoptNode(oldShadowRoot);
3933
+ }
3934
+ var originalGetSelection = document.getSelection;
3935
+ mixin(Document.prototype, {
3936
+ adoptNode: function(node) {
3937
+ if (node.parentNode) node.parentNode.removeChild(node);
3938
+ adoptNodeNoRemove(node, this);
3939
+ return node;
3940
+ },
3941
+ elementFromPoint: function(x, y) {
3942
+ return elementFromPoint(this, this, x, y);
3943
+ },
3944
+ importNode: function(node, deep) {
3945
+ return cloneNode(node, deep, unsafeUnwrap(this));
3946
+ },
3947
+ getSelection: function() {
3948
+ renderAllPending();
3949
+ return new Selection(originalGetSelection.call(unwrap(this)));
3950
+ },
3951
+ getElementsByName: function(name) {
3952
+ return SelectorsInterface.querySelectorAll.call(this, "[name=" + JSON.stringify(String(name)) + "]");
3953
+ }
3954
+ });
3955
+ if (document.registerElement) {
3956
+ var originalRegisterElement = document.registerElement;
3957
+ Document.prototype.registerElement = function(tagName, object) {
3958
+ var prototype, extendsOption;
3959
+ if (object !== undefined) {
3960
+ prototype = object.prototype;
3961
+ extendsOption = object.extends;
3962
+ }
3963
+ if (!prototype) prototype = Object.create(HTMLElement.prototype);
3964
+ if (scope.nativePrototypeTable.get(prototype)) {
3965
+ throw new Error("NotSupportedError");
3966
+ }
3967
+ var proto = Object.getPrototypeOf(prototype);
3968
+ var nativePrototype;
3969
+ var prototypes = [];
3970
+ while (proto) {
3971
+ nativePrototype = scope.nativePrototypeTable.get(proto);
3972
+ if (nativePrototype) break;
3973
+ prototypes.push(proto);
3974
+ proto = Object.getPrototypeOf(proto);
3975
+ }
3976
+ if (!nativePrototype) {
3977
+ throw new Error("NotSupportedError");
3978
+ }
3979
+ var newPrototype = Object.create(nativePrototype);
3980
+ for (var i = prototypes.length - 1; i >= 0; i--) {
3981
+ newPrototype = Object.create(newPrototype);
3982
+ }
3983
+ [ "createdCallback", "attachedCallback", "detachedCallback", "attributeChangedCallback" ].forEach(function(name) {
3984
+ var f = prototype[name];
3985
+ if (!f) return;
3986
+ newPrototype[name] = function() {
3987
+ if (!(wrap(this) instanceof CustomElementConstructor)) {
3988
+ rewrap(this);
3989
+ }
3990
+ f.apply(wrap(this), arguments);
3991
+ };
3992
+ });
3993
+ var p = {
3994
+ prototype: newPrototype
3995
+ };
3996
+ if (extendsOption) p.extends = extendsOption;
3997
+ function CustomElementConstructor(node) {
3998
+ if (!node) {
3999
+ if (extendsOption) {
4000
+ return document.createElement(extendsOption, tagName);
4001
+ } else {
4002
+ return document.createElement(tagName);
4003
+ }
4004
+ }
4005
+ setWrapper(node, this);
4006
+ }
4007
+ CustomElementConstructor.prototype = prototype;
4008
+ CustomElementConstructor.prototype.constructor = CustomElementConstructor;
4009
+ scope.constructorTable.set(newPrototype, CustomElementConstructor);
4010
+ scope.nativePrototypeTable.set(prototype, newPrototype);
4011
+ var nativeConstructor = originalRegisterElement.call(unwrap(this), tagName, p);
4012
+ return CustomElementConstructor;
4013
+ };
4014
+ forwardMethodsToWrapper([ window.HTMLDocument || window.Document ], [ "registerElement" ]);
4015
+ }
4016
+ forwardMethodsToWrapper([ window.HTMLBodyElement, window.HTMLDocument || window.Document, window.HTMLHeadElement, window.HTMLHtmlElement ], [ "appendChild", "compareDocumentPosition", "contains", "getElementsByClassName", "getElementsByTagName", "getElementsByTagNameNS", "insertBefore", "querySelector", "querySelectorAll", "removeChild", "replaceChild" ].concat(matchesNames));
4017
+ forwardMethodsToWrapper([ window.HTMLDocument || window.Document ], [ "adoptNode", "importNode", "contains", "createComment", "createDocumentFragment", "createElement", "createElementNS", "createEvent", "createEventNS", "createRange", "createTextNode", "elementFromPoint", "getElementById", "getElementsByName", "getSelection" ]);
4018
+ mixin(Document.prototype, GetElementsByInterface);
4019
+ mixin(Document.prototype, ParentNodeInterface);
4020
+ mixin(Document.prototype, SelectorsInterface);
4021
+ mixin(Document.prototype, {
4022
+ get implementation() {
4023
+ var implementation = implementationTable.get(this);
4024
+ if (implementation) return implementation;
4025
+ implementation = new DOMImplementation(unwrap(this).implementation);
4026
+ implementationTable.set(this, implementation);
4027
+ return implementation;
4028
+ },
4029
+ get defaultView() {
4030
+ return wrap(unwrap(this).defaultView);
4031
+ }
4032
+ });
4033
+ registerWrapper(window.Document, Document, document.implementation.createHTMLDocument(""));
4034
+ if (window.HTMLDocument) registerWrapper(window.HTMLDocument, Document);
4035
+ wrapEventTargetMethods([ window.HTMLBodyElement, window.HTMLDocument || window.Document, window.HTMLHeadElement ]);
4036
+ function DOMImplementation(impl) {
4037
+ setWrapper(impl, this);
4038
+ }
4039
+ function wrapImplMethod(constructor, name) {
4040
+ var original = document.implementation[name];
4041
+ constructor.prototype[name] = function() {
4042
+ return wrap(original.apply(unsafeUnwrap(this), arguments));
4043
+ };
4044
+ }
4045
+ function forwardImplMethod(constructor, name) {
4046
+ var original = document.implementation[name];
4047
+ constructor.prototype[name] = function() {
4048
+ return original.apply(unsafeUnwrap(this), arguments);
4049
+ };
4050
+ }
4051
+ wrapImplMethod(DOMImplementation, "createDocumentType");
4052
+ wrapImplMethod(DOMImplementation, "createDocument");
4053
+ wrapImplMethod(DOMImplementation, "createHTMLDocument");
4054
+ forwardImplMethod(DOMImplementation, "hasFeature");
4055
+ registerWrapper(window.DOMImplementation, DOMImplementation);
4056
+ forwardMethodsToWrapper([ window.DOMImplementation ], [ "createDocumentType", "createDocument", "createHTMLDocument", "hasFeature" ]);
4057
+ scope.adoptNodeNoRemove = adoptNodeNoRemove;
4058
+ scope.wrappers.DOMImplementation = DOMImplementation;
4059
+ scope.wrappers.Document = Document;
4060
+ })(window.ShadowDOMPolyfill);
4061
+ (function(scope) {
4062
+ "use strict";
4063
+ var EventTarget = scope.wrappers.EventTarget;
4064
+ var Selection = scope.wrappers.Selection;
4065
+ var mixin = scope.mixin;
4066
+ var registerWrapper = scope.registerWrapper;
4067
+ var renderAllPending = scope.renderAllPending;
4068
+ var unwrap = scope.unwrap;
4069
+ var unwrapIfNeeded = scope.unwrapIfNeeded;
4070
+ var wrap = scope.wrap;
4071
+ var OriginalWindow = window.Window;
4072
+ var originalGetComputedStyle = window.getComputedStyle;
4073
+ var originalGetDefaultComputedStyle = window.getDefaultComputedStyle;
4074
+ var originalGetSelection = window.getSelection;
4075
+ function Window(impl) {
4076
+ EventTarget.call(this, impl);
4077
+ }
4078
+ Window.prototype = Object.create(EventTarget.prototype);
4079
+ OriginalWindow.prototype.getComputedStyle = function(el, pseudo) {
4080
+ return wrap(this || window).getComputedStyle(unwrapIfNeeded(el), pseudo);
4081
+ };
4082
+ if (originalGetDefaultComputedStyle) {
4083
+ OriginalWindow.prototype.getDefaultComputedStyle = function(el, pseudo) {
4084
+ return wrap(this || window).getDefaultComputedStyle(unwrapIfNeeded(el), pseudo);
4085
+ };
4086
+ }
4087
+ OriginalWindow.prototype.getSelection = function() {
4088
+ return wrap(this || window).getSelection();
4089
+ };
4090
+ delete window.getComputedStyle;
4091
+ delete window.getDefaultComputedStyle;
4092
+ delete window.getSelection;
4093
+ [ "addEventListener", "removeEventListener", "dispatchEvent" ].forEach(function(name) {
4094
+ OriginalWindow.prototype[name] = function() {
4095
+ var w = wrap(this || window);
4096
+ return w[name].apply(w, arguments);
4097
+ };
4098
+ delete window[name];
4099
+ });
4100
+ mixin(Window.prototype, {
4101
+ getComputedStyle: function(el, pseudo) {
4102
+ renderAllPending();
4103
+ return originalGetComputedStyle.call(unwrap(this), unwrapIfNeeded(el), pseudo);
4104
+ },
4105
+ getSelection: function() {
4106
+ renderAllPending();
4107
+ return new Selection(originalGetSelection.call(unwrap(this)));
4108
+ },
4109
+ get document() {
4110
+ return wrap(unwrap(this).document);
4111
+ }
4112
+ });
4113
+ if (originalGetDefaultComputedStyle) {
4114
+ Window.prototype.getDefaultComputedStyle = function(el, pseudo) {
4115
+ renderAllPending();
4116
+ return originalGetDefaultComputedStyle.call(unwrap(this), unwrapIfNeeded(el), pseudo);
4117
+ };
4118
+ }
4119
+ registerWrapper(OriginalWindow, Window, window);
4120
+ scope.wrappers.Window = Window;
4121
+ })(window.ShadowDOMPolyfill);
4122
+ (function(scope) {
4123
+ "use strict";
4124
+ var unwrap = scope.unwrap;
4125
+ var OriginalDataTransfer = window.DataTransfer || window.Clipboard;
4126
+ var OriginalDataTransferSetDragImage = OriginalDataTransfer.prototype.setDragImage;
4127
+ if (OriginalDataTransferSetDragImage) {
4128
+ OriginalDataTransfer.prototype.setDragImage = function(image, x, y) {
4129
+ OriginalDataTransferSetDragImage.call(this, unwrap(image), x, y);
4130
+ };
4131
+ }
4132
+ })(window.ShadowDOMPolyfill);
4133
+ (function(scope) {
4134
+ "use strict";
4135
+ var registerWrapper = scope.registerWrapper;
4136
+ var setWrapper = scope.setWrapper;
4137
+ var unwrap = scope.unwrap;
4138
+ var OriginalFormData = window.FormData;
4139
+ if (!OriginalFormData) return;
4140
+ function FormData(formElement) {
4141
+ var impl;
4142
+ if (formElement instanceof OriginalFormData) {
4143
+ impl = formElement;
4144
+ } else {
4145
+ impl = new OriginalFormData(formElement && unwrap(formElement));
4146
+ }
4147
+ setWrapper(impl, this);
4148
+ }
4149
+ registerWrapper(OriginalFormData, FormData, new OriginalFormData());
4150
+ scope.wrappers.FormData = FormData;
4151
+ })(window.ShadowDOMPolyfill);
4152
+ (function(scope) {
4153
+ "use strict";
4154
+ var unwrapIfNeeded = scope.unwrapIfNeeded;
4155
+ var originalSend = XMLHttpRequest.prototype.send;
4156
+ XMLHttpRequest.prototype.send = function(obj) {
4157
+ return originalSend.call(this, unwrapIfNeeded(obj));
4158
+ };
4159
+ })(window.ShadowDOMPolyfill);
4160
+ (function(scope) {
4161
+ "use strict";
4162
+ var isWrapperFor = scope.isWrapperFor;
4163
+ var elements = {
4164
+ a: "HTMLAnchorElement",
4165
+ area: "HTMLAreaElement",
4166
+ audio: "HTMLAudioElement",
4167
+ base: "HTMLBaseElement",
4168
+ body: "HTMLBodyElement",
4169
+ br: "HTMLBRElement",
4170
+ button: "HTMLButtonElement",
4171
+ canvas: "HTMLCanvasElement",
4172
+ caption: "HTMLTableCaptionElement",
4173
+ col: "HTMLTableColElement",
4174
+ content: "HTMLContentElement",
4175
+ data: "HTMLDataElement",
4176
+ datalist: "HTMLDataListElement",
4177
+ del: "HTMLModElement",
4178
+ dir: "HTMLDirectoryElement",
4179
+ div: "HTMLDivElement",
4180
+ dl: "HTMLDListElement",
4181
+ embed: "HTMLEmbedElement",
4182
+ fieldset: "HTMLFieldSetElement",
4183
+ font: "HTMLFontElement",
4184
+ form: "HTMLFormElement",
4185
+ frame: "HTMLFrameElement",
4186
+ frameset: "HTMLFrameSetElement",
4187
+ h1: "HTMLHeadingElement",
4188
+ head: "HTMLHeadElement",
4189
+ hr: "HTMLHRElement",
4190
+ html: "HTMLHtmlElement",
4191
+ iframe: "HTMLIFrameElement",
4192
+ img: "HTMLImageElement",
4193
+ input: "HTMLInputElement",
4194
+ keygen: "HTMLKeygenElement",
4195
+ label: "HTMLLabelElement",
4196
+ legend: "HTMLLegendElement",
4197
+ li: "HTMLLIElement",
4198
+ link: "HTMLLinkElement",
4199
+ map: "HTMLMapElement",
4200
+ marquee: "HTMLMarqueeElement",
4201
+ menu: "HTMLMenuElement",
4202
+ menuitem: "HTMLMenuItemElement",
4203
+ meta: "HTMLMetaElement",
4204
+ meter: "HTMLMeterElement",
4205
+ object: "HTMLObjectElement",
4206
+ ol: "HTMLOListElement",
4207
+ optgroup: "HTMLOptGroupElement",
4208
+ option: "HTMLOptionElement",
4209
+ output: "HTMLOutputElement",
4210
+ p: "HTMLParagraphElement",
4211
+ param: "HTMLParamElement",
4212
+ pre: "HTMLPreElement",
4213
+ progress: "HTMLProgressElement",
4214
+ q: "HTMLQuoteElement",
4215
+ script: "HTMLScriptElement",
4216
+ select: "HTMLSelectElement",
4217
+ shadow: "HTMLShadowElement",
4218
+ source: "HTMLSourceElement",
4219
+ span: "HTMLSpanElement",
4220
+ style: "HTMLStyleElement",
4221
+ table: "HTMLTableElement",
4222
+ tbody: "HTMLTableSectionElement",
4223
+ template: "HTMLTemplateElement",
4224
+ textarea: "HTMLTextAreaElement",
4225
+ thead: "HTMLTableSectionElement",
4226
+ time: "HTMLTimeElement",
4227
+ title: "HTMLTitleElement",
4228
+ tr: "HTMLTableRowElement",
4229
+ track: "HTMLTrackElement",
4230
+ ul: "HTMLUListElement",
4231
+ video: "HTMLVideoElement"
4232
+ };
4233
+ function overrideConstructor(tagName) {
4234
+ var nativeConstructorName = elements[tagName];
4235
+ var nativeConstructor = window[nativeConstructorName];
4236
+ if (!nativeConstructor) return;
4237
+ var element = document.createElement(tagName);
4238
+ var wrapperConstructor = element.constructor;
4239
+ window[nativeConstructorName] = wrapperConstructor;
4240
+ }
4241
+ Object.keys(elements).forEach(overrideConstructor);
4242
+ Object.getOwnPropertyNames(scope.wrappers).forEach(function(name) {
4243
+ window[name] = scope.wrappers[name];
4244
+ });
4245
+ })(window.ShadowDOMPolyfill);
4246
+ (function(scope) {
4247
+ var ShadowCSS = {
4248
+ strictStyling: false,
4249
+ registry: {},
4250
+ shimStyling: function(root, name, extendsName) {
4251
+ var scopeStyles = this.prepareRoot(root, name, extendsName);
4252
+ var typeExtension = this.isTypeExtension(extendsName);
4253
+ var scopeSelector = this.makeScopeSelector(name, typeExtension);
4254
+ var cssText = stylesToCssText(scopeStyles, true);
4255
+ cssText = this.scopeCssText(cssText, scopeSelector);
4256
+ if (root) {
4257
+ root.shimmedStyle = cssText;
4258
+ }
4259
+ this.addCssToDocument(cssText, name);
4260
+ },
4261
+ shimStyle: function(style, selector) {
4262
+ return this.shimCssText(style.textContent, selector);
4263
+ },
4264
+ shimCssText: function(cssText, selector) {
4265
+ cssText = this.insertDirectives(cssText);
4266
+ return this.scopeCssText(cssText, selector);
4267
+ },
4268
+ makeScopeSelector: function(name, typeExtension) {
4269
+ if (name) {
4270
+ return typeExtension ? "[is=" + name + "]" : name;
4271
+ }
4272
+ return "";
4273
+ },
4274
+ isTypeExtension: function(extendsName) {
4275
+ return extendsName && extendsName.indexOf("-") < 0;
4276
+ },
4277
+ prepareRoot: function(root, name, extendsName) {
4278
+ var def = this.registerRoot(root, name, extendsName);
4279
+ this.replaceTextInStyles(def.rootStyles, this.insertDirectives);
4280
+ this.removeStyles(root, def.rootStyles);
4281
+ if (this.strictStyling) {
4282
+ this.applyScopeToContent(root, name);
4283
+ }
4284
+ return def.scopeStyles;
4285
+ },
4286
+ removeStyles: function(root, styles) {
4287
+ for (var i = 0, l = styles.length, s; i < l && (s = styles[i]); i++) {
4288
+ s.parentNode.removeChild(s);
4289
+ }
4290
+ },
4291
+ registerRoot: function(root, name, extendsName) {
4292
+ var def = this.registry[name] = {
4293
+ root: root,
4294
+ name: name,
4295
+ extendsName: extendsName
4296
+ };
4297
+ var styles = this.findStyles(root);
4298
+ def.rootStyles = styles;
4299
+ def.scopeStyles = def.rootStyles;
4300
+ var extendee = this.registry[def.extendsName];
4301
+ if (extendee) {
4302
+ def.scopeStyles = extendee.scopeStyles.concat(def.scopeStyles);
4303
+ }
4304
+ return def;
4305
+ },
4306
+ findStyles: function(root) {
4307
+ if (!root) {
4308
+ return [];
4309
+ }
4310
+ var styles = root.querySelectorAll("style");
4311
+ return Array.prototype.filter.call(styles, function(s) {
4312
+ return !s.hasAttribute(NO_SHIM_ATTRIBUTE);
4313
+ });
4314
+ },
4315
+ applyScopeToContent: function(root, name) {
4316
+ if (root) {
4317
+ Array.prototype.forEach.call(root.querySelectorAll("*"), function(node) {
4318
+ node.setAttribute(name, "");
4319
+ });
4320
+ Array.prototype.forEach.call(root.querySelectorAll("template"), function(template) {
4321
+ this.applyScopeToContent(template.content, name);
4322
+ }, this);
4323
+ }
4324
+ },
4325
+ insertDirectives: function(cssText) {
4326
+ cssText = this.insertPolyfillDirectivesInCssText(cssText);
4327
+ return this.insertPolyfillRulesInCssText(cssText);
4328
+ },
4329
+ insertPolyfillDirectivesInCssText: function(cssText) {
4330
+ cssText = cssText.replace(cssCommentNextSelectorRe, function(match, p1) {
4331
+ return p1.slice(0, -2) + "{";
4332
+ });
4333
+ return cssText.replace(cssContentNextSelectorRe, function(match, p1) {
4334
+ return p1 + " {";
4335
+ });
4336
+ },
4337
+ insertPolyfillRulesInCssText: function(cssText) {
4338
+ cssText = cssText.replace(cssCommentRuleRe, function(match, p1) {
4339
+ return p1.slice(0, -1);
4340
+ });
4341
+ return cssText.replace(cssContentRuleRe, function(match, p1, p2, p3) {
4342
+ var rule = match.replace(p1, "").replace(p2, "");
4343
+ return p3 + rule;
4344
+ });
4345
+ },
4346
+ scopeCssText: function(cssText, scopeSelector) {
4347
+ var unscoped = this.extractUnscopedRulesFromCssText(cssText);
4348
+ cssText = this.insertPolyfillHostInCssText(cssText);
4349
+ cssText = this.convertColonHost(cssText);
4350
+ cssText = this.convertColonHostContext(cssText);
4351
+ cssText = this.convertShadowDOMSelectors(cssText);
4352
+ if (scopeSelector) {
4353
+ var self = this, cssText;
4354
+ withCssRules(cssText, function(rules) {
4355
+ cssText = self.scopeRules(rules, scopeSelector);
4356
+ });
4357
+ }
4358
+ cssText = cssText + "\n" + unscoped;
4359
+ return cssText.trim();
4360
+ },
4361
+ extractUnscopedRulesFromCssText: function(cssText) {
4362
+ var r = "", m;
4363
+ while (m = cssCommentUnscopedRuleRe.exec(cssText)) {
4364
+ r += m[1].slice(0, -1) + "\n\n";
4365
+ }
4366
+ while (m = cssContentUnscopedRuleRe.exec(cssText)) {
4367
+ r += m[0].replace(m[2], "").replace(m[1], m[3]) + "\n\n";
4368
+ }
4369
+ return r;
4370
+ },
4371
+ convertColonHost: function(cssText) {
4372
+ return this.convertColonRule(cssText, cssColonHostRe, this.colonHostPartReplacer);
4373
+ },
4374
+ convertColonHostContext: function(cssText) {
4375
+ return this.convertColonRule(cssText, cssColonHostContextRe, this.colonHostContextPartReplacer);
4376
+ },
4377
+ convertColonRule: function(cssText, regExp, partReplacer) {
4378
+ return cssText.replace(regExp, function(m, p1, p2, p3) {
4379
+ p1 = polyfillHostNoCombinator;
4380
+ if (p2) {
4381
+ var parts = p2.split(","), r = [];
4382
+ for (var i = 0, l = parts.length, p; i < l && (p = parts[i]); i++) {
4383
+ p = p.trim();
4384
+ r.push(partReplacer(p1, p, p3));
4385
+ }
4386
+ return r.join(",");
4387
+ } else {
4388
+ return p1 + p3;
4389
+ }
4390
+ });
4391
+ },
4392
+ colonHostContextPartReplacer: function(host, part, suffix) {
4393
+ if (part.match(polyfillHost)) {
4394
+ return this.colonHostPartReplacer(host, part, suffix);
4395
+ } else {
4396
+ return host + part + suffix + ", " + part + " " + host + suffix;
4397
+ }
4398
+ },
4399
+ colonHostPartReplacer: function(host, part, suffix) {
4400
+ return host + part.replace(polyfillHost, "") + suffix;
4401
+ },
4402
+ convertShadowDOMSelectors: function(cssText) {
4403
+ for (var i = 0; i < shadowDOMSelectorsRe.length; i++) {
4404
+ cssText = cssText.replace(shadowDOMSelectorsRe[i], " ");
4405
+ }
4406
+ return cssText;
4407
+ },
4408
+ scopeRules: function(cssRules, scopeSelector) {
4409
+ var cssText = "";
4410
+ if (cssRules) {
4411
+ Array.prototype.forEach.call(cssRules, function(rule) {
4412
+ if (rule.selectorText && (rule.style && rule.style.cssText !== undefined)) {
4413
+ cssText += this.scopeSelector(rule.selectorText, scopeSelector, this.strictStyling) + " {\n ";
4414
+ cssText += this.propertiesFromRule(rule) + "\n}\n\n";
4415
+ } else if (rule.type === CSSRule.MEDIA_RULE) {
4416
+ cssText += "@media " + rule.media.mediaText + " {\n";
4417
+ cssText += this.scopeRules(rule.cssRules, scopeSelector);
4418
+ cssText += "\n}\n\n";
4419
+ } else {
4420
+ try {
4421
+ if (rule.cssText) {
4422
+ cssText += rule.cssText + "\n\n";
4423
+ }
4424
+ } catch (x) {
4425
+ if (rule.type === CSSRule.KEYFRAMES_RULE && rule.cssRules) {
4426
+ cssText += this.ieSafeCssTextFromKeyFrameRule(rule);
4427
+ }
4428
+ }
4429
+ }
4430
+ }, this);
4431
+ }
4432
+ return cssText;
4433
+ },
4434
+ ieSafeCssTextFromKeyFrameRule: function(rule) {
4435
+ var cssText = "@keyframes " + rule.name + " {";
4436
+ Array.prototype.forEach.call(rule.cssRules, function(rule) {
4437
+ cssText += " " + rule.keyText + " {" + rule.style.cssText + "}";
4438
+ });
4439
+ cssText += " }";
4440
+ return cssText;
4441
+ },
4442
+ scopeSelector: function(selector, scopeSelector, strict) {
4443
+ var r = [], parts = selector.split(",");
4444
+ parts.forEach(function(p) {
4445
+ p = p.trim();
4446
+ if (this.selectorNeedsScoping(p, scopeSelector)) {
4447
+ p = strict && !p.match(polyfillHostNoCombinator) ? this.applyStrictSelectorScope(p, scopeSelector) : this.applySelectorScope(p, scopeSelector);
4448
+ }
4449
+ r.push(p);
4450
+ }, this);
4451
+ return r.join(", ");
4452
+ },
4453
+ selectorNeedsScoping: function(selector, scopeSelector) {
4454
+ if (Array.isArray(scopeSelector)) {
4455
+ return true;
4456
+ }
4457
+ var re = this.makeScopeMatcher(scopeSelector);
4458
+ return !selector.match(re);
4459
+ },
4460
+ makeScopeMatcher: function(scopeSelector) {
4461
+ scopeSelector = scopeSelector.replace(/\[/g, "\\[").replace(/\[/g, "\\]");
4462
+ return new RegExp("^(" + scopeSelector + ")" + selectorReSuffix, "m");
4463
+ },
4464
+ applySelectorScope: function(selector, selectorScope) {
4465
+ return Array.isArray(selectorScope) ? this.applySelectorScopeList(selector, selectorScope) : this.applySimpleSelectorScope(selector, selectorScope);
4466
+ },
4467
+ applySelectorScopeList: function(selector, scopeSelectorList) {
4468
+ var r = [];
4469
+ for (var i = 0, s; s = scopeSelectorList[i]; i++) {
4470
+ r.push(this.applySimpleSelectorScope(selector, s));
4471
+ }
4472
+ return r.join(", ");
4473
+ },
4474
+ applySimpleSelectorScope: function(selector, scopeSelector) {
4475
+ if (selector.match(polyfillHostRe)) {
4476
+ selector = selector.replace(polyfillHostNoCombinator, scopeSelector);
4477
+ return selector.replace(polyfillHostRe, scopeSelector + " ");
4478
+ } else {
4479
+ return scopeSelector + " " + selector;
4480
+ }
4481
+ },
4482
+ applyStrictSelectorScope: function(selector, scopeSelector) {
4483
+ scopeSelector = scopeSelector.replace(/\[is=([^\]]*)\]/g, "$1");
4484
+ var splits = [ " ", ">", "+", "~" ], scoped = selector, attrName = "[" + scopeSelector + "]";
4485
+ splits.forEach(function(sep) {
4486
+ var parts = scoped.split(sep);
4487
+ scoped = parts.map(function(p) {
4488
+ var t = p.trim().replace(polyfillHostRe, "");
4489
+ if (t && splits.indexOf(t) < 0 && t.indexOf(attrName) < 0) {
4490
+ p = t.replace(/([^:]*)(:*)(.*)/, "$1" + attrName + "$2$3");
4491
+ }
4492
+ return p;
4493
+ }).join(sep);
4494
+ });
4495
+ return scoped;
4496
+ },
4497
+ insertPolyfillHostInCssText: function(selector) {
4498
+ return selector.replace(colonHostContextRe, polyfillHostContext).replace(colonHostRe, polyfillHost);
4499
+ },
4500
+ propertiesFromRule: function(rule) {
4501
+ var cssText = rule.style.cssText;
4502
+ if (rule.style.content && !rule.style.content.match(/['"]+|attr/)) {
4503
+ cssText = cssText.replace(/content:[^;]*;/g, "content: '" + rule.style.content + "';");
4504
+ }
4505
+ var style = rule.style;
4506
+ for (var i in style) {
4507
+ if (style[i] === "initial") {
4508
+ cssText += i + ": initial; ";
4509
+ }
4510
+ }
4511
+ return cssText;
4512
+ },
4513
+ replaceTextInStyles: function(styles, action) {
4514
+ if (styles && action) {
4515
+ if (!(styles instanceof Array)) {
4516
+ styles = [ styles ];
4517
+ }
4518
+ Array.prototype.forEach.call(styles, function(s) {
4519
+ s.textContent = action.call(this, s.textContent);
4520
+ }, this);
4521
+ }
4522
+ },
4523
+ addCssToDocument: function(cssText, name) {
4524
+ if (cssText.match("@import")) {
4525
+ addOwnSheet(cssText, name);
4526
+ } else {
4527
+ addCssToDocument(cssText);
4528
+ }
4529
+ }
4530
+ };
4531
+ 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 = ")(?:\\((" + "(?:\\([^)(]*\\)|[^)(]*)+?" + ")\\))?([^,{]*)";
4532
+ 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 ];
4533
+ function stylesToCssText(styles, preserveComments) {
4534
+ var cssText = "";
4535
+ Array.prototype.forEach.call(styles, function(s) {
4536
+ cssText += s.textContent + "\n\n";
4537
+ });
4538
+ if (!preserveComments) {
4539
+ cssText = cssText.replace(cssCommentRe, "");
4540
+ }
4541
+ return cssText;
4542
+ }
4543
+ function cssTextToStyle(cssText) {
4544
+ var style = document.createElement("style");
4545
+ style.textContent = cssText;
4546
+ return style;
4547
+ }
4548
+ function cssToRules(cssText) {
4549
+ var style = cssTextToStyle(cssText);
4550
+ document.head.appendChild(style);
4551
+ var rules = [];
4552
+ if (style.sheet) {
4553
+ try {
4554
+ rules = style.sheet.cssRules;
4555
+ } catch (e) {}
4556
+ } else {
4557
+ console.warn("sheet not found", style);
4558
+ }
4559
+ style.parentNode.removeChild(style);
4560
+ return rules;
4561
+ }
4562
+ var frame = document.createElement("iframe");
4563
+ frame.style.display = "none";
4564
+ function initFrame() {
4565
+ frame.initialized = true;
4566
+ document.body.appendChild(frame);
4567
+ var doc = frame.contentDocument;
4568
+ var base = doc.createElement("base");
4569
+ base.href = document.baseURI;
4570
+ doc.head.appendChild(base);
4571
+ }
4572
+ function inFrame(fn) {
4573
+ if (!frame.initialized) {
4574
+ initFrame();
4575
+ }
4576
+ document.body.appendChild(frame);
4577
+ fn(frame.contentDocument);
4578
+ document.body.removeChild(frame);
4579
+ }
4580
+ var isChrome = navigator.userAgent.match("Chrome");
4581
+ function withCssRules(cssText, callback) {
4582
+ if (!callback) {
4583
+ return;
4584
+ }
4585
+ var rules;
4586
+ if (cssText.match("@import") && isChrome) {
4587
+ var style = cssTextToStyle(cssText);
4588
+ inFrame(function(doc) {
4589
+ doc.head.appendChild(style.impl);
4590
+ rules = Array.prototype.slice.call(style.sheet.cssRules, 0);
4591
+ callback(rules);
4592
+ });
4593
+ } else {
4594
+ rules = cssToRules(cssText);
4595
+ callback(rules);
4596
+ }
4597
+ }
4598
+ function rulesToCss(cssRules) {
4599
+ for (var i = 0, css = []; i < cssRules.length; i++) {
4600
+ css.push(cssRules[i].cssText);
4601
+ }
4602
+ return css.join("\n\n");
4603
+ }
4604
+ function addCssToDocument(cssText) {
4605
+ if (cssText) {
4606
+ getSheet().appendChild(document.createTextNode(cssText));
4607
+ }
4608
+ }
4609
+ function addOwnSheet(cssText, name) {
4610
+ var style = cssTextToStyle(cssText);
4611
+ style.setAttribute(name, "");
4612
+ style.setAttribute(SHIMMED_ATTRIBUTE, "");
4613
+ document.head.appendChild(style);
4614
+ }
4615
+ var SHIM_ATTRIBUTE = "shim-shadowdom";
4616
+ var SHIMMED_ATTRIBUTE = "shim-shadowdom-css";
4617
+ var NO_SHIM_ATTRIBUTE = "no-shim";
4618
+ var sheet;
4619
+ function getSheet() {
4620
+ if (!sheet) {
4621
+ sheet = document.createElement("style");
4622
+ sheet.setAttribute(SHIMMED_ATTRIBUTE, "");
4623
+ sheet[SHIMMED_ATTRIBUTE] = true;
4624
+ }
4625
+ return sheet;
4626
+ }
4627
+ if (window.ShadowDOMPolyfill) {
4628
+ addCssToDocument("style { display: none !important; }\n");
4629
+ var doc = ShadowDOMPolyfill.wrap(document);
4630
+ var head = doc.querySelector("head");
4631
+ head.insertBefore(getSheet(), head.childNodes[0]);
4632
+ document.addEventListener("DOMContentLoaded", function() {
4633
+ var urlResolver = scope.urlResolver;
4634
+ if (window.HTMLImports && !HTMLImports.useNative) {
4635
+ var SHIM_SHEET_SELECTOR = "link[rel=stylesheet]" + "[" + SHIM_ATTRIBUTE + "]";
4636
+ var SHIM_STYLE_SELECTOR = "style[" + SHIM_ATTRIBUTE + "]";
4637
+ HTMLImports.importer.documentPreloadSelectors += "," + SHIM_SHEET_SELECTOR;
4638
+ HTMLImports.importer.importsPreloadSelectors += "," + SHIM_SHEET_SELECTOR;
4639
+ HTMLImports.parser.documentSelectors = [ HTMLImports.parser.documentSelectors, SHIM_SHEET_SELECTOR, SHIM_STYLE_SELECTOR ].join(",");
4640
+ var originalParseGeneric = HTMLImports.parser.parseGeneric;
4641
+ HTMLImports.parser.parseGeneric = function(elt) {
4642
+ if (elt[SHIMMED_ATTRIBUTE]) {
4643
+ return;
4644
+ }
4645
+ var style = elt.__importElement || elt;
4646
+ if (!style.hasAttribute(SHIM_ATTRIBUTE)) {
4647
+ originalParseGeneric.call(this, elt);
4648
+ return;
4649
+ }
4650
+ if (elt.__resource) {
4651
+ style = elt.ownerDocument.createElement("style");
4652
+ style.textContent = elt.__resource;
4653
+ }
4654
+ HTMLImports.path.resolveUrlsInStyle(style);
4655
+ style.textContent = ShadowCSS.shimStyle(style);
4656
+ style.removeAttribute(SHIM_ATTRIBUTE, "");
4657
+ style.setAttribute(SHIMMED_ATTRIBUTE, "");
4658
+ style[SHIMMED_ATTRIBUTE] = true;
4659
+ if (style.parentNode !== head) {
4660
+ if (elt.parentNode === head) {
4661
+ head.replaceChild(style, elt);
4662
+ } else {
4663
+ this.addElementToDocument(style);
4664
+ }
4665
+ }
4666
+ style.__importParsed = true;
4667
+ this.markParsingComplete(elt);
4668
+ this.parseNext();
4669
+ };
4670
+ var hasResource = HTMLImports.parser.hasResource;
4671
+ HTMLImports.parser.hasResource = function(node) {
4672
+ if (node.localName === "link" && node.rel === "stylesheet" && node.hasAttribute(SHIM_ATTRIBUTE)) {
4673
+ return node.__resource;
4674
+ } else {
4675
+ return hasResource.call(this, node);
4676
+ }
4677
+ };
4678
+ }
4679
+ });
4680
+ }
4681
+ scope.ShadowCSS = ShadowCSS;
4682
+ })(window.WebComponents);
4683
+}
4684
+
4685
+(function(scope) {
4686
+ if (window.ShadowDOMPolyfill) {
4687
+ window.wrap = ShadowDOMPolyfill.wrapIfNeeded;
4688
+ window.unwrap = ShadowDOMPolyfill.unwrapIfNeeded;
4689
+ } else {
4690
+ window.wrap = window.unwrap = function(n) {
4691
+ return n;
4692
+ };
4693
+ }
4694
+})(window.WebComponents);
4695
+
4696
+(function(global) {
4697
+ var registrationsTable = new WeakMap();
4698
+ var setImmediate;
4699
+ if (/Trident/.test(navigator.userAgent)) {
4700
+ setImmediate = setTimeout;
4701
+ } else if (window.setImmediate) {
4702
+ setImmediate = window.setImmediate;
4703
+ } else {
4704
+ var setImmediateQueue = [];
4705
+ var sentinel = String(Math.random());
4706
+ window.addEventListener("message", function(e) {
4707
+ if (e.data === sentinel) {
4708
+ var queue = setImmediateQueue;
4709
+ setImmediateQueue = [];
4710
+ queue.forEach(function(func) {
4711
+ func();
4712
+ });
4713
+ }
4714
+ });
4715
+ setImmediate = function(func) {
4716
+ setImmediateQueue.push(func);
4717
+ window.postMessage(sentinel, "*");
4718
+ };
4719
+ }
4720
+ var isScheduled = false;
4721
+ var scheduledObservers = [];
4722
+ function scheduleCallback(observer) {
4723
+ scheduledObservers.push(observer);
4724
+ if (!isScheduled) {
4725
+ isScheduled = true;
4726
+ setImmediate(dispatchCallbacks);
4727
+ }
4728
+ }
4729
+ function wrapIfNeeded(node) {
4730
+ return window.ShadowDOMPolyfill && window.ShadowDOMPolyfill.wrapIfNeeded(node) || node;
4731
+ }
4732
+ function dispatchCallbacks() {
4733
+ isScheduled = false;
4734
+ var observers = scheduledObservers;
4735
+ scheduledObservers = [];
4736
+ observers.sort(function(o1, o2) {
4737
+ return o1.uid_ - o2.uid_;
4738
+ });
4739
+ var anyNonEmpty = false;
4740
+ observers.forEach(function(observer) {
4741
+ var queue = observer.takeRecords();
4742
+ removeTransientObserversFor(observer);
4743
+ if (queue.length) {
4744
+ observer.callback_(queue, observer);
4745
+ anyNonEmpty = true;
4746
+ }
4747
+ });
4748
+ if (anyNonEmpty) dispatchCallbacks();
4749
+ }
4750
+ function removeTransientObserversFor(observer) {
4751
+ observer.nodes_.forEach(function(node) {
4752
+ var registrations = registrationsTable.get(node);
4753
+ if (!registrations) return;
4754
+ registrations.forEach(function(registration) {
4755
+ if (registration.observer === observer) registration.removeTransientObservers();
4756
+ });
4757
+ });
4758
+ }
4759
+ function forEachAncestorAndObserverEnqueueRecord(target, callback) {
4760
+ for (var node = target; node; node = node.parentNode) {
4761
+ var registrations = registrationsTable.get(node);
4762
+ if (registrations) {
4763
+ for (var j = 0; j < registrations.length; j++) {
4764
+ var registration = registrations[j];
4765
+ var options = registration.options;
4766
+ if (node !== target && !options.subtree) continue;
4767
+ var record = callback(options);
4768
+ if (record) registration.enqueue(record);
4769
+ }
4770
+ }
4771
+ }
4772
+ }
4773
+ var uidCounter = 0;
4774
+ function JsMutationObserver(callback) {
4775
+ this.callback_ = callback;
4776
+ this.nodes_ = [];
4777
+ this.records_ = [];
4778
+ this.uid_ = ++uidCounter;
4779
+ }
4780
+ JsMutationObserver.prototype = {
4781
+ observe: function(target, options) {
4782
+ target = wrapIfNeeded(target);
4783
+ if (!options.childList && !options.attributes && !options.characterData || options.attributeOldValue && !options.attributes || options.attributeFilter && options.attributeFilter.length && !options.attributes || options.characterDataOldValue && !options.characterData) {
4784
+ throw new SyntaxError();
4785
+ }
4786
+ var registrations = registrationsTable.get(target);
4787
+ if (!registrations) registrationsTable.set(target, registrations = []);
4788
+ var registration;
4789
+ for (var i = 0; i < registrations.length; i++) {
4790
+ if (registrations[i].observer === this) {
4791
+ registration = registrations[i];
4792
+ registration.removeListeners();
4793
+ registration.options = options;
4794
+ break;
4795
+ }
4796
+ }
4797
+ if (!registration) {
4798
+ registration = new Registration(this, target, options);
4799
+ registrations.push(registration);
4800
+ this.nodes_.push(target);
4801
+ }
4802
+ registration.addListeners();
4803
+ },
4804
+ disconnect: function() {
4805
+ this.nodes_.forEach(function(node) {
4806
+ var registrations = registrationsTable.get(node);
4807
+ for (var i = 0; i < registrations.length; i++) {
4808
+ var registration = registrations[i];
4809
+ if (registration.observer === this) {
4810
+ registration.removeListeners();
4811
+ registrations.splice(i, 1);
4812
+ break;
4813
+ }
4814
+ }
4815
+ }, this);
4816
+ this.records_ = [];
4817
+ },
4818
+ takeRecords: function() {
4819
+ var copyOfRecords = this.records_;
4820
+ this.records_ = [];
4821
+ return copyOfRecords;
4822
+ }
4823
+ };
4824
+ function MutationRecord(type, target) {
4825
+ this.type = type;
4826
+ this.target = target;
4827
+ this.addedNodes = [];
4828
+ this.removedNodes = [];
4829
+ this.previousSibling = null;
4830
+ this.nextSibling = null;
4831
+ this.attributeName = null;
4832
+ this.attributeNamespace = null;
4833
+ this.oldValue = null;
4834
+ }
4835
+ function copyMutationRecord(original) {
4836
+ var record = new MutationRecord(original.type, original.target);
4837
+ record.addedNodes = original.addedNodes.slice();
4838
+ record.removedNodes = original.removedNodes.slice();
4839
+ record.previousSibling = original.previousSibling;
4840
+ record.nextSibling = original.nextSibling;
4841
+ record.attributeName = original.attributeName;
4842
+ record.attributeNamespace = original.attributeNamespace;
4843
+ record.oldValue = original.oldValue;
4844
+ return record;
4845
+ }
4846
+ var currentRecord, recordWithOldValue;
4847
+ function getRecord(type, target) {
4848
+ return currentRecord = new MutationRecord(type, target);
4849
+ }
4850
+ function getRecordWithOldValue(oldValue) {
4851
+ if (recordWithOldValue) return recordWithOldValue;
4852
+ recordWithOldValue = copyMutationRecord(currentRecord);
4853
+ recordWithOldValue.oldValue = oldValue;
4854
+ return recordWithOldValue;
4855
+ }
4856
+ function clearRecords() {
4857
+ currentRecord = recordWithOldValue = undefined;
4858
+ }
4859
+ function recordRepresentsCurrentMutation(record) {
4860
+ return record === recordWithOldValue || record === currentRecord;
4861
+ }
4862
+ function selectRecord(lastRecord, newRecord) {
4863
+ if (lastRecord === newRecord) return lastRecord;
4864
+ if (recordWithOldValue && recordRepresentsCurrentMutation(lastRecord)) return recordWithOldValue;
4865
+ return null;
4866
+ }
4867
+ function Registration(observer, target, options) {
4868
+ this.observer = observer;
4869
+ this.target = target;
4870
+ this.options = options;
4871
+ this.transientObservedNodes = [];
4872
+ }
4873
+ Registration.prototype = {
4874
+ enqueue: function(record) {
4875
+ var records = this.observer.records_;
4876
+ var length = records.length;
4877
+ if (records.length > 0) {
4878
+ var lastRecord = records[length - 1];
4879
+ var recordToReplaceLast = selectRecord(lastRecord, record);
4880
+ if (recordToReplaceLast) {
4881
+ records[length - 1] = recordToReplaceLast;
4882
+ return;
4883
+ }
4884
+ } else {
4885
+ scheduleCallback(this.observer);
4886
+ }
4887
+ records[length] = record;
4888
+ },
4889
+ addListeners: function() {
4890
+ this.addListeners_(this.target);
4891
+ },
4892
+ addListeners_: function(node) {
4893
+ var options = this.options;
4894
+ if (options.attributes) node.addEventListener("DOMAttrModified", this, true);
4895
+ if (options.characterData) node.addEventListener("DOMCharacterDataModified", this, true);
4896
+ if (options.childList) node.addEventListener("DOMNodeInserted", this, true);
4897
+ if (options.childList || options.subtree) node.addEventListener("DOMNodeRemoved", this, true);
4898
+ },
4899
+ removeListeners: function() {
4900
+ this.removeListeners_(this.target);
4901
+ },
4902
+ removeListeners_: function(node) {
4903
+ var options = this.options;
4904
+ if (options.attributes) node.removeEventListener("DOMAttrModified", this, true);
4905
+ if (options.characterData) node.removeEventListener("DOMCharacterDataModified", this, true);
4906
+ if (options.childList) node.removeEventListener("DOMNodeInserted", this, true);
4907
+ if (options.childList || options.subtree) node.removeEventListener("DOMNodeRemoved", this, true);
4908
+ },
4909
+ addTransientObserver: function(node) {
4910
+ if (node === this.target) return;
4911
+ this.addListeners_(node);
4912
+ this.transientObservedNodes.push(node);
4913
+ var registrations = registrationsTable.get(node);
4914
+ if (!registrations) registrationsTable.set(node, registrations = []);
4915
+ registrations.push(this);
4916
+ },
4917
+ removeTransientObservers: function() {
4918
+ var transientObservedNodes = this.transientObservedNodes;
4919
+ this.transientObservedNodes = [];
4920
+ transientObservedNodes.forEach(function(node) {
4921
+ this.removeListeners_(node);
4922
+ var registrations = registrationsTable.get(node);
4923
+ for (var i = 0; i < registrations.length; i++) {
4924
+ if (registrations[i] === this) {
4925
+ registrations.splice(i, 1);
4926
+ break;
4927
+ }
4928
+ }
4929
+ }, this);
4930
+ },
4931
+ handleEvent: function(e) {
4932
+ e.stopImmediatePropagation();
4933
+ switch (e.type) {
4934
+ case "DOMAttrModified":
4935
+ var name = e.attrName;
4936
+ var namespace = e.relatedNode.namespaceURI;
4937
+ var target = e.target;
4938
+ var record = new getRecord("attributes", target);
4939
+ record.attributeName = name;
4940
+ record.attributeNamespace = namespace;
4941
+ var oldValue = e.attrChange === MutationEvent.ADDITION ? null : e.prevValue;
4942
+ forEachAncestorAndObserverEnqueueRecord(target, function(options) {
4943
+ if (!options.attributes) return;
4944
+ if (options.attributeFilter && options.attributeFilter.length && options.attributeFilter.indexOf(name) === -1 && options.attributeFilter.indexOf(namespace) === -1) {
4945
+ return;
4946
+ }
4947
+ if (options.attributeOldValue) return getRecordWithOldValue(oldValue);
4948
+ return record;
4949
+ });
4950
+ break;
4951
+
4952
+ case "DOMCharacterDataModified":
4953
+ var target = e.target;
4954
+ var record = getRecord("characterData", target);
4955
+ var oldValue = e.prevValue;
4956
+ forEachAncestorAndObserverEnqueueRecord(target, function(options) {
4957
+ if (!options.characterData) return;
4958
+ if (options.characterDataOldValue) return getRecordWithOldValue(oldValue);
4959
+ return record;
4960
+ });
4961
+ break;
4962
+
4963
+ case "DOMNodeRemoved":
4964
+ this.addTransientObserver(e.target);
4965
+
4966
+ case "DOMNodeInserted":
4967
+ var target = e.relatedNode;
4968
+ var changedNode = e.target;
4969
+ var addedNodes, removedNodes;
4970
+ if (e.type === "DOMNodeInserted") {
4971
+ addedNodes = [ changedNode ];
4972
+ removedNodes = [];
4973
+ } else {
4974
+ addedNodes = [];
4975
+ removedNodes = [ changedNode ];
4976
+ }
4977
+ var previousSibling = changedNode.previousSibling;
4978
+ var nextSibling = changedNode.nextSibling;
4979
+ var record = getRecord("childList", target);
4980
+ record.addedNodes = addedNodes;
4981
+ record.removedNodes = removedNodes;
4982
+ record.previousSibling = previousSibling;
4983
+ record.nextSibling = nextSibling;
4984
+ forEachAncestorAndObserverEnqueueRecord(target, function(options) {
4985
+ if (!options.childList) return;
4986
+ return record;
4987
+ });
4988
+ }
4989
+ clearRecords();
4990
+ }
4991
+ };
4992
+ global.JsMutationObserver = JsMutationObserver;
4993
+ if (!global.MutationObserver) global.MutationObserver = JsMutationObserver;
4994
+})(this);
4995
+
4996
+window.HTMLImports = window.HTMLImports || {
4997
+ flags: {}
4998
+};
4999
+
This file is too large to show in full.