gobstones-code-runner 0.0.5

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