@dooboostore/simple-web-component 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +67 -70
  2. package/dist/cjs/decorators/addEventListener.js +42 -0
  3. package/dist/cjs/decorators/addEventListener.js.map +7 -0
  4. package/dist/cjs/decorators/attributeChanged.js +24 -4
  5. package/dist/cjs/decorators/attributeChanged.js.map +2 -2
  6. package/dist/cjs/decorators/{element.js → elementDefind.js} +91 -13
  7. package/dist/cjs/decorators/elementDefind.js.map +7 -0
  8. package/dist/cjs/decorators/query.js +53 -0
  9. package/dist/cjs/decorators/query.js.map +7 -0
  10. package/dist/cjs/decorators/queryAll.js +53 -0
  11. package/dist/cjs/decorators/queryAll.js.map +7 -0
  12. package/dist/cjs/elements/SwcChoose.js +117 -0
  13. package/dist/cjs/elements/SwcChoose.js.map +7 -0
  14. package/dist/cjs/elements/SwcForOf.js +196 -0
  15. package/dist/cjs/elements/SwcForOf.js.map +7 -0
  16. package/dist/cjs/elements/SwcIf.js +135 -0
  17. package/dist/cjs/elements/SwcIf.js.map +7 -0
  18. package/dist/cjs/elements/SwcOther.js +56 -0
  19. package/dist/cjs/elements/SwcOther.js.map +7 -0
  20. package/dist/cjs/elements/SwcWhen.js +56 -0
  21. package/dist/cjs/elements/SwcWhen.js.map +7 -0
  22. package/dist/cjs/index.js +9 -1
  23. package/dist/cjs/index.js.map +2 -2
  24. package/dist/esm/decorators/addEventListener.js +23 -0
  25. package/dist/esm/decorators/addEventListener.js.map +7 -0
  26. package/dist/esm/decorators/attributeChanged.js +24 -4
  27. package/dist/esm/decorators/attributeChanged.js.map +2 -2
  28. package/dist/esm/decorators/{element.js → elementDefind.js} +89 -11
  29. package/dist/esm/decorators/elementDefind.js.map +7 -0
  30. package/dist/esm/decorators/query.js +34 -0
  31. package/dist/esm/decorators/query.js.map +7 -0
  32. package/dist/esm/decorators/queryAll.js +34 -0
  33. package/dist/esm/decorators/queryAll.js.map +7 -0
  34. package/dist/esm/elements/SwcChoose.js +98 -0
  35. package/dist/esm/elements/SwcChoose.js.map +7 -0
  36. package/dist/esm/elements/SwcForOf.js +177 -0
  37. package/dist/esm/elements/SwcForOf.js.map +7 -0
  38. package/dist/esm/elements/SwcIf.js +116 -0
  39. package/dist/esm/elements/SwcIf.js.map +7 -0
  40. package/dist/esm/elements/SwcOther.js +37 -0
  41. package/dist/esm/elements/SwcOther.js.map +7 -0
  42. package/dist/esm/elements/SwcWhen.js +37 -0
  43. package/dist/esm/elements/SwcWhen.js.map +7 -0
  44. package/dist/esm/index.js +9 -1
  45. package/dist/esm/index.js.map +2 -2
  46. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +649 -14
  47. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  48. package/dist/types/decorators/addEventListener.d.ts +16 -0
  49. package/dist/types/decorators/addEventListener.d.ts.map +1 -0
  50. package/dist/types/decorators/attributeChanged.d.ts +3 -1
  51. package/dist/types/decorators/attributeChanged.d.ts.map +1 -1
  52. package/dist/types/decorators/{element.d.ts → elementDefind.d.ts} +2 -2
  53. package/dist/types/decorators/elementDefind.d.ts.map +1 -0
  54. package/dist/types/decorators/query.d.ts +13 -0
  55. package/dist/types/decorators/query.d.ts.map +1 -0
  56. package/dist/types/decorators/queryAll.d.ts +13 -0
  57. package/dist/types/decorators/queryAll.d.ts.map +1 -0
  58. package/dist/types/elements/SwcChoose.d.ts +12 -0
  59. package/dist/types/elements/SwcChoose.d.ts.map +1 -0
  60. package/dist/types/elements/SwcForOf.d.ts +16 -0
  61. package/dist/types/elements/SwcForOf.d.ts.map +1 -0
  62. package/dist/types/elements/SwcIf.d.ts +14 -0
  63. package/dist/types/elements/SwcIf.d.ts.map +1 -0
  64. package/dist/types/elements/SwcOther.d.ts +5 -0
  65. package/dist/types/elements/SwcOther.d.ts.map +1 -0
  66. package/dist/types/elements/SwcWhen.d.ts +5 -0
  67. package/dist/types/elements/SwcWhen.d.ts.map +1 -0
  68. package/dist/types/index.d.ts +9 -1
  69. package/dist/types/index.d.ts.map +1 -1
  70. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +649 -14
  71. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  72. package/package.json +1 -1
  73. package/src/decorators/addEventListener.ts +35 -0
  74. package/src/decorators/attributeChanged.ts +29 -6
  75. package/src/decorators/{element.ts → elementDefind.ts} +121 -11
  76. package/src/decorators/query.ts +46 -0
  77. package/src/decorators/queryAll.ts +46 -0
  78. package/src/elements/SwcChoose.ts +83 -0
  79. package/src/elements/SwcForOf.ts +170 -0
  80. package/src/elements/SwcIf.ts +111 -0
  81. package/src/elements/SwcOther.ts +14 -0
  82. package/src/elements/SwcWhen.ts +14 -0
  83. package/src/index.ts +10 -2
  84. package/dist/cjs/decorators/element.js.map +0 -7
  85. package/dist/esm/decorators/element.js.map +0 -7
  86. package/dist/types/decorators/element.d.ts.map +0 -1
@@ -52,17 +52,36 @@ var ReflectUtils;
52
52
 
53
53
  // src/decorators/attributeChanged.ts
54
54
  var ATTRIBUTE_CHANGED_METADATA_KEY = Symbol("simple-web-component:attribute-changed");
55
- var attributeChanged = (attributeName) => {
56
- return (target, propertyKey, descriptor) => {
55
+ var ATTRIBUTE_CHANGED_WILDCARD = "*";
56
+ function attributeChanged(arg1, arg2, arg3) {
57
+ const decorator = (attributeName, target, propertyKey) => {
57
58
  const constructor = target.constructor;
58
59
  let meta = ReflectUtils.getMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, constructor);
59
60
  if (!meta) {
60
61
  meta = /* @__PURE__ */ new Map();
61
62
  ReflectUtils.defineMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, meta, constructor);
62
63
  }
63
- meta.set(attributeName, propertyKey);
64
+ let methods = meta.get(attributeName);
65
+ if (!methods) {
66
+ methods = [];
67
+ meta.set(attributeName, methods);
68
+ }
69
+ if (!methods.includes(propertyKey)) {
70
+ methods.push(propertyKey);
71
+ }
64
72
  };
65
- };
73
+ if (typeof arg1 === "string") {
74
+ return (target, propertyKey) => {
75
+ decorator(arg1, target, propertyKey);
76
+ };
77
+ } else if (Array.isArray(arg1)) {
78
+ return (target, propertyKey) => {
79
+ arg1.forEach((name) => decorator(name, target, propertyKey));
80
+ };
81
+ } else if (arg1 && arg2) {
82
+ decorator(ATTRIBUTE_CHANGED_WILDCARD, arg1, arg2);
83
+ }
84
+ }
66
85
  var getAttributeChangedMap = (target) => {
67
86
  const constructor = target instanceof Function ? target : target.constructor;
68
87
  return ReflectUtils.getMetadata(ATTRIBUTE_CHANGED_METADATA_KEY, constructor);
@@ -88,7 +107,83 @@ var getStyleMethod = (target) => {
88
107
  return ReflectUtils.getMetadata(STYLE_METHOD_KEY, constructor);
89
108
  };
90
109
 
91
- // src/decorators/element.ts
110
+ // src/decorators/query.ts
111
+ var QUERY_METADATA_KEY = Symbol("simple-web-component:query");
112
+ var query = (selector, options = { useShadow: true }) => {
113
+ return (target, propertyKey, descriptor) => {
114
+ const isMethod = !!descriptor;
115
+ const constructor = target.constructor;
116
+ let queries = ReflectUtils.getMetadata(QUERY_METADATA_KEY, constructor);
117
+ if (!queries) {
118
+ queries = [];
119
+ ReflectUtils.defineMetadata(QUERY_METADATA_KEY, queries, constructor);
120
+ }
121
+ queries.push({ selector, options, propertyKey, isMethod });
122
+ if (!isMethod) {
123
+ Object.defineProperty(target, propertyKey, {
124
+ get() {
125
+ const root = options.useShadow !== false && this.shadowRoot ? this.shadowRoot : this;
126
+ return root.querySelector(selector);
127
+ },
128
+ enumerable: true,
129
+ configurable: true
130
+ });
131
+ }
132
+ };
133
+ };
134
+ var getQueryMetadata = (target) => {
135
+ const constructor = target instanceof Function ? target : target.constructor;
136
+ return ReflectUtils.getMetadata(QUERY_METADATA_KEY, constructor);
137
+ };
138
+
139
+ // src/decorators/queryAll.ts
140
+ var QUERY_ALL_METADATA_KEY = Symbol("simple-web-component:query-all");
141
+ var queryAll = (selector, options = { useShadow: true }) => {
142
+ return (target, propertyKey, descriptor) => {
143
+ const isMethod = !!descriptor;
144
+ const constructor = target.constructor;
145
+ let queries = ReflectUtils.getMetadata(QUERY_ALL_METADATA_KEY, constructor);
146
+ if (!queries) {
147
+ queries = [];
148
+ ReflectUtils.defineMetadata(QUERY_ALL_METADATA_KEY, queries, constructor);
149
+ }
150
+ queries.push({ selector, options, propertyKey, isMethod });
151
+ if (!isMethod) {
152
+ Object.defineProperty(target, propertyKey, {
153
+ get() {
154
+ const root = options.useShadow !== false && this.shadowRoot ? this.shadowRoot : this;
155
+ return root.querySelectorAll(selector);
156
+ },
157
+ enumerable: true,
158
+ configurable: true
159
+ });
160
+ }
161
+ };
162
+ };
163
+ var getQueryAllMetadata = (target) => {
164
+ const constructor = target instanceof Function ? target : target.constructor;
165
+ return ReflectUtils.getMetadata(QUERY_ALL_METADATA_KEY, constructor);
166
+ };
167
+
168
+ // src/decorators/addEventListener.ts
169
+ var ADD_EVENT_LISTENER_METADATA_KEY = Symbol("simple-web-component:add-event-listener");
170
+ var addEventListener = (options) => {
171
+ return (target, propertyKey, descriptor) => {
172
+ const constructor = target.constructor;
173
+ let listeners = ReflectUtils.getMetadata(ADD_EVENT_LISTENER_METADATA_KEY, constructor);
174
+ if (!listeners) {
175
+ listeners = [];
176
+ ReflectUtils.defineMetadata(ADD_EVENT_LISTENER_METADATA_KEY, listeners, constructor);
177
+ }
178
+ listeners.push({ options, propertyKey });
179
+ };
180
+ };
181
+ var getAddEventListenerMetadata = (target) => {
182
+ const constructor = target instanceof Function ? target : target.constructor;
183
+ return ReflectUtils.getMetadata(ADD_EVENT_LISTENER_METADATA_KEY, constructor);
184
+ };
185
+
186
+ // src/decorators/elementDefind.ts
92
187
  var ELEMENT_CONFIG_KEY = Symbol("simple-web-component:element-config");
93
188
  var BUILT_IN_TAG_MAP = /* @__PURE__ */ new Map();
94
189
  var registerTag = (className, tagName) => {
@@ -154,7 +249,7 @@ var registerTag = (className, tagName) => {
154
249
  ["HTMLVideoElement", "video"],
155
250
  ["HTMLHeadingElement", "h1"]
156
251
  ].forEach(([cls, tag]) => registerTag(cls, tag));
157
- var element = (inConfig) => (constructor) => {
252
+ var elementDefind = (inConfig) => (constructor) => {
158
253
  const config = typeof inConfig === "string" ? { tagName: inConfig } : inConfig;
159
254
  let extendsTagName = config.extends;
160
255
  if (!extendsTagName) {
@@ -167,7 +262,7 @@ var element = (inConfig) => (constructor) => {
167
262
  }
168
263
  }
169
264
  const attributeChangedMap = getAttributeChangedMap(constructor);
170
- const observedFromDecorators = attributeChangedMap ? Array.from(attributeChangedMap.keys()) : [];
265
+ const observedFromDecorators = attributeChangedMap ? Array.from(attributeChangedMap.keys()).filter((it) => it !== ATTRIBUTE_CHANGED_WILDCARD) : [];
171
266
  const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...config.observedAttributes ?? [], ...observedFromDecorators])];
172
267
  const NewClass = class extends constructor {
173
268
  static get observedAttributes() {
@@ -175,11 +270,68 @@ var element = (inConfig) => (constructor) => {
175
270
  }
176
271
  constructor(...args) {
177
272
  super(...args);
273
+ this._observer = null;
274
+ this._boundElements = /* @__PURE__ */ new WeakMap();
178
275
  if (config.useShadow === true && !this.shadowRoot) {
179
276
  this.attachShadow({ mode: "open" });
180
277
  }
181
278
  }
279
+ _syncDecorators() {
280
+ const queryMetadata = getQueryMetadata(this);
281
+ if (queryMetadata) {
282
+ queryMetadata.filter((it) => it.isMethod).forEach((it) => {
283
+ const root = it.options.useShadow !== false && this.shadowRoot ? this.shadowRoot : this;
284
+ const element = root.querySelector(it.selector);
285
+ if (element) {
286
+ let bound = this._boundElements.get(element);
287
+ if (!bound) {
288
+ bound = /* @__PURE__ */ new Set();
289
+ this._boundElements.set(element, bound);
290
+ }
291
+ if (!bound.has(it.propertyKey)) {
292
+ this[it.propertyKey](element);
293
+ bound.add(it.propertyKey);
294
+ }
295
+ }
296
+ });
297
+ }
298
+ const queryAllMetadata = getQueryAllMetadata(this);
299
+ if (queryAllMetadata) {
300
+ queryAllMetadata.filter((it) => it.isMethod).forEach((it) => {
301
+ const root = it.options.useShadow !== false && this.shadowRoot ? this.shadowRoot : this;
302
+ const elements = root.querySelectorAll(it.selector);
303
+ this[it.propertyKey](elements);
304
+ });
305
+ }
306
+ const eventListeners = getAddEventListenerMetadata(this);
307
+ if (eventListeners) {
308
+ eventListeners.forEach((it) => {
309
+ const { selector, eventName, useShadow, ...options } = it.options;
310
+ const root = useShadow !== false && this.shadowRoot ? this.shadowRoot : this;
311
+ const targetElements = selector ? root.querySelectorAll(selector) : [this];
312
+ targetElements.forEach((targetElement) => {
313
+ if (targetElement) {
314
+ let bound = this._boundElements.get(targetElement);
315
+ if (!bound) {
316
+ bound = /* @__PURE__ */ new Set();
317
+ this._boundElements.set(targetElement, bound);
318
+ }
319
+ const eventKey = `event:${String(it.propertyKey)}:${eventName}`;
320
+ if (!bound.has(eventKey)) {
321
+ targetElement.addEventListener(eventName, (event) => {
322
+ this[it.propertyKey](event);
323
+ }, options);
324
+ bound.add(eventKey);
325
+ }
326
+ }
327
+ });
328
+ });
329
+ }
330
+ }
182
331
  disconnectedCallback() {
332
+ if (this._observer) {
333
+ this._observer.disconnect();
334
+ }
183
335
  if (super.disconnectedCallback) {
184
336
  super.disconnectedCallback();
185
337
  }
@@ -195,9 +347,6 @@ var element = (inConfig) => (constructor) => {
195
347
  }
196
348
  }
197
349
  async connectedCallback() {
198
- if (super.connectedCallback) {
199
- await super.connectedCallback();
200
- }
201
350
  const templateMethod = getTemplateMethod(this);
202
351
  const styleMethod = getStyleMethod(this);
203
352
  const template2 = templateMethod ? await this[templateMethod]() : void 0;
@@ -219,15 +368,36 @@ var element = (inConfig) => (constructor) => {
219
368
  } else {
220
369
  this.innerHTML = content;
221
370
  }
371
+ this._syncDecorators();
372
+ this._observer = new MutationObserver(() => {
373
+ this._syncDecorators();
374
+ });
375
+ const target = this.shadowRoot || this;
376
+ this._observer.observe(target, { childList: true, subtree: true });
377
+ if (super.connectedCallback) {
378
+ await super.connectedCallback();
379
+ }
222
380
  }
223
381
  // 4. Handle attribute changes and route to decorated methods
224
382
  attributeChangedCallback(name, oldValue, newValue) {
225
383
  if (super.attributeChangedCallback) {
226
384
  super.attributeChangedCallback(name, oldValue, newValue);
227
385
  }
228
- const methodKey = attributeChangedMap?.get(name);
229
- if (methodKey && typeof this[methodKey] === "function") {
230
- this[methodKey](newValue, oldValue);
386
+ const methodKeys = attributeChangedMap?.get(name);
387
+ if (methodKeys && Array.isArray(methodKeys)) {
388
+ methodKeys.forEach((key) => {
389
+ if (typeof this[key] === "function") {
390
+ this[key](newValue, oldValue, name);
391
+ }
392
+ });
393
+ }
394
+ const wildcardMethodKeys = attributeChangedMap?.get(ATTRIBUTE_CHANGED_WILDCARD);
395
+ if (wildcardMethodKeys && Array.isArray(wildcardMethodKeys)) {
396
+ wildcardMethodKeys.forEach((key) => {
397
+ if (typeof this[key] === "function") {
398
+ this[key](newValue, oldValue, name);
399
+ }
400
+ });
231
401
  }
232
402
  }
233
403
  };
@@ -243,17 +413,482 @@ var getElementConfig = (target) => {
243
413
  const constructor = target instanceof Function ? target : target.constructor;
244
414
  return ReflectUtils.getMetadata(ELEMENT_CONFIG_KEY, constructor);
245
415
  };
416
+
417
+ // src/elements/SwcForOf.ts
418
+ var __decorate = function(decorators, target, key, desc) {
419
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
420
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
421
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
422
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
423
+ };
424
+ var __metadata = function(k, v) {
425
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
426
+ };
427
+ var SwcForOf = class SwcForOf2 extends HTMLElement {
428
+ constructor() {
429
+ super();
430
+ this._value = [];
431
+ this._masterTplNodes = [];
432
+ }
433
+ set value(val) {
434
+ if (!Array.isArray(val))
435
+ val = [];
436
+ this._value = this.createProxy(val);
437
+ this.renderAll();
438
+ }
439
+ get value() {
440
+ return this._value;
441
+ }
442
+ createProxy(arr) {
443
+ return new Proxy(arr, {
444
+ set: (target, prop, val) => {
445
+ const isIndex = !isNaN(Number(prop));
446
+ target[prop] = val;
447
+ if (isIndex) {
448
+ this.updateSingleRow(Number(prop), val);
449
+ } else if (prop === "length" && val < target.length) {
450
+ this.renderAll();
451
+ }
452
+ return true;
453
+ },
454
+ deleteProperty: (target, prop) => {
455
+ const res = delete target[prop];
456
+ this.renderAll();
457
+ return res;
458
+ }
459
+ });
460
+ }
461
+ styles() {
462
+ return `
463
+ :host { display: contents; }
464
+ `;
465
+ }
466
+ renderTemplate() {
467
+ return `
468
+ <slot id="tpl-slot" style="display:none;"></slot>
469
+ `;
470
+ }
471
+ connectedCallback() {
472
+ const tplSlot = this.shadowRoot?.getElementById("tpl-slot");
473
+ if (tplSlot) {
474
+ this._masterTplNodes = tplSlot.assignedNodes().map((n) => n.cloneNode(true));
475
+ }
476
+ this.renderAll();
477
+ }
478
+ updateSingleRow(index, newValue) {
479
+ const targets = this.querySelectorAll(`[slot="row-${index}"]`);
480
+ if (targets.length > 0) {
481
+ targets.forEach((target) => this.applyData(target, newValue, index));
482
+ } else {
483
+ this.renderRow(newValue, index);
484
+ }
485
+ }
486
+ applyData(node, data, index) {
487
+ const getValueByPath = (obj, path) => {
488
+ if (path === "value")
489
+ return obj;
490
+ if (path.startsWith("value.")) {
491
+ return path.split(".").slice(1).reduce((acc, part) => acc && acc[part], obj);
492
+ }
493
+ return void 0;
494
+ };
495
+ const walk = (n) => {
496
+ if (n.nodeType === Node.TEXT_NODE) {
497
+ if (!n._original)
498
+ n._original = n.textContent;
499
+ let text = n._original;
500
+ text = text.replace(/{{(.*?)}}/g, (match, path) => {
501
+ path = path.trim();
502
+ if (path === "index")
503
+ return index.toString();
504
+ const val = getValueByPath(data, path);
505
+ return val !== void 0 ? val : match;
506
+ });
507
+ if (n.textContent !== text)
508
+ n.textContent = text;
509
+ } else if (n.nodeType === Node.ELEMENT_NODE) {
510
+ const el = n;
511
+ Array.from(el.attributes).forEach((a) => {
512
+ if (!a._original)
513
+ a._original = a.value;
514
+ let val = a._original;
515
+ val = val.replace(/{{(.*?)}}/g, (match, path) => {
516
+ path = path.trim();
517
+ if (path === "index")
518
+ return index.toString();
519
+ const v = getValueByPath(data, path);
520
+ return v !== void 0 ? v : match;
521
+ });
522
+ if (a.value !== val)
523
+ a.value = val;
524
+ });
525
+ el.childNodes.forEach(walk);
526
+ }
527
+ };
528
+ walk(node);
529
+ }
530
+ renderRow(item, index) {
531
+ if (!this.shadowRoot || this._masterTplNodes.length === 0)
532
+ return;
533
+ const slotName = `row-${index}`;
534
+ if (!this.shadowRoot.querySelector(`slot[name="${slotName}"]`)) {
535
+ const slot = document.createElement("slot");
536
+ slot.name = slotName;
537
+ this.shadowRoot.appendChild(slot);
538
+ }
539
+ this._masterTplNodes.forEach((tplNode) => {
540
+ const clone = tplNode.cloneNode(true);
541
+ if (clone.nodeType === Node.ELEMENT_NODE) {
542
+ clone.setAttribute("slot", slotName);
543
+ clone.style.display = "";
544
+ } else if (clone.nodeType === Node.TEXT_NODE) {
545
+ if (clone.textContent?.trim().length === 0)
546
+ return;
547
+ const span = document.createElement("span");
548
+ span.setAttribute("slot", slotName);
549
+ span.appendChild(clone);
550
+ this.appendChild(span);
551
+ this.applyData(span, item, index);
552
+ return;
553
+ }
554
+ this.appendChild(clone);
555
+ this.applyData(clone, item, index);
556
+ });
557
+ }
558
+ renderAll() {
559
+ if (this._masterTplNodes.length === 0 || !this.shadowRoot)
560
+ return;
561
+ Array.from(this.children).forEach((c) => {
562
+ const slot = c.getAttribute("slot");
563
+ if (slot && slot.startsWith("row-")) {
564
+ c.remove();
565
+ }
566
+ });
567
+ Array.from(this.shadowRoot.querySelectorAll("slot")).forEach((s) => {
568
+ if (s.id !== "tpl-slot")
569
+ s.remove();
570
+ });
571
+ this._value.forEach((item, index) => this.renderRow(item, index));
572
+ }
573
+ };
574
+ __decorate([
575
+ style,
576
+ __metadata("design:type", Function),
577
+ __metadata("design:paramtypes", []),
578
+ __metadata("design:returntype", void 0)
579
+ ], SwcForOf.prototype, "styles", null);
580
+ __decorate([
581
+ template,
582
+ __metadata("design:type", Function),
583
+ __metadata("design:paramtypes", []),
584
+ __metadata("design:returntype", void 0)
585
+ ], SwcForOf.prototype, "renderTemplate", null);
586
+ SwcForOf = __decorate([
587
+ elementDefind({ tagName: "swc-for-of", useShadow: true }),
588
+ __metadata("design:paramtypes", [])
589
+ ], SwcForOf);
590
+
591
+ // src/elements/SwcIf.ts
592
+ var __decorate2 = function(decorators, target, key, desc) {
593
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
594
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
595
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
596
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
597
+ };
598
+ var __metadata2 = function(k, v) {
599
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
600
+ };
601
+ var SwcIf = class SwcIf2 extends HTMLElement {
602
+ constructor() {
603
+ super();
604
+ this._value = false;
605
+ this._masterTplNodes = [];
606
+ this._observer = null;
607
+ }
608
+ set value(val) {
609
+ this._value = val;
610
+ this.render();
611
+ }
612
+ get value() {
613
+ return this._value;
614
+ }
615
+ styles() {
616
+ return `
617
+ :host { display: contents; }
618
+ `;
619
+ }
620
+ renderTemplate() {
621
+ return `
622
+ <slot id="tpl-slot" style="display:none;"></slot>
623
+ `;
624
+ }
625
+ connectedCallback() {
626
+ const tplSlot = this.shadowRoot?.getElementById("tpl-slot");
627
+ if (tplSlot) {
628
+ this._masterTplNodes = tplSlot.assignedNodes().map((n) => n.cloneNode(true));
629
+ }
630
+ this._observer = new MutationObserver(() => this.render());
631
+ this._observer.observe(this, { attributes: true });
632
+ this.render();
633
+ }
634
+ disconnectedCallback() {
635
+ this._observer?.disconnect();
636
+ }
637
+ render() {
638
+ if (!this.shadowRoot)
639
+ return;
640
+ const attrValue = this.getAttribute("value");
641
+ if (attrValue !== null && attrValue.includes("{{"))
642
+ return;
643
+ let displayValue = attrValue !== null ? attrValue : this._value;
644
+ let isTruthy = !!displayValue;
645
+ if (typeof displayValue === "string") {
646
+ if (displayValue === "false" || displayValue === "0" || displayValue === "")
647
+ isTruthy = false;
648
+ else {
649
+ try {
650
+ isTruthy = !!new Function(`return ${displayValue}`)();
651
+ } catch (e) {
652
+ isTruthy = true;
653
+ }
654
+ }
655
+ }
656
+ Array.from(this.children).forEach((c) => {
657
+ if (c.getAttribute("slot") === "if-content") {
658
+ c.remove();
659
+ }
660
+ });
661
+ const existingSlot = this.shadowRoot.querySelector('slot[name="if-content"]');
662
+ if (existingSlot)
663
+ existingSlot.remove();
664
+ if (isTruthy && this._masterTplNodes.length > 0) {
665
+ const contentSlot = document.createElement("slot");
666
+ contentSlot.name = "if-content";
667
+ this.shadowRoot.appendChild(contentSlot);
668
+ this._masterTplNodes.forEach((tplNode) => {
669
+ const clone = tplNode.cloneNode(true);
670
+ if (clone.nodeType === Node.ELEMENT_NODE) {
671
+ clone.setAttribute("slot", "if-content");
672
+ clone.style.display = "";
673
+ } else if (clone.nodeType === Node.TEXT_NODE) {
674
+ if (clone.textContent?.trim().length === 0)
675
+ return;
676
+ const span = document.createElement("span");
677
+ span.setAttribute("slot", "if-content");
678
+ span.appendChild(clone);
679
+ this.appendChild(span);
680
+ return;
681
+ }
682
+ this.appendChild(clone);
683
+ });
684
+ }
685
+ }
686
+ };
687
+ __decorate2([
688
+ style,
689
+ __metadata2("design:type", Function),
690
+ __metadata2("design:paramtypes", []),
691
+ __metadata2("design:returntype", void 0)
692
+ ], SwcIf.prototype, "styles", null);
693
+ __decorate2([
694
+ template,
695
+ __metadata2("design:type", Function),
696
+ __metadata2("design:paramtypes", []),
697
+ __metadata2("design:returntype", void 0)
698
+ ], SwcIf.prototype, "renderTemplate", null);
699
+ SwcIf = __decorate2([
700
+ elementDefind({ tagName: "swc-if", useShadow: true }),
701
+ __metadata2("design:paramtypes", [])
702
+ ], SwcIf);
703
+
704
+ // src/elements/SwcChoose.ts
705
+ var __decorate3 = function(decorators, target, key, desc) {
706
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
707
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
708
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
709
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
710
+ };
711
+ var __metadata3 = function(k, v) {
712
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
713
+ };
714
+ var SwcChoose = class SwcChoose2 extends HTMLElement {
715
+ constructor() {
716
+ super(...arguments);
717
+ this._observer = null;
718
+ this._value = void 0;
719
+ }
720
+ set value(val) {
721
+ this._value = val;
722
+ this.evaluate();
723
+ }
724
+ get value() {
725
+ return this._value;
726
+ }
727
+ styles() {
728
+ return `:host { display: contents; }`;
729
+ }
730
+ render() {
731
+ return `<slot id="choose-slot"></slot>`;
732
+ }
733
+ connectedCallback() {
734
+ this._observer = new MutationObserver(() => this.evaluate());
735
+ this._observer.observe(this, { attributes: true, subtree: true, childList: true });
736
+ this.evaluate();
737
+ }
738
+ disconnectedCallback() {
739
+ this._observer?.disconnect();
740
+ }
741
+ evaluate() {
742
+ const whens = Array.from(this.querySelectorAll("swc-when"));
743
+ const other = this.querySelector("swc-other");
744
+ let matched = false;
745
+ const chooseValue = this.getAttribute("value") ?? this._value;
746
+ whens.forEach((when) => {
747
+ if (matched) {
748
+ when.style.display = "none";
749
+ return;
750
+ }
751
+ const testAttr = when.getAttribute("test");
752
+ if (testAttr === null)
753
+ return;
754
+ if (testAttr.includes("{{"))
755
+ return;
756
+ let isConditionMet = false;
757
+ if (chooseValue !== void 0 && chooseValue !== null) {
758
+ isConditionMet = String(chooseValue) === String(testAttr);
759
+ } else {
760
+ try {
761
+ if (testAttr === "true")
762
+ isConditionMet = true;
763
+ else if (testAttr === "false")
764
+ isConditionMet = false;
765
+ else
766
+ isConditionMet = !!new Function(`return ${testAttr}`)();
767
+ } catch (e) {
768
+ isConditionMet = false;
769
+ }
770
+ }
771
+ if (isConditionMet) {
772
+ when.style.display = "";
773
+ matched = true;
774
+ } else {
775
+ when.style.display = "none";
776
+ }
777
+ });
778
+ if (other) {
779
+ other.style.display = matched ? "none" : "";
780
+ }
781
+ }
782
+ };
783
+ __decorate3([
784
+ style,
785
+ __metadata3("design:type", Function),
786
+ __metadata3("design:paramtypes", []),
787
+ __metadata3("design:returntype", void 0)
788
+ ], SwcChoose.prototype, "styles", null);
789
+ __decorate3([
790
+ template,
791
+ __metadata3("design:type", Function),
792
+ __metadata3("design:paramtypes", []),
793
+ __metadata3("design:returntype", void 0)
794
+ ], SwcChoose.prototype, "render", null);
795
+ SwcChoose = __decorate3([
796
+ elementDefind({ tagName: "swc-choose", useShadow: true })
797
+ ], SwcChoose);
798
+
799
+ // src/elements/SwcWhen.ts
800
+ var __decorate4 = function(decorators, target, key, desc) {
801
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
802
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
803
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
804
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
805
+ };
806
+ var __metadata4 = function(k, v) {
807
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
808
+ };
809
+ var SwcWhen = class SwcWhen2 extends HTMLElement {
810
+ styles() {
811
+ return `:host { display: contents; }`;
812
+ }
813
+ render() {
814
+ return `<slot></slot>`;
815
+ }
816
+ };
817
+ __decorate4([
818
+ style,
819
+ __metadata4("design:type", Function),
820
+ __metadata4("design:paramtypes", []),
821
+ __metadata4("design:returntype", void 0)
822
+ ], SwcWhen.prototype, "styles", null);
823
+ __decorate4([
824
+ template,
825
+ __metadata4("design:type", Function),
826
+ __metadata4("design:paramtypes", []),
827
+ __metadata4("design:returntype", void 0)
828
+ ], SwcWhen.prototype, "render", null);
829
+ SwcWhen = __decorate4([
830
+ elementDefind({ tagName: "swc-when", useShadow: true })
831
+ ], SwcWhen);
832
+
833
+ // src/elements/SwcOther.ts
834
+ var __decorate5 = function(decorators, target, key, desc) {
835
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
836
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
837
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
838
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
839
+ };
840
+ var __metadata5 = function(k, v) {
841
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
842
+ };
843
+ var SwcOther = class SwcOther2 extends HTMLElement {
844
+ styles() {
845
+ return `:host { display: contents; }`;
846
+ }
847
+ render() {
848
+ return `<slot></slot>`;
849
+ }
850
+ };
851
+ __decorate5([
852
+ style,
853
+ __metadata5("design:type", Function),
854
+ __metadata5("design:paramtypes", []),
855
+ __metadata5("design:returntype", void 0)
856
+ ], SwcOther.prototype, "styles", null);
857
+ __decorate5([
858
+ template,
859
+ __metadata5("design:type", Function),
860
+ __metadata5("design:paramtypes", []),
861
+ __metadata5("design:returntype", void 0)
862
+ ], SwcOther.prototype, "render", null);
863
+ SwcOther = __decorate5([
864
+ elementDefind({ tagName: "swc-other", useShadow: true })
865
+ ], SwcOther);
246
866
  export {
867
+ ADD_EVENT_LISTENER_METADATA_KEY,
247
868
  ATTRIBUTE_CHANGED_METADATA_KEY,
869
+ ATTRIBUTE_CHANGED_WILDCARD,
248
870
  ELEMENT_CONFIG_KEY,
871
+ QUERY_ALL_METADATA_KEY,
872
+ QUERY_METADATA_KEY,
249
873
  STYLE_METHOD_KEY,
874
+ SwcChoose,
875
+ SwcForOf,
876
+ SwcIf,
877
+ SwcOther,
878
+ SwcWhen,
250
879
  TEMPLATE_METHOD_KEY,
880
+ addEventListener,
251
881
  attributeChanged,
252
- element,
882
+ elementDefind,
883
+ getAddEventListenerMetadata,
253
884
  getAttributeChangedMap,
254
885
  getElementConfig,
886
+ getQueryAllMetadata,
887
+ getQueryMetadata,
255
888
  getStyleMethod,
256
889
  getTemplateMethod,
890
+ query,
891
+ queryAll,
257
892
  style,
258
893
  template
259
894
  };