@bigmistqke/whiteboard 0.3.1 → 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 (153) 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/index.js +4 -3
  32. package/dist/plugins/toc/public/client.js +1 -0
  33. package/dist/plugins/toc/public/style.css +93 -0
  34. package/dist/plugins/window/README.md +29 -0
  35. package/dist/plugins/window/index.js +64 -0
  36. package/dist/solid/index.js +14 -11
  37. package/dist/src/client/page/base.css +1078 -199
  38. package/dist/src/client/page/main.js +174 -33
  39. package/dist/src/loader.js +7 -2
  40. package/dist/src/package.js +3 -6
  41. package/dist/src/pages/blocks.js +8 -13
  42. package/dist/src/pages/markdown.js +1 -1
  43. package/dist/src/pages/render.js +74 -15
  44. package/dist/src/pages/window.js +30 -0
  45. package/dist/src/public.js +24 -0
  46. package/dist/src/server.js +36 -14
  47. package/package.json +3 -1
  48. package/plugins/callout/index.ts +3 -1
  49. package/plugins/callout/public/style.css +30 -0
  50. package/plugins/chat/autosize.ts +43 -9
  51. package/plugins/chat/client.tsx +22 -5
  52. package/plugins/chat/index.ts +22 -8
  53. package/plugins/chat/public/style.css +98 -0
  54. package/plugins/claude-code/index.ts +49 -14
  55. package/plugins/code/diff.ts +28 -8
  56. package/plugins/code/index.ts +30 -20
  57. package/plugins/code/public/style.css +68 -0
  58. package/plugins/comments/client.ts +139 -71
  59. package/plugins/comments/index.ts +9 -7
  60. package/plugins/comments/public/style.css +185 -0
  61. package/plugins/details/index.ts +7 -2
  62. package/plugins/details/public/style.css +7 -0
  63. package/plugins/forge/index.ts +16 -3
  64. package/plugins/form/index.ts +75 -27
  65. package/plugins/form/public/style.css +126 -0
  66. package/plugins/gallery/client.tsx +9 -3
  67. package/plugins/gallery/index.ts +31 -9
  68. package/plugins/gallery/public/style.css +90 -0
  69. package/plugins/grid/index.ts +19 -5
  70. package/plugins/grid/public/style.css +71 -0
  71. package/plugins/iframe/index.ts +20 -23
  72. package/plugins/iframe/public/style.css +13 -0
  73. package/plugins/index.ts +16 -1
  74. package/plugins/mermaid/index.ts +3 -1
  75. package/plugins/mermaid/{style.css → public/style.css} +7 -2
  76. package/plugins/terminal/client.ts +105 -48
  77. package/plugins/terminal/host.ts +131 -29
  78. package/plugins/terminal/index.ts +84 -25
  79. package/plugins/terminal/public/style.css +225 -0
  80. package/plugins/terminal/server.ts +64 -13
  81. package/plugins/terminal/sizes.ts +13 -3
  82. package/plugins/toc/client.ts +45 -26
  83. package/plugins/toc/index.ts +9 -6
  84. package/plugins/toc/public/style.css +93 -0
  85. package/plugins/window/README.md +29 -0
  86. package/plugins/window/index.ts +85 -0
  87. package/skills/whiteboard/SKILL.md +3 -1
  88. package/solid/index.tsx +24 -9
  89. package/src/auth.ts +25 -7
  90. package/src/client/forms.ts +74 -28
  91. package/src/client/markdown.ts +15 -4
  92. package/src/client/page/base.css +1078 -199
  93. package/src/client/page/elsewhere.ts +32 -15
  94. package/src/client/page/fresh.ts +91 -23
  95. package/src/client/page/hold.ts +11 -2
  96. package/src/client/page/live.ts +10 -6
  97. package/src/client/page/main.ts +106 -36
  98. package/src/client/page/orphans.ts +25 -10
  99. package/src/client/page/sort.ts +14 -4
  100. package/src/client/page/sticky.ts +11 -3
  101. package/src/client/page/theme.ts +11 -7
  102. package/src/client/page/waiting.ts +141 -34
  103. package/src/client/page/window.ts +40 -0
  104. package/src/client/reactive.ts +19 -0
  105. package/src/client/read.ts +17 -10
  106. package/src/client/runtime.ts +130 -35
  107. package/src/client/scroll.ts +14 -4
  108. package/src/client/toast.ts +19 -5
  109. package/src/config.ts +20 -5
  110. package/src/define.ts +65 -25
  111. package/src/events.ts +111 -24
  112. package/src/html.ts +6 -2
  113. package/src/icons.ts +4 -2
  114. package/src/load.ts +10 -2
  115. package/src/loader.ts +75 -11
  116. package/src/package.ts +9 -8
  117. package/src/pages/blocks.ts +20 -14
  118. package/src/pages/markdown.ts +113 -34
  119. package/src/pages/render.ts +199 -39
  120. package/src/pages/window.ts +71 -0
  121. package/src/plugins.ts +90 -24
  122. package/src/public.ts +39 -0
  123. package/src/running.ts +8 -2
  124. package/src/serve.ts +29 -7
  125. package/src/server.ts +348 -107
  126. package/src/status.ts +15 -9
  127. package/dist/plugins/callout/style.css +0 -12
  128. package/dist/plugins/chat/style.css +0 -24
  129. package/dist/plugins/code/style.css +0 -29
  130. package/dist/plugins/comments/client.js +0 -10
  131. package/dist/plugins/comments/style.css +0 -40
  132. package/dist/plugins/details/style.css +0 -3
  133. package/dist/plugins/form/style.css +0 -44
  134. package/dist/plugins/gallery/client.js +0 -1
  135. package/dist/plugins/gallery/style.css +0 -27
  136. package/dist/plugins/grid/style.css +0 -25
  137. package/dist/plugins/iframe/client.js +0 -1
  138. package/dist/plugins/iframe/style.css +0 -29
  139. package/dist/plugins/toc/client.js +0 -1
  140. package/dist/plugins/toc/style.css +0 -19
  141. package/plugins/callout/style.css +0 -12
  142. package/plugins/chat/style.css +0 -24
  143. package/plugins/code/style.css +0 -29
  144. package/plugins/comments/style.css +0 -40
  145. package/plugins/details/style.css +0 -3
  146. package/plugins/form/style.css +0 -44
  147. package/plugins/gallery/style.css +0 -27
  148. package/plugins/grid/style.css +0 -25
  149. package/plugins/iframe/client.ts +0 -46
  150. package/plugins/iframe/style.css +0 -29
  151. package/plugins/terminal/style.css +0 -71
  152. package/plugins/toc/style.css +0 -19
  153. /package/dist/plugins/terminal/{client.js → public/client.js} +0 -0
@@ -286,72 +286,226 @@
286
286
 
287
287
  /* The terminal drawer (see terminal.ts). Pages morph into each other on navigation, and the drawer is
288
288
  named, so it keeps its place and size while the page around it changes. */
289
- @view-transition { navigation: auto; }
289
+ @view-transition {
290
+ navigation: auto;
291
+ }
290
292
 
291
293
  /* How much of the window the drawer takes at the bottom, for the page to keep clear: its content
292
294
  scrolls to above it, and its own fixed elements sit above it (the page's buttons at the bottom).
293
295
  Registered as a length so that it computes to pixels a script can read. */
294
- @property --wb-inset-bottom { syntax: '<length>'; inherits: true; initial-value: 0px; }
296
+ @property --wb-inset-bottom {
297
+ syntax: '<length>';
298
+ inherits: true;
299
+ initial-value: 0px;
300
+ }
295
301
 
296
- :root { --wb-term-h: 320px; --wb-term-bar: 34px; }
297
- :root:has(body > #wb-terminal) { --wb-inset-bottom: var(--wb-term-bar); }
298
- :root:has(body > #wb-terminal[data-state=open]) { --wb-inset-bottom: calc(var(--wb-term-bar) + var(--wb-term-h)); }
302
+ :root {
303
+ --wb-term-h: 320px;
304
+ --wb-term-bar: 34px;
305
+ }
306
+ :root:has(body > #wb-terminal) {
307
+ --wb-inset-bottom: var(--wb-term-bar);
308
+ }
309
+ :root:has(body > #wb-terminal[data-state='open']) {
310
+ --wb-inset-bottom: calc(var(--wb-term-bar) + var(--wb-term-h));
311
+ }
299
312
 
300
313
  #wb-terminal {
301
314
  view-transition-name: wb-terminal;
302
- position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
303
- display: flex; flex-direction: column;
304
- background: #0f1115; color: #d7dae0;
305
- border-top: 1px solid #2a2f3a;
306
- box-shadow: 0 -6px 24px rgb(0 0 0 / .18);
307
- font: 500 12px/1 ui-sans-serif, system-ui, sans-serif;
315
+ position: fixed;
316
+ left: 0;
317
+ right: 0;
318
+ bottom: 0;
319
+ z-index: var(--layer-top);
320
+ display: flex;
321
+ flex-direction: column;
322
+ background: #0f1115;
323
+ color: #d7dae0;
324
+ border-top: var(--hairline) solid #2a2f3a;
325
+ box-shadow: 0 -6px 24px rgb(0 0 0 / 0.18);
326
+ font:
327
+ 500 12px/1 ui-sans-serif,
328
+ system-ui,
329
+ sans-serif;
330
+ }
331
+ body:has(> #wb-terminal) {
332
+ padding-bottom: var(--wb-inset-bottom);
333
+ }
334
+
335
+ .wb-term-grip {
336
+ position: absolute;
337
+ left: 0;
338
+ right: 0;
339
+ top: -4px;
340
+ height: 8px;
341
+ cursor: ns-resize;
342
+ touch-action: none;
343
+ }
344
+ .wb-term-bar {
345
+ height: var(--wb-term-bar);
346
+ display: flex;
347
+ align-items: center;
348
+ gap: var(--space-xl);
349
+ padding: 0 var(--space-lg) 0 var(--space-sm);
350
+ flex: none;
308
351
  }
309
- body:has(> #wb-terminal) { padding-bottom: var(--wb-inset-bottom); }
310
-
311
- .wb-term-grip { position: absolute; left: 0; right: 0; top: -4px; height: 8px; cursor: ns-resize; touch-action: none; }
312
- .wb-term-bar { height: var(--wb-term-bar); display: flex; align-items: center; gap: 12px; padding: 0 10px 0 6px; flex: none; }
313
352
  .wb-term-bar button {
314
- font: inherit; color: inherit; background: transparent; border: 1px solid transparent; border-radius: 5px;
315
- padding: 5px 8px; cursor: pointer;
353
+ font: inherit;
354
+ color: inherit;
355
+ background: transparent;
356
+ border: var(--hairline) solid transparent;
357
+ border-radius: var(--radius-sm);
358
+ padding: var(--space-xs) var(--space-md);
359
+ cursor: pointer;
360
+ }
361
+ .wb-term-bar button:hover {
362
+ background: #1c2029;
363
+ border-color: #2a2f3a;
364
+ }
365
+ .wb-term-toggle {
366
+ display: inline-flex;
367
+ align-items: center;
368
+ gap: var(--space-sm);
369
+ letter-spacing: var(--caps-spacing);
370
+ text-transform: uppercase;
316
371
  }
317
- .wb-term-bar button:hover { background: #1c2029; border-color: #2a2f3a; }
318
- .wb-term-toggle { display: inline-flex; align-items: center; gap: 7px; letter-spacing: .04em; text-transform: uppercase; }
319
372
  /* points up while closed (it opens upward), down while open */
320
- .wb-term-chevron { width: 7px; height: 7px; border: solid currentColor; border-width: 0 1.5px 1.5px 0; rotate: 45deg; translate: 0 -2px; transition: rotate .2s, translate .2s; }
321
- #wb-terminal[data-state=collapsed] .wb-term-chevron { rotate: -135deg; translate: 0 2px; }
322
- .wb-term-status { color: #8b93a3; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
323
- .wb-term-actions { display: flex; gap: 4px; }
373
+ .wb-term-chevron {
374
+ width: 7px;
375
+ height: 7px;
376
+ border: solid currentColor;
377
+ border-width: 0 1.5px 1.5px 0;
378
+ rotate: 45deg;
379
+ translate: 0 -2px;
380
+ transition:
381
+ rotate 0.2s,
382
+ translate 0.2s;
383
+ }
384
+ #wb-terminal[data-state='collapsed'] .wb-term-chevron {
385
+ rotate: -135deg;
386
+ translate: 0 2px;
387
+ }
388
+ .wb-term-status {
389
+ color: #8b93a3;
390
+ flex: 1;
391
+ min-width: 0;
392
+ overflow: hidden;
393
+ text-overflow: ellipsis;
394
+ white-space: nowrap;
395
+ }
396
+ .wb-term-actions {
397
+ display: flex;
398
+ gap: var(--space-xs);
399
+ }
324
400
 
325
401
  /* the tabs: one per session, the current one lit */
326
402
  /* the bar: the toggle, what the current tab says (status, actions), then the tabs and "+" at the right */
327
- .wb-term-tabs { display: flex; align-items: center; gap: 2px; min-width: 0; flex: 0 1 auto; overflow-x: auto; scrollbar-width: none; }
328
- .wb-term-bar .wb-term-add { flex: none; }
329
- .wb-term-tab { display: inline-flex; align-items: center; flex: none; border-radius: 5px; }
330
- .wb-term-bar .wb-term-tab button { padding: 5px 4px 5px 8px; }
331
- .wb-term-bar .wb-term-tab .wb-term-tab-close { padding: 5px 7px 5px 3px; opacity: .45; }
332
- .wb-term-bar .wb-term-tab .wb-term-tab-close:hover { opacity: 1; background: transparent; border-color: transparent; }
333
- .wb-term-bar .wb-term-tab button:hover { background: transparent; border-color: transparent; }
334
- .wb-term-tab:hover { background: #1c2029; }
335
- .wb-term-tab.wb-current { background: #232836; color: #fff; }
336
- .wb-term-tab[data-exited] { color: #8b93a3; }
337
- .wb-term-bar .wb-term-add { padding: 3px 8px; font-size: 15px; line-height: 1; color: #8b93a3; }
338
- .wb-term-bar .wb-term-add:hover { color: #d7dae0; }
403
+ .wb-term-tabs {
404
+ display: flex;
405
+ align-items: center;
406
+ gap: var(--space-2xs);
407
+ min-width: 0;
408
+ flex: 0 1 auto;
409
+ overflow-x: auto;
410
+ scrollbar-width: none;
411
+ }
412
+ .wb-term-bar .wb-term-add {
413
+ flex: none;
414
+ }
415
+ .wb-term-tab {
416
+ display: inline-flex;
417
+ align-items: center;
418
+ flex: none;
419
+ border-radius: var(--radius-sm);
420
+ }
421
+ .wb-term-bar .wb-term-tab button {
422
+ padding: var(--space-xs) var(--space-xs) var(--space-xs) var(--space-md);
423
+ }
424
+ .wb-term-bar .wb-term-tab .wb-term-tab-close {
425
+ padding: var(--space-xs) var(--space-sm) var(--space-xs) var(--space-2xs);
426
+ opacity: 0.45;
427
+ }
428
+ .wb-term-bar .wb-term-tab .wb-term-tab-close:hover {
429
+ opacity: 1;
430
+ background: transparent;
431
+ border-color: transparent;
432
+ }
433
+ .wb-term-bar .wb-term-tab button:hover {
434
+ background: transparent;
435
+ border-color: transparent;
436
+ }
437
+ .wb-term-tab:hover {
438
+ background: #1c2029;
439
+ }
440
+ .wb-term-tab.wb-current {
441
+ background: #232836;
442
+ color: #fff;
443
+ }
444
+ .wb-term-tab[data-exited] {
445
+ color: #8b93a3;
446
+ }
447
+ .wb-term-bar .wb-term-add {
448
+ padding: var(--space-2xs) var(--space-md);
449
+ font-size: 15px;
450
+ line-height: 1;
451
+ color: #8b93a3;
452
+ }
453
+ .wb-term-bar .wb-term-add:hover {
454
+ color: #d7dae0;
455
+ }
339
456
 
340
457
  /* content-box: the fit addon reads this height as the room for rows, so the padding must not be in it */
341
- .wb-term-screen { height: calc(var(--wb-term-h) - 10px); padding: 4px 0 6px 10px; box-sizing: content-box; overflow: hidden; }
458
+ .wb-term-screen {
459
+ height: calc(var(--wb-term-h) - 10px);
460
+ padding: var(--space-xs) 0 var(--space-sm) var(--space-lg);
461
+ box-sizing: content-box;
462
+ overflow: hidden;
463
+ }
342
464
  /* the screen as the server wrote it into the page, over the terminal until that has drawn it */
343
- .wb-term-screen { position: relative; }
465
+ .wb-term-screen {
466
+ position: relative;
467
+ }
344
468
  .wb-term-placeholder {
345
- position: absolute; inset: 4px 0 6px 10px; z-index: 1; overflow: hidden; background: #0f1115;
346
- font: 13px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre; color: #d7dae0;
469
+ position: absolute;
470
+ inset: 4px 0 6px 10px;
471
+ z-index: 1;
472
+ overflow: hidden;
473
+ background: #0f1115;
474
+ font:
475
+ 13px/1.2 ui-monospace,
476
+ SFMono-Regular,
477
+ Menlo,
478
+ monospace;
479
+ white-space: pre;
480
+ color: #d7dae0;
481
+ }
482
+ .wb-term-placeholder > div {
483
+ height: 1.2em;
347
484
  }
348
- .wb-term-placeholder > div { height: 1.2em; }
349
485
  /* the server writes every tab's screen; the current tab's shows */
350
- .wb-term-placeholder:not(.wb-current) { display: none; }
351
- #wb-terminal[data-state=collapsed] .wb-term-screen { height: 0; padding: 0; visibility: hidden; }
486
+ .wb-term-placeholder:not(.wb-current) {
487
+ display: none;
488
+ }
489
+ #wb-terminal[data-state='collapsed'] .wb-term-screen {
490
+ height: 0;
491
+ padding: 0;
492
+ visibility: hidden;
493
+ }
352
494
 
353
- ::view-transition-group(wb-terminal) { animation-duration: .22s; animation-timing-function: cubic-bezier(.2, .7, .2, 1); }
495
+ ::view-transition-group(wb-terminal) {
496
+ animation-duration: 0.22s;
497
+ animation-timing-function: cubic-bezier(0.2, 0.7, 0.2, 1);
498
+ }
354
499
  /* opening and closing: the pictures keep their scale and stay anchored at the bar, so the text
355
500
  doesn't stretch while the drawer grows */
356
- ::view-transition-old(wb-terminal), ::view-transition-new(wb-terminal) { height: 100%; object-fit: none; object-position: top; }
357
- @media (prefers-reduced-motion: reduce) { ::view-transition-group(*) { animation: none !important; } }
501
+ ::view-transition-old(wb-terminal),
502
+ ::view-transition-new(wb-terminal) {
503
+ height: 100%;
504
+ object-fit: none;
505
+ object-position: top;
506
+ }
507
+ @media (prefers-reduced-motion: reduce) {
508
+ ::view-transition-group(*) {
509
+ animation: none !important;
510
+ }
511
+ }
@@ -1,4 +1,4 @@
1
- import { packagePath } from "../../src/package.js";
1
+ import { builtinPublic } from "../../src/package.js";
2
2
  // plugins/toc/index.ts
3
3
  const DOCS = `## Table of contents
4
4
 
@@ -10,9 +10,10 @@ function toc(options = {}) {
10
10
  return {
11
11
  name: "toc",
12
12
  docs: () => options.always ? DOCS + "\nIn this project every page has it; a page without it says `toc: false` in its frontmatter.\n" : DOCS + "\nA page has it when its frontmatter says `toc: true`:\n\n```markdown\n---\ntoc: true\n---\n# A long page\n```\n",
13
- style: packagePath("dist/plugins/toc/style.css"),
13
+ public: builtinPublic("toc"),
14
+ style: "style.css",
14
15
  setup: () => ({
15
- client: packagePath("dist/plugins/toc/client.js"),
16
+ client: "client.js",
16
17
  shell: () => ({ head: `<meta name="wb-toc" content="${options.always ? "always" : "opt-in"}">` })
17
18
  })
18
19
  };
@@ -0,0 +1 @@
1
+ const e=document.createElement(`nav`);e.className=`wb-toc`,e.setAttribute(`aria-label`,`Contents`);const t=document.createElement(`ol`);e.append(t);const n=document.createElement(`button`);n.type=`button`,n.className=`wb-toc-toggle`,n.title=n.ariaLabel=`Contents`,n.innerHTML=`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"><path d="M2.5 4h11M2.5 8h11M2.5 12h7"/></svg>`;let r,i,a=[];const o=()=>document.querySelector(`.wb-nav`)?.getBoundingClientRect().height??0;function s(){return r.getBoundingClientRect().left>=230}let c;function l(){let e=c.frontmatter().toc?.trim().toLowerCase();return document.querySelector(`meta[name=wb-toc]`)?.getAttribute(`content`)===`always`?e!==`false`:e===`true`}function u(){a=l()?[...r.querySelectorAll(`:scope > h2, :scope > h3`)]:[];let i=0,o=0;t.replaceChildren(...a.map((e,t)=>{let n=e.tagName===`H2`?`${++i}`:`${i}.${++o}`;e.tagName===`H2`&&(o=0);let r=document.createElement(`li`);r.dataset.level=e.tagName===`H2`?`2`:`3`;let a=document.createElement(`a`);return a.href=`#`,a.dataset.index=String(t),a.innerHTML=`<span class="wb-toc-number"></span><span class="wb-toc-text"></span>`,a.querySelector(`.wb-toc-number`).textContent=n,a.querySelector(`.wb-toc-text`).textContent=e.textContent??``,r.append(a),r}));let c=a.length>1;n.hidden=!c||s(),e.hidden=!c||!s()&&!e.classList.contains(`wb-toc-open`),e.classList.toggle(`wb-toc-docked`,s()),f(),p()}function d(e){let t=-1;for(let n=0;n<a.length&&a[n].compareDocumentPosition(e)&Node.DOCUMENT_POSITION_FOLLOWING;n++)t=n;return t}function f(){let e=/* @__PURE__ */ new Set,n=new Set(i.unread().map(e=>e.id)),o=[...r.querySelectorAll(`form[data-wb-open]`),...[...r.querySelectorAll(`[data-wb-message]`)].filter(e=>n.has(e.dataset.wbMessage))];for(let t of o)e.add(d(t));for(let t of document.querySelectorAll(`[data-wb-holds]`)){if(!t.dataset.wbHolds.split(` `).some(e=>n.has(e)))continue;let r=t.getBoundingClientRect().top,i=-1;a.forEach((e,t)=>{e.getBoundingClientRect().top<=r&&(i=t)}),e.add(i)}t.querySelectorAll(`a`).forEach((t,n)=>t.toggleAttribute(`data-waiting`,e.has(n)))}function p(){let e=o()+40,n=0;a.forEach((t,r)=>{t.getBoundingClientRect().top<=e&&(n=r)}),t.querySelectorAll(`a`).forEach((e,t)=>e.toggleAttribute(`aria-current`,t===n&&a.length>0))}function m(t){let n=a[t];n&&(scrollTo({top:Math.max(0,scrollY+n.getBoundingClientRect().top-o()-12),behavior:`smooth`}),s()||(e.classList.remove(`wb-toc-open`),e.hidden=!0))}const h=(a,o,s)=>{if(o.kind!==`page`&&o.kind!==`file`)return;c=o,r=a.querySelector(`#wb-main`)??a,i=s,document.body.append(e),a.querySelector(`.wb-nav .wb-theme`)?.before(n),t.addEventListener(`click`,e=>{let t=e.target.closest(`a[data-index]`);t&&(e.preventDefault(),m(Number(t.dataset.index)))}),n.addEventListener(`click`,()=>{let t=!e.classList.contains(`wb-toc-open`);e.classList.toggle(`wb-toc-open`,t),e.hidden=!t}),document.addEventListener(`keydown`,t=>{t.key===`Escape`&&e.classList.contains(`wb-toc-open`)&&n.click()});let l=0,d=e=>()=>{cancelAnimationFrame(l),l=requestAnimationFrame(e)};addEventListener(`scroll`,d(p),{passive:!0}),addEventListener(`resize`,d(u)),i.onRendered(u),o.frontmatter.on(u),i.forms.on(()=>f()),i.events.on(()=>requestAnimationFrame(f)),u()};export{h as default};
@@ -0,0 +1,93 @@
1
+ /* the table of contents (client.ts): in the margin left of the text, or opened from the header */
2
+ .wb-toc {
3
+ position: fixed;
4
+ z-index: var(--layer-aside);
5
+ font: var(--ui-small)/var(--ui-line-height) var(--sans, sans-serif);
6
+ }
7
+ .wb-toc[hidden],
8
+ .wb-toc-toggle[hidden] {
9
+ display: none;
10
+ }
11
+ .wb-toc-docked {
12
+ top: 72px;
13
+ left: max(16px, calc((100vw - var(--measure, 680px)) / 2 - 250px));
14
+ width: 210px;
15
+ max-height: calc(100vh - 120px - var(--wb-inset-bottom, 0px));
16
+ overflow: auto;
17
+ }
18
+ .wb-toc-open:not(.wb-toc-docked) {
19
+ top: 52px;
20
+ left: 16px;
21
+ width: min(300px, 100vw - 32px);
22
+ max-height: calc(100vh - 100px - var(--wb-inset-bottom, 0px));
23
+ overflow: auto;
24
+ padding: var(--space-sm);
25
+ background: var(--bg, Canvas);
26
+ border: var(--hairline) solid var(--border, #e3e5e9);
27
+ border-radius: var(--radius);
28
+ box-shadow: var(--shadow-pop);
29
+ }
30
+ .wb-toc ol {
31
+ list-style: none;
32
+ margin: 0;
33
+ padding: 0;
34
+ }
35
+ .wb-toc li[data-level='3'] {
36
+ padding-left: var(--space-xl);
37
+ }
38
+ .wb-toc a {
39
+ display: flex;
40
+ gap: var(--space-md);
41
+ align-items: baseline;
42
+ padding: var(--space-2xs) var(--space-md);
43
+ border-radius: var(--radius-sm);
44
+ color: var(--muted, #696e76);
45
+ text-decoration: none;
46
+ border-left: 2px solid transparent;
47
+ }
48
+ .wb-toc a:hover {
49
+ color: var(--text, CanvasText);
50
+ background: color-mix(in srgb, var(--text, CanvasText) var(--tint-faint), transparent);
51
+ }
52
+ .wb-toc a[aria-current] {
53
+ color: var(--text, CanvasText);
54
+ border-left-color: var(--accent, #1d5bbf);
55
+ font-weight: var(--weight-strong);
56
+ }
57
+ .wb-toc-number {
58
+ font-variant-numeric: tabular-nums;
59
+ opacity: 0.7;
60
+ flex: none;
61
+ }
62
+ .wb-toc-text {
63
+ overflow: hidden;
64
+ text-overflow: ellipsis;
65
+ }
66
+ /* something waits for the reader in this section */
67
+ .wb-toc a[data-waiting]::after {
68
+ content: '';
69
+ flex: none;
70
+ width: 7px;
71
+ height: 7px;
72
+ margin-left: auto;
73
+ align-self: center;
74
+ border-radius: 50%;
75
+ background: var(--accent, #1d5bbf);
76
+ }
77
+ .wb-toc-toggle {
78
+ flex: none;
79
+ display: inline-grid;
80
+ place-items: center;
81
+ height: 24px;
82
+ box-sizing: border-box;
83
+ padding: 0 var(--space-sm);
84
+ border-radius: var(--radius-pill);
85
+ border: var(--hairline) solid var(--border, #e3e5e9);
86
+ background: none;
87
+ color: var(--muted, #696e76);
88
+ cursor: pointer;
89
+ }
90
+ .wb-toc-toggle:hover {
91
+ color: var(--text, CanvasText);
92
+ border-color: var(--muted, #696e76);
93
+ }
@@ -0,0 +1,29 @@
1
+ Windows: a header with a label, a button that fills the browser window with
2
+ what it shows (the same button, or Esc, puts it back), and one that opens it on
3
+ its own. `bare` leaves the header out; `wide` makes it wider than the text
4
+ column; `height` (pixels or a CSS length) fixes its height, scrolling inside.
5
+
6
+ **One image or video**, its label the title, ↗ opening the file:
7
+
8
+ ```markdown
9
+ ::image[The new onboarding]{src="onboarding.png"}
10
+
11
+ ::video[The bug, recorded]{src="bug.mp4" loop muted poster="bug.png"}
12
+ ```
13
+
14
+ A video has its controls; `loop`, `autoplay` (which starts it muted, as
15
+ browsers require) and `poster` are as for a `<video>`. A plain markdown image,
16
+ `![…](shot.png)`, stays an image without a window.
17
+
18
+ **Any markdown**, in `:::window`: a diagram, a table, a screenshot with words
19
+ under it. When it holds one image or video, ↗ opens that file.
20
+
21
+ ````markdown
22
+ :::window[How a page is served]{wide}
23
+ ```mermaid
24
+ graph LR; file --> server --> browser
25
+ ```
26
+ :::
27
+ ````
28
+
29
+ An iframe (`::iframe`) is a window around another page.
@@ -0,0 +1,64 @@
1
+ import fs from "node:fs";
2
+ import { definePlugin, html, raw, windowFrame } from "@bigmistqke/whiteboard";
3
+ // plugins/window/index.ts
4
+ /** What it shows on its own: the file of one image or video, its only content. */
5
+ function openOf(children) {
6
+ const content = children.filter((n) => !(n.type === "text" && !n.value?.trim()));
7
+ if (content.length !== 1) return null;
8
+ const only = content[0];
9
+ if (only.type === "paragraph") return openOf(only.children ?? []);
10
+ if (only.type === "image") return only.url ?? null;
11
+ if (only.type === "html") return /^\s*<(?:video|img|audio)\b[^>]*\bsrc="([^"]+)"/i.exec(only.value ?? "")?.[1] ?? null;
12
+ return null;
13
+ }
14
+ /** A height in px (a bare number) or a CSS length; else none. */
15
+ const height = (value) => value && /^\d+(\.\d+)?$/.test(value) ? `${value}px` : value && /^\d+(\.\d+)?(px|em|rem|vh|svh|dvh)$/.test(value) ? value : void 0;
16
+ /** http(s), protocol-relative, or a path on this server; never `javascript:` or `data:`. */
17
+ const safeSrc = (src) => /^(https?:)?\/\//i.test(src) || !/^[a-z][a-z0-9+.-]*:/i.test(src);
18
+ /** ::image[label]{src} and ::video[label]{src loop autoplay muted poster}: one file, in a window. */
19
+ const media = (kind) => (ctx) => {
20
+ const src = (ctx.attrs.src ?? "").trim();
21
+ if (!src) return html`<pre class="wb-error">
22
+ ${kind}: needs a src, like ::${kind}[a label]{src="${kind === "image" ? "shot.png" : "demo.mp4"}"}</pre>`;
23
+ if (!safeSrc(src)) return html`<pre class="wb-error">${kind}: src must be an http(s) URL or a path, not ${src.split(":")[0]}:</pre>`;
24
+ const alt = ctx.labelText ?? ctx.attrs.alt ?? "";
25
+ const flag = (name) => name in ctx.attrs && raw(` ${name}`);
26
+ const poster = ctx.attrs.poster && safeSrc(ctx.attrs.poster) ? html` poster="${ctx.attrs.poster}"` : "";
27
+ const body = kind === "image" ? html`<img src="${src}" alt="${alt}" loading="lazy" />` : html`<video
28
+ src="${src}"
29
+ controls${flag("loop")}${flag("autoplay")}${"autoplay" in ctx.attrs || "muted" in ctx.attrs ? raw(" muted") : ""}
30
+ playsinline
31
+ preload="metadata"
32
+ ${poster}${alt ? html` aria-label="${alt}"` : ""}
33
+ ></video>`;
34
+ return windowFrame({
35
+ label: ctx.label,
36
+ open: src,
37
+ wide: "wide" in ctx.attrs,
38
+ bare: "bare" in ctx.attrs,
39
+ height: height(ctx.attrs.height),
40
+ body
41
+ });
42
+ };
43
+ async function render(ctx) {
44
+ return windowFrame({
45
+ label: ctx.label,
46
+ open: openOf(ctx.children),
47
+ wide: "wide" in ctx.attrs,
48
+ bare: "bare" in ctx.attrs,
49
+ height: height(ctx.attrs.height),
50
+ body: await ctx.toHtml(ctx.children)
51
+ });
52
+ }
53
+ function windows() {
54
+ return definePlugin({
55
+ name: "window",
56
+ blocks: {
57
+ window: { html: render },
58
+ image: { html: media("image") },
59
+ video: { html: media("video") }
60
+ },
61
+ docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
62
+ });
63
+ }
64
+ export { windows as default, openOf, render };
@@ -2,27 +2,30 @@ import { createComponent, render } from "@solidjs/web";
2
2
  import { createContext, createSignal, onSettled, useContext } from "solid-js";
3
3
  // solid/index.tsx
4
4
  const WhiteboardContext = createContext();
5
- /** The page's events and theme, as signals. Use inside a component passed to solid(). */
5
+ /** The page's events, theme, listeners, forms and unread messages, as signals. Use inside a component passed to solid(). */
6
6
  const useWhiteboard = () => useContext(WhiteboardContext);
7
7
  /** Turn a Solid component into a template client: `export default solid(MyComponent)`. */
8
8
  function solid(Component) {
9
9
  return (element, props, api) => render(() => {
10
- const [events, setEvents] = createSignal(api.events());
11
- const [theme, setTheme] = createSignal(api.theme());
12
- onSettled(() => {
13
- const offEvents = api.onEvents((list) => setEvents(() => list));
14
- const offTheme = api.onTheme(setTheme);
15
- return () => {
16
- offEvents();
17
- offTheme();
18
- };
19
- });
10
+ const signal = (value) => {
11
+ const [get, set] = createSignal({ v: value() });
12
+ onSettled(() => value.on((next) => set({ v: next })));
13
+ return () => get().v;
14
+ };
15
+ const events = signal(api.events);
16
+ const theme = signal(api.theme);
17
+ const listeners = signal(api.listeners);
18
+ const forms = signal(api.forms);
19
+ const unread = signal(api.unread);
20
20
  const value = {
21
21
  page: api.page,
22
22
  events,
23
23
  last: (type) => events().findLast((e) => e.type === type),
24
24
  append: api.append,
25
25
  theme,
26
+ listeners,
27
+ forms,
28
+ unread,
26
29
  markdown: api.markdown
27
30
  };
28
31
  return createComponent(WhiteboardContext, {