embedded-react 0.18.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 (117) hide show
  1. package/NOTICE +1 -1
  2. package/README.md +8 -4
  3. package/aot/compile.mjs +178 -58
  4. package/aot/compiler/animations.mjs +290 -281
  5. package/aot/compiler/boot.mjs +70 -33
  6. package/aot/compiler/branch-merge.mjs +4 -3
  7. package/aot/compiler/check.mjs +9 -9
  8. package/aot/compiler/collect.mjs +324 -205
  9. package/aot/compiler/control-flow.mjs +209 -197
  10. package/aot/compiler/diagnostics.mjs +22 -25
  11. package/aot/compiler/elements/activity-indicator.mjs +25 -24
  12. package/aot/compiler/elements/dial.mjs +91 -77
  13. package/aot/compiler/elements/flat-list.mjs +24 -22
  14. package/aot/compiler/elements/image.mjs +51 -50
  15. package/aot/compiler/elements/modal.mjs +31 -30
  16. package/aot/compiler/elements/props.mjs +23 -23
  17. package/aot/compiler/elements/switch.mjs +42 -34
  18. package/aot/compiler/elements/text-input.mjs +34 -32
  19. package/aot/compiler/expressions.mjs +372 -333
  20. package/aot/compiler/handlers.mjs +473 -387
  21. package/aot/compiler/ir/functions.mjs +11 -1
  22. package/aot/compiler/ir/nodes.mjs +4 -4
  23. package/aot/compiler/ir/reads.mjs +19 -19
  24. package/aot/compiler/ir/types.mjs +14 -14
  25. package/aot/compiler/ir/vectors.mjs +5 -1
  26. package/aot/compiler/keyboard.mjs +17 -7
  27. package/aot/compiler/lower.mjs +77 -80
  28. package/aot/compiler/nodes.mjs +169 -152
  29. package/aot/compiler/options.mjs +35 -30
  30. package/aot/compiler/out.mjs +18 -22
  31. package/aot/compiler/package/animations.mjs +669 -0
  32. package/aot/compiler/package/arena.mjs +252 -0
  33. package/aot/compiler/package/assemble.mjs +177 -0
  34. package/aot/compiler/package/bytecode.mjs +286 -0
  35. package/aot/compiler/package/checks.mjs +1022 -0
  36. package/aot/compiler/package/codegen.mjs +1329 -0
  37. package/aot/compiler/package/enums.mjs +138 -0
  38. package/aot/compiler/package/format.mjs +760 -0
  39. package/aot/compiler/package/layouts.mjs +136 -0
  40. package/aot/compiler/package/lower.mjs +1606 -0
  41. package/aot/compiler/package/props.mjs +118 -0
  42. package/aot/compiler/package/tables.mjs +103 -0
  43. package/aot/compiler/package/vectors.mjs +502 -0
  44. package/aot/compiler/package/writer.mjs +664 -0
  45. package/aot/compiler/pan-responder.mjs +69 -61
  46. package/aot/compiler/parse.mjs +21 -21
  47. package/aot/compiler/static-eval.mjs +25 -23
  48. package/aot/compiler/style-text.mjs +161 -172
  49. package/aot/compiler/svg.mjs +477 -251
  50. package/aot/screenshot-smoke.mjs +55 -41
  51. package/aot/style-map.mjs +102 -90
  52. package/assets/bake-font.mjs +123 -77
  53. package/assets/bake-image.mjs +39 -22
  54. package/assets/bake-svg.mjs +361 -262
  55. package/assets/build-builtin-font.mjs +14 -10
  56. package/assets/emit-c.mjs +83 -62
  57. package/assets/emit-container.mjs +124 -38
  58. package/assets/emit-pack.mjs +77 -67
  59. package/assets/font-config.mjs +9 -6
  60. package/assets/font-sizes.mjs +163 -123
  61. package/assets/glyph-coverage.mjs +74 -54
  62. package/assets/index.mjs +31 -9
  63. package/assets/rasterize.mjs +126 -99
  64. package/assets/svg-loader.mjs +8 -8
  65. package/build.mjs +16 -14
  66. package/cli.mjs +359 -172
  67. package/compile-bin.mjs +5 -5
  68. package/flash.mjs +537 -0
  69. package/hotreload/dev-device.mjs +90 -33
  70. package/hotreload/pack-app.mjs +55 -43
  71. package/hotreload/pack-split.mjs +46 -37
  72. package/hotreload/package-transfer.mjs +175 -0
  73. package/hotreload/protocol.mjs +51 -38
  74. package/hotreload/uploader.mjs +38 -27
  75. package/hotreload/watch-tree.mjs +19 -19
  76. package/pack-container.mjs +31 -23
  77. package/package.json +11 -12
  78. package/persist-transform.mjs +34 -28
  79. package/qjsc-wasm.mjs +25 -14
  80. package/sim/embedded-react.cjs +1 -1
  81. package/sim/embedded-react.js +1 -1
  82. package/sim/embedded-react.wasm +0 -0
  83. package/sim/index.html +94 -85
  84. package/sim-server.mjs +101 -82
  85. package/src/embedded-react/Animated.js +24 -24
  86. package/src/embedded-react/Easing.js +1 -1
  87. package/src/embedded-react/FlatList.js +4 -4
  88. package/src/embedded-react/LayoutAnimation.js +8 -5
  89. package/src/embedded-react/PanResponder.js +75 -71
  90. package/src/embedded-react/Pressable.js +2 -8
  91. package/src/embedded-react/SectionList.js +6 -6
  92. package/src/embedded-react/StyleSheet.js +4 -3
  93. package/src/embedded-react/TouchableOpacity.js +13 -8
  94. package/src/embedded-react/index.d.ts +5 -5
  95. package/src/embedded-react/layout-anim-config.js +10 -4
  96. package/src/embedded-react/list-child.js +5 -5
  97. package/src/embedded-react/named-colors.js +1 -1
  98. package/src/embedded-react/split-style.js +11 -11
  99. package/src/embedded-react/svg-ops.js +760 -593
  100. package/src/embedded-react/useHostValue.js +3 -3
  101. package/src/embedded-react/usePersistentState.js +6 -6
  102. package/src/embedded-react/warn-props.js +1 -1
  103. package/src/host-config.js +60 -53
  104. package/src/props.js +49 -41
  105. package/src/renderer.js +7 -4
  106. package/aot/compiler/assemble.mjs +0 -944
  107. package/aot/compiler/c/animations.mjs +0 -436
  108. package/aot/compiler/c/boot.mjs +0 -127
  109. package/aot/compiler/c/expressions.mjs +0 -270
  110. package/aot/compiler/c/functions.mjs +0 -268
  111. package/aot/compiler/c/keyboard.mjs +0 -96
  112. package/aot/compiler/c/nodes.mjs +0 -303
  113. package/aot/compiler/c/pan-responder.mjs +0 -136
  114. package/aot/compiler/c/statements.mjs +0 -319
  115. package/aot/compiler/c/text.mjs +0 -83
  116. package/aot/compiler/c/vectors.mjs +0 -381
  117. package/aot/compiler/c-syntax.mjs +0 -127
@@ -53,7 +53,10 @@ const MAX_DEPTH = 16;
53
53
  // parser chokes on (a future syntax, a mangled bundle). Strictly weaker, never silently preferred.
54
54
  const LITERAL_SIZE = /\bfontSize\s*:\s*(\d+(?:\.\d+)?)/g;
55
55
 
56
- const PARSER_OPTS = {
56
+ // Unresolved fontSize expressions are reported up to this many characters.
57
+ const SNIPPET_MAX_LENGTH = 48;
58
+
59
+ const PARSER_OPTIONS = {
57
60
  sourceType: 'unambiguous', // an IIFE bundle is a script; an app entry is a module
58
61
  errorRecovery: true,
59
62
  // Same pair the AOT parser uses: the TS plugin is harmless on plain JS/JSX and lets a .tsx app
@@ -80,7 +83,7 @@ const NON_NODE_KEYS = new Set([
80
83
  /** Depth-first visit of every AST node under `node`, in source order. */
81
84
  function walk(node, visit) {
82
85
  if (Array.isArray(node)) {
83
- for (const n of node) walk(n, visit);
86
+ for (const item of node) walk(item, visit);
84
87
  return;
85
88
  }
86
89
  if (!node || typeof node !== 'object' || typeof node.type !== 'string')
@@ -96,11 +99,11 @@ function walk(node, visit) {
96
99
  /** Static name of a non-computed property key, or null when the key isn't a fixed string. */
97
100
  function keyName(node) {
98
101
  if (node.computed) return null;
99
- const k = node.key;
100
- if (!k) return null;
101
- if (k.type === 'Identifier') return k.name;
102
- if (k.type === 'StringLiteral') return k.value;
103
- if (k.type === 'NumericLiteral') return String(k.value);
102
+ const key = node.key;
103
+ if (!key) return null;
104
+ if (key.type === 'Identifier') return key.name;
105
+ if (key.type === 'StringLiteral') return key.value;
106
+ if (key.type === 'NumericLiteral') return String(key.value);
104
107
  return null;
105
108
  }
106
109
 
@@ -108,9 +111,11 @@ function keyName(node) {
108
111
 
109
112
  // A folded value is either a number or a Scale: an object/array whose properties are themselves
110
113
  // candidate lists, so `TYPE.title` is a lookup and a ternary is a union.
111
- const scale = props => ({props});
112
- const isScale = v =>
113
- v !== null && typeof v === 'object' && v.props instanceof Map;
114
+ const scale = properties => ({properties});
115
+ const isScale = value =>
116
+ value !== null &&
117
+ typeof value === 'object' &&
118
+ value.properties instanceof Map;
114
119
 
115
120
  /** Trims a candidate list to the fan-out budget, dropping duplicates first. */
116
121
  const cap = values =>
@@ -119,20 +124,20 @@ const cap = values =>
119
124
  : values;
120
125
 
121
126
  /** The numbers in a candidate list (a Scale is not a size). */
122
- const numbers = values => values.filter(v => typeof v === 'number');
127
+ const numbers = values => values.filter(value => typeof value === 'number');
123
128
 
124
129
  const ARITHMETIC = {
125
- '+': (a, b) => a + b,
126
- '-': (a, b) => a - b,
127
- '*': (a, b) => a * b,
128
- '/': (a, b) => a / b,
129
- '%': (a, b) => a % b,
130
- '**': (a, b) => a ** b,
130
+ '+': (left, right) => left + right,
131
+ '-': (left, right) => left - right,
132
+ '*': (left, right) => left * right,
133
+ '/': (left, right) => left / right,
134
+ '%': (left, right) => left % right,
135
+ '**': (left, right) => left ** right,
131
136
  };
132
137
 
133
138
  // Rounding is how a ratio-based scale lands on whole pixels (Math.round(base * 1.25)); min/max is
134
139
  // how it gets clamped. Anything else on Math is left unresolved rather than guessed.
135
- const MATH_FNS = {
140
+ const MATH_FUNCTIONS = {
136
141
  round: Math.round,
137
142
  floor: Math.floor,
138
143
  ceil: Math.ceil,
@@ -151,7 +156,7 @@ const MATH_FNS = {
151
156
  */
152
157
  function evaluate(node, scope, depth = 0) {
153
158
  if (!node || depth > MAX_DEPTH) return [];
154
- const rec = n => evaluate(n, scope, depth + 1);
159
+ const evaluateChild = child => evaluate(child, scope, depth + 1);
155
160
 
156
161
  switch (node.type) {
157
162
  case 'NumericLiteral':
@@ -167,77 +172,84 @@ function evaluate(node, scope, depth = 0) {
167
172
  case 'TSNonNullExpression':
168
173
  case 'TSTypeAssertion':
169
174
  case 'TypeCastExpression':
170
- return rec(node.expression);
175
+ return evaluateChild(node.expression);
171
176
 
172
177
  case 'UnaryExpression': {
173
178
  if (node.operator !== '-' && node.operator !== '+') return [];
174
179
  const sign = node.operator === '-' ? -1 : 1;
175
- return numbers(rec(node.argument)).map(v => sign * v);
180
+ return numbers(evaluateChild(node.argument)).map(value => sign * value);
176
181
  }
177
182
 
178
183
  case 'BinaryExpression': {
179
- const op = ARITHMETIC[node.operator];
180
- if (!op) return [];
181
- const left = numbers(rec(node.left));
182
- const right = numbers(rec(node.right));
183
- const out = [];
184
- for (const a of left) for (const b of right) out.push(op(a, b));
185
- return cap(out);
184
+ const operation = ARITHMETIC[node.operator];
185
+ if (!operation) return [];
186
+ const left = numbers(evaluateChild(node.left));
187
+ const right = numbers(evaluateChild(node.right));
188
+ const results = [];
189
+ for (const leftValue of left)
190
+ for (const rightValue of right)
191
+ results.push(operation(leftValue, rightValue));
192
+ return cap(results);
186
193
  }
187
194
 
188
195
  // Both arms: which one a responsive app takes depends on the panel it boots on, and the same
189
196
  // bundle runs on all of them.
190
197
  case 'ConditionalExpression':
191
- return cap([...rec(node.consequent), ...rec(node.alternate)]);
198
+ return cap([
199
+ ...evaluateChild(node.consequent),
200
+ ...evaluateChild(node.alternate),
201
+ ]);
192
202
 
193
203
  // `a ?? b` / `a || b` are the same shape of choice; `&&` can only ever yield its right arm.
194
204
  case 'LogicalExpression':
195
205
  return node.operator === '&&'
196
- ? rec(node.right)
197
- : cap([...rec(node.left), ...rec(node.right)]);
206
+ ? evaluateChild(node.right)
207
+ : cap([...evaluateChild(node.left), ...evaluateChild(node.right)]);
198
208
 
199
209
  case 'ObjectExpression': {
200
- const props = new Map();
201
- for (const p of node.properties) {
202
- if (p.type === 'SpreadElement') {
203
- for (const base of rec(p.argument).filter(isScale))
204
- for (const [k, v] of base.props) props.set(k, v);
210
+ const properties = new Map();
211
+ for (const property of node.properties) {
212
+ if (property.type === 'SpreadElement') {
213
+ for (const base of evaluateChild(property.argument).filter(isScale))
214
+ for (const [key, values] of base.properties)
215
+ properties.set(key, values);
205
216
  continue;
206
217
  }
207
- if (p.type !== 'ObjectProperty') continue; // a method is never a size
208
- const name = keyName(p);
218
+ if (property.type !== 'ObjectProperty') continue; // a method is never a size
219
+ const name = keyName(property);
209
220
  if (name === null) continue;
210
- const values = rec(p.value);
211
- if (values.length) props.set(name, values);
221
+ const values = evaluateChild(property.value);
222
+ if (values.length) properties.set(name, values);
212
223
  }
213
- return [scale(props)];
224
+ return [scale(properties)];
214
225
  }
215
226
 
216
227
  case 'ArrayExpression': {
217
- const props = new Map();
218
- node.elements.forEach((el, i) => {
219
- if (!el || el.type === 'SpreadElement') return;
220
- const values = rec(el);
221
- if (values.length) props.set(String(i), values);
228
+ const properties = new Map();
229
+ node.elements.forEach((element, index) => {
230
+ if (!element || element.type === 'SpreadElement') return;
231
+ const values = evaluateChild(element);
232
+ if (values.length) properties.set(String(index), values);
222
233
  });
223
- return [scale(props)];
234
+ return [scale(properties)];
224
235
  }
225
236
 
226
237
  case 'MemberExpression': {
227
- const objects = rec(node.object).filter(isScale);
238
+ const objects = evaluateChild(node.object).filter(isScale);
228
239
  if (!objects.length) return [];
229
240
  const key = memberKey(node, scope, depth);
230
- const out = [];
231
- for (const obj of objects) {
241
+ const results = [];
242
+ for (const object of objects) {
232
243
  // An unresolvable key (`TYPE[variant]`) still narrows things to one scale, and every entry
233
244
  // in it is something the app can reach — take the lot rather than nothing.
234
245
  if (key === null) {
235
- for (const v of obj.props.values()) out.push(...v);
246
+ for (const values of object.properties.values())
247
+ results.push(...values);
236
248
  } else {
237
- out.push(...(obj.props.get(key) ?? []));
249
+ results.push(...(object.properties.get(key) ?? []));
238
250
  }
239
251
  }
240
- return cap(out);
252
+ return cap(results);
241
253
  }
242
254
 
243
255
  case 'CallExpression': {
@@ -250,12 +262,20 @@ function evaluate(node, scope, depth = 0) {
250
262
  callee.property?.type !== 'Identifier'
251
263
  )
252
264
  return [];
253
- const fn = MATH_FNS[callee.property.name];
254
- if (!fn) return [];
265
+ const mathFunction = MATH_FUNCTIONS[callee.property.name];
266
+ if (!mathFunction) return [];
255
267
  // Every argument must resolve, or the result isn't the one the app computes.
256
- const args = node.arguments.map(a => numbers(rec(a)));
257
- if (!args.length || args.some(a => !a.length)) return [];
258
- return cap(combine(args).map(vals => fn(...vals)));
268
+ const argumentValues = node.arguments.map(argument =>
269
+ numbers(evaluateChild(argument)),
270
+ );
271
+ if (
272
+ !argumentValues.length ||
273
+ argumentValues.some(candidates => !candidates.length)
274
+ )
275
+ return [];
276
+ return cap(
277
+ combine(argumentValues).map(values => mathFunction(...values)),
278
+ );
259
279
  }
260
280
 
261
281
  default:
@@ -269,9 +289,9 @@ function combine(lists) {
269
289
  for (const list of lists) {
270
290
  const next = [];
271
291
  for (const row of rows)
272
- for (const v of list) {
292
+ for (const value of list) {
273
293
  if (next.length >= MAX_CANDIDATES) break;
274
- next.push([...row, v]);
294
+ next.push([...row, value]);
275
295
  }
276
296
  rows = next;
277
297
  }
@@ -297,7 +317,7 @@ function memberKey(node, scope, depth) {
297
317
  * names a bundle contains are only ever evaluated for the handful a fontSize actually reads.
298
318
  */
299
319
  function lookup(name, scope, depth) {
300
- const known = scope.env.get(name);
320
+ const known = scope.environment.get(name);
301
321
  if (known !== undefined) return known; // a memoized "nothing" is an answer, not a miss
302
322
  const bound = scope.bindings.get(name);
303
323
  if (!bound || scope.resolving.has(name)) return [];
@@ -307,7 +327,7 @@ function lookup(name, scope, depth) {
307
327
  bound.flatMap(node => evaluate(node, scope, depth + 1)).filter(isScale),
308
328
  );
309
329
  scope.resolving.delete(name);
310
- scope.env.set(name, values);
330
+ scope.environment.set(name, values);
311
331
  return values;
312
332
  }
313
333
 
@@ -326,7 +346,7 @@ function lookup(name, scope, depth) {
326
346
  * places resolves to all of them, which over-bakes at worst; declared names always win.
327
347
  *
328
348
  * @param {object} ast Parsed program.
329
- * @returns {{env: Map<string,any[]>, bindings: Map<string,object[]>, resolving: Set<string>}}
349
+ * @returns {{environment: Map<string,any[]>, bindings: Map<string,object[]>, resolving: Set<string>}}
330
350
  */
331
351
  function buildScope(ast) {
332
352
  const declarations = [];
@@ -339,25 +359,25 @@ function buildScope(ast) {
339
359
  else bindings.set(name, [node]);
340
360
  };
341
361
 
342
- walk(ast.program, n => {
343
- if (n.type === 'VariableDeclarator') {
344
- if (n.id?.type === 'Identifier' && n.init) {
345
- declarations.push(n);
346
- counts.set(n.id.name, (counts.get(n.id.name) ?? 0) + 1);
362
+ walk(ast.program, node => {
363
+ if (node.type === 'VariableDeclarator') {
364
+ if (node.id?.type === 'Identifier' && node.init) {
365
+ declarations.push(node);
366
+ counts.set(node.id.name, (counts.get(node.id.name) ?? 0) + 1);
347
367
  }
348
368
  return;
349
369
  }
350
370
  if (
351
- n.type === 'JSXAttribute' &&
352
- n.name?.type === 'JSXIdentifier' &&
353
- n.value?.type === 'JSXExpressionContainer'
371
+ node.type === 'JSXAttribute' &&
372
+ node.name?.type === 'JSXIdentifier' &&
373
+ node.value?.type === 'JSXExpressionContainer'
354
374
  ) {
355
- bind(n.name.name, n.value.expression);
375
+ bind(node.name.name, node.value.expression);
356
376
  return;
357
377
  }
358
- if (n.type === 'ObjectProperty') {
359
- const name = keyName(n);
360
- if (name !== null) bind(name, n.value);
378
+ if (node.type === 'ObjectProperty') {
379
+ const name = keyName(node);
380
+ if (name !== null) bind(name, node.value);
361
381
  }
362
382
  });
363
383
 
@@ -365,13 +385,17 @@ function buildScope(ast) {
365
385
  // binding consulted mid-fold could cache an answer taken from a half-built environment. Two passes,
366
386
  // so a scale that reads a constant declared below it still folds; a third would only help a chain
367
387
  // that deep, which no type scale is.
368
- const scope = {env: new Map(), bindings: new Map(), resolving: new Set()};
388
+ const scope = {
389
+ environment: new Map(),
390
+ bindings: new Map(),
391
+ resolving: new Set(),
392
+ };
369
393
  for (let pass = 0; pass < 2; pass++) {
370
- for (const d of declarations) {
371
- const name = d.id.name;
394
+ for (const declaration of declarations) {
395
+ const name = declaration.id.name;
372
396
  if (counts.get(name) > 1) continue;
373
- const values = evaluate(d.init, scope);
374
- if (values.length) scope.env.set(name, values);
397
+ const values = evaluate(declaration.init, scope);
398
+ if (values.length) scope.environment.set(name, values);
375
399
  }
376
400
  }
377
401
  // A declared name resolves to its declaration or to nothing; it never falls through to a binding.
@@ -384,24 +408,30 @@ function buildScope(ast) {
384
408
 
385
409
  /** Rounds a folded value to a bakeable pixel size, or null when it isn't one. */
386
410
  function toPixelSize(value) {
387
- const px = Math.round(value);
388
- return Number.isFinite(px) && px >= MIN_PX && px <= MAX_PX ? px : null;
411
+ const pixelSize = Math.round(value);
412
+ return Number.isFinite(pixelSize) &&
413
+ pixelSize >= MIN_PX &&
414
+ pixelSize <= MAX_PX
415
+ ? pixelSize
416
+ : null;
389
417
  }
390
418
 
391
419
  /** One-line, length-capped rendering of the expression behind an unresolved fontSize. */
392
420
  function snippet(source, node) {
393
421
  const raw = source.slice(node.start, node.end).replace(/\s+/g, ' ').trim();
394
- return raw.length > 48 ? `${raw.slice(0, 47)}…` : raw;
422
+ return raw.length > SNIPPET_MAX_LENGTH
423
+ ? `${raw.slice(0, SNIPPET_MAX_LENGTH - 1)}…`
424
+ : raw;
395
425
  }
396
426
 
397
427
  /** Literal-only discovery, for a source the parser rejected. */
398
428
  function scanLiterals(source) {
399
429
  const sizes = new Set();
400
- for (const m of source.matchAll(LITERAL_SIZE)) {
401
- const px = toPixelSize(Number(m[1]));
402
- if (px !== null) sizes.add(px);
430
+ for (const match of source.matchAll(LITERAL_SIZE)) {
431
+ const pixelSize = toPixelSize(Number(match[1]));
432
+ if (pixelSize !== null) sizes.add(pixelSize);
403
433
  }
404
- return {sizes: [...sizes].sort((a, b) => a - b), dynamic: []};
434
+ return {sizes: [...sizes].sort((left, right) => left - right), dynamic: []};
405
435
  }
406
436
 
407
437
  /**
@@ -416,7 +446,7 @@ export function analyzeFontSizes(source) {
416
446
  if (!source) return {sizes: [], dynamic: []};
417
447
  let ast;
418
448
  try {
419
- ast = parse(source, PARSER_OPTS);
449
+ ast = parse(source, PARSER_OPTIONS);
420
450
  } catch {
421
451
  return scanLiterals(source); // never worse than the literal scan this replaced
422
452
  }
@@ -424,27 +454,30 @@ export function analyzeFontSizes(source) {
424
454
  const scope = buildScope(ast);
425
455
  const sizes = new Set();
426
456
  const dynamic = new Map(); // expression text → occurrences
427
- walk(ast.program, n => {
428
- if (n.type !== 'ObjectProperty' || keyName(n) !== 'fontSize') return;
457
+ walk(ast.program, node => {
458
+ if (node.type !== 'ObjectProperty' || keyName(node) !== 'fontSize') return;
429
459
  // A value that resolves but can't be baked (0, negative, past the engine's uint8 pixel_size) is
430
460
  // an authoring slip, not a discovery failure: leave it out of the bake and out of the report.
431
- const resolved = numbers(evaluate(n.value, scope));
461
+ const resolved = numbers(evaluate(node.value, scope));
432
462
  if (resolved.length) {
433
463
  for (const value of resolved) {
434
- const px = toPixelSize(value);
435
- if (px !== null) sizes.add(px);
464
+ const pixelSize = toPixelSize(value);
465
+ if (pixelSize !== null) sizes.add(pixelSize);
436
466
  }
437
467
  return;
438
468
  }
439
- const expr = snippet(source, n.value);
440
- dynamic.set(expr, (dynamic.get(expr) ?? 0) + 1);
469
+ const expression = snippet(source, node.value);
470
+ dynamic.set(expression, (dynamic.get(expression) ?? 0) + 1);
441
471
  });
442
472
 
443
473
  return {
444
- sizes: [...sizes].sort((a, b) => a - b),
474
+ sizes: [...sizes].sort((left, right) => left - right),
445
475
  dynamic: [...dynamic]
446
- .map(([expr, count]) => ({expr, count}))
447
- .sort((a, b) => b.count - a.count || a.expr.localeCompare(b.expr)),
476
+ .map(([expression, count]) => ({expr: expression, count}))
477
+ .sort(
478
+ (left, right) =>
479
+ right.count - left.count || left.expr.localeCompare(right.expr),
480
+ ),
448
481
  };
449
482
  }
450
483
 
@@ -462,7 +495,7 @@ export function analyzeFontSizes(source) {
462
495
  */
463
496
  export function fontSizeSignature(used) {
464
497
  const {sizes = [], dynamic = []} = used ?? {};
465
- return `${sizes.join(',')}|${dynamic.map(d => d.expr).join('\u0000')}`;
498
+ return `${sizes.join(',')}|${dynamic.map(entry => entry.expr).join('\u0000')}`;
466
499
  }
467
500
 
468
501
  /*--- Coverage check -----------------------------------------------------------------------------*/
@@ -470,8 +503,8 @@ export function fontSizeSignature(used) {
470
503
  /** Pixel sizes a bakeFont() result — or the job that produced it — covers. */
471
504
  function bakedSizes(font) {
472
505
  return (font.sizes ?? [])
473
- .map(s => (typeof s === 'number' ? s : s?.pixelSize))
474
- .filter(px => Number.isFinite(px));
506
+ .map(size => (typeof size === 'number' ? size : size?.pixelSize))
507
+ .filter(pixelSize => Number.isFinite(pixelSize));
475
508
  }
476
509
 
477
510
  /**
@@ -486,10 +519,14 @@ function bakedSizes(font) {
486
519
  export function pickBakedSize(baked, wanted) {
487
520
  const target = Math.min(Math.max(wanted, RENDER_MIN_PX), RENDER_MAX_PX);
488
521
  let best = baked[0];
489
- for (const px of baked.slice(1)) {
490
- const diff = Math.abs(target - px);
491
- const bestDiff = Math.abs(target - best);
492
- if (diff < bestDiff || (diff === bestDiff && px > best)) best = px;
522
+ for (const size of baked.slice(1)) {
523
+ const difference = Math.abs(target - size);
524
+ const bestDifference = Math.abs(target - best);
525
+ if (
526
+ difference < bestDifference ||
527
+ (difference === bestDifference && size > best)
528
+ )
529
+ best = size;
493
530
  }
494
531
  return best;
495
532
  }
@@ -511,7 +548,7 @@ export function pickBakedSize(baked, wanted) {
511
548
  */
512
549
  export function findSizeGaps({sizes = [], fonts = []}) {
513
550
  const checked = fonts.length
514
- ? fonts.map(f => ({family: f.family, baked: bakedSizes(f)}))
551
+ ? fonts.map(font => ({family: font.family, baked: bakedSizes(font)}))
515
552
  : [{family: BUILTIN_FAMILY, baked: [...BUILTIN_SIZES]}];
516
553
 
517
554
  const gaps = [];
@@ -535,13 +572,14 @@ export function findSizeGaps({sizes = [], fonts = []}) {
535
572
  baked: live,
536
573
  });
537
574
  }
538
- return {gaps: gaps.sort((a, b) => a.size - b.size), dropped};
575
+ return {gaps: gaps.sort((left, right) => left.size - right.size), dropped};
539
576
  }
540
577
 
541
578
  const MAX_LISTED = 8;
542
579
 
543
580
  /** `[a, b, c]` as an assets.config.js `sizes` line would spell it. */
544
- const sizeList = sizes => `[${[...sizes].sort((a, b) => a - b).join(', ')}]`;
581
+ const sizeList = sizes =>
582
+ `[${[...sizes].sort((left, right) => left - right).join(', ')}]`;
545
583
 
546
584
  /** A family name as a valid object key (a family is a file basename — `Inter-Regular` needs quotes). */
547
585
  const configKey = family =>
@@ -569,8 +607,8 @@ export function formatFontSizeReport({
569
607
  const lines = gaps
570
608
  .slice(0, MAX_LISTED)
571
609
  .map(
572
- g =>
573
- ` ${g.size}px → renders at ${g.snapsTo}px in ${g.family} (baked: ${g.baked.join(', ')})`,
610
+ gap =>
611
+ ` ${gap.size}px → renders at ${gap.snapsTo}px in ${gap.family} (baked: ${gap.baked.join(', ')})`,
574
612
  );
575
613
  if (gaps.length > MAX_LISTED)
576
614
  lines.push(` … and ${gaps.length - MAX_LISTED} more`);
@@ -581,10 +619,10 @@ export function formatFontSizeReport({
581
619
  }
582
620
 
583
621
  if (dynamic.length) {
584
- const total = dynamic.reduce((n, d) => n + d.count, 0);
585
- const lines = dynamic.slice(0, MAX_LISTED).map(d => {
586
- const times = d.count > 1 ? ` (×${d.count})` : '';
587
- return ` fontSize: ${d.expr}${times}`;
622
+ const total = dynamic.reduce((sum, entry) => sum + entry.count, 0);
623
+ const lines = dynamic.slice(0, MAX_LISTED).map(entry => {
624
+ const times = entry.count > 1 ? ` (×${entry.count})` : '';
625
+ return ` fontSize: ${entry.expr}${times}`;
588
626
  });
589
627
  if (dynamic.length > MAX_LISTED)
590
628
  lines.push(` … and ${dynamic.length - MAX_LISTED} more`);
@@ -598,12 +636,12 @@ export function formatFontSizeReport({
598
636
  );
599
637
  }
600
638
 
601
- for (const d of dropped) {
639
+ for (const droppedFamily of dropped) {
602
640
  blocks.push(
603
- `embedded-react: ${d.family} is baked at more than ${MAX_BAKED_SIZES} sizes — the engine ` +
604
- `registers the first ${MAX_BAKED_SIZES} and ignores ${sizeList(d.ignored)}, so text at ` +
641
+ `embedded-react: ${droppedFamily.family} is baked at more than ${MAX_BAKED_SIZES} sizes — the engine ` +
642
+ `registers the first ${MAX_BAKED_SIZES} and ignores ${sizeList(droppedFamily.ignored)}, so text at ` +
605
643
  `those sizes snaps to one that did register.\n fix: choose the ${MAX_BAKED_SIZES} that ` +
606
- `matter — assets.config.js → fonts: {${configKey(d.family)}: {sizes: ${sizeList(d.registered)}}}`,
644
+ `matter — assets.config.js → fonts: {${configKey(droppedFamily.family)}: {sizes: ${sizeList(droppedFamily.registered)}}}`,
607
645
  );
608
646
  }
609
647
 
@@ -616,15 +654,17 @@ function gapFix(gaps, fonts) {
616
654
  return (
617
655
  ` fix: the built-in font is baked at ${sizeList(BUILTIN_SIZES)} — use one of those sizes, or ` +
618
656
  `import a .ttf/.otf\n and bake your own (assets.config.js → fonts: ` +
619
- `{<Family>: {sizes: ${sizeList(new Set(gaps.map(g => g.size)))}}})`
657
+ `{<Family>: {sizes: ${sizeList(new Set(gaps.map(gap => gap.size)))}}})`
620
658
  );
621
659
  }
622
660
  const perFamily = fonts
623
- .map(f => {
624
- const missing = gaps.filter(g => g.family === f.family).map(g => g.size);
661
+ .map(font => {
662
+ const missing = gaps
663
+ .filter(gap => gap.family === font.family)
664
+ .map(gap => gap.size);
625
665
  if (!missing.length) return null;
626
- const wanted = new Set([...bakedSizes(f), ...missing]);
627
- return `${configKey(f.family)}: {sizes: ${sizeList(wanted)}}`;
666
+ const wanted = new Set([...bakedSizes(font), ...missing]);
667
+ return `${configKey(font.family)}: {sizes: ${sizeList(wanted)}}`;
628
668
  })
629
669
  .filter(Boolean);
630
670
  return ` fix: assets.config.js → fonts: {${perFamily.join(', ')}}`;