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.
- package/README.md +2 -2
- package/aot/compile.mjs +1 -1
- package/aot/compiler/alerts.mjs +604 -0
- package/aot/compiler/check.mjs +1 -1
- package/aot/compiler/collect.mjs +1 -1
- package/aot/compiler/elements/button.mjs +3 -3
- package/aot/compiler/elements/image-background.mjs +1 -1
- package/aot/compiler/elements/props.mjs +10 -6
- package/aot/compiler/elements/section-list.mjs +1 -1
- package/aot/compiler/expressions.mjs +29 -2
- package/aot/compiler/handlers.mjs +73 -16
- package/aot/compiler/keyboard-dismiss.mjs +99 -0
- package/aot/compiler/keyboard.mjs +1 -1
- package/aot/compiler/lower.mjs +12 -0
- package/aot/compiler/nodes.mjs +17 -9
- package/aot/compiler/out.mjs +4 -0
- package/aot/compiler/package/codegen.mjs +36 -2
- package/aot/compiler/package/format.mjs +5 -3
- package/aot/compiler/package/lower.mjs +53 -19
- package/aot/compiler/scroll-to.mjs +112 -0
- package/aot/compiler/style-text.mjs +2 -2
- package/aot/compiler/svg.mjs +6 -3
- package/aot/compiler/updaters.mjs +1 -0
- package/aot/style-map.mjs +44 -1
- package/assets/bake-font.mjs +187 -244
- package/assets/bake-image.mjs +47 -71
- package/assets/bake-svg.mjs +465 -533
- package/assets/build-builtin-font.mjs +14 -27
- package/assets/emit-c.mjs +124 -204
- package/assets/emit-container.mjs +129 -197
- package/assets/emit-pack.mjs +92 -136
- package/assets/font-config.mjs +19 -27
- package/assets/font-sizes.mjs +432 -507
- package/assets/glyph-coverage.mjs +170 -214
- package/assets/index.mjs +52 -97
- package/assets/rasterize.mjs +173 -194
- package/assets/svg-loader.mjs +42 -48
- package/build.mjs +84 -101
- package/cli.mjs +482 -621
- package/compile-bin.mjs +24 -36
- package/flash.mjs +297 -401
- package/hotreload/dev-device.mjs +229 -270
- package/hotreload/pack-app.mjs +118 -159
- package/hotreload/pack-split.mjs +144 -200
- package/hotreload/package-transfer.mjs +128 -131
- package/hotreload/protocol.mjs +118 -118
- package/hotreload/uploader.mjs +132 -159
- package/hotreload/watch-tree.mjs +56 -65
- package/pack-container.mjs +93 -123
- package/package.json +19 -16
- package/persist-transform.mjs +89 -105
- package/qjsc-wasm.mjs +47 -72
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +1 -1
- package/sim-server.mjs +260 -354
- package/src/embedded-react/Alert.mjs +112 -0
- package/src/embedded-react/Animated.mjs +412 -0
- package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
- package/src/embedded-react/{Button.js → Button.mjs} +29 -53
- package/src/embedded-react/{Dimensions.js → Dimensions.mjs} +12 -17
- package/src/embedded-react/Easing.mjs +34 -0
- package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
- package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
- package/src/embedded-react/Keyboard.mjs +82 -0
- package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
- package/src/embedded-react/PanResponder.mjs +256 -0
- package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
- package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
- package/src/embedded-react/SectionList.mjs +103 -0
- package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
- package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
- package/src/embedded-react/background-image.mjs +321 -0
- package/src/embedded-react/{components.js → components.mjs} +1 -3
- package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
- package/src/embedded-react/index.d.ts +155 -2
- package/src/embedded-react/index.js +26 -19
- package/src/embedded-react/layout-anim-config.mjs +85 -0
- package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
- package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
- package/src/embedded-react/nativeModule.mjs +371 -0
- package/src/embedded-react/split-style.mjs +57 -0
- package/src/embedded-react/svg-ops.mjs +1075 -0
- package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
- package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
- package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
- package/src/host-config.mjs +512 -0
- package/src/{native-ui.js → native-ui.mjs} +1 -8
- package/src/props.mjs +341 -0
- package/src/{renderer.js → renderer.mjs} +30 -44
- package/src/embedded-react/Animated.js +0 -440
- package/src/embedded-react/Easing.js +0 -39
- package/src/embedded-react/PanResponder.js +0 -330
- package/src/embedded-react/SectionList.js +0 -146
- package/src/embedded-react/layout-anim-config.js +0 -101
- package/src/embedded-react/nativeModule.js +0 -462
- package/src/embedded-react/split-style.js +0 -58
- package/src/embedded-react/svg-ops.js +0 -1295
- package/src/host-config.js +0 -548
- 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
|
// Build-time glyph-coverage check: a character the app renders but the bake has no glyph for is
|
|
18
17
|
// silently substituted with '?' by the engine (font_glyph() in engine/font/font_bitmap.c), so the
|
|
19
18
|
// only way to find out used to be looking at the device. Every bake path (build, pack, sim, hot
|
|
@@ -22,150 +21,132 @@
|
|
|
22
21
|
// The check is source-driven: it reads string and template literals (plus JSX element text, for the
|
|
23
22
|
// unbundled `.jsx` the AOT flow compiles). Non-ASCII from a runtime source — a fetched string,
|
|
24
23
|
// String.fromCharCode — can't be seen here. Comments are skipped: an em dash in prose is not text.
|
|
25
|
-
import {
|
|
26
|
-
ASCII_FIRST,
|
|
27
|
-
ASCII_LAST,
|
|
28
|
-
BUILTIN_EXTRAS,
|
|
29
|
-
loadGlyphProbe,
|
|
30
|
-
} from './bake-font.mjs';
|
|
31
|
-
|
|
24
|
+
import { ASCII_FIRST, ASCII_LAST, BUILTIN_EXTRAS, loadGlyphProbe, } from './bake-font.mjs';
|
|
32
25
|
/** Name used for the engine's fallback font in warnings (it has no family of its own). */
|
|
33
26
|
export const BUILTIN_FAMILY = 'the built-in font';
|
|
34
|
-
|
|
35
27
|
const MAX_CODEPOINT = 0x10ffff;
|
|
36
28
|
const CODEPOINT_HEX_DIGITS = 4;
|
|
37
29
|
const EXCERPT_CONTEXT = 12; // characters shown either side of the one found
|
|
38
|
-
|
|
39
30
|
// Comments first so an apostrophe inside one can't open a bogus string; then the three literal
|
|
40
31
|
// forms. Bundled output is machine-generated, so the simple form is enough (a regex literal
|
|
41
32
|
// containing a lone quote is the only realistic misread, and it costs at most a stray sample).
|
|
42
|
-
const LITERALS =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
const LITERALS = /\/\/[^\n]*|\/\*[\s\S]*?\*\/|'(?:[^'\\\n]|\\[\s\S])*'|"(?:[^"\\\n]|\\[\s\S])*"|`(?:[^`\\]|\\[\s\S])*`/g;
|
|
34
|
+
const SIMPLE_ESCAPES = {
|
|
35
|
+
n: '\n',
|
|
36
|
+
t: '\t',
|
|
37
|
+
r: '\r',
|
|
38
|
+
b: '\b',
|
|
39
|
+
f: '\f',
|
|
40
|
+
v: '\v',
|
|
41
|
+
};
|
|
47
42
|
/** Resolves the \u{...}, \uXXXX, \xNN and simple escapes a bundler emits back to characters. */
|
|
48
43
|
function decodeEscapes(body) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
},
|
|
63
|
-
);
|
|
44
|
+
return body.replace(/\\u\{([0-9a-fA-F]{1,6})\}|\\u([0-9a-fA-F]{4})|\\x([0-9a-fA-F]{2})|\\([\s\S])/g, (_match, braced, unicode, hex, other) => {
|
|
45
|
+
if (braced !== undefined) {
|
|
46
|
+
const codepoint = parseInt(braced, 16);
|
|
47
|
+
return codepoint <= MAX_CODEPOINT
|
|
48
|
+
? String.fromCodePoint(codepoint)
|
|
49
|
+
: '';
|
|
50
|
+
}
|
|
51
|
+
if (unicode !== undefined)
|
|
52
|
+
return String.fromCharCode(parseInt(unicode, 16));
|
|
53
|
+
if (hex !== undefined)
|
|
54
|
+
return String.fromCharCode(parseInt(hex, 16));
|
|
55
|
+
return SIMPLE_ESCAPES[other] ?? other; // \\ \' \" \` and friends: the character itself
|
|
56
|
+
});
|
|
64
57
|
}
|
|
65
|
-
|
|
66
58
|
/** Invisible/formatting characters that are never baked and never render — not worth warning about. */
|
|
67
59
|
function ignorable(codepoint) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
);
|
|
60
|
+
return ((codepoint >= 0x7f && codepoint <= 0x9f) || // DEL + C1 controls
|
|
61
|
+
(codepoint >= 0x200b && codepoint <= 0x200f) || // zero-width + bidi marks
|
|
62
|
+
(codepoint >= 0x2028 && codepoint <= 0x202e) || // line/paragraph separators + bidi overrides
|
|
63
|
+
(codepoint >= 0xfe00 && codepoint <= 0xfe0f) || // variation selectors
|
|
64
|
+
codepoint === 0xfeff // BOM
|
|
65
|
+
);
|
|
75
66
|
}
|
|
76
|
-
|
|
77
67
|
// Text between two tags in unbundled JSX: `<Text>24° out</Text>`. Braces are excluded so an
|
|
78
68
|
// expression child stays out of it — its own literals are already covered by LITERALS.
|
|
79
69
|
const JSX_TEXT = />([^<>{}]+)</g;
|
|
80
|
-
|
|
81
70
|
/**
|
|
82
71
|
* Collects every non-ASCII character that appears in the app's rendered text.
|
|
83
72
|
*
|
|
84
|
-
* @param
|
|
85
|
-
* @
|
|
86
|
-
* @param {boolean} [opts.jsx] Also read JSX element text. Set it for unbundled `.jsx` — a bundler
|
|
87
|
-
* has already turned element text into string literals, and on bundled output the extra
|
|
88
|
-
* pass would only misread `a > b` comparisons.
|
|
89
|
-
* @returns {Map<number, string>} Codepoint → a short excerpt of the text it was found in.
|
|
73
|
+
* @param source JS source (a bundle, a chunk, or a single component file).
|
|
74
|
+
* @returns Codepoint → a short excerpt of the text it was found in.
|
|
90
75
|
*/
|
|
91
|
-
export function scanTextCodepoints(source, {jsx = false} = {}) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
76
|
+
export function scanTextCodepoints(source, { jsx = false } = {}) {
|
|
77
|
+
const found = new Map();
|
|
78
|
+
const collect = (text) => {
|
|
79
|
+
let offset = 0;
|
|
80
|
+
for (const character of text) {
|
|
81
|
+
const codepoint = character.codePointAt(0);
|
|
82
|
+
if (codepoint > ASCII_LAST &&
|
|
83
|
+
!ignorable(codepoint) &&
|
|
84
|
+
!found.has(codepoint))
|
|
85
|
+
found.set(codepoint, excerpt(text, offset, character.length));
|
|
86
|
+
offset += character.length;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
// Blank each token out as it is read, so the JSX pass below sees neither strings (already
|
|
90
|
+
// collected) nor comments (never rendered) — only real element text.
|
|
91
|
+
const bare = source.replace(LITERALS, token => {
|
|
92
|
+
if (token[0] !== '/')
|
|
93
|
+
collect(decodeEscapes(token.slice(1, -1)));
|
|
94
|
+
return ' '.repeat(token.length);
|
|
95
|
+
});
|
|
96
|
+
if (jsx)
|
|
97
|
+
for (const match of bare.matchAll(JSX_TEXT))
|
|
98
|
+
collect(match[1]);
|
|
99
|
+
return found;
|
|
115
100
|
}
|
|
116
|
-
|
|
117
101
|
/**
|
|
118
102
|
* Compact signature of the non-ASCII characters a source renders. Watch loops fold this into their
|
|
119
103
|
* "did the asset inputs change?" key so new text is re-checked, not just new fonts.
|
|
120
104
|
*
|
|
121
|
-
* @param
|
|
122
|
-
* @param
|
|
123
|
-
* @returns
|
|
105
|
+
* @param source JS source to scan.
|
|
106
|
+
* @param opts Passed through to scanTextCodepoints (e.g. `{jsx: true}`).
|
|
107
|
+
* @returns Sorted codepoints, comma-joined.
|
|
124
108
|
*/
|
|
125
109
|
export function textSignature(source, opts) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
110
|
+
return [...scanTextCodepoints(source, opts).keys()]
|
|
111
|
+
.sort((left, right) => left - right)
|
|
112
|
+
.join(',');
|
|
129
113
|
}
|
|
130
|
-
|
|
131
114
|
/** A one-line, printable window of `text` around the character at `at` (a UTF-16 index). */
|
|
132
115
|
function excerpt(text, at, length) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
116
|
+
const start = Math.max(0, at - EXCERPT_CONTEXT);
|
|
117
|
+
const end = Math.min(text.length, at + length + EXCERPT_CONTEXT);
|
|
118
|
+
const body = text
|
|
119
|
+
.slice(start, end)
|
|
120
|
+
.replace(/[\n\r\t]/g, ' ')
|
|
121
|
+
.replace(/^[\udc00-\udfff]|[\ud800-\udbff]$/g, '') // a pair split by the window
|
|
122
|
+
.trim();
|
|
123
|
+
return `${start > 0 ? '…' : ''}${body}${end < text.length ? '…' : ''}`;
|
|
141
124
|
}
|
|
142
|
-
|
|
143
125
|
/** The set of codepoints a baked font can render: the dense ASCII range plus its baked extras. */
|
|
144
126
|
function coverageOf(baked) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
127
|
+
const size = baked.sizes?.[0];
|
|
128
|
+
const covered = new Set();
|
|
129
|
+
const first = size ? size.first : ASCII_FIRST;
|
|
130
|
+
const last = size ? size.last : ASCII_LAST;
|
|
131
|
+
for (let codepoint = first; codepoint <= last; codepoint++)
|
|
132
|
+
covered.add(codepoint);
|
|
133
|
+
for (const extra of size?.extras ?? [])
|
|
134
|
+
covered.add(extra.codepoint);
|
|
135
|
+
return covered;
|
|
153
136
|
}
|
|
154
|
-
|
|
155
137
|
/** The engine's fallback font, shaped like a bakeFont() result so both go through one code path. */
|
|
156
138
|
function builtinFont() {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
139
|
+
return {
|
|
140
|
+
family: BUILTIN_FAMILY,
|
|
141
|
+
sizes: [
|
|
142
|
+
{
|
|
143
|
+
first: ASCII_FIRST,
|
|
144
|
+
last: ASCII_LAST,
|
|
145
|
+
extras: BUILTIN_EXTRAS.map(codepoint => ({ codepoint })),
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
};
|
|
167
149
|
}
|
|
168
|
-
|
|
169
150
|
/**
|
|
170
151
|
* Finds the characters the app renders that some font in the bake has no glyph for.
|
|
171
152
|
*
|
|
@@ -174,128 +155,103 @@ function builtinFont() {
|
|
|
174
155
|
* character the app's own font lacks is exactly the bug worth reporting); with none, the engine's
|
|
175
156
|
* built-in fallback is checked instead.
|
|
176
157
|
*
|
|
177
|
-
* @
|
|
178
|
-
* @param {string} opts.source App/bundle JS to scan for rendered text.
|
|
179
|
-
* @param {Array<object>} [opts.fonts] bakeFont() results; empty means built-in font only.
|
|
180
|
-
* @param {boolean} [opts.jsx] Source is unbundled JSX — read element text too.
|
|
181
|
-
* @returns {Array<{codepoint:number, char:string, sample:string, missingFrom:string[],
|
|
182
|
-
* noGlyphIn:string[]}>} Sorted by codepoint. `noGlyphIn` narrows `missingFrom` to the
|
|
183
|
-
* fonts whose file has no glyph for the character at all — baking it there can't help.
|
|
158
|
+
* @returns Sorted by codepoint.
|
|
184
159
|
*/
|
|
185
|
-
export function findMissingGlyphs({source, fonts = [], jsx = false}) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
160
|
+
export function findMissingGlyphs({ source, fonts = [], jsx = false, }) {
|
|
161
|
+
const checked = fonts.length ? fonts : [builtinFont()];
|
|
162
|
+
const coverage = checked.map(font => ({
|
|
163
|
+
family: font.family,
|
|
164
|
+
path: font.path,
|
|
165
|
+
covered: coverageOf(font),
|
|
166
|
+
}));
|
|
167
|
+
// Opened lazily and only for a font with a gap: most builds have none and pay nothing.
|
|
168
|
+
const probes = new Map();
|
|
169
|
+
const hasGlyph = (font, codepoint) => {
|
|
170
|
+
if (!font.path)
|
|
171
|
+
return true; // the built-in font's coverage is its bake, nothing more to ask
|
|
172
|
+
if (!probes.has(font.path))
|
|
173
|
+
probes.set(font.path, loadGlyphProbe(font.path));
|
|
174
|
+
return probes.get(font.path)(codepoint);
|
|
175
|
+
};
|
|
176
|
+
const missing = [];
|
|
177
|
+
for (const [codepoint, sample] of scanTextCodepoints(source, { jsx })) {
|
|
178
|
+
const gaps = coverage.filter(entry => !entry.covered.has(codepoint));
|
|
179
|
+
if (!gaps.length)
|
|
180
|
+
continue;
|
|
181
|
+
missing.push({
|
|
182
|
+
codepoint,
|
|
183
|
+
char: String.fromCodePoint(codepoint),
|
|
184
|
+
sample,
|
|
185
|
+
missingFrom: gaps.map(gap => gap.family),
|
|
186
|
+
noGlyphIn: gaps
|
|
187
|
+
.filter(gap => !hasGlyph(gap, codepoint))
|
|
188
|
+
.map(gap => gap.family),
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return missing.sort((left, right) => left.codepoint - right.codepoint);
|
|
216
192
|
}
|
|
217
|
-
|
|
218
193
|
const MAX_LISTED = 12;
|
|
219
|
-
|
|
220
194
|
/**
|
|
221
195
|
* Renders findMissingGlyphs() output as a developer-facing warning, ending with the config change
|
|
222
196
|
* that fixes it.
|
|
223
197
|
*
|
|
224
|
-
* @param
|
|
225
|
-
* @param
|
|
226
|
-
* @returns
|
|
198
|
+
* @param missing Result of findMissingGlyphs().
|
|
199
|
+
* @param fonts The same bakeFont() results, for the suggested config line.
|
|
200
|
+
* @returns The warning text (empty when nothing is missing).
|
|
227
201
|
*/
|
|
228
202
|
export function formatMissingGlyphs(missing, fonts = []) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
)
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
return characters
|
|
259
|
-
? `${key}: {extraGlyphs: ${JSON.stringify(characters)}}`
|
|
260
|
-
: null;
|
|
203
|
+
if (!missing.length)
|
|
204
|
+
return '';
|
|
205
|
+
const lines = missing.slice(0, MAX_LISTED).map(glyph => {
|
|
206
|
+
const hex = glyph.codepoint
|
|
207
|
+
.toString(16)
|
|
208
|
+
.toUpperCase()
|
|
209
|
+
.padStart(CODEPOINT_HEX_DIGITS, '0');
|
|
210
|
+
const note = glyph.noGlyphIn.length
|
|
211
|
+
? ` (the font file itself has no glyph for it — pick a font that covers it)`
|
|
212
|
+
: '';
|
|
213
|
+
return ` U+${hex} '${glyph.char}' missing from ${glyph.missingFrom.join(', ')}${note} in "${glyph.sample}"`;
|
|
214
|
+
});
|
|
215
|
+
if (missing.length > MAX_LISTED)
|
|
216
|
+
lines.push(` … and ${missing.length - MAX_LISTED} more`);
|
|
217
|
+
// One config entry per font, listing only what baking it there would actually fix.
|
|
218
|
+
const perFamily = fonts
|
|
219
|
+
.map(font => {
|
|
220
|
+
const characters = missing
|
|
221
|
+
.filter(glyph => glyph.missingFrom.includes(font.family) &&
|
|
222
|
+
!glyph.noGlyphIn.includes(font.family))
|
|
223
|
+
.map(glyph => glyph.char)
|
|
224
|
+
.join('');
|
|
225
|
+
// A family is a file basename, so it often needs quoting to be a valid key ('Inter-Regular').
|
|
226
|
+
const key = /^[A-Za-z_$][\w$]*$/.test(font.family)
|
|
227
|
+
? font.family
|
|
228
|
+
: JSON.stringify(font.family);
|
|
229
|
+
return characters
|
|
230
|
+
? `${key}: {extraGlyphs: ${JSON.stringify(characters)}}`
|
|
231
|
+
: null;
|
|
261
232
|
})
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
return (
|
|
272
|
-
`embedded-react: ${missing.length} character(s) in the app's text have no baked glyph and will ` +
|
|
273
|
-
`render as '?':\n${lines.join('\n')}\n${fix}`
|
|
274
|
-
);
|
|
233
|
+
.filter(Boolean);
|
|
234
|
+
const fix = perFamily.length
|
|
235
|
+
? ` fix: assets.config.js → fonts: {${perFamily.join(', ')}}`
|
|
236
|
+
: fonts.length
|
|
237
|
+
? ` fix: bake these from a font that has them (assets.config.js → fonts: {<Family>: {extraGlyphs: ...}})`
|
|
238
|
+
: ` fix: the built-in font covers ASCII + common symbols only — import a .ttf/.otf and bake the\n` +
|
|
239
|
+
` rest with assets.config.js → fonts: {<Family>: {extraGlyphs: ${JSON.stringify(missing.map(glyph => glyph.char).join(''))}}}`;
|
|
240
|
+
return (`embedded-react: ${missing.length} character(s) in the app's text have no baked glyph and will ` +
|
|
241
|
+
`render as '?':\n${lines.join('\n')}\n${fix}`);
|
|
275
242
|
}
|
|
276
|
-
|
|
277
243
|
let lastWarning = null; // dev loops re-bake on every save — don't reprint an unchanged warning
|
|
278
|
-
|
|
279
244
|
/**
|
|
280
245
|
* Checks glyph coverage and warns. Repeats are suppressed while the warning is unchanged, so a
|
|
281
246
|
* watch/hot-reload loop reports each gap once rather than on every save.
|
|
282
247
|
*
|
|
283
|
-
* @
|
|
284
|
-
* @param {string} opts.source App/bundle JS to scan for rendered text.
|
|
285
|
-
* @param {Array<object>} [opts.fonts] bakeFont() results; empty means built-in font only.
|
|
286
|
-
* @param {boolean} [opts.jsx] Source is unbundled JSX — read element text too.
|
|
287
|
-
* @param {Function} [opts.log] Sink for the warning (default console.warn).
|
|
288
|
-
* @returns {Array<object>} The missing-glyph records (empty when coverage is complete).
|
|
248
|
+
* @returns The missing-glyph records (empty when coverage is complete).
|
|
289
249
|
*/
|
|
290
|
-
export function warnMissingGlyphs({
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
const text = formatMissingGlyphs(missing, fonts);
|
|
298
|
-
if (text && text !== lastWarning) log(text);
|
|
299
|
-
lastWarning = text || null;
|
|
300
|
-
return missing;
|
|
250
|
+
export function warnMissingGlyphs({ source, fonts = [], jsx = false, log = console.warn, }) {
|
|
251
|
+
const missing = findMissingGlyphs({ source, fonts, jsx });
|
|
252
|
+
const text = formatMissingGlyphs(missing, fonts);
|
|
253
|
+
if (text && text !== lastWarning)
|
|
254
|
+
log(text);
|
|
255
|
+
lastWarning = text || null;
|
|
256
|
+
return missing;
|
|
301
257
|
}
|
package/assets/index.mjs
CHANGED
|
@@ -13,116 +13,71 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
16
|
// Asset baking orchestrator: turns the images and fonts an app imports into a single generated C
|
|
18
|
-
// translation unit (assets.generated.c + .h) exposing er_register_assets(). Invoked by build.
|
|
17
|
+
// translation unit (assets.generated.c + .h) exposing er_register_assets(). Invoked by build.mts
|
|
19
18
|
// after bundling; the example firmware compiles the .c and calls er_register_assets() at boot.
|
|
20
19
|
import fs from 'node:fs';
|
|
21
20
|
import path from 'node:path';
|
|
22
|
-
import {bakeImage} from './bake-image.mjs';
|
|
23
|
-
import {bakeFont} from './bake-font.mjs';
|
|
24
|
-
import {emitAssetsC} from './emit-c.mjs';
|
|
25
|
-
import {emitAssetPack} from './emit-pack.mjs';
|
|
26
|
-
import {warnMissingGlyphs} from './glyph-coverage.mjs';
|
|
27
|
-
import {warnFontSizes} from './font-sizes.mjs';
|
|
28
|
-
|
|
21
|
+
import { bakeImage } from './bake-image.mjs';
|
|
22
|
+
import { bakeFont } from './bake-font.mjs';
|
|
23
|
+
import { emitAssetsC } from './emit-c.mjs';
|
|
24
|
+
import { emitAssetPack } from './emit-pack.mjs';
|
|
25
|
+
import { warnMissingGlyphs } from './glyph-coverage.mjs';
|
|
26
|
+
import { warnFontSizes } from './font-sizes.mjs';
|
|
29
27
|
/**
|
|
30
|
-
* Bakes the given assets and writes assets.generated.{c,h} into outDir.
|
|
31
|
-
*
|
|
32
|
-
* @param {object} opts
|
|
33
|
-
* @param {Array<{path:string,name:string,format?:string}>} [opts.images] Discovered image
|
|
34
|
-
* imports; format 'rgb565' bakes 16-bit (see bake-image.mjs), default ARGB8888.
|
|
35
|
-
* @param {Array<{path:string,family:string,sizes:number[],bpp:number,glyphs:any,extraGlyphs:any}>}
|
|
36
|
-
* [opts.fonts] Discovered font imports with their resolved size/bpp/glyph config.
|
|
37
|
-
* @param {string} opts.outDir Directory to write the generated files into.
|
|
38
|
-
* @param {string} [opts.source] Bundled app JS — scanned for text the bake has no glyph for.
|
|
39
|
-
* @param {{sizes:number[],dynamic:Array<object>}} [opts.usedSizes] analyzeFontSizes() result,
|
|
40
|
-
* checked against what was baked so an unbaked size is reported rather than silently snapped.
|
|
41
|
-
* @returns {{cPath:string, hPath:string, images:number, fonts:number}}
|
|
28
|
+
* Bakes the given assets and writes assets.generated.{c,h} into outDir, the directory to write into.
|
|
42
29
|
*/
|
|
43
|
-
export function bakeAssets({
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const cPath = path.join(outDir, 'assets.generated.c');
|
|
64
|
-
const hPath = path.join(outDir, headerName);
|
|
65
|
-
fs.writeFileSync(cPath, cSource);
|
|
66
|
-
fs.writeFileSync(hPath, header);
|
|
67
|
-
|
|
68
|
-
const fontSizes = bakedFonts.reduce(
|
|
69
|
-
(total, font) => total + font.sizes.length,
|
|
70
|
-
0,
|
|
71
|
-
);
|
|
72
|
-
return {cPath, hPath, images: bakedImages.length, fonts: fontSizes};
|
|
30
|
+
export function bakeAssets({ images = [], fonts = [], outDir, source, usedSizes, }) {
|
|
31
|
+
const bakedImages = images.map(image => bakeImage(image));
|
|
32
|
+
const bakedFonts = fonts.map(font => bakeFont(font));
|
|
33
|
+
if (source)
|
|
34
|
+
warnMissingGlyphs({ source, fonts: bakedFonts });
|
|
35
|
+
if (usedSizes)
|
|
36
|
+
warnFontSizes({ used: usedSizes, fonts: bakedFonts });
|
|
37
|
+
const headerName = 'assets.generated.h';
|
|
38
|
+
const { c: cSource, h: header } = emitAssetsC({
|
|
39
|
+
headerName,
|
|
40
|
+
images: bakedImages,
|
|
41
|
+
fonts: bakedFonts,
|
|
42
|
+
});
|
|
43
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
44
|
+
const cPath = path.join(outDir, 'assets.generated.c');
|
|
45
|
+
const hPath = path.join(outDir, headerName);
|
|
46
|
+
fs.writeFileSync(cPath, cSource);
|
|
47
|
+
fs.writeFileSync(hPath, header);
|
|
48
|
+
const fontSizes = bakedFonts.reduce((total, font) => total + font.sizes.length, 0);
|
|
49
|
+
return { cPath, hPath, images: bakedImages.length, fonts: fontSizes };
|
|
73
50
|
}
|
|
74
|
-
|
|
75
51
|
/**
|
|
76
52
|
* Bakes the given assets into ERPK pack bytes, with the same bakers as bakeAssets, without writing a file.
|
|
77
53
|
*
|
|
78
|
-
* @
|
|
79
|
-
* @param {Array<{path:string,name:string}>} [opts.images]
|
|
80
|
-
* @param {Array<{path:string,family:string,sizes:number[],bpp:number,glyphs:any,extraGlyphs:any}>}
|
|
81
|
-
* [opts.fonts]
|
|
82
|
-
* @returns {Buffer} The pack.
|
|
54
|
+
* @returns The pack.
|
|
83
55
|
*/
|
|
84
|
-
export function bakeAssetPackBytes({images = [], fonts = []}) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
56
|
+
export function bakeAssetPackBytes({ images = [], fonts = [], }) {
|
|
57
|
+
return emitAssetPack({
|
|
58
|
+
images: images.map(image => bakeImage(image)),
|
|
59
|
+
fonts: fonts.map(font => bakeFont(font)),
|
|
60
|
+
});
|
|
89
61
|
}
|
|
90
|
-
|
|
91
62
|
/**
|
|
92
63
|
* Bakes the given assets into a binary ERPK pack the simulator loads at runtime (hot-reloadable),
|
|
93
|
-
* using the same bakers as bakeAssets so the result is pixel-identical.
|
|
94
|
-
*
|
|
95
|
-
* @param {object} opts
|
|
96
|
-
* @param {Array<{path:string,name:string}>} [opts.images]
|
|
97
|
-
* @param {Array<{path:string,family:string,sizes:number[],bpp:number,glyphs:any,extraGlyphs:any}>}
|
|
98
|
-
* [opts.fonts]
|
|
99
|
-
* @param {string} opts.outPath Path to write the .pack file.
|
|
100
|
-
* @param {string} [opts.source] Bundled app JS — scanned for text the bake has no glyph for.
|
|
101
|
-
* @param {{sizes:number[],dynamic:Array<object>}} [opts.usedSizes] analyzeFontSizes() result.
|
|
102
|
-
* @returns {{path:string, bytes:number, images:number, fonts:number}}
|
|
64
|
+
* using the same bakers as bakeAssets so the result is pixel-identical. outPath is the .pack file to write.
|
|
103
65
|
*/
|
|
104
|
-
export function bakeAssetPack({
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
);
|
|
122
|
-
return {
|
|
123
|
-
path: outPath,
|
|
124
|
-
bytes: pack.length,
|
|
125
|
-
images: bakedImages.length,
|
|
126
|
-
fonts: fontSizes,
|
|
127
|
-
};
|
|
66
|
+
export function bakeAssetPack({ images = [], fonts = [], outPath, source, usedSizes, }) {
|
|
67
|
+
const bakedImages = images.map(image => bakeImage(image));
|
|
68
|
+
const bakedFonts = fonts.map(font => bakeFont(font));
|
|
69
|
+
if (source)
|
|
70
|
+
warnMissingGlyphs({ source, fonts: bakedFonts });
|
|
71
|
+
if (usedSizes)
|
|
72
|
+
warnFontSizes({ used: usedSizes, fonts: bakedFonts });
|
|
73
|
+
const pack = emitAssetPack({ images: bakedImages, fonts: bakedFonts });
|
|
74
|
+
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
|
75
|
+
fs.writeFileSync(outPath, pack);
|
|
76
|
+
const fontSizes = bakedFonts.reduce((total, font) => total + font.sizes.length, 0);
|
|
77
|
+
return {
|
|
78
|
+
path: outPath,
|
|
79
|
+
bytes: pack.length,
|
|
80
|
+
images: bakedImages.length,
|
|
81
|
+
fonts: fontSizes,
|
|
82
|
+
};
|
|
128
83
|
}
|