@skathi-native/cli 0.1.0-beta.2 → 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.
- 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/cli/aot-build.ts +189 -0
- package/cli/build-app.ts +67 -25
- package/cli/config.ts +44 -101
- package/cli/create.ts +10 -53
- package/cli/help.ts +4 -5
- package/cli/host-fetch.ts +87 -48
- package/cli/host.ts +18 -8
- package/cli/sk.ts +16 -25
- package/cli/skpk.ts +4 -0
- package/package.json +3 -2
- package/templates/icon.png +0 -0
- package/templates/minimal/.vscode/settings.json +3 -0
- package/templates/showcase/.vscode/settings.json +3 -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/SystemPage.vue +3 -3
- package/templates/showcase/src/components/Missing.vue +0 -26
package/cli/host-fetch.ts
CHANGED
|
@@ -8,10 +8,12 @@
|
|
|
8
8
|
|
|
9
9
|
import { chmodSync, mkdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
10
10
|
import { dirname, join } from "node:path";
|
|
11
|
-
import {
|
|
11
|
+
import type { CompilerInfo } from "../aot/pin";
|
|
12
|
+
import type { Variant } from "./config";
|
|
12
13
|
import {
|
|
13
14
|
CLI_VERSION,
|
|
14
15
|
cachedHost,
|
|
16
|
+
cacheRoot,
|
|
15
17
|
HostError,
|
|
16
18
|
resolveHost,
|
|
17
19
|
type HostInfo,
|
|
@@ -35,14 +37,31 @@ export interface HostManifestEntry {
|
|
|
35
37
|
info: HostInfo;
|
|
36
38
|
}
|
|
37
39
|
|
|
40
|
+
/** sk-aot (`sk build --aot`), matching the release's hosts. */
|
|
41
|
+
export interface AotCompilerEntry {
|
|
42
|
+
platform: Platform;
|
|
43
|
+
arch: string;
|
|
44
|
+
/** The release asset: sk-aot, gzipped. */
|
|
45
|
+
file: string;
|
|
46
|
+
/** Of sk-aot itself, not of the gzip. */
|
|
47
|
+
sha256: string;
|
|
48
|
+
size: number;
|
|
49
|
+
/** What `sk-aot info` prints: the frontend, engine and builtin table it compiles for. */
|
|
50
|
+
info: CompilerInfo;
|
|
51
|
+
}
|
|
52
|
+
|
|
38
53
|
export interface HostManifest {
|
|
39
54
|
skathi: string;
|
|
40
55
|
hosts: HostManifestEntry[];
|
|
56
|
+
aot?: AotCompilerEntry[];
|
|
41
57
|
}
|
|
42
58
|
|
|
43
59
|
export const hostAssetName = (platform: Platform, arch: string, variant: Variant): string =>
|
|
44
60
|
`sk-host-${platform}-${arch}-${variant}${platform === "windows" ? ".exe" : ""}.gz`;
|
|
45
61
|
|
|
62
|
+
export const aotCompilerAssetName = (platform: Platform, arch: string): string =>
|
|
63
|
+
`sk-aot-${platform}-${arch}${platform === "windows" ? ".exe" : ""}.gz`;
|
|
64
|
+
|
|
46
65
|
export const sha256 = (bytes: Uint8Array): string =>
|
|
47
66
|
new Bun.CryptoHasher("sha256").update(new Uint8Array(bytes)).digest("hex");
|
|
48
67
|
|
|
@@ -75,14 +94,16 @@ async function download(asset: ReleaseAsset, headers: Record<string, string>): P
|
|
|
75
94
|
return new Uint8Array(await res.arrayBuffer());
|
|
76
95
|
}
|
|
77
96
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
97
|
+
interface Release {
|
|
98
|
+
tag: string;
|
|
99
|
+
repo: string;
|
|
100
|
+
headers: Record<string, string>;
|
|
101
|
+
manifest: HostManifest;
|
|
102
|
+
asset: (name: string) => ReleaseAsset | undefined;
|
|
103
|
+
}
|
|
85
104
|
|
|
105
|
+
async function readRelease(version: string): Promise<Release> {
|
|
106
|
+
const { repo, api, headers } = source();
|
|
86
107
|
const tag = `v${version}`;
|
|
87
108
|
const res = await fetch(`${api}/repos/${repo}/releases/tags/${tag}`, {
|
|
88
109
|
headers: { ...headers, Accept: "application/vnd.github+json" },
|
|
@@ -100,6 +121,41 @@ export async function fetchHost(options: FetchOptions): Promise<{ path: string;
|
|
|
100
121
|
const manifestAsset = asset(MANIFEST_NAME);
|
|
101
122
|
if (!manifestAsset) throw new HostError(`release ${tag} of github.com/${repo} has no ${MANIFEST_NAME}`);
|
|
102
123
|
const manifest = JSON.parse(new TextDecoder().decode(await download(manifestAsset, headers))) as HostManifest;
|
|
124
|
+
return { tag, repo, headers, manifest, asset };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Gunzips `name` and writes it to `dest` only when it matches `size` and `sha256`. */
|
|
128
|
+
async function cacheAsset(
|
|
129
|
+
release: Release,
|
|
130
|
+
name: string,
|
|
131
|
+
size: number,
|
|
132
|
+
digest: string,
|
|
133
|
+
dest: string,
|
|
134
|
+
log: (line: string) => void,
|
|
135
|
+
): Promise<void> {
|
|
136
|
+
const asset = release.asset(name);
|
|
137
|
+
if (!asset) throw new HostError(`release ${release.tag} lists ${name} in ${MANIFEST_NAME} but does not carry it`);
|
|
138
|
+
log(`downloading ${name} (${(asset.size / 1048576).toFixed(1)} MB) from github.com/${release.repo} ${release.tag}`);
|
|
139
|
+
const bytes = Bun.gunzipSync(await download(asset, release.headers));
|
|
140
|
+
if (bytes.length !== size || sha256(bytes) !== digest) {
|
|
141
|
+
throw new HostError(`${name} does not match the sha256 in ${MANIFEST_NAME}; nothing was cached`);
|
|
142
|
+
}
|
|
143
|
+
mkdirSync(dirname(dest), { recursive: true });
|
|
144
|
+
const tmp = `${dest}.partial`;
|
|
145
|
+
writeFileSync(tmp, bytes);
|
|
146
|
+
if (process.platform !== "win32") chmodSync(tmp, 0o755);
|
|
147
|
+
rmSync(dest, { force: true });
|
|
148
|
+
renameSync(tmp, dest);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Downloads the host for `variant` from the release of `version` into the local cache, checked against `hosts.json`. */
|
|
152
|
+
export async function fetchHost(options: FetchOptions): Promise<{ path: string; info: HostInfo }> {
|
|
153
|
+
const version = options.version ?? CLI_VERSION;
|
|
154
|
+
const platform = options.platform ?? currentPlatform();
|
|
155
|
+
const arch = options.arch ?? process.arch;
|
|
156
|
+
const log = options.log ?? (() => {});
|
|
157
|
+
const release = await readRelease(version);
|
|
158
|
+
const { manifest, tag } = release;
|
|
103
159
|
const entry = manifest.hosts.find((h) => h.platform === platform && h.arch === arch && h.variant === options.variant);
|
|
104
160
|
if (!entry) {
|
|
105
161
|
const offered = manifest.hosts
|
|
@@ -111,63 +167,46 @@ export async function fetchHost(options: FetchOptions): Promise<{ path: string;
|
|
|
111
167
|
(offered ? ` (it has: ${offered}); other variants are built from a checkout with sk host build` : ""),
|
|
112
168
|
);
|
|
113
169
|
}
|
|
114
|
-
const hostAsset = asset(entry.file);
|
|
115
|
-
if (!hostAsset) throw new HostError(`release ${tag} lists ${entry.file} in ${MANIFEST_NAME} but does not carry it`);
|
|
116
|
-
|
|
117
|
-
log(`downloading ${entry.file} (${(hostAsset.size / 1048576).toFixed(1)} MB) from github.com/${repo} ${tag}`);
|
|
118
|
-
const bytes = Bun.gunzipSync(await download(hostAsset, headers));
|
|
119
|
-
if (bytes.length !== entry.size || sha256(bytes) !== entry.sha256) {
|
|
120
|
-
throw new HostError(`${entry.file} does not match the sha256 in ${MANIFEST_NAME}; nothing was cached`);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
170
|
const dest = cachedHost(version, options.variant, platform);
|
|
124
|
-
|
|
125
|
-
const tmp = `${dest}.partial`;
|
|
126
|
-
writeFileSync(tmp, bytes);
|
|
127
|
-
if (process.platform !== "win32") chmodSync(tmp, 0o755);
|
|
128
|
-
rmSync(dest, { force: true });
|
|
129
|
-
renameSync(tmp, dest);
|
|
171
|
+
await cacheAsset(release, entry.file, entry.size, entry.sha256, dest, log);
|
|
130
172
|
writeFileSync(join(dirname(dest), "host.json"), JSON.stringify(entry.info, null, 2) + "\n");
|
|
131
173
|
log(`cached ${options.variant} host ${version} → ${dest}`);
|
|
132
174
|
return { path: dest, info: entry.info };
|
|
133
175
|
}
|
|
134
176
|
|
|
135
|
-
/**
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
177
|
+
/** Where the sk-aot of Skathi `version` is cached. */
|
|
178
|
+
export const cachedAotCompiler = (version: string, platform: Platform = currentPlatform()) =>
|
|
179
|
+
join(cacheRoot(platform), version, "aot", `sk-aot${platform === "windows" ? ".exe" : ""}`);
|
|
180
|
+
|
|
181
|
+
/** Downloads sk-aot from the release of `version` into the local cache, checked against `hosts.json`. */
|
|
182
|
+
export async function fetchAotCompiler(
|
|
183
|
+
options: Omit<FetchOptions, "variant"> = {},
|
|
184
|
+
): Promise<{ path: string; info: CompilerInfo }> {
|
|
185
|
+
const version = options.version ?? CLI_VERSION;
|
|
186
|
+
const platform = options.platform ?? currentPlatform();
|
|
187
|
+
const arch = options.arch ?? process.arch;
|
|
188
|
+
const log = options.log ?? (() => {});
|
|
189
|
+
const release = await readRelease(version);
|
|
190
|
+
const entry = release.manifest.aot?.find((c) => c.platform === platform && c.arch === arch);
|
|
191
|
+
if (!entry) throw new HostError(`release ${release.tag} has no sk-aot for ${platform}-${arch}`);
|
|
192
|
+
const dest = cachedAotCompiler(version, platform);
|
|
193
|
+
await cacheAsset(release, entry.file, entry.size, entry.sha256, dest, log);
|
|
194
|
+
writeFileSync(join(dirname(dest), "compiler.json"), JSON.stringify(entry.info, null, 2) + "\n");
|
|
195
|
+
log(`cached sk-aot ${version} → ${dest}`);
|
|
196
|
+
return { path: dest, info: entry.info };
|
|
146
197
|
}
|
|
147
198
|
|
|
148
199
|
/**
|
|
149
200
|
* {@link resolveHost}, and when it finds nothing for this OS and no host was named, a download into the
|
|
150
|
-
* cache first.
|
|
151
|
-
* so. SK_HOST_OFFLINE=1 turns the download off.
|
|
201
|
+
* cache first. SK_HOST_OFFLINE=1 turns the download off.
|
|
152
202
|
*/
|
|
153
|
-
export async function resolveOrFetchHost(options: ResolveOptions): Promise<ResolvedHost
|
|
203
|
+
export async function resolveOrFetchHost(options: ResolveOptions): Promise<ResolvedHost> {
|
|
154
204
|
try {
|
|
155
205
|
return resolveHost(options);
|
|
156
206
|
} catch (e) {
|
|
157
207
|
const named = options.host ?? process.env.SK_HOST;
|
|
158
208
|
const cross = (options.platform ?? currentPlatform()) !== currentPlatform();
|
|
159
209
|
if (!(e instanceof HostError) || named || cross || process.env.SK_HOST_OFFLINE === "1") throw e;
|
|
160
|
-
const instead = VARIANTS.includes(options.variant) ? null : standIn(options.variant);
|
|
161
|
-
if (instead) {
|
|
162
|
-
const host = await resolveOrFetchHost({ ...options, variant: instead });
|
|
163
|
-
const extra = partsLeftOut(instead).length < partsLeftOut(options.variant).length;
|
|
164
|
-
return {
|
|
165
|
-
...host,
|
|
166
|
-
substitute:
|
|
167
|
-
`no prebuilt ${options.variant} host: using ${instead}` +
|
|
168
|
-
(extra ? ", which also carries parts this app leaves out (sk host build makes an exact one)" : ""),
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
210
|
try {
|
|
172
211
|
await fetchHost({ variant: options.variant, ...(options.log && { log: options.log }) });
|
|
173
212
|
} catch (f) {
|
package/cli/host.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Where `sk build` gets the prebuilt bare host it stamps: `cargo build --release -p sk-app
|
|
2
|
-
// --features prod` (the whole engine, no app), built once per Skathi version and variant
|
|
3
|
-
//
|
|
2
|
+
// --features prod` (the whole engine, no app), built once per Skathi version and variant: `standard`, or
|
|
3
|
+
// `no-devtools` with the devtools compiled out.
|
|
4
4
|
//
|
|
5
5
|
// Resolution, first hit wins: 1. `--host <exe>` or `SK_HOST`; 2. in-repo
|
|
6
6
|
// target/x86_64-pc-windows-msvc/release/sk-app.exe, when that is a prod host of this variant and
|
|
@@ -29,7 +29,8 @@ import {
|
|
|
29
29
|
} from "node:fs";
|
|
30
30
|
import { homedir } from "node:os";
|
|
31
31
|
import { dirname, join, resolve } from "node:path";
|
|
32
|
-
import {
|
|
32
|
+
import type { CompilerInfo } from "../aot/pin";
|
|
33
|
+
import { cargoFeatureArgs, ENGINE_FEATURES, VARIANTS, type Variant } from "./config";
|
|
33
34
|
import { appendedPayloadOf, elfMachineOf } from "./elf";
|
|
34
35
|
import { bundlePayloadPath, machOArchs } from "./macos-bundle";
|
|
35
36
|
import { readPe, RT } from "./pe";
|
|
@@ -56,6 +57,13 @@ export interface HostInfo {
|
|
|
56
57
|
jscPin: string;
|
|
57
58
|
payloadFormat: number;
|
|
58
59
|
profile: string;
|
|
60
|
+
/** A host built with the native AOT loader: what an app image must be compiled against. */
|
|
61
|
+
aot?: HostAot | null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface HostAot extends CompilerInfo {
|
|
65
|
+
transform: string;
|
|
66
|
+
preludeSha256: string;
|
|
59
67
|
}
|
|
60
68
|
|
|
61
69
|
export interface ResolvedHost {
|
|
@@ -110,14 +118,14 @@ export function crossHostInfo(
|
|
|
110
118
|
}
|
|
111
119
|
} catch {}
|
|
112
120
|
}
|
|
113
|
-
const
|
|
121
|
+
const devtools = variant !== "no-devtools";
|
|
114
122
|
const info: HostInfo = {
|
|
115
123
|
mode: "prod",
|
|
116
124
|
skathi: CLI_VERSION,
|
|
117
125
|
crate: "unknown",
|
|
118
126
|
variant,
|
|
119
|
-
devtools
|
|
120
|
-
features: ["prod", ...
|
|
127
|
+
devtools,
|
|
128
|
+
features: ["prod", ...(devtools ? [] : ["no-devtools"]), ...ENGINE_FEATURES],
|
|
121
129
|
jscPin: "unknown",
|
|
122
130
|
payloadFormat: 1,
|
|
123
131
|
profile: "unknown",
|
|
@@ -173,9 +181,11 @@ export function checkHost(exe: string, info: HostInfo, variant: Variant | null,
|
|
|
173
181
|
}
|
|
174
182
|
if (info.mode !== "prod") return `${exe} is a ${info.mode} host — sk build needs one built with --features prod`;
|
|
175
183
|
if (variant && info.variant !== variant) return `${exe} is the ${info.variant} variant, not ${variant}`;
|
|
176
|
-
if (!
|
|
177
|
-
return `${exe}
|
|
184
|
+
if (!VARIANTS.includes(info.variant)) {
|
|
185
|
+
return `${exe} is the ${info.variant} variant, which leaves engine parts out — sk build stamps only ${VARIANTS.join(" or ")} hosts`;
|
|
178
186
|
}
|
|
187
|
+
const missing = ENGINE_FEATURES.filter((f) => !info.features?.includes(f));
|
|
188
|
+
if (missing.length) return `${exe} lacks ${missing.join(", ")} — rebuild or replace the cached host`;
|
|
179
189
|
return mismatch;
|
|
180
190
|
}
|
|
181
191
|
|
package/cli/sk.ts
CHANGED
|
@@ -3,17 +3,9 @@
|
|
|
3
3
|
// Rust toolchain.
|
|
4
4
|
|
|
5
5
|
import { spawn } from "node:child_process";
|
|
6
|
+
import { aotFlags } from "./aot-build";
|
|
6
7
|
import { buildApp, summary } from "./build-app";
|
|
7
|
-
import {
|
|
8
|
-
ConfigError,
|
|
9
|
-
OPTIONAL,
|
|
10
|
-
parseParts,
|
|
11
|
-
partsLeftOut,
|
|
12
|
-
selectVariant,
|
|
13
|
-
VARIANTS,
|
|
14
|
-
variantFor,
|
|
15
|
-
type Variant,
|
|
16
|
-
} from "./config";
|
|
8
|
+
import { ConfigError, parseVariant, PARTS_NOT_SELECTABLE, VARIANTS, type Variant } from "./config";
|
|
17
9
|
import { dev } from "./dev";
|
|
18
10
|
import { addHost, buildHost, CLI_VERSION, DEV_HOST, HostError, hostInfo, resolveHost } from "./host";
|
|
19
11
|
import { fetchHost } from "./host-fetch";
|
|
@@ -31,6 +23,8 @@ const BOOLEAN = new Set([
|
|
|
31
23
|
"payload-only",
|
|
32
24
|
"allow-host-mismatch",
|
|
33
25
|
"aot-inputs",
|
|
26
|
+
"aot",
|
|
27
|
+
"no-aot",
|
|
34
28
|
"help",
|
|
35
29
|
"version",
|
|
36
30
|
"json",
|
|
@@ -76,21 +70,15 @@ function parse(argv: string[]): {
|
|
|
76
70
|
return { positional, flags, repeated, rest };
|
|
77
71
|
}
|
|
78
72
|
|
|
73
|
+
function refuseParts(flags: Flags): void {
|
|
74
|
+
for (const gone of ["without", "features"]) {
|
|
75
|
+
if (flags[gone] !== undefined) throw new ConfigError(`--${gone}: ${PARTS_NOT_SELECTABLE}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
79
|
function variantOf(flags: Flags): Variant | undefined {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (v === undefined) return undefined;
|
|
83
|
-
if (typeof v !== "string" || !v.trim())
|
|
84
|
-
throw new ConfigError(`--${name} needs a list of parts (${OPTIONAL.join(", ")})`);
|
|
85
|
-
return parseParts(v, `--${name}`);
|
|
86
|
-
};
|
|
87
|
-
const host = flags.variant;
|
|
88
|
-
if (host !== undefined && (typeof host !== "string" || !host.trim()))
|
|
89
|
-
throw new ConfigError("--variant needs a variant name");
|
|
90
|
-
const sel = { features: list("features"), without: list("without"), host: host as string | undefined };
|
|
91
|
-
if (!sel.features && !sel.without && !sel.host) return undefined;
|
|
92
|
-
// Normalised: `no-audio+no-devtools` and `no-devtools+no-audio` are one host.
|
|
93
|
-
return variantFor(partsLeftOut(selectVariant(sel, "the command line")));
|
|
80
|
+
refuseParts(flags);
|
|
81
|
+
return flags.variant === undefined ? undefined : parseVariant(flags.variant, "--variant");
|
|
94
82
|
}
|
|
95
83
|
|
|
96
84
|
async function main(argv: string[]): Promise<number> {
|
|
@@ -139,6 +127,8 @@ async function main(argv: string[]): Promise<number> {
|
|
|
139
127
|
allowHostMismatch: flags["allow-host-mismatch"] === true,
|
|
140
128
|
defines: repeated.define,
|
|
141
129
|
aotInputs: flags["aot-inputs"] === true,
|
|
130
|
+
...aotFlags(flags),
|
|
131
|
+
color: colorEnabled(process.stderr, colorFlag(flags)),
|
|
142
132
|
platform,
|
|
143
133
|
sign: flags["no-sign"] ? false : typeof flags.sign === "string" ? flags.sign.trim() : undefined,
|
|
144
134
|
mode: command === "publish" ? "release" : "debug",
|
|
@@ -150,6 +140,7 @@ async function main(argv: string[]): Promise<number> {
|
|
|
150
140
|
exe: result.exe,
|
|
151
141
|
skpk: result.skpk,
|
|
152
142
|
aotInputs: result.aotInputs,
|
|
143
|
+
native: result.native,
|
|
153
144
|
name: result.config.name,
|
|
154
145
|
productName: result.config.productName,
|
|
155
146
|
version: result.config.version,
|
|
@@ -255,12 +246,12 @@ async function main(argv: string[]): Promise<number> {
|
|
|
255
246
|
}
|
|
256
247
|
|
|
257
248
|
if (command === "create") {
|
|
249
|
+
refuseParts(flags);
|
|
258
250
|
const str = (k: string) => (typeof flags[k] === "string" ? (flags[k] as string) : undefined);
|
|
259
251
|
const yesNo = (k: string) => (flags[k] ? true : flags[`no-${k}`] ? false : undefined);
|
|
260
252
|
return await createCommand(args[0], {
|
|
261
253
|
name: str("name"),
|
|
262
254
|
os: str("os"),
|
|
263
|
-
without: str("without"),
|
|
264
255
|
devtools: yesNo("devtools"),
|
|
265
256
|
template: str("template"),
|
|
266
257
|
pm: str("pm"),
|
package/cli/skpk.ts
CHANGED
|
@@ -25,6 +25,8 @@ export const KIND = {
|
|
|
25
25
|
WINDOW: 2,
|
|
26
26
|
SCRIPT: 3,
|
|
27
27
|
BYTECODE: 4,
|
|
28
|
+
NATIVE_MANIFEST: 5,
|
|
29
|
+
NATIVE_IMAGE: 6,
|
|
28
30
|
ASSET: 16,
|
|
29
31
|
} as const;
|
|
30
32
|
|
|
@@ -33,6 +35,8 @@ export const NAMES = {
|
|
|
33
35
|
WINDOW: "sk/window.json",
|
|
34
36
|
SCRIPT: "sk/app.js",
|
|
35
37
|
BYTECODE: "sk/app.bc",
|
|
38
|
+
NATIVE_MANIFEST: "sk/app.native.json",
|
|
39
|
+
NATIVE_IMAGE: "sk/app.image",
|
|
36
40
|
} as const;
|
|
37
41
|
|
|
38
42
|
export const FLAG_HAS_BYTECODE = 1;
|
package/package.json
CHANGED
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
"url": "git+https://github.com/argon-chat/skathi.git",
|
|
7
7
|
"directory": "packages/cli"
|
|
8
8
|
},
|
|
9
|
-
"version": "0.1.0-beta.
|
|
9
|
+
"version": "0.1.0-beta.3",
|
|
10
10
|
"type": "module",
|
|
11
11
|
"files": [
|
|
12
|
+
"aot",
|
|
12
13
|
"cli",
|
|
13
14
|
"check",
|
|
14
15
|
"templates",
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
33
|
"@clack/prompts": "^1.9.0",
|
|
33
|
-
"@skathi-native/runtime": "0.1.0-beta.
|
|
34
|
+
"@skathi-native/runtime": "0.1.0-beta.3",
|
|
34
35
|
"@vue/compiler-sfc": "^3.5.41",
|
|
35
36
|
"postcss": "^8.4.31",
|
|
36
37
|
"tailwindcss": "3.4",
|
|
Binary file
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
// strip drag the window, and `--window-control` on each button gives it the OS behaviour (snap layouts on maximize).
|
|
4
4
|
import { appWindow } from "@skathi-native/runtime";
|
|
5
5
|
import { onMounted, onUnmounted, ref } from "vue";
|
|
6
|
-
import { nav } from "../engine";
|
|
7
6
|
import { productName } from "../product";
|
|
8
7
|
|
|
9
8
|
defineProps<{ page: string }>();
|
|
@@ -16,12 +15,12 @@ const read = () => {
|
|
|
16
15
|
};
|
|
17
16
|
|
|
18
17
|
onMounted(() => {
|
|
19
|
-
|
|
18
|
+
navigator.windowControlsOverlay.addEventListener("geometrychange", read);
|
|
20
19
|
appWindow.addEventListener("maximize", read);
|
|
21
20
|
appWindow.addEventListener("unmaximize", read);
|
|
22
21
|
});
|
|
23
22
|
onUnmounted(() => {
|
|
24
|
-
|
|
23
|
+
navigator.windowControlsOverlay.removeEventListener("geometrychange", read);
|
|
25
24
|
appWindow.removeEventListener("maximize", read);
|
|
26
25
|
appWindow.removeEventListener("unmaximize", read);
|
|
27
26
|
});
|
|
@@ -63,6 +62,11 @@ onUnmounted(() => {
|
|
|
63
62
|
user-select: none;
|
|
64
63
|
border-bottom: 1px solid var(--line);
|
|
65
64
|
}
|
|
65
|
+
@media (display-mode: fullscreen) {
|
|
66
|
+
.titlebar {
|
|
67
|
+
display: none;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
66
70
|
.brand {
|
|
67
71
|
display: flex;
|
|
68
72
|
align-items: center;
|
|
@@ -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>
|