@occluze/umber 0.2.1 → 0.4.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.md +21 -0
- package/README.md +126 -50
- package/THIRD-PARTY-NOTICES.md +33 -0
- package/dist/chunks/badge.js +2 -0
- package/dist/chunks/basis.js +2 -0
- package/dist/chunks/basis_transcoder.js +2 -0
- package/dist/chunks/basis_transcoder.wasm +0 -0
- package/dist/chunks/batches.js +2 -0
- package/dist/chunks/capture.js +2 -2
- package/dist/chunks/covers.js +2 -2
- package/dist/chunks/curves.js +2 -0
- package/dist/chunks/flip.js +2 -2
- package/dist/chunks/fx.js +2 -102
- package/dist/chunks/gl.js +2 -180
- package/dist/chunks/glsl.js +2 -239
- package/dist/chunks/glyphs.js +2 -0
- package/dist/chunks/inspect.js +2 -6
- package/dist/chunks/instances.js +2 -93
- package/dist/chunks/layers.js +2 -21
- package/dist/chunks/licence.js +2 -2
- package/dist/chunks/morph.js +2 -2
- package/dist/chunks/pace.js +2 -0
- package/dist/chunks/patch.js +2 -0
- package/dist/chunks/prepared.js +2 -0
- package/dist/chunks/profiler.js +2 -0
- package/dist/chunks/recheck.js +2 -0
- package/dist/chunks/resize.js +2 -0
- package/dist/chunks/restore.js +2 -2
- package/dist/chunks/shapes.js +2 -2
- package/dist/chunks/sim.js +2 -22
- package/dist/chunks/text.js +2 -52
- package/dist/chunks/video.js +2 -2
- package/dist/chunks/vocabulary.js +2 -0
- package/dist/chunks/warm.js +2 -2
- package/dist/modules/debug.js +2 -36
- package/dist/modules/debug.mjs +2 -36
- package/dist/modules/handoff.js +2 -2
- package/dist/modules/handoff.mjs +2 -2
- package/dist/modules/input.js +2 -2
- package/dist/modules/input.mjs +2 -2
- package/dist/modules/scrollfx.js +2 -0
- package/dist/modules/scrollfx.mjs +2 -0
- package/dist/modules/scrub.js +2 -8
- package/dist/modules/scrub.mjs +2 -8
- package/dist/modules/three.js +2 -0
- package/dist/modules/three.mjs +2 -0
- package/dist/node/assets.mjs +11 -0
- package/dist/node/astro.mjs +55 -0
- package/dist/node/cli.mjs +162 -0
- package/dist/node/shared-P6KINBNR.mjs +2113 -0
- package/dist/node/shared-VQKZUUXF.mjs +289 -0
- package/dist/node/vite.mjs +14 -0
- package/dist/prepared.mjs +2 -0
- package/dist/umber.css +2 -2
- package/dist/umber.js +2 -2
- package/dist/umber.mjs +2 -2
- package/docs/AI-quick.md +104 -86
- package/docs/AI.md +2299 -1692
- package/docs/npm.md +40 -32
- package/package.json +176 -24
- package/types/assets.d.ts +192 -0
- package/types/astro.d.ts +40 -0
- package/types/debug.d.ts +18 -17
- package/types/esm.d.ts +13 -17
- package/types/global.d.ts +17 -0
- package/types/handoff.d.ts +26 -25
- package/types/input.d.ts +63 -55
- package/types/loop.d.ts +87 -0
- package/types/module.d.ts +106 -0
- package/types/scrollfx.d.ts +44 -0
- package/types/scrub.d.ts +33 -32
- package/types/three.d.ts +251 -0
- package/types/umber.d.ts +705 -432
- package/types/vite.d.ts +33 -0
- package/dist/chunks/views.js +0 -2
- package/dist/modules/router-swap.js +0 -13
- package/dist/modules/router.js +0 -2
- package/dist/modules/router.mjs +0 -2
- package/dist/modules/scroll.js +0 -2
- package/dist/modules/scroll.mjs +0 -2
- package/types/router.d.ts +0 -181
- package/types/scroll.d.ts +0 -132
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/*! Umber v0.4.0 asset tool | (c) Ravi Klaassens | UNLICENSED */
|
|
3
|
+
import {
|
|
4
|
+
prepareSite
|
|
5
|
+
} from "./shared-P6KINBNR.mjs";
|
|
6
|
+
|
|
7
|
+
// tools/assets/cli.ts
|
|
8
|
+
import { resolve } from "node:path";
|
|
9
|
+
import { pathToFileURL } from "node:url";
|
|
10
|
+
import { parseArgs } from "node:util";
|
|
11
|
+
var HELP = `Usage: umber assets <folder> [options]
|
|
12
|
+
|
|
13
|
+
Prepares the pictures Umber draws on the built site in <folder>: each becomes BC7, ASTC
|
|
14
|
+
and ETC2 textures with all their mip levels, plus an AVIF, and the fonts of its GL text
|
|
15
|
+
become glyph outlines; every page that shows one gets a <meta name="umber-assets"> tag. Umber then uploads the file the visitor's GPU draws
|
|
16
|
+
as it is: nothing to decode in the browser, a quarter of the GPU memory.
|
|
17
|
+
|
|
18
|
+
Options:
|
|
19
|
+
--base-url <path> the URL path the folder is served at (default /)
|
|
20
|
+
--folder <name> the folder the prepared files go to, inside <folder> (default _umber)
|
|
21
|
+
--all every picture in <folder>, not only the ones Umber draws
|
|
22
|
+
--pictures <list> more pictures to prepare, files or folders inside <folder> (uploads,img/work); a
|
|
23
|
+
shader's uniform draws a prepared file only for a picture named here:
|
|
24
|
+
for pages a server renders (pageWriter() in @occluze/umber/assets), or a
|
|
25
|
+
scene of your own (picture() in @occluze/umber/prepared)
|
|
26
|
+
--data <list> the site's own number files to pack, each a path inside <folder> and what
|
|
27
|
+
it holds (alps/height.bin:u16,mesh/points.bin:f32; raw, u8, i8, u16, i16,
|
|
28
|
+
u32, i32, f32, f64; no type: raw). Loaded with data() of @occluze/umber/prepared
|
|
29
|
+
--formats <list> bc7,astc,etc2 (default: all three)
|
|
30
|
+
--no-avif no AVIF fallback
|
|
31
|
+
--avif-quality <n> 1 to 100 (default 80)
|
|
32
|
+
--effort <level> fast, normal (default) or best
|
|
33
|
+
--max-size <px> the longest side of the largest level (default 4096)
|
|
34
|
+
--dom-images <what> what the page's own <img> shows: tiny (default) a small placeholder
|
|
35
|
+
while GL loads, avif the full AVIF, source the file as it was
|
|
36
|
+
--tiny-size <px> the placeholder's longer side (default 512)
|
|
37
|
+
--tiny-quality <n> the placeholder's AVIF quality, 1 to 100 (default 50)
|
|
38
|
+
--cache <folder> where prepared files are kept between builds (default node_modules/.cache/umber-assets)
|
|
39
|
+
--no-cache make every picture again
|
|
40
|
+
--no-fonts do not prepare the fonts of GL text. By default each font a GL text uses
|
|
41
|
+
is prepared, so its letters are painted from their outlines, sharp at any
|
|
42
|
+
scale; without, from the glyph atlas (the browser's own rasterising).
|
|
43
|
+
A prepared font's outlines are a public file: check the font's licence
|
|
44
|
+
--encode-videos encode the site's scrubbed videos with the ffmpeg on this computer (the PATH,
|
|
45
|
+
or $FFMPEG): a keyframe on every frame where a video has not, a phone-sized
|
|
46
|
+
file (720 px) and a poster frame for each. The tool ships no encoder: with no
|
|
47
|
+
ffmpeg it says so and leaves the videos alone
|
|
48
|
+
--no-videos leave scrubbed videos as they are (by default one whose index is at the end
|
|
49
|
+
of the file gets it moved in front, so it scrubs while it downloads)
|
|
50
|
+
--hints <list> more of Umber's chunks for every GL page to fetch early (shapes,sim...):
|
|
51
|
+
the tool reads what a page's elements and stylesheets ask for,
|
|
52
|
+
this names what only a script does
|
|
53
|
+
--effects <file> a module of the site's own whose \`effects\` (or default) export is its
|
|
54
|
+
effects by name, as it hands them to umber.effect(): a page whose elements
|
|
55
|
+
name one is hinted for the chunks that effect needs
|
|
56
|
+
-h, --help this text`;
|
|
57
|
+
function readArgs(args) {
|
|
58
|
+
const { values, positionals } = parseArgs({
|
|
59
|
+
args,
|
|
60
|
+
allowPositionals: true,
|
|
61
|
+
options: {
|
|
62
|
+
"base-url": { type: "string" },
|
|
63
|
+
folder: { type: "string" },
|
|
64
|
+
all: { type: "boolean" },
|
|
65
|
+
pictures: { type: "string" },
|
|
66
|
+
data: { type: "string" },
|
|
67
|
+
"no-videos": { type: "boolean" },
|
|
68
|
+
"encode-videos": { type: "boolean" },
|
|
69
|
+
formats: { type: "string" },
|
|
70
|
+
"no-avif": { type: "boolean" },
|
|
71
|
+
"avif-quality": { type: "string" },
|
|
72
|
+
effort: { type: "string" },
|
|
73
|
+
"max-size": { type: "string" },
|
|
74
|
+
"dom-images": { type: "string" },
|
|
75
|
+
"tiny-size": { type: "string" },
|
|
76
|
+
"tiny-quality": { type: "string" },
|
|
77
|
+
cache: { type: "string" },
|
|
78
|
+
"no-cache": { type: "boolean" },
|
|
79
|
+
"no-fonts": { type: "boolean" },
|
|
80
|
+
hints: { type: "string" },
|
|
81
|
+
effects: { type: "string" },
|
|
82
|
+
help: { type: "boolean", short: "h" }
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
const [command, dir, ...rest] = positionals;
|
|
86
|
+
if (values.help || command !== "assets" || !dir || rest.length) return null;
|
|
87
|
+
const formats = values.formats?.split(",").map((name) => name.trim());
|
|
88
|
+
const effort = values.effort;
|
|
89
|
+
return {
|
|
90
|
+
dir,
|
|
91
|
+
baseUrl: values["base-url"],
|
|
92
|
+
folder: values.folder,
|
|
93
|
+
all: values.all,
|
|
94
|
+
pictures: values.pictures?.split(",").map((name) => name.trim()),
|
|
95
|
+
data: values.data?.split(",").map((named) => {
|
|
96
|
+
const [, file = named, type] = /^(.*):(\w+)$/.exec(named.trim()) ?? [];
|
|
97
|
+
return type ? { file, type } : file.trim();
|
|
98
|
+
}),
|
|
99
|
+
formats,
|
|
100
|
+
avif: !values["no-avif"],
|
|
101
|
+
avifQuality: values["avif-quality"] ? Number(values["avif-quality"]) : void 0,
|
|
102
|
+
effort,
|
|
103
|
+
maxSize: values["max-size"] ? Number(values["max-size"]) : void 0,
|
|
104
|
+
domImages: values["dom-images"],
|
|
105
|
+
tinySize: values["tiny-size"] ? Number(values["tiny-size"]) : void 0,
|
|
106
|
+
tinyQuality: values["tiny-quality"] ? Number(values["tiny-quality"]) : void 0,
|
|
107
|
+
cache: values["no-cache"] ? false : values.cache,
|
|
108
|
+
videos: !values["no-videos"],
|
|
109
|
+
encodeVideos: values["encode-videos"],
|
|
110
|
+
fonts: !values["no-fonts"],
|
|
111
|
+
hints: values.hints?.split(",").map((name) => name.trim()),
|
|
112
|
+
effectsFile: values.effects
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
async function readEffects(file) {
|
|
116
|
+
const module = await import(pathToFileURL(resolve(file)).href);
|
|
117
|
+
return module.effects ?? module.default;
|
|
118
|
+
}
|
|
119
|
+
var kb = (bytes = 0) => `${(bytes / 1024).toFixed(0)} KB`;
|
|
120
|
+
async function main() {
|
|
121
|
+
const args = readArgs(process.argv.slice(2));
|
|
122
|
+
if (!args) {
|
|
123
|
+
console.log(HELP);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const { effectsFile, ...options } = args;
|
|
127
|
+
const result = await prepareSite({
|
|
128
|
+
...options,
|
|
129
|
+
effects: effectsFile ? await readEffects(effectsFile) : void 0,
|
|
130
|
+
log: (line) => {
|
|
131
|
+
console.log(line);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
for (const line of result.skipped) console.warn(`skipped ${line}`);
|
|
135
|
+
if (result.encoded) console.log(`${result.encoded} files encoded for scrubbed videos.`);
|
|
136
|
+
if (result.videos) console.log(`${result.videos} scrubbed videos have their index in front of their frames now.`);
|
|
137
|
+
if (result.hinted) {
|
|
138
|
+
console.log(`${result.hinted} pages fetch Umber's files early (hints in <head>).`);
|
|
139
|
+
if (!options.hints?.length)
|
|
140
|
+
console.log(
|
|
141
|
+
"Hinted from each page's elements and stylesheets. Chunks only a script asks for (umber.sim(), umber.view(), patch: true, an effect put on an element from code) are not known to this command: name them with --hints, or build with the Vite plugin or the Astro integration, which read the site's scripts."
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
if (!result.manifest) {
|
|
145
|
+
console.log(
|
|
146
|
+
"No page has a picture Umber draws (a [data-umber] element's <img>): nothing to prepare. --all prepares every picture."
|
|
147
|
+
);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const { source, ...made } = result.bytes;
|
|
151
|
+
const sizes = Object.entries(made).map(([kind, bytes]) => `${kind} ${kb(bytes)}`);
|
|
152
|
+
const pictures = sizes.length ? `Pictures: sources ${kb(source)}, prepared ${sizes.join(", ")}. ` : "";
|
|
153
|
+
const fonts = result.fonts ? `${result.fonts} fonts for GL text. ` : "";
|
|
154
|
+
const data = result.data ? `${result.data} number files: ${kb(result.bytes.dataSource)} packed to ${kb(result.bytes.data)}. ` : "";
|
|
155
|
+
console.log(`${pictures}${fonts}${data}${result.pages} pages point at ${result.manifest}`);
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
await main();
|
|
159
|
+
} catch (err) {
|
|
160
|
+
console.error(`umber assets: ${err instanceof Error ? err.message : String(err)}`);
|
|
161
|
+
process.exitCode = 1;
|
|
162
|
+
}
|