@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.
Files changed (63) hide show
  1. package/aot/host-globals.json +1 -1
  2. package/aot/pin.ts +1 -1
  3. package/aot/toolchain.lock.json +5 -5
  4. package/aot/transform.ts +9 -1
  5. package/aot-inputs.ts +21 -2
  6. package/build.ts +284 -64
  7. package/check/builtins.json +11 -11
  8. package/check/bundle.ts +265 -0
  9. package/check/codes.ts +46 -0
  10. package/check/css-catalog.json +451 -0
  11. package/check/css.ts +512 -0
  12. package/check/finding.ts +63 -1
  13. package/check/graph.ts +14 -1
  14. package/check/index.ts +30 -49
  15. package/check/program.ts +26 -6
  16. package/cli/aot-build.ts +2 -6
  17. package/cli/build-app.ts +19 -0
  18. package/cli/create.ts +70 -12
  19. package/cli/dev.ts +11 -6
  20. package/cli/effects.ts +39 -18
  21. package/cli/gallery.ts +106 -0
  22. package/cli/sk.ts +5 -2
  23. package/devtools/commands.ts +26 -1
  24. package/devtools/ctl.ts +4 -3
  25. package/effects/compile.ts +160 -31
  26. package/effects/sk.slang +359 -30
  27. package/gallery.json +1 -0
  28. package/package.json +9 -5
  29. package/prod.ts +78 -10
  30. package/svelte.ts +76 -0
  31. package/templates/icon.png +0 -0
  32. package/templates/showcase/assets/textures/golden.png +0 -0
  33. package/templates/showcase/assets/textures/hammered.png +0 -0
  34. package/templates/showcase/assets/textures/noir.png +0 -0
  35. package/templates/showcase/assets/textures/reeded.png +0 -0
  36. package/templates/showcase/assets/textures/teal-orange.png +0 -0
  37. package/templates/showcase/shaders/dissolve.slang +40 -0
  38. package/templates/showcase/shaders/fireflies.slang +58 -0
  39. package/templates/showcase/shaders/glass.slang +31 -0
  40. package/templates/showcase/shaders/grade.slang +34 -0
  41. package/templates/showcase/shaders/halftone.slang +42 -0
  42. package/templates/showcase/shaders/lens.slang +51 -0
  43. package/templates/showcase/shaders/nebula.slang +57 -0
  44. package/templates/showcase/shaders/orbit.slang +52 -0
  45. package/templates/showcase/shaders/pond.slang +76 -0
  46. package/templates/showcase/shaders/ripples.slang +71 -0
  47. package/templates/showcase/shaders/shatter.slang +116 -0
  48. package/templates/showcase/shaders/snow.slang +57 -0
  49. package/templates/showcase/shaders/spotlight.slang +52 -0
  50. package/templates/showcase/src/App.vue +11 -16
  51. package/templates/showcase/src/components/FullWindow.vue +77 -0
  52. package/templates/showcase/src/components/Page.vue +2 -0
  53. package/templates/showcase/src/fullwindow.ts +36 -0
  54. package/templates/showcase/src/icons.ts +2 -0
  55. package/templates/showcase/src/pages/GraphicsPage.vue +122 -0
  56. package/templates/showcase/src/pages/MotionPage.vue +71 -1
  57. package/templates/showcase/src/pages/ShadersPage.vue +443 -0
  58. package/templates/showcase/src/router.ts +32 -1
  59. package/templates/svelte/.vscode/settings.json +3 -0
  60. package/templates/svelte/assets/hello.txt +1 -0
  61. package/templates/svelte/src/App.svelte +142 -0
  62. package/templates/svelte/src/main.ts +4 -0
  63. package/vitecompat.ts +2 -0
@@ -0,0 +1,76 @@
1
+ import sk;
2
+
3
+ // A water surface over the element's own painting. The pointer drags through it; the waves it makes
4
+ // run outwards, bounce off the edges and die down, and they bend and light what is under them.
5
+ //
6
+ // The surface is a wave equation stepped in the history: red is the height now, green the height one
7
+ // step ago. The window keeps repainting for four seconds after the pointer last moved, which is long
8
+ // enough for the water to settle.
9
+ [SkEffect("pond")]
10
+ [SkDoc("a rippling water surface the pointer stirs, over the element's own painting")]
11
+ [SkContent]
12
+ [SkHistory]
13
+ struct Pond : IEffect
14
+ {
15
+ // How long a wave lasts: the share of its height it keeps each step.
16
+ [SkDefault("0.985")] [SkRange(0.8, 0.999)]
17
+ float damping;
18
+
19
+ // How far the slope of the water shifts what is under it.
20
+ [SkLength] [SkDefault("40")] [SkRange(0.0, 400.0)]
21
+ float depth;
22
+
23
+ [SkColor] [SkOptional] [SkDefault("#bfe3ff")]
24
+ float4 light;
25
+
26
+ [SkPointer]
27
+ float2 at;
28
+
29
+ [SkPointerTimes] [SkAnimatedFor(4.0)]
30
+ float3 seen;
31
+
32
+ // The grid the waves travel on, in device pixels: coarser than a pixel so they move at a
33
+ // readable speed with the history stepping at most 75 times a second.
34
+ float spacing(EffectInput input)
35
+ {
36
+ return 2.0 * input.scale;
37
+ }
38
+
39
+ float height(EffectInput input, float2 px)
40
+ {
41
+ return input.historyAtPx(px).r;
42
+ }
43
+
44
+ override float4 update(EffectInput input)
45
+ {
46
+ float s = spacing(input);
47
+ float around = height(input, input.px + float2(s, 0.0)) + height(input, input.px - float2(s, 0.0))
48
+ + height(input, input.px + float2(0.0, s)) + height(input, input.px - float2(0.0, s));
49
+ float next = (around * 0.5 - input.history.g) * damping;
50
+
51
+ // The pointer pushes the water down while it moves inside the element.
52
+ float2 pointer = at * input.size;
53
+ float moving = 1.0 - saturate((input.time - seen.x) / 0.05);
54
+ bool inside = all(at >= 0.0) && all(at <= 1.0) && seen.y > seen.z;
55
+ float radius = 9.0 * input.scale;
56
+ float2 d = input.px - pointer;
57
+ next -= inside ? moving * 0.9 * exp(-dot(d, d) / (radius * radius)) : 0.0;
58
+
59
+ return float4(clamp(next, -4.0, 4.0), input.history.r, 0.0, 0.0);
60
+ }
61
+
62
+ float4 shade(EffectInput input)
63
+ {
64
+ float s = spacing(input);
65
+ float2 slope = float2(
66
+ height(input, input.px + float2(s, 0.0)) - height(input, input.px - float2(s, 0.0)),
67
+ height(input, input.px + float2(0.0, s)) - height(input, input.px - float2(0.0, s)));
68
+
69
+ // Kept inside the box: past its edge the element painted nothing to show.
70
+ float4 under = input.contentAtPx(clamp(input.px + slope * depth, 0.5, input.size - 0.5));
71
+ // Light from the top left catches the faces of the waves that tilt towards it.
72
+ float glint = pow(saturate(dot(slope, float2(-0.6, -0.8)) * 1.6), 2.0);
73
+ float3 rgb = under.rgb * (1.0 + input.history.r * 0.08) + light.rgb * glint * light.a * under.a;
74
+ return float4(rgb, under.a);
75
+ }
76
+ };
@@ -0,0 +1,71 @@
1
+ import sk;
2
+
3
+ // Rings of water spreading from up to eight points, refracting whatever is behind the element. The
4
+ // rings add up as heights, so where two meet they interfere: crests stack, crest and trough cancel.
5
+ //
6
+ // A ring is where it started and when, on the effect clock (`performance.now() / 1000` in JS), so
7
+ // the page sets it once per click and the effect works out the age itself. The window repaints for
8
+ // three seconds after the newest ring and then the effect is still.
9
+ [SkEffect("ripples")]
10
+ [SkDoc("interfering water rings that refract the backdrop")]
11
+ [SkBackdrop]
12
+ struct Ripples : IEffect
13
+ {
14
+ // Where each ring starts, 0..1 across the element.
15
+ float2 at0;
16
+ float2 at1;
17
+ float2 at2;
18
+ float2 at3;
19
+ float2 at4;
20
+ float2 at5;
21
+ float2 at6;
22
+ float2 at7;
23
+
24
+ // When each ring started; long ago is no ring.
25
+ [SkAnimatedFor(3.0)] [SkDefault("-1000")]
26
+ float4 born0;
27
+ [SkAnimatedFor(3.0)] [SkDefault("-1000")]
28
+ float4 born1;
29
+
30
+ // Height of one ring at `px` and its slope along the ring's radius.
31
+ float2 ring(float2 at, float born, EffectInput input, out float2 outward)
32
+ {
33
+ outward = float2(0.0, 0.0);
34
+ float age = input.time - born;
35
+ if (age < 0.0 || age > 3.0)
36
+ return float2(0.0, 0.0);
37
+ float2 d = input.px - at * input.size;
38
+ float r = length(d);
39
+ outward = d / max(r, 1.0);
40
+
41
+ float s = input.scale;
42
+ float wavelength = 34.0 * s;
43
+ float front = age * 300.0 * s;
44
+ float width = (40.0 + 90.0 * age) * s;
45
+ float x = (r - front) / width;
46
+ float packet = exp(-x * x) * pow(1.0 - age / 3.0, 2.0) / sqrt(1.0 + r / (160.0 * s));
47
+ float phase = (r - front) / wavelength * 6.28318530718;
48
+ return float2(sin(phase), cos(phase) * 6.28318530718 / wavelength) * packet;
49
+ }
50
+
51
+ float4 shade(EffectInput input)
52
+ {
53
+ float2 ats[8] = { at0, at1, at2, at3, at4, at5, at6, at7 };
54
+ float borns[8] = { born0.x, born0.y, born0.z, born0.w, born1.x, born1.y, born1.z, born1.w };
55
+ float2 slope = float2(0.0, 0.0);
56
+ float height = 0.0;
57
+ for (int i = 0; i < 8; i++)
58
+ {
59
+ float2 outward;
60
+ float2 h = ring(ats[i], borns[i], input, outward);
61
+ height += h.x;
62
+ slope += outward * h.y;
63
+ }
64
+
65
+ // The surface's slope bends the view; its tilt toward a light at the top left makes highlights.
66
+ float4 seen = input.backdropAtPx(input.px + slope * 70.0 * input.scale);
67
+ float glint = saturate(dot(slope, float2(-0.6, -0.8)) * 5.0 * input.scale);
68
+ float shade = 1.0 + height * 0.06;
69
+ return float4(seen.rgb * shade + glint * glint * 0.35 * seen.a, seen.a);
70
+ }
71
+ };
@@ -0,0 +1,116 @@
1
+ import sk;
2
+
3
+ // Breaks whatever is behind the element into Voronoi shards that crack from `origin`, fall away and,
4
+ // as `progress` goes back to 0, fly back into place. Each pixel finds the shard now covering it by
5
+ // undoing every nearby shard's motion and testing which cell the result lands in; only then does it
6
+ // read the backdrop, once, at that point.
7
+ [SkEffect("shatter")]
8
+ [SkDoc("cracks the backdrop into falling shards; progress 0..1")]
9
+ [SkBackdrop]
10
+ struct Shatter : IEffect
11
+ {
12
+ [SkDefault("0")] [SkRange(0.0, 1.0)]
13
+ float progress;
14
+
15
+ // Where the crack starts, 0..1 across the element.
16
+ [SkDefault("0.5 0.5")]
17
+ float2 origin;
18
+
19
+ [SkLength] [SkDefault("110")] [SkRange(24.0, 512.0)]
20
+ float shard;
21
+
22
+ // What shows in the cracks and where the shards have gone. Transparent by default, so a window
23
+ // with a transparent background opens onto whatever is behind it.
24
+ [SkColor] [SkOptional] [SkDefault("#00000000")]
25
+ float4 behind;
26
+
27
+ float2 seed(float2 cell)
28
+ {
29
+ return (cell + 0.5 + (sk_hash22(cell) - 0.5) * 0.7) * shard;
30
+ }
31
+
32
+ // Distance from `q` to the border of `cell`'s Voronoi region: positive inside it.
33
+ float inside(float2 q, float2 cell)
34
+ {
35
+ float2 own = seed(cell);
36
+ float nearest = 1e9;
37
+ for (int y = -1; y <= 1; y++)
38
+ {
39
+ for (int x = -1; x <= 1; x++)
40
+ {
41
+ if (x == 0 && y == 0)
42
+ continue;
43
+ float2 other = seed(cell + float2(x, y));
44
+ float2 across = other - own;
45
+ nearest = min(nearest, -dot(q - (own + other) * 0.5, across) / length(across));
46
+ }
47
+ }
48
+ return nearest;
49
+ }
50
+
51
+ float4 shade(EffectInput input)
52
+ {
53
+ float2 from = origin * input.size;
54
+ float reach = length(input.size);
55
+ float front = saturate(progress / 0.25) * reach * 1.1;
56
+ float2 home = floor(input.px / shard);
57
+
58
+ bool found = false;
59
+ float2 source = input.px;
60
+ float edge = 0.0;
61
+ float fall = 0.0;
62
+ float cracked = 0.0;
63
+ float spin = 0.0;
64
+ // A shard falls at most two cells and drifts at most one sideways, so these are the only ones
65
+ // that can cover this pixel. Falling shards recede, so the least fallen one is in front.
66
+ for (int dy = 1; dy >= -2; dy--)
67
+ {
68
+ for (int dx = -1; dx <= 1; dx++)
69
+ {
70
+ float2 cell = home + float2(dx, dy);
71
+ float2 centre = seed(cell);
72
+ float delay = length(centre - from) / reach;
73
+ float u = saturate((progress - 0.22 - delay * 0.3) / 0.45);
74
+ float e = u * u;
75
+ float hit = step(length(centre - from), front);
76
+ float h1 = sk_hash12(cell + 3.1);
77
+ float h2 = sk_hash12(cell + 7.7);
78
+
79
+ float2 away = normalize(centre - from + 1e-3);
80
+ float2 shift = (sk_hash22(cell + 1.3) - 0.5) * 3.0 * input.scale * hit;
81
+ shift += float2((h1 - 0.5) * 0.6 + away.x * 0.3, 1.8) * e * shard;
82
+ float angle = (h2 - 0.5) * 3.0 * e;
83
+ float size = 1.0 - 0.7 * e;
84
+
85
+ float2 q = centre + sk_rotate(input.px - centre - shift, -angle) / size;
86
+ float d = inside(q, cell);
87
+ if (d >= 0.0 && u < 0.999 && (!found || u < fall))
88
+ {
89
+ found = true;
90
+ source = q;
91
+ edge = d * size;
92
+ fall = u;
93
+ cracked = hit;
94
+ spin = angle;
95
+ }
96
+ }
97
+ }
98
+
99
+ float4 seen = input.backdropAtPx(source);
100
+ float4 gone = sk_premultiply(behind);
101
+ if (!found)
102
+ return gone;
103
+
104
+ // A tilted shard catches or loses the light; its broken edge glints.
105
+ float light = 1.0 - 0.3 * fall + 0.25 * fall * sin(spin * 3.0);
106
+ float px = input.scale;
107
+ float crack = cracked * (1.0 - saturate(edge / (0.9 * px)));
108
+ float glint = cracked * (1.0 - saturate(abs(edge - 1.6 * px) / px)) * (0.35 + 0.4 * fall);
109
+
110
+ float4 glass = float4(seen.rgb * light + glint * seen.a, seen.a);
111
+ // Premultiplied, so scaling the whole colour thins the alpha too: cracks and fading shards
112
+ // let through what is behind the window rather than darkening it.
113
+ float keep = (1.0 - crack) * (1.0 - smoothstep(0.6, 1.0, fall));
114
+ return glass * keep + gone * (1.0 - keep);
115
+ }
116
+ };
@@ -0,0 +1,57 @@
1
+ import sk;
2
+
3
+ // Four layers of snow, the nearer ones bigger, softer and faster. The flakes near the pointer are
4
+ // pushed gently aside while it is in the window; the rest of the snow does not notice it.
5
+ [SkEffect("snow")]
6
+ [SkDoc("parallax snowfall that parts around the pointer")]
7
+ struct Snow : IEffect
8
+ {
9
+ [SkAnimated] [SkDefault("1")] [SkRange(0.0, 4.0)]
10
+ float speed;
11
+
12
+ // How wide a berth the flakes give the pointer; 0 turns it off.
13
+ [SkLength] [SkDefault("90")] [SkRange(0.0, 1024.0)]
14
+ float berth;
15
+
16
+ [SkDefault("0.6")] [SkRange(0.0, 1.0)]
17
+ float amount;
18
+
19
+ [SkPointer]
20
+ float2 at;
21
+
22
+ [SkPointerTimes]
23
+ float3 seen;
24
+
25
+ static override bool straightAlpha() { return true; }
26
+
27
+ float4 shade(EffectInput input)
28
+ {
29
+ float t = input.time * speed;
30
+ float2 pointer = at * input.size;
31
+ float2 offset = input.px - pointer;
32
+ float reach = max(berth, 1.0);
33
+ float near = sk_pointer_presence(seen, input.time, 0.5);
34
+ float part = berth > 0.0 ? 0.3 * near * exp(-dot(offset, offset) / (reach * reach)) : 0.0;
35
+ float2 p = pointer + offset * (1.0 - part);
36
+
37
+ float alpha = 0.0;
38
+ for (int layer = 0; layer < 4; layer++)
39
+ {
40
+ float depth = float(layer);
41
+ float cell = (38.0 + 30.0 * depth) * input.scale;
42
+ float fall = (26.0 + 30.0 * depth) * input.scale;
43
+ float2 q = p - float2(0.0, t * fall);
44
+ float2 id = floor(q / cell) + depth * 17.0;
45
+ float2 jitter = sk_hash22(id);
46
+ float2 spot = (floor(q / cell) + 0.25 + 0.5 * jitter) * cell;
47
+ spot.x += sin(t * (0.8 + jitter.y) + jitter.x * 6.28) * cell * 0.18;
48
+
49
+ float radius = (0.8 + 0.9 * depth + jitter.y * 0.8) * input.scale;
50
+ float soft = (0.6 + 0.9 * depth) * input.scale;
51
+ float flake = 1.0 - smoothstep(radius - soft, radius + soft, length(q - spot));
52
+ float present = step(sk_hash12(id + 5.0), amount);
53
+ alpha = max(alpha, flake * present * (0.45 + 0.15 * depth));
54
+ }
55
+ return float4(0.93, 0.96, 1.0, alpha);
56
+ }
57
+ };
@@ -0,0 +1,52 @@
1
+ import sk;
2
+
3
+ // A dot grid that swells and lights up around the pointer, pushing the dots aside as it passes. The
4
+ // host hands the effect the pointer, so no script runs: the light dims as the pointer moves off the
5
+ // element and fades when it leaves the window.
6
+ [SkEffect("spotlight")]
7
+ [SkDoc("a dot grid lit and displaced around the pointer")]
8
+ struct Spotlight : IEffect
9
+ {
10
+ [SkLength] [SkDefault("140")] [SkRange(8.0, 1024.0)]
11
+ float radius;
12
+
13
+ // 0 is a dim, even grid; 1 is the full light.
14
+ [SkDefault("1")] [SkRange(0.0, 1.0)]
15
+ float strength;
16
+
17
+ [SkColor] [SkOptional] [SkDefault("#8b9dff")]
18
+ float4 color;
19
+
20
+ [SkPointer]
21
+ float2 at;
22
+
23
+ [SkPointerTimes] [SkAnimatedFor(0.3)]
24
+ float3 seen;
25
+
26
+ static override bool straightAlpha() { return true; }
27
+
28
+ float4 shade(EffectInput input)
29
+ {
30
+ float2 pointer = at * input.size;
31
+ float2 outside = max(abs(pointer - input.size * 0.5) - input.size * 0.5, 0.0);
32
+ float over = 1.0 - smoothstep(0.0, 28.0 * input.scale, length(outside));
33
+ float lit = strength * over * sk_pointer_presence(seen, input.time, 0.3);
34
+
35
+ float2 offset = input.px - pointer;
36
+ float reach = max(radius, 1.0);
37
+ float near = exp(-dot(offset, offset) / (reach * reach)) * lit;
38
+
39
+ // Near the light each pixel looks up the grid closer to it, which magnifies the dots there.
40
+ float zoom = 1.0 - 0.45 * near;
41
+ float2 p = pointer + offset * zoom;
42
+
43
+ float spacing = 16.0 * input.scale;
44
+ float2 cell = (frac(p / spacing) - 0.5) * spacing / zoom;
45
+ float size = (0.9 + 1.6 * near) * input.scale;
46
+ float disc = input.aa(length(cell) - size);
47
+
48
+ float3 rgb = lerp(float3(0.62, 0.64, 0.72), lerp(color.rgb, float3(1.0, 1.0, 1.0), near * near * 0.5), near);
49
+ float alpha = disc * (0.16 + 0.84 * near) + near * near * 0.22;
50
+ return float4(rgb, saturate(alpha * color.a));
51
+ }
52
+ };
@@ -2,6 +2,7 @@
2
2
  import { appDevtools } from "@skathi-native/runtime";
3
3
  import { computed } from "vue";
4
4
  import { useRoute } from "vue-router";
5
+ import FullWindow from "./components/FullWindow.vue";
5
6
  import Icon from "./components/Icon.vue";
6
7
  import Titlebar from "./components/Titlebar.vue";
7
8
  import { pages } from "./router";
@@ -32,13 +33,10 @@ const sections = computed(() => {
32
33
  <div v-if="devtools" class="foot">F12 opens the devtools</div>
33
34
  </nav>
34
35
  <main class="content">
35
- <RouterView v-slot="{ Component }">
36
- <Transition name="page" mode="out-in">
37
- <component :is="Component" />
38
- </Transition>
39
- </RouterView>
36
+ <RouterView />
40
37
  </main>
41
38
  </div>
39
+ <FullWindow />
42
40
  </div>
43
41
  </template>
44
42
 
@@ -112,17 +110,14 @@ const sections = computed(() => {
112
110
  min-width: 0;
113
111
  overflow-y: auto;
114
112
  }
115
- .page-enter-active,
116
- .page-leave-active {
117
- transition:
118
- opacity 140ms ease,
119
- transform 140ms ease;
120
- }
121
- .page-enter-from {
122
- opacity: 0;
123
- transform: translateY(6px);
113
+ /* Page navigations (router.ts): the page cross-fades while its title moves into place. */
114
+ ::view-transition-group(*) {
115
+ animation-duration: 220ms;
116
+ animation-timing-function: cubic-bezier(0.2, 0, 0, 1);
124
117
  }
125
- .page-leave-to {
126
- opacity: 0;
118
+ ::view-transition-old(page-title),
119
+ ::view-transition-new(page-title) {
120
+ width: auto;
121
+ height: 100%;
127
122
  }
128
123
  </style>
@@ -0,0 +1,77 @@
1
+ <script setup lang="ts">
2
+ import { computed, onMounted, onUnmounted, shallowRef } from "vue";
3
+ import { fullWindow } from "../fullwindow";
4
+
5
+ // Layers over the whole window that take no pointer events, so the page under them works as usual.
6
+ // Snow and fireflies get the pointer from the host; ripples are clicks read from the document.
7
+ const root = shallowRef<HTMLElement | null>(null);
8
+
9
+ // The last eight clicks while ripples are on, each where it landed (0..1 across the window) and when,
10
+ // on the clock the effect reads (`performance.now()` in seconds). The effect ages them itself.
11
+ const RINGS = 8;
12
+ const RING_MS = 3000;
13
+ type Drop = { x: number; y: number; born: number };
14
+ const drops = shallowRef<Drop[]>([]);
15
+ let prune: ReturnType<typeof setTimeout> | undefined;
16
+
17
+ function drop(e: MouseEvent) {
18
+ const rect = root.value?.getBoundingClientRect();
19
+ if (!fullWindow.ripples || !rect || !rect.width || !rect.height) return;
20
+ const at = { x: (e.clientX - rect.left) / rect.width, y: (e.clientY - rect.top) / rect.height };
21
+ drops.value = [...drops.value, { ...at, born: performance.now() / 1000 }].slice(-RINGS);
22
+ clearTimeout(prune);
23
+ prune = setTimeout(() => (drops.value = []), RING_MS);
24
+ }
25
+
26
+ const f = (n: number) => n.toFixed(4);
27
+ const ripples = computed(() => {
28
+ if (!drops.value.length) return null;
29
+ const ring = (i: number) => drops.value[i];
30
+ const at = Array.from({ length: RINGS }, (_, i) => `${f(ring(i)?.x ?? 0)}, ${f(ring(i)?.y ?? 0)}`);
31
+ const born = Array.from({ length: RINGS }, (_, i) => (ring(i)?.born ?? -1000).toFixed(3));
32
+ return `ripples(${[...at, ...born].join(", ")})`;
33
+ });
34
+
35
+ onMounted(() => document.addEventListener("mousedown", drop));
36
+ onUnmounted(() => {
37
+ document.removeEventListener("mousedown", drop);
38
+ clearTimeout(prune);
39
+ });
40
+
41
+ const shatter = computed(() => {
42
+ const rect = root.value?.getBoundingClientRect();
43
+ const x = rect?.width ? (fullWindow.impact.x - rect.left) / rect.width : 0.5;
44
+ const y = rect?.height ? (fullWindow.impact.y - rect.top) / rect.height : 0.5;
45
+ return `shatter(${f(fullWindow.shatter ?? 0)}, ${f(x)}, ${f(y)}, 110px)`;
46
+ });
47
+ </script>
48
+
49
+ <template>
50
+ <div ref="root" class="full">
51
+ <div v-if="ripples" class="layer" :style="{ '--shading': ripples }" />
52
+ <div v-if="fullWindow.fireflies" class="layer fireflies" />
53
+ <div v-if="fullWindow.snow" class="layer snow" />
54
+ <div v-if="fullWindow.shatter !== null" class="layer" :style="{ '--shading': shatter }" />
55
+ </div>
56
+ </template>
57
+
58
+ <style scoped>
59
+ .full,
60
+ .layer {
61
+ position: absolute;
62
+ left: 0;
63
+ top: 0;
64
+ right: 0;
65
+ bottom: 0;
66
+ pointer-events: none;
67
+ }
68
+ .full {
69
+ z-index: 100;
70
+ }
71
+ .snow {
72
+ --shading: snow(1, 90px, 0.6);
73
+ }
74
+ .fireflies {
75
+ --shading: fireflies(1, 16px, 0.5);
76
+ }
77
+ </style>
@@ -30,6 +30,8 @@ defineProps<{ title: string; lead: string }>();
30
30
  font-size: 24px;
31
31
  font-weight: 700;
32
32
  color: var(--text);
33
+ align-self: flex-start;
34
+ view-transition-name: page-title;
33
35
  }
34
36
  .lead {
35
37
  margin: 0;
@@ -0,0 +1,36 @@
1
+ import { reactive } from "vue";
2
+
3
+ /** The effects drawn over the whole window, by components/FullWindow.vue. */
4
+ export const fullWindow = reactive({
5
+ snow: false,
6
+ fireflies: false,
7
+ /** Every click anywhere sends out a ring of water. */
8
+ ripples: false,
9
+ /** 0 intact to 1 fallen apart; null while no shatter runs. */
10
+ shatter: null as number | null,
11
+ /** Where the crack starts, in client pixels. */
12
+ impact: { x: 0, y: 0 },
13
+ });
14
+
15
+ const APART_MS = 1300;
16
+ const HOLD_MS = 600;
17
+ const BACK_MS = 1300;
18
+
19
+ /** Breaks the window from the point (x, y) and puts it back together. */
20
+ export function shatter(x: number, y: number) {
21
+ if (fullWindow.shatter !== null) return;
22
+ fullWindow.impact = { x, y };
23
+ fullWindow.shatter = 0;
24
+ let start = -1;
25
+ const step = (now: number) => {
26
+ if (start < 0) start = now;
27
+ const t = now - start;
28
+ if (t >= APART_MS + HOLD_MS + BACK_MS) {
29
+ fullWindow.shatter = null;
30
+ return;
31
+ }
32
+ fullWindow.shatter = t < APART_MS ? t / APART_MS : Math.min(1, 1 - (t - APART_MS - HOLD_MS) / BACK_MS);
33
+ requestAnimationFrame(step);
34
+ };
35
+ requestAnimationFrame(step);
36
+ }
@@ -10,6 +10,8 @@ export const icons = {
10
10
  media: "M3 5h18v14H3z M3 16l5-5 4 4 3-3 6 6 M16 9h.01",
11
11
  audio: "M9 18V5l12-2v13 M9 18a3 3 0 1 1-6 0 3 3 0 0 1 6 0z M21 16a3 3 0 1 1-6 0 3 3 0 0 1 6 0z",
12
12
  graphics: "M12 3l9 16H3z M12 9v4",
13
+ shaders:
14
+ "M10 3l1.8 4.9L17 10l-5.2 2.1L10 17l-1.8-4.9L3 10l5.2-2.1z M18 14l.9 2.1L21 17l-2.1.9L18 20l-.9-2.1L15 17l2.1-.9z",
13
15
  motion: "M12 3v4 M12 17v4 M3 12h4 M17 12h4 M6 6l2.5 2.5 M15.5 15.5 18 18 M6 18l2.5-2.5 M15.5 8.5 18 6",
14
16
  styles:
15
17
  "M12 3a9 9 0 1 0 0 18c1.1 0 2-.9 2-2 0-.5-.2-1-.5-1.3-.3-.4-.5-.8-.5-1.3 0-1.1.9-2 2-2h2.4A4.6 4.6 0 0 0 21 9.8C21 6 17 3 12 3z M7.5 11h.01 M10 7h.01 M15 7.5h.01",