@skathi-native/cli 0.1.0-beta.4 → 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 (46) 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/graph.ts +3 -1
  5. package/check/index.ts +10 -1
  6. package/check/program.ts +26 -6
  7. package/cli/create.ts +29 -7
  8. package/devtools/commands.ts +25 -0
  9. package/effects/compile.ts +160 -31
  10. package/effects/sk.slang +353 -29
  11. package/package.json +7 -4
  12. package/prod.ts +40 -7
  13. package/svelte.ts +76 -0
  14. package/templates/icon.png +0 -0
  15. package/templates/showcase/assets/textures/golden.png +0 -0
  16. package/templates/showcase/assets/textures/hammered.png +0 -0
  17. package/templates/showcase/assets/textures/noir.png +0 -0
  18. package/templates/showcase/assets/textures/reeded.png +0 -0
  19. package/templates/showcase/assets/textures/teal-orange.png +0 -0
  20. package/templates/showcase/shaders/dissolve.slang +40 -0
  21. package/templates/showcase/shaders/fireflies.slang +58 -0
  22. package/templates/showcase/shaders/glass.slang +31 -0
  23. package/templates/showcase/shaders/grade.slang +34 -0
  24. package/templates/showcase/shaders/halftone.slang +42 -0
  25. package/templates/showcase/shaders/lens.slang +51 -0
  26. package/templates/showcase/shaders/nebula.slang +57 -0
  27. package/templates/showcase/shaders/orbit.slang +52 -0
  28. package/templates/showcase/shaders/pond.slang +76 -0
  29. package/templates/showcase/shaders/ripples.slang +71 -0
  30. package/templates/showcase/shaders/shatter.slang +116 -0
  31. package/templates/showcase/shaders/snow.slang +57 -0
  32. package/templates/showcase/shaders/spotlight.slang +52 -0
  33. package/templates/showcase/src/App.vue +11 -16
  34. package/templates/showcase/src/components/FullWindow.vue +77 -0
  35. package/templates/showcase/src/components/Page.vue +2 -0
  36. package/templates/showcase/src/fullwindow.ts +36 -0
  37. package/templates/showcase/src/icons.ts +2 -0
  38. package/templates/showcase/src/pages/GraphicsPage.vue +122 -0
  39. package/templates/showcase/src/pages/MotionPage.vue +71 -1
  40. package/templates/showcase/src/pages/ShadersPage.vue +443 -0
  41. package/templates/showcase/src/router.ts +32 -1
  42. package/templates/svelte/.vscode/settings.json +3 -0
  43. package/templates/svelte/assets/hello.txt +1 -0
  44. package/templates/svelte/src/App.svelte +142 -0
  45. package/templates/svelte/src/main.ts +4 -0
  46. package/vitecompat.ts +2 -0
@@ -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",
@@ -3,6 +3,14 @@ import { onMounted, onUnmounted, ref, shallowRef } from "vue";
3
3
  import Card from "../components/Card.vue";
4
4
  import Page from "../components/Page.vue";
5
5
  import { describe, everyFrame } from "../engine";
6
+ import { icons, type IconName } from "../icons";
7
+
8
+ const maskIcons: IconName[] = ["home", "shaders", "audio", "permissions"];
9
+ const tints = ["#8b93ff", "#f0b45a", "#5ad1a8", "#f07a9a"];
10
+ const iconMask = (name: IconName) =>
11
+ `url("data:image/svg+xml,${encodeURIComponent(
12
+ `<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='${icons[name]}'/></svg>`,
13
+ )}")`;
6
14
 
7
15
  const W = 640;
8
16
  const H = 220;
@@ -118,6 +126,31 @@ onMounted(() => {
118
126
  if (surface.value) startGpu(surface.value).catch((e: unknown) => (adapterName.value = describe(e)));
119
127
  });
120
128
  onUnmounted(() => stopGpu?.());
129
+
130
+ const stage = shallowRef<HTMLElement | null>(null);
131
+ const locked = ref(false);
132
+ const lockError = ref("");
133
+ const spin = ref({ x: -20, y: 30 });
134
+ const travelled = ref(0);
135
+
136
+ function lock() {
137
+ lockError.value = "";
138
+ stage.value?.requestPointerLock().catch((e: unknown) => (lockError.value = describe(e)));
139
+ }
140
+ function look(e: MouseEvent) {
141
+ if (!locked.value) return;
142
+ spin.value = {
143
+ x: Math.max(-80, Math.min(80, spin.value.x - e.movementY * 0.4)),
144
+ y: (spin.value.y + e.movementX * 0.4) % 360,
145
+ };
146
+ travelled.value += Math.hypot(e.movementX, e.movementY);
147
+ }
148
+ const onLockChange = () => (locked.value = document.pointerLockElement === stage.value);
149
+ onMounted(() => document.addEventListener("pointerlockchange", onLockChange));
150
+ onUnmounted(() => {
151
+ document.removeEventListener("pointerlockchange", onLockChange);
152
+ if (locked.value) document.exitPointerLock();
153
+ });
121
154
  </script>
122
155
 
123
156
  <template>
@@ -142,6 +175,36 @@ onUnmounted(() => stopGpu?.());
142
175
  <canvas ref="surface" class="canvas" :width="W * dpr" :height="H * dpr" />
143
176
  <p class="faint">A WGSL fragment shader, redrawn every frame with the time in a uniform buffer.</p>
144
177
  </Card>
178
+
179
+ <Card title="Masks" api="mask-image">
180
+ <div class="row">
181
+ <span
182
+ v-for="(name, i) in maskIcons"
183
+ :key="name"
184
+ class="mask-icon"
185
+ :style="{ maskImage: iconMask(name), color: tints[i] }"
186
+ />
187
+ <div class="fade">
188
+ <p v-for="n in 4" :key="n">Line {{ n }} of text under a gradient mask that fades it out.</p>
189
+ </div>
190
+ </div>
191
+ <p class="faint">SVG icons masking a currentColor background, and a gradient that fades the text out.</p>
192
+ </Card>
193
+
194
+ <Card title="Pointer lock" api="requestPointerLock()">
195
+ <div ref="stage" class="stage" :class="{ locked }" @click="lock" @mousemove="look">
196
+ <div class="cube" :style="{ transform: `rotate(${spin.y}deg) skewX(${spin.x / 4}deg)` }">
197
+ <div class="face" />
198
+ </div>
199
+ <span class="hint">{{ locked ? "Move the mouse to turn the shape" : "Click to lock the pointer" }}</span>
200
+ </div>
201
+ <div class="row">
202
+ <span class="badge" :class="{ on: locked }">{{ locked ? "Locked" : "Not locked" }}</span>
203
+ <span class="faint">Esc releases the pointer</span>
204
+ <span class="faint mono">{{ Math.round(travelled) }} px of movement</span>
205
+ </div>
206
+ <p v-if="lockError" class="faint">{{ lockError }}</p>
207
+ </Card>
145
208
  </Page>
146
209
  </template>
147
210
 
@@ -151,4 +214,63 @@ onUnmounted(() => stopGpu?.());
151
214
  height: 220px;
152
215
  border-radius: 10px;
153
216
  }
217
+ .mask-icon {
218
+ width: 32px;
219
+ height: 32px;
220
+ background: currentColor;
221
+ mask-size: contain;
222
+ mask-repeat: no-repeat;
223
+ mask-position: center;
224
+ }
225
+ .fade {
226
+ margin-left: 12px;
227
+ font-size: 13px;
228
+ line-height: 18px;
229
+ mask-image: linear-gradient(to bottom, #000 40%, transparent);
230
+ }
231
+ .stage {
232
+ position: relative;
233
+ width: 640px;
234
+ height: 180px;
235
+ border-radius: 10px;
236
+ border: 1px solid var(--line);
237
+ background: radial-gradient(circle at 50% 40%, #1f1b3a, #121218);
238
+ display: flex;
239
+ align-items: center;
240
+ justify-content: center;
241
+ cursor: pointer;
242
+ }
243
+ .stage.locked {
244
+ border-color: var(--accent);
245
+ }
246
+ .cube {
247
+ width: 72px;
248
+ height: 72px;
249
+ }
250
+ .face {
251
+ width: 100%;
252
+ height: 100%;
253
+ border-radius: 14px;
254
+ background: linear-gradient(135deg, var(--accent), var(--accent-strong));
255
+ box-shadow: 0 10px 30px #6d7cff55;
256
+ }
257
+ .hint {
258
+ position: absolute;
259
+ left: 14px;
260
+ bottom: 10px;
261
+ font-size: 12px;
262
+ color: var(--text-faint);
263
+ }
264
+ .badge {
265
+ padding: 2px 8px;
266
+ border-radius: 999px;
267
+ font-size: 12px;
268
+ border: 1px solid var(--line-strong);
269
+ color: var(--text-faint);
270
+ }
271
+ .badge.on {
272
+ color: var(--text);
273
+ border-color: var(--accent);
274
+ background: var(--accent-soft);
275
+ }
154
276
  </style>
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { ref, shallowRef } from "vue";
2
+ import { nextTick, ref, shallowRef } from "vue";
3
3
  import Card from "../components/Card.vue";
4
4
  import Page from "../components/Page.vue";
5
5
 
@@ -26,6 +26,20 @@ const shown = ref(true);
26
26
  const words = ["Native", "Fast", "Small", "Vue"];
27
27
  const word = ref(0);
28
28
  const nextWord = () => (word.value = (word.value + 1) % words.length);
29
+
30
+ const tiles = [
31
+ { name: "Dusk", fill: "linear-gradient(135deg, #8b9dff, #b48cff)", text: "Violet light after sundown." },
32
+ { name: "Tide", fill: "linear-gradient(135deg, #38bdf8, #2dd4bf)", text: "Cool water over pale sand." },
33
+ { name: "Ember", fill: "linear-gradient(135deg, #fb923c, #f43f5e)", text: "The last coals of a fire." },
34
+ { name: "Moss", fill: "linear-gradient(135deg, #a3e635, #22c55e)", text: "Green on a north-facing stone." },
35
+ ];
36
+ const open = ref<number | null>(null);
37
+ const opened = () => tiles[open.value ?? 0]!;
38
+ const show = (i: number | null) =>
39
+ document.startViewTransition(async () => {
40
+ open.value = i;
41
+ await nextTick();
42
+ });
29
43
  </script>
30
44
 
31
45
  <template>
@@ -67,6 +81,26 @@ const nextWord = () => (word.value = (word.value + 1) % words.length);
67
81
  <div :key="word" class="word">{{ words[word] }}</div>
68
82
  </Transition>
69
83
  </Card>
84
+
85
+ <Card title="View transitions" api="document.startViewTransition()">
86
+ <div v-if="open === null" class="tiles">
87
+ <div
88
+ v-for="(tile, i) in tiles"
89
+ :key="tile.name"
90
+ class="tile"
91
+ :style="{ background: tile.fill, viewTransitionName: `tile-${i}` }"
92
+ @click="show(i)"
93
+ >
94
+ <span class="tile-name" :style="{ viewTransitionName: `tile-name-${i}` }">{{ tile.name }}</span>
95
+ </div>
96
+ </div>
97
+ <div v-else class="detail" @click="show(null)">
98
+ <div class="hero" :style="{ background: opened().fill, viewTransitionName: `tile-${open}` }">
99
+ <span class="hero-name" :style="{ viewTransitionName: `tile-name-${open}` }">{{ opened().name }}</span>
100
+ </div>
101
+ <p class="muted">{{ opened().text }} Click to go back.</p>
102
+ </div>
103
+ </Card>
70
104
  </Page>
71
105
  </template>
72
106
 
@@ -196,4 +230,40 @@ const nextWord = () => (word.value = (word.value + 1) % words.length);
196
230
  opacity: 0;
197
231
  transform: translateY(-10px);
198
232
  }
233
+ .tiles {
234
+ display: grid;
235
+ grid-template-columns: repeat(4, 1fr);
236
+ gap: 10px;
237
+ }
238
+ .tile {
239
+ height: 72px;
240
+ display: flex;
241
+ align-items: flex-end;
242
+ padding: 10px;
243
+ border-radius: 12px;
244
+ cursor: pointer;
245
+ }
246
+ .tile-name {
247
+ font-size: 13px;
248
+ font-weight: 600;
249
+ color: #ffffff;
250
+ }
251
+ .detail {
252
+ display: flex;
253
+ flex-direction: column;
254
+ gap: 10px;
255
+ cursor: pointer;
256
+ }
257
+ .hero {
258
+ height: 180px;
259
+ display: flex;
260
+ align-items: flex-end;
261
+ padding: 18px;
262
+ border-radius: 18px;
263
+ }
264
+ .hero-name {
265
+ font-size: 28px;
266
+ font-weight: 700;
267
+ color: #ffffff;
268
+ }
199
269
  </style>