@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.
Files changed (128) hide show
  1. package/README.md +177 -26
  2. package/bin/whiteboard.ts +331 -16
  3. package/dist/bin/whiteboard.js +268 -17
  4. package/dist/client/runtime.js +66 -23
  5. package/dist/plugins/ansi/README.md +36 -0
  6. package/dist/plugins/ansi/index.js +64 -0
  7. package/dist/plugins/ansi/public/style.css +28 -0
  8. package/dist/plugins/badge/README.md +28 -0
  9. package/dist/plugins/badge/index.js +24 -0
  10. package/dist/plugins/badge/public/style.css +30 -0
  11. package/dist/plugins/chat/public/style.css +7 -2
  12. package/dist/plugins/code/README.md +4 -2
  13. package/dist/plugins/code/diff.js +12 -2
  14. package/dist/plugins/draft/README.md +14 -0
  15. package/dist/plugins/draft/index.js +21 -0
  16. package/dist/plugins/draft/public/style.css +21 -0
  17. package/dist/plugins/grid/README.md +12 -12
  18. package/dist/plugins/grid/index.js +7 -19
  19. package/dist/plugins/grid/public/style.css +4 -33
  20. package/dist/plugins/iframe/README.md +7 -7
  21. package/dist/plugins/iframe/index.js +11 -11
  22. package/dist/plugins/iframe/public/style.css +15 -0
  23. package/dist/plugins/index.js +11 -3
  24. package/dist/plugins/lightbox/README.md +22 -0
  25. package/dist/plugins/lightbox/index.js +20 -0
  26. package/dist/plugins/lightbox/public/client.js +4 -0
  27. package/dist/plugins/lightbox/public/style.css +66 -0
  28. package/dist/plugins/steps/README.md +42 -0
  29. package/dist/plugins/steps/index.js +60 -0
  30. package/dist/plugins/steps/public/client.js +1 -0
  31. package/dist/plugins/steps/public/style.css +77 -0
  32. package/dist/plugins/terminal/host.js +9 -3
  33. package/dist/plugins/terminal/public/client.js +1 -1
  34. package/dist/plugins/terminal/sizes.js +2 -1
  35. package/dist/plugins/toc/README.md +21 -3
  36. package/dist/plugins/toc/index.js +8 -2
  37. package/dist/plugins/toc/public/client.js +1 -1
  38. package/dist/plugins/toc/public/style.css +10 -4
  39. package/dist/plugins/window/README.md +34 -14
  40. package/dist/plugins/window/index.js +21 -13
  41. package/dist/src/auth.js +6 -4
  42. package/dist/src/client/page/base.css +61 -1
  43. package/dist/src/client/page/main.js +74 -20
  44. package/dist/src/entries.js +211 -0
  45. package/dist/src/events.js +1 -1
  46. package/dist/src/hub.js +272 -0
  47. package/dist/src/loader.js +12 -3
  48. package/dist/src/package.js +23 -1
  49. package/dist/src/pages/blocks.js +1 -0
  50. package/dist/src/pages/index.js +1 -1
  51. package/dist/src/pages/markdown.js +87 -33
  52. package/dist/src/pages/render.js +157 -28
  53. package/dist/src/pages/window.js +17 -18
  54. package/dist/src/running.js +37 -2
  55. package/dist/src/serve.js +111 -2
  56. package/dist/src/server.js +264 -23
  57. package/package.json +3 -2
  58. package/plugins/ansi/README.md +36 -0
  59. package/plugins/ansi/index.ts +95 -0
  60. package/plugins/ansi/public/style.css +28 -0
  61. package/plugins/badge/README.md +28 -0
  62. package/plugins/badge/index.ts +35 -0
  63. package/plugins/badge/public/style.css +30 -0
  64. package/plugins/chat/public/style.css +7 -2
  65. package/plugins/code/README.md +4 -2
  66. package/plugins/code/diff.ts +14 -2
  67. package/plugins/code/index.ts +3 -1
  68. package/plugins/draft/README.md +14 -0
  69. package/plugins/draft/index.ts +23 -0
  70. package/plugins/draft/public/style.css +21 -0
  71. package/plugins/grid/README.md +12 -12
  72. package/plugins/grid/index.ts +11 -26
  73. package/plugins/grid/public/style.css +4 -33
  74. package/plugins/iframe/README.md +7 -7
  75. package/plugins/iframe/index.ts +15 -15
  76. package/plugins/iframe/public/style.css +15 -0
  77. package/plugins/index.ts +10 -2
  78. package/plugins/lightbox/README.md +22 -0
  79. package/plugins/lightbox/client.ts +99 -0
  80. package/plugins/lightbox/index.ts +25 -0
  81. package/plugins/lightbox/public/style.css +66 -0
  82. package/plugins/mermaid/index.ts +4 -2
  83. package/plugins/steps/README.md +42 -0
  84. package/plugins/steps/client.ts +75 -0
  85. package/plugins/steps/index.ts +84 -0
  86. package/plugins/steps/public/style.css +77 -0
  87. package/plugins/terminal/client.ts +16 -7
  88. package/plugins/terminal/host.ts +12 -6
  89. package/plugins/terminal/sizes.ts +3 -1
  90. package/plugins/toc/README.md +21 -3
  91. package/plugins/toc/client.ts +47 -6
  92. package/plugins/toc/index.ts +19 -6
  93. package/plugins/toc/public/style.css +10 -4
  94. package/plugins/window/README.md +34 -14
  95. package/plugins/window/index.ts +20 -13
  96. package/skills/whiteboard/SKILL.md +18 -10
  97. package/src/auth.ts +8 -5
  98. package/src/client/base.ts +19 -0
  99. package/src/client/forms.ts +2 -1
  100. package/src/client/markdown.ts +2 -1
  101. package/src/client/page/base.css +61 -1
  102. package/src/client/page/elsewhere.ts +72 -16
  103. package/src/client/page/fresh.ts +2 -1
  104. package/src/client/page/main.ts +18 -6
  105. package/src/client/page/sort.ts +2 -1
  106. package/src/client/runtime.ts +62 -25
  107. package/src/define.ts +126 -19
  108. package/src/entries.ts +258 -0
  109. package/src/events.ts +2 -1
  110. package/src/hub.ts +355 -0
  111. package/src/loader.ts +14 -3
  112. package/src/package.ts +22 -0
  113. package/src/pages/blocks.ts +3 -0
  114. package/src/pages/index.ts +6 -4
  115. package/src/pages/markdown.ts +89 -32
  116. package/src/pages/render.ts +181 -28
  117. package/src/pages/window.ts +23 -25
  118. package/src/running.ts +47 -1
  119. package/src/serve.ts +114 -1
  120. package/src/server.ts +332 -26
  121. package/dist/plugins/gallery/README.md +0 -30
  122. package/dist/plugins/gallery/index.js +0 -75
  123. package/dist/plugins/gallery/public/client.js +0 -1
  124. package/dist/plugins/gallery/public/style.css +0 -90
  125. package/plugins/gallery/README.md +0 -30
  126. package/plugins/gallery/client.tsx +0 -70
  127. package/plugins/gallery/index.ts +0 -89
  128. 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
- overflow-x: auto;
62
- max-width: 100%;
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. Use four
21
- backticks around it, since a diff can hold three.
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.
@@ -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 (!/^(@@ -\d|diff --git )/m.test(text)) {
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
  }
@@ -17,6 +17,7 @@ import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
17
17
  // of the text) and where it is (`data-wb-at="file:line"`), which comments on the line record.
18
18
  // shiki loads the first time a page has code, not with the plugin: the command line loads the
19
19
  // built-in plugins too, for their declarations
20
+ import type * as Shiki from 'shiki'
20
21
  import type { BundledTheme, Highlighter } from 'shiki'
21
22
  import type { FenceContext } from '@bigmistqke/whiteboard'
22
23
  import { diffLines } from './diff.ts'
@@ -41,7 +42,8 @@ export default function code(options: Options = {}): Plugin {
41
42
  const themes = options.themes ?? DEFAULT_THEMES
42
43
  const colorReplacements = options.colorReplacements ?? (options.themes ? {} : DEFAULT_REPLACEMENTS)
43
44
  let highlighter: Promise<Highlighter> | undefined
44
- let shiki: typeof import('shiki') | undefined
45
+ // loaded the first time a page has code, not with the plugin: the command line loads plugins too
46
+ let shiki: typeof Shiki | undefined
45
47
  const loaded = new Set<string>()
46
48
 
47
49
  /** Highlight `code` as `lang`; an unknown or missing language renders as plain text. */
@@ -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,23 @@
1
+ // Draft: what is there while a page is written, and not once it is built (`whiteboard build` leaves
2
+ // it out by default): a note to check something, two versions of a paragraph, a question for later.
3
+ import fs from 'node:fs'
4
+ import { definePlugin, html, raw, type DirectiveContext, type Plugin } from '@bigmistqke/whiteboard'
5
+ import { builtinPublic } from '../../src/package.ts'
6
+
7
+ export async function render(ctx: DirectiveContext) {
8
+ const label = ctx.label != null && String(ctx.label) !== '' ? ctx.label : 'draft'
9
+ return html`<aside class="wb-draft">
10
+ <div class="wb-draft-label">${raw(String(label))}</div>
11
+ ${raw(await ctx.toHtml(ctx.children))}
12
+ </aside>`
13
+ }
14
+
15
+ export default function draft(): Plugin {
16
+ return definePlugin({
17
+ name: 'draft',
18
+ public: builtinPublic('draft'),
19
+ style: 'style.css',
20
+ blocks: { draft: { html: render } },
21
+ docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
22
+ })
23
+ }
@@ -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. Each heading at the shallowest level inside the
2
- block starts a card; everything under it is the card body (any markdown,
3
- including other blocks). Without headings, each paragraph is a card.
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 `{word}` gets a badge. `done ok yes good` are green,
6
- `active new info` blue, `open todo maybe warning` amber,
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 {done}
13
+ ### Parser :badge[done]
14
14
  remark + remark-directive.
15
15
 
16
- ### Islands {active}
16
+ ### Islands :badge[active]
17
17
  Solid components mounted per block.
18
18
 
19
- ### Docs {todo}
19
+ ### Docs :badge[todo]
20
20
  Live examples on `/_/docs`.
21
21
  :::
22
22
  ```
23
23
 
24
24
  :::grid{cols=3}
25
- ### Parser {done}
25
+ ### Parser :badge[done]
26
26
  remark + remark-directive.
27
27
 
28
- ### Islands {active}
28
+ ### Islands :badge[active]
29
29
  Solid components mounted per block.
30
30
 
31
- ### Docs {todo}
31
+ ### Docs :badge[todo]
32
32
  Live examples on `/_/docs`.
33
33
  :::
@@ -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
- const slug = (s: string) =>
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 { intro, sections } = await ctx.sections()
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
- const cards = sections.map(s => {
19
- let title = s.title
20
- let badge: string | null = null
21
- const m = title ? /^(.*?)\s*\{([^}]+)\}\s*$/s.exec(title) : null
22
- if (m) {
23
- title = m[1]
24
- badge = m[2].trim()
25
- }
26
- // a section's title and html are HTML already; the badge is text from the heading
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: a coloured dot and a word, not a pill */
43
- .wb-badge {
44
- --c: var(--muted);
45
- flex: none;
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. A header like a browser window's
3
- shows its label (or, without one, its address), opens it on its own, and fills the window with
4
- it (the same button, or Esc, puts it back). Drag the frame's bottom edge to
5
- make it taller.
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), `bare` (no
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,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 window (src/pages/window.ts): a
3
- // header with its label or address, open on its own, fill the window; the frame can be made taller
4
- // by dragging its bottom edge.
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, windowFrame, type DirectiveContext } from '@bigmistqke/whiteboard'
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
- // in a window (the page's: its label, or the address; open on its own; fill the window), its
27
- // body the frame, which the reader can drag taller
28
- return windowFrame({
29
- label: ctx.label,
30
- open: src,
31
- wide: 'wide' in ctx.attrs,
32
- bare: 'bare' in ctx.attrs,
33
- bodyClass: 'wb-iframe-frame',
34
- height: height(ctx.attrs.height),
35
- body: html`<iframe src="${src}" title="${title}" loading="lazy" referrerpolicy="no-referrer"></iframe>`,
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,12 +10,16 @@ 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'
17
16
  import quiet from './quiet/index.ts'
18
17
  import windows from './window/index.ts'
18
+ import steps from './steps/index.ts'
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'
19
23
 
20
24
  export function builtins(): Plugin[] {
21
25
  return [
@@ -26,11 +30,15 @@ export function builtins(): Plugin[] {
26
30
  details(),
27
31
  forge(),
28
32
  form(),
29
- gallery(),
30
33
  grid(),
31
34
  iframe(),
32
35
  mermaid(),
33
36
  quiet(),
34
37
  windows(),
38
+ steps(),
39
+ draft(),
40
+ lightbox(),
41
+ badge(),
42
+ ansi(),
35
43
  ]
36
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).
@@ -0,0 +1,99 @@
1
+ // The lightbox in the browser (index.ts): a click on a picture inside a container marked
2
+ // `data-lightbox` opens it large, over the page, with the container's other pictures and videos to
3
+ // step through (‹ ›, ← →); Esc or a click beside it closes it. It lives outside the page's content,
4
+ // so the page's updates leave it as it is.
5
+ import type { PluginMount } from '../../src/define'
6
+
7
+ const icon = (d: string) =>
8
+ `<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="${d}"/></svg>`
9
+ const PREV = icon('M10 3.5 5.5 8l4.5 4.5')
10
+ const NEXT = icon('M6 3.5 10.5 8 6 12.5')
11
+ const CLOSE = icon('M4 4l8 8M12 4l-8 8')
12
+
13
+ /** What the lightbox shows of a container: its pictures and videos, in order; not a picture that is a link. */
14
+ const mediaIn = (scope: Element) =>
15
+ [...scope.querySelectorAll<HTMLImageElement | HTMLVideoElement>('img, video')].filter(
16
+ m => !m.closest('a, .wb-window-bar, .wb-lightbox'),
17
+ )
18
+
19
+ let overlay: HTMLElement | null = null
20
+ let items: (HTMLImageElement | HTMLVideoElement)[] = []
21
+ let at = 0
22
+
23
+ function show() {
24
+ if (!overlay) return
25
+ const item = items[at]!
26
+ const stage = overlay.querySelector('.wb-lightbox-stage')!
27
+ let shown: HTMLElement
28
+ if (item instanceof HTMLVideoElement) {
29
+ const video = item.cloneNode(true) as HTMLVideoElement
30
+ video.controls = true
31
+ video.removeAttribute('autoplay')
32
+ shown = video
33
+ } else {
34
+ const img = document.createElement('img')
35
+ img.src = item.currentSrc || item.src
36
+ img.alt = item.alt
37
+ shown = img
38
+ }
39
+ stage.replaceChildren(shown)
40
+ overlay.querySelector('.wb-lightbox-caption')!.textContent =
41
+ (item instanceof HTMLImageElement ? item.alt : item.getAttribute('aria-label')) ?? ''
42
+ for (const button of overlay.querySelectorAll<HTMLElement>('.wb-lightbox-prev, .wb-lightbox-next'))
43
+ button.hidden = items.length < 2
44
+ }
45
+
46
+ function open(scope: Element, picture: HTMLImageElement) {
47
+ items = mediaIn(scope)
48
+ at = Math.max(0, items.indexOf(picture))
49
+ overlay?.remove()
50
+ overlay = document.createElement('div')
51
+ overlay.className = 'wb-lightbox'
52
+ overlay.setAttribute('role', 'dialog')
53
+ overlay.setAttribute('aria-modal', 'true')
54
+ overlay.innerHTML = `<div class="wb-lightbox-stage"></div><div class="wb-lightbox-caption"></div>
55
+ <button type="button" class="wb-lightbox-prev" aria-label="Previous">${PREV}</button>
56
+ <button type="button" class="wb-lightbox-next" aria-label="Next">${NEXT}</button>
57
+ <button type="button" class="wb-lightbox-close" aria-label="Close">${CLOSE}</button>`
58
+ overlay.addEventListener('click', e => {
59
+ const target = e.target as Element
60
+ if (target.closest('.wb-lightbox-prev')) step(-1)
61
+ else if (target.closest('.wb-lightbox-next')) step(1)
62
+ else if (target.closest('.wb-lightbox-close') || target === overlay || target.matches('.wb-lightbox-stage')) close()
63
+ })
64
+ document.body.append(overlay)
65
+ show()
66
+ }
67
+
68
+ function step(by: number) {
69
+ if (items.length < 2) return
70
+ at = (at + by + items.length) % items.length
71
+ show()
72
+ }
73
+
74
+ function close() {
75
+ overlay?.remove()
76
+ overlay = null
77
+ }
78
+
79
+ let listening = false
80
+ const mount: PluginMount = () => {
81
+ if (listening) return
82
+ listening = true
83
+ document.addEventListener('click', e => {
84
+ const picture = (e.target as Element).closest?.('img')
85
+ const scope = picture?.closest('[data-lightbox]')
86
+ if (!picture || !scope || picture.closest('a, .wb-lightbox')) return
87
+ e.preventDefault()
88
+ open(scope, picture)
89
+ })
90
+ document.addEventListener('keydown', e => {
91
+ if (!overlay) return
92
+ if (e.key === 'Escape') close()
93
+ else if (e.key === 'ArrowLeft') step(-1)
94
+ else if (e.key === 'ArrowRight') step(1)
95
+ else return
96
+ e.preventDefault()
97
+ })
98
+ }
99
+ export default mount
@@ -0,0 +1,25 @@
1
+ // The lightbox: composed around a container (`:::grid{compose=lightbox}`), it makes the pictures in
2
+ // it open large on a click, and ← → step through the container's pictures and videos. The pictures
3
+ // themselves know nothing of it: outside one, a picture is just a picture. It marks the container
4
+ // (its outer element gets `data-lightbox`) rather than wrapping it, so the page lays the container
5
+ // out as before (a wide grid stays wide); the browser module (client.ts) does the rest.
6
+ import fs from 'node:fs'
7
+ import { definePlugin, html, raw, type Plugin } from '@bigmistqke/whiteboard'
8
+ import { builtinPublic } from '../../src/package.ts'
9
+
10
+ /** The container's HTML with its outer element marked; around it, when it starts with no element. */
11
+ export function mark(children: string): string {
12
+ const marked = children.replace(/^(\s*<[a-zA-Z][\w-]*)(?=[\s>/])/, '$1 data-lightbox')
13
+ return marked !== children ? marked : String(html`<div data-lightbox>${raw(children)}</div>`)
14
+ }
15
+
16
+ export default function lightbox(): Plugin {
17
+ return definePlugin({
18
+ name: 'lightbox',
19
+ public: builtinPublic('lightbox'),
20
+ style: 'style.css',
21
+ compose: ({ children }) => mark(String(children)),
22
+ setup: () => ({ client: 'client.js' }),
23
+ docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
24
+ })
25
+ }