xbintsc 0.7.8 → 0.7.9
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/dist/src/cli/help.d.ts +1 -1
- package/dist/src/cli/help.js +1 -1
- package/dist/src/codegen/generator/context.d.ts +4 -3
- package/dist/src/codegen/generator/context.js +6 -5
- package/dist/src/codegen/generator/context.js.map +1 -1
- package/dist/src/codegen/generator/expressions/assignment.js +3 -3
- package/dist/src/driver/config.d.ts +1 -1
- package/dist/src/driver/options.d.ts +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/gui/features.d.ts +14 -6
- package/dist/src/extensions/gui/features.js +34 -6
- package/dist/src/extensions/gui/features.js.map +1 -1
- package/dist/src/extensions/gui/index.js +3 -3
- package/dist/tests/codegen/llvm.test.js +1 -1
- package/dist/tests/e2e/gui-audio.test.js +24 -0
- package/dist/tests/e2e/gui-audio.test.js.map +1 -1
- package/dist/tests/e2e/gui-draw-perf.test.js +9 -0
- package/dist/tests/e2e/gui-draw-perf.test.js.map +1 -1
- package/dist/tests/e2e/gui-font-face.test.d.ts +3 -1
- package/dist/tests/e2e/gui-font-face.test.js +99 -7
- package/dist/tests/e2e/gui-font-face.test.js.map +1 -1
- package/dist/tests/e2e/gui-frame-pacing.test.d.ts +15 -0
- package/dist/tests/e2e/gui-frame-pacing.test.js +68 -0
- package/dist/tests/e2e/gui-frame-pacing.test.js.map +1 -0
- package/dist/tests/e2e/gui-initial-url.test.d.ts +10 -0
- package/dist/tests/e2e/gui-initial-url.test.js +49 -0
- package/dist/tests/e2e/gui-initial-url.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl-depth-range.test.d.ts +18 -0
- package/dist/tests/e2e/gui-webgl-depth-range.test.js +140 -0
- package/dist/tests/e2e/gui-webgl-depth-range.test.js.map +1 -0
- package/dist/tests/extensions/gui-features.test.js +27 -2
- package/dist/tests/extensions/gui-features.test.js.map +1 -1
- package/doc/ai/extensions.md +10 -4
- package/doc/ai/zh-CN/extensions.md +8 -3
- package/doc/gui/api.md +35 -2
- package/doc/gui/build.md +34 -15
- package/doc/gui/known-issues.md +1 -1
- package/doc/gui/rendering.md +45 -8
- package/doc/gui/runtime.md +13 -0
- package/doc/gui/webgl.md +11 -2
- package/doc/gui.md +9 -4
- package/doc/implemented/codegen.md +3 -2
- package/doc/zh-CN/gui/api.md +25 -2
- package/doc/zh-CN/gui/build.md +20 -7
- package/doc/zh-CN/gui/known-issues.md +1 -1
- package/doc/zh-CN/gui/rendering.md +33 -8
- package/doc/zh-CN/gui/runtime.md +9 -0
- package/doc/zh-CN/gui/webgl.md +3 -2
- package/doc/zh-CN/gui.md +10 -5
- package/doc/zh-CN/implemented/codegen.md +3 -2
- package/package.json +7 -7
- package/runtime/ext_gui/audio_graph_commands.cpp +127 -0
- package/runtime/ext_gui/audio_mixer.cpp +84 -163
- package/runtime/ext_gui/audio_mixer.h +59 -3
- package/runtime/ext_gui/audio_mixer_extra.cpp +8 -0
- package/runtime/ext_gui/audio_param_apply.cpp +160 -0
- package/runtime/ext_gui/browser.cpp +6 -19
- package/runtime/ext_gui/browser_location.cpp +78 -0
- package/runtime/ext_gui/css_sheet.cpp +4 -2
- package/runtime/ext_gui/document_animation.cpp +7 -0
- package/runtime/ext_gui/dom_api_computed_style.cpp +3 -2
- package/runtime/ext_gui/dom_api_webgl.cpp +31 -0
- package/runtime/ext_gui/dom_api_webgl_internal.h +4 -0
- package/runtime/ext_gui/dom_api_webgl_shader.cpp +19 -4
- package/runtime/ext_gui/dom_api_webgl_state.cpp +6 -3
- package/runtime/ext_gui/gui.cpp +100 -1
- package/runtime/ext_gui/gui_events.cpp +8 -2
- package/runtime/ext_gui/perf.cpp +18 -6
- package/runtime/ext_gui/perf.h +37 -0
- package/runtime/ext_gui/style.cpp +27 -10
- package/runtime/ext_gui/style.h +10 -1
- package/runtime/ext_gui/text.cpp +4 -0
- package/runtime/ext_gui/text_font_bytes.cpp +117 -0
- package/runtime/ext_gui/text_font_bytes.h +65 -0
- package/runtime/ext_gui/text_font_db.cpp +5 -0
- package/runtime/ext_gui/text_font_sfnt.cpp +71 -24
- package/runtime/ext_gui/text_font_sfnt.h +5 -2
- package/runtime/ext_gui/text_hb.cpp +34 -5
- package/runtime/ext_gui/text_stb.cpp +7 -30
- package/runtime/ext_gui/text_webfont.cpp +217 -0
- package/runtime/ext_gui/warnings.cpp +26 -0
- package/runtime/ext_gui/warnings.h +8 -0
- package/runtime/ext_gui/webfont_bridge.c +23 -0
- package/runtime/ext_gui/webgl.h +34 -39
- package/runtime/ext_gui/webgl_blit_color.cpp +5 -0
- package/runtime/ext_gui/webgl_buffer_objects.cpp +19 -5
- package/runtime/ext_gui/webgl_draw.cpp +72 -12
- package/runtime/ext_gui/webgl_draw_setup.cpp +8 -2
- package/runtime/ext_gui/webgl_draw_state.h +13 -2
- package/runtime/ext_gui/webgl_objects.h +4 -0
- package/runtime/ext_gui/webgl_program.h +64 -0
- package/runtime/ext_gui/webgl_state.cpp +7 -0
- package/runtime/ext_gui/webgl_uniform.cpp +78 -0
- package/runtime/ext_gui/window.cpp +6 -0
- package/runtime/rt_object.h +6 -0
- package/runtime/rt_profile.h +6 -0
- package/runtime/xt_containers/access.inc +2 -47
- package/runtime/xt_containers/ic_get.inc +70 -0
- package/runtime/xt_containers/method_cache.inc +24 -10
- package/runtime/xt_containers/objects.inc +12 -1
- package/runtime/xt_containers/shapes.inc +78 -0
- package/runtime/xt_containers.c +1 -0
- package/runtime/xt_profile.c +3 -0
- package/scripts/build-gui.ts +43 -49
- package/scripts/gui-engine-build.ts +58 -0
- package/scripts/gui-vendor-source.ts +53 -0
- package/scripts/gui-webfont-build.ts +138 -0
- package/src/cli/help.ts +1 -1
- package/src/codegen/generator/context.ts +6 -6
- package/src/codegen/generator/expressions/assignment.ts +3 -3
- package/src/driver/config.ts +1 -1
- package/src/driver/options.ts +1 -1
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/features.ts +34 -6
- package/src/extensions/gui/index.ts +3 -3
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile the WOFF/WOFF2 decompression sources into the GUI archive.
|
|
3
|
+
*
|
|
4
|
+
* Kept out of `build-gui.ts` (which has a file-size budget) and next to it so
|
|
5
|
+
* the "what does the `webfonts` feature cost?" question is reviewable in one
|
|
6
|
+
* place. The sources are fetched, not committed (see `fetch-vendored.ts` and
|
|
7
|
+
* the repository's vendor policy): they are compiled once into `gui.a`, and a
|
|
8
|
+
* program that never loads a compressed font never extracts them.
|
|
9
|
+
*
|
|
10
|
+
* Layers, from the outside in:
|
|
11
|
+
* - `text_webfont.cpp` (the engine, compiled with the other engine objects)
|
|
12
|
+
* parses the WOFF 1.0 container itself and calls the woff2 reference
|
|
13
|
+
* decoder for WOFF 2.0;
|
|
14
|
+
* - `vendor/woff2` reconstructs the transformed `glyf`/`loca`/`hmtx` tables
|
|
15
|
+
* from the Brotli-compressed stream;
|
|
16
|
+
* - `vendor/brotli` decodes that stream (decoder only: the encoder, CLI
|
|
17
|
+
* tools and the shared-dictionary API are not compiled);
|
|
18
|
+
* - `vendor/miniz`'s `miniz_tinfl.c` inflates each WOFF 1.0 table.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { join } from "node:path";
|
|
22
|
+
import { SECTION_FLAGS } from "./gui-build-options.js";
|
|
23
|
+
import { sysrootFlags } from "../src/driver/toolchain.js";
|
|
24
|
+
|
|
25
|
+
/** Pinned versions; override to test a different decoder release. */
|
|
26
|
+
export const BROTLI_VERSION = process.env.BROTLI_VERSION || "1.1.0";
|
|
27
|
+
export const WOFF2_VERSION = process.env.WOFF2_VERSION || "1.0.2";
|
|
28
|
+
const BROTLI_URL = `https://codeload.github.com/google/brotli/tar.gz/refs/tags/v${BROTLI_VERSION}`;
|
|
29
|
+
const WOFF2_URL = `https://codeload.github.com/google/woff2/tar.gz/refs/tags/v${WOFF2_VERSION}`;
|
|
30
|
+
|
|
31
|
+
/** Brotli files the decoder needs (`common/` holds the static dictionary and
|
|
32
|
+
* the context/transform tables; `dec/` is the decoder itself). */
|
|
33
|
+
const BROTLI_COMMON = ["constants", "context", "dictionary", "platform", "shared_dictionary", "transform"];
|
|
34
|
+
const BROTLI_DECODER = ["bit_reader", "decode", "huffman", "state"];
|
|
35
|
+
|
|
36
|
+
/** woff2 files the decoder needs; the encoder/compressor and the CLI are not
|
|
37
|
+
* compiled. */
|
|
38
|
+
const WOFF2_SOURCES = ["woff2_dec", "woff2_common", "table_tags", "variable_length", "woff2_out"];
|
|
39
|
+
|
|
40
|
+
/** Include directories these sources need, for the engine compile as well
|
|
41
|
+
* (`text_webfont.cpp` includes `<woff2/decode.h>` and `miniz_tinfl.h`). */
|
|
42
|
+
export function webfontIncludeFlags(vendorDir: string): string[] {
|
|
43
|
+
return [
|
|
44
|
+
"-I", join(vendorDir, "miniz"),
|
|
45
|
+
"-I", join(vendorDir, "brotli", "c", "include"),
|
|
46
|
+
"-I", join(vendorDir, "woff2", "include"),
|
|
47
|
+
"-I", join(vendorDir, "woff2", "src"),
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Fetch and extract a release tarball into `vendor/<name>`. */
|
|
52
|
+
export type FetchSource = (name: string, url: string, extractedName: string) => void;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Fetch Brotli and woff2 (an already-extracted copy is reused). This must run
|
|
56
|
+
* before the engine is compiled: `text_webfont.cpp` includes `<woff2/decode.h>`
|
|
57
|
+
* and `miniz_tinfl.h`, so the include directories have to exist by then.
|
|
58
|
+
*/
|
|
59
|
+
export function fetchWebfontSources(fetchSource: FetchSource): void {
|
|
60
|
+
fetchSource("brotli", BROTLI_URL, `brotli-${BROTLI_VERSION}`);
|
|
61
|
+
fetchSource("woff2", WOFF2_URL, `woff2-${WOFF2_VERSION}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface WebfontBuildOptions {
|
|
65
|
+
readonly vendorDir: string;
|
|
66
|
+
/** Directory the engine objects are written to. */
|
|
67
|
+
readonly objDir: string;
|
|
68
|
+
/** `.o` or `.obj`, matching the archive's ABI. */
|
|
69
|
+
readonly objectSuffix: string;
|
|
70
|
+
/** C and C++ compilers from the same toolchain as the driver. */
|
|
71
|
+
readonly clang: string;
|
|
72
|
+
readonly clangxx: string;
|
|
73
|
+
/** Include directories, including the ones these sources need. */
|
|
74
|
+
readonly includeFlags: readonly string[];
|
|
75
|
+
/** macOS SDK for `-isysroot`; absent elsewhere. */
|
|
76
|
+
readonly sdkRoot?: string;
|
|
77
|
+
/** True for the MSVC ABI (`-fPIC` is rejected there). */
|
|
78
|
+
readonly msvc: boolean;
|
|
79
|
+
/** Run a command, failing the build on a non-zero exit. */
|
|
80
|
+
run(command: string, args: readonly string[]): void;
|
|
81
|
+
/** Fetch and extract a release tarball into `vendor/<name>`. */
|
|
82
|
+
fetchSource: FetchSource;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Compile Brotli, the woff2 reference decoder and miniz's inflater into
|
|
87
|
+
* `objDir` with the same flags as the engine. Returns the object paths to add
|
|
88
|
+
* to the archive.
|
|
89
|
+
*/
|
|
90
|
+
export function buildWebfontObjects(options: WebfontBuildOptions): string[] {
|
|
91
|
+
const { vendorDir, objDir, objectSuffix, clang, clangxx, includeFlags, msvc, run } = options;
|
|
92
|
+
fetchWebfontSources(options.fetchSource);
|
|
93
|
+
|
|
94
|
+
/* Brotli and miniz are C, so they get the C flags (the C++ standard would be
|
|
95
|
+
* rejected for a `.c` input); woff2 additionally gets the C++ standard.
|
|
96
|
+
* Neither layer is warned about: upstream code is not ours to keep
|
|
97
|
+
* `-Wall`-clean. */
|
|
98
|
+
const common = [
|
|
99
|
+
"-O2",
|
|
100
|
+
...SECTION_FLAGS,
|
|
101
|
+
...sysrootFlags(options.sdkRoot),
|
|
102
|
+
...(msvc ? [] : ["-fPIC"]),
|
|
103
|
+
...includeFlags,
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
const sources: readonly { readonly source: string; readonly cxx: boolean }[] = [
|
|
107
|
+
...BROTLI_COMMON.map((name) => ({
|
|
108
|
+
source: join(vendorDir, "brotli", "c", "common", `${name}.c`),
|
|
109
|
+
cxx: false,
|
|
110
|
+
})),
|
|
111
|
+
...BROTLI_DECODER.map((name) => ({
|
|
112
|
+
source: join(vendorDir, "brotli", "c", "dec", `${name}.c`),
|
|
113
|
+
cxx: false,
|
|
114
|
+
})),
|
|
115
|
+
{ source: join(vendorDir, "miniz", "miniz_tinfl.c"), cxx: false },
|
|
116
|
+
...WOFF2_SOURCES.map((name) => ({
|
|
117
|
+
source: join(vendorDir, "woff2", "src", `${name}.cc`),
|
|
118
|
+
cxx: true,
|
|
119
|
+
})),
|
|
120
|
+
];
|
|
121
|
+
|
|
122
|
+
const objects: string[] = [];
|
|
123
|
+
for (const entry of sources) {
|
|
124
|
+
const name = entry.source.replace(/^.*[\\/]/, "").replace(/\.(?:c|cc)$/, "");
|
|
125
|
+
const object = join(objDir, `webfont_${name}${objectSuffix}`);
|
|
126
|
+
console.log(`xbintsc: compiling ${entry.source.slice(vendorDir.length + 1)}`);
|
|
127
|
+
run(entry.cxx ? clangxx : clang, [
|
|
128
|
+
...(entry.cxx ? ["-std=c++17"] : []),
|
|
129
|
+
...common,
|
|
130
|
+
"-c",
|
|
131
|
+
entry.source,
|
|
132
|
+
"-o",
|
|
133
|
+
object,
|
|
134
|
+
]);
|
|
135
|
+
objects.push(object);
|
|
136
|
+
}
|
|
137
|
+
return objects;
|
|
138
|
+
}
|
package/src/cli/help.ts
CHANGED
|
@@ -26,7 +26,7 @@ Options:
|
|
|
26
26
|
--emit <kind> exe | obj | ir (default: exe)
|
|
27
27
|
-O0..-O3 Optimization level (default: -O2)
|
|
28
28
|
--ext <names> Comma separated extensions (e.g. node,gui)
|
|
29
|
-
--feature <names> Force optional link features on (media,gpu,images,shaping,webgl,storage,tls,wasm,all)
|
|
29
|
+
--feature <names> Force optional link features on (media,gpu,images,shaping,webfonts,webgl,storage,tls,wasm,all)
|
|
30
30
|
--no-feature <n> Keep optional link features out even when detected
|
|
31
31
|
--ext-native <m> Register a C++/Rust extension from a JSON manifest
|
|
32
32
|
(comma separated for several)
|
|
@@ -331,18 +331,18 @@ export class GeneratorContext {
|
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
/**
|
|
334
|
-
* Allocate a
|
|
335
|
-
*
|
|
336
|
-
*
|
|
334
|
+
* Allocate a four-entry inline cache for one property access and return the
|
|
335
|
+
* `i64*` the runtime fills with (shape, property index) pairs. One entry made
|
|
336
|
+
* the cache monomorphic: generic call sites read a field across several
|
|
337
|
+
* layouts and missed nearly every time. Zero-initialised means empty.
|
|
337
338
|
*/
|
|
338
339
|
icCachePointer(): string {
|
|
339
340
|
const name = `@ic.${this.icCounter++}`;
|
|
340
|
-
this.globals.push(`${name} = internal global [
|
|
341
|
+
this.globals.push(`${name} = internal global [8 x i64] zeroinitializer`);
|
|
341
342
|
const ptr = this.reg();
|
|
342
|
-
this.emit(` ${ptr} = getelementptr [
|
|
343
|
+
this.emit(` ${ptr} = getelementptr [8 x i64], [8 x i64]* ${name}, i64 0, i64 0`);
|
|
343
344
|
return ptr;
|
|
344
345
|
}
|
|
345
|
-
|
|
346
346
|
/** Lay already-computed values out as a contiguous `i64*` argument buffer. */
|
|
347
347
|
emitValueArguments(values: readonly string[]): { argc: string; ptr: string } {
|
|
348
348
|
if (values.length === 0) return { argc: "0", ptr: "null" };
|
|
@@ -144,14 +144,14 @@ export const assignmentExpressionMethods: AssignmentExpressionMethods = {
|
|
|
144
144
|
}
|
|
145
145
|
const object = this.emitExpression(access.expression);
|
|
146
146
|
const key = this.stringValue(access.name.text);
|
|
147
|
-
/* A store site gets the same
|
|
147
|
+
/* A store site gets the same four-entry inline cache a read site has:
|
|
148
148
|
* `obj.x = v` in a hot loop otherwise resolves the property (own scan,
|
|
149
149
|
* prototype-chain walk for setters) on every assignment. */
|
|
150
150
|
this.extraDeclarations.add("declare i64 @xt_set_ic(i64, i64, i64, i64*)");
|
|
151
151
|
const cache = `@st.${this.icCounter++}`;
|
|
152
|
-
this.globals.push(`${cache} = internal global [
|
|
152
|
+
this.globals.push(`${cache} = internal global [8 x i64] zeroinitializer`);
|
|
153
153
|
const slot = this.reg();
|
|
154
|
-
this.emit(` ${slot} = getelementptr [
|
|
154
|
+
this.emit(` ${slot} = getelementptr [8 x i64], [8 x i64]* ${cache}, i64 0, i64 0`);
|
|
155
155
|
this.emit(` call i64 @xt_set_ic(i64 ${object}, i64 ${key}, i64 ${value}, i64* ${slot})`);
|
|
156
156
|
return;
|
|
157
157
|
}
|
package/src/driver/config.ts
CHANGED
|
@@ -55,7 +55,7 @@ export interface ProjectConfig {
|
|
|
55
55
|
readonly pgoDir?: string;
|
|
56
56
|
readonly extensions?: readonly string[];
|
|
57
57
|
readonly extNative?: readonly string[];
|
|
58
|
-
/** Optional link features to force on (`media`, `gpu`, `images`, `shaping`, `webgl`, `all`). */
|
|
58
|
+
/** Optional link features to force on (`media`, `gpu`, `images`, `shaping`, `webfonts`, `webgl`, `all`). */
|
|
59
59
|
readonly features?: readonly string[];
|
|
60
60
|
/** Optional link features to keep out even when auto-detection finds a use. */
|
|
61
61
|
readonly noFeatures?: readonly string[];
|
package/src/driver/options.ts
CHANGED
|
@@ -64,7 +64,7 @@ export interface BuildOptions {
|
|
|
64
64
|
/** Profile directory (default: `<outDir>/pgo`). */
|
|
65
65
|
readonly pgoDir?: string;
|
|
66
66
|
/**
|
|
67
|
-
* Optional link features to force on (`media`, `gpu`, `images`, `shaping`, `webgl`, or `all`). Features are
|
|
67
|
+
* Optional link features to force on (`media`, `gpu`, `images`, `shaping`, `webfonts`, `webgl`, or `all`). Features are
|
|
68
68
|
* otherwise selected from a static scan of the bundled program; forcing one
|
|
69
69
|
* is the escape hatch for HTML/CSS built from runtime data.
|
|
70
70
|
*/
|
package/src/driver/version.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Optional link features of the `gui` extension.
|
|
3
3
|
*
|
|
4
|
-
* The GUI engine itself is always linked with `--ext gui`; these are the
|
|
5
|
-
*
|
|
4
|
+
* The GUI engine itself is always linked with `--ext gui`; these are the heavy
|
|
5
|
+
* halves a program may never touch:
|
|
6
6
|
*
|
|
7
7
|
* - `media` — the FFmpeg decoder backend (`runtime/xt_media/`, `media.a`).
|
|
8
8
|
* The DOM media surface lives in `gui.a`; only decoding is optional, and an
|
|
@@ -11,12 +11,16 @@
|
|
|
11
11
|
* by WebGL *and* by the `mix-blend-mode` / `backdrop-filter` offscreen
|
|
12
12
|
* compositor. The engine's own shaders are precompiled, so a DOM page
|
|
13
13
|
* never needs it.
|
|
14
|
+
* - `webfonts` — WOFF/WOFF2 decompression (miniz + Brotli + the woff2
|
|
15
|
+
* reference decoder) for author `@font-face` sources. A page that only
|
|
16
|
+
* names local sfnt faces never pays for it.
|
|
14
17
|
*
|
|
15
18
|
* Detection is static: the compiler sees imported `.html`/`.css` assets and all
|
|
16
|
-
* bundled modules, so it can recognise `<video>`/`<audio>`, `getContext("webgl")
|
|
17
|
-
*
|
|
18
|
-
* the usage collector sets `dynamicMarkup`, which
|
|
19
|
-
* features; users who know better can
|
|
19
|
+
* bundled modules, so it can recognise `<video>`/`<audio>`, `getContext("webgl")`,
|
|
20
|
+
* `mix-blend-mode`/`backdrop-filter` and `.woff`/`.woff2` sources. When markup
|
|
21
|
+
* can be built at run time the usage collector sets `dynamicMarkup`, which
|
|
22
|
+
* conservatively enables the optional features; users who know better can
|
|
23
|
+
* shrink the binary with `--no-feature`.
|
|
20
24
|
*/
|
|
21
25
|
|
|
22
26
|
import { join } from "node:path";
|
|
@@ -28,6 +32,10 @@ import { findRuntimeLibrary, runtimeLibDir } from "../../driver/runtime-lib.js";
|
|
|
28
32
|
const MEDIA_TAG = /<(?:video|audio)\b/i;
|
|
29
33
|
/** A literal tag name handed to `createElement("video")`. */
|
|
30
34
|
const MEDIA_TAG_NAME = /^(?:video|audio)$/i;
|
|
35
|
+
/** A `.woff`/`.woff2` source anywhere in the program's strings. An imported
|
|
36
|
+
* `.css` asset is bundled as a string, so an author `@font-face` rule that
|
|
37
|
+
* names a compressed font is visible here. */
|
|
38
|
+
const WEBFONT_TOKEN = /\bwoff2?\b/i;
|
|
31
39
|
/** Anything that needs the GLSL translator. */
|
|
32
40
|
const GPU_TOKEN = /webgl|mix-blend-mode|mixBlendMode|backdrop-filter|backdropFilter/i;
|
|
33
41
|
|
|
@@ -92,6 +100,14 @@ export function hasShapingUsage(usage: ProgramUsage): boolean {
|
|
|
92
100
|
});
|
|
93
101
|
}
|
|
94
102
|
|
|
103
|
+
/** True when the program may load a compressed webfont. WOFF/WOFF2 `@font-face`
|
|
104
|
+
* sources need a decompressor (miniz + Brotli/woff2) that a page with plain
|
|
105
|
+
* sfnt files never pays for. */
|
|
106
|
+
export function hasWebfontUsage(usage: ProgramUsage): boolean {
|
|
107
|
+
if (usage.dynamicMarkup) return true;
|
|
108
|
+
return usage.strings.some((value) => WEBFONT_TOKEN.test(value));
|
|
109
|
+
}
|
|
110
|
+
|
|
95
111
|
/** Absolute path to the per-platform prebuilt media archive. */
|
|
96
112
|
function mediaArchive(): string {
|
|
97
113
|
return join(runtimeLibDir(), process.platform === "win32" ? "media.lib" : "media.a");
|
|
@@ -163,6 +179,18 @@ export const guiLinkFeatures: readonly LinkFeature[] = [
|
|
|
163
179
|
runtimeSources: () => [join(findRuntimeDir(), "ext_gui", "text_bridge.c")],
|
|
164
180
|
used: hasShapingUsage,
|
|
165
181
|
},
|
|
182
|
+
{
|
|
183
|
+
name: "webfonts",
|
|
184
|
+
description: "WOFF/WOFF2 decompression for author @font-face sources",
|
|
185
|
+
/**
|
|
186
|
+
* `webfont_bridge.c` installs the decoder and references `text_webfont.cpp`,
|
|
187
|
+
* pulling miniz (zlib inflate), Brotli and the woff2 reference decoder out
|
|
188
|
+
* of `gui.a`. A page whose fonts are plain sfnt files — the common case for
|
|
189
|
+
* system faces — links none of them.
|
|
190
|
+
*/
|
|
191
|
+
runtimeSources: () => [join(findRuntimeDir(), "ext_gui", "webfont_bridge.c")],
|
|
192
|
+
used: hasWebfontUsage,
|
|
193
|
+
},
|
|
166
194
|
{
|
|
167
195
|
name: "webgpu",
|
|
168
196
|
description: "WebGPU (navigator.gpu, WGSL) rendering over SDL_GPU (requires gpu)",
|
|
@@ -311,9 +311,9 @@ export const guiExtension: Extension = {
|
|
|
311
311
|
/** Rewrite imported `.html` assets and patch three.js's shader unroller. */
|
|
312
312
|
assetLoaders: () => ({ ".html": loadHtmlAsset, ".js": loadScriptAsset, ".mjs": loadScriptAsset }),
|
|
313
313
|
/**
|
|
314
|
-
* FFmpeg and
|
|
315
|
-
* program (see `features.ts`). A program that only
|
|
316
|
-
* links
|
|
314
|
+
* FFmpeg, glslang and the WOFF/WOFF2 decompressors are optional halves of the
|
|
315
|
+
* engine, selected from the program (see `features.ts`). A program that only
|
|
316
|
+
* renders HTML/CSS never links them.
|
|
317
317
|
*/
|
|
318
318
|
linkFeatures: () => guiLinkFeatures,
|
|
319
319
|
};
|