@dooboostore/simple-web-component 1.0.49 → 1.0.51

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 (251) hide show
  1. package/README.md +790 -337
  2. package/dist/cjs/SwcAppEngine.js.map +2 -2
  3. package/dist/cjs/decorators/addEventListener.js +1925 -22
  4. package/dist/cjs/decorators/addEventListener.js.map +2 -2
  5. package/dist/cjs/decorators/applyAttribute.js +41 -47
  6. package/dist/cjs/decorators/applyAttribute.js.map +2 -2
  7. package/dist/cjs/decorators/applyClass.js +14 -11
  8. package/dist/cjs/decorators/applyClass.js.map +2 -2
  9. package/dist/cjs/decorators/applyNode.js +19 -21
  10. package/dist/cjs/decorators/applyNode.js.map +2 -2
  11. package/dist/cjs/decorators/applyProperty.js +24 -48
  12. package/dist/cjs/decorators/applyProperty.js.map +2 -2
  13. package/dist/cjs/decorators/applySlot.js +9 -8
  14. package/dist/cjs/decorators/applySlot.js.map +2 -2
  15. package/dist/cjs/decorators/applyStyle.js +14 -11
  16. package/dist/cjs/decorators/applyStyle.js.map +2 -2
  17. package/dist/cjs/decorators/around.js +124 -0
  18. package/dist/cjs/decorators/around.js.map +7 -0
  19. package/dist/cjs/decorators/changedAttribute.js +61 -24
  20. package/dist/cjs/decorators/changedAttribute.js.map +2 -2
  21. package/dist/cjs/decorators/elementDefine.js +240 -196
  22. package/dist/cjs/decorators/elementDefine.js.map +3 -3
  23. package/dist/cjs/decorators/emitCustomEvent.js +14 -12
  24. package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
  25. package/dist/cjs/decorators/eventMedia.js +112 -0
  26. package/dist/cjs/decorators/eventMedia.js.map +7 -0
  27. package/dist/cjs/decorators/fetch.js +278 -0
  28. package/dist/cjs/decorators/fetch.js.map +7 -0
  29. package/dist/cjs/decorators/index.js +8 -2
  30. package/dist/cjs/decorators/index.js.map +2 -2
  31. package/dist/cjs/decorators/intersectionObserver.js +76 -65
  32. package/dist/cjs/decorators/intersectionObserver.js.map +2 -2
  33. package/dist/cjs/decorators/lifecycles.js +11 -11
  34. package/dist/cjs/decorators/lifecycles.js.map +2 -2
  35. package/dist/cjs/decorators/mutationObserver.js +97 -90
  36. package/dist/cjs/decorators/mutationObserver.js.map +3 -3
  37. package/dist/cjs/decorators/parameter.js +156 -0
  38. package/dist/cjs/decorators/parameter.js.map +7 -0
  39. package/dist/cjs/decorators/publishSwcAppMessage.js +2 -2
  40. package/dist/cjs/decorators/publishSwcAppMessage.js.map +2 -2
  41. package/dist/cjs/decorators/query.js +11 -5
  42. package/dist/cjs/decorators/query.js.map +2 -2
  43. package/dist/cjs/decorators/requestAnimationFrame.js +115 -0
  44. package/dist/cjs/decorators/requestAnimationFrame.js.map +7 -0
  45. package/dist/cjs/decorators/resizeObserver.js +84 -69
  46. package/dist/cjs/decorators/resizeObserver.js.map +3 -3
  47. package/dist/cjs/decorators/setInterval.js +65 -22
  48. package/dist/cjs/decorators/setInterval.js.map +2 -2
  49. package/dist/cjs/decorators/setTimeout.js +68 -22
  50. package/dist/cjs/decorators/setTimeout.js.map +2 -2
  51. package/dist/cjs/decorators/state.js +13 -10
  52. package/dist/cjs/decorators/state.js.map +2 -2
  53. package/dist/cjs/decorators/{subscribeSwcAppMessageWhileConnected.js → subscribeSwcAppMessage.js} +20 -21
  54. package/dist/cjs/decorators/subscribeSwcAppMessage.js.map +7 -0
  55. package/dist/cjs/decorators/{subscribeSwcAppRouteChangeWhileConnected.js → subscribeSwcAppRouteChange.js} +23 -19
  56. package/dist/cjs/decorators/subscribeSwcAppRouteChange.js.map +7 -0
  57. package/dist/cjs/decorators/swcAppRoute.js +149 -0
  58. package/dist/cjs/decorators/swcAppRoute.js.map +7 -0
  59. package/dist/cjs/elements/SwcApp.js +70 -0
  60. package/dist/cjs/elements/SwcApp.js.map +2 -2
  61. package/dist/cjs/elements/SwcAppMixin.js +256 -67
  62. package/dist/cjs/elements/SwcAppMixin.js.map +3 -3
  63. package/dist/cjs/types/index.js +5 -1
  64. package/dist/cjs/types/index.js.map +2 -2
  65. package/dist/cjs/types/window.d.js.map +1 -1
  66. package/dist/cjs/utils/Utils.js +36 -15
  67. package/dist/cjs/utils/Utils.js.map +2 -2
  68. package/dist/esm/SwcAppEngine.js.map +2 -2
  69. package/dist/esm/decorators/addEventListener.js +1925 -22
  70. package/dist/esm/decorators/addEventListener.js.map +2 -2
  71. package/dist/esm/decorators/applyAttribute.js +41 -47
  72. package/dist/esm/decorators/applyAttribute.js.map +2 -2
  73. package/dist/esm/decorators/applyClass.js +14 -11
  74. package/dist/esm/decorators/applyClass.js.map +2 -2
  75. package/dist/esm/decorators/applyNode.js +20 -22
  76. package/dist/esm/decorators/applyNode.js.map +2 -2
  77. package/dist/esm/decorators/applyProperty.js +24 -48
  78. package/dist/esm/decorators/applyProperty.js.map +2 -2
  79. package/dist/esm/decorators/applySlot.js +9 -8
  80. package/dist/esm/decorators/applySlot.js.map +2 -2
  81. package/dist/esm/decorators/applyStyle.js +14 -11
  82. package/dist/esm/decorators/applyStyle.js.map +2 -2
  83. package/dist/esm/decorators/around.js +105 -0
  84. package/dist/esm/decorators/around.js.map +7 -0
  85. package/dist/esm/decorators/changedAttribute.js +61 -24
  86. package/dist/esm/decorators/changedAttribute.js.map +2 -2
  87. package/dist/esm/decorators/elementDefine.js +238 -194
  88. package/dist/esm/decorators/elementDefine.js.map +3 -3
  89. package/dist/esm/decorators/emitCustomEvent.js +15 -13
  90. package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
  91. package/dist/esm/decorators/eventMedia.js +94 -0
  92. package/dist/esm/decorators/eventMedia.js.map +7 -0
  93. package/dist/esm/decorators/fetch.js +259 -0
  94. package/dist/esm/decorators/fetch.js.map +7 -0
  95. package/dist/esm/decorators/index.js +8 -2
  96. package/dist/esm/decorators/index.js.map +2 -2
  97. package/dist/esm/decorators/intersectionObserver.js +76 -65
  98. package/dist/esm/decorators/intersectionObserver.js.map +2 -2
  99. package/dist/esm/decorators/lifecycles.js +11 -11
  100. package/dist/esm/decorators/lifecycles.js.map +2 -2
  101. package/dist/esm/decorators/mutationObserver.js +97 -90
  102. package/dist/esm/decorators/mutationObserver.js.map +3 -3
  103. package/dist/esm/decorators/parameter.js +137 -0
  104. package/dist/esm/decorators/parameter.js.map +7 -0
  105. package/dist/esm/decorators/publishSwcAppMessage.js +2 -2
  106. package/dist/esm/decorators/publishSwcAppMessage.js.map +2 -2
  107. package/dist/esm/decorators/query.js +11 -5
  108. package/dist/esm/decorators/query.js.map +2 -2
  109. package/dist/esm/decorators/requestAnimationFrame.js +96 -0
  110. package/dist/esm/decorators/requestAnimationFrame.js.map +7 -0
  111. package/dist/esm/decorators/resizeObserver.js +84 -69
  112. package/dist/esm/decorators/resizeObserver.js.map +2 -2
  113. package/dist/esm/decorators/setInterval.js +65 -23
  114. package/dist/esm/decorators/setInterval.js.map +2 -2
  115. package/dist/esm/decorators/setTimeout.js +68 -23
  116. package/dist/esm/decorators/setTimeout.js.map +2 -2
  117. package/dist/esm/decorators/state.js +13 -10
  118. package/dist/esm/decorators/state.js.map +2 -2
  119. package/dist/esm/decorators/subscribeSwcAppMessage.js +53 -0
  120. package/dist/esm/decorators/subscribeSwcAppMessage.js.map +7 -0
  121. package/dist/esm/decorators/{subscribeSwcAppRouteChangeWhileConnected.js → subscribeSwcAppRouteChange.js} +20 -16
  122. package/dist/esm/decorators/subscribeSwcAppRouteChange.js.map +7 -0
  123. package/dist/esm/decorators/swcAppRoute.js +130 -0
  124. package/dist/esm/decorators/swcAppRoute.js.map +7 -0
  125. package/dist/esm/elements/SwcApp.js +70 -0
  126. package/dist/esm/elements/SwcApp.js.map +2 -2
  127. package/dist/esm/elements/SwcAppMixin.js +258 -69
  128. package/dist/esm/elements/SwcAppMixin.js.map +3 -3
  129. package/dist/esm/types/index.js +5 -1
  130. package/dist/esm/types/index.js.map +2 -2
  131. package/dist/esm/utils/Utils.js +36 -15
  132. package/dist/esm/utils/Utils.js.map +2 -2
  133. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +4395 -1266
  134. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  135. package/dist/types/SwcAppEngine.d.ts +1 -0
  136. package/dist/types/SwcAppEngine.d.ts.map +1 -1
  137. package/dist/types/decorators/addEventListener.d.ts +936 -11
  138. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  139. package/dist/types/decorators/applyAttribute.d.ts +27 -37
  140. package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
  141. package/dist/types/decorators/applyClass.d.ts +2 -2
  142. package/dist/types/decorators/applyClass.d.ts.map +1 -1
  143. package/dist/types/decorators/applyNode.d.ts +16 -16
  144. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  145. package/dist/types/decorators/applyProperty.d.ts +28 -44
  146. package/dist/types/decorators/applyProperty.d.ts.map +1 -1
  147. package/dist/types/decorators/applySlot.d.ts.map +1 -1
  148. package/dist/types/decorators/applyStyle.d.ts +2 -2
  149. package/dist/types/decorators/applyStyle.d.ts.map +1 -1
  150. package/dist/types/decorators/around.d.ts +87 -0
  151. package/dist/types/decorators/around.d.ts.map +1 -0
  152. package/dist/types/decorators/changedAttribute.d.ts +22 -4
  153. package/dist/types/decorators/changedAttribute.d.ts.map +1 -1
  154. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  155. package/dist/types/decorators/emitCustomEvent.d.ts +0 -1
  156. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  157. package/dist/types/decorators/eventMedia.d.ts +48 -0
  158. package/dist/types/decorators/eventMedia.d.ts.map +1 -0
  159. package/dist/types/decorators/fetch.d.ts +139 -0
  160. package/dist/types/decorators/fetch.d.ts.map +1 -0
  161. package/dist/types/decorators/index.d.ts +8 -2
  162. package/dist/types/decorators/index.d.ts.map +1 -1
  163. package/dist/types/decorators/intersectionObserver.d.ts +32 -10
  164. package/dist/types/decorators/intersectionObserver.d.ts.map +1 -1
  165. package/dist/types/decorators/lifecycles.d.ts +8 -7
  166. package/dist/types/decorators/lifecycles.d.ts.map +1 -1
  167. package/dist/types/decorators/mutationObserver.d.ts +34 -12
  168. package/dist/types/decorators/mutationObserver.d.ts.map +1 -1
  169. package/dist/types/decorators/parameter.d.ts +113 -0
  170. package/dist/types/decorators/parameter.d.ts.map +1 -0
  171. package/dist/types/decorators/publishSwcAppMessage.d.ts +0 -1
  172. package/dist/types/decorators/publishSwcAppMessage.d.ts.map +1 -1
  173. package/dist/types/decorators/query.d.ts +7 -7
  174. package/dist/types/decorators/query.d.ts.map +1 -1
  175. package/dist/types/decorators/requestAnimationFrame.d.ts +47 -0
  176. package/dist/types/decorators/requestAnimationFrame.d.ts.map +1 -0
  177. package/dist/types/decorators/resizeObserver.d.ts +34 -12
  178. package/dist/types/decorators/resizeObserver.d.ts.map +1 -1
  179. package/dist/types/decorators/setInterval.d.ts +27 -5
  180. package/dist/types/decorators/setInterval.d.ts.map +1 -1
  181. package/dist/types/decorators/setTimeout.d.ts +27 -5
  182. package/dist/types/decorators/setTimeout.d.ts.map +1 -1
  183. package/dist/types/decorators/state.d.ts.map +1 -1
  184. package/dist/types/decorators/subscribeSwcAppMessage.d.ts +44 -0
  185. package/dist/types/decorators/subscribeSwcAppMessage.d.ts.map +1 -0
  186. package/dist/types/decorators/subscribeSwcAppRouteChange.d.ts +60 -0
  187. package/dist/types/decorators/subscribeSwcAppRouteChange.d.ts.map +1 -0
  188. package/dist/types/decorators/swcAppRoute.d.ts +94 -0
  189. package/dist/types/decorators/swcAppRoute.d.ts.map +1 -0
  190. package/dist/types/elements/SwcApp.d.ts.map +1 -1
  191. package/dist/types/elements/SwcAppMixin.d.ts +423 -388
  192. package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
  193. package/dist/types/types/index.d.ts +43 -4
  194. package/dist/types/types/index.d.ts.map +1 -1
  195. package/dist/types/utils/Utils.d.ts +15 -5
  196. package/dist/types/utils/Utils.d.ts.map +1 -1
  197. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +4395 -1266
  198. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  199. package/package.json +8 -6
  200. package/src/SwcAppEngine.ts +1 -0
  201. package/src/decorators/addEventListener.ts +1086 -28
  202. package/src/decorators/applyAttribute.ts +82 -134
  203. package/src/decorators/applyClass.ts +14 -10
  204. package/src/decorators/applyNode.ts +39 -37
  205. package/src/decorators/applyProperty.ts +72 -100
  206. package/src/decorators/applySlot.ts +9 -8
  207. package/src/decorators/applyStyle.ts +14 -10
  208. package/src/decorators/around.ts +196 -0
  209. package/src/decorators/changedAttribute.ts +65 -26
  210. package/src/decorators/elementDefine.ts +298 -220
  211. package/src/decorators/emitCustomEvent.ts +17 -13
  212. package/src/decorators/eventMedia.ts +119 -0
  213. package/src/decorators/fetch.ts +454 -0
  214. package/src/decorators/index.ts +8 -2
  215. package/src/decorators/intersectionObserver.ts +108 -78
  216. package/src/decorators/lifecycles.ts +24 -22
  217. package/src/decorators/mutationObserver.ts +140 -104
  218. package/src/decorators/parameter.ts +212 -0
  219. package/src/decorators/publishSwcAppMessage.ts +3 -4
  220. package/src/decorators/query.ts +22 -14
  221. package/src/decorators/requestAnimationFrame.ts +149 -0
  222. package/src/decorators/resizeObserver.ts +119 -82
  223. package/src/decorators/setInterval.ts +90 -23
  224. package/src/decorators/setTimeout.ts +93 -23
  225. package/src/decorators/state.ts +19 -13
  226. package/src/decorators/subscribeSwcAppMessage.ts +106 -0
  227. package/src/decorators/subscribeSwcAppRouteChange.ts +131 -0
  228. package/src/decorators/swcAppRoute.ts +231 -0
  229. package/src/elements/SwcApp.ts +40 -10
  230. package/src/elements/SwcAppMixin.ts +329 -85
  231. package/src/types/index.ts +38 -5
  232. package/src/types/window.d.ts +2 -18
  233. package/src/utils/Utils.ts +50 -18
  234. package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +0 -7
  235. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +0 -7
  236. package/dist/cjs/examples/RxJSOperatorsExample.js +0 -285
  237. package/dist/cjs/examples/RxJSOperatorsExample.js.map +0 -7
  238. package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +0 -54
  239. package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +0 -7
  240. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +0 -7
  241. package/dist/esm/examples/RxJSOperatorsExample.js +0 -266
  242. package/dist/esm/examples/RxJSOperatorsExample.js.map +0 -7
  243. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +0 -23
  244. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +0 -1
  245. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +0 -31
  246. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +0 -1
  247. package/dist/types/examples/RxJSOperatorsExample.d.ts +0 -94
  248. package/dist/types/examples/RxJSOperatorsExample.d.ts.map +0 -1
  249. package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +0 -91
  250. package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +0 -107
  251. package/src/examples/RxJSOperatorsExample.ts +0 -279
@@ -11,18 +11,23 @@ import { getQueryMetadata, getQueryAllMetadata } from "./query.js";
11
11
  import { SwcUtils } from "../utils/Utils.js";
12
12
  import { DOM_EVENT_NAMES, HTML_TAG_ENTRIES } from "../config/config.js";
13
13
  import { SituationTypeContainer, SituationTypeContainers } from "@dooboostore/simple-boot/decorators/inject/Inject";
14
+ import { buildSwcParameterArgs, getParameterMetadata } from "./parameter.js";
14
15
  import { InjectSituationType } from "../types/index.js";
15
16
  import { ConvertUtils, ElementApply } from "@dooboostore/core-web";
16
17
  import { isSSR } from "../elements/SwcAppMixin.js";
17
18
  import { findAllStateMetadata } from "./state.js";
19
+ import { findAllAroundMetadata } from "./around.js";
18
20
  import { findAllPropertyMetadata } from "./applyProperty.js";
19
- import { MessageSubscribeLifeCycler } from "./subscribeSwcAppMessageWhileConnected.js";
20
- import { RouteSubscribeLifeCycler } from "./subscribeSwcAppRouteChangeWhileConnected.js";
21
+ import { MessageSubscribeLifeCycler } from "./subscribeSwcAppMessage.js";
22
+ import { RouteSubscribeLifeCycler } from "./subscribeSwcAppRouteChange.js";
21
23
  import { SetIntervalLifeCycler } from "./setInterval.js";
22
24
  import { SetTimeoutLifeCycler } from "./setTimeout.js";
25
+ import { RequestAnimationFrameLifeCycler } from "./requestAnimationFrame.js";
26
+ import { EventMediaLifeCycler } from "./eventMedia.js";
27
+ import { FetchLifeCycler } from "./fetch.js";
23
28
  const ELEMENT_CONFIG_KEY = Symbol.for("simple-web-component:element-config");
24
29
  const getElementConfig = (target) => {
25
- const constructor = target instanceof Function ? target : target.constructor;
30
+ const constructor = typeof target === "function" ? target : target.constructor;
26
31
  return ReflectUtils.getMetadata(ELEMENT_CONFIG_KEY, constructor);
27
32
  };
28
33
  const ensureInit = (inst) => {
@@ -30,7 +35,7 @@ const ensureInit = (inst) => {
30
35
  inst._swcId = inst?.getAttribute?.("swc-use-ssr") ?? "s" + Math.random().toString(36).substring(2, 11).toLowerCase();
31
36
  inst._emitHandlers = /* @__PURE__ */ new Map();
32
37
  inst.__swc_initialized = true;
33
- const target = inst instanceof Function ? inst : inst.constructor;
38
+ const target = typeof inst === "function" ? inst : inst.constructor;
34
39
  const attributeAllList = findAllAttributeMetadata(target).filter((it) => it.type === "property");
35
40
  if (attributeAllList) {
36
41
  attributeAllList.forEach((meta) => {
@@ -52,15 +57,40 @@ const ensureInit = (inst) => {
52
57
  const propertyAllList = findAllPropertyMetadata(target).filter((it) => it.type === "property");
53
58
  if (propertyAllList) {
54
59
  propertyAllList.forEach((meta) => {
60
+ let proto = Object.getPrototypeOf(inst);
61
+ let hasGetter = false;
62
+ while (proto && proto !== Object.prototype) {
63
+ const d = Object.getOwnPropertyDescriptor(proto, meta.propertyKey);
64
+ if (d) {
65
+ hasGetter = typeof d.get === "function";
66
+ break;
67
+ }
68
+ proto = Object.getPrototypeOf(proto);
69
+ }
70
+ if (!hasGetter) return;
55
71
  delete inst[meta.propertyKey];
56
72
  });
57
73
  }
58
74
  const stateAllList = findAllStateMetadata(target);
59
75
  if (stateAllList) {
60
76
  stateAllList.forEach((meta) => {
61
- const initUserData = inst[meta.propertyKey];
62
- delete inst[meta.propertyKey];
63
- inst[meta.propertyKey] = initUserData;
77
+ const own = Object.getOwnPropertyDescriptor(inst, meta.propertyKey);
78
+ if (own && "value" in own) {
79
+ const initUserData = own.value;
80
+ delete inst[meta.propertyKey];
81
+ inst[meta.propertyKey] = initUserData;
82
+ }
83
+ });
84
+ }
85
+ const aroundAllList = findAllAroundMetadata(target);
86
+ if (aroundAllList) {
87
+ aroundAllList.forEach((meta) => {
88
+ const own = Object.getOwnPropertyDescriptor(inst, meta.propertyKey);
89
+ if (own && "value" in own) {
90
+ const initUserData = own.value;
91
+ delete inst[meta.propertyKey];
92
+ inst[meta.propertyKey] = initUserData;
93
+ }
64
94
  });
65
95
  }
66
96
  const hostSet = SwcUtils.getHostSet(inst);
@@ -80,7 +110,7 @@ const handleGlobalSwcEvent = async (event) => {
80
110
  if (!(node instanceof HTMLElement)) continue;
81
111
  const script = node.getAttribute?.(attrName);
82
112
  if (script && !getElementConfig(node)) {
83
- const host = SwcUtils.findNearestSwcHostIncludingSelf(node);
113
+ const host = SwcUtils.findNearestSwcAncestorHost(node);
84
114
  if (host && host.isConnected && typeof host.__swc_executeAttributeEvent === "function") {
85
115
  await host.__swc_executeAttributeEvent(node, attrName, script, event);
86
116
  event.__swc_handled = true;
@@ -111,8 +141,7 @@ const setupPrototype = (proto, win) => {
111
141
  const script = this.getAttribute(attrName);
112
142
  if (script) {
113
143
  try {
114
- const conf = getElementConfig(this);
115
- const currentWin = this._resolveWindow(conf);
144
+ const currentWin = SwcUtils.resolveWindow(this);
116
145
  const helpers = SwcUtils.getHelperSet(currentWin);
117
146
  const args = { ...hostSet, ...helpers, ...extraArgs, $el: this, $root: this.getRootNode() };
118
147
  FunctionUtils.execute({ script, context: this, args });
@@ -121,21 +150,14 @@ const setupPrototype = (proto, win) => {
121
150
  }
122
151
  }
123
152
  };
124
- proto._resolveWindow = function(localConfig) {
125
- ensureInit(this);
126
- if (localConfig?.window) return localConfig.window;
127
- const ancestors = SwcUtils.findAllSwcHostsIncludingSelf(this);
128
- for (let i = ancestors.length - 1; i >= 0; i--) {
129
- const aConf = getElementConfig(ancestors[i]);
130
- if (aConf?.window) return aConf.window;
131
- }
132
- return getElementConfig(this).window ?? (typeof window !== "undefined" ? window : void 0);
133
- };
134
153
  proto._invokeLifecycleMethod = function(methodName, hostSet, extraArgs = []) {
135
154
  ensureInit(this);
136
155
  if (typeof this[methodName] !== "function") return;
137
- const useHostSet = hostSet ?? SwcUtils.getHelperAndHostSet(win, this);
156
+ const useHostSet = hostSet ?? SwcUtils.getHelperAndHostSet(this);
138
157
  const app = useHostSet?.$appHost?.simpleApplication;
158
+ const helperSetValue = SwcUtils.getHelperSet(win);
159
+ const helperHostSetValue = { ...helperSetValue, ...useHostSet, $this: this };
160
+ const kindValues = { hostSet: useHostSet, helperHostSet: helperHostSetValue, helperSet: helperSetValue };
139
161
  if (app) {
140
162
  const otherStorage = /* @__PURE__ */ new Map();
141
163
  const situations = new SituationTypeContainers([new SituationTypeContainer({ situationType: InjectSituationType.HOST_SET, data: useHostSet }), new SituationTypeContainer({ situationType: InjectSituationType.APP_HOST, data: useHostSet.$appHost }), new SituationTypeContainer({ situationType: InjectSituationType.APP_HOSTS, data: useHostSet.$appHosts }), new SituationTypeContainer({
@@ -146,16 +168,23 @@ const setupPrototype = (proto, win) => {
146
168
  data: useHostSet.$firstAppHost
147
169
  }), new SituationTypeContainer({ situationType: InjectSituationType.LAST_APP_HOST, data: useHostSet.$lastAppHost })]);
148
170
  otherStorage.set(SituationTypeContainers, situations);
171
+ const firstCheckMaker = ({ target, targetKey }, token, idx) => {
172
+ const saves = getParameterMetadata(target, targetKey);
173
+ const found = saves.find((s) => s.index === idx);
174
+ return found ? kindValues[found.kind] ?? null : void 0;
175
+ };
149
176
  return app.simstanceManager.executeBindParameterSim(
150
177
  {
151
178
  target: this,
152
179
  targetKey: methodName,
153
- inputParameters: extraArgs
180
+ inputParameters: extraArgs,
181
+ firstCheckMaker: [firstCheckMaker]
154
182
  },
155
183
  otherStorage
156
184
  );
157
185
  } else {
158
- return this[methodName](...extraArgs);
186
+ const args = buildSwcParameterArgs(this, methodName, kindValues, extraArgs);
187
+ return this[methodName](...args);
159
188
  }
160
189
  };
161
190
  proto._bindAttributeEvent = function(el, attrName, script, eventName) {
@@ -174,8 +203,7 @@ const setupPrototype = (proto, win) => {
174
203
  if (oldHandler) el.removeEventListener(eventName, oldHandler);
175
204
  const handler = async (event) => {
176
205
  const hostSet = SwcUtils.getHostSet(el);
177
- const conf = getElementConfig(this);
178
- const currentWin = this._resolveWindow(conf);
206
+ const currentWin = SwcUtils.resolveWindow(this);
179
207
  const helpers = SwcUtils.getHelperSet(currentWin);
180
208
  const args = {
181
209
  event,
@@ -193,8 +221,7 @@ const setupPrototype = (proto, win) => {
193
221
  proto.__swc_executeAttributeEvent = async function(el, attrName, script, event) {
194
222
  ensureInit(this);
195
223
  const hostSet = SwcUtils.getHostSet(el);
196
- const conf = getElementConfig(this);
197
- const currentWin = this._resolveWindow(conf);
224
+ const currentWin = SwcUtils.resolveWindow(this);
198
225
  const currentHelpers = SwcUtils.getHelperSet(currentWin);
199
226
  const detail = event.detail;
200
227
  const args = {
@@ -210,6 +237,8 @@ const setupPrototype = (proto, win) => {
210
237
  await FunctionUtils.execute({ script, context: el, args });
211
238
  };
212
239
  };
240
+ const SWC_ORIGINAL_CALLBACK = Symbol.for("simple-web-component:original-callback");
241
+ const userCallback = (fn) => typeof fn === "function" && SWC_ORIGINAL_CALLBACK in fn ? fn[SWC_ORIGINAL_CALLBACK] : fn;
213
242
  const elementDefine = (name, config = {}) => (constructor) => {
214
243
  const { win, doc, builtInTagMap: BUILT_IN_TAG_MAP, domHelpers: SWC_DOM_HELPERS } = buildEnv(config.window);
215
244
  const metadata = { ...config, name, window: win };
@@ -236,28 +265,60 @@ const elementDefine = (name, config = {}) => (constructor) => {
236
265
  const originalStaticObservedAttributes = constructor.observedAttributes ?? [];
237
266
  const proto = constructor.prototype;
238
267
  setupPrototype(proto, win);
239
- let helperHostSet = null;
268
+ const connectedHelperHostSet = (inst) => inst.__swc_helperHostSet ?? SwcUtils.getHelperAndHostSet(inst);
240
269
  const eventCycler = new EventListenerLifeCycler();
270
+ const resizeCycler = new ResizeObserverLifeCycler();
271
+ const intersectionCycler = new IntersectionObserverLifeCycler();
272
+ const mutationCycler = new MutationObserverLifeCycler();
241
273
  const cyclers = [
242
274
  eventCycler,
243
275
  new ChangedAttributeLifeCycler(),
244
276
  new EmitCustomEventLifeCycler(),
245
- new ResizeObserverLifeCycler(),
246
- new IntersectionObserverLifeCycler(),
247
- new MutationObserverLifeCycler(),
277
+ resizeCycler,
278
+ intersectionCycler,
279
+ mutationCycler,
248
280
  new MessageSubscribeLifeCycler(),
249
281
  new RouteSubscribeLifeCycler(),
250
282
  new SetIntervalLifeCycler(),
251
- new SetTimeoutLifeCycler()
283
+ new SetTimeoutLifeCycler(),
284
+ new RequestAnimationFrameLifeCycler(),
285
+ new EventMediaLifeCycler(),
286
+ new FetchLifeCycler()
252
287
  ];
253
288
  const cyclerObservedAttributes = cyclers.flatMap((c) => c.getObservedAttributeNames?.(constructor) ?? []);
254
289
  const mergedObservedAttributes = [.../* @__PURE__ */ new Set([...metadata.observedAttributes ?? [], ...originalStaticObservedAttributes, ...cyclerObservedAttributes, ...attributeApplyNames, ...hostAttributes, ...swcLifecycleAttributes, ...swcOnEvents])];
255
- const buildObservers = async (helperHostSet2) => {
256
- const inst = helperHostSet2.$this;
257
- const observers = [];
258
- let resizeObserverSet = [];
259
- let mutationObserverSet = [];
260
- let intersectionObserverSet = [];
290
+ const newObserverState = () => ({
291
+ observers: [],
292
+ roCallbacks: /* @__PURE__ */ new Set(),
293
+ roObserved: /* @__PURE__ */ new WeakSet(),
294
+ resizeDelegates: [],
295
+ intersectionDelegates: [],
296
+ moCallbacks: /* @__PURE__ */ new Set(),
297
+ moTargets: /* @__PURE__ */ new Map()
298
+ });
299
+ const mergeMutationInit = (existing, next) => {
300
+ if (!existing) return next;
301
+ const mergedFilter = existing.attributeFilter || next.attributeFilter ? [.../* @__PURE__ */ new Set([...existing.attributeFilter ?? [], ...next.attributeFilter ?? []])] : void 0;
302
+ return {
303
+ childList: existing.childList || next.childList,
304
+ attributes: existing.attributes || next.attributes,
305
+ characterData: existing.characterData || next.characterData,
306
+ subtree: existing.subtree || next.subtree,
307
+ attributeOldValue: existing.attributeOldValue || next.attributeOldValue,
308
+ characterDataOldValue: existing.characterDataOldValue || next.characterDataOldValue,
309
+ attributeFilter: mergedFilter
310
+ };
311
+ };
312
+ const forDelegateMatches = (n, selector, fn) => {
313
+ if (n.nodeType !== 1) return;
314
+ const el = n;
315
+ const isThis = selector === "$this" || selector === "";
316
+ if (isThis || el.matches?.(selector) || el.closest?.(selector)) fn(el);
317
+ else el.querySelectorAll(selector).forEach(fn);
318
+ };
319
+ const buildObservers = async (helperHostSet, scope, st, alive) => {
320
+ const inst = helperHostSet.$this;
321
+ const activeCyclers = scope === "self" ? [resizeCycler, mutationCycler] : cyclers;
261
322
  const resolveDelegateRoots = (delegateRoot) => {
262
323
  const r = delegateRoot || "auto";
263
324
  const roots = [];
@@ -270,202 +331,139 @@ const elementDefine = (name, config = {}) => (constructor) => {
270
331
  }
271
332
  return roots;
272
333
  };
273
- for (const c of cyclers) {
274
- const result = await c.onConnected?.(helperHostSet2, resizeObserverSet);
334
+ let resizeObserverSet = [];
335
+ let mutationObserverSet = [];
336
+ let intersectionObserverSet = [];
337
+ for (const c of activeCyclers) {
338
+ const result = await c.onConnected?.(helperHostSet, resizeObserverSet, scope);
339
+ if (!alive()) return;
275
340
  if (!result) continue;
276
341
  if (result.resizeObserverSet?.length) resizeObserverSet = [...resizeObserverSet, ...result.resizeObserverSet];
277
342
  if (result.mutationObserverSet?.length) mutationObserverSet = [...mutationObserverSet, ...result.mutationObserverSet];
278
343
  if (result.intersectionObserverSet?.length) intersectionObserverSet = [...intersectionObserverSet, ...result.intersectionObserverSet];
279
344
  }
280
- const resizeDelegates = (resizeObserverSet ?? []).filter((t) => t.delegate && typeof t.target === "string");
281
- let resizeObserve;
282
- let resizeUnobserve;
283
- const resizeObserved = /* @__PURE__ */ new WeakSet();
284
- if (resizeObserverSet?.length) {
285
- const roCallbacks = [...new Set(resizeObserverSet.map((e) => e.callback))];
286
- const ro = new win.ResizeObserver((entries, obs) => {
287
- for (const cb of roCallbacks) cb(entries, obs);
288
- });
345
+ const resizeObserve = (el, opts) => {
346
+ if (!st.ro || st.roObserved.has(el)) return;
347
+ st.ro.observe(el, opts);
348
+ st.roObserved.add(el);
349
+ };
350
+ const resizeUnobserve = (el) => {
351
+ if (!st.ro || !st.roObserved.has(el)) return;
352
+ st.ro.unobserve(el);
353
+ st.roObserved.delete(el);
354
+ };
355
+ const newResizeDelegates = [];
356
+ if (resizeObserverSet.length) {
357
+ if (!st.ro) {
358
+ st.ro = new win.ResizeObserver((entries, obs) => {
359
+ for (const cb of st.roCallbacks) cb(entries, obs);
360
+ });
361
+ st.observers.push(st.ro);
362
+ }
289
363
  for (const e of resizeObserverSet) {
290
- if (e.delegate) continue;
364
+ st.roCallbacks.add(e.callback);
365
+ if (e.delegate) {
366
+ if (typeof e.target === "string") newResizeDelegates.push(e);
367
+ continue;
368
+ }
291
369
  if (typeof e.target === "string") {
292
- const scope = resolveDelegateRoots(e.delegateRoot);
293
- for (const sr of scope) {
294
- sr.querySelectorAll(e.target).forEach((el) => {
295
- if (!resizeObserved.has(el)) {
296
- ro.observe(el, e.options);
297
- resizeObserved.add(el);
298
- }
299
- });
300
- }
370
+ for (const r of resolveDelegateRoots(e.delegateRoot)) r.querySelectorAll(e.target).forEach((el) => resizeObserve(el, e.options));
301
371
  continue;
302
372
  }
303
- ro.observe(e.target, e.options);
304
- if (e.target instanceof Element) resizeObserved.add(e.target);
373
+ st.ro.observe(e.target, e.options);
374
+ if (e.target instanceof Element) st.roObserved.add(e.target);
305
375
  }
306
- resizeObserve = (el, opts) => {
307
- if (resizeObserved.has(el)) return;
308
- ro.observe(el, opts);
309
- resizeObserved.add(el);
310
- };
311
- resizeUnobserve = (el) => {
312
- if (!resizeObserved.has(el)) return;
313
- ro.unobserve(el);
314
- resizeObserved.delete(el);
315
- };
316
- observers.push(ro);
376
+ st.resizeDelegates.push(...newResizeDelegates);
317
377
  }
318
- const intersectionDelegates = [];
378
+ const newIntersectionDelegates = [];
319
379
  for (const group of intersectionObserverSet) {
320
380
  const ioCallbacks = [...new Set(group.observeTargets.map((e) => e.callback))];
321
381
  const io = new win.IntersectionObserver((entries, obs) => {
322
382
  for (const cb of ioCallbacks) cb(entries, obs);
323
383
  }, group.options);
324
384
  const ioObserved = /* @__PURE__ */ new WeakSet();
385
+ const observe = (el) => {
386
+ if (ioObserved.has(el)) return;
387
+ io.observe(el);
388
+ ioObserved.add(el);
389
+ };
390
+ const unobserve = (el) => {
391
+ if (!ioObserved.has(el)) return;
392
+ io.unobserve(el);
393
+ ioObserved.delete(el);
394
+ };
325
395
  for (const e of group.observeTargets) {
326
396
  if (e.delegate) {
327
- const target = e.target;
328
- const observe = (el) => {
329
- if (ioObserved.has(el)) return;
330
- io.observe(el);
331
- ioObserved.add(el);
332
- };
333
- const unobserve = (el) => {
334
- if (!ioObserved.has(el)) return;
335
- io.unobserve(el);
336
- ioObserved.delete(el);
337
- };
338
- intersectionDelegates.push({ target, delegateRoot: e.delegateRoot, observe, unobserve });
397
+ newIntersectionDelegates.push({ target: e.target, delegateRoot: e.delegateRoot, observe, unobserve });
339
398
  continue;
340
399
  }
341
400
  if (typeof e.target === "string") {
342
- const scope = resolveDelegateRoots(e.delegateRoot);
343
- for (const sr of scope) {
344
- sr.querySelectorAll(e.target).forEach((el) => {
345
- if (!ioObserved.has(el)) {
346
- io.observe(el);
347
- ioObserved.add(el);
348
- }
349
- });
350
- }
401
+ for (const r of resolveDelegateRoots(e.delegateRoot)) r.querySelectorAll(e.target).forEach(observe);
351
402
  continue;
352
403
  }
353
- io.observe(e.target);
354
- if (e.target instanceof Element) ioObserved.add(e.target);
404
+ observe(e.target);
355
405
  }
356
- observers.push(io);
406
+ st.observers.push(io);
357
407
  }
358
- const handleResizeDelegate = (n, observe) => {
359
- if (!resizeObserve || !resizeUnobserve || n.nodeType !== 1) return;
360
- const el = n;
361
- for (const d of resizeDelegates) {
362
- const isThis = d.target === "$this" || d.target === "";
363
- const matchesSel = (node) => {
364
- if (!node || node.nodeType !== 1) return false;
365
- if (isThis) return true;
366
- return node.matches?.(d.target) || !!node.closest?.(d.target);
367
- };
368
- if (matchesSel(el)) {
369
- observe ? resizeObserve(el, d.options) : resizeUnobserve(el);
370
- } else if (!isThis) {
371
- el.querySelectorAll(d.target).forEach((sub) => {
372
- observe ? resizeObserve(sub, d.options) : resizeUnobserve(sub);
373
- });
374
- }
375
- }
376
- };
377
- const handleIntersectionDelegate = (n, observe) => {
378
- if (n.nodeType !== 1) return;
379
- const el = n;
380
- for (const d of intersectionDelegates) {
381
- const isThis = d.target === "$this" || d.target === "";
382
- const matchesSel = (node) => {
383
- if (!node || node.nodeType !== 1) return false;
384
- if (isThis) return true;
385
- return node.matches?.(d.target) || !!node.closest?.(d.target);
386
- };
387
- if (matchesSel(el)) {
388
- observe ? d.observe(el) : d.unobserve(el);
389
- } else if (!isThis) {
390
- el.querySelectorAll(d.target).forEach((sub) => {
391
- observe ? d.observe(sub) : d.unobserve(sub);
392
- });
393
- }
408
+ st.intersectionDelegates.push(...newIntersectionDelegates);
409
+ if (mutationObserverSet.length || newResizeDelegates.length || newIntersectionDelegates.length) {
410
+ if (!st.mo) {
411
+ st.mo = new win.MutationObserver((mutations, obs) => {
412
+ for (const mut of mutations) {
413
+ for (const [nodes, on] of [[mut.addedNodes, true], [mut.removedNodes, false]]) {
414
+ for (const n of Array.from(nodes)) {
415
+ for (const d of st.resizeDelegates) forDelegateMatches(n, d.target, (el) => on ? resizeObserve(el, d.options) : resizeUnobserve(el));
416
+ for (const d of st.intersectionDelegates) forDelegateMatches(n, d.target, (el) => on ? d.observe(el) : d.unobserve(el));
417
+ }
418
+ }
419
+ }
420
+ for (const cb of st.moCallbacks) cb(mutations, obs);
421
+ });
422
+ st.observers.push(st.mo);
394
423
  }
395
- };
396
- if (mutationObserverSet?.length || resizeDelegates.length > 0 || intersectionDelegates.length > 0) {
397
- const callbacks = [...new Set((mutationObserverSet ?? []).map((e) => e.callback))];
398
- const mo = new win.MutationObserver((mutations, obs) => {
399
- for (const mut of mutations) {
400
- Array.from(mut.addedNodes || []).forEach((n) => {
401
- handleResizeDelegate(n, true);
402
- handleIntersectionDelegate(n, true);
403
- });
404
- Array.from(mut.removedNodes || []).forEach((n) => {
405
- handleResizeDelegate(n, false);
406
- handleIntersectionDelegate(n, false);
407
- });
408
- }
409
- for (const cb of callbacks) cb(mutations, obs);
410
- });
411
- const moObserveTargets = /* @__PURE__ */ new Map();
412
- const mergeMutationInit = (existing, next) => {
413
- if (!existing) return next;
414
- const mergedFilter = existing.attributeFilter || next.attributeFilter ? [.../* @__PURE__ */ new Set([...existing.attributeFilter ?? [], ...next.attributeFilter ?? []])] : void 0;
415
- return {
416
- childList: existing.childList || next.childList,
417
- attributes: existing.attributes || next.attributes,
418
- characterData: existing.characterData || next.characterData,
419
- subtree: existing.subtree || next.subtree,
420
- attributeOldValue: existing.attributeOldValue || next.attributeOldValue,
421
- characterDataOldValue: existing.characterDataOldValue || next.characterDataOldValue,
422
- attributeFilter: mergedFilter
423
- };
424
- };
425
424
  const addObserveTarget = (target, options) => {
426
- moObserveTargets.set(target, mergeMutationInit(moObserveTargets.get(target), options));
425
+ st.moTargets.set(target, mergeMutationInit(st.moTargets.get(target), options));
427
426
  };
428
- for (const e of mutationObserverSet ?? []) {
427
+ for (const e of mutationObserverSet) {
428
+ st.moCallbacks.add(e.callback);
429
429
  if (e.delegate) continue;
430
430
  const init = e.options ?? { childList: true };
431
431
  if (typeof e.target === "string") {
432
- const scope = resolveDelegateRoots(e.delegateRoot);
433
- for (const sr of scope) {
434
- sr.querySelectorAll(e.target).forEach((el) => addObserveTarget(el, init));
435
- }
432
+ for (const r of resolveDelegateRoots(e.delegateRoot)) r.querySelectorAll(e.target).forEach((el) => addObserveTarget(el, init));
436
433
  continue;
437
434
  }
438
435
  addObserveTarget(e.target, init);
439
436
  }
440
- for (const d of resizeDelegates) {
437
+ for (const d of [...newResizeDelegates, ...newIntersectionDelegates]) {
441
438
  for (const r of resolveDelegateRoots(d.delegateRoot)) addObserveTarget(r, { childList: true, subtree: true });
442
439
  }
443
- for (const d of intersectionDelegates) {
444
- for (const r of resolveDelegateRoots(d.delegateRoot)) addObserveTarget(r, { childList: true, subtree: true });
445
- }
446
- for (const [target, options] of moObserveTargets) {
447
- mo.observe(target, options);
448
- }
449
- observers.push(mo);
440
+ for (const [target, options] of st.moTargets) st.mo.observe(target, options);
450
441
  }
451
- inst.__swc_observers = observers;
442
+ inst.__swc_observers = st.observers;
452
443
  };
453
- const originalConnected = proto.connectedCallback;
444
+ const originalConnected = userCallback(proto.connectedCallback);
454
445
  proto.connectedCallback = async function() {
455
446
  ensureInit(this);
456
- helperHostSet = SwcUtils.getHelperAndHostSet(win, this);
447
+ const helperHostSet = SwcUtils.getHelperAndHostSet(this);
448
+ this.__swc_helperHostSet = helperHostSet;
457
449
  const appHost = helperHostSet.$appHost;
458
450
  const useSsr = isSSR(this);
451
+ const gen = this.__swc_connectGen = (this.__swc_connectGen ?? 0) + 1;
452
+ const alive = () => this.__swc_connectGen === gen;
453
+ const obsState = newObserverState();
459
454
  try {
460
455
  if (appHost && typeof appHost._connected === "function") {
461
456
  await appHost._connected(this);
457
+ if (!alive()) return;
462
458
  } else if (appHost && typeof appHost) {
463
459
  appHost._connected_safari_and_standby ?? (appHost._connected_safari_and_standby = []);
464
460
  appHost._connected_safari_and_standby.push(this);
465
461
  }
466
462
  const conf = getElementConfig(this);
467
- const currentWin = this._resolveWindow(conf);
468
- for (const m of findAllOnConnectedBeforeMetadata(this)) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
463
+ for (const m of findAllOnConnectedBeforeMetadata(this)) {
464
+ await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
465
+ if (!alive()) return;
466
+ }
469
467
  this._executeSwcScript("swc-on-before-connected", helperHostSet);
470
468
  const targetConnectedList = useSsr ? [] : findAllOnConnectedMetadata(constructor);
471
469
  const shadowMode = conf?.useShadow || targetConnectedList.find((it) => it.options.useShadow)?.options.useShadow;
@@ -473,6 +471,8 @@ const elementDefine = (name, config = {}) => (constructor) => {
473
471
  const mode = shadowMode === true ? "open" : shadowMode;
474
472
  this.attachShadow({ mode });
475
473
  }
474
+ await buildObservers(helperHostSet, "self", obsState, alive);
475
+ if (!alive()) return;
476
476
  const stateContext = { ...helperHostSet };
477
477
  findAllStateMetadata(this).forEach((it) => {
478
478
  stateContext[it.name] = this[it.propertyKey];
@@ -480,8 +480,39 @@ const elementDefine = (name, config = {}) => (constructor) => {
480
480
  const shadowChildren = [];
481
481
  const lightChildren = [];
482
482
  if (targetConnectedList.length > 0) {
483
+ const toNodes = (value) => {
484
+ if (!value) return [];
485
+ if (typeof value === "string") {
486
+ const htmlTemplateElement = doc.createElement("template");
487
+ htmlTemplateElement.innerHTML = value;
488
+ return Array.from(htmlTemplateElement.content.childNodes);
489
+ }
490
+ if (Array.isArray(value)) return value;
491
+ return [value];
492
+ };
493
+ const shownFallbacks = [];
494
+ const removeFallbacks = () => shownFallbacks.splice(0).forEach((n) => n.remove());
483
495
  for (const meta of targetConnectedList) {
496
+ const useShadowRoot = meta.options.useShadow || conf?.useShadow;
497
+ if (meta.options.fallback) {
498
+ const fb = typeof meta.options.fallback === "function" ? meta.options.fallback(helperHostSet) : meta.options.fallback;
499
+ const fallbackNodes = toNodes(fb);
500
+ const parent = useShadowRoot ? this.shadowRoot : this;
501
+ if (fallbackNodes.length && parent) {
502
+ try {
503
+ const processed = SwcUtils.projectProcessHtml(this._swcId, fallbackNodes, doc);
504
+ parent.append(...processed);
505
+ shownFallbacks.push(...processed);
506
+ } catch (e) {
507
+ console.error("[ElementDefine] fallback setting error:", e);
508
+ }
509
+ }
510
+ }
484
511
  let res = await this._invokeLifecycleMethod(meta.propertyKey, helperHostSet);
512
+ if (!alive()) {
513
+ removeFallbacks();
514
+ return;
515
+ }
485
516
  if (typeof res === "string") {
486
517
  const htmlTemplateElement = doc.createElement("template");
487
518
  htmlTemplateElement.innerHTML = res;
@@ -496,6 +527,7 @@ const elementDefine = (name, config = {}) => (constructor) => {
496
527
  }
497
528
  }
498
529
  }
530
+ removeFallbacks();
499
531
  try {
500
532
  if (this.shadowRoot) {
501
533
  const applyShadowChildren = SwcUtils.projectProcessHtml(this._swcId, shadowChildren, doc);
@@ -519,22 +551,30 @@ const elementDefine = (name, config = {}) => (constructor) => {
519
551
  });
520
552
  globalDelegatedRoots.add(root);
521
553
  }
522
- await buildObservers(SwcUtils.getHelperAndHostSet(win, this));
554
+ await buildObservers(helperHostSet, "rest", obsState, alive);
555
+ if (!alive()) return;
523
556
  if (originalConnected) await originalConnected.apply(this);
524
- for (const m of findAllOnConnectedAfterMetadata(this)) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
557
+ if (!alive()) return;
558
+ for (const m of findAllOnConnectedAfterMetadata(this)) {
559
+ await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
560
+ if (!alive()) return;
561
+ }
525
562
  this._executeSwcScript("swc-on-connected", helperHostSet);
526
563
  this._executeSwcScript("swc-on-after-connected", helperHostSet);
527
564
  this.__swc_connected = true;
528
565
  } finally {
529
- for (const m of findAllLifecycleMetadata(this, ON_CONNECTED_COMPLETED_METADATA_KEY)) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
566
+ const aborted = !alive();
567
+ if (!aborted) for (const m of findAllLifecycleMetadata(this, ON_CONNECTED_COMPLETED_METADATA_KEY)) await this._invokeLifecycleMethod(m.propertyKey, helperHostSet);
530
568
  if (appHost && typeof appHost._connectedDone === "function") {
531
- await appHost._connectedDone(this);
569
+ await appHost._connectedDone(this, { aborted });
532
570
  }
533
571
  }
534
572
  };
535
- const originalDisconnected = proto.disconnectedCallback;
573
+ const originalDisconnected = userCallback(proto.disconnectedCallback);
536
574
  proto.disconnectedCallback = function() {
537
- const appHost = helperHostSet?.$appHost;
575
+ this.__swc_connectGen = (this.__swc_connectGen ?? 0) + 1;
576
+ const helperHostSet = connectedHelperHostSet(this);
577
+ const appHost = helperHostSet.$appHost;
538
578
  if (appHost && typeof appHost._disconnected === "function") {
539
579
  appHost._disconnected(this);
540
580
  }
@@ -556,28 +596,28 @@ const elementDefine = (name, config = {}) => (constructor) => {
556
596
  this._executeSwcScript("swc-on-after-disconnected", helperHostSet);
557
597
  this.__swc_connected = false;
558
598
  };
559
- const originalAdopted = proto.adoptedCallback;
599
+ const originalAdopted = userCallback(proto.adoptedCallback);
560
600
  proto.adoptedCallback = function() {
561
601
  const hostSet = SwcUtils.getHostSet(this);
562
602
  this._executeSwcScript("swc-on-before-adopted", hostSet);
563
603
  for (const m of findAllLifecycleMetadata(this, ON_BEFORE_ADOPTED_METADATA_KEY)) this._invokeLifecycleMethod(m.propertyKey, hostSet);
564
- for (const c of cyclers) c.onAdopted?.(helperHostSet);
604
+ for (const c of cyclers) c.onAdopted?.(connectedHelperHostSet(this));
565
605
  if (originalAdopted) originalAdopted.apply(this);
566
606
  for (const m of findAllLifecycleMetadata(this, ON_AFTER_ADOPTED_METADATA_KEY)) this._invokeLifecycleMethod(m.propertyKey, hostSet);
567
607
  this._executeSwcScript("swc-on-adopted", hostSet);
568
608
  this._executeSwcScript("swc-on-after-adopted", hostSet);
569
609
  };
570
- const originalAttributeChanged = proto.attributeChangedCallback;
610
+ const originalAttributeChanged = userCallback(proto.attributeChangedCallback);
571
611
  proto.attributeChangedCallback = function(name2, old, newVal) {
572
612
  if (originalAttributeChanged) originalAttributeChanged.apply(this, [name2, old, newVal]);
573
- const helperAndHostSet = SwcUtils.getHelperAndHostSet(win, this);
613
+ const helperAndHostSet = SwcUtils.getHelperAndHostSet(this);
574
614
  let processedVal = newVal;
575
615
  if (newVal !== null) {
576
616
  const ae = new ActionExpression(newVal);
577
617
  const expr = ae.getFirstExpression("callReturn");
578
618
  if (expr) {
579
- const win2 = this._resolveWindow?.() || (typeof window !== "undefined" ? window : void 0);
580
- const exprHelperAndHostSet = SwcUtils.getHelperAndHostSet(win2, this);
619
+ const win2 = SwcUtils.resolveWindow(this);
620
+ const exprHelperAndHostSet = SwcUtils.getHelperAndHostSet(this);
581
621
  const script = ConvertUtils.decodeHtmlEntity(expr.script, win2.document);
582
622
  try {
583
623
  const result = FunctionUtils.executeReturn({
@@ -604,6 +644,10 @@ const elementDefine = (name, config = {}) => (constructor) => {
604
644
  get: () => mergedObservedAttributes,
605
645
  configurable: true
606
646
  });
647
+ proto.connectedCallback[SWC_ORIGINAL_CALLBACK] = originalConnected;
648
+ proto.disconnectedCallback[SWC_ORIGINAL_CALLBACK] = originalDisconnected;
649
+ proto.adoptedCallback[SWC_ORIGINAL_CALLBACK] = originalAdopted;
650
+ proto.attributeChangedCallback[SWC_ORIGINAL_CALLBACK] = originalAttributeChanged;
607
651
  ReflectUtils.defineMetadata(ELEMENT_CONFIG_KEY, metadata, constructor);
608
652
  const registry = metadata.customElementRegistry || win?.customElements;
609
653
  if (registry && !registry.get(metadata.name)) {