embedded-react 0.21.0 → 0.22.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.
Files changed (99) hide show
  1. package/README.md +2 -2
  2. package/aot/compile.mjs +1 -1
  3. package/aot/compiler/alerts.mjs +604 -0
  4. package/aot/compiler/check.mjs +1 -1
  5. package/aot/compiler/collect.mjs +1 -1
  6. package/aot/compiler/elements/button.mjs +3 -3
  7. package/aot/compiler/elements/image-background.mjs +1 -1
  8. package/aot/compiler/elements/props.mjs +10 -6
  9. package/aot/compiler/elements/section-list.mjs +1 -1
  10. package/aot/compiler/expressions.mjs +29 -2
  11. package/aot/compiler/handlers.mjs +73 -16
  12. package/aot/compiler/keyboard-dismiss.mjs +99 -0
  13. package/aot/compiler/keyboard.mjs +1 -1
  14. package/aot/compiler/lower.mjs +12 -0
  15. package/aot/compiler/nodes.mjs +17 -9
  16. package/aot/compiler/out.mjs +4 -0
  17. package/aot/compiler/package/codegen.mjs +36 -2
  18. package/aot/compiler/package/format.mjs +5 -3
  19. package/aot/compiler/package/lower.mjs +53 -19
  20. package/aot/compiler/scroll-to.mjs +112 -0
  21. package/aot/compiler/style-text.mjs +2 -2
  22. package/aot/compiler/svg.mjs +6 -3
  23. package/aot/compiler/updaters.mjs +1 -0
  24. package/aot/style-map.mjs +44 -1
  25. package/assets/bake-font.mjs +187 -244
  26. package/assets/bake-image.mjs +47 -71
  27. package/assets/bake-svg.mjs +465 -533
  28. package/assets/build-builtin-font.mjs +14 -27
  29. package/assets/emit-c.mjs +124 -204
  30. package/assets/emit-container.mjs +129 -197
  31. package/assets/emit-pack.mjs +92 -136
  32. package/assets/font-config.mjs +19 -27
  33. package/assets/font-sizes.mjs +432 -507
  34. package/assets/glyph-coverage.mjs +170 -214
  35. package/assets/index.mjs +52 -97
  36. package/assets/rasterize.mjs +173 -194
  37. package/assets/svg-loader.mjs +42 -48
  38. package/build.mjs +84 -101
  39. package/cli.mjs +482 -621
  40. package/compile-bin.mjs +24 -36
  41. package/flash.mjs +297 -401
  42. package/hotreload/dev-device.mjs +229 -270
  43. package/hotreload/pack-app.mjs +118 -159
  44. package/hotreload/pack-split.mjs +144 -200
  45. package/hotreload/package-transfer.mjs +128 -131
  46. package/hotreload/protocol.mjs +118 -118
  47. package/hotreload/uploader.mjs +132 -159
  48. package/hotreload/watch-tree.mjs +56 -65
  49. package/pack-container.mjs +93 -123
  50. package/package.json +19 -16
  51. package/persist-transform.mjs +89 -105
  52. package/qjsc-wasm.mjs +47 -72
  53. package/sim/embedded-react.wasm +0 -0
  54. package/sim/index.html +1 -1
  55. package/sim-server.mjs +260 -354
  56. package/src/embedded-react/Alert.mjs +112 -0
  57. package/src/embedded-react/Animated.mjs +412 -0
  58. package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
  59. package/src/embedded-react/{Button.js → Button.mjs} +29 -53
  60. package/src/embedded-react/{Dimensions.js → Dimensions.mjs} +12 -17
  61. package/src/embedded-react/Easing.mjs +34 -0
  62. package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
  63. package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
  64. package/src/embedded-react/Keyboard.mjs +82 -0
  65. package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
  66. package/src/embedded-react/PanResponder.mjs +256 -0
  67. package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
  68. package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
  69. package/src/embedded-react/SectionList.mjs +103 -0
  70. package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
  71. package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
  72. package/src/embedded-react/background-image.mjs +321 -0
  73. package/src/embedded-react/{components.js → components.mjs} +1 -3
  74. package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
  75. package/src/embedded-react/index.d.ts +155 -2
  76. package/src/embedded-react/index.js +26 -19
  77. package/src/embedded-react/layout-anim-config.mjs +85 -0
  78. package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
  79. package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
  80. package/src/embedded-react/nativeModule.mjs +371 -0
  81. package/src/embedded-react/split-style.mjs +57 -0
  82. package/src/embedded-react/svg-ops.mjs +1075 -0
  83. package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
  84. package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
  85. package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
  86. package/src/host-config.mjs +512 -0
  87. package/src/{native-ui.js → native-ui.mjs} +1 -8
  88. package/src/props.mjs +341 -0
  89. package/src/{renderer.js → renderer.mjs} +30 -44
  90. package/src/embedded-react/Animated.js +0 -440
  91. package/src/embedded-react/Easing.js +0 -39
  92. package/src/embedded-react/PanResponder.js +0 -330
  93. package/src/embedded-react/SectionList.js +0 -146
  94. package/src/embedded-react/layout-anim-config.js +0 -101
  95. package/src/embedded-react/nativeModule.js +0 -462
  96. package/src/embedded-react/split-style.js +0 -58
  97. package/src/embedded-react/svg-ops.js +0 -1295
  98. package/src/host-config.js +0 -548
  99. package/src/props.js +0 -306
@@ -13,7 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
-
17
16
  // Regenerates the engine's built-in font (engine/font/font_data.c) from assets/fonts/Inter-Regular.ttf
18
17
  // using the same JS bakers as app assets — this is the single source of truth for the built-in font
19
18
  // (there is no Python step). font_registry.c falls back to g_inter_sizes[] for any text without a
@@ -23,40 +22,28 @@
23
22
  //
24
23
  // Regenerating changes glyph metrics slightly vs a prior rasterizer, so re-run the engine text tests
25
24
  // (test_text, yoga_parity) and re-flash to eyeball on-device after changing it.
26
- import {resolve, dirname} from 'node:path';
27
- import {fileURLToPath} from 'node:url';
28
- import {writeFileSync} from 'node:fs';
29
- import {bakeFont, BUILTIN_EXTRAS, BUILTIN_SIZES} from './bake-font.mjs';
30
- import {emitBuiltinFont} from './emit-c.mjs';
31
-
25
+ import { resolve, dirname } from 'node:path';
26
+ import { fileURLToPath } from 'node:url';
27
+ import { writeFileSync } from 'node:fs';
28
+ import { bakeFont, BUILTIN_EXTRAS, BUILTIN_SIZES } from './bake-font.mjs';
29
+ import { emitBuiltinFont } from './emit-c.mjs';
32
30
  const here = dirname(fileURLToPath(import.meta.url)); // packages/embedded-react/assets
33
31
  const repoRoot = resolve(here, '../../..');
34
32
  const FONT_PATH = resolve(repoRoot, 'assets/fonts/Inter-Regular.ttf');
35
33
  const OUTPUT_PATH = resolve(repoRoot, 'engine/font/font_data.c');
36
34
  const BITS_PER_PIXEL = 4;
37
-
38
35
  // The built-in covers printable ASCII plus a fixed set of common symbols (degrees, arrows, math,
39
36
  // punctuation, etc.) the UI components rely on — kept stable across regenerations. The set lives in
40
- // bake-font.mjs as BUILTIN_EXTRAS — with BUILTIN_SIZES alongside it — so the build-time coverage
37
+ // bake-font.mts as BUILTIN_EXTRAS — with BUILTIN_SIZES alongside it — so the build-time coverage
41
38
  // checks report against what is actually baked here.
42
39
  const SIZES = BUILTIN_SIZES;
43
-
44
40
  const font = bakeFont({
45
- path: FONT_PATH,
46
- family: 'Inter',
47
- sizes: SIZES,
48
- bpp: BITS_PER_PIXEL,
49
- glyphs: BUILTIN_EXTRAS,
41
+ path: FONT_PATH,
42
+ family: 'Inter',
43
+ sizes: SIZES,
44
+ bpp: BITS_PER_PIXEL,
45
+ glyphs: BUILTIN_EXTRAS,
50
46
  });
51
- writeFileSync(
52
- OUTPUT_PATH,
53
- emitBuiltinFont({font, symbol: 'inter', sourceName: 'Inter-Regular.ttf'}),
54
- );
55
-
56
- const bitmapBytes = font.sizes.reduce(
57
- (total, size) => total + size.bitmap.length,
58
- 0,
59
- );
60
- console.log(
61
- `Regenerated ${OUTPUT_PATH}\n ${SIZES.length} sizes [${SIZES.join(',')}], bpp ${BITS_PER_PIXEL}, ${font.sizes[0].extras.length} extra glyphs, ${bitmapBytes} bitmap bytes`,
62
- );
47
+ writeFileSync(OUTPUT_PATH, emitBuiltinFont({ font, symbol: 'inter', sourceName: 'Inter-Regular.ttf' }));
48
+ const bitmapBytes = font.sizes.reduce((total, size) => total + size.bitmap.length, 0);
49
+ console.log(`Regenerated ${OUTPUT_PATH}\n ${SIZES.length} sizes [${SIZES.join(',')}], bpp ${BITS_PER_PIXEL}, ${font.sizes[0].extras.length} extra glyphs, ${bitmapBytes} bitmap bytes`);
package/assets/emit-c.mjs CHANGED
@@ -13,12 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
-
17
- // Emits the generated C for baked assets: one .c with the image pixel arrays + font BitmapFont data,
18
- // and one .h declaring er_register_assets(). The .c depends only on the public engine header
19
- // (er_scene.h, which exposes both er_image_load/er_font_register and the BitmapFont format), so it
20
- // drops into any target's build the same way the bundle does.
21
-
22
16
  const ARGB8888_HEX_DIGITS = 8;
23
17
  const RGB565_HEX_DIGITS = 4;
24
18
  const BYTE_HEX_DIGITS = 2;
@@ -26,228 +20,154 @@ const ARGB8888_WORDS_PER_LINE = 8;
26
20
  const RGB565_WORDS_PER_LINE = 12;
27
21
  const BITMAP_BYTES_PER_LINE = 16;
28
22
  const DEFAULT_BPP = 4;
29
-
30
23
  /** Sanitizes an asset/family name into a C identifier fragment. */
31
24
  function cIdent(name) {
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';
25
+ let identifier = String(name).replace(/[^0-9a-zA-Z_]/g, '_');
26
+ if (identifier && /[0-9]/.test(identifier[0]))
27
+ identifier = '_' + identifier;
28
+ return identifier || '_asset';
35
29
  }
36
-
37
30
  /** Formats an array of byte/word strings into wrapped C initializer lines. */
38
31
  function rows(values, perLine, indent = ' ') {
39
- const lines = [];
40
- for (let start = 0; start < values.length; start += perLine) {
41
- lines.push(indent + values.slice(start, start + perLine).join(', ') + ',');
42
- }
43
- return lines.join('\n');
32
+ const lines = [];
33
+ for (let start = 0; start < values.length; start += perLine) {
34
+ lines.push(indent + values.slice(start, start + perLine).join(', ') + ',');
35
+ }
36
+ return lines.join('\n');
44
37
  }
45
-
46
38
  /** Emits the GlyphInfo designated-initializer for one glyph. */
47
39
  function glyphInit(glyph) {
48
- return (
49
- `{ .bitmap_offset = ${glyph.bitmapOffset}, .width = ${glyph.width}, .height = ${glyph.height}, ` +
50
- `.x_offset = ${glyph.xOffset}, .y_offset = ${glyph.yOffset}, .advance = ${glyph.advance} }`
51
- );
40
+ return (`{ .bitmap_offset = ${glyph.bitmapOffset}, .width = ${glyph.width}, .height = ${glyph.height}, ` +
41
+ `.x_offset = ${glyph.xOffset}, .y_offset = ${glyph.yOffset}, .advance = ${glyph.advance} }`);
52
42
  }
53
-
54
43
  /**
55
44
  * Builds the .c and .h text for a set of baked images and fonts.
56
45
  *
57
- * @param {object} opts
58
- * @param {string} opts.headerName Basename of the .h (for the .c's #include).
59
- * @param {Array<object>} [opts.images] Results from bakeImage().
60
- * @param {Array<object>} [opts.fonts] Results from bakeFont().
61
- * @returns {{c:string, h:string}}
46
+ * headerName is the basename of the .h, for the .c's #include.
62
47
  */
63
- export function emitAssetsC({headerName, images = [], fonts = []}) {
64
- const guard = 'ER_' + cIdent(headerName).toUpperCase();
65
- const header =
66
- `/* Generated by packages/embedded-react/assets — DO NOT EDIT. */\n` +
67
- `#ifndef ${guard}\n#define ${guard}\n\n` +
68
- `#ifdef __cplusplus\nextern "C"\n{\n#endif\n\n` +
69
- ` /** @brief Registers every baked image and font with the engine (call once at boot, after\n` +
70
- ` * embedded_renderer_set_backend()). */\n` +
71
- ` void er_register_assets(void);\n\n` +
72
- `#ifdef __cplusplus\n}\n#endif\n\n` +
73
- `#endif\n`;
74
-
75
- const lines = [];
76
- lines.push(
77
- `/* Generated by packages/embedded-react/assets — DO NOT EDIT. */`,
78
- );
79
- lines.push(
80
- `/* Images: premultiplied ARGB8888 (or RGB565 when baked 16-bit), referenced by pointer. Fonts: baked BitmapFont per size. */`,
81
- );
82
- lines.push(``);
83
- lines.push(`#include "${headerName}"`);
84
- lines.push(
85
- `#include "er_scene.h" /* er_image_load, er_font_register, BitmapFont */`,
86
- );
87
- lines.push(`#include <stddef.h>`);
88
- lines.push(`#include <stdint.h>`);
89
- lines.push(``);
90
-
91
- // --- Images ---------------------------------------------------------------------------------
92
- for (const image of images) {
93
- const identifier = cIdent(image.name);
94
- const is565 = image.format === 'rgb565';
95
- const hex = Array.from(
96
- image.pixels,
97
- pixel =>
98
- '0x' +
99
- pixel
100
- .toString(16)
101
- .toUpperCase()
102
- .padStart(is565 ? RGB565_HEX_DIGITS : ARGB8888_HEX_DIGITS, '0') +
103
- 'u',
104
- );
105
- lines.push(
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[] = {`,
110
- );
111
- lines.push(
112
- rows(hex, is565 ? RGB565_WORDS_PER_LINE : ARGB8888_WORDS_PER_LINE),
113
- );
114
- lines.push(`};`);
48
+ export function emitAssetsC({ headerName, images = [], fonts = [], }) {
49
+ const guard = 'ER_' + cIdent(headerName).toUpperCase();
50
+ const header = `/* Generated by packages/embedded-react/assets — DO NOT EDIT. */\n` +
51
+ `#ifndef ${guard}\n#define ${guard}\n\n` +
52
+ `#ifdef __cplusplus\nextern "C"\n{\n#endif\n\n` +
53
+ ` /** @brief Registers every baked image and font with the engine (call once at boot, after\n` +
54
+ ` * embedded_renderer_set_backend()). */\n` +
55
+ ` void er_register_assets(void);\n\n` +
56
+ `#ifdef __cplusplus\n}\n#endif\n\n` +
57
+ `#endif\n`;
58
+ const lines = [];
59
+ lines.push(`/* Generated by packages/embedded-react/assets — DO NOT EDIT. */`);
60
+ lines.push(`/* Images: premultiplied ARGB8888 (or RGB565 when baked 16-bit), referenced by pointer. Fonts: baked BitmapFont per size. */`);
115
61
  lines.push(``);
116
- }
117
-
118
- // --- Fonts ----------------------------------------------------------------------------------
119
- const fontRegistrations = [];
120
- for (const font of fonts) {
121
- const familyIdentifier = cIdent(font.family);
122
- lines.push(
123
- `/* font "${font.family}" — ${font.sizes.map(size => `${size.pixelSize}px`).join(', ')} */`,
124
- );
125
- emitFontSizes(lines, font, familyIdentifier, 'static const '); // file-local: only er_register_assets refers to these
126
- for (const size of font.sizes) {
127
- fontRegistrations.push(
128
- ` er_font_register(${JSON.stringify(font.family)}, &g_font_${familyIdentifier}_${size.pixelSize});`,
129
- );
62
+ lines.push(`#include "${headerName}"`);
63
+ lines.push(`#include "er_scene.h" /* er_image_load, er_font_register, BitmapFont */`);
64
+ lines.push(`#include <stddef.h>`);
65
+ lines.push(`#include <stdint.h>`);
66
+ lines.push(``);
67
+ // --- Images ---------------------------------------------------------------------------------
68
+ for (const image of images) {
69
+ const identifier = cIdent(image.name);
70
+ const is565 = image.format === 'rgb565';
71
+ const hex = Array.from(image.pixels, pixel => '0x' +
72
+ pixel
73
+ .toString(16)
74
+ .toUpperCase()
75
+ .padStart(is565 ? RGB565_HEX_DIGITS : ARGB8888_HEX_DIGITS, '0') +
76
+ 'u');
77
+ lines.push(`/* image "${image.name}" — ${image.width}x${image.height}${is565 ? ' (RGB565)' : ''} */`);
78
+ lines.push(`static const ${is565 ? 'uint16_t' : 'uint32_t'} ${identifier}_px[] = {`);
79
+ lines.push(rows(hex, is565 ? RGB565_WORDS_PER_LINE : ARGB8888_WORDS_PER_LINE));
80
+ lines.push(`};`);
81
+ lines.push(``);
82
+ }
83
+ // --- Fonts ----------------------------------------------------------------------------------
84
+ const fontRegistrations = [];
85
+ for (const font of fonts) {
86
+ const familyIdentifier = cIdent(font.family);
87
+ lines.push(`/* font "${font.family}" — ${font.sizes.map(size => `${size.pixelSize}px`).join(', ')} */`);
88
+ emitFontSizes(lines, font, familyIdentifier, 'static const '); // file-local: only er_register_assets refers to these
89
+ for (const size of font.sizes) {
90
+ fontRegistrations.push(` er_font_register(${JSON.stringify(font.family)}, &g_font_${familyIdentifier}_${size.pixelSize});`);
91
+ }
130
92
  }
131
- }
132
-
133
- // --- Registration entry point ---------------------------------------------------------------
134
- lines.push(`void er_register_assets(void)`);
135
- lines.push(`{`);
136
- for (const image of images) {
137
- const loadFunction =
138
- image.format === 'rgb565' ? 'er_image_load_rgb565' : 'er_image_load';
139
- lines.push(
140
- ` ${loadFunction}(${JSON.stringify(image.name)}, ${cIdent(image.name)}_px, ${image.width}, ${image.height});`,
141
- );
142
- }
143
- for (const registration of fontRegistrations) lines.push(registration);
144
- if (images.length === 0 && fontRegistrations.length === 0) {
145
- lines.push(` /* no baked assets */`);
146
- }
147
- lines.push(`}`);
148
- lines.push(``);
149
-
150
- return {c: lines.join('\n'), h: header};
93
+ // --- Registration entry point ---------------------------------------------------------------
94
+ lines.push(`void er_register_assets(void)`);
95
+ lines.push(`{`);
96
+ for (const image of images) {
97
+ const loadFunction = image.format === 'rgb565' ? 'er_image_load_rgb565' : 'er_image_load';
98
+ lines.push(` ${loadFunction}(${JSON.stringify(image.name)}, ${cIdent(image.name)}_px, ${image.width}, ${image.height});`);
99
+ }
100
+ for (const registration of fontRegistrations)
101
+ lines.push(registration);
102
+ if (images.length === 0 && fontRegistrations.length === 0) {
103
+ lines.push(` /* no baked assets */`);
104
+ }
105
+ lines.push(`}`);
106
+ lines.push(``);
107
+ return { c: lines.join('\n'), h: header };
151
108
  }
152
-
153
109
  /** Emits the per-size BitmapFont blocks (bitmap + glyphs + extras + struct) for one font. */
154
110
  function emitFontSizes(lines, font, symbol, fontStorage) {
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}] = {`,
163
- );
164
- lines.push(
165
- size.bitmap.length ? rows(hex, BITMAP_BYTES_PER_LINE) : ' 0x00,',
166
- );
167
- lines.push(`};`);
168
- lines.push(``);
169
-
170
- lines.push(
171
- `static const GlyphInfo ${prefix}_glyphs[${size.dense.length}] = {`,
172
- );
173
- for (const glyph of size.dense) lines.push(` ${glyphInit(glyph)},`);
174
- lines.push(`};`);
175
- lines.push(``);
176
-
177
- if (size.extras.length) {
178
- lines.push(
179
- `static const ExtraGlyph ${prefix}_extras[${size.extras.length}] = {`,
180
- );
181
- for (const extra of size.extras) {
182
- lines.push(
183
- ` { .codepoint = 0x${extra.codepoint.toString(16).toUpperCase()}, .info = ${glyphInit(extra.info)} },`,
184
- );
185
- }
186
- lines.push(`};`);
187
- lines.push(``);
111
+ for (const size of font.sizes) {
112
+ const prefix = `s_${symbol}_${size.pixelSize}`;
113
+ const hex = size.bitmap.map(byte => '0x' + byte.toString(16).toUpperCase().padStart(BYTE_HEX_DIGITS, '0'));
114
+ lines.push(`static const uint8_t ${prefix}_bitmap[${size.bitmap.length || 1}] = {`);
115
+ lines.push(size.bitmap.length ? rows(hex, BITMAP_BYTES_PER_LINE) : ' 0x00,');
116
+ lines.push(`};`);
117
+ lines.push(``);
118
+ lines.push(`static const GlyphInfo ${prefix}_glyphs[${size.dense.length}] = {`);
119
+ for (const glyph of size.dense)
120
+ lines.push(` ${glyphInit(glyph)},`);
121
+ lines.push(`};`);
122
+ lines.push(``);
123
+ if (size.extras.length) {
124
+ lines.push(`static const ExtraGlyph ${prefix}_extras[${size.extras.length}] = {`);
125
+ for (const extra of size.extras) {
126
+ lines.push(` { .codepoint = 0x${extra.codepoint.toString(16).toUpperCase()}, .info = ${glyphInit(extra.info)} },`);
127
+ }
128
+ lines.push(`};`);
129
+ lines.push(``);
130
+ }
131
+ lines.push(`${fontStorage}BitmapFont g_font_${symbol}_${size.pixelSize} = {`);
132
+ lines.push(` .bitmap = ${prefix}_bitmap,`);
133
+ lines.push(` .glyphs = ${prefix}_glyphs,`);
134
+ lines.push(` .extras = ${size.extras.length ? `${prefix}_extras` : 'NULL'},`);
135
+ lines.push(` .extras_count = ${size.extras.length},`);
136
+ lines.push(` .first = 0x${size.first.toString(16).toUpperCase()},`);
137
+ lines.push(` .last = 0x${size.last.toString(16).toUpperCase()},`);
138
+ lines.push(` .pixel_size = ${size.pixelSize},`);
139
+ lines.push(` .line_height = ${size.lineHeight},`);
140
+ lines.push(` .baseline = ${size.baseline},`);
141
+ lines.push(` .format = ${size.bpp},`);
142
+ lines.push(`};`);
143
+ lines.push(``);
188
144
  }
189
-
190
- lines.push(
191
- `${fontStorage}BitmapFont g_font_${symbol}_${size.pixelSize} = {`,
192
- );
193
- lines.push(` .bitmap = ${prefix}_bitmap,`);
194
- lines.push(` .glyphs = ${prefix}_glyphs,`);
195
- lines.push(
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()},`,
204
- );
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},`);
209
- lines.push(`};`);
210
- lines.push(``);
211
- }
212
145
  }
213
-
214
146
  /**
215
147
  * Emits the engine's built-in font translation unit (font_data.c format): the per-size BitmapFont
216
148
  * structs plus the `g_<symbol>_sizes[]` array + `_count` that font_registry.c falls back to. Depends
217
149
  * only on font_bitmap.h. Symbol must be 'inter' to satisfy the extern decls in font_bitmap.h.
218
150
  *
219
- * @param {object} opts
220
- * @param {object} opts.font Result of bakeFont().
221
- * @param {string} [opts.symbol] C symbol prefix (default 'inter').
222
- * @param {string} [opts.sourceName] Source font filename, for the header comment.
223
- * @returns {string} The .c source text.
151
+ * @returns The .c source text.
224
152
  */
225
- export function emitBuiltinFont({font, symbol = 'inter', sourceName = ''}) {
226
- const sizeList = font.sizes.map(size => size.pixelSize).join(',');
227
- const bpp = font.sizes[0] ? font.sizes[0].bpp : DEFAULT_BPP;
228
- const lines = [];
229
- lines.push(
230
- `/* AUTO-GENERATED by packages/embedded-react/assets/build-builtin-font.mjs — do not edit by hand.`,
231
- );
232
- lines.push(` * Source : ${sourceName}`);
233
- lines.push(` * Sizes : ${sizeList} (bpp ${bpp}, family "${font.family}")`);
234
- lines.push(
235
- ` * Regenerate: cd packages/embedded-react && npm run build:builtin-font`,
236
- );
237
- lines.push(` */`);
238
- lines.push(`#include "font_bitmap.h"`);
239
- lines.push(`#include <stddef.h>`);
240
- lines.push(``);
241
-
242
- emitFontSizes(lines, font, symbol, 'const '); // file-scope const: referenced by g_<symbol>_sizes
243
-
244
- lines.push(`const BitmapFont *const g_${symbol}_sizes[] = {`);
245
- for (const size of font.sizes)
246
- lines.push(` &g_font_${symbol}_${size.pixelSize},`);
247
- lines.push(`};`);
248
- lines.push(
249
- `const size_t g_${symbol}_sizes_count = sizeof(g_${symbol}_sizes) / sizeof(g_${symbol}_sizes[0]);`,
250
- );
251
- lines.push(``);
252
- return lines.join('\n');
153
+ export function emitBuiltinFont({ font, symbol = 'inter', sourceName = '', }) {
154
+ const sizeList = font.sizes.map(size => size.pixelSize).join(',');
155
+ const bpp = font.sizes[0] ? font.sizes[0].bpp : DEFAULT_BPP;
156
+ const lines = [];
157
+ lines.push(`/* AUTO-GENERATED by packages/embedded-react/assets/build-builtin-font.mts — do not edit by hand.`);
158
+ lines.push(` * Source : ${sourceName}`);
159
+ lines.push(` * Sizes : ${sizeList} (bpp ${bpp}, family "${font.family}")`);
160
+ lines.push(` * Regenerate: cd packages/embedded-react && npm run build:builtin-font`);
161
+ lines.push(` */`);
162
+ lines.push(`#include "font_bitmap.h"`);
163
+ lines.push(`#include <stddef.h>`);
164
+ lines.push(``);
165
+ emitFontSizes(lines, font, symbol, 'const '); // file-scope const: referenced by g_<symbol>_sizes
166
+ lines.push(`const BitmapFont *const g_${symbol}_sizes[] = {`);
167
+ for (const size of font.sizes)
168
+ lines.push(` &g_font_${symbol}_${size.pixelSize},`);
169
+ lines.push(`};`);
170
+ lines.push(`const size_t g_${symbol}_sizes_count = sizeof(g_${symbol}_sizes) / sizeof(g_${symbol}_sizes[0]);`);
171
+ lines.push(``);
172
+ return lines.join('\n');
253
173
  }