@skathi-native/cli 0.1.0-beta.4 → 0.3.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/aot/host-globals.json +1 -1
- package/aot/pin.ts +1 -1
- package/aot/toolchain.lock.json +5 -5
- package/aot/transform.ts +9 -1
- package/aot-inputs.ts +21 -2
- package/build.ts +284 -64
- package/check/builtins.json +11 -11
- package/check/bundle.ts +265 -0
- package/check/codes.ts +46 -0
- package/check/css-catalog.json +451 -0
- package/check/css.ts +512 -0
- package/check/finding.ts +63 -1
- package/check/graph.ts +14 -1
- package/check/index.ts +30 -49
- package/check/program.ts +26 -6
- package/cli/aot-build.ts +2 -6
- package/cli/build-app.ts +19 -0
- package/cli/create.ts +70 -12
- package/cli/dev.ts +11 -6
- package/cli/effects.ts +39 -18
- package/cli/gallery.ts +106 -0
- package/cli/sk.ts +5 -2
- package/devtools/commands.ts +26 -1
- package/devtools/ctl.ts +4 -3
- package/effects/compile.ts +160 -31
- package/effects/sk.slang +359 -30
- package/gallery.json +1 -0
- package/package.json +9 -5
- package/prod.ts +78 -10
- package/svelte.ts +76 -0
- package/templates/icon.png +0 -0
- package/templates/showcase/assets/textures/golden.png +0 -0
- package/templates/showcase/assets/textures/hammered.png +0 -0
- package/templates/showcase/assets/textures/noir.png +0 -0
- package/templates/showcase/assets/textures/reeded.png +0 -0
- package/templates/showcase/assets/textures/teal-orange.png +0 -0
- package/templates/showcase/shaders/dissolve.slang +40 -0
- package/templates/showcase/shaders/fireflies.slang +58 -0
- package/templates/showcase/shaders/glass.slang +31 -0
- package/templates/showcase/shaders/grade.slang +34 -0
- package/templates/showcase/shaders/halftone.slang +42 -0
- package/templates/showcase/shaders/lens.slang +51 -0
- package/templates/showcase/shaders/nebula.slang +57 -0
- package/templates/showcase/shaders/orbit.slang +52 -0
- package/templates/showcase/shaders/pond.slang +76 -0
- package/templates/showcase/shaders/ripples.slang +71 -0
- package/templates/showcase/shaders/shatter.slang +116 -0
- package/templates/showcase/shaders/snow.slang +57 -0
- package/templates/showcase/shaders/spotlight.slang +52 -0
- package/templates/showcase/src/App.vue +11 -16
- package/templates/showcase/src/components/FullWindow.vue +77 -0
- package/templates/showcase/src/components/Page.vue +2 -0
- package/templates/showcase/src/fullwindow.ts +36 -0
- package/templates/showcase/src/icons.ts +2 -0
- package/templates/showcase/src/pages/GraphicsPage.vue +122 -0
- package/templates/showcase/src/pages/MotionPage.vue +71 -1
- package/templates/showcase/src/pages/ShadersPage.vue +443 -0
- package/templates/showcase/src/router.ts +32 -1
- package/templates/svelte/.vscode/settings.json +3 -0
- package/templates/svelte/assets/hello.txt +1 -0
- package/templates/svelte/src/App.svelte +142 -0
- package/templates/svelte/src/main.ts +4 -0
- package/vitecompat.ts +2 -0
package/cli/gallery.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Templates that live in github.com/argon-chat/skathi-templates. A Skathi checkout has them in its
|
|
2
|
+
// templates/ submodule; an installed CLI downloads the commit it was released with, which the release
|
|
3
|
+
// writes into gallery.json beside package.json.
|
|
4
|
+
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { dirname, join, resolve } from "node:path";
|
|
7
|
+
import { ConfigError } from "./config";
|
|
8
|
+
import { cacheRoot } from "./host";
|
|
9
|
+
|
|
10
|
+
export const GALLERY_REPO = "argon-chat/skathi-templates";
|
|
11
|
+
|
|
12
|
+
const CHECKOUT = resolve(import.meta.dir, "../../../templates");
|
|
13
|
+
const PIN = resolve(import.meta.dir, "../gallery.json");
|
|
14
|
+
|
|
15
|
+
function pinnedCommit(): string | null {
|
|
16
|
+
try {
|
|
17
|
+
const commit: unknown = JSON.parse(readFileSync(PIN, "utf8")).commit;
|
|
18
|
+
return typeof commit === "string" && /^[0-9a-f]{40}$/.test(commit) ? commit : null;
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const cachedGallery = (commit: string) => join(dirname(cacheRoot()), "templates", commit);
|
|
25
|
+
|
|
26
|
+
/** Where the template's files are, or null when they still have to be downloaded. */
|
|
27
|
+
export function galleryDir(template: string): string | null {
|
|
28
|
+
const local = join(CHECKOUT, template);
|
|
29
|
+
if (existsSync(local)) return local;
|
|
30
|
+
const commit = pinnedCommit();
|
|
31
|
+
const cached = commit ? join(cachedGallery(commit), template) : null;
|
|
32
|
+
return cached && existsSync(cached) ? cached : null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Downloads the pinned templates unless they are already here. */
|
|
36
|
+
export async function fetchGallery(template: string): Promise<string> {
|
|
37
|
+
const ready = galleryDir(template);
|
|
38
|
+
if (ready) return ready;
|
|
39
|
+
const commit = pinnedCommit();
|
|
40
|
+
if (!commit) {
|
|
41
|
+
throw new ConfigError(
|
|
42
|
+
`sk create: the ${template} template comes from github.com/${GALLERY_REPO}; in a Skathi checkout run ` +
|
|
43
|
+
"`git submodule update --init templates`",
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
const url = `https://codeload.github.com/${GALLERY_REPO}/tar.gz/${commit}`;
|
|
47
|
+
const res = await fetch(url, { headers: { "User-Agent": "skathi-cli" } });
|
|
48
|
+
if (!res.ok) throw new ConfigError(`sk create: downloading the ${template} template from ${url}: HTTP ${res.status}`);
|
|
49
|
+
const files = untar(Bun.gunzipSync(new Uint8Array(await res.arrayBuffer())));
|
|
50
|
+
|
|
51
|
+
const root = cachedGallery(commit);
|
|
52
|
+
const part = `${root}.part-${process.pid}`;
|
|
53
|
+
rmSync(part, { recursive: true, force: true });
|
|
54
|
+
for (const [path, bytes] of files) {
|
|
55
|
+
const rel = path.split("/").slice(1).join("/");
|
|
56
|
+
if (!rel) continue;
|
|
57
|
+
const dest = join(part, rel);
|
|
58
|
+
mkdirSync(dirname(dest), { recursive: true });
|
|
59
|
+
writeFileSync(dest, bytes);
|
|
60
|
+
}
|
|
61
|
+
rmSync(root, { recursive: true, force: true });
|
|
62
|
+
renameSync(part, root);
|
|
63
|
+
|
|
64
|
+
const dir = galleryDir(template);
|
|
65
|
+
if (!dir) throw new ConfigError(`sk create: github.com/${GALLERY_REPO} at ${commit} has no ${template} template`);
|
|
66
|
+
return dir;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The regular files of a tar archive, by path. */
|
|
70
|
+
export function untar(tar: Uint8Array): Map<string, Uint8Array> {
|
|
71
|
+
const decoder = new TextDecoder();
|
|
72
|
+
const text = (from: number, length: number) => {
|
|
73
|
+
const field = tar.subarray(from, from + length);
|
|
74
|
+
const end = field.indexOf(0);
|
|
75
|
+
return decoder.decode(end < 0 ? field : field.subarray(0, end));
|
|
76
|
+
};
|
|
77
|
+
const out = new Map<string, Uint8Array>();
|
|
78
|
+
let longName: string | null = null;
|
|
79
|
+
for (let at = 0; at + 512 <= tar.length;) {
|
|
80
|
+
const name = text(at, 100);
|
|
81
|
+
if (!name) break;
|
|
82
|
+
const size = Number.parseInt(text(at + 124, 12).trim() || "0", 8);
|
|
83
|
+
const type = tar[at + 156] ?? 0;
|
|
84
|
+
const prefix = text(at + 345, 155);
|
|
85
|
+
const body = tar.subarray(at + 512, at + 512 + size);
|
|
86
|
+
at += 512 + Math.ceil(size / 512) * 512;
|
|
87
|
+
|
|
88
|
+
if (type === 0x78 /* x: pax */) {
|
|
89
|
+
longName = /(?:^|\n)\d+ path=([^\n]*)\n/.exec(decoder.decode(body))?.[1] ?? null;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (type === 0x4c /* L: GNU long name */) {
|
|
93
|
+
longName = decoder.decode(body).replace(/\0+$/, "");
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const path = longName ?? (prefix ? `${prefix}/${name}` : name);
|
|
97
|
+
longName = null;
|
|
98
|
+
if (type !== 0x30 && type !== 0) continue;
|
|
99
|
+
if (path.split("/").some((part) => part === ".." || part === "")) {
|
|
100
|
+
if (!path.endsWith("/")) throw new ConfigError(`the template archive has an unsafe path: ${path}`);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
out.set(path, body);
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
package/cli/sk.ts
CHANGED
|
@@ -140,7 +140,10 @@ export function cli(run: Run): Command {
|
|
|
140
140
|
.description("Start a new app. In a terminal it asks for whatever the options leave open.")
|
|
141
141
|
.argument("[dir]")
|
|
142
142
|
.option("--name <name>", "The app's name (default: the directory's)")
|
|
143
|
-
.option(
|
|
143
|
+
.option(
|
|
144
|
+
"--template <name>",
|
|
145
|
+
"showcase (every feature), minimal, svelte, player (a Svelte music player) or weather (a Vue weather app)",
|
|
146
|
+
)
|
|
144
147
|
.option("--os <list>", "What to package for: windows, macos, linux")
|
|
145
148
|
.option("--devtools", "Keep devtools (F12) in published builds")
|
|
146
149
|
.addOption(hidden("--no-devtools"))
|
|
@@ -165,7 +168,7 @@ export function cli(run: Run): Command {
|
|
|
165
168
|
.command("dev")
|
|
166
169
|
.summary("Run the app with hot reload")
|
|
167
170
|
.description(
|
|
168
|
-
"Run the app with hot reload: edits to .vue, .ts and .css apply without a restart; an edit to a shaders/*.slang effect recompiles it and
|
|
171
|
+
"Run the app with hot reload: edits to .vue, .ts and .css apply without a restart; an edit to a shaders/*.slang effect recompiles it and reloads it in the running app.",
|
|
169
172
|
)
|
|
170
173
|
.argument("[app]")
|
|
171
174
|
.option("--exe <workload>", "Run this dev workload instead of the cached one")
|
package/devtools/commands.ts
CHANGED
|
@@ -407,7 +407,7 @@ export const COMMANDS: CommandSpec[] = [
|
|
|
407
407
|
{
|
|
408
408
|
cmd: "screenshot",
|
|
409
409
|
description:
|
|
410
|
-
"Capture the app window to a PNG. Default backend is gpui's render_to_image readback: the " +
|
|
410
|
+
"Capture the app window (or the one `window` names) to a PNG. Default backend is gpui's render_to_image readback: the " +
|
|
411
411
|
"CLIENT area exactly (clientX/clientY come back 0), works unfocused, occluded, off-screen " +
|
|
412
412
|
"and minimized, and never raises or activates the window — but it cannot see a mica/acrylic " +
|
|
413
413
|
"backdrop, which DWM composites under the app. Pass backend=print_window for the composed " +
|
|
@@ -769,6 +769,31 @@ export const COMMANDS: CommandSpec[] = [
|
|
|
769
769
|
name: typeof flags.name === "string" ? flags.name : rest[1],
|
|
770
770
|
}),
|
|
771
771
|
},
|
|
772
|
+
{
|
|
773
|
+
cmd: "effects",
|
|
774
|
+
description:
|
|
775
|
+
"`--shading` effects: the effects.json schemas the host loaded (built-ins and the app's own), and " +
|
|
776
|
+
"every element painting one with its declared text, resolved parameters and the rules that declare " +
|
|
777
|
+
"it. `set` overrides an element's `--shading` inline, live, and answers the advisories the value " +
|
|
778
|
+
"raises; `reset` puts back what the app had.",
|
|
779
|
+
usage: [
|
|
780
|
+
" effects [list] schemas and the elements using them",
|
|
781
|
+
" effects node --node N one element's effect",
|
|
782
|
+
" effects set --node N --value TEXT override live, e.g. --value 'frost(0.6, 14px)'",
|
|
783
|
+
" effects reset --node N drop the override",
|
|
784
|
+
],
|
|
785
|
+
args: {
|
|
786
|
+
op: str('"list" (default), "node", "set" or "reset"'),
|
|
787
|
+
node: NODE,
|
|
788
|
+
value: str("for op=set: the `--shading` value, e.g. frost(0.6, 14px) or none"),
|
|
789
|
+
},
|
|
790
|
+
cli: (rest, flags) =>
|
|
791
|
+
compact({
|
|
792
|
+
op: rest[0] || "list",
|
|
793
|
+
node: num(flags.node ?? rest[1]),
|
|
794
|
+
value: stringFlag(flags.value),
|
|
795
|
+
}),
|
|
796
|
+
},
|
|
772
797
|
{
|
|
773
798
|
cmd: "raise",
|
|
774
799
|
description:
|
package/devtools/ctl.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { connect } from "node:net";
|
|
13
|
-
import { readFileSync } from "node:fs";
|
|
13
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
14
14
|
import { resolve, dirname, join } from "node:path";
|
|
15
15
|
import { fileURLToPath } from "node:url";
|
|
16
16
|
|
|
@@ -18,7 +18,8 @@ import { buildRequest, usageBlock, UsageError, splitArgs } from "./commands";
|
|
|
18
18
|
import { appSlot } from "./apps";
|
|
19
19
|
|
|
20
20
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
21
|
-
const
|
|
21
|
+
const APP_DIST = resolve("dist", ".sk-dev");
|
|
22
|
+
const DEFAULT_DIST = existsSync(join(APP_DIST, "devtools.json")) ? APP_DIST : resolve(HERE, "..", "dist");
|
|
22
23
|
/** A wedged pump must never hang the caller. Overridable with --timeout <ms>. */
|
|
23
24
|
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
24
25
|
|
|
@@ -71,7 +72,7 @@ function readHandshake(dir: string): Handshake {
|
|
|
71
72
|
} catch {
|
|
72
73
|
die(
|
|
73
74
|
`no devtools.json at ${path} — is a dev host running with this dist?\n` +
|
|
74
|
-
` start one:
|
|
75
|
+
` start one: run \`sk dev\` in the app's folder, then run this from the same folder\n` +
|
|
75
76
|
` or point at another slot: --dist <dir>`,
|
|
76
77
|
);
|
|
77
78
|
}
|
package/effects/compile.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { PIN, ShaderCompilerError } from "./redslangc";
|
|
|
20
20
|
|
|
21
21
|
/// Bumped when the prelude or generated wrapper changes codegen or schema shape; rides in every
|
|
22
22
|
/// header and effects.json. Rust refuses an effects.json with an unknown schema.
|
|
23
|
-
export const SCHEMA =
|
|
23
|
+
export const SCHEMA = 10;
|
|
24
24
|
|
|
25
25
|
export const PRELUDE = join(import.meta.dir, "sk.slang");
|
|
26
26
|
|
|
@@ -28,8 +28,8 @@ export const PRELUDE = join(import.meta.dir, "sk.slang");
|
|
|
28
28
|
/// `gpui_windows` and `gpui_wgpu`, and the ids in `crates/sk-effects/generated/effects.json`. It is not alphabetical.
|
|
29
29
|
export const BUILTIN_EFFECTS = ["frost", "noise", "glow"];
|
|
30
30
|
|
|
31
|
-
///
|
|
32
|
-
const PARAM_SLOTS =
|
|
31
|
+
/// Floats per instance (`EffectQuad::params`); raising it widens every effect quad.
|
|
32
|
+
const PARAM_SLOTS = 32;
|
|
33
33
|
|
|
34
34
|
const ENTRY = "effect_fragment";
|
|
35
35
|
|
|
@@ -73,8 +73,10 @@ const TARGETS: Target[] = [
|
|
|
73
73
|
},
|
|
74
74
|
];
|
|
75
75
|
|
|
76
|
-
// Group 0 the globals, 1 the instance buffer, 2 the backdrop, its sampler and the snapshot
|
|
77
|
-
|
|
76
|
+
// Group 0 the globals, 1 the instance buffer, 2 the backdrop, its sampler and the snapshot, the
|
|
77
|
+
// `SkTexture` images (3..6), the element's content (7) and history (8), and the images' repeating
|
|
78
|
+
// sampler (9).
|
|
79
|
+
const WGSL_BINDINGS = new Set(["0:0", "1:0", "2:0", "2:1", "2:2", "2:3", "2:4", "2:5", "2:6", "2:7", "2:8", "2:9"]);
|
|
78
80
|
|
|
79
81
|
/// The renderer builds one pipeline layout for every effect; a resource outside it would fail at
|
|
80
82
|
/// pipeline creation on the user's machine, so refuse it here.
|
|
@@ -90,14 +92,21 @@ function checkWgslBindings(code: string, file: string) {
|
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
94
|
|
|
93
|
-
/// The prelude's resources on Metal, where Slang keeps the HLSL registers (b0, t1, t0, t2, s1). One
|
|
95
|
+
/// The prelude's resources on Metal, where Slang keeps the HLSL registers (b0, t1, t0, t2, t3..t8, s1, s2). One
|
|
94
96
|
/// argument table for every effect, so the renderer binds these and nothing else.
|
|
95
97
|
const METAL_BINDINGS: Array<[at: string, name: string, what: string]> = [
|
|
96
98
|
["buffer(0)", "GlobalParams", "constant, the 48-byte globals"],
|
|
97
|
-
["buffer(1)", "sk_effect_quads", "device EffectQuad[],
|
|
99
|
+
["buffer(1)", "sk_effect_quads", "device EffectQuad[], 224 bytes each"],
|
|
98
100
|
["texture(0)", "sk_backdrop_input", "the blurred backdrop"],
|
|
99
101
|
["texture(2)", "sk_backdrop_original", "the render-target snapshot"],
|
|
102
|
+
["texture(7)", "sk_content", "the element's content"],
|
|
103
|
+
["texture(8)", "sk_history", "the effect's history"],
|
|
100
104
|
["sampler(1)", "sk_clamp_sampler", "clamp to edge"],
|
|
105
|
+
["texture(3)", "sk_texture0", "the first SkTexture"],
|
|
106
|
+
["texture(4)", "sk_texture1", "the second SkTexture"],
|
|
107
|
+
["texture(5)", "sk_texture2", "the third SkTexture"],
|
|
108
|
+
["texture(6)", "sk_texture3", "the fourth SkTexture"],
|
|
109
|
+
["sampler(2)", "sk_repeat_sampler", "repeat"],
|
|
101
110
|
];
|
|
102
111
|
|
|
103
112
|
/// Refuses Metal output whose entry point or arguments are not the ones the renderer provides.
|
|
@@ -126,26 +135,47 @@ const METAL_NOTE =
|
|
|
126
135
|
METAL_BINDINGS.map(([at, name, what]) => `// [[${at}]]`.padEnd(20) + `${name.padEnd(22)}${what}\n`).join("") +
|
|
127
136
|
`// The VERTEX half is the Metal renderer's own, shared by every effect.\n`;
|
|
128
137
|
|
|
129
|
-
type ParamKind = "number" | "length" | "color";
|
|
138
|
+
type ParamKind = "number" | "length" | "color" | "texture";
|
|
130
139
|
|
|
131
140
|
type ParamSchema = {
|
|
132
141
|
name: string;
|
|
133
142
|
kind: ParamKind;
|
|
143
|
+
/// A texture's first slot holds its width and the next its height, which the host writes.
|
|
134
144
|
slot: number;
|
|
135
145
|
required: boolean;
|
|
146
|
+
/// A texture's is what it reads as while missing, straight RGBA.
|
|
136
147
|
default: [number, number, number, number];
|
|
137
148
|
range: [number, number] | null;
|
|
149
|
+
/// A texture's binding, 0..3 (t3..t6), in declaration order.
|
|
150
|
+
texture?: number;
|
|
151
|
+
/// A texture sampled as stored, without premultiplying ([SkLinear]).
|
|
152
|
+
linear?: boolean;
|
|
138
153
|
};
|
|
139
154
|
|
|
155
|
+
/// `SkTexture` fields per effect: the bindings the renderers provide.
|
|
156
|
+
const TEXTURE_SLOTS = 4;
|
|
157
|
+
|
|
140
158
|
export type EffectSchema = {
|
|
141
159
|
name: string;
|
|
142
160
|
struct: string;
|
|
143
161
|
doc: string | null;
|
|
144
162
|
backdrop: boolean;
|
|
163
|
+
/// `[SkContent]`: drawn in place of its element's own painting, which it reads.
|
|
164
|
+
content: boolean;
|
|
165
|
+
/// `[SkHistory]`: keeps state per element from frame to frame.
|
|
166
|
+
history: boolean;
|
|
145
167
|
params: ParamSchema[];
|
|
146
168
|
backdropRadiusParam: number | null;
|
|
147
169
|
bleedParam: number | null;
|
|
148
170
|
animatedParam: number | null;
|
|
171
|
+
/// `[SkPointer]`'s first slot: the host writes the pointer there; not a CSS argument.
|
|
172
|
+
pointerParam: number | null;
|
|
173
|
+
/// `[SkPointerTimes]`'s first slot, host-filled like `pointerParam`.
|
|
174
|
+
pointerTimesParam: number | null;
|
|
175
|
+
/// Every slot of an `[SkAnimatedFor]` field: times on the effect clock.
|
|
176
|
+
clockSlots: number[];
|
|
177
|
+
/// The longest `[SkAnimatedFor]` window, in seconds.
|
|
178
|
+
clockWindow: number | null;
|
|
149
179
|
signature: string;
|
|
150
180
|
};
|
|
151
181
|
|
|
@@ -177,25 +207,24 @@ float4 sk_reflect_probe(float4 sk_position : SV_Position) : SV_Target
|
|
|
177
207
|
`;
|
|
178
208
|
}
|
|
179
209
|
|
|
180
|
-
|
|
181
|
-
const bank = slot < 4 ? "params0" : "params1";
|
|
182
|
-
return `sk_in.${bank}.${"xyzw"[slot % 4]}`;
|
|
183
|
-
}
|
|
210
|
+
const slotExpr = (slot: number): string => `sk_in.param(${slot}u)`;
|
|
184
211
|
|
|
185
|
-
function loadExpr(
|
|
186
|
-
if (
|
|
212
|
+
function loadExpr(field: Field): string {
|
|
213
|
+
if (field.texture) {
|
|
214
|
+
const { index, fallback } = field.texture;
|
|
215
|
+
return (
|
|
216
|
+
`sk_texture(${index}u, float2(${slotExpr(field.slot)}, ${slotExpr(field.slot + 1)}), ` +
|
|
217
|
+
`float4(${fallback.join(", ")}))`
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
if (field.components === 1) return slotExpr(field.slot);
|
|
187
221
|
const parts: string[] = [];
|
|
188
|
-
for (let c = 0; c < components; c += 1) parts.push(slotExpr(
|
|
189
|
-
return `float${components}(${parts.join(", ")})`;
|
|
222
|
+
for (let c = 0; c < field.components; c += 1) parts.push(slotExpr(field.slot + c));
|
|
223
|
+
return `float${field.components}(${parts.join(", ")})`;
|
|
190
224
|
}
|
|
191
225
|
|
|
192
226
|
function realWrapper(effect: EffectSchema, fields: Field[]): string {
|
|
193
|
-
const assignments = fields
|
|
194
|
-
.map((field) => {
|
|
195
|
-
const param = effect.params[field.firstParam];
|
|
196
|
-
return ` sk_material.${field.name} = ${loadExpr(param!, field.components)};`;
|
|
197
|
-
})
|
|
198
|
-
.join("\n");
|
|
227
|
+
const assignments = fields.map((field) => ` sk_material.${field.name} = ${loadExpr(field)};`).join("\n");
|
|
199
228
|
return `${WRAPPER_BANNER}
|
|
200
229
|
// Kept for the record: reflection reads this declaration, every backend
|
|
201
230
|
// strips it (nothing references it), and the renderer never binds it.
|
|
@@ -256,6 +285,7 @@ const readText = (file: string): string => readFileSync(file, "utf8").replace(/\
|
|
|
256
285
|
|
|
257
286
|
interface ReflType {
|
|
258
287
|
kind?: string;
|
|
288
|
+
name?: string;
|
|
259
289
|
scalarType?: string;
|
|
260
290
|
elementType?: ReflType;
|
|
261
291
|
elementCount?: number | string;
|
|
@@ -366,8 +396,9 @@ type Attribute = { name: string; arguments: unknown[] };
|
|
|
366
396
|
type Field = {
|
|
367
397
|
name: string;
|
|
368
398
|
components: number;
|
|
369
|
-
|
|
370
|
-
|
|
399
|
+
slot: number;
|
|
400
|
+
/// An `SkTexture`: its binding and the colour it reads as while missing, as `sample` returns it.
|
|
401
|
+
texture?: { index: number; fallback: [number, number, number, number] };
|
|
371
402
|
};
|
|
372
403
|
|
|
373
404
|
function attr(attrs: Attribute[], name: string): Attribute | undefined {
|
|
@@ -436,7 +467,10 @@ function allocate(used: boolean[], components: number): number {
|
|
|
436
467
|
return -1;
|
|
437
468
|
}
|
|
438
469
|
|
|
470
|
+
const isTexture = (type: ReflType | undefined): boolean => type?.kind === "struct" && type.name === "SkTexture";
|
|
471
|
+
|
|
439
472
|
function fieldComponents(type: ReflType | undefined, where: string): number {
|
|
473
|
+
if (isTexture(type)) return 2;
|
|
440
474
|
if (type?.kind === "scalar") {
|
|
441
475
|
if (type.scalarType !== "float32") {
|
|
442
476
|
throw new SchemaError(
|
|
@@ -455,14 +489,25 @@ function fieldComponents(type: ReflType | undefined, where: string): number {
|
|
|
455
489
|
return n;
|
|
456
490
|
}
|
|
457
491
|
throw new SchemaError(
|
|
458
|
-
`${where}: unsupported parameter type \`${type?.kind ?? "?"}\` — a parameter must be ` +
|
|
459
|
-
"`float`, `float2`, `float3` or `
|
|
460
|
-
"samplers cannot ride in the
|
|
492
|
+
`${where}: unsupported parameter type \`${type?.name ?? type?.kind ?? "?"}\` — a parameter must be ` +
|
|
493
|
+
"`float`, `float2`, `float3`, `float4` or `SkTexture` (an image: matrices, arrays, raw " +
|
|
494
|
+
"textures and samplers cannot ride in the 32-float parameter block)",
|
|
461
495
|
);
|
|
462
496
|
}
|
|
463
497
|
|
|
464
498
|
const COMPONENT_SUFFIX = ["x", "y", "z", "w"];
|
|
465
499
|
|
|
500
|
+
const HOST_FILLED_REFUSES = [
|
|
501
|
+
"SkDefault",
|
|
502
|
+
"SkRange",
|
|
503
|
+
"SkLength",
|
|
504
|
+
"SkColor",
|
|
505
|
+
"SkOptional",
|
|
506
|
+
"SkAnimated",
|
|
507
|
+
"SkBleed",
|
|
508
|
+
"SkBackdropRadius",
|
|
509
|
+
];
|
|
510
|
+
|
|
466
511
|
function buildSchema(
|
|
467
512
|
reflection: Reflection | null,
|
|
468
513
|
structName: string,
|
|
@@ -502,6 +547,11 @@ function buildSchema(
|
|
|
502
547
|
let backdropRadiusParam: number | null = null;
|
|
503
548
|
let bleedParam: number | null = null;
|
|
504
549
|
let animatedParam: number | null = null;
|
|
550
|
+
let pointerParam: number | null = null;
|
|
551
|
+
let pointerTimesParam: number | null = null;
|
|
552
|
+
const clockSlots: number[] = [];
|
|
553
|
+
let clockWindow: number | null = null;
|
|
554
|
+
let textures = 0;
|
|
505
555
|
let backdrop = attr(structAttrs, "SkBackdrop") !== undefined;
|
|
506
556
|
// Taken float slots: `[SkSlot]` runs are reserved first, then fields pack in declaration order.
|
|
507
557
|
const used: boolean[] = new Array(PARAM_SLOTS).fill(false);
|
|
@@ -541,7 +591,7 @@ function buildSchema(
|
|
|
541
591
|
if (isColor && isLength) {
|
|
542
592
|
throw new SchemaError(`${where}: [SkColor] and [SkLength] are mutually exclusive`);
|
|
543
593
|
}
|
|
544
|
-
if (optional && components > 1 && !isColor) {
|
|
594
|
+
if (optional && components > 1 && !isColor && !isTexture(field.type)) {
|
|
545
595
|
// A bare vector expands to one CSS argument per component and optional parameters are
|
|
546
596
|
// skipped one argument at a time, so half a `float2` could be filled in: refuse.
|
|
547
597
|
throw new SchemaError(
|
|
@@ -557,13 +607,82 @@ function buildSchema(
|
|
|
557
607
|
if (slot < 0) {
|
|
558
608
|
throw new SchemaError(
|
|
559
609
|
`${where}: no room left in the parameter block. An effect quad carries ` +
|
|
560
|
-
`${PARAM_SLOTS} floats (EffectQuad::
|
|
610
|
+
`${PARAM_SLOTS} floats (EffectQuad::params) and a <color> costs 4; ` +
|
|
561
611
|
"drop or merge a parameter.",
|
|
562
612
|
);
|
|
563
613
|
}
|
|
564
614
|
for (let c = 0; c < components; c += 1) used[slot + c] = true;
|
|
565
615
|
}
|
|
566
616
|
|
|
617
|
+
const linear = attr(attrs, "SkLinear") !== undefined;
|
|
618
|
+
if (isTexture(field.type)) {
|
|
619
|
+
const refused = [
|
|
620
|
+
...HOST_FILLED_REFUSES.filter((a) => a !== "SkDefault" && a !== "SkOptional"),
|
|
621
|
+
"SkAnimatedFor",
|
|
622
|
+
"SkPointer",
|
|
623
|
+
"SkPointerTimes",
|
|
624
|
+
].find((a) => attr(attrs, a) !== undefined);
|
|
625
|
+
if (refused) throw new SchemaError(`${where}: [${refused}] cannot go on an SkTexture`);
|
|
626
|
+
if (textures === TEXTURE_SLOTS) {
|
|
627
|
+
throw new SchemaError(`${where}: an effect samples at most ${TEXTURE_SLOTS} SkTexture images`);
|
|
628
|
+
}
|
|
629
|
+
const fallback = defaultAttr
|
|
630
|
+
? parseDefault(String(defaultAttr.arguments?.[0] ?? ""), 4, where)
|
|
631
|
+
: ([0, 0, 0, 0] as [number, number, number, number]);
|
|
632
|
+
const [r, g, b, a] = fallback;
|
|
633
|
+
fields.push({
|
|
634
|
+
name: fieldName,
|
|
635
|
+
components,
|
|
636
|
+
slot,
|
|
637
|
+
texture: { index: textures, fallback: linear ? fallback : [r * a, g * a, b * a, a] },
|
|
638
|
+
});
|
|
639
|
+
params.push({
|
|
640
|
+
name: fieldName,
|
|
641
|
+
kind: "texture",
|
|
642
|
+
slot,
|
|
643
|
+
required: !optional,
|
|
644
|
+
default: fallback,
|
|
645
|
+
range: null,
|
|
646
|
+
texture: textures,
|
|
647
|
+
linear,
|
|
648
|
+
});
|
|
649
|
+
textures += 1;
|
|
650
|
+
continue;
|
|
651
|
+
}
|
|
652
|
+
if (linear) throw new SchemaError(`${where}: [SkLinear] is only legal on an SkTexture`);
|
|
653
|
+
fields.push({ name: fieldName, components, slot });
|
|
654
|
+
|
|
655
|
+
const animatedFor = attr(attrs, "SkAnimatedFor");
|
|
656
|
+
if (animatedFor) {
|
|
657
|
+
const seconds = Number(animatedFor.arguments?.[0]);
|
|
658
|
+
if (!Number.isFinite(seconds) || seconds <= 0) {
|
|
659
|
+
throw new SchemaError(
|
|
660
|
+
`${where}: [SkAnimatedFor(${animatedFor.arguments?.[0]})] needs a positive number of seconds`,
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
clockWindow = Math.max(clockWindow ?? 0, seconds);
|
|
664
|
+
for (let c = 0; c < components; c += 1) clockSlots.push(slot + c);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
const host = (["SkPointer", "SkPointerTimes"] as const).filter((a) => attr(attrs, a) !== undefined);
|
|
668
|
+
if (host.length > 1) throw new SchemaError(`${where}: [SkPointer] and [SkPointerTimes] are mutually exclusive`);
|
|
669
|
+
if (host[0]) {
|
|
670
|
+
const kind = host[0];
|
|
671
|
+
const wanted = kind === "SkPointer" ? 2 : 3;
|
|
672
|
+
if (components !== wanted) throw new SchemaError(`${where}: [${kind}] is only legal on a float${wanted}`);
|
|
673
|
+
const css = HOST_FILLED_REFUSES.find((a) => attr(attrs, a) !== undefined);
|
|
674
|
+
if (css) {
|
|
675
|
+
throw new SchemaError(
|
|
676
|
+
`${where}: [${css}] cannot go on a [${kind}] parameter — the host fills it, it is not a CSS argument`,
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
const current = kind === "SkPointer" ? pointerParam : pointerTimesParam;
|
|
680
|
+
if (current !== null) throw new SchemaError(`${where}: [${kind}] appears more than once in \`${structName}\``);
|
|
681
|
+
if (kind === "SkPointer") pointerParam = slot;
|
|
682
|
+
else pointerTimesParam = slot;
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
685
|
+
|
|
567
686
|
const defaults = defaultAttr
|
|
568
687
|
? parseDefault(String(defaultAttr.arguments?.[0] ?? ""), components, where)
|
|
569
688
|
: ([0, 0, 0, 0] as [number, number, number, number]);
|
|
@@ -571,7 +690,6 @@ function buildSchema(
|
|
|
571
690
|
? ([Number(rangeAttr.arguments?.[0]), Number(rangeAttr.arguments?.[1])] as [number, number])
|
|
572
691
|
: null;
|
|
573
692
|
|
|
574
|
-
const firstParam = params.length;
|
|
575
693
|
if (isColor) {
|
|
576
694
|
params.push({ name: fieldName, kind: "color", slot, required: !optional, default: defaults, range: null });
|
|
577
695
|
} else {
|
|
@@ -586,7 +704,6 @@ function buildSchema(
|
|
|
586
704
|
});
|
|
587
705
|
}
|
|
588
706
|
}
|
|
589
|
-
fields.push({ name: fieldName, components, attributes: attrs, firstParam });
|
|
590
707
|
|
|
591
708
|
const marker = (attrName: string, current: number | null, requires: string) => {
|
|
592
709
|
if (attr(attrs, attrName) === undefined) return current;
|
|
@@ -634,10 +751,16 @@ function buildSchema(
|
|
|
634
751
|
struct: structName,
|
|
635
752
|
doc: docAttr ? String(docAttr.arguments?.[0] ?? "") : null,
|
|
636
753
|
backdrop,
|
|
754
|
+
content: attr(structAttrs, "SkContent") !== undefined,
|
|
755
|
+
history: attr(structAttrs, "SkHistory") !== undefined,
|
|
637
756
|
params,
|
|
638
757
|
backdropRadiusParam,
|
|
639
758
|
bleedParam,
|
|
640
759
|
animatedParam,
|
|
760
|
+
pointerParam,
|
|
761
|
+
pointerTimesParam,
|
|
762
|
+
clockSlots,
|
|
763
|
+
clockWindow,
|
|
641
764
|
signature,
|
|
642
765
|
},
|
|
643
766
|
fields,
|
|
@@ -862,6 +985,8 @@ export function effectFiles(
|
|
|
862
985
|
struct: c.effect.struct,
|
|
863
986
|
doc: c.effect.doc,
|
|
864
987
|
backdrop: c.effect.backdrop,
|
|
988
|
+
content: c.effect.content,
|
|
989
|
+
history: c.effect.history,
|
|
865
990
|
...Object.fromEntries(c.outputs.map((o) => [o.target, `${stemOf(c.file)}.${o.target}`])),
|
|
866
991
|
source: sourceOf(c.file),
|
|
867
992
|
sourceSha256: c.sourceSha256,
|
|
@@ -870,6 +995,10 @@ export function effectFiles(
|
|
|
870
995
|
backdropRadiusParam: c.effect.backdropRadiusParam,
|
|
871
996
|
bleedParam: c.effect.bleedParam,
|
|
872
997
|
animatedParam: c.effect.animatedParam,
|
|
998
|
+
pointerParam: c.effect.pointerParam,
|
|
999
|
+
pointerTimesParam: c.effect.pointerTimesParam,
|
|
1000
|
+
clockSlots: c.effect.clockSlots,
|
|
1001
|
+
clockWindow: c.effect.clockWindow,
|
|
873
1002
|
params: c.effect.params,
|
|
874
1003
|
bindings: c.reflection,
|
|
875
1004
|
})),
|