@dooboostore/simple-web-component 1.0.48 → 1.0.50

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 (192) hide show
  1. package/README.md +189 -19
  2. package/dist/cjs/config/config.js +1 -1
  3. package/dist/cjs/config/config.js.map +2 -2
  4. package/dist/cjs/decorators/addEventListener.js +2373 -30
  5. package/dist/cjs/decorators/addEventListener.js.map +3 -3
  6. package/dist/cjs/decorators/applyAttribute.js +31 -0
  7. package/dist/cjs/decorators/applyAttribute.js.map +2 -2
  8. package/dist/cjs/decorators/applyClass.js +55 -18
  9. package/dist/cjs/decorators/applyClass.js.map +3 -3
  10. package/dist/cjs/decorators/applyNode.js +73 -1
  11. package/dist/cjs/decorators/applyNode.js.map +3 -3
  12. package/dist/cjs/decorators/applyProperty.js +107 -3
  13. package/dist/cjs/decorators/applyProperty.js.map +2 -2
  14. package/dist/cjs/decorators/applySlot.js +6 -5
  15. package/dist/cjs/decorators/applySlot.js.map +2 -2
  16. package/dist/cjs/decorators/applyStyle.js +42 -5
  17. package/dist/cjs/decorators/applyStyle.js.map +2 -2
  18. package/dist/cjs/decorators/changedAttribute.js +61 -13
  19. package/dist/cjs/decorators/changedAttribute.js.map +2 -2
  20. package/dist/cjs/decorators/elementDefine.js +254 -439
  21. package/dist/cjs/decorators/elementDefine.js.map +3 -3
  22. package/dist/cjs/decorators/emitCustomEvent.js +55 -0
  23. package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
  24. package/dist/cjs/decorators/eventMedia.js +84 -0
  25. package/dist/cjs/decorators/eventMedia.js.map +7 -0
  26. package/dist/cjs/decorators/index.js +6 -1
  27. package/dist/cjs/decorators/index.js.map +2 -2
  28. package/dist/cjs/decorators/intersectionObserver.js +200 -0
  29. package/dist/cjs/decorators/intersectionObserver.js.map +7 -0
  30. package/dist/cjs/decorators/mutationObserver.js +186 -55
  31. package/dist/cjs/decorators/mutationObserver.js.map +3 -3
  32. package/dist/cjs/decorators/parameter.js +73 -0
  33. package/dist/cjs/decorators/parameter.js.map +7 -0
  34. package/dist/cjs/decorators/query.js +117 -102
  35. package/dist/cjs/decorators/query.js.map +2 -2
  36. package/dist/cjs/decorators/requestAnimationFrame.js +124 -0
  37. package/dist/cjs/decorators/requestAnimationFrame.js.map +7 -0
  38. package/dist/cjs/decorators/resizeObserver.js +133 -55
  39. package/dist/cjs/decorators/resizeObserver.js.map +2 -2
  40. package/dist/cjs/decorators/setInterval.js +114 -0
  41. package/dist/cjs/decorators/setInterval.js.map +7 -0
  42. package/dist/cjs/decorators/setTimeout.js +117 -0
  43. package/dist/cjs/decorators/setTimeout.js.map +7 -0
  44. package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js +9 -0
  45. package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
  46. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -0
  47. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  48. package/dist/cjs/elements/SwcAppMixin.js +19 -3
  49. package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
  50. package/dist/cjs/types/index.js.map +1 -1
  51. package/dist/cjs/types/window.d.js.map +1 -1
  52. package/dist/esm/config/config.js +1 -1
  53. package/dist/esm/config/config.js.map +2 -2
  54. package/dist/esm/decorators/addEventListener.js +2374 -30
  55. package/dist/esm/decorators/addEventListener.js.map +3 -3
  56. package/dist/esm/decorators/applyAttribute.js +31 -0
  57. package/dist/esm/decorators/applyAttribute.js.map +2 -2
  58. package/dist/esm/decorators/applyClass.js +55 -18
  59. package/dist/esm/decorators/applyClass.js.map +3 -3
  60. package/dist/esm/decorators/applyNode.js +73 -1
  61. package/dist/esm/decorators/applyNode.js.map +3 -3
  62. package/dist/esm/decorators/applyProperty.js +107 -3
  63. package/dist/esm/decorators/applyProperty.js.map +2 -2
  64. package/dist/esm/decorators/applySlot.js +6 -5
  65. package/dist/esm/decorators/applySlot.js.map +2 -2
  66. package/dist/esm/decorators/applyStyle.js +42 -5
  67. package/dist/esm/decorators/applyStyle.js.map +2 -2
  68. package/dist/esm/decorators/changedAttribute.js +62 -13
  69. package/dist/esm/decorators/changedAttribute.js.map +2 -2
  70. package/dist/esm/decorators/elementDefine.js +261 -446
  71. package/dist/esm/decorators/elementDefine.js.map +3 -3
  72. package/dist/esm/decorators/emitCustomEvent.js +55 -0
  73. package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
  74. package/dist/esm/decorators/eventMedia.js +66 -0
  75. package/dist/esm/decorators/eventMedia.js.map +7 -0
  76. package/dist/esm/decorators/index.js +6 -1
  77. package/dist/esm/decorators/index.js.map +2 -2
  78. package/dist/esm/decorators/intersectionObserver.js +182 -0
  79. package/dist/esm/decorators/intersectionObserver.js.map +7 -0
  80. package/dist/esm/decorators/mutationObserver.js +187 -55
  81. package/dist/esm/decorators/mutationObserver.js.map +3 -3
  82. package/dist/esm/decorators/parameter.js +54 -0
  83. package/dist/esm/decorators/parameter.js.map +7 -0
  84. package/dist/esm/decorators/query.js +117 -102
  85. package/dist/esm/decorators/query.js.map +2 -2
  86. package/dist/esm/decorators/requestAnimationFrame.js +105 -0
  87. package/dist/esm/decorators/requestAnimationFrame.js.map +7 -0
  88. package/dist/esm/decorators/resizeObserver.js +134 -55
  89. package/dist/esm/decorators/resizeObserver.js.map +2 -2
  90. package/dist/esm/decorators/setInterval.js +95 -0
  91. package/dist/esm/decorators/setInterval.js.map +7 -0
  92. package/dist/esm/decorators/setTimeout.js +98 -0
  93. package/dist/esm/decorators/setTimeout.js.map +7 -0
  94. package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +9 -0
  95. package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
  96. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -0
  97. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  98. package/dist/esm/elements/SwcAppMixin.js +20 -4
  99. package/dist/esm/elements/SwcAppMixin.js.map +2 -2
  100. package/dist/esm/types/index.js.map +1 -1
  101. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +4961 -1628
  102. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  103. package/dist/types/config/config.d.ts.map +1 -1
  104. package/dist/types/decorators/addEventListener.d.ts +1046 -33
  105. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  106. package/dist/types/decorators/applyAttribute.d.ts +24 -34
  107. package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
  108. package/dist/types/decorators/applyClass.d.ts +36 -34
  109. package/dist/types/decorators/applyClass.d.ts.map +1 -1
  110. package/dist/types/decorators/applyNode.d.ts +32 -20
  111. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  112. package/dist/types/decorators/applyProperty.d.ts +61 -34
  113. package/dist/types/decorators/applyProperty.d.ts.map +1 -1
  114. package/dist/types/decorators/applySlot.d.ts.map +1 -1
  115. package/dist/types/decorators/applyStyle.d.ts +27 -12
  116. package/dist/types/decorators/applyStyle.d.ts.map +1 -1
  117. package/dist/types/decorators/changedAttribute.d.ts +12 -3
  118. package/dist/types/decorators/changedAttribute.d.ts.map +1 -1
  119. package/dist/types/decorators/elementDefine.d.ts +0 -14
  120. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  121. package/dist/types/decorators/emitCustomEvent.d.ts +28 -4
  122. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  123. package/dist/types/decorators/eventMedia.d.ts +25 -0
  124. package/dist/types/decorators/eventMedia.d.ts.map +1 -0
  125. package/dist/types/decorators/index.d.ts +6 -1
  126. package/dist/types/decorators/index.d.ts.map +1 -1
  127. package/dist/types/decorators/intersectionObserver.d.ts +58 -0
  128. package/dist/types/decorators/intersectionObserver.d.ts.map +1 -0
  129. package/dist/types/decorators/mutationObserver.d.ts +44 -25
  130. package/dist/types/decorators/mutationObserver.d.ts.map +1 -1
  131. package/dist/types/decorators/parameter.d.ts +35 -0
  132. package/dist/types/decorators/parameter.d.ts.map +1 -0
  133. package/dist/types/decorators/query.d.ts +57 -14
  134. package/dist/types/decorators/query.d.ts.map +1 -1
  135. package/dist/types/decorators/requestAnimationFrame.d.ts +47 -0
  136. package/dist/types/decorators/requestAnimationFrame.d.ts.map +1 -0
  137. package/dist/types/decorators/resizeObserver.d.ts +43 -23
  138. package/dist/types/decorators/resizeObserver.d.ts.map +1 -1
  139. package/dist/types/decorators/setInterval.d.ts +41 -0
  140. package/dist/types/decorators/setInterval.d.ts.map +1 -0
  141. package/dist/types/decorators/setTimeout.d.ts +41 -0
  142. package/dist/types/decorators/setTimeout.d.ts.map +1 -0
  143. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +7 -1
  144. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
  145. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +6 -0
  146. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
  147. package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
  148. package/dist/types/types/index.d.ts +104 -0
  149. package/dist/types/types/index.d.ts.map +1 -1
  150. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +4961 -1628
  151. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  152. package/package.json +7 -5
  153. package/src/config/config.ts +1 -1
  154. package/src/decorators/addEventListener.ts +1446 -34
  155. package/src/decorators/applyAttribute.ts +60 -36
  156. package/src/decorators/applyClass.ts +86 -26
  157. package/src/decorators/applyNode.ts +124 -36
  158. package/src/decorators/applyProperty.ts +172 -40
  159. package/src/decorators/applySlot.ts +6 -5
  160. package/src/decorators/applyStyle.ts +74 -17
  161. package/src/decorators/changedAttribute.ts +76 -15
  162. package/src/decorators/elementDefine.ts +310 -582
  163. package/src/decorators/emitCustomEvent.ts +73 -5
  164. package/src/decorators/eventMedia.ts +78 -0
  165. package/src/decorators/index.ts +6 -1
  166. package/src/decorators/intersectionObserver.ts +275 -0
  167. package/src/decorators/mutationObserver.ts +282 -89
  168. package/src/decorators/parameter.ts +81 -0
  169. package/src/decorators/query.ts +168 -126
  170. package/src/decorators/requestAnimationFrame.ts +158 -0
  171. package/src/decorators/resizeObserver.ts +211 -89
  172. package/src/decorators/setInterval.ts +136 -0
  173. package/src/decorators/setTimeout.ts +139 -0
  174. package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +17 -0
  175. package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +19 -0
  176. package/src/elements/SwcAppMixin.ts +20 -5
  177. package/src/types/index.ts +141 -0
  178. package/src/types/window.d.ts +2 -18
  179. package/dist/cjs/decorators/queryAll.js +0 -181
  180. package/dist/cjs/decorators/queryAll.js.map +0 -7
  181. package/dist/cjs/examples/RxJSOperatorsExample.js +0 -285
  182. package/dist/cjs/examples/RxJSOperatorsExample.js.map +0 -7
  183. package/dist/esm/decorators/queryAll.js +0 -162
  184. package/dist/esm/decorators/queryAll.js.map +0 -7
  185. package/dist/esm/examples/RxJSOperatorsExample.js +0 -266
  186. package/dist/esm/examples/RxJSOperatorsExample.js.map +0 -7
  187. package/dist/types/decorators/queryAll.d.ts +0 -22
  188. package/dist/types/decorators/queryAll.d.ts.map +0 -1
  189. package/dist/types/examples/RxJSOperatorsExample.d.ts +0 -94
  190. package/dist/types/examples/RxJSOperatorsExample.d.ts.map +0 -1
  191. package/src/decorators/queryAll.ts +0 -186
  192. package/src/examples/RxJSOperatorsExample.ts +0 -279
@@ -24,24 +24,30 @@ __export(elementDefine_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(elementDefine_exports);
26
26
  var import_core = require("@dooboostore/core");
27
- var import_operators = require("@dooboostore/core/message/operators");
28
27
  var import_addEventListener = require("./addEventListener");
29
28
  var import_mutationObserver = require("./mutationObserver");
30
29
  var import_resizeObserver = require("./resizeObserver");
30
+ var import_intersectionObserver = require("./intersectionObserver");
31
31
  var import_lifecycles = require("./lifecycles");
32
32
  var import_emitCustomEvent = require("./emitCustomEvent");
33
33
  var import_changedAttribute = require("./changedAttribute");
34
34
  var import_applyAttribute = require("./applyAttribute");
35
35
  var import_query = require("./query");
36
- var import_queryAll = require("./queryAll");
37
36
  var import_Utils = require("../utils/Utils");
38
37
  var import_config = require("../config/config");
39
38
  var import_Inject = require("@dooboostore/simple-boot/decorators/inject/Inject");
39
+ var import_parameter = require("./parameter");
40
40
  var import_types = require("../types");
41
41
  var import_core_web = require("@dooboostore/core-web");
42
42
  var import_SwcAppMixin = require("../elements/SwcAppMixin");
43
43
  var import_state = require("./state");
44
44
  var import_applyProperty = require("./applyProperty");
45
+ var import_subscribeSwcAppMessageWhileConnected = require("./subscribeSwcAppMessageWhileConnected");
46
+ var import_subscribeSwcAppRouteChangeWhileConnected = require("./subscribeSwcAppRouteChangeWhileConnected");
47
+ var import_setInterval = require("./setInterval");
48
+ var import_setTimeout = require("./setTimeout");
49
+ var import_requestAnimationFrame = require("./requestAnimationFrame");
50
+ var import_eventMedia = require("./eventMedia");
45
51
  const ELEMENT_CONFIG_KEY = Symbol.for("simple-web-component:element-config");
46
52
  const getElementConfig = (target) => {
47
53
  const constructor = target instanceof Function ? target : target.constructor;
@@ -65,7 +71,7 @@ const ensureInit = (inst) => {
65
71
  delete inst[meta.propertyKey];
66
72
  });
67
73
  }
68
- const queryAllList = (0, import_queryAll.getQueryAllMetadata)(target);
74
+ const queryAllList = (0, import_query.getQueryAllMetadata)(target);
69
75
  if (queryAllList) {
70
76
  queryAllList.forEach((meta) => {
71
77
  delete inst[meta.propertyKey];
@@ -158,6 +164,9 @@ const setupPrototype = (proto, win) => {
158
164
  if (typeof this[methodName] !== "function") return;
159
165
  const useHostSet = hostSet ?? import_Utils.SwcUtils.getHelperAndHostSet(win, this);
160
166
  const app = useHostSet?.$appHost?.simpleApplication;
167
+ const helperSetValue = import_Utils.SwcUtils.getHelperSet(win);
168
+ const helperHostSetValue = { ...helperSetValue, ...useHostSet, $this: this };
169
+ const kindValues = { hostSet: useHostSet, helperHostSet: helperHostSetValue, helperSet: helperSetValue };
161
170
  if (app) {
162
171
  const otherStorage = /* @__PURE__ */ new Map();
163
172
  const situations = new import_Inject.SituationTypeContainers([new import_Inject.SituationTypeContainer({ situationType: import_types.InjectSituationType.HOST_SET, data: useHostSet }), new import_Inject.SituationTypeContainer({ situationType: import_types.InjectSituationType.APP_HOST, data: useHostSet.$appHost }), new import_Inject.SituationTypeContainer({ situationType: import_types.InjectSituationType.APP_HOSTS, data: useHostSet.$appHosts }), new import_Inject.SituationTypeContainer({
@@ -168,16 +177,23 @@ const setupPrototype = (proto, win) => {
168
177
  data: useHostSet.$firstAppHost
169
178
  }), new import_Inject.SituationTypeContainer({ situationType: import_types.InjectSituationType.LAST_APP_HOST, data: useHostSet.$lastAppHost })]);
170
179
  otherStorage.set(import_Inject.SituationTypeContainers, situations);
180
+ const firstCheckMaker = ({ target, targetKey }, token, idx) => {
181
+ const saves = (0, import_parameter.getParameterMetadata)(target, targetKey);
182
+ const found = saves.find((s) => s.index === idx);
183
+ return found ? kindValues[found.kind] : void 0;
184
+ };
171
185
  return app.simstanceManager.executeBindParameterSim(
172
186
  {
173
187
  target: this,
174
188
  targetKey: methodName,
175
- inputParameters: extraArgs
189
+ inputParameters: extraArgs,
190
+ firstCheckMaker: [firstCheckMaker]
176
191
  },
177
192
  otherStorage
178
193
  );
179
194
  } else {
180
- return this[methodName](...extraArgs);
195
+ const args = (0, import_parameter.buildSwcParameterArgs)(this, methodName, kindValues, extraArgs);
196
+ return this[methodName](...args);
181
197
  }
182
198
  };
183
199
  proto._bindAttributeEvent = function(el, attrName, script, eventName) {
@@ -249,12 +265,6 @@ const elementDefine = (name, config = {}) => (constructor) => {
249
265
  }
250
266
  metadata.extends = extendsTagName;
251
267
  }
252
- const emitCustomEventList = (0, import_emitCustomEvent.getEmitCustomEventMetadataList)(constructor) || [];
253
- const emitHostCustomEventList = emitCustomEventList.filter((meta) => meta.selector === "$this" || meta.selector === "");
254
- const addEventListenerList = (0, import_addEventListener.getAddEventListenerMetadata)(constructor) || [];
255
- const mutationObserverList = (0, import_mutationObserver.getMutationObserverMetadata)(constructor) || [];
256
- const resizeObserverList = (0, import_resizeObserver.getResizeObserverMetadata)(constructor) || [];
257
- const attrChangeMap = (0, import_changedAttribute.findAllAttributeChangedMetadata)(constructor);
258
268
  const attributeList = (0, import_applyAttribute.findAllAttributeMetadata)(constructor);
259
269
  const applyAttributeMap = (0, import_applyAttribute.findAllAttributeApplyMetadata)(constructor);
260
270
  const swcLifecycleAttributes = ["swc-on-constructor", "swc-on-connected", "swc-on-disconnected", "swc-on-before-connected", "swc-on-after-connected", "swc-on-before-disconnected", "swc-on-after-disconnected", "swc-on-before-adopted", "swc-on-after-adopted", "swc-on-attribute-changed"];
@@ -262,22 +272,227 @@ const elementDefine = (name, config = {}) => (constructor) => {
262
272
  const attributeApplyNames = Array.from(applyAttributeMap.values()).map((it) => it.targetAttributeName).filter(Boolean);
263
273
  const hostAttributes = attributeList.filter((it) => it.selector === "$this").map((it) => it.propertyKey || String(it.propertyKey));
264
274
  const originalStaticObservedAttributes = constructor.observedAttributes ?? [];
265
- const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...metadata.observedAttributes ?? [], ...originalStaticObservedAttributes, ...attrChangeMap.keys(), ...attributeApplyNames, ...hostAttributes, ...emitHostCustomEventList.map((it) => it.options.attributeName).filter(Boolean), ...swcLifecycleAttributes, ...swcOnEvents])];
266
275
  const proto = constructor.prototype;
267
276
  setupPrototype(proto, win);
268
277
  let helperHostSet = null;
269
- let boundListeners = [];
270
- let shadowMutationObserver = null;
271
- let lightMutationObserver = null;
272
- let resizeObserver = null;
273
- let resizeObservers = [];
274
- let removeObserverCallbacks = [];
278
+ const eventCycler = new import_addEventListener.EventListenerLifeCycler();
279
+ const cyclers = [
280
+ eventCycler,
281
+ new import_changedAttribute.ChangedAttributeLifeCycler(),
282
+ new import_emitCustomEvent.EmitCustomEventLifeCycler(),
283
+ new import_resizeObserver.ResizeObserverLifeCycler(),
284
+ new import_intersectionObserver.IntersectionObserverLifeCycler(),
285
+ new import_mutationObserver.MutationObserverLifeCycler(),
286
+ new import_subscribeSwcAppMessageWhileConnected.MessageSubscribeLifeCycler(),
287
+ new import_subscribeSwcAppRouteChangeWhileConnected.RouteSubscribeLifeCycler(),
288
+ new import_setInterval.SetIntervalLifeCycler(),
289
+ new import_setTimeout.SetTimeoutLifeCycler(),
290
+ new import_requestAnimationFrame.RequestAnimationFrameLifeCycler(),
291
+ new import_eventMedia.EventMediaLifeCycler()
292
+ ];
293
+ const cyclerObservedAttributes = cyclers.flatMap((c) => c.getObservedAttributeNames?.(constructor) ?? []);
294
+ const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...metadata.observedAttributes ?? [], ...originalStaticObservedAttributes, ...cyclerObservedAttributes, ...attributeApplyNames, ...hostAttributes, ...swcLifecycleAttributes, ...swcOnEvents])];
295
+ const buildObservers = async (helperHostSet2) => {
296
+ const inst = helperHostSet2.$this;
297
+ const observers = [];
298
+ let resizeObserverSet = [];
299
+ let mutationObserverSet = [];
300
+ let intersectionObserverSet = [];
301
+ const resolveDelegateRoots = (delegateRoot) => {
302
+ const r = delegateRoot || "auto";
303
+ const roots = [];
304
+ if (r === "auto") roots.push(inst.shadowRoot || inst);
305
+ else if (r === "light") roots.push(inst);
306
+ else if (r === "shadow" && inst.shadowRoot) roots.push(inst.shadowRoot);
307
+ else if (r === "all") {
308
+ roots.push(inst);
309
+ if (inst.shadowRoot) roots.push(inst.shadowRoot);
310
+ }
311
+ return roots;
312
+ };
313
+ for (const c of cyclers) {
314
+ const result = await c.onConnected?.(helperHostSet2, resizeObserverSet);
315
+ if (!result) continue;
316
+ if (result.resizeObserverSet?.length) resizeObserverSet = [...resizeObserverSet, ...result.resizeObserverSet];
317
+ if (result.mutationObserverSet?.length) mutationObserverSet = [...mutationObserverSet, ...result.mutationObserverSet];
318
+ if (result.intersectionObserverSet?.length) intersectionObserverSet = [...intersectionObserverSet, ...result.intersectionObserverSet];
319
+ }
320
+ const resizeDelegates = (resizeObserverSet ?? []).filter((t) => t.delegate && typeof t.target === "string");
321
+ let resizeObserve;
322
+ let resizeUnobserve;
323
+ const resizeObserved = /* @__PURE__ */ new WeakSet();
324
+ if (resizeObserverSet?.length) {
325
+ const roCallbacks = [...new Set(resizeObserverSet.map((e) => e.callback))];
326
+ const ro = new win.ResizeObserver((entries, obs) => {
327
+ for (const cb of roCallbacks) cb(entries, obs);
328
+ });
329
+ for (const e of resizeObserverSet) {
330
+ if (e.delegate) continue;
331
+ if (typeof e.target === "string") {
332
+ const scope = resolveDelegateRoots(e.delegateRoot);
333
+ for (const sr of scope) {
334
+ sr.querySelectorAll(e.target).forEach((el) => {
335
+ if (!resizeObserved.has(el)) {
336
+ ro.observe(el, e.options);
337
+ resizeObserved.add(el);
338
+ }
339
+ });
340
+ }
341
+ continue;
342
+ }
343
+ ro.observe(e.target, e.options);
344
+ if (e.target instanceof Element) resizeObserved.add(e.target);
345
+ }
346
+ resizeObserve = (el, opts) => {
347
+ if (resizeObserved.has(el)) return;
348
+ ro.observe(el, opts);
349
+ resizeObserved.add(el);
350
+ };
351
+ resizeUnobserve = (el) => {
352
+ if (!resizeObserved.has(el)) return;
353
+ ro.unobserve(el);
354
+ resizeObserved.delete(el);
355
+ };
356
+ observers.push(ro);
357
+ }
358
+ const intersectionDelegates = [];
359
+ for (const group of intersectionObserverSet) {
360
+ const ioCallbacks = [...new Set(group.observeTargets.map((e) => e.callback))];
361
+ const io = new win.IntersectionObserver((entries, obs) => {
362
+ for (const cb of ioCallbacks) cb(entries, obs);
363
+ }, group.options);
364
+ const ioObserved = /* @__PURE__ */ new WeakSet();
365
+ for (const e of group.observeTargets) {
366
+ if (e.delegate) {
367
+ const target = e.target;
368
+ const observe = (el) => {
369
+ if (ioObserved.has(el)) return;
370
+ io.observe(el);
371
+ ioObserved.add(el);
372
+ };
373
+ const unobserve = (el) => {
374
+ if (!ioObserved.has(el)) return;
375
+ io.unobserve(el);
376
+ ioObserved.delete(el);
377
+ };
378
+ intersectionDelegates.push({ target, delegateRoot: e.delegateRoot, observe, unobserve });
379
+ continue;
380
+ }
381
+ if (typeof e.target === "string") {
382
+ const scope = resolveDelegateRoots(e.delegateRoot);
383
+ for (const sr of scope) {
384
+ sr.querySelectorAll(e.target).forEach((el) => {
385
+ if (!ioObserved.has(el)) {
386
+ io.observe(el);
387
+ ioObserved.add(el);
388
+ }
389
+ });
390
+ }
391
+ continue;
392
+ }
393
+ io.observe(e.target);
394
+ if (e.target instanceof Element) ioObserved.add(e.target);
395
+ }
396
+ observers.push(io);
397
+ }
398
+ const handleResizeDelegate = (n, observe) => {
399
+ if (!resizeObserve || !resizeUnobserve || n.nodeType !== 1) return;
400
+ const el = n;
401
+ for (const d of resizeDelegates) {
402
+ const isThis = d.target === "$this" || d.target === "";
403
+ const matchesSel = (node) => {
404
+ if (!node || node.nodeType !== 1) return false;
405
+ if (isThis) return true;
406
+ return node.matches?.(d.target) || !!node.closest?.(d.target);
407
+ };
408
+ if (matchesSel(el)) {
409
+ observe ? resizeObserve(el, d.options) : resizeUnobserve(el);
410
+ } else if (!isThis) {
411
+ el.querySelectorAll(d.target).forEach((sub) => {
412
+ observe ? resizeObserve(sub, d.options) : resizeUnobserve(sub);
413
+ });
414
+ }
415
+ }
416
+ };
417
+ const handleIntersectionDelegate = (n, observe) => {
418
+ if (n.nodeType !== 1) return;
419
+ const el = n;
420
+ for (const d of intersectionDelegates) {
421
+ const isThis = d.target === "$this" || d.target === "";
422
+ const matchesSel = (node) => {
423
+ if (!node || node.nodeType !== 1) return false;
424
+ if (isThis) return true;
425
+ return node.matches?.(d.target) || !!node.closest?.(d.target);
426
+ };
427
+ if (matchesSel(el)) {
428
+ observe ? d.observe(el) : d.unobserve(el);
429
+ } else if (!isThis) {
430
+ el.querySelectorAll(d.target).forEach((sub) => {
431
+ observe ? d.observe(sub) : d.unobserve(sub);
432
+ });
433
+ }
434
+ }
435
+ };
436
+ if (mutationObserverSet?.length || resizeDelegates.length > 0 || intersectionDelegates.length > 0) {
437
+ const callbacks = [...new Set((mutationObserverSet ?? []).map((e) => e.callback))];
438
+ const mo = new win.MutationObserver((mutations, obs) => {
439
+ for (const mut of mutations) {
440
+ Array.from(mut.addedNodes || []).forEach((n) => {
441
+ handleResizeDelegate(n, true);
442
+ handleIntersectionDelegate(n, true);
443
+ });
444
+ Array.from(mut.removedNodes || []).forEach((n) => {
445
+ handleResizeDelegate(n, false);
446
+ handleIntersectionDelegate(n, false);
447
+ });
448
+ }
449
+ for (const cb of callbacks) cb(mutations, obs);
450
+ });
451
+ const moObserveTargets = /* @__PURE__ */ new Map();
452
+ const mergeMutationInit = (existing, next) => {
453
+ if (!existing) return next;
454
+ const mergedFilter = existing.attributeFilter || next.attributeFilter ? [.../* @__PURE__ */ new Set([...existing.attributeFilter ?? [], ...next.attributeFilter ?? []])] : void 0;
455
+ return {
456
+ childList: existing.childList || next.childList,
457
+ attributes: existing.attributes || next.attributes,
458
+ characterData: existing.characterData || next.characterData,
459
+ subtree: existing.subtree || next.subtree,
460
+ attributeOldValue: existing.attributeOldValue || next.attributeOldValue,
461
+ characterDataOldValue: existing.characterDataOldValue || next.characterDataOldValue,
462
+ attributeFilter: mergedFilter
463
+ };
464
+ };
465
+ const addObserveTarget = (target, options) => {
466
+ moObserveTargets.set(target, mergeMutationInit(moObserveTargets.get(target), options));
467
+ };
468
+ for (const e of mutationObserverSet ?? []) {
469
+ if (e.delegate) continue;
470
+ const init = e.options ?? { childList: true };
471
+ if (typeof e.target === "string") {
472
+ const scope = resolveDelegateRoots(e.delegateRoot);
473
+ for (const sr of scope) {
474
+ sr.querySelectorAll(e.target).forEach((el) => addObserveTarget(el, init));
475
+ }
476
+ continue;
477
+ }
478
+ addObserveTarget(e.target, init);
479
+ }
480
+ for (const d of resizeDelegates) {
481
+ for (const r of resolveDelegateRoots(d.delegateRoot)) addObserveTarget(r, { childList: true, subtree: true });
482
+ }
483
+ for (const d of intersectionDelegates) {
484
+ for (const r of resolveDelegateRoots(d.delegateRoot)) addObserveTarget(r, { childList: true, subtree: true });
485
+ }
486
+ for (const [target, options] of moObserveTargets) {
487
+ mo.observe(target, options);
488
+ }
489
+ observers.push(mo);
490
+ }
491
+ inst.__swc_observers = observers;
492
+ };
275
493
  const originalConnected = proto.connectedCallback;
276
494
  proto.connectedCallback = async function() {
277
495
  ensureInit(this);
278
- boundListeners = [];
279
- resizeObservers = [];
280
- removeObserverCallbacks = [];
281
496
  helperHostSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
282
497
  const appHost = helperHostSet.$appHost;
283
498
  const useSsr = (0, import_SwcAppMixin.isSSR)(this);
@@ -290,14 +505,12 @@ const elementDefine = (name, config = {}) => (constructor) => {
290
505
  }
291
506
  const conf = getElementConfig(this);
292
507
  const currentWin = this._resolveWindow(conf);
293
- const bMethods = (0, import_lifecycles.findAllOnConnectedBeforeMetadata)(this);
294
- for (const m of bMethods) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
508
+ for (const m of (0, import_lifecycles.findAllOnConnectedBeforeMetadata)(this)) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
295
509
  this._executeSwcScript("swc-on-before-connected", helperHostSet);
296
510
  const targetConnectedList = useSsr ? [] : (0, import_lifecycles.findAllOnConnectedMetadata)(constructor);
297
511
  const shadowMode = conf?.useShadow || targetConnectedList.find((it) => it.options.useShadow)?.options.useShadow;
298
512
  if (shadowMode && !this.shadowRoot) {
299
513
  const mode = shadowMode === true ? "open" : shadowMode;
300
- console.log("tagName=", this.tagName, "mode", mode, this.shadowRoot);
301
514
  this.attachShadow({ mode });
302
515
  }
303
516
  const stateContext = { ...helperHostSet };
@@ -306,7 +519,6 @@ const elementDefine = (name, config = {}) => (constructor) => {
306
519
  });
307
520
  const shadowChildren = [];
308
521
  const lightChildren = [];
309
- console.log("targetConnectList", this.tagName, targetConnectedList.length);
310
522
  if (targetConnectedList.length > 0) {
311
523
  for (const meta of targetConnectedList) {
312
524
  let res = await this._invokeLifecycleMethod(meta.propertyKey, helperHostSet);
@@ -347,366 +559,14 @@ const elementDefine = (name, config = {}) => (constructor) => {
347
559
  });
348
560
  globalDelegatedRoots.add(root);
349
561
  }
350
- const delegateListeners = [];
351
- const nonDelegateListeners = [];
352
- addEventListenerList.forEach((meta) => {
353
- const isStringSelector = typeof meta.selector === "string";
354
- if (meta.options.delegate && isStringSelector && meta.selector !== "$window" && meta.selector !== "$document" && meta.selector !== "$host" && meta.selector !== "$appHost" && meta.selector !== "$firstHost" && meta.selector !== "$lastHost" && meta.selector !== "$firstAppHost" && meta.selector !== "$lastAppHost" && meta.selector !== "$hosts" && meta.selector !== "$appHosts" && meta.selector !== "$this" && meta.selector !== "") {
355
- delegateListeners.push(meta);
356
- } else {
357
- nonDelegateListeners.push(meta);
358
- }
359
- });
360
- const delegatesByTypeAndRoot = /* @__PURE__ */ new Map();
361
- delegateListeners.forEach((meta) => {
362
- const r = meta.options.root || "auto";
363
- const rootKey = `${meta.type}:${r}`;
364
- if (!delegatesByTypeAndRoot.has(rootKey)) {
365
- delegatesByTypeAndRoot.set(rootKey, []);
366
- }
367
- delegatesByTypeAndRoot.get(rootKey).push(meta);
368
- });
369
- delegatesByTypeAndRoot.forEach((metaList, typeRootKey) => {
370
- const [type, rStr] = typeRootKey.split(":");
371
- const r = rStr === "auto" ? "auto" : rStr;
372
- const opts = { capture: metaList[0].options.capture, once: metaList[0].options.once, passive: metaList[0].options.passive };
373
- const bindRoots = [];
374
- if (r === "auto") bindRoots.push(this.shadowRoot || this);
375
- else if (r === "light") bindRoots.push(this);
376
- else if (r === "shadow" && this.shadowRoot) bindRoots.push(this.shadowRoot);
377
- else if (r === "all") {
378
- bindRoots.push(this);
379
- if (this.shadowRoot) bindRoots.push(this.shadowRoot);
380
- }
381
- bindRoots.forEach((br) => {
382
- const sortedMetaList = [...metaList].sort((a, b) => {
383
- const aStop = a.options.stopPropagation ? 1 : 0;
384
- const bStop = b.options.stopPropagation ? 1 : 0;
385
- return bStop - aStop;
386
- });
387
- const unifiedHandler = async (event) => {
388
- for (const meta of sortedMetaList) {
389
- const { selector, options } = meta;
390
- const matchedEl = event.target?.closest(selector);
391
- if (matchedEl && br.contains(matchedEl)) {
392
- if (options.filter) {
393
- const helper = import_Utils.SwcUtils.getHelperAndHostSet(currentWin, matchedEl);
394
- if (!options.filter(event, helper)) {
395
- continue;
396
- }
397
- }
398
- if (options.stopPropagation) event.stopPropagation();
399
- if (options.stopImmediatePropagation) event.stopImmediatePropagation();
400
- if (options.preventDefault) event.preventDefault();
401
- const currentHostSet = import_Utils.SwcUtils.getHostSet(this);
402
- const args = { event, ...currentHostSet, $el: matchedEl, $root: br };
403
- await this[meta.propertyKey](event, { ...currentHostSet, $matchedElement: matchedEl }, args);
404
- if (event.cancelBubble) break;
405
- }
406
- }
407
- };
408
- br.addEventListener(type, unifiedHandler, opts);
409
- const onRemoves = [];
410
- for (const m of sortedMetaList) {
411
- if (m.options.removeListener) {
412
- onRemoves.push({ fn: m.options.removeListener, opts: m.options });
413
- }
414
- }
415
- boundListeners.push({ target: br, type, handler: unifiedHandler, options: opts, onRemoves });
416
- });
417
- });
418
- nonDelegateListeners.forEach((meta) => {
419
- const { selector, type, options } = meta;
420
- const opts = { capture: options.capture, once: options.once, passive: options.passive };
421
- const bindTargets = [];
422
- const r = options.root || "auto";
423
- let resolvedSelector = null;
424
- if (typeof selector === "function") {
425
- const hostSet = import_Utils.SwcUtils.getHelperAndHostSet(currentWin, this);
426
- const result = selector(this, hostSet);
427
- if (typeof result === "string") {
428
- resolvedSelector = result;
429
- } else if (result instanceof currentWin.Element) {
430
- bindTargets.push(result);
431
- } else if (result instanceof currentWin.NodeList) {
432
- bindTargets.push(...Array.from(result));
433
- } else if (Array.isArray(result)) {
434
- bindTargets.push(...result);
435
- }
436
- } else {
437
- resolvedSelector = selector;
438
- }
439
- const applyRootOption = (target) => {
440
- if (!target) return;
441
- if (r === "auto") {
442
- bindTargets.push(target.shadowRoot || target);
443
- } else {
444
- if (r === "light" || r === "all") bindTargets.push(target);
445
- if ((r === "shadow" || r === "all") && target.shadowRoot) bindTargets.push(target.shadowRoot);
446
- }
447
- };
448
- if (resolvedSelector) {
449
- if (resolvedSelector === "$window") bindTargets.push(currentWin);
450
- else if (resolvedSelector === "$document") bindTargets.push(currentWin.document);
451
- else if (resolvedSelector === "$host") applyRootOption(helperHostSet.$host);
452
- else if (resolvedSelector === "$parentHost") applyRootOption(helperHostSet.$parentHost);
453
- else if (resolvedSelector === "$appHost") applyRootOption(helperHostSet.$appHost);
454
- else if (resolvedSelector === "$firstHost") applyRootOption(helperHostSet.$firstHost);
455
- else if (resolvedSelector === "$lastHost") applyRootOption(helperHostSet.$lastHost);
456
- else if (resolvedSelector === "$firstAppHost") applyRootOption(helperHostSet.$firstAppHost);
457
- else if (resolvedSelector === "$lastAppHost") applyRootOption(helperHostSet.$lastAppHost);
458
- else if (resolvedSelector === "$hosts") helperHostSet.$hosts.forEach(applyRootOption);
459
- else if (resolvedSelector === "$appHosts") helperHostSet.$appHosts.forEach(applyRootOption);
460
- else if (resolvedSelector === "$this" || !resolvedSelector) applyRootOption(this);
461
- else {
462
- const searchRoots = [];
463
- if (r === "auto") searchRoots.push(this.shadowRoot || this);
464
- else if (r === "light") searchRoots.push(this);
465
- else if (r === "shadow" && this.shadowRoot) searchRoots.push(this.shadowRoot);
466
- else if (r === "all") {
467
- searchRoots.push(this);
468
- if (this.shadowRoot) searchRoots.push(this.shadowRoot);
469
- }
470
- searchRoots.forEach((sr) => {
471
- sr.querySelectorAll(resolvedSelector).forEach((el) => bindTargets.push(el));
472
- });
473
- }
474
- }
475
- bindTargets.forEach((t) => {
476
- const handler = async (event) => {
477
- if (options.filter) {
478
- const helper = import_Utils.SwcUtils.getHelperAndHostSet(currentWin, t);
479
- if (!options.filter(event, { currentThis: this, helper })) {
480
- return;
481
- }
482
- }
483
- if (options.stopPropagation) event.stopPropagation();
484
- if (options.stopImmediatePropagation) event.stopImmediatePropagation();
485
- if (options.preventDefault) event.preventDefault();
486
- const currentHostSet = import_Utils.SwcUtils.getHostSet(this);
487
- const args = { event, ...currentHostSet, $el: t, $root: t };
488
- await this[meta.propertyKey](event, { currentHostSet, $matchedElement: event.currentTarget }, args);
489
- };
490
- const eventSubject = new import_core.Subject();
491
- let eventStream = eventSubject;
492
- if (options.debounceTime !== void 0 && options.debounceTime > 0) {
493
- eventStream = eventStream.pipe((0, import_operators.debounceTime)(options.debounceTime));
494
- }
495
- if (options.throttleTime !== void 0 && options.throttleTime > 0) {
496
- eventStream = eventStream.pipe((0, import_operators.throttleTime)(options.throttleTime));
497
- }
498
- if (options.distinctUntilChanged !== void 0 && options.distinctUntilChanged !== false) {
499
- if (typeof options.distinctUntilChanged === "function") {
500
- eventStream = eventStream.pipe((0, import_operators.distinctUntilChanged)(options.distinctUntilChanged));
501
- } else {
502
- eventStream = eventStream.pipe((0, import_operators.distinctUntilChanged)());
503
- }
504
- }
505
- const subscription = eventStream.subscribe({
506
- next: (event) => {
507
- handler(event).catch((err) => console.error("Event handler error:", err));
508
- },
509
- error: (err) => console.error("Event stream error:", err)
510
- });
511
- const wrappedHandler = (event) => {
512
- eventSubject.next(event);
513
- };
514
- t.addEventListener(type, wrappedHandler, opts);
515
- const onRemoves = options.removeListener ? [{ fn: options.removeListener, opts }] : [];
516
- boundListeners.push({ target: t, type, handler: wrappedHandler, options: opts, subscription, onRemoves });
517
- });
518
- });
519
- shadowMutationObserver = null;
520
- lightMutationObserver = null;
521
- resizeObserver = null;
522
- if (resizeObserverList.length > 0) {
523
- const root2 = this.shadowRoot || this;
524
- resizeObserver = new ResizeObserver((entries, obs) => {
525
- for (const m of resizeObserverList) {
526
- let matchedEls = [];
527
- if (m.options.delegate && typeof m.selector === "string") {
528
- const isThis = m.selector === "$this" || m.selector === "";
529
- const matchesSel = (node) => {
530
- if (!node || node.nodeType !== 1) return false;
531
- if (isThis) return true;
532
- const el = node;
533
- return el.matches?.(m.selector) || !!el.closest?.(m.selector);
534
- };
535
- matchedEls = entries.map((e) => e.target).filter(matchesSel);
536
- } else {
537
- matchedEls = entries.map((e) => e.target).filter((t) => t && t.nodeType === 1);
538
- }
539
- if (matchedEls.length === 0) continue;
540
- if (m.options.filter) {
541
- const helper = import_Utils.SwcUtils.getHelperAndHostSet(currentWin, this);
542
- if (!m.options.filter(matchedEls, { currentThis: this, helper })) continue;
543
- }
544
- const hostSet = import_Utils.SwcUtils.getHostSet(this);
545
- this[m.propertyKey](matchedEls, entries, obs, { ...hostSet, $root: root2 });
546
- }
547
- });
548
- resizeObservers.push(resizeObserver);
549
- for (const m of resizeObserverList) {
550
- if (m.options.removeObserver) {
551
- removeObserverCallbacks.push({ fn: m.options.removeObserver, target: root2, opts: m.options });
552
- }
553
- }
554
- }
555
- const shadowMetas = mutationObserverList.filter((m) => {
556
- const r = m.options.root || "auto";
557
- return this.shadowRoot && (r === "shadow" || r === "all" || r === "auto");
558
- });
559
- const lightMetas = mutationObserverList.filter((m) => {
560
- const r = m.options.root || "auto";
561
- return r === "light" || r === "all" || !this.shadowRoot && r === "auto";
562
- });
563
- const setupMutationObserver = (root2, metas, resizeDelegates = []) => {
564
- if (metas.length === 0) return null;
565
- const initFrom = (o) => {
566
- const init = {
567
- childList: o.childList,
568
- attributes: o.attributes,
569
- characterData: o.characterData,
570
- subtree: o.subtree,
571
- attributeFilter: o.attributeFilter,
572
- attributeOldValue: o.attributeOldValue,
573
- characterDataOldValue: o.characterDataOldValue
574
- };
575
- if (!init.childList && !init.attributes && !init.characterData) init.childList = true;
576
- return init;
577
- };
578
- const observer = new MutationObserver((mutations, obs) => {
579
- for (const meta of metas) {
580
- const { selector, options } = meta;
581
- let matchedEls = [];
582
- if (options.delegate && typeof selector === "string") {
583
- const isThis = selector === "$this" || selector === "";
584
- const matchesSel = (node) => {
585
- if (!node || node.nodeType !== 1) return false;
586
- if (isThis) return true;
587
- const el = node;
588
- return el.matches?.(selector) || !!el.closest?.(selector);
589
- };
590
- matchedEls = mutations.flatMap((m) => {
591
- const els = [];
592
- if (matchesSel(m.target)) els.push(m.target);
593
- Array.from(m.addedNodes || []).filter(matchesSel).forEach((n) => els.push(n));
594
- Array.from(m.removedNodes || []).filter(matchesSel).forEach((n) => els.push(n));
595
- return els;
596
- });
597
- } else if (typeof selector === "string") {
598
- const isThis = selector === "$this" || selector === "";
599
- const matchesSel = (node) => {
600
- if (!node || node.nodeType !== 1) return false;
601
- if (isThis) return true;
602
- return node.matches?.(selector);
603
- };
604
- matchedEls = mutations.flatMap((m) => {
605
- const els = [];
606
- if (matchesSel(m.target)) els.push(m.target);
607
- Array.from(m.addedNodes || []).filter(matchesSel).forEach((n) => els.push(n));
608
- Array.from(m.removedNodes || []).filter(matchesSel).forEach((n) => els.push(n));
609
- return els;
610
- });
611
- } else {
612
- matchedEls = mutations.map((m) => m.target).filter((t) => t && t.nodeType === 1);
613
- }
614
- if (matchedEls.length === 0) continue;
615
- if (options.filter) {
616
- const helper = import_Utils.SwcUtils.getHelperAndHostSet(currentWin, this);
617
- if (!options.filter(matchedEls, { currentThis: this, helper })) continue;
618
- }
619
- const hostSet = import_Utils.SwcUtils.getHostSet(this);
620
- this[meta.propertyKey](matchedEls, mutations, obs, { ...hostSet, $root: root2 });
621
- }
622
- if (resizeDelegates.length > 0 && resizeObserver) {
623
- const handle = (n, observe) => {
624
- if (n.nodeType !== 1) return;
625
- const el = n;
626
- for (const m of resizeDelegates) {
627
- if (typeof m.selector !== "string") continue;
628
- const isThis = m.selector === "$this" || m.selector === "";
629
- const matchesSel = (node) => {
630
- if (!node || node.nodeType !== 1) return false;
631
- if (isThis) return true;
632
- const e = node;
633
- return e.matches?.(m.selector) || !!e.closest?.(m.selector);
634
- };
635
- if (matchesSel(el)) {
636
- if (observe) resizeObserver.observe(el, m.options.box ? { box: m.options.box } : void 0);
637
- else resizeObserver.unobserve(el);
638
- } else if (!isThis) {
639
- el.querySelectorAll(m.selector).forEach((sub) => {
640
- if (observe) resizeObserver.observe(sub, m.options.box ? { box: m.options.box } : void 0);
641
- else resizeObserver.unobserve(sub);
642
- });
643
- }
644
- }
645
- };
646
- for (const m of mutations) {
647
- Array.from(m.addedNodes || []).forEach((n) => handle(n, true));
648
- Array.from(m.removedNodes || []).forEach((n) => handle(n, false));
649
- }
650
- }
651
- });
652
- const hasDelegate = metas.some((m) => m.options.delegate) || resizeDelegates.some((m) => m.options.delegate);
653
- if (hasDelegate) {
654
- observer.observe(root2, { childList: true, subtree: true });
655
- }
656
- const nonDelegateMetas = metas.filter((m) => !m.options.delegate);
657
- for (const m of nonDelegateMetas) {
658
- const { selector, options } = m;
659
- const mInit = initFrom(options);
660
- if (typeof selector === "string") {
661
- if (selector === "$this" || selector === "") {
662
- observer.observe(root2, mInit);
663
- } else {
664
- root2.querySelectorAll(selector).forEach((el) => observer.observe(el, mInit));
665
- }
666
- } else if (typeof selector === "function") {
667
- observer.observe(root2, mInit);
668
- }
669
- }
670
- return observer;
671
- };
672
- const shadowResizeDelegateMetas = resizeObserverList.filter((m) => {
673
- if (!m.options.delegate) return false;
674
- const r = m.options.root || "auto";
675
- return this.shadowRoot && (r === "shadow" || r === "all" || r === "auto");
676
- });
677
- const lightResizeDelegateMetas = resizeObserverList.filter((m) => {
678
- if (!m.options.delegate) return false;
679
- const r = m.options.root || "auto";
680
- return r === "light" || r === "all" || !this.shadowRoot && r === "auto";
681
- });
682
- if (this.shadowRoot) shadowMutationObserver = setupMutationObserver(this.shadowRoot, shadowMetas, shadowResizeDelegateMetas);
683
- lightMutationObserver = setupMutationObserver(this, lightMetas, lightResizeDelegateMetas);
684
- for (const m of mutationObserverList) {
685
- if (m.options.removeObserver) {
686
- const rootForM = this.shadowRoot && (m.options.root === "shadow" || m.options.root === "all" || m.options.root === "auto" && this.shadowRoot) ? this.shadowRoot : this;
687
- removeObserverCallbacks.push({ fn: m.options.removeObserver, target: rootForM, opts: m.options });
688
- }
689
- }
562
+ await buildObservers(import_Utils.SwcUtils.getHelperAndHostSet(win, this));
690
563
  if (originalConnected) await originalConnected.apply(this);
691
- const aMethods = (0, import_lifecycles.findAllOnConnectedAfterMetadata)(this);
692
- for (const m of aMethods) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
564
+ for (const m of (0, import_lifecycles.findAllOnConnectedAfterMetadata)(this)) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
693
565
  this._executeSwcScript("swc-on-connected", helperHostSet);
694
566
  this._executeSwcScript("swc-on-after-connected", helperHostSet);
695
567
  this.__swc_connected = true;
696
- for (let [name2, metaList] of Array.from(attrChangeMap)) {
697
- for (const meta of metaList) {
698
- if (meta.options.while === "connected") {
699
- const val = (0, import_applyAttribute.getAttributeValue)(this, name2, { type: meta.options.type });
700
- if (val !== null) {
701
- await this[meta.propertyKey](val, null, name2, helperHostSet);
702
- }
703
- }
704
- }
705
- }
706
568
  } finally {
707
- for (let m of (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_CONNECTED_COMPLETED_METADATA_KEY)) {
708
- await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
709
- }
569
+ for (const m of (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_CONNECTED_COMPLETED_METADATA_KEY)) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
710
570
  if (appHost && typeof appHost._connectedDone === "function") {
711
571
  await appHost._connectedDone(this);
712
572
  }
@@ -714,55 +574,24 @@ const elementDefine = (name, config = {}) => (constructor) => {
714
574
  };
715
575
  const originalDisconnected = proto.disconnectedCallback;
716
576
  proto.disconnectedCallback = function() {
717
- const appHost = helperHostSet.$appHost;
577
+ const appHost = helperHostSet?.$appHost;
718
578
  if (appHost && typeof appHost._disconnected === "function") {
719
579
  appHost._disconnected(this);
720
580
  }
721
581
  this._executeSwcScript("swc-on-before-disconnected", helperHostSet);
722
- const bMethods = (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_BEFORE_DISCONNECTED_METADATA_KEY);
723
- for (const m of bMethods) this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
724
- if (boundListeners.length > 0) {
725
- boundListeners.forEach((l) => {
726
- l.target.removeEventListener(l.type, l.handler, l.options);
727
- if (l.subscription && typeof l.subscription.unsubscribe === "function") {
728
- l.subscription.unsubscribe();
729
- }
730
- if (Array.isArray(l.onRemoves)) {
731
- for (const r of l.onRemoves) {
732
- try {
733
- r.fn(l.target, r.opts);
734
- } catch (e) {
735
- console.error("[SWC] removeListener error:", e);
736
- }
737
- }
738
- }
739
- });
740
- boundListeners = [];
741
- }
742
- const _obs = [shadowMutationObserver, lightMutationObserver, resizeObserver, ...resizeObservers];
743
- for (const o of _obs) {
582
+ for (const m of (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_BEFORE_DISCONNECTED_METADATA_KEY)) this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
583
+ for (const c of cyclers) c.onDisconnected?.(helperHostSet);
584
+ for (const o of this.__swc_observers ?? []) {
744
585
  try {
745
586
  o?.disconnect?.();
746
587
  } catch (e) {
747
588
  console.error("[SWC] observer disconnect error:", e);
748
589
  }
749
590
  }
750
- shadowMutationObserver = null;
751
- lightMutationObserver = null;
752
- resizeObserver = null;
753
- resizeObservers = [];
754
- for (const cb of removeObserverCallbacks) {
755
- try {
756
- cb.fn(cb.target, cb.opts);
757
- } catch (e) {
758
- console.error("[SWC] removeObserver error:", e);
759
- }
760
- }
761
- removeObserverCallbacks = [];
591
+ this.__swc_observers = [];
762
592
  new import_core_web.ElementApply(this, { id: this._swcId }).removeAllEventListener();
763
593
  if (originalDisconnected) originalDisconnected.apply(this);
764
- const aMethods = (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_AFTER_DISCONNECTED_METADATA_KEY);
765
- for (const m of aMethods) this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
594
+ for (const m of (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_AFTER_DISCONNECTED_METADATA_KEY)) this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
766
595
  this._executeSwcScript("swc-on-disconnected", helperHostSet);
767
596
  this._executeSwcScript("swc-on-after-disconnected", helperHostSet);
768
597
  this.__swc_connected = false;
@@ -771,35 +600,34 @@ const elementDefine = (name, config = {}) => (constructor) => {
771
600
  proto.adoptedCallback = function() {
772
601
  const hostSet = import_Utils.SwcUtils.getHostSet(this);
773
602
  this._executeSwcScript("swc-on-before-adopted", hostSet);
774
- const bMethods = (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_BEFORE_ADOPTED_METADATA_KEY);
775
- for (const m of bMethods) this._invokeLifecycleMethod(m.propertyKey, hostSet);
603
+ for (const m of (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_BEFORE_ADOPTED_METADATA_KEY)) this._invokeLifecycleMethod(m.propertyKey, hostSet);
604
+ for (const c of cyclers) c.onAdopted?.(helperHostSet);
776
605
  if (originalAdopted) originalAdopted.apply(this);
777
- const aMethods = (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_AFTER_ADOPTED_METADATA_KEY);
778
- for (const m of aMethods) this._invokeLifecycleMethod(m.propertyKey, hostSet);
606
+ for (const m of (0, import_lifecycles.findAllLifecycleMetadata)(this, import_lifecycles.ON_AFTER_ADOPTED_METADATA_KEY)) this._invokeLifecycleMethod(m.propertyKey, hostSet);
779
607
  this._executeSwcScript("swc-on-adopted", hostSet);
780
608
  this._executeSwcScript("swc-on-after-adopted", hostSet);
781
609
  };
782
610
  const originalAttributeChanged = proto.attributeChangedCallback;
783
611
  proto.attributeChangedCallback = function(name2, old, newVal) {
784
612
  if (originalAttributeChanged) originalAttributeChanged.apply(this, [name2, old, newVal]);
785
- const hSet = import_Utils.SwcUtils.getHostSet(this);
613
+ const helperAndHostSet = import_Utils.SwcUtils.getHelperAndHostSet(win, this);
786
614
  let processedVal = newVal;
787
615
  if (newVal !== null) {
788
616
  const ae = new import_core.ActionExpression(newVal);
789
617
  const expr = ae.getFirstExpression("callReturn");
790
618
  if (expr) {
791
619
  const win2 = this._resolveWindow?.() || (typeof window !== "undefined" ? window : void 0);
792
- const helperAndHostSet = import_Utils.SwcUtils.getHelperAndHostSet(win2, this);
620
+ const exprHelperAndHostSet = import_Utils.SwcUtils.getHelperAndHostSet(win2, this);
793
621
  const script = import_core_web.ConvertUtils.decodeHtmlEntity(expr.script, win2.document);
794
622
  try {
795
623
  const result = import_core.FunctionUtils.executeReturn({
796
624
  script,
797
625
  context: this,
798
- args: helperAndHostSet
626
+ args: exprHelperAndHostSet
799
627
  });
800
628
  processedVal = result;
801
629
  } catch (e) {
802
- console.error(`[SWC] Failed to execute directive {{= ${expr.script} }} on attribute ${name2}: ${helperAndHostSet}`, e);
630
+ console.error(`[SWC] Failed to execute directive {{= ${expr.script} }} on attribute ${name2}: ${exprHelperAndHostSet}`, e);
803
631
  processedVal = newVal;
804
632
  }
805
633
  }
@@ -810,20 +638,7 @@ const elementDefine = (name, config = {}) => (constructor) => {
810
638
  this._bindAttributeEvent(this, name2, newVal, eventName);
811
639
  }
812
640
  }
813
- const hostCustomEventMeta = emitHostCustomEventList.find((it) => it.options.attributeName === name2);
814
- if (hostCustomEventMeta && newVal !== null) {
815
- this._bindAttributeEvent(this, name2, newVal, hostCustomEventMeta.type);
816
- }
817
- const metaList = attrChangeMap.get(name2);
818
- if (metaList && Array.isArray(metaList)) {
819
- for (const meta of metaList) {
820
- if (meta.options.while === "connected" && !this.__swc_connected) {
821
- continue;
822
- }
823
- const convertedVal = (0, import_changedAttribute.convertAttributeValue)(processedVal, meta.options.type);
824
- this[meta.propertyKey](convertedVal, old, name2, hSet);
825
- }
826
- }
641
+ for (const c of cyclers) c.onAttributeChanged?.(helperAndHostSet, name2, old, processedVal);
827
642
  };
828
643
  Object.defineProperty(constructor, "observedAttributes", {
829
644
  get: () => mergedObservedAttributes,