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
@@ -17,16 +17,15 @@
17
17
  - Imports
18
18
  ---------------------------------------------------------------------------------------------------------------------*/
19
19
  import { attemptLowering, check } from './check.mjs';
20
+ import { shapeOf } from './typing.mjs';
20
21
  import { BootReadError, bootEnvOf, bootSlotOf, foldBoot, isBoot, } from './boot.mjs';
21
- import { lowerStyle, isStyleKey, STYLE_KEYS, DYN_FIELDS, colorLiteral, } from '../style-map.mjs';
22
+ import { lowerStyle, isStyleKey, STYLE_KEYS, DYN_FIELDS, parseColorValue, } from '../style-map.mjs';
22
23
  import { parseColor } from '../../src/embedded-react/svg-ops.js';
23
24
  import { aotError, checkEngineString } from './diagnostics.mjs';
24
25
  import { at, checkAnimatedStyleKey, checkAttributes, checkStyleKey, inlineFragments, TEXT_SPAN, } from './elements/props.mjs';
25
26
  import { evalStatic, foldScope, withUndefined } from './static-eval.mjs';
26
- import { cstr } from './c-syntax.mjs';
27
27
  import { jsxChildText, lowerExpr, lowerText } from './expressions.mjs';
28
- import { printPropValue } from './c/nodes.mjs';
29
- import { ANIM_COLOR_KEYS, ANIM_STYLE_PROPS, ANIM_TRANSFORM_PROPS, parseInterp, } from './animations.mjs';
28
+ import { ANIMATED_COLOR_KEYS, ANIMATED_STYLE_PROPS, ANIMATED_TRANSFORM_PROPS, parseInterp, } from './animations.mjs';
30
29
  /*----------------------------------------------------------------------------------------------------------------------
31
30
  - Constants
32
31
  ---------------------------------------------------------------------------------------------------------------------*/
@@ -38,6 +37,8 @@ const BOOT_PIXEL_FIELDS = {
38
37
  bottom: 'bottom',
39
38
  flexBasis: 'flex_basis',
40
39
  };
40
+ /** A span's weight, style or decoration that takes its parent's. */
41
+ const SPAN_INHERIT = 0xff;
41
42
  /*----------------------------------------------------------------------------------------------------------------------
42
43
  - Implementation
43
44
  ---------------------------------------------------------------------------------------------------------------------*/
@@ -45,48 +46,41 @@ const BOOT_PIXEL_FIELDS = {
45
46
  * A JSX attribute's value as an expression: a bare `name` is `true`, `name="x"` the string, `name={expr}` the
46
47
  * expression.
47
48
  *
48
- * @param attr The attribute.
49
+ * @param attribute The attribute.
49
50
  *
50
51
  * @returns Its value.
51
52
  */
52
- export function attrExpr(attr) {
53
- const attrValue = attr.value;
54
- if (!attrValue)
53
+ export function attrExpr(attribute) {
54
+ const attributeValue = attribute.value;
55
+ if (!attributeValue)
55
56
  return { type: 'BooleanLiteral', value: true };
56
- if (attrValue.type === 'StringLiteral')
57
- return attrValue;
58
- if (attrValue.type === 'JSXExpressionContainer')
59
- return attrValue.expression;
60
- return attrValue;
57
+ if (attributeValue.type === 'StringLiteral')
58
+ return attributeValue;
59
+ if (attributeValue.type === 'JSXExpressionContainer')
60
+ return attributeValue.expression;
61
+ return attributeValue;
61
62
  }
62
63
  /**
63
- * A static ARGB8888 C literal (`0xAARRGGBBu`) from a CSS color string or number.
64
+ * A static ARGB8888 value from a CSS color string or number.
64
65
  *
65
66
  * @param value The color.
66
67
  *
67
- * @returns Its C literal.
68
+ * @returns Its value.
68
69
  */
69
- export function argbLiteral(value) {
70
- return ('0x' +
71
- (parseColor(String(value)) >>> 0)
72
- .toString(16)
73
- .padStart(8, '0')
74
- .toUpperCase() +
75
- 'u');
76
- }
70
+ export const argbValue = (value) => parseColor(String(value)) >>> 0;
77
71
  /**
78
72
  * Refuses an animated binding whose values do not fit the key: a color key takes only an interpolation onto
79
73
  * colors, and every other key only numbers.
80
74
  *
81
75
  * @param key The style or transform key.
82
- * @param interp The binding's interpolation, or undefined for the value itself.
76
+ * @param interpolation The binding's interpolation, or undefined for the value itself.
83
77
  * @param node The node to pin an error to.
84
78
  */
85
- function checkAnimatedColor(key, interp, node) {
86
- if (ANIM_COLOR_KEYS.has(key) && !interp?.colors) {
79
+ function checkAnimatedColor(key, interpolation, node) {
80
+ if (ANIMATED_COLOR_KEYS.has(key) && !interpolation?.colors) {
87
81
  throw at(aotError(`AOT: an animated "${key}" needs colors`, "bind value.interpolate({inputRange: [0, 1], outputRange: ['#000', '#fff']}) rather than a number."), node);
88
82
  }
89
- if (!ANIM_COLOR_KEYS.has(key) && interp?.colors) {
83
+ if (!ANIMATED_COLOR_KEYS.has(key) && interpolation?.colors) {
90
84
  throw at(aotError(`AOT: an animated "${key}" takes numbers, not colors`, 'an outputRange of colors drives backgroundColor or color.'), node);
91
85
  }
92
86
  }
@@ -94,34 +88,34 @@ function checkAnimatedColor(key, interp, node) {
94
88
  * Lowers a dynamic (state-referencing) color expression to an ARGB value: a color, or a ternary of them.
95
89
  *
96
90
  * @param node The color expression.
97
- * @param env The expression environment.
91
+ * @param environment The expression environment.
98
92
  *
99
93
  * @returns The value.
100
94
  */
101
- export function lowerColorValue(node, env) {
95
+ export function lowerColorValue(node, environment) {
102
96
  if (node.type === 'StringLiteral') {
103
- return { kind: 'constant', code: colorLiteral(node.value) };
97
+ return { kind: 'constant', value: parseColorValue(node.value) };
104
98
  }
105
99
  if (node.type === 'ConditionalExpression') {
106
100
  return {
107
101
  kind: 'select',
108
- test: lowerExpr(node.test, env),
109
- whenTrue: lowerColorValue(node.consequent, env),
110
- whenFalse: lowerColorValue(node.alternate, env),
102
+ test: lowerExpr(node.test, environment),
103
+ whenTrue: lowerColorValue(node.consequent, environment),
104
+ whenFalse: lowerColorValue(node.alternate, environment),
111
105
  };
112
106
  }
113
107
  // A const worked out at boot picks its color at boot, from its own expression.
114
- const bootAlias = bootAliasOf(node, env);
108
+ const bootAlias = bootAliasOf(node, environment);
115
109
  if (bootAlias) {
116
- const picked = tryLowering(() => lowerColorValue(bootAlias.node, bootAlias.env));
110
+ const picked = tryLowering(() => lowerColorValue(bootAlias.node, bootAlias.environment));
117
111
  if (picked)
118
112
  return picked;
119
113
  }
120
114
  // A statically resolvable color (a const string, or a theme token like `theme.card`) folds to a literal.
121
115
  try {
122
- const color = evalStatic(node, foldScope(env, env.consts ?? {}));
116
+ const color = evalStatic(node, foldScope(environment, environment.constants ?? {}));
123
117
  if (typeof color === 'string') {
124
- return { kind: 'constant', code: colorLiteral(color) };
118
+ return { kind: 'constant', value: parseColorValue(color) };
125
119
  }
126
120
  }
127
121
  catch {
@@ -129,26 +123,17 @@ export function lowerColorValue(node, env) {
129
123
  }
130
124
  throw new Error('AOT: a dynamic color must be a color string literal or a ternary of them');
131
125
  }
132
- /**
133
- * A dynamic color expression as C for its ARGB value (see lowerColorValue).
134
- *
135
- * @param node The color expression.
136
- * @param env The expression environment.
137
- *
138
- * @returns The C.
139
- */
140
- export const emitColorExpr = (node, env) => printPropValue(lowerColorValue(node, env));
141
126
  /**
142
127
  * Lowers a dynamic enum-style expression (e.g. `flexDirection: row ? 'row' : 'column'`) to its ER_* constant
143
128
  * (or a ternary of them), looking values up in the style key's enum `table`.
144
129
  *
145
130
  * @param node The enum expression.
146
131
  * @param table The RN value → ER_* constant table.
147
- * @param env The expression environment.
132
+ * @param environment The expression environment.
148
133
  *
149
134
  * @returns The value.
150
135
  */
151
- export function lowerEnumValue(node, table, env) {
136
+ export function lowerEnumValue(node, table, environment) {
152
137
  if (node.type === 'StringLiteral') {
153
138
  const enumConstant = Object.hasOwn(table, node.value)
154
139
  ? table[node.value]
@@ -156,28 +141,28 @@ export function lowerEnumValue(node, table, env) {
156
141
  if (!enumConstant) {
157
142
  throw aotError(`AOT: unsupported enum value "${node.value}"`, `one of: ${Object.keys(table).join(', ')}`);
158
143
  }
159
- return { kind: 'constant', code: enumConstant };
144
+ return { kind: 'constant', value: enumConstant };
160
145
  }
161
146
  if (node.type === 'ConditionalExpression') {
162
147
  return {
163
148
  kind: 'select',
164
- test: lowerExpr(node.test, env),
165
- whenTrue: lowerEnumValue(node.consequent, table, env),
166
- whenFalse: lowerEnumValue(node.alternate, table, env),
149
+ test: lowerExpr(node.test, environment),
150
+ whenTrue: lowerEnumValue(node.consequent, table, environment),
151
+ whenFalse: lowerEnumValue(node.alternate, table, environment),
167
152
  };
168
153
  }
169
154
  // A const worked out at boot picks its value at boot, from its own expression.
170
- const bootAlias = bootAliasOf(node, env);
155
+ const bootAlias = bootAliasOf(node, environment);
171
156
  if (bootAlias) {
172
- const picked = tryLowering(() => lowerEnumValue(bootAlias.node, table, bootAlias.env));
157
+ const picked = tryLowering(() => lowerEnumValue(bootAlias.node, table, bootAlias.environment));
173
158
  if (picked)
174
159
  return picked;
175
160
  }
176
161
  // A statically resolvable enum (a const string) folds to its constant.
177
162
  try {
178
- const enumValue = evalStatic(node, foldScope(env, env.consts ?? {}));
163
+ const enumValue = evalStatic(node, foldScope(environment, environment.constants ?? {}));
179
164
  if (typeof enumValue === 'string' && Object.hasOwn(table, enumValue)) {
180
- return { kind: 'constant', code: table[enumValue] };
165
+ return { kind: 'constant', value: table[enumValue] };
181
166
  }
182
167
  }
183
168
  catch {
@@ -185,16 +170,6 @@ export function lowerEnumValue(node, table, env) {
185
170
  }
186
171
  throw aotError('AOT: a state-driven enum style must be a string literal or a ternary of them', "e.g. flexDirection: wide ? 'row' : 'column'");
187
172
  }
188
- /**
189
- * A dynamic enum-style expression as C for its ER_* value (see lowerEnumValue).
190
- *
191
- * @param node The enum expression.
192
- * @param table The RN value → ER_* constant table.
193
- * @param env The expression environment.
194
- *
195
- * @returns The C.
196
- */
197
- export const emitEnumExpr = (node, table, env) => printPropValue(lowerEnumValue(node, table, env));
198
173
  /**
199
174
  * The diagnostic for a style key the AOT has no lowering for, static or dynamic.
200
175
  *
@@ -236,11 +211,11 @@ function lowerStyleChecked(key, value) {
236
211
  *
237
212
  * @param key The style key.
238
213
  * @param valueNode Its state-driven value.
239
- * @param env The expression environment.
214
+ * @param environment The expression environment.
240
215
  *
241
216
  * @returns The ERProps writes.
242
217
  */
243
- function lowerDynamicStyleValue(key, valueNode, env) {
218
+ function lowerDynamicStyleValue(key, valueNode, environment) {
244
219
  // Own properties only, so a key like `toString` cannot resolve to Object.prototype and emit `p.undefined`.
245
220
  const dynamicField = Object.hasOwn(DYN_FIELDS, key)
246
221
  ? DYN_FIELDS[key]
@@ -254,24 +229,27 @@ function lowerDynamicStyleValue(key, valueNode, env) {
254
229
  `layout enums (flexDirection, alignItems, alignSelf, justifyContent, position, ` +
255
230
  `display). Make "${key}" static, or drive the change another way.`);
256
231
  }
257
- // Colors and enums lower to a constant or a C ternary of constants.
232
+ // Colors and enums lower to a constant or a choice of constants.
258
233
  if (dynamicField.kind === 'color') {
259
234
  return [
260
- { field: dynamicField.field, value: lowerColorValue(valueNode, env) },
235
+ {
236
+ field: dynamicField.field,
237
+ value: lowerColorValue(valueNode, environment),
238
+ },
261
239
  ];
262
240
  }
263
241
  if (dynamicField.kind === 'enum') {
264
242
  return [
265
243
  {
266
244
  field: dynamicField.field,
267
- value: lowerEnumValue(valueNode, dynamicField.table, env),
245
+ value: lowerEnumValue(valueNode, dynamicField.table, environment),
268
246
  },
269
247
  ];
270
248
  }
271
- // Opacity and every size are numbers; C would take a char[] here as its address or refuse it.
272
- const valueExpr = lowerExpr(valueNode, env);
273
- if (valueExpr.type.kind === 'string') {
274
- const error = aotError(`AOT: style "${key}" needs a number, but the value is a string`, "JS would coerce the string; C cannot. Keep the state numeric — useState(10), not useState('10').");
249
+ // Opacity and every size are numbers.
250
+ const valueExpression = lowerExpr(valueNode, environment);
251
+ if (shapeOf(valueExpression) === 'string') {
252
+ const error = aotError(`AOT: style "${key}" needs a number, but the value is a string`, "JS would coerce the string; the AOT doesn't. Keep the state numeric — useState(10), not useState('10').");
275
253
  if (valueNode.loc) {
276
254
  error.aotLoc = valueNode.loc.start;
277
255
  }
@@ -279,11 +257,26 @@ function lowerDynamicStyleValue(key, valueNode, env) {
279
257
  }
280
258
  if (dynamicField.kind === 'opacity') {
281
259
  return [
282
- { field: dynamicField.field, value: { kind: 'opacity', value: valueExpr } },
260
+ {
261
+ field: dynamicField.field,
262
+ value: { kind: 'opacity', value: valueExpression },
263
+ },
264
+ ];
265
+ }
266
+ // A byte field takes a float with its fraction dropped, where a dimension would round it.
267
+ if (dynamicField.kind === 'byte') {
268
+ return [
269
+ {
270
+ field: dynamicField.field,
271
+ value: { kind: 'float', value: valueExpression },
272
+ },
283
273
  ];
284
274
  }
285
275
  return [
286
- { field: dynamicField.field, value: { kind: 'dimension', value: valueExpr } },
276
+ {
277
+ field: dynamicField.field,
278
+ value: { kind: 'dimension', value: valueExpression },
279
+ },
287
280
  ];
288
281
  }
289
282
  /**
@@ -291,22 +284,22 @@ function lowerDynamicStyleValue(key, valueNode, env) {
291
284
  * entry of one), for a lowering that picks between literals.
292
285
  *
293
286
  * @param node The expression.
294
- * @param env The expression environment.
287
+ * @param environment The expression environment.
295
288
  *
296
289
  * @returns The value's own expression and the environment it lowers in, or null.
297
290
  */
298
- function bootAliasOf(node, env) {
291
+ function bootAliasOf(node, environment) {
299
292
  let value;
300
293
  try {
301
- value = evalStatic(node, foldScope(env, env.consts ?? {}), 'boot');
294
+ value = evalStatic(node, foldScope(environment, environment.constants ?? {}), 'boot');
302
295
  }
303
296
  catch {
304
297
  return null;
305
298
  }
306
299
  if (!isBoot(value) || !value.node || value.node === node)
307
300
  return null;
308
- const bootEnv = bootEnvOf(value);
309
- return bootEnv && { node: value.node, env: bootEnv };
301
+ const bootEnvironment = bootEnvOf(value);
302
+ return bootEnvironment && { node: value.node, environment: bootEnvironment };
310
303
  }
311
304
  /**
312
305
  * A style entry worked out at boot, as the runtime write of its field: a size or an opacity. Null for a value
@@ -317,7 +310,7 @@ function bootAliasOf(node, env) {
317
310
  *
318
311
  * @returns The write, or null.
319
312
  */
320
- function bootStyleAssign(key, value) {
313
+ export function bootStyleAssign(key, value) {
321
314
  const dynamicField = Object.hasOwn(DYN_FIELDS, key)
322
315
  ? DYN_FIELDS[key]
323
316
  : undefined;
@@ -326,17 +319,18 @@ function bootStyleAssign(key, value) {
326
319
  : undefined;
327
320
  // A color or an enum lowers its own expression (a ternary of literals) against the names it reads.
328
321
  if (dynamicField?.kind === 'color' || dynamicField?.kind === 'enum') {
329
- const env = bootEnvOf(value);
322
+ const environment = bootEnvOf(value);
330
323
  const valueNode = value.node;
331
- if (!env || !valueNode)
324
+ if (!environment || !valueNode)
332
325
  return null;
333
326
  const propValue = tryLowering(() => dynamicField.kind === 'enum'
334
- ? lowerEnumValue(valueNode, dynamicField.table, env)
335
- : lowerColorValue(valueNode, env));
327
+ ? lowerEnumValue(valueNode, dynamicField.table, environment)
328
+ : lowerColorValue(valueNode, environment));
336
329
  return propValue && { field: dynamicField.field, value: propValue };
337
330
  }
338
331
  const isNumeric = pixelField ||
339
332
  dynamicField?.kind === 'opacity' ||
333
+ dynamicField?.kind === 'byte' ||
340
334
  dynamicField?.kind === 'num';
341
335
  if (!isNumeric)
342
336
  return null;
@@ -348,7 +342,11 @@ function bootStyleAssign(key, value) {
348
342
  return {
349
343
  field: pixelField ?? dynamicField.field,
350
344
  value: {
351
- kind: dynamicField?.kind === 'opacity' ? 'opacity' : 'dimension',
345
+ kind: dynamicField?.kind === 'opacity'
346
+ ? 'opacity'
347
+ : dynamicField?.kind === 'byte'
348
+ ? 'float'
349
+ : 'dimension',
352
350
  value: { kind: 'boot', slot, type: slot.type },
353
351
  },
354
352
  };
@@ -359,16 +357,16 @@ function bootStyleAssign(key, value) {
359
357
  *
360
358
  * @param key The style key.
361
359
  * @param valueNode The value expression.
362
- * @param env The expression environment.
360
+ * @param environment The expression environment.
363
361
  *
364
362
  * @returns The runtime writes.
365
363
  */
366
- function lowerBootStyleValue(key, valueNode, env) {
364
+ function lowerBootStyleValue(key, valueNode, environment) {
367
365
  if (!Object.hasOwn(BOOT_PIXEL_FIELDS, key)) {
368
- return lowerDynamicStyleValue(key, valueNode, env);
366
+ return lowerDynamicStyleValue(key, valueNode, environment);
369
367
  }
370
- const value = lowerExpr(valueNode, env);
371
- if (value.type.kind !== 'int' && value.type.kind !== 'float') {
368
+ const value = lowerExpr(valueNode, environment);
369
+ if (shapeOf(value) !== 'number') {
372
370
  throw new Error(`AOT: style "${key}" needs a number`);
373
371
  }
374
372
  return [{ field: BOOT_PIXEL_FIELDS[key], value: { kind: 'dimension', value } }];
@@ -390,18 +388,18 @@ function tryLowering(attempt) {
390
388
  }
391
389
  /**
392
390
  * Whether a style already writes `field`, counting its percentage twin: `width: '50%'` lowers to
393
- * `width_pct`, and the author has still set the width. Used by the components that fall back to a
391
+ * `width_percent`, and the author has still set the width. Used by the components that fall back to a
394
392
  * built-in size or inset when the style leaves one out — without the twin they inject a pixel default
395
393
  * ALONGSIDE the percentage, and the engine prefers the pixel value for a size.
396
394
  *
397
395
  * @param staticAssigns Static field writes from collectStyleAssigns().
398
- * @param dynAssigns State-driven field writes from collectStyleAssigns().
396
+ * @param dynamicAssigns State-driven field writes from collectStyleAssigns().
399
397
  * @param field ERProps field to look for.
400
398
  *
401
- * @returns Whether either list writes the field or its `_pct` twin.
399
+ * @returns Whether either list writes the field or its `_percent` twin.
402
400
  */
403
- export const styleWrites = (staticAssigns, dynAssigns, field) => [field, `${field}_pct`].some(fieldName => staticAssigns.some(assign => assign.field === fieldName) ||
404
- dynAssigns.some(assign => assign.field === fieldName));
401
+ export const styleWrites = (staticAssigns, dynamicAssigns, field) => [field, `${field}_percent`].some(fieldName => staticAssigns.some(assign => assign.field === fieldName) ||
402
+ dynamicAssigns.some(assign => assign.field === fieldName));
405
403
  /**
406
404
  * Collects an element's merged style into static field assigns and dynamic (state-driven) field assigns.
407
405
  * Inline object values are tried statically first; a value that references state becomes a dynAssign.
@@ -410,36 +408,38 @@ export const styleWrites = (staticAssigns, dynAssigns, field) => [field, `${fiel
410
408
  *
411
409
  * @param openingElement The element's opening tag.
412
410
  * @param scope Compile-time constants in reach.
413
- * @param env The expression environment.
411
+ * @param environment The expression environment.
414
412
  * @param spec The element, for the style keys it takes.
415
413
  * @param bootValues How a value worked out at boot is set: once at build, or taken at the build's panel.
416
414
  *
417
415
  * @returns The style's constant writes, state-driven writes, and animated-value binds.
418
416
  */
419
- export function collectStyleAssigns(openingElement, scope, env, spec, bootValues = 'boot') {
420
- // ERProps field → its last write: a constant's C, or a state-driven value.
417
+ export function collectStyleAssigns(openingElement, scope, environment, spec, bootValues = 'boot') {
418
+ // ERProps field → its last write: a constant, or a state-driven value.
421
419
  const fields = new Map();
422
420
  const binds = []; // animated values bound to node properties (native driver)
423
421
  // A size in pixels and its percentage twin are one style key, so a later write of either replaces both.
424
422
  const setField = (field, write) => {
425
- fields.delete(field.endsWith('_pct') ? field.slice(0, -'_pct'.length) : `${field}_pct`);
423
+ fields.delete(field.endsWith('_percent')
424
+ ? field.slice(0, -'_percent'.length)
425
+ : `${field}_percent`);
426
426
  fields.set(field, write);
427
427
  };
428
- // The C handle of an animated value used directly as a style value, or null.
429
- const animRef = (node) => node?.type === 'Identifier' && env.animations?.has(node.name)
430
- ? env.animations.get(node.name).cVar
428
+ // The handle of an animated value used directly as a style value, or null.
429
+ const animRef = (node) => node?.type === 'Identifier' && environment.animations?.has(node.name)
430
+ ? environment.animations.get(node.name).slotName
431
431
  : null;
432
- // `<animValue>.interpolate({ inputRange, outputRange, extrapolate })` → { cVar, interp } for a mapped bind.
432
+ // `<animValue>.interpolate({ inputRange, outputRange, extrapolate })` → { slotName, interp } for a mapped bind.
433
433
  const animInterpRef = (node) => {
434
434
  if (node?.type === 'CallExpression' &&
435
435
  node.callee.type === 'MemberExpression' &&
436
436
  !node.callee.computed &&
437
437
  node.callee.property.name === 'interpolate' &&
438
438
  node.callee.object.type === 'Identifier' &&
439
- env.animations?.has(node.callee.object.name)) {
439
+ environment.animations?.has(node.callee.object.name)) {
440
440
  return {
441
- cVar: env.animations.get(node.callee.object.name).cVar,
442
- interp: parseInterp(node.arguments[0], env),
441
+ slotName: environment.animations.get(node.callee.object.name).slotName,
442
+ interpolation: parseInterp(node.arguments[0], environment),
443
443
  };
444
444
  }
445
445
  return null;
@@ -468,14 +468,18 @@ export function collectStyleAssigns(openingElement, scope, env, spec, bootValues
468
468
  continue;
469
469
  }
470
470
  // An animated entry the engine has no property for is refused, not skipped.
471
- if (!Object.hasOwn(ANIM_TRANSFORM_PROPS, transformKey)) {
472
- throw at(aotError(`AOT: transform "${transformKey}" cannot be animated in Flow B`, `animated transforms: ${Object.keys(ANIM_TRANSFORM_PROPS).join(', ')}.`), transformProp);
471
+ if (!Object.hasOwn(ANIMATED_TRANSFORM_PROPS, transformKey)) {
472
+ throw at(aotError(`AOT: transform "${transformKey}" cannot be animated in Flow B`, `animated transforms: ${Object.keys(ANIMATED_TRANSFORM_PROPS).join(', ')}.`), transformProp);
473
473
  }
474
- checkAnimatedColor(transformKey, mapped?.interp, transformProp);
475
- for (const animProp of ANIM_TRANSFORM_PROPS[transformKey]) {
474
+ checkAnimatedColor(transformKey, mapped?.interpolation, transformProp);
475
+ for (const animationProp of ANIMATED_TRANSFORM_PROPS[transformKey]) {
476
476
  transformBinds.push(mapped
477
- ? { cVar: mapped.cVar, prop: animProp, interp: mapped.interp }
478
- : { cVar: direct, prop: animProp });
477
+ ? {
478
+ slotName: mapped.slotName,
479
+ prop: animationProp,
480
+ interpolation: mapped.interpolation,
481
+ }
482
+ : { slotName: direct, prop: animationProp });
479
483
  }
480
484
  }
481
485
  }
@@ -488,22 +492,22 @@ export function collectStyleAssigns(openingElement, scope, env, spec, bootValues
488
492
  return transformBinds;
489
493
  };
490
494
  // Lowers one style source (an array, an inline object, or a static reference) into `fields` and `binds`.
491
- const applyStyle = (expr) => {
495
+ const applyStyle = (expression) => {
492
496
  // RN ignores an undefined style or style-array entry; so does Flow A's flattenStyle.
493
- if (expr.type === 'Identifier' && expr.name === 'undefined')
497
+ if (expression.type === 'Identifier' && expression.name === 'undefined')
494
498
  return;
495
499
  // A style array applies its entries in order, so later entries win.
496
- if (expr.type === 'ArrayExpression') {
497
- for (const styleEntry of expr.elements) {
500
+ if (expression.type === 'ArrayExpression') {
501
+ for (const styleEntry of expression.elements) {
498
502
  if (styleEntry) {
499
503
  applyStyle(styleEntry);
500
504
  }
501
505
  }
502
506
  return;
503
507
  }
504
- // Inline object: bind animated values natively; fold other keys statically or re-apply them in app_update.
505
- if (expr.type === 'ObjectExpression') {
506
- for (const prop of expr.properties) {
508
+ // Inline object: bind animated values natively; fold other keys statically or re-apply them in the update.
509
+ if (expression.type === 'ObjectExpression') {
510
+ for (const prop of expression.properties) {
507
511
  if (prop.type !== 'ObjectProperty') {
508
512
  throw new Error('AOT: spread/method in an inline style object not supported');
509
513
  }
@@ -517,24 +521,24 @@ export function collectStyleAssigns(openingElement, scope, env, spec, bootValues
517
521
  continue;
518
522
  }
519
523
  // Bind an animated value to its prop (opacity / backgroundColor / color), directly or via .interpolate().
520
- const animVar = animRef(prop.value);
521
- if (animVar && ANIM_STYLE_PROPS[key]) {
524
+ const animationValue = animRef(prop.value);
525
+ if (animationValue && ANIMATED_STYLE_PROPS[key]) {
522
526
  checkAnimatedStyleKey(spec, key, prop);
523
527
  checkAnimatedColor(key, undefined, prop);
524
- for (const animProp of ANIM_STYLE_PROPS[key]) {
525
- binds.push({ cVar: animVar, prop: animProp });
528
+ for (const animationProp of ANIMATED_STYLE_PROPS[key]) {
529
+ binds.push({ slotName: animationValue, prop: animationProp });
526
530
  }
527
531
  continue;
528
532
  }
529
- const animInterp = animInterpRef(prop.value);
530
- if (animInterp && ANIM_STYLE_PROPS[key]) {
533
+ const animationInterpolation = animInterpRef(prop.value);
534
+ if (animationInterpolation && ANIMATED_STYLE_PROPS[key]) {
531
535
  checkAnimatedStyleKey(spec, key, prop);
532
- checkAnimatedColor(key, animInterp.interp, prop);
533
- for (const animProp of ANIM_STYLE_PROPS[key]) {
536
+ checkAnimatedColor(key, animationInterpolation.interpolation, prop);
537
+ for (const animationProp of ANIMATED_STYLE_PROPS[key]) {
534
538
  binds.push({
535
- cVar: animInterp.cVar,
536
- prop: animProp,
537
- interp: animInterp.interp,
539
+ slotName: animationInterpolation.slotName,
540
+ prop: animationProp,
541
+ interpolation: animationInterpolation.interpolation,
538
542
  });
539
543
  }
540
544
  continue;
@@ -553,7 +557,7 @@ export function collectStyleAssigns(openingElement, scope, env, spec, bootValues
553
557
  let readsBoot = false;
554
558
  try {
555
559
  staticValue = {
556
- v: evalStatic(prop.value, withUndefined(scope), bootValues === 'fold' ? 'fold' : 'strict'),
560
+ value: evalStatic(prop.value, withUndefined(scope), bootValues === 'fold' ? 'fold' : 'strict'),
557
561
  };
558
562
  }
559
563
  catch (error) {
@@ -562,7 +566,7 @@ export function collectStyleAssigns(openingElement, scope, env, spec, bootValues
562
566
  }
563
567
  // A value worked out at boot is set once at build; a key that takes no runtime value folds it instead.
564
568
  if (readsBoot) {
565
- const bootAssigns = tryLowering(() => lowerBootStyleValue(key, prop.value, env));
569
+ const bootAssigns = tryLowering(() => lowerBootStyleValue(key, prop.value, environment));
566
570
  if (bootAssigns) {
567
571
  checkStyleKey(spec, key, prop);
568
572
  for (const assign of bootAssigns) {
@@ -570,19 +574,19 @@ export function collectStyleAssigns(openingElement, scope, env, spec, bootValues
570
574
  }
571
575
  continue;
572
576
  }
573
- staticValue = { v: evalStatic(prop.value, withUndefined(scope)) };
577
+ staticValue = { value: evalStatic(prop.value, withUndefined(scope)) };
574
578
  }
575
579
  if (staticValue) {
576
- if (staticValue.v != null) {
580
+ if (staticValue.value != null) {
577
581
  checkStyleKey(spec, key, prop);
578
582
  }
579
- for (const assign of lowerStyleChecked(key, staticValue.v)) {
580
- setField(assign.field, { code: assign.expr });
583
+ for (const assign of lowerStyleChecked(key, staticValue.value)) {
584
+ setField(assign.field, { constant: assign.value });
581
585
  }
582
586
  }
583
587
  else {
584
588
  checkStyleKey(spec, key, prop);
585
- for (const assign of lowerDynamicStyleValue(key, prop.value, env)) {
589
+ for (const assign of lowerDynamicStyleValue(key, prop.value, environment)) {
586
590
  setField(assign.field, { value: assign.value });
587
591
  }
588
592
  }
@@ -590,7 +594,7 @@ export function collectStyleAssigns(openingElement, scope, env, spec, bootValues
590
594
  return;
591
595
  }
592
596
  // A static style reference; null, undefined or false (`cond && s`) means no style, as in RN.
593
- let resolved = evalStatic(expr, withUndefined(scope), 'boot');
597
+ let resolved = evalStatic(expression, withUndefined(scope), 'boot');
594
598
  if (isBoot(resolved)) {
595
599
  resolved = foldBoot(resolved);
596
600
  }
@@ -603,39 +607,39 @@ export function collectStyleAssigns(openingElement, scope, env, spec, bootValues
603
607
  ? bootStyleAssign(styleKey, entry)
604
608
  : null;
605
609
  if (bootAssign) {
606
- checkStyleKey(spec, styleKey, expr);
610
+ checkStyleKey(spec, styleKey, expression);
607
611
  setField(bootAssign.field, { value: bootAssign.value });
608
612
  continue;
609
613
  }
610
614
  const styleValue = foldBoot(entry);
611
615
  if (styleValue === undefined || styleValue === null)
612
616
  continue;
613
- checkStyleKey(spec, styleKey, expr);
617
+ checkStyleKey(spec, styleKey, expression);
614
618
  for (const assign of lowerStyleChecked(styleKey, styleValue)) {
615
- setField(assign.field, { code: assign.expr });
619
+ setField(assign.field, { constant: assign.value });
616
620
  }
617
621
  }
618
622
  };
619
623
  // Apply every style attribute in source order.
620
- for (const attr of openingElement.attributes) {
621
- if (attr.type !== 'JSXAttribute' ||
622
- attr.name.name !== 'style') {
624
+ for (const attribute of openingElement.attributes) {
625
+ if (attribute.type !== 'JSXAttribute' ||
626
+ attribute.name.name !== 'style') {
623
627
  continue;
624
628
  }
625
- applyStyle(attrExpr(attr));
629
+ applyStyle(attrExpr(attribute));
626
630
  }
627
631
  // Split the merged fields into constant writes and state-driven writes.
628
632
  const staticAssigns = [];
629
- const dynAssigns = [];
633
+ const dynamicAssigns = [];
630
634
  for (const [field, fieldWrite] of fields) {
631
635
  if ('value' in fieldWrite) {
632
- dynAssigns.push({ field, value: fieldWrite.value });
636
+ dynamicAssigns.push({ field, value: fieldWrite.value });
633
637
  }
634
638
  else {
635
- staticAssigns.push({ field, expr: fieldWrite.code });
639
+ staticAssigns.push({ field, value: fieldWrite.constant });
636
640
  }
637
641
  }
638
- return { staticAssigns, dynAssigns, binds };
642
+ return { staticAssigns, dynamicAssigns, binds };
639
643
  }
640
644
  /**
641
645
  * Lowers a Text node's body. Static interpolations fold into literal text; any that reference state are values
@@ -643,11 +647,11 @@ export function collectStyleAssigns(openingElement, scope, env, spec, bootValues
643
647
  *
644
648
  * @param children The <Text>'s children.
645
649
  * @param scope Compile-time constants in reach.
646
- * @param env The expression environment.
650
+ * @param environment The expression environment.
647
651
  *
648
652
  * @returns The body.
649
653
  */
650
- export function lowerNodeText(children, scope, env) {
654
+ export function lowerNodeText(children, scope, environment) {
651
655
  const parts = [];
652
656
  for (const child of inlineFragments(children)) {
653
657
  if (child.type === 'JSXText') {
@@ -657,7 +661,7 @@ export function lowerNodeText(children, scope, env) {
657
661
  if (child.expression.type === 'JSXEmptyExpression')
658
662
  continue;
659
663
  // Constants fold into literal text; anything referencing state is a runtime value.
660
- parts.push(...lowerText(child.expression, env, scope).parts);
664
+ parts.push(...lowerText(child.expression, environment, scope).parts);
661
665
  }
662
666
  else if (child.type === 'JSXElement') {
663
667
  throw new Error('AOT: nested <Text> / element children inside <Text> not yet supported (spans)');
@@ -739,17 +743,17 @@ function staticTextContent(children, scope) {
739
743
  }
740
744
  /**
741
745
  * If a <Text>'s children include a nested <Text>, returns inline SPANS [{text, color, font_size,
742
- * font_weight, font_style, text_decoration, letter_spacing}] (C-expr fields; inherit sentinels for unset).
746
+ * font_weight, font_style, text_decoration, letter_spacing}] (constants; inherit sentinels for unset).
743
747
  * Returns null when there's no nested <Text> (caller uses the single-string buildText path). Static only —
744
748
  * a dynamic {…} segment or a state-driven span style throws.
745
749
  *
746
750
  * @param children The <Text>'s children.
747
751
  * @param scope Compile-time constants in reach.
748
- * @param env The expression environment.
752
+ * @param environment The expression environment.
749
753
  *
750
754
  * @returns The spans, or null when the <Text> has no nested <Text>.
751
755
  */
752
- export function collectTextSpans(children, scope, env) {
756
+ export function collectTextSpans(children, scope, environment) {
753
757
  // Without a nested <Text>, the caller uses the single-string buildText path.
754
758
  children = inlineFragments(children);
755
759
  if (!children.some(child => child.type === 'JSXElement' &&
@@ -759,17 +763,17 @@ export function collectTextSpans(children, scope, env) {
759
763
  // Inherit sentinels (see ERTextSpan doc): color 0, font_size 0, weight/style/decoration 0xFF, spacing AUTO.
760
764
  const inheritSpan = (text) => ({
761
765
  text,
762
- color: '0u',
763
- font_size: '0',
764
- font_weight: '0xFF',
765
- font_style: '0xFF',
766
- text_decoration: '0xFF',
766
+ color: 0,
767
+ font_size: 0,
768
+ font_weight: SPAN_INHERIT,
769
+ font_style: SPAN_INHERIT,
770
+ text_decoration: SPAN_INHERIT,
767
771
  letter_spacing: 'ER_LAYOUT_AUTO',
768
772
  });
769
- // A span's text is a C literal in a fixed engine buffer.
773
+ // A span's text goes in a fixed engine buffer.
770
774
  const spanText = (text) => {
771
775
  checkEngineString(text, 'ER_SPAN_TEXT_MAX', 'a <Text> span');
772
- return cstr(text);
776
+ return text;
773
777
  };
774
778
  // One span per child: text and static {…} values inherit the parent's style; a nested <Text> carries its own.
775
779
  const spans = [];
@@ -799,20 +803,20 @@ export function collectTextSpans(children, scope, env) {
799
803
  child.openingElement.name.name === 'Text') {
800
804
  checkAttributes(TEXT_SPAN, child.openingElement);
801
805
  // A span is a static table, so a value worked out at boot is taken at the build's panel instead.
802
- const { staticAssigns, dynAssigns } = collectStyleAssigns(child.openingElement, scope, env, TEXT_SPAN, 'fold');
803
- if (dynAssigns.length) {
806
+ const { staticAssigns, dynamicAssigns } = collectStyleAssigns(child.openingElement, scope, environment, TEXT_SPAN, 'fold');
807
+ if (dynamicAssigns.length) {
804
808
  throw aotError('AOT: a state-driven style on a nested <Text> span is not supported', 'give the span <Text> a static style.');
805
809
  }
806
810
  // Each span field is the nested <Text>'s own static style value, or the inherit sentinel.
807
- const spanStyle = (fieldName, fallback) => staticAssigns.find(assign => assign.field === fieldName)?.expr ??
811
+ const spanStyle = (fieldName, fallback) => staticAssigns.find(assign => assign.field === fieldName)?.value ??
808
812
  fallback;
809
813
  spans.push({
810
814
  text: spanText(staticTextContent(child.children, scope)),
811
- color: spanStyle('color', '0u'),
812
- font_size: spanStyle('font_size', '0'),
813
- font_weight: spanStyle('font_weight', '0xFF'),
814
- font_style: spanStyle('font_style', '0xFF'),
815
- text_decoration: spanStyle('text_decoration', '0xFF'),
815
+ color: spanStyle('color', 0),
816
+ font_size: spanStyle('font_size', 0),
817
+ font_weight: spanStyle('font_weight', SPAN_INHERIT),
818
+ font_style: spanStyle('font_style', SPAN_INHERIT),
819
+ text_decoration: spanStyle('text_decoration', SPAN_INHERIT),
816
820
  letter_spacing: spanStyle('letter_spacing', 'ER_LAYOUT_AUTO'),
817
821
  });
818
822
  }
@@ -824,7 +828,7 @@ export function collectTextSpans(children, scope, env) {
824
828
  check({
825
829
  kind: 'textSpans',
826
830
  count: spans.length,
827
- max: env.caps.maxTextSpans,
831
+ max: environment.caps.maxTextSpans,
828
832
  });
829
833
  return spans;
830
834
  }