@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/prod.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// `sk build` (cli/build-app.ts) packs it into the SKPK payload.
|
|
7
7
|
// dist/window.json the `window` block of sk.config.json
|
|
8
8
|
// dist/assets.json [{ key, path }]: every file imported by URL, packed into the payload under key
|
|
9
|
+
// dist/styles.json { files, tailwind }: the files whose CSS the bundle includes, for sk build's CSS warnings
|
|
9
10
|
//
|
|
10
11
|
// Unlike build.ts: "vue" and "@skathi-native/runtime" alias to src/runtime.ts, inlineTemplate is true (no HMR),
|
|
11
12
|
// styles go to (globalThis.__SK_CSS__ ??= []) ahead of the bundle, no HMR epilogue.
|
|
@@ -19,8 +20,9 @@ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "
|
|
|
19
20
|
|
|
20
21
|
import { asciiOnly, checkAscii, nonAsciiCount } from "./ascii";
|
|
21
22
|
import { AotInputs, aotEngineIdentity } from "./aot-inputs";
|
|
22
|
-
import type { ModuleGraph } from "./check/graph";
|
|
23
|
+
import type { BuildStyles, ModuleGraph } from "./check/graph";
|
|
23
24
|
import { pruneVendorPrefixes } from "./css-prefixes";
|
|
25
|
+
import { SVELTE_SOURCE, compileSvelte } from "./svelte";
|
|
24
26
|
import {
|
|
25
27
|
RUNTIME_DIR,
|
|
26
28
|
RUNTIME_ENTRY,
|
|
@@ -82,6 +84,7 @@ const SK_CONFIG_DIR = appRootOverride ?? (APP_SRC_DIR.endsWith(`${sep}src`) ? di
|
|
|
82
84
|
const SK_CONFIG_PATH = configOverride ?? join(SK_CONFIG_DIR, "sk.config.json");
|
|
83
85
|
const WINDOW_JSON = join(dirname(OUT_FILE), "window.json");
|
|
84
86
|
const ASSETS_JSON = join(dirname(OUT_FILE), "assets.json");
|
|
87
|
+
const STYLES_JSON = join(dirname(OUT_FILE), "styles.json");
|
|
85
88
|
|
|
86
89
|
function readSkConfig(): Record<string, unknown> {
|
|
87
90
|
const path = SK_CONFIG_PATH;
|
|
@@ -166,6 +169,9 @@ for (const [k, v] of Object.entries(APP_DEFINES.defines)) {
|
|
|
166
169
|
} catch {}
|
|
167
170
|
}
|
|
168
171
|
|
|
172
|
+
// As Vite's production build: a package's `production` export (esm-env's DEV is `false`, not a NODE_ENV probe).
|
|
173
|
+
const PROD_CONDITIONS = ["production"];
|
|
174
|
+
|
|
169
175
|
const DEFINES: Record<string, string> = {
|
|
170
176
|
__DEV__: "false",
|
|
171
177
|
"process.env.NODE_ENV": '"production"',
|
|
@@ -233,9 +239,26 @@ const scopeIdOf = (id: string) => Bun.hash(id).toString(16).slice(0, 8);
|
|
|
233
239
|
const PROD_TEMPLATE_COMMENTS = false;
|
|
234
240
|
|
|
235
241
|
const cssById = new Map<string, string>();
|
|
242
|
+
/** Every .css file whose CSS the build includes, @imports too, and index.html when it has a `<style>`. */
|
|
243
|
+
const STYLE_FILES = new Set<string>();
|
|
244
|
+
/** The .vue and .svelte files whose `<style>` the build includes. */
|
|
245
|
+
const STYLED_COMPONENTS = new Set<string>();
|
|
246
|
+
|
|
247
|
+
function noteStyles(seen: Set<string>) {
|
|
248
|
+
for (const file of seen) if (/\.css$/i.test(file)) STYLE_FILES.add(file);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** An index.html `<style>` piece: noted as the page itself. */
|
|
252
|
+
function inlinePage(piece: CssPiece): boolean {
|
|
253
|
+
if (!piece.from.startsWith(`${INDEX_HTML}?`)) return false;
|
|
254
|
+
STYLE_FILES.add(INDEX_HTML);
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
236
257
|
|
|
237
258
|
async function viteCss(text: string, from: string, label: string): Promise<string> {
|
|
238
|
-
|
|
259
|
+
const seen = new Set([resolve(from)]);
|
|
260
|
+
let css = inlineCssImports(text, from, SK_CONFIG_DIR, advise, seen, ASSETS);
|
|
261
|
+
noteStyles(seen);
|
|
239
262
|
if (TW_CONFIG && needsTailwindPass(css)) {
|
|
240
263
|
try {
|
|
241
264
|
css = await generateTailwind(TW_CONFIG, { text: css, from: from.replace(/\?.*$/, "") });
|
|
@@ -318,6 +341,7 @@ async function compileVue(absPath: string, source: string): Promise<{ contents:
|
|
|
318
341
|
}
|
|
319
342
|
code = transformSource(code, absPath, SHAPES) ?? code;
|
|
320
343
|
|
|
344
|
+
STYLED_COMPONENTS.add(absPath);
|
|
321
345
|
const cssChunks: string[] = [];
|
|
322
346
|
for (const style of descriptor.styles) {
|
|
323
347
|
let text = style.content;
|
|
@@ -416,7 +440,7 @@ const AOT_INPUTS = aotInputsDir
|
|
|
416
440
|
})
|
|
417
441
|
: null;
|
|
418
442
|
|
|
419
|
-
/** `--graph`: every .js/.ts/.vue file the build loaded, by absolute path. */
|
|
443
|
+
/** `--graph`: every .js/.ts/.vue/.svelte file the build loaded, by absolute path. */
|
|
420
444
|
const GRAPH_LOADED = new Set<string>();
|
|
421
445
|
const SHAPE_NOTES = new Map<string, number>();
|
|
422
446
|
const SHAPES = {
|
|
@@ -465,6 +489,17 @@ const vuePlugin = {
|
|
|
465
489
|
if (graphOut) GRAPH_LOADED.add(args.path);
|
|
466
490
|
return compileVue(args.path, source);
|
|
467
491
|
});
|
|
492
|
+
build.onLoad({ filter: SVELTE_SOURCE }, async (args: Bun.OnLoadArgs) => {
|
|
493
|
+
const id = toId(args.path);
|
|
494
|
+
if (graphOut) GRAPH_LOADED.add(args.path);
|
|
495
|
+
const source = await Bun.file(args.path).text();
|
|
496
|
+
const out = await compileSvelte(APP_ROOT, args.path, source, { dev: false, filename: id });
|
|
497
|
+
AOT_INPUTS?.svelte(args.path, source, out.js);
|
|
498
|
+
for (const w of out.warnings) advise(w);
|
|
499
|
+
STYLED_COMPONENTS.add(args.path);
|
|
500
|
+
if (out.css) cssById.set(id, await viteCss(out.css, args.path, `${id} <style>`));
|
|
501
|
+
return { contents: transformSource(out.js, args.path, SHAPES) ?? out.js, loader: "js" as const };
|
|
502
|
+
});
|
|
468
503
|
},
|
|
469
504
|
};
|
|
470
505
|
|
|
@@ -522,28 +557,51 @@ async function writeGraph(out: string) {
|
|
|
522
557
|
target: "browser",
|
|
523
558
|
define: DEFINES,
|
|
524
559
|
plugins: [viteShapesPlugin(SHAPES), vuePlugin, entryPlugin],
|
|
560
|
+
conditions: PROD_CONDITIONS,
|
|
525
561
|
minify: minify ? { whitespace: true, identifiers: true, syntax: true } : false,
|
|
526
|
-
sourcemap: "
|
|
562
|
+
sourcemap: "external",
|
|
527
563
|
metafile: true,
|
|
528
564
|
throw: false,
|
|
529
565
|
});
|
|
530
|
-
// Metafile keys are relative, to a base that varies between runs
|
|
531
|
-
// match them against the absolute paths the plugins loaded.
|
|
566
|
+
// Metafile keys and sourcemap sources are relative, to a base that varies between runs
|
|
567
|
+
// ("node_modules/…", "../../C:/…"): match them against the absolute paths the plugins loaded.
|
|
532
568
|
const byName = new Map<string, { key: string; path: string }[]>();
|
|
533
569
|
for (const path of GRAPH_LOADED) {
|
|
534
570
|
const key = resolve(path).split(sep).join("/").toLowerCase();
|
|
535
571
|
const name = key.slice(key.lastIndexOf("/") + 1);
|
|
536
572
|
byName.set(name, [...(byName.get(name) ?? []), { key, path: resolve(path) }]);
|
|
537
573
|
}
|
|
574
|
+
const loadedPaths = (key: string) => {
|
|
575
|
+
const tail = `/${key.replace(/^(?:\.\.\/)+/, "").replace(/^[A-Za-z]:\//, "")}`.toLowerCase();
|
|
576
|
+
return (byName.get(tail.slice(tail.lastIndexOf("/") + 1)) ?? []).filter((l) => l.key.endsWith(tail));
|
|
577
|
+
};
|
|
538
578
|
const modules = new Set<string>();
|
|
539
579
|
for (const output of Object.values(result.metafile?.outputs ?? {})) {
|
|
540
580
|
for (const [key, input] of Object.entries(output.inputs)) {
|
|
541
581
|
if (input.bytesInOutput <= 0) continue;
|
|
542
|
-
const
|
|
543
|
-
for (const loaded of byName.get(tail.slice(tail.lastIndexOf("/") + 1)) ?? [])
|
|
544
|
-
if (loaded.key.endsWith(tail)) modules.add(loaded.path);
|
|
582
|
+
for (const loaded of loadedPaths(key)) modules.add(loaded.path);
|
|
545
583
|
}
|
|
546
584
|
}
|
|
585
|
+
let bundle: ModuleGraph["bundle"];
|
|
586
|
+
const code = result.outputs.find((o) => o.kind === "entry-point");
|
|
587
|
+
const map = result.outputs.find((o) => o.kind === "sourcemap");
|
|
588
|
+
if (result.success && code && map) {
|
|
589
|
+
const raw = JSON.parse(await map.text()) as { sources: string[]; sourcesContent?: string[]; mappings: string };
|
|
590
|
+
const sources = raw.sources.map((key, i) => {
|
|
591
|
+
const [loaded, ...others] = loadedPaths(key);
|
|
592
|
+
if (!loaded || others.length) return null;
|
|
593
|
+
// Positions are the file's own only when the bundler read it as is (not a compiled .vue or .svelte).
|
|
594
|
+
const text = readFileSync(loaded.path, "utf8").replace(/^\uFEFF/, "");
|
|
595
|
+
return raw.sourcesContent?.[i] === text ? loaded.path : null;
|
|
596
|
+
});
|
|
597
|
+
bundle = { code: await code.text(), sources, mappings: raw.mappings };
|
|
598
|
+
}
|
|
599
|
+
for (const piece of LIFTED ? [...LIFTED.headCss, ...LIFTED.bodyCss] : []) {
|
|
600
|
+
if (inlinePage(piece)) continue;
|
|
601
|
+
const seen = new Set([resolve(piece.from)]);
|
|
602
|
+
inlineCssImports(piece.text, piece.from, SK_CONFIG_DIR, () => {}, seen);
|
|
603
|
+
noteStyles(seen);
|
|
604
|
+
}
|
|
547
605
|
const graph: ModuleGraph = {
|
|
548
606
|
schema: "skathi.module-graph",
|
|
549
607
|
version: 1,
|
|
@@ -557,6 +615,9 @@ async function writeGraph(out: string) {
|
|
|
557
615
|
},
|
|
558
616
|
declarations: [...new Bun.Glob("*.d.ts").scanSync({ cwd: RUNTIME_SRC_DIR, absolute: true })],
|
|
559
617
|
modules: [...modules].sort(),
|
|
618
|
+
styles: [...STYLE_FILES].sort(),
|
|
619
|
+
tailwind: TW_CONFIG !== null,
|
|
620
|
+
...(bundle ? { bundle } : {}),
|
|
560
621
|
errors: result.logs
|
|
561
622
|
.filter((log) => log.level === "error")
|
|
562
623
|
.map((log) => ({
|
|
@@ -584,6 +645,7 @@ async function build() {
|
|
|
584
645
|
target: "browser",
|
|
585
646
|
define: DEFINES,
|
|
586
647
|
plugins: [viteShapesPlugin(SHAPES), vuePlugin, entryPlugin],
|
|
648
|
+
conditions: PROD_CONDITIONS,
|
|
587
649
|
minify: minify ? { whitespace: true, identifiers: true, syntax: true } : false,
|
|
588
650
|
sourcemap: "none",
|
|
589
651
|
});
|
|
@@ -619,6 +681,7 @@ async function build() {
|
|
|
619
681
|
const htmlCss = async (pieces: CssPiece[]) => {
|
|
620
682
|
const out: string[] = [];
|
|
621
683
|
for (const p of pieces) {
|
|
684
|
+
inlinePage(p);
|
|
622
685
|
if (declaresUtilities(p.text)) appOwnsUtilities = true;
|
|
623
686
|
out.push(await viteCss(p.text, p.from, toId(p.from)));
|
|
624
687
|
}
|
|
@@ -658,8 +721,13 @@ async function build() {
|
|
|
658
721
|
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
659
722
|
.map(([key, path]) => ({ key, path }));
|
|
660
723
|
writeAtomic(ASSETS_JSON, JSON.stringify(assets, null, 2) + "\n");
|
|
724
|
+
const styles: BuildStyles = {
|
|
725
|
+
files: [...STYLED_COMPONENTS, ...STYLE_FILES].sort(),
|
|
726
|
+
tailwind: TW_CONFIG !== null,
|
|
727
|
+
};
|
|
728
|
+
writeAtomic(STYLES_JSON, JSON.stringify(styles, null, 2) + "\n");
|
|
661
729
|
if (AOT_INPUTS) {
|
|
662
|
-
const pinsPath = join(WS_ROOT, "vendor", "redjs", "pins.txt");
|
|
730
|
+
const pinsPath = join(WS_ROOT, "vendor", "redjs", "redjs", "pins.txt");
|
|
663
731
|
const engine = aotEngineIdentity(existsSync(pinsPath) ? readFileSync(pinsPath, "utf8") : null);
|
|
664
732
|
const manifest = AOT_INPUTS.write({
|
|
665
733
|
script: out,
|
package/svelte.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Svelte 5 components (`.svelte`) and rune modules (`.svelte.ts`, `.svelte.js`), compiled with the app's own
|
|
2
|
+
// `svelte/compiler`: the compiled code calls `svelte/internal/client`, which must be the same version.
|
|
3
|
+
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import type * as SvelteCompiler from "svelte/compiler";
|
|
6
|
+
|
|
7
|
+
type Compiler = typeof SvelteCompiler;
|
|
8
|
+
|
|
9
|
+
/** Files the Svelte compiler owns, components and rune modules both. */
|
|
10
|
+
export const SVELTE_SOURCE = /\.svelte(?:\.[jt]s)?$/;
|
|
11
|
+
const RUNE_MODULE = /\.svelte\.[jt]s$/;
|
|
12
|
+
|
|
13
|
+
const compilers = new Map<string, Promise<Compiler>>();
|
|
14
|
+
|
|
15
|
+
/** `svelte/compiler` as the app at `appRoot` resolves it. */
|
|
16
|
+
export function svelteCompiler(appRoot: string): Promise<Compiler> {
|
|
17
|
+
let compiler = compilers.get(appRoot);
|
|
18
|
+
if (!compiler) {
|
|
19
|
+
compiler = (async () => {
|
|
20
|
+
let path: string;
|
|
21
|
+
try {
|
|
22
|
+
path = Bun.resolveSync("svelte/compiler", appRoot);
|
|
23
|
+
} catch {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`${appRoot}: a .svelte file needs Svelte 5 installed in the app: add "svelte" to its dependencies`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
const mod = (await import(pathToFileURL(path).href)) as Compiler;
|
|
29
|
+
if (!/^5\./.test(mod.VERSION)) {
|
|
30
|
+
throw new Error(`${appRoot}: svelte ${mod.VERSION} is installed; Skathi compiles Svelte 5 components`);
|
|
31
|
+
}
|
|
32
|
+
return mod;
|
|
33
|
+
})();
|
|
34
|
+
compilers.set(appRoot, compiler);
|
|
35
|
+
}
|
|
36
|
+
return compiler;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface SvelteOutput {
|
|
40
|
+
js: string;
|
|
41
|
+
css: string | null;
|
|
42
|
+
warnings: string[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const stripTypes = new Bun.Transpiler({ loader: "ts", trimUnusedImports: false });
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Compiles one Svelte source. `filename` names it in dev diagnostics and seeds the scoped-CSS hash, so it is the
|
|
49
|
+
* module id, stable across machines. `dev` adds Svelte's runtime checks and the `import.meta.hot` epilogue.
|
|
50
|
+
*/
|
|
51
|
+
export async function compileSvelte(
|
|
52
|
+
appRoot: string,
|
|
53
|
+
absPath: string,
|
|
54
|
+
source: string,
|
|
55
|
+
o: { dev: boolean; filename: string },
|
|
56
|
+
): Promise<SvelteOutput> {
|
|
57
|
+
const svelte = await svelteCompiler(appRoot);
|
|
58
|
+
const describe = (w: SvelteCompiler.Warning) =>
|
|
59
|
+
`${o.filename}${w.start ? `:${w.start.line}:${w.start.column + 1}` : ""}: ${w.message.split("\n")[0]} (${w.code})`;
|
|
60
|
+
if (RUNE_MODULE.test(absPath)) {
|
|
61
|
+
const js = absPath.endsWith(".ts") ? stripTypes.transformSync(source) : source;
|
|
62
|
+
const out = svelte.compileModule(js, { filename: o.filename, generate: "client", dev: o.dev });
|
|
63
|
+
return { js: out.js.code, css: null, warnings: out.warnings.map(describe) };
|
|
64
|
+
}
|
|
65
|
+
const out = svelte.compile(source, {
|
|
66
|
+
filename: o.filename,
|
|
67
|
+
generate: "client",
|
|
68
|
+
dev: o.dev,
|
|
69
|
+
hmr: o.dev,
|
|
70
|
+
// The builders route component CSS into the app stylesheet, as they do an SFC's <style>.
|
|
71
|
+
css: "external",
|
|
72
|
+
// svelte-dom-shim: fragments: "tree" builds templates with createElement, since Skathi's DOM has no HTML parser for the default <template> innerHTML; goes with the custom renderer (sveltejs/svelte#18042)
|
|
73
|
+
fragments: "tree",
|
|
74
|
+
});
|
|
75
|
+
return { js: out.js.code, css: out.css?.code ?? null, warnings: out.warnings.map(describe) };
|
|
76
|
+
}
|
package/templates/icon.png
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import sk;
|
|
2
|
+
|
|
3
|
+
// Burns the element away: its own painting is eaten by noise from the ragged edge inwards, with a
|
|
4
|
+
// glowing ember rim. `progress` is a plain number, so a CSS transition on `--shading` plays the burn.
|
|
5
|
+
[SkEffect("dissolve")]
|
|
6
|
+
[SkDoc("burns the element's own painting away behind an ember edge")]
|
|
7
|
+
[SkContent]
|
|
8
|
+
struct Dissolve : IEffect
|
|
9
|
+
{
|
|
10
|
+
// 0 is the element untouched, 1 is all of it gone.
|
|
11
|
+
[SkDefault("0")] [SkRange(0.0, 1.0)]
|
|
12
|
+
float progress;
|
|
13
|
+
|
|
14
|
+
// The size of the burnt patches.
|
|
15
|
+
[SkLength] [SkDefault("46")] [SkRange(4.0, 1024.0)]
|
|
16
|
+
float grain;
|
|
17
|
+
|
|
18
|
+
[SkColor] [SkOptional] [SkDefault("#ff7a1a")]
|
|
19
|
+
float4 ember;
|
|
20
|
+
|
|
21
|
+
float4 shade(EffectInput input)
|
|
22
|
+
{
|
|
23
|
+
// Mostly noise, a little of the distance from the top left, so the burn sweeps across.
|
|
24
|
+
float n = sk_fbm(input.px / max(grain, 1.0)) * 0.75 + dot(input.local, float2(0.15, 0.1));
|
|
25
|
+
float edge = progress * 1.12 - 0.06;
|
|
26
|
+
float burnt = n - edge;
|
|
27
|
+
float width = 0.05;
|
|
28
|
+
|
|
29
|
+
float4 content = input.contentAtPx(input.px + float2(0.0, -6.0 * input.scale * saturate(1.0 - burnt / width)));
|
|
30
|
+
float alive = smoothstep(0.0, 0.012, burnt);
|
|
31
|
+
float rim = alive * (1.0 - smoothstep(0.0, width, burnt));
|
|
32
|
+
|
|
33
|
+
// The rim chars the content to black, then glows through it.
|
|
34
|
+
float3 rgb = lerp(content.rgb, float3(0.0, 0.0, 0.0), rim * 0.8 * content.a);
|
|
35
|
+
float flicker = 0.6 + 0.4 * sk_value_noise(input.px / (6.0 * input.scale) + input.time * 3.0);
|
|
36
|
+
float glow = rim * rim * flicker * content.a;
|
|
37
|
+
float4 shaded = float4(rgb, content.a) * alive;
|
|
38
|
+
return sk_over(shaded, float4(ember.rgb, 1.0) * glow * ember.a);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import sk;
|
|
2
|
+
|
|
3
|
+
// Fireflies wandering over the element on paths made of incommensurate sines, so no two repeat,
|
|
4
|
+
// each blinking on its own rhythm. With `lure` above 0 the ones near the pointer gather round it while
|
|
5
|
+
// it is in the window.
|
|
6
|
+
[SkEffect("fireflies")]
|
|
7
|
+
[SkDoc("glowing fireflies drifting about, drawn to the pointer")]
|
|
8
|
+
struct Fireflies : IEffect
|
|
9
|
+
{
|
|
10
|
+
[SkAnimated] [SkDefault("1")] [SkRange(0.0, 4.0)]
|
|
11
|
+
float speed;
|
|
12
|
+
|
|
13
|
+
// The glow's radius.
|
|
14
|
+
[SkLength] [SkDefault("16")] [SkRange(2.0, 128.0)]
|
|
15
|
+
float glow;
|
|
16
|
+
|
|
17
|
+
// 0 ignores the pointer; 1 gathers the nearby fireflies round it.
|
|
18
|
+
[SkDefault("0")] [SkRange(0.0, 1.0)]
|
|
19
|
+
float lure;
|
|
20
|
+
|
|
21
|
+
[SkPointer]
|
|
22
|
+
float2 at;
|
|
23
|
+
|
|
24
|
+
[SkPointerTimes]
|
|
25
|
+
float3 seen;
|
|
26
|
+
|
|
27
|
+
float4 shade(EffectInput input)
|
|
28
|
+
{
|
|
29
|
+
float t = input.time * speed;
|
|
30
|
+
float reach = max(glow, 1.0);
|
|
31
|
+
float aspect = input.size.x / max(input.size.y, 1.0);
|
|
32
|
+
float near = sk_pointer_presence(seen, input.time, 0.5);
|
|
33
|
+
float3 light = float3(0.0, 0.0, 0.0);
|
|
34
|
+
for (int i = 0; i < 28; i++)
|
|
35
|
+
{
|
|
36
|
+
float2 h = sk_hash22(float2(i, 3.7));
|
|
37
|
+
float2 k = sk_hash22(float2(i, 9.1));
|
|
38
|
+
float2 wander = 0.5 + float2(
|
|
39
|
+
0.30 * sin(t * (0.07 + 0.09 * h.x) + 6.28 * h.y) + 0.17 * sin(t * (0.19 + 0.13 * k.x) + 6.28 * k.y),
|
|
40
|
+
0.28 * sin(t * (0.05 + 0.08 * k.y) + 6.28 * k.x) + 0.18 * sin(t * (0.23 + 0.11 * h.y) + 6.28 * h.x));
|
|
41
|
+
|
|
42
|
+
// Drawn in by distance in the element's own proportions, then kept circling the pointer.
|
|
43
|
+
float2 toward = (at - wander) * float2(aspect, 1.0);
|
|
44
|
+
float pull = lure * near * exp(-dot(toward, toward) / 0.35);
|
|
45
|
+
float2 circle = float2(cos(t * (0.6 + h.x) + 6.28 * k.x) / aspect, sin(t * (0.6 + h.x) + 6.28 * k.x));
|
|
46
|
+
float2 spot = lerp(wander, at + circle * (0.04 + 0.06 * k.y), pull) * input.size;
|
|
47
|
+
|
|
48
|
+
float2 d = input.px - spot;
|
|
49
|
+
float r2 = dot(d, d) / (reach * reach);
|
|
50
|
+
float blink = 0.15 + 0.85 * pow(saturate(sin(t * (0.7 + 1.1 * h.y) + 6.28 * k.x)), 3.0);
|
|
51
|
+
float shine = (exp(-r2 * 24.0) + 0.35 * exp(-r2 * 2.0)) * blink;
|
|
52
|
+
float3 tint = lerp(float3(0.75, 1.0, 0.35), float3(1.0, 0.78, 0.3), k.x);
|
|
53
|
+
light += tint * shine;
|
|
54
|
+
}
|
|
55
|
+
float strength = max(light.r, max(light.g, light.b));
|
|
56
|
+
return float4(light, saturate(strength));
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import sk;
|
|
2
|
+
|
|
3
|
+
// Patterned glass. A tiling normal map bends the backdrop pixel by pixel and catches a little light,
|
|
4
|
+
// one texel of the map per `scale` pixels.
|
|
5
|
+
[SkEffect("glass")]
|
|
6
|
+
[SkDoc("textured glass: a repeating normal map refracts what is behind")]
|
|
7
|
+
[SkBackdrop]
|
|
8
|
+
struct Glass : IEffect
|
|
9
|
+
{
|
|
10
|
+
[SkLinear] [SkDefault("#8080ffff")]
|
|
11
|
+
SkTexture normals;
|
|
12
|
+
|
|
13
|
+
[SkLength] [SkDefault("10")] [SkRange(0.0, 64.0)]
|
|
14
|
+
float depth;
|
|
15
|
+
|
|
16
|
+
[SkDefault("1")] [SkRange(0.25, 8.0)]
|
|
17
|
+
float scale;
|
|
18
|
+
|
|
19
|
+
[SkColor] [SkOptional] [SkDefault("#ffffff10")]
|
|
20
|
+
float4 tint;
|
|
21
|
+
|
|
22
|
+
float4 shade(EffectInput input)
|
|
23
|
+
{
|
|
24
|
+
float2 tile = max(normals.size, float2(1.0, 1.0)) * scale;
|
|
25
|
+
float3 n = normals.sampleRepeat(input.px / tile).xyz * 2.0 - 1.0;
|
|
26
|
+
float4 seen = input.backdropAtPx(input.px + n.xy * depth);
|
|
27
|
+
float light = 0.2 * pow(saturate(dot(normalize(n), normalize(float3(-0.4, -0.6, 0.7)))), 12.0);
|
|
28
|
+
float4 glass = sk_over(seen, sk_premultiply(tint));
|
|
29
|
+
return float4(glass.rgb + light, saturate(glass.a + light * (1.0 - glass.a)));
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import sk;
|
|
2
|
+
|
|
3
|
+
// A colour grade through a 3D lookup table: 16 slices of 16x16 side by side, red across a slice,
|
|
4
|
+
// green down it, blue from slice to slice. Until the image arrives it shows the backdrop as it is.
|
|
5
|
+
[SkEffect("grade")]
|
|
6
|
+
[SkDoc("re-colours the backdrop through a 16x16x16 LUT image")]
|
|
7
|
+
[SkBackdrop]
|
|
8
|
+
struct Grade : IEffect
|
|
9
|
+
{
|
|
10
|
+
[SkLinear]
|
|
11
|
+
SkTexture lut;
|
|
12
|
+
|
|
13
|
+
[SkDefault("1")] [SkRange(0.0, 1.0)]
|
|
14
|
+
float amount;
|
|
15
|
+
|
|
16
|
+
float3 lookup(float3 c)
|
|
17
|
+
{
|
|
18
|
+
float blue = c.b * 15.0;
|
|
19
|
+
float slice = floor(blue);
|
|
20
|
+
float2 cell = float2(c.r * 15.0 + 0.5, c.g * 15.0 + 0.5);
|
|
21
|
+
float3 lo = lut.sample((cell + float2(slice * 16.0, 0.0)) / lut.size).rgb;
|
|
22
|
+
float3 hi = lut.sample((cell + float2(min(slice + 1.0, 15.0) * 16.0, 0.0)) / lut.size).rgb;
|
|
23
|
+
return lerp(lo, hi, blue - slice);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
float4 shade(EffectInput input)
|
|
27
|
+
{
|
|
28
|
+
float4 seen = input.backdrop;
|
|
29
|
+
if (!lut.loaded())
|
|
30
|
+
return seen;
|
|
31
|
+
float3 rgb = saturate(seen.rgb / max(seen.a, 1e-4));
|
|
32
|
+
return float4(lerp(rgb, lookup(rgb), amount) * seen.a, seen.a);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import sk;
|
|
2
|
+
|
|
3
|
+
// A print-style halftone of whatever is behind the element: an image, a video, the page. Every pixel
|
|
4
|
+
// of a cell reads the backdrop at the cell's centre, so a cell is one dot of one colour, sized by how
|
|
5
|
+
// bright that spot is.
|
|
6
|
+
[SkEffect("halftone")]
|
|
7
|
+
[SkDoc("re-screens the backdrop as rotated halftone dots")]
|
|
8
|
+
[SkBackdrop]
|
|
9
|
+
struct Halftone : IEffect
|
|
10
|
+
{
|
|
11
|
+
[SkLength] [SkDefault("9")] [SkRange(3.0, 64.0)]
|
|
12
|
+
float cell;
|
|
13
|
+
|
|
14
|
+
// Screen angle in turns: 0.125 is the classic 45 degrees.
|
|
15
|
+
[SkDefault("0.125")] [SkRange(-1.0, 1.0)]
|
|
16
|
+
float angle;
|
|
17
|
+
|
|
18
|
+
// How much colour the dots keep: 0 prints them in `paper`'s complement, 1 in the backdrop's own.
|
|
19
|
+
[SkDefault("1")] [SkRange(0.0, 1.0)]
|
|
20
|
+
float colour;
|
|
21
|
+
|
|
22
|
+
[SkColor] [SkOptional] [SkDefault("#0b0b12")]
|
|
23
|
+
float4 paper;
|
|
24
|
+
|
|
25
|
+
float4 shade(EffectInput input)
|
|
26
|
+
{
|
|
27
|
+
float turn = angle * 6.28318530718;
|
|
28
|
+
float2 q = sk_rotate(input.px, -turn) / cell;
|
|
29
|
+
float2 centre = floor(q) + 0.5;
|
|
30
|
+
|
|
31
|
+
// Back to element pixels, kept inside the element so the edge cells read its own backdrop.
|
|
32
|
+
float2 at = clamp(sk_rotate(centre * cell, turn), float2(0.0, 0.0), input.size);
|
|
33
|
+
float4 seen = input.backdropAtPx(at);
|
|
34
|
+
|
|
35
|
+
float3 rgb = seen.rgb / max(seen.a, 1e-4);
|
|
36
|
+
float ink = sqrt(saturate(sk_luma(rgb) * 1.15)) * 0.5 * cell;
|
|
37
|
+
float disc = input.aa(length(q - centre) * cell - ink);
|
|
38
|
+
|
|
39
|
+
float3 tone = lerp(1.0 - paper.rgb, saturate(rgb * 1.2), colour);
|
|
40
|
+
return float4(lerp(paper.rgb, tone, disc), 1.0);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import sk;
|
|
2
|
+
|
|
3
|
+
// Liquid glass. It reads the backdrop at displaced coordinates rather than under the pixel: the
|
|
4
|
+
// middle magnifies a little, and the curved rim gathers in what lies just outside the element, each
|
|
5
|
+
// colour channel from a slightly different place.
|
|
6
|
+
[SkEffect("lens")]
|
|
7
|
+
[SkDoc("liquid glass: refraction, dispersion and a specular rim over whatever is behind")]
|
|
8
|
+
[SkBackdrop]
|
|
9
|
+
struct Lens : IEffect
|
|
10
|
+
{
|
|
11
|
+
// How far past the edge the rim reaches for what it shows.
|
|
12
|
+
[SkLength] [SkDefault("18")] [SkRange(0.0, 96.0)]
|
|
13
|
+
float depth;
|
|
14
|
+
|
|
15
|
+
// The width of the curved rim; inside it the glass is flat.
|
|
16
|
+
[SkLength] [SkDefault("24")] [SkRange(1.0, 256.0)]
|
|
17
|
+
float bevel;
|
|
18
|
+
|
|
19
|
+
// How far apart red and blue refract, as a fraction of the bend.
|
|
20
|
+
[SkDefault("0.12")] [SkRange(0.0, 1.0)]
|
|
21
|
+
float dispersion;
|
|
22
|
+
|
|
23
|
+
[SkColor] [SkOptional] [SkDefault("#ffffff0f")]
|
|
24
|
+
float4 tint;
|
|
25
|
+
|
|
26
|
+
float4 shade(EffectInput input)
|
|
27
|
+
{
|
|
28
|
+
// `sd` is a distance field, so its screen-space gradient is the outward normal of the rim.
|
|
29
|
+
float2 gradient = float2(ddx(input.sd), ddy(input.sd));
|
|
30
|
+
float2 normal = gradient / max(length(gradient), 1e-4);
|
|
31
|
+
|
|
32
|
+
float edge = 1.0 - saturate(-input.sd / max(bevel, 1.0));
|
|
33
|
+
float curve = edge * edge;
|
|
34
|
+
|
|
35
|
+
float2 magnify = (input.size * 0.5 - input.px) * 0.07;
|
|
36
|
+
float2 shift = normal * depth * curve + magnify;
|
|
37
|
+
float r = input.backdropAtPx(input.px + shift * (1.0 + dispersion)).r;
|
|
38
|
+
float4 g = input.backdropAtPx(input.px + shift);
|
|
39
|
+
float b = input.backdropAtPx(input.px + shift * (1.0 - dispersion)).b;
|
|
40
|
+
float4 glass = sk_over(float4(r, g.g, b, g.a), sk_premultiply(tint));
|
|
41
|
+
|
|
42
|
+
// A key light from the top left catches that rim, a weaker internal reflection the opposite one.
|
|
43
|
+
float facing = dot(normal, float2(-0.6, -0.8));
|
|
44
|
+
float rim = pow(edge, 5.0);
|
|
45
|
+
float specular = rim * (0.5 * saturate(facing) + 0.16 * saturate(-facing));
|
|
46
|
+
float sheen = 0.05 * saturate(1.0 - input.local.y * 1.6) * (1.0 - edge);
|
|
47
|
+
|
|
48
|
+
float light = specular + sheen;
|
|
49
|
+
return float4(glass.rgb + light, saturate(glass.a + light * (1.0 - glass.a)));
|
|
50
|
+
}
|
|
51
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import sk;
|
|
2
|
+
|
|
3
|
+
// Domain warping: noise sampled at coordinates bent by more noise, twice over, so the field folds into
|
|
4
|
+
// gas-like filaments. It paints the whole element; `hue` is a plain number, so a CSS transition on
|
|
5
|
+
// `--shading` cross-fades the palette while the gas keeps moving.
|
|
6
|
+
[SkEffect("nebula")]
|
|
7
|
+
[SkDoc("drifting domain-warped gas with twinkling stars")]
|
|
8
|
+
struct Nebula : IEffect
|
|
9
|
+
{
|
|
10
|
+
[SkAnimated] [SkDefault("0.12")] [SkRange(0.0, 2.0)]
|
|
11
|
+
float speed;
|
|
12
|
+
|
|
13
|
+
// Features per shorter side of the element.
|
|
14
|
+
[SkDefault("2.2")] [SkRange(0.2, 12.0)]
|
|
15
|
+
float scale;
|
|
16
|
+
|
|
17
|
+
// Shifts the palette around the colour wheel, 0..1.
|
|
18
|
+
[SkDefault("0")] [SkRange(-4.0, 4.0)]
|
|
19
|
+
float hue;
|
|
20
|
+
|
|
21
|
+
// The brightest filaments and the stars.
|
|
22
|
+
[SkColor] [SkOptional] [SkDefault("#ffe6c7")]
|
|
23
|
+
float4 glow;
|
|
24
|
+
|
|
25
|
+
float4 shade(EffectInput input)
|
|
26
|
+
{
|
|
27
|
+
float t = input.time * speed;
|
|
28
|
+
float2 p = input.centered() * scale;
|
|
29
|
+
|
|
30
|
+
float2 q = float2(sk_fbm(p + float2(0.0, t)), sk_fbm(p + float2(5.2, 1.3) - t * 0.7));
|
|
31
|
+
float2 r = float2(
|
|
32
|
+
sk_fbm(p + 2.8 * q + float2(1.7, 9.2) + t * 1.3),
|
|
33
|
+
sk_fbm(p + 2.8 * q + float2(8.3, 2.8) - t * 0.9));
|
|
34
|
+
float f = sk_fbm(p + 2.8 * r);
|
|
35
|
+
|
|
36
|
+
float3 rgb = sk_palette(
|
|
37
|
+
f + length(q) * 0.35 + hue,
|
|
38
|
+
float3(0.42, 0.30, 0.52),
|
|
39
|
+
float3(0.42, 0.30, 0.40),
|
|
40
|
+
float3(1.0, 1.0, 1.0),
|
|
41
|
+
float3(0.62, 0.78, 0.95));
|
|
42
|
+
float density = smoothstep(0.25, 0.95, f * f * 1.6 + r.x * 0.45);
|
|
43
|
+
rgb *= 0.18 + 0.95 * density;
|
|
44
|
+
rgb = lerp(rgb, glow.rgb, pow(saturate(f * 1.25 - 0.35), 3.0) * glow.a);
|
|
45
|
+
|
|
46
|
+
// A sparse star field on a lattice in logical pixels, so the stars keep their size on any display.
|
|
47
|
+
float lattice = 7.0 * input.scale;
|
|
48
|
+
float2 cell = floor(input.px / lattice);
|
|
49
|
+
float2 spot = (cell + 0.2 + 0.6 * sk_hash22(cell + 11.0)) * lattice;
|
|
50
|
+
float size = (0.5 + 0.9 * sk_hash12(cell + 5.0)) * input.scale;
|
|
51
|
+
float star = step(0.975, sk_hash12(cell)) * input.aa(length(input.px - spot) - size);
|
|
52
|
+
float twinkle = 0.5 + 0.5 * sin(input.time * (1.5 + 3.0 * sk_hash12(cell + 7.0)) + 40.0 * sk_hash12(cell + 3.0));
|
|
53
|
+
rgb += glow.rgb * star * twinkle * (1.0 - density * 0.5);
|
|
54
|
+
|
|
55
|
+
return float4(rgb, 1.0);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import sk;
|
|
2
|
+
|
|
3
|
+
// Two comets chasing each other around the element's rounded border. `halo` is the `[SkBleed]`
|
|
4
|
+
// parameter: the drawn quad grows by it, so the light spills past the border box instead of being cut
|
|
5
|
+
// off at it.
|
|
6
|
+
[SkEffect("orbit")]
|
|
7
|
+
[SkDoc("light running around the border, glowing past it")]
|
|
8
|
+
struct Orbit : IEffect
|
|
9
|
+
{
|
|
10
|
+
// Laps per second.
|
|
11
|
+
[SkAnimated] [SkDefault("0.35")] [SkRange(0.0, 4.0)]
|
|
12
|
+
float speed;
|
|
13
|
+
|
|
14
|
+
[SkLength] [SkDefault("2")] [SkRange(0.5, 16.0)]
|
|
15
|
+
float width;
|
|
16
|
+
|
|
17
|
+
[SkLength] [SkBleed] [SkDefault("18")] [SkRange(0.0, 96.0)]
|
|
18
|
+
float halo;
|
|
19
|
+
|
|
20
|
+
// How much of the lap the tail covers, 0..1.
|
|
21
|
+
[SkDefault("0.35")] [SkRange(0.02, 1.0)]
|
|
22
|
+
float tail;
|
|
23
|
+
|
|
24
|
+
[SkColor] [SkDefault("#7fd4ff")]
|
|
25
|
+
float4 color;
|
|
26
|
+
|
|
27
|
+
static override bool straightAlpha() { return true; }
|
|
28
|
+
|
|
29
|
+
// A long tail behind the head and a short soft front, so no edge of the light is a hard cut.
|
|
30
|
+
float comet(float around, float head)
|
|
31
|
+
{
|
|
32
|
+
float ahead = frac(around - head + 0.5) - 0.5;
|
|
33
|
+
float front = ahead / 0.02;
|
|
34
|
+
return ahead > 0.0 ? exp(-front * front) : pow(saturate(1.0 + ahead / tail), 3.0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
float4 shade(EffectInput input)
|
|
38
|
+
{
|
|
39
|
+
float2 c = input.local * 2.0 - 1.0;
|
|
40
|
+
float around = atan2(c.y, c.x) / 6.28318530718 + 0.5;
|
|
41
|
+
float head = frac(input.time * speed);
|
|
42
|
+
float light = comet(around, head) + 0.65 * comet(around, head + 0.5);
|
|
43
|
+
|
|
44
|
+
float stroke = input.aa(abs(input.sd + width * 0.5) - width * 0.5);
|
|
45
|
+
float outside = max(input.sd, 0.0) / max(halo, 1.0);
|
|
46
|
+
float glow = exp(-outside * 4.0) * (input.sd > 0.0 ? 1.0 : saturate(1.0 + input.sd / (width * 4.0)));
|
|
47
|
+
|
|
48
|
+
float alpha = stroke * (0.14 + 0.86 * light) + glow * light * 0.55;
|
|
49
|
+
float3 rgb = lerp(color.rgb, float3(1.0, 1.0, 1.0), stroke * light * light * 0.6);
|
|
50
|
+
return float4(rgb, saturate(alpha * color.a));
|
|
51
|
+
}
|
|
52
|
+
};
|