@bigmistqke/whiteboard 0.5.0 → 0.6.1

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 (106) hide show
  1. package/README.md +125 -25
  2. package/bin/whiteboard.ts +299 -16
  3. package/dist/bin/whiteboard.js +247 -17
  4. package/dist/client/runtime.js +22 -10
  5. package/dist/plugins/ansi/README.md +36 -0
  6. package/dist/plugins/ansi/index.js +64 -0
  7. package/dist/plugins/ansi/public/style.css +28 -0
  8. package/dist/plugins/badge/README.md +28 -0
  9. package/dist/plugins/badge/index.js +24 -0
  10. package/dist/plugins/badge/public/style.css +30 -0
  11. package/dist/plugins/chat/public/style.css +7 -2
  12. package/dist/plugins/code/README.md +4 -2
  13. package/dist/plugins/code/diff.js +12 -2
  14. package/dist/plugins/grid/README.md +12 -12
  15. package/dist/plugins/grid/index.js +7 -19
  16. package/dist/plugins/grid/public/style.css +4 -33
  17. package/dist/plugins/iframe/README.md +7 -7
  18. package/dist/plugins/iframe/index.js +11 -11
  19. package/dist/plugins/iframe/public/style.css +15 -0
  20. package/dist/plugins/index.js +7 -3
  21. package/dist/plugins/lightbox/README.md +22 -0
  22. package/dist/plugins/lightbox/index.js +20 -0
  23. package/dist/plugins/lightbox/public/client.js +4 -0
  24. package/dist/plugins/lightbox/public/style.css +66 -0
  25. package/dist/plugins/steps/README.md +3 -3
  26. package/dist/plugins/steps/index.js +3 -42
  27. package/dist/plugins/steps/public/client.js +1 -1
  28. package/dist/plugins/terminal/host.js +1 -1
  29. package/dist/plugins/terminal/public/client.js +1 -1
  30. package/dist/plugins/window/README.md +34 -14
  31. package/dist/plugins/window/index.js +21 -13
  32. package/dist/src/auth.js +4 -3
  33. package/dist/src/client/page/base.css +61 -1
  34. package/dist/src/client/page/main.js +60 -14
  35. package/dist/src/entries.js +217 -0
  36. package/dist/src/events.js +1 -1
  37. package/dist/src/hub.js +272 -0
  38. package/dist/src/loader.js +4 -1
  39. package/dist/src/package.js +23 -1
  40. package/dist/src/pages/blocks.js +1 -0
  41. package/dist/src/pages/index.js +1 -1
  42. package/dist/src/pages/markdown.js +87 -33
  43. package/dist/src/pages/render.js +116 -14
  44. package/dist/src/pages/window.js +16 -18
  45. package/dist/src/running.js +37 -2
  46. package/dist/src/serve.js +111 -2
  47. package/dist/src/server.js +49 -14
  48. package/package.json +1 -1
  49. package/plugins/ansi/README.md +36 -0
  50. package/plugins/ansi/index.ts +95 -0
  51. package/plugins/ansi/public/style.css +28 -0
  52. package/plugins/badge/README.md +28 -0
  53. package/plugins/badge/index.ts +35 -0
  54. package/plugins/badge/public/style.css +30 -0
  55. package/plugins/chat/public/style.css +7 -2
  56. package/plugins/code/README.md +4 -2
  57. package/plugins/code/diff.ts +14 -2
  58. package/plugins/grid/README.md +12 -12
  59. package/plugins/grid/index.ts +11 -26
  60. package/plugins/grid/public/style.css +4 -33
  61. package/plugins/iframe/README.md +7 -7
  62. package/plugins/iframe/index.ts +15 -15
  63. package/plugins/iframe/public/style.css +15 -0
  64. package/plugins/index.ts +6 -2
  65. package/plugins/lightbox/README.md +22 -0
  66. package/plugins/lightbox/client.ts +99 -0
  67. package/plugins/lightbox/index.ts +25 -0
  68. package/plugins/lightbox/public/style.css +66 -0
  69. package/plugins/steps/README.md +3 -3
  70. package/plugins/steps/client.ts +15 -6
  71. package/plugins/steps/index.ts +3 -46
  72. package/plugins/terminal/client.ts +16 -7
  73. package/plugins/window/README.md +34 -14
  74. package/plugins/window/index.ts +20 -13
  75. package/skills/whiteboard/SKILL.md +17 -10
  76. package/src/auth.ts +5 -3
  77. package/src/client/base.ts +19 -0
  78. package/src/client/forms.ts +2 -1
  79. package/src/client/markdown.ts +2 -1
  80. package/src/client/page/base.css +61 -1
  81. package/src/client/page/elsewhere.ts +72 -16
  82. package/src/client/page/fresh.ts +2 -1
  83. package/src/client/page/sort.ts +2 -1
  84. package/src/client/runtime.ts +11 -9
  85. package/src/define.ts +66 -7
  86. package/src/entries.ts +269 -0
  87. package/src/events.ts +2 -1
  88. package/src/hub.ts +355 -0
  89. package/src/loader.ts +7 -1
  90. package/src/package.ts +22 -0
  91. package/src/pages/blocks.ts +3 -0
  92. package/src/pages/index.ts +4 -2
  93. package/src/pages/markdown.ts +89 -32
  94. package/src/pages/render.ts +134 -13
  95. package/src/pages/window.ts +16 -25
  96. package/src/running.ts +47 -1
  97. package/src/serve.ts +114 -1
  98. package/src/server.ts +80 -14
  99. package/dist/plugins/gallery/README.md +0 -30
  100. package/dist/plugins/gallery/index.js +0 -75
  101. package/dist/plugins/gallery/public/client.js +0 -1
  102. package/dist/plugins/gallery/public/style.css +0 -90
  103. package/plugins/gallery/README.md +0 -30
  104. package/plugins/gallery/client.tsx +0 -70
  105. package/plugins/gallery/index.ts +0 -89
  106. package/plugins/gallery/public/style.css +0 -90
@@ -1,70 +0,0 @@
1
- import { createSignal, For, Show, onSettled } from 'solid-js'
2
- import { solid } from '@bigmistqke/whiteboard/solid'
3
- import type { Item } from './index'
4
-
5
- function Gallery(props: { items: Item[]; min: string | null; narrow: boolean }) {
6
- const [open, setOpen] = createSignal<number | null>(null)
7
- const current = () => {
8
- const i = open()
9
- return i == null ? undefined : props.items[i]
10
- }
11
- const step = (d: number) => setOpen(i => (i == null ? i : (i + d + props.items.length) % props.items.length))
12
-
13
- onSettled(() => {
14
- const onKey = (e: KeyboardEvent) => {
15
- if (open() == null) return
16
- if (e.key === 'Escape') setOpen(null)
17
- else if (e.key === 'ArrowRight') step(1)
18
- else if (e.key === 'ArrowLeft') step(-1)
19
- }
20
- addEventListener('keydown', onKey)
21
- return () => removeEventListener('keydown', onKey)
22
- })
23
-
24
- return (
25
- <>
26
- <div class={['wb-gallery', { 'wb-wide': !props.narrow }]} style={{ '--wb-gallery-min': props.min ?? '240px' }}>
27
- <For each={props.items}>
28
- {(item, i) => (
29
- <figure class="wb-gallery-item">
30
- <Show when={item.src}>
31
- <button type="button" class="wb-gallery-thumb" onClick={() => setOpen(i())}>
32
- <img src={item.src!} alt={item.alt} loading="lazy" />
33
- </button>
34
- </Show>
35
- <Show when={item.title || item.html}>
36
- <figcaption>
37
- <Show when={item.title}>
38
- <h3 innerHTML={item.title!} />
39
- </Show>
40
- <div innerHTML={item.html} />
41
- </figcaption>
42
- </Show>
43
- </figure>
44
- )}
45
- </For>
46
- </div>
47
- <Show when={current()}>
48
- {item => (
49
- <div class="wb-lightbox" onClick={e => e.target === e.currentTarget && setOpen(null)}>
50
- <img src={item().src ?? ''} alt={item().alt} />
51
- <div class="wb-lightbox-caption" innerHTML={item().title ?? ''} />
52
- <Show when={props.items.length > 1}>
53
- <button type="button" class="wb-lightbox-prev" aria-label="Previous" onClick={() => step(-1)}>
54
- ‹
55
- </button>
56
- <button type="button" class="wb-lightbox-next" aria-label="Next" onClick={() => step(1)}>
57
- ›
58
- </button>
59
- </Show>
60
- <button type="button" class="wb-lightbox-close" aria-label="Close" onClick={() => setOpen(null)}>
61
- ×
62
- </button>
63
- </div>
64
- )}
65
- </Show>
66
- </>
67
- )
68
- }
69
-
70
- export default solid(Gallery)
@@ -1,89 +0,0 @@
1
- import fs from 'node:fs'
2
- import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
3
- // Turns the block's content into gallery items: one per heading (first image in the section is
4
- // its picture), or one per image when there are no headings.
5
- import { escape, type DirectiveContext } from '@bigmistqke/whiteboard'
6
- import { builtinPublic } from '../../src/package.ts'
7
-
8
- interface Node {
9
- type: string
10
- depth?: number
11
- url?: string
12
- alt?: string
13
- children?: Node[]
14
- }
15
- export interface Item {
16
- src: string | null
17
- alt: string
18
- title: string | null
19
- html: string
20
- }
21
-
22
- /** Remove and return the first image in a list of nodes (searching inside paragraphs). */
23
- function takeImage(nodes: Node[]): Node | null {
24
- for (let i = 0; i < nodes.length; i++) {
25
- const n = nodes[i]
26
- if (n.type === 'image') {
27
- nodes.splice(i, 1)
28
- return n
29
- }
30
- if (n.children) {
31
- const found = takeImage(n.children)
32
- if (found) {
33
- if (n.type === 'paragraph' && n.children.every(c => c.type === 'text' && !String((c as any).value).trim()))
34
- nodes.splice(i, 1)
35
- return found
36
- }
37
- }
38
- }
39
- return null
40
- }
41
-
42
- export async function props(ctx: DirectiveContext) {
43
- const children = ctx.children as Node[]
44
- const heads = children.filter(n => n.type === 'heading')
45
- const items: Item[] = []
46
- if (heads.length) {
47
- const depth = Math.min(...heads.map(h => h.depth!))
48
- let current: { heading: Node; body: Node[] } | null = null
49
- const groups: { heading: Node; body: Node[] }[] = []
50
- for (const n of children) {
51
- if (n.type === 'heading' && n.depth === depth) groups.push((current = { heading: n, body: [] }))
52
- else current?.body.push(n)
53
- }
54
- for (const g of groups) {
55
- const img = takeImage(g.body)
56
- items.push({
57
- src: img?.url ?? null,
58
- alt: img?.alt ?? '',
59
- title: await ctx.toHtml(g.heading.children ?? []),
60
- html: await ctx.toHtml(g.body),
61
- })
62
- }
63
- } else {
64
- const walk = (nodes: Node[]) => {
65
- for (const n of nodes) {
66
- if (n.type === 'image')
67
- items.push({ src: n.url!, alt: n.alt ?? '', title: n.alt ? escape(n.alt) : null, html: '' })
68
- else if (n.children) walk(n.children)
69
- }
70
- }
71
- walk(children)
72
- }
73
- return { items, min: ctx.attrs.min ?? null, narrow: 'narrow' in ctx.attrs }
74
- }
75
-
76
- export default function gallery(): Plugin {
77
- return definePlugin({
78
- name: 'gallery',
79
- public: builtinPublic('gallery'),
80
- blocks: {
81
- gallery: {
82
- props,
83
- client: 'client.js',
84
- style: 'style.css',
85
- },
86
- },
87
- docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
88
- })
89
- }
@@ -1,90 +0,0 @@
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
- }