@dooboostore/simple-web-component 1.0.37 → 1.0.38

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 (156) hide show
  1. package/README.md +384 -93
  2. package/dist/cjs/SwcAppEngine.js +3 -0
  3. package/dist/cjs/SwcAppEngine.js.map +2 -2
  4. package/dist/cjs/decorators/addEventListener.js +20 -4
  5. package/dist/cjs/decorators/addEventListener.js.map +2 -2
  6. package/dist/cjs/decorators/applyAttribute.js.map +1 -1
  7. package/dist/cjs/decorators/applyClass.js.map +1 -1
  8. package/dist/cjs/decorators/applyNode.js +97 -15
  9. package/dist/cjs/decorators/applyNode.js.map +2 -2
  10. package/dist/cjs/decorators/applySlot.js +16 -9
  11. package/dist/cjs/decorators/applySlot.js.map +2 -2
  12. package/dist/cjs/decorators/applyStyle.js.map +2 -2
  13. package/dist/cjs/decorators/attribute.js.map +1 -1
  14. package/dist/cjs/decorators/elementDefine.js +68 -38
  15. package/dist/cjs/decorators/elementDefine.js.map +2 -2
  16. package/dist/cjs/decorators/emitCustomEvent.js.map +1 -1
  17. package/dist/cjs/decorators/index.js +1 -0
  18. package/dist/cjs/decorators/index.js.map +2 -2
  19. package/dist/cjs/decorators/lifecycles.js +47 -31
  20. package/dist/cjs/decorators/lifecycles.js.map +3 -3
  21. package/dist/cjs/decorators/publishSwcAppMessage.js.map +2 -2
  22. package/dist/cjs/decorators/query.js +1 -1
  23. package/dist/cjs/decorators/query.js.map +2 -2
  24. package/dist/cjs/decorators/queryAll.js.map +1 -1
  25. package/dist/cjs/decorators/setProperty.js.map +1 -1
  26. package/dist/cjs/decorators/state.js +84 -0
  27. package/dist/cjs/decorators/state.js.map +7 -0
  28. package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
  29. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  30. package/dist/cjs/elements/SwcApp.js +193 -305
  31. package/dist/cjs/elements/SwcApp.js.map +3 -3
  32. package/dist/cjs/elements/SwcAppMixin.js +291 -0
  33. package/dist/cjs/elements/SwcAppMixin.js.map +7 -0
  34. package/dist/cjs/elements/index.js +3 -21
  35. package/dist/cjs/elements/index.js.map +3 -3
  36. package/dist/cjs/index.js +1 -3
  37. package/dist/cjs/index.js.map +2 -2
  38. package/dist/cjs/{types.js → types/index.js} +1 -1
  39. package/dist/cjs/types/index.js.map +7 -0
  40. package/dist/cjs/types/window.d.js.map +1 -1
  41. package/dist/cjs/utils/Utils.js +159 -20
  42. package/dist/cjs/utils/Utils.js.map +3 -3
  43. package/dist/esm/SwcAppEngine.js +3 -0
  44. package/dist/esm/SwcAppEngine.js.map +2 -2
  45. package/dist/esm/decorators/addEventListener.js +20 -4
  46. package/dist/esm/decorators/addEventListener.js.map +2 -2
  47. package/dist/esm/decorators/applyAttribute.js.map +1 -1
  48. package/dist/esm/decorators/applyClass.js.map +1 -1
  49. package/dist/esm/decorators/applyNode.js +97 -15
  50. package/dist/esm/decorators/applyNode.js.map +2 -2
  51. package/dist/esm/decorators/applySlot.js +16 -9
  52. package/dist/esm/decorators/applySlot.js.map +2 -2
  53. package/dist/esm/decorators/applyStyle.js.map +2 -2
  54. package/dist/esm/decorators/attribute.js.map +1 -1
  55. package/dist/esm/decorators/elementDefine.js +72 -42
  56. package/dist/esm/decorators/elementDefine.js.map +2 -2
  57. package/dist/esm/decorators/emitCustomEvent.js.map +1 -1
  58. package/dist/esm/decorators/index.js +1 -0
  59. package/dist/esm/decorators/index.js.map +2 -2
  60. package/dist/esm/decorators/lifecycles.js +47 -31
  61. package/dist/esm/decorators/lifecycles.js.map +3 -3
  62. package/dist/esm/decorators/publishSwcAppMessage.js.map +2 -2
  63. package/dist/esm/decorators/query.js +1 -1
  64. package/dist/esm/decorators/query.js.map +2 -2
  65. package/dist/esm/decorators/queryAll.js.map +1 -1
  66. package/dist/esm/decorators/setProperty.js.map +1 -1
  67. package/dist/esm/decorators/state.js +65 -0
  68. package/dist/esm/decorators/state.js.map +7 -0
  69. package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
  70. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  71. package/dist/esm/elements/SwcApp.js +195 -307
  72. package/dist/esm/elements/SwcApp.js.map +3 -3
  73. package/dist/esm/elements/SwcAppMixin.js +273 -0
  74. package/dist/esm/elements/SwcAppMixin.js.map +7 -0
  75. package/dist/esm/elements/index.js +2 -7
  76. package/dist/esm/elements/index.js.map +2 -2
  77. package/dist/esm/index.js +2 -4
  78. package/dist/esm/index.js.map +2 -2
  79. package/dist/esm/{types.js → types/index.js} +1 -1
  80. package/dist/esm/types/index.js.map +7 -0
  81. package/dist/esm/utils/Utils.js +159 -20
  82. package/dist/esm/utils/Utils.js.map +3 -3
  83. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +3356 -2477
  84. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  85. package/dist/types/SwcAppEngine.d.ts +1 -1
  86. package/dist/types/SwcAppEngine.d.ts.map +1 -1
  87. package/dist/types/decorators/addEventListener.d.ts +5 -2
  88. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  89. package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
  90. package/dist/types/decorators/applyClass.d.ts.map +1 -1
  91. package/dist/types/decorators/applyNode.d.ts +22 -6
  92. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  93. package/dist/types/decorators/applySlot.d.ts.map +1 -1
  94. package/dist/types/decorators/applyStyle.d.ts.map +1 -1
  95. package/dist/types/decorators/attribute.d.ts.map +1 -1
  96. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  97. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  98. package/dist/types/decorators/index.d.ts +1 -0
  99. package/dist/types/decorators/index.d.ts.map +1 -1
  100. package/dist/types/decorators/lifecycles.d.ts +10 -14
  101. package/dist/types/decorators/lifecycles.d.ts.map +1 -1
  102. package/dist/types/decorators/publishSwcAppMessage.d.ts.map +1 -1
  103. package/dist/types/decorators/query.d.ts +1 -1
  104. package/dist/types/decorators/query.d.ts.map +1 -1
  105. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  106. package/dist/types/decorators/setProperty.d.ts +1 -1
  107. package/dist/types/decorators/setProperty.d.ts.map +1 -1
  108. package/dist/types/decorators/state.d.ts +9 -0
  109. package/dist/types/decorators/state.d.ts.map +1 -0
  110. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
  111. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +5 -1
  112. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
  113. package/dist/types/elements/SwcApp.d.ts +35 -6
  114. package/dist/types/elements/SwcApp.d.ts.map +1 -1
  115. package/dist/types/elements/SwcAppMixin.d.ts +405 -0
  116. package/dist/types/elements/SwcAppMixin.d.ts.map +1 -0
  117. package/dist/types/elements/index.d.ts +2 -2
  118. package/dist/types/elements/index.d.ts.map +1 -1
  119. package/dist/types/index.d.ts +1 -1
  120. package/dist/types/index.d.ts.map +1 -1
  121. package/dist/types/{types.d.ts → types/index.d.ts} +11 -11
  122. package/dist/types/types/index.d.ts.map +1 -0
  123. package/dist/types/utils/Utils.d.ts +14 -2
  124. package/dist/types/utils/Utils.d.ts.map +1 -1
  125. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +3358 -2479
  126. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  127. package/package.json +4 -4
  128. package/src/SwcAppEngine.ts +6 -2
  129. package/src/decorators/addEventListener.ts +21 -5
  130. package/src/decorators/applyAttribute.ts +1 -1
  131. package/src/decorators/applyClass.ts +1 -1
  132. package/src/decorators/applyNode.ts +180 -62
  133. package/src/decorators/applySlot.ts +27 -67
  134. package/src/decorators/applyStyle.ts +4 -4
  135. package/src/decorators/attribute.ts +1 -1
  136. package/src/decorators/elementDefine.ts +110 -58
  137. package/src/decorators/emitCustomEvent.ts +1 -1
  138. package/src/decorators/index.ts +2 -0
  139. package/src/decorators/lifecycles.ts +50 -26
  140. package/src/decorators/publishSwcAppMessage.ts +2 -3
  141. package/src/decorators/query.ts +4 -4
  142. package/src/decorators/queryAll.ts +1 -1
  143. package/src/decorators/setProperty.ts +1 -1
  144. package/src/decorators/state.ts +84 -0
  145. package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +1 -1
  146. package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +4 -3
  147. package/src/elements/SwcApp.ts +239 -441
  148. package/src/elements/SwcAppMixin.ts +328 -0
  149. package/src/elements/index.ts +2 -9
  150. package/src/index.ts +2 -4
  151. package/src/{types.ts → types/index.ts} +13 -10
  152. package/src/types/window.d.ts +3 -0
  153. package/src/utils/Utils.ts +205 -20
  154. package/dist/cjs/types.js.map +0 -7
  155. package/dist/esm/types.js.map +0 -7
  156. package/dist/types/types.d.ts.map +0 -1
@@ -0,0 +1,273 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import { findAllLifecycleMetadata, getSubscribeSwcAppMessageWhileConnectedMetadata, getSubscribeSwcAppRouteChangeWhileConnectedMetadata, ON_CONNECTED_SWC_APP_METADATA_KEY } from "../decorators/index.js";
5
+ import { SwcAppEngine } from "../SwcAppEngine.js";
6
+ import { debounceTimeIntervalLock, FunctionUtils } from "@dooboostore/core";
7
+ import { SwcUtils } from "../utils/Utils.js";
8
+ const isSSR = (i) => {
9
+ return i.hasAttribute("swc-use-ssr");
10
+ };
11
+ const setSSRAttribute = (i) => {
12
+ i.setAttribute("swc-use-ssr", i._swcId ?? "");
13
+ };
14
+ const removeSSRAttribute = (i) => {
15
+ i.removeAttribute("swc-use-ssr");
16
+ };
17
+ function SwcAppMixin(Base) {
18
+ return class SwcAppMixinClass extends Base {
19
+ constructor(...args) {
20
+ super(...args);
21
+ __publicField(this, "__swc_engine", new SwcAppEngine(this));
22
+ __publicField(this, "_swc_connected_instance", /* @__PURE__ */ new Set());
23
+ __publicField(this, "_routerSubscription");
24
+ __publicField(this, "_lastRouterEvent");
25
+ __publicField(this, "_routeChangeInvocations", 0);
26
+ __publicField(this, "_connectedInvocations", 0);
27
+ __publicField(this, "_childrenRouteChangedInterval");
28
+ __publicField(this, "_childrenConnectedDoneInterval");
29
+ /**
30
+ * Safari is 속성 처리
31
+ * Safari polyfill에서는 자식부터 만들어지고 부모가 만들어지므로
32
+ * 부모가 자식들을 강제로 등록해주는 형태로 처리
33
+ */
34
+ __publicField(this, "_connected_safari_and_standby", []);
35
+ console.log("[SWC-APP-MIXIN] constructor");
36
+ }
37
+ get simpleApplication() {
38
+ return this.__swc_engine.simpleApplication;
39
+ }
40
+ get config() {
41
+ return this.__swc_engine?.config;
42
+ }
43
+ get router() {
44
+ return this.__swc_engine?.router;
45
+ }
46
+ async _invokeRouteChangeSubscribers(instance, re) {
47
+ if (instance.isConnected === false) return;
48
+ this._routeChangeInvocations++;
49
+ if (this._childrenRouteChangedInterval) {
50
+ this.config.window.clearInterval(this._childrenRouteChangedInterval);
51
+ }
52
+ const intervalConfig = { setInterval: this.config.window.setInterval.bind(this.config.window), clearInterval: this.config.window.clearInterval.bind(this.config.window) };
53
+ this._childrenRouteChangedInterval = debounceTimeIntervalLock(
54
+ () => this._routeChangeInvocations === 0,
55
+ () => {
56
+ this._childrenRouteChangedInterval = null;
57
+ this.config.onChildrenRouteChanged?.(re, this);
58
+ },
59
+ this.config?.childrenConnectedDoneCheckIntervalTime ?? 30,
60
+ intervalConfig
61
+ );
62
+ try {
63
+ const routeChangeSubscribers = getSubscribeSwcAppRouteChangeWhileConnectedMetadata(instance);
64
+ if (routeChangeSubscribers && Array.isArray(routeChangeSubscribers)) {
65
+ console.log("[SWC-MIXIN] Route change subscribers found");
66
+ const ps = routeChangeSubscribers.map(async (metadata) => {
67
+ const methodName = metadata.propertyKey;
68
+ let pathPattern = metadata.options?.path;
69
+ const filter = metadata.options?.filter;
70
+ if (typeof pathPattern === "function") {
71
+ pathPattern = pathPattern(instance);
72
+ }
73
+ let pathMatched = false;
74
+ let pathData = null;
75
+ if (!pathPattern) {
76
+ pathMatched = true;
77
+ pathData = {};
78
+ } else if (Array.isArray(pathPattern)) {
79
+ for (const pattern of pathPattern) {
80
+ const data = SwcUtils.parsePathPattern(pattern, re.path || "/");
81
+ if (data !== null) {
82
+ pathMatched = true;
83
+ pathData = data;
84
+ break;
85
+ }
86
+ }
87
+ } else {
88
+ pathData = SwcUtils.parsePathPattern(pathPattern, re.path || "/");
89
+ pathMatched = pathData !== null;
90
+ }
91
+ const hostSet = SwcUtils.getHelperAndHostSet(this.config.window, this);
92
+ const filterPassed = !filter || filter(this.router, { helper: hostSet, currentThis: instance });
93
+ if (pathMatched && filterPassed && instance[methodName]) {
94
+ await instance[methodName]({ ...re, pathData });
95
+ }
96
+ });
97
+ await Promise.allSettled(ps);
98
+ }
99
+ } finally {
100
+ if (this.config?.ssr) {
101
+ setSSRAttribute(instance);
102
+ } else {
103
+ removeSSRAttribute(instance);
104
+ }
105
+ this._routeChangeInvocations = Math.max(0, this._routeChangeInvocations - 1);
106
+ }
107
+ }
108
+ async _connected(instance, option) {
109
+ if (instance) {
110
+ if (!this.simpleApplication && !this.config) {
111
+ this._connected_safari_and_standby.push(instance);
112
+ return;
113
+ }
114
+ this.config.onConnectedChildBefore?.(instance);
115
+ if (!option?.noIncrements) {
116
+ this._connectedInvocations++;
117
+ }
118
+ this._swc_connected_instance.add(instance);
119
+ const connectedSwcAppCallBacks = findAllLifecycleMetadata(instance, ON_CONNECTED_SWC_APP_METADATA_KEY) ?? [];
120
+ for (let connectedSwcAppCallBack of connectedSwcAppCallBacks) {
121
+ await instance?._invokeLifecycleMethod?.(connectedSwcAppCallBack);
122
+ }
123
+ if (this._childrenConnectedDoneInterval) {
124
+ this.config.window.clearInterval(this._childrenConnectedDoneInterval);
125
+ }
126
+ const intervalConfig = { setInterval: this.config.window.setInterval.bind(this.config.window), clearInterval: this.config.window.clearInterval.bind(this.config.window) };
127
+ this._childrenConnectedDoneInterval = debounceTimeIntervalLock(
128
+ () => this._connectedInvocations === 0,
129
+ () => {
130
+ this._childrenConnectedDoneInterval = null;
131
+ this.config.onChildrenConnectedDone?.(this);
132
+ },
133
+ this.config?.childrenConnectedDoneCheckIntervalTime ?? 30,
134
+ intervalConfig
135
+ );
136
+ if (this.simpleApplication) {
137
+ try {
138
+ if (this.router && this._lastRouterEvent) {
139
+ await this._invokeRouteChangeSubscribers(instance, this._lastRouterEvent);
140
+ }
141
+ } catch (e) {
142
+ throw e;
143
+ }
144
+ }
145
+ if (this.config?.ssr) {
146
+ setSSRAttribute(instance);
147
+ } else {
148
+ removeSSRAttribute(instance);
149
+ }
150
+ }
151
+ this.config.onConnectedChildAfter?.(instance);
152
+ return this;
153
+ }
154
+ async _connectedDone(instance) {
155
+ try {
156
+ } finally {
157
+ this._connectedInvocations = Math.max(0, this._connectedInvocations - 1);
158
+ }
159
+ }
160
+ _disconnected(instance) {
161
+ if (instance) {
162
+ this._swc_connected_instance.delete(instance);
163
+ this.config?.onDisconnectedChildAfter?.(instance);
164
+ }
165
+ }
166
+ async _handleRouteChange(route) {
167
+ this._lastRouterEvent = route;
168
+ const swcConnectedInstance = Array.from(this._swc_connected_instance);
169
+ const ps = swcConnectedInstance.map((instance) => this._invokeRouteChangeSubscribers(instance, route));
170
+ await Promise.allSettled(ps);
171
+ }
172
+ async connect(config) {
173
+ console.log("[SWC-MIXIN] connect");
174
+ const swcConfig = {
175
+ routeType: "element",
176
+ window: config?.window,
177
+ ...config
178
+ };
179
+ await this.__swc_engine.connect(swcConfig);
180
+ this._connected_safari_and_standby.forEach((instance) => {
181
+ this._connected(instance, { noIncrements: true });
182
+ });
183
+ if (!this._routerSubscription && this.router) {
184
+ const config2 = this.__swc_engine.config;
185
+ this._routerSubscription = this.router.observable.subscribe(async (route) => {
186
+ console.log("[SWC-MIXIN] Router event received:", route.triggerPoint);
187
+ if (route.triggerPoint === "end") {
188
+ await this._handleRouteChange(route);
189
+ }
190
+ });
191
+ if (config2?.path) {
192
+ console.log("[DEBUG] Navigating to initial path:", config2.path);
193
+ }
194
+ }
195
+ }
196
+ connectedCallback() {
197
+ super.connectedCallback?.();
198
+ const configStr = this.getAttribute("swc-get-application-config");
199
+ const win = this.ownerDocument?.defaultView || window;
200
+ if (configStr && win) {
201
+ try {
202
+ const userConfig = FunctionUtils.executeReturn({
203
+ script: configStr,
204
+ context: this,
205
+ args: SwcUtils.getHelperAndHostSet(win, this)
206
+ });
207
+ this.connect(userConfig);
208
+ } catch (e) {
209
+ console.error("[SWC-MIXIN] Script execution failed:", e);
210
+ }
211
+ }
212
+ this._connected(this);
213
+ this.__swc_engine?.config?.onConnected?.(this);
214
+ this._connectedDone(this);
215
+ }
216
+ disconnectedCallback() {
217
+ super.disconnectedCallback?.();
218
+ this._routerSubscription?.unsubscribe();
219
+ this._routerSubscription = void 0;
220
+ this._lastRouterEvent = void 0;
221
+ this.__swc_engine.disconnect();
222
+ this.__swc_engine?.config?.onDisconnected?.(this);
223
+ this._disconnected(this);
224
+ }
225
+ async routing(path) {
226
+ await this.router?.go(path);
227
+ }
228
+ back() {
229
+ this.router?.back();
230
+ }
231
+ forward() {
232
+ this.router?.forward();
233
+ }
234
+ reload() {
235
+ this.router?.reload();
236
+ }
237
+ publishMessage(message) {
238
+ this._swc_connected_instance.forEach((instance) => {
239
+ this._invokeMessageSubscribers(instance, message);
240
+ });
241
+ }
242
+ _invokeMessageSubscribers(instance, message) {
243
+ const messageSubscribers = getSubscribeSwcAppMessageWhileConnectedMetadata(instance);
244
+ if (messageSubscribers && Array.isArray(messageSubscribers)) {
245
+ messageSubscribers.forEach((metadata) => {
246
+ const methodName = metadata.propertyKey;
247
+ const messageType = metadata.messageType;
248
+ const filter = metadata.filter;
249
+ let typeMatched = false;
250
+ if (!messageType) {
251
+ typeMatched = true;
252
+ } else if (message.type === messageType) {
253
+ typeMatched = true;
254
+ }
255
+ let filterMatched = true;
256
+ if (filter && typeMatched) {
257
+ filterMatched = filter(message, instance);
258
+ }
259
+ if (typeMatched && filterMatched && typeof instance[methodName] === "function") {
260
+ instance[methodName](message);
261
+ }
262
+ });
263
+ }
264
+ }
265
+ };
266
+ }
267
+ export {
268
+ SwcAppMixin,
269
+ isSSR,
270
+ removeSSRAttribute,
271
+ setSSRAttribute
272
+ };
273
+ //# sourceMappingURL=SwcAppMixin.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/elements/SwcAppMixin.ts"],
4
+ "sourcesContent": ["import {SwcAppInterface, SwcAppMessage} from \"../types\";\nimport {findAllLifecycleMetadata, getSubscribeSwcAppMessageWhileConnectedMetadata, getSubscribeSwcAppRouteChangeWhileConnectedMetadata, ON_CONNECTED_SWC_APP_METADATA_KEY} from \"../decorators\";\nimport {SwcAppEngine, SwcAttributeConfigType, SwcConfigType} from \"../SwcAppEngine\";\nimport {debounceTimeIntervalLock, FunctionUtils, Subscription} from \"@dooboostore/core\";\nimport {RouterEventType} from \"@dooboostore/core-web\";\nimport {SwcUtils} from \"../utils/Utils\";\n\nexport const isSSR = (i: HTMLElement) => {\n return i.hasAttribute('swc-use-ssr');\n}\nexport const setSSRAttribute = (i: HTMLElement) => {\n i.setAttribute('swc-use-ssr', (i as any)._swcId ?? '');\n}\nexport const removeSSRAttribute = (i: HTMLElement) => {\n i.removeAttribute('swc-use-ssr');\n}\n\n/**\n * SwcAppMixin: SwcApp \uAE30\uB2A5\uC744 \uBAA8\uB4E0 HTMLElement\uC5D0 \uCD94\uAC00\uD560 \uC218 \uC788\uB294 Mixin\n * \n * \uC0AC\uC6A9 \uC608:\n * @elementDefine('custom-app', { window: w })\n * class CustomApp extends SwcAppMixin(w.HTMLElement) implements SwcAppInterface {\n * // \uCD94\uAC00 \uAE30\uB2A5 \uAD6C\uD604\n * }\n */\nexport function SwcAppMixin<T extends { new(...args: any[]): HTMLElement }>(Base: T) {\n return class SwcAppMixinClass extends Base implements SwcAppInterface {\n __swc_engine = new SwcAppEngine(this as any);\n _swc_connected_instance = new Set<any>();\n _routerSubscription?: Subscription;\n _lastRouterEvent?: RouterEventType;\n _routeChangeInvocations = 0;\n _connectedInvocations = 0;\n\n _childrenRouteChangedInterval: any;\n _childrenConnectedDoneInterval: any;\n\n /**\n * Safari is \uC18D\uC131 \uCC98\uB9AC\n * Safari polyfill\uC5D0\uC11C\uB294 \uC790\uC2DD\uBD80\uD130 \uB9CC\uB4E4\uC5B4\uC9C0\uACE0 \uBD80\uBAA8\uAC00 \uB9CC\uB4E4\uC5B4\uC9C0\uBBC0\uB85C\n * \uBD80\uBAA8\uAC00 \uC790\uC2DD\uB4E4\uC744 \uAC15\uC81C\uB85C \uB4F1\uB85D\uD574\uC8FC\uB294 \uD615\uD0DC\uB85C \uCC98\uB9AC\n */\n _connected_safari_and_standby = [];\n\n constructor(...args: any[]) {\n super(...args);\n console.log('[SWC-APP-MIXIN] constructor')\n }\n\n get simpleApplication() {\n return this.__swc_engine.simpleApplication;\n }\n\n get config() {\n return this.__swc_engine?.config;\n }\n\n get router() {\n return this.__swc_engine?.router;\n }\n\n async _invokeRouteChangeSubscribers(instance: HTMLElement, re: RouterEventType) {\n if (instance.isConnected === false) return;\n\n this._routeChangeInvocations++;\n\n if (this._childrenRouteChangedInterval) {\n this.config.window.clearInterval(this._childrenRouteChangedInterval);\n }\n const intervalConfig = {setInterval: this.config.window.setInterval.bind(this.config.window), clearInterval: this.config.window.clearInterval.bind(this.config.window)};\n this._childrenRouteChangedInterval = debounceTimeIntervalLock(\n () => this._routeChangeInvocations === 0,\n () => {\n this._childrenRouteChangedInterval = null;\n this.config.onChildrenRouteChanged?.(re, this)\n },\n this.config?.childrenConnectedDoneCheckIntervalTime ?? 30,\n intervalConfig\n );\n\n try {\n const routeChangeSubscribers = getSubscribeSwcAppRouteChangeWhileConnectedMetadata(instance);\n if (routeChangeSubscribers && Array.isArray(routeChangeSubscribers)) {\n console.log('[SWC-MIXIN] Route change subscribers found')\n const ps = routeChangeSubscribers.map(async metadata => {\n const methodName = metadata.propertyKey;\n let pathPattern = metadata.options?.path as any;\n const filter = metadata.options?.filter;\n\n if (typeof pathPattern === 'function') {\n pathPattern = (pathPattern as Function)(instance);\n }\n\n let pathMatched = false;\n let pathData: any = null;\n\n if (!pathPattern) {\n pathMatched = true;\n pathData = {};\n } else if (Array.isArray(pathPattern)) {\n for (const pattern of pathPattern) {\n const data = SwcUtils.parsePathPattern(pattern, re.path || '/');\n if (data !== null) {\n pathMatched = true;\n pathData = data;\n break;\n }\n }\n } else {\n pathData = SwcUtils.parsePathPattern(pathPattern, re.path || '/');\n pathMatched = pathData !== null;\n }\n\n const hostSet = SwcUtils.getHelperAndHostSet(this.config.window, this);\n const filterPassed = !filter || filter(this.router!, {helper:hostSet, currentThis:instance});\n\n if (pathMatched && filterPassed && instance[methodName]) {\n await instance[methodName]({...re, pathData: pathData});\n }\n });\n await Promise.allSettled(ps);\n }\n } finally {\n if (this.config?.ssr) {\n setSSRAttribute(instance);\n } else {\n removeSSRAttribute(instance);\n }\n this._routeChangeInvocations = Math.max(0, this._routeChangeInvocations - 1);\n }\n }\n\n async _connected(instance: HTMLElement, option?: { noIncrements: boolean }) {\n if (instance) {\n if (!this.simpleApplication && !this.config) {\n this._connected_safari_and_standby.push(instance);\n return;\n }\n\n this.config.onConnectedChildBefore?.(instance);\n if (!option?.noIncrements) {\n this._connectedInvocations++;\n }\n this._swc_connected_instance.add(instance);\n\n const connectedSwcAppCallBacks = findAllLifecycleMetadata(instance, ON_CONNECTED_SWC_APP_METADATA_KEY) ?? [];\n for (let connectedSwcAppCallBack of connectedSwcAppCallBacks) {\n await (instance as any)?._invokeLifecycleMethod?.(connectedSwcAppCallBack);\n }\n\n if (this._childrenConnectedDoneInterval) {\n this.config.window.clearInterval(this._childrenConnectedDoneInterval);\n }\n const intervalConfig = {setInterval: this.config.window.setInterval.bind(this.config.window), clearInterval: this.config.window.clearInterval.bind(this.config.window)};\n this._childrenConnectedDoneInterval = debounceTimeIntervalLock(\n () => this._connectedInvocations === 0,\n () => {\n this._childrenConnectedDoneInterval = null;\n this.config.onChildrenConnectedDone?.(this)\n },\n this.config?.childrenConnectedDoneCheckIntervalTime ?? 30,\n intervalConfig\n );\n\n if (this.simpleApplication) {\n try {\n if (this.router && this._lastRouterEvent) {\n await this._invokeRouteChangeSubscribers(instance, this._lastRouterEvent!);\n }\n } catch (e) {\n throw e;\n }\n }\n\n if (this.config?.ssr) {\n setSSRAttribute(instance);\n } else {\n removeSSRAttribute(instance);\n }\n }\n\n this.config.onConnectedChildAfter?.(instance);\n return this;\n }\n\n async _connectedDone(instance: any) {\n try {\n // \uB0B4\uBD80 \uC5F0\uACB0 \uCC98\uB9AC \uB85C\uC9C1\n } finally {\n this._connectedInvocations = Math.max(0, this._connectedInvocations - 1);\n }\n }\n\n _disconnected(instance: any) {\n if (instance) {\n this._swc_connected_instance.delete(instance);\n this.config?.onDisconnectedChildAfter?.(instance);\n }\n }\n\n async _handleRouteChange(route: RouterEventType) {\n this._lastRouterEvent = route;\n const swcConnectedInstance = Array.from(this._swc_connected_instance);\n const ps = swcConnectedInstance.map((instance: any) => this._invokeRouteChangeSubscribers(instance, route));\n await Promise.allSettled(ps);\n }\n\n async connect(config?: SwcAttributeConfigType) {\n console.log('[SWC-MIXIN] connect')\n const swcConfig = {\n routeType: 'element',\n window: config?.window,\n ...config\n } as SwcConfigType;\n\n await this.__swc_engine.connect(swcConfig);\n\n // Safari is \uC18D\uC131 \uCC98\uB9AC\n this._connected_safari_and_standby.forEach((instance: any) => {\n this._connected(instance, {noIncrements: true});\n });\n\n // \uB77C\uC6B0\uD130 \uBCC0\uACBD \uAD6C\uB3C5\n if (!this._routerSubscription && this.router) {\n const config = this.__swc_engine.config;\n\n this._routerSubscription = this.router.observable.subscribe(async (route: RouterEventType) => {\n console.log('[SWC-MIXIN] Router event received:', route.triggerPoint);\n if (route.triggerPoint === 'end') {\n await this._handleRouteChange(route);\n }\n });\n\n if (config?.path) {\n console.log('[DEBUG] Navigating to initial path:', config.path);\n }\n }\n }\n\n connectedCallback() {\n // \uBD80\uBAA8 \uD074\uB798\uC2A4\uC758 connectedCallback \uD638\uCD9C\n // @ts-ignore\n super.connectedCallback?.();\n\n const configStr = this.getAttribute('swc-get-application-config');\n const win = this.ownerDocument?.defaultView || window;\n if (configStr && win) {\n try {\n const userConfig = FunctionUtils.executeReturn({\n script: configStr,\n context: this,\n args: SwcUtils.getHelperAndHostSet(win, this)\n });\n this.connect(userConfig);\n } catch (e) {\n console.error('[SWC-MIXIN] Script execution failed:', e);\n }\n }\n\n this._connected(this);\n this.__swc_engine?.config?.onConnected?.(this);\n this._connectedDone(this);\n }\n\n disconnectedCallback() {\n // \uBD80\uBAA8 \uD074\uB798\uC2A4\uC758 disconnectedCallback \uD638\uCD9C\n // @ts-ignore\n super.disconnectedCallback?.();\n \n this._routerSubscription?.unsubscribe();\n this._routerSubscription = undefined;\n this._lastRouterEvent = undefined;\n this.__swc_engine.disconnect();\n this.__swc_engine?.config?.onDisconnected?.(this);\n this._disconnected(this);\n }\n\n async routing(path: string) {\n await this.router?.go(path);\n }\n\n back(): void {\n this.router?.back();\n }\n\n forward(): void {\n this.router?.forward();\n }\n\n reload(): void {\n this.router?.reload();\n }\n\n publishMessage(message: SwcAppMessage): void {\n this._swc_connected_instance.forEach((instance: any) => {\n this._invokeMessageSubscribers(instance, message);\n });\n }\n\n _invokeMessageSubscribers(instance: any, message: SwcAppMessage) {\n const messageSubscribers = getSubscribeSwcAppMessageWhileConnectedMetadata(instance);\n if (messageSubscribers && Array.isArray(messageSubscribers)) {\n messageSubscribers.forEach(metadata => {\n const methodName = metadata.propertyKey;\n const messageType = metadata.messageType;\n const filter = metadata.filter;\n\n let typeMatched = false;\n if (!messageType) {\n typeMatched = true;\n } else if (message.type === messageType) {\n typeMatched = true;\n }\n\n let filterMatched = true;\n if (filter && typeMatched) {\n filterMatched = filter(message, instance);\n }\n\n if (typeMatched && filterMatched && typeof instance[methodName] === 'function') {\n instance[methodName](message);\n }\n });\n }\n }\n };\n}\n"],
5
+ "mappings": ";;;AACA,SAAQ,0BAA0B,iDAAiD,qDAAqD,yCAAwC;AAChL,SAAQ,oBAA0D;AAClE,SAAQ,0BAA0B,qBAAkC;AAEpE,SAAQ,gBAAe;AAEhB,MAAM,QAAQ,CAAC,MAAmB;AACvC,SAAO,EAAE,aAAa,aAAa;AACrC;AACO,MAAM,kBAAkB,CAAC,MAAmB;AACjD,IAAE,aAAa,eAAgB,EAAU,UAAU,EAAE;AACvD;AACO,MAAM,qBAAqB,CAAC,MAAmB;AACpD,IAAE,gBAAgB,aAAa;AACjC;AAWO,SAAS,YAA4D,MAAS;AACnF,SAAO,MAAM,yBAAyB,KAAgC;AAAA,IAkBpE,eAAe,MAAa;AAC1B,YAAM,GAAG,IAAI;AAlBf,0CAAe,IAAI,aAAa,IAAW;AAC3C,qDAA0B,oBAAI,IAAS;AACvC;AACA;AACA,qDAA0B;AAC1B,mDAAwB;AAExB;AACA;AAOA;AAAA;AAAA;AAAA;AAAA;AAAA,2DAAgC,CAAC;AAI/B,cAAQ,IAAI,6BAA6B;AAAA,IAC3C;AAAA,IAEA,IAAI,oBAAoB;AACtB,aAAO,KAAK,aAAa;AAAA,IAC3B;AAAA,IAEA,IAAI,SAAS;AACX,aAAO,KAAK,cAAc;AAAA,IAC5B;AAAA,IAEA,IAAI,SAAS;AACX,aAAO,KAAK,cAAc;AAAA,IAC5B;AAAA,IAEA,MAAM,8BAA8B,UAAuB,IAAqB;AAC9E,UAAI,SAAS,gBAAgB,MAAO;AAEpC,WAAK;AAEL,UAAI,KAAK,+BAA+B;AACtC,aAAK,OAAO,OAAO,cAAc,KAAK,6BAA6B;AAAA,MACrE;AACA,YAAM,iBAAiB,EAAC,aAAa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;AAAA,IAEA,eAAe,SAA8B;AAC3C,WAAK,wBAAwB,QAAQ,CAAC,aAAkB;AACtD,aAAK,0BAA0B,UAAU,OAAO;AAAA,MAClD,CAAC;AAAA,IACH;AAAA,IAEA,0BAA0B,UAAe,SAAwB;AAC/D,YAAM,qBAAqB,gDAAgD,QAAQ;AACnF,UAAI,sBAAsB,MAAM,QAAQ,kBAAkB,GAAG;AAC3D,2BAAmB,QAAQ,cAAY;AACrC,gBAAM,aAAa,SAAS;AAC5B,gBAAM,cAAc,SAAS;AAC7B,gBAAM,SAAS,SAAS;AAExB,cAAI,cAAc;AAClB,cAAI,CAAC,aAAa;AAChB,0BAAc;AAAA,UAChB,WAAW,QAAQ,SAAS,aAAa;AACvC,0BAAc;AAAA,UAChB;AAEA,cAAI,gBAAgB;AACpB,cAAI,UAAU,aAAa;AACzB,4BAAgB,OAAO,SAAS,QAAQ;AAAA,UAC1C;AAEA,cAAI,eAAe,iBAAiB,OAAO,SAAS,UAAU,MAAM,YAAY;AAC9E,qBAAS,UAAU,EAAE,OAAO;AAAA,UAC9B;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;",
6
+ "names": ["config"]
7
+ }
@@ -1,8 +1,3 @@
1
- import swcAppFactory from "./SwcApp.js";
2
- const registerSwcApp = swcAppFactory;
3
- const register = [swcAppFactory];
4
- export {
5
- register,
6
- registerSwcApp
7
- };
1
+ export * from "./SwcAppMixin.js";
2
+ export * from "./SwcApp.js";
8
3
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/elements/index.ts"],
4
- "sourcesContent": ["// export * from './tt/register';\nimport swcAppFactory from './SwcApp'\n// import swcAsyncFactory from './SwcAsync'\n// import swcLoopFactory from './SwcLoop'\n// import swcIfFactory from './SwcIf'\nexport const registerSwcApp = swcAppFactory;\n// export const registerSwcAsync = swcAsyncFactory;\n// export const registerSwcLoop = swcLoopFactory;\n// export const registerSwcIf = swcIfFactory;\n\nexport const register = [swcAppFactory];"],
5
- "mappings": "AACA,OAAO,mBAAmB;AAInB,MAAM,iBAAiB;AAKvB,MAAM,WAAW,CAAC,aAAa;",
4
+ "sourcesContent": ["// export * from './tt/register';\nexport * from './SwcAppMixin'\nexport * from './SwcApp'\n\n"],
5
+ "mappings": "AACA,cAAc;AACd,cAAc;",
6
6
  "names": []
7
7
  }
package/dist/esm/index.js CHANGED
@@ -1,14 +1,12 @@
1
1
  import "reflect-metadata";
2
2
  export * from "./elements/index.js";
3
- import { register } from "./elements/index.js";
3
+ import { defineSwcAppAll } from "./elements/index.js";
4
4
  export * from "./decorators/index.js";
5
5
  export * from "./types/index.js";
6
6
  export * from "./utils/Utils.js";
7
7
  export * from "./config/config.js";
8
8
  var src_default = async (w, other) => {
9
- console.log("rr");
10
- const cr = await Promise.all(register.map((it) => it(w)));
11
- console.log("rr11");
9
+ const cr = await defineSwcAppAll(w);
12
10
  if (other) {
13
11
  for (const fn of other) {
14
12
  if (typeof fn === "function") {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["import 'reflect-metadata';\nexport * from './elements'\nimport { register } from './elements';\nimport {ConstructorType} from \"@dooboostore/core\";\n\n// Decorators\nexport * from './decorators';\n\n// Types\nexport * from './types';\n\n// Utilities\nexport * from './utils/Utils';\n\n// Config\nexport * from './config/config';\n\n// Registration Factory\nexport default async (w: Window, other?: (((w: Window) => Promise<CustomElementConstructor> | CustomElementConstructor) | any) []) => {\n console.log('rr')\n const cr = await Promise.all(register.map(it => it(w)));\n console.log('rr11')\n // const cr = await elementFactories(w);\n if (other) {\n for (const fn of other) {\n if (typeof fn === 'function') {\n await fn(w);\n }\n }\n }\n\n return cr;\n};\n"],
5
- "mappings": "AAAA,OAAO;AACP,cAAc;AACd,SAAS,gBAAgB;AAIzB,cAAc;AAGd,cAAc;AAGd,cAAc;AAGd,cAAc;AAGd,IAAO,cAAQ,OAAO,GAAW,UAAqG;AACpI,UAAQ,IAAI,IAAI;AAChB,QAAM,KAAK,MAAM,QAAQ,IAAI,SAAS,IAAI,QAAM,GAAG,CAAC,CAAC,CAAC;AACtD,UAAQ,IAAI,MAAM;AAElB,MAAI,OAAO;AACT,eAAW,MAAM,OAAO;AACtB,UAAI,OAAO,OAAO,YAAY;AAC5B,cAAM,GAAG,CAAC;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
4
+ "sourcesContent": ["import 'reflect-metadata';\nexport * from './elements'\nimport { defineSwcAppAll } from './elements';\nimport {ConstructorType} from \"@dooboostore/core\";\n\n// Decorators\nexport * from './decorators';\n\n// Types\nexport * from './types';\n\n// Utilities\nexport * from './utils/Utils';\n\n// Config\nexport * from './config/config';\n\n// Registration Factory\nexport default async (w: Window, other?: (((w: Window) => Promise<CustomElementConstructor> | CustomElementConstructor) | any) []) => {\n const cr = await defineSwcAppAll(w);\n // const cr = await elementFactories(w);\n if (other) {\n for (const fn of other) {\n if (typeof fn === 'function') {\n await fn(w);\n }\n }\n }\n\n return cr;\n};\n"],
5
+ "mappings": "AAAA,OAAO;AACP,cAAc;AACd,SAAS,uBAAuB;AAIhC,cAAc;AAGd,cAAc;AAGd,cAAc;AAGd,cAAc;AAGd,IAAO,cAAQ,OAAO,GAAW,UAAqG;AACpI,QAAM,KAAK,MAAM,gBAAgB,CAAC;AAElC,MAAI,OAAO;AACT,eAAW,MAAM,OAAO;AACtB,UAAI,OAAO,OAAO,YAAY;AAC5B,cAAM,GAAG,CAAC;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -14,4 +14,4 @@ var InjectSituationType = /* @__PURE__ */ ((InjectSituationType2) => {
14
14
  export {
15
15
  InjectSituationType
16
16
  };
17
- //# sourceMappingURL=types.js.map
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/types/index.ts"],
4
+ "sourcesContent": ["import { SimpleApplication } from '@dooboostore/simple-boot';\nimport { Router } from '@dooboostore/core-web';\nimport {SwcAttributeConfigType, SwcConfigType} from \"../SwcAppEngine\";\n\nexport enum InjectSituationType {\n HOST_SET = 'SIMPLE_WEB_COMPONENT://HOSTSET',\n APP_HOST = 'SIMPLE_WEB_COMPONENT://APPHOST',\n APP_HOSTS = 'SIMPLE_WEB_COMPONENT://APPHOSTS',\n HOST = 'SIMPLE_WEB_COMPONENT://HOST',\n PARENT_HOST = 'SIMPLE_WEB_COMPONENT://PARENTHOST',\n HOSTS = 'SIMPLE_WEB_COMPONENT://HOSTS',\n FIRST_HOST = 'SIMPLE_WEB_COMPONENT://FIRSTHOST',\n LAST_HOST = 'SIMPLE_WEB_COMPONENT://LASTHOST',\n FIRST_APP_HOST = 'SIMPLE_WEB_COMPONENT://FIRSTAPPHOST',\n LAST_APP_HOST = 'SIMPLE_WEB_COMPONENT://LASTAPPHOST'\n}\n\nexport type SwcRootType = 'light' | 'shadow' | 'all' | 'auto';\n\nexport type SpecialSelector = '$this' | '$window' | '$document' | '$host' | '$appHost' | '$firstHost' | '$lastHost' | '$firstAppHost' | '$lastAppHost' | '$hosts' | '$appHosts';\n\nexport type SwcQueryOptions = { root?: SwcRootType };\n\nexport type HelperSet = {\n $d: Document;\n $w: Window;\n $q: (selector: string, root?: Element | Document | ShadowRoot) => HTMLElement | null;\n $qa: (selector: string, root?: Element | Document | ShadowRoot) => HTMLElement[];\n $qi: (id: string, root?: Document | ShadowRoot) => HTMLElement | null;\n};\n\nexport type HostSet = {\n $host: HTMLElement | null; // Nearest parent SWC component\n $parentHost: HTMLElement | null; // Grandparent SWC ancestor\n $hosts: HTMLElement[]; // All SWC ancestors [root, ..., parent]\n $firstHost: HTMLElement | null; // Top-most SWC ancestor\n $lastHost: HTMLElement | null; // Same as $host\n // $templateHost: HTMLTemplateElement | null | undefined;\n $appHost: SwcAppInterface | null;\n $appHosts: SwcAppInterface[];\n $firstAppHost: SwcAppInterface | null;\n $lastAppHost: SwcAppInterface | null;\n};\n\nexport type HelperHostSet = HelperSet & HostSet & {$this: any};\n\nexport type SwcAppMessage<T = any> = {\n publisher?: any;\n data?: T;\n type?: string;\n};\n\n\nexport interface SwcAppInterface extends HTMLElement {\n simpleApplication?: SimpleApplication;\n config?: SwcConfigType;\n router?: Router;\n connect(config?: SwcAttributeConfigType): Promise<void>;\n routing(path: string): Promise<void>;\n reload(): void;\n back(): void;\n forward(): void;\n publishMessage(message: SwcAppMessage): void;\n}\n\nexport interface SwcElement {\n // _swcId: string;\n createSlotString(id: string): string\n createEaHtml(id: string, script: string): string\n createEaText(id: string, script: string): string\n createEaAttribute(id: string, attributeName: string): string\n createEaEvent(id: string, eventName: string): string\n createEaProperty(id: string, propertyName: string): string\n}"],
5
+ "mappings": "AAIO,IAAK,sBAAL,kBAAKA,yBAAL;AACL,EAAAA,qBAAA,cAAW;AACX,EAAAA,qBAAA,cAAW;AACX,EAAAA,qBAAA,eAAY;AACZ,EAAAA,qBAAA,UAAO;AACP,EAAAA,qBAAA,iBAAc;AACd,EAAAA,qBAAA,WAAQ;AACR,EAAAA,qBAAA,gBAAa;AACb,EAAAA,qBAAA,eAAY;AACZ,EAAAA,qBAAA,oBAAiB;AACjB,EAAAA,qBAAA,mBAAgB;AAVN,SAAAA;AAAA,GAAA;",
6
+ "names": ["InjectSituationType"]
7
+ }
@@ -1,10 +1,20 @@
1
1
  import { getElementConfig } from "../decorators/index.js";
2
+ import { ActionExpression } from "@dooboostore/core";
3
+ import { ElementApply, NodeSlot } from "@dooboostore/core-web";
2
4
  const SWC_NOT_FOUND = Symbol.for("simple-web-component:not-found");
3
- const htmlFragment = (html, doc) => {
4
- const d = doc || (typeof document !== "undefined" ? document : void 0);
5
- if (!d) throw new Error("Document is not available");
6
- const template = d.createElement("template");
7
- template.innerHTML = html.trim();
5
+ const html = (str, document2) => {
6
+ return [...document2.createRange().createContextualFragment(str).childNodes];
7
+ };
8
+ const htmlFragment = (html2, doc) => {
9
+ if (!doc) throw new Error("Document is not available");
10
+ const template = doc.createElement("template");
11
+ if (typeof html2 === "string") {
12
+ template.innerHTML = html2.trim();
13
+ } else if (html2 instanceof Node) {
14
+ template.appendChild(html2);
15
+ } else if (Array.isArray(html2)) {
16
+ template.append(...html2);
17
+ }
8
18
  return template.content;
9
19
  };
10
20
  const textNode = (text, doc) => {
@@ -23,38 +33,38 @@ const createElement = (documentOrWindow, tagName, options) => {
23
33
  const el = doc.createElement(tagName);
24
34
  if (options?.innerHtml) el.innerHTML = options.innerHtml;
25
35
  if (options?.attrs) {
26
- Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
36
+ Object.entries(options.attrs).filter(([k, v]) => v).forEach(([k, v]) => el.setAttribute(k, String(v)));
27
37
  }
28
38
  if (options?.property) {
29
39
  Object.entries(options.property).forEach(([k, v]) => el[k] = v);
30
40
  }
31
41
  return el;
32
42
  };
33
- const htmlDivElement = (html, options) => {
43
+ const htmlDivElement = (html2, options) => {
34
44
  const d = options?.doc || (typeof document !== "undefined" ? document : void 0);
35
45
  if (!d) throw new Error("Document is not available");
36
46
  const el = d.createElement("div");
37
- el.innerHTML = html.trim();
47
+ el.innerHTML = html2.trim();
38
48
  if (options?.attrs) {
39
49
  Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
40
50
  }
41
51
  return el;
42
52
  };
43
- const htmlSpanElement = (html, options) => {
53
+ const htmlSpanElement = (html2, options) => {
44
54
  const d = options?.doc || (typeof document !== "undefined" ? document : void 0);
45
55
  if (!d) throw new Error("Document is not available");
46
56
  const el = d.createElement("span");
47
- el.innerHTML = html.trim();
57
+ el.innerHTML = html2.trim();
48
58
  if (options?.attrs) {
49
59
  Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
50
60
  }
51
61
  return el;
52
62
  };
53
- const htmlButtonElement = (html, options) => {
63
+ const htmlButtonElement = (html2, options) => {
54
64
  const d = options?.doc || (typeof document !== "undefined" ? document : void 0);
55
65
  if (!d) throw new Error("Document is not available");
56
66
  const el = d.createElement("button");
57
- el.innerHTML = html.trim();
67
+ el.innerHTML = html2.trim();
58
68
  if (options?.attrs) {
59
69
  Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
60
70
  }
@@ -69,42 +79,42 @@ const htmlUlElement = (options) => {
69
79
  }
70
80
  return el;
71
81
  };
72
- const htmlLiElement = (html, options) => {
82
+ const htmlLiElement = (html2, options) => {
73
83
  const d = options?.doc || (typeof document !== "undefined" ? document : void 0);
74
84
  if (!d) throw new Error("Document is not available");
75
85
  const el = d.createElement("li");
76
- el.innerHTML = html.trim();
86
+ el.innerHTML = html2.trim();
77
87
  if (options?.attrs) {
78
88
  Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
79
89
  }
80
90
  return el;
81
91
  };
82
- const htmlAElement = (html, options) => {
92
+ const htmlAElement = (html2, options) => {
83
93
  const d = options?.doc || (typeof document !== "undefined" ? document : void 0);
84
94
  if (!d) throw new Error("Document is not available");
85
95
  const el = d.createElement("a");
86
- el.innerHTML = html.trim();
96
+ el.innerHTML = html2.trim();
87
97
  if (options?.href) el.href = options.href;
88
98
  if (options?.attrs) {
89
99
  Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
90
100
  }
91
101
  return el;
92
102
  };
93
- const htmlPElement = (html, options) => {
103
+ const htmlPElement = (html2, options) => {
94
104
  const d = options?.doc || (typeof document !== "undefined" ? document : void 0);
95
105
  if (!d) throw new Error("Document is not available");
96
106
  const el = d.createElement("p");
97
- el.innerHTML = html.trim();
107
+ el.innerHTML = html2.trim();
98
108
  if (options?.attrs) {
99
109
  Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
100
110
  }
101
111
  return el;
102
112
  };
103
- const htmlHeadingElement = (level, html, options) => {
113
+ const htmlHeadingElement = (level, html2, options) => {
104
114
  const d = options?.doc || (typeof document !== "undefined" ? document : void 0);
105
115
  if (!d) throw new Error("Document is not available");
106
116
  const el = d.createElement(`h${level}`);
107
- el.innerHTML = html.trim();
117
+ el.innerHTML = html2.trim();
108
118
  if (options?.attrs) {
109
119
  Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
110
120
  }
@@ -219,6 +229,134 @@ var SwcUtils;
219
229
  if (getElementConfig(el)) return el;
220
230
  return (0, SwcUtils2.findNearestSwcHostIncludingSelf)(el);
221
231
  };
232
+ function projectProcessHtml(id, htmlOrNode, document2) {
233
+ if (typeof htmlOrNode === "string") {
234
+ let t = htmlOrNode;
235
+ t = SwcUtils2.processHtml(id, t, { document: document2, replaceWrap: { start: "<!--[[", end: "]]-->" }, replacer: (id2, script) => NodeSlot.slot(id2, script) });
236
+ t = SwcUtils2.processHtml(id, t, { document: document2, replaceWrap: { start: "<!--[html", end: "]-->" }, replacer: (id2, script) => ElementApply.html(id2, script) });
237
+ t = SwcUtils2.processHtml(id, t, { document: document2, replaceWrap: { start: "<!--[text", end: "]-->" }, replacer: (id2, script) => ElementApply.text(id2, script) });
238
+ t = SwcUtils2.processHtml(id, t, {
239
+ document: document2,
240
+ replaceWrap: { start: /a::\w+=\s*"/, end: /"\s/ },
241
+ replacer: (id2, script, er) => {
242
+ console.log("start: /a-->", er);
243
+ const match = er.expressionStart.match(/^\w+::(\w+)="/);
244
+ const name = match?.[1];
245
+ return ElementApply.attribute(id2, name, script);
246
+ }
247
+ });
248
+ t = SwcUtils2.processHtml(id, t, {
249
+ document: document2,
250
+ replaceWrap: { start: /e::\w+=\s*"/, end: /"\s/ },
251
+ replacer: (id2, script, er) => {
252
+ console.log("start: /e-->", er);
253
+ const match = er.expressionStart.match(/^\w+::(\w+)="/);
254
+ const name = match?.[1];
255
+ return ElementApply.event(id2, name, script);
256
+ }
257
+ });
258
+ t = SwcUtils2.processHtml(id, t, {
259
+ document: document2,
260
+ replaceWrap: { start: /p:\w+=\s*"/, end: /"\s/ },
261
+ replacer: (id2, script, er) => {
262
+ console.log("start: /p-->", er);
263
+ const match = er.expressionStart.match(/^\w+:(\w+)="/);
264
+ const name = match?.[1];
265
+ return ElementApply.property(id2, name, script);
266
+ }
267
+ });
268
+ return t;
269
+ } else if (htmlOrNode) {
270
+ const nodes = Array.isArray(htmlOrNode) ? htmlOrNode : [htmlOrNode];
271
+ const window2 = document2.defaultView;
272
+ nodes.forEach((node) => {
273
+ node.normalize();
274
+ const nodes2 = document2.createTreeWalker(node, window2.NodeFilter.SHOW_ELEMENT | window2.NodeFilter.SHOW_COMMENT);
275
+ const getSlotData = (s) => {
276
+ return s.match(/^\[\[([\s\S]+)\]\]$/)?.[1]?.trim();
277
+ };
278
+ const getHtmlData = (s) => {
279
+ return s.match(/^\[html([\s\S]+)\]$/)?.[1]?.trim();
280
+ };
281
+ const getTextData = (s) => {
282
+ return s.match(/^\[text([\s\S]+)\]$/)?.[1]?.trim();
283
+ };
284
+ while (nodes2.nextNode()) {
285
+ const currentNode = nodes2.currentNode;
286
+ if (currentNode.nodeType === window2.Node.COMMENT_NODE) {
287
+ const targetNode = currentNode;
288
+ const v = targetNode.data.trim();
289
+ const slotData = getSlotData(v);
290
+ const htmlData = getHtmlData(v);
291
+ const textData = getTextData(v);
292
+ if (v && slotData) {
293
+ const res = NodeSlot.slotIds(id, slotData);
294
+ targetNode.data = res.start;
295
+ const end = document2.createComment(res.end);
296
+ targetNode.parentNode?.insertBefore(end, targetNode.nextSibling);
297
+ } else if (v && htmlData) {
298
+ const s = ElementApply.htmlDataSet(id, htmlData);
299
+ targetNode.data = s.start;
300
+ const end = document2.createComment(s.end);
301
+ targetNode.parentNode?.insertBefore(end, targetNode.nextSibling);
302
+ } else if (v && textData) {
303
+ const s = ElementApply.textDataSet(id, textData);
304
+ const end = document2.createComment(s.end);
305
+ targetNode.data = s.start;
306
+ targetNode.parentNode?.insertBefore(end, targetNode.nextSibling);
307
+ }
308
+ } else if (currentNode.nodeType === window2.Node.ELEMENT_NODE) {
309
+ const targetNode = currentNode;
310
+ targetNode.getAttributeNames().forEach((it) => {
311
+ const e = it.match(/e::(\w+)$/);
312
+ const eventName = e?.[1];
313
+ const p = it.match(/p::(\w+)$/);
314
+ const propertyName = p?.[1];
315
+ const a = it.match(/a::(\w+)$/);
316
+ const attributeName = a?.[1];
317
+ const value = targetNode.getAttribute(it);
318
+ if (eventName) {
319
+ targetNode.setAttribute(ElementApply.eventName(id, eventName), value);
320
+ targetNode.removeAttribute(it);
321
+ } else if (propertyName) {
322
+ targetNode.setAttribute(ElementApply.propertyName(id, propertyName), value);
323
+ targetNode.removeAttribute(it);
324
+ } else if (attributeName) {
325
+ targetNode.setAttribute(ElementApply.attributeName(id, attributeName), value);
326
+ targetNode.removeAttribute(it);
327
+ }
328
+ });
329
+ }
330
+ }
331
+ });
332
+ return nodes;
333
+ }
334
+ }
335
+ SwcUtils2.projectProcessHtml = projectProcessHtml;
336
+ function processHtml(id, html2, config) {
337
+ const replaceStart = config.replaceWrap.start;
338
+ const replaceEnd = config.replaceWrap.end;
339
+ const callReturnStart = `${config.replaceWrap.start}=`;
340
+ const callReturnEnd = `${config.replaceWrap.end}`;
341
+ const callStart = `${config.replaceWrap.start}@`;
342
+ const callEnd = `${config.replaceWrap.end}`;
343
+ const hasPattern = (text, start, end) => {
344
+ if (!text) return false;
345
+ const s = text.indexOf(start);
346
+ const e = text.indexOf(end, s + start.length);
347
+ return s !== -1 && e !== -1 && s < e;
348
+ };
349
+ const actionConfig = { expression: { replace: { start: replaceStart, end: replaceEnd }, callReturn: { start: callReturnStart, end: callReturnEnd }, call: { start: callStart, end: callEnd } } };
350
+ const runActionExpression = (source) => {
351
+ const actionExpression = new ActionExpression(source, actionConfig);
352
+ actionExpression.getExpressions().filter((it) => it.type === "replace").forEach((it) => {
353
+ actionExpression.replace(it, config.replacer(id, it.script?.trim(), it));
354
+ });
355
+ return actionExpression.toResult();
356
+ };
357
+ return runActionExpression(html2);
358
+ }
359
+ SwcUtils2.processHtml = processHtml;
222
360
  SwcUtils2.getAppHosts = (el) => {
223
361
  const hosts = SwcUtils2.findAllAppHostsIncludingSelfDirect(el);
224
362
  return hosts;
@@ -314,6 +452,7 @@ export {
314
452
  SwcUtils,
315
453
  commentNode,
316
454
  createElement,
455
+ html,
317
456
  htmlAElement,
318
457
  htmlArticleElement,
319
458
  htmlButtonElement,