@mantou/gem 1.6.8 → 1.6.9

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/gem.es.js ADDED
@@ -0,0 +1,3272 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __accessCheck = (obj, member, msg) => {
21
+ if (!member.has(obj))
22
+ throw TypeError("Cannot " + msg);
23
+ };
24
+ var __privateGet = (obj, member, getter) => {
25
+ __accessCheck(obj, member, "read from private field");
26
+ return getter ? getter.call(obj) : member.get(obj);
27
+ };
28
+ var __privateAdd = (obj, member, value) => {
29
+ if (member.has(obj))
30
+ throw TypeError("Cannot add the same private member more than once");
31
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
32
+ };
33
+ var __privateSet = (obj, member, value, setter) => {
34
+ __accessCheck(obj, member, "write to private field");
35
+ setter ? setter.call(obj, value) : member.set(obj, value);
36
+ return value;
37
+ };
38
+ var __privateMethod = (obj, member, method) => {
39
+ __accessCheck(obj, member, "access private method");
40
+ return method;
41
+ };
42
+ var _map, _firstItem, _lastItem, _delete, delete_fn, _stringify, _parse, _nextSibling, _parentElement, _inertStore, _a, _cacheCurrentKey, cacheCurrentKey_get, _urlParamsLang, urlParamsLang_get, _cacheLang, cacheLang_get, _isMain, isMain_get, _lang, lang_set;
43
+ var Gem = /* @__PURE__ */ Object.freeze({
44
+ __proto__: null,
45
+ [Symbol.toStringTag]: "Module",
46
+ get StoreListenerMap() {
47
+ return StoreListenerMap;
48
+ },
49
+ get createStore() {
50
+ return createStore;
51
+ },
52
+ get createStoreSet() {
53
+ return createStoreSet;
54
+ },
55
+ get updateStore() {
56
+ return updateStore;
57
+ },
58
+ get connect() {
59
+ return connect;
60
+ },
61
+ get disconnect() {
62
+ return disconnect;
63
+ },
64
+ get history() {
65
+ return history;
66
+ },
67
+ get basePathStore() {
68
+ return basePathStore;
69
+ },
70
+ get titleStore() {
71
+ return titleStore;
72
+ },
73
+ get html() {
74
+ return html;
75
+ },
76
+ get svg() {
77
+ return svg;
78
+ },
79
+ get render() {
80
+ return render;
81
+ },
82
+ get directive() {
83
+ return directive;
84
+ },
85
+ get TemplateResult() {
86
+ return TemplateResult;
87
+ },
88
+ get SVGTemplateResult() {
89
+ return SVGTemplateResult;
90
+ },
91
+ get repeat() {
92
+ return repeat;
93
+ },
94
+ get guard() {
95
+ return guard;
96
+ },
97
+ get ifDefined() {
98
+ return ifDefined;
99
+ },
100
+ get GemElement() {
101
+ return GemElement;
102
+ },
103
+ get defineAttribute() {
104
+ return defineAttribute;
105
+ },
106
+ get defineProperty() {
107
+ return defineProperty;
108
+ },
109
+ get defineRef() {
110
+ return defineRef;
111
+ },
112
+ get defineCSSState() {
113
+ return defineCSSState;
114
+ },
115
+ get nativeDefineElement() {
116
+ return nativeDefineElement;
117
+ },
118
+ get refobject() {
119
+ return refobject;
120
+ },
121
+ get attribute() {
122
+ return attribute;
123
+ },
124
+ get boolattribute() {
125
+ return boolattribute;
126
+ },
127
+ get numattribute() {
128
+ return numattribute;
129
+ },
130
+ get property() {
131
+ return property;
132
+ },
133
+ get state() {
134
+ return state;
135
+ },
136
+ get slot() {
137
+ return slot;
138
+ },
139
+ get part() {
140
+ return part;
141
+ },
142
+ get emitter() {
143
+ return emitter;
144
+ },
145
+ get globalemitter() {
146
+ return globalemitter;
147
+ },
148
+ get adoptedStyle() {
149
+ return adoptedStyle;
150
+ },
151
+ get connectStore() {
152
+ return connectStore;
153
+ },
154
+ get rootElement() {
155
+ return rootElement;
156
+ },
157
+ get customElement() {
158
+ return customElement;
159
+ },
160
+ get addMicrotask() {
161
+ return addMicrotask;
162
+ },
163
+ get addMicrotaskToStack() {
164
+ return addMicrotaskToStack;
165
+ },
166
+ get absoluteLocation() {
167
+ return absoluteLocation;
168
+ },
169
+ get LinkedList() {
170
+ return LinkedList;
171
+ },
172
+ get PropProxyMap() {
173
+ return PropProxyMap;
174
+ },
175
+ get QueryString() {
176
+ return QueryString;
177
+ },
178
+ get raw() {
179
+ return raw;
180
+ },
181
+ get css() {
182
+ return css;
183
+ },
184
+ get SheetToken() {
185
+ return SheetToken;
186
+ },
187
+ get useNativeCSSStyleSheet() {
188
+ return useNativeCSSStyleSheet;
189
+ },
190
+ get createCSSSheet() {
191
+ return createCSSSheet;
192
+ },
193
+ get randomStr() {
194
+ return randomStr;
195
+ },
196
+ get styled() {
197
+ return styled;
198
+ },
199
+ get camelToKebabCase() {
200
+ return camelToKebabCase;
201
+ },
202
+ get kebabToCamelCase() {
203
+ return kebabToCamelCase;
204
+ },
205
+ get cleanObject() {
206
+ return cleanObject;
207
+ },
208
+ get GemError() {
209
+ return GemError;
210
+ },
211
+ get isArrayChange() {
212
+ return isArrayChange;
213
+ },
214
+ get removeItems() {
215
+ return removeItems;
216
+ },
217
+ get styleMap() {
218
+ return styleMap;
219
+ },
220
+ get classMap() {
221
+ return classMap;
222
+ },
223
+ get partMap() {
224
+ return partMap;
225
+ },
226
+ get version() {
227
+ return version;
228
+ }
229
+ });
230
+ /**
231
+ * @license
232
+ * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
233
+ * This code may only be used under the BSD style license found at
234
+ * http://polymer.github.io/LICENSE.txt
235
+ * The complete set of authors may be found at
236
+ * http://polymer.github.io/AUTHORS.txt
237
+ * The complete set of contributors may be found at
238
+ * http://polymer.github.io/CONTRIBUTORS.txt
239
+ * Code distributed by Google as part of the polymer project is also
240
+ * subject to an additional IP rights grant found at
241
+ * http://polymer.github.io/PATENTS.txt
242
+ */
243
+ const directives = new WeakMap();
244
+ const directive = (f) => (...args) => {
245
+ const d = f(...args);
246
+ directives.set(d, true);
247
+ return d;
248
+ };
249
+ const isDirective = (o) => {
250
+ return typeof o === "function" && directives.has(o);
251
+ };
252
+ /**
253
+ * @license
254
+ * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
255
+ * This code may only be used under the BSD style license found at
256
+ * http://polymer.github.io/LICENSE.txt
257
+ * The complete set of authors may be found at
258
+ * http://polymer.github.io/AUTHORS.txt
259
+ * The complete set of contributors may be found at
260
+ * http://polymer.github.io/CONTRIBUTORS.txt
261
+ * Code distributed by Google as part of the polymer project is also
262
+ * subject to an additional IP rights grant found at
263
+ * http://polymer.github.io/PATENTS.txt
264
+ */
265
+ const isCEPolyfill = typeof window !== "undefined" && window.customElements != null && window.customElements.polyfillWrapFlushCallback !== void 0;
266
+ const reparentNodes = (container, start, end = null, before = null) => {
267
+ while (start !== end) {
268
+ const n = start.nextSibling;
269
+ container.insertBefore(start, before);
270
+ start = n;
271
+ }
272
+ };
273
+ const removeNodes = (container, start, end = null) => {
274
+ while (start !== end) {
275
+ const n = start.nextSibling;
276
+ container.removeChild(start);
277
+ start = n;
278
+ }
279
+ };
280
+ /**
281
+ * @license
282
+ * Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
283
+ * This code may only be used under the BSD style license found at
284
+ * http://polymer.github.io/LICENSE.txt
285
+ * The complete set of authors may be found at
286
+ * http://polymer.github.io/AUTHORS.txt
287
+ * The complete set of contributors may be found at
288
+ * http://polymer.github.io/CONTRIBUTORS.txt
289
+ * Code distributed by Google as part of the polymer project is also
290
+ * subject to an additional IP rights grant found at
291
+ * http://polymer.github.io/PATENTS.txt
292
+ */
293
+ const noChange = {};
294
+ const nothing = {};
295
+ /**
296
+ * @license
297
+ * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
298
+ * This code may only be used under the BSD style license found at
299
+ * http://polymer.github.io/LICENSE.txt
300
+ * The complete set of authors may be found at
301
+ * http://polymer.github.io/AUTHORS.txt
302
+ * The complete set of contributors may be found at
303
+ * http://polymer.github.io/CONTRIBUTORS.txt
304
+ * Code distributed by Google as part of the polymer project is also
305
+ * subject to an additional IP rights grant found at
306
+ * http://polymer.github.io/PATENTS.txt
307
+ */
308
+ const marker = `{{lit-${String(Math.random()).slice(2)}}}`;
309
+ const nodeMarker = `<!--${marker}-->`;
310
+ const markerRegex = new RegExp(`${marker}|${nodeMarker}`);
311
+ const boundAttributeSuffix = "$lit$";
312
+ class Template {
313
+ constructor(result, element) {
314
+ this.parts = [];
315
+ this.element = element;
316
+ const nodesToRemove = [];
317
+ const stack = [];
318
+ const walker = document.createTreeWalker(element.content, 133, null, false);
319
+ let lastPartIndex = 0;
320
+ let index = -1;
321
+ let partIndex = 0;
322
+ const { strings, values: { length } } = result;
323
+ while (partIndex < length) {
324
+ const node = walker.nextNode();
325
+ if (node === null) {
326
+ walker.currentNode = stack.pop();
327
+ continue;
328
+ }
329
+ index++;
330
+ if (node.nodeType === 1) {
331
+ if (node.hasAttributes()) {
332
+ const attributes = node.attributes;
333
+ const { length: length2 } = attributes;
334
+ let count = 0;
335
+ for (let i = 0; i < length2; i++) {
336
+ if (endsWith(attributes[i].name, boundAttributeSuffix)) {
337
+ count++;
338
+ }
339
+ }
340
+ while (count-- > 0) {
341
+ const stringForPart = strings[partIndex];
342
+ const name = lastAttributeNameRegex.exec(stringForPart)[2];
343
+ const attributeLookupName = name.toLowerCase() + boundAttributeSuffix;
344
+ const attributeValue = node.getAttribute(attributeLookupName);
345
+ node.removeAttribute(attributeLookupName);
346
+ const statics = attributeValue.split(markerRegex);
347
+ this.parts.push({ type: "attribute", index, name, strings: statics });
348
+ partIndex += statics.length - 1;
349
+ }
350
+ }
351
+ if (node.tagName === "TEMPLATE") {
352
+ stack.push(node);
353
+ walker.currentNode = node.content;
354
+ }
355
+ } else if (node.nodeType === 3) {
356
+ const data = node.data;
357
+ if (data.indexOf(marker) >= 0) {
358
+ const parent = node.parentNode;
359
+ const strings2 = data.split(markerRegex);
360
+ const lastIndex = strings2.length - 1;
361
+ for (let i = 0; i < lastIndex; i++) {
362
+ let insert;
363
+ let s = strings2[i];
364
+ if (s === "") {
365
+ insert = createMarker();
366
+ } else {
367
+ const match = lastAttributeNameRegex.exec(s);
368
+ if (match !== null && endsWith(match[2], boundAttributeSuffix)) {
369
+ s = s.slice(0, match.index) + match[1] + match[2].slice(0, -boundAttributeSuffix.length) + match[3];
370
+ }
371
+ insert = document.createTextNode(s);
372
+ }
373
+ parent.insertBefore(insert, node);
374
+ this.parts.push({ type: "node", index: ++index });
375
+ }
376
+ if (strings2[lastIndex] === "") {
377
+ parent.insertBefore(createMarker(), node);
378
+ nodesToRemove.push(node);
379
+ } else {
380
+ node.data = strings2[lastIndex];
381
+ }
382
+ partIndex += lastIndex;
383
+ }
384
+ } else if (node.nodeType === 8) {
385
+ if (node.data === marker) {
386
+ const parent = node.parentNode;
387
+ if (node.previousSibling === null || index === lastPartIndex) {
388
+ index++;
389
+ parent.insertBefore(createMarker(), node);
390
+ }
391
+ lastPartIndex = index;
392
+ this.parts.push({ type: "node", index });
393
+ if (node.nextSibling === null) {
394
+ node.data = "";
395
+ } else {
396
+ nodesToRemove.push(node);
397
+ index--;
398
+ }
399
+ partIndex++;
400
+ } else {
401
+ let i = -1;
402
+ while ((i = node.data.indexOf(marker, i + 1)) !== -1) {
403
+ this.parts.push({ type: "node", index: -1 });
404
+ partIndex++;
405
+ }
406
+ }
407
+ }
408
+ }
409
+ for (const n of nodesToRemove) {
410
+ n.parentNode.removeChild(n);
411
+ }
412
+ }
413
+ }
414
+ const endsWith = (str, suffix) => {
415
+ const index = str.length - suffix.length;
416
+ return index >= 0 && str.slice(index) === suffix;
417
+ };
418
+ const isTemplatePartActive = (part2) => part2.index !== -1;
419
+ const createMarker = () => document.createComment("");
420
+ const lastAttributeNameRegex = /([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F "'>=/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/;
421
+ /**
422
+ * @license
423
+ * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
424
+ * This code may only be used under the BSD style license found at
425
+ * http://polymer.github.io/LICENSE.txt
426
+ * The complete set of authors may be found at
427
+ * http://polymer.github.io/AUTHORS.txt
428
+ * The complete set of contributors may be found at
429
+ * http://polymer.github.io/CONTRIBUTORS.txt
430
+ * Code distributed by Google as part of the polymer project is also
431
+ * subject to an additional IP rights grant found at
432
+ * http://polymer.github.io/PATENTS.txt
433
+ */
434
+ class TemplateInstance {
435
+ constructor(template, processor, options) {
436
+ this.__parts = [];
437
+ this.template = template;
438
+ this.processor = processor;
439
+ this.options = options;
440
+ }
441
+ update(values) {
442
+ let i = 0;
443
+ for (const part2 of this.__parts) {
444
+ if (part2 !== void 0) {
445
+ part2.setValue(values[i]);
446
+ }
447
+ i++;
448
+ }
449
+ for (const part2 of this.__parts) {
450
+ if (part2 !== void 0) {
451
+ part2.commit();
452
+ }
453
+ }
454
+ }
455
+ _clone() {
456
+ const fragment = isCEPolyfill ? this.template.element.content.cloneNode(true) : document.importNode(this.template.element.content, true);
457
+ const stack = [];
458
+ const parts2 = this.template.parts;
459
+ const walker = document.createTreeWalker(fragment, 133, null, false);
460
+ let partIndex = 0;
461
+ let nodeIndex = 0;
462
+ let part2;
463
+ let node = walker.nextNode();
464
+ while (partIndex < parts2.length) {
465
+ part2 = parts2[partIndex];
466
+ if (!isTemplatePartActive(part2)) {
467
+ this.__parts.push(void 0);
468
+ partIndex++;
469
+ continue;
470
+ }
471
+ while (nodeIndex < part2.index) {
472
+ nodeIndex++;
473
+ if (node.nodeName === "TEMPLATE") {
474
+ stack.push(node);
475
+ walker.currentNode = node.content;
476
+ }
477
+ if ((node = walker.nextNode()) === null) {
478
+ walker.currentNode = stack.pop();
479
+ node = walker.nextNode();
480
+ }
481
+ }
482
+ if (part2.type === "node") {
483
+ const part3 = this.processor.handleTextExpression(this.options);
484
+ part3.insertAfterNode(node.previousSibling);
485
+ this.__parts.push(part3);
486
+ } else {
487
+ this.__parts.push(...this.processor.handleAttributeExpressions(node, part2.name, part2.strings, this.options));
488
+ }
489
+ partIndex++;
490
+ }
491
+ if (isCEPolyfill) {
492
+ document.adoptNode(fragment);
493
+ customElements.upgrade(fragment);
494
+ }
495
+ return fragment;
496
+ }
497
+ }
498
+ /**
499
+ * @license
500
+ * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
501
+ * This code may only be used under the BSD style license found at
502
+ * http://polymer.github.io/LICENSE.txt
503
+ * The complete set of authors may be found at
504
+ * http://polymer.github.io/AUTHORS.txt
505
+ * The complete set of contributors may be found at
506
+ * http://polymer.github.io/CONTRIBUTORS.txt
507
+ * Code distributed by Google as part of the polymer project is also
508
+ * subject to an additional IP rights grant found at
509
+ * http://polymer.github.io/PATENTS.txt
510
+ */
511
+ const policy = window.trustedTypes && trustedTypes.createPolicy("lit-html", { createHTML: (s) => s });
512
+ const commentMarker = ` ${marker} `;
513
+ class TemplateResult {
514
+ constructor(strings, values, type, processor) {
515
+ this.strings = strings;
516
+ this.values = values;
517
+ this.type = type;
518
+ this.processor = processor;
519
+ }
520
+ getHTML() {
521
+ const l = this.strings.length - 1;
522
+ let html2 = "";
523
+ let isCommentBinding = false;
524
+ for (let i = 0; i < l; i++) {
525
+ const s = this.strings[i];
526
+ const commentOpen = s.lastIndexOf("<!--");
527
+ isCommentBinding = (commentOpen > -1 || isCommentBinding) && s.indexOf("-->", commentOpen + 1) === -1;
528
+ const attributeMatch = lastAttributeNameRegex.exec(s);
529
+ if (attributeMatch === null) {
530
+ html2 += s + (isCommentBinding ? commentMarker : nodeMarker);
531
+ } else {
532
+ html2 += s.substr(0, attributeMatch.index) + attributeMatch[1] + attributeMatch[2] + boundAttributeSuffix + attributeMatch[3] + marker;
533
+ }
534
+ }
535
+ html2 += this.strings[l];
536
+ return html2;
537
+ }
538
+ getTemplateElement() {
539
+ const template = document.createElement("template");
540
+ let value = this.getHTML();
541
+ if (policy !== void 0) {
542
+ value = policy.createHTML(value);
543
+ }
544
+ template.innerHTML = value;
545
+ return template;
546
+ }
547
+ }
548
+ class SVGTemplateResult extends TemplateResult {
549
+ getHTML() {
550
+ return `<svg>${super.getHTML()}</svg>`;
551
+ }
552
+ getTemplateElement() {
553
+ const template = super.getTemplateElement();
554
+ const content = template.content;
555
+ const svgElement = content.firstChild;
556
+ content.removeChild(svgElement);
557
+ reparentNodes(content, svgElement.firstChild);
558
+ return template;
559
+ }
560
+ }
561
+ /**
562
+ * @license
563
+ * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
564
+ * This code may only be used under the BSD style license found at
565
+ * http://polymer.github.io/LICENSE.txt
566
+ * The complete set of authors may be found at
567
+ * http://polymer.github.io/AUTHORS.txt
568
+ * The complete set of contributors may be found at
569
+ * http://polymer.github.io/CONTRIBUTORS.txt
570
+ * Code distributed by Google as part of the polymer project is also
571
+ * subject to an additional IP rights grant found at
572
+ * http://polymer.github.io/PATENTS.txt
573
+ */
574
+ const isPrimitive = (value) => {
575
+ return value === null || !(typeof value === "object" || typeof value === "function");
576
+ };
577
+ const isIterable = (value) => {
578
+ return Array.isArray(value) || !!(value && value[Symbol.iterator]);
579
+ };
580
+ class AttributeCommitter {
581
+ constructor(element, name, strings) {
582
+ this.dirty = true;
583
+ this.element = element;
584
+ this.name = name;
585
+ this.strings = strings;
586
+ this.parts = [];
587
+ for (let i = 0; i < strings.length - 1; i++) {
588
+ this.parts[i] = this._createPart();
589
+ }
590
+ }
591
+ _createPart() {
592
+ return new AttributePart(this);
593
+ }
594
+ _getValue() {
595
+ const strings = this.strings;
596
+ const l = strings.length - 1;
597
+ const parts2 = this.parts;
598
+ if (l === 1 && strings[0] === "" && strings[1] === "") {
599
+ const v = parts2[0].value;
600
+ if (typeof v === "symbol") {
601
+ return String(v);
602
+ }
603
+ if (typeof v === "string" || !isIterable(v)) {
604
+ return v;
605
+ }
606
+ }
607
+ let text = "";
608
+ for (let i = 0; i < l; i++) {
609
+ text += strings[i];
610
+ const part2 = parts2[i];
611
+ if (part2 !== void 0) {
612
+ const v = part2.value;
613
+ if (isPrimitive(v) || !isIterable(v)) {
614
+ text += typeof v === "string" ? v : String(v);
615
+ } else {
616
+ for (const t of v) {
617
+ text += typeof t === "string" ? t : String(t);
618
+ }
619
+ }
620
+ }
621
+ }
622
+ text += strings[l];
623
+ return text;
624
+ }
625
+ commit() {
626
+ if (this.dirty) {
627
+ this.dirty = false;
628
+ this.element.setAttribute(this.name, this._getValue());
629
+ }
630
+ }
631
+ }
632
+ class AttributePart {
633
+ constructor(committer) {
634
+ this.value = void 0;
635
+ this.committer = committer;
636
+ }
637
+ setValue(value) {
638
+ if (value !== noChange && (!isPrimitive(value) || value !== this.value)) {
639
+ this.value = value;
640
+ if (!isDirective(value)) {
641
+ this.committer.dirty = true;
642
+ }
643
+ }
644
+ }
645
+ commit() {
646
+ while (isDirective(this.value)) {
647
+ const directive2 = this.value;
648
+ this.value = noChange;
649
+ directive2(this);
650
+ }
651
+ if (this.value === noChange) {
652
+ return;
653
+ }
654
+ this.committer.commit();
655
+ }
656
+ }
657
+ class NodePart {
658
+ constructor(options) {
659
+ this.value = void 0;
660
+ this.__pendingValue = void 0;
661
+ this.options = options;
662
+ }
663
+ appendInto(container) {
664
+ this.startNode = container.appendChild(createMarker());
665
+ this.endNode = container.appendChild(createMarker());
666
+ }
667
+ insertAfterNode(ref) {
668
+ this.startNode = ref;
669
+ this.endNode = ref.nextSibling;
670
+ }
671
+ appendIntoPart(part2) {
672
+ part2.__insert(this.startNode = createMarker());
673
+ part2.__insert(this.endNode = createMarker());
674
+ }
675
+ insertAfterPart(ref) {
676
+ ref.__insert(this.startNode = createMarker());
677
+ this.endNode = ref.endNode;
678
+ ref.endNode = this.startNode;
679
+ }
680
+ setValue(value) {
681
+ this.__pendingValue = value;
682
+ }
683
+ commit() {
684
+ if (this.startNode.parentNode === null) {
685
+ return;
686
+ }
687
+ while (isDirective(this.__pendingValue)) {
688
+ const directive2 = this.__pendingValue;
689
+ this.__pendingValue = noChange;
690
+ directive2(this);
691
+ }
692
+ const value = this.__pendingValue;
693
+ if (value === noChange) {
694
+ return;
695
+ }
696
+ if (isPrimitive(value)) {
697
+ if (value !== this.value) {
698
+ this.__commitText(value);
699
+ }
700
+ } else if (value instanceof TemplateResult) {
701
+ this.__commitTemplateResult(value);
702
+ } else if (value instanceof Node) {
703
+ this.__commitNode(value);
704
+ } else if (isIterable(value)) {
705
+ this.__commitIterable(value);
706
+ } else if (value === nothing) {
707
+ this.value = nothing;
708
+ this.clear();
709
+ } else {
710
+ this.__commitText(value);
711
+ }
712
+ }
713
+ __insert(node) {
714
+ this.endNode.parentNode.insertBefore(node, this.endNode);
715
+ }
716
+ __commitNode(value) {
717
+ if (this.value === value) {
718
+ return;
719
+ }
720
+ this.clear();
721
+ this.__insert(value);
722
+ this.value = value;
723
+ }
724
+ __commitText(value) {
725
+ const node = this.startNode.nextSibling;
726
+ value = value == null ? "" : value;
727
+ const valueAsString = typeof value === "string" ? value : String(value);
728
+ if (node === this.endNode.previousSibling && node.nodeType === 3) {
729
+ node.data = valueAsString;
730
+ } else {
731
+ this.__commitNode(document.createTextNode(valueAsString));
732
+ }
733
+ this.value = value;
734
+ }
735
+ __commitTemplateResult(value) {
736
+ const template = this.options.templateFactory(value);
737
+ if (this.value instanceof TemplateInstance && this.value.template === template) {
738
+ this.value.update(value.values);
739
+ } else {
740
+ const instance = new TemplateInstance(template, value.processor, this.options);
741
+ const fragment = instance._clone();
742
+ instance.update(value.values);
743
+ this.__commitNode(fragment);
744
+ this.value = instance;
745
+ }
746
+ }
747
+ __commitIterable(value) {
748
+ if (!Array.isArray(this.value)) {
749
+ this.value = [];
750
+ this.clear();
751
+ }
752
+ const itemParts = this.value;
753
+ let partIndex = 0;
754
+ let itemPart;
755
+ for (const item of value) {
756
+ itemPart = itemParts[partIndex];
757
+ if (itemPart === void 0) {
758
+ itemPart = new NodePart(this.options);
759
+ itemParts.push(itemPart);
760
+ if (partIndex === 0) {
761
+ itemPart.appendIntoPart(this);
762
+ } else {
763
+ itemPart.insertAfterPart(itemParts[partIndex - 1]);
764
+ }
765
+ }
766
+ itemPart.setValue(item);
767
+ itemPart.commit();
768
+ partIndex++;
769
+ }
770
+ if (partIndex < itemParts.length) {
771
+ itemParts.length = partIndex;
772
+ this.clear(itemPart && itemPart.endNode);
773
+ }
774
+ }
775
+ clear(startNode = this.startNode) {
776
+ removeNodes(this.startNode.parentNode, startNode.nextSibling, this.endNode);
777
+ }
778
+ }
779
+ class BooleanAttributePart {
780
+ constructor(element, name, strings) {
781
+ this.value = void 0;
782
+ this.__pendingValue = void 0;
783
+ if (strings.length !== 2 || strings[0] !== "" || strings[1] !== "") {
784
+ throw new Error("Boolean attributes can only contain a single expression");
785
+ }
786
+ this.element = element;
787
+ this.name = name;
788
+ this.strings = strings;
789
+ }
790
+ setValue(value) {
791
+ this.__pendingValue = value;
792
+ }
793
+ commit() {
794
+ while (isDirective(this.__pendingValue)) {
795
+ const directive2 = this.__pendingValue;
796
+ this.__pendingValue = noChange;
797
+ directive2(this);
798
+ }
799
+ if (this.__pendingValue === noChange) {
800
+ return;
801
+ }
802
+ const value = !!this.__pendingValue;
803
+ if (this.value !== value) {
804
+ if (value) {
805
+ this.element.setAttribute(this.name, "");
806
+ } else {
807
+ this.element.removeAttribute(this.name);
808
+ }
809
+ this.value = value;
810
+ }
811
+ this.__pendingValue = noChange;
812
+ }
813
+ }
814
+ class PropertyCommitter extends AttributeCommitter {
815
+ constructor(element, name, strings) {
816
+ super(element, name, strings);
817
+ this.single = strings.length === 2 && strings[0] === "" && strings[1] === "";
818
+ }
819
+ _createPart() {
820
+ return new PropertyPart(this);
821
+ }
822
+ _getValue() {
823
+ if (this.single) {
824
+ return this.parts[0].value;
825
+ }
826
+ return super._getValue();
827
+ }
828
+ commit() {
829
+ if (this.dirty) {
830
+ this.dirty = false;
831
+ this.element[this.name] = this._getValue();
832
+ }
833
+ }
834
+ }
835
+ class PropertyPart extends AttributePart {
836
+ }
837
+ let eventOptionsSupported = false;
838
+ (() => {
839
+ try {
840
+ const options = {
841
+ get capture() {
842
+ eventOptionsSupported = true;
843
+ return false;
844
+ }
845
+ };
846
+ window.addEventListener("test", options, options);
847
+ window.removeEventListener("test", options, options);
848
+ } catch (_e) {
849
+ }
850
+ })();
851
+ class EventPart {
852
+ constructor(element, eventName, eventContext) {
853
+ this.value = void 0;
854
+ this.__pendingValue = void 0;
855
+ this.element = element;
856
+ this.eventName = eventName;
857
+ this.eventContext = eventContext;
858
+ this.__boundHandleEvent = (e) => this.handleEvent(e);
859
+ }
860
+ setValue(value) {
861
+ this.__pendingValue = value;
862
+ }
863
+ commit() {
864
+ while (isDirective(this.__pendingValue)) {
865
+ const directive2 = this.__pendingValue;
866
+ this.__pendingValue = noChange;
867
+ directive2(this);
868
+ }
869
+ if (this.__pendingValue === noChange) {
870
+ return;
871
+ }
872
+ const newListener = this.__pendingValue;
873
+ const oldListener = this.value;
874
+ const shouldRemoveListener = newListener == null || oldListener != null && (newListener.capture !== oldListener.capture || newListener.once !== oldListener.once || newListener.passive !== oldListener.passive);
875
+ const shouldAddListener = newListener != null && (oldListener == null || shouldRemoveListener);
876
+ if (shouldRemoveListener) {
877
+ this.element.removeEventListener(this.eventName, this.__boundHandleEvent, this.__options);
878
+ }
879
+ if (shouldAddListener) {
880
+ this.__options = getOptions(newListener);
881
+ this.element.addEventListener(this.eventName, this.__boundHandleEvent, this.__options);
882
+ }
883
+ this.value = newListener;
884
+ this.__pendingValue = noChange;
885
+ }
886
+ handleEvent(event) {
887
+ if (typeof this.value === "function") {
888
+ this.value.call(this.eventContext || this.element, event);
889
+ } else {
890
+ this.value.handleEvent(event);
891
+ }
892
+ }
893
+ }
894
+ const getOptions = (o) => o && (eventOptionsSupported ? { capture: o.capture, passive: o.passive, once: o.once } : o.capture);
895
+ /**
896
+ * @license
897
+ * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
898
+ * This code may only be used under the BSD style license found at
899
+ * http://polymer.github.io/LICENSE.txt
900
+ * The complete set of authors may be found at
901
+ * http://polymer.github.io/AUTHORS.txt
902
+ * The complete set of contributors may be found at
903
+ * http://polymer.github.io/CONTRIBUTORS.txt
904
+ * Code distributed by Google as part of the polymer project is also
905
+ * subject to an additional IP rights grant found at
906
+ * http://polymer.github.io/PATENTS.txt
907
+ */
908
+ class DefaultTemplateProcessor {
909
+ handleAttributeExpressions(element, name, strings, options) {
910
+ const prefix = name[0];
911
+ if (prefix === ".") {
912
+ const committer2 = new PropertyCommitter(element, name.slice(1), strings);
913
+ return committer2.parts;
914
+ }
915
+ if (prefix === "@") {
916
+ return [new EventPart(element, name.slice(1), options.eventContext)];
917
+ }
918
+ if (prefix === "?") {
919
+ return [new BooleanAttributePart(element, name.slice(1), strings)];
920
+ }
921
+ const committer = new AttributeCommitter(element, name, strings);
922
+ return committer.parts;
923
+ }
924
+ handleTextExpression(options) {
925
+ return new NodePart(options);
926
+ }
927
+ }
928
+ const defaultTemplateProcessor = new DefaultTemplateProcessor();
929
+ /**
930
+ * @license
931
+ * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
932
+ * This code may only be used under the BSD style license found at
933
+ * http://polymer.github.io/LICENSE.txt
934
+ * The complete set of authors may be found at
935
+ * http://polymer.github.io/AUTHORS.txt
936
+ * The complete set of contributors may be found at
937
+ * http://polymer.github.io/CONTRIBUTORS.txt
938
+ * Code distributed by Google as part of the polymer project is also
939
+ * subject to an additional IP rights grant found at
940
+ * http://polymer.github.io/PATENTS.txt
941
+ */
942
+ function templateFactory(result) {
943
+ let templateCache = templateCaches.get(result.type);
944
+ if (templateCache === void 0) {
945
+ templateCache = {
946
+ stringsArray: new WeakMap(),
947
+ keyString: new Map()
948
+ };
949
+ templateCaches.set(result.type, templateCache);
950
+ }
951
+ let template = templateCache.stringsArray.get(result.strings);
952
+ if (template !== void 0) {
953
+ return template;
954
+ }
955
+ const key2 = result.strings.join(marker);
956
+ template = templateCache.keyString.get(key2);
957
+ if (template === void 0) {
958
+ template = new Template(result, result.getTemplateElement());
959
+ templateCache.keyString.set(key2, template);
960
+ }
961
+ templateCache.stringsArray.set(result.strings, template);
962
+ return template;
963
+ }
964
+ const templateCaches = new Map();
965
+ /**
966
+ * @license
967
+ * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
968
+ * This code may only be used under the BSD style license found at
969
+ * http://polymer.github.io/LICENSE.txt
970
+ * The complete set of authors may be found at
971
+ * http://polymer.github.io/AUTHORS.txt
972
+ * The complete set of contributors may be found at
973
+ * http://polymer.github.io/CONTRIBUTORS.txt
974
+ * Code distributed by Google as part of the polymer project is also
975
+ * subject to an additional IP rights grant found at
976
+ * http://polymer.github.io/PATENTS.txt
977
+ */
978
+ const parts = new WeakMap();
979
+ const render = (result, container, options) => {
980
+ let part2 = parts.get(container);
981
+ if (part2 === void 0) {
982
+ removeNodes(container, container.firstChild);
983
+ parts.set(container, part2 = new NodePart(Object.assign({ templateFactory }, options)));
984
+ part2.appendInto(container);
985
+ }
986
+ part2.setValue(result);
987
+ part2.commit();
988
+ };
989
+ /**
990
+ * @license
991
+ * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
992
+ * This code may only be used under the BSD style license found at
993
+ * http://polymer.github.io/LICENSE.txt
994
+ * The complete set of authors may be found at
995
+ * http://polymer.github.io/AUTHORS.txt
996
+ * The complete set of contributors may be found at
997
+ * http://polymer.github.io/CONTRIBUTORS.txt
998
+ * Code distributed by Google as part of the polymer project is also
999
+ * subject to an additional IP rights grant found at
1000
+ * http://polymer.github.io/PATENTS.txt
1001
+ */
1002
+ if (typeof window !== "undefined") {
1003
+ (window["litHtmlVersions"] || (window["litHtmlVersions"] = [])).push("1.4.1");
1004
+ }
1005
+ const html = (strings, ...values) => new TemplateResult(strings, values, "html", defaultTemplateProcessor);
1006
+ const svg = (strings, ...values) => new SVGTemplateResult(strings, values, "svg", defaultTemplateProcessor);
1007
+ const microtaskSet = new Set();
1008
+ function addMicrotask(func) {
1009
+ if (typeof func !== "function")
1010
+ return;
1011
+ if (!microtaskSet.size) {
1012
+ globalThis.queueMicrotask(() => {
1013
+ microtaskSet.forEach((func2) => func2());
1014
+ microtaskSet.clear();
1015
+ });
1016
+ }
1017
+ microtaskSet.delete(func);
1018
+ microtaskSet.add(func);
1019
+ }
1020
+ const microtaskStack = [];
1021
+ function execMicrotaskStack() {
1022
+ for (let i = microtaskStack.length - 1; i >= 0; i--) {
1023
+ microtaskStack[i]();
1024
+ }
1025
+ microtaskStack.length = 0;
1026
+ }
1027
+ function addMicrotaskToStack(func) {
1028
+ if (!microtaskStack.length) {
1029
+ addMicrotask(execMicrotaskStack);
1030
+ }
1031
+ microtaskStack.push(func);
1032
+ }
1033
+ function absoluteLocation(currentPath = "", relativePath = "") {
1034
+ const { pathname, search, hash } = new URL(relativePath, location.origin + currentPath);
1035
+ return pathname + search + hash;
1036
+ }
1037
+ class LinkedList extends (globalThis.EventTarget || Object) {
1038
+ constructor() {
1039
+ super(...arguments);
1040
+ __privateAdd(this, _delete);
1041
+ __privateAdd(this, _map, void 0);
1042
+ __privateAdd(this, _firstItem, void 0);
1043
+ __privateAdd(this, _lastItem, void 0);
1044
+ __privateSet(this, _map, new Map());
1045
+ }
1046
+ get size() {
1047
+ return __privateGet(this, _map).size;
1048
+ }
1049
+ add(value) {
1050
+ if (!__privateGet(this, _lastItem)) {
1051
+ this.dispatchEvent(new CustomEvent("start"));
1052
+ }
1053
+ const item = __privateMethod(this, _delete, delete_fn).call(this, value) || { value };
1054
+ item.prev = __privateGet(this, _lastItem);
1055
+ if (item.prev) {
1056
+ item.prev.next = item;
1057
+ }
1058
+ item.next = void 0;
1059
+ __privateSet(this, _lastItem, item);
1060
+ if (!__privateGet(this, _firstItem)) {
1061
+ __privateSet(this, _firstItem, item);
1062
+ }
1063
+ __privateGet(this, _map).set(value, item);
1064
+ }
1065
+ delete(value) {
1066
+ const deleteItem = __privateMethod(this, _delete, delete_fn).call(this, value);
1067
+ if (!__privateGet(this, _firstItem)) {
1068
+ this.dispatchEvent(new CustomEvent("end"));
1069
+ }
1070
+ return deleteItem;
1071
+ }
1072
+ get() {
1073
+ const firstItem = __privateGet(this, _firstItem);
1074
+ if (!firstItem)
1075
+ return;
1076
+ __privateMethod(this, _delete, delete_fn).call(this, firstItem.value);
1077
+ return firstItem.value;
1078
+ }
1079
+ }
1080
+ _map = new WeakMap();
1081
+ _firstItem = new WeakMap();
1082
+ _lastItem = new WeakMap();
1083
+ _delete = new WeakSet();
1084
+ delete_fn = function(value) {
1085
+ const existItem = __privateGet(this, _map).get(value);
1086
+ if (existItem) {
1087
+ if (existItem.prev) {
1088
+ existItem.prev.next = existItem.next;
1089
+ } else {
1090
+ __privateSet(this, _firstItem, existItem.next);
1091
+ }
1092
+ if (existItem.next) {
1093
+ existItem.next.prev = existItem.prev;
1094
+ } else {
1095
+ __privateSet(this, _lastItem, existItem.prev);
1096
+ }
1097
+ __privateGet(this, _map).delete(value);
1098
+ }
1099
+ return existItem;
1100
+ };
1101
+ class PropProxyMap extends WeakMap {
1102
+ get(ele) {
1103
+ let proxy = super.get(ele);
1104
+ if (!proxy) {
1105
+ proxy = {};
1106
+ this.set(ele, proxy);
1107
+ }
1108
+ return proxy;
1109
+ }
1110
+ }
1111
+ class QueryString extends URLSearchParams {
1112
+ constructor(param) {
1113
+ super(param);
1114
+ __privateAdd(this, _stringify, (value) => typeof value === "string" ? value : JSON.stringify(value));
1115
+ __privateAdd(this, _parse, (value) => {
1116
+ if (!value)
1117
+ return null;
1118
+ try {
1119
+ return JSON.parse(value);
1120
+ } catch {
1121
+ return null;
1122
+ }
1123
+ });
1124
+ }
1125
+ concat(param) {
1126
+ let query;
1127
+ if (typeof param === "string") {
1128
+ query = Object.fromEntries(new URLSearchParams(param).entries());
1129
+ } else {
1130
+ query = param;
1131
+ }
1132
+ Object.entries(query).forEach(([key2, value]) => {
1133
+ this.append(key2, __privateGet(this, _stringify).call(this, value));
1134
+ });
1135
+ }
1136
+ setAny(key2, value) {
1137
+ if (Array.isArray(value)) {
1138
+ this.delete(key2);
1139
+ value.forEach((e) => this.append(key2, __privateGet(this, _stringify).call(this, e)));
1140
+ } else {
1141
+ const v = __privateGet(this, _stringify).call(this, value);
1142
+ v ? this.set(key2, v) : this.delete(key2);
1143
+ }
1144
+ }
1145
+ getAny(key2) {
1146
+ return this.getAnyAll(key2)[0];
1147
+ }
1148
+ getAnyAll(key2) {
1149
+ return this.getAll(key2).filter((e) => e !== "").map((e) => __privateGet(this, _parse).call(this, e));
1150
+ }
1151
+ toString() {
1152
+ const string = super.toString();
1153
+ return string ? `?${string}` : "";
1154
+ }
1155
+ toJSON() {
1156
+ return this.toString();
1157
+ }
1158
+ }
1159
+ _stringify = new WeakMap();
1160
+ _parse = new WeakMap();
1161
+ function raw(arr, ...args) {
1162
+ return arr.reduce((prev, current, index) => {
1163
+ var _a2;
1164
+ return prev + ((_a2 = args[index - 1]) != null ? _a2 : "") + current;
1165
+ });
1166
+ }
1167
+ function css(arr, ...args) {
1168
+ return raw(arr, ...args);
1169
+ }
1170
+ const SheetToken = Symbol("sheet token");
1171
+ let useNativeCSSStyleSheet = true;
1172
+ let CSSStyleSheet = window.CSSStyleSheet;
1173
+ try {
1174
+ new CSSStyleSheet();
1175
+ } catch {
1176
+ useNativeCSSStyleSheet = false;
1177
+ CSSStyleSheet = class {
1178
+ constructor() {
1179
+ this.media = { mediaText: "" };
1180
+ this.style = "";
1181
+ this.replaceSync = (style) => this.style = style;
1182
+ }
1183
+ };
1184
+ }
1185
+ function createCSSSheet(rules, mediaQuery2 = "") {
1186
+ const styleSheet = new CSSStyleSheet();
1187
+ const sheet = {};
1188
+ styleSheet.media.mediaText = mediaQuery2;
1189
+ let style = "";
1190
+ if (typeof rules === "string") {
1191
+ style = rules;
1192
+ } else {
1193
+ Object.keys(rules).forEach((key2) => {
1194
+ sheet[key2] = `${key2}-${randomStr()}`;
1195
+ style += rules[key2].styledContent.replace(/&/g, sheet[key2]);
1196
+ });
1197
+ }
1198
+ styleSheet.replaceSync(style);
1199
+ sheet[SheetToken] = styleSheet;
1200
+ return sheet;
1201
+ }
1202
+ function randomStr(number = 5, origin = "0123456789abcdefghijklmnopqrstuvwxyz") {
1203
+ const len = origin.length;
1204
+ let str = "";
1205
+ for (let i = 0; i < number; i++) {
1206
+ str += origin[Math.floor(Math.random() * len)];
1207
+ }
1208
+ return str;
1209
+ }
1210
+ const nestingRuleRegExp = new RegExp("&.*{((.|\n)*)}", "g");
1211
+ function flatStyled(style, type) {
1212
+ const nestingRules = [];
1213
+ let styledContent = `& {${style.replace(nestingRuleRegExp, (substr) => {
1214
+ nestingRules.push(substr);
1215
+ return "";
1216
+ })}}` + nestingRules.join("");
1217
+ styledContent = styledContent.replace(/&/g, type === "class" ? ".&" : "#&");
1218
+ return { styledContent, type };
1219
+ }
1220
+ const styled = {
1221
+ class: (arr, ...args) => {
1222
+ const style = raw(arr, ...args);
1223
+ return flatStyled(style, "class");
1224
+ },
1225
+ id: (arr, ...args) => {
1226
+ const style = raw(arr, ...args);
1227
+ return flatStyled(style, "id");
1228
+ },
1229
+ keyframes: (arr, ...args) => {
1230
+ const keyframesContent = raw(arr, ...args);
1231
+ const styledContent = `@keyframes & {${keyframesContent}}`;
1232
+ return { styledContent, type: "keyframes" };
1233
+ }
1234
+ };
1235
+ function camelToKebabCase(str) {
1236
+ return str.replace(/[A-Z]/g, ($1) => "-" + $1.toLowerCase());
1237
+ }
1238
+ function kebabToCamelCase(str) {
1239
+ return str.replace(/-(.)/g, (_substr, $1) => $1.toUpperCase());
1240
+ }
1241
+ function cleanObject(o) {
1242
+ Object.keys(o).forEach((key2) => {
1243
+ const k = key2;
1244
+ delete o[k];
1245
+ });
1246
+ return o;
1247
+ }
1248
+ class GemError extends Error {
1249
+ constructor(msg) {
1250
+ super(msg);
1251
+ this.message = `gem: ${this.message}`;
1252
+ }
1253
+ }
1254
+ function isArrayChange(newValues, oldValues) {
1255
+ const length = newValues.length;
1256
+ if (oldValues.length !== length)
1257
+ return true;
1258
+ for (let i = 0; i < length; i++) {
1259
+ if (newValues[i] !== oldValues[i])
1260
+ return true;
1261
+ }
1262
+ return false;
1263
+ }
1264
+ function removeItems(target, items) {
1265
+ const set = new Set(items);
1266
+ return target.filter((e) => {
1267
+ if (set.has(e)) {
1268
+ set.delete(e);
1269
+ return false;
1270
+ }
1271
+ return true;
1272
+ });
1273
+ }
1274
+ function styleMap(object) {
1275
+ let styleString = "";
1276
+ for (const key2 in object) {
1277
+ if (object[key2] !== void 0) {
1278
+ styleString += `${camelToKebabCase(key2)}:${object[key2]};`;
1279
+ }
1280
+ }
1281
+ return styleString;
1282
+ }
1283
+ function classMap(obj) {
1284
+ let classList = " ";
1285
+ for (const className in obj) {
1286
+ if (obj[className]) {
1287
+ classList += `${className} `;
1288
+ }
1289
+ }
1290
+ return classList;
1291
+ }
1292
+ const partMap = classMap;
1293
+ const StoreListenerMap = new WeakMap();
1294
+ function createStore(originStore) {
1295
+ if (StoreListenerMap.has(originStore)) {
1296
+ throw new GemError("argument error");
1297
+ }
1298
+ StoreListenerMap.set(originStore, new Set());
1299
+ return originStore;
1300
+ }
1301
+ function createStoreSet(originStoreSet) {
1302
+ const keys = Object.keys(originStoreSet);
1303
+ keys.forEach((key2) => {
1304
+ createStore(originStoreSet[key2]);
1305
+ });
1306
+ return originStoreSet;
1307
+ }
1308
+ function updateStore(store2, value) {
1309
+ Object.assign(store2, value);
1310
+ const listeners = StoreListenerMap.get(store2);
1311
+ listeners == null ? void 0 : listeners.forEach((func) => {
1312
+ addMicrotask(func);
1313
+ });
1314
+ }
1315
+ function connect(store2, func) {
1316
+ const listeners = StoreListenerMap.get(store2);
1317
+ listeners == null ? void 0 : listeners.add(func);
1318
+ }
1319
+ function disconnect(store2, func) {
1320
+ const listeners = StoreListenerMap.get(store2);
1321
+ listeners == null ? void 0 : listeners.delete(func);
1322
+ }
1323
+ /**
1324
+ * @license
1325
+ * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
1326
+ * This code may only be used under the BSD style license found at
1327
+ * http://polymer.github.io/LICENSE.txt
1328
+ * The complete set of authors may be found at
1329
+ * http://polymer.github.io/AUTHORS.txt
1330
+ * The complete set of contributors may be found at
1331
+ * http://polymer.github.io/CONTRIBUTORS.txt
1332
+ * Code distributed by Google as part of the polymer project is also
1333
+ * subject to an additional IP rights grant found at
1334
+ * http://polymer.github.io/PATENTS.txt
1335
+ */
1336
+ const createAndInsertPart = (containerPart, beforePart) => {
1337
+ const container = containerPart.startNode.parentNode;
1338
+ const beforeNode = beforePart === void 0 ? containerPart.endNode : beforePart.startNode;
1339
+ const startNode = container.insertBefore(createMarker(), beforeNode);
1340
+ container.insertBefore(createMarker(), beforeNode);
1341
+ const newPart = new NodePart(containerPart.options);
1342
+ newPart.insertAfterNode(startNode);
1343
+ return newPart;
1344
+ };
1345
+ const updatePart = (part2, value) => {
1346
+ part2.setValue(value);
1347
+ part2.commit();
1348
+ return part2;
1349
+ };
1350
+ const insertPartBefore = (containerPart, part2, ref) => {
1351
+ const container = containerPart.startNode.parentNode;
1352
+ const beforeNode = ref ? ref.startNode : containerPart.endNode;
1353
+ const endNode = part2.endNode.nextSibling;
1354
+ if (endNode !== beforeNode) {
1355
+ reparentNodes(container, part2.startNode, endNode, beforeNode);
1356
+ }
1357
+ };
1358
+ const removePart = (part2) => {
1359
+ removeNodes(part2.startNode.parentNode, part2.startNode, part2.endNode.nextSibling);
1360
+ };
1361
+ const generateMap = (list, start, end) => {
1362
+ const map = new Map();
1363
+ for (let i = start; i <= end; i++) {
1364
+ map.set(list[i], i);
1365
+ }
1366
+ return map;
1367
+ };
1368
+ const partListCache = new WeakMap();
1369
+ const keyListCache = new WeakMap();
1370
+ const repeat = directive((items, keyFnOrTemplate, template) => {
1371
+ let keyFn;
1372
+ if (template === void 0) {
1373
+ template = keyFnOrTemplate;
1374
+ } else if (keyFnOrTemplate !== void 0) {
1375
+ keyFn = keyFnOrTemplate;
1376
+ }
1377
+ return (containerPart) => {
1378
+ if (!(containerPart instanceof NodePart)) {
1379
+ throw new Error("repeat can only be used in text bindings");
1380
+ }
1381
+ const oldParts = partListCache.get(containerPart) || [];
1382
+ const oldKeys = keyListCache.get(containerPart) || [];
1383
+ const newParts = [];
1384
+ const newValues = [];
1385
+ const newKeys = [];
1386
+ let index = 0;
1387
+ for (const item of items) {
1388
+ newKeys[index] = keyFn ? keyFn(item, index) : index;
1389
+ newValues[index] = template(item, index);
1390
+ index++;
1391
+ }
1392
+ let newKeyToIndexMap;
1393
+ let oldKeyToIndexMap;
1394
+ let oldHead = 0;
1395
+ let oldTail = oldParts.length - 1;
1396
+ let newHead = 0;
1397
+ let newTail = newValues.length - 1;
1398
+ while (oldHead <= oldTail && newHead <= newTail) {
1399
+ if (oldParts[oldHead] === null) {
1400
+ oldHead++;
1401
+ } else if (oldParts[oldTail] === null) {
1402
+ oldTail--;
1403
+ } else if (oldKeys[oldHead] === newKeys[newHead]) {
1404
+ newParts[newHead] = updatePart(oldParts[oldHead], newValues[newHead]);
1405
+ oldHead++;
1406
+ newHead++;
1407
+ } else if (oldKeys[oldTail] === newKeys[newTail]) {
1408
+ newParts[newTail] = updatePart(oldParts[oldTail], newValues[newTail]);
1409
+ oldTail--;
1410
+ newTail--;
1411
+ } else if (oldKeys[oldHead] === newKeys[newTail]) {
1412
+ newParts[newTail] = updatePart(oldParts[oldHead], newValues[newTail]);
1413
+ insertPartBefore(containerPart, oldParts[oldHead], newParts[newTail + 1]);
1414
+ oldHead++;
1415
+ newTail--;
1416
+ } else if (oldKeys[oldTail] === newKeys[newHead]) {
1417
+ newParts[newHead] = updatePart(oldParts[oldTail], newValues[newHead]);
1418
+ insertPartBefore(containerPart, oldParts[oldTail], oldParts[oldHead]);
1419
+ oldTail--;
1420
+ newHead++;
1421
+ } else {
1422
+ if (newKeyToIndexMap === void 0) {
1423
+ newKeyToIndexMap = generateMap(newKeys, newHead, newTail);
1424
+ oldKeyToIndexMap = generateMap(oldKeys, oldHead, oldTail);
1425
+ }
1426
+ if (!newKeyToIndexMap.has(oldKeys[oldHead])) {
1427
+ removePart(oldParts[oldHead]);
1428
+ oldHead++;
1429
+ } else if (!newKeyToIndexMap.has(oldKeys[oldTail])) {
1430
+ removePart(oldParts[oldTail]);
1431
+ oldTail--;
1432
+ } else {
1433
+ const oldIndex = oldKeyToIndexMap.get(newKeys[newHead]);
1434
+ const oldPart = oldIndex !== void 0 ? oldParts[oldIndex] : null;
1435
+ if (oldPart === null) {
1436
+ const newPart = createAndInsertPart(containerPart, oldParts[oldHead]);
1437
+ updatePart(newPart, newValues[newHead]);
1438
+ newParts[newHead] = newPart;
1439
+ } else {
1440
+ newParts[newHead] = updatePart(oldPart, newValues[newHead]);
1441
+ insertPartBefore(containerPart, oldPart, oldParts[oldHead]);
1442
+ oldParts[oldIndex] = null;
1443
+ }
1444
+ newHead++;
1445
+ }
1446
+ }
1447
+ }
1448
+ while (newHead <= newTail) {
1449
+ const newPart = createAndInsertPart(containerPart, newParts[newTail + 1]);
1450
+ updatePart(newPart, newValues[newHead]);
1451
+ newParts[newHead++] = newPart;
1452
+ }
1453
+ while (oldHead <= oldTail) {
1454
+ const oldPart = oldParts[oldHead++];
1455
+ if (oldPart !== null) {
1456
+ removePart(oldPart);
1457
+ }
1458
+ }
1459
+ partListCache.set(containerPart, newParts);
1460
+ keyListCache.set(containerPart, newKeys);
1461
+ };
1462
+ });
1463
+ /**
1464
+ * @license
1465
+ * Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
1466
+ * This code may only be used under the BSD style license found at
1467
+ * http://polymer.github.io/LICENSE.txt
1468
+ * The complete set of authors may be found at
1469
+ * http://polymer.github.io/AUTHORS.txt
1470
+ * The complete set of contributors may be found at
1471
+ * http://polymer.github.io/CONTRIBUTORS.txt
1472
+ * Code distributed by Google as part of the polymer project is also
1473
+ * subject to an additional IP rights grant found at
1474
+ * http://polymer.github.io/PATENTS.txt
1475
+ */
1476
+ const previousValues$1 = new WeakMap();
1477
+ const guard = directive((value, f) => (part2) => {
1478
+ const previousValue = previousValues$1.get(part2);
1479
+ if (Array.isArray(value)) {
1480
+ if (Array.isArray(previousValue) && previousValue.length === value.length && value.every((v, i) => v === previousValue[i])) {
1481
+ return;
1482
+ }
1483
+ } else if (previousValue === value && (value !== void 0 || previousValues$1.has(part2))) {
1484
+ return;
1485
+ }
1486
+ part2.setValue(f());
1487
+ previousValues$1.set(part2, Array.isArray(value) ? Array.from(value) : value);
1488
+ });
1489
+ /**
1490
+ * @license
1491
+ * Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
1492
+ * This code may only be used under the BSD style license found at
1493
+ * http://polymer.github.io/LICENSE.txt
1494
+ * The complete set of authors may be found at
1495
+ * http://polymer.github.io/AUTHORS.txt
1496
+ * The complete set of contributors may be found at
1497
+ * http://polymer.github.io/CONTRIBUTORS.txt
1498
+ * Code distributed by Google as part of the polymer project is also
1499
+ * subject to an additional IP rights grant found at
1500
+ * http://polymer.github.io/PATENTS.txt
1501
+ */
1502
+ const previousValues = new WeakMap();
1503
+ const ifDefined = directive((value) => (part2) => {
1504
+ const previousValue = previousValues.get(part2);
1505
+ if (value === void 0 && part2 instanceof AttributePart) {
1506
+ if (previousValue !== void 0 || !previousValues.has(part2)) {
1507
+ const name = part2.committer.name;
1508
+ part2.committer.element.removeAttribute(name);
1509
+ }
1510
+ } else if (value !== previousValue) {
1511
+ part2.setValue(value);
1512
+ }
1513
+ previousValues.set(part2, value);
1514
+ });
1515
+ var __accessCheck$1 = (obj, member, msg) => {
1516
+ if (!member.has(obj))
1517
+ throw TypeError("Cannot " + msg);
1518
+ };
1519
+ var __privateGet$1 = (obj, member, getter) => {
1520
+ __accessCheck$1(obj, member, "read from private field");
1521
+ return getter ? getter.call(obj) : member.get(obj);
1522
+ };
1523
+ var __privateAdd$1 = (obj, member, value) => {
1524
+ if (member.has(obj))
1525
+ throw TypeError("Cannot add the same private member more than once");
1526
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1527
+ };
1528
+ var __privateSet$1 = (obj, member, value, setter) => {
1529
+ __accessCheck$1(obj, member, "write to private field");
1530
+ setter ? setter.call(obj, value) : member.set(obj, value);
1531
+ return value;
1532
+ };
1533
+ var _renderRoot, _internals, _isAppendReason, _isAsync, _effectList, _momeList, _unmountCallback, _exec, _execEffect, _execMemo, _initEffect, _render, _shouldUpdate, _updateCallback, _update, _updated, _connectedCallback;
1534
+ function emptyFunction() {
1535
+ }
1536
+ function execCallback(fun) {
1537
+ typeof fun === "function" && fun();
1538
+ }
1539
+ const asyncRenderTaskList = new LinkedList();
1540
+ const tick = (timeStamp = performance.now()) => {
1541
+ if (performance.now() > timeStamp + 16)
1542
+ return requestAnimationFrame(tick);
1543
+ const task = asyncRenderTaskList.get();
1544
+ if (task) {
1545
+ task();
1546
+ tick(timeStamp);
1547
+ }
1548
+ };
1549
+ asyncRenderTaskList.addEventListener("start", () => addMicrotask(tick));
1550
+ const initSymbol = Symbol("init");
1551
+ const updateSymbol = Symbol("update");
1552
+ class GemElement extends HTMLElement {
1553
+ constructor({ isAsync, isLight, delegatesFocus } = {}) {
1554
+ super();
1555
+ __privateAdd$1(this, _renderRoot, void 0);
1556
+ __privateAdd$1(this, _internals, void 0);
1557
+ __privateAdd$1(this, _isAppendReason, void 0);
1558
+ __privateAdd$1(this, _isAsync, void 0);
1559
+ __privateAdd$1(this, _effectList, void 0);
1560
+ __privateAdd$1(this, _momeList, void 0);
1561
+ __privateAdd$1(this, _unmountCallback, void 0);
1562
+ this.setState = (payload) => {
1563
+ if (!this.state)
1564
+ throw new GemError("`state` not initialized");
1565
+ Object.assign(this.state, payload);
1566
+ addMicrotask(__privateGet$1(this, _update));
1567
+ };
1568
+ __privateAdd$1(this, _exec, (list) => {
1569
+ list == null ? void 0 : list.forEach((effectItem) => {
1570
+ const { callback, getDep, values, preCallback } = effectItem;
1571
+ const newValues = getDep == null ? void 0 : getDep();
1572
+ if (!getDep || !values || isArrayChange(values, newValues)) {
1573
+ execCallback(preCallback);
1574
+ effectItem.preCallback = callback(newValues, values);
1575
+ effectItem.values = newValues;
1576
+ }
1577
+ });
1578
+ });
1579
+ __privateAdd$1(this, _execEffect, () => {
1580
+ __privateGet$1(this, _exec).call(this, __privateGet$1(this, _effectList));
1581
+ });
1582
+ __privateAdd$1(this, _execMemo, () => {
1583
+ __privateGet$1(this, _exec).call(this, __privateGet$1(this, _momeList));
1584
+ });
1585
+ this.effect = (callback, getDep) => {
1586
+ if (!__privateGet$1(this, _effectList))
1587
+ __privateSet$1(this, _effectList, []);
1588
+ const effectItem = {
1589
+ callback,
1590
+ getDep,
1591
+ values: void 0,
1592
+ initialized: !!this.isConnected
1593
+ };
1594
+ if (this.isConnected) {
1595
+ effectItem.values = getDep == null ? void 0 : getDep();
1596
+ effectItem.preCallback = callback(effectItem.values);
1597
+ }
1598
+ __privateGet$1(this, _effectList).push(effectItem);
1599
+ };
1600
+ this.memo = (callback, getDep) => {
1601
+ if (!__privateGet$1(this, _momeList))
1602
+ __privateSet$1(this, _momeList, []);
1603
+ __privateGet$1(this, _momeList).push({
1604
+ callback,
1605
+ getDep,
1606
+ values: [Symbol()],
1607
+ initialized: this.isConnected
1608
+ });
1609
+ };
1610
+ __privateAdd$1(this, _initEffect, () => {
1611
+ var _a2;
1612
+ (_a2 = __privateGet$1(this, _effectList)) == null ? void 0 : _a2.forEach((effectItem) => {
1613
+ const { callback, getDep, initialized } = effectItem;
1614
+ if (!initialized) {
1615
+ effectItem.values = getDep == null ? void 0 : getDep();
1616
+ effectItem.preCallback = callback(effectItem.values);
1617
+ effectItem.initialized = true;
1618
+ }
1619
+ });
1620
+ });
1621
+ __privateAdd$1(this, _render, () => {
1622
+ var _a2, _b;
1623
+ __privateGet$1(this, _execMemo).call(this);
1624
+ const styles = useNativeCSSStyleSheet ? "" : html`${(_b = (_a2 = this.shadowRoot) == null ? void 0 : _a2.adoptedStyleSheets) == null ? void 0 : _b.map((e) => html`
1625
+ <style media=${e.media.mediaText}>
1626
+ ${e.style}
1627
+ </style>
1628
+ `)}`;
1629
+ if (this.render)
1630
+ return html`${this.render()}${styles}`;
1631
+ return __privateGet$1(this, _renderRoot) === this ? void 0 : html`<slot></slot>${styles}`;
1632
+ });
1633
+ __privateAdd$1(this, _shouldUpdate, () => {
1634
+ return this.shouldUpdate ? this.shouldUpdate() : true;
1635
+ });
1636
+ __privateAdd$1(this, _updateCallback, () => {
1637
+ if (this.isConnected && __privateGet$1(this, _shouldUpdate).call(this)) {
1638
+ const temp = __privateGet$1(this, _render).call(this);
1639
+ temp !== void 0 && render(temp, __privateGet$1(this, _renderRoot));
1640
+ addMicrotask(__privateGet$1(this, _updated));
1641
+ addMicrotask(__privateGet$1(this, _execEffect));
1642
+ }
1643
+ });
1644
+ __privateAdd$1(this, _update, () => {
1645
+ if (__privateGet$1(this, _isAsync)) {
1646
+ asyncRenderTaskList.add(__privateGet$1(this, _updateCallback));
1647
+ } else {
1648
+ __privateGet$1(this, _updateCallback).call(this);
1649
+ }
1650
+ });
1651
+ this.update = () => {
1652
+ addMicrotask(__privateGet$1(this, _update));
1653
+ };
1654
+ __privateAdd$1(this, _updated, () => {
1655
+ var _a2;
1656
+ (_a2 = this.updated) == null ? void 0 : _a2.call(this);
1657
+ });
1658
+ __privateAdd$1(this, _connectedCallback, () => {
1659
+ var _a2, _b, _c;
1660
+ if (__privateGet$1(this, _isAppendReason)) {
1661
+ __privateSet$1(this, _isAppendReason, false);
1662
+ return;
1663
+ }
1664
+ (_a2 = this.willMount) == null ? void 0 : _a2.call(this);
1665
+ const { observedStores, rootElement: rootElement2 } = this.constructor;
1666
+ observedStores == null ? void 0 : observedStores.forEach((store2) => {
1667
+ connect(store2, __privateGet$1(this, _update));
1668
+ });
1669
+ const temp = __privateGet$1(this, _render).call(this);
1670
+ temp !== void 0 && render(temp, __privateGet$1(this, _renderRoot));
1671
+ __privateSet$1(this, _unmountCallback, (_b = this.mounted) == null ? void 0 : _b.call(this));
1672
+ __privateGet$1(this, _initEffect).call(this);
1673
+ if (rootElement2 && ((_c = this.getRootNode().host) == null ? void 0 : _c.tagName) !== rootElement2.toUpperCase()) {
1674
+ throw new GemError(`not allow current root type`);
1675
+ }
1676
+ });
1677
+ addMicrotask(() => this[initSymbol] = false);
1678
+ this[initSymbol] = true;
1679
+ this[updateSymbol] = () => {
1680
+ if (this.isConnected) {
1681
+ addMicrotask(__privateGet$1(this, _update));
1682
+ }
1683
+ };
1684
+ __privateSet$1(this, _isAsync, isAsync);
1685
+ __privateSet$1(this, _renderRoot, isLight ? this : this.attachShadow({ mode: "open", delegatesFocus }));
1686
+ const { adoptedStyleSheets } = new.target;
1687
+ if (adoptedStyleSheets) {
1688
+ const sheets = adoptedStyleSheets.map((item) => item[SheetToken] || item);
1689
+ if (this.shadowRoot) {
1690
+ this.shadowRoot.adoptedStyleSheets = sheets;
1691
+ } else {
1692
+ this.effect(() => {
1693
+ const root = this.getRootNode();
1694
+ if (!useNativeCSSStyleSheet) {
1695
+ const ele = root === document ? document.body : root;
1696
+ ele._sheets = ele._sheets || {};
1697
+ sheets.forEach(({ style, media }) => {
1698
+ if (ele._sheets[style]) {
1699
+ ele._sheets[style].count++;
1700
+ } else {
1701
+ const s = document.createElement("style");
1702
+ s.innerHTML = style;
1703
+ s.media = media.mediaText;
1704
+ ele.append(s);
1705
+ ele._sheets[style] = { ele: s, count: 1 };
1706
+ }
1707
+ });
1708
+ return () => {
1709
+ sheets.forEach(({ style }) => {
1710
+ ele._sheets[style].count--;
1711
+ if (!ele._sheets[style].count) {
1712
+ delete ele._sheets[style];
1713
+ }
1714
+ });
1715
+ };
1716
+ } else {
1717
+ root.adoptedStyleSheets = [...root.adoptedStyleSheets, ...sheets];
1718
+ return () => {
1719
+ root.adoptedStyleSheets = removeItems(root.adoptedStyleSheets, sheets);
1720
+ };
1721
+ }
1722
+ }, () => []);
1723
+ }
1724
+ }
1725
+ }
1726
+ get internals() {
1727
+ if (!__privateGet$1(this, _internals)) {
1728
+ const getCustomStateSet = () => {
1729
+ const getV = (v) => v.replace(/-/g, "");
1730
+ return {
1731
+ has: (v) => getV(v) in this.dataset,
1732
+ add: (v) => {
1733
+ this.dataset[getV(v)] = "";
1734
+ },
1735
+ delete: (v) => delete this.dataset[getV(v)]
1736
+ };
1737
+ };
1738
+ if (!this.attachInternals) {
1739
+ this.attachInternals = () => {
1740
+ return { states: getCustomStateSet() };
1741
+ };
1742
+ }
1743
+ __privateSet$1(this, _internals, this.attachInternals());
1744
+ if (!__privateGet$1(this, _internals).states) {
1745
+ __privateGet$1(this, _internals).states = getCustomStateSet();
1746
+ }
1747
+ }
1748
+ return __privateGet$1(this, _internals);
1749
+ }
1750
+ attributeChangedCallback() {
1751
+ if (this.isConnected) {
1752
+ addMicrotask(__privateGet$1(this, _update));
1753
+ }
1754
+ }
1755
+ closestElement(constructorOrTag) {
1756
+ const isConstructor = typeof constructorOrTag === "function";
1757
+ const tagName = typeof constructorOrTag === "string" && constructorOrTag.toUpperCase();
1758
+ const getRootElement = (ele) => {
1759
+ const rootEle = ele.parentElement || ele.getRootNode().host;
1760
+ if (!rootEle)
1761
+ return null;
1762
+ if (isConstructor) {
1763
+ if (rootEle.constructor === constructorOrTag) {
1764
+ return rootEle;
1765
+ }
1766
+ } else if (rootEle.tagName === tagName) {
1767
+ return rootEle;
1768
+ }
1769
+ return getRootElement(rootEle);
1770
+ };
1771
+ return getRootElement(this);
1772
+ }
1773
+ connectedCallback() {
1774
+ if (__privateGet$1(this, _isAsync)) {
1775
+ asyncRenderTaskList.add(__privateGet$1(this, _connectedCallback));
1776
+ } else {
1777
+ __privateGet$1(this, _connectedCallback).call(this);
1778
+ }
1779
+ }
1780
+ disconnectedCallback() {
1781
+ var _a2, _b, _c;
1782
+ if (this.isConnected) {
1783
+ __privateSet$1(this, _isAppendReason, true);
1784
+ return;
1785
+ }
1786
+ const { observedStores } = this.constructor;
1787
+ observedStores == null ? void 0 : observedStores.forEach((store2) => {
1788
+ disconnect(store2, __privateGet$1(this, _update));
1789
+ });
1790
+ execCallback(__privateGet$1(this, _unmountCallback));
1791
+ (_a2 = this.unmounted) == null ? void 0 : _a2.call(this);
1792
+ (_b = __privateGet$1(this, _effectList)) == null ? void 0 : _b.forEach((effectItem) => {
1793
+ execCallback(effectItem.preCallback);
1794
+ });
1795
+ __privateSet$1(this, _momeList, (_c = __privateGet$1(this, _momeList)) == null ? void 0 : _c.filter(({ initialized }) => !initialized));
1796
+ }
1797
+ }
1798
+ _renderRoot = new WeakMap();
1799
+ _internals = new WeakMap();
1800
+ _isAppendReason = new WeakMap();
1801
+ _isAsync = new WeakMap();
1802
+ _effectList = new WeakMap();
1803
+ _momeList = new WeakMap();
1804
+ _unmountCallback = new WeakMap();
1805
+ _exec = new WeakMap();
1806
+ _execEffect = new WeakMap();
1807
+ _execMemo = new WeakMap();
1808
+ _initEffect = new WeakMap();
1809
+ _render = new WeakMap();
1810
+ _shouldUpdate = new WeakMap();
1811
+ _updateCallback = new WeakMap();
1812
+ _update = new WeakMap();
1813
+ _updated = new WeakMap();
1814
+ _connectedCallback = new WeakMap();
1815
+ const gemElementProxyMap = new PropProxyMap();
1816
+ function defineAttribute(target, prop, attr) {
1817
+ const { booleanAttributes, numberAttributes } = target.constructor;
1818
+ Object.defineProperty(target, prop, {
1819
+ configurable: true,
1820
+ get() {
1821
+ if (!(initSymbol in this))
1822
+ return;
1823
+ const that = this;
1824
+ const value = that.getAttribute(attr);
1825
+ if (booleanAttributes == null ? void 0 : booleanAttributes.has(attr)) {
1826
+ return value === null ? false : true;
1827
+ }
1828
+ if (numberAttributes == null ? void 0 : numberAttributes.has(attr)) {
1829
+ return Number(value);
1830
+ }
1831
+ return value || "";
1832
+ },
1833
+ set(v) {
1834
+ const that = this;
1835
+ const proxy = gemElementProxyMap.get(this);
1836
+ const hasSet = proxy[prop];
1837
+ const value = that.getAttribute(attr);
1838
+ if (this[initSymbol] && value !== null && !hasSet)
1839
+ return;
1840
+ proxy[prop] = true;
1841
+ const isBool = booleanAttributes == null ? void 0 : booleanAttributes.has(attr);
1842
+ if (v === null || v === void 0) {
1843
+ that.removeAttribute(attr);
1844
+ } else if (isBool) {
1845
+ that.toggleAttribute(attr, !!v);
1846
+ } else {
1847
+ if (value !== String(v))
1848
+ that.setAttribute(attr, String(v));
1849
+ }
1850
+ }
1851
+ });
1852
+ }
1853
+ const isEventHandleSymbol = Symbol("event handle");
1854
+ function defineProperty(target, prop, event, eventOptions) {
1855
+ Object.defineProperty(target, prop, {
1856
+ configurable: true,
1857
+ get() {
1858
+ const value = gemElementProxyMap.get(this)[prop];
1859
+ if (value || !event) {
1860
+ return value;
1861
+ } else {
1862
+ this[prop] = emptyFunction;
1863
+ return this[prop];
1864
+ }
1865
+ },
1866
+ set(v) {
1867
+ const that = this;
1868
+ const proxy = gemElementProxyMap.get(that);
1869
+ if (v !== proxy[prop]) {
1870
+ if (event) {
1871
+ proxy[prop] = (v == null ? void 0 : v[isEventHandleSymbol]) ? v : (detail, options) => {
1872
+ const evt = new CustomEvent(event, __spreadProps(__spreadValues(__spreadValues({}, options), eventOptions), { detail }));
1873
+ that.dispatchEvent(evt);
1874
+ v(detail, options);
1875
+ };
1876
+ proxy[prop][isEventHandleSymbol] = true;
1877
+ } else {
1878
+ proxy[prop] = v;
1879
+ this[updateSymbol]();
1880
+ }
1881
+ }
1882
+ }
1883
+ });
1884
+ }
1885
+ function defineRef(target, prop, ref) {
1886
+ Object.defineProperty(target, prop, {
1887
+ configurable: true,
1888
+ get() {
1889
+ const proxy = gemElementProxyMap.get(this);
1890
+ let refobject2 = proxy[prop];
1891
+ if (!refobject2) {
1892
+ const that = this;
1893
+ const ele = that.shadowRoot || that;
1894
+ refobject2 = {
1895
+ get ref() {
1896
+ return ref;
1897
+ },
1898
+ get element() {
1899
+ const gemReflects = [...ele.querySelectorAll("gem-reflect")].map((e) => e.target);
1900
+ for (const e of [ele, ...gemReflects]) {
1901
+ const result = e.querySelector(`[ref=${ref}]`);
1902
+ if (result)
1903
+ return result;
1904
+ }
1905
+ }
1906
+ };
1907
+ proxy[prop] = refobject2;
1908
+ }
1909
+ return refobject2;
1910
+ }
1911
+ });
1912
+ }
1913
+ function defineCSSState(target, prop, state2) {
1914
+ Object.defineProperty(target, prop, {
1915
+ configurable: true,
1916
+ get() {
1917
+ var _a2;
1918
+ const that = this;
1919
+ const { states } = that.internals;
1920
+ return (_a2 = states.has) == null ? void 0 : _a2.call(states, state2);
1921
+ },
1922
+ set(v) {
1923
+ const that = this;
1924
+ const { states } = that.internals;
1925
+ if (v) {
1926
+ states.add(state2);
1927
+ } else {
1928
+ states.delete(state2);
1929
+ }
1930
+ }
1931
+ });
1932
+ }
1933
+ const nativeDefineElement = customElements.define.bind(customElements);
1934
+ customElements.define = (name, cls, options) => {
1935
+ if (cls.prototype instanceof GemElement) {
1936
+ const { observedAttributes, observedPropertys, defineEvents, defineCSSStates, defineRefs } = cls;
1937
+ observedAttributes == null ? void 0 : observedAttributes.forEach((attr) => defineAttribute(cls.prototype, kebabToCamelCase(attr), attr));
1938
+ observedPropertys == null ? void 0 : observedPropertys.forEach((prop) => defineProperty(cls.prototype, prop));
1939
+ defineEvents == null ? void 0 : defineEvents.forEach((event) => defineProperty(cls.prototype, kebabToCamelCase(event), event));
1940
+ defineCSSStates == null ? void 0 : defineCSSStates.forEach((state2) => defineCSSState(cls.prototype, kebabToCamelCase(state2), `--${state2}`));
1941
+ defineRefs == null ? void 0 : defineRefs.forEach((ref) => defineRef(cls.prototype, kebabToCamelCase(ref), ref));
1942
+ }
1943
+ nativeDefineElement(name, cls, options);
1944
+ };
1945
+ function pushStaticField(target, field, member, isSet = false) {
1946
+ const cls = target.constructor;
1947
+ const current = cls[field];
1948
+ if (!cls.hasOwnProperty(field)) {
1949
+ Object.defineProperty(cls, field, {
1950
+ value: isSet ? new Set(current) : current ? Array.from(current) : []
1951
+ });
1952
+ }
1953
+ cls[field][isSet ? "add" : "push"](member);
1954
+ }
1955
+ function refobject(target, prop) {
1956
+ const ref = `${camelToKebabCase(prop)}-${randomStr()}`;
1957
+ pushStaticField(target, "defineRefs", ref);
1958
+ defineRef(target, prop, ref);
1959
+ }
1960
+ function defineAttr(target, prop, attr) {
1961
+ pushStaticField(target, "observedAttributes", attr);
1962
+ defineAttribute(target, prop, attr);
1963
+ }
1964
+ function attribute(target, prop) {
1965
+ defineAttr(target, prop, camelToKebabCase(prop));
1966
+ }
1967
+ function boolattribute(target, prop) {
1968
+ const attr = camelToKebabCase(prop);
1969
+ pushStaticField(target, "booleanAttributes", attr, true);
1970
+ defineAttr(target, prop, attr);
1971
+ }
1972
+ function numattribute(target, prop) {
1973
+ const attr = camelToKebabCase(prop);
1974
+ pushStaticField(target, "numberAttributes", attr, true);
1975
+ defineAttr(target, prop, attr);
1976
+ }
1977
+ function property(target, prop) {
1978
+ pushStaticField(target, "observedPropertys", prop);
1979
+ defineProperty(target, prop);
1980
+ }
1981
+ function state(target, prop) {
1982
+ const attr = camelToKebabCase(prop);
1983
+ pushStaticField(target, "defineCSSStates", attr);
1984
+ defineCSSState(target, prop, `--${attr}`);
1985
+ }
1986
+ function slot(target, prop) {
1987
+ const attr = camelToKebabCase(target[prop] || prop);
1988
+ target[prop] = attr;
1989
+ pushStaticField(target instanceof GemElement ? target : target.prototype, "defineSlots", attr);
1990
+ }
1991
+ function part(target, prop) {
1992
+ const attr = camelToKebabCase(target[prop] || prop);
1993
+ target[prop] = attr;
1994
+ pushStaticField(target instanceof GemElement ? target : target.prototype, "defineParts", attr);
1995
+ }
1996
+ function emitter(target, prop) {
1997
+ defineEmitter(target, prop);
1998
+ }
1999
+ function globalemitter(target, prop) {
2000
+ defineEmitter(target, prop, { bubbles: true, composed: true });
2001
+ }
2002
+ function defineEmitter(target, prop, options) {
2003
+ const event = camelToKebabCase(prop);
2004
+ pushStaticField(target, "defineEvents", event);
2005
+ defineProperty(target, prop, event, options);
2006
+ }
2007
+ function adoptedStyle(style) {
2008
+ return function(cls) {
2009
+ const con = cls;
2010
+ pushStaticField(con.prototype, "adoptedStyleSheets", style);
2011
+ };
2012
+ }
2013
+ function connectStore(store2) {
2014
+ return function(cls) {
2015
+ const con = cls;
2016
+ pushStaticField(con.prototype, "observedStores", store2);
2017
+ };
2018
+ }
2019
+ function rootElement(rootType) {
2020
+ return function(cls) {
2021
+ const con = cls;
2022
+ con.rootElement = rootType;
2023
+ };
2024
+ }
2025
+ function customElement(name) {
2026
+ return function(cls) {
2027
+ nativeDefineElement(name, cls);
2028
+ };
2029
+ }
2030
+ const history = window.history;
2031
+ const location$1 = window.location;
2032
+ const pushState = history.pushState.bind(history);
2033
+ const replaceState = history.replaceState.bind(history);
2034
+ let key = 0;
2035
+ const getKey = () => `${performance.now()}-${++key}`;
2036
+ const store = createStore({
2037
+ $hasCloseHandle: false,
2038
+ $hasOpenHandle: false,
2039
+ $hasShouldCloseHandle: false,
2040
+ $key: ""
2041
+ });
2042
+ const paramsMap = new Map();
2043
+ function validData({ $key, $hasCloseHandle, $hasOpenHandle, $hasShouldCloseHandle } = {}) {
2044
+ if (store.$key === $key)
2045
+ return;
2046
+ if ($key)
2047
+ throw new GemError("`$key` is not allowed");
2048
+ if ($hasCloseHandle)
2049
+ throw new GemError("`$hasCloseHandle` is not allowed");
2050
+ if ($hasOpenHandle)
2051
+ throw new GemError("`$hasOpenHandle` is not allowed");
2052
+ if ($hasShouldCloseHandle)
2053
+ throw new GemError("`$hasShouldCloseHandle` is not allowed");
2054
+ }
2055
+ function getUrlbarPath(internalPath) {
2056
+ return history.basePath ? history.basePath + internalPath : internalPath;
2057
+ }
2058
+ function getInternalPath(urlbarPath) {
2059
+ if (urlbarPath === history.basePath)
2060
+ return "/";
2061
+ return urlbarPath.replace(new RegExp(`^${history.basePath}/`), "/");
2062
+ }
2063
+ function initParams(params) {
2064
+ const current = paramsMap.get(store.$key) || {};
2065
+ const path = params.path ? absoluteLocation(current.path, params.path) : getInternalPath(location$1.pathname);
2066
+ const query = new QueryString(params.query || (params.path ? "" : location$1.search));
2067
+ const pathChanged = params.path && params.path !== current.path || params.query && String(params.query) !== String(current.query);
2068
+ const title = params.title || (pathChanged ? "" : document.title);
2069
+ const statusChanged = params.close || params.data || params.open || params.shouldClose;
2070
+ const hash = params.hash || (!pathChanged && statusChanged ? decodeURIComponent(location$1.hash) : "");
2071
+ return __spreadProps(__spreadValues({}, params), { title, path, query, hash });
2072
+ }
2073
+ function updateHistory(type, p) {
2074
+ validData(p.data);
2075
+ const params = initParams(p);
2076
+ const { title, path, query, hash, close, open: open2, shouldClose, data } = params;
2077
+ const state2 = __spreadValues({
2078
+ $hasCloseHandle: !!close,
2079
+ $hasOpenHandle: !!open2,
2080
+ $hasShouldCloseHandle: !!shouldClose,
2081
+ $key: getKey()
2082
+ }, data);
2083
+ paramsMap.set(state2.$key, params);
2084
+ updateStore(cleanObject(store), state2);
2085
+ const url = getUrlbarPath(path) + new QueryString(query) + hash;
2086
+ const prevHave = decodeURIComponent(location$1.hash);
2087
+ (type === "push" ? pushState : replaceState)(state2, title, url);
2088
+ if (prevHave !== hash)
2089
+ window.dispatchEvent(new CustomEvent("hashchange"));
2090
+ }
2091
+ function updateHistoryByNative(type, data, title, originUrl) {
2092
+ validData(data);
2093
+ const state2 = __spreadValues({
2094
+ $key: getKey()
2095
+ }, data || {});
2096
+ const { pathname, search, hash } = new URL(originUrl, location$1.origin + location$1.pathname);
2097
+ const params = initParams({ path: pathname, query: new QueryString(search), hash, title, data });
2098
+ paramsMap.set(state2.$key, params);
2099
+ updateStore(cleanObject(store), state2);
2100
+ const url = getUrlbarPath(pathname) + params.query + hash;
2101
+ const prevHash = location$1.hash;
2102
+ (type === "push" ? pushState : replaceState)(state2, title, url);
2103
+ if (prevHash !== hash)
2104
+ window.dispatchEvent(new CustomEvent("hashchange"));
2105
+ }
2106
+ const basePathStore = createStore({
2107
+ basePath: ""
2108
+ });
2109
+ window.addEventListener("hashchange", ({ isTrusted }) => {
2110
+ if (isTrusted) {
2111
+ history.replace({ hash: decodeURIComponent(location$1.hash) });
2112
+ }
2113
+ });
2114
+ Object.defineProperties(history, {
2115
+ basePath: {
2116
+ get() {
2117
+ return basePathStore.basePath;
2118
+ },
2119
+ set(basePath) {
2120
+ updateStore(basePathStore, { basePath });
2121
+ Object.assign(paramsMap.get(store.$key), { path: getInternalPath(location$1.pathname) });
2122
+ }
2123
+ },
2124
+ getParams: {
2125
+ value: function() {
2126
+ return paramsMap.get(store.$key);
2127
+ }
2128
+ },
2129
+ updateParams: {
2130
+ value: function(params) {
2131
+ Object.assign(paramsMap.get(store.$key), params);
2132
+ updateStore(store, {});
2133
+ }
2134
+ },
2135
+ store: {
2136
+ value: store
2137
+ },
2138
+ push: {
2139
+ value: function(params) {
2140
+ history.pushState(params, "");
2141
+ }
2142
+ },
2143
+ pushIgnoreCloseHandle: {
2144
+ value: function(params) {
2145
+ var _a2, _b;
2146
+ if (store.$hasCloseHandle) {
2147
+ (_b = (_a2 = paramsMap.get(store.$key)) == null ? void 0 : _a2.close) == null ? void 0 : _b.call(_a2);
2148
+ history.replace(params);
2149
+ } else {
2150
+ history.push(params);
2151
+ }
2152
+ }
2153
+ },
2154
+ replace: {
2155
+ value: function(params) {
2156
+ updateHistory("replace", params);
2157
+ }
2158
+ }
2159
+ });
2160
+ history.pushState = function(data, title, path) {
2161
+ if (path) {
2162
+ updateHistoryByNative("push", data, title, path);
2163
+ } else {
2164
+ updateHistory("push", data);
2165
+ }
2166
+ };
2167
+ history.replaceState = function(data, title, path) {
2168
+ updateHistoryByNative("replace", data, title, path);
2169
+ };
2170
+ if (!history.state) {
2171
+ const { pathname, search, hash } = location$1;
2172
+ history.replace({ path: pathname, query: search, hash });
2173
+ } else if (history.state.$hasCloseHandle) {
2174
+ updateStore(store, history.state);
2175
+ const params = initParams({ title: document.title });
2176
+ paramsMap.set(store.$key, params);
2177
+ history.back();
2178
+ } else {
2179
+ const params = initParams({ title: document.title, hash: location$1.hash });
2180
+ updateStore(store, __spreadValues({
2181
+ $key: getKey()
2182
+ }, history.state || {}));
2183
+ paramsMap.set(store.$key, params);
2184
+ }
2185
+ const titleStore = createStore({ title: "" });
2186
+ connect(titleStore, () => {
2187
+ const params = paramsMap.get(store.$key);
2188
+ if (params) {
2189
+ params.title = titleStore.title;
2190
+ }
2191
+ });
2192
+ connect(store, () => {
2193
+ const { title } = history.getParams();
2194
+ if (title !== titleStore.title) {
2195
+ updateStore(titleStore, { title });
2196
+ }
2197
+ });
2198
+ let navigating = false;
2199
+ window.addEventListener("popstate", (event) => {
2200
+ var _a2, _b;
2201
+ const newState = event.state;
2202
+ if (!(newState == null ? void 0 : newState.$key)) {
2203
+ return;
2204
+ }
2205
+ if (navigating) {
2206
+ navigating = false;
2207
+ return;
2208
+ }
2209
+ if (!paramsMap.has(newState.$key)) {
2210
+ const { pathname, search, hash } = location$1;
2211
+ paramsMap.set(newState.$key, {
2212
+ path: pathname,
2213
+ query: new QueryString(search),
2214
+ hash,
2215
+ title: document.title,
2216
+ data: newState
2217
+ });
2218
+ }
2219
+ const prevState = store;
2220
+ if (parseFloat(newState.$key) > parseFloat(prevState.$key) && newState.$hasOpenHandle) {
2221
+ (_b = (_a2 = paramsMap.get(newState.$key)) == null ? void 0 : _a2.open) == null ? void 0 : _b.call(_a2);
2222
+ } else if (prevState.$hasCloseHandle) {
2223
+ const prevParams = paramsMap.get(prevState.$key);
2224
+ const closeHandle = prevParams == null ? void 0 : prevParams.close;
2225
+ const shouldCloseHandle = prevParams == null ? void 0 : prevParams.shouldClose;
2226
+ const notAllowClose = shouldCloseHandle && !shouldCloseHandle();
2227
+ if (notAllowClose) {
2228
+ navigating = true;
2229
+ history.forward();
2230
+ return;
2231
+ } else {
2232
+ if (closeHandle) {
2233
+ closeHandle();
2234
+ } else if (newState.$hasCloseHandle) {
2235
+ navigating = true;
2236
+ history.back();
2237
+ }
2238
+ }
2239
+ }
2240
+ updateStore(cleanObject(store), newState);
2241
+ });
2242
+ var __defProp$6 = Object.defineProperty;
2243
+ var __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor;
2244
+ var __decorateClass$6 = (decorators, target, key2, kind) => {
2245
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key2) : target;
2246
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
2247
+ if (decorator = decorators[i])
2248
+ result = (kind ? decorator(target, key2, result) : decorator(result)) || result;
2249
+ if (kind && result)
2250
+ __defProp$6(target, key2, result);
2251
+ return result;
2252
+ };
2253
+ var __accessCheck2 = (obj, member, msg) => {
2254
+ if (!member.has(obj))
2255
+ throw TypeError("Cannot " + msg);
2256
+ };
2257
+ var __privateGet2 = (obj, member, getter) => {
2258
+ __accessCheck2(obj, member, "read from private field");
2259
+ return getter ? getter.call(obj) : member.get(obj);
2260
+ };
2261
+ var __privateAdd2 = (obj, member, value) => {
2262
+ if (member.has(obj))
2263
+ throw TypeError("Cannot add the same private member more than once");
2264
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
2265
+ };
2266
+ var __privateSet2 = (obj, member, value, setter) => {
2267
+ __accessCheck2(obj, member, "write to private field");
2268
+ setter ? setter.call(obj, value) : member.set(obj, value);
2269
+ return value;
2270
+ };
2271
+ var _lastLoader, _updateLocationStore, _setContent;
2272
+ class ParamsRegExp extends RegExp {
2273
+ constructor(pattern) {
2274
+ const namePosition = {};
2275
+ let i = 0;
2276
+ super(`^${pattern.replace(/:([^/$]+)/g, (_m, name) => {
2277
+ namePosition[name] = i++;
2278
+ return `([^/]+)`;
2279
+ }).replace("*", ".*")}$`, "i");
2280
+ this.namePosition = namePosition;
2281
+ }
2282
+ }
2283
+ function matchPath(pattern, path) {
2284
+ const reg = new ParamsRegExp(pattern);
2285
+ const matchResult = path.match(reg) || `${path}/`.match(reg);
2286
+ if (!matchResult)
2287
+ return null;
2288
+ const params = {};
2289
+ if (matchResult) {
2290
+ Object.keys(reg.namePosition).forEach((name) => {
2291
+ params[name] = matchResult[reg.namePosition[name] + 1];
2292
+ });
2293
+ }
2294
+ return params;
2295
+ }
2296
+ function createPath(route, options) {
2297
+ let path = route.pattern;
2298
+ const params = options == null ? void 0 : options.params;
2299
+ if (params) {
2300
+ Object.keys(params).forEach((key2) => {
2301
+ path = path.replace(new RegExp(`:${key2}`, "g"), params[key2]);
2302
+ });
2303
+ }
2304
+ return path;
2305
+ }
2306
+ function createHistoryParams(route, options) {
2307
+ const path = createPath(route, options);
2308
+ return __spreadValues({
2309
+ path
2310
+ }, options);
2311
+ }
2312
+ let GemRouteElement = class extends GemElement {
2313
+ constructor({ isLight, routes } = {}) {
2314
+ super({ isLight });
2315
+ this.currentParams = {};
2316
+ __privateAdd2(this, _lastLoader, void 0);
2317
+ this.state = {
2318
+ content: void 0
2319
+ };
2320
+ __privateAdd2(this, _updateLocationStore, () => {
2321
+ if (this.locationStore) {
2322
+ const { path, query, data } = history.getParams();
2323
+ updateStore(this.locationStore, {
2324
+ path,
2325
+ params: this.currentParams,
2326
+ query,
2327
+ data
2328
+ });
2329
+ }
2330
+ });
2331
+ __privateAdd2(this, _setContent, (route, params, content) => {
2332
+ __privateSet2(this, _lastLoader, void 0);
2333
+ this.currentRoute = route;
2334
+ this.currentParams = params;
2335
+ this.setState({ content });
2336
+ this.routechange(this.currentRoute);
2337
+ const title = route == null ? void 0 : route.title;
2338
+ if (title)
2339
+ updateStore(titleStore, { title });
2340
+ __privateGet2(this, _updateLocationStore).call(this);
2341
+ });
2342
+ this.routes = routes;
2343
+ }
2344
+ mounted() {
2345
+ this.effect(([key2, path], old) => {
2346
+ if (old && key2 === old[0] && path === old[1]) {
2347
+ __privateGet2(this, _updateLocationStore).call(this);
2348
+ return;
2349
+ }
2350
+ const { route, params = {} } = GemRouteElement.findRoute(this.routes, path);
2351
+ const { redirect, content, getContent } = route || {};
2352
+ if (redirect) {
2353
+ history.replace({ path: redirect });
2354
+ return;
2355
+ }
2356
+ const contentOrLoader = content || (getContent == null ? void 0 : getContent(params));
2357
+ if (contentOrLoader instanceof Promise) {
2358
+ this.loading(route);
2359
+ __privateSet2(this, _lastLoader, contentOrLoader);
2360
+ const isSomeLoader = () => __privateGet2(this, _lastLoader) === contentOrLoader;
2361
+ contentOrLoader.then((content2) => {
2362
+ if (isSomeLoader())
2363
+ __privateGet2(this, _setContent).call(this, route, params, content2);
2364
+ }).catch((err) => {
2365
+ if (isSomeLoader())
2366
+ this.error(err);
2367
+ });
2368
+ return;
2369
+ }
2370
+ __privateGet2(this, _setContent).call(this, route, params, contentOrLoader);
2371
+ }, () => {
2372
+ const { path } = history.getParams();
2373
+ return [this.key, path, location.search];
2374
+ });
2375
+ }
2376
+ shouldUpdate() {
2377
+ if (this.inert)
2378
+ return false;
2379
+ return true;
2380
+ }
2381
+ render() {
2382
+ const { content } = this.state;
2383
+ if (!this.shadowRoot)
2384
+ return html`${content}`;
2385
+ return html`
2386
+ <style>
2387
+ :host,
2388
+ :not(:defined) {
2389
+ display: contents;
2390
+ }
2391
+ </style>
2392
+ ${content != null ? content : html`<slot></slot>`}
2393
+ `;
2394
+ }
2395
+ };
2396
+ _lastLoader = new WeakMap();
2397
+ _updateLocationStore = new WeakMap();
2398
+ _setContent = new WeakMap();
2399
+ GemRouteElement.createLocationStore = () => {
2400
+ const { path, query, data } = history.getParams();
2401
+ return createStore({ path, query, data, params: {} });
2402
+ };
2403
+ GemRouteElement.findRoute = (target = [], path) => {
2404
+ let defaultRoute = null;
2405
+ let routes;
2406
+ if (target instanceof Array) {
2407
+ routes = target;
2408
+ } else {
2409
+ routes = Object.values(target);
2410
+ }
2411
+ for (const route of routes) {
2412
+ if (route.pattern === "*") {
2413
+ defaultRoute = route;
2414
+ } else {
2415
+ const params = matchPath(route.pattern, path);
2416
+ if (params) {
2417
+ return { route, params };
2418
+ }
2419
+ }
2420
+ }
2421
+ return { route: defaultRoute };
2422
+ };
2423
+ __decorateClass$6([
2424
+ property
2425
+ ], GemRouteElement.prototype, "routes", 2);
2426
+ __decorateClass$6([
2427
+ property
2428
+ ], GemRouteElement.prototype, "locationStore", 2);
2429
+ __decorateClass$6([
2430
+ property
2431
+ ], GemRouteElement.prototype, "key", 2);
2432
+ __decorateClass$6([
2433
+ emitter
2434
+ ], GemRouteElement.prototype, "routechange", 2);
2435
+ __decorateClass$6([
2436
+ emitter
2437
+ ], GemRouteElement.prototype, "loading", 2);
2438
+ __decorateClass$6([
2439
+ emitter
2440
+ ], GemRouteElement.prototype, "error", 2);
2441
+ GemRouteElement = __decorateClass$6([
2442
+ connectStore(history.store),
2443
+ customElement("gem-route")
2444
+ ], GemRouteElement);
2445
+ let GemLightRouteElement = class extends GemRouteElement {
2446
+ constructor(options = {}) {
2447
+ super(__spreadProps(__spreadValues({}, options), { isLight: true }));
2448
+ }
2449
+ };
2450
+ GemLightRouteElement = __decorateClass$6([
2451
+ customElement("gem-light-route")
2452
+ ], GemLightRouteElement);
2453
+ var __defProp$5 = Object.defineProperty;
2454
+ var __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor;
2455
+ var __decorateClass$5 = (decorators, target, key2, kind) => {
2456
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key2) : target;
2457
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
2458
+ if (decorator = decorators[i])
2459
+ result = (kind ? decorator(target, key2, result) : decorator(result)) || result;
2460
+ if (kind && result)
2461
+ __defProp$5(target, key2, result);
2462
+ return result;
2463
+ };
2464
+ let GemLinkElement = class extends GemElement {
2465
+ constructor() {
2466
+ super();
2467
+ this.clickHandle = async (e) => {
2468
+ var _a2;
2469
+ const pathInfo = this.getPathInfo();
2470
+ if (!pathInfo)
2471
+ return;
2472
+ if (this.isExternal(pathInfo)) {
2473
+ switch (this.target) {
2474
+ case "_self":
2475
+ window.location.href = pathInfo;
2476
+ return;
2477
+ case "_parent":
2478
+ window.parent.location.href = pathInfo;
2479
+ return;
2480
+ case "_top":
2481
+ window.top.location.href = pathInfo;
2482
+ return;
2483
+ default:
2484
+ window.open(pathInfo);
2485
+ return;
2486
+ }
2487
+ }
2488
+ const { path, query, hash } = history.getParams();
2489
+ if (path + query + hash === pathInfo) {
2490
+ return;
2491
+ }
2492
+ e.stopPropagation();
2493
+ await ((_a2 = this.prepare) == null ? void 0 : _a2.call(this));
2494
+ if (this.route) {
2495
+ history.pushIgnoreCloseHandle(__spreadProps(__spreadValues({}, createHistoryParams(this.route, this.options)), {
2496
+ title: this.route.title || this.docTitle
2497
+ }));
2498
+ } else if (this.href) {
2499
+ const { pathname, search, hash: hash2 } = new URL(pathInfo, location.origin);
2500
+ history.pushIgnoreCloseHandle({
2501
+ path: pathname,
2502
+ query: search,
2503
+ hash: hash2,
2504
+ title: this.docTitle
2505
+ });
2506
+ } else {
2507
+ history.pushIgnoreCloseHandle({ path: this.path, query: this.query, hash: this.hash, title: this.docTitle });
2508
+ }
2509
+ };
2510
+ this.preventDefault = (e) => {
2511
+ e.preventDefault();
2512
+ };
2513
+ this.addEventListener("click", this.clickHandle);
2514
+ }
2515
+ getPathInfo() {
2516
+ var _a2, _b;
2517
+ if (this.route) {
2518
+ const queryProp = ((_a2 = this.options) == null ? void 0 : _a2.query) || "";
2519
+ const hashProp = ((_b = this.options) == null ? void 0 : _b.hash) || "";
2520
+ return createPath(this.route, this.options) + queryProp + hashProp;
2521
+ } else {
2522
+ const url = this.href || this.path + this.query + this.hash;
2523
+ const { path, query } = history.getParams();
2524
+ if (url.startsWith("#")) {
2525
+ return `${path}${query}${url}`;
2526
+ } else if (url.startsWith("?")) {
2527
+ return `${path}${url}`;
2528
+ } else if (url.startsWith(".")) {
2529
+ return absoluteLocation(path, url);
2530
+ } else {
2531
+ return url;
2532
+ }
2533
+ }
2534
+ }
2535
+ isExternal(pathInfo) {
2536
+ return !pathInfo.startsWith("/");
2537
+ }
2538
+ render(pathInfo = this.getPathInfo()) {
2539
+ return html`
2540
+ <style>
2541
+ :host {
2542
+ /* link default style */
2543
+ cursor: pointer;
2544
+ color: blue;
2545
+ text-decoration: underline;
2546
+ }
2547
+ a {
2548
+ all: unset;
2549
+ display: contents;
2550
+ }
2551
+ a:visited {
2552
+ color: unset;
2553
+ }
2554
+ </style>
2555
+ <a
2556
+ part=${this.link}
2557
+ @click=${this.preventDefault}
2558
+ href=${ifDefined(this.hint === "off" ? void 0 : this.isExternal(pathInfo) ? pathInfo : new URL(history.basePath + pathInfo, location.origin).toString())}
2559
+ >
2560
+ <slot></slot>
2561
+ </a>
2562
+ `;
2563
+ }
2564
+ };
2565
+ __decorateClass$5([
2566
+ attribute
2567
+ ], GemLinkElement.prototype, "href", 2);
2568
+ __decorateClass$5([
2569
+ attribute
2570
+ ], GemLinkElement.prototype, "target", 2);
2571
+ __decorateClass$5([
2572
+ attribute
2573
+ ], GemLinkElement.prototype, "path", 2);
2574
+ __decorateClass$5([
2575
+ attribute
2576
+ ], GemLinkElement.prototype, "query", 2);
2577
+ __decorateClass$5([
2578
+ attribute
2579
+ ], GemLinkElement.prototype, "hash", 2);
2580
+ __decorateClass$5([
2581
+ attribute
2582
+ ], GemLinkElement.prototype, "docTitle", 2);
2583
+ __decorateClass$5([
2584
+ attribute
2585
+ ], GemLinkElement.prototype, "hint", 2);
2586
+ __decorateClass$5([
2587
+ property
2588
+ ], GemLinkElement.prototype, "route", 2);
2589
+ __decorateClass$5([
2590
+ property
2591
+ ], GemLinkElement.prototype, "options", 2);
2592
+ __decorateClass$5([
2593
+ property
2594
+ ], GemLinkElement.prototype, "prepare", 2);
2595
+ __decorateClass$5([
2596
+ part
2597
+ ], GemLinkElement.prototype, "link", 2);
2598
+ GemLinkElement = __decorateClass$5([
2599
+ customElement("gem-link"),
2600
+ connectStore(basePathStore)
2601
+ ], GemLinkElement);
2602
+ let GemActiveLinkElement = class extends GemLinkElement {
2603
+ render() {
2604
+ const { path, query, hash } = history.getParams();
2605
+ const isMatchPattern = this.pattern && matchPath(this.pattern, path);
2606
+ const pathInfo = this.getPathInfo();
2607
+ if (isMatchPattern || path + query + hash === pathInfo) {
2608
+ this.active = true;
2609
+ } else {
2610
+ this.active = false;
2611
+ }
2612
+ return super.render(pathInfo);
2613
+ }
2614
+ };
2615
+ __decorateClass$5([
2616
+ attribute
2617
+ ], GemActiveLinkElement.prototype, "pattern", 2);
2618
+ __decorateClass$5([
2619
+ state
2620
+ ], GemActiveLinkElement.prototype, "active", 2);
2621
+ GemActiveLinkElement = __decorateClass$5([
2622
+ customElement("gem-active-link"),
2623
+ connectStore(history.store)
2624
+ ], GemActiveLinkElement);
2625
+ var __defProp$4 = Object.defineProperty;
2626
+ var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
2627
+ var __decorateClass$4 = (decorators, target, key2, kind) => {
2628
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key2) : target;
2629
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
2630
+ if (decorator = decorators[i])
2631
+ result = (kind ? decorator(target, key2, result) : decorator(result)) || result;
2632
+ if (kind && result)
2633
+ __defProp$4(target, key2, result);
2634
+ return result;
2635
+ };
2636
+ let GemTitleElement = class extends GemElement {
2637
+ static setTitle(title) {
2638
+ updateStore(titleStore, { title });
2639
+ }
2640
+ static updateTitle(str = "", suffix = "") {
2641
+ const { title } = titleStore;
2642
+ if (title && title !== GemTitleElement.defaultTitle) {
2643
+ GemTitleElement.title = title;
2644
+ document.title = GemTitleElement.title + suffix;
2645
+ } else if (str) {
2646
+ GemTitleElement.title = str;
2647
+ document.title = GemTitleElement.title + suffix;
2648
+ } else {
2649
+ GemTitleElement.title = GemTitleElement.defaultTitle;
2650
+ document.title = GemTitleElement.title;
2651
+ }
2652
+ }
2653
+ constructor() {
2654
+ super();
2655
+ new MutationObserver(() => this.update()).observe(this, { childList: true, characterData: true, subtree: true });
2656
+ }
2657
+ render() {
2658
+ GemTitleElement.updateTitle(this.textContent || "", this.suffix);
2659
+ if (this.hidden) {
2660
+ return html``;
2661
+ }
2662
+ return html`${GemTitleElement.title}`;
2663
+ }
2664
+ };
2665
+ GemTitleElement.title = document.title;
2666
+ GemTitleElement.defaultTitle = document.title;
2667
+ GemTitleElement.defaultSuffix = ` - ${document.title}`;
2668
+ __decorateClass$4([
2669
+ attribute
2670
+ ], GemTitleElement.prototype, "suffix", 2);
2671
+ GemTitleElement = __decorateClass$4([
2672
+ connectStore(titleStore),
2673
+ customElement("gem-title")
2674
+ ], GemTitleElement);
2675
+ connect(titleStore, GemTitleElement.updateTitle);
2676
+ var __defProp$3 = Object.defineProperty;
2677
+ var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
2678
+ var __decorateClass$3 = (decorators, target, key2, kind) => {
2679
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key2) : target;
2680
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
2681
+ if (decorator = decorators[i])
2682
+ result = (kind ? decorator(target, key2, result) : decorator(result)) || result;
2683
+ if (kind && result)
2684
+ __defProp$3(target, key2, result);
2685
+ return result;
2686
+ };
2687
+ const eleCache = new Map();
2688
+ let GemUseElement = class extends GemElement {
2689
+ getContent() {
2690
+ const ele = this.element || (this.selector ? (this.root || document).querySelector(this.selector) : null);
2691
+ if (typeof ele === "string") {
2692
+ let temp = eleCache.get(ele);
2693
+ if (!temp) {
2694
+ temp = document.createElement("template");
2695
+ temp.innerHTML = ele;
2696
+ eleCache.set(ele, temp);
2697
+ }
2698
+ return temp.content.cloneNode(true);
2699
+ } else if (ele instanceof HTMLTemplateElement) {
2700
+ return ele.content.cloneNode(true);
2701
+ } else {
2702
+ return ele == null ? void 0 : ele.cloneNode(true);
2703
+ }
2704
+ }
2705
+ render() {
2706
+ return html`
2707
+ <style>
2708
+ :host {
2709
+ position: relative;
2710
+ }
2711
+ :host(:not([hidden])) {
2712
+ display: inline-flex;
2713
+ align-items: center;
2714
+ }
2715
+ svg {
2716
+ width: 100%;
2717
+ height: 100%;
2718
+ }
2719
+ </style>
2720
+ ${this.getContent()}
2721
+ <slot></slot>
2722
+ `;
2723
+ }
2724
+ };
2725
+ __decorateClass$3([
2726
+ attribute
2727
+ ], GemUseElement.prototype, "selector", 2);
2728
+ __decorateClass$3([
2729
+ property
2730
+ ], GemUseElement.prototype, "root", 2);
2731
+ __decorateClass$3([
2732
+ property
2733
+ ], GemUseElement.prototype, "element", 2);
2734
+ __decorateClass$3([
2735
+ state
2736
+ ], GemUseElement.prototype, "active", 2);
2737
+ GemUseElement = __decorateClass$3([
2738
+ customElement("gem-use")
2739
+ ], GemUseElement);
2740
+ var __defProp$2 = Object.defineProperty;
2741
+ var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
2742
+ var __decorateClass$2 = (decorators, target, key2, kind) => {
2743
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key2) : target;
2744
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
2745
+ if (decorator = decorators[i])
2746
+ result = (kind ? decorator(target, key2, result) : decorator(result)) || result;
2747
+ if (kind && result)
2748
+ __defProp$2(target, key2, result);
2749
+ return result;
2750
+ };
2751
+ let GemUnsafeElement = class extends GemElement {
2752
+ constructor() {
2753
+ super();
2754
+ this.effect(() => {
2755
+ if (this.shadowRoot) {
2756
+ this.shadowRoot.innerHTML = `
2757
+ <style>
2758
+ :host {
2759
+ display: contents;
2760
+ }
2761
+ ${this.contentcss}
2762
+ </style>
2763
+ ${this.content}
2764
+ `;
2765
+ }
2766
+ }, () => [this.content, this.contentcss]);
2767
+ }
2768
+ render() {
2769
+ return void 0;
2770
+ }
2771
+ };
2772
+ __decorateClass$2([
2773
+ attribute
2774
+ ], GemUnsafeElement.prototype, "content", 2);
2775
+ __decorateClass$2([
2776
+ attribute
2777
+ ], GemUnsafeElement.prototype, "contentcss", 2);
2778
+ GemUnsafeElement = __decorateClass$2([
2779
+ customElement("gem-unsafe")
2780
+ ], GemUnsafeElement);
2781
+ var __defProp$1 = Object.defineProperty;
2782
+ var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
2783
+ var __decorateClass$1 = (decorators, target, key2, kind) => {
2784
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key2) : target;
2785
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
2786
+ if (decorator = decorators[i])
2787
+ result = (kind ? decorator(target, key2, result) : decorator(result)) || result;
2788
+ if (kind && result)
2789
+ __defProp$1(target, key2, result);
2790
+ return result;
2791
+ };
2792
+ document.querySelectorAll("[data-reflect]").forEach((e) => e.remove());
2793
+ let GemReflectElement = class extends GemElement {
2794
+ constructor() {
2795
+ super({ isLight: true });
2796
+ this.target = document.head;
2797
+ this.hidden = true;
2798
+ this.effect(() => {
2799
+ const childNodes = [...this.childNodes];
2800
+ childNodes.forEach((node) => {
2801
+ if (node instanceof HTMLElement) {
2802
+ node.dataset.reflect = "";
2803
+ }
2804
+ this.target.append(node);
2805
+ });
2806
+ return () => {
2807
+ childNodes.forEach((node) => node.remove());
2808
+ };
2809
+ }, () => [this.target]);
2810
+ }
2811
+ };
2812
+ __decorateClass$1([
2813
+ property
2814
+ ], GemReflectElement.prototype, "target", 2);
2815
+ GemReflectElement = __decorateClass$1([
2816
+ customElement("gem-reflect")
2817
+ ], GemReflectElement);
2818
+ const open = Symbol("open mark");
2819
+ function createModalClass(options) {
2820
+ var _a2;
2821
+ return _a2 = class extends GemElement {
2822
+ constructor() {
2823
+ super();
2824
+ this.label = "";
2825
+ this.internals.role = "alertdialog";
2826
+ this.internals.ariaModal = "true";
2827
+ }
2828
+ static get isOpen() {
2829
+ return this.store[open];
2830
+ }
2831
+ static get observedStores() {
2832
+ return [history.store, this.store];
2833
+ }
2834
+ static open(opts) {
2835
+ const instance = new this();
2836
+ this.instance = instance;
2837
+ this.inertStore = [...document.body.children].filter((e) => !e.inert);
2838
+ this.inertStore.forEach((e) => e.inert = true);
2839
+ document.body.append(instance);
2840
+ const changeStore = () => updateStore(this.store, __spreadValues({ [open]: true }, opts));
2841
+ setTimeout(() => {
2842
+ changeStore();
2843
+ history.push({
2844
+ title: instance.label,
2845
+ open: changeStore,
2846
+ close: this.closeHandle.bind(this),
2847
+ shouldClose: this.shouldClose.bind(this)
2848
+ });
2849
+ }, 100);
2850
+ }
2851
+ static close() {
2852
+ history.back();
2853
+ }
2854
+ static closeHandle() {
2855
+ var _a3;
2856
+ this.inertStore.forEach((e) => e.inert = false);
2857
+ (_a3 = this.instance) == null ? void 0 : _a3.remove();
2858
+ updateStore(this.store, __spreadValues({ [open]: false }, options));
2859
+ }
2860
+ static shouldClose() {
2861
+ return true;
2862
+ }
2863
+ }, _a2.inertStore = [], _a2.instance = null, _a2.store = createStore(__spreadValues({
2864
+ [open]: false
2865
+ }, options)), _a2;
2866
+ }
2867
+ var __defProp2 = Object.defineProperty;
2868
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
2869
+ var __decorateClass = (decorators, target, key2, kind) => {
2870
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key2) : target;
2871
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
2872
+ if (decorator = decorators[i])
2873
+ result = (kind ? decorator(target, key2, result) : decorator(result)) || result;
2874
+ if (kind && result)
2875
+ __defProp2(target, key2, result);
2876
+ return result;
2877
+ };
2878
+ let DialogBaseElement = (_a = class extends GemElement {
2879
+ constructor() {
2880
+ super();
2881
+ __privateAdd(this, _nextSibling, void 0);
2882
+ __privateAdd(this, _parentElement, void 0);
2883
+ __privateAdd(this, _inertStore, void 0);
2884
+ this.inert = true;
2885
+ __privateSet(this, _inertStore, []);
2886
+ this.closeHandle = () => {
2887
+ var _a2;
2888
+ this.inert = true;
2889
+ __privateGet(this, _inertStore).forEach((e) => e.inert = false);
2890
+ if (__privateGet(this, _nextSibling)) {
2891
+ __privateGet(this, _nextSibling).before(this);
2892
+ } else if (__privateGet(this, _parentElement)) {
2893
+ (_a2 = __privateGet(this, _parentElement)) == null ? void 0 : _a2.appendChild(this);
2894
+ }
2895
+ this.dispatchEvent(new CustomEvent("close"));
2896
+ this.opened = false;
2897
+ };
2898
+ this.openHandle = () => {
2899
+ this.hidden = false;
2900
+ this.inert = false;
2901
+ __privateSet(this, _nextSibling, this.nextSibling);
2902
+ __privateSet(this, _parentElement, this.parentElement || this.getRootNode());
2903
+ __privateSet(this, _inertStore, [...document.body.children].filter((e) => !e.inert));
2904
+ __privateGet(this, _inertStore).forEach((e) => e.inert = true);
2905
+ document.body.append(this);
2906
+ this.dispatchEvent(new CustomEvent("open"));
2907
+ this.opened = true;
2908
+ };
2909
+ this.open = () => {
2910
+ if (this.opened)
2911
+ return;
2912
+ this.openHandle();
2913
+ history.push({
2914
+ title: this.label,
2915
+ open: this.openHandle,
2916
+ close: this.closeHandle,
2917
+ shouldClose: this.shouldClose
2918
+ });
2919
+ };
2920
+ this.close = () => {
2921
+ history.back();
2922
+ };
2923
+ this.forceClose = () => {
2924
+ this.opened = false;
2925
+ setTimeout(this.close, 100);
2926
+ };
2927
+ this.internals.role = "dialog";
2928
+ this.internals.ariaModal = "true";
2929
+ }
2930
+ shouldClose() {
2931
+ return true;
2932
+ }
2933
+ }, _nextSibling = new WeakMap(), _parentElement = new WeakMap(), _inertStore = new WeakMap(), _a);
2934
+ __decorateClass([
2935
+ attribute
2936
+ ], DialogBaseElement.prototype, "label", 2);
2937
+ __decorateClass([
2938
+ state
2939
+ ], DialogBaseElement.prototype, "opened", 2);
2940
+ DialogBaseElement = __decorateClass([
2941
+ connectStore(history.store)
2942
+ ], DialogBaseElement);
2943
+ const themeStoreMap = new WeakMap();
2944
+ function getThemeStore(theme) {
2945
+ return themeStoreMap.get(theme);
2946
+ }
2947
+ const themePropMap = new WeakMap();
2948
+ function getThemeProp(theme) {
2949
+ return themePropMap.get(theme);
2950
+ }
2951
+ function replaceStyle(style, theme) {
2952
+ const themeStore = themeStoreMap.get(theme);
2953
+ const themeProp = themePropMap.get(theme);
2954
+ const rules = Object.keys(themeStore).reduce((prev, key2) => {
2955
+ if (!themeStore[key2])
2956
+ return prev;
2957
+ return prev + `${themeProp[key2]}:${themeStore[key2]};`;
2958
+ }, "");
2959
+ style.textContent = `:root, :host {${rules}}`;
2960
+ }
2961
+ function createTheme(themeObj) {
2962
+ const salt = randomStr();
2963
+ const style = document.createElement("style");
2964
+ const themeStore = createStore(themeObj);
2965
+ const theme = {};
2966
+ const themeProp = {};
2967
+ themePropMap.set(theme, themeProp);
2968
+ themeStoreMap.set(theme, themeStore);
2969
+ Object.keys(themeStore).forEach((key2) => {
2970
+ themeProp[key2] = `--${camelToKebabCase(key2)}-${salt}`;
2971
+ theme[key2] = `var(${themeProp[key2]})`;
2972
+ });
2973
+ const replace = () => replaceStyle(style, theme);
2974
+ connect(themeStore, replace);
2975
+ replace();
2976
+ (document.head || document.documentElement).append(style);
2977
+ return theme;
2978
+ }
2979
+ function updateTheme(theme, newThemeObj) {
2980
+ const store2 = getThemeStore(theme);
2981
+ updateStore(store2, newThemeObj);
2982
+ }
2983
+ const splitReg = /\$\d(?:<[^>]*>)?/;
2984
+ const matchReg = /\$(\d)(<([^>]*)>)?/g;
2985
+ const matchStrIndex = 3;
2986
+ function splice(rawValue, ...rest) {
2987
+ const templateArr = rawValue.split(splitReg);
2988
+ const values = [];
2989
+ let result;
2990
+ while (result = matchReg.exec(rawValue)) {
2991
+ const str = result[matchStrIndex];
2992
+ const index = Number(result[1]) - 1;
2993
+ const arg = rest[index];
2994
+ values.push(typeof arg === "string" ? arg : arg(str));
2995
+ }
2996
+ return html(templateArr, ...values);
2997
+ }
2998
+ const modules = new Set();
2999
+ const _I18n = class {
3000
+ constructor(options) {
3001
+ __privateAdd(this, _cacheCurrentKey);
3002
+ __privateAdd(this, _urlParamsLang);
3003
+ __privateAdd(this, _cacheLang);
3004
+ __privateAdd(this, _isMain);
3005
+ __privateAdd(this, _lang);
3006
+ this.cachePrefix = "gem-i18n";
3007
+ if (!options.resources[options.fallbackLanguage]) {
3008
+ throw new GemError("i18n: fallbackLanguage invalid");
3009
+ }
3010
+ this.store = createStore(this);
3011
+ Object.assign(this, options);
3012
+ let currentLanguage = __privateGet(this, _urlParamsLang, urlParamsLang_get) || this.currentLanguage || __privateGet(this, _cacheLang, cacheLang_get);
3013
+ const ele = document.querySelector(`[type*=${this.cachePrefix}]`);
3014
+ if (ele) {
3015
+ try {
3016
+ const prerenderData = JSON.parse(ele.textContent || "");
3017
+ currentLanguage = prerenderData.currentLanguage;
3018
+ this.resources[prerenderData.currentLanguage] = prerenderData.currentLanguagePack;
3019
+ } catch {
3020
+ }
3021
+ }
3022
+ if (currentLanguage) {
3023
+ __privateSet(this, _lang, currentLanguage, lang_set);
3024
+ this.setLanguage(currentLanguage);
3025
+ } else {
3026
+ this.resetLanguage();
3027
+ }
3028
+ }
3029
+ get(s, ...rest) {
3030
+ const currentLanguagePack = this.resources[this.currentLanguage];
3031
+ const fallbackLanguagePack = this.resources[this.fallbackLanguage];
3032
+ const msg = currentLanguagePack[s] || fallbackLanguagePack[s];
3033
+ const rawValue = (msg == null ? void 0 : msg.message) || msg || `[${s}]`;
3034
+ if (!rest.length)
3035
+ return rawValue;
3036
+ return splice(rawValue, ...rest);
3037
+ }
3038
+ detectLanguage() {
3039
+ const availableLangs = Object.keys(this.resources);
3040
+ const uiLangs = navigator.languages.map((lang) => lang.replace(/-(.*)/, ($1) => $1.toUpperCase()));
3041
+ for (const lang of uiLangs) {
3042
+ const matched = availableLangs.find((e) => e === lang || lang.startsWith(`${e}-`));
3043
+ if (matched)
3044
+ return matched;
3045
+ }
3046
+ return this.fallbackLanguage;
3047
+ }
3048
+ async setLanguage(lang) {
3049
+ if (__privateGet(this, _isMain, isMain_get)) {
3050
+ modules.forEach(async (i18n) => await i18n.setLanguage(lang));
3051
+ }
3052
+ let pack;
3053
+ const data = this.resources[lang];
3054
+ if (!data) {
3055
+ console.warn(`${this.cachePrefix}: not found \`${lang}\``);
3056
+ return this.resetLanguage();
3057
+ }
3058
+ if (typeof data === "string") {
3059
+ const prefix = `${this.cachePrefix}:`;
3060
+ const localKey = `${prefix}${data}`;
3061
+ const localPackString = localStorage.getItem(localKey);
3062
+ const fetchPack = async () => {
3063
+ const pack2 = await (await fetch(data)).json();
3064
+ if (this.cache) {
3065
+ for (let i = 0; i < localStorage.length; i++) {
3066
+ const key2 = localStorage.key(i);
3067
+ if (key2.startsWith(prefix)) {
3068
+ localStorage.removeItem(key2);
3069
+ }
3070
+ }
3071
+ localStorage.setItem(localKey, JSON.stringify(pack2));
3072
+ }
3073
+ return pack2;
3074
+ };
3075
+ if (localPackString) {
3076
+ try {
3077
+ pack = JSON.parse(localPackString);
3078
+ } catch (e) {
3079
+ pack = await fetchPack();
3080
+ }
3081
+ } else {
3082
+ pack = await fetchPack();
3083
+ }
3084
+ } else {
3085
+ pack = data;
3086
+ }
3087
+ this.resources[lang] = pack;
3088
+ updateStore(this.store, {});
3089
+ if (lang !== this.currentLanguage) {
3090
+ __privateSet(this, _lang, lang, lang_set);
3091
+ }
3092
+ if (this.cache === true) {
3093
+ this.setCache();
3094
+ }
3095
+ return lang;
3096
+ }
3097
+ resetLanguage() {
3098
+ if (__privateGet(this, _isMain, isMain_get)) {
3099
+ modules.forEach((i18n) => i18n.resetLanguage());
3100
+ }
3101
+ __privateSet(this, _lang, this.fallbackLanguage, lang_set);
3102
+ if (this.cache) {
3103
+ localStorage.removeItem(__privateGet(this, _cacheCurrentKey, cacheCurrentKey_get));
3104
+ }
3105
+ return this.setLanguage(this.detectLanguage());
3106
+ }
3107
+ setCache() {
3108
+ if (__privateGet(this, _isMain, isMain_get)) {
3109
+ modules.forEach((i18n) => i18n.setCache());
3110
+ }
3111
+ localStorage.setItem(__privateGet(this, _cacheCurrentKey, cacheCurrentKey_get), this.currentLanguage);
3112
+ }
3113
+ createSubModule(name, resources) {
3114
+ const module = new _I18n({
3115
+ resources,
3116
+ cachePrefix: `${this.cachePrefix}-${name}`,
3117
+ currentLanguage: this.currentLanguage,
3118
+ fallbackLanguage: this.fallbackLanguage,
3119
+ cache: this.cache
3120
+ });
3121
+ modules.add(module);
3122
+ return module;
3123
+ }
3124
+ toJSON() {
3125
+ return {
3126
+ currentLanguage: this.currentLanguage,
3127
+ currentLanguagePack: this.resources[this.currentLanguage]
3128
+ };
3129
+ }
3130
+ };
3131
+ let I18n = _I18n;
3132
+ _cacheCurrentKey = new WeakSet();
3133
+ cacheCurrentKey_get = function() {
3134
+ return `${this.cachePrefix}:current`;
3135
+ };
3136
+ _urlParamsLang = new WeakSet();
3137
+ urlParamsLang_get = function() {
3138
+ const { hostname, pathname, search } = location;
3139
+ const parts2 = hostname.split(".");
3140
+ switch (this.urlParamsType) {
3141
+ case "ccTLD":
3142
+ return parts2.pop();
3143
+ case "gTLD":
3144
+ return parts2.shift();
3145
+ case "path":
3146
+ return pathname.split("/")[1];
3147
+ default:
3148
+ const fragment = this.urlParamsName && new URLSearchParams(search).get(this.urlParamsName) || "";
3149
+ return fragment in this.resources ? fragment : "";
3150
+ }
3151
+ };
3152
+ _cacheLang = new WeakSet();
3153
+ cacheLang_get = function() {
3154
+ return this.cache && localStorage.getItem(__privateGet(this, _cacheCurrentKey, cacheCurrentKey_get)) || "";
3155
+ };
3156
+ _isMain = new WeakSet();
3157
+ isMain_get = function() {
3158
+ return !modules.has(this);
3159
+ };
3160
+ _lang = new WeakSet();
3161
+ lang_set = function(lang) {
3162
+ var _a2;
3163
+ if (__privateGet(this, _isMain, isMain_get)) {
3164
+ document.documentElement.lang = lang;
3165
+ }
3166
+ this.currentLanguage = lang;
3167
+ (_a2 = this.onChange) == null ? void 0 : _a2.call(this, lang);
3168
+ };
3169
+ const defaultReq = {
3170
+ credentials: "include",
3171
+ mode: "cors"
3172
+ };
3173
+ async function request(uri, options = {}) {
3174
+ const res = await fetch(uri, __spreadValues(__spreadValues({}, defaultReq), options));
3175
+ if (res.status === 0)
3176
+ throw new Error("Request fail");
3177
+ if (res.status >= 500)
3178
+ throw new Error(res.statusText);
3179
+ if (res.status >= 400)
3180
+ throw new Error(await res.text() || res.statusText);
3181
+ return await res.json();
3182
+ }
3183
+ const TypedArray = Object.getPrototypeOf(Object.getPrototypeOf(new Int8Array()));
3184
+ function serializationBody(body) {
3185
+ if (body instanceof FormData || body instanceof Blob || body instanceof TypedArray || body instanceof URLSearchParams || body instanceof ReadableStream || body instanceof ArrayBuffer) {
3186
+ return body;
3187
+ }
3188
+ if (typeof body === "object") {
3189
+ return JSON.stringify(body);
3190
+ }
3191
+ return body;
3192
+ }
3193
+ function get(url, params) {
3194
+ const { origin, pathname, search } = new URL(url, location.origin);
3195
+ const query = new URLSearchParams(params).toString();
3196
+ return request(`${origin}${pathname}${search ? `${search}&` : query ? "?" : ""}${query}`, {
3197
+ method: "GET"
3198
+ });
3199
+ }
3200
+ function del(url) {
3201
+ return request(url, { method: "DELETE" });
3202
+ }
3203
+ function put(url, body) {
3204
+ return request(url, { method: "PUT", body: serializationBody(body) });
3205
+ }
3206
+ function post(url, body) {
3207
+ return request(url, { method: "POST", body: serializationBody(body) });
3208
+ }
3209
+ const matche = (query) => window.matchMedia(query).matches;
3210
+ const mediaQuery = {
3211
+ PRINT: "print",
3212
+ get isPrint() {
3213
+ return matche(this.PRINT);
3214
+ },
3215
+ HOVER: "(hover: hover)",
3216
+ get isHover() {
3217
+ return matche(this.HOVER);
3218
+ },
3219
+ PHONE: "(min-width: 319px) and (max-width: 480px)",
3220
+ get isPhone() {
3221
+ return matche(this.PHONE);
3222
+ },
3223
+ LAPTOP: "(min-width: 1023px) and (max-width: 1280px) and (orientation: landscape)",
3224
+ get isLaptop() {
3225
+ return matche(this.LAPTOP);
3226
+ },
3227
+ DESKTOP: "(min-width: 1279px) and (orientation: landscape)",
3228
+ get isDesktop() {
3229
+ return matche(this.DESKTOP);
3230
+ },
3231
+ WIDTHSCREEN: "(min-width: 1919px) and (orientation: landscape)",
3232
+ get isWidthScreen() {
3233
+ return matche(this.WIDTHSCREEN);
3234
+ },
3235
+ PHONE_LANDSCAPE: "(min-width: 479px) and (max-width: 767px) and (orientation: landscape)",
3236
+ get isPhoneLandscape() {
3237
+ return matche(this.PHONE_LANDSCAPE);
3238
+ },
3239
+ TABLET: "(min-width: 768px) and (max-width: 1024px)",
3240
+ get isTablet() {
3241
+ return matche(this.TABLET);
3242
+ },
3243
+ SMALL_PHONE: "(min-width: 319px) and (max-width: 480px) and (max-height: 640px)",
3244
+ get isSmallPhone() {
3245
+ return matche(this.SMALL_PHONE);
3246
+ },
3247
+ WATCH: "(max-width: 319px)",
3248
+ get isWatch() {
3249
+ return matche(this.WATCH);
3250
+ },
3251
+ SHORT: "(min-width: 479px) and (max-height: 320px)",
3252
+ get isShort() {
3253
+ return matche(this.SHORT);
3254
+ },
3255
+ PWA: "(display-mode: standalone)",
3256
+ get isPWA() {
3257
+ return matche(this.PWA);
3258
+ },
3259
+ MOTION_REDUCE: "(prefers-reduced-motion: reduce)",
3260
+ get isMotionReduce() {
3261
+ return matche(this.MOTION_REDUCE);
3262
+ },
3263
+ DATA_REDUCE: "(prefers-reduced-data: reduce)",
3264
+ get isDataReduce() {
3265
+ return matche(this.DATA_REDUCE);
3266
+ }
3267
+ };
3268
+ const version = "1.6.5";
3269
+ if (window.__GEM_DEVTOOLS__HOOK__) {
3270
+ Object.assign(window.__GEM_DEVTOOLS__HOOK__, __spreadValues({}, Gem));
3271
+ }
3272
+ export { DialogBaseElement, GemActiveLinkElement, GemElement, GemError, GemLightRouteElement, GemLinkElement, GemReflectElement, GemRouteElement, GemTitleElement, GemUnsafeElement, GemUseElement, I18n, LinkedList, PropProxyMap, QueryString, SVGTemplateResult, SheetToken, StoreListenerMap, TemplateResult, absoluteLocation, addMicrotask, addMicrotaskToStack, adoptedStyle, attribute, basePathStore, boolattribute, camelToKebabCase, classMap, cleanObject, connect, connectStore, createCSSSheet, createHistoryParams, createModalClass, createPath, createStore, createStoreSet, createTheme, css, customElement, defineAttribute, defineCSSState, defineProperty, defineRef, del, directive, disconnect, emitter, get, getThemeProp, getThemeStore, globalemitter, guard, history, html, ifDefined, isArrayChange, kebabToCamelCase, matchPath, mediaQuery, nativeDefineElement, numattribute, part, partMap, post, property, put, randomStr, raw, refobject, removeItems, render, repeat, request, rootElement, slot, splice, state, styleMap, styled, svg, titleStore, updateStore, updateTheme, useNativeCSSStyleSheet, version };