webcomponentsjs-rails 0.7.12

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