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
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
// (there is no Python step). font_registry.c falls back to g_inter_sizes[] for any text without a
|
|
20
20
|
// matching custom family.
|
|
21
21
|
//
|
|
22
|
-
// cd
|
|
22
|
+
// cd packages/embedded-react && npm run build:builtin-font
|
|
23
23
|
//
|
|
24
24
|
// Regenerating changes glyph metrics slightly vs a prior rasterizer, so re-run the engine text tests
|
|
25
25
|
// (test_text, yoga_parity) and re-flash to eyeball on-device after changing it.
|
|
@@ -29,10 +29,11 @@ import {writeFileSync} from 'node:fs';
|
|
|
29
29
|
import {bakeFont, BUILTIN_EXTRAS, BUILTIN_SIZES} from './bake-font.mjs';
|
|
30
30
|
import {emitBuiltinFont} from './emit-c.mjs';
|
|
31
31
|
|
|
32
|
-
const here = dirname(fileURLToPath(import.meta.url)); //
|
|
33
|
-
const repoRoot = resolve(here, '
|
|
34
|
-
const
|
|
35
|
-
const
|
|
32
|
+
const here = dirname(fileURLToPath(import.meta.url)); // packages/embedded-react/assets
|
|
33
|
+
const repoRoot = resolve(here, '../../..');
|
|
34
|
+
const FONT_PATH = resolve(repoRoot, 'assets/fonts/Inter-Regular.ttf');
|
|
35
|
+
const OUTPUT_PATH = resolve(repoRoot, 'engine/font/font_data.c');
|
|
36
|
+
const BITS_PER_PIXEL = 4;
|
|
36
37
|
|
|
37
38
|
// The built-in covers printable ASCII plus a fixed set of common symbols (degrees, arrows, math,
|
|
38
39
|
// punctuation, etc.) the UI components rely on — kept stable across regenerations. The set lives in
|
|
@@ -41,18 +42,21 @@ const OUT = resolve(repoRoot, 'engine/font/font_data.c');
|
|
|
41
42
|
const SIZES = BUILTIN_SIZES;
|
|
42
43
|
|
|
43
44
|
const font = bakeFont({
|
|
44
|
-
path:
|
|
45
|
+
path: FONT_PATH,
|
|
45
46
|
family: 'Inter',
|
|
46
47
|
sizes: SIZES,
|
|
47
|
-
bpp:
|
|
48
|
+
bpp: BITS_PER_PIXEL,
|
|
48
49
|
glyphs: BUILTIN_EXTRAS,
|
|
49
50
|
});
|
|
50
51
|
writeFileSync(
|
|
51
|
-
|
|
52
|
+
OUTPUT_PATH,
|
|
52
53
|
emitBuiltinFont({font, symbol: 'inter', sourceName: 'Inter-Regular.ttf'}),
|
|
53
54
|
);
|
|
54
55
|
|
|
55
|
-
const
|
|
56
|
+
const bitmapBytes = font.sizes.reduce(
|
|
57
|
+
(total, size) => total + size.bitmap.length,
|
|
58
|
+
0,
|
|
59
|
+
);
|
|
56
60
|
console.log(
|
|
57
|
-
`Regenerated ${
|
|
61
|
+
`Regenerated ${OUTPUT_PATH}\n ${SIZES.length} sizes [${SIZES.join(',')}], bpp ${BITS_PER_PIXEL}, ${font.sizes[0].extras.length} extra glyphs, ${bitmapBytes} bitmap bytes`,
|
|
58
62
|
);
|
package/assets/emit-c.mjs
CHANGED
|
@@ -19,27 +19,35 @@
|
|
|
19
19
|
// (er_scene.h, which exposes both er_image_load/er_font_register and the BitmapFont format), so it
|
|
20
20
|
// drops into any target's build the same way the bundle does.
|
|
21
21
|
|
|
22
|
+
const ARGB8888_HEX_DIGITS = 8;
|
|
23
|
+
const RGB565_HEX_DIGITS = 4;
|
|
24
|
+
const BYTE_HEX_DIGITS = 2;
|
|
25
|
+
const ARGB8888_WORDS_PER_LINE = 8;
|
|
26
|
+
const RGB565_WORDS_PER_LINE = 12;
|
|
27
|
+
const BITMAP_BYTES_PER_LINE = 16;
|
|
28
|
+
const DEFAULT_BPP = 4;
|
|
29
|
+
|
|
22
30
|
/** Sanitizes an asset/family name into a C identifier fragment. */
|
|
23
31
|
function cIdent(name) {
|
|
24
|
-
let
|
|
25
|
-
if (
|
|
26
|
-
return
|
|
32
|
+
let identifier = String(name).replace(/[^0-9a-zA-Z_]/g, '_');
|
|
33
|
+
if (identifier && /[0-9]/.test(identifier[0])) identifier = '_' + identifier;
|
|
34
|
+
return identifier || '_asset';
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
/** Formats an array of byte/word strings into wrapped C initializer lines. */
|
|
30
38
|
function rows(values, perLine, indent = ' ') {
|
|
31
|
-
const
|
|
32
|
-
for (let
|
|
33
|
-
|
|
39
|
+
const lines = [];
|
|
40
|
+
for (let start = 0; start < values.length; start += perLine) {
|
|
41
|
+
lines.push(indent + values.slice(start, start + perLine).join(', ') + ',');
|
|
34
42
|
}
|
|
35
|
-
return
|
|
43
|
+
return lines.join('\n');
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
/** Emits the GlyphInfo designated-initializer for one glyph. */
|
|
39
|
-
function glyphInit(
|
|
47
|
+
function glyphInit(glyph) {
|
|
40
48
|
return (
|
|
41
|
-
`{ .bitmap_offset = ${
|
|
42
|
-
`.x_offset = ${
|
|
49
|
+
`{ .bitmap_offset = ${glyph.bitmapOffset}, .width = ${glyph.width}, .height = ${glyph.height}, ` +
|
|
50
|
+
`.x_offset = ${glyph.xOffset}, .y_offset = ${glyph.yOffset}, .advance = ${glyph.advance} }`
|
|
43
51
|
);
|
|
44
52
|
}
|
|
45
53
|
|
|
@@ -54,8 +62,8 @@ function glyphInit(g) {
|
|
|
54
62
|
*/
|
|
55
63
|
export function emitAssetsC({headerName, images = [], fonts = []}) {
|
|
56
64
|
const guard = 'ER_' + cIdent(headerName).toUpperCase();
|
|
57
|
-
const
|
|
58
|
-
`/* Generated by
|
|
65
|
+
const header =
|
|
66
|
+
`/* Generated by packages/embedded-react/assets — DO NOT EDIT. */\n` +
|
|
59
67
|
`#ifndef ${guard}\n#define ${guard}\n\n` +
|
|
60
68
|
`#ifdef __cplusplus\nextern "C"\n{\n#endif\n\n` +
|
|
61
69
|
` /** @brief Registers every baked image and font with the engine (call once at boot, after\n` +
|
|
@@ -65,7 +73,9 @@ export function emitAssetsC({headerName, images = [], fonts = []}) {
|
|
|
65
73
|
`#endif\n`;
|
|
66
74
|
|
|
67
75
|
const lines = [];
|
|
68
|
-
lines.push(
|
|
76
|
+
lines.push(
|
|
77
|
+
`/* Generated by packages/embedded-react/assets — DO NOT EDIT. */`,
|
|
78
|
+
);
|
|
69
79
|
lines.push(
|
|
70
80
|
`/* Images: premultiplied ARGB8888 (or RGB565 when baked 16-bit), referenced by pointer. Fonts: baked BitmapFont per size. */`,
|
|
71
81
|
);
|
|
@@ -79,26 +89,28 @@ export function emitAssetsC({headerName, images = [], fonts = []}) {
|
|
|
79
89
|
lines.push(``);
|
|
80
90
|
|
|
81
91
|
// --- Images ---------------------------------------------------------------------------------
|
|
82
|
-
for (const
|
|
83
|
-
const
|
|
84
|
-
const is565 =
|
|
92
|
+
for (const image of images) {
|
|
93
|
+
const identifier = cIdent(image.name);
|
|
94
|
+
const is565 = image.format === 'rgb565';
|
|
85
95
|
const hex = Array.from(
|
|
86
|
-
|
|
87
|
-
|
|
96
|
+
image.pixels,
|
|
97
|
+
pixel =>
|
|
88
98
|
'0x' +
|
|
89
|
-
|
|
99
|
+
pixel
|
|
90
100
|
.toString(16)
|
|
91
101
|
.toUpperCase()
|
|
92
|
-
.padStart(is565 ?
|
|
102
|
+
.padStart(is565 ? RGB565_HEX_DIGITS : ARGB8888_HEX_DIGITS, '0') +
|
|
93
103
|
'u',
|
|
94
104
|
);
|
|
95
105
|
lines.push(
|
|
96
|
-
`/* image "${
|
|
106
|
+
`/* image "${image.name}" — ${image.width}x${image.height}${is565 ? ' (RGB565)' : ''} */`,
|
|
107
|
+
);
|
|
108
|
+
lines.push(
|
|
109
|
+
`static const ${is565 ? 'uint16_t' : 'uint32_t'} ${identifier}_px[] = {`,
|
|
97
110
|
);
|
|
98
111
|
lines.push(
|
|
99
|
-
|
|
112
|
+
rows(hex, is565 ? RGB565_WORDS_PER_LINE : ARGB8888_WORDS_PER_LINE),
|
|
100
113
|
);
|
|
101
|
-
lines.push(rows(hex, is565 ? 12 : 8));
|
|
102
114
|
lines.push(`};`);
|
|
103
115
|
lines.push(``);
|
|
104
116
|
}
|
|
@@ -106,14 +118,14 @@ export function emitAssetsC({headerName, images = [], fonts = []}) {
|
|
|
106
118
|
// --- Fonts ----------------------------------------------------------------------------------
|
|
107
119
|
const fontRegistrations = [];
|
|
108
120
|
for (const font of fonts) {
|
|
109
|
-
const
|
|
121
|
+
const familyIdentifier = cIdent(font.family);
|
|
110
122
|
lines.push(
|
|
111
|
-
`/* font "${font.family}" — ${font.sizes.map(
|
|
123
|
+
`/* font "${font.family}" — ${font.sizes.map(size => `${size.pixelSize}px`).join(', ')} */`,
|
|
112
124
|
);
|
|
113
|
-
emitFontSizes(lines, font,
|
|
114
|
-
for (const
|
|
125
|
+
emitFontSizes(lines, font, familyIdentifier, 'static const '); // file-local: only er_register_assets refers to these
|
|
126
|
+
for (const size of font.sizes) {
|
|
115
127
|
fontRegistrations.push(
|
|
116
|
-
` er_font_register(${JSON.stringify(font.family)}, &g_font_${
|
|
128
|
+
` er_font_register(${JSON.stringify(font.family)}, &g_font_${familyIdentifier}_${size.pixelSize});`,
|
|
117
129
|
);
|
|
118
130
|
}
|
|
119
131
|
}
|
|
@@ -121,70 +133,79 @@ export function emitAssetsC({headerName, images = [], fonts = []}) {
|
|
|
121
133
|
// --- Registration entry point ---------------------------------------------------------------
|
|
122
134
|
lines.push(`void er_register_assets(void)`);
|
|
123
135
|
lines.push(`{`);
|
|
124
|
-
for (const
|
|
125
|
-
const
|
|
126
|
-
|
|
136
|
+
for (const image of images) {
|
|
137
|
+
const loadFunction =
|
|
138
|
+
image.format === 'rgb565' ? 'er_image_load_rgb565' : 'er_image_load';
|
|
127
139
|
lines.push(
|
|
128
|
-
` ${
|
|
140
|
+
` ${loadFunction}(${JSON.stringify(image.name)}, ${cIdent(image.name)}_px, ${image.width}, ${image.height});`,
|
|
129
141
|
);
|
|
130
142
|
}
|
|
131
|
-
for (const
|
|
143
|
+
for (const registration of fontRegistrations) lines.push(registration);
|
|
132
144
|
if (images.length === 0 && fontRegistrations.length === 0) {
|
|
133
145
|
lines.push(` /* no baked assets */`);
|
|
134
146
|
}
|
|
135
147
|
lines.push(`}`);
|
|
136
148
|
lines.push(``);
|
|
137
149
|
|
|
138
|
-
return {c: lines.join('\n'), h};
|
|
150
|
+
return {c: lines.join('\n'), h: header};
|
|
139
151
|
}
|
|
140
152
|
|
|
141
153
|
/** Emits the per-size BitmapFont blocks (bitmap + glyphs + extras + struct) for one font. */
|
|
142
154
|
function emitFontSizes(lines, font, symbol, fontStorage) {
|
|
143
|
-
for (const
|
|
144
|
-
const prefix = `s_${symbol}_${
|
|
145
|
-
const hex =
|
|
146
|
-
|
|
155
|
+
for (const size of font.sizes) {
|
|
156
|
+
const prefix = `s_${symbol}_${size.pixelSize}`;
|
|
157
|
+
const hex = size.bitmap.map(
|
|
158
|
+
byte =>
|
|
159
|
+
'0x' + byte.toString(16).toUpperCase().padStart(BYTE_HEX_DIGITS, '0'),
|
|
147
160
|
);
|
|
148
161
|
lines.push(
|
|
149
|
-
`static const uint8_t ${prefix}_bitmap[${
|
|
162
|
+
`static const uint8_t ${prefix}_bitmap[${size.bitmap.length || 1}] = {`,
|
|
163
|
+
);
|
|
164
|
+
lines.push(
|
|
165
|
+
size.bitmap.length ? rows(hex, BITMAP_BYTES_PER_LINE) : ' 0x00,',
|
|
150
166
|
);
|
|
151
|
-
lines.push(sz.bitmap.length ? rows(hex, 16) : ' 0x00,');
|
|
152
167
|
lines.push(`};`);
|
|
153
168
|
lines.push(``);
|
|
154
169
|
|
|
155
170
|
lines.push(
|
|
156
|
-
`static const GlyphInfo ${prefix}_glyphs[${
|
|
171
|
+
`static const GlyphInfo ${prefix}_glyphs[${size.dense.length}] = {`,
|
|
157
172
|
);
|
|
158
|
-
for (const
|
|
173
|
+
for (const glyph of size.dense) lines.push(` ${glyphInit(glyph)},`);
|
|
159
174
|
lines.push(`};`);
|
|
160
175
|
lines.push(``);
|
|
161
176
|
|
|
162
|
-
if (
|
|
177
|
+
if (size.extras.length) {
|
|
163
178
|
lines.push(
|
|
164
|
-
`static const ExtraGlyph ${prefix}_extras[${
|
|
179
|
+
`static const ExtraGlyph ${prefix}_extras[${size.extras.length}] = {`,
|
|
165
180
|
);
|
|
166
|
-
for (const
|
|
181
|
+
for (const extra of size.extras) {
|
|
167
182
|
lines.push(
|
|
168
|
-
` { .codepoint = 0x${
|
|
183
|
+
` { .codepoint = 0x${extra.codepoint.toString(16).toUpperCase()}, .info = ${glyphInit(extra.info)} },`,
|
|
169
184
|
);
|
|
170
185
|
}
|
|
171
186
|
lines.push(`};`);
|
|
172
187
|
lines.push(``);
|
|
173
188
|
}
|
|
174
189
|
|
|
175
|
-
lines.push(
|
|
190
|
+
lines.push(
|
|
191
|
+
`${fontStorage}BitmapFont g_font_${symbol}_${size.pixelSize} = {`,
|
|
192
|
+
);
|
|
176
193
|
lines.push(` .bitmap = ${prefix}_bitmap,`);
|
|
177
194
|
lines.push(` .glyphs = ${prefix}_glyphs,`);
|
|
178
195
|
lines.push(
|
|
179
|
-
` .extras = ${
|
|
196
|
+
` .extras = ${size.extras.length ? `${prefix}_extras` : 'NULL'},`,
|
|
197
|
+
);
|
|
198
|
+
lines.push(` .extras_count = ${size.extras.length},`);
|
|
199
|
+
lines.push(
|
|
200
|
+
` .first = 0x${size.first.toString(16).toUpperCase()},`,
|
|
201
|
+
);
|
|
202
|
+
lines.push(
|
|
203
|
+
` .last = 0x${size.last.toString(16).toUpperCase()},`,
|
|
180
204
|
);
|
|
181
|
-
lines.push(` .
|
|
182
|
-
lines.push(` .
|
|
183
|
-
lines.push(` .
|
|
184
|
-
lines.push(` .
|
|
185
|
-
lines.push(` .line_height = ${sz.lineHeight},`);
|
|
186
|
-
lines.push(` .baseline = ${sz.baseline},`);
|
|
187
|
-
lines.push(` .format = ${sz.bpp},`);
|
|
205
|
+
lines.push(` .pixel_size = ${size.pixelSize},`);
|
|
206
|
+
lines.push(` .line_height = ${size.lineHeight},`);
|
|
207
|
+
lines.push(` .baseline = ${size.baseline},`);
|
|
208
|
+
lines.push(` .format = ${size.bpp},`);
|
|
188
209
|
lines.push(`};`);
|
|
189
210
|
lines.push(``);
|
|
190
211
|
}
|
|
@@ -202,16 +223,16 @@ function emitFontSizes(lines, font, symbol, fontStorage) {
|
|
|
202
223
|
* @returns {string} The .c source text.
|
|
203
224
|
*/
|
|
204
225
|
export function emitBuiltinFont({font, symbol = 'inter', sourceName = ''}) {
|
|
205
|
-
const
|
|
206
|
-
const bpp = font.sizes[0] ? font.sizes[0].bpp :
|
|
226
|
+
const sizeList = font.sizes.map(size => size.pixelSize).join(',');
|
|
227
|
+
const bpp = font.sizes[0] ? font.sizes[0].bpp : DEFAULT_BPP;
|
|
207
228
|
const lines = [];
|
|
208
229
|
lines.push(
|
|
209
|
-
`/* AUTO-GENERATED by
|
|
230
|
+
`/* AUTO-GENERATED by packages/embedded-react/assets/build-builtin-font.mjs — do not edit by hand.`,
|
|
210
231
|
);
|
|
211
232
|
lines.push(` * Source : ${sourceName}`);
|
|
212
|
-
lines.push(` * Sizes : ${
|
|
233
|
+
lines.push(` * Sizes : ${sizeList} (bpp ${bpp}, family "${font.family}")`);
|
|
213
234
|
lines.push(
|
|
214
|
-
` * Regenerate: cd
|
|
235
|
+
` * Regenerate: cd packages/embedded-react && npm run build:builtin-font`,
|
|
215
236
|
);
|
|
216
237
|
lines.push(` */`);
|
|
217
238
|
lines.push(`#include "font_bitmap.h"`);
|
|
@@ -221,8 +242,8 @@ export function emitBuiltinFont({font, symbol = 'inter', sourceName = ''}) {
|
|
|
221
242
|
emitFontSizes(lines, font, symbol, 'const '); // file-scope const: referenced by g_<symbol>_sizes
|
|
222
243
|
|
|
223
244
|
lines.push(`const BitmapFont *const g_${symbol}_sizes[] = {`);
|
|
224
|
-
for (const
|
|
225
|
-
lines.push(` &g_font_${symbol}_${
|
|
245
|
+
for (const size of font.sizes)
|
|
246
|
+
lines.push(` &g_font_${symbol}_${size.pixelSize},`);
|
|
226
247
|
lines.push(`};`);
|
|
227
248
|
lines.push(
|
|
228
249
|
`const size_t g_${symbol}_sizes_count = sizeof(g_${symbol}_sizes) / sizeof(g_${symbol}_sizes[0]);`,
|
|
@@ -50,6 +50,16 @@
|
|
|
50
50
|
|
|
51
51
|
const FORMAT_VERSION = 1;
|
|
52
52
|
|
|
53
|
+
const HEADER_BYTES = 12; // magic + format_version + crc32
|
|
54
|
+
const TAG_LENGTH_BYTES = 2;
|
|
55
|
+
const SECTION_COUNT_BYTES = 4;
|
|
56
|
+
const SECTION_HEADER_BYTES = 8; // type + len
|
|
57
|
+
const SECTION_ALIGNMENT = 4;
|
|
58
|
+
|
|
59
|
+
const CRC32_POLYNOMIAL = 0xedb88320;
|
|
60
|
+
const CRC32_INVERT = 0xffffffff;
|
|
61
|
+
const BITS_PER_BYTE = 8;
|
|
62
|
+
|
|
53
63
|
export const SECTION_PAD = 0;
|
|
54
64
|
export const SECTION_BYTECODE = 1;
|
|
55
65
|
export const SECTION_ASSET_PACK = 2;
|
|
@@ -57,22 +67,22 @@ export const SECTION_VENDOR_BYTECODE = 3;
|
|
|
57
67
|
|
|
58
68
|
/**
|
|
59
69
|
* CRC-32/IEEE (zlib polynomial 0xEDB88320), computed without a lookup table to match er_crc32() in
|
|
60
|
-
*
|
|
70
|
+
* runtime/er_container.c byte-for-byte — the one checksum of the whole delivery pipeline (this
|
|
61
71
|
* container, the hot-reload transport frame that carries it, and the device's verification of both).
|
|
62
72
|
* hotreload/protocol.mjs imports this rather than keeping its own.
|
|
63
73
|
*
|
|
64
|
-
* @param {Buffer|Uint8Array}
|
|
74
|
+
* @param {Buffer|Uint8Array} data Bytes to checksum.
|
|
65
75
|
* @returns {number} The CRC as an unsigned 32-bit integer.
|
|
66
76
|
*/
|
|
67
|
-
export function crc32(
|
|
68
|
-
let crc =
|
|
69
|
-
for (let
|
|
70
|
-
crc ^=
|
|
71
|
-
for (let
|
|
72
|
-
crc = (crc >>> 1) ^ (
|
|
77
|
+
export function crc32(data) {
|
|
78
|
+
let crc = CRC32_INVERT;
|
|
79
|
+
for (let index = 0; index < data.length; index++) {
|
|
80
|
+
crc ^= data[index];
|
|
81
|
+
for (let bit = 0; bit < BITS_PER_BYTE; bit++) {
|
|
82
|
+
crc = (crc >>> 1) ^ (CRC32_POLYNOMIAL & -(crc & 1));
|
|
73
83
|
}
|
|
74
84
|
}
|
|
75
|
-
return (crc ^
|
|
85
|
+
return (crc ^ CRC32_INVERT) >>> 0;
|
|
76
86
|
}
|
|
77
87
|
|
|
78
88
|
/** Accumulates little-endian binary chunks (mirrors emit-pack.mjs's Writer). */
|
|
@@ -80,23 +90,23 @@ class Writer {
|
|
|
80
90
|
constructor() {
|
|
81
91
|
this.chunks = [];
|
|
82
92
|
}
|
|
83
|
-
u16(
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
this.chunks.push(
|
|
93
|
+
u16(value) {
|
|
94
|
+
const buffer = Buffer.alloc(2);
|
|
95
|
+
buffer.writeUInt16LE(value & 0xffff, 0);
|
|
96
|
+
this.chunks.push(buffer);
|
|
87
97
|
}
|
|
88
|
-
u32(
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
this.chunks.push(
|
|
98
|
+
u32(value) {
|
|
99
|
+
const buffer = Buffer.alloc(4);
|
|
100
|
+
buffer.writeUInt32LE(value >>> 0, 0);
|
|
101
|
+
this.chunks.push(buffer);
|
|
92
102
|
}
|
|
93
|
-
str(
|
|
94
|
-
const
|
|
95
|
-
this.u16(
|
|
96
|
-
this.chunks.push(
|
|
103
|
+
str(text) {
|
|
104
|
+
const buffer = Buffer.from(text, 'utf8');
|
|
105
|
+
this.u16(buffer.length);
|
|
106
|
+
this.chunks.push(buffer);
|
|
97
107
|
}
|
|
98
|
-
bytes(
|
|
99
|
-
this.chunks.push(Buffer.from(
|
|
108
|
+
bytes(data) {
|
|
109
|
+
this.chunks.push(Buffer.from(data));
|
|
100
110
|
}
|
|
101
111
|
done() {
|
|
102
112
|
return Buffer.concat(this.chunks);
|
|
@@ -135,31 +145,107 @@ export function emitContainer({bytecode, vendorBytecode, assetPack, qjsTag}) {
|
|
|
135
145
|
// 4-align the asset pack's first byte relative to the container (see the alignment contract above)
|
|
136
146
|
// by inserting a type-0 padding section ahead of it when the layout calls for one. Walk the layout
|
|
137
147
|
// once to place pads, then write — section_count must already include them.
|
|
138
|
-
const
|
|
139
|
-
let
|
|
148
|
+
const paddedSections = [];
|
|
149
|
+
let offset =
|
|
150
|
+
HEADER_BYTES +
|
|
151
|
+
TAG_LENGTH_BYTES +
|
|
152
|
+
Buffer.byteLength(qjsTag, 'utf8') +
|
|
153
|
+
SECTION_COUNT_BYTES;
|
|
140
154
|
for (const [type, data] of sections) {
|
|
141
155
|
if (type === SECTION_ASSET_PACK) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
156
|
+
// Counts this section's own type+len header.
|
|
157
|
+
const padding =
|
|
158
|
+
(SECTION_ALIGNMENT -
|
|
159
|
+
((offset + SECTION_HEADER_BYTES) % SECTION_ALIGNMENT)) %
|
|
160
|
+
SECTION_ALIGNMENT;
|
|
161
|
+
if (padding) {
|
|
162
|
+
paddedSections.push([SECTION_PAD, Buffer.alloc(padding)]);
|
|
163
|
+
offset += SECTION_HEADER_BYTES + padding;
|
|
146
164
|
}
|
|
147
165
|
}
|
|
148
|
-
|
|
149
|
-
|
|
166
|
+
paddedSections.push([type, data]);
|
|
167
|
+
offset += SECTION_HEADER_BYTES + data.length;
|
|
150
168
|
}
|
|
151
169
|
|
|
152
|
-
body.u32(
|
|
153
|
-
for (const [type, data] of
|
|
170
|
+
body.u32(paddedSections.length);
|
|
171
|
+
for (const [type, data] of paddedSections) {
|
|
172
|
+
body.u32(type);
|
|
173
|
+
body.u32(data.length);
|
|
174
|
+
body.bytes(data);
|
|
175
|
+
}
|
|
176
|
+
const bodyBytes = body.done();
|
|
177
|
+
|
|
178
|
+
const header = new Writer();
|
|
179
|
+
header.bytes(Buffer.from('ERCF', 'ascii'));
|
|
180
|
+
header.u32(FORMAT_VERSION);
|
|
181
|
+
header.u32(crc32(bodyBytes));
|
|
182
|
+
return Buffer.concat([header.done(), bodyBytes]);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export const SECTION_PROGRAM = 4;
|
|
186
|
+
export const SECTION_DEBUG = 5;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Serializes a Flow B package into an ERCF container tagged `erb`: the asset pack, the program, then the debug
|
|
190
|
+
* table. Every section starts 4-aligned in the container, since the runtime reads each in place.
|
|
191
|
+
*
|
|
192
|
+
* @param {object} opts
|
|
193
|
+
* @param {Uint8Array} opts.program The program section (aot/compiler/package/writer.mts).
|
|
194
|
+
* @param {Uint8Array} [opts.assetPack] ERPK asset pack bytes; omitted/empty → no asset section.
|
|
195
|
+
* @param {Uint8Array} [opts.debug] The debug section; omitted for a release build.
|
|
196
|
+
* @returns {{bytes: Buffer, sections: Array<{type:number, offset:number, bytes:number}>}} The container, and
|
|
197
|
+
* where each non-padding section's data starts in it.
|
|
198
|
+
*/
|
|
199
|
+
export function emitPackageContainer({program, assetPack, debug}) {
|
|
200
|
+
if (!program || !program.length)
|
|
201
|
+
throw new Error('emitPackageContainer: program is required');
|
|
202
|
+
|
|
203
|
+
const tag = 'erb';
|
|
204
|
+
const sections = [];
|
|
205
|
+
if (assetPack && assetPack.length)
|
|
206
|
+
sections.push([SECTION_ASSET_PACK, assetPack]);
|
|
207
|
+
sections.push([SECTION_PROGRAM, program]);
|
|
208
|
+
if (debug && debug.length) sections.push([SECTION_DEBUG, debug]);
|
|
209
|
+
|
|
210
|
+
const paddedSections = [];
|
|
211
|
+
const placed = [];
|
|
212
|
+
let offset =
|
|
213
|
+
HEADER_BYTES +
|
|
214
|
+
TAG_LENGTH_BYTES +
|
|
215
|
+
Buffer.byteLength(tag, 'utf8') +
|
|
216
|
+
SECTION_COUNT_BYTES;
|
|
217
|
+
for (const [type, data] of sections) {
|
|
218
|
+
if ((offset + SECTION_HEADER_BYTES) % SECTION_ALIGNMENT) {
|
|
219
|
+
// A padding section has its own 8-byte header, so its data has to cover what is left after it.
|
|
220
|
+
const padding =
|
|
221
|
+
(SECTION_ALIGNMENT -
|
|
222
|
+
((offset + 2 * SECTION_HEADER_BYTES) % SECTION_ALIGNMENT)) %
|
|
223
|
+
SECTION_ALIGNMENT;
|
|
224
|
+
paddedSections.push([SECTION_PAD, Buffer.alloc(padding)]);
|
|
225
|
+
offset += SECTION_HEADER_BYTES + padding;
|
|
226
|
+
}
|
|
227
|
+
placed.push({
|
|
228
|
+
type,
|
|
229
|
+
offset: offset + SECTION_HEADER_BYTES,
|
|
230
|
+
bytes: data.length,
|
|
231
|
+
});
|
|
232
|
+
paddedSections.push([type, data]);
|
|
233
|
+
offset += SECTION_HEADER_BYTES + data.length;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const body = new Writer();
|
|
237
|
+
body.str(tag);
|
|
238
|
+
body.u32(paddedSections.length);
|
|
239
|
+
for (const [type, data] of paddedSections) {
|
|
154
240
|
body.u32(type);
|
|
155
241
|
body.u32(data.length);
|
|
156
242
|
body.bytes(data);
|
|
157
243
|
}
|
|
158
244
|
const bodyBytes = body.done();
|
|
159
245
|
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return Buffer.concat([
|
|
246
|
+
const header = new Writer();
|
|
247
|
+
header.bytes(Buffer.from('ERCF', 'ascii'));
|
|
248
|
+
header.u32(FORMAT_VERSION);
|
|
249
|
+
header.u32(crc32(bodyBytes));
|
|
250
|
+
return {bytes: Buffer.concat([header.done(), bodyBytes]), sections: placed};
|
|
165
251
|
}
|