@skathi-native/cli 0.0.0 → 0.1.0-beta.2

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 (81) hide show
  1. package/aot-inputs.ts +294 -0
  2. package/ascii.ts +397 -0
  3. package/build.ts +1236 -0
  4. package/check/builtins.json +1219 -0
  5. package/check/builtins.ts +112 -0
  6. package/check/codes.ts +178 -0
  7. package/check/command.ts +105 -0
  8. package/check/config.ts +76 -0
  9. package/check/finding.ts +30 -0
  10. package/check/graph.ts +69 -0
  11. package/check/highlight.ts +40 -0
  12. package/check/index.ts +308 -0
  13. package/check/packages.ts +54 -0
  14. package/check/program.ts +209 -0
  15. package/check/report.ts +219 -0
  16. package/check/rules.ts +307 -0
  17. package/check/schema.ts +69 -0
  18. package/check/typing.ts +703 -0
  19. package/cli/assets.ts +114 -0
  20. package/cli/build-app.ts +587 -0
  21. package/cli/config.ts +646 -0
  22. package/cli/create.ts +327 -0
  23. package/cli/dev.ts +92 -0
  24. package/cli/elf.ts +142 -0
  25. package/cli/help.ts +160 -0
  26. package/cli/host-fetch.ts +178 -0
  27. package/cli/host.ts +378 -0
  28. package/cli/icon.ts +303 -0
  29. package/cli/macos-bundle.ts +451 -0
  30. package/cli/pe.ts +429 -0
  31. package/cli/platform.ts +74 -0
  32. package/cli/sk.ts +290 -0
  33. package/cli/skpk.ts +268 -0
  34. package/cli/stamp.ts +254 -0
  35. package/cli/term.ts +176 -0
  36. package/cli/versioninfo.ts +123 -0
  37. package/css-prefixes.ts +118 -0
  38. package/devtools/apps.ts +68 -0
  39. package/devtools/commands.ts +860 -0
  40. package/devtools/ctl.ts +166 -0
  41. package/package.json +52 -3
  42. package/prod.ts +701 -0
  43. package/runtime-path.ts +24 -0
  44. package/tailwind.ts +76 -0
  45. package/templates/minimal/assets/hello.txt +1 -0
  46. package/templates/minimal/src/App.vue +142 -0
  47. package/templates/minimal/src/main.ts +4 -0
  48. package/templates/showcase/assets/hello.txt +1 -0
  49. package/templates/showcase/assets/media/aurora.png +0 -0
  50. package/templates/showcase/assets/media/clip.mp4 +0 -0
  51. package/templates/showcase/assets/media/sticker.tgs +0 -0
  52. package/templates/showcase/src/App.vue +128 -0
  53. package/templates/showcase/src/components/Card.vue +41 -0
  54. package/templates/showcase/src/components/Icon.vue +29 -0
  55. package/templates/showcase/src/components/Missing.vue +26 -0
  56. package/templates/showcase/src/components/Page.vue +41 -0
  57. package/templates/showcase/src/components/Titlebar.vue +128 -0
  58. package/templates/showcase/src/engine.ts +33 -0
  59. package/templates/showcase/src/icons.ts +22 -0
  60. package/templates/showcase/src/main.ts +7 -0
  61. package/templates/showcase/src/pages/AudioPage.vue +124 -0
  62. package/templates/showcase/src/pages/FilesPage.vue +91 -0
  63. package/templates/showcase/src/pages/FormsPage.vue +139 -0
  64. package/templates/showcase/src/pages/GraphicsPage.vue +156 -0
  65. package/templates/showcase/src/pages/HomePage.vue +141 -0
  66. package/templates/showcase/src/pages/LocalePage.vue +71 -0
  67. package/templates/showcase/src/pages/MediaPage.vue +85 -0
  68. package/templates/showcase/src/pages/MotionPage.vue +199 -0
  69. package/templates/showcase/src/pages/NetworkPage.vue +103 -0
  70. package/templates/showcase/src/pages/PermissionsPage.vue +80 -0
  71. package/templates/showcase/src/pages/StoragePage.vue +117 -0
  72. package/templates/showcase/src/pages/StylesPage.vue +199 -0
  73. package/templates/showcase/src/pages/SystemPage.vue +89 -0
  74. package/templates/showcase/src/pages/TrayPage.vue +66 -0
  75. package/templates/showcase/src/pages/WindowPage.vue +128 -0
  76. package/templates/showcase/src/product.ts +2 -0
  77. package/templates/showcase/src/router.ts +149 -0
  78. package/templates/showcase/src/stores/counter.ts +9 -0
  79. package/templates/showcase/src/stores/desktop.ts +115 -0
  80. package/templates/showcase/src/styles.css +140 -0
  81. package/vitecompat.ts +1151 -0
@@ -0,0 +1,22 @@
1
+ // 24×24 stroke paths, drawn with `stroke="currentColor"` so an icon takes its colour from the text.
2
+ export const icons = {
3
+ home: "M3 10.5 12 3l9 7.5V21h-6v-6H9v6H3z",
4
+ window: "M3 5h18v14H3z M3 9h18 M6 7h.01",
5
+ tray: "M6 17V10a6 6 0 0 1 12 0v7 M4 17h16 M10 21h4",
6
+ files: "M6 2h8l5 5v15H6z M14 2v5h5 M9 13h6 M9 17h6",
7
+ storage:
8
+ "M4 6c0-1.7 3.6-3 8-3s8 1.3 8 3-3.6 3-8 3-8-1.3-8-3z M4 6v12c0 1.7 3.6 3 8 3s8-1.3 8-3V6 M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3",
9
+ network: "M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18z M3 12h18 M12 3c5 5 5 13 0 18 M12 3c-5 5-5 13 0 18",
10
+ media: "M3 5h18v14H3z M3 16l5-5 4 4 3-3 6 6 M16 9h.01",
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
+ graphics: "M12 3l9 16H3z M12 9v4",
13
+ 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
+ styles:
15
+ "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",
16
+ forms: "M4 7h16v10H4z M8 10v4 M17 4v3 M17 17v3",
17
+ locale: "M4 5h9 M8.5 3v2 M6 5c1 3 3.5 5.5 6.5 6.5 M11 5c-1 3.5-3.5 6.5-7 8 M13 21l4-9 4 9 M14.5 18h5",
18
+ permissions: "M12 3l8 3v6c0 4.5-3.4 8.3-8 9-4.6-.7-8-4.5-8-9V6z M9 12l2 2 4-4",
19
+ system: "M4 5h16v11H4z M8 20h8 M12 16v4 M8 9l2 2-2 2 M13 13h3",
20
+ } as const;
21
+
22
+ export type IconName = keyof typeof icons;
@@ -0,0 +1,7 @@
1
+ import { createApp } from "vue";
2
+ import { createPinia } from "pinia";
3
+ import App from "./App.vue";
4
+ import { router } from "./router";
5
+ import "./styles.css";
6
+
7
+ createApp(App).use(createPinia()).use(router).mount();
@@ -0,0 +1,124 @@
1
+ <script setup lang="ts">
2
+ import { onUnmounted, ref } from "vue";
3
+ import Card from "../components/Card.vue";
4
+ import Missing from "../components/Missing.vue";
5
+ import Page from "../components/Page.vue";
6
+ import { audio, everyFrame } from "../engine";
7
+
8
+ const NOTES = [
9
+ ["C", 261.63],
10
+ ["D", 293.66],
11
+ ["E", 329.63],
12
+ ["G", 392.0],
13
+ ["A", 440.0],
14
+ ["C", 523.25],
15
+ ["D", 587.33],
16
+ ["E", 659.25],
17
+ ] as const;
18
+ const WAVES = ["sine", "triangle", "square", "sawtooth"];
19
+ const BARS = 32;
20
+
21
+ const wave = ref("triangle");
22
+ const levels = ref<number[]>(Array.from({ length: BARS }, () => 0));
23
+
24
+ let engine: { ctx: SkAudioContext; tap: SkAnalyserNode; stop: () => void } | null = null;
25
+
26
+ // Created on the first note, so the audio device is not opened until something plays.
27
+ function start(Context: NonNullable<typeof audio>) {
28
+ const ctx = new Context();
29
+ const tap = ctx.createAnalyser();
30
+ tap.fftSize = 128;
31
+ tap.connect(ctx.destination);
32
+ const bins = new Uint8Array(tap.frequencyBinCount);
33
+ const stop = everyFrame(() => {
34
+ tap.getByteFrequencyData(bins);
35
+ levels.value = levels.value.map((_, i) => (bins[i] ?? 0) / 255);
36
+ });
37
+ return { ctx, tap, stop };
38
+ }
39
+
40
+ function play(frequency: number) {
41
+ if (!audio) return;
42
+ engine ??= start(audio);
43
+ const { ctx, tap } = engine;
44
+ const now = ctx.currentTime;
45
+ const osc = ctx.createOscillator();
46
+ const gain = ctx.createGain();
47
+ osc.type = wave.value;
48
+ osc.frequency.value = frequency;
49
+ gain.gain.setValueAtTime(0.0001, now);
50
+ gain.gain.exponentialRampToValueAtTime(0.3, now + 0.02);
51
+ gain.gain.exponentialRampToValueAtTime(0.0001, now + 1.2);
52
+ osc.connect(gain);
53
+ gain.connect(tap);
54
+ osc.start(now);
55
+ osc.stop(now + 1.25);
56
+ }
57
+
58
+ onUnmounted(() => {
59
+ engine?.stop();
60
+ engine?.ctx.suspend();
61
+ });
62
+ </script>
63
+
64
+ <template>
65
+ <Page title="Audio" lead="The Web Audio API on a native audio engine: oscillators, gain envelopes and an analyser.">
66
+ <Card v-if="audio" title="Synth" api="AudioContext">
67
+ <div class="keys">
68
+ <button v-for="([name, hz], i) in NOTES" :key="i" class="key" @mousedown="play(hz)">{{ name }}</button>
69
+ </div>
70
+ <div class="row">
71
+ <button v-for="w in WAVES" :key="w" class="btn" :class="{ on: wave === w }" @click="wave = w">{{ w }}</button>
72
+ </div>
73
+ <div class="spectrum">
74
+ <div v-for="(level, i) in levels" :key="i" class="bar" :style="{ height: `${4 + level * 96}px` }" />
75
+ </div>
76
+ </Card>
77
+ <Missing v-else part="audio" />
78
+ </Page>
79
+ </template>
80
+
81
+ <style scoped>
82
+ .keys {
83
+ display: flex;
84
+ gap: 6px;
85
+ }
86
+ .key {
87
+ flex: 1;
88
+ height: 120px;
89
+ display: flex;
90
+ align-items: flex-end;
91
+ justify-content: center;
92
+ padding-bottom: 12px;
93
+ border-radius: 10px;
94
+ border: 1px solid var(--line);
95
+ background: linear-gradient(180deg, #ffffff14, #ffffff06);
96
+ color: var(--text-muted);
97
+ font-size: 13px;
98
+ font-weight: 600;
99
+ cursor: pointer;
100
+ transition:
101
+ background-color 80ms ease,
102
+ transform 80ms ease;
103
+ }
104
+ .key:hover {
105
+ border-color: var(--line-strong);
106
+ color: var(--text);
107
+ }
108
+ .key:active {
109
+ transform: translateY(2px);
110
+ background: var(--accent-soft);
111
+ }
112
+ .spectrum {
113
+ height: 100px;
114
+ display: flex;
115
+ align-items: flex-end;
116
+ gap: 3px;
117
+ }
118
+ .bar {
119
+ flex: 1;
120
+ border-radius: 3px;
121
+ background: linear-gradient(0deg, var(--accent-strong), #b48cff);
122
+ transition: height 60ms linear;
123
+ }
124
+ </style>
@@ -0,0 +1,91 @@
1
+ <script setup lang="ts">
2
+ import { ref, shallowRef } from "vue";
3
+ import Card from "../components/Card.vue";
4
+ import Missing from "../components/Missing.vue";
5
+ import Page from "../components/Page.vue";
6
+ import { clipboard, describe } from "../engine";
7
+
8
+ // The File System Access API: a picker needs a click, and a handle names its file but never shows its path.
9
+ const TYPES = [{ description: "Text", accept: { "text/plain": [".txt", ".md", ".log"] } }];
10
+
11
+ const text = ref("Write something, then save it.\n");
12
+ const file = shallowRef<SkFileSystemFileHandle | null>(null);
13
+ const status = ref("");
14
+
15
+ async function attempt(action: () => Promise<string>) {
16
+ try {
17
+ status.value = await action();
18
+ } catch (e) {
19
+ status.value = describe(e);
20
+ }
21
+ }
22
+
23
+ async function write(handle: SkFileSystemFileHandle) {
24
+ const stream = await handle.createWritable();
25
+ await stream.write(text.value);
26
+ await stream.close();
27
+ }
28
+
29
+ const open = () =>
30
+ attempt(async () => {
31
+ const [handle] = await showOpenFilePicker({ id: "notes", types: TYPES });
32
+ if (!handle) return "";
33
+ text.value = await (await handle.getFile()).text();
34
+ file.value = handle;
35
+ return `Opened ${handle.name}`;
36
+ });
37
+
38
+ const save = () =>
39
+ attempt(async () => {
40
+ const handle = file.value ?? (await showSaveFilePicker({ id: "notes", suggestedName: "notes.txt", types: TYPES }));
41
+ await write(handle);
42
+ file.value = handle;
43
+ return `Saved ${handle.name}`;
44
+ });
45
+
46
+ type Clipboard = SkNavigator["clipboard"];
47
+
48
+ const copy = (board: Clipboard) =>
49
+ attempt(async () => {
50
+ await board.writeText(text.value);
51
+ return "Copied to the clipboard";
52
+ });
53
+
54
+ const paste = (board: Clipboard) =>
55
+ attempt(async () => {
56
+ text.value = await board.readText();
57
+ return "Pasted from the clipboard";
58
+ });
59
+ </script>
60
+
61
+ <template>
62
+ <Page title="Files" lead="Native open and save dialogs through the web's own APIs, and the system clipboard.">
63
+ <Card title="Editor" :api="file ? file.name : 'untitled'">
64
+ <textarea v-model="text" class="input editor" spellcheck="false" />
65
+ <div class="row">
66
+ <button class="btn" @click="open">Open…</button>
67
+ <button class="btn primary" @click="save">{{ file ? "Save" : "Save as…" }}</button>
68
+ <button v-if="file" class="btn" @click="file = null">Forget the file</button>
69
+ <span class="faint">{{ status }}</span>
70
+ </div>
71
+ </Card>
72
+
73
+ <Card title="Clipboard" api="navigator.clipboard">
74
+ <div v-if="clipboard" class="row">
75
+ <button class="btn" @click="copy(clipboard)">Copy the text</button>
76
+ <button class="btn" @click="paste(clipboard)">Paste over it</button>
77
+ </div>
78
+ <Missing v-else part="clipboard" />
79
+ <p class="faint">Ctrl+C and Ctrl+V in text fields work either way: they belong to the field.</p>
80
+ </Card>
81
+ </Page>
82
+ </template>
83
+
84
+ <style scoped>
85
+ .editor {
86
+ height: 220px;
87
+ padding: 12px;
88
+ font-family: var(--mono);
89
+ line-height: 19px;
90
+ }
91
+ </style>
@@ -0,0 +1,139 @@
1
+ <script setup lang="ts">
2
+ import { onMounted, onUnmounted, ref } from "vue";
3
+ import Card from "../components/Card.vue";
4
+ import Page from "../components/Page.vue";
5
+ import { dom } from "../engine";
6
+
7
+ const name = ref("");
8
+ const plan = ref("team");
9
+ const seats = ref(5);
10
+ const yearly = ref(true);
11
+ const notes = ref("");
12
+ const price = () => seats.value * (plan.value === "team" ? 8 : 15) * (yearly.value ? 10 : 1);
13
+
14
+ // Selection is the document's, as in a browser: drag over the paragraph, or double-click a word.
15
+ const selected = ref("");
16
+ const onSelection = () => (selected.value = getSelection()?.toString() ?? "");
17
+ onMounted(() => dom.addEventListener("selectionchange", onSelection));
18
+ onUnmounted(() => dom.removeEventListener("selectionchange", onSelection));
19
+ </script>
20
+
21
+ <template>
22
+ <Page title="Forms" lead="Native text editing with IME, undo and the system caret, driven by plain v-model.">
23
+ <Card title="Controls" api="v-model">
24
+ <div class="form">
25
+ <label class="field">
26
+ <span class="label">Name</span>
27
+ <input v-model="name" class="input" placeholder="Ada Lovelace" />
28
+ </label>
29
+ <label class="field">
30
+ <span class="label">Plan</span>
31
+ <select v-model="plan" class="input">
32
+ <option value="team">Team</option>
33
+ <option value="business">Business</option>
34
+ </select>
35
+ </label>
36
+ <label class="field">
37
+ <span class="label">Seats · {{ seats }}</span>
38
+ <input v-model.number="seats" type="range" min="1" max="50" />
39
+ </label>
40
+ <div class="check">
41
+ <button
42
+ class="switch"
43
+ :class="{ on: yearly }"
44
+ role="switch"
45
+ :aria-checked="yearly"
46
+ aria-label="Pay yearly"
47
+ @click="yearly = !yearly"
48
+ >
49
+ <span class="knob" />
50
+ </button>
51
+ <span>Pay yearly (two months free)</span>
52
+ </div>
53
+ <label class="field">
54
+ <span class="label">Notes</span>
55
+ <textarea v-model="notes" class="input notes" placeholder="Enter adds a line" />
56
+ </label>
57
+ </div>
58
+ <div class="summary">
59
+ {{ name || "Someone" }} · {{ plan }} · {{ seats }} seats · ${{ price() }} per {{ yearly ? "year" : "month" }}
60
+ </div>
61
+ </Card>
62
+
63
+ <Card title="Text selection" api="getSelection()">
64
+ <p class="prose">
65
+ Text in a Skathi window is selectable like text on a web page. Drag across this paragraph, double-click a word
66
+ or press Ctrl+A, then Ctrl+C: the selection goes to the system clipboard.
67
+ </p>
68
+ <p class="faint">Selected: {{ selected || "nothing" }}</p>
69
+ <p class="prose locked">user-select: none keeps this line out of every selection.</p>
70
+ </Card>
71
+ </Page>
72
+ </template>
73
+
74
+ <style scoped>
75
+ .form {
76
+ display: flex;
77
+ flex-direction: column;
78
+ gap: 14px;
79
+ max-width: 420px;
80
+ }
81
+ .field {
82
+ display: flex;
83
+ flex-direction: column;
84
+ gap: 6px;
85
+ }
86
+ .label {
87
+ font-size: 12px;
88
+ color: var(--text-faint);
89
+ }
90
+ .check {
91
+ display: flex;
92
+ align-items: center;
93
+ gap: 10px;
94
+ font-size: 13px;
95
+ }
96
+ .switch {
97
+ display: flex;
98
+ width: 36px;
99
+ height: 20px;
100
+ padding: 2px;
101
+ border-radius: 10px;
102
+ background: var(--surface-strong);
103
+ cursor: pointer;
104
+ transition: background-color 160ms ease;
105
+ }
106
+ .switch.on {
107
+ background: var(--accent-strong);
108
+ }
109
+ .knob {
110
+ width: 16px;
111
+ height: 16px;
112
+ border-radius: 8px;
113
+ background: #ffffff;
114
+ transition: margin-left 160ms ease;
115
+ }
116
+ .switch.on .knob {
117
+ margin-left: 16px;
118
+ }
119
+ .notes {
120
+ height: 80px;
121
+ padding: 8px 12px;
122
+ }
123
+ .summary {
124
+ padding: 12px;
125
+ border-radius: 10px;
126
+ background: var(--accent-soft);
127
+ font-size: 13px;
128
+ }
129
+ .prose {
130
+ margin: 0;
131
+ font-size: 14px;
132
+ line-height: 22px;
133
+ color: var(--text);
134
+ }
135
+ .locked {
136
+ user-select: none;
137
+ color: var(--text-faint);
138
+ }
139
+ </style>
@@ -0,0 +1,156 @@
1
+ <script setup lang="ts">
2
+ import { onMounted, onUnmounted, ref, shallowRef } from "vue";
3
+ import Card from "../components/Card.vue";
4
+ import Missing from "../components/Missing.vue";
5
+ import Page from "../components/Page.vue";
6
+ import { describe, everyFrame, gpu } from "../engine";
7
+
8
+ const W = 640;
9
+ const H = 220;
10
+ const dpr = devicePixelRatio;
11
+
12
+ const pad = shallowRef<SkCanvasElement | null>(null);
13
+ let ctx: SkCanvas2D | null = null;
14
+ let last: { x: number; y: number } | null = null;
15
+ let hue = 220;
16
+
17
+ function clear() {
18
+ if (!ctx) return;
19
+ const bg = ctx.createLinearGradient(0, 0, W, H);
20
+ bg.addColorStop(0, "#14141c");
21
+ bg.addColorStop(1, "#1c1630");
22
+ ctx.fillStyle = bg;
23
+ ctx.fillRect(0, 0, W, H);
24
+ ctx.fillStyle = "#ffffff40";
25
+ ctx.font = "13px Segoe UI";
26
+ ctx.fillText("Drag to draw", 16, 26);
27
+ }
28
+
29
+ const at = (e: SkMouseEvent) => {
30
+ const rect = pad.value!.getBoundingClientRect();
31
+ return { x: e.clientX - rect.left, y: e.clientY - rect.top };
32
+ };
33
+ const down = (e: SkMouseEvent) => (last = at(e));
34
+ const up = () => (last = null);
35
+ function move(e: SkMouseEvent) {
36
+ if (!ctx || !last) return;
37
+ const next = at(e);
38
+ hue = (hue + 2) % 360;
39
+ ctx.strokeStyle = `hsl(${hue}, 90%, 68%)`;
40
+ ctx.lineWidth = 6;
41
+ ctx.lineCap = "round";
42
+ ctx.beginPath();
43
+ ctx.moveTo(last.x, last.y);
44
+ ctx.lineTo(next.x, next.y);
45
+ ctx.stroke();
46
+ last = next;
47
+ }
48
+
49
+ onMounted(() => {
50
+ ctx = pad.value?.getContext("2d") ?? null;
51
+ ctx?.scale(dpr, dpr);
52
+ clear();
53
+ });
54
+
55
+ const SHADER = /* wgsl */ `
56
+ struct Uniforms { time: f32, aspect: f32 }
57
+ @group(0) @binding(0) var<uniform> u: Uniforms;
58
+
59
+ struct Varying { @builtin(position) position: vec4f, @location(0) uv: vec2f }
60
+
61
+ @vertex fn vs(@builtin(vertex_index) i: u32) -> Varying {
62
+ var corners = array<vec2f, 3>(vec2f(-1.0, -3.0), vec2f(-1.0, 1.0), vec2f(3.0, 1.0));
63
+ var out: Varying;
64
+ out.position = vec4f(corners[i], 0.0, 1.0);
65
+ out.uv = corners[i] * 0.5 + 0.5;
66
+ return out;
67
+ }
68
+
69
+ @fragment fn fs(v: Varying) -> @location(0) vec4f {
70
+ let p = (v.uv - 0.5) * vec2f(u.aspect, 1.0) * 6.0;
71
+ let t = u.time;
72
+ let w = sin(p.x + t) + sin(p.y * 1.3 - t * 0.8) + sin(length(p) * 1.5 - t * 1.2);
73
+ let c = 0.5 + 0.5 * cos(vec3f(0.0, 2.1, 4.2) + w + t * 0.3);
74
+ return vec4f(c * vec3f(0.55, 0.6, 1.0), 1.0);
75
+ }`;
76
+
77
+ const surface = shallowRef<SkCanvasElement | null>(null);
78
+ const adapterName = ref("");
79
+ let stopGpu: (() => void) | null = null;
80
+
81
+ async function startGpu(api: SkGPU, canvas: SkCanvasElement) {
82
+ const adapter = await api.requestAdapter();
83
+ const context = canvas.getContext("webgpu");
84
+ if (!adapter || !context || !GPUBufferUsage) throw new Error("No GPU adapter for WebGPU on this machine");
85
+ adapterName.value = adapter.info.description;
86
+ const device = await adapter.requestDevice();
87
+ const format = api.getPreferredCanvasFormat();
88
+ context.configure({ device, format, alphaMode: "opaque" });
89
+ const module = device.createShaderModule({ code: SHADER });
90
+ const pipeline = device.createRenderPipeline({
91
+ layout: "auto",
92
+ vertex: { module, entryPoint: "vs" },
93
+ fragment: { module, entryPoint: "fs", targets: [{ format }] },
94
+ });
95
+ const uniforms = device.createBuffer({ size: 16, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST });
96
+ const bindings = device.createBindGroup({
97
+ layout: pipeline.getBindGroupLayout(0),
98
+ entries: [{ binding: 0, resource: { buffer: uniforms } }],
99
+ });
100
+ const stop = everyFrame((time) => {
101
+ device.queue.writeBuffer(uniforms, 0, new Float32Array([time / 1000, W / H, 0, 0]));
102
+ const encoder = device.createCommandEncoder();
103
+ const pass = encoder.beginRenderPass({
104
+ colorAttachments: [{ view: context.getCurrentTexture().createView(), loadOp: "clear", storeOp: "store" }],
105
+ });
106
+ pass.setPipeline(pipeline);
107
+ pass.setBindGroup(0, bindings);
108
+ pass.draw(3);
109
+ pass.end();
110
+ device.queue.submit([encoder.finish()]);
111
+ });
112
+ stopGpu = () => {
113
+ stop();
114
+ device.destroy();
115
+ };
116
+ }
117
+
118
+ onMounted(() => {
119
+ if (gpu && surface.value) startGpu(gpu, surface.value).catch((e: unknown) => (adapterName.value = describe(e)));
120
+ });
121
+ onUnmounted(() => stopGpu?.());
122
+ </script>
123
+
124
+ <template>
125
+ <Page title="Graphics" lead="Canvas 2D and WebGPU draw into the same GPU-composited tree as the rest of the page.">
126
+ <Card title="Canvas 2D" api="getContext('2d')">
127
+ <canvas
128
+ ref="pad"
129
+ class="canvas"
130
+ :width="W * dpr"
131
+ :height="H * dpr"
132
+ @mousedown="down"
133
+ @mousemove="move"
134
+ @mouseup="up"
135
+ @mouseleave="up"
136
+ />
137
+ <div class="row">
138
+ <button class="btn" @click="clear">Clear</button>
139
+ </div>
140
+ </Card>
141
+
142
+ <Card title="WebGPU" :api="adapterName || 'navigator.gpu'">
143
+ <canvas v-if="gpu" ref="surface" class="canvas" :width="W * dpr" :height="H * dpr" />
144
+ <Missing v-else part="webgpu" />
145
+ <p class="faint">A WGSL fragment shader, redrawn every frame with the time in a uniform buffer.</p>
146
+ </Card>
147
+ </Page>
148
+ </template>
149
+
150
+ <style scoped>
151
+ .canvas {
152
+ width: 640px;
153
+ height: 220px;
154
+ border-radius: 10px;
155
+ }
156
+ </style>
@@ -0,0 +1,141 @@
1
+ <script setup lang="ts">
2
+ import { onMounted, ref } from "vue";
3
+ import Icon from "../components/Icon.vue";
4
+ import { http } from "../engine";
5
+ import { productName } from "../product";
6
+ import { pages } from "../router";
7
+ import { useCounter } from "../stores/counter";
8
+
9
+ const counter = useCounter();
10
+ const features = pages.filter((p) => p.blurb);
11
+
12
+ // A relative URL resolves against the app root in dev and against the packaged assets in a build.
13
+ const greeting = ref("");
14
+ onMounted(async () => {
15
+ const res = await http("assets/hello.txt");
16
+ if (res.ok) greeting.value = (await res.text()).trim();
17
+ });
18
+ </script>
19
+
20
+ <template>
21
+ <section class="home">
22
+ <div class="hero">
23
+ <div class="logo">{{ productName.charAt(0) }}</div>
24
+ <h1 class="title">{{ productName }}</h1>
25
+ <p class="lead">
26
+ Vue 3 on a native GPU renderer, with no browser inside. Every page in the sidebar shows one part of Skathi in a
27
+ few lines of code; open <span class="mono">src/pages</span> next to it and change things while
28
+ <span class="mono">sk dev</span> runs.
29
+ </p>
30
+ <div class="row">
31
+ <button class="btn primary" @click="counter.increment()">Count up · {{ counter.count }}</button>
32
+ <button class="btn" :disabled="counter.count === 0" @click="counter.reset()">Reset</button>
33
+ </div>
34
+ <p class="faint">
35
+ The count is a pinia store: the pop-out window, the tray menu and the global hotkey all change the same one.
36
+ </p>
37
+ <p v-if="greeting" class="faint">{{ greeting }}</p>
38
+ </div>
39
+
40
+ <div class="grid">
41
+ <RouterLink v-for="page in features" :key="page.path" :to="page.path" class="feature">
42
+ <span class="badge"><Icon :name="page.icon" /></span>
43
+ <span class="name">{{ page.title }}</span>
44
+ <span class="blurb">{{ page.blurb }}</span>
45
+ </RouterLink>
46
+ </div>
47
+ </section>
48
+ </template>
49
+
50
+ <style scoped>
51
+ .home {
52
+ display: flex;
53
+ flex-direction: column;
54
+ gap: 32px;
55
+ padding: 40px 32px;
56
+ }
57
+ .hero {
58
+ display: flex;
59
+ flex-direction: column;
60
+ align-items: center;
61
+ gap: 14px;
62
+ text-align: center;
63
+ }
64
+ .logo {
65
+ width: 72px;
66
+ height: 72px;
67
+ border-radius: 20px;
68
+ display: flex;
69
+ align-items: center;
70
+ justify-content: center;
71
+ background: linear-gradient(135deg, var(--accent), #b48cff);
72
+ box-shadow: 0 14px 36px #6d7cff55;
73
+ color: #ffffff;
74
+ font-size: 34px;
75
+ font-weight: 700;
76
+ animation: float 5s ease-in-out infinite;
77
+ }
78
+ @keyframes float {
79
+ 50% {
80
+ transform: translateY(-6px);
81
+ }
82
+ }
83
+ .title {
84
+ margin: 0;
85
+ font-size: 32px;
86
+ font-weight: 700;
87
+ }
88
+ .lead {
89
+ margin: 0;
90
+ max-width: 560px;
91
+ font-size: 14px;
92
+ line-height: 22px;
93
+ color: var(--text-muted);
94
+ }
95
+ .grid {
96
+ display: flex;
97
+ flex-wrap: wrap;
98
+ justify-content: center;
99
+ gap: 12px;
100
+ }
101
+ .feature {
102
+ width: 220px;
103
+ display: flex;
104
+ flex-direction: column;
105
+ gap: 6px;
106
+ padding: 16px;
107
+ border-radius: var(--radius);
108
+ border: 1px solid var(--line);
109
+ background: var(--surface);
110
+ cursor: pointer;
111
+ transition:
112
+ background-color 150ms ease,
113
+ border-color 150ms ease,
114
+ transform 150ms ease;
115
+ }
116
+ .feature:hover {
117
+ background: var(--surface-hover);
118
+ border-color: var(--line-strong);
119
+ transform: translateY(-2px);
120
+ }
121
+ .badge {
122
+ width: 30px;
123
+ height: 30px;
124
+ border-radius: 9px;
125
+ display: flex;
126
+ align-items: center;
127
+ justify-content: center;
128
+ background: var(--accent-soft);
129
+ color: var(--accent);
130
+ }
131
+ .name {
132
+ font-size: 14px;
133
+ font-weight: 600;
134
+ color: var(--text);
135
+ }
136
+ .blurb {
137
+ font-size: 12px;
138
+ line-height: 17px;
139
+ color: var(--text-muted);
140
+ }
141
+ </style>