embedded-react 0.18.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/NOTICE +1 -1
- package/README.md +8 -4
- 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 +55 -41
- 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 +14 -10
- package/assets/emit-c.mjs +83 -62
- package/assets/emit-container.mjs +124 -38
- 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 +16 -14
- package/cli.mjs +359 -172
- package/compile-bin.mjs +5 -5
- 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 +51 -38
- package/hotreload/uploader.mjs +38 -27
- package/hotreload/watch-tree.mjs +19 -19
- package/pack-container.mjs +31 -23
- package/package.json +11 -12
- 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 +4 -4
- 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
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
* Constant props as package records.
|
|
18
|
+
*/
|
|
19
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
20
|
+
- Imports
|
|
21
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
22
|
+
import { aotError } from '../diagnostics.mjs';
|
|
23
|
+
import { ABI_PROPS, ENGINE_VALUES, PropKind } from './format.mjs';
|
|
24
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
25
|
+
- Constants
|
|
26
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
27
|
+
// The values each whole-number kind holds, as the runtime checks them at load. A float holds any, and an
|
|
28
|
+
// enum's largest value is its prop's own.
|
|
29
|
+
const RANGES = {
|
|
30
|
+
i16: [-32768, 32767],
|
|
31
|
+
u8: [0, 255],
|
|
32
|
+
opacity: [0, 255],
|
|
33
|
+
u16: [0, 65535],
|
|
34
|
+
bool: [0, 1],
|
|
35
|
+
color: [0, 0xffffffff],
|
|
36
|
+
};
|
|
37
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
38
|
+
- Implementation
|
|
39
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
40
|
+
/**
|
|
41
|
+
* The ABI prop an ERProps field is.
|
|
42
|
+
*
|
|
43
|
+
* @param field The field, as lowering names it (`flex_grow`, `gradient_stops[0].color`).
|
|
44
|
+
*
|
|
45
|
+
* @returns The prop.
|
|
46
|
+
*/
|
|
47
|
+
export function abiProp(field) {
|
|
48
|
+
const prop = ABI_PROPS.get(field);
|
|
49
|
+
if (!prop) {
|
|
50
|
+
throw aotError(`AOT: a package has no engine prop for \`${field}\` yet`);
|
|
51
|
+
}
|
|
52
|
+
return prop;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A float's 32 bits.
|
|
56
|
+
*
|
|
57
|
+
* @param value The number.
|
|
58
|
+
*
|
|
59
|
+
* @returns The bits.
|
|
60
|
+
*/
|
|
61
|
+
export function floatBits(value) {
|
|
62
|
+
const view = new DataView(new ArrayBuffer(4));
|
|
63
|
+
view.setFloat32(0, value, true);
|
|
64
|
+
return view.getUint32(0, true);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A constant's number.
|
|
68
|
+
*
|
|
69
|
+
* @param constant A number, or an er_scene.h name.
|
|
70
|
+
*
|
|
71
|
+
* @returns The number, or null for a name the format doesn't have.
|
|
72
|
+
*/
|
|
73
|
+
export function constantNumber(constant) {
|
|
74
|
+
return typeof constant === 'number'
|
|
75
|
+
? constant
|
|
76
|
+
: (ENGINE_VALUES.get(constant) ?? null);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A constant prop as a prop set entry.
|
|
80
|
+
*
|
|
81
|
+
* @param field The ERProps field.
|
|
82
|
+
* @param constant Its value.
|
|
83
|
+
*
|
|
84
|
+
* @returns The entry.
|
|
85
|
+
*/
|
|
86
|
+
export function constantPropEntry(field, constant) {
|
|
87
|
+
const prop = abiProp(field);
|
|
88
|
+
const value = constantNumber(constant);
|
|
89
|
+
if (value === null || !Number.isFinite(value)) {
|
|
90
|
+
throw aotError(`AOT: a package can't hold the constant \`${constant}\` for \`${field}\` yet`);
|
|
91
|
+
}
|
|
92
|
+
if (prop.kind === 'float') {
|
|
93
|
+
return { prop: prop.id, kind: PropKind.float, value: floatBits(value) };
|
|
94
|
+
}
|
|
95
|
+
// The runtime refuses a package with a value its field can't hold.
|
|
96
|
+
const whole = Math.trunc(value);
|
|
97
|
+
const [min, max] = prop.kind === 'enum' ? [0, prop.max] : RANGES[prop.kind];
|
|
98
|
+
if (whole < min || whole > max) {
|
|
99
|
+
throw aotError(`AOT: \`${field}\` is ${whole}, but the engine holds ${min} to ${max} there`, 'use a value in that range.');
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
prop: prop.id,
|
|
103
|
+
kind: PropKind[prop.kind],
|
|
104
|
+
value: prop.kind === 'color' ? whole >>> 0 : whole | 0,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* A string or image prop as a prop set entry.
|
|
109
|
+
*
|
|
110
|
+
* @param field `text`, `placeholder` or `image_name`.
|
|
111
|
+
* @param stringIndex The string's index in the strings table.
|
|
112
|
+
*
|
|
113
|
+
* @returns The entry.
|
|
114
|
+
*/
|
|
115
|
+
export function stringPropEntry(field, stringIndex) {
|
|
116
|
+
const prop = abiProp(field);
|
|
117
|
+
return { prop: prop.id, kind: PropKind[prop.kind], value: stringIndex };
|
|
118
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
* The tables a program's pieces share: strings, constants and prop sets, each entry stored once.
|
|
18
|
+
*/
|
|
19
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
20
|
+
- Imports
|
|
21
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
22
|
+
import { NONE } from './format.mjs';
|
|
23
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
24
|
+
- Classes
|
|
25
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
26
|
+
/**
|
|
27
|
+
* The shared tables, filled as the program is lowered.
|
|
28
|
+
*
|
|
29
|
+
* @class ProgramTables
|
|
30
|
+
*/
|
|
31
|
+
export class ProgramTables {
|
|
32
|
+
strings = [];
|
|
33
|
+
const32 = [];
|
|
34
|
+
const64 = [];
|
|
35
|
+
propSets = [];
|
|
36
|
+
stringIndex = new Map();
|
|
37
|
+
const32Index = new Map();
|
|
38
|
+
const64Index = new Map();
|
|
39
|
+
propSetIndex = new Map();
|
|
40
|
+
/**
|
|
41
|
+
* A string's index, adding it the first time.
|
|
42
|
+
*
|
|
43
|
+
* @param text The string.
|
|
44
|
+
*
|
|
45
|
+
* @returns Its index.
|
|
46
|
+
*/
|
|
47
|
+
string(text) {
|
|
48
|
+
return intern(this.stringIndex, this.strings, text);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A 32-bit constant's index, adding it the first time.
|
|
52
|
+
*
|
|
53
|
+
* @param bits Its bits, as an unsigned number.
|
|
54
|
+
*
|
|
55
|
+
* @returns Its index.
|
|
56
|
+
*/
|
|
57
|
+
constant32(bits) {
|
|
58
|
+
return intern(this.const32Index, this.const32, bits >>> 0);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A 64-bit constant's index, adding it the first time.
|
|
62
|
+
*
|
|
63
|
+
* @param bits Its bits.
|
|
64
|
+
*
|
|
65
|
+
* @returns Its index.
|
|
66
|
+
*/
|
|
67
|
+
constant64(bits) {
|
|
68
|
+
return intern(this.const64Index, this.const64, BigInt.asUintN(64, bits));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A prop set's index, adding it the first time.
|
|
72
|
+
*
|
|
73
|
+
* @param entries The set's entries, applied in order.
|
|
74
|
+
*
|
|
75
|
+
* @returns Its index, or NONE for an empty set.
|
|
76
|
+
*/
|
|
77
|
+
propSet(entries) {
|
|
78
|
+
return entries.length
|
|
79
|
+
? intern(this.propSetIndex, this.propSets, entries, JSON.stringify(entries))
|
|
80
|
+
: NONE;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
84
|
+
- Implementation
|
|
85
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
86
|
+
/**
|
|
87
|
+
* A value's index in a table, adding it the first time.
|
|
88
|
+
*
|
|
89
|
+
* @param index The table's index, by key.
|
|
90
|
+
* @param table The table.
|
|
91
|
+
* @param value The value.
|
|
92
|
+
* @param key Its key, when it isn't the value itself.
|
|
93
|
+
*
|
|
94
|
+
* @returns Its index.
|
|
95
|
+
*/
|
|
96
|
+
function intern(index, table, value, key = value) {
|
|
97
|
+
let at = index.get(key);
|
|
98
|
+
if (at === undefined) {
|
|
99
|
+
at = table.push(value) - 1;
|
|
100
|
+
index.set(key, at);
|
|
101
|
+
}
|
|
102
|
+
return at;
|
|
103
|
+
}
|