sepal 0.1.0-alpha.2 → 0.2.0-alpha.0
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/README.md +4 -6
- package/package.json +3 -20
- package/src/index.js +5 -1
- package/src/shims.js +88 -10
- package/types/shims.d.ts +12 -0
- package/types/vite/sveltekit.d.ts +8 -0
- package/types/vite/vite.d.ts +6 -30
- package/vite/sveltekit.js +46 -7
- package/vite/vite.js +22 -61
- package/ambient.d.ts +0 -20
- package/types/vite/navigation.d.ts +0 -1
- package/types/vite/router-entry.d.ts +0 -1
- package/types/vite/router.d.ts +0 -21
- package/types/vite/routes.d.ts +0 -41
- package/types/vite/routing.svelte.d.ts +0 -131
- package/types/vite/state.d.ts +0 -1
- package/vite/Router.svelte +0 -32
- package/vite/RouterError.svelte +0 -11
- package/vite/navigation.js +0 -3
- package/vite/router-entry.js +0 -12
- package/vite/router.js +0 -17
- package/vite/routes.js +0 -219
- package/vite/routing.svelte.js +0 -378
- package/vite/state.js +0 -2
- package/vite/virtual.d.ts +0 -9
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ a Rust HTML/CSS engine; the JavaScript runs in an embedded QuickJS.
|
|
|
9
9
|
|
|
10
10
|
An alpha, on macOS (Linux builds and passes its tests headless; its window has
|
|
11
11
|
not been tried yet). Svelte 5 and Tailwind v4 as on the web, pages as files
|
|
12
|
-
|
|
12
|
+
run by SvelteKit's router, shadcn-svelte components through an opt-in
|
|
13
13
|
DOM layer, desktop APIs behind permissions, macOS `.app` bundles and
|
|
14
14
|
self-update, and no frame loop: an idle app does no work.
|
|
15
15
|
|
|
@@ -24,7 +24,7 @@ runs; [how they were measured](https://github.com/etherCorps/sepal/blob/main/com
|
|
|
24
24
|
| Idle memory, 1,000 issues | 107 MB RAM, 43 MB GPU memory |
|
|
25
25
|
| Memory after wheel-scrolling the whole list, 1,000 issues | 305 MB RAM, 220 MB GPU memory |
|
|
26
26
|
|
|
27
|
-
This one package is the runtime, the Vite
|
|
27
|
+
This one package is the runtime, the Vite presets and the `sepal` command; the
|
|
28
28
|
prebuilt host comes with it. Start a project with the starter rather than by
|
|
29
29
|
installing it directly:
|
|
30
30
|
|
|
@@ -41,10 +41,8 @@ What is in here:
|
|
|
41
41
|
| `sepal/updater` | self-update |
|
|
42
42
|
| `sepal/dom` | a small DOM for component libraries written for the web (`dom: true`) |
|
|
43
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()`,
|
|
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 |
|
|
44
|
+
| `sepal/vite` | the Vite preset for apps without routes, `sepal()`, and `defineConfig` for `sepal.config.ts` |
|
|
45
|
+
| `sepal/sveltekit` | `sepalKit()`, for apps with pages in `src/routes`: it takes the place of both `sveltekit()` and the adapter |
|
|
48
46
|
|
|
49
47
|
The preset compiles Svelte for the Blitz renderer, writes the one `app.js` and
|
|
50
48
|
`app.css` the host loads, reads `sepal.config.ts`, and in `vite build --watch`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sepal",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-alpha.0",
|
|
4
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
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"gui",
|
|
23
23
|
"vite",
|
|
24
24
|
"vite-plugin",
|
|
25
|
-
"router",
|
|
26
25
|
"svelte-blitz"
|
|
27
26
|
],
|
|
28
27
|
"type": "module",
|
|
@@ -77,32 +76,16 @@
|
|
|
77
76
|
"./sveltekit": {
|
|
78
77
|
"types": "./types/vite/sveltekit.d.ts",
|
|
79
78
|
"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
79
|
}
|
|
96
80
|
},
|
|
97
81
|
"files": [
|
|
98
82
|
"src",
|
|
99
83
|
"vite",
|
|
100
84
|
"types",
|
|
101
|
-
"ambient.d.ts",
|
|
102
85
|
"cli.js"
|
|
103
86
|
],
|
|
104
87
|
"dependencies": {
|
|
105
|
-
"@ethercorps/calyx": "0.
|
|
88
|
+
"@ethercorps/calyx": "0.2.0-alpha.0"
|
|
106
89
|
},
|
|
107
90
|
"peerDependencies": {
|
|
108
91
|
"svelte": "^5.59.0",
|
|
@@ -124,6 +107,6 @@
|
|
|
124
107
|
"vite": "^8.3.8"
|
|
125
108
|
},
|
|
126
109
|
"scripts": {
|
|
127
|
-
"check": "tsc && tsc -p tsconfig.
|
|
110
|
+
"check": "tsc && tsc -p tsconfig.node.json"
|
|
128
111
|
}
|
|
129
112
|
}
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Shims must be evaluated before Svelte's runtime.
|
|
2
|
-
import { run_timers, next_timer, track_rejection, report_rejections, rejection_count } from './shims.js';
|
|
2
|
+
import { run_timers, next_timer, run_frame, frame_pending, track_rejection, report_rejections, rejection_count } from './shims.js';
|
|
3
3
|
import { mount as svelte_mount, unmount } from 'svelte';
|
|
4
4
|
import renderer, { root, dispatch, take_batch, stats, keep_alive, host_hooks } from './renderer.js';
|
|
5
5
|
import { settle_call } from './host-call.js';
|
|
@@ -38,6 +38,10 @@ for (const [name, value] of Object.entries({ fetch, Headers, Request, Response }
|
|
|
38
38
|
timers: run_timers,
|
|
39
39
|
/** The next timer deadline on the host clock, or -1. Read at the end of a turn. */
|
|
40
40
|
next_timer,
|
|
41
|
+
/** Run one `requestAnimationFrame` callback; `false` when this frame has none left. Called until it says so. */
|
|
42
|
+
frame: run_frame,
|
|
43
|
+
/** Whether a `requestAnimationFrame` callback waits for a frame. Read at the end of a turn. */
|
|
44
|
+
frame_pending,
|
|
41
45
|
/** Answer a call the app made to the host (see host-call.js). */
|
|
42
46
|
resolve: settle_call,
|
|
43
47
|
/**
|
package/src/shims.js
CHANGED
|
@@ -89,8 +89,13 @@ if (typeof g.queueMicrotask !== 'function') {
|
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
// One clock for scripts, timers and frame timestamps: the host's, which
|
|
93
|
+
// stands still headless until a test moves it. QuickJS-ng has a `performance`
|
|
94
|
+
// of its own, on real time, whose `now` cannot be replaced; animation code
|
|
95
|
+
// compares a frame's timestamp with `performance.now()`, so the whole object
|
|
96
|
+
// is. Its `timeOrigin` stays.
|
|
97
|
+
if (typeof g.performance === 'undefined' || host.now) {
|
|
98
|
+
g.performance = { ...g.performance, now: clock };
|
|
94
99
|
}
|
|
95
100
|
|
|
96
101
|
// ---------------------------------------------------------------------------
|
|
@@ -101,11 +106,24 @@ if (typeof g.performance === 'undefined') {
|
|
|
101
106
|
// timer is pending.
|
|
102
107
|
// ---------------------------------------------------------------------------
|
|
103
108
|
|
|
104
|
-
/** @typedef {{ fn: Function, args: any[], at: number, every: number }} Timer */
|
|
109
|
+
/** @typedef {{ fn: Function, args: any[], at: number, every: number, level: number }} Timer */
|
|
105
110
|
|
|
106
111
|
/** @type {Map<number, Timer>} */
|
|
107
112
|
const timers = new Map();
|
|
108
113
|
let next_timer_id = 1;
|
|
114
|
+
/**
|
|
115
|
+
* HTML's timer nesting level: that of the timer whose callback, or whose
|
|
116
|
+
* microtasks, run now; 0 outside a timer.
|
|
117
|
+
*/
|
|
118
|
+
let timer_level = 0;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* As in HTML: from the sixth nested timer on, a timer waits at least 4 ms.
|
|
122
|
+
* A chain of `setTimeout(fn, 0)` then wakes the host about 250 times a
|
|
123
|
+
* second, not once per turn as fast as it can go.
|
|
124
|
+
* @param {number} delay
|
|
125
|
+
*/
|
|
126
|
+
const clamped = (delay) => (timer_level > 5 ? Math.max(4, delay) : delay);
|
|
109
127
|
|
|
110
128
|
/**
|
|
111
129
|
* @param {unknown} fn
|
|
@@ -116,8 +134,8 @@ let next_timer_id = 1;
|
|
|
116
134
|
function add_timer(fn, delay, every, args) {
|
|
117
135
|
if (typeof fn !== 'function') return 0;
|
|
118
136
|
const id = next_timer_id++;
|
|
119
|
-
const at = clock() + Math.max(0, Number(delay) || 0);
|
|
120
|
-
timers.set(id, { fn, args, at, every });
|
|
137
|
+
const at = clock() + clamped(Math.max(0, Number(delay) || 0));
|
|
138
|
+
timers.set(id, { fn, args, at, every, level: timer_level + 1 });
|
|
121
139
|
return id;
|
|
122
140
|
}
|
|
123
141
|
|
|
@@ -172,6 +190,7 @@ let round = null;
|
|
|
172
190
|
* @returns {boolean}
|
|
173
191
|
*/
|
|
174
192
|
export function run_timers() {
|
|
193
|
+
timer_level = 0;
|
|
175
194
|
if (round === null) {
|
|
176
195
|
if (timers.size === 0) return false;
|
|
177
196
|
const now = clock();
|
|
@@ -190,8 +209,13 @@ export function run_timers() {
|
|
|
190
209
|
}
|
|
191
210
|
const [id, timer] = next;
|
|
192
211
|
if (!timers.has(id)) continue; // cleared by an earlier callback
|
|
193
|
-
|
|
194
|
-
|
|
212
|
+
// Until the next call: the microtasks the host runs in between belong to this timer.
|
|
213
|
+
timer_level = timer.level;
|
|
214
|
+
if (timer.every > 0) {
|
|
215
|
+
// Each run of an interval is nested in the one before.
|
|
216
|
+
timer.at = clock() + clamped(timer.every);
|
|
217
|
+
timer.level++;
|
|
218
|
+
} else timers.delete(id);
|
|
195
219
|
try {
|
|
196
220
|
timer.fn(...timer.args);
|
|
197
221
|
} catch (error) {
|
|
@@ -222,8 +246,62 @@ if (typeof g.setTimeout !== 'function') {
|
|
|
222
246
|
g.clearInterval = g.clearTimeout;
|
|
223
247
|
}
|
|
224
248
|
|
|
249
|
+
// ---------------------------------------------------------------------------
|
|
250
|
+
// Animation frames
|
|
251
|
+
//
|
|
252
|
+
// A `requestAnimationFrame` callback runs when the host draws its next frame,
|
|
253
|
+
// before it lays the page out and paints. The host asks `frame_pending()` at
|
|
254
|
+
// the end of every turn and draws a frame only when the answer is yes, so
|
|
255
|
+
// with no callback queued nothing is drawn and nothing wakes it.
|
|
256
|
+
// ---------------------------------------------------------------------------
|
|
257
|
+
|
|
258
|
+
/** Queued callbacks, in the order they were queued. @type {Map<number, (time: number) => void>} */
|
|
259
|
+
const frame_callbacks = new Map();
|
|
260
|
+
let next_frame_id = 1;
|
|
261
|
+
/** The callbacks that were queued when the host started this frame. @type {number[] | null} */
|
|
262
|
+
let frame = null;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Run one callback of this frame, and say whether there was one. As with
|
|
266
|
+
* timers, the host calls this until the answer is no, and runs microtasks
|
|
267
|
+
* after every call. Every callback of a frame gets the same `time`; one
|
|
268
|
+
* queued during the frame runs in the next.
|
|
269
|
+
*
|
|
270
|
+
* @param {number} time the frame's timestamp, on the host clock
|
|
271
|
+
* @returns {boolean}
|
|
272
|
+
*/
|
|
273
|
+
export function run_frame(time) {
|
|
274
|
+
if (frame === null) {
|
|
275
|
+
if (frame_callbacks.size === 0) return false;
|
|
276
|
+
frame = [...frame_callbacks.keys()];
|
|
277
|
+
}
|
|
278
|
+
for (;;) {
|
|
279
|
+
const id = frame.shift();
|
|
280
|
+
if (id === undefined) {
|
|
281
|
+
frame = null;
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
const fn = frame_callbacks.get(id);
|
|
285
|
+
if (fn === undefined) continue; // cancelled by an earlier callback
|
|
286
|
+
frame_callbacks.delete(id);
|
|
287
|
+
try {
|
|
288
|
+
fn(time);
|
|
289
|
+
} catch (error) {
|
|
290
|
+
g.console.error('Error in requestAnimationFrame callback:', error);
|
|
291
|
+
}
|
|
292
|
+
return true;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** Whether the app waits for a frame. The host asks at the end of every turn. */
|
|
297
|
+
export const frame_pending = () => frame_callbacks.size > 0;
|
|
298
|
+
|
|
225
299
|
if (typeof g.requestAnimationFrame !== 'function') {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
300
|
+
g.requestAnimationFrame = (/** @type {unknown} */ fn) => {
|
|
301
|
+
if (typeof fn !== 'function') throw new TypeError('requestAnimationFrame: the callback is not a function');
|
|
302
|
+
const id = next_frame_id++;
|
|
303
|
+
frame_callbacks.set(id, /** @type {(time: number) => void} */ (fn));
|
|
304
|
+
return id;
|
|
305
|
+
};
|
|
306
|
+
g.cancelAnimationFrame = (/** @type {number} */ id) => void frame_callbacks.delete(id);
|
|
229
307
|
}
|
package/types/shims.d.ts
CHANGED
|
@@ -20,10 +20,22 @@ export function run_timers(): boolean;
|
|
|
20
20
|
* @returns {number} the earliest deadline on the host clock, or -1 if no timer is pending
|
|
21
21
|
*/
|
|
22
22
|
export function next_timer(): number;
|
|
23
|
+
/**
|
|
24
|
+
* Run one callback of this frame, and say whether there was one. As with
|
|
25
|
+
* timers, the host calls this until the answer is no, and runs microtasks
|
|
26
|
+
* after every call. Every callback of a frame gets the same `time`; one
|
|
27
|
+
* queued during the frame runs in the next.
|
|
28
|
+
*
|
|
29
|
+
* @param {number} time the frame's timestamp, on the host clock
|
|
30
|
+
* @returns {boolean}
|
|
31
|
+
*/
|
|
32
|
+
export function run_frame(time: number): boolean;
|
|
23
33
|
export function rejection_count(): number;
|
|
34
|
+
export function frame_pending(): boolean;
|
|
24
35
|
export type Timer = {
|
|
25
36
|
fn: Function;
|
|
26
37
|
args: any[];
|
|
27
38
|
at: number;
|
|
28
39
|
every: number;
|
|
40
|
+
level: number;
|
|
29
41
|
};
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The files under `src` that SvelteKit would run on a server, which an app
|
|
3
|
+
* does not have: they would build, and then never run. Relative to `src`.
|
|
4
|
+
*
|
|
5
|
+
* ponytail: comes out when the backend thread lands; that is where they will run.
|
|
6
|
+
* @param {string} src
|
|
7
|
+
*/
|
|
8
|
+
export function server_files(src: string): string[];
|
|
1
9
|
/**
|
|
2
10
|
* Turn what SvelteKit built (an HTML page that imports one module) into what
|
|
3
11
|
* the host loads (a script, a stylesheet, and the other files as they are).
|
package/types/vite/vite.d.ts
CHANGED
|
@@ -22,19 +22,6 @@
|
|
|
22
22
|
* window?: { title?: string, width?: number, height?: number }
|
|
23
23
|
* }} AppManifest
|
|
24
24
|
*/
|
|
25
|
-
/**
|
|
26
|
-
* Routing. Leave it out for the default: the built-in router when the
|
|
27
|
-
* project has a `src/routes` directory, no router when it does not.
|
|
28
|
-
*
|
|
29
|
-
* - `false` turns routing off even if `src/routes` exists.
|
|
30
|
-
* - `dir` is where the route files are (default `src/routes`).
|
|
31
|
-
* - `entry` is a router of your own: a module that becomes the app's entry.
|
|
32
|
-
* It mounts the app itself, and can import the generated route table
|
|
33
|
-
* (`routes`, `fallback`) from `virtual:sepal/routes`. The built-in
|
|
34
|
-
* `$app/navigation` and `$app/state` are not set up for it.
|
|
35
|
-
*
|
|
36
|
-
* @typedef {false | { dir?: string, entry?: string }} RouterOptions
|
|
37
|
-
*/
|
|
38
25
|
/**
|
|
39
26
|
* What the app may do outside its window. Everything is off unless it is
|
|
40
27
|
* listed here; a call that is not allowed rejects with a message naming the
|
|
@@ -69,10 +56,12 @@
|
|
|
69
56
|
* (`window`, `document`, element methods; see `sepal/dom`)
|
|
70
57
|
* before anything else, so those libraries find what they reach for.
|
|
71
58
|
*
|
|
59
|
+
* `entry` is the module the app starts from (default `src/main.js` or
|
|
60
|
+
* `src/main.ts`). It mounts the app; a router of your own goes there.
|
|
61
|
+
*
|
|
72
62
|
* @typedef {{
|
|
73
63
|
* app?: AppManifest,
|
|
74
64
|
* permissions?: Permissions,
|
|
75
|
-
* router?: RouterOptions,
|
|
76
65
|
* entry?: string,
|
|
77
66
|
* dom?: boolean
|
|
78
67
|
* }} Config
|
|
@@ -124,21 +113,6 @@ export type AppManifest = {
|
|
|
124
113
|
height?: number;
|
|
125
114
|
};
|
|
126
115
|
};
|
|
127
|
-
/**
|
|
128
|
-
* Routing. Leave it out for the default: the built-in router when the
|
|
129
|
-
* project has a `src/routes` directory, no router when it does not.
|
|
130
|
-
*
|
|
131
|
-
* - `false` turns routing off even if `src/routes` exists.
|
|
132
|
-
* - `dir` is where the route files are (default `src/routes`).
|
|
133
|
-
* - `entry` is a router of your own: a module that becomes the app's entry.
|
|
134
|
-
* It mounts the app itself, and can import the generated route table
|
|
135
|
-
* (`routes`, `fallback`) from `virtual:sepal/routes`. The built-in
|
|
136
|
-
* `$app/navigation` and `$app/state` are not set up for it.
|
|
137
|
-
*/
|
|
138
|
-
export type RouterOptions = false | {
|
|
139
|
-
dir?: string;
|
|
140
|
-
entry?: string;
|
|
141
|
-
};
|
|
142
116
|
/**
|
|
143
117
|
* What the app may do outside its window. Everything is off unless it is
|
|
144
118
|
* listed here; a call that is not allowed rejects with a message naming the
|
|
@@ -171,11 +145,13 @@ export type Permissions = {
|
|
|
171
145
|
* It builds the app as a browser bundle and loads a small DOM
|
|
172
146
|
* (`window`, `document`, element methods; see `sepal/dom`)
|
|
173
147
|
* before anything else, so those libraries find what they reach for.
|
|
148
|
+
*
|
|
149
|
+
* `entry` is the module the app starts from (default `src/main.js` or
|
|
150
|
+
* `src/main.ts`). It mounts the app; a router of your own goes there.
|
|
174
151
|
*/
|
|
175
152
|
export type Config = {
|
|
176
153
|
app?: AppManifest;
|
|
177
154
|
permissions?: Permissions;
|
|
178
|
-
router?: RouterOptions;
|
|
179
155
|
entry?: string;
|
|
180
156
|
dom?: boolean;
|
|
181
157
|
};
|
package/vite/sveltekit.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
//
|
|
19
19
|
// Runs in Node.
|
|
20
20
|
|
|
21
|
-
import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
21
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
22
22
|
import { dirname, join, posix, relative, resolve } from 'node:path';
|
|
23
23
|
import { dev_window, load_config, manifest } from './app.js';
|
|
24
24
|
import { element_bindings } from './bindings.js';
|
|
@@ -59,6 +59,18 @@ function files_in(directory) {
|
|
|
59
59
|
.map((entry) => relative(directory, join(entry.parentPath, entry.name)).replaceAll('\\', '/'));
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
/**
|
|
63
|
+
* The files under `src` that SvelteKit would run on a server, which an app
|
|
64
|
+
* does not have: they would build, and then never run. Relative to `src`.
|
|
65
|
+
*
|
|
66
|
+
* ponytail: comes out when the backend thread lands; that is where they will run.
|
|
67
|
+
* @param {string} src
|
|
68
|
+
*/
|
|
69
|
+
export function server_files(src) {
|
|
70
|
+
if (!existsSync(src)) return [];
|
|
71
|
+
return files_in(src).filter((file) => /(^|\/)(\+(page|layout)\.server\.|\+server\.|hooks\.server\.)|\.remote\.[^/]+$/.test(file));
|
|
72
|
+
}
|
|
73
|
+
|
|
62
74
|
/**
|
|
63
75
|
* Turn what SvelteKit built (an HTML page that imports one module) into what
|
|
64
76
|
* the host loads (a script, a stylesheet, and the other files as they are).
|
|
@@ -98,19 +110,28 @@ export function convert(from, to) {
|
|
|
98
110
|
writeFileSync(
|
|
99
111
|
join(to, 'app.js'),
|
|
100
112
|
`(() => {
|
|
113
|
+
// The bundle was a module, and module code is strict. Run as a sloppy script,
|
|
114
|
+
// the minified Tracker broke on V8 (a renderer method missing on Insights).
|
|
115
|
+
'use strict';
|
|
101
116
|
const __module_url = ${JSON.stringify(`http://app.localhost/${bundle}`)};
|
|
102
117
|
${code}
|
|
103
118
|
globalThis.${payload}
|
|
104
119
|
// Where SvelteKit puts the app: the element its start script sat in.
|
|
105
|
-
const
|
|
106
|
-
document.body.appendChild(
|
|
107
|
-
${start}(
|
|
120
|
+
const __sepal_target = document.createElement('div');
|
|
121
|
+
document.body.appendChild(__sepal_target);
|
|
122
|
+
${start}(__sepal_target);
|
|
108
123
|
})();
|
|
109
124
|
`
|
|
110
125
|
);
|
|
111
126
|
|
|
112
127
|
const styles = [...html.matchAll(/<link href="\/([^"]+)" rel="stylesheet">/g)].map((link) => link[1]).filter((file) => files.includes(file));
|
|
113
|
-
|
|
128
|
+
const css = styles.map((file) => rebase_css(readFileSync(join(from, file), 'utf8'), posix.dirname(file)));
|
|
129
|
+
// SvelteKit's route announcer is a 1px `overflow: hidden` box at the top
|
|
130
|
+
// left. Blitz hit-tests what overflows such a box, so after the first
|
|
131
|
+
// navigation its invisible text took clicks meant for what is drawn there.
|
|
132
|
+
// ponytail: until Blitz's hit testing clips to `overflow: hidden`; then this goes.
|
|
133
|
+
css.push('#svelte-announcer { pointer-events: none }');
|
|
134
|
+
writeFileSync(join(to, 'app.css'), css.join('\n'));
|
|
114
135
|
|
|
115
136
|
// Everything else is for the app to load by its path: static files, and
|
|
116
137
|
// what SvelteKit put in `_app/immutable/assets`.
|
|
@@ -159,6 +180,8 @@ export async function sepalKit(inline = {}) {
|
|
|
159
180
|
let root = process.cwd();
|
|
160
181
|
let watching = false;
|
|
161
182
|
const show = dev_window(() => ({ root, out_dir: resolve(root, out), name: options.app?.name }));
|
|
183
|
+
// Deprecated in SvelteKit 3's types, but still the only way to move `static/`:
|
|
184
|
+
// the top-level `assets` is `paths.assets`, a URL.
|
|
162
185
|
const static_dir = () => resolve(root, kit.files?.assets ?? 'static');
|
|
163
186
|
|
|
164
187
|
/** @type {import('@sveltejs/kit').Adapter} */
|
|
@@ -167,8 +190,9 @@ export async function sepalKit(inline = {}) {
|
|
|
167
190
|
async adapt(builder) {
|
|
168
191
|
const staging = builder.getBuildDirectory('sepal');
|
|
169
192
|
const to = resolve(root, out);
|
|
170
|
-
builder.rimraf
|
|
171
|
-
|
|
193
|
+
// `builder.rimraf` is deprecated in SvelteKit 3.
|
|
194
|
+
rmSync(staging, { force: true, recursive: true });
|
|
195
|
+
rmSync(to, { force: true, recursive: true });
|
|
172
196
|
builder.writeClient(staging);
|
|
173
197
|
// The page SvelteKit serves for a route it did not prerender: nothing
|
|
174
198
|
// in it but the script that starts the app.
|
|
@@ -202,6 +226,17 @@ export async function sepalKit(inline = {}) {
|
|
|
202
226
|
root = config.root;
|
|
203
227
|
watching = config.build.watch != null;
|
|
204
228
|
},
|
|
229
|
+
buildStart() {
|
|
230
|
+
// On every build, so that a file added in watch mode is caught too.
|
|
231
|
+
const src = resolve(root, kit.files?.src ?? 'src');
|
|
232
|
+
const found = server_files(src);
|
|
233
|
+
if (found.length > 0) {
|
|
234
|
+
const names = found.map((file) => posix.join(relative(root, src).replaceAll('\\', '/'), file)).join(', ');
|
|
235
|
+
this.error(
|
|
236
|
+
`sepal: ${names} ${found.length === 1 ? 'is' : 'are'} server code. It would run in the app's backend thread, which Sepal does not have yet, so it would never run. Use +page.ts/+layout.ts (\`load\` runs in the app) until then.`
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
},
|
|
205
240
|
transform(code, id) {
|
|
206
241
|
const edit = patch.find(({ file }) => id.endsWith(file));
|
|
207
242
|
if (edit === undefined) return;
|
|
@@ -221,6 +256,10 @@ export async function sepalKit(inline = {}) {
|
|
|
221
256
|
output: { ...kit.output, bundleStrategy: 'single' },
|
|
222
257
|
// Nothing is rendered ahead of time. There is no server to send it.
|
|
223
258
|
prerender: { ...kit.prerender, entries: kit.prerender?.entries ?? [] },
|
|
259
|
+
// SvelteKit 3 asks the server for a new version every hour by default:
|
|
260
|
+
// a wake-up on a timer, and a request nothing answers. An app updates
|
|
261
|
+
// through `sepal/updater` instead.
|
|
262
|
+
version: { ...kit.version, pollInterval: kit.version?.pollInterval ?? 0 },
|
|
224
263
|
// Ours first: they have to see `bind:` on elements and `<svelte:head>`
|
|
225
264
|
// before Svelte refuses them.
|
|
226
265
|
preprocess: [element_bindings(), head(), ...[kit.preprocess ?? []].flat()],
|
package/vite/vite.js
CHANGED
|
@@ -6,27 +6,20 @@
|
|
|
6
6
|
// root, so that `vite.config.ts` stays a list of plugins. Options passed to
|
|
7
7
|
// `sepal()` directly override the file, key by key.
|
|
8
8
|
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
// swaps in a router of your own, or turns routing off.
|
|
9
|
+
// The entry is `src/main.js` or `src/main.ts`, or the `entry` option. An app
|
|
10
|
+
// with pages in `src/routes` is a SvelteKit app: it uses `sepalKit()` from
|
|
11
|
+
// `sepal/sveltekit` instead of this preset.
|
|
13
12
|
//
|
|
14
13
|
// In watch mode (`vite build --watch`) with a host binary available, it also
|
|
15
14
|
// opens the app and reloads it in place after every rebuild.
|
|
16
15
|
|
|
17
16
|
import { existsSync, readFileSync } from 'node:fs';
|
|
18
17
|
import { join, resolve } from 'node:path';
|
|
19
|
-
import { fileURLToPath } from 'node:url';
|
|
20
18
|
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
|
21
19
|
import { normalizePath } from 'vite';
|
|
22
20
|
import { dev_window, load_config, manifest } from './app.js';
|
|
23
21
|
import { element_bindings } from './bindings.js';
|
|
24
22
|
import { head } from './head.js';
|
|
25
|
-
import { generate_routes } from './routes.js';
|
|
26
|
-
|
|
27
|
-
const ROUTES_ID = 'virtual:sepal/routes';
|
|
28
|
-
/** @param {string} file a file in this package's `src` */
|
|
29
|
-
const own = (file) => fileURLToPath(new URL(file, import.meta.url));
|
|
30
23
|
|
|
31
24
|
/**
|
|
32
25
|
* What the app tells the host about itself. Written to `dist/app.json`.
|
|
@@ -53,20 +46,6 @@ const own = (file) => fileURLToPath(new URL(file, import.meta.url));
|
|
|
53
46
|
* }} AppManifest
|
|
54
47
|
*/
|
|
55
48
|
|
|
56
|
-
/**
|
|
57
|
-
* Routing. Leave it out for the default: the built-in router when the
|
|
58
|
-
* project has a `src/routes` directory, no router when it does not.
|
|
59
|
-
*
|
|
60
|
-
* - `false` turns routing off even if `src/routes` exists.
|
|
61
|
-
* - `dir` is where the route files are (default `src/routes`).
|
|
62
|
-
* - `entry` is a router of your own: a module that becomes the app's entry.
|
|
63
|
-
* It mounts the app itself, and can import the generated route table
|
|
64
|
-
* (`routes`, `fallback`) from `virtual:sepal/routes`. The built-in
|
|
65
|
-
* `$app/navigation` and `$app/state` are not set up for it.
|
|
66
|
-
*
|
|
67
|
-
* @typedef {false | { dir?: string, entry?: string }} RouterOptions
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
49
|
/**
|
|
71
50
|
* What the app may do outside its window. Everything is off unless it is
|
|
72
51
|
* listed here; a call that is not allowed rejects with a message naming the
|
|
@@ -102,10 +81,12 @@ const own = (file) => fileURLToPath(new URL(file, import.meta.url));
|
|
|
102
81
|
* (`window`, `document`, element methods; see `sepal/dom`)
|
|
103
82
|
* before anything else, so those libraries find what they reach for.
|
|
104
83
|
*
|
|
84
|
+
* `entry` is the module the app starts from (default `src/main.js` or
|
|
85
|
+
* `src/main.ts`). It mounts the app; a router of your own goes there.
|
|
86
|
+
*
|
|
105
87
|
* @typedef {{
|
|
106
88
|
* app?: AppManifest,
|
|
107
89
|
* permissions?: Permissions,
|
|
108
|
-
* router?: RouterOptions,
|
|
109
90
|
* entry?: string,
|
|
110
91
|
* dom?: boolean
|
|
111
92
|
* }} Config
|
|
@@ -135,7 +116,6 @@ export function sepal(inline = {}) {
|
|
|
135
116
|
let config_path = null;
|
|
136
117
|
/** @type {import('vite').ConfigEnv} */
|
|
137
118
|
let config_env = { mode: 'production', command: 'build' };
|
|
138
|
-
let routes_dir = '';
|
|
139
119
|
/** The entry module, absolute and without extension, when `dom` is on. */
|
|
140
120
|
let dom_entry = '';
|
|
141
121
|
const user = inline.svelte ?? {};
|
|
@@ -172,17 +152,14 @@ export function sepal(inline = {}) {
|
|
|
172
152
|
config_path = file.path;
|
|
173
153
|
options = { ...file.config, ...inline };
|
|
174
154
|
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
? own('./router-entry.js')
|
|
184
|
-
: // No extension: Vite resolves `src/main.js` or `src/main.ts`, whichever exists.
|
|
185
|
-
(options.entry ?? 'src/main');
|
|
155
|
+
const has_main = ['js', 'ts'].some((ext) => existsSync(join(project, `src/main.${ext}`)));
|
|
156
|
+
if (options.entry === undefined && !has_main && existsSync(join(project, 'src/routes'))) {
|
|
157
|
+
throw new Error(
|
|
158
|
+
"sepal: this app has pages in src/routes and no src/main. Pages are SvelteKit's: in vite.config.ts, use `sepalKit()` from 'sepal/sveltekit' in place of `sepal()`, and add a src/routes/+layout.ts with `export const ssr = false;`."
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
// No extension: Vite resolves `src/main.js` or `src/main.ts`, whichever exists.
|
|
162
|
+
const entry = options.entry ?? 'src/main';
|
|
186
163
|
|
|
187
164
|
// Vite's module ids use `/` on Windows as well.
|
|
188
165
|
if (options.dom) dom_entry = normalizePath(resolve(project, entry)).replace(/\.[cm]?[jt]s$/, '');
|
|
@@ -197,14 +174,8 @@ export function sepal(inline = {}) {
|
|
|
197
174
|
// `dom`, `browser` as well: libraries check it at build time to
|
|
198
175
|
// decide whether there is a DOM to work with.
|
|
199
176
|
conditions: ['svelte-custom-renderer', ...(options.dom ? ['browser'] : []), 'svelte', 'module', 'import', 'default'],
|
|
200
|
-
// The
|
|
201
|
-
|
|
202
|
-
alias: {
|
|
203
|
-
$lib: join(project, 'src/lib'),
|
|
204
|
-
...(built_in_router
|
|
205
|
-
? { '$app/navigation': own('./navigation.js'), '$app/state': own('./state.js') }
|
|
206
|
-
: {})
|
|
207
|
-
}
|
|
177
|
+
// The name SvelteKit 2 projects use for `src/lib`.
|
|
178
|
+
alias: { $lib: join(project, 'src/lib') }
|
|
208
179
|
},
|
|
209
180
|
build: {
|
|
210
181
|
target: 'es2022',
|
|
@@ -215,13 +186,13 @@ export function sepal(inline = {}) {
|
|
|
215
186
|
formats: ['iife'],
|
|
216
187
|
fileName: () => 'app.js',
|
|
217
188
|
cssFileName: 'app'
|
|
218
|
-
}
|
|
189
|
+
},
|
|
190
|
+
// The sources are modules, and module code is strict; the IIFE
|
|
191
|
+
// keeps it so. Rolldown's default only keeps directives it finds.
|
|
192
|
+
rolldownOptions: { output: { strict: true } }
|
|
219
193
|
}
|
|
220
194
|
};
|
|
221
195
|
},
|
|
222
|
-
resolveId(id) {
|
|
223
|
-
if (id === ROUTES_ID) return '\0' + ROUTES_ID;
|
|
224
|
-
},
|
|
225
196
|
transform(code, id) {
|
|
226
197
|
// The DOM has to exist before any library module runs, so it is the
|
|
227
198
|
// entry module's first import.
|
|
@@ -229,16 +200,6 @@ export function sepal(inline = {}) {
|
|
|
229
200
|
return { code: `import 'sepal/dom';\n${code}`, map: null };
|
|
230
201
|
}
|
|
231
202
|
},
|
|
232
|
-
load(id) {
|
|
233
|
-
if (id !== '\0' + ROUTES_ID) return;
|
|
234
|
-
// A custom router may not use route files at all.
|
|
235
|
-
if (!existsSync(routes_dir)) return 'export const routes = [];\nexport const fallback = { layouts: [], error: null };\n';
|
|
236
|
-
const { code, files } = generate_routes(routes_dir);
|
|
237
|
-
// Rebuild when a route file is added, removed or changed.
|
|
238
|
-
this.addWatchFile(routes_dir);
|
|
239
|
-
for (const file of files) this.addWatchFile(file);
|
|
240
|
-
return code;
|
|
241
|
-
},
|
|
242
203
|
configResolved(config) {
|
|
243
204
|
root = config.root;
|
|
244
205
|
static_dir = config.publicDir;
|
|
@@ -248,11 +209,11 @@ export function sepal(inline = {}) {
|
|
|
248
209
|
async buildStart() {
|
|
249
210
|
// In watch mode, pick up edits to the config file. What it says about
|
|
250
211
|
// the app and its permissions takes effect on the next build; a
|
|
251
|
-
// change to `
|
|
212
|
+
// change to `entry` needs Vite restarted.
|
|
252
213
|
if (config_path === null) return;
|
|
253
214
|
this.addWatchFile(config_path);
|
|
254
215
|
const file = await load_config(root, config_env);
|
|
255
|
-
options = { ...file.config, ...inline,
|
|
216
|
+
options = { ...file.config, ...inline, entry: options.entry };
|
|
256
217
|
},
|
|
257
218
|
generateBundle() {
|
|
258
219
|
let written;
|
package/ambient.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { goto, back, forward } from "./routing.svelte.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|