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.
- package/README.md +7 -3
- package/aot/compile.mjs +178 -58
- package/aot/compiler/animations.mjs +290 -281
- package/aot/compiler/boot.mjs +70 -33
- package/aot/compiler/branch-merge.mjs +4 -3
- package/aot/compiler/check.mjs +9 -9
- package/aot/compiler/collect.mjs +324 -205
- package/aot/compiler/control-flow.mjs +209 -197
- package/aot/compiler/diagnostics.mjs +22 -25
- package/aot/compiler/elements/activity-indicator.mjs +25 -24
- package/aot/compiler/elements/dial.mjs +91 -77
- package/aot/compiler/elements/flat-list.mjs +24 -22
- package/aot/compiler/elements/image.mjs +51 -50
- package/aot/compiler/elements/modal.mjs +31 -30
- package/aot/compiler/elements/props.mjs +23 -23
- package/aot/compiler/elements/switch.mjs +42 -34
- package/aot/compiler/elements/text-input.mjs +34 -32
- package/aot/compiler/expressions.mjs +372 -333
- package/aot/compiler/handlers.mjs +473 -387
- package/aot/compiler/ir/functions.mjs +11 -1
- package/aot/compiler/ir/nodes.mjs +4 -4
- package/aot/compiler/ir/reads.mjs +19 -19
- package/aot/compiler/ir/types.mjs +14 -14
- package/aot/compiler/ir/vectors.mjs +5 -1
- package/aot/compiler/keyboard.mjs +17 -7
- package/aot/compiler/lower.mjs +77 -80
- package/aot/compiler/nodes.mjs +169 -152
- package/aot/compiler/options.mjs +35 -30
- package/aot/compiler/out.mjs +18 -22
- package/aot/compiler/package/animations.mjs +669 -0
- package/aot/compiler/package/arena.mjs +252 -0
- package/aot/compiler/package/assemble.mjs +177 -0
- package/aot/compiler/package/bytecode.mjs +286 -0
- package/aot/compiler/package/checks.mjs +1022 -0
- package/aot/compiler/package/codegen.mjs +1329 -0
- package/aot/compiler/package/enums.mjs +138 -0
- package/aot/compiler/package/format.mjs +760 -0
- package/aot/compiler/package/layouts.mjs +136 -0
- package/aot/compiler/package/lower.mjs +1606 -0
- package/aot/compiler/package/props.mjs +118 -0
- package/aot/compiler/package/tables.mjs +103 -0
- package/aot/compiler/package/vectors.mjs +502 -0
- package/aot/compiler/package/writer.mjs +664 -0
- package/aot/compiler/pan-responder.mjs +69 -61
- package/aot/compiler/parse.mjs +21 -21
- package/aot/compiler/static-eval.mjs +25 -23
- package/aot/compiler/style-text.mjs +161 -172
- package/aot/compiler/svg.mjs +477 -251
- package/aot/screenshot-smoke.mjs +54 -40
- package/aot/style-map.mjs +102 -90
- 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 +14 -12
- package/cli.mjs +359 -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 +46 -37
- 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 +28 -20
- 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 +101 -82
- package/src/embedded-react/Animated.js +24 -24
- 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 +6 -6
- package/src/embedded-react/StyleSheet.js +4 -3
- package/src/embedded-react/TouchableOpacity.js +13 -8
- package/src/embedded-react/index.d.ts +5 -5
- 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/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
package/aot/compiler/c/nodes.mjs
DELETED
|
@@ -1,303 +0,0 @@
|
|
|
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 { printStringWrite } from './statements.mjs';
|
|
23
|
-
import { formatArgs, printText } from './text.mjs';
|
|
24
|
-
import { printStateDrivenVectorWiring, printVectorOps } from './vectors.mjs';
|
|
25
|
-
import { branchElements, hasRuntimeProps, isStateDriven } from '../ir/nodes.mjs';
|
|
26
|
-
/*----------------------------------------------------------------------------------------------------------------------
|
|
27
|
-
- Implementation
|
|
28
|
-
---------------------------------------------------------------------------------------------------------------------*/
|
|
29
|
-
/**
|
|
30
|
-
* The C condition a conditional's node shows under.
|
|
31
|
-
*
|
|
32
|
-
* @param show The condition.
|
|
33
|
-
*
|
|
34
|
-
* @returns The C.
|
|
35
|
-
*/
|
|
36
|
-
export function printShow(show) {
|
|
37
|
-
if (show.kind === 'rowInUse') {
|
|
38
|
-
return `(${show.row} < ${show.list.countMember})`;
|
|
39
|
-
}
|
|
40
|
-
const test = printCondition(show.test);
|
|
41
|
-
const shown = show.negate ? `!(${test})` : test;
|
|
42
|
-
return show.within ? `((${printShow(show.within)}) && (${shown}))` : shown;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* A state-driven prop value as the C written to its ERProps field.
|
|
46
|
-
*
|
|
47
|
-
* @param value The value.
|
|
48
|
-
*
|
|
49
|
-
* @returns The C.
|
|
50
|
-
*/
|
|
51
|
-
export function printPropValue(value) {
|
|
52
|
-
switch (value.kind) {
|
|
53
|
-
case 'constant':
|
|
54
|
-
return value.code;
|
|
55
|
-
case 'select':
|
|
56
|
-
return (`((${printCondition(value.test)}) ? ${printPropValue(value.whenTrue)} : ` +
|
|
57
|
-
`${printPropValue(value.whenFalse)})`);
|
|
58
|
-
case 'opacity':
|
|
59
|
-
return `app_opacity(${printExpr(value.value)})`;
|
|
60
|
-
case 'dimension':
|
|
61
|
-
return `app_round_dim(${printExpr(value.value)})`;
|
|
62
|
-
case 'visible':
|
|
63
|
-
return `((${printExpr(value.value)}) ? ER_DISPLAY_FLEX : ER_DISPLAY_NONE)`;
|
|
64
|
-
case 'shown':
|
|
65
|
-
return `((${printShow(value.show)}) ? ER_DISPLAY_FLEX : ER_DISPLAY_NONE)`;
|
|
66
|
-
case 'whileShown':
|
|
67
|
-
return `((${printShow(value.show)}) ? ${printPropValue(value.value)} : 0)`;
|
|
68
|
-
case 'flag': {
|
|
69
|
-
const test = value.truthiness === 'condition'
|
|
70
|
-
? printCondition(value.test)
|
|
71
|
-
: printExpr(value.test);
|
|
72
|
-
return `(uint8_t)((${value.negate ? `!(${test})` : test}) ? ${value.whenTrue} : 0)`;
|
|
73
|
-
}
|
|
74
|
-
case 'byte':
|
|
75
|
-
return `(uint8_t)(${printPropValue(value.value)})`;
|
|
76
|
-
case 'float':
|
|
77
|
-
return `(float)(${printExpr(value.value)})`;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* An animated value's bind onto a node; an interpolated one first declares its table. The Dial lays its table
|
|
82
|
-
* out one field per line.
|
|
83
|
-
*
|
|
84
|
-
* @param node The node.
|
|
85
|
-
* @param bind The bind.
|
|
86
|
-
* @param index Numbers the table within the node.
|
|
87
|
-
*
|
|
88
|
-
* @returns The C lines.
|
|
89
|
-
*/
|
|
90
|
-
function printBind(node, bind, index) {
|
|
91
|
-
if (!bind.interp) {
|
|
92
|
-
return [` er_anim_value_bind(${bind.cVar}, ${node.id}, ${bind.prop});`];
|
|
93
|
-
}
|
|
94
|
-
const interp = bind.interp;
|
|
95
|
-
const name = `interp_${node.id}_${index}`;
|
|
96
|
-
const input = interp.input.map(floatLit).join(', ');
|
|
97
|
-
if (interp.colors) {
|
|
98
|
-
const colors = interp.colors
|
|
99
|
-
.map(c => `0x${c.toString(16).padStart(8, '0').toUpperCase()}u`)
|
|
100
|
-
.join(', ');
|
|
101
|
-
return [
|
|
102
|
-
` {`,
|
|
103
|
-
` static const ERColorInterpolation ${name} = { { ${input} }, { ${colors} }, ` +
|
|
104
|
-
`${interp.input.length}, ${interp.exLeft}, ${interp.exRight} };`,
|
|
105
|
-
` er_anim_value_bind_color(${bind.cVar}, ${node.id}, ${bind.prop}, &${name});`,
|
|
106
|
-
` }`,
|
|
107
|
-
];
|
|
108
|
-
}
|
|
109
|
-
const output = interp.output.map(floatLit).join(', ');
|
|
110
|
-
const table = node.type === 'ER_NODE_ARC'
|
|
111
|
-
? [
|
|
112
|
-
` static const ERInterpolation ${name} = {`,
|
|
113
|
-
` { ${input} },`,
|
|
114
|
-
` { ${output} },`,
|
|
115
|
-
` ${interp.input.length},`,
|
|
116
|
-
` ${interp.exLeft},`,
|
|
117
|
-
` ${interp.exRight}`,
|
|
118
|
-
` };`,
|
|
119
|
-
]
|
|
120
|
-
: [
|
|
121
|
-
` static const ERInterpolation ${name} = { { ${input} }, { ${output} }, ` +
|
|
122
|
-
`${interp.input.length}, ${interp.exLeft}, ${interp.exRight} };`,
|
|
123
|
-
];
|
|
124
|
-
return [
|
|
125
|
-
` {`,
|
|
126
|
-
...table,
|
|
127
|
-
` er_anim_value_bind_interpolated(${bind.cVar}, ${node.id}, ${bind.prop}, &${name});`,
|
|
128
|
-
` }`,
|
|
129
|
-
];
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Wires a PanResponder's handlers and queries onto a node.
|
|
133
|
-
*
|
|
134
|
-
* @param pan The responder.
|
|
135
|
-
* @param nodeId The node's variable.
|
|
136
|
-
*
|
|
137
|
-
* @returns The C lines.
|
|
138
|
-
*/
|
|
139
|
-
export function printPanWiring(pan, nodeId) {
|
|
140
|
-
return [
|
|
141
|
-
...pan.events.map(event => ` er_event_set(${nodeId}, ${event.event}, ${panEventName(pan, event)}, NULL);`),
|
|
142
|
-
...pan.queries.map(query => ` er_responder_query_set(${nodeId}, ${query.query}, ${panQueryName(pan, query)}, NULL);`),
|
|
143
|
-
];
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* A node as C. A node with no state-driven content sets its props once; otherwise it keeps a handle and
|
|
147
|
-
* app_update() sets them all again. Spans and the node's wiring are set up once.
|
|
148
|
-
*
|
|
149
|
-
* @param node The node.
|
|
150
|
-
*
|
|
151
|
-
* @returns Its build lines and app_update() entry.
|
|
152
|
-
*/
|
|
153
|
-
export function printNode(node) {
|
|
154
|
-
const { id } = node;
|
|
155
|
-
const text = node.text ? printText(node.text) : null;
|
|
156
|
-
const imageName = node.image?.kind === 'value'
|
|
157
|
-
? printExpr(node.image.value)
|
|
158
|
-
: node.image
|
|
159
|
-
? cstr(node.image.name)
|
|
160
|
-
: null;
|
|
161
|
-
const build = [` ${id} = app_node_create(${node.type});`];
|
|
162
|
-
let update = null;
|
|
163
|
-
if (isStateDriven(node)) {
|
|
164
|
-
build.push(` s_${id} = ${id};`);
|
|
165
|
-
update = {
|
|
166
|
-
nodeId: id,
|
|
167
|
-
styleAssigns: node.constantProps,
|
|
168
|
-
text,
|
|
169
|
-
dynAssigns: node.stateProps,
|
|
170
|
-
imageName,
|
|
171
|
-
placeholder: node.placeholder,
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
else if (hasRuntimeProps(node)) {
|
|
175
|
-
// Props that read-only values worked out at boot are set once, here.
|
|
176
|
-
build.push(...printNodeUpdate({
|
|
177
|
-
nodeId: id,
|
|
178
|
-
styleAssigns: node.constantProps,
|
|
179
|
-
text,
|
|
180
|
-
dynAssigns: node.stateProps,
|
|
181
|
-
imageName,
|
|
182
|
-
placeholder: node.placeholder,
|
|
183
|
-
}, id));
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
build.push(` er_props_default(&p);`);
|
|
187
|
-
for (const prop of node.constantProps) {
|
|
188
|
-
build.push(` p.${prop.field} = ${prop.expr};`);
|
|
189
|
-
}
|
|
190
|
-
if (node.placeholder != null) {
|
|
191
|
-
build.push(` snprintf(p.placeholder, sizeof(p.placeholder), "%s", ${cstr(node.placeholder)});`);
|
|
192
|
-
}
|
|
193
|
-
if (text) {
|
|
194
|
-
build.push(` snprintf(p.text, sizeof(p.text), "%s", ${cstr(text.format.replace(/%%/g, '%'))});`);
|
|
195
|
-
}
|
|
196
|
-
if (node.image?.kind === 'static') {
|
|
197
|
-
build.push(` snprintf(p.image_name, sizeof(p.image_name), "%s", ${cstr(node.image.name)});`);
|
|
198
|
-
}
|
|
199
|
-
build.push(` er_node_set_props(${id}, &p);`);
|
|
200
|
-
}
|
|
201
|
-
// Inline text spans are set once; each inherits the node's base style unless it overrides it.
|
|
202
|
-
if (node.spans) {
|
|
203
|
-
build.push(` {`, ` static const ERTextSpan spans_${id}[] = {`);
|
|
204
|
-
for (const span of node.spans) {
|
|
205
|
-
build.push(` { ${span.text}, ${span.color}, ${span.font_size}, ${span.font_weight}, ` +
|
|
206
|
-
`${span.font_style}, ${span.text_decoration}, ${span.letter_spacing} },`);
|
|
207
|
-
}
|
|
208
|
-
build.push(` };`, ` er_node_set_text_spans(${id}, spans_${id}, ${node.spans.length});`, ` }`);
|
|
209
|
-
}
|
|
210
|
-
// Binds, refs, events and PanResponders, in the order the element wires them.
|
|
211
|
-
for (const wire of node.wiring) {
|
|
212
|
-
switch (wire.kind) {
|
|
213
|
-
case 'bind':
|
|
214
|
-
build.push(...printBind(node, wire.bind, wire.index));
|
|
215
|
-
break;
|
|
216
|
-
case 'ref':
|
|
217
|
-
build.push(` ${wire.slot} = ${id};`);
|
|
218
|
-
break;
|
|
219
|
-
case 'event':
|
|
220
|
-
build.push(` er_event_set(${id}, ${wire.event}, ${wire.handler}, NULL);`);
|
|
221
|
-
break;
|
|
222
|
-
case 'responder':
|
|
223
|
-
build.push(...printPanWiring(wire.pan, id));
|
|
224
|
-
break;
|
|
225
|
-
case 'vectorTables':
|
|
226
|
-
build.push(...printVectorOps(id, wire.tables));
|
|
227
|
-
break;
|
|
228
|
-
case 'stateDrivenVector':
|
|
229
|
-
build.push(...printStateDrivenVectorWiring(id, wire.vector));
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return { build, update };
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Appends a built element to its container.
|
|
237
|
-
*
|
|
238
|
-
* @param parentId The container's variable.
|
|
239
|
-
* @param child The element.
|
|
240
|
-
*
|
|
241
|
-
* @returns The C line.
|
|
242
|
-
*/
|
|
243
|
-
export const printAppend = (parentId, child) => ` er_tree_append_child(${parentId}, ${child.id});`;
|
|
244
|
-
/**
|
|
245
|
-
* An element and everything under it as er_app_build() lines: each node, then each child's subtree followed by
|
|
246
|
-
* the line that appends it.
|
|
247
|
-
*
|
|
248
|
-
* @param element The element.
|
|
249
|
-
*
|
|
250
|
-
* @returns The C lines.
|
|
251
|
-
*/
|
|
252
|
-
export function printElementTree(element) {
|
|
253
|
-
if (element.kind === 'component') {
|
|
254
|
-
return printElementTree(element.root);
|
|
255
|
-
}
|
|
256
|
-
const lines = printNode(element.node).build;
|
|
257
|
-
const appendChild = (child) => {
|
|
258
|
-
if (child) {
|
|
259
|
-
lines.push(...printElementTree(child), printAppend(element.id, child));
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
for (const child of element.node.children) {
|
|
263
|
-
if (child.kind === 'element') {
|
|
264
|
-
appendChild(child.element);
|
|
265
|
-
}
|
|
266
|
-
else if (child.kind === 'conditional') {
|
|
267
|
-
branchElements(child).forEach(appendChild);
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
child.rows.forEach(appendChild);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
return lines;
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* A state-driven node's app_update() entry: its props built again, then set.
|
|
277
|
-
*
|
|
278
|
-
* @param update The node's entry.
|
|
279
|
-
* @param target The node's variable: its file-scope handle, unless er_app_build() sets it.
|
|
280
|
-
*
|
|
281
|
-
* @returns The C lines.
|
|
282
|
-
*/
|
|
283
|
-
export function printNodeUpdate(update, target = `s_${update.nodeId}`) {
|
|
284
|
-
const lines = [` er_props_default(&p);`];
|
|
285
|
-
for (const assign of update.styleAssigns) {
|
|
286
|
-
lines.push(` p.${assign.field} = ${assign.expr};`);
|
|
287
|
-
}
|
|
288
|
-
for (const assign of update.dynAssigns) {
|
|
289
|
-
lines.push(` p.${assign.field} = ${printPropValue(assign.value)};`);
|
|
290
|
-
}
|
|
291
|
-
if (update.placeholder != null) {
|
|
292
|
-
lines.push(` snprintf(p.placeholder, sizeof(p.placeholder), "%s", ${cstr(update.placeholder)});`);
|
|
293
|
-
}
|
|
294
|
-
// A static image name was checked at compile time; one from state is checked here.
|
|
295
|
-
if (update.imageName != null) {
|
|
296
|
-
lines.push(...printStringWrite('p.image_name', `"%s", ${update.imageName}`, update.imageName.startsWith('"'), 'image name cut short at ER_IMAGE_NAME_MAX', ' '));
|
|
297
|
-
}
|
|
298
|
-
if (update.text) {
|
|
299
|
-
lines.push(...printStringWrite('p.text', formatArgs(update.text), !update.text.args.length, 'text cut short at ER_TEXT_MAX', ' '));
|
|
300
|
-
}
|
|
301
|
-
lines.push(` er_node_set_props(${target}, &p);`);
|
|
302
|
-
return lines;
|
|
303
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
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
|
-
});
|