@webtides/element-js 0.7.3 → 1.0.0-alpha.1

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/dist/index.js CHANGED
@@ -1,10 +1,8 @@
1
1
  var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2
3
  var __publicField = (obj, key, value) => {
3
- if (typeof key !== "symbol")
4
- key += "";
5
- if (key in obj)
6
- return __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value});
7
- return obj[key] = value;
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
8
6
  };
9
7
 
10
8
  // src/util/AttributeParser.js
@@ -60,8 +58,23 @@ function dashToCamel(string) {
60
58
  function camelToDash(string) {
61
59
  return string.replace(/([A-Z])/g, "-$1").toLowerCase();
62
60
  }
61
+ function encodeAttribute(attribute2) {
62
+ return `${attribute2}`.replace(/'/g, "&apos;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\r\n/g, "\n").replace(/[\r\n]/g, "\n");
63
+ }
63
64
 
64
65
  // src/util/DOMHelper.js
66
+ var ELEMENT_NODE = 1;
67
+ var COMMENT_NODE = 8;
68
+ var getNodePath = (node) => {
69
+ const path = [];
70
+ let parentNode = node.parentNode;
71
+ while (parentNode) {
72
+ path.push([...parentNode.childNodes].indexOf(node));
73
+ node = parentNode;
74
+ parentNode = node.parentNode;
75
+ }
76
+ return path;
77
+ };
65
78
  function getShadowParentOrBody(element) {
66
79
  if (element instanceof ShadowRoot) {
67
80
  return element;
@@ -75,16 +88,22 @@ function getShadowParentOrBody(element) {
75
88
  }
76
89
  var supportsAdoptingStyleSheets = () => "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype;
77
90
  var supportsAppendingStyleSheets = !window.ShadyDOM;
91
+ var convertStringToTemplate = (string) => {
92
+ var _a;
93
+ const template = (_a = globalThis.document) == null ? void 0 : _a.createElement("template");
94
+ template.innerHTML = string.trimStart().trimEnd();
95
+ return template.content;
96
+ };
78
97
 
79
98
  // src/util/Store.js
80
99
  var Store = class {
81
100
  constructor(value) {
82
- __publicField(this, "_observer", new Set());
101
+ __publicField(this, "_observer", /* @__PURE__ */ new Set());
83
102
  __publicField(this, "_singlePropertyMode", false);
84
103
  __publicField(this, "_state", {});
85
104
  this._singlePropertyMode = arguments.length > 0 && !isObjectLike(value);
86
- const specificValues = this._singlePropertyMode ? {value} : value;
87
- this._state = {...!this._singlePropertyMode && this.properties(), ...specificValues};
105
+ const specificValues = this._singlePropertyMode ? { value } : value;
106
+ this._state = { ...!this._singlePropertyMode && this.properties(), ...specificValues };
88
107
  Object.entries(this._state).map(([key, value2]) => {
89
108
  Object.defineProperty(this, key, {
90
109
  get: () => {
@@ -184,23 +203,19 @@ var BaseElement = class extends HTMLElement {
184
203
  propertyOptions: {},
185
204
  ...options
186
205
  };
187
- if (options.childListUpdate !== void 0 && options.childListUpdate !== null) {
188
- this._options.mutationObserverOptions.childList = options.childListUpdate;
189
- console.warn(`[${this.localName}] Using the "childListUpdate" option is deprecated and will be removed before 1.0! Please use the "mutationObserverOptions" dictionary instead. See the docs for more info`);
190
- }
191
206
  }
192
207
  connectedCallback() {
193
208
  this.defineAttributesAsProperties();
194
209
  this.defineProperties();
195
- this.defineComputedProperties();
196
210
  this.definePropertyInjection();
197
211
  this.defineObserver();
198
212
  if (this.hasAttribute("defer-update") || this._options.deferUpdate) {
199
213
  this.registerEventsAndRefs();
200
214
  this.triggerHook("connected");
201
215
  } else {
202
- this.requestUpdate({notify: false}).then(() => {
216
+ this.requestUpdate({ notify: false }).then(() => {
203
217
  this.triggerHook("connected");
218
+ this.triggerHook("afterUpdate");
204
219
  });
205
220
  }
206
221
  }
@@ -208,7 +223,10 @@ var BaseElement = class extends HTMLElement {
208
223
  this._mutationObserver = new MutationObserver((mutations) => {
209
224
  mutations.forEach((mutation) => {
210
225
  if (mutation.type === "attributes" && mutation.target === this && this._state.hasOwnProperty(dashToCamel(mutation.attributeName))) {
211
- this[dashToCamel(mutation.attributeName)] = parseAttribute(this.getAttribute(mutation.attributeName), this._options.propertyOptions[dashToCamel(mutation.attributeName)]);
226
+ this[dashToCamel(mutation.attributeName)] = parseAttribute(
227
+ this.getAttribute(mutation.attributeName),
228
+ this._options.propertyOptions[dashToCamel(mutation.attributeName)]
229
+ );
212
230
  }
213
231
  if (mutation.type === "attributes" && mutation.target !== this) {
214
232
  this.requestUpdate();
@@ -239,7 +257,7 @@ var BaseElement = class extends HTMLElement {
239
257
  });
240
258
  this.triggerHook("disconnected");
241
259
  }
242
- requestUpdate(options = {notify: true}) {
260
+ requestUpdate(options = { notify: true }) {
243
261
  if (options.notify === true) {
244
262
  this.triggerHook("beforeUpdate");
245
263
  }
@@ -248,19 +266,19 @@ var BaseElement = class extends HTMLElement {
248
266
  this._batchUpdate = false;
249
267
  }
250
268
  return new Promise((resolve, reject) => {
251
- this._requestedUpdates.push({resolve, reject});
269
+ this._requestedUpdates.push({ resolve, reject });
252
270
  this._batchUpdate = requestAnimationFrame(() => {
253
271
  try {
254
272
  this.update(options);
255
- this._requestedUpdates.forEach(({resolve: resolve2, reject: reject2}) => resolve2());
273
+ this._requestedUpdates.forEach(({ resolve: resolve2, reject: reject2 }) => resolve2());
256
274
  } catch (e) {
257
- this._requestedUpdates.forEach(({resolve: resolve2, reject: reject2}) => reject2(e));
275
+ this._requestedUpdates.forEach(({ resolve: resolve2, reject: reject2 }) => reject2(e));
258
276
  }
259
277
  this._requestedUpdates = [];
260
278
  });
261
279
  });
262
280
  }
263
- update(options = {notify: true}) {
281
+ update(options = { notify: true }) {
264
282
  this.registerEventsAndRefs();
265
283
  if (options.notify === true) {
266
284
  this.triggerHook("afterUpdate");
@@ -272,19 +290,19 @@ var BaseElement = class extends HTMLElement {
272
290
  }
273
291
  defineAttributesAsProperties() {
274
292
  const ignoreAttributes = ["class", "style"];
275
- Array.from(this.attributes).filter((attribute) => {
276
- return !ignoreAttributes.includes(attribute.name);
277
- }).forEach((attribute) => {
278
- const name = dashToCamel(attribute.name);
293
+ Array.from(this.attributes).filter((attribute2) => {
294
+ return !ignoreAttributes.includes(attribute2.name);
295
+ }).forEach((attribute2) => {
296
+ const name = dashToCamel(attribute2.name);
279
297
  const parseOptions = this._options.propertyOptions[name];
280
- this.defineProperty(name, parseAttribute(attribute.value, parseOptions), true);
298
+ this.defineProperty(name, parseAttribute(attribute2.value, parseOptions), true);
281
299
  });
282
300
  }
283
301
  properties() {
284
302
  return {};
285
303
  }
286
304
  defineProperties() {
287
- Object.keys({...this.injectProperties(), ...this.properties()}).forEach((prop) => {
305
+ Object.keys({ ...this.injectProperties(), ...this.properties() }).forEach((prop) => {
288
306
  const value = this[prop] || this.properties()[prop];
289
307
  this.defineProperty(prop, value);
290
308
  });
@@ -298,7 +316,7 @@ var BaseElement = class extends HTMLElement {
298
316
  return;
299
317
  }
300
318
  if (!reflectAttribute && ((_a = this._options.propertyOptions[property]) == null ? void 0 : _a.reflect)) {
301
- this.reflectProperty({property, newValue: value});
319
+ this.reflectProperty({ property, newValue: value });
302
320
  }
303
321
  if (((_b = this._options.propertyOptions[property]) == null ? void 0 : _b.reflect) === false) {
304
322
  this.removeAttribute(camelToDash(property));
@@ -318,7 +336,7 @@ var BaseElement = class extends HTMLElement {
318
336
  newValue.subscribe(this);
319
337
  }
320
338
  if (reflectAttribute || ((_a2 = this._options.propertyOptions[property]) == null ? void 0 : _a2.reflect)) {
321
- this.reflectProperty({property, newValue, newValueString});
339
+ this.reflectProperty({ property, newValue, newValueString });
322
340
  }
323
341
  if (this._options.autoUpdate) {
324
342
  this.requestUpdate({
@@ -353,7 +371,7 @@ var BaseElement = class extends HTMLElement {
353
371
  }
354
372
  reflectProperty(options) {
355
373
  var _a;
356
- const {property, newValue} = options;
374
+ const { property, newValue } = options;
357
375
  const newValueString = options.newValueString || JSON.stringify(newValue);
358
376
  if (newValue === void 0 || newValue === null || isNaN(newValue)) {
359
377
  this.setAttribute(camelToDash(property), "");
@@ -380,7 +398,7 @@ var BaseElement = class extends HTMLElement {
380
398
  }
381
399
  }
382
400
  requestContext(propertyName, valueOrCallback) {
383
- this.dispatch("request-context", {[propertyName]: valueOrCallback}, true);
401
+ this.dispatch("request-context", { [propertyName]: valueOrCallback }, true);
384
402
  }
385
403
  onRequestContext(event) {
386
404
  var _a;
@@ -398,9 +416,6 @@ var BaseElement = class extends HTMLElement {
398
416
  }
399
417
  });
400
418
  }
401
- hooks() {
402
- return {};
403
- }
404
419
  connected() {
405
420
  }
406
421
  beforeUpdate() {
@@ -410,11 +425,6 @@ var BaseElement = class extends HTMLElement {
410
425
  disconnected() {
411
426
  }
412
427
  triggerHook(name) {
413
- if (this.hooks && name in this.hooks()) {
414
- console.warn(`[${this.localName}] Using the hooks() map for lifecycle hooks is deprecated! Please overwrite the existing lifecycle hook functions. See the docs for more info`);
415
- this.hooks()[name]();
416
- return;
417
- }
418
428
  if (name in this) {
419
429
  this[name]();
420
430
  }
@@ -422,19 +432,6 @@ var BaseElement = class extends HTMLElement {
422
432
  watch() {
423
433
  return {};
424
434
  }
425
- computed() {
426
- return {};
427
- }
428
- defineComputedProperties() {
429
- Object.keys(this.computed()).forEach((prop) => {
430
- if (!this.hasOwnProperty(prop)) {
431
- console.warn(`[${this.localName}] Using the computed() map for computed properties is deprecated! Please use regular JS getters and return the computed value. See the docs for more info`);
432
- Object.defineProperty(this, prop, {
433
- get: () => this.computed()[prop]()
434
- });
435
- }
436
- });
437
- }
438
435
  events() {
439
436
  return {};
440
437
  }
@@ -443,7 +440,7 @@ var BaseElement = class extends HTMLElement {
443
440
  const eventDefinitions = this.events();
444
441
  Object.keys(eventDefinitions).forEach((elementSelector) => {
445
442
  const events = eventDefinitions[elementSelector];
446
- const selectorWhiteList = {window, document, this: this.getRoot()};
443
+ const selectorWhiteList = { window, document, this: this.getRoot() };
447
444
  const whiteListElement = selectorWhiteList[elementSelector];
448
445
  const eventTargets = whiteListElement ? [whiteListElement] : this.getRoot().querySelectorAll(elementSelector);
449
446
  eventTargets.forEach((eventTarget) => {
@@ -453,18 +450,18 @@ var BaseElement = class extends HTMLElement {
453
450
  if (typeof notation === "function") {
454
451
  const callback = notation.bind(this);
455
452
  eventTarget.addEventListener(eventName, callback);
456
- this._registeredEvents.push({eventTarget, eventName, callback});
453
+ this._registeredEvents.push({ eventTarget, eventName, callback });
457
454
  } else if (typeof notation === "object" && typeof notation.listener === "function") {
458
455
  const callback = notation.listener.bind(this);
459
456
  eventTarget.addEventListener(eventName, callback, (_a = notation.options) != null ? _a : {});
460
- this._registeredEvents.push({eventTarget, eventName, callback});
457
+ this._registeredEvents.push({ eventTarget, eventName, callback });
461
458
  }
462
459
  });
463
460
  });
464
461
  });
465
462
  }
466
463
  removeEvents() {
467
- this._registeredEvents.forEach(({eventTarget, eventName, callback}) => {
464
+ this._registeredEvents.forEach(({ eventTarget, eventName, callback }) => {
468
465
  if (eventTarget === window || eventTarget === document || this.getRoot().contains(eventTarget)) {
469
466
  eventTarget.removeEventListener(eventName, callback);
470
467
  }
@@ -488,7 +485,9 @@ var BaseElement = class extends HTMLElement {
488
485
  } else if (!hasListRef) {
489
486
  refsMap[refKey] = refNode;
490
487
  } else {
491
- console.warn(`Did not register singular ref ${refKey}, ${refNode} as a ref list is already registered under the same name.`);
488
+ console.warn(
489
+ `Did not register singular ref ${refKey}, ${refNode} as a ref list is already registered under the same name.`
490
+ );
492
491
  }
493
492
  });
494
493
  this.$refs = refsMap;
@@ -545,11 +544,6 @@ var _StyledElement = class extends BaseElement {
545
544
  super.connectedCallback();
546
545
  if (supportsAdoptingStyleSheets() && this._options.shadowRender) {
547
546
  this.adoptStyleSheets();
548
- } else if (this._options.shadowRender && window.ShadyCSS !== void 0) {
549
- window.ShadyCSS.ScopingShim.prepareAdoptedCssText(this._styles, this.localName);
550
- }
551
- if (window.ShadyCSS !== void 0) {
552
- window.ShadyCSS.styleElement(this);
553
547
  }
554
548
  }
555
549
  styles() {
@@ -559,7 +553,7 @@ var _StyledElement = class extends BaseElement {
559
553
  var _a, _b;
560
554
  if (!supportsAdoptingStyleSheets() || this._options.shadowRender === false) {
561
555
  const appendableStyles = [...this._styles];
562
- if (this._options.shadowRender && this._options.adoptGlobalStyles && !window.ShadyCSS) {
556
+ if (this._options.shadowRender && this._options.adoptGlobalStyles) {
563
557
  appendableStyles.unshift((_b = (_a = _StyledElement.globalStyles) == null ? void 0 : _a.textContent) != null ? _b : "");
564
558
  }
565
559
  this.appendStyleSheets(appendableStyles);
@@ -603,979 +597,688 @@ var StyledElement = _StyledElement;
603
597
  __publicField(StyledElement, "globalStyles", null);
604
598
  StyledElement.updateGlobalStyles();
605
599
 
606
- // node_modules/lit-html/lib/directive.js
607
- /**
608
- * @license
609
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
610
- * This code may only be used under the BSD style license found at
611
- * http://polymer.github.io/LICENSE.txt
612
- * The complete set of authors may be found at
613
- * http://polymer.github.io/AUTHORS.txt
614
- * The complete set of contributors may be found at
615
- * http://polymer.github.io/CONTRIBUTORS.txt
616
- * Code distributed by Google as part of the polymer project is also
617
- * subject to an additional IP rights grant found at
618
- * http://polymer.github.io/PATENTS.txt
619
- */
620
- var directives = new WeakMap();
621
- var isDirective = (o) => {
622
- return typeof o === "function" && directives.has(o);
623
- };
624
-
625
- // node_modules/lit-html/lib/dom.js
626
- /**
627
- * @license
628
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
629
- * This code may only be used under the BSD style license found at
630
- * http://polymer.github.io/LICENSE.txt
631
- * The complete set of authors may be found at
632
- * http://polymer.github.io/AUTHORS.txt
633
- * The complete set of contributors may be found at
634
- * http://polymer.github.io/CONTRIBUTORS.txt
635
- * Code distributed by Google as part of the polymer project is also
636
- * subject to an additional IP rights grant found at
637
- * http://polymer.github.io/PATENTS.txt
638
- */
639
- var isCEPolyfill = typeof window !== "undefined" && window.customElements != null && window.customElements.polyfillWrapFlushCallback !== void 0;
640
- var removeNodes = (container, start, end = null) => {
641
- while (start !== end) {
642
- const n = start.nextSibling;
643
- container.removeChild(start);
644
- start = n;
600
+ // src/dom-parts/Part.js
601
+ var Part = class {
602
+ constructor() {
603
+ __publicField(this, "processor");
604
+ }
605
+ update(value) {
645
606
  }
646
607
  };
647
608
 
648
- // node_modules/lit-html/lib/part.js
649
- /**
650
- * @license
651
- * Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
652
- * This code may only be used under the BSD style license found at
653
- * http://polymer.github.io/LICENSE.txt
654
- * The complete set of authors may be found at
655
- * http://polymer.github.io/AUTHORS.txt
656
- * The complete set of contributors may be found at
657
- * http://polymer.github.io/CONTRIBUTORS.txt
658
- * Code distributed by Google as part of the polymer project is also
659
- * subject to an additional IP rights grant found at
660
- * http://polymer.github.io/PATENTS.txt
661
- */
662
- var noChange = {};
663
- var nothing = {};
664
-
665
- // node_modules/lit-html/lib/template.js
666
- /**
667
- * @license
668
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
669
- * This code may only be used under the BSD style license found at
670
- * http://polymer.github.io/LICENSE.txt
671
- * The complete set of authors may be found at
672
- * http://polymer.github.io/AUTHORS.txt
673
- * The complete set of contributors may be found at
674
- * http://polymer.github.io/CONTRIBUTORS.txt
675
- * Code distributed by Google as part of the polymer project is also
676
- * subject to an additional IP rights grant found at
677
- * http://polymer.github.io/PATENTS.txt
678
- */
679
- var marker = `{{lit-${String(Math.random()).slice(2)}}}`;
680
- var nodeMarker = `<!--${marker}-->`;
681
- var markerRegex = new RegExp(`${marker}|${nodeMarker}`);
682
- var boundAttributeSuffix = "$lit$";
683
- var Template = class {
684
- constructor(result, element) {
685
- this.parts = [];
686
- this.element = element;
687
- const nodesToRemove = [];
688
- const stack = [];
689
- const walker = document.createTreeWalker(element.content, 133, null, false);
690
- let lastPartIndex = 0;
691
- let index = -1;
692
- let partIndex = 0;
693
- const {strings, values: {length}} = result;
694
- while (partIndex < length) {
695
- const node = walker.nextNode();
696
- if (node === null) {
697
- walker.currentNode = stack.pop();
698
- continue;
699
- }
700
- index++;
701
- if (node.nodeType === 1) {
702
- if (node.hasAttributes()) {
703
- const attributes = node.attributes;
704
- const {length: length2} = attributes;
705
- let count = 0;
706
- for (let i = 0; i < length2; i++) {
707
- if (endsWith(attributes[i].name, boundAttributeSuffix)) {
708
- count++;
709
- }
710
- }
711
- while (count-- > 0) {
712
- const stringForPart = strings[partIndex];
713
- const name = lastAttributeNameRegex.exec(stringForPart)[2];
714
- const attributeLookupName = name.toLowerCase() + boundAttributeSuffix;
715
- const attributeValue = node.getAttribute(attributeLookupName);
716
- node.removeAttribute(attributeLookupName);
717
- const statics = attributeValue.split(markerRegex);
718
- this.parts.push({type: "attribute", index, name, strings: statics});
719
- partIndex += statics.length - 1;
720
- }
721
- }
722
- if (node.tagName === "TEMPLATE") {
723
- stack.push(node);
724
- walker.currentNode = node.content;
725
- }
726
- } else if (node.nodeType === 3) {
727
- const data = node.data;
728
- if (data.indexOf(marker) >= 0) {
729
- const parent = node.parentNode;
730
- const strings2 = data.split(markerRegex);
731
- const lastIndex = strings2.length - 1;
732
- for (let i = 0; i < lastIndex; i++) {
733
- let insert;
734
- let s = strings2[i];
735
- if (s === "") {
736
- insert = createMarker();
737
- } else {
738
- const match = lastAttributeNameRegex.exec(s);
739
- if (match !== null && endsWith(match[2], boundAttributeSuffix)) {
740
- s = s.slice(0, match.index) + match[1] + match[2].slice(0, -boundAttributeSuffix.length) + match[3];
741
- }
742
- insert = document.createTextNode(s);
743
- }
744
- parent.insertBefore(insert, node);
745
- this.parts.push({type: "node", index: ++index});
746
- }
747
- if (strings2[lastIndex] === "") {
748
- parent.insertBefore(createMarker(), node);
749
- nodesToRemove.push(node);
750
- } else {
751
- node.data = strings2[lastIndex];
752
- }
753
- partIndex += lastIndex;
754
- }
755
- } else if (node.nodeType === 8) {
756
- if (node.data === marker) {
757
- const parent = node.parentNode;
758
- if (node.previousSibling === null || index === lastPartIndex) {
759
- index++;
760
- parent.insertBefore(createMarker(), node);
761
- }
762
- lastPartIndex = index;
763
- this.parts.push({type: "node", index});
764
- if (node.nextSibling === null) {
765
- node.data = "";
766
- } else {
767
- nodesToRemove.push(node);
768
- index--;
769
- }
770
- partIndex++;
771
- } else {
772
- let i = -1;
773
- while ((i = node.data.indexOf(marker, i + 1)) !== -1) {
774
- this.parts.push({type: "node", index: -1});
775
- partIndex++;
776
- }
777
- }
778
- }
779
- }
780
- for (const n of nodesToRemove) {
781
- n.parentNode.removeChild(n);
782
- }
783
- }
609
+ // src/dom-parts/AttributePart.js
610
+ var processBooleanAttribute = (node, name, oldValue) => {
611
+ node.removeAttribute(`?${name}`);
612
+ return (newValue) => {
613
+ const value = !!(newValue == null ? void 0 : newValue.valueOf()) && newValue !== "false";
614
+ if (oldValue !== value) {
615
+ node.toggleAttribute(name, oldValue = !!value);
616
+ }
617
+ };
784
618
  };
785
- var endsWith = (str, suffix) => {
786
- const index = str.length - suffix.length;
787
- return index >= 0 && str.slice(index) === suffix;
619
+ var processPropertyAttribute = (node, name) => {
620
+ node.removeAttribute(`.${name}`);
621
+ return (value) => {
622
+ node[name] = value;
623
+ };
788
624
  };
789
- var isTemplatePartActive = (part) => part.index !== -1;
790
- var createMarker = () => document.createComment("");
791
- var lastAttributeNameRegex = /([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F "'>=/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/;
792
-
793
- // node_modules/lit-html/lib/template-instance.js
794
- /**
795
- * @license
796
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
797
- * This code may only be used under the BSD style license found at
798
- * http://polymer.github.io/LICENSE.txt
799
- * The complete set of authors may be found at
800
- * http://polymer.github.io/AUTHORS.txt
801
- * The complete set of contributors may be found at
802
- * http://polymer.github.io/CONTRIBUTORS.txt
803
- * Code distributed by Google as part of the polymer project is also
804
- * subject to an additional IP rights grant found at
805
- * http://polymer.github.io/PATENTS.txt
806
- */
807
- var TemplateInstance = class {
808
- constructor(template, processor, options) {
809
- this.__parts = [];
810
- this.template = template;
811
- this.processor = processor;
812
- this.options = options;
813
- }
814
- update(values) {
815
- let i = 0;
816
- for (const part of this.__parts) {
817
- if (part !== void 0) {
818
- part.setValue(values[i]);
819
- }
820
- i++;
821
- }
822
- for (const part of this.__parts) {
823
- if (part !== void 0) {
824
- part.commit();
825
- }
826
- }
827
- }
828
- _clone() {
829
- const fragment = isCEPolyfill ? this.template.element.content.cloneNode(true) : document.importNode(this.template.element.content, true);
830
- const stack = [];
831
- const parts2 = this.template.parts;
832
- const walker = document.createTreeWalker(fragment, 133, null, false);
833
- let partIndex = 0;
834
- let nodeIndex = 0;
835
- let part;
836
- let node = walker.nextNode();
837
- while (partIndex < parts2.length) {
838
- part = parts2[partIndex];
839
- if (!isTemplatePartActive(part)) {
840
- this.__parts.push(void 0);
841
- partIndex++;
842
- continue;
843
- }
844
- while (nodeIndex < part.index) {
845
- nodeIndex++;
846
- if (node.nodeName === "TEMPLATE") {
847
- stack.push(node);
848
- walker.currentNode = node.content;
849
- }
850
- if ((node = walker.nextNode()) === null) {
851
- walker.currentNode = stack.pop();
852
- node = walker.nextNode();
625
+ var processEventAttribute = (node, name) => {
626
+ node.removeAttribute(name);
627
+ let oldValue = void 0;
628
+ let type = name.startsWith("@") ? name.slice(1) : name.toLowerCase().slice(2);
629
+ return (newValue) => {
630
+ if (oldValue !== newValue) {
631
+ if (oldValue)
632
+ node.removeEventListener(type, oldValue);
633
+ if (oldValue = newValue)
634
+ node.addEventListener(type, oldValue);
635
+ }
636
+ };
637
+ };
638
+ var processAttribute = (node, name) => {
639
+ var _a;
640
+ let oldValue, orphan = true;
641
+ const attributeNode = (_a = globalThis.document) == null ? void 0 : _a.createAttributeNS(null, name);
642
+ return (newValue) => {
643
+ const value = newValue == null ? void 0 : newValue.valueOf();
644
+ if (oldValue !== value) {
645
+ if ((oldValue = value) == null) {
646
+ if (!orphan) {
647
+ node.removeAttributeNode(attributeNode);
648
+ orphan = true;
853
649
  }
854
- }
855
- if (part.type === "node") {
856
- const part2 = this.processor.handleTextExpression(this.options);
857
- part2.insertAfterNode(node.previousSibling);
858
- this.__parts.push(part2);
859
650
  } else {
860
- this.__parts.push(...this.processor.handleAttributeExpressions(node, part.name, part.strings, this.options));
651
+ attributeNode.value = value;
652
+ if (orphan) {
653
+ node.setAttributeNodeNS(attributeNode);
654
+ orphan = false;
655
+ }
861
656
  }
862
- partIndex++;
863
657
  }
864
- if (isCEPolyfill) {
865
- document.adoptNode(fragment);
866
- customElements.upgrade(fragment);
867
- }
868
- return fragment;
869
- }
658
+ };
870
659
  };
871
-
872
- // node_modules/lit-html/lib/template-result.js
873
- /**
874
- * @license
875
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
876
- * This code may only be used under the BSD style license found at
877
- * http://polymer.github.io/LICENSE.txt
878
- * The complete set of authors may be found at
879
- * http://polymer.github.io/AUTHORS.txt
880
- * The complete set of contributors may be found at
881
- * http://polymer.github.io/CONTRIBUTORS.txt
882
- * Code distributed by Google as part of the polymer project is also
883
- * subject to an additional IP rights grant found at
884
- * http://polymer.github.io/PATENTS.txt
885
- */
886
- var commentMarker = ` ${marker} `;
887
- var TemplateResult = class {
888
- constructor(strings, values, type, processor) {
889
- this.strings = strings;
890
- this.values = values;
891
- this.type = type;
892
- this.processor = processor;
893
- }
894
- getHTML() {
895
- const l = this.strings.length - 1;
896
- let html2 = "";
897
- let isCommentBinding = false;
898
- for (let i = 0; i < l; i++) {
899
- const s = this.strings[i];
900
- const commentOpen = s.lastIndexOf("<!--");
901
- isCommentBinding = (commentOpen > -1 || isCommentBinding) && s.indexOf("-->", commentOpen + 1) === -1;
902
- const attributeMatch = lastAttributeNameRegex.exec(s);
903
- if (attributeMatch === null) {
904
- html2 += s + (isCommentBinding ? commentMarker : nodeMarker);
905
- } else {
906
- html2 += s.substr(0, attributeMatch.index) + attributeMatch[1] + attributeMatch[2] + boundAttributeSuffix + attributeMatch[3] + marker;
907
- }
908
- }
909
- html2 += this.strings[l];
910
- return html2;
660
+ var processAttributePart = (node, name) => {
661
+ if (name.startsWith("?")) {
662
+ return processBooleanAttribute(node, name.slice(1), false);
911
663
  }
912
- getTemplateElement() {
913
- const template = document.createElement("template");
914
- template.innerHTML = this.getHTML();
915
- return template;
664
+ if (name.startsWith(".")) {
665
+ return processPropertyAttribute(node, name.slice(1));
916
666
  }
667
+ if (name.startsWith("@") || name.startsWith("on")) {
668
+ return processEventAttribute(node, name);
669
+ }
670
+ return processAttribute(node, name);
917
671
  };
918
-
919
- // node_modules/lit-html/lib/parts.js
920
- /**
921
- * @license
922
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
923
- * This code may only be used under the BSD style license found at
924
- * http://polymer.github.io/LICENSE.txt
925
- * The complete set of authors may be found at
926
- * http://polymer.github.io/AUTHORS.txt
927
- * The complete set of contributors may be found at
928
- * http://polymer.github.io/CONTRIBUTORS.txt
929
- * Code distributed by Google as part of the polymer project is also
930
- * subject to an additional IP rights grant found at
931
- * http://polymer.github.io/PATENTS.txt
932
- */
933
- var isPrimitive = (value) => {
934
- return value === null || !(typeof value === "object" || typeof value === "function");
935
- };
936
- var isIterable = (value) => {
937
- return Array.isArray(value) || !!(value && value[Symbol.iterator]);
938
- };
939
- var AttributeCommitter = class {
940
- constructor(element, name, strings) {
941
- this.dirty = true;
942
- this.element = element;
672
+ var AttributePart = class extends Part {
673
+ constructor(node, name, initialValue) {
674
+ super();
675
+ __publicField(this, "name");
676
+ __publicField(this, "interpolations", 1);
677
+ __publicField(this, "values", []);
678
+ __publicField(this, "currentValueIndex", 0);
679
+ __publicField(this, "initialValue");
943
680
  this.name = name;
944
- this.strings = strings;
945
- this.parts = [];
946
- for (let i = 0; i < strings.length - 1; i++) {
947
- this.parts[i] = this._createPart();
948
- }
681
+ this.initialValue = initialValue;
682
+ this.processor = processAttributePart(node.nextElementSibling, this.name);
949
683
  }
950
- _createPart() {
951
- return new AttributePart(this);
952
- }
953
- _getValue() {
954
- const strings = this.strings;
955
- const l = strings.length - 1;
956
- let text = "";
957
- for (let i = 0; i < l; i++) {
958
- text += strings[i];
959
- const part = this.parts[i];
960
- if (part !== void 0) {
961
- const v = part.value;
962
- if (isPrimitive(v) || !isIterable(v)) {
963
- text += typeof v === "string" ? v : String(v);
964
- } else {
965
- for (const t of v) {
966
- text += typeof t === "string" ? t : String(t);
967
- }
968
- }
969
- }
970
- }
971
- text += strings[l];
972
- return text;
684
+ addNode(node) {
685
+ this.interpolations++;
973
686
  }
974
- commit() {
975
- if (this.dirty) {
976
- this.dirty = false;
977
- this.element.setAttribute(this.name, this._getValue());
687
+ update(value) {
688
+ if (this.initialValue === "") {
689
+ this.processor(value);
690
+ return;
978
691
  }
979
- }
980
- };
981
- var AttributePart = class {
982
- constructor(committer) {
983
- this.value = void 0;
984
- this.committer = committer;
985
- }
986
- setValue(value) {
987
- if (value !== noChange && (!isPrimitive(value) || value !== this.value)) {
988
- this.value = value;
989
- if (!isDirective(value)) {
990
- this.committer.dirty = true;
991
- }
692
+ this.values[this.currentValueIndex++] = value;
693
+ if (this.interpolations === this.currentValueIndex) {
694
+ this.currentValueIndex = 0;
695
+ let replaceIndex = 0;
696
+ const parsedValue = this.initialValue.replace(/\x03/g, () => this.values[replaceIndex++]);
697
+ this.processor(parsedValue);
992
698
  }
993
699
  }
994
- commit() {
995
- while (isDirective(this.value)) {
996
- const directive2 = this.value;
997
- this.value = noChange;
998
- directive2(this);
999
- }
1000
- if (this.value === noChange) {
1001
- return;
700
+ };
701
+
702
+ // src/dom-parts/ChildNodePart.js
703
+ var removeChildNodes = (node) => {
704
+ var _a;
705
+ const range = (_a = globalThis.document) == null ? void 0 : _a.createRange();
706
+ const firstChild = Array.isArray(node) ? node[0] : node instanceof TemplatePart ? node.childNodes[0] : node.firstChild;
707
+ const lastChild = Array.isArray(node) ? node[node.length - 1] : node instanceof TemplatePart ? node.childNodes[node.childNodes.length - 1] : node.lastChild;
708
+ range.setStartAfter(firstChild);
709
+ range.setEndAfter(lastChild);
710
+ range.deleteContents();
711
+ return firstChild;
712
+ };
713
+ var removeNodesBetweenComments = (commentNode) => {
714
+ while (commentNode.previousSibling) {
715
+ if (commentNode.previousSibling.nodeType === COMMENT_NODE && commentNode.previousSibling.data === commentNode.data.replace("/", "")) {
716
+ break;
1002
717
  }
1003
- this.committer.commit();
718
+ commentNode.parentNode.removeChild(commentNode.previousSibling);
1004
719
  }
1005
720
  };
1006
- var NodePart = class {
1007
- constructor(options) {
1008
- this.value = void 0;
1009
- this.__pendingValue = void 0;
1010
- this.options = options;
1011
- }
1012
- appendInto(container) {
1013
- this.startNode = container.appendChild(createMarker());
1014
- this.endNode = container.appendChild(createMarker());
1015
- }
1016
- insertAfterNode(ref) {
1017
- this.startNode = ref;
1018
- this.endNode = ref.nextSibling;
1019
- }
1020
- appendIntoPart(part) {
1021
- part.__insert(this.startNode = createMarker());
1022
- part.__insert(this.endNode = createMarker());
1023
- }
1024
- insertAfterPart(ref) {
1025
- ref.__insert(this.startNode = createMarker());
1026
- this.endNode = ref.endNode;
1027
- ref.endNode = this.startNode;
1028
- }
1029
- setValue(value) {
1030
- this.__pendingValue = value;
1031
- }
1032
- commit() {
1033
- if (this.startNode.parentNode === null) {
1034
- return;
721
+ var diffChildNodes = function(parentNode, domChildNodes, templateChildNodes, anchorNode) {
722
+ let length = Math.max(templateChildNodes.length, domChildNodes.length);
723
+ for (let index = 0; index < length; index++) {
724
+ let domChildNode = domChildNodes[index];
725
+ let templateChildNode = templateChildNodes[index];
726
+ if (!domChildNode) {
727
+ if (templateChildNode instanceof TemplatePart) {
728
+ anchorNode.before(...templateChildNode.childNodes);
729
+ } else if (typeof templateChildNode === "object" && "ELEMENT_NODE" in templateChildNode) {
730
+ parentNode.insertBefore(templateChildNode, anchorNode);
731
+ } else {
732
+ parentNode.insertBefore(document.createTextNode(templateChildNode), anchorNode);
733
+ }
734
+ continue;
1035
735
  }
1036
- while (isDirective(this.__pendingValue)) {
1037
- const directive2 = this.__pendingValue;
1038
- this.__pendingValue = noChange;
1039
- directive2(this);
736
+ if (!templateChildNode) {
737
+ parentNode.removeChild(removeChildNodes(domChildNode));
738
+ continue;
1040
739
  }
1041
- const value = this.__pendingValue;
1042
- if (value === noChange) {
1043
- return;
740
+ if (domChildNode === templateChildNode) {
741
+ continue;
1044
742
  }
1045
- if (isPrimitive(value)) {
1046
- if (value !== this.value) {
1047
- this.__commitText(value);
1048
- }
1049
- } else if (value instanceof TemplateResult) {
1050
- this.__commitTemplateResult(value);
1051
- } else if (value instanceof Node) {
1052
- this.__commitNode(value);
1053
- } else if (isIterable(value)) {
1054
- this.__commitIterable(value);
1055
- } else if (value === nothing) {
1056
- this.value = nothing;
1057
- this.clear();
1058
- } else {
1059
- this.__commitText(value);
743
+ if (templateChildNode.nodeType !== domChildNode.nodeType) {
744
+ parentNode.replaceChild(templateChildNode, domChildNode);
745
+ continue;
1060
746
  }
1061
- }
1062
- __insert(node) {
1063
- this.endNode.parentNode.insertBefore(node, this.endNode);
1064
- }
1065
- __commitNode(value) {
1066
- if (this.value === value) {
1067
- return;
747
+ if (templateChildNode.nodeType === ELEMENT_NODE && templateChildNode.tagName !== domChildNode.tagName) {
748
+ parentNode.replaceChild(templateChildNode, domChildNode);
749
+ continue;
1068
750
  }
1069
- this.clear();
1070
- this.__insert(value);
1071
- this.value = value;
1072
- }
1073
- __commitText(value) {
1074
- const node = this.startNode.nextSibling;
1075
- value = value == null ? "" : value;
1076
- const valueAsString = typeof value === "string" ? value : String(value);
1077
- if (node === this.endNode.previousSibling && node.nodeType === 3) {
1078
- node.data = valueAsString;
1079
- } else {
1080
- this.__commitNode(document.createTextNode(valueAsString));
751
+ if (templateChildNode.nodeType === ELEMENT_NODE && templateChildNode.tagName === "SVG") {
752
+ parentNode.replaceChild(templateChildNode, domChildNode);
753
+ continue;
1081
754
  }
1082
- this.value = value;
1083
755
  }
1084
- __commitTemplateResult(value) {
1085
- const template = this.options.templateFactory(value);
1086
- if (this.value instanceof TemplateInstance && this.value.template === template) {
1087
- this.value.update(value.values);
1088
- } else {
1089
- const instance = new TemplateInstance(template, value.processor, this.options);
1090
- const fragment = instance._clone();
1091
- instance.update(value.values);
1092
- this.__commitNode(fragment);
1093
- this.value = instance;
1094
- }
1095
- }
1096
- __commitIterable(value) {
1097
- if (!Array.isArray(this.value)) {
1098
- this.value = [];
1099
- this.clear();
1100
- }
1101
- const itemParts = this.value;
1102
- let partIndex = 0;
1103
- let itemPart;
1104
- for (const item of value) {
1105
- itemPart = itemParts[partIndex];
1106
- if (itemPart === void 0) {
1107
- itemPart = new NodePart(this.options);
1108
- itemParts.push(itemPart);
1109
- if (partIndex === 0) {
1110
- itemPart.appendIntoPart(this);
1111
- } else {
1112
- itemPart.insertAfterPart(itemParts[partIndex - 1]);
756
+ return templateChildNodes;
757
+ };
758
+ var processNodePart = (comment, initialValue) => {
759
+ let nodes = [];
760
+ let oldValue = initialValue instanceof TemplatePart ? [...initialValue.childNodes] : initialValue;
761
+ let cachedTextNode = void 0;
762
+ const processNodeValue = (newValue) => {
763
+ var _a, _b;
764
+ switch (typeof newValue) {
765
+ case "string":
766
+ case "number":
767
+ case "boolean":
768
+ if (oldValue !== newValue) {
769
+ oldValue = newValue;
770
+ if (!cachedTextNode)
771
+ cachedTextNode = (_a = globalThis.document) == null ? void 0 : _a.createTextNode("");
772
+ cachedTextNode.data = newValue;
773
+ if (((_b = comment.previousSibling) == null ? void 0 : _b.data) === comment.data.replace("/", "")) {
774
+ comment.parentNode.insertBefore(cachedTextNode, comment);
775
+ } else {
776
+ comment.previousSibling.data = newValue;
777
+ }
778
+ nodes = [cachedTextNode];
1113
779
  }
1114
- }
1115
- itemPart.setValue(item);
1116
- itemPart.commit();
1117
- partIndex++;
1118
- }
1119
- if (partIndex < itemParts.length) {
1120
- itemParts.length = partIndex;
1121
- this.clear(itemPart && itemPart.endNode);
780
+ break;
781
+ case "object":
782
+ case "undefined":
783
+ if (newValue === null || newValue === void 0) {
784
+ if (oldValue !== newValue) {
785
+ oldValue = newValue;
786
+ removeNodesBetweenComments(comment);
787
+ nodes = [];
788
+ }
789
+ break;
790
+ }
791
+ if (Array.isArray(newValue)) {
792
+ if (newValue.length === 0) {
793
+ removeNodesBetweenComments(comment);
794
+ nodes = [];
795
+ } else {
796
+ nodes = diffChildNodes(comment.parentNode, oldValue || [], newValue, comment);
797
+ }
798
+ oldValue = newValue;
799
+ break;
800
+ }
801
+ if (oldValue !== newValue) {
802
+ if ("ELEMENT_NODE" in newValue) {
803
+ oldValue = newValue;
804
+ nodes = diffChildNodes(comment.parentNode, nodes, [newValue], comment);
805
+ } else if (newValue instanceof TemplatePart) {
806
+ oldValue = newValue;
807
+ nodes = diffChildNodes(comment.parentNode, nodes, [...newValue.childNodes], comment);
808
+ } else {
809
+ console.warn("Could not process value", newValue);
810
+ }
811
+ }
812
+ break;
813
+ case "function":
814
+ processNodeValue(newValue(comment));
815
+ break;
1122
816
  }
1123
- }
1124
- clear(startNode = this.startNode) {
1125
- removeNodes(this.startNode.parentNode, startNode.nextSibling, this.endNode);
1126
- }
817
+ };
818
+ return processNodeValue;
1127
819
  };
1128
- var BooleanAttributePart = class {
1129
- constructor(element, name, strings) {
1130
- this.value = void 0;
1131
- this.__pendingValue = void 0;
1132
- if (strings.length !== 2 || strings[0] !== "" || strings[1] !== "") {
1133
- throw new Error("Boolean attributes can only contain a single expression");
820
+ var ChildNodePart = class extends Part {
821
+ constructor(startNode, value) {
822
+ var _a;
823
+ if (startNode && (startNode == null ? void 0 : startNode.nodeType) !== COMMENT_NODE) {
824
+ throw new Error("ChildNodePart: startNode is not a comment node");
1134
825
  }
1135
- this.element = element;
1136
- this.name = name;
1137
- this.strings = strings;
1138
- }
1139
- setValue(value) {
1140
- this.__pendingValue = value;
1141
- }
1142
- commit() {
1143
- while (isDirective(this.__pendingValue)) {
1144
- const directive2 = this.__pendingValue;
1145
- this.__pendingValue = noChange;
1146
- directive2(this);
826
+ super();
827
+ __publicField(this, "startNode");
828
+ __publicField(this, "endNode");
829
+ __publicField(this, "parts", []);
830
+ __publicField(this, "templatePart");
831
+ __publicField(this, "childNodes", []);
832
+ let serverSideRendered = false;
833
+ if (startNode) {
834
+ const placeholder = startNode.data;
835
+ const childNodes = [startNode];
836
+ let childNode = startNode.nextSibling;
837
+ while (childNode && childNode.data !== `/${placeholder}`) {
838
+ childNodes.push(childNode);
839
+ childNode = childNode.nextSibling;
840
+ }
841
+ const endNode = childNode;
842
+ childNodes.push(endNode);
843
+ if (childNodes.length > 2) {
844
+ serverSideRendered = true;
845
+ }
846
+ this.childNodes = childNodes;
847
+ this.startNode = startNode;
848
+ this.endNode = endNode;
1147
849
  }
1148
- if (this.__pendingValue === noChange) {
1149
- return;
850
+ const initialValue = this.parseValue(value);
851
+ if (this.endNode) {
852
+ this.processor = processNodePart(this.endNode, serverSideRendered ? initialValue : void 0);
1150
853
  }
1151
- const value = !!this.__pendingValue;
1152
- if (this.value !== value) {
1153
- if (value) {
1154
- this.element.setAttribute(this.name, "");
1155
- } else {
1156
- this.element.removeAttribute(this.name);
854
+ if (!serverSideRendered) {
855
+ if (value instanceof TemplateResult || Array.isArray(value)) {
856
+ this.updateParts(value);
1157
857
  }
1158
- this.value = value;
858
+ this.childNodes = [...this.childNodes];
859
+ (_a = this.processor) == null ? void 0 : _a.call(this, initialValue);
1159
860
  }
1160
- this.__pendingValue = noChange;
1161
861
  }
1162
- };
1163
- var PropertyCommitter = class extends AttributeCommitter {
1164
- constructor(element, name, strings) {
1165
- super(element, name, strings);
1166
- this.single = strings.length === 2 && strings[0] === "" && strings[1] === "";
1167
- }
1168
- _createPart() {
1169
- return new PropertyPart(this);
1170
- }
1171
- _getValue() {
1172
- if (this.single) {
1173
- return this.parts[0].value;
862
+ update(value) {
863
+ var _a;
864
+ const parsedValue = this.parseValue(value);
865
+ if (value instanceof TemplateResult || Array.isArray(value)) {
866
+ this.updateParts(value);
1174
867
  }
1175
- return super._getValue();
868
+ (_a = this.processor) == null ? void 0 : _a.call(this, parsedValue);
1176
869
  }
1177
- commit() {
1178
- if (this.dirty) {
1179
- this.dirty = false;
1180
- this.element[this.name] = this._getValue();
870
+ updateParts(value) {
871
+ var _a;
872
+ if (value instanceof TemplateResult) {
873
+ this.templatePart.update(value);
1181
874
  }
1182
- }
1183
- };
1184
- var PropertyPart = class extends AttributePart {
1185
- };
1186
- var eventOptionsSupported = false;
1187
- (() => {
1188
- try {
1189
- const options = {
1190
- get capture() {
1191
- eventOptionsSupported = true;
1192
- return false;
875
+ if (Array.isArray(value)) {
876
+ for (let index = 0; index < value.length; index++) {
877
+ (_a = this.parts[index]) == null ? void 0 : _a.update(value[index]);
1193
878
  }
1194
- };
1195
- window.addEventListener("test", options, options);
1196
- window.removeEventListener("test", options, options);
1197
- } catch (_e) {
1198
- }
1199
- })();
1200
- var EventPart = class {
1201
- constructor(element, eventName, eventContext) {
1202
- this.value = void 0;
1203
- this.__pendingValue = void 0;
1204
- this.element = element;
1205
- this.eventName = eventName;
1206
- this.eventContext = eventContext;
1207
- this.__boundHandleEvent = (e) => this.handleEvent(e);
1208
- }
1209
- setValue(value) {
1210
- this.__pendingValue = value;
1211
- }
1212
- commit() {
1213
- while (isDirective(this.__pendingValue)) {
1214
- const directive2 = this.__pendingValue;
1215
- this.__pendingValue = noChange;
1216
- directive2(this);
1217
879
  }
1218
- if (this.__pendingValue === noChange) {
1219
- return;
880
+ }
881
+ parseValue(value) {
882
+ var _a;
883
+ if (value instanceof TemplateResult) {
884
+ if (!this.templatePart) {
885
+ const templatePartCommentNodes = (_a = this.childNodes) == null ? void 0 : _a.filter(
886
+ (node) => node && node.nodeType === COMMENT_NODE && node.data === "template-part"
887
+ );
888
+ const startNode = templatePartCommentNodes[0];
889
+ this.templatePart = new TemplatePart(startNode, value);
890
+ }
891
+ return this.templatePart;
1220
892
  }
1221
- const newListener = this.__pendingValue;
1222
- const oldListener = this.value;
1223
- const shouldRemoveListener = newListener == null || oldListener != null && (newListener.capture !== oldListener.capture || newListener.once !== oldListener.once || newListener.passive !== oldListener.passive);
1224
- const shouldAddListener = newListener != null && (oldListener == null || shouldRemoveListener);
1225
- if (shouldRemoveListener) {
1226
- this.element.removeEventListener(this.eventName, this.__boundHandleEvent, this.__options);
893
+ if (Array.isArray(value)) {
894
+ return this.parseArray(value);
1227
895
  }
1228
- if (shouldAddListener) {
1229
- this.__options = getOptions(newListener);
1230
- this.element.addEventListener(this.eventName, this.__boundHandleEvent, this.__options);
896
+ return value;
897
+ }
898
+ parseArray(values) {
899
+ var _a, _b;
900
+ const parsedValues = [];
901
+ for (let index = 0; index < values.length; index++) {
902
+ let value = values[index];
903
+ if (value instanceof TemplateResult) {
904
+ let templatePart = this.parts[index];
905
+ if (!templatePart) {
906
+ const templatePartCommentNodes = (_a = this.childNodes) == null ? void 0 : _a.filter(
907
+ (node) => node && node.nodeType === COMMENT_NODE && node.data === "template-part"
908
+ );
909
+ const startNode = templatePartCommentNodes[index];
910
+ templatePart = new TemplatePart(startNode, value);
911
+ this.parts[index] = templatePart;
912
+ }
913
+ parsedValues[index] = templatePart;
914
+ } else if (Array.isArray(value)) {
915
+ let childNodePart = this.parts[index];
916
+ if (!childNodePart) {
917
+ const templatePartCommentNodes = (_b = this.childNodes) == null ? void 0 : _b.filter(
918
+ (node) => node && node.nodeType === COMMENT_NODE && node.data === "template-part"
919
+ );
920
+ const startNode = templatePartCommentNodes[index];
921
+ childNodePart = new ChildNodePart(startNode, value);
922
+ this.parts[index] = childNodePart;
923
+ }
924
+ parsedValues[index] = childNodePart;
925
+ } else {
926
+ parsedValues[index] = typeof value === "function" ? value() : value;
927
+ }
1231
928
  }
1232
- this.value = newListener;
1233
- this.__pendingValue = noChange;
929
+ return parsedValues;
1234
930
  }
1235
- handleEvent(event) {
1236
- if (typeof this.value === "function") {
1237
- this.value.call(this.eventContext || this.element, event);
1238
- } else {
1239
- this.value.handleEvent(event);
931
+ };
932
+
933
+ // src/dom-parts/NodePart.js
934
+ var NodePart = class extends Part {
935
+ constructor(node, initialValue) {
936
+ if (!isObjectLike(initialValue) && !initialValue.directiveClass) {
937
+ throw new Error(
938
+ "NodePart: value is not a wrapped directive function. You must wrap you custom directive class with the defineDirective function."
939
+ );
1240
940
  }
941
+ super();
942
+ __publicField(this, "node");
943
+ __publicField(this, "directive");
944
+ this.node = node.nextElementSibling;
945
+ const { directiveClass, values } = initialValue;
946
+ this.directive = new directiveClass(node.nextElementSibling);
947
+ }
948
+ update(value) {
949
+ const { directiveClass, values } = value;
950
+ this.directive.update(...values);
1241
951
  }
1242
952
  };
1243
- var getOptions = (o) => o && (eventOptionsSupported ? {capture: o.capture, passive: o.passive, once: o.once} : o.capture);
1244
953
 
1245
- // node_modules/lit-html/lib/default-template-processor.js
1246
- /**
1247
- * @license
1248
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1249
- * This code may only be used under the BSD style license found at
1250
- * http://polymer.github.io/LICENSE.txt
1251
- * The complete set of authors may be found at
1252
- * http://polymer.github.io/AUTHORS.txt
1253
- * The complete set of contributors may be found at
1254
- * http://polymer.github.io/CONTRIBUTORS.txt
1255
- * Code distributed by Google as part of the polymer project is also
1256
- * subject to an additional IP rights grant found at
1257
- * http://polymer.github.io/PATENTS.txt
1258
- */
1259
- var DefaultTemplateProcessor = class {
1260
- handleAttributeExpressions(element, name, strings, options) {
1261
- const prefix = name[0];
1262
- if (prefix === ".") {
1263
- const committer2 = new PropertyCommitter(element, name.slice(1), strings);
1264
- return committer2.parts;
954
+ // src/dom-parts/TemplatePart.js
955
+ var partsCache = /* @__PURE__ */ new WeakMap();
956
+ var fragmentsCache = /* @__PURE__ */ new WeakMap();
957
+ var TemplatePart = class extends Part {
958
+ constructor(startNode, value) {
959
+ if (startNode && (startNode == null ? void 0 : startNode.nodeType) !== COMMENT_NODE) {
960
+ throw new Error("TemplatePart: startNode is not a comment node");
1265
961
  }
1266
- if (prefix === "@") {
1267
- return [new EventPart(element, name.slice(1), options.eventContext)];
962
+ super();
963
+ __publicField(this, "parts", []);
964
+ __publicField(this, "strings");
965
+ __publicField(this, "childNodes", []);
966
+ let serverSideRendered = false;
967
+ if (startNode) {
968
+ const placeholder = startNode.data;
969
+ const childNodes = [startNode];
970
+ let childNode = startNode.nextSibling;
971
+ while (childNode && childNode.data !== `/${placeholder}`) {
972
+ childNodes.push(childNode);
973
+ childNode = childNode.nextSibling;
974
+ }
975
+ const endNode = childNode;
976
+ childNodes.push(endNode);
977
+ if (childNodes.length > 2) {
978
+ serverSideRendered = true;
979
+ this.childNodes = childNodes;
980
+ }
1268
981
  }
1269
- if (prefix === "?") {
1270
- return [new BooleanAttributePart(element, name.slice(1), strings)];
982
+ this.parseValue(value);
983
+ if (!serverSideRendered) {
984
+ this.updateParts(value.values);
985
+ this.childNodes = [...this.childNodes];
1271
986
  }
1272
- const committer = new AttributeCommitter(element, name, strings);
1273
- return committer.parts;
1274
987
  }
1275
- handleTextExpression(options) {
1276
- return new NodePart(options);
988
+ update(value) {
989
+ this.parseValue(value);
990
+ this.updateParts(value.values);
1277
991
  }
1278
- };
1279
- var defaultTemplateProcessor = new DefaultTemplateProcessor();
1280
-
1281
- // node_modules/lit-html/lib/template-factory.js
1282
- /**
1283
- * @license
1284
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1285
- * This code may only be used under the BSD style license found at
1286
- * http://polymer.github.io/LICENSE.txt
1287
- * The complete set of authors may be found at
1288
- * http://polymer.github.io/AUTHORS.txt
1289
- * The complete set of contributors may be found at
1290
- * http://polymer.github.io/CONTRIBUTORS.txt
1291
- * Code distributed by Google as part of the polymer project is also
1292
- * subject to an additional IP rights grant found at
1293
- * http://polymer.github.io/PATENTS.txt
1294
- */
1295
- function templateFactory(result) {
1296
- let templateCache = templateCaches.get(result.type);
1297
- if (templateCache === void 0) {
1298
- templateCache = {
1299
- stringsArray: new WeakMap(),
1300
- keyString: new Map()
1301
- };
1302
- templateCaches.set(result.type, templateCache);
992
+ updateParts(values) {
993
+ var _a;
994
+ for (let index = 0; index < values.length; index++) {
995
+ (_a = this.parts[index]) == null ? void 0 : _a.update(values[index]);
996
+ }
1303
997
  }
1304
- let template = templateCache.stringsArray.get(result.strings);
1305
- if (template !== void 0) {
1306
- return template;
998
+ parseValue(templateResult) {
999
+ var _a;
1000
+ if (this.strings !== templateResult.strings) {
1001
+ if (this.childNodes.length === 0) {
1002
+ let fragment = fragmentsCache.get(templateResult.strings);
1003
+ if (!fragment) {
1004
+ fragment = this.parseFragment(templateResult);
1005
+ fragmentsCache.set(templateResult.strings, fragment);
1006
+ }
1007
+ const importedFragment = (_a = globalThis.document) == null ? void 0 : _a.importNode(fragment, true);
1008
+ this.childNodes = importedFragment.childNodes;
1009
+ }
1010
+ let parts = partsCache.get(templateResult.strings);
1011
+ if (!parts) {
1012
+ parts = templateResult.parseParts(this.childNodes);
1013
+ partsCache.set(templateResult.strings, parts);
1014
+ }
1015
+ let previousAttributePart = void 0;
1016
+ this.parts = parts.map((part, index) => {
1017
+ const node = part.path.reduceRight(({ childNodes }, i) => childNodes[i], this);
1018
+ if (part.type === "node") {
1019
+ return new ChildNodePart(node, templateResult.values[index]);
1020
+ }
1021
+ if (part.type === "attribute") {
1022
+ if (previousAttributePart && previousAttributePart.name === part.name) {
1023
+ previousAttributePart.addNode(node);
1024
+ return previousAttributePart;
1025
+ }
1026
+ return previousAttributePart = new AttributePart(node, part.name, part.initialValue);
1027
+ }
1028
+ if (part.type === "directive") {
1029
+ return new NodePart(node, templateResult.values[index]);
1030
+ }
1031
+ throw `cannot map part: ${part}`;
1032
+ });
1033
+ this.strings = templateResult.strings;
1034
+ }
1307
1035
  }
1308
- const key = result.strings.join(marker);
1309
- template = templateCache.keyString.get(key);
1310
- if (template === void 0) {
1311
- template = new Template(result, result.getTemplateElement());
1312
- templateCache.keyString.set(key, template);
1036
+ parseFragment(templateResult) {
1037
+ const templateString = templateResult.templateString;
1038
+ return convertStringToTemplate(templateString);
1313
1039
  }
1314
- templateCache.stringsArray.set(result.strings, template);
1315
- return template;
1316
- }
1317
- var templateCaches = new Map();
1318
-
1319
- // node_modules/lit-html/lib/render.js
1320
- /**
1321
- * @license
1322
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1323
- * This code may only be used under the BSD style license found at
1324
- * http://polymer.github.io/LICENSE.txt
1325
- * The complete set of authors may be found at
1326
- * http://polymer.github.io/AUTHORS.txt
1327
- * The complete set of contributors may be found at
1328
- * http://polymer.github.io/CONTRIBUTORS.txt
1329
- * Code distributed by Google as part of the polymer project is also
1330
- * subject to an additional IP rights grant found at
1331
- * http://polymer.github.io/PATENTS.txt
1332
- */
1333
- var parts = new WeakMap();
1334
- var render = (result, container, options) => {
1335
- let part = parts.get(container);
1336
- if (part === void 0) {
1337
- removeNodes(container, container.firstChild);
1338
- parts.set(container, part = new NodePart(Object.assign({templateFactory}, options)));
1339
- part.appendInto(container);
1340
- }
1341
- part.setValue(result);
1342
- part.commit();
1343
1040
  };
1344
1041
 
1345
- // node_modules/lit-html/lit-html.js
1346
- /**
1347
- * @license
1348
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1349
- * This code may only be used under the BSD style license found at
1350
- * http://polymer.github.io/LICENSE.txt
1351
- * The complete set of authors may be found at
1352
- * http://polymer.github.io/AUTHORS.txt
1353
- * The complete set of contributors may be found at
1354
- * http://polymer.github.io/CONTRIBUTORS.txt
1355
- * Code distributed by Google as part of the polymer project is also
1356
- * subject to an additional IP rights grant found at
1357
- * http://polymer.github.io/PATENTS.txt
1358
- */
1359
- if (typeof window !== "undefined") {
1360
- (window["litHtmlVersions"] || (window["litHtmlVersions"] = [])).push("1.2.1");
1361
- }
1362
- var html = (strings, ...values) => new TemplateResult(strings, values, "html", defaultTemplateProcessor);
1363
-
1364
- // node_modules/lit-html/lib/modify-template.js
1365
- /**
1366
- * @license
1367
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1368
- * This code may only be used under the BSD style license found at
1369
- * http://polymer.github.io/LICENSE.txt
1370
- * The complete set of authors may be found at
1371
- * http://polymer.github.io/AUTHORS.txt
1372
- * The complete set of contributors may be found at
1373
- * http://polymer.github.io/CONTRIBUTORS.txt
1374
- * Code distributed by Google as part of the polymer project is also
1375
- * subject to an additional IP rights grant found at
1376
- * http://polymer.github.io/PATENTS.txt
1377
- */
1378
- var walkerNodeFilter = 133;
1379
- function removeNodesFromTemplate(template, nodesToRemove) {
1380
- const {element: {content}, parts: parts2} = template;
1381
- const walker = document.createTreeWalker(content, walkerNodeFilter, null, false);
1382
- let partIndex = nextActiveIndexInTemplateParts(parts2);
1383
- let part = parts2[partIndex];
1384
- let nodeIndex = -1;
1385
- let removeCount = 0;
1386
- const nodesToRemoveInTemplate = [];
1387
- let currentRemovingNode = null;
1388
- while (walker.nextNode()) {
1389
- nodeIndex++;
1390
- const node = walker.currentNode;
1391
- if (node.previousSibling === currentRemovingNode) {
1392
- currentRemovingNode = null;
1393
- }
1394
- if (nodesToRemove.has(node)) {
1395
- nodesToRemoveInTemplate.push(node);
1396
- if (currentRemovingNode === null) {
1397
- currentRemovingNode = node;
1042
+ // src/dom-parts/TemplateResult.js
1043
+ var voidElements = /^(?:area|base|br|col|embed|hr|img|input|link|meta|source|track|wbr)$/i;
1044
+ var elements = /<([a-z]+[a-z0-9:._-]*)([^>]*?)(\/?)>/g;
1045
+ var attributes = /([^\s]*)=((?:")[^"]*(?:")|(?:')[^']*(?:')|[^\s\/>]*)|([^\s\/>]*)/g;
1046
+ var partPositions = /[\x01\x02]/g;
1047
+ var interpolation = new RegExp(`(<!--dom-part-(\\d+)--><!--/dom-part-(\\d+)-->|(\\S\\w+)="(")?|)`, "g");
1048
+ var createTemplateString = (templateStrings, attributePlaceholders = "") => {
1049
+ let partIndex = 0;
1050
+ let template = templateStrings.join("").trim();
1051
+ template = template.replace(elements, (_, name, attributesString, trailingSlash) => {
1052
+ let elementTagWithAttributes = name + attributesString.replaceAll("", attributePlaceholders).trimEnd();
1053
+ if (trailingSlash.length)
1054
+ elementTagWithAttributes += voidElements.test(name) ? " /" : "></" + name;
1055
+ const attributeParts = attributesString.replace(attributes, (attribute2, name2, valueWithQuotes, directive) => {
1056
+ if (directive) {
1057
+ return `<!--$-->`;
1398
1058
  }
1059
+ const value = (valueWithQuotes == null ? void 0 : valueWithQuotes.startsWith('"')) || (valueWithQuotes == null ? void 0 : valueWithQuotes.startsWith("'")) ? valueWithQuotes.slice(1, -1) : valueWithQuotes;
1060
+ const partsCount = (attribute2.match(/\x01/g) || []).length;
1061
+ const parts = [];
1062
+ for (let index = 0; index < partsCount; index++) {
1063
+ parts.push(`<!--:${name2}=${value.replaceAll("", "")}-->`);
1064
+ }
1065
+ return parts.join("");
1066
+ });
1067
+ return `
1068
+ ${attributesString.includes("") ? attributeParts : ""}
1069
+ <${elementTagWithAttributes}>
1070
+ `;
1071
+ });
1072
+ template = template.replace(partPositions, (partPosition) => {
1073
+ if (partPosition === "") {
1074
+ return `<!--dom-part-${partIndex}--><!--/dom-part-${partIndex++}-->`;
1399
1075
  }
1400
- if (currentRemovingNode !== null) {
1401
- removeCount++;
1402
- }
1403
- while (part !== void 0 && part.index === nodeIndex) {
1404
- part.index = currentRemovingNode !== null ? -1 : part.index - removeCount;
1405
- partIndex = nextActiveIndexInTemplateParts(parts2, partIndex);
1406
- part = parts2[partIndex];
1076
+ if (partPosition === "") {
1077
+ return `dom-part-${partIndex++}`;
1407
1078
  }
1408
- }
1409
- nodesToRemoveInTemplate.forEach((n) => n.parentNode.removeChild(n));
1410
- }
1411
- var countNodes = (node) => {
1412
- let count = node.nodeType === 11 ? 0 : 1;
1413
- const walker = document.createTreeWalker(node, walkerNodeFilter, null, false);
1414
- while (walker.nextNode()) {
1415
- count++;
1416
- }
1417
- return count;
1079
+ });
1080
+ return `
1081
+ <!--template-part-->
1082
+ ${template}
1083
+ <!--/template-part-->
1084
+ `;
1418
1085
  };
1419
- var nextActiveIndexInTemplateParts = (parts2, startIndex = -1) => {
1420
- for (let i = startIndex + 1; i < parts2.length; i++) {
1421
- const part = parts2[i];
1422
- if (isTemplatePartActive(part)) {
1423
- return i;
1424
- }
1086
+ var attribute = (name, value, isSingleValue = true) => {
1087
+ return ` ${name}="${encodeAttribute(isObjectLike(value) ? JSON.stringify(value) : value)}${isSingleValue ? '"' : ""}`;
1088
+ };
1089
+ var getValue = (value) => {
1090
+ switch (typeof value) {
1091
+ case "string":
1092
+ return encodeAttribute(value);
1093
+ case "boolean":
1094
+ case "number":
1095
+ return String(value);
1096
+ case "object":
1097
+ switch (true) {
1098
+ case Array.isArray(value):
1099
+ return value.map(getValue).join("");
1100
+ case value instanceof TemplateResult:
1101
+ return value.toString();
1102
+ }
1103
+ break;
1104
+ case "function":
1105
+ return getValue(value());
1425
1106
  }
1426
- return -1;
1107
+ return value == null ? "" : encodeAttribute(String(value));
1427
1108
  };
1428
- function insertNodeIntoTemplate(template, node, refNode = null) {
1429
- const {element: {content}, parts: parts2} = template;
1430
- if (refNode === null || refNode === void 0) {
1431
- content.appendChild(node);
1432
- return;
1433
- }
1434
- const walker = document.createTreeWalker(content, walkerNodeFilter, null, false);
1435
- let partIndex = nextActiveIndexInTemplateParts(parts2);
1436
- let insertCount = 0;
1437
- let walkerIndex = -1;
1438
- while (walker.nextNode()) {
1439
- walkerIndex++;
1440
- const walkerNode = walker.currentNode;
1441
- if (walkerNode === refNode) {
1442
- insertCount = countNodes(node);
1443
- refNode.parentNode.insertBefore(node, refNode);
1109
+ var parsedUpdates = /* @__PURE__ */ new WeakMap();
1110
+ var templateParts = /* @__PURE__ */ new WeakMap();
1111
+ var TemplateResult = class {
1112
+ constructor(strings, ...values) {
1113
+ this.strings = strings;
1114
+ this.values = values;
1115
+ }
1116
+ renderInto(domNode) {
1117
+ let serverSideRendered = false;
1118
+ let templatePart = templateParts.get(domNode);
1119
+ if (!templatePart) {
1120
+ const startNode = Array.from(domNode.childNodes).filter((node) => node.nodeType === COMMENT_NODE).find((node) => node.data === "template-part");
1121
+ serverSideRendered = startNode !== void 0;
1122
+ templatePart = new TemplatePart(startNode, this);
1123
+ templateParts.set(domNode, templatePart);
1124
+ if (!serverSideRendered) {
1125
+ domNode.replaceChildren(...templatePart.childNodes);
1126
+ }
1127
+ } else {
1128
+ templatePart.update(this);
1444
1129
  }
1445
- while (partIndex !== -1 && parts2[partIndex].index === walkerIndex) {
1446
- if (insertCount > 0) {
1447
- while (partIndex !== -1) {
1448
- parts2[partIndex].index += insertCount;
1449
- partIndex = nextActiveIndexInTemplateParts(parts2, partIndex);
1130
+ }
1131
+ parse(strings) {
1132
+ const html2 = createTemplateString(strings, "");
1133
+ const parts = [];
1134
+ let i = 0;
1135
+ let match = null;
1136
+ while (match = interpolation.exec(html2)) {
1137
+ const pre = html2.slice(i, match.index);
1138
+ i = match.index + match[0].length;
1139
+ if (match[2]) {
1140
+ const index = match[2];
1141
+ parts.push((value) => `${pre}<!--dom-part-${index}-->${getValue(value)}<!--/dom-part-${index}-->`);
1142
+ } else if (match[4]) {
1143
+ const isSingleValue = match[5] !== void 0;
1144
+ let name = match[4];
1145
+ switch (true) {
1146
+ case name[0] === "?":
1147
+ const booleanName = name.slice(1).toLowerCase();
1148
+ parts.push((value) => {
1149
+ if (!value)
1150
+ return "";
1151
+ return `${pre} ${booleanName}=""`;
1152
+ });
1153
+ break;
1154
+ case name[0] === ".":
1155
+ const lower = name.slice(1).toLowerCase();
1156
+ parts.push((value) => {
1157
+ let result = pre;
1158
+ if (value === null || value === void 0 || value === "") {
1159
+ result += attribute(lower, "");
1160
+ } else {
1161
+ result += attribute(lower, value, isSingleValue);
1162
+ }
1163
+ return result;
1164
+ });
1165
+ break;
1166
+ case name[0] === "@":
1167
+ name = "on" + name.slice(1);
1168
+ case (name[0] === "o" && name[1] === "n"):
1169
+ parts.push((value) => {
1170
+ return pre;
1171
+ });
1172
+ break;
1173
+ default:
1174
+ parts.push((value) => {
1175
+ let result = pre;
1176
+ if (value != null) {
1177
+ result += attribute(name, value, isSingleValue);
1178
+ }
1179
+ return result;
1180
+ });
1181
+ break;
1450
1182
  }
1451
- return;
1183
+ } else {
1184
+ parts.push((value) => {
1185
+ let result = pre;
1186
+ if (isObjectLike(value) && value.directiveClass) {
1187
+ } else if (value != null) {
1188
+ result += encodeAttribute(isObjectLike(value) ? JSON.stringify(value) : value);
1189
+ }
1190
+ return result;
1191
+ });
1452
1192
  }
1453
- partIndex = nextActiveIndexInTemplateParts(parts2, partIndex);
1454
1193
  }
1194
+ if (parts.length !== strings.length - 1) {
1195
+ throw {
1196
+ name: "ParseTemplateError",
1197
+ message: "Could not parse parts from template correctly. Parts length has not the expected length.",
1198
+ strings,
1199
+ templateString: html2,
1200
+ parts
1201
+ };
1202
+ }
1203
+ if (parts.length) {
1204
+ const last = parts[parts.length - 1];
1205
+ const chunk = html2.slice(i);
1206
+ parts[parts.length - 1] = (value) => last(value) + chunk;
1207
+ } else {
1208
+ parts.push(() => html2);
1209
+ }
1210
+ return parts;
1455
1211
  }
1456
- }
1457
-
1458
- // node_modules/lit-html/lib/shady-render.js
1459
- /**
1460
- * @license
1461
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1462
- * This code may only be used under the BSD style license found at
1463
- * http://polymer.github.io/LICENSE.txt
1464
- * The complete set of authors may be found at
1465
- * http://polymer.github.io/AUTHORS.txt
1466
- * The complete set of contributors may be found at
1467
- * http://polymer.github.io/CONTRIBUTORS.txt
1468
- * Code distributed by Google as part of the polymer project is also
1469
- * subject to an additional IP rights grant found at
1470
- * http://polymer.github.io/PATENTS.txt
1471
- */
1472
- var getTemplateCacheKey = (type, scopeName) => `${type}--${scopeName}`;
1473
- var compatibleShadyCSSVersion = true;
1474
- if (typeof window.ShadyCSS === "undefined") {
1475
- compatibleShadyCSSVersion = false;
1476
- } else if (typeof window.ShadyCSS.prepareTemplateDom === "undefined") {
1477
- console.warn(`Incompatible ShadyCSS version detected. Please update to at least @webcomponents/webcomponentsjs@2.0.2 and @webcomponents/shadycss@1.3.1.`);
1478
- compatibleShadyCSSVersion = false;
1479
- }
1480
- var shadyTemplateFactory = (scopeName) => (result) => {
1481
- const cacheKey = getTemplateCacheKey(result.type, scopeName);
1482
- let templateCache = templateCaches.get(cacheKey);
1483
- if (templateCache === void 0) {
1484
- templateCache = {
1485
- stringsArray: new WeakMap(),
1486
- keyString: new Map()
1212
+ parseParts(childNodes) {
1213
+ var _a, _b;
1214
+ const range = (_a = globalThis.document) == null ? void 0 : _a.createRange();
1215
+ range.setStartBefore(childNodes[0]);
1216
+ range.setEndAfter(childNodes[childNodes.length - 1]);
1217
+ const template = range.cloneContents();
1218
+ const treeWalker = (_b = globalThis.document) == null ? void 0 : _b.createTreeWalker(template, 128);
1219
+ let node = treeWalker.currentNode;
1220
+ const getParts = () => {
1221
+ const parts2 = [];
1222
+ let currentPart = void 0;
1223
+ while (node = treeWalker.nextNode()) {
1224
+ if (/^template-part$/.test(node.data) && currentPart) {
1225
+ currentPart.parts = getParts();
1226
+ }
1227
+ if (/^\/template-part$/.test(node.data)) {
1228
+ return parts2;
1229
+ }
1230
+ if (/^dom-part-\d+$/.test(node.data)) {
1231
+ parts2.push(currentPart = { type: "node", path: getNodePath(node), parts: [] });
1232
+ }
1233
+ if (/^dom-part-\d+:/.test(node.data)) {
1234
+ const [_, attribute2] = node.data.split(":");
1235
+ const [name, initialValue] = attribute2.split("=");
1236
+ currentPart = void 0;
1237
+ parts2.push({ type: "attribute", path: getNodePath(node), name, initialValue });
1238
+ }
1239
+ if (/^dom-part-\d+\$/.test(node.data)) {
1240
+ currentPart = void 0;
1241
+ parts2.push({ type: "directive", path: getNodePath(node) });
1242
+ }
1243
+ }
1244
+ return parts2;
1487
1245
  };
1488
- templateCaches.set(cacheKey, templateCache);
1489
- }
1490
- let template = templateCache.stringsArray.get(result.strings);
1491
- if (template !== void 0) {
1492
- return template;
1493
- }
1494
- const key = result.strings.join(marker);
1495
- template = templateCache.keyString.get(key);
1496
- if (template === void 0) {
1497
- const element = result.getTemplateElement();
1498
- if (compatibleShadyCSSVersion) {
1499
- window.ShadyCSS.prepareTemplateDom(element, scopeName);
1500
- }
1501
- template = new Template(result, element);
1502
- templateCache.keyString.set(key, template);
1246
+ const parts = getParts();
1247
+ if (parts.length !== this.strings.length - 1) {
1248
+ throw {
1249
+ name: "ParseTemplateError",
1250
+ message: "Could not parse parts from template correctly. Parts length has not the expected length. -> " + JSON.stringify({
1251
+ strings: this.strings,
1252
+ templateString: this.templateString,
1253
+ childNodes,
1254
+ template,
1255
+ parts
1256
+ })
1257
+ };
1258
+ }
1259
+ return parts;
1260
+ }
1261
+ get templateString() {
1262
+ return createTemplateString(this.strings);
1503
1263
  }
1504
- templateCache.stringsArray.set(result.strings, template);
1505
- return template;
1506
- };
1507
- var TEMPLATE_TYPES = ["html", "svg"];
1508
- var removeStylesFromLitTemplates = (scopeName) => {
1509
- TEMPLATE_TYPES.forEach((type) => {
1510
- const templates = templateCaches.get(getTemplateCacheKey(type, scopeName));
1511
- if (templates !== void 0) {
1512
- templates.keyString.forEach((template) => {
1513
- const {element: {content}} = template;
1514
- const styles = new Set();
1515
- Array.from(content.querySelectorAll("style")).forEach((s) => {
1516
- styles.add(s);
1517
- });
1518
- removeNodesFromTemplate(template, styles);
1519
- });
1264
+ toString() {
1265
+ let updates = parsedUpdates.get(this.strings);
1266
+ if (!updates) {
1267
+ updates = this.parse(this.strings);
1268
+ parsedUpdates.set(this.strings, updates);
1520
1269
  }
1521
- });
1522
- };
1523
- var shadyRenderSet = new Set();
1524
- var prepareTemplateStyles = (scopeName, renderedDOM, template) => {
1525
- shadyRenderSet.add(scopeName);
1526
- const templateElement = !!template ? template.element : document.createElement("template");
1527
- const styles = renderedDOM.querySelectorAll("style");
1528
- const {length} = styles;
1529
- if (length === 0) {
1530
- window.ShadyCSS.prepareTemplateStyles(templateElement, scopeName);
1531
- return;
1532
- }
1533
- const condensedStyle = document.createElement("style");
1534
- for (let i = 0; i < length; i++) {
1535
- const style2 = styles[i];
1536
- style2.parentNode.removeChild(style2);
1537
- condensedStyle.textContent += style2.textContent;
1538
- }
1539
- removeStylesFromLitTemplates(scopeName);
1540
- const content = templateElement.content;
1541
- if (!!template) {
1542
- insertNodeIntoTemplate(template, condensedStyle, content.firstChild);
1543
- } else {
1544
- content.insertBefore(condensedStyle, content.firstChild);
1545
- }
1546
- window.ShadyCSS.prepareTemplateStyles(templateElement, scopeName);
1547
- const style = content.querySelector("style");
1548
- if (window.ShadyCSS.nativeShadow && style !== null) {
1549
- renderedDOM.insertBefore(style.cloneNode(true), renderedDOM.firstChild);
1550
- } else if (!!template) {
1551
- content.insertBefore(condensedStyle, content.firstChild);
1552
- const removes = new Set();
1553
- removes.add(condensedStyle);
1554
- removeNodesFromTemplate(template, removes);
1270
+ return this.values.length ? this.values.map((value, index) => updates[index](value)).join("") : updates[0]();
1555
1271
  }
1556
1272
  };
1557
- var render2 = (result, container, options) => {
1558
- if (!options || typeof options !== "object" || !options.scopeName) {
1559
- throw new Error("The `scopeName` option is required.");
1560
- }
1561
- const scopeName = options.scopeName;
1562
- const hasRendered = parts.has(container);
1563
- const needsScoping = compatibleShadyCSSVersion && container.nodeType === 11 && !!container.host;
1564
- const firstScopeRender = needsScoping && !shadyRenderSet.has(scopeName);
1565
- const renderContainer = firstScopeRender ? document.createDocumentFragment() : container;
1566
- render(result, renderContainer, Object.assign({templateFactory: shadyTemplateFactory(scopeName)}, options));
1567
- if (firstScopeRender) {
1568
- const part = parts.get(renderContainer);
1569
- parts.delete(renderContainer);
1570
- const template = part.value instanceof TemplateInstance ? part.value.template : void 0;
1571
- prepareTemplateStyles(scopeName, renderContainer, template);
1572
- removeNodes(container, container.firstChild);
1573
- container.appendChild(renderContainer);
1574
- parts.set(container, part);
1575
- }
1576
- if (!hasRendered && needsScoping) {
1577
- window.ShadyCSS.styleElement(container.host);
1578
- }
1273
+
1274
+ // src/dom-parts/html.js
1275
+ var html = function(strings, ...values) {
1276
+ return new TemplateResult(strings, ...values);
1277
+ };
1278
+
1279
+ // src/dom-parts/render.js
1280
+ var render = (template, domNode) => {
1281
+ template.renderInto(domNode);
1579
1282
  };
1580
1283
 
1581
1284
  // src/TemplateElement.js
@@ -1593,7 +1296,7 @@ var TemplateElement = class extends StyledElement {
1593
1296
  });
1594
1297
  this._template = this._options.template;
1595
1298
  if (this._options.shadowRender)
1596
- this.attachShadow({mode: "open"});
1299
+ this.attachShadow({ mode: "open" });
1597
1300
  }
1598
1301
  template() {
1599
1302
  return html``;
@@ -1607,10 +1310,7 @@ var TemplateElement = class extends StyledElement {
1607
1310
  if (typeof template === "string") {
1608
1311
  this.getRoot().innerHTML = `${template}`;
1609
1312
  } else {
1610
- render2(html` ${template} `, this.getRoot(), {
1611
- scopeName: this.localName,
1612
- eventContext: this
1613
- });
1313
+ render(template, this.getRoot());
1614
1314
  }
1615
1315
  }
1616
1316
  getRoot() {