embedded-react 0.14.1 → 0.16.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 (61) hide show
  1. package/README.md +51 -486
  2. package/aot/compile.mjs +173 -8272
  3. package/aot/compiler/animations.mjs +1001 -0
  4. package/aot/compiler/assemble.mjs +806 -0
  5. package/aot/compiler/c/animations.mjs +362 -0
  6. package/aot/compiler/c/expressions.mjs +215 -0
  7. package/aot/compiler/c/functions.mjs +268 -0
  8. package/aot/compiler/c/keyboard.mjs +96 -0
  9. package/aot/compiler/c/nodes.mjs +282 -0
  10. package/aot/compiler/c/pan-responder.mjs +136 -0
  11. package/aot/compiler/c/statements.mjs +242 -0
  12. package/aot/compiler/c/text.mjs +83 -0
  13. package/aot/compiler/c/vectors.mjs +381 -0
  14. package/aot/compiler/c-syntax.mjs +127 -0
  15. package/aot/compiler/check.mjs +165 -0
  16. package/aot/compiler/collect.mjs +743 -0
  17. package/aot/compiler/control-flow.mjs +683 -0
  18. package/aot/compiler/diagnostics.mjs +137 -0
  19. package/aot/compiler/elements/activity-indicator.mjs +160 -0
  20. package/aot/compiler/elements/dial.mjs +343 -0
  21. package/aot/compiler/elements/flat-list.mjs +139 -0
  22. package/aot/compiler/elements/image.mjs +151 -0
  23. package/aot/compiler/elements/modal.mjs +158 -0
  24. package/aot/compiler/elements/props.mjs +474 -0
  25. package/aot/compiler/elements/switch.mjs +183 -0
  26. package/aot/compiler/elements/text-input.mjs +171 -0
  27. package/aot/compiler/expressions.mjs +1479 -0
  28. package/aot/compiler/handlers.mjs +1072 -0
  29. package/aot/compiler/ir/animations.mjs +16 -0
  30. package/aot/compiler/ir/app.mjs +16 -0
  31. package/aot/compiler/ir/expressions.mjs +16 -0
  32. package/aot/compiler/ir/functions.mjs +16 -0
  33. package/aot/compiler/ir/keyboard.mjs +16 -0
  34. package/aot/compiler/ir/nodes.mjs +83 -0
  35. package/aot/compiler/ir/pan-responder.mjs +16 -0
  36. package/aot/compiler/ir/source.mjs +16 -0
  37. package/aot/compiler/ir/statements.mjs +16 -0
  38. package/aot/compiler/ir/text.mjs +16 -0
  39. package/aot/compiler/ir/types.mjs +185 -0
  40. package/aot/compiler/ir/vectors.mjs +16 -0
  41. package/aot/compiler/keyboard.mjs +152 -0
  42. package/aot/compiler/lower.mjs +282 -0
  43. package/aot/compiler/nodes.mjs +683 -0
  44. package/aot/compiler/options.mjs +55 -0
  45. package/aot/compiler/out.mjs +94 -0
  46. package/aot/compiler/pan-responder.mjs +354 -0
  47. package/aot/compiler/parse.mjs +300 -0
  48. package/aot/compiler/static-eval.mjs +228 -0
  49. package/aot/compiler/style-text.mjs +648 -0
  50. package/aot/compiler/svg.mjs +1167 -0
  51. package/aot/compiler/types.mjs +16 -0
  52. package/aot/screenshot-smoke.mjs +95 -55
  53. package/aot/style-map.mjs +366 -304
  54. package/cli.mjs +5 -8
  55. package/package.json +14 -6
  56. package/sim/embedded-react.cjs +1 -1
  57. package/sim/embedded-react.js +1 -1
  58. package/sim/embedded-react.wasm +0 -0
  59. package/src/embedded-react/FlatList.js +4 -4
  60. package/src/embedded-react/index.d.ts +2 -1
  61. package/src/props.js +1 -1
@@ -0,0 +1,137 @@
1
+ /*
2
+ * Copyright 2026 Cory Lamming
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /*----------------------------------------------------------------------------------------------------------------------
17
+ - Imports
18
+ ---------------------------------------------------------------------------------------------------------------------*/
19
+ import { codeFrameColumns } from '@babel/code-frame';
20
+ /*----------------------------------------------------------------------------------------------------------------------
21
+ - Constants
22
+ ---------------------------------------------------------------------------------------------------------------------*/
23
+ /** The location of each node a located emitter is lowering, innermost last; undefined for a node without one. */
24
+ const loweringAt = [];
25
+ /*----------------------------------------------------------------------------------------------------------------------
26
+ - Implementation
27
+ ---------------------------------------------------------------------------------------------------------------------*/
28
+ /**
29
+ * Where an AOT error thrown now would be reported: the innermost node being lowered that has a location.
30
+ *
31
+ * @returns The location, or undefined outside every located emitter.
32
+ */
33
+ export function currentLoc() {
34
+ for (let index = loweringAt.length - 1; index >= 0; index--) {
35
+ if (loweringAt[index]) {
36
+ return loweringAt[index];
37
+ }
38
+ }
39
+ return undefined;
40
+ }
41
+ /**
42
+ * Builds an AOT error carrying an optional `hint` (a "rewrite it like this" suggestion shown to the user).
43
+ *
44
+ * @param message What is not supported; "AOT: " is prefixed when missing.
45
+ * @param hint How to rewrite it when there is a known way.
46
+ *
47
+ * @returns The error, for the caller to throw.
48
+ */
49
+ export function aotError(message, hint) {
50
+ const error = new Error(message.startsWith('AOT:') ? message : `AOT: ${message}`);
51
+ if (hint) {
52
+ error.aotHint = hint;
53
+ }
54
+ return error;
55
+ }
56
+ /**
57
+ * Pins an AOT error that has no location yet to `loc`, as a located emitter does.
58
+ *
59
+ * @param error The thrown value.
60
+ * @param loc Where the construct being lowered is, if it is anywhere.
61
+ */
62
+ export function locateError(error, loc) {
63
+ if (error &&
64
+ typeof error.message === 'string' &&
65
+ error.message.startsWith('AOT:') &&
66
+ !error.aotLoc &&
67
+ loc) {
68
+ error.aotLoc = loc;
69
+ }
70
+ }
71
+ /**
72
+ * Wraps an emit function so a thrown AOT error (without a location yet) is tagged with the current node's
73
+ * loc. Wrapped emitters nest, so the deepest node that failed is the one reported. The expression, node, and
74
+ * handler emitters are all wrapped, and compileSource formats the result with formatAotError. While it runs,
75
+ * currentLoc() reports the same location, for a check recorded now and run later.
76
+ *
77
+ * @param fn The emit function; its first parameter is the node it lowers.
78
+ *
79
+ * @returns The same function, with its AOT errors located.
80
+ */
81
+ export function withLoc(fn) {
82
+ return function (node, ...rest) {
83
+ loweringAt.push(node?.loc?.start);
84
+ try {
85
+ return fn(node, ...rest);
86
+ }
87
+ catch (error) {
88
+ locateError(error, node?.loc?.start); // babel loc: { line (1-based), column (0-based) }
89
+ throw error;
90
+ }
91
+ finally {
92
+ loweringAt.pop();
93
+ }
94
+ };
95
+ }
96
+ /**
97
+ * Rebuilds an AOT error with `file:line:col`, a code-frame, any hint, and the screen size this build folded
98
+ * its layout at (from the resolved `opts`), all folded into the message, for compileSource to throw.
99
+ *
100
+ * @param error The error compileSource caught.
101
+ * @param src The app's source, for the code-frame.
102
+ * @param filename The source's path, as the message should show it.
103
+ * @param opts The compile's resolved options, for the screen footer.
104
+ *
105
+ * @returns The located error; `error` itself when it has no location.
106
+ */
107
+ export function formatAotError(error, src, filename, opts) {
108
+ if (!error || !error.aotLoc)
109
+ return error; // nothing to locate — leave the bare message
110
+ // Render the code-frame around the error's location, and the hint when there is one.
111
+ const { line, column } = error.aotLoc;
112
+ const frameLoc = { start: { line, column: column + 1 } }; // code-frame columns are 1-based
113
+ let codeFrame = '';
114
+ try {
115
+ codeFrame = codeFrameColumns(src, frameLoc, { highlightCode: false });
116
+ }
117
+ catch {
118
+ /* code-frame is best-effort */
119
+ }
120
+ // Name the screen size the layout was folded at: it picks which branch of a responsive app the error came from.
121
+ const hint = error.aotHint ? `\n\nhint: ${error.aotHint}` : '';
122
+ const size = `${opts.screen.width}×${opts.screen.height}`;
123
+ const screen = opts.screenFrom === 'option'
124
+ ? `\n\nscreen: ${size}.`
125
+ : opts.screenFrom === 'env'
126
+ ? `\n\nscreen: ${size} (from ER_AOT_SCREEN_W/H).`
127
+ : `\n\nscreen: ${size} — ER_AOT_SCREEN_W/H did not supply both dimensions, so the ` +
128
+ `default filled in. A responsive app picks its layout from \`screen\`, so this may be compiling a ` +
129
+ `branch meant for another board.`;
130
+ // Build the located error, keeping the location and hint for any caller that inspects them.
131
+ const located = new Error(`${error.message}\n at ${filename}:${line}:${column + 1}\n\n${codeFrame}${hint}${screen}`);
132
+ located.aotLoc = error.aotLoc;
133
+ if (error.aotHint) {
134
+ located.aotHint = error.aotHint;
135
+ }
136
+ return located;
137
+ }
@@ -0,0 +1,160 @@
1
+ /*
2
+ * Copyright 2026 Cory Lamming
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /*----------------------------------------------------------------------------------------------------------------------
17
+ - Imports
18
+ ---------------------------------------------------------------------------------------------------------------------*/
19
+ import { colorLiteral } from '../../style-map.mjs';
20
+ import { aotError } from '../diagnostics.mjs';
21
+ import { evalStatic } from '../static-eval.mjs';
22
+ import { lowerExpr } from '../expressions.mjs';
23
+ import { attrExpr, lowerColorValue, styleWrites, collectStyleAssigns, } from '../style-text.mjs';
24
+ import { checkInterpolations, lowerRefBinds } from '../nodes.mjs';
25
+ import { at, elementSpec } from './props.mjs';
26
+ /*----------------------------------------------------------------------------------------------------------------------
27
+ - Constants
28
+ ---------------------------------------------------------------------------------------------------------------------*/
29
+ const SIZE_SMALL = 20;
30
+ const SIZE_LARGE = 36;
31
+ /*----------------------------------------------------------------------------------------------------------------------
32
+ - Implementation
33
+ ---------------------------------------------------------------------------------------------------------------------*/
34
+ /**
35
+ * @brief One of the typed element emitters that emitNodeImpl (nodes.mts) dispatches to.
36
+ *
37
+ * The engine spins it on its own (a looping rotate; render is a ring of 8 fading dots). No intrinsic size, so
38
+ * a default box is set from `size` (small=20, large=36) unless style sets width/height.
39
+ *
40
+ * ```jsx
41
+ * <ActivityIndicator color={…} size="small"|"large"|N animating={…} style={…} />
42
+ *
43
+ * <ActivityIndicator> -> ER_NODE_ACTIVITY_INDICATOR
44
+ * ```
45
+ *
46
+ * @param element The JSX element.
47
+ * @param scope The current scope.
48
+ * @param out The current output.
49
+ * @param env The current environment.
50
+ *
51
+ * @returns The name of the node variable (Node ID).
52
+ */
53
+ export function emitActivityIndicator(element, scope, out, env) {
54
+ // get node id
55
+ const nodeId = `n${out.allocateNodeId()}`;
56
+ // collect style assignments
57
+ const { staticAssigns, dynAssigns, binds } = collectStyleAssigns(element.openingElement, scope, env, elementSpec('ActivityIndicator'));
58
+ const hasField = (field) => styleWrites(staticAssigns, dynAssigns, field);
59
+ // `style.color` tints the spinner, as in Flow A; a `color` prop written after it wins.
60
+ for (const assign of [...staticAssigns, ...dynAssigns]) {
61
+ if (assign.field === 'color') {
62
+ assign.field = 'indicator_color';
63
+ }
64
+ }
65
+ // process element attributes
66
+ let size = SIZE_LARGE;
67
+ for (const attr of element.openingElement.attributes) {
68
+ // Ensure all props are explicit named attributes.
69
+ // Spread props cannot be analyzed statically
70
+ if (attr.type !== 'JSXAttribute') {
71
+ throw aotError('AOT: spread props on <ActivityIndicator> are not supported');
72
+ }
73
+ // skip non-props
74
+ const name = attr.name.name;
75
+ if (name === 'style' || name === 'ref' || name === 'key')
76
+ continue;
77
+ // process props
78
+ const node = attrExpr(attr);
79
+ if (name === 'color') {
80
+ try {
81
+ staticAssigns.push({
82
+ field: 'indicator_color',
83
+ expr: colorLiteral(String(evalStatic(node, scope))),
84
+ });
85
+ }
86
+ catch {
87
+ dynAssigns.push({
88
+ field: 'indicator_color',
89
+ value: lowerColorValue(node, env),
90
+ });
91
+ }
92
+ }
93
+ else if (name === 'size') {
94
+ const sizeValue = evalStatic(node, scope);
95
+ size =
96
+ sizeValue === 'small'
97
+ ? SIZE_SMALL
98
+ : sizeValue === 'large'
99
+ ? SIZE_LARGE
100
+ : typeof sizeValue === 'number' &&
101
+ Number.isFinite(sizeValue) &&
102
+ sizeValue > 0
103
+ ? Math.round(sizeValue)
104
+ : NaN;
105
+ if (Number.isNaN(size)) {
106
+ throw at(aotError(`AOT: <ActivityIndicator size> must be 'small', 'large' or a number of pixels (got ${JSON.stringify(sizeValue) ?? String(sizeValue)})`), attr);
107
+ }
108
+ }
109
+ else if (name === 'animating') {
110
+ try {
111
+ staticAssigns.push({
112
+ field: 'animating',
113
+ expr: evalStatic(node, scope) ? '1' : '0',
114
+ });
115
+ }
116
+ catch {
117
+ dynAssigns.push({
118
+ field: 'animating',
119
+ value: {
120
+ kind: 'flag',
121
+ test: lowerExpr(node, env),
122
+ truthiness: 'value',
123
+ negate: false,
124
+ whenTrue: 1,
125
+ },
126
+ });
127
+ }
128
+ }
129
+ else {
130
+ throw aotError(`AOT: <ActivityIndicator> prop "${name}" is not supported`, 'supported props: color, size, animating, style.');
131
+ }
132
+ }
133
+ // default size: large unless style sets width/height
134
+ if (!hasField('width')) {
135
+ staticAssigns.push({ field: 'width', expr: String(size) });
136
+ }
137
+ if (!hasField('height')) {
138
+ staticAssigns.push({ field: 'height', expr: String(size) });
139
+ }
140
+ const node = {
141
+ id: nodeId,
142
+ type: 'ER_NODE_ACTIVITY_INDICATOR',
143
+ constantProps: staticAssigns,
144
+ stateProps: dynAssigns,
145
+ placeholder: null,
146
+ text: null,
147
+ image: null,
148
+ spans: null,
149
+ children: [],
150
+ wiring: [
151
+ ...binds.map((bind, index) => ({ kind: 'bind', bind, index })),
152
+ ...lowerRefBinds(element.openingElement, env).map(slot => ({
153
+ kind: 'ref',
154
+ slot,
155
+ })),
156
+ ],
157
+ };
158
+ checkInterpolations(node);
159
+ return node;
160
+ }
@@ -0,0 +1,343 @@
1
+ /*
2
+ * Copyright 2026 Cory Lamming
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /*----------------------------------------------------------------------------------------------------------------------
17
+ - Imports
18
+ ---------------------------------------------------------------------------------------------------------------------*/
19
+ import { check, checkNumber, DIAL_MAX_GRADIENT_STOPS } from '../check.mjs';
20
+ import { colorLiteral } from '../../style-map.mjs';
21
+ import { aotError } from '../diagnostics.mjs';
22
+ import { evalStaticOrThrow, evalStatic } from '../static-eval.mjs';
23
+ import { floatLit } from '../c-syntax.mjs';
24
+ import { lowerExpr } from '../expressions.mjs';
25
+ import { isFn } from '../collect.mjs';
26
+ import { attrExpr, lowerColorValue, lowerEnumValue, styleWrites, collectStyleAssigns, } from '../style-text.mjs';
27
+ import { lowerValueHandler } from '../handlers.mjs';
28
+ import { emitChildren } from '../control-flow.mjs';
29
+ import { checkInterpolations, lowerRefBinds } from '../nodes.mjs';
30
+ import { at, elementSpec } from './props.mjs';
31
+ import { imageNameFromSource } from './image.mjs';
32
+ /*----------------------------------------------------------------------------------------------------------------------
33
+ - Constants
34
+ ---------------------------------------------------------------------------------------------------------------------*/
35
+ /** <Dial> prop → ERProps field tables (see emitDial). */
36
+ const DIAL_FLOAT_PROPS = {
37
+ value: 'arc_value',
38
+ valueStart: 'arc_value_start',
39
+ minSpan: 'arc_min_span',
40
+ min: 'arc_min',
41
+ max: 'arc_max',
42
+ startAngle: 'arc_start_angle',
43
+ sweepAngle: 'arc_sweep_angle',
44
+ step: 'arc_step',
45
+ gapAngle: 'arc_gap_angle',
46
+ };
47
+ const DIAL_INT_PROPS = {
48
+ thickness: 'arc_width',
49
+ bandThickness: 'arc_band_width',
50
+ knobSize: 'arc_knob_size',
51
+ knobBorderWidth: 'arc_knob_border_width',
52
+ segments: 'arc_segments',
53
+ };
54
+ const DIAL_COLOR_PROPS = {
55
+ trackColor: 'arc_track_color',
56
+ indicatorColor: 'arc_indicator_color',
57
+ bandColor: 'arc_band_color',
58
+ knobColor: 'arc_knob_color',
59
+ knobBorderColor: 'arc_knob_border_color',
60
+ };
61
+ const DIAL_ENUM_PROPS = {
62
+ cap: {
63
+ field: 'arc_cap',
64
+ table: { butt: 'ER_ARC_CAP_BUTT', round: 'ER_ARC_CAP_ROUND' },
65
+ },
66
+ knob: {
67
+ field: 'arc_knob',
68
+ table: {
69
+ none: 'ER_ARC_KNOB_NONE',
70
+ circle: 'ER_ARC_KNOB_CIRCLE',
71
+ image: 'ER_ARC_KNOB_IMAGE',
72
+ child: 'ER_ARC_KNOB_CHILD',
73
+ },
74
+ },
75
+ };
76
+ /*----------------------------------------------------------------------------------------------------------------------
77
+ - Implementation
78
+ ---------------------------------------------------------------------------------------------------------------------*/
79
+ /**
80
+ * <Dial value={v} min max startAngle sweepAngle step thickness bandThickness trackColor indicatorColor
81
+ * indicatorGradient bandColor cap segments gapAngle knob knobSize knobColor knobBorderColor
82
+ * knobBorderWidth knobImage adjustable onChange={(v) => setV(v)} style=… />
83
+ * → ER_NODE_ARC, the engine's native arc widget. Numbers and colors are static literals or state-driven
84
+ * (recomputed in app_update); `value` may also be a useAnimatedValue handle, which binds ER_PROP_ARC_VALUE
85
+ * natively so a ramp costs no app_update at all. onChange lowers to ER_EVENT_VALUE_CHANGE with its param
86
+ * bound to data->value (the quantized value the built-in drag produced). Default 120x120 box.
87
+ *
88
+ * @param element The <Dial>.
89
+ * @param scope Compile-time constants in reach.
90
+ * @param out Everything emitted so far.
91
+ * @param env The expression environment.
92
+ * @param state The component's state table.
93
+ *
94
+ * @returns The node's variable.
95
+ */
96
+ export function emitDial(element, scope, out, env, state) {
97
+ // get node id
98
+ const nodeID = `n${out.allocateNodeId()}`;
99
+ // collect style assignments
100
+ const { staticAssigns, dynAssigns, binds } = collectStyleAssigns(element.openingElement, scope, env, elementSpec('Dial'));
101
+ const hasField = (field) => styleWrites(staticAssigns, dynAssigns, field);
102
+ if (!hasField('width')) {
103
+ staticAssigns.push({ field: 'width', expr: '120' });
104
+ }
105
+ if (!hasField('height')) {
106
+ staticAssigns.push({ field: 'height', expr: '120' });
107
+ }
108
+ // Fold numeric props when possible; otherwise emit runtime assignments for app_update().
109
+ const numeric = (field, node, isFloat, attr) => {
110
+ let number;
111
+ try {
112
+ number = evalStatic(node, scope);
113
+ }
114
+ catch {
115
+ const value = lowerExpr(node, env);
116
+ dynAssigns.push({
117
+ field,
118
+ value: isFloat ? { kind: 'float', value } : { kind: 'dimension', value },
119
+ });
120
+ return;
121
+ }
122
+ if (typeof number !== 'number') {
123
+ throw at(aotError(`AOT: <Dial ${attr.name.name}> must be a number (got ${JSON.stringify(number) ?? String(number)})`), attr);
124
+ }
125
+ // floatLit checks a float field itself; an int field needs the same check before it is rounded.
126
+ if (!isFloat) {
127
+ checkNumber(number);
128
+ }
129
+ staticAssigns.push({
130
+ field,
131
+ expr: isFloat ? floatLit(number) : String(Math.round(number)),
132
+ });
133
+ };
134
+ // Fold static colors now; emit dynamic color expressions for app_update().
135
+ const colour = (field, node, attr) => {
136
+ let color;
137
+ try {
138
+ color = evalStatic(node, scope);
139
+ }
140
+ catch {
141
+ dynAssigns.push({ field, value: lowerColorValue(node, env) });
142
+ return;
143
+ }
144
+ if (typeof color !== 'string') {
145
+ throw at(aotError(`AOT: <Dial ${attr.name.name}> must be a color string (got ${JSON.stringify(color) ?? String(color)})`), attr);
146
+ }
147
+ staticAssigns.push({ field, expr: colorLiteral(color) });
148
+ };
149
+ // Process <Dial> props, splitting them into static props, dynamic updates, binds, assets, and handlers.
150
+ let onChangeFn = null;
151
+ let knobImage = null; // static asset name
152
+ for (const attr of element.openingElement.attributes) {
153
+ // Ensure all props are explicit named attributes.
154
+ // Spread props cannot be analyzed statically
155
+ if (attr.type !== 'JSXAttribute') {
156
+ throw aotError('AOT: spread props on <Dial> are not supported');
157
+ }
158
+ // skip non-props
159
+ const name = attr.name.name;
160
+ if (name === 'style' || name === 'ref' || name === 'key')
161
+ continue;
162
+ // process props
163
+ const node = attrExpr(attr);
164
+ if ((name === 'value' || name === 'valueStart') &&
165
+ node?.type === 'Identifier' &&
166
+ env.animations?.has(node.name)) {
167
+ binds.push({
168
+ cVar: env.animations.get(node.name).cVar,
169
+ prop: name === 'value' ? 'ER_PROP_ARC_VALUE' : 'ER_PROP_ARC_VALUE_START',
170
+ });
171
+ }
172
+ else if (DIAL_FLOAT_PROPS[name]) {
173
+ numeric(DIAL_FLOAT_PROPS[name], node, true, attr);
174
+ }
175
+ else if (DIAL_INT_PROPS[name]) {
176
+ numeric(DIAL_INT_PROPS[name], node, false, attr);
177
+ }
178
+ else if (DIAL_COLOR_PROPS[name]) {
179
+ colour(DIAL_COLOR_PROPS[name], node, attr);
180
+ }
181
+ else if (DIAL_ENUM_PROPS[name]) {
182
+ const { field, table } = DIAL_ENUM_PROPS[name];
183
+ let token = null;
184
+ try {
185
+ token = evalStatic(node, scope);
186
+ }
187
+ catch {
188
+ /* state-driven — handled below */
189
+ }
190
+ if (typeof token === 'string') {
191
+ if (!table[token]) {
192
+ throw aotError(`AOT: unsupported <Dial ${name}> "${token}"`, `${name} must be one of: ${Object.keys(table).join(' / ')}.`);
193
+ }
194
+ staticAssigns.push({ field, expr: table[token] });
195
+ }
196
+ else {
197
+ dynAssigns.push({
198
+ field,
199
+ value: { kind: 'byte', value: lowerEnumValue(node, table, env) },
200
+ });
201
+ }
202
+ }
203
+ else if (name === 'adjustable' || name === 'range') {
204
+ const field = name === 'range' ? 'arc_range' : 'arc_adjustable';
205
+ try {
206
+ staticAssigns.push({ field, expr: evalStatic(node, scope) ? '1' : '0' });
207
+ }
208
+ catch {
209
+ dynAssigns.push({
210
+ field,
211
+ value: {
212
+ kind: 'flag',
213
+ test: lowerExpr(node, env),
214
+ truthiness: 'value',
215
+ negate: false,
216
+ whenTrue: 1,
217
+ },
218
+ });
219
+ }
220
+ }
221
+ else if (name === 'knobImage') {
222
+ knobImage = imageNameFromSource(node, env);
223
+ if (knobImage == null) {
224
+ throw aotError('AOT: <Dial knobImage> must resolve to a static asset name', "use an imported image (`import knob from './knob.png'` → knobImage={knob}) or a string asset name.");
225
+ }
226
+ const path = env.imageNames?.get(knobImage);
227
+ if (path) {
228
+ out.images.set(knobImage, path);
229
+ }
230
+ }
231
+ else if (name === 'indicatorGradient') {
232
+ // Allow indicatorGradient to be statically defined but conditionally enabled with a ternary against null/undefined.
233
+ let gradNode = node;
234
+ let gradCond = null;
235
+ if (node?.type === 'ConditionalExpression') {
236
+ const nullish = (n) => n?.type === 'NullLiteral' ||
237
+ (n?.type === 'Identifier' && n.name === 'undefined');
238
+ if (nullish(node.alternate)) {
239
+ gradNode = node.consequent;
240
+ gradCond = { test: lowerExpr(node.test, env), negate: false };
241
+ }
242
+ else if (nullish(node.consequent)) {
243
+ gradNode = node.alternate;
244
+ gradCond = { test: lowerExpr(node.test, env), negate: true };
245
+ }
246
+ }
247
+ // Validate and normalize the static gradient definition, keeping only the engine-supported stop count.
248
+ const gradient = evalStaticOrThrow(gradNode, scope, 'AOT: <Dial indicatorGradient> must be a static object (optionally behind a ternary against null)', "indicatorGradient={{ type: 'conic', stops: [{ color: '#00f' }, { color: '#f00' }] }}, or " +
249
+ 'indicatorGradient={on ? {…} : null}');
250
+ const allStops = Array.isArray(gradient?.stops) ? gradient.stops : [];
251
+ check({ kind: 'dialGradientStops', count: allStops.length });
252
+ const stops = allStops.slice(0, DIAL_MAX_GRADIENT_STOPS);
253
+ staticAssigns.push({
254
+ field: 'gradient_type',
255
+ expr: gradient.type === 'radial'
256
+ ? 'ER_GRADIENT_RADIAL'
257
+ : 'ER_GRADIENT_CONIC',
258
+ });
259
+ // Emit the stop count separately so a ternary can enable/disable the static gradient at runtime.
260
+ if (gradCond) {
261
+ dynAssigns.push({
262
+ field: 'gradient_stop_count',
263
+ value: {
264
+ kind: 'flag',
265
+ test: gradCond.test,
266
+ truthiness: 'value',
267
+ negate: gradCond.negate,
268
+ whenTrue: stops.length,
269
+ },
270
+ });
271
+ }
272
+ else {
273
+ staticAssigns.push({
274
+ field: 'gradient_stop_count',
275
+ expr: String(stops.length),
276
+ });
277
+ }
278
+ // Emit each fixed stop, filling in missing offsets with evenly spaced positions.
279
+ stops.forEach((st, i) => {
280
+ const off = typeof st.offset === 'number' ? st.offset : i / (stops.length - 1);
281
+ staticAssigns.push({
282
+ field: `gradient_stops[${i}].color`,
283
+ expr: colorLiteral(String(st.color)),
284
+ });
285
+ staticAssigns.push({
286
+ field: `gradient_stops[${i}].position`,
287
+ expr: floatLit(off),
288
+ });
289
+ });
290
+ }
291
+ else if (name === 'onChange') {
292
+ onChangeFn = node;
293
+ }
294
+ else {
295
+ throw aotError(`AOT: <Dial> prop "${name}" is not supported`);
296
+ }
297
+ }
298
+ // Animated bindings: style props plus an animated `value` (ER_PROP_ARC_VALUE).
299
+ const node = {
300
+ id: nodeID,
301
+ type: 'ER_NODE_ARC',
302
+ constantProps: staticAssigns,
303
+ stateProps: dynAssigns,
304
+ placeholder: null,
305
+ text: null,
306
+ image: knobImage != null
307
+ ? { kind: 'static', name: knobImage, resetOnUpdate: true }
308
+ : null,
309
+ spans: null,
310
+ children: [],
311
+ wiring: binds.map((bind, index) => ({ kind: 'bind', bind, index })),
312
+ };
313
+ // Compile <Dial onChange> into an ER_EVENT_VALUE_CHANGE handler.
314
+ if (onChangeFn) {
315
+ // A useCallback identifier resolves to its arrow, the same way the generic host-node event path does —
316
+ // a dial's change handler is exactly the kind of thing an app wraps in useCallback.
317
+ if (onChangeFn.type === 'Identifier' &&
318
+ env.callbacks?.has(onChangeFn.name)) {
319
+ onChangeFn = env.callbacks.get(onChangeFn.name);
320
+ }
321
+ // Require a function node so lowerValueHandler can bind the dial's value parameters.
322
+ if (!isFn(onChangeFn)) {
323
+ throw aotError('AOT: <Dial onChange> must be an inline function or a useCallback', 'onChange={(v) => setValue(v)}');
324
+ }
325
+ const handlerName = `er_handler_${out.handlers.length}`;
326
+ out.handlers.push({
327
+ kind: 'callback',
328
+ name: handlerName,
329
+ callback: lowerValueHandler(onChangeFn, 'data->value', env, state, out, 'float', 'data->value_start'),
330
+ });
331
+ node.wiring.push({
332
+ kind: 'event',
333
+ event: 'ER_EVENT_VALUE_CHANGE',
334
+ handler: handlerName,
335
+ });
336
+ }
337
+ for (const slot of lowerRefBinds(element.openingElement, env)) {
338
+ node.wiring.push({ kind: 'ref', slot });
339
+ }
340
+ checkInterpolations(node);
341
+ node.children = emitChildren(element.children, scope, out, env, state);
342
+ return node;
343
+ }