@webtides/element-js 0.7.4 → 1.0.0-alpha.10

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.
Files changed (51) hide show
  1. package/README.md +2 -2
  2. package/docs/README.md +174 -0
  3. package/docs/concepts/classes.md +167 -0
  4. package/docs/concepts/hierarchy.md +61 -0
  5. package/docs/concepts/lifecycle.md +45 -0
  6. package/docs/concepts/reactivity.md +14 -0
  7. package/docs/features/computed-properties.md +28 -0
  8. package/docs/features/dependency-injection-context-protocol.md +132 -0
  9. package/docs/features/events.md +155 -0
  10. package/docs/features/global-styles.md +131 -0
  11. package/docs/features/methods.md +34 -0
  12. package/docs/features/properties.md +56 -0
  13. package/docs/features/refs.md +47 -0
  14. package/docs/features/renderless.md +70 -0
  15. package/docs/features/store.md +143 -0
  16. package/docs/features/styles.md +169 -0
  17. package/docs/features/templates.md +308 -0
  18. package/docs/features/watch.md +54 -0
  19. package/docs/getting-started/upgrade-to-v1.md +243 -0
  20. package/docs/guide/guide.md +112 -0
  21. package/index.js +9 -2
  22. package/package.json +19 -27
  23. package/src/BaseElement.js +176 -86
  24. package/src/StyledElement.js +66 -55
  25. package/src/TemplateElement.js +34 -8
  26. package/src/dom-parts/AttributePart.js +167 -0
  27. package/src/dom-parts/ChildNodePart.js +329 -0
  28. package/src/dom-parts/NodePart.js +38 -0
  29. package/src/dom-parts/Part.js +12 -0
  30. package/src/dom-parts/TemplatePart.js +134 -0
  31. package/src/dom-parts/TemplateResult.js +342 -0
  32. package/src/dom-parts/directives.js +111 -0
  33. package/src/dom-parts/html.js +12 -0
  34. package/src/dom-parts/render.js +10 -0
  35. package/src/util/AttributeParser.js +62 -29
  36. package/src/util/DOMHelper.js +253 -5
  37. package/src/util/Directive.js +42 -0
  38. package/src/util/GlobalStylesStore.js +66 -0
  39. package/src/util/SerializeStateHelper.js +103 -0
  40. package/src/util/Store.js +92 -9
  41. package/src/util/defineElement.js +2 -2
  42. package/src/util/toString.js +2 -2
  43. package/CHANGELOG.md +0 -154
  44. package/dist/index.js +0 -1673
  45. package/dist/index.js.map +0 -7
  46. package/src/renderer/vanilla/TemplateElement.js +0 -50
  47. package/src/renderer/vanilla/index.js +0 -18
  48. package/src/renderer/vanilla/util/directives.js +0 -78
  49. package/src/renderer/vanilla/util/html.js +0 -65
  50. package/src/renderer/vanilla/util/render.js +0 -149
  51. package/src/util/i18n.js +0 -20
package/dist/index.js DELETED
@@ -1,1673 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- 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;
8
- };
9
-
10
- // src/util/AttributeParser.js
11
- function isObjectLike(value) {
12
- return typeof value == "object" && value !== null;
13
- }
14
- function isJSON(str) {
15
- try {
16
- return JSON.parse(str) && !!str;
17
- } catch (e) {
18
- return false;
19
- }
20
- }
21
- function isBoolean(value) {
22
- return value === "true" || value === "false";
23
- }
24
- function parseBoolean(value) {
25
- return value === "true";
26
- }
27
- function isString(value) {
28
- return typeof value === "string" || !!value && typeof value === "object" && Object.prototype.toString.call(value) === "[object String]";
29
- }
30
- function isNumber(value) {
31
- return new RegExp("^-?(0|0\\.\\d+|[1-9]\\d*(\\.\\d+)?)$").test(value);
32
- }
33
- function isNaN(value) {
34
- return Number.isNaN(value);
35
- }
36
- function deepEquals(valueA, valueB) {
37
- return JSON.stringify(valueA) === JSON.stringify(valueB);
38
- }
39
- function parseAttribute(value, options = {}) {
40
- if (options.parse === false || !isString(value)) {
41
- return value;
42
- }
43
- if (typeof options.parse === "function") {
44
- return options.parse(value);
45
- }
46
- let parsedValue = value;
47
- if (isJSON(value))
48
- parsedValue = JSON.parse(value);
49
- else if (isBoolean(value))
50
- parsedValue = parseBoolean(value);
51
- else if (isNumber(value))
52
- parsedValue = parseFloat(value);
53
- return parsedValue;
54
- }
55
- function dashToCamel(string) {
56
- if (string.indexOf("-") === -1)
57
- return string;
58
- return string.replace(/-[a-z]/g, (matches) => matches[1].toUpperCase());
59
- }
60
- function camelToDash(string) {
61
- return string.replace(/([A-Z])/g, "-$1").toLowerCase();
62
- }
63
-
64
- // src/util/DOMHelper.js
65
- function getShadowParentOrBody(element) {
66
- if (element instanceof ShadowRoot) {
67
- return element;
68
- }
69
- while (element.parentNode && (element = element.parentNode)) {
70
- if (element instanceof ShadowRoot) {
71
- return element;
72
- }
73
- }
74
- return document.body;
75
- }
76
- function getAllElementChildren(domNode, instanceOfFilter = HTMLElement) {
77
- const nodeIterator = document.createNodeIterator(domNode, NodeFilter.SHOW_ELEMENT, (node) => node.nodeName.includes("-") && node instanceof instanceOfFilter ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT);
78
- const customElements2 = [];
79
- let currentNode;
80
- while (currentNode = nodeIterator.nextNode()) {
81
- customElements2.push(currentNode);
82
- }
83
- return customElements2;
84
- }
85
- var supportsAdoptingStyleSheets = () => "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype;
86
- var supportsAppendingStyleSheets = !window.ShadyDOM;
87
-
88
- // src/util/Store.js
89
- var Store = class {
90
- constructor(value) {
91
- __publicField(this, "_observer", new Set());
92
- __publicField(this, "_singlePropertyMode", false);
93
- __publicField(this, "_state", {});
94
- this._singlePropertyMode = arguments.length > 0 && !isObjectLike(value);
95
- const specificValues = this._singlePropertyMode ? {value} : value;
96
- this._state = {...!this._singlePropertyMode && this.properties(), ...specificValues};
97
- Object.entries(this._state).map(([key, value2]) => {
98
- if (value2 instanceof Store) {
99
- value2.subscribe(this);
100
- }
101
- Object.defineProperty(this, key, {
102
- get: () => {
103
- return this._state[key];
104
- },
105
- set: (newValue) => {
106
- const oldValue = this._state[key];
107
- this._state[key] = newValue;
108
- if (value2 instanceof Store) {
109
- value2.subscribe(this);
110
- }
111
- if (!deepEquals(newValue, oldValue)) {
112
- const watch = this.watch();
113
- if (watch.hasOwnProperty(key) && typeof watch[key] === "function") {
114
- watch[key](newValue, oldValue);
115
- }
116
- this.requestUpdate();
117
- }
118
- }
119
- });
120
- });
121
- }
122
- properties() {
123
- return {};
124
- }
125
- watch() {
126
- return {};
127
- }
128
- valueOf() {
129
- return this._singlePropertyMode ? this._state.value : this._state;
130
- }
131
- toString() {
132
- return `${this._singlePropertyMode ? this._state.value : this._state}`;
133
- }
134
- subscribe(observer) {
135
- this._observer.add(observer);
136
- }
137
- unsubscribe(observer) {
138
- this._observer.delete(observer);
139
- }
140
- requestUpdate() {
141
- this._observer.forEach(async (observer) => {
142
- var _a, _b, _c;
143
- if (observer instanceof BaseElement || observer instanceof Store) {
144
- if (((_a = observer == null ? void 0 : observer._options) == null ? void 0 : _a.autoUpdate) !== false) {
145
- await observer.requestUpdate();
146
- }
147
- if (Object.keys((_b = observer.watch()) != null ? _b : {}).length > 0) {
148
- Object.keys((_c = observer.watch()) != null ? _c : {}).forEach((key) => {
149
- var _a2;
150
- if (observer._state[key] === this) {
151
- if (observer instanceof Store) {
152
- (_a2 = observer.watch) == null ? void 0 : _a2.call(observer)[key](this, this);
153
- } else {
154
- observer.callPropertyWatcher(key, this, this);
155
- observer.notifyPropertyChange(key, this);
156
- }
157
- }
158
- });
159
- }
160
- } else if (typeof observer === "function") {
161
- observer();
162
- } else {
163
- console.error("Store: observer type is not supported.", observer);
164
- }
165
- });
166
- }
167
- };
168
-
169
- // src/util/defineElement.js
170
- function defineElement(name, constructor) {
171
- try {
172
- customElements.define(name, constructor);
173
- } catch (e) {
174
- }
175
- }
176
-
177
- // src/util/toString.js
178
- function toString(value) {
179
- try {
180
- return JSON.stringify(value);
181
- } catch (e) {
182
- return "";
183
- }
184
- }
185
-
186
- // src/BaseElement.js
187
- var BaseElement = class extends HTMLElement {
188
- constructor(options = {}) {
189
- super();
190
- this.$refs = {};
191
- this._state = {};
192
- this._mutationObserver = null;
193
- this._registeredEvents = [];
194
- this._batchUpdate = null;
195
- this._requestedUpdates = [];
196
- this._options = {
197
- autoUpdate: true,
198
- deferUpdate: true,
199
- deferConnected: false,
200
- mutationObserverOptions: {
201
- attributes: true,
202
- childList: true,
203
- subtree: false,
204
- ...options.mutationObserverOptions
205
- },
206
- propertyOptions: {},
207
- ...options
208
- };
209
- if (this.hasAttribute("defer-update")) {
210
- this._options.deferUpdate = true;
211
- }
212
- if (this.hasAttribute("defer-connected")) {
213
- this._options.deferConnected = true;
214
- }
215
- if (options.childListUpdate !== void 0 && options.childListUpdate !== null) {
216
- this._options.mutationObserverOptions.childList = options.childListUpdate;
217
- 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`);
218
- }
219
- }
220
- connectedCallback() {
221
- if (this._options.deferConnected) {
222
- this._options.deferConnected = false;
223
- return;
224
- }
225
- this.defineAttributesAsProperties();
226
- this.defineProperties();
227
- this.defineComputedProperties();
228
- this.definePropertyInjection();
229
- this.defineObserver();
230
- if (this._options.deferUpdate) {
231
- this.registerEventsAndRefs();
232
- this.triggerHook("connected");
233
- } else {
234
- this.requestUpdate({notify: false}).then(() => {
235
- this.triggerHook("connected");
236
- });
237
- }
238
- }
239
- defineObserver() {
240
- this._mutationObserver = new MutationObserver((mutations) => {
241
- mutations.forEach((mutation) => {
242
- if (mutation.type === "attributes" && mutation.target === this && this._state.hasOwnProperty(dashToCamel(mutation.attributeName))) {
243
- this[dashToCamel(mutation.attributeName)] = parseAttribute(this.getAttribute(mutation.attributeName), this._options.propertyOptions[dashToCamel(mutation.attributeName)]);
244
- }
245
- if (mutation.type === "attributes" && mutation.target !== this) {
246
- this.requestUpdate();
247
- }
248
- if (mutation.type === "childList") {
249
- this.requestUpdate();
250
- }
251
- });
252
- });
253
- this._mutationObserver.observe(this, {
254
- attributes: true,
255
- childList: true,
256
- subtree: false,
257
- ...this._options.mutationObserverOptions
258
- });
259
- }
260
- disconnectedCallback() {
261
- this.removeEvents();
262
- if (Object.keys(this.provideProperties()).length > 0) {
263
- this.removeEventListener("request-context", this.onRequestContext);
264
- }
265
- if (this._mutationObserver)
266
- this._mutationObserver.disconnect();
267
- Object.values(this.properties()).forEach((property) => {
268
- if (property instanceof Store) {
269
- property.unsubscribe(this);
270
- }
271
- });
272
- this.triggerHook("disconnected");
273
- }
274
- requestUpdate(options = {notify: true}) {
275
- if (options.notify === true) {
276
- this.triggerHook("beforeUpdate");
277
- }
278
- if (this._batchUpdate) {
279
- cancelAnimationFrame(this._batchUpdate);
280
- this._batchUpdate = false;
281
- }
282
- return new Promise((resolve, reject) => {
283
- this._requestedUpdates.push({resolve, reject});
284
- this._batchUpdate = requestAnimationFrame(() => {
285
- try {
286
- this.update(options);
287
- this._requestedUpdates.forEach(({resolve: resolve2, reject: reject2}) => resolve2());
288
- } catch (e) {
289
- this._requestedUpdates.forEach(({resolve: resolve2, reject: reject2}) => reject2(e));
290
- }
291
- this._requestedUpdates = [];
292
- });
293
- });
294
- }
295
- update(options = {notify: true}) {
296
- this.registerEventsAndRefs();
297
- if (options.notify === true) {
298
- this.triggerHook("afterUpdate");
299
- }
300
- }
301
- registerEventsAndRefs() {
302
- this.registerEvents();
303
- this.registerRefs();
304
- }
305
- defineAttributesAsProperties() {
306
- const ignoreAttributes = ["class", "style"];
307
- Array.from(this.attributes).filter((attribute) => {
308
- return !ignoreAttributes.includes(attribute.name);
309
- }).forEach((attribute) => {
310
- const name = dashToCamel(attribute.name);
311
- const parseOptions = this._options.propertyOptions[name];
312
- this.defineProperty(name, parseAttribute(attribute.value, parseOptions), true);
313
- });
314
- }
315
- properties() {
316
- return {};
317
- }
318
- defineProperties() {
319
- Object.keys({...this.injectProperties(), ...this.properties()}).forEach((prop) => {
320
- const value = this[prop] || this.properties()[prop];
321
- this.defineProperty(prop, value);
322
- });
323
- }
324
- defineProperty(property, value, reflectAttribute = false) {
325
- var _a, _b;
326
- if (value instanceof Store) {
327
- value.subscribe(this);
328
- }
329
- if (this._state.hasOwnProperty(property)) {
330
- return;
331
- }
332
- if (!reflectAttribute && ((_a = this._options.propertyOptions[property]) == null ? void 0 : _a.reflect)) {
333
- this.reflectProperty({property, newValue: value});
334
- }
335
- if (((_b = this._options.propertyOptions[property]) == null ? void 0 : _b.reflect) === false) {
336
- this.removeAttribute(camelToDash(property));
337
- }
338
- this._state[property] = value;
339
- Object.defineProperty(this, property, {
340
- get: () => {
341
- return this._state[property];
342
- },
343
- set: (newValue) => {
344
- var _a2;
345
- const oldValue = this._state[property];
346
- const newValueString = JSON.stringify(newValue);
347
- if (JSON.stringify(oldValue) !== newValueString) {
348
- this._state[property] = newValue;
349
- if (newValue instanceof Store) {
350
- newValue.subscribe(this);
351
- }
352
- if (reflectAttribute || ((_a2 = this._options.propertyOptions[property]) == null ? void 0 : _a2.reflect)) {
353
- this.reflectProperty({property, newValue, newValueString});
354
- }
355
- if (this._options.autoUpdate) {
356
- this.requestUpdate({
357
- notify: true,
358
- property,
359
- newValue,
360
- newValueString,
361
- oldValue
362
- }).finally(() => {
363
- this.callPropertyWatcher(property, newValue, oldValue);
364
- this.notifyPropertyChange(property, newValue);
365
- });
366
- } else {
367
- this.callPropertyWatcher(property, newValue, oldValue);
368
- this.notifyPropertyChange(property, newValue);
369
- }
370
- }
371
- return this;
372
- }
373
- });
374
- }
375
- callPropertyWatcher(property, newValue, oldValue) {
376
- const watch = this.watch();
377
- if (property in watch) {
378
- watch[property](newValue, oldValue);
379
- }
380
- }
381
- notifyPropertyChange(property, newValue) {
382
- if (property in this._options["propertyOptions"] && this._options["propertyOptions"][property]["notify"] === true) {
383
- this.dispatch(`${camelToDash(property)}-changed`, newValue, true);
384
- }
385
- }
386
- reflectProperty(options) {
387
- var _a;
388
- const {property, newValue} = options;
389
- const newValueString = options.newValueString || JSON.stringify(newValue);
390
- if (newValue === void 0 || newValue === null || isNaN(newValue)) {
391
- this.setAttribute(camelToDash(property), "");
392
- } else {
393
- let attributeValue = isObjectLike(newValue) ? newValueString : newValue;
394
- if (typeof ((_a = this._options.propertyOptions[property]) == null ? void 0 : _a.reflect) === "function") {
395
- attributeValue = this._options.propertyOptions[property].reflect(newValue);
396
- }
397
- this.setAttribute(camelToDash(property), attributeValue);
398
- }
399
- }
400
- injectProperties() {
401
- return {};
402
- }
403
- provideProperties() {
404
- return {};
405
- }
406
- definePropertyInjection() {
407
- Object.entries(this.injectProperties()).forEach(([key, value]) => {
408
- this.requestContext(key, value);
409
- });
410
- const providedKeys = Object.keys(this.provideProperties());
411
- if (providedKeys.length > 0) {
412
- this.addEventListener("request-context", this.onRequestContext);
413
- getAllElementChildren(this.getRoot(), BaseElement).forEach((customChild) => {
414
- var _a, _b;
415
- const requestedProperties = (_b = (_a = customChild.injectProperties) == null ? void 0 : _a.call(customChild)) != null ? _b : {};
416
- Object.entries(requestedProperties).forEach(([key, value]) => {
417
- if (providedKeys.includes(key)) {
418
- customChild.requestContext(key, value);
419
- }
420
- });
421
- });
422
- }
423
- }
424
- requestContext(propertyName, valueOrCallback) {
425
- this.dispatch("request-context", {[propertyName]: valueOrCallback}, true, true, true);
426
- }
427
- onRequestContext(event) {
428
- var _a;
429
- const provideProperties = this.provideProperties();
430
- Object.entries((_a = event.detail) != null ? _a : {}).forEach(([key, valueOrCallback]) => {
431
- if (key in provideProperties) {
432
- const providedValue = provideProperties[key];
433
- event.stopPropagation();
434
- if (typeof valueOrCallback === "function") {
435
- valueOrCallback(providedValue);
436
- } else {
437
- const eventPath = event.composedPath();
438
- const target = eventPath[0] || event.target;
439
- target[key] = providedValue;
440
- }
441
- }
442
- });
443
- }
444
- hooks() {
445
- return {};
446
- }
447
- connected() {
448
- }
449
- beforeUpdate() {
450
- }
451
- afterUpdate() {
452
- }
453
- disconnected() {
454
- }
455
- triggerHook(name) {
456
- if (this.hooks && name in this.hooks()) {
457
- 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`);
458
- this.hooks()[name]();
459
- return;
460
- }
461
- if (name in this) {
462
- this[name]();
463
- }
464
- }
465
- watch() {
466
- return {};
467
- }
468
- computed() {
469
- return {};
470
- }
471
- defineComputedProperties() {
472
- Object.keys(this.computed()).forEach((prop) => {
473
- if (!this.hasOwnProperty(prop)) {
474
- 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`);
475
- Object.defineProperty(this, prop, {
476
- get: () => this.computed()[prop]()
477
- });
478
- }
479
- });
480
- }
481
- events() {
482
- return {};
483
- }
484
- registerEvents() {
485
- this.removeEvents();
486
- const eventDefinitions = this.events();
487
- Object.keys(eventDefinitions).forEach((elementSelector) => {
488
- const events = eventDefinitions[elementSelector];
489
- const selectorWhiteList = {window, document, this: this.getRoot()};
490
- const whiteListElement = selectorWhiteList[elementSelector];
491
- const eventTargets = whiteListElement ? [whiteListElement] : this.getRoot().querySelectorAll(elementSelector);
492
- eventTargets.forEach((eventTarget) => {
493
- Object.keys(events).forEach((eventName) => {
494
- var _a;
495
- const notation = events[eventName];
496
- if (typeof notation === "function") {
497
- const callback = notation.bind(this);
498
- eventTarget.addEventListener(eventName, callback);
499
- this._registeredEvents.push({eventTarget, eventName, callback});
500
- } else if (typeof notation === "object" && typeof notation.listener === "function") {
501
- const callback = notation.listener.bind(this);
502
- eventTarget.addEventListener(eventName, callback, (_a = notation.options) != null ? _a : {});
503
- this._registeredEvents.push({eventTarget, eventName, callback});
504
- }
505
- });
506
- });
507
- });
508
- }
509
- removeEvents() {
510
- this._registeredEvents.forEach(({eventTarget, eventName, callback}) => {
511
- if (eventTarget === window || eventTarget === document || this.getRoot().contains(eventTarget)) {
512
- eventTarget.removeEventListener(eventName, callback);
513
- }
514
- });
515
- this._registeredEvents = [];
516
- }
517
- registerRefs() {
518
- const refsNodeList = this.getRoot().querySelectorAll("[ref]");
519
- const refsArray = Array.from(refsNodeList);
520
- const refsMap = {};
521
- refsArray.forEach((refNode) => {
522
- const refKey = refNode.getAttribute("ref");
523
- const isListKey = refKey.endsWith("[]");
524
- const cleanKey = isListKey ? refKey.slice(0, -2) : refKey;
525
- const hasListRef = Array.isArray(refsMap[cleanKey]);
526
- if (isListKey) {
527
- if (!refsMap[cleanKey] || !hasListRef) {
528
- refsMap[cleanKey] = [];
529
- }
530
- refsMap[cleanKey].push(refNode);
531
- } else if (!hasListRef) {
532
- refsMap[refKey] = refNode;
533
- } else {
534
- console.warn(`Did not register singular ref ${refKey}, ${refNode} as a ref list is already registered under the same name.`);
535
- }
536
- });
537
- this.$refs = refsMap;
538
- }
539
- dispatch(name, data, bubble = false, cancelable = false, composed = false) {
540
- const event = new CustomEvent(name, {
541
- bubbles: bubble,
542
- cancelable,
543
- composed,
544
- detail: data
545
- });
546
- this.dispatchEvent(event);
547
- }
548
- getRoot() {
549
- return this;
550
- }
551
- };
552
-
553
- // src/util/i18n.js
554
- function i18n(key, fallback) {
555
- try {
556
- const translations = window.elementjs.i18n();
557
- if (translations[key] === void 0) {
558
- throw "Translation Missing";
559
- }
560
- return translations[key];
561
- } catch (err) {
562
- if (fallback)
563
- return fallback;
564
- else
565
- return key;
566
- }
567
- }
568
-
569
- // src/StyledElement.js
570
- var _StyledElement = class extends BaseElement {
571
- static updateGlobalStyles() {
572
- _StyledElement.globalStyles = document.getElementById("globalStyles");
573
- if (_StyledElement.globalStyles && _StyledElement["globalStyleSheet"]) {
574
- _StyledElement["globalStyleSheet"].replaceSync(_StyledElement.globalStyles.textContent);
575
- }
576
- }
577
- constructor(options) {
578
- super({
579
- deferUpdate: false,
580
- shadowRender: false,
581
- styles: [],
582
- adoptGlobalStyles: true,
583
- ...options
584
- });
585
- this._styles = [...this._options.styles, ...this.styles()];
586
- }
587
- connectedCallback() {
588
- super.connectedCallback();
589
- if (supportsAdoptingStyleSheets() && this._options.shadowRender) {
590
- this.adoptStyleSheets();
591
- } else if (this._options.shadowRender && window.ShadyCSS !== void 0) {
592
- window.ShadyCSS.ScopingShim.prepareAdoptedCssText(this._styles, this.localName);
593
- }
594
- if (window.ShadyCSS !== void 0) {
595
- window.ShadyCSS.styleElement(this);
596
- }
597
- }
598
- styles() {
599
- return [];
600
- }
601
- update(options) {
602
- var _a, _b;
603
- if (!supportsAdoptingStyleSheets() || this._options.shadowRender === false) {
604
- const appendableStyles = [...this._styles];
605
- if (this._options.shadowRender && this._options.adoptGlobalStyles && !window.ShadyCSS) {
606
- appendableStyles.unshift((_b = (_a = _StyledElement.globalStyles) == null ? void 0 : _a.textContent) != null ? _b : "");
607
- }
608
- this.appendStyleSheets(appendableStyles);
609
- }
610
- super.update(options);
611
- }
612
- adoptStyleSheets() {
613
- if (!this.constructor["cssStyleSheets"]) {
614
- this.constructor["cssStyleSheets"] = this._styles.map((style) => {
615
- const sheet = new CSSStyleSheet();
616
- if (sheet && sheet.cssRules.length === 0) {
617
- sheet.replaceSync(style);
618
- }
619
- return sheet;
620
- });
621
- }
622
- if (_StyledElement.globalStyles && !_StyledElement["globalStyleSheet"]) {
623
- _StyledElement["globalStyleSheet"] = new CSSStyleSheet();
624
- _StyledElement["globalStyleSheet"].replaceSync(_StyledElement.globalStyles.textContent);
625
- }
626
- this.getRoot().adoptedStyleSheets = [
627
- ...this._options.shadowRender && this._options.adoptGlobalStyles && _StyledElement["globalStyleSheet"] ? [_StyledElement["globalStyleSheet"]] : [],
628
- ...this.constructor["cssStyleSheets"]
629
- ];
630
- }
631
- appendStyleSheets(styles) {
632
- const parentDocument = getShadowParentOrBody(this.getRoot());
633
- styles.forEach((style, index) => {
634
- const identifier = this.tagName + index;
635
- if (!parentDocument.querySelector(`#${identifier}`)) {
636
- const styleElement = document.createElement("style");
637
- styleElement.id = identifier;
638
- styleElement.style.display = "none";
639
- styleElement.textContent = style;
640
- parentDocument.appendChild(styleElement);
641
- }
642
- });
643
- }
644
- };
645
- var StyledElement = _StyledElement;
646
- __publicField(StyledElement, "globalStyles", null);
647
- StyledElement.updateGlobalStyles();
648
-
649
- // node_modules/lit-html/lib/directive.js
650
- /**
651
- * @license
652
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
653
- * This code may only be used under the BSD style license found at
654
- * http://polymer.github.io/LICENSE.txt
655
- * The complete set of authors may be found at
656
- * http://polymer.github.io/AUTHORS.txt
657
- * The complete set of contributors may be found at
658
- * http://polymer.github.io/CONTRIBUTORS.txt
659
- * Code distributed by Google as part of the polymer project is also
660
- * subject to an additional IP rights grant found at
661
- * http://polymer.github.io/PATENTS.txt
662
- */
663
- var directives = new WeakMap();
664
- var isDirective = (o) => {
665
- return typeof o === "function" && directives.has(o);
666
- };
667
-
668
- // node_modules/lit-html/lib/dom.js
669
- /**
670
- * @license
671
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
672
- * This code may only be used under the BSD style license found at
673
- * http://polymer.github.io/LICENSE.txt
674
- * The complete set of authors may be found at
675
- * http://polymer.github.io/AUTHORS.txt
676
- * The complete set of contributors may be found at
677
- * http://polymer.github.io/CONTRIBUTORS.txt
678
- * Code distributed by Google as part of the polymer project is also
679
- * subject to an additional IP rights grant found at
680
- * http://polymer.github.io/PATENTS.txt
681
- */
682
- var isCEPolyfill = typeof window !== "undefined" && window.customElements != null && window.customElements.polyfillWrapFlushCallback !== void 0;
683
- var removeNodes = (container, start, end = null) => {
684
- while (start !== end) {
685
- const n = start.nextSibling;
686
- container.removeChild(start);
687
- start = n;
688
- }
689
- };
690
-
691
- // node_modules/lit-html/lib/part.js
692
- /**
693
- * @license
694
- * Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
695
- * This code may only be used under the BSD style license found at
696
- * http://polymer.github.io/LICENSE.txt
697
- * The complete set of authors may be found at
698
- * http://polymer.github.io/AUTHORS.txt
699
- * The complete set of contributors may be found at
700
- * http://polymer.github.io/CONTRIBUTORS.txt
701
- * Code distributed by Google as part of the polymer project is also
702
- * subject to an additional IP rights grant found at
703
- * http://polymer.github.io/PATENTS.txt
704
- */
705
- var noChange = {};
706
- var nothing = {};
707
-
708
- // node_modules/lit-html/lib/template.js
709
- /**
710
- * @license
711
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
712
- * This code may only be used under the BSD style license found at
713
- * http://polymer.github.io/LICENSE.txt
714
- * The complete set of authors may be found at
715
- * http://polymer.github.io/AUTHORS.txt
716
- * The complete set of contributors may be found at
717
- * http://polymer.github.io/CONTRIBUTORS.txt
718
- * Code distributed by Google as part of the polymer project is also
719
- * subject to an additional IP rights grant found at
720
- * http://polymer.github.io/PATENTS.txt
721
- */
722
- var marker = `{{lit-${String(Math.random()).slice(2)}}}`;
723
- var nodeMarker = `<!--${marker}-->`;
724
- var markerRegex = new RegExp(`${marker}|${nodeMarker}`);
725
- var boundAttributeSuffix = "$lit$";
726
- var Template = class {
727
- constructor(result, element) {
728
- this.parts = [];
729
- this.element = element;
730
- const nodesToRemove = [];
731
- const stack = [];
732
- const walker = document.createTreeWalker(element.content, 133, null, false);
733
- let lastPartIndex = 0;
734
- let index = -1;
735
- let partIndex = 0;
736
- const {strings, values: {length}} = result;
737
- while (partIndex < length) {
738
- const node = walker.nextNode();
739
- if (node === null) {
740
- walker.currentNode = stack.pop();
741
- continue;
742
- }
743
- index++;
744
- if (node.nodeType === 1) {
745
- if (node.hasAttributes()) {
746
- const attributes = node.attributes;
747
- const {length: length2} = attributes;
748
- let count = 0;
749
- for (let i = 0; i < length2; i++) {
750
- if (endsWith(attributes[i].name, boundAttributeSuffix)) {
751
- count++;
752
- }
753
- }
754
- while (count-- > 0) {
755
- const stringForPart = strings[partIndex];
756
- const name = lastAttributeNameRegex.exec(stringForPart)[2];
757
- const attributeLookupName = name.toLowerCase() + boundAttributeSuffix;
758
- const attributeValue = node.getAttribute(attributeLookupName);
759
- node.removeAttribute(attributeLookupName);
760
- const statics = attributeValue.split(markerRegex);
761
- this.parts.push({type: "attribute", index, name, strings: statics});
762
- partIndex += statics.length - 1;
763
- }
764
- }
765
- if (node.tagName === "TEMPLATE") {
766
- stack.push(node);
767
- walker.currentNode = node.content;
768
- }
769
- } else if (node.nodeType === 3) {
770
- const data = node.data;
771
- if (data.indexOf(marker) >= 0) {
772
- const parent = node.parentNode;
773
- const strings2 = data.split(markerRegex);
774
- const lastIndex = strings2.length - 1;
775
- for (let i = 0; i < lastIndex; i++) {
776
- let insert;
777
- let s = strings2[i];
778
- if (s === "") {
779
- insert = createMarker();
780
- } else {
781
- const match = lastAttributeNameRegex.exec(s);
782
- if (match !== null && endsWith(match[2], boundAttributeSuffix)) {
783
- s = s.slice(0, match.index) + match[1] + match[2].slice(0, -boundAttributeSuffix.length) + match[3];
784
- }
785
- insert = document.createTextNode(s);
786
- }
787
- parent.insertBefore(insert, node);
788
- this.parts.push({type: "node", index: ++index});
789
- }
790
- if (strings2[lastIndex] === "") {
791
- parent.insertBefore(createMarker(), node);
792
- nodesToRemove.push(node);
793
- } else {
794
- node.data = strings2[lastIndex];
795
- }
796
- partIndex += lastIndex;
797
- }
798
- } else if (node.nodeType === 8) {
799
- if (node.data === marker) {
800
- const parent = node.parentNode;
801
- if (node.previousSibling === null || index === lastPartIndex) {
802
- index++;
803
- parent.insertBefore(createMarker(), node);
804
- }
805
- lastPartIndex = index;
806
- this.parts.push({type: "node", index});
807
- if (node.nextSibling === null) {
808
- node.data = "";
809
- } else {
810
- nodesToRemove.push(node);
811
- index--;
812
- }
813
- partIndex++;
814
- } else {
815
- let i = -1;
816
- while ((i = node.data.indexOf(marker, i + 1)) !== -1) {
817
- this.parts.push({type: "node", index: -1});
818
- partIndex++;
819
- }
820
- }
821
- }
822
- }
823
- for (const n of nodesToRemove) {
824
- n.parentNode.removeChild(n);
825
- }
826
- }
827
- };
828
- var endsWith = (str, suffix) => {
829
- const index = str.length - suffix.length;
830
- return index >= 0 && str.slice(index) === suffix;
831
- };
832
- var isTemplatePartActive = (part) => part.index !== -1;
833
- var createMarker = () => document.createComment("");
834
- var lastAttributeNameRegex = /([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F "'>=/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/;
835
-
836
- // node_modules/lit-html/lib/template-instance.js
837
- /**
838
- * @license
839
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
840
- * This code may only be used under the BSD style license found at
841
- * http://polymer.github.io/LICENSE.txt
842
- * The complete set of authors may be found at
843
- * http://polymer.github.io/AUTHORS.txt
844
- * The complete set of contributors may be found at
845
- * http://polymer.github.io/CONTRIBUTORS.txt
846
- * Code distributed by Google as part of the polymer project is also
847
- * subject to an additional IP rights grant found at
848
- * http://polymer.github.io/PATENTS.txt
849
- */
850
- var TemplateInstance = class {
851
- constructor(template, processor, options) {
852
- this.__parts = [];
853
- this.template = template;
854
- this.processor = processor;
855
- this.options = options;
856
- }
857
- update(values) {
858
- let i = 0;
859
- for (const part of this.__parts) {
860
- if (part !== void 0) {
861
- part.setValue(values[i]);
862
- }
863
- i++;
864
- }
865
- for (const part of this.__parts) {
866
- if (part !== void 0) {
867
- part.commit();
868
- }
869
- }
870
- }
871
- _clone() {
872
- const fragment = isCEPolyfill ? this.template.element.content.cloneNode(true) : document.importNode(this.template.element.content, true);
873
- const stack = [];
874
- const parts2 = this.template.parts;
875
- const walker = document.createTreeWalker(fragment, 133, null, false);
876
- let partIndex = 0;
877
- let nodeIndex = 0;
878
- let part;
879
- let node = walker.nextNode();
880
- while (partIndex < parts2.length) {
881
- part = parts2[partIndex];
882
- if (!isTemplatePartActive(part)) {
883
- this.__parts.push(void 0);
884
- partIndex++;
885
- continue;
886
- }
887
- while (nodeIndex < part.index) {
888
- nodeIndex++;
889
- if (node.nodeName === "TEMPLATE") {
890
- stack.push(node);
891
- walker.currentNode = node.content;
892
- }
893
- if ((node = walker.nextNode()) === null) {
894
- walker.currentNode = stack.pop();
895
- node = walker.nextNode();
896
- }
897
- }
898
- if (part.type === "node") {
899
- const part2 = this.processor.handleTextExpression(this.options);
900
- part2.insertAfterNode(node.previousSibling);
901
- this.__parts.push(part2);
902
- } else {
903
- this.__parts.push(...this.processor.handleAttributeExpressions(node, part.name, part.strings, this.options));
904
- }
905
- partIndex++;
906
- }
907
- if (isCEPolyfill) {
908
- document.adoptNode(fragment);
909
- customElements.upgrade(fragment);
910
- }
911
- return fragment;
912
- }
913
- };
914
-
915
- // node_modules/lit-html/lib/template-result.js
916
- /**
917
- * @license
918
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
919
- * This code may only be used under the BSD style license found at
920
- * http://polymer.github.io/LICENSE.txt
921
- * The complete set of authors may be found at
922
- * http://polymer.github.io/AUTHORS.txt
923
- * The complete set of contributors may be found at
924
- * http://polymer.github.io/CONTRIBUTORS.txt
925
- * Code distributed by Google as part of the polymer project is also
926
- * subject to an additional IP rights grant found at
927
- * http://polymer.github.io/PATENTS.txt
928
- */
929
- var commentMarker = ` ${marker} `;
930
- var TemplateResult = class {
931
- constructor(strings, values, type, processor) {
932
- this.strings = strings;
933
- this.values = values;
934
- this.type = type;
935
- this.processor = processor;
936
- }
937
- getHTML() {
938
- const l = this.strings.length - 1;
939
- let html2 = "";
940
- let isCommentBinding = false;
941
- for (let i = 0; i < l; i++) {
942
- const s = this.strings[i];
943
- const commentOpen = s.lastIndexOf("<!--");
944
- isCommentBinding = (commentOpen > -1 || isCommentBinding) && s.indexOf("-->", commentOpen + 1) === -1;
945
- const attributeMatch = lastAttributeNameRegex.exec(s);
946
- if (attributeMatch === null) {
947
- html2 += s + (isCommentBinding ? commentMarker : nodeMarker);
948
- } else {
949
- html2 += s.substr(0, attributeMatch.index) + attributeMatch[1] + attributeMatch[2] + boundAttributeSuffix + attributeMatch[3] + marker;
950
- }
951
- }
952
- html2 += this.strings[l];
953
- return html2;
954
- }
955
- getTemplateElement() {
956
- const template = document.createElement("template");
957
- template.innerHTML = this.getHTML();
958
- return template;
959
- }
960
- };
961
-
962
- // node_modules/lit-html/lib/parts.js
963
- /**
964
- * @license
965
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
966
- * This code may only be used under the BSD style license found at
967
- * http://polymer.github.io/LICENSE.txt
968
- * The complete set of authors may be found at
969
- * http://polymer.github.io/AUTHORS.txt
970
- * The complete set of contributors may be found at
971
- * http://polymer.github.io/CONTRIBUTORS.txt
972
- * Code distributed by Google as part of the polymer project is also
973
- * subject to an additional IP rights grant found at
974
- * http://polymer.github.io/PATENTS.txt
975
- */
976
- var isPrimitive = (value) => {
977
- return value === null || !(typeof value === "object" || typeof value === "function");
978
- };
979
- var isIterable = (value) => {
980
- return Array.isArray(value) || !!(value && value[Symbol.iterator]);
981
- };
982
- var AttributeCommitter = class {
983
- constructor(element, name, strings) {
984
- this.dirty = true;
985
- this.element = element;
986
- this.name = name;
987
- this.strings = strings;
988
- this.parts = [];
989
- for (let i = 0; i < strings.length - 1; i++) {
990
- this.parts[i] = this._createPart();
991
- }
992
- }
993
- _createPart() {
994
- return new AttributePart(this);
995
- }
996
- _getValue() {
997
- const strings = this.strings;
998
- const l = strings.length - 1;
999
- let text = "";
1000
- for (let i = 0; i < l; i++) {
1001
- text += strings[i];
1002
- const part = this.parts[i];
1003
- if (part !== void 0) {
1004
- const v = part.value;
1005
- if (isPrimitive(v) || !isIterable(v)) {
1006
- text += typeof v === "string" ? v : String(v);
1007
- } else {
1008
- for (const t of v) {
1009
- text += typeof t === "string" ? t : String(t);
1010
- }
1011
- }
1012
- }
1013
- }
1014
- text += strings[l];
1015
- return text;
1016
- }
1017
- commit() {
1018
- if (this.dirty) {
1019
- this.dirty = false;
1020
- this.element.setAttribute(this.name, this._getValue());
1021
- }
1022
- }
1023
- };
1024
- var AttributePart = class {
1025
- constructor(committer) {
1026
- this.value = void 0;
1027
- this.committer = committer;
1028
- }
1029
- setValue(value) {
1030
- if (value !== noChange && (!isPrimitive(value) || value !== this.value)) {
1031
- this.value = value;
1032
- if (!isDirective(value)) {
1033
- this.committer.dirty = true;
1034
- }
1035
- }
1036
- }
1037
- commit() {
1038
- while (isDirective(this.value)) {
1039
- const directive2 = this.value;
1040
- this.value = noChange;
1041
- directive2(this);
1042
- }
1043
- if (this.value === noChange) {
1044
- return;
1045
- }
1046
- this.committer.commit();
1047
- }
1048
- };
1049
- var NodePart = class {
1050
- constructor(options) {
1051
- this.value = void 0;
1052
- this.__pendingValue = void 0;
1053
- this.options = options;
1054
- }
1055
- appendInto(container) {
1056
- this.startNode = container.appendChild(createMarker());
1057
- this.endNode = container.appendChild(createMarker());
1058
- }
1059
- insertAfterNode(ref) {
1060
- this.startNode = ref;
1061
- this.endNode = ref.nextSibling;
1062
- }
1063
- appendIntoPart(part) {
1064
- part.__insert(this.startNode = createMarker());
1065
- part.__insert(this.endNode = createMarker());
1066
- }
1067
- insertAfterPart(ref) {
1068
- ref.__insert(this.startNode = createMarker());
1069
- this.endNode = ref.endNode;
1070
- ref.endNode = this.startNode;
1071
- }
1072
- setValue(value) {
1073
- this.__pendingValue = value;
1074
- }
1075
- commit() {
1076
- if (this.startNode.parentNode === null) {
1077
- return;
1078
- }
1079
- while (isDirective(this.__pendingValue)) {
1080
- const directive2 = this.__pendingValue;
1081
- this.__pendingValue = noChange;
1082
- directive2(this);
1083
- }
1084
- const value = this.__pendingValue;
1085
- if (value === noChange) {
1086
- return;
1087
- }
1088
- if (isPrimitive(value)) {
1089
- if (value !== this.value) {
1090
- this.__commitText(value);
1091
- }
1092
- } else if (value instanceof TemplateResult) {
1093
- this.__commitTemplateResult(value);
1094
- } else if (value instanceof Node) {
1095
- this.__commitNode(value);
1096
- } else if (isIterable(value)) {
1097
- this.__commitIterable(value);
1098
- } else if (value === nothing) {
1099
- this.value = nothing;
1100
- this.clear();
1101
- } else {
1102
- this.__commitText(value);
1103
- }
1104
- }
1105
- __insert(node) {
1106
- this.endNode.parentNode.insertBefore(node, this.endNode);
1107
- }
1108
- __commitNode(value) {
1109
- if (this.value === value) {
1110
- return;
1111
- }
1112
- this.clear();
1113
- this.__insert(value);
1114
- this.value = value;
1115
- }
1116
- __commitText(value) {
1117
- const node = this.startNode.nextSibling;
1118
- value = value == null ? "" : value;
1119
- const valueAsString = typeof value === "string" ? value : String(value);
1120
- if (node === this.endNode.previousSibling && node.nodeType === 3) {
1121
- node.data = valueAsString;
1122
- } else {
1123
- this.__commitNode(document.createTextNode(valueAsString));
1124
- }
1125
- this.value = value;
1126
- }
1127
- __commitTemplateResult(value) {
1128
- const template = this.options.templateFactory(value);
1129
- if (this.value instanceof TemplateInstance && this.value.template === template) {
1130
- this.value.update(value.values);
1131
- } else {
1132
- const instance = new TemplateInstance(template, value.processor, this.options);
1133
- const fragment = instance._clone();
1134
- instance.update(value.values);
1135
- this.__commitNode(fragment);
1136
- this.value = instance;
1137
- }
1138
- }
1139
- __commitIterable(value) {
1140
- if (!Array.isArray(this.value)) {
1141
- this.value = [];
1142
- this.clear();
1143
- }
1144
- const itemParts = this.value;
1145
- let partIndex = 0;
1146
- let itemPart;
1147
- for (const item of value) {
1148
- itemPart = itemParts[partIndex];
1149
- if (itemPart === void 0) {
1150
- itemPart = new NodePart(this.options);
1151
- itemParts.push(itemPart);
1152
- if (partIndex === 0) {
1153
- itemPart.appendIntoPart(this);
1154
- } else {
1155
- itemPart.insertAfterPart(itemParts[partIndex - 1]);
1156
- }
1157
- }
1158
- itemPart.setValue(item);
1159
- itemPart.commit();
1160
- partIndex++;
1161
- }
1162
- if (partIndex < itemParts.length) {
1163
- itemParts.length = partIndex;
1164
- this.clear(itemPart && itemPart.endNode);
1165
- }
1166
- }
1167
- clear(startNode = this.startNode) {
1168
- removeNodes(this.startNode.parentNode, startNode.nextSibling, this.endNode);
1169
- }
1170
- };
1171
- var BooleanAttributePart = class {
1172
- constructor(element, name, strings) {
1173
- this.value = void 0;
1174
- this.__pendingValue = void 0;
1175
- if (strings.length !== 2 || strings[0] !== "" || strings[1] !== "") {
1176
- throw new Error("Boolean attributes can only contain a single expression");
1177
- }
1178
- this.element = element;
1179
- this.name = name;
1180
- this.strings = strings;
1181
- }
1182
- setValue(value) {
1183
- this.__pendingValue = value;
1184
- }
1185
- commit() {
1186
- while (isDirective(this.__pendingValue)) {
1187
- const directive2 = this.__pendingValue;
1188
- this.__pendingValue = noChange;
1189
- directive2(this);
1190
- }
1191
- if (this.__pendingValue === noChange) {
1192
- return;
1193
- }
1194
- const value = !!this.__pendingValue;
1195
- if (this.value !== value) {
1196
- if (value) {
1197
- this.element.setAttribute(this.name, "");
1198
- } else {
1199
- this.element.removeAttribute(this.name);
1200
- }
1201
- this.value = value;
1202
- }
1203
- this.__pendingValue = noChange;
1204
- }
1205
- };
1206
- var PropertyCommitter = class extends AttributeCommitter {
1207
- constructor(element, name, strings) {
1208
- super(element, name, strings);
1209
- this.single = strings.length === 2 && strings[0] === "" && strings[1] === "";
1210
- }
1211
- _createPart() {
1212
- return new PropertyPart(this);
1213
- }
1214
- _getValue() {
1215
- if (this.single) {
1216
- return this.parts[0].value;
1217
- }
1218
- return super._getValue();
1219
- }
1220
- commit() {
1221
- if (this.dirty) {
1222
- this.dirty = false;
1223
- this.element[this.name] = this._getValue();
1224
- }
1225
- }
1226
- };
1227
- var PropertyPart = class extends AttributePart {
1228
- };
1229
- var eventOptionsSupported = false;
1230
- (() => {
1231
- try {
1232
- const options = {
1233
- get capture() {
1234
- eventOptionsSupported = true;
1235
- return false;
1236
- }
1237
- };
1238
- window.addEventListener("test", options, options);
1239
- window.removeEventListener("test", options, options);
1240
- } catch (_e) {
1241
- }
1242
- })();
1243
- var EventPart = class {
1244
- constructor(element, eventName, eventContext) {
1245
- this.value = void 0;
1246
- this.__pendingValue = void 0;
1247
- this.element = element;
1248
- this.eventName = eventName;
1249
- this.eventContext = eventContext;
1250
- this.__boundHandleEvent = (e) => this.handleEvent(e);
1251
- }
1252
- setValue(value) {
1253
- this.__pendingValue = value;
1254
- }
1255
- commit() {
1256
- while (isDirective(this.__pendingValue)) {
1257
- const directive2 = this.__pendingValue;
1258
- this.__pendingValue = noChange;
1259
- directive2(this);
1260
- }
1261
- if (this.__pendingValue === noChange) {
1262
- return;
1263
- }
1264
- const newListener = this.__pendingValue;
1265
- const oldListener = this.value;
1266
- const shouldRemoveListener = newListener == null || oldListener != null && (newListener.capture !== oldListener.capture || newListener.once !== oldListener.once || newListener.passive !== oldListener.passive);
1267
- const shouldAddListener = newListener != null && (oldListener == null || shouldRemoveListener);
1268
- if (shouldRemoveListener) {
1269
- this.element.removeEventListener(this.eventName, this.__boundHandleEvent, this.__options);
1270
- }
1271
- if (shouldAddListener) {
1272
- this.__options = getOptions(newListener);
1273
- this.element.addEventListener(this.eventName, this.__boundHandleEvent, this.__options);
1274
- }
1275
- this.value = newListener;
1276
- this.__pendingValue = noChange;
1277
- }
1278
- handleEvent(event) {
1279
- if (typeof this.value === "function") {
1280
- this.value.call(this.eventContext || this.element, event);
1281
- } else {
1282
- this.value.handleEvent(event);
1283
- }
1284
- }
1285
- };
1286
- var getOptions = (o) => o && (eventOptionsSupported ? {capture: o.capture, passive: o.passive, once: o.once} : o.capture);
1287
-
1288
- // node_modules/lit-html/lib/default-template-processor.js
1289
- /**
1290
- * @license
1291
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1292
- * This code may only be used under the BSD style license found at
1293
- * http://polymer.github.io/LICENSE.txt
1294
- * The complete set of authors may be found at
1295
- * http://polymer.github.io/AUTHORS.txt
1296
- * The complete set of contributors may be found at
1297
- * http://polymer.github.io/CONTRIBUTORS.txt
1298
- * Code distributed by Google as part of the polymer project is also
1299
- * subject to an additional IP rights grant found at
1300
- * http://polymer.github.io/PATENTS.txt
1301
- */
1302
- var DefaultTemplateProcessor = class {
1303
- handleAttributeExpressions(element, name, strings, options) {
1304
- const prefix = name[0];
1305
- if (prefix === ".") {
1306
- const committer2 = new PropertyCommitter(element, name.slice(1), strings);
1307
- return committer2.parts;
1308
- }
1309
- if (prefix === "@") {
1310
- return [new EventPart(element, name.slice(1), options.eventContext)];
1311
- }
1312
- if (prefix === "?") {
1313
- return [new BooleanAttributePart(element, name.slice(1), strings)];
1314
- }
1315
- const committer = new AttributeCommitter(element, name, strings);
1316
- return committer.parts;
1317
- }
1318
- handleTextExpression(options) {
1319
- return new NodePart(options);
1320
- }
1321
- };
1322
- var defaultTemplateProcessor = new DefaultTemplateProcessor();
1323
-
1324
- // node_modules/lit-html/lib/template-factory.js
1325
- /**
1326
- * @license
1327
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1328
- * This code may only be used under the BSD style license found at
1329
- * http://polymer.github.io/LICENSE.txt
1330
- * The complete set of authors may be found at
1331
- * http://polymer.github.io/AUTHORS.txt
1332
- * The complete set of contributors may be found at
1333
- * http://polymer.github.io/CONTRIBUTORS.txt
1334
- * Code distributed by Google as part of the polymer project is also
1335
- * subject to an additional IP rights grant found at
1336
- * http://polymer.github.io/PATENTS.txt
1337
- */
1338
- function templateFactory(result) {
1339
- let templateCache = templateCaches.get(result.type);
1340
- if (templateCache === void 0) {
1341
- templateCache = {
1342
- stringsArray: new WeakMap(),
1343
- keyString: new Map()
1344
- };
1345
- templateCaches.set(result.type, templateCache);
1346
- }
1347
- let template = templateCache.stringsArray.get(result.strings);
1348
- if (template !== void 0) {
1349
- return template;
1350
- }
1351
- const key = result.strings.join(marker);
1352
- template = templateCache.keyString.get(key);
1353
- if (template === void 0) {
1354
- template = new Template(result, result.getTemplateElement());
1355
- templateCache.keyString.set(key, template);
1356
- }
1357
- templateCache.stringsArray.set(result.strings, template);
1358
- return template;
1359
- }
1360
- var templateCaches = new Map();
1361
-
1362
- // node_modules/lit-html/lib/render.js
1363
- /**
1364
- * @license
1365
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1366
- * This code may only be used under the BSD style license found at
1367
- * http://polymer.github.io/LICENSE.txt
1368
- * The complete set of authors may be found at
1369
- * http://polymer.github.io/AUTHORS.txt
1370
- * The complete set of contributors may be found at
1371
- * http://polymer.github.io/CONTRIBUTORS.txt
1372
- * Code distributed by Google as part of the polymer project is also
1373
- * subject to an additional IP rights grant found at
1374
- * http://polymer.github.io/PATENTS.txt
1375
- */
1376
- var parts = new WeakMap();
1377
- var render = (result, container, options) => {
1378
- let part = parts.get(container);
1379
- if (part === void 0) {
1380
- removeNodes(container, container.firstChild);
1381
- parts.set(container, part = new NodePart(Object.assign({templateFactory}, options)));
1382
- part.appendInto(container);
1383
- }
1384
- part.setValue(result);
1385
- part.commit();
1386
- };
1387
-
1388
- // node_modules/lit-html/lit-html.js
1389
- /**
1390
- * @license
1391
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1392
- * This code may only be used under the BSD style license found at
1393
- * http://polymer.github.io/LICENSE.txt
1394
- * The complete set of authors may be found at
1395
- * http://polymer.github.io/AUTHORS.txt
1396
- * The complete set of contributors may be found at
1397
- * http://polymer.github.io/CONTRIBUTORS.txt
1398
- * Code distributed by Google as part of the polymer project is also
1399
- * subject to an additional IP rights grant found at
1400
- * http://polymer.github.io/PATENTS.txt
1401
- */
1402
- if (typeof window !== "undefined") {
1403
- (window["litHtmlVersions"] || (window["litHtmlVersions"] = [])).push("1.2.1");
1404
- }
1405
- var html = (strings, ...values) => new TemplateResult(strings, values, "html", defaultTemplateProcessor);
1406
-
1407
- // node_modules/lit-html/lib/modify-template.js
1408
- /**
1409
- * @license
1410
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1411
- * This code may only be used under the BSD style license found at
1412
- * http://polymer.github.io/LICENSE.txt
1413
- * The complete set of authors may be found at
1414
- * http://polymer.github.io/AUTHORS.txt
1415
- * The complete set of contributors may be found at
1416
- * http://polymer.github.io/CONTRIBUTORS.txt
1417
- * Code distributed by Google as part of the polymer project is also
1418
- * subject to an additional IP rights grant found at
1419
- * http://polymer.github.io/PATENTS.txt
1420
- */
1421
- var walkerNodeFilter = 133;
1422
- function removeNodesFromTemplate(template, nodesToRemove) {
1423
- const {element: {content}, parts: parts2} = template;
1424
- const walker = document.createTreeWalker(content, walkerNodeFilter, null, false);
1425
- let partIndex = nextActiveIndexInTemplateParts(parts2);
1426
- let part = parts2[partIndex];
1427
- let nodeIndex = -1;
1428
- let removeCount = 0;
1429
- const nodesToRemoveInTemplate = [];
1430
- let currentRemovingNode = null;
1431
- while (walker.nextNode()) {
1432
- nodeIndex++;
1433
- const node = walker.currentNode;
1434
- if (node.previousSibling === currentRemovingNode) {
1435
- currentRemovingNode = null;
1436
- }
1437
- if (nodesToRemove.has(node)) {
1438
- nodesToRemoveInTemplate.push(node);
1439
- if (currentRemovingNode === null) {
1440
- currentRemovingNode = node;
1441
- }
1442
- }
1443
- if (currentRemovingNode !== null) {
1444
- removeCount++;
1445
- }
1446
- while (part !== void 0 && part.index === nodeIndex) {
1447
- part.index = currentRemovingNode !== null ? -1 : part.index - removeCount;
1448
- partIndex = nextActiveIndexInTemplateParts(parts2, partIndex);
1449
- part = parts2[partIndex];
1450
- }
1451
- }
1452
- nodesToRemoveInTemplate.forEach((n) => n.parentNode.removeChild(n));
1453
- }
1454
- var countNodes = (node) => {
1455
- let count = node.nodeType === 11 ? 0 : 1;
1456
- const walker = document.createTreeWalker(node, walkerNodeFilter, null, false);
1457
- while (walker.nextNode()) {
1458
- count++;
1459
- }
1460
- return count;
1461
- };
1462
- var nextActiveIndexInTemplateParts = (parts2, startIndex = -1) => {
1463
- for (let i = startIndex + 1; i < parts2.length; i++) {
1464
- const part = parts2[i];
1465
- if (isTemplatePartActive(part)) {
1466
- return i;
1467
- }
1468
- }
1469
- return -1;
1470
- };
1471
- function insertNodeIntoTemplate(template, node, refNode = null) {
1472
- const {element: {content}, parts: parts2} = template;
1473
- if (refNode === null || refNode === void 0) {
1474
- content.appendChild(node);
1475
- return;
1476
- }
1477
- const walker = document.createTreeWalker(content, walkerNodeFilter, null, false);
1478
- let partIndex = nextActiveIndexInTemplateParts(parts2);
1479
- let insertCount = 0;
1480
- let walkerIndex = -1;
1481
- while (walker.nextNode()) {
1482
- walkerIndex++;
1483
- const walkerNode = walker.currentNode;
1484
- if (walkerNode === refNode) {
1485
- insertCount = countNodes(node);
1486
- refNode.parentNode.insertBefore(node, refNode);
1487
- }
1488
- while (partIndex !== -1 && parts2[partIndex].index === walkerIndex) {
1489
- if (insertCount > 0) {
1490
- while (partIndex !== -1) {
1491
- parts2[partIndex].index += insertCount;
1492
- partIndex = nextActiveIndexInTemplateParts(parts2, partIndex);
1493
- }
1494
- return;
1495
- }
1496
- partIndex = nextActiveIndexInTemplateParts(parts2, partIndex);
1497
- }
1498
- }
1499
- }
1500
-
1501
- // node_modules/lit-html/lib/shady-render.js
1502
- /**
1503
- * @license
1504
- * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1505
- * This code may only be used under the BSD style license found at
1506
- * http://polymer.github.io/LICENSE.txt
1507
- * The complete set of authors may be found at
1508
- * http://polymer.github.io/AUTHORS.txt
1509
- * The complete set of contributors may be found at
1510
- * http://polymer.github.io/CONTRIBUTORS.txt
1511
- * Code distributed by Google as part of the polymer project is also
1512
- * subject to an additional IP rights grant found at
1513
- * http://polymer.github.io/PATENTS.txt
1514
- */
1515
- var getTemplateCacheKey = (type, scopeName) => `${type}--${scopeName}`;
1516
- var compatibleShadyCSSVersion = true;
1517
- if (typeof window.ShadyCSS === "undefined") {
1518
- compatibleShadyCSSVersion = false;
1519
- } else if (typeof window.ShadyCSS.prepareTemplateDom === "undefined") {
1520
- console.warn(`Incompatible ShadyCSS version detected. Please update to at least @webcomponents/webcomponentsjs@2.0.2 and @webcomponents/shadycss@1.3.1.`);
1521
- compatibleShadyCSSVersion = false;
1522
- }
1523
- var shadyTemplateFactory = (scopeName) => (result) => {
1524
- const cacheKey = getTemplateCacheKey(result.type, scopeName);
1525
- let templateCache = templateCaches.get(cacheKey);
1526
- if (templateCache === void 0) {
1527
- templateCache = {
1528
- stringsArray: new WeakMap(),
1529
- keyString: new Map()
1530
- };
1531
- templateCaches.set(cacheKey, templateCache);
1532
- }
1533
- let template = templateCache.stringsArray.get(result.strings);
1534
- if (template !== void 0) {
1535
- return template;
1536
- }
1537
- const key = result.strings.join(marker);
1538
- template = templateCache.keyString.get(key);
1539
- if (template === void 0) {
1540
- const element = result.getTemplateElement();
1541
- if (compatibleShadyCSSVersion) {
1542
- window.ShadyCSS.prepareTemplateDom(element, scopeName);
1543
- }
1544
- template = new Template(result, element);
1545
- templateCache.keyString.set(key, template);
1546
- }
1547
- templateCache.stringsArray.set(result.strings, template);
1548
- return template;
1549
- };
1550
- var TEMPLATE_TYPES = ["html", "svg"];
1551
- var removeStylesFromLitTemplates = (scopeName) => {
1552
- TEMPLATE_TYPES.forEach((type) => {
1553
- const templates = templateCaches.get(getTemplateCacheKey(type, scopeName));
1554
- if (templates !== void 0) {
1555
- templates.keyString.forEach((template) => {
1556
- const {element: {content}} = template;
1557
- const styles = new Set();
1558
- Array.from(content.querySelectorAll("style")).forEach((s) => {
1559
- styles.add(s);
1560
- });
1561
- removeNodesFromTemplate(template, styles);
1562
- });
1563
- }
1564
- });
1565
- };
1566
- var shadyRenderSet = new Set();
1567
- var prepareTemplateStyles = (scopeName, renderedDOM, template) => {
1568
- shadyRenderSet.add(scopeName);
1569
- const templateElement = !!template ? template.element : document.createElement("template");
1570
- const styles = renderedDOM.querySelectorAll("style");
1571
- const {length} = styles;
1572
- if (length === 0) {
1573
- window.ShadyCSS.prepareTemplateStyles(templateElement, scopeName);
1574
- return;
1575
- }
1576
- const condensedStyle = document.createElement("style");
1577
- for (let i = 0; i < length; i++) {
1578
- const style2 = styles[i];
1579
- style2.parentNode.removeChild(style2);
1580
- condensedStyle.textContent += style2.textContent;
1581
- }
1582
- removeStylesFromLitTemplates(scopeName);
1583
- const content = templateElement.content;
1584
- if (!!template) {
1585
- insertNodeIntoTemplate(template, condensedStyle, content.firstChild);
1586
- } else {
1587
- content.insertBefore(condensedStyle, content.firstChild);
1588
- }
1589
- window.ShadyCSS.prepareTemplateStyles(templateElement, scopeName);
1590
- const style = content.querySelector("style");
1591
- if (window.ShadyCSS.nativeShadow && style !== null) {
1592
- renderedDOM.insertBefore(style.cloneNode(true), renderedDOM.firstChild);
1593
- } else if (!!template) {
1594
- content.insertBefore(condensedStyle, content.firstChild);
1595
- const removes = new Set();
1596
- removes.add(condensedStyle);
1597
- removeNodesFromTemplate(template, removes);
1598
- }
1599
- };
1600
- var render2 = (result, container, options) => {
1601
- if (!options || typeof options !== "object" || !options.scopeName) {
1602
- throw new Error("The `scopeName` option is required.");
1603
- }
1604
- const scopeName = options.scopeName;
1605
- const hasRendered = parts.has(container);
1606
- const needsScoping = compatibleShadyCSSVersion && container.nodeType === 11 && !!container.host;
1607
- const firstScopeRender = needsScoping && !shadyRenderSet.has(scopeName);
1608
- const renderContainer = firstScopeRender ? document.createDocumentFragment() : container;
1609
- render(result, renderContainer, Object.assign({templateFactory: shadyTemplateFactory(scopeName)}, options));
1610
- if (firstScopeRender) {
1611
- const part = parts.get(renderContainer);
1612
- parts.delete(renderContainer);
1613
- const template = part.value instanceof TemplateInstance ? part.value.template : void 0;
1614
- prepareTemplateStyles(scopeName, renderContainer, template);
1615
- removeNodes(container, container.firstChild);
1616
- container.appendChild(renderContainer);
1617
- parts.set(container, part);
1618
- }
1619
- if (!hasRendered && needsScoping) {
1620
- window.ShadyCSS.styleElement(container.host);
1621
- }
1622
- };
1623
-
1624
- // src/TemplateElement.js
1625
- var TemplateElement = class extends StyledElement {
1626
- constructor(options) {
1627
- super({
1628
- deferUpdate: false,
1629
- shadowRender: false,
1630
- styles: [],
1631
- adoptGlobalStyles: true,
1632
- mutationObserverOptions: {
1633
- childList: false
1634
- },
1635
- ...options
1636
- });
1637
- this._template = this._options.template;
1638
- if (this._options.shadowRender)
1639
- this.attachShadow({mode: "open"});
1640
- }
1641
- template() {
1642
- return html``;
1643
- }
1644
- update(options) {
1645
- this.renderTemplate();
1646
- super.update(options);
1647
- }
1648
- renderTemplate() {
1649
- const template = this._template || this.template();
1650
- if (typeof template === "string") {
1651
- this.getRoot().innerHTML = `${template}`;
1652
- } else {
1653
- render2(html` ${template} `, this.getRoot(), {
1654
- scopeName: this.localName,
1655
- eventContext: this
1656
- });
1657
- }
1658
- }
1659
- getRoot() {
1660
- return this.shadowRoot !== null ? this.shadowRoot : this;
1661
- }
1662
- };
1663
- export {
1664
- BaseElement,
1665
- Store,
1666
- StyledElement,
1667
- TemplateElement,
1668
- defineElement,
1669
- html,
1670
- i18n,
1671
- toString
1672
- };
1673
- //# sourceMappingURL=index.js.map