@null3d/vite-plugin 0.0.0-stage → 0.0.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/LICENSE-APACHE +176 -0
- package/LICENSE-MIT +21 -0
- package/THIRD-PARTY-NOTICES.txt +398 -0
- package/dist/shader-compiler.stamp.json +4 -0
- package/dist/shader-compiler.wasm +0 -0
- package/lib/assets.d.ts +94 -0
- package/lib/assets.js +189 -0
- package/lib/client.d.ts +21 -0
- package/lib/compile-pool.d.ts +25 -0
- package/lib/compile-pool.js +90 -0
- package/lib/compile-worker.js +11 -0
- package/lib/compiler-calls.d.ts +26 -0
- package/lib/compiler-calls.js +97 -0
- package/lib/compiler-stamp.d.ts +8 -0
- package/lib/compiler-stamp.js +34 -0
- package/lib/declarations.d.ts +10 -0
- package/lib/declarations.js +80 -0
- package/lib/engine-shaders-local.d.ts +6 -0
- package/lib/engine-shaders-local.js +75 -0
- package/lib/engine-shaders.d.ts +61 -0
- package/lib/engine-shaders.js +170 -0
- package/lib/hash-pool.d.ts +24 -0
- package/lib/hash-pool.js +84 -0
- package/lib/hash-worker.js +53 -0
- package/lib/hot.d.ts +53 -0
- package/lib/hot.js +101 -0
- package/lib/index.d.ts +95 -0
- package/lib/index.js +895 -0
- package/lib/material-builds.d.ts +91 -0
- package/lib/material-builds.js +236 -0
- package/lib/offline.d.ts +92 -0
- package/lib/offline.js +304 -0
- package/lib/pack.d.ts +30 -0
- package/lib/pack.js +112 -0
- package/lib/package-files.d.ts +12 -0
- package/lib/package-files.js +39 -0
- package/lib/paragraphs.d.ts +19 -0
- package/lib/paragraphs.js +131 -0
- package/lib/shader-cache.d.ts +59 -0
- package/lib/shader-cache.js +213 -0
- package/lib/shader-compiler.d.ts +258 -0
- package/lib/shader-compiler.js +169 -0
- package/lib/shader-types.d.ts +261 -0
- package/lib/shader-types.js +4 -0
- package/lib/wgsl.d.ts +118 -0
- package/lib/wgsl.js +446 -0
- package/lib/worker-preload.d.ts +17 -0
- package/lib/worker-preload.js +65 -0
- package/package.json +69 -5
- package/README.md +0 -3
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ShaderPack } from './pack.js';
|
|
2
|
+
import type { CompiledWgsl, ShaderVariant } from './shader-types.js';
|
|
3
|
+
/** The prefix of the virtual modules that hold sets of custom materials' builds. */
|
|
4
|
+
export declare const MATERIAL_BUILDS = "virtual:null3d/builds/";
|
|
5
|
+
/**
|
|
6
|
+
* The name or module id of a virtual module of builds, as Vite's hook filters match them. Its last
|
|
7
|
+
* part names the kind, the GPU path, the set's bits and a hash of its builds, and gives a build's
|
|
8
|
+
* file of the set its name, such as `material-glsl-3-<hash>.js` or `curve-wgsl-0-<hash>.js`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const MATERIAL_BUILDS_ADDRESS: RegExp;
|
|
11
|
+
/** The permutation bit of WebGL2 builds that read the draw index of a multi-draw. */
|
|
12
|
+
export declare const DRAW_INDEX = 1;
|
|
13
|
+
/** The permutation bit of builds that tone map in the shader, on the 8-bit path. */
|
|
14
|
+
export declare const TONE_MAP = 2;
|
|
15
|
+
/** The permutation bit of builds that skin in the vertex shader. */
|
|
16
|
+
export declare const SKIN = 64;
|
|
17
|
+
/** A GPU path, as a build's field of its output names it. */
|
|
18
|
+
type Target = 'wgsl' | 'glsl';
|
|
19
|
+
/** The builds of one custom material, by name. */
|
|
20
|
+
type Builds = Readonly<Record<string, ShaderVariant>>;
|
|
21
|
+
/**
|
|
22
|
+
* The builds of `builds` with output for `target` in the set `set`: those whose skinning bit and
|
|
23
|
+
* fixed bits are the set's. A build without a fixed bit belongs to the set with the bit too, when
|
|
24
|
+
* no twin of it has the bit, such as a shadow caster's build, which never tone maps. Each build
|
|
25
|
+
* keeps only its output for `target`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildsOfSet(builds: Builds, target: Target, set: number): Builds;
|
|
28
|
+
/** The sets of a GPU path: each value of its fixed bits, without and with skinning. */
|
|
29
|
+
export declare function setsOf(target: Target): number[];
|
|
30
|
+
/** A kind of compiled WGSL whose builds load on first use. */
|
|
31
|
+
export type BuildKind = 'material' | 'effect' | 'toneCurve';
|
|
32
|
+
/** One shader of a module whose builds load on first use. */
|
|
33
|
+
export interface BuildSource {
|
|
34
|
+
/** The shader's kind, which keeps the sets of one kind apart from another's. */
|
|
35
|
+
readonly kind: BuildKind;
|
|
36
|
+
/** The shader's builds, by name. */
|
|
37
|
+
readonly variants: Builds;
|
|
38
|
+
}
|
|
39
|
+
/** The shaders of one module whose builds go to sets, in the order that the module holds them. */
|
|
40
|
+
export declare class ModuleBuilds {
|
|
41
|
+
readonly sources: BuildSource[];
|
|
42
|
+
/** How many shaders of each kind the module gave, which numbers their records in a set. */
|
|
43
|
+
private readonly counts;
|
|
44
|
+
/**
|
|
45
|
+
* The JavaScript expression of `shader` in a module that `pack` packs, as `ShaderPack.value`
|
|
46
|
+
* gives it. The value of a shader whose builds load on first use keeps none: it gets a
|
|
47
|
+
* function that imports a set.
|
|
48
|
+
*/
|
|
49
|
+
value(pack: ShaderPack, shader: CompiledWgsl, hot?: string): string;
|
|
50
|
+
}
|
|
51
|
+
/** One set of a module's builds that load on first use, as its own module carries them. */
|
|
52
|
+
export interface BuildSet {
|
|
53
|
+
/** The module's name, which tells the set's builds apart from a build of other ones. */
|
|
54
|
+
readonly name: string;
|
|
55
|
+
/** The kind, the GPU path and the permutation bits of the set, as the engine names it:
|
|
56
|
+
* `"material wgsl 2"`. */
|
|
57
|
+
readonly key: string;
|
|
58
|
+
/** The builds of each shader of the module that the set serves, by name. */
|
|
59
|
+
readonly records: readonly Builds[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The sets that hold `sources`' builds: for a material one for each GPU path and value of its fixed
|
|
63
|
+
* bits, and for an effect or a tone curve one for each GPU path. Each set holds the builds of every
|
|
64
|
+
* shader of its kind that the set serves.
|
|
65
|
+
*/
|
|
66
|
+
export declare function buildSets(sources: readonly BuildSource[]): BuildSet[];
|
|
67
|
+
/** The code of the module that holds one set of builds. */
|
|
68
|
+
export declare function setModule(records: readonly Builds[]): string;
|
|
69
|
+
/**
|
|
70
|
+
* The function that imports the set of builds that a shader needs when the engine first needs it,
|
|
71
|
+
* or nothing for a module without sets. `address` gives the module of each set, which is a virtual
|
|
72
|
+
* module on the dev server and a file beside the module in a packed package.
|
|
73
|
+
*/
|
|
74
|
+
export declare function loadBuilds(sets: readonly BuildSet[], address: (name: string) => string): string;
|
|
75
|
+
/** The sets of builds that the plugin wrote, by the name of each set's virtual module. */
|
|
76
|
+
export declare class MaterialBuilds {
|
|
77
|
+
private readonly sets;
|
|
78
|
+
/** The names of the sets of each module, so a module's new compile drops its old sets. */
|
|
79
|
+
private readonly owners;
|
|
80
|
+
/**
|
|
81
|
+
* The code that ends module `file`, whose shaders `builds` holds: the function that imports
|
|
82
|
+
* each set, or nothing for a module without such shaders. The sets of the module's previous
|
|
83
|
+
* compile go, unless another module has the same.
|
|
84
|
+
*/
|
|
85
|
+
finish(file: string, builds: ModuleBuilds): string;
|
|
86
|
+
/** The code of the virtual module `id`, or undefined for a module that this plugin did not name. */
|
|
87
|
+
module(id: string): string | undefined;
|
|
88
|
+
/** True when a module's current compile has the set named `name`. */
|
|
89
|
+
private owned;
|
|
90
|
+
}
|
|
91
|
+
export {};
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// Compiled shaders' builds load on first use, as the engine's own shader files do. A custom
|
|
2
|
+
// material builds into every variant of the standard material on both GPU paths, and a device
|
|
3
|
+
// draws with a few of them: those of its GPU path and of the permutation bits that it fixes, the
|
|
4
|
+
// draw index on WebGL2 and tone mapping in the shader on the 8-bit path. A custom effect and a
|
|
5
|
+
// custom tone curve build into every variant of their template, and a device draws with those of
|
|
6
|
+
// its own path. So the module that holds a shader keeps none of its builds. The plugin puts them in
|
|
7
|
+
// virtual modules of its own. A material gets one for each GPU path, each value of those bits and
|
|
8
|
+
// the builds that skin in the vertex shader or the others: 4 sets for WebGPU and 8 for WebGL2. An
|
|
9
|
+
// effect or a tone curve gets one for each GPU path. Each set holds the builds of every shader of
|
|
10
|
+
// its kind in the module, with the text that they share once. A shader's value in the module gets
|
|
11
|
+
// a function that imports one set, which the engine calls when the shader is first used: for a
|
|
12
|
+
// material the set of its device at once, and the others when a pipeline needs one, such as the
|
|
13
|
+
// builds without tone mapping once bloom turns on, or those that skin for the first skinned mesh.
|
|
14
|
+
// A build of the project puts each set in a file of its own, which pages of other devices never
|
|
15
|
+
// download. Custom shaders build without half precision, so the half bit, which splits the engine's
|
|
16
|
+
// own WebGPU modules, does not split these sets.
|
|
17
|
+
import { createHash } from 'node:crypto';
|
|
18
|
+
import { LOAD_BUILDS, ShaderPack } from "./pack.js";
|
|
19
|
+
/** The prefix of the virtual modules that hold sets of custom materials' builds. */
|
|
20
|
+
export const MATERIAL_BUILDS = 'virtual:null3d/builds/';
|
|
21
|
+
/**
|
|
22
|
+
* The name or module id of a virtual module of builds, as Vite's hook filters match them. Its last
|
|
23
|
+
* part names the kind, the GPU path, the set's bits and a hash of its builds, and gives a build's
|
|
24
|
+
* file of the set its name, such as `material-glsl-3-<hash>.js` or `curve-wgsl-0-<hash>.js`.
|
|
25
|
+
*/
|
|
26
|
+
export const MATERIAL_BUILDS_ADDRESS = /^\0?virtual:null3d\/builds\/(?:material|effect|curve)-(?:wgsl|glsl)-\d+-[0-9a-f]+$/;
|
|
27
|
+
/** The permutation bit of WebGL2 builds that read the draw index of a multi-draw. */
|
|
28
|
+
export const DRAW_INDEX = 1;
|
|
29
|
+
/** The permutation bit of builds that tone map in the shader, on the 8-bit path. */
|
|
30
|
+
export const TONE_MAP = 2;
|
|
31
|
+
/** The permutation bit of builds that skin in the vertex shader. */
|
|
32
|
+
export const SKIN = 64;
|
|
33
|
+
/** The permutation bits that a device of each GPU path fixes, which split its builds into sets. */
|
|
34
|
+
const FIXED = { wgsl: TONE_MAP, glsl: TONE_MAP | DRAW_INDEX };
|
|
35
|
+
/** Each value of the bits of `mask`, from 0 up. */
|
|
36
|
+
function valuesOf(mask) {
|
|
37
|
+
let values = [0];
|
|
38
|
+
for (let bit = 1; bit <= mask; bit <<= 1)
|
|
39
|
+
if (mask & bit)
|
|
40
|
+
values = values.flatMap((value) => [value, value | bit]);
|
|
41
|
+
return values;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The builds of `builds` with output for `target` in the set `set`: those whose skinning bit and
|
|
45
|
+
* fixed bits are the set's. A build without a fixed bit belongs to the set with the bit too, when
|
|
46
|
+
* no twin of it has the bit, such as a shadow caster's build, which never tone maps. Each build
|
|
47
|
+
* keeps only its output for `target`.
|
|
48
|
+
*/
|
|
49
|
+
export function buildsOfSet(builds, target, set) {
|
|
50
|
+
const fixed = FIXED[target];
|
|
51
|
+
const permutations = new Set();
|
|
52
|
+
for (const build of Object.values(builds))
|
|
53
|
+
if (build[target] !== null)
|
|
54
|
+
permutations.add(build.permutation);
|
|
55
|
+
const picked = {};
|
|
56
|
+
for (const [name, build] of Object.entries(builds)) {
|
|
57
|
+
const output = build[target];
|
|
58
|
+
const p = build.permutation;
|
|
59
|
+
if (output === null || (p & SKIN) !== (set & SKIN))
|
|
60
|
+
continue;
|
|
61
|
+
let fits = true;
|
|
62
|
+
for (let bit = 1; bit <= fixed && fits; bit <<= 1)
|
|
63
|
+
if (fixed & bit && (p & bit) !== (set & bit))
|
|
64
|
+
fits = (p & bit) === 0 && !permutations.has(p | bit);
|
|
65
|
+
if (!fits)
|
|
66
|
+
continue;
|
|
67
|
+
picked[name] = {
|
|
68
|
+
permutation: p,
|
|
69
|
+
wgsl: target === 'wgsl' ? build.wgsl : null,
|
|
70
|
+
glsl: target === 'glsl' ? build.glsl : null,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return picked;
|
|
74
|
+
}
|
|
75
|
+
/** The sets of a GPU path: each value of its fixed bits, without and with skinning. */
|
|
76
|
+
export function setsOf(target) {
|
|
77
|
+
return valuesOf(FIXED[target] | SKIN).sort((x, y) => x - y);
|
|
78
|
+
}
|
|
79
|
+
/** The OR of every build's permutation bits, which tells the engine what the material can draw. */
|
|
80
|
+
function permutationsOf(builds) {
|
|
81
|
+
let bits = 0;
|
|
82
|
+
for (const build of Object.values(builds))
|
|
83
|
+
bits |= build.permutation;
|
|
84
|
+
return bits;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The kinds whose builds take a set for each GPU path alone, without the bits that pick a set, and
|
|
88
|
+
* the prefix of each set's file name.
|
|
89
|
+
*/
|
|
90
|
+
const LATER_KINDS = [
|
|
91
|
+
['effect', 'effect'],
|
|
92
|
+
['toneCurve', 'curve'],
|
|
93
|
+
];
|
|
94
|
+
/** True for a kind of compiled WGSL whose builds load on first use. */
|
|
95
|
+
function isBuildKind(kind) {
|
|
96
|
+
return kind === 'material' || kind === 'effect' || kind === 'toneCurve';
|
|
97
|
+
}
|
|
98
|
+
/** The shaders of one module whose builds go to sets, in the order that the module holds them. */
|
|
99
|
+
export class ModuleBuilds {
|
|
100
|
+
sources = [];
|
|
101
|
+
/** How many shaders of each kind the module gave, which numbers their records in a set. */
|
|
102
|
+
counts = new Map();
|
|
103
|
+
/**
|
|
104
|
+
* The JavaScript expression of `shader` in a module that `pack` packs, as `ShaderPack.value`
|
|
105
|
+
* gives it. The value of a shader whose builds load on first use keeps none: it gets a
|
|
106
|
+
* function that imports a set.
|
|
107
|
+
*/
|
|
108
|
+
value(pack, shader, hot) {
|
|
109
|
+
const kind = shader.kind;
|
|
110
|
+
const variants = isBuildKind(kind)
|
|
111
|
+
? shader.variants
|
|
112
|
+
: undefined;
|
|
113
|
+
if (variants === undefined || Object.keys(variants).length === 0)
|
|
114
|
+
return pack.value(shader, hot);
|
|
115
|
+
const index = this.counts.get(kind) ?? 0;
|
|
116
|
+
this.counts.set(kind, index + 1);
|
|
117
|
+
this.sources.push({ kind: kind, variants });
|
|
118
|
+
// An effect's pieces reach the thread that draws. An effect that reads the pixels beside its
|
|
119
|
+
// own joins a host as the first member of a group or of the fold. The shader build gives no
|
|
120
|
+
// pieces to an effect that declares textures or reads bloom's chain, which draws its own pass.
|
|
121
|
+
return pack.value({ ...shader, variants: {}, permutations: permutationsOf(variants) }, hot, index, kind);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** The builds of `variants` that the GPU path `target` draws, and no output for the other path. */
|
|
125
|
+
function onlyTarget(variants, target) {
|
|
126
|
+
const kept = {};
|
|
127
|
+
for (const [name, build] of Object.entries(variants)) {
|
|
128
|
+
if (build[target] === null)
|
|
129
|
+
continue;
|
|
130
|
+
kept[name] = {
|
|
131
|
+
permutation: build.permutation,
|
|
132
|
+
wgsl: target === 'wgsl' ? build.wgsl : null,
|
|
133
|
+
glsl: target === 'glsl' ? build.glsl : null,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return kept;
|
|
137
|
+
}
|
|
138
|
+
/** The builds of the shaders of `kind` in `sources`, in the module's order. */
|
|
139
|
+
function variantsOf(sources, kind) {
|
|
140
|
+
return sources.filter((source) => source.kind === kind).map((source) => source.variants);
|
|
141
|
+
}
|
|
142
|
+
/** The set of `records`, named after its bits and a hash of its builds. */
|
|
143
|
+
function setOf(bits, key, records) {
|
|
144
|
+
const json = JSON.stringify(records);
|
|
145
|
+
const digest = createHash('sha256').update(json).digest('hex').slice(0, 16);
|
|
146
|
+
return { name: `${bits}-${digest}`, key, records };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The sets that hold `sources`' builds: for a material one for each GPU path and value of its fixed
|
|
150
|
+
* bits, and for an effect or a tone curve one for each GPU path. Each set holds the builds of every
|
|
151
|
+
* shader of its kind that the set serves.
|
|
152
|
+
*/
|
|
153
|
+
export function buildSets(sources) {
|
|
154
|
+
const sets = [];
|
|
155
|
+
for (const target of ['wgsl', 'glsl']) {
|
|
156
|
+
const materials = variantsOf(sources, 'material');
|
|
157
|
+
if (materials.length > 0)
|
|
158
|
+
for (const set of setsOf(target)) {
|
|
159
|
+
const records = materials.map((variants) => buildsOfSet(variants, target, set));
|
|
160
|
+
if (records.every((record) => Object.keys(record).length === 0))
|
|
161
|
+
continue;
|
|
162
|
+
sets.push(setOf(`material-${target}-${set}`, `material ${target} ${set}`, records));
|
|
163
|
+
}
|
|
164
|
+
for (const [kind, prefix] of LATER_KINDS) {
|
|
165
|
+
const shaders = variantsOf(sources, kind);
|
|
166
|
+
if (shaders.length === 0)
|
|
167
|
+
continue;
|
|
168
|
+
const records = shaders.map((variants) => onlyTarget(variants, target));
|
|
169
|
+
if (records.every((record) => Object.keys(record).length === 0))
|
|
170
|
+
continue;
|
|
171
|
+
sets.push(setOf(`${prefix}-${target}-0`, `${kind} ${target} 0`, records));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return sets;
|
|
175
|
+
}
|
|
176
|
+
/** The code of the module that holds one set of builds. */
|
|
177
|
+
export function setModule(records) {
|
|
178
|
+
const pack = new ShaderPack();
|
|
179
|
+
return `export default ${pack.value(records)};\n${pack.unpacker()}`;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The function that imports the set of builds that a shader needs when the engine first needs it,
|
|
183
|
+
* or nothing for a module without sets. `address` gives the module of each set, which is a virtual
|
|
184
|
+
* module on the dev server and a file beside the module in a packed package.
|
|
185
|
+
*/
|
|
186
|
+
export function loadBuilds(sets, address) {
|
|
187
|
+
if (sets.length === 0)
|
|
188
|
+
return '';
|
|
189
|
+
const loaders = sets.map(({ name, key }) => `${JSON.stringify(key)}: () => import(${JSON.stringify(address(name))})`);
|
|
190
|
+
return `
|
|
191
|
+
function ${LOAD_BUILDS}(kind, target, set) {
|
|
192
|
+
const load = {
|
|
193
|
+
${loaders.join(',\n\t\t')},
|
|
194
|
+
}[kind + ' ' + target + ' ' + set];
|
|
195
|
+
return load ? load() : Promise.resolve({ default: [] });
|
|
196
|
+
}
|
|
197
|
+
`;
|
|
198
|
+
}
|
|
199
|
+
/** The sets of builds that the plugin wrote, by the name of each set's virtual module. */
|
|
200
|
+
export class MaterialBuilds {
|
|
201
|
+
sets = new Map();
|
|
202
|
+
/** The names of the sets of each module, so a module's new compile drops its old sets. */
|
|
203
|
+
owners = new Map();
|
|
204
|
+
/**
|
|
205
|
+
* The code that ends module `file`, whose shaders `builds` holds: the function that imports
|
|
206
|
+
* each set, or nothing for a module without such shaders. The sets of the module's previous
|
|
207
|
+
* compile go, unless another module has the same.
|
|
208
|
+
*/
|
|
209
|
+
finish(file, builds) {
|
|
210
|
+
const sets = buildSets(builds.sources);
|
|
211
|
+
const names = new Set(sets.map((set) => set.name));
|
|
212
|
+
for (const set of sets)
|
|
213
|
+
this.sets.set(set.name, [...set.records]);
|
|
214
|
+
const before = this.owners.get(file);
|
|
215
|
+
if (names.size > 0)
|
|
216
|
+
this.owners.set(file, names);
|
|
217
|
+
else
|
|
218
|
+
this.owners.delete(file);
|
|
219
|
+
for (const name of before ?? [])
|
|
220
|
+
if (!names.has(name) && !this.owned(name))
|
|
221
|
+
this.sets.delete(name);
|
|
222
|
+
return loadBuilds(sets, (name) => `${MATERIAL_BUILDS}${name}`);
|
|
223
|
+
}
|
|
224
|
+
/** The code of the virtual module `id`, or undefined for a module that this plugin did not name. */
|
|
225
|
+
module(id) {
|
|
226
|
+
const records = this.sets.get(id.slice(id.lastIndexOf('/') + 1));
|
|
227
|
+
return records && setModule(records);
|
|
228
|
+
}
|
|
229
|
+
/** True when a module's current compile has the set named `name`. */
|
|
230
|
+
owned(name) {
|
|
231
|
+
for (const names of this.owners.values())
|
|
232
|
+
if (names.has(name))
|
|
233
|
+
return true;
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
package/lib/offline.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Plugin, Rollup } from 'vite';
|
|
2
|
+
import type { Null3dPackage } from './package-files.js';
|
|
3
|
+
/** The file that a production build writes beside the page, with the build's files by group. */
|
|
4
|
+
export declare const FILES_LIST = "null3d-files.json";
|
|
5
|
+
/** The list of a build's files, with paths relative to the build's folder. */
|
|
6
|
+
export interface OfflineFiles {
|
|
7
|
+
/** Changes whenever any file of the list does, so a service worker can name its cache after it. */
|
|
8
|
+
version: string;
|
|
9
|
+
/** The files that a page may need to start, its pages and scripts among them. */
|
|
10
|
+
start: string[];
|
|
11
|
+
/** The files that each feature downloads on its first use, by the feature's name. */
|
|
12
|
+
features: Record<string, string[]>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The engine's modules that make up the features which are not shader features, by feature, as
|
|
16
|
+
* paths in the engine package. A shader feature's files are the shader modules named after it.
|
|
17
|
+
*/
|
|
18
|
+
export declare const FEATURE_MODULES: Readonly<Record<string, readonly string[]>>;
|
|
19
|
+
/**
|
|
20
|
+
* The features whose files hold the engine module `module`, none for a module of the start. A
|
|
21
|
+
* shader feature takes the name that `createEngine`'s `preload` gives it, such as `instance_index`
|
|
22
|
+
* for `shaders-instance-index-wgsl`. The module of the shader builds that need several features
|
|
23
|
+
* belongs to each of them.
|
|
24
|
+
*/
|
|
25
|
+
export declare function featuresOf(module: string): string[];
|
|
26
|
+
/**
|
|
27
|
+
* The path of a module in the engine package, as the list's groups name it: from the package's
|
|
28
|
+
* source or built folder, without the extension of a script. Undefined for a file of another
|
|
29
|
+
* package or of the project.
|
|
30
|
+
*/
|
|
31
|
+
export declare function engineModule(id: string, packageOf: (file: string) => Null3dPackage | undefined): string | undefined;
|
|
32
|
+
/** One file of a build, as the list reads it. */
|
|
33
|
+
export interface ListedFile {
|
|
34
|
+
fileName: string;
|
|
35
|
+
/** True for a file that a page loads first: an HTML page or an entry script. */
|
|
36
|
+
entry: boolean;
|
|
37
|
+
/** The engine modules that the file holds, as `engineModule` names them. */
|
|
38
|
+
modules: readonly string[];
|
|
39
|
+
/** The files that the file imports statically, which load with it. */
|
|
40
|
+
imports: readonly string[];
|
|
41
|
+
/** The files that the file imports on demand. */
|
|
42
|
+
loads: readonly string[];
|
|
43
|
+
/**
|
|
44
|
+
* The file's text, when it may name other files: a script, a page or a style sheet. A script's
|
|
45
|
+
* text leaves out the list of the files that its imports on demand import, which Vite writes
|
|
46
|
+
* for the browser to fetch beside them: those files load only with their importers.
|
|
47
|
+
*/
|
|
48
|
+
text?: string;
|
|
49
|
+
}
|
|
50
|
+
/** The list of the files of a build. */
|
|
51
|
+
export declare function offlineFiles(files: readonly ListedFile[]): OfflineFiles;
|
|
52
|
+
/**
|
|
53
|
+
* Finds in a text each of `bases`, the base names of a build's files, wherever it stands: inside a
|
|
54
|
+
* longer name too, as one pattern of every base name finds it. Such a pattern grows with the
|
|
55
|
+
* build's files, and a build holds thousands of shader modules, so in Node it took a quarter of a
|
|
56
|
+
* build of the demos. So, when every name has an extension, the search looks only for the names'
|
|
57
|
+
* extensions. At each, it reads the characters that end there, finds the names with that ending,
|
|
58
|
+
* and checks each of them in place. That finds each name the pattern finds, and a name that
|
|
59
|
+
* overlaps another as well.
|
|
60
|
+
*/
|
|
61
|
+
export declare function baseNamesIn(bases: readonly string[]): (text: string) => string[];
|
|
62
|
+
/** What a worker build's file holds, which the main bundle's copy of the file lacks. */
|
|
63
|
+
export interface WorkerFile {
|
|
64
|
+
moduleIds: readonly string[];
|
|
65
|
+
imports: readonly string[];
|
|
66
|
+
loads: readonly string[];
|
|
67
|
+
/** True for a script that the worker bundle made, whose text can name other files. */
|
|
68
|
+
chunk: boolean;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The files that a worker build made and that a file in the bundle still names, but that the
|
|
72
|
+
* bundle lacks, each with the source that the worker copied. Vite drops a worker's files when it
|
|
73
|
+
* reads the worker as dead, even when another file names one of them: a page then fails to
|
|
74
|
+
* download an engine shader module at run time, although the build succeeded. The caller emits
|
|
75
|
+
* these back, so a build's files always hold every file that its files name.
|
|
76
|
+
*/
|
|
77
|
+
export declare function missingWorkerAssets(bundle: Rollup.OutputBundle, workerFiles: ReadonlyMap<string, WorkerFile>): {
|
|
78
|
+
fileName: string;
|
|
79
|
+
source: string;
|
|
80
|
+
}[];
|
|
81
|
+
/** A plugin for each worker build that records what each of its files holds, by file name. */
|
|
82
|
+
export declare function workerFilesPlugin(record: Map<string, WorkerFile>): Plugin;
|
|
83
|
+
/**
|
|
84
|
+
* The files of a client build's bundle as the list reads them, with what the worker builds
|
|
85
|
+
* recorded for the files that they made. A file copied from the engine's source, such as a shader
|
|
86
|
+
* module, holds no script that names another file, so its text is left out; `tables` names the
|
|
87
|
+
* files such a module does load, its kind's shared table of shader paragraphs and one for each
|
|
88
|
+
* feature family whose paragraphs it holds. A module of a feature that loads on first use names
|
|
89
|
+
* them, so the tables join that feature's files and never the start's, which is what keeps a
|
|
90
|
+
* page's first download free of them.
|
|
91
|
+
*/
|
|
92
|
+
export declare function listedFiles(bundle: Rollup.OutputBundle, workerFiles: ReadonlyMap<string, WorkerFile>, packageOf: (file: string) => Null3dPackage | undefined, root: string, tables?: ReadonlyMap<string, readonly string[]>): ListedFile[];
|