UNPKG

spincycle

Version:

A reactive message router and object manager that lets clients subscribe to object property changes on the server

1,954 lines 54.2 kB
<!-- @license Copyright (c) 2014 The Polymer Project Authors. All rights reserved. This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt 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 --><link rel="import" href="polymer-micro.html"><script>Polymer.Base._addFeature({ _prepTemplate: function () { if (this._template === undefined) { this._template = Polymer.DomModule.import(this.is, 'template'); } if (this._template && this._template.hasAttribute('is')) { this._warn(this._logf('_prepTemplate', 'top-level Polymer template ' + 'must not be a type-extension, found', this._template, 'Move inside simple <template>.')); } if (this._template && !this._template.content && window.HTMLTemplateElement && HTMLTemplateElement.decorate) { HTMLTemplateElement.decorate(this._template); } }, _stampTemplate: function () { if (this._template) { this.root = this.instanceTemplate(this._template); } }, instanceTemplate: function (template) { var dom = document.importNode(template._content || template.content, true); return dom; } });(function () { var baseAttachedCallback = Polymer.Base.attachedCallback; Polymer.Base._addFeature({ _hostStack: [], ready: function () { }, _registerHost: function (host) { this.dataHost = host = host || Polymer.Base._hostStack[Polymer.Base._hostStack.length - 1]; if (host && host._clients) { host._clients.push(this); } this._clients = null; this._clientsReadied = false; }, _beginHosting: function () { Polymer.Base._hostStack.push(this); if (!this._clients) { this._clients = []; } }, _endHosting: function () { Polymer.Base._hostStack.pop(); }, _tryReady: function () { this._readied = false; if (this._canReady()) { this._ready(); } }, _canReady: function () { return !this.dataHost || this.dataHost._clientsReadied; }, _ready: function () { this._beforeClientsReady(); if (this._template) { this._setupRoot(); this._readyClients(); } this._clientsReadied = true; this._clients = null; this._afterClientsReady(); this._readySelf(); }, _readyClients: function () { this._beginDistribute(); var c$ = this._clients; if (c$) { for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { c._ready(); } } this._finishDistribute(); }, _readySelf: function () { this._doBehavior('ready'); this._readied = true; if (this._attachedPending) { this._attachedPending = false; this.attachedCallback(); } }, _beforeClientsReady: function () { }, _afterClientsReady: function () { }, _beforeAttached: function () { }, attachedCallback: function () { if (this._readied) { this._beforeAttached(); baseAttachedCallback.call(this); } else { this._attachedPending = true; } } }); }());Polymer.ArraySplice = function () { function newSplice(index, removed, addedCount) { return { index: index, removed: removed, addedCount: addedCount }; } var EDIT_LEAVE = 0; var EDIT_UPDATE = 1; var EDIT_ADD = 2; var EDIT_DELETE = 3; function ArraySplice() { } ArraySplice.prototype = { calcEditDistances: function (current, currentStart, currentEnd, old, oldStart, oldEnd) { var rowCount = oldEnd - oldStart + 1; var columnCount = currentEnd - currentStart + 1; var distances = new Array(rowCount); for (var i = 0; i < rowCount; i++) { distances[i] = new Array(columnCount); distances[i][0] = i; } for (var j = 0; j < columnCount; j++) distances[0][j] = j; for (i = 1; i < rowCount; i++) { for (j = 1; j < columnCount; j++) { if (this.equals(current[currentStart + j - 1], old[oldStart + i - 1])) distances[i][j] = distances[i - 1][j - 1]; else { var north = distances[i - 1][j] + 1; var west = distances[i][j - 1] + 1; distances[i][j] = north < west ? north : west; } } } return distances; }, spliceOperationsFromEditDistances: function (distances) { var i = distances.length - 1; var j = distances[0].length - 1; var current = distances[i][j]; var edits = []; while (i > 0 || j > 0) { if (i == 0) { edits.push(EDIT_ADD); j--; continue; } if (j == 0) { edits.push(EDIT_DELETE); i--; continue; } var northWest = distances[i - 1][j - 1]; var west = distances[i - 1][j]; var north = distances[i][j - 1]; var min; if (west < north) min = west < northWest ? west : northWest; else min = north < northWest ? north : northWest; if (min == northWest) { if (northWest == current) { edits.push(EDIT_LEAVE); } else { edits.push(EDIT_UPDATE); current = northWest; } i--; j--; } else if (min == west) { edits.push(EDIT_DELETE); i--; current = west; } else { edits.push(EDIT_ADD); j--; current = north; } } edits.reverse(); return edits; }, calcSplices: function (current, currentStart, currentEnd, old, oldStart, oldEnd) { var prefixCount = 0; var suffixCount = 0; var minLength = Math.min(currentEnd - currentStart, oldEnd - oldStart); if (currentStart == 0 && oldStart == 0) prefixCount = this.sharedPrefix(current, old, minLength); if (currentEnd == current.length && oldEnd == old.length) suffixCount = this.sharedSuffix(current, old, minLength - prefixCount); currentStart += prefixCount; oldStart += prefixCount; currentEnd -= suffixCount; oldEnd -= suffixCount; if (currentEnd - currentStart == 0 && oldEnd - oldStart == 0) return []; if (currentStart == currentEnd) { var splice = newSplice(currentStart, [], 0); while (oldStart < oldEnd) splice.removed.push(old[oldStart++]); return [splice]; } else if (oldStart == oldEnd) return [newSplice(currentStart, [], currentEnd - currentStart)]; var ops = this.spliceOperationsFromEditDistances(this.calcEditDistances(current, currentStart, currentEnd, old, oldStart, oldEnd)); splice = undefined; var splices = []; var index = currentStart; var oldIndex = oldStart; for (var i = 0; i < ops.length; i++) { switch (ops[i]) { case EDIT_LEAVE: if (splice) { splices.push(splice); splice = undefined; } index++; oldIndex++; break; case EDIT_UPDATE: if (!splice) splice = newSplice(index, [], 0); splice.addedCount++; index++; splice.removed.push(old[oldIndex]); oldIndex++; break; case EDIT_ADD: if (!splice) splice = newSplice(index, [], 0); splice.addedCount++; index++; break; case EDIT_DELETE: if (!splice) splice = newSplice(index, [], 0); splice.removed.push(old[oldIndex]); oldIndex++; break; } } if (splice) { splices.push(splice); } return splices; }, sharedPrefix: function (current, old, searchLength) { for (var i = 0; i < searchLength; i++) if (!this.equals(current[i], old[i])) return i; return searchLength; }, sharedSuffix: function (current, old, searchLength) { var index1 = current.length; var index2 = old.length; var count = 0; while (count < searchLength && this.equals(current[--index1], old[--index2])) count++; return count; }, calculateSplices: function (current, previous) { return this.calcSplices(current, 0, current.length, previous, 0, previous.length); }, equals: function (currentValue, previousValue) { return currentValue === previousValue; } }; return new ArraySplice(); }();Polymer.domInnerHTML = function () { var escapeAttrRegExp = /[&\u00A0"]/g; var escapeDataRegExp = /[&\u00A0<>]/g; function escapeReplace(c) { switch (c) { case '&': return '&amp;'; case '<': return '&lt;'; case '>': return '&gt;'; case '"': return '&quot;'; case '\xA0': return '&nbsp;'; } } function escapeAttr(s) { return s.replace(escapeAttrRegExp, escapeReplace); } function escapeData(s) { return s.replace(escapeDataRegExp, escapeReplace); } function makeSet(arr) { var set = {}; for (var i = 0; i < arr.length; i++) { set[arr[i]] = true; } return set; } 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' ]); function getOuterHTML(node, parentNode, composed) { switch (node.nodeType) { case Node.ELEMENT_NODE: var tagName = node.localName; var s = '<' + tagName; var attrs = node.attributes; 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, composed) + '</' + tagName + '>'; case Node.TEXT_NODE: var data = node.data; if (parentNode && plaintextParents[parentNode.localName]) { return data; } return escapeData(data); case Node.COMMENT_NODE: return '<!--' + node.data + '-->'; default: console.error(node); throw new Error('not implemented'); } } function getInnerHTML(node, composed) { if (node instanceof HTMLTemplateElement) node = node.content; var s = ''; var c$ = Polymer.dom(node).childNodes; for (var i = 0, l = c$.length, child; i < l && (child = c$[i]); i++) { s += getOuterHTML(child, node, composed); } return s; } return { getInnerHTML: getInnerHTML }; }();(function () { 'use strict'; var nativeInsertBefore = Element.prototype.insertBefore; var nativeAppendChild = Element.prototype.appendChild; var nativeRemoveChild = Element.prototype.removeChild; Polymer.TreeApi = { arrayCopyChildNodes: function (parent) { var copy = [], i = 0; for (var n = parent.firstChild; n; n = n.nextSibling) { copy[i++] = n; } return copy; }, arrayCopyChildren: function (parent) { var copy = [], i = 0; for (var n = parent.firstElementChild; n; n = n.nextElementSibling) { copy[i++] = n; } return copy; }, arrayCopy: function (a$) { var l = a$.length; var copy = new Array(l); for (var i = 0; i < l; i++) { copy[i] = a$[i]; } return copy; } }; Polymer.TreeApi.Logical = { hasParentNode: function (node) { return Boolean(node.__dom && node.__dom.parentNode); }, hasChildNodes: function (node) { return Boolean(node.__dom && node.__dom.childNodes !== undefined); }, getChildNodes: function (node) { return this.hasChildNodes(node) ? this._getChildNodes(node) : node.childNodes; }, _getChildNodes: function (node) { if (!node.__dom.childNodes) { node.__dom.childNodes = []; for (var n = node.__dom.firstChild; n; n = n.__dom.nextSibling) { node.__dom.childNodes.push(n); } } return node.__dom.childNodes; }, getParentNode: function (node) { return node.__dom && node.__dom.parentNode !== undefined ? node.__dom.parentNode : node.parentNode; }, getFirstChild: function (node) { return node.__dom && node.__dom.firstChild !== undefined ? node.__dom.firstChild : node.firstChild; }, getLastChild: function (node) { return node.__dom && node.__dom.lastChild !== undefined ? node.__dom.lastChild : node.lastChild; }, getNextSibling: function (node) { return node.__dom && node.__dom.nextSibling !== undefined ? node.__dom.nextSibling : node.nextSibling; }, getPreviousSibling: function (node) { return node.__dom && node.__dom.previousSibling !== undefined ? node.__dom.previousSibling : node.previousSibling; }, getFirstElementChild: function (node) { return node.__dom && node.__dom.firstChild !== undefined ? this._getFirstElementChild(node) : node.firstElementChild; }, _getFirstElementChild: function (node) { var n = node.__dom.firstChild; while (n && n.nodeType !== Node.ELEMENT_NODE) { n = n.__dom.nextSibling; } return n; }, getLastElementChild: function (node) { return node.__dom && node.__dom.lastChild !== undefined ? this._getLastElementChild(node) : node.lastElementChild; }, _getLastElementChild: function (node) { var n = node.__dom.lastChild; while (n && n.nodeType !== Node.ELEMENT_NODE) { n = n.__dom.previousSibling; } return n; }, getNextElementSibling: function (node) { return node.__dom && node.__dom.nextSibling !== undefined ? this._getNextElementSibling(node) : node.nextElementSibling; }, _getNextElementSibling: function (node) { var n = node.__dom.nextSibling; while (n && n.nodeType !== Node.ELEMENT_NODE) { n = n.__dom.nextSibling; } return n; }, getPreviousElementSibling: function (node) { return node.__dom && node.__dom.previousSibling !== undefined ? this._getPreviousElementSibling(node) : node.previousElementSibling; }, _getPreviousElementSibling: function (node) { var n = node.__dom.previousSibling; while (n && n.nodeType !== Node.ELEMENT_NODE) { n = n.__dom.previousSibling; } return n; }, saveChildNodes: function (node) { if (!this.hasChildNodes(node)) { node.__dom = node.__dom || {}; node.__dom.firstChild = node.firstChild; node.__dom.lastChild = node.lastChild; node.__dom.childNodes = []; for (var n = node.firstChild; n; n = n.nextSibling) { n.__dom = n.__dom || {}; n.__dom.parentNode = node; node.__dom.childNodes.push(n); n.__dom.nextSibling = n.nextSibling; n.__dom.previousSibling = n.previousSibling; } } }, recordInsertBefore: function (node, container, ref_node) { container.__dom.childNodes = null; if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { for (var n = node.firstChild; n; n = n.nextSibling) { this._linkNode(n, container, ref_node); } } else { this._linkNode(node, container, ref_node); } }, _linkNode: function (node, container, ref_node) { node.__dom = node.__dom || {}; container.__dom = container.__dom || {}; if (ref_node) { ref_node.__dom = ref_node.__dom || {}; } node.__dom.previousSibling = ref_node ? ref_node.__dom.previousSibling : container.__dom.lastChild; if (node.__dom.previousSibling) { node.__dom.previousSibling.__dom.nextSibling = node; } node.__dom.nextSibling = ref_node || null; if (node.__dom.nextSibling) { node.__dom.nextSibling.__dom.previousSibling = node; } node.__dom.parentNode = container; if (ref_node) { if (ref_node === container.__dom.firstChild) { container.__dom.firstChild = node; } } else { container.__dom.lastChild = node; if (!container.__dom.firstChild) { container.__dom.firstChild = node; } } container.__dom.childNodes = null; }, recordRemoveChild: function (node, container) { node.__dom = node.__dom || {}; container.__dom = container.__dom || {}; if (node === container.__dom.firstChild) { container.__dom.firstChild = node.__dom.nextSibling; } if (node === container.__dom.lastChild) { container.__dom.lastChild = node.__dom.previousSibling; } var p = node.__dom.previousSibling; var n = node.__dom.nextSibling; if (p) { p.__dom.nextSibling = n; } if (n) { n.__dom.previousSibling = p; } node.__dom.parentNode = node.__dom.previousSibling = node.__dom.nextSibling = undefined; container.__dom.childNodes = null; } }; Polymer.TreeApi.Composed = { getChildNodes: function (node) { return Polymer.TreeApi.arrayCopyChildNodes(node); }, getParentNode: function (node) { return node.parentNode; }, clearChildNodes: function (node) { node.textContent = ''; }, insertBefore: function (parentNode, newChild, refChild) { return nativeInsertBefore.call(parentNode, newChild, refChild || null); }, appendChild: function (parentNode, newChild) { return nativeAppendChild.call(parentNode, newChild); }, removeChild: function (parentNode, node) { return nativeRemoveChild.call(parentNode, node); } }; }());Polymer.DomApi = function () { 'use strict'; var Settings = Polymer.Settings; var TreeApi = Polymer.TreeApi; var DomApi = function (node) { this.node = needsToWrap ? DomApi.wrap(node) : node; }; var needsToWrap = Settings.hasShadow && !Settings.nativeShadow; DomApi.wrap = window.wrap ? window.wrap : function (node) { return node; }; DomApi.prototype = { flush: function () { Polymer.dom.flush(); }, deepContains: function (node) { if (this.node.contains(node)) { return true; } var n = node; var doc = node.ownerDocument; while (n && n !== doc && n !== this.node) { n = Polymer.dom(n).parentNode || n.host; } return n === this.node; }, queryDistributedElements: function (selector) { var c$ = this.getEffectiveChildNodes(); var list = []; for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { if (c.nodeType === Node.ELEMENT_NODE && DomApi.matchesSelector.call(c, selector)) { list.push(c); } } return list; }, getEffectiveChildNodes: function () { var list = []; var c$ = this.childNodes; for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { if (c.localName === CONTENT) { var d$ = dom(c).getDistributedNodes(); for (var j = 0; j < d$.length; j++) { list.push(d$[j]); } } else { list.push(c); } } return list; }, observeNodes: function (callback) { if (callback) { if (!this.observer) { this.observer = this.node.localName === CONTENT ? new DomApi.DistributedNodesObserver(this) : new DomApi.EffectiveNodesObserver(this); } return this.observer.addListener(callback); } }, unobserveNodes: function (handle) { if (this.observer) { this.observer.removeListener(handle); } }, notifyObserver: function () { if (this.observer) { this.observer.notify(); } }, _query: function (matcher, node, halter) { node = node || this.node; var list = []; this._queryElements(TreeApi.Logical.getChildNodes(node), matcher, halter, list); return list; }, _queryElements: function (elements, matcher, halter, list) { for (var i = 0, l = elements.length, c; i < l && (c = elements[i]); i++) { if (c.nodeType === Node.ELEMENT_NODE) { if (this._queryElement(c, matcher, halter, list)) { return true; } } } }, _queryElement: function (node, matcher, halter, list) { var result = matcher(node); if (result) { list.push(node); } if (halter && halter(result)) { return result; } this._queryElements(TreeApi.Logical.getChildNodes(node), matcher, halter, list); } }; var CONTENT = DomApi.CONTENT = 'content'; var dom = DomApi.factory = function (node) { node = node || document; if (!node.__domApi) { node.__domApi = new DomApi.ctor(node); } return node.__domApi; }; DomApi.hasApi = function (node) { return Boolean(node.__domApi); }; DomApi.ctor = DomApi; Polymer.dom = function (obj, patch) { if (obj instanceof Event) { return Polymer.EventApi.factory(obj); } else { return DomApi.factory(obj, patch); } }; var p = Element.prototype; DomApi.matchesSelector = p.matches || p.matchesSelector || p.mozMatchesSelector || p.msMatchesSelector || p.oMatchesSelector || p.webkitMatchesSelector; return DomApi; }();(function () { 'use strict'; var Settings = Polymer.Settings; var DomApi = Polymer.DomApi; var dom = DomApi.factory; var TreeApi = Polymer.TreeApi; var getInnerHTML = Polymer.domInnerHTML.getInnerHTML; var CONTENT = DomApi.CONTENT; if (Settings.useShadow) { return; } var nativeCloneNode = Element.prototype.cloneNode; var nativeImportNode = Document.prototype.importNode; Polymer.Base.extend(DomApi.prototype, { _lazyDistribute: function (host) { if (host.shadyRoot && host.shadyRoot._distributionClean) { host.shadyRoot._distributionClean = false; Polymer.dom.addDebouncer(host.debounce('_distribute', host._distributeContent)); } }, appendChild: function (node) { return this.insertBefore(node); }, insertBefore: function (node, ref_node) { if (ref_node && TreeApi.Logical.getParentNode(ref_node) !== this.node) { throw Error('The ref_node to be inserted before is not a child ' + 'of this node'); } if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) { var parent = TreeApi.Logical.getParentNode(node); if (parent) { if (DomApi.hasApi(parent)) { dom(parent).notifyObserver(); } this._removeNode(node); } else { this._removeOwnerShadyRoot(node); } } if (!this._addNode(node, ref_node)) { if (ref_node) { ref_node = ref_node.localName === CONTENT ? this._firstComposedNode(ref_node) : ref_node; } var container = this.node._isShadyRoot ? this.node.host : this.node; if (ref_node) { TreeApi.Composed.insertBefore(container, node, ref_node); } else { TreeApi.Composed.appendChild(container, node); } } this.notifyObserver(); return node; }, _addNode: function (node, ref_node) { var root = this.getOwnerRoot(); if (root) { var ipAdded = this._maybeAddInsertionPoint(node, this.node); if (!root._invalidInsertionPoints) { root._invalidInsertionPoints = ipAdded; } this._addNodeToHost(root.host, node); } if (TreeApi.Logical.hasChildNodes(this.node)) { TreeApi.Logical.recordInsertBefore(node, this.node, ref_node); } var handled = this._maybeDistribute(node) || this.node.shadyRoot; if (handled) { if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { while (node.firstChild) { TreeApi.Composed.removeChild(node, node.firstChild); } } else { var parent = TreeApi.Composed.getParentNode(node); if (parent) { TreeApi.Composed.removeChild(parent, node); } } } return handled; }, removeChild: function (node) { if (TreeApi.Logical.getParentNode(node) !== this.node) { throw Error('The node to be removed is not a child of this node: ' + node); } if (!this._removeNode(node)) { var container = this.node._isShadyRoot ? this.node.host : this.node; var parent = TreeApi.Composed.getParentNode(node); if (container === parent) { TreeApi.Composed.removeChild(container, node); } } this.notifyObserver(); return node; }, _removeNode: function (node) { var logicalParent = TreeApi.Logical.hasParentNode(node) && TreeApi.Logical.getParentNode(node); var distributed; var root = this._ownerShadyRootForNode(node); if (logicalParent) { distributed = dom(node)._maybeDistributeParent(); TreeApi.Logical.recordRemoveChild(node, logicalParent); if (root && this._removeDistributedChildren(root, node)) { root._invalidInsertionPoints = true; this._lazyDistribute(root.host); } } this._removeOwnerShadyRoot(node); if (root) { this._removeNodeFromHost(root.host, node); } return distributed; }, replaceChild: function (node, ref_node) { this.insertBefore(node, ref_node); this.removeChild(ref_node); return node; }, _hasCachedOwnerRoot: function (node) { return Boolean(node._ownerShadyRoot !== undefined); }, getOwnerRoot: function () { return this._ownerShadyRootForNode(this.node); }, _ownerShadyRootForNode: function (node) { if (!node) { return; } var root = node._ownerShadyRoot; if (root === undefined) { if (node._isShadyRoot) { root = node; } else { var parent = TreeApi.Logical.getParentNode(node); if (parent) { root = parent._isShadyRoot ? parent : this._ownerShadyRootForNode(parent); } else { root = null; } } if (root || document.documentElement.contains(node)) { node._ownerShadyRoot = root; } } return root; }, _maybeDistribute: function (node) { var fragContent = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && !node.__noContent && dom(node).querySelector(CONTENT); var wrappedContent = fragContent && TreeApi.Logical.getParentNode(fragContent).nodeType !== Node.DOCUMENT_FRAGMENT_NODE; var hasContent = fragContent || node.localName === CONTENT; if (hasContent) { var root = this.getOwnerRoot(); if (root) { this._lazyDistribute(root.host); } } var needsDist = this._nodeNeedsDistribution(this.node); if (needsDist) { this._lazyDistribute(this.node); } return needsDist || hasContent && !wrappedContent; }, _maybeAddInsertionPoint: function (node, parent) { var added; if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && !node.__noContent) { var c$ = dom(node).querySelectorAll(CONTENT); for (var i = 0, n, np, na; i < c$.length && (n = c$[i]); i++) { np = TreeApi.Logical.getParentNode(n); if (np === node) { np = parent; } na = this._maybeAddInsertionPoint(n, np); added = added || na; } } else if (node.localName === CONTENT) { TreeApi.Logical.saveChildNodes(parent); TreeApi.Logical.saveChildNodes(node); added = true; } return added; }, _updateInsertionPoints: function (host) { var i$ = host.shadyRoot._insertionPoints = dom(host.shadyRoot).querySelectorAll(CONTENT); for (var i = 0, c; i < i$.length; i++) { c = i$[i]; TreeApi.Logical.saveChildNodes(c); TreeApi.Logical.saveChildNodes(TreeApi.Logical.getParentNode(c)); } }, _nodeNeedsDistribution: function (node) { return node && node.shadyRoot && DomApi.hasInsertionPoint(node.shadyRoot); }, _addNodeToHost: function (host, node) { if (host._elementAdd) { host._elementAdd(node); } }, _removeNodeFromHost: function (host, node) { if (host._elementRemove) { host._elementRemove(node); } }, _removeDistributedChildren: function (root, container) { var hostNeedsDist; var ip$ = root._insertionPoints; for (var i = 0; i < ip$.length; i++) { var content = ip$[i]; if (this._contains(container, content)) { var dc$ = dom(content).getDistributedNodes(); for (var j = 0; j < dc$.length; j++) { hostNeedsDist = true; var node = dc$[j]; var parent = TreeApi.Composed.getParentNode(node); if (parent) { TreeApi.Composed.removeChild(parent, node); } } } } return hostNeedsDist; }, _contains: function (container, node) { while (node) { if (node == container) { return true; } node = TreeApi.Logical.getParentNode(node); } }, _removeOwnerShadyRoot: function (node) { if (this._hasCachedOwnerRoot(node)) { var c$ = TreeApi.Logical.getChildNodes(node); for (var i = 0, l = c$.length, n; i < l && (n = c$[i]); i++) { this._removeOwnerShadyRoot(n); } } node._ownerShadyRoot = undefined; }, _firstComposedNode: function (content) { var n$ = dom(content).getDistributedNodes(); for (var i = 0, l = n$.length, n, p$; i < l && (n = n$[i]); i++) { p$ = dom(n).getDestinationInsertionPoints(); if (p$[p$.length - 1] === content) { return n; } } }, querySelector: function (selector) { var result = this._query(function (n) { return DomApi.matchesSelector.call(n, selector); }, this.node, function (n) { return Boolean(n); })[0]; return result || null; }, querySelectorAll: function (selector) { return this._query(function (n) { return DomApi.matchesSelector.call(n, selector); }, this.node); }, getDestinationInsertionPoints: function () { return this.node._destinationInsertionPoints || []; }, getDistributedNodes: function () { return this.node._distributedNodes || []; }, _clear: function () { while (this.childNodes.length) { this.removeChild(this.childNodes[0]); } }, setAttribute: function (name, value) { this.node.setAttribute(name, value); this._maybeDistributeParent(); }, removeAttribute: function (name) { this.node.removeAttribute(name); this._maybeDistributeParent(); }, _maybeDistributeParent: function () { if (this._nodeNeedsDistribution(this.parentNode)) { this._lazyDistribute(this.parentNode); return true; } }, cloneNode: function (deep) { var n = nativeCloneNode.call(this.node, false); if (deep) { var c$ = this.childNodes; var d = dom(n); for (var i = 0, nc; i < c$.length; i++) { nc = dom(c$[i]).cloneNode(true); d.appendChild(nc); } } return n; }, importNode: function (externalNode, deep) { var doc = this.node instanceof Document ? this.node : this.node.ownerDocument; var n = nativeImportNode.call(doc, externalNode, false); if (deep) { var c$ = TreeApi.Logical.getChildNodes(externalNode); var d = dom(n); for (var i = 0, nc; i < c$.length; i++) { nc = dom(doc).importNode(c$[i], true); d.appendChild(nc); } } return n; }, _getComposedInnerHTML: function () { return getInnerHTML(this.node, true); } }); Object.defineProperties(DomApi.prototype, { activeElement: { get: function () { var active = document.activeElement; if (!active) { return null; } var isShadyRoot = !!this.node._isShadyRoot; if (this.node !== document) { if (!isShadyRoot) { return null; } if (this.node.host === active || !this.node.host.contains(active)) { return null; } } var activeRoot = dom(active).getOwnerRoot(); while (activeRoot && activeRoot !== this.node) { active = activeRoot.host; activeRoot = dom(active).getOwnerRoot(); } if (this.node === document) { return activeRoot ? null : active; } else { return activeRoot === this.node ? active : null; } }, configurable: true }, childNodes: { get: function () { var c$ = TreeApi.Logical.getChildNodes(this.node); return Array.isArray(c$) ? c$ : TreeApi.arrayCopyChildNodes(this.node); }, configurable: true }, children: { get: function () { if (TreeApi.Logical.hasChildNodes(this.node)) { return Array.prototype.filter.call(this.childNodes, function (n) { return n.nodeType === Node.ELEMENT_NODE; }); } else { return TreeApi.arrayCopyChildren(this.node); } }, configurable: true }, parentNode: { get: function () { return TreeApi.Logical.getParentNode(this.node); }, configurable: true }, firstChild: { get: function () { return TreeApi.Logical.getFirstChild(this.node); }, configurable: true }, lastChild: { get: function () { return TreeApi.Logical.getLastChild(this.node); }, configurable: true }, nextSibling: { get: function () { return TreeApi.Logical.getNextSibling(this.node); }, configurable: true }, previousSibling: { get: function () { return TreeApi.Logical.getPreviousSibling(this.node); }, configurable: true }, firstElementChild: { get: function () { return TreeApi.Logical.getFirstElementChild(this.node); }, configurable: true }, lastElementChild: { get: function () { return TreeApi.Logical.getLastElementChild(this.node); }, configurable: true }, nextElementSibling: { get: function () { return TreeApi.Logical.getNextElementSibling(this.node); }, configurable: true }, previousElementSibling: { get: function () { return TreeApi.Logical.getPreviousElementSibling(this.node); }, configurable: true }, textContent: { get: function () { var nt = this.node.nodeType; if (nt === Node.TEXT_NODE || nt === Node.COMMENT_NODE) { return this.node.textContent; } else { var tc = []; for (var i = 0, cn = this.childNodes, c; c = cn[i]; i++) { if (c.nodeType !== Node.COMMENT_NODE) { tc.push(c.textContent); } } return tc.join(''); } }, set: function (text) { var nt = this.node.nodeType; if (nt === Node.TEXT_NODE || nt === Node.COMMENT_NODE) { this.node.textContent = text; } else { this._clear(); if (text) { this.appendChild(document.createTextNode(text)); } } }, configurable: true }, innerHTML: { get: function () { var nt = this.node.nodeType; if (nt === Node.TEXT_NODE || nt === Node.COMMENT_NODE) { return null; } else { return getInnerHTML(this.node); } }, set: function (text) { var nt = this.node.nodeType; if (nt !== Node.TEXT_NODE || nt !== Node.COMMENT_NODE) { this._clear(); var d = document.createElement('div'); d.innerHTML = text; var c$ = TreeApi.arrayCopyChildNodes(d); for (var i = 0; i < c$.length; i++) { this.appendChild(c$[i]); } } }, configurable: true } }); DomApi.hasInsertionPoint = function (root) { return Boolean(root && root._insertionPoints.length); }; }());(function () { 'use strict'; var Settings = Polymer.Settings; var TreeApi = Polymer.TreeApi; var DomApi = Polymer.DomApi; if (!Settings.useShadow) { return; } Polymer.Base.extend(DomApi.prototype, { querySelectorAll: function (selector) { return TreeApi.arrayCopy(this.node.querySelectorAll(selector)); }, getOwnerRoot: function () { var n = this.node; while (n) { if (n.nodeType === Node.DOCUMENT_FRAGMENT_NODE && n.host) { return n; } n = n.parentNode; } }, importNode: function (externalNode, deep) { var doc = this.node instanceof Document ? this.node : this.node.ownerDocument; return doc.importNode(externalNode, deep); }, getDestinationInsertionPoints: function () { var n$ = this.node.getDestinationInsertionPoints && this.node.getDestinationInsertionPoints(); return n$ ? TreeApi.arrayCopy(n$) : []; }, getDistributedNodes: function () { var n$ = this.node.getDistributedNodes && this.node.getDistributedNodes(); return n$ ? TreeApi.arrayCopy(n$) : []; } }); Object.defineProperties(DomApi.prototype, { activeElement: { get: function () { var node = DomApi.wrap(this.node); var activeElement = node.activeElement; return node.contains(activeElement) ? activeElement : null; }, configurable: true }, childNodes: { get: function () { return TreeApi.arrayCopyChildNodes(this.node); }, configurable: true }, children: { get: function () { return TreeApi.arrayCopyChildren(this.node); }, configurable: true }, textContent: { get: function () { return this.node.textContent; }, set: function (value) { return this.node.textContent = value; }, configurable: true }, innerHTML: { get: function () { return this.node.innerHTML; }, set: function (value) { return this.node.innerHTML = value; }, configurable: true } }); var forwardMethods = function (m$) { for (var i = 0; i < m$.length; i++) { forwardMethod(m$[i]); } }; var forwardMethod = function (method) { DomApi.prototype[method] = function () { return this.node[method].apply(this.node, arguments); }; }; forwardMethods([ 'cloneNode', 'appendChild', 'insertBefore', 'removeChild', 'replaceChild', 'setAttribute', 'removeAttribute', 'querySelector' ]); var forwardProperties = function (f$) { for (var i = 0; i < f$.length; i++) { forwardProperty(f$[i]); } }; var forwardProperty = function (name) { Object.defineProperty(DomApi.prototype, name, { get: function () { return this.node[name]; }, configurable: true }); }; forwardProperties([ 'parentNode', 'firstChild', 'lastChild', 'nextSibling', 'previousSibling', 'firstElementChild', 'lastElementChild', 'nextElementSibling', 'previousElementSibling' ]); }());Polymer.Base.extend(Polymer.dom, { _flushGuard: 0, _FLUSH_MAX: 100, _needsTakeRecords: !Polymer.Settings.useNativeCustomElements, _debouncers: [], _staticFlushList: [], _finishDebouncer: null, flush: function () { this._flushGuard = 0; this._prepareFlush(); while (this._debouncers.length && this._flushGuard < this._FLUSH_MAX) { while (this._debouncers.length) { this._debouncers.shift().complete(); } if (this._finishDebouncer) { this._finishDebouncer.complete(); } this._prepareFlush(); this._flushGuard++; } if (this._flushGuard >= this._FLUSH_MAX) { console.warn('Polymer.dom.flush aborted. Flush may not be complete.'); } }, _prepareFlush: function () { if (this._needsTakeRecords) { CustomElements.takeRecords(); } for (var i = 0; i < this._staticFlushList.length; i++) { this._staticFlushList[i](); } }, addStaticFlush: function (fn) { this._staticFlushList.push(fn); }, removeStaticFlush: function (fn) { var i = this._staticFlushList.indexOf(fn); if (i >= 0) { this._staticFlushList.splice(i, 1); } }, addDebouncer: function (debouncer) { this._debouncers.push(debouncer); this._finishDebouncer = Polymer.Debounce(this._finishDebouncer, this._finishFlush); }, _finishFlush: function () { Polymer.dom._debouncers = []; } });Polymer.EventApi = function () { 'use strict'; var DomApi = Polymer.DomApi.ctor; var Settings = Polymer.Settings; DomApi.Event = function (event) { this.event = event; }; if (Settings.useShadow) { DomApi.Event.prototype = { get rootTarget() { return this.event.path[0]; }, get localTarget() { return this.event.target; }, get path() { var path = this.event.path; if (!Array.isArray(path)) { path = Array.prototype.slice.call(path); } return path; } }; } else { DomApi.Event.prototype = { get rootTarget() { return this.event.target; }, get localTarget() { var current = this.event.currentTarget; var currentRoot = current && Polymer.dom(current).getOwnerRoot(); var p$ = this.path; for (var i = 0; i < p$.length; i++) { if (Polymer.dom(p$[i]).getOwnerRoot() === currentRoot) { return p$[i]; } } }, get path() { if (!this.event._path) { var path = []; var current = this.rootTarget; while (current) { path.push(current); var insertionPoints = Polymer.dom(current).getDestinationInsertionPoints(); if (insertionPoints.length) { for (var i = 0; i < insertionPoints.length - 1; i++) { path.push(insertionPoints[i]); } current = insertionPoints[insertionPoints.length - 1]; } else { current = Polymer.dom(current).parentNode || current.host; } } path.push(window); this.event._path = path; } return this.event._path; } }; } var factory = function (event) { if (!event.__eventApi) { event.__eventApi = new DomApi.Event(event); } return event.__eventApi; }; return { factory: factory }; }();(function () { 'use strict'; var DomApi = Polymer.DomApi.ctor; var useShadow = Polymer.Settings.useShadow; Object.defineProperty(DomApi.prototype, 'classList', { get: function () { if (!this._classList) { this._classList = new DomApi.ClassList(this); } return this._classList; }, configurable: true }); DomApi.ClassList = function (host) { this.domApi = host; this.node = host.node; }; DomApi.ClassList.prototype = { add: function () { this.node.classList.add.apply(this.node.classList, arguments); this._distributeParent(); }, remove: function () { this.node.classList.remove.apply(this.node.classList, arguments); this._distributeParent(); }, toggle: function () { this.node.classList.toggle.apply(this.node.classList, arguments); this._distributeParent(); }, _distributeParent: function () { if (!useShadow) { this.domApi._maybeDistributeParent(); } }, contains: function () { return this.node.classList.contains.apply(this.node.classList, arguments); } }; }());(function () { 'use strict'; var DomApi = Polymer.DomApi.ctor; var Settings = Polymer.Settings; DomApi.EffectiveNodesObserver = function (domApi) { this.domApi = domApi; this.node = this.domApi.node; this._listeners = []; }; DomApi.EffectiveNodesObserver.prototype = { addListener: function (callback) { if (!this._isSetup) { this._setup(); this._isSetup = true; } var listener = { fn: callback, _nodes: [] }; this._listeners.push(listener); this._scheduleNotify(); return listener; }, removeListener: function (handle) { var i = this._listeners.indexOf(handle); if (i >= 0) { this._listeners.splice(i, 1); handle._nodes = []; } if (!this._hasListeners()) { this._cleanup(); this._isSetup = false; } }, _setup: function () { this._observeContentElements(this.domApi.childNodes); }, _cleanup: function () { this._unobserveContentElements(this.domApi.childNodes); }, _hasListeners: function () { return Boolean(this._listeners.length); }, _scheduleNotify: function () { if (this._debouncer) { this._debouncer.stop(); } this._debouncer = Polymer.Debounce(this._debouncer, this._notify); this._debouncer.context = this; Polymer.dom.addDebouncer(this._debouncer); }, notify: function () { if (this._hasListeners()) { this._scheduleNotify(); } }, _notify: function () { this._beforeCallListeners(); this._callListeners(); }, _beforeCallListeners: function () { this._updateContentElements(); }, _updateContentElements: function () { this._observeContentElements(this.domApi.childNodes); }, _observeContentElements: function (elements) { for (var i = 0, n; i < elements.length && (n = elements[i]); i++) { if (this._isContent(n)) { n.__observeNodesMap = n.__observeNodesMap || new WeakMap(); if (!n.__observeNodesMap.has(this)) { n.__observeNodesMap.set(this, this._observeContent(n)); } } } }, _observeContent: function (content) { var self = this; var h = Polymer.dom(content).observeNodes(function () { self._scheduleNotify(); }); h._avoidChangeCalculation = true; return h; }, _unobserveContentElements: function (elements) { for (var i = 0, n, h; i < elements.length && (n = elements[i]); i++) { if (this._isContent(n)) { h = n.__observeNodesMap.get(this); if (h) { Polymer.dom(n).unobserveNodes(h); n.__observeNodesMap.delete(this); } } } }, _isContent: function (node) { return node.localName === 'content'; }, _callListeners: function () { var o$ = this._listeners; var nodes = this._getEffectiveNodes(); for (var i = 0, o; i < o$.length && (o = o$[i]); i++) { var info = this._generateListenerInfo(o, nodes); if (info || o._alwaysNotify) { this._callListener(o, info); } } }, _getEffectiveNodes: function () { return this.domApi.getEffectiveChildNodes(); }, _generateListenerInfo: function (listener, newNodes) { if (listener._avoidChangeCalculation) { return true; } var oldNodes = listener._nodes; var info = { target: this.node, addedNodes: [], removedNodes: [] }; var splices = Polymer.ArraySplice.calculateSplices(newNodes, oldNodes); for (var i = 0, s; i < splices.length && (s = splices[i]); i++) { for (var j = 0, n; j < s.removed.length && (n = s.removed[j]); j++) { info.removedNodes.push(n); } } for (i = 0, s; i < splices.length && (s = splices[i]); i++) { for (j = s.index; j < s.index + s.addedCount; j++) { info.addedNodes.push(newNodes[j]); } } listener._nodes = newNodes; if (info.addedNodes.length || info.removedNodes.length) { return info; } }, _callListener: function (listener, info) { return listener.fn.call(this.node, info); }, enableShadowAttributeTracking: function () { } }; if (Settings.useShadow) { var baseSetup = DomApi.EffectiveNodesObserver.prototype._setup; var baseCleanup = DomApi.EffectiveNodesObserver.prototype._cleanup; Polymer.Base.extend(DomApi.EffectiveNodesObserver.prototype, { _setup: function () { if (!this._observer) { var self = this; this._mutationHandler = function (mxns) { if (mxns && mxns.length) { self._scheduleNotify(); } }; this._observer = new MutationObserver(this._mutationHandler); this._boundFlush = function () { self._flush(); }; Polymer.dom.addStaticFlush(this._boundFlush); this._observer.observe(this.node, { childList: true }); } baseSetup.call(this); }, _cleanup: function () { this._observer.disconnect(); this._observer = null; this._mutationHandler = null; Polymer.dom.removeStaticFlush(this._boundFlush); baseCleanup.call(this); }, _flush: function () { if (this._observer) { this._mutationHandler(this._observer.takeRecords()); } }, enableShadowAttributeTracking: function () { if (this._observer) { this._makeContentListenersAlwaysNotify(); this._observer.disconnect(); this._observer.observe(this.node, { childList: true, attributes: true, subtree: true }); var root = this.domApi.getOwnerRoot(); var host = root && root.host; if (host && Polymer.dom(host).observer) { Polymer.dom(host).observer.enableShadowAttributeTracking(); } } }, _makeContentListenersAlwaysNotify: function () { for (var i = 0, h; i < this._listeners.length; i++) { h = this._listeners[i]; h._alwaysNotify = h._isContentListener; } } }); } }());(function () { 'use strict'; var DomApi = Polymer.DomApi.ctor; var Settings = Polymer.Settings; DomApi.DistributedNodesObserver = function (domApi) { DomApi.EffectiveNodesObserver.call(this, domApi); }; DomApi.DistributedNodesObserver.prototype = Object.create(DomApi.EffectiveNodesObserver.prototype); Polymer.Base.extend(DomApi.DistributedNodesObserver.prototype, { _setup: function () { }, _cleanup: function () { }, _beforeCallListeners: function () { }, _getEffectiveNodes: function () { return this.domApi.getDistributedNodes(); } }); if (Settings.useShadow) { Polymer.Base.extend(DomApi.DistributedNodesObserver.prototype, { _setup: function () { if (!this._observer) { var root = this.domApi.getOwnerRoot(); var host = root && root.host; if (host) { var self = this; this._observer = Polymer.dom(host).observeNodes(function () { self._scheduleNotify(); }); this._observer._isContentListener = true; if (this._hasAttrSelect()) { Polymer.dom(host).observer.enableShadowAttributeTracking(); } } } }, _hasAttrSelect: function () { var select = this.node.getAttribute('select'); return select && select.match(/[[.]+/); }, _cleanup: function () { var root = this.domApi.getOwnerRoot(); var host = root && root.host; if (host) { Polymer.dom(host).unobserveNodes(this._observer); } this._observer = null; } }); } }());(function () { var DomApi = Polymer.DomApi; var TreeApi = Polymer.TreeApi; Polymer.Base._addFeature({ _prepShady: function () { this._useContent = this._useContent || Boolean(this._template); }, _setupShady: function () { this.shadyRoot = null; if (!this.__domApi) { this.__domApi = null; } if (!this.__dom) { this.__dom = null; } if (!this._ownerShadyRoot) { this._ownerShadyRoot = undefined; } }, _poolContent: function () { if (this._useContent) { TreeApi.Logical.saveChildNodes(this); } }, _setupRoot: function () { if (this._useContent) { this._createLocalRoot(); if (!this.dataHost) { upgradeLogicalChildren(TreeApi.Logical.getChildNodes(this)); } } }, _createLocalRoot: function () { this.shadyRoot = this.root; this.shadyRoot._distributionClean = false; this.shadyRoot._hasDistributed = false; this.shadyRoot._isShadyRoot = true; this.shadyRoot._dirtyRoots = []; var i$ = this.shadyRoot._insertionPoints = !this._notes || this._notes._hasContent ? this.shadyRoot.querySelectorAll('content') : []; TreeApi.Logical.saveChildNodes(this.shadyRoot); for (var i = 0, c; i < i$.length; i++) { c = i$[i]; TreeApi.Logical.saveChildNodes(c); TreeApi.Logical.saveChildNodes(c.parentNode); } this.shadyRoot.host = this; }, get domHost() { var root = Polymer.dom(this).getOwnerRoot(); return root && root.host; }, distributeContent: function (updateInsertionPoints) { if (this.shadyRoot) { this.shadyRoot._invalidInsertionPoints = this.shadyRoot._invalidInsertionPoints || updateInsertionPoints; var host = getTopDistributingHost(this); Polymer.dom(this)._lazyDistribute(host); } }, _distributeContent: function () { if (this._useContent && !this.shadyRoot._distributionClean) { if (this.shadyRoot._invalidInsertionPoints) { Polymer.dom(this)._updateInsertionPoints(this); this.shadyRoot._invalidInsertionPoints = false; } this._beginDistribute(); this._distributeDirtyRoots(); this._finishDistribute(); } }, _beginDistribute: function () { if (this._useContent && DomApi.hasInsertionPoint(this.shadyRoot)) { this._resetDistribution(); this._distributePool(this.shadyRoot, this._collectPool()); } }, _distributeDirtyRoots: function () { var c$ = this.shadyRoot._dirtyRoots; for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { c._distributeContent(); } this.shadyRoot._dirtyRoots = []; }, _finishDistribute: function () { if (this._useContent) { this.shadyRoot._distributionClean = true; if (DomApi.hasInsertionPoint(this.shadyRoot)) { this._composeTree(); notifyContentObservers(this.shadyRoot); } else { if (!this.shadyRoot._hasDistributed) { TreeApi.Composed.clearChildNodes(this); this.appendChild(this.shadyRoot); } else { var children = this._composeNode(this); this._updateChildNodes(this, children); } } if (!this.shadyRoot._hasDistributed) { notifyInitialDistribution(this); } this.shadyRoot._hasDistributed = true; } }, elementMatches: function (selector, node) { node = node || this; return DomApi.matchesSelector.call(node, selector); }, _resetDistribution: function () { var children = TreeApi.Logical.getChildNodes(this); for (var i = 0; i < children.length; i++) { var child = children[i]; if (child._destinationInsertionPoints) { child._destinationInsertionPoints = undefined; } if (isInsertionPoint(child)) { clearDistributedDestinationInsertionPoints(child); } } var root = this.shadyRoot; var p$ = root._insertionPoints; for (var j = 0; j < p$.length; j++) { p$[j]._distributedNodes = []; } }, _collectPool: function () { var pool = []; var children = TreeApi.Logical.getChildNodes(this); for (var i = 0; i < children.length; i++) { var child = children[i]; if (isInsertionPoint(child)) { pool.push.apply(pool, child._distributedNodes); } else { pool.push(child); } } return pool; }, _distributePool: function (node, pool) { var p$ = node._insertionPoints; for (var i = 0, l = p$.length, p; i < l && (p = p$[i]); i++) { this._distributeInsertionPoint(p, pool); maybeRedistributeParent(p, this); } }, _distributeInsertionPoint: function (content, pool) { var anyDistributed = false; for (var i = 0, l = pool.length, node; i < l; i++) { node = pool[i]; if (!node) { continue; } if (this._matchesContentSelect(node, content)) { distributeNodeInto(node, content); pool[i] = undefined; anyDistributed = true; } } if (!anyDistributed) { var children = TreeApi.Logical.getChildNodes(content); for (var j = 0; j < children.length; j++) { distributeNodeInto(children[j], content); } } }, _composeTree: function () { this._updateChildNodes(this, this._composeNode(this)); var p$ = this.shadyRoot._insertionPoints; for (var i = 0, l = p$.length, p, parent; i < l && (p = p$[i]); i++) { parent = TreeApi.Logical.getParentNode(p); if (!parent._useContent && parent !== this && parent !== this.shadyRoot) { this._updateChildNodes(parent, this._composeNode(parent)); } } }, _composeNode: function (node) { var children = []; var c$ = TreeApi.Logical.getChildNodes(node.shadyRoot || node); for (var i = 0; i < c$.length; i++) { var child = c$[i]; if (isInsertionPoint(child)) { var distributedNodes = child._distributedNodes; for (var j = 0; j < distributedNodes.length; j++) { var distributedNode = distributedNodes[j]; if (isFinalDestination(child, distributedNode)) { children.push(distributedNode); } } } else { children.push(child); } } return children; }, _updateChildNodes: function (container, children) { var composed = TreeApi.Composed.getChildNodes(container); var splices = Polymer.ArraySplice.calculateSplices(children, composed); for (var i = 0, d = 0, s; i < splices.length && (s = splices[i]); i++) { for (var j = 0, n; j < s.removed.length && (n = s.removed[j]); j++) { if (TreeApi.Composed.getParentNode(n) === container) { TreeApi.Composed.removeChild(container, n); } composed.splice(s.index + d, 1); } d -= s.addedCount; } for (var i = 0, s, next; i < splices.length && (s = splices[i]); i++) { next = composed[s.index]; for (j = s.index, n; j < s.index + s.addedCount; j++) { n = children[j]; TreeApi.Composed.insertBefore(container, n, next); composed.splice(j, 0, n); } } }, _matchesContentSelect: function (node, contentElement) { var select = contentElement.getAttribute('select'); if (!select) { return true; } select = select.trim(); if (!select) { return true; } if (!(node instanceof Element)) { return false; } var validSelectors = /^(:not\()?[*.#[a-zA-Z_|]/; if (!validSelectors.test(select)) { return false; } return this.elementMatches(select, node); }, _elementAdd: function () { }, _elementRemove: function () { } }); function distributeNodeInto(child, insertionPoint) { insertionPoint._distributedNodes.push(child); var points = child._destinationInsertionPoints; if (!points) { child._destinationInsertionPoints = [insertionPoint]; } else { points.push(insertionPoint); } } function clearDistributedDestinationInsertionPoints(content) { var e$ = content._distributedNodes; if (e$) { for (var i = 0; i < e$.length; i++) { var d = e$[i]._destinationInsertionPoints; if (d) { d.splice(d.indexOf(content) + 1, d.length); } } } } function maybeRedistributeParent(content, host) { var parent = TreeApi.Logical.getParentNode(content); if (parent && parent.shadyRoot && DomApi.hasInsertionPoint(parent.shadyRoot) && parent.shadyRoot._distributionClean) { parent.shadyRoot._distributionClean = false; host.shadyRoot._dirtyRoots.push(parent); } } function isFinalDestination(insertionPoint, node) { var points = node._destinationInsertionPoints; return points && points[points.length - 1] === insertionPoint; } function isInsertionPoint(node) { return node.localName == 'content'; } function getTopDistributingHost(host) { while (host && hostNeedsRedistribution(host)) { host = host.domHost; } return host; } function hostNeedsRedistribution(host)