@bigmistqke/whiteboard 0.4.0 → 0.6.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 +177 -26
- package/bin/whiteboard.ts +331 -16
- package/dist/bin/whiteboard.js +268 -17
- package/dist/client/runtime.js +66 -23
- 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/draft/README.md +14 -0
- package/dist/plugins/draft/index.js +21 -0
- package/dist/plugins/draft/public/style.css +21 -0
- 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 +11 -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 +42 -0
- package/dist/plugins/steps/index.js +60 -0
- package/dist/plugins/steps/public/client.js +1 -0
- package/dist/plugins/steps/public/style.css +77 -0
- package/dist/plugins/terminal/host.js +9 -3
- package/dist/plugins/terminal/public/client.js +1 -1
- package/dist/plugins/terminal/sizes.js +2 -1
- package/dist/plugins/toc/README.md +21 -3
- package/dist/plugins/toc/index.js +8 -2
- package/dist/plugins/toc/public/client.js +1 -1
- package/dist/plugins/toc/public/style.css +10 -4
- package/dist/plugins/window/README.md +34 -14
- package/dist/plugins/window/index.js +21 -13
- package/dist/src/auth.js +6 -4
- package/dist/src/client/page/base.css +61 -1
- package/dist/src/client/page/main.js +74 -20
- package/dist/src/entries.js +211 -0
- package/dist/src/events.js +1 -1
- package/dist/src/hub.js +272 -0
- package/dist/src/loader.js +12 -3
- 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 +157 -28
- package/dist/src/pages/window.js +17 -18
- package/dist/src/running.js +37 -2
- package/dist/src/serve.js +111 -2
- package/dist/src/server.js +264 -23
- package/package.json +3 -2
- 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/code/index.ts +3 -1
- package/plugins/draft/README.md +14 -0
- package/plugins/draft/index.ts +23 -0
- package/plugins/draft/public/style.css +21 -0
- 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 +10 -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/mermaid/index.ts +4 -2
- package/plugins/steps/README.md +42 -0
- package/plugins/steps/client.ts +75 -0
- package/plugins/steps/index.ts +84 -0
- package/plugins/steps/public/style.css +77 -0
- package/plugins/terminal/client.ts +16 -7
- package/plugins/terminal/host.ts +12 -6
- package/plugins/terminal/sizes.ts +3 -1
- package/plugins/toc/README.md +21 -3
- package/plugins/toc/client.ts +47 -6
- package/plugins/toc/index.ts +19 -6
- package/plugins/toc/public/style.css +10 -4
- package/plugins/window/README.md +34 -14
- package/plugins/window/index.ts +20 -13
- package/skills/whiteboard/SKILL.md +18 -10
- package/src/auth.ts +8 -5
- 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/main.ts +18 -6
- package/src/client/page/sort.ts +2 -1
- package/src/client/runtime.ts +62 -25
- package/src/define.ts +126 -19
- package/src/entries.ts +258 -0
- package/src/events.ts +2 -1
- package/src/hub.ts +355 -0
- package/src/loader.ts +14 -3
- package/src/package.ts +22 -0
- package/src/pages/blocks.ts +3 -0
- package/src/pages/index.ts +6 -4
- package/src/pages/markdown.ts +89 -32
- package/src/pages/render.ts +181 -28
- package/src/pages/window.ts +23 -25
- package/src/running.ts +47 -1
- package/src/serve.ts +114 -1
- package/src/server.ts +332 -26
- 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,64 @@
|
|
|
1
|
+
import { builtinPublic } from "../../src/package.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { definePlugin, html, raw, windowFrame } from "@bigmistqke/whiteboard";
|
|
4
|
+
import xtermHeadless from "@xterm/headless";
|
|
5
|
+
import xtermSerialize from "@xterm/addon-serialize";
|
|
6
|
+
// plugins/ansi/index.ts
|
|
7
|
+
const { Terminal } = xtermHeadless;
|
|
8
|
+
const { SerializeAddon } = xtermSerialize;
|
|
9
|
+
/** The widest a line is laid out before it wraps, as a terminal would. */
|
|
10
|
+
const MAX_COLS = 240;
|
|
11
|
+
const ESC = "\x1B";
|
|
12
|
+
/**
|
|
13
|
+
* Escapes written out as text count as escapes: an agent writing a page often can't put the ESC
|
|
14
|
+
* byte itself in a file, so `\e[31m`, `\x1b[31m`, `\033[31m`, `\u001b[31m` and `^[[31m` are one.
|
|
15
|
+
*/
|
|
16
|
+
const unescape = (text) => text.replace(/\\e(?=\[)|\\x1b|\\033|\\u001b|\^\[(?=\[)/gi, ESC);
|
|
17
|
+
/** How wide a line shows: its characters, without its escape sequences. */
|
|
18
|
+
const shown = (line) => [...line.replace(/\x1b\[[0-?]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\x1b[@-_]/g, "").split("\r").at(-1)].length;
|
|
19
|
+
/**
|
|
20
|
+
* What the text shows in a terminal as wide as its widest line (up to MAX_COLS), as HTML rows: the
|
|
21
|
+
* serializer's spans, colours inline, text escaped; trailing blank space and blank rows left out.
|
|
22
|
+
*/
|
|
23
|
+
async function toHtml(text) {
|
|
24
|
+
const input = unescape(text).replace(/\r?\n$/, "");
|
|
25
|
+
const lines = input.split(/\r?\n/);
|
|
26
|
+
const cols = Math.min(MAX_COLS, Math.max(20, ...lines.map(shown)));
|
|
27
|
+
const term = new Terminal({
|
|
28
|
+
cols,
|
|
29
|
+
rows: Math.max(1, lines.length),
|
|
30
|
+
scrollback: 1e5,
|
|
31
|
+
allowProposedApi: true,
|
|
32
|
+
convertEol: true
|
|
33
|
+
});
|
|
34
|
+
const serializer = new SerializeAddon();
|
|
35
|
+
term.loadAddon(serializer);
|
|
36
|
+
await new Promise((resolve) => term.write(input, resolve));
|
|
37
|
+
const out = serializer.serializeAsHTML({ includeGlobalBackground: false });
|
|
38
|
+
term.dispose();
|
|
39
|
+
const rows = [...(/<pre><div style='[^']*'>([\s\S]*)<\/div><\/pre>/.exec(out)?.[1] ?? "").matchAll(/<div>([\s\S]*?)<\/div>/g)].map((m) => m[1].replace(/<span><\/span>/g, "").replace(/<span> +<\/span>$/, "").replace(/(<span>[^<]*?) +(<\/span>)$/, "$1$2"));
|
|
40
|
+
while (rows.length && !rows.at(-1).replace(/<[^>]+>/g, "").trim()) rows.pop();
|
|
41
|
+
return rows.map((r) => `<span class="wb-ansi-row">${r}</span>`).join("\n");
|
|
42
|
+
}
|
|
43
|
+
async function render(ctx) {
|
|
44
|
+
const body = html`<pre class="wb-ansi"><code>${raw(await toHtml(ctx.text))}</code></pre>`;
|
|
45
|
+
const title = ctx.attrs.title;
|
|
46
|
+
return title ? windowFrame({
|
|
47
|
+
body,
|
|
48
|
+
label: String(html`${title}`),
|
|
49
|
+
className: "wb-ansi-window"
|
|
50
|
+
}) : body;
|
|
51
|
+
}
|
|
52
|
+
function ansi() {
|
|
53
|
+
return definePlugin({
|
|
54
|
+
name: "ansi",
|
|
55
|
+
public: builtinPublic("ansi"),
|
|
56
|
+
blocks: { ansi: {
|
|
57
|
+
fence: true,
|
|
58
|
+
html: render,
|
|
59
|
+
style: "style.css"
|
|
60
|
+
} },
|
|
61
|
+
docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export { ansi as default, render, toHtml, unescape };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* Terminal output: dark as a terminal in either theme, since the colours in it are a terminal's
|
|
2
|
+
palette, written inline. Wide output scrolls sideways rather than wrapping. */
|
|
3
|
+
.wb-ansi {
|
|
4
|
+
margin: 1.6em 0;
|
|
5
|
+
padding: 12px 16px;
|
|
6
|
+
overflow-x: auto;
|
|
7
|
+
background: #0f1115;
|
|
8
|
+
color: #d7dae0;
|
|
9
|
+
border-radius: var(--radius, 6px);
|
|
10
|
+
font: 0.82rem/1.45 var(--mono, ui-monospace, SFMono-Regular, Menlo, monospace);
|
|
11
|
+
white-space: pre;
|
|
12
|
+
tab-size: 8;
|
|
13
|
+
}
|
|
14
|
+
.wb-ansi code {
|
|
15
|
+
font: inherit;
|
|
16
|
+
background: none;
|
|
17
|
+
padding: 0;
|
|
18
|
+
color: inherit;
|
|
19
|
+
}
|
|
20
|
+
/* in a window (title=, or compose=window) the terminal fills it, the frame its edge */
|
|
21
|
+
.wb-window-body:has(> .wb-ansi:only-child) {
|
|
22
|
+
padding: 0;
|
|
23
|
+
background: #0f1115;
|
|
24
|
+
}
|
|
25
|
+
.wb-window-body > .wb-ansi {
|
|
26
|
+
margin: 0;
|
|
27
|
+
border-radius: 0;
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
A status as a coloured dot and a word, inline wherever text goes: in a
|
|
2
|
+
heading, a table cell, a list item, a sentence. `done ok yes good` are
|
|
3
|
+
green, `active new info` blue, `open todo maybe warning` amber,
|
|
4
|
+
`blocked no bad error` red; any other word is grey.
|
|
5
|
+
|
|
6
|
+
```markdown
|
|
7
|
+
### Parser :badge[done]
|
|
8
|
+
|
|
9
|
+
| step | state |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| parse | :badge[done] |
|
|
12
|
+
| render | :badge[active] |
|
|
13
|
+
| docs | :badge[todo] |
|
|
14
|
+
|
|
15
|
+
The release is :badge[blocked] on review.
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
A grid card whose heading ends in a badge shows it at the card's right edge.
|
|
19
|
+
|
|
20
|
+
### Parser :badge[done]
|
|
21
|
+
|
|
22
|
+
| step | state |
|
|
23
|
+
| --- | --- |
|
|
24
|
+
| parse | :badge[done] |
|
|
25
|
+
| render | :badge[active] |
|
|
26
|
+
| docs | :badge[todo] |
|
|
27
|
+
|
|
28
|
+
The release is :badge[blocked] on review.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { builtinPublic } from "../../src/package.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { definePlugin, html, raw } from "@bigmistqke/whiteboard";
|
|
4
|
+
// plugins/badge/index.ts
|
|
5
|
+
/** The word a badge's colour is chosen by: its text, lowercased, runs of other characters a `-`. */
|
|
6
|
+
const tone = (s) => s.toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
7
|
+
/** `:badge[done]`: a coloured dot and a word, inline wherever text goes. */
|
|
8
|
+
function render(ctx) {
|
|
9
|
+
const text = ctx.labelText?.trim();
|
|
10
|
+
if (!text) return html``;
|
|
11
|
+
return html`<span class="wb-badge" data-badge="${tone(text)}">${raw(ctx.label ?? "")}</span>`;
|
|
12
|
+
}
|
|
13
|
+
function badge() {
|
|
14
|
+
return definePlugin({
|
|
15
|
+
name: "badge",
|
|
16
|
+
public: builtinPublic("badge"),
|
|
17
|
+
blocks: { badge: {
|
|
18
|
+
html: render,
|
|
19
|
+
style: "style.css"
|
|
20
|
+
} },
|
|
21
|
+
docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export { badge as default, render, tone };
|
|
@@ -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,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
What is there while a page is written, and not once it is built: a note to
|
|
2
|
+
check something, two versions of a paragraph, a question for later. It shows
|
|
3
|
+
set apart, marked as a draft; `whiteboard build` leaves it out (it is in the
|
|
4
|
+
build's `skip` by default). The label is optional.
|
|
5
|
+
|
|
6
|
+
```markdown
|
|
7
|
+
:::draft[Check with the API]
|
|
8
|
+
Is `wait` really the only way to get answers?
|
|
9
|
+
:::
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
:::draft[Check with the API]
|
|
13
|
+
Is `wait` really the only way to get answers?
|
|
14
|
+
:::
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { builtinPublic } from "../../src/package.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { definePlugin, html, raw } from "@bigmistqke/whiteboard";
|
|
4
|
+
// plugins/draft/index.ts
|
|
5
|
+
async function render(ctx) {
|
|
6
|
+
const label = ctx.label != null && String(ctx.label) !== "" ? ctx.label : "draft";
|
|
7
|
+
return html`<aside class="wb-draft">
|
|
8
|
+
<div class="wb-draft-label">${raw(String(label))}</div>
|
|
9
|
+
${raw(await ctx.toHtml(ctx.children))}
|
|
10
|
+
</aside>`;
|
|
11
|
+
}
|
|
12
|
+
function draft() {
|
|
13
|
+
return definePlugin({
|
|
14
|
+
name: "draft",
|
|
15
|
+
public: builtinPublic("draft"),
|
|
16
|
+
style: "style.css",
|
|
17
|
+
blocks: { draft: { html: render } },
|
|
18
|
+
docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export { draft as default, render };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* A draft (index.ts): set apart, plainly not final */
|
|
2
|
+
.wb-draft {
|
|
3
|
+
margin: calc(var(--rhythm) * 2) 0;
|
|
4
|
+
padding: var(--space-md) var(--space-xl) var(--space-xl);
|
|
5
|
+
border: var(--hairline) dashed color-mix(in srgb, var(--warn) var(--tint-strong), transparent);
|
|
6
|
+
border-radius: var(--radius);
|
|
7
|
+
background: color-mix(in srgb, var(--warn) var(--tint-faint), transparent);
|
|
8
|
+
}
|
|
9
|
+
.wb-draft-label {
|
|
10
|
+
font: var(--weight-strong) var(--ui-tiny) / var(--ui-line-height) var(--sans);
|
|
11
|
+
letter-spacing: var(--caps-spacing);
|
|
12
|
+
text-transform: uppercase;
|
|
13
|
+
color: var(--warn);
|
|
14
|
+
margin-bottom: var(--space-xs);
|
|
15
|
+
}
|
|
16
|
+
.wb-draft-label > * {
|
|
17
|
+
margin: 0;
|
|
18
|
+
}
|
|
19
|
+
.wb-draft > :last-child {
|
|
20
|
+
margin-bottom: 0;
|
|
21
|
+
}
|
|
@@ -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,12 +5,16 @@ 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";
|
|
12
11
|
import quiet from "./quiet/index.js";
|
|
13
12
|
import windows from "./window/index.js";
|
|
13
|
+
import steps from "./steps/index.js";
|
|
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";
|
|
14
18
|
// plugins/index.ts
|
|
15
19
|
function builtins() {
|
|
16
20
|
return [
|
|
@@ -21,12 +25,16 @@ function builtins() {
|
|
|
21
25
|
details(),
|
|
22
26
|
forge(),
|
|
23
27
|
formPlugin(),
|
|
24
|
-
gallery(),
|
|
25
28
|
grid(),
|
|
26
29
|
iframe(),
|
|
27
30
|
mermaid(),
|
|
28
31
|
quiet(),
|
|
29
|
-
windows()
|
|
32
|
+
windows(),
|
|
33
|
+
steps(),
|
|
34
|
+
draft(),
|
|
35
|
+
lightbox(),
|
|
36
|
+
badge(),
|
|
37
|
+
ansi()
|
|
30
38
|
];
|
|
31
39
|
}
|
|
32
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};
|