embedded-react 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/README.md +7 -3
  2. package/aot/compile.mjs +178 -58
  3. package/aot/compiler/animations.mjs +290 -281
  4. package/aot/compiler/boot.mjs +70 -33
  5. package/aot/compiler/branch-merge.mjs +4 -3
  6. package/aot/compiler/check.mjs +9 -9
  7. package/aot/compiler/collect.mjs +324 -205
  8. package/aot/compiler/control-flow.mjs +209 -197
  9. package/aot/compiler/diagnostics.mjs +22 -25
  10. package/aot/compiler/elements/activity-indicator.mjs +25 -24
  11. package/aot/compiler/elements/dial.mjs +91 -77
  12. package/aot/compiler/elements/flat-list.mjs +24 -22
  13. package/aot/compiler/elements/image.mjs +51 -50
  14. package/aot/compiler/elements/modal.mjs +31 -30
  15. package/aot/compiler/elements/props.mjs +23 -23
  16. package/aot/compiler/elements/switch.mjs +42 -34
  17. package/aot/compiler/elements/text-input.mjs +34 -32
  18. package/aot/compiler/expressions.mjs +372 -333
  19. package/aot/compiler/handlers.mjs +473 -387
  20. package/aot/compiler/ir/functions.mjs +11 -1
  21. package/aot/compiler/ir/nodes.mjs +4 -4
  22. package/aot/compiler/ir/reads.mjs +19 -19
  23. package/aot/compiler/ir/types.mjs +14 -14
  24. package/aot/compiler/ir/vectors.mjs +5 -1
  25. package/aot/compiler/keyboard.mjs +17 -7
  26. package/aot/compiler/lower.mjs +77 -80
  27. package/aot/compiler/nodes.mjs +169 -152
  28. package/aot/compiler/options.mjs +35 -30
  29. package/aot/compiler/out.mjs +18 -22
  30. package/aot/compiler/package/animations.mjs +669 -0
  31. package/aot/compiler/package/arena.mjs +252 -0
  32. package/aot/compiler/package/assemble.mjs +177 -0
  33. package/aot/compiler/package/bytecode.mjs +286 -0
  34. package/aot/compiler/package/checks.mjs +1022 -0
  35. package/aot/compiler/package/codegen.mjs +1329 -0
  36. package/aot/compiler/package/enums.mjs +138 -0
  37. package/aot/compiler/package/format.mjs +760 -0
  38. package/aot/compiler/package/layouts.mjs +136 -0
  39. package/aot/compiler/package/lower.mjs +1606 -0
  40. package/aot/compiler/package/props.mjs +118 -0
  41. package/aot/compiler/package/tables.mjs +103 -0
  42. package/aot/compiler/package/vectors.mjs +502 -0
  43. package/aot/compiler/package/writer.mjs +664 -0
  44. package/aot/compiler/pan-responder.mjs +69 -61
  45. package/aot/compiler/parse.mjs +21 -21
  46. package/aot/compiler/static-eval.mjs +25 -23
  47. package/aot/compiler/style-text.mjs +161 -172
  48. package/aot/compiler/svg.mjs +477 -251
  49. package/aot/screenshot-smoke.mjs +54 -40
  50. package/aot/style-map.mjs +102 -90
  51. package/assets/bake-font.mjs +123 -77
  52. package/assets/bake-image.mjs +39 -22
  53. package/assets/bake-svg.mjs +361 -262
  54. package/assets/build-builtin-font.mjs +11 -7
  55. package/assets/emit-c.mjs +77 -58
  56. package/assets/emit-container.mjs +123 -37
  57. package/assets/emit-pack.mjs +77 -67
  58. package/assets/font-config.mjs +9 -6
  59. package/assets/font-sizes.mjs +163 -123
  60. package/assets/glyph-coverage.mjs +74 -54
  61. package/assets/index.mjs +31 -9
  62. package/assets/rasterize.mjs +126 -99
  63. package/assets/svg-loader.mjs +8 -8
  64. package/build.mjs +14 -12
  65. package/cli.mjs +359 -172
  66. package/compile-bin.mjs +3 -3
  67. package/flash.mjs +537 -0
  68. package/hotreload/dev-device.mjs +90 -33
  69. package/hotreload/pack-app.mjs +55 -43
  70. package/hotreload/pack-split.mjs +46 -37
  71. package/hotreload/package-transfer.mjs +175 -0
  72. package/hotreload/protocol.mjs +50 -37
  73. package/hotreload/uploader.mjs +38 -27
  74. package/hotreload/watch-tree.mjs +19 -19
  75. package/pack-container.mjs +28 -20
  76. package/package.json +7 -8
  77. package/persist-transform.mjs +34 -28
  78. package/qjsc-wasm.mjs +25 -14
  79. package/sim/embedded-react.cjs +1 -1
  80. package/sim/embedded-react.js +1 -1
  81. package/sim/embedded-react.wasm +0 -0
  82. package/sim/index.html +94 -85
  83. package/sim-server.mjs +101 -82
  84. package/src/embedded-react/Animated.js +24 -24
  85. package/src/embedded-react/Easing.js +1 -1
  86. package/src/embedded-react/FlatList.js +3 -3
  87. package/src/embedded-react/LayoutAnimation.js +8 -5
  88. package/src/embedded-react/PanResponder.js +75 -71
  89. package/src/embedded-react/Pressable.js +2 -8
  90. package/src/embedded-react/SectionList.js +6 -6
  91. package/src/embedded-react/StyleSheet.js +4 -3
  92. package/src/embedded-react/TouchableOpacity.js +13 -8
  93. package/src/embedded-react/index.d.ts +5 -5
  94. package/src/embedded-react/layout-anim-config.js +10 -4
  95. package/src/embedded-react/list-child.js +5 -5
  96. package/src/embedded-react/named-colors.js +1 -1
  97. package/src/embedded-react/split-style.js +11 -11
  98. package/src/embedded-react/svg-ops.js +760 -593
  99. package/src/embedded-react/useHostValue.js +3 -3
  100. package/src/embedded-react/usePersistentState.js +6 -6
  101. package/src/embedded-react/warn-props.js +1 -1
  102. package/src/host-config.js +60 -53
  103. package/src/props.js +49 -41
  104. package/src/renderer.js +7 -4
  105. package/aot/compiler/assemble.mjs +0 -944
  106. package/aot/compiler/c/animations.mjs +0 -436
  107. package/aot/compiler/c/boot.mjs +0 -127
  108. package/aot/compiler/c/expressions.mjs +0 -270
  109. package/aot/compiler/c/functions.mjs +0 -268
  110. package/aot/compiler/c/keyboard.mjs +0 -96
  111. package/aot/compiler/c/nodes.mjs +0 -303
  112. package/aot/compiler/c/pan-responder.mjs +0 -136
  113. package/aot/compiler/c/statements.mjs +0 -319
  114. package/aot/compiler/c/text.mjs +0 -83
  115. package/aot/compiler/c/vectors.mjs +0 -381
  116. package/aot/compiler/c-syntax.mjs +0 -127
@@ -17,11 +17,11 @@
17
17
  /*
18
18
  * `npm run aot:smoke` — automated compile-and-screenshot smoke test for the Flow B (AOT) demos.
19
19
  *
20
- * For each demo it: (1) compiles App.jsx → dist/app.gen.{c,h} (`node aot/compile.mts`), (2) rebuilds the
21
- * linux-aot SDL host (which links the generated C), (3) runs it headless via ER_AOT_SHOT to render ONE
22
- * frame to a BMP, and (4) checks the image actually has content (distinct colors above a floor) — i.e., it
23
- * compiled, linked, and rendered something rather than crashing or drawing a blank screen. Exits non-zero
24
- * if any demo fails, so it can gate CI.
20
+ * It builds the linux-aot SDL host (which loads a package), then for each demo: (1) compiles App.jsx →
21
+ * dist/app.erpkg (`node aot/compile.mts`), (2) runs the host headless via ER_AOT_SHOT to render ONE frame to
22
+ * a BMP, and (3) checks the image actually has content (distinct colors above a floor) — i.e., it compiled,
23
+ * loaded, and rendered something rather than crashing or drawing a blank screen. Exits non-zero if any demo
24
+ * fails, so it can gate CI.
25
25
  *
26
26
  * Prereq: the linux-aot CMake build must be configurable (SDL2 found). It reuses examples/linux-aot/build;
27
27
  * if that isn't configured yet, set CMAKE_TOOLCHAIN_FILE (e.g. a vcpkg toolchain) and it will configure it.
@@ -32,22 +32,29 @@ import {existsSync, mkdirSync, readFileSync, rmSync} from 'node:fs';
32
32
  import {resolve, dirname} from 'node:path';
33
33
  import {fileURLToPath} from 'node:url';
34
34
 
35
+ // Where a BMP's header keeps what the check reads, and the 'BM' it starts with.
36
+ const BMP_MAGIC = [0x42, 0x4d];
37
+ const BMP_PIXEL_OFFSET_AT = 10;
38
+ const BMP_WIDTH_AT = 18;
39
+ const BMP_HEIGHT_AT = 22;
40
+ const BMP_BITS_PER_PIXEL_AT = 28;
41
+
35
42
  const here = dirname(fileURLToPath(import.meta.url)); // packages/embedded-react/aot
36
- const jsDir = resolve(here, '..'); // packages/embedded-react
37
- const repoRoot = resolve(here, '../../..');
38
- const exampleDir = resolve(repoRoot, 'examples/linux-aot');
39
- const buildDir = resolve(exampleDir, 'build');
40
- const exe = resolve(
41
- buildDir,
43
+ const packageDirectory = resolve(here, '..'); // packages/embedded-react
44
+ const repositoryRoot = resolve(here, '../../..');
45
+ const exampleDirectory = resolve(repositoryRoot, 'examples/linux-aot');
46
+ const buildDirectory = resolve(exampleDirectory, 'build');
47
+ const executable = resolve(
48
+ buildDirectory,
42
49
  process.platform === 'win32'
43
50
  ? 'embedded-react-desktop-aot.exe'
44
51
  : 'embedded-react-desktop-aot',
45
52
  );
46
- const tmpDir = resolve(jsDir, 'dist', '.smoke');
53
+ const temporaryDirectory = resolve(packageDirectory, 'dist', '.smoke');
47
54
 
48
55
  /**
49
- * The demos to smoke-test. `screen` sets ER_AOT_SCREEN_W/H so the responsive thermostat folds to its `solo`
50
- * (AOT-compilable) branch; `minColors` is the floor of distinct sampled colors that counts as "rendered".
56
+ * The demos to smoke-test. `screen` sets ER_AOT_SCREEN_W/H, the panel the package is for and the window's size;
57
+ * `minColors` is the floor of distinct sampled colors that counts as "rendered".
51
58
  */
52
59
  const DEMOS = [
53
60
  {name: 'watch-face', screen: {w: 240, h: 280}, minColors: 40},
@@ -64,14 +71,14 @@ const DEMOS = [
64
71
  * @returns The number of distinct colors sampled.
65
72
  */
66
73
  function bmpDistinctColors(path, step = 4) {
67
- const bmp = readFileSync(path);
68
- if (bmp[0] !== 0x42 || bmp[1] !== 0x4d) {
74
+ const bitmap = readFileSync(path);
75
+ if (bitmap[0] !== BMP_MAGIC[0] || bitmap[1] !== BMP_MAGIC[1]) {
69
76
  throw new Error(`not a BMP: ${path}`);
70
77
  }
71
- const pixelOffset = bmp.readUInt32LE(10);
72
- const width = bmp.readInt32LE(18);
73
- const height = Math.abs(bmp.readInt32LE(22));
74
- const bitsPerPixel = bmp.readUInt16LE(28);
78
+ const pixelOffset = bitmap.readUInt32LE(BMP_PIXEL_OFFSET_AT);
79
+ const width = bitmap.readInt32LE(BMP_WIDTH_AT);
80
+ const height = Math.abs(bitmap.readInt32LE(BMP_HEIGHT_AT));
81
+ const bitsPerPixel = bitmap.readUInt16LE(BMP_BITS_PER_PIXEL_AT);
75
82
  if (bitsPerPixel !== 24 && bitsPerPixel !== 32) {
76
83
  throw new Error(`unexpected BMP bpp ${bitsPerPixel}`);
77
84
  }
@@ -81,54 +88,60 @@ function bmpDistinctColors(path, step = 4) {
81
88
  for (let y = 0; y < height; y += step) {
82
89
  for (let x = 0; x < width; x += step) {
83
90
  const index = pixelOffset + y * rowSize + x * bytesPerPixel;
84
- colors.add((bmp[index] << 16) | (bmp[index + 1] << 8) | bmp[index + 2]); // BGR triplet
91
+ colors.add(
92
+ (bitmap[index] << 16) | (bitmap[index + 1] << 8) | bitmap[index + 2],
93
+ ); // BGR triplet
85
94
  }
86
95
  }
87
96
  return colors.size;
88
97
  }
89
98
 
90
- function run(command, args, options = {}) {
91
- execFileSync(command, args, {stdio: 'pipe', ...options});
99
+ function run(command, commandArguments, options = {}) {
100
+ execFileSync(command, commandArguments, {stdio: 'pipe', ...options});
92
101
  }
93
102
 
94
103
  /** Configures the linux-aot CMake build on the first run. */
95
104
  function ensureConfigured() {
96
- if (existsSync(resolve(buildDir, 'CMakeCache.txt'))) return;
105
+ if (existsSync(resolve(buildDirectory, 'CMakeCache.txt'))) return;
97
106
  console.log('• configuring linux-aot build (first run)…');
98
- const args = ['-S', exampleDir, '-B', buildDir];
107
+ const cmakeArguments = ['-S', exampleDirectory, '-B', buildDirectory];
99
108
  if (process.env.CMAKE_TOOLCHAIN_FILE) {
100
- args.push(`-DCMAKE_TOOLCHAIN_FILE=${process.env.CMAKE_TOOLCHAIN_FILE}`);
109
+ cmakeArguments.push(
110
+ `-DCMAKE_TOOLCHAIN_FILE=${process.env.CMAKE_TOOLCHAIN_FILE}`,
111
+ );
101
112
  }
102
113
  if (process.platform === 'win32') {
103
- args.push('-G', 'MinGW Makefiles');
114
+ cmakeArguments.push('-G', 'MinGW Makefiles');
104
115
  }
105
- run('cmake', args);
116
+ run('cmake', cmakeArguments);
106
117
  }
107
118
 
108
119
  /**
109
- * Compiles one demo, relinks the host, renders one frame and checks the frame has content. A step that cannot
110
- * run (the compiler, the build or the host) throws.
120
+ * Compiles one demo, renders one frame and checks the frame has content. A step that cannot run (the compiler or
121
+ * the host) throws.
111
122
  *
112
123
  * @param demo The demo, from DEMOS.
113
124
  *
114
125
  * @returns Why the demo failed, or null when it rendered.
115
126
  */
116
127
  function smokeTest(demo) {
117
- const shot = resolve(tmpDir, `${demo.name}.bmp`);
128
+ const shot = resolve(temporaryDirectory, `${demo.name}.bmp`);
118
129
  rmSync(shot, {force: true});
119
130
 
120
- // Compile with the demo's screen size, relink the host, then render one frame to the BMP.
121
- const compileEnv = {...process.env};
131
+ // Compile at the demo's screen size, then render one frame to the BMP in a window of that size.
132
+ const screenEnvironment = {...process.env};
122
133
  if (demo.screen) {
123
- compileEnv.ER_AOT_SCREEN_W = String(demo.screen.w);
124
- compileEnv.ER_AOT_SCREEN_H = String(demo.screen.h);
134
+ screenEnvironment.ER_AOT_SCREEN_W = String(demo.screen.w);
135
+ screenEnvironment.ER_AOT_SCREEN_H = String(demo.screen.h);
125
136
  }
126
137
  run('node', [resolve(here, 'compile.mts'), demo.name], {
127
- cwd: jsDir,
128
- env: compileEnv,
138
+ cwd: packageDirectory,
139
+ env: screenEnvironment,
140
+ });
141
+ run(executable, [resolve(packageDirectory, 'dist/app.erpkg')], {
142
+ cwd: buildDirectory,
143
+ env: {...screenEnvironment, ER_NO_HIDPI: '1', ER_AOT_SHOT: shot},
129
144
  });
130
- run('cmake', ['--build', buildDir]);
131
- run(exe, [], {cwd: buildDir, env: {...process.env, ER_AOT_SHOT: shot}});
132
145
 
133
146
  // The frame must exist and show more than a blank screen.
134
147
  if (!existsSync(shot)) {
@@ -143,8 +156,9 @@ function smokeTest(demo) {
143
156
  }
144
157
 
145
158
  let failures = 0;
146
- mkdirSync(tmpDir, {recursive: true});
159
+ mkdirSync(temporaryDirectory, {recursive: true});
147
160
  ensureConfigured();
161
+ run('cmake', ['--build', buildDirectory]);
148
162
 
149
163
  for (const demo of DEMOS) {
150
164
  let failure;
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',
@@ -96,7 +97,7 @@ const NUM_FIELDS = {
96
97
  };
97
98
  /**
98
99
  * 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).
100
+ * matching ER_* constant via its table. Changing one in an update re-runs layout (props_hash covers it).
100
101
  */
101
102
  const ENUM_FIELDS = {
102
103
  flexDirection: { field: 'flex_direction', table: FLEX_DIRECTION },
@@ -107,12 +108,12 @@ const ENUM_FIELDS = {
107
108
  display: { field: 'display', table: DISPLAY },
108
109
  };
109
110
  /**
110
- * Every style key whose value can be state-driven, with its ERProps field and how app_update() lowers it (see
111
+ * Every style key whose value can be state-driven, with its ERProps field and how an update lowers it (see
111
112
  * DynamicStyleField). Keys absent here (such as the `flex` shorthand, `flexBasis`, the four insets and
112
113
  * `fontWeight`) can only be static.
113
114
  */
114
115
  export const DYN_FIELDS = {
115
- ...Object.fromEntries(Object.entries(NUM_FIELDS).map(([styleKey, field]) => [
116
+ ...Object.fromEntries(Object.entries(NUMBER_FIELDS).map(([styleKey, field]) => [
116
117
  styleKey,
117
118
  { field, kind: 'num' },
118
119
  ])),
@@ -125,6 +126,12 @@ export const DYN_FIELDS = {
125
126
  borderColor: { field: 'border_color', kind: 'color' },
126
127
  opacity: { field: 'opacity', kind: 'opacity' },
127
128
  };
129
+ /** The engine's opacity for fully opaque, which a 0–1 opacity scales to. */
130
+ export const OPACITY_OPAQUE = 255;
131
+ /** The alpha of a color written without one. */
132
+ const ALPHA_OPAQUE = 0xff;
133
+ /** The lightest numeric fontWeight drawn bold. */
134
+ const BOLD_WEIGHT = 600;
128
135
  /*----------------------------------------------------------------------------------------------------------------------
129
136
  - Implementation
130
137
  ---------------------------------------------------------------------------------------------------------------------*/
@@ -159,7 +166,7 @@ export function parseColorValue(color) {
159
166
  // Split out the channels; a 6-digit color is opaque.
160
167
  let red, green, blue, alpha;
161
168
  if (hex.length === 6) {
162
- alpha = 0xff;
169
+ alpha = ALPHA_OPAQUE;
163
170
  red = parseInt(hex.slice(0, 2), 16);
164
171
  green = parseInt(hex.slice(2, 4), 16);
165
172
  blue = parseInt(hex.slice(4, 6), 16);
@@ -174,14 +181,19 @@ export function parseColorValue(color) {
174
181
  return ((alpha << 24) | (red << 16) | (green << 8) | blue) >>> 0;
175
182
  }
176
183
  /**
177
- * Formats an ARGB int as a C unsigned hex literal, e.g. 0xFF0F172Au.
184
+ * A number for a float field, checked.
178
185
  *
179
- * @param color A color string (see parseColorValue).
186
+ * @param rawValue The value; anything `Number()` converts to a finite float.
180
187
  *
181
- * @returns Its C literal.
188
+ * @returns The number.
182
189
  */
183
- export function colorLiteral(color) {
184
- return `0x${parseColorValue(color).toString(16).toUpperCase().padStart(8, '0')}u`;
190
+ export function floatConstant(rawValue) {
191
+ // The check pass refuses what a float cannot hold; a value that reaches here unchecked fails the same way.
192
+ const problem = numberProblem(rawValue);
193
+ if (problem) {
194
+ throw problem;
195
+ }
196
+ return Number(rawValue);
185
197
  }
186
198
  /**
187
199
  * Looks an enum style value up in its table.
@@ -201,7 +213,7 @@ const enumKey = (table, name) => (value) => {
201
213
  return constant;
202
214
  };
203
215
  /**
204
- * A pixel dimension as C.
216
+ * A pixel dimension as a constant.
205
217
  *
206
218
  * @param value The style value; must be a finite number.
207
219
  *
@@ -211,19 +223,20 @@ const dimension = (value) => {
211
223
  if (typeof value !== 'number' || !Number.isFinite(value)) {
212
224
  throw new Error(`expected a numeric dimension, got ${JSON.stringify(value)}`);
213
225
  }
214
- return String(Math.round(value));
226
+ // Adding 0 turns -0 into 0, whose bits a float field keeps.
227
+ return Math.round(value) + 0;
215
228
  };
216
229
  /**
217
- * A dimension that may be a percentage. `'50%'` → the engine's float `*_pct` field (% of the parent);
230
+ * A dimension that may be a percentage. `'50%'` → the engine's float `*_percent` field (% of the parent);
218
231
  * a number → the pixel field. Used for width / height / flexBasis and the four insets, all of which the
219
232
  * engine resolves at layout.
220
233
  *
221
- * @param pxField ERProps pixel field (e.g. 'width').
222
- * @param pctField ERProps percentage field (e.g. 'width_pct').
234
+ * @param pixelField ERProps pixel field (e.g. 'width').
235
+ * @param percentField ERProps percentage field (e.g. 'width_percent').
223
236
  *
224
237
  * @returns The lowering for that key.
225
238
  */
226
- const pctOrPx = (pxField, pctField) => value => {
239
+ const percentOrPixels = (pixelField, percentField) => value => {
227
240
  if (typeof value === 'string' && value.trim().endsWith('%')) {
228
241
  const percent = parseFloat(value);
229
242
  if (!Number.isFinite(percent)) {
@@ -231,148 +244,148 @@ const pctOrPx = (pxField, pctField) => value => {
231
244
  }
232
245
  // The engine reads a 0.0 percentage as "not set", so lower 0% to the pixel field, where 0 means the same.
233
246
  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 }];
247
+ return [{ field: pixelField, value: 0 }];
248
+ return [{ field: percentField, value: percent }];
240
249
  }
241
- return [{ field: pxField, expr: dimension(value) }];
250
+ return [{ field: pixelField, value: dimension(value) }];
242
251
  };
243
252
  /**
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.
253
+ * Per-style-key lowering. Each entry maps a style value to one or more { field, value } ERProps writes
254
+ * (field = ERProps member, value = the constant). `flex` expands to several fields.
246
255
  */
247
256
  const KEYS = {
248
257
  // 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) }],
258
+ width: percentOrPixels('width', 'width_percent'),
259
+ height: percentOrPixels('height', 'height_percent'),
260
+ flexBasis: percentOrPixels('flex_basis', 'flex_basis_percent'),
261
+ minWidth: width => [{ field: 'min_width', value: dimension(width) }],
262
+ maxWidth: width => [{ field: 'max_width', value: dimension(width) }],
263
+ minHeight: height => [{ field: 'min_height', value: dimension(height) }],
264
+ maxHeight: height => [{ field: 'max_height', value: dimension(height) }],
265
+ padding: padding => [{ field: 'padding', value: dimension(padding) }],
257
266
  paddingHorizontal: padding => [
258
- { field: 'padding_horizontal', expr: dimension(padding) },
267
+ { field: 'padding_horizontal', value: dimension(padding) },
259
268
  ],
260
269
  paddingVertical: padding => [
261
- { field: 'padding_vertical', expr: dimension(padding) },
270
+ { field: 'padding_vertical', value: dimension(padding) },
271
+ ],
272
+ paddingLeft: padding => [{ field: 'padding_left', value: dimension(padding) }],
273
+ paddingTop: padding => [{ field: 'padding_top', value: dimension(padding) }],
274
+ paddingRight: padding => [
275
+ { field: 'padding_right', value: dimension(padding) },
262
276
  ],
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
277
  paddingBottom: padding => [
267
- { field: 'padding_bottom', expr: dimension(padding) },
278
+ { field: 'padding_bottom', value: dimension(padding) },
268
279
  ],
269
- margin: margin => [{ field: 'margin', expr: dimension(margin) }],
280
+ margin: margin => [{ field: 'margin', value: dimension(margin) }],
270
281
  marginHorizontal: margin => [
271
- { field: 'margin_horizontal', expr: dimension(margin) },
282
+ { field: 'margin_horizontal', value: dimension(margin) },
272
283
  ],
273
284
  marginVertical: margin => [
274
- { field: 'margin_vertical', expr: dimension(margin) },
285
+ { field: 'margin_vertical', value: dimension(margin) },
275
286
  ],
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) }],
287
+ marginLeft: margin => [{ field: 'margin_left', value: dimension(margin) }],
288
+ marginTop: margin => [{ field: 'margin_top', value: dimension(margin) }],
289
+ marginRight: margin => [{ field: 'margin_right', value: dimension(margin) }],
290
+ marginBottom: margin => [{ field: 'margin_bottom', value: dimension(margin) }],
291
+ gap: gap => [{ field: 'gap', value: dimension(gap) }],
292
+ rowGap: gap => [{ field: 'row_gap', value: dimension(gap) }],
293
+ columnGap: gap => [{ field: 'column_gap', value: dimension(gap) }],
294
+ flexGrow: grow => [{ field: 'flex_grow', value: dimension(grow) }],
295
+ flexShrink: shrink => [{ field: 'flex_shrink', value: dimension(shrink) }],
285
296
  flexDirection: direction => [
286
297
  {
287
298
  field: 'flex_direction',
288
- expr: enumKey(FLEX_DIRECTION, 'flexDirection')(direction),
299
+ value: enumKey(FLEX_DIRECTION, 'flexDirection')(direction),
289
300
  },
290
301
  ],
291
302
  alignItems: alignment => [
292
- { field: 'align_items', expr: enumKey(ALIGN, 'alignItems')(alignment) },
303
+ { field: 'align_items', value: enumKey(ALIGN, 'alignItems')(alignment) },
293
304
  ],
294
305
  alignSelf: alignment => [
295
- { field: 'align_self', expr: enumKey(ALIGN, 'alignSelf')(alignment) },
306
+ { field: 'align_self', value: enumKey(ALIGN, 'alignSelf')(alignment) },
296
307
  ],
297
308
  justifyContent: justification => [
298
309
  {
299
310
  field: 'justify_content',
300
- expr: enumKey(JUSTIFY, 'justifyContent')(justification),
311
+ value: enumKey(JUSTIFY, 'justifyContent')(justification),
301
312
  },
302
313
  ],
303
314
  // Positioning: `position: 'absolute'` takes a node out of flow; left/top/right/bottom are its anchors.
304
315
  position: position => [
305
- { field: 'position', expr: enumKey(POSITION, 'position')(position) },
316
+ { field: 'position', value: enumKey(POSITION, 'position')(position) },
306
317
  ],
307
318
  display: display => [
308
- { field: 'display', expr: enumKey(DISPLAY, 'display')(display) },
319
+ { field: 'display', value: enumKey(DISPLAY, 'display')(display) },
309
320
  ],
310
- left: pctOrPx('left', 'left_pct'),
311
- top: pctOrPx('top', 'top_pct'),
312
- right: pctOrPx('right', 'right_pct'),
313
- bottom: pctOrPx('bottom', 'bottom_pct'),
321
+ left: percentOrPixels('left', 'left_percent'),
322
+ top: percentOrPixels('top', 'top_percent'),
323
+ right: percentOrPixels('right', 'right_percent'),
324
+ bottom: percentOrPixels('bottom', 'bottom_percent'),
314
325
  // `flex: n` → grow=n, shrink=1, basis=0 (RN semantics; matches native_ui_bridge apply_flex).
315
326
  flex: flexValue => {
316
327
  const factor = Number(flexValue);
317
328
  if (factor > 0) {
318
329
  return [
319
- { field: 'flex_grow', expr: dimension(factor) },
320
- { field: 'flex_shrink', expr: '1' },
321
- { field: 'flex_basis', expr: '0' },
330
+ { field: 'flex_grow', value: dimension(factor) },
331
+ { field: 'flex_shrink', value: 1 },
332
+ { field: 'flex_basis', value: 0 },
322
333
  ];
323
334
  }
324
335
  if (factor === 0) {
325
336
  return [
326
- { field: 'flex_grow', expr: '0' },
327
- { field: 'flex_shrink', expr: '0' },
337
+ { field: 'flex_grow', value: 0 },
338
+ { field: 'flex_shrink', value: 0 },
328
339
  ];
329
340
  }
330
341
  return [
331
- { field: 'flex_grow', expr: '0' },
332
- { field: 'flex_shrink', expr: '1' },
342
+ { field: 'flex_grow', value: 0 },
343
+ { field: 'flex_shrink', value: 1 },
333
344
  ];
334
345
  },
335
346
  // View visual
336
347
  backgroundColor: color => [
337
- { field: 'background_color', expr: colorLiteral(color) },
348
+ { field: 'background_color', value: parseColorValue(color) },
338
349
  ],
339
- borderRadius: radius => [{ field: 'border_radius', expr: dimension(radius) }],
350
+ borderRadius: radius => [{ field: 'border_radius', value: dimension(radius) }],
340
351
  // Per-corner radii; the engine reads 0 in one of these as "use borderRadius" (same as Flow A).
341
352
  borderTopLeftRadius: radius => [
342
- { field: 'border_top_left_radius', expr: dimension(radius) },
353
+ { field: 'border_top_left_radius', value: dimension(radius) },
343
354
  ],
344
355
  borderTopRightRadius: radius => [
345
- { field: 'border_top_right_radius', expr: dimension(radius) },
356
+ { field: 'border_top_right_radius', value: dimension(radius) },
346
357
  ],
347
358
  borderBottomRightRadius: radius => [
348
- { field: 'border_bottom_right_radius', expr: dimension(radius) },
359
+ { field: 'border_bottom_right_radius', value: dimension(radius) },
349
360
  ],
350
361
  borderBottomLeftRadius: radius => [
351
- { field: 'border_bottom_left_radius', expr: dimension(radius) },
362
+ { field: 'border_bottom_left_radius', value: dimension(radius) },
363
+ ],
364
+ borderWidth: width => [{ field: 'border_width', value: dimension(width) }],
365
+ borderColor: color => [
366
+ { field: 'border_color', value: parseColorValue(color) },
352
367
  ],
353
- borderWidth: width => [{ field: 'border_width', expr: dimension(width) }],
354
- borderColor: color => [{ field: 'border_color', expr: colorLiteral(color) }],
355
368
  opacity: opacity => [
356
369
  {
357
370
  field: 'opacity',
358
- expr: String(Math.round(Math.max(0, Math.min(1, Number(opacity))) * 255)),
371
+ value: Math.round(Math.max(0, Math.min(1, Number(opacity))) * OPACITY_OPAQUE),
359
372
  },
360
373
  ],
361
- zIndex: zIndex => [{ field: 'z_index', expr: dimension(zIndex) }],
374
+ zIndex: zIndex => [{ field: 'z_index', value: dimension(zIndex) }],
362
375
  // Text
363
- color: color => [{ field: 'color', expr: colorLiteral(color) }],
364
- fontSize: size => [{ field: 'font_size', expr: dimension(size) }],
376
+ color: color => [{ field: 'color', value: parseColorValue(color) }],
377
+ fontSize: size => [{ field: 'font_size', value: dimension(size) }],
365
378
  fontWeight: weight => [
366
379
  {
367
380
  field: 'font_weight',
368
- expr: weight === 'bold' || Number(weight) >= 600 ? '1' : '0',
381
+ value: weight === 'bold' || Number(weight) >= BOLD_WEIGHT ? 1 : 0,
369
382
  },
370
383
  ],
371
384
  lineHeight: lineHeight => [
372
- { field: 'line_height', expr: dimension(lineHeight) },
385
+ { field: 'line_height', value: dimension(lineHeight) },
373
386
  ],
374
387
  letterSpacing: spacing => [
375
- { field: 'letter_spacing', expr: dimension(spacing) },
388
+ { field: 'letter_spacing', value: dimension(spacing) },
376
389
  ],
377
390
  };
378
391
  /**
@@ -387,9 +400,8 @@ export const isStyleKey = (key) => Object.hasOwn(KEYS, key);
387
400
  export const STYLE_KEYS = Object.keys(KEYS);
388
401
  /**
389
402
  * 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
403
+ * of what native_ui_bridge.c does at runtime in Flow A: the package builds the same prop bags as Flow A,
404
+ * from the same defaults (er_props_default), so both render the same pixels. An unsupported key throws, so the compiler fails
393
405
  * loudly instead of silently dropping a style.
394
406
  *
395
407
  * @param style Flattened style (plain key→value; values already statically resolved).