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
|
@@ -1,270 +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, i64Lit } from '../c-syntax.mjs';
|
|
20
|
-
import { slotOf } from '../ir/types.mjs';
|
|
21
|
-
/*----------------------------------------------------------------------------------------------------------------------
|
|
22
|
-
- Constants
|
|
23
|
-
---------------------------------------------------------------------------------------------------------------------*/
|
|
24
|
-
/** The C function each float Math function prints as. */
|
|
25
|
-
const FLOAT_MATH_C = {
|
|
26
|
-
sin: 'sinf',
|
|
27
|
-
cos: 'cosf',
|
|
28
|
-
tan: 'tanf',
|
|
29
|
-
sqrt: 'sqrtf',
|
|
30
|
-
abs: 'fabsf',
|
|
31
|
-
round: 'app_roundf',
|
|
32
|
-
floor: 'floorf',
|
|
33
|
-
ceil: 'ceilf',
|
|
34
|
-
min: 'fminf',
|
|
35
|
-
max: 'fmaxf',
|
|
36
|
-
atan2: 'atan2f',
|
|
37
|
-
pow: 'powf',
|
|
38
|
-
mod: 'fmodf',
|
|
39
|
-
};
|
|
40
|
-
/** The C function each float Math function prints as when a boot value is worked out in double precision. */
|
|
41
|
-
const DOUBLE_MATH_C = {
|
|
42
|
-
sin: 'sin',
|
|
43
|
-
cos: 'cos',
|
|
44
|
-
tan: 'tan',
|
|
45
|
-
sqrt: 'sqrt',
|
|
46
|
-
abs: 'fabs',
|
|
47
|
-
round: 'app_round',
|
|
48
|
-
floor: 'floor',
|
|
49
|
-
ceil: 'ceil',
|
|
50
|
-
min: 'fmin',
|
|
51
|
-
max: 'fmax',
|
|
52
|
-
atan2: 'atan2',
|
|
53
|
-
pow: 'pow',
|
|
54
|
-
mod: 'fmod',
|
|
55
|
-
};
|
|
56
|
-
/** The field of the engine's ERRect each onLayout field reads. */
|
|
57
|
-
const LAYOUT_RECT_C = {
|
|
58
|
-
x: 'x',
|
|
59
|
-
y: 'y',
|
|
60
|
-
width: 'w',
|
|
61
|
-
height: 'h',
|
|
62
|
-
};
|
|
63
|
-
/** The smallest C int. */
|
|
64
|
-
const INT_MIN = -(2 ** 31);
|
|
65
|
-
/** Whether a fraction prints as a double, as JS computes it, rather than a float (see printInDoubles). */
|
|
66
|
-
let inDoubles = false;
|
|
67
|
-
/*----------------------------------------------------------------------------------------------------------------------
|
|
68
|
-
- Implementation
|
|
69
|
-
---------------------------------------------------------------------------------------------------------------------*/
|
|
70
|
-
/**
|
|
71
|
-
* `expr` used as a C condition. JS treats a string as truthy when it is non-empty; a bare char[] in C tests
|
|
72
|
-
* its ADDRESS, which is always true — and real GCC refuses that under -Werror=address.
|
|
73
|
-
*
|
|
74
|
-
* @param expr The lowered expression.
|
|
75
|
-
*
|
|
76
|
-
* @returns C that is true exactly when JS would find `expr` truthy.
|
|
77
|
-
*/
|
|
78
|
-
export const asCond = (expr) => expr.cType === 'string' ? `(${expr.code}[0] != '\\0')` : expr.code;
|
|
79
|
-
/**
|
|
80
|
-
* A gestureState field. Travel is rebased onto the grant (RN's anchor); the point and the velocity come straight
|
|
81
|
-
* off the engine payload; the finger count is the engine's own, which is why er_touch_active_count() exists.
|
|
82
|
-
*
|
|
83
|
-
* @param expr The field.
|
|
84
|
-
*
|
|
85
|
-
* @returns The C expression.
|
|
86
|
-
*/
|
|
87
|
-
function printGestureField(expr) {
|
|
88
|
-
switch (expr.field) {
|
|
89
|
-
case 'dx':
|
|
90
|
-
case 'dy':
|
|
91
|
-
return `(data->${expr.field} - ${expr.statePrefix}_base_${expr.field})`;
|
|
92
|
-
case 'moveX':
|
|
93
|
-
return 'data->x';
|
|
94
|
-
case 'moveY':
|
|
95
|
-
return 'data->y';
|
|
96
|
-
case 'x0':
|
|
97
|
-
case 'y0':
|
|
98
|
-
return `${expr.statePrefix}_${expr.field}`;
|
|
99
|
-
case 'vx':
|
|
100
|
-
case 'vy':
|
|
101
|
-
return `data->${expr.field}`;
|
|
102
|
-
case 'numberActiveTouches':
|
|
103
|
-
return 'er_touch_active_count()';
|
|
104
|
-
case 'stateID':
|
|
105
|
-
return String(expr.stateID);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* A compile-time number as a C constant.
|
|
110
|
-
*
|
|
111
|
-
* @param expr The number.
|
|
112
|
-
*
|
|
113
|
-
* @returns Its C constant.
|
|
114
|
-
*/
|
|
115
|
-
function printNumber(expr) {
|
|
116
|
-
if (expr.type.kind === 'float') {
|
|
117
|
-
return inDoubles ? doubleLit(expr.value) : floatLit(expr.value);
|
|
118
|
-
}
|
|
119
|
-
if (expr.type.kind === 'int64') {
|
|
120
|
-
return i64Lit(expr.value);
|
|
121
|
-
}
|
|
122
|
-
// `-2147483648` is `-` applied to 2147483648, which does not fit an int.
|
|
123
|
-
return expr.value === INT_MIN ? '(-2147483647 - 1)' : String(expr.value);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* A number as a C double constant.
|
|
127
|
-
*
|
|
128
|
-
* @param value The number.
|
|
129
|
-
*
|
|
130
|
-
* @returns Its C constant.
|
|
131
|
-
*/
|
|
132
|
-
export const doubleLit = (value) => floatLit(value).replace(/f$/, '');
|
|
133
|
-
/**
|
|
134
|
-
* Prints with every fraction worked out in double precision, as JS works it out: a value set once at boot then
|
|
135
|
-
* rounds exactly as the compiler's own fold would have.
|
|
136
|
-
*
|
|
137
|
-
* @param print The printing.
|
|
138
|
-
*
|
|
139
|
-
* @returns What it prints.
|
|
140
|
-
*/
|
|
141
|
-
export function printInDoubles(print) {
|
|
142
|
-
const outer = inDoubles;
|
|
143
|
-
inDoubles = true;
|
|
144
|
-
try {
|
|
145
|
-
return print();
|
|
146
|
-
}
|
|
147
|
-
finally {
|
|
148
|
-
inDoubles = outer;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* An expression as a C condition (see asCond).
|
|
153
|
-
*
|
|
154
|
-
* @param expr The expression.
|
|
155
|
-
*
|
|
156
|
-
* @returns C that is true exactly when JS would find it truthy.
|
|
157
|
-
*/
|
|
158
|
-
export const printCondition = (expr) => asCond({ code: printExpr(expr), cType: slotOf(expr.type) });
|
|
159
|
-
/**
|
|
160
|
-
* The C type a fraction is worked out in.
|
|
161
|
-
*
|
|
162
|
-
* @returns `double` while printing in doubles, else `float`.
|
|
163
|
-
*/
|
|
164
|
-
const fraction = () => (inDoubles ? 'double' : 'float');
|
|
165
|
-
/**
|
|
166
|
-
* Prints an expression as C.
|
|
167
|
-
*
|
|
168
|
-
* @param expr The expression.
|
|
169
|
-
*
|
|
170
|
-
* @returns Its C.
|
|
171
|
-
*/
|
|
172
|
-
export function printExpr(expr) {
|
|
173
|
-
switch (expr.kind) {
|
|
174
|
-
case 'number':
|
|
175
|
-
return printNumber(expr);
|
|
176
|
-
case 'string':
|
|
177
|
-
return cstr(expr.value);
|
|
178
|
-
case 'boolean':
|
|
179
|
-
return expr.value ? '1' : '0';
|
|
180
|
-
case 'state':
|
|
181
|
-
return expr.state.cMember;
|
|
182
|
-
case 'boot':
|
|
183
|
-
return `s_boot.${expr.slot.field}`;
|
|
184
|
-
case 'local':
|
|
185
|
-
return expr.local.code;
|
|
186
|
-
case 'ref':
|
|
187
|
-
return expr.ref.cVar;
|
|
188
|
-
case 'listLength':
|
|
189
|
-
return expr.list.countMember;
|
|
190
|
-
case 'itemField':
|
|
191
|
-
return `${expr.item.code}.${expr.field.key}`;
|
|
192
|
-
case 'event':
|
|
193
|
-
return `data->${expr.field}`;
|
|
194
|
-
case 'layout':
|
|
195
|
-
return `data->layout_rect.${LAYOUT_RECT_C[expr.field]}`;
|
|
196
|
-
case 'clock':
|
|
197
|
-
return expr.clock === 'Date' ? 'app_date_now()' : 'app_perf_now()';
|
|
198
|
-
case 'pi':
|
|
199
|
-
return inDoubles ? 'M_PI' : '(float)M_PI';
|
|
200
|
-
case 'gesture':
|
|
201
|
-
return printGestureField(expr);
|
|
202
|
-
case 'toFloat':
|
|
203
|
-
return `((${fraction()})${printExpr(expr.operand)})`;
|
|
204
|
-
case 'unary': {
|
|
205
|
-
// The operand is parenthesized so `-` on a negative operand prints `(-(-x))`, not `(--x)` (a decrement).
|
|
206
|
-
const operand = expr.op === '!'
|
|
207
|
-
? printCondition(expr.operand)
|
|
208
|
-
: printExpr(expr.operand);
|
|
209
|
-
return `(${expr.op}(${operand}))`;
|
|
210
|
-
}
|
|
211
|
-
case 'helper':
|
|
212
|
-
return `app_${expr.helper}${expr.bits === 64 ? '64' : ''}(${expr.args.map(printExpr).join(', ')})`;
|
|
213
|
-
case 'arithmetic':
|
|
214
|
-
return `(${printExpr(expr.left)} ${expr.op} ${printExpr(expr.right)})`;
|
|
215
|
-
case 'floatDivide':
|
|
216
|
-
return `((${fraction()})(${printExpr(expr.left)}) / (${fraction()})(${printExpr(expr.right)}))`;
|
|
217
|
-
case 'narrowRemainder':
|
|
218
|
-
return `((int)(${printExpr(expr.left)} % ${printExpr(expr.right)}))`;
|
|
219
|
-
case 'floatMath': {
|
|
220
|
-
const args = expr.args.map(arg => `(${fraction()})(${printExpr(arg)})`);
|
|
221
|
-
const fn = (inDoubles ? DOUBLE_MATH_C : FLOAT_MATH_C)[expr.fn];
|
|
222
|
-
return `${fn}(${args.join(', ')})`;
|
|
223
|
-
}
|
|
224
|
-
case 'wholeRound':
|
|
225
|
-
return printExpr(expr.operand);
|
|
226
|
-
case 'trunc':
|
|
227
|
-
return inDoubles
|
|
228
|
-
? `app_d2i((double)(${printExpr(expr.operand)}))`
|
|
229
|
-
: `app_f2i((float)(${printExpr(expr.operand)}))`;
|
|
230
|
-
case 'toInt':
|
|
231
|
-
return `${inDoubles ? 'app_d2i' : 'app_f2i'}(${printExpr(expr.operand)})`;
|
|
232
|
-
case 'compare':
|
|
233
|
-
return `(${printExpr(expr.left)} ${expr.op} ${printExpr(expr.right)})`;
|
|
234
|
-
case 'stringEquals':
|
|
235
|
-
return `(strcmp(${printExpr(expr.left)}, ${printExpr(expr.right)}) ${expr.op} 0)`;
|
|
236
|
-
case 'logical':
|
|
237
|
-
return `(${printCondition(expr.left)} ${expr.op} ${printCondition(expr.right)})`;
|
|
238
|
-
case 'pick': {
|
|
239
|
-
// Reading `left` twice is safe: expressions have no side effects, and the clock only moves in er_tick().
|
|
240
|
-
const left = printExpr(expr.left);
|
|
241
|
-
const right = printExpr(expr.right);
|
|
242
|
-
return expr.op === '||'
|
|
243
|
-
? `(${left} ? ${left} : ${right})`
|
|
244
|
-
: `(${left} ? ${right} : ${left})`;
|
|
245
|
-
}
|
|
246
|
-
case 'conditional':
|
|
247
|
-
return `(${printCondition(expr.test)} ? ${printExpr(expr.consequent)} : ${printExpr(expr.alternate)})`;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* An expression as the C expression the emitters build with: its C, and what is known about its value.
|
|
252
|
-
*
|
|
253
|
-
* @param expr The expression.
|
|
254
|
-
*
|
|
255
|
-
* @returns The C expression.
|
|
256
|
-
*/
|
|
257
|
-
export function toCExpr(expr) {
|
|
258
|
-
// A bare local is the Local itself, so a list row keeps its struct (extractProps copies it into a prop).
|
|
259
|
-
if (expr.kind === 'local') {
|
|
260
|
-
return expr.local;
|
|
261
|
-
}
|
|
262
|
-
const cExpr = { code: printExpr(expr), cType: slotOf(expr.type) };
|
|
263
|
-
if (expr.type.kind === 'bool') {
|
|
264
|
-
cExpr.isBool = true;
|
|
265
|
-
}
|
|
266
|
-
else if (expr.type.kind === 'int64' && expr.type.source !== 'time') {
|
|
267
|
-
cExpr[expr.type.source === 'number' ? 'lit' : 'wide'] = true;
|
|
268
|
-
}
|
|
269
|
-
return cExpr;
|
|
270
|
-
}
|
|
@@ -1,268 +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 { cScalarType, floatLit } from '../c-syntax.mjs';
|
|
20
|
-
import { printChainFunctions, printCompletionWait } from './animations.mjs';
|
|
21
|
-
import { toCExpr } from './expressions.mjs';
|
|
22
|
-
import { printPanEvent } from './pan-responder.mjs';
|
|
23
|
-
import { APP_UPDATE_CALL, printCallback, printStmts } from './statements.mjs';
|
|
24
|
-
/*----------------------------------------------------------------------------------------------------------------------
|
|
25
|
-
- Constants
|
|
26
|
-
---------------------------------------------------------------------------------------------------------------------*/
|
|
27
|
-
const INDENT = ' ';
|
|
28
|
-
/*----------------------------------------------------------------------------------------------------------------------
|
|
29
|
-
- Implementation
|
|
30
|
-
---------------------------------------------------------------------------------------------------------------------*/
|
|
31
|
-
/**
|
|
32
|
-
* The function a dep-driven effect runs in.
|
|
33
|
-
*
|
|
34
|
-
* @param effect The effect.
|
|
35
|
-
*
|
|
36
|
-
* @returns Its name.
|
|
37
|
-
*/
|
|
38
|
-
export const effectName = (effect) => `er_effect_${effect.id}`;
|
|
39
|
-
/**
|
|
40
|
-
* The flag that says an effect's last run reached its cleanup.
|
|
41
|
-
*
|
|
42
|
-
* @param effectId The effect's id.
|
|
43
|
-
*
|
|
44
|
-
* @returns The flag's name.
|
|
45
|
-
*/
|
|
46
|
-
export const armedFlag = (effectId) => `s_eff${effectId}_armed`;
|
|
47
|
-
/**
|
|
48
|
-
* The copy an effect keeps of one dep from its last run.
|
|
49
|
-
*
|
|
50
|
-
* @param effect The effect.
|
|
51
|
-
* @param depIndex The dep's position in the list.
|
|
52
|
-
*
|
|
53
|
-
* @returns The copy's name.
|
|
54
|
-
*/
|
|
55
|
-
const depCopy = (effect, depIndex) => `s_eff${effect.id}_d${depIndex}`;
|
|
56
|
-
/**
|
|
57
|
-
* A press fade as a scoped timing animation of the node's opacity value.
|
|
58
|
-
*
|
|
59
|
-
* @param fade The fade.
|
|
60
|
-
*
|
|
61
|
-
* @returns The C lines.
|
|
62
|
-
*/
|
|
63
|
-
const printPressFade = (fade) => [
|
|
64
|
-
' {',
|
|
65
|
-
' ERAnimConfig cfg;',
|
|
66
|
-
' memset(&cfg, 0, sizeof(cfg));',
|
|
67
|
-
' cfg.type = ER_ANIM_TIMING;',
|
|
68
|
-
` cfg.duration_ms = ${fade.durationMs};`,
|
|
69
|
-
' cfg.easing = ER_EASE_QUAD_IN_OUT;',
|
|
70
|
-
` er_anim_value_animate(${fade.value}, ${floatLit(fade.opacity)}, &cfg);`,
|
|
71
|
-
' }',
|
|
72
|
-
];
|
|
73
|
-
/**
|
|
74
|
-
* An event handler as a C function.
|
|
75
|
-
*
|
|
76
|
-
* @param handler The handler.
|
|
77
|
-
*
|
|
78
|
-
* @returns The function.
|
|
79
|
-
*/
|
|
80
|
-
export function printHandler(handler) {
|
|
81
|
-
switch (handler.kind) {
|
|
82
|
-
case 'callback':
|
|
83
|
-
return { name: handler.name, body: printCallback(handler.callback) };
|
|
84
|
-
case 'pressFade':
|
|
85
|
-
return {
|
|
86
|
-
name: handler.name,
|
|
87
|
-
body: [
|
|
88
|
-
...printPressFade(handler.fade),
|
|
89
|
-
...(handler.then
|
|
90
|
-
? [` ${handler.then}(node, data, user_data);`]
|
|
91
|
-
: []),
|
|
92
|
-
],
|
|
93
|
-
};
|
|
94
|
-
case 'panEvent':
|
|
95
|
-
return printPanEvent(handler.pan, handler.event);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* A timer callback as a C function.
|
|
100
|
-
*
|
|
101
|
-
* @param timer The timer callback.
|
|
102
|
-
*
|
|
103
|
-
* @returns The function.
|
|
104
|
-
*/
|
|
105
|
-
export const printTimerFunction = (timer) => ({
|
|
106
|
-
name: timer.name,
|
|
107
|
-
body: printCallback(timer.callback),
|
|
108
|
-
});
|
|
109
|
-
/**
|
|
110
|
-
* An animation's on_complete callbacks as C functions.
|
|
111
|
-
*
|
|
112
|
-
* @param callback The callbacks.
|
|
113
|
-
*
|
|
114
|
-
* @returns The functions.
|
|
115
|
-
*/
|
|
116
|
-
export function printAnimationCallback(callback) {
|
|
117
|
-
switch (callback.kind) {
|
|
118
|
-
case 'completion':
|
|
119
|
-
return [
|
|
120
|
-
{
|
|
121
|
-
name: callback.completion.name,
|
|
122
|
-
body: printCallback(callback.completion),
|
|
123
|
-
},
|
|
124
|
-
];
|
|
125
|
-
case 'completionWait':
|
|
126
|
-
return [printCompletionWait(callback.completion, callback.wait)];
|
|
127
|
-
case 'chain':
|
|
128
|
-
return printChainFunctions(callback.chain).callbacks;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* A function an effect runs in. A dep-driven effect with a cleanup first runs the last run's cleanup, if that
|
|
133
|
-
* run armed it.
|
|
134
|
-
*
|
|
135
|
-
* @param effectFunction The function.
|
|
136
|
-
*
|
|
137
|
-
* @returns The C function.
|
|
138
|
-
*/
|
|
139
|
-
export function printEffectFunction(effectFunction) {
|
|
140
|
-
switch (effectFunction.kind) {
|
|
141
|
-
case 'effect': {
|
|
142
|
-
const { effect } = effectFunction;
|
|
143
|
-
const name = effectName(effect);
|
|
144
|
-
const body = printStmts(effect.body, INDENT);
|
|
145
|
-
if (!effect.hasCleanup) {
|
|
146
|
-
return { name, body };
|
|
147
|
-
}
|
|
148
|
-
const armed = armedFlag(effect.id);
|
|
149
|
-
return {
|
|
150
|
-
name,
|
|
151
|
-
body: [
|
|
152
|
-
` if (${armed})`,
|
|
153
|
-
' {',
|
|
154
|
-
` ${armed} = 0;`,
|
|
155
|
-
` ${name}_cleanup();`,
|
|
156
|
-
' }',
|
|
157
|
-
...body,
|
|
158
|
-
],
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
case 'cleanup':
|
|
162
|
-
return {
|
|
163
|
-
name: `${effectName(effectFunction.effect)}_cleanup`,
|
|
164
|
-
body: printStmts(effectFunction.effect.cleanup, INDENT),
|
|
165
|
-
};
|
|
166
|
-
case 'mount':
|
|
167
|
-
return {
|
|
168
|
-
name: effectFunction.name,
|
|
169
|
-
body: printStmts(effectFunction.body, INDENT),
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* The statement that copies one dep of an effect, so the next app_update() can tell whether it changed.
|
|
175
|
-
*
|
|
176
|
-
* @param effect The effect.
|
|
177
|
-
* @param depIndex The dep's position in the list.
|
|
178
|
-
*
|
|
179
|
-
* @returns The C statement, without its `;`.
|
|
180
|
-
*/
|
|
181
|
-
function printDepSnapshot(effect, depIndex) {
|
|
182
|
-
const dep = toCExpr(effect.deps[depIndex]);
|
|
183
|
-
const copy = depCopy(effect, depIndex);
|
|
184
|
-
return dep.cType === 'string'
|
|
185
|
-
? `snprintf(${copy}, sizeof(${copy}), "%s", ${dep.code})`
|
|
186
|
-
: `${copy} = ${dep.code}`;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* What er_app_build() runs for one mount effect.
|
|
190
|
-
*
|
|
191
|
-
* @param mountEffect The mount effect.
|
|
192
|
-
*
|
|
193
|
-
* @returns The C lines.
|
|
194
|
-
*/
|
|
195
|
-
export function printMountEffect(mountEffect) {
|
|
196
|
-
switch (mountEffect.kind) {
|
|
197
|
-
case 'inline':
|
|
198
|
-
return printCallback(mountEffect.callback);
|
|
199
|
-
case 'call':
|
|
200
|
-
return [
|
|
201
|
-
` ${mountEffect.name}();`,
|
|
202
|
-
...(mountEffect.updatesState ? [APP_UPDATE_CALL] : []),
|
|
203
|
-
];
|
|
204
|
-
case 'depEffect': {
|
|
205
|
-
const { effect } = mountEffect;
|
|
206
|
-
return [
|
|
207
|
-
` ${effectName(effect)}();`,
|
|
208
|
-
...effect.deps.map((_, depIndex) => ` ${printDepSnapshot(effect, depIndex)};`),
|
|
209
|
-
];
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* The app_update() block that copies each dep of an effect that changed, and runs the effect once if any did.
|
|
215
|
-
*
|
|
216
|
-
* @param effect The effect.
|
|
217
|
-
*
|
|
218
|
-
* @returns The C block.
|
|
219
|
-
*/
|
|
220
|
-
export function printDepEffectCheck(effect) {
|
|
221
|
-
const lines = [' {', ' int er_changed = 0;'];
|
|
222
|
-
effect.deps.forEach((depExpr, depIndex) => {
|
|
223
|
-
const dep = toCExpr(depExpr);
|
|
224
|
-
const copy = depCopy(effect, depIndex);
|
|
225
|
-
if (dep.cType === 'string') {
|
|
226
|
-
lines.push(` if (strcmp(${copy}, ${dep.code}) != 0) { ` +
|
|
227
|
-
`${printDepSnapshot(effect, depIndex)}; er_changed = 1; }`);
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
const cType = cScalarType(dep.cType);
|
|
231
|
-
lines.push(` ${cType} er_d${depIndex} = ${dep.code}; if (er_d${depIndex} != ` +
|
|
232
|
-
`${copy}) { ${copy} = er_d${depIndex}; ` +
|
|
233
|
-
`er_changed = 1; }`);
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
lines.push(` if (er_changed) ${effectName(effect)}();`, ' }');
|
|
237
|
-
return lines.join('\n');
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* A file-scope variable that effects and animation chains keep between calls.
|
|
241
|
-
*
|
|
242
|
-
* @param decl The variable.
|
|
243
|
-
* @param stringCap The size of a string buffer.
|
|
244
|
-
*
|
|
245
|
-
* @returns The C declarations.
|
|
246
|
-
*/
|
|
247
|
-
export function printStaticDecl(decl, stringCap) {
|
|
248
|
-
switch (decl.kind) {
|
|
249
|
-
case 'local':
|
|
250
|
-
return [
|
|
251
|
-
decl.cType === 'string'
|
|
252
|
-
? `static char ${decl.name}[${stringCap}];`
|
|
253
|
-
: `static ${cScalarType(decl.cType)} ${decl.name};`,
|
|
254
|
-
];
|
|
255
|
-
case 'armed':
|
|
256
|
-
return [`static int ${armedFlag(decl.effect.id)};`];
|
|
257
|
-
case 'deps':
|
|
258
|
-
return decl.effect.deps.map((depExpr, depIndex) => {
|
|
259
|
-
const copy = depCopy(decl.effect, depIndex);
|
|
260
|
-
const { cType } = toCExpr(depExpr);
|
|
261
|
-
return cType === 'string'
|
|
262
|
-
? `static char ${copy}[${stringCap}];`
|
|
263
|
-
: `static ${cScalarType(cType)} ${copy};`;
|
|
264
|
-
});
|
|
265
|
-
case 'chain':
|
|
266
|
-
return printChainFunctions(decl.chain).decls;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
@@ -1,96 +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 } 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
|
-
}
|