@histoire/dev-proxy 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +16 -2
- package/dist/appearance.d.ts +11 -0
- package/dist/appearance.js +11 -0
- package/dist/browser/chunks/transitions-3JvGwb-W.js +71 -0
- package/dist/browser/demo.js +50 -0
- package/dist/browser/lifecycle.js +55 -0
- package/dist/client/demo.d.ts +1 -0
- package/dist/client/demo.js +46 -0
- package/dist/client/lifecycle.d.ts +1 -0
- package/dist/client/lifecycle.js +73 -0
- package/dist/client/mark.d.ts +2 -0
- package/dist/client/mark.js +8 -0
- package/dist/client/page.d.ts +14 -0
- package/dist/client/page.js +18 -0
- package/dist/client/playground.d.ts +5 -0
- package/dist/client/playground.js +32 -0
- package/dist/client/status.d.ts +3 -0
- package/dist/client/status.js +9 -0
- package/dist/client/styles.d.ts +2 -0
- package/dist/client/styles.js +139 -0
- package/dist/client/transitions.d.ts +8 -0
- package/dist/client/transitions.js +45 -0
- package/dist/config/discovery.d.ts +12 -0
- package/dist/config/discovery.js +57 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/index.js +4 -0
- package/dist/config/inputs.d.ts +18 -0
- package/dist/config/inputs.js +29 -0
- package/dist/config/snapshots.d.ts +16 -0
- package/dist/config/snapshots.js +25 -0
- package/dist/config/watcher.d.ts +12 -0
- package/dist/config/watcher.js +108 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +303 -0
- package/dist/lifecycle/coordinator.d.ts +51 -0
- package/dist/lifecycle/coordinator.js +244 -0
- package/dist/lifecycle/index.d.ts +3 -0
- package/dist/lifecycle/index.js +2 -0
- package/dist/lifecycle/wait.d.ts +2 -0
- package/dist/lifecycle/wait.js +22 -0
- package/dist/process/child.d.ts +55 -0
- package/dist/process/child.js +191 -0
- package/dist/protocol.d.ts +182 -0
- package/dist/protocol.js +77 -0
- package/dist/server/events.d.ts +11 -0
- package/dist/server/events.js +37 -0
- package/dist/server/http.d.ts +19 -0
- package/dist/server/http.js +139 -0
- package/dist/server/listener.d.ts +5 -0
- package/dist/server/listener.js +53 -0
- package/dist/server/observe.d.ts +47 -0
- package/dist/server/observe.js +59 -0
- package/package.json +58 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Guillaume Chau
|
|
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,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @histoire/dev-proxy
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Early HTTP hosting and process ownership for `histoire dev`. Public listener responds before project configuration or Vite imports. Standalone loading document draws a wireframe Histoire logo, animates transitions between lifecycle states (reduced motion applies them instantly), and offers a restart action after failures (`POST /__histoire/dev/restart`, same-origin only). `/__histoire/dev/loading` serves that document with a state switcher and scripted sequence for design iteration.
|
|
4
|
+
|
|
5
|
+
`startDevProxy({ runtime, root, port, host, runtimeOptions })` binds public listener and returns `{ url, status, ready, restart, close }`. `ready` observes initial acquisition; config errors reject it while persistent watcher permits later recovery. `close()` is idempotent. Public address defaults to `localhost:6006`; port `0` selects an ephemeral port.
|
|
6
|
+
|
|
7
|
+
Runtime executable receives typed private IPC from `@histoire/dev-proxy/protocol`. It starts once, reports evaluated configuration inputs and backend readiness, and handles graceful shutdown. Proxy owns file watching and serialized replacement. Ten-second winddown ends with forced owned-process-tree termination if necessary; successor never starts before exit is confirmed.
|
|
8
|
+
|
|
9
|
+
Package subpaths:
|
|
10
|
+
|
|
11
|
+
- `./lifecycle`: framework-neutral restart coordinator and abort-aware readiness.
|
|
12
|
+
- `./config`: config discovery, evaluation snapshots and byte-aware directory watches.
|
|
13
|
+
- `./protocol`: process messages and browser-safe lifecycle state.
|
|
14
|
+
|
|
15
|
+
Browser assets are built into `dist/browser` and served directly under `/__histoire/dev/`, independently of project Vite. No runtime dependency on other Histoire packages. SDK/MCP compatibility adapters can import lifecycle/config subpaths without loading HTTP or browser assets.
|
|
16
|
+
|
|
17
|
+
Validation covers real HTTP/process races, streamed requests, disconnect cancellation, forced descendant cleanup, browser handoff/HMR, and tarball installation outside workspace. Run `pnpm --filter @histoire/dev-proxy build` before package tests; CLI/browser integration suites consume built Histoire packages too.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page background of the startup document, mirroring the workbench home tokens.
|
|
3
|
+
* Runtime documents loaded after it (the workbench app shell) paint the same
|
|
4
|
+
* color before their styles exist, so the handoff never flashes.
|
|
5
|
+
*/
|
|
6
|
+
export declare const startupBackground: {
|
|
7
|
+
/** Light scheme background. */
|
|
8
|
+
readonly light: 'rgb(247 247 248)';
|
|
9
|
+
/** Dark scheme background. */
|
|
10
|
+
readonly dark: 'rgb(13 14 17)';
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page background of the startup document, mirroring the workbench home tokens.
|
|
3
|
+
* Runtime documents loaded after it (the workbench app shell) paint the same
|
|
4
|
+
* color before their styles exist, so the handoff never flashes.
|
|
5
|
+
*/
|
|
6
|
+
export const startupBackground = {
|
|
7
|
+
/** Light scheme background. */
|
|
8
|
+
light: 'rgb(247 247 248)',
|
|
9
|
+
/** Dark scheme background. */
|
|
10
|
+
dark: 'rgb(13 14 17)',
|
|
11
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// src/client/status.ts
|
|
2
|
+
/** Headline shared by server-rendered startup page and live status updates. */
|
|
3
|
+
function statusTitle(status) {
|
|
4
|
+
switch (status) {
|
|
5
|
+
case "failed": return "Failed to start";
|
|
6
|
+
case "restarting": return "Restarting";
|
|
7
|
+
case "closed": return "Stopped";
|
|
8
|
+
default: return "Starting";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
// src/client/transitions.ts
|
|
12
|
+
/** Latest requested swap; an older pending swap must not overwrite a newer state. */
|
|
13
|
+
var version = 0;
|
|
14
|
+
/** Whether the viewer asked for no motion; transitions then apply instantly. */
|
|
15
|
+
function reducedMotion() {
|
|
16
|
+
return matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Applies one public state to the startup page. CSS reacts to `body[data-status]` (logo, failure
|
|
20
|
+
* outcome); the headline text slides out and back in so successive states read as a sequence.
|
|
21
|
+
*/
|
|
22
|
+
function applyStatus(state) {
|
|
23
|
+
const status = document.getElementById("status");
|
|
24
|
+
const title = statusTitle(state.status);
|
|
25
|
+
if (state.error) document.getElementById("detail").textContent = state.error;
|
|
26
|
+
if (document.body.dataset.status === state.status && status.textContent === title) return;
|
|
27
|
+
document.body.dataset.status = state.status;
|
|
28
|
+
const current = ++version;
|
|
29
|
+
/** Swaps headline text and tone together so color and shimmer change with the words. */
|
|
30
|
+
const swap = () => {
|
|
31
|
+
status.textContent = title;
|
|
32
|
+
status.dataset.tone = state.status;
|
|
33
|
+
};
|
|
34
|
+
if (reducedMotion()) {
|
|
35
|
+
swap();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
status.getAnimations().forEach((animation) => animation.cancel());
|
|
39
|
+
const leave = status.animate([{
|
|
40
|
+
opacity: 1,
|
|
41
|
+
transform: "none"
|
|
42
|
+
}, {
|
|
43
|
+
opacity: 0,
|
|
44
|
+
transform: "translateY(-6px)"
|
|
45
|
+
}], {
|
|
46
|
+
duration: 140,
|
|
47
|
+
easing: "ease-in",
|
|
48
|
+
fill: "forwards"
|
|
49
|
+
});
|
|
50
|
+
leave.finished.then(() => {
|
|
51
|
+
if (current !== version) return;
|
|
52
|
+
swap();
|
|
53
|
+
leave.cancel();
|
|
54
|
+
status.animate([{
|
|
55
|
+
opacity: 0,
|
|
56
|
+
transform: "translateY(6px)"
|
|
57
|
+
}, {
|
|
58
|
+
opacity: 1,
|
|
59
|
+
transform: "none"
|
|
60
|
+
}], {
|
|
61
|
+
duration: 260,
|
|
62
|
+
easing: "cubic-bezier(.2, .8, .2, 1)"
|
|
63
|
+
});
|
|
64
|
+
}, () => {});
|
|
65
|
+
}
|
|
66
|
+
/** Fades the startup screen out, then resolves; callers navigate afterwards. */
|
|
67
|
+
function leaveStartup() {
|
|
68
|
+
document.body.dataset.leaving = "";
|
|
69
|
+
return new Promise((resolve) => setTimeout(resolve, reducedMotion() ? 0 : 200));
|
|
70
|
+
}
|
|
71
|
+
export { leaveStartup as n, applyStatus as t };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { n as leaveStartup, t as applyStatus } from "./chunks/transitions-3JvGwb-W.js";
|
|
2
|
+
// src/client/demo.ts
|
|
3
|
+
/** Representative lifecycle: a failed start, a manual restart failing again, then a successful one. */
|
|
4
|
+
var sequence = [
|
|
5
|
+
["starting", 2200],
|
|
6
|
+
["failed", 3e3],
|
|
7
|
+
["restarting", 2200],
|
|
8
|
+
["failed", 3e3],
|
|
9
|
+
["restarting", 2200],
|
|
10
|
+
["ready", 1200]
|
|
11
|
+
];
|
|
12
|
+
/** Drives the frozen design page through lifecycle transitions without a real runtime. */
|
|
13
|
+
function demo() {
|
|
14
|
+
const switcher = document.querySelector("[data-demo]");
|
|
15
|
+
if (!switcher) return;
|
|
16
|
+
const error = switcher.dataset.error;
|
|
17
|
+
let timer;
|
|
18
|
+
/** Shows one state with the same transitions as the live page. */
|
|
19
|
+
async function show(step) {
|
|
20
|
+
for (const button of switcher.querySelectorAll("button")) button.toggleAttribute("aria-pressed", button.value === step);
|
|
21
|
+
if (step !== "ready") {
|
|
22
|
+
applyStatus({
|
|
23
|
+
status: step,
|
|
24
|
+
error: step === "failed" ? error : void 0
|
|
25
|
+
});
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
await leaveStartup();
|
|
29
|
+
delete document.body.dataset.leaving;
|
|
30
|
+
applyStatus({ status: "starting" });
|
|
31
|
+
}
|
|
32
|
+
/** Plays the scripted sequence from `index`, looping until another control is used. */
|
|
33
|
+
function play(index = 0) {
|
|
34
|
+
const [step, duration] = sequence[index];
|
|
35
|
+
show(step);
|
|
36
|
+
timer = setTimeout(() => play((index + 1) % sequence.length), duration);
|
|
37
|
+
}
|
|
38
|
+
switcher.addEventListener("click", (event) => {
|
|
39
|
+
const button = event.target.closest("button");
|
|
40
|
+
if (!button) return;
|
|
41
|
+
clearTimeout(timer);
|
|
42
|
+
if (button.value === "sequence") play();
|
|
43
|
+
else show(button.value);
|
|
44
|
+
});
|
|
45
|
+
document.getElementById("restart").addEventListener("click", () => {
|
|
46
|
+
clearTimeout(timer);
|
|
47
|
+
show("restarting");
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
demo();
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { n as leaveStartup, t as applyStatus } from "./chunks/transitions-3JvGwb-W.js";
|
|
2
|
+
// src/client/lifecycle.ts
|
|
3
|
+
/** Connect top-level workbench/loading documents to proxy-owned process lifecycle. */
|
|
4
|
+
function connect() {
|
|
5
|
+
if (window.top !== window || !("EventSource" in window)) return;
|
|
6
|
+
const script = document.querySelector("script[data-histoire-generation]");
|
|
7
|
+
const loading = document.body.hasAttribute("data-histoire-loading");
|
|
8
|
+
const generation = script?.dataset.histoireGeneration ?? document.body.dataset.generation;
|
|
9
|
+
const originalBase = script?.dataset.histoireBase ?? document.body.dataset.base ?? "/";
|
|
10
|
+
const events = new EventSource("/__histoire/dev/events");
|
|
11
|
+
let navigating = false;
|
|
12
|
+
let disposeTimer;
|
|
13
|
+
/** Preserve selected route and URL state across an updated application base. */
|
|
14
|
+
async function navigate(base) {
|
|
15
|
+
if (navigating) return;
|
|
16
|
+
navigating = true;
|
|
17
|
+
events.close();
|
|
18
|
+
if (loading) await leaveStartup();
|
|
19
|
+
const url = new URL(location.href);
|
|
20
|
+
if (url.pathname === "/") url.pathname = base;
|
|
21
|
+
else if (originalBase !== base && !url.pathname.startsWith(base) && url.pathname.startsWith(originalBase)) url.pathname = base + url.pathname.slice(originalBase.length);
|
|
22
|
+
if (url.href === location.href) location.reload();
|
|
23
|
+
else location.replace(url.href);
|
|
24
|
+
}
|
|
25
|
+
events.onmessage = ({ data }) => {
|
|
26
|
+
let state;
|
|
27
|
+
try {
|
|
28
|
+
state = JSON.parse(data);
|
|
29
|
+
} catch {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
clearTimeout(disposeTimer);
|
|
33
|
+
if (loading) {
|
|
34
|
+
if (state.status === "ready") navigate(state.base);
|
|
35
|
+
else applyStatus(state);
|
|
36
|
+
} else if (state.status !== "closed" && (state.status !== "ready" || state.generation !== generation)) navigate(state.base);
|
|
37
|
+
};
|
|
38
|
+
const restart = document.getElementById("restart");
|
|
39
|
+
restart?.addEventListener("click", () => {
|
|
40
|
+
restart.disabled = true;
|
|
41
|
+
fetch("/__histoire/dev/restart", { method: "POST" }).catch(() => {}).finally(() => {
|
|
42
|
+
restart.disabled = false;
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
events.onerror = () => {
|
|
46
|
+
if (loading) disposeTimer = setTimeout(() => {
|
|
47
|
+
document.getElementById("status").textContent = "Connecting";
|
|
48
|
+
}, 3e3);
|
|
49
|
+
};
|
|
50
|
+
window.addEventListener("pagehide", () => {
|
|
51
|
+
events.close();
|
|
52
|
+
clearTimeout(disposeTimer);
|
|
53
|
+
}, { once: true });
|
|
54
|
+
}
|
|
55
|
+
connect();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { applyStatus, leaveStartup } from './transitions.js';
|
|
2
|
+
/** Representative lifecycle: a failed start, a manual restart failing again, then a successful one. */
|
|
3
|
+
const sequence = [['starting', 2200], ['failed', 3000], ['restarting', 2200], ['failed', 3000], ['restarting', 2200], ['ready', 1200]];
|
|
4
|
+
/** Drives the frozen design page through lifecycle transitions without a real runtime. */
|
|
5
|
+
function demo() {
|
|
6
|
+
const switcher = document.querySelector('[data-demo]');
|
|
7
|
+
if (!switcher)
|
|
8
|
+
return;
|
|
9
|
+
const error = switcher.dataset.error;
|
|
10
|
+
let timer;
|
|
11
|
+
/** Shows one state with the same transitions as the live page. */
|
|
12
|
+
async function show(step) {
|
|
13
|
+
for (const button of switcher.querySelectorAll('button'))
|
|
14
|
+
button.toggleAttribute('aria-pressed', button.value === step);
|
|
15
|
+
if (step !== 'ready') {
|
|
16
|
+
applyStatus({ status: step, error: step === 'failed' ? error : undefined });
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// Simulated handoff: fade out as before navigation, then come back as a fresh page load.
|
|
20
|
+
await leaveStartup();
|
|
21
|
+
delete document.body.dataset.leaving;
|
|
22
|
+
applyStatus({ status: 'starting' });
|
|
23
|
+
}
|
|
24
|
+
/** Plays the scripted sequence from `index`, looping until another control is used. */
|
|
25
|
+
function play(index = 0) {
|
|
26
|
+
const [step, duration] = sequence[index];
|
|
27
|
+
void show(step);
|
|
28
|
+
timer = setTimeout(() => play((index + 1) % sequence.length), duration);
|
|
29
|
+
}
|
|
30
|
+
switcher.addEventListener('click', (event) => {
|
|
31
|
+
const button = event.target.closest('button');
|
|
32
|
+
if (!button)
|
|
33
|
+
return;
|
|
34
|
+
clearTimeout(timer);
|
|
35
|
+
if (button.value === 'sequence')
|
|
36
|
+
play();
|
|
37
|
+
else
|
|
38
|
+
void show(button.value);
|
|
39
|
+
});
|
|
40
|
+
// Same affordance as the live failure screen, simulated.
|
|
41
|
+
document.getElementById('restart').addEventListener('click', () => {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
void show('restarting');
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
demo();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { applyStatus, leaveStartup } from './transitions.js';
|
|
2
|
+
/** Connect top-level workbench/loading documents to proxy-owned process lifecycle. */
|
|
3
|
+
function connect() {
|
|
4
|
+
if (window.top !== window || !('EventSource' in window))
|
|
5
|
+
return;
|
|
6
|
+
const script = document.querySelector('script[data-histoire-generation]');
|
|
7
|
+
const loading = document.body.hasAttribute('data-histoire-loading');
|
|
8
|
+
const generation = script?.dataset.histoireGeneration ?? document.body.dataset.generation;
|
|
9
|
+
const originalBase = script?.dataset.histoireBase ?? document.body.dataset.base ?? '/';
|
|
10
|
+
const events = new EventSource('/__histoire/dev/events');
|
|
11
|
+
let navigating = false;
|
|
12
|
+
let disposeTimer;
|
|
13
|
+
/** Preserve selected route and URL state across an updated application base. */
|
|
14
|
+
async function navigate(base) {
|
|
15
|
+
if (navigating)
|
|
16
|
+
return;
|
|
17
|
+
navigating = true;
|
|
18
|
+
events.close();
|
|
19
|
+
if (loading)
|
|
20
|
+
await leaveStartup();
|
|
21
|
+
const url = new URL(location.href);
|
|
22
|
+
if (url.pathname === '/')
|
|
23
|
+
url.pathname = base;
|
|
24
|
+
else if (originalBase !== base && !url.pathname.startsWith(base) && url.pathname.startsWith(originalBase))
|
|
25
|
+
url.pathname = base + url.pathname.slice(originalBase.length);
|
|
26
|
+
// Same-URL replace with a fragment can stay in current document. Explicit
|
|
27
|
+
// reload is required to exchange loader HTML for ready workbench HTML.
|
|
28
|
+
if (url.href === location.href)
|
|
29
|
+
location.reload();
|
|
30
|
+
else
|
|
31
|
+
location.replace(url.href);
|
|
32
|
+
}
|
|
33
|
+
events.onmessage = ({ data }) => {
|
|
34
|
+
let state;
|
|
35
|
+
try {
|
|
36
|
+
state = JSON.parse(data);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
clearTimeout(disposeTimer);
|
|
42
|
+
if (loading) {
|
|
43
|
+
if (state.status === 'ready')
|
|
44
|
+
void navigate(state.base);
|
|
45
|
+
else
|
|
46
|
+
applyStatus(state);
|
|
47
|
+
}
|
|
48
|
+
// Shutdown leaves workbench in place; reloading would only reach a closed listener.
|
|
49
|
+
else if (state.status !== 'closed' && (state.status !== 'ready' || state.generation !== generation)) {
|
|
50
|
+
void navigate(state.base);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const restart = document.getElementById('restart');
|
|
54
|
+
restart?.addEventListener('click', () => {
|
|
55
|
+
restart.disabled = true;
|
|
56
|
+
// New status arrives over the event stream; re-enable once the request settles.
|
|
57
|
+
void fetch('/__histoire/dev/restart', { method: 'POST' }).catch(() => { }).finally(() => {
|
|
58
|
+
restart.disabled = false;
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
events.onerror = () => {
|
|
62
|
+
if (loading) {
|
|
63
|
+
disposeTimer = setTimeout(() => {
|
|
64
|
+
document.getElementById('status').textContent = 'Connecting';
|
|
65
|
+
}, 3000);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
window.addEventListener('pagehide', () => {
|
|
69
|
+
events.close();
|
|
70
|
+
clearTimeout(disposeTimer);
|
|
71
|
+
}, { once: true });
|
|
72
|
+
}
|
|
73
|
+
connect();
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** Wireframe logo drawn by the startup screen; strokes and motion come from startup styles. */
|
|
2
|
+
export declare const blueprintMark = "<svg class=\"mark\" viewBox=\"0 0 512 512\" aria-hidden=\"true\" focusable=\"false\"><g opacity=\".5\"><rect width=\"314.30923\" height=\"406.60901\" x=\"-26.565063\" y=\"134.75079\" transform=\"rotate(-23.821262)\" rx=\"8\"/></g><rect width=\"314.30923\" height=\"406.60901\" x=\"77.571838\" y=\"72.808708\" transform=\"rotate(-4.5744534)\" rx=\"8\"/><path d=\"M152.59788 156.05591 191.25804 335.47786 273.64124 273.06608 359.38947 355.95134 320.72935 176.52942 238.34613 238.94118Z\"/></svg>";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Back sheet geometry from repository logo.svg. */
|
|
2
|
+
const back = '<rect width="314.30923" height="406.60901" x="-26.565063" y="134.75079" transform="rotate(-23.821262)" rx="8"/>';
|
|
3
|
+
/** Front sheet geometry from repository logo.svg. */
|
|
4
|
+
const front = '<rect width="314.30923" height="406.60901" x="77.571838" y="72.808708" transform="rotate(-4.5744534)" rx="8"/>';
|
|
5
|
+
/** Zap as one outline: the logo's two triangles share their diagonal edge, so their union is this hexagon. */
|
|
6
|
+
const zap = '<path d="M152.59788 156.05591 191.25804 335.47786 273.64124 273.06608 359.38947 355.95134 320.72935 176.52942 238.34613 238.94118Z"/>';
|
|
7
|
+
/** Wireframe logo drawn by the startup screen; strokes and motion come from startup styles. */
|
|
8
|
+
export const blueprintMark = `<svg class="mark" viewBox="0 0 512 512" aria-hidden="true" focusable="false"><g opacity=".5">${back}</g>${front}${zap}</svg>`;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PublicState } from '../protocol.js';
|
|
2
|
+
/** Render-time options for the startup document. */
|
|
3
|
+
export interface LoadingPageOptions {
|
|
4
|
+
/** Page without live lifecycle updates or navigation; `scripts` replace the lifecycle client. */
|
|
5
|
+
frozen?: boolean;
|
|
6
|
+
/** Browser assets loaded by a frozen page. */
|
|
7
|
+
scripts?: string[];
|
|
8
|
+
/** Extra markup appended to the body, such as the state switcher. */
|
|
9
|
+
extra?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Escapes server-provided detail before insertion into standalone document. */
|
|
12
|
+
export declare function escape(value: string): string;
|
|
13
|
+
/** Render immediate useful HTML without Vue, Vite transforms or project assets. */
|
|
14
|
+
export declare function renderLoadingPage(state: PublicState, options?: LoadingPageOptions): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { blueprintMark } from './mark.js';
|
|
2
|
+
import { statusTitle } from './status.js';
|
|
3
|
+
import { startupStyles } from './styles.js';
|
|
4
|
+
/** Escapes server-provided detail before insertion into standalone document. */
|
|
5
|
+
export function escape(value) {
|
|
6
|
+
return value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('"', '"');
|
|
7
|
+
}
|
|
8
|
+
/** Applies the workbench's stored color scheme before first paint; storage may be unavailable. */
|
|
9
|
+
const schemeScript = 'try{const s=localStorage.getItem("histoire-color-scheme");if(s==="dark"||s==="light")document.documentElement.dataset.scheme=s}catch{}';
|
|
10
|
+
/** Render immediate useful HTML without Vue, Vite transforms or project assets. */
|
|
11
|
+
export function renderLoadingPage(state, options = {}) {
|
|
12
|
+
const scripts = (options.frozen ? options.scripts ?? [] : ['lifecycle.js'])
|
|
13
|
+
.map(name => `<script type="module" src="/__histoire/dev/${name}"></script>`)
|
|
14
|
+
.join('');
|
|
15
|
+
const status = escape(state.status);
|
|
16
|
+
// `#outcome` stays in the document for every state so failure can expand into view.
|
|
17
|
+
return `<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Histoire</title><script>${schemeScript}</script><style>${startupStyles}</style></head><body data-histoire-loading data-status="${status}" data-generation="${escape(state.generation)}" data-base="${escape(state.base)}"><main class="startup">${blueprintMark}<h1>Histoire</h1><p id="status" role="status" aria-live="polite" data-tone="${status}">${statusTitle(state.status)}</p><div id="outcome"><div><p id="detail">${escape(state.error ?? '')}</p><button id="restart" type="button">Restart</button></div></div></main>${options.extra ?? ''}${scripts}</body></html>`;
|
|
18
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PublicState } from '../protocol.js';
|
|
2
|
+
/** Route serving the startup screen with a scripted state switcher for design iteration. */
|
|
3
|
+
export declare const designPlaygroundPath = "/__histoire/dev/loading";
|
|
4
|
+
/** Renders the startup screen in the requested state, driven client-side by `demo.js`. */
|
|
5
|
+
export declare function renderDesignPlayground(query: URLSearchParams, live: PublicState): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { escape, renderLoadingPage } from './page.js';
|
|
2
|
+
/** Route serving the startup screen with a scripted state switcher for design iteration. */
|
|
3
|
+
export const designPlaygroundPath = '/__histoire/dev/loading';
|
|
4
|
+
/** States a viewer can jump to; `ready` plays the handoff fade. */
|
|
5
|
+
const steps = ['starting', 'restarting', 'failed', 'ready'];
|
|
6
|
+
/** Realistic one-line failure, matching what the proxy keeps from runtime errors. */
|
|
7
|
+
const sampleError = 'Cannot find module \'./plugins/theme\' imported from /home/me/project/histoire.config.ts';
|
|
8
|
+
/** Fixed top switcher; its styles stay inside this dev-only page. */
|
|
9
|
+
const switcherStyles = `<style>
|
|
10
|
+
.design-switcher {
|
|
11
|
+
position: fixed; z-index: 10; left: 50%; top: 12px; transform: translateX(-50%);
|
|
12
|
+
display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; max-width: calc(100vw - 32px);
|
|
13
|
+
padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
|
|
14
|
+
}
|
|
15
|
+
.design-switcher button {
|
|
16
|
+
padding: 7px 10px; border: 0; border-radius: 6px; background: none; color: var(--muted);
|
|
17
|
+
font: 12px/1 Inter, ui-sans-serif, system-ui, sans-serif; cursor: pointer;
|
|
18
|
+
}
|
|
19
|
+
.design-switcher button:hover { color: var(--text); }
|
|
20
|
+
.design-switcher button[aria-pressed] { background: var(--line); color: var(--text); }
|
|
21
|
+
.design-switcher hr { width: 1px; margin: 2px 4px; border: 0; background: var(--line); }
|
|
22
|
+
</style>`;
|
|
23
|
+
/** Renders the startup screen in the requested state, driven client-side by `demo.js`. */
|
|
24
|
+
export function renderDesignPlayground(query, live) {
|
|
25
|
+
const requested = query.get('status');
|
|
26
|
+
const status = requested && steps.includes(requested) && requested !== 'ready' ? requested : 'starting';
|
|
27
|
+
const error = query.get('error') ?? sampleError;
|
|
28
|
+
const state = { ...live, status, error: status === 'failed' ? error : undefined };
|
|
29
|
+
const buttons = steps.map(step => `<button type="button" value="${step}"${step === status ? ' aria-pressed' : ''}>${step}</button>`).join('');
|
|
30
|
+
const switcher = `${switcherStyles}<nav class="design-switcher" aria-label="Startup states" data-demo data-error="${escape(error)}">${buttons}<hr><button type="button" value="sequence">Play sequence</button></nav>`;
|
|
31
|
+
return renderLoadingPage(state, { frozen: true, scripts: ['demo.js'], extra: switcher });
|
|
32
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Headline shared by server-rendered startup page and live status updates. */
|
|
2
|
+
export function statusTitle(status) {
|
|
3
|
+
switch (status) {
|
|
4
|
+
case 'failed': return 'Failed to start';
|
|
5
|
+
case 'restarting': return 'Restarting';
|
|
6
|
+
case 'closed': return 'Stopped';
|
|
7
|
+
default: return 'Starting';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { startupBackground } from '../appearance.js';
|
|
2
|
+
/** Workbench dark palette (`histoire-app` tokens.pcss), so the handoff keeps the same colors. */
|
|
3
|
+
const darkTokens = `
|
|
4
|
+
color-scheme: dark;
|
|
5
|
+
--background: ${startupBackground.dark};
|
|
6
|
+
--surface: rgb(22 23 27);
|
|
7
|
+
--text: rgb(230 231 234);
|
|
8
|
+
--muted: rgb(138 142 151);
|
|
9
|
+
--line: rgb(38 40 45);
|
|
10
|
+
--accent: rgb(52 211 153);
|
|
11
|
+
--danger: rgb(248 113 113);
|
|
12
|
+
--danger-soft: rgb(42 29 31);
|
|
13
|
+
`;
|
|
14
|
+
/** Standalone document exception: must render before project CSS or Vue exists. */
|
|
15
|
+
export const startupStyles = `
|
|
16
|
+
/* Light palette mirrors workbench home tokens; dark follows the stored app choice, else the system. */
|
|
17
|
+
:root {
|
|
18
|
+
color-scheme: light;
|
|
19
|
+
--background: ${startupBackground.light};
|
|
20
|
+
--surface: rgb(255 255 255);
|
|
21
|
+
--text: rgb(24 24 27);
|
|
22
|
+
--muted: rgb(95 99 112);
|
|
23
|
+
--line: rgb(228 228 231);
|
|
24
|
+
--accent: rgb(5 150 105);
|
|
25
|
+
--danger: rgb(220 38 38);
|
|
26
|
+
--danger-soft: rgb(254 242 242);
|
|
27
|
+
--ease-out: cubic-bezier(.2, .8, .2, 1);
|
|
28
|
+
}
|
|
29
|
+
:root[data-scheme="dark"] {${darkTokens}}
|
|
30
|
+
@media (prefers-color-scheme: dark) {
|
|
31
|
+
:root:not([data-scheme="light"]) {${darkTokens}}
|
|
32
|
+
}
|
|
33
|
+
* { box-sizing: border-box; }
|
|
34
|
+
body {
|
|
35
|
+
margin: 0;
|
|
36
|
+
background: var(--background);
|
|
37
|
+
color: var(--text);
|
|
38
|
+
font-family: Inter, ui-sans-serif, system-ui, sans-serif;
|
|
39
|
+
}
|
|
40
|
+
.startup {
|
|
41
|
+
display: grid;
|
|
42
|
+
place-content: center;
|
|
43
|
+
justify-items: center;
|
|
44
|
+
min-height: 100svh;
|
|
45
|
+
padding: 32px;
|
|
46
|
+
text-align: center;
|
|
47
|
+
animation: startup-enter .4s var(--ease-out);
|
|
48
|
+
transition: opacity .2s ease-in;
|
|
49
|
+
}
|
|
50
|
+
/* Handoff to the ready workbench fades the screen out before navigation. */
|
|
51
|
+
body[data-leaving] .startup { opacity: 0; }
|
|
52
|
+
@keyframes startup-enter { from { opacity: 0; } }
|
|
53
|
+
.startup h1 { margin: 0; font-size: 30px; font-weight: 600; letter-spacing: -1px; }
|
|
54
|
+
|
|
55
|
+
/* Wireframe logo: dashes march while working; failure freezes them where they are and greys the drawing. */
|
|
56
|
+
.mark { width: 140px; height: 140px; margin-bottom: 24px; overflow: visible; }
|
|
57
|
+
.mark rect, .mark path {
|
|
58
|
+
fill: transparent;
|
|
59
|
+
stroke: var(--accent);
|
|
60
|
+
stroke-width: 4;
|
|
61
|
+
stroke-dasharray: 14 10;
|
|
62
|
+
animation: mark-march 1.2s linear infinite;
|
|
63
|
+
transition: stroke .5s;
|
|
64
|
+
}
|
|
65
|
+
@keyframes mark-march { to { stroke-dashoffset: -24; } }
|
|
66
|
+
[data-status="failed"] .mark rect, [data-status="failed"] .mark path, [data-status="closed"] .mark rect, [data-status="closed"] .mark path {
|
|
67
|
+
animation-play-state: paused;
|
|
68
|
+
stroke: var(--muted);
|
|
69
|
+
}
|
|
70
|
+
/* Entering failure plays one small falter; the animation restarts whenever the state is re-entered. */
|
|
71
|
+
[data-status="failed"] .mark { animation: mark-falter .5s var(--ease-out); }
|
|
72
|
+
@keyframes mark-falter {
|
|
73
|
+
20% { transform: translateX(-5px) rotate(-1.5deg); }
|
|
74
|
+
45% { transform: translateX(4px) rotate(1deg); }
|
|
75
|
+
70% { transform: translateX(-2px); }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* Status headline: working states shimmer through a clipped gradient. */
|
|
79
|
+
#status { margin: 10px 0 0; font-size: 14px; line-height: 1.5; color: var(--muted); }
|
|
80
|
+
#status:not([data-tone="failed"]):not([data-tone="closed"]) {
|
|
81
|
+
background: linear-gradient(90deg, var(--muted) 35%, var(--text) 50%, var(--muted) 65%) 0 0 / 300% 100%;
|
|
82
|
+
-webkit-background-clip: text;
|
|
83
|
+
background-clip: text;
|
|
84
|
+
color: transparent;
|
|
85
|
+
animation: status-shimmer 2s linear infinite;
|
|
86
|
+
}
|
|
87
|
+
@keyframes status-shimmer {
|
|
88
|
+
from { background-position: 100% 0; }
|
|
89
|
+
to { background-position: 0 0; }
|
|
90
|
+
}
|
|
91
|
+
#status[data-tone="failed"] { color: var(--danger); }
|
|
92
|
+
|
|
93
|
+
/* Failure outcome expands from zero height (grid row 0fr to 1fr) and collapses back on restart. */
|
|
94
|
+
#outcome {
|
|
95
|
+
display: grid;
|
|
96
|
+
grid-template-rows: 0fr;
|
|
97
|
+
opacity: 0;
|
|
98
|
+
visibility: hidden;
|
|
99
|
+
transition: grid-template-rows .4s var(--ease-out), opacity .25s, visibility 0s .4s;
|
|
100
|
+
}
|
|
101
|
+
[data-status="failed"] #outcome {
|
|
102
|
+
grid-template-rows: 1fr;
|
|
103
|
+
opacity: 1;
|
|
104
|
+
visibility: visible;
|
|
105
|
+
transition: grid-template-rows .4s var(--ease-out), opacity .3s .1s, visibility 0s;
|
|
106
|
+
}
|
|
107
|
+
#outcome > div { display: grid; justify-items: center; min-height: 0; overflow: hidden; }
|
|
108
|
+
#detail {
|
|
109
|
+
max-width: 520px;
|
|
110
|
+
margin: 16px 0 0;
|
|
111
|
+
padding: 12px 14px;
|
|
112
|
+
border: 1px solid var(--danger-soft);
|
|
113
|
+
border-radius: 8px;
|
|
114
|
+
background: var(--danger-soft);
|
|
115
|
+
font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
116
|
+
text-align: left;
|
|
117
|
+
overflow-wrap: anywhere;
|
|
118
|
+
}
|
|
119
|
+
#detail:empty { display: none; }
|
|
120
|
+
#restart {
|
|
121
|
+
margin: 14px 0 2px;
|
|
122
|
+
padding: 7px 14px;
|
|
123
|
+
border: 1px solid var(--line);
|
|
124
|
+
border-radius: 8px;
|
|
125
|
+
background: var(--surface);
|
|
126
|
+
color: var(--text);
|
|
127
|
+
font-family: inherit;
|
|
128
|
+
font-size: 13px;
|
|
129
|
+
font-weight: 500;
|
|
130
|
+
line-height: 1.2;
|
|
131
|
+
cursor: pointer;
|
|
132
|
+
}
|
|
133
|
+
#restart:hover { border-color: var(--accent); }
|
|
134
|
+
#restart:disabled { opacity: .6; cursor: default; }
|
|
135
|
+
|
|
136
|
+
@media (prefers-reduced-motion: reduce) {
|
|
137
|
+
*, *::before, *::after { animation: none !important; transition: none !important; }
|
|
138
|
+
}
|
|
139
|
+
`;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PublicState } from '../protocol.js';
|
|
2
|
+
/**
|
|
3
|
+
* Applies one public state to the startup page. CSS reacts to `body[data-status]` (logo, failure
|
|
4
|
+
* outcome); the headline text slides out and back in so successive states read as a sequence.
|
|
5
|
+
*/
|
|
6
|
+
export declare function applyStatus(state: Pick<PublicState, 'status' | 'error'>): void;
|
|
7
|
+
/** Fades the startup screen out, then resolves; callers navigate afterwards. */
|
|
8
|
+
export declare function leaveStartup(): Promise<void>;
|