embedded-react 0.12.0 → 0.13.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 +144 -5
- package/aot/compile.mjs +1222 -72
- package/aot/style-map.mjs +10 -5
- package/assets/bake-font.mjs +104 -12
- package/assets/bake-svg.mjs +11 -1
- package/assets/build-builtin-font.mjs +6 -12
- package/assets/emit-c.mjs +10 -2
- package/assets/font-config.mjs +49 -0
- package/assets/font-sizes.mjs +652 -0
- package/assets/glyph-coverage.mjs +281 -0
- package/assets/index.mjs +29 -5
- package/build.mjs +11 -21
- package/cli.mjs +13 -1
- package/compile-bin.mjs +71 -0
- package/hotreload/pack-app.mjs +8 -21
- package/hotreload/pack-split.mjs +12 -27
- package/pack-container.mjs +10 -47
- package/package.json +2 -1
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +32 -3
- package/sim-server.mjs +33 -27
- package/src/embedded-react/Animated.js +23 -9
- package/src/embedded-react/Button.js +98 -0
- package/src/embedded-react/FlatList.js +88 -0
- package/src/embedded-react/ImageBackground.js +67 -0
- package/src/embedded-react/PanResponder.js +326 -0
- package/src/embedded-react/SectionList.js +148 -0
- package/src/embedded-react/TouchableOpacity.js +152 -0
- package/src/embedded-react/components.js +4 -3
- package/src/embedded-react/index.d.ts +866 -60
- package/src/embedded-react/index.js +7 -2
- package/src/embedded-react/list-child.js +54 -0
- package/src/embedded-react/svg-ops.js +220 -72
- package/src/embedded-react/warn-props.js +80 -0
- package/src/host-config.js +98 -3
- package/src/props.js +38 -0
package/aot/style-map.mjs
CHANGED
|
@@ -118,7 +118,8 @@ const dim = v => {
|
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
120
|
* A dimension that may be a percentage. `'50%'` → the engine's float `*_pct` field (% of the parent);
|
|
121
|
-
* a number → the pixel field. Used for width / height / flexBasis
|
|
121
|
+
* a number → the pixel field. Used for width / height / flexBasis and the four insets, all of which the
|
|
122
|
+
* engine resolves at layout.
|
|
122
123
|
*
|
|
123
124
|
* @param {string} pxField ERProps pixel field (e.g. 'width').
|
|
124
125
|
* @param {string} pctField ERProps percentage field (e.g. 'width_pct').
|
|
@@ -130,6 +131,9 @@ const pctOrPx = (pxField, pctField) => v => {
|
|
|
130
131
|
throw new Error(
|
|
131
132
|
`expected a percentage like '50%', got ${JSON.stringify(v)}`,
|
|
132
133
|
);
|
|
134
|
+
// 0% of any box is 0px, and the engine reads 0.0 in a percentage field as "not set" — so lower an
|
|
135
|
+
// authored 0% onto the pixel field, where it still means the same thing.
|
|
136
|
+
if (n === 0) return [{field: pxField, expr: '0'}];
|
|
133
137
|
// A valid C float literal needs a decimal point — `50f` is a syntax error, `50.0f` is not.
|
|
134
138
|
const lit = Number.isInteger(n) ? `${n}.0f` : `${n}f`;
|
|
135
139
|
return [{field: pctField, expr: lit}];
|
|
@@ -185,10 +189,10 @@ const KEYS = {
|
|
|
185
189
|
// Positioning: `position: 'absolute'` takes a node out of flow; left/top/right/bottom are its anchors.
|
|
186
190
|
position: v => [{field: 'position', expr: enumKey(POSITION, 'position')(v)}],
|
|
187
191
|
display: v => [{field: 'display', expr: enumKey(DISPLAY, 'display')(v)}],
|
|
188
|
-
left:
|
|
189
|
-
top:
|
|
190
|
-
right:
|
|
191
|
-
bottom:
|
|
192
|
+
left: pctOrPx('left', 'left_pct'),
|
|
193
|
+
top: pctOrPx('top', 'top_pct'),
|
|
194
|
+
right: pctOrPx('right', 'right_pct'),
|
|
195
|
+
bottom: pctOrPx('bottom', 'bottom_pct'),
|
|
192
196
|
// `flex: n` → grow=n, shrink=1, basis=0 (RN semantics; matches native_ui_bridge apply_flex).
|
|
193
197
|
flex: v => {
|
|
194
198
|
const n = Number(v);
|
|
@@ -257,6 +261,7 @@ export const NODE_TYPES = {
|
|
|
257
261
|
View: 'ER_NODE_VIEW',
|
|
258
262
|
Text: 'ER_NODE_TEXT',
|
|
259
263
|
Pressable: 'ER_NODE_PRESSABLE',
|
|
264
|
+
TouchableOpacity: 'ER_NODE_PRESSABLE',
|
|
260
265
|
Image: 'ER_NODE_IMAGE',
|
|
261
266
|
ScrollView: 'ER_NODE_SCROLL_VIEW',
|
|
262
267
|
};
|
package/assets/bake-font.mjs
CHANGED
|
@@ -58,26 +58,109 @@ const SYMBOL_SETS = {
|
|
|
58
58
|
),
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
+
// The engine's built-in font (engine/font/font_data.c) covers printable ASCII plus these. It is its
|
|
62
|
+
// own list, not an alias of a named set: build-builtin-font.mjs bakes from it and the coverage check
|
|
63
|
+
// reports against it, so the two can never drift — while the named sets stay free to evolve.
|
|
64
|
+
// Changing it changes the engine's fallback font; re-run `npm run build:builtin-font` if you do.
|
|
65
|
+
export const BUILTIN_EXTRAS = Object.freeze([
|
|
66
|
+
0x00a2, 0x00a3, 0x00a5, 0x00a7, 0x00a9, 0x00ae, 0x00b0, 0x00b1, 0x00b5,
|
|
67
|
+
0x00d7, 0x00f7, 0x2013, 0x2014, 0x2018, 0x2019, 0x201c, 0x201d, 0x2020,
|
|
68
|
+
0x2021, 0x2022, 0x2026, 0x2030, 0x20ac, 0x2122, 0x2190, 0x2191, 0x2192,
|
|
69
|
+
0x2193, 0x2194, 0x21b5, 0x2202, 0x2206, 0x2211, 0x2212, 0x221a, 0x221e,
|
|
70
|
+
0x2248, 0x2260, 0x2264, 0x2265, 0x25a0, 0x25c6, 0x25cf, 0x2605, 0x2606,
|
|
71
|
+
0x2713, 0x2717,
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Pixel sizes the engine's built-in font is baked at (engine/font/font_data.c). Like BUILTIN_EXTRAS
|
|
76
|
+
* this is the single source of truth: build-builtin-font.mjs bakes from it and the build-time size
|
|
77
|
+
* check reports against it, so an app rendering at some other size is told what it will snap to.
|
|
78
|
+
* Changing it changes the engine's fallback font; re-run `npm run build:builtin-font` if you do.
|
|
79
|
+
*/
|
|
80
|
+
export const BUILTIN_SIZES = Object.freeze([10, 12, 16, 20, 24, 32, 48]);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Normalizes one codepoint list: numbers are codepoints, a string contributes every character in
|
|
84
|
+
* it — so `'°±'` and `[0x00b0, 0x00b1]` mean the same thing.
|
|
85
|
+
*
|
|
86
|
+
* @param {number|string|Array<number|string>|undefined} spec
|
|
87
|
+
* @param {string} field Config field name, for error messages.
|
|
88
|
+
* @returns {number[]} Codepoints, unsorted and possibly duplicated.
|
|
89
|
+
*/
|
|
90
|
+
function toCodepoints(spec, field) {
|
|
91
|
+
if (spec === undefined || spec === null) return [];
|
|
92
|
+
const out = [];
|
|
93
|
+
for (const item of Array.isArray(spec) ? spec : [spec]) {
|
|
94
|
+
if (typeof item === 'string') {
|
|
95
|
+
for (const ch of item) out.push(ch.codePointAt(0));
|
|
96
|
+
} else if (
|
|
97
|
+
typeof item === 'number' &&
|
|
98
|
+
Number.isInteger(item) &&
|
|
99
|
+
item >= 0 &&
|
|
100
|
+
item <= 0x10ffff
|
|
101
|
+
) {
|
|
102
|
+
out.push(item);
|
|
103
|
+
} else {
|
|
104
|
+
throw new Error(
|
|
105
|
+
`${field}: expected a codepoint number or a string of characters, got ${JSON.stringify(item)}`,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
|
|
61
112
|
/**
|
|
62
113
|
* Resolves a glyph-coverage spec into a sorted list of extra (sparse) codepoints.
|
|
63
114
|
*
|
|
64
|
-
*
|
|
115
|
+
* `glyphs` picks the baseline: 'ascii' (none), a named set, or an explicit list. `extraGlyphs` adds
|
|
116
|
+
* the per-app characters no named set can cover, as codepoints or as the characters themselves.
|
|
117
|
+
*
|
|
118
|
+
* @param {string|Array<number|string>|undefined} glyphs 'ascii', a named set, or explicit codepoints.
|
|
119
|
+
* @param {number|string|Array<number|string>} [extraGlyphs] Per-app additions, on top of `glyphs`.
|
|
65
120
|
* @returns {number[]} Sorted extra codepoints outside the dense ASCII range.
|
|
66
121
|
*/
|
|
67
|
-
export function resolveExtras(glyphs) {
|
|
68
|
-
if (!glyphs || glyphs === 'ascii') return [];
|
|
122
|
+
export function resolveExtras(glyphs, extraGlyphs) {
|
|
69
123
|
let cps;
|
|
70
|
-
if (
|
|
71
|
-
else if (
|
|
72
|
-
|
|
124
|
+
if (!glyphs || glyphs === 'ascii') cps = [];
|
|
125
|
+
else if (typeof glyphs === 'string') {
|
|
126
|
+
if (!SYMBOL_SETS[glyphs])
|
|
127
|
+
throw new Error(
|
|
128
|
+
`unknown glyph set "${glyphs}" (use 'ascii', one of [${Object.keys(SYMBOL_SETS).join(', ')}], or a list of codepoints/characters)`,
|
|
129
|
+
);
|
|
130
|
+
cps = SYMBOL_SETS[glyphs].slice();
|
|
131
|
+
} else cps = toCodepoints(glyphs, 'glyphs');
|
|
132
|
+
|
|
133
|
+
// A bare set name here is almost certainly meant for `glyphs` — as characters it would be a
|
|
134
|
+
// silent no-op (all ASCII), so say so instead of baking nothing.
|
|
135
|
+
if (typeof extraGlyphs === 'string' && SYMBOL_SETS[extraGlyphs])
|
|
73
136
|
throw new Error(
|
|
74
|
-
`
|
|
137
|
+
`extraGlyphs: "${extraGlyphs}" is a named glyph set — put it in \`glyphs\` (extraGlyphs takes the characters themselves)`,
|
|
75
138
|
);
|
|
139
|
+
cps.push(...toCodepoints(extraGlyphs, 'extraGlyphs'));
|
|
140
|
+
|
|
76
141
|
return [...new Set(cps)]
|
|
77
142
|
.filter(c => c < ASCII_FIRST || c > ASCII_LAST)
|
|
78
143
|
.sort((a, b) => a - b);
|
|
79
144
|
}
|
|
80
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Opens a font file and returns a predicate for "does this file have a glyph for this codepoint?".
|
|
148
|
+
* The coverage check uses it to tell a missing bake ("add it to extraGlyphs") apart from a font that
|
|
149
|
+
* simply cannot draw the character ("pick a different font").
|
|
150
|
+
*
|
|
151
|
+
* @param {string} path Path to the .ttf/.otf file.
|
|
152
|
+
* @returns {(cp:number)=>boolean} Always true if the file can't be read, so a probe failure never
|
|
153
|
+
* turns into a misleading claim about the font.
|
|
154
|
+
*/
|
|
155
|
+
export function loadGlyphProbe(path) {
|
|
156
|
+
try {
|
|
157
|
+
const font = opentype.parse(fs.readFileSync(path).buffer);
|
|
158
|
+
return cp => font.charToGlyphIndex(String.fromCodePoint(cp)) !== 0;
|
|
159
|
+
} catch {
|
|
160
|
+
return () => true;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
81
164
|
/**
|
|
82
165
|
* Packs an 8-bit coverage bitmap (one byte per pixel) into the engine's per-row bpp layout.
|
|
83
166
|
*
|
|
@@ -155,14 +238,23 @@ function bakeGlyph(font, cp, pixelSize, baseline, scale, bpp) {
|
|
|
155
238
|
* @param {string} opts.family Family name to register under (used by fontFamily lookups).
|
|
156
239
|
* @param {number[]} opts.sizes Pixel sizes to bake.
|
|
157
240
|
* @param {number} [opts.bpp] Bits per pixel (default 4).
|
|
158
|
-
* @param {string|Array<number>} [opts.glyphs] Extra glyph coverage beyond ASCII (default 'ascii').
|
|
159
|
-
* @
|
|
241
|
+
* @param {string|Array<number|string>} [opts.glyphs] Extra glyph coverage beyond ASCII (default 'ascii').
|
|
242
|
+
* @param {number|string|Array<number|string>} [opts.extraGlyphs] Per-app additions on top of `glyphs`.
|
|
243
|
+
* @returns {{family:string, path:string, sizes:Array<object>}} Baked data ready for the C emitter.
|
|
244
|
+
* Extras the font file has no glyph for are silently absent from each size's `extras`.
|
|
160
245
|
*/
|
|
161
|
-
export function bakeFont({
|
|
246
|
+
export function bakeFont({
|
|
247
|
+
path,
|
|
248
|
+
family,
|
|
249
|
+
sizes,
|
|
250
|
+
bpp = 4,
|
|
251
|
+
glyphs = 'ascii',
|
|
252
|
+
extraGlyphs,
|
|
253
|
+
}) {
|
|
162
254
|
if (![1, 2, 4, 8].includes(bpp))
|
|
163
255
|
throw new Error(`bpp must be 1, 2, 4, or 8 (got ${bpp})`);
|
|
164
256
|
const font = opentype.parse(fs.readFileSync(path).buffer);
|
|
165
|
-
const extraCps = resolveExtras(glyphs);
|
|
257
|
+
const extraCps = resolveExtras(glyphs, extraGlyphs);
|
|
166
258
|
|
|
167
259
|
const baked = [];
|
|
168
260
|
for (const pixelSize of sizes) {
|
|
@@ -210,5 +302,5 @@ export function bakeFont({path, family, sizes, bpp = 4, glyphs = 'ascii'}) {
|
|
|
210
302
|
bitmap,
|
|
211
303
|
});
|
|
212
304
|
}
|
|
213
|
-
return {family, sizes: baked};
|
|
305
|
+
return {family, path, sizes: baked};
|
|
214
306
|
}
|
package/assets/bake-svg.mjs
CHANGED
|
@@ -33,6 +33,7 @@ import {createHash} from 'node:crypto';
|
|
|
33
33
|
import {
|
|
34
34
|
parsePath,
|
|
35
35
|
parseColor,
|
|
36
|
+
rectRadii,
|
|
36
37
|
VOP_SHAPE,
|
|
37
38
|
VOP_MOVE,
|
|
38
39
|
VOP_LINE,
|
|
@@ -148,7 +149,16 @@ function rectPath(a) {
|
|
|
148
149
|
const w = num(a.width);
|
|
149
150
|
const h = num(a.height);
|
|
150
151
|
if (w <= 0 || h <= 0) return '';
|
|
151
|
-
|
|
152
|
+
const [rx, ry] = rectRadii(a.rx, a.ry, w, h);
|
|
153
|
+
if (!rx || !ry)
|
|
154
|
+
return `M${x} ${y}L${x + w} ${y}L${x + w} ${y + h}L${x} ${y + h}Z`;
|
|
155
|
+
// Quarter-ellipse corners; parsePath lowers each `A` to the same single cubic the runtime emits.
|
|
156
|
+
return (
|
|
157
|
+
`M${x + rx} ${y}L${x + w - rx} ${y}A${rx} ${ry} 0 0 1 ${x + w} ${y + ry}` +
|
|
158
|
+
`L${x + w} ${y + h - ry}A${rx} ${ry} 0 0 1 ${x + w - rx} ${y + h}` +
|
|
159
|
+
`L${x + rx} ${y + h}A${rx} ${ry} 0 0 1 ${x} ${y + h - ry}` +
|
|
160
|
+
`L${x} ${y + ry}A${rx} ${ry} 0 0 1 ${x + rx} ${y}Z`
|
|
161
|
+
);
|
|
152
162
|
}
|
|
153
163
|
function circlePath(a) {
|
|
154
164
|
const cx = num(a.cx);
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
import {resolve, dirname} from 'node:path';
|
|
27
27
|
import {fileURLToPath} from 'node:url';
|
|
28
28
|
import {writeFileSync} from 'node:fs';
|
|
29
|
-
import {bakeFont} from './bake-font.mjs';
|
|
29
|
+
import {bakeFont, BUILTIN_EXTRAS, BUILTIN_SIZES} from './bake-font.mjs';
|
|
30
30
|
import {emitBuiltinFont} from './emit-c.mjs';
|
|
31
31
|
|
|
32
32
|
const here = dirname(fileURLToPath(import.meta.url)); // bridges/quickjs/js/assets
|
|
@@ -35,23 +35,17 @@ const FONT = resolve(repoRoot, 'assets/fonts/Inter-Regular.ttf');
|
|
|
35
35
|
const OUT = resolve(repoRoot, 'engine/font/font_data.c');
|
|
36
36
|
|
|
37
37
|
// The built-in covers printable ASCII plus a fixed set of common symbols (degrees, arrows, math,
|
|
38
|
-
// punctuation, etc.) the UI components rely on — kept stable across regenerations.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
0x00d7, 0x00f7, 0x2013, 0x2014, 0x2018, 0x2019, 0x201c, 0x201d, 0x2020,
|
|
43
|
-
0x2021, 0x2022, 0x2026, 0x2030, 0x20ac, 0x2122, 0x2190, 0x2191, 0x2192,
|
|
44
|
-
0x2193, 0x2194, 0x21b5, 0x2202, 0x2206, 0x2211, 0x2212, 0x221a, 0x221e,
|
|
45
|
-
0x2248, 0x2260, 0x2264, 0x2265, 0x25a0, 0x25c6, 0x25cf, 0x2605, 0x2606,
|
|
46
|
-
0x2713, 0x2717,
|
|
47
|
-
];
|
|
38
|
+
// punctuation, etc.) the UI components rely on — kept stable across regenerations. The set lives in
|
|
39
|
+
// bake-font.mjs as BUILTIN_EXTRAS — with BUILTIN_SIZES alongside it — so the build-time coverage
|
|
40
|
+
// checks report against what is actually baked here.
|
|
41
|
+
const SIZES = BUILTIN_SIZES;
|
|
48
42
|
|
|
49
43
|
const font = bakeFont({
|
|
50
44
|
path: FONT,
|
|
51
45
|
family: 'Inter',
|
|
52
46
|
sizes: SIZES,
|
|
53
47
|
bpp: 4,
|
|
54
|
-
glyphs:
|
|
48
|
+
glyphs: BUILTIN_EXTRAS,
|
|
55
49
|
});
|
|
56
50
|
writeFileSync(
|
|
57
51
|
OUT,
|
package/assets/emit-c.mjs
CHANGED
|
@@ -84,12 +84,20 @@ export function emitAssetsC({headerName, images = [], fonts = []}) {
|
|
|
84
84
|
const is565 = img.format === 'rgb565';
|
|
85
85
|
const hex = Array.from(
|
|
86
86
|
img.pixels,
|
|
87
|
-
p =>
|
|
87
|
+
p =>
|
|
88
|
+
'0x' +
|
|
89
|
+
p
|
|
90
|
+
.toString(16)
|
|
91
|
+
.toUpperCase()
|
|
92
|
+
.padStart(is565 ? 4 : 8, '0') +
|
|
93
|
+
'u',
|
|
88
94
|
);
|
|
89
95
|
lines.push(
|
|
90
96
|
`/* image "${img.name}" — ${img.width}x${img.height}${is565 ? ' (RGB565)' : ''} */`,
|
|
91
97
|
);
|
|
92
|
-
lines.push(
|
|
98
|
+
lines.push(
|
|
99
|
+
`static const ${is565 ? 'uint16_t' : 'uint32_t'} ${id}_px[] = {`,
|
|
100
|
+
);
|
|
93
101
|
lines.push(rows(hex, is565 ? 12 : 8));
|
|
94
102
|
lines.push(`};`);
|
|
95
103
|
lines.push(``);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Cory Lamming
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// Turns the `fonts` block of a project's assets.config.js into bakeFont() jobs. Six entry points
|
|
18
|
+
// bake fonts (build, pack, sim, sim-server, hot-reload app/split chunks); they share this so a
|
|
19
|
+
// config field means the same thing in every one of them.
|
|
20
|
+
|
|
21
|
+
/** Fallback pixel size when no fontSize could be discovered and the config pins none. */
|
|
22
|
+
const DEFAULT_SIZE = 16;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Resolves discovered font imports against their per-project config.
|
|
26
|
+
*
|
|
27
|
+
* @param {Map<string,string>} fonts Discovered imports: family → .ttf/.otf path.
|
|
28
|
+
* @param {object} [fontConfig] assets.config.js `fonts` block, keyed by family.
|
|
29
|
+
* @param {number[]} [discoveredSizes] Sizes the bundle uses (font-sizes.mjs analyzeFontSizes).
|
|
30
|
+
* @returns {Array<{path:string, family:string, sizes:number[], bpp:number, glyphs:any,
|
|
31
|
+
* extraGlyphs:any}>} One bakeFont() job per imported font.
|
|
32
|
+
*/
|
|
33
|
+
export function resolveFontJobs(fonts, fontConfig = {}, discoveredSizes = []) {
|
|
34
|
+
return [...fonts.entries()].map(([family, path]) => {
|
|
35
|
+
const fc = fontConfig[family] || {};
|
|
36
|
+
return {
|
|
37
|
+
path,
|
|
38
|
+
family,
|
|
39
|
+
sizes: fc.sizes?.length
|
|
40
|
+
? fc.sizes
|
|
41
|
+
: discoveredSizes.length
|
|
42
|
+
? discoveredSizes
|
|
43
|
+
: [DEFAULT_SIZE],
|
|
44
|
+
bpp: fc.bpp ?? 4,
|
|
45
|
+
glyphs: fc.glyphs ?? 'ascii',
|
|
46
|
+
extraGlyphs: fc.extraGlyphs,
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
}
|