@bigmistqke/whiteboard 0.5.0 → 0.6.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.
- package/README.md +125 -25
- package/bin/whiteboard.ts +299 -16
- package/dist/bin/whiteboard.js +247 -17
- package/dist/client/runtime.js +22 -10
- package/dist/plugins/ansi/README.md +36 -0
- package/dist/plugins/ansi/index.js +64 -0
- package/dist/plugins/ansi/public/style.css +28 -0
- package/dist/plugins/badge/README.md +28 -0
- package/dist/plugins/badge/index.js +24 -0
- package/dist/plugins/badge/public/style.css +30 -0
- package/dist/plugins/chat/public/style.css +7 -2
- package/dist/plugins/code/README.md +4 -2
- package/dist/plugins/code/diff.js +12 -2
- package/dist/plugins/grid/README.md +12 -12
- package/dist/plugins/grid/index.js +7 -19
- package/dist/plugins/grid/public/style.css +4 -33
- package/dist/plugins/iframe/README.md +7 -7
- package/dist/plugins/iframe/index.js +11 -11
- package/dist/plugins/iframe/public/style.css +15 -0
- package/dist/plugins/index.js +7 -3
- package/dist/plugins/lightbox/README.md +22 -0
- package/dist/plugins/lightbox/index.js +20 -0
- package/dist/plugins/lightbox/public/client.js +4 -0
- package/dist/plugins/lightbox/public/style.css +66 -0
- package/dist/plugins/steps/README.md +3 -3
- package/dist/plugins/steps/index.js +3 -42
- package/dist/plugins/steps/public/client.js +1 -1
- package/dist/plugins/terminal/host.js +1 -1
- package/dist/plugins/terminal/public/client.js +1 -1
- package/dist/plugins/window/README.md +34 -14
- package/dist/plugins/window/index.js +21 -13
- package/dist/src/auth.js +4 -3
- package/dist/src/client/page/base.css +61 -1
- package/dist/src/client/page/main.js +60 -14
- package/dist/src/entries.js +217 -0
- package/dist/src/events.js +1 -1
- package/dist/src/hub.js +272 -0
- package/dist/src/loader.js +4 -1
- package/dist/src/package.js +23 -1
- package/dist/src/pages/blocks.js +1 -0
- package/dist/src/pages/index.js +1 -1
- package/dist/src/pages/markdown.js +87 -33
- package/dist/src/pages/render.js +116 -14
- package/dist/src/pages/window.js +16 -18
- package/dist/src/running.js +37 -2
- package/dist/src/serve.js +111 -2
- package/dist/src/server.js +49 -14
- package/package.json +1 -1
- package/plugins/ansi/README.md +36 -0
- package/plugins/ansi/index.ts +95 -0
- package/plugins/ansi/public/style.css +28 -0
- package/plugins/badge/README.md +28 -0
- package/plugins/badge/index.ts +35 -0
- package/plugins/badge/public/style.css +30 -0
- package/plugins/chat/public/style.css +7 -2
- package/plugins/code/README.md +4 -2
- package/plugins/code/diff.ts +14 -2
- package/plugins/grid/README.md +12 -12
- package/plugins/grid/index.ts +11 -26
- package/plugins/grid/public/style.css +4 -33
- package/plugins/iframe/README.md +7 -7
- package/plugins/iframe/index.ts +15 -15
- package/plugins/iframe/public/style.css +15 -0
- package/plugins/index.ts +6 -2
- package/plugins/lightbox/README.md +22 -0
- package/plugins/lightbox/client.ts +99 -0
- package/plugins/lightbox/index.ts +25 -0
- package/plugins/lightbox/public/style.css +66 -0
- package/plugins/steps/README.md +3 -3
- package/plugins/steps/client.ts +15 -6
- package/plugins/steps/index.ts +3 -46
- package/plugins/terminal/client.ts +16 -7
- package/plugins/window/README.md +34 -14
- package/plugins/window/index.ts +20 -13
- package/skills/whiteboard/SKILL.md +17 -10
- package/src/auth.ts +5 -3
- package/src/client/base.ts +19 -0
- package/src/client/forms.ts +2 -1
- package/src/client/markdown.ts +2 -1
- package/src/client/page/base.css +61 -1
- package/src/client/page/elsewhere.ts +72 -16
- package/src/client/page/fresh.ts +2 -1
- package/src/client/page/sort.ts +2 -1
- package/src/client/runtime.ts +11 -9
- package/src/define.ts +66 -7
- package/src/entries.ts +269 -0
- package/src/events.ts +2 -1
- package/src/hub.ts +355 -0
- package/src/loader.ts +7 -1
- package/src/package.ts +22 -0
- package/src/pages/blocks.ts +3 -0
- package/src/pages/index.ts +4 -2
- package/src/pages/markdown.ts +89 -32
- package/src/pages/render.ts +134 -13
- package/src/pages/window.ts +16 -25
- package/src/running.ts +47 -1
- package/src/serve.ts +114 -1
- package/src/server.ts +80 -14
- package/dist/plugins/gallery/README.md +0 -30
- package/dist/plugins/gallery/index.js +0 -75
- package/dist/plugins/gallery/public/client.js +0 -1
- package/dist/plugins/gallery/public/style.css +0 -90
- package/plugins/gallery/README.md +0 -30
- package/plugins/gallery/client.tsx +0 -70
- package/plugins/gallery/index.ts +0 -89
- package/plugins/gallery/public/style.css +0 -90
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* a coloured dot and a word, not a pill */
|
|
2
|
+
.wb-badge {
|
|
3
|
+
--c: var(--muted);
|
|
4
|
+
display: inline-flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
gap: var(--space-sm);
|
|
7
|
+
font: 500 var(--ui-tiny)/1 var(--sans);
|
|
8
|
+
color: var(--muted);
|
|
9
|
+
white-space: nowrap;
|
|
10
|
+
vertical-align: 0.1em;
|
|
11
|
+
}
|
|
12
|
+
.wb-badge::before {
|
|
13
|
+
content: '';
|
|
14
|
+
width: 7px;
|
|
15
|
+
height: 7px;
|
|
16
|
+
border-radius: 50%;
|
|
17
|
+
background: var(--c);
|
|
18
|
+
}
|
|
19
|
+
.wb-badge:is([data-badge='done'], [data-badge='ok'], [data-badge='yes'], [data-badge='good']) {
|
|
20
|
+
--c: var(--ok);
|
|
21
|
+
}
|
|
22
|
+
.wb-badge:is([data-badge='active'], [data-badge='new'], [data-badge='info']) {
|
|
23
|
+
--c: var(--info);
|
|
24
|
+
}
|
|
25
|
+
.wb-badge:is([data-badge='open'], [data-badge='todo'], [data-badge='maybe'], [data-badge='warning']) {
|
|
26
|
+
--c: var(--warn);
|
|
27
|
+
}
|
|
28
|
+
.wb-badge:is([data-badge='blocked'], [data-badge='no'], [data-badge='bad'], [data-badge='error']) {
|
|
29
|
+
--c: var(--bad);
|
|
30
|
+
}
|
|
@@ -34,6 +34,8 @@
|
|
|
34
34
|
color: var(--accent);
|
|
35
35
|
}
|
|
36
36
|
.wb-chat-bubble {
|
|
37
|
+
max-width: 100%;
|
|
38
|
+
box-sizing: border-box;
|
|
37
39
|
white-space: pre-wrap;
|
|
38
40
|
padding: var(--space-md) var(--space-xl);
|
|
39
41
|
border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-sm);
|
|
@@ -54,12 +56,15 @@
|
|
|
54
56
|
.wb-chat-bubble[data-md] :is(p, ul, ol, pre, blockquote) {
|
|
55
57
|
margin: 0 0 0.5em;
|
|
56
58
|
}
|
|
59
|
+
/* code wraps at the bubble's edge, as the text around it does: a long line would otherwise make the
|
|
60
|
+
bubble as wide (it fits its content), and the chat and the page with it; and a scrollbar under it
|
|
61
|
+
is drawn over the text below in WebKit (its height left out when the block first lays out) */
|
|
57
62
|
.wb-chat-bubble[data-md] pre {
|
|
58
63
|
font-size: var(--ui-small);
|
|
59
64
|
padding: var(--space-md) var(--space-lg);
|
|
60
65
|
border-radius: var(--radius-sm);
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
white-space: pre-wrap;
|
|
67
|
+
overflow-wrap: anywhere;
|
|
63
68
|
}
|
|
64
69
|
.wb-chat-message[data-from='you'] .wb-chat-bubble[data-md] a {
|
|
65
70
|
color: inherit;
|
|
@@ -17,8 +17,10 @@ A `diff` fence (what `git diff` or `diff -u` prints) is shown for reading:
|
|
|
17
17
|
each file's headers become its name, a hunk's `@@ … @@` line becomes a `⋯`
|
|
18
18
|
where lines are skipped, lines have their numbers in a gutter and are tinted
|
|
19
19
|
when added or removed. Each line in a hunk also says where it is from
|
|
20
|
-
(`src/a.ts:12`), and a comment on it records that.
|
|
21
|
-
|
|
20
|
+
(`src/a.ts:12`), and a comment on it records that. A hunk can start with a
|
|
21
|
+
bare `@@`: its lines show without numbers. `---` and `+++` lines name the file
|
|
22
|
+
without a `diff --git` above them. Use four backticks around it, since a diff
|
|
23
|
+
can hold three.
|
|
22
24
|
|
|
23
25
|
A missing or unknown language renders as plain text. Fences named after
|
|
24
26
|
another block, such as `mermaid`, still go to that block.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// plugins/code/diff.ts
|
|
2
2
|
const unprefix = (p) => p.replace(/\t.*$/, "").replace(/^"|"$/g, "").replace(/^[ab]\//, "");
|
|
3
3
|
function diffLines(text) {
|
|
4
|
-
if (!/^(
|
|
5
|
-
let file = "", oldFile = "", oldN = 0, newN = 0, inHunk = false;
|
|
4
|
+
if (!/^(@@|diff --git )/m.test(text) && !/^--- .*\n\+\+\+ /m.test(text)) return text.split("\n").map((line) => ({ kind: line[0] === "+" ? "add" : line[0] === "-" ? "del" : "context" }));
|
|
5
|
+
let file = "", oldFile = "", oldN = 0, newN = 0, numbered = false, inHunk = false;
|
|
6
6
|
let status = "", renamedFrom = "";
|
|
7
7
|
return text.split("\n").map((line) => {
|
|
8
8
|
const at = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(line);
|
|
@@ -10,6 +10,15 @@ function diffLines(text) {
|
|
|
10
10
|
oldN = Number(at[1]);
|
|
11
11
|
newN = Number(at[2]);
|
|
12
12
|
inHunk = true;
|
|
13
|
+
numbered = true;
|
|
14
|
+
return {
|
|
15
|
+
kind: "hunk",
|
|
16
|
+
label: ""
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (line.startsWith("@@")) {
|
|
20
|
+
inHunk = true;
|
|
21
|
+
numbered = false;
|
|
13
22
|
return {
|
|
14
23
|
kind: "hunk",
|
|
15
24
|
label: ""
|
|
@@ -18,6 +27,7 @@ function diffLines(text) {
|
|
|
18
27
|
if (inHunk) {
|
|
19
28
|
const sign = line[0];
|
|
20
29
|
const where = (side, n) => {
|
|
30
|
+
if (!numbered) return {};
|
|
21
31
|
const name = side === "old" ? oldFile || file : file || oldFile;
|
|
22
32
|
return name ? {
|
|
23
33
|
n,
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
Cards in a responsive grid
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
Cards in a responsive grid, one per item: a heading at the block's
|
|
2
|
+
shallowest heading level starts one, titled by it, and so does a `---`,
|
|
3
|
+
untitled; everything up to the next is the card body (any markdown,
|
|
4
|
+
including other blocks). Content with neither is one card.
|
|
4
5
|
|
|
5
|
-
A heading that ends in
|
|
6
|
-
|
|
7
|
-
`blocked no bad error` red; any other word is grey.
|
|
6
|
+
A heading that ends in a badge (`:badge[done]`) shows it at the card's
|
|
7
|
+
right edge.
|
|
8
8
|
|
|
9
9
|
Attributes: `cols` (target column count on a wide screen, default 3).
|
|
10
10
|
|
|
11
11
|
```markdown
|
|
12
12
|
:::grid{cols=3}
|
|
13
|
-
### Parser
|
|
13
|
+
### Parser :badge[done]
|
|
14
14
|
remark + remark-directive.
|
|
15
15
|
|
|
16
|
-
### Islands
|
|
16
|
+
### Islands :badge[active]
|
|
17
17
|
Solid components mounted per block.
|
|
18
18
|
|
|
19
|
-
### Docs
|
|
19
|
+
### Docs :badge[todo]
|
|
20
20
|
Live examples on `/_/docs`.
|
|
21
21
|
:::
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
:::grid{cols=3}
|
|
25
|
-
### Parser
|
|
25
|
+
### Parser :badge[done]
|
|
26
26
|
remark + remark-directive.
|
|
27
27
|
|
|
28
|
-
### Islands
|
|
28
|
+
### Islands :badge[active]
|
|
29
29
|
Solid components mounted per block.
|
|
30
30
|
|
|
31
|
-
### Docs
|
|
31
|
+
### Docs :badge[todo]
|
|
32
32
|
Live examples on `/_/docs`.
|
|
33
33
|
:::
|
|
@@ -2,28 +2,16 @@ import { builtinPublic } from "../../src/package.js";
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import { definePlugin, html, raw } from "@bigmistqke/whiteboard";
|
|
4
4
|
// plugins/grid/index.ts
|
|
5
|
-
|
|
5
|
+
/** A card per item (DirectiveContext.items): a heading, or a `---`, starts one. */
|
|
6
6
|
async function render(ctx) {
|
|
7
|
-
const
|
|
7
|
+
const items = await ctx.items();
|
|
8
8
|
const cols = Number(ctx.attrs.cols);
|
|
9
9
|
const style = cols ? html` style="--wb-grid-cols:${cols}"` : null;
|
|
10
|
-
const cards =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
title = m[1];
|
|
16
|
-
badge = m[2].trim();
|
|
17
|
-
}
|
|
18
|
-
const b = badge && html`<span class="wb-badge" data-badge="${slug(badge)}">${badge}</span>`;
|
|
19
|
-
const head = (title || b) && html`<header>${title && html`<h3>${raw(title)}</h3>`}${b}</header>`;
|
|
20
|
-
return html`<article class="wb-card" ${badge && html` data-badge="${slug(badge)}"`}>
|
|
21
|
-
${head}
|
|
22
|
-
<div class="wb-card-body">${raw(s.html)}</div>
|
|
23
|
-
</article>`;
|
|
24
|
-
});
|
|
25
|
-
return html`${raw(intro)}
|
|
26
|
-
<div class="wb-grid${"narrow" in ctx.attrs ? "" : " wb-wide"}" ${style}>${cards}</div>`;
|
|
10
|
+
const cards = items.map((s) => html`<article class="wb-card">
|
|
11
|
+
${s.title && html`<header><h3>${raw(s.title)}</h3></header>`}
|
|
12
|
+
<div class="wb-card-body">${raw(s.html)}</div>
|
|
13
|
+
</article>`);
|
|
14
|
+
return html`<div class="wb-grid${"narrow" in ctx.attrs ? "" : " wb-wide"}" ${style}>${cards}</div>`;
|
|
27
15
|
}
|
|
28
16
|
function grid() {
|
|
29
17
|
return definePlugin({
|
|
@@ -18,10 +18,6 @@
|
|
|
18
18
|
min-width: 0;
|
|
19
19
|
}
|
|
20
20
|
.wb-card > header {
|
|
21
|
-
display: flex;
|
|
22
|
-
gap: var(--space-lg);
|
|
23
|
-
align-items: baseline;
|
|
24
|
-
justify-content: space-between;
|
|
25
21
|
margin-bottom: 0.55em;
|
|
26
22
|
}
|
|
27
23
|
.wb-card h3 {
|
|
@@ -39,33 +35,8 @@
|
|
|
39
35
|
margin-bottom: 0;
|
|
40
36
|
}
|
|
41
37
|
|
|
42
|
-
/* badge
|
|
43
|
-
.wb-badge {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
display: inline-flex;
|
|
47
|
-
align-items: center;
|
|
48
|
-
gap: var(--space-sm);
|
|
49
|
-
font: 500 var(--ui-tiny)/1 var(--sans);
|
|
50
|
-
color: var(--muted);
|
|
51
|
-
white-space: nowrap;
|
|
52
|
-
}
|
|
53
|
-
.wb-badge::before {
|
|
54
|
-
content: '';
|
|
55
|
-
width: 7px;
|
|
56
|
-
height: 7px;
|
|
57
|
-
border-radius: 50%;
|
|
58
|
-
background: var(--c);
|
|
59
|
-
}
|
|
60
|
-
.wb-badge:is([data-badge='done'], [data-badge='ok'], [data-badge='yes'], [data-badge='good']) {
|
|
61
|
-
--c: var(--ok);
|
|
62
|
-
}
|
|
63
|
-
.wb-badge:is([data-badge='active'], [data-badge='new'], [data-badge='info']) {
|
|
64
|
-
--c: var(--info);
|
|
65
|
-
}
|
|
66
|
-
.wb-badge:is([data-badge='open'], [data-badge='todo'], [data-badge='maybe'], [data-badge='warning']) {
|
|
67
|
-
--c: var(--warn);
|
|
68
|
-
}
|
|
69
|
-
.wb-badge:is([data-badge='blocked'], [data-badge='no'], [data-badge='bad'], [data-badge='error']) {
|
|
70
|
-
--c: var(--bad);
|
|
38
|
+
/* a badge that ends the heading (`### Parser :badge[done]`) sits at the card's right edge */
|
|
39
|
+
.wb-card h3 > .wb-badge:last-child {
|
|
40
|
+
float: right;
|
|
41
|
+
margin: 0.45em 0 0 var(--space-lg);
|
|
71
42
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
Another page inside this one: a running app (a dev server), a deployed
|
|
2
|
-
site, or an HTML file next to the pages.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
site, or an HTML file next to the pages. Drag the frame's bottom edge to
|
|
3
|
+
make it taller. With `compose=window`, it is in a window: a header with its label
|
|
4
|
+
(or, without one, its address), a button that opens it on its own, and one
|
|
5
|
+
that fills the browser window with it (the same button, or Esc, puts it
|
|
6
|
+
back).
|
|
6
7
|
|
|
7
8
|
Attributes: `src` (required: an http(s) URL, or a path such as `demo.html`
|
|
8
9
|
for `.whiteboard/pages/demo.html`), `height` (a number of pixels or a CSS
|
|
9
|
-
length, default 480), `wide` (wider than the text column)
|
|
10
|
-
header: the frame alone).
|
|
10
|
+
length, default 480), `compose=window`, `wide` (wider than the text column).
|
|
11
11
|
|
|
12
12
|
```markdown
|
|
13
|
-
::iframe[The app as it runs now]{src="http://localhost:5173" height=600 wide}
|
|
13
|
+
::iframe[The app as it runs now]{src="http://localhost:5173" height=600 compose=window wide}
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
A site that forbids being framed (most large ones do, with
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { builtinPublic } from "../../src/package.js";
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
-
import { definePlugin, html
|
|
3
|
+
import { definePlugin, html } from "@bigmistqke/whiteboard";
|
|
4
4
|
// plugins/iframe/index.ts
|
|
5
5
|
/** http(s), protocol-relative, or a path on this server; never `javascript:` or `data:`. */
|
|
6
6
|
const safeSrc = (src) => /^(https?:)?\/\//i.test(src) || !/^[a-z][a-z0-9+.-]*:/i.test(src);
|
|
@@ -15,15 +15,14 @@ async function render(ctx) {
|
|
|
15
15
|
if (!src) return html`<pre class="wb-error">iframe: needs a src, like ::iframe{src="http://localhost:5173"}</pre>`;
|
|
16
16
|
if (!safeSrc(src)) return html`<pre class="wb-error">iframe: src must be an http(s) URL or a path, not ${src.split(":")[0]}:</pre>`;
|
|
17
17
|
const title = ctx.labelText ?? ctx.attrs.title ?? src;
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
18
|
+
return html`<div class="wb-iframe-frame" style="height: ${height(ctx.attrs.height)}">
|
|
19
|
+
<iframe src="${src}" title="${title}" loading="lazy" referrerpolicy="no-referrer"></iframe>
|
|
20
|
+
</div>`;
|
|
21
|
+
}
|
|
22
|
+
/** What it shows on its own, for the ↗ of a window around it: its address. */
|
|
23
|
+
function open(ctx) {
|
|
24
|
+
const src = (ctx.attrs.src ?? "").trim();
|
|
25
|
+
return src && safeSrc(src) ? src : null;
|
|
27
26
|
}
|
|
28
27
|
function iframe() {
|
|
29
28
|
return definePlugin({
|
|
@@ -31,9 +30,10 @@ function iframe() {
|
|
|
31
30
|
public: builtinPublic("iframe"),
|
|
32
31
|
blocks: { iframe: {
|
|
33
32
|
html: render,
|
|
33
|
+
open,
|
|
34
34
|
style: "style.css"
|
|
35
35
|
} },
|
|
36
36
|
docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
export { iframe as default, height, render, safeSrc };
|
|
39
|
+
export { iframe as default, height, open, render, safeSrc };
|
|
@@ -11,3 +11,18 @@
|
|
|
11
11
|
height: 100%;
|
|
12
12
|
border: 0;
|
|
13
13
|
}
|
|
14
|
+
/* in a window (`::iframe{src window}`): the frame is its body, edge to edge; filling the browser
|
|
15
|
+
window, as tall as it is */
|
|
16
|
+
.wb-window-body:has(> .wb-iframe-frame:only-child) {
|
|
17
|
+
padding: 0;
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
}
|
|
20
|
+
.wb-window[data-wb-maximized] .wb-window-body:has(> .wb-iframe-frame:only-child) {
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
}
|
|
24
|
+
.wb-window[data-wb-maximized] .wb-iframe-frame {
|
|
25
|
+
flex: 1;
|
|
26
|
+
height: auto !important;
|
|
27
|
+
resize: none;
|
|
28
|
+
}
|
package/dist/plugins/index.js
CHANGED
|
@@ -5,7 +5,6 @@ import comments from "./comments/index.js";
|
|
|
5
5
|
import details from "./details/index.js";
|
|
6
6
|
import forge from "./forge/index.js";
|
|
7
7
|
import formPlugin from "./form/index.js";
|
|
8
|
-
import gallery from "./gallery/index.js";
|
|
9
8
|
import grid from "./grid/index.js";
|
|
10
9
|
import iframe from "./iframe/index.js";
|
|
11
10
|
import mermaid from "./mermaid/index.js";
|
|
@@ -13,6 +12,9 @@ import quiet from "./quiet/index.js";
|
|
|
13
12
|
import windows from "./window/index.js";
|
|
14
13
|
import steps from "./steps/index.js";
|
|
15
14
|
import draft from "./draft/index.js";
|
|
15
|
+
import lightbox from "./lightbox/index.js";
|
|
16
|
+
import badge from "./badge/index.js";
|
|
17
|
+
import ansi from "./ansi/index.js";
|
|
16
18
|
// plugins/index.ts
|
|
17
19
|
function builtins() {
|
|
18
20
|
return [
|
|
@@ -23,14 +25,16 @@ function builtins() {
|
|
|
23
25
|
details(),
|
|
24
26
|
forge(),
|
|
25
27
|
formPlugin(),
|
|
26
|
-
gallery(),
|
|
27
28
|
grid(),
|
|
28
29
|
iframe(),
|
|
29
30
|
mermaid(),
|
|
30
31
|
quiet(),
|
|
31
32
|
windows(),
|
|
32
33
|
steps(),
|
|
33
|
-
draft()
|
|
34
|
+
draft(),
|
|
35
|
+
lightbox(),
|
|
36
|
+
badge(),
|
|
37
|
+
ansi()
|
|
34
38
|
];
|
|
35
39
|
}
|
|
36
40
|
export { builtins };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Composed around a container, the pictures in it open large on a click: ← →
|
|
2
|
+
(or ‹ ›) step through the container's pictures and videos, Esc or a click
|
|
3
|
+
beside it closes. A picture that is a link keeps going to its link, and a
|
|
4
|
+
video is not opened by a click (that plays it), but takes part in the
|
|
5
|
+
stepping.
|
|
6
|
+
|
|
7
|
+
```markdown
|
|
8
|
+
:::grid{min=200px compose=lightbox}
|
|
9
|
+
### Dunes
|
|
10
|
+
::image{src="dunes.jpg" alt="Dunes at dusk"}
|
|
11
|
+
Option A: warm, quiet.
|
|
12
|
+
|
|
13
|
+
### Coast
|
|
14
|
+
::image{src="coast.jpg"}
|
|
15
|
+
Option B: more contrast.
|
|
16
|
+
:::
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
That is a gallery: a grid, and a lightbox around it. It goes around any
|
|
20
|
+
container (a window, steps, a list of pictures), and with other parts:
|
|
21
|
+
`compose=lightbox,window`. A picture's caption in the lightbox is its alt
|
|
22
|
+
text (an `::image`'s label).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { builtinPublic } from "../../src/package.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { definePlugin, html, raw } from "@bigmistqke/whiteboard";
|
|
4
|
+
// plugins/lightbox/index.ts
|
|
5
|
+
/** The container's HTML with its outer element marked; around it, when it starts with no element. */
|
|
6
|
+
function mark(children) {
|
|
7
|
+
const marked = children.replace(/^(\s*<[a-zA-Z][\w-]*)(?=[\s>/])/, "$1 data-lightbox");
|
|
8
|
+
return marked !== children ? marked : String(html`<div data-lightbox>${raw(children)}</div>`);
|
|
9
|
+
}
|
|
10
|
+
function lightbox() {
|
|
11
|
+
return definePlugin({
|
|
12
|
+
name: "lightbox",
|
|
13
|
+
public: builtinPublic("lightbox"),
|
|
14
|
+
style: "style.css",
|
|
15
|
+
compose: ({ children }) => mark(String(children)),
|
|
16
|
+
setup: () => ({ client: "client.js" }),
|
|
17
|
+
docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export { lightbox as default, mark };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
const e=e=>`<svg viewBox="0 0 16 16" width="18" height="18" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="${e}"/></svg>`,t=e(`M10 3.5 5.5 8l4.5 4.5`),n=e(`M6 3.5 10.5 8 6 12.5`),r=e(`M4 4l8 8M12 4l-8 8`),i=e=>[...e.querySelectorAll(`img, video`)].filter(e=>!e.closest(`a, .wb-window-bar, .wb-lightbox`));let a=null,o=[],s=0;function c(){if(!a)return;let e=o[s],t=a.querySelector(`.wb-lightbox-stage`),n;if(e instanceof HTMLVideoElement){let t=e.cloneNode(!0);t.controls=!0,t.removeAttribute(`autoplay`),n=t}else{let t=document.createElement(`img`);t.src=e.currentSrc||e.src,t.alt=e.alt,n=t}t.replaceChildren(n),a.querySelector(`.wb-lightbox-caption`).textContent=(e instanceof HTMLImageElement?e.alt:e.getAttribute(`aria-label`))??``;for(let e of a.querySelectorAll(`.wb-lightbox-prev, .wb-lightbox-next`))e.hidden=o.length<2}function l(e,l){o=i(e),s=Math.max(0,o.indexOf(l)),a?.remove(),a=document.createElement(`div`),a.className=`wb-lightbox`,a.setAttribute(`role`,`dialog`),a.setAttribute(`aria-modal`,`true`),a.innerHTML=`<div class="wb-lightbox-stage"></div><div class="wb-lightbox-caption"></div>
|
|
2
|
+
<button type="button" class="wb-lightbox-prev" aria-label="Previous">${t}</button>
|
|
3
|
+
<button type="button" class="wb-lightbox-next" aria-label="Next">${n}</button>
|
|
4
|
+
<button type="button" class="wb-lightbox-close" aria-label="Close">${r}</button>`,a.addEventListener(`click`,e=>{let t=e.target;t.closest(`.wb-lightbox-prev`)?u(-1):t.closest(`.wb-lightbox-next`)?u(1):(t.closest(`.wb-lightbox-close`)||t===a||t.matches(`.wb-lightbox-stage`))&&d()}),document.body.append(a),c()}function u(e){o.length<2||(s=(s+e+o.length)%o.length,c())}function d(){a?.remove(),a=null}let f=!1;const p=()=>{f||(f=!0,document.addEventListener(`click`,e=>{let t=e.target.closest?.(`img`),n=t?.closest(`[data-lightbox]`);t&&n&&!t.closest(`a, .wb-lightbox`)&&(e.preventDefault(),l(n,t))}),document.addEventListener(`keydown`,e=>{if(a){if(e.key===`Escape`)d();else if(e.key===`ArrowLeft`)u(-1);else if(e.key===`ArrowRight`)u(1);else return;e.preventDefault()}}))};export{p as default};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/* The lightbox (index.ts, client.ts): pictures in a container composed with it open on a click */
|
|
2
|
+
[data-lightbox] img:not(a img) {
|
|
3
|
+
cursor: zoom-in;
|
|
4
|
+
}
|
|
5
|
+
/* over the page: the picture or video as large as fits, its caption under it */
|
|
6
|
+
.wb-lightbox {
|
|
7
|
+
position: fixed;
|
|
8
|
+
inset: 0;
|
|
9
|
+
z-index: var(--layer-top);
|
|
10
|
+
background: rgb(0 0 0 / 0.86);
|
|
11
|
+
display: grid;
|
|
12
|
+
place-items: center;
|
|
13
|
+
grid-template-rows: 1fr auto;
|
|
14
|
+
padding: var(--space-3xl) var(--space-2xl);
|
|
15
|
+
}
|
|
16
|
+
.wb-lightbox-stage {
|
|
17
|
+
display: grid;
|
|
18
|
+
place-items: center;
|
|
19
|
+
min-height: 0;
|
|
20
|
+
width: 100%;
|
|
21
|
+
height: 100%;
|
|
22
|
+
}
|
|
23
|
+
.wb-lightbox-stage > :is(img, video) {
|
|
24
|
+
max-width: 100%;
|
|
25
|
+
max-height: calc(100vh - 110px);
|
|
26
|
+
object-fit: contain;
|
|
27
|
+
border-radius: var(--radius-sm);
|
|
28
|
+
}
|
|
29
|
+
.wb-lightbox-caption {
|
|
30
|
+
color: #eee;
|
|
31
|
+
text-align: center;
|
|
32
|
+
padding-top: var(--space-lg);
|
|
33
|
+
}
|
|
34
|
+
.wb-lightbox button {
|
|
35
|
+
position: absolute;
|
|
36
|
+
display: grid;
|
|
37
|
+
place-items: center;
|
|
38
|
+
background: rgb(255 255 255 / 0.12);
|
|
39
|
+
color: #fff;
|
|
40
|
+
border: 0;
|
|
41
|
+
width: 44px;
|
|
42
|
+
height: 44px;
|
|
43
|
+
border-radius: 50%;
|
|
44
|
+
padding: 0;
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
}
|
|
47
|
+
.wb-lightbox button:hover {
|
|
48
|
+
background: rgb(255 255 255 / 0.22);
|
|
49
|
+
}
|
|
50
|
+
.wb-lightbox-prev {
|
|
51
|
+
left: 12px;
|
|
52
|
+
top: 50%;
|
|
53
|
+
translate: 0 -50%;
|
|
54
|
+
}
|
|
55
|
+
.wb-lightbox-next {
|
|
56
|
+
right: 12px;
|
|
57
|
+
top: 50%;
|
|
58
|
+
translate: 0 -50%;
|
|
59
|
+
}
|
|
60
|
+
.wb-lightbox button[hidden] {
|
|
61
|
+
display: none;
|
|
62
|
+
}
|
|
63
|
+
.wb-lightbox-close {
|
|
64
|
+
right: 12px;
|
|
65
|
+
top: 12px;
|
|
66
|
+
}
|
|
@@ -2,14 +2,14 @@ One pane, one item at a time, with ‹ › between them: an A/B, the steps of a
|
|
|
2
2
|
procedure, versions of a design. It is a window, so ⤢ fills the browser
|
|
3
3
|
window with it (for going through steps, large).
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
A heading at the block's shallowest heading level starts an item, titled by
|
|
6
|
+
it, and so does a `---`, untitled. With up to four items, all titled, the header shows the
|
|
7
7
|
titles as tabs; else it counts (`2 / 5`) and each item shows its title.
|
|
8
8
|
|
|
9
9
|
The items are laid over each other, so the pane is as tall as the tallest
|
|
10
10
|
and flipping doesn't move the page. ← and → step when it has the focus (a
|
|
11
11
|
click in it) or fills the window. Which item shows stays when the page
|
|
12
|
-
updates.
|
|
12
|
+
updates, even when a step is added before it.
|
|
13
13
|
|
|
14
14
|
Attributes: `count` (count, never tabs), `wide`, `height`.
|
|
15
15
|
|
|
@@ -2,41 +2,6 @@ import { builtinPublic } from "../../src/package.js";
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import { definePlugin, html, raw, windowFrame } from "@bigmistqke/whiteboard";
|
|
4
4
|
// plugins/steps/index.ts
|
|
5
|
-
/**
|
|
6
|
-
* The items of a block: one per heading at its shallowest level (what comes before the first is an
|
|
7
|
-
* item of its own); without headings, `---` separates them; else it is one item.
|
|
8
|
-
*/
|
|
9
|
-
function split(children) {
|
|
10
|
-
const content = children.filter((n) => !(n.type === "text" && !n.value?.trim()));
|
|
11
|
-
const heads = content.filter((n) => n.type === "heading");
|
|
12
|
-
const parts = [];
|
|
13
|
-
if (heads.length) {
|
|
14
|
-
const depth = Math.min(...heads.map((h) => h.depth));
|
|
15
|
-
for (const n of content) if (n.type === "heading" && n.depth === depth) parts.push({
|
|
16
|
-
title: n.children ?? [],
|
|
17
|
-
body: []
|
|
18
|
-
});
|
|
19
|
-
else if (parts.length) parts.at(-1).body.push(n);
|
|
20
|
-
else parts.push({
|
|
21
|
-
title: null,
|
|
22
|
-
body: [n]
|
|
23
|
-
});
|
|
24
|
-
return parts;
|
|
25
|
-
}
|
|
26
|
-
let current = {
|
|
27
|
-
title: null,
|
|
28
|
-
body: []
|
|
29
|
-
};
|
|
30
|
-
for (const n of content) if (n.type === "thematicBreak") {
|
|
31
|
-
if (current.body.length) parts.push(current);
|
|
32
|
-
current = {
|
|
33
|
-
title: null,
|
|
34
|
-
body: []
|
|
35
|
-
};
|
|
36
|
-
} else current.body.push(n);
|
|
37
|
-
if (current.body.length || !parts.length) parts.push(current);
|
|
38
|
-
return parts;
|
|
39
|
-
}
|
|
40
5
|
/** A height in px (a bare number) or a CSS length; else none. */
|
|
41
6
|
const height = (value) => value && /^\d+(\.\d+)?$/.test(value) ? `${value}px` : value && /^\d+(\.\d+)?(px|em|rem|vh|svh|dvh)$/.test(value) ? value : void 0;
|
|
42
7
|
const svg = (d) => raw(`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`);
|
|
@@ -45,11 +10,7 @@ const NEXT = svg("M6 3.5 10.5 8 6 12.5");
|
|
|
45
10
|
/** With this many items or fewer, all titled, the header shows their titles as tabs. */
|
|
46
11
|
const TABS = 4;
|
|
47
12
|
async function render(ctx) {
|
|
48
|
-
const
|
|
49
|
-
const items = await Promise.all(parts.map(async (p) => ({
|
|
50
|
-
title: p.title ? await ctx.toHtml(p.title) : null,
|
|
51
|
-
html: await ctx.toHtml(p.body)
|
|
52
|
-
})));
|
|
13
|
+
const items = await ctx.items();
|
|
53
14
|
const tabs = !("count" in ctx.attrs) && items.length <= TABS && items.every((i) => i.title);
|
|
54
15
|
const n = items.length;
|
|
55
16
|
const marks = tabs ? items.map((item, i) => html`<button type="button" class="wb-steps-tab wb-steps-mark" data-steps="${String(i)}">
|
|
@@ -73,7 +34,7 @@ async function render(ctx) {
|
|
|
73
34
|
</button>
|
|
74
35
|
</span>`;
|
|
75
36
|
const body = html`<div class="wb-steps" tabindex="0">
|
|
76
|
-
${items.map((item) => html`<section class="wb-steps-item">
|
|
37
|
+
${items.map((item) => html`<section class="wb-steps-item" data-key="${item.key}">
|
|
77
38
|
${!tabs && item.title ? html`<div class="wb-steps-title">${raw(item.title)}</div>` : ""} ${raw(item.html)}
|
|
78
39
|
</section>`)}
|
|
79
40
|
</div>`;
|
|
@@ -96,4 +57,4 @@ function steps() {
|
|
|
96
57
|
docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
|
|
97
58
|
});
|
|
98
59
|
}
|
|
99
|
-
export { steps as default, render
|
|
60
|
+
export { steps as default, render };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=()=>[...document.querySelectorAll(`#wb-main .wb-steps-window`)],t=e=>[...e.querySelectorAll(`:scope > .wb-window-body > .wb-steps > .wb-steps-item`)],n=e=>[...e.querySelectorAll(`:scope > .wb-window-bar .wb-steps-mark`)],r=/* @__PURE__ */ new Map;function i(e,i,a){let o=t(e),s=Math.max(o.length,1);a=Math.min(Math.max(a,0),s-1),r.set(i,a),e.setAttribute(`data-wb-step`,String(a)),o.forEach((e,t)=>e.toggleAttribute(`data-wb-current`,t===a)),n(e).forEach((e,t)=>e.toggleAttribute(`data-wb-current`,t===a)),e.toggleAttribute(`data-wb-first`,a===0),e.toggleAttribute(`data-wb-last`,a===s-1)}const
|
|
1
|
+
const e=()=>[...document.querySelectorAll(`#wb-main .wb-steps-window`)],t=e=>[...e.querySelectorAll(`:scope > .wb-window-body > .wb-steps > .wb-steps-item`)],n=e=>[...e.querySelectorAll(`:scope > .wb-window-bar .wb-steps-mark`)],r=/* @__PURE__ */ new Map;function i(e,n){let i=r.get(n);if(!i)return 0;let a=i.key?t(e).findIndex(e=>e.dataset.key===i.key):-1;return a>=0?a:i.index}function a(e,i,a){let o=t(e),s=Math.max(o.length,1);a=Math.min(Math.max(a,0),s-1),r.set(i,{key:o[a]?.dataset.key??null,index:a}),e.setAttribute(`data-wb-step`,String(a)),o.forEach((e,t)=>e.toggleAttribute(`data-wb-current`,t===a)),n(e).forEach((e,t)=>e.toggleAttribute(`data-wb-current`,t===a)),e.toggleAttribute(`data-wb-first`,a===0),e.toggleAttribute(`data-wb-last`,a===s-1)}const o=()=>e().forEach((e,t)=>a(e,t,i(e,t)));function s(t,n){let r=e().indexOf(t);if(r<0)return;let o=i(t,r);a(t,r,n===`prev`?o-1:n===`next`?o+1:n)}const c=e=>!!e?.closest?.(`input, textarea, select, [contenteditable]:not([contenteditable="false"])`);let l=!1;const u=(e,t,n)=>{o(),n.onRendered(o),l||(l=!0,document.addEventListener(`click`,e=>{let t=e.target.closest?.(`[data-steps]`),n=t?.closest(`.wb-steps-window`);if(!t||!n)return;let r=t.dataset.steps;s(n,r===`prev`||r===`next`?r:Number(r))}),document.addEventListener(`keydown`,e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`||e.metaKey||e.ctrlKey||e.altKey)return;let t=e.target;if(c(t))return;let n=t.closest?.(`.wb-steps-window`)??document.querySelector(`#wb-main .wb-steps-window[data-wb-maximized]`);n&&(e.preventDefault(),s(n,e.key===`ArrowLeft`?`prev`:`next`))}))};export{u as default};
|
|
@@ -3,9 +3,9 @@ import { handOver, lastUsed, leave, report } from "./sizes.js";
|
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import net from "node:net";
|
|
7
6
|
import xtermHeadless from "@xterm/headless";
|
|
8
7
|
import xtermSerialize from "@xterm/addon-serialize";
|
|
8
|
+
import net from "node:net";
|
|
9
9
|
// plugins/terminal/host.ts
|
|
10
10
|
const require = createRequire(import.meta.url);
|
|
11
11
|
const [dir, socket] = process.argv.slice(2);
|
|
@@ -38,4 +38,4 @@ WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){t
|
|
|
38
38
|
* http://bellard.org/jslinux/
|
|
39
39
|
* Copyright (c) 2011 Fabrice Bellard
|
|
40
40
|
*/
|
|
41
|
-
this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),a=window.getComputedStyle(this._terminal.element),o={top:parseInt(a.getPropertyValue(`padding-top`)),bottom:parseInt(a.getPropertyValue(`padding-bottom`)),right:parseInt(a.getPropertyValue(`padding-right`)),left:parseInt(a.getPropertyValue(`padding-left`))},s=o.top+o.bottom,c=o.right+o.left,l=r-s,u=i-c-t;return{cols:Math.max(ns,Math.floor(u/e.css.cell.width)),rows:Math.max(rs,Math.floor(l/e.css.cell.height))}}};const as={get:e=>{try{return sessionStorage.getItem(e)}catch{return null}},set:(e,t)=>{try{sessionStorage.setItem(e,t)}catch{}}};function
|
|
41
|
+
this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),a=window.getComputedStyle(this._terminal.element),o={top:parseInt(a.getPropertyValue(`padding-top`)),bottom:parseInt(a.getPropertyValue(`padding-bottom`)),right:parseInt(a.getPropertyValue(`padding-right`)),left:parseInt(a.getPropertyValue(`padding-left`))},s=o.top+o.bottom,c=o.right+o.left,l=r-s,u=i-c-t;return{cols:Math.max(ns,Math.floor(u/e.css.cell.width)),rows:Math.max(rs,Math.floor(l/e.css.cell.height))}}};const as={get:e=>{try{return sessionStorage.getItem(e)}catch{return null}},set:(e,t)=>{try{sessionStorage.setItem(e,t)}catch{}}},os=(()=>{try{return JSON.parse(document.getElementById(`wb-page`)?.textContent??`{}`).base??``}catch{return``}})();function ss(e){let t=e.querySelector(`.wb-term-screen`),n=e.querySelector(`.wb-term-tabs`),r=e.querySelector(`.wb-term-status`),i=e.querySelector(`.wb-term-actions`),a=e.querySelector(`.wb-term-toggle`),o=e.querySelector(`.wb-term-grip`),s=[];try{({sessions:s}=JSON.parse(e.dataset.sessions??`{}`)),s??=[]}catch{}let c=e.dataset.tab??s[0]?.id??null,l=new ts({fontFamily:`ui-monospace, SFMono-Regular, Menlo, monospace`,fontSize:13,cursorBlink:!0,scrollback:5e3,scrollSensitivity:3,allowProposedApi:!0,theme:{background:`#0f1115`,foreground:`#d7dae0`,cursor:`#d7dae0`,selectionBackground:`#3a4150`}}),u=new is;l.loadAddon(u),l.open(t);let d=()=>e.dataset.state===`open`;if(new URLSearchParams(location.search).get(`terminal`)===`open`){as.set(`wb-terminal-open`,`1`);let e=new URL(location.href);e.searchParams.delete(`terminal`),history.replaceState(history.state,``,e)}let f=crypto.randomUUID(),p=null,m=null,h=as.get(`wb-terminal-active`)===`1`,g=``,_=()=>p===f;function ee(){if(!d()||!c)return;let e=u.proposeDimensions();if(!e?.cols||!e?.rows)return;let t=`${c} ${e.cols}x${e.rows} ${h}`;t!==g&&(g=t,cs(os+`/api/terminal/resize`,{id:c,viewer:f,cols:e.cols,rows:e.rows,active:h}),h&&=(p=f,!1)),te()}function te(){let e=u.proposeDimensions(),t=_()||!m?e:m;t?.cols&&t?.rows&&(t.cols!==l.cols||t.rows!==l.rows)&&l.resize(t.cols,t.rows)}function ne(){!_()&&c&&(h=!0,ee())}new ResizeObserver(()=>ee()).observe(t),l.textarea?.addEventListener(`focus`,ne);function re(t){let n=()=>{e.dataset.state=t?`open`:`collapsed`,as.set(`wb-terminal-open`,t?`1`:`0`)},r=document.startViewTransition;r&&!matchMedia(`(prefers-reduced-motion: reduce)`).matches?r.call(document,n):n(),requestAnimationFrame(()=>{t&&ne(),ee(),t&&l.focus()})}a.addEventListener(`click`,()=>re(!d())),addEventListener(`keydown`,e=>{e.ctrlKey&&e.key==="`"&&(e.preventDefault(),re(!d()))}),o.addEventListener(`pointerdown`,t=>{t.preventDefault(),o.setPointerCapture(t.pointerId),d()||re(!0);let n=e.querySelector(`.wb-term-bar`).offsetHeight,r=e=>{let t=Math.max(120,Math.min(innerHeight-80,innerHeight-e.clientY-n));document.documentElement.style.setProperty(`--wb-term-h`,`${Math.round(t)}px`)},i=()=>{o.removeEventListener(`pointermove`,r),o.removeEventListener(`pointerup`,i);let e=getComputedStyle(document.documentElement).getPropertyValue(`--wb-term-h`);as.set(`wb-terminal-height`,String(parseInt(e)||``)),ee()};o.addEventListener(`pointermove`,r),o.addEventListener(`pointerup`,i)});let ie=``,ae=Promise.resolve();l.onData(e=>{if(!c)return;ne();let t=c;ie||queueMicrotask(()=>{let e=ie;ie=``,ae=ae.then(()=>cs(os+`/api/terminal/input`,{id:t,data:e})).then(()=>{},()=>{})}),ie+=e});function v(e,t=[]){r.textContent=e,i.replaceChildren(...t.map(([e,t])=>{let n=document.createElement(`button`);return n.type=`button`,n.textContent=e,n.addEventListener(`click`,t),n}))}function oe(){n.replaceChildren(...s.map(e=>{let t=document.createElement(`span`);t.className=`wb-term-tab`,t.dataset.id=e.id,t.classList.toggle(`wb-current`,e.id===c),t.toggleAttribute(`data-exited`,!e.running);let n=document.createElement(`button`);n.type=`button`,n.className=`wb-term-tab-name`,n.textContent=e.label,n.title=e.running?e.label:`${e.label}: exited (${e.exited})`,n.addEventListener(`click`,()=>ce(e.id)),t.append(n);let r=document.createElement(`button`);return r.type=`button`,r.className=`wb-term-tab-close`,r.title=`Close this tab (ends its program)`,r.textContent=`×`,r.addEventListener(`click`,()=>b(e.id)),t.append(r),t})),se()}let y=document.createElement(`button`);y.type=`button`,y.className=`wb-term-add`,y.title=`A new tab with a shell`,y.textContent=`+`,y.addEventListener(`click`,()=>le({})),n.after(y);function se(){let e=s.find(e=>e.id===c);if(!e||e.running)return v(``,[]);v(e.exited==null?`stopped`:`exited (${e.exited})`,[[`Start again`,()=>le({id:e.id,restart:!0})]])}function ce(e){e===c&&S||(c=e,e&&as.set(`wb-terminal-tab`,e),oe(),C()),d()&&l.focus()}async function b(e){await cs(os+`/api/terminal/close`,{id:e}),s=s.filter(t=>t.id!==e),c===e?ce(s.at(-1)?.id??null):oe()}async function le(e){v(`starting…`);let t=await cs(os+`/api/terminal/start`,e),n=await t.json().catch(()=>({}));if(!t.ok)return v(n.error??`could not start`,[[`Try again`,()=>le(e)]]);await x(),d()||re(!0),ce(n.session),l.focus()}async function x(){try{let e=await fetch(os+`/api/terminal/sessions`);e.ok&&({sessions:s}=await e.json())}catch{}oe()}let S=null;function C(){S?.close(),l.reset(),g=``,c||se(),S=new EventSource(`${os}/api/terminal/stream?${c?`id=${encodeURIComponent(c)}&`:``}viewer=${f}`),S.addEventListener(`sessions`,e=>{if(s=JSON.parse(e.data).sessions,c?!s.some(e=>e.id===c):s.length)return ce(s.at(-1)?.id??null);oe()}),S.addEventListener(`none`,()=>{l.reset(),t.querySelectorAll(`.wb-term-placeholder`).forEach(e=>e.remove()),se()}),S.addEventListener(`screen`,e=>{let{d:n,cols:r,rows:i,active:a}=JSON.parse(e.data);l.reset(),m=r&&i?{cols:r,rows:i}:null,p=a??null,m&&l.resize(m.cols,m.rows),l.write(n,()=>{ee(),t.querySelectorAll(`.wb-term-placeholder`).forEach(e=>e.remove())}),se(),d()&&as.get(`wb-terminal-focus`)===`1`&&l.focus()}),S.addEventListener(`data`,e=>l.write(JSON.parse(e.data).d)),S.addEventListener(`navigate`,e=>{let{path:t}=JSON.parse(e.data);typeof t==`string`&&t.startsWith(`/`)&&!t.startsWith(`//`)&&location.assign(os+t)}),S.addEventListener(`size`,e=>{let{cols:t,rows:n,active:r}=JSON.parse(e.data);m={cols:t,rows:n},p=r??null,as.set(`wb-terminal-active`,_()?`1`:`0`),te()}),S.addEventListener(`exit`,e=>{let t=JSON.parse(e.data).code,n=s.find(e=>e.id===c);n&&(n.running=!1,n.exited=t),oe()})}addEventListener(`pagehide`,()=>as.set(`wb-terminal-focus`,e.contains(document.activeElement)?`1`:`0`)),oe(),C()}function cs(e,t){return fetch(e,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)})}const ls=document.getElementById(`wb-terminal`);ls&&ss(ls);
|