embedded-react 0.20.0 → 0.22.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 (140) hide show
  1. package/NOTICE +5 -0
  2. package/README.md +3 -2
  3. package/aot/app-file-loader.mjs +116 -0
  4. package/aot/compile.mjs +17 -47
  5. package/aot/compiler/alerts.mjs +604 -0
  6. package/aot/compiler/animations.mjs +299 -57
  7. package/aot/compiler/boot.mjs +27 -2
  8. package/aot/compiler/check.mjs +62 -10
  9. package/aot/compiler/collect.mjs +517 -137
  10. package/aot/compiler/contexts.mjs +391 -0
  11. package/aot/compiler/control-flow.mjs +276 -117
  12. package/aot/compiler/custom-hooks.mjs +686 -0
  13. package/aot/compiler/elements/button.mjs +182 -0
  14. package/aot/compiler/elements/image-background.mjs +76 -0
  15. package/aot/compiler/elements/image.mjs +2 -1
  16. package/aot/compiler/elements/props.mjs +47 -8
  17. package/aot/compiler/elements/rewrite.mjs +118 -0
  18. package/aot/compiler/elements/section-list.mjs +370 -0
  19. package/aot/compiler/expressions.mjs +1378 -97
  20. package/aot/compiler/handlers.mjs +1807 -354
  21. package/aot/compiler/helper-values.mjs +312 -0
  22. package/aot/compiler/ir/nodes.mjs +40 -1
  23. package/aot/compiler/ir/reads.mjs +206 -5
  24. package/aot/compiler/ir/text.mjs +5 -1
  25. package/aot/compiler/ir/types.mjs +12 -0
  26. package/aot/compiler/kept-states.mjs +177 -0
  27. package/aot/compiler/keyboard-dismiss.mjs +99 -0
  28. package/aot/compiler/keyboard.mjs +1 -1
  29. package/aot/compiler/list-items.mjs +226 -0
  30. package/aot/compiler/list-order.mjs +586 -0
  31. package/aot/compiler/list-split.mjs +259 -0
  32. package/aot/compiler/loops.mjs +582 -0
  33. package/aot/compiler/lower.mjs +203 -53
  34. package/aot/compiler/native-files.mjs +439 -0
  35. package/aot/compiler/native-header.mjs +335 -0
  36. package/aot/compiler/native-modules.mjs +1173 -0
  37. package/aot/compiler/nodes.mjs +45 -31
  38. package/aot/compiler/options.mjs +3 -2
  39. package/aot/compiler/out.mjs +18 -1
  40. package/aot/compiler/package/animations.mjs +133 -23
  41. package/aot/compiler/package/assemble.mjs +2 -4
  42. package/aot/compiler/package/bytecode.mjs +37 -8
  43. package/aot/compiler/package/checks.mjs +4 -0
  44. package/aot/compiler/package/codegen.mjs +906 -33
  45. package/aot/compiler/package/enums.mjs +10 -0
  46. package/aot/compiler/package/format.mjs +16 -3
  47. package/aot/compiler/package/lower.mjs +707 -176
  48. package/aot/compiler/package/string-caps.mjs +515 -0
  49. package/aot/compiler/package/tables.mjs +24 -0
  50. package/aot/compiler/package/writer.mjs +22 -0
  51. package/aot/compiler/parse.mjs +3 -1
  52. package/aot/compiler/record-shapes.mjs +246 -0
  53. package/aot/compiler/records.mjs +654 -0
  54. package/aot/compiler/reducers.mjs +272 -0
  55. package/aot/compiler/scroll-to.mjs +112 -0
  56. package/aot/compiler/static-eval.mjs +315 -7
  57. package/aot/compiler/style-text.mjs +20 -5
  58. package/aot/compiler/svg.mjs +13 -7
  59. package/aot/compiler/switch-cases.mjs +198 -0
  60. package/aot/compiler/tagged-records.mjs +450 -0
  61. package/aot/compiler/typing.mjs +307 -0
  62. package/aot/compiler/updaters.mjs +321 -0
  63. package/aot/compiler/window-dimensions.mjs +94 -0
  64. package/aot/compiler/worked-values.mjs +319 -0
  65. package/aot/demo-file.mjs +30 -0
  66. package/aot/style-map.mjs +94 -3
  67. package/assets/bake-font.mjs +187 -244
  68. package/assets/bake-image.mjs +47 -71
  69. package/assets/bake-svg.mjs +465 -533
  70. package/assets/build-builtin-font.mjs +14 -27
  71. package/assets/emit-c.mjs +124 -204
  72. package/assets/emit-container.mjs +129 -197
  73. package/assets/emit-pack.mjs +92 -136
  74. package/assets/font-config.mjs +19 -27
  75. package/assets/font-sizes.mjs +432 -507
  76. package/assets/glyph-coverage.mjs +170 -214
  77. package/assets/index.mjs +52 -97
  78. package/assets/rasterize.mjs +173 -194
  79. package/assets/svg-loader.mjs +42 -48
  80. package/build.mjs +85 -94
  81. package/cli.mjs +490 -586
  82. package/compile-bin.mjs +24 -36
  83. package/flash.mjs +297 -401
  84. package/hotreload/dev-device.mjs +229 -270
  85. package/hotreload/pack-app.mjs +118 -159
  86. package/hotreload/pack-split.mjs +146 -213
  87. package/hotreload/package-transfer.mjs +128 -131
  88. package/hotreload/protocol.mjs +118 -118
  89. package/hotreload/uploader.mjs +132 -159
  90. package/hotreload/watch-tree.mjs +56 -65
  91. package/pack-container.mjs +94 -116
  92. package/package.json +19 -16
  93. package/persist-transform.mjs +89 -105
  94. package/qjsc-wasm.mjs +47 -72
  95. package/sim/embedded-react.wasm +0 -0
  96. package/sim/index.html +1 -1
  97. package/sim-server.mjs +260 -354
  98. package/src/embedded-react/Alert.mjs +112 -0
  99. package/src/embedded-react/Animated.mjs +412 -0
  100. package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
  101. package/src/embedded-react/{Button.js → Button.mjs} +29 -53
  102. package/src/embedded-react/Dimensions.mjs +32 -0
  103. package/src/embedded-react/Easing.mjs +34 -0
  104. package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
  105. package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
  106. package/src/embedded-react/Keyboard.mjs +82 -0
  107. package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
  108. package/src/embedded-react/PanResponder.mjs +256 -0
  109. package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
  110. package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
  111. package/src/embedded-react/SectionList.mjs +103 -0
  112. package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
  113. package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
  114. package/src/embedded-react/background-image.mjs +321 -0
  115. package/src/embedded-react/{components.js → components.mjs} +1 -3
  116. package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
  117. package/src/embedded-react/index.d.ts +238 -5
  118. package/src/embedded-react/index.js +26 -17
  119. package/src/embedded-react/layout-anim-config.mjs +85 -0
  120. package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
  121. package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
  122. package/src/embedded-react/nativeModule.mjs +371 -0
  123. package/src/embedded-react/split-style.mjs +57 -0
  124. package/src/embedded-react/svg-ops.mjs +1075 -0
  125. package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
  126. package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
  127. package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
  128. package/src/host-config.mjs +512 -0
  129. package/src/{native-ui.js → native-ui.mjs} +1 -8
  130. package/src/props.mjs +341 -0
  131. package/src/{renderer.js → renderer.mjs} +30 -44
  132. package/src/embedded-react/Animated.js +0 -440
  133. package/src/embedded-react/Easing.js +0 -39
  134. package/src/embedded-react/PanResponder.js +0 -330
  135. package/src/embedded-react/SectionList.js +0 -148
  136. package/src/embedded-react/layout-anim-config.js +0 -101
  137. package/src/embedded-react/split-style.js +0 -58
  138. package/src/embedded-react/svg-ops.js +0 -1295
  139. package/src/host-config.js +0 -548
  140. package/src/props.js +0 -306
@@ -1,548 +0,0 @@
1
- /*
2
- * Copyright 2026 Cory Lamming
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- import {DefaultEventPriority} from 'react-reconciler/constants';
18
- import {NativeUI} from './native-ui.js';
19
- import {
20
- buildProps,
21
- buildTextSpans,
22
- deepEqualProps,
23
- isEventProp,
24
- isTextContent,
25
- } from './props.js';
26
- import {
27
- flattenSvg,
28
- PAINT_PROPS,
29
- warnVectorCaps,
30
- scaleVectorArtifact,
31
- encodeVectorGradients,
32
- } from './embedded-react/svg-ops.js';
33
- import {splitAnimatedStyle} from './embedded-react/split-style.js';
34
-
35
- // --- Animated bindings ---------------------------------------------------------------------------
36
- // A bound prop is owned by the engine from then on: it re-pushes the animated value over the static
37
- // props of every later setProps (er_animation_reapply_bound), which is what keeps a re-render from jumping
38
- // a running animation back to its declared value. Nothing in React says "this prop stopped being
39
- // animated", so the binding has to be released explicitly or it keeps writing the prop forever — and a
40
- // prop that swapped Animated.Values ends up written by both. Instances are bare node handles with no
41
- // JS object to hang state on, so what we bound is remembered here: handle → (prop → animated value).
42
- const boundValues = new Map();
43
-
44
- /**
45
- * True when two animated values bind a prop the same way, so a re-render can leave the live binding
46
- * alone. Identity settles an Animated.Value; an interpolation is a throwaway object that
47
- * `value.interpolate(...)` rebuilds on every render, so it answers __bindEq for itself.
48
- */
49
- function sameBinding(previous, next) {
50
- if (previous === next) return true;
51
- if (previous == null || next == null) return false;
52
- return typeof previous.__bindEq === 'function' && previous.__bindEq(next);
53
- }
54
-
55
- /** The value `bindings` (from splitAnimatedStyle) drives `prop` with, or undefined if none does. */
56
- function bindingFor(bindings, prop) {
57
- for (const binding of bindings) {
58
- if (binding.prop === prop) return binding.value;
59
- }
60
- return undefined;
61
- }
62
-
63
- /**
64
- * Releases the bindings a node has that its new props no longer ask for — a prop that went back to a
65
- * static value, or moved to a different Animated.Value.
66
- *
67
- * Runs BEFORE the node's setProps, and that order is the whole point: setProps re-pushes every value
68
- * still bound to the node over the static props it just wrote, so a binding released afterwards would
69
- * leave its last animated float sitting on the node instead of the value React just set.
70
- */
71
- function releaseStaleBindings(handle, bindings) {
72
- const bound = boundValues.get(handle);
73
- if (bound === undefined) return;
74
- for (const [prop, value] of bound) {
75
- if (sameBinding(value, bindingFor(bindings, prop))) continue;
76
- NativeUI.animUnbind(handle, prop);
77
- bound.delete(prop);
78
- }
79
- if (bound.size === 0) boundValues.delete(handle);
80
- }
81
-
82
- /**
83
- * Binds the props that aren't already bound to the value asking for them. The engine ignores a
84
- * duplicate bind, but the bridge crossing to find that out isn't free on an MCU.
85
- */
86
- function applyBindings(handle, bindings) {
87
- if (bindings.length === 0) return;
88
- let bound = boundValues.get(handle);
89
- for (const binding of bindings) {
90
- if (
91
- bound !== undefined &&
92
- sameBinding(bound.get(binding.prop), binding.value)
93
- )
94
- continue;
95
- binding.value.__bind(handle, binding.prop);
96
- if (bound === undefined) {
97
- bound = new Map();
98
- boundValues.set(handle, bound);
99
- }
100
- bound.set(binding.prop, binding.value);
101
- }
102
- }
103
-
104
- /**
105
- * Forgets what a handle was bound to. The engine releases the bindings itself when a node is destroyed
106
- * (er_animation_unbind_node), so this only drops our record — but it has to happen, or the map keeps a
107
- * record for every destroyed node. Called on destroy for the node React hands us, and again from
108
- * detachDeletedInstance because destroyNode reclaims a whole SUBTREE in C — React never hands
109
- * removeChild the descendants, and detaching is where it names them.
110
- */
111
- function forgetBindings(handle) {
112
- boundValues.delete(handle);
113
- }
114
-
115
- // --- Failed creates ------------------------------------------------------------------------------
116
- // createNode returns 0 when the node pool is full. React creates children before their parent, so the
117
- // children of a parent that did not fit are never attached to anything, and removing that parent frees
118
- // nothing in C. Each failed create gets its own negative instance (the bridge ignores handles <= 0), and
119
- // the children appended to it are kept here so they are freed when it is deleted.
120
- const FAILED_CREATE = 0; // createNode's handle when the pool is full
121
- const orphansOf = new Map(); // failed instance → Set of child handles
122
- let nextFailedInstance = -1;
123
-
124
- /** Records `child` as held by `parent` when `parent` is a failed create. */
125
- function adoptIfOrphan(parent, child) {
126
- if (parent >= 0 || child <= 0) return;
127
- let orphans = orphansOf.get(parent);
128
- if (orphans === undefined) {
129
- orphans = new Set();
130
- orphansOf.set(parent, orphans);
131
- }
132
- orphans.add(child);
133
- }
134
-
135
- /** Frees the children a failed create was holding. */
136
- function freeOrphans(instance) {
137
- const orphans = orphansOf.get(instance);
138
- if (orphans === undefined) return;
139
- orphansOf.delete(instance);
140
- for (const child of orphans) {
141
- NativeUI.destroyNode(child);
142
- forgetBindings(child);
143
- }
144
- }
145
-
146
- /**
147
- * Applies a node's resolved props, binding any Animated.Value found in its `style` to the matching
148
- * node prop (native driver). This makes animated styles work on ANY host element — `<Pressable
149
- * style={{ transform: [{ scale: v }] }}>` binds without an Animated.* wrapper — which is what the
150
- * Flow B AOT compiler does too, so the two render paths stay in parity (and what an Animated.* wrapper
151
- * relies on: it forwards its style untouched and is bound here like any other element).
152
- *
153
- * Returns the resolved flat style so a paired applyTextSpans call can reuse it instead of
154
- * re-flattening props.style from scratch — style flattening (recursive array walk and object merge)
155
- * is one of the costlier steps in commitUpdate's JS-side work on a bytecode-interpreted MCU target.
156
- */
157
- function applyProps(type, handle, props) {
158
- const {staticStyle, bindings} = splitAnimatedStyle(props.style);
159
- // <Dial value={animatedValue}>: the value is a native-driver binding (ER_PROP_ARC_VALUE), not a prop —
160
- // the engine ramps it with no JS per frame and damages only the swept sliver.
161
- if (type === 'Dial') {
162
- if (props.value && props.value.__animated) {
163
- bindings.push({prop: 'value', value: props.value});
164
- props = {...props, value: undefined};
165
- }
166
- if (props.valueStart && props.valueStart.__animated) {
167
- bindings.push({prop: 'valueStart', value: props.valueStart});
168
- props = {...props, valueStart: undefined};
169
- }
170
- }
171
- releaseStaleBindings(handle, bindings);
172
- NativeUI.setProps(handle, buildProps(type, props, staticStyle));
173
- applyBindings(handle, bindings);
174
- return staticStyle;
175
- }
176
-
177
- /**
178
- * Applies inline-styled text spans for a <Text> node (no-op for other types). buildTextSpans returns
179
- * [] for uniform text, which reverts the node to plain-text rendering — so this also clears stale
180
- * spans when a Text changes from styled-runs to a single style across renders. `flatStyle`, when
181
- * given, is the already-resolved style from a paired applyProps call on the same props (avoids a
182
- * second full flattening of props.style).
183
- */
184
- function applyTextSpans(type, handle, props, flatStyle) {
185
- if (type === 'Text')
186
- NativeUI.setTextSpans(handle, buildTextSpans(props, flatStyle));
187
- }
188
-
189
- /** Resolves an <Svg>'s render-box dimension from style/props, falling back to the source's intrinsic size. */
190
- function svgBoxSize(props, dimension, intrinsic) {
191
- const styleSize =
192
- props.style && typeof props.style[dimension] === 'number'
193
- ? props.style[dimension]
194
- : undefined;
195
- const propSize =
196
- typeof props[dimension] === 'number' ? props[dimension] : undefined;
197
- return styleSize ?? propSize ?? intrinsic;
198
- }
199
-
200
- /**
201
- * A `<Svg source={imported}>` whose imported .svg fell back to a RASTER image at build time (the SVG used
202
- * features the vector baker can't represent). Returns the artifact, or null for a vector/declarative
203
- * Svg. Such a Svg is rendered as an IMAGE node, not a vector node — `props.source.kind` is the discriminator
204
- * (an imported artifact's kind is fixed at build time, so it never flips for a given element).
205
- */
206
- function rasterSvgArtifact(type, props) {
207
- const source = props && props.source;
208
- return type === 'Svg' && source && source.kind === 'raster' ? source : null;
209
- }
210
-
211
- /** Maps a raster `<Svg source>` to equivalent `<Image>` props: the baked asset name + the resolved box size. */
212
- function rasterImageProps(props, artifact) {
213
- const width = svgBoxSize(props, 'width', artifact.width);
214
- const height = svgBoxSize(props, 'height', artifact.height);
215
- return {
216
- ...props,
217
- source: artifact.name,
218
- style: {...(props.style || {}), width, height},
219
- };
220
- }
221
-
222
- /**
223
- * Sets an <Svg>'s vector op-tape. Two sources, source prop wins:
224
- * <Svg source={imported}> — an imported .svg's baked artifact ({kind:'vector', ops, paints, width,
225
- * height}); we scale its op-tape from intrinsic px to the node's box.
226
- * <Svg><Path/>...</Svg> — declarative children flattened here (the Svg owns its subtree; React does
227
- * not mount the shape children, so we compile them on create + every update).
228
- */
229
- function applyVectorOps(type, handle, props) {
230
- if (type !== 'Svg') return;
231
- let ops;
232
- let paints;
233
- let gradients;
234
- const source = props.source;
235
- if (source && source.kind === 'vector' && Array.isArray(source.ops)) {
236
- ({ops, paints, gradients} = scaleVectorArtifact(
237
- source,
238
- svgBoxSize(props, 'width', source.width),
239
- svgBoxSize(props, 'height', source.height),
240
- ));
241
- } else {
242
- ({ops, paints, gradients} = flattenSvg(props));
243
- }
244
- warnVectorCaps(
245
- ops.length,
246
- paints.length,
247
- NativeUI.maxVectorOps,
248
- NativeUI.maxVectorPaints,
249
- gradients ? gradients.length : 0,
250
- NativeUI.maxVectorGrads,
251
- );
252
- NativeUI.setVectorOps(
253
- handle,
254
- ops,
255
- paints,
256
- gradients && gradients.length
257
- ? encodeVectorGradients(gradients)
258
- : undefined,
259
- );
260
- }
261
-
262
- /**
263
- * True when a `<Svg source={vectorArtifact}>`'s resolved render box changed between renders — the
264
- * one style-driven input to the op-tape (the tape is scaled from the artifact's intrinsic px to the
265
- * box, see scaleVectorArtifact). A style change that leaves the box alone (a position move during a
266
- * drag, a color tweak) does not need the tape re-uploaded.
267
- */
268
- function svgSourceBoxChanged(prevProps, nextProps) {
269
- const source = nextProps.source;
270
- const intrinsicWidth =
271
- source && source.kind === 'vector' ? source.width : undefined;
272
- const intrinsicHeight =
273
- source && source.kind === 'vector' ? source.height : undefined;
274
- return (
275
- svgBoxSize(prevProps, 'width', intrinsicWidth) !==
276
- svgBoxSize(nextProps, 'width', intrinsicWidth) ||
277
- svgBoxSize(prevProps, 'height', intrinsicHeight) !==
278
- svgBoxSize(nextProps, 'height', intrinsicHeight)
279
- );
280
- }
281
-
282
- /**
283
- * Diffs a re-rendered host element's props and returns what commitUpdate must re-apply — or null
284
- * when nothing observable changed, which makes React skip the commit entirely (no Update effect, no
285
- * bridge traffic). Re-marshaling props across the JS->C bridge is the dominant cost of a Flow A
286
- * re-render, and a parent's state change re-renders every non-memoized child with identical props,
287
- * so the null case is the common one on interactive screens.
288
- *
289
- * The payload is a set of section flags, so a partial change re-applies only its section:
290
- * props — NativeUI.setProps (resolved style + passthrough props + text)
291
- * spans — inline text spans (<Text> only; derived from children + style)
292
- * vector — the <Svg> op-tape upload (flattenSvg/scaleVectorArtifact + setVectorOps)
293
- * events — on* handler registration (an inline closure has a new identity every render and must be
294
- * re-stored — its captures went stale — but that alone shouldn't re-serialize the props)
295
- *
296
- * The vector flag tracks the op-tape's actual inputs. A source artifact tape depends on the source
297
- * reference and the resolved box; a declarative <Svg><Path/></Svg> tape depends on the shape
298
- * children, viewBox, the direct width/height props, and its own paint props, which cascade to its
299
- * shapes (flattenSvg never reads style). So a position-only style move of either kind — the
300
- * interactive-drag hot path — skips the upload.
301
- *
302
- * Props buildProps never reads still set the props flag when they change — conservative, and only
303
- * paid when such a value actually changed.
304
- */
305
- function diffUpdate(type, prevProps, nextProps) {
306
- let props = false;
307
- let spans = false;
308
- let events = false;
309
- let vector = false;
310
- const diffKey = key => {
311
- const previousValue = prevProps[key];
312
- const nextValue = nextProps[key];
313
- if (Object.is(previousValue, nextValue)) return;
314
- if (isEventProp(key, previousValue) || isEventProp(key, nextValue)) {
315
- events = true;
316
- return;
317
- }
318
- switch (key) {
319
- case 'children':
320
- // Only subtree-owning types render children through their OWN props (shouldSetTextContent);
321
- // everywhere else children are separate host instances React mutates directly.
322
- if (type === 'Text') {
323
- if (!deepEqualProps(previousValue, nextValue)) {
324
- props = true; // flat.text is built from children
325
- spans = true;
326
- }
327
- } else if (type === 'Svg') {
328
- if (!deepEqualProps(previousValue, nextValue)) vector = true;
329
- }
330
- return;
331
- case 'style':
332
- if (!deepEqualProps(previousValue, nextValue)) {
333
- props = true;
334
- if (type === 'Text') spans = true;
335
- if (type === 'Svg' && nextProps.source)
336
- vector = vector || svgSourceBoxChanged(prevProps, nextProps);
337
- }
338
- return;
339
- case 'source':
340
- props = true; // imageName (Image / raster Svg fallback)
341
- if (type === 'Svg') vector = true; // artifact swap → new tape
342
- return;
343
- case 'width':
344
- case 'height':
345
- case 'viewBox':
346
- if (type === 'Svg') {
347
- props = true; // width/height fold into the resolved style box
348
- vector = true; // and drive the tape's root transform / artifact scale
349
- return;
350
- }
351
- // fall through: on other types these are ordinary (ignored or passthrough) props
352
- default:
353
- if (!deepEqualProps(previousValue, nextValue)) {
354
- props = true;
355
- // A source tape ignores root paint.
356
- if (type === 'Svg' && !nextProps.source && PAINT_PROPS.includes(key))
357
- vector = true;
358
- }
359
- }
360
- };
361
- for (const key in prevProps) diffKey(key);
362
- for (const key in nextProps) {
363
- if (!Object.prototype.hasOwnProperty.call(prevProps, key)) diffKey(key);
364
- }
365
- return props || spans || events || vector
366
- ? {props, spans, events, vector}
367
- : null;
368
- }
369
-
370
- /**
371
- * Registers/clears on* event handlers. A handler present in old but not new props is cleared.
372
- */
373
- function applyEvents(handle, prevProps, nextProps) {
374
- if (prevProps) {
375
- for (const key in prevProps) {
376
- if (
377
- isEventProp(key, prevProps[key]) &&
378
- !(nextProps && isEventProp(key, nextProps[key]))
379
- ) {
380
- NativeUI.setEvent(handle, key, null);
381
- }
382
- }
383
- }
384
- for (const key in nextProps) {
385
- if (isEventProp(key, nextProps[key])) {
386
- NativeUI.setEvent(handle, key, nextProps[key]);
387
- }
388
- }
389
- }
390
-
391
- export const hostConfig = {
392
- supportsMutation: true,
393
- supportsPersistence: false,
394
- supportsHydration: false,
395
- isPrimaryRenderer: true,
396
- noTimeout: -1,
397
- warnsIfNotActing: false,
398
-
399
- // --- Context (we carry none) ---
400
- getRootHostContext() {
401
- return {};
402
- },
403
- getChildHostContext(parentContext) {
404
- return parentContext;
405
- },
406
- getPublicInstance(instance) {
407
- return instance;
408
- },
409
-
410
- // --- Commit lifecycle ---
411
- // These two bracket React's mutation phase exactly, which is the only place the reconciler touches
412
- // the bridge — so on an instrumented build they are what makes the marshaling bucket cover the JS
413
- // glue (applyProps, style flattening) and not just the NativeUI calls it ends up making.
414
- prepareForCommit() {
415
- NativeUI.perfMarshalBegin?.();
416
- return null;
417
- },
418
- resetAfterCommit() {
419
- NativeUI.perfMarshalEnd?.();
420
- NativeUI.commit();
421
- },
422
-
423
- // --- Creation ---
424
- createInstance(type, props) {
425
- // A raster-fallback <Svg source> becomes a real Image node (the SVG was rasterized at build time).
426
- const raster = rasterSvgArtifact(type, props);
427
- if (raster) {
428
- const handle = NativeUI.createNode('Image');
429
- if (handle === FAILED_CREATE) return nextFailedInstance--;
430
- applyProps('Image', handle, rasterImageProps(props, raster));
431
- applyEvents(handle, null, props);
432
- return handle;
433
- }
434
- const handle = NativeUI.createNode(type);
435
- if (handle === FAILED_CREATE) return nextFailedInstance--;
436
- const flatStyle = applyProps(type, handle, props);
437
- applyTextSpans(type, handle, props, flatStyle);
438
- applyVectorOps(type, handle, props);
439
- applyEvents(handle, null, props);
440
- return handle;
441
- },
442
- createTextInstance(text) {
443
- // Raw text is only legal inside <Text> (handled via shouldSetTextContent). This fallback
444
- // wraps stray text in a Text node so it still renders rather than crashing.
445
- const handle = NativeUI.createNode('Text');
446
- NativeUI.setProps(handle, {text: String(text)});
447
- return handle;
448
- },
449
- appendInitialChild(parent, child) {
450
- NativeUI.appendChild(parent, child);
451
- adoptIfOrphan(parent, child);
452
- },
453
- finalizeInitialChildren() {
454
- return false;
455
- },
456
- shouldSetTextContent(type, props) {
457
- // Own the whole subtree for any flattenable <Text> (strings, interpolation, nested <Text>): React
458
- // skips mounting children and we render them via the node's text + spans. Non-flattenable content
459
- // (e.g. a <View> inside <Text>) returns false, falling back to mounted child instances.
460
- // <Svg> also owns its subtree: the shape children are flattened into the vector op-tape
461
- // (applyVectorOps), never mounted as host nodes.
462
- return type === 'Svg' || (type === 'Text' && isTextContent(props.children));
463
- },
464
-
465
- // --- Mutation ---
466
- appendChild(parent, child) {
467
- NativeUI.appendChild(parent, child);
468
- adoptIfOrphan(parent, child);
469
- },
470
- appendChildToContainer(container, child) {
471
- NativeUI.appendChild(container, child);
472
- },
473
- insertBefore(parent, child, beforeChild) {
474
- NativeUI.insertBefore(parent, child, beforeChild);
475
- adoptIfOrphan(parent, child);
476
- },
477
- insertInContainerBefore(container, child, beforeChild) {
478
- NativeUI.insertBefore(container, child, beforeChild);
479
- },
480
- removeChild(parent, child) {
481
- NativeUI.removeChild(parent, child);
482
- orphansOf.get(parent)?.delete(child);
483
- NativeUI.destroyNode(child);
484
- forgetBindings(child);
485
- },
486
- removeChildFromContainer(container, child) {
487
- NativeUI.removeChild(container, child);
488
- NativeUI.destroyNode(child);
489
- forgetBindings(child);
490
- },
491
- clearContainer() {
492
- // Children are removed individually via removeChildFromContainer.
493
- },
494
- prepareUpdate(instance, type, oldProps, newProps) {
495
- // Runs in the render phase. null → React schedules no Update effect and commitUpdate never
496
- // fires for this node — the win that makes an unchanged re-render bridge-free.
497
- return diffUpdate(type, oldProps, newProps);
498
- },
499
- commitUpdate(instance, payload, type, prevProps, nextProps) {
500
- const raster = rasterSvgArtifact(type, nextProps);
501
- if (raster) {
502
- // The Svg instance is an Image node (raster fallback); re-apply as image props, never vector ops.
503
- if (payload.props)
504
- applyProps('Image', instance, rasterImageProps(nextProps, raster));
505
- if (payload.events) applyEvents(instance, prevProps, nextProps);
506
- return;
507
- }
508
- // payload.spans is only ever set alongside payload.props for Text nodes (see diffUpdate), so
509
- // flatStyle is defined whenever applyTextSpans actually needs it.
510
- let flatStyle;
511
- if (payload.props) flatStyle = applyProps(type, instance, nextProps);
512
- if (payload.spans) applyTextSpans(type, instance, nextProps, flatStyle);
513
- if (payload.vector) applyVectorOps(type, instance, nextProps);
514
- if (payload.events) applyEvents(instance, prevProps, nextProps);
515
- },
516
- commitTextUpdate(textInstance, _oldText, newText) {
517
- NativeUI.setProps(textInstance, {text: String(newText)});
518
- },
519
-
520
- // --- Misc required hooks (no-ops for our renderer) ---
521
- detachDeletedInstance(instance) {
522
- // Called for every host instance in a deleted subtree, including failed creates below its top.
523
- if (instance < 0) freeOrphans(instance);
524
- else forgetBindings(instance);
525
- },
526
- getCurrentEventPriority() {
527
- return DefaultEventPriority;
528
- },
529
- getInstanceFromNode() {
530
- return null;
531
- },
532
- beforeActiveInstanceBlur() {},
533
- afterActiveInstanceBlur() {},
534
- prepareScopeUpdate() {},
535
- getInstanceFromScope() {
536
- return null;
537
- },
538
-
539
- // --- Scheduling ---
540
- scheduleTimeout: (callback, delay) => setTimeout(callback, delay),
541
- cancelTimeout: timeoutId => clearTimeout(timeoutId),
542
- supportsMicrotasks: true,
543
- scheduleMicrotask:
544
- typeof queueMicrotask === 'function'
545
- ? queueMicrotask
546
- : callback => Promise.resolve().then(callback),
547
- now: () => NativeUI.now(),
548
- };