@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,95 @@
|
|
|
1
|
+
// Terminal output in a page: an `ansi` fence holds what a program printed, escape codes and all, and
|
|
2
|
+
// the page shows it as the terminal did. The text goes through a headless terminal (xterm's, the
|
|
3
|
+
// one the terminal plugin keeps its screens in), so what a terminal does with it is what shows:
|
|
4
|
+
// colours (16, 256 and true colour), bold, a progress line `\r` writes over, the cursor moving.
|
|
5
|
+
// Rendered on the server to plain HTML, so nothing runs on the page and a built site has it too.
|
|
6
|
+
import fs from 'node:fs'
|
|
7
|
+
import { definePlugin, html, raw, windowFrame, type FenceContext, type Plugin } from '@bigmistqke/whiteboard'
|
|
8
|
+
import xtermHeadless from '@xterm/headless'
|
|
9
|
+
import xtermSerialize from '@xterm/addon-serialize'
|
|
10
|
+
import { builtinPublic } from '../../src/package.ts'
|
|
11
|
+
|
|
12
|
+
// CommonJS packages: their exports are the default's
|
|
13
|
+
const { Terminal } = xtermHeadless
|
|
14
|
+
const { SerializeAddon } = xtermSerialize
|
|
15
|
+
|
|
16
|
+
/** The widest a line is laid out before it wraps, as a terminal would. */
|
|
17
|
+
const MAX_COLS = 240
|
|
18
|
+
const ESC = '\x1b'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Escapes written out as text count as escapes: an agent writing a page often can't put the ESC
|
|
22
|
+
* byte itself in a file, so `\e[31m`, `\x1b[31m`, `\033[31m`, `\u001b[31m` and `^[[31m` are one.
|
|
23
|
+
*/
|
|
24
|
+
export const unescape = (text: string): string => text.replace(/\\e(?=\[)|\\x1b|\\033|\\u001b|\^\[(?=\[)/gi, ESC)
|
|
25
|
+
|
|
26
|
+
/** How wide a line shows: its characters, without its escape sequences. */
|
|
27
|
+
const shown = (line: string) =>
|
|
28
|
+
[
|
|
29
|
+
...line
|
|
30
|
+
.replace(/\x1b\[[0-?]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\x1b[@-_]/g, '')
|
|
31
|
+
.split('\r')
|
|
32
|
+
.at(-1)!,
|
|
33
|
+
].length
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* What the text shows in a terminal as wide as its widest line (up to MAX_COLS), as HTML rows: the
|
|
37
|
+
* serializer's spans, colours inline, text escaped; trailing blank space and blank rows left out.
|
|
38
|
+
*/
|
|
39
|
+
export async function toHtml(text: string): Promise<string> {
|
|
40
|
+
const input = unescape(text).replace(/\r?\n$/, '')
|
|
41
|
+
const lines = input.split(/\r?\n/)
|
|
42
|
+
const cols = Math.min(MAX_COLS, Math.max(20, ...lines.map(shown)))
|
|
43
|
+
const term = new Terminal({
|
|
44
|
+
cols,
|
|
45
|
+
rows: Math.max(1, lines.length),
|
|
46
|
+
scrollback: 100_000,
|
|
47
|
+
allowProposedApi: true,
|
|
48
|
+
convertEol: true,
|
|
49
|
+
})
|
|
50
|
+
const serializer = new SerializeAddon()
|
|
51
|
+
term.loadAddon(serializer)
|
|
52
|
+
await new Promise<void>(resolve => term.write(input, resolve))
|
|
53
|
+
const out = serializer.serializeAsHTML({ includeGlobalBackground: false })
|
|
54
|
+
term.dispose()
|
|
55
|
+
// the rows, without the wrapper that sets the serializer's own colours and font
|
|
56
|
+
const body = /<pre><div style='[^']*'>([\s\S]*)<\/div><\/pre>/.exec(out)?.[1] ?? ''
|
|
57
|
+
const rows = [...body.matchAll(/<div>([\s\S]*?)<\/div>/g)].map(m =>
|
|
58
|
+
// a row's padding to the terminal's width is no part of the output
|
|
59
|
+
m[1]!
|
|
60
|
+
.replace(/<span><\/span>/g, '')
|
|
61
|
+
.replace(/<span> +<\/span>$/, '')
|
|
62
|
+
.replace(/(<span>[^<]*?) +(<\/span>)$/, '$1$2'),
|
|
63
|
+
)
|
|
64
|
+
while (
|
|
65
|
+
rows.length &&
|
|
66
|
+
!rows
|
|
67
|
+
.at(-1)!
|
|
68
|
+
.replace(/<[^>]+>/g, '')
|
|
69
|
+
.trim()
|
|
70
|
+
)
|
|
71
|
+
rows.pop()
|
|
72
|
+
return rows.map(r => `<span class="wb-ansi-row">${r}</span>`).join('\n')
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function render(ctx: FenceContext) {
|
|
76
|
+
const body = html`<pre class="wb-ansi"><code>${raw(await toHtml(ctx.text))}</code></pre>`
|
|
77
|
+
// a title makes it a terminal window with that label, as `compose=window` would
|
|
78
|
+
const title = ctx.attrs.title
|
|
79
|
+
return title ? windowFrame({ body, label: String(html`${title}`), className: 'wb-ansi-window' }) : body
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export default function ansi(): Plugin {
|
|
83
|
+
return definePlugin({
|
|
84
|
+
name: 'ansi',
|
|
85
|
+
public: builtinPublic('ansi'),
|
|
86
|
+
blocks: {
|
|
87
|
+
ansi: {
|
|
88
|
+
fence: true,
|
|
89
|
+
html: render,
|
|
90
|
+
style: 'style.css',
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
|
|
94
|
+
})
|
|
95
|
+
}
|
|
@@ -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,35 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
|
|
3
|
+
// Static block: no component, so no JavaScript on the page.
|
|
4
|
+
import { html, raw, type DirectiveContext } from '@bigmistqke/whiteboard'
|
|
5
|
+
import { builtinPublic } from '../../src/package.ts'
|
|
6
|
+
|
|
7
|
+
/** The word a badge's colour is chosen by: its text, lowercased, runs of other characters a `-`. */
|
|
8
|
+
export const tone = (s: string) =>
|
|
9
|
+
s
|
|
10
|
+
.toLowerCase()
|
|
11
|
+
.trim()
|
|
12
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
13
|
+
.replace(/^-|-$/g, '')
|
|
14
|
+
|
|
15
|
+
/** `:badge[done]`: a coloured dot and a word, inline wherever text goes. */
|
|
16
|
+
export function render(ctx: DirectiveContext) {
|
|
17
|
+
const text = ctx.labelText?.trim()
|
|
18
|
+
if (!text) return html``
|
|
19
|
+
// the label is HTML already; its plain text picks the colour
|
|
20
|
+
return html`<span class="wb-badge" data-badge="${tone(text)}">${raw(ctx.label ?? '')}</span>`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default function badge(): Plugin {
|
|
24
|
+
return definePlugin({
|
|
25
|
+
name: 'badge',
|
|
26
|
+
public: builtinPublic('badge'),
|
|
27
|
+
blocks: {
|
|
28
|
+
badge: {
|
|
29
|
+
html: render,
|
|
30
|
+
style: 'style.css',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
|
|
34
|
+
})
|
|
35
|
+
}
|
|
@@ -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;
|
package/plugins/code/README.md
CHANGED
|
@@ -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.
|
package/plugins/code/diff.ts
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
// `index`, `---`, modes), which the block leaves out. A line in a hunk has its number (`n`) and
|
|
4
4
|
// where it is (`at`: `file:line` in the new file; a removed line counts in the old one,
|
|
5
5
|
// `file (old):line`). Reads unified diffs, as `git diff` and `diff -u` print them, and snippets of
|
|
6
|
-
// only +, - and unchanged lines.
|
|
6
|
+
// only +, - and unchanged lines. An agent often writes a hunk's start as a bare `@@`, without the
|
|
7
|
+
// line numbers: that starts a hunk too, whose lines have no numbers, and a `---` line followed by a
|
|
8
|
+
// `+++` line names the file, with or without a `diff --git` above them.
|
|
7
9
|
|
|
8
10
|
export type DiffKind = 'add' | 'del' | 'context' | 'hunk' | 'file' | 'meta'
|
|
9
11
|
|
|
@@ -26,7 +28,7 @@ const unprefix = (p: string) =>
|
|
|
26
28
|
export function diffLines(text: string): DiffLineInfo[] {
|
|
27
29
|
// a snippet without hunks or file headers (only +, - and unchanged lines, as people paste them):
|
|
28
30
|
// every line is one of those, without numbers, as no header says where it is
|
|
29
|
-
if (!/^(
|
|
31
|
+
if (!/^(@@|diff --git )/m.test(text) && !/^--- .*\n\+\+\+ /m.test(text)) {
|
|
30
32
|
return text
|
|
31
33
|
.split('\n')
|
|
32
34
|
.map((line): DiffLineInfo => ({ kind: line[0] === '+' ? 'add' : line[0] === '-' ? 'del' : 'context' }))
|
|
@@ -35,6 +37,8 @@ export function diffLines(text: string): DiffLineInfo[] {
|
|
|
35
37
|
oldFile = '',
|
|
36
38
|
oldN = 0,
|
|
37
39
|
newN = 0,
|
|
40
|
+
// a hunk started by a bare @@ says no line numbers: its lines have none
|
|
41
|
+
numbered = false,
|
|
38
42
|
inHunk = false
|
|
39
43
|
let status = '',
|
|
40
44
|
renamedFrom = ''
|
|
@@ -44,13 +48,21 @@ export function diffLines(text: string): DiffLineInfo[] {
|
|
|
44
48
|
oldN = Number(at[1])
|
|
45
49
|
newN = Number(at[2])
|
|
46
50
|
inHunk = true
|
|
51
|
+
numbered = true
|
|
47
52
|
// only a mark that lines were skipped: the numbers are in the gutter, and the text git adds
|
|
48
53
|
// after them is a guess at the enclosing line, often just the one before
|
|
49
54
|
return { kind: 'hunk', label: '' }
|
|
50
55
|
}
|
|
56
|
+
// a bare @@ (or one whose numbers don't read): a hunk all the same, without numbers
|
|
57
|
+
if (line.startsWith('@@')) {
|
|
58
|
+
inHunk = true
|
|
59
|
+
numbered = false
|
|
60
|
+
return { kind: 'hunk', label: '' }
|
|
61
|
+
}
|
|
51
62
|
if (inHunk) {
|
|
52
63
|
const sign = line[0]
|
|
53
64
|
const where = (side: 'old' | 'new', n: number): DiffLineInfo | {} => {
|
|
65
|
+
if (!numbered) return {}
|
|
54
66
|
const name = side === 'old' ? oldFile || file : file || oldFile
|
|
55
67
|
return name ? { n, at: side === 'old' ? `${name} (old):${n}` : `${name}:${n}` } : { n }
|
|
56
68
|
}
|
package/plugins/grid/README.md
CHANGED
|
@@ -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
|
:::
|
package/plugins/grid/index.ts
CHANGED
|
@@ -4,35 +4,20 @@ import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
|
|
|
4
4
|
import { html, raw, type DirectiveContext } from '@bigmistqke/whiteboard'
|
|
5
5
|
import { builtinPublic } from '../../src/package.ts'
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
s
|
|
9
|
-
.toLowerCase()
|
|
10
|
-
.trim()
|
|
11
|
-
.replace(/[^a-z0-9]+/g, '-')
|
|
12
|
-
.replace(/^-|-$/g, '')
|
|
13
|
-
|
|
7
|
+
/** A card per item (DirectiveContext.items): a heading, or a `---`, starts one. */
|
|
14
8
|
export async function render(ctx: DirectiveContext) {
|
|
15
|
-
const
|
|
9
|
+
const items = await ctx.items()
|
|
16
10
|
const cols = Number(ctx.attrs.cols)
|
|
17
11
|
const style = cols ? html` style="--wb-grid-cols:${cols}"` : null
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const b = badge && html`<span class="wb-badge" data-badge="${slug(badge)}">${badge}</span>`
|
|
28
|
-
const head = (title || b) && html`<header>${title && html`<h3>${raw(title)}</h3>`}${b}</header>`
|
|
29
|
-
return html`<article class="wb-card" ${badge && html` data-badge="${slug(badge)}"`}>
|
|
30
|
-
${head}
|
|
31
|
-
<div class="wb-card-body">${raw(s.html)}</div>
|
|
32
|
-
</article>`
|
|
33
|
-
})
|
|
34
|
-
return html`${raw(intro)}
|
|
35
|
-
<div class="wb-grid${'narrow' in ctx.attrs ? '' : ' wb-wide'}" ${style}>${cards}</div>`
|
|
12
|
+
// a section's title and html are HTML already
|
|
13
|
+
const cards = items.map(
|
|
14
|
+
s =>
|
|
15
|
+
html`<article class="wb-card">
|
|
16
|
+
${s.title && html`<header><h3>${raw(s.title)}</h3></header>`}
|
|
17
|
+
<div class="wb-card-body">${raw(s.html)}</div>
|
|
18
|
+
</article>`,
|
|
19
|
+
)
|
|
20
|
+
return html`<div class="wb-grid${'narrow' in ctx.attrs ? '' : ' wb-wide'}" ${style}>${cards}</div>`
|
|
36
21
|
}
|
|
37
22
|
|
|
38
23
|
export default function grid(): Plugin {
|
|
@@ -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
|
}
|
package/plugins/iframe/README.md
CHANGED
|
@@ -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
|
package/plugins/iframe/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Another page inside this one: a URL (a dev server, a deployed site) or an HTML file next to the
|
|
2
|
-
// pages (`demo.html` in .whiteboard/pages/ is served as it is), in a
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// pages (`demo.html` in .whiteboard/pages/ is served as it is), in a frame that can be made taller
|
|
3
|
+
// by dragging its bottom edge. With `compose=window`, in a window (src/pages/window.ts): a header with its
|
|
4
|
+
// label, open on its own, fill the browser window.
|
|
5
5
|
import fs from 'node:fs'
|
|
6
6
|
import { builtinPublic } from '../../src/package.ts'
|
|
7
7
|
import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
|
|
8
|
-
import { html,
|
|
8
|
+
import { html, type DirectiveContext } from '@bigmistqke/whiteboard'
|
|
9
9
|
|
|
10
10
|
/** http(s), protocol-relative, or a path on this server; never `javascript:` or `data:`. */
|
|
11
11
|
export const safeSrc = (src: string) => /^(https?:)?\/\//i.test(src) || !/^[a-z][a-z0-9+.-]*:/i.test(src)
|
|
@@ -23,17 +23,16 @@ export async function render(ctx: DirectiveContext) {
|
|
|
23
23
|
if (!safeSrc(src))
|
|
24
24
|
return html`<pre class="wb-error">iframe: src must be an http(s) URL or a path, not ${src.split(':')[0]}:</pre>`
|
|
25
25
|
const title = ctx.labelText ?? ctx.attrs.title ?? src
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
})
|
|
26
|
+
// the frame, which the reader can drag taller
|
|
27
|
+
return html`<div class="wb-iframe-frame" style="height: ${height(ctx.attrs.height)}">
|
|
28
|
+
<iframe src="${src}" title="${title}" loading="lazy" referrerpolicy="no-referrer"></iframe>
|
|
29
|
+
</div>`
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** What it shows on its own, for the ↗ of a window around it: its address. */
|
|
33
|
+
export function open(ctx: DirectiveContext) {
|
|
34
|
+
const src = (ctx.attrs.src ?? '').trim()
|
|
35
|
+
return src && safeSrc(src) ? src : null
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
export default function iframe(): Plugin {
|
|
@@ -43,6 +42,7 @@ export default function iframe(): Plugin {
|
|
|
43
42
|
blocks: {
|
|
44
43
|
iframe: {
|
|
45
44
|
html: render,
|
|
45
|
+
open,
|
|
46
46
|
style: 'style.css',
|
|
47
47
|
},
|
|
48
48
|
},
|
|
@@ -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/plugins/index.ts
CHANGED
|
@@ -10,7 +10,6 @@ import comments from './comments/index.ts'
|
|
|
10
10
|
import details from './details/index.ts'
|
|
11
11
|
import forge from './forge/index.ts'
|
|
12
12
|
import form from './form/index.ts'
|
|
13
|
-
import gallery from './gallery/index.ts'
|
|
14
13
|
import grid from './grid/index.ts'
|
|
15
14
|
import iframe from './iframe/index.ts'
|
|
16
15
|
import mermaid from './mermaid/index.ts'
|
|
@@ -18,6 +17,9 @@ import quiet from './quiet/index.ts'
|
|
|
18
17
|
import windows from './window/index.ts'
|
|
19
18
|
import steps from './steps/index.ts'
|
|
20
19
|
import draft from './draft/index.ts'
|
|
20
|
+
import lightbox from './lightbox/index.ts'
|
|
21
|
+
import badge from './badge/index.ts'
|
|
22
|
+
import ansi from './ansi/index.ts'
|
|
21
23
|
|
|
22
24
|
export function builtins(): Plugin[] {
|
|
23
25
|
return [
|
|
@@ -28,7 +30,6 @@ export function builtins(): Plugin[] {
|
|
|
28
30
|
details(),
|
|
29
31
|
forge(),
|
|
30
32
|
form(),
|
|
31
|
-
gallery(),
|
|
32
33
|
grid(),
|
|
33
34
|
iframe(),
|
|
34
35
|
mermaid(),
|
|
@@ -36,5 +37,8 @@ export function builtins(): Plugin[] {
|
|
|
36
37
|
windows(),
|
|
37
38
|
steps(),
|
|
38
39
|
draft(),
|
|
40
|
+
lightbox(),
|
|
41
|
+
badge(),
|
|
42
|
+
ansi(),
|
|
39
43
|
]
|
|
40
44
|
}
|
|
@@ -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).
|