@number10/jsx-core 5.0.0

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 (340) hide show
  1. package/LICENSE +667 -0
  2. package/README.md +38 -0
  3. package/dist/animation/animated-signal.cjs +19 -0
  4. package/dist/animation/animated-signal.cjs.map +1 -0
  5. package/dist/animation/animated-signal.d.ts +35 -0
  6. package/dist/animation/animated-signal.d.ts.map +1 -0
  7. package/dist/animation/animated-signal.js +19 -0
  8. package/dist/animation/animated-signal.js.map +1 -0
  9. package/dist/animation/create-spring.cjs +80 -0
  10. package/dist/animation/create-spring.cjs.map +1 -0
  11. package/dist/animation/create-spring.d.ts +56 -0
  12. package/dist/animation/create-spring.d.ts.map +1 -0
  13. package/dist/animation/create-spring.js +80 -0
  14. package/dist/animation/create-spring.js.map +1 -0
  15. package/dist/animation/easing.cjs +76 -0
  16. package/dist/animation/easing.cjs.map +1 -0
  17. package/dist/animation/easing.d.ts +45 -0
  18. package/dist/animation/easing.d.ts.map +1 -0
  19. package/dist/animation/easing.js +76 -0
  20. package/dist/animation/easing.js.map +1 -0
  21. package/dist/animation/effect-definitions.cjs +441 -0
  22. package/dist/animation/effect-definitions.cjs.map +1 -0
  23. package/dist/animation/effect-definitions.d.ts +60 -0
  24. package/dist/animation/effect-definitions.d.ts.map +1 -0
  25. package/dist/animation/effect-definitions.js +441 -0
  26. package/dist/animation/effect-definitions.js.map +1 -0
  27. package/dist/animation/effect-engine.cjs +189 -0
  28. package/dist/animation/effect-engine.cjs.map +1 -0
  29. package/dist/animation/effect-engine.d.ts +70 -0
  30. package/dist/animation/effect-engine.d.ts.map +1 -0
  31. package/dist/animation/effect-engine.js +189 -0
  32. package/dist/animation/effect-engine.js.map +1 -0
  33. package/dist/animation/index.d.ts +24 -0
  34. package/dist/animation/index.d.ts.map +1 -0
  35. package/dist/animation/spring-physics.cjs +94 -0
  36. package/dist/animation/spring-physics.cjs.map +1 -0
  37. package/dist/animation/spring-physics.d.ts +145 -0
  38. package/dist/animation/spring-physics.d.ts.map +1 -0
  39. package/dist/animation/spring-physics.js +94 -0
  40. package/dist/animation/spring-physics.js.map +1 -0
  41. package/dist/animation/tween.cjs +67 -0
  42. package/dist/animation/tween.cjs.map +1 -0
  43. package/dist/animation/tween.d.ts +60 -0
  44. package/dist/animation/tween.d.ts.map +1 -0
  45. package/dist/animation/tween.js +67 -0
  46. package/dist/animation/tween.js.map +1 -0
  47. package/dist/animation/types.d.ts +31 -0
  48. package/dist/animation/types.d.ts.map +1 -0
  49. package/dist/animation/useSpring.cjs +152 -0
  50. package/dist/animation/useSpring.cjs.map +1 -0
  51. package/dist/animation/useSpring.d.ts +55 -0
  52. package/dist/animation/useSpring.d.ts.map +1 -0
  53. package/dist/animation/useSpring.js +149 -0
  54. package/dist/animation/useSpring.js.map +1 -0
  55. package/dist/animation/useTween.cjs +208 -0
  56. package/dist/animation/useTween.cjs.map +1 -0
  57. package/dist/animation/useTween.d.ts +116 -0
  58. package/dist/animation/useTween.d.ts.map +1 -0
  59. package/dist/animation/useTween.js +208 -0
  60. package/dist/animation/useTween.js.map +1 -0
  61. package/dist/border-geometry.cjs +447 -0
  62. package/dist/border-geometry.cjs.map +1 -0
  63. package/dist/border-geometry.d.ts +114 -0
  64. package/dist/border-geometry.d.ts.map +1 -0
  65. package/dist/border-geometry.js +447 -0
  66. package/dist/border-geometry.js.map +1 -0
  67. package/dist/colors/color-presets.cjs +236 -0
  68. package/dist/colors/color-presets.cjs.map +1 -0
  69. package/dist/colors/color-presets.d.ts +89 -0
  70. package/dist/colors/color-presets.d.ts.map +1 -0
  71. package/dist/colors/color-presets.js +236 -0
  72. package/dist/colors/color-presets.js.map +1 -0
  73. package/dist/colors/color-theme-helpers.cjs +32 -0
  74. package/dist/colors/color-theme-helpers.cjs.map +1 -0
  75. package/dist/colors/color-theme-helpers.d.ts +65 -0
  76. package/dist/colors/color-theme-helpers.d.ts.map +1 -0
  77. package/dist/colors/color-theme-helpers.js +32 -0
  78. package/dist/colors/color-theme-helpers.js.map +1 -0
  79. package/dist/colors/color-types.cjs +38 -0
  80. package/dist/colors/color-types.cjs.map +1 -0
  81. package/dist/colors/color-types.d.ts +112 -0
  82. package/dist/colors/color-types.d.ts.map +1 -0
  83. package/dist/colors/color-types.js +38 -0
  84. package/dist/colors/color-types.js.map +1 -0
  85. package/dist/colors/color-utils.cjs +197 -0
  86. package/dist/colors/color-utils.cjs.map +1 -0
  87. package/dist/colors/color-utils.d.ts +216 -0
  88. package/dist/colors/color-utils.d.ts.map +1 -0
  89. package/dist/colors/color-utils.js +197 -0
  90. package/dist/colors/color-utils.js.map +1 -0
  91. package/dist/colors/contrast-contracts.cjs +265 -0
  92. package/dist/colors/contrast-contracts.cjs.map +1 -0
  93. package/dist/colors/contrast-contracts.d.ts +289 -0
  94. package/dist/colors/contrast-contracts.d.ts.map +1 -0
  95. package/dist/colors/contrast-contracts.js +265 -0
  96. package/dist/colors/contrast-contracts.js.map +1 -0
  97. package/dist/colors/index.cjs +55 -0
  98. package/dist/colors/index.cjs.map +1 -0
  99. package/dist/colors/index.d.ts +16 -0
  100. package/dist/colors/index.d.ts.map +1 -0
  101. package/dist/colors/index.js +55 -0
  102. package/dist/colors/index.js.map +1 -0
  103. package/dist/core-props.cjs +66 -0
  104. package/dist/core-props.cjs.map +1 -0
  105. package/dist/core-props.d.ts +395 -0
  106. package/dist/core-props.d.ts.map +1 -0
  107. package/dist/core-props.js +66 -0
  108. package/dist/core-props.js.map +1 -0
  109. package/dist/design-tokens/design-token-presets.cjs +91 -0
  110. package/dist/design-tokens/design-token-presets.cjs.map +1 -0
  111. package/dist/design-tokens/design-token-presets.d.ts +34 -0
  112. package/dist/design-tokens/design-token-presets.d.ts.map +1 -0
  113. package/dist/design-tokens/design-token-presets.js +91 -0
  114. package/dist/design-tokens/design-token-presets.js.map +1 -0
  115. package/dist/design-tokens/design-token-types.d.ts +97 -0
  116. package/dist/design-tokens/design-token-types.d.ts.map +1 -0
  117. package/dist/design-tokens/index.cjs +10 -0
  118. package/dist/design-tokens/index.cjs.map +1 -0
  119. package/dist/design-tokens/index.d.ts +9 -0
  120. package/dist/design-tokens/index.d.ts.map +1 -0
  121. package/dist/design-tokens/index.js +10 -0
  122. package/dist/design-tokens/index.js.map +1 -0
  123. package/dist/dev-config.cjs +296 -0
  124. package/dist/dev-config.cjs.map +1 -0
  125. package/dist/dev-config.d.ts +238 -0
  126. package/dist/dev-config.d.ts.map +1 -0
  127. package/dist/dev-config.js +296 -0
  128. package/dist/dev-config.js.map +1 -0
  129. package/dist/effects.cjs +69 -0
  130. package/dist/effects.cjs.map +1 -0
  131. package/dist/effects.d.ts +152 -0
  132. package/dist/effects.d.ts.map +1 -0
  133. package/dist/effects.js +69 -0
  134. package/dist/effects.js.map +1 -0
  135. package/dist/global-registry.cjs +25 -0
  136. package/dist/global-registry.cjs.map +1 -0
  137. package/dist/global-registry.d.ts +19 -0
  138. package/dist/global-registry.d.ts.map +1 -0
  139. package/dist/global-registry.js +25 -0
  140. package/dist/global-registry.js.map +1 -0
  141. package/dist/hooks.cjs +378 -0
  142. package/dist/hooks.cjs.map +1 -0
  143. package/dist/hooks.d.ts +322 -0
  144. package/dist/hooks.d.ts.map +1 -0
  145. package/dist/hooks.js +378 -0
  146. package/dist/hooks.js.map +1 -0
  147. package/dist/host-adapter.d.ts +414 -0
  148. package/dist/host-adapter.d.ts.map +1 -0
  149. package/dist/index.cjs +229 -0
  150. package/dist/index.cjs.map +1 -0
  151. package/dist/index.d.ts +32 -0
  152. package/dist/index.d.ts.map +1 -0
  153. package/dist/index.js +226 -0
  154. package/dist/index.js.map +1 -0
  155. package/dist/jsx-dev-runtime.cjs +10 -0
  156. package/dist/jsx-dev-runtime.cjs.map +1 -0
  157. package/dist/jsx-dev-runtime.d.ts +5 -0
  158. package/dist/jsx-dev-runtime.d.ts.map +1 -0
  159. package/dist/jsx-dev-runtime.js +11 -0
  160. package/dist/jsx-dev-runtime.js.map +1 -0
  161. package/dist/jsx-runtime.cjs +44 -0
  162. package/dist/jsx-runtime.cjs.map +1 -0
  163. package/dist/jsx-runtime.d.ts +24 -0
  164. package/dist/jsx-runtime.d.ts.map +1 -0
  165. package/dist/jsx-runtime.js +44 -0
  166. package/dist/jsx-runtime.js.map +1 -0
  167. package/dist/jsx-types.d.ts +25 -0
  168. package/dist/jsx-types.d.ts.map +1 -0
  169. package/dist/layout/appliers/container-applier.cjs +20 -0
  170. package/dist/layout/appliers/container-applier.cjs.map +1 -0
  171. package/dist/layout/appliers/container-applier.d.ts +9 -0
  172. package/dist/layout/appliers/container-applier.d.ts.map +1 -0
  173. package/dist/layout/appliers/container-applier.js +20 -0
  174. package/dist/layout/appliers/container-applier.js.map +1 -0
  175. package/dist/layout/appliers/position-applier.cjs +31 -0
  176. package/dist/layout/appliers/position-applier.cjs.map +1 -0
  177. package/dist/layout/appliers/position-applier.d.ts +8 -0
  178. package/dist/layout/appliers/position-applier.d.ts.map +1 -0
  179. package/dist/layout/appliers/position-applier.js +31 -0
  180. package/dist/layout/appliers/position-applier.js.map +1 -0
  181. package/dist/layout/layout-engine-test-utils.d.ts +26 -0
  182. package/dist/layout/layout-engine-test-utils.d.ts.map +1 -0
  183. package/dist/layout/layout-engine.cjs +628 -0
  184. package/dist/layout/layout-engine.cjs.map +1 -0
  185. package/dist/layout/layout-engine.d.ts +140 -0
  186. package/dist/layout/layout-engine.d.ts.map +1 -0
  187. package/dist/layout/layout-engine.js +628 -0
  188. package/dist/layout/layout-engine.js.map +1 -0
  189. package/dist/layout/strategies/base-strategy.cjs +31 -0
  190. package/dist/layout/strategies/base-strategy.cjs.map +1 -0
  191. package/dist/layout/strategies/base-strategy.d.ts +59 -0
  192. package/dist/layout/strategies/base-strategy.d.ts.map +1 -0
  193. package/dist/layout/strategies/base-strategy.js +31 -0
  194. package/dist/layout/strategies/base-strategy.js.map +1 -0
  195. package/dist/layout/strategies/column-layout.cjs +145 -0
  196. package/dist/layout/strategies/column-layout.cjs.map +1 -0
  197. package/dist/layout/strategies/column-layout.d.ts +38 -0
  198. package/dist/layout/strategies/column-layout.d.ts.map +1 -0
  199. package/dist/layout/strategies/column-layout.js +145 -0
  200. package/dist/layout/strategies/column-layout.js.map +1 -0
  201. package/dist/layout/strategies/row-layout.cjs +145 -0
  202. package/dist/layout/strategies/row-layout.cjs.map +1 -0
  203. package/dist/layout/strategies/row-layout.d.ts +38 -0
  204. package/dist/layout/strategies/row-layout.d.ts.map +1 -0
  205. package/dist/layout/strategies/row-layout.js +145 -0
  206. package/dist/layout/strategies/row-layout.js.map +1 -0
  207. package/dist/layout/strategies/stack-layout.cjs +94 -0
  208. package/dist/layout/strategies/stack-layout.cjs.map +1 -0
  209. package/dist/layout/strategies/stack-layout.d.ts +30 -0
  210. package/dist/layout/strategies/stack-layout.d.ts.map +1 -0
  211. package/dist/layout/strategies/stack-layout.js +94 -0
  212. package/dist/layout/strategies/stack-layout.js.map +1 -0
  213. package/dist/layout/types.d.ts +134 -0
  214. package/dist/layout/types.d.ts.map +1 -0
  215. package/dist/layout/utils/child-utils.cjs +129 -0
  216. package/dist/layout/utils/child-utils.cjs.map +1 -0
  217. package/dist/layout/utils/child-utils.d.ts +54 -0
  218. package/dist/layout/utils/child-utils.d.ts.map +1 -0
  219. package/dist/layout/utils/child-utils.js +129 -0
  220. package/dist/layout/utils/child-utils.js.map +1 -0
  221. package/dist/layout/utils/dimension-calculator.cjs +109 -0
  222. package/dist/layout/utils/dimension-calculator.cjs.map +1 -0
  223. package/dist/layout/utils/dimension-calculator.d.ts +59 -0
  224. package/dist/layout/utils/dimension-calculator.d.ts.map +1 -0
  225. package/dist/layout/utils/dimension-calculator.js +109 -0
  226. package/dist/layout/utils/dimension-calculator.js.map +1 -0
  227. package/dist/layout/utils/flex-distributor.cjs +173 -0
  228. package/dist/layout/utils/flex-distributor.cjs.map +1 -0
  229. package/dist/layout/utils/flex-distributor.d.ts +18 -0
  230. package/dist/layout/utils/flex-distributor.d.ts.map +1 -0
  231. package/dist/layout/utils/flex-distributor.js +173 -0
  232. package/dist/layout/utils/flex-distributor.js.map +1 -0
  233. package/dist/layout/utils/size-resolver.cjs +280 -0
  234. package/dist/layout/utils/size-resolver.cjs.map +1 -0
  235. package/dist/layout/utils/size-resolver.d.ts +84 -0
  236. package/dist/layout/utils/size-resolver.d.ts.map +1 -0
  237. package/dist/layout/utils/size-resolver.js +280 -0
  238. package/dist/layout/utils/size-resolver.js.map +1 -0
  239. package/dist/layout/utils/spacing-calculator.cjs +50 -0
  240. package/dist/layout/utils/spacing-calculator.cjs.map +1 -0
  241. package/dist/layout/utils/spacing-calculator.d.ts +27 -0
  242. package/dist/layout/utils/spacing-calculator.d.ts.map +1 -0
  243. package/dist/layout/utils/spacing-calculator.js +50 -0
  244. package/dist/layout/utils/spacing-calculator.js.map +1 -0
  245. package/dist/memo.cjs +18 -0
  246. package/dist/memo.cjs.map +1 -0
  247. package/dist/memo.d.ts +29 -0
  248. package/dist/memo.d.ts.map +1 -0
  249. package/dist/memo.js +18 -0
  250. package/dist/memo.js.map +1 -0
  251. package/dist/nineslice-contract.cjs +60 -0
  252. package/dist/nineslice-contract.cjs.map +1 -0
  253. package/dist/nineslice-contract.d.ts +107 -0
  254. package/dist/nineslice-contract.d.ts.map +1 -0
  255. package/dist/nineslice-contract.js +60 -0
  256. package/dist/nineslice-contract.js.map +1 -0
  257. package/dist/placeholder.cjs +12 -0
  258. package/dist/placeholder.cjs.map +1 -0
  259. package/dist/placeholder.d.ts +44 -0
  260. package/dist/placeholder.d.ts.map +1 -0
  261. package/dist/placeholder.js +12 -0
  262. package/dist/placeholder.js.map +1 -0
  263. package/dist/portal.cjs +89 -0
  264. package/dist/portal.cjs.map +1 -0
  265. package/dist/portal.d.ts +62 -0
  266. package/dist/portal.d.ts.map +1 -0
  267. package/dist/portal.js +89 -0
  268. package/dist/portal.js.map +1 -0
  269. package/dist/primitive-contracts.cjs +12 -0
  270. package/dist/primitive-contracts.cjs.map +1 -0
  271. package/dist/primitive-contracts.d.ts +186 -0
  272. package/dist/primitive-contracts.d.ts.map +1 -0
  273. package/dist/primitive-contracts.js +12 -0
  274. package/dist/primitive-contracts.js.map +1 -0
  275. package/dist/theme.cjs +332 -0
  276. package/dist/theme.cjs.map +1 -0
  277. package/dist/theme.d.ts +204 -0
  278. package/dist/theme.d.ts.map +1 -0
  279. package/dist/theme.js +332 -0
  280. package/dist/theme.js.map +1 -0
  281. package/dist/types.d.ts +86 -0
  282. package/dist/types.d.ts.map +1 -0
  283. package/dist/vdom/create-runtime.cjs +79 -0
  284. package/dist/vdom/create-runtime.cjs.map +1 -0
  285. package/dist/vdom/create-runtime.d.ts +7 -0
  286. package/dist/vdom/create-runtime.d.ts.map +1 -0
  287. package/dist/vdom/create-runtime.js +79 -0
  288. package/dist/vdom/create-runtime.js.map +1 -0
  289. package/dist/vdom/index.cjs +8 -0
  290. package/dist/vdom/index.cjs.map +1 -0
  291. package/dist/vdom/index.d.ts +4 -0
  292. package/dist/vdom/index.d.ts.map +1 -0
  293. package/dist/vdom/index.js +8 -0
  294. package/dist/vdom/index.js.map +1 -0
  295. package/dist/vdom/mount.cjs +161 -0
  296. package/dist/vdom/mount.cjs.map +1 -0
  297. package/dist/vdom/mount.d.ts +6 -0
  298. package/dist/vdom/mount.d.ts.map +1 -0
  299. package/dist/vdom/mount.js +161 -0
  300. package/dist/vdom/mount.js.map +1 -0
  301. package/dist/vdom/patch.cjs +163 -0
  302. package/dist/vdom/patch.cjs.map +1 -0
  303. package/dist/vdom/patch.d.ts +3 -0
  304. package/dist/vdom/patch.d.ts.map +1 -0
  305. package/dist/vdom/patch.js +163 -0
  306. package/dist/vdom/patch.js.map +1 -0
  307. package/dist/vdom/registry.cjs +85 -0
  308. package/dist/vdom/registry.cjs.map +1 -0
  309. package/dist/vdom/registry.d.ts +28 -0
  310. package/dist/vdom/registry.d.ts.map +1 -0
  311. package/dist/vdom/registry.js +85 -0
  312. package/dist/vdom/registry.js.map +1 -0
  313. package/dist/vdom/runtime-helpers.cjs +23 -0
  314. package/dist/vdom/runtime-helpers.cjs.map +1 -0
  315. package/dist/vdom/runtime-helpers.d.ts +8 -0
  316. package/dist/vdom/runtime-helpers.d.ts.map +1 -0
  317. package/dist/vdom/runtime-helpers.js +23 -0
  318. package/dist/vdom/runtime-helpers.js.map +1 -0
  319. package/dist/vdom/surface.cjs +107 -0
  320. package/dist/vdom/surface.cjs.map +1 -0
  321. package/dist/vdom/surface.d.ts +9 -0
  322. package/dist/vdom/surface.d.ts.map +1 -0
  323. package/dist/vdom/surface.js +107 -0
  324. package/dist/vdom/surface.js.map +1 -0
  325. package/dist/vdom/types.d.ts +104 -0
  326. package/dist/vdom/types.d.ts.map +1 -0
  327. package/dist/vdom/utils.cjs +146 -0
  328. package/dist/vdom/utils.cjs.map +1 -0
  329. package/dist/vdom/utils.d.ts +24 -0
  330. package/dist/vdom/utils.d.ts.map +1 -0
  331. package/dist/vdom/utils.js +146 -0
  332. package/dist/vdom/utils.js.map +1 -0
  333. package/dist/vdom.d.ts +4 -0
  334. package/dist/vdom.d.ts.map +1 -0
  335. package/dist/vector-draw-context.d.ts +63 -0
  336. package/dist/vector-draw-context.d.ts.map +1 -0
  337. package/package.json +161 -0
  338. package/vdom/index.cjs +1 -0
  339. package/vdom/index.d.ts +1 -0
  340. package/vdom/index.js +1 -0
@@ -0,0 +1,161 @@
1
+ import { disposeCtx, withHooks } from "../hooks.js";
2
+ import { Fragment } from "../jsx-runtime.js";
3
+ import { createRuntimeHelpers } from "./runtime-helpers.js";
4
+ import { flattenChildren, attachRef, shouldSkipChild, applyThemeToChild, setVNodePropSafe, normalizeVNodeLike, isLayoutContainer } from "./utils.js";
5
+ function createMountOps(state, getPatchVNode) {
6
+ const { getHostContext, recalculateLayout, runEffects } = createRuntimeHelpers(state);
7
+ const updateHandler = (hookCtx) => {
8
+ const ctx = hookCtx;
9
+ if (ctx.disposed || !state.getHostAdapter().isAlive(ctx.parent)) return;
10
+ const componentProps = ctx.componentVNode.props ?? {};
11
+ const propsWithChildren = ctx.componentVNode.children?.length ? { ...componentProps, children: ctx.componentVNode.children } : componentProps;
12
+ ctx.surface = getHostContext(ctx.parent);
13
+ const nextVNode = normalizeVNodeLike(
14
+ withHooks(ctx, () => ctx.function(propsWithChildren), {
15
+ isAlive: () => state.getHostAdapter().isAlive(ctx.parent)
16
+ })
17
+ );
18
+ getPatchVNode()(ctx.parent, ctx.vnode, nextVNode);
19
+ ctx.vnode = nextVNode;
20
+ runEffects(ctx);
21
+ };
22
+ const mount = (parentOrScene, vnode) => {
23
+ if (!vnode || typeof vnode !== "object") {
24
+ return state.bridge.createDummyNode(parentOrScene);
25
+ }
26
+ if (vnode.type === void 0 || vnode.type === null) {
27
+ return state.bridge.createDummyNode(parentOrScene);
28
+ }
29
+ if (vnode.type === Fragment) {
30
+ let firstNode;
31
+ const flatChildren2 = flattenChildren(vnode.children);
32
+ for (let i = 0; i < flatChildren2.length; i++) {
33
+ const child = flatChildren2[i];
34
+ if (shouldSkipChild(child)) continue;
35
+ let nextChild = child;
36
+ nextChild = applyThemeToChild(nextChild, vnode.__theme, {});
37
+ flatChildren2[i] = nextChild;
38
+ const childNode = mount(parentOrScene, nextChild);
39
+ if (!firstNode) firstNode = childNode;
40
+ }
41
+ setVNodePropSafe(setVNodePropSafe(vnode, "__node", firstNode), "__parent", parentOrScene);
42
+ return firstNode ?? state.bridge.createDummyNode(parentOrScene);
43
+ }
44
+ if (typeof vnode.type === "function") {
45
+ const ctx = {
46
+ index: 0,
47
+ slots: [],
48
+ effects: [],
49
+ cleanups: [],
50
+ vnode,
51
+ componentVNode: vnode,
52
+ parent: parentOrScene,
53
+ function: vnode.type,
54
+ isFactory: false,
55
+ theme: vnode.__theme,
56
+ themeTokens: getHostContext(parentOrScene)?.themeTokens,
57
+ surface: getHostContext(parentOrScene),
58
+ updateHandler
59
+ };
60
+ vnode = setVNodePropSafe(vnode, "__ctx", ctx);
61
+ const propsWithChildren = vnode.children?.length ? { ...vnode.props ?? {}, children: vnode.children } : vnode.props;
62
+ const renderedRaw = withHooks(ctx, () => ctx.function(propsWithChildren), {
63
+ isAlive: () => state.getHostAdapter().isAlive(parentOrScene)
64
+ });
65
+ let rendered = normalizeVNodeLike(renderedRaw);
66
+ if (!rendered) {
67
+ ctx.vnode = rendered;
68
+ runEffects(ctx);
69
+ return state.bridge.createDummyNode(parentOrScene);
70
+ }
71
+ if (ctx.theme && !rendered.__theme) {
72
+ rendered = setVNodePropSafe(rendered, "__theme", ctx.theme);
73
+ }
74
+ if (ctx.slots.length === 0 && ctx.effects.length === 0) {
75
+ ctx.isFactory = true;
76
+ ctx.vnode = rendered;
77
+ if (vnode.__addConfig) {
78
+ rendered = setVNodePropSafe(rendered, "__addConfig", vnode.__addConfig);
79
+ }
80
+ return mount(parentOrScene, rendered);
81
+ }
82
+ if (vnode.__addConfig) {
83
+ rendered = setVNodePropSafe(rendered, "__addConfig", vnode.__addConfig);
84
+ }
85
+ const node2 = mount(parentOrScene, rendered);
86
+ ctx.cleanups.push(() => unmount(rendered));
87
+ ctx.vnode = rendered;
88
+ runEffects(ctx);
89
+ return node2;
90
+ }
91
+ const nodeType = vnode.type;
92
+ const { props: themedProps, nestedTheme } = state.bridge.resolveProps(
93
+ nodeType,
94
+ vnode.__theme,
95
+ vnode.props ?? {}
96
+ );
97
+ const hostCtx = getHostContext(parentOrScene);
98
+ const node = state.getHostAdapter().create(nodeType, themedProps, hostCtx);
99
+ state.bridge.attachSurfaceContext?.(node, hostCtx);
100
+ vnode = setVNodePropSafe(setVNodePropSafe(vnode, "__node", node), "__parent", parentOrScene);
101
+ attachRef(
102
+ vnode.props?.ref,
103
+ node
104
+ );
105
+ state.getHostAdapter().append(parentOrScene, node, hostCtx);
106
+ const flatChildren = flattenChildren(vnode.children);
107
+ for (let i = 0; i < flatChildren.length; i++) {
108
+ const child = flatChildren[i];
109
+ if (shouldSkipChild(child)) continue;
110
+ if (!child || typeof child !== "object" || !("type" in child)) continue;
111
+ let nextChild = child;
112
+ nextChild = applyThemeToChild(
113
+ nextChild,
114
+ vnode.__theme,
115
+ nestedTheme
116
+ );
117
+ flatChildren[i] = nextChild;
118
+ mount(node, nextChild);
119
+ }
120
+ if (isLayoutContainer(node)) {
121
+ recalculateLayout(node, parentOrScene);
122
+ }
123
+ return node;
124
+ };
125
+ const unmount = (vnode) => {
126
+ if (!vnode) return;
127
+ if (vnode.type === Fragment) {
128
+ flattenChildren(vnode.children).forEach(unmount);
129
+ return;
130
+ }
131
+ if (typeof vnode.type === "function") {
132
+ const ctx = vnode.__ctx;
133
+ if (ctx) {
134
+ disposeCtx(ctx);
135
+ delete vnode.__ctx;
136
+ }
137
+ if (ctx?.vnode) unmount(ctx.vnode);
138
+ return;
139
+ }
140
+ attachRef(
141
+ vnode.props?.ref,
142
+ null
143
+ );
144
+ flattenChildren(vnode.children).forEach(unmount);
145
+ const node = vnode.__node;
146
+ if (node) {
147
+ const parent = vnode.__parent;
148
+ if (parent && state.getHostAdapter().isAlive(parent) && state.getHostAdapter().isAlive(node)) {
149
+ state.getHostAdapter().remove(parent, node, getHostContext(parent));
150
+ }
151
+ }
152
+ };
153
+ return {
154
+ mount,
155
+ unmount
156
+ };
157
+ }
158
+ export {
159
+ createMountOps
160
+ };
161
+ //# sourceMappingURL=mount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount.js","sources":["../../src/vdom/mount.ts"],"sourcesContent":["import { disposeCtx, withHooks, type HookContext } from '../hooks'\nimport type { NodeType } from '../host-adapter'\nimport { Fragment } from '../jsx-runtime'\nimport type { PartialTheme } from '../theme'\nimport type { VNodeLike } from '../types'\nimport { createRuntimeHelpers } from './runtime-helpers'\nimport type { MountFn, PatchVNodeFn, RuntimeState, UnmountFn, VDOMHookContext } from './types'\nimport {\n applyThemeToChild,\n attachRef,\n flattenChildren,\n isLayoutContainer,\n normalizeVNodeLike,\n setVNodePropSafe,\n shouldSkipChild,\n} from './utils'\n\nexport function createMountOps(state: RuntimeState, getPatchVNode: () => PatchVNodeFn) {\n const { getHostContext, recalculateLayout, runEffects } = createRuntimeHelpers(state)\n\n const updateHandler = (hookCtx: HookContext): void => {\n const ctx = hookCtx as VDOMHookContext\n if (ctx.disposed || !state.getHostAdapter().isAlive(ctx.parent)) return\n\n const componentProps = ctx.componentVNode.props ?? {}\n const propsWithChildren = ctx.componentVNode.children?.length\n ? { ...componentProps, children: ctx.componentVNode.children }\n : componentProps\n\n ctx.surface = getHostContext(ctx.parent)\n const nextVNode = normalizeVNodeLike(\n withHooks(ctx, () => ctx.function(propsWithChildren), {\n isAlive: () => state.getHostAdapter().isAlive(ctx.parent),\n }) as VNodeLike\n )\n\n getPatchVNode()(ctx.parent, ctx.vnode, nextVNode)\n ctx.vnode = nextVNode\n runEffects(ctx)\n }\n\n const mount: MountFn = (parentOrScene, vnode) => {\n if (!vnode || typeof vnode !== 'object') {\n return state.bridge.createDummyNode(parentOrScene)\n }\n\n if (vnode.type === undefined || vnode.type === null) {\n return state.bridge.createDummyNode(parentOrScene)\n }\n\n if (vnode.type === Fragment) {\n let firstNode\n const flatChildren = flattenChildren(vnode.children)\n for (let i = 0; i < flatChildren.length; i++) {\n const child = flatChildren[i]\n if (shouldSkipChild(child)) continue\n let nextChild = child as typeof vnode\n nextChild = applyThemeToChild(nextChild, vnode.__theme as PartialTheme | undefined, {})\n flatChildren[i] = nextChild\n const childNode = mount(parentOrScene, nextChild)\n if (!firstNode) firstNode = childNode\n }\n setVNodePropSafe(setVNodePropSafe(vnode, '__node', firstNode), '__parent', parentOrScene)\n return firstNode ?? state.bridge.createDummyNode(parentOrScene)\n }\n\n if (typeof vnode.type === 'function') {\n const ctx: VDOMHookContext = {\n index: 0,\n slots: [],\n effects: [],\n cleanups: [],\n vnode,\n componentVNode: vnode,\n parent: parentOrScene,\n function: vnode.type as (props: unknown) => VNodeLike,\n isFactory: false,\n theme: vnode.__theme as PartialTheme | undefined,\n themeTokens: getHostContext(parentOrScene)?.themeTokens,\n surface: getHostContext(parentOrScene),\n updateHandler,\n }\n vnode = setVNodePropSafe(vnode, '__ctx', ctx)\n\n const propsWithChildren = vnode.children?.length\n ? { ...(vnode.props ?? {}), children: vnode.children }\n : vnode.props\n const renderedRaw = withHooks(ctx, () => ctx.function(propsWithChildren), {\n isAlive: () => state.getHostAdapter().isAlive(parentOrScene),\n })\n let rendered = normalizeVNodeLike(renderedRaw as VNodeLike)\n\n if (!rendered) {\n ctx.vnode = rendered\n runEffects(ctx)\n return state.bridge.createDummyNode(parentOrScene)\n }\n\n if (ctx.theme && !rendered.__theme) {\n rendered = setVNodePropSafe(rendered, '__theme', ctx.theme)\n }\n\n if (ctx.slots.length === 0 && ctx.effects.length === 0) {\n ctx.isFactory = true\n ctx.vnode = rendered\n if (vnode.__addConfig) {\n rendered = setVNodePropSafe(rendered, '__addConfig', vnode.__addConfig)\n }\n return mount(parentOrScene, rendered)\n }\n\n if (vnode.__addConfig) {\n rendered = setVNodePropSafe(rendered, '__addConfig', vnode.__addConfig)\n }\n\n const node = mount(parentOrScene, rendered)\n ctx.cleanups.push(() => unmount(rendered))\n ctx.vnode = rendered\n runEffects(ctx)\n return node\n }\n\n const nodeType = vnode.type as NodeType\n const { props: themedProps, nestedTheme } = state.bridge.resolveProps(\n nodeType,\n vnode.__theme as PartialTheme | undefined,\n (vnode.props ?? {}) as Record<string, unknown>\n )\n\n const hostCtx = getHostContext(parentOrScene)\n const node = state.getHostAdapter().create(nodeType, themedProps, hostCtx)\n state.bridge.attachSurfaceContext?.(node, hostCtx)\n vnode = setVNodePropSafe(setVNodePropSafe(vnode, '__node', node), '__parent', parentOrScene)\n\n attachRef(\n vnode.props?.ref as\n | { current: typeof node | null }\n | ((value: typeof node | null) => void)\n | undefined,\n node\n )\n state.getHostAdapter().append(parentOrScene, node, hostCtx)\n\n const flatChildren = flattenChildren(vnode.children)\n for (let i = 0; i < flatChildren.length; i++) {\n const child = flatChildren[i]\n if (shouldSkipChild(child)) continue\n if (!child || typeof child !== 'object' || !('type' in child)) continue\n\n let nextChild = child as typeof vnode\n nextChild = applyThemeToChild(\n nextChild,\n vnode.__theme as PartialTheme | undefined,\n nestedTheme\n )\n flatChildren[i] = nextChild\n mount(node, nextChild)\n }\n\n if (isLayoutContainer(node)) {\n recalculateLayout(node, parentOrScene)\n }\n\n return node\n }\n\n const unmount: UnmountFn = (vnode) => {\n if (!vnode) return\n\n if (vnode.type === Fragment) {\n flattenChildren(vnode.children).forEach(unmount)\n return\n }\n\n if (typeof vnode.type === 'function') {\n const ctx = (vnode as typeof vnode & { __ctx?: VDOMHookContext }).__ctx\n if (ctx) {\n disposeCtx(ctx)\n delete (vnode as typeof vnode & { __ctx?: VDOMHookContext }).__ctx\n }\n if (ctx?.vnode) unmount(ctx.vnode)\n return\n }\n\n attachRef(\n vnode.props?.ref as\n | { current: unknown | null }\n | ((value: unknown | null) => void)\n | undefined,\n null\n )\n\n flattenChildren(vnode.children).forEach(unmount)\n\n const node = vnode.__node\n if (node) {\n const parent = vnode.__parent\n if (\n parent &&\n state.getHostAdapter().isAlive(parent) &&\n state.getHostAdapter().isAlive(node)\n ) {\n state.getHostAdapter().remove(parent, node, getHostContext(parent))\n }\n }\n }\n\n return {\n mount,\n unmount,\n }\n}\n"],"names":["flatChildren","node"],"mappings":";;;;AAiBO,SAAS,eAAe,OAAqB,eAAmC;AACrF,QAAM,EAAE,gBAAgB,mBAAmB,WAAA,IAAe,qBAAqB,KAAK;AAEpF,QAAM,gBAAgB,CAAC,YAA+B;AACpD,UAAM,MAAM;AACZ,QAAI,IAAI,YAAY,CAAC,MAAM,iBAAiB,QAAQ,IAAI,MAAM,EAAG;AAEjE,UAAM,iBAAiB,IAAI,eAAe,SAAS,CAAA;AACnD,UAAM,oBAAoB,IAAI,eAAe,UAAU,SACnD,EAAE,GAAG,gBAAgB,UAAU,IAAI,eAAe,SAAA,IAClD;AAEJ,QAAI,UAAU,eAAe,IAAI,MAAM;AACvC,UAAM,YAAY;AAAA,MAChB,UAAU,KAAK,MAAM,IAAI,SAAS,iBAAiB,GAAG;AAA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AAQ,MAAM,KACrC,MAAM,eAAA,EAAiB,QAAQ,IAAI,GACnC;AACA,cAAM,iBAAiB,OAAO,QAAQ,MAAM,eAAe,MAAM,CAAC;AAAA,MACpE;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EAAA;AAEJ;"}
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const hooks = require("../hooks.cjs");
4
+ const jsxRuntime = require("../jsx-runtime.cjs");
5
+ const runtimeHelpers = require("./runtime-helpers.cjs");
6
+ const utils = require("./utils.cjs");
7
+ function createPatchVNode(state, getMount, getUnmount) {
8
+ const { getHostContext, recalculateLayout, runEffects } = runtimeHelpers.createRuntimeHelpers(state);
9
+ const patchVNode = (parent, oldV, newV) => {
10
+ const mount = getMount();
11
+ const unmount = getUnmount();
12
+ if (!oldV && !newV) return;
13
+ if (!oldV && newV) {
14
+ mount(parent, newV);
15
+ return;
16
+ }
17
+ if (oldV && !newV) {
18
+ unmount(oldV);
19
+ return;
20
+ }
21
+ if (!oldV || !newV) return;
22
+ if (oldV.__key !== newV.__key) {
23
+ unmount(oldV);
24
+ mount(parent, newV);
25
+ if (utils.isLayoutContainer(parent) && parent.__layoutProps) {
26
+ recalculateLayout(parent, utils.getLayoutParent(parent) ?? parent);
27
+ }
28
+ return;
29
+ }
30
+ if (oldV.type === jsxRuntime.Fragment && newV.type === jsxRuntime.Fragment) {
31
+ const a2 = utils.flattenChildren(oldV.children);
32
+ const b2 = utils.flattenChildren(newV.children);
33
+ const len2 = Math.max(a2.length, b2.length);
34
+ for (let i = 0; i < len2; i++) {
35
+ const c1 = a2[i];
36
+ const c2 = b2[i];
37
+ const valid1 = c1 != null && c1 !== false;
38
+ const valid2 = c2 != null && c2 !== false;
39
+ if (!valid1 && valid2) {
40
+ mount(parent, c2);
41
+ } else if (valid1 && !valid2) {
42
+ unmount(c1);
43
+ } else if (valid1 && valid2) {
44
+ patchVNode(parent, c1, c2);
45
+ }
46
+ }
47
+ return;
48
+ }
49
+ if (typeof oldV.type === "function" || typeof newV.type === "function") {
50
+ if (oldV.type === newV.type) {
51
+ const ctx = oldV.__ctx;
52
+ if (!ctx) {
53
+ mount(parent, newV);
54
+ return;
55
+ }
56
+ if (newV.props !== void 0) ctx.componentVNode.props = newV.props;
57
+ if (newV.children !== void 0) ctx.componentVNode.children = newV.children;
58
+ const previousTheme = ctx.theme;
59
+ if (newV.__theme !== void 0) ctx.theme = newV.__theme;
60
+ const newVNodeWithCtx = utils.setVNodePropSafe(newV, "__ctx", ctx);
61
+ const propsWithChildren = utils.withChildrenProps(ctx.componentVNode);
62
+ const themeChanged = !Object.is(previousTheme, ctx.theme);
63
+ const propsChanged = hooks.shouldComponentUpdate(ctx, propsWithChildren);
64
+ if (!themeChanged && !propsChanged) return;
65
+ ctx.surface = getHostContext(parent);
66
+ let renderedNext = utils.normalizeVNodeLike(
67
+ hooks.withHooks(
68
+ ctx,
69
+ () => newVNodeWithCtx.type(propsWithChildren),
70
+ {
71
+ isAlive: () => state.getHostAdapter().isAlive(parent)
72
+ }
73
+ )
74
+ );
75
+ if (!renderedNext) {
76
+ ctx.vnode = renderedNext;
77
+ runEffects(ctx);
78
+ return;
79
+ }
80
+ if (ctx.theme && !renderedNext.__theme) {
81
+ renderedNext = utils.setVNodePropSafe(renderedNext, "__theme", ctx.theme);
82
+ }
83
+ patchVNode(parent, ctx.vnode, renderedNext);
84
+ ctx.vnode = renderedNext;
85
+ runEffects(ctx);
86
+ return;
87
+ }
88
+ unmount(oldV);
89
+ mount(parent, newV);
90
+ return;
91
+ }
92
+ if (oldV.type !== newV.type) {
93
+ unmount(oldV);
94
+ mount(parent, newV);
95
+ return;
96
+ }
97
+ const nodeType = oldV.type;
98
+ newV = utils.setVNodePropSafe(utils.setVNodePropSafe(newV, "__node", oldV.__node), "__parent", parent);
99
+ const oldRef = oldV.props?.ref;
100
+ const newRef = newV.props?.ref;
101
+ if (oldRef !== newRef) {
102
+ utils.attachRef(oldRef, null);
103
+ utils.attachRef(newRef, oldV.__node);
104
+ }
105
+ const { props: oldProps } = state.bridge.resolveProps(
106
+ nodeType,
107
+ oldV.__theme,
108
+ oldV.props ?? {}
109
+ );
110
+ const { props: newProps, nestedTheme } = state.bridge.resolveProps(
111
+ nodeType,
112
+ newV.__theme,
113
+ newV.props ?? {}
114
+ );
115
+ state.getHostAdapter().patch(nodeType, oldV.__node, oldProps, newProps, getHostContext(parent));
116
+ const a = utils.flattenChildren(oldV.children);
117
+ const b = utils.flattenChildren(newV.children);
118
+ const len = Math.max(a.length, b.length);
119
+ let childrenChanged = a.filter(Boolean).length !== b.filter(Boolean).length;
120
+ const containerLayoutChanged = utils.hasLayoutPropsChanged(oldV, newV);
121
+ for (let i = 0; i < len; i++) {
122
+ const c1 = a[i];
123
+ const c2 = b[i];
124
+ const valid1 = c1 != null && c1 !== false;
125
+ const valid2 = c2 != null && c2 !== false;
126
+ if (!valid1 && valid2) {
127
+ const themed = utils.applyThemeToChild(
128
+ c2,
129
+ newV.__theme,
130
+ nestedTheme
131
+ );
132
+ b[i] = themed;
133
+ mount(oldV.__node, themed);
134
+ childrenChanged = true;
135
+ } else if (valid1 && !valid2) {
136
+ unmount(c1);
137
+ childrenChanged = true;
138
+ } else if (valid1 && valid2) {
139
+ const themed = utils.applyThemeToChild(
140
+ c2,
141
+ newV.__theme,
142
+ nestedTheme
143
+ );
144
+ b[i] = themed;
145
+ const childLayoutChanged = utils.hasLayoutPropsChanged(c1, themed);
146
+ const textContentChanged = c1.props?.text !== themed.props?.text || !utils.deepEqual(c1.props?.style, themed.props?.style);
147
+ const previousChildSize = utils.readVNodeLayoutSize(c1);
148
+ patchVNode(oldV.__node, c1, themed);
149
+ const nextChildSize = utils.readVNodeLayoutSize(c1);
150
+ const childSizeChanged = previousChildSize === null || nextChildSize === null ? false : Math.abs(previousChildSize.width - nextChildSize.width) >= 0.5 || Math.abs(previousChildSize.height - nextChildSize.height) >= 0.5;
151
+ if (childLayoutChanged || textContentChanged || childSizeChanged) {
152
+ childrenChanged = true;
153
+ }
154
+ }
155
+ }
156
+ if (oldV.__node && utils.isLayoutContainer(oldV.__node) && (containerLayoutChanged || childrenChanged)) {
157
+ recalculateLayout(oldV.__node, parent);
158
+ }
159
+ };
160
+ return patchVNode;
161
+ }
162
+ exports.createPatchVNode = createPatchVNode;
163
+ //# sourceMappingURL=patch.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patch.cjs","sources":["../../src/vdom/patch.ts"],"sourcesContent":["import { shouldComponentUpdate, withHooks } from '../hooks'\nimport type { NodeType } from '../host-adapter'\nimport { Fragment } from '../jsx-runtime'\nimport type { PartialTheme } from '../theme'\nimport type { VNodeLike } from '../types'\nimport { createRuntimeHelpers } from './runtime-helpers'\nimport type { MountFn, PatchVNodeFn, RuntimeState, UnmountFn, VDOMHookContext } from './types'\nimport {\n applyThemeToChild,\n attachRef,\n deepEqual,\n flattenChildren,\n getLayoutParent,\n hasLayoutPropsChanged,\n isLayoutContainer,\n normalizeVNodeLike,\n readVNodeLayoutSize,\n setVNodePropSafe,\n withChildrenProps,\n} from './utils'\n\nexport function createPatchVNode(\n state: RuntimeState,\n getMount: () => MountFn,\n getUnmount: () => UnmountFn\n): PatchVNodeFn {\n const { getHostContext, recalculateLayout, runEffects } = createRuntimeHelpers(state)\n\n const patchVNode: PatchVNodeFn = (parent, oldV, newV) => {\n const mount = getMount()\n const unmount = getUnmount()\n\n if (!oldV && !newV) return\n if (!oldV && newV) {\n mount(parent, newV)\n return\n }\n if (oldV && !newV) {\n unmount(oldV)\n return\n }\n if (!oldV || !newV) return\n\n if (oldV.__key !== newV.__key) {\n unmount(oldV)\n mount(parent, newV)\n\n if (isLayoutContainer(parent) && parent.__layoutProps) {\n recalculateLayout(parent, getLayoutParent(parent) ?? parent)\n }\n return\n }\n\n if (oldV.type === Fragment && newV.type === Fragment) {\n const a = flattenChildren(oldV.children)\n const b = flattenChildren(newV.children)\n const len = Math.max(a.length, b.length)\n for (let i = 0; i < len; i++) {\n const c1 = a[i]\n const c2 = b[i]\n const valid1 = c1 != null && c1 !== false\n const valid2 = c2 != null && c2 !== false\n if (!valid1 && valid2) {\n mount(parent, c2 as typeof oldV)\n } else if (valid1 && !valid2) {\n unmount(c1 as typeof oldV)\n } else if (valid1 && valid2) {\n patchVNode(parent, c1 as typeof oldV, c2 as typeof oldV)\n }\n }\n return\n }\n\n if (typeof oldV.type === 'function' || typeof newV.type === 'function') {\n if (oldV.type === newV.type) {\n const ctx = (oldV as typeof oldV & { __ctx?: VDOMHookContext }).__ctx\n if (!ctx) {\n // No hook context — component was never properly mounted (e.g. VNode\n // came from a previous renderer that was torn down). Do a fresh mount\n // without trying to unmount the old VNode — its host nodes are already\n // gone (different renderer root).\n mount(parent, newV)\n return\n }\n\n if (newV.props !== undefined) ctx.componentVNode.props = newV.props\n if (newV.children !== undefined) ctx.componentVNode.children = newV.children\n const previousTheme = ctx.theme\n if (newV.__theme !== undefined) ctx.theme = newV.__theme as PartialTheme\n\n const newVNodeWithCtx = setVNodePropSafe(newV, '__ctx', ctx)\n const propsWithChildren = withChildrenProps(ctx.componentVNode)\n const themeChanged = !Object.is(previousTheme, ctx.theme)\n const propsChanged = shouldComponentUpdate(ctx, propsWithChildren)\n if (!themeChanged && !propsChanged) return\n\n ctx.surface = getHostContext(parent)\n let renderedNext = normalizeVNodeLike(\n withHooks(\n ctx,\n () => (newVNodeWithCtx.type as (props: unknown) => VNodeLike)(propsWithChildren),\n {\n isAlive: () => state.getHostAdapter().isAlive(parent),\n }\n ) as VNodeLike\n )\n\n if (!renderedNext) {\n ctx.vnode = renderedNext\n runEffects(ctx)\n return\n }\n\n if (ctx.theme && !renderedNext.__theme) {\n renderedNext = setVNodePropSafe(renderedNext, '__theme', ctx.theme)\n }\n\n patchVNode(parent, ctx.vnode, renderedNext)\n ctx.vnode = renderedNext\n runEffects(ctx)\n return\n }\n\n unmount(oldV)\n mount(parent, newV)\n return\n }\n\n if (oldV.type !== newV.type) {\n unmount(oldV)\n mount(parent, newV)\n return\n }\n\n const nodeType = oldV.type as NodeType\n newV = setVNodePropSafe(setVNodePropSafe(newV, '__node', oldV.__node), '__parent', parent)\n\n const oldRef = oldV.props?.ref as\n | { current: unknown | null }\n | ((value: unknown | null) => void)\n | undefined\n const newRef = newV.props?.ref as\n | { current: unknown | null }\n | ((value: unknown | null) => void)\n | undefined\n if (oldRef !== newRef) {\n attachRef(oldRef, null)\n attachRef(newRef, oldV.__node)\n }\n\n const { props: oldProps } = state.bridge.resolveProps(\n nodeType,\n oldV.__theme as PartialTheme | undefined,\n (oldV.props ?? {}) as Record<string, unknown>\n )\n const { props: newProps, nestedTheme } = state.bridge.resolveProps(\n nodeType,\n newV.__theme as PartialTheme | undefined,\n (newV.props ?? {}) as Record<string, unknown>\n )\n\n state.getHostAdapter().patch(nodeType, oldV.__node, oldProps, newProps, getHostContext(parent))\n\n const a = flattenChildren(oldV.children)\n const b = flattenChildren(newV.children)\n const len = Math.max(a.length, b.length)\n let childrenChanged = a.filter(Boolean).length !== b.filter(Boolean).length\n const containerLayoutChanged = hasLayoutPropsChanged(oldV, newV)\n\n for (let i = 0; i < len; i++) {\n const c1 = a[i]\n const c2 = b[i]\n const valid1 = c1 != null && c1 !== false\n const valid2 = c2 != null && c2 !== false\n\n if (!valid1 && valid2) {\n const themed = applyThemeToChild(\n c2 as typeof oldV,\n newV.__theme as PartialTheme | undefined,\n nestedTheme\n )\n b[i] = themed\n mount(oldV.__node, themed)\n childrenChanged = true\n } else if (valid1 && !valid2) {\n unmount(c1 as typeof oldV)\n childrenChanged = true\n } else if (valid1 && valid2) {\n const themed = applyThemeToChild(\n c2 as typeof oldV,\n newV.__theme as PartialTheme | undefined,\n nestedTheme\n )\n b[i] = themed\n\n const childLayoutChanged = hasLayoutPropsChanged(c1 as typeof oldV, themed)\n const textContentChanged =\n (c1 as typeof oldV).props?.text !== themed.props?.text ||\n !deepEqual((c1 as typeof oldV).props?.style, themed.props?.style)\n const previousChildSize = readVNodeLayoutSize(c1 as typeof oldV)\n\n patchVNode(oldV.__node, c1 as typeof oldV, themed)\n\n const nextChildSize = readVNodeLayoutSize(c1 as typeof oldV)\n const childSizeChanged =\n previousChildSize === null || nextChildSize === null\n ? false\n : Math.abs(previousChildSize.width - nextChildSize.width) >= 0.5 ||\n Math.abs(previousChildSize.height - nextChildSize.height) >= 0.5\n\n if (childLayoutChanged || textContentChanged || childSizeChanged) {\n childrenChanged = true\n }\n }\n }\n\n if (\n oldV.__node &&\n isLayoutContainer(oldV.__node) &&\n (containerLayoutChanged || childrenChanged)\n ) {\n recalculateLayout(oldV.__node, parent)\n }\n }\n\n return patchVNode\n}\n"],"names":["createRuntimeHelpers","isLayoutContainer","getLayoutParent","Fragment","a","flattenChildren","b","len","setVNodePropSafe","withChildrenProps","shouldComponentUpdate","normalizeVNodeLike","withHooks","attachRef","hasLayoutPropsChanged","applyThemeToChild","deepEqual","readVNodeLayoutSize"],"mappings":";;;;;;AAqBO,SAAS,iBACd,OACA,UACA,YACc;AACd,QAAM,EAAE,gBAAgB,mBAAmB,WAAA,IAAeA,eAAAA,qBAAqB,KAAK;AAEpF,QAAM,aAA2B,CAAC,QAAQ,MAAM,SAAS;AACvD,UAAM,QAAQ,SAAA;AACd,UAAM,UAAU,WAAA;AAEhB,QAAI,CAAC,QAAQ,CAAC,KAAM;AACpB,QAAI,CAAC,QAAQ,MAAM;AACjB,YAAM,QAAQ,IAAI;AAClB;AAAA,IACF;AACA,QAAI,QAAQ,CAAC,MAAM;AACjB,cAAQ,IAAI;AACZ;AAAA,IACF;AACA,QAAI,CAAC,QAAQ,CAAC,KAAM;AAEpB,QAAI,KAAK,UAAU,KAAK,OAAO;AAC7B,cAAQ,IAAI;AACZ,YAAM,QAAQ,IAAI;AAElB,UAAIC,wBAAkB,MAAM,KAAK,OAAO,eAAe;AACrD,0BAAkB,QAAQC,MAAAA,gBAAgB,MAAM,KAAK,MAAM;AAAA,MAC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,cAAM,mBACJ,sBAAsB,QAAQ,kBAAkB,OAC5C,QACA,KAAK,IAAI,kBAAkB,QAAQ,cAAc,KAAK,KAAK,OAC3D,KAAK,IAAI,kBAAkB,SAAS,cAAc,MAAM,KAAK;AAEnE,YAAI,sBAAsB,sBAAsB,kBAAkB;AAChE,4BAAkB;AAAA,QACpB;AAAA,MACF;AAAA,IACF;AAEA,QACE,KAAK,UACLhB,wBAAkB,KAAK,MAAM,MAC5B,0BAA0B,kBAC3B;AACA,wBAAkB,KAAK,QAAQ,MAAM;AAAA,IACvC;AAAA,EACF;AAEA,SAAO;AACT;;"}
@@ -0,0 +1,3 @@
1
+ import { MountFn, PatchVNodeFn, RuntimeState, UnmountFn } from './types';
2
+ export declare function createPatchVNode(state: RuntimeState, getMount: () => MountFn, getUnmount: () => UnmountFn): PatchVNodeFn;
3
+ //# sourceMappingURL=patch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patch.d.ts","sourceRoot":"","sources":["../../src/vdom/patch.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAmB,MAAM,SAAS,CAAA;AAe9F,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,MAAM,OAAO,EACvB,UAAU,EAAE,MAAM,SAAS,GAC1B,YAAY,CAyMd"}
@@ -0,0 +1,163 @@
1
+ import { shouldComponentUpdate, withHooks } from "../hooks.js";
2
+ import { Fragment } from "../jsx-runtime.js";
3
+ import { createRuntimeHelpers } from "./runtime-helpers.js";
4
+ import { isLayoutContainer, getLayoutParent, flattenChildren, setVNodePropSafe, withChildrenProps, normalizeVNodeLike, attachRef, hasLayoutPropsChanged, applyThemeToChild, deepEqual, readVNodeLayoutSize } from "./utils.js";
5
+ function createPatchVNode(state, getMount, getUnmount) {
6
+ const { getHostContext, recalculateLayout, runEffects } = createRuntimeHelpers(state);
7
+ const patchVNode = (parent, oldV, newV) => {
8
+ const mount = getMount();
9
+ const unmount = getUnmount();
10
+ if (!oldV && !newV) return;
11
+ if (!oldV && newV) {
12
+ mount(parent, newV);
13
+ return;
14
+ }
15
+ if (oldV && !newV) {
16
+ unmount(oldV);
17
+ return;
18
+ }
19
+ if (!oldV || !newV) return;
20
+ if (oldV.__key !== newV.__key) {
21
+ unmount(oldV);
22
+ mount(parent, newV);
23
+ if (isLayoutContainer(parent) && parent.__layoutProps) {
24
+ recalculateLayout(parent, getLayoutParent(parent) ?? parent);
25
+ }
26
+ return;
27
+ }
28
+ if (oldV.type === Fragment && newV.type === Fragment) {
29
+ const a2 = flattenChildren(oldV.children);
30
+ const b2 = flattenChildren(newV.children);
31
+ const len2 = Math.max(a2.length, b2.length);
32
+ for (let i = 0; i < len2; i++) {
33
+ const c1 = a2[i];
34
+ const c2 = b2[i];
35
+ const valid1 = c1 != null && c1 !== false;
36
+ const valid2 = c2 != null && c2 !== false;
37
+ if (!valid1 && valid2) {
38
+ mount(parent, c2);
39
+ } else if (valid1 && !valid2) {
40
+ unmount(c1);
41
+ } else if (valid1 && valid2) {
42
+ patchVNode(parent, c1, c2);
43
+ }
44
+ }
45
+ return;
46
+ }
47
+ if (typeof oldV.type === "function" || typeof newV.type === "function") {
48
+ if (oldV.type === newV.type) {
49
+ const ctx = oldV.__ctx;
50
+ if (!ctx) {
51
+ mount(parent, newV);
52
+ return;
53
+ }
54
+ if (newV.props !== void 0) ctx.componentVNode.props = newV.props;
55
+ if (newV.children !== void 0) ctx.componentVNode.children = newV.children;
56
+ const previousTheme = ctx.theme;
57
+ if (newV.__theme !== void 0) ctx.theme = newV.__theme;
58
+ const newVNodeWithCtx = setVNodePropSafe(newV, "__ctx", ctx);
59
+ const propsWithChildren = withChildrenProps(ctx.componentVNode);
60
+ const themeChanged = !Object.is(previousTheme, ctx.theme);
61
+ const propsChanged = shouldComponentUpdate(ctx, propsWithChildren);
62
+ if (!themeChanged && !propsChanged) return;
63
+ ctx.surface = getHostContext(parent);
64
+ let renderedNext = normalizeVNodeLike(
65
+ withHooks(
66
+ ctx,
67
+ () => newVNodeWithCtx.type(propsWithChildren),
68
+ {
69
+ isAlive: () => state.getHostAdapter().isAlive(parent)
70
+ }
71
+ )
72
+ );
73
+ if (!renderedNext) {
74
+ ctx.vnode = renderedNext;
75
+ runEffects(ctx);
76
+ return;
77
+ }
78
+ if (ctx.theme && !renderedNext.__theme) {
79
+ renderedNext = setVNodePropSafe(renderedNext, "__theme", ctx.theme);
80
+ }
81
+ patchVNode(parent, ctx.vnode, renderedNext);
82
+ ctx.vnode = renderedNext;
83
+ runEffects(ctx);
84
+ return;
85
+ }
86
+ unmount(oldV);
87
+ mount(parent, newV);
88
+ return;
89
+ }
90
+ if (oldV.type !== newV.type) {
91
+ unmount(oldV);
92
+ mount(parent, newV);
93
+ return;
94
+ }
95
+ const nodeType = oldV.type;
96
+ newV = setVNodePropSafe(setVNodePropSafe(newV, "__node", oldV.__node), "__parent", parent);
97
+ const oldRef = oldV.props?.ref;
98
+ const newRef = newV.props?.ref;
99
+ if (oldRef !== newRef) {
100
+ attachRef(oldRef, null);
101
+ attachRef(newRef, oldV.__node);
102
+ }
103
+ const { props: oldProps } = state.bridge.resolveProps(
104
+ nodeType,
105
+ oldV.__theme,
106
+ oldV.props ?? {}
107
+ );
108
+ const { props: newProps, nestedTheme } = state.bridge.resolveProps(
109
+ nodeType,
110
+ newV.__theme,
111
+ newV.props ?? {}
112
+ );
113
+ state.getHostAdapter().patch(nodeType, oldV.__node, oldProps, newProps, getHostContext(parent));
114
+ const a = flattenChildren(oldV.children);
115
+ const b = flattenChildren(newV.children);
116
+ const len = Math.max(a.length, b.length);
117
+ let childrenChanged = a.filter(Boolean).length !== b.filter(Boolean).length;
118
+ const containerLayoutChanged = hasLayoutPropsChanged(oldV, newV);
119
+ for (let i = 0; i < len; i++) {
120
+ const c1 = a[i];
121
+ const c2 = b[i];
122
+ const valid1 = c1 != null && c1 !== false;
123
+ const valid2 = c2 != null && c2 !== false;
124
+ if (!valid1 && valid2) {
125
+ const themed = applyThemeToChild(
126
+ c2,
127
+ newV.__theme,
128
+ nestedTheme
129
+ );
130
+ b[i] = themed;
131
+ mount(oldV.__node, themed);
132
+ childrenChanged = true;
133
+ } else if (valid1 && !valid2) {
134
+ unmount(c1);
135
+ childrenChanged = true;
136
+ } else if (valid1 && valid2) {
137
+ const themed = applyThemeToChild(
138
+ c2,
139
+ newV.__theme,
140
+ nestedTheme
141
+ );
142
+ b[i] = themed;
143
+ const childLayoutChanged = hasLayoutPropsChanged(c1, themed);
144
+ const textContentChanged = c1.props?.text !== themed.props?.text || !deepEqual(c1.props?.style, themed.props?.style);
145
+ const previousChildSize = readVNodeLayoutSize(c1);
146
+ patchVNode(oldV.__node, c1, themed);
147
+ const nextChildSize = readVNodeLayoutSize(c1);
148
+ const childSizeChanged = previousChildSize === null || nextChildSize === null ? false : Math.abs(previousChildSize.width - nextChildSize.width) >= 0.5 || Math.abs(previousChildSize.height - nextChildSize.height) >= 0.5;
149
+ if (childLayoutChanged || textContentChanged || childSizeChanged) {
150
+ childrenChanged = true;
151
+ }
152
+ }
153
+ }
154
+ if (oldV.__node && isLayoutContainer(oldV.__node) && (containerLayoutChanged || childrenChanged)) {
155
+ recalculateLayout(oldV.__node, parent);
156
+ }
157
+ };
158
+ return patchVNode;
159
+ }
160
+ export {
161
+ createPatchVNode
162
+ };
163
+ //# sourceMappingURL=patch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patch.js","sources":["../../src/vdom/patch.ts"],"sourcesContent":["import { shouldComponentUpdate, withHooks } from '../hooks'\nimport type { NodeType } from '../host-adapter'\nimport { Fragment } from '../jsx-runtime'\nimport type { PartialTheme } from '../theme'\nimport type { VNodeLike } from '../types'\nimport { createRuntimeHelpers } from './runtime-helpers'\nimport type { MountFn, PatchVNodeFn, RuntimeState, UnmountFn, VDOMHookContext } from './types'\nimport {\n applyThemeToChild,\n attachRef,\n deepEqual,\n flattenChildren,\n getLayoutParent,\n hasLayoutPropsChanged,\n isLayoutContainer,\n normalizeVNodeLike,\n readVNodeLayoutSize,\n setVNodePropSafe,\n withChildrenProps,\n} from './utils'\n\nexport function createPatchVNode(\n state: RuntimeState,\n getMount: () => MountFn,\n getUnmount: () => UnmountFn\n): PatchVNodeFn {\n const { getHostContext, recalculateLayout, runEffects } = createRuntimeHelpers(state)\n\n const patchVNode: PatchVNodeFn = (parent, oldV, newV) => {\n const mount = getMount()\n const unmount = getUnmount()\n\n if (!oldV && !newV) return\n if (!oldV && newV) {\n mount(parent, newV)\n return\n }\n if (oldV && !newV) {\n unmount(oldV)\n return\n }\n if (!oldV || !newV) return\n\n if (oldV.__key !== newV.__key) {\n unmount(oldV)\n mount(parent, newV)\n\n if (isLayoutContainer(parent) && parent.__layoutProps) {\n recalculateLayout(parent, getLayoutParent(parent) ?? parent)\n }\n return\n }\n\n if (oldV.type === Fragment && newV.type === Fragment) {\n const a = flattenChildren(oldV.children)\n const b = flattenChildren(newV.children)\n const len = Math.max(a.length, b.length)\n for (let i = 0; i < len; i++) {\n const c1 = a[i]\n const c2 = b[i]\n const valid1 = c1 != null && c1 !== false\n const valid2 = c2 != null && c2 !== false\n if (!valid1 && valid2) {\n mount(parent, c2 as typeof oldV)\n } else if (valid1 && !valid2) {\n unmount(c1 as typeof oldV)\n } else if (valid1 && valid2) {\n patchVNode(parent, c1 as typeof oldV, c2 as typeof oldV)\n }\n }\n return\n }\n\n if (typeof oldV.type === 'function' || typeof newV.type === 'function') {\n if (oldV.type === newV.type) {\n const ctx = (oldV as typeof oldV & { __ctx?: VDOMHookContext }).__ctx\n if (!ctx) {\n // No hook context — component was never properly mounted (e.g. VNode\n // came from a previous renderer that was torn down). Do a fresh mount\n // without trying to unmount the old VNode — its host nodes are already\n // gone (different renderer root).\n mount(parent, newV)\n return\n }\n\n if (newV.props !== undefined) ctx.componentVNode.props = newV.props\n if (newV.children !== undefined) ctx.componentVNode.children = newV.children\n const previousTheme = ctx.theme\n if (newV.__theme !== undefined) ctx.theme = newV.__theme as PartialTheme\n\n const newVNodeWithCtx = setVNodePropSafe(newV, '__ctx', ctx)\n const propsWithChildren = withChildrenProps(ctx.componentVNode)\n const themeChanged = !Object.is(previousTheme, ctx.theme)\n const propsChanged = shouldComponentUpdate(ctx, propsWithChildren)\n if (!themeChanged && !propsChanged) return\n\n ctx.surface = getHostContext(parent)\n let renderedNext = normalizeVNodeLike(\n withHooks(\n ctx,\n () => (newVNodeWithCtx.type as (props: unknown) => VNodeLike)(propsWithChildren),\n {\n isAlive: () => state.getHostAdapter().isAlive(parent),\n }\n ) as VNodeLike\n )\n\n if (!renderedNext) {\n ctx.vnode = renderedNext\n runEffects(ctx)\n return\n }\n\n if (ctx.theme && !renderedNext.__theme) {\n renderedNext = setVNodePropSafe(renderedNext, '__theme', ctx.theme)\n }\n\n patchVNode(parent, ctx.vnode, renderedNext)\n ctx.vnode = renderedNext\n runEffects(ctx)\n return\n }\n\n unmount(oldV)\n mount(parent, newV)\n return\n }\n\n if (oldV.type !== newV.type) {\n unmount(oldV)\n mount(parent, newV)\n return\n }\n\n const nodeType = oldV.type as NodeType\n newV = setVNodePropSafe(setVNodePropSafe(newV, '__node', oldV.__node), '__parent', parent)\n\n const oldRef = oldV.props?.ref as\n | { current: unknown | null }\n | ((value: unknown | null) => void)\n | undefined\n const newRef = newV.props?.ref as\n | { current: unknown | null }\n | ((value: unknown | null) => void)\n | undefined\n if (oldRef !== newRef) {\n attachRef(oldRef, null)\n attachRef(newRef, oldV.__node)\n }\n\n const { props: oldProps } = state.bridge.resolveProps(\n nodeType,\n oldV.__theme as PartialTheme | undefined,\n (oldV.props ?? {}) as Record<string, unknown>\n )\n const { props: newProps, nestedTheme } = state.bridge.resolveProps(\n nodeType,\n newV.__theme as PartialTheme | undefined,\n (newV.props ?? {}) as Record<string, unknown>\n )\n\n state.getHostAdapter().patch(nodeType, oldV.__node, oldProps, newProps, getHostContext(parent))\n\n const a = flattenChildren(oldV.children)\n const b = flattenChildren(newV.children)\n const len = Math.max(a.length, b.length)\n let childrenChanged = a.filter(Boolean).length !== b.filter(Boolean).length\n const containerLayoutChanged = hasLayoutPropsChanged(oldV, newV)\n\n for (let i = 0; i < len; i++) {\n const c1 = a[i]\n const c2 = b[i]\n const valid1 = c1 != null && c1 !== false\n const valid2 = c2 != null && c2 !== false\n\n if (!valid1 && valid2) {\n const themed = applyThemeToChild(\n c2 as typeof oldV,\n newV.__theme as PartialTheme | undefined,\n nestedTheme\n )\n b[i] = themed\n mount(oldV.__node, themed)\n childrenChanged = true\n } else if (valid1 && !valid2) {\n unmount(c1 as typeof oldV)\n childrenChanged = true\n } else if (valid1 && valid2) {\n const themed = applyThemeToChild(\n c2 as typeof oldV,\n newV.__theme as PartialTheme | undefined,\n nestedTheme\n )\n b[i] = themed\n\n const childLayoutChanged = hasLayoutPropsChanged(c1 as typeof oldV, themed)\n const textContentChanged =\n (c1 as typeof oldV).props?.text !== themed.props?.text ||\n !deepEqual((c1 as typeof oldV).props?.style, themed.props?.style)\n const previousChildSize = readVNodeLayoutSize(c1 as typeof oldV)\n\n patchVNode(oldV.__node, c1 as typeof oldV, themed)\n\n const nextChildSize = readVNodeLayoutSize(c1 as typeof oldV)\n const childSizeChanged =\n previousChildSize === null || nextChildSize === null\n ? false\n : Math.abs(previousChildSize.width - nextChildSize.width) >= 0.5 ||\n Math.abs(previousChildSize.height - nextChildSize.height) >= 0.5\n\n if (childLayoutChanged || textContentChanged || childSizeChanged) {\n childrenChanged = true\n }\n }\n }\n\n if (\n oldV.__node &&\n isLayoutContainer(oldV.__node) &&\n (containerLayoutChanged || childrenChanged)\n ) {\n recalculateLayout(oldV.__node, parent)\n }\n }\n\n return patchVNode\n}\n"],"names":["a","b","len"],"mappings":";;;;AAqBO,SAAS,iBACd,OACA,UACA,YACc;AACd,QAAM,EAAE,gBAAgB,mBAAmB,WAAA,IAAe,qBAAqB,KAAK;AAEpF,QAAM,aAA2B,CAAC,QAAQ,MAAM,SAAS;AACvD,UAAM,QA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B,sBAAsB,IAAmB,MAAM;AAC1E,cAAM,qBACH,GAAmB,OAAO,SAAS,OAAO,OAAO,QAClD,CAAC,UAAW,GAAmB,OAAO,OAAO,OAAO,OAAO,KAAK;AAClE,cAAM,oBAAoB,oBAAoB,EAAiB;AAE/D,mBAAW,KAAK,QAAQ,IAAmB,MAAM;AAEjD,cAAM,gBAAgB,oBAAoB,EAAiB;AAC3D,cAAM,mBACJ,sBAAsB,QAAQ,kBAAkB,OAC5C,QACA,KAAK,IAAI,kBAAkB,QAAQ,cAAc,KAAK,KAAK,OAC3D,KAAK,IAAI,kBAAkB,SAAS,cAAc,MAAM,KAAK;AAEnE,YAAI,sBAAsB,sBAAsB,kBAAkB;AAChE,4BAAkB;AAAA,QACpB;AAAA,MACF;AAAA,IACF;AAEA,QACE,KAAK,UACL,kBAAkB,KAAK,MAAM,MAC5B,0BAA0B,kBAC3B;AACA,wBAAkB,KAAK,QAAQ,MAAM;AAAA,IACvC;AAAA,EACF;AAEA,SAAO;AACT;"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const utils = require("./utils.cjs");
4
+ class MountRegistry {
5
+ entries = /* @__PURE__ */ new Map();
6
+ nextId = 1;
7
+ nodeIds = /* @__PURE__ */ new WeakMap();
8
+ register(entry) {
9
+ const id = this.nextId++;
10
+ this.entries.set(id, { id, ...entry });
11
+ if (utils.isObjectKey(entry.rootNode)) {
12
+ this.nodeIds.set(entry.rootNode, id);
13
+ }
14
+ return id;
15
+ }
16
+ unregister(id) {
17
+ const entry = this.entries.get(id);
18
+ if (!entry) return;
19
+ if (utils.isObjectKey(entry.rootNode)) {
20
+ this.nodeIds.delete(entry.rootNode);
21
+ }
22
+ this.entries.delete(id);
23
+ }
24
+ getEntry(id) {
25
+ return this.entries.get(id);
26
+ }
27
+ getEntryByNode(node) {
28
+ if (!utils.isObjectKey(node)) return void 0;
29
+ const id = this.nodeIds.get(node);
30
+ return id !== void 0 ? this.entries.get(id) : void 0;
31
+ }
32
+ findByParentAndKey(parent, key, isAlive) {
33
+ for (const entry of this.entries.values()) {
34
+ if (!isAlive(entry.parent) || !isAlive(entry.rootNode)) {
35
+ this.unregister(entry.id);
36
+ continue;
37
+ }
38
+ const entryKey = entry.props.key;
39
+ if (key !== void 0) {
40
+ if (entry.parent === parent && entryKey === key) return entry;
41
+ } else if (entry.parent === parent) {
42
+ return entry;
43
+ }
44
+ }
45
+ return void 0;
46
+ }
47
+ getAllEntries() {
48
+ return Array.from(this.entries.values());
49
+ }
50
+ clear() {
51
+ this.entries.clear();
52
+ this.nodeIds = /* @__PURE__ */ new WeakMap();
53
+ this.nextId = 1;
54
+ }
55
+ getStats(hostAdapter) {
56
+ const byType = /* @__PURE__ */ new Map();
57
+ const byParent = /* @__PURE__ */ new Map();
58
+ const byKey = /* @__PURE__ */ new Map();
59
+ const mounts = [];
60
+ for (const entry of this.entries.values()) {
61
+ const typeName = typeof entry.type === "string" ? entry.type : entry.type.name || "Component";
62
+ byType.set(typeName, (byType.get(typeName) ?? 0) + 1);
63
+ byParent.set(entry.parent, (byParent.get(entry.parent) ?? 0) + 1);
64
+ if (entry.props.key) {
65
+ byKey.set(entry.props.key, (byKey.get(entry.props.key) ?? 0) + 1);
66
+ }
67
+ mounts.push({
68
+ id: entry.id,
69
+ type: typeName,
70
+ ...entry.props.key !== void 0 ? { key: entry.props.key } : {},
71
+ parentType: entry.surface ? "RootSurface" : hostAdapter.isSurface?.(entry.parent) ? "Surface" : "Container",
72
+ propsKeys: Object.keys(entry.props)
73
+ });
74
+ }
75
+ return {
76
+ totalMounts: this.entries.size,
77
+ byType,
78
+ byParent,
79
+ byKey,
80
+ mounts
81
+ };
82
+ }
83
+ }
84
+ exports.MountRegistry = MountRegistry;
85
+ //# sourceMappingURL=registry.cjs.map