@bigmistqke/whiteboard 0.3.0 → 0.4.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 (155) hide show
  1. package/README.md +67 -17
  2. package/bin/whiteboard.ts +268 -71
  3. package/dist/client/runtime.js +88 -41
  4. package/dist/define.js +21 -2
  5. package/dist/plugins/callout/index.js +3 -1
  6. package/dist/plugins/callout/public/style.css +30 -0
  7. package/dist/plugins/chat/index.js +7 -4
  8. package/dist/plugins/chat/{client.js → public/client.js} +1 -1
  9. package/dist/plugins/chat/public/style.css +98 -0
  10. package/dist/plugins/code/index.js +3 -1
  11. package/dist/plugins/code/public/style.css +68 -0
  12. package/dist/plugins/comments/index.js +4 -5
  13. package/dist/plugins/comments/public/client.js +19 -0
  14. package/dist/plugins/comments/public/style.css +185 -0
  15. package/dist/plugins/details/index.js +7 -2
  16. package/dist/plugins/details/public/style.css +7 -0
  17. package/dist/plugins/form/index.js +37 -8
  18. package/dist/plugins/form/public/style.css +126 -0
  19. package/dist/plugins/gallery/index.js +4 -3
  20. package/dist/plugins/gallery/public/client.js +1 -0
  21. package/dist/plugins/gallery/public/style.css +90 -0
  22. package/dist/plugins/grid/index.js +9 -3
  23. package/dist/plugins/grid/public/style.css +71 -0
  24. package/dist/plugins/iframe/index.js +13 -14
  25. package/dist/plugins/iframe/public/style.css +13 -0
  26. package/dist/plugins/index.js +3 -1
  27. package/dist/plugins/mermaid/index.js +3 -1
  28. package/dist/plugins/mermaid/{style.css → public/style.css} +7 -2
  29. package/dist/plugins/terminal/index.js +10 -9
  30. package/dist/plugins/terminal/{style.css → public/style.css} +199 -45
  31. package/dist/plugins/toc/README.md +12 -0
  32. package/dist/plugins/toc/index.js +9 -5
  33. package/dist/plugins/toc/public/client.js +1 -0
  34. package/dist/plugins/toc/public/style.css +93 -0
  35. package/dist/plugins/window/README.md +29 -0
  36. package/dist/plugins/window/index.js +64 -0
  37. package/dist/solid/index.js +14 -11
  38. package/dist/src/client/page/base.css +1078 -199
  39. package/dist/src/client/page/main.js +174 -32
  40. package/dist/src/loader.js +7 -2
  41. package/dist/src/package.js +3 -6
  42. package/dist/src/pages/blocks.js +8 -13
  43. package/dist/src/pages/markdown.js +1 -1
  44. package/dist/src/pages/render.js +73 -13
  45. package/dist/src/pages/window.js +30 -0
  46. package/dist/src/public.js +24 -0
  47. package/dist/src/server.js +37 -15
  48. package/package.json +3 -1
  49. package/plugins/callout/index.ts +3 -1
  50. package/plugins/callout/public/style.css +30 -0
  51. package/plugins/chat/autosize.ts +43 -9
  52. package/plugins/chat/client.tsx +22 -5
  53. package/plugins/chat/index.ts +22 -8
  54. package/plugins/chat/public/style.css +98 -0
  55. package/plugins/claude-code/index.ts +49 -14
  56. package/plugins/code/diff.ts +28 -8
  57. package/plugins/code/index.ts +30 -20
  58. package/plugins/code/public/style.css +68 -0
  59. package/plugins/comments/client.ts +139 -71
  60. package/plugins/comments/index.ts +9 -7
  61. package/plugins/comments/public/style.css +185 -0
  62. package/plugins/details/index.ts +7 -2
  63. package/plugins/details/public/style.css +7 -0
  64. package/plugins/forge/index.ts +16 -3
  65. package/plugins/form/index.ts +75 -27
  66. package/plugins/form/public/style.css +126 -0
  67. package/plugins/gallery/client.tsx +9 -3
  68. package/plugins/gallery/index.ts +31 -9
  69. package/plugins/gallery/public/style.css +90 -0
  70. package/plugins/grid/index.ts +19 -5
  71. package/plugins/grid/public/style.css +71 -0
  72. package/plugins/iframe/index.ts +20 -23
  73. package/plugins/iframe/public/style.css +13 -0
  74. package/plugins/index.ts +16 -1
  75. package/plugins/mermaid/index.ts +3 -1
  76. package/plugins/mermaid/{style.css → public/style.css} +7 -2
  77. package/plugins/terminal/client.ts +105 -48
  78. package/plugins/terminal/host.ts +131 -29
  79. package/plugins/terminal/index.ts +84 -25
  80. package/plugins/terminal/public/style.css +225 -0
  81. package/plugins/terminal/server.ts +64 -13
  82. package/plugins/terminal/sizes.ts +13 -3
  83. package/plugins/toc/README.md +12 -0
  84. package/plugins/toc/client.ts +58 -29
  85. package/plugins/toc/index.ts +22 -5
  86. package/plugins/toc/public/style.css +93 -0
  87. package/plugins/window/README.md +29 -0
  88. package/plugins/window/index.ts +85 -0
  89. package/skills/whiteboard/SKILL.md +3 -1
  90. package/solid/index.tsx +24 -9
  91. package/src/auth.ts +25 -7
  92. package/src/client/forms.ts +74 -28
  93. package/src/client/markdown.ts +15 -4
  94. package/src/client/page/base.css +1078 -199
  95. package/src/client/page/elsewhere.ts +32 -15
  96. package/src/client/page/fresh.ts +91 -23
  97. package/src/client/page/hold.ts +11 -2
  98. package/src/client/page/live.ts +10 -6
  99. package/src/client/page/main.ts +106 -34
  100. package/src/client/page/orphans.ts +25 -10
  101. package/src/client/page/sort.ts +14 -4
  102. package/src/client/page/sticky.ts +11 -3
  103. package/src/client/page/theme.ts +11 -7
  104. package/src/client/page/waiting.ts +141 -34
  105. package/src/client/page/window.ts +40 -0
  106. package/src/client/reactive.ts +19 -0
  107. package/src/client/read.ts +17 -10
  108. package/src/client/runtime.ts +130 -35
  109. package/src/client/scroll.ts +14 -4
  110. package/src/client/toast.ts +19 -5
  111. package/src/config.ts +20 -5
  112. package/src/define.ts +67 -23
  113. package/src/events.ts +111 -24
  114. package/src/html.ts +6 -2
  115. package/src/icons.ts +4 -2
  116. package/src/load.ts +10 -2
  117. package/src/loader.ts +75 -11
  118. package/src/package.ts +9 -8
  119. package/src/pages/blocks.ts +20 -14
  120. package/src/pages/markdown.ts +113 -34
  121. package/src/pages/render.ts +198 -37
  122. package/src/pages/window.ts +71 -0
  123. package/src/plugins.ts +90 -24
  124. package/src/public.ts +39 -0
  125. package/src/running.ts +8 -2
  126. package/src/serve.ts +29 -7
  127. package/src/server.ts +351 -108
  128. package/src/status.ts +15 -9
  129. package/dist/plugins/callout/style.css +0 -12
  130. package/dist/plugins/chat/style.css +0 -24
  131. package/dist/plugins/code/style.css +0 -29
  132. package/dist/plugins/comments/client.js +0 -10
  133. package/dist/plugins/comments/style.css +0 -40
  134. package/dist/plugins/details/style.css +0 -3
  135. package/dist/plugins/form/style.css +0 -44
  136. package/dist/plugins/gallery/client.js +0 -1
  137. package/dist/plugins/gallery/style.css +0 -27
  138. package/dist/plugins/grid/style.css +0 -25
  139. package/dist/plugins/iframe/client.js +0 -1
  140. package/dist/plugins/iframe/style.css +0 -29
  141. package/dist/plugins/toc/client.js +0 -1
  142. package/dist/plugins/toc/style.css +0 -19
  143. package/plugins/callout/style.css +0 -12
  144. package/plugins/chat/style.css +0 -24
  145. package/plugins/code/style.css +0 -29
  146. package/plugins/comments/style.css +0 -40
  147. package/plugins/details/style.css +0 -3
  148. package/plugins/form/style.css +0 -44
  149. package/plugins/gallery/style.css +0 -27
  150. package/plugins/grid/style.css +0 -25
  151. package/plugins/iframe/client.ts +0 -46
  152. package/plugins/iframe/style.css +0 -29
  153. package/plugins/terminal/style.css +0 -71
  154. package/plugins/toc/style.css +0 -19
  155. /package/dist/plugins/terminal/{client.js → public/client.js} +0 -0
@@ -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'),
@@ -0,0 +1,71 @@
1
+ .wb-grid {
2
+ display: grid;
3
+ gap: var(--space-3xl);
4
+ margin: 4em 0;
5
+ grid-template-columns: repeat(
6
+ auto-fill,
7
+ minmax(min(100%, calc(var(--wide, 1040px) / var(--wb-grid-cols, 3) - 16px)), 1fr)
8
+ );
9
+ }
10
+ .wb-grid:not(.wb-wide) {
11
+ grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
12
+ }
13
+ .wb-card {
14
+ background: var(--surface);
15
+ border: var(--hairline) solid var(--border);
16
+ border-radius: var(--radius);
17
+ padding: var(--space-2xl) var(--space-2xl) var(--space-2xl);
18
+ min-width: 0;
19
+ }
20
+ .wb-card > header {
21
+ display: flex;
22
+ gap: var(--space-lg);
23
+ align-items: baseline;
24
+ justify-content: space-between;
25
+ margin-bottom: 0.55em;
26
+ }
27
+ .wb-card h3 {
28
+ margin: 0;
29
+ font-size: 1.02rem;
30
+ }
31
+ .wb-card-body {
32
+ font-size: var(--ui-text);
33
+ line-height: 1.6;
34
+ }
35
+ .wb-card-body > :first-child {
36
+ margin-top: 0;
37
+ }
38
+ .wb-card-body > :last-child {
39
+ margin-bottom: 0;
40
+ }
41
+
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);
71
+ }
@@ -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). A header shows its label and address,
3
- // opens it on its own, and fills the window with it; the frame can be made taller by dragging its
4
- // bottom edge.
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.
5
5
  import fs from 'node:fs'
6
- import { packagePath } from '../../src/package.ts'
6
+ import { builtinPublic } from '../../src/package.ts'
7
7
  import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
8
- import { html, raw, type DirectiveContext } from '@bigmistqke/whiteboard'
8
+ import { html, windowFrame, 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)
@@ -17,38 +17,35 @@ export function height(value: string | undefined): string {
17
17
  return '480px'
18
18
  }
19
19
 
20
- // the header's buttons, as icons
21
- const svg = (d: string) => raw(`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">${d}</svg>`)
22
- const OPEN = svg('<path d="M9 2.5h4.5V7M13.5 2.5 7.5 8.5M11.5 9.5v3a1 1 0 0 1-1 1h-7a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1h3"/>')
23
- const MAXIMIZE = svg('<path d="M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10"/>')
24
- const RESTORE = svg('<path d="M6 2.5V6H2.5M13.5 6H10V2.5M10 13.5V10h3.5M2.5 10H6v3.5"/>')
25
-
26
20
  export async function render(ctx: DirectiveContext) {
27
21
  const src = (ctx.attrs.src ?? '').trim()
28
22
  if (!src) return html`<pre class="wb-error">iframe: needs a src, like ::iframe{src="http://localhost:5173"}</pre>`
29
- if (!safeSrc(src)) return html`<pre class="wb-error">iframe: src must be an http(s) URL or a path, not ${src.split(':')[0]}:</pre>`
23
+ if (!safeSrc(src))
24
+ return html`<pre class="wb-error">iframe: src must be an http(s) URL or a path, not ${src.split(':')[0]}:</pre>`
30
25
  const title = ctx.labelText ?? ctx.attrs.title ?? src
31
- // a header like a browser window's: the label, or the address without one (hovering the label
32
- // shows the address), opening it on its own, and filling the window with it (client.ts).
33
- // `bare`: the frame alone.
34
- const header = !('bare' in ctx.attrs) && html`<div class="wb-iframe-bar">
35
- <span class="wb-iframe-name" title="${src}">${ctx.label ? html`<span class="wb-iframe-title">${raw(ctx.label)}</span>` : html`<span class="wb-iframe-url">${src}</span>`}</span>
36
- <a class="wb-iframe-button" href="${src}" target="_blank" rel="noopener" title="Open on its own" aria-label="Open on its own">${OPEN}</a>
37
- <button type="button" class="wb-iframe-button" data-wb-maximize title="Fill the window" aria-label="Fill the window"><span class="wb-iframe-max">${MAXIMIZE}</span><span class="wb-iframe-restore">${RESTORE}</span></button>
38
- </div>`
39
- return html`<div class="wb-iframe${'wide' in ctx.attrs && raw(' wb-wide')}">${header}<div class="wb-iframe-frame" style="height: ${height(ctx.attrs.height)}"><iframe src="${src}" title="${title}" loading="lazy" referrerpolicy="no-referrer"></iframe></div></div>`
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
+ })
40
37
  }
41
38
 
42
39
  export default function iframe(): Plugin {
43
40
  return definePlugin({
44
41
  name: 'iframe',
42
+ public: builtinPublic('iframe'),
45
43
  blocks: {
46
44
  iframe: {
47
45
  html: render,
48
- style: new URL('./style.css', import.meta.url),
46
+ style: 'style.css',
49
47
  },
50
48
  },
51
- setup: () => ({ client: packagePath('dist/plugins/iframe/client.js') }),
52
49
  docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
53
50
  })
54
51
  }
@@ -0,0 +1,13 @@
1
+ /* the iframe in its window (the window's look is the page's): a frame its bottom edge drags taller */
2
+ .wb-iframe-frame {
3
+ resize: vertical;
4
+ overflow: hidden;
5
+ min-height: 120px;
6
+ background: #fff;
7
+ }
8
+ .wb-iframe-frame iframe {
9
+ display: block;
10
+ width: 100%;
11
+ height: 100%;
12
+ border: 0;
13
+ }
package/plugins/index.ts CHANGED
@@ -15,7 +15,22 @@ import grid from './grid/index.ts'
15
15
  import iframe from './iframe/index.ts'
16
16
  import mermaid from './mermaid/index.ts'
17
17
  import quiet from './quiet/index.ts'
18
+ import windows from './window/index.ts'
18
19
 
19
20
  export function builtins(): Plugin[] {
20
- return [callout(), chat(), code(), comments(), details(), forge(), form(), gallery(), grid(), iframe(), mermaid(), quiet()]
21
+ return [
22
+ callout(),
23
+ chat(),
24
+ code(),
25
+ comments(),
26
+ details(),
27
+ forge(),
28
+ form(),
29
+ gallery(),
30
+ grid(),
31
+ iframe(),
32
+ mermaid(),
33
+ quiet(),
34
+ windows(),
35
+ ]
21
36
  }
@@ -6,6 +6,7 @@ import crypto from 'node:crypto'
6
6
  // pele loads the first time a page has a diagram, not with the plugin
7
7
  let pele: typeof import('pele') | undefined
8
8
  import { html, raw, type FenceContext } from '@bigmistqke/whiteboard'
9
+ import { builtinPublic } from '../../src/package.ts'
9
10
 
10
11
  const FONT = 'ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif'
11
12
 
@@ -28,11 +29,12 @@ export async function render(ctx: FenceContext) {
28
29
  export default function mermaid(): Plugin {
29
30
  return definePlugin({
30
31
  name: 'mermaid',
32
+ public: builtinPublic('mermaid'),
31
33
  blocks: {
32
34
  mermaid: {
33
35
  fence: true,
34
36
  html: render,
35
- style: new URL('./style.css', import.meta.url),
37
+ style: 'style.css',
36
38
  },
37
39
  },
38
40
  docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
@@ -1,7 +1,9 @@
1
1
  /* Pele reads its colours from --pele-* variables; map them onto the page's tokens so diagrams
2
2
  follow the theme without being re-rendered. */
3
3
  .wb-diagram {
4
- margin: 4em 0; overflow-x: auto; text-align: center;
4
+ margin: 4em 0;
5
+ overflow-x: auto;
6
+ text-align: center;
5
7
  --pele-bg: transparent;
6
8
  --pele-fg: var(--text);
7
9
  --pele-muted: var(--muted);
@@ -13,4 +15,7 @@
13
15
  --pele-font: var(--sans);
14
16
  --pele-radius: 6px;
15
17
  }
16
- .wb-diagram svg { max-width: 100%; height: auto; }
18
+ .wb-diagram svg {
19
+ max-width: 100%;
20
+ height: auto;
21
+ }
@@ -10,11 +10,28 @@ import { Terminal } from '@xterm/xterm'
10
10
  import { FitAddon } from '@xterm/addon-fit'
11
11
 
12
12
  const store = {
13
- get: (k: string) => { try { return sessionStorage.getItem(k) } catch { return null } },
14
- set: (k: string, v: string) => { try { sessionStorage.setItem(k, v) } catch { /* storage unavailable */ } },
13
+ get: (k: string) => {
14
+ try {
15
+ return sessionStorage.getItem(k)
16
+ } catch {
17
+ return null
18
+ }
19
+ },
20
+ set: (k: string, v: string) => {
21
+ try {
22
+ sessionStorage.setItem(k, v)
23
+ } catch {
24
+ /* storage unavailable */
25
+ }
26
+ },
15
27
  }
16
28
 
17
- interface Session { id: string; label: string; running: boolean; exited: number | null }
29
+ interface Session {
30
+ id: string
31
+ label: string
32
+ running: boolean
33
+ exited: number | null
34
+ }
18
35
 
19
36
  function init(drawer: HTMLElement) {
20
37
  const screen = drawer.querySelector<HTMLElement>('.wb-term-screen')!
@@ -25,7 +42,12 @@ function init(drawer: HTMLElement) {
25
42
  const grip = drawer.querySelector<HTMLElement>('.wb-term-grip')!
26
43
  // the sessions as the server wrote them into the page, and the tab this browser tab shows
27
44
  let sessions: Session[] = []
28
- try { ({ sessions } = JSON.parse(drawer.dataset.sessions ?? '{}')); sessions ??= [] } catch { /* none */ }
45
+ try {
46
+ ;({ sessions } = JSON.parse(drawer.dataset.sessions ?? '{}'))
47
+ sessions ??= []
48
+ } catch {
49
+ /* none */
50
+ }
29
51
  let current: string | null = drawer.dataset.tab ?? sessions[0]?.id ?? null
30
52
 
31
53
  const term = new Terminal({
@@ -77,7 +99,10 @@ function init(drawer: HTMLElement) {
77
99
  sent = key
78
100
  post('/api/terminal/resize', { id: current, viewer, cols: dims.cols, rows: dims.rows, active: claim })
79
101
  // it is ours from now on; the host confirms with a `size`
80
- if (claim) { active = viewer; claim = false }
102
+ if (claim) {
103
+ active = viewer
104
+ claim = false
105
+ }
81
106
  }
82
107
  show()
83
108
  }
@@ -86,7 +111,8 @@ function init(drawer: HTMLElement) {
86
111
  function show() {
87
112
  const dims = fit.proposeDimensions()
88
113
  const size = mine() || !session ? dims : session
89
- if (size?.cols && size?.rows && (size.cols !== term.cols || size.rows !== term.rows)) term.resize(size.cols, size.rows)
114
+ if (size?.cols && size?.rows && (size.cols !== term.cols || size.rows !== term.rows))
115
+ term.resize(size.cols, size.rows)
90
116
  }
91
117
 
92
118
  /** The reader uses this drawer: the session takes its size. */
@@ -109,11 +135,18 @@ function init(drawer: HTMLElement) {
109
135
  const vt = (document as any).startViewTransition
110
136
  if (vt && !matchMedia('(prefers-reduced-motion: reduce)').matches) vt.call(document, apply)
111
137
  else apply()
112
- requestAnimationFrame(() => { if (open) use(); refit(); if (open) term.focus() })
138
+ requestAnimationFrame(() => {
139
+ if (open) use()
140
+ refit()
141
+ if (open) term.focus()
142
+ })
113
143
  }
114
144
  toggle.addEventListener('click', () => setOpen(!isOpen()))
115
145
  addEventListener('keydown', e => {
116
- if (e.ctrlKey && e.key === '`') { e.preventDefault(); setOpen(!isOpen()) }
146
+ if (e.ctrlKey && e.key === '`') {
147
+ e.preventDefault()
148
+ setOpen(!isOpen())
149
+ }
117
150
  })
118
151
 
119
152
  // ---- height --------------------------------------------------------------------------------
@@ -145,50 +178,60 @@ function init(drawer: HTMLElement) {
145
178
  if (!current) return
146
179
  use()
147
180
  const id = current
148
- if (!pending) queueMicrotask(() => {
149
- const data = pending
150
- pending = ''
151
- chain = chain.then(() => post('/api/terminal/input', { id, data })).then(() => {}, () => {})
152
- })
181
+ if (!pending)
182
+ queueMicrotask(() => {
183
+ const data = pending
184
+ pending = ''
185
+ chain = chain
186
+ .then(() => post('/api/terminal/input', { id, data }))
187
+ .then(
188
+ () => {},
189
+ () => {},
190
+ )
191
+ })
153
192
  pending += d
154
193
  })
155
194
 
156
195
  // ---- the session ---------------------------------------------------------------------------
157
196
  function setStatus(text: string, buttons: [string, () => void][] = []) {
158
197
  status.textContent = text
159
- actions.replaceChildren(...buttons.map(([label, run]) => {
160
- const b = document.createElement('button')
161
- b.type = 'button'
162
- b.textContent = label
163
- b.addEventListener('click', run)
164
- return b
165
- }))
198
+ actions.replaceChildren(
199
+ ...buttons.map(([label, run]) => {
200
+ const b = document.createElement('button')
201
+ b.type = 'button'
202
+ b.textContent = label
203
+ b.addEventListener('click', run)
204
+ return b
205
+ }),
206
+ )
166
207
  }
167
208
 
168
209
  // ---- tabs ----------------------------------------------------------------------------------
169
210
  function drawTabs() {
170
- tabs.replaceChildren(...sessions.map(x => {
171
- const tab = document.createElement('span')
172
- tab.className = 'wb-term-tab'
173
- tab.dataset.id = x.id
174
- tab.classList.toggle('wb-current', x.id === current)
175
- tab.toggleAttribute('data-exited', !x.running)
176
- const name = document.createElement('button')
177
- name.type = 'button'
178
- name.className = 'wb-term-tab-name'
179
- name.textContent = x.label
180
- name.title = x.running ? x.label : `${x.label}: exited (${x.exited})`
181
- name.addEventListener('click', () => select(x.id))
182
- tab.append(name)
183
- const close = document.createElement('button')
184
- close.type = 'button'
185
- close.className = 'wb-term-tab-close'
186
- close.title = 'Close this tab (ends its program)'
187
- close.textContent = '×'
188
- close.addEventListener('click', () => closeTab(x.id))
189
- tab.append(close)
190
- return tab
191
- }))
211
+ tabs.replaceChildren(
212
+ ...sessions.map(x => {
213
+ const tab = document.createElement('span')
214
+ tab.className = 'wb-term-tab'
215
+ tab.dataset.id = x.id
216
+ tab.classList.toggle('wb-current', x.id === current)
217
+ tab.toggleAttribute('data-exited', !x.running)
218
+ const name = document.createElement('button')
219
+ name.type = 'button'
220
+ name.className = 'wb-term-tab-name'
221
+ name.textContent = x.label
222
+ name.title = x.running ? x.label : `${x.label}: exited (${x.exited})`
223
+ name.addEventListener('click', () => select(x.id))
224
+ tab.append(name)
225
+ const close = document.createElement('button')
226
+ close.type = 'button'
227
+ close.className = 'wb-term-tab-close'
228
+ close.title = 'Close this tab (ends its program)'
229
+ close.textContent = '×'
230
+ close.addEventListener('click', () => closeTab(x.id))
231
+ tab.append(close)
232
+ return tab
233
+ }),
234
+ )
192
235
  showStatus()
193
236
  }
194
237
 
@@ -206,12 +249,17 @@ function init(drawer: HTMLElement) {
206
249
  // no tab yet: "+" opens one
207
250
  if (!x) return setStatus('', [])
208
251
  if (x.running) return setStatus('', [])
209
- setStatus(x.exited == null ? 'stopped' : `exited (${x.exited})`, [['Start again', () => start({ id: x.id, restart: true })]])
252
+ setStatus(x.exited == null ? 'stopped' : `exited (${x.exited})`, [
253
+ ['Start again', () => start({ id: x.id, restart: true })],
254
+ ])
210
255
  }
211
256
 
212
257
  function select(id: string | null) {
213
258
  // the tab that shows already: just give it the keyboard back
214
- if (id === current && stream) { if (isOpen()) term.focus(); return }
259
+ if (id === current && stream) {
260
+ if (isOpen()) term.focus()
261
+ return
262
+ }
215
263
  current = id
216
264
  if (id) store.set('wb-terminal-tab', id)
217
265
  drawTabs()
@@ -242,7 +290,9 @@ function init(drawer: HTMLElement) {
242
290
  try {
243
291
  const res = await fetch('/api/terminal/sessions')
244
292
  if (res.ok) ({ sessions } = await res.json())
245
- } catch { /* the server is away: the stream reconnects */ }
293
+ } catch {
294
+ /* the server is away: the stream reconnects */
295
+ }
246
296
  drawTabs()
247
297
  }
248
298
 
@@ -253,7 +303,9 @@ function init(drawer: HTMLElement) {
253
303
  sent = ''
254
304
  if (!current) showStatus()
255
305
  // without a tab too: the host tells it when one appears (started from the command line, say)
256
- stream = new EventSource(`/api/terminal/stream?${current ? `id=${encodeURIComponent(current)}&` : ''}viewer=${viewer}`)
306
+ stream = new EventSource(
307
+ `/api/terminal/stream?${current ? `id=${encodeURIComponent(current)}&` : ''}viewer=${viewer}`,
308
+ )
257
309
  stream.addEventListener('sessions', e => {
258
310
  sessions = JSON.parse((e as MessageEvent).data).sessions
259
311
  // the current tab is gone, or there was none and one appeared: show the last
@@ -297,13 +349,18 @@ function init(drawer: HTMLElement) {
297
349
  stream.addEventListener('exit', e => {
298
350
  const code = JSON.parse((e as MessageEvent).data).code
299
351
  const x = sessions.find(y => y.id === current)
300
- if (x) { x.running = false; x.exited = code }
352
+ if (x) {
353
+ x.running = false
354
+ x.exited = code
355
+ }
301
356
  drawTabs()
302
357
  })
303
358
  }
304
359
 
305
360
  // whether the terminal had the keyboard, for the next page
306
- addEventListener('pagehide', () => store.set('wb-terminal-focus', drawer.contains(document.activeElement) ? '1' : '0'))
361
+ addEventListener('pagehide', () =>
362
+ store.set('wb-terminal-focus', drawer.contains(document.activeElement) ? '1' : '0'),
363
+ )
307
364
 
308
365
  drawTabs()
309
366
  connect()