@dooboostore/simple-web-component 1.0.15 → 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 (108) hide show
  1. package/README.md +275 -91
  2. package/dist/cjs/decorators/addEventListener.js +2 -3
  3. package/dist/cjs/decorators/addEventListener.js.map +2 -2
  4. package/dist/cjs/decorators/elementDefine.js +161 -34
  5. package/dist/cjs/decorators/elementDefine.js.map +3 -3
  6. package/dist/cjs/decorators/emitCustomEvent.js +2 -14
  7. package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
  8. package/dist/cjs/decorators/query.js +47 -36
  9. package/dist/cjs/decorators/query.js.map +2 -2
  10. package/dist/cjs/decorators/queryAll.js +42 -36
  11. package/dist/cjs/decorators/queryAll.js.map +2 -2
  12. package/dist/cjs/elements/SwcAppEngine.js +2 -1
  13. package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
  14. package/dist/cjs/elements/SwcAsync.js +188 -0
  15. package/dist/cjs/elements/SwcAsync.js.map +7 -0
  16. package/dist/cjs/elements/SwcChoose.js +155 -0
  17. package/dist/cjs/elements/SwcChoose.js.map +7 -0
  18. package/dist/cjs/elements/SwcIf.js +167 -0
  19. package/dist/cjs/elements/SwcIf.js.map +7 -0
  20. package/dist/cjs/elements/SwcLoop.js +246 -0
  21. package/dist/cjs/elements/SwcLoop.js.map +7 -0
  22. package/dist/cjs/elements/SwcSubTemplates.js +65 -0
  23. package/dist/cjs/elements/SwcSubTemplates.js.map +7 -0
  24. package/dist/cjs/elements/index.js +7 -0
  25. package/dist/cjs/elements/index.js.map +2 -2
  26. package/dist/cjs/index.js +1 -1
  27. package/dist/cjs/index.js.map +2 -2
  28. package/dist/cjs/types.js +1 -0
  29. package/dist/cjs/types.js.map +2 -2
  30. package/dist/cjs/utils/Utils.js +92 -162
  31. package/dist/cjs/utils/Utils.js.map +3 -3
  32. package/dist/esm/decorators/addEventListener.js +2 -3
  33. package/dist/esm/decorators/addEventListener.js.map +2 -2
  34. package/dist/esm/decorators/elementDefine.js +161 -34
  35. package/dist/esm/decorators/elementDefine.js.map +3 -3
  36. package/dist/esm/decorators/emitCustomEvent.js +2 -14
  37. package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
  38. package/dist/esm/decorators/query.js +47 -36
  39. package/dist/esm/decorators/query.js.map +2 -2
  40. package/dist/esm/decorators/queryAll.js +42 -36
  41. package/dist/esm/decorators/queryAll.js.map +2 -2
  42. package/dist/esm/elements/SwcAppEngine.js +2 -1
  43. package/dist/esm/elements/SwcAppEngine.js.map +2 -2
  44. package/dist/esm/elements/SwcAsync.js +169 -0
  45. package/dist/esm/elements/SwcAsync.js.map +7 -0
  46. package/dist/esm/elements/SwcChoose.js +136 -0
  47. package/dist/esm/elements/SwcChoose.js.map +7 -0
  48. package/dist/esm/elements/SwcIf.js +148 -0
  49. package/dist/esm/elements/SwcIf.js.map +7 -0
  50. package/dist/esm/elements/SwcLoop.js +227 -0
  51. package/dist/esm/elements/SwcLoop.js.map +7 -0
  52. package/dist/esm/elements/SwcSubTemplates.js +46 -0
  53. package/dist/esm/elements/SwcSubTemplates.js.map +7 -0
  54. package/dist/esm/elements/index.js +7 -0
  55. package/dist/esm/elements/index.js.map +2 -2
  56. package/dist/esm/index.js +1 -1
  57. package/dist/esm/index.js.map +1 -1
  58. package/dist/esm/types.js +1 -0
  59. package/dist/esm/types.js.map +2 -2
  60. package/dist/esm/utils/Utils.js +92 -162
  61. package/dist/esm/utils/Utils.js.map +3 -3
  62. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +1150 -326
  63. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  64. package/dist/types/decorators/addEventListener.d.ts +10 -4
  65. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  66. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  67. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  68. package/dist/types/decorators/query.d.ts +4 -5
  69. package/dist/types/decorators/query.d.ts.map +1 -1
  70. package/dist/types/decorators/queryAll.d.ts +4 -5
  71. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  72. package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
  73. package/dist/types/elements/SwcAsync.d.ts +16 -0
  74. package/dist/types/elements/SwcAsync.d.ts.map +1 -0
  75. package/dist/types/elements/SwcChoose.d.ts +13 -0
  76. package/dist/types/elements/SwcChoose.d.ts.map +1 -0
  77. package/dist/types/elements/SwcIf.d.ts +15 -0
  78. package/dist/types/elements/SwcIf.d.ts.map +1 -0
  79. package/dist/types/elements/SwcLoop.d.ts +20 -0
  80. package/dist/types/elements/SwcLoop.d.ts.map +1 -0
  81. package/dist/types/elements/SwcSubTemplates.d.ts +13 -0
  82. package/dist/types/elements/SwcSubTemplates.d.ts.map +1 -0
  83. package/dist/types/elements/index.d.ts +7 -0
  84. package/dist/types/elements/index.d.ts.map +1 -1
  85. package/dist/types/index.d.ts +1 -1
  86. package/dist/types/index.d.ts.map +1 -1
  87. package/dist/types/types.d.ts +11 -1
  88. package/dist/types/types.d.ts.map +1 -1
  89. package/dist/types/utils/Utils.d.ts +19 -21
  90. package/dist/types/utils/Utils.d.ts.map +1 -1
  91. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +1150 -326
  92. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  93. package/package.json +10 -3
  94. package/src/decorators/addEventListener.ts +11 -7
  95. package/src/decorators/elementDefine.ts +165 -39
  96. package/src/decorators/emitCustomEvent.ts +5 -21
  97. package/src/decorators/query.ts +46 -41
  98. package/src/decorators/queryAll.ts +45 -41
  99. package/src/elements/SwcAppEngine.ts +2 -1
  100. package/src/elements/SwcAsync.ts +163 -0
  101. package/src/elements/SwcChoose.ts +127 -0
  102. package/src/elements/SwcIf.ts +134 -0
  103. package/src/elements/SwcLoop.ts +215 -0
  104. package/src/elements/SwcSubTemplates.ts +19 -0
  105. package/src/elements/index.ts +8 -3
  106. package/src/index.ts +1 -1
  107. package/src/types.ts +15 -5
  108. package/src/utils/Utils.ts +111 -197
@@ -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");
@@ -1248,16 +1278,15 @@ var getInnerHtmlMetadataList = (target) => {
1248
1278
 
1249
1279
  // src/decorators/addEventListener.ts
1250
1280
  var ADD_EVENT_LISTENER_METADATA_KEY = Symbol("simple-web-component:add-event-listener");
1251
- function addEventListener(arg1, arg2) {
1281
+ function addEventListener(selector, type, options = {}) {
1252
1282
  return (target, propertyKey, descriptor) => {
1253
1283
  const constructor = target.constructor;
1254
- const options = typeof arg1 === "string" ? { type: arg1, query: arg2 } : arg1;
1255
1284
  let listeners = ReflectUtils.getMetadata(ADD_EVENT_LISTENER_METADATA_KEY, constructor);
1256
1285
  if (!listeners) {
1257
1286
  listeners = [];
1258
1287
  ReflectUtils.defineMetadata(ADD_EVENT_LISTENER_METADATA_KEY, listeners, constructor);
1259
1288
  }
1260
- listeners.push({ options, propertyKey });
1289
+ listeners.push({ selector, type, options, propertyKey });
1261
1290
  };
1262
1291
  }
1263
1292
  var getAddEventListenerMetadata = (target) => {
@@ -1303,11 +1332,11 @@ var findAllLifecycleMetadata = (target, metadataKey) => {
1303
1332
  // src/decorators/emitCustomEvent.ts
1304
1333
  var EMIT_CUSTOM_EVENT_METADATA_KEY = Symbol("simple-web-component:emit-custom-event");
1305
1334
  function emitCustomEvent(typeOrOptions) {
1306
- return (target, propertyKey, descriptor) => {
1335
+ return (target, propertyKey) => {
1307
1336
  const constructor = target.constructor;
1308
1337
  const options = typeof typeOrOptions === "string" ? { type: typeOrOptions } : typeOrOptions;
1309
1338
  if (!options.attributeName) {
1310
- options.attributeName = `on${options.type}`;
1339
+ options.attributeName = `swc-on-${options.type}`;
1311
1340
  }
1312
1341
  if (options.bubbles === void 0) options.bubbles = true;
1313
1342
  if (options.composed === void 0) options.composed = true;
@@ -1317,18 +1346,6 @@ function emitCustomEvent(typeOrOptions) {
1317
1346
  ReflectUtils.defineMetadata(EMIT_CUSTOM_EVENT_METADATA_KEY, list, constructor);
1318
1347
  }
1319
1348
  list.push({ propertyKey, options });
1320
- const originalMethod = descriptor.value;
1321
- descriptor.value = function(...args) {
1322
- const detail = originalMethod.apply(this, args);
1323
- const event = new CustomEvent(options.type, {
1324
- detail,
1325
- bubbles: options.bubbles,
1326
- composed: options.composed,
1327
- cancelable: options.cancelable
1328
- });
1329
- this.dispatchEvent(event);
1330
- return detail;
1331
- };
1332
1349
  };
1333
1350
  }
1334
1351
  var getEmitCustomEventMetadataList = (target) => {
@@ -1393,183 +1410,112 @@ var findAllSetAttributeMetadata = (target) => {
1393
1410
 
1394
1411
  // src/utils/Utils.ts
1395
1412
  var SWC_NOT_FOUND = Symbol("SWC_NOT_FOUND");
1396
- var SwcUtils = class _SwcUtils {
1397
- 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) => {
1398
1434
  if (!obj || !path) return SWC_NOT_FOUND;
1399
1435
  const parts = path.split(".");
1400
- if (parts[0] === rootName && parts.length > 1) {
1401
- const subParts = parts.slice(1);
1402
- let subResult = obj;
1403
- for (const part of subParts) {
1404
- if (subResult === null || typeof subResult !== "object" || !(part in subResult)) return SWC_NOT_FOUND;
1405
- subResult = subResult[part];
1406
- }
1407
- return subResult;
1408
- }
1409
- let result = obj;
1436
+ let current = obj;
1410
1437
  for (const part of parts) {
1411
- if (result === null || typeof result !== "object" || !(part in result)) {
1412
- return SWC_NOT_FOUND;
1413
- }
1414
- result = result[part];
1438
+ if (current === null || current === void 0) return SWC_NOT_FOUND;
1439
+ current = current[part];
1415
1440
  }
1416
- if (result !== obj && !(result instanceof HTMLElement)) {
1417
- return result;
1441
+ return 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;
1448
+ if (getElementConfig(current)) return current;
1449
+ current = current.parentElement || current.getRootNode?.()?.host;
1418
1450
  }
1419
- return SWC_NOT_FOUND;
1420
- }
1421
- static evalExpression(expr, context) {
1422
- try {
1423
- const keys = Object.keys(context);
1424
- const values = Object.values(context);
1425
- return new Function(...keys, `return (${expr})`).apply(null, values);
1426
- } catch {
1427
- return SWC_NOT_FOUND;
1428
- }
1429
- }
1430
- static applyData(node, data, options) {
1431
- const { asKey, asIndexKey, index, hostContext } = options;
1432
- const context = {};
1433
- if (index !== void 0) {
1434
- context[asIndexKey] = index;
1435
- }
1436
- if (data !== null && data !== void 0) {
1437
- context[asKey] = data;
1438
- context["value"] = data;
1439
- }
1440
- const fullContext = { ...hostContext || {}, ...context };
1441
- const resolveExpr = (expr, match) => {
1442
- expr = expr.trim();
1443
- const simpleVal = _SwcUtils.getValueByPath(data, expr, asKey);
1444
- if (simpleVal !== SWC_NOT_FOUND && typeof simpleVal !== "symbol") {
1445
- return simpleVal === null || simpleVal === void 0 ? "" : String(simpleVal);
1446
- }
1447
- const exprVal = _SwcUtils.evalExpression(expr, fullContext);
1448
- if (exprVal !== SWC_NOT_FOUND && typeof exprVal !== "symbol") {
1449
- return exprVal === null || exprVal === void 0 ? "" : String(exprVal);
1450
- }
1451
- return match;
1452
- };
1453
- const walk = (n) => {
1454
- if (n.nodeType === Node.TEXT_NODE) {
1455
- if (!n._original) n._original = n.textContent;
1456
- let text = n._original;
1457
- text = text.replace(/{{(.*?)}}/g, (match, path) => {
1458
- return resolveExpr(path, match);
1459
- });
1460
- if (n.textContent !== text) n.textContent = text;
1461
- } else if (n.nodeType === Node.ELEMENT_NODE) {
1462
- const el = n;
1463
- Array.from(el.attributes).forEach((a) => {
1464
- if (!a._original) a._original = a.value;
1465
- let val = a._original;
1466
- val = val.replace(/{{(.*?)}}/g, (match, path) => {
1467
- return resolveExpr(path, match);
1468
- });
1469
- if (a.value !== val) a.value = val;
1470
- });
1471
- el.childNodes.forEach(walk);
1472
- }
1473
- };
1474
- walk(node);
1475
- }
1476
- static createReactiveProxy(target, onChange, onIndexChange) {
1477
- const makeRecursiveProxy = (obj) => {
1478
- if (typeof obj !== "object" || obj === null || obj instanceof Node) return obj;
1479
- if (obj.__swc_is_proxy) return obj;
1480
- const IS_PROXY_KEY = "__swc_is_proxy";
1481
- const proxy = new Proxy(obj, {
1482
- get: (t, prop) => {
1483
- if (prop === IS_PROXY_KEY) return true;
1484
- if (typeof prop === "symbol") return t[prop];
1485
- return t[prop];
1486
- },
1487
- set: (t, prop, val) => {
1488
- if (prop === IS_PROXY_KEY) return true;
1489
- if (typeof prop === "symbol") {
1490
- t[prop] = val;
1491
- return true;
1492
- }
1493
- const oldVal = t[prop];
1494
- if (oldVal === val) return true;
1495
- t[prop] = makeRecursiveProxy(val);
1496
- const isIndex = !isNaN(Number(prop)) && Array.isArray(t);
1497
- if (isIndex && onIndexChange) {
1498
- onIndexChange(Number(prop), val);
1499
- } else {
1500
- onChange();
1501
- }
1502
- return true;
1503
- },
1504
- deleteProperty: (t, prop) => {
1505
- delete t[prop];
1506
- onChange();
1507
- return true;
1508
- }
1509
- });
1510
- return proxy;
1511
- };
1512
- return makeRecursiveProxy(target);
1513
- }
1514
- static findNearestSwcHost(el) {
1515
- const hosts = this.findAllSwcHosts(el);
1516
- return hosts.length > 0 ? hosts[hosts.length - 1] : null;
1517
- }
1518
- static findAllSwcHosts(el) {
1451
+ return void 0;
1452
+ };
1453
+ SwcUtils2.findAllSwcHosts = (el) => {
1519
1454
  const hosts = [];
1520
- let curr = el instanceof Node && !(el instanceof HTMLElement) ? el.host : el;
1521
- curr = curr?.parentElement || curr?.getRootNode()?.host;
1522
- while (curr) {
1523
- if (curr._swcId) hosts.push(curr);
1524
- curr = curr.parentElement || curr?.getRootNode()?.host;
1455
+ let current = (0, SwcUtils2.findNearestSwcHost)(el);
1456
+ while (current) {
1457
+ hosts.push(current);
1458
+ current = (0, SwcUtils2.findNearestSwcHost)(current);
1525
1459
  }
1526
1460
  return hosts.reverse();
1527
- }
1528
- static getHosts(el) {
1529
- return this.findAllSwcHosts(el);
1530
- }
1531
- static getHost(el) {
1532
- const hosts = this.getHosts(el);
1533
- return hosts.length > 0 ? hosts[hosts.length - 1] : void 0;
1534
- }
1535
- static getFirstHost(el) {
1536
- const hosts = this.getHosts(el);
1537
- return hosts.length > 0 ? hosts[0] : void 0;
1538
- }
1539
- static getAppHosts(el) {
1540
- 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);
1541
1473
  return hosts.filter((host) => host.tagName.toLowerCase() === "swc-app" || host.getAttribute("is")?.startsWith("swc-app-"));
1542
- }
1543
- static getAppHost(el) {
1544
- const appHosts = this.getAppHosts(el);
1545
- return appHosts.length > 0 ? appHosts[appHosts.length - 1] : void 0;
1546
- }
1547
- static getFirstAppHost(el) {
1548
- const appHosts = this.getAppHosts(el);
1549
- return appHosts.length > 0 ? appHosts[0] : void 0;
1550
- }
1551
- static getLastAppHost(el) {
1552
- return this.getAppHost(el);
1553
- }
1554
- static getHostSet(el) {
1555
- const $hosts = this.getHosts(el);
1556
- const $appHosts = this.getAppHosts(el);
1557
- const $firstHost = $hosts[0] || null;
1558
- const $lastHost = $hosts[$hosts.length - 1] || null;
1559
- const $firstAppHost = $appHosts[0] || null;
1560
- const $lastAppHost = $appHosts[$appHosts.length - 1] || null;
1474
+ };
1475
+ SwcUtils2.getAppHost = (el) => {
1476
+ const appHosts = (0, SwcUtils2.getAppHosts)(el);
1477
+ const appHostsWithoutSelf = appHosts.filter((h) => h !== el);
1478
+ return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : void 0;
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
+ }
1502
+ const $appHosts = $hosts.filter((h) => h.tagName.toLowerCase() === "swc-app" || h.getAttribute("is")?.startsWith("swc-app-"));
1503
+ const $appHost = $appHosts.length > 0 ? $appHosts[$appHosts.length - 1] === el ? $appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null : $appHosts[$appHosts.length - 1] : null;
1504
+ const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;
1561
1505
  return {
1562
- $host: $lastHost,
1506
+ $host,
1507
+ $parentHost,
1563
1508
  $hosts,
1564
1509
  $firstHost,
1565
- $lastHost,
1566
- $appHost: $lastAppHost,
1510
+ $lastHost: $parentHost,
1511
+ $appHost,
1567
1512
  $appHosts,
1568
1513
  $firstAppHost,
1569
- $lastAppHost
1514
+ $lastAppHost: $appHost,
1515
+ ...loopContext
1570
1516
  };
1571
- }
1572
- };
1517
+ };
1518
+ })(SwcUtils || (SwcUtils = {}));
1573
1519
 
1574
1520
  // src/config/config.ts
1575
1521
  var HTML_TAG_ENTRIES = [
@@ -1681,6 +1627,7 @@ var InjectSituationType = /* @__PURE__ */ ((InjectSituationType2) => {
1681
1627
  InjectSituationType2["APP_HOST"] = "SIMPLE_WEB_COMPONENT://APPHOST";
1682
1628
  InjectSituationType2["APP_HOSTS"] = "SIMPLE_WEB_COMPONENT://APPHOSTS";
1683
1629
  InjectSituationType2["HOST"] = "SIMPLE_WEB_COMPONENT://HOST";
1630
+ InjectSituationType2["PARENT_HOST"] = "SIMPLE_WEB_COMPONENT://PARENTHOST";
1684
1631
  InjectSituationType2["HOSTS"] = "SIMPLE_WEB_COMPONENT://HOSTS";
1685
1632
  InjectSituationType2["FIRST_HOST"] = "SIMPLE_WEB_COMPONENT://FIRSTHOST";
1686
1633
  InjectSituationType2["LAST_HOST"] = "SIMPLE_WEB_COMPONENT://LASTHOST";
@@ -1691,6 +1638,7 @@ var InjectSituationType = /* @__PURE__ */ ((InjectSituationType2) => {
1691
1638
 
1692
1639
  // src/decorators/elementDefine.ts
1693
1640
  var ELEMENT_CONFIG_KEY = Symbol("simple-web-component:element-config");
1641
+ var globalDelegatedRoots = /* @__PURE__ */ new WeakSet();
1694
1642
  function buildEnv(configWindow) {
1695
1643
  const win = configWindow || (typeof window !== "undefined" ? window : void 0);
1696
1644
  const doc = win?.document;
@@ -1699,13 +1647,7 @@ function buildEnv(configWindow) {
1699
1647
  if (win?.[cls])
1700
1648
  builtInTagMap.set(win[cls], tag);
1701
1649
  }
1702
- const domHelpers = {
1703
- $d: doc,
1704
- $w: win,
1705
- $q: (sel, root) => (root ?? doc).querySelector(sel),
1706
- $qa: (sel, root) => Array.from((root ?? doc).querySelectorAll(sel)),
1707
- $qi: (id, root) => (root ?? doc).getElementById(id)
1708
- };
1650
+ const domHelpers = SwcUtils.getHelperSet(win);
1709
1651
  return { win, doc, builtInTagMap, domHelpers };
1710
1652
  }
1711
1653
  var getHandlers = (inst) => {
@@ -1717,8 +1659,6 @@ var elementDefine = (inConfig) => (constructor) => {
1717
1659
  const config = typeof inConfig === "string" ? { name: inConfig } : inConfig;
1718
1660
  const { win, doc, builtInTagMap: BUILT_IN_TAG_MAP, domHelpers: SWC_DOM_HELPERS } = buildEnv(config.window);
1719
1661
  config.window = win;
1720
- const SWC_DOM_HELPER_KEYS = Object.keys(SWC_DOM_HELPERS);
1721
- const SWC_DOM_HELPER_VALS = () => SWC_DOM_HELPER_KEYS.map((k) => SWC_DOM_HELPERS[k]);
1722
1662
  let extendsTagName = config.extends;
1723
1663
  if (!extendsTagName) {
1724
1664
  let proto = constructor;
@@ -1744,9 +1684,7 @@ var elementDefine = (inConfig) => (constructor) => {
1744
1684
  if (script) {
1745
1685
  try {
1746
1686
  const args = { ...hostSet, ...SWC_DOM_HELPERS, ...extraArgs };
1747
- const argNames = Object.keys(args);
1748
- const argValues = Object.values(args);
1749
- new Function(...argNames, script).apply(this, argValues);
1687
+ FunctionUtils.execute({ script, context: this, args });
1750
1688
  } catch (e) {
1751
1689
  console.error(`[SWC] Failed to execute ${attrName}:`, e);
1752
1690
  }
@@ -1769,10 +1707,12 @@ var elementDefine = (inConfig) => (constructor) => {
1769
1707
  return this[methodName](...extraArgs);
1770
1708
  }
1771
1709
  }
1772
- _bindAttributeEvent(el, attrName, script) {
1773
- if (!attrName.startsWith("swc-on-"))
1774
- return;
1775
- const eventName = attrName.substring(7);
1710
+ _bindAttributeEvent(el, attrName, script, eventName) {
1711
+ if (!eventName) {
1712
+ if (!attrName.startsWith("swc-on-"))
1713
+ return;
1714
+ eventName = attrName.substring(7);
1715
+ }
1776
1716
  if (swcLifecycleAttributes.includes(attrName))
1777
1717
  return;
1778
1718
  const elHandlers = getHandlers(this);
@@ -1786,9 +1726,13 @@ var elementDefine = (inConfig) => (constructor) => {
1786
1726
  el.removeEventListener(eventName, oldHandler);
1787
1727
  const handler = (event) => {
1788
1728
  const hostSet = SwcUtils.getHostSet(el);
1789
- const argNames = Object.keys(hostSet);
1790
- const argValues = Object.values(hostSet);
1791
- 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 });
1792
1736
  };
1793
1737
  el.addEventListener(eventName, handler);
1794
1738
  handlers.set(attrName, handler);
@@ -1797,6 +1741,7 @@ var elementDefine = (inConfig) => (constructor) => {
1797
1741
  super(...args);
1798
1742
  this._swcId = Math.random().toString(36).substring(2, 11);
1799
1743
  this._emitHandlers = /* @__PURE__ */ new Map();
1744
+ this._boundListeners = [];
1800
1745
  const hostSet = SwcUtils.getHostSet(this);
1801
1746
  this._executeSwcScript("swc-on-constructor", hostSet);
1802
1747
  if (innerHtmlList.some((it) => it.options.useShadow === true) && !this.shadowRoot) {
@@ -1807,6 +1752,9 @@ var elementDefine = (inConfig) => (constructor) => {
1807
1752
  return mergedObservedAttributes;
1808
1753
  }
1809
1754
  async connectedCallback() {
1755
+ const conf = getElementConfig(this);
1756
+ const currentWin = conf?.window || window;
1757
+ const currentDoc = currentWin.document;
1810
1758
  const hostSet = SwcUtils.getHostSet(this);
1811
1759
  this._executeSwcScript("swc-on-before-connected", hostSet);
1812
1760
  const bMethods = findAllLifecycleMetadata(this, ON_BEFORE_CONNECTED_METADATA_KEY);
@@ -1832,19 +1780,122 @@ var elementDefine = (inConfig) => (constructor) => {
1832
1780
  if (lContent)
1833
1781
  this.innerHTML = lContent;
1834
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
+ }
1835
1827
  addEventListenerList.forEach((meta) => {
1836
- const { type, query: query2, root, capture, once, passive, stopPropagation, stopImmediatePropagation, preventDefault } = meta.options;
1837
- const targetEls = [];
1838
- if (!query2) {
1839
- targetEls.push(this);
1828
+ const { selector, type, options } = meta;
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) {
1857
+ const bindRoots = [];
1858
+ const r = root || "auto";
1859
+ if (r === "auto")
1860
+ bindRoots.push(this.shadowRoot || this);
1861
+ else if (r === "light")
1862
+ bindRoots.push(this);
1863
+ else if (r === "shadow") {
1864
+ if (this.shadowRoot)
1865
+ bindRoots.push(this.shadowRoot);
1866
+ } else if (r === "all") {
1867
+ bindRoots.push(this);
1868
+ if (this.shadowRoot)
1869
+ bindRoots.push(this.shadowRoot);
1870
+ }
1871
+ bindRoots.forEach((br) => {
1872
+ const handler = (event) => {
1873
+ const matchedEl = event.target.closest(selector);
1874
+ if (matchedEl && br.contains(matchedEl)) {
1875
+ if (stopPropagation)
1876
+ event.stopPropagation();
1877
+ if (stopImmediatePropagation)
1878
+ event.stopImmediatePropagation();
1879
+ if (preventDefault)
1880
+ event.preventDefault();
1881
+ const currentHostSet = SwcUtils.getHostSet(this);
1882
+ this._invokeLifecycleMethod(meta.propertyKey, currentHostSet, [event, currentHostSet, matchedEl]);
1883
+ }
1884
+ };
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
+ }
1890
+ });
1840
1891
  } else {
1841
1892
  const searchRoots = [];
1842
1893
  const r = root || "auto";
1843
- if (r === "auto") {
1894
+ if (r === "auto")
1844
1895
  searchRoots.push(this.shadowRoot || this);
1845
- } else if (r === "light") {
1896
+ else if (r === "light")
1846
1897
  searchRoots.push(this);
1847
- } else if (r === "shadow") {
1898
+ else if (r === "shadow") {
1848
1899
  if (this.shadowRoot)
1849
1900
  searchRoots.push(this.shadowRoot);
1850
1901
  } else if (r === "all") {
@@ -1853,11 +1904,10 @@ var elementDefine = (inConfig) => (constructor) => {
1853
1904
  searchRoots.push(this.shadowRoot);
1854
1905
  }
1855
1906
  searchRoots.forEach((sr) => {
1856
- const found = sr.querySelectorAll(query2);
1857
- found.forEach((el) => targetEls.push(el));
1907
+ sr.querySelectorAll(selector).forEach((el) => bindTargets.push(el));
1858
1908
  });
1859
1909
  }
1860
- targetEls.forEach((el) => {
1910
+ bindTargets.forEach((target) => {
1861
1911
  const handler = (event) => {
1862
1912
  if (stopPropagation)
1863
1913
  event.stopPropagation();
@@ -1865,11 +1915,13 @@ var elementDefine = (inConfig) => (constructor) => {
1865
1915
  event.stopImmediatePropagation();
1866
1916
  if (preventDefault)
1867
1917
  event.preventDefault();
1868
- const hostSet2 = SwcUtils.getHostSet(this);
1869
- this._invokeLifecycleMethod(meta.propertyKey, hostSet2, [event, hostSet2]);
1918
+ const currentHostSet = SwcUtils.getHostSet(this);
1919
+ this._invokeLifecycleMethod(meta.propertyKey, currentHostSet, [event, currentHostSet]);
1870
1920
  };
1871
- const options = { capture, once, passive };
1872
- el.addEventListener(type, handler, options);
1921
+ target.addEventListener(type, handler, opts);
1922
+ if (removeOnDisconnected === true || target === currentWin || target === currentDoc) {
1923
+ this._boundListeners.push({ target, type, handler, options: opts });
1924
+ }
1873
1925
  });
1874
1926
  });
1875
1927
  if (super.connectedCallback)
@@ -1888,6 +1940,8 @@ var elementDefine = (inConfig) => (constructor) => {
1888
1940
  const bMethods = findAllLifecycleMetadata(this, ON_BEFORE_DISCONNECTED_METADATA_KEY);
1889
1941
  if (bMethods)
1890
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 = [];
1891
1945
  if (super.disconnectedCallback)
1892
1946
  super.disconnectedCallback();
1893
1947
  const aMethods = findAllLifecycleMetadata(this, ON_AFTER_DISCONNECTED_METADATA_KEY);
@@ -1915,7 +1969,9 @@ var elementDefine = (inConfig) => (constructor) => {
1915
1969
  super.attributeChangedCallback(name, old, newVal);
1916
1970
  if (name.startsWith("swc-on-") && !swcLifecycleAttributes.includes(name)) {
1917
1971
  if (newVal !== null) {
1918
- this._bindAttributeEvent(this, name, newVal);
1972
+ const customEventMeta = emitCustomEventList.find((it) => it.options.attributeName === name);
1973
+ const eventName = customEventMeta ? customEventMeta.options.type : name.substring(7);
1974
+ this._bindAttributeEvent(this, name, newVal, eventName);
1919
1975
  }
1920
1976
  }
1921
1977
  const mKeys = attrChangeMap.get(name);
@@ -1940,6 +1996,23 @@ var elementDefine = (inConfig) => (constructor) => {
1940
1996
  };
1941
1997
  }
1942
1998
  });
1999
+ emitCustomEventList.forEach((meta) => {
2000
+ const { propertyKey, options } = meta;
2001
+ const original = NewClass.prototype[propertyKey];
2002
+ if (typeof original === "function") {
2003
+ NewClass.prototype[propertyKey] = function(...args) {
2004
+ const detail = original.apply(this, args);
2005
+ const event = new CustomEvent(options.type, {
2006
+ detail,
2007
+ bubbles: options.bubbles,
2008
+ composed: options.composed,
2009
+ cancelable: options.cancelable
2010
+ });
2011
+ this.dispatchEvent(event);
2012
+ return detail;
2013
+ };
2014
+ }
2015
+ });
1943
2016
  const originalProto = constructor.prototype;
1944
2017
  const newProto = NewClass.prototype;
1945
2018
  Object.getOwnPropertyNames(originalProto).forEach((name) => {
@@ -1963,48 +2036,57 @@ var getElementConfig = (target) => {
1963
2036
 
1964
2037
  // src/decorators/query.ts
1965
2038
  var QUERY_METADATA_KEY = Symbol("simple-web-component:query");
1966
- function query(arg1, arg2) {
1967
- const decorator = (selector, options, target, propertyKey, descriptor) => {
1968
- const isMethod = !!descriptor;
2039
+ function query(selector, options = {}) {
2040
+ return (target, propertyKey, descriptor) => {
2041
+ if (descriptor !== void 0) {
2042
+ throw new Error(`@query decorator cannot be used on methods. (Method: ${String(propertyKey)})`);
2043
+ }
1969
2044
  const constructor = target.constructor;
1970
2045
  let queries = ReflectUtils.getMetadata(QUERY_METADATA_KEY, constructor);
1971
2046
  if (!queries) {
1972
2047
  queries = [];
1973
2048
  ReflectUtils.defineMetadata(QUERY_METADATA_KEY, queries, constructor);
1974
2049
  }
1975
- queries.push({ selector, options, propertyKey, isMethod });
1976
- if (!isMethod) {
1977
- Object.defineProperty(target, propertyKey, {
1978
- get() {
1979
- if (!selector)
1980
- return this;
1981
- let searchRoot = this;
1982
- if (options.root === "shadow")
1983
- searchRoot = this.shadowRoot || this;
1984
- else if (options.root === "light")
1985
- searchRoot = this;
1986
- else
1987
- searchRoot = this.shadowRoot || this;
1988
- return searchRoot.querySelector(selector);
1989
- },
1990
- enumerable: true,
1991
- configurable: true
1992
- });
1993
- }
1994
- };
1995
- if (arg1 && typeof arg2 === "string") {
1996
- return decorator("", {}, arg1, arg2);
1997
- }
1998
- return (target, propertyKey, descriptor) => {
1999
- let selector = "";
2000
- let options = {};
2001
- if (typeof arg1 === "string") {
2002
- selector = arg1;
2003
- } else if (typeof arg1 === "object") {
2004
- options = arg1;
2005
- selector = options.selector || "";
2006
- }
2007
- decorator(selector, options, target, propertyKey, descriptor);
2050
+ queries.push({ selector, options, propertyKey });
2051
+ Object.defineProperty(target, propertyKey, {
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;
2073
+ if (!selector || selector === ":host")
2074
+ return this;
2075
+ const r = options.root || "auto";
2076
+ if (r === "shadow") {
2077
+ return this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;
2078
+ }
2079
+ if (r === "light") {
2080
+ return this.querySelector(selector);
2081
+ }
2082
+ if (r === "all") {
2083
+ return this.shadowRoot?.querySelector(selector) || this.querySelector(selector);
2084
+ }
2085
+ return (this.shadowRoot || this).querySelector(selector);
2086
+ },
2087
+ enumerable: true,
2088
+ configurable: true
2089
+ });
2008
2090
  };
2009
2091
  }
2010
2092
  var getQueryMetadata = (target) => {
@@ -2014,48 +2096,52 @@ var getQueryMetadata = (target) => {
2014
2096
 
2015
2097
  // src/decorators/queryAll.ts
2016
2098
  var QUERY_ALL_METADATA_KEY = Symbol("simple-web-component:query-all");
2017
- function queryAll(arg1, arg2) {
2018
- const decorator = (selector, options, target, propertyKey, descriptor) => {
2019
- const isMethod = !!descriptor;
2099
+ function queryAll(selector, options = {}) {
2100
+ return (target, propertyKey, descriptor) => {
2101
+ if (descriptor !== void 0) {
2102
+ throw new Error(`@queryAll decorator cannot be used on methods. (Method: ${String(propertyKey)})`);
2103
+ }
2020
2104
  const constructor = target.constructor;
2021
2105
  let queries = ReflectUtils.getMetadata(QUERY_ALL_METADATA_KEY, constructor);
2022
2106
  if (!queries) {
2023
2107
  queries = [];
2024
2108
  ReflectUtils.defineMetadata(QUERY_ALL_METADATA_KEY, queries, constructor);
2025
2109
  }
2026
- queries.push({ selector, options, propertyKey, isMethod });
2027
- if (!isMethod) {
2028
- Object.defineProperty(target, propertyKey, {
2029
- get() {
2030
- if (!selector)
2031
- return [this];
2032
- let searchRoot = this;
2033
- if (options.root === "shadow")
2034
- searchRoot = this.shadowRoot || this;
2035
- else if (options.root === "light")
2036
- searchRoot = this;
2037
- else
2038
- searchRoot = this.shadowRoot || this;
2039
- return searchRoot.querySelectorAll(selector);
2040
- },
2041
- enumerable: true,
2042
- configurable: true
2043
- });
2044
- }
2045
- };
2046
- if (arg1 && typeof arg2 === "string") {
2047
- return decorator("", {}, arg1, arg2);
2048
- }
2049
- return (target, propertyKey, descriptor) => {
2050
- let selector = "";
2051
- let options = {};
2052
- if (typeof arg1 === "string") {
2053
- selector = arg1;
2054
- } else if (typeof arg1 === "object") {
2055
- options = arg1;
2056
- selector = options.selector || "";
2057
- }
2058
- decorator(selector, options, target, propertyKey, descriptor);
2110
+ queries.push({ selector, options, propertyKey });
2111
+ Object.defineProperty(target, propertyKey, {
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];
2125
+ if (!selector || selector === ":host")
2126
+ return [this];
2127
+ const r = options.root || "auto";
2128
+ if (r === "shadow") {
2129
+ return this.shadowRoot ? this.shadowRoot.querySelectorAll(selector) : [];
2130
+ }
2131
+ if (r === "light") {
2132
+ return this.querySelectorAll(selector);
2133
+ }
2134
+ if (r === "all") {
2135
+ const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];
2136
+ const lNodes = Array.from(this.querySelectorAll(selector));
2137
+ return [...sNodes, ...lNodes];
2138
+ }
2139
+ const root = this.shadowRoot || this;
2140
+ return root.querySelectorAll(selector);
2141
+ },
2142
+ enumerable: true,
2143
+ configurable: true
2144
+ });
2059
2145
  };
2060
2146
  }
2061
2147
  var getQueryAllMetadata = (target) => {
@@ -7680,7 +7766,7 @@ var SwcAppEngine = class {
7680
7766
  const configStr = this.host.getAttribute("swc-get-application-config");
7681
7767
  if (!configStr) return;
7682
7768
  try {
7683
- const userConfig = new Function(`return ${configStr}`).apply(this.host);
7769
+ const userConfig = FunctionUtils.executeReturn({ script: configStr, context: this.host });
7684
7770
  if (userConfig && userConfig.rootRouter) {
7685
7771
  const _config = {
7686
7772
  routeType: "element",
@@ -9544,6 +9630,732 @@ var SwcAppBody = class SwcAppBody2 extends HTMLBodyElement {
9544
9630
  SwcAppBody = __decorate57([
9545
9631
  elementDefine({ name: "swc-app-body", extends: "body" })
9546
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);
9547
10359
  export {
9548
10360
  ADD_EVENT_LISTENER_METADATA_KEY,
9549
10361
  ATTRIBUTE_CHANGED_WILDCARD,
@@ -9563,6 +10375,7 @@ export {
9563
10375
  QUERY_METADATA_KEY,
9564
10376
  SET_ATTRIBUTE_METADATA_KEY,
9565
10377
  SWC_NOT_FOUND,
10378
+ SwcApp,
9566
10379
  SwcAppAnchor,
9567
10380
  SwcAppArea,
9568
10381
  SwcAppAudio,
@@ -9577,6 +10390,7 @@ export {
9577
10390
  SwcAppDiv,
9578
10391
  SwcAppDl,
9579
10392
  SwcAppEmbed,
10393
+ SwcAppEngine,
9580
10394
  SwcAppFieldSet,
9581
10395
  SwcAppForm,
9582
10396
  SwcAppHeading,
@@ -9620,7 +10434,17 @@ export {
9620
10434
  SwcAppTrack,
9621
10435
  SwcAppUl,
9622
10436
  SwcAppVideo,
10437
+ SwcAsync,
10438
+ SwcChoose,
10439
+ SwcDefault,
10440
+ SwcError,
10441
+ SwcIf,
10442
+ SwcLoading,
10443
+ SwcLoop,
10444
+ SwcOtherwise,
10445
+ SwcSuccess,
9623
10446
  SwcUtils,
10447
+ SwcWhen,
9624
10448
  addEventListener,
9625
10449
  changedAttribute,
9626
10450
  elementDefine,