@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
@@ -23,6 +23,8 @@ __export(query_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(query_exports);
25
25
  var import_ReflectUtils = require("@dooboostore/core/reflect/ReflectUtils");
26
+ var import_elementDefine = require("./elementDefine");
27
+ var import_Utils = require("../utils/Utils");
26
28
  const QUERY_METADATA_KEY = Symbol("simple-web-component:query");
27
29
  function query(selector, options = {}) {
28
30
  return (target, propertyKey, descriptor) => {
@@ -38,6 +40,26 @@ function query(selector, options = {}) {
38
40
  queries.push({ selector, options, propertyKey });
39
41
  Object.defineProperty(target, propertyKey, {
40
42
  get() {
43
+ const hostSet = import_Utils.SwcUtils.getHostSet(this);
44
+ if (selector === ":parentHost")
45
+ return hostSet.$parentHost;
46
+ if (selector === ":appHost")
47
+ return hostSet.$appHost;
48
+ if (selector === ":firstHost")
49
+ return hostSet.$firstHost;
50
+ if (selector === ":lastHost")
51
+ return hostSet.$lastHost;
52
+ if (selector === ":firstAppHost")
53
+ return hostSet.$firstAppHost;
54
+ if (selector === ":lastAppHost")
55
+ return hostSet.$lastAppHost;
56
+ const config = (0, import_elementDefine.getElementConfig)(this);
57
+ const win = config?.window || window;
58
+ const doc = win.document;
59
+ if (selector === ":window")
60
+ return win;
61
+ if (selector === ":document")
62
+ return doc;
41
63
  if (!selector || selector === ":host")
42
64
  return this;
43
65
  const r = options.root || "auto";
@@ -52,6 +74,22 @@ function query(selector, options = {}) {
52
74
  }
53
75
  return (this.shadowRoot || this).querySelector(selector);
54
76
  },
77
+ set(nv) {
78
+ if (nv === null || nv === void 0) {
79
+ const r = options.root || "auto";
80
+ let targetEl = null;
81
+ if (r === "shadow")
82
+ targetEl = this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;
83
+ else if (r === "light")
84
+ targetEl = this.querySelector(selector);
85
+ else if (r === "all")
86
+ targetEl = this.shadowRoot?.querySelector(selector) || this.querySelector(selector);
87
+ else
88
+ targetEl = (this.shadowRoot || this).querySelector(selector);
89
+ if (targetEl)
90
+ targetEl.remove();
91
+ }
92
+ },
55
93
  enumerable: true,
56
94
  configurable: true
57
95
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/decorators/query.ts"],
4
- "sourcesContent": ["import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\n\nexport interface QueryOptions {\n root?: 'light' | 'shadow' | 'all' | 'auto';\n}\n\nexport interface QueryMetadata {\n selector: string;\n options: QueryOptions;\n propertyKey: string | symbol;\n}\n\nexport const QUERY_METADATA_KEY = Symbol('simple-web-component:query');\n\n/**\n * @query decorator to inject a single element into a class property.\n * Usage: @query('.my-class') myEl!: HTMLElement;\n * Usage: @query('#my-id', { root: 'shadow' }) myEl!: HTMLElement;\n */\nexport function query(selector: string, options: QueryOptions = {}): PropertyDecorator {\n return (target: Object, propertyKey: string | symbol, descriptor?: never): void => {\n if (descriptor !== undefined) {\n throw new Error(`@query decorator cannot be used on methods. (Method: ${String(propertyKey)})`);\n }\n\n const constructor = target.constructor;\n let queries = ReflectUtils.getMetadata<QueryMetadata[]>(QUERY_METADATA_KEY, constructor);\n if (!queries) {\n queries = [];\n ReflectUtils.defineMetadata(QUERY_METADATA_KEY, queries, constructor);\n }\n queries.push({ selector, options, propertyKey });\n\n Object.defineProperty(target, propertyKey, {\n get(this: HTMLElement) {\n if (!selector || selector === ':host') return this;\n const r = options.root || 'auto';\n\n if (r === 'shadow') {\n return this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;\n }\n if (r === 'light') {\n return this.querySelector(selector);\n }\n if (r === 'all') {\n return this.shadowRoot?.querySelector(selector) || this.querySelector(selector);\n }\n // auto\n return (this.shadowRoot || this).querySelector(selector);\n },\n enumerable: true,\n configurable: true\n });\n };\n}\n\nexport const getQueryMetadata = (target: any): QueryMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(QUERY_METADATA_KEY, constructor);\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;;;;;;;0BAA6B;AAYtB,MAAM,qBAAqB,OAAO,4BAA4B;AAO/D,SAAU,MAAM,UAAkB,UAAwB,CAAA,GAAE;AAChE,SAAO,CAAC,QAAgB,aAA8B,eAA4B;AAChF,QAAI,eAAe,QAAW;AAC5B,YAAM,IAAI,MAAM,wDAAwD,OAAO,WAAW,CAAC,GAAG;IAChG;AAEA,UAAM,cAAc,OAAO;AAC3B,QAAI,UAAU,iCAAa,YAA6B,oBAAoB,WAAW;AACvF,QAAI,CAAC,SAAS;AACZ,gBAAU,CAAA;AACV,uCAAa,eAAe,oBAAoB,SAAS,WAAW;IACtE;AACA,YAAQ,KAAK,EAAE,UAAU,SAAS,YAAW,CAAE;AAE/C,WAAO,eAAe,QAAQ,aAAa;MACzC,MAAG;AACD,YAAI,CAAC,YAAY,aAAa;AAAS,iBAAO;AAC9C,cAAM,IAAI,QAAQ,QAAQ;AAE1B,YAAI,MAAM,UAAU;AAClB,iBAAO,KAAK,aAAa,KAAK,WAAW,cAAc,QAAQ,IAAI;QACrE;AACA,YAAI,MAAM,SAAS;AACjB,iBAAO,KAAK,cAAc,QAAQ;QACpC;AACA,YAAI,MAAM,OAAO;AACf,iBAAO,KAAK,YAAY,cAAc,QAAQ,KAAK,KAAK,cAAc,QAAQ;QAChF;AAEA,gBAAQ,KAAK,cAAc,MAAM,cAAc,QAAQ;MACzD;MACA,YAAY;MACZ,cAAc;KACf;EACH;AACF;AAEO,MAAM,mBAAmB,CAAC,WAA4C;AAC3E,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,iCAAa,YAAY,oBAAoB,WAAW;AACjE;",
4
+ "sourcesContent": ["import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\nimport { getElementConfig } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\n\nexport interface QueryOptions {\n root?: 'light' | 'shadow' | 'all' | 'auto';\n}\n\nexport interface QueryMetadata {\n selector: string;\n options: QueryOptions;\n propertyKey: string | symbol;\n}\n\nexport const QUERY_METADATA_KEY = Symbol('simple-web-component:query');\n\n/**\n * @query decorator to inject a single element into a class property.\n */\nexport function query(selector: string, options: QueryOptions = {}): PropertyDecorator {\n return (target: Object, propertyKey: string | symbol, descriptor?: never): void => {\n if (descriptor !== undefined) {\n throw new Error(`@query decorator cannot be used on methods. (Method: ${String(propertyKey)})`);\n }\n\n const constructor = target.constructor;\n let queries = ReflectUtils.getMetadata<QueryMetadata[]>(QUERY_METADATA_KEY, constructor);\n if (!queries) {\n queries = [];\n ReflectUtils.defineMetadata(QUERY_METADATA_KEY, queries, constructor);\n }\n queries.push({ selector, options, propertyKey });\n\n Object.defineProperty(target, propertyKey, {\n get(this: HTMLElement) {\n // --- Special Selectors: HostSet ---\n const hostSet = SwcUtils.getHostSet(this);\n if (selector === ':parentHost') return hostSet.$parentHost;\n if (selector === ':appHost') return hostSet.$appHost;\n if (selector === ':firstHost') return hostSet.$firstHost;\n if (selector === ':lastHost') return hostSet.$lastHost;\n if (selector === ':firstAppHost') return hostSet.$firstAppHost;\n if (selector === ':lastAppHost') return hostSet.$lastAppHost;\n\n // --- Special Selectors: Env ---\n const config = getElementConfig(this);\n const win = config?.window || window;\n const doc = win.document;\n\n if (selector === ':window') return win;\n if (selector === ':document') return doc;\n if (!selector || selector === ':host') return this;\n\n // --- Standard Selectors ---\n const r = options.root || 'auto';\n\n if (r === 'shadow') {\n return this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;\n }\n if (r === 'light') {\n return this.querySelector(selector);\n }\n if (r === 'all') {\n return this.shadowRoot?.querySelector(selector) || this.querySelector(selector);\n }\n // auto\n return (this.shadowRoot || this).querySelector(selector);\n },\n set(this: HTMLElement, nv: any) {\n if (nv === null || nv === undefined) {\n const r = options.root || 'auto';\n let targetEl: Element | null = null;\n if (r === 'shadow') targetEl = this.shadowRoot ? this.shadowRoot.querySelector(selector) : null;\n else if (r === 'light') targetEl = this.querySelector(selector);\n else if (r === 'all') targetEl = this.shadowRoot?.querySelector(selector) || this.querySelector(selector);\n else targetEl = (this.shadowRoot || this).querySelector(selector);\n\n if (targetEl) targetEl.remove();\n }\n },\n enumerable: true,\n configurable: true\n });\n };\n}\n\nexport const getQueryMetadata = (target: any): QueryMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(QUERY_METADATA_KEY, constructor);\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;;;;;;;0BAA6B;AAC7B,2BAAiC;AACjC,mBAAyB;AAYlB,MAAM,qBAAqB,OAA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D;MACA,IAAuB,IAAO;AAC5B,YAAI,OAAO,QAAQ,OAAO,QAAW;AACnC,gBAAM,IAAI,QAAQ,QAAQ;AAC1B,cAAI,WAA2B;AAC/B,cAAI,MAAM;AAAU,uBAAW,KAAK,aAAa,KAAK,WAAW,cAAc,QAAQ,IAAI;mBAClF,MAAM;AAAS,uBAAW,KAAK,cAAc,QAAQ;mBACrD,MAAM;AAAO,uBAAW,KAAK,YAAY,cAAc,QAAQ,KAAK,KAAK,cAAc,QAAQ;;AACnG,wBAAY,KAAK,cAAc,MAAM,cAAc,QAAQ;AAEhE,cAAI;AAAU,qBAAS,OAAM;QAC/B;MACF;MACA,YAAY;MACZ,cAAc;KACf;EACH;AACF;AAEO,MAAM,mBAAmB,CAAC,WAA4C;AAC3E,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,iCAAa,YAAY,oBAAoB,WAAW;AACjE;",
6
6
  "names": []
7
7
  }
@@ -23,6 +23,8 @@ __export(queryAll_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(queryAll_exports);
25
25
  var import_ReflectUtils = require("@dooboostore/core/reflect/ReflectUtils");
26
+ var import_elementDefine = require("./elementDefine");
27
+ var import_Utils = require("../utils/Utils");
26
28
  const QUERY_ALL_METADATA_KEY = Symbol("simple-web-component:query-all");
27
29
  function queryAll(selector, options = {}) {
28
30
  return (target, propertyKey, descriptor) => {
@@ -38,6 +40,18 @@ function queryAll(selector, options = {}) {
38
40
  queries.push({ selector, options, propertyKey });
39
41
  Object.defineProperty(target, propertyKey, {
40
42
  get() {
43
+ const hostSet = import_Utils.SwcUtils.getHostSet(this);
44
+ if (selector === ":hosts")
45
+ return hostSet.$hosts;
46
+ if (selector === ":appHosts")
47
+ return hostSet.$appHosts;
48
+ const config = (0, import_elementDefine.getElementConfig)(this);
49
+ const win = config?.window || window;
50
+ const doc = win.document;
51
+ if (selector === ":window")
52
+ return [win];
53
+ if (selector === ":document")
54
+ return [doc];
41
55
  if (!selector || selector === ":host")
42
56
  return [this];
43
57
  const r = options.root || "auto";
@@ -55,6 +69,24 @@ function queryAll(selector, options = {}) {
55
69
  const root = this.shadowRoot || this;
56
70
  return root.querySelectorAll(selector);
57
71
  },
72
+ set(nv) {
73
+ if (nv === null || nv === void 0 || Array.isArray(nv) && nv.length === 0) {
74
+ const r = options.root || "auto";
75
+ let targets = [];
76
+ if (r === "shadow")
77
+ targets = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];
78
+ else if (r === "light")
79
+ targets = Array.from(this.querySelectorAll(selector));
80
+ else if (r === "all") {
81
+ const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];
82
+ const lNodes = Array.from(this.querySelectorAll(selector));
83
+ targets = [...sNodes, ...lNodes];
84
+ } else {
85
+ targets = Array.from((this.shadowRoot || this).querySelectorAll(selector));
86
+ }
87
+ targets.forEach((t) => t.remove());
88
+ }
89
+ },
58
90
  enumerable: true,
59
91
  configurable: true
60
92
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/decorators/queryAll.ts"],
4
- "sourcesContent": ["import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\n\nexport interface QueryAllOptions {\n root?: 'light' | 'shadow' | 'all' | 'auto';\n}\n\nexport interface QueryAllMetadata {\n selector: string;\n options: QueryAllOptions;\n propertyKey: string | symbol;\n}\n\nexport const QUERY_ALL_METADATA_KEY = Symbol('simple-web-component:query-all');\n\n/**\n * @queryAll decorator to inject a list of elements into a class property.\n * Usage: @queryAll('.items') list!: NodeListOf<HTMLElement>;\n * Usage: @queryAll('li', { root: 'shadow' }) list!: HTMLElement[];\n */\nexport function queryAll(selector: string, options: QueryAllOptions = {}): PropertyDecorator {\n return (target: Object, propertyKey: string | symbol, descriptor?: never): void => {\n if (descriptor !== undefined) {\n throw new Error(`@queryAll decorator cannot be used on methods. (Method: ${String(propertyKey)})`);\n }\n\n const constructor = target.constructor;\n let queries = ReflectUtils.getMetadata<QueryAllMetadata[]>(QUERY_ALL_METADATA_KEY, constructor);\n if (!queries) {\n queries = [];\n ReflectUtils.defineMetadata(QUERY_ALL_METADATA_KEY, queries, constructor);\n }\n queries.push({ selector, options, propertyKey });\n\n Object.defineProperty(target, propertyKey, {\n get(this: HTMLElement) {\n if (!selector || selector === ':host') return [this];\n const r = options.root || 'auto';\n\n if (r === 'shadow') {\n return this.shadowRoot ? this.shadowRoot.querySelectorAll(selector) : [];\n }\n if (r === 'light') {\n return this.querySelectorAll(selector);\n }\n if (r === 'all') {\n const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];\n const lNodes = Array.from(this.querySelectorAll(selector));\n return [...sNodes, ...lNodes];\n }\n // auto\n const root = this.shadowRoot || this;\n return root.querySelectorAll(selector);\n },\n enumerable: true,\n configurable: true\n });\n };\n}\n\nexport const getQueryAllMetadata = (target: any): QueryAllMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(QUERY_ALL_METADATA_KEY, constructor);\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;;;;;;;0BAA6B;AAYtB,MAAM,yBAAyB,OAAO,gCAAgC;AAOvE,SAAU,SAAS,UAAkB,UAA2B,CAAA,GAAE;AACtE,SAAO,CAAC,QAAgB,aAA8B,eAA4B;AAChF,QAAI,eAAe,QAAW;AAC5B,YAAM,IAAI,MAAM,2DAA2D,OAAO,WAAW,CAAC,GAAG;IACnG;AAEA,UAAM,cAAc,OAAO;AAC3B,QAAI,UAAU,iCAAa,YAAgC,wBAAwB,WAAW;AAC9F,QAAI,CAAC,SAAS;AACZ,gBAAU,CAAA;AACV,uCAAa,eAAe,wBAAwB,SAAS,WAAW;IAC1E;AACA,YAAQ,KAAK,EAAE,UAAU,SAAS,YAAW,CAAE;AAE/C,WAAO,eAAe,QAAQ,aAAa;MACzC,MAAG;AACD,YAAI,CAAC,YAAY,aAAa;AAAS,iBAAO,CAAC,IAAI;AACnD,cAAM,IAAI,QAAQ,QAAQ;AAE1B,YAAI,MAAM,UAAU;AAClB,iBAAO,KAAK,aAAa,KAAK,WAAW,iBAAiB,QAAQ,IAAI,CAAA;QACxE;AACA,YAAI,MAAM,SAAS;AACjB,iBAAO,KAAK,iBAAiB,QAAQ;QACvC;AACA,YAAI,MAAM,OAAO;AACf,gBAAM,SAAS,KAAK,aAAa,MAAM,KAAK,KAAK,WAAW,iBAAiB,QAAQ,CAAC,IAAI,CAAA;AAC1F,gBAAM,SAAS,MAAM,KAAK,KAAK,iBAAiB,QAAQ,CAAC;AACzD,iBAAO,CAAC,GAAG,QAAQ,GAAG,MAAM;QAC9B;AAEA,cAAM,OAAO,KAAK,cAAc;AAChC,eAAO,KAAK,iBAAiB,QAAQ;MACvC;MACA,YAAY;MACZ,cAAc;KACf;EACH;AACF;AAEO,MAAM,sBAAsB,CAAC,WAA+C;AACjF,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,iCAAa,YAAY,wBAAwB,WAAW;AACrE;",
4
+ "sourcesContent": ["import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\nimport { getElementConfig } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\n\nexport interface QueryAllOptions {\n root?: 'light' | 'shadow' | 'all' | 'auto';\n}\n\nexport interface QueryAllMetadata {\n selector: string;\n options: QueryAllOptions;\n propertyKey: string | symbol;\n}\n\nexport const QUERY_ALL_METADATA_KEY = Symbol('simple-web-component:query-all');\n\n/**\n * @queryAll decorator to inject a list of elements into a class property.\n */\nexport function queryAll(selector: string, options: QueryAllOptions = {}): PropertyDecorator {\n return (target: Object, propertyKey: string | symbol, descriptor?: never): void => {\n if (descriptor !== undefined) {\n throw new Error(`@queryAll decorator cannot be used on methods. (Method: ${String(propertyKey)})`);\n }\n\n const constructor = target.constructor;\n let queries = ReflectUtils.getMetadata<QueryAllMetadata[]>(QUERY_ALL_METADATA_KEY, constructor);\n if (!queries) {\n queries = [];\n ReflectUtils.defineMetadata(QUERY_ALL_METADATA_KEY, queries, constructor);\n }\n queries.push({ selector, options, propertyKey });\n\n Object.defineProperty(target, propertyKey, {\n get(this: HTMLElement) {\n // --- Special Selectors: HostSet ---\n const hostSet = SwcUtils.getHostSet(this);\n if (selector === ':hosts') return hostSet.$hosts;\n if (selector === ':appHosts') return hostSet.$appHosts;\n\n // --- Special Selectors: Env ---\n const config = getElementConfig(this);\n const win = config?.window || window;\n const doc = win.document;\n\n if (selector === ':window') return [win];\n if (selector === ':document') return [doc];\n if (!selector || selector === ':host') return [this];\n\n // --- Standard Selectors ---\n const r = options.root || 'auto';\n\n if (r === 'shadow') {\n return this.shadowRoot ? this.shadowRoot.querySelectorAll(selector) : [];\n }\n if (r === 'light') {\n return this.querySelectorAll(selector);\n }\n if (r === 'all') {\n const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];\n const lNodes = Array.from(this.querySelectorAll(selector));\n return [...sNodes, ...lNodes];\n }\n // auto\n const root = this.shadowRoot || this;\n return root.querySelectorAll(selector);\n },\n set(this: HTMLElement, nv: any) {\n if (nv === null || nv === undefined || (Array.isArray(nv) && nv.length === 0)) {\n const r = options.root || 'auto';\n let targets: (Element | Node)[] = [];\n if (r === 'shadow') targets = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];\n else if (r === 'light') targets = Array.from(this.querySelectorAll(selector));\n else if (r === 'all') {\n const sNodes = this.shadowRoot ? Array.from(this.shadowRoot.querySelectorAll(selector)) : [];\n const lNodes = Array.from(this.querySelectorAll(selector));\n targets = [...sNodes, ...lNodes];\n } else {\n targets = Array.from((this.shadowRoot || this).querySelectorAll(selector));\n }\n targets.forEach(t => (t as Element).remove());\n }\n },\n enumerable: true,\n configurable: true\n });\n };\n}\n\nexport const getQueryAllMetadata = (target: any): QueryAllMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(QUERY_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AC1F,gBAAM,SAAS,MAAM,KAAK,KAAK,iBAAiB,QAAQ,CAAC;AACzD,iBAAO,CAAC,GAAG,QAAQ,GAAG,MAAM;QAC9B;AAEA,cAAM,OAAO,KAAK,cAAc;AAChC,eAAO,KAAK,iBAAiB,QAAQ;MACvC;MACA,IAAuB,IAAO;AAC5B,YAAI,OAAO,QAAQ,OAAO,UAAc,MAAM,QAAQ,EAAE,KAAK,GAAG,WAAW,GAAI;AAC7E,gBAAM,IAAI,QAAQ,QAAQ;AAC1B,cAAI,UAA8B,CAAA;AAClC,cAAI,MAAM;AAAU,sBAAU,KAAK,aAAa,MAAM,KAAK,KAAK,WAAW,iBAAiB,QAAQ,CAAC,IAAI,CAAA;mBAChG,MAAM;AAAS,sBAAU,MAAM,KAAK,KAAK,iBAAiB,QAAQ,CAAC;mBACnE,MAAM,OAAO;AACpB,kBAAM,SAAS,KAAK,aAAa,MAAM,KAAK,KAAK,WAAW,iBAAiB,QAAQ,CAAC,IAAI,CAAA;AAC1F,kBAAM,SAAS,MAAM,KAAK,KAAK,iBAAiB,QAAQ,CAAC;AACzD,sBAAU,CAAC,GAAG,QAAQ,GAAG,MAAM;UACjC,OAAO;AACL,sBAAU,MAAM,MAAM,KAAK,cAAc,MAAM,iBAAiB,QAAQ,CAAC;UAC3E;AACA,kBAAQ,QAAQ,OAAM,EAAc,OAAM,CAAE;QAC9C;MACF;MACA,YAAY;MACZ,cAAc;KACf;EACH;AACF;AAEO,MAAM,sBAAsB,CAAC,WAA+C;AACjF,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,iCAAa,YAAY,wBAAwB,WAAW;AACrE;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,53 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var replaceChildren_exports = {};
19
+ __export(replaceChildren_exports, {
20
+ REPLACE_CHILDREN_METADATA_KEY: () => REPLACE_CHILDREN_METADATA_KEY,
21
+ findAllReplaceChildrenMetadata: () => findAllReplaceChildrenMetadata,
22
+ getReplaceChildrenMetadata: () => getReplaceChildrenMetadata,
23
+ replaceChildren: () => replaceChildren
24
+ });
25
+ module.exports = __toCommonJS(replaceChildren_exports);
26
+ var import_ReflectUtils = require("@dooboostore/core/reflect/ReflectUtils");
27
+ const REPLACE_CHILDREN_METADATA_KEY = Symbol("simple-web-component:replace-children");
28
+ function replaceChildren(selector) {
29
+ return (target, propertyKey) => {
30
+ const constructor = target.constructor;
31
+ let meta = import_ReflectUtils.ReflectUtils.getOwnMetadata(REPLACE_CHILDREN_METADATA_KEY, constructor);
32
+ if (!meta) {
33
+ meta = /* @__PURE__ */ new Map();
34
+ import_ReflectUtils.ReflectUtils.defineMetadata(REPLACE_CHILDREN_METADATA_KEY, meta, constructor);
35
+ }
36
+ meta.set(propertyKey, selector);
37
+ };
38
+ }
39
+ const getReplaceChildrenMetadata = (target) => {
40
+ const constructor = target instanceof Function ? target : target.constructor;
41
+ return import_ReflectUtils.ReflectUtils.getMetadata(REPLACE_CHILDREN_METADATA_KEY, constructor);
42
+ };
43
+ const findAllReplaceChildrenMetadata = (target) => {
44
+ const result = /* @__PURE__ */ new Map();
45
+ const maps = import_ReflectUtils.ReflectUtils.findAllMetadata(REPLACE_CHILDREN_METADATA_KEY, target);
46
+ maps.forEach((map) => {
47
+ if (map instanceof Map) {
48
+ map.forEach((v, k) => result.set(k, v));
49
+ }
50
+ });
51
+ return result;
52
+ };
53
+ //# sourceMappingURL=replaceChildren.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/decorators/replaceChildren.ts"],
4
+ "sourcesContent": ["import { ReflectUtils } from '@dooboostore/core/reflect/ReflectUtils';\n\nexport const REPLACE_CHILDREN_METADATA_KEY = Symbol('simple-web-component:replace-children');\n\n/**\n * @replaceChildren decorator to surgically replace children of a target element.\n * Usage: @replaceChildren('#container') renderPart() { return '<div>New Content</div>'; }\n */\nexport function replaceChildren(selector: string): MethodDecorator {\n return (target: Object, propertyKey: string | symbol) => {\n const constructor = target.constructor;\n let meta = ReflectUtils.getOwnMetadata(REPLACE_CHILDREN_METADATA_KEY, constructor) as Map<string | symbol, string>;\n if (!meta) {\n meta = new Map<string | symbol, string>();\n ReflectUtils.defineMetadata(REPLACE_CHILDREN_METADATA_KEY, meta, constructor);\n }\n meta.set(propertyKey, selector);\n };\n}\n\nexport const getReplaceChildrenMetadata = (target: any): Map<string | symbol, string> | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(REPLACE_CHILDREN_METADATA_KEY, constructor);\n};\n\nexport const findAllReplaceChildrenMetadata = (target: any): Map<string | symbol, string> => {\n const result = new Map<string | symbol, string>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, string>>(REPLACE_CHILDREN_METADATA_KEY, target);\n maps.forEach(map => {\n if (map instanceof Map) {\n map.forEach((v, k) => result.set(k, v));\n }\n });\n return result;\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA6B;AAEtB,MAAM,gCAAgC,OAAO,uCAAuC;AAMpF,SAAS,gBAAgB,UAAmC;AACjE,SAAO,CAAC,QAAgB,gBAAiC;AACvD,UAAM,cAAc,OAAO;AAC3B,QAAI,OAAO,iCAAa,eAAe,+BAA+B,WAAW;AACjF,QAAI,CAAC,MAAM;AACT,aAAO,oBAAI,IAA6B;AACxC,uCAAa,eAAe,+BAA+B,MAAM,WAAW;AAAA,IAC9E;AACA,SAAK,IAAI,aAAa,QAAQ;AAAA,EAChC;AACF;AAEO,MAAM,6BAA6B,CAAC,WAA0D;AACnG,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,iCAAa,YAAY,+BAA+B,WAAW;AAC5E;AAEO,MAAM,iCAAiC,CAAC,WAA8C;AAC3F,QAAM,SAAS,oBAAI,IAA6B;AAChD,QAAM,OAAO,iCAAa,gBAA8C,+BAA+B,MAAM;AAC7G,OAAK,QAAQ,SAAO;AAClB,QAAI,eAAe,KAAK;AACtB,UAAI,QAAQ,CAAC,GAAG,MAAM,OAAO,IAAI,GAAG,CAAC,CAAC;AAAA,IACxC;AAAA,EACF,CAAC;AACD,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -26,6 +26,7 @@ var import_HashRouter = require("@dooboostore/core-web/routers/HashRouter");
26
26
  var import_ElementRouter = require("../router/ElementRouter");
27
27
  var import_SimOption = require("@dooboostore/simple-boot/SimOption");
28
28
  var import_Router = require("@dooboostore/core-web/routers/Router");
29
+ var import_FunctionUtils = require("@dooboostore/core/function/FunctionUtils");
29
30
  class SwcAppEngine {
30
31
  constructor(host) {
31
32
  this.host = host;
@@ -38,7 +39,7 @@ class SwcAppEngine {
38
39
  const configStr = this.host.getAttribute("swc-get-application-config");
39
40
  if (!configStr) return;
40
41
  try {
41
- const userConfig = new Function(`return ${configStr}`).apply(this.host);
42
+ const userConfig = import_FunctionUtils.FunctionUtils.executeReturn({ script: configStr, context: this.host });
42
43
  if (userConfig && userConfig.rootRouter) {
43
44
  const _config = {
44
45
  routeType: "element",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/elements/SwcAppEngine.ts"],
4
- "sourcesContent": ["import { SimpleApplication } from '@dooboostore/simple-boot/SimpleApplication';\nimport { PathRouter } from '@dooboostore/core-web/routers/PathRouter';\nimport { HashRouter } from '@dooboostore/core-web/routers/HashRouter';\nimport { ElementRouter } from '../router/ElementRouter';\nimport { SimOption } from '@dooboostore/simple-boot/SimOption';\nimport { Router, RouterEventType } from '@dooboostore/core-web/routers/Router';\nimport { Subscription } from '@dooboostore/core/message/Subscription';\nimport { ConstructorType, Optional } from '@dooboostore/core/types';\n\nexport type SwcConfigType = {\n rootRouter: ConstructorType<any>;\n routeType: 'path' | 'hash' | 'element';\n path?: string;\n window: Window;\n};\n\nexport type SwcAttributeConfigType = Optional<SwcConfigType, 'routeType' | 'window'>;\n\nexport class SwcAppEngine {\n public simpleApplication?: SimpleApplication;\n public router?: Router;\n private routerSubscription?: Subscription;\n private _isInitialized = false;\n\n constructor(private host: HTMLElement) {}\n\n async connect() {\n if (this._isInitialized) return;\n this._isInitialized = true;\n\n // Wait for event loop to ensure attributes and global scripts are ready\n await new Promise(resolve => setTimeout(resolve, 0));\n\n const configStr = this.host.getAttribute('swc-get-application-config');\n if (!configStr) return;\n\n try {\n const userConfig: SwcAttributeConfigType = new Function(`return ${configStr}`).apply(this.host);\n if (userConfig && userConfig.rootRouter) {\n const _config: SwcConfigType = {\n routeType: 'element',\n window: window,\n ...userConfig\n } as SwcConfigType;\n\n // Router Selection\n if (_config.routeType === 'path') {\n this.router = new PathRouter({ window: _config.window, firstUrl: _config.path });\n } else if (_config.routeType === 'hash') {\n this.router = new HashRouter({ window: _config.window, firstUrl: _config.path });\n } else if (_config.routeType === 'element') {\n this.router = new ElementRouter({ window: _config.window, firstUrl: _config.path });\n }\n\n // Routing sync\n if (this.router) {\n this.routerSubscription = this.router.observable.subscribe((route: RouterEventType) => {\n if (route.triggerPoint === 'end') {\n this.simpleApplication?.routing(route.path);\n }\n });\n }\n\n // App start\n this.simpleApplication = new SimpleApplication(new SimOption({ excludeProxys: [Node], rootRouter: _config.rootRouter }));\n\n const otherInstanceSim = new Map<any, any>();\n if (this.router) otherInstanceSim.set(Router, this.router);\n this.simpleApplication.run(otherInstanceSim);\n\n // Rendering\n const data = this.simpleApplication.sim(_config.rootRouter);\n if (data instanceof Node) {\n if (this.host.shadowRoot) this.host.shadowRoot.replaceChildren(data);\n else this.host.replaceChildren(data);\n }\n\n if (_config.path) await this.router?.go(_config.path);\n }\n } catch (e) {\n console.error('[SWC-APP-ENGINE] Init failed:', e);\n }\n }\n\n disconnect() {\n this.routerSubscription?.unsubscribe();\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+BAAkC;AAClC,wBAA2B;AAC3B,wBAA2B;AAC3B,2BAA8B;AAC9B,uBAA0B;AAC1B,oBAAwC;AAajC,MAAM,aAAa;AAAA,EAMxB,YAAoB,MAAmB;AAAnB;AAFpB,SAAQ,iBAAiB;AAAA,EAEe;AAAA,EAExC,MAAM,UAAU;AACd,QAAI,KAAK,eAAgB;AACzB,SAAK,iBAAiB;AAGtB,UAAM,IAAI,QAAQ,aAAW,WAAW,SAAS,CAAC,CAAC;AAEnD,UAAM,YAAY,KAAK,KAAK,aAAa,4BAA4B;AACrE,QAAI,CAAC,UAAW;AAEhB,QAAI;AACF,YAAM,aAAqC,IAAI,SAAS,UAAU,SAAS,EAAE,EAAE,MAAM,KAAK,IAAI;AAC9F,UAAI,cAAc,WAAW,YAAY;AACvC,cAAM,UAAyB;AAAA,UAC7B,WAAW;AAAA,UACX;AAAA,UACA,GAAG;AAAA,QACL;AAGA,YAAI,QAAQ,cAAc,QAAQ;AAChC,eAAK,SAAS,IAAI,6BAAW,EAAE,QAAQ,QAAQ,QAAQ,UAAU,QAAQ,KAAK,CAAC;AAAA,QACjF,WAAW,QAAQ,cAAc,QAAQ;AACvC,eAAK,SAAS,IAAI,6BAAW,EAAE,QAAQ,QAAQ,QAAQ,UAAU,QAAQ,KAAK,CAAC;AAAA,QACjF,WAAW,QAAQ,cAAc,WAAW;AAC1C,eAAK,SAAS,IAAI,mCAAc,EAAE,QAAQ,QAAQ,QAAQ,UAAU,QAAQ,KAAK,CAAC;AAAA,QACpF;AAGA,YAAI,KAAK,QAAQ;AACf,eAAK,qBAAqB,KAAK,OAAO,WAAW,UAAU,CAAC,UAA2B;AACrF,gBAAI,MAAM,iBAAiB,OAAO;AAChC,mBAAK,mBAAmB,QAAQ,MAAM,IAAI;AAAA,YAC5C;AAAA,UACF,CAAC;AAAA,QACH;AAGA,aAAK,oBAAoB,IAAI,2CAAkB,IAAI,2BAAU,EAAE,eAAe,CAAC,IAAI,GAAG,YAAY,QAAQ,WAAW,CAAC,CAAC;AAEvH,cAAM,mBAAmB,oBAAI,IAAc;AAC3C,YAAI,KAAK,OAAQ,kBAAiB,IAAI,sBAAQ,KAAK,MAAM;AACzD,aAAK,kBAAkB,IAAI,gBAAgB;AAG3C,cAAM,OAAO,KAAK,kBAAkB,IAAI,QAAQ,UAAU;AAC1D,YAAI,gBAAgB,MAAM;AACxB,cAAI,KAAK,KAAK,WAAY,MAAK,KAAK,WAAW,gBAAgB,IAAI;AAAA,cAC9D,MAAK,KAAK,gBAAgB,IAAI;AAAA,QACrC;AAEA,YAAI,QAAQ,KAAM,OAAM,KAAK,QAAQ,GAAG,QAAQ,IAAI;AAAA,MACtD;AAAA,IACF,SAAS,GAAG;AACV,cAAQ,MAAM,iCAAiC,CAAC;AAAA,IAClD;AAAA,EACF;AAAA,EAEA,aAAa;AACX,SAAK,oBAAoB,YAAY;AAAA,EACvC;AACF;",
4
+ "sourcesContent": ["import { SimpleApplication } from '@dooboostore/simple-boot/SimpleApplication';\nimport { PathRouter } from '@dooboostore/core-web/routers/PathRouter';\nimport { HashRouter } from '@dooboostore/core-web/routers/HashRouter';\nimport { ElementRouter } from '../router/ElementRouter';\nimport { SimOption } from '@dooboostore/simple-boot/SimOption';\nimport { Router, RouterEventType } from '@dooboostore/core-web/routers/Router';\nimport { Subscription } from '@dooboostore/core/message/Subscription';\nimport { ConstructorType, Optional } from '@dooboostore/core/types';\nimport { FunctionUtils } from '@dooboostore/core/function/FunctionUtils';\n\nexport type SwcConfigType = {\n rootRouter: ConstructorType<any>;\n routeType: 'path' | 'hash' | 'element';\n path?: string;\n window: Window;\n};\n\nexport type SwcAttributeConfigType = Optional<SwcConfigType, 'routeType' | 'window'>;\n\nexport class SwcAppEngine {\n public simpleApplication?: SimpleApplication;\n public router?: Router;\n private routerSubscription?: Subscription;\n private _isInitialized = false;\n\n constructor(private host: HTMLElement) {}\n\n async connect() {\n if (this._isInitialized) return;\n this._isInitialized = true;\n\n // Wait for event loop to ensure attributes and global scripts are ready\n await new Promise(resolve => setTimeout(resolve, 0));\n\n const configStr = this.host.getAttribute('swc-get-application-config');\n if (!configStr) return;\n\n try {\n const userConfig: SwcAttributeConfigType = FunctionUtils.executeReturn({ script: configStr, context: this.host });\n if (userConfig && userConfig.rootRouter) {\n const _config: SwcConfigType = {\n routeType: 'element',\n window: window,\n ...userConfig\n } as SwcConfigType;\n\n // Router Selection\n if (_config.routeType === 'path') {\n this.router = new PathRouter({ window: _config.window, firstUrl: _config.path });\n } else if (_config.routeType === 'hash') {\n this.router = new HashRouter({ window: _config.window, firstUrl: _config.path });\n } else if (_config.routeType === 'element') {\n this.router = new ElementRouter({ window: _config.window, firstUrl: _config.path });\n }\n\n // Routing sync\n if (this.router) {\n this.routerSubscription = this.router.observable.subscribe((route: RouterEventType) => {\n if (route.triggerPoint === 'end') {\n this.simpleApplication?.routing(route.path);\n }\n });\n }\n\n // App start\n this.simpleApplication = new SimpleApplication(new SimOption({ excludeProxys: [Node], rootRouter: _config.rootRouter }));\n\n const otherInstanceSim = new Map<any, any>();\n if (this.router) otherInstanceSim.set(Router, this.router);\n this.simpleApplication.run(otherInstanceSim);\n\n // Rendering\n const data = this.simpleApplication.sim(_config.rootRouter);\n if (data instanceof Node) {\n if (this.host.shadowRoot) this.host.shadowRoot.replaceChildren(data);\n else this.host.replaceChildren(data);\n }\n\n if (_config.path) await this.router?.go(_config.path);\n }\n } catch (e) {\n console.error('[SWC-APP-ENGINE] Init failed:', e);\n }\n }\n\n disconnect() {\n this.routerSubscription?.unsubscribe();\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+BAAkC;AAClC,wBAA2B;AAC3B,wBAA2B;AAC3B,2BAA8B;AAC9B,uBAA0B;AAC1B,oBAAwC;AAGxC,2BAA8B;AAWvB,MAAM,aAAa;AAAA,EAMxB,YAAoB,MAAmB;AAAnB;AAFpB,SAAQ,iBAAiB;AAAA,EAEe;AAAA,EAExC,MAAM,UAAU;AACd,QAAI,KAAK,eAAgB;AACzB,SAAK,iBAAiB;AAGtB,UAAM,IAAI,QAAQ,aAAW,WAAW,SAAS,CAAC,CAAC;AAEnD,UAAM,YAAY,KAAK,KAAK,aAAa,4BAA4B;AACrE,QAAI,CAAC,UAAW;AAEhB,QAAI;AACF,YAAM,aAAqC,mCAAc,cAAc,EAAE,QAAQ,WAAW,SAAS,KAAK,KAAK,CAAC;AAChH,UAAI,cAAc,WAAW,YAAY;AACvC,cAAM,UAAyB;AAAA,UAC7B,WAAW;AAAA,UACX;AAAA,UACA,GAAG;AAAA,QACL;AAGA,YAAI,QAAQ,cAAc,QAAQ;AAChC,eAAK,SAAS,IAAI,6BAAW,EAAE,QAAQ,QAAQ,QAAQ,UAAU,QAAQ,KAAK,CAAC;AAAA,QACjF,WAAW,QAAQ,cAAc,QAAQ;AACvC,eAAK,SAAS,IAAI,6BAAW,EAAE,QAAQ,QAAQ,QAAQ,UAAU,QAAQ,KAAK,CAAC;AAAA,QACjF,WAAW,QAAQ,cAAc,WAAW;AAC1C,eAAK,SAAS,IAAI,mCAAc,EAAE,QAAQ,QAAQ,QAAQ,UAAU,QAAQ,KAAK,CAAC;AAAA,QACpF;AAGA,YAAI,KAAK,QAAQ;AACf,eAAK,qBAAqB,KAAK,OAAO,WAAW,UAAU,CAAC,UAA2B;AACrF,gBAAI,MAAM,iBAAiB,OAAO;AAChC,mBAAK,mBAAmB,QAAQ,MAAM,IAAI;AAAA,YAC5C;AAAA,UACF,CAAC;AAAA,QACH;AAGA,aAAK,oBAAoB,IAAI,2CAAkB,IAAI,2BAAU,EAAE,eAAe,CAAC,IAAI,GAAG,YAAY,QAAQ,WAAW,CAAC,CAAC;AAEvH,cAAM,mBAAmB,oBAAI,IAAc;AAC3C,YAAI,KAAK,OAAQ,kBAAiB,IAAI,sBAAQ,KAAK,MAAM;AACzD,aAAK,kBAAkB,IAAI,gBAAgB;AAG3C,cAAM,OAAO,KAAK,kBAAkB,IAAI,QAAQ,UAAU;AAC1D,YAAI,gBAAgB,MAAM;AACxB,cAAI,KAAK,KAAK,WAAY,MAAK,KAAK,WAAW,gBAAgB,IAAI;AAAA,cAC9D,MAAK,KAAK,gBAAgB,IAAI;AAAA,QACrC;AAEA,YAAI,QAAQ,KAAM,OAAM,KAAK,QAAQ,GAAG,QAAQ,IAAI;AAAA,MACtD;AAAA,IACF,SAAS,GAAG;AACV,cAAQ,MAAM,iCAAiC,CAAC;AAAA,IAClD;AAAA,EACF;AAAA,EAEA,aAAa;AACX,SAAK,oBAAoB,YAAY;AAAA,EACvC;AACF;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,188 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var SwcAsync_exports = {};
19
+ __export(SwcAsync_exports, {
20
+ SwcAsync: () => SwcAsync
21
+ });
22
+ module.exports = __toCommonJS(SwcAsync_exports);
23
+ var import_elementDefine = require("../decorators/elementDefine");
24
+ var import_changedAttribute = require("../decorators/changedAttribute");
25
+ var import_Utils = require("../utils/Utils");
26
+ var import_FunctionUtils = require("@dooboostore/core/function/FunctionUtils");
27
+ var __decorate = function(decorators, target, key, desc) {
28
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
29
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
30
+ 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;
31
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
32
+ };
33
+ var __metadata = function(k, v) {
34
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
35
+ };
36
+ let SwcAsync = class SwcAsync2 extends HTMLTemplateElement {
37
+ constructor() {
38
+ super(...arguments);
39
+ this._nodes = [];
40
+ this._currentPromise = null;
41
+ this._value = null;
42
+ }
43
+ get value() {
44
+ return this._value;
45
+ }
46
+ set value(nv) {
47
+ if (nv instanceof Promise) {
48
+ this.handlePromise(nv);
49
+ } else {
50
+ this._value = nv;
51
+ this.render(nv === null ? "default" : "success", nv);
52
+ }
53
+ }
54
+ refresh(newValue) {
55
+ const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
56
+ if (!script) {
57
+ this.value = null;
58
+ return;
59
+ }
60
+ if (!this.parentElement)
61
+ return;
62
+ const helperHostSet = import_Utils.SwcUtils.getHelperAndHostSet(window, this);
63
+ try {
64
+ const result = import_FunctionUtils.FunctionUtils.executeReturn({
65
+ script,
66
+ context: this,
67
+ args: helperHostSet
68
+ });
69
+ if (result instanceof Promise) {
70
+ this.handlePromise(result);
71
+ } else {
72
+ this.value = result;
73
+ }
74
+ } catch (e) {
75
+ this.render("error", e);
76
+ }
77
+ }
78
+ async handlePromise(promise) {
79
+ this._currentPromise = promise;
80
+ this.render("loading");
81
+ try {
82
+ const result = await promise;
83
+ if (this._currentPromise !== promise)
84
+ return;
85
+ this._value = result;
86
+ this.render("success", result);
87
+ } catch (e) {
88
+ if (this._currentPromise !== promise)
89
+ return;
90
+ this.render("error", e);
91
+ }
92
+ }
93
+ render(state, data) {
94
+ this.cleanup();
95
+ if (!this.parentElement)
96
+ return;
97
+ let fragment;
98
+ const ctx = {
99
+ $nodes: [],
100
+ $elements: [],
101
+ $state: state,
102
+ $value: null,
103
+ $error: null
104
+ };
105
+ if (state === "default") {
106
+ const t = this.content.querySelector('template[is="swc-default"]');
107
+ fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
108
+ } else if (state === "loading") {
109
+ const t = this.content.querySelector('template[is="swc-loading"]');
110
+ fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
111
+ } else if (state === "error") {
112
+ const t = this.content.querySelector('template[is="swc-error"]');
113
+ ctx.$error = data;
114
+ fragment = t ? t.content.cloneNode(true) : document.createDocumentFragment();
115
+ } else {
116
+ const t = this.content.querySelector('template[is="swc-success"]');
117
+ ctx.$value = data;
118
+ if (t) {
119
+ fragment = t.content.cloneNode(true);
120
+ } else {
121
+ const clone = this.content.cloneNode(true);
122
+ Array.from(clone.querySelectorAll('template[is="swc-loading"], template[is="swc-error"], template[is="swc-success"], template[is="swc-default"]')).forEach((tmp) => tmp.remove());
123
+ fragment = clone;
124
+ }
125
+ }
126
+ this.mount(fragment, ctx);
127
+ }
128
+ mount(fragment, ctx) {
129
+ const nodes = Array.from(fragment.childNodes);
130
+ const elements = nodes.filter((n) => n.nodeType === 1);
131
+ Object.assign(ctx, {
132
+ $nodes: nodes,
133
+ $elements: elements,
134
+ $firstNode: nodes[0],
135
+ $lastNode: nodes[nodes.length - 1],
136
+ $firstElement: elements[0],
137
+ $lastElement: elements[elements.length - 1]
138
+ });
139
+ this._executeCallback("on-clone-nodes", ctx);
140
+ nodes.forEach((node, nodeIndex) => {
141
+ if (node instanceof HTMLElement) {
142
+ node.__swc_host = this;
143
+ }
144
+ this._executeCallback("on-clone-node", {
145
+ ...ctx,
146
+ $node: node,
147
+ $nodeIndex: nodeIndex,
148
+ $isElement: node.nodeType === 1
149
+ });
150
+ });
151
+ this._nodes = nodes;
152
+ this.parentElement?.insertBefore(fragment, this.nextSibling);
153
+ }
154
+ _executeCallback(attrName, extraArgs) {
155
+ const script = this.getAttribute(attrName);
156
+ if (!script)
157
+ return;
158
+ const helperHostSet = import_Utils.SwcUtils.getHelperAndHostSet(window, this);
159
+ try {
160
+ import_FunctionUtils.FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
161
+ } catch (e) {
162
+ console.error(`[SwcAsync] Error in ${attrName}:`, e);
163
+ }
164
+ }
165
+ cleanup() {
166
+ this._nodes.forEach((n) => {
167
+ if (n.parentElement)
168
+ n.parentElement.removeChild(n);
169
+ });
170
+ this._nodes = [];
171
+ }
172
+ connectedCallback() {
173
+ this.refresh();
174
+ }
175
+ disconnectedCallback() {
176
+ this.cleanup();
177
+ }
178
+ };
179
+ __decorate([
180
+ (0, import_changedAttribute.changedAttribute)("on-get-value"),
181
+ __metadata("design:type", Function),
182
+ __metadata("design:paramtypes", [String]),
183
+ __metadata("design:returntype", void 0)
184
+ ], SwcAsync.prototype, "refresh", null);
185
+ SwcAsync = __decorate([
186
+ (0, import_elementDefine.elementDefine)({ name: "swc-async", extends: "template" })
187
+ ], SwcAsync);
188
+ //# sourceMappingURL=SwcAsync.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/elements/SwcAsync.ts"],
4
+ "sourcesContent": ["import { elementDefine } from '../decorators/elementDefine';\nimport { changedAttribute } from '../decorators/changedAttribute';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core/function/FunctionUtils';\nimport { SwcLoading, SwcError, SwcSuccess, SwcDefault } from './SwcSubTemplates';\n\n@elementDefine({ name: 'swc-async', extends: 'template' })\nexport class SwcAsync extends HTMLTemplateElement {\n private _nodes: Node[] = [];\n private _currentPromise: Promise<any> | null = null;\n private _value: any = null;\n\n get value(): any {\n return this._value;\n }\n\n set value(nv: any) {\n if (nv instanceof Promise) {\n this.handlePromise(nv);\n } else {\n this._value = nv;\n this.render(nv === null ? 'default' : 'success', nv);\n }\n }\n\n @changedAttribute('on-get-value')\n private refresh(newValue?: string | null) {\n const script = newValue !== undefined ? newValue : this.getAttribute('on-get-value');\n if (!script) {\n this.value = null; // Triggers default render\n return;\n }\n if (!this.parentElement) return;\n\n const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);\n try {\n const result = FunctionUtils.executeReturn({\n script,\n context: this,\n args: helperHostSet\n });\n\n if (result instanceof Promise) {\n this.handlePromise(result);\n } else {\n this.value = result;\n }\n } catch (e) {\n this.render('error', e);\n }\n }\n\n private async handlePromise(promise: Promise<any>) {\n this._currentPromise = promise;\n this.render('loading');\n\n try {\n const result = await promise;\n if (this._currentPromise !== promise) return;\n this._value = result;\n this.render('success', result);\n } catch (e) {\n if (this._currentPromise !== promise) return;\n this.render('error', e);\n }\n }\n\n private render(state: 'loading' | 'error' | 'success' | 'default', data?: any) {\n this.cleanup();\n if (!this.parentElement) return;\n\n let fragment: DocumentFragment;\n const ctx: any = {\n $nodes: [],\n $elements: [],\n $state: state,\n $value: null,\n $error: null\n };\n\n if (state === 'default') {\n const t = this.content.querySelector('template[is=\"swc-default\"]') as HTMLTemplateElement;\n fragment = t ? (t.content.cloneNode(true) as DocumentFragment) : document.createDocumentFragment();\n } else if (state === 'loading') {\n const t = this.content.querySelector('template[is=\"swc-loading\"]') as HTMLTemplateElement;\n fragment = t ? (t.content.cloneNode(true) as DocumentFragment) : document.createDocumentFragment();\n } else if (state === 'error') {\n const t = this.content.querySelector('template[is=\"swc-error\"]') as HTMLTemplateElement;\n ctx.$error = data;\n fragment = t ? (t.content.cloneNode(true) as DocumentFragment) : document.createDocumentFragment();\n } else {\n // Success\n const t = this.content.querySelector('template[is=\"swc-success\"]') as HTMLTemplateElement;\n ctx.$value = data;\n if (t) {\n fragment = t.content.cloneNode(true) as DocumentFragment;\n } else {\n const clone = this.content.cloneNode(true) as DocumentFragment;\n Array.from(clone.querySelectorAll('template[is=\"swc-loading\"], template[is=\"swc-error\"], template[is=\"swc-success\"], template[is=\"swc-default\"]')).forEach(tmp => tmp.remove());\n fragment = clone;\n }\n }\n\n this.mount(fragment, ctx);\n }\n\n private mount(fragment: DocumentFragment, ctx: any) {\n const nodes = Array.from(fragment.childNodes);\n const elements = nodes.filter(n => n.nodeType === 1) as HTMLElement[];\n\n Object.assign(ctx, {\n $nodes: nodes,\n $elements: elements,\n $firstNode: nodes[0],\n $lastNode: nodes[nodes.length - 1],\n $firstElement: elements[0],\n $lastElement: elements[elements.length - 1]\n });\n\n // Execution Callbacks\n this._executeCallback('on-clone-nodes', ctx);\n nodes.forEach((node, nodeIndex) => {\n if (node instanceof HTMLElement) {\n (node as any).__swc_host = this;\n }\n this._executeCallback('on-clone-node', {\n ...ctx,\n $node: node,\n $nodeIndex: nodeIndex,\n $isElement: node.nodeType === 1\n });\n });\n\n this._nodes = nodes;\n this.parentElement?.insertBefore(fragment, this.nextSibling);\n }\n\n private _executeCallback(attrName: string, extraArgs: Record<string, any>) {\n const script = this.getAttribute(attrName);\n if (!script) return;\n const helperHostSet = SwcUtils.getHelperAndHostSet(window, this);\n try {\n FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });\n } catch (e) {\n console.error(`[SwcAsync] Error in ${attrName}:`, e);\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => {\n if (n.parentElement) n.parentElement.removeChild(n);\n });\n this._nodes = [];\n }\n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iB,kBAAkB,GAAG;AAC3C,UAAM,QAAQ,CAAC,MAAM,cAAa;AAChC,UAAI,gBAAgB,aAAa;AAC9B,aAAa,aAAa;MAC7B;AACA,WAAK,iBAAiB,iBAAiB;QACrC,GAAG;QACH,OAAO;QACP,YAAY;QACZ,YAAY,KAAK,aAAa;OAC/B;IACH,CAAC;AAED,SAAK,SAAS;AACd,SAAK,eAAe,aAAa,UAAU,KAAK,WAAW;EAC7D;EAEQ,iBAAiB,UAAkB,WAA8B;AACvE,UAAM,SAAS,KAAK,aAAa,QAAQ;AACzC,QAAI,CAAC;AAAQ;AACb,UAAM,gBAAgB,sBAAS,oBAAoB,QAAQ,IAAI;AAC/D,QAAI;AACF,yCAAc,QAAQ,EAAE,QAAQ,SAAS,MAAM,MAAM,EAAE,GAAG,eAAe,GAAG,UAAS,EAAE,CAAE;IAC3F,SAAS,GAAG;AACV,cAAQ,MAAM,uBAAuB,QAAQ,KAAK,CAAC;IACrD;EACF;EAEQ,UAAO;AACb,SAAK,OAAO,QAAQ,OAAI;AACtB,UAAI,EAAE;AAAe,UAAE,cAAc,YAAY,CAAC;IACpD,CAAC;AACD,SAAK,SAAS,CAAA;EAChB;EAEA,oBAAiB;AACf,SAAK,QAAO;EACd;EAEA,uBAAoB;AAClB,SAAK,QAAO;EACd;;AAvIQ,WAAA;MADP,0CAAiB,cAAc;;;;;AAlBrB,WAAQ,WAAA;MADpB,oCAAc,EAAE,MAAM,aAAa,SAAS,WAAU,CAAE;GAC5C,QAAQ;",
6
+ "names": ["SwcAsync"]
7
+ }
@@ -0,0 +1,155 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var SwcChoose_exports = {};
19
+ __export(SwcChoose_exports, {
20
+ SwcChoose: () => SwcChoose
21
+ });
22
+ module.exports = __toCommonJS(SwcChoose_exports);
23
+ var import_elementDefine = require("../decorators/elementDefine");
24
+ var import_changedAttribute = require("../decorators/changedAttribute");
25
+ var import_Utils = require("../utils/Utils");
26
+ var import_FunctionUtils = require("@dooboostore/core/function/FunctionUtils");
27
+ var __decorate = function(decorators, target, key, desc) {
28
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
29
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
30
+ 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;
31
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
32
+ };
33
+ var __metadata = function(k, v) {
34
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
35
+ };
36
+ let SwcChoose = class SwcChoose2 extends HTMLTemplateElement {
37
+ constructor() {
38
+ super(...arguments);
39
+ this._nodes = [];
40
+ this._value = null;
41
+ }
42
+ get value() {
43
+ return this._value;
44
+ }
45
+ set value(nv) {
46
+ this._value = nv;
47
+ this.render();
48
+ }
49
+ _executeCallback(attrName, extraArgs) {
50
+ const script = this.getAttribute(attrName);
51
+ if (!script)
52
+ return;
53
+ const helperHostSet = import_Utils.SwcUtils.getHelperAndHostSet(window, this);
54
+ try {
55
+ import_FunctionUtils.FunctionUtils.execute({ script, context: this, args: { ...helperHostSet, ...extraArgs } });
56
+ } catch (e) {
57
+ console.error(`[SwcChoose] Error in ${attrName}:`, e);
58
+ }
59
+ }
60
+ refresh(newValue) {
61
+ const script = newValue !== void 0 ? newValue : this.getAttribute("on-get-value");
62
+ if (!script) {
63
+ this.value = null;
64
+ return;
65
+ }
66
+ if (!this.parentElement)
67
+ return;
68
+ const helperHostSet = import_Utils.SwcUtils.getHelperAndHostSet(window, this);
69
+ try {
70
+ const result = import_FunctionUtils.FunctionUtils.executeReturn({
71
+ script,
72
+ context: this,
73
+ args: helperHostSet
74
+ });
75
+ this.value = result;
76
+ } catch (e) {
77
+ console.error("[SwcChoose] Error in on-get-value:", e);
78
+ }
79
+ }
80
+ render() {
81
+ this.cleanup();
82
+ if (!this.parentElement)
83
+ return;
84
+ const templates = Array.from(this.content.querySelectorAll("template"));
85
+ let selected = null;
86
+ let otherwise = null;
87
+ let defaultTmp = null;
88
+ for (const t of templates) {
89
+ const is = t.getAttribute("is");
90
+ if (is === "swc-when") {
91
+ const whenVal = t.getAttribute("value");
92
+ if (String(whenVal) === String(this._value)) {
93
+ selected = t;
94
+ break;
95
+ }
96
+ } else if (is === "swc-otherwise") {
97
+ otherwise = t;
98
+ } else if (is === "swc-default") {
99
+ defaultTmp = t;
100
+ }
101
+ }
102
+ const targetTemplate = (this._value == null ? defaultTmp : selected) || otherwise || defaultTmp;
103
+ if (targetTemplate) {
104
+ const clone = targetTemplate.content.cloneNode(true);
105
+ const nodes = Array.from(clone.childNodes);
106
+ const elements = nodes.filter((n) => n.nodeType === 1);
107
+ const ctx = {
108
+ $value: this._value,
109
+ $nodes: nodes,
110
+ $elements: elements,
111
+ $firstNode: nodes[0],
112
+ $lastNode: nodes[nodes.length - 1],
113
+ $firstElement: elements[0],
114
+ $lastElement: elements[elements.length - 1]
115
+ };
116
+ this._executeCallback("on-clone-nodes", ctx);
117
+ nodes.forEach((node, nodeIndex) => {
118
+ if (node instanceof HTMLElement) {
119
+ node.__swc_host = this;
120
+ }
121
+ this._executeCallback("on-clone-node", {
122
+ ...ctx,
123
+ $node: node,
124
+ $nodeIndex: nodeIndex,
125
+ $isElement: node.nodeType === 1
126
+ });
127
+ });
128
+ this._nodes = nodes;
129
+ this.parentElement.insertBefore(clone, this.nextSibling);
130
+ }
131
+ }
132
+ cleanup() {
133
+ this._nodes.forEach((n) => {
134
+ if (n.parentElement)
135
+ n.parentElement.removeChild(n);
136
+ });
137
+ this._nodes = [];
138
+ }
139
+ connectedCallback() {
140
+ this.refresh();
141
+ }
142
+ disconnectedCallback() {
143
+ this.cleanup();
144
+ }
145
+ };
146
+ __decorate([
147
+ (0, import_changedAttribute.changedAttribute)("on-get-value"),
148
+ __metadata("design:type", Function),
149
+ __metadata("design:paramtypes", [String]),
150
+ __metadata("design:returntype", void 0)
151
+ ], SwcChoose.prototype, "refresh", null);
152
+ SwcChoose = __decorate([
153
+ (0, import_elementDefine.elementDefine)({ name: "swc-choose", extends: "template" })
154
+ ], SwcChoose);
155
+ //# sourceMappingURL=SwcChoose.js.map