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.
- package/NOTICE +5 -0
- package/README.md +8 -3
- package/aot/app-file-loader.mjs +116 -0
- package/aot/compile.mjs +180 -90
- package/aot/compiler/animations.mjs +568 -317
- package/aot/compiler/boot.mjs +97 -35
- package/aot/compiler/branch-merge.mjs +4 -3
- package/aot/compiler/check.mjs +70 -18
- package/aot/compiler/collect.mjs +787 -288
- package/aot/compiler/contexts.mjs +391 -0
- package/aot/compiler/control-flow.mjs +439 -268
- package/aot/compiler/custom-hooks.mjs +686 -0
- package/aot/compiler/diagnostics.mjs +22 -25
- package/aot/compiler/elements/activity-indicator.mjs +25 -24
- package/aot/compiler/elements/button.mjs +182 -0
- package/aot/compiler/elements/dial.mjs +91 -77
- package/aot/compiler/elements/flat-list.mjs +24 -22
- package/aot/compiler/elements/image-background.mjs +76 -0
- package/aot/compiler/elements/image.mjs +52 -50
- package/aot/compiler/elements/modal.mjs +31 -30
- package/aot/compiler/elements/props.mjs +61 -26
- package/aot/compiler/elements/rewrite.mjs +118 -0
- package/aot/compiler/elements/section-list.mjs +370 -0
- package/aot/compiler/elements/switch.mjs +42 -34
- package/aot/compiler/elements/text-input.mjs +34 -32
- package/aot/compiler/expressions.mjs +1685 -392
- package/aot/compiler/handlers.mjs +2029 -547
- package/aot/compiler/helper-values.mjs +312 -0
- package/aot/compiler/ir/functions.mjs +11 -1
- package/aot/compiler/ir/nodes.mjs +43 -4
- package/aot/compiler/ir/reads.mjs +223 -22
- package/aot/compiler/ir/text.mjs +5 -1
- package/aot/compiler/ir/types.mjs +26 -14
- package/aot/compiler/ir/vectors.mjs +5 -1
- package/aot/compiler/kept-states.mjs +177 -0
- package/aot/compiler/keyboard.mjs +17 -7
- package/aot/compiler/list-items.mjs +226 -0
- package/aot/compiler/list-order.mjs +586 -0
- package/aot/compiler/list-split.mjs +259 -0
- package/aot/compiler/loops.mjs +582 -0
- package/aot/compiler/lower.mjs +246 -111
- package/aot/compiler/native-files.mjs +439 -0
- package/aot/compiler/native-header.mjs +335 -0
- package/aot/compiler/native-modules.mjs +1173 -0
- package/aot/compiler/nodes.mjs +195 -172
- package/aot/compiler/options.mjs +37 -31
- package/aot/compiler/out.mjs +32 -23
- package/aot/compiler/package/animations.mjs +779 -0
- package/aot/compiler/package/arena.mjs +252 -0
- package/aot/compiler/package/assemble.mjs +175 -0
- package/aot/compiler/package/bytecode.mjs +315 -0
- package/aot/compiler/package/checks.mjs +1026 -0
- package/aot/compiler/package/codegen.mjs +2168 -0
- package/aot/compiler/package/enums.mjs +148 -0
- package/aot/compiler/package/format.mjs +771 -0
- package/aot/compiler/package/layouts.mjs +136 -0
- package/aot/compiler/package/lower.mjs +2103 -0
- package/aot/compiler/package/props.mjs +118 -0
- package/aot/compiler/package/string-caps.mjs +515 -0
- package/aot/compiler/package/tables.mjs +127 -0
- package/aot/compiler/package/vectors.mjs +502 -0
- package/aot/compiler/package/writer.mjs +686 -0
- package/aot/compiler/pan-responder.mjs +69 -61
- package/aot/compiler/parse.mjs +23 -21
- package/aot/compiler/record-shapes.mjs +246 -0
- package/aot/compiler/records.mjs +654 -0
- package/aot/compiler/reducers.mjs +272 -0
- package/aot/compiler/static-eval.mjs +340 -30
- package/aot/compiler/style-text.mjs +178 -174
- package/aot/compiler/svg.mjs +480 -251
- package/aot/compiler/switch-cases.mjs +198 -0
- package/aot/compiler/tagged-records.mjs +450 -0
- package/aot/compiler/typing.mjs +307 -0
- package/aot/compiler/updaters.mjs +320 -0
- package/aot/compiler/window-dimensions.mjs +94 -0
- package/aot/compiler/worked-values.mjs +319 -0
- package/aot/demo-file.mjs +30 -0
- package/aot/screenshot-smoke.mjs +54 -40
- package/aot/style-map.mjs +152 -92
- package/assets/bake-font.mjs +123 -77
- package/assets/bake-image.mjs +39 -22
- package/assets/bake-svg.mjs +361 -262
- package/assets/build-builtin-font.mjs +11 -7
- package/assets/emit-c.mjs +77 -58
- package/assets/emit-container.mjs +123 -37
- package/assets/emit-pack.mjs +77 -67
- package/assets/font-config.mjs +9 -6
- package/assets/font-sizes.mjs +163 -123
- package/assets/glyph-coverage.mjs +74 -54
- package/assets/index.mjs +31 -9
- package/assets/rasterize.mjs +126 -99
- package/assets/svg-loader.mjs +8 -8
- package/build.mjs +23 -13
- package/cli.mjs +402 -172
- package/compile-bin.mjs +3 -3
- package/flash.mjs +537 -0
- package/hotreload/dev-device.mjs +90 -33
- package/hotreload/pack-app.mjs +55 -43
- package/hotreload/pack-split.mjs +62 -64
- package/hotreload/package-transfer.mjs +175 -0
- package/hotreload/protocol.mjs +50 -37
- package/hotreload/uploader.mjs +38 -27
- package/hotreload/watch-tree.mjs +19 -19
- package/pack-container.mjs +37 -21
- package/package.json +7 -8
- package/persist-transform.mjs +34 -28
- package/qjsc-wasm.mjs +25 -14
- package/sim/embedded-react.cjs +1 -1
- package/sim/embedded-react.js +1 -1
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +94 -85
- package/sim-server.mjs +113 -94
- package/src/embedded-react/Animated.js +24 -24
- package/src/embedded-react/Dimensions.js +37 -0
- package/src/embedded-react/Easing.js +1 -1
- package/src/embedded-react/FlatList.js +3 -3
- package/src/embedded-react/LayoutAnimation.js +8 -5
- package/src/embedded-react/PanResponder.js +75 -71
- package/src/embedded-react/Pressable.js +2 -8
- package/src/embedded-react/SectionList.js +7 -9
- package/src/embedded-react/StyleSheet.js +4 -3
- package/src/embedded-react/TouchableOpacity.js +13 -8
- package/src/embedded-react/index.d.ts +88 -8
- package/src/embedded-react/index.js +2 -0
- package/src/embedded-react/layout-anim-config.js +10 -4
- package/src/embedded-react/list-child.js +5 -5
- package/src/embedded-react/named-colors.js +1 -1
- package/src/embedded-react/nativeModule.js +462 -0
- package/src/embedded-react/split-style.js +11 -11
- package/src/embedded-react/svg-ops.js +760 -593
- package/src/embedded-react/useHostValue.js +3 -3
- package/src/embedded-react/usePersistentState.js +6 -6
- package/src/embedded-react/warn-props.js +1 -1
- package/src/host-config.js +60 -53
- package/src/props.js +49 -41
- package/src/renderer.js +7 -4
- package/aot/compiler/assemble.mjs +0 -944
- package/aot/compiler/c/animations.mjs +0 -436
- package/aot/compiler/c/boot.mjs +0 -127
- package/aot/compiler/c/expressions.mjs +0 -270
- package/aot/compiler/c/functions.mjs +0 -268
- package/aot/compiler/c/keyboard.mjs +0 -96
- package/aot/compiler/c/nodes.mjs +0 -303
- package/aot/compiler/c/pan-responder.mjs +0 -136
- package/aot/compiler/c/statements.mjs +0 -319
- package/aot/compiler/c/text.mjs +0 -83
- package/aot/compiler/c/vectors.mjs +0 -381
- package/aot/compiler/c-syntax.mjs +0 -127
|
@@ -17,10 +17,9 @@
|
|
|
17
17
|
- Imports
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
19
|
import { check, checkNumber, DIAL_MAX_GRADIENT_STOPS } from '../check.mjs';
|
|
20
|
-
import {
|
|
21
|
-
import { aotError } from '../diagnostics.mjs';
|
|
20
|
+
import { floatConstant, parseColorValue } from '../../style-map.mjs';
|
|
21
|
+
import { aotError, currentLoc } from '../diagnostics.mjs';
|
|
22
22
|
import { evalStaticOrThrow, evalStatic } from '../static-eval.mjs';
|
|
23
|
-
import { floatLit } from '../c-syntax.mjs';
|
|
24
23
|
import { lowerExpr } from '../expressions.mjs';
|
|
25
24
|
import { isFn } from '../collect.mjs';
|
|
26
25
|
import { attrExpr, lowerColorValue, lowerEnumValue, styleWrites, collectStyleAssigns, } from '../style-text.mjs';
|
|
@@ -29,6 +28,7 @@ import { emitChildren } from '../control-flow.mjs';
|
|
|
29
28
|
import { checkInterpolations, lowerRefBinds } from '../nodes.mjs';
|
|
30
29
|
import { at, elementSpec } from './props.mjs';
|
|
31
30
|
import { imageNameFromSource } from './image.mjs';
|
|
31
|
+
import { FLOAT } from '../ir/types.mjs';
|
|
32
32
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
33
33
|
- Constants
|
|
34
34
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -73,6 +73,8 @@ const DIAL_ENUM_PROPS = {
|
|
|
73
73
|
},
|
|
74
74
|
},
|
|
75
75
|
};
|
|
76
|
+
/** A <Dial>'s width and height when its style sets neither. */
|
|
77
|
+
const DEFAULT_SIZE = 120;
|
|
76
78
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
77
79
|
- Implementation
|
|
78
80
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -81,102 +83,102 @@ const DIAL_ENUM_PROPS = {
|
|
|
81
83
|
* indicatorGradient bandColor cap segments gapAngle knob knobSize knobColor knobBorderColor
|
|
82
84
|
* knobBorderWidth knobImage adjustable onChange={(v) => setV(v)} style=… />
|
|
83
85
|
* → ER_NODE_ARC, the engine's native arc widget. Numbers and colors are static literals or state-driven
|
|
84
|
-
* (recomputed in
|
|
85
|
-
* natively so a ramp costs no
|
|
86
|
+
* (recomputed in the update); `value` may also be a useAnimatedValue handle, which binds ER_PROP_ARC_VALUE
|
|
87
|
+
* natively so a ramp costs no update at all. onChange lowers to ER_EVENT_VALUE_CHANGE with its param
|
|
86
88
|
* bound to data->value (the quantized value the built-in drag produced). Default 120x120 box.
|
|
87
89
|
*
|
|
88
90
|
* @param element The <Dial>.
|
|
89
91
|
* @param scope Compile-time constants in reach.
|
|
90
|
-
* @param
|
|
91
|
-
* @param
|
|
92
|
+
* @param output Everything emitted so far.
|
|
93
|
+
* @param environment The expression environment.
|
|
92
94
|
* @param state The component's state table.
|
|
93
95
|
*
|
|
94
96
|
* @returns The node's variable.
|
|
95
97
|
*/
|
|
96
|
-
export function emitDial(element, scope,
|
|
98
|
+
export function emitDial(element, scope, output, environment, state) {
|
|
97
99
|
// get node id
|
|
98
|
-
const nodeID = `n${
|
|
100
|
+
const nodeID = `n${output.allocateNodeId()}`;
|
|
99
101
|
// collect style assignments
|
|
100
|
-
const { staticAssigns,
|
|
101
|
-
const hasField = (field) => styleWrites(staticAssigns,
|
|
102
|
+
const { staticAssigns, dynamicAssigns, binds } = collectStyleAssigns(element.openingElement, scope, environment, elementSpec('Dial'));
|
|
103
|
+
const hasField = (field) => styleWrites(staticAssigns, dynamicAssigns, field);
|
|
102
104
|
if (!hasField('width')) {
|
|
103
|
-
staticAssigns.push({ field: 'width',
|
|
105
|
+
staticAssigns.push({ field: 'width', value: DEFAULT_SIZE });
|
|
104
106
|
}
|
|
105
107
|
if (!hasField('height')) {
|
|
106
|
-
staticAssigns.push({ field: 'height',
|
|
108
|
+
staticAssigns.push({ field: 'height', value: DEFAULT_SIZE });
|
|
107
109
|
}
|
|
108
|
-
// Fold numeric props when possible; otherwise emit runtime assignments for
|
|
109
|
-
const numeric = (field, node, isFloat,
|
|
110
|
+
// Fold numeric props when possible; otherwise emit runtime assignments for the update.
|
|
111
|
+
const numeric = (field, node, isFloat, attribute) => {
|
|
110
112
|
let number;
|
|
111
113
|
try {
|
|
112
114
|
number = evalStatic(node, scope, 'strict');
|
|
113
115
|
}
|
|
114
116
|
catch {
|
|
115
|
-
const value = lowerExpr(node,
|
|
116
|
-
|
|
117
|
+
const value = lowerExpr(node, environment);
|
|
118
|
+
dynamicAssigns.push({
|
|
117
119
|
field,
|
|
118
120
|
value: isFloat ? { kind: 'float', value } : { kind: 'dimension', value },
|
|
119
121
|
});
|
|
120
122
|
return;
|
|
121
123
|
}
|
|
122
124
|
if (typeof number !== 'number') {
|
|
123
|
-
throw at(aotError(`AOT: <Dial ${
|
|
125
|
+
throw at(aotError(`AOT: <Dial ${attribute.name.name}> must be a number (got ${JSON.stringify(number) ?? String(number)})`), attribute);
|
|
124
126
|
}
|
|
125
|
-
//
|
|
127
|
+
// floatConstant checks a float field itself; an int field needs the same check before it is rounded.
|
|
126
128
|
if (!isFloat) {
|
|
127
129
|
checkNumber(number);
|
|
128
130
|
}
|
|
129
131
|
staticAssigns.push({
|
|
130
132
|
field,
|
|
131
|
-
|
|
133
|
+
value: isFloat ? floatConstant(number) : Math.round(number),
|
|
132
134
|
});
|
|
133
135
|
};
|
|
134
|
-
// Fold static colors now; emit dynamic color expressions for
|
|
135
|
-
const colour = (field, node,
|
|
136
|
+
// Fold static colors now; emit dynamic color expressions for the update.
|
|
137
|
+
const colour = (field, node, attribute) => {
|
|
136
138
|
let color;
|
|
137
139
|
try {
|
|
138
140
|
color = evalStatic(node, scope, 'strict');
|
|
139
141
|
}
|
|
140
142
|
catch {
|
|
141
|
-
|
|
143
|
+
dynamicAssigns.push({ field, value: lowerColorValue(node, environment) });
|
|
142
144
|
return;
|
|
143
145
|
}
|
|
144
146
|
if (typeof color !== 'string') {
|
|
145
|
-
throw at(aotError(`AOT: <Dial ${
|
|
147
|
+
throw at(aotError(`AOT: <Dial ${attribute.name.name}> must be a color string (got ${JSON.stringify(color) ?? String(color)})`), attribute);
|
|
146
148
|
}
|
|
147
|
-
staticAssigns.push({ field,
|
|
149
|
+
staticAssigns.push({ field, value: parseColorValue(color) });
|
|
148
150
|
};
|
|
149
151
|
// Process <Dial> props, splitting them into static props, dynamic updates, binds, assets, and handlers.
|
|
150
|
-
let
|
|
152
|
+
let onChangeFunction = null;
|
|
151
153
|
let knobImage = null; // static asset name
|
|
152
|
-
for (const
|
|
154
|
+
for (const attribute of element.openingElement.attributes) {
|
|
153
155
|
// Ensure all props are explicit named attributes.
|
|
154
156
|
// Spread props cannot be analyzed statically
|
|
155
|
-
if (
|
|
157
|
+
if (attribute.type !== 'JSXAttribute') {
|
|
156
158
|
throw aotError('AOT: spread props on <Dial> are not supported');
|
|
157
159
|
}
|
|
158
160
|
// skip non-props
|
|
159
|
-
const name =
|
|
161
|
+
const name = attribute.name.name;
|
|
160
162
|
if (name === 'style' || name === 'ref' || name === 'key')
|
|
161
163
|
continue;
|
|
162
164
|
// process props
|
|
163
|
-
const node = attrExpr(
|
|
165
|
+
const node = attrExpr(attribute);
|
|
164
166
|
if ((name === 'value' || name === 'valueStart') &&
|
|
165
167
|
node?.type === 'Identifier' &&
|
|
166
|
-
|
|
168
|
+
environment.animations?.has(node.name)) {
|
|
167
169
|
binds.push({
|
|
168
|
-
|
|
170
|
+
slotName: environment.animations.get(node.name).slotName,
|
|
169
171
|
prop: name === 'value' ? 'ER_PROP_ARC_VALUE' : 'ER_PROP_ARC_VALUE_START',
|
|
170
172
|
});
|
|
171
173
|
}
|
|
172
174
|
else if (DIAL_FLOAT_PROPS[name]) {
|
|
173
|
-
numeric(DIAL_FLOAT_PROPS[name], node, true,
|
|
175
|
+
numeric(DIAL_FLOAT_PROPS[name], node, true, attribute);
|
|
174
176
|
}
|
|
175
177
|
else if (DIAL_INT_PROPS[name]) {
|
|
176
|
-
numeric(DIAL_INT_PROPS[name], node, false,
|
|
178
|
+
numeric(DIAL_INT_PROPS[name], node, false, attribute);
|
|
177
179
|
}
|
|
178
180
|
else if (DIAL_COLOR_PROPS[name]) {
|
|
179
|
-
colour(DIAL_COLOR_PROPS[name], node,
|
|
181
|
+
colour(DIAL_COLOR_PROPS[name], node, attribute);
|
|
180
182
|
}
|
|
181
183
|
else if (DIAL_ENUM_PROPS[name]) {
|
|
182
184
|
const { field, table } = DIAL_ENUM_PROPS[name];
|
|
@@ -191,12 +193,15 @@ export function emitDial(element, scope, out, env, state) {
|
|
|
191
193
|
if (!table[token]) {
|
|
192
194
|
throw aotError(`AOT: unsupported <Dial ${name}> "${token}"`, `${name} must be one of: ${Object.keys(table).join(' / ')}.`);
|
|
193
195
|
}
|
|
194
|
-
staticAssigns.push({ field,
|
|
196
|
+
staticAssigns.push({ field, value: table[token] });
|
|
195
197
|
}
|
|
196
198
|
else {
|
|
197
|
-
|
|
199
|
+
dynamicAssigns.push({
|
|
198
200
|
field,
|
|
199
|
-
value: {
|
|
201
|
+
value: {
|
|
202
|
+
kind: 'byte',
|
|
203
|
+
value: lowerEnumValue(node, table, environment),
|
|
204
|
+
},
|
|
200
205
|
});
|
|
201
206
|
}
|
|
202
207
|
}
|
|
@@ -205,15 +210,15 @@ export function emitDial(element, scope, out, env, state) {
|
|
|
205
210
|
try {
|
|
206
211
|
staticAssigns.push({
|
|
207
212
|
field,
|
|
208
|
-
|
|
213
|
+
value: evalStatic(node, scope, 'strict') ? 1 : 0,
|
|
209
214
|
});
|
|
210
215
|
}
|
|
211
216
|
catch {
|
|
212
|
-
|
|
217
|
+
dynamicAssigns.push({
|
|
213
218
|
field,
|
|
214
219
|
value: {
|
|
215
220
|
kind: 'flag',
|
|
216
|
-
test: lowerExpr(node,
|
|
221
|
+
test: lowerExpr(node, environment),
|
|
217
222
|
truthiness: 'value',
|
|
218
223
|
negate: false,
|
|
219
224
|
whenTrue: 1,
|
|
@@ -222,52 +227,58 @@ export function emitDial(element, scope, out, env, state) {
|
|
|
222
227
|
}
|
|
223
228
|
}
|
|
224
229
|
else if (name === 'knobImage') {
|
|
225
|
-
knobImage = imageNameFromSource(node,
|
|
230
|
+
knobImage = imageNameFromSource(node, environment);
|
|
226
231
|
if (knobImage == null) {
|
|
227
232
|
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.");
|
|
228
233
|
}
|
|
229
|
-
const path =
|
|
234
|
+
const path = environment.imageNames?.get(knobImage);
|
|
230
235
|
if (path) {
|
|
231
|
-
|
|
236
|
+
output.images.set(knobImage, path);
|
|
232
237
|
}
|
|
233
238
|
}
|
|
234
239
|
else if (name === 'indicatorGradient') {
|
|
235
240
|
// Allow indicatorGradient to be statically defined but conditionally enabled with a ternary against null/undefined.
|
|
236
|
-
let
|
|
237
|
-
let
|
|
241
|
+
let gradientNode = node;
|
|
242
|
+
let gradientCondition = null;
|
|
238
243
|
if (node?.type === 'ConditionalExpression') {
|
|
239
|
-
const nullish = (
|
|
240
|
-
(
|
|
244
|
+
const nullish = (candidate) => candidate?.type === 'NullLiteral' ||
|
|
245
|
+
(candidate?.type === 'Identifier' && candidate.name === 'undefined');
|
|
241
246
|
if (nullish(node.alternate)) {
|
|
242
|
-
|
|
243
|
-
|
|
247
|
+
gradientNode = node.consequent;
|
|
248
|
+
gradientCondition = {
|
|
249
|
+
test: lowerExpr(node.test, environment),
|
|
250
|
+
negate: false,
|
|
251
|
+
};
|
|
244
252
|
}
|
|
245
253
|
else if (nullish(node.consequent)) {
|
|
246
|
-
|
|
247
|
-
|
|
254
|
+
gradientNode = node.alternate;
|
|
255
|
+
gradientCondition = {
|
|
256
|
+
test: lowerExpr(node.test, environment),
|
|
257
|
+
negate: true,
|
|
258
|
+
};
|
|
248
259
|
}
|
|
249
260
|
}
|
|
250
261
|
// Validate and normalize the static gradient definition, keeping only the engine-supported stop count.
|
|
251
|
-
const gradient = evalStaticOrThrow(
|
|
262
|
+
const gradient = evalStaticOrThrow(gradientNode, scope, 'AOT: <Dial indicatorGradient> must be a static object (optionally behind a ternary against null)', "indicatorGradient={{ type: 'conic', stops: [{ color: '#00f' }, { color: '#f00' }] }}, or " +
|
|
252
263
|
'indicatorGradient={on ? {…} : null}');
|
|
253
264
|
const allStops = Array.isArray(gradient?.stops) ? gradient.stops : [];
|
|
254
265
|
check({ kind: 'dialGradientStops', count: allStops.length });
|
|
255
266
|
const stops = allStops.slice(0, DIAL_MAX_GRADIENT_STOPS);
|
|
256
267
|
staticAssigns.push({
|
|
257
268
|
field: 'gradient_type',
|
|
258
|
-
|
|
269
|
+
value: gradient.type === 'radial'
|
|
259
270
|
? 'ER_GRADIENT_RADIAL'
|
|
260
271
|
: 'ER_GRADIENT_CONIC',
|
|
261
272
|
});
|
|
262
273
|
// Emit the stop count separately so a ternary can enable/disable the static gradient at runtime.
|
|
263
|
-
if (
|
|
264
|
-
|
|
274
|
+
if (gradientCondition) {
|
|
275
|
+
dynamicAssigns.push({
|
|
265
276
|
field: 'gradient_stop_count',
|
|
266
277
|
value: {
|
|
267
278
|
kind: 'flag',
|
|
268
|
-
test:
|
|
279
|
+
test: gradientCondition.test,
|
|
269
280
|
truthiness: 'value',
|
|
270
|
-
negate:
|
|
281
|
+
negate: gradientCondition.negate,
|
|
271
282
|
whenTrue: stops.length,
|
|
272
283
|
},
|
|
273
284
|
});
|
|
@@ -275,24 +286,26 @@ export function emitDial(element, scope, out, env, state) {
|
|
|
275
286
|
else {
|
|
276
287
|
staticAssigns.push({
|
|
277
288
|
field: 'gradient_stop_count',
|
|
278
|
-
|
|
289
|
+
value: stops.length,
|
|
279
290
|
});
|
|
280
291
|
}
|
|
281
292
|
// Emit each fixed stop, filling in missing offsets with evenly spaced positions.
|
|
282
|
-
stops.forEach((
|
|
283
|
-
const
|
|
293
|
+
stops.forEach((stop, index) => {
|
|
294
|
+
const offset = typeof stop.offset === 'number'
|
|
295
|
+
? stop.offset
|
|
296
|
+
: index / (stops.length - 1);
|
|
284
297
|
staticAssigns.push({
|
|
285
|
-
field: `gradient_stops[${
|
|
286
|
-
|
|
298
|
+
field: `gradient_stops[${index}].color`,
|
|
299
|
+
value: parseColorValue(String(stop.color)),
|
|
287
300
|
});
|
|
288
301
|
staticAssigns.push({
|
|
289
|
-
field: `gradient_stops[${
|
|
290
|
-
|
|
302
|
+
field: `gradient_stops[${index}].position`,
|
|
303
|
+
value: floatConstant(offset),
|
|
291
304
|
});
|
|
292
305
|
});
|
|
293
306
|
}
|
|
294
307
|
else if (name === 'onChange') {
|
|
295
|
-
|
|
308
|
+
onChangeFunction = node;
|
|
296
309
|
}
|
|
297
310
|
else {
|
|
298
311
|
throw aotError(`AOT: <Dial> prop "${name}" is not supported`);
|
|
@@ -301,9 +314,10 @@ export function emitDial(element, scope, out, env, state) {
|
|
|
301
314
|
// Animated bindings: style props plus an animated `value` (ER_PROP_ARC_VALUE).
|
|
302
315
|
const node = {
|
|
303
316
|
id: nodeID,
|
|
317
|
+
location: currentLoc(),
|
|
304
318
|
type: 'ER_NODE_ARC',
|
|
305
319
|
constantProps: staticAssigns,
|
|
306
|
-
stateProps:
|
|
320
|
+
stateProps: dynamicAssigns,
|
|
307
321
|
placeholder: null,
|
|
308
322
|
text: null,
|
|
309
323
|
image: knobImage != null ? { kind: 'static', name: knobImage } : null,
|
|
@@ -312,22 +326,22 @@ export function emitDial(element, scope, out, env, state) {
|
|
|
312
326
|
wiring: binds.map((bind, index) => ({ kind: 'bind', bind, index })),
|
|
313
327
|
};
|
|
314
328
|
// Compile <Dial onChange> into an ER_EVENT_VALUE_CHANGE handler.
|
|
315
|
-
if (
|
|
329
|
+
if (onChangeFunction) {
|
|
316
330
|
// A useCallback identifier resolves to its arrow, the same way the generic host-node event path does —
|
|
317
331
|
// a dial's change handler is exactly the kind of thing an app wraps in useCallback.
|
|
318
|
-
if (
|
|
319
|
-
|
|
320
|
-
|
|
332
|
+
if (onChangeFunction.type === 'Identifier' &&
|
|
333
|
+
environment.callbacks?.has(onChangeFunction.name)) {
|
|
334
|
+
onChangeFunction = environment.callbacks.get(onChangeFunction.name);
|
|
321
335
|
}
|
|
322
336
|
// Require a function node so lowerValueHandler can bind the dial's value parameters.
|
|
323
|
-
if (!isFn(
|
|
337
|
+
if (!isFn(onChangeFunction)) {
|
|
324
338
|
throw aotError('AOT: <Dial onChange> must be an inline function or a useCallback', 'onChange={(v) => setValue(v)}');
|
|
325
339
|
}
|
|
326
|
-
const handlerName = `
|
|
327
|
-
|
|
340
|
+
const handlerName = `handler_${output.handlers.length}`;
|
|
341
|
+
output.handlers.push({
|
|
328
342
|
kind: 'callback',
|
|
329
343
|
name: handlerName,
|
|
330
|
-
callback: lowerValueHandler(
|
|
344
|
+
callback: lowerValueHandler(onChangeFunction, environment, state, output, 'float', false, { kind: 'event', field: 'value', type: FLOAT }, { kind: 'event', field: 'value_start', type: FLOAT }),
|
|
331
345
|
});
|
|
332
346
|
node.wiring.push({
|
|
333
347
|
kind: 'event',
|
|
@@ -335,10 +349,10 @@ export function emitDial(element, scope, out, env, state) {
|
|
|
335
349
|
handler: handlerName,
|
|
336
350
|
});
|
|
337
351
|
}
|
|
338
|
-
for (const slot of lowerRefBinds(element.openingElement,
|
|
352
|
+
for (const slot of lowerRefBinds(element.openingElement, environment)) {
|
|
339
353
|
node.wiring.push({ kind: 'ref', slot });
|
|
340
354
|
}
|
|
341
355
|
checkInterpolations(node);
|
|
342
|
-
node.children = emitChildren(element.children, scope,
|
|
356
|
+
node.children = emitChildren(element.children, scope, output, environment, state);
|
|
343
357
|
return node;
|
|
344
358
|
}
|
|
@@ -31,37 +31,37 @@ import { emitNode } from '../nodes.mjs';
|
|
|
31
31
|
*
|
|
32
32
|
* @param element The <FlatList>.
|
|
33
33
|
* @param scope Compile-time constants in reach.
|
|
34
|
-
* @param
|
|
35
|
-
* @param
|
|
34
|
+
* @param output Everything emitted so far.
|
|
35
|
+
* @param environment The expression environment.
|
|
36
36
|
* @param state The component's state table.
|
|
37
|
-
* @param
|
|
37
|
+
* @param options How the element is placed.
|
|
38
38
|
*
|
|
39
39
|
* @returns The variable of the <ScrollView> node it lowers to.
|
|
40
40
|
*/
|
|
41
|
-
export function emitFlatList(element, scope,
|
|
41
|
+
export function emitFlatList(element, scope, output, environment, state, options) {
|
|
42
42
|
// Collect the supported <FlatList> props, rejecting anything the AOT rewrite cannot statically lower.
|
|
43
43
|
let dataNode = null;
|
|
44
44
|
let renderItem = null;
|
|
45
|
-
let
|
|
46
|
-
for (const
|
|
45
|
+
let styleAttribute = null;
|
|
46
|
+
for (const attribute of element.openingElement.attributes) {
|
|
47
47
|
// Ensure all props are explicit named attributes.
|
|
48
48
|
// Spread props cannot be analyzed statically
|
|
49
|
-
if (
|
|
49
|
+
if (attribute.type !== 'JSXAttribute') {
|
|
50
50
|
throw aotError('AOT: spread props on <FlatList> are not supported');
|
|
51
51
|
}
|
|
52
52
|
// skip non-props
|
|
53
|
-
const name =
|
|
53
|
+
const name = attribute.name.name;
|
|
54
54
|
if (name === 'keyExtractor' || name === 'key')
|
|
55
55
|
continue;
|
|
56
56
|
// process props
|
|
57
57
|
if (name === 'data') {
|
|
58
|
-
dataNode = attrExpr(
|
|
58
|
+
dataNode = attrExpr(attribute);
|
|
59
59
|
}
|
|
60
60
|
else if (name === 'renderItem') {
|
|
61
|
-
renderItem = attrExpr(
|
|
61
|
+
renderItem = attrExpr(attribute);
|
|
62
62
|
}
|
|
63
63
|
else if (name === 'style') {
|
|
64
|
-
|
|
64
|
+
styleAttribute = attribute;
|
|
65
65
|
}
|
|
66
66
|
else {
|
|
67
67
|
throw aotError(`AOT: <FlatList> prop "${name}" is not supported`, 'supported: data, renderItem, keyExtractor, style. For headers/footers/horizontal/onEndReached etc., use <ScrollView> + .map directly.');
|
|
@@ -74,14 +74,14 @@ export function emitFlatList(element, scope, out, env, state, opts) {
|
|
|
74
74
|
if (!renderItem || !isFn(renderItem)) {
|
|
75
75
|
throw aotError('AOT: <FlatList> needs a renderItem function', 'renderItem={({ item, index }) => <Row item={item} />}');
|
|
76
76
|
}
|
|
77
|
-
const
|
|
78
|
-
if (!
|
|
77
|
+
const parameter = renderItem.params[0];
|
|
78
|
+
if (!parameter || parameter.type !== 'ObjectPattern') {
|
|
79
79
|
throw aotError('AOT: FlatList renderItem must destructure ({ item, index })', 'renderItem={({ item }) => <Row item={item} />}');
|
|
80
80
|
}
|
|
81
81
|
// Extract the local item/index names from renderItem's destructured parameter, rejecting any unsupported row fields or patterns.
|
|
82
82
|
let itemName = null;
|
|
83
83
|
let indexName = null;
|
|
84
|
-
for (const prop of
|
|
84
|
+
for (const prop of parameter.properties) {
|
|
85
85
|
if (prop.type !== 'ObjectProperty' || prop.value.type !== 'Identifier') {
|
|
86
86
|
throw aotError('AOT: FlatList renderItem may destructure only item / index (to plain names)');
|
|
87
87
|
}
|
|
@@ -95,18 +95,20 @@ export function emitFlatList(element, scope, out, env, state, opts) {
|
|
|
95
95
|
throw aotError(`AOT: FlatList renderItem cannot destructure "${prop.key.name}" (only item / index)`);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
// Ensure renderItem binds the required item value; index is optional for the
|
|
98
|
+
// Ensure renderItem binds the required item value; index is optional for the map callback.
|
|
99
99
|
if (!itemName) {
|
|
100
100
|
throw aotError('AOT: FlatList renderItem must destructure item', 'renderItem={({ item }) => …}');
|
|
101
101
|
}
|
|
102
102
|
// Rewrite renderItem `({ item, index }) => BODY` → a positional `.map` callback `(item, index) => BODY`.
|
|
103
|
-
const
|
|
103
|
+
const callbackParameters = [
|
|
104
|
+
{ type: 'Identifier', name: itemName },
|
|
105
|
+
];
|
|
104
106
|
if (indexName) {
|
|
105
|
-
|
|
107
|
+
callbackParameters.push({ type: 'Identifier', name: indexName });
|
|
106
108
|
}
|
|
107
|
-
const
|
|
109
|
+
const callback = {
|
|
108
110
|
type: 'ArrowFunctionExpression',
|
|
109
|
-
params:
|
|
111
|
+
params: callbackParameters,
|
|
110
112
|
body: renderItem.body,
|
|
111
113
|
async: false,
|
|
112
114
|
expression: renderItem.body.type !== 'BlockStatement',
|
|
@@ -119,14 +121,14 @@ export function emitFlatList(element, scope, out, env, state, opts) {
|
|
|
119
121
|
property: { type: 'Identifier', name: 'map' },
|
|
120
122
|
computed: false,
|
|
121
123
|
},
|
|
122
|
-
arguments: [
|
|
124
|
+
arguments: [callback],
|
|
123
125
|
};
|
|
124
126
|
const scrollView = {
|
|
125
127
|
type: 'JSXElement',
|
|
126
128
|
openingElement: {
|
|
127
129
|
type: 'JSXOpeningElement',
|
|
128
130
|
name: { type: 'JSXIdentifier', name: 'ScrollView' },
|
|
129
|
-
attributes:
|
|
131
|
+
attributes: styleAttribute ? [styleAttribute] : [],
|
|
130
132
|
selfClosing: false,
|
|
131
133
|
},
|
|
132
134
|
closingElement: {
|
|
@@ -135,5 +137,5 @@ export function emitFlatList(element, scope, out, env, state, opts) {
|
|
|
135
137
|
},
|
|
136
138
|
children: [{ type: 'JSXExpressionContainer', expression: mapCall }],
|
|
137
139
|
};
|
|
138
|
-
return emitNode(scrollView, scope,
|
|
140
|
+
return emitNode(scrollView, scope, output, environment, state, options);
|
|
139
141
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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 { attrExpr } from '../style-text.mjs';
|
|
20
|
+
import { emitNode } from '../nodes.mjs';
|
|
21
|
+
import { attributeOf, elementOf, literalObject, refuseSpreads, renamed, } from './rewrite.mjs';
|
|
22
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
23
|
+
- Constants
|
|
24
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
25
|
+
/** StyleSheet.absoluteFill: the image fills the container's padding box. */
|
|
26
|
+
const ABSOLUTE_FILL = {
|
|
27
|
+
position: 'absolute',
|
|
28
|
+
left: 0,
|
|
29
|
+
right: 0,
|
|
30
|
+
top: 0,
|
|
31
|
+
bottom: 0,
|
|
32
|
+
};
|
|
33
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
34
|
+
- Implementation
|
|
35
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
36
|
+
/**
|
|
37
|
+
* <ImageBackground style imageStyle imageRef …imageProps>children</ImageBackground> → the tree
|
|
38
|
+
* ImageBackground.js renders: a <View> holding an <Image> that fills it, then the children. `style` and `ref`
|
|
39
|
+
* go to the View, every other prop to the Image.
|
|
40
|
+
*
|
|
41
|
+
* @param element The <ImageBackground>, its props already checked.
|
|
42
|
+
* @param scope Compile-time constants in reach.
|
|
43
|
+
* @param output Everything emitted so far.
|
|
44
|
+
* @param environment The expression environment.
|
|
45
|
+
* @param state The component's state table.
|
|
46
|
+
* @param options How the element is placed.
|
|
47
|
+
*
|
|
48
|
+
* @returns What the <View> lowers to.
|
|
49
|
+
*/
|
|
50
|
+
export function emitImageBackground(element, scope, output, environment, state, options) {
|
|
51
|
+
refuseSpreads(element, 'ImageBackground');
|
|
52
|
+
const viewAttributes = [];
|
|
53
|
+
const imageAttributes = [];
|
|
54
|
+
const imageStyles = [literalObject(ABSOLUTE_FILL)];
|
|
55
|
+
for (const attribute of element.openingElement
|
|
56
|
+
.attributes) {
|
|
57
|
+
const name = attribute.name.name;
|
|
58
|
+
if (name === 'key')
|
|
59
|
+
continue;
|
|
60
|
+
if (name === 'style' || name === 'ref') {
|
|
61
|
+
viewAttributes.push(attribute);
|
|
62
|
+
}
|
|
63
|
+
else if (name === 'imageStyle') {
|
|
64
|
+
imageStyles.push(attrExpr(attribute));
|
|
65
|
+
}
|
|
66
|
+
else if (name === 'imageRef') {
|
|
67
|
+
imageAttributes.push(renamed(attribute, 'ref'));
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
imageAttributes.push(attribute);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
imageAttributes.push(attributeOf('style', { type: 'ArrayExpression', elements: imageStyles }));
|
|
74
|
+
const image = elementOf('Image', imageAttributes, [], element);
|
|
75
|
+
return emitNode(elementOf('View', viewAttributes, [image, ...element.children], element), scope, output, environment, state, options);
|
|
76
|
+
}
|