| Index: packages/web_components/lib/webcomponents.js
|
| diff --git a/packages/web_components/lib/webcomponents.js b/packages/web_components/lib/webcomponents.js
|
| index 8e6523a8fd8c52a0263c1c1345f5eb25290c594f..8e9feb24c2ae1323c05ac9b2175988e786bdff94 100644
|
| --- a/packages/web_components/lib/webcomponents.js
|
| +++ b/packages/web_components/lib/webcomponents.js
|
| @@ -7,17 +7,21 @@
|
| * Code distributed by Google as part of the polymer project is also
|
| * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
| */
|
| -// @version 0.5.1
|
| -window.WebComponents = window.WebComponents || {};
|
| -
|
| -(function(scope) {
|
| - var flags = scope.flags || {};
|
| +// @version 0.7.21
|
| +(function() {
|
| + window.WebComponents = window.WebComponents || {
|
| + flags: {}
|
| + };
|
| var file = "webcomponents.js";
|
| var script = document.querySelector('script[src*="' + file + '"]');
|
| + var flags = {};
|
| if (!flags.noOpts) {
|
| - location.search.slice(1).split("&").forEach(function(o) {
|
| - o = o.split("=");
|
| - o[0] && (flags[o[0]] = o[1] || true);
|
| + location.search.slice(1).split("&").forEach(function(option) {
|
| + var parts = option.split("=");
|
| + var match;
|
| + if (parts[0] && (match = parts[0].match(/wc-(.+)/))) {
|
| + flags[match[1]] = parts[1] || true;
|
| + }
|
| });
|
| if (script) {
|
| for (var i = 0, a; a = script.attributes[i]; i++) {
|
| @@ -26,7 +30,7 @@ window.WebComponents = window.WebComponents || {};
|
| }
|
| }
|
| }
|
| - if (flags.log) {
|
| + if (flags.log && flags.log.split) {
|
| var parts = flags.log.split(",");
|
| flags.log = {};
|
| parts.forEach(function(f) {
|
| @@ -48,8 +52,8 @@ window.WebComponents = window.WebComponents || {};
|
| };
|
| window.CustomElements.flags.register = flags.register;
|
| }
|
| - scope.flags = flags;
|
| -})(WebComponents);
|
| + WebComponents.flags = flags;
|
| +})();
|
|
|
| if (WebComponents.flags.shadow) {
|
| if (typeof WeakMap === "undefined") {
|
| @@ -155,13 +159,20 @@ if (WebComponents.flags.shadow) {
|
| defineProperty(object, name, nonEnumerableDataDescriptor);
|
| }
|
| getOwnPropertyNames(window);
|
| - function getWrapperConstructor(node) {
|
| + function getWrapperConstructor(node, opt_instance) {
|
| var nativePrototype = node.__proto__ || Object.getPrototypeOf(node);
|
| + if (isFirefox) {
|
| + try {
|
| + getOwnPropertyNames(nativePrototype);
|
| + } catch (error) {
|
| + nativePrototype = nativePrototype.__proto__;
|
| + }
|
| + }
|
| var wrapperConstructor = constructorTable.get(nativePrototype);
|
| if (wrapperConstructor) return wrapperConstructor;
|
| var parentWrapperConstructor = getWrapperConstructor(nativePrototype);
|
| var GeneratedWrapper = createWrapperConstructor(parentWrapperConstructor);
|
| - registerInternal(nativePrototype, GeneratedWrapper, node);
|
| + registerInternal(nativePrototype, GeneratedWrapper, opt_instance);
|
| return GeneratedWrapper;
|
| }
|
| function addForwardingProperties(nativePrototype, wrapperPrototype) {
|
| @@ -181,7 +192,7 @@ if (WebComponents.flags.shadow) {
|
| return /^on[a-z]+$/.test(name);
|
| }
|
| function isIdentifierName(name) {
|
| - return /^\w[a-zA-Z_0-9]*$/.test(name);
|
| + return /^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(name);
|
| }
|
| function getGetter(name) {
|
| return hasEval && isIdentifierName(name) ? new Function("return this.__impl4cf1e782hg__." + name) : function() {
|
| @@ -221,8 +232,10 @@ if (WebComponents.flags.shadow) {
|
| }
|
| var descriptor = getDescriptor(source, name);
|
| var getter, setter;
|
| - if (allowMethod && typeof descriptor.value === "function") {
|
| - target[name] = getMethod(name);
|
| + if (typeof descriptor.value === "function") {
|
| + if (allowMethod) {
|
| + target[name] = getMethod(name);
|
| + }
|
| continue;
|
| }
|
| var isEvent = isEventHandlerName(name);
|
| @@ -230,15 +243,19 @@ if (WebComponents.flags.shadow) {
|
| if (descriptor.writable || descriptor.set || isBrokenSafari) {
|
| if (isEvent) setter = scope.getEventHandlerSetter(name); else setter = getSetter(name);
|
| }
|
| + var configurable = isBrokenSafari || descriptor.configurable;
|
| defineProperty(target, name, {
|
| get: getter,
|
| set: setter,
|
| - configurable: descriptor.configurable,
|
| + configurable: configurable,
|
| enumerable: descriptor.enumerable
|
| });
|
| }
|
| }
|
| function register(nativeConstructor, wrapperConstructor, opt_instance) {
|
| + if (nativeConstructor == null) {
|
| + return;
|
| + }
|
| var nativePrototype = nativeConstructor.prototype;
|
| registerInternal(nativePrototype, wrapperConstructor, opt_instance);
|
| mixinStatics(wrapperConstructor, nativeConstructor);
|
| @@ -281,7 +298,11 @@ if (WebComponents.flags.shadow) {
|
| function wrap(impl) {
|
| if (impl === null) return null;
|
| assert(isNative(impl));
|
| - return impl.__wrapper8e3dd93a60__ || (impl.__wrapper8e3dd93a60__ = new (getWrapperConstructor(impl))(impl));
|
| + var wrapper = impl.__wrapper8e3dd93a60__;
|
| + if (wrapper != null) {
|
| + return wrapper;
|
| + }
|
| + return impl.__wrapper8e3dd93a60__ = new (getWrapperConstructor(impl, impl))(impl);
|
| }
|
| function unwrap(wrapper) {
|
| if (wrapper === null) return null;
|
| @@ -331,11 +352,13 @@ if (WebComponents.flags.shadow) {
|
| });
|
| });
|
| }
|
| + scope.addForwardingProperties = addForwardingProperties;
|
| scope.assert = assert;
|
| scope.constructorTable = constructorTable;
|
| scope.defineGetter = defineGetter;
|
| scope.defineWrapGetter = defineWrapGetter;
|
| scope.forwardMethodsToWrapper = forwardMethodsToWrapper;
|
| + scope.isIdentifierName = isIdentifierName;
|
| scope.isWrapper = isWrapper;
|
| scope.isWrapperFor = isWrapperFor;
|
| scope.mixin = mixin;
|
| @@ -1137,6 +1160,24 @@ if (WebComponents.flags.shadow) {
|
| stopImmediatePropagationTable.set(this, true);
|
| }
|
| };
|
| + var supportsDefaultPrevented = function() {
|
| + var e = document.createEvent("Event");
|
| + e.initEvent("test", true, true);
|
| + e.preventDefault();
|
| + return e.defaultPrevented;
|
| + }();
|
| + if (!supportsDefaultPrevented) {
|
| + Event.prototype.preventDefault = function() {
|
| + if (!this.cancelable) return;
|
| + unsafeUnwrap(this).preventDefault();
|
| + Object.defineProperty(this, "defaultPrevented", {
|
| + get: function() {
|
| + return true;
|
| + },
|
| + configurable: true
|
| + });
|
| + };
|
| + }
|
| registerWrapper(OriginalEvent, Event, document.createEvent("Event"));
|
| function unwrapOptions(options) {
|
| if (!options || !options.relatedTarget) return options;
|
| @@ -1756,11 +1797,12 @@ if (WebComponents.flags.shadow) {
|
| var OriginalDocumentFragment = window.DocumentFragment;
|
| var originalAppendChild = OriginalNode.prototype.appendChild;
|
| var originalCompareDocumentPosition = OriginalNode.prototype.compareDocumentPosition;
|
| + var originalIsEqualNode = OriginalNode.prototype.isEqualNode;
|
| var originalInsertBefore = OriginalNode.prototype.insertBefore;
|
| var originalRemoveChild = OriginalNode.prototype.removeChild;
|
| var originalReplaceChild = OriginalNode.prototype.replaceChild;
|
| - var isIe = /Trident/.test(navigator.userAgent);
|
| - var removeChildOriginalHelper = isIe ? function(parent, child) {
|
| + var isIEOrEdge = /Trident|Edge/.test(navigator.userAgent);
|
| + var removeChildOriginalHelper = isIEOrEdge ? function(parent, child) {
|
| try {
|
| originalRemoveChild.call(parent, child);
|
| } catch (ex) {
|
| @@ -1984,6 +2026,9 @@ if (WebComponents.flags.shadow) {
|
| compareDocumentPosition: function(otherNode) {
|
| return originalCompareDocumentPosition.call(unsafeUnwrap(this), unwrapIfNeeded(otherNode));
|
| },
|
| + isEqualNode: function(otherNode) {
|
| + return originalIsEqualNode.call(unsafeUnwrap(this), unwrapIfNeeded(otherNode));
|
| + },
|
| normalize: function() {
|
| var nodes = snapshotNodeList(this.childNodes);
|
| var remNodes = [];
|
| @@ -1992,7 +2037,7 @@ if (WebComponents.flags.shadow) {
|
| for (var i = 0, n; i < nodes.length; i++) {
|
| n = nodes[i];
|
| if (n.nodeType === Node.TEXT_NODE) {
|
| - if (!modNode && !n.data.length) this.removeNode(n); else if (!modNode) modNode = n; else {
|
| + if (!modNode && !n.data.length) this.removeChild(n); else if (!modNode) modNode = n; else {
|
| s += n.data;
|
| remNodes.push(n);
|
| }
|
| @@ -2060,7 +2105,10 @@ if (WebComponents.flags.shadow) {
|
| return index;
|
| }
|
| function shimSelector(selector) {
|
| - return String(selector).replace(/\/deep\//g, " ");
|
| + return String(selector).replace(/\/deep\/|::shadow|>>>/g, " ");
|
| + }
|
| + function shimMatchesSelector(selector) {
|
| + return String(selector).replace(/:host\(([^\s]+)\)/g, "$1").replace(/([^\s]):host/g, "$1").replace(":host", "*").replace(/\^|\/shadow\/|\/shadow-deep\/|::shadow|\/deep\/|::content|>>>/g, " ");
|
| }
|
| function findOne(node, selector) {
|
| var m, el = node.firstElementChild;
|
| @@ -2151,6 +2199,12 @@ if (WebComponents.flags.shadow) {
|
| return result;
|
| }
|
| };
|
| + var MatchesInterface = {
|
| + matches: function(selector) {
|
| + selector = shimMatchesSelector(selector);
|
| + return scope.originalMatches.call(unsafeUnwrap(this), selector);
|
| + }
|
| + };
|
| function getElementsByTagNameFiltered(p, index, result, localName, lowercase) {
|
| var target = unsafeUnwrap(this);
|
| var list;
|
| @@ -2205,6 +2259,7 @@ if (WebComponents.flags.shadow) {
|
| };
|
| scope.GetElementsByInterface = GetElementsByInterface;
|
| scope.SelectorsInterface = SelectorsInterface;
|
| + scope.MatchesInterface = MatchesInterface;
|
| })(window.ShadowDOMPolyfill);
|
| (function(scope) {
|
| "use strict";
|
| @@ -2257,7 +2312,14 @@ if (WebComponents.flags.shadow) {
|
| return backwardsElement(this.previousSibling);
|
| }
|
| };
|
| + var NonElementParentNodeInterface = {
|
| + getElementById: function(id) {
|
| + if (/[ \t\n\r\f]/.test(id)) return null;
|
| + return this.querySelector('[id="' + id + '"]');
|
| + }
|
| + };
|
| scope.ChildNodeInterface = ChildNodeInterface;
|
| + scope.NonElementParentNodeInterface = NonElementParentNodeInterface;
|
| scope.ParentNodeInterface = ParentNodeInterface;
|
| })(window.ShadowDOMPolyfill);
|
| (function(scope) {
|
| @@ -2274,6 +2336,12 @@ if (WebComponents.flags.shadow) {
|
| }
|
| CharacterData.prototype = Object.create(Node.prototype);
|
| mixin(CharacterData.prototype, {
|
| + get nodeValue() {
|
| + return this.data;
|
| + },
|
| + set nodeValue(data) {
|
| + this.data = data;
|
| + },
|
| get textContent() {
|
| return this.data;
|
| },
|
| @@ -2327,53 +2395,59 @@ if (WebComponents.flags.shadow) {
|
| })(window.ShadowDOMPolyfill);
|
| (function(scope) {
|
| "use strict";
|
| - var setWrapper = scope.setWrapper;
|
| + if (!window.DOMTokenList) {
|
| + console.warn("Missing DOMTokenList prototype, please include a " + "compatible classList polyfill such as http://goo.gl/uTcepH.");
|
| + return;
|
| + }
|
| var unsafeUnwrap = scope.unsafeUnwrap;
|
| + var enqueueMutation = scope.enqueueMutation;
|
| + function getClass(el) {
|
| + return unsafeUnwrap(el).getAttribute("class");
|
| + }
|
| + function enqueueClassAttributeChange(el, oldValue) {
|
| + enqueueMutation(el, "attributes", {
|
| + name: "class",
|
| + namespace: null,
|
| + oldValue: oldValue
|
| + });
|
| + }
|
| function invalidateClass(el) {
|
| scope.invalidateRendererBasedOnAttribute(el, "class");
|
| }
|
| - function DOMTokenList(impl, ownerElement) {
|
| - setWrapper(impl, this);
|
| - this.ownerElement_ = ownerElement;
|
| - }
|
| - DOMTokenList.prototype = {
|
| - constructor: DOMTokenList,
|
| - get length() {
|
| - return unsafeUnwrap(this).length;
|
| - },
|
| - item: function(index) {
|
| - return unsafeUnwrap(this).item(index);
|
| - },
|
| - contains: function(token) {
|
| - return unsafeUnwrap(this).contains(token);
|
| - },
|
| - add: function() {
|
| - unsafeUnwrap(this).add.apply(unsafeUnwrap(this), arguments);
|
| - invalidateClass(this.ownerElement_);
|
| - },
|
| - remove: function() {
|
| - unsafeUnwrap(this).remove.apply(unsafeUnwrap(this), arguments);
|
| - invalidateClass(this.ownerElement_);
|
| - },
|
| - toggle: function(token) {
|
| - var rv = unsafeUnwrap(this).toggle.apply(unsafeUnwrap(this), arguments);
|
| - invalidateClass(this.ownerElement_);
|
| - return rv;
|
| - },
|
| - toString: function() {
|
| - return unsafeUnwrap(this).toString();
|
| + function changeClass(tokenList, method, args) {
|
| + var ownerElement = tokenList.ownerElement_;
|
| + if (ownerElement == null) {
|
| + return method.apply(tokenList, args);
|
| + }
|
| + var oldValue = getClass(ownerElement);
|
| + var retv = method.apply(tokenList, args);
|
| + if (getClass(ownerElement) !== oldValue) {
|
| + enqueueClassAttributeChange(ownerElement, oldValue);
|
| + invalidateClass(ownerElement);
|
| }
|
| + return retv;
|
| + }
|
| + var oldAdd = DOMTokenList.prototype.add;
|
| + DOMTokenList.prototype.add = function() {
|
| + changeClass(this, oldAdd, arguments);
|
| + };
|
| + var oldRemove = DOMTokenList.prototype.remove;
|
| + DOMTokenList.prototype.remove = function() {
|
| + changeClass(this, oldRemove, arguments);
|
| + };
|
| + var oldToggle = DOMTokenList.prototype.toggle;
|
| + DOMTokenList.prototype.toggle = function() {
|
| + return changeClass(this, oldToggle, arguments);
|
| };
|
| - scope.wrappers.DOMTokenList = DOMTokenList;
|
| })(window.ShadowDOMPolyfill);
|
| (function(scope) {
|
| "use strict";
|
| var ChildNodeInterface = scope.ChildNodeInterface;
|
| var GetElementsByInterface = scope.GetElementsByInterface;
|
| var Node = scope.wrappers.Node;
|
| - var DOMTokenList = scope.wrappers.DOMTokenList;
|
| var ParentNodeInterface = scope.ParentNodeInterface;
|
| var SelectorsInterface = scope.SelectorsInterface;
|
| + var MatchesInterface = scope.MatchesInterface;
|
| var addWrapNodeListMethod = scope.addWrapNodeListMethod;
|
| var enqueueMutation = scope.enqueueMutation;
|
| var mixin = scope.mixin;
|
| @@ -2428,13 +2502,13 @@ if (WebComponents.flags.shadow) {
|
| enqueAttributeChange(this, name, oldValue);
|
| invalidateRendererBasedOnAttribute(this, name);
|
| },
|
| - matches: function(selector) {
|
| - return originalMatches.call(unsafeUnwrap(this), selector);
|
| - },
|
| get classList() {
|
| var list = classListTable.get(this);
|
| if (!list) {
|
| - classListTable.set(this, list = new DOMTokenList(unsafeUnwrap(this).classList, this));
|
| + list = unsafeUnwrap(this).classList;
|
| + if (!list) return;
|
| + list.ownerElement_ = this;
|
| + classListTable.set(this, list);
|
| }
|
| return list;
|
| },
|
| @@ -2465,9 +2539,11 @@ if (WebComponents.flags.shadow) {
|
| mixin(Element.prototype, GetElementsByInterface);
|
| mixin(Element.prototype, ParentNodeInterface);
|
| mixin(Element.prototype, SelectorsInterface);
|
| + mixin(Element.prototype, MatchesInterface);
|
| registerWrapper(OriginalElement, Element, document.createElementNS(null, "x"));
|
| scope.invalidateRendererBasedOnAttribute = invalidateRendererBasedOnAttribute;
|
| scope.matchesNames = matchesNames;
|
| + scope.originalMatches = originalMatches;
|
| scope.wrappers.Element = Element;
|
| })(window.ShadowDOMPolyfill);
|
| (function(scope) {
|
| @@ -2519,6 +2595,12 @@ if (WebComponents.flags.shadow) {
|
| }
|
| var voidElements = makeSet([ "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr" ]);
|
| var plaintextParents = makeSet([ "style", "script", "xmp", "iframe", "noembed", "noframes", "plaintext", "noscript" ]);
|
| + var XHTML_NS = "http://www.w3.org/1999/xhtml";
|
| + function needsSelfClosingSlash(node) {
|
| + if (node.namespaceURI !== XHTML_NS) return true;
|
| + var doctype = node.ownerDocument.doctype;
|
| + return doctype && doctype.publicId && doctype.systemId;
|
| + }
|
| function getOuterHTML(node, parentNode) {
|
| switch (node.nodeType) {
|
| case Node.ELEMENT_NODE:
|
| @@ -2528,9 +2610,11 @@ if (WebComponents.flags.shadow) {
|
| for (var i = 0, attr; attr = attrs[i]; i++) {
|
| s += " " + attr.name + '="' + escapeAttr(attr.value) + '"';
|
| }
|
| - s += ">";
|
| - if (voidElements[tagName]) return s;
|
| - return s + getInnerHTML(node) + "</" + tagName + ">";
|
| + if (voidElements[tagName]) {
|
| + if (needsSelfClosingSlash(node)) s += "/";
|
| + return s + ">";
|
| + }
|
| + return s + ">" + getInnerHTML(node) + "</" + tagName + ">";
|
|
|
| case Node.TEXT_NODE:
|
| var data = node.data;
|
| @@ -2688,7 +2772,7 @@ if (WebComponents.flags.shadow) {
|
| enumerable: true
|
| });
|
| }
|
| - [ "getBoundingClientRect", "getClientRects", "scrollIntoView" ].forEach(methodRequiresRendering);
|
| + [ "focus", "getBoundingClientRect", "getClientRects", "scrollIntoView" ].forEach(methodRequiresRendering);
|
| registerWrapper(OriginalHTMLElement, HTMLElement, document.createElement("b"));
|
| scope.wrappers.HTMLElement = HTMLElement;
|
| scope.getInnerHTML = getInnerHTML;
|
| @@ -3095,16 +3179,29 @@ if (WebComponents.flags.shadow) {
|
| "use strict";
|
| var Element = scope.wrappers.Element;
|
| var HTMLElement = scope.wrappers.HTMLElement;
|
| - var registerObject = scope.registerObject;
|
| + var registerWrapper = scope.registerWrapper;
|
| + var defineWrapGetter = scope.defineWrapGetter;
|
| + var unsafeUnwrap = scope.unsafeUnwrap;
|
| + var wrap = scope.wrap;
|
| + var mixin = scope.mixin;
|
| var SVG_NS = "http://www.w3.org/2000/svg";
|
| + var OriginalSVGElement = window.SVGElement;
|
| var svgTitleElement = document.createElementNS(SVG_NS, "title");
|
| - var SVGTitleElement = registerObject(svgTitleElement);
|
| - var SVGElement = Object.getPrototypeOf(SVGTitleElement.prototype).constructor;
|
| if (!("classList" in svgTitleElement)) {
|
| var descr = Object.getOwnPropertyDescriptor(Element.prototype, "classList");
|
| Object.defineProperty(HTMLElement.prototype, "classList", descr);
|
| delete Element.prototype.classList;
|
| }
|
| + function SVGElement(node) {
|
| + Element.call(this, node);
|
| + }
|
| + SVGElement.prototype = Object.create(Element.prototype);
|
| + mixin(SVGElement.prototype, {
|
| + get ownerSVGElement() {
|
| + return wrap(unsafeUnwrap(this).ownerSVGElement);
|
| + }
|
| + });
|
| + registerWrapper(OriginalSVGElement, SVGElement, document.createElementNS(SVG_NS, "title"));
|
| scope.wrappers.SVGElement = SVGElement;
|
| })(window.ShadowDOMPolyfill);
|
| (function(scope) {
|
| @@ -3210,6 +3307,7 @@ if (WebComponents.flags.shadow) {
|
| })(window.ShadowDOMPolyfill);
|
| (function(scope) {
|
| "use strict";
|
| + var addForwardingProperties = scope.addForwardingProperties;
|
| var mixin = scope.mixin;
|
| var registerWrapper = scope.registerWrapper;
|
| var setWrapper = scope.setWrapper;
|
| @@ -3234,6 +3332,10 @@ if (WebComponents.flags.shadow) {
|
| unsafeUnwrap(this).texSubImage2D.apply(unsafeUnwrap(this), arguments);
|
| }
|
| });
|
| + var OriginalWebGLRenderingContextBase = Object.getPrototypeOf(OriginalWebGLRenderingContext.prototype);
|
| + if (OriginalWebGLRenderingContextBase !== Object.prototype) {
|
| + addForwardingProperties(OriginalWebGLRenderingContextBase, WebGLRenderingContext.prototype);
|
| + }
|
| var instanceProperties = /WebKit/.test(navigator.userAgent) ? {
|
| drawingBufferHeight: null,
|
| drawingBufferWidth: null
|
| @@ -3243,30 +3345,153 @@ if (WebComponents.flags.shadow) {
|
| })(window.ShadowDOMPolyfill);
|
| (function(scope) {
|
| "use strict";
|
| + var Node = scope.wrappers.Node;
|
| + var GetElementsByInterface = scope.GetElementsByInterface;
|
| + var NonElementParentNodeInterface = scope.NonElementParentNodeInterface;
|
| + var ParentNodeInterface = scope.ParentNodeInterface;
|
| + var SelectorsInterface = scope.SelectorsInterface;
|
| + var mixin = scope.mixin;
|
| + var registerObject = scope.registerObject;
|
| + var registerWrapper = scope.registerWrapper;
|
| + var OriginalDocumentFragment = window.DocumentFragment;
|
| + function DocumentFragment(node) {
|
| + Node.call(this, node);
|
| + }
|
| + DocumentFragment.prototype = Object.create(Node.prototype);
|
| + mixin(DocumentFragment.prototype, ParentNodeInterface);
|
| + mixin(DocumentFragment.prototype, SelectorsInterface);
|
| + mixin(DocumentFragment.prototype, GetElementsByInterface);
|
| + mixin(DocumentFragment.prototype, NonElementParentNodeInterface);
|
| + registerWrapper(OriginalDocumentFragment, DocumentFragment, document.createDocumentFragment());
|
| + scope.wrappers.DocumentFragment = DocumentFragment;
|
| + var Comment = registerObject(document.createComment(""));
|
| + scope.wrappers.Comment = Comment;
|
| + })(window.ShadowDOMPolyfill);
|
| + (function(scope) {
|
| + "use strict";
|
| + var DocumentFragment = scope.wrappers.DocumentFragment;
|
| + var TreeScope = scope.TreeScope;
|
| + var elementFromPoint = scope.elementFromPoint;
|
| + var getInnerHTML = scope.getInnerHTML;
|
| + var getTreeScope = scope.getTreeScope;
|
| + var mixin = scope.mixin;
|
| + var rewrap = scope.rewrap;
|
| + var setInnerHTML = scope.setInnerHTML;
|
| + var unsafeUnwrap = scope.unsafeUnwrap;
|
| + var unwrap = scope.unwrap;
|
| + var wrap = scope.wrap;
|
| + var shadowHostTable = new WeakMap();
|
| + var nextOlderShadowTreeTable = new WeakMap();
|
| + function ShadowRoot(hostWrapper) {
|
| + var node = unwrap(unsafeUnwrap(hostWrapper).ownerDocument.createDocumentFragment());
|
| + DocumentFragment.call(this, node);
|
| + rewrap(node, this);
|
| + var oldShadowRoot = hostWrapper.shadowRoot;
|
| + nextOlderShadowTreeTable.set(this, oldShadowRoot);
|
| + this.treeScope_ = new TreeScope(this, getTreeScope(oldShadowRoot || hostWrapper));
|
| + shadowHostTable.set(this, hostWrapper);
|
| + }
|
| + ShadowRoot.prototype = Object.create(DocumentFragment.prototype);
|
| + mixin(ShadowRoot.prototype, {
|
| + constructor: ShadowRoot,
|
| + get innerHTML() {
|
| + return getInnerHTML(this);
|
| + },
|
| + set innerHTML(value) {
|
| + setInnerHTML(this, value);
|
| + this.invalidateShadowRenderer();
|
| + },
|
| + get olderShadowRoot() {
|
| + return nextOlderShadowTreeTable.get(this) || null;
|
| + },
|
| + get host() {
|
| + return shadowHostTable.get(this) || null;
|
| + },
|
| + invalidateShadowRenderer: function() {
|
| + return shadowHostTable.get(this).invalidateShadowRenderer();
|
| + },
|
| + elementFromPoint: function(x, y) {
|
| + return elementFromPoint(this, this.ownerDocument, x, y);
|
| + },
|
| + getSelection: function() {
|
| + return document.getSelection();
|
| + },
|
| + get activeElement() {
|
| + var unwrappedActiveElement = unwrap(this).ownerDocument.activeElement;
|
| + if (!unwrappedActiveElement || !unwrappedActiveElement.nodeType) return null;
|
| + var activeElement = wrap(unwrappedActiveElement);
|
| + while (!this.contains(activeElement)) {
|
| + while (activeElement.parentNode) {
|
| + activeElement = activeElement.parentNode;
|
| + }
|
| + if (activeElement.host) {
|
| + activeElement = activeElement.host;
|
| + } else {
|
| + return null;
|
| + }
|
| + }
|
| + return activeElement;
|
| + }
|
| + });
|
| + scope.wrappers.ShadowRoot = ShadowRoot;
|
| + })(window.ShadowDOMPolyfill);
|
| + (function(scope) {
|
| + "use strict";
|
| var registerWrapper = scope.registerWrapper;
|
| var setWrapper = scope.setWrapper;
|
| var unsafeUnwrap = scope.unsafeUnwrap;
|
| var unwrap = scope.unwrap;
|
| var unwrapIfNeeded = scope.unwrapIfNeeded;
|
| var wrap = scope.wrap;
|
| + var getTreeScope = scope.getTreeScope;
|
| var OriginalRange = window.Range;
|
| + var ShadowRoot = scope.wrappers.ShadowRoot;
|
| + function getHost(node) {
|
| + var root = getTreeScope(node).root;
|
| + if (root instanceof ShadowRoot) {
|
| + return root.host;
|
| + }
|
| + return null;
|
| + }
|
| + function hostNodeToShadowNode(refNode, offset) {
|
| + if (refNode.shadowRoot) {
|
| + offset = Math.min(refNode.childNodes.length - 1, offset);
|
| + var child = refNode.childNodes[offset];
|
| + if (child) {
|
| + var insertionPoint = scope.getDestinationInsertionPoints(child);
|
| + if (insertionPoint.length > 0) {
|
| + var parentNode = insertionPoint[0].parentNode;
|
| + if (parentNode.nodeType == Node.ELEMENT_NODE) {
|
| + refNode = parentNode;
|
| + }
|
| + }
|
| + }
|
| + }
|
| + return refNode;
|
| + }
|
| + function shadowNodeToHostNode(node) {
|
| + node = wrap(node);
|
| + return getHost(node) || node;
|
| + }
|
| function Range(impl) {
|
| setWrapper(impl, this);
|
| }
|
| Range.prototype = {
|
| get startContainer() {
|
| - return wrap(unsafeUnwrap(this).startContainer);
|
| + return shadowNodeToHostNode(unsafeUnwrap(this).startContainer);
|
| },
|
| get endContainer() {
|
| - return wrap(unsafeUnwrap(this).endContainer);
|
| + return shadowNodeToHostNode(unsafeUnwrap(this).endContainer);
|
| },
|
| get commonAncestorContainer() {
|
| - return wrap(unsafeUnwrap(this).commonAncestorContainer);
|
| + return shadowNodeToHostNode(unsafeUnwrap(this).commonAncestorContainer);
|
| },
|
| setStart: function(refNode, offset) {
|
| + refNode = hostNodeToShadowNode(refNode, offset);
|
| unsafeUnwrap(this).setStart(unwrapIfNeeded(refNode), offset);
|
| },
|
| setEnd: function(refNode, offset) {
|
| + refNode = hostNodeToShadowNode(refNode, offset);
|
| unsafeUnwrap(this).setEnd(unwrapIfNeeded(refNode), offset);
|
| },
|
| setStartBefore: function(refNode) {
|
| @@ -3328,74 +3553,6 @@ if (WebComponents.flags.shadow) {
|
| })(window.ShadowDOMPolyfill);
|
| (function(scope) {
|
| "use strict";
|
| - var GetElementsByInterface = scope.GetElementsByInterface;
|
| - var ParentNodeInterface = scope.ParentNodeInterface;
|
| - var SelectorsInterface = scope.SelectorsInterface;
|
| - var mixin = scope.mixin;
|
| - var registerObject = scope.registerObject;
|
| - var DocumentFragment = registerObject(document.createDocumentFragment());
|
| - mixin(DocumentFragment.prototype, ParentNodeInterface);
|
| - mixin(DocumentFragment.prototype, SelectorsInterface);
|
| - mixin(DocumentFragment.prototype, GetElementsByInterface);
|
| - var Comment = registerObject(document.createComment(""));
|
| - scope.wrappers.Comment = Comment;
|
| - scope.wrappers.DocumentFragment = DocumentFragment;
|
| - })(window.ShadowDOMPolyfill);
|
| - (function(scope) {
|
| - "use strict";
|
| - var DocumentFragment = scope.wrappers.DocumentFragment;
|
| - var TreeScope = scope.TreeScope;
|
| - var elementFromPoint = scope.elementFromPoint;
|
| - var getInnerHTML = scope.getInnerHTML;
|
| - var getTreeScope = scope.getTreeScope;
|
| - var mixin = scope.mixin;
|
| - var rewrap = scope.rewrap;
|
| - var setInnerHTML = scope.setInnerHTML;
|
| - var unsafeUnwrap = scope.unsafeUnwrap;
|
| - var unwrap = scope.unwrap;
|
| - var shadowHostTable = new WeakMap();
|
| - var nextOlderShadowTreeTable = new WeakMap();
|
| - var spaceCharRe = /[ \t\n\r\f]/;
|
| - function ShadowRoot(hostWrapper) {
|
| - var node = unwrap(unsafeUnwrap(hostWrapper).ownerDocument.createDocumentFragment());
|
| - DocumentFragment.call(this, node);
|
| - rewrap(node, this);
|
| - var oldShadowRoot = hostWrapper.shadowRoot;
|
| - nextOlderShadowTreeTable.set(this, oldShadowRoot);
|
| - this.treeScope_ = new TreeScope(this, getTreeScope(oldShadowRoot || hostWrapper));
|
| - shadowHostTable.set(this, hostWrapper);
|
| - }
|
| - ShadowRoot.prototype = Object.create(DocumentFragment.prototype);
|
| - mixin(ShadowRoot.prototype, {
|
| - constructor: ShadowRoot,
|
| - get innerHTML() {
|
| - return getInnerHTML(this);
|
| - },
|
| - set innerHTML(value) {
|
| - setInnerHTML(this, value);
|
| - this.invalidateShadowRenderer();
|
| - },
|
| - get olderShadowRoot() {
|
| - return nextOlderShadowTreeTable.get(this) || null;
|
| - },
|
| - get host() {
|
| - return shadowHostTable.get(this) || null;
|
| - },
|
| - invalidateShadowRenderer: function() {
|
| - return shadowHostTable.get(this).invalidateShadowRenderer();
|
| - },
|
| - elementFromPoint: function(x, y) {
|
| - return elementFromPoint(this, this.ownerDocument, x, y);
|
| - },
|
| - getElementById: function(id) {
|
| - if (spaceCharRe.test(id)) return null;
|
| - return this.querySelector('[id="' + id + '"]');
|
| - }
|
| - });
|
| - scope.wrappers.ShadowRoot = ShadowRoot;
|
| - })(window.ShadowDOMPolyfill);
|
| - (function(scope) {
|
| - "use strict";
|
| var Element = scope.wrappers.Element;
|
| var HTMLContentElement = scope.wrappers.HTMLContentElement;
|
| var HTMLShadowElement = scope.wrappers.HTMLShadowElement;
|
| @@ -3846,7 +4003,7 @@ if (WebComponents.flags.shadow) {
|
| return wrap(unsafeUnwrap(this).focusNode);
|
| },
|
| addRange: function(range) {
|
| - unsafeUnwrap(this).addRange(unwrap(range));
|
| + unsafeUnwrap(this).addRange(unwrapIfNeeded(range));
|
| },
|
| collapse: function(node, index) {
|
| unsafeUnwrap(this).collapse(unwrapIfNeeded(node), index);
|
| @@ -3854,9 +4011,6 @@ if (WebComponents.flags.shadow) {
|
| containsNode: function(node, allowPartial) {
|
| return unsafeUnwrap(this).containsNode(unwrapIfNeeded(node), allowPartial);
|
| },
|
| - extend: function(node, offset) {
|
| - unsafeUnwrap(this).extend(unwrapIfNeeded(node), offset);
|
| - },
|
| getRangeAt: function(index) {
|
| return wrap(unsafeUnwrap(this).getRangeAt(index));
|
| },
|
| @@ -3864,25 +4018,78 @@ if (WebComponents.flags.shadow) {
|
| unsafeUnwrap(this).removeRange(unwrap(range));
|
| },
|
| selectAllChildren: function(node) {
|
| - unsafeUnwrap(this).selectAllChildren(unwrapIfNeeded(node));
|
| + unsafeUnwrap(this).selectAllChildren(node instanceof ShadowRoot ? unsafeUnwrap(node.host) : unwrapIfNeeded(node));
|
| },
|
| toString: function() {
|
| return unsafeUnwrap(this).toString();
|
| }
|
| };
|
| + if (OriginalSelection.prototype.extend) {
|
| + Selection.prototype.extend = function(node, offset) {
|
| + unsafeUnwrap(this).extend(unwrapIfNeeded(node), offset);
|
| + };
|
| + }
|
| registerWrapper(window.Selection, Selection, window.getSelection());
|
| scope.wrappers.Selection = Selection;
|
| })(window.ShadowDOMPolyfill);
|
| (function(scope) {
|
| "use strict";
|
| + var registerWrapper = scope.registerWrapper;
|
| + var setWrapper = scope.setWrapper;
|
| + var unsafeUnwrap = scope.unsafeUnwrap;
|
| + var unwrapIfNeeded = scope.unwrapIfNeeded;
|
| + var wrap = scope.wrap;
|
| + var OriginalTreeWalker = window.TreeWalker;
|
| + function TreeWalker(impl) {
|
| + setWrapper(impl, this);
|
| + }
|
| + TreeWalker.prototype = {
|
| + get root() {
|
| + return wrap(unsafeUnwrap(this).root);
|
| + },
|
| + get currentNode() {
|
| + return wrap(unsafeUnwrap(this).currentNode);
|
| + },
|
| + set currentNode(node) {
|
| + unsafeUnwrap(this).currentNode = unwrapIfNeeded(node);
|
| + },
|
| + get filter() {
|
| + return unsafeUnwrap(this).filter;
|
| + },
|
| + parentNode: function() {
|
| + return wrap(unsafeUnwrap(this).parentNode());
|
| + },
|
| + firstChild: function() {
|
| + return wrap(unsafeUnwrap(this).firstChild());
|
| + },
|
| + lastChild: function() {
|
| + return wrap(unsafeUnwrap(this).lastChild());
|
| + },
|
| + previousSibling: function() {
|
| + return wrap(unsafeUnwrap(this).previousSibling());
|
| + },
|
| + previousNode: function() {
|
| + return wrap(unsafeUnwrap(this).previousNode());
|
| + },
|
| + nextNode: function() {
|
| + return wrap(unsafeUnwrap(this).nextNode());
|
| + }
|
| + };
|
| + registerWrapper(OriginalTreeWalker, TreeWalker);
|
| + scope.wrappers.TreeWalker = TreeWalker;
|
| + })(window.ShadowDOMPolyfill);
|
| + (function(scope) {
|
| + "use strict";
|
| var GetElementsByInterface = scope.GetElementsByInterface;
|
| var Node = scope.wrappers.Node;
|
| var ParentNodeInterface = scope.ParentNodeInterface;
|
| + var NonElementParentNodeInterface = scope.NonElementParentNodeInterface;
|
| var Selection = scope.wrappers.Selection;
|
| var SelectorsInterface = scope.SelectorsInterface;
|
| var ShadowRoot = scope.wrappers.ShadowRoot;
|
| var TreeScope = scope.TreeScope;
|
| var cloneNode = scope.cloneNode;
|
| + var defineGetter = scope.defineGetter;
|
| var defineWrapGetter = scope.defineWrapGetter;
|
| var elementFromPoint = scope.elementFromPoint;
|
| var forwardMethodsToWrapper = scope.forwardMethodsToWrapper;
|
| @@ -3906,13 +4113,29 @@ if (WebComponents.flags.shadow) {
|
| defineWrapGetter(Document, "documentElement");
|
| defineWrapGetter(Document, "body");
|
| defineWrapGetter(Document, "head");
|
| + defineGetter(Document, "activeElement", function() {
|
| + var unwrappedActiveElement = unwrap(this).activeElement;
|
| + if (!unwrappedActiveElement || !unwrappedActiveElement.nodeType) return null;
|
| + var activeElement = wrap(unwrappedActiveElement);
|
| + while (!this.contains(activeElement)) {
|
| + while (activeElement.parentNode) {
|
| + activeElement = activeElement.parentNode;
|
| + }
|
| + if (activeElement.host) {
|
| + activeElement = activeElement.host;
|
| + } else {
|
| + return null;
|
| + }
|
| + }
|
| + return activeElement;
|
| + });
|
| function wrapMethod(name) {
|
| var original = document[name];
|
| Document.prototype[name] = function() {
|
| return wrap(original.apply(unsafeUnwrap(this), arguments));
|
| };
|
| }
|
| - [ "createComment", "createDocumentFragment", "createElement", "createElementNS", "createEvent", "createEventNS", "createRange", "createTextNode", "getElementById" ].forEach(wrapMethod);
|
| + [ "createComment", "createDocumentFragment", "createElement", "createElementNS", "createEvent", "createEventNS", "createRange", "createTextNode" ].forEach(wrapMethod);
|
| var originalAdoptNode = document.adoptNode;
|
| function adoptNodeNoRemove(node, doc) {
|
| originalAdoptNode.call(unsafeUnwrap(doc), unwrap(node));
|
| @@ -3950,11 +4173,30 @@ if (WebComponents.flags.shadow) {
|
| return SelectorsInterface.querySelectorAll.call(this, "[name=" + JSON.stringify(String(name)) + "]");
|
| }
|
| });
|
| - if (document.registerElement) {
|
| - var originalRegisterElement = document.registerElement;
|
| - Document.prototype.registerElement = function(tagName, object) {
|
| - var prototype, extendsOption;
|
| - if (object !== undefined) {
|
| + var originalCreateTreeWalker = document.createTreeWalker;
|
| + var TreeWalkerWrapper = scope.wrappers.TreeWalker;
|
| + Document.prototype.createTreeWalker = function(root, whatToShow, filter, expandEntityReferences) {
|
| + var newFilter = null;
|
| + if (filter) {
|
| + if (filter.acceptNode && typeof filter.acceptNode === "function") {
|
| + newFilter = {
|
| + acceptNode: function(node) {
|
| + return filter.acceptNode(wrap(node));
|
| + }
|
| + };
|
| + } else if (typeof filter === "function") {
|
| + newFilter = function(node) {
|
| + return filter(wrap(node));
|
| + };
|
| + }
|
| + }
|
| + return new TreeWalkerWrapper(originalCreateTreeWalker.call(unwrap(this), unwrap(root), whatToShow, newFilter, expandEntityReferences));
|
| + };
|
| + if (document.registerElement) {
|
| + var originalRegisterElement = document.registerElement;
|
| + Document.prototype.registerElement = function(tagName, object) {
|
| + var prototype, extendsOption;
|
| + if (object !== undefined) {
|
| prototype = object.prototype;
|
| extendsOption = object.extends;
|
| }
|
| @@ -4011,11 +4253,13 @@ if (WebComponents.flags.shadow) {
|
| };
|
| forwardMethodsToWrapper([ window.HTMLDocument || window.Document ], [ "registerElement" ]);
|
| }
|
| - forwardMethodsToWrapper([ window.HTMLBodyElement, window.HTMLDocument || window.Document, window.HTMLHeadElement, window.HTMLHtmlElement ], [ "appendChild", "compareDocumentPosition", "contains", "getElementsByClassName", "getElementsByTagName", "getElementsByTagNameNS", "insertBefore", "querySelector", "querySelectorAll", "removeChild", "replaceChild" ].concat(matchesNames));
|
| - forwardMethodsToWrapper([ window.HTMLDocument || window.Document ], [ "adoptNode", "importNode", "contains", "createComment", "createDocumentFragment", "createElement", "createElementNS", "createEvent", "createEventNS", "createRange", "createTextNode", "elementFromPoint", "getElementById", "getElementsByName", "getSelection" ]);
|
| + forwardMethodsToWrapper([ window.HTMLBodyElement, window.HTMLDocument || window.Document, window.HTMLHeadElement, window.HTMLHtmlElement ], [ "appendChild", "compareDocumentPosition", "contains", "getElementsByClassName", "getElementsByTagName", "getElementsByTagNameNS", "insertBefore", "querySelector", "querySelectorAll", "removeChild", "replaceChild" ]);
|
| + forwardMethodsToWrapper([ window.HTMLBodyElement, window.HTMLHeadElement, window.HTMLHtmlElement ], matchesNames);
|
| + forwardMethodsToWrapper([ window.HTMLDocument || window.Document ], [ "adoptNode", "importNode", "contains", "createComment", "createDocumentFragment", "createElement", "createElementNS", "createEvent", "createEventNS", "createRange", "createTextNode", "createTreeWalker", "elementFromPoint", "getElementById", "getElementsByName", "getSelection" ]);
|
| mixin(Document.prototype, GetElementsByInterface);
|
| mixin(Document.prototype, ParentNodeInterface);
|
| mixin(Document.prototype, SelectorsInterface);
|
| + mixin(Document.prototype, NonElementParentNodeInterface);
|
| mixin(Document.prototype, {
|
| get implementation() {
|
| var implementation = implementationTable.get(this);
|
| @@ -4034,6 +4278,11 @@ if (WebComponents.flags.shadow) {
|
| function DOMImplementation(impl) {
|
| setWrapper(impl, this);
|
| }
|
| + var originalCreateDocument = document.implementation.createDocument;
|
| + DOMImplementation.prototype.createDocument = function() {
|
| + arguments[2] = unwrap(arguments[2]);
|
| + return wrap(originalCreateDocument.apply(unsafeUnwrap(this), arguments));
|
| + };
|
| function wrapImplMethod(constructor, name) {
|
| var original = document.implementation[name];
|
| constructor.prototype[name] = function() {
|
| @@ -4047,11 +4296,10 @@ if (WebComponents.flags.shadow) {
|
| };
|
| }
|
| wrapImplMethod(DOMImplementation, "createDocumentType");
|
| - wrapImplMethod(DOMImplementation, "createDocument");
|
| wrapImplMethod(DOMImplementation, "createHTMLDocument");
|
| forwardImplMethod(DOMImplementation, "hasFeature");
|
| registerWrapper(window.DOMImplementation, DOMImplementation);
|
| - forwardMethodsToWrapper([ window.DOMImplementation ], [ "createDocumentType", "createDocument", "createHTMLDocument", "hasFeature" ]);
|
| + forwardMethodsToWrapper([ window.DOMImplementation ], [ "createDocument", "createDocumentType", "createHTMLDocument", "hasFeature" ]);
|
| scope.adoptNodeNoRemove = adoptNodeNoRemove;
|
| scope.wrappers.DOMImplementation = DOMImplementation;
|
| scope.wrappers.Document = Document;
|
| @@ -4456,7 +4704,7 @@ if (WebComponents.flags.shadow) {
|
| return !selector.match(re);
|
| },
|
| makeScopeMatcher: function(scopeSelector) {
|
| - scopeSelector = scopeSelector.replace(/\[/g, "\\[").replace(/\[/g, "\\]");
|
| + scopeSelector = scopeSelector.replace(/\[/g, "\\[").replace(/\]/g, "\\]");
|
| return new RegExp("^(" + scopeSelector + ")" + selectorReSuffix, "m");
|
| },
|
| applySelectorScope: function(selector, selectorScope) {
|
| @@ -4526,8 +4774,8 @@ if (WebComponents.flags.shadow) {
|
| }
|
| }
|
| };
|
| - var selectorRe = /([^{]*)({[\s\S]*?})/gim, cssCommentRe = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//gim, cssCommentNextSelectorRe = /\/\*\s*@polyfill ([^*]*\*+([^/*][^*]*\*+)*\/)([^{]*?){/gim, cssContentNextSelectorRe = /polyfill-next-selector[^}]*content\:[\s]*?['"](.*?)['"][;\s]*}([^{]*?){/gim, cssCommentRuleRe = /\/\*\s@polyfill-rule([^*]*\*+([^/*][^*]*\*+)*)\//gim, cssContentRuleRe = /(polyfill-rule)[^}]*(content\:[\s]*['"](.*?)['"])[;\s]*[^}]*}/gim, cssCommentUnscopedRuleRe = /\/\*\s@polyfill-unscoped-rule([^*]*\*+([^/*][^*]*\*+)*)\//gim, cssContentUnscopedRuleRe = /(polyfill-unscoped-rule)[^}]*(content\:[\s]*['"](.*?)['"])[;\s]*[^}]*}/gim, cssPseudoRe = /::(x-[^\s{,(]*)/gim, cssPartRe = /::part\(([^)]*)\)/gim, polyfillHost = "-shadowcsshost", polyfillHostContext = "-shadowcsscontext", parenSuffix = ")(?:\\((" + "(?:\\([^)(]*\\)|[^)(]*)+?" + ")\\))?([^,{]*)";
|
| - var cssColonHostRe = new RegExp("(" + polyfillHost + parenSuffix, "gim"), cssColonHostContextRe = new RegExp("(" + polyfillHostContext + parenSuffix, "gim"), selectorReSuffix = "([>\\s~+[.,{:][\\s\\S]*)?$", colonHostRe = /\:host/gim, colonHostContextRe = /\:host-context/gim, polyfillHostNoCombinator = polyfillHost + "-no-combinator", polyfillHostRe = new RegExp(polyfillHost, "gim"), polyfillHostContextRe = new RegExp(polyfillHostContext, "gim"), shadowDOMSelectorsRe = [ /\^\^/g, /\^/g, /\/shadow\//g, /\/shadow-deep\//g, /::shadow/g, /\/deep\//g, /::content/g ];
|
| + var selectorRe = /([^{]*)({[\s\S]*?})/gim, cssCommentRe = /\/\*[^*]*\*+([^\/*][^*]*\*+)*\//gim, cssCommentNextSelectorRe = /\/\*\s*@polyfill ([^*]*\*+([^\/*][^*]*\*+)*\/)([^{]*?){/gim, cssContentNextSelectorRe = /polyfill-next-selector[^}]*content\:[\s]*?['"](.*?)['"][;\s]*}([^{]*?){/gim, cssCommentRuleRe = /\/\*\s@polyfill-rule([^*]*\*+([^\/*][^*]*\*+)*)\//gim, cssContentRuleRe = /(polyfill-rule)[^}]*(content\:[\s]*['"](.*?)['"])[;\s]*[^}]*}/gim, cssCommentUnscopedRuleRe = /\/\*\s@polyfill-unscoped-rule([^*]*\*+([^\/*][^*]*\*+)*)\//gim, cssContentUnscopedRuleRe = /(polyfill-unscoped-rule)[^}]*(content\:[\s]*['"](.*?)['"])[;\s]*[^}]*}/gim, cssPseudoRe = /::(x-[^\s{,(]*)/gim, cssPartRe = /::part\(([^)]*)\)/gim, polyfillHost = "-shadowcsshost", polyfillHostContext = "-shadowcsscontext", parenSuffix = ")(?:\\((" + "(?:\\([^)(]*\\)|[^)(]*)+?" + ")\\))?([^,{]*)";
|
| + var cssColonHostRe = new RegExp("(" + polyfillHost + parenSuffix, "gim"), cssColonHostContextRe = new RegExp("(" + polyfillHostContext + parenSuffix, "gim"), selectorReSuffix = "([>\\s~+[.,{:][\\s\\S]*)?$", colonHostRe = /\:host/gim, colonHostContextRe = /\:host-context/gim, polyfillHostNoCombinator = polyfillHost + "-no-combinator", polyfillHostRe = new RegExp(polyfillHost, "gim"), polyfillHostContextRe = new RegExp(polyfillHostContext, "gim"), shadowDOMSelectorsRe = [ />>>/g, /::shadow/g, /::content/g, /\/deep\//g, /\/shadow\//g, /\/shadow-deep\//g, /\^\^/g, /\^/g ];
|
| function stylesToCssText(styles, preserveComments) {
|
| var cssText = "";
|
| Array.prototype.forEach.call(styles, function(s) {
|
| @@ -4649,7 +4897,7 @@ if (WebComponents.flags.shadow) {
|
| style = elt.ownerDocument.createElement("style");
|
| style.textContent = elt.__resource;
|
| }
|
| - HTMLImports.path.resolveUrlsInStyle(style);
|
| + HTMLImports.path.resolveUrlsInStyle(style, elt.href);
|
| style.textContent = ShadowCSS.shimStyle(style);
|
| style.removeAttribute(SHIM_ATTRIBUTE, "");
|
| style.setAttribute(SHIMMED_ATTRIBUTE, "");
|
| @@ -4691,10 +4939,535 @@ if (WebComponents.flags.shadow) {
|
| }
|
| })(window.WebComponents);
|
|
|
| +(function(scope) {
|
| + "use strict";
|
| + var hasWorkingUrl = false;
|
| + if (!scope.forceJURL) {
|
| + try {
|
| + var u = new URL("b", "http://a");
|
| + u.pathname = "c%20d";
|
| + hasWorkingUrl = u.href === "http://a/c%20d";
|
| + } catch (e) {}
|
| + }
|
| + if (hasWorkingUrl) return;
|
| + var relative = Object.create(null);
|
| + relative["ftp"] = 21;
|
| + relative["file"] = 0;
|
| + relative["gopher"] = 70;
|
| + relative["http"] = 80;
|
| + relative["https"] = 443;
|
| + relative["ws"] = 80;
|
| + relative["wss"] = 443;
|
| + var relativePathDotMapping = Object.create(null);
|
| + relativePathDotMapping["%2e"] = ".";
|
| + relativePathDotMapping[".%2e"] = "..";
|
| + relativePathDotMapping["%2e."] = "..";
|
| + relativePathDotMapping["%2e%2e"] = "..";
|
| + function isRelativeScheme(scheme) {
|
| + return relative[scheme] !== undefined;
|
| + }
|
| + function invalid() {
|
| + clear.call(this);
|
| + this._isInvalid = true;
|
| + }
|
| + function IDNAToASCII(h) {
|
| + if ("" == h) {
|
| + invalid.call(this);
|
| + }
|
| + return h.toLowerCase();
|
| + }
|
| + function percentEscape(c) {
|
| + var unicode = c.charCodeAt(0);
|
| + if (unicode > 32 && unicode < 127 && [ 34, 35, 60, 62, 63, 96 ].indexOf(unicode) == -1) {
|
| + return c;
|
| + }
|
| + return encodeURIComponent(c);
|
| + }
|
| + function percentEscapeQuery(c) {
|
| + var unicode = c.charCodeAt(0);
|
| + if (unicode > 32 && unicode < 127 && [ 34, 35, 60, 62, 96 ].indexOf(unicode) == -1) {
|
| + return c;
|
| + }
|
| + return encodeURIComponent(c);
|
| + }
|
| + var EOF = undefined, ALPHA = /[a-zA-Z]/, ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
|
| + function parse(input, stateOverride, base) {
|
| + function err(message) {
|
| + errors.push(message);
|
| + }
|
| + var state = stateOverride || "scheme start", cursor = 0, buffer = "", seenAt = false, seenBracket = false, errors = [];
|
| + loop: while ((input[cursor - 1] != EOF || cursor == 0) && !this._isInvalid) {
|
| + var c = input[cursor];
|
| + switch (state) {
|
| + case "scheme start":
|
| + if (c && ALPHA.test(c)) {
|
| + buffer += c.toLowerCase();
|
| + state = "scheme";
|
| + } else if (!stateOverride) {
|
| + buffer = "";
|
| + state = "no scheme";
|
| + continue;
|
| + } else {
|
| + err("Invalid scheme.");
|
| + break loop;
|
| + }
|
| + break;
|
| +
|
| + case "scheme":
|
| + if (c && ALPHANUMERIC.test(c)) {
|
| + buffer += c.toLowerCase();
|
| + } else if (":" == c) {
|
| + this._scheme = buffer;
|
| + buffer = "";
|
| + if (stateOverride) {
|
| + break loop;
|
| + }
|
| + if (isRelativeScheme(this._scheme)) {
|
| + this._isRelative = true;
|
| + }
|
| + if ("file" == this._scheme) {
|
| + state = "relative";
|
| + } else if (this._isRelative && base && base._scheme == this._scheme) {
|
| + state = "relative or authority";
|
| + } else if (this._isRelative) {
|
| + state = "authority first slash";
|
| + } else {
|
| + state = "scheme data";
|
| + }
|
| + } else if (!stateOverride) {
|
| + buffer = "";
|
| + cursor = 0;
|
| + state = "no scheme";
|
| + continue;
|
| + } else if (EOF == c) {
|
| + break loop;
|
| + } else {
|
| + err("Code point not allowed in scheme: " + c);
|
| + break loop;
|
| + }
|
| + break;
|
| +
|
| + case "scheme data":
|
| + if ("?" == c) {
|
| + this._query = "?";
|
| + state = "query";
|
| + } else if ("#" == c) {
|
| + this._fragment = "#";
|
| + state = "fragment";
|
| + } else {
|
| + if (EOF != c && " " != c && "\n" != c && "\r" != c) {
|
| + this._schemeData += percentEscape(c);
|
| + }
|
| + }
|
| + break;
|
| +
|
| + case "no scheme":
|
| + if (!base || !isRelativeScheme(base._scheme)) {
|
| + err("Missing scheme.");
|
| + invalid.call(this);
|
| + } else {
|
| + state = "relative";
|
| + continue;
|
| + }
|
| + break;
|
| +
|
| + case "relative or authority":
|
| + if ("/" == c && "/" == input[cursor + 1]) {
|
| + state = "authority ignore slashes";
|
| + } else {
|
| + err("Expected /, got: " + c);
|
| + state = "relative";
|
| + continue;
|
| + }
|
| + break;
|
| +
|
| + case "relative":
|
| + this._isRelative = true;
|
| + if ("file" != this._scheme) this._scheme = base._scheme;
|
| + if (EOF == c) {
|
| + this._host = base._host;
|
| + this._port = base._port;
|
| + this._path = base._path.slice();
|
| + this._query = base._query;
|
| + this._username = base._username;
|
| + this._password = base._password;
|
| + break loop;
|
| + } else if ("/" == c || "\\" == c) {
|
| + if ("\\" == c) err("\\ is an invalid code point.");
|
| + state = "relative slash";
|
| + } else if ("?" == c) {
|
| + this._host = base._host;
|
| + this._port = base._port;
|
| + this._path = base._path.slice();
|
| + this._query = "?";
|
| + this._username = base._username;
|
| + this._password = base._password;
|
| + state = "query";
|
| + } else if ("#" == c) {
|
| + this._host = base._host;
|
| + this._port = base._port;
|
| + this._path = base._path.slice();
|
| + this._query = base._query;
|
| + this._fragment = "#";
|
| + this._username = base._username;
|
| + this._password = base._password;
|
| + state = "fragment";
|
| + } else {
|
| + var nextC = input[cursor + 1];
|
| + var nextNextC = input[cursor + 2];
|
| + if ("file" != this._scheme || !ALPHA.test(c) || nextC != ":" && nextC != "|" || EOF != nextNextC && "/" != nextNextC && "\\" != nextNextC && "?" != nextNextC && "#" != nextNextC) {
|
| + this._host = base._host;
|
| + this._port = base._port;
|
| + this._username = base._username;
|
| + this._password = base._password;
|
| + this._path = base._path.slice();
|
| + this._path.pop();
|
| + }
|
| + state = "relative path";
|
| + continue;
|
| + }
|
| + break;
|
| +
|
| + case "relative slash":
|
| + if ("/" == c || "\\" == c) {
|
| + if ("\\" == c) {
|
| + err("\\ is an invalid code point.");
|
| + }
|
| + if ("file" == this._scheme) {
|
| + state = "file host";
|
| + } else {
|
| + state = "authority ignore slashes";
|
| + }
|
| + } else {
|
| + if ("file" != this._scheme) {
|
| + this._host = base._host;
|
| + this._port = base._port;
|
| + this._username = base._username;
|
| + this._password = base._password;
|
| + }
|
| + state = "relative path";
|
| + continue;
|
| + }
|
| + break;
|
| +
|
| + case "authority first slash":
|
| + if ("/" == c) {
|
| + state = "authority second slash";
|
| + } else {
|
| + err("Expected '/', got: " + c);
|
| + state = "authority ignore slashes";
|
| + continue;
|
| + }
|
| + break;
|
| +
|
| + case "authority second slash":
|
| + state = "authority ignore slashes";
|
| + if ("/" != c) {
|
| + err("Expected '/', got: " + c);
|
| + continue;
|
| + }
|
| + break;
|
| +
|
| + case "authority ignore slashes":
|
| + if ("/" != c && "\\" != c) {
|
| + state = "authority";
|
| + continue;
|
| + } else {
|
| + err("Expected authority, got: " + c);
|
| + }
|
| + break;
|
| +
|
| + case "authority":
|
| + if ("@" == c) {
|
| + if (seenAt) {
|
| + err("@ already seen.");
|
| + buffer += "%40";
|
| + }
|
| + seenAt = true;
|
| + for (var i = 0; i < buffer.length; i++) {
|
| + var cp = buffer[i];
|
| + if (" " == cp || "\n" == cp || "\r" == cp) {
|
| + err("Invalid whitespace in authority.");
|
| + continue;
|
| + }
|
| + if (":" == cp && null === this._password) {
|
| + this._password = "";
|
| + continue;
|
| + }
|
| + var tempC = percentEscape(cp);
|
| + null !== this._password ? this._password += tempC : this._username += tempC;
|
| + }
|
| + buffer = "";
|
| + } else if (EOF == c || "/" == c || "\\" == c || "?" == c || "#" == c) {
|
| + cursor -= buffer.length;
|
| + buffer = "";
|
| + state = "host";
|
| + continue;
|
| + } else {
|
| + buffer += c;
|
| + }
|
| + break;
|
| +
|
| + case "file host":
|
| + if (EOF == c || "/" == c || "\\" == c || "?" == c || "#" == c) {
|
| + if (buffer.length == 2 && ALPHA.test(buffer[0]) && (buffer[1] == ":" || buffer[1] == "|")) {
|
| + state = "relative path";
|
| + } else if (buffer.length == 0) {
|
| + state = "relative path start";
|
| + } else {
|
| + this._host = IDNAToASCII.call(this, buffer);
|
| + buffer = "";
|
| + state = "relative path start";
|
| + }
|
| + continue;
|
| + } else if (" " == c || "\n" == c || "\r" == c) {
|
| + err("Invalid whitespace in file host.");
|
| + } else {
|
| + buffer += c;
|
| + }
|
| + break;
|
| +
|
| + case "host":
|
| + case "hostname":
|
| + if (":" == c && !seenBracket) {
|
| + this._host = IDNAToASCII.call(this, buffer);
|
| + buffer = "";
|
| + state = "port";
|
| + if ("hostname" == stateOverride) {
|
| + break loop;
|
| + }
|
| + } else if (EOF == c || "/" == c || "\\" == c || "?" == c || "#" == c) {
|
| + this._host = IDNAToASCII.call(this, buffer);
|
| + buffer = "";
|
| + state = "relative path start";
|
| + if (stateOverride) {
|
| + break loop;
|
| + }
|
| + continue;
|
| + } else if (" " != c && "\n" != c && "\r" != c) {
|
| + if ("[" == c) {
|
| + seenBracket = true;
|
| + } else if ("]" == c) {
|
| + seenBracket = false;
|
| + }
|
| + buffer += c;
|
| + } else {
|
| + err("Invalid code point in host/hostname: " + c);
|
| + }
|
| + break;
|
| +
|
| + case "port":
|
| + if (/[0-9]/.test(c)) {
|
| + buffer += c;
|
| + } else if (EOF == c || "/" == c || "\\" == c || "?" == c || "#" == c || stateOverride) {
|
| + if ("" != buffer) {
|
| + var temp = parseInt(buffer, 10);
|
| + if (temp != relative[this._scheme]) {
|
| + this._port = temp + "";
|
| + }
|
| + buffer = "";
|
| + }
|
| + if (stateOverride) {
|
| + break loop;
|
| + }
|
| + state = "relative path start";
|
| + continue;
|
| + } else if (" " == c || "\n" == c || "\r" == c) {
|
| + err("Invalid code point in port: " + c);
|
| + } else {
|
| + invalid.call(this);
|
| + }
|
| + break;
|
| +
|
| + case "relative path start":
|
| + if ("\\" == c) err("'\\' not allowed in path.");
|
| + state = "relative path";
|
| + if ("/" != c && "\\" != c) {
|
| + continue;
|
| + }
|
| + break;
|
| +
|
| + case "relative path":
|
| + if (EOF == c || "/" == c || "\\" == c || !stateOverride && ("?" == c || "#" == c)) {
|
| + if ("\\" == c) {
|
| + err("\\ not allowed in relative path.");
|
| + }
|
| + var tmp;
|
| + if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
|
| + buffer = tmp;
|
| + }
|
| + if (".." == buffer) {
|
| + this._path.pop();
|
| + if ("/" != c && "\\" != c) {
|
| + this._path.push("");
|
| + }
|
| + } else if ("." == buffer && "/" != c && "\\" != c) {
|
| + this._path.push("");
|
| + } else if ("." != buffer) {
|
| + if ("file" == this._scheme && this._path.length == 0 && buffer.length == 2 && ALPHA.test(buffer[0]) && buffer[1] == "|") {
|
| + buffer = buffer[0] + ":";
|
| + }
|
| + this._path.push(buffer);
|
| + }
|
| + buffer = "";
|
| + if ("?" == c) {
|
| + this._query = "?";
|
| + state = "query";
|
| + } else if ("#" == c) {
|
| + this._fragment = "#";
|
| + state = "fragment";
|
| + }
|
| + } else if (" " != c && "\n" != c && "\r" != c) {
|
| + buffer += percentEscape(c);
|
| + }
|
| + break;
|
| +
|
| + case "query":
|
| + if (!stateOverride && "#" == c) {
|
| + this._fragment = "#";
|
| + state = "fragment";
|
| + } else if (EOF != c && " " != c && "\n" != c && "\r" != c) {
|
| + this._query += percentEscapeQuery(c);
|
| + }
|
| + break;
|
| +
|
| + case "fragment":
|
| + if (EOF != c && " " != c && "\n" != c && "\r" != c) {
|
| + this._fragment += c;
|
| + }
|
| + break;
|
| + }
|
| + cursor++;
|
| + }
|
| + }
|
| + function clear() {
|
| + this._scheme = "";
|
| + this._schemeData = "";
|
| + this._username = "";
|
| + this._password = null;
|
| + this._host = "";
|
| + this._port = "";
|
| + this._path = [];
|
| + this._query = "";
|
| + this._fragment = "";
|
| + this._isInvalid = false;
|
| + this._isRelative = false;
|
| + }
|
| + function jURL(url, base) {
|
| + if (base !== undefined && !(base instanceof jURL)) base = new jURL(String(base));
|
| + this._url = url;
|
| + clear.call(this);
|
| + var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, "");
|
| + parse.call(this, input, null, base);
|
| + }
|
| + jURL.prototype = {
|
| + toString: function() {
|
| + return this.href;
|
| + },
|
| + get href() {
|
| + if (this._isInvalid) return this._url;
|
| + var authority = "";
|
| + if ("" != this._username || null != this._password) {
|
| + authority = this._username + (null != this._password ? ":" + this._password : "") + "@";
|
| + }
|
| + return this.protocol + (this._isRelative ? "//" + authority + this.host : "") + this.pathname + this._query + this._fragment;
|
| + },
|
| + set href(href) {
|
| + clear.call(this);
|
| + parse.call(this, href);
|
| + },
|
| + get protocol() {
|
| + return this._scheme + ":";
|
| + },
|
| + set protocol(protocol) {
|
| + if (this._isInvalid) return;
|
| + parse.call(this, protocol + ":", "scheme start");
|
| + },
|
| + get host() {
|
| + return this._isInvalid ? "" : this._port ? this._host + ":" + this._port : this._host;
|
| + },
|
| + set host(host) {
|
| + if (this._isInvalid || !this._isRelative) return;
|
| + parse.call(this, host, "host");
|
| + },
|
| + get hostname() {
|
| + return this._host;
|
| + },
|
| + set hostname(hostname) {
|
| + if (this._isInvalid || !this._isRelative) return;
|
| + parse.call(this, hostname, "hostname");
|
| + },
|
| + get port() {
|
| + return this._port;
|
| + },
|
| + set port(port) {
|
| + if (this._isInvalid || !this._isRelative) return;
|
| + parse.call(this, port, "port");
|
| + },
|
| + get pathname() {
|
| + return this._isInvalid ? "" : this._isRelative ? "/" + this._path.join("/") : this._schemeData;
|
| + },
|
| + set pathname(pathname) {
|
| + if (this._isInvalid || !this._isRelative) return;
|
| + this._path = [];
|
| + parse.call(this, pathname, "relative path start");
|
| + },
|
| + get search() {
|
| + return this._isInvalid || !this._query || "?" == this._query ? "" : this._query;
|
| + },
|
| + set search(search) {
|
| + if (this._isInvalid || !this._isRelative) return;
|
| + this._query = "?";
|
| + if ("?" == search[0]) search = search.slice(1);
|
| + parse.call(this, search, "query");
|
| + },
|
| + get hash() {
|
| + return this._isInvalid || !this._fragment || "#" == this._fragment ? "" : this._fragment;
|
| + },
|
| + set hash(hash) {
|
| + if (this._isInvalid) return;
|
| + this._fragment = "#";
|
| + if ("#" == hash[0]) hash = hash.slice(1);
|
| + parse.call(this, hash, "fragment");
|
| + },
|
| + get origin() {
|
| + var host;
|
| + if (this._isInvalid || !this._scheme) {
|
| + return "";
|
| + }
|
| + switch (this._scheme) {
|
| + case "data":
|
| + case "file":
|
| + case "javascript":
|
| + case "mailto":
|
| + return "null";
|
| + }
|
| + host = this.host;
|
| + if (!host) {
|
| + return "";
|
| + }
|
| + return this._scheme + "://" + host;
|
| + }
|
| + };
|
| + var OriginalURL = scope.URL;
|
| + if (OriginalURL) {
|
| + jURL.createObjectURL = function(blob) {
|
| + return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
|
| + };
|
| + jURL.revokeObjectURL = function(url) {
|
| + OriginalURL.revokeObjectURL(url);
|
| + };
|
| + }
|
| + scope.URL = jURL;
|
| +})(self);
|
| +
|
| (function(global) {
|
| + if (global.JsMutationObserver) {
|
| + return;
|
| + }
|
| var registrationsTable = new WeakMap();
|
| var setImmediate;
|
| - if (/Trident/.test(navigator.userAgent)) {
|
| + if (/Trident|Edge/.test(navigator.userAgent)) {
|
| setImmediate = setTimeout;
|
| } else if (window.setImmediate) {
|
| setImmediate = window.setImmediate;
|
| @@ -4962,7 +5735,6 @@ if (WebComponents.flags.shadow) {
|
| this.addTransientObserver(e.target);
|
|
|
| case "DOMNodeInserted":
|
| - var target = e.relatedNode;
|
| var changedNode = e.target;
|
| var addedNodes, removedNodes;
|
| if (e.type === "DOMNodeInserted") {
|
| @@ -4974,12 +5746,12 @@ if (WebComponents.flags.shadow) {
|
| }
|
| var previousSibling = changedNode.previousSibling;
|
| var nextSibling = changedNode.nextSibling;
|
| - var record = getRecord("childList", target);
|
| + var record = getRecord("childList", e.target.parentNode);
|
| record.addedNodes = addedNodes;
|
| record.removedNodes = removedNodes;
|
| record.previousSibling = previousSibling;
|
| record.nextSibling = nextSibling;
|
| - forEachAncestorAndObserverEnqueueRecord(target, function(options) {
|
| + forEachAncestorAndObserverEnqueueRecord(e.relatedNode, function(options) {
|
| if (!options.childList) return;
|
| return record;
|
| });
|
| @@ -4988,8 +5760,83 @@ if (WebComponents.flags.shadow) {
|
| }
|
| };
|
| global.JsMutationObserver = JsMutationObserver;
|
| - if (!global.MutationObserver) global.MutationObserver = JsMutationObserver;
|
| -})(this);
|
| + if (!global.MutationObserver) {
|
| + global.MutationObserver = JsMutationObserver;
|
| + JsMutationObserver._isPolyfilled = true;
|
| + }
|
| +})(self);
|
| +
|
| +(function(scope) {
|
| + "use strict";
|
| + if (!window.performance) {
|
| + var start = Date.now();
|
| + window.performance = {
|
| + now: function() {
|
| + return Date.now() - start;
|
| + }
|
| + };
|
| + }
|
| + if (!window.requestAnimationFrame) {
|
| + window.requestAnimationFrame = function() {
|
| + var nativeRaf = window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame;
|
| + return nativeRaf ? function(callback) {
|
| + return nativeRaf(function() {
|
| + callback(performance.now());
|
| + });
|
| + } : function(callback) {
|
| + return window.setTimeout(callback, 1e3 / 60);
|
| + };
|
| + }();
|
| + }
|
| + if (!window.cancelAnimationFrame) {
|
| + window.cancelAnimationFrame = function() {
|
| + return window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || function(id) {
|
| + clearTimeout(id);
|
| + };
|
| + }();
|
| + }
|
| + var workingDefaultPrevented = function() {
|
| + var e = document.createEvent("Event");
|
| + e.initEvent("foo", true, true);
|
| + e.preventDefault();
|
| + return e.defaultPrevented;
|
| + }();
|
| + if (!workingDefaultPrevented) {
|
| + var origPreventDefault = Event.prototype.preventDefault;
|
| + Event.prototype.preventDefault = function() {
|
| + if (!this.cancelable) {
|
| + return;
|
| + }
|
| + origPreventDefault.call(this);
|
| + Object.defineProperty(this, "defaultPrevented", {
|
| + get: function() {
|
| + return true;
|
| + },
|
| + configurable: true
|
| + });
|
| + };
|
| + }
|
| + var isIE = /Trident/.test(navigator.userAgent);
|
| + if (!window.CustomEvent || isIE && typeof window.CustomEvent !== "function") {
|
| + window.CustomEvent = function(inType, params) {
|
| + params = params || {};
|
| + var e = document.createEvent("CustomEvent");
|
| + e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable), params.detail);
|
| + return e;
|
| + };
|
| + window.CustomEvent.prototype = window.Event.prototype;
|
| + }
|
| + if (!window.Event || isIE && typeof window.Event !== "function") {
|
| + var origEvent = window.Event;
|
| + window.Event = function(inType, params) {
|
| + params = params || {};
|
| + var e = document.createEvent("Event");
|
| + e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable));
|
| + return e;
|
| + };
|
| + window.Event.prototype = origEvent.prototype;
|
| + }
|
| +})(window.WebComponents);
|
|
|
| window.HTMLImports = window.HTMLImports || {
|
| flags: {}
|
| @@ -5000,12 +5847,12 @@ window.HTMLImports = window.HTMLImports || {
|
| var useNative = Boolean(IMPORT_LINK_TYPE in document.createElement("link"));
|
| var hasShadowDOMPolyfill = Boolean(window.ShadowDOMPolyfill);
|
| var wrap = function(node) {
|
| - return hasShadowDOMPolyfill ? ShadowDOMPolyfill.wrapIfNeeded(node) : node;
|
| + return hasShadowDOMPolyfill ? window.ShadowDOMPolyfill.wrapIfNeeded(node) : node;
|
| };
|
| var rootDocument = wrap(document);
|
| var currentScriptDescriptor = {
|
| get: function() {
|
| - var script = HTMLImports.currentScript || document.currentScript || (document.readyState !== "complete" ? document.scripts[document.scripts.length - 1] : null);
|
| + var script = window.HTMLImports.currentScript || document.currentScript || (document.readyState !== "complete" ? document.scripts[document.scripts.length - 1] : null);
|
| return wrap(script);
|
| },
|
| configurable: true
|
| @@ -5042,26 +5889,36 @@ window.HTMLImports = window.HTMLImports || {
|
| }
|
| function watchImportsLoad(callback, doc) {
|
| var imports = doc.querySelectorAll("link[rel=import]");
|
| - var loaded = 0, l = imports.length;
|
| - function checkDone(d) {
|
| - if (loaded == l && callback) {
|
| - callback();
|
| + var parsedCount = 0, importCount = imports.length, newImports = [], errorImports = [];
|
| + function checkDone() {
|
| + if (parsedCount == importCount && callback) {
|
| + callback({
|
| + allImports: imports,
|
| + loadedImports: newImports,
|
| + errorImports: errorImports
|
| + });
|
| }
|
| }
|
| function loadedImport(e) {
|
| markTargetLoaded(e);
|
| - loaded++;
|
| + newImports.push(this);
|
| + parsedCount++;
|
| + checkDone();
|
| + }
|
| + function errorLoadingImport(e) {
|
| + errorImports.push(this);
|
| + parsedCount++;
|
| checkDone();
|
| }
|
| - if (l) {
|
| - for (var i = 0, imp; i < l && (imp = imports[i]); i++) {
|
| + if (importCount) {
|
| + for (var i = 0, imp; i < importCount && (imp = imports[i]); i++) {
|
| if (isImportLoaded(imp)) {
|
| - loadedImport.call(imp, {
|
| - target: imp
|
| - });
|
| + newImports.push(this);
|
| + parsedCount++;
|
| + checkDone();
|
| } else {
|
| imp.addEventListener("load", loadedImport);
|
| - imp.addEventListener("error", loadedImport);
|
| + imp.addEventListener("error", errorLoadingImport);
|
| }
|
| }
|
| } else {
|
| @@ -5111,19 +5968,19 @@ window.HTMLImports = window.HTMLImports || {
|
| }
|
| })();
|
| }
|
| - whenReady(function() {
|
| - HTMLImports.ready = true;
|
| - HTMLImports.readyTime = new Date().getTime();
|
| - rootDocument.dispatchEvent(new CustomEvent("HTMLImportsLoaded", {
|
| - bubbles: true
|
| - }));
|
| + whenReady(function(detail) {
|
| + window.HTMLImports.ready = true;
|
| + window.HTMLImports.readyTime = new Date().getTime();
|
| + var evt = rootDocument.createEvent("CustomEvent");
|
| + evt.initCustomEvent("HTMLImportsLoaded", true, true, detail);
|
| + rootDocument.dispatchEvent(evt);
|
| });
|
| scope.IMPORT_LINK_TYPE = IMPORT_LINK_TYPE;
|
| scope.useNative = useNative;
|
| scope.rootDocument = rootDocument;
|
| scope.whenReady = whenReady;
|
| scope.isIE = isIE;
|
| -})(HTMLImports);
|
| +})(window.HTMLImports);
|
|
|
| (function(scope) {
|
| var modules = [];
|
| @@ -5137,26 +5994,29 @@ window.HTMLImports = window.HTMLImports || {
|
| };
|
| scope.addModule = addModule;
|
| scope.initializeModules = initializeModules;
|
| -})(HTMLImports);
|
| +})(window.HTMLImports);
|
|
|
| -HTMLImports.addModule(function(scope) {
|
| +window.HTMLImports.addModule(function(scope) {
|
| var CSS_URL_REGEXP = /(url\()([^)]*)(\))/g;
|
| var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g;
|
| var path = {
|
| - resolveUrlsInStyle: function(style) {
|
| + resolveUrlsInStyle: function(style, linkUrl) {
|
| var doc = style.ownerDocument;
|
| var resolver = doc.createElement("a");
|
| - style.textContent = this.resolveUrlsInCssText(style.textContent, resolver);
|
| + style.textContent = this.resolveUrlsInCssText(style.textContent, linkUrl, resolver);
|
| return style;
|
| },
|
| - resolveUrlsInCssText: function(cssText, urlObj) {
|
| - var r = this.replaceUrls(cssText, urlObj, CSS_URL_REGEXP);
|
| - r = this.replaceUrls(r, urlObj, CSS_IMPORT_REGEXP);
|
| + resolveUrlsInCssText: function(cssText, linkUrl, urlObj) {
|
| + var r = this.replaceUrls(cssText, urlObj, linkUrl, CSS_URL_REGEXP);
|
| + r = this.replaceUrls(r, urlObj, linkUrl, CSS_IMPORT_REGEXP);
|
| return r;
|
| },
|
| - replaceUrls: function(text, urlObj, regexp) {
|
| + replaceUrls: function(text, urlObj, linkUrl, regexp) {
|
| return text.replace(regexp, function(m, pre, url, post) {
|
| var urlPath = url.replace(/["']/g, "");
|
| + if (linkUrl) {
|
| + urlPath = new URL(urlPath, linkUrl).href;
|
| + }
|
| urlObj.href = urlPath;
|
| urlPath = urlObj.href;
|
| return pre + "'" + urlPath + "'" + post;
|
| @@ -5166,8 +6026,8 @@ HTMLImports.addModule(function(scope) {
|
| scope.path = path;
|
| });
|
|
|
| -HTMLImports.addModule(function(scope) {
|
| - xhr = {
|
| +window.HTMLImports.addModule(function(scope) {
|
| + var xhr = {
|
| async: true,
|
| ok: function(request) {
|
| return request.status >= 200 && request.status < 300 || request.status === 304 || request.status === 0;
|
| @@ -5180,10 +6040,14 @@ HTMLImports.addModule(function(scope) {
|
| request.open("GET", url, xhr.async);
|
| request.addEventListener("readystatechange", function(e) {
|
| if (request.readyState === 4) {
|
| - var locationHeader = request.getResponseHeader("Location");
|
| var redirectedUrl = null;
|
| - if (locationHeader) {
|
| - var redirectedUrl = locationHeader.substr(0, 1) === "/" ? location.origin + locationHeader : locationHeader;
|
| + try {
|
| + var locationHeader = request.getResponseHeader("Location");
|
| + if (locationHeader) {
|
| + redirectedUrl = locationHeader.substr(0, 1) === "/" ? location.origin + locationHeader : locationHeader;
|
| + }
|
| + } catch (e) {
|
| + console.error(e.message);
|
| }
|
| next.call(nextContext, !xhr.ok(request) && request, request.response || request.responseText, redirectedUrl);
|
| }
|
| @@ -5198,7 +6062,7 @@ HTMLImports.addModule(function(scope) {
|
| scope.xhr = xhr;
|
| });
|
|
|
| -HTMLImports.addModule(function(scope) {
|
| +window.HTMLImports.addModule(function(scope) {
|
| var xhr = scope.xhr;
|
| var flags = scope.flags;
|
| var Loader = function(onLoad, onComplete) {
|
| @@ -5244,7 +6108,13 @@ HTMLImports.addModule(function(scope) {
|
| },
|
| fetch: function(url, elt) {
|
| flags.load && console.log("fetch", url, elt);
|
| - if (url.match(/^data:/)) {
|
| + if (!url) {
|
| + setTimeout(function() {
|
| + this.receive(url, elt, {
|
| + error: "href must be specified"
|
| + }, null);
|
| + }.bind(this), 0);
|
| + } else if (url.match(/^data:/)) {
|
| var pieces = url.split(",");
|
| var header = pieces[0];
|
| var body = pieces[1];
|
| @@ -5285,7 +6155,7 @@ HTMLImports.addModule(function(scope) {
|
| scope.Loader = Loader;
|
| });
|
|
|
| -HTMLImports.addModule(function(scope) {
|
| +window.HTMLImports.addModule(function(scope) {
|
| var Observer = function(addCallback) {
|
| this.addCallback = addCallback;
|
| this.mo = new MutationObserver(this.handler.bind(this));
|
| @@ -5318,7 +6188,7 @@ HTMLImports.addModule(function(scope) {
|
| scope.Observer = Observer;
|
| });
|
|
|
| -HTMLImports.addModule(function(scope) {
|
| +window.HTMLImports.addModule(function(scope) {
|
| var path = scope.path;
|
| var rootDocument = scope.rootDocument;
|
| var flags = scope.flags;
|
| @@ -5327,7 +6197,7 @@ HTMLImports.addModule(function(scope) {
|
| var IMPORT_SELECTOR = "link[rel=" + IMPORT_LINK_TYPE + "]";
|
| var importParser = {
|
| documentSelectors: IMPORT_SELECTOR,
|
| - importsSelectors: [ IMPORT_SELECTOR, "link[rel=stylesheet]", "style", "script:not([type])", 'script[type="text/javascript"]' ].join(","),
|
| + importsSelectors: [ IMPORT_SELECTOR, "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",
|
| @@ -5378,8 +6248,9 @@ HTMLImports.addModule(function(scope) {
|
| }
|
| },
|
| parseImport: function(elt) {
|
| - if (HTMLImports.__importsParsingHook) {
|
| - HTMLImports.__importsParsingHook(elt);
|
| + elt.import = elt.__doc;
|
| + if (window.HTMLImports.__importsParsingHook) {
|
| + window.HTMLImports.__importsParsingHook(elt);
|
| }
|
| if (elt.import) {
|
| elt.import.__importParsed = true;
|
| @@ -5418,6 +6289,7 @@ HTMLImports.addModule(function(scope) {
|
| parseStyle: function(elt) {
|
| var src = elt;
|
| elt = cloneStyle(elt);
|
| + src.__appliedElement = elt;
|
| elt.__importElement = src;
|
| this.parseGeneric(elt);
|
| },
|
| @@ -5434,16 +6306,13 @@ HTMLImports.addModule(function(scope) {
|
| },
|
| addElementToDocument: function(elt) {
|
| var port = this.rootImportForElement(elt.__importElement || elt);
|
| - var l = port.__insertedElements = port.__insertedElements || 0;
|
| - var refNode = port.nextElementSibling;
|
| - for (var i = 0; i < l; i++) {
|
| - refNode = refNode && refNode.nextElementSibling;
|
| - }
|
| - port.parentNode.insertBefore(elt, refNode);
|
| + port.parentNode.insertBefore(elt, port);
|
| },
|
| trackElement: function(elt, callback) {
|
| var self = this;
|
| var done = function(e) {
|
| + elt.removeEventListener("load", done);
|
| + elt.removeEventListener("error", done);
|
| if (callback) {
|
| callback(e);
|
| }
|
| @@ -5467,9 +6336,11 @@ HTMLImports.addModule(function(scope) {
|
| }
|
| }
|
| if (fakeLoad) {
|
| - elt.dispatchEvent(new CustomEvent("load", {
|
| - bubbles: false
|
| - }));
|
| + setTimeout(function() {
|
| + elt.dispatchEvent(new CustomEvent("load", {
|
| + bubbles: false
|
| + }));
|
| + });
|
| }
|
| }
|
| },
|
| @@ -5479,7 +6350,9 @@ HTMLImports.addModule(function(scope) {
|
| script.src = scriptElt.src ? scriptElt.src : generateScriptDataUrl(scriptElt);
|
| scope.currentScript = scriptElt;
|
| this.trackElement(script, function(e) {
|
| - script.parentNode.removeChild(script);
|
| + if (script.parentNode) {
|
| + script.parentNode.removeChild(script);
|
| + }
|
| scope.currentScript = null;
|
| });
|
| this.addElementToDocument(script);
|
| @@ -5492,10 +6365,10 @@ HTMLImports.addModule(function(scope) {
|
| if (doc && this._mayParse.indexOf(doc) < 0) {
|
| this._mayParse.push(doc);
|
| var nodes = doc.querySelectorAll(this.parseSelectorsForNode(doc));
|
| - for (var i = 0, l = nodes.length, p = 0, n; i < l && (n = nodes[i]); i++) {
|
| + for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
|
| if (!this.isParsed(n)) {
|
| if (this.hasResource(n)) {
|
| - return nodeIsImport(n) ? this.nextToParseInDoc(n.import, n) : n;
|
| + return nodeIsImport(n) ? this.nextToParseInDoc(n.__doc, n) : n;
|
| } else {
|
| return;
|
| }
|
| @@ -5518,7 +6391,7 @@ HTMLImports.addModule(function(scope) {
|
| return this.dynamicElements.indexOf(elt) >= 0;
|
| },
|
| hasResource: function(node) {
|
| - if (nodeIsImport(node) && node.import === undefined) {
|
| + if (nodeIsImport(node) && node.__doc === undefined) {
|
| return false;
|
| }
|
| return true;
|
| @@ -5552,7 +6425,7 @@ HTMLImports.addModule(function(scope) {
|
| scope.IMPORT_SELECTOR = IMPORT_SELECTOR;
|
| });
|
|
|
| -HTMLImports.addModule(function(scope) {
|
| +window.HTMLImports.addModule(function(scope) {
|
| var flags = scope.flags;
|
| var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE;
|
| var IMPORT_SELECTOR = scope.IMPORT_SELECTOR;
|
| @@ -5592,7 +6465,7 @@ HTMLImports.addModule(function(scope) {
|
| }
|
| this.documents[url] = doc;
|
| }
|
| - elt.import = doc;
|
| + elt.__doc = doc;
|
| }
|
| parser.parseNext();
|
| },
|
| @@ -5613,13 +6486,18 @@ HTMLImports.addModule(function(scope) {
|
| function isLinkRel(elt, rel) {
|
| return elt.localName === "link" && elt.getAttribute("rel") === rel;
|
| }
|
| + function hasBaseURIAccessor(doc) {
|
| + return !!Object.getOwnPropertyDescriptor(doc, "baseURI");
|
| + }
|
| function makeDocument(resource, url) {
|
| var doc = document.implementation.createHTMLDocument(IMPORT_LINK_TYPE);
|
| doc._URL = url;
|
| var base = doc.createElement("base");
|
| base.setAttribute("href", url);
|
| - if (!doc.baseURI) {
|
| - doc.baseURI = url;
|
| + if (!doc.baseURI && !hasBaseURIAccessor(doc)) {
|
| + Object.defineProperty(doc, "baseURI", {
|
| + value: url
|
| + });
|
| }
|
| var meta = doc.createElement("meta");
|
| meta.setAttribute("charset", "utf-8");
|
| @@ -5646,12 +6524,12 @@ HTMLImports.addModule(function(scope) {
|
| scope.importLoader = importLoader;
|
| });
|
|
|
| -HTMLImports.addModule(function(scope) {
|
| +window.HTMLImports.addModule(function(scope) {
|
| var parser = scope.parser;
|
| var importer = scope.importer;
|
| var dynamic = {
|
| added: function(nodes) {
|
| - var owner, parsed;
|
| + var owner, parsed, loading;
|
| for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
|
| if (!owner) {
|
| owner = n.ownerDocument;
|
| @@ -5678,28 +6556,22 @@ HTMLImports.addModule(function(scope) {
|
| });
|
|
|
| (function(scope) {
|
| - initializeModules = scope.initializeModules;
|
| + var initializeModules = scope.initializeModules;
|
| + var isIE = scope.isIE;
|
| if (scope.useNative) {
|
| return;
|
| }
|
| - if (typeof window.CustomEvent !== "function") {
|
| - window.CustomEvent = function(inType, dictionary) {
|
| - var e = document.createEvent("HTMLEvents");
|
| - e.initEvent(inType, dictionary.bubbles === false ? false : true, dictionary.cancelable === false ? false : true, dictionary.detail);
|
| - return e;
|
| - };
|
| - }
|
| initializeModules();
|
| var rootDocument = scope.rootDocument;
|
| function bootstrap() {
|
| - HTMLImports.importer.bootDocument(rootDocument);
|
| + window.HTMLImports.importer.bootDocument(rootDocument);
|
| }
|
| if (document.readyState === "complete" || document.readyState === "interactive" && !window.attachEvent) {
|
| bootstrap();
|
| } else {
|
| document.addEventListener("DOMContentLoaded", bootstrap);
|
| }
|
| -})(HTMLImports);
|
| +})(window.HTMLImports);
|
|
|
| window.CustomElements = window.CustomElements || {
|
| flags: {}
|
| @@ -5719,11 +6591,12 @@ window.CustomElements = window.CustomElements || {
|
| scope.addModule = addModule;
|
| scope.initializeModules = initializeModules;
|
| scope.hasNative = Boolean(document.registerElement);
|
| - scope.useNative = !flags.register && scope.hasNative && !window.ShadowDOMPolyfill && (!window.HTMLImports || HTMLImports.useNative);
|
| -})(CustomElements);
|
| + scope.isIE = /Trident/.test(navigator.userAgent);
|
| + scope.useNative = !flags.register && scope.hasNative && !window.ShadowDOMPolyfill && (!window.HTMLImports || window.HTMLImports.useNative);
|
| +})(window.CustomElements);
|
|
|
| -CustomElements.addModule(function(scope) {
|
| - var IMPORT_LINK_TYPE = window.HTMLImports ? HTMLImports.IMPORT_LINK_TYPE : "none";
|
| +window.CustomElements.addModule(function(scope) {
|
| + var IMPORT_LINK_TYPE = window.HTMLImports ? window.HTMLImports.IMPORT_LINK_TYPE : "none";
|
| function forSubtree(node, cb) {
|
| findAllElements(node, function(e) {
|
| if (cb(e)) {
|
| @@ -5756,14 +6629,11 @@ CustomElements.addModule(function(scope) {
|
| root = root.olderShadowRoot;
|
| }
|
| }
|
| - var processingDocuments;
|
| function forDocumentTree(doc, cb) {
|
| - processingDocuments = [];
|
| - _forDocumentTree(doc, cb);
|
| - processingDocuments = null;
|
| + _forDocumentTree(doc, cb, []);
|
| }
|
| - function _forDocumentTree(doc, cb) {
|
| - doc = wrap(doc);
|
| + function _forDocumentTree(doc, cb, processingDocuments) {
|
| + doc = window.wrap(doc);
|
| if (processingDocuments.indexOf(doc) >= 0) {
|
| return;
|
| }
|
| @@ -5771,7 +6641,7 @@ CustomElements.addModule(function(scope) {
|
| var imports = doc.querySelectorAll("link[rel=" + IMPORT_LINK_TYPE + "]");
|
| for (var i = 0, l = imports.length, n; i < l && (n = imports[i]); i++) {
|
| if (n.import) {
|
| - _forDocumentTree(n.import, cb);
|
| + _forDocumentTree(n.import, cb, processingDocuments);
|
| }
|
| }
|
| cb(doc);
|
| @@ -5780,36 +6650,31 @@ CustomElements.addModule(function(scope) {
|
| scope.forSubtree = forSubtree;
|
| });
|
|
|
| -CustomElements.addModule(function(scope) {
|
| +window.CustomElements.addModule(function(scope) {
|
| var flags = scope.flags;
|
| var forSubtree = scope.forSubtree;
|
| var forDocumentTree = scope.forDocumentTree;
|
| - function addedNode(node) {
|
| - return added(node) || addedSubtree(node);
|
| + function addedNode(node, isAttached) {
|
| + return added(node, isAttached) || addedSubtree(node, isAttached);
|
| }
|
| - function added(node) {
|
| - if (scope.upgrade(node)) {
|
| + function added(node, isAttached) {
|
| + if (scope.upgrade(node, isAttached)) {
|
| return true;
|
| }
|
| - attached(node);
|
| + if (isAttached) {
|
| + attached(node);
|
| + }
|
| }
|
| - function addedSubtree(node) {
|
| + function addedSubtree(node, isAttached) {
|
| forSubtree(node, function(e) {
|
| - if (added(e)) {
|
| + if (added(e, isAttached)) {
|
| return true;
|
| }
|
| });
|
| }
|
| - function attachedNode(node) {
|
| - attached(node);
|
| - if (inDocument(node)) {
|
| - forSubtree(node, function(e) {
|
| - attached(e);
|
| - });
|
| - }
|
| - }
|
| - var hasPolyfillMutations = !window.MutationObserver || window.MutationObserver === window.JsMutationObserver;
|
| - scope.hasPolyfillMutations = hasPolyfillMutations;
|
| + var hasThrottledAttached = window.MutationObserver._isPolyfilled && flags["throttle-attached"];
|
| + scope.hasPolyfillMutations = hasThrottledAttached;
|
| + scope.hasThrottledAttached = hasThrottledAttached;
|
| var isPendingMutations = false;
|
| var pendingMutations = [];
|
| function deferMutation(fn) {
|
| @@ -5828,7 +6693,7 @@ CustomElements.addModule(function(scope) {
|
| pendingMutations = [];
|
| }
|
| function attached(element) {
|
| - if (hasPolyfillMutations) {
|
| + if (hasThrottledAttached) {
|
| deferMutation(function() {
|
| _attached(element);
|
| });
|
| @@ -5837,12 +6702,10 @@ CustomElements.addModule(function(scope) {
|
| }
|
| }
|
| function _attached(element) {
|
| - if (element.__upgraded__ && (element.attachedCallback || element.detachedCallback)) {
|
| - if (!element.__attached && inDocument(element)) {
|
| - element.__attached = true;
|
| - if (element.attachedCallback) {
|
| - element.attachedCallback();
|
| - }
|
| + if (element.__upgraded__ && !element.__attached) {
|
| + element.__attached = true;
|
| + if (element.attachedCallback) {
|
| + element.attachedCallback();
|
| }
|
| }
|
| }
|
| @@ -5853,7 +6716,7 @@ CustomElements.addModule(function(scope) {
|
| });
|
| }
|
| function detached(element) {
|
| - if (hasPolyfillMutations) {
|
| + if (hasThrottledAttached) {
|
| deferMutation(function() {
|
| _detached(element);
|
| });
|
| @@ -5862,23 +6725,21 @@ CustomElements.addModule(function(scope) {
|
| }
|
| }
|
| function _detached(element) {
|
| - if (element.__upgraded__ && (element.attachedCallback || element.detachedCallback)) {
|
| - if (element.__attached && !inDocument(element)) {
|
| - element.__attached = false;
|
| - if (element.detachedCallback) {
|
| - element.detachedCallback();
|
| - }
|
| + if (element.__upgraded__ && element.__attached) {
|
| + element.__attached = false;
|
| + if (element.detachedCallback) {
|
| + element.detachedCallback();
|
| }
|
| }
|
| }
|
| function inDocument(element) {
|
| var p = element;
|
| - var doc = wrap(document);
|
| + var doc = window.wrap(document);
|
| while (p) {
|
| if (p == doc) {
|
| return true;
|
| }
|
| - p = p.parentNode || p.host;
|
| + p = p.parentNode || p.nodeType === Node.DOCUMENT_FRAGMENT_NODE && p.host;
|
| }
|
| }
|
| function watchShadow(node) {
|
| @@ -5891,7 +6752,7 @@ CustomElements.addModule(function(scope) {
|
| }
|
| }
|
| }
|
| - function handler(mutations) {
|
| + function handler(root, mutations) {
|
| if (flags.dom) {
|
| var mx = mutations[0];
|
| if (mx && mx.type === "childList" && mx.addedNodes) {
|
| @@ -5906,13 +6767,14 @@ CustomElements.addModule(function(scope) {
|
| }
|
| console.group("mutations (%d) [%s]", mutations.length, u || "");
|
| }
|
| + var isAttached = inDocument(root);
|
| mutations.forEach(function(mx) {
|
| if (mx.type === "childList") {
|
| forEach(mx.addedNodes, function(n) {
|
| if (!n.localName) {
|
| return;
|
| }
|
| - addedNode(n);
|
| + addedNode(n, isAttached);
|
| });
|
| forEach(mx.removedNodes, function(n) {
|
| if (!n.localName) {
|
| @@ -5925,16 +6787,16 @@ CustomElements.addModule(function(scope) {
|
| flags.dom && console.groupEnd();
|
| }
|
| function takeRecords(node) {
|
| - node = wrap(node);
|
| + node = window.wrap(node);
|
| if (!node) {
|
| - node = wrap(document);
|
| + node = window.wrap(document);
|
| }
|
| while (node.parentNode) {
|
| node = node.parentNode;
|
| }
|
| var observer = node.__observer;
|
| if (observer) {
|
| - handler(observer.takeRecords());
|
| + handler(node, observer.takeRecords());
|
| takeMutations();
|
| }
|
| }
|
| @@ -5943,7 +6805,7 @@ CustomElements.addModule(function(scope) {
|
| if (inRoot.__observer) {
|
| return;
|
| }
|
| - var observer = new MutationObserver(handler);
|
| + var observer = new MutationObserver(handler.bind(this, inRoot));
|
| observer.observe(inRoot, {
|
| childList: true,
|
| subtree: true
|
| @@ -5951,9 +6813,10 @@ CustomElements.addModule(function(scope) {
|
| inRoot.__observer = observer;
|
| }
|
| function upgradeDocument(doc) {
|
| - doc = wrap(doc);
|
| + doc = window.wrap(doc);
|
| flags.dom && console.group("upgradeDocument: ", doc.baseURI.split("/").pop());
|
| - addedNode(doc);
|
| + var isMainDocument = doc === window.wrap(document);
|
| + addedNode(doc, isMainDocument);
|
| observe(doc);
|
| flags.dom && console.groupEnd();
|
| }
|
| @@ -5961,35 +6824,41 @@ CustomElements.addModule(function(scope) {
|
| forDocumentTree(doc, upgradeDocument);
|
| }
|
| var originalCreateShadowRoot = Element.prototype.createShadowRoot;
|
| - Element.prototype.createShadowRoot = function() {
|
| - var root = originalCreateShadowRoot.call(this);
|
| - CustomElements.watchShadow(this);
|
| - return root;
|
| - };
|
| + if (originalCreateShadowRoot) {
|
| + Element.prototype.createShadowRoot = function() {
|
| + var root = originalCreateShadowRoot.call(this);
|
| + window.CustomElements.watchShadow(this);
|
| + return root;
|
| + };
|
| + }
|
| scope.watchShadow = watchShadow;
|
| scope.upgradeDocumentTree = upgradeDocumentTree;
|
| + scope.upgradeDocument = upgradeDocument;
|
| scope.upgradeSubtree = addedSubtree;
|
| scope.upgradeAll = addedNode;
|
| - scope.attachedNode = attachedNode;
|
| + scope.attached = attached;
|
| scope.takeRecords = takeRecords;
|
| });
|
|
|
| -CustomElements.addModule(function(scope) {
|
| +window.CustomElements.addModule(function(scope) {
|
| var flags = scope.flags;
|
| - function upgrade(node) {
|
| + function upgrade(node, isAttached) {
|
| + if (node.localName === "template") {
|
| + if (window.HTMLTemplateElement && HTMLTemplateElement.decorate) {
|
| + HTMLTemplateElement.decorate(node);
|
| + }
|
| + }
|
| if (!node.__upgraded__ && node.nodeType === Node.ELEMENT_NODE) {
|
| var is = node.getAttribute("is");
|
| - var definition = scope.getRegisteredDefinition(is || node.localName);
|
| + var definition = scope.getRegisteredDefinition(node.localName) || scope.getRegisteredDefinition(is);
|
| if (definition) {
|
| - if (is && definition.tag == node.localName) {
|
| - return upgradeWithDefinition(node, definition);
|
| - } else if (!is && !definition.extends) {
|
| - return upgradeWithDefinition(node, definition);
|
| + if (is && definition.tag == node.localName || !is && !definition.extends) {
|
| + return upgradeWithDefinition(node, definition, isAttached);
|
| }
|
| }
|
| }
|
| }
|
| - function upgradeWithDefinition(element, definition) {
|
| + function upgradeWithDefinition(element, definition, isAttached) {
|
| flags.upgrade && console.group("upgrade:", element.localName);
|
| if (definition.is) {
|
| element.setAttribute("is", definition.is);
|
| @@ -5997,8 +6866,10 @@ CustomElements.addModule(function(scope) {
|
| implementPrototype(element, definition);
|
| element.__upgraded__ = true;
|
| created(element);
|
| - scope.attachedNode(element);
|
| - scope.upgradeSubtree(element);
|
| + if (isAttached) {
|
| + scope.attached(element);
|
| + }
|
| + scope.upgradeSubtree(element, isAttached);
|
| flags.upgrade && console.groupEnd();
|
| return element;
|
| }
|
| @@ -6034,9 +6905,10 @@ CustomElements.addModule(function(scope) {
|
| scope.implementPrototype = implementPrototype;
|
| });
|
|
|
| -CustomElements.addModule(function(scope) {
|
| +window.CustomElements.addModule(function(scope) {
|
| + var isIE = scope.isIE;
|
| var upgradeDocumentTree = scope.upgradeDocumentTree;
|
| - var upgrade = scope.upgrade;
|
| + var upgradeAll = scope.upgradeAll;
|
| var upgradeWithDefinition = scope.upgradeWithDefinition;
|
| var implementPrototype = scope.implementPrototype;
|
| var useNative = scope.useNative;
|
| @@ -6125,17 +6997,23 @@ CustomElements.addModule(function(scope) {
|
| var nativePrototype = HTMLElement.prototype;
|
| if (definition.is) {
|
| var inst = document.createElement(definition.tag);
|
| - var expectedPrototype = Object.getPrototypeOf(inst);
|
| - if (expectedPrototype === definition.prototype) {
|
| - nativePrototype = expectedPrototype;
|
| - }
|
| + nativePrototype = Object.getPrototypeOf(inst);
|
| }
|
| var proto = definition.prototype, ancestor;
|
| - while (proto && proto !== nativePrototype) {
|
| + var foundPrototype = false;
|
| + while (proto) {
|
| + if (proto == nativePrototype) {
|
| + foundPrototype = true;
|
| + }
|
| ancestor = Object.getPrototypeOf(proto);
|
| - proto.__proto__ = ancestor;
|
| + if (ancestor) {
|
| + proto.__proto__ = ancestor;
|
| + }
|
| proto = ancestor;
|
| }
|
| + if (!foundPrototype) {
|
| + console.warn(definition.tag + " prototype not found in prototype chain for " + definition.is);
|
| + }
|
| definition.native = nativePrototype;
|
| }
|
| }
|
| @@ -6165,6 +7043,12 @@ CustomElements.addModule(function(scope) {
|
| }
|
| }
|
| function createElement(tag, typeExtension) {
|
| + if (tag) {
|
| + tag = tag.toLowerCase();
|
| + }
|
| + if (typeExtension) {
|
| + typeExtension = typeExtension.toLowerCase();
|
| + }
|
| var definition = getRegisteredDefinition(typeExtension || tag);
|
| if (definition) {
|
| if (tag == definition.tag && typeExtension == definition.is) {
|
| @@ -6186,17 +7070,14 @@ CustomElements.addModule(function(scope) {
|
| }
|
| return element;
|
| }
|
| - function cloneNode(deep) {
|
| - var n = domCloneNode.call(this, deep);
|
| - upgrade(n);
|
| - return n;
|
| - }
|
| var domCreateElement = document.createElement.bind(document);
|
| var domCreateElementNS = document.createElementNS.bind(document);
|
| - var domCloneNode = Node.prototype.cloneNode;
|
| var isInstance;
|
| if (!Object.__proto__ && !useNative) {
|
| isInstance = function(obj, ctor) {
|
| + if (obj instanceof ctor) {
|
| + return true;
|
| + }
|
| var p = obj;
|
| while (p) {
|
| if (p === ctor.prototype) {
|
| @@ -6211,10 +7092,34 @@ CustomElements.addModule(function(scope) {
|
| return obj instanceof base;
|
| };
|
| }
|
| + function wrapDomMethodToForceUpgrade(obj, methodName) {
|
| + var orig = obj[methodName];
|
| + obj[methodName] = function() {
|
| + var n = orig.apply(this, arguments);
|
| + upgradeAll(n);
|
| + return n;
|
| + };
|
| + }
|
| + wrapDomMethodToForceUpgrade(Node.prototype, "cloneNode");
|
| + wrapDomMethodToForceUpgrade(document, "importNode");
|
| + if (isIE) {
|
| + (function() {
|
| + var importNode = document.importNode;
|
| + document.importNode = function() {
|
| + var n = importNode.apply(document, arguments);
|
| + if (n.nodeType == n.DOCUMENT_FRAGMENT_NODE) {
|
| + var f = document.createDocumentFragment();
|
| + f.appendChild(n);
|
| + return f;
|
| + } else {
|
| + return n;
|
| + }
|
| + };
|
| + })();
|
| + }
|
| document.registerElement = register;
|
| document.createElement = createElement;
|
| document.createElementNS = createElementNS;
|
| - Node.prototype.cloneNode = cloneNode;
|
| scope.registry = registry;
|
| scope.instanceof = isInstance;
|
| scope.reservedTagList = reservedTagList;
|
| @@ -6225,6 +7130,7 @@ CustomElements.addModule(function(scope) {
|
| (function(scope) {
|
| var useNative = scope.useNative;
|
| var initializeModules = scope.initializeModules;
|
| + var isIE = scope.isIE;
|
| if (useNative) {
|
| var nop = function() {};
|
| scope.watchShadow = nop;
|
| @@ -6240,49 +7146,48 @@ CustomElements.addModule(function(scope) {
|
| initializeModules();
|
| }
|
| var upgradeDocumentTree = scope.upgradeDocumentTree;
|
| + var upgradeDocument = scope.upgradeDocument;
|
| if (!window.wrap) {
|
| if (window.ShadowDOMPolyfill) {
|
| - window.wrap = ShadowDOMPolyfill.wrapIfNeeded;
|
| - window.unwrap = ShadowDOMPolyfill.unwrapIfNeeded;
|
| + window.wrap = window.ShadowDOMPolyfill.wrapIfNeeded;
|
| + window.unwrap = window.ShadowDOMPolyfill.unwrapIfNeeded;
|
| } else {
|
| window.wrap = window.unwrap = function(node) {
|
| return node;
|
| };
|
| }
|
| }
|
| - function bootstrap() {
|
| - upgradeDocumentTree(wrap(document));
|
| - if (window.HTMLImports) {
|
| - HTMLImports.__importsParsingHook = function(elt) {
|
| - upgradeDocumentTree(wrap(elt.import));
|
| - };
|
| - }
|
| - CustomElements.ready = true;
|
| - setTimeout(function() {
|
| - CustomElements.readyTime = Date.now();
|
| - if (window.HTMLImports) {
|
| - CustomElements.elapsed = CustomElements.readyTime - HTMLImports.readyTime;
|
| + if (window.HTMLImports) {
|
| + window.HTMLImports.__importsParsingHook = function(elt) {
|
| + if (elt.import) {
|
| + upgradeDocument(wrap(elt.import));
|
| }
|
| - document.dispatchEvent(new CustomEvent("WebComponentsReady", {
|
| - bubbles: true
|
| - }));
|
| - });
|
| + };
|
| }
|
| - if (typeof window.CustomEvent !== "function") {
|
| - window.CustomEvent = function(inType, params) {
|
| - params = params || {};
|
| - var e = document.createEvent("CustomEvent");
|
| - e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable), params.detail);
|
| - return e;
|
| + function bootstrap() {
|
| + upgradeDocumentTree(window.wrap(document));
|
| + window.CustomElements.ready = true;
|
| + var requestAnimationFrame = window.requestAnimationFrame || function(f) {
|
| + setTimeout(f, 16);
|
| };
|
| - window.CustomEvent.prototype = window.Event.prototype;
|
| + requestAnimationFrame(function() {
|
| + setTimeout(function() {
|
| + window.CustomElements.readyTime = Date.now();
|
| + if (window.HTMLImports) {
|
| + window.CustomElements.elapsed = window.CustomElements.readyTime - window.HTMLImports.readyTime;
|
| + }
|
| + document.dispatchEvent(new CustomEvent("WebComponentsReady", {
|
| + bubbles: true
|
| + }));
|
| + });
|
| + });
|
| }
|
| if (document.readyState === "complete" || scope.flags.eager) {
|
| bootstrap();
|
| } else if (document.readyState === "interactive" && !window.attachEvent && (!window.HTMLImports || window.HTMLImports.ready)) {
|
| bootstrap();
|
| } else {
|
| - var loadEvent = window.HTMLImports && !HTMLImports.ready ? "HTMLImportsLoaded" : "DOMContentLoaded";
|
| + var loadEvent = window.HTMLImports && !window.HTMLImports.ready ? "HTMLImportsLoaded" : "DOMContentLoaded";
|
| window.addEventListener(loadEvent, bootstrap);
|
| }
|
| })(window.CustomElements);
|
| @@ -6302,66 +7207,6 @@ CustomElements.addModule(function(scope) {
|
| })(window.WebComponents);
|
|
|
| (function(scope) {
|
| - "use strict";
|
| - if (!window.performance) {
|
| - var start = Date.now();
|
| - window.performance = {
|
| - now: function() {
|
| - return Date.now() - start;
|
| - }
|
| - };
|
| - }
|
| - if (!window.requestAnimationFrame) {
|
| - window.requestAnimationFrame = function() {
|
| - var nativeRaf = window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame;
|
| - return nativeRaf ? function(callback) {
|
| - return nativeRaf(function() {
|
| - callback(performance.now());
|
| - });
|
| - } : function(callback) {
|
| - return window.setTimeout(callback, 1e3 / 60);
|
| - };
|
| - }();
|
| - }
|
| - if (!window.cancelAnimationFrame) {
|
| - window.cancelAnimationFrame = function() {
|
| - return window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || function(id) {
|
| - clearTimeout(id);
|
| - };
|
| - }();
|
| - }
|
| - var elementDeclarations = [];
|
| - var polymerStub = function(name, dictionary) {
|
| - if (typeof name !== "string" && arguments.length === 1) {
|
| - Array.prototype.push.call(arguments, document._currentScript);
|
| - }
|
| - elementDeclarations.push(arguments);
|
| - };
|
| - window.Polymer = polymerStub;
|
| - scope.consumeDeclarations = function(callback) {
|
| - scope.consumeDeclarations = function() {
|
| - throw "Possible attempt to load Polymer twice";
|
| - };
|
| - if (callback) {
|
| - callback(elementDeclarations);
|
| - }
|
| - elementDeclarations = null;
|
| - };
|
| - function installPolymerWarning() {
|
| - if (window.Polymer === polymerStub) {
|
| - window.Polymer = function() {
|
| - throw new Error("You tried to use polymer without loading it first. To " + 'load polymer, <link rel="import" href="' + 'components/polymer/polymer.html">');
|
| - };
|
| - }
|
| - }
|
| - if (HTMLImports.useNative) {
|
| - installPolymerWarning();
|
| - } else {
|
| - addEventListener("DOMContentLoaded", installPolymerWarning);
|
| - }
|
| -})(window.WebComponents);
|
| -
|
| -(function(scope) {
|
| var style = document.createElement("style");
|
| style.textContent = "" + "body {" + "transition: opacity ease-in 0.2s;" + " } \n" + "body[unresolved] {" + "opacity: 0; display: block; overflow: hidden; position: relative;" + " } \n";
|
| var head = document.querySelector("head");
|
| @@ -6370,4 +7215,4 @@ CustomElements.addModule(function(scope) {
|
|
|
| (function(scope) {
|
| window.Platform = scope;
|
| -})(window.WebComponents);
|
| +})(window.WebComponents);
|
|
|