embedded-react 0.19.0 → 0.20.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 (116) hide show
  1. package/README.md +7 -3
  2. package/aot/compile.mjs +178 -58
  3. package/aot/compiler/animations.mjs +290 -281
  4. package/aot/compiler/boot.mjs +70 -33
  5. package/aot/compiler/branch-merge.mjs +4 -3
  6. package/aot/compiler/check.mjs +9 -9
  7. package/aot/compiler/collect.mjs +324 -205
  8. package/aot/compiler/control-flow.mjs +209 -197
  9. package/aot/compiler/diagnostics.mjs +22 -25
  10. package/aot/compiler/elements/activity-indicator.mjs +25 -24
  11. package/aot/compiler/elements/dial.mjs +91 -77
  12. package/aot/compiler/elements/flat-list.mjs +24 -22
  13. package/aot/compiler/elements/image.mjs +51 -50
  14. package/aot/compiler/elements/modal.mjs +31 -30
  15. package/aot/compiler/elements/props.mjs +23 -23
  16. package/aot/compiler/elements/switch.mjs +42 -34
  17. package/aot/compiler/elements/text-input.mjs +34 -32
  18. package/aot/compiler/expressions.mjs +372 -333
  19. package/aot/compiler/handlers.mjs +473 -387
  20. package/aot/compiler/ir/functions.mjs +11 -1
  21. package/aot/compiler/ir/nodes.mjs +4 -4
  22. package/aot/compiler/ir/reads.mjs +19 -19
  23. package/aot/compiler/ir/types.mjs +14 -14
  24. package/aot/compiler/ir/vectors.mjs +5 -1
  25. package/aot/compiler/keyboard.mjs +17 -7
  26. package/aot/compiler/lower.mjs +77 -80
  27. package/aot/compiler/nodes.mjs +169 -152
  28. package/aot/compiler/options.mjs +35 -30
  29. package/aot/compiler/out.mjs +18 -22
  30. package/aot/compiler/package/animations.mjs +669 -0
  31. package/aot/compiler/package/arena.mjs +252 -0
  32. package/aot/compiler/package/assemble.mjs +177 -0
  33. package/aot/compiler/package/bytecode.mjs +286 -0
  34. package/aot/compiler/package/checks.mjs +1022 -0
  35. package/aot/compiler/package/codegen.mjs +1329 -0
  36. package/aot/compiler/package/enums.mjs +138 -0
  37. package/aot/compiler/package/format.mjs +760 -0
  38. package/aot/compiler/package/layouts.mjs +136 -0
  39. package/aot/compiler/package/lower.mjs +1606 -0
  40. package/aot/compiler/package/props.mjs +118 -0
  41. package/aot/compiler/package/tables.mjs +103 -0
  42. package/aot/compiler/package/vectors.mjs +502 -0
  43. package/aot/compiler/package/writer.mjs +664 -0
  44. package/aot/compiler/pan-responder.mjs +69 -61
  45. package/aot/compiler/parse.mjs +21 -21
  46. package/aot/compiler/static-eval.mjs +25 -23
  47. package/aot/compiler/style-text.mjs +161 -172
  48. package/aot/compiler/svg.mjs +477 -251
  49. package/aot/screenshot-smoke.mjs +54 -40
  50. package/aot/style-map.mjs +102 -90
  51. package/assets/bake-font.mjs +123 -77
  52. package/assets/bake-image.mjs +39 -22
  53. package/assets/bake-svg.mjs +361 -262
  54. package/assets/build-builtin-font.mjs +11 -7
  55. package/assets/emit-c.mjs +77 -58
  56. package/assets/emit-container.mjs +123 -37
  57. package/assets/emit-pack.mjs +77 -67
  58. package/assets/font-config.mjs +9 -6
  59. package/assets/font-sizes.mjs +163 -123
  60. package/assets/glyph-coverage.mjs +74 -54
  61. package/assets/index.mjs +31 -9
  62. package/assets/rasterize.mjs +126 -99
  63. package/assets/svg-loader.mjs +8 -8
  64. package/build.mjs +14 -12
  65. package/cli.mjs +359 -172
  66. package/compile-bin.mjs +3 -3
  67. package/flash.mjs +537 -0
  68. package/hotreload/dev-device.mjs +90 -33
  69. package/hotreload/pack-app.mjs +55 -43
  70. package/hotreload/pack-split.mjs +46 -37
  71. package/hotreload/package-transfer.mjs +175 -0
  72. package/hotreload/protocol.mjs +50 -37
  73. package/hotreload/uploader.mjs +38 -27
  74. package/hotreload/watch-tree.mjs +19 -19
  75. package/pack-container.mjs +28 -20
  76. package/package.json +7 -8
  77. package/persist-transform.mjs +34 -28
  78. package/qjsc-wasm.mjs +25 -14
  79. package/sim/embedded-react.cjs +1 -1
  80. package/sim/embedded-react.js +1 -1
  81. package/sim/embedded-react.wasm +0 -0
  82. package/sim/index.html +94 -85
  83. package/sim-server.mjs +101 -82
  84. package/src/embedded-react/Animated.js +24 -24
  85. package/src/embedded-react/Easing.js +1 -1
  86. package/src/embedded-react/FlatList.js +3 -3
  87. package/src/embedded-react/LayoutAnimation.js +8 -5
  88. package/src/embedded-react/PanResponder.js +75 -71
  89. package/src/embedded-react/Pressable.js +2 -8
  90. package/src/embedded-react/SectionList.js +6 -6
  91. package/src/embedded-react/StyleSheet.js +4 -3
  92. package/src/embedded-react/TouchableOpacity.js +13 -8
  93. package/src/embedded-react/index.d.ts +5 -5
  94. package/src/embedded-react/layout-anim-config.js +10 -4
  95. package/src/embedded-react/list-child.js +5 -5
  96. package/src/embedded-react/named-colors.js +1 -1
  97. package/src/embedded-react/split-style.js +11 -11
  98. package/src/embedded-react/svg-ops.js +760 -593
  99. package/src/embedded-react/useHostValue.js +3 -3
  100. package/src/embedded-react/usePersistentState.js +6 -6
  101. package/src/embedded-react/warn-props.js +1 -1
  102. package/src/host-config.js +60 -53
  103. package/src/props.js +49 -41
  104. package/src/renderer.js +7 -4
  105. package/aot/compiler/assemble.mjs +0 -944
  106. package/aot/compiler/c/animations.mjs +0 -436
  107. package/aot/compiler/c/boot.mjs +0 -127
  108. package/aot/compiler/c/expressions.mjs +0 -270
  109. package/aot/compiler/c/functions.mjs +0 -268
  110. package/aot/compiler/c/keyboard.mjs +0 -96
  111. package/aot/compiler/c/nodes.mjs +0 -303
  112. package/aot/compiler/c/pan-responder.mjs +0 -136
  113. package/aot/compiler/c/statements.mjs +0 -319
  114. package/aot/compiler/c/text.mjs +0 -83
  115. package/aot/compiler/c/vectors.mjs +0 -381
  116. package/aot/compiler/c-syntax.mjs +0 -127
@@ -25,6 +25,9 @@ import { INT } from './ir/types.mjs';
25
25
  const SLOT_KINDS = new Set(['bool', 'int', 'float', 'string']);
26
26
  /** The current compile's boot values, or null outside a compile. */
27
27
  let context = null;
28
+ /** The longest source text an error quotes, and what ends a longer one. */
29
+ const MAX_QUOTED_LENGTH = 80;
30
+ const ELLIPSIS = '...';
28
31
  /*----------------------------------------------------------------------------------------------------------------------
29
32
  - Implementation
30
33
  ---------------------------------------------------------------------------------------------------------------------*/
@@ -161,7 +164,7 @@ export function nameBootValues(value, name) {
161
164
  }
162
165
  }
163
166
  /**
164
- * The `screen` global: its width and height are boot values, set from er_app_build()'s arguments.
167
+ * The `screen` global: its width and height are boot values, set from the panel the app boots on.
165
168
  *
166
169
  * @param screen The panel the build is compiled for.
167
170
  * @param screen.width Its width.
@@ -175,10 +178,13 @@ export const screenBinding = (screen) => ({
175
178
  });
176
179
  /**
177
180
  * Starts recording a compile's boot values.
181
+ *
182
+ * @param source The source text.
178
183
  */
179
- export function beginBoot() {
184
+ export function beginBoot(source = '') {
180
185
  context = {
181
- env: null,
186
+ source,
187
+ environment: null,
182
188
  lower: null,
183
189
  slots: [],
184
190
  assumed: new Set(),
@@ -189,12 +195,12 @@ export function beginBoot() {
189
195
  /**
190
196
  * Gives the compile's boot values the environment and lowering their slots are worked out with.
191
197
  *
192
- * @param env The app's environment.
198
+ * @param environment The app's environment.
193
199
  * @param lower The expression lowering.
194
200
  */
195
- export function setBootLowering(env, lower) {
201
+ export function setBootLowering(environment, lower) {
196
202
  if (context) {
197
- context.env = env;
203
+ context.environment = environment;
198
204
  context.lower = lower;
199
205
  }
200
206
  }
@@ -210,30 +216,60 @@ export function endBoot() {
210
216
  // Look each assumed value's slot up while the context still lowers, so the guard can read it.
211
217
  const assumptions = [];
212
218
  const guarded = new Set();
213
- let assumesPanel = false;
219
+ let panelSource = null;
214
220
  const assume = (value) => {
215
221
  const slot = bootSlotOf(value);
216
222
  const buildValue = buildValueOf(value);
217
223
  if (slot && isGuardable(buildValue)) {
218
224
  if (!guarded.has(slot)) {
219
225
  guarded.add(slot);
220
- assumptions.push({ kind: 'value', slot, value: buildValue });
226
+ assumptions.push({
227
+ kind: 'value',
228
+ slot,
229
+ value: buildValue,
230
+ source: sourceOfValue(value),
231
+ });
221
232
  }
222
233
  }
223
234
  else if (value.basis.length) {
224
235
  value.basis.forEach(assume);
225
236
  }
226
237
  else {
227
- assumesPanel = true;
238
+ panelSource ??= sourceOfValue(value) ?? '';
228
239
  }
229
240
  };
230
241
  ending.assumed.forEach(assume);
231
- if (assumesPanel) {
232
- assumptions.push({ kind: 'panel' });
242
+ if (panelSource !== null) {
243
+ assumptions.push({ kind: 'panel', source: panelSource || null });
233
244
  }
234
245
  context = null;
235
246
  return { slots: ending.slots, assumptions };
236
247
  }
248
+ /**
249
+ * An expression's source text, on one line, as an error names it.
250
+ *
251
+ * @param node The expression.
252
+ *
253
+ * @returns The text, or null outside a compile.
254
+ */
255
+ export function bootSourceText(node) {
256
+ if (!context?.source || node.start == null || node.end == null)
257
+ return null;
258
+ const text = context.source.slice(node.start, node.end).replace(/\s+/g, ' ');
259
+ return text.length > MAX_QUOTED_LENGTH
260
+ ? `${text.slice(0, MAX_QUOTED_LENGTH - ELLIPSIS.length)}${ELLIPSIS}`
261
+ : text;
262
+ }
263
+ /**
264
+ * What a boot value is called in an error: its source, or the panel dimension it is.
265
+ *
266
+ * @param value The value.
267
+ *
268
+ * @returns The text, or null when it has none.
269
+ */
270
+ const sourceOfValue = (value) => value.dimension
271
+ ? `screen.${value.dimension}`
272
+ : value.node && bootSourceText(value.node);
237
273
  /**
238
274
  * Drops a compile's boot values after it failed.
239
275
  */
@@ -251,7 +287,7 @@ const isGuardable = (value) => typeof value === 'string' ||
251
287
  typeof value === 'boolean' ||
252
288
  (typeof value === 'number' && Number.isFinite(value));
253
289
  /**
254
- * A C identifier for a slot named after `name`, unique among the compile's slots.
290
+ * An identifier for a slot named after `name`, unique among the compile's slots.
255
291
  *
256
292
  * @param name The name.
257
293
  *
@@ -295,29 +331,29 @@ function sameExpr(first, second) {
295
331
  * The environment a slot's expression lowers in: the app's, with no runtime names, and `scope` as its
296
332
  * constants.
297
333
  *
298
- * @param env The app's environment.
334
+ * @param environment The app's environment.
299
335
  * @param scope The names the expression reads.
300
336
  *
301
337
  * @returns The environment.
302
338
  */
303
- const bootEnv = (env, scope) => ({
304
- ...env,
339
+ const bootEnv = (environment, scope) => ({
340
+ ...environment,
305
341
  state: new Map(),
306
342
  locals: new Map(),
307
- consts: scope,
343
+ constants: scope,
308
344
  animations: new Map(),
309
345
  refs: new Map(),
310
346
  pans: new Map(),
311
347
  callbacks: new Map(),
312
348
  helpers: new Map(),
313
349
  children: null,
314
- fnProps: undefined,
315
- cbPrefix: undefined,
350
+ functionProps: undefined,
351
+ callbackPrefix: undefined,
316
352
  event: null,
317
353
  gesture: null,
318
354
  pan: null,
319
355
  math64: false,
320
- animLocals: undefined,
356
+ animationLocals: undefined,
321
357
  });
322
358
  /**
323
359
  * The environment a boot value's own expression lowers in, for a caller that lowers it some other way than
@@ -328,9 +364,9 @@ const bootEnv = (env, scope) => ({
328
364
  * @returns The environment, or null when boot cannot work the value out.
329
365
  */
330
366
  export function bootEnvOf(value) {
331
- if (!context?.env || !value.lowerable || !value.node)
367
+ if (!context?.environment || !value.lowerable || !value.node)
332
368
  return null;
333
- return bootEnv(context.env, value.scope);
369
+ return bootEnv(context.environment, value.scope);
334
370
  }
335
371
  /**
336
372
  * The slot boot reads a value from, lowered on first use, after the slots its expression reads. A value boot
@@ -343,7 +379,7 @@ export function bootEnvOf(value) {
343
379
  export function bootSlotOf(value) {
344
380
  if (value.slot !== undefined)
345
381
  return value.slot;
346
- if (!context?.env || !context.lower)
382
+ if (!context?.environment || !context.lower)
347
383
  return null;
348
384
  // Null first, so an expression that reads itself has no slot.
349
385
  value.slot = null;
@@ -352,18 +388,18 @@ export function bootSlotOf(value) {
352
388
  slot = {
353
389
  field: slotField(`screen_${value.dimension}`),
354
390
  type: INT,
355
- init: { kind: 'screen', dimension: value.dimension },
391
+ initializer: { kind: 'screen', dimension: value.dimension },
356
392
  };
357
393
  }
358
394
  else {
359
395
  if (!value.lowerable || !value.node)
360
396
  return null;
361
- const { env, lower } = context;
362
- let expr;
397
+ const { environment, lower } = context;
398
+ let expression;
363
399
  const { lowering } = context;
364
400
  lowering.add(value.node);
365
401
  try {
366
- expr = attemptLowering(() => lower(value.node, bootEnv(env, value.scope)));
402
+ expression = attemptLowering(() => lower(value.node, bootEnv(environment, value.scope)));
367
403
  }
368
404
  catch {
369
405
  return null;
@@ -371,22 +407,23 @@ export function bootSlotOf(value) {
371
407
  finally {
372
408
  lowering.delete(value.node);
373
409
  }
374
- if (!SLOT_KINDS.has(expr.type.kind))
410
+ if (!SLOT_KINDS.has(expression.type.kind))
375
411
  return null;
376
412
  // A value that only reads another slot shares it, as does one worked out the same way as an earlier slot.
377
- if (expr.kind === 'boot') {
378
- value.slot = expr.slot;
379
- return expr.slot;
413
+ if (expression.kind === 'boot') {
414
+ value.slot = expression.slot;
415
+ return expression.slot;
380
416
  }
381
- const sameSlot = context.slots.find(slot => slot.init.kind === 'expr' && sameExpr(slot.init.expr, expr));
417
+ const sameSlot = context.slots.find(slot => slot.initializer.kind === 'expr' &&
418
+ sameExpr(slot.initializer.expression, expression));
382
419
  if (sameSlot) {
383
420
  value.slot = sameSlot;
384
421
  return sameSlot;
385
422
  }
386
423
  slot = {
387
424
  field: slotField(value.name ?? 'value'),
388
- type: expr.type,
389
- init: { kind: 'expr', expr },
425
+ type: expression.type,
426
+ initializer: { kind: 'expr', expression },
390
427
  };
391
428
  }
392
429
  context.slots.push(slot);
@@ -122,11 +122,12 @@ function isLowerableMath(node) {
122
122
  node.callee.object.type !== 'Identifier' ||
123
123
  node.callee.object.name !== 'Math' ||
124
124
  node.callee.property.type !== 'Identifier' ||
125
- node.arguments.some(arg => arg.type === 'SpreadElement')) {
125
+ node.arguments.some(argument => argument.type === 'SpreadElement')) {
126
126
  return false;
127
127
  }
128
- const fn = node.callee.property.name;
129
- return (Object.hasOwn(MATH_ARITY, fn) && MATH_ARITY[fn] === node.arguments.length);
128
+ const mathFunction = node.callee.property.name;
129
+ return (Object.hasOwn(MATH_ARITY, mathFunction) &&
130
+ MATH_ARITY[mathFunction] === node.arguments.length);
130
131
  }
131
132
  /**
132
133
  * `test ? whenTrue : whenFalse`, entry by entry where both are object or array literals of the same shape, so
@@ -46,7 +46,7 @@ export function numberProblem(rawValue) {
46
46
  const value = Number(rawValue);
47
47
  if (!Number.isFinite(value)) {
48
48
  return aotError(`AOT: a numeric constant folded to ` +
49
- `${rawValue === undefined ? 'undefined' : String(rawValue)}, which has no C form`, 'the value must be a finite number.');
49
+ `${rawValue === undefined ? 'undefined' : String(rawValue)}, which a number slot cannot hold`, 'the value must be a finite number.');
50
50
  }
51
51
  if (!Number.isFinite(Math.fround(value))) {
52
52
  return aotError(`AOT: the numeric constant ${value} is past the float range`, 'a float holds up to about 3.4e38.');
@@ -54,13 +54,13 @@ export function numberProblem(rawValue) {
54
54
  return null;
55
55
  }
56
56
  /**
57
- * What is wrong with an animation time, if anything: it is rounded to whole milliseconds, and C holds those
57
+ * What is wrong with an animation time, if anything: it is rounded to whole milliseconds, and an int holds those
58
58
  * from 0 to INT_MAX.
59
59
  *
60
60
  * @param field What the time is, for the error.
61
61
  * @param rawValue The value; anything `Number()` converts.
62
62
  *
63
- * @returns The error to report, or null for a time C holds.
63
+ * @returns The error to report, or null for a time an int holds.
64
64
  */
65
65
  export function millisecondsProblem(field, rawValue) {
66
66
  const hint = `a time is a number of milliseconds from 0 to ${MAX_MILLISECONDS}.`;
@@ -118,16 +118,16 @@ export function checkProblem(subject) {
118
118
  * reported; otherwise, or inside a fallback attempt, it is checked at once.
119
119
  *
120
120
  * @param subject The subject.
121
- * @param loc Where its error is reported, when that is more exact than the node being lowered.
121
+ * @param location Where its error is reported, when that is more exact than the node being lowered.
122
122
  */
123
- export function check(subject, loc) {
123
+ export function check(subject, location) {
124
124
  if (recording && !attempts) {
125
- recording.push({ ...subject, loc: loc ?? currentLoc() });
125
+ recording.push({ ...subject, location: location ?? currentLoc() });
126
126
  return;
127
127
  }
128
128
  const problem = checkProblem(subject);
129
129
  if (problem) {
130
- locateError(problem, loc);
130
+ locateError(problem, location);
131
131
  throw problem;
132
132
  }
133
133
  }
@@ -162,8 +162,8 @@ export function runChecks(checks) {
162
162
  for (const recorded of checks) {
163
163
  const problem = checkProblem(recorded);
164
164
  if (problem) {
165
- if (recorded.loc) {
166
- problem.aotLoc = recorded.loc;
165
+ if (recorded.location) {
166
+ problem.aotLoc = recorded.location;
167
167
  }
168
168
  throw problem;
169
169
  }