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
package/src/props.js DELETED
@@ -1,306 +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
- // Pure prop-marshalling helpers. No engine / NativeUI dependency, so these are unit-testable in
18
- // plain Node (see src/__tests__/props.unit.test.js). The host config wires them to NativeUI.
19
-
20
- // Top-level props NativeUI understands directly (not part of `style`). Everything else style-ish is
21
- // expected inside props.style. Event handlers (on*) are routed separately via setEvent.
22
- export const PASSTHROUGH = [
23
- 'delayLongPress',
24
- 'numberOfLines',
25
- 'ellipsizeMode',
26
- 'value',
27
- 'placeholder',
28
- 'placeholderTextColor',
29
- 'editable',
30
- 'secureTextEntry',
31
- 'animating',
32
- 'visible',
33
- 'backdropColor', // <Modal>'s scrim, as React Native takes it (the style key works too)
34
- 'resizeMode',
35
- 'tintColor',
36
- 'imageName',
37
- // Switch colours.
38
- 'trackColor',
39
- 'thumbColor',
40
- // <Dial> (the native arc widget, ER_NODE_ARC).
41
- 'min',
42
- 'max',
43
- 'startAngle',
44
- 'sweepAngle',
45
- 'step',
46
- 'gapAngle',
47
- 'thickness',
48
- 'bandThickness',
49
- 'knobSize',
50
- 'knobBorderWidth',
51
- 'indicatorColor',
52
- 'bandColor',
53
- 'knobColor',
54
- 'knobBorderColor',
55
- 'segments',
56
- 'cap',
57
- 'knob',
58
- 'knobImage',
59
- 'adjustable',
60
- 'range',
61
- 'valueStart',
62
- 'minSpan',
63
- 'indicatorGradient',
64
- ];
65
-
66
- /**
67
- * Flattens RN-style `style` (object or nested array) into the `output` object.
68
- */
69
- export function flattenStyle(style, output) {
70
- if (!style) return;
71
- if (Array.isArray(style)) {
72
- for (const entry of style) flattenStyle(entry, output);
73
- } else {
74
- Object.assign(output, style);
75
- }
76
- }
77
-
78
- /** Flattens a style (object/array) into a fresh plain object. */
79
- export function flattenStyleObj(style) {
80
- const flattened = {};
81
- flattenStyle(style, flattened);
82
- return flattened;
83
- }
84
-
85
- // Style fields the engine honors per inline text span (everything else inherits from the node).
86
- const SPAN_STYLE_KEYS = [
87
- 'color',
88
- 'fontSize',
89
- 'fontWeight',
90
- 'fontStyle',
91
- 'textDecorationLine',
92
- 'letterSpacing',
93
- ];
94
-
95
- /**
96
- * True when a <Text>'s children can be flattened inline — i.e. every leaf is a string/number or a
97
- * nested <Text> element. A non-Text element (View, a component) makes it false, so the reconciler
98
- * falls back to mounting children as separate instances.
99
- */
100
- export function isTextContent(children) {
101
- if (children == null || children === false || children === true) return true;
102
- if (typeof children === 'string' || typeof children === 'number') return true;
103
- if (Array.isArray(children)) return children.every(isTextContent);
104
- // A React element: only nested <Text> participates in inline flattening (type is the 'Text' tag).
105
- if (children && children.props !== undefined) return children.type === 'Text';
106
- return false;
107
- }
108
-
109
- /**
110
- * Walks a <Text>'s children into an ordered list of { text, style } segments. Primitive siblings
111
- * share the parent's (base) style object by reference; a nested <Text> with its own style produces
112
- * a new merged style object. Adjacent segments with the same style reference are coalesced — so
113
- * plain interpolation like `Hi {name}` collapses to a single segment (no spans needed).
114
- */
115
- export function flattenTextChildren(children, baseStyle) {
116
- const segments = [];
117
- const push = (text, style) => {
118
- if (text === '') return;
119
- const last = segments[segments.length - 1];
120
- if (last && last.style === style) last.text += text;
121
- else segments.push({text, style});
122
- };
123
- const walk = (node, style) => {
124
- if (node == null || node === false || node === true) return;
125
- if (typeof node === 'string' || typeof node === 'number') {
126
- push(String(node), style);
127
- return;
128
- }
129
- if (Array.isArray(node)) {
130
- for (const child of node) walk(child, style);
131
- return;
132
- }
133
- if (node && node.props !== undefined) {
134
- // Nested <Text>: merge its style over the inherited one (new object only when it has style,
135
- // so an unstyled nested <Text> keeps the same reference and still coalesces with siblings).
136
- const merged = node.props.style
137
- ? Object.assign({}, style, flattenStyleObj(node.props.style))
138
- : style;
139
- walk(node.props.children, merged);
140
- }
141
- };
142
- walk(children, baseStyle);
143
- return segments;
144
- }
145
-
146
- /**
147
- * Builds the inline-span array for a <Text> (for NativeUI.setTextSpans). Returns [] when the content
148
- * is uniformly the base style (plain text — no spans needed); otherwise one span per styled segment,
149
- * each carrying only the span-relevant style keys (the engine inherits the rest from the node).
150
- */
151
- export function buildTextSpans(props, flatStyle) {
152
- if (!isTextContent(props.children)) return [];
153
- const baseStyle = flatStyle || flattenStyleObj(props.style);
154
- const segments = flattenTextChildren(props.children, baseStyle);
155
- if (!segments.some(segment => segment.style !== baseStyle)) return [];
156
- return segments.map(segment => {
157
- const span = {text: segment.text};
158
- for (const key of SPAN_STYLE_KEYS) {
159
- if (segment.style && segment.style[key] !== undefined)
160
- span[key] = segment.style[key];
161
- }
162
- return span;
163
- });
164
- }
165
-
166
- /**
167
- * Builds the flat prop bag NativeUI.setProps expects: resolved style + passthrough props + text.
168
- */
169
- /**
170
- * Resolves an <Image source> to the engine asset name (the string registered via er_image_load and
171
- * stored on the node as imageName). Accepts a bare name string — which is also what the bundler's
172
- * image plugin turns `import logo from './logo.png'` into (the file's basename) — or an RN-style
173
- * { uri } object. Returns null for anything unresolvable (e.g., a numeric require() id).
174
- */
175
- export function resolveImageSource(source) {
176
- if (typeof source === 'string') return source;
177
- if (source && typeof source === 'object' && typeof source.uri === 'string')
178
- return source.uri;
179
- return null;
180
- }
181
-
182
- export function buildProps(type, props, flatStyle) {
183
- const flat = flatStyle ? {...flatStyle} : {};
184
- if (!flatStyle) flattenStyle(props.style, flat);
185
- for (const key of PASSTHROUGH) {
186
- if (props[key] !== undefined) flat[key] = props[key];
187
- }
188
- // <Svg> takes width/height as DIRECT props (the react-native-svg convention) — the engine sizes the
189
- // vector node from them. Fold them into the resolved style (an explicit style width/height still wins)
190
- // so Flow A matches the Flow B AOT, which reads svg.props.width/height directly (aot/compiler/svg.mts emitSvgBox).
191
- if (type === 'Svg') {
192
- if (flat.width === undefined && props.width !== undefined)
193
- flat.width = props.width;
194
- if (flat.height === undefined && props.height !== undefined)
195
- flat.height = props.height;
196
- }
197
- // <Image source={...}> resolves to the engine asset name unless imageName was set explicitly.
198
- if (flat.imageName === undefined && props.source != null) {
199
- const name = resolveImageSource(props.source);
200
- if (name != null) flat.imageName = name;
201
- }
202
- // <Dial knobImage={require(...)}> takes an asset source like <Image source>; a plain string is an
203
- // asset name already.
204
- if (
205
- type === 'Dial' &&
206
- props.knobImage != null &&
207
- typeof props.knobImage !== 'string'
208
- ) {
209
- const name = resolveImageSource(props.knobImage);
210
- flat.knobImage = name != null ? name : undefined;
211
- }
212
- // `visible` is the Modal's own show/hide prop (it maps to ERProps.modal_visible). On every other
213
- // component it used to be silently inert; it now means the same thing as `display`, so a subtree can
214
- // be pruned from layout, raster and hit-testing without unmounting it. An explicit style `display`
215
- // wins, so the two spellings can't disagree.
216
- if (type !== 'Modal' && flat.visible !== undefined) {
217
- if (flat.display === undefined)
218
- flat.display = flat.visible ? 'flex' : 'none';
219
- delete flat.visible;
220
- }
221
- // <Text> content: flatten string/number/nested-<Text> children into the node's full-text string.
222
- // The engine renders this when no spans are set; with spans (buildTextSpans) it carries the same
223
- // text for the plain-text fallback. Non-flattenable children fall back to mounted child instances.
224
- if (type === 'Text' && isTextContent(props.children)) {
225
- const baseStyle = flatStyle || flattenStyleObj(props.style);
226
- flat.text = flattenTextChildren(props.children, baseStyle)
227
- .map(segment => segment.text)
228
- .join('');
229
- }
230
- return flat;
231
- }
232
-
233
- // Bail-out depth for deepEqualProps. Real host props are shallow (style ≈ 2 levels, a nested-<Text>
234
- // span or <Svg> shape tree ≈ 3 levels per element); anything deeper is pathological and bails to
235
- // "changed", whose worst case is a redundant re-apply — exactly the pre-diff behavior.
236
- const DEEP_EQUAL_MAX_DEPTH = 24;
237
-
238
- /**
239
- * Deep value equality for host-prop diffing (the reconciler's prepareUpdate). Re-renders recreate
240
- * prop objects every time, so identity alone can't tell "nothing changed" — this compares by value:
241
- * primitives via Object.is, arrays elementwise, React elements by type and props (keys don't affect a
242
- * flattened <Text>/<Svg> subtree's output), and plain objects key-by-key. Class instances (e.g.,
243
- * Animated.Value) compare by IDENTITY only: a fresh instance must read as changed, so it gets bound
244
- * to the node, while the same instance is already bound and can be skipped.
245
- */
246
- export function deepEqualProps(left, right, depth = 0) {
247
- if (Object.is(left, right)) return true;
248
- if (depth >= DEEP_EQUAL_MAX_DEPTH) return false;
249
- if (
250
- typeof left !== 'object' ||
251
- typeof right !== 'object' ||
252
- left === null ||
253
- right === null
254
- )
255
- return false;
256
- if (Array.isArray(left) || Array.isArray(right)) {
257
- if (
258
- !Array.isArray(left) ||
259
- !Array.isArray(right) ||
260
- left.length !== right.length
261
- )
262
- return false;
263
- for (let index = 0; index < left.length; index++) {
264
- if (!deepEqualProps(left[index], right[index], depth + 1)) return false;
265
- }
266
- return true;
267
- }
268
- // React elements: equal when they render the same host output — same type, same props.
269
- if (left.$$typeof !== right.$$typeof) return false;
270
- if (left.$$typeof !== undefined) {
271
- return (
272
- left.type === right.type &&
273
- deepEqualProps(left.props, right.props, depth + 1)
274
- );
275
- }
276
- // Plain objects only; class instances fall through to "changed" (identity already ruled equal out).
277
- const leftPrototype = Object.getPrototypeOf(left);
278
- const rightPrototype = Object.getPrototypeOf(right);
279
- if (
280
- (leftPrototype !== null && leftPrototype !== Object.prototype) ||
281
- (rightPrototype !== null && rightPrototype !== Object.prototype)
282
- )
283
- return false;
284
- const leftKeys = Object.keys(left);
285
- const rightKeys = Object.keys(right);
286
- if (leftKeys.length !== rightKeys.length) return false;
287
- for (const key of leftKeys) {
288
- if (!Object.prototype.hasOwnProperty.call(right, key)) return false;
289
- if (!deepEqualProps(left[key], right[key], depth + 1)) return false;
290
- }
291
- return true;
292
- }
293
-
294
- /**
295
- * True for an `onXxx` prop whose value is a function (an event handler to route via setEvent).
296
- */
297
- export function isEventProp(key, value) {
298
- return (
299
- key.length > 2 &&
300
- key[0] === 'o' &&
301
- key[1] === 'n' &&
302
- key[2] >= 'A' &&
303
- key[2] <= 'Z' &&
304
- typeof value === 'function'
305
- );
306
- }