@dooboostore/simple-web-component 1.0.16 → 1.0.18

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 (130) hide show
  1. package/README.md +109 -48
  2. package/dist/cjs/decorators/addEventListener.js.map +2 -2
  3. package/dist/cjs/decorators/appendChild.js +48 -0
  4. package/dist/cjs/decorators/appendChild.js.map +7 -0
  5. package/dist/cjs/decorators/elementDefine.js +216 -67
  6. package/dist/cjs/decorators/elementDefine.js.map +3 -3
  7. package/dist/cjs/decorators/index.js +2 -1
  8. package/dist/cjs/decorators/index.js.map +2 -2
  9. package/dist/cjs/decorators/{innerHtml.js → onConnectedInnerHtml.js} +8 -8
  10. package/dist/cjs/decorators/onConnectedInnerHtml.js.map +7 -0
  11. package/dist/cjs/decorators/query.js +38 -0
  12. package/dist/cjs/decorators/query.js.map +2 -2
  13. package/dist/cjs/decorators/queryAll.js +32 -0
  14. package/dist/cjs/decorators/queryAll.js.map +2 -2
  15. package/dist/cjs/decorators/replaceChildren.js +53 -0
  16. package/dist/cjs/decorators/replaceChildren.js.map +7 -0
  17. package/dist/cjs/elements/SwcAppEngine.js +2 -1
  18. package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
  19. package/dist/cjs/elements/SwcAsync.js +188 -0
  20. package/dist/cjs/elements/SwcAsync.js.map +7 -0
  21. package/dist/cjs/elements/SwcChoose.js +155 -0
  22. package/dist/cjs/elements/SwcChoose.js.map +7 -0
  23. package/dist/cjs/elements/SwcIf.js +167 -0
  24. package/dist/cjs/elements/SwcIf.js.map +7 -0
  25. package/dist/cjs/elements/SwcLoop.js +246 -0
  26. package/dist/cjs/elements/SwcLoop.js.map +7 -0
  27. package/dist/cjs/elements/SwcSubTemplates.js +65 -0
  28. package/dist/cjs/elements/SwcSubTemplates.js.map +7 -0
  29. package/dist/cjs/elements/index.js +7 -0
  30. package/dist/cjs/elements/index.js.map +2 -2
  31. package/dist/cjs/index.js +12 -2
  32. package/dist/cjs/index.js.map +2 -2
  33. package/dist/cjs/types.js.map +1 -1
  34. package/dist/cjs/utils/Utils.js +74 -37
  35. package/dist/cjs/utils/Utils.js.map +3 -3
  36. package/dist/esm/decorators/addEventListener.js.map +2 -2
  37. package/dist/esm/decorators/appendChild.js +29 -0
  38. package/dist/esm/decorators/appendChild.js.map +7 -0
  39. package/dist/esm/decorators/elementDefine.js +216 -67
  40. package/dist/esm/decorators/elementDefine.js.map +3 -3
  41. package/dist/esm/decorators/index.js +2 -1
  42. package/dist/esm/decorators/index.js.map +2 -2
  43. package/dist/esm/decorators/{innerHtml.js → onConnectedInnerHtml.js} +5 -5
  44. package/dist/esm/decorators/onConnectedInnerHtml.js.map +7 -0
  45. package/dist/esm/decorators/query.js +38 -0
  46. package/dist/esm/decorators/query.js.map +2 -2
  47. package/dist/esm/decorators/queryAll.js +32 -0
  48. package/dist/esm/decorators/queryAll.js.map +2 -2
  49. package/dist/esm/decorators/replaceChildren.js +34 -0
  50. package/dist/esm/decorators/replaceChildren.js.map +7 -0
  51. package/dist/esm/elements/SwcAppEngine.js +2 -1
  52. package/dist/esm/elements/SwcAppEngine.js.map +2 -2
  53. package/dist/esm/elements/SwcAsync.js +169 -0
  54. package/dist/esm/elements/SwcAsync.js.map +7 -0
  55. package/dist/esm/elements/SwcChoose.js +136 -0
  56. package/dist/esm/elements/SwcChoose.js.map +7 -0
  57. package/dist/esm/elements/SwcIf.js +148 -0
  58. package/dist/esm/elements/SwcIf.js.map +7 -0
  59. package/dist/esm/elements/SwcLoop.js +227 -0
  60. package/dist/esm/elements/SwcLoop.js.map +7 -0
  61. package/dist/esm/elements/SwcSubTemplates.js +46 -0
  62. package/dist/esm/elements/SwcSubTemplates.js.map +7 -0
  63. package/dist/esm/elements/index.js +7 -0
  64. package/dist/esm/elements/index.js.map +2 -2
  65. package/dist/esm/index.js +8 -2
  66. package/dist/esm/index.js.map +2 -2
  67. package/dist/esm/types.js.map +1 -1
  68. package/dist/esm/utils/Utils.js +74 -37
  69. package/dist/esm/utils/Utils.js.map +3 -3
  70. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +1226 -149
  71. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  72. package/dist/types/decorators/addEventListener.d.ts +1 -0
  73. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  74. package/dist/types/decorators/appendChild.d.ts +17 -0
  75. package/dist/types/decorators/appendChild.d.ts.map +1 -0
  76. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  77. package/dist/types/decorators/index.d.ts +2 -1
  78. package/dist/types/decorators/index.d.ts.map +1 -1
  79. package/dist/types/decorators/onConnectedInnerHtml.d.ts +15 -0
  80. package/dist/types/decorators/onConnectedInnerHtml.d.ts.map +1 -0
  81. package/dist/types/decorators/query.d.ts +0 -2
  82. package/dist/types/decorators/query.d.ts.map +1 -1
  83. package/dist/types/decorators/queryAll.d.ts +0 -2
  84. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  85. package/dist/types/decorators/replaceChildren.d.ts +9 -0
  86. package/dist/types/decorators/replaceChildren.d.ts.map +1 -0
  87. package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
  88. package/dist/types/elements/SwcAsync.d.ts +16 -0
  89. package/dist/types/elements/SwcAsync.d.ts.map +1 -0
  90. package/dist/types/elements/SwcChoose.d.ts +13 -0
  91. package/dist/types/elements/SwcChoose.d.ts.map +1 -0
  92. package/dist/types/elements/SwcIf.d.ts +15 -0
  93. package/dist/types/elements/SwcIf.d.ts.map +1 -0
  94. package/dist/types/elements/SwcLoop.d.ts +20 -0
  95. package/dist/types/elements/SwcLoop.d.ts.map +1 -0
  96. package/dist/types/elements/SwcSubTemplates.d.ts +13 -0
  97. package/dist/types/elements/SwcSubTemplates.d.ts.map +1 -0
  98. package/dist/types/elements/index.d.ts +7 -0
  99. package/dist/types/elements/index.d.ts.map +1 -1
  100. package/dist/types/index.d.ts +5 -2
  101. package/dist/types/index.d.ts.map +1 -1
  102. package/dist/types/types.d.ts +8 -0
  103. package/dist/types/types.d.ts.map +1 -1
  104. package/dist/types/utils/Utils.d.ts +16 -10
  105. package/dist/types/utils/Utils.d.ts.map +1 -1
  106. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +1226 -149
  107. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  108. package/package.json +10 -3
  109. package/src/decorators/addEventListener.ts +1 -0
  110. package/src/decorators/appendChild.ts +42 -0
  111. package/src/decorators/elementDefine.ts +225 -71
  112. package/src/decorators/index.ts +2 -1
  113. package/src/decorators/{innerHtml.ts → onConnectedInnerHtml.ts} +7 -6
  114. package/src/decorators/query.ts +32 -2
  115. package/src/decorators/queryAll.ts +32 -2
  116. package/src/decorators/replaceChildren.ts +35 -0
  117. package/src/elements/SwcAppEngine.ts +2 -1
  118. package/src/elements/SwcAsync.ts +163 -0
  119. package/src/elements/SwcChoose.ts +127 -0
  120. package/src/elements/SwcIf.ts +134 -0
  121. package/src/elements/SwcLoop.ts +215 -0
  122. package/src/elements/SwcSubTemplates.ts +19 -0
  123. package/src/elements/index.ts +8 -3
  124. package/src/index.ts +5 -2
  125. package/src/types.ts +9 -1
  126. package/src/utils/Utils.ts +86 -36
  127. package/dist/cjs/decorators/innerHtml.js.map +0 -7
  128. package/dist/esm/decorators/innerHtml.js.map +0 -7
  129. package/dist/types/decorators/innerHtml.d.ts +0 -12
  130. package/dist/types/decorators/innerHtml.d.ts.map +0 -1
@@ -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,35 +1188,73 @@ 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
- // src/decorators/innerHtml.ts
1255
+ // src/decorators/onConnectedInnerHtml.ts
1226
1256
  var INNER_HTML_METADATA_KEY = Symbol("simple-web-component:inner-html");
1227
- function innerHtml(arg1, arg2, arg3) {
1257
+ function onConnectedInnerHtml(arg1, arg2, arg3) {
1228
1258
  const decorator = (options, target, propertyKey) => {
1229
1259
  const constructor = target.constructor;
1230
1260
  let list = ReflectUtils.getMetadata(INNER_HTML_METADATA_KEY, constructor);
@@ -1241,7 +1271,7 @@ function innerHtml(arg1, arg2, arg3) {
1241
1271
  decorator(arg1 || {}, target, propertyKey);
1242
1272
  };
1243
1273
  }
1244
- var getInnerHtmlMetadataList = (target) => {
1274
+ var getOnConnectedInnerHtmlMetadata = (target) => {
1245
1275
  const constructor = target instanceof Function ? target : target.constructor;
1246
1276
  return ReflectUtils.getMetadata(INNER_HTML_METADATA_KEY, constructor);
1247
1277
  };
@@ -1378,10 +1408,81 @@ var findAllSetAttributeMetadata = (target) => {
1378
1408
  return result;
1379
1409
  };
1380
1410
 
1411
+ // src/decorators/replaceChildren.ts
1412
+ var REPLACE_CHILDREN_METADATA_KEY = Symbol("simple-web-component:replace-children");
1413
+ function replaceChildren(selector) {
1414
+ return (target, propertyKey) => {
1415
+ const constructor = target.constructor;
1416
+ let meta = ReflectUtils.getOwnMetadata(REPLACE_CHILDREN_METADATA_KEY, constructor);
1417
+ if (!meta) {
1418
+ meta = /* @__PURE__ */ new Map();
1419
+ ReflectUtils.defineMetadata(REPLACE_CHILDREN_METADATA_KEY, meta, constructor);
1420
+ }
1421
+ meta.set(propertyKey, selector);
1422
+ };
1423
+ }
1424
+ var getReplaceChildrenMetadata = (target) => {
1425
+ const constructor = target instanceof Function ? target : target.constructor;
1426
+ return ReflectUtils.getMetadata(REPLACE_CHILDREN_METADATA_KEY, constructor);
1427
+ };
1428
+ var findAllReplaceChildrenMetadata = (target) => {
1429
+ const result = /* @__PURE__ */ new Map();
1430
+ const maps = ReflectUtils.findAllMetadata(REPLACE_CHILDREN_METADATA_KEY, target);
1431
+ maps.forEach((map) => {
1432
+ if (map instanceof Map) {
1433
+ map.forEach((v, k) => result.set(k, v));
1434
+ }
1435
+ });
1436
+ return result;
1437
+ };
1438
+
1439
+ // src/decorators/appendChild.ts
1440
+ var APPEND_CHILD_METADATA_KEY = Symbol("simple-web-component:append-child");
1441
+ function appendChild(selector, options = { position: "lastChild" }) {
1442
+ return (target, propertyKey) => {
1443
+ const constructor = target.constructor;
1444
+ let meta = ReflectUtils.getOwnMetadata(APPEND_CHILD_METADATA_KEY, constructor);
1445
+ if (!meta) {
1446
+ meta = /* @__PURE__ */ new Map();
1447
+ ReflectUtils.defineMetadata(APPEND_CHILD_METADATA_KEY, meta, constructor);
1448
+ }
1449
+ meta.set(propertyKey, { propertyKey, selector, options });
1450
+ };
1451
+ }
1452
+ var findAllAppendChildMetadata = (target) => {
1453
+ const result = /* @__PURE__ */ new Map();
1454
+ const maps = ReflectUtils.findAllMetadata(APPEND_CHILD_METADATA_KEY, target);
1455
+ maps.forEach((map) => {
1456
+ if (map instanceof Map) {
1457
+ map.forEach((v, k) => result.set(k, v));
1458
+ }
1459
+ });
1460
+ return result;
1461
+ };
1462
+
1381
1463
  // src/utils/Utils.ts
1382
1464
  var SWC_NOT_FOUND = Symbol("SWC_NOT_FOUND");
1383
- var SwcUtils = class {
1384
- static getValueByPath(obj, path, rootName) {
1465
+ var SwcUtils;
1466
+ ((SwcUtils2) => {
1467
+ SwcUtils2.getHelperSet = (win) => {
1468
+ const doc = win.document;
1469
+ return {
1470
+ $d: doc,
1471
+ $w: win,
1472
+ $q: (sel, root) => (root ?? doc).querySelector(sel),
1473
+ $qa: (sel, root) => Array.from((root ?? doc).querySelectorAll(sel)),
1474
+ $qi: (id, root) => (root ?? doc).getElementById(id)
1475
+ };
1476
+ };
1477
+ SwcUtils2.getHelperAndHostSet = (win, el) => {
1478
+ const helperSet = (0, SwcUtils2.getHelperSet)(win);
1479
+ const hostSet = (0, SwcUtils2.getHostSet)(el);
1480
+ return {
1481
+ ...helperSet,
1482
+ ...hostSet
1483
+ };
1484
+ };
1485
+ SwcUtils2.getValueByPath = (obj, path, rootName) => {
1385
1486
  if (!obj || !path) return SWC_NOT_FOUND;
1386
1487
  const parts = path.split(".");
1387
1488
  let current = obj;
@@ -1390,49 +1491,66 @@ var SwcUtils = class {
1390
1491
  current = current[part];
1391
1492
  }
1392
1493
  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) {
1494
+ };
1495
+ SwcUtils2.findNearestSwcHost = (el) => {
1496
+ if (el.__swc_host) return el.__swc_host;
1497
+ let current = el.parentElement || el.getRootNode?.()?.host;
1498
+ while (current && current !== document && current !== window) {
1499
+ if (current.__swc_host) return current.__swc_host;
1398
1500
  if (getElementConfig(current)) return current;
1399
- current = current.parentElement || current?.getRootNode()?.host;
1501
+ current = current.parentElement || current.getRootNode?.()?.host;
1400
1502
  }
1401
1503
  return void 0;
1402
- }
1403
- /**
1404
- * Returns all SWC ancestors (excluding self) in [root, ..., parent] order.
1405
- */
1406
- static findAllSwcHosts(el) {
1504
+ };
1505
+ SwcUtils2.findAllSwcHosts = (el) => {
1407
1506
  const hosts = [];
1408
- let current = this.findNearestSwcHost(el);
1507
+ let current = (0, SwcUtils2.findNearestSwcHost)(el);
1409
1508
  while (current) {
1410
1509
  hosts.push(current);
1411
- current = this.findNearestSwcHost(current);
1510
+ current = (0, SwcUtils2.findNearestSwcHost)(current);
1412
1511
  }
1413
1512
  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);
1513
+ };
1514
+ SwcUtils2.getHosts = (el) => {
1515
+ const ancestors = (0, SwcUtils2.findAllSwcHosts)(el);
1516
+ if (getElementConfig(el)) return [...ancestors, el];
1517
+ return ancestors;
1518
+ };
1519
+ SwcUtils2.getHost = (el) => {
1520
+ if (getElementConfig(el)) return el;
1521
+ return (0, SwcUtils2.findNearestSwcHost)(el);
1522
+ };
1523
+ SwcUtils2.getAppHosts = (el) => {
1524
+ const hosts = (0, SwcUtils2.getHosts)(el);
1423
1525
  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);
1526
+ };
1527
+ SwcUtils2.getAppHost = (el) => {
1528
+ const appHosts = (0, SwcUtils2.getAppHosts)(el);
1427
1529
  const appHostsWithoutSelf = appHosts.filter((h) => h !== el);
1428
1530
  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;
1531
+ };
1532
+ SwcUtils2.getHostSet = (el) => {
1533
+ const isSwc = !!getElementConfig(el);
1534
+ const ancestors = (0, SwcUtils2.findAllSwcHosts)(el);
1535
+ let $host;
1536
+ let $parentHost;
1537
+ if (isSwc) {
1538
+ $host = el;
1539
+ $parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;
1540
+ } else {
1541
+ $host = ancestors.length > 0 ? ancestors[ancestors.length - 1] : el;
1542
+ $parentHost = ancestors.length > 1 ? ancestors[ancestors.length - 2] : null;
1543
+ }
1544
+ const $hosts = isSwc ? [...ancestors, el] : ancestors;
1545
+ const $firstHost = $hosts.length > 0 ? $hosts[0] : null;
1546
+ const loopContext = {};
1547
+ let curr = el;
1548
+ while (curr && curr !== document.documentElement) {
1549
+ if (curr.__swc_loop_context) {
1550
+ Object.assign(loopContext, curr.__swc_loop_context);
1551
+ }
1552
+ curr = curr.parentElement || curr.getRootNode().host;
1553
+ }
1436
1554
  const $appHosts = $hosts.filter((h) => h.tagName.toLowerCase() === "swc-app" || h.getAttribute("is")?.startsWith("swc-app-"));
1437
1555
  const $appHost = $appHosts.length > 0 ? $appHosts[$appHosts.length - 1] === el ? $appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null : $appHosts[$appHosts.length - 1] : null;
1438
1556
  const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;
@@ -1445,10 +1563,11 @@ var SwcUtils = class {
1445
1563
  $appHost,
1446
1564
  $appHosts,
1447
1565
  $firstAppHost,
1448
- $lastAppHost: $appHost
1566
+ $lastAppHost: $appHost,
1567
+ ...loopContext
1449
1568
  };
1450
- }
1451
- };
1569
+ };
1570
+ })(SwcUtils || (SwcUtils = {}));
1452
1571
 
1453
1572
  // src/config/config.ts
1454
1573
  var HTML_TAG_ENTRIES = [
@@ -1571,6 +1690,7 @@ var InjectSituationType = /* @__PURE__ */ ((InjectSituationType2) => {
1571
1690
 
1572
1691
  // src/decorators/elementDefine.ts
1573
1692
  var ELEMENT_CONFIG_KEY = Symbol("simple-web-component:element-config");
1693
+ var globalDelegatedRoots = /* @__PURE__ */ new WeakSet();
1574
1694
  function buildEnv(configWindow) {
1575
1695
  const win = configWindow || (typeof window !== "undefined" ? window : void 0);
1576
1696
  const doc = win?.document;
@@ -1579,13 +1699,7 @@ function buildEnv(configWindow) {
1579
1699
  if (win?.[cls])
1580
1700
  builtInTagMap.set(win[cls], tag);
1581
1701
  }
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
- };
1702
+ const domHelpers = SwcUtils.getHelperSet(win);
1589
1703
  return { win, doc, builtInTagMap, domHelpers };
1590
1704
  }
1591
1705
  var getHandlers = (inst) => {
@@ -1597,8 +1711,6 @@ var elementDefine = (inConfig) => (constructor) => {
1597
1711
  const config = typeof inConfig === "string" ? { name: inConfig } : inConfig;
1598
1712
  const { win, doc, builtInTagMap: BUILT_IN_TAG_MAP, domHelpers: SWC_DOM_HELPERS } = buildEnv(config.window);
1599
1713
  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
1714
  let extendsTagName = config.extends;
1603
1715
  if (!extendsTagName) {
1604
1716
  let proto = constructor;
@@ -1614,19 +1726,19 @@ var elementDefine = (inConfig) => (constructor) => {
1614
1726
  const addEventListenerList = getAddEventListenerMetadata(constructor) || [];
1615
1727
  const attrChangeMap = findAllAttributeChangedMetadata(constructor);
1616
1728
  const setAttrMap = findAllSetAttributeMetadata(constructor);
1729
+ const replaceChildrenMap = findAllReplaceChildrenMetadata(constructor);
1730
+ const appendChildMap = findAllAppendChildMetadata(constructor);
1617
1731
  const swcLifecycleAttributes = ["swc-on-constructor", "swc-on-connected", "swc-on-disconnected", "swc-on-before-connected", "swc-on-after-connected", "swc-on-before-disconnected", "swc-on-after-disconnected", "swc-on-before-adopted", "swc-on-after-adopted", "swc-on-attribute-changed"];
1618
1732
  const swcOnEvents = DOM_EVENT_NAMES.map((e) => `swc-on-${e}`);
1619
1733
  const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...config.observedAttributes ?? [], ...attrChangeMap.keys(), ...setAttrMap.keys(), ...emitCustomEventList.map((it) => it.options.attributeName), ...swcLifecycleAttributes, ...swcOnEvents])];
1620
- const innerHtmlList = getInnerHtmlMetadataList(constructor) || [];
1734
+ const connectedInnerHtmlList = getOnConnectedInnerHtmlMetadata(constructor) || [];
1621
1735
  const NewClass = class extends constructor {
1622
1736
  _executeSwcScript(attrName, hostSet, extraArgs = {}) {
1623
1737
  const script = this.getAttribute(attrName);
1624
1738
  if (script) {
1625
1739
  try {
1626
1740
  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);
1741
+ FunctionUtils.execute({ script, context: this, args });
1630
1742
  } catch (e) {
1631
1743
  console.error(`[SWC] Failed to execute ${attrName}:`, e);
1632
1744
  }
@@ -1668,9 +1780,13 @@ var elementDefine = (inConfig) => (constructor) => {
1668
1780
  el.removeEventListener(eventName, oldHandler);
1669
1781
  const handler = (event) => {
1670
1782
  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());
1783
+ const args = {
1784
+ event,
1785
+ $data: event.detail,
1786
+ ...hostSet,
1787
+ ...SWC_DOM_HELPERS
1788
+ };
1789
+ FunctionUtils.execute({ script, context: el, args });
1674
1790
  };
1675
1791
  el.addEventListener(eventName, handler);
1676
1792
  handlers.set(attrName, handler);
@@ -1679,9 +1795,10 @@ var elementDefine = (inConfig) => (constructor) => {
1679
1795
  super(...args);
1680
1796
  this._swcId = Math.random().toString(36).substring(2, 11);
1681
1797
  this._emitHandlers = /* @__PURE__ */ new Map();
1798
+ this._boundListeners = [];
1682
1799
  const hostSet = SwcUtils.getHostSet(this);
1683
1800
  this._executeSwcScript("swc-on-constructor", hostSet);
1684
- if (innerHtmlList.some((it) => it.options.useShadow === true) && !this.shadowRoot) {
1801
+ if (connectedInnerHtmlList.some((it) => it.options.useShadow === true) && !this.shadowRoot) {
1685
1802
  this.attachShadow({ mode: "open" });
1686
1803
  }
1687
1804
  }
@@ -1689,6 +1806,9 @@ var elementDefine = (inConfig) => (constructor) => {
1689
1806
  return mergedObservedAttributes;
1690
1807
  }
1691
1808
  async connectedCallback() {
1809
+ const conf = getElementConfig(this);
1810
+ const currentWin = conf?.window || window;
1811
+ const currentDoc = currentWin.document;
1692
1812
  const hostSet = SwcUtils.getHostSet(this);
1693
1813
  this._executeSwcScript("swc-on-before-connected", hostSet);
1694
1814
  const bMethods = findAllLifecycleMetadata(this, ON_BEFORE_CONNECTED_METADATA_KEY);
@@ -1698,9 +1818,9 @@ var elementDefine = (inConfig) => (constructor) => {
1698
1818
  }
1699
1819
  if (typeof this.initCore === "function")
1700
1820
  this.initCore();
1701
- if (innerHtmlList.length > 0) {
1821
+ if (connectedInnerHtmlList.length > 0) {
1702
1822
  let sContent = "", lContent = "";
1703
- for (const meta of innerHtmlList) {
1823
+ for (const meta of connectedInnerHtmlList) {
1704
1824
  const res = await this[meta.propertyKey]();
1705
1825
  if (res !== void 0) {
1706
1826
  if (meta.options.useShadow)
@@ -1714,17 +1834,88 @@ var elementDefine = (inConfig) => (constructor) => {
1714
1834
  if (lContent)
1715
1835
  this.innerHTML = lContent;
1716
1836
  }
1837
+ const createDelegationHandler = (delegateHost) => (event) => {
1838
+ if (event.__swc_handled)
1839
+ return;
1840
+ const path = event.composedPath();
1841
+ const type = event.type;
1842
+ const attrName = `swc-on-${type}`;
1843
+ for (const node of path) {
1844
+ if (node === delegateHost)
1845
+ break;
1846
+ if (!(node instanceof HTMLElement))
1847
+ continue;
1848
+ const script = node.getAttribute?.(attrName);
1849
+ if (script && !getElementConfig(node)) {
1850
+ const host = SwcUtils.findNearestSwcHost(node);
1851
+ if (host) {
1852
+ const childHostSet = SwcUtils.getHostSet(node);
1853
+ const args = {
1854
+ event,
1855
+ $data: event.detail,
1856
+ ...childHostSet,
1857
+ ...SWC_DOM_HELPERS
1858
+ };
1859
+ FunctionUtils.execute({ script, context: node, args });
1860
+ event.__swc_handled = true;
1861
+ break;
1862
+ }
1863
+ }
1864
+ }
1865
+ };
1866
+ DOM_EVENT_NAMES.forEach((type) => {
1867
+ const handler = createDelegationHandler(this);
1868
+ this.addEventListener(type, handler);
1869
+ this._boundListeners.push({ target: this, type, handler });
1870
+ });
1871
+ const hasParentHost = SwcUtils.findAllSwcHosts(this).length > 0;
1872
+ if (!hasParentHost) {
1873
+ const root = this.getRootNode();
1874
+ if (!globalDelegatedRoots.has(root)) {
1875
+ DOM_EVENT_NAMES.forEach((type) => {
1876
+ const handler = createDelegationHandler(root);
1877
+ root.addEventListener(type, handler);
1878
+ });
1879
+ globalDelegatedRoots.add(root);
1880
+ }
1881
+ }
1717
1882
  addEventListenerList.forEach((meta) => {
1718
1883
  const { selector, type, options } = meta;
1719
- const { root, capture, once, passive, stopPropagation, stopImmediatePropagation, preventDefault, delegate } = options;
1720
- if (delegate && selector && selector !== ":host") {
1884
+ const { root, capture, once, passive, stopPropagation, stopImmediatePropagation, preventDefault, delegate, removeOnDisconnected } = options;
1885
+ const opts = { capture, once, passive };
1886
+ const bindTargets = [];
1887
+ if (selector === ":window") {
1888
+ bindTargets.push(currentWin);
1889
+ } else if (selector === ":document") {
1890
+ bindTargets.push(currentDoc);
1891
+ } else if (selector === ":parentHost") {
1892
+ if (hostSet.$parentHost)
1893
+ bindTargets.push(hostSet.$parentHost);
1894
+ } else if (selector === ":appHost") {
1895
+ if (hostSet.$appHost)
1896
+ bindTargets.push(hostSet.$appHost);
1897
+ } else if (selector === ":firstHost") {
1898
+ if (hostSet.$firstHost)
1899
+ bindTargets.push(hostSet.$firstHost);
1900
+ } else if (selector === ":lastHost") {
1901
+ if (hostSet.$lastHost)
1902
+ bindTargets.push(hostSet.$lastHost);
1903
+ } else if (selector === ":firstAppHost") {
1904
+ if (hostSet.$firstAppHost)
1905
+ bindTargets.push(hostSet.$firstAppHost);
1906
+ } else if (selector === ":lastAppHost") {
1907
+ if (hostSet.$lastAppHost)
1908
+ bindTargets.push(hostSet.$lastAppHost);
1909
+ } else if (!selector || selector === ":host") {
1910
+ bindTargets.push(this);
1911
+ } else if (delegate) {
1721
1912
  const bindRoots = [];
1722
1913
  const r = root || "auto";
1723
- if (r === "auto") {
1914
+ if (r === "auto")
1724
1915
  bindRoots.push(this.shadowRoot || this);
1725
- } else if (r === "light") {
1916
+ else if (r === "light")
1726
1917
  bindRoots.push(this);
1727
- } else if (r === "shadow") {
1918
+ else if (r === "shadow") {
1728
1919
  if (this.shadowRoot)
1729
1920
  bindRoots.push(this.shadowRoot);
1730
1921
  } else if (r === "all") {
@@ -1732,62 +1923,61 @@ var elementDefine = (inConfig) => (constructor) => {
1732
1923
  if (this.shadowRoot)
1733
1924
  bindRoots.push(this.shadowRoot);
1734
1925
  }
1735
- bindRoots.forEach((bindRoot) => {
1926
+ bindRoots.forEach((br) => {
1736
1927
  const handler = (event) => {
1737
- const target = event.target;
1738
- const matchedEl = target.closest(selector);
1739
- if (matchedEl && bindRoot.contains(matchedEl)) {
1928
+ const matchedEl = event.target.closest(selector);
1929
+ if (matchedEl && br.contains(matchedEl)) {
1740
1930
  if (stopPropagation)
1741
1931
  event.stopPropagation();
1742
1932
  if (stopImmediatePropagation)
1743
1933
  event.stopImmediatePropagation();
1744
1934
  if (preventDefault)
1745
1935
  event.preventDefault();
1746
- const hostSet2 = SwcUtils.getHostSet(this);
1747
- this._invokeLifecycleMethod(meta.propertyKey, hostSet2, [event, hostSet2, matchedEl]);
1936
+ const currentHostSet = SwcUtils.getHostSet(this);
1937
+ this._invokeLifecycleMethod(meta.propertyKey, currentHostSet, [event, currentHostSet, matchedEl]);
1748
1938
  }
1749
1939
  };
1750
- bindRoot.addEventListener(type, handler, { capture, once, passive });
1940
+ br.addEventListener(type, handler, opts);
1941
+ const self2 = this;
1942
+ if (removeOnDisconnected === true || br !== self2 && br !== self2.shadowRoot) {
1943
+ this._boundListeners.push({ target: br, type, handler, options: opts });
1944
+ }
1751
1945
  });
1752
1946
  } 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
- });
1947
+ const searchRoots = [];
1948
+ const r = root || "auto";
1949
+ if (r === "auto")
1950
+ searchRoots.push(this.shadowRoot || this);
1951
+ else if (r === "light")
1952
+ searchRoots.push(this);
1953
+ else if (r === "shadow") {
1954
+ if (this.shadowRoot)
1955
+ searchRoots.push(this.shadowRoot);
1956
+ } else if (r === "all") {
1957
+ searchRoots.push(this);
1958
+ if (this.shadowRoot)
1959
+ searchRoots.push(this.shadowRoot);
1775
1960
  }
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);
1961
+ searchRoots.forEach((sr) => {
1962
+ sr.querySelectorAll(selector).forEach((el) => bindTargets.push(el));
1789
1963
  });
1790
1964
  }
1965
+ bindTargets.forEach((target) => {
1966
+ const handler = (event) => {
1967
+ if (stopPropagation)
1968
+ event.stopPropagation();
1969
+ if (stopImmediatePropagation)
1970
+ event.stopImmediatePropagation();
1971
+ if (preventDefault)
1972
+ event.preventDefault();
1973
+ const currentHostSet = SwcUtils.getHostSet(this);
1974
+ this._invokeLifecycleMethod(meta.propertyKey, currentHostSet, [event, currentHostSet]);
1975
+ };
1976
+ target.addEventListener(type, handler, opts);
1977
+ if (removeOnDisconnected === true || target === currentWin || target === currentDoc) {
1978
+ this._boundListeners.push({ target, type, handler, options: opts });
1979
+ }
1980
+ });
1791
1981
  });
1792
1982
  if (super.connectedCallback)
1793
1983
  await super.connectedCallback();
@@ -1805,6 +1995,8 @@ var elementDefine = (inConfig) => (constructor) => {
1805
1995
  const bMethods = findAllLifecycleMetadata(this, ON_BEFORE_DISCONNECTED_METADATA_KEY);
1806
1996
  if (bMethods)
1807
1997
  bMethods.forEach((m) => this._invokeLifecycleMethod(m, hostSet));
1998
+ this._boundListeners.forEach((l) => l.target.removeEventListener(l.type, l.handler, l.options));
1999
+ this._boundListeners = [];
1808
2000
  if (super.disconnectedCallback)
1809
2001
  super.disconnectedCallback();
1810
2002
  const aMethods = findAllLifecycleMetadata(this, ON_AFTER_DISCONNECTED_METADATA_KEY);
@@ -1876,6 +2068,79 @@ var elementDefine = (inConfig) => (constructor) => {
1876
2068
  };
1877
2069
  }
1878
2070
  });
2071
+ replaceChildrenMap.forEach((selector, methodName) => {
2072
+ const original = NewClass.prototype[methodName];
2073
+ if (typeof original === "function") {
2074
+ NewClass.prototype[methodName] = function(...args) {
2075
+ const res = original.apply(this, args);
2076
+ if (res !== void 0) {
2077
+ const conf = getElementConfig(this);
2078
+ const currentWin = conf?.window || window;
2079
+ const currentDoc = currentWin.document;
2080
+ let targetEl = null;
2081
+ if (selector === ":host" || !selector) {
2082
+ targetEl = this;
2083
+ } else {
2084
+ targetEl = (this.shadowRoot || this).querySelector(selector);
2085
+ }
2086
+ if (targetEl) {
2087
+ const nodes = Array.isArray(res) ? res : [res];
2088
+ const normalizedNodes = nodes.map((n) => {
2089
+ if (typeof n === "string") {
2090
+ const t = currentDoc.createElement("template");
2091
+ t.innerHTML = n;
2092
+ return t.content;
2093
+ }
2094
+ return n;
2095
+ });
2096
+ targetEl.replaceChildren(...normalizedNodes);
2097
+ }
2098
+ }
2099
+ return res;
2100
+ };
2101
+ }
2102
+ });
2103
+ appendChildMap.forEach((meta, methodName) => {
2104
+ const { selector, options } = meta;
2105
+ const original = NewClass.prototype[methodName];
2106
+ if (typeof original === "function") {
2107
+ NewClass.prototype[methodName] = function(...args) {
2108
+ const res = original.apply(this, args);
2109
+ if (res !== void 0) {
2110
+ const conf = getElementConfig(this);
2111
+ const currentWin = conf?.window || window;
2112
+ const currentDoc = currentWin.document;
2113
+ let targetEl = null;
2114
+ if (selector === ":host" || !selector) {
2115
+ targetEl = this;
2116
+ } else {
2117
+ targetEl = (this.shadowRoot || this).querySelector(selector);
2118
+ }
2119
+ if (targetEl) {
2120
+ const nodes = Array.isArray(res) ? res : [res];
2121
+ const normalizedNodes = nodes.map((n) => {
2122
+ if (typeof n === "string") {
2123
+ const t = currentDoc.createElement("template");
2124
+ t.innerHTML = n;
2125
+ return t.content;
2126
+ }
2127
+ return n;
2128
+ });
2129
+ const pos = options.position || "lastChild";
2130
+ if (pos === "lastChild")
2131
+ targetEl.append(...normalizedNodes);
2132
+ else if (pos === "firstChild")
2133
+ targetEl.prepend(...normalizedNodes);
2134
+ else if (pos === "nextSibling")
2135
+ targetEl.after(...normalizedNodes);
2136
+ else if (pos === "previousSibling")
2137
+ targetEl.before(...normalizedNodes);
2138
+ }
2139
+ }
2140
+ return res;
2141
+ };
2142
+ }
2143
+ });
1879
2144
  const originalProto = constructor.prototype;
1880
2145
  const newProto = NewClass.prototype;
1881
2146
  Object.getOwnPropertyNames(originalProto).forEach((name) => {
@@ -1913,6 +2178,26 @@ function query(selector, options = {}) {
1913
2178
  queries.push({ selector, options, propertyKey });
1914
2179
  Object.defineProperty(target, propertyKey, {
1915
2180
  get() {
2181
+ const hostSet = SwcUtils.getHostSet(this);
2182
+ if (selector === ":parentHost")
2183
+ return hostSet.$parentHost;
2184
+ if (selector === ":appHost")
2185
+ return hostSet.$appHost;
2186
+ if (selector === ":firstHost")
2187
+ return hostSet.$firstHost;
2188
+ if (selector === ":lastHost")
2189
+ return hostSet.$lastHost;
2190
+ if (selector === ":firstAppHost")
2191
+ return hostSet.$firstAppHost;
2192
+ if (selector === ":lastAppHost")
2193
+ return hostSet.$lastAppHost;
2194
+ const config = getElementConfig(this);
2195
+ const win = config?.window || window;
2196
+ const doc = win.document;
2197
+ if (selector === ":window")
2198
+ return win;
2199
+ if (selector === ":document")
2200
+ return doc;
1916
2201
  if (!selector || selector === ":host")
1917
2202
  return this;
1918
2203
  const r = options.root || "auto";
@@ -1927,6 +2212,22 @@ function query(selector, options = {}) {
1927
2212
  }
1928
2213
  return (this.shadowRoot || this).querySelector(selector);
1929
2214
  },
2215
+ set(nv) {
2216
+ if (nv === null || nv === void 0) {
2217
+ const r = options.root || "auto";
2218
+ let targetEl = null;
2219
+ if (r === "shadow")
2220
+ targetEl = this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;
2221
+ else if (r === "light")
2222
+ targetEl = this.querySelector(selector);
2223
+ else if (r === "all")
2224
+ targetEl = this.shadowRoot?.querySelector(selector) || this.querySelector(selector);
2225
+ else
2226
+ targetEl = (this.shadowRoot || this).querySelector(selector);
2227
+ if (targetEl)
2228
+ targetEl.remove();
2229
+ }
2230
+ },
1930
2231
  enumerable: true,
1931
2232
  configurable: true
1932
2233
  });
@@ -1953,6 +2254,18 @@ function queryAll(selector, options = {}) {
1953
2254
  queries.push({ selector, options, propertyKey });
1954
2255
  Object.defineProperty(target, propertyKey, {
1955
2256
  get() {
2257
+ const hostSet = SwcUtils.getHostSet(this);
2258
+ if (selector === ":hosts")
2259
+ return hostSet.$hosts;
2260
+ if (selector === ":appHosts")
2261
+ return hostSet.$appHosts;
2262
+ const config = getElementConfig(this);
2263
+ const win = config?.window || window;
2264
+ const doc = win.document;
2265
+ if (selector === ":window")
2266
+ return [win];
2267
+ if (selector === ":document")
2268
+ return [doc];
1956
2269
  if (!selector || selector === ":host")
1957
2270
  return [this];
1958
2271
  const r = options.root || "auto";
@@ -1970,6 +2283,24 @@ function queryAll(selector, options = {}) {
1970
2283
  const root = this.shadowRoot || this;
1971
2284
  return root.querySelectorAll(selector);
1972
2285
  },
2286
+ set(nv) {
2287
+ if (nv === null || nv === void 0 || Array.isArray(nv) && nv.length === 0) {
2288
+ const r = options.root || "auto";
2289
+ let targets = [];
2290
+ if (r === "shadow")
2291
+ targets = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];
2292
+ else if (r === "light")
2293
+ targets = Array.from(this.querySelectorAll(selector));
2294
+ else if (r === "all") {
2295
+ const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];
2296
+ const lNodes = Array.from(this.querySelectorAll(selector));
2297
+ targets = [...sNodes, ...lNodes];
2298
+ } else {
2299
+ targets = Array.from((this.shadowRoot || this).querySelectorAll(selector));
2300
+ }
2301
+ targets.forEach((t) => t.remove());
2302
+ }
2303
+ },
1973
2304
  enumerable: true,
1974
2305
  configurable: true
1975
2306
  });
@@ -7597,7 +7928,7 @@ var SwcAppEngine = class {
7597
7928
  const configStr = this.host.getAttribute("swc-get-application-config");
7598
7929
  if (!configStr) return;
7599
7930
  try {
7600
- const userConfig = new Function(`return ${configStr}`).apply(this.host);
7931
+ const userConfig = FunctionUtils.executeReturn({ script: configStr, context: this.host });
7601
7932
  if (userConfig && userConfig.rootRouter) {
7602
7933
  const _config = {
7603
7934
  routeType: "element",
@@ -9461,8 +9792,735 @@ var SwcAppBody = class SwcAppBody2 extends HTMLBodyElement {
9461
9792
  SwcAppBody = __decorate57([
9462
9793
  elementDefine({ name: "swc-app-body", extends: "body" })
9463
9794
  ], SwcAppBody);
9795
+
9796
+ // src/elements/SwcSubTemplates.ts
9797
+ var __decorate58 = function(decorators, target, key, desc) {
9798
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9799
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
9800
+ 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;
9801
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
9802
+ };
9803
+ var SwcLoading = class SwcLoading2 extends HTMLTemplateElement {
9804
+ };
9805
+ SwcLoading = __decorate58([
9806
+ elementDefine({ name: "swc-loading", extends: "template" })
9807
+ ], SwcLoading);
9808
+ var SwcError = class SwcError2 extends HTMLTemplateElement {
9809
+ };
9810
+ SwcError = __decorate58([
9811
+ elementDefine({ name: "swc-error", extends: "template" })
9812
+ ], SwcError);
9813
+ var SwcSuccess = class SwcSuccess2 extends HTMLTemplateElement {
9814
+ };
9815
+ SwcSuccess = __decorate58([
9816
+ elementDefine({ name: "swc-success", extends: "template" })
9817
+ ], SwcSuccess);
9818
+ var SwcWhen = class SwcWhen2 extends HTMLTemplateElement {
9819
+ };
9820
+ SwcWhen = __decorate58([
9821
+ elementDefine({ name: "swc-when", extends: "template" })
9822
+ ], SwcWhen);
9823
+ var SwcOtherwise = class SwcOtherwise2 extends HTMLTemplateElement {
9824
+ };
9825
+ SwcOtherwise = __decorate58([
9826
+ elementDefine({ name: "swc-otherwise", extends: "template" })
9827
+ ], SwcOtherwise);
9828
+ var SwcDefault = class SwcDefault2 extends HTMLTemplateElement {
9829
+ };
9830
+ SwcDefault = __decorate58([
9831
+ elementDefine({ name: "swc-default", extends: "template" })
9832
+ ], SwcDefault);
9833
+
9834
+ // src/elements/SwcLoop.ts
9835
+ var __decorate59 = function(decorators, target, key, desc) {
9836
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9837
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
9838
+ 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;
9839
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
9840
+ };
9841
+ var __metadata = function(k, v) {
9842
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9843
+ };
9844
+ var SwcLoop = class SwcLoop2 extends HTMLTemplateElement {
9845
+ constructor() {
9846
+ super(...arguments);
9847
+ this._value = [];
9848
+ this._nodes = [];
9849
+ this._defaultNodes = [];
9850
+ }
9851
+ get value() {
9852
+ return this._value;
9853
+ }
9854
+ set value(nv) {
9855
+ this._value = Array.isArray(nv) ? [...nv] : [];
9856
+ this.render();
9857
+ }
9858
+ getNodes(index) {
9859
+ return this._nodes[index] || null;
9860
+ }
9861
+ _getTarget() {
9862
+ const script = this.getAttribute("on-get-portal");
9863
+ if (!script)
9864
+ return null;
9865
+ try {
9866
+ const res = FunctionUtils.executeReturn({
9867
+ script,
9868
+ context: this,
9869
+ args: SwcUtils.getHelperAndHostSet(window, this)
9870
+ });
9871
+ if (typeof res === "string")
9872
+ return document.querySelector(res);
9873
+ if (res instanceof Node)
9874
+ return res;
9875
+ } catch (e) {
9876
+ console.error("[SwcLoop] Portal target error:", e);
9877
+ }
9878
+ return null;
9879
+ }
9880
+ append(...items) {
9881
+ if (!items.length || !this.parentElement)
9882
+ return;
9883
+ if (this._defaultNodes.length > 0)
9884
+ this._cleanupDefault();
9885
+ const fragment = document.createDocumentFragment();
9886
+ const startIndex = this._value.length;
9887
+ items.forEach((item, i) => {
9888
+ const index = startIndex + i;
9889
+ const nodes = this._createItemNodes(item, index);
9890
+ if (nodes) {
9891
+ this._nodes.push(nodes);
9892
+ nodes.forEach((n) => fragment.appendChild(n));
9893
+ this._value.push(item);
9894
+ } else {
9895
+ this._nodes.push(null);
9896
+ this._value.push(null);
9897
+ }
9898
+ });
9899
+ const target = this._getTarget();
9900
+ if (target) {
9901
+ target.appendChild(fragment);
9902
+ } else {
9903
+ const lastValidIdx = this._nodes.length - items.length - 1;
9904
+ let refNode = this;
9905
+ for (let i = lastValidIdx; i >= 0; i--) {
9906
+ const group = this._nodes[i];
9907
+ if (group && group.length > 0) {
9908
+ refNode = group[group.length - 1];
9909
+ break;
9910
+ }
9911
+ }
9912
+ this.parentElement.insertBefore(fragment, refNode.nextSibling);
9913
+ }
9914
+ }
9915
+ remove(index) {
9916
+ const targetIdx = index !== void 0 ? index : this._nodes.length - 1;
9917
+ if (targetIdx < 0 || targetIdx >= this._nodes.length)
9918
+ return;
9919
+ const nodes = this._nodes[targetIdx];
9920
+ if (nodes) {
9921
+ nodes.forEach((n) => {
9922
+ if (n.parentElement)
9923
+ n.parentElement.removeChild(n);
9924
+ });
9925
+ this._nodes[targetIdx] = null;
9926
+ this._value[targetIdx] = null;
9927
+ }
9928
+ const activeRows = this._value.filter((v) => v !== null);
9929
+ if (activeRows.length === 0) {
9930
+ this.render();
9931
+ }
9932
+ }
9933
+ _createItemNodes(item, index) {
9934
+ const clone = this.content.cloneNode(true);
9935
+ Array.from(clone.querySelectorAll('template[is="swc-default"]')).forEach((t) => t.remove());
9936
+ const nodes = Array.from(clone.childNodes);
9937
+ const elements = nodes.filter((n) => n.nodeType === 1);
9938
+ const groupCtx = {
9939
+ $index: index,
9940
+ $item: item,
9941
+ $nodes: nodes,
9942
+ $elements: elements,
9943
+ $firstNode: nodes[0],
9944
+ $lastNode: nodes[nodes.length - 1],
9945
+ $firstElement: elements[0],
9946
+ $lastElement: elements[elements.length - 1],
9947
+ $isFirst: index === 0,
9948
+ $isLast: index === this._value.length - 1,
9949
+ $isEven: index % 2 === 0,
9950
+ $isOdd: index % 2 !== 0,
9951
+ $count: this._value.length
9952
+ };
9953
+ this._executeCallback("on-clone-nodes", groupCtx);
9954
+ nodes.forEach((node, nodeIndex) => {
9955
+ if (node instanceof HTMLElement)
9956
+ node.__swc_host = this;
9957
+ this._executeCallback("on-clone-node", { ...groupCtx, $node: node, $nodeIndex: nodeIndex, $isElement: node.nodeType === 1 });
9958
+ });
9959
+ return nodes;
9960
+ }
9961
+ _executeCallback(attrName, extraArgs) {
9962
+ const script = this.getAttribute(attrName);
9963
+ if (!script)
9964
+ return;
9965
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
9966
+ try {
9967
+ FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
9968
+ } catch (e) {
9969
+ console.error(`[SwcLoop] Error in ${attrName}:`, e);
9970
+ }
9971
+ }
9972
+ refreshValue(newValue) {
9973
+ const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
9974
+ if (!script) {
9975
+ this.value = [];
9976
+ return;
9977
+ }
9978
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
9979
+ try {
9980
+ const res = FunctionUtils.executeReturn({ script, context: this, args: helperHostSet });
9981
+ if (Array.isArray(res)) {
9982
+ this.value = res;
9983
+ }
9984
+ } catch (e) {
9985
+ console.error("[SwcLoop] Failed to get value from on-get-value script:", e);
9986
+ this.value = [];
9987
+ }
9988
+ }
9989
+ render() {
9990
+ this._cleanup();
9991
+ if (!this.parentElement)
9992
+ return;
9993
+ const activeRows = this._value.filter((v) => v !== null);
9994
+ const target = this._getTarget();
9995
+ if (activeRows.length === 0) {
9996
+ const t = this.content.querySelector('template[is="swc-default"]');
9997
+ if (t) {
9998
+ const clone = t.content.cloneNode(true);
9999
+ this._defaultNodes = Array.from(clone.childNodes);
10000
+ this._defaultNodes.forEach((n) => {
10001
+ if (n instanceof HTMLElement)
10002
+ n.__swc_host = this;
10003
+ });
10004
+ if (target)
10005
+ target.appendChild(clone);
10006
+ else
10007
+ this.parentElement.insertBefore(clone, this.nextSibling);
10008
+ }
10009
+ return;
10010
+ }
10011
+ const fragment = document.createDocumentFragment();
10012
+ this._value.forEach((item, index) => {
10013
+ if (item === null) {
10014
+ this._nodes.push(null);
10015
+ return;
10016
+ }
10017
+ const nodes = this._createItemNodes(item, index);
10018
+ this._nodes.push(nodes);
10019
+ nodes.forEach((n) => fragment.appendChild(n));
10020
+ });
10021
+ if (target)
10022
+ target.appendChild(fragment);
10023
+ else
10024
+ this.parentElement.insertBefore(fragment, this.nextSibling);
10025
+ }
10026
+ _cleanup() {
10027
+ this._nodes.forEach((group) => {
10028
+ if (group)
10029
+ group.forEach((node) => node.parentElement?.removeChild(node));
10030
+ });
10031
+ this._nodes = [];
10032
+ this._cleanupDefault();
10033
+ }
10034
+ _cleanupDefault() {
10035
+ this._defaultNodes.forEach((n) => n.parentElement?.removeChild(n));
10036
+ this._defaultNodes = [];
10037
+ }
10038
+ connectedCallback() {
10039
+ this.refreshValue();
10040
+ }
10041
+ disconnectedCallback() {
10042
+ this._cleanup();
10043
+ }
10044
+ };
10045
+ __decorate59([
10046
+ changedAttribute("on-get-value"),
10047
+ __metadata("design:type", Function),
10048
+ __metadata("design:paramtypes", [String]),
10049
+ __metadata("design:returntype", void 0)
10050
+ ], SwcLoop.prototype, "refreshValue", null);
10051
+ SwcLoop = __decorate59([
10052
+ elementDefine({ name: "swc-loop", extends: "template" })
10053
+ ], SwcLoop);
10054
+
10055
+ // src/elements/SwcIf.ts
10056
+ var __decorate60 = function(decorators, target, key, desc) {
10057
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10058
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10059
+ 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;
10060
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
10061
+ };
10062
+ var __metadata2 = function(k, v) {
10063
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10064
+ };
10065
+ var SwcIf = class SwcIf2 extends HTMLTemplateElement {
10066
+ constructor() {
10067
+ super(...arguments);
10068
+ this._nodes = [];
10069
+ this._value = null;
10070
+ }
10071
+ get value() {
10072
+ return this._value;
10073
+ }
10074
+ set value(nv) {
10075
+ this._value = nv;
10076
+ this.render();
10077
+ }
10078
+ _getTarget() {
10079
+ const script = this.getAttribute("on-get-portal");
10080
+ if (!script)
10081
+ return null;
10082
+ try {
10083
+ const res = FunctionUtils.executeReturn({
10084
+ script,
10085
+ context: this,
10086
+ args: SwcUtils.getHelperAndHostSet(window, this)
10087
+ });
10088
+ if (typeof res === "string")
10089
+ return document.querySelector(res);
10090
+ if (res instanceof Node)
10091
+ return res;
10092
+ } catch (e) {
10093
+ console.error("[SwcIf] Portal target error:", e);
10094
+ }
10095
+ return null;
10096
+ }
10097
+ _executeCallback(attrName, extraArgs) {
10098
+ const script = this.getAttribute(attrName);
10099
+ if (!script)
10100
+ return;
10101
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
10102
+ try {
10103
+ FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
10104
+ } catch (e) {
10105
+ console.error(`[SwcIf] Error in ${attrName}:`, e);
10106
+ }
10107
+ }
10108
+ refresh(newValue) {
10109
+ const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
10110
+ if (!script) {
10111
+ this.value = null;
10112
+ return;
10113
+ }
10114
+ if (!this.parentElement)
10115
+ return;
10116
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
10117
+ try {
10118
+ const result = FunctionUtils.executeReturn({
10119
+ script,
10120
+ context: this,
10121
+ args: helperHostSet
10122
+ });
10123
+ this.value = result;
10124
+ } catch (e) {
10125
+ console.error("[SwcIf] Error in on-get-value:", e);
10126
+ this.value = null;
10127
+ }
10128
+ }
10129
+ render() {
10130
+ this.cleanup();
10131
+ if (!this.parentElement)
10132
+ return;
10133
+ let fragment = null;
10134
+ const ctx = { $value: this._value, $nodes: [], $elements: [] };
10135
+ if (this._value) {
10136
+ const clone = this.content.cloneNode(true);
10137
+ Array.from(clone.querySelectorAll('template[is="swc-default"]')).forEach((t) => t.remove());
10138
+ fragment = clone;
10139
+ } else {
10140
+ const t = this.content.querySelector('template[is="swc-default"]');
10141
+ if (t)
10142
+ fragment = t.content.cloneNode(true);
10143
+ }
10144
+ if (fragment) {
10145
+ this.mount(fragment, ctx);
10146
+ }
10147
+ }
10148
+ mount(fragment, ctx) {
10149
+ const nodes = Array.from(fragment.childNodes);
10150
+ const elements = nodes.filter((n) => n.nodeType === 1);
10151
+ Object.assign(ctx, {
10152
+ $nodes: nodes,
10153
+ $elements: elements,
10154
+ $firstNode: nodes[0],
10155
+ $lastNode: nodes[nodes.length - 1],
10156
+ $firstElement: elements[0],
10157
+ $lastElement: elements[elements.length - 1]
10158
+ });
10159
+ this._executeCallback("on-clone-nodes", ctx);
10160
+ nodes.forEach((node, nodeIndex) => {
10161
+ if (node instanceof HTMLElement)
10162
+ node.__swc_host = this;
10163
+ this._executeCallback("on-clone-node", { ...ctx, $node: node, $nodeIndex: nodeIndex, $isElement: node.nodeType === 1 });
10164
+ });
10165
+ this._nodes = nodes;
10166
+ const target = this._getTarget();
10167
+ if (target) {
10168
+ target.appendChild(fragment);
10169
+ } else {
10170
+ this.parentElement?.insertBefore(fragment, this.nextSibling);
10171
+ }
10172
+ }
10173
+ cleanup() {
10174
+ this._nodes.forEach((n) => {
10175
+ if (n.parentElement)
10176
+ n.parentElement.removeChild(n);
10177
+ });
10178
+ this._nodes = [];
10179
+ }
10180
+ connectedCallback() {
10181
+ this.refresh();
10182
+ }
10183
+ disconnectedCallback() {
10184
+ this.cleanup();
10185
+ }
10186
+ };
10187
+ __decorate60([
10188
+ changedAttribute("on-get-value"),
10189
+ __metadata2("design:type", Function),
10190
+ __metadata2("design:paramtypes", [String]),
10191
+ __metadata2("design:returntype", void 0)
10192
+ ], SwcIf.prototype, "refresh", null);
10193
+ SwcIf = __decorate60([
10194
+ elementDefine({ name: "swc-if", extends: "template" })
10195
+ ], SwcIf);
10196
+
10197
+ // src/elements/SwcChoose.ts
10198
+ var __decorate61 = function(decorators, target, key, desc) {
10199
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10200
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10201
+ 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;
10202
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
10203
+ };
10204
+ var __metadata3 = function(k, v) {
10205
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10206
+ };
10207
+ var SwcChoose = class SwcChoose2 extends HTMLTemplateElement {
10208
+ constructor() {
10209
+ super(...arguments);
10210
+ this._nodes = [];
10211
+ this._value = null;
10212
+ }
10213
+ get value() {
10214
+ return this._value;
10215
+ }
10216
+ set value(nv) {
10217
+ this._value = nv;
10218
+ this.render();
10219
+ }
10220
+ _executeCallback(attrName, extraArgs) {
10221
+ const script = this.getAttribute(attrName);
10222
+ if (!script)
10223
+ return;
10224
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
10225
+ try {
10226
+ FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
10227
+ } catch (e) {
10228
+ console.error(`[SwcChoose] Error in ${attrName}:`, e);
10229
+ }
10230
+ }
10231
+ refresh(newValue) {
10232
+ const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
10233
+ if (!script) {
10234
+ this.value = null;
10235
+ return;
10236
+ }
10237
+ if (!this.parentElement)
10238
+ return;
10239
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
10240
+ try {
10241
+ const result = FunctionUtils.executeReturn({
10242
+ script,
10243
+ context: this,
10244
+ args: helperHostSet
10245
+ });
10246
+ this.value = result;
10247
+ } catch (e) {
10248
+ console.error("[SwcChoose] Error in on-get-value:", e);
10249
+ }
10250
+ }
10251
+ render() {
10252
+ this.cleanup();
10253
+ if (!this.parentElement)
10254
+ return;
10255
+ const templates = Array.from(this.content.querySelectorAll("template"));
10256
+ let selected = null;
10257
+ let otherwise = null;
10258
+ let defaultTmp = null;
10259
+ for (const t of templates) {
10260
+ const is = t.getAttribute("is");
10261
+ if (is === "swc-when") {
10262
+ const whenVal = t.getAttribute("value");
10263
+ if (String(whenVal) === String(this._value)) {
10264
+ selected = t;
10265
+ break;
10266
+ }
10267
+ } else if (is === "swc-otherwise") {
10268
+ otherwise = t;
10269
+ } else if (is === "swc-default") {
10270
+ defaultTmp = t;
10271
+ }
10272
+ }
10273
+ const targetTemplate = (this._value == null ? defaultTmp : selected) || otherwise || defaultTmp;
10274
+ if (targetTemplate) {
10275
+ const clone = targetTemplate.content.cloneNode(true);
10276
+ const nodes = Array.from(clone.childNodes);
10277
+ const elements = nodes.filter((n) => n.nodeType === 1);
10278
+ const ctx = {
10279
+ $value: this._value,
10280
+ $nodes: nodes,
10281
+ $elements: elements,
10282
+ $firstNode: nodes[0],
10283
+ $lastNode: nodes[nodes.length - 1],
10284
+ $firstElement: elements[0],
10285
+ $lastElement: elements[elements.length - 1]
10286
+ };
10287
+ this._executeCallback("on-clone-nodes", ctx);
10288
+ nodes.forEach((node, nodeIndex) => {
10289
+ if (node instanceof HTMLElement) {
10290
+ node.__swc_host = this;
10291
+ }
10292
+ this._executeCallback("on-clone-node", {
10293
+ ...ctx,
10294
+ $node: node,
10295
+ $nodeIndex: nodeIndex,
10296
+ $isElement: node.nodeType === 1
10297
+ });
10298
+ });
10299
+ this._nodes = nodes;
10300
+ this.parentElement.insertBefore(clone, this.nextSibling);
10301
+ }
10302
+ }
10303
+ cleanup() {
10304
+ this._nodes.forEach((n) => {
10305
+ if (n.parentElement)
10306
+ n.parentElement.removeChild(n);
10307
+ });
10308
+ this._nodes = [];
10309
+ }
10310
+ connectedCallback() {
10311
+ this.refresh();
10312
+ }
10313
+ disconnectedCallback() {
10314
+ this.cleanup();
10315
+ }
10316
+ };
10317
+ __decorate61([
10318
+ changedAttribute("on-get-value"),
10319
+ __metadata3("design:type", Function),
10320
+ __metadata3("design:paramtypes", [String]),
10321
+ __metadata3("design:returntype", void 0)
10322
+ ], SwcChoose.prototype, "refresh", null);
10323
+ SwcChoose = __decorate61([
10324
+ elementDefine({ name: "swc-choose", extends: "template" })
10325
+ ], SwcChoose);
10326
+
10327
+ // src/elements/SwcAsync.ts
10328
+ var __decorate62 = function(decorators, target, key, desc) {
10329
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10330
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10331
+ 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;
10332
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
10333
+ };
10334
+ var __metadata4 = function(k, v) {
10335
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10336
+ };
10337
+ var SwcAsync = class SwcAsync2 extends HTMLTemplateElement {
10338
+ constructor() {
10339
+ super(...arguments);
10340
+ this._nodes = [];
10341
+ this._currentPromise = null;
10342
+ this._value = null;
10343
+ }
10344
+ get value() {
10345
+ return this._value;
10346
+ }
10347
+ set value(nv) {
10348
+ if (nv instanceof Promise) {
10349
+ this.handlePromise(nv);
10350
+ } else {
10351
+ this._value = nv;
10352
+ this.render(nv === null ? "default" : "success", nv);
10353
+ }
10354
+ }
10355
+ refresh(newValue) {
10356
+ const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
10357
+ if (!script) {
10358
+ this.value = null;
10359
+ return;
10360
+ }
10361
+ if (!this.parentElement)
10362
+ return;
10363
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
10364
+ try {
10365
+ const result = FunctionUtils.executeReturn({
10366
+ script,
10367
+ context: this,
10368
+ args: helperHostSet
10369
+ });
10370
+ if (result instanceof Promise) {
10371
+ this.handlePromise(result);
10372
+ } else {
10373
+ this.value = result;
10374
+ }
10375
+ } catch (e) {
10376
+ this.render("error", e);
10377
+ }
10378
+ }
10379
+ async handlePromise(promise) {
10380
+ this._currentPromise = promise;
10381
+ this.render("loading");
10382
+ try {
10383
+ const result = await promise;
10384
+ if (this._currentPromise !== promise)
10385
+ return;
10386
+ this._value = result;
10387
+ this.render("success", result);
10388
+ } catch (e) {
10389
+ if (this._currentPromise !== promise)
10390
+ return;
10391
+ this.render("error", e);
10392
+ }
10393
+ }
10394
+ render(state, data) {
10395
+ this.cleanup();
10396
+ if (!this.parentElement)
10397
+ return;
10398
+ let fragment;
10399
+ const ctx = {
10400
+ $nodes: [],
10401
+ $elements: [],
10402
+ $state: state,
10403
+ $value: null,
10404
+ $error: null
10405
+ };
10406
+ if (state === "default") {
10407
+ const t = this.content.querySelector('template[is="swc-default"]');
10408
+ fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
10409
+ } else if (state === "loading") {
10410
+ const t = this.content.querySelector('template[is="swc-loading"]');
10411
+ fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
10412
+ } else if (state === "error") {
10413
+ const t = this.content.querySelector('template[is="swc-error"]');
10414
+ ctx.$error = data;
10415
+ fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
10416
+ } else {
10417
+ const t = this.content.querySelector('template[is="swc-success"]');
10418
+ ctx.$value = data;
10419
+ if (t) {
10420
+ fragment = t.content.cloneNode(true);
10421
+ } else {
10422
+ const clone = this.content.cloneNode(true);
10423
+ Array.from(clone.querySelectorAll('template[is="swc-loading"], template[is="swc-error"], template[is="swc-success"], template[is="swc-default"]')).forEach((tmp) => tmp.remove());
10424
+ fragment = clone;
10425
+ }
10426
+ }
10427
+ this.mount(fragment, ctx);
10428
+ }
10429
+ mount(fragment, ctx) {
10430
+ const nodes = Array.from(fragment.childNodes);
10431
+ const elements = nodes.filter((n) => n.nodeType === 1);
10432
+ Object.assign(ctx, {
10433
+ $nodes: nodes,
10434
+ $elements: elements,
10435
+ $firstNode: nodes[0],
10436
+ $lastNode: nodes[nodes.length - 1],
10437
+ $firstElement: elements[0],
10438
+ $lastElement: elements[elements.length - 1]
10439
+ });
10440
+ this._executeCallback("on-clone-nodes", ctx);
10441
+ nodes.forEach((node, nodeIndex) => {
10442
+ if (node instanceof HTMLElement) {
10443
+ node.__swc_host = this;
10444
+ }
10445
+ this._executeCallback("on-clone-node", {
10446
+ ...ctx,
10447
+ $node: node,
10448
+ $nodeIndex: nodeIndex,
10449
+ $isElement: node.nodeType === 1
10450
+ });
10451
+ });
10452
+ this._nodes = nodes;
10453
+ this.parentElement?.insertBefore(fragment, this.nextSibling);
10454
+ }
10455
+ _executeCallback(attrName, extraArgs) {
10456
+ const script = this.getAttribute(attrName);
10457
+ if (!script)
10458
+ return;
10459
+ const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);
10460
+ try {
10461
+ FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
10462
+ } catch (e) {
10463
+ console.error(`[SwcAsync] Error in ${attrName}:`, e);
10464
+ }
10465
+ }
10466
+ cleanup() {
10467
+ this._nodes.forEach((n) => {
10468
+ if (n.parentElement)
10469
+ n.parentElement.removeChild(n);
10470
+ });
10471
+ this._nodes = [];
10472
+ }
10473
+ connectedCallback() {
10474
+ this.refresh();
10475
+ }
10476
+ disconnectedCallback() {
10477
+ this.cleanup();
10478
+ }
10479
+ };
10480
+ __decorate62([
10481
+ changedAttribute("on-get-value"),
10482
+ __metadata4("design:type", Function),
10483
+ __metadata4("design:paramtypes", [String]),
10484
+ __metadata4("design:returntype", void 0)
10485
+ ], SwcAsync.prototype, "refresh", null);
10486
+ SwcAsync = __decorate62([
10487
+ elementDefine({ name: "swc-async", extends: "template" })
10488
+ ], SwcAsync);
10489
+
10490
+ // src/elements/SwcApp.ts
10491
+ var __decorate63 = function(decorators, target, key, desc) {
10492
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10493
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10494
+ 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;
10495
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
10496
+ };
10497
+ var SwcApp = class SwcApp2 extends HTMLElement {
10498
+ constructor() {
10499
+ super(...arguments);
10500
+ this._engine = new SwcAppEngine(this);
10501
+ }
10502
+ get simpleApplication() {
10503
+ return this._engine.simpleApplication;
10504
+ }
10505
+ get router() {
10506
+ return this._engine.router;
10507
+ }
10508
+ connectedCallback() {
10509
+ this._engine.connect();
10510
+ }
10511
+ disconnectedCallback() {
10512
+ this._engine.disconnect();
10513
+ }
10514
+ async routing(path) {
10515
+ await this._engine.router?.go(path);
10516
+ }
10517
+ };
10518
+ SwcApp = __decorate63([
10519
+ elementDefine({ name: "swc-app", extends: void 0 })
10520
+ ], SwcApp);
9464
10521
  export {
9465
10522
  ADD_EVENT_LISTENER_METADATA_KEY,
10523
+ APPEND_CHILD_METADATA_KEY,
9466
10524
  ATTRIBUTE_CHANGED_WILDCARD,
9467
10525
  ELEMENT_CONFIG_KEY,
9468
10526
  EMIT_CUSTOM_EVENT_METADATA_KEY,
@@ -9478,8 +10536,10 @@ export {
9478
10536
  ON_BEFORE_DISCONNECTED_METADATA_KEY,
9479
10537
  QUERY_ALL_METADATA_KEY,
9480
10538
  QUERY_METADATA_KEY,
10539
+ REPLACE_CHILDREN_METADATA_KEY,
9481
10540
  SET_ATTRIBUTE_METADATA_KEY,
9482
10541
  SWC_NOT_FOUND,
10542
+ SwcApp,
9483
10543
  SwcAppAnchor,
9484
10544
  SwcAppArea,
9485
10545
  SwcAppAudio,
@@ -9494,6 +10554,7 @@ export {
9494
10554
  SwcAppDiv,
9495
10555
  SwcAppDl,
9496
10556
  SwcAppEmbed,
10557
+ SwcAppEngine,
9497
10558
  SwcAppFieldSet,
9498
10559
  SwcAppForm,
9499
10560
  SwcAppHeading,
@@ -9537,23 +10598,37 @@ export {
9537
10598
  SwcAppTrack,
9538
10599
  SwcAppUl,
9539
10600
  SwcAppVideo,
10601
+ SwcAsync,
10602
+ SwcChoose,
10603
+ SwcDefault,
10604
+ SwcError,
10605
+ SwcIf,
10606
+ SwcLoading,
10607
+ SwcLoop,
10608
+ SwcOtherwise,
10609
+ SwcSuccess,
9540
10610
  SwcUtils,
10611
+ SwcWhen,
9541
10612
  addEventListener,
10613
+ appendChild,
9542
10614
  changedAttribute,
9543
10615
  elementDefine,
9544
10616
  emitCustomEvent,
10617
+ findAllAppendChildMetadata,
9545
10618
  findAllAttributeChangedMetadata,
9546
10619
  findAllLifecycleMetadata,
10620
+ findAllReplaceChildrenMetadata,
9547
10621
  findAllSetAttributeMetadata,
9548
10622
  getAddEventListenerMetadata,
9549
10623
  getChangedAttributeMetadata,
9550
10624
  getElementConfig,
9551
10625
  getEmitCustomEventMetadataList,
9552
- getInnerHtmlMetadataList,
10626
+ getOnConnectedInnerHtmlMetadata,
9553
10627
  getQueryAllMetadata,
9554
10628
  getQueryMetadata,
10629
+ getReplaceChildrenMetadata,
9555
10630
  getSetAttributeMetadata,
9556
- innerHtml,
10631
+ onConnectedInnerHtml as innerHtml,
9557
10632
  onAddEventListener,
9558
10633
  onAdopted,
9559
10634
  onAfterAdopted,
@@ -9563,9 +10638,11 @@ export {
9563
10638
  onBeforeConnected,
9564
10639
  onBeforeDisconnected,
9565
10640
  onConnected,
10641
+ onConnectedInnerHtml,
9566
10642
  onDisconnected,
9567
10643
  query,
9568
10644
  queryAll,
10645
+ replaceChildren,
9569
10646
  setAttribute
9570
10647
  };
9571
10648
  /*! Bundled license information: