Guest User

Untitled

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