xref: /aosp_15_r20/external/chromium-trace/catapult/third_party/polymer/components/polymer/polymer-mini.html (revision 1fa4b3da657c0e9ad43c0220bacf9731820715a5)
1<!--
2@license
3Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7Code distributed by Google as part of the polymer project is also
8subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9--><link rel="import" href="polymer-micro.html"><script>(function () {
10function resolveCss(cssText, ownerDocument) {
11return cssText.replace(CSS_URL_RX, function (m, pre, url, post) {
12return pre + '\'' + resolve(url.replace(/["']/g, ''), ownerDocument) + '\'' + post;
13});
14}
15function resolveAttrs(element, ownerDocument) {
16for (var name in URL_ATTRS) {
17var a$ = URL_ATTRS[name];
18for (var i = 0, l = a$.length, a, at, v; i < l && (a = a$[i]); i++) {
19if (name === '*' || element.localName === name) {
20at = element.attributes[a];
21v = at && at.value;
22if (v && v.search(BINDING_RX) < 0) {
23at.value = a === 'style' ? resolveCss(v, ownerDocument) : resolve(v, ownerDocument);
24}
25}
26}
27}
28}
29function resolve(url, ownerDocument) {
30if (url && ABS_URL.test(url)) {
31return url;
32}
33var resolver = getUrlResolver(ownerDocument);
34resolver.href = url;
35return resolver.href || url;
36}
37var tempDoc;
38var tempDocBase;
39function resolveUrl(url, baseUri) {
40if (!tempDoc) {
41tempDoc = document.implementation.createHTMLDocument('temp');
42tempDocBase = tempDoc.createElement('base');
43tempDoc.head.appendChild(tempDocBase);
44}
45tempDocBase.href = baseUri;
46return resolve(url, tempDoc);
47}
48function getUrlResolver(ownerDocument) {
49return ownerDocument.body.__urlResolver || (ownerDocument.body.__urlResolver = ownerDocument.createElement('a'));
50}
51function pathFromUrl(url) {
52return url.substring(0, url.lastIndexOf('/') + 1);
53}
54var CSS_URL_RX = /(url\()([^)]*)(\))/g;
55var URL_ATTRS = {
56'*': [
57'href',
58'src',
59'style',
60'url'
61],
62form: ['action']
63};
64var ABS_URL = /(^\/)|(^#)|(^[\w-\d]*:)/;
65var BINDING_RX = /\{\{|\[\[/;
66Polymer.ResolveUrl = {
67resolveCss: resolveCss,
68resolveAttrs: resolveAttrs,
69resolveUrl: resolveUrl,
70pathFromUrl: pathFromUrl
71};
72Polymer.rootPath = Polymer.Settings.rootPath || pathFromUrl(document.baseURI || window.location.href);
73}());Polymer.Base._addFeature({
74_prepTemplate: function () {
75var module;
76if (this._template === undefined) {
77module = Polymer.DomModule.import(this.is);
78this._template = module && module.querySelector('template');
79}
80if (module) {
81var assetPath = module.getAttribute('assetpath') || '';
82var importURL = Polymer.ResolveUrl.resolveUrl(assetPath, module.ownerDocument.baseURI);
83this._importPath = Polymer.ResolveUrl.pathFromUrl(importURL);
84} else {
85this._importPath = '';
86}
87if (this._template && this._template.hasAttribute('is')) {
88this._warn(this._logf('_prepTemplate', 'top-level Polymer template ' + 'must not be a type-extension, found', this._template, 'Move inside simple <template>.'));
89}
90if (this._template && !this._template.content && window.HTMLTemplateElement && HTMLTemplateElement.decorate) {
91HTMLTemplateElement.decorate(this._template);
92}
93},
94_stampTemplate: function () {
95if (this._template) {
96this.root = this.instanceTemplate(this._template);
97}
98},
99instanceTemplate: function (template) {
100var dom = document.importNode(template._content || template.content, true);
101return dom;
102}
103});(function () {
104var baseAttachedCallback = Polymer.Base.attachedCallback;
105var baseDetachedCallback = Polymer.Base.detachedCallback;
106Polymer.Base._addFeature({
107_hostStack: [],
108ready: function () {
109},
110_registerHost: function (host) {
111this.dataHost = host = host || Polymer.Base._hostStack[Polymer.Base._hostStack.length - 1];
112if (host && host._clients) {
113host._clients.push(this);
114}
115this._clients = null;
116this._clientsReadied = false;
117},
118_beginHosting: function () {
119Polymer.Base._hostStack.push(this);
120if (!this._clients) {
121this._clients = [];
122}
123},
124_endHosting: function () {
125Polymer.Base._hostStack.pop();
126},
127_tryReady: function () {
128this._readied = false;
129if (this._canReady()) {
130this._ready();
131}
132},
133_canReady: function () {
134return !this.dataHost || this.dataHost._clientsReadied;
135},
136_ready: function () {
137this._beforeClientsReady();
138if (this._template) {
139this._setupRoot();
140this._readyClients();
141}
142this._clientsReadied = true;
143this._clients = null;
144this._afterClientsReady();
145this._readySelf();
146},
147_readyClients: function () {
148this._beginDistribute();
149var c$ = this._clients;
150if (c$) {
151for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) {
152c._ready();
153}
154}
155this._finishDistribute();
156},
157_readySelf: function () {
158for (var i = 0, b; i < this.behaviors.length; i++) {
159b = this.behaviors[i];
160if (b.ready) {
161b.ready.call(this);
162}
163}
164if (this.ready) {
165this.ready();
166}
167this._readied = true;
168if (this._attachedPending) {
169this._attachedPending = false;
170this.attachedCallback();
171}
172},
173_beforeClientsReady: function () {
174},
175_afterClientsReady: function () {
176},
177_beforeAttached: function () {
178},
179attachedCallback: function () {
180if (this._readied) {
181this._beforeAttached();
182baseAttachedCallback.call(this);
183} else {
184this._attachedPending = true;
185}
186},
187detachedCallback: function () {
188if (this._readied) {
189baseDetachedCallback.call(this);
190} else {
191this._attachedPending = false;
192}
193}
194});
195}());Polymer.ArraySplice = function () {
196function newSplice(index, removed, addedCount) {
197return {
198index: index,
199removed: removed,
200addedCount: addedCount
201};
202}
203var EDIT_LEAVE = 0;
204var EDIT_UPDATE = 1;
205var EDIT_ADD = 2;
206var EDIT_DELETE = 3;
207function ArraySplice() {
208}
209ArraySplice.prototype = {
210calcEditDistances: function (current, currentStart, currentEnd, old, oldStart, oldEnd) {
211var rowCount = oldEnd - oldStart + 1;
212var columnCount = currentEnd - currentStart + 1;
213var distances = new Array(rowCount);
214for (var i = 0; i < rowCount; i++) {
215distances[i] = new Array(columnCount);
216distances[i][0] = i;
217}
218for (var j = 0; j < columnCount; j++)
219distances[0][j] = j;
220for (i = 1; i < rowCount; i++) {
221for (j = 1; j < columnCount; j++) {
222if (this.equals(current[currentStart + j - 1], old[oldStart + i - 1]))
223distances[i][j] = distances[i - 1][j - 1];
224else {
225var north = distances[i - 1][j] + 1;
226var west = distances[i][j - 1] + 1;
227distances[i][j] = north < west ? north : west;
228}
229}
230}
231return distances;
232},
233spliceOperationsFromEditDistances: function (distances) {
234var i = distances.length - 1;
235var j = distances[0].length - 1;
236var current = distances[i][j];
237var edits = [];
238while (i > 0 || j > 0) {
239if (i == 0) {
240edits.push(EDIT_ADD);
241j--;
242continue;
243}
244if (j == 0) {
245edits.push(EDIT_DELETE);
246i--;
247continue;
248}
249var northWest = distances[i - 1][j - 1];
250var west = distances[i - 1][j];
251var north = distances[i][j - 1];
252var min;
253if (west < north)
254min = west < northWest ? west : northWest;
255else
256min = north < northWest ? north : northWest;
257if (min == northWest) {
258if (northWest == current) {
259edits.push(EDIT_LEAVE);
260} else {
261edits.push(EDIT_UPDATE);
262current = northWest;
263}
264i--;
265j--;
266} else if (min == west) {
267edits.push(EDIT_DELETE);
268i--;
269current = west;
270} else {
271edits.push(EDIT_ADD);
272j--;
273current = north;
274}
275}
276edits.reverse();
277return edits;
278},
279calcSplices: function (current, currentStart, currentEnd, old, oldStart, oldEnd) {
280var prefixCount = 0;
281var suffixCount = 0;
282var minLength = Math.min(currentEnd - currentStart, oldEnd - oldStart);
283if (currentStart == 0 && oldStart == 0)
284prefixCount = this.sharedPrefix(current, old, minLength);
285if (currentEnd == current.length && oldEnd == old.length)
286suffixCount = this.sharedSuffix(current, old, minLength - prefixCount);
287currentStart += prefixCount;
288oldStart += prefixCount;
289currentEnd -= suffixCount;
290oldEnd -= suffixCount;
291if (currentEnd - currentStart == 0 && oldEnd - oldStart == 0)
292return [];
293if (currentStart == currentEnd) {
294var splice = newSplice(currentStart, [], 0);
295while (oldStart < oldEnd)
296splice.removed.push(old[oldStart++]);
297return [splice];
298} else if (oldStart == oldEnd)
299return [newSplice(currentStart, [], currentEnd - currentStart)];
300var ops = this.spliceOperationsFromEditDistances(this.calcEditDistances(current, currentStart, currentEnd, old, oldStart, oldEnd));
301splice = undefined;
302var splices = [];
303var index = currentStart;
304var oldIndex = oldStart;
305for (var i = 0; i < ops.length; i++) {
306switch (ops[i]) {
307case EDIT_LEAVE:
308if (splice) {
309splices.push(splice);
310splice = undefined;
311}
312index++;
313oldIndex++;
314break;
315case EDIT_UPDATE:
316if (!splice)
317splice = newSplice(index, [], 0);
318splice.addedCount++;
319index++;
320splice.removed.push(old[oldIndex]);
321oldIndex++;
322break;
323case EDIT_ADD:
324if (!splice)
325splice = newSplice(index, [], 0);
326splice.addedCount++;
327index++;
328break;
329case EDIT_DELETE:
330if (!splice)
331splice = newSplice(index, [], 0);
332splice.removed.push(old[oldIndex]);
333oldIndex++;
334break;
335}
336}
337if (splice) {
338splices.push(splice);
339}
340return splices;
341},
342sharedPrefix: function (current, old, searchLength) {
343for (var i = 0; i < searchLength; i++)
344if (!this.equals(current[i], old[i]))
345return i;
346return searchLength;
347},
348sharedSuffix: function (current, old, searchLength) {
349var index1 = current.length;
350var index2 = old.length;
351var count = 0;
352while (count < searchLength && this.equals(current[--index1], old[--index2]))
353count++;
354return count;
355},
356calculateSplices: function (current, previous) {
357return this.calcSplices(current, 0, current.length, previous, 0, previous.length);
358},
359equals: function (currentValue, previousValue) {
360return currentValue === previousValue;
361}
362};
363return new ArraySplice();
364}();Polymer.domInnerHTML = function () {
365var escapeAttrRegExp = /[&\u00A0"]/g;
366var escapeDataRegExp = /[&\u00A0<>]/g;
367function escapeReplace(c) {
368switch (c) {
369case '&':
370return '&amp;';
371case '<':
372return '&lt;';
373case '>':
374return '&gt;';
375case '"':
376return '&quot;';
377case '\xA0':
378return '&nbsp;';
379}
380}
381function escapeAttr(s) {
382return s.replace(escapeAttrRegExp, escapeReplace);
383}
384function escapeData(s) {
385return s.replace(escapeDataRegExp, escapeReplace);
386}
387function makeSet(arr) {
388var set = {};
389for (var i = 0; i < arr.length; i++) {
390set[arr[i]] = true;
391}
392return set;
393}
394var voidElements = makeSet([
395'area',
396'base',
397'br',
398'col',
399'command',
400'embed',
401'hr',
402'img',
403'input',
404'keygen',
405'link',
406'meta',
407'param',
408'source',
409'track',
410'wbr'
411]);
412var plaintextParents = makeSet([
413'style',
414'script',
415'xmp',
416'iframe',
417'noembed',
418'noframes',
419'plaintext',
420'noscript'
421]);
422function getOuterHTML(node, parentNode, composed) {
423switch (node.nodeType) {
424case Node.ELEMENT_NODE:
425var tagName = node.localName;
426var s = '<' + tagName;
427var attrs = node.attributes;
428for (var i = 0, attr; attr = attrs[i]; i++) {
429s += ' ' + attr.name + '="' + escapeAttr(attr.value) + '"';
430}
431s += '>';
432if (voidElements[tagName]) {
433return s;
434}
435return s + getInnerHTML(node, composed) + '</' + tagName + '>';
436case Node.TEXT_NODE:
437var data = node.data;
438if (parentNode && plaintextParents[parentNode.localName]) {
439return data;
440}
441return escapeData(data);
442case Node.COMMENT_NODE:
443return '<!--' + node.data + '-->';
444default:
445console.error(node);
446throw new Error('not implemented');
447}
448}
449function getInnerHTML(node, composed) {
450if (node instanceof HTMLTemplateElement)
451node = node.content;
452var s = '';
453var c$ = Polymer.dom(node).childNodes;
454for (var i = 0, l = c$.length, child; i < l && (child = c$[i]); i++) {
455s += getOuterHTML(child, node, composed);
456}
457return s;
458}
459return { getInnerHTML: getInnerHTML };
460}();(function () {
461'use strict';
462var nativeInsertBefore = Element.prototype.insertBefore;
463var nativeAppendChild = Element.prototype.appendChild;
464var nativeRemoveChild = Element.prototype.removeChild;
465Polymer.TreeApi = {
466arrayCopyChildNodes: function (parent) {
467var copy = [], i = 0;
468for (var n = parent.firstChild; n; n = n.nextSibling) {
469copy[i++] = n;
470}
471return copy;
472},
473arrayCopyChildren: function (parent) {
474var copy = [], i = 0;
475for (var n = parent.firstElementChild; n; n = n.nextElementSibling) {
476copy[i++] = n;
477}
478return copy;
479},
480arrayCopy: function (a$) {
481var l = a$.length;
482var copy = new Array(l);
483for (var i = 0; i < l; i++) {
484copy[i] = a$[i];
485}
486return copy;
487}
488};
489Polymer.TreeApi.Logical = {
490hasParentNode: function (node) {
491return Boolean(node.__dom && node.__dom.parentNode);
492},
493hasChildNodes: function (node) {
494return Boolean(node.__dom && node.__dom.childNodes !== undefined);
495},
496getChildNodes: function (node) {
497return this.hasChildNodes(node) ? this._getChildNodes(node) : node.childNodes;
498},
499_getChildNodes: function (node) {
500if (!node.__dom.childNodes) {
501node.__dom.childNodes = [];
502for (var n = node.__dom.firstChild; n; n = n.__dom.nextSibling) {
503node.__dom.childNodes.push(n);
504}
505}
506return node.__dom.childNodes;
507},
508getParentNode: function (node) {
509return node.__dom && node.__dom.parentNode !== undefined ? node.__dom.parentNode : node.parentNode;
510},
511getFirstChild: function (node) {
512return node.__dom && node.__dom.firstChild !== undefined ? node.__dom.firstChild : node.firstChild;
513},
514getLastChild: function (node) {
515return node.__dom && node.__dom.lastChild !== undefined ? node.__dom.lastChild : node.lastChild;
516},
517getNextSibling: function (node) {
518return node.__dom && node.__dom.nextSibling !== undefined ? node.__dom.nextSibling : node.nextSibling;
519},
520getPreviousSibling: function (node) {
521return node.__dom && node.__dom.previousSibling !== undefined ? node.__dom.previousSibling : node.previousSibling;
522},
523getFirstElementChild: function (node) {
524return node.__dom && node.__dom.firstChild !== undefined ? this._getFirstElementChild(node) : node.firstElementChild;
525},
526_getFirstElementChild: function (node) {
527var n = node.__dom.firstChild;
528while (n && n.nodeType !== Node.ELEMENT_NODE) {
529n = n.__dom.nextSibling;
530}
531return n;
532},
533getLastElementChild: function (node) {
534return node.__dom && node.__dom.lastChild !== undefined ? this._getLastElementChild(node) : node.lastElementChild;
535},
536_getLastElementChild: function (node) {
537var n = node.__dom.lastChild;
538while (n && n.nodeType !== Node.ELEMENT_NODE) {
539n = n.__dom.previousSibling;
540}
541return n;
542},
543getNextElementSibling: function (node) {
544return node.__dom && node.__dom.nextSibling !== undefined ? this._getNextElementSibling(node) : node.nextElementSibling;
545},
546_getNextElementSibling: function (node) {
547var n = node.__dom.nextSibling;
548while (n && n.nodeType !== Node.ELEMENT_NODE) {
549n = n.__dom.nextSibling;
550}
551return n;
552},
553getPreviousElementSibling: function (node) {
554return node.__dom && node.__dom.previousSibling !== undefined ? this._getPreviousElementSibling(node) : node.previousElementSibling;
555},
556_getPreviousElementSibling: function (node) {
557var n = node.__dom.previousSibling;
558while (n && n.nodeType !== Node.ELEMENT_NODE) {
559n = n.__dom.previousSibling;
560}
561return n;
562},
563saveChildNodes: function (node) {
564if (!this.hasChildNodes(node)) {
565node.__dom = node.__dom || {};
566node.__dom.firstChild = node.firstChild;
567node.__dom.lastChild = node.lastChild;
568node.__dom.childNodes = [];
569for (var n = node.firstChild; n; n = n.nextSibling) {
570n.__dom = n.__dom || {};
571n.__dom.parentNode = node;
572node.__dom.childNodes.push(n);
573n.__dom.nextSibling = n.nextSibling;
574n.__dom.previousSibling = n.previousSibling;
575}
576}
577},
578recordInsertBefore: function (node, container, ref_node) {
579container.__dom.childNodes = null;
580if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
581for (var n = node.firstChild; n; n = n.nextSibling) {
582this._linkNode(n, container, ref_node);
583}
584} else {
585this._linkNode(node, container, ref_node);
586}
587},
588_linkNode: function (node, container, ref_node) {
589node.__dom = node.__dom || {};
590container.__dom = container.__dom || {};
591if (ref_node) {
592ref_node.__dom = ref_node.__dom || {};
593}
594node.__dom.previousSibling = ref_node ? ref_node.__dom.previousSibling : container.__dom.lastChild;
595if (node.__dom.previousSibling) {
596node.__dom.previousSibling.__dom.nextSibling = node;
597}
598node.__dom.nextSibling = ref_node || null;
599if (node.__dom.nextSibling) {
600node.__dom.nextSibling.__dom.previousSibling = node;
601}
602node.__dom.parentNode = container;
603if (ref_node) {
604if (ref_node === container.__dom.firstChild) {
605container.__dom.firstChild = node;
606}
607} else {
608container.__dom.lastChild = node;
609if (!container.__dom.firstChild) {
610container.__dom.firstChild = node;
611}
612}
613container.__dom.childNodes = null;
614},
615recordRemoveChild: function (node, container) {
616node.__dom = node.__dom || {};
617container.__dom = container.__dom || {};
618if (node === container.__dom.firstChild) {
619container.__dom.firstChild = node.__dom.nextSibling;
620}
621if (node === container.__dom.lastChild) {
622container.__dom.lastChild = node.__dom.previousSibling;
623}
624var p = node.__dom.previousSibling;
625var n = node.__dom.nextSibling;
626if (p) {
627p.__dom.nextSibling = n;
628}
629if (n) {
630n.__dom.previousSibling = p;
631}
632node.__dom.parentNode = node.__dom.previousSibling = node.__dom.nextSibling = undefined;
633container.__dom.childNodes = null;
634}
635};
636Polymer.TreeApi.Composed = {
637getChildNodes: function (node) {
638return Polymer.TreeApi.arrayCopyChildNodes(node);
639},
640getParentNode: function (node) {
641return node.parentNode;
642},
643clearChildNodes: function (node) {
644node.textContent = '';
645},
646insertBefore: function (parentNode, newChild, refChild) {
647return nativeInsertBefore.call(parentNode, newChild, refChild || null);
648},
649appendChild: function (parentNode, newChild) {
650return nativeAppendChild.call(parentNode, newChild);
651},
652removeChild: function (parentNode, node) {
653return nativeRemoveChild.call(parentNode, node);
654}
655};
656}());Polymer.DomApi = function () {
657'use strict';
658var Settings = Polymer.Settings;
659var TreeApi = Polymer.TreeApi;
660var DomApi = function (node) {
661this.node = needsToWrap ? DomApi.wrap(node) : node;
662};
663var needsToWrap = Settings.hasShadow && !Settings.nativeShadow;
664DomApi.wrap = window.wrap ? window.wrap : function (node) {
665return node;
666};
667DomApi.prototype = {
668flush: function () {
669Polymer.dom.flush();
670},
671deepContains: function (node) {
672if (this.node.contains(node)) {
673return true;
674}
675var n = node;
676var doc = node.ownerDocument;
677while (n && n !== doc && n !== this.node) {
678n = Polymer.dom(n).parentNode || n.host;
679}
680return n === this.node;
681},
682queryDistributedElements: function (selector) {
683var c$ = this.getEffectiveChildNodes();
684var list = [];
685for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) {
686if (c.nodeType === Node.ELEMENT_NODE && DomApi.matchesSelector.call(c, selector)) {
687list.push(c);
688}
689}
690return list;
691},
692getEffectiveChildNodes: function () {
693var list = [];
694var c$ = this.childNodes;
695for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) {
696if (c.localName === CONTENT) {
697var d$ = dom(c).getDistributedNodes();
698for (var j = 0; j < d$.length; j++) {
699list.push(d$[j]);
700}
701} else {
702list.push(c);
703}
704}
705return list;
706},
707observeNodes: function (callback) {
708if (callback) {
709if (!this.observer) {
710this.observer = this.node.localName === CONTENT ? new DomApi.DistributedNodesObserver(this) : new DomApi.EffectiveNodesObserver(this);
711}
712return this.observer.addListener(callback);
713}
714},
715unobserveNodes: function (handle) {
716if (this.observer) {
717this.observer.removeListener(handle);
718}
719},
720notifyObserver: function () {
721if (this.observer) {
722this.observer.notify();
723}
724},
725_query: function (matcher, node, halter) {
726node = node || this.node;
727var list = [];
728this._queryElements(TreeApi.Logical.getChildNodes(node), matcher, halter, list);
729return list;
730},
731_queryElements: function (elements, matcher, halter, list) {
732for (var i = 0, l = elements.length, c; i < l && (c = elements[i]); i++) {
733if (c.nodeType === Node.ELEMENT_NODE) {
734if (this._queryElement(c, matcher, halter, list)) {
735return true;
736}
737}
738}
739},
740_queryElement: function (node, matcher, halter, list) {
741var result = matcher(node);
742if (result) {
743list.push(node);
744}
745if (halter && halter(result)) {
746return result;
747}
748this._queryElements(TreeApi.Logical.getChildNodes(node), matcher, halter, list);
749}
750};
751var CONTENT = DomApi.CONTENT = 'content';
752var dom = DomApi.factory = function (node) {
753node = node || document;
754if (!node.__domApi) {
755node.__domApi = new DomApi.ctor(node);
756}
757return node.__domApi;
758};
759DomApi.hasApi = function (node) {
760return Boolean(node.__domApi);
761};
762DomApi.ctor = DomApi;
763Polymer.dom = function (obj, patch) {
764if (obj instanceof Event) {
765return Polymer.EventApi.factory(obj);
766} else {
767return DomApi.factory(obj, patch);
768}
769};
770var p = Element.prototype;
771DomApi.matchesSelector = p.matches || p.matchesSelector || p.mozMatchesSelector || p.msMatchesSelector || p.oMatchesSelector || p.webkitMatchesSelector;
772return DomApi;
773}();(function () {
774'use strict';
775var Settings = Polymer.Settings;
776var DomApi = Polymer.DomApi;
777var dom = DomApi.factory;
778var TreeApi = Polymer.TreeApi;
779var getInnerHTML = Polymer.domInnerHTML.getInnerHTML;
780var CONTENT = DomApi.CONTENT;
781if (Settings.useShadow) {
782return;
783}
784var nativeCloneNode = Element.prototype.cloneNode;
785var nativeImportNode = Document.prototype.importNode;
786Polymer.Base.mixin(DomApi.prototype, {
787_lazyDistribute: function (host) {
788if (host.shadyRoot && host.shadyRoot._distributionClean) {
789host.shadyRoot._distributionClean = false;
790Polymer.dom.addDebouncer(host.debounce('_distribute', host._distributeContent));
791}
792},
793appendChild: function (node) {
794return this.insertBefore(node);
795},
796insertBefore: function (node, ref_node) {
797if (ref_node && TreeApi.Logical.getParentNode(ref_node) !== this.node) {
798throw Error('The ref_node to be inserted before is not a child ' + 'of this node');
799}
800if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
801var parent = TreeApi.Logical.getParentNode(node);
802if (parent) {
803if (DomApi.hasApi(parent)) {
804dom(parent).notifyObserver();
805}
806this._removeNode(node);
807} else {
808this._removeOwnerShadyRoot(node);
809}
810}
811if (!this._addNode(node, ref_node)) {
812if (ref_node) {
813ref_node = ref_node.localName === CONTENT ? this._firstComposedNode(ref_node) : ref_node;
814}
815var container = this.node._isShadyRoot ? this.node.host : this.node;
816if (ref_node) {
817TreeApi.Composed.insertBefore(container, node, ref_node);
818} else {
819TreeApi.Composed.appendChild(container, node);
820}
821}
822this.notifyObserver();
823return node;
824},
825_addNode: function (node, ref_node) {
826var root = this.getOwnerRoot();
827if (root) {
828var ipAdded = this._maybeAddInsertionPoint(node, this.node);
829if (!root._invalidInsertionPoints) {
830root._invalidInsertionPoints = ipAdded;
831}
832this._addNodeToHost(root.host, node);
833}
834if (TreeApi.Logical.hasChildNodes(this.node)) {
835TreeApi.Logical.recordInsertBefore(node, this.node, ref_node);
836}
837var handled = this._maybeDistribute(node) || this.node.shadyRoot;
838if (handled) {
839if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
840while (node.firstChild) {
841TreeApi.Composed.removeChild(node, node.firstChild);
842}
843} else {
844var parent = TreeApi.Composed.getParentNode(node);
845if (parent) {
846TreeApi.Composed.removeChild(parent, node);
847}
848}
849}
850return handled;
851},
852removeChild: function (node) {
853if (TreeApi.Logical.getParentNode(node) !== this.node) {
854throw Error('The node to be removed is not a child of this node: ' + node);
855}
856if (!this._removeNode(node)) {
857var container = this.node._isShadyRoot ? this.node.host : this.node;
858var parent = TreeApi.Composed.getParentNode(node);
859if (container === parent) {
860TreeApi.Composed.removeChild(container, node);
861}
862}
863this.notifyObserver();
864return node;
865},
866_removeNode: function (node) {
867var logicalParent = TreeApi.Logical.hasParentNode(node) && TreeApi.Logical.getParentNode(node);
868var distributed;
869var root = this._ownerShadyRootForNode(node);
870if (logicalParent) {
871distributed = dom(node)._maybeDistributeParent();
872TreeApi.Logical.recordRemoveChild(node, logicalParent);
873if (root && this._removeDistributedChildren(root, node)) {
874root._invalidInsertionPoints = true;
875this._lazyDistribute(root.host);
876}
877}
878this._removeOwnerShadyRoot(node);
879if (root) {
880this._removeNodeFromHost(root.host, node);
881}
882return distributed;
883},
884replaceChild: function (node, ref_node) {
885this.insertBefore(node, ref_node);
886this.removeChild(ref_node);
887return node;
888},
889_hasCachedOwnerRoot: function (node) {
890return Boolean(node._ownerShadyRoot !== undefined);
891},
892getOwnerRoot: function () {
893return this._ownerShadyRootForNode(this.node);
894},
895_ownerShadyRootForNode: function (node) {
896if (!node) {
897return;
898}
899var root = node._ownerShadyRoot;
900if (root === undefined) {
901if (node._isShadyRoot) {
902root = node;
903} else {
904var parent = TreeApi.Logical.getParentNode(node);
905if (parent) {
906root = parent._isShadyRoot ? parent : this._ownerShadyRootForNode(parent);
907} else {
908root = null;
909}
910}
911if (root || document.documentElement.contains(node)) {
912node._ownerShadyRoot = root;
913}
914}
915return root;
916},
917_maybeDistribute: function (node) {
918var fragContent = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && !node.__noContent && dom(node).querySelector(CONTENT);
919var wrappedContent = fragContent && TreeApi.Logical.getParentNode(fragContent).nodeType !== Node.DOCUMENT_FRAGMENT_NODE;
920var hasContent = fragContent || node.localName === CONTENT;
921if (hasContent) {
922var root = this.getOwnerRoot();
923if (root) {
924this._lazyDistribute(root.host);
925}
926}
927var needsDist = this._nodeNeedsDistribution(this.node);
928if (needsDist) {
929this._lazyDistribute(this.node);
930}
931return needsDist || hasContent && !wrappedContent;
932},
933_maybeAddInsertionPoint: function (node, parent) {
934var added;
935if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && !node.__noContent) {
936var c$ = dom(node).querySelectorAll(CONTENT);
937for (var i = 0, n, np, na; i < c$.length && (n = c$[i]); i++) {
938np = TreeApi.Logical.getParentNode(n);
939if (np === node) {
940np = parent;
941}
942na = this._maybeAddInsertionPoint(n, np);
943added = added || na;
944}
945} else if (node.localName === CONTENT) {
946TreeApi.Logical.saveChildNodes(parent);
947TreeApi.Logical.saveChildNodes(node);
948added = true;
949}
950return added;
951},
952_updateInsertionPoints: function (host) {
953var i$ = host.shadyRoot._insertionPoints = dom(host.shadyRoot).querySelectorAll(CONTENT);
954for (var i = 0, c; i < i$.length; i++) {
955c = i$[i];
956TreeApi.Logical.saveChildNodes(c);
957TreeApi.Logical.saveChildNodes(TreeApi.Logical.getParentNode(c));
958}
959},
960_nodeNeedsDistribution: function (node) {
961return node && node.shadyRoot && DomApi.hasInsertionPoint(node.shadyRoot);
962},
963_addNodeToHost: function (host, node) {
964if (host._elementAdd) {
965host._elementAdd(node);
966}
967},
968_removeNodeFromHost: function (host, node) {
969if (host._elementRemove) {
970host._elementRemove(node);
971}
972},
973_removeDistributedChildren: function (root, container) {
974var hostNeedsDist;
975var ip$ = root._insertionPoints;
976for (var i = 0; i < ip$.length; i++) {
977var content = ip$[i];
978if (this._contains(container, content)) {
979var dc$ = dom(content).getDistributedNodes();
980for (var j = 0; j < dc$.length; j++) {
981hostNeedsDist = true;
982var node = dc$[j];
983var parent = TreeApi.Composed.getParentNode(node);
984if (parent) {
985TreeApi.Composed.removeChild(parent, node);
986}
987}
988}
989}
990return hostNeedsDist;
991},
992_contains: function (container, node) {
993while (node) {
994if (node == container) {
995return true;
996}
997node = TreeApi.Logical.getParentNode(node);
998}
999},
1000_removeOwnerShadyRoot: function (node) {
1001if (this._hasCachedOwnerRoot(node)) {
1002var c$ = TreeApi.Logical.getChildNodes(node);
1003for (var i = 0, l = c$.length, n; i < l && (n = c$[i]); i++) {
1004this._removeOwnerShadyRoot(n);
1005}
1006}
1007node._ownerShadyRoot = undefined;
1008},
1009_firstComposedNode: function (content) {
1010var n$ = dom(content).getDistributedNodes();
1011for (var i = 0, l = n$.length, n, p$; i < l && (n = n$[i]); i++) {
1012p$ = dom(n).getDestinationInsertionPoints();
1013if (p$[p$.length - 1] === content) {
1014return n;
1015}
1016}
1017},
1018querySelector: function (selector) {
1019var result = this._query(function (n) {
1020return DomApi.matchesSelector.call(n, selector);
1021}, this.node, function (n) {
1022return Boolean(n);
1023})[0];
1024return result || null;
1025},
1026querySelectorAll: function (selector) {
1027return this._query(function (n) {
1028return DomApi.matchesSelector.call(n, selector);
1029}, this.node);
1030},
1031getDestinationInsertionPoints: function () {
1032return this.node._destinationInsertionPoints || [];
1033},
1034getDistributedNodes: function () {
1035return this.node._distributedNodes || [];
1036},
1037_clear: function () {
1038while (this.childNodes.length) {
1039this.removeChild(this.childNodes[0]);
1040}
1041},
1042setAttribute: function (name, value) {
1043this.node.setAttribute(name, value);
1044this._maybeDistributeParent();
1045},
1046removeAttribute: function (name) {
1047this.node.removeAttribute(name);
1048this._maybeDistributeParent();
1049},
1050_maybeDistributeParent: function () {
1051if (this._nodeNeedsDistribution(this.parentNode)) {
1052this._lazyDistribute(this.parentNode);
1053return true;
1054}
1055},
1056cloneNode: function (deep) {
1057var n = nativeCloneNode.call(this.node, false);
1058if (deep) {
1059var c$ = this.childNodes;
1060var d = dom(n);
1061for (var i = 0, nc; i < c$.length; i++) {
1062nc = dom(c$[i]).cloneNode(true);
1063d.appendChild(nc);
1064}
1065}
1066return n;
1067},
1068importNode: function (externalNode, deep) {
1069var doc = this.node instanceof Document ? this.node : this.node.ownerDocument;
1070var n = nativeImportNode.call(doc, externalNode, false);
1071if (deep) {
1072var c$ = TreeApi.Logical.getChildNodes(externalNode);
1073var d = dom(n);
1074for (var i = 0, nc; i < c$.length; i++) {
1075nc = dom(doc).importNode(c$[i], true);
1076d.appendChild(nc);
1077}
1078}
1079return n;
1080},
1081_getComposedInnerHTML: function () {
1082return getInnerHTML(this.node, true);
1083}
1084});
1085Object.defineProperties(DomApi.prototype, {
1086activeElement: {
1087get: function () {
1088var active = document.activeElement;
1089if (!active) {
1090return null;
1091}
1092var isShadyRoot = !!this.node._isShadyRoot;
1093if (this.node !== document) {
1094if (!isShadyRoot) {
1095return null;
1096}
1097if (this.node.host === active || !this.node.host.contains(active)) {
1098return null;
1099}
1100}
1101var activeRoot = dom(active).getOwnerRoot();
1102while (activeRoot && activeRoot !== this.node) {
1103active = activeRoot.host;
1104activeRoot = dom(active).getOwnerRoot();
1105}
1106if (this.node === document) {
1107return activeRoot ? null : active;
1108} else {
1109return activeRoot === this.node ? active : null;
1110}
1111},
1112configurable: true
1113},
1114childNodes: {
1115get: function () {
1116var c$ = TreeApi.Logical.getChildNodes(this.node);
1117return Array.isArray(c$) ? c$ : TreeApi.arrayCopyChildNodes(this.node);
1118},
1119configurable: true
1120},
1121children: {
1122get: function () {
1123if (TreeApi.Logical.hasChildNodes(this.node)) {
1124return Array.prototype.filter.call(this.childNodes, function (n) {
1125return n.nodeType === Node.ELEMENT_NODE;
1126});
1127} else {
1128return TreeApi.arrayCopyChildren(this.node);
1129}
1130},
1131configurable: true
1132},
1133parentNode: {
1134get: function () {
1135return TreeApi.Logical.getParentNode(this.node);
1136},
1137configurable: true
1138},
1139firstChild: {
1140get: function () {
1141return TreeApi.Logical.getFirstChild(this.node);
1142},
1143configurable: true
1144},
1145lastChild: {
1146get: function () {
1147return TreeApi.Logical.getLastChild(this.node);
1148},
1149configurable: true
1150},
1151nextSibling: {
1152get: function () {
1153return TreeApi.Logical.getNextSibling(this.node);
1154},
1155configurable: true
1156},
1157previousSibling: {
1158get: function () {
1159return TreeApi.Logical.getPreviousSibling(this.node);
1160},
1161configurable: true
1162},
1163firstElementChild: {
1164get: function () {
1165return TreeApi.Logical.getFirstElementChild(this.node);
1166},
1167configurable: true
1168},
1169lastElementChild: {
1170get: function () {
1171return TreeApi.Logical.getLastElementChild(this.node);
1172},
1173configurable: true
1174},
1175nextElementSibling: {
1176get: function () {
1177return TreeApi.Logical.getNextElementSibling(this.node);
1178},
1179configurable: true
1180},
1181previousElementSibling: {
1182get: function () {
1183return TreeApi.Logical.getPreviousElementSibling(this.node);
1184},
1185configurable: true
1186},
1187textContent: {
1188get: function () {
1189var nt = this.node.nodeType;
1190if (nt === Node.TEXT_NODE || nt === Node.COMMENT_NODE) {
1191return this.node.textContent;
1192} else {
1193var tc = [];
1194for (var i = 0, cn = this.childNodes, c; c = cn[i]; i++) {
1195if (c.nodeType !== Node.COMMENT_NODE) {
1196tc.push(c.textContent);
1197}
1198}
1199return tc.join('');
1200}
1201},
1202set: function (text) {
1203var nt = this.node.nodeType;
1204if (nt === Node.TEXT_NODE || nt === Node.COMMENT_NODE) {
1205this.node.textContent = text;
1206} else {
1207this._clear();
1208if (text) {
1209this.appendChild(document.createTextNode(text));
1210}
1211}
1212},
1213configurable: true
1214},
1215innerHTML: {
1216get: function () {
1217var nt = this.node.nodeType;
1218if (nt === Node.TEXT_NODE || nt === Node.COMMENT_NODE) {
1219return null;
1220} else {
1221return getInnerHTML(this.node);
1222}
1223},
1224set: function (text) {
1225var nt = this.node.nodeType;
1226if (nt !== Node.TEXT_NODE || nt !== Node.COMMENT_NODE) {
1227this._clear();
1228var d = document.createElement('div');
1229d.innerHTML = text;
1230var c$ = TreeApi.arrayCopyChildNodes(d);
1231for (var i = 0; i < c$.length; i++) {
1232this.appendChild(c$[i]);
1233}
1234}
1235},
1236configurable: true
1237}
1238});
1239DomApi.hasInsertionPoint = function (root) {
1240return Boolean(root && root._insertionPoints.length);
1241};
1242}());(function () {
1243'use strict';
1244var Settings = Polymer.Settings;
1245var TreeApi = Polymer.TreeApi;
1246var DomApi = Polymer.DomApi;
1247if (!Settings.useShadow) {
1248return;
1249}
1250Polymer.Base.mixin(DomApi.prototype, {
1251querySelectorAll: function (selector) {
1252return TreeApi.arrayCopy(this.node.querySelectorAll(selector));
1253},
1254getOwnerRoot: function () {
1255var n = this.node;
1256while (n) {
1257if (n.nodeType === Node.DOCUMENT_FRAGMENT_NODE && n.host) {
1258return n;
1259}
1260n = n.parentNode;
1261}
1262},
1263importNode: function (externalNode, deep) {
1264var doc = this.node instanceof Document ? this.node : this.node.ownerDocument;
1265return doc.importNode(externalNode, deep);
1266},
1267getDestinationInsertionPoints: function () {
1268var n$ = this.node.getDestinationInsertionPoints && this.node.getDestinationInsertionPoints();
1269return n$ ? TreeApi.arrayCopy(n$) : [];
1270},
1271getDistributedNodes: function () {
1272var n$ = this.node.getDistributedNodes && this.node.getDistributedNodes();
1273return n$ ? TreeApi.arrayCopy(n$) : [];
1274}
1275});
1276Object.defineProperties(DomApi.prototype, {
1277activeElement: {
1278get: function () {
1279var node = DomApi.wrap(this.node);
1280var activeElement = node.activeElement;
1281return node.contains(activeElement) ? activeElement : null;
1282},
1283configurable: true
1284},
1285childNodes: {
1286get: function () {
1287return TreeApi.arrayCopyChildNodes(this.node);
1288},
1289configurable: true
1290},
1291children: {
1292get: function () {
1293return TreeApi.arrayCopyChildren(this.node);
1294},
1295configurable: true
1296},
1297textContent: {
1298get: function () {
1299return this.node.textContent;
1300},
1301set: function (value) {
1302return this.node.textContent = value;
1303},
1304configurable: true
1305},
1306innerHTML: {
1307get: function () {
1308return this.node.innerHTML;
1309},
1310set: function (value) {
1311return this.node.innerHTML = value;
1312},
1313configurable: true
1314}
1315});
1316var forwardMethods = function (m$) {
1317for (var i = 0; i < m$.length; i++) {
1318forwardMethod(m$[i]);
1319}
1320};
1321var forwardMethod = function (method) {
1322DomApi.prototype[method] = function () {
1323return this.node[method].apply(this.node, arguments);
1324};
1325};
1326forwardMethods([
1327'cloneNode',
1328'appendChild',
1329'insertBefore',
1330'removeChild',
1331'replaceChild',
1332'setAttribute',
1333'removeAttribute',
1334'querySelector'
1335]);
1336var forwardProperties = function (f$) {
1337for (var i = 0; i < f$.length; i++) {
1338forwardProperty(f$[i]);
1339}
1340};
1341var forwardProperty = function (name) {
1342Object.defineProperty(DomApi.prototype, name, {
1343get: function () {
1344return this.node[name];
1345},
1346configurable: true
1347});
1348};
1349forwardProperties([
1350'parentNode',
1351'firstChild',
1352'lastChild',
1353'nextSibling',
1354'previousSibling',
1355'firstElementChild',
1356'lastElementChild',
1357'nextElementSibling',
1358'previousElementSibling'
1359]);
1360}());Polymer.Base.mixin(Polymer.dom, {
1361_flushGuard: 0,
1362_FLUSH_MAX: 100,
1363_needsTakeRecords: !Polymer.Settings.useNativeCustomElements,
1364_debouncers: [],
1365_staticFlushList: [],
1366_finishDebouncer: null,
1367flush: function () {
1368this._flushGuard = 0;
1369this._prepareFlush();
1370while (this._debouncers.length && this._flushGuard < this._FLUSH_MAX) {
1371while (this._debouncers.length) {
1372this._debouncers.shift().complete();
1373}
1374if (this._finishDebouncer) {
1375this._finishDebouncer.complete();
1376}
1377this._prepareFlush();
1378this._flushGuard++;
1379}
1380if (this._flushGuard >= this._FLUSH_MAX) {
1381console.warn('Polymer.dom.flush aborted. Flush may not be complete.');
1382}
1383},
1384_prepareFlush: function () {
1385if (this._needsTakeRecords) {
1386CustomElements.takeRecords();
1387}
1388for (var i = 0; i < this._staticFlushList.length; i++) {
1389this._staticFlushList[i]();
1390}
1391},
1392addStaticFlush: function (fn) {
1393this._staticFlushList.push(fn);
1394},
1395removeStaticFlush: function (fn) {
1396var i = this._staticFlushList.indexOf(fn);
1397if (i >= 0) {
1398this._staticFlushList.splice(i, 1);
1399}
1400},
1401addDebouncer: function (debouncer) {
1402this._debouncers.push(debouncer);
1403this._finishDebouncer = Polymer.Debounce(this._finishDebouncer, this._finishFlush);
1404},
1405_finishFlush: function () {
1406Polymer.dom._debouncers = [];
1407}
1408});Polymer.EventApi = function () {
1409'use strict';
1410var DomApi = Polymer.DomApi.ctor;
1411var Settings = Polymer.Settings;
1412DomApi.Event = function (event) {
1413this.event = event;
1414};
1415if (Settings.useShadow) {
1416DomApi.Event.prototype = {
1417get rootTarget() {
1418return this.event.path[0];
1419},
1420get localTarget() {
1421return this.event.target;
1422},
1423get path() {
1424var path = this.event.path;
1425if (!Array.isArray(path)) {
1426path = Array.prototype.slice.call(path);
1427}
1428return path;
1429}
1430};
1431} else {
1432DomApi.Event.prototype = {
1433get rootTarget() {
1434return this.event.target;
1435},
1436get localTarget() {
1437var current = this.event.currentTarget;
1438var currentRoot = current && Polymer.dom(current).getOwnerRoot();
1439var p$ = this.path;
1440for (var i = 0; i < p$.length; i++) {
1441if (Polymer.dom(p$[i]).getOwnerRoot() === currentRoot) {
1442return p$[i];
1443}
1444}
1445},
1446get path() {
1447if (!this.event._path) {
1448var path = [];
1449var current = this.rootTarget;
1450while (current) {
1451path.push(current);
1452var insertionPoints = Polymer.dom(current).getDestinationInsertionPoints();
1453if (insertionPoints.length) {
1454for (var i = 0; i < insertionPoints.length - 1; i++) {
1455path.push(insertionPoints[i]);
1456}
1457current = insertionPoints[insertionPoints.length - 1];
1458} else {
1459current = Polymer.dom(current).parentNode || current.host;
1460}
1461}
1462path.push(window);
1463this.event._path = path;
1464}
1465return this.event._path;
1466}
1467};
1468}
1469var factory = function (event) {
1470if (!event.__eventApi) {
1471event.__eventApi = new DomApi.Event(event);
1472}
1473return event.__eventApi;
1474};
1475return { factory: factory };
1476}();(function () {
1477'use strict';
1478var DomApi = Polymer.DomApi.ctor;
1479var useShadow = Polymer.Settings.useShadow;
1480Object.defineProperty(DomApi.prototype, 'classList', {
1481get: function () {
1482if (!this._classList) {
1483this._classList = new DomApi.ClassList(this);
1484}
1485return this._classList;
1486},
1487configurable: true
1488});
1489DomApi.ClassList = function (host) {
1490this.domApi = host;
1491this.node = host.node;
1492};
1493DomApi.ClassList.prototype = {
1494add: function () {
1495this.node.classList.add.apply(this.node.classList, arguments);
1496this._distributeParent();
1497},
1498remove: function () {
1499this.node.classList.remove.apply(this.node.classList, arguments);
1500this._distributeParent();
1501},
1502toggle: function () {
1503this.node.classList.toggle.apply(this.node.classList, arguments);
1504this._distributeParent();
1505},
1506_distributeParent: function () {
1507if (!useShadow) {
1508this.domApi._maybeDistributeParent();
1509}
1510},
1511contains: function () {
1512return this.node.classList.contains.apply(this.node.classList, arguments);
1513}
1514};
1515}());(function () {
1516'use strict';
1517var DomApi = Polymer.DomApi.ctor;
1518var Settings = Polymer.Settings;
1519DomApi.EffectiveNodesObserver = function (domApi) {
1520this.domApi = domApi;
1521this.node = this.domApi.node;
1522this._listeners = [];
1523};
1524DomApi.EffectiveNodesObserver.prototype = {
1525addListener: function (callback) {
1526if (!this._isSetup) {
1527this._setup();
1528this._isSetup = true;
1529}
1530var listener = {
1531fn: callback,
1532_nodes: []
1533};
1534this._listeners.push(listener);
1535this._scheduleNotify();
1536return listener;
1537},
1538removeListener: function (handle) {
1539var i = this._listeners.indexOf(handle);
1540if (i >= 0) {
1541this._listeners.splice(i, 1);
1542handle._nodes = [];
1543}
1544if (!this._hasListeners()) {
1545this._cleanup();
1546this._isSetup = false;
1547}
1548},
1549_setup: function () {
1550this._observeContentElements(this.domApi.childNodes);
1551},
1552_cleanup: function () {
1553this._unobserveContentElements(this.domApi.childNodes);
1554},
1555_hasListeners: function () {
1556return Boolean(this._listeners.length);
1557},
1558_scheduleNotify: function () {
1559if (this._debouncer) {
1560this._debouncer.stop();
1561}
1562this._debouncer = Polymer.Debounce(this._debouncer, this._notify);
1563this._debouncer.context = this;
1564Polymer.dom.addDebouncer(this._debouncer);
1565},
1566notify: function () {
1567if (this._hasListeners()) {
1568this._scheduleNotify();
1569}
1570},
1571_notify: function () {
1572this._beforeCallListeners();
1573this._callListeners();
1574},
1575_beforeCallListeners: function () {
1576this._updateContentElements();
1577},
1578_updateContentElements: function () {
1579this._observeContentElements(this.domApi.childNodes);
1580},
1581_observeContentElements: function (elements) {
1582for (var i = 0, n; i < elements.length && (n = elements[i]); i++) {
1583if (this._isContent(n)) {
1584n.__observeNodesMap = n.__observeNodesMap || new WeakMap();
1585if (!n.__observeNodesMap.has(this)) {
1586n.__observeNodesMap.set(this, this._observeContent(n));
1587}
1588}
1589}
1590},
1591_observeContent: function (content) {
1592var self = this;
1593var h = Polymer.dom(content).observeNodes(function () {
1594self._scheduleNotify();
1595});
1596h._avoidChangeCalculation = true;
1597return h;
1598},
1599_unobserveContentElements: function (elements) {
1600for (var i = 0, n, h; i < elements.length && (n = elements[i]); i++) {
1601if (this._isContent(n)) {
1602h = n.__observeNodesMap.get(this);
1603if (h) {
1604Polymer.dom(n).unobserveNodes(h);
1605n.__observeNodesMap.delete(this);
1606}
1607}
1608}
1609},
1610_isContent: function (node) {
1611return node.localName === 'content';
1612},
1613_callListeners: function () {
1614var o$ = this._listeners;
1615var nodes = this._getEffectiveNodes();
1616for (var i = 0, o; i < o$.length && (o = o$[i]); i++) {
1617var info = this._generateListenerInfo(o, nodes);
1618if (info || o._alwaysNotify) {
1619this._callListener(o, info);
1620}
1621}
1622},
1623_getEffectiveNodes: function () {
1624return this.domApi.getEffectiveChildNodes();
1625},
1626_generateListenerInfo: function (listener, newNodes) {
1627if (listener._avoidChangeCalculation) {
1628return true;
1629}
1630var oldNodes = listener._nodes;
1631var info = {
1632target: this.node,
1633addedNodes: [],
1634removedNodes: []
1635};
1636var splices = Polymer.ArraySplice.calculateSplices(newNodes, oldNodes);
1637for (var i = 0, s; i < splices.length && (s = splices[i]); i++) {
1638for (var j = 0, n; j < s.removed.length && (n = s.removed[j]); j++) {
1639info.removedNodes.push(n);
1640}
1641}
1642for (i = 0, s; i < splices.length && (s = splices[i]); i++) {
1643for (j = s.index; j < s.index + s.addedCount; j++) {
1644info.addedNodes.push(newNodes[j]);
1645}
1646}
1647listener._nodes = newNodes;
1648if (info.addedNodes.length || info.removedNodes.length) {
1649return info;
1650}
1651},
1652_callListener: function (listener, info) {
1653return listener.fn.call(this.node, info);
1654},
1655enableShadowAttributeTracking: function () {
1656}
1657};
1658if (Settings.useShadow) {
1659var baseSetup = DomApi.EffectiveNodesObserver.prototype._setup;
1660var baseCleanup = DomApi.EffectiveNodesObserver.prototype._cleanup;
1661Polymer.Base.mixin(DomApi.EffectiveNodesObserver.prototype, {
1662_setup: function () {
1663if (!this._observer) {
1664var self = this;
1665this._mutationHandler = function (mxns) {
1666if (mxns && mxns.length) {
1667self._scheduleNotify();
1668}
1669};
1670this._observer = new MutationObserver(this._mutationHandler);
1671this._boundFlush = function () {
1672self._flush();
1673};
1674Polymer.dom.addStaticFlush(this._boundFlush);
1675this._observer.observe(this.node, { childList: true });
1676}
1677baseSetup.call(this);
1678},
1679_cleanup: function () {
1680this._observer.disconnect();
1681this._observer = null;
1682this._mutationHandler = null;
1683Polymer.dom.removeStaticFlush(this._boundFlush);
1684baseCleanup.call(this);
1685},
1686_flush: function () {
1687if (this._observer) {
1688this._mutationHandler(this._observer.takeRecords());
1689}
1690},
1691enableShadowAttributeTracking: function () {
1692if (this._observer) {
1693this._makeContentListenersAlwaysNotify();
1694this._observer.disconnect();
1695this._observer.observe(this.node, {
1696childList: true,
1697attributes: true,
1698subtree: true
1699});
1700var root = this.domApi.getOwnerRoot();
1701var host = root && root.host;
1702if (host && Polymer.dom(host).observer) {
1703Polymer.dom(host).observer.enableShadowAttributeTracking();
1704}
1705}
1706},
1707_makeContentListenersAlwaysNotify: function () {
1708for (var i = 0, h; i < this._listeners.length; i++) {
1709h = this._listeners[i];
1710h._alwaysNotify = h._isContentListener;
1711}
1712}
1713});
1714}
1715}());(function () {
1716'use strict';
1717var DomApi = Polymer.DomApi.ctor;
1718var Settings = Polymer.Settings;
1719DomApi.DistributedNodesObserver = function (domApi) {
1720DomApi.EffectiveNodesObserver.call(this, domApi);
1721};
1722DomApi.DistributedNodesObserver.prototype = Object.create(DomApi.EffectiveNodesObserver.prototype);
1723Polymer.Base.mixin(DomApi.DistributedNodesObserver.prototype, {
1724_setup: function () {
1725},
1726_cleanup: function () {
1727},
1728_beforeCallListeners: function () {
1729},
1730_getEffectiveNodes: function () {
1731return this.domApi.getDistributedNodes();
1732}
1733});
1734if (Settings.useShadow) {
1735Polymer.Base.mixin(DomApi.DistributedNodesObserver.prototype, {
1736_setup: function () {
1737if (!this._observer) {
1738var root = this.domApi.getOwnerRoot();
1739var host = root && root.host;
1740if (host) {
1741var self = this;
1742this._observer = Polymer.dom(host).observeNodes(function () {
1743self._scheduleNotify();
1744});
1745this._observer._isContentListener = true;
1746if (this._hasAttrSelect()) {
1747Polymer.dom(host).observer.enableShadowAttributeTracking();
1748}
1749}
1750}
1751},
1752_hasAttrSelect: function () {
1753var select = this.node.getAttribute('select');
1754return select && select.match(/[[.]+/);
1755},
1756_cleanup: function () {
1757var root = this.domApi.getOwnerRoot();
1758var host = root && root.host;
1759if (host) {
1760Polymer.dom(host).unobserveNodes(this._observer);
1761}
1762this._observer = null;
1763}
1764});
1765}
1766}());(function () {
1767var DomApi = Polymer.DomApi;
1768var TreeApi = Polymer.TreeApi;
1769Polymer.Base._addFeature({
1770_prepShady: function () {
1771this._useContent = this._useContent || Boolean(this._template);
1772},
1773_setupShady: function () {
1774this.shadyRoot = null;
1775if (!this.__domApi) {
1776this.__domApi = null;
1777}
1778if (!this.__dom) {
1779this.__dom = null;
1780}
1781if (!this._ownerShadyRoot) {
1782this._ownerShadyRoot = undefined;
1783}
1784},
1785_poolContent: function () {
1786if (this._useContent) {
1787TreeApi.Logical.saveChildNodes(this);
1788}
1789},
1790_setupRoot: function () {
1791if (this._useContent) {
1792this._createLocalRoot();
1793if (!this.dataHost) {
1794upgradeLogicalChildren(TreeApi.Logical.getChildNodes(this));
1795}
1796}
1797},
1798_createLocalRoot: function () {
1799this.shadyRoot = this.root;
1800this.shadyRoot._distributionClean = false;
1801this.shadyRoot._hasDistributed = false;
1802this.shadyRoot._isShadyRoot = true;
1803this.shadyRoot._dirtyRoots = [];
1804var i$ = this.shadyRoot._insertionPoints = !this._notes || this._notes._hasContent ? this.shadyRoot.querySelectorAll('content') : [];
1805TreeApi.Logical.saveChildNodes(this.shadyRoot);
1806for (var i = 0, c; i < i$.length; i++) {
1807c = i$[i];
1808TreeApi.Logical.saveChildNodes(c);
1809TreeApi.Logical.saveChildNodes(c.parentNode);
1810}
1811this.shadyRoot.host = this;
1812},
1813distributeContent: function (updateInsertionPoints) {
1814if (this.shadyRoot) {
1815this.shadyRoot._invalidInsertionPoints = this.shadyRoot._invalidInsertionPoints || updateInsertionPoints;
1816var host = getTopDistributingHost(this);
1817Polymer.dom(this)._lazyDistribute(host);
1818}
1819},
1820_distributeContent: function () {
1821if (this._useContent && !this.shadyRoot._distributionClean) {
1822if (this.shadyRoot._invalidInsertionPoints) {
1823Polymer.dom(this)._updateInsertionPoints(this);
1824this.shadyRoot._invalidInsertionPoints = false;
1825}
1826this._beginDistribute();
1827this._distributeDirtyRoots();
1828this._finishDistribute();
1829}
1830},
1831_beginDistribute: function () {
1832if (this._useContent && DomApi.hasInsertionPoint(this.shadyRoot)) {
1833this._resetDistribution();
1834this._distributePool(this.shadyRoot, this._collectPool());
1835}
1836},
1837_distributeDirtyRoots: function () {
1838var c$ = this.shadyRoot._dirtyRoots;
1839for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) {
1840c._distributeContent();
1841}
1842this.shadyRoot._dirtyRoots = [];
1843},
1844_finishDistribute: function () {
1845if (this._useContent) {
1846this.shadyRoot._distributionClean = true;
1847if (DomApi.hasInsertionPoint(this.shadyRoot)) {
1848this._composeTree();
1849notifyContentObservers(this.shadyRoot);
1850} else {
1851if (!this.shadyRoot._hasDistributed) {
1852TreeApi.Composed.clearChildNodes(this);
1853this.appendChild(this.shadyRoot);
1854} else {
1855var children = this._composeNode(this);
1856this._updateChildNodes(this, children);
1857}
1858}
1859if (!this.shadyRoot._hasDistributed) {
1860notifyInitialDistribution(this);
1861}
1862this.shadyRoot._hasDistributed = true;
1863}
1864},
1865elementMatches: function (selector, node) {
1866node = node || this;
1867return DomApi.matchesSelector.call(node, selector);
1868},
1869_resetDistribution: function () {
1870var children = TreeApi.Logical.getChildNodes(this);
1871for (var i = 0; i < children.length; i++) {
1872var child = children[i];
1873if (child._destinationInsertionPoints) {
1874child._destinationInsertionPoints = undefined;
1875}
1876if (isInsertionPoint(child)) {
1877clearDistributedDestinationInsertionPoints(child);
1878}
1879}
1880var root = this.shadyRoot;
1881var p$ = root._insertionPoints;
1882for (var j = 0; j < p$.length; j++) {
1883p$[j]._distributedNodes = [];
1884}
1885},
1886_collectPool: function () {
1887var pool = [];
1888var children = TreeApi.Logical.getChildNodes(this);
1889for (var i = 0; i < children.length; i++) {
1890var child = children[i];
1891if (isInsertionPoint(child)) {
1892pool.push.apply(pool, child._distributedNodes);
1893} else {
1894pool.push(child);
1895}
1896}
1897return pool;
1898},
1899_distributePool: function (node, pool) {
1900var p$ = node._insertionPoints;
1901for (var i = 0, l = p$.length, p; i < l && (p = p$[i]); i++) {
1902this._distributeInsertionPoint(p, pool);
1903maybeRedistributeParent(p, this);
1904}
1905},
1906_distributeInsertionPoint: function (content, pool) {
1907var anyDistributed = false;
1908for (var i = 0, l = pool.length, node; i < l; i++) {
1909node = pool[i];
1910if (!node) {
1911continue;
1912}
1913if (this._matchesContentSelect(node, content)) {
1914distributeNodeInto(node, content);
1915pool[i] = undefined;
1916anyDistributed = true;
1917}
1918}
1919if (!anyDistributed) {
1920var children = TreeApi.Logical.getChildNodes(content);
1921for (var j = 0; j < children.length; j++) {
1922distributeNodeInto(children[j], content);
1923}
1924}
1925},
1926_composeTree: function () {
1927this._updateChildNodes(this, this._composeNode(this));
1928var p$ = this.shadyRoot._insertionPoints;
1929for (var i = 0, l = p$.length, p, parent; i < l && (p = p$[i]); i++) {
1930parent = TreeApi.Logical.getParentNode(p);
1931if (!parent._useContent && parent !== this && parent !== this.shadyRoot) {
1932this._updateChildNodes(parent, this._composeNode(parent));
1933}
1934}
1935},
1936_composeNode: function (node) {
1937var children = [];
1938var c$ = TreeApi.Logical.getChildNodes(node.shadyRoot || node);
1939for (var i = 0; i < c$.length; i++) {
1940var child = c$[i];
1941if (isInsertionPoint(child)) {
1942var distributedNodes = child._distributedNodes;
1943for (var j = 0; j < distributedNodes.length; j++) {
1944var distributedNode = distributedNodes[j];
1945if (isFinalDestination(child, distributedNode)) {
1946children.push(distributedNode);
1947}
1948}
1949} else {
1950children.push(child);
1951}
1952}
1953return children;
1954},
1955_updateChildNodes: function (container, children) {
1956var composed = TreeApi.Composed.getChildNodes(container);
1957var splices = Polymer.ArraySplice.calculateSplices(children, composed);
1958for (var i = 0, d = 0, s; i < splices.length && (s = splices[i]); i++) {
1959for (var j = 0, n; j < s.removed.length && (n = s.removed[j]); j++) {
1960if (TreeApi.Composed.getParentNode(n) === container) {
1961TreeApi.Composed.removeChild(container, n);
1962}
1963composed.splice(s.index + d, 1);
1964}
1965d -= s.addedCount;
1966}
1967for (var i = 0, s, next; i < splices.length && (s = splices[i]); i++) {
1968next = composed[s.index];
1969for (j = s.index, n; j < s.index + s.addedCount; j++) {
1970n = children[j];
1971TreeApi.Composed.insertBefore(container, n, next);
1972composed.splice(j, 0, n);
1973}
1974}
1975},
1976_matchesContentSelect: function (node, contentElement) {
1977var select = contentElement.getAttribute('select');
1978if (!select) {
1979return true;
1980}
1981select = select.trim();
1982if (!select) {
1983return true;
1984}
1985if (!(node instanceof Element)) {
1986return false;
1987}
1988var validSelectors = /^(:not\()?[*.#[a-zA-Z_|]/;
1989if (!validSelectors.test(select)) {
1990return false;
1991}
1992return this.elementMatches(select, node);
1993},
1994_elementAdd: function () {
1995},
1996_elementRemove: function () {
1997}
1998});
1999var domHostDesc = {
2000get: function () {
2001var root = Polymer.dom(this).getOwnerRoot();
2002return root && root.host;
2003},
2004configurable: true
2005};
2006Object.defineProperty(Polymer.Base, 'domHost', domHostDesc);
2007Polymer.BaseDescriptors.domHost = domHostDesc;
2008function distributeNodeInto(child, insertionPoint) {
2009insertionPoint._distributedNodes.push(child);
2010var points = child._destinationInsertionPoints;
2011if (!points) {
2012child._destinationInsertionPoints = [insertionPoint];
2013} else {
2014points.push(insertionPoint);
2015}
2016}
2017function clearDistributedDestinationInsertionPoints(content) {
2018var e$ = content._distributedNodes;
2019if (e$) {
2020for (var i = 0; i < e$.length; i++) {
2021var d = e$[i]._destinationInsertionPoints;
2022if (d) {
2023d.splice(d.indexOf(content) + 1, d.length);
2024}
2025}
2026}
2027}
2028function maybeRedistributeParent(content, host) {
2029var parent = TreeApi.Logical.getParentNode(content);
2030if (parent && parent.shadyRoot && DomApi.hasInsertionPoint(parent.shadyRoot) && parent.shadyRoot._distributionClean) {
2031parent.shadyRoot._distributionClean = false;
2032host.shadyRoot._dirtyRoots.push(parent);
2033}
2034}
2035function isFinalDestination(insertionPoint, node) {
2036var points = node._destinationInsertionPoints;
2037return points && points[points.length - 1] === insertionPoint;
2038}
2039function isInsertionPoint(node) {
2040return node.localName == 'content';
2041}
2042function getTopDistributingHost(host) {
2043while (host && hostNeedsRedistribution(host)) {
2044host = host.domHost;
2045}
2046return host;
2047}
2048function hostNeedsRedistribution(host) {
2049var c$ = TreeApi.Logical.getChildNodes(host);
2050for (var i = 0, c; i < c$.length; i++) {
2051c = c$[i];
2052if (c.localName && c.localName === 'content') {
2053return host.domHost;
2054}
2055}
2056}
2057function notifyContentObservers(root) {
2058for (var i = 0, c; i < root._insertionPoints.length; i++) {
2059c = root._insertionPoints[i];
2060if (DomApi.hasApi(c)) {
2061Polymer.dom(c).notifyObserver();
2062}
2063}
2064}
2065function notifyInitialDistribution(host) {
2066if (DomApi.hasApi(host)) {
2067Polymer.dom(host).notifyObserver();
2068}
2069}
2070var needsUpgrade = window.CustomElements && !CustomElements.useNative;
2071function upgradeLogicalChildren(children) {
2072if (needsUpgrade && children) {
2073for (var i = 0; i < children.length; i++) {
2074CustomElements.upgrade(children[i]);
2075}
2076}
2077}
2078}());if (Polymer.Settings.useShadow) {
2079Polymer.Base._addFeature({
2080_poolContent: function () {
2081},
2082_beginDistribute: function () {
2083},
2084distributeContent: function () {
2085},
2086_distributeContent: function () {
2087},
2088_finishDistribute: function () {
2089},
2090_createLocalRoot: function () {
2091this.createShadowRoot();
2092this.shadowRoot.appendChild(this.root);
2093this.root = this.shadowRoot;
2094}
2095});
2096}Polymer.Async = {
2097_currVal: 0,
2098_lastVal: 0,
2099_callbacks: [],
2100_twiddleContent: 0,
2101_twiddle: document.createTextNode(''),
2102run: function (callback, waitTime) {
2103if (waitTime > 0) {
2104return ~setTimeout(callback, waitTime);
2105} else {
2106this._twiddle.textContent = this._twiddleContent++;
2107this._callbacks.push(callback);
2108return this._currVal++;
2109}
2110},
2111cancel: function (handle) {
2112if (handle < 0) {
2113clearTimeout(~handle);
2114} else {
2115var idx = handle - this._lastVal;
2116if (idx >= 0) {
2117if (!this._callbacks[idx]) {
2118throw 'invalid async handle: ' + handle;
2119}
2120this._callbacks[idx] = null;
2121}
2122}
2123},
2124_atEndOfMicrotask: function () {
2125var len = this._callbacks.length;
2126for (var i = 0; i < len; i++) {
2127var cb = this._callbacks[i];
2128if (cb) {
2129try {
2130cb();
2131} catch (e) {
2132i++;
2133this._callbacks.splice(0, i);
2134this._lastVal += i;
2135this._twiddle.textContent = this._twiddleContent++;
2136throw e;
2137}
2138}
2139}
2140this._callbacks.splice(0, len);
2141this._lastVal += len;
2142}
2143};
2144new window.MutationObserver(function () {
2145Polymer.Async._atEndOfMicrotask();
2146}).observe(Polymer.Async._twiddle, { characterData: true });Polymer.Debounce = function () {
2147var Async = Polymer.Async;
2148var Debouncer = function (context) {
2149this.context = context;
2150var self = this;
2151this.boundComplete = function () {
2152self.complete();
2153};
2154};
2155Debouncer.prototype = {
2156go: function (callback, wait) {
2157var h;
2158this.finish = function () {
2159Async.cancel(h);
2160};
2161h = Async.run(this.boundComplete, wait);
2162this.callback = callback;
2163},
2164stop: function () {
2165if (this.finish) {
2166this.finish();
2167this.finish = null;
2168this.callback = null;
2169}
2170},
2171complete: function () {
2172if (this.finish) {
2173var callback = this.callback;
2174this.stop();
2175callback.call(this.context);
2176}
2177}
2178};
2179function debounce(debouncer, callback, wait) {
2180if (debouncer) {
2181debouncer.stop();
2182} else {
2183debouncer = new Debouncer(this);
2184}
2185debouncer.go(callback, wait);
2186return debouncer;
2187}
2188return debounce;
2189}();Polymer.Base._addFeature({
2190_setupDebouncers: function () {
2191this._debouncers = {};
2192},
2193debounce: function (jobName, callback, wait) {
2194return this._debouncers[jobName] = Polymer.Debounce.call(this, this._debouncers[jobName], callback, wait);
2195},
2196isDebouncerActive: function (jobName) {
2197var debouncer = this._debouncers[jobName];
2198return !!(debouncer && debouncer.finish);
2199},
2200flushDebouncer: function (jobName) {
2201var debouncer = this._debouncers[jobName];
2202if (debouncer) {
2203debouncer.complete();
2204}
2205},
2206cancelDebouncer: function (jobName) {
2207var debouncer = this._debouncers[jobName];
2208if (debouncer) {
2209debouncer.stop();
2210}
2211}
2212});Polymer.DomModule = document.createElement('dom-module');
2213Polymer.Base._addFeature({
2214_registerFeatures: function () {
2215this._prepIs();
2216this._prepBehaviors();
2217this._prepConstructor();
2218this._prepTemplate();
2219this._prepShady();
2220this._prepPropertyInfo();
2221},
2222_prepBehavior: function (b) {
2223this._addHostAttributes(b.hostAttributes);
2224},
2225_initFeatures: function () {
2226this._registerHost();
2227if (this._template) {
2228this._poolContent();
2229this._beginHosting();
2230this._stampTemplate();
2231this._endHosting();
2232}
2233this._marshalHostAttributes();
2234this._setupDebouncers();
2235this._marshalBehaviors();
2236this._tryReady();
2237},
2238_marshalBehavior: function (b) {
2239}
2240});</script>
2241
2242
2243
2244
2245
2246
2247