@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
@@ -1116,32 +1116,33 @@ var import_reflect_metadata2 = __toESM(require_Reflect(), 1);
1116
1116
  var import_reflect_metadata = __toESM(require_Reflect(), 1);
1117
1117
 
1118
1118
  // ../core/dist/esm/reflect/ReflectUtils.js
1119
- var ReflectUtils = {
1120
- getParameterTypes: (target, propertyKey) => {
1119
+ var ReflectUtils;
1120
+ ((ReflectUtils2) => {
1121
+ ReflectUtils2.getParameterTypes = (target, propertyKey) => {
1121
1122
  if (propertyKey) {
1122
1123
  return Reflect.getMetadata("design:paramtypes", target, propertyKey) || [];
1123
1124
  } else {
1124
1125
  return Reflect.getMetadata("design:paramtypes", target) || [];
1125
1126
  }
1126
- },
1127
- getReturnType: (target, propertyKey) => {
1127
+ };
1128
+ ReflectUtils2.getReturnType = (target, propertyKey) => {
1128
1129
  return Reflect.getMetadata("design:returntype", target, propertyKey);
1129
- },
1130
- getType: (target, propertyKey) => {
1130
+ };
1131
+ ReflectUtils2.getType = (target, propertyKey) => {
1131
1132
  if (propertyKey) {
1132
1133
  return Reflect.getMetadata("design:type", target, propertyKey);
1133
1134
  } else {
1134
1135
  return Reflect.getMetadata("design:type", target);
1135
1136
  }
1136
- },
1137
- getMetadata: (metadataKey, target, propertyKey) => {
1137
+ };
1138
+ ReflectUtils2.getMetadata = (metadataKey, target, propertyKey) => {
1138
1139
  if (propertyKey) {
1139
1140
  return Reflect.getMetadata(metadataKey, target, propertyKey);
1140
1141
  } else {
1141
1142
  return Reflect.getMetadata(metadataKey, target);
1142
1143
  }
1143
- },
1144
- findMetadata: (metadataKey, target, propertyKey) => {
1144
+ };
1145
+ ReflectUtils2.findMetadata = (metadataKey, target, propertyKey) => {
1145
1146
  if (target == null) return void 0;
1146
1147
  let searchTarget = typeof target === "object" && typeof target !== "function" ? target.constructor : target;
1147
1148
  while (searchTarget && searchTarget !== Object) {
@@ -1152,11 +1153,8 @@ var ReflectUtils = {
1152
1153
  if (searchTarget === target) break;
1153
1154
  }
1154
1155
  return void 0;
1155
- },
1156
- /**
1157
- * 프로토타입 체인의 모든 메타데이터를 수집하여 리스트로 반환합니다. (부모 -> 자식 순)
1158
- */
1159
- findAllMetadata: (metadataKey, target, propertyKey) => {
1156
+ };
1157
+ ReflectUtils2.findAllMetadata = (metadataKey, target, propertyKey) => {
1160
1158
  const results = [];
1161
1159
  if (target == null) return results;
1162
1160
  let searchTarget = typeof target === "object" && typeof target !== "function" ? target.constructor : target;
@@ -1168,24 +1166,18 @@ var ReflectUtils = {
1168
1166
  if (searchTarget === target) break;
1169
1167
  }
1170
1168
  return results;
1171
- },
1172
- /**
1173
- * 모든 메타데이터(배열 형태)를 수집하여 하나의 배열로 합칩니다. (부모 -> 자식 순)
1174
- */
1175
- findAllMetadataFlatten: (metadataKey, target, propertyKey) => {
1169
+ };
1170
+ ReflectUtils2.findAllMetadataFlatten = (metadataKey, target, propertyKey) => {
1176
1171
  const results = [];
1177
- const metaList = ReflectUtils.findAllMetadata(metadataKey, target, propertyKey);
1172
+ const metaList = (0, ReflectUtils2.findAllMetadata)(metadataKey, target, propertyKey);
1178
1173
  metaList.forEach((data) => {
1179
1174
  if (Array.isArray(data)) results.push(...data);
1180
1175
  });
1181
1176
  return [...new Set(results)];
1182
- },
1183
- /**
1184
- * 프로토타입 체인의 모든 메타데이터(맵 형태)를 수집하여 합칩니다. (부모 -> 자식 순)
1185
- */
1186
- findAllMapMetadata: (metadataKey, target) => {
1177
+ };
1178
+ ReflectUtils2.findAllMapMetadata = (metadataKey, target) => {
1187
1179
  const finalMap = /* @__PURE__ */ new Map();
1188
- const metaList = ReflectUtils.findAllMetadata(metadataKey, target);
1180
+ const metaList = (0, ReflectUtils2.findAllMetadata)(metadataKey, target);
1189
1181
  metaList.forEach((data) => {
1190
1182
  if (data instanceof Map) {
1191
1183
  data.forEach((values, key) => {
@@ -1196,31 +1188,69 @@ var ReflectUtils = {
1196
1188
  }
1197
1189
  });
1198
1190
  return finalMap;
1199
- },
1200
- getMetadataKeys: (target) => {
1191
+ };
1192
+ ReflectUtils2.getMetadataKeys = (target) => {
1201
1193
  return Reflect.getMetadataKeys(target);
1202
- },
1203
- getOwnMetadata: (metadataKey, target, propertyKey) => {
1194
+ };
1195
+ ReflectUtils2.getOwnMetadata = (metadataKey, target, propertyKey) => {
1204
1196
  if (propertyKey) {
1205
1197
  return Reflect.getOwnMetadata(metadataKey, target, propertyKey);
1206
1198
  } else {
1207
1199
  return Reflect.getOwnMetadata(metadataKey, target);
1208
1200
  }
1209
- },
1210
- getMetadatas: (target) => {
1211
- return ReflectUtils.getMetadataKeys(target).map((it) => ReflectUtils.getMetadata(it, target));
1212
- },
1213
- metadata: (metadataKey, data) => {
1201
+ };
1202
+ ReflectUtils2.getMetadatas = (target) => {
1203
+ return (0, ReflectUtils2.getMetadataKeys)(target).map((it) => (0, ReflectUtils2.getMetadata)(it, target));
1204
+ };
1205
+ ReflectUtils2.metadata = (metadataKey, data) => {
1214
1206
  return Reflect.metadata(metadataKey, data);
1215
- },
1216
- defineMetadata: (metadataKey, value, target, propertyKey) => {
1207
+ };
1208
+ ReflectUtils2.defineMetadata = (metadataKey, value, target, propertyKey) => {
1217
1209
  if (propertyKey && Reflect.defineMetadata) {
1218
1210
  Reflect.defineMetadata(metadataKey, value, target, propertyKey);
1219
1211
  } else if (Reflect.defineMetadata) {
1220
1212
  Reflect.defineMetadata(metadataKey, value, target);
1221
1213
  }
1222
- }
1223
- };
1214
+ };
1215
+ })(ReflectUtils || (ReflectUtils = {}));
1216
+
1217
+ // ../core/dist/esm/function/FunctionUtils.js
1218
+ var FunctionUtils;
1219
+ ((FunctionUtils2) => {
1220
+ FunctionUtils2.getParameterNames = (func, property) => {
1221
+ if (typeof func === "object" && property) {
1222
+ func = func[property];
1223
+ }
1224
+ return new RegExp("(?:" + func.name + "\\s*|^)\\s*\\((.*?)\\)").exec(func.toString().replace(/\n/g, ""))?.[1].replace(/\/\*.*?\*\//g, "").replace(/ /g, "").split(",") ?? [];
1225
+ };
1226
+ FunctionUtils2.evalScript = (script, obj) => {
1227
+ try {
1228
+ if (script && obj) {
1229
+ return Function(`"use strict";
1230
+ ${script}
1231
+ `).bind(obj)();
1232
+ } else if (script) {
1233
+ return new Function("return " + script)();
1234
+ } else {
1235
+ return null;
1236
+ }
1237
+ } catch (e) {
1238
+ return null;
1239
+ }
1240
+ };
1241
+ FunctionUtils2.execute = (params) => {
1242
+ const { script, context, args = {} } = params;
1243
+ const argNames = Object.keys(args);
1244
+ const argValues = Object.values(args);
1245
+ return new Function(...argNames, script).apply(context, argValues);
1246
+ };
1247
+ FunctionUtils2.executeReturn = (params) => {
1248
+ const { script, context, args = {} } = params;
1249
+ const argNames = Object.keys(args);
1250
+ const argValues = Object.values(args);
1251
+ return new Function(...argNames, `return ${script}`).apply(context, argValues);
1252
+ };
1253
+ })(FunctionUtils || (FunctionUtils = {}));
1224
1254
 
1225
1255
  // src/decorators/innerHtml.ts
1226
1256
  var INNER_HTML_METADATA_KEY = Symbol("simple-web-component:inner-html");
@@ -1380,8 +1410,27 @@ var findAllSetAttributeMetadata = (target) => {
1380
1410
 
1381
1411
  // src/utils/Utils.ts
1382
1412
  var SWC_NOT_FOUND = Symbol("SWC_NOT_FOUND");
1383
- var SwcUtils = class {
1384
- static getValueByPath(obj, path, rootName) {
1413
+ var SwcUtils;
1414
+ ((SwcUtils2) => {
1415
+ SwcUtils2.getHelperSet = (win) => {
1416
+ const doc = win.document;
1417
+ return {
1418
+ $d: doc,
1419
+ $w: win,
1420
+ $q: (sel, root) => (root ?? doc).querySelector(sel),
1421
+ $qa: (sel, root) => Array.from((root ?? doc).querySelectorAll(sel)),
1422
+ $qi: (id, root) => (root ?? doc).getElementById(id)
1423
+ };
1424
+ };
1425
+ SwcUtils2.getHelperAndHostSet = (win, el) => {
1426
+ const helperSet = (0, SwcUtils2.getHelperSet)(win);
1427
+ const hostSet = (0, SwcUtils2.getHostSet)(el);
1428
+ return {
1429
+ ...helperSet,
1430
+ ...hostSet
1431
+ };
1432
+ };
1433
+ SwcUtils2.getValueByPath = (obj, path, rootName) => {
1385
1434
  if (!obj || !path) return SWC_NOT_FOUND;
1386
1435
  const parts = path.split(".");
1387
1436
  let current = obj;
@@ -1390,49 +1439,66 @@ var SwcUtils = class {
1390
1439
  current = current[part];
1391
1440
  }
1392
1441
  return current;
1393
- }
1394
- static findNearestSwcHost(el) {
1395
- let current = el instanceof Node && !(el instanceof HTMLElement) ? el.host : el;
1396
- current = current?.parentElement || current?.getRootNode()?.host;
1397
- while (current) {
1442
+ };
1443
+ SwcUtils2.findNearestSwcHost = (el) => {
1444
+ if (el.__swc_host) return el.__swc_host;
1445
+ let current = el.parentElement || el.getRootNode?.()?.host;
1446
+ while (current && current !== document && current !== window) {
1447
+ if (current.__swc_host) return current.__swc_host;
1398
1448
  if (getElementConfig(current)) return current;
1399
- current = current.parentElement || current?.getRootNode()?.host;
1449
+ current = current.parentElement || current.getRootNode?.()?.host;
1400
1450
  }
1401
1451
  return void 0;
1402
- }
1403
- /**
1404
- * Returns all SWC ancestors (excluding self) in [root, ..., parent] order.
1405
- */
1406
- static findAllSwcHosts(el) {
1452
+ };
1453
+ SwcUtils2.findAllSwcHosts = (el) => {
1407
1454
  const hosts = [];
1408
- let current = this.findNearestSwcHost(el);
1455
+ let current = (0, SwcUtils2.findNearestSwcHost)(el);
1409
1456
  while (current) {
1410
1457
  hosts.push(current);
1411
- current = this.findNearestSwcHost(current);
1458
+ current = (0, SwcUtils2.findNearestSwcHost)(current);
1412
1459
  }
1413
1460
  return hosts.reverse();
1414
- }
1415
- static getHosts(el) {
1416
- return [...this.findAllSwcHosts(el), el];
1417
- }
1418
- static getHost(el) {
1419
- return el;
1420
- }
1421
- static getAppHosts(el) {
1422
- const hosts = this.getHosts(el);
1461
+ };
1462
+ SwcUtils2.getHosts = (el) => {
1463
+ const ancestors = (0, SwcUtils2.findAllSwcHosts)(el);
1464
+ if (getElementConfig(el)) return [...ancestors, el];
1465
+ return ancestors;
1466
+ };
1467
+ SwcUtils2.getHost = (el) => {
1468
+ if (getElementConfig(el)) return el;
1469
+ return (0, SwcUtils2.findNearestSwcHost)(el);
1470
+ };
1471
+ SwcUtils2.getAppHosts = (el) => {
1472
+ const hosts = (0, SwcUtils2.getHosts)(el);
1423
1473
  return hosts.filter((host) => host.tagName.toLowerCase() === "swc-app" || host.getAttribute("is")?.startsWith("swc-app-"));
1424
- }
1425
- static getAppHost(el) {
1426
- const appHosts = this.getAppHosts(el);
1474
+ };
1475
+ SwcUtils2.getAppHost = (el) => {
1476
+ const appHosts = (0, SwcUtils2.getAppHosts)(el);
1427
1477
  const appHostsWithoutSelf = appHosts.filter((h) => h !== el);
1428
1478
  return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : void 0;
1429
- }
1430
- static getHostSet(el) {
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;
1479
+ };
1480
+ SwcUtils2.getHostSet = (el) => {
1481
+ const isSwc = !!getElementConfig(el);
1482
+ const ancestors = (0, SwcUtils2.findAllSwcHosts)(el);
1483
+ let $host;
1484
+ let $parentHost;
1485
+ if (isSwc) {
1486
+ $host = el;
1487
+ $parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;
1488
+ } else {
1489
+ $host = ancestors.length > 0 ? ancestors[ancestors.length - 1] : el;
1490
+ $parentHost = ancestors.length > 1 ? ancestors[ancestors.length - 2] : null;
1491
+ }
1492
+ const $hosts = isSwc ? [...ancestors, el] : ancestors;
1493
+ const $firstHost = $hosts.length > 0 ? $hosts[0] : null;
1494
+ const loopContext = {};
1495
+ let curr = el;
1496
+ while (curr && curr !== document.documentElement) {
1497
+ if (curr.__swc_loop_context) {
1498
+ Object.assign(loopContext, curr.__swc_loop_context);
1499
+ }
1500
+ curr = curr.parentElement || curr.getRootNode().host;
1501
+ }
1436
1502
  const $appHosts = $hosts.filter((h) => h.tagName.toLowerCase() === "swc-app" || h.getAttribute("is")?.startsWith("swc-app-"));
1437
1503
  const $appHost = $appHosts.length > 0 ? $appHosts[$appHosts.length - 1] === el ? $appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null : $appHosts[$appHosts.length - 1] : null;
1438
1504
  const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;
@@ -1445,10 +1511,11 @@ var SwcUtils = class {
1445
1511
  $appHost,
1446
1512
  $appHosts,
1447
1513
  $firstAppHost,
1448
- $lastAppHost: $appHost
1514
+ $lastAppHost: $appHost,
1515
+ ...loopContext
1449
1516
  };
1450
- }
1451
- };
1517
+ };
1518
+ })(SwcUtils || (SwcUtils = {}));
1452
1519
 
1453
1520
  // src/config/config.ts
1454
1521
  var HTML_TAG_ENTRIES = [
@@ -1571,6 +1638,7 @@ var InjectSituationType = /* @__PURE__ */ ((InjectSituationType2) => {
1571
1638
 
1572
1639
  // src/decorators/elementDefine.ts
1573
1640
  var ELEMENT_CONFIG_KEY = Symbol("simple-web-component:element-config");
1641
+ var globalDelegatedRoots = /* @__PURE__ */ new WeakSet();
1574
1642
  function buildEnv(configWindow) {
1575
1643
  const win = configWindow || (typeof window !== "undefined" ? window : void 0);
1576
1644
  const doc = win?.document;
@@ -1579,13 +1647,7 @@ function buildEnv(configWindow) {
1579
1647
  if (win?.[cls])
1580
1648
  builtInTagMap.set(win[cls], tag);
1581
1649
  }
1582
- const domHelpers = {
1583
- $d: doc,
1584
- $w: win,
1585
- $q: (sel, root) => (root ?? doc).querySelector(sel),
1586
- $qa: (sel, root) => Array.from((root ?? doc).querySelectorAll(sel)),
1587
- $qi: (id, root) => (root ?? doc).getElementById(id)
1588
- };
1650
+ const domHelpers = SwcUtils.getHelperSet(win);
1589
1651
  return { win, doc, builtInTagMap, domHelpers };
1590
1652
  }
1591
1653
  var getHandlers = (inst) => {
@@ -1597,8 +1659,6 @@ var elementDefine = (inConfig) => (constructor) => {
1597
1659
  const config = typeof inConfig === "string" ? { name: inConfig } : inConfig;
1598
1660
  const { win, doc, builtInTagMap: BUILT_IN_TAG_MAP, domHelpers: SWC_DOM_HELPERS } = buildEnv(config.window);
1599
1661
  config.window = win;
1600
- const SWC_DOM_HELPER_KEYS = Object.keys(SWC_DOM_HELPERS);
1601
- const SWC_DOM_HELPER_VALS = () => SWC_DOM_HELPER_KEYS.map((k) => SWC_DOM_HELPERS[k]);
1602
1662
  let extendsTagName = config.extends;
1603
1663
  if (!extendsTagName) {
1604
1664
  let proto = constructor;
@@ -1624,9 +1684,7 @@ var elementDefine = (inConfig) => (constructor) => {
1624
1684
  if (script) {
1625
1685
  try {
1626
1686
  const args = { ...hostSet, ...SWC_DOM_HELPERS, ...extraArgs };
1627
- const argNames = Object.keys(args);
1628
- const argValues = Object.values(args);
1629
- new Function(...argNames, script).apply(this, argValues);
1687
+ FunctionUtils.execute({ script, context: this, args });
1630
1688
  } catch (e) {
1631
1689
  console.error(`[SWC] Failed to execute ${attrName}:`, e);
1632
1690
  }
@@ -1668,9 +1726,13 @@ var elementDefine = (inConfig) => (constructor) => {
1668
1726
  el.removeEventListener(eventName, oldHandler);
1669
1727
  const handler = (event) => {
1670
1728
  const hostSet = SwcUtils.getHostSet(el);
1671
- const argNames = Object.keys(hostSet);
1672
- const argValues = Object.values(hostSet);
1673
- new Function("event", "$data", ...argNames, ...SWC_DOM_HELPER_KEYS, script).call(el, event, event.detail, ...argValues, ...SWC_DOM_HELPER_VALS());
1729
+ const args = {
1730
+ event,
1731
+ $data: event.detail,
1732
+ ...hostSet,
1733
+ ...SWC_DOM_HELPERS
1734
+ };
1735
+ FunctionUtils.execute({ script, context: el, args });
1674
1736
  };
1675
1737
  el.addEventListener(eventName, handler);
1676
1738
  handlers.set(attrName, handler);
@@ -1679,6 +1741,7 @@ var elementDefine = (inConfig) => (constructor) => {
1679
1741
  super(...args);
1680
1742
  this._swcId = Math.random().toString(36).substring(2, 11);
1681
1743
  this._emitHandlers = /* @__PURE__ */ new Map();
1744
+ this._boundListeners = [];
1682
1745
  const hostSet = SwcUtils.getHostSet(this);
1683
1746
  this._executeSwcScript("swc-on-constructor", hostSet);
1684
1747
  if (innerHtmlList.some((it) => it.options.useShadow === true) && !this.shadowRoot) {
@@ -1689,6 +1752,9 @@ var elementDefine = (inConfig) => (constructor) => {
1689
1752
  return mergedObservedAttributes;
1690
1753
  }
1691
1754
  async connectedCallback() {
1755
+ const conf = getElementConfig(this);
1756
+ const currentWin = conf?.window || window;
1757
+ const currentDoc = currentWin.document;
1692
1758
  const hostSet = SwcUtils.getHostSet(this);
1693
1759
  this._executeSwcScript("swc-on-before-connected", hostSet);
1694
1760
  const bMethods = findAllLifecycleMetadata(this, ON_BEFORE_CONNECTED_METADATA_KEY);
@@ -1714,17 +1780,87 @@ var elementDefine = (inConfig) => (constructor) => {
1714
1780
  if (lContent)
1715
1781
  this.innerHTML = lContent;
1716
1782
  }
1783
+ const createDelegationHandler = (delegateHost) => (event) => {
1784
+ if (event.__swc_handled)
1785
+ return;
1786
+ const path = event.composedPath();
1787
+ const type = event.type;
1788
+ const attrName = `swc-on-${type}`;
1789
+ for (const node of path) {
1790
+ if (node === delegateHost)
1791
+ break;
1792
+ if (!(node instanceof HTMLElement))
1793
+ continue;
1794
+ const script = node.getAttribute?.(attrName);
1795
+ if (script && !getElementConfig(node)) {
1796
+ const host = SwcUtils.findNearestSwcHost(node);
1797
+ if (host) {
1798
+ const childHostSet = SwcUtils.getHostSet(node);
1799
+ const args = {
1800
+ event,
1801
+ $data: event.detail,
1802
+ ...childHostSet,
1803
+ ...SWC_DOM_HELPERS
1804
+ };
1805
+ FunctionUtils.execute({ script, context: node, args });
1806
+ event.__swc_handled = true;
1807
+ break;
1808
+ }
1809
+ }
1810
+ }
1811
+ };
1812
+ DOM_EVENT_NAMES.forEach((type) => {
1813
+ this.addEventListener(type, createDelegationHandler(this));
1814
+ this._boundListeners.push({ target: this, type, handler: createDelegationHandler(this) });
1815
+ });
1816
+ const hasParentHost = SwcUtils.findAllSwcHosts(this).length > 0;
1817
+ if (!hasParentHost) {
1818
+ const root = this.getRootNode();
1819
+ if (!globalDelegatedRoots.has(root)) {
1820
+ DOM_EVENT_NAMES.forEach((type) => {
1821
+ const handler = createDelegationHandler(root);
1822
+ root.addEventListener(type, handler);
1823
+ });
1824
+ globalDelegatedRoots.add(root);
1825
+ }
1826
+ }
1717
1827
  addEventListenerList.forEach((meta) => {
1718
1828
  const { selector, type, options } = meta;
1719
- const { root, capture, once, passive, stopPropagation, stopImmediatePropagation, preventDefault, delegate } = options;
1720
- if (delegate && selector && selector !== ":host") {
1829
+ const { root, capture, once, passive, stopPropagation, stopImmediatePropagation, preventDefault, delegate, removeOnDisconnected } = options;
1830
+ const opts = { capture, once, passive };
1831
+ const bindTargets = [];
1832
+ if (selector === ":window") {
1833
+ bindTargets.push(currentWin);
1834
+ } else if (selector === ":document") {
1835
+ bindTargets.push(currentDoc);
1836
+ } else if (selector === ":parentHost") {
1837
+ if (hostSet.$parentHost)
1838
+ bindTargets.push(hostSet.$parentHost);
1839
+ } else if (selector === ":appHost") {
1840
+ if (hostSet.$appHost)
1841
+ bindTargets.push(hostSet.$appHost);
1842
+ } else if (selector === ":firstHost") {
1843
+ if (hostSet.$firstHost)
1844
+ bindTargets.push(hostSet.$firstHost);
1845
+ } else if (selector === ":lastHost") {
1846
+ if (hostSet.$lastHost)
1847
+ bindTargets.push(hostSet.$lastHost);
1848
+ } else if (selector === ":firstAppHost") {
1849
+ if (hostSet.$firstAppHost)
1850
+ bindTargets.push(hostSet.$firstAppHost);
1851
+ } else if (selector === ":lastAppHost") {
1852
+ if (hostSet.$lastAppHost)
1853
+ bindTargets.push(hostSet.$lastAppHost);
1854
+ } else if (!selector || selector === ":host") {
1855
+ bindTargets.push(this);
1856
+ } else if (delegate) {
1721
1857
  const bindRoots = [];
1722
1858
  const r = root || "auto";
1723
- if (r === "auto") {
1859
+ if (r === "auto")
1724
1860
  bindRoots.push(this.shadowRoot || this);
1725
- } else if (r === "light") {
1861
+ else if (r === "light")
1726
1862
  bindRoots.push(this);
1727
- } else if (r === "shadow") {
1863
+ else if (r === "shadow") {
1728
1864
  if (this.shadowRoot)
1729
1865
  bindRoots.push(this.shadowRoot);
1730
1866
  } else if (r === "all") {
@@ -1732,62 +1868,61 @@ var elementDefine = (inConfig) => (constructor) => {
1732
1868
  if (this.shadowRoot)
1733
1869
  bindRoots.push(this.shadowRoot);
1734
1870
  }
1735
- bindRoots.forEach((bindRoot) => {
1871
+ bindRoots.forEach((br) => {
1736
1872
  const handler = (event) => {
1737
- const target = event.target;
1738
- const matchedEl = target.closest(selector);
1739
- if (matchedEl && bindRoot.contains(matchedEl)) {
1873
+ const matchedEl = event.target.closest(selector);
1874
+ if (matchedEl && br.contains(matchedEl)) {
1740
1875
  if (stopPropagation)
1741
1876
  event.stopPropagation();
1742
1877
  if (stopImmediatePropagation)
1743
1878
  event.stopImmediatePropagation();
1744
1879
  if (preventDefault)
1745
1880
  event.preventDefault();
1746
- const hostSet2 = SwcUtils.getHostSet(this);
1747
- this._invokeLifecycleMethod(meta.propertyKey, hostSet2, [event, hostSet2, matchedEl]);
1881
+ const currentHostSet = SwcUtils.getHostSet(this);
1882
+ this._invokeLifecycleMethod(meta.propertyKey, currentHostSet, [event, currentHostSet, matchedEl]);
1748
1883
  }
1749
1884
  };
1750
- bindRoot.addEventListener(type, handler, { capture, once, passive });
1885
+ br.addEventListener(type, handler, opts);
1886
+ const self2 = this;
1887
+ if (removeOnDisconnected === true || br !== self2 && br !== self2.shadowRoot) {
1888
+ this._boundListeners.push({ target: br, type, handler, options: opts });
1889
+ }
1751
1890
  });
1752
1891
  } 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
- });
1892
+ const searchRoots = [];
1893
+ const r = root || "auto";
1894
+ if (r === "auto")
1895
+ searchRoots.push(this.shadowRoot || this);
1896
+ else if (r === "light")
1897
+ searchRoots.push(this);
1898
+ else if (r === "shadow") {
1899
+ if (this.shadowRoot)
1900
+ searchRoots.push(this.shadowRoot);
1901
+ } else if (r === "all") {
1902
+ searchRoots.push(this);
1903
+ if (this.shadowRoot)
1904
+ searchRoots.push(this.shadowRoot);
1775
1905
  }
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);
1906
+ searchRoots.forEach((sr) => {
1907
+ sr.querySelectorAll(selector).forEach((el) => bindTargets.push(el));
1789
1908
  });
1790
1909
  }
1910
+ bindTargets.forEach((target) => {
1911
+ const handler = (event) => {
1912
+ if (stopPropagation)
1913
+ event.stopPropagation();
1914
+ if (stopImmediatePropagation)
1915
+ event.stopImmediatePropagation();
1916
+ if (preventDefault)
1917
+ event.preventDefault();
1918
+ const currentHostSet = SwcUtils.getHostSet(this);
1919
+ this._invokeLifecycleMethod(meta.propertyKey, currentHostSet, [event, currentHostSet]);
1920
+ };
1921
+ target.addEventListener(type, handler, opts);
1922
+ if (removeOnDisconnected === true || target === currentWin || target === currentDoc) {
1923
+ this._boundListeners.push({ target, type, handler, options: opts });
1924
+ }
1925
+ });
1791
1926
  });
1792
1927
  if (super.connectedCallback)
1793
1928
  await super.connectedCallback();
@@ -1805,6 +1940,8 @@ var elementDefine = (inConfig) => (constructor) => {
1805
1940
  const bMethods = findAllLifecycleMetadata(this, ON_BEFORE_DISCONNECTED_METADATA_KEY);
1806
1941
  if (bMethods)
1807
1942
  bMethods.forEach((m) => this._invokeLifecycleMethod(m, hostSet));
1943
+ this._boundListeners.forEach((l) => l.target.removeEventListener(l.type, l.handler, l.options));
1944
+ this._boundListeners = [];
1808
1945
  if (super.disconnectedCallback)
1809
1946
  super.disconnectedCallback();
1810
1947
  const aMethods = findAllLifecycleMetadata(this, ON_AFTER_DISCONNECTED_METADATA_KEY);
@@ -1913,6 +2050,26 @@ function query(selector, options = {}) {
1913
2050
  queries.push({ selector, options, propertyKey });
1914
2051
  Object.defineProperty(target, propertyKey, {
1915
2052
  get() {
2053
+ const hostSet = SwcUtils.getHostSet(this);
2054
+ if (selector === ":parentHost")
2055
+ return hostSet.$parentHost;
2056
+ if (selector === ":appHost")
2057
+ return hostSet.$appHost;
2058
+ if (selector === ":firstHost")
2059
+ return hostSet.$firstHost;
2060
+ if (selector === ":lastHost")
2061
+ return hostSet.$lastHost;
2062
+ if (selector === ":firstAppHost")
2063
+ return hostSet.$firstAppHost;
2064
+ if (selector === ":lastAppHost")
2065
+ return hostSet.$lastAppHost;
2066
+ const config = getElementConfig(this);
2067
+ const win = config?.window || window;
2068
+ const doc = win.document;
2069
+ if (selector === ":window")
2070
+ return win;
2071
+ if (selector === ":document")
2072
+ return doc;
1916
2073
  if (!selector || selector === ":host")
1917
2074
  return this;
1918
2075
  const r = options.root || "auto";
@@ -1953,6 +2110,18 @@ function queryAll(selector, options = {}) {
1953
2110
  queries.push({ selector, options, propertyKey });
1954
2111
  Object.defineProperty(target, propertyKey, {
1955
2112
  get() {
2113
+ const hostSet = SwcUtils.getHostSet(this);
2114
+ if (selector === ":hosts")
2115
+ return hostSet.$hosts;
2116
+ if (selector === ":appHosts")
2117
+ return hostSet.$appHosts;
2118
+ const config = getElementConfig(this);
2119
+ const win = config?.window || window;
2120
+ const doc = win.document;
2121
+ if (selector === ":window")
2122
+ return [win];
2123
+ if (selector === ":document")
2124
+ return [doc];
1956
2125
  if (!selector || selector === ":host")
1957
2126
  return [this];
1958
2127
  const r = options.root || "auto";
@@ -7597,7 +7766,7 @@ var SwcAppEngine = class {
7597
7766
  const configStr = this.host.getAttribute("swc-get-application-config");
7598
7767
  if (!configStr) return;
7599
7768
  try {
7600
- const userConfig = new Function(`return ${configStr}`).apply(this.host);
7769
+ const userConfig = FunctionUtils.executeReturn({ script: configStr, context: this.host });
7601
7770
  if (userConfig && userConfig.rootRouter) {
7602
7771
  const _config = {
7603
7772
  routeType: "element",
@@ -9461,6 +9630,732 @@ var SwcAppBody = class SwcAppBody2 extends HTMLBodyElement {
9461
9630
  SwcAppBody = __decorate57([
9462
9631
  elementDefine({ name: "swc-app-body", extends: "body" })
9463
9632
  ], SwcAppBody);
9633
+
9634
+ // src/elements/SwcSubTemplates.ts
9635
+ var __decorate58 = function(decorators, target, key, desc) {
9636
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9637
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
9638
+ 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;
9639
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
9640
+ };
9641
+ var SwcLoading = class SwcLoading2 extends HTMLTemplateElement {
9642
+ };
9643
+ SwcLoading = __decorate58([
9644
+ elementDefine({ name: "swc-loading", extends: "template" })
9645
+ ], SwcLoading);
9646
+ var SwcError = class SwcError2 extends HTMLTemplateElement {
9647
+ };
9648
+ SwcError = __decorate58([
9649
+ elementDefine({ name: "swc-error", extends: "template" })
9650
+ ], SwcError);
9651
+ var SwcSuccess = class SwcSuccess2 extends HTMLTemplateElement {
9652
+ };
9653
+ SwcSuccess = __decorate58([
9654
+ elementDefine({ name: "swc-success", extends: "template" })
9655
+ ], SwcSuccess);
9656
+ var SwcWhen = class SwcWhen2 extends HTMLTemplateElement {
9657
+ };
9658
+ SwcWhen = __decorate58([
9659
+ elementDefine({ name: "swc-when", extends: "template" })
9660
+ ], SwcWhen);
9661
+ var SwcOtherwise = class SwcOtherwise2 extends HTMLTemplateElement {
9662
+ };
9663
+ SwcOtherwise = __decorate58([
9664
+ elementDefine({ name: "swc-otherwise", extends: "template" })
9665
+ ], SwcOtherwise);
9666
+ var SwcDefault = class SwcDefault2 extends HTMLTemplateElement {
9667
+ };
9668
+ SwcDefault = __decorate58([
9669
+ elementDefine({ name: "swc-default", extends: "template" })
9670
+ ], SwcDefault);
9671
+
9672
+ // src/elements/SwcLoop.ts
9673
+ var __decorate59 = function(decorators, target, key, desc) {
9674
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9675
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
9676
+ 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;
9677
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
9678
+ };
9679
+ var __metadata = function(k, v) {
9680
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9681
+ };
9682
+ var SwcLoop = class SwcLoop2 extends HTMLTemplateElement {
9683
+ constructor() {
9684
+ super(...arguments);
9685
+ this._value = [];
9686
+ this._nodes = [];
9687
+ this._defaultNodes = [];
9688
+ }
9689
+ get value() {
9690
+ return this._value;
9691
+ }
9692
+ set value(nv) {
9693
+ this._value = Array.isArray(nv) ? [...nv] : [];
9694
+ this.render();
9695
+ }
9696
+ getNodes(index) {
9697
+ return this._nodes[index] || null;
9698
+ }
9699
+ _getTarget() {
9700
+ const script = this.getAttribute("on-get-portal");
9701
+ if (!script)
9702
+ return null;
9703
+ try {
9704
+ const res = FunctionUtils.executeReturn({
9705
+ script,
9706
+ context: this,
9707
+ args: SwcUtils.getHelperAndHostSet(window, this)
9708
+ });
9709
+ if (typeof res === "string")
9710
+ return document.querySelector(res);
9711
+ if (res instanceof Node)
9712
+ return res;
9713
+ } catch (e) {
9714
+ console.error("[SwcLoop] Portal target error:", e);
9715
+ }
9716
+ return null;
9717
+ }
9718
+ append(...items) {
9719
+ if (!items.length || !this.parentElement)
9720
+ return;
9721
+ if (this._defaultNodes.length > 0)
9722
+ this._cleanupDefault();
9723
+ const fragment = document.createDocumentFragment();
9724
+ const startIndex = this._value.length;
9725
+ items.forEach((item, i) => {
9726
+ const index = startIndex + i;
9727
+ const nodes = this._createItemNodes(item, index);
9728
+ if (nodes) {
9729
+ this._nodes.push(nodes);
9730
+ nodes.forEach((n) => fragment.appendChild(n));
9731
+ this._value.push(item);
9732
+ } else {
9733
+ this._nodes.push(null);
9734
+ this._value.push(null);
9735
+ }
9736
+ });
9737
+ const target = this._getTarget();
9738
+ if (target) {
9739
+ target.appendChild(fragment);
9740
+ } else {
9741
+ const lastValidIdx = this._nodes.length - items.length - 1;
9742
+ let refNode = this;
9743
+ for (let i = lastValidIdx; i >= 0; i--) {
9744
+ const group = this._nodes[i];
9745
+ if (group && group.length > 0) {
9746
+ refNode = group[group.length - 1];
9747
+ break;
9748
+ }
9749
+ }
9750
+ this.parentElement.insertBefore(fragment, refNode.nextSibling);
9751
+ }
9752
+ }
9753
+ remove(index) {
9754
+ const targetIdx = index !== void 0 ? index : this._nodes.length - 1;
9755
+ if (targetIdx < 0 || targetIdx >= this._nodes.length)
9756
+ return;
9757
+ const nodes = this._nodes[targetIdx];
9758
+ if (nodes) {
9759
+ nodes.forEach((n) => {
9760
+ if (n.parentElement)
9761
+ n.parentElement.removeChild(n);
9762
+ });
9763
+ this._nodes[targetIdx] = null;
9764
+ this._value[targetIdx] = null;
9765
+ }
9766
+ const activeRows = this._value.filter((v) => v !== null);
9767
+ if (activeRows.length === 0) {
9768
+ this.render();
9769
+ }
9770
+ }
9771
+ _createItemNodes(item, index) {
9772
+ const clone = this.content.cloneNode(true);
9773
+ Array.from(clone.querySelectorAll('template[is="swc-default"]')).forEach((t) => t.remove());
9774
+ const nodes = Array.from(clone.childNodes);
9775
+ const elements = nodes.filter((n) => n.nodeType === 1);
9776
+ const groupCtx = {
9777
+ $index: index,
9778
+ $item: item,
9779
+ $nodes: nodes,
9780
+ $elements: elements,
9781
+ $firstNode: nodes[0],
9782
+ $lastNode: nodes[nodes.length - 1],
9783
+ $firstElement: elements[0],
9784
+ $lastElement: elements[elements.length - 1],
9785
+ $isFirst: index === 0,
9786
+ $isLast: index === this._value.length - 1,
9787
+ $isEven: index % 2 === 0,
9788
+ $isOdd: index % 2 !== 0,
9789
+ $count: this._value.length
9790
+ };
9791
+ this._executeCallback("on-clone-nodes", groupCtx);
9792
+ nodes.forEach((node, nodeIndex) => {
9793
+ if (node instanceof HTMLElement)
9794
+ node.__swc_host = this;
9795
+ this._executeCallback("on-clone-node", { ...groupCtx, $node: node, $nodeIndex: nodeIndex, $isElement: node.nodeType === 1 });
9796
+ });
9797
+ return nodes;
9798
+ }
9799
+ _executeCallback(attrName, extraArgs) {
9800
+ const script = this.getAttribute(attrName);
9801
+ if (!script)
9802
+ return;
9803
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
9804
+ try {
9805
+ FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
9806
+ } catch (e) {
9807
+ console.error(`[SwcLoop] Error in ${attrName}:`, e);
9808
+ }
9809
+ }
9810
+ refreshValue(newValue) {
9811
+ const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
9812
+ if (!script) {
9813
+ this.value = [];
9814
+ return;
9815
+ }
9816
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
9817
+ try {
9818
+ const res = FunctionUtils.executeReturn({ script, context: this, args: helperHostSet });
9819
+ if (Array.isArray(res)) {
9820
+ this.value = res;
9821
+ }
9822
+ } catch (e) {
9823
+ console.error("[SwcLoop] Failed to get value from on-get-value script:", e);
9824
+ this.value = [];
9825
+ }
9826
+ }
9827
+ render() {
9828
+ this._cleanup();
9829
+ if (!this.parentElement)
9830
+ return;
9831
+ const activeRows = this._value.filter((v) => v !== null);
9832
+ const target = this._getTarget();
9833
+ if (activeRows.length === 0) {
9834
+ const t = this.content.querySelector('template[is="swc-default"]');
9835
+ if (t) {
9836
+ const clone = t.content.cloneNode(true);
9837
+ this._defaultNodes = Array.from(clone.childNodes);
9838
+ this._defaultNodes.forEach((n) => {
9839
+ if (n instanceof HTMLElement)
9840
+ n.__swc_host = this;
9841
+ });
9842
+ if (target)
9843
+ target.appendChild(clone);
9844
+ else
9845
+ this.parentElement.insertBefore(clone, this.nextSibling);
9846
+ }
9847
+ return;
9848
+ }
9849
+ const fragment = document.createDocumentFragment();
9850
+ this._value.forEach((item, index) => {
9851
+ if (item === null) {
9852
+ this._nodes.push(null);
9853
+ return;
9854
+ }
9855
+ const nodes = this._createItemNodes(item, index);
9856
+ this._nodes.push(nodes);
9857
+ nodes.forEach((n) => fragment.appendChild(n));
9858
+ });
9859
+ if (target)
9860
+ target.appendChild(fragment);
9861
+ else
9862
+ this.parentElement.insertBefore(fragment, this.nextSibling);
9863
+ }
9864
+ _cleanup() {
9865
+ this._nodes.forEach((group) => {
9866
+ if (group)
9867
+ group.forEach((node) => node.parentElement?.removeChild(node));
9868
+ });
9869
+ this._nodes = [];
9870
+ this._cleanupDefault();
9871
+ }
9872
+ _cleanupDefault() {
9873
+ this._defaultNodes.forEach((n) => n.parentElement?.removeChild(n));
9874
+ this._defaultNodes = [];
9875
+ }
9876
+ connectedCallback() {
9877
+ this.refreshValue();
9878
+ }
9879
+ disconnectedCallback() {
9880
+ this._cleanup();
9881
+ }
9882
+ };
9883
+ __decorate59([
9884
+ changedAttribute("on-get-value"),
9885
+ __metadata("design:type", Function),
9886
+ __metadata("design:paramtypes", [String]),
9887
+ __metadata("design:returntype", void 0)
9888
+ ], SwcLoop.prototype, "refreshValue", null);
9889
+ SwcLoop = __decorate59([
9890
+ elementDefine({ name: "swc-loop", extends: "template" })
9891
+ ], SwcLoop);
9892
+
9893
+ // src/elements/SwcIf.ts
9894
+ var __decorate60 = function(decorators, target, key, desc) {
9895
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9896
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
9897
+ 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;
9898
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
9899
+ };
9900
+ var __metadata2 = function(k, v) {
9901
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9902
+ };
9903
+ var SwcIf = class SwcIf2 extends HTMLTemplateElement {
9904
+ constructor() {
9905
+ super(...arguments);
9906
+ this._nodes = [];
9907
+ this._value = null;
9908
+ }
9909
+ get value() {
9910
+ return this._value;
9911
+ }
9912
+ set value(nv) {
9913
+ this._value = nv;
9914
+ this.render();
9915
+ }
9916
+ _getTarget() {
9917
+ const script = this.getAttribute("on-get-portal");
9918
+ if (!script)
9919
+ return null;
9920
+ try {
9921
+ const res = FunctionUtils.executeReturn({
9922
+ script,
9923
+ context: this,
9924
+ args: SwcUtils.getHelperAndHostSet(window, this)
9925
+ });
9926
+ if (typeof res === "string")
9927
+ return document.querySelector(res);
9928
+ if (res instanceof Node)
9929
+ return res;
9930
+ } catch (e) {
9931
+ console.error("[SwcIf] Portal target error:", e);
9932
+ }
9933
+ return null;
9934
+ }
9935
+ _executeCallback(attrName, extraArgs) {
9936
+ const script = this.getAttribute(attrName);
9937
+ if (!script)
9938
+ return;
9939
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
9940
+ try {
9941
+ FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
9942
+ } catch (e) {
9943
+ console.error(`[SwcIf] Error in ${attrName}:`, e);
9944
+ }
9945
+ }
9946
+ refresh(newValue) {
9947
+ const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
9948
+ if (!script) {
9949
+ this.value = null;
9950
+ return;
9951
+ }
9952
+ if (!this.parentElement)
9953
+ return;
9954
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
9955
+ try {
9956
+ const result = FunctionUtils.executeReturn({
9957
+ script,
9958
+ context: this,
9959
+ args: helperHostSet
9960
+ });
9961
+ this.value = result;
9962
+ } catch (e) {
9963
+ console.error("[SwcIf] Error in on-get-value:", e);
9964
+ this.value = null;
9965
+ }
9966
+ }
9967
+ render() {
9968
+ this.cleanup();
9969
+ if (!this.parentElement)
9970
+ return;
9971
+ let fragment = null;
9972
+ const ctx = { $value: this._value, $nodes: [], $elements: [] };
9973
+ if (this._value) {
9974
+ const clone = this.content.cloneNode(true);
9975
+ Array.from(clone.querySelectorAll('template[is="swc-default"]')).forEach((t) => t.remove());
9976
+ fragment = clone;
9977
+ } else {
9978
+ const t = this.content.querySelector('template[is="swc-default"]');
9979
+ if (t)
9980
+ fragment = t.content.cloneNode(true);
9981
+ }
9982
+ if (fragment) {
9983
+ this.mount(fragment, ctx);
9984
+ }
9985
+ }
9986
+ mount(fragment, ctx) {
9987
+ const nodes = Array.from(fragment.childNodes);
9988
+ const elements = nodes.filter((n) => n.nodeType === 1);
9989
+ Object.assign(ctx, {
9990
+ $nodes: nodes,
9991
+ $elements: elements,
9992
+ $firstNode: nodes[0],
9993
+ $lastNode: nodes[nodes.length - 1],
9994
+ $firstElement: elements[0],
9995
+ $lastElement: elements[elements.length - 1]
9996
+ });
9997
+ this._executeCallback("on-clone-nodes", ctx);
9998
+ nodes.forEach((node, nodeIndex) => {
9999
+ if (node instanceof HTMLElement)
10000
+ node.__swc_host = this;
10001
+ this._executeCallback("on-clone-node", { ...ctx, $node: node, $nodeIndex: nodeIndex, $isElement: node.nodeType === 1 });
10002
+ });
10003
+ this._nodes = nodes;
10004
+ const target = this._getTarget();
10005
+ if (target) {
10006
+ target.appendChild(fragment);
10007
+ } else {
10008
+ this.parentElement?.insertBefore(fragment, this.nextSibling);
10009
+ }
10010
+ }
10011
+ cleanup() {
10012
+ this._nodes.forEach((n) => {
10013
+ if (n.parentElement)
10014
+ n.parentElement.removeChild(n);
10015
+ });
10016
+ this._nodes = [];
10017
+ }
10018
+ connectedCallback() {
10019
+ this.refresh();
10020
+ }
10021
+ disconnectedCallback() {
10022
+ this.cleanup();
10023
+ }
10024
+ };
10025
+ __decorate60([
10026
+ changedAttribute("on-get-value"),
10027
+ __metadata2("design:type", Function),
10028
+ __metadata2("design:paramtypes", [String]),
10029
+ __metadata2("design:returntype", void 0)
10030
+ ], SwcIf.prototype, "refresh", null);
10031
+ SwcIf = __decorate60([
10032
+ elementDefine({ name: "swc-if", extends: "template" })
10033
+ ], SwcIf);
10034
+
10035
+ // src/elements/SwcChoose.ts
10036
+ var __decorate61 = function(decorators, target, key, desc) {
10037
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10038
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10039
+ 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;
10040
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
10041
+ };
10042
+ var __metadata3 = function(k, v) {
10043
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10044
+ };
10045
+ var SwcChoose = class SwcChoose2 extends HTMLTemplateElement {
10046
+ constructor() {
10047
+ super(...arguments);
10048
+ this._nodes = [];
10049
+ this._value = null;
10050
+ }
10051
+ get value() {
10052
+ return this._value;
10053
+ }
10054
+ set value(nv) {
10055
+ this._value = nv;
10056
+ this.render();
10057
+ }
10058
+ _executeCallback(attrName, extraArgs) {
10059
+ const script = this.getAttribute(attrName);
10060
+ if (!script)
10061
+ return;
10062
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
10063
+ try {
10064
+ FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
10065
+ } catch (e) {
10066
+ console.error(`[SwcChoose] Error in ${attrName}:`, e);
10067
+ }
10068
+ }
10069
+ refresh(newValue) {
10070
+ const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
10071
+ if (!script) {
10072
+ this.value = null;
10073
+ return;
10074
+ }
10075
+ if (!this.parentElement)
10076
+ return;
10077
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
10078
+ try {
10079
+ const result = FunctionUtils.executeReturn({
10080
+ script,
10081
+ context: this,
10082
+ args: helperHostSet
10083
+ });
10084
+ this.value = result;
10085
+ } catch (e) {
10086
+ console.error("[SwcChoose] Error in on-get-value:", e);
10087
+ }
10088
+ }
10089
+ render() {
10090
+ this.cleanup();
10091
+ if (!this.parentElement)
10092
+ return;
10093
+ const templates = Array.from(this.content.querySelectorAll("template"));
10094
+ let selected = null;
10095
+ let otherwise = null;
10096
+ let defaultTmp = null;
10097
+ for (const t of templates) {
10098
+ const is = t.getAttribute("is");
10099
+ if (is === "swc-when") {
10100
+ const whenVal = t.getAttribute("value");
10101
+ if (String(whenVal) === String(this._value)) {
10102
+ selected = t;
10103
+ break;
10104
+ }
10105
+ } else if (is === "swc-otherwise") {
10106
+ otherwise = t;
10107
+ } else if (is === "swc-default") {
10108
+ defaultTmp = t;
10109
+ }
10110
+ }
10111
+ const targetTemplate = (this._value == null ? defaultTmp : selected) || otherwise || defaultTmp;
10112
+ if (targetTemplate) {
10113
+ const clone = targetTemplate.content.cloneNode(true);
10114
+ const nodes = Array.from(clone.childNodes);
10115
+ const elements = nodes.filter((n) => n.nodeType === 1);
10116
+ const ctx = {
10117
+ $value: this._value,
10118
+ $nodes: nodes,
10119
+ $elements: elements,
10120
+ $firstNode: nodes[0],
10121
+ $lastNode: nodes[nodes.length - 1],
10122
+ $firstElement: elements[0],
10123
+ $lastElement: elements[elements.length - 1]
10124
+ };
10125
+ this._executeCallback("on-clone-nodes", ctx);
10126
+ nodes.forEach((node, nodeIndex) => {
10127
+ if (node instanceof HTMLElement) {
10128
+ node.__swc_host = this;
10129
+ }
10130
+ this._executeCallback("on-clone-node", {
10131
+ ...ctx,
10132
+ $node: node,
10133
+ $nodeIndex: nodeIndex,
10134
+ $isElement: node.nodeType === 1
10135
+ });
10136
+ });
10137
+ this._nodes = nodes;
10138
+ this.parentElement.insertBefore(clone, this.nextSibling);
10139
+ }
10140
+ }
10141
+ cleanup() {
10142
+ this._nodes.forEach((n) => {
10143
+ if (n.parentElement)
10144
+ n.parentElement.removeChild(n);
10145
+ });
10146
+ this._nodes = [];
10147
+ }
10148
+ connectedCallback() {
10149
+ this.refresh();
10150
+ }
10151
+ disconnectedCallback() {
10152
+ this.cleanup();
10153
+ }
10154
+ };
10155
+ __decorate61([
10156
+ changedAttribute("on-get-value"),
10157
+ __metadata3("design:type", Function),
10158
+ __metadata3("design:paramtypes", [String]),
10159
+ __metadata3("design:returntype", void 0)
10160
+ ], SwcChoose.prototype, "refresh", null);
10161
+ SwcChoose = __decorate61([
10162
+ elementDefine({ name: "swc-choose", extends: "template" })
10163
+ ], SwcChoose);
10164
+
10165
+ // src/elements/SwcAsync.ts
10166
+ var __decorate62 = function(decorators, target, key, desc) {
10167
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10168
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10169
+ 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;
10170
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
10171
+ };
10172
+ var __metadata4 = function(k, v) {
10173
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10174
+ };
10175
+ var SwcAsync = class SwcAsync2 extends HTMLTemplateElement {
10176
+ constructor() {
10177
+ super(...arguments);
10178
+ this._nodes = [];
10179
+ this._currentPromise = null;
10180
+ this._value = null;
10181
+ }
10182
+ get value() {
10183
+ return this._value;
10184
+ }
10185
+ set value(nv) {
10186
+ if (nv instanceof Promise) {
10187
+ this.handlePromise(nv);
10188
+ } else {
10189
+ this._value = nv;
10190
+ this.render(nv === null ? "default" : "success", nv);
10191
+ }
10192
+ }
10193
+ refresh(newValue) {
10194
+ const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
10195
+ if (!script) {
10196
+ this.value = null;
10197
+ return;
10198
+ }
10199
+ if (!this.parentElement)
10200
+ return;
10201
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
10202
+ try {
10203
+ const result = FunctionUtils.executeReturn({
10204
+ script,
10205
+ context: this,
10206
+ args: helperHostSet
10207
+ });
10208
+ if (result instanceof Promise) {
10209
+ this.handlePromise(result);
10210
+ } else {
10211
+ this.value = result;
10212
+ }
10213
+ } catch (e) {
10214
+ this.render("error", e);
10215
+ }
10216
+ }
10217
+ async handlePromise(promise) {
10218
+ this._currentPromise = promise;
10219
+ this.render("loading");
10220
+ try {
10221
+ const result = await promise;
10222
+ if (this._currentPromise !== promise)
10223
+ return;
10224
+ this._value = result;
10225
+ this.render("success", result);
10226
+ } catch (e) {
10227
+ if (this._currentPromise !== promise)
10228
+ return;
10229
+ this.render("error", e);
10230
+ }
10231
+ }
10232
+ render(state, data) {
10233
+ this.cleanup();
10234
+ if (!this.parentElement)
10235
+ return;
10236
+ let fragment;
10237
+ const ctx = {
10238
+ $nodes: [],
10239
+ $elements: [],
10240
+ $state: state,
10241
+ $value: null,
10242
+ $error: null
10243
+ };
10244
+ if (state === "default") {
10245
+ const t = this.content.querySelector('template[is="swc-default"]');
10246
+ fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
10247
+ } else if (state === "loading") {
10248
+ const t = this.content.querySelector('template[is="swc-loading"]');
10249
+ fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
10250
+ } else if (state === "error") {
10251
+ const t = this.content.querySelector('template[is="swc-error"]');
10252
+ ctx.$error = data;
10253
+ fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
10254
+ } else {
10255
+ const t = this.content.querySelector('template[is="swc-success"]');
10256
+ ctx.$value = data;
10257
+ if (t) {
10258
+ fragment = t.content.cloneNode(true);
10259
+ } else {
10260
+ const clone = this.content.cloneNode(true);
10261
+ Array.from(clone.querySelectorAll('template[is="swc-loading"], template[is="swc-error"], template[is="swc-success"], template[is="swc-default"]')).forEach((tmp) => tmp.remove());
10262
+ fragment = clone;
10263
+ }
10264
+ }
10265
+ this.mount(fragment, ctx);
10266
+ }
10267
+ mount(fragment, ctx) {
10268
+ const nodes = Array.from(fragment.childNodes);
10269
+ const elements = nodes.filter((n) => n.nodeType === 1);
10270
+ Object.assign(ctx, {
10271
+ $nodes: nodes,
10272
+ $elements: elements,
10273
+ $firstNode: nodes[0],
10274
+ $lastNode: nodes[nodes.length - 1],
10275
+ $firstElement: elements[0],
10276
+ $lastElement: elements[elements.length - 1]
10277
+ });
10278
+ this._executeCallback("on-clone-nodes", ctx);
10279
+ nodes.forEach((node, nodeIndex) => {
10280
+ if (node instanceof HTMLElement) {
10281
+ node.__swc_host = this;
10282
+ }
10283
+ this._executeCallback("on-clone-node", {
10284
+ ...ctx,
10285
+ $node: node,
10286
+ $nodeIndex: nodeIndex,
10287
+ $isElement: node.nodeType === 1
10288
+ });
10289
+ });
10290
+ this._nodes = nodes;
10291
+ this.parentElement?.insertBefore(fragment, this.nextSibling);
10292
+ }
10293
+ _executeCallback(attrName, extraArgs) {
10294
+ const script = this.getAttribute(attrName);
10295
+ if (!script)
10296
+ return;
10297
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
10298
+ try {
10299
+ FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
10300
+ } catch (e) {
10301
+ console.error(`[SwcAsync] Error in ${attrName}:`, e);
10302
+ }
10303
+ }
10304
+ cleanup() {
10305
+ this._nodes.forEach((n) => {
10306
+ if (n.parentElement)
10307
+ n.parentElement.removeChild(n);
10308
+ });
10309
+ this._nodes = [];
10310
+ }
10311
+ connectedCallback() {
10312
+ this.refresh();
10313
+ }
10314
+ disconnectedCallback() {
10315
+ this.cleanup();
10316
+ }
10317
+ };
10318
+ __decorate62([
10319
+ changedAttribute("on-get-value"),
10320
+ __metadata4("design:type", Function),
10321
+ __metadata4("design:paramtypes", [String]),
10322
+ __metadata4("design:returntype", void 0)
10323
+ ], SwcAsync.prototype, "refresh", null);
10324
+ SwcAsync = __decorate62([
10325
+ elementDefine({ name: "swc-async", extends: "template" })
10326
+ ], SwcAsync);
10327
+
10328
+ // src/elements/SwcApp.ts
10329
+ var __decorate63 = function(decorators, target, key, desc) {
10330
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10331
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10332
+ 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;
10333
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
10334
+ };
10335
+ var SwcApp = class SwcApp2 extends HTMLElement {
10336
+ constructor() {
10337
+ super(...arguments);
10338
+ this._engine = new SwcAppEngine(this);
10339
+ }
10340
+ get simpleApplication() {
10341
+ return this._engine.simpleApplication;
10342
+ }
10343
+ get router() {
10344
+ return this._engine.router;
10345
+ }
10346
+ connectedCallback() {
10347
+ this._engine.connect();
10348
+ }
10349
+ disconnectedCallback() {
10350
+ this._engine.disconnect();
10351
+ }
10352
+ async routing(path) {
10353
+ await this._engine.router?.go(path);
10354
+ }
10355
+ };
10356
+ SwcApp = __decorate63([
10357
+ elementDefine({ name: "swc-app", extends: void 0 })
10358
+ ], SwcApp);
9464
10359
  export {
9465
10360
  ADD_EVENT_LISTENER_METADATA_KEY,
9466
10361
  ATTRIBUTE_CHANGED_WILDCARD,
@@ -9480,6 +10375,7 @@ export {
9480
10375
  QUERY_METADATA_KEY,
9481
10376
  SET_ATTRIBUTE_METADATA_KEY,
9482
10377
  SWC_NOT_FOUND,
10378
+ SwcApp,
9483
10379
  SwcAppAnchor,
9484
10380
  SwcAppArea,
9485
10381
  SwcAppAudio,
@@ -9494,6 +10390,7 @@ export {
9494
10390
  SwcAppDiv,
9495
10391
  SwcAppDl,
9496
10392
  SwcAppEmbed,
10393
+ SwcAppEngine,
9497
10394
  SwcAppFieldSet,
9498
10395
  SwcAppForm,
9499
10396
  SwcAppHeading,
@@ -9537,7 +10434,17 @@ export {
9537
10434
  SwcAppTrack,
9538
10435
  SwcAppUl,
9539
10436
  SwcAppVideo,
10437
+ SwcAsync,
10438
+ SwcChoose,
10439
+ SwcDefault,
10440
+ SwcError,
10441
+ SwcIf,
10442
+ SwcLoading,
10443
+ SwcLoop,
10444
+ SwcOtherwise,
10445
+ SwcSuccess,
9540
10446
  SwcUtils,
10447
+ SwcWhen,
9541
10448
  addEventListener,
9542
10449
  changedAttribute,
9543
10450
  elementDefine,