@gluon/gluon 2.5.2 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/gluon.es5.js DELETED
@@ -1,2061 +0,0 @@
1
- /**
2
- * @license
3
- * MIT License
4
- *
5
- * Copyright (c) 2018 Goffert van Gool
6
- *
7
- * Permission is hereby granted, free of charge, to any person obtaining a copy
8
- * of this software and associated documentation files (the "Software"), to deal
9
- * in the Software without restriction, including without limitation the rights
10
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- * copies of the Software, and to permit persons to whom the Software is
12
- * furnished to do so, subject to the following conditions:
13
- *
14
- * The above copyright notice and this permission notice shall be included in all
15
- * copies or substantial portions of the Software.
16
- *
17
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- * SOFTWARE.
24
- */
25
-
26
- var GluonJS = (function (exports) {
27
- 'use strict';
28
-
29
- /**
30
- * @license
31
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
32
- * This code may only be used under the BSD style license found at
33
- * http://polymer.github.io/LICENSE.txt
34
- * The complete set of authors may be found at
35
- * http://polymer.github.io/AUTHORS.txt
36
- * The complete set of contributors may be found at
37
- * http://polymer.github.io/CONTRIBUTORS.txt
38
- * Code distributed by Google as part of the polymer project is also
39
- * subject to an additional IP rights grant found at
40
- * http://polymer.github.io/PATENTS.txt
41
- */
42
- /**
43
- * True if the custom elements polyfill is in use.
44
- */
45
- var isCEPolyfill = window.customElements !== undefined && window.customElements.polyfillWrapFlushCallback !== undefined;
46
- /**
47
- * Reparents nodes, starting from `startNode` (inclusive) to `endNode`
48
- * (exclusive), into another container (could be the same container), before
49
- * `beforeNode`. If `beforeNode` is null, it appends the nodes to the
50
- * container.
51
- */
52
- var reparentNodes = function reparentNodes(container, start) {
53
- var end = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
54
- var before = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
55
-
56
- var node = start;
57
- while (node !== end) {
58
- var n = node.nextSibling;
59
- container.insertBefore(node, before);
60
- node = n;
61
- }
62
- };
63
- /**
64
- * Removes nodes, starting from `startNode` (inclusive) to `endNode`
65
- * (exclusive), from `container`.
66
- */
67
- var removeNodes = function removeNodes(container, startNode) {
68
- var endNode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
69
-
70
- var node = startNode;
71
- while (node !== endNode) {
72
- var n = node.nextSibling;
73
- container.removeChild(node);
74
- node = n;
75
- }
76
- };
77
-
78
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
79
- return typeof obj;
80
- } : function (obj) {
81
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
82
- };
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
- var asyncToGenerator = function (fn) {
93
- return function () {
94
- var gen = fn.apply(this, arguments);
95
- return new Promise(function (resolve, reject) {
96
- function step(key, arg) {
97
- try {
98
- var info = gen[key](arg);
99
- var value = info.value;
100
- } catch (error) {
101
- reject(error);
102
- return;
103
- }
104
-
105
- if (info.done) {
106
- resolve(value);
107
- } else {
108
- return Promise.resolve(value).then(function (value) {
109
- step("next", value);
110
- }, function (err) {
111
- step("throw", err);
112
- });
113
- }
114
- }
115
-
116
- return step("next");
117
- });
118
- };
119
- };
120
-
121
- var classCallCheck = function (instance, Constructor) {
122
- if (!(instance instanceof Constructor)) {
123
- throw new TypeError("Cannot call a class as a function");
124
- }
125
- };
126
-
127
- var createClass = function () {
128
- function defineProperties(target, props) {
129
- for (var i = 0; i < props.length; i++) {
130
- var descriptor = props[i];
131
- descriptor.enumerable = descriptor.enumerable || false;
132
- descriptor.configurable = true;
133
- if ("value" in descriptor) descriptor.writable = true;
134
- Object.defineProperty(target, descriptor.key, descriptor);
135
- }
136
- }
137
-
138
- return function (Constructor, protoProps, staticProps) {
139
- if (protoProps) defineProperties(Constructor.prototype, protoProps);
140
- if (staticProps) defineProperties(Constructor, staticProps);
141
- return Constructor;
142
- };
143
- }();
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
- var get = function get(object, property, receiver) {
152
- if (object === null) object = Function.prototype;
153
- var desc = Object.getOwnPropertyDescriptor(object, property);
154
-
155
- if (desc === undefined) {
156
- var parent = Object.getPrototypeOf(object);
157
-
158
- if (parent === null) {
159
- return undefined;
160
- } else {
161
- return get(parent, property, receiver);
162
- }
163
- } else if ("value" in desc) {
164
- return desc.value;
165
- } else {
166
- var getter = desc.get;
167
-
168
- if (getter === undefined) {
169
- return undefined;
170
- }
171
-
172
- return getter.call(receiver);
173
- }
174
- };
175
-
176
- var inherits = function (subClass, superClass) {
177
- if (typeof superClass !== "function" && superClass !== null) {
178
- throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
179
- }
180
-
181
- subClass.prototype = Object.create(superClass && superClass.prototype, {
182
- constructor: {
183
- value: subClass,
184
- enumerable: false,
185
- writable: true,
186
- configurable: true
187
- }
188
- });
189
- if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
190
- };
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
- var possibleConstructorReturn = function (self, call) {
203
- if (!self) {
204
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
205
- }
206
-
207
- return call && (typeof call === "object" || typeof call === "function") ? call : self;
208
- };
209
-
210
-
211
-
212
-
213
-
214
-
215
-
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
-
224
-
225
-
226
-
227
-
228
- var toConsumableArray = function (arr) {
229
- if (Array.isArray(arr)) {
230
- for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
231
-
232
- return arr2;
233
- } else {
234
- return Array.from(arr);
235
- }
236
- };
237
-
238
- /**
239
- * @license
240
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
241
- * This code may only be used under the BSD style license found at
242
- * http://polymer.github.io/LICENSE.txt
243
- * The complete set of authors may be found at
244
- * http://polymer.github.io/AUTHORS.txt
245
- * The complete set of contributors may be found at
246
- * http://polymer.github.io/CONTRIBUTORS.txt
247
- * Code distributed by Google as part of the polymer project is also
248
- * subject to an additional IP rights grant found at
249
- * http://polymer.github.io/PATENTS.txt
250
- */
251
- /**
252
- * An expression marker with embedded unique key to avoid collision with
253
- * possible text in templates.
254
- */
255
- var marker = '{{lit-' + String(Math.random()).slice(2) + '}}';
256
- /**
257
- * An expression marker used text-positions, multi-binding attributes, and
258
- * attributes with markup-like text values.
259
- */
260
- var nodeMarker = '<!--' + marker + '-->';
261
- var markerRegex = new RegExp(marker + '|' + nodeMarker);
262
- /**
263
- * Suffix appended to all bound attribute names.
264
- */
265
- var boundAttributeSuffix = '$lit$';
266
- /**
267
- * An updateable Template that tracks the location of dynamic parts.
268
- */
269
- var Template = function Template(result, element) {
270
- var _this = this;
271
-
272
- classCallCheck(this, Template);
273
-
274
- this.parts = [];
275
- this.element = element;
276
- var index = -1;
277
- var partIndex = 0;
278
- var nodesToRemove = [];
279
- var _prepareTemplate = function _prepareTemplate(template) {
280
- var content = template.content;
281
- // Edge needs all 4 parameters present; IE11 needs 3rd parameter to be
282
- // null
283
- var walker = document.createTreeWalker(content, 133 /* NodeFilter.SHOW_{ELEMENT|COMMENT|TEXT} */, null, false);
284
- // Keeps track of the last index associated with a part. We try to delete
285
- // unnecessary nodes, but we never want to associate two different parts
286
- // to the same index. They must have a constant node between.
287
- var lastPartIndex = 0;
288
- while (walker.nextNode()) {
289
- index++;
290
- var node = walker.currentNode;
291
- if (node.nodeType === 1 /* Node.ELEMENT_NODE */) {
292
- if (node.hasAttributes()) {
293
- var attributes = node.attributes;
294
- // Per
295
- // https://developer.mozilla.org/en-US/docs/Web/API/NamedNodeMap,
296
- // attributes are not guaranteed to be returned in document order.
297
- // In particular, Edge/IE can return them out of order, so we cannot
298
- // assume a correspondance between part index and attribute index.
299
- var count = 0;
300
- for (var i = 0; i < attributes.length; i++) {
301
- if (attributes[i].value.indexOf(marker) >= 0) {
302
- count++;
303
- }
304
- }
305
- while (count-- > 0) {
306
- // Get the template literal section leading up to the first
307
- // expression in this attribute
308
- var stringForPart = result.strings[partIndex];
309
- // Find the attribute name
310
- var name = lastAttributeNameRegex.exec(stringForPart)[2];
311
- // Find the corresponding attribute
312
- // All bound attributes have had a suffix added in
313
- // TemplateResult#getHTML to opt out of special attribute
314
- // handling. To look up the attribute value we also need to add
315
- // the suffix.
316
- var attributeLookupName = name.toLowerCase() + boundAttributeSuffix;
317
- var attributeValue = node.getAttribute(attributeLookupName);
318
- var strings = attributeValue.split(markerRegex);
319
- _this.parts.push({ type: 'attribute', index: index, name: name, strings: strings });
320
- node.removeAttribute(attributeLookupName);
321
- partIndex += strings.length - 1;
322
- }
323
- }
324
- if (node.tagName === 'TEMPLATE') {
325
- _prepareTemplate(node);
326
- }
327
- } else if (node.nodeType === 3 /* Node.TEXT_NODE */) {
328
- var data = node.data;
329
- if (data.indexOf(marker) >= 0) {
330
- var parent = node.parentNode;
331
- var _strings = data.split(markerRegex);
332
- var lastIndex = _strings.length - 1;
333
- // Generate a new text node for each literal section
334
- // These nodes are also used as the markers for node parts
335
- for (var _i = 0; _i < lastIndex; _i++) {
336
- parent.insertBefore(_strings[_i] === '' ? createMarker() : document.createTextNode(_strings[_i]), node);
337
- _this.parts.push({ type: 'node', index: ++index });
338
- }
339
- // If there's no text, we must insert a comment to mark our place.
340
- // Else, we can trust it will stick around after cloning.
341
- if (_strings[lastIndex] === '') {
342
- parent.insertBefore(createMarker(), node);
343
- nodesToRemove.push(node);
344
- } else {
345
- node.data = _strings[lastIndex];
346
- }
347
- // We have a part for each match found
348
- partIndex += lastIndex;
349
- }
350
- } else if (node.nodeType === 8 /* Node.COMMENT_NODE */) {
351
- if (node.data === marker) {
352
- var _parent = node.parentNode;
353
- // Add a new marker node to be the startNode of the Part if any of
354
- // the following are true:
355
- // * We don't have a previousSibling
356
- // * The previousSibling is already the start of a previous part
357
- if (node.previousSibling === null || index === lastPartIndex) {
358
- index++;
359
- _parent.insertBefore(createMarker(), node);
360
- }
361
- lastPartIndex = index;
362
- _this.parts.push({ type: 'node', index: index });
363
- // If we don't have a nextSibling, keep this node so we have an end.
364
- // Else, we can remove it to save future costs.
365
- if (node.nextSibling === null) {
366
- node.data = '';
367
- } else {
368
- nodesToRemove.push(node);
369
- index--;
370
- }
371
- partIndex++;
372
- } else {
373
- var _i2 = -1;
374
- while ((_i2 = node.data.indexOf(marker, _i2 + 1)) !== -1) {
375
- // Comment node has a binding marker inside, make an inactive part
376
- // The binding won't work, but subsequent bindings will
377
- // TODO (justinfagnani): consider whether it's even worth it to
378
- // make bindings in comments work
379
- _this.parts.push({ type: 'node', index: -1 });
380
- }
381
- }
382
- }
383
- }
384
- };
385
- _prepareTemplate(element);
386
- // Remove text binding nodes after the walk to not disturb the TreeWalker
387
- var _iteratorNormalCompletion = true;
388
- var _didIteratorError = false;
389
- var _iteratorError = undefined;
390
-
391
- try {
392
- for (var _iterator = nodesToRemove[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
393
- var n = _step.value;
394
-
395
- n.parentNode.removeChild(n);
396
- }
397
- } catch (err) {
398
- _didIteratorError = true;
399
- _iteratorError = err;
400
- } finally {
401
- try {
402
- if (!_iteratorNormalCompletion && _iterator.return) {
403
- _iterator.return();
404
- }
405
- } finally {
406
- if (_didIteratorError) {
407
- throw _iteratorError;
408
- }
409
- }
410
- }
411
- };
412
- var isTemplatePartActive = function isTemplatePartActive(part) {
413
- return part.index !== -1;
414
- };
415
- // Allows `document.createComment('')` to be renamed for a
416
- // small manual size-savings.
417
- var createMarker = function createMarker() {
418
- return document.createComment('');
419
- };
420
- /**
421
- * This regex extracts the attribute name preceding an attribute-position
422
- * expression. It does this by matching the syntax allowed for attributes
423
- * against the string literal directly preceding the expression, assuming that
424
- * the expression is in an attribute-value position.
425
- *
426
- * See attributes in the HTML spec:
427
- * https://www.w3.org/TR/html5/syntax.html#attributes-0
428
- *
429
- * "\0-\x1F\x7F-\x9F" are Unicode control characters
430
- *
431
- * " \x09\x0a\x0c\x0d" are HTML space characters:
432
- * https://www.w3.org/TR/html5/infrastructure.html#space-character
433
- *
434
- * So an attribute is:
435
- * * The name: any character except a control character, space character, ('),
436
- * ("), ">", "=", or "/"
437
- * * Followed by zero or more space characters
438
- * * Followed by "="
439
- * * Followed by zero or more space characters
440
- * * Followed by:
441
- * * Any character except space, ('), ("), "<", ">", "=", (`), or
442
- * * (") then any non-("), or
443
- * * (') then any non-(')
444
- */
445
- var lastAttributeNameRegex = /([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F \x09\x0a\x0c\x0d"'>=/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/;
446
-
447
- /**
448
- * @license
449
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
450
- * This code may only be used under the BSD style license found at
451
- * http://polymer.github.io/LICENSE.txt
452
- * The complete set of authors may be found at
453
- * http://polymer.github.io/AUTHORS.txt
454
- * The complete set of contributors may be found at
455
- * http://polymer.github.io/CONTRIBUTORS.txt
456
- * Code distributed by Google as part of the polymer project is also
457
- * subject to an additional IP rights grant found at
458
- * http://polymer.github.io/PATENTS.txt
459
- */
460
- /**
461
- * @module shady-render
462
- */
463
- var walkerNodeFilter = 133;
464
- /**
465
- * Removes the list of nodes from a Template safely. In addition to removing
466
- * nodes from the Template, the Template part indices are updated to match
467
- * the mutated Template DOM.
468
- *
469
- * As the template is walked the removal state is tracked and
470
- * part indices are adjusted as needed.
471
- *
472
- * div
473
- * div#1 (remove) <-- start removing (removing node is div#1)
474
- * div
475
- * div#2 (remove) <-- continue removing (removing node is still div#1)
476
- * div
477
- * div <-- stop removing since previous sibling is the removing node (div#1,
478
- * removed 4 nodes)
479
- */
480
- function removeNodesFromTemplate(template, nodesToRemove) {
481
- var content = template.element.content,
482
- parts = template.parts;
483
-
484
- var walker = document.createTreeWalker(content, walkerNodeFilter, null, false);
485
- var partIndex = nextActiveIndexInTemplateParts(parts);
486
- var part = parts[partIndex];
487
- var nodeIndex = -1;
488
- var removeCount = 0;
489
- var nodesToRemoveInTemplate = [];
490
- var currentRemovingNode = null;
491
- while (walker.nextNode()) {
492
- nodeIndex++;
493
- var node = walker.currentNode;
494
- // End removal if stepped past the removing node
495
- if (node.previousSibling === currentRemovingNode) {
496
- currentRemovingNode = null;
497
- }
498
- // A node to remove was found in the template
499
- if (nodesToRemove.has(node)) {
500
- nodesToRemoveInTemplate.push(node);
501
- // Track node we're removing
502
- if (currentRemovingNode === null) {
503
- currentRemovingNode = node;
504
- }
505
- }
506
- // When removing, increment count by which to adjust subsequent part indices
507
- if (currentRemovingNode !== null) {
508
- removeCount++;
509
- }
510
- while (part !== undefined && part.index === nodeIndex) {
511
- // If part is in a removed node deactivate it by setting index to -1 or
512
- // adjust the index as needed.
513
- part.index = currentRemovingNode !== null ? -1 : part.index - removeCount;
514
- // go to the next active part.
515
- partIndex = nextActiveIndexInTemplateParts(parts, partIndex);
516
- part = parts[partIndex];
517
- }
518
- }
519
- nodesToRemoveInTemplate.forEach(function (n) {
520
- return n.parentNode.removeChild(n);
521
- });
522
- }
523
- var countNodes = function countNodes(node) {
524
- var count = node.nodeType === 11 /* Node.DOCUMENT_FRAGMENT_NODE */ ? 0 : 1;
525
- var walker = document.createTreeWalker(node, walkerNodeFilter, null, false);
526
- while (walker.nextNode()) {
527
- count++;
528
- }
529
- return count;
530
- };
531
- var nextActiveIndexInTemplateParts = function nextActiveIndexInTemplateParts(parts) {
532
- var startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
533
-
534
- for (var i = startIndex + 1; i < parts.length; i++) {
535
- var part = parts[i];
536
- if (isTemplatePartActive(part)) {
537
- return i;
538
- }
539
- }
540
- return -1;
541
- };
542
- /**
543
- * Inserts the given node into the Template, optionally before the given
544
- * refNode. In addition to inserting the node into the Template, the Template
545
- * part indices are updated to match the mutated Template DOM.
546
- */
547
- function insertNodeIntoTemplate(template, node) {
548
- var refNode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
549
- var content = template.element.content,
550
- parts = template.parts;
551
- // If there's no refNode, then put node at end of template.
552
- // No part indices need to be shifted in this case.
553
-
554
- if (refNode === null || refNode === undefined) {
555
- content.appendChild(node);
556
- return;
557
- }
558
- var walker = document.createTreeWalker(content, walkerNodeFilter, null, false);
559
- var partIndex = nextActiveIndexInTemplateParts(parts);
560
- var insertCount = 0;
561
- var walkerIndex = -1;
562
- while (walker.nextNode()) {
563
- walkerIndex++;
564
- var walkerNode = walker.currentNode;
565
- if (walkerNode === refNode) {
566
- insertCount = countNodes(node);
567
- refNode.parentNode.insertBefore(node, refNode);
568
- }
569
- while (partIndex !== -1 && parts[partIndex].index === walkerIndex) {
570
- // If we've inserted the node, simply adjust all subsequent parts
571
- if (insertCount > 0) {
572
- while (partIndex !== -1) {
573
- parts[partIndex].index += insertCount;
574
- partIndex = nextActiveIndexInTemplateParts(parts, partIndex);
575
- }
576
- return;
577
- }
578
- partIndex = nextActiveIndexInTemplateParts(parts, partIndex);
579
- }
580
- }
581
- }
582
-
583
- /**
584
- * @license
585
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
586
- * This code may only be used under the BSD style license found at
587
- * http://polymer.github.io/LICENSE.txt
588
- * The complete set of authors may be found at
589
- * http://polymer.github.io/AUTHORS.txt
590
- * The complete set of contributors may be found at
591
- * http://polymer.github.io/CONTRIBUTORS.txt
592
- * Code distributed by Google as part of the polymer project is also
593
- * subject to an additional IP rights grant found at
594
- * http://polymer.github.io/PATENTS.txt
595
- */
596
- var directives = new WeakMap();
597
- /**
598
- * Brands a function as a directive so that lit-html will call the function
599
- * during template rendering, rather than passing as a value.
600
- *
601
- * @param f The directive factory function. Must be a function that returns a
602
- * function of the signature `(part: Part) => void`. The returned function will
603
- * be called with the part object
604
- *
605
- * @example
606
- *
607
- * ```
608
- * import {directive, html} from 'lit-html';
609
- *
610
- * const immutable = directive((v) => (part) => {
611
- * if (part.value !== v) {
612
- * part.setValue(v)
613
- * }
614
- * });
615
- * ```
616
- */
617
- // tslint:disable-next-line:no-any
618
-
619
- var isDirective = function isDirective(o) {
620
- return typeof o === 'function' && directives.has(o);
621
- };
622
-
623
- /**
624
- * @license
625
- * Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
626
- * This code may only be used under the BSD style license found at
627
- * http://polymer.github.io/LICENSE.txt
628
- * The complete set of authors may be found at
629
- * http://polymer.github.io/AUTHORS.txt
630
- * The complete set of contributors may be found at
631
- * http://polymer.github.io/CONTRIBUTORS.txt
632
- * Code distributed by Google as part of the polymer project is also
633
- * subject to an additional IP rights grant found at
634
- * http://polymer.github.io/PATENTS.txt
635
- */
636
- /**
637
- * A sentinel value that signals that a value was handled by a directive and
638
- * should not be written to the DOM.
639
- */
640
- var noChange = {};
641
- /**
642
- * A sentinel value that signals a NodePart to fully clear its content.
643
- */
644
- var nothing = {};
645
-
646
- /**
647
- * @license
648
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
649
- * This code may only be used under the BSD style license found at
650
- * http://polymer.github.io/LICENSE.txt
651
- * The complete set of authors may be found at
652
- * http://polymer.github.io/AUTHORS.txt
653
- * The complete set of contributors may be found at
654
- * http://polymer.github.io/CONTRIBUTORS.txt
655
- * Code distributed by Google as part of the polymer project is also
656
- * subject to an additional IP rights grant found at
657
- * http://polymer.github.io/PATENTS.txt
658
- */
659
- /**
660
- * @module lit-html
661
- */
662
- /**
663
- * An instance of a `Template` that can be attached to the DOM and updated
664
- * with new values.
665
- */
666
- var TemplateInstance = function () {
667
- function TemplateInstance(template, processor, options) {
668
- classCallCheck(this, TemplateInstance);
669
-
670
- this._parts = [];
671
- this.template = template;
672
- this.processor = processor;
673
- this.options = options;
674
- }
675
-
676
- createClass(TemplateInstance, [{
677
- key: 'update',
678
- value: function update(values) {
679
- var i = 0;
680
- var _iteratorNormalCompletion = true;
681
- var _didIteratorError = false;
682
- var _iteratorError = undefined;
683
-
684
- try {
685
- for (var _iterator = this._parts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
686
- var part = _step.value;
687
-
688
- if (part !== undefined) {
689
- part.setValue(values[i]);
690
- }
691
- i++;
692
- }
693
- } catch (err) {
694
- _didIteratorError = true;
695
- _iteratorError = err;
696
- } finally {
697
- try {
698
- if (!_iteratorNormalCompletion && _iterator.return) {
699
- _iterator.return();
700
- }
701
- } finally {
702
- if (_didIteratorError) {
703
- throw _iteratorError;
704
- }
705
- }
706
- }
707
-
708
- var _iteratorNormalCompletion2 = true;
709
- var _didIteratorError2 = false;
710
- var _iteratorError2 = undefined;
711
-
712
- try {
713
- for (var _iterator2 = this._parts[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
714
- var _part = _step2.value;
715
-
716
- if (_part !== undefined) {
717
- _part.commit();
718
- }
719
- }
720
- } catch (err) {
721
- _didIteratorError2 = true;
722
- _iteratorError2 = err;
723
- } finally {
724
- try {
725
- if (!_iteratorNormalCompletion2 && _iterator2.return) {
726
- _iterator2.return();
727
- }
728
- } finally {
729
- if (_didIteratorError2) {
730
- throw _iteratorError2;
731
- }
732
- }
733
- }
734
- }
735
- }, {
736
- key: '_clone',
737
- value: function _clone() {
738
- var _this = this;
739
-
740
- // When using the Custom Elements polyfill, clone the node, rather than
741
- // importing it, to keep the fragment in the template's document. This
742
- // leaves the fragment inert so custom elements won't upgrade and
743
- // potentially modify their contents by creating a polyfilled ShadowRoot
744
- // while we traverse the tree.
745
- var fragment = isCEPolyfill ? this.template.element.content.cloneNode(true) : document.importNode(this.template.element.content, true);
746
- var parts = this.template.parts;
747
- var partIndex = 0;
748
- var nodeIndex = 0;
749
- var _prepareInstance = function _prepareInstance(fragment) {
750
- // Edge needs all 4 parameters present; IE11 needs 3rd parameter to be
751
- // null
752
- var walker = document.createTreeWalker(fragment, 133 /* NodeFilter.SHOW_{ELEMENT|COMMENT|TEXT} */, null, false);
753
- var node = walker.nextNode();
754
- // Loop through all the nodes and parts of a template
755
- while (partIndex < parts.length && node !== null) {
756
- var part = parts[partIndex];
757
- // Consecutive Parts may have the same node index, in the case of
758
- // multiple bound attributes on an element. So each iteration we either
759
- // increment the nodeIndex, if we aren't on a node with a part, or the
760
- // partIndex if we are. By not incrementing the nodeIndex when we find a
761
- // part, we allow for the next part to be associated with the current
762
- // node if neccessasry.
763
- if (!isTemplatePartActive(part)) {
764
- _this._parts.push(undefined);
765
- partIndex++;
766
- } else if (nodeIndex === part.index) {
767
- if (part.type === 'node') {
768
- var _part2 = _this.processor.handleTextExpression(_this.options);
769
- _part2.insertAfterNode(node.previousSibling);
770
- _this._parts.push(_part2);
771
- } else {
772
- var _parts;
773
-
774
- (_parts = _this._parts).push.apply(_parts, toConsumableArray(_this.processor.handleAttributeExpressions(node, part.name, part.strings, _this.options)));
775
- }
776
- partIndex++;
777
- } else {
778
- nodeIndex++;
779
- if (node.nodeName === 'TEMPLATE') {
780
- _prepareInstance(node.content);
781
- }
782
- node = walker.nextNode();
783
- }
784
- }
785
- };
786
- _prepareInstance(fragment);
787
- if (isCEPolyfill) {
788
- document.adoptNode(fragment);
789
- customElements.upgrade(fragment);
790
- }
791
- return fragment;
792
- }
793
- }]);
794
- return TemplateInstance;
795
- }();
796
-
797
- /**
798
- * @license
799
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
800
- * This code may only be used under the BSD style license found at
801
- * http://polymer.github.io/LICENSE.txt
802
- * The complete set of authors may be found at
803
- * http://polymer.github.io/AUTHORS.txt
804
- * The complete set of contributors may be found at
805
- * http://polymer.github.io/CONTRIBUTORS.txt
806
- * Code distributed by Google as part of the polymer project is also
807
- * subject to an additional IP rights grant found at
808
- * http://polymer.github.io/PATENTS.txt
809
- */
810
- /**
811
- * @module lit-html
812
- */
813
- /**
814
- * The return type of `html`, which holds a Template and the values from
815
- * interpolated expressions.
816
- */
817
- var TemplateResult = function () {
818
- function TemplateResult(strings, values, type, processor) {
819
- classCallCheck(this, TemplateResult);
820
-
821
- this.strings = strings;
822
- this.values = values;
823
- this.type = type;
824
- this.processor = processor;
825
- }
826
- /**
827
- * Returns a string of HTML used to create a `<template>` element.
828
- */
829
-
830
- createClass(TemplateResult, [{
831
- key: 'getHTML',
832
- value: function getHTML() {
833
- var endIndex = this.strings.length - 1;
834
- var html = '';
835
- for (var i = 0; i < endIndex; i++) {
836
- var s = this.strings[i];
837
- // This exec() call does two things:
838
- // 1) Appends a suffix to the bound attribute name to opt out of special
839
- // attribute value parsing that IE11 and Edge do, like for style and
840
- // many SVG attributes. The Template class also appends the same suffix
841
- // when looking up attributes to create Parts.
842
- // 2) Adds an unquoted-attribute-safe marker for the first expression in
843
- // an attribute. Subsequent attribute expressions will use node markers,
844
- // and this is safe since attributes with multiple expressions are
845
- // guaranteed to be quoted.
846
- var match = lastAttributeNameRegex.exec(s);
847
- if (match) {
848
- // We're starting a new bound attribute.
849
- // Add the safe attribute suffix, and use unquoted-attribute-safe
850
- // marker.
851
- html += s.substr(0, match.index) + match[1] + match[2] + boundAttributeSuffix + match[3] + marker;
852
- } else {
853
- // We're either in a bound node, or trailing bound attribute.
854
- // Either way, nodeMarker is safe to use.
855
- html += s + nodeMarker;
856
- }
857
- }
858
- return html + this.strings[endIndex];
859
- }
860
- }, {
861
- key: 'getTemplateElement',
862
- value: function getTemplateElement() {
863
- var template = document.createElement('template');
864
- template.innerHTML = this.getHTML();
865
- return template;
866
- }
867
- }]);
868
- return TemplateResult;
869
- }();
870
- /**
871
- * A TemplateResult for SVG fragments.
872
- *
873
- * This class wraps HTMl in an `<svg>` tag in order to parse its contents in the
874
- * SVG namespace, then modifies the template to remove the `<svg>` tag so that
875
- * clones only container the original fragment.
876
- */
877
- var SVGTemplateResult = function (_TemplateResult) {
878
- inherits(SVGTemplateResult, _TemplateResult);
879
-
880
- function SVGTemplateResult() {
881
- classCallCheck(this, SVGTemplateResult);
882
- return possibleConstructorReturn(this, (SVGTemplateResult.__proto__ || Object.getPrototypeOf(SVGTemplateResult)).apply(this, arguments));
883
- }
884
-
885
- createClass(SVGTemplateResult, [{
886
- key: 'getHTML',
887
- value: function getHTML() {
888
- return '<svg>' + get(SVGTemplateResult.prototype.__proto__ || Object.getPrototypeOf(SVGTemplateResult.prototype), 'getHTML', this).call(this) + '</svg>';
889
- }
890
- }, {
891
- key: 'getTemplateElement',
892
- value: function getTemplateElement() {
893
- var template = get(SVGTemplateResult.prototype.__proto__ || Object.getPrototypeOf(SVGTemplateResult.prototype), 'getTemplateElement', this).call(this);
894
- var content = template.content;
895
- var svgElement = content.firstChild;
896
- content.removeChild(svgElement);
897
- reparentNodes(content, svgElement.firstChild);
898
- return template;
899
- }
900
- }]);
901
- return SVGTemplateResult;
902
- }(TemplateResult);
903
-
904
- /**
905
- * @license
906
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
907
- * This code may only be used under the BSD style license found at
908
- * http://polymer.github.io/LICENSE.txt
909
- * The complete set of authors may be found at
910
- * http://polymer.github.io/AUTHORS.txt
911
- * The complete set of contributors may be found at
912
- * http://polymer.github.io/CONTRIBUTORS.txt
913
- * Code distributed by Google as part of the polymer project is also
914
- * subject to an additional IP rights grant found at
915
- * http://polymer.github.io/PATENTS.txt
916
- */
917
- /**
918
- * @module lit-html
919
- */
920
- var isPrimitive = function isPrimitive(value) {
921
- return value === null || !((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' || typeof value === 'function');
922
- };
923
- /**
924
- * Sets attribute values for AttributeParts, so that the value is only set once
925
- * even if there are multiple parts for an attribute.
926
- */
927
- var AttributeCommitter = function () {
928
- function AttributeCommitter(element, name, strings) {
929
- classCallCheck(this, AttributeCommitter);
930
-
931
- this.dirty = true;
932
- this.element = element;
933
- this.name = name;
934
- this.strings = strings;
935
- this.parts = [];
936
- for (var i = 0; i < strings.length - 1; i++) {
937
- this.parts[i] = this._createPart();
938
- }
939
- }
940
- /**
941
- * Creates a single part. Override this to create a differnt type of part.
942
- */
943
-
944
- createClass(AttributeCommitter, [{
945
- key: '_createPart',
946
- value: function _createPart() {
947
- return new AttributePart(this);
948
- }
949
- }, {
950
- key: '_getValue',
951
- value: function _getValue() {
952
- var strings = this.strings;
953
- var l = strings.length - 1;
954
- var text = '';
955
- for (var i = 0; i < l; i++) {
956
- text += strings[i];
957
- var part = this.parts[i];
958
- if (part !== undefined) {
959
- var v = part.value;
960
- if (v != null && (Array.isArray(v) ||
961
- // tslint:disable-next-line:no-any
962
- typeof v !== 'string' && v[Symbol.iterator])) {
963
- var _iteratorNormalCompletion = true;
964
- var _didIteratorError = false;
965
- var _iteratorError = undefined;
966
-
967
- try {
968
- for (var _iterator = v[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
969
- var t = _step.value;
970
-
971
- text += typeof t === 'string' ? t : String(t);
972
- }
973
- } catch (err) {
974
- _didIteratorError = true;
975
- _iteratorError = err;
976
- } finally {
977
- try {
978
- if (!_iteratorNormalCompletion && _iterator.return) {
979
- _iterator.return();
980
- }
981
- } finally {
982
- if (_didIteratorError) {
983
- throw _iteratorError;
984
- }
985
- }
986
- }
987
- } else {
988
- text += typeof v === 'string' ? v : String(v);
989
- }
990
- }
991
- }
992
- text += strings[l];
993
- return text;
994
- }
995
- }, {
996
- key: 'commit',
997
- value: function commit() {
998
- if (this.dirty) {
999
- this.dirty = false;
1000
- this.element.setAttribute(this.name, this._getValue());
1001
- }
1002
- }
1003
- }]);
1004
- return AttributeCommitter;
1005
- }();
1006
- var AttributePart = function () {
1007
- function AttributePart(comitter) {
1008
- classCallCheck(this, AttributePart);
1009
-
1010
- this.value = undefined;
1011
- this.committer = comitter;
1012
- }
1013
-
1014
- createClass(AttributePart, [{
1015
- key: 'setValue',
1016
- value: function setValue(value) {
1017
- if (value !== noChange && (!isPrimitive(value) || value !== this.value)) {
1018
- this.value = value;
1019
- // If the value is a not a directive, dirty the committer so that it'll
1020
- // call setAttribute. If the value is a directive, it'll dirty the
1021
- // committer if it calls setValue().
1022
- if (!isDirective(value)) {
1023
- this.committer.dirty = true;
1024
- }
1025
- }
1026
- }
1027
- }, {
1028
- key: 'commit',
1029
- value: function commit() {
1030
- while (isDirective(this.value)) {
1031
- var directive$$1 = this.value;
1032
- this.value = noChange;
1033
- directive$$1(this);
1034
- }
1035
- if (this.value === noChange) {
1036
- return;
1037
- }
1038
- this.committer.commit();
1039
- }
1040
- }]);
1041
- return AttributePart;
1042
- }();
1043
- var NodePart = function () {
1044
- function NodePart(options) {
1045
- classCallCheck(this, NodePart);
1046
-
1047
- this.value = undefined;
1048
- this._pendingValue = undefined;
1049
- this.options = options;
1050
- }
1051
- /**
1052
- * Inserts this part into a container.
1053
- *
1054
- * This part must be empty, as its contents are not automatically moved.
1055
- */
1056
-
1057
- createClass(NodePart, [{
1058
- key: 'appendInto',
1059
- value: function appendInto(container) {
1060
- this.startNode = container.appendChild(createMarker());
1061
- this.endNode = container.appendChild(createMarker());
1062
- }
1063
- /**
1064
- * Inserts this part between `ref` and `ref`'s next sibling. Both `ref` and
1065
- * its next sibling must be static, unchanging nodes such as those that appear
1066
- * in a literal section of a template.
1067
- *
1068
- * This part must be empty, as its contents are not automatically moved.
1069
- */
1070
-
1071
- }, {
1072
- key: 'insertAfterNode',
1073
- value: function insertAfterNode(ref) {
1074
- this.startNode = ref;
1075
- this.endNode = ref.nextSibling;
1076
- }
1077
- /**
1078
- * Appends this part into a parent part.
1079
- *
1080
- * This part must be empty, as its contents are not automatically moved.
1081
- */
1082
-
1083
- }, {
1084
- key: 'appendIntoPart',
1085
- value: function appendIntoPart(part) {
1086
- part._insert(this.startNode = createMarker());
1087
- part._insert(this.endNode = createMarker());
1088
- }
1089
- /**
1090
- * Appends this part after `ref`
1091
- *
1092
- * This part must be empty, as its contents are not automatically moved.
1093
- */
1094
-
1095
- }, {
1096
- key: 'insertAfterPart',
1097
- value: function insertAfterPart(ref) {
1098
- ref._insert(this.startNode = createMarker());
1099
- this.endNode = ref.endNode;
1100
- ref.endNode = this.startNode;
1101
- }
1102
- }, {
1103
- key: 'setValue',
1104
- value: function setValue(value) {
1105
- this._pendingValue = value;
1106
- }
1107
- }, {
1108
- key: 'commit',
1109
- value: function commit() {
1110
- while (isDirective(this._pendingValue)) {
1111
- var directive$$1 = this._pendingValue;
1112
- this._pendingValue = noChange;
1113
- directive$$1(this);
1114
- }
1115
- var value = this._pendingValue;
1116
- if (value === noChange) {
1117
- return;
1118
- }
1119
- if (isPrimitive(value)) {
1120
- if (value !== this.value) {
1121
- this._commitText(value);
1122
- }
1123
- } else if (value instanceof TemplateResult) {
1124
- this._commitTemplateResult(value);
1125
- } else if (value instanceof Node) {
1126
- this._commitNode(value);
1127
- } else if (Array.isArray(value) ||
1128
- // tslint:disable-next-line:no-any
1129
- value[Symbol.iterator]) {
1130
- this._commitIterable(value);
1131
- } else if (value === nothing) {
1132
- this.value = nothing;
1133
- this.clear();
1134
- } else {
1135
- // Fallback, will render the string representation
1136
- this._commitText(value);
1137
- }
1138
- }
1139
- }, {
1140
- key: '_insert',
1141
- value: function _insert(node) {
1142
- this.endNode.parentNode.insertBefore(node, this.endNode);
1143
- }
1144
- }, {
1145
- key: '_commitNode',
1146
- value: function _commitNode(value) {
1147
- if (this.value === value) {
1148
- return;
1149
- }
1150
- this.clear();
1151
- this._insert(value);
1152
- this.value = value;
1153
- }
1154
- }, {
1155
- key: '_commitText',
1156
- value: function _commitText(value) {
1157
- var node = this.startNode.nextSibling;
1158
- value = value == null ? '' : value;
1159
- if (node === this.endNode.previousSibling && node.nodeType === 3 /* Node.TEXT_NODE */) {
1160
- // If we only have a single text node between the markers, we can just
1161
- // set its value, rather than replacing it.
1162
- // TODO(justinfagnani): Can we just check if this.value is primitive?
1163
- node.data = value;
1164
- } else {
1165
- this._commitNode(document.createTextNode(typeof value === 'string' ? value : String(value)));
1166
- }
1167
- this.value = value;
1168
- }
1169
- }, {
1170
- key: '_commitTemplateResult',
1171
- value: function _commitTemplateResult(value) {
1172
- var template = this.options.templateFactory(value);
1173
- if (this.value instanceof TemplateInstance && this.value.template === template) {
1174
- this.value.update(value.values);
1175
- } else {
1176
- // Make sure we propagate the template processor from the TemplateResult
1177
- // so that we use its syntax extension, etc. The template factory comes
1178
- // from the render function options so that it can control template
1179
- // caching and preprocessing.
1180
- var instance = new TemplateInstance(template, value.processor, this.options);
1181
- var fragment = instance._clone();
1182
- instance.update(value.values);
1183
- this._commitNode(fragment);
1184
- this.value = instance;
1185
- }
1186
- }
1187
- }, {
1188
- key: '_commitIterable',
1189
- value: function _commitIterable(value) {
1190
- // For an Iterable, we create a new InstancePart per item, then set its
1191
- // value to the item. This is a little bit of overhead for every item in
1192
- // an Iterable, but it lets us recurse easily and efficiently update Arrays
1193
- // of TemplateResults that will be commonly returned from expressions like:
1194
- // array.map((i) => html`${i}`), by reusing existing TemplateInstances.
1195
- // If _value is an array, then the previous render was of an
1196
- // iterable and _value will contain the NodeParts from the previous
1197
- // render. If _value is not an array, clear this part and make a new
1198
- // array for NodeParts.
1199
- if (!Array.isArray(this.value)) {
1200
- this.value = [];
1201
- this.clear();
1202
- }
1203
- // Lets us keep track of how many items we stamped so we can clear leftover
1204
- // items from a previous render
1205
- var itemParts = this.value;
1206
- var partIndex = 0;
1207
- var itemPart = void 0;
1208
- var _iteratorNormalCompletion2 = true;
1209
- var _didIteratorError2 = false;
1210
- var _iteratorError2 = undefined;
1211
-
1212
- try {
1213
- for (var _iterator2 = value[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
1214
- var item = _step2.value;
1215
-
1216
- // Try to reuse an existing part
1217
- itemPart = itemParts[partIndex];
1218
- // If no existing part, create a new one
1219
- if (itemPart === undefined) {
1220
- itemPart = new NodePart(this.options);
1221
- itemParts.push(itemPart);
1222
- if (partIndex === 0) {
1223
- itemPart.appendIntoPart(this);
1224
- } else {
1225
- itemPart.insertAfterPart(itemParts[partIndex - 1]);
1226
- }
1227
- }
1228
- itemPart.setValue(item);
1229
- itemPart.commit();
1230
- partIndex++;
1231
- }
1232
- } catch (err) {
1233
- _didIteratorError2 = true;
1234
- _iteratorError2 = err;
1235
- } finally {
1236
- try {
1237
- if (!_iteratorNormalCompletion2 && _iterator2.return) {
1238
- _iterator2.return();
1239
- }
1240
- } finally {
1241
- if (_didIteratorError2) {
1242
- throw _iteratorError2;
1243
- }
1244
- }
1245
- }
1246
-
1247
- if (partIndex < itemParts.length) {
1248
- // Truncate the parts array so _value reflects the current state
1249
- itemParts.length = partIndex;
1250
- this.clear(itemPart && itemPart.endNode);
1251
- }
1252
- }
1253
- }, {
1254
- key: 'clear',
1255
- value: function clear() {
1256
- var startNode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.startNode;
1257
-
1258
- removeNodes(this.startNode.parentNode, startNode.nextSibling, this.endNode);
1259
- }
1260
- }]);
1261
- return NodePart;
1262
- }();
1263
- /**
1264
- * Implements a boolean attribute, roughly as defined in the HTML
1265
- * specification.
1266
- *
1267
- * If the value is truthy, then the attribute is present with a value of
1268
- * ''. If the value is falsey, the attribute is removed.
1269
- */
1270
- var BooleanAttributePart = function () {
1271
- function BooleanAttributePart(element, name, strings) {
1272
- classCallCheck(this, BooleanAttributePart);
1273
-
1274
- this.value = undefined;
1275
- this._pendingValue = undefined;
1276
- if (strings.length !== 2 || strings[0] !== '' || strings[1] !== '') {
1277
- throw new Error('Boolean attributes can only contain a single expression');
1278
- }
1279
- this.element = element;
1280
- this.name = name;
1281
- this.strings = strings;
1282
- }
1283
-
1284
- createClass(BooleanAttributePart, [{
1285
- key: 'setValue',
1286
- value: function setValue(value) {
1287
- this._pendingValue = value;
1288
- }
1289
- }, {
1290
- key: 'commit',
1291
- value: function commit() {
1292
- while (isDirective(this._pendingValue)) {
1293
- var directive$$1 = this._pendingValue;
1294
- this._pendingValue = noChange;
1295
- directive$$1(this);
1296
- }
1297
- if (this._pendingValue === noChange) {
1298
- return;
1299
- }
1300
- var value = !!this._pendingValue;
1301
- if (this.value !== value) {
1302
- if (value) {
1303
- this.element.setAttribute(this.name, '');
1304
- } else {
1305
- this.element.removeAttribute(this.name);
1306
- }
1307
- }
1308
- this.value = value;
1309
- this._pendingValue = noChange;
1310
- }
1311
- }]);
1312
- return BooleanAttributePart;
1313
- }();
1314
- /**
1315
- * Sets attribute values for PropertyParts, so that the value is only set once
1316
- * even if there are multiple parts for a property.
1317
- *
1318
- * If an expression controls the whole property value, then the value is simply
1319
- * assigned to the property under control. If there are string literals or
1320
- * multiple expressions, then the strings are expressions are interpolated into
1321
- * a string first.
1322
- */
1323
- var PropertyCommitter = function (_AttributeCommitter) {
1324
- inherits(PropertyCommitter, _AttributeCommitter);
1325
-
1326
- function PropertyCommitter(element, name, strings) {
1327
- classCallCheck(this, PropertyCommitter);
1328
-
1329
- var _this = possibleConstructorReturn(this, (PropertyCommitter.__proto__ || Object.getPrototypeOf(PropertyCommitter)).call(this, element, name, strings));
1330
-
1331
- _this.single = strings.length === 2 && strings[0] === '' && strings[1] === '';
1332
- return _this;
1333
- }
1334
-
1335
- createClass(PropertyCommitter, [{
1336
- key: '_createPart',
1337
- value: function _createPart() {
1338
- return new PropertyPart(this);
1339
- }
1340
- }, {
1341
- key: '_getValue',
1342
- value: function _getValue() {
1343
- if (this.single) {
1344
- return this.parts[0].value;
1345
- }
1346
- return get(PropertyCommitter.prototype.__proto__ || Object.getPrototypeOf(PropertyCommitter.prototype), '_getValue', this).call(this);
1347
- }
1348
- }, {
1349
- key: 'commit',
1350
- value: function commit() {
1351
- if (this.dirty) {
1352
- this.dirty = false;
1353
- // tslint:disable-next-line:no-any
1354
- this.element[this.name] = this._getValue();
1355
- }
1356
- }
1357
- }]);
1358
- return PropertyCommitter;
1359
- }(AttributeCommitter);
1360
- var PropertyPart = function (_AttributePart) {
1361
- inherits(PropertyPart, _AttributePart);
1362
-
1363
- function PropertyPart() {
1364
- classCallCheck(this, PropertyPart);
1365
- return possibleConstructorReturn(this, (PropertyPart.__proto__ || Object.getPrototypeOf(PropertyPart)).apply(this, arguments));
1366
- }
1367
-
1368
- return PropertyPart;
1369
- }(AttributePart);
1370
- // Detect event listener options support. If the `capture` property is read
1371
- // from the options object, then options are supported. If not, then the thrid
1372
- // argument to add/removeEventListener is interpreted as the boolean capture
1373
- // value so we should only pass the `capture` property.
1374
- var eventOptionsSupported = false;
1375
- try {
1376
- var options = {
1377
- get capture() {
1378
- eventOptionsSupported = true;
1379
- return false;
1380
- }
1381
- };
1382
- // tslint:disable-next-line:no-any
1383
- window.addEventListener('test', options, options);
1384
- // tslint:disable-next-line:no-any
1385
- window.removeEventListener('test', options, options);
1386
- } catch (_e) {}
1387
- var EventPart = function () {
1388
- function EventPart(element, eventName, eventContext) {
1389
- var _this3 = this;
1390
-
1391
- classCallCheck(this, EventPart);
1392
-
1393
- this.value = undefined;
1394
- this._pendingValue = undefined;
1395
- this.element = element;
1396
- this.eventName = eventName;
1397
- this.eventContext = eventContext;
1398
- this._boundHandleEvent = function (e) {
1399
- return _this3.handleEvent(e);
1400
- };
1401
- }
1402
-
1403
- createClass(EventPart, [{
1404
- key: 'setValue',
1405
- value: function setValue(value) {
1406
- this._pendingValue = value;
1407
- }
1408
- }, {
1409
- key: 'commit',
1410
- value: function commit() {
1411
- while (isDirective(this._pendingValue)) {
1412
- var directive$$1 = this._pendingValue;
1413
- this._pendingValue = noChange;
1414
- directive$$1(this);
1415
- }
1416
- if (this._pendingValue === noChange) {
1417
- return;
1418
- }
1419
- var newListener = this._pendingValue;
1420
- var oldListener = this.value;
1421
- var shouldRemoveListener = newListener == null || oldListener != null && (newListener.capture !== oldListener.capture || newListener.once !== oldListener.once || newListener.passive !== oldListener.passive);
1422
- var shouldAddListener = newListener != null && (oldListener == null || shouldRemoveListener);
1423
- if (shouldRemoveListener) {
1424
- this.element.removeEventListener(this.eventName, this._boundHandleEvent, this._options);
1425
- }
1426
- if (shouldAddListener) {
1427
- this._options = getOptions(newListener);
1428
- this.element.addEventListener(this.eventName, this._boundHandleEvent, this._options);
1429
- }
1430
- this.value = newListener;
1431
- this._pendingValue = noChange;
1432
- }
1433
- }, {
1434
- key: 'handleEvent',
1435
- value: function handleEvent(event) {
1436
- if (typeof this.value === 'function') {
1437
- this.value.call(this.eventContext || this.element, event);
1438
- } else {
1439
- this.value.handleEvent(event);
1440
- }
1441
- }
1442
- }]);
1443
- return EventPart;
1444
- }();
1445
- // We copy options because of the inconsistent behavior of browsers when reading
1446
- // the third argument of add/removeEventListener. IE11 doesn't support options
1447
- // at all. Chrome 41 only reads `capture` if the argument is an object.
1448
- var getOptions = function getOptions(o) {
1449
- return o && (eventOptionsSupported ? { capture: o.capture, passive: o.passive, once: o.once } : o.capture);
1450
- };
1451
-
1452
- /**
1453
- * @license
1454
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1455
- * This code may only be used under the BSD style license found at
1456
- * http://polymer.github.io/LICENSE.txt
1457
- * The complete set of authors may be found at
1458
- * http://polymer.github.io/AUTHORS.txt
1459
- * The complete set of contributors may be found at
1460
- * http://polymer.github.io/CONTRIBUTORS.txt
1461
- * Code distributed by Google as part of the polymer project is also
1462
- * subject to an additional IP rights grant found at
1463
- * http://polymer.github.io/PATENTS.txt
1464
- */
1465
- /**
1466
- * The default TemplateFactory which caches Templates keyed on
1467
- * result.type and result.strings.
1468
- */
1469
- function templateFactory(result) {
1470
- var templateCache = templateCaches.get(result.type);
1471
- if (templateCache === undefined) {
1472
- templateCache = {
1473
- stringsArray: new WeakMap(),
1474
- keyString: new Map()
1475
- };
1476
- templateCaches.set(result.type, templateCache);
1477
- }
1478
- var template = templateCache.stringsArray.get(result.strings);
1479
- if (template !== undefined) {
1480
- return template;
1481
- }
1482
- // If the TemplateStringsArray is new, generate a key from the strings
1483
- // This key is shared between all templates with identical content
1484
- var key = result.strings.join(marker);
1485
- // Check if we already have a Template for this key
1486
- template = templateCache.keyString.get(key);
1487
- if (template === undefined) {
1488
- // If we have not seen this key before, create a new Template
1489
- template = new Template(result, result.getTemplateElement());
1490
- // Cache the Template for this key
1491
- templateCache.keyString.set(key, template);
1492
- }
1493
- // Cache all future queries for this TemplateStringsArray
1494
- templateCache.stringsArray.set(result.strings, template);
1495
- return template;
1496
- }
1497
- var templateCaches = new Map();
1498
-
1499
- /**
1500
- * @license
1501
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1502
- * This code may only be used under the BSD style license found at
1503
- * http://polymer.github.io/LICENSE.txt
1504
- * The complete set of authors may be found at
1505
- * http://polymer.github.io/AUTHORS.txt
1506
- * The complete set of contributors may be found at
1507
- * http://polymer.github.io/CONTRIBUTORS.txt
1508
- * Code distributed by Google as part of the polymer project is also
1509
- * subject to an additional IP rights grant found at
1510
- * http://polymer.github.io/PATENTS.txt
1511
- */
1512
- /**
1513
- * @module lit-html
1514
- */
1515
- var parts = new WeakMap();
1516
- /**
1517
- * Renders a template to a container.
1518
- *
1519
- * To update a container with new values, reevaluate the template literal and
1520
- * call `render` with the new result.
1521
- *
1522
- * @param result a TemplateResult created by evaluating a template tag like
1523
- * `html` or `svg`.
1524
- * @param container A DOM parent to render to. The entire contents are either
1525
- * replaced, or efficiently updated if the same result type was previous
1526
- * rendered there.
1527
- * @param options RenderOptions for the entire render tree rendered to this
1528
- * container. Render options must *not* change between renders to the same
1529
- * container, as those changes will not effect previously rendered DOM.
1530
- */
1531
- var render = function render(result, container, options) {
1532
- var part = parts.get(container);
1533
- if (part === undefined) {
1534
- removeNodes(container, container.firstChild);
1535
- parts.set(container, part = new NodePart(Object.assign({ templateFactory: templateFactory }, options)));
1536
- part.appendInto(container);
1537
- }
1538
- part.setValue(result);
1539
- part.commit();
1540
- };
1541
-
1542
- /**
1543
- * @license
1544
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1545
- * This code may only be used under the BSD style license found at
1546
- * http://polymer.github.io/LICENSE.txt
1547
- * The complete set of authors may be found at
1548
- * http://polymer.github.io/AUTHORS.txt
1549
- * The complete set of contributors may be found at
1550
- * http://polymer.github.io/CONTRIBUTORS.txt
1551
- * Code distributed by Google as part of the polymer project is also
1552
- * subject to an additional IP rights grant found at
1553
- * http://polymer.github.io/PATENTS.txt
1554
- */
1555
- /**
1556
- * Creates Parts when a template is instantiated.
1557
- */
1558
- var DefaultTemplateProcessor = function () {
1559
- function DefaultTemplateProcessor() {
1560
- classCallCheck(this, DefaultTemplateProcessor);
1561
- }
1562
-
1563
- createClass(DefaultTemplateProcessor, [{
1564
- key: 'handleAttributeExpressions',
1565
-
1566
- /**
1567
- * Create parts for an attribute-position binding, given the event, attribute
1568
- * name, and string literals.
1569
- *
1570
- * @param element The element containing the binding
1571
- * @param name The attribute name
1572
- * @param strings The string literals. There are always at least two strings,
1573
- * event for fully-controlled bindings with a single expression.
1574
- */
1575
- value: function handleAttributeExpressions(element, name, strings, options) {
1576
- var prefix = name[0];
1577
- if (prefix === '.') {
1578
- var _comitter = new PropertyCommitter(element, name.slice(1), strings);
1579
- return _comitter.parts;
1580
- }
1581
- if (prefix === '@') {
1582
- return [new EventPart(element, name.slice(1), options.eventContext)];
1583
- }
1584
- if (prefix === '?') {
1585
- return [new BooleanAttributePart(element, name.slice(1), strings)];
1586
- }
1587
- var comitter = new AttributeCommitter(element, name, strings);
1588
- return comitter.parts;
1589
- }
1590
- /**
1591
- * Create parts for a text-position binding.
1592
- * @param templateFactory
1593
- */
1594
-
1595
- }, {
1596
- key: 'handleTextExpression',
1597
- value: function handleTextExpression(options) {
1598
- return new NodePart(options);
1599
- }
1600
- }]);
1601
- return DefaultTemplateProcessor;
1602
- }();
1603
- var defaultTemplateProcessor = new DefaultTemplateProcessor();
1604
-
1605
- /**
1606
- * @license
1607
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1608
- * This code may only be used under the BSD style license found at
1609
- * http://polymer.github.io/LICENSE.txt
1610
- * The complete set of authors may be found at
1611
- * http://polymer.github.io/AUTHORS.txt
1612
- * The complete set of contributors may be found at
1613
- * http://polymer.github.io/CONTRIBUTORS.txt
1614
- * Code distributed by Google as part of the polymer project is also
1615
- * subject to an additional IP rights grant found at
1616
- * http://polymer.github.io/PATENTS.txt
1617
- */
1618
- /**
1619
- *
1620
- * Main lit-html module.
1621
- *
1622
- * Main exports:
1623
- *
1624
- * - [[html]]
1625
- * - [[svg]]
1626
- * - [[render]]
1627
- *
1628
- * @module lit-html
1629
- * @preferred
1630
- */
1631
- /**
1632
- * Do not remove this comment; it keeps typedoc from misplacing the module
1633
- * docs.
1634
- */
1635
- // IMPORTANT: do not change the property name or the assignment expression.
1636
- // This line will be used in regexes to search for lit-html usage.
1637
- // TODO(justinfagnani): inject version number at build time
1638
- (window['litHtmlVersions'] || (window['litHtmlVersions'] = [])).push('1.0.0');
1639
- /**
1640
- * Interprets a template literal as an HTML template that can efficiently
1641
- * render to and update a container.
1642
- */
1643
- var html = function html(strings) {
1644
- for (var _len = arguments.length, values = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1645
- values[_key - 1] = arguments[_key];
1646
- }
1647
-
1648
- return new TemplateResult(strings, values, 'html', defaultTemplateProcessor);
1649
- };
1650
- /**
1651
- * Interprets a template literal as an SVG template that can efficiently
1652
- * render to and update a container.
1653
- */
1654
-
1655
- /**
1656
- * @license
1657
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1658
- * This code may only be used under the BSD style license found at
1659
- * http://polymer.github.io/LICENSE.txt
1660
- * The complete set of authors may be found at
1661
- * http://polymer.github.io/AUTHORS.txt
1662
- * The complete set of contributors may be found at
1663
- * http://polymer.github.io/CONTRIBUTORS.txt
1664
- * Code distributed by Google as part of the polymer project is also
1665
- * subject to an additional IP rights grant found at
1666
- * http://polymer.github.io/PATENTS.txt
1667
- */
1668
- /**
1669
- * Module to add shady DOM/shady CSS polyfill support to lit-html template
1670
- * rendering. See the [[render]] method for details.
1671
- *
1672
- * @module shady-render
1673
- * @preferred
1674
- */
1675
- /**
1676
- * Do not remove this comment; it keeps typedoc from misplacing the module
1677
- * docs.
1678
- */
1679
- // Get a key to lookup in `templateCaches`.
1680
- var getTemplateCacheKey = function getTemplateCacheKey(type, scopeName) {
1681
- return type + '--' + scopeName;
1682
- };
1683
- var compatibleShadyCSSVersion = true;
1684
- if (typeof window.ShadyCSS === 'undefined') {
1685
- compatibleShadyCSSVersion = false;
1686
- } else if (typeof window.ShadyCSS.prepareTemplateDom === 'undefined') {
1687
- console.warn('Incompatible ShadyCSS version detected.' + 'Please update to at least @webcomponents/webcomponentsjs@2.0.2 and' + '@webcomponents/shadycss@1.3.1.');
1688
- compatibleShadyCSSVersion = false;
1689
- }
1690
- /**
1691
- * Template factory which scopes template DOM using ShadyCSS.
1692
- * @param scopeName {string}
1693
- */
1694
- var shadyTemplateFactory = function shadyTemplateFactory(scopeName) {
1695
- return function (result) {
1696
- var cacheKey = getTemplateCacheKey(result.type, scopeName);
1697
- var templateCache = templateCaches.get(cacheKey);
1698
- if (templateCache === undefined) {
1699
- templateCache = {
1700
- stringsArray: new WeakMap(),
1701
- keyString: new Map()
1702
- };
1703
- templateCaches.set(cacheKey, templateCache);
1704
- }
1705
- var template = templateCache.stringsArray.get(result.strings);
1706
- if (template !== undefined) {
1707
- return template;
1708
- }
1709
- var key = result.strings.join(marker);
1710
- template = templateCache.keyString.get(key);
1711
- if (template === undefined) {
1712
- var element = result.getTemplateElement();
1713
- if (compatibleShadyCSSVersion) {
1714
- window.ShadyCSS.prepareTemplateDom(element, scopeName);
1715
- }
1716
- template = new Template(result, element);
1717
- templateCache.keyString.set(key, template);
1718
- }
1719
- templateCache.stringsArray.set(result.strings, template);
1720
- return template;
1721
- };
1722
- };
1723
- var TEMPLATE_TYPES = ['html', 'svg'];
1724
- /**
1725
- * Removes all style elements from Templates for the given scopeName.
1726
- */
1727
- var removeStylesFromLitTemplates = function removeStylesFromLitTemplates(scopeName) {
1728
- TEMPLATE_TYPES.forEach(function (type) {
1729
- var templates = templateCaches.get(getTemplateCacheKey(type, scopeName));
1730
- if (templates !== undefined) {
1731
- templates.keyString.forEach(function (template) {
1732
- var content = template.element.content;
1733
- // IE 11 doesn't support the iterable param Set constructor
1734
-
1735
- var styles = new Set();
1736
- Array.from(content.querySelectorAll('style')).forEach(function (s) {
1737
- styles.add(s);
1738
- });
1739
- removeNodesFromTemplate(template, styles);
1740
- });
1741
- }
1742
- });
1743
- };
1744
- var shadyRenderSet = new Set();
1745
- /**
1746
- * For the given scope name, ensures that ShadyCSS style scoping is performed.
1747
- * This is done just once per scope name so the fragment and template cannot
1748
- * be modified.
1749
- * (1) extracts styles from the rendered fragment and hands them to ShadyCSS
1750
- * to be scoped and appended to the document
1751
- * (2) removes style elements from all lit-html Templates for this scope name.
1752
- *
1753
- * Note, <style> elements can only be placed into templates for the
1754
- * initial rendering of the scope. If <style> elements are included in templates
1755
- * dynamically rendered to the scope (after the first scope render), they will
1756
- * not be scoped and the <style> will be left in the template and rendered
1757
- * output.
1758
- */
1759
- var prepareTemplateStyles = function prepareTemplateStyles(renderedDOM, template, scopeName) {
1760
- shadyRenderSet.add(scopeName);
1761
- // Move styles out of rendered DOM and store.
1762
- var styles = renderedDOM.querySelectorAll('style');
1763
- // If there are no styles, skip unnecessary work
1764
- if (styles.length === 0) {
1765
- // Ensure prepareTemplateStyles is called to support adding
1766
- // styles via `prepareAdoptedCssText` since that requires that
1767
- // `prepareTemplateStyles` is called.
1768
- window.ShadyCSS.prepareTemplateStyles(template.element, scopeName);
1769
- return;
1770
- }
1771
- var condensedStyle = document.createElement('style');
1772
- // Collect styles into a single style. This helps us make sure ShadyCSS
1773
- // manipulations will not prevent us from being able to fix up template
1774
- // part indices.
1775
- // NOTE: collecting styles is inefficient for browsers but ShadyCSS
1776
- // currently does this anyway. When it does not, this should be changed.
1777
- for (var i = 0; i < styles.length; i++) {
1778
- var style = styles[i];
1779
- style.parentNode.removeChild(style);
1780
- condensedStyle.textContent += style.textContent;
1781
- }
1782
- // Remove styles from nested templates in this scope.
1783
- removeStylesFromLitTemplates(scopeName);
1784
- // And then put the condensed style into the "root" template passed in as
1785
- // `template`.
1786
- insertNodeIntoTemplate(template, condensedStyle, template.element.content.firstChild);
1787
- // Note, it's important that ShadyCSS gets the template that `lit-html`
1788
- // will actually render so that it can update the style inside when
1789
- // needed (e.g. @apply native Shadow DOM case).
1790
- window.ShadyCSS.prepareTemplateStyles(template.element, scopeName);
1791
- if (window.ShadyCSS.nativeShadow) {
1792
- // When in native Shadow DOM, re-add styling to rendered content using
1793
- // the style ShadyCSS produced.
1794
- var _style = template.element.content.querySelector('style');
1795
- renderedDOM.insertBefore(_style.cloneNode(true), renderedDOM.firstChild);
1796
- } else {
1797
- // When not in native Shadow DOM, at this point ShadyCSS will have
1798
- // removed the style from the lit template and parts will be broken as a
1799
- // result. To fix this, we put back the style node ShadyCSS removed
1800
- // and then tell lit to remove that node from the template.
1801
- // NOTE, ShadyCSS creates its own style so we can safely add/remove
1802
- // `condensedStyle` here.
1803
- template.element.content.insertBefore(condensedStyle, template.element.content.firstChild);
1804
- var removes = new Set();
1805
- removes.add(condensedStyle);
1806
- removeNodesFromTemplate(template, removes);
1807
- }
1808
- };
1809
- /**
1810
- * Extension to the standard `render` method which supports rendering
1811
- * to ShadowRoots when the ShadyDOM (https://github.com/webcomponents/shadydom)
1812
- * and ShadyCSS (https://github.com/webcomponents/shadycss) polyfills are used
1813
- * or when the webcomponentsjs
1814
- * (https://github.com/webcomponents/webcomponentsjs) polyfill is used.
1815
- *
1816
- * Adds a `scopeName` option which is used to scope element DOM and stylesheets
1817
- * when native ShadowDOM is unavailable. The `scopeName` will be added to
1818
- * the class attribute of all rendered DOM. In addition, any style elements will
1819
- * be automatically re-written with this `scopeName` selector and moved out
1820
- * of the rendered DOM and into the document `<head>`.
1821
- *
1822
- * It is common to use this render method in conjunction with a custom element
1823
- * which renders a shadowRoot. When this is done, typically the element's
1824
- * `localName` should be used as the `scopeName`.
1825
- *
1826
- * In addition to DOM scoping, ShadyCSS also supports a basic shim for css
1827
- * custom properties (needed only on older browsers like IE11) and a shim for
1828
- * a deprecated feature called `@apply` that supports applying a set of css
1829
- * custom properties to a given location.
1830
- *
1831
- * Usage considerations:
1832
- *
1833
- * * Part values in `<style>` elements are only applied the first time a given
1834
- * `scopeName` renders. Subsequent changes to parts in style elements will have
1835
- * no effect. Because of this, parts in style elements should only be used for
1836
- * values that will never change, for example parts that set scope-wide theme
1837
- * values or parts which render shared style elements.
1838
- *
1839
- * * Note, due to a limitation of the ShadyDOM polyfill, rendering in a
1840
- * custom element's `constructor` is not supported. Instead rendering should
1841
- * either done asynchronously, for example at microtask timing (for example
1842
- * `Promise.resolve()`), or be deferred until the first time the element's
1843
- * `connectedCallback` runs.
1844
- *
1845
- * Usage considerations when using shimmed custom properties or `@apply`:
1846
- *
1847
- * * Whenever any dynamic changes are made which affect
1848
- * css custom properties, `ShadyCSS.styleElement(element)` must be called
1849
- * to update the element. There are two cases when this is needed:
1850
- * (1) the element is connected to a new parent, (2) a class is added to the
1851
- * element that causes it to match different custom properties.
1852
- * To address the first case when rendering a custom element, `styleElement`
1853
- * should be called in the element's `connectedCallback`.
1854
- *
1855
- * * Shimmed custom properties may only be defined either for an entire
1856
- * shadowRoot (for example, in a `:host` rule) or via a rule that directly
1857
- * matches an element with a shadowRoot. In other words, instead of flowing from
1858
- * parent to child as do native css custom properties, shimmed custom properties
1859
- * flow only from shadowRoots to nested shadowRoots.
1860
- *
1861
- * * When using `@apply` mixing css shorthand property names with
1862
- * non-shorthand names (for example `border` and `border-width`) is not
1863
- * supported.
1864
- */
1865
- var render$1 = function render$$1(result, container, options) {
1866
- var scopeName = options.scopeName;
1867
- var hasRendered = parts.has(container);
1868
- var needsScoping = container instanceof ShadowRoot && compatibleShadyCSSVersion && result instanceof TemplateResult;
1869
- // Handle first render to a scope specially...
1870
- var firstScopeRender = needsScoping && !shadyRenderSet.has(scopeName);
1871
- // On first scope render, render into a fragment; this cannot be a single
1872
- // fragment that is reused since nested renders can occur synchronously.
1873
- var renderContainer = firstScopeRender ? document.createDocumentFragment() : container;
1874
- render(result, renderContainer, Object.assign({ templateFactory: shadyTemplateFactory(scopeName) }, options));
1875
- // When performing first scope render,
1876
- // (1) We've rendered into a fragment so that there's a chance to
1877
- // `prepareTemplateStyles` before sub-elements hit the DOM
1878
- // (which might cause them to render based on a common pattern of
1879
- // rendering in a custom element's `connectedCallback`);
1880
- // (2) Scope the template with ShadyCSS one time only for this scope.
1881
- // (3) Render the fragment into the container and make sure the
1882
- // container knows its `part` is the one we just rendered. This ensures
1883
- // DOM will be re-used on subsequent renders.
1884
- if (firstScopeRender) {
1885
- var part = parts.get(renderContainer);
1886
- parts.delete(renderContainer);
1887
- if (part.value instanceof TemplateInstance) {
1888
- prepareTemplateStyles(renderContainer, part.value.template, scopeName);
1889
- }
1890
- removeNodes(container, container.firstChild);
1891
- container.appendChild(renderContainer);
1892
- parts.set(container, part);
1893
- }
1894
- // After elements have hit the DOM, update styling if this is the
1895
- // initial render to this container.
1896
- // This is needed whenever dynamic changes are made so it would be
1897
- // safest to do every render; however, this would regress performance
1898
- // so we leave it up to the user to call `ShadyCSSS.styleElement`
1899
- // for dynamic changes.
1900
- if (!hasRendered && needsScoping) {
1901
- window.ShadyCSS.styleElement(container.host);
1902
- }
1903
- };
1904
-
1905
- // Key to store the HTML tag in a custom element class
1906
- var TAG = Symbol('tag');
1907
-
1908
- // Key to store render status in a custom element instance
1909
- var NEEDSRENDER = Symbol('needsRender');
1910
-
1911
- // Transforms a camelCased string into a kebab-cased string
1912
- var camelToKebab = function camelToKebab(camel) {
1913
- return camel.replace(/([a-z](?=[A-Z]))|([A-Z](?=[A-Z][a-z]))/g, '$1$2-').toLowerCase();
1914
- };
1915
-
1916
- // Creates an ID cache in the `$` property of a custom element instance
1917
- var createIdCache = function createIdCache(element) {
1918
- element.$ = {};
1919
- element.renderRoot.querySelectorAll('[id]').forEach(function (node) {
1920
- element.$[node.id] = node;
1921
- });
1922
- };
1923
-
1924
- /**
1925
- * A lightweight base class for custom elements
1926
- *
1927
- * Features:
1928
- *
1929
- * - Determines an appropriate HTML tagname based on an element's class name
1930
- * - Efficient rendering engine using lit-html (https://github.com/Polymer/lit-html)
1931
- * - Creates a cache for descendant nodes with an `id` in the `$` property
1932
- */
1933
- var GluonElement = function (_HTMLElement) {
1934
- inherits(GluonElement, _HTMLElement);
1935
-
1936
- function GluonElement() {
1937
- classCallCheck(this, GluonElement);
1938
-
1939
- var _this = possibleConstructorReturn(this, (GluonElement.__proto__ || Object.getPrototypeOf(GluonElement)).call(this));
1940
-
1941
- _this.renderRoot = _this.createRenderRoot();
1942
-
1943
- // This ensures that any properties that are set prior to upgrading this element
1944
- // have their instance setters called
1945
- Object.getOwnPropertyNames(_this).forEach(function (property) {
1946
- var propertyValue = _this[property];
1947
- delete _this[property];
1948
- _this[property] = propertyValue;
1949
- });
1950
- return _this;
1951
- }
1952
-
1953
- /**
1954
- * Returns an open shadowRoot as the default rendering root
1955
- *
1956
- * Override this method to provide an alternative rendering root
1957
- * For example, return `this` to render the template as childNodes
1958
- */
1959
-
1960
- createClass(GluonElement, [{
1961
- key: 'createRenderRoot',
1962
- value: function createRenderRoot() {
1963
- return this.attachShadow({ mode: 'open' });
1964
- }
1965
-
1966
- /**
1967
- * Returns the HTML tagname for elements of this class
1968
- *
1969
- * It defaults to the kebab-cased version of the class name. To override,
1970
- * defined a `static get is()` property on your custom element class, and return
1971
- * whatever string you want to use for the HTML tagname
1972
- */
1973
-
1974
- }, {
1975
- key: 'connectedCallback',
1976
-
1977
- /**
1978
- * Called when an element is connected to the DOM
1979
- *
1980
- * When an element has a `template`, attach a shadowRoot to the element,
1981
- * and render the template. Once the template is rendered, creates an ID cache
1982
- * in the `$` property
1983
- *
1984
- * When adding a `connectedCallback` to your custom element, you should call
1985
- * `super.connectedCallback()` before doing anything other than actions
1986
- * that alter the result of the template rendering.
1987
- */
1988
- value: function connectedCallback() {
1989
- if ('template' in this) {
1990
- this.render({ sync: true });
1991
- createIdCache(this);
1992
- }
1993
- }
1994
-
1995
- /**
1996
- * Renders the template for this element into the shadowRoot
1997
- *
1998
- * @param { sync }: perform a synchronous (blocking) render. The default render
1999
- * is asynchronous, and multiple calls to `render()` are batched by default
2000
- *
2001
- * @returns a Promise that resolves once template has been rendered
2002
- */
2003
-
2004
- }, {
2005
- key: 'render',
2006
- value: function () {
2007
- var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
2008
- var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
2009
- _ref2$sync = _ref2.sync,
2010
- sync = _ref2$sync === undefined ? false : _ref2$sync;
2011
-
2012
- return regeneratorRuntime.wrap(function _callee$(_context) {
2013
- while (1) {
2014
- switch (_context.prev = _context.next) {
2015
- case 0:
2016
- this[NEEDSRENDER] = true;
2017
-
2018
- if (sync) {
2019
- _context.next = 4;
2020
- break;
2021
- }
2022
-
2023
- _context.next = 4;
2024
- return 0;
2025
-
2026
- case 4:
2027
- if (this[NEEDSRENDER]) {
2028
- this[NEEDSRENDER] = false;
2029
- render$1(this.template, this.renderRoot, { scopeName: this.constructor.is, eventContext: this });
2030
- }
2031
-
2032
- case 5:
2033
- case 'end':
2034
- return _context.stop();
2035
- }
2036
- }
2037
- }, _callee, this);
2038
- }));
2039
-
2040
- function render$$1() {
2041
- return _ref.apply(this, arguments);
2042
- }
2043
-
2044
- return render$$1;
2045
- }()
2046
- }], [{
2047
- key: 'is',
2048
- get: function get$$1() {
2049
- return this.hasOwnProperty(TAG) && this[TAG] || (this[TAG] = camelToKebab(this.name));
2050
- }
2051
- }]);
2052
- return GluonElement;
2053
- }(HTMLElement);
2054
-
2055
- exports.GluonElement = GluonElement;
2056
- exports.html = html;
2057
-
2058
- return exports;
2059
-
2060
- }({}));
2061
- //# sourceMappingURL=gluon.es5.js.map