@dooboostore/simple-web-component 1.0.15 → 1.0.16

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 (53) hide show
  1. package/README.md +183 -92
  2. package/dist/cjs/decorators/addEventListener.js +2 -3
  3. package/dist/cjs/decorators/addEventListener.js.map +2 -2
  4. package/dist/cjs/decorators/elementDefine.js +89 -33
  5. package/dist/cjs/decorators/elementDefine.js.map +2 -2
  6. package/dist/cjs/decorators/emitCustomEvent.js +2 -14
  7. package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
  8. package/dist/cjs/decorators/query.js +25 -36
  9. package/dist/cjs/decorators/query.js.map +2 -2
  10. package/dist/cjs/decorators/queryAll.js +28 -36
  11. package/dist/cjs/decorators/queryAll.js.map +2 -2
  12. package/dist/cjs/types.js +1 -0
  13. package/dist/cjs/types.js.map +2 -2
  14. package/dist/cjs/utils/Utils.js +36 -143
  15. package/dist/cjs/utils/Utils.js.map +2 -2
  16. package/dist/esm/decorators/addEventListener.js +2 -3
  17. package/dist/esm/decorators/addEventListener.js.map +2 -2
  18. package/dist/esm/decorators/elementDefine.js +89 -33
  19. package/dist/esm/decorators/elementDefine.js.map +2 -2
  20. package/dist/esm/decorators/emitCustomEvent.js +2 -14
  21. package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
  22. package/dist/esm/decorators/query.js +25 -36
  23. package/dist/esm/decorators/query.js.map +2 -2
  24. package/dist/esm/decorators/queryAll.js +28 -36
  25. package/dist/esm/decorators/queryAll.js.map +2 -2
  26. package/dist/esm/types.js +1 -0
  27. package/dist/esm/types.js.map +2 -2
  28. package/dist/esm/utils/Utils.js +36 -143
  29. package/dist/esm/utils/Utils.js.map +2 -2
  30. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +183 -266
  31. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +3 -3
  32. package/dist/types/decorators/addEventListener.d.ts +9 -4
  33. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  34. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  35. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  36. package/dist/types/decorators/query.d.ts +6 -5
  37. package/dist/types/decorators/query.d.ts.map +1 -1
  38. package/dist/types/decorators/queryAll.d.ts +6 -5
  39. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  40. package/dist/types/types.d.ts +3 -1
  41. package/dist/types/types.d.ts.map +1 -1
  42. package/dist/types/utils/Utils.d.ts +6 -14
  43. package/dist/types/utils/Utils.d.ts.map +1 -1
  44. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +183 -266
  45. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +3 -3
  46. package/package.json +3 -3
  47. package/src/decorators/addEventListener.ts +10 -7
  48. package/src/decorators/elementDefine.ts +86 -31
  49. package/src/decorators/emitCustomEvent.ts +5 -21
  50. package/src/decorators/query.ts +33 -46
  51. package/src/decorators/queryAll.ts +36 -46
  52. package/src/types.ts +6 -4
  53. package/src/utils/Utils.ts +40 -176
@@ -1248,16 +1248,15 @@ var getInnerHtmlMetadataList = (target) => {
1248
1248
 
1249
1249
  // src/decorators/addEventListener.ts
1250
1250
  var ADD_EVENT_LISTENER_METADATA_KEY = Symbol("simple-web-component:add-event-listener");
1251
- function addEventListener(arg1, arg2) {
1251
+ function addEventListener(selector, type, options = {}) {
1252
1252
  return (target, propertyKey, descriptor) => {
1253
1253
  const constructor = target.constructor;
1254
- const options = typeof arg1 === "string" ? { type: arg1, query: arg2 } : arg1;
1255
1254
  let listeners = ReflectUtils.getMetadata(ADD_EVENT_LISTENER_METADATA_KEY, constructor);
1256
1255
  if (!listeners) {
1257
1256
  listeners = [];
1258
1257
  ReflectUtils.defineMetadata(ADD_EVENT_LISTENER_METADATA_KEY, listeners, constructor);
1259
1258
  }
1260
- listeners.push({ options, propertyKey });
1259
+ listeners.push({ selector, type, options, propertyKey });
1261
1260
  };
1262
1261
  }
1263
1262
  var getAddEventListenerMetadata = (target) => {
@@ -1303,11 +1302,11 @@ var findAllLifecycleMetadata = (target, metadataKey) => {
1303
1302
  // src/decorators/emitCustomEvent.ts
1304
1303
  var EMIT_CUSTOM_EVENT_METADATA_KEY = Symbol("simple-web-component:emit-custom-event");
1305
1304
  function emitCustomEvent(typeOrOptions) {
1306
- return (target, propertyKey, descriptor) => {
1305
+ return (target, propertyKey) => {
1307
1306
  const constructor = target.constructor;
1308
1307
  const options = typeof typeOrOptions === "string" ? { type: typeOrOptions } : typeOrOptions;
1309
1308
  if (!options.attributeName) {
1310
- options.attributeName = `on${options.type}`;
1309
+ options.attributeName = `swc-on-${options.type}`;
1311
1310
  }
1312
1311
  if (options.bubbles === void 0) options.bubbles = true;
1313
1312
  if (options.composed === void 0) options.composed = true;
@@ -1317,18 +1316,6 @@ function emitCustomEvent(typeOrOptions) {
1317
1316
  ReflectUtils.defineMetadata(EMIT_CUSTOM_EVENT_METADATA_KEY, list, constructor);
1318
1317
  }
1319
1318
  list.push({ propertyKey, options });
1320
- const originalMethod = descriptor.value;
1321
- descriptor.value = function(...args) {
1322
- const detail = originalMethod.apply(this, args);
1323
- const event = new CustomEvent(options.type, {
1324
- detail,
1325
- bubbles: options.bubbles,
1326
- composed: options.composed,
1327
- cancelable: options.cancelable
1328
- });
1329
- this.dispatchEvent(event);
1330
- return detail;
1331
- };
1332
1319
  };
1333
1320
  }
1334
1321
  var getEmitCustomEventMetadataList = (target) => {
@@ -1393,148 +1380,43 @@ var findAllSetAttributeMetadata = (target) => {
1393
1380
 
1394
1381
  // src/utils/Utils.ts
1395
1382
  var SWC_NOT_FOUND = Symbol("SWC_NOT_FOUND");
1396
- var SwcUtils = class _SwcUtils {
1383
+ var SwcUtils = class {
1397
1384
  static getValueByPath(obj, path, rootName) {
1398
1385
  if (!obj || !path) return SWC_NOT_FOUND;
1399
1386
  const parts = path.split(".");
1400
- if (parts[0] === rootName && parts.length > 1) {
1401
- const subParts = parts.slice(1);
1402
- let subResult = obj;
1403
- for (const part of subParts) {
1404
- if (subResult === null || typeof subResult !== "object" || !(part in subResult)) return SWC_NOT_FOUND;
1405
- subResult = subResult[part];
1406
- }
1407
- return subResult;
1408
- }
1409
- let result = obj;
1387
+ let current = obj;
1410
1388
  for (const part of parts) {
1411
- if (result === null || typeof result !== "object" || !(part in result)) {
1412
- return SWC_NOT_FOUND;
1413
- }
1414
- result = result[part];
1415
- }
1416
- if (result !== obj && !(result instanceof HTMLElement)) {
1417
- return result;
1389
+ if (current === null || current === void 0) return SWC_NOT_FOUND;
1390
+ current = current[part];
1418
1391
  }
1419
- return SWC_NOT_FOUND;
1420
- }
1421
- static evalExpression(expr, context) {
1422
- try {
1423
- const keys = Object.keys(context);
1424
- const values = Object.values(context);
1425
- return new Function(...keys, `return (${expr})`).apply(null, values);
1426
- } catch {
1427
- return SWC_NOT_FOUND;
1428
- }
1429
- }
1430
- static applyData(node, data, options) {
1431
- const { asKey, asIndexKey, index, hostContext } = options;
1432
- const context = {};
1433
- if (index !== void 0) {
1434
- context[asIndexKey] = index;
1435
- }
1436
- if (data !== null && data !== void 0) {
1437
- context[asKey] = data;
1438
- context["value"] = data;
1439
- }
1440
- const fullContext = { ...hostContext || {}, ...context };
1441
- const resolveExpr = (expr, match) => {
1442
- expr = expr.trim();
1443
- const simpleVal = _SwcUtils.getValueByPath(data, expr, asKey);
1444
- if (simpleVal !== SWC_NOT_FOUND && typeof simpleVal !== "symbol") {
1445
- return simpleVal === null || simpleVal === void 0 ? "" : String(simpleVal);
1446
- }
1447
- const exprVal = _SwcUtils.evalExpression(expr, fullContext);
1448
- if (exprVal !== SWC_NOT_FOUND && typeof exprVal !== "symbol") {
1449
- return exprVal === null || exprVal === void 0 ? "" : String(exprVal);
1450
- }
1451
- return match;
1452
- };
1453
- const walk = (n) => {
1454
- if (n.nodeType === Node.TEXT_NODE) {
1455
- if (!n._original) n._original = n.textContent;
1456
- let text = n._original;
1457
- text = text.replace(/{{(.*?)}}/g, (match, path) => {
1458
- return resolveExpr(path, match);
1459
- });
1460
- if (n.textContent !== text) n.textContent = text;
1461
- } else if (n.nodeType === Node.ELEMENT_NODE) {
1462
- const el = n;
1463
- Array.from(el.attributes).forEach((a) => {
1464
- if (!a._original) a._original = a.value;
1465
- let val = a._original;
1466
- val = val.replace(/{{(.*?)}}/g, (match, path) => {
1467
- return resolveExpr(path, match);
1468
- });
1469
- if (a.value !== val) a.value = val;
1470
- });
1471
- el.childNodes.forEach(walk);
1472
- }
1473
- };
1474
- walk(node);
1475
- }
1476
- static createReactiveProxy(target, onChange, onIndexChange) {
1477
- const makeRecursiveProxy = (obj) => {
1478
- if (typeof obj !== "object" || obj === null || obj instanceof Node) return obj;
1479
- if (obj.__swc_is_proxy) return obj;
1480
- const IS_PROXY_KEY = "__swc_is_proxy";
1481
- const proxy = new Proxy(obj, {
1482
- get: (t, prop) => {
1483
- if (prop === IS_PROXY_KEY) return true;
1484
- if (typeof prop === "symbol") return t[prop];
1485
- return t[prop];
1486
- },
1487
- set: (t, prop, val) => {
1488
- if (prop === IS_PROXY_KEY) return true;
1489
- if (typeof prop === "symbol") {
1490
- t[prop] = val;
1491
- return true;
1492
- }
1493
- const oldVal = t[prop];
1494
- if (oldVal === val) return true;
1495
- t[prop] = makeRecursiveProxy(val);
1496
- const isIndex = !isNaN(Number(prop)) && Array.isArray(t);
1497
- if (isIndex && onIndexChange) {
1498
- onIndexChange(Number(prop), val);
1499
- } else {
1500
- onChange();
1501
- }
1502
- return true;
1503
- },
1504
- deleteProperty: (t, prop) => {
1505
- delete t[prop];
1506
- onChange();
1507
- return true;
1508
- }
1509
- });
1510
- return proxy;
1511
- };
1512
- return makeRecursiveProxy(target);
1392
+ return current;
1513
1393
  }
1514
1394
  static findNearestSwcHost(el) {
1515
- const hosts = this.findAllSwcHosts(el);
1516
- return hosts.length > 0 ? hosts[hosts.length - 1] : null;
1395
+ let current = el instanceof Node && !(el instanceof HTMLElement) ? el.host : el;
1396
+ current = current?.parentElement || current?.getRootNode()?.host;
1397
+ while (current) {
1398
+ if (getElementConfig(current)) return current;
1399
+ current = current.parentElement || current?.getRootNode()?.host;
1400
+ }
1401
+ return void 0;
1517
1402
  }
1403
+ /**
1404
+ * Returns all SWC ancestors (excluding self) in [root, ..., parent] order.
1405
+ */
1518
1406
  static findAllSwcHosts(el) {
1519
1407
  const hosts = [];
1520
- let curr = el instanceof Node && !(el instanceof HTMLElement) ? el.host : el;
1521
- curr = curr?.parentElement || curr?.getRootNode()?.host;
1522
- while (curr) {
1523
- if (curr._swcId) hosts.push(curr);
1524
- curr = curr.parentElement || curr?.getRootNode()?.host;
1408
+ let current = this.findNearestSwcHost(el);
1409
+ while (current) {
1410
+ hosts.push(current);
1411
+ current = this.findNearestSwcHost(current);
1525
1412
  }
1526
1413
  return hosts.reverse();
1527
1414
  }
1528
1415
  static getHosts(el) {
1529
- return this.findAllSwcHosts(el);
1416
+ return [...this.findAllSwcHosts(el), el];
1530
1417
  }
1531
1418
  static getHost(el) {
1532
- const hosts = this.getHosts(el);
1533
- return hosts.length > 0 ? hosts[hosts.length - 1] : void 0;
1534
- }
1535
- static getFirstHost(el) {
1536
- const hosts = this.getHosts(el);
1537
- return hosts.length > 0 ? hosts[0] : void 0;
1419
+ return el;
1538
1420
  }
1539
1421
  static getAppHosts(el) {
1540
1422
  const hosts = this.getHosts(el);
@@ -1542,31 +1424,28 @@ var SwcUtils = class _SwcUtils {
1542
1424
  }
1543
1425
  static getAppHost(el) {
1544
1426
  const appHosts = this.getAppHosts(el);
1545
- return appHosts.length > 0 ? appHosts[appHosts.length - 1] : void 0;
1546
- }
1547
- static getFirstAppHost(el) {
1548
- const appHosts = this.getAppHosts(el);
1549
- return appHosts.length > 0 ? appHosts[0] : void 0;
1550
- }
1551
- static getLastAppHost(el) {
1552
- return this.getAppHost(el);
1427
+ const appHostsWithoutSelf = appHosts.filter((h) => h !== el);
1428
+ return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : void 0;
1553
1429
  }
1554
1430
  static getHostSet(el) {
1555
- const $hosts = this.getHosts(el);
1556
- const $appHosts = this.getAppHosts(el);
1557
- const $firstHost = $hosts[0] || null;
1558
- const $lastHost = $hosts[$hosts.length - 1] || null;
1559
- const $firstAppHost = $appHosts[0] || null;
1560
- const $lastAppHost = $appHosts[$appHosts.length - 1] || null;
1431
+ const ancestors = this.findAllSwcHosts(el);
1432
+ const $host = el;
1433
+ const $hosts = [...ancestors, $host];
1434
+ const $parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;
1435
+ const $firstHost = ancestors.length > 0 ? ancestors[0] : null;
1436
+ const $appHosts = $hosts.filter((h) => h.tagName.toLowerCase() === "swc-app" || h.getAttribute("is")?.startsWith("swc-app-"));
1437
+ const $appHost = $appHosts.length > 0 ? $appHosts[$appHosts.length - 1] === el ? $appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null : $appHosts[$appHosts.length - 1] : null;
1438
+ const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;
1561
1439
  return {
1562
- $host: $lastHost,
1440
+ $host,
1441
+ $parentHost,
1563
1442
  $hosts,
1564
1443
  $firstHost,
1565
- $lastHost,
1566
- $appHost: $lastAppHost,
1444
+ $lastHost: $parentHost,
1445
+ $appHost,
1567
1446
  $appHosts,
1568
1447
  $firstAppHost,
1569
- $lastAppHost
1448
+ $lastAppHost: $appHost
1570
1449
  };
1571
1450
  }
1572
1451
  };
@@ -1681,6 +1560,7 @@ var InjectSituationType = /* @__PURE__ */ ((InjectSituationType2) => {
1681
1560
  InjectSituationType2["APP_HOST"] = "SIMPLE_WEB_COMPONENT://APPHOST";
1682
1561
  InjectSituationType2["APP_HOSTS"] = "SIMPLE_WEB_COMPONENT://APPHOSTS";
1683
1562
  InjectSituationType2["HOST"] = "SIMPLE_WEB_COMPONENT://HOST";
1563
+ InjectSituationType2["PARENT_HOST"] = "SIMPLE_WEB_COMPONENT://PARENTHOST";
1684
1564
  InjectSituationType2["HOSTS"] = "SIMPLE_WEB_COMPONENT://HOSTS";
1685
1565
  InjectSituationType2["FIRST_HOST"] = "SIMPLE_WEB_COMPONENT://FIRSTHOST";
1686
1566
  InjectSituationType2["LAST_HOST"] = "SIMPLE_WEB_COMPONENT://LASTHOST";
@@ -1769,10 +1649,12 @@ var elementDefine = (inConfig) => (constructor) => {
1769
1649
  return this[methodName](...extraArgs);
1770
1650
  }
1771
1651
  }
1772
- _bindAttributeEvent(el, attrName, script) {
1773
- if (!attrName.startsWith("swc-on-"))
1774
- return;
1775
- const eventName = attrName.substring(7);
1652
+ _bindAttributeEvent(el, attrName, script, eventName) {
1653
+ if (!eventName) {
1654
+ if (!attrName.startsWith("swc-on-"))
1655
+ return;
1656
+ eventName = attrName.substring(7);
1657
+ }
1776
1658
  if (swcLifecycleAttributes.includes(attrName))
1777
1659
  return;
1778
1660
  const elHandlers = getHandlers(this);
@@ -1833,44 +1715,79 @@ var elementDefine = (inConfig) => (constructor) => {
1833
1715
  this.innerHTML = lContent;
1834
1716
  }
1835
1717
  addEventListenerList.forEach((meta) => {
1836
- const { type, query: query2, root, capture, once, passive, stopPropagation, stopImmediatePropagation, preventDefault } = meta.options;
1837
- const targetEls = [];
1838
- if (!query2) {
1839
- targetEls.push(this);
1840
- } else {
1841
- const searchRoots = [];
1718
+ const { selector, type, options } = meta;
1719
+ const { root, capture, once, passive, stopPropagation, stopImmediatePropagation, preventDefault, delegate } = options;
1720
+ if (delegate && selector && selector !== ":host") {
1721
+ const bindRoots = [];
1842
1722
  const r = root || "auto";
1843
1723
  if (r === "auto") {
1844
- searchRoots.push(this.shadowRoot || this);
1724
+ bindRoots.push(this.shadowRoot || this);
1845
1725
  } else if (r === "light") {
1846
- searchRoots.push(this);
1726
+ bindRoots.push(this);
1847
1727
  } else if (r === "shadow") {
1848
1728
  if (this.shadowRoot)
1849
- searchRoots.push(this.shadowRoot);
1729
+ bindRoots.push(this.shadowRoot);
1850
1730
  } else if (r === "all") {
1851
- searchRoots.push(this);
1731
+ bindRoots.push(this);
1852
1732
  if (this.shadowRoot)
1853
- searchRoots.push(this.shadowRoot);
1733
+ bindRoots.push(this.shadowRoot);
1854
1734
  }
1855
- searchRoots.forEach((sr) => {
1856
- const found = sr.querySelectorAll(query2);
1857
- found.forEach((el) => targetEls.push(el));
1735
+ bindRoots.forEach((bindRoot) => {
1736
+ const handler = (event) => {
1737
+ const target = event.target;
1738
+ const matchedEl = target.closest(selector);
1739
+ if (matchedEl && bindRoot.contains(matchedEl)) {
1740
+ if (stopPropagation)
1741
+ event.stopPropagation();
1742
+ if (stopImmediatePropagation)
1743
+ event.stopImmediatePropagation();
1744
+ if (preventDefault)
1745
+ event.preventDefault();
1746
+ const hostSet2 = SwcUtils.getHostSet(this);
1747
+ this._invokeLifecycleMethod(meta.propertyKey, hostSet2, [event, hostSet2, matchedEl]);
1748
+ }
1749
+ };
1750
+ bindRoot.addEventListener(type, handler, { capture, once, passive });
1751
+ });
1752
+ } else {
1753
+ const targetEls = [];
1754
+ if (!selector || selector === ":host") {
1755
+ targetEls.push(this);
1756
+ } else {
1757
+ const searchRoots = [];
1758
+ const r = root || "auto";
1759
+ if (r === "auto") {
1760
+ searchRoots.push(this.shadowRoot || this);
1761
+ } else if (r === "light") {
1762
+ searchRoots.push(this);
1763
+ } else if (r === "shadow") {
1764
+ if (this.shadowRoot)
1765
+ searchRoots.push(this.shadowRoot);
1766
+ } else if (r === "all") {
1767
+ searchRoots.push(this);
1768
+ if (this.shadowRoot)
1769
+ searchRoots.push(this.shadowRoot);
1770
+ }
1771
+ searchRoots.forEach((sr) => {
1772
+ const found = sr.querySelectorAll(selector);
1773
+ found.forEach((el) => targetEls.push(el));
1774
+ });
1775
+ }
1776
+ targetEls.forEach((el) => {
1777
+ const handler = (event) => {
1778
+ if (stopPropagation)
1779
+ event.stopPropagation();
1780
+ if (stopImmediatePropagation)
1781
+ event.stopImmediatePropagation();
1782
+ if (preventDefault)
1783
+ event.preventDefault();
1784
+ const hostSet2 = SwcUtils.getHostSet(this);
1785
+ this._invokeLifecycleMethod(meta.propertyKey, hostSet2, [event, hostSet2]);
1786
+ };
1787
+ const opts = { capture, once, passive };
1788
+ el.addEventListener(type, handler, opts);
1858
1789
  });
1859
1790
  }
1860
- targetEls.forEach((el) => {
1861
- const handler = (event) => {
1862
- if (stopPropagation)
1863
- event.stopPropagation();
1864
- if (stopImmediatePropagation)
1865
- event.stopImmediatePropagation();
1866
- if (preventDefault)
1867
- event.preventDefault();
1868
- const hostSet2 = SwcUtils.getHostSet(this);
1869
- this._invokeLifecycleMethod(meta.propertyKey, hostSet2, [event, hostSet2]);
1870
- };
1871
- const options = { capture, once, passive };
1872
- el.addEventListener(type, handler, options);
1873
- });
1874
1791
  });
1875
1792
  if (super.connectedCallback)
1876
1793
  await super.connectedCallback();
@@ -1915,7 +1832,9 @@ var elementDefine = (inConfig) => (constructor) => {
1915
1832
  super.attributeChangedCallback(name, old, newVal);
1916
1833
  if (name.startsWith("swc-on-") && !swcLifecycleAttributes.includes(name)) {
1917
1834
  if (newVal !== null) {
1918
- this._bindAttributeEvent(this, name, newVal);
1835
+ const customEventMeta = emitCustomEventList.find((it) => it.options.attributeName === name);
1836
+ const eventName = customEventMeta ? customEventMeta.options.type : name.substring(7);
1837
+ this._bindAttributeEvent(this, name, newVal, eventName);
1919
1838
  }
1920
1839
  }
1921
1840
  const mKeys = attrChangeMap.get(name);
@@ -1940,6 +1859,23 @@ var elementDefine = (inConfig) => (constructor) => {
1940
1859
  };
1941
1860
  }
1942
1861
  });
1862
+ emitCustomEventList.forEach((meta) => {
1863
+ const { propertyKey, options } = meta;
1864
+ const original = NewClass.prototype[propertyKey];
1865
+ if (typeof original === "function") {
1866
+ NewClass.prototype[propertyKey] = function(...args) {
1867
+ const detail = original.apply(this, args);
1868
+ const event = new CustomEvent(options.type, {
1869
+ detail,
1870
+ bubbles: options.bubbles,
1871
+ composed: options.composed,
1872
+ cancelable: options.cancelable
1873
+ });
1874
+ this.dispatchEvent(event);
1875
+ return detail;
1876
+ };
1877
+ }
1878
+ });
1943
1879
  const originalProto = constructor.prototype;
1944
1880
  const newProto = NewClass.prototype;
1945
1881
  Object.getOwnPropertyNames(originalProto).forEach((name) => {
@@ -1963,48 +1899,37 @@ var getElementConfig = (target) => {
1963
1899
 
1964
1900
  // src/decorators/query.ts
1965
1901
  var QUERY_METADATA_KEY = Symbol("simple-web-component:query");
1966
- function query(arg1, arg2) {
1967
- const decorator = (selector, options, target, propertyKey, descriptor) => {
1968
- const isMethod = !!descriptor;
1902
+ function query(selector, options = {}) {
1903
+ return (target, propertyKey, descriptor) => {
1904
+ if (descriptor !== void 0) {
1905
+ throw new Error(`@query decorator cannot be used on methods. (Method: ${String(propertyKey)})`);
1906
+ }
1969
1907
  const constructor = target.constructor;
1970
1908
  let queries = ReflectUtils.getMetadata(QUERY_METADATA_KEY, constructor);
1971
1909
  if (!queries) {
1972
1910
  queries = [];
1973
1911
  ReflectUtils.defineMetadata(QUERY_METADATA_KEY, queries, constructor);
1974
1912
  }
1975
- queries.push({ selector, options, propertyKey, isMethod });
1976
- if (!isMethod) {
1977
- Object.defineProperty(target, propertyKey, {
1978
- get() {
1979
- if (!selector)
1980
- return this;
1981
- let searchRoot = this;
1982
- if (options.root === "shadow")
1983
- searchRoot = this.shadowRoot || this;
1984
- else if (options.root === "light")
1985
- searchRoot = this;
1986
- else
1987
- searchRoot = this.shadowRoot || this;
1988
- return searchRoot.querySelector(selector);
1989
- },
1990
- enumerable: true,
1991
- configurable: true
1992
- });
1993
- }
1994
- };
1995
- if (arg1 && typeof arg2 === "string") {
1996
- return decorator("", {}, arg1, arg2);
1997
- }
1998
- return (target, propertyKey, descriptor) => {
1999
- let selector = "";
2000
- let options = {};
2001
- if (typeof arg1 === "string") {
2002
- selector = arg1;
2003
- } else if (typeof arg1 === "object") {
2004
- options = arg1;
2005
- selector = options.selector || "";
2006
- }
2007
- decorator(selector, options, target, propertyKey, descriptor);
1913
+ queries.push({ selector, options, propertyKey });
1914
+ Object.defineProperty(target, propertyKey, {
1915
+ get() {
1916
+ if (!selector || selector === ":host")
1917
+ return this;
1918
+ const r = options.root || "auto";
1919
+ if (r === "shadow") {
1920
+ return this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;
1921
+ }
1922
+ if (r === "light") {
1923
+ return this.querySelector(selector);
1924
+ }
1925
+ if (r === "all") {
1926
+ return this.shadowRoot?.querySelector(selector) || this.querySelector(selector);
1927
+ }
1928
+ return (this.shadowRoot || this).querySelector(selector);
1929
+ },
1930
+ enumerable: true,
1931
+ configurable: true
1932
+ });
2008
1933
  };
2009
1934
  }
2010
1935
  var getQueryMetadata = (target) => {
@@ -2014,48 +1939,40 @@ var getQueryMetadata = (target) => {
2014
1939
 
2015
1940
  // src/decorators/queryAll.ts
2016
1941
  var QUERY_ALL_METADATA_KEY = Symbol("simple-web-component:query-all");
2017
- function queryAll(arg1, arg2) {
2018
- const decorator = (selector, options, target, propertyKey, descriptor) => {
2019
- const isMethod = !!descriptor;
1942
+ function queryAll(selector, options = {}) {
1943
+ return (target, propertyKey, descriptor) => {
1944
+ if (descriptor !== void 0) {
1945
+ throw new Error(`@queryAll decorator cannot be used on methods. (Method: ${String(propertyKey)})`);
1946
+ }
2020
1947
  const constructor = target.constructor;
2021
1948
  let queries = ReflectUtils.getMetadata(QUERY_ALL_METADATA_KEY, constructor);
2022
1949
  if (!queries) {
2023
1950
  queries = [];
2024
1951
  ReflectUtils.defineMetadata(QUERY_ALL_METADATA_KEY, queries, constructor);
2025
1952
  }
2026
- queries.push({ selector, options, propertyKey, isMethod });
2027
- if (!isMethod) {
2028
- Object.defineProperty(target, propertyKey, {
2029
- get() {
2030
- if (!selector)
2031
- return [this];
2032
- let searchRoot = this;
2033
- if (options.root === "shadow")
2034
- searchRoot = this.shadowRoot || this;
2035
- else if (options.root === "light")
2036
- searchRoot = this;
2037
- else
2038
- searchRoot = this.shadowRoot || this;
2039
- return searchRoot.querySelectorAll(selector);
2040
- },
2041
- enumerable: true,
2042
- configurable: true
2043
- });
2044
- }
2045
- };
2046
- if (arg1 && typeof arg2 === "string") {
2047
- return decorator("", {}, arg1, arg2);
2048
- }
2049
- return (target, propertyKey, descriptor) => {
2050
- let selector = "";
2051
- let options = {};
2052
- if (typeof arg1 === "string") {
2053
- selector = arg1;
2054
- } else if (typeof arg1 === "object") {
2055
- options = arg1;
2056
- selector = options.selector || "";
2057
- }
2058
- decorator(selector, options, target, propertyKey, descriptor);
1953
+ queries.push({ selector, options, propertyKey });
1954
+ Object.defineProperty(target, propertyKey, {
1955
+ get() {
1956
+ if (!selector || selector === ":host")
1957
+ return [this];
1958
+ const r = options.root || "auto";
1959
+ if (r === "shadow") {
1960
+ return this.shadowRoot ? this.shadowRoot.querySelectorAll(selector) : [];
1961
+ }
1962
+ if (r === "light") {
1963
+ return this.querySelectorAll(selector);
1964
+ }
1965
+ if (r === "all") {
1966
+ const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];
1967
+ const lNodes = Array.from(this.querySelectorAll(selector));
1968
+ return [...sNodes, ...lNodes];
1969
+ }
1970
+ const root = this.shadowRoot || this;
1971
+ return root.querySelectorAll(selector);
1972
+ },
1973
+ enumerable: true,
1974
+ configurable: true
1975
+ });
2059
1976
  };
2060
1977
  }
2061
1978
  var getQueryAllMetadata = (target) => {