@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.
- package/LICENSE +667 -0
- package/README.md +38 -0
- package/dist/animation/animated-signal.cjs +19 -0
- package/dist/animation/animated-signal.cjs.map +1 -0
- package/dist/animation/animated-signal.d.ts +35 -0
- package/dist/animation/animated-signal.d.ts.map +1 -0
- package/dist/animation/animated-signal.js +19 -0
- package/dist/animation/animated-signal.js.map +1 -0
- package/dist/animation/create-spring.cjs +80 -0
- package/dist/animation/create-spring.cjs.map +1 -0
- package/dist/animation/create-spring.d.ts +56 -0
- package/dist/animation/create-spring.d.ts.map +1 -0
- package/dist/animation/create-spring.js +80 -0
- package/dist/animation/create-spring.js.map +1 -0
- package/dist/animation/easing.cjs +76 -0
- package/dist/animation/easing.cjs.map +1 -0
- package/dist/animation/easing.d.ts +45 -0
- package/dist/animation/easing.d.ts.map +1 -0
- package/dist/animation/easing.js +76 -0
- package/dist/animation/easing.js.map +1 -0
- package/dist/animation/effect-definitions.cjs +441 -0
- package/dist/animation/effect-definitions.cjs.map +1 -0
- package/dist/animation/effect-definitions.d.ts +60 -0
- package/dist/animation/effect-definitions.d.ts.map +1 -0
- package/dist/animation/effect-definitions.js +441 -0
- package/dist/animation/effect-definitions.js.map +1 -0
- package/dist/animation/effect-engine.cjs +189 -0
- package/dist/animation/effect-engine.cjs.map +1 -0
- package/dist/animation/effect-engine.d.ts +70 -0
- package/dist/animation/effect-engine.d.ts.map +1 -0
- package/dist/animation/effect-engine.js +189 -0
- package/dist/animation/effect-engine.js.map +1 -0
- package/dist/animation/index.d.ts +24 -0
- package/dist/animation/index.d.ts.map +1 -0
- package/dist/animation/spring-physics.cjs +94 -0
- package/dist/animation/spring-physics.cjs.map +1 -0
- package/dist/animation/spring-physics.d.ts +145 -0
- package/dist/animation/spring-physics.d.ts.map +1 -0
- package/dist/animation/spring-physics.js +94 -0
- package/dist/animation/spring-physics.js.map +1 -0
- package/dist/animation/tween.cjs +67 -0
- package/dist/animation/tween.cjs.map +1 -0
- package/dist/animation/tween.d.ts +60 -0
- package/dist/animation/tween.d.ts.map +1 -0
- package/dist/animation/tween.js +67 -0
- package/dist/animation/tween.js.map +1 -0
- package/dist/animation/types.d.ts +31 -0
- package/dist/animation/types.d.ts.map +1 -0
- package/dist/animation/useSpring.cjs +152 -0
- package/dist/animation/useSpring.cjs.map +1 -0
- package/dist/animation/useSpring.d.ts +55 -0
- package/dist/animation/useSpring.d.ts.map +1 -0
- package/dist/animation/useSpring.js +149 -0
- package/dist/animation/useSpring.js.map +1 -0
- package/dist/animation/useTween.cjs +208 -0
- package/dist/animation/useTween.cjs.map +1 -0
- package/dist/animation/useTween.d.ts +116 -0
- package/dist/animation/useTween.d.ts.map +1 -0
- package/dist/animation/useTween.js +208 -0
- package/dist/animation/useTween.js.map +1 -0
- package/dist/border-geometry.cjs +447 -0
- package/dist/border-geometry.cjs.map +1 -0
- package/dist/border-geometry.d.ts +114 -0
- package/dist/border-geometry.d.ts.map +1 -0
- package/dist/border-geometry.js +447 -0
- package/dist/border-geometry.js.map +1 -0
- package/dist/colors/color-presets.cjs +236 -0
- package/dist/colors/color-presets.cjs.map +1 -0
- package/dist/colors/color-presets.d.ts +89 -0
- package/dist/colors/color-presets.d.ts.map +1 -0
- package/dist/colors/color-presets.js +236 -0
- package/dist/colors/color-presets.js.map +1 -0
- package/dist/colors/color-theme-helpers.cjs +32 -0
- package/dist/colors/color-theme-helpers.cjs.map +1 -0
- package/dist/colors/color-theme-helpers.d.ts +65 -0
- package/dist/colors/color-theme-helpers.d.ts.map +1 -0
- package/dist/colors/color-theme-helpers.js +32 -0
- package/dist/colors/color-theme-helpers.js.map +1 -0
- package/dist/colors/color-types.cjs +38 -0
- package/dist/colors/color-types.cjs.map +1 -0
- package/dist/colors/color-types.d.ts +112 -0
- package/dist/colors/color-types.d.ts.map +1 -0
- package/dist/colors/color-types.js +38 -0
- package/dist/colors/color-types.js.map +1 -0
- package/dist/colors/color-utils.cjs +197 -0
- package/dist/colors/color-utils.cjs.map +1 -0
- package/dist/colors/color-utils.d.ts +216 -0
- package/dist/colors/color-utils.d.ts.map +1 -0
- package/dist/colors/color-utils.js +197 -0
- package/dist/colors/color-utils.js.map +1 -0
- package/dist/colors/contrast-contracts.cjs +265 -0
- package/dist/colors/contrast-contracts.cjs.map +1 -0
- package/dist/colors/contrast-contracts.d.ts +289 -0
- package/dist/colors/contrast-contracts.d.ts.map +1 -0
- package/dist/colors/contrast-contracts.js +265 -0
- package/dist/colors/contrast-contracts.js.map +1 -0
- package/dist/colors/index.cjs +55 -0
- package/dist/colors/index.cjs.map +1 -0
- package/dist/colors/index.d.ts +16 -0
- package/dist/colors/index.d.ts.map +1 -0
- package/dist/colors/index.js +55 -0
- package/dist/colors/index.js.map +1 -0
- package/dist/core-props.cjs +66 -0
- package/dist/core-props.cjs.map +1 -0
- package/dist/core-props.d.ts +395 -0
- package/dist/core-props.d.ts.map +1 -0
- package/dist/core-props.js +66 -0
- package/dist/core-props.js.map +1 -0
- package/dist/design-tokens/design-token-presets.cjs +91 -0
- package/dist/design-tokens/design-token-presets.cjs.map +1 -0
- package/dist/design-tokens/design-token-presets.d.ts +34 -0
- package/dist/design-tokens/design-token-presets.d.ts.map +1 -0
- package/dist/design-tokens/design-token-presets.js +91 -0
- package/dist/design-tokens/design-token-presets.js.map +1 -0
- package/dist/design-tokens/design-token-types.d.ts +97 -0
- package/dist/design-tokens/design-token-types.d.ts.map +1 -0
- package/dist/design-tokens/index.cjs +10 -0
- package/dist/design-tokens/index.cjs.map +1 -0
- package/dist/design-tokens/index.d.ts +9 -0
- package/dist/design-tokens/index.d.ts.map +1 -0
- package/dist/design-tokens/index.js +10 -0
- package/dist/design-tokens/index.js.map +1 -0
- package/dist/dev-config.cjs +296 -0
- package/dist/dev-config.cjs.map +1 -0
- package/dist/dev-config.d.ts +238 -0
- package/dist/dev-config.d.ts.map +1 -0
- package/dist/dev-config.js +296 -0
- package/dist/dev-config.js.map +1 -0
- package/dist/effects.cjs +69 -0
- package/dist/effects.cjs.map +1 -0
- package/dist/effects.d.ts +152 -0
- package/dist/effects.d.ts.map +1 -0
- package/dist/effects.js +69 -0
- package/dist/effects.js.map +1 -0
- package/dist/global-registry.cjs +25 -0
- package/dist/global-registry.cjs.map +1 -0
- package/dist/global-registry.d.ts +19 -0
- package/dist/global-registry.d.ts.map +1 -0
- package/dist/global-registry.js +25 -0
- package/dist/global-registry.js.map +1 -0
- package/dist/hooks.cjs +378 -0
- package/dist/hooks.cjs.map +1 -0
- package/dist/hooks.d.ts +322 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +378 -0
- package/dist/hooks.js.map +1 -0
- package/dist/host-adapter.d.ts +414 -0
- package/dist/host-adapter.d.ts.map +1 -0
- package/dist/index.cjs +229 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +226 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-dev-runtime.cjs +10 -0
- package/dist/jsx-dev-runtime.cjs.map +1 -0
- package/dist/jsx-dev-runtime.d.ts +5 -0
- package/dist/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx-dev-runtime.js +11 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-runtime.cjs +44 -0
- package/dist/jsx-runtime.cjs.map +1 -0
- package/dist/jsx-runtime.d.ts +24 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +44 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/jsx-types.d.ts +25 -0
- package/dist/jsx-types.d.ts.map +1 -0
- package/dist/layout/appliers/container-applier.cjs +20 -0
- package/dist/layout/appliers/container-applier.cjs.map +1 -0
- package/dist/layout/appliers/container-applier.d.ts +9 -0
- package/dist/layout/appliers/container-applier.d.ts.map +1 -0
- package/dist/layout/appliers/container-applier.js +20 -0
- package/dist/layout/appliers/container-applier.js.map +1 -0
- package/dist/layout/appliers/position-applier.cjs +31 -0
- package/dist/layout/appliers/position-applier.cjs.map +1 -0
- package/dist/layout/appliers/position-applier.d.ts +8 -0
- package/dist/layout/appliers/position-applier.d.ts.map +1 -0
- package/dist/layout/appliers/position-applier.js +31 -0
- package/dist/layout/appliers/position-applier.js.map +1 -0
- package/dist/layout/layout-engine-test-utils.d.ts +26 -0
- package/dist/layout/layout-engine-test-utils.d.ts.map +1 -0
- package/dist/layout/layout-engine.cjs +628 -0
- package/dist/layout/layout-engine.cjs.map +1 -0
- package/dist/layout/layout-engine.d.ts +140 -0
- package/dist/layout/layout-engine.d.ts.map +1 -0
- package/dist/layout/layout-engine.js +628 -0
- package/dist/layout/layout-engine.js.map +1 -0
- package/dist/layout/strategies/base-strategy.cjs +31 -0
- package/dist/layout/strategies/base-strategy.cjs.map +1 -0
- package/dist/layout/strategies/base-strategy.d.ts +59 -0
- package/dist/layout/strategies/base-strategy.d.ts.map +1 -0
- package/dist/layout/strategies/base-strategy.js +31 -0
- package/dist/layout/strategies/base-strategy.js.map +1 -0
- package/dist/layout/strategies/column-layout.cjs +145 -0
- package/dist/layout/strategies/column-layout.cjs.map +1 -0
- package/dist/layout/strategies/column-layout.d.ts +38 -0
- package/dist/layout/strategies/column-layout.d.ts.map +1 -0
- package/dist/layout/strategies/column-layout.js +145 -0
- package/dist/layout/strategies/column-layout.js.map +1 -0
- package/dist/layout/strategies/row-layout.cjs +145 -0
- package/dist/layout/strategies/row-layout.cjs.map +1 -0
- package/dist/layout/strategies/row-layout.d.ts +38 -0
- package/dist/layout/strategies/row-layout.d.ts.map +1 -0
- package/dist/layout/strategies/row-layout.js +145 -0
- package/dist/layout/strategies/row-layout.js.map +1 -0
- package/dist/layout/strategies/stack-layout.cjs +94 -0
- package/dist/layout/strategies/stack-layout.cjs.map +1 -0
- package/dist/layout/strategies/stack-layout.d.ts +30 -0
- package/dist/layout/strategies/stack-layout.d.ts.map +1 -0
- package/dist/layout/strategies/stack-layout.js +94 -0
- package/dist/layout/strategies/stack-layout.js.map +1 -0
- package/dist/layout/types.d.ts +134 -0
- package/dist/layout/types.d.ts.map +1 -0
- package/dist/layout/utils/child-utils.cjs +129 -0
- package/dist/layout/utils/child-utils.cjs.map +1 -0
- package/dist/layout/utils/child-utils.d.ts +54 -0
- package/dist/layout/utils/child-utils.d.ts.map +1 -0
- package/dist/layout/utils/child-utils.js +129 -0
- package/dist/layout/utils/child-utils.js.map +1 -0
- package/dist/layout/utils/dimension-calculator.cjs +109 -0
- package/dist/layout/utils/dimension-calculator.cjs.map +1 -0
- package/dist/layout/utils/dimension-calculator.d.ts +59 -0
- package/dist/layout/utils/dimension-calculator.d.ts.map +1 -0
- package/dist/layout/utils/dimension-calculator.js +109 -0
- package/dist/layout/utils/dimension-calculator.js.map +1 -0
- package/dist/layout/utils/flex-distributor.cjs +173 -0
- package/dist/layout/utils/flex-distributor.cjs.map +1 -0
- package/dist/layout/utils/flex-distributor.d.ts +18 -0
- package/dist/layout/utils/flex-distributor.d.ts.map +1 -0
- package/dist/layout/utils/flex-distributor.js +173 -0
- package/dist/layout/utils/flex-distributor.js.map +1 -0
- package/dist/layout/utils/size-resolver.cjs +280 -0
- package/dist/layout/utils/size-resolver.cjs.map +1 -0
- package/dist/layout/utils/size-resolver.d.ts +84 -0
- package/dist/layout/utils/size-resolver.d.ts.map +1 -0
- package/dist/layout/utils/size-resolver.js +280 -0
- package/dist/layout/utils/size-resolver.js.map +1 -0
- package/dist/layout/utils/spacing-calculator.cjs +50 -0
- package/dist/layout/utils/spacing-calculator.cjs.map +1 -0
- package/dist/layout/utils/spacing-calculator.d.ts +27 -0
- package/dist/layout/utils/spacing-calculator.d.ts.map +1 -0
- package/dist/layout/utils/spacing-calculator.js +50 -0
- package/dist/layout/utils/spacing-calculator.js.map +1 -0
- package/dist/memo.cjs +18 -0
- package/dist/memo.cjs.map +1 -0
- package/dist/memo.d.ts +29 -0
- package/dist/memo.d.ts.map +1 -0
- package/dist/memo.js +18 -0
- package/dist/memo.js.map +1 -0
- package/dist/nineslice-contract.cjs +60 -0
- package/dist/nineslice-contract.cjs.map +1 -0
- package/dist/nineslice-contract.d.ts +107 -0
- package/dist/nineslice-contract.d.ts.map +1 -0
- package/dist/nineslice-contract.js +60 -0
- package/dist/nineslice-contract.js.map +1 -0
- package/dist/placeholder.cjs +12 -0
- package/dist/placeholder.cjs.map +1 -0
- package/dist/placeholder.d.ts +44 -0
- package/dist/placeholder.d.ts.map +1 -0
- package/dist/placeholder.js +12 -0
- package/dist/placeholder.js.map +1 -0
- package/dist/portal.cjs +89 -0
- package/dist/portal.cjs.map +1 -0
- package/dist/portal.d.ts +62 -0
- package/dist/portal.d.ts.map +1 -0
- package/dist/portal.js +89 -0
- package/dist/portal.js.map +1 -0
- package/dist/primitive-contracts.cjs +12 -0
- package/dist/primitive-contracts.cjs.map +1 -0
- package/dist/primitive-contracts.d.ts +186 -0
- package/dist/primitive-contracts.d.ts.map +1 -0
- package/dist/primitive-contracts.js +12 -0
- package/dist/primitive-contracts.js.map +1 -0
- package/dist/theme.cjs +332 -0
- package/dist/theme.cjs.map +1 -0
- package/dist/theme.d.ts +204 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +332 -0
- package/dist/theme.js.map +1 -0
- package/dist/types.d.ts +86 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/vdom/create-runtime.cjs +79 -0
- package/dist/vdom/create-runtime.cjs.map +1 -0
- package/dist/vdom/create-runtime.d.ts +7 -0
- package/dist/vdom/create-runtime.d.ts.map +1 -0
- package/dist/vdom/create-runtime.js +79 -0
- package/dist/vdom/create-runtime.js.map +1 -0
- package/dist/vdom/index.cjs +8 -0
- package/dist/vdom/index.cjs.map +1 -0
- package/dist/vdom/index.d.ts +4 -0
- package/dist/vdom/index.d.ts.map +1 -0
- package/dist/vdom/index.js +8 -0
- package/dist/vdom/index.js.map +1 -0
- package/dist/vdom/mount.cjs +161 -0
- package/dist/vdom/mount.cjs.map +1 -0
- package/dist/vdom/mount.d.ts +6 -0
- package/dist/vdom/mount.d.ts.map +1 -0
- package/dist/vdom/mount.js +161 -0
- package/dist/vdom/mount.js.map +1 -0
- package/dist/vdom/patch.cjs +163 -0
- package/dist/vdom/patch.cjs.map +1 -0
- package/dist/vdom/patch.d.ts +3 -0
- package/dist/vdom/patch.d.ts.map +1 -0
- package/dist/vdom/patch.js +163 -0
- package/dist/vdom/patch.js.map +1 -0
- package/dist/vdom/registry.cjs +85 -0
- package/dist/vdom/registry.cjs.map +1 -0
- package/dist/vdom/registry.d.ts +28 -0
- package/dist/vdom/registry.d.ts.map +1 -0
- package/dist/vdom/registry.js +85 -0
- package/dist/vdom/registry.js.map +1 -0
- package/dist/vdom/runtime-helpers.cjs +23 -0
- package/dist/vdom/runtime-helpers.cjs.map +1 -0
- package/dist/vdom/runtime-helpers.d.ts +8 -0
- package/dist/vdom/runtime-helpers.d.ts.map +1 -0
- package/dist/vdom/runtime-helpers.js +23 -0
- package/dist/vdom/runtime-helpers.js.map +1 -0
- package/dist/vdom/surface.cjs +107 -0
- package/dist/vdom/surface.cjs.map +1 -0
- package/dist/vdom/surface.d.ts +9 -0
- package/dist/vdom/surface.d.ts.map +1 -0
- package/dist/vdom/surface.js +107 -0
- package/dist/vdom/surface.js.map +1 -0
- package/dist/vdom/types.d.ts +104 -0
- package/dist/vdom/types.d.ts.map +1 -0
- package/dist/vdom/utils.cjs +146 -0
- package/dist/vdom/utils.cjs.map +1 -0
- package/dist/vdom/utils.d.ts +24 -0
- package/dist/vdom/utils.d.ts.map +1 -0
- package/dist/vdom/utils.js +146 -0
- package/dist/vdom/utils.js.map +1 -0
- package/dist/vdom.d.ts +4 -0
- package/dist/vdom.d.ts.map +1 -0
- package/dist/vector-draw-context.d.ts +63 -0
- package/dist/vector-draw-context.d.ts.map +1 -0
- package/package.json +161 -0
- package/vdom/index.cjs +1 -0
- package/vdom/index.d.ts +1 -0
- 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,Y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,YAAM,MAAO,MAAqD;AAClE,UAAI,KAAK;AACP,mBAAW,GAAG;AACd,eAAQ,MAAqD;AAAA,MAC/D;AACA,UAAI,KAAK,MAAO,SAAQ,IAAI,KAAK;AACjC;AAAA,IACF;AAEA;AAAA,MACE,MAAM,OAAO;AAAA,MAIb;AAAA,IAAA;AAGF,oBAAgB,MAAM,QAAQ,EAAE,QAAQ,OAAO;AAE/C,UAAM,OAAO,MAAM;AACnB,QAAI,MAAM;AACR,YAAM,SAAS,MAAM;AACrB,UACE,UACA,MAAM,eAAA,EAAiB,QAAQ,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,IA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AE,CAAC,IAAI;AAEP,cAAM,qBAAqBD,MAAAA,sBAAsB,IAAmB,MAAM;AAC1E,cAAM,qBACH,GAAmB,OAAO,SAAS,OAAO,OAAO,QAClD,CAACE,MAAAA,UAAW,GAAmB,OAAO,OAAO,OAAO,OAAO,KAAK;AAClE,cAAM,oBAAoBC,MAAAA,oBAAoB,EAAiB;AAE/D,mBAAW,KAAK,QAAQ,IAAmB,MAAM;AAEjD,cAAM,gBAAgBA,MAAAA,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,UACLhB,wBAAkB,KAAK,MAAM,MAC5B,0BAA0B,kBAC3B;AACA,wBAAkB,KAAK,QAAQ,MAAM;AAAA,IACvC;AAAA,EACF;AAEA,SAAO;AACT;;"}
|
|
@@ -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,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UAAU,QAAQ;AAC3B,cAAM,SAAS;AAAA,UACb;AAAA,UACA,KAAK;AAAA,UACL;AAAA,QAAA;AAEF,UAAE,CAAC,IAAI;AAEP,cAAM,qBAAqB,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
|