sepal 0.0.0-stage → 0.1.0-alpha.1

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 (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +79 -2
  3. package/ambient.d.ts +20 -0
  4. package/cli.js +70 -0
  5. package/package.json +126 -3
  6. package/src/base64.js +42 -0
  7. package/src/clipboard.js +13 -0
  8. package/src/dialog.js +47 -0
  9. package/src/dom.js +1263 -0
  10. package/src/fetch.js +114 -0
  11. package/src/fs.js +71 -0
  12. package/src/host-call.js +42 -0
  13. package/src/index.js +54 -0
  14. package/src/protocol.js +32 -0
  15. package/src/renderer.js +659 -0
  16. package/src/shell.js +13 -0
  17. package/src/shims.js +229 -0
  18. package/src/text.js +87 -0
  19. package/src/updater.js +48 -0
  20. package/src/url.js +339 -0
  21. package/src/window.js +50 -0
  22. package/types/base64.d.ts +9 -0
  23. package/types/cli.d.ts +2 -0
  24. package/types/clipboard.d.ts +4 -0
  25. package/types/dialog.d.ts +46 -0
  26. package/types/dom.d.ts +12 -0
  27. package/types/fetch.d.ts +56 -0
  28. package/types/fs.d.ts +38 -0
  29. package/types/host-call.d.ts +13 -0
  30. package/types/index.d.ts +17 -0
  31. package/types/protocol.d.ts +21 -0
  32. package/types/renderer.d.ts +204 -0
  33. package/types/shell.d.ts +7 -0
  34. package/types/shims.d.ts +29 -0
  35. package/types/text.d.ts +21 -0
  36. package/types/updater.d.ts +38 -0
  37. package/types/url.d.ts +53 -0
  38. package/types/vite/app.d.ts +36 -0
  39. package/types/vite/bindings.d.ts +2 -0
  40. package/types/vite/head.d.ts +2 -0
  41. package/types/vite/navigation.d.ts +1 -0
  42. package/types/vite/router-entry.d.ts +1 -0
  43. package/types/vite/router.d.ts +21 -0
  44. package/types/vite/routes.d.ts +41 -0
  45. package/types/vite/routing.svelte.d.ts +131 -0
  46. package/types/vite/state.d.ts +1 -0
  47. package/types/vite/sveltekit.d.ts +28 -0
  48. package/types/vite/vite.d.ts +181 -0
  49. package/types/window.d.ts +20 -0
  50. package/vite/Router.svelte +32 -0
  51. package/vite/RouterError.svelte +11 -0
  52. package/vite/app.js +124 -0
  53. package/vite/bindings.js +99 -0
  54. package/vite/head.js +79 -0
  55. package/vite/icon.png +0 -0
  56. package/vite/navigation.js +3 -0
  57. package/vite/router-entry.js +12 -0
  58. package/vite/router.js +17 -0
  59. package/vite/routes.js +219 -0
  60. package/vite/routing.svelte.js +378 -0
  61. package/vite/state.js +2 -0
  62. package/vite/sveltekit.js +219 -0
  63. package/vite/virtual.d.ts +9 -0
  64. package/vite/vite.js +278 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ethercorps
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,80 @@
1
- # Temporary Holding Version
1
+ # sepal
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Native Svelte apps, drawn by Blitz.**
4
+
5
+ [Sepal](https://github.com/etherCorps/sepal): Svelte apps in a native window, without
6
+ a webview and without Node at run time. Svelte components are compiled with
7
+ Svelte's custom renderer API and drive [Blitz](https://github.com/DioxusLabs/blitz),
8
+ a Rust HTML/CSS engine; the JavaScript runs in an embedded QuickJS.
9
+
10
+ An alpha, on macOS (Linux builds and passes its tests headless; its window has
11
+ not been tried yet). Svelte 5 and Tailwind v4 as on the web, pages as files
12
+ (Sepal's router or SvelteKit's), shadcn-svelte components through an opt-in
13
+ DOM layer, desktop APIs behind permissions, macOS `.app` bundles and
14
+ self-update, and no frame loop: an idle app does no work.
15
+
16
+ ![The Tracker example in a Sepal window on macOS](https://raw.githubusercontent.com/etherCorps/sepal/main/docs/tracker.png)
17
+
18
+ The Tracker example with 1,000 issues, on an Apple M4 Pro (medians of three
19
+ runs; [how they were measured](https://github.com/etherCorps/sepal/blob/main/compare/results/compare.md)):
20
+
21
+ | | |
22
+ |---|---|
23
+ | Idle CPU, 1,000 issues | 4 ms of CPU time in 20 s, 0.02% of a core |
24
+ | Idle memory, 1,000 issues | 107 MB RAM, 43 MB GPU memory |
25
+ | Memory after wheel-scrolling the whole list, 1,000 issues | 305 MB RAM, 220 MB GPU memory |
26
+
27
+ This one package is the runtime, the Vite preset and the `sepal` command; the
28
+ prebuilt host comes with it. Start a project with the starter rather than by
29
+ installing it directly:
30
+
31
+ ```sh
32
+ pnpm create sepal my-app
33
+ ```
34
+
35
+ What is in here:
36
+
37
+ | Import | |
38
+ |---|---|
39
+ | `sepal` | `mount`, `unmount` |
40
+ | `sepal/fs`, `sepal/dialog`, `sepal/clipboard`, `sepal/shell`, `sepal/window` | desktop APIs, each behind a permission in `sepal.config.ts` |
41
+ | `sepal/updater` | self-update |
42
+ | `sepal/dom` | a small DOM for component libraries written for the web (`dom: true`) |
43
+ | `sepal/renderer`, `sepal/protocol` | what the Vite preset and the host are built against |
44
+ | `sepal/vite` | the Vite preset, `sepal()`, and `defineConfig` for `sepal.config.ts` |
45
+ | `sepal/sveltekit` | `sepalKit()`, which takes the place of both `sveltekit()` and the adapter |
46
+ | `sepal/router`, `sepal/navigation`, `sepal/state` | the file-based router (`src/routes`, `$app/navigation`, `$app/state`) |
47
+ | `sepal/ambient` | types for `$app/*`; add it to `types` in tsconfig.json |
48
+
49
+ The preset compiles Svelte for the Blitz renderer, writes the one `app.js` and
50
+ `app.css` the host loads, reads `sepal.config.ts`, and in `vite build --watch`
51
+ opens the app and reloads it on save.
52
+
53
+ ```ts
54
+ // vite.config.ts
55
+ import { sepal } from 'sepal/vite';
56
+ export default { plugins: [sepal()] };
57
+ ```
58
+
59
+ ```ts
60
+ // sepal.config.ts
61
+ import { defineConfig } from 'sepal/vite';
62
+ export default defineConfig({ app: { name: 'My App' } });
63
+ ```
64
+
65
+ The `sepal` command runs, bundles and screenshots a built app:
66
+
67
+ ```
68
+ sepal run [dist] open the built app in a window
69
+ sepal bundle [dist] [out-dir] [--sign <identity>] [--notarize <keychain-profile>]
70
+ [--update-key <private-key-file>] [--update-notes <text>]
71
+ build a macOS .app; with a key, also the signed update
72
+ sepal signer generate <private-key-file> make the key pair updates are signed with
73
+ sepal screenshot <out.png> [dist] [WIDTHxHEIGHT]
74
+ ```
75
+
76
+ Building is Vite's job: `vite build`, and `vite build --watch` for dev.
77
+ `fetch`, `console` and timers are globals. Everything else is in the
78
+ [documentation](https://github.com/etherCorps/sepal#readme).
79
+
80
+ MIT
package/ambient.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ // Module names the Vite preset provides. Add
2
+ // "sepal/ambient" to `types` in tsconfig.json.
3
+
4
+ declare module '$app/navigation' {
5
+ export * from 'sepal/navigation';
6
+ }
7
+
8
+ declare module '$app/state' {
9
+ export * from 'sepal/state';
10
+ }
11
+
12
+ // The route table generated from the routes directory. The built-in router
13
+ // runs on it; a router of your own can import it too.
14
+ declare module 'virtual:sepal/routes' {
15
+ import type { Route, RouteNode } from 'sepal/router';
16
+ import type { Component } from 'svelte';
17
+
18
+ export const routes: Route[];
19
+ export const fallback: { layouts: RouteNode[]; error: Component<any> | null };
20
+ }
package/cli.js ADDED
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env node
2
+ // The sepal command: run, bundle and screenshot an app.
3
+ // Building is Vite's job (`vite build`, and `vite build --watch` for dev).
4
+
5
+ import { spawnSync } from 'node:child_process';
6
+ import { readFileSync } from 'node:fs';
7
+ import { find_host, platform_package } from '@ethercorps/calyx';
8
+
9
+ const own = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
10
+
11
+ const USAGE = `usage:
12
+ sepal run [dist] open the built app in a window
13
+ sepal bundle [dist] [out-dir] [--sign <identity>] [--notarize <keychain-profile>]
14
+ [--update-key <private-key-file>] [--update-notes <text>]
15
+ build a macOS .app; with a key, also the signed update
16
+ sepal signer generate <private-key-file> make the key pair updates are signed with
17
+ sepal screenshot <out.png> [dist] [WIDTHxHEIGHT]
18
+
19
+ Build first with \`vite build\`. For dev, \`vite build --watch\` opens the app
20
+ and reloads it on every save.
21
+ To start a project: pnpm create sepal my-app`;
22
+
23
+ /** @param {string} message @returns {never} */
24
+ function fail(message) {
25
+ console.error(message);
26
+ process.exit(1);
27
+ }
28
+
29
+ /** Run the host with these arguments and exit with its status. @param {string[]} args @returns {never} */
30
+ function host(args) {
31
+ /** @type {ReturnType<typeof find_host>} */
32
+ let found;
33
+ try {
34
+ found = find_host();
35
+ } catch (error) {
36
+ fail(`sepal: ${/** @type {Error} */ (error).message}`);
37
+ }
38
+ // The pins are exact (sepal -> calyx -> the platform package), so this only
39
+ // happens to a node_modules put together by hand or half updated. A
40
+ // calyx from SEPAL_HOST is the user's choice and is not checked.
41
+ if (found.version !== null && found.version !== own.version) {
42
+ fail(
43
+ `sepal: this is sepal ${own.version}, but its calyx binary (${platform_package()}) is ${found.version}.\n` +
44
+ `They have to be the same version. Reinstall sepal@${own.version} (or remove node_modules and install\n` +
45
+ 'again). To run a different calyx on purpose, point SEPAL_HOST at it.'
46
+ );
47
+ }
48
+ const { status, error } = spawnSync(found.path, args, { stdio: 'inherit' });
49
+ if (error) fail(`sepal: cannot start ${found.path}: ${error.message}`);
50
+ process.exit(status ?? 1);
51
+ }
52
+
53
+ const [command, ...args] = process.argv.slice(2);
54
+ // `bundle --sign x` with no directory still means `dist`.
55
+ const dist = args[0] !== undefined && !args[0].startsWith('--') ? args : ['dist', ...args];
56
+
57
+ switch (command) {
58
+ case 'run':
59
+ host(dist);
60
+ case 'bundle':
61
+ host(['--bundle', ...dist]);
62
+ case 'signer':
63
+ if (args[0] !== 'generate' || !args[1]) fail(USAGE);
64
+ host(['--updater-keygen', args[1]]);
65
+ case 'screenshot':
66
+ if (!args[0]) fail(USAGE);
67
+ host(['--screenshot', args[0], ...(args.length > 1 ? args.slice(1) : ['dist'])]);
68
+ default:
69
+ fail(USAGE);
70
+ }
package/package.json CHANGED
@@ -1,6 +1,129 @@
1
1
  {
2
2
  "name": "sepal",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "Native Svelte apps, drawn by Blitz: a Svelte custom renderer for the Blitz HTML/CSS engine, its Vite preset and the sepal command",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/etherCorps/sepal.git",
9
+ "directory": "packages/sepal"
10
+ },
11
+ "homepage": "https://github.com/etherCorps/sepal#readme",
12
+ "bugs": "https://github.com/etherCorps/sepal/issues",
13
+ "engines": {
14
+ "node": ">=22"
15
+ },
16
+ "keywords": [
17
+ "svelte",
18
+ "blitz",
19
+ "desktop",
20
+ "native",
21
+ "renderer",
22
+ "gui",
23
+ "vite",
24
+ "vite-plugin",
25
+ "router",
26
+ "svelte-blitz"
27
+ ],
28
+ "type": "module",
29
+ "bin": {
30
+ "sepal": "./cli.js"
31
+ },
32
+ "exports": {
33
+ ".": {
34
+ "types": "./types/index.d.ts",
35
+ "default": "./src/index.js"
36
+ },
37
+ "./renderer": {
38
+ "types": "./types/renderer.d.ts",
39
+ "default": "./src/renderer.js"
40
+ },
41
+ "./protocol": {
42
+ "types": "./types/protocol.d.ts",
43
+ "default": "./src/protocol.js"
44
+ },
45
+ "./updater": {
46
+ "types": "./types/updater.d.ts",
47
+ "default": "./src/updater.js"
48
+ },
49
+ "./fs": {
50
+ "types": "./types/fs.d.ts",
51
+ "default": "./src/fs.js"
52
+ },
53
+ "./dialog": {
54
+ "types": "./types/dialog.d.ts",
55
+ "default": "./src/dialog.js"
56
+ },
57
+ "./clipboard": {
58
+ "types": "./types/clipboard.d.ts",
59
+ "default": "./src/clipboard.js"
60
+ },
61
+ "./shell": {
62
+ "types": "./types/shell.d.ts",
63
+ "default": "./src/shell.js"
64
+ },
65
+ "./window": {
66
+ "types": "./types/window.d.ts",
67
+ "default": "./src/window.js"
68
+ },
69
+ "./dom": {
70
+ "types": "./types/dom.d.ts",
71
+ "default": "./src/dom.js"
72
+ },
73
+ "./vite": {
74
+ "types": "./types/vite/vite.d.ts",
75
+ "default": "./vite/vite.js"
76
+ },
77
+ "./sveltekit": {
78
+ "types": "./types/vite/sveltekit.d.ts",
79
+ "default": "./vite/sveltekit.js"
80
+ },
81
+ "./router": {
82
+ "types": "./types/vite/router.d.ts",
83
+ "default": "./vite/router.js"
84
+ },
85
+ "./navigation": {
86
+ "types": "./types/vite/navigation.d.ts",
87
+ "default": "./vite/navigation.js"
88
+ },
89
+ "./state": {
90
+ "types": "./types/vite/state.d.ts",
91
+ "default": "./vite/state.js"
92
+ },
93
+ "./ambient": {
94
+ "types": "./ambient.d.ts"
95
+ }
96
+ },
97
+ "files": [
98
+ "src",
99
+ "vite",
100
+ "types",
101
+ "ambient.d.ts",
102
+ "cli.js"
103
+ ],
104
+ "dependencies": {
105
+ "@ethercorps/calyx": "0.1.0-alpha.1"
106
+ },
107
+ "peerDependencies": {
108
+ "svelte": "^5.59.0",
109
+ "@sveltejs/vite-plugin-svelte": ">=7",
110
+ "vite": ">=8",
111
+ "@sveltejs/kit": ">=3.4"
112
+ },
113
+ "peerDependenciesMeta": {
114
+ "@sveltejs/kit": {
115
+ "optional": true
116
+ }
117
+ },
118
+ "devDependencies": {
119
+ "@sveltejs/kit": "^3.4.0",
120
+ "@sveltejs/vite-plugin-svelte": "^7.3.1",
121
+ "@types/node": "^26.6.6",
122
+ "svelte": "^5.59.1",
123
+ "typescript": "^6.0.3",
124
+ "vite": "^8.3.8"
125
+ },
126
+ "scripts": {
127
+ "check": "tsc && tsc -p tsconfig.vite.json && tsc -p tsconfig.node.json"
128
+ }
6
129
  }
package/src/base64.js ADDED
@@ -0,0 +1,42 @@
1
+ // Bytes cross the host boundary as base64. The engine has no `atob`/`btoa`.
2
+
3
+ const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
4
+ /** @type {Record<string, number>} */
5
+ const VALUES = {};
6
+ for (let index = 0; index < ALPHABET.length; index++) VALUES[ALPHABET[index]] = index;
7
+
8
+ /** @param {Uint8Array} bytes */
9
+ export function encode(bytes) {
10
+ let text = '';
11
+ for (let at = 0; at < bytes.length; at += 3) {
12
+ const [a, b, c] = [bytes[at], bytes[at + 1], bytes[at + 2]];
13
+ text += ALPHABET[a >> 2] + ALPHABET[((a & 3) << 4) | ((b ?? 0) >> 4)];
14
+ text += b === undefined ? '=' : ALPHABET[((b & 15) << 2) | ((c ?? 0) >> 6)];
15
+ text += c === undefined ? '=' : ALPHABET[c & 63];
16
+ }
17
+ return text;
18
+ }
19
+
20
+ /** @param {string} text */
21
+ export function decode(text) {
22
+ const padding = text.endsWith('==') ? 2 : text.endsWith('=') ? 1 : 0;
23
+ const bytes = new Uint8Array((text.length / 4) * 3 - padding);
24
+ for (let at = 0, out = 0; at < text.length; at += 4) {
25
+ const group =
26
+ (VALUES[text[at]] << 18) | (VALUES[text[at + 1]] << 12) | ((VALUES[text[at + 2]] ?? 0) << 6) | (VALUES[text[at + 3]] ?? 0);
27
+ if (out < bytes.length) bytes[out++] = group >> 16;
28
+ if (out < bytes.length) bytes[out++] = (group >> 8) & 255;
29
+ if (out < bytes.length) bytes[out++] = group & 255;
30
+ }
31
+ return bytes;
32
+ }
33
+
34
+ /**
35
+ * Whatever byte container the caller has, as a `Uint8Array`.
36
+ * @param {ArrayBuffer | ArrayBufferView} data
37
+ */
38
+ export function to_bytes(data) {
39
+ if (data instanceof Uint8Array) return data;
40
+ if (ArrayBuffer.isView(data)) return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
41
+ return new Uint8Array(data);
42
+ }
@@ -0,0 +1,13 @@
1
+ // The clipboard, text only. Needs `permissions.clipboard`.
2
+
3
+ import { host_call } from './host-call.js';
4
+
5
+ /** @returns {Promise<string>} rejects when the clipboard holds no text */
6
+ export function readText() {
7
+ return host_call('clipboard.read_text');
8
+ }
9
+
10
+ /** @param {string} text @returns {Promise<void>} */
11
+ export function writeText(text) {
12
+ return host_call('clipboard.write_text', { text });
13
+ }
package/src/dialog.js ADDED
@@ -0,0 +1,47 @@
1
+ // Native dialogs. Needs `permissions.dialog`.
2
+ //
3
+ // import { open, save, confirm } from 'sepal/dialog';
4
+ //
5
+ // const path = await open({ filters: [{ name: 'Images', extensions: ['png', 'jpg'] }] });
6
+ //
7
+ // A path the user picks here can be read and written with the file APIs for
8
+ // as long as the app runs, without being listed in `permissions.fs`.
9
+
10
+ import { host_call } from './host-call.js';
11
+
12
+ /** @typedef {{ name: string, extensions: string[] }} Filter */
13
+ /**
14
+ * @typedef {{ title?: string, defaultPath?: string, filters?: Filter[] }} FileDialogOptions
15
+ * `defaultPath` is the directory the dialog starts in.
16
+ */
17
+
18
+ /**
19
+ * Let the user choose a file, several files (`multiple`) or a folder (`directory`).
20
+ * @template {FileDialogOptions & { multiple?: boolean, directory?: boolean }} Options
21
+ * @param {Options} [options]
22
+ * @returns {Promise<(Options extends { multiple: true } ? string[] : string) | null>} `null` if the user cancelled
23
+ */
24
+ export function open(options) {
25
+ return host_call('dialog.open', options ?? {});
26
+ }
27
+
28
+ /**
29
+ * Let the user choose where to save a file.
30
+ * @param {FileDialogOptions & { defaultName?: string }} [options]
31
+ * @returns {Promise<string | null>} `null` if the user cancelled
32
+ */
33
+ export function save(options = {}) {
34
+ return host_call('dialog.save', options);
35
+ }
36
+
37
+ /** @typedef {{ title?: string, kind?: 'info' | 'warning' | 'error' }} MessageOptions */
38
+
39
+ /** Show a message with an OK button. @param {string} text @param {MessageOptions} [options] @returns {Promise<void>} */
40
+ export async function message(text, options = {}) {
41
+ await host_call('dialog.message', { ...options, message: text });
42
+ }
43
+
44
+ /** Ask a question with OK and Cancel. @param {string} text @param {MessageOptions} [options] @returns {Promise<boolean>} `true` for OK */
45
+ export function confirm(text, options = {}) {
46
+ return host_call('dialog.message', { ...options, message: text, confirm: true });
47
+ }