embedded-react 0.21.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 (99) hide show
  1. package/README.md +2 -2
  2. package/aot/compile.mjs +1 -1
  3. package/aot/compiler/alerts.mjs +604 -0
  4. package/aot/compiler/check.mjs +1 -1
  5. package/aot/compiler/collect.mjs +1 -1
  6. package/aot/compiler/elements/button.mjs +3 -3
  7. package/aot/compiler/elements/image-background.mjs +1 -1
  8. package/aot/compiler/elements/props.mjs +10 -6
  9. package/aot/compiler/elements/section-list.mjs +1 -1
  10. package/aot/compiler/expressions.mjs +29 -2
  11. package/aot/compiler/handlers.mjs +73 -16
  12. package/aot/compiler/keyboard-dismiss.mjs +99 -0
  13. package/aot/compiler/keyboard.mjs +1 -1
  14. package/aot/compiler/lower.mjs +12 -0
  15. package/aot/compiler/nodes.mjs +17 -9
  16. package/aot/compiler/out.mjs +4 -0
  17. package/aot/compiler/package/codegen.mjs +36 -2
  18. package/aot/compiler/package/format.mjs +5 -3
  19. package/aot/compiler/package/lower.mjs +53 -19
  20. package/aot/compiler/scroll-to.mjs +112 -0
  21. package/aot/compiler/style-text.mjs +2 -2
  22. package/aot/compiler/svg.mjs +6 -3
  23. package/aot/compiler/updaters.mjs +1 -0
  24. package/aot/style-map.mjs +44 -1
  25. package/assets/bake-font.mjs +187 -244
  26. package/assets/bake-image.mjs +47 -71
  27. package/assets/bake-svg.mjs +465 -533
  28. package/assets/build-builtin-font.mjs +14 -27
  29. package/assets/emit-c.mjs +124 -204
  30. package/assets/emit-container.mjs +129 -197
  31. package/assets/emit-pack.mjs +92 -136
  32. package/assets/font-config.mjs +19 -27
  33. package/assets/font-sizes.mjs +432 -507
  34. package/assets/glyph-coverage.mjs +170 -214
  35. package/assets/index.mjs +52 -97
  36. package/assets/rasterize.mjs +173 -194
  37. package/assets/svg-loader.mjs +42 -48
  38. package/build.mjs +84 -101
  39. package/cli.mjs +482 -621
  40. package/compile-bin.mjs +24 -36
  41. package/flash.mjs +297 -401
  42. package/hotreload/dev-device.mjs +229 -270
  43. package/hotreload/pack-app.mjs +118 -159
  44. package/hotreload/pack-split.mjs +144 -200
  45. package/hotreload/package-transfer.mjs +128 -131
  46. package/hotreload/protocol.mjs +118 -118
  47. package/hotreload/uploader.mjs +132 -159
  48. package/hotreload/watch-tree.mjs +56 -65
  49. package/pack-container.mjs +93 -123
  50. package/package.json +19 -16
  51. package/persist-transform.mjs +89 -105
  52. package/qjsc-wasm.mjs +47 -72
  53. package/sim/embedded-react.wasm +0 -0
  54. package/sim/index.html +1 -1
  55. package/sim-server.mjs +260 -354
  56. package/src/embedded-react/Alert.mjs +112 -0
  57. package/src/embedded-react/Animated.mjs +412 -0
  58. package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
  59. package/src/embedded-react/{Button.js → Button.mjs} +29 -53
  60. package/src/embedded-react/{Dimensions.js → Dimensions.mjs} +12 -17
  61. package/src/embedded-react/Easing.mjs +34 -0
  62. package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
  63. package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
  64. package/src/embedded-react/Keyboard.mjs +82 -0
  65. package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
  66. package/src/embedded-react/PanResponder.mjs +256 -0
  67. package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
  68. package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
  69. package/src/embedded-react/SectionList.mjs +103 -0
  70. package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
  71. package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
  72. package/src/embedded-react/background-image.mjs +321 -0
  73. package/src/embedded-react/{components.js → components.mjs} +1 -3
  74. package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
  75. package/src/embedded-react/index.d.ts +155 -2
  76. package/src/embedded-react/index.js +26 -19
  77. package/src/embedded-react/layout-anim-config.mjs +85 -0
  78. package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
  79. package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
  80. package/src/embedded-react/nativeModule.mjs +371 -0
  81. package/src/embedded-react/split-style.mjs +57 -0
  82. package/src/embedded-react/svg-ops.mjs +1075 -0
  83. package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
  84. package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
  85. package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
  86. package/src/host-config.mjs +512 -0
  87. package/src/{native-ui.js → native-ui.mjs} +1 -8
  88. package/src/props.mjs +341 -0
  89. package/src/{renderer.js → renderer.mjs} +30 -44
  90. package/src/embedded-react/Animated.js +0 -440
  91. package/src/embedded-react/Easing.js +0 -39
  92. package/src/embedded-react/PanResponder.js +0 -330
  93. package/src/embedded-react/SectionList.js +0 -146
  94. package/src/embedded-react/layout-anim-config.js +0 -101
  95. package/src/embedded-react/nativeModule.js +0 -462
  96. package/src/embedded-react/split-style.js +0 -58
  97. package/src/embedded-react/svg-ops.js +0 -1295
  98. package/src/host-config.js +0 -548
  99. 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
- }