embedded-react 0.19.0 → 0.21.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 (148) hide show
  1. package/NOTICE +5 -0
  2. package/README.md +8 -3
  3. package/aot/app-file-loader.mjs +116 -0
  4. package/aot/compile.mjs +180 -90
  5. package/aot/compiler/animations.mjs +568 -317
  6. package/aot/compiler/boot.mjs +97 -35
  7. package/aot/compiler/branch-merge.mjs +4 -3
  8. package/aot/compiler/check.mjs +70 -18
  9. package/aot/compiler/collect.mjs +787 -288
  10. package/aot/compiler/contexts.mjs +391 -0
  11. package/aot/compiler/control-flow.mjs +439 -268
  12. package/aot/compiler/custom-hooks.mjs +686 -0
  13. package/aot/compiler/diagnostics.mjs +22 -25
  14. package/aot/compiler/elements/activity-indicator.mjs +25 -24
  15. package/aot/compiler/elements/button.mjs +182 -0
  16. package/aot/compiler/elements/dial.mjs +91 -77
  17. package/aot/compiler/elements/flat-list.mjs +24 -22
  18. package/aot/compiler/elements/image-background.mjs +76 -0
  19. package/aot/compiler/elements/image.mjs +52 -50
  20. package/aot/compiler/elements/modal.mjs +31 -30
  21. package/aot/compiler/elements/props.mjs +61 -26
  22. package/aot/compiler/elements/rewrite.mjs +118 -0
  23. package/aot/compiler/elements/section-list.mjs +370 -0
  24. package/aot/compiler/elements/switch.mjs +42 -34
  25. package/aot/compiler/elements/text-input.mjs +34 -32
  26. package/aot/compiler/expressions.mjs +1685 -392
  27. package/aot/compiler/handlers.mjs +2029 -547
  28. package/aot/compiler/helper-values.mjs +312 -0
  29. package/aot/compiler/ir/functions.mjs +11 -1
  30. package/aot/compiler/ir/nodes.mjs +43 -4
  31. package/aot/compiler/ir/reads.mjs +223 -22
  32. package/aot/compiler/ir/text.mjs +5 -1
  33. package/aot/compiler/ir/types.mjs +26 -14
  34. package/aot/compiler/ir/vectors.mjs +5 -1
  35. package/aot/compiler/kept-states.mjs +177 -0
  36. package/aot/compiler/keyboard.mjs +17 -7
  37. package/aot/compiler/list-items.mjs +226 -0
  38. package/aot/compiler/list-order.mjs +586 -0
  39. package/aot/compiler/list-split.mjs +259 -0
  40. package/aot/compiler/loops.mjs +582 -0
  41. package/aot/compiler/lower.mjs +246 -111
  42. package/aot/compiler/native-files.mjs +439 -0
  43. package/aot/compiler/native-header.mjs +335 -0
  44. package/aot/compiler/native-modules.mjs +1173 -0
  45. package/aot/compiler/nodes.mjs +195 -172
  46. package/aot/compiler/options.mjs +37 -31
  47. package/aot/compiler/out.mjs +32 -23
  48. package/aot/compiler/package/animations.mjs +779 -0
  49. package/aot/compiler/package/arena.mjs +252 -0
  50. package/aot/compiler/package/assemble.mjs +175 -0
  51. package/aot/compiler/package/bytecode.mjs +315 -0
  52. package/aot/compiler/package/checks.mjs +1026 -0
  53. package/aot/compiler/package/codegen.mjs +2168 -0
  54. package/aot/compiler/package/enums.mjs +148 -0
  55. package/aot/compiler/package/format.mjs +771 -0
  56. package/aot/compiler/package/layouts.mjs +136 -0
  57. package/aot/compiler/package/lower.mjs +2103 -0
  58. package/aot/compiler/package/props.mjs +118 -0
  59. package/aot/compiler/package/string-caps.mjs +515 -0
  60. package/aot/compiler/package/tables.mjs +127 -0
  61. package/aot/compiler/package/vectors.mjs +502 -0
  62. package/aot/compiler/package/writer.mjs +686 -0
  63. package/aot/compiler/pan-responder.mjs +69 -61
  64. package/aot/compiler/parse.mjs +23 -21
  65. package/aot/compiler/record-shapes.mjs +246 -0
  66. package/aot/compiler/records.mjs +654 -0
  67. package/aot/compiler/reducers.mjs +272 -0
  68. package/aot/compiler/static-eval.mjs +340 -30
  69. package/aot/compiler/style-text.mjs +178 -174
  70. package/aot/compiler/svg.mjs +480 -251
  71. package/aot/compiler/switch-cases.mjs +198 -0
  72. package/aot/compiler/tagged-records.mjs +450 -0
  73. package/aot/compiler/typing.mjs +307 -0
  74. package/aot/compiler/updaters.mjs +320 -0
  75. package/aot/compiler/window-dimensions.mjs +94 -0
  76. package/aot/compiler/worked-values.mjs +319 -0
  77. package/aot/demo-file.mjs +30 -0
  78. package/aot/screenshot-smoke.mjs +54 -40
  79. package/aot/style-map.mjs +152 -92
  80. package/assets/bake-font.mjs +123 -77
  81. package/assets/bake-image.mjs +39 -22
  82. package/assets/bake-svg.mjs +361 -262
  83. package/assets/build-builtin-font.mjs +11 -7
  84. package/assets/emit-c.mjs +77 -58
  85. package/assets/emit-container.mjs +123 -37
  86. package/assets/emit-pack.mjs +77 -67
  87. package/assets/font-config.mjs +9 -6
  88. package/assets/font-sizes.mjs +163 -123
  89. package/assets/glyph-coverage.mjs +74 -54
  90. package/assets/index.mjs +31 -9
  91. package/assets/rasterize.mjs +126 -99
  92. package/assets/svg-loader.mjs +8 -8
  93. package/build.mjs +23 -13
  94. package/cli.mjs +402 -172
  95. package/compile-bin.mjs +3 -3
  96. package/flash.mjs +537 -0
  97. package/hotreload/dev-device.mjs +90 -33
  98. package/hotreload/pack-app.mjs +55 -43
  99. package/hotreload/pack-split.mjs +62 -64
  100. package/hotreload/package-transfer.mjs +175 -0
  101. package/hotreload/protocol.mjs +50 -37
  102. package/hotreload/uploader.mjs +38 -27
  103. package/hotreload/watch-tree.mjs +19 -19
  104. package/pack-container.mjs +37 -21
  105. package/package.json +7 -8
  106. package/persist-transform.mjs +34 -28
  107. package/qjsc-wasm.mjs +25 -14
  108. package/sim/embedded-react.cjs +1 -1
  109. package/sim/embedded-react.js +1 -1
  110. package/sim/embedded-react.wasm +0 -0
  111. package/sim/index.html +94 -85
  112. package/sim-server.mjs +113 -94
  113. package/src/embedded-react/Animated.js +24 -24
  114. package/src/embedded-react/Dimensions.js +37 -0
  115. package/src/embedded-react/Easing.js +1 -1
  116. package/src/embedded-react/FlatList.js +3 -3
  117. package/src/embedded-react/LayoutAnimation.js +8 -5
  118. package/src/embedded-react/PanResponder.js +75 -71
  119. package/src/embedded-react/Pressable.js +2 -8
  120. package/src/embedded-react/SectionList.js +7 -9
  121. package/src/embedded-react/StyleSheet.js +4 -3
  122. package/src/embedded-react/TouchableOpacity.js +13 -8
  123. package/src/embedded-react/index.d.ts +88 -8
  124. package/src/embedded-react/index.js +2 -0
  125. package/src/embedded-react/layout-anim-config.js +10 -4
  126. package/src/embedded-react/list-child.js +5 -5
  127. package/src/embedded-react/named-colors.js +1 -1
  128. package/src/embedded-react/nativeModule.js +462 -0
  129. package/src/embedded-react/split-style.js +11 -11
  130. package/src/embedded-react/svg-ops.js +760 -593
  131. package/src/embedded-react/useHostValue.js +3 -3
  132. package/src/embedded-react/usePersistentState.js +6 -6
  133. package/src/embedded-react/warn-props.js +1 -1
  134. package/src/host-config.js +60 -53
  135. package/src/props.js +49 -41
  136. package/src/renderer.js +7 -4
  137. package/aot/compiler/assemble.mjs +0 -944
  138. package/aot/compiler/c/animations.mjs +0 -436
  139. package/aot/compiler/c/boot.mjs +0 -127
  140. package/aot/compiler/c/expressions.mjs +0 -270
  141. package/aot/compiler/c/functions.mjs +0 -268
  142. package/aot/compiler/c/keyboard.mjs +0 -96
  143. package/aot/compiler/c/nodes.mjs +0 -303
  144. package/aot/compiler/c/pan-responder.mjs +0 -136
  145. package/aot/compiler/c/statements.mjs +0 -319
  146. package/aot/compiler/c/text.mjs +0 -83
  147. package/aot/compiler/c/vectors.mjs +0 -381
  148. package/aot/compiler/c-syntax.mjs +0 -127
@@ -23,8 +23,8 @@
23
23
  //
24
24
  // const pan = useRef(PanResponder.create({
25
25
  // onStartShouldSetPanResponder: () => true,
26
- // onPanResponderMove: (e, g) => setX(g.dx),
27
- // onPanResponderRelease: (e, g) => (g.vx > 0.5 ? next() : settle()),
26
+ // onPanResponderMove: (event, gesture) => setX(gesture.dx),
27
+ // onPanResponderRelease: (event, gesture) => (gesture.vx > 0.5 ? next() : settle()),
28
28
  // })).current;
29
29
  //
30
30
  // <View {...pan.panHandlers} />
@@ -86,7 +86,8 @@ const SUPPORTED = [
86
86
  * The engine's monotonic millisecond clock, used for velocity. `performance.now()` is installed by the
87
87
  * QuickJS runtime on every context (it is React's scheduler clock) and exists in the simulator and in
88
88
  * Node; `Date.now()` jumps whenever the host sets the wall clock, so it is never used here.
89
- * The clock only advances when the host ticks, so a dt of 0 is normal and leaves velocity untouched.
89
+ * The clock only advances when the host ticks, so an elapsed time of 0 is normal and leaves velocity
90
+ * untouched.
90
91
  */
91
92
  const now = () =>
92
93
  typeof performance !== 'undefined' && typeof performance.now === 'function'
@@ -108,10 +109,10 @@ function asConfig(config) {
108
109
  /** Warns ONCE PER KEY about config keys this module does not act on. */
109
110
  function warnUnsupportedConfig(config) {
110
111
  const names = Object.keys(config).filter(
111
- k => !SUPPORTED.includes(k) && !s_warnedKeys.has(k),
112
+ key => !SUPPORTED.includes(key) && !s_warnedKeys.has(key),
112
113
  );
113
114
  if (names.length === 0) return;
114
- for (const k of names) s_warnedKeys.add(k);
115
+ for (const key of names) s_warnedKeys.add(key);
115
116
  console.warn(
116
117
  `embedded-react: PanResponder ignores ${names.join(', ')} — ` +
117
118
  `supported: ${SUPPORTED.join(', ')}.`,
@@ -122,17 +123,17 @@ function warnUnsupportedConfig(config) {
122
123
  * Clears the travel/velocity fields between gestures. `numberActiveTouches` is deliberately left alone:
123
124
  * it counts fingers on the panel, which outlives the gesture when a second finger is still down.
124
125
  *
125
- * @param {object} g The gesture state to reset in place.
126
+ * @param {object} gestureState The gesture state to reset in place.
126
127
  */
127
- function resetGestureState(g) {
128
- g.moveX = 0;
129
- g.moveY = 0;
130
- g.x0 = 0;
131
- g.y0 = 0;
132
- g.dx = 0;
133
- g.dy = 0;
134
- g.vx = 0;
135
- g.vy = 0;
128
+ function resetGestureState(gestureState) {
129
+ gestureState.moveX = 0;
130
+ gestureState.moveY = 0;
131
+ gestureState.x0 = 0;
132
+ gestureState.y0 = 0;
133
+ gestureState.dx = 0;
134
+ gestureState.dy = 0;
135
+ gestureState.vx = 0;
136
+ gestureState.vy = 0;
136
137
  }
137
138
 
138
139
  /**
@@ -170,62 +171,63 @@ export function create(userConfig = {}) {
170
171
 
171
172
  let granted = false;
172
173
  let lastMoveTime = 0;
173
- // The engine measures e.dx/e.dy from TOUCH-DOWN; RN (and this module) measure g.dx/g.dy from the
174
- // GRANT — a responder that needed 10px of slop to claim starts its own travel at zero, so the slop
175
- // never shows up as a jump. The base is what e.dx read at the moment of the grant.
174
+ // The engine measures event.dx/event.dy from TOUCH-DOWN; RN (and this module) measure
175
+ // gestureState.dx/dy from the GRANT — a responder that needed 10px of slop to claim starts its own
176
+ // travel at zero, so the slop never shows up as a jump. The base is what event.dx read at the moment
177
+ // of the grant.
176
178
  let baseDx = 0;
177
179
  let baseDy = 0;
178
180
 
179
- const fire = (name, e) => {
180
- if (typeof config[name] === 'function') config[name](e, gestureState);
181
+ const fire = (name, event) => {
182
+ if (typeof config[name] === 'function') config[name](event, gestureState);
181
183
  };
182
184
 
183
- /** Folds one engine payload (e.x/e.y absolute, e.dx/e.dy from touch-down) into the travel fields. */
184
- const advance = e => {
185
- gestureState.moveX = e.x;
186
- gestureState.moveY = e.y;
187
- gestureState.dx = e.dx - baseDx;
188
- gestureState.dy = e.dy - baseDy;
185
+ /** Folds one engine payload (event.x/y absolute, event.dx/dy from touch-down) into the travel fields. */
186
+ const advance = event => {
187
+ gestureState.moveX = event.x;
188
+ gestureState.moveY = event.y;
189
+ gestureState.dx = event.dx - baseDx;
190
+ gestureState.dy = event.dy - baseDy;
189
191
  };
190
192
 
191
193
  /** A move: travel, plus a fresh velocity reading over the time since the last one. */
192
- const track = e => {
193
- const t = now();
194
- const dt = t - lastMoveTime;
195
- const prevDx = gestureState.dx;
196
- const prevDy = gestureState.dy;
194
+ const track = event => {
195
+ const time = now();
196
+ const elapsed = time - lastMoveTime;
197
+ const previousDx = gestureState.dx;
198
+ const previousDy = gestureState.dy;
197
199
 
198
- advance(e);
200
+ advance(event);
199
201
 
200
- // dt is 0 whenever two touches land inside one host frame (the clock only moves on er_tick), and
201
- // the division would be Infinity. Keeping the previous velocity is the honest answer: nothing new
202
- // has been measured yet.
203
- if (dt > 0) {
204
- gestureState.vx = (gestureState.dx - prevDx) / dt;
205
- gestureState.vy = (gestureState.dy - prevDy) / dt;
202
+ // The elapsed time is 0 whenever two touches land inside one host frame (the clock only moves on
203
+ // er_tick), and the division would be Infinity. Keeping the previous velocity is the honest
204
+ // answer: nothing new has been measured yet.
205
+ if (elapsed > 0) {
206
+ gestureState.vx = (gestureState.dx - previousDx) / elapsed;
207
+ gestureState.vy = (gestureState.dy - previousDy) / elapsed;
206
208
  }
207
- lastMoveTime = t;
209
+ lastMoveTime = time;
208
210
  };
209
211
 
210
212
  /** Wraps a should-set predicate as an engine query: track the point, ask, absent means "no" (as in RN). */
211
213
  const query = name =>
212
214
  typeof config[name] === 'function'
213
- ? e => {
214
- if (!granted) advance(e);
215
- return config[name](e, gestureState) === true;
215
+ ? event => {
216
+ if (!granted) advance(event);
217
+ return config[name](event, gestureState) === true;
216
218
  }
217
219
  : undefined;
218
220
 
219
221
  /** Ends the gesture: reports it if this responder owned it, then clears the state for the next one. */
220
- const finish = (e, callback) => {
222
+ const finish = (event, callback) => {
221
223
  const wasGranted = granted;
222
224
  granted = false;
223
225
  // Fold the final point into the travel so `dx` is the gesture's true total even when the finger
224
226
  // lifted without a final move — but leave vx/vy at the last MOVE's reading. A fling ends with the
225
227
  // finger resting for a frame or two, and re-measuring across that would report zero and throw the
226
228
  // throw away.
227
- advance(e);
228
- if (wasGranted) fire(callback, e);
229
+ advance(event);
230
+ if (wasGranted) fire(callback, event);
229
231
  resetGestureState(gestureState);
230
232
  baseDx = 0;
231
233
  baseDy = 0;
@@ -233,7 +235,7 @@ export function create(userConfig = {}) {
233
235
 
234
236
  const panHandlers = {
235
237
  // --- Raw touch bookkeeping (bubbles per finger): finger count + Start/End for extra fingers ---
236
- onTouchStart(e) {
238
+ onTouchStart(event) {
237
239
  gestureState.numberActiveTouches += 1;
238
240
  // A later finger joins the gesture in flight (the engine events carry no finger id, so
239
241
  // independent tracking is impossible). Its own touch slot re-negotiates and re-grants this
@@ -242,19 +244,19 @@ export function create(userConfig = {}) {
242
244
  resetGestureState(gestureState);
243
245
  baseDx = 0;
244
246
  baseDy = 0;
245
- gestureState.x0 = e.x;
246
- gestureState.y0 = e.y;
247
- gestureState.moveX = e.x;
248
- gestureState.moveY = e.y;
247
+ gestureState.x0 = event.x;
248
+ gestureState.y0 = event.y;
249
+ gestureState.moveX = event.x;
250
+ gestureState.moveY = event.y;
249
251
  lastMoveTime = now();
250
252
  },
251
- onTouchEnd(e) {
253
+ onTouchEnd(event) {
252
254
  if (gestureState.numberActiveTouches > 0)
253
255
  gestureState.numberActiveTouches -= 1;
254
256
  // A finger lifted but the gesture continues; the RELEASE for the last one arrives as a
255
257
  // responder event below.
256
258
  if (granted && gestureState.numberActiveTouches > 0)
257
- fire('onPanResponderEnd', e);
259
+ fire('onPanResponderEnd', event);
258
260
  },
259
261
  onTouchCancel() {
260
262
  gestureState.numberActiveTouches = 0;
@@ -271,53 +273,55 @@ export function create(userConfig = {}) {
271
273
  ),
272
274
  onResponderTerminationRequest:
273
275
  typeof config.onPanResponderTerminationRequest === 'function'
274
- ? e => config.onPanResponderTerminationRequest(e, gestureState) === true
276
+ ? event =>
277
+ config.onPanResponderTerminationRequest(event, gestureState) ===
278
+ true
275
279
  : undefined, // absent → the engine's default: yield (RN's default too)
276
280
 
277
281
  // --- Responder lifecycle (native events; fire only on the node that owns the gesture) ---
278
- onResponderGrant(e) {
282
+ onResponderGrant(event) {
279
283
  if (granted) {
280
284
  // A second finger's touch slot granted the same node: one gesture, not two. RN calls this a
281
285
  // responder "start" for the extra touch.
282
- fire('onPanResponderStart', e);
286
+ fire('onPanResponderStart', event);
283
287
  return;
284
288
  }
285
289
  granted = true;
286
- baseDx = e.dx;
287
- baseDy = e.dy;
288
- gestureState.x0 = e.x;
289
- gestureState.y0 = e.y;
290
+ baseDx = event.dx;
291
+ baseDy = event.dy;
292
+ gestureState.x0 = event.x;
293
+ gestureState.y0 = event.y;
290
294
  gestureState.dx = 0;
291
295
  gestureState.dy = 0;
292
296
  lastMoveTime = now();
293
- fire('onPanResponderGrant', e);
297
+ fire('onPanResponderGrant', event);
294
298
  },
295
- onResponderMove(e) {
299
+ onResponderMove(event) {
296
300
  if (!granted) return;
297
- track(e);
298
- fire('onPanResponderMove', e);
301
+ track(event);
302
+ fire('onPanResponderMove', event);
299
303
  },
300
- onResponderRelease(e) {
304
+ onResponderRelease(event) {
301
305
  if (!granted) return;
302
306
  // Another finger still down: its touch slot keeps the responder, so the gesture continues (the
303
307
  // raw onTouchEnd above already reported the End).
304
308
  if (gestureState.numberActiveTouches > 0) return;
305
- finish(e, 'onPanResponderRelease');
309
+ finish(event, 'onPanResponderRelease');
306
310
  },
307
- onResponderTerminate(e) {
311
+ onResponderTerminate(event) {
308
312
  if (!granted) return;
309
313
  gestureState.numberActiveTouches = 0;
310
- finish(e, 'onPanResponderTerminate');
314
+ finish(event, 'onPanResponderTerminate');
311
315
  },
312
- onResponderReject(e) {
313
- fire('onPanResponderReject', e);
316
+ onResponderReject(event) {
317
+ fire('onPanResponderReject', event);
314
318
  },
315
319
  };
316
320
 
317
321
  // Absent queries must not appear as props at all (an undefined on* prop is skipped by the host
318
322
  // config anyway, but a clean bag is easier to reason about and to spread).
319
- for (const k of Object.keys(panHandlers)) {
320
- if (panHandlers[k] === undefined) delete panHandlers[k];
323
+ for (const key of Object.keys(panHandlers)) {
324
+ if (panHandlers[key] === undefined) delete panHandlers[key];
321
325
  }
322
326
 
323
327
  return {panHandlers};
@@ -38,14 +38,8 @@ import {Pressable as HostPressable} from './components.js';
38
38
  * @returns {*} A host <Pressable> element.
39
39
  */
40
40
  export const Pressable = forwardRef(function Pressable(props = {}, ref) {
41
- const {
42
- disabled,
43
- onPress,
44
- onLongPress,
45
- onPressIn,
46
- onPressOut,
47
- ...rest
48
- } = props;
41
+ const {disabled, onPress, onLongPress, onPressIn, onPressOut, ...rest} =
42
+ props;
49
43
 
50
44
  return createElement(HostPressable, {
51
45
  ...rest,
@@ -33,9 +33,7 @@
33
33
  // stays mounted. Size `sections x (1 + rows) x nodes-per-row` against ERUI_MAX_NODES before writing
34
34
  // the screen.
35
35
  //
36
- // Unlike <FlatList>, this has no Flow B counterpart yet — the AOT unrolls one `.map` per container
37
- // and a section expands to a header AND a variable number of rows. It is a Flow A / simulator
38
- // component until that lands; the AOT says so by name rather than "unknown element".
36
+ // Flow B builds the same tree, unrolling the sections at build time (aot/compiler/elements/section-list.mts).
39
37
  import {createElement} from 'react';
40
38
  import {ScrollView} from './components.js';
41
39
  import {pushKeyedChild} from './list-child.js';
@@ -91,12 +89,12 @@ export function SectionList(props = {}) {
91
89
 
92
90
  const children = [];
93
91
  if (Array.isArray(sections)) {
94
- for (let s = 0; s < sections.length; s++) {
95
- const section = sections[s];
92
+ for (let sectionIndex = 0; sectionIndex < sections.length; sectionIndex++) {
93
+ const section = sections[sectionIndex];
96
94
  if (section === null || typeof section !== 'object') continue;
97
95
  const sectionKey =
98
96
  section.key === null || section.key === undefined
99
- ? String(s)
97
+ ? String(sectionIndex)
100
98
  : String(section.key);
101
99
 
102
100
  if (typeof renderSectionHeader === 'function')
@@ -120,11 +118,11 @@ export function SectionList(props = {}) {
120
118
  const row = rowRenderer({item, index, section});
121
119
  // Built lazily, so keyExtractor never runs for a row that rendered nothing or for a raw
122
120
  // string — see pushKeyedChild.
123
- pushKeyedChild(children, row, el => {
121
+ pushKeyedChild(children, row, element => {
124
122
  const key = rowKey
125
123
  ? String(rowKey(item, index))
126
- : el.key !== null && el.key !== undefined
127
- ? el.key
124
+ : element.key !== null && element.key !== undefined
125
+ ? element.key
128
126
  : String(index);
129
127
  return `${sectionKey}:${key}`;
130
128
  });
@@ -24,9 +24,10 @@ export const StyleSheet = {
24
24
  flatten(style) {
25
25
  if (!style) return {};
26
26
  if (Array.isArray(style)) {
27
- const out = {};
28
- for (const s of style) Object.assign(out, StyleSheet.flatten(s));
29
- return out;
27
+ const flattened = {};
28
+ for (const entry of style)
29
+ Object.assign(flattened, StyleSheet.flatten(entry));
30
+ return flattened;
30
31
  }
31
32
  return style;
32
33
  },
@@ -22,7 +22,7 @@
22
22
  // <Pressable style={[styles.tile, {opacity: dim}]} onPressIn={…} onPressOut={…}>…</Pressable>
23
23
  //
24
24
  // The fade is a native-driver animation, not a re-render: the two press handlers hand the engine a
25
- // target opacity and a duration, and it runs the ramp in C (er_anim_value_*). Nothing re-enters JS per
25
+ // target opacity and a duration, and it runs the ramp in C (er_animation_value_*). Nothing re-enters JS per
26
26
  // frame, and the subtree React just built is not touched at all.
27
27
  //
28
28
  // Worth knowing before wrapping a whole screen in one: an opacity below 1 makes the Pressable an
@@ -45,6 +45,7 @@ import {flattenStyleObj} from '../props.js';
45
45
  // RN's own numbers (Libraries/Components/Touchable/TouchableOpacity.js): the dim lands on touch-down
46
46
  // with no ramp at all and fades back over a quarter second once the finger lifts.
47
47
  const DEFAULT_ACTIVE_OPACITY = 0.2;
48
+ const FULLY_OPAQUE = 1;
48
49
  const DIM_MS = 0;
49
50
  const RESTORE_MS = 250;
50
51
 
@@ -52,8 +53,8 @@ let warnedAnimatedOpacity = false;
52
53
 
53
54
  /** The opacity the touchable rests at — whatever its style asks for, fully opaque if it asks nothing. */
54
55
  function restingOpacity(style) {
55
- const o = flattenStyleObj(style).opacity;
56
- if (o && o.__animated) {
56
+ const opacity = flattenStyleObj(style).opacity;
57
+ if (opacity && opacity.__animated) {
57
58
  if (!warnedAnimatedOpacity) {
58
59
  warnedAnimatedOpacity = true;
59
60
  console.warn(
@@ -62,14 +63,18 @@ function restingOpacity(style) {
62
63
  'onPressIn/onPressOut driving an Animated.Value.',
63
64
  );
64
65
  }
65
- return 1;
66
+ return FULLY_OPAQUE;
66
67
  }
67
- return typeof o === 'number' ? o : 1;
68
+ return typeof opacity === 'number' ? opacity : FULLY_OPAQUE;
68
69
  }
69
70
 
70
- /** Runs `value` to `to` over `ms` on the native driver (a 0 ms ramp snaps, without taking a slot). */
71
- function fadeTo(value, to, ms) {
72
- timing(value, {toValue: to, duration: ms, easing: Easing.quadInOut}).start();
71
+ /** Runs `value` to `target` over `durationMs` on the native driver (a 0 ms ramp snaps, without taking a slot). */
72
+ function fadeTo(value, target, durationMs) {
73
+ timing(value, {
74
+ toValue: target,
75
+ duration: durationMs,
76
+ easing: Easing.quadInOut,
77
+ }).start();
73
78
  }
74
79
 
75
80
  /**
@@ -182,7 +182,7 @@ export interface ViewStyle {
182
182
  transform?: TransformStyle[];
183
183
  transformOrigin?: TransformOrigin;
184
184
 
185
- // Shadow. Rendered only in a build with shadows enabled (ERUI_SHADOWS) and `shadowOpacity` above 0.
185
+ // Shadow. Rendered only in a build with shadows enabled (ERUI_SHADOWS), by `shadowOpacity` above 0 or an `elevation`.
186
186
  shadowColor?: string;
187
187
  shadowOffset?: ShadowOffset;
188
188
  shadowOpacity?: number;
@@ -434,8 +434,8 @@ export interface FlatListProps<T = unknown> {
434
434
  /**
435
435
  * `<SectionList>` is a thin `<ScrollView>` alias like `<FlatList>` — no virtualization, no sticky
436
436
  * headers, and every header, row and footer mounts as a real engine node and stays mounted. Header,
437
- * rows and footer are flat siblings, exactly as in RN. Flow A / simulator only for now: the AOT has no
438
- * `<SectionList>` lowering yet.
437
+ * rows and footer are flat siblings, exactly as in RN. Flow B unrolls the sections at build time, so
438
+ * write them out in place or use a constant array.
439
439
  */
440
440
  export interface SectionListProps<ItemT = unknown, SectionT = DefaultSectionT> {
441
441
  sections?: ReadonlyArray<SectionListData<ItemT, SectionT>>;
@@ -670,9 +670,9 @@ export interface SvgPaintProps {
670
670
  strokeMiterlimit?: SvgNumber;
671
671
  fillRule?: 'nonzero' | 'evenodd';
672
672
  /** Fills with a gradient instead of the solid `fill`. */
673
- fillGrad?: VectorGradient;
673
+ fillGradient?: VectorGradient;
674
674
  /** Strokes with a gradient instead of the solid `stroke`. */
675
- strokeGrad?: VectorGradient;
675
+ strokeGradient?: VectorGradient;
676
676
  }
677
677
 
678
678
  /** A `.svg` import: the build bakes it to a vector op-tape, or to a raster asset when it uses features the
@@ -788,6 +788,23 @@ export const Platform: {
788
788
  select<T>(specifics: Record<string, T>): T | undefined;
789
789
  };
790
790
 
791
+ // --- Dimensions ------------------------------------------------------------
792
+ /** The panel's size in pixels. `scale` and `fontScale` are always 1. */
793
+ export interface ScaledSize {
794
+ width: number;
795
+ height: number;
796
+ scale: number;
797
+ fontScale: number;
798
+ }
799
+
800
+ export const Dimensions: {
801
+ /** The panel's size. 'window' and 'screen' are the same on a panel. */
802
+ get(dimension: 'window' | 'screen'): ScaledSize;
803
+ };
804
+
805
+ /** The panel's size. It is fixed while the app runs. */
806
+ export function useWindowDimensions(): ScaledSize;
807
+
791
808
  // --- AppRegistry -----------------------------------------------------------
792
809
  export const AppRegistry: {
793
810
  registerComponent(
@@ -929,6 +946,69 @@ export function usePersistentState<S>(
929
946
  ): [S, (value: S | ((prev: S) => S)) => void];
930
947
 
931
948
  export function useHostValue(initial: number): number;
949
+
950
+ /** A whole number. A native method's `Int` is an int in C, where a `number` is a float. */
951
+ export type Int = number;
952
+
953
+ /**
954
+ * A whole number that may be past an Int's range: a native method's `Int64` is an int64_t in C. In JS it is a number,
955
+ * so it is exact up to 2^53.
956
+ */
957
+ export type Int64 = number;
958
+
959
+ /** An optional native module, as nativeModule.optional returns it. */
960
+ export type OptionalNativeModule<T> = T & {
961
+ /** Whether the firmware has every method and event of the module. Set at load, and it never changes. */
962
+ readonly available: boolean;
963
+ };
964
+
965
+ /**
966
+ * A module the firmware provides in C, declared at module level by an interface of its methods, which take and
967
+ * return Int, Int64, number, boolean, string and records of them:
968
+ * `const Sensors = nativeModule<Sensors>('sensors', 1)`. Its events are the interface's `events`:
969
+ * `events: {reading(celsius: number): void}`.
970
+ */
971
+ export const nativeModule: {
972
+ <T>(name: string, version: number): T;
973
+ /**
974
+ * A module only some boards have: `const Wifi = nativeModule.optional<Wifi>('wifi', 1)`. A package that uses it
975
+ * loads without it, and `Wifi.available` says whether it is there. Calling a method of a module that isn't stops
976
+ * the app; its events never arrive.
977
+ */
978
+ optional<T>(name: string, version: number): OptionalNativeModule<T>;
979
+ };
980
+
981
+ /** The events a native module's interface declares. */
982
+ export type NativeEvents<T> = T extends {events: infer E} ? E : {};
983
+
984
+ /** The values an event is posted with. */
985
+ export type NativeEventValues<
986
+ T,
987
+ K extends keyof NativeEvents<T>,
988
+ > = NativeEvents<T>[K] extends (...values: infer V) => void ? V : never;
989
+
990
+ /**
991
+ * Runs `handler` with an event's values each time the firmware posts it, while the component is mounted:
992
+ * `useNativeEvent(Sensors, 'reading', celsius => setTemperature(celsius))`.
993
+ */
994
+ export function useNativeEvent<T, K extends keyof NativeEvents<T> & string>(
995
+ module: T,
996
+ event: K,
997
+ handler: (...values: NativeEventValues<T, K>) => void,
998
+ ): void;
999
+
1000
+ /** Posts one of a mocked module's events, as the firmware would. false while one of the mock's methods runs. */
1001
+ export type NativeEmit<T> = <K extends keyof NativeEvents<T> & string>(
1002
+ event: K,
1003
+ ...values: NativeEventValues<T, K>
1004
+ ) => boolean;
1005
+
1006
+ /**
1007
+ * A native module's mock for the simulators, the default export of `<name>.mock.ts`: its methods, or a function
1008
+ * that is given `emit` and returns them.
1009
+ */
1010
+ export type NativeMock<T> =
1011
+ Omit<T, 'events'> | ((emit: NativeEmit<T>) => Omit<T, 'events'>);
932
1012
  export const Easing: {readonly [K in EasingName]: K} & {
933
1013
  bezier(x1: number, y1: number, x2: number, y2: number): BezierEasing;
934
1014
  };
@@ -1058,8 +1138,8 @@ export interface VectorShape {
1058
1138
  cap?: 'butt' | 'round' | 'square';
1059
1139
  join?: 'miter' | 'round' | 'bevel';
1060
1140
  fillRule?: 'nonzero' | 'evenodd';
1061
- fillGrad?: VectorGradient;
1062
- strokeGrad?: VectorGradient;
1141
+ fillGradient?: VectorGradient;
1142
+ strokeGradient?: VectorGradient;
1063
1143
  }
1064
1144
 
1065
1145
  /**
@@ -1103,7 +1183,7 @@ export interface KeyboardConfig {
1103
1183
  rowHeight?: number;
1104
1184
  keyGap?: number;
1105
1185
  keyRadius?: number;
1106
- gridCols?: number;
1186
+ gridColumns?: number;
1107
1187
  layers?: KeyboardKey[][][];
1108
1188
  }
1109
1189
 
@@ -49,10 +49,12 @@ export {SectionList} from './SectionList.js';
49
49
  export {updateVector, updateText, setKeyboardConfig} from './imperative.js';
50
50
  export {StyleSheet} from './StyleSheet.js';
51
51
  export {Platform} from './Platform.js';
52
+ export {Dimensions, useWindowDimensions} from './Dimensions.js';
52
53
  export {AppRegistry} from './AppRegistry.js';
53
54
  export {Animated, useAnimatedValue} from './Animated.js';
54
55
  export {PanResponder} from './PanResponder.js';
55
56
  export {usePersistentState} from './usePersistentState.js';
56
57
  export {useHostValue} from './useHostValue.js';
58
+ export {nativeModule, useNativeEvent} from './nativeModule.js';
57
59
  export {Easing} from './Easing.js';
58
60
  export {LayoutAnimation} from './LayoutAnimation.js';
@@ -18,6 +18,9 @@
18
18
  // Node (see __tests__/layout-animation.unit.test.js). LayoutAnimation.js wires configureNext to the
19
19
  // bridge using these.
20
20
 
21
+ /** Duration when a config gives none, as in RN. */
22
+ export const DEFAULT_DURATION_MS = 300;
23
+
21
24
  /** RN-compatible animation type tokens. */
22
25
  export const Types = {
23
26
  spring: 'spring',
@@ -58,10 +61,13 @@ function easingForType(type) {
58
61
  * are accepted for parity but not separately animated.
59
62
  */
60
63
  export function toEngineConfig(config) {
61
- const c = config || {};
62
- const duration = typeof c.duration === 'number' ? c.duration : 300;
63
- const update = c.update || {};
64
- const type = update.type || c.type || Types.easeInEaseOut;
64
+ const options = config || {};
65
+ const duration =
66
+ typeof options.duration === 'number'
67
+ ? options.duration
68
+ : DEFAULT_DURATION_MS;
69
+ const update = options.update || {};
70
+ const type = update.type || options.type || Types.easeInEaseOut;
65
71
  if (type === Types.spring) {
66
72
  return {type: 'spring', duration};
67
73
  }
@@ -28,7 +28,7 @@ export const isElement = node =>
28
28
  node !== null && typeof node === 'object' && node.$$typeof !== undefined;
29
29
 
30
30
  /**
31
- * Appends one rendered row to `out`, keyed, or drops it if it rendered nothing.
31
+ * Appends one rendered row to `children`, keyed, or drops it if it rendered nothing.
32
32
  *
33
33
  * Callers own the key because they know what makes one unique (a SectionList's rows are siblings
34
34
  * across sections, a FlatList's are not). A row that is not an element goes in untouched: there is no
@@ -39,16 +39,16 @@ export const isElement = node =>
39
39
  * nothing, or for a raw string that cannot be cloned, is both wasted work on the commit path and a
40
40
  * side effect the app never asked for. Passing the key by value invites exactly that, and did.
41
41
  *
42
- * @param {Array} out The child list being built.
42
+ * @param {Array} children The child list being built.
43
43
  * @param {*} node Whatever the render callback returned.
44
44
  * @param {(element: object) => string} keyFor Builds the React key, given the keyable element.
45
45
  */
46
- export function pushKeyedChild(out, node, keyFor) {
46
+ export function pushKeyedChild(children, node, keyFor) {
47
47
  if (rendersNothing(node)) return;
48
48
  if (!isElement(node)) {
49
- out.push(node);
49
+ children.push(node);
50
50
  return;
51
51
  }
52
52
  const key = keyFor(node);
53
- out.push(node.key === key ? node : cloneElement(node, {key}));
53
+ children.push(node.key === key ? node : cloneElement(node, {key}));
54
54
  }
@@ -15,7 +15,7 @@
15
15
  */
16
16
 
17
17
  // The named colors every path accepts, as ARGB8888 with their CSS values. Keys are lowercase; callers
18
- // lowercase the name first. The bridge's k_named table (native_ui_bridge.c) must list the same entries.
18
+ // lowercase the name first. The bridge's k_named_colors table (native_ui_bridge.c) must list the same entries.
19
19
  // No prototype, so `name in NAMED_COLORS` never finds `toString` and friends.
20
20
 
21
21
  /** @type {Readonly<Record<string, number>>} */