embedded-react 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/aot/compile.mjs +173 -8272
- package/aot/compiler/animations.mjs +1001 -0
- package/aot/compiler/assemble.mjs +806 -0
- package/aot/compiler/c/animations.mjs +362 -0
- package/aot/compiler/c/expressions.mjs +215 -0
- package/aot/compiler/c/functions.mjs +268 -0
- package/aot/compiler/c/keyboard.mjs +96 -0
- package/aot/compiler/c/nodes.mjs +282 -0
- package/aot/compiler/c/pan-responder.mjs +136 -0
- package/aot/compiler/c/statements.mjs +242 -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 +743 -0
- package/aot/compiler/control-flow.mjs +683 -0
- package/aot/compiler/diagnostics.mjs +137 -0
- package/aot/compiler/elements/activity-indicator.mjs +160 -0
- package/aot/compiler/elements/dial.mjs +343 -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 +1479 -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/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 +83 -0
- package/aot/compiler/ir/pan-responder.mjs +16 -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 +282 -0
- package/aot/compiler/nodes.mjs +683 -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 +228 -0
- package/aot/compiler/style-text.mjs +648 -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,16 @@
|
|
|
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
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
- Implementation
|
|
18
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
|
+
/**
|
|
20
|
+
* Whether state drives any of a node's props, text or image, so it keeps a handle and app_update() sets its
|
|
21
|
+
* props again.
|
|
22
|
+
*
|
|
23
|
+
* @param node The node.
|
|
24
|
+
*
|
|
25
|
+
* @returns True when state drives it.
|
|
26
|
+
*/
|
|
27
|
+
export const isStateDriven = (node) => (node.text?.parts.some(part => part.kind !== 'literal') ?? false) ||
|
|
28
|
+
node.stateProps.length > 0 ||
|
|
29
|
+
node.image?.kind === 'value';
|
|
30
|
+
/**
|
|
31
|
+
* The drawing state drives on a node, if it has one.
|
|
32
|
+
*
|
|
33
|
+
* @param node The node.
|
|
34
|
+
*
|
|
35
|
+
* @returns The drawing, or null.
|
|
36
|
+
*/
|
|
37
|
+
export function stateDrivenVectorOf(node) {
|
|
38
|
+
for (const wire of node.wiring) {
|
|
39
|
+
if (wire.kind === 'stateDrivenVector') {
|
|
40
|
+
return wire.vector;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Every node under an element, each before its children, in the order er_app_build() creates them.
|
|
47
|
+
*
|
|
48
|
+
* @param element The element.
|
|
49
|
+
*
|
|
50
|
+
* @returns The nodes.
|
|
51
|
+
*/
|
|
52
|
+
export function nodesOf(element) {
|
|
53
|
+
if (element.kind === 'component') {
|
|
54
|
+
return nodesOf(element.root);
|
|
55
|
+
}
|
|
56
|
+
const nodes = [element.node];
|
|
57
|
+
for (const child of element.node.children) {
|
|
58
|
+
if (child.kind === 'element') {
|
|
59
|
+
nodes.push(...nodesOf(child.element));
|
|
60
|
+
}
|
|
61
|
+
else if (child.kind === 'conditional') {
|
|
62
|
+
nodes.push(...branchElements(child).flatMap(nodesOf));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
nodes.push(...child.rows.flatMap(nodesOf));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return nodes;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The elements a conditional builds, in source order: every branch, nested conditionals included.
|
|
72
|
+
*
|
|
73
|
+
* @param conditional The conditional.
|
|
74
|
+
*
|
|
75
|
+
* @returns The elements.
|
|
76
|
+
*/
|
|
77
|
+
export function branchElements(conditional) {
|
|
78
|
+
return [conditional.whenTrue, conditional.whenFalse].flatMap(branch => branch == null
|
|
79
|
+
? []
|
|
80
|
+
: branch.kind === 'conditional'
|
|
81
|
+
? branchElements(branch)
|
|
82
|
+
: [branch]);
|
|
83
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export {};
|
|
@@ -0,0 +1,185 @@
|
|
|
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
|
+
- Constants
|
|
18
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
|
+
export const BOOL = { kind: 'bool' };
|
|
20
|
+
export const INT = { kind: 'int' };
|
|
21
|
+
export const FLOAT = { kind: 'float' };
|
|
22
|
+
export const STRING = { kind: 'string' };
|
|
23
|
+
export const TIME = { kind: 'int64', source: 'time' };
|
|
24
|
+
export const INT64_NUMBER = { kind: 'int64', source: 'number' };
|
|
25
|
+
export const INT64_MATH = { kind: 'int64', source: 'math' };
|
|
26
|
+
export const STRUCT = { kind: 'struct' };
|
|
27
|
+
export const NODE = { kind: 'node' };
|
|
28
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
29
|
+
- Implementation
|
|
30
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
31
|
+
/**
|
|
32
|
+
* The slot a value of a type is stored in: a boolean in an int, every 64-bit number in an int64. A list row's
|
|
33
|
+
* item has none: it is read through its fields.
|
|
34
|
+
*
|
|
35
|
+
* @param type The type.
|
|
36
|
+
*
|
|
37
|
+
* @returns The slot's kind, or undefined for a list row's item.
|
|
38
|
+
*/
|
|
39
|
+
export function slotOf(type) {
|
|
40
|
+
switch (type.kind) {
|
|
41
|
+
case 'bool':
|
|
42
|
+
return 'int';
|
|
43
|
+
case 'int64':
|
|
44
|
+
return 'i64';
|
|
45
|
+
case 'struct':
|
|
46
|
+
return undefined;
|
|
47
|
+
case 'node':
|
|
48
|
+
return 'ERNode*'; // a handle, which no number or text slot holds
|
|
49
|
+
default:
|
|
50
|
+
return type.kind;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The type of a 64-bit number from a source.
|
|
55
|
+
*
|
|
56
|
+
* @param source Where it comes from.
|
|
57
|
+
*
|
|
58
|
+
* @returns The type.
|
|
59
|
+
*/
|
|
60
|
+
export const int64Of = (source) => source === 'time' ? TIME : source === 'number' ? INT64_NUMBER : INT64_MATH;
|
|
61
|
+
/**
|
|
62
|
+
* The type of a value whose slot is known: a boolean when it holds one, a time when it is a 64-bit slot.
|
|
63
|
+
*
|
|
64
|
+
* @param slot The slot's kind.
|
|
65
|
+
* @param isBool The value is a JS boolean.
|
|
66
|
+
*
|
|
67
|
+
* @returns The type.
|
|
68
|
+
*/
|
|
69
|
+
export function typeOfSlot(slot, isBool = false) {
|
|
70
|
+
if (isBool) {
|
|
71
|
+
if (slot !== 'int') {
|
|
72
|
+
throw new Error(`AOT internal: a boolean in a "${slot}" slot`);
|
|
73
|
+
}
|
|
74
|
+
return BOOL;
|
|
75
|
+
}
|
|
76
|
+
switch (slot) {
|
|
77
|
+
case 'int':
|
|
78
|
+
return INT;
|
|
79
|
+
case 'float':
|
|
80
|
+
return FLOAT;
|
|
81
|
+
case 'string':
|
|
82
|
+
return STRING;
|
|
83
|
+
case 'i64':
|
|
84
|
+
return TIME;
|
|
85
|
+
case undefined:
|
|
86
|
+
return STRUCT;
|
|
87
|
+
}
|
|
88
|
+
// Only a node ref's handle, cast to a slot, reaches here.
|
|
89
|
+
return NODE;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The type of a value lowered to C: its slot, and what the C form records about it.
|
|
93
|
+
*
|
|
94
|
+
* @param value The lowered value.
|
|
95
|
+
*
|
|
96
|
+
* @returns The type.
|
|
97
|
+
*/
|
|
98
|
+
export function typeOfCExpr(value) {
|
|
99
|
+
if (value.lit || value.wide) {
|
|
100
|
+
if (value.cType !== 'i64' || (value.lit && value.wide)) {
|
|
101
|
+
throw new Error('AOT internal: a 64-bit source on a value that is not one 64-bit number');
|
|
102
|
+
}
|
|
103
|
+
return value.lit ? INT64_NUMBER : INT64_MATH;
|
|
104
|
+
}
|
|
105
|
+
return typeOfSlot(value.cType, value.isBool);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Whether a value is a time: a 64-bit number computed at runtime from a clock.
|
|
109
|
+
*
|
|
110
|
+
* @param type The value's type.
|
|
111
|
+
*
|
|
112
|
+
* @returns True for a time.
|
|
113
|
+
*/
|
|
114
|
+
export const isTime = (type) => type.kind === 'int64' && type.source === 'time';
|
|
115
|
+
/**
|
|
116
|
+
* Whether a value is a JS boolean.
|
|
117
|
+
*
|
|
118
|
+
* @param type The value's type.
|
|
119
|
+
*
|
|
120
|
+
* @returns True for a boolean.
|
|
121
|
+
*/
|
|
122
|
+
export const isBoolean = (type) => type.kind === 'bool';
|
|
123
|
+
/**
|
|
124
|
+
* Whether a value is a 64-bit number that is not a time (a number past the int range, or whole-number math),
|
|
125
|
+
* which converts to float like any other number.
|
|
126
|
+
*
|
|
127
|
+
* @param type The value's type.
|
|
128
|
+
*
|
|
129
|
+
* @returns True for such a number.
|
|
130
|
+
*/
|
|
131
|
+
export const isConvertible64 = (type) => type.kind === 'int64' && type.source !== 'time';
|
|
132
|
+
/**
|
|
133
|
+
* Whether a value is stored in an int: an int, or a boolean.
|
|
134
|
+
*
|
|
135
|
+
* @param type The value's type.
|
|
136
|
+
*
|
|
137
|
+
* @returns True for an int slot.
|
|
138
|
+
*/
|
|
139
|
+
export const isIntSlot = (type) => type.kind === 'int' || type.kind === 'bool';
|
|
140
|
+
/**
|
|
141
|
+
* The type of a 64-bit value picked from several (a ternary's branches, the operands of `&&` / `||`): a time
|
|
142
|
+
* when any of them is one, a number when every 64-bit one is, whole-number math otherwise.
|
|
143
|
+
*
|
|
144
|
+
* @param types The types it is picked from.
|
|
145
|
+
*
|
|
146
|
+
* @returns The picked value's type.
|
|
147
|
+
*/
|
|
148
|
+
export function int64Join(...types) {
|
|
149
|
+
const sources = types.flatMap(type => type.kind === 'int64' ? [type.source] : []);
|
|
150
|
+
if (sources.includes('time'))
|
|
151
|
+
return TIME;
|
|
152
|
+
return sources.every(source => source === 'number')
|
|
153
|
+
? INT64_NUMBER
|
|
154
|
+
: INT64_MATH;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* The type of a 64-bit slot: a time, unless it only ever holds 64-bit numbers that are not times.
|
|
158
|
+
*
|
|
159
|
+
* @param widened What the slot was widened to hold, if it was.
|
|
160
|
+
*
|
|
161
|
+
* @returns The type of a read of the slot.
|
|
162
|
+
*/
|
|
163
|
+
const wideSlotType = (widened) => widened === 'number' ? INT64_NUMBER : TIME;
|
|
164
|
+
/**
|
|
165
|
+
* The type of a scalar state's value.
|
|
166
|
+
*
|
|
167
|
+
* @param state The state.
|
|
168
|
+
*
|
|
169
|
+
* @returns Its type.
|
|
170
|
+
*/
|
|
171
|
+
export const stateType = (state) => state.cType === 'i64'
|
|
172
|
+
? wideSlotType(state.widened)
|
|
173
|
+
: typeOfSlot(state.cType, state.isBool);
|
|
174
|
+
/**
|
|
175
|
+
* The type of a ref's current value.
|
|
176
|
+
*
|
|
177
|
+
* @param ref The ref.
|
|
178
|
+
*
|
|
179
|
+
* @returns A node handle for a node ref, the value's type otherwise.
|
|
180
|
+
*/
|
|
181
|
+
export const refType = (ref) => ref.kind === 'node'
|
|
182
|
+
? NODE
|
|
183
|
+
: ref.cType === 'i64'
|
|
184
|
+
? wideSlotType(ref.widened)
|
|
185
|
+
: typeOfSlot(ref.cType);
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export {};
|
|
@@ -0,0 +1,152 @@
|
|
|
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 { parseColor } from '../../src/embedded-react/svg-ops.js';
|
|
20
|
+
import { aotError } from './diagnostics.mjs';
|
|
21
|
+
import { evalStatic } from './static-eval.mjs';
|
|
22
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
23
|
+
- Implementation
|
|
24
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
25
|
+
/**
|
|
26
|
+
* A keyboard-config color as ARGB; null when the config leaves it out (the engine's default).
|
|
27
|
+
*
|
|
28
|
+
* @param color The color, if the config gives one.
|
|
29
|
+
*
|
|
30
|
+
* @returns The color, or null.
|
|
31
|
+
*/
|
|
32
|
+
const kbdColor = (color) => color == null ? null : parseColor(String(color)) >>> 0;
|
|
33
|
+
/**
|
|
34
|
+
* A keyboard-config size, rounded; null when the config leaves it out (the engine's default).
|
|
35
|
+
*
|
|
36
|
+
* @param size The size, if the config gives one.
|
|
37
|
+
*
|
|
38
|
+
* @returns The size, or null.
|
|
39
|
+
*/
|
|
40
|
+
const kbdSize = (size) => size == null ? null : Math.round(Number(size));
|
|
41
|
+
/**
|
|
42
|
+
* Lowers one JS keyboard key object. A key marked `highlight` (e.g., shift) is drawn highlighted while its own
|
|
43
|
+
* layer is showing. Shapes: { char } (types it), { char:' ', span } (space), { label, layer } (switch),
|
|
44
|
+
* { label, backspace }, { label, done }; optional span / highlight.
|
|
45
|
+
*
|
|
46
|
+
* @param key The key's config object.
|
|
47
|
+
* @param layerIndex The index of the layer the key is on.
|
|
48
|
+
*
|
|
49
|
+
* @returns The key.
|
|
50
|
+
*/
|
|
51
|
+
function lowerKey(key, layerIndex) {
|
|
52
|
+
if (key == null || typeof key !== 'object') {
|
|
53
|
+
throw aotError('AOT: each setKeyboardConfig key must be an object', 'e.g. { char: "q" } or { label: "shift", layer: 1, highlight: true }');
|
|
54
|
+
}
|
|
55
|
+
// Work out the key's kind from the one action field it carries, with that kind's default label.
|
|
56
|
+
let kind;
|
|
57
|
+
let label;
|
|
58
|
+
let text = null;
|
|
59
|
+
let layer = 0;
|
|
60
|
+
if (key.backspace) {
|
|
61
|
+
kind = 'backspace';
|
|
62
|
+
label = key.label ?? '<';
|
|
63
|
+
}
|
|
64
|
+
else if (key.done) {
|
|
65
|
+
kind = 'done';
|
|
66
|
+
label = key.label ?? 'OK';
|
|
67
|
+
}
|
|
68
|
+
else if (key.layer != null) {
|
|
69
|
+
kind = 'layer';
|
|
70
|
+
label = key.label ?? '';
|
|
71
|
+
layer = Math.round(Number(key.layer));
|
|
72
|
+
}
|
|
73
|
+
else if (key.char != null) {
|
|
74
|
+
kind = 'char';
|
|
75
|
+
text = String(key.char);
|
|
76
|
+
label = key.label ?? (String(key.char) === ' ' ? '' : String(key.char)); // a space bar shows no label
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
throw aotError('AOT: a setKeyboardConfig key needs one of char / layer / backspace / done');
|
|
80
|
+
}
|
|
81
|
+
// Span defaults to one grid column.
|
|
82
|
+
return {
|
|
83
|
+
kind,
|
|
84
|
+
label: label === '' ? null : String(label),
|
|
85
|
+
text,
|
|
86
|
+
layer,
|
|
87
|
+
span: key.span != null ? Math.round(Number(key.span)) : 1,
|
|
88
|
+
highlightLayer: key.highlight ? layerIndex : null,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Lowers a module-level `setKeyboardConfig({...})`, which customizes the on-screen keyboard (colors/sizes, and
|
|
93
|
+
* optionally a full layout) from the app with no engine edit. The config must be statically foldable; omit
|
|
94
|
+
* `layers` to keep the built-in QWERTY.
|
|
95
|
+
*
|
|
96
|
+
* @param program The parsed module.
|
|
97
|
+
*
|
|
98
|
+
* @returns The config, or null when the module has none.
|
|
99
|
+
*/
|
|
100
|
+
export function lowerKeyboardConfig(program) {
|
|
101
|
+
// Find the first top-level setKeyboardConfig(...) call; without one, the built-in keyboard stays as is.
|
|
102
|
+
let configArg = null;
|
|
103
|
+
for (const statement of program.body) {
|
|
104
|
+
if (statement.type === 'ExpressionStatement' &&
|
|
105
|
+
statement.expression.type === 'CallExpression' &&
|
|
106
|
+
statement.expression.callee.type === 'Identifier' &&
|
|
107
|
+
statement.expression.callee.name === 'setKeyboardConfig') {
|
|
108
|
+
configArg = statement.expression.arguments[0];
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!configArg)
|
|
113
|
+
return null;
|
|
114
|
+
// Fold the config object at compile time.
|
|
115
|
+
let config;
|
|
116
|
+
try {
|
|
117
|
+
config = evalStatic(configArg, {});
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
throw aotError('AOT: setKeyboardConfig(...) needs a statically-foldable config object', 'pass an object literal of colors/sizes (+ an optional `layers` array) — no state or runtime values.');
|
|
121
|
+
}
|
|
122
|
+
if (config == null || typeof config !== 'object') {
|
|
123
|
+
throw aotError('AOT: setKeyboardConfig(...) needs a config object');
|
|
124
|
+
}
|
|
125
|
+
// Lower the layout when the app gives one, layer by layer and row by row.
|
|
126
|
+
let layers = null;
|
|
127
|
+
if (Array.isArray(config.layers)) {
|
|
128
|
+
layers = config.layers.map((layer, layerIndex) => {
|
|
129
|
+
if (!Array.isArray(layer)) {
|
|
130
|
+
throw aotError('AOT: setKeyboardConfig `layers[i]` must be an array of rows');
|
|
131
|
+
}
|
|
132
|
+
return layer.map(row => {
|
|
133
|
+
if (!Array.isArray(row) || !row.length) {
|
|
134
|
+
throw aotError('AOT: each keyboard row must be a non-empty array of keys');
|
|
135
|
+
}
|
|
136
|
+
return row.map(key => lowerKey(key, layerIndex));
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
layers,
|
|
142
|
+
gridCols: kbdSize(config.gridCols),
|
|
143
|
+
rowHeight: kbdSize(config.rowHeight),
|
|
144
|
+
keyGap: kbdSize(config.keyGap),
|
|
145
|
+
keyRadius: kbdSize(config.keyRadius),
|
|
146
|
+
fontSize: kbdSize(config.fontSize),
|
|
147
|
+
panelColor: kbdColor(config.panelColor),
|
|
148
|
+
keyColor: kbdColor(config.keyColor),
|
|
149
|
+
keyActiveColor: kbdColor(config.keyActiveColor),
|
|
150
|
+
labelColor: kbdColor(config.labelColor),
|
|
151
|
+
};
|
|
152
|
+
}
|