@skathi-native/cli 0.1.0-beta.3 → 0.2.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.
Files changed (68) hide show
  1. package/aot-inputs.ts +21 -2
  2. package/build.ts +241 -60
  3. package/check/bundle.ts +265 -0
  4. package/check/codes.ts +19 -0
  5. package/check/command.ts +5 -3
  6. package/check/graph.ts +3 -1
  7. package/check/index.ts +54 -2
  8. package/check/program.ts +26 -6
  9. package/cli/aot-build.ts +10 -7
  10. package/cli/build-app.ts +37 -8
  11. package/cli/config.ts +2 -2
  12. package/cli/create.ts +31 -8
  13. package/cli/dev.ts +109 -19
  14. package/cli/effects.ts +162 -0
  15. package/cli/elf.ts +3 -2
  16. package/cli/help.ts +56 -147
  17. package/cli/host-fetch.ts +33 -10
  18. package/cli/host.ts +43 -33
  19. package/cli/sk.ts +437 -234
  20. package/cli/skpk.ts +2 -0
  21. package/cli/stamp.ts +2 -2
  22. package/cli/term.ts +169 -38
  23. package/cli/workload-cache.ts +258 -0
  24. package/devtools/commands.ts +25 -0
  25. package/effects/compile.ts +1081 -0
  26. package/effects/redslangc.json +23 -0
  27. package/effects/redslangc.ts +220 -0
  28. package/effects/sk.slang +882 -0
  29. package/package.json +10 -4
  30. package/prod.ts +40 -7
  31. package/svelte.ts +76 -0
  32. package/templates/icon.png +0 -0
  33. package/templates/minimal/src/App.vue +2 -2
  34. package/templates/showcase/assets/textures/golden.png +0 -0
  35. package/templates/showcase/assets/textures/hammered.png +0 -0
  36. package/templates/showcase/assets/textures/noir.png +0 -0
  37. package/templates/showcase/assets/textures/reeded.png +0 -0
  38. package/templates/showcase/assets/textures/teal-orange.png +0 -0
  39. package/templates/showcase/shaders/dissolve.slang +40 -0
  40. package/templates/showcase/shaders/fireflies.slang +58 -0
  41. package/templates/showcase/shaders/glass.slang +31 -0
  42. package/templates/showcase/shaders/grade.slang +34 -0
  43. package/templates/showcase/shaders/halftone.slang +42 -0
  44. package/templates/showcase/shaders/lens.slang +51 -0
  45. package/templates/showcase/shaders/nebula.slang +57 -0
  46. package/templates/showcase/shaders/orbit.slang +52 -0
  47. package/templates/showcase/shaders/pond.slang +76 -0
  48. package/templates/showcase/shaders/ripples.slang +71 -0
  49. package/templates/showcase/shaders/shatter.slang +116 -0
  50. package/templates/showcase/shaders/sheen.slang +23 -0
  51. package/templates/showcase/shaders/snow.slang +57 -0
  52. package/templates/showcase/shaders/spotlight.slang +52 -0
  53. package/templates/showcase/src/App.vue +11 -16
  54. package/templates/showcase/src/components/FullWindow.vue +77 -0
  55. package/templates/showcase/src/components/Page.vue +2 -0
  56. package/templates/showcase/src/fullwindow.ts +36 -0
  57. package/templates/showcase/src/icons.ts +2 -0
  58. package/templates/showcase/src/pages/GraphicsPage.vue +122 -0
  59. package/templates/showcase/src/pages/MotionPage.vue +71 -1
  60. package/templates/showcase/src/pages/ShadersPage.vue +443 -0
  61. package/templates/showcase/src/pages/StylesPage.vue +9 -1
  62. package/templates/showcase/src/router.ts +32 -1
  63. package/templates/showcase/src/styles.css +2 -2
  64. package/templates/svelte/.vscode/settings.json +3 -0
  65. package/templates/svelte/assets/hello.txt +1 -0
  66. package/templates/svelte/src/App.svelte +142 -0
  67. package/templates/svelte/src/main.ts +4 -0
  68. package/vitecompat.ts +2 -0
package/package.json CHANGED
@@ -6,12 +6,13 @@
6
6
  "url": "git+https://github.com/argon-chat/skathi.git",
7
7
  "directory": "packages/cli"
8
8
  },
9
- "version": "0.1.0-beta.3",
9
+ "version": "0.2.0",
10
10
  "type": "module",
11
11
  "files": [
12
12
  "aot",
13
13
  "cli",
14
14
  "check",
15
+ "effects",
15
16
  "templates",
16
17
  "devtools/apps.ts",
17
18
  "devtools/commands.ts",
@@ -22,6 +23,7 @@
22
23
  "css-prefixes.ts",
23
24
  "prod.ts",
24
25
  "runtime-path.ts",
26
+ "svelte.ts",
25
27
  "tailwind.ts",
26
28
  "vitecompat.ts"
27
29
  ],
@@ -31,14 +33,17 @@
31
33
  },
32
34
  "dependencies": {
33
35
  "@clack/prompts": "^1.9.0",
34
- "@skathi-native/runtime": "0.1.0-beta.3",
36
+ "@commander-js/extra-typings": "~15.1.0",
37
+ "@skathi-native/runtime": "0.2.0",
35
38
  "@vue/compiler-sfc": "^3.5.41",
39
+ "commander": "~15.1.0",
36
40
  "postcss": "^8.4.31",
37
41
  "tailwindcss": "3.4",
38
42
  "typescript": "5"
39
43
  },
40
44
  "devDependencies": {
41
- "@modelcontextprotocol/sdk": "^1.30.0"
45
+ "@modelcontextprotocol/sdk": "^1.30.0",
46
+ "svelte": "5.57.3"
42
47
  },
43
48
  "engines": {
44
49
  "bun": ">=1.4"
@@ -54,7 +59,8 @@
54
59
  "comments": {
55
60
  "tailwindcss": "Pinned to 3.4.x: v3 emits literal declarations that crates/sk-css maps onto gpui; v4 uses var(--tw-*) + calc() + @property, which the engine does not fully resolve yet (see tailwind.ts).",
56
61
  "@modelcontextprotocol/sdk": "devDependency: used only by devtools/mcp.ts. devtools/ctl.ts is dependency-free so an agent can drive the app through Bash without bun install.",
57
- "typescript": "sk check and the AOT input inventory (sk build --aot-inputs). Builds do not invoke tsc: bun transpiles .ts directly."
62
+ "typescript": "sk check and the AOT input inventory (sk build --aot-inputs). Builds do not invoke tsc: bun transpiles .ts directly.",
63
+ "svelte": "devDependency: types and tests. A Svelte app compiles with its own svelte/compiler, the version its runtime is."
58
64
  },
59
65
  "publishConfig": {
60
66
  "access": "public"
package/prod.ts CHANGED
@@ -21,6 +21,7 @@ import { asciiOnly, checkAscii, nonAsciiCount } from "./ascii";
21
21
  import { AotInputs, aotEngineIdentity } from "./aot-inputs";
22
22
  import type { ModuleGraph } from "./check/graph";
23
23
  import { pruneVendorPrefixes } from "./css-prefixes";
24
+ import { SVELTE_SOURCE, compileSvelte } from "./svelte";
24
25
  import {
25
26
  RUNTIME_DIR,
26
27
  RUNTIME_ENTRY,
@@ -166,6 +167,9 @@ for (const [k, v] of Object.entries(APP_DEFINES.defines)) {
166
167
  } catch {}
167
168
  }
168
169
 
170
+ // As Vite's production build: a package's `production` export (esm-env's DEV is `false`, not a NODE_ENV probe).
171
+ const PROD_CONDITIONS = ["production"];
172
+
169
173
  const DEFINES: Record<string, string> = {
170
174
  __DEV__: "false",
171
175
  "process.env.NODE_ENV": '"production"',
@@ -416,7 +420,7 @@ const AOT_INPUTS = aotInputsDir
416
420
  })
417
421
  : null;
418
422
 
419
- /** `--graph`: every .js/.ts/.vue file the build loaded, by absolute path. */
423
+ /** `--graph`: every .js/.ts/.vue/.svelte file the build loaded, by absolute path. */
420
424
  const GRAPH_LOADED = new Set<string>();
421
425
  const SHAPE_NOTES = new Map<string, number>();
422
426
  const SHAPES = {
@@ -465,6 +469,16 @@ const vuePlugin = {
465
469
  if (graphOut) GRAPH_LOADED.add(args.path);
466
470
  return compileVue(args.path, source);
467
471
  });
472
+ build.onLoad({ filter: SVELTE_SOURCE }, async (args: Bun.OnLoadArgs) => {
473
+ const id = toId(args.path);
474
+ if (graphOut) GRAPH_LOADED.add(args.path);
475
+ const source = await Bun.file(args.path).text();
476
+ const out = await compileSvelte(APP_ROOT, args.path, source, { dev: false, filename: id });
477
+ AOT_INPUTS?.svelte(args.path, source, out.js);
478
+ for (const w of out.warnings) advise(w);
479
+ if (out.css) cssById.set(id, await viteCss(out.css, args.path, `${id} <style>`));
480
+ return { contents: transformSource(out.js, args.path, SHAPES) ?? out.js, loader: "js" as const };
481
+ });
468
482
  },
469
483
  };
470
484
 
@@ -522,28 +536,45 @@ async function writeGraph(out: string) {
522
536
  target: "browser",
523
537
  define: DEFINES,
524
538
  plugins: [viteShapesPlugin(SHAPES), vuePlugin, entryPlugin],
539
+ conditions: PROD_CONDITIONS,
525
540
  minify: minify ? { whitespace: true, identifiers: true, syntax: true } : false,
526
- sourcemap: "none",
541
+ sourcemap: "external",
527
542
  metafile: true,
528
543
  throw: false,
529
544
  });
530
- // Metafile keys are relative, to a base that varies between runs ("node_modules/…", "../../C:/…"):
531
- // match them against the absolute paths the plugins loaded.
545
+ // Metafile keys and sourcemap sources are relative, to a base that varies between runs
546
+ // ("node_modules/…", "../../C:/…"): match them against the absolute paths the plugins loaded.
532
547
  const byName = new Map<string, { key: string; path: string }[]>();
533
548
  for (const path of GRAPH_LOADED) {
534
549
  const key = resolve(path).split(sep).join("/").toLowerCase();
535
550
  const name = key.slice(key.lastIndexOf("/") + 1);
536
551
  byName.set(name, [...(byName.get(name) ?? []), { key, path: resolve(path) }]);
537
552
  }
553
+ const loadedPaths = (key: string) => {
554
+ const tail = `/${key.replace(/^(?:\.\.\/)+/, "").replace(/^[A-Za-z]:\//, "")}`.toLowerCase();
555
+ return (byName.get(tail.slice(tail.lastIndexOf("/") + 1)) ?? []).filter((l) => l.key.endsWith(tail));
556
+ };
538
557
  const modules = new Set<string>();
539
558
  for (const output of Object.values(result.metafile?.outputs ?? {})) {
540
559
  for (const [key, input] of Object.entries(output.inputs)) {
541
560
  if (input.bytesInOutput <= 0) continue;
542
- const tail = `/${key.replace(/^(?:\.\.\/)+/, "").replace(/^[A-Za-z]:\//, "")}`.toLowerCase();
543
- for (const loaded of byName.get(tail.slice(tail.lastIndexOf("/") + 1)) ?? [])
544
- if (loaded.key.endsWith(tail)) modules.add(loaded.path);
561
+ for (const loaded of loadedPaths(key)) modules.add(loaded.path);
545
562
  }
546
563
  }
564
+ let bundle: ModuleGraph["bundle"];
565
+ const code = result.outputs.find((o) => o.kind === "entry-point");
566
+ const map = result.outputs.find((o) => o.kind === "sourcemap");
567
+ if (result.success && code && map) {
568
+ const raw = JSON.parse(await map.text()) as { sources: string[]; sourcesContent?: string[]; mappings: string };
569
+ const sources = raw.sources.map((key, i) => {
570
+ const [loaded, ...others] = loadedPaths(key);
571
+ if (!loaded || others.length) return null;
572
+ // Positions are the file's own only when the bundler read it as is (not a compiled .vue or .svelte).
573
+ const text = readFileSync(loaded.path, "utf8").replace(/^\uFEFF/, "");
574
+ return raw.sourcesContent?.[i] === text ? loaded.path : null;
575
+ });
576
+ bundle = { code: await code.text(), sources, mappings: raw.mappings };
577
+ }
547
578
  const graph: ModuleGraph = {
548
579
  schema: "skathi.module-graph",
549
580
  version: 1,
@@ -557,6 +588,7 @@ async function writeGraph(out: string) {
557
588
  },
558
589
  declarations: [...new Bun.Glob("*.d.ts").scanSync({ cwd: RUNTIME_SRC_DIR, absolute: true })],
559
590
  modules: [...modules].sort(),
591
+ ...(bundle ? { bundle } : {}),
560
592
  errors: result.logs
561
593
  .filter((log) => log.level === "error")
562
594
  .map((log) => ({
@@ -584,6 +616,7 @@ async function build() {
584
616
  target: "browser",
585
617
  define: DEFINES,
586
618
  plugins: [viteShapesPlugin(SHAPES), vuePlugin, entryPlugin],
619
+ conditions: PROD_CONDITIONS,
587
620
  minify: minify ? { whitespace: true, identifiers: true, syntax: true } : false,
588
621
  sourcemap: "none",
589
622
  });
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
+ }
Binary file
@@ -42,7 +42,7 @@ onMounted(async () => {
42
42
  gap: 20px;
43
43
  padding: 32px;
44
44
  color: #f4f4f5;
45
- font-family: "Segoe UI", system-ui, sans-serif;
45
+ font-family: system-ui, sans-serif;
46
46
  }
47
47
  .card {
48
48
  width: 380px;
@@ -88,7 +88,7 @@ onMounted(async () => {
88
88
  text-align: center;
89
89
  }
90
90
  .code {
91
- font-family: "Cascadia Mono", Consolas, monospace;
91
+ font-family: monospace;
92
92
  font-size: 13px;
93
93
  color: #d4d4d8;
94
94
  }
@@ -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
+ };