@skathi-native/cli 0.1.0-beta.1 → 0.1.0-beta.3

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 (53) hide show
  1. package/aot/host-globals.json +105 -0
  2. package/aot/native.ts +142 -0
  3. package/aot/pin.ts +67 -0
  4. package/aot/toolchain.lock.json +17 -0
  5. package/aot/transform.ts +69 -0
  6. package/cli/aot-build.ts +189 -0
  7. package/cli/build-app.ts +67 -25
  8. package/cli/config.ts +44 -101
  9. package/cli/create.ts +107 -234
  10. package/cli/help.ts +159 -0
  11. package/cli/host-fetch.ts +87 -48
  12. package/cli/host.ts +18 -8
  13. package/cli/sk.ts +35 -110
  14. package/cli/skpk.ts +4 -0
  15. package/package.json +4 -2
  16. package/templates/icon.png +0 -0
  17. package/templates/minimal/.vscode/settings.json +3 -0
  18. package/templates/minimal/assets/hello.txt +1 -0
  19. package/templates/minimal/src/App.vue +142 -0
  20. package/templates/minimal/src/main.ts +4 -0
  21. package/templates/showcase/.vscode/settings.json +3 -0
  22. package/templates/showcase/assets/hello.txt +1 -0
  23. package/templates/showcase/assets/media/aurora.png +0 -0
  24. package/templates/showcase/assets/media/clip.mp4 +0 -0
  25. package/templates/showcase/assets/media/sticker.tgs +0 -0
  26. package/templates/showcase/src/App.vue +128 -0
  27. package/templates/showcase/src/components/Card.vue +41 -0
  28. package/templates/showcase/src/components/Icon.vue +29 -0
  29. package/templates/showcase/src/components/Page.vue +41 -0
  30. package/templates/showcase/src/components/Titlebar.vue +132 -0
  31. package/templates/showcase/src/engine.ts +10 -0
  32. package/templates/showcase/src/icons.ts +22 -0
  33. package/templates/showcase/src/main.ts +7 -0
  34. package/templates/showcase/src/pages/AudioPage.vue +121 -0
  35. package/templates/showcase/src/pages/FilesPage.vue +87 -0
  36. package/templates/showcase/src/pages/FormsPage.vue +138 -0
  37. package/templates/showcase/src/pages/GraphicsPage.vue +154 -0
  38. package/templates/showcase/src/pages/HomePage.vue +140 -0
  39. package/templates/showcase/src/pages/LocalePage.vue +71 -0
  40. package/templates/showcase/src/pages/MediaPage.vue +85 -0
  41. package/templates/showcase/src/pages/MotionPage.vue +199 -0
  42. package/templates/showcase/src/pages/NetworkPage.vue +104 -0
  43. package/templates/showcase/src/pages/PermissionsPage.vue +80 -0
  44. package/templates/showcase/src/pages/StoragePage.vue +104 -0
  45. package/templates/showcase/src/pages/StylesPage.vue +199 -0
  46. package/templates/showcase/src/pages/SystemPage.vue +89 -0
  47. package/templates/showcase/src/pages/TrayPage.vue +66 -0
  48. package/templates/showcase/src/pages/WindowPage.vue +128 -0
  49. package/templates/showcase/src/product.ts +2 -0
  50. package/templates/showcase/src/router.ts +149 -0
  51. package/templates/showcase/src/stores/counter.ts +9 -0
  52. package/templates/showcase/src/stores/desktop.ts +115 -0
  53. package/templates/showcase/src/styles.css +140 -0
@@ -0,0 +1,87 @@
1
+ <script setup lang="ts">
2
+ import { ref, shallowRef } from "vue";
3
+ import Card from "../components/Card.vue";
4
+ import Page from "../components/Page.vue";
5
+ import { describe } from "../engine";
6
+
7
+ // The File System Access API: a picker needs a click, and a handle names its file but never shows its path.
8
+ const TYPES = [{ description: "Text", accept: { "text/plain": [".txt", ".md", ".log"] } }];
9
+
10
+ const text = ref("Write something, then save it.\n");
11
+ const file = shallowRef<FileSystemFileHandle | null>(null);
12
+ const status = ref("");
13
+
14
+ async function attempt(action: () => Promise<string>) {
15
+ try {
16
+ status.value = await action();
17
+ } catch (e) {
18
+ status.value = describe(e);
19
+ }
20
+ }
21
+
22
+ async function write(handle: FileSystemFileHandle) {
23
+ const stream = await handle.createWritable();
24
+ await stream.write(text.value);
25
+ await stream.close();
26
+ }
27
+
28
+ const open = () =>
29
+ attempt(async () => {
30
+ const [handle] = await showOpenFilePicker({ id: "notes", types: TYPES });
31
+ if (!handle) return "";
32
+ text.value = await (await handle.getFile()).text();
33
+ file.value = handle;
34
+ return `Opened ${handle.name}`;
35
+ });
36
+
37
+ const save = () =>
38
+ attempt(async () => {
39
+ const handle = file.value ?? (await showSaveFilePicker({ id: "notes", suggestedName: "notes.txt", types: TYPES }));
40
+ await write(handle);
41
+ file.value = handle;
42
+ return `Saved ${handle.name}`;
43
+ });
44
+
45
+ const copy = () =>
46
+ attempt(async () => {
47
+ await navigator.clipboard.writeText(text.value);
48
+ return "Copied to the clipboard";
49
+ });
50
+
51
+ const paste = () =>
52
+ attempt(async () => {
53
+ text.value = await navigator.clipboard.readText();
54
+ return "Pasted from the clipboard";
55
+ });
56
+ </script>
57
+
58
+ <template>
59
+ <Page title="Files" lead="Native open and save dialogs through the web's own APIs, and the system clipboard.">
60
+ <Card title="Editor" :api="file ? file.name : 'untitled'">
61
+ <textarea v-model="text" class="input editor" spellcheck="false" />
62
+ <div class="row">
63
+ <button class="btn" @click="open">Open…</button>
64
+ <button class="btn primary" @click="save">{{ file ? "Save" : "Save as…" }}</button>
65
+ <button v-if="file" class="btn" @click="file = null">Forget the file</button>
66
+ <span class="faint">{{ status }}</span>
67
+ </div>
68
+ </Card>
69
+
70
+ <Card title="Clipboard" api="navigator.clipboard">
71
+ <div class="row">
72
+ <button class="btn" @click="copy">Copy the text</button>
73
+ <button class="btn" @click="paste">Paste over it</button>
74
+ </div>
75
+ <p class="faint">Ctrl+C and Ctrl+V in text fields need none of this: they belong to the field.</p>
76
+ </Card>
77
+ </Page>
78
+ </template>
79
+
80
+ <style scoped>
81
+ .editor {
82
+ height: 220px;
83
+ padding: 12px;
84
+ font-family: var(--mono);
85
+ line-height: 19px;
86
+ }
87
+ </style>
@@ -0,0 +1,138 @@
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
+
6
+ const name = ref("");
7
+ const plan = ref("team");
8
+ const seats = ref(5);
9
+ const yearly = ref(true);
10
+ const notes = ref("");
11
+ const price = () => seats.value * (plan.value === "team" ? 8 : 15) * (yearly.value ? 10 : 1);
12
+
13
+ // Selection is the document's, as in a browser: drag over the paragraph, or double-click a word.
14
+ const selected = ref("");
15
+ const onSelection = () => (selected.value = getSelection()?.toString() ?? "");
16
+ onMounted(() => document.addEventListener("selectionchange", onSelection));
17
+ onUnmounted(() => document.removeEventListener("selectionchange", onSelection));
18
+ </script>
19
+
20
+ <template>
21
+ <Page title="Forms" lead="Native text editing with IME, undo and the system caret, driven by plain v-model.">
22
+ <Card title="Controls" api="v-model">
23
+ <div class="form">
24
+ <label class="field">
25
+ <span class="label">Name</span>
26
+ <input v-model="name" class="input" placeholder="Ada Lovelace" />
27
+ </label>
28
+ <label class="field">
29
+ <span class="label">Plan</span>
30
+ <select v-model="plan" class="input">
31
+ <option value="team">Team</option>
32
+ <option value="business">Business</option>
33
+ </select>
34
+ </label>
35
+ <label class="field">
36
+ <span class="label">Seats · {{ seats }}</span>
37
+ <input v-model.number="seats" type="range" min="1" max="50" />
38
+ </label>
39
+ <div class="check">
40
+ <button
41
+ class="switch"
42
+ :class="{ on: yearly }"
43
+ role="switch"
44
+ :aria-checked="yearly"
45
+ aria-label="Pay yearly"
46
+ @click="yearly = !yearly"
47
+ >
48
+ <span class="knob" />
49
+ </button>
50
+ <span>Pay yearly (two months free)</span>
51
+ </div>
52
+ <label class="field">
53
+ <span class="label">Notes</span>
54
+ <textarea v-model="notes" class="input notes" placeholder="Enter adds a line" />
55
+ </label>
56
+ </div>
57
+ <div class="summary">
58
+ {{ name || "Someone" }} · {{ plan }} · {{ seats }} seats · ${{ price() }} per {{ yearly ? "year" : "month" }}
59
+ </div>
60
+ </Card>
61
+
62
+ <Card title="Text selection" api="getSelection()">
63
+ <p class="prose">
64
+ Text in a Skathi window is selectable like text on a web page. Drag across this paragraph, double-click a word
65
+ or press Ctrl+A, then Ctrl+C: the selection goes to the system clipboard.
66
+ </p>
67
+ <p class="faint">Selected: {{ selected || "nothing" }}</p>
68
+ <p class="prose locked">user-select: none keeps this line out of every selection.</p>
69
+ </Card>
70
+ </Page>
71
+ </template>
72
+
73
+ <style scoped>
74
+ .form {
75
+ display: flex;
76
+ flex-direction: column;
77
+ gap: 14px;
78
+ max-width: 420px;
79
+ }
80
+ .field {
81
+ display: flex;
82
+ flex-direction: column;
83
+ gap: 6px;
84
+ }
85
+ .label {
86
+ font-size: 12px;
87
+ color: var(--text-faint);
88
+ }
89
+ .check {
90
+ display: flex;
91
+ align-items: center;
92
+ gap: 10px;
93
+ font-size: 13px;
94
+ }
95
+ .switch {
96
+ display: flex;
97
+ width: 36px;
98
+ height: 20px;
99
+ padding: 2px;
100
+ border-radius: 10px;
101
+ background: var(--surface-strong);
102
+ cursor: pointer;
103
+ transition: background-color 160ms ease;
104
+ }
105
+ .switch.on {
106
+ background: var(--accent-strong);
107
+ }
108
+ .knob {
109
+ width: 16px;
110
+ height: 16px;
111
+ border-radius: 8px;
112
+ background: #ffffff;
113
+ transition: margin-left 160ms ease;
114
+ }
115
+ .switch.on .knob {
116
+ margin-left: 16px;
117
+ }
118
+ .notes {
119
+ height: 80px;
120
+ padding: 8px 12px;
121
+ }
122
+ .summary {
123
+ padding: 12px;
124
+ border-radius: 10px;
125
+ background: var(--accent-soft);
126
+ font-size: 13px;
127
+ }
128
+ .prose {
129
+ margin: 0;
130
+ font-size: 14px;
131
+ line-height: 22px;
132
+ color: var(--text);
133
+ }
134
+ .locked {
135
+ user-select: none;
136
+ color: var(--text-faint);
137
+ }
138
+ </style>
@@ -0,0 +1,154 @@
1
+ <script setup lang="ts">
2
+ import { onMounted, onUnmounted, ref, shallowRef } from "vue";
3
+ import Card from "../components/Card.vue";
4
+ import Page from "../components/Page.vue";
5
+ import { describe, everyFrame } from "../engine";
6
+
7
+ const W = 640;
8
+ const H = 220;
9
+ const dpr = devicePixelRatio;
10
+
11
+ const pad = shallowRef<HTMLCanvasElement | null>(null);
12
+ let ctx: CanvasRenderingContext2D | null = null;
13
+ let last: { x: number; y: number } | null = null;
14
+ let hue = 220;
15
+
16
+ function clear() {
17
+ if (!ctx) return;
18
+ const bg = ctx.createLinearGradient(0, 0, W, H);
19
+ bg.addColorStop(0, "#14141c");
20
+ bg.addColorStop(1, "#1c1630");
21
+ ctx.fillStyle = bg;
22
+ ctx.fillRect(0, 0, W, H);
23
+ ctx.fillStyle = "#ffffff40";
24
+ ctx.font = "13px Segoe UI";
25
+ ctx.fillText("Drag to draw", 16, 26);
26
+ }
27
+
28
+ const at = (e: MouseEvent) => {
29
+ const rect = pad.value!.getBoundingClientRect();
30
+ return { x: e.clientX - rect.left, y: e.clientY - rect.top };
31
+ };
32
+ const down = (e: MouseEvent) => (last = at(e));
33
+ const up = () => (last = null);
34
+ function move(e: MouseEvent) {
35
+ if (!ctx || !last) return;
36
+ const next = at(e);
37
+ hue = (hue + 2) % 360;
38
+ ctx.strokeStyle = `hsl(${hue}, 90%, 68%)`;
39
+ ctx.lineWidth = 6;
40
+ ctx.lineCap = "round";
41
+ ctx.beginPath();
42
+ ctx.moveTo(last.x, last.y);
43
+ ctx.lineTo(next.x, next.y);
44
+ ctx.stroke();
45
+ last = next;
46
+ }
47
+
48
+ onMounted(() => {
49
+ ctx = pad.value?.getContext("2d") ?? null;
50
+ ctx?.scale(dpr, dpr);
51
+ clear();
52
+ });
53
+
54
+ const SHADER = /* wgsl */ `
55
+ struct Uniforms { time: f32, aspect: f32 }
56
+ @group(0) @binding(0) var<uniform> u: Uniforms;
57
+
58
+ struct Varying { @builtin(position) position: vec4f, @location(0) uv: vec2f }
59
+
60
+ @vertex fn vs(@builtin(vertex_index) i: u32) -> Varying {
61
+ var corners = array<vec2f, 3>(vec2f(-1.0, -3.0), vec2f(-1.0, 1.0), vec2f(3.0, 1.0));
62
+ var out: Varying;
63
+ out.position = vec4f(corners[i], 0.0, 1.0);
64
+ out.uv = corners[i] * 0.5 + 0.5;
65
+ return out;
66
+ }
67
+
68
+ @fragment fn fs(v: Varying) -> @location(0) vec4f {
69
+ let p = (v.uv - 0.5) * vec2f(u.aspect, 1.0) * 6.0;
70
+ let t = u.time;
71
+ let w = sin(p.x + t) + sin(p.y * 1.3 - t * 0.8) + sin(length(p) * 1.5 - t * 1.2);
72
+ let c = 0.5 + 0.5 * cos(vec3f(0.0, 2.1, 4.2) + w + t * 0.3);
73
+ return vec4f(c * vec3f(0.55, 0.6, 1.0), 1.0);
74
+ }`;
75
+
76
+ const surface = shallowRef<HTMLCanvasElement | null>(null);
77
+ const adapterName = ref("");
78
+ let stopGpu: (() => void) | null = null;
79
+
80
+ async function startGpu(canvas: HTMLCanvasElement) {
81
+ const adapter = await navigator.gpu.requestAdapter();
82
+ const context = canvas.getContext("webgpu");
83
+ if (!adapter || !context) throw new Error("No GPU adapter for WebGPU on this machine");
84
+ adapterName.value = adapter.info.description;
85
+ const device = await adapter.requestDevice();
86
+ const format = navigator.gpu.getPreferredCanvasFormat();
87
+ context.configure({ device, format, alphaMode: "opaque" });
88
+ const module = device.createShaderModule({ code: SHADER });
89
+ const pipeline = device.createRenderPipeline({
90
+ layout: "auto",
91
+ vertex: { module, entryPoint: "vs" },
92
+ fragment: { module, entryPoint: "fs", targets: [{ format }] },
93
+ });
94
+ const uniforms = device.createBuffer({ size: 16, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST });
95
+ const bindings = device.createBindGroup({
96
+ layout: pipeline.getBindGroupLayout(0),
97
+ entries: [{ binding: 0, resource: { buffer: uniforms } }],
98
+ });
99
+ const stop = everyFrame((time) => {
100
+ device.queue.writeBuffer(uniforms, 0, new Float32Array([time / 1000, W / H, 0, 0]));
101
+ const encoder = device.createCommandEncoder();
102
+ const pass = encoder.beginRenderPass({
103
+ colorAttachments: [{ view: context.getCurrentTexture().createView(), loadOp: "clear", storeOp: "store" }],
104
+ });
105
+ pass.setPipeline(pipeline);
106
+ pass.setBindGroup(0, bindings);
107
+ pass.draw(3);
108
+ pass.end();
109
+ device.queue.submit([encoder.finish()]);
110
+ });
111
+ stopGpu = () => {
112
+ stop();
113
+ device.destroy();
114
+ };
115
+ }
116
+
117
+ onMounted(() => {
118
+ if (surface.value) startGpu(surface.value).catch((e: unknown) => (adapterName.value = describe(e)));
119
+ });
120
+ onUnmounted(() => stopGpu?.());
121
+ </script>
122
+
123
+ <template>
124
+ <Page title="Graphics" lead="Canvas 2D and WebGPU draw into the same GPU-composited tree as the rest of the page.">
125
+ <Card title="Canvas 2D" api="getContext('2d')">
126
+ <canvas
127
+ ref="pad"
128
+ class="canvas"
129
+ :width="W * dpr"
130
+ :height="H * dpr"
131
+ @mousedown="down"
132
+ @mousemove="move"
133
+ @mouseup="up"
134
+ @mouseleave="up"
135
+ />
136
+ <div class="row">
137
+ <button class="btn" @click="clear">Clear</button>
138
+ </div>
139
+ </Card>
140
+
141
+ <Card title="WebGPU" :api="adapterName || 'navigator.gpu'">
142
+ <canvas ref="surface" class="canvas" :width="W * dpr" :height="H * dpr" />
143
+ <p class="faint">A WGSL fragment shader, redrawn every frame with the time in a uniform buffer.</p>
144
+ </Card>
145
+ </Page>
146
+ </template>
147
+
148
+ <style scoped>
149
+ .canvas {
150
+ width: 640px;
151
+ height: 220px;
152
+ border-radius: 10px;
153
+ }
154
+ </style>
@@ -0,0 +1,140 @@
1
+ <script setup lang="ts">
2
+ import { onMounted, ref } from "vue";
3
+ import Icon from "../components/Icon.vue";
4
+ import { productName } from "../product";
5
+ import { pages } from "../router";
6
+ import { useCounter } from "../stores/counter";
7
+
8
+ const counter = useCounter();
9
+ const features = pages.filter((p) => p.blurb);
10
+
11
+ // A relative URL resolves against the app root in dev and against the packaged assets in a build.
12
+ const greeting = ref("");
13
+ onMounted(async () => {
14
+ const res = await fetch("assets/hello.txt");
15
+ if (res.ok) greeting.value = (await res.text()).trim();
16
+ });
17
+ </script>
18
+
19
+ <template>
20
+ <section class="home">
21
+ <div class="hero">
22
+ <div class="logo">{{ productName.charAt(0) }}</div>
23
+ <h1 class="title">{{ productName }}</h1>
24
+ <p class="lead">
25
+ Vue 3 on a native GPU renderer, with no browser inside. Every page in the sidebar shows one part of Skathi in a
26
+ few lines of code; open <span class="mono">src/pages</span> next to it and change things while
27
+ <span class="mono">sk dev</span> runs.
28
+ </p>
29
+ <div class="row">
30
+ <button class="btn primary" @click="counter.increment()">Count up · {{ counter.count }}</button>
31
+ <button class="btn" :disabled="counter.count === 0" @click="counter.reset()">Reset</button>
32
+ </div>
33
+ <p class="faint">
34
+ The count is a pinia store: the pop-out window, the tray menu and the global hotkey all change the same one.
35
+ </p>
36
+ <p v-if="greeting" class="faint">{{ greeting }}</p>
37
+ </div>
38
+
39
+ <div class="grid">
40
+ <RouterLink v-for="page in features" :key="page.path" :to="page.path" class="feature">
41
+ <span class="badge"><Icon :name="page.icon" /></span>
42
+ <span class="name">{{ page.title }}</span>
43
+ <span class="blurb">{{ page.blurb }}</span>
44
+ </RouterLink>
45
+ </div>
46
+ </section>
47
+ </template>
48
+
49
+ <style scoped>
50
+ .home {
51
+ display: flex;
52
+ flex-direction: column;
53
+ gap: 32px;
54
+ padding: 40px 32px;
55
+ }
56
+ .hero {
57
+ display: flex;
58
+ flex-direction: column;
59
+ align-items: center;
60
+ gap: 14px;
61
+ text-align: center;
62
+ }
63
+ .logo {
64
+ width: 72px;
65
+ height: 72px;
66
+ border-radius: 20px;
67
+ display: flex;
68
+ align-items: center;
69
+ justify-content: center;
70
+ background: linear-gradient(135deg, var(--accent), #b48cff);
71
+ box-shadow: 0 14px 36px #6d7cff55;
72
+ color: #ffffff;
73
+ font-size: 34px;
74
+ font-weight: 700;
75
+ animation: float 5s ease-in-out infinite;
76
+ }
77
+ @keyframes float {
78
+ 50% {
79
+ transform: translateY(-6px);
80
+ }
81
+ }
82
+ .title {
83
+ margin: 0;
84
+ font-size: 32px;
85
+ font-weight: 700;
86
+ }
87
+ .lead {
88
+ margin: 0;
89
+ max-width: 560px;
90
+ font-size: 14px;
91
+ line-height: 22px;
92
+ color: var(--text-muted);
93
+ }
94
+ .grid {
95
+ display: flex;
96
+ flex-wrap: wrap;
97
+ justify-content: center;
98
+ gap: 12px;
99
+ }
100
+ .feature {
101
+ width: 220px;
102
+ display: flex;
103
+ flex-direction: column;
104
+ gap: 6px;
105
+ padding: 16px;
106
+ border-radius: var(--radius);
107
+ border: 1px solid var(--line);
108
+ background: var(--surface);
109
+ cursor: pointer;
110
+ transition:
111
+ background-color 150ms ease,
112
+ border-color 150ms ease,
113
+ transform 150ms ease;
114
+ }
115
+ .feature:hover {
116
+ background: var(--surface-hover);
117
+ border-color: var(--line-strong);
118
+ transform: translateY(-2px);
119
+ }
120
+ .badge {
121
+ width: 30px;
122
+ height: 30px;
123
+ border-radius: 9px;
124
+ display: flex;
125
+ align-items: center;
126
+ justify-content: center;
127
+ background: var(--accent-soft);
128
+ color: var(--accent);
129
+ }
130
+ .name {
131
+ font-size: 14px;
132
+ font-weight: 600;
133
+ color: var(--text);
134
+ }
135
+ .blurb {
136
+ font-size: 12px;
137
+ line-height: 17px;
138
+ color: var(--text-muted);
139
+ }
140
+ </style>
@@ -0,0 +1,71 @@
1
+ <script setup lang="ts">
2
+ import { appLocale } from "@skathi-native/runtime";
3
+ import { computed, ref } from "vue";
4
+ import Card from "../components/Card.vue";
5
+ import Page from "../components/Page.vue";
6
+ import { productName } from "../product";
7
+
8
+ // `{name}` is filled from the arguments to t(). `sk.*` keys reword the SDK's own text (its dialogs and prompts).
9
+ appLocale.define({
10
+ en: { greeting: "Welcome to {name}", files: "{count} files selected", today: "Today is a good day to ship." },
11
+ de: { greeting: "Willkommen bei {name}", files: "{count} Dateien ausgewählt", today: "Heute ist ein guter Tag." },
12
+ es: { greeting: "Bienvenido a {name}", files: "{count} archivos seleccionados", today: "Hoy es un buen día." },
13
+ ja: { greeting: "{name} へようこそ", files: "{count} 個のファイルを選択", today: "今日はリリース日和です。" },
14
+ });
15
+
16
+ const LANGUAGES = [null, "en", "de", "es", "ja"] as const;
17
+ const language = ref(appLocale.language);
18
+ const count = ref(3);
19
+ const systemLanguages = navigator.languages.join(", ");
20
+
21
+ function choose(tag: (typeof LANGUAGES)[number]) {
22
+ appLocale.language = tag;
23
+ language.value = tag;
24
+ }
25
+
26
+ // appLocale is not reactive: reading `language` is what makes this recompute after a switch.
27
+ const text = computed(() => {
28
+ void language.value;
29
+ return {
30
+ resolved: appLocale.resolved,
31
+ greeting: appLocale.t("greeting", { name: productName }),
32
+ files: appLocale.t("files", { count: count.value }),
33
+ today: appLocale.t("today"),
34
+ };
35
+ });
36
+ </script>
37
+
38
+ <template>
39
+ <Page title="Locale" lead="A message catalog per language; t() picks the best match for the user's languages.">
40
+ <Card title="Language" :api="`resolved: ${text.resolved}`">
41
+ <div class="row">
42
+ <button
43
+ v-for="tag in LANGUAGES"
44
+ :key="tag ?? 'auto'"
45
+ class="btn"
46
+ :class="{ on: language === tag }"
47
+ @click="choose(tag)"
48
+ >
49
+ {{ tag ?? "System" }}
50
+ </button>
51
+ </div>
52
+ <p class="faint">System follows navigator.languages: {{ systemLanguages }}</p>
53
+ </Card>
54
+
55
+ <Card title="Messages" api="appLocale.t()">
56
+ <div class="greeting">{{ text.greeting }}</div>
57
+ <div class="row">
58
+ <button class="btn" @click="count++">+1</button>
59
+ <span class="muted">{{ text.files }}</span>
60
+ </div>
61
+ <p class="muted">{{ text.today }}</p>
62
+ </Card>
63
+ </Page>
64
+ </template>
65
+
66
+ <style scoped>
67
+ .greeting {
68
+ font-size: 22px;
69
+ font-weight: 700;
70
+ }
71
+ </style>
@@ -0,0 +1,85 @@
1
+ <script setup lang="ts">
2
+ import { ref } from "vue";
3
+ import Card from "../components/Card.vue";
4
+ import Page from "../components/Page.vue";
5
+
6
+ const video = ref<HTMLVideoElement | null>(null);
7
+ const playing = ref(true);
8
+ const toggleVideo = () => {
9
+ if (!video.value) return;
10
+ if (video.value.paused) video.value.play();
11
+ else video.value.pause();
12
+ playing.value = !video.value.paused;
13
+ };
14
+
15
+ const stickerPlaying = ref(true);
16
+ const speed = ref(1);
17
+ </script>
18
+
19
+ <template>
20
+ <Page
21
+ title="Media"
22
+ lead="Images, video and Lottie animations, loaded from assets/media. sk.config.json puts that folder in its own pack, media.skpk, beside the exe."
23
+ >
24
+ <div class="tiles">
25
+ <Card class="tile" title="Image" api="<img>">
26
+ <img class="shot zoom" src="assets/media/aurora.png" alt="Aurora" />
27
+ </Card>
28
+
29
+ <Card class="tile" title="Video" api="<video>">
30
+ <video ref="video" class="shot" src="assets/media/clip.mp4" autoplay loop muted />
31
+ <div class="row">
32
+ <button class="btn" @click="toggleVideo">{{ playing ? "Pause" : "Play" }}</button>
33
+ <span class="faint">Decoded by the OS media stack.</span>
34
+ </div>
35
+ </Card>
36
+
37
+ <Card class="tile" title="Lottie sticker" api="<lottie>">
38
+ <div class="stage">
39
+ <lottie class="sticker" src="assets/media/sticker.tgs" loop :autoplay="stickerPlaying" :speed="speed" />
40
+ </div>
41
+ <div class="row">
42
+ <button class="btn" @click="stickerPlaying = !stickerPlaying">{{ stickerPlaying ? "Pause" : "Play" }}</button>
43
+ <button v-for="s in [0.5, 1, 2]" :key="s" class="btn" :class="{ on: speed === s }" @click="speed = s">
44
+ {{ s }}×
45
+ </button>
46
+ </div>
47
+ </Card>
48
+ </div>
49
+ </Page>
50
+ </template>
51
+
52
+ <style scoped>
53
+ .tiles {
54
+ display: flex;
55
+ flex-wrap: wrap;
56
+ gap: 16px;
57
+ }
58
+ .tile {
59
+ width: 320px;
60
+ }
61
+ .shot {
62
+ width: 100%;
63
+ height: 160px;
64
+ border-radius: 10px;
65
+ object-fit: cover;
66
+ }
67
+ .zoom {
68
+ transition: transform 300ms ease;
69
+ }
70
+ .zoom:hover {
71
+ transform: scale(1.04);
72
+ }
73
+ .stage {
74
+ height: 160px;
75
+ display: flex;
76
+ align-items: center;
77
+ justify-content: center;
78
+ border-radius: 10px;
79
+ background: radial-gradient(circle, #8b9dff30, #00000000);
80
+ }
81
+ .sticker {
82
+ width: 120px;
83
+ height: 120px;
84
+ }
85
+ </style>