@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
@@ -15,12 +15,12 @@
15
15
  // The parts are whiteboard-free: server.ts is a request handler, host.ts the process that runs the
16
16
  // sessions, client.ts the drawer in the browser. This file wires them in.
17
17
  import { html, raw } from '../../src/html.ts'
18
- import { packagePath } from '../../src/package.ts'
18
+ import { builtinPublic } from '../../src/package.ts'
19
19
  import { createTerminal, type Sessions, type StartOptions } from './server.ts'
20
20
  import type { CommandContext, Plugin } from '../../src/define.ts'
21
21
 
22
- const CLIENT = packagePath('dist/plugins/terminal/client.js')
23
- const STYLE = packagePath('dist/plugins/terminal/style.css')
22
+ const CLIENT = 'client.js'
23
+ const STYLE = 'style.css'
24
24
 
25
25
  /**
26
26
  * The drawer's markup, written by the server so that it is there when the page first renders and
@@ -29,17 +29,45 @@ const STYLE = packagePath('dist/plugins/terminal/style.css')
29
29
  * render, and each session's screen is in it as HTML, so a page shows it from its first render on;
30
30
  * client.js puts the live terminal in its place.
31
31
  */
32
- const drawer = (state: Sessions, screens: Record<string, string>, client: string) => html`<aside id="wb-terminal" aria-label="Terminal" data-sessions="${JSON.stringify(state)}">
33
- <div class="wb-term-grip" title="drag to resize"></div>
34
- <div class="wb-term-bar"><button type="button" class="wb-term-toggle" title="Toggle the terminal (Ctrl+\`)"><span class="wb-term-chevron"></span>terminal</button><span class="wb-term-status"></span><span class="wb-term-actions"></span><span class="wb-term-tabs">${state.sessions.map(s => html`<button type="button" class="wb-term-tab" data-id="${s.id}">${s.label}</button>`)}</span></div>
35
- <div class="wb-term-screen">${state.sessions.map(s => screens[s.id] && html`<div class="wb-term-placeholder" data-id="${s.id}" aria-hidden="true">${raw(screens[s.id])}</div>`)}</div>
36
- </aside>
37
- <script>try{const t=document.getElementById('wb-terminal'),s=sessionStorage,o=new URLSearchParams(location.search).get('terminal')==='open'||s.getItem('wb-terminal-open')==='1';t.dataset.state=o?'open':'collapsed';const h=+s.getItem('wb-terminal-height');if(h)document.documentElement.style.setProperty('--wb-term-h',h+'px');const tabs=[...t.querySelectorAll('.wb-term-tab')],k=s.getItem('wb-terminal-tab'),a=tabs.find(b=>b.dataset.id===k)??tabs[0];if(a){t.dataset.tab=a.dataset.id;a.classList.add('wb-current');t.querySelector('.wb-term-placeholder[data-id="'+a.dataset.id+'"]')?.classList.add('wb-current')}}catch{}</script>
38
- <script type="module" src="${client}"></script>`
32
+ const drawer = (state: Sessions, screens: Record<string, string>, client: string) =>
33
+ html`<aside id="wb-terminal" aria-label="Terminal" data-sessions="${JSON.stringify(state)}">
34
+ <div class="wb-term-grip" title="drag to resize"></div>
35
+ <div class="wb-term-bar">
36
+ <button type="button" class="wb-term-toggle" title="Toggle the terminal (Ctrl+\`)">
37
+ <span class="wb-term-chevron"></span>terminal</button
38
+ ><span class="wb-term-status"></span><span class="wb-term-actions"></span
39
+ ><span class="wb-term-tabs"
40
+ >${state.sessions.map(s => html`<button type="button" class="wb-term-tab" data-id="${s.id}">${s.label}</button>`)}</span
41
+ >
42
+ </div>
43
+ <div class="wb-term-screen">
44
+ ${state.sessions.map(s => screens[s.id] && html`<div class="wb-term-placeholder" data-id="${s.id}" aria-hidden="true">${raw(screens[s.id])}</div>`)}
45
+ </div>
46
+ </aside>
47
+ <script>
48
+ try {
49
+ const t = document.getElementById('wb-terminal'),
50
+ s = sessionStorage,
51
+ o = new URLSearchParams(location.search).get('terminal') === 'open' || s.getItem('wb-terminal-open') === '1'
52
+ t.dataset.state = o ? 'open' : 'collapsed'
53
+ const h = +s.getItem('wb-terminal-height')
54
+ if (h) document.documentElement.style.setProperty('--wb-term-h', h + 'px')
55
+ const tabs = [...t.querySelectorAll('.wb-term-tab')],
56
+ k = s.getItem('wb-terminal-tab'),
57
+ a = tabs.find(b => b.dataset.id === k) ?? tabs[0]
58
+ if (a) {
59
+ t.dataset.tab = a.dataset.id
60
+ a.classList.add('wb-current')
61
+ t.querySelector('.wb-term-placeholder[data-id="' + a.dataset.id + '"]')?.classList.add('wb-current')
62
+ }
63
+ } catch {}
64
+ </script>
65
+ <script type="module" src="${client}"></script>`
39
66
 
40
67
  export default function terminal(): Plugin {
41
68
  return {
42
69
  name: 'terminal',
70
+ public: builtinPublic('terminal'),
43
71
  // the drawer's look: on every page, since every page can have the drawer
44
72
  style: STYLE,
45
73
  setup(ctx) {
@@ -48,31 +76,57 @@ export default function terminal(): Plugin {
48
76
  return {
49
77
  // all of them run code or show what runs, so all need the project's token
50
78
  routes: {
51
- 'GET /sessions': { description: 'the sessions (the drawer\'s tabs): id, label, whether each runs', auth: true, run: () => term.sessions() },
79
+ 'GET /sessions': {
80
+ description: "the sessions (the drawer's tabs): id, label, whether each runs",
81
+ auth: true,
82
+ run: () => term.sessions(),
83
+ },
52
84
  'POST /start': {
53
- description: 'start a tab: the shell, or program (with its arguments) in it; in session id, a new tab without one; with restart, start it again as it was',
85
+ description:
86
+ 'start a tab: the shell, or program (with its arguments) in it; in session id, a new tab without one; with restart, start it again as it was',
54
87
  auth: true,
55
88
  body: { id: 'string?', program: 'string[]?', restart: 'boolean?' },
56
89
  run: ({ body }) => term.start(body as StartOptions),
57
90
  },
58
- 'POST /input': { description: 'keystrokes for a session, as the terminal sends them', auth: true, body: { id: 'string', data: 'string' }, run: ({ body }) => term.input(body.id as string, body.data as string) },
91
+ 'POST /input': {
92
+ description: 'keystrokes for a session, as the terminal sends them',
93
+ auth: true,
94
+ body: { id: 'string', data: 'string' },
95
+ run: ({ body }) => term.input(body.id as string, body.data as string),
96
+ },
59
97
  'POST /resize': {
60
- description: 'the size that fits the terminal in a page (`viewer`: that drawer); `active`: the reader uses this drawer now, so the session takes its size',
98
+ description:
99
+ 'the size that fits the terminal in a page (`viewer`: that drawer); `active`: the reader uses this drawer now, so the session takes its size',
61
100
  auth: true,
62
101
  body: { id: 'string', viewer: 'string', cols: 'number', rows: 'number', active: 'boolean?' },
63
- run: ({ body }) => term.resize(body.id as string, body.viewer as string, body.cols as number, body.rows as number, !!body.active),
102
+ run: ({ body }) =>
103
+ term.resize(
104
+ body.id as string,
105
+ body.viewer as string,
106
+ body.cols as number,
107
+ body.rows as number,
108
+ !!body.active,
109
+ ),
64
110
  },
65
111
  'GET /stream': {
66
- description: 'the tabs and a session\'s whole screen, then its output as it comes (events sessions, screen, data, size, navigate, exit; none without that session)',
112
+ description:
113
+ "the tabs and a session's whole screen, then its output as it comes (events sessions, screen, data, size, navigate, exit; none without that session)",
67
114
  auth: true,
68
115
  stream: true,
69
116
  query: { id: 'string?', viewer: 'string?' },
70
- run: ({ req, res, query }) => term.stream(req, res!, query.id as string | undefined, query.viewer as string | undefined),
117
+ run: ({ req, res, query }) =>
118
+ term.stream(req, res!, query.id as string | undefined, query.viewer as string | undefined),
119
+ },
120
+ 'POST /close': {
121
+ description: 'end a session and drop its tab',
122
+ auth: true,
123
+ body: { id: 'string' },
124
+ run: ({ body }) => term.close(body.id as string),
71
125
  },
72
- 'POST /close': { description: 'end a session and drop its tab', auth: true, body: { id: 'string' }, run: ({ body }) => term.close(body.id as string) },
73
126
  'POST /stop': { description: 'end every session and their host', auth: true, run: () => term.stop() },
74
127
  'POST /open': {
75
- description: 'show the page at path in the browser tab whose drawer the reader used last, for session id or, without one, of all; how many were shown',
128
+ description:
129
+ 'show the page at path in the browser tab whose drawer the reader used last, for session id or, without one, of all; how many were shown',
76
130
  auth: true,
77
131
  body: { id: 'string?', path: 'string' },
78
132
  run: ({ body }) => term.open(body.id as string | undefined, body.path as string),
@@ -87,7 +141,8 @@ export default function terminal(): Plugin {
87
141
  },
88
142
  commands: {
89
143
  '': {
90
- description: 'print a link that opens the terminal drawer in this browser (it gives the browser the project\'s token); with --new, open a tab with the shell; with a program after --, run it in a new tab',
144
+ description:
145
+ "print a link that opens the terminal drawer in this browser (it gives the browser the project's token); with --new, open a tab with the shell; with a program after --, run it in a new tab",
91
146
  args: '[page]',
92
147
  options: {
93
148
  new: { type: 'boolean?', description: 'open a new tab with the shell' },
@@ -95,29 +150,33 @@ export default function terminal(): Plugin {
95
150
  rest: '<program> [arguments]',
96
151
  async run(ctx) {
97
152
  if (ctx.options.new || ctx.rest.length) {
98
- const body = await call(ctx, 'POST', '/start', { program: ctx.rest }) as { session: string }
153
+ const body = (await call(ctx, 'POST', '/start', { program: ctx.rest })) as { session: string }
99
154
  console.error(`whiteboard: started in tab ${body.session}`)
100
155
  }
101
156
  console.log(await ctx.authLink(`${ctx.pagePath(ctx.positionals[0])}?terminal=open`))
102
157
  },
103
158
  },
104
159
  open: {
105
- description: 'show a page in the browser tab whose drawer the reader used last (from a program in a terminal tab: that tab\'s drawer)',
160
+ description:
161
+ "show a page in the browser tab whose drawer the reader used last (from a program in a terminal tab: that tab's drawer)",
106
162
  args: '<page|file>',
107
163
  async run(ctx) {
108
164
  if (!ctx.positionals[0]) throw new Error('usage: whiteboard terminal open <page|file>')
109
165
  // a program in a tab knows its tab; anything else gets the drawer the reader used last
110
166
  const id = process.env.WHITEBOARD_TERMINAL || undefined
111
167
  const path = ctx.pagePath(ctx.positionals[0])
112
- const { shown } = await call(ctx, 'POST', '/open', { id, path }) as { shown: number }
113
- if (!shown) throw new Error(`no browser shows ${id ? `terminal tab ${id}` : 'the terminal drawer'} right now; the page is at ${await ctx.server()}${path}`)
168
+ const { shown } = (await call(ctx, 'POST', '/open', { id, path })) as { shown: number }
169
+ if (!shown)
170
+ throw new Error(
171
+ `no browser shows ${id ? `terminal tab ${id}` : 'the terminal drawer'} right now; the page is at ${await ctx.server()}${path}`,
172
+ )
114
173
  console.log(`opened ${path} ${id ? `where tab ${id}'s drawer is` : 'where the drawer you used last is'}`)
115
174
  },
116
175
  },
117
176
  stop: {
118
177
  description: 'end every session and their host',
119
178
  async run(ctx) {
120
- const { stopped } = await call(ctx, 'POST', '/stop') as { stopped: boolean }
179
+ const { stopped } = (await call(ctx, 'POST', '/stop')) as { stopped: boolean }
121
180
  console.log(stopped ? 'stopped' : 'no session ran')
122
181
  },
123
182
  },
@@ -0,0 +1,225 @@
1
+ /* The terminal drawer (see terminal.ts). Pages morph into each other on navigation, and the drawer is
2
+ named, so it keeps its place and size while the page around it changes. */
3
+ @view-transition {
4
+ navigation: auto;
5
+ }
6
+
7
+ /* How much of the window the drawer takes at the bottom, for the page to keep clear: its content
8
+ scrolls to above it, and its own fixed elements sit above it (the page's buttons at the bottom).
9
+ Registered as a length so that it computes to pixels a script can read. */
10
+ @property --wb-inset-bottom {
11
+ syntax: '<length>';
12
+ inherits: true;
13
+ initial-value: 0px;
14
+ }
15
+
16
+ :root {
17
+ --wb-term-h: 320px;
18
+ --wb-term-bar: 34px;
19
+ }
20
+ :root:has(body > #wb-terminal) {
21
+ --wb-inset-bottom: var(--wb-term-bar);
22
+ }
23
+ :root:has(body > #wb-terminal[data-state='open']) {
24
+ --wb-inset-bottom: calc(var(--wb-term-bar) + var(--wb-term-h));
25
+ }
26
+
27
+ #wb-terminal {
28
+ view-transition-name: wb-terminal;
29
+ position: fixed;
30
+ left: 0;
31
+ right: 0;
32
+ bottom: 0;
33
+ z-index: var(--layer-top);
34
+ display: flex;
35
+ flex-direction: column;
36
+ background: #0f1115;
37
+ color: #d7dae0;
38
+ border-top: var(--hairline) solid #2a2f3a;
39
+ box-shadow: 0 -6px 24px rgb(0 0 0 / 0.18);
40
+ font:
41
+ 500 12px/1 ui-sans-serif,
42
+ system-ui,
43
+ sans-serif;
44
+ }
45
+ body:has(> #wb-terminal) {
46
+ padding-bottom: var(--wb-inset-bottom);
47
+ }
48
+
49
+ .wb-term-grip {
50
+ position: absolute;
51
+ left: 0;
52
+ right: 0;
53
+ top: -4px;
54
+ height: 8px;
55
+ cursor: ns-resize;
56
+ touch-action: none;
57
+ }
58
+ .wb-term-bar {
59
+ height: var(--wb-term-bar);
60
+ display: flex;
61
+ align-items: center;
62
+ gap: var(--space-xl);
63
+ padding: 0 var(--space-lg) 0 var(--space-sm);
64
+ flex: none;
65
+ }
66
+ .wb-term-bar button {
67
+ font: inherit;
68
+ color: inherit;
69
+ background: transparent;
70
+ border: var(--hairline) solid transparent;
71
+ border-radius: var(--radius-sm);
72
+ padding: var(--space-xs) var(--space-md);
73
+ cursor: pointer;
74
+ }
75
+ .wb-term-bar button:hover {
76
+ background: #1c2029;
77
+ border-color: #2a2f3a;
78
+ }
79
+ .wb-term-toggle {
80
+ display: inline-flex;
81
+ align-items: center;
82
+ gap: var(--space-sm);
83
+ letter-spacing: var(--caps-spacing);
84
+ text-transform: uppercase;
85
+ }
86
+ /* points up while closed (it opens upward), down while open */
87
+ .wb-term-chevron {
88
+ width: 7px;
89
+ height: 7px;
90
+ border: solid currentColor;
91
+ border-width: 0 1.5px 1.5px 0;
92
+ rotate: 45deg;
93
+ translate: 0 -2px;
94
+ transition:
95
+ rotate 0.2s,
96
+ translate 0.2s;
97
+ }
98
+ #wb-terminal[data-state='collapsed'] .wb-term-chevron {
99
+ rotate: -135deg;
100
+ translate: 0 2px;
101
+ }
102
+ .wb-term-status {
103
+ color: #8b93a3;
104
+ flex: 1;
105
+ min-width: 0;
106
+ overflow: hidden;
107
+ text-overflow: ellipsis;
108
+ white-space: nowrap;
109
+ }
110
+ .wb-term-actions {
111
+ display: flex;
112
+ gap: var(--space-xs);
113
+ }
114
+
115
+ /* the tabs: one per session, the current one lit */
116
+ /* the bar: the toggle, what the current tab says (status, actions), then the tabs and "+" at the right */
117
+ .wb-term-tabs {
118
+ display: flex;
119
+ align-items: center;
120
+ gap: var(--space-2xs);
121
+ min-width: 0;
122
+ flex: 0 1 auto;
123
+ overflow-x: auto;
124
+ scrollbar-width: none;
125
+ }
126
+ .wb-term-bar .wb-term-add {
127
+ flex: none;
128
+ }
129
+ .wb-term-tab {
130
+ display: inline-flex;
131
+ align-items: center;
132
+ flex: none;
133
+ border-radius: var(--radius-sm);
134
+ }
135
+ .wb-term-bar .wb-term-tab button {
136
+ padding: var(--space-xs) var(--space-xs) var(--space-xs) var(--space-md);
137
+ }
138
+ .wb-term-bar .wb-term-tab .wb-term-tab-close {
139
+ padding: var(--space-xs) var(--space-sm) var(--space-xs) var(--space-2xs);
140
+ opacity: 0.45;
141
+ }
142
+ .wb-term-bar .wb-term-tab .wb-term-tab-close:hover {
143
+ opacity: 1;
144
+ background: transparent;
145
+ border-color: transparent;
146
+ }
147
+ .wb-term-bar .wb-term-tab button:hover {
148
+ background: transparent;
149
+ border-color: transparent;
150
+ }
151
+ .wb-term-tab:hover {
152
+ background: #1c2029;
153
+ }
154
+ .wb-term-tab.wb-current {
155
+ background: #232836;
156
+ color: #fff;
157
+ }
158
+ .wb-term-tab[data-exited] {
159
+ color: #8b93a3;
160
+ }
161
+ .wb-term-bar .wb-term-add {
162
+ padding: var(--space-2xs) var(--space-md);
163
+ font-size: 15px;
164
+ line-height: 1;
165
+ color: #8b93a3;
166
+ }
167
+ .wb-term-bar .wb-term-add:hover {
168
+ color: #d7dae0;
169
+ }
170
+
171
+ /* content-box: the fit addon reads this height as the room for rows, so the padding must not be in it */
172
+ .wb-term-screen {
173
+ height: calc(var(--wb-term-h) - 10px);
174
+ padding: var(--space-xs) 0 var(--space-sm) var(--space-lg);
175
+ box-sizing: content-box;
176
+ overflow: hidden;
177
+ }
178
+ /* the screen as the server wrote it into the page, over the terminal until that has drawn it */
179
+ .wb-term-screen {
180
+ position: relative;
181
+ }
182
+ .wb-term-placeholder {
183
+ position: absolute;
184
+ inset: 4px 0 6px 10px;
185
+ z-index: 1;
186
+ overflow: hidden;
187
+ background: #0f1115;
188
+ font:
189
+ 13px/1.2 ui-monospace,
190
+ SFMono-Regular,
191
+ Menlo,
192
+ monospace;
193
+ white-space: pre;
194
+ color: #d7dae0;
195
+ }
196
+ .wb-term-placeholder > div {
197
+ height: 1.2em;
198
+ }
199
+ /* the server writes every tab's screen; the current tab's shows */
200
+ .wb-term-placeholder:not(.wb-current) {
201
+ display: none;
202
+ }
203
+ #wb-terminal[data-state='collapsed'] .wb-term-screen {
204
+ height: 0;
205
+ padding: 0;
206
+ visibility: hidden;
207
+ }
208
+
209
+ ::view-transition-group(wb-terminal) {
210
+ animation-duration: 0.22s;
211
+ animation-timing-function: cubic-bezier(0.2, 0.7, 0.2, 1);
212
+ }
213
+ /* opening and closing: the pictures keep their scale and stay anchored at the bar, so the text
214
+ doesn't stretch while the drawer grows */
215
+ ::view-transition-old(wb-terminal),
216
+ ::view-transition-new(wb-terminal) {
217
+ height: 100%;
218
+ object-fit: none;
219
+ object-position: top;
220
+ }
221
+ @media (prefers-reduced-motion: reduce) {
222
+ ::view-transition-group(*) {
223
+ animation: none !important;
224
+ }
225
+ }
@@ -52,7 +52,14 @@ type Reply = Record<string, any>
52
52
  const require = createRequire(import.meta.url)
53
53
  const HOST = fileURLToPath(new URL(`./host${path.extname(fileURLToPath(import.meta.url))}`, import.meta.url))
54
54
 
55
- const hasPty = () => { try { require.resolve('node-pty'); return true } catch { return false } }
55
+ const hasPty = () => {
56
+ try {
57
+ require.resolve('node-pty')
58
+ return true
59
+ } catch {
60
+ return false
61
+ }
62
+ }
56
63
 
57
64
  /**
58
65
  * Where the host listens: `host.sock` in the terminal's folder, or, when that path is too long for
@@ -60,7 +67,9 @@ const hasPty = () => { try { require.resolve('node-pty'); return true } catch {
60
67
  */
61
68
  export function hostSocket(home: string): string {
62
69
  const own = path.join(home, 'host.sock')
63
- return Buffer.byteLength(own) < 100 ? own : path.join('/tmp', `wb-term-${crypto.createHash('sha1').update(home).digest('hex').slice(0, 12)}.sock`)
70
+ return Buffer.byteLength(own) < 100
71
+ ? own
72
+ : path.join('/tmp', `wb-term-${crypto.createHash('sha1').update(home).digest('hex').slice(0, 12)}.sock`)
64
73
  }
65
74
 
66
75
  /** `dir` the folder the sessions run in, `home` where the socket and log go */
@@ -85,10 +94,24 @@ export function createTerminal({ dir, home }: { dir: string; home: string }) {
85
94
  if (!conn) return null
86
95
  return new Promise(resolve => {
87
96
  let buf = ''
88
- const done = (value: Reply | null) => { clearTimeout(timer); conn.destroy(); resolve(value) }
97
+ const done = (value: Reply | null) => {
98
+ clearTimeout(timer)
99
+ conn.destroy()
100
+ resolve(value)
101
+ }
89
102
  const timer = setTimeout(() => done(null), timeout)
90
103
  conn.setEncoding('utf8')
91
- conn.on('data', (c: string) => { buf += c; const nl = buf.indexOf('\n'); if (nl >= 0) { try { done(JSON.parse(buf.slice(0, nl))) } catch { done(null) } } })
104
+ conn.on('data', (c: string) => {
105
+ buf += c
106
+ const nl = buf.indexOf('\n')
107
+ if (nl >= 0) {
108
+ try {
109
+ done(JSON.parse(buf.slice(0, nl)))
110
+ } catch {
111
+ done(null)
112
+ }
113
+ }
114
+ })
92
115
  conn.on('error', () => done(null))
93
116
  conn.on('end', () => done(null))
94
117
  conn.write(JSON.stringify(req) + '\n')
@@ -98,7 +121,12 @@ export function createTerminal({ dir, home }: { dir: string; home: string }) {
98
121
  /** Start the host (detached: it outlives this server) and wait until it answers. */
99
122
  async function startHost(): Promise<boolean> {
100
123
  const out = fs.openSync(log, 'a')
101
- const child = spawn(process.execPath, [HOST, dir, own], { cwd: dir, detached: true, stdio: ['ignore', out, out], env: process.env })
124
+ const child = spawn(process.execPath, [HOST, dir, own], {
125
+ cwd: dir,
126
+ detached: true,
127
+ stdio: ['ignore', out, out],
128
+ env: process.env,
129
+ })
102
130
  child.unref()
103
131
  fs.closeSync(out)
104
132
  for (let i = 0; i < 40; i++) {
@@ -119,7 +147,11 @@ export function createTerminal({ dir, home }: { dir: string; home: string }) {
119
147
  /** The screens as HTML rows by session id, for a page's first render. */
120
148
  async function screens(list: Session[]): Promise<Record<string, string>> {
121
149
  const out: Record<string, string> = {}
122
- await Promise.all(list.map(async s => { out[s.id] = (await ask({ t: 'html', id: s.id }, 300))?.html ?? '' }))
150
+ await Promise.all(
151
+ list.map(async s => {
152
+ out[s.id] = (await ask({ t: 'html', id: s.id }, 300))?.html ?? ''
153
+ }),
154
+ )
123
155
  return out
124
156
  }
125
157
 
@@ -134,7 +166,14 @@ export function createTerminal({ dir, home }: { dir: string; home: string }) {
134
166
  async function start({ id, program = [], restart = false }: StartOptions = {}) {
135
167
  if (!hasPty()) throw failure('the terminal needs node-pty: npm install node-pty')
136
168
  const request = program.length
137
- ? { t: 'start', id, command: shell, args: ['-c', '"$@"; exec "$0" -l', shell, ...program], label: path.basename(program[0]!), restart }
169
+ ? {
170
+ t: 'start',
171
+ id,
172
+ command: shell,
173
+ args: ['-c', '"$@"; exec "$0" -l', shell, ...program],
174
+ label: path.basename(program[0]!),
175
+ restart,
176
+ }
138
177
  : restart && id != null
139
178
  ? { t: 'start', id, restart }
140
179
  : { t: 'start', id, command: shell, args: ['-l'], label: path.basename(shell), restart }
@@ -147,9 +186,13 @@ export function createTerminal({ dir, home }: { dir: string; home: string }) {
147
186
  return { available: true, session: reply.session ?? '1', already: !!reply.already }
148
187
  }
149
188
 
150
- const input = async (id: string, data: string) => { await ask({ t: 'input', id, d: data }) }
189
+ const input = async (id: string, data: string) => {
190
+ await ask({ t: 'input', id, d: data })
191
+ }
151
192
  /** The size that fits drawer `viewer`; `active`: the reader is using that drawer now (see host.ts, Sizes). */
152
- const resize = async (id: string, viewer: string, cols: number, rows: number, active = false) => { await ask({ t: 'resize', id, viewer, cols, rows, active }) }
193
+ const resize = async (id: string, viewer: string, cols: number, rows: number, active = false) => {
194
+ await ask({ t: 'resize', id, viewer, cols, rows, active })
195
+ }
153
196
 
154
197
  /** End one session and drop its tab. */
155
198
  async function close(id: string) {
@@ -185,13 +228,20 @@ export function createTerminal({ dir, home }: { dir: string; home: string }) {
185
228
  try {
186
229
  const { t, ...data } = JSON.parse(line)
187
230
  res.write(`event: ${t}\ndata: ${JSON.stringify(data)}\n\n`)
188
- } catch { /* not a message */ }
231
+ } catch {
232
+ /* not a message */
233
+ }
189
234
  }
190
235
  })
191
236
  // the host went away (stopped, or its program ended and it left): the page shows it as stopped
192
- conn.on('close', () => { if (!res.writableEnded) res.write('event: exit\ndata: {"code":null}\n\n') })
237
+ conn.on('close', () => {
238
+ if (!res.writableEnded) res.write('event: exit\ndata: {"code":null}\n\n')
239
+ })
193
240
  conn.on('error', () => {})
194
- req.on('close', () => { clearInterval(ping); conn.destroy() })
241
+ req.on('close', () => {
242
+ clearInterval(ping)
243
+ conn.destroy()
244
+ })
195
245
  conn.write(JSON.stringify({ t: 'attach', id, viewer }) + '\n')
196
246
  }
197
247
 
@@ -205,7 +255,8 @@ export function createTerminal({ dir, home }: { dir: string; home: string }) {
205
255
  * last: for session `id`, or without one, of all sessions.
206
256
  */
207
257
  async function open(id: string | undefined, path: string) {
208
- if (!path.startsWith('/') || path.startsWith('//')) throw failure('open takes a path on this server, like /plan', 400)
258
+ if (!path.startsWith('/') || path.startsWith('//'))
259
+ throw failure('open takes a path on this server, like /plan', 400)
209
260
  const reply = await ask({ t: 'open', id, path })
210
261
  if (!reply) throw failure('no terminal host runs', 404)
211
262
  return { shown: Number(reply.shown ?? 0) }
@@ -20,9 +20,16 @@ export interface Sizes {
20
20
  * A drawer reports the size that fits it; `used`: the reader uses it now. Returns the size the
21
21
  * session should have: its own when the drawer is (now) the active one, else the session's as it is.
22
22
  */
23
- export function report(s: Sizes, viewer: string, cols: number, rows: number, used: boolean, now = Date.now()): { cols: number; rows: number } {
23
+ export function report(
24
+ s: Sizes,
25
+ viewer: string,
26
+ cols: number,
27
+ rows: number,
28
+ used: boolean,
29
+ now = Date.now(),
30
+ ): { cols: number; rows: number } {
24
31
  const known = s.viewers.get(viewer)
25
- s.viewers.set(viewer, { cols, rows, used: used ? now : known?.used ?? 0 })
32
+ s.viewers.set(viewer, { cols, rows, used: used ? now : (known?.used ?? 0) })
26
33
  if (used || !s.active || !s.viewers.has(s.active)) s.active = viewer
27
34
  return s.active === viewer ? { cols, rows } : { cols: s.cols, rows: s.rows }
28
35
  }
@@ -40,7 +47,9 @@ export function leave(s: Sizes, viewer: string): boolean {
40
47
  */
41
48
  export function handOver(s: Sizes, viewer: string): { cols: number; rows: number } | null {
42
49
  if (s.active !== viewer || s.viewers.has(viewer)) return null
43
- const next = [...s.viewers].sort((a, b) => b[1].used - a[1].used)[0]
50
+ // the one used last: the first of them, as a stable sort by `used` would give
51
+ let next: [string, { cols: number; rows: number; used: number }] | undefined
52
+ for (const viewer of s.viewers) if (!next || viewer[1].used > next[1].used) next = viewer
44
53
  s.active = next?.[0] ?? null
45
54
  return next ? { cols: next[1].cols, rows: next[1].rows } : null
46
55
  }
@@ -54,7 +63,10 @@ export function lastUsed<S extends Sizes>(sessions: S[]): S | undefined {
54
63
  let at = -1
55
64
  for (const s of sessions) {
56
65
  const viewer = s.active ? s.viewers.get(s.active) : undefined
57
- if (viewer && viewer.used > at) { best = s; at = viewer.used }
66
+ if (viewer && viewer.used > at) {
67
+ best = s
68
+ at = viewer.used
69
+ }
58
70
  }
59
71
  return best
60
72
  }
@@ -9,14 +9,32 @@ import toc from '@bigmistqke/whiteboard/toc'
9
9
  export default defineConfig({ plugins: [toc()] })
10
10
  ```
11
11
 
12
- A page has it when its frontmatter says `toc: true`:
12
+ A page has it when its frontmatter asks, under `plugins:` (where every
13
+ plugin's settings for a page go, by the plugin's name):
13
14
 
14
15
  ```markdown
15
16
  ---
16
- toc: true
17
+ plugins:
18
+ toc: true
17
19
  ---
18
20
  # A long page
19
21
  ```
20
22
 
21
23
  To have it on every page, `toc({ always: true })`; a page then goes without
22
- with `toc: false`.
24
+ with `toc: false` there.
25
+
26
+ The panel fits its items, between a minimum and a maximum width (160px and
27
+ 320px by default). A project sets its own in the options, and a page in its
28
+ frontmatter, which is then also how it asks for the contents:
29
+
30
+ ```ts
31
+ toc({ minWidth: 180, maxWidth: '24rem' }) // pixels, or a CSS length
32
+ ```
33
+
34
+ ```markdown
35
+ ---
36
+ plugins:
37
+ toc:
38
+ maxWidth: 240px
39
+ ---
40
+ ```