embedded-react 0.19.0 → 0.21.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 +5 -0
- package/README.md +8 -3
- package/aot/app-file-loader.mjs +116 -0
- package/aot/compile.mjs +180 -90
- package/aot/compiler/animations.mjs +568 -317
- package/aot/compiler/boot.mjs +97 -35
- package/aot/compiler/branch-merge.mjs +4 -3
- package/aot/compiler/check.mjs +70 -18
- package/aot/compiler/collect.mjs +787 -288
- package/aot/compiler/contexts.mjs +391 -0
- package/aot/compiler/control-flow.mjs +439 -268
- package/aot/compiler/custom-hooks.mjs +686 -0
- package/aot/compiler/diagnostics.mjs +22 -25
- package/aot/compiler/elements/activity-indicator.mjs +25 -24
- package/aot/compiler/elements/button.mjs +182 -0
- package/aot/compiler/elements/dial.mjs +91 -77
- package/aot/compiler/elements/flat-list.mjs +24 -22
- package/aot/compiler/elements/image-background.mjs +76 -0
- package/aot/compiler/elements/image.mjs +52 -50
- package/aot/compiler/elements/modal.mjs +31 -30
- package/aot/compiler/elements/props.mjs +61 -26
- package/aot/compiler/elements/rewrite.mjs +118 -0
- package/aot/compiler/elements/section-list.mjs +370 -0
- package/aot/compiler/elements/switch.mjs +42 -34
- package/aot/compiler/elements/text-input.mjs +34 -32
- package/aot/compiler/expressions.mjs +1685 -392
- package/aot/compiler/handlers.mjs +2029 -547
- package/aot/compiler/helper-values.mjs +312 -0
- package/aot/compiler/ir/functions.mjs +11 -1
- package/aot/compiler/ir/nodes.mjs +43 -4
- package/aot/compiler/ir/reads.mjs +223 -22
- package/aot/compiler/ir/text.mjs +5 -1
- package/aot/compiler/ir/types.mjs +26 -14
- package/aot/compiler/ir/vectors.mjs +5 -1
- package/aot/compiler/kept-states.mjs +177 -0
- package/aot/compiler/keyboard.mjs +17 -7
- package/aot/compiler/list-items.mjs +226 -0
- package/aot/compiler/list-order.mjs +586 -0
- package/aot/compiler/list-split.mjs +259 -0
- package/aot/compiler/loops.mjs +582 -0
- package/aot/compiler/lower.mjs +246 -111
- package/aot/compiler/native-files.mjs +439 -0
- package/aot/compiler/native-header.mjs +335 -0
- package/aot/compiler/native-modules.mjs +1173 -0
- package/aot/compiler/nodes.mjs +195 -172
- package/aot/compiler/options.mjs +37 -31
- package/aot/compiler/out.mjs +32 -23
- package/aot/compiler/package/animations.mjs +779 -0
- package/aot/compiler/package/arena.mjs +252 -0
- package/aot/compiler/package/assemble.mjs +175 -0
- package/aot/compiler/package/bytecode.mjs +315 -0
- package/aot/compiler/package/checks.mjs +1026 -0
- package/aot/compiler/package/codegen.mjs +2168 -0
- package/aot/compiler/package/enums.mjs +148 -0
- package/aot/compiler/package/format.mjs +771 -0
- package/aot/compiler/package/layouts.mjs +136 -0
- package/aot/compiler/package/lower.mjs +2103 -0
- package/aot/compiler/package/props.mjs +118 -0
- package/aot/compiler/package/string-caps.mjs +515 -0
- package/aot/compiler/package/tables.mjs +127 -0
- package/aot/compiler/package/vectors.mjs +502 -0
- package/aot/compiler/package/writer.mjs +686 -0
- package/aot/compiler/pan-responder.mjs +69 -61
- package/aot/compiler/parse.mjs +23 -21
- package/aot/compiler/record-shapes.mjs +246 -0
- package/aot/compiler/records.mjs +654 -0
- package/aot/compiler/reducers.mjs +272 -0
- package/aot/compiler/static-eval.mjs +340 -30
- package/aot/compiler/style-text.mjs +178 -174
- package/aot/compiler/svg.mjs +480 -251
- package/aot/compiler/switch-cases.mjs +198 -0
- package/aot/compiler/tagged-records.mjs +450 -0
- package/aot/compiler/typing.mjs +307 -0
- package/aot/compiler/updaters.mjs +320 -0
- package/aot/compiler/window-dimensions.mjs +94 -0
- package/aot/compiler/worked-values.mjs +319 -0
- package/aot/demo-file.mjs +30 -0
- package/aot/screenshot-smoke.mjs +54 -40
- package/aot/style-map.mjs +152 -92
- 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 +23 -13
- package/cli.mjs +402 -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 +62 -64
- 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 +37 -21
- 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 +113 -94
- package/src/embedded-react/Animated.js +24 -24
- package/src/embedded-react/Dimensions.js +37 -0
- 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 +7 -9
- package/src/embedded-react/StyleSheet.js +4 -3
- package/src/embedded-react/TouchableOpacity.js +13 -8
- package/src/embedded-react/index.d.ts +88 -8
- package/src/embedded-react/index.js +2 -0
- 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/nativeModule.js +462 -0
- 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
|
@@ -31,8 +31,9 @@ import {emitBuiltinFont} from './emit-c.mjs';
|
|
|
31
31
|
|
|
32
32
|
const here = dirname(fileURLToPath(import.meta.url)); // packages/embedded-react/assets
|
|
33
33
|
const repoRoot = resolve(here, '../../..');
|
|
34
|
-
const
|
|
35
|
-
const
|
|
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,7 +62,7 @@ function glyphInit(g) {
|
|
|
54
62
|
*/
|
|
55
63
|
export function emitAssetsC({headerName, images = [], fonts = []}) {
|
|
56
64
|
const guard = 'ER_' + cIdent(headerName).toUpperCase();
|
|
57
|
-
const
|
|
65
|
+
const header =
|
|
58
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` +
|
|
@@ -81,26 +89,28 @@ export function emitAssetsC({headerName, images = [], fonts = []}) {
|
|
|
81
89
|
lines.push(``);
|
|
82
90
|
|
|
83
91
|
// --- Images ---------------------------------------------------------------------------------
|
|
84
|
-
for (const
|
|
85
|
-
const
|
|
86
|
-
const is565 =
|
|
92
|
+
for (const image of images) {
|
|
93
|
+
const identifier = cIdent(image.name);
|
|
94
|
+
const is565 = image.format === 'rgb565';
|
|
87
95
|
const hex = Array.from(
|
|
88
|
-
|
|
89
|
-
|
|
96
|
+
image.pixels,
|
|
97
|
+
pixel =>
|
|
90
98
|
'0x' +
|
|
91
|
-
|
|
99
|
+
pixel
|
|
92
100
|
.toString(16)
|
|
93
101
|
.toUpperCase()
|
|
94
|
-
.padStart(is565 ?
|
|
102
|
+
.padStart(is565 ? RGB565_HEX_DIGITS : ARGB8888_HEX_DIGITS, '0') +
|
|
95
103
|
'u',
|
|
96
104
|
);
|
|
97
105
|
lines.push(
|
|
98
|
-
`/* image "${
|
|
106
|
+
`/* image "${image.name}" — ${image.width}x${image.height}${is565 ? ' (RGB565)' : ''} */`,
|
|
99
107
|
);
|
|
100
108
|
lines.push(
|
|
101
|
-
`static const ${is565 ? 'uint16_t' : 'uint32_t'} ${
|
|
109
|
+
`static const ${is565 ? 'uint16_t' : 'uint32_t'} ${identifier}_px[] = {`,
|
|
110
|
+
);
|
|
111
|
+
lines.push(
|
|
112
|
+
rows(hex, is565 ? RGB565_WORDS_PER_LINE : ARGB8888_WORDS_PER_LINE),
|
|
102
113
|
);
|
|
103
|
-
lines.push(rows(hex, is565 ? 12 : 8));
|
|
104
114
|
lines.push(`};`);
|
|
105
115
|
lines.push(``);
|
|
106
116
|
}
|
|
@@ -108,14 +118,14 @@ export function emitAssetsC({headerName, images = [], fonts = []}) {
|
|
|
108
118
|
// --- Fonts ----------------------------------------------------------------------------------
|
|
109
119
|
const fontRegistrations = [];
|
|
110
120
|
for (const font of fonts) {
|
|
111
|
-
const
|
|
121
|
+
const familyIdentifier = cIdent(font.family);
|
|
112
122
|
lines.push(
|
|
113
|
-
`/* font "${font.family}" — ${font.sizes.map(
|
|
123
|
+
`/* font "${font.family}" — ${font.sizes.map(size => `${size.pixelSize}px`).join(', ')} */`,
|
|
114
124
|
);
|
|
115
|
-
emitFontSizes(lines, font,
|
|
116
|
-
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) {
|
|
117
127
|
fontRegistrations.push(
|
|
118
|
-
` er_font_register(${JSON.stringify(font.family)}, &g_font_${
|
|
128
|
+
` er_font_register(${JSON.stringify(font.family)}, &g_font_${familyIdentifier}_${size.pixelSize});`,
|
|
119
129
|
);
|
|
120
130
|
}
|
|
121
131
|
}
|
|
@@ -123,70 +133,79 @@ export function emitAssetsC({headerName, images = [], fonts = []}) {
|
|
|
123
133
|
// --- Registration entry point ---------------------------------------------------------------
|
|
124
134
|
lines.push(`void er_register_assets(void)`);
|
|
125
135
|
lines.push(`{`);
|
|
126
|
-
for (const
|
|
127
|
-
const
|
|
128
|
-
|
|
136
|
+
for (const image of images) {
|
|
137
|
+
const loadFunction =
|
|
138
|
+
image.format === 'rgb565' ? 'er_image_load_rgb565' : 'er_image_load';
|
|
129
139
|
lines.push(
|
|
130
|
-
` ${
|
|
140
|
+
` ${loadFunction}(${JSON.stringify(image.name)}, ${cIdent(image.name)}_px, ${image.width}, ${image.height});`,
|
|
131
141
|
);
|
|
132
142
|
}
|
|
133
|
-
for (const
|
|
143
|
+
for (const registration of fontRegistrations) lines.push(registration);
|
|
134
144
|
if (images.length === 0 && fontRegistrations.length === 0) {
|
|
135
145
|
lines.push(` /* no baked assets */`);
|
|
136
146
|
}
|
|
137
147
|
lines.push(`}`);
|
|
138
148
|
lines.push(``);
|
|
139
149
|
|
|
140
|
-
return {c: lines.join('\n'), h};
|
|
150
|
+
return {c: lines.join('\n'), h: header};
|
|
141
151
|
}
|
|
142
152
|
|
|
143
153
|
/** Emits the per-size BitmapFont blocks (bitmap + glyphs + extras + struct) for one font. */
|
|
144
154
|
function emitFontSizes(lines, font, symbol, fontStorage) {
|
|
145
|
-
for (const
|
|
146
|
-
const prefix = `s_${symbol}_${
|
|
147
|
-
const hex =
|
|
148
|
-
|
|
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'),
|
|
160
|
+
);
|
|
161
|
+
lines.push(
|
|
162
|
+
`static const uint8_t ${prefix}_bitmap[${size.bitmap.length || 1}] = {`,
|
|
149
163
|
);
|
|
150
164
|
lines.push(
|
|
151
|
-
|
|
165
|
+
size.bitmap.length ? rows(hex, BITMAP_BYTES_PER_LINE) : ' 0x00,',
|
|
152
166
|
);
|
|
153
|
-
lines.push(sz.bitmap.length ? rows(hex, 16) : ' 0x00,');
|
|
154
167
|
lines.push(`};`);
|
|
155
168
|
lines.push(``);
|
|
156
169
|
|
|
157
170
|
lines.push(
|
|
158
|
-
`static const GlyphInfo ${prefix}_glyphs[${
|
|
171
|
+
`static const GlyphInfo ${prefix}_glyphs[${size.dense.length}] = {`,
|
|
159
172
|
);
|
|
160
|
-
for (const
|
|
173
|
+
for (const glyph of size.dense) lines.push(` ${glyphInit(glyph)},`);
|
|
161
174
|
lines.push(`};`);
|
|
162
175
|
lines.push(``);
|
|
163
176
|
|
|
164
|
-
if (
|
|
177
|
+
if (size.extras.length) {
|
|
165
178
|
lines.push(
|
|
166
|
-
`static const ExtraGlyph ${prefix}_extras[${
|
|
179
|
+
`static const ExtraGlyph ${prefix}_extras[${size.extras.length}] = {`,
|
|
167
180
|
);
|
|
168
|
-
for (const
|
|
181
|
+
for (const extra of size.extras) {
|
|
169
182
|
lines.push(
|
|
170
|
-
` { .codepoint = 0x${
|
|
183
|
+
` { .codepoint = 0x${extra.codepoint.toString(16).toUpperCase()}, .info = ${glyphInit(extra.info)} },`,
|
|
171
184
|
);
|
|
172
185
|
}
|
|
173
186
|
lines.push(`};`);
|
|
174
187
|
lines.push(``);
|
|
175
188
|
}
|
|
176
189
|
|
|
177
|
-
lines.push(
|
|
190
|
+
lines.push(
|
|
191
|
+
`${fontStorage}BitmapFont g_font_${symbol}_${size.pixelSize} = {`,
|
|
192
|
+
);
|
|
178
193
|
lines.push(` .bitmap = ${prefix}_bitmap,`);
|
|
179
194
|
lines.push(` .glyphs = ${prefix}_glyphs,`);
|
|
180
195
|
lines.push(
|
|
181
|
-
` .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()},`,
|
|
182
204
|
);
|
|
183
|
-
lines.push(` .
|
|
184
|
-
lines.push(` .
|
|
185
|
-
lines.push(` .
|
|
186
|
-
lines.push(` .
|
|
187
|
-
lines.push(` .line_height = ${sz.lineHeight},`);
|
|
188
|
-
lines.push(` .baseline = ${sz.baseline},`);
|
|
189
|
-
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},`);
|
|
190
209
|
lines.push(`};`);
|
|
191
210
|
lines.push(``);
|
|
192
211
|
}
|
|
@@ -204,14 +223,14 @@ function emitFontSizes(lines, font, symbol, fontStorage) {
|
|
|
204
223
|
* @returns {string} The .c source text.
|
|
205
224
|
*/
|
|
206
225
|
export function emitBuiltinFont({font, symbol = 'inter', sourceName = ''}) {
|
|
207
|
-
const
|
|
208
|
-
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;
|
|
209
228
|
const lines = [];
|
|
210
229
|
lines.push(
|
|
211
230
|
`/* AUTO-GENERATED by packages/embedded-react/assets/build-builtin-font.mjs — do not edit by hand.`,
|
|
212
231
|
);
|
|
213
232
|
lines.push(` * Source : ${sourceName}`);
|
|
214
|
-
lines.push(` * Sizes : ${
|
|
233
|
+
lines.push(` * Sizes : ${sizeList} (bpp ${bpp}, family "${font.family}")`);
|
|
215
234
|
lines.push(
|
|
216
235
|
` * Regenerate: cd packages/embedded-react && npm run build:builtin-font`,
|
|
217
236
|
);
|
|
@@ -223,8 +242,8 @@ export function emitBuiltinFont({font, symbol = 'inter', sourceName = ''}) {
|
|
|
223
242
|
emitFontSizes(lines, font, symbol, 'const '); // file-scope const: referenced by g_<symbol>_sizes
|
|
224
243
|
|
|
225
244
|
lines.push(`const BitmapFont *const g_${symbol}_sizes[] = {`);
|
|
226
|
-
for (const
|
|
227
|
-
lines.push(` &g_font_${symbol}_${
|
|
245
|
+
for (const size of font.sizes)
|
|
246
|
+
lines.push(` &g_font_${symbol}_${size.pixelSize},`);
|
|
228
247
|
lines.push(`};`);
|
|
229
248
|
lines.push(
|
|
230
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;
|
|
@@ -61,18 +71,18 @@ export const SECTION_VENDOR_BYTECODE = 3;
|
|
|
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
|
}
|