@dooboostore/simple-web-component 1.0.16 → 1.0.17

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 (98) hide show
  1. package/README.md +93 -0
  2. package/dist/cjs/decorators/addEventListener.js.map +2 -2
  3. package/dist/cjs/decorators/elementDefine.js +133 -62
  4. package/dist/cjs/decorators/elementDefine.js.map +3 -3
  5. package/dist/cjs/decorators/query.js +22 -0
  6. package/dist/cjs/decorators/query.js.map +2 -2
  7. package/dist/cjs/decorators/queryAll.js +14 -0
  8. package/dist/cjs/decorators/queryAll.js.map +2 -2
  9. package/dist/cjs/elements/SwcAppEngine.js +2 -1
  10. package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
  11. package/dist/cjs/elements/SwcAsync.js +188 -0
  12. package/dist/cjs/elements/SwcAsync.js.map +7 -0
  13. package/dist/cjs/elements/SwcChoose.js +155 -0
  14. package/dist/cjs/elements/SwcChoose.js.map +7 -0
  15. package/dist/cjs/elements/SwcIf.js +167 -0
  16. package/dist/cjs/elements/SwcIf.js.map +7 -0
  17. package/dist/cjs/elements/SwcLoop.js +246 -0
  18. package/dist/cjs/elements/SwcLoop.js.map +7 -0
  19. package/dist/cjs/elements/SwcSubTemplates.js +65 -0
  20. package/dist/cjs/elements/SwcSubTemplates.js.map +7 -0
  21. package/dist/cjs/elements/index.js +7 -0
  22. package/dist/cjs/elements/index.js.map +2 -2
  23. package/dist/cjs/index.js +1 -1
  24. package/dist/cjs/index.js.map +2 -2
  25. package/dist/cjs/types.js.map +1 -1
  26. package/dist/cjs/utils/Utils.js +74 -37
  27. package/dist/cjs/utils/Utils.js.map +3 -3
  28. package/dist/esm/decorators/addEventListener.js.map +2 -2
  29. package/dist/esm/decorators/elementDefine.js +133 -62
  30. package/dist/esm/decorators/elementDefine.js.map +3 -3
  31. package/dist/esm/decorators/query.js +22 -0
  32. package/dist/esm/decorators/query.js.map +2 -2
  33. package/dist/esm/decorators/queryAll.js +14 -0
  34. package/dist/esm/decorators/queryAll.js.map +2 -2
  35. package/dist/esm/elements/SwcAppEngine.js +2 -1
  36. package/dist/esm/elements/SwcAppEngine.js.map +2 -2
  37. package/dist/esm/elements/SwcAsync.js +169 -0
  38. package/dist/esm/elements/SwcAsync.js.map +7 -0
  39. package/dist/esm/elements/SwcChoose.js +136 -0
  40. package/dist/esm/elements/SwcChoose.js.map +7 -0
  41. package/dist/esm/elements/SwcIf.js +148 -0
  42. package/dist/esm/elements/SwcIf.js.map +7 -0
  43. package/dist/esm/elements/SwcLoop.js +227 -0
  44. package/dist/esm/elements/SwcLoop.js.map +7 -0
  45. package/dist/esm/elements/SwcSubTemplates.js +46 -0
  46. package/dist/esm/elements/SwcSubTemplates.js.map +7 -0
  47. package/dist/esm/elements/index.js +7 -0
  48. package/dist/esm/elements/index.js.map +2 -2
  49. package/dist/esm/index.js +1 -1
  50. package/dist/esm/index.js.map +1 -1
  51. package/dist/esm/types.js.map +1 -1
  52. package/dist/esm/utils/Utils.js +74 -37
  53. package/dist/esm/utils/Utils.js.map +3 -3
  54. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +1047 -140
  55. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  56. package/dist/types/decorators/addEventListener.d.ts +1 -0
  57. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  58. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  59. package/dist/types/decorators/query.d.ts +0 -2
  60. package/dist/types/decorators/query.d.ts.map +1 -1
  61. package/dist/types/decorators/queryAll.d.ts +0 -2
  62. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  63. package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
  64. package/dist/types/elements/SwcAsync.d.ts +16 -0
  65. package/dist/types/elements/SwcAsync.d.ts.map +1 -0
  66. package/dist/types/elements/SwcChoose.d.ts +13 -0
  67. package/dist/types/elements/SwcChoose.d.ts.map +1 -0
  68. package/dist/types/elements/SwcIf.d.ts +15 -0
  69. package/dist/types/elements/SwcIf.d.ts.map +1 -0
  70. package/dist/types/elements/SwcLoop.d.ts +20 -0
  71. package/dist/types/elements/SwcLoop.d.ts.map +1 -0
  72. package/dist/types/elements/SwcSubTemplates.d.ts +13 -0
  73. package/dist/types/elements/SwcSubTemplates.d.ts.map +1 -0
  74. package/dist/types/elements/index.d.ts +7 -0
  75. package/dist/types/elements/index.d.ts.map +1 -1
  76. package/dist/types/index.d.ts +1 -1
  77. package/dist/types/index.d.ts.map +1 -1
  78. package/dist/types/types.d.ts +8 -0
  79. package/dist/types/types.d.ts.map +1 -1
  80. package/dist/types/utils/Utils.d.ts +16 -10
  81. package/dist/types/utils/Utils.d.ts.map +1 -1
  82. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +1047 -140
  83. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  84. package/package.json +10 -3
  85. package/src/decorators/addEventListener.ts +1 -0
  86. package/src/decorators/elementDefine.ts +137 -66
  87. package/src/decorators/query.ts +20 -2
  88. package/src/decorators/queryAll.ts +16 -2
  89. package/src/elements/SwcAppEngine.ts +2 -1
  90. package/src/elements/SwcAsync.ts +163 -0
  91. package/src/elements/SwcChoose.ts +127 -0
  92. package/src/elements/SwcIf.ts +134 -0
  93. package/src/elements/SwcLoop.ts +215 -0
  94. package/src/elements/SwcSubTemplates.ts +19 -0
  95. package/src/elements/index.ts +8 -3
  96. package/src/index.ts +1 -1
  97. package/src/types.ts +9 -1
  98. package/src/utils/Utils.ts +86 -36
@@ -1136,6 +1136,7 @@ var dooboostoreSimpleWebComponent = (() => {
1136
1136
  QUERY_METADATA_KEY: () => QUERY_METADATA_KEY,
1137
1137
  SET_ATTRIBUTE_METADATA_KEY: () => SET_ATTRIBUTE_METADATA_KEY,
1138
1138
  SWC_NOT_FOUND: () => SWC_NOT_FOUND,
1139
+ SwcApp: () => SwcApp,
1139
1140
  SwcAppAnchor: () => SwcAppAnchor,
1140
1141
  SwcAppArea: () => SwcAppArea,
1141
1142
  SwcAppAudio: () => SwcAppAudio,
@@ -1150,6 +1151,7 @@ var dooboostoreSimpleWebComponent = (() => {
1150
1151
  SwcAppDiv: () => SwcAppDiv,
1151
1152
  SwcAppDl: () => SwcAppDl,
1152
1153
  SwcAppEmbed: () => SwcAppEmbed,
1154
+ SwcAppEngine: () => SwcAppEngine,
1153
1155
  SwcAppFieldSet: () => SwcAppFieldSet,
1154
1156
  SwcAppForm: () => SwcAppForm,
1155
1157
  SwcAppHeading: () => SwcAppHeading,
@@ -1193,7 +1195,17 @@ var dooboostoreSimpleWebComponent = (() => {
1193
1195
  SwcAppTrack: () => SwcAppTrack,
1194
1196
  SwcAppUl: () => SwcAppUl,
1195
1197
  SwcAppVideo: () => SwcAppVideo,
1198
+ SwcAsync: () => SwcAsync,
1199
+ SwcChoose: () => SwcChoose,
1200
+ SwcDefault: () => SwcDefault,
1201
+ SwcError: () => SwcError,
1202
+ SwcIf: () => SwcIf,
1203
+ SwcLoading: () => SwcLoading,
1204
+ SwcLoop: () => SwcLoop,
1205
+ SwcOtherwise: () => SwcOtherwise,
1206
+ SwcSuccess: () => SwcSuccess,
1196
1207
  SwcUtils: () => SwcUtils,
1208
+ SwcWhen: () => SwcWhen,
1197
1209
  addEventListener: () => addEventListener,
1198
1210
  changedAttribute: () => changedAttribute,
1199
1211
  elementDefine: () => elementDefine,
@@ -1230,32 +1242,33 @@ var dooboostoreSimpleWebComponent = (() => {
1230
1242
  var import_reflect_metadata = __toESM(require_Reflect(), 1);
1231
1243
 
1232
1244
  // ../core/dist/esm/reflect/ReflectUtils.js
1233
- var ReflectUtils = {
1234
- getParameterTypes: (target, propertyKey) => {
1245
+ var ReflectUtils;
1246
+ ((ReflectUtils2) => {
1247
+ ReflectUtils2.getParameterTypes = (target, propertyKey) => {
1235
1248
  if (propertyKey) {
1236
1249
  return Reflect.getMetadata("design:paramtypes", target, propertyKey) || [];
1237
1250
  } else {
1238
1251
  return Reflect.getMetadata("design:paramtypes", target) || [];
1239
1252
  }
1240
- },
1241
- getReturnType: (target, propertyKey) => {
1253
+ };
1254
+ ReflectUtils2.getReturnType = (target, propertyKey) => {
1242
1255
  return Reflect.getMetadata("design:returntype", target, propertyKey);
1243
- },
1244
- getType: (target, propertyKey) => {
1256
+ };
1257
+ ReflectUtils2.getType = (target, propertyKey) => {
1245
1258
  if (propertyKey) {
1246
1259
  return Reflect.getMetadata("design:type", target, propertyKey);
1247
1260
  } else {
1248
1261
  return Reflect.getMetadata("design:type", target);
1249
1262
  }
1250
- },
1251
- getMetadata: (metadataKey, target, propertyKey) => {
1263
+ };
1264
+ ReflectUtils2.getMetadata = (metadataKey, target, propertyKey) => {
1252
1265
  if (propertyKey) {
1253
1266
  return Reflect.getMetadata(metadataKey, target, propertyKey);
1254
1267
  } else {
1255
1268
  return Reflect.getMetadata(metadataKey, target);
1256
1269
  }
1257
- },
1258
- findMetadata: (metadataKey, target, propertyKey) => {
1270
+ };
1271
+ ReflectUtils2.findMetadata = (metadataKey, target, propertyKey) => {
1259
1272
  if (target == null) return void 0;
1260
1273
  let searchTarget = typeof target === "object" && typeof target !== "function" ? target.constructor : target;
1261
1274
  while (searchTarget && searchTarget !== Object) {
@@ -1266,11 +1279,8 @@ var dooboostoreSimpleWebComponent = (() => {
1266
1279
  if (searchTarget === target) break;
1267
1280
  }
1268
1281
  return void 0;
1269
- },
1270
- /**
1271
- * 프로토타입 체인의 모든 메타데이터를 수집하여 리스트로 반환합니다. (부모 -> 자식 순)
1272
- */
1273
- findAllMetadata: (metadataKey, target, propertyKey) => {
1282
+ };
1283
+ ReflectUtils2.findAllMetadata = (metadataKey, target, propertyKey) => {
1274
1284
  const results = [];
1275
1285
  if (target == null) return results;
1276
1286
  let searchTarget = typeof target === "object" && typeof target !== "function" ? target.constructor : target;
@@ -1282,24 +1292,18 @@ var dooboostoreSimpleWebComponent = (() => {
1282
1292
  if (searchTarget === target) break;
1283
1293
  }
1284
1294
  return results;
1285
- },
1286
- /**
1287
- * 모든 메타데이터(배열 형태)를 수집하여 하나의 배열로 합칩니다. (부모 -> 자식 순)
1288
- */
1289
- findAllMetadataFlatten: (metadataKey, target, propertyKey) => {
1295
+ };
1296
+ ReflectUtils2.findAllMetadataFlatten = (metadataKey, target, propertyKey) => {
1290
1297
  const results = [];
1291
- const metaList = ReflectUtils.findAllMetadata(metadataKey, target, propertyKey);
1298
+ const metaList = (0, ReflectUtils2.findAllMetadata)(metadataKey, target, propertyKey);
1292
1299
  metaList.forEach((data) => {
1293
1300
  if (Array.isArray(data)) results.push(...data);
1294
1301
  });
1295
1302
  return [...new Set(results)];
1296
- },
1297
- /**
1298
- * 프로토타입 체인의 모든 메타데이터(맵 형태)를 수집하여 합칩니다. (부모 -> 자식 순)
1299
- */
1300
- findAllMapMetadata: (metadataKey, target) => {
1303
+ };
1304
+ ReflectUtils2.findAllMapMetadata = (metadataKey, target) => {
1301
1305
  const finalMap = /* @__PURE__ */ new Map();
1302
- const metaList = ReflectUtils.findAllMetadata(metadataKey, target);
1306
+ const metaList = (0, ReflectUtils2.findAllMetadata)(metadataKey, target);
1303
1307
  metaList.forEach((data) => {
1304
1308
  if (data instanceof Map) {
1305
1309
  data.forEach((values, key) => {
@@ -1310,31 +1314,69 @@ var dooboostoreSimpleWebComponent = (() => {
1310
1314
  }
1311
1315
  });
1312
1316
  return finalMap;
1313
- },
1314
- getMetadataKeys: (target) => {
1317
+ };
1318
+ ReflectUtils2.getMetadataKeys = (target) => {
1315
1319
  return Reflect.getMetadataKeys(target);
1316
- },
1317
- getOwnMetadata: (metadataKey, target, propertyKey) => {
1320
+ };
1321
+ ReflectUtils2.getOwnMetadata = (metadataKey, target, propertyKey) => {
1318
1322
  if (propertyKey) {
1319
1323
  return Reflect.getOwnMetadata(metadataKey, target, propertyKey);
1320
1324
  } else {
1321
1325
  return Reflect.getOwnMetadata(metadataKey, target);
1322
1326
  }
1323
- },
1324
- getMetadatas: (target) => {
1325
- return ReflectUtils.getMetadataKeys(target).map((it) => ReflectUtils.getMetadata(it, target));
1326
- },
1327
- metadata: (metadataKey, data) => {
1327
+ };
1328
+ ReflectUtils2.getMetadatas = (target) => {
1329
+ return (0, ReflectUtils2.getMetadataKeys)(target).map((it) => (0, ReflectUtils2.getMetadata)(it, target));
1330
+ };
1331
+ ReflectUtils2.metadata = (metadataKey, data) => {
1328
1332
  return Reflect.metadata(metadataKey, data);
1329
- },
1330
- defineMetadata: (metadataKey, value, target, propertyKey) => {
1333
+ };
1334
+ ReflectUtils2.defineMetadata = (metadataKey, value, target, propertyKey) => {
1331
1335
  if (propertyKey && Reflect.defineMetadata) {
1332
1336
  Reflect.defineMetadata(metadataKey, value, target, propertyKey);
1333
1337
  } else if (Reflect.defineMetadata) {
1334
1338
  Reflect.defineMetadata(metadataKey, value, target);
1335
1339
  }
1336
- }
1337
- };
1340
+ };
1341
+ })(ReflectUtils || (ReflectUtils = {}));
1342
+
1343
+ // ../core/dist/esm/function/FunctionUtils.js
1344
+ var FunctionUtils;
1345
+ ((FunctionUtils2) => {
1346
+ FunctionUtils2.getParameterNames = (func, property) => {
1347
+ if (typeof func === "object" && property) {
1348
+ func = func[property];
1349
+ }
1350
+ return new RegExp("(?:" + func.name + "\\s*|^)\\s*\\((.*?)\\)").exec(func.toString().replace(/\n/g, ""))?.[1].replace(/\/\*.*?\*\//g, "").replace(/ /g, "").split(",") ?? [];
1351
+ };
1352
+ FunctionUtils2.evalScript = (script, obj) => {
1353
+ try {
1354
+ if (script && obj) {
1355
+ return Function(`"use strict";
1356
+ ${script}
1357
+ `).bind(obj)();
1358
+ } else if (script) {
1359
+ return new Function("return " + script)();
1360
+ } else {
1361
+ return null;
1362
+ }
1363
+ } catch (e) {
1364
+ return null;
1365
+ }
1366
+ };
1367
+ FunctionUtils2.execute = (params) => {
1368
+ const { script, context, args = {} } = params;
1369
+ const argNames = Object.keys(args);
1370
+ const argValues = Object.values(args);
1371
+ return new Function(...argNames, script).apply(context, argValues);
1372
+ };
1373
+ FunctionUtils2.executeReturn = (params) => {
1374
+ const { script, context, args = {} } = params;
1375
+ const argNames = Object.keys(args);
1376
+ const argValues = Object.values(args);
1377
+ return new Function(...argNames, `return ${script}`).apply(context, argValues);
1378
+ };
1379
+ })(FunctionUtils || (FunctionUtils = {}));
1338
1380
 
1339
1381
  // src/decorators/innerHtml.ts
1340
1382
  var INNER_HTML_METADATA_KEY = Symbol("simple-web-component:inner-html");
@@ -1494,8 +1536,27 @@ var dooboostoreSimpleWebComponent = (() => {
1494
1536
 
1495
1537
  // src/utils/Utils.ts
1496
1538
  var SWC_NOT_FOUND = Symbol("SWC_NOT_FOUND");
1497
- var SwcUtils = class {
1498
- static getValueByPath(obj, path, rootName) {
1539
+ var SwcUtils;
1540
+ ((SwcUtils2) => {
1541
+ SwcUtils2.getHelperSet = (win) => {
1542
+ const doc = win.document;
1543
+ return {
1544
+ $d: doc,
1545
+ $w: win,
1546
+ $q: (sel, root) => (root ?? doc).querySelector(sel),
1547
+ $qa: (sel, root) => Array.from((root ?? doc).querySelectorAll(sel)),
1548
+ $qi: (id, root) => (root ?? doc).getElementById(id)
1549
+ };
1550
+ };
1551
+ SwcUtils2.getHelperAndHostSet = (win, el) => {
1552
+ const helperSet = (0, SwcUtils2.getHelperSet)(win);
1553
+ const hostSet = (0, SwcUtils2.getHostSet)(el);
1554
+ return {
1555
+ ...helperSet,
1556
+ ...hostSet
1557
+ };
1558
+ };
1559
+ SwcUtils2.getValueByPath = (obj, path, rootName) => {
1499
1560
  if (!obj || !path) return SWC_NOT_FOUND;
1500
1561
  const parts = path.split(".");
1501
1562
  let current = obj;
@@ -1504,49 +1565,66 @@ var dooboostoreSimpleWebComponent = (() => {
1504
1565
  current = current[part];
1505
1566
  }
1506
1567
  return current;
1507
- }
1508
- static findNearestSwcHost(el) {
1509
- let current = el instanceof Node && !(el instanceof HTMLElement) ? el.host : el;
1510
- current = current?.parentElement || current?.getRootNode()?.host;
1511
- while (current) {
1568
+ };
1569
+ SwcUtils2.findNearestSwcHost = (el) => {
1570
+ if (el.__swc_host) return el.__swc_host;
1571
+ let current = el.parentElement || el.getRootNode?.()?.host;
1572
+ while (current && current !== document && current !== window) {
1573
+ if (current.__swc_host) return current.__swc_host;
1512
1574
  if (getElementConfig(current)) return current;
1513
- current = current.parentElement || current?.getRootNode()?.host;
1575
+ current = current.parentElement || current.getRootNode?.()?.host;
1514
1576
  }
1515
1577
  return void 0;
1516
- }
1517
- /**
1518
- * Returns all SWC ancestors (excluding self) in [root, ..., parent] order.
1519
- */
1520
- static findAllSwcHosts(el) {
1578
+ };
1579
+ SwcUtils2.findAllSwcHosts = (el) => {
1521
1580
  const hosts = [];
1522
- let current = this.findNearestSwcHost(el);
1581
+ let current = (0, SwcUtils2.findNearestSwcHost)(el);
1523
1582
  while (current) {
1524
1583
  hosts.push(current);
1525
- current = this.findNearestSwcHost(current);
1584
+ current = (0, SwcUtils2.findNearestSwcHost)(current);
1526
1585
  }
1527
1586
  return hosts.reverse();
1528
- }
1529
- static getHosts(el) {
1530
- return [...this.findAllSwcHosts(el), el];
1531
- }
1532
- static getHost(el) {
1533
- return el;
1534
- }
1535
- static getAppHosts(el) {
1536
- const hosts = this.getHosts(el);
1587
+ };
1588
+ SwcUtils2.getHosts = (el) => {
1589
+ const ancestors = (0, SwcUtils2.findAllSwcHosts)(el);
1590
+ if (getElementConfig(el)) return [...ancestors, el];
1591
+ return ancestors;
1592
+ };
1593
+ SwcUtils2.getHost = (el) => {
1594
+ if (getElementConfig(el)) return el;
1595
+ return (0, SwcUtils2.findNearestSwcHost)(el);
1596
+ };
1597
+ SwcUtils2.getAppHosts = (el) => {
1598
+ const hosts = (0, SwcUtils2.getHosts)(el);
1537
1599
  return hosts.filter((host) => host.tagName.toLowerCase() === "swc-app" || host.getAttribute("is")?.startsWith("swc-app-"));
1538
- }
1539
- static getAppHost(el) {
1540
- const appHosts = this.getAppHosts(el);
1600
+ };
1601
+ SwcUtils2.getAppHost = (el) => {
1602
+ const appHosts = (0, SwcUtils2.getAppHosts)(el);
1541
1603
  const appHostsWithoutSelf = appHosts.filter((h) => h !== el);
1542
1604
  return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : void 0;
1543
- }
1544
- static getHostSet(el) {
1545
- const ancestors = this.findAllSwcHosts(el);
1546
- const $host = el;
1547
- const $hosts = [...ancestors, $host];
1548
- const $parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;
1549
- const $firstHost = ancestors.length > 0 ? ancestors[0] : null;
1605
+ };
1606
+ SwcUtils2.getHostSet = (el) => {
1607
+ const isSwc = !!getElementConfig(el);
1608
+ const ancestors = (0, SwcUtils2.findAllSwcHosts)(el);
1609
+ let $host;
1610
+ let $parentHost;
1611
+ if (isSwc) {
1612
+ $host = el;
1613
+ $parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;
1614
+ } else {
1615
+ $host = ancestors.length > 0 ? ancestors[ancestors.length - 1] : el;
1616
+ $parentHost = ancestors.length > 1 ? ancestors[ancestors.length - 2] : null;
1617
+ }
1618
+ const $hosts = isSwc ? [...ancestors, el] : ancestors;
1619
+ const $firstHost = $hosts.length > 0 ? $hosts[0] : null;
1620
+ const loopContext = {};
1621
+ let curr = el;
1622
+ while (curr && curr !== document.documentElement) {
1623
+ if (curr.__swc_loop_context) {
1624
+ Object.assign(loopContext, curr.__swc_loop_context);
1625
+ }
1626
+ curr = curr.parentElement || curr.getRootNode().host;
1627
+ }
1550
1628
  const $appHosts = $hosts.filter((h) => h.tagName.toLowerCase() === "swc-app" || h.getAttribute("is")?.startsWith("swc-app-"));
1551
1629
  const $appHost = $appHosts.length > 0 ? $appHosts[$appHosts.length - 1] === el ? $appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null : $appHosts[$appHosts.length - 1] : null;
1552
1630
  const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;
@@ -1559,10 +1637,11 @@ var dooboostoreSimpleWebComponent = (() => {
1559
1637
  $appHost,
1560
1638
  $appHosts,
1561
1639
  $firstAppHost,
1562
- $lastAppHost: $appHost
1640
+ $lastAppHost: $appHost,
1641
+ ...loopContext
1563
1642
  };
1564
- }
1565
- };
1643
+ };
1644
+ })(SwcUtils || (SwcUtils = {}));
1566
1645
 
1567
1646
  // src/config/config.ts
1568
1647
  var HTML_TAG_ENTRIES = [
@@ -1685,6 +1764,7 @@ var dooboostoreSimpleWebComponent = (() => {
1685
1764
 
1686
1765
  // src/decorators/elementDefine.ts
1687
1766
  var ELEMENT_CONFIG_KEY = Symbol("simple-web-component:element-config");
1767
+ var globalDelegatedRoots = /* @__PURE__ */ new WeakSet();
1688
1768
  function buildEnv(configWindow) {
1689
1769
  const win = configWindow || (typeof window !== "undefined" ? window : void 0);
1690
1770
  const doc = win?.document;
@@ -1693,13 +1773,7 @@ var dooboostoreSimpleWebComponent = (() => {
1693
1773
  if (win?.[cls])
1694
1774
  builtInTagMap.set(win[cls], tag);
1695
1775
  }
1696
- const domHelpers = {
1697
- $d: doc,
1698
- $w: win,
1699
- $q: (sel, root) => (root ?? doc).querySelector(sel),
1700
- $qa: (sel, root) => Array.from((root ?? doc).querySelectorAll(sel)),
1701
- $qi: (id, root) => (root ?? doc).getElementById(id)
1702
- };
1776
+ const domHelpers = SwcUtils.getHelperSet(win);
1703
1777
  return { win, doc, builtInTagMap, domHelpers };
1704
1778
  }
1705
1779
  var getHandlers = (inst) => {
@@ -1711,8 +1785,6 @@ var dooboostoreSimpleWebComponent = (() => {
1711
1785
  const config = typeof inConfig === "string" ? { name: inConfig } : inConfig;
1712
1786
  const { win, doc, builtInTagMap: BUILT_IN_TAG_MAP, domHelpers: SWC_DOM_HELPERS } = buildEnv(config.window);
1713
1787
  config.window = win;
1714
- const SWC_DOM_HELPER_KEYS = Object.keys(SWC_DOM_HELPERS);
1715
- const SWC_DOM_HELPER_VALS = () => SWC_DOM_HELPER_KEYS.map((k) => SWC_DOM_HELPERS[k]);
1716
1788
  let extendsTagName = config.extends;
1717
1789
  if (!extendsTagName) {
1718
1790
  let proto = constructor;
@@ -1738,9 +1810,7 @@ var dooboostoreSimpleWebComponent = (() => {
1738
1810
  if (script) {
1739
1811
  try {
1740
1812
  const args = { ...hostSet, ...SWC_DOM_HELPERS, ...extraArgs };
1741
- const argNames = Object.keys(args);
1742
- const argValues = Object.values(args);
1743
- new Function(...argNames, script).apply(this, argValues);
1813
+ FunctionUtils.execute({ script, context: this, args });
1744
1814
  } catch (e) {
1745
1815
  console.error(`[SWC] Failed to execute ${attrName}:`, e);
1746
1816
  }
@@ -1782,9 +1852,13 @@ var dooboostoreSimpleWebComponent = (() => {
1782
1852
  el.removeEventListener(eventName, oldHandler);
1783
1853
  const handler = (event) => {
1784
1854
  const hostSet = SwcUtils.getHostSet(el);
1785
- const argNames = Object.keys(hostSet);
1786
- const argValues = Object.values(hostSet);
1787
- new Function("event", "$data", ...argNames, ...SWC_DOM_HELPER_KEYS, script).call(el, event, event.detail, ...argValues, ...SWC_DOM_HELPER_VALS());
1855
+ const args = {
1856
+ event,
1857
+ $data: event.detail,
1858
+ ...hostSet,
1859
+ ...SWC_DOM_HELPERS
1860
+ };
1861
+ FunctionUtils.execute({ script, context: el, args });
1788
1862
  };
1789
1863
  el.addEventListener(eventName, handler);
1790
1864
  handlers.set(attrName, handler);
@@ -1793,6 +1867,7 @@ var dooboostoreSimpleWebComponent = (() => {
1793
1867
  super(...args);
1794
1868
  this._swcId = Math.random().toString(36).substring(2, 11);
1795
1869
  this._emitHandlers = /* @__PURE__ */ new Map();
1870
+ this._boundListeners = [];
1796
1871
  const hostSet = SwcUtils.getHostSet(this);
1797
1872
  this._executeSwcScript("swc-on-constructor", hostSet);
1798
1873
  if (innerHtmlList.some((it) => it.options.useShadow === true) && !this.shadowRoot) {
@@ -1803,6 +1878,9 @@ var dooboostoreSimpleWebComponent = (() => {
1803
1878
  return mergedObservedAttributes;
1804
1879
  }
1805
1880
  async connectedCallback() {
1881
+ const conf = getElementConfig(this);
1882
+ const currentWin = conf?.window || window;
1883
+ const currentDoc = currentWin.document;
1806
1884
  const hostSet = SwcUtils.getHostSet(this);
1807
1885
  this._executeSwcScript("swc-on-before-connected", hostSet);
1808
1886
  const bMethods = findAllLifecycleMetadata(this, ON_BEFORE_CONNECTED_METADATA_KEY);
@@ -1828,17 +1906,87 @@ var dooboostoreSimpleWebComponent = (() => {
1828
1906
  if (lContent)
1829
1907
  this.innerHTML = lContent;
1830
1908
  }
1909
+ const createDelegationHandler = (delegateHost) => (event) => {
1910
+ if (event.__swc_handled)
1911
+ return;
1912
+ const path = event.composedPath();
1913
+ const type = event.type;
1914
+ const attrName = `swc-on-${type}`;
1915
+ for (const node of path) {
1916
+ if (node === delegateHost)
1917
+ break;
1918
+ if (!(node instanceof HTMLElement))
1919
+ continue;
1920
+ const script = node.getAttribute?.(attrName);
1921
+ if (script && !getElementConfig(node)) {
1922
+ const host = SwcUtils.findNearestSwcHost(node);
1923
+ if (host) {
1924
+ const childHostSet = SwcUtils.getHostSet(node);
1925
+ const args = {
1926
+ event,
1927
+ $data: event.detail,
1928
+ ...childHostSet,
1929
+ ...SWC_DOM_HELPERS
1930
+ };
1931
+ FunctionUtils.execute({ script, context: node, args });
1932
+ event.__swc_handled = true;
1933
+ break;
1934
+ }
1935
+ }
1936
+ }
1937
+ };
1938
+ DOM_EVENT_NAMES.forEach((type) => {
1939
+ this.addEventListener(type, createDelegationHandler(this));
1940
+ this._boundListeners.push({ target: this, type, handler: createDelegationHandler(this) });
1941
+ });
1942
+ const hasParentHost = SwcUtils.findAllSwcHosts(this).length > 0;
1943
+ if (!hasParentHost) {
1944
+ const root = this.getRootNode();
1945
+ if (!globalDelegatedRoots.has(root)) {
1946
+ DOM_EVENT_NAMES.forEach((type) => {
1947
+ const handler = createDelegationHandler(root);
1948
+ root.addEventListener(type, handler);
1949
+ });
1950
+ globalDelegatedRoots.add(root);
1951
+ }
1952
+ }
1831
1953
  addEventListenerList.forEach((meta) => {
1832
1954
  const { selector, type, options } = meta;
1833
- const { root, capture, once, passive, stopPropagation, stopImmediatePropagation, preventDefault, delegate } = options;
1834
- if (delegate && selector && selector !== ":host") {
1955
+ const { root, capture, once, passive, stopPropagation, stopImmediatePropagation, preventDefault, delegate, removeOnDisconnected } = options;
1956
+ const opts = { capture, once, passive };
1957
+ const bindTargets = [];
1958
+ if (selector === ":window") {
1959
+ bindTargets.push(currentWin);
1960
+ } else if (selector === ":document") {
1961
+ bindTargets.push(currentDoc);
1962
+ } else if (selector === ":parentHost") {
1963
+ if (hostSet.$parentHost)
1964
+ bindTargets.push(hostSet.$parentHost);
1965
+ } else if (selector === ":appHost") {
1966
+ if (hostSet.$appHost)
1967
+ bindTargets.push(hostSet.$appHost);
1968
+ } else if (selector === ":firstHost") {
1969
+ if (hostSet.$firstHost)
1970
+ bindTargets.push(hostSet.$firstHost);
1971
+ } else if (selector === ":lastHost") {
1972
+ if (hostSet.$lastHost)
1973
+ bindTargets.push(hostSet.$lastHost);
1974
+ } else if (selector === ":firstAppHost") {
1975
+ if (hostSet.$firstAppHost)
1976
+ bindTargets.push(hostSet.$firstAppHost);
1977
+ } else if (selector === ":lastAppHost") {
1978
+ if (hostSet.$lastAppHost)
1979
+ bindTargets.push(hostSet.$lastAppHost);
1980
+ } else if (!selector || selector === ":host") {
1981
+ bindTargets.push(this);
1982
+ } else if (delegate) {
1835
1983
  const bindRoots = [];
1836
1984
  const r = root || "auto";
1837
- if (r === "auto") {
1985
+ if (r === "auto")
1838
1986
  bindRoots.push(this.shadowRoot || this);
1839
- } else if (r === "light") {
1987
+ else if (r === "light")
1840
1988
  bindRoots.push(this);
1841
- } else if (r === "shadow") {
1989
+ else if (r === "shadow") {
1842
1990
  if (this.shadowRoot)
1843
1991
  bindRoots.push(this.shadowRoot);
1844
1992
  } else if (r === "all") {
@@ -1846,62 +1994,61 @@ var dooboostoreSimpleWebComponent = (() => {
1846
1994
  if (this.shadowRoot)
1847
1995
  bindRoots.push(this.shadowRoot);
1848
1996
  }
1849
- bindRoots.forEach((bindRoot) => {
1997
+ bindRoots.forEach((br) => {
1850
1998
  const handler = (event) => {
1851
- const target = event.target;
1852
- const matchedEl = target.closest(selector);
1853
- if (matchedEl && bindRoot.contains(matchedEl)) {
1999
+ const matchedEl = event.target.closest(selector);
2000
+ if (matchedEl && br.contains(matchedEl)) {
1854
2001
  if (stopPropagation)
1855
2002
  event.stopPropagation();
1856
2003
  if (stopImmediatePropagation)
1857
2004
  event.stopImmediatePropagation();
1858
2005
  if (preventDefault)
1859
2006
  event.preventDefault();
1860
- const hostSet2 = SwcUtils.getHostSet(this);
1861
- this._invokeLifecycleMethod(meta.propertyKey, hostSet2, [event, hostSet2, matchedEl]);
2007
+ const currentHostSet = SwcUtils.getHostSet(this);
2008
+ this._invokeLifecycleMethod(meta.propertyKey, currentHostSet, [event, currentHostSet, matchedEl]);
1862
2009
  }
1863
2010
  };
1864
- bindRoot.addEventListener(type, handler, { capture, once, passive });
2011
+ br.addEventListener(type, handler, opts);
2012
+ const self2 = this;
2013
+ if (removeOnDisconnected === true || br !== self2 && br !== self2.shadowRoot) {
2014
+ this._boundListeners.push({ target: br, type, handler, options: opts });
2015
+ }
1865
2016
  });
1866
2017
  } else {
1867
- const targetEls = [];
1868
- if (!selector || selector === ":host") {
1869
- targetEls.push(this);
1870
- } else {
1871
- const searchRoots = [];
1872
- const r = root || "auto";
1873
- if (r === "auto") {
1874
- searchRoots.push(this.shadowRoot || this);
1875
- } else if (r === "light") {
1876
- searchRoots.push(this);
1877
- } else if (r === "shadow") {
1878
- if (this.shadowRoot)
1879
- searchRoots.push(this.shadowRoot);
1880
- } else if (r === "all") {
1881
- searchRoots.push(this);
1882
- if (this.shadowRoot)
1883
- searchRoots.push(this.shadowRoot);
1884
- }
1885
- searchRoots.forEach((sr) => {
1886
- const found = sr.querySelectorAll(selector);
1887
- found.forEach((el) => targetEls.push(el));
1888
- });
2018
+ const searchRoots = [];
2019
+ const r = root || "auto";
2020
+ if (r === "auto")
2021
+ searchRoots.push(this.shadowRoot || this);
2022
+ else if (r === "light")
2023
+ searchRoots.push(this);
2024
+ else if (r === "shadow") {
2025
+ if (this.shadowRoot)
2026
+ searchRoots.push(this.shadowRoot);
2027
+ } else if (r === "all") {
2028
+ searchRoots.push(this);
2029
+ if (this.shadowRoot)
2030
+ searchRoots.push(this.shadowRoot);
1889
2031
  }
1890
- targetEls.forEach((el) => {
1891
- const handler = (event) => {
1892
- if (stopPropagation)
1893
- event.stopPropagation();
1894
- if (stopImmediatePropagation)
1895
- event.stopImmediatePropagation();
1896
- if (preventDefault)
1897
- event.preventDefault();
1898
- const hostSet2 = SwcUtils.getHostSet(this);
1899
- this._invokeLifecycleMethod(meta.propertyKey, hostSet2, [event, hostSet2]);
1900
- };
1901
- const opts = { capture, once, passive };
1902
- el.addEventListener(type, handler, opts);
2032
+ searchRoots.forEach((sr) => {
2033
+ sr.querySelectorAll(selector).forEach((el) => bindTargets.push(el));
1903
2034
  });
1904
2035
  }
2036
+ bindTargets.forEach((target) => {
2037
+ const handler = (event) => {
2038
+ if (stopPropagation)
2039
+ event.stopPropagation();
2040
+ if (stopImmediatePropagation)
2041
+ event.stopImmediatePropagation();
2042
+ if (preventDefault)
2043
+ event.preventDefault();
2044
+ const currentHostSet = SwcUtils.getHostSet(this);
2045
+ this._invokeLifecycleMethod(meta.propertyKey, currentHostSet, [event, currentHostSet]);
2046
+ };
2047
+ target.addEventListener(type, handler, opts);
2048
+ if (removeOnDisconnected === true || target === currentWin || target === currentDoc) {
2049
+ this._boundListeners.push({ target, type, handler, options: opts });
2050
+ }
2051
+ });
1905
2052
  });
1906
2053
  if (super.connectedCallback)
1907
2054
  await super.connectedCallback();
@@ -1919,6 +2066,8 @@ var dooboostoreSimpleWebComponent = (() => {
1919
2066
  const bMethods = findAllLifecycleMetadata(this, ON_BEFORE_DISCONNECTED_METADATA_KEY);
1920
2067
  if (bMethods)
1921
2068
  bMethods.forEach((m) => this._invokeLifecycleMethod(m, hostSet));
2069
+ this._boundListeners.forEach((l) => l.target.removeEventListener(l.type, l.handler, l.options));
2070
+ this._boundListeners = [];
1922
2071
  if (super.disconnectedCallback)
1923
2072
  super.disconnectedCallback();
1924
2073
  const aMethods = findAllLifecycleMetadata(this, ON_AFTER_DISCONNECTED_METADATA_KEY);
@@ -2027,6 +2176,26 @@ var dooboostoreSimpleWebComponent = (() => {
2027
2176
  queries.push({ selector, options, propertyKey });
2028
2177
  Object.defineProperty(target, propertyKey, {
2029
2178
  get() {
2179
+ const hostSet = SwcUtils.getHostSet(this);
2180
+ if (selector === ":parentHost")
2181
+ return hostSet.$parentHost;
2182
+ if (selector === ":appHost")
2183
+ return hostSet.$appHost;
2184
+ if (selector === ":firstHost")
2185
+ return hostSet.$firstHost;
2186
+ if (selector === ":lastHost")
2187
+ return hostSet.$lastHost;
2188
+ if (selector === ":firstAppHost")
2189
+ return hostSet.$firstAppHost;
2190
+ if (selector === ":lastAppHost")
2191
+ return hostSet.$lastAppHost;
2192
+ const config = getElementConfig(this);
2193
+ const win = config?.window || window;
2194
+ const doc = win.document;
2195
+ if (selector === ":window")
2196
+ return win;
2197
+ if (selector === ":document")
2198
+ return doc;
2030
2199
  if (!selector || selector === ":host")
2031
2200
  return this;
2032
2201
  const r = options.root || "auto";
@@ -2067,6 +2236,18 @@ var dooboostoreSimpleWebComponent = (() => {
2067
2236
  queries.push({ selector, options, propertyKey });
2068
2237
  Object.defineProperty(target, propertyKey, {
2069
2238
  get() {
2239
+ const hostSet = SwcUtils.getHostSet(this);
2240
+ if (selector === ":hosts")
2241
+ return hostSet.$hosts;
2242
+ if (selector === ":appHosts")
2243
+ return hostSet.$appHosts;
2244
+ const config = getElementConfig(this);
2245
+ const win = config?.window || window;
2246
+ const doc = win.document;
2247
+ if (selector === ":window")
2248
+ return [win];
2249
+ if (selector === ":document")
2250
+ return [doc];
2070
2251
  if (!selector || selector === ":host")
2071
2252
  return [this];
2072
2253
  const r = options.root || "auto";
@@ -7711,7 +7892,7 @@ var dooboostoreSimpleWebComponent = (() => {
7711
7892
  const configStr = this.host.getAttribute("swc-get-application-config");
7712
7893
  if (!configStr) return;
7713
7894
  try {
7714
- const userConfig = new Function(`return ${configStr}`).apply(this.host);
7895
+ const userConfig = FunctionUtils.executeReturn({ script: configStr, context: this.host });
7715
7896
  if (userConfig && userConfig.rootRouter) {
7716
7897
  const _config = {
7717
7898
  routeType: "element",
@@ -9575,6 +9756,732 @@ var dooboostoreSimpleWebComponent = (() => {
9575
9756
  SwcAppBody = __decorate57([
9576
9757
  elementDefine({ name: "swc-app-body", extends: "body" })
9577
9758
  ], SwcAppBody);
9759
+
9760
+ // src/elements/SwcSubTemplates.ts
9761
+ var __decorate58 = function(decorators, target, key, desc) {
9762
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9763
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
9764
+ 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;
9765
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
9766
+ };
9767
+ var SwcLoading = class SwcLoading2 extends HTMLTemplateElement {
9768
+ };
9769
+ SwcLoading = __decorate58([
9770
+ elementDefine({ name: "swc-loading", extends: "template" })
9771
+ ], SwcLoading);
9772
+ var SwcError = class SwcError2 extends HTMLTemplateElement {
9773
+ };
9774
+ SwcError = __decorate58([
9775
+ elementDefine({ name: "swc-error", extends: "template" })
9776
+ ], SwcError);
9777
+ var SwcSuccess = class SwcSuccess2 extends HTMLTemplateElement {
9778
+ };
9779
+ SwcSuccess = __decorate58([
9780
+ elementDefine({ name: "swc-success", extends: "template" })
9781
+ ], SwcSuccess);
9782
+ var SwcWhen = class SwcWhen2 extends HTMLTemplateElement {
9783
+ };
9784
+ SwcWhen = __decorate58([
9785
+ elementDefine({ name: "swc-when", extends: "template" })
9786
+ ], SwcWhen);
9787
+ var SwcOtherwise = class SwcOtherwise2 extends HTMLTemplateElement {
9788
+ };
9789
+ SwcOtherwise = __decorate58([
9790
+ elementDefine({ name: "swc-otherwise", extends: "template" })
9791
+ ], SwcOtherwise);
9792
+ var SwcDefault = class SwcDefault2 extends HTMLTemplateElement {
9793
+ };
9794
+ SwcDefault = __decorate58([
9795
+ elementDefine({ name: "swc-default", extends: "template" })
9796
+ ], SwcDefault);
9797
+
9798
+ // src/elements/SwcLoop.ts
9799
+ var __decorate59 = function(decorators, target, key, desc) {
9800
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9801
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
9802
+ 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;
9803
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
9804
+ };
9805
+ var __metadata = function(k, v) {
9806
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9807
+ };
9808
+ var SwcLoop = class SwcLoop2 extends HTMLTemplateElement {
9809
+ constructor() {
9810
+ super(...arguments);
9811
+ this._value = [];
9812
+ this._nodes = [];
9813
+ this._defaultNodes = [];
9814
+ }
9815
+ get value() {
9816
+ return this._value;
9817
+ }
9818
+ set value(nv) {
9819
+ this._value = Array.isArray(nv) ? [...nv] : [];
9820
+ this.render();
9821
+ }
9822
+ getNodes(index) {
9823
+ return this._nodes[index] || null;
9824
+ }
9825
+ _getTarget() {
9826
+ const script = this.getAttribute("on-get-portal");
9827
+ if (!script)
9828
+ return null;
9829
+ try {
9830
+ const res = FunctionUtils.executeReturn({
9831
+ script,
9832
+ context: this,
9833
+ args: SwcUtils.getHelperAndHostSet(window, this)
9834
+ });
9835
+ if (typeof res === "string")
9836
+ return document.querySelector(res);
9837
+ if (res instanceof Node)
9838
+ return res;
9839
+ } catch (e) {
9840
+ console.error("[SwcLoop] Portal target error:", e);
9841
+ }
9842
+ return null;
9843
+ }
9844
+ append(...items) {
9845
+ if (!items.length || !this.parentElement)
9846
+ return;
9847
+ if (this._defaultNodes.length > 0)
9848
+ this._cleanupDefault();
9849
+ const fragment = document.createDocumentFragment();
9850
+ const startIndex = this._value.length;
9851
+ items.forEach((item, i) => {
9852
+ const index = startIndex + i;
9853
+ const nodes = this._createItemNodes(item, index);
9854
+ if (nodes) {
9855
+ this._nodes.push(nodes);
9856
+ nodes.forEach((n) => fragment.appendChild(n));
9857
+ this._value.push(item);
9858
+ } else {
9859
+ this._nodes.push(null);
9860
+ this._value.push(null);
9861
+ }
9862
+ });
9863
+ const target = this._getTarget();
9864
+ if (target) {
9865
+ target.appendChild(fragment);
9866
+ } else {
9867
+ const lastValidIdx = this._nodes.length - items.length - 1;
9868
+ let refNode = this;
9869
+ for (let i = lastValidIdx; i >= 0; i--) {
9870
+ const group = this._nodes[i];
9871
+ if (group && group.length > 0) {
9872
+ refNode = group[group.length - 1];
9873
+ break;
9874
+ }
9875
+ }
9876
+ this.parentElement.insertBefore(fragment, refNode.nextSibling);
9877
+ }
9878
+ }
9879
+ remove(index) {
9880
+ const targetIdx = index !== void 0 ? index : this._nodes.length - 1;
9881
+ if (targetIdx < 0 || targetIdx >= this._nodes.length)
9882
+ return;
9883
+ const nodes = this._nodes[targetIdx];
9884
+ if (nodes) {
9885
+ nodes.forEach((n) => {
9886
+ if (n.parentElement)
9887
+ n.parentElement.removeChild(n);
9888
+ });
9889
+ this._nodes[targetIdx] = null;
9890
+ this._value[targetIdx] = null;
9891
+ }
9892
+ const activeRows = this._value.filter((v) => v !== null);
9893
+ if (activeRows.length === 0) {
9894
+ this.render();
9895
+ }
9896
+ }
9897
+ _createItemNodes(item, index) {
9898
+ const clone = this.content.cloneNode(true);
9899
+ Array.from(clone.querySelectorAll('template[is="swc-default"]')).forEach((t) => t.remove());
9900
+ const nodes = Array.from(clone.childNodes);
9901
+ const elements = nodes.filter((n) => n.nodeType === 1);
9902
+ const groupCtx = {
9903
+ $index: index,
9904
+ $item: item,
9905
+ $nodes: nodes,
9906
+ $elements: elements,
9907
+ $firstNode: nodes[0],
9908
+ $lastNode: nodes[nodes.length - 1],
9909
+ $firstElement: elements[0],
9910
+ $lastElement: elements[elements.length - 1],
9911
+ $isFirst: index === 0,
9912
+ $isLast: index === this._value.length - 1,
9913
+ $isEven: index % 2 === 0,
9914
+ $isOdd: index % 2 !== 0,
9915
+ $count: this._value.length
9916
+ };
9917
+ this._executeCallback("on-clone-nodes", groupCtx);
9918
+ nodes.forEach((node, nodeIndex) => {
9919
+ if (node instanceof HTMLElement)
9920
+ node.__swc_host = this;
9921
+ this._executeCallback("on-clone-node", { ...groupCtx, $node: node, $nodeIndex: nodeIndex, $isElement: node.nodeType === 1 });
9922
+ });
9923
+ return nodes;
9924
+ }
9925
+ _executeCallback(attrName, extraArgs) {
9926
+ const script = this.getAttribute(attrName);
9927
+ if (!script)
9928
+ return;
9929
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
9930
+ try {
9931
+ FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
9932
+ } catch (e) {
9933
+ console.error(`[SwcLoop] Error in ${attrName}:`, e);
9934
+ }
9935
+ }
9936
+ refreshValue(newValue) {
9937
+ const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
9938
+ if (!script) {
9939
+ this.value = [];
9940
+ return;
9941
+ }
9942
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
9943
+ try {
9944
+ const res = FunctionUtils.executeReturn({ script, context: this, args: helperHostSet });
9945
+ if (Array.isArray(res)) {
9946
+ this.value = res;
9947
+ }
9948
+ } catch (e) {
9949
+ console.error("[SwcLoop] Failed to get value from on-get-value script:", e);
9950
+ this.value = [];
9951
+ }
9952
+ }
9953
+ render() {
9954
+ this._cleanup();
9955
+ if (!this.parentElement)
9956
+ return;
9957
+ const activeRows = this._value.filter((v) => v !== null);
9958
+ const target = this._getTarget();
9959
+ if (activeRows.length === 0) {
9960
+ const t = this.content.querySelector('template[is="swc-default"]');
9961
+ if (t) {
9962
+ const clone = t.content.cloneNode(true);
9963
+ this._defaultNodes = Array.from(clone.childNodes);
9964
+ this._defaultNodes.forEach((n) => {
9965
+ if (n instanceof HTMLElement)
9966
+ n.__swc_host = this;
9967
+ });
9968
+ if (target)
9969
+ target.appendChild(clone);
9970
+ else
9971
+ this.parentElement.insertBefore(clone, this.nextSibling);
9972
+ }
9973
+ return;
9974
+ }
9975
+ const fragment = document.createDocumentFragment();
9976
+ this._value.forEach((item, index) => {
9977
+ if (item === null) {
9978
+ this._nodes.push(null);
9979
+ return;
9980
+ }
9981
+ const nodes = this._createItemNodes(item, index);
9982
+ this._nodes.push(nodes);
9983
+ nodes.forEach((n) => fragment.appendChild(n));
9984
+ });
9985
+ if (target)
9986
+ target.appendChild(fragment);
9987
+ else
9988
+ this.parentElement.insertBefore(fragment, this.nextSibling);
9989
+ }
9990
+ _cleanup() {
9991
+ this._nodes.forEach((group) => {
9992
+ if (group)
9993
+ group.forEach((node) => node.parentElement?.removeChild(node));
9994
+ });
9995
+ this._nodes = [];
9996
+ this._cleanupDefault();
9997
+ }
9998
+ _cleanupDefault() {
9999
+ this._defaultNodes.forEach((n) => n.parentElement?.removeChild(n));
10000
+ this._defaultNodes = [];
10001
+ }
10002
+ connectedCallback() {
10003
+ this.refreshValue();
10004
+ }
10005
+ disconnectedCallback() {
10006
+ this._cleanup();
10007
+ }
10008
+ };
10009
+ __decorate59([
10010
+ changedAttribute("on-get-value"),
10011
+ __metadata("design:type", Function),
10012
+ __metadata("design:paramtypes", [String]),
10013
+ __metadata("design:returntype", void 0)
10014
+ ], SwcLoop.prototype, "refreshValue", null);
10015
+ SwcLoop = __decorate59([
10016
+ elementDefine({ name: "swc-loop", extends: "template" })
10017
+ ], SwcLoop);
10018
+
10019
+ // src/elements/SwcIf.ts
10020
+ var __decorate60 = function(decorators, target, key, desc) {
10021
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10022
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10023
+ 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;
10024
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
10025
+ };
10026
+ var __metadata2 = function(k, v) {
10027
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10028
+ };
10029
+ var SwcIf = class SwcIf2 extends HTMLTemplateElement {
10030
+ constructor() {
10031
+ super(...arguments);
10032
+ this._nodes = [];
10033
+ this._value = null;
10034
+ }
10035
+ get value() {
10036
+ return this._value;
10037
+ }
10038
+ set value(nv) {
10039
+ this._value = nv;
10040
+ this.render();
10041
+ }
10042
+ _getTarget() {
10043
+ const script = this.getAttribute("on-get-portal");
10044
+ if (!script)
10045
+ return null;
10046
+ try {
10047
+ const res = FunctionUtils.executeReturn({
10048
+ script,
10049
+ context: this,
10050
+ args: SwcUtils.getHelperAndHostSet(window, this)
10051
+ });
10052
+ if (typeof res === "string")
10053
+ return document.querySelector(res);
10054
+ if (res instanceof Node)
10055
+ return res;
10056
+ } catch (e) {
10057
+ console.error("[SwcIf] Portal target error:", e);
10058
+ }
10059
+ return null;
10060
+ }
10061
+ _executeCallback(attrName, extraArgs) {
10062
+ const script = this.getAttribute(attrName);
10063
+ if (!script)
10064
+ return;
10065
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
10066
+ try {
10067
+ FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
10068
+ } catch (e) {
10069
+ console.error(`[SwcIf] Error in ${attrName}:`, e);
10070
+ }
10071
+ }
10072
+ refresh(newValue) {
10073
+ const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
10074
+ if (!script) {
10075
+ this.value = null;
10076
+ return;
10077
+ }
10078
+ if (!this.parentElement)
10079
+ return;
10080
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
10081
+ try {
10082
+ const result = FunctionUtils.executeReturn({
10083
+ script,
10084
+ context: this,
10085
+ args: helperHostSet
10086
+ });
10087
+ this.value = result;
10088
+ } catch (e) {
10089
+ console.error("[SwcIf] Error in on-get-value:", e);
10090
+ this.value = null;
10091
+ }
10092
+ }
10093
+ render() {
10094
+ this.cleanup();
10095
+ if (!this.parentElement)
10096
+ return;
10097
+ let fragment = null;
10098
+ const ctx = { $value: this._value, $nodes: [], $elements: [] };
10099
+ if (this._value) {
10100
+ const clone = this.content.cloneNode(true);
10101
+ Array.from(clone.querySelectorAll('template[is="swc-default"]')).forEach((t) => t.remove());
10102
+ fragment = clone;
10103
+ } else {
10104
+ const t = this.content.querySelector('template[is="swc-default"]');
10105
+ if (t)
10106
+ fragment = t.content.cloneNode(true);
10107
+ }
10108
+ if (fragment) {
10109
+ this.mount(fragment, ctx);
10110
+ }
10111
+ }
10112
+ mount(fragment, ctx) {
10113
+ const nodes = Array.from(fragment.childNodes);
10114
+ const elements = nodes.filter((n) => n.nodeType === 1);
10115
+ Object.assign(ctx, {
10116
+ $nodes: nodes,
10117
+ $elements: elements,
10118
+ $firstNode: nodes[0],
10119
+ $lastNode: nodes[nodes.length - 1],
10120
+ $firstElement: elements[0],
10121
+ $lastElement: elements[elements.length - 1]
10122
+ });
10123
+ this._executeCallback("on-clone-nodes", ctx);
10124
+ nodes.forEach((node, nodeIndex) => {
10125
+ if (node instanceof HTMLElement)
10126
+ node.__swc_host = this;
10127
+ this._executeCallback("on-clone-node", { ...ctx, $node: node, $nodeIndex: nodeIndex, $isElement: node.nodeType === 1 });
10128
+ });
10129
+ this._nodes = nodes;
10130
+ const target = this._getTarget();
10131
+ if (target) {
10132
+ target.appendChild(fragment);
10133
+ } else {
10134
+ this.parentElement?.insertBefore(fragment, this.nextSibling);
10135
+ }
10136
+ }
10137
+ cleanup() {
10138
+ this._nodes.forEach((n) => {
10139
+ if (n.parentElement)
10140
+ n.parentElement.removeChild(n);
10141
+ });
10142
+ this._nodes = [];
10143
+ }
10144
+ connectedCallback() {
10145
+ this.refresh();
10146
+ }
10147
+ disconnectedCallback() {
10148
+ this.cleanup();
10149
+ }
10150
+ };
10151
+ __decorate60([
10152
+ changedAttribute("on-get-value"),
10153
+ __metadata2("design:type", Function),
10154
+ __metadata2("design:paramtypes", [String]),
10155
+ __metadata2("design:returntype", void 0)
10156
+ ], SwcIf.prototype, "refresh", null);
10157
+ SwcIf = __decorate60([
10158
+ elementDefine({ name: "swc-if", extends: "template" })
10159
+ ], SwcIf);
10160
+
10161
+ // src/elements/SwcChoose.ts
10162
+ var __decorate61 = function(decorators, target, key, desc) {
10163
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10164
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10165
+ 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;
10166
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
10167
+ };
10168
+ var __metadata3 = function(k, v) {
10169
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10170
+ };
10171
+ var SwcChoose = class SwcChoose2 extends HTMLTemplateElement {
10172
+ constructor() {
10173
+ super(...arguments);
10174
+ this._nodes = [];
10175
+ this._value = null;
10176
+ }
10177
+ get value() {
10178
+ return this._value;
10179
+ }
10180
+ set value(nv) {
10181
+ this._value = nv;
10182
+ this.render();
10183
+ }
10184
+ _executeCallback(attrName, extraArgs) {
10185
+ const script = this.getAttribute(attrName);
10186
+ if (!script)
10187
+ return;
10188
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
10189
+ try {
10190
+ FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
10191
+ } catch (e) {
10192
+ console.error(`[SwcChoose] Error in ${attrName}:`, e);
10193
+ }
10194
+ }
10195
+ refresh(newValue) {
10196
+ const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
10197
+ if (!script) {
10198
+ this.value = null;
10199
+ return;
10200
+ }
10201
+ if (!this.parentElement)
10202
+ return;
10203
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
10204
+ try {
10205
+ const result = FunctionUtils.executeReturn({
10206
+ script,
10207
+ context: this,
10208
+ args: helperHostSet
10209
+ });
10210
+ this.value = result;
10211
+ } catch (e) {
10212
+ console.error("[SwcChoose] Error in on-get-value:", e);
10213
+ }
10214
+ }
10215
+ render() {
10216
+ this.cleanup();
10217
+ if (!this.parentElement)
10218
+ return;
10219
+ const templates = Array.from(this.content.querySelectorAll("template"));
10220
+ let selected = null;
10221
+ let otherwise = null;
10222
+ let defaultTmp = null;
10223
+ for (const t of templates) {
10224
+ const is = t.getAttribute("is");
10225
+ if (is === "swc-when") {
10226
+ const whenVal = t.getAttribute("value");
10227
+ if (String(whenVal) === String(this._value)) {
10228
+ selected = t;
10229
+ break;
10230
+ }
10231
+ } else if (is === "swc-otherwise") {
10232
+ otherwise = t;
10233
+ } else if (is === "swc-default") {
10234
+ defaultTmp = t;
10235
+ }
10236
+ }
10237
+ const targetTemplate = (this._value == null ? defaultTmp : selected) || otherwise || defaultTmp;
10238
+ if (targetTemplate) {
10239
+ const clone = targetTemplate.content.cloneNode(true);
10240
+ const nodes = Array.from(clone.childNodes);
10241
+ const elements = nodes.filter((n) => n.nodeType === 1);
10242
+ const ctx = {
10243
+ $value: this._value,
10244
+ $nodes: nodes,
10245
+ $elements: elements,
10246
+ $firstNode: nodes[0],
10247
+ $lastNode: nodes[nodes.length - 1],
10248
+ $firstElement: elements[0],
10249
+ $lastElement: elements[elements.length - 1]
10250
+ };
10251
+ this._executeCallback("on-clone-nodes", ctx);
10252
+ nodes.forEach((node, nodeIndex) => {
10253
+ if (node instanceof HTMLElement) {
10254
+ node.__swc_host = this;
10255
+ }
10256
+ this._executeCallback("on-clone-node", {
10257
+ ...ctx,
10258
+ $node: node,
10259
+ $nodeIndex: nodeIndex,
10260
+ $isElement: node.nodeType === 1
10261
+ });
10262
+ });
10263
+ this._nodes = nodes;
10264
+ this.parentElement.insertBefore(clone, this.nextSibling);
10265
+ }
10266
+ }
10267
+ cleanup() {
10268
+ this._nodes.forEach((n) => {
10269
+ if (n.parentElement)
10270
+ n.parentElement.removeChild(n);
10271
+ });
10272
+ this._nodes = [];
10273
+ }
10274
+ connectedCallback() {
10275
+ this.refresh();
10276
+ }
10277
+ disconnectedCallback() {
10278
+ this.cleanup();
10279
+ }
10280
+ };
10281
+ __decorate61([
10282
+ changedAttribute("on-get-value"),
10283
+ __metadata3("design:type", Function),
10284
+ __metadata3("design:paramtypes", [String]),
10285
+ __metadata3("design:returntype", void 0)
10286
+ ], SwcChoose.prototype, "refresh", null);
10287
+ SwcChoose = __decorate61([
10288
+ elementDefine({ name: "swc-choose", extends: "template" })
10289
+ ], SwcChoose);
10290
+
10291
+ // src/elements/SwcAsync.ts
10292
+ var __decorate62 = function(decorators, target, key, desc) {
10293
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10294
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10295
+ 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;
10296
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
10297
+ };
10298
+ var __metadata4 = function(k, v) {
10299
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10300
+ };
10301
+ var SwcAsync = class SwcAsync2 extends HTMLTemplateElement {
10302
+ constructor() {
10303
+ super(...arguments);
10304
+ this._nodes = [];
10305
+ this._currentPromise = null;
10306
+ this._value = null;
10307
+ }
10308
+ get value() {
10309
+ return this._value;
10310
+ }
10311
+ set value(nv) {
10312
+ if (nv instanceof Promise) {
10313
+ this.handlePromise(nv);
10314
+ } else {
10315
+ this._value = nv;
10316
+ this.render(nv === null ? "default" : "success", nv);
10317
+ }
10318
+ }
10319
+ refresh(newValue) {
10320
+ const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
10321
+ if (!script) {
10322
+ this.value = null;
10323
+ return;
10324
+ }
10325
+ if (!this.parentElement)
10326
+ return;
10327
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
10328
+ try {
10329
+ const result = FunctionUtils.executeReturn({
10330
+ script,
10331
+ context: this,
10332
+ args: helperHostSet
10333
+ });
10334
+ if (result instanceof Promise) {
10335
+ this.handlePromise(result);
10336
+ } else {
10337
+ this.value = result;
10338
+ }
10339
+ } catch (e) {
10340
+ this.render("error", e);
10341
+ }
10342
+ }
10343
+ async handlePromise(promise) {
10344
+ this._currentPromise = promise;
10345
+ this.render("loading");
10346
+ try {
10347
+ const result = await promise;
10348
+ if (this._currentPromise !== promise)
10349
+ return;
10350
+ this._value = result;
10351
+ this.render("success", result);
10352
+ } catch (e) {
10353
+ if (this._currentPromise !== promise)
10354
+ return;
10355
+ this.render("error", e);
10356
+ }
10357
+ }
10358
+ render(state, data) {
10359
+ this.cleanup();
10360
+ if (!this.parentElement)
10361
+ return;
10362
+ let fragment;
10363
+ const ctx = {
10364
+ $nodes: [],
10365
+ $elements: [],
10366
+ $state: state,
10367
+ $value: null,
10368
+ $error: null
10369
+ };
10370
+ if (state === "default") {
10371
+ const t = this.content.querySelector('template[is="swc-default"]');
10372
+ fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
10373
+ } else if (state === "loading") {
10374
+ const t = this.content.querySelector('template[is="swc-loading"]');
10375
+ fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
10376
+ } else if (state === "error") {
10377
+ const t = this.content.querySelector('template[is="swc-error"]');
10378
+ ctx.$error = data;
10379
+ fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
10380
+ } else {
10381
+ const t = this.content.querySelector('template[is="swc-success"]');
10382
+ ctx.$value = data;
10383
+ if (t) {
10384
+ fragment = t.content.cloneNode(true);
10385
+ } else {
10386
+ const clone = this.content.cloneNode(true);
10387
+ Array.from(clone.querySelectorAll('template[is="swc-loading"], template[is="swc-error"], template[is="swc-success"], template[is="swc-default"]')).forEach((tmp) => tmp.remove());
10388
+ fragment = clone;
10389
+ }
10390
+ }
10391
+ this.mount(fragment, ctx);
10392
+ }
10393
+ mount(fragment, ctx) {
10394
+ const nodes = Array.from(fragment.childNodes);
10395
+ const elements = nodes.filter((n) => n.nodeType === 1);
10396
+ Object.assign(ctx, {
10397
+ $nodes: nodes,
10398
+ $elements: elements,
10399
+ $firstNode: nodes[0],
10400
+ $lastNode: nodes[nodes.length - 1],
10401
+ $firstElement: elements[0],
10402
+ $lastElement: elements[elements.length - 1]
10403
+ });
10404
+ this._executeCallback("on-clone-nodes", ctx);
10405
+ nodes.forEach((node, nodeIndex) => {
10406
+ if (node instanceof HTMLElement) {
10407
+ node.__swc_host = this;
10408
+ }
10409
+ this._executeCallback("on-clone-node", {
10410
+ ...ctx,
10411
+ $node: node,
10412
+ $nodeIndex: nodeIndex,
10413
+ $isElement: node.nodeType === 1
10414
+ });
10415
+ });
10416
+ this._nodes = nodes;
10417
+ this.parentElement?.insertBefore(fragment, this.nextSibling);
10418
+ }
10419
+ _executeCallback(attrName, extraArgs) {
10420
+ const script = this.getAttribute(attrName);
10421
+ if (!script)
10422
+ return;
10423
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
10424
+ try {
10425
+ FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
10426
+ } catch (e) {
10427
+ console.error(`[SwcAsync] Error in ${attrName}:`, e);
10428
+ }
10429
+ }
10430
+ cleanup() {
10431
+ this._nodes.forEach((n) => {
10432
+ if (n.parentElement)
10433
+ n.parentElement.removeChild(n);
10434
+ });
10435
+ this._nodes = [];
10436
+ }
10437
+ connectedCallback() {
10438
+ this.refresh();
10439
+ }
10440
+ disconnectedCallback() {
10441
+ this.cleanup();
10442
+ }
10443
+ };
10444
+ __decorate62([
10445
+ changedAttribute("on-get-value"),
10446
+ __metadata4("design:type", Function),
10447
+ __metadata4("design:paramtypes", [String]),
10448
+ __metadata4("design:returntype", void 0)
10449
+ ], SwcAsync.prototype, "refresh", null);
10450
+ SwcAsync = __decorate62([
10451
+ elementDefine({ name: "swc-async", extends: "template" })
10452
+ ], SwcAsync);
10453
+
10454
+ // src/elements/SwcApp.ts
10455
+ var __decorate63 = function(decorators, target, key, desc) {
10456
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10457
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10458
+ 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;
10459
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
10460
+ };
10461
+ var SwcApp = class SwcApp2 extends HTMLElement {
10462
+ constructor() {
10463
+ super(...arguments);
10464
+ this._engine = new SwcAppEngine(this);
10465
+ }
10466
+ get simpleApplication() {
10467
+ return this._engine.simpleApplication;
10468
+ }
10469
+ get router() {
10470
+ return this._engine.router;
10471
+ }
10472
+ connectedCallback() {
10473
+ this._engine.connect();
10474
+ }
10475
+ disconnectedCallback() {
10476
+ this._engine.disconnect();
10477
+ }
10478
+ async routing(path) {
10479
+ await this._engine.router?.go(path);
10480
+ }
10481
+ };
10482
+ SwcApp = __decorate63([
10483
+ elementDefine({ name: "swc-app", extends: void 0 })
10484
+ ], SwcApp);
9578
10485
  return __toCommonJS(bundle_entry_exports);
9579
10486
  })();
9580
10487
  /*! Bundled license information: