embedded-react 0.15.0 → 0.17.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/aot/compile.mjs +173 -8272
- package/aot/compiler/animations.mjs +1001 -0
- package/aot/compiler/assemble.mjs +922 -0
- package/aot/compiler/boot.mjs +441 -0
- package/aot/compiler/branch-merge.mjs +319 -0
- package/aot/compiler/c/animations.mjs +362 -0
- package/aot/compiler/c/boot.mjs +127 -0
- package/aot/compiler/c/expressions.mjs +270 -0
- package/aot/compiler/c/functions.mjs +268 -0
- package/aot/compiler/c/keyboard.mjs +96 -0
- package/aot/compiler/c/nodes.mjs +294 -0
- package/aot/compiler/c/pan-responder.mjs +136 -0
- package/aot/compiler/c/statements.mjs +271 -0
- package/aot/compiler/c/text.mjs +83 -0
- package/aot/compiler/c/vectors.mjs +381 -0
- package/aot/compiler/c-syntax.mjs +127 -0
- package/aot/compiler/check.mjs +165 -0
- package/aot/compiler/collect.mjs +785 -0
- package/aot/compiler/control-flow.mjs +696 -0
- package/aot/compiler/diagnostics.mjs +137 -0
- package/aot/compiler/elements/activity-indicator.mjs +160 -0
- package/aot/compiler/elements/dial.mjs +346 -0
- package/aot/compiler/elements/flat-list.mjs +139 -0
- package/aot/compiler/elements/image.mjs +151 -0
- package/aot/compiler/elements/modal.mjs +158 -0
- package/aot/compiler/elements/props.mjs +474 -0
- package/aot/compiler/elements/switch.mjs +183 -0
- package/aot/compiler/elements/text-input.mjs +171 -0
- package/aot/compiler/expressions.mjs +1579 -0
- package/aot/compiler/handlers.mjs +1072 -0
- package/aot/compiler/ir/animations.mjs +16 -0
- package/aot/compiler/ir/app.mjs +16 -0
- package/aot/compiler/ir/boot.mjs +16 -0
- package/aot/compiler/ir/expressions.mjs +16 -0
- package/aot/compiler/ir/functions.mjs +16 -0
- package/aot/compiler/ir/keyboard.mjs +16 -0
- package/aot/compiler/ir/nodes.mjs +107 -0
- package/aot/compiler/ir/pan-responder.mjs +16 -0
- package/aot/compiler/ir/reads.mjs +351 -0
- package/aot/compiler/ir/source.mjs +16 -0
- package/aot/compiler/ir/statements.mjs +16 -0
- package/aot/compiler/ir/text.mjs +16 -0
- package/aot/compiler/ir/types.mjs +185 -0
- package/aot/compiler/ir/vectors.mjs +16 -0
- package/aot/compiler/keyboard.mjs +152 -0
- package/aot/compiler/lower.mjs +311 -0
- package/aot/compiler/nodes.mjs +688 -0
- package/aot/compiler/options.mjs +55 -0
- package/aot/compiler/out.mjs +94 -0
- package/aot/compiler/pan-responder.mjs +354 -0
- package/aot/compiler/parse.mjs +300 -0
- package/aot/compiler/static-eval.mjs +454 -0
- package/aot/compiler/style-text.mjs +807 -0
- package/aot/compiler/svg.mjs +1167 -0
- package/aot/compiler/types.mjs +16 -0
- package/aot/screenshot-smoke.mjs +95 -55
- package/aot/style-map.mjs +366 -304
- package/cli.mjs +5 -8
- package/package.json +14 -6
- package/sim/embedded-react.wasm +0 -0
- package/src/embedded-react/FlatList.js +4 -4
- package/src/props.js +1 -1
|
@@ -0,0 +1,96 @@
|
|
|
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 { cstr } from '../c-syntax.mjs';
|
|
20
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
21
|
+
- Constants
|
|
22
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
23
|
+
/** Key kind → its ERKeyboardKey type. */
|
|
24
|
+
const KEY_TYPES = {
|
|
25
|
+
char: 'ER_KBD_KEY_CHAR',
|
|
26
|
+
layer: 'ER_KBD_KEY_LAYER',
|
|
27
|
+
backspace: 'ER_KBD_KEY_BACKSPACE',
|
|
28
|
+
done: 'ER_KBD_KEY_DONE',
|
|
29
|
+
};
|
|
30
|
+
/** The highlight layer that means "never highlighted". */
|
|
31
|
+
const NEVER_HIGHLIGHTED = 255;
|
|
32
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
33
|
+
- Implementation
|
|
34
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
35
|
+
/**
|
|
36
|
+
* An ARGB color as a C literal, or the engine's "use default" 0.
|
|
37
|
+
*
|
|
38
|
+
* @param color The color, or null.
|
|
39
|
+
*
|
|
40
|
+
* @returns The C.
|
|
41
|
+
*/
|
|
42
|
+
const colorOrDefault = (color) => color == null
|
|
43
|
+
? '0'
|
|
44
|
+
: '0x' + color.toString(16).padStart(8, '0').toUpperCase() + 'u';
|
|
45
|
+
/**
|
|
46
|
+
* A size, or the engine's "use default" 0.
|
|
47
|
+
*
|
|
48
|
+
* @param size The size, or null.
|
|
49
|
+
*
|
|
50
|
+
* @returns The C.
|
|
51
|
+
*/
|
|
52
|
+
const sizeOrDefault = (size) => size == null ? '0' : String(size);
|
|
53
|
+
/**
|
|
54
|
+
* One key as an ERKeyboardKey initializer.
|
|
55
|
+
*
|
|
56
|
+
* @param key The key.
|
|
57
|
+
*
|
|
58
|
+
* @returns The C.
|
|
59
|
+
*/
|
|
60
|
+
const printKey = (key) => `{ ${key.label == null ? 'NULL' : cstr(key.label)}, ${key.text == null ? 'NULL' : cstr(key.text)}, ` +
|
|
61
|
+
`${KEY_TYPES[key.kind]}, ${key.layer}, ${key.span}, ${key.highlightLayer ?? NEVER_HIGHLIGHTED} }`;
|
|
62
|
+
/**
|
|
63
|
+
* A keyboard config as static C tables (a key table per row, a row table per layer, the layer table, and the
|
|
64
|
+
* ERKeyboardConfig) and the er_app_build() line that installs it.
|
|
65
|
+
*
|
|
66
|
+
* @param keyboard The config.
|
|
67
|
+
*
|
|
68
|
+
* @returns The tables and the setup line.
|
|
69
|
+
*/
|
|
70
|
+
export function printKeyboard(keyboard) {
|
|
71
|
+
const tables = [];
|
|
72
|
+
let layersExpr = 'NULL';
|
|
73
|
+
if (keyboard.layers) {
|
|
74
|
+
const layerInits = keyboard.layers.map((layer, layerIndex) => {
|
|
75
|
+
const rowInits = layer.map((row, rowIndex) => {
|
|
76
|
+
const name = `kbd_l${layerIndex}r${rowIndex}`;
|
|
77
|
+
tables.push(`static const ERKeyboardKey ${name}[] = { ${row.map(printKey).join(', ')} };`);
|
|
78
|
+
return `{ ${name}, ${row.length} }`;
|
|
79
|
+
});
|
|
80
|
+
tables.push(`static const ERKeyboardRow kbd_l${layerIndex}rows[] = { ${rowInits.join(', ')} };`);
|
|
81
|
+
return `{ kbd_l${layerIndex}rows, ${layer.length} }`;
|
|
82
|
+
});
|
|
83
|
+
tables.push(`static const ERKeyboardLayer kbd_layers[] = { ${layerInits.join(', ')} };`);
|
|
84
|
+
layersExpr = 'kbd_layers';
|
|
85
|
+
}
|
|
86
|
+
tables.push(`static const ERKeyboardConfig kbd_cfg = { ${layersExpr}, ${keyboard.layers?.length ?? 0}, ` +
|
|
87
|
+
`${sizeOrDefault(keyboard.gridCols)}, ${sizeOrDefault(keyboard.rowHeight)}, ` +
|
|
88
|
+
`${sizeOrDefault(keyboard.keyGap)}, ${sizeOrDefault(keyboard.keyRadius)}, ` +
|
|
89
|
+
`${sizeOrDefault(keyboard.fontSize)}, ${colorOrDefault(keyboard.panelColor)}, ` +
|
|
90
|
+
`${colorOrDefault(keyboard.keyColor)}, ` +
|
|
91
|
+
`${colorOrDefault(keyboard.keyActiveColor)}, ${colorOrDefault(keyboard.labelColor)} };`);
|
|
92
|
+
return {
|
|
93
|
+
data: tables.join('\n'),
|
|
94
|
+
setup: ' er_keyboard_set_config(&kbd_cfg);',
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -0,0 +1,294 @@
|
|
|
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 { cstr, floatLit } from '../c-syntax.mjs';
|
|
20
|
+
import { printCondition, printExpr } from './expressions.mjs';
|
|
21
|
+
import { panEventName, panQueryName } from './pan-responder.mjs';
|
|
22
|
+
import { printText } from './text.mjs';
|
|
23
|
+
import { printStateDrivenVectorWiring, printVectorOps } from './vectors.mjs';
|
|
24
|
+
import { branchElements, hasRuntimeProps, isStateDriven } from '../ir/nodes.mjs';
|
|
25
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
26
|
+
- Implementation
|
|
27
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
28
|
+
/**
|
|
29
|
+
* The C condition a conditional's node shows under.
|
|
30
|
+
*
|
|
31
|
+
* @param show The condition.
|
|
32
|
+
*
|
|
33
|
+
* @returns The C.
|
|
34
|
+
*/
|
|
35
|
+
export function printShow(show) {
|
|
36
|
+
if (show.kind === 'rowInUse') {
|
|
37
|
+
return `(${show.row} < ${show.list.countMember})`;
|
|
38
|
+
}
|
|
39
|
+
const test = printCondition(show.test);
|
|
40
|
+
const shown = show.negate ? `!(${test})` : test;
|
|
41
|
+
return show.within ? `((${printShow(show.within)}) && (${shown}))` : shown;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A state-driven prop value as the C written to its ERProps field.
|
|
45
|
+
*
|
|
46
|
+
* @param value The value.
|
|
47
|
+
*
|
|
48
|
+
* @returns The C.
|
|
49
|
+
*/
|
|
50
|
+
export function printPropValue(value) {
|
|
51
|
+
switch (value.kind) {
|
|
52
|
+
case 'constant':
|
|
53
|
+
return value.code;
|
|
54
|
+
case 'select':
|
|
55
|
+
return (`((${printCondition(value.test)}) ? ${printPropValue(value.whenTrue)} : ` +
|
|
56
|
+
`${printPropValue(value.whenFalse)})`);
|
|
57
|
+
case 'opacity':
|
|
58
|
+
return `app_opacity(${printExpr(value.value)})`;
|
|
59
|
+
case 'dimension':
|
|
60
|
+
return `app_round_dim(${printExpr(value.value)})`;
|
|
61
|
+
case 'visible':
|
|
62
|
+
return `((${printExpr(value.value)}) ? ER_DISPLAY_FLEX : ER_DISPLAY_NONE)`;
|
|
63
|
+
case 'shown':
|
|
64
|
+
return `((${printShow(value.show)}) ? ER_DISPLAY_FLEX : ER_DISPLAY_NONE)`;
|
|
65
|
+
case 'whileShown':
|
|
66
|
+
return `((${printShow(value.show)}) ? ${printPropValue(value.value)} : 0)`;
|
|
67
|
+
case 'flag': {
|
|
68
|
+
const test = value.truthiness === 'condition'
|
|
69
|
+
? printCondition(value.test)
|
|
70
|
+
: printExpr(value.test);
|
|
71
|
+
return `(uint8_t)((${value.negate ? `!(${test})` : test}) ? ${value.whenTrue} : 0)`;
|
|
72
|
+
}
|
|
73
|
+
case 'byte':
|
|
74
|
+
return `(uint8_t)(${printPropValue(value.value)})`;
|
|
75
|
+
case 'float':
|
|
76
|
+
return `(float)(${printExpr(value.value)})`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* An animated value's bind onto a node; an interpolated one first declares its table. The Dial lays its table
|
|
81
|
+
* out one field per line.
|
|
82
|
+
*
|
|
83
|
+
* @param node The node.
|
|
84
|
+
* @param bind The bind.
|
|
85
|
+
* @param index Numbers the table within the node.
|
|
86
|
+
*
|
|
87
|
+
* @returns The C lines.
|
|
88
|
+
*/
|
|
89
|
+
function printBind(node, bind, index) {
|
|
90
|
+
if (!bind.interp) {
|
|
91
|
+
return [` er_anim_value_bind(${bind.cVar}, ${node.id}, ${bind.prop});`];
|
|
92
|
+
}
|
|
93
|
+
const interp = bind.interp;
|
|
94
|
+
const name = `interp_${node.id}_${index}`;
|
|
95
|
+
const input = interp.input.map(floatLit).join(', ');
|
|
96
|
+
const output = interp.output.map(floatLit).join(', ');
|
|
97
|
+
const table = node.type === 'ER_NODE_ARC'
|
|
98
|
+
? [
|
|
99
|
+
` static const ERInterpolation ${name} = {`,
|
|
100
|
+
` { ${input} },`,
|
|
101
|
+
` { ${output} },`,
|
|
102
|
+
` ${interp.input.length},`,
|
|
103
|
+
` ${interp.exLeft},`,
|
|
104
|
+
` ${interp.exRight}`,
|
|
105
|
+
` };`,
|
|
106
|
+
]
|
|
107
|
+
: [
|
|
108
|
+
` static const ERInterpolation ${name} = { { ${input} }, { ${output} }, ` +
|
|
109
|
+
`${interp.input.length}, ${interp.exLeft}, ${interp.exRight} };`,
|
|
110
|
+
];
|
|
111
|
+
return [
|
|
112
|
+
` {`,
|
|
113
|
+
...table,
|
|
114
|
+
` er_anim_value_bind_interpolated(${bind.cVar}, ${node.id}, ${bind.prop}, &${name});`,
|
|
115
|
+
` }`,
|
|
116
|
+
];
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Wires a PanResponder's handlers and queries onto a node.
|
|
120
|
+
*
|
|
121
|
+
* @param pan The responder.
|
|
122
|
+
* @param nodeId The node's variable.
|
|
123
|
+
*
|
|
124
|
+
* @returns The C lines.
|
|
125
|
+
*/
|
|
126
|
+
export function printPanWiring(pan, nodeId) {
|
|
127
|
+
return [
|
|
128
|
+
...pan.events.map(event => ` er_event_set(${nodeId}, ${event.event}, ${panEventName(pan, event)}, NULL);`),
|
|
129
|
+
...pan.queries.map(query => ` er_responder_query_set(${nodeId}, ${query.query}, ${panQueryName(pan, query)}, NULL);`),
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* A node as C. A node with no state-driven content sets its props once; otherwise it keeps a handle and
|
|
134
|
+
* app_update() sets them all again. Spans and the node's wiring are set up once.
|
|
135
|
+
*
|
|
136
|
+
* @param node The node.
|
|
137
|
+
*
|
|
138
|
+
* @returns Its build lines and app_update() entry.
|
|
139
|
+
*/
|
|
140
|
+
export function printNode(node) {
|
|
141
|
+
const { id } = node;
|
|
142
|
+
const text = node.text ? printText(node.text) : null;
|
|
143
|
+
const imageName = node.image?.kind === 'value'
|
|
144
|
+
? printExpr(node.image.value)
|
|
145
|
+
: node.image?.resetOnUpdate
|
|
146
|
+
? cstr(node.image.name)
|
|
147
|
+
: null;
|
|
148
|
+
const build = [` ${id} = er_node_create(${node.type});`];
|
|
149
|
+
let update = null;
|
|
150
|
+
if (isStateDriven(node)) {
|
|
151
|
+
build.push(` s_${id} = ${id};`);
|
|
152
|
+
update = {
|
|
153
|
+
nodeId: id,
|
|
154
|
+
styleAssigns: node.constantProps,
|
|
155
|
+
text,
|
|
156
|
+
dynAssigns: node.stateProps,
|
|
157
|
+
imageName,
|
|
158
|
+
placeholder: node.placeholder,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
else if (hasRuntimeProps(node)) {
|
|
162
|
+
// Props that read-only values worked out at boot are set once, here.
|
|
163
|
+
build.push(...printNodeUpdate({
|
|
164
|
+
nodeId: id,
|
|
165
|
+
styleAssigns: node.constantProps,
|
|
166
|
+
text,
|
|
167
|
+
dynAssigns: node.stateProps,
|
|
168
|
+
imageName: node.image?.kind === 'static' ? cstr(node.image.name) : imageName,
|
|
169
|
+
placeholder: node.placeholder,
|
|
170
|
+
}, id));
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
build.push(` er_props_default(&p);`);
|
|
174
|
+
for (const prop of node.constantProps) {
|
|
175
|
+
build.push(` p.${prop.field} = ${prop.expr};`);
|
|
176
|
+
}
|
|
177
|
+
if (node.placeholder != null) {
|
|
178
|
+
build.push(` snprintf(p.placeholder, sizeof(p.placeholder), "%s", ${cstr(node.placeholder)});`);
|
|
179
|
+
}
|
|
180
|
+
if (text) {
|
|
181
|
+
build.push(` snprintf(p.text, sizeof(p.text), "%s", ${cstr(text.format.replace(/%%/g, '%'))});`);
|
|
182
|
+
}
|
|
183
|
+
if (node.image?.kind === 'static') {
|
|
184
|
+
build.push(` snprintf(p.image_name, sizeof(p.image_name), "%s", ${cstr(node.image.name)});`);
|
|
185
|
+
}
|
|
186
|
+
build.push(` er_node_set_props(${id}, &p);`);
|
|
187
|
+
}
|
|
188
|
+
// Inline text spans are set once; each inherits the node's base style unless it overrides it.
|
|
189
|
+
if (node.spans) {
|
|
190
|
+
build.push(` {`, ` static const ERTextSpan spans_${id}[] = {`);
|
|
191
|
+
for (const span of node.spans) {
|
|
192
|
+
build.push(` { ${span.text}, ${span.color}, ${span.font_size}, ${span.font_weight}, ` +
|
|
193
|
+
`${span.font_style}, ${span.text_decoration}, ${span.letter_spacing} },`);
|
|
194
|
+
}
|
|
195
|
+
build.push(` };`, ` er_node_set_text_spans(${id}, spans_${id}, ${node.spans.length});`, ` }`);
|
|
196
|
+
}
|
|
197
|
+
// Binds, refs, events and PanResponders, in the order the element wires them.
|
|
198
|
+
for (const wire of node.wiring) {
|
|
199
|
+
switch (wire.kind) {
|
|
200
|
+
case 'bind':
|
|
201
|
+
build.push(...printBind(node, wire.bind, wire.index));
|
|
202
|
+
break;
|
|
203
|
+
case 'ref':
|
|
204
|
+
build.push(` ${wire.slot} = ${id};`);
|
|
205
|
+
break;
|
|
206
|
+
case 'event':
|
|
207
|
+
build.push(` er_event_set(${id}, ${wire.event}, ${wire.handler}, NULL);`);
|
|
208
|
+
break;
|
|
209
|
+
case 'responder':
|
|
210
|
+
build.push(...printPanWiring(wire.pan, id));
|
|
211
|
+
break;
|
|
212
|
+
case 'vectorTables':
|
|
213
|
+
build.push(...printVectorOps(id, wire.tables));
|
|
214
|
+
break;
|
|
215
|
+
case 'stateDrivenVector':
|
|
216
|
+
build.push(...printStateDrivenVectorWiring(id, wire.vector));
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return { build, update };
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Appends a built element to its container.
|
|
224
|
+
*
|
|
225
|
+
* @param parentId The container's variable.
|
|
226
|
+
* @param child The element.
|
|
227
|
+
*
|
|
228
|
+
* @returns The C line.
|
|
229
|
+
*/
|
|
230
|
+
export const printAppend = (parentId, child) => ` er_tree_append_child(${parentId}, ${child.id});`;
|
|
231
|
+
/**
|
|
232
|
+
* An element and everything under it as er_app_build() lines: each node, then each child's subtree followed by
|
|
233
|
+
* the line that appends it.
|
|
234
|
+
*
|
|
235
|
+
* @param element The element.
|
|
236
|
+
*
|
|
237
|
+
* @returns The C lines.
|
|
238
|
+
*/
|
|
239
|
+
export function printElementTree(element) {
|
|
240
|
+
if (element.kind === 'component') {
|
|
241
|
+
return printElementTree(element.root);
|
|
242
|
+
}
|
|
243
|
+
const lines = printNode(element.node).build;
|
|
244
|
+
const appendChild = (child) => {
|
|
245
|
+
if (child) {
|
|
246
|
+
lines.push(...printElementTree(child), printAppend(element.id, child));
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
for (const child of element.node.children) {
|
|
250
|
+
if (child.kind === 'element') {
|
|
251
|
+
appendChild(child.element);
|
|
252
|
+
}
|
|
253
|
+
else if (child.kind === 'conditional') {
|
|
254
|
+
branchElements(child).forEach(appendChild);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
child.rows.forEach(appendChild);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return lines;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* A state-driven node's app_update() entry: its props built again, then set.
|
|
264
|
+
*
|
|
265
|
+
* @param update The node's entry.
|
|
266
|
+
* @param target The node's variable: its file-scope handle, unless er_app_build() sets it.
|
|
267
|
+
*
|
|
268
|
+
* @returns The C lines.
|
|
269
|
+
*/
|
|
270
|
+
export function printNodeUpdate(update, target = `s_${update.nodeId}`) {
|
|
271
|
+
const lines = [` er_props_default(&p);`];
|
|
272
|
+
for (const assign of update.styleAssigns) {
|
|
273
|
+
lines.push(` p.${assign.field} = ${assign.expr};`);
|
|
274
|
+
}
|
|
275
|
+
for (const assign of update.dynAssigns) {
|
|
276
|
+
lines.push(` p.${assign.field} = ${printPropValue(assign.value)};`);
|
|
277
|
+
}
|
|
278
|
+
if (update.placeholder != null) {
|
|
279
|
+
lines.push(` snprintf(p.placeholder, sizeof(p.placeholder), "%s", ${cstr(update.placeholder)});`);
|
|
280
|
+
}
|
|
281
|
+
if (update.imageName != null) {
|
|
282
|
+
lines.push(` snprintf(p.image_name, sizeof(p.image_name), "%s", ${update.imageName});`);
|
|
283
|
+
}
|
|
284
|
+
if (update.text) {
|
|
285
|
+
if (update.text.args.length) {
|
|
286
|
+
lines.push(` snprintf(p.text, sizeof(p.text), ${cstr(update.text.format)}, ${update.text.args.join(', ')});`);
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
lines.push(` snprintf(p.text, sizeof(p.text), "%s", ${cstr(update.text.format.replace(/%%/g, '%'))});`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
lines.push(` er_node_set_props(${target}, &p);`);
|
|
293
|
+
return lines;
|
|
294
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
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 { printExpr } from './expressions.mjs';
|
|
20
|
+
import { printCallback } from './statements.mjs';
|
|
21
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
22
|
+
- Constants
|
|
23
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
24
|
+
/** Query constant → the suffix of the C function emitted for it. */
|
|
25
|
+
const QUERY_SUFFIX = {
|
|
26
|
+
ER_QUERY_START_SHOULD_SET: 'start_should_set',
|
|
27
|
+
ER_QUERY_START_SHOULD_SET_CAPTURE: 'start_should_set_capture',
|
|
28
|
+
ER_QUERY_MOVE_SHOULD_SET: 'move_should_set',
|
|
29
|
+
ER_QUERY_MOVE_SHOULD_SET_CAPTURE: 'move_should_set_capture',
|
|
30
|
+
ER_QUERY_TERMINATION_REQUEST: 'termination_request',
|
|
31
|
+
};
|
|
32
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
33
|
+
- Implementation
|
|
34
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
35
|
+
/**
|
|
36
|
+
* The C function that handles one of a responder's events.
|
|
37
|
+
*
|
|
38
|
+
* @param pan The responder.
|
|
39
|
+
* @param event The event.
|
|
40
|
+
*
|
|
41
|
+
* @returns The function's name.
|
|
42
|
+
*/
|
|
43
|
+
export const panEventName = (pan, event) => `${pan.fnPrefix}_${event.role}`;
|
|
44
|
+
/**
|
|
45
|
+
* The C function that answers one of a responder's should-set queries.
|
|
46
|
+
*
|
|
47
|
+
* @param pan The responder.
|
|
48
|
+
* @param query The query.
|
|
49
|
+
*
|
|
50
|
+
* @returns The function's name.
|
|
51
|
+
*/
|
|
52
|
+
export const panQueryName = (pan, query) => `${pan.fnPrefix}_${QUERY_SUFFIX[query.query]}`;
|
|
53
|
+
/**
|
|
54
|
+
* A responder's file-scope gesture state: whether the gesture is granted, the anchor, and RN's x0/y0.
|
|
55
|
+
*
|
|
56
|
+
* @param pan The responder.
|
|
57
|
+
*
|
|
58
|
+
* @returns The C declarations.
|
|
59
|
+
*/
|
|
60
|
+
export function printPanDecls(pan) {
|
|
61
|
+
const prefix = pan.statePrefix;
|
|
62
|
+
return [
|
|
63
|
+
`/* PanResponder "${pan.name}" (gesture ${pan.stateID}) — RN's gestureState. The grant anchors the`,
|
|
64
|
+
` travel so g.dx opens at 0 however much slop the claim cost; data->dx runs from touch-down. */`,
|
|
65
|
+
`static int ${prefix}_granted = 0;`,
|
|
66
|
+
`static int ${prefix}_base_dx = 0;`,
|
|
67
|
+
`static int ${prefix}_base_dy = 0;`,
|
|
68
|
+
`static int ${prefix}_x0 = 0;`,
|
|
69
|
+
`static int ${prefix}_y0 = 0;`,
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* One responder event's C handler: the gesture bookkeeping its role needs around the app's callback.
|
|
74
|
+
*
|
|
75
|
+
* @param pan The responder.
|
|
76
|
+
* @param event The event.
|
|
77
|
+
*
|
|
78
|
+
* @returns The C function.
|
|
79
|
+
*/
|
|
80
|
+
export function printPanEvent(pan, event) {
|
|
81
|
+
const prefix = pan.statePrefix;
|
|
82
|
+
const callback = event.callback ? printCallback(event.callback) : [];
|
|
83
|
+
const grantedGuard = [
|
|
84
|
+
` if (!${prefix}_granted)`,
|
|
85
|
+
' {',
|
|
86
|
+
' return;',
|
|
87
|
+
' }',
|
|
88
|
+
];
|
|
89
|
+
let body;
|
|
90
|
+
switch (event.role) {
|
|
91
|
+
case 'grant':
|
|
92
|
+
body = [
|
|
93
|
+
` if (${prefix}_granted)`,
|
|
94
|
+
' {',
|
|
95
|
+
' return; /* a second finger re-granted this node: one gesture, not two */',
|
|
96
|
+
' }',
|
|
97
|
+
` ${prefix}_granted = 1;`,
|
|
98
|
+
` ${prefix}_base_dx = data->dx;`,
|
|
99
|
+
` ${prefix}_base_dy = data->dy;`,
|
|
100
|
+
` ${prefix}_x0 = data->x;`,
|
|
101
|
+
` ${prefix}_y0 = data->y;`,
|
|
102
|
+
...callback,
|
|
103
|
+
];
|
|
104
|
+
break;
|
|
105
|
+
case 'release':
|
|
106
|
+
case 'terminate':
|
|
107
|
+
// The callback runs while g.dx's anchor is still valid; the gesture is cleared after it.
|
|
108
|
+
body = [
|
|
109
|
+
...grantedGuard,
|
|
110
|
+
...callback,
|
|
111
|
+
` ${prefix}_granted = 0;`,
|
|
112
|
+
` ${prefix}_base_dx = 0;`,
|
|
113
|
+
` ${prefix}_base_dy = 0;`,
|
|
114
|
+
];
|
|
115
|
+
break;
|
|
116
|
+
case 'move':
|
|
117
|
+
body = [...grantedGuard, ...callback];
|
|
118
|
+
break;
|
|
119
|
+
case 'reject':
|
|
120
|
+
body = callback;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
return { name: panEventName(pan, event), body };
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* A should-set query as the C function the engine calls: its name and its condition.
|
|
127
|
+
*
|
|
128
|
+
* @param pan The responder.
|
|
129
|
+
* @param query The query.
|
|
130
|
+
*
|
|
131
|
+
* @returns The query function.
|
|
132
|
+
*/
|
|
133
|
+
export const printPanQuery = (pan, query) => ({
|
|
134
|
+
name: panQueryName(pan, query),
|
|
135
|
+
expr: `(${printExpr(query.test)}) != 0`,
|
|
136
|
+
});
|