embedded-react 0.14.1 → 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/README.md +51 -486
- 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.cjs +1 -1
- package/sim/embedded-react.js +1 -1
- package/sim/embedded-react.wasm +0 -0
- package/src/embedded-react/FlatList.js +4 -4
- package/src/embedded-react/index.d.ts +2 -1
- 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 {};
|
package/aot/screenshot-smoke.mjs
CHANGED
|
@@ -14,17 +14,19 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
/*
|
|
18
|
+
* `npm run aot:smoke` — automated compile-and-screenshot smoke test for the Flow B (AOT) demos.
|
|
19
|
+
*
|
|
20
|
+
* For each demo it: (1) compiles App.jsx → dist/app.gen.{c,h} (`node aot/compile.mts`), (2) rebuilds the
|
|
21
|
+
* linux-aot SDL host (which links the generated C), (3) runs it headless via ER_AOT_SHOT to render ONE
|
|
22
|
+
* frame to a BMP, and (4) checks the image actually has content (distinct colors above a floor) — i.e., it
|
|
23
|
+
* compiled, linked, and rendered something rather than crashing or drawing a blank screen. Exits non-zero
|
|
24
|
+
* if any demo fails, so it can gate CI.
|
|
25
|
+
*
|
|
26
|
+
* Prereq: the linux-aot CMake build must be configurable (SDL2 found). It reuses examples/linux-aot/build;
|
|
27
|
+
* if that isn't configured yet, set CMAKE_TOOLCHAIN_FILE (e.g. a vcpkg toolchain) and it will configure it.
|
|
28
|
+
* Needs a display (SDL video); on a headless box run under a virtual framebuffer.
|
|
29
|
+
*/
|
|
28
30
|
import {execFileSync} from 'node:child_process';
|
|
29
31
|
import {existsSync, mkdirSync, readFileSync, rmSync} from 'node:fs';
|
|
30
32
|
import {resolve, dirname} from 'node:path';
|
|
@@ -43,79 +45,117 @@ const exe = resolve(
|
|
|
43
45
|
);
|
|
44
46
|
const tmpDir = resolve(jsDir, 'dist', '.smoke');
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
/**
|
|
49
|
+
* The demos to smoke-test. `screen` sets ER_AOT_SCREEN_W/H so the responsive thermostat folds to its `solo`
|
|
50
|
+
* (AOT-compilable) branch; `minColors` is the floor of distinct sampled colors that counts as "rendered".
|
|
51
|
+
*/
|
|
48
52
|
const DEMOS = [
|
|
49
53
|
{name: 'watch-face', screen: {w: 240, h: 280}, minColors: 40},
|
|
50
54
|
{name: 'thermostat', screen: {w: 240, h: 320}, minColors: 40},
|
|
51
55
|
];
|
|
52
56
|
|
|
53
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Counts the distinct colors in an uncompressed 24/32-bpp BMP, sampling every `step` pixels — a quick
|
|
59
|
+
* "is anything drawn?" signal.
|
|
60
|
+
*
|
|
61
|
+
* @param path The BMP file.
|
|
62
|
+
* @param step The sampling stride, in pixels, along both axes.
|
|
63
|
+
*
|
|
64
|
+
* @returns The number of distinct colors sampled.
|
|
65
|
+
*/
|
|
54
66
|
function bmpDistinctColors(path, step = 4) {
|
|
55
|
-
const
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
67
|
+
const bmp = readFileSync(path);
|
|
68
|
+
if (bmp[0] !== 0x42 || bmp[1] !== 0x4d) {
|
|
69
|
+
throw new Error(`not a BMP: ${path}`);
|
|
70
|
+
}
|
|
71
|
+
const pixelOffset = bmp.readUInt32LE(10);
|
|
72
|
+
const width = bmp.readInt32LE(18);
|
|
73
|
+
const height = Math.abs(bmp.readInt32LE(22));
|
|
74
|
+
const bitsPerPixel = bmp.readUInt16LE(28);
|
|
75
|
+
if (bitsPerPixel !== 24 && bitsPerPixel !== 32) {
|
|
76
|
+
throw new Error(`unexpected BMP bpp ${bitsPerPixel}`);
|
|
77
|
+
}
|
|
78
|
+
const bytesPerPixel = bitsPerPixel / 8;
|
|
79
|
+
const rowSize = Math.floor((bitsPerPixel * width + 31) / 32) * 4; // rows padded to 4 bytes
|
|
64
80
|
const colors = new Set();
|
|
65
|
-
for (let y = 0; y <
|
|
66
|
-
for (let x = 0; x <
|
|
67
|
-
const
|
|
68
|
-
colors.add((
|
|
81
|
+
for (let y = 0; y < height; y += step) {
|
|
82
|
+
for (let x = 0; x < width; x += step) {
|
|
83
|
+
const index = pixelOffset + y * rowSize + x * bytesPerPixel;
|
|
84
|
+
colors.add((bmp[index] << 16) | (bmp[index + 1] << 8) | bmp[index + 2]); // BGR triplet
|
|
69
85
|
}
|
|
70
86
|
}
|
|
71
87
|
return colors.size;
|
|
72
88
|
}
|
|
73
89
|
|
|
74
|
-
function run(
|
|
75
|
-
execFileSync(
|
|
90
|
+
function run(command, args, options = {}) {
|
|
91
|
+
execFileSync(command, args, {stdio: 'pipe', ...options});
|
|
76
92
|
}
|
|
77
93
|
|
|
94
|
+
/** Configures the linux-aot CMake build on the first run. */
|
|
78
95
|
function ensureConfigured() {
|
|
79
96
|
if (existsSync(resolve(buildDir, 'CMakeCache.txt'))) return;
|
|
80
97
|
console.log('• configuring linux-aot build (first run)…');
|
|
81
98
|
const args = ['-S', exampleDir, '-B', buildDir];
|
|
82
|
-
if (process.env.CMAKE_TOOLCHAIN_FILE)
|
|
99
|
+
if (process.env.CMAKE_TOOLCHAIN_FILE) {
|
|
83
100
|
args.push(`-DCMAKE_TOOLCHAIN_FILE=${process.env.CMAKE_TOOLCHAIN_FILE}`);
|
|
84
|
-
|
|
101
|
+
}
|
|
102
|
+
if (process.platform === 'win32') {
|
|
103
|
+
args.push('-G', 'MinGW Makefiles');
|
|
104
|
+
}
|
|
85
105
|
run('cmake', args);
|
|
86
106
|
}
|
|
87
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Compiles one demo, relinks the host, renders one frame and checks the frame has content. A step that cannot
|
|
110
|
+
* run (the compiler, the build or the host) throws.
|
|
111
|
+
*
|
|
112
|
+
* @param demo The demo, from DEMOS.
|
|
113
|
+
*
|
|
114
|
+
* @returns Why the demo failed, or null when it rendered.
|
|
115
|
+
*/
|
|
116
|
+
function smokeTest(demo) {
|
|
117
|
+
const shot = resolve(tmpDir, `${demo.name}.bmp`);
|
|
118
|
+
rmSync(shot, {force: true});
|
|
119
|
+
|
|
120
|
+
// Compile with the demo's screen size, relink the host, then render one frame to the BMP.
|
|
121
|
+
const compileEnv = {...process.env};
|
|
122
|
+
if (demo.screen) {
|
|
123
|
+
compileEnv.ER_AOT_SCREEN_W = String(demo.screen.w);
|
|
124
|
+
compileEnv.ER_AOT_SCREEN_H = String(demo.screen.h);
|
|
125
|
+
}
|
|
126
|
+
run('node', [resolve(here, 'compile.mts'), demo.name], {
|
|
127
|
+
cwd: jsDir,
|
|
128
|
+
env: compileEnv,
|
|
129
|
+
});
|
|
130
|
+
run('cmake', ['--build', buildDir]);
|
|
131
|
+
run(exe, [], {cwd: buildDir, env: {...process.env, ER_AOT_SHOT: shot}});
|
|
132
|
+
|
|
133
|
+
// The frame must exist and show more than a blank screen.
|
|
134
|
+
if (!existsSync(shot)) {
|
|
135
|
+
return 'no screenshot written (host crashed before present?)';
|
|
136
|
+
}
|
|
137
|
+
const colors = bmpDistinctColors(shot);
|
|
138
|
+
if (colors < demo.minColors) {
|
|
139
|
+
return `screenshot looks blank (${colors} distinct colors < ${demo.minColors})`;
|
|
140
|
+
}
|
|
141
|
+
console.log(`✓ ${demo.name}: rendered (${colors} distinct colors)`);
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
|
|
88
145
|
let failures = 0;
|
|
89
146
|
mkdirSync(tmpDir, {recursive: true});
|
|
90
147
|
ensureConfigured();
|
|
91
148
|
|
|
92
149
|
for (const demo of DEMOS) {
|
|
93
|
-
|
|
150
|
+
let failure;
|
|
94
151
|
try {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
run('node', [resolve(here, 'compile.mjs'), demo.name], {
|
|
102
|
-
cwd: jsDir,
|
|
103
|
-
env: genEnv,
|
|
104
|
-
}); // → dist/app.gen.{c,h}
|
|
105
|
-
run('cmake', ['--build', buildDir]); // relink the generated C
|
|
106
|
-
run(exe, [], {cwd: buildDir, env: {...process.env, ER_AOT_SHOT: shot}}); // render one frame → BMP
|
|
107
|
-
|
|
108
|
-
if (!existsSync(shot))
|
|
109
|
-
throw new Error('no screenshot written (host crashed before present?)');
|
|
110
|
-
const colors = bmpDistinctColors(shot);
|
|
111
|
-
if (colors < demo.minColors)
|
|
112
|
-
throw new Error(
|
|
113
|
-
`screenshot looks blank (${colors} distinct colours < ${demo.minColors})`,
|
|
114
|
-
);
|
|
115
|
-
console.log(`✓ ${demo.name}: rendered (${colors} distinct colours)`);
|
|
116
|
-
} catch (e) {
|
|
152
|
+
failure = smokeTest(demo);
|
|
153
|
+
} catch (error) {
|
|
154
|
+
failure = error.message?.split('\n')[0] || String(error);
|
|
155
|
+
}
|
|
156
|
+
if (failure) {
|
|
117
157
|
failures++;
|
|
118
|
-
console.error(`✗ ${demo.name}: ${
|
|
158
|
+
console.error(`✗ ${demo.name}: ${failure}`);
|
|
119
159
|
}
|
|
120
160
|
}
|
|
121
161
|
|