@bigmistqke/whiteboard 0.3.1 → 0.5.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 (174) hide show
  1. package/README.md +119 -18
  2. package/bin/whiteboard.ts +300 -71
  3. package/dist/bin/whiteboard.js +21 -0
  4. package/dist/client/runtime.js +132 -54
  5. package/dist/define.js +21 -2
  6. package/dist/plugins/callout/index.js +3 -1
  7. package/dist/plugins/callout/public/style.css +30 -0
  8. package/dist/plugins/chat/index.js +7 -4
  9. package/dist/plugins/chat/{client.js → public/client.js} +1 -1
  10. package/dist/plugins/chat/public/style.css +98 -0
  11. package/dist/plugins/code/index.js +3 -1
  12. package/dist/plugins/code/public/style.css +68 -0
  13. package/dist/plugins/comments/index.js +4 -5
  14. package/dist/plugins/comments/public/client.js +19 -0
  15. package/dist/plugins/comments/public/style.css +185 -0
  16. package/dist/plugins/details/index.js +7 -2
  17. package/dist/plugins/details/public/style.css +7 -0
  18. package/dist/plugins/draft/README.md +14 -0
  19. package/dist/plugins/draft/index.js +21 -0
  20. package/dist/plugins/draft/public/style.css +21 -0
  21. package/dist/plugins/form/index.js +37 -8
  22. package/dist/plugins/form/public/style.css +126 -0
  23. package/dist/plugins/gallery/index.js +4 -3
  24. package/dist/plugins/gallery/public/client.js +1 -0
  25. package/dist/plugins/gallery/public/style.css +90 -0
  26. package/dist/plugins/grid/index.js +9 -3
  27. package/dist/plugins/grid/public/style.css +71 -0
  28. package/dist/plugins/iframe/index.js +13 -14
  29. package/dist/plugins/iframe/public/style.css +13 -0
  30. package/dist/plugins/index.js +7 -1
  31. package/dist/plugins/mermaid/index.js +3 -1
  32. package/dist/plugins/mermaid/{style.css → public/style.css} +7 -2
  33. package/dist/plugins/steps/README.md +42 -0
  34. package/dist/plugins/steps/index.js +99 -0
  35. package/dist/plugins/steps/public/client.js +1 -0
  36. package/dist/plugins/steps/public/style.css +77 -0
  37. package/dist/plugins/terminal/host.js +9 -3
  38. package/dist/plugins/terminal/index.js +10 -9
  39. package/dist/plugins/terminal/{style.css → public/style.css} +199 -45
  40. package/dist/plugins/terminal/sizes.js +2 -1
  41. package/dist/plugins/toc/README.md +21 -3
  42. package/dist/plugins/toc/index.js +12 -5
  43. package/dist/plugins/toc/public/client.js +1 -0
  44. package/dist/plugins/toc/public/style.css +99 -0
  45. package/dist/plugins/window/README.md +29 -0
  46. package/dist/plugins/window/index.js +64 -0
  47. package/dist/solid/index.js +14 -11
  48. package/dist/src/auth.js +2 -1
  49. package/dist/src/client/page/base.css +1078 -199
  50. package/dist/src/client/page/main.js +188 -39
  51. package/dist/src/loader.js +14 -3
  52. package/dist/src/package.js +3 -6
  53. package/dist/src/pages/blocks.js +8 -13
  54. package/dist/src/pages/markdown.js +1 -1
  55. package/dist/src/pages/render.js +106 -20
  56. package/dist/src/pages/window.js +31 -0
  57. package/dist/src/public.js +24 -0
  58. package/dist/src/server.js +251 -23
  59. package/package.json +5 -2
  60. package/plugins/callout/index.ts +3 -1
  61. package/plugins/callout/public/style.css +30 -0
  62. package/plugins/chat/autosize.ts +43 -9
  63. package/plugins/chat/client.tsx +22 -5
  64. package/plugins/chat/index.ts +22 -8
  65. package/plugins/chat/public/style.css +98 -0
  66. package/plugins/claude-code/index.ts +49 -14
  67. package/plugins/code/diff.ts +28 -8
  68. package/plugins/code/index.ts +33 -21
  69. package/plugins/code/public/style.css +68 -0
  70. package/plugins/comments/client.ts +139 -71
  71. package/plugins/comments/index.ts +9 -7
  72. package/plugins/comments/public/style.css +185 -0
  73. package/plugins/details/index.ts +7 -2
  74. package/plugins/details/public/style.css +7 -0
  75. package/plugins/draft/README.md +14 -0
  76. package/plugins/draft/index.ts +23 -0
  77. package/plugins/draft/public/style.css +21 -0
  78. package/plugins/forge/index.ts +16 -3
  79. package/plugins/form/index.ts +75 -27
  80. package/plugins/form/public/style.css +126 -0
  81. package/plugins/gallery/client.tsx +9 -3
  82. package/plugins/gallery/index.ts +31 -9
  83. package/plugins/gallery/public/style.css +90 -0
  84. package/plugins/grid/index.ts +19 -5
  85. package/plugins/grid/public/style.css +71 -0
  86. package/plugins/iframe/index.ts +20 -23
  87. package/plugins/iframe/public/style.css +13 -0
  88. package/plugins/index.ts +20 -1
  89. package/plugins/mermaid/index.ts +7 -3
  90. package/plugins/mermaid/{style.css → public/style.css} +7 -2
  91. package/plugins/steps/README.md +42 -0
  92. package/plugins/steps/client.ts +66 -0
  93. package/plugins/steps/index.ts +127 -0
  94. package/plugins/steps/public/style.css +77 -0
  95. package/plugins/terminal/client.ts +105 -48
  96. package/plugins/terminal/host.ts +143 -35
  97. package/plugins/terminal/index.ts +84 -25
  98. package/plugins/terminal/public/style.css +225 -0
  99. package/plugins/terminal/server.ts +64 -13
  100. package/plugins/terminal/sizes.ts +16 -4
  101. package/plugins/toc/README.md +21 -3
  102. package/plugins/toc/client.ts +90 -30
  103. package/plugins/toc/index.ts +26 -10
  104. package/plugins/toc/public/style.css +99 -0
  105. package/plugins/window/README.md +29 -0
  106. package/plugins/window/index.ts +85 -0
  107. package/skills/whiteboard/SKILL.md +3 -1
  108. package/solid/index.tsx +24 -9
  109. package/src/auth.ts +28 -9
  110. package/src/client/forms.ts +74 -28
  111. package/src/client/markdown.ts +15 -4
  112. package/src/client/page/base.css +1078 -199
  113. package/src/client/page/elsewhere.ts +32 -15
  114. package/src/client/page/fresh.ts +91 -23
  115. package/src/client/page/hold.ts +11 -2
  116. package/src/client/page/live.ts +10 -6
  117. package/src/client/page/main.ts +124 -42
  118. package/src/client/page/orphans.ts +25 -10
  119. package/src/client/page/sort.ts +14 -4
  120. package/src/client/page/sticky.ts +11 -3
  121. package/src/client/page/theme.ts +11 -7
  122. package/src/client/page/waiting.ts +141 -34
  123. package/src/client/page/window.ts +40 -0
  124. package/src/client/reactive.ts +19 -0
  125. package/src/client/read.ts +17 -10
  126. package/src/client/runtime.ts +170 -40
  127. package/src/client/scroll.ts +14 -4
  128. package/src/client/toast.ts +19 -5
  129. package/src/config.ts +20 -5
  130. package/src/define.ts +119 -31
  131. package/src/events.ts +111 -24
  132. package/src/html.ts +6 -2
  133. package/src/icons.ts +4 -2
  134. package/src/load.ts +10 -2
  135. package/src/loader.ts +81 -12
  136. package/src/package.ts +9 -8
  137. package/src/pages/blocks.ts +20 -14
  138. package/src/pages/index.ts +2 -2
  139. package/src/pages/markdown.ts +113 -34
  140. package/src/pages/render.ts +233 -41
  141. package/src/pages/window.ts +78 -0
  142. package/src/plugins.ts +90 -24
  143. package/src/public.ts +39 -0
  144. package/src/running.ts +8 -2
  145. package/src/serve.ts +29 -7
  146. package/src/server.ts +591 -110
  147. package/src/status.ts +15 -9
  148. package/dist/plugins/callout/style.css +0 -12
  149. package/dist/plugins/chat/style.css +0 -24
  150. package/dist/plugins/code/style.css +0 -29
  151. package/dist/plugins/comments/client.js +0 -10
  152. package/dist/plugins/comments/style.css +0 -40
  153. package/dist/plugins/details/style.css +0 -3
  154. package/dist/plugins/form/style.css +0 -44
  155. package/dist/plugins/gallery/client.js +0 -1
  156. package/dist/plugins/gallery/style.css +0 -27
  157. package/dist/plugins/grid/style.css +0 -25
  158. package/dist/plugins/iframe/client.js +0 -1
  159. package/dist/plugins/iframe/style.css +0 -29
  160. package/dist/plugins/toc/client.js +0 -1
  161. package/dist/plugins/toc/style.css +0 -19
  162. package/plugins/callout/style.css +0 -12
  163. package/plugins/chat/style.css +0 -24
  164. package/plugins/code/style.css +0 -29
  165. package/plugins/comments/style.css +0 -40
  166. package/plugins/details/style.css +0 -3
  167. package/plugins/form/style.css +0 -44
  168. package/plugins/gallery/style.css +0 -27
  169. package/plugins/grid/style.css +0 -25
  170. package/plugins/iframe/client.ts +0 -46
  171. package/plugins/iframe/style.css +0 -29
  172. package/plugins/terminal/style.css +0 -71
  173. package/plugins/toc/style.css +0 -19
  174. /package/dist/plugins/terminal/{client.js → public/client.js} +0 -0
@@ -1,19 +1,24 @@
1
1
  import fs from 'node:fs'
2
2
  import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
3
3
  import { html, raw, type DirectiveContext } from '@bigmistqke/whiteboard'
4
+ import { builtinPublic } from '../../src/package.ts'
4
5
 
5
6
  export async function render(ctx: DirectiveContext) {
6
7
  // the label and content are HTML already
7
- return html`<details class="wb-details"${'open' in ctx.attrs && raw(' open')}><summary>${ctx.label ? raw(ctx.label) : 'Details'}</summary><div class="wb-details-body">${raw(await ctx.toHtml(ctx.children))}</div></details>`
8
+ return html`<details class="wb-details" ${'open' in ctx.attrs && raw(' open')}>
9
+ <summary>${ctx.label ? raw(ctx.label) : 'Details'}</summary>
10
+ <div class="wb-details-body">${raw(await ctx.toHtml(ctx.children))}</div>
11
+ </details>`
8
12
  }
9
13
 
10
14
  export default function details(): Plugin {
11
15
  return definePlugin({
12
16
  name: 'details',
17
+ public: builtinPublic('details'),
13
18
  blocks: {
14
19
  details: {
15
20
  html: render,
16
- style: new URL('./style.css', import.meta.url),
21
+ style: 'style.css',
17
22
  },
18
23
  },
19
24
  docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
@@ -0,0 +1,7 @@
1
+ /* the base <details> style does the work; the body wrapper only needs spacing */
2
+ .wb-details > .wb-details-body > :first-child {
3
+ margin-top: 0.2em;
4
+ }
5
+ .wb-details > .wb-details-body > :last-child {
6
+ margin-bottom: 0;
7
+ }
@@ -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
+ }
@@ -9,7 +9,11 @@ import { execFileSync } from 'node:child_process'
9
9
  import { definePlugin, type Plugin, type TextLink } from '@bigmistqke/whiteboard'
10
10
 
11
11
  export type ForgeKind = 'github' | 'gitlab'
12
- export interface Forge { kind: ForgeKind; host: string; repo: string }
12
+ export interface Forge {
13
+ kind: ForgeKind
14
+ host: string
15
+ repo: string
16
+ }
13
17
 
14
18
  /** A git remote's URL → its host and repository path: https, ssh (`git@host:path`), ssh://. */
15
19
  export function parseRemote(url: string): { host: string; repo: string } | null {
@@ -22,7 +26,8 @@ export function parseRemote(url: string): { host: string; repo: string } | null
22
26
  }
23
27
 
24
28
  /** GitHub or GitLab, by the host's name; null for any other. */
25
- export const kindOf = (host: string): ForgeKind | null => /(^|\.)github\./.test(host) ? 'github' : /(^|\.)gitlab\./.test(host) || /^gitlab/.test(host) ? 'gitlab' : null
29
+ export const kindOf = (host: string): ForgeKind | null =>
30
+ /(^|\.)github\./.test(host) ? 'github' : /(^|\.)gitlab\./.test(host) || /^gitlab/.test(host) ? 'gitlab' : null
26
31
 
27
32
  /** The links for one forge: issues (`#n`) and pull or merge requests (`!n`), here or in `owner/repo`. */
28
33
  export function forgeLinks({ kind, host, repo }: Forge): TextLink[] {
@@ -42,7 +47,15 @@ export function forgeLinks({ kind, host, repo }: Forge): TextLink[] {
42
47
  /** The project's forge, from its `origin` remote; null without one it knows. */
43
48
  export function detect(dir: string): Forge | null {
44
49
  let url: string
45
- try { url = execFileSync('git', ['remote', 'get-url', 'origin'], { cwd: dir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }) } catch { return null }
50
+ try {
51
+ url = execFileSync('git', ['remote', 'get-url', 'origin'], {
52
+ cwd: dir,
53
+ encoding: 'utf8',
54
+ stdio: ['ignore', 'pipe', 'ignore'],
55
+ })
56
+ } catch {
57
+ return null
58
+ }
46
59
  const remote = parseRemote(url)
47
60
  const kind = remote && kindOf(remote.host)
48
61
  return remote && kind ? { kind, ...remote } : null
@@ -10,18 +10,25 @@ import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
10
10
  import { html, raw, type Block, type DirectiveContext } from '@bigmistqke/whiteboard'
11
11
  import { chatThread } from '../chat/index.ts'
12
12
  import { isQuestionName } from '../../src/status.ts'
13
+ import { builtinPublic } from '../../src/package.ts'
13
14
 
14
- const style = new URL('./style.css', import.meta.url)
15
+ const style = 'style.css'
15
16
 
16
17
  const CHOICES = new Set(['radio', 'check', 'select', 'hidden'])
17
18
 
18
- interface Node { type: string; name?: string; attributes?: Record<string, string>; children?: Node[] }
19
+ interface Node {
20
+ type: string
21
+ name?: string
22
+ attributes?: Record<string, string>
23
+ children?: Node[]
24
+ }
19
25
 
20
26
  /** The inputs written inside a form's markdown (forms inside it excluded: forms don't nest). */
21
27
  function inputsOf(nodes: Node[]) {
22
28
  const found: { name: string; attrs: Record<string, string> }[] = []
23
29
  const walk = (node: Node) => {
24
- if ((node.type === 'textDirective' || node.type === 'leafDirective') && node.name) found.push({ name: node.name, attrs: node.attributes ?? {} })
30
+ if ((node.type === 'textDirective' || node.type === 'leafDirective') && node.name)
31
+ found.push({ name: node.name, attrs: node.attributes ?? {} })
25
32
  if (node.type === 'containerDirective' && node.name === 'form') return
26
33
  for (const child of node.children ?? []) walk(child)
27
34
  }
@@ -37,15 +44,21 @@ const form: Block = {
37
44
  const c = ctx as DirectiveContext
38
45
  const name = c.attrs.name || c.attrs.id || 'form'
39
46
  // a colon marks the events of whiteboard or a plugin (`chat:message`), never an answer
40
- if (!isQuestionName(name)) throw new Error(`form name "${name}" has a colon: those names are reserved for events of whiteboard and plugins`)
47
+ if (!isQuestionName(name))
48
+ throw new Error(`form name "${name}" has a colon: those names are reserved for events of whiteboard and plugins`)
41
49
  const inputs = inputsOf(c.children as Node[])
42
50
  const choices = [...new Set(inputs.filter(i => CHOICES.has(i.name) && i.attrs.name).map(i => i.attrs.name))]
43
51
  const hasButton = inputs.some(i => i.name === 'button')
44
52
  // the first button is the form's primary one; the markup is the button block's own
45
- const body = (await c.toHtml(c.children)).replace('<button name="action"', '<button class="wb-primary" name="action"')
53
+ const body = (await c.toHtml(c.children)).replace(
54
+ '<button name="action"',
55
+ '<button class="wb-primary" name="action"',
56
+ )
46
57
  // the form's chat: talk about the question, named after the form (see ../chat)
47
58
  const thread = await chatThread(c, name, { choices })
48
- return html`<form name="${name}" class="wb-form">${raw(body)}${!hasButton && html`<p><button class="wb-primary">Send</button></p>`}${raw(thread)}</form>`
59
+ return html`<form name="${name}" class="wb-form">
60
+ ${raw(body)}${!hasButton && html`<p><button class="wb-primary">Send</button></p>`}${raw(thread)}
61
+ </form>`
49
62
  },
50
63
  }
51
64
 
@@ -57,22 +70,44 @@ const labelOf = (c: DirectiveContext, fallback = '') => (c.label ? raw(c.label)
57
70
  * the list: the option has a text box, typing in it picks the option, and it sends what was typed
58
71
  * (the core's forms.ts, `data-wb-other`).
59
72
  */
60
- const option = (type: 'radio' | 'checkbox'): Block['html'] => (ctx) => {
61
- const c = ctx as DirectiveContext
62
- if ('other' in c.attrs) {
63
- const placeholder = c.attrs.placeholder ?? 'something else'
64
- return html`<label class="wb-form-option wb-form-other"><input type="${type}" name="${c.attrs.name}" value="" data-wb-other><span class="wb-form-option-label">${labelOf(c, 'Other')}</span><input type="text" class="wb-form-other-text" data-wb-other-text placeholder="${placeholder}" aria-label="${c.labelText ?? 'Other'}"></label>`
73
+ const option =
74
+ (type: 'radio' | 'checkbox'): Block['html'] =>
75
+ ctx => {
76
+ const c = ctx as DirectiveContext
77
+ if ('other' in c.attrs) {
78
+ const placeholder = c.attrs.placeholder ?? 'something else'
79
+ return html`<label class="wb-form-option wb-form-other"
80
+ ><input type="${type}" name="${c.attrs.name}" value="" data-wb-other /><span class="wb-form-option-label"
81
+ >${labelOf(c, 'Other')}</span
82
+ ><input
83
+ type="text"
84
+ class="wb-form-other-text"
85
+ data-wb-other-text
86
+ placeholder="${placeholder}"
87
+ aria-label="${c.labelText ?? 'Other'}"
88
+ /></label>`
89
+ }
90
+ const value = c.attrs.value ?? c.labelText ?? ''
91
+ return html`<label class="wb-form-option"
92
+ ><input type="${type}" name="${c.attrs.name}" value="${value}" ${'checked' in c.attrs && raw(' checked')} /><span
93
+ class="wb-form-option-label"
94
+ >${labelOf(c, value)}</span
95
+ >${'recommended' in c.attrs && recommendedTag}</label
96
+ >`
65
97
  }
66
- const value = c.attrs.value ?? c.labelText ?? ''
67
- return html`<label class="wb-form-option"><input type="${type}" name="${c.attrs.name}" value="${value}"${'checked' in c.attrs && raw(' checked')}><span class="wb-form-option-label">${labelOf(c, value)}</span>${'recommended' in c.attrs && recommendedTag}</label>`
68
- }
69
98
 
70
99
  /** :text[label]{name=… placeholder=…}, and number, date, range */
71
- const field = (type: string): Block['html'] => (ctx) => {
72
- const c = ctx as DirectiveContext
73
- const extra = ['placeholder', 'min', 'max', 'step', 'value'].filter(k => k in c.attrs).map(k => html` ${raw(k)}="${c.attrs[k]}"`)
74
- return html`<label class="wb-form-field"><span class="wb-form-label">${labelOf(c)}</span><input type="${type}" name="${c.attrs.name}"${extra}></label>`
75
- }
100
+ const field =
101
+ (type: string): Block['html'] =>
102
+ ctx => {
103
+ const c = ctx as DirectiveContext
104
+ const extra = ['placeholder', 'min', 'max', 'step', 'value']
105
+ .filter(k => k in c.attrs)
106
+ .map(k => html` ${raw(k)}="${c.attrs[k]}"`)
107
+ return html`<label class="wb-form-field"
108
+ ><span class="wb-form-label">${labelOf(c)}</span><input type="${type}" name="${c.attrs.name}" ${extra}
109
+ /></label>`
110
+ }
76
111
 
77
112
  const input = (name: string, render: Block['html']): [string, Block] => [name, { html: render, style }]
78
113
 
@@ -83,20 +118,32 @@ const inputs: [string, Block][] = [
83
118
  input('number', field('number')),
84
119
  input('date', field('date')),
85
120
  input('range', field('range')),
86
- input('textarea', (ctx) => {
121
+ input('textarea', ctx => {
87
122
  const c = ctx as DirectiveContext
88
- return html`<label class="wb-form-field"><span class="wb-form-label">${labelOf(c)}</span><textarea name="${c.attrs.name}" rows="3" placeholder="${c.attrs.placeholder ?? ''}">${c.attrs.value ?? ''}</textarea></label>`
123
+ return html`<label class="wb-form-field"
124
+ ><span class="wb-form-label">${labelOf(c)}</span
125
+ ><textarea name="${c.attrs.name}" rows="3" placeholder="${c.attrs.placeholder ?? ''}">
126
+ ${c.attrs.value ?? ''}</textarea>
127
+ </label>`
89
128
  }),
90
- input('select', (ctx) => {
129
+ input('select', ctx => {
91
130
  const c = ctx as DirectiveContext
92
- const options = (c.attrs.options ?? '').split(',').map(s => s.trim()).filter(Boolean)
93
- return html`<label class="wb-form-field"><span class="wb-form-label">${labelOf(c)}</span><select name="${c.attrs.name}">${options.map(o => html`<option${o === c.attrs.value && raw(' selected')}>${o}</option>`)}</select></label>`
131
+ const options = (c.attrs.options ?? '')
132
+ .split(',')
133
+ .map(s => s.trim())
134
+ .filter(Boolean)
135
+ return html`<label class="wb-form-field"
136
+ ><span class="wb-form-label">${labelOf(c)}</span
137
+ ><select name="${c.attrs.name}">
138
+ ${options.map(o => html`<option${o === c.attrs.value && raw(' selected')}>${o}</option>`)}
139
+ </select></label
140
+ >`
94
141
  }),
95
- input('hidden', (ctx) => {
142
+ input('hidden', ctx => {
96
143
  const c = ctx as DirectiveContext
97
- return html`<input type="hidden" name="${c.attrs.name}" value="${c.attrs.value ?? ''}">`
144
+ return html`<input type="hidden" name="${c.attrs.name}" value="${c.attrs.value ?? ''}" />`
98
145
  }),
99
- input('button', (ctx) => {
146
+ input('button', ctx => {
100
147
  const c = ctx as DirectiveContext
101
148
  const value = c.labelText ?? 'Send'
102
149
  return html`<button name="action" value="${value}">${labelOf(c, 'Send')}</button>`
@@ -106,6 +153,7 @@ const inputs: [string, Block][] = [
106
153
  export default function formPlugin(): Plugin {
107
154
  return definePlugin({
108
155
  name: 'form',
156
+ public: builtinPublic('form'),
109
157
  blocks: { form, ...Object.fromEntries(inputs) },
110
158
  docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
111
159
  })
@@ -0,0 +1,126 @@
1
+ /* a form reads as a set-off part of the article: hairline rules above and below, no box */
2
+ .wb-form {
3
+ margin: calc(var(--rhythm) * 3) 0;
4
+ padding: 1.6em 0 1.7em;
5
+ border-top: var(--hairline) solid var(--border);
6
+ border-bottom: var(--hairline) solid var(--border);
7
+ display: grid;
8
+ gap: var(--space-2xl);
9
+ }
10
+ .wb-form-pending {
11
+ min-height: 72px;
12
+ }
13
+ /* the form's body is markdown: its first and last blocks sit flush with the rules */
14
+ .wb-form > :first-child {
15
+ margin-top: 0;
16
+ }
17
+ .wb-form > :last-child {
18
+ margin-bottom: 0;
19
+ }
20
+ .wb-form > :is(p, ul, ol, table, .wb-grid, div) {
21
+ margin-top: 0;
22
+ margin-bottom: 0;
23
+ }
24
+
25
+ /* an inline option, :radio[…] or :check[…]: the input and its label read as one */
26
+ .wb-form-option {
27
+ display: inline-flex;
28
+ gap: var(--space-md);
29
+ align-items: baseline;
30
+ cursor: pointer;
31
+ }
32
+ .wb-form-option + .wb-form-option {
33
+ margin-left: var(--space-2xl);
34
+ }
35
+ .wb-form-option input {
36
+ margin: 0;
37
+ translate: 0 0.1em;
38
+ }
39
+ .wb-form-option-label {
40
+ font-weight: var(--weight-strong);
41
+ }
42
+ /* an answer not on the list: a text box in the option's line (`other`) */
43
+ .wb-form-other {
44
+ align-items: center;
45
+ }
46
+ .wb-form-other .wb-form-other-text {
47
+ translate: none;
48
+ font: inherit;
49
+ padding: var(--space-2xs) var(--space-md);
50
+ min-width: 12em;
51
+ border: var(--hairline) solid var(--border);
52
+ border-radius: var(--radius-sm);
53
+ background: var(--bg);
54
+ color: var(--text);
55
+ }
56
+ .wb-form-recommended {
57
+ font: 500 var(--ui-tiny)/var(--ui-line-height) var(--sans);
58
+ color: var(--muted);
59
+ letter-spacing: var(--caps-spacing);
60
+ text-transform: uppercase;
61
+ margin-left: var(--space-lg);
62
+ }
63
+
64
+ /* a list item that starts with an option is a row to pick: no bullet, the picked one tinted, and
65
+ the rest of the item reads as what the option means */
66
+ .wb-form li:has(> p:first-child > .wb-form-option:first-child),
67
+ .wb-form li:has(> .wb-form-option:first-child) {
68
+ list-style: none;
69
+ margin-left: -1.2em;
70
+ padding: var(--space-sm) var(--space-lg);
71
+ border-radius: var(--radius-sm);
72
+ }
73
+ .wb-form li:has(> p:first-child > .wb-form-option:first-child):hover,
74
+ .wb-form li:has(> .wb-form-option:first-child):hover {
75
+ background: var(--tint);
76
+ }
77
+ .wb-form li:has(> p:first-child > .wb-form-option:first-child input:checked),
78
+ .wb-form li:has(> .wb-form-option:first-child input:checked) {
79
+ background: color-mix(in srgb, var(--accent) var(--tint-faint), transparent);
80
+ }
81
+ .wb-form li > p:first-child {
82
+ margin-bottom: 0.2em;
83
+ }
84
+ .wb-form li > p:first-child > .wb-form-option:first-child,
85
+ .wb-form li > .wb-form-option:first-child {
86
+ display: flex;
87
+ margin-bottom: 0.15em;
88
+ }
89
+
90
+ /* fields: the label above the input */
91
+ .wb-form-field {
92
+ display: flex;
93
+ flex-direction: column;
94
+ gap: var(--space-sm);
95
+ margin: 0;
96
+ min-width: 0;
97
+ }
98
+ .wb-form-field :is(input:not([type='range']), textarea, select) {
99
+ width: 100%;
100
+ }
101
+ .wb-form-field textarea {
102
+ resize: vertical;
103
+ }
104
+ .wb-form-label {
105
+ font: var(--weight-strong) var(--ui-small)/var(--ui-line-height) var(--sans);
106
+ color: var(--muted);
107
+ letter-spacing: 0.01em;
108
+ }
109
+ .wb-form-label:empty {
110
+ display: none;
111
+ }
112
+
113
+ /* buttons: the first one of a form is its primary one */
114
+ .wb-form button[name='action'] + button[name='action'] {
115
+ margin-left: var(--space-md);
116
+ }
117
+ .wb-form button.wb-primary {
118
+ background: var(--accent);
119
+ color: var(--accent-text);
120
+ border-color: var(--accent);
121
+ }
122
+ .wb-card .wb-form {
123
+ padding: 0;
124
+ border: 0;
125
+ margin: 0.6em 0 0;
126
+ }
@@ -50,10 +50,16 @@ function Gallery(props: { items: Item[]; min: string | null; narrow: boolean })
50
50
  <img src={item().src ?? ''} alt={item().alt} />
51
51
  <div class="wb-lightbox-caption" innerHTML={item().title ?? ''} />
52
52
  <Show when={props.items.length > 1}>
53
- <button type="button" class="wb-lightbox-prev" aria-label="Previous" onClick={() => step(-1)}>‹</button>
54
- <button type="button" class="wb-lightbox-next" aria-label="Next" onClick={() => step(1)}>›</button>
53
+ <button type="button" class="wb-lightbox-prev" aria-label="Previous" onClick={() => step(-1)}>
54
+ ‹
55
+ </button>
56
+ <button type="button" class="wb-lightbox-next" aria-label="Next" onClick={() => step(1)}>
57
+ ›
58
+ </button>
55
59
  </Show>
56
- <button type="button" class="wb-lightbox-close" aria-label="Close" onClick={() => setOpen(null)}>×</button>
60
+ <button type="button" class="wb-lightbox-close" aria-label="Close" onClick={() => setOpen(null)}>
61
+ ×
62
+ </button>
57
63
  </div>
58
64
  )}
59
65
  </Show>
@@ -3,20 +3,35 @@ import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
3
3
  // Turns the block's content into gallery items: one per heading (first image in the section is
4
4
  // its picture), or one per image when there are no headings.
5
5
  import { escape, type DirectiveContext } from '@bigmistqke/whiteboard'
6
- import { builtFile } from '../../src/package.ts'
6
+ import { builtinPublic } from '../../src/package.ts'
7
7
 
8
- interface Node { type: string; depth?: number; url?: string; alt?: string; children?: Node[] }
9
- export interface Item { src: string | null; alt: string; title: string | null; html: string }
8
+ interface Node {
9
+ type: string
10
+ depth?: number
11
+ url?: string
12
+ alt?: string
13
+ children?: Node[]
14
+ }
15
+ export interface Item {
16
+ src: string | null
17
+ alt: string
18
+ title: string | null
19
+ html: string
20
+ }
10
21
 
11
22
  /** Remove and return the first image in a list of nodes (searching inside paragraphs). */
12
23
  function takeImage(nodes: Node[]): Node | null {
13
24
  for (let i = 0; i < nodes.length; i++) {
14
25
  const n = nodes[i]
15
- if (n.type === 'image') { nodes.splice(i, 1); return n }
26
+ if (n.type === 'image') {
27
+ nodes.splice(i, 1)
28
+ return n
29
+ }
16
30
  if (n.children) {
17
31
  const found = takeImage(n.children)
18
32
  if (found) {
19
- if (n.type === 'paragraph' && n.children.every(c => c.type === 'text' && !String((c as any).value).trim())) nodes.splice(i, 1)
33
+ if (n.type === 'paragraph' && n.children.every(c => c.type === 'text' && !String((c as any).value).trim()))
34
+ nodes.splice(i, 1)
20
35
  return found
21
36
  }
22
37
  }
@@ -38,12 +53,18 @@ export async function props(ctx: DirectiveContext) {
38
53
  }
39
54
  for (const g of groups) {
40
55
  const img = takeImage(g.body)
41
- items.push({ src: img?.url ?? null, alt: img?.alt ?? '', title: await ctx.toHtml(g.heading.children ?? []), html: await ctx.toHtml(g.body) })
56
+ items.push({
57
+ src: img?.url ?? null,
58
+ alt: img?.alt ?? '',
59
+ title: await ctx.toHtml(g.heading.children ?? []),
60
+ html: await ctx.toHtml(g.body),
61
+ })
42
62
  }
43
63
  } else {
44
64
  const walk = (nodes: Node[]) => {
45
65
  for (const n of nodes) {
46
- if (n.type === 'image') items.push({ src: n.url!, alt: n.alt ?? '', title: n.alt ? escape(n.alt) : null, html: '' })
66
+ if (n.type === 'image')
67
+ items.push({ src: n.url!, alt: n.alt ?? '', title: n.alt ? escape(n.alt) : null, html: '' })
47
68
  else if (n.children) walk(n.children)
48
69
  }
49
70
  }
@@ -55,11 +76,12 @@ export async function props(ctx: DirectiveContext) {
55
76
  export default function gallery(): Plugin {
56
77
  return definePlugin({
57
78
  name: 'gallery',
79
+ public: builtinPublic('gallery'),
58
80
  blocks: {
59
81
  gallery: {
60
82
  props,
61
- client: builtFile(import.meta.url, 'client.js'),
62
- style: new URL('./style.css', import.meta.url),
83
+ client: 'client.js',
84
+ style: 'style.css',
63
85
  },
64
86
  },
65
87
  docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
@@ -0,0 +1,90 @@
1
+ .wb-gallery {
2
+ display: grid;
3
+ gap: 40px var(--space-3xl);
4
+ margin: 4em 0;
5
+ grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--wb-gallery-min, 240px)), 1fr));
6
+ }
7
+ .wb-gallery-item {
8
+ margin: 0;
9
+ overflow: hidden;
10
+ display: flex;
11
+ flex-direction: column;
12
+ min-width: 0;
13
+ }
14
+ .wb-gallery-thumb {
15
+ padding: 0;
16
+ border: 0;
17
+ border-radius: var(--radius);
18
+ overflow: hidden;
19
+ background: var(--code-bg);
20
+ cursor: zoom-in;
21
+ display: block;
22
+ }
23
+ .wb-gallery-thumb img {
24
+ display: block;
25
+ width: 100%;
26
+ aspect-ratio: 4 / 3;
27
+ object-fit: cover;
28
+ border-radius: 0;
29
+ }
30
+ .wb-gallery-item figcaption {
31
+ padding: var(--space-xl) var(--space-2xs) 0;
32
+ font: var(--ui-text)/var(--ui-line-height) var(--serif);
33
+ color: var(--text);
34
+ }
35
+ .wb-gallery-item figcaption h3 {
36
+ margin: 0 0 0.25em;
37
+ font-size: 1rem;
38
+ }
39
+ .wb-gallery-item figcaption > div > :first-child {
40
+ margin-top: 0;
41
+ }
42
+ .wb-gallery-item figcaption > div > :last-child {
43
+ margin-bottom: 0;
44
+ }
45
+
46
+ .wb-lightbox {
47
+ position: fixed;
48
+ inset: 0;
49
+ z-index: var(--layer-top);
50
+ background: rgb(0 0 0 / 0.86);
51
+ display: grid;
52
+ place-items: center;
53
+ grid-template-rows: 1fr auto;
54
+ padding: var(--space-3xl) var(--space-2xl);
55
+ }
56
+ .wb-lightbox img {
57
+ max-width: 100%;
58
+ max-height: calc(100vh - 110px);
59
+ object-fit: contain;
60
+ border-radius: var(--radius-sm);
61
+ }
62
+ .wb-lightbox-caption {
63
+ color: #eee;
64
+ text-align: center;
65
+ padding-top: var(--space-lg);
66
+ }
67
+ .wb-lightbox button {
68
+ position: absolute;
69
+ background: rgb(255 255 255 / 0.12);
70
+ color: #fff;
71
+ border: 0;
72
+ font-size: 1.6rem;
73
+ line-height: 1;
74
+ width: 44px;
75
+ height: 44px;
76
+ border-radius: 50%;
77
+ padding: 0;
78
+ }
79
+ .wb-lightbox-prev {
80
+ left: 12px;
81
+ top: 50%;
82
+ }
83
+ .wb-lightbox-next {
84
+ right: 12px;
85
+ top: 50%;
86
+ }
87
+ .wb-lightbox-close {
88
+ right: 12px;
89
+ top: 12px;
90
+ }
@@ -2,8 +2,14 @@ import fs from 'node:fs'
2
2
  import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
3
3
  // Static block: no component, so no JavaScript on the page.
4
4
  import { html, raw, type DirectiveContext } from '@bigmistqke/whiteboard'
5
+ import { builtinPublic } from '../../src/package.ts'
5
6
 
6
- const slug = (s: string) => s.toLowerCase().trim().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '')
7
+ const slug = (s: string) =>
8
+ s
9
+ .toLowerCase()
10
+ .trim()
11
+ .replace(/[^a-z0-9]+/g, '-')
12
+ .replace(/^-|-$/g, '')
7
13
 
8
14
  export async function render(ctx: DirectiveContext) {
9
15
  const { intro, sections } = await ctx.sections()
@@ -13,22 +19,30 @@ export async function render(ctx: DirectiveContext) {
13
19
  let title = s.title
14
20
  let badge: string | null = null
15
21
  const m = title ? /^(.*?)\s*\{([^}]+)\}\s*$/s.exec(title) : null
16
- if (m) { title = m[1]; badge = m[2].trim() }
22
+ if (m) {
23
+ title = m[1]
24
+ badge = m[2].trim()
25
+ }
17
26
  // a section's title and html are HTML already; the badge is text from the heading
18
27
  const b = badge && html`<span class="wb-badge" data-badge="${slug(badge)}">${badge}</span>`
19
28
  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)}"`}>${head}<div class="wb-card-body">${raw(s.html)}</div></article>`
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>`
21
33
  })
22
- return html`${raw(intro)}<div class="wb-grid${'narrow' in ctx.attrs ? '' : ' wb-wide'}"${style}>${cards}</div>`
34
+ return html`${raw(intro)}
35
+ <div class="wb-grid${'narrow' in ctx.attrs ? '' : ' wb-wide'}" ${style}>${cards}</div>`
23
36
  }
24
37
 
25
38
  export default function grid(): Plugin {
26
39
  return definePlugin({
27
40
  name: 'grid',
41
+ public: builtinPublic('grid'),
28
42
  blocks: {
29
43
  grid: {
30
44
  html: render,
31
- style: new URL('./style.css', import.meta.url),
45
+ style: 'style.css',
32
46
  },
33
47
  },
34
48
  docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),