polymer-rails 1.1.5 → 1.2.0

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