embedded-react 0.19.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/NOTICE +5 -0
  2. package/README.md +8 -3
  3. package/aot/app-file-loader.mjs +116 -0
  4. package/aot/compile.mjs +180 -90
  5. package/aot/compiler/animations.mjs +568 -317
  6. package/aot/compiler/boot.mjs +97 -35
  7. package/aot/compiler/branch-merge.mjs +4 -3
  8. package/aot/compiler/check.mjs +70 -18
  9. package/aot/compiler/collect.mjs +787 -288
  10. package/aot/compiler/contexts.mjs +391 -0
  11. package/aot/compiler/control-flow.mjs +439 -268
  12. package/aot/compiler/custom-hooks.mjs +686 -0
  13. package/aot/compiler/diagnostics.mjs +22 -25
  14. package/aot/compiler/elements/activity-indicator.mjs +25 -24
  15. package/aot/compiler/elements/button.mjs +182 -0
  16. package/aot/compiler/elements/dial.mjs +91 -77
  17. package/aot/compiler/elements/flat-list.mjs +24 -22
  18. package/aot/compiler/elements/image-background.mjs +76 -0
  19. package/aot/compiler/elements/image.mjs +52 -50
  20. package/aot/compiler/elements/modal.mjs +31 -30
  21. package/aot/compiler/elements/props.mjs +61 -26
  22. package/aot/compiler/elements/rewrite.mjs +118 -0
  23. package/aot/compiler/elements/section-list.mjs +370 -0
  24. package/aot/compiler/elements/switch.mjs +42 -34
  25. package/aot/compiler/elements/text-input.mjs +34 -32
  26. package/aot/compiler/expressions.mjs +1685 -392
  27. package/aot/compiler/handlers.mjs +2029 -547
  28. package/aot/compiler/helper-values.mjs +312 -0
  29. package/aot/compiler/ir/functions.mjs +11 -1
  30. package/aot/compiler/ir/nodes.mjs +43 -4
  31. package/aot/compiler/ir/reads.mjs +223 -22
  32. package/aot/compiler/ir/text.mjs +5 -1
  33. package/aot/compiler/ir/types.mjs +26 -14
  34. package/aot/compiler/ir/vectors.mjs +5 -1
  35. package/aot/compiler/kept-states.mjs +177 -0
  36. package/aot/compiler/keyboard.mjs +17 -7
  37. package/aot/compiler/list-items.mjs +226 -0
  38. package/aot/compiler/list-order.mjs +586 -0
  39. package/aot/compiler/list-split.mjs +259 -0
  40. package/aot/compiler/loops.mjs +582 -0
  41. package/aot/compiler/lower.mjs +246 -111
  42. package/aot/compiler/native-files.mjs +439 -0
  43. package/aot/compiler/native-header.mjs +335 -0
  44. package/aot/compiler/native-modules.mjs +1173 -0
  45. package/aot/compiler/nodes.mjs +195 -172
  46. package/aot/compiler/options.mjs +37 -31
  47. package/aot/compiler/out.mjs +32 -23
  48. package/aot/compiler/package/animations.mjs +779 -0
  49. package/aot/compiler/package/arena.mjs +252 -0
  50. package/aot/compiler/package/assemble.mjs +175 -0
  51. package/aot/compiler/package/bytecode.mjs +315 -0
  52. package/aot/compiler/package/checks.mjs +1026 -0
  53. package/aot/compiler/package/codegen.mjs +2168 -0
  54. package/aot/compiler/package/enums.mjs +148 -0
  55. package/aot/compiler/package/format.mjs +771 -0
  56. package/aot/compiler/package/layouts.mjs +136 -0
  57. package/aot/compiler/package/lower.mjs +2103 -0
  58. package/aot/compiler/package/props.mjs +118 -0
  59. package/aot/compiler/package/string-caps.mjs +515 -0
  60. package/aot/compiler/package/tables.mjs +127 -0
  61. package/aot/compiler/package/vectors.mjs +502 -0
  62. package/aot/compiler/package/writer.mjs +686 -0
  63. package/aot/compiler/pan-responder.mjs +69 -61
  64. package/aot/compiler/parse.mjs +23 -21
  65. package/aot/compiler/record-shapes.mjs +246 -0
  66. package/aot/compiler/records.mjs +654 -0
  67. package/aot/compiler/reducers.mjs +272 -0
  68. package/aot/compiler/static-eval.mjs +340 -30
  69. package/aot/compiler/style-text.mjs +178 -174
  70. package/aot/compiler/svg.mjs +480 -251
  71. package/aot/compiler/switch-cases.mjs +198 -0
  72. package/aot/compiler/tagged-records.mjs +450 -0
  73. package/aot/compiler/typing.mjs +307 -0
  74. package/aot/compiler/updaters.mjs +320 -0
  75. package/aot/compiler/window-dimensions.mjs +94 -0
  76. package/aot/compiler/worked-values.mjs +319 -0
  77. package/aot/demo-file.mjs +30 -0
  78. package/aot/screenshot-smoke.mjs +54 -40
  79. package/aot/style-map.mjs +152 -92
  80. package/assets/bake-font.mjs +123 -77
  81. package/assets/bake-image.mjs +39 -22
  82. package/assets/bake-svg.mjs +361 -262
  83. package/assets/build-builtin-font.mjs +11 -7
  84. package/assets/emit-c.mjs +77 -58
  85. package/assets/emit-container.mjs +123 -37
  86. package/assets/emit-pack.mjs +77 -67
  87. package/assets/font-config.mjs +9 -6
  88. package/assets/font-sizes.mjs +163 -123
  89. package/assets/glyph-coverage.mjs +74 -54
  90. package/assets/index.mjs +31 -9
  91. package/assets/rasterize.mjs +126 -99
  92. package/assets/svg-loader.mjs +8 -8
  93. package/build.mjs +23 -13
  94. package/cli.mjs +402 -172
  95. package/compile-bin.mjs +3 -3
  96. package/flash.mjs +537 -0
  97. package/hotreload/dev-device.mjs +90 -33
  98. package/hotreload/pack-app.mjs +55 -43
  99. package/hotreload/pack-split.mjs +62 -64
  100. package/hotreload/package-transfer.mjs +175 -0
  101. package/hotreload/protocol.mjs +50 -37
  102. package/hotreload/uploader.mjs +38 -27
  103. package/hotreload/watch-tree.mjs +19 -19
  104. package/pack-container.mjs +37 -21
  105. package/package.json +7 -8
  106. package/persist-transform.mjs +34 -28
  107. package/qjsc-wasm.mjs +25 -14
  108. package/sim/embedded-react.cjs +1 -1
  109. package/sim/embedded-react.js +1 -1
  110. package/sim/embedded-react.wasm +0 -0
  111. package/sim/index.html +94 -85
  112. package/sim-server.mjs +113 -94
  113. package/src/embedded-react/Animated.js +24 -24
  114. package/src/embedded-react/Dimensions.js +37 -0
  115. package/src/embedded-react/Easing.js +1 -1
  116. package/src/embedded-react/FlatList.js +3 -3
  117. package/src/embedded-react/LayoutAnimation.js +8 -5
  118. package/src/embedded-react/PanResponder.js +75 -71
  119. package/src/embedded-react/Pressable.js +2 -8
  120. package/src/embedded-react/SectionList.js +7 -9
  121. package/src/embedded-react/StyleSheet.js +4 -3
  122. package/src/embedded-react/TouchableOpacity.js +13 -8
  123. package/src/embedded-react/index.d.ts +88 -8
  124. package/src/embedded-react/index.js +2 -0
  125. package/src/embedded-react/layout-anim-config.js +10 -4
  126. package/src/embedded-react/list-child.js +5 -5
  127. package/src/embedded-react/named-colors.js +1 -1
  128. package/src/embedded-react/nativeModule.js +462 -0
  129. package/src/embedded-react/split-style.js +11 -11
  130. package/src/embedded-react/svg-ops.js +760 -593
  131. package/src/embedded-react/useHostValue.js +3 -3
  132. package/src/embedded-react/usePersistentState.js +6 -6
  133. package/src/embedded-react/warn-props.js +1 -1
  134. package/src/host-config.js +60 -53
  135. package/src/props.js +49 -41
  136. package/src/renderer.js +7 -4
  137. package/aot/compiler/assemble.mjs +0 -944
  138. package/aot/compiler/c/animations.mjs +0 -436
  139. package/aot/compiler/c/boot.mjs +0 -127
  140. package/aot/compiler/c/expressions.mjs +0 -270
  141. package/aot/compiler/c/functions.mjs +0 -268
  142. package/aot/compiler/c/keyboard.mjs +0 -96
  143. package/aot/compiler/c/nodes.mjs +0 -303
  144. package/aot/compiler/c/pan-responder.mjs +0 -136
  145. package/aot/compiler/c/statements.mjs +0 -319
  146. package/aot/compiler/c/text.mjs +0 -83
  147. package/aot/compiler/c/vectors.mjs +0 -381
  148. package/aot/compiler/c-syntax.mjs +0 -127
package/aot/style-map.mjs CHANGED
@@ -17,6 +17,7 @@
17
17
  - Imports
18
18
  ---------------------------------------------------------------------------------------------------------------------*/
19
19
  import { NAMED_COLORS } from '../src/embedded-react/named-colors.js';
20
+ import { numberProblem } from './compiler/check.mjs';
20
21
  /*----------------------------------------------------------------------------------------------------------------------
21
22
  - Constants
22
23
  ---------------------------------------------------------------------------------------------------------------------*/
@@ -37,14 +38,14 @@ const JUSTIFY = {
37
38
  'space-evenly': 'ER_JUSTIFY_SPACE_EVENLY',
38
39
  };
39
40
  const FLEX_DIRECTION = {
40
- column: 'ER_FLEX_COL',
41
+ column: 'ER_FLEX_COLUMN',
41
42
  row: 'ER_FLEX_ROW',
42
43
  'row-reverse': 'ER_FLEX_ROW_REVERSE',
43
- 'column-reverse': 'ER_FLEX_COL_REVERSE',
44
+ 'column-reverse': 'ER_FLEX_COLUMN_REVERSE',
44
45
  };
45
46
  const POSITION = {
46
- relative: 'ER_POS_RELATIVE',
47
- absolute: 'ER_POS_ABSOLUTE',
47
+ relative: 'ER_POSITION_RELATIVE',
48
+ absolute: 'ER_POSITION_ABSOLUTE',
48
49
  };
49
50
  const DISPLAY = { flex: 'ER_DISPLAY_FLEX', none: 'ER_DISPLAY_NONE' };
50
51
  /** Maps a JSX host tag to its ERNodeType enum, for the components the generic node emitter handles. */
@@ -57,7 +58,7 @@ export const NODE_TYPES = {
57
58
  ScrollView: 'ER_NODE_SCROLL_VIEW',
58
59
  };
59
60
  /** Numeric style keys that can be state-driven and the ERProps field each one writes. */
60
- const NUM_FIELDS = {
61
+ const NUMBER_FIELDS = {
61
62
  width: 'width',
62
63
  height: 'height',
63
64
  minWidth: 'min_width',
@@ -93,10 +94,11 @@ const NUM_FIELDS = {
93
94
  fontSize: 'font_size',
94
95
  lineHeight: 'line_height',
95
96
  letterSpacing: 'letter_spacing',
97
+ shadowOpacity: 'shadow_opacity',
96
98
  };
97
99
  /**
98
100
  * Enum style keys that can be state-driven: the value (a string literal or a ternary of them) lowers to the
99
- * matching ER_* constant via its table. Changing one in app_update re-runs layout (props_hash covers it).
101
+ * matching ER_* constant via its table. Changing one in an update re-runs layout (props_hash covers it).
100
102
  */
101
103
  const ENUM_FIELDS = {
102
104
  flexDirection: { field: 'flex_direction', table: FLEX_DIRECTION },
@@ -107,12 +109,12 @@ const ENUM_FIELDS = {
107
109
  display: { field: 'display', table: DISPLAY },
108
110
  };
109
111
  /**
110
- * Every style key whose value can be state-driven, with its ERProps field and how app_update() lowers it (see
111
- * DynamicStyleField). Keys absent here (such as the `flex` shorthand, `flexBasis`, the four insets and
112
- * `fontWeight`) can only be static.
112
+ * Every style key whose value can be state-driven, with its ERProps field and how an update lowers it (see
113
+ * DynamicStyleField). Keys absent here (such as the `flex` shorthand, `flexBasis`, the four insets,
114
+ * `fontWeight` and `shadowOffset`) can only be static.
113
115
  */
114
116
  export const DYN_FIELDS = {
115
- ...Object.fromEntries(Object.entries(NUM_FIELDS).map(([styleKey, field]) => [
117
+ ...Object.fromEntries(Object.entries(NUMBER_FIELDS).map(([styleKey, field]) => [
116
118
  styleKey,
117
119
  { field, kind: 'num' },
118
120
  ])),
@@ -123,8 +125,19 @@ export const DYN_FIELDS = {
123
125
  backgroundColor: { field: 'background_color', kind: 'color' },
124
126
  color: { field: 'color', kind: 'color' },
125
127
  borderColor: { field: 'border_color', kind: 'color' },
128
+ shadowColor: { field: 'shadow_color', kind: 'color' },
129
+ shadowRadius: { field: 'shadow_radius', kind: 'byte' },
130
+ elevation: { field: 'elevation', kind: 'byte' },
126
131
  opacity: { field: 'opacity', kind: 'opacity' },
127
132
  };
133
+ /** The engine's opacity for fully opaque, which a 0–1 opacity scales to. */
134
+ export const OPACITY_OPAQUE = 255;
135
+ /** The alpha of a color written without one. */
136
+ const ALPHA_OPAQUE = 0xff;
137
+ /** The largest value a byte field holds. */
138
+ const BYTE_MAX = 255;
139
+ /** The lightest numeric fontWeight drawn bold. */
140
+ const BOLD_WEIGHT = 600;
128
141
  /*----------------------------------------------------------------------------------------------------------------------
129
142
  - Implementation
130
143
  ---------------------------------------------------------------------------------------------------------------------*/
@@ -159,7 +172,7 @@ export function parseColorValue(color) {
159
172
  // Split out the channels; a 6-digit color is opaque.
160
173
  let red, green, blue, alpha;
161
174
  if (hex.length === 6) {
162
- alpha = 0xff;
175
+ alpha = ALPHA_OPAQUE;
163
176
  red = parseInt(hex.slice(0, 2), 16);
164
177
  green = parseInt(hex.slice(2, 4), 16);
165
178
  blue = parseInt(hex.slice(4, 6), 16);
@@ -174,14 +187,19 @@ export function parseColorValue(color) {
174
187
  return ((alpha << 24) | (red << 16) | (green << 8) | blue) >>> 0;
175
188
  }
176
189
  /**
177
- * Formats an ARGB int as a C unsigned hex literal, e.g. 0xFF0F172Au.
190
+ * A number for a float field, checked.
178
191
  *
179
- * @param color A color string (see parseColorValue).
192
+ * @param rawValue The value; anything `Number()` converts to a finite float.
180
193
  *
181
- * @returns Its C literal.
194
+ * @returns The number.
182
195
  */
183
- export function colorLiteral(color) {
184
- return `0x${parseColorValue(color).toString(16).toUpperCase().padStart(8, '0')}u`;
196
+ export function floatConstant(rawValue) {
197
+ // The check pass refuses what a float cannot hold; a value that reaches here unchecked fails the same way.
198
+ const problem = numberProblem(rawValue);
199
+ if (problem) {
200
+ throw problem;
201
+ }
202
+ return Number(rawValue);
185
203
  }
186
204
  /**
187
205
  * Looks an enum style value up in its table.
@@ -201,7 +219,7 @@ const enumKey = (table, name) => (value) => {
201
219
  return constant;
202
220
  };
203
221
  /**
204
- * A pixel dimension as C.
222
+ * A pixel dimension as a constant.
205
223
  *
206
224
  * @param value The style value; must be a finite number.
207
225
  *
@@ -211,19 +229,42 @@ const dimension = (value) => {
211
229
  if (typeof value !== 'number' || !Number.isFinite(value)) {
212
230
  throw new Error(`expected a numeric dimension, got ${JSON.stringify(value)}`);
213
231
  }
214
- return String(Math.round(value));
232
+ // Adding 0 turns -0 into 0, whose bits a float field keeps.
233
+ return Math.round(value) + 0;
215
234
  };
216
235
  /**
217
- * A dimension that may be a percentage. `'50%'` → the engine's float `*_pct` field (% of the parent);
236
+ * A whole number for a byte field.
237
+ *
238
+ * @param value The style value; must be a finite number.
239
+ *
240
+ * @returns It with its fraction dropped, clamped to 0–255, as Flow A reads one.
241
+ */
242
+ const byteValue = (value) => {
243
+ if (typeof value !== 'number' || !Number.isFinite(value)) {
244
+ throw new Error(`expected a number, got ${JSON.stringify(value)}`);
245
+ }
246
+ // Adding 0 turns -0 into 0.
247
+ return Math.min(BYTE_MAX, Math.max(0, Math.trunc(value))) + 0;
248
+ };
249
+ /**
250
+ * One side of a `shadowOffset`.
251
+ *
252
+ * @param offset `width` or `height`; left out, it is 0.
253
+ *
254
+ * @returns The offset in pixels.
255
+ */
256
+ const shadowOffsetSide = (offset) => offset === undefined || offset === null ? 0 : floatConstant(offset);
257
+ /**
258
+ * A dimension that may be a percentage. `'50%'` → the engine's float `*_percent` field (% of the parent);
218
259
  * a number → the pixel field. Used for width / height / flexBasis and the four insets, all of which the
219
260
  * engine resolves at layout.
220
261
  *
221
- * @param pxField ERProps pixel field (e.g. 'width').
222
- * @param pctField ERProps percentage field (e.g. 'width_pct').
262
+ * @param pixelField ERProps pixel field (e.g. 'width').
263
+ * @param percentField ERProps percentage field (e.g. 'width_percent').
223
264
  *
224
265
  * @returns The lowering for that key.
225
266
  */
226
- const pctOrPx = (pxField, pctField) => value => {
267
+ const percentOrPixels = (pixelField, percentField) => value => {
227
268
  if (typeof value === 'string' && value.trim().endsWith('%')) {
228
269
  const percent = parseFloat(value);
229
270
  if (!Number.isFinite(percent)) {
@@ -231,148 +272,168 @@ const pctOrPx = (pxField, pctField) => value => {
231
272
  }
232
273
  // The engine reads a 0.0 percentage as "not set", so lower 0% to the pixel field, where 0 means the same.
233
274
  if (percent === 0)
234
- return [{ field: pxField, expr: '0' }];
235
- // A valid C float literal needs a decimal point — `50f` is a syntax error, `50.0f` is not.
236
- const floatLiteral = Number.isInteger(percent)
237
- ? `${percent}.0f`
238
- : `${percent}f`;
239
- return [{ field: pctField, expr: floatLiteral }];
275
+ return [{ field: pixelField, value: 0 }];
276
+ return [{ field: percentField, value: percent }];
240
277
  }
241
- return [{ field: pxField, expr: dimension(value) }];
278
+ return [{ field: pixelField, value: dimension(value) }];
242
279
  };
243
280
  /**
244
- * Per-style-key lowering. Each entry maps a style value to one or more { field, expr } ERProps writes
245
- * (field = ERProps C member, expr = C source for the value). `flex` expands to several fields.
281
+ * Per-style-key lowering. Each entry maps a style value to one or more { field, value } ERProps writes
282
+ * (field = ERProps member, value = the constant). `flex` expands to several fields.
246
283
  */
247
284
  const KEYS = {
248
285
  // Layout
249
- width: pctOrPx('width', 'width_pct'),
250
- height: pctOrPx('height', 'height_pct'),
251
- flexBasis: pctOrPx('flex_basis', 'flex_basis_pct'),
252
- minWidth: width => [{ field: 'min_width', expr: dimension(width) }],
253
- maxWidth: width => [{ field: 'max_width', expr: dimension(width) }],
254
- minHeight: height => [{ field: 'min_height', expr: dimension(height) }],
255
- maxHeight: height => [{ field: 'max_height', expr: dimension(height) }],
256
- padding: padding => [{ field: 'padding', expr: dimension(padding) }],
286
+ width: percentOrPixels('width', 'width_percent'),
287
+ height: percentOrPixels('height', 'height_percent'),
288
+ flexBasis: percentOrPixels('flex_basis', 'flex_basis_percent'),
289
+ minWidth: width => [{ field: 'min_width', value: dimension(width) }],
290
+ maxWidth: width => [{ field: 'max_width', value: dimension(width) }],
291
+ minHeight: height => [{ field: 'min_height', value: dimension(height) }],
292
+ maxHeight: height => [{ field: 'max_height', value: dimension(height) }],
293
+ padding: padding => [{ field: 'padding', value: dimension(padding) }],
257
294
  paddingHorizontal: padding => [
258
- { field: 'padding_horizontal', expr: dimension(padding) },
295
+ { field: 'padding_horizontal', value: dimension(padding) },
259
296
  ],
260
297
  paddingVertical: padding => [
261
- { field: 'padding_vertical', expr: dimension(padding) },
298
+ { field: 'padding_vertical', value: dimension(padding) },
299
+ ],
300
+ paddingLeft: padding => [{ field: 'padding_left', value: dimension(padding) }],
301
+ paddingTop: padding => [{ field: 'padding_top', value: dimension(padding) }],
302
+ paddingRight: padding => [
303
+ { field: 'padding_right', value: dimension(padding) },
262
304
  ],
263
- paddingLeft: padding => [{ field: 'padding_left', expr: dimension(padding) }],
264
- paddingTop: padding => [{ field: 'padding_top', expr: dimension(padding) }],
265
- paddingRight: padding => [{ field: 'padding_right', expr: dimension(padding) }],
266
305
  paddingBottom: padding => [
267
- { field: 'padding_bottom', expr: dimension(padding) },
306
+ { field: 'padding_bottom', value: dimension(padding) },
268
307
  ],
269
- margin: margin => [{ field: 'margin', expr: dimension(margin) }],
308
+ margin: margin => [{ field: 'margin', value: dimension(margin) }],
270
309
  marginHorizontal: margin => [
271
- { field: 'margin_horizontal', expr: dimension(margin) },
310
+ { field: 'margin_horizontal', value: dimension(margin) },
272
311
  ],
273
312
  marginVertical: margin => [
274
- { field: 'margin_vertical', expr: dimension(margin) },
313
+ { field: 'margin_vertical', value: dimension(margin) },
275
314
  ],
276
- marginLeft: margin => [{ field: 'margin_left', expr: dimension(margin) }],
277
- marginTop: margin => [{ field: 'margin_top', expr: dimension(margin) }],
278
- marginRight: margin => [{ field: 'margin_right', expr: dimension(margin) }],
279
- marginBottom: margin => [{ field: 'margin_bottom', expr: dimension(margin) }],
280
- gap: gap => [{ field: 'gap', expr: dimension(gap) }],
281
- rowGap: gap => [{ field: 'row_gap', expr: dimension(gap) }],
282
- columnGap: gap => [{ field: 'column_gap', expr: dimension(gap) }],
283
- flexGrow: grow => [{ field: 'flex_grow', expr: dimension(grow) }],
284
- flexShrink: shrink => [{ field: 'flex_shrink', expr: dimension(shrink) }],
315
+ marginLeft: margin => [{ field: 'margin_left', value: dimension(margin) }],
316
+ marginTop: margin => [{ field: 'margin_top', value: dimension(margin) }],
317
+ marginRight: margin => [{ field: 'margin_right', value: dimension(margin) }],
318
+ marginBottom: margin => [{ field: 'margin_bottom', value: dimension(margin) }],
319
+ gap: gap => [{ field: 'gap', value: dimension(gap) }],
320
+ rowGap: gap => [{ field: 'row_gap', value: dimension(gap) }],
321
+ columnGap: gap => [{ field: 'column_gap', value: dimension(gap) }],
322
+ flexGrow: grow => [{ field: 'flex_grow', value: dimension(grow) }],
323
+ flexShrink: shrink => [{ field: 'flex_shrink', value: dimension(shrink) }],
285
324
  flexDirection: direction => [
286
325
  {
287
326
  field: 'flex_direction',
288
- expr: enumKey(FLEX_DIRECTION, 'flexDirection')(direction),
327
+ value: enumKey(FLEX_DIRECTION, 'flexDirection')(direction),
289
328
  },
290
329
  ],
291
330
  alignItems: alignment => [
292
- { field: 'align_items', expr: enumKey(ALIGN, 'alignItems')(alignment) },
331
+ { field: 'align_items', value: enumKey(ALIGN, 'alignItems')(alignment) },
293
332
  ],
294
333
  alignSelf: alignment => [
295
- { field: 'align_self', expr: enumKey(ALIGN, 'alignSelf')(alignment) },
334
+ { field: 'align_self', value: enumKey(ALIGN, 'alignSelf')(alignment) },
296
335
  ],
297
336
  justifyContent: justification => [
298
337
  {
299
338
  field: 'justify_content',
300
- expr: enumKey(JUSTIFY, 'justifyContent')(justification),
339
+ value: enumKey(JUSTIFY, 'justifyContent')(justification),
301
340
  },
302
341
  ],
303
342
  // Positioning: `position: 'absolute'` takes a node out of flow; left/top/right/bottom are its anchors.
304
343
  position: position => [
305
- { field: 'position', expr: enumKey(POSITION, 'position')(position) },
344
+ { field: 'position', value: enumKey(POSITION, 'position')(position) },
306
345
  ],
307
346
  display: display => [
308
- { field: 'display', expr: enumKey(DISPLAY, 'display')(display) },
347
+ { field: 'display', value: enumKey(DISPLAY, 'display')(display) },
309
348
  ],
310
- left: pctOrPx('left', 'left_pct'),
311
- top: pctOrPx('top', 'top_pct'),
312
- right: pctOrPx('right', 'right_pct'),
313
- bottom: pctOrPx('bottom', 'bottom_pct'),
349
+ left: percentOrPixels('left', 'left_percent'),
350
+ top: percentOrPixels('top', 'top_percent'),
351
+ right: percentOrPixels('right', 'right_percent'),
352
+ bottom: percentOrPixels('bottom', 'bottom_percent'),
314
353
  // `flex: n` → grow=n, shrink=1, basis=0 (RN semantics; matches native_ui_bridge apply_flex).
315
354
  flex: flexValue => {
316
355
  const factor = Number(flexValue);
317
356
  if (factor > 0) {
318
357
  return [
319
- { field: 'flex_grow', expr: dimension(factor) },
320
- { field: 'flex_shrink', expr: '1' },
321
- { field: 'flex_basis', expr: '0' },
358
+ { field: 'flex_grow', value: dimension(factor) },
359
+ { field: 'flex_shrink', value: 1 },
360
+ { field: 'flex_basis', value: 0 },
322
361
  ];
323
362
  }
324
363
  if (factor === 0) {
325
364
  return [
326
- { field: 'flex_grow', expr: '0' },
327
- { field: 'flex_shrink', expr: '0' },
365
+ { field: 'flex_grow', value: 0 },
366
+ { field: 'flex_shrink', value: 0 },
328
367
  ];
329
368
  }
330
369
  return [
331
- { field: 'flex_grow', expr: '0' },
332
- { field: 'flex_shrink', expr: '1' },
370
+ { field: 'flex_grow', value: 0 },
371
+ { field: 'flex_shrink', value: 1 },
333
372
  ];
334
373
  },
335
374
  // View visual
336
375
  backgroundColor: color => [
337
- { field: 'background_color', expr: colorLiteral(color) },
376
+ { field: 'background_color', value: parseColorValue(color) },
338
377
  ],
339
- borderRadius: radius => [{ field: 'border_radius', expr: dimension(radius) }],
378
+ borderRadius: radius => [{ field: 'border_radius', value: dimension(radius) }],
340
379
  // Per-corner radii; the engine reads 0 in one of these as "use borderRadius" (same as Flow A).
341
380
  borderTopLeftRadius: radius => [
342
- { field: 'border_top_left_radius', expr: dimension(radius) },
381
+ { field: 'border_top_left_radius', value: dimension(radius) },
343
382
  ],
344
383
  borderTopRightRadius: radius => [
345
- { field: 'border_top_right_radius', expr: dimension(radius) },
384
+ { field: 'border_top_right_radius', value: dimension(radius) },
346
385
  ],
347
386
  borderBottomRightRadius: radius => [
348
- { field: 'border_bottom_right_radius', expr: dimension(radius) },
387
+ { field: 'border_bottom_right_radius', value: dimension(radius) },
349
388
  ],
350
389
  borderBottomLeftRadius: radius => [
351
- { field: 'border_bottom_left_radius', expr: dimension(radius) },
390
+ { field: 'border_bottom_left_radius', value: dimension(radius) },
391
+ ],
392
+ borderWidth: width => [{ field: 'border_width', value: dimension(width) }],
393
+ borderColor: color => [
394
+ { field: 'border_color', value: parseColorValue(color) },
352
395
  ],
353
- borderWidth: width => [{ field: 'border_width', expr: dimension(width) }],
354
- borderColor: color => [{ field: 'border_color', expr: colorLiteral(color) }],
355
396
  opacity: opacity => [
356
397
  {
357
398
  field: 'opacity',
358
- expr: String(Math.round(Math.max(0, Math.min(1, Number(opacity))) * 255)),
399
+ value: Math.round(Math.max(0, Math.min(1, Number(opacity))) * OPACITY_OPAQUE),
359
400
  },
360
401
  ],
361
- zIndex: zIndex => [{ field: 'z_index', expr: dimension(zIndex) }],
402
+ zIndex: zIndex => [{ field: 'z_index', value: dimension(zIndex) }],
403
+ // Shadow, drawn only by a firmware built with ERUI_SHADOWS (same as Flow A).
404
+ shadowColor: color => [
405
+ { field: 'shadow_color', value: parseColorValue(color) },
406
+ ],
407
+ // Both sides are written, so a later shadowOffset replaces an earlier one whole, as in RN.
408
+ shadowOffset: offset => {
409
+ if (typeof offset !== 'object' || Array.isArray(offset)) {
410
+ throw new Error(`expected {width, height}, got ${JSON.stringify(offset)}`);
411
+ }
412
+ const { width, height } = offset;
413
+ return [
414
+ { field: 'shadow_offset_x', value: shadowOffsetSide(width) },
415
+ { field: 'shadow_offset_y', value: shadowOffsetSide(height) },
416
+ ];
417
+ },
418
+ shadowOpacity: opacity => [
419
+ { field: 'shadow_opacity', value: floatConstant(opacity) },
420
+ ],
421
+ shadowRadius: radius => [{ field: 'shadow_radius', value: byteValue(radius) }],
422
+ elevation: elevation => [{ field: 'elevation', value: byteValue(elevation) }],
362
423
  // Text
363
- color: color => [{ field: 'color', expr: colorLiteral(color) }],
364
- fontSize: size => [{ field: 'font_size', expr: dimension(size) }],
424
+ color: color => [{ field: 'color', value: parseColorValue(color) }],
425
+ fontSize: size => [{ field: 'font_size', value: dimension(size) }],
365
426
  fontWeight: weight => [
366
427
  {
367
428
  field: 'font_weight',
368
- expr: weight === 'bold' || Number(weight) >= 600 ? '1' : '0',
429
+ value: weight === 'bold' || Number(weight) >= BOLD_WEIGHT ? 1 : 0,
369
430
  },
370
431
  ],
371
432
  lineHeight: lineHeight => [
372
- { field: 'line_height', expr: dimension(lineHeight) },
433
+ { field: 'line_height', value: dimension(lineHeight) },
373
434
  ],
374
435
  letterSpacing: spacing => [
375
- { field: 'letter_spacing', expr: dimension(spacing) },
436
+ { field: 'letter_spacing', value: dimension(spacing) },
376
437
  ],
377
438
  };
378
439
  /**
@@ -387,9 +448,8 @@ export const isStyleKey = (key) => Object.hasOwn(KEYS, key);
387
448
  export const STYLE_KEYS = Object.keys(KEYS);
388
449
  /**
389
450
  * Lowers one flattened style object to a list of ERProps field assignments. This is the build-time mirror
390
- * of what native_ui_bridge.c does at runtime in Flow A: the generated C (e.g.
391
- * `p.background_color = 0xFF0F172Au;`) builds the same prop bags as Flow A, from the same defaults
392
- * (er_props_default), so both render the same pixels. An unsupported key throws, so the compiler fails
451
+ * of what native_ui_bridge.c does at runtime in Flow A: the package builds the same prop bags as Flow A,
452
+ * from the same defaults (er_props_default), so both render the same pixels. An unsupported key throws, so the compiler fails
393
453
  * loudly instead of silently dropping a style.
394
454
  *
395
455
  * @param style Flattened style (plain key→value; values already statically resolved).