@skathi-native/cli 0.1.0-beta.2 → 0.1.0-beta.4
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.
- package/aot/host-globals.json +105 -0
- package/aot/native.ts +142 -0
- package/aot/pin.ts +67 -0
- package/aot/toolchain.lock.json +17 -0
- package/aot/transform.ts +69 -0
- package/check/codes.ts +19 -0
- package/check/command.ts +5 -3
- package/check/index.ts +44 -1
- package/cli/aot-build.ts +192 -0
- package/cli/build-app.ts +102 -31
- package/cli/config.ts +45 -102
- package/cli/create.ts +12 -54
- package/cli/dev.ts +109 -19
- package/cli/effects.ts +162 -0
- package/cli/elf.ts +3 -2
- package/cli/help.ts +56 -148
- package/cli/host-fetch.ts +116 -54
- package/cli/host.ts +59 -39
- package/cli/sk.ts +440 -246
- package/cli/skpk.ts +6 -0
- package/cli/stamp.ts +2 -2
- package/cli/term.ts +169 -38
- package/cli/workload-cache.ts +258 -0
- package/effects/compile.ts +952 -0
- package/effects/redslangc.json +23 -0
- package/effects/redslangc.ts +220 -0
- package/effects/sk.slang +558 -0
- package/package.json +6 -2
- package/templates/icon.png +0 -0
- package/templates/minimal/.vscode/settings.json +3 -0
- package/templates/minimal/src/App.vue +2 -2
- package/templates/showcase/.vscode/settings.json +3 -0
- package/templates/showcase/shaders/sheen.slang +23 -0
- package/templates/showcase/src/components/Titlebar.vue +7 -3
- package/templates/showcase/src/engine.ts +3 -26
- package/templates/showcase/src/pages/AudioPage.vue +6 -9
- package/templates/showcase/src/pages/FilesPage.vue +11 -15
- package/templates/showcase/src/pages/FormsPage.vue +2 -3
- package/templates/showcase/src/pages/GraphicsPage.vue +13 -15
- package/templates/showcase/src/pages/HomePage.vue +1 -2
- package/templates/showcase/src/pages/LocalePage.vue +2 -2
- package/templates/showcase/src/pages/MediaPage.vue +1 -1
- package/templates/showcase/src/pages/MotionPage.vue +1 -1
- package/templates/showcase/src/pages/NetworkPage.vue +6 -5
- package/templates/showcase/src/pages/PermissionsPage.vue +2 -2
- package/templates/showcase/src/pages/StoragePage.vue +23 -36
- package/templates/showcase/src/pages/StylesPage.vue +9 -1
- package/templates/showcase/src/pages/SystemPage.vue +3 -3
- package/templates/showcase/src/styles.css +2 -2
- package/templates/showcase/src/components/Missing.vue +0 -26
|
@@ -1,33 +1,10 @@
|
|
|
1
|
-
// The web surface the pages use, resolved once. Engine parts an app leaves out ("windows": { "without": [...] }
|
|
2
|
-
// in sk.config.json) are absent globals rather than stubs, so each one is `null` here when its part is out.
|
|
3
|
-
|
|
4
|
-
function required<T>(value: T | undefined, name: string): T {
|
|
5
|
-
if (value === undefined) throw new Error(`${name} is missing: this code runs in a Skathi window`);
|
|
6
|
-
return value;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const nav = required(typeof navigator === "object" ? navigator : undefined, "navigator");
|
|
10
|
-
export const dom = required(
|
|
11
|
-
typeof document === "object" ? document : undefined,
|
|
12
|
-
"document",
|
|
13
|
-
) as unknown as SkDomDocument;
|
|
14
|
-
export const http = required(typeof fetch === "function" ? fetch : undefined, "fetch");
|
|
15
|
-
|
|
16
|
-
export const audio = typeof AudioContext === "function" ? AudioContext : null;
|
|
17
|
-
export const clipboard = typeof nav.clipboard === "object" ? nav.clipboard : null;
|
|
18
|
-
export const storage = typeof localStorage === "object" ? localStorage : null;
|
|
19
|
-
export const idb = typeof indexedDB === "object" ? indexedDB : null;
|
|
20
|
-
export const gpu = nav.gpu ?? null;
|
|
21
|
-
|
|
22
1
|
/** Calls `draw` once per painted frame until the returned function is called. */
|
|
23
2
|
export function everyFrame(draw: (time: number) => void): () => void {
|
|
24
|
-
|
|
25
|
-
const cancel = required(typeof cancelAnimationFrame === "function" ? cancelAnimationFrame : undefined, "cAF");
|
|
26
|
-
let handle = request(function frame(time) {
|
|
3
|
+
let handle = requestAnimationFrame(function frame(time) {
|
|
27
4
|
draw(time);
|
|
28
|
-
handle =
|
|
5
|
+
handle = requestAnimationFrame(frame);
|
|
29
6
|
});
|
|
30
|
-
return () =>
|
|
7
|
+
return () => cancelAnimationFrame(handle);
|
|
31
8
|
}
|
|
32
9
|
|
|
33
10
|
export const describe = (e: unknown) => (e instanceof Error ? e.message : String(e));
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { onUnmounted, ref } from "vue";
|
|
3
3
|
import Card from "../components/Card.vue";
|
|
4
|
-
import Missing from "../components/Missing.vue";
|
|
5
4
|
import Page from "../components/Page.vue";
|
|
6
|
-
import {
|
|
5
|
+
import { everyFrame } from "../engine";
|
|
7
6
|
|
|
8
7
|
const NOTES = [
|
|
9
8
|
["C", 261.63],
|
|
@@ -21,11 +20,11 @@ const BARS = 32;
|
|
|
21
20
|
const wave = ref("triangle");
|
|
22
21
|
const levels = ref<number[]>(Array.from({ length: BARS }, () => 0));
|
|
23
22
|
|
|
24
|
-
let engine: { ctx:
|
|
23
|
+
let engine: { ctx: AudioContext; tap: AnalyserNode; stop: () => void } | null = null;
|
|
25
24
|
|
|
26
25
|
// Created on the first note, so the audio device is not opened until something plays.
|
|
27
|
-
function start(
|
|
28
|
-
const ctx = new
|
|
26
|
+
function start() {
|
|
27
|
+
const ctx = new AudioContext();
|
|
29
28
|
const tap = ctx.createAnalyser();
|
|
30
29
|
tap.fftSize = 128;
|
|
31
30
|
tap.connect(ctx.destination);
|
|
@@ -38,8 +37,7 @@ function start(Context: NonNullable<typeof audio>) {
|
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
function play(frequency: number) {
|
|
41
|
-
|
|
42
|
-
engine ??= start(audio);
|
|
40
|
+
engine ??= start();
|
|
43
41
|
const { ctx, tap } = engine;
|
|
44
42
|
const now = ctx.currentTime;
|
|
45
43
|
const osc = ctx.createOscillator();
|
|
@@ -63,7 +61,7 @@ onUnmounted(() => {
|
|
|
63
61
|
|
|
64
62
|
<template>
|
|
65
63
|
<Page title="Audio" lead="The Web Audio API on a native audio engine: oscillators, gain envelopes and an analyser.">
|
|
66
|
-
<Card
|
|
64
|
+
<Card title="Synth" api="AudioContext">
|
|
67
65
|
<div class="keys">
|
|
68
66
|
<button v-for="([name, hz], i) in NOTES" :key="i" class="key" @mousedown="play(hz)">{{ name }}</button>
|
|
69
67
|
</div>
|
|
@@ -74,7 +72,6 @@ onUnmounted(() => {
|
|
|
74
72
|
<div v-for="(level, i) in levels" :key="i" class="bar" :style="{ height: `${4 + level * 96}px` }" />
|
|
75
73
|
</div>
|
|
76
74
|
</Card>
|
|
77
|
-
<Missing v-else part="audio" />
|
|
78
75
|
</Page>
|
|
79
76
|
</template>
|
|
80
77
|
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { ref, shallowRef } from "vue";
|
|
3
3
|
import Card from "../components/Card.vue";
|
|
4
|
-
import Missing from "../components/Missing.vue";
|
|
5
4
|
import Page from "../components/Page.vue";
|
|
6
|
-
import {
|
|
5
|
+
import { describe } from "../engine";
|
|
7
6
|
|
|
8
7
|
// The File System Access API: a picker needs a click, and a handle names its file but never shows its path.
|
|
9
8
|
const TYPES = [{ description: "Text", accept: { "text/plain": [".txt", ".md", ".log"] } }];
|
|
10
9
|
|
|
11
10
|
const text = ref("Write something, then save it.\n");
|
|
12
|
-
const file = shallowRef<
|
|
11
|
+
const file = shallowRef<FileSystemFileHandle | null>(null);
|
|
13
12
|
const status = ref("");
|
|
14
13
|
|
|
15
14
|
async function attempt(action: () => Promise<string>) {
|
|
@@ -20,7 +19,7 @@ async function attempt(action: () => Promise<string>) {
|
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
async function write(handle:
|
|
22
|
+
async function write(handle: FileSystemFileHandle) {
|
|
24
23
|
const stream = await handle.createWritable();
|
|
25
24
|
await stream.write(text.value);
|
|
26
25
|
await stream.close();
|
|
@@ -43,17 +42,15 @@ const save = () =>
|
|
|
43
42
|
return `Saved ${handle.name}`;
|
|
44
43
|
});
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const copy = (board: Clipboard) =>
|
|
45
|
+
const copy = () =>
|
|
49
46
|
attempt(async () => {
|
|
50
|
-
await
|
|
47
|
+
await navigator.clipboard.writeText(text.value);
|
|
51
48
|
return "Copied to the clipboard";
|
|
52
49
|
});
|
|
53
50
|
|
|
54
|
-
const paste = (
|
|
51
|
+
const paste = () =>
|
|
55
52
|
attempt(async () => {
|
|
56
|
-
text.value = await
|
|
53
|
+
text.value = await navigator.clipboard.readText();
|
|
57
54
|
return "Pasted from the clipboard";
|
|
58
55
|
});
|
|
59
56
|
</script>
|
|
@@ -71,12 +68,11 @@ const paste = (board: Clipboard) =>
|
|
|
71
68
|
</Card>
|
|
72
69
|
|
|
73
70
|
<Card title="Clipboard" api="navigator.clipboard">
|
|
74
|
-
<div
|
|
75
|
-
<button class="btn" @click="copy
|
|
76
|
-
<button class="btn" @click="paste
|
|
71
|
+
<div class="row">
|
|
72
|
+
<button class="btn" @click="copy">Copy the text</button>
|
|
73
|
+
<button class="btn" @click="paste">Paste over it</button>
|
|
77
74
|
</div>
|
|
78
|
-
<
|
|
79
|
-
<p class="faint">Ctrl+C and Ctrl+V in text fields work either way: they belong to the field.</p>
|
|
75
|
+
<p class="faint">Ctrl+C and Ctrl+V in text fields need none of this: they belong to the field.</p>
|
|
80
76
|
</Card>
|
|
81
77
|
</Page>
|
|
82
78
|
</template>
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { onMounted, onUnmounted, ref } from "vue";
|
|
3
3
|
import Card from "../components/Card.vue";
|
|
4
4
|
import Page from "../components/Page.vue";
|
|
5
|
-
import { dom } from "../engine";
|
|
6
5
|
|
|
7
6
|
const name = ref("");
|
|
8
7
|
const plan = ref("team");
|
|
@@ -14,8 +13,8 @@ const price = () => seats.value * (plan.value === "team" ? 8 : 15) * (yearly.val
|
|
|
14
13
|
// Selection is the document's, as in a browser: drag over the paragraph, or double-click a word.
|
|
15
14
|
const selected = ref("");
|
|
16
15
|
const onSelection = () => (selected.value = getSelection()?.toString() ?? "");
|
|
17
|
-
onMounted(() =>
|
|
18
|
-
onUnmounted(() =>
|
|
16
|
+
onMounted(() => document.addEventListener("selectionchange", onSelection));
|
|
17
|
+
onUnmounted(() => document.removeEventListener("selectionchange", onSelection));
|
|
19
18
|
</script>
|
|
20
19
|
|
|
21
20
|
<template>
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { onMounted, onUnmounted, ref, shallowRef } from "vue";
|
|
3
3
|
import Card from "../components/Card.vue";
|
|
4
|
-
import Missing from "../components/Missing.vue";
|
|
5
4
|
import Page from "../components/Page.vue";
|
|
6
|
-
import { describe, everyFrame
|
|
5
|
+
import { describe, everyFrame } from "../engine";
|
|
7
6
|
|
|
8
7
|
const W = 640;
|
|
9
8
|
const H = 220;
|
|
10
9
|
const dpr = devicePixelRatio;
|
|
11
10
|
|
|
12
|
-
const pad = shallowRef<
|
|
13
|
-
let ctx:
|
|
11
|
+
const pad = shallowRef<HTMLCanvasElement | null>(null);
|
|
12
|
+
let ctx: CanvasRenderingContext2D | null = null;
|
|
14
13
|
let last: { x: number; y: number } | null = null;
|
|
15
14
|
let hue = 220;
|
|
16
15
|
|
|
@@ -26,13 +25,13 @@ function clear() {
|
|
|
26
25
|
ctx.fillText("Drag to draw", 16, 26);
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
const at = (e:
|
|
28
|
+
const at = (e: MouseEvent) => {
|
|
30
29
|
const rect = pad.value!.getBoundingClientRect();
|
|
31
30
|
return { x: e.clientX - rect.left, y: e.clientY - rect.top };
|
|
32
31
|
};
|
|
33
|
-
const down = (e:
|
|
32
|
+
const down = (e: MouseEvent) => (last = at(e));
|
|
34
33
|
const up = () => (last = null);
|
|
35
|
-
function move(e:
|
|
34
|
+
function move(e: MouseEvent) {
|
|
36
35
|
if (!ctx || !last) return;
|
|
37
36
|
const next = at(e);
|
|
38
37
|
hue = (hue + 2) % 360;
|
|
@@ -74,17 +73,17 @@ struct Varying { @builtin(position) position: vec4f, @location(0) uv: vec2f }
|
|
|
74
73
|
return vec4f(c * vec3f(0.55, 0.6, 1.0), 1.0);
|
|
75
74
|
}`;
|
|
76
75
|
|
|
77
|
-
const surface = shallowRef<
|
|
76
|
+
const surface = shallowRef<HTMLCanvasElement | null>(null);
|
|
78
77
|
const adapterName = ref("");
|
|
79
78
|
let stopGpu: (() => void) | null = null;
|
|
80
79
|
|
|
81
|
-
async function startGpu(
|
|
82
|
-
const adapter = await
|
|
80
|
+
async function startGpu(canvas: HTMLCanvasElement) {
|
|
81
|
+
const adapter = await navigator.gpu.requestAdapter();
|
|
83
82
|
const context = canvas.getContext("webgpu");
|
|
84
|
-
if (!adapter || !context
|
|
83
|
+
if (!adapter || !context) throw new Error("No GPU adapter for WebGPU on this machine");
|
|
85
84
|
adapterName.value = adapter.info.description;
|
|
86
85
|
const device = await adapter.requestDevice();
|
|
87
|
-
const format =
|
|
86
|
+
const format = navigator.gpu.getPreferredCanvasFormat();
|
|
88
87
|
context.configure({ device, format, alphaMode: "opaque" });
|
|
89
88
|
const module = device.createShaderModule({ code: SHADER });
|
|
90
89
|
const pipeline = device.createRenderPipeline({
|
|
@@ -116,7 +115,7 @@ async function startGpu(api: SkGPU, canvas: SkCanvasElement) {
|
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
onMounted(() => {
|
|
119
|
-
if (
|
|
118
|
+
if (surface.value) startGpu(surface.value).catch((e: unknown) => (adapterName.value = describe(e)));
|
|
120
119
|
});
|
|
121
120
|
onUnmounted(() => stopGpu?.());
|
|
122
121
|
</script>
|
|
@@ -140,8 +139,7 @@ onUnmounted(() => stopGpu?.());
|
|
|
140
139
|
</Card>
|
|
141
140
|
|
|
142
141
|
<Card title="WebGPU" :api="adapterName || 'navigator.gpu'">
|
|
143
|
-
<canvas
|
|
144
|
-
<Missing v-else part="webgpu" />
|
|
142
|
+
<canvas ref="surface" class="canvas" :width="W * dpr" :height="H * dpr" />
|
|
145
143
|
<p class="faint">A WGSL fragment shader, redrawn every frame with the time in a uniform buffer.</p>
|
|
146
144
|
</Card>
|
|
147
145
|
</Page>
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { onMounted, ref } from "vue";
|
|
3
3
|
import Icon from "../components/Icon.vue";
|
|
4
|
-
import { http } from "../engine";
|
|
5
4
|
import { productName } from "../product";
|
|
6
5
|
import { pages } from "../router";
|
|
7
6
|
import { useCounter } from "../stores/counter";
|
|
@@ -12,7 +11,7 @@ const features = pages.filter((p) => p.blurb);
|
|
|
12
11
|
// A relative URL resolves against the app root in dev and against the packaged assets in a build.
|
|
13
12
|
const greeting = ref("");
|
|
14
13
|
onMounted(async () => {
|
|
15
|
-
const res = await
|
|
14
|
+
const res = await fetch("assets/hello.txt");
|
|
16
15
|
if (res.ok) greeting.value = (await res.text()).trim();
|
|
17
16
|
});
|
|
18
17
|
</script>
|
|
@@ -3,7 +3,6 @@ import { appLocale } from "@skathi-native/runtime";
|
|
|
3
3
|
import { computed, ref } from "vue";
|
|
4
4
|
import Card from "../components/Card.vue";
|
|
5
5
|
import Page from "../components/Page.vue";
|
|
6
|
-
import { nav } from "../engine";
|
|
7
6
|
import { productName } from "../product";
|
|
8
7
|
|
|
9
8
|
// `{name}` is filled from the arguments to t(). `sk.*` keys reword the SDK's own text (its dialogs and prompts).
|
|
@@ -17,6 +16,7 @@ appLocale.define({
|
|
|
17
16
|
const LANGUAGES = [null, "en", "de", "es", "ja"] as const;
|
|
18
17
|
const language = ref(appLocale.language);
|
|
19
18
|
const count = ref(3);
|
|
19
|
+
const systemLanguages = navigator.languages.join(", ");
|
|
20
20
|
|
|
21
21
|
function choose(tag: (typeof LANGUAGES)[number]) {
|
|
22
22
|
appLocale.language = tag;
|
|
@@ -49,7 +49,7 @@ const text = computed(() => {
|
|
|
49
49
|
{{ tag ?? "System" }}
|
|
50
50
|
</button>
|
|
51
51
|
</div>
|
|
52
|
-
<p class="faint">System follows navigator.languages: {{
|
|
52
|
+
<p class="faint">System follows navigator.languages: {{ systemLanguages }}</p>
|
|
53
53
|
</Card>
|
|
54
54
|
|
|
55
55
|
<Card title="Messages" api="appLocale.t()">
|
|
@@ -3,7 +3,7 @@ import { ref } from "vue";
|
|
|
3
3
|
import Card from "../components/Card.vue";
|
|
4
4
|
import Page from "../components/Page.vue";
|
|
5
5
|
|
|
6
|
-
const video = ref<
|
|
6
|
+
const video = ref<HTMLVideoElement | null>(null);
|
|
7
7
|
const playing = ref(true);
|
|
8
8
|
const toggleVideo = () => {
|
|
9
9
|
if (!video.value) return;
|
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
import { onUnmounted, ref, shallowRef } from "vue";
|
|
3
3
|
import Card from "../components/Card.vue";
|
|
4
4
|
import Page from "../components/Page.vue";
|
|
5
|
-
import { describe
|
|
5
|
+
import { describe } from "../engine";
|
|
6
6
|
|
|
7
|
+
const online = () => navigator.onLine;
|
|
7
8
|
const quote = ref("");
|
|
8
9
|
const took = ref("");
|
|
9
10
|
async function load() {
|
|
10
11
|
const start = performance.now();
|
|
11
12
|
try {
|
|
12
|
-
const res = await
|
|
13
|
+
const res = await fetch("https://api.github.com/zen");
|
|
13
14
|
quote.value = res.ok ? await res.text() : `HTTP ${res.status}`;
|
|
14
15
|
} catch (e) {
|
|
15
16
|
quote.value = describe(e);
|
|
@@ -18,7 +19,7 @@ async function load() {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
const ECHO = "wss://echo.websocket.org";
|
|
21
|
-
const socket = shallowRef<
|
|
22
|
+
const socket = shallowRef<WebSocket | null>(null);
|
|
22
23
|
const message = ref("Hello over a socket");
|
|
23
24
|
const log = ref<string[]>([]);
|
|
24
25
|
const note = (line: string) => (log.value = [line, ...log.value].slice(0, 6));
|
|
@@ -33,7 +34,7 @@ function connect() {
|
|
|
33
34
|
};
|
|
34
35
|
socket.value = ws;
|
|
35
36
|
}
|
|
36
|
-
function send(ws:
|
|
37
|
+
function send(ws: WebSocket) {
|
|
37
38
|
ws.send(message.value);
|
|
38
39
|
note(`→ ${message.value}`);
|
|
39
40
|
}
|
|
@@ -48,7 +49,7 @@ const embedded = ref(false);
|
|
|
48
49
|
title="Network"
|
|
49
50
|
lead='fetch and WebSocket as in a browser; responses are cached on disk (sk.config.json "httpCache").'
|
|
50
51
|
>
|
|
51
|
-
<Card title="fetch" :api="
|
|
52
|
+
<Card title="fetch" :api="online() ? 'online' : 'offline'">
|
|
52
53
|
<div class="row">
|
|
53
54
|
<button class="btn primary" @click="load">GET api.github.com/zen</button>
|
|
54
55
|
<span class="faint">{{ took }}</span>
|
|
@@ -3,7 +3,7 @@ import { appPermissions } from "@skathi-native/runtime";
|
|
|
3
3
|
import { onMounted, onUnmounted, ref } from "vue";
|
|
4
4
|
import Card from "../components/Card.vue";
|
|
5
5
|
import Page from "../components/Page.vue";
|
|
6
|
-
import { describe
|
|
6
|
+
import { describe } from "../engine";
|
|
7
7
|
|
|
8
8
|
const rows = ref(appPermissions.list());
|
|
9
9
|
const asking = ref("");
|
|
@@ -30,7 +30,7 @@ async function request(name: string) {
|
|
|
30
30
|
|
|
31
31
|
async function tryMicrophone() {
|
|
32
32
|
try {
|
|
33
|
-
const stream = await
|
|
33
|
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
34
34
|
status.value = stream.getAudioTracks()[0]?.label ?? "a microphone";
|
|
35
35
|
for (const track of stream.getTracks()) track.stop();
|
|
36
36
|
} catch (e) {
|
|
@@ -2,19 +2,18 @@
|
|
|
2
2
|
import { appStorage } from "@skathi-native/runtime";
|
|
3
3
|
import { onMounted, ref } from "vue";
|
|
4
4
|
import Card from "../components/Card.vue";
|
|
5
|
-
import Missing from "../components/Missing.vue";
|
|
6
5
|
import Page from "../components/Page.vue";
|
|
7
|
-
import { describe
|
|
6
|
+
import { describe } from "../engine";
|
|
8
7
|
import { appName } from "../product";
|
|
9
8
|
|
|
10
9
|
const visits = ref(0);
|
|
11
10
|
const note = ref("");
|
|
12
11
|
onMounted(() => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
note.value = storage.getItem("note") ?? "";
|
|
12
|
+
visits.value = Number(localStorage.getItem("visits") ?? 0) + 1;
|
|
13
|
+
localStorage.setItem("visits", String(visits.value));
|
|
14
|
+
note.value = localStorage.getItem("note") ?? "";
|
|
17
15
|
});
|
|
16
|
+
const saveNote = () => localStorage.setItem("note", note.value);
|
|
18
17
|
|
|
19
18
|
interface Todo {
|
|
20
19
|
id: number;
|
|
@@ -24,32 +23,31 @@ const todos = ref<Todo[]>([]);
|
|
|
24
23
|
const draft = ref("");
|
|
25
24
|
const status = ref("");
|
|
26
25
|
|
|
27
|
-
const done = <T,>(request:
|
|
26
|
+
const done = <T,>(request: IDBRequest<T>) =>
|
|
28
27
|
new Promise<T>((resolve, reject) => {
|
|
29
28
|
request.onsuccess = () => resolve(request.result);
|
|
30
29
|
request.onerror = () => reject(request.error);
|
|
31
30
|
});
|
|
32
31
|
|
|
33
|
-
let db:
|
|
32
|
+
let db: IDBDatabase | null = null;
|
|
34
33
|
async function store(mode: "readonly" | "readwrite") {
|
|
35
|
-
if (!idb) throw new Error("no IndexedDB");
|
|
36
34
|
if (!db) {
|
|
37
|
-
const open =
|
|
35
|
+
const open = indexedDB.open(appName, 1);
|
|
38
36
|
open.onupgradeneeded = () => open.result.createObjectStore("todos", { keyPath: "id", autoIncrement: true });
|
|
39
37
|
db = await done(open);
|
|
40
38
|
}
|
|
41
39
|
return db.transaction("todos", mode).objectStore("todos");
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
async function update(change?: (todos:
|
|
42
|
+
async function update(change?: (todos: IDBObjectStore) => IDBRequest) {
|
|
45
43
|
try {
|
|
46
44
|
if (change) await done(change(await store("readwrite")));
|
|
47
|
-
todos.value = await done((await store("readonly")).getAll() as
|
|
45
|
+
todos.value = await done((await store("readonly")).getAll() as IDBRequest<Todo[]>);
|
|
48
46
|
} catch (e) {
|
|
49
47
|
status.value = describe(e);
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
|
-
onMounted(() =>
|
|
50
|
+
onMounted(() => update());
|
|
53
51
|
|
|
54
52
|
function add() {
|
|
55
53
|
const text = draft.value.trim();
|
|
@@ -62,32 +60,21 @@ function add() {
|
|
|
62
60
|
<template>
|
|
63
61
|
<Page title="Storage" lead="The web's storage APIs, kept on disk in the app's own data folder between runs.">
|
|
64
62
|
<Card title="localStorage" api="localStorage">
|
|
65
|
-
<
|
|
66
|
-
|
|
67
|
-
<input
|
|
68
|
-
v-model="note"
|
|
69
|
-
class="input"
|
|
70
|
-
placeholder="A note that survives a restart"
|
|
71
|
-
@input="storage.setItem('note', note)"
|
|
72
|
-
/>
|
|
73
|
-
</template>
|
|
74
|
-
<Missing v-else part="storages" />
|
|
63
|
+
<p class="muted">This page was opened {{ visits }} times, counting earlier runs.</p>
|
|
64
|
+
<input v-model="note" class="input" placeholder="A note that survives a restart" @input="saveNote" />
|
|
75
65
|
</Card>
|
|
76
66
|
|
|
77
67
|
<Card title="IndexedDB" api="indexedDB">
|
|
78
|
-
<
|
|
79
|
-
<
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
<
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
<p v-if="status" class="faint">{{ status }}</p>
|
|
89
|
-
</template>
|
|
90
|
-
<Missing v-else part="indexeddb" />
|
|
68
|
+
<div class="row">
|
|
69
|
+
<input v-model="draft" class="input grow" placeholder="Something to do" @keyup.enter="add" />
|
|
70
|
+
<button class="btn primary" @click="add">Add</button>
|
|
71
|
+
</div>
|
|
72
|
+
<div v-for="todo in todos" :key="todo.id" class="todo">
|
|
73
|
+
<span>{{ todo.text }}</span>
|
|
74
|
+
<button class="btn" @click="update((s) => s.delete(todo.id))">Done</button>
|
|
75
|
+
</div>
|
|
76
|
+
<p v-if="!todos.length" class="faint">Nothing yet. Items are rows in a SQLite file under the data folder.</p>
|
|
77
|
+
<p v-if="status" class="faint">{{ status }}</p>
|
|
91
78
|
</Card>
|
|
92
79
|
|
|
93
80
|
<Card title="Where it goes" api="appStorage">
|
|
@@ -35,8 +35,12 @@ const hot = ref(false);
|
|
|
35
35
|
<div class="swatch frost">frost</div>
|
|
36
36
|
<div class="swatch noise">noise</div>
|
|
37
37
|
<div class="swatch glow" :class="{ hot }" @click="hot = !hot">glow · click</div>
|
|
38
|
+
<div class="swatch sheen">sheen</div>
|
|
38
39
|
</div>
|
|
39
|
-
<p class="faint">
|
|
40
|
+
<p class="faint">
|
|
41
|
+
Skathi's own effects, in a custom property that a browser simply ignores. sheen is this app's, from
|
|
42
|
+
shaders/sheen.slang.
|
|
43
|
+
</p>
|
|
40
44
|
</Card>
|
|
41
45
|
|
|
42
46
|
<Card title="Layout" api="grid · ::before · :hover">
|
|
@@ -156,6 +160,10 @@ const hot = ref(false);
|
|
|
156
160
|
.glow.hot {
|
|
157
161
|
--shading: glow(#ff2d95, 30px, 1);
|
|
158
162
|
}
|
|
163
|
+
.sheen {
|
|
164
|
+
background: linear-gradient(135deg, #3b3f9e, #8b5cf6);
|
|
165
|
+
--shading: sheen(0.5, #ffffffcc);
|
|
166
|
+
}
|
|
159
167
|
.grid {
|
|
160
168
|
display: grid;
|
|
161
169
|
grid-template-columns: 1fr 1fr 1fr;
|
|
@@ -3,7 +3,7 @@ import { appDevtools, appHost, appLaunch, appShell, appStorage, type SkLaunchEve
|
|
|
3
3
|
import { onMounted, onUnmounted, ref } from "vue";
|
|
4
4
|
import Card from "../components/Card.vue";
|
|
5
5
|
import Page from "../components/Page.vue";
|
|
6
|
-
import { describe
|
|
6
|
+
import { describe } from "../engine";
|
|
7
7
|
|
|
8
8
|
const status = ref("");
|
|
9
9
|
const launches = ref<string[]>([]);
|
|
@@ -19,7 +19,7 @@ async function run(action: Promise<void>) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
// Fires in the running app when the exe is started again under "singleInstance": true, or opened by a URL it owns.
|
|
22
|
-
const onLaunch = (event:
|
|
22
|
+
const onLaunch = (event: Event) => {
|
|
23
23
|
const { source, argv } = event as SkLaunchEvent;
|
|
24
24
|
launches.value = [`${source}: ${argv.join(" ")}`, ...launches.value].slice(0, 4);
|
|
25
25
|
};
|
|
@@ -37,7 +37,7 @@ onUnmounted(off);
|
|
|
37
37
|
<button class="btn" @click="run(appShell.openExternal('https://github.com/argon-chat/skathi'))">
|
|
38
38
|
Open the Skathi repository
|
|
39
39
|
</button>
|
|
40
|
-
<button v-if="
|
|
40
|
+
<button v-if="appStorage.folder" class="btn" @click="run(appShell.openPath(appStorage.folder))">
|
|
41
41
|
Open the data folder
|
|
42
42
|
</button>
|
|
43
43
|
<span class="faint">{{ status }}</span>
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
defineProps<{ part: string }>();
|
|
3
|
-
</script>
|
|
4
|
-
|
|
5
|
-
<template>
|
|
6
|
-
<div class="missing">
|
|
7
|
-
<span class="pill warn">{{ part }} left out</span>
|
|
8
|
-
<span class="muted">
|
|
9
|
-
This build has no <span class="mono">{{ part }}</span> engine part: sk.config.json lists it under
|
|
10
|
-
<span class="mono">"windows": { "without": [...] }</span>, which keeps the exe smaller. Take it out of that list
|
|
11
|
-
to bring the API back.
|
|
12
|
-
</span>
|
|
13
|
-
</div>
|
|
14
|
-
</template>
|
|
15
|
-
|
|
16
|
-
<style scoped>
|
|
17
|
-
.missing {
|
|
18
|
-
display: flex;
|
|
19
|
-
align-items: center;
|
|
20
|
-
gap: 12px;
|
|
21
|
-
padding: 14px;
|
|
22
|
-
border-radius: 10px;
|
|
23
|
-
border: 1px dashed #fbbf2440;
|
|
24
|
-
background: #fbbf240a;
|
|
25
|
-
}
|
|
26
|
-
</style>
|