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
package/sim-server.mjs CHANGED
@@ -53,11 +53,16 @@ const {registerSvgVectorLoader} = await import(
53
53
  const {transformPersist, shouldPersist} = await import(
54
54
  pathToFileURL(resolve(HERE, 'persist-transform.mjs')).href
55
55
  );
56
+ const {loadAppFile, loadDependencyFile} =
57
+ await import('./aot/app-file-loader.mjs');
56
58
 
57
59
  const REACT_PIN = Object.fromEntries(
58
60
  ['react', 'react-reconciler', 'scheduler']
59
- .map(p => [p, resolve(HERE, 'node_modules', p)])
60
- .filter(([, p]) => existsSync(p)),
61
+ .map(packageName => [
62
+ packageName,
63
+ resolve(HERE, 'node_modules', packageName),
64
+ ])
65
+ .filter(([, pinPath]) => existsSync(pinPath)),
61
66
  );
62
67
 
63
68
  const MIME = {
@@ -66,10 +71,10 @@ const MIME = {
66
71
  '.wasm': 'application/wasm',
67
72
  '.pack': 'application/octet-stream',
68
73
  };
69
- const assetName = p => basename(p).replace(/\.[^.]+$/, '');
70
- const mtime = p => {
74
+ const assetName = filePath => basename(filePath).replace(/\.[^.]+$/, '');
75
+ const mtime = filePath => {
71
76
  try {
72
- return statSync(p).mtimeMs;
77
+ return statSync(filePath).mtimeMs;
73
78
  } catch {
74
79
  return 0;
75
80
  }
@@ -97,23 +102,26 @@ function createBundle({
97
102
  }) {
98
103
  const bundlePath = resolve(outDir, 'app.js');
99
104
  const packPath = resolve(outDir, 'assets.pack');
100
- const projNorm = projectRoot.replace(/\\/g, '/');
105
+ const projectRootNormalized = projectRoot.replace(/\\/g, '/');
101
106
  const images = new Map();
102
107
  const fonts = new Map();
103
- let lastAssetSig = null;
108
+ let lastAssetSignature = null;
104
109
 
105
110
  async function bakePack() {
106
- const bundleSrc = readFileSync(bundlePath, 'utf8');
107
- const usedSizes = analyzeFontSizes(bundleSrc);
111
+ const bundleSource = readFileSync(bundlePath, 'utf8');
112
+ const usedSizes = analyzeFontSizes(bundleSource);
108
113
 
109
- let cfg = {};
110
- const cp = resolve(projectRoot, 'assets.config.js');
111
- if (existsSync(cp))
112
- cfg =
113
- (await import(`${pathToFileURL(cp).href}?t=${mtime(cp)}`)).default ||
114
- {};
115
- const fontConfig = cfg.fonts || {};
116
- const imageConfig = cfg.images || {};
114
+ let assetsConfig = {};
115
+ const assetsConfigPath = resolve(projectRoot, 'assets.config.js');
116
+ if (existsSync(assetsConfigPath))
117
+ assetsConfig =
118
+ (
119
+ await import(
120
+ `${pathToFileURL(assetsConfigPath).href}?t=${mtime(assetsConfigPath)}`
121
+ )
122
+ ).default || {};
123
+ const fontConfig = assetsConfig.fonts || {};
124
+ const imageConfig = assetsConfig.images || {};
117
125
 
118
126
  const fontJobs = resolveFontJobs(fonts, fontConfig, usedSizes.sizes);
119
127
  const imageJobs = [...images.entries()].map(([name, path]) => ({
@@ -124,44 +132,46 @@ function createBundle({
124
132
 
125
133
  // The app's text is an asset input too: new characters and new font sizes must both be
126
134
  // re-checked against the bake even when no font or image file changed.
127
- const sig = JSON.stringify({
128
- t: textSignature(bundleSrc),
129
- z: fontSizeSignature(usedSizes),
130
- i: imageJobs.map(j => [j.name, j.path, mtime(j.path), j.format]).sort(),
131
- f: fontJobs
132
- .map(j => [
133
- j.family,
134
- j.path,
135
- mtime(j.path),
136
- j.sizes,
137
- j.bpp,
138
- j.glyphs,
139
- j.extraGlyphs,
135
+ const assetSignature = JSON.stringify({
136
+ text: textSignature(bundleSource),
137
+ fontSizes: fontSizeSignature(usedSizes),
138
+ images: imageJobs
139
+ .map(job => [job.name, job.path, mtime(job.path), job.format])
140
+ .sort(),
141
+ fonts: fontJobs
142
+ .map(job => [
143
+ job.family,
144
+ job.path,
145
+ mtime(job.path),
146
+ job.sizes,
147
+ job.bpp,
148
+ job.glyphs,
149
+ job.extraGlyphs,
140
150
  ])
141
151
  .sort(),
142
152
  });
143
- if (sig === lastAssetSig) return;
144
- lastAssetSig = sig;
153
+ if (assetSignature === lastAssetSignature) return;
154
+ lastAssetSignature = assetSignature;
145
155
  if (!imageJobs.length && !fontJobs.length) {
146
156
  // Built-in font only → no pack, but its glyph and size coverage still bind.
147
- warnMissingGlyphs({source: bundleSrc});
157
+ warnMissingGlyphs({source: bundleSource});
148
158
  warnFontSizes({used: usedSizes});
149
159
  return;
150
160
  }
151
161
 
152
162
  try {
153
- const s = bakeAssetPack({
163
+ const summary = bakeAssetPack({
154
164
  images: imageJobs,
155
165
  fonts: fontJobs,
156
166
  outPath: packPath,
157
- source: bundleSrc,
167
+ source: bundleSource,
158
168
  usedSizes,
159
169
  });
160
170
  console.log(
161
- ` assets → ${s.images} image(s), ${s.fonts} font size(s), ${s.bytes} B`,
171
+ ` assets → ${summary.images} image(s), ${summary.fonts} font size(s), ${summary.bytes} B`,
162
172
  );
163
- } catch (e) {
164
- console.error(` asset bake failed: ${e.message}`);
173
+ } catch (error) {
174
+ console.error(` asset bake failed: ${error.message}`);
165
175
  }
166
176
  }
167
177
 
@@ -181,52 +191,61 @@ function createBundle({
181
191
  plugins: [
182
192
  {
183
193
  name: 'embedded-react-websim',
184
- setup(b) {
185
- b.onStart(() => {
194
+ setup(pluginBuild) {
195
+ pluginBuild.onStart(() => {
186
196
  images.clear();
187
197
  fonts.clear();
188
198
  });
189
- b.onLoad({filter: /\.(jsx?|tsx?)$/}, a => {
190
- // Transform ONLY the app's own source — never dependencies (see shouldPersist: excluding
191
- // node_modules is what stops the library's usePersistentState being rewritten to call itself).
192
- if (!persist || !shouldPersist(a.path, projNorm)) return undefined;
199
+ pluginBuild.onLoad({filter: /\.(jsx?|tsx?)$/}, async loadArgs => {
200
+ // Only the app's own source — never dependencies (see shouldPersist: excluding node_modules is what
201
+ // stops the library's usePersistentState being rewritten to call itself). Native modules get their
202
+ // signatures and mocks, and with persist on, useState persists. A package's native modules get theirs too.
203
+ if (!shouldPersist(loadArgs.path, projectRootNormalized))
204
+ return loadDependencyFile(loadArgs.path, {mocks: true});
193
205
  try {
194
- // Match the esbuild loader to the source extension so TS type syntax (preserved by the
195
- // persist transform) is stripped: .tsx → tsx, .ts → ts, .jsx/.js → jsx.
196
- const loader = a.path.endsWith('.tsx')
197
- ? 'tsx'
198
- : a.path.endsWith('.ts')
199
- ? 'ts'
200
- : 'jsx';
201
- return {
202
- contents: transformPersist(
203
- readFileSync(a.path, 'utf8'),
204
- relative(projectRoot, a.path).replace(/\\/g, '/'),
205
- ),
206
- loader,
207
- };
208
- } catch (e) {
209
- return {errors: [{text: `persist transform: ${e.message}`}]};
206
+ return await loadAppFile(
207
+ loadArgs.path,
208
+ persist
209
+ ? source =>
210
+ transformPersist(
211
+ source,
212
+ relative(projectRoot, loadArgs.path).replace(
213
+ /\\/g,
214
+ '/',
215
+ ),
216
+ )
217
+ : undefined,
218
+ {mocks: true},
219
+ );
220
+ } catch (error) {
221
+ return {errors: [{text: `persist transform: ${error.message}`}]};
210
222
  }
211
223
  });
212
- b.onLoad({filter: /\.(png|jpe?g|webp|gif|bmp)$/i}, a => {
213
- images.set(assetName(a.path), a.path);
214
- return {
215
- contents: `module.exports = ${JSON.stringify(assetName(a.path))};`,
216
- loader: 'js',
217
- };
218
- });
219
- b.onLoad({filter: /\.(ttf|otf)$/i}, a => {
220
- fonts.set(assetName(a.path), a.path);
224
+ pluginBuild.onLoad(
225
+ {filter: /\.(png|jpe?g|webp|gif|bmp)$/i},
226
+ loadArgs => {
227
+ images.set(assetName(loadArgs.path), loadArgs.path);
228
+ return {
229
+ contents: `module.exports = ${JSON.stringify(assetName(loadArgs.path))};`,
230
+ loader: 'js',
231
+ };
232
+ },
233
+ );
234
+ pluginBuild.onLoad({filter: /\.(ttf|otf)$/i}, loadArgs => {
235
+ fonts.set(assetName(loadArgs.path), loadArgs.path);
221
236
  return {
222
- contents: `module.exports = ${JSON.stringify(assetName(a.path))};`,
237
+ contents: `module.exports = ${JSON.stringify(assetName(loadArgs.path))};`,
223
238
  loader: 'js',
224
239
  };
225
240
  });
226
- registerSvgVectorLoader(b, (name, p) => images.set(name, p)); // raster-fallback SVGs join the image pack
227
- b.onEnd(async r => {
228
- if (r.errors.length) {
229
- console.error(`✗ build failed (${r.errors.length} error(s))`);
241
+ registerSvgVectorLoader(pluginBuild, (name, svgPath) =>
242
+ images.set(name, svgPath),
243
+ ); // raster-fallback SVGs join the image pack
244
+ pluginBuild.onEnd(async result => {
245
+ if (result.errors.length) {
246
+ console.error(
247
+ `✗ build failed (${result.errors.length} error(s))`,
248
+ );
230
249
  return;
231
250
  }
232
251
  await bakePack();
@@ -283,7 +302,7 @@ export async function runDevServer({
283
302
  }) {
284
303
  const clients = new Set();
285
304
  const broadcastReload = () => {
286
- for (const res of clients) res.write('data: reload\n\n');
305
+ for (const response of clients) response.write('data: reload\n\n');
287
306
  };
288
307
 
289
308
  const {options} = createBundle({
@@ -299,38 +318,38 @@ export async function runDevServer({
299
318
  },
300
319
  });
301
320
 
302
- const ctx = await esbuild.context(options);
303
- await ctx.rebuild();
304
- await ctx.watch();
321
+ const buildContext = await esbuild.context(options);
322
+ await buildContext.rebuild();
323
+ await buildContext.watch();
305
324
 
306
325
  // Serve the host page; embedded-react.{js,wasm} from simDir, the freshly bundled app.js/assets.pack from
307
326
  // outDir. The page references ./public/<name>. window.__erHot is injected so the page connects to /reload.
308
- const send = async (res, file) => {
327
+ const send = async (response, file) => {
309
328
  try {
310
329
  const body = await readFile(file);
311
- res
330
+ response
312
331
  .writeHead(200, {
313
332
  'content-type': MIME[extname(file)] || 'application/octet-stream',
314
333
  'cache-control': 'no-store',
315
334
  })
316
335
  .end(body);
317
336
  } catch {
318
- res.writeHead(404).end('not found');
337
+ response.writeHead(404).end('not found');
319
338
  }
320
339
  };
321
- const server = createServer(async (req, res) => {
340
+ const server = createServer(async (request, response) => {
322
341
  const path = decodeURIComponent(
323
- new URL(req.url, 'http://localhost').pathname,
342
+ new URL(request.url, 'http://localhost').pathname,
324
343
  );
325
344
  if (path === '/reload') {
326
- res.writeHead(200, {
345
+ response.writeHead(200, {
327
346
  'content-type': 'text/event-stream',
328
347
  'cache-control': 'no-cache',
329
348
  connection: 'keep-alive',
330
349
  });
331
- res.write('retry: 1000\n\n');
332
- clients.add(res);
333
- req.on('close', () => clients.delete(res));
350
+ response.write('retry: 1000\n\n');
351
+ clients.add(response);
352
+ request.on('close', () => clients.delete(response));
334
353
  return;
335
354
  }
336
355
  if (path === '/' || path === '/index.html') {
@@ -339,14 +358,14 @@ export async function runDevServer({
339
358
  '</head>',
340
359
  '<script>window.__erHot=true</script></head>',
341
360
  );
342
- res
361
+ response
343
362
  .writeHead(200, {
344
363
  'content-type': MIME['.html'],
345
364
  'cache-control': 'no-store',
346
365
  })
347
366
  .end(html);
348
367
  } catch {
349
- res.writeHead(404).end('not found');
368
+ response.writeHead(404).end('not found');
350
369
  }
351
370
  return;
352
371
  }
@@ -356,23 +375,23 @@ export async function runDevServer({
356
375
  name === 'embedded-react.js' || name === 'embedded-react.wasm'
357
376
  ? simDir
358
377
  : outDir;
359
- return void send(res, resolve(dir, name));
378
+ return void send(response, resolve(dir, name));
360
379
  }
361
- res.writeHead(404).end('not found');
380
+ response.writeHead(404).end('not found');
362
381
  });
363
382
 
364
- await new Promise(r => server.listen(port, r));
383
+ await new Promise(onListening => server.listen(port, onListening));
365
384
  console.log(`embedded-react WASM sim → http://localhost:${port}/`);
366
385
  console.log(`watching ${label} — edit & save to hot-reload. Ctrl-C to quit.`);
367
386
 
368
387
  const shutdown = async () => {
369
388
  try {
370
- await ctx.dispose();
389
+ await buildContext.dispose();
371
390
  } catch {}
372
391
  server.close();
373
392
  process.exit(0);
374
393
  };
375
394
  process.on('SIGINT', shutdown);
376
395
  process.on('SIGTERM', shutdown);
377
- return {ctx, server};
396
+ return {ctx: buildContext, server};
378
397
  }
@@ -15,7 +15,7 @@
15
15
  */
16
16
 
17
17
  // Animated — the React Native analog, backed by the engine's native-driver value system
18
- // (er_anim_value_*). An Animated.Value is a handle to an engine-side float; binding it to a node
18
+ // (er_animation_value_*). An Animated.Value is a handle to an engine-side float; binding it to a node
19
19
  // prop (via Animated.View) lets the engine advance the animation each frame with NO per-frame JS.
20
20
  import {createElement, useRef, useEffect} from 'react';
21
21
  import {NativeUI} from '../native-ui.js';
@@ -55,9 +55,9 @@ export class AnimatedValue {
55
55
  this._destroyed = false;
56
56
  }
57
57
 
58
- setValue(v) {
59
- this._value = v;
60
- NativeUI.animValueSet(this._handle, v);
58
+ setValue(value) {
59
+ this._value = value;
60
+ NativeUI.animValueSet(this._handle, value);
61
61
  }
62
62
 
63
63
  /**
@@ -103,14 +103,14 @@ export class AnimatedInterpolation {
103
103
  }
104
104
 
105
105
  __bind(node, prop) {
106
- const out = this._config?.outputRange;
107
- if (Array.isArray(out)) {
106
+ const outputRange = this._config?.outputRange;
107
+ if (Array.isArray(outputRange)) {
108
108
  if (COLOR_PROPS.has(prop)) {
109
- if (out.some(c => typeof c !== 'string')) {
109
+ if (outputRange.some(output => typeof output !== 'string')) {
110
110
  warnColorBind(prop);
111
111
  return;
112
112
  }
113
- } else if (out.some(n => typeof n !== 'number')) {
113
+ } else if (outputRange.some(output => typeof output !== 'number')) {
114
114
  warnNumberBind(prop);
115
115
  return;
116
116
  }
@@ -142,13 +142,13 @@ export class AnimatedInterpolation {
142
142
  }
143
143
  }
144
144
 
145
- /** Wraps fn so it runs at most once, regardless of how many times it is invoked. */
146
- function once(fn) {
145
+ /** Wraps callback so it runs at most once, regardless of how many times it is invoked. */
146
+ function once(callback) {
147
147
  let called = false;
148
- return arg => {
148
+ return argument => {
149
149
  if (called) return;
150
150
  called = true;
151
- if (fn) fn(arg);
151
+ if (callback) callback(argument);
152
152
  };
153
153
  }
154
154
 
@@ -166,11 +166,11 @@ function makeAnimation(value, toValue, config) {
166
166
  _value: value,
167
167
  start(onComplete) {
168
168
  // Always pass a wrapper so we can null out the (possibly recycled) handle on completion.
169
- const cb = finished => {
169
+ const onEnd = finished => {
170
170
  handle = 0;
171
171
  if (onComplete) onComplete({finished: !!finished});
172
172
  };
173
- handle = NativeUI.animValueAnimate(value._handle, toValue, config, cb);
173
+ handle = NativeUI.animValueAnimate(value._handle, toValue, config, onEnd);
174
174
  },
175
175
  stop() {
176
176
  if (handle) NativeUI.animStop(handle);
@@ -252,16 +252,16 @@ export function parallel(animations, config) {
252
252
  anyUnfinished = true;
253
253
  if (stopTogether && !stopped) {
254
254
  stopped = true;
255
- for (const a of animations) a.stop();
255
+ for (const animation of animations) animation.stop();
256
256
  }
257
257
  }
258
258
  if (doneCount >= total) done({finished: !anyUnfinished});
259
259
  };
260
- for (const a of animations) a.start(onChild);
260
+ for (const animation of animations) animation.start(onChild);
261
261
  },
262
262
  stop() {
263
263
  stopped = true;
264
- for (const a of animations) a.stop();
264
+ for (const animation of animations) animation.stop();
265
265
  },
266
266
  };
267
267
  }
@@ -285,22 +285,22 @@ export function stagger(delay, animations) {
285
285
  if (!result || result.finished === false) anyUnfinished = true;
286
286
  if (doneCount >= total) done({finished: !anyUnfinished});
287
287
  };
288
- animations.forEach((a, i) => {
289
- if (i === 0) {
290
- a.start(onChild);
288
+ animations.forEach((animation, index) => {
289
+ if (index === 0) {
290
+ animation.start(onChild);
291
291
  } else {
292
292
  timers.push(
293
293
  setTimeout(() => {
294
- if (!stopped) a.start(onChild);
295
- }, delay * i),
294
+ if (!stopped) animation.start(onChild);
295
+ }, delay * index),
296
296
  );
297
297
  }
298
298
  });
299
299
  },
300
300
  stop() {
301
301
  stopped = true;
302
- for (const t of timers) clearTimeout(t);
303
- for (const a of animations) a.stop();
302
+ for (const timer of timers) clearTimeout(timer);
303
+ for (const animation of animations) animation.stop();
304
304
  },
305
305
  };
306
306
  }
@@ -0,0 +1,37 @@
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
+ // Dimensions — RN analog over the host-injected `screen` global. A panel has no pixel-density or font
18
+ // setting, so `scale` and `fontScale` are 1, and 'window' and 'screen' are the same size.
19
+ export const Dimensions = {
20
+ get(dimension) {
21
+ if (dimension !== 'window' && dimension !== 'screen') {
22
+ throw new Error(`Dimensions.get: no dimension named "${dimension}"`);
23
+ }
24
+
25
+ return {
26
+ width: screen.width,
27
+ height: screen.height,
28
+ scale: 1,
29
+ fontScale: 1,
30
+ };
31
+ },
32
+ };
33
+
34
+ // The panel's size. It is fixed while the app runs, so this never re-renders.
35
+ export function useWindowDimensions() {
36
+ return Dimensions.get('window');
37
+ }
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- // Easing tokens. The engine implements a fixed set of easing curves (ERAnimEasing), so unlike RN's
17
+ // Easing tokens. The engine implements a fixed set of easing curves (ERAnimationEasing), so unlike RN's
18
18
  // composable Easing functions these are string tokens the bridge maps to the engine enum. `bezier`
19
19
  // returns a control-point object the bridge reads as a custom cubic-bezier curve.
20
20
  export const Easing = {
@@ -74,11 +74,11 @@ export function FlatList(props = {}) {
74
74
  const row = renderItem({item, index});
75
75
  // The key is built lazily: pushKeyedChild calls this only for a row that can hold one, so
76
76
  // keyExtractor never runs for a row that rendered nothing or for a raw string.
77
- pushKeyedChild(rows, row, el =>
77
+ pushKeyedChild(rows, row, element =>
78
78
  keyExtractor
79
79
  ? String(keyExtractor(item, index))
80
- : el.key !== null && el.key !== undefined
81
- ? el.key
80
+ : element.key !== null && element.key !== undefined
81
+ ? element.key
82
82
  : String(index),
83
83
  );
84
84
  }
@@ -16,8 +16,8 @@
16
16
 
17
17
  // LayoutAnimation — the React Native analog. Calling configureNext(...) before a state update that
18
18
  // changes layout makes the engine tween every node whose computed rect moved (instead of snapping)
19
- // on the next commit. Backed by the engine's er_layout_anim_configure_next; the tween advances in C
20
- // each frame (er_layout_anim_tick), so there's no per-frame JS.
19
+ // on the next commit. Backed by the engine's er_layout_animation_configure_next; the tween advances in C
20
+ // each frame (er_layout_animation_tick), so there's no per-frame JS.
21
21
  import {NativeUI} from '../native-ui.js';
22
22
  import {
23
23
  Types,
@@ -25,6 +25,7 @@ import {
25
25
  Presets,
26
26
  toEngineConfig,
27
27
  create,
28
+ DEFAULT_DURATION_MS,
28
29
  } from './layout-anim-config.js';
29
30
 
30
31
  /**
@@ -34,9 +35,11 @@ import {
34
35
  export function configureNext(config, onAnimationDidEnd) {
35
36
  NativeUI.configureNextLayoutAnimation(toEngineConfig(config));
36
37
  if (typeof onAnimationDidEnd === 'function') {
37
- const ms =
38
- config && typeof config.duration === 'number' ? config.duration : 300;
39
- setTimeout(onAnimationDidEnd, ms);
38
+ const durationMs =
39
+ config && typeof config.duration === 'number'
40
+ ? config.duration
41
+ : DEFAULT_DURATION_MS;
42
+ setTimeout(onAnimationDidEnd, durationMs);
40
43
  }
41
44
  }
42
45