@bigmistqke/whiteboard 0.4.0 → 0.6.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.
- package/README.md +177 -26
- package/bin/whiteboard.ts +331 -16
- package/dist/bin/whiteboard.js +268 -17
- package/dist/client/runtime.js +66 -23
- package/dist/plugins/ansi/README.md +36 -0
- package/dist/plugins/ansi/index.js +64 -0
- package/dist/plugins/ansi/public/style.css +28 -0
- package/dist/plugins/badge/README.md +28 -0
- package/dist/plugins/badge/index.js +24 -0
- package/dist/plugins/badge/public/style.css +30 -0
- package/dist/plugins/chat/public/style.css +7 -2
- package/dist/plugins/code/README.md +4 -2
- package/dist/plugins/code/diff.js +12 -2
- package/dist/plugins/draft/README.md +14 -0
- package/dist/plugins/draft/index.js +21 -0
- package/dist/plugins/draft/public/style.css +21 -0
- package/dist/plugins/grid/README.md +12 -12
- package/dist/plugins/grid/index.js +7 -19
- package/dist/plugins/grid/public/style.css +4 -33
- package/dist/plugins/iframe/README.md +7 -7
- package/dist/plugins/iframe/index.js +11 -11
- package/dist/plugins/iframe/public/style.css +15 -0
- package/dist/plugins/index.js +11 -3
- package/dist/plugins/lightbox/README.md +22 -0
- package/dist/plugins/lightbox/index.js +20 -0
- package/dist/plugins/lightbox/public/client.js +4 -0
- package/dist/plugins/lightbox/public/style.css +66 -0
- package/dist/plugins/steps/README.md +42 -0
- package/dist/plugins/steps/index.js +60 -0
- package/dist/plugins/steps/public/client.js +1 -0
- package/dist/plugins/steps/public/style.css +77 -0
- package/dist/plugins/terminal/host.js +9 -3
- package/dist/plugins/terminal/public/client.js +1 -1
- package/dist/plugins/terminal/sizes.js +2 -1
- package/dist/plugins/toc/README.md +21 -3
- package/dist/plugins/toc/index.js +8 -2
- package/dist/plugins/toc/public/client.js +1 -1
- package/dist/plugins/toc/public/style.css +10 -4
- package/dist/plugins/window/README.md +34 -14
- package/dist/plugins/window/index.js +21 -13
- package/dist/src/auth.js +6 -4
- package/dist/src/client/page/base.css +61 -1
- package/dist/src/client/page/main.js +74 -20
- package/dist/src/entries.js +211 -0
- package/dist/src/events.js +1 -1
- package/dist/src/hub.js +272 -0
- package/dist/src/loader.js +12 -3
- package/dist/src/package.js +23 -1
- package/dist/src/pages/blocks.js +1 -0
- package/dist/src/pages/index.js +1 -1
- package/dist/src/pages/markdown.js +87 -33
- package/dist/src/pages/render.js +157 -28
- package/dist/src/pages/window.js +17 -18
- package/dist/src/running.js +37 -2
- package/dist/src/serve.js +111 -2
- package/dist/src/server.js +264 -23
- package/package.json +3 -2
- package/plugins/ansi/README.md +36 -0
- package/plugins/ansi/index.ts +95 -0
- package/plugins/ansi/public/style.css +28 -0
- package/plugins/badge/README.md +28 -0
- package/plugins/badge/index.ts +35 -0
- package/plugins/badge/public/style.css +30 -0
- package/plugins/chat/public/style.css +7 -2
- package/plugins/code/README.md +4 -2
- package/plugins/code/diff.ts +14 -2
- package/plugins/code/index.ts +3 -1
- package/plugins/draft/README.md +14 -0
- package/plugins/draft/index.ts +23 -0
- package/plugins/draft/public/style.css +21 -0
- package/plugins/grid/README.md +12 -12
- package/plugins/grid/index.ts +11 -26
- package/plugins/grid/public/style.css +4 -33
- package/plugins/iframe/README.md +7 -7
- package/plugins/iframe/index.ts +15 -15
- package/plugins/iframe/public/style.css +15 -0
- package/plugins/index.ts +10 -2
- package/plugins/lightbox/README.md +22 -0
- package/plugins/lightbox/client.ts +99 -0
- package/plugins/lightbox/index.ts +25 -0
- package/plugins/lightbox/public/style.css +66 -0
- package/plugins/mermaid/index.ts +4 -2
- package/plugins/steps/README.md +42 -0
- package/plugins/steps/client.ts +75 -0
- package/plugins/steps/index.ts +84 -0
- package/plugins/steps/public/style.css +77 -0
- package/plugins/terminal/client.ts +16 -7
- package/plugins/terminal/host.ts +12 -6
- package/plugins/terminal/sizes.ts +3 -1
- package/plugins/toc/README.md +21 -3
- package/plugins/toc/client.ts +47 -6
- package/plugins/toc/index.ts +19 -6
- package/plugins/toc/public/style.css +10 -4
- package/plugins/window/README.md +34 -14
- package/plugins/window/index.ts +20 -13
- package/skills/whiteboard/SKILL.md +18 -10
- package/src/auth.ts +8 -5
- package/src/client/base.ts +19 -0
- package/src/client/forms.ts +2 -1
- package/src/client/markdown.ts +2 -1
- package/src/client/page/base.css +61 -1
- package/src/client/page/elsewhere.ts +72 -16
- package/src/client/page/fresh.ts +2 -1
- package/src/client/page/main.ts +18 -6
- package/src/client/page/sort.ts +2 -1
- package/src/client/runtime.ts +62 -25
- package/src/define.ts +126 -19
- package/src/entries.ts +258 -0
- package/src/events.ts +2 -1
- package/src/hub.ts +355 -0
- package/src/loader.ts +14 -3
- package/src/package.ts +22 -0
- package/src/pages/blocks.ts +3 -0
- package/src/pages/index.ts +6 -4
- package/src/pages/markdown.ts +89 -32
- package/src/pages/render.ts +181 -28
- package/src/pages/window.ts +23 -25
- package/src/running.ts +47 -1
- package/src/serve.ts +114 -1
- package/src/server.ts +332 -26
- package/dist/plugins/gallery/README.md +0 -30
- package/dist/plugins/gallery/index.js +0 -75
- package/dist/plugins/gallery/public/client.js +0 -1
- package/dist/plugins/gallery/public/style.css +0 -90
- package/plugins/gallery/README.md +0 -30
- package/plugins/gallery/client.tsx +0 -70
- package/plugins/gallery/index.ts +0 -89
- package/plugins/gallery/public/style.css +0 -90
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/* The lightbox (index.ts, client.ts): pictures in a container composed with it open on a click */
|
|
2
|
+
[data-lightbox] img:not(a img) {
|
|
3
|
+
cursor: zoom-in;
|
|
4
|
+
}
|
|
5
|
+
/* over the page: the picture or video as large as fits, its caption under it */
|
|
6
|
+
.wb-lightbox {
|
|
7
|
+
position: fixed;
|
|
8
|
+
inset: 0;
|
|
9
|
+
z-index: var(--layer-top);
|
|
10
|
+
background: rgb(0 0 0 / 0.86);
|
|
11
|
+
display: grid;
|
|
12
|
+
place-items: center;
|
|
13
|
+
grid-template-rows: 1fr auto;
|
|
14
|
+
padding: var(--space-3xl) var(--space-2xl);
|
|
15
|
+
}
|
|
16
|
+
.wb-lightbox-stage {
|
|
17
|
+
display: grid;
|
|
18
|
+
place-items: center;
|
|
19
|
+
min-height: 0;
|
|
20
|
+
width: 100%;
|
|
21
|
+
height: 100%;
|
|
22
|
+
}
|
|
23
|
+
.wb-lightbox-stage > :is(img, video) {
|
|
24
|
+
max-width: 100%;
|
|
25
|
+
max-height: calc(100vh - 110px);
|
|
26
|
+
object-fit: contain;
|
|
27
|
+
border-radius: var(--radius-sm);
|
|
28
|
+
}
|
|
29
|
+
.wb-lightbox-caption {
|
|
30
|
+
color: #eee;
|
|
31
|
+
text-align: center;
|
|
32
|
+
padding-top: var(--space-lg);
|
|
33
|
+
}
|
|
34
|
+
.wb-lightbox button {
|
|
35
|
+
position: absolute;
|
|
36
|
+
display: grid;
|
|
37
|
+
place-items: center;
|
|
38
|
+
background: rgb(255 255 255 / 0.12);
|
|
39
|
+
color: #fff;
|
|
40
|
+
border: 0;
|
|
41
|
+
width: 44px;
|
|
42
|
+
height: 44px;
|
|
43
|
+
border-radius: 50%;
|
|
44
|
+
padding: 0;
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
}
|
|
47
|
+
.wb-lightbox button:hover {
|
|
48
|
+
background: rgb(255 255 255 / 0.22);
|
|
49
|
+
}
|
|
50
|
+
.wb-lightbox-prev {
|
|
51
|
+
left: 12px;
|
|
52
|
+
top: 50%;
|
|
53
|
+
translate: 0 -50%;
|
|
54
|
+
}
|
|
55
|
+
.wb-lightbox-next {
|
|
56
|
+
right: 12px;
|
|
57
|
+
top: 50%;
|
|
58
|
+
translate: 0 -50%;
|
|
59
|
+
}
|
|
60
|
+
.wb-lightbox button[hidden] {
|
|
61
|
+
display: none;
|
|
62
|
+
}
|
|
63
|
+
.wb-lightbox-close {
|
|
64
|
+
right: 12px;
|
|
65
|
+
top: 12px;
|
|
66
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
One pane, one item at a time, with ‹ › between them: an A/B, the steps of a
|
|
2
|
+
procedure, versions of a design. It is a window, so ⤢ fills the browser
|
|
3
|
+
window with it (for going through steps, large).
|
|
4
|
+
|
|
5
|
+
A heading at the block's shallowest heading level starts an item, titled by
|
|
6
|
+
it, and so does a `---`, untitled. With up to four items, all titled, the header shows the
|
|
7
|
+
titles as tabs; else it counts (`2 / 5`) and each item shows its title.
|
|
8
|
+
|
|
9
|
+
The items are laid over each other, so the pane is as tall as the tallest
|
|
10
|
+
and flipping doesn't move the page. ← and → step when it has the focus (a
|
|
11
|
+
click in it) or fills the window. Which item shows stays when the page
|
|
12
|
+
updates, even when a step is added before it.
|
|
13
|
+
|
|
14
|
+
Attributes: `count` (count, never tabs), `wide`, `height`.
|
|
15
|
+
|
|
16
|
+
```markdown
|
|
17
|
+
:::steps[Two headers]
|
|
18
|
+
### A
|
|
19
|
+
The label on the left, the buttons on the right.
|
|
20
|
+
|
|
21
|
+
### B
|
|
22
|
+
Everything centred.
|
|
23
|
+
:::
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
:::steps[Two headers]
|
|
27
|
+
### A
|
|
28
|
+
The label on the left, the buttons on the right.
|
|
29
|
+
|
|
30
|
+
### B
|
|
31
|
+
Everything centred.
|
|
32
|
+
:::
|
|
33
|
+
|
|
34
|
+
```markdown
|
|
35
|
+
:::steps[The migration]
|
|
36
|
+
### Copy the table
|
|
37
|
+
`migrate --dry-run` on staging first.
|
|
38
|
+
|
|
39
|
+
### Switch the reads
|
|
40
|
+
…
|
|
41
|
+
:::
|
|
42
|
+
```
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { builtinPublic } from "../../src/package.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { definePlugin, html, raw, windowFrame } from "@bigmistqke/whiteboard";
|
|
4
|
+
// plugins/steps/index.ts
|
|
5
|
+
/** A height in px (a bare number) or a CSS length; else none. */
|
|
6
|
+
const height = (value) => value && /^\d+(\.\d+)?$/.test(value) ? `${value}px` : value && /^\d+(\.\d+)?(px|em|rem|vh|svh|dvh)$/.test(value) ? value : void 0;
|
|
7
|
+
const svg = (d) => raw(`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`);
|
|
8
|
+
const PREV = svg("M10 3.5 5.5 8l4.5 4.5");
|
|
9
|
+
const NEXT = svg("M6 3.5 10.5 8 6 12.5");
|
|
10
|
+
/** With this many items or fewer, all titled, the header shows their titles as tabs. */
|
|
11
|
+
const TABS = 4;
|
|
12
|
+
async function render(ctx) {
|
|
13
|
+
const items = await ctx.items();
|
|
14
|
+
const tabs = !("count" in ctx.attrs) && items.length <= TABS && items.every((i) => i.title);
|
|
15
|
+
const n = items.length;
|
|
16
|
+
const marks = tabs ? items.map((item, i) => html`<button type="button" class="wb-steps-tab wb-steps-mark" data-steps="${String(i)}">
|
|
17
|
+
${raw(item.title)}
|
|
18
|
+
</button>`) : html`<span class="wb-steps-count">
|
|
19
|
+
${items.map((_, i) => html`<span class="wb-steps-mark">${String(i + 1)} / ${String(n)}</span>`)}
|
|
20
|
+
</span>`;
|
|
21
|
+
const controls = html`<span class="wb-steps-nav">
|
|
22
|
+
<button
|
|
23
|
+
type="button"
|
|
24
|
+
class="wb-window-button wb-steps-prev"
|
|
25
|
+
data-steps="prev"
|
|
26
|
+
title="Previous (←)"
|
|
27
|
+
aria-label="Previous"
|
|
28
|
+
>
|
|
29
|
+
${PREV}
|
|
30
|
+
</button>
|
|
31
|
+
${marks}
|
|
32
|
+
<button type="button" class="wb-window-button wb-steps-next" data-steps="next" title="Next (→)" aria-label="Next">
|
|
33
|
+
${NEXT}
|
|
34
|
+
</button>
|
|
35
|
+
</span>`;
|
|
36
|
+
const body = html`<div class="wb-steps" tabindex="0">
|
|
37
|
+
${items.map((item) => html`<section class="wb-steps-item" data-key="${item.key}">
|
|
38
|
+
${!tabs && item.title ? html`<div class="wb-steps-title">${raw(item.title)}</div>` : ""} ${raw(item.html)}
|
|
39
|
+
</section>`)}
|
|
40
|
+
</div>`;
|
|
41
|
+
return windowFrame({
|
|
42
|
+
label: ctx.label,
|
|
43
|
+
className: "wb-steps-window",
|
|
44
|
+
controls,
|
|
45
|
+
wide: "wide" in ctx.attrs,
|
|
46
|
+
height: height(ctx.attrs.height),
|
|
47
|
+
body
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function steps() {
|
|
51
|
+
return definePlugin({
|
|
52
|
+
name: "steps",
|
|
53
|
+
public: builtinPublic("steps"),
|
|
54
|
+
style: "style.css",
|
|
55
|
+
setup: () => ({ client: "client.js" }),
|
|
56
|
+
blocks: { steps: { html: render } },
|
|
57
|
+
docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export { steps as default, render };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=()=>[...document.querySelectorAll(`#wb-main .wb-steps-window`)],t=e=>[...e.querySelectorAll(`:scope > .wb-window-body > .wb-steps > .wb-steps-item`)],n=e=>[...e.querySelectorAll(`:scope > .wb-window-bar .wb-steps-mark`)],r=/* @__PURE__ */ new Map;function i(e,n){let i=r.get(n);if(!i)return 0;let a=i.key?t(e).findIndex(e=>e.dataset.key===i.key):-1;return a>=0?a:i.index}function a(e,i,a){let o=t(e),s=Math.max(o.length,1);a=Math.min(Math.max(a,0),s-1),r.set(i,{key:o[a]?.dataset.key??null,index:a}),e.setAttribute(`data-wb-step`,String(a)),o.forEach((e,t)=>e.toggleAttribute(`data-wb-current`,t===a)),n(e).forEach((e,t)=>e.toggleAttribute(`data-wb-current`,t===a)),e.toggleAttribute(`data-wb-first`,a===0),e.toggleAttribute(`data-wb-last`,a===s-1)}const o=()=>e().forEach((e,t)=>a(e,t,i(e,t)));function s(t,n){let r=e().indexOf(t);if(r<0)return;let o=i(t,r);a(t,r,n===`prev`?o-1:n===`next`?o+1:n)}const c=e=>!!e?.closest?.(`input, textarea, select, [contenteditable]:not([contenteditable="false"])`);let l=!1;const u=(e,t,n)=>{o(),n.onRendered(o),l||(l=!0,document.addEventListener(`click`,e=>{let t=e.target.closest?.(`[data-steps]`),n=t?.closest(`.wb-steps-window`);if(!t||!n)return;let r=t.dataset.steps;s(n,r===`prev`||r===`next`?r:Number(r))}),document.addEventListener(`keydown`,e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`||e.metaKey||e.ctrlKey||e.altKey)return;let t=e.target;if(c(t))return;let n=t.closest?.(`.wb-steps-window`)??document.querySelector(`#wb-main .wb-steps-window[data-wb-maximized]`);n&&(e.preventDefault(),s(n,e.key===`ArrowLeft`?`prev`:`next`))}))};export{u as default};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/* Steps (index.ts): the items over each other in one grid cell, so the pane is as tall as the
|
|
2
|
+
tallest; one shows. Before the browser marks one (data-wb-step), the first. */
|
|
3
|
+
.wb-steps {
|
|
4
|
+
display: grid;
|
|
5
|
+
outline: none;
|
|
6
|
+
}
|
|
7
|
+
.wb-steps:focus-visible {
|
|
8
|
+
box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) var(--tint-strong), transparent);
|
|
9
|
+
}
|
|
10
|
+
.wb-steps > .wb-steps-item {
|
|
11
|
+
grid-area: 1 / 1;
|
|
12
|
+
min-width: 0;
|
|
13
|
+
}
|
|
14
|
+
.wb-steps > .wb-steps-item > :first-child {
|
|
15
|
+
margin-top: 0;
|
|
16
|
+
}
|
|
17
|
+
.wb-steps > .wb-steps-item > :last-child {
|
|
18
|
+
margin-bottom: 0;
|
|
19
|
+
}
|
|
20
|
+
.wb-steps-window:not([data-wb-step]) > .wb-window-body > .wb-steps > .wb-steps-item:not(:first-child),
|
|
21
|
+
.wb-steps-window[data-wb-step] > .wb-window-body > .wb-steps > .wb-steps-item:not([data-wb-current]) {
|
|
22
|
+
visibility: hidden;
|
|
23
|
+
}
|
|
24
|
+
.wb-steps-title {
|
|
25
|
+
font: var(--weight-strong) var(--ui-small) / var(--ui-line-height) var(--sans);
|
|
26
|
+
color: var(--muted);
|
|
27
|
+
letter-spacing: var(--caps-spacing);
|
|
28
|
+
text-transform: uppercase;
|
|
29
|
+
margin-bottom: var(--space-md);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* the header: ‹ 2 / 5 › or ‹ A B › */
|
|
33
|
+
.wb-steps-nav {
|
|
34
|
+
display: flex;
|
|
35
|
+
align-items: center;
|
|
36
|
+
gap: var(--space-2xs);
|
|
37
|
+
flex: none;
|
|
38
|
+
}
|
|
39
|
+
.wb-steps-count {
|
|
40
|
+
font: var(--ui-tiny) / 1 var(--sans);
|
|
41
|
+
font-variant-numeric: tabular-nums;
|
|
42
|
+
color: var(--muted);
|
|
43
|
+
padding: 0 var(--space-2xs);
|
|
44
|
+
}
|
|
45
|
+
.wb-steps-window:not([data-wb-step]) > .wb-window-bar .wb-steps-count > .wb-steps-mark:not(:first-child),
|
|
46
|
+
.wb-steps-window[data-wb-step] > .wb-window-bar .wb-steps-count > .wb-steps-mark:not([data-wb-current]) {
|
|
47
|
+
display: none;
|
|
48
|
+
}
|
|
49
|
+
.wb-steps-tab {
|
|
50
|
+
font: var(--ui-tiny) / 1 var(--sans);
|
|
51
|
+
color: var(--muted);
|
|
52
|
+
background: none;
|
|
53
|
+
border: var(--hairline) solid transparent;
|
|
54
|
+
border-radius: var(--radius-pill);
|
|
55
|
+
padding: var(--space-xs) var(--space-md);
|
|
56
|
+
cursor: pointer;
|
|
57
|
+
white-space: nowrap;
|
|
58
|
+
}
|
|
59
|
+
.wb-steps-tab > * {
|
|
60
|
+
margin: 0;
|
|
61
|
+
}
|
|
62
|
+
.wb-steps-tab:hover {
|
|
63
|
+
color: var(--text);
|
|
64
|
+
background: color-mix(in srgb, var(--text) var(--tint-faint), transparent);
|
|
65
|
+
}
|
|
66
|
+
.wb-steps-window:not([data-wb-step]) > .wb-window-bar .wb-steps-tab:first-of-type,
|
|
67
|
+
.wb-steps-window > .wb-window-bar .wb-steps-tab[data-wb-current] {
|
|
68
|
+
color: var(--accent);
|
|
69
|
+
border-color: color-mix(in srgb, var(--accent) var(--tint-strong), transparent);
|
|
70
|
+
background: color-mix(in srgb, var(--accent) var(--tint-faint), transparent);
|
|
71
|
+
}
|
|
72
|
+
.wb-steps-window:not([data-wb-step]) > .wb-window-bar .wb-steps-prev,
|
|
73
|
+
.wb-steps-window[data-wb-first] > .wb-window-bar .wb-steps-prev,
|
|
74
|
+
.wb-steps-window[data-wb-last] > .wb-window-bar .wb-steps-next {
|
|
75
|
+
opacity: 0.35;
|
|
76
|
+
pointer-events: none;
|
|
77
|
+
}
|
|
@@ -3,6 +3,8 @@ import { handOver, lastUsed, leave, report } from "./sizes.js";
|
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
|
+
import xtermHeadless from "@xterm/headless";
|
|
7
|
+
import xtermSerialize from "@xterm/addon-serialize";
|
|
6
8
|
import net from "node:net";
|
|
7
9
|
// plugins/terminal/host.ts
|
|
8
10
|
const require = createRequire(import.meta.url);
|
|
@@ -11,7 +13,11 @@ if (!dir || !socket) {
|
|
|
11
13
|
console.error("usage: host <project dir> <socket path>");
|
|
12
14
|
process.exit(2);
|
|
13
15
|
}
|
|
14
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* node-pty, loaded when a session starts rather than imported: a native module that may not load on
|
|
18
|
+
* this machine, which then is an error to report, not a host that fails to start. Its prebuilt
|
|
19
|
+
* helper ships without execute permission (1.1.0): add it.
|
|
20
|
+
*/
|
|
15
21
|
function loadPty() {
|
|
16
22
|
const pty = require("node-pty");
|
|
17
23
|
const helper = path.join(path.dirname(require.resolve("node-pty/package.json")), "prebuilds", `${process.platform}-${process.arch}`, "spawn-helper");
|
|
@@ -20,8 +26,8 @@ function loadPty() {
|
|
|
20
26
|
} catch {}
|
|
21
27
|
return pty;
|
|
22
28
|
}
|
|
23
|
-
const { Terminal } =
|
|
24
|
-
const { SerializeAddon } =
|
|
29
|
+
const { Terminal } = xtermHeadless;
|
|
30
|
+
const { SerializeAddon } = xtermSerialize;
|
|
25
31
|
/** the sessions by id, in the order they were made */
|
|
26
32
|
const sessions = /* @__PURE__ */ new Map();
|
|
27
33
|
let nextId = 1;
|
|
@@ -38,4 +38,4 @@ WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){t
|
|
|
38
38
|
* http://bellard.org/jslinux/
|
|
39
39
|
* Copyright (c) 2011 Fabrice Bellard
|
|
40
40
|
*/
|
|
41
|
-
this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),a=window.getComputedStyle(this._terminal.element),o={top:parseInt(a.getPropertyValue(`padding-top`)),bottom:parseInt(a.getPropertyValue(`padding-bottom`)),right:parseInt(a.getPropertyValue(`padding-right`)),left:parseInt(a.getPropertyValue(`padding-left`))},s=o.top+o.bottom,c=o.right+o.left,l=r-s,u=i-c-t;return{cols:Math.max(ns,Math.floor(u/e.css.cell.width)),rows:Math.max(rs,Math.floor(l/e.css.cell.height))}}};const as={get:e=>{try{return sessionStorage.getItem(e)}catch{return null}},set:(e,t)=>{try{sessionStorage.setItem(e,t)}catch{}}};function
|
|
41
|
+
this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),a=window.getComputedStyle(this._terminal.element),o={top:parseInt(a.getPropertyValue(`padding-top`)),bottom:parseInt(a.getPropertyValue(`padding-bottom`)),right:parseInt(a.getPropertyValue(`padding-right`)),left:parseInt(a.getPropertyValue(`padding-left`))},s=o.top+o.bottom,c=o.right+o.left,l=r-s,u=i-c-t;return{cols:Math.max(ns,Math.floor(u/e.css.cell.width)),rows:Math.max(rs,Math.floor(l/e.css.cell.height))}}};const as={get:e=>{try{return sessionStorage.getItem(e)}catch{return null}},set:(e,t)=>{try{sessionStorage.setItem(e,t)}catch{}}},os=(()=>{try{return JSON.parse(document.getElementById(`wb-page`)?.textContent??`{}`).base??``}catch{return``}})();function ss(e){let t=e.querySelector(`.wb-term-screen`),n=e.querySelector(`.wb-term-tabs`),r=e.querySelector(`.wb-term-status`),i=e.querySelector(`.wb-term-actions`),a=e.querySelector(`.wb-term-toggle`),o=e.querySelector(`.wb-term-grip`),s=[];try{({sessions:s}=JSON.parse(e.dataset.sessions??`{}`)),s??=[]}catch{}let c=e.dataset.tab??s[0]?.id??null,l=new ts({fontFamily:`ui-monospace, SFMono-Regular, Menlo, monospace`,fontSize:13,cursorBlink:!0,scrollback:5e3,scrollSensitivity:3,allowProposedApi:!0,theme:{background:`#0f1115`,foreground:`#d7dae0`,cursor:`#d7dae0`,selectionBackground:`#3a4150`}}),u=new is;l.loadAddon(u),l.open(t);let d=()=>e.dataset.state===`open`;if(new URLSearchParams(location.search).get(`terminal`)===`open`){as.set(`wb-terminal-open`,`1`);let e=new URL(location.href);e.searchParams.delete(`terminal`),history.replaceState(history.state,``,e)}let f=crypto.randomUUID(),p=null,m=null,h=as.get(`wb-terminal-active`)===`1`,g=``,_=()=>p===f;function ee(){if(!d()||!c)return;let e=u.proposeDimensions();if(!e?.cols||!e?.rows)return;let t=`${c} ${e.cols}x${e.rows} ${h}`;t!==g&&(g=t,cs(os+`/api/terminal/resize`,{id:c,viewer:f,cols:e.cols,rows:e.rows,active:h}),h&&=(p=f,!1)),te()}function te(){let e=u.proposeDimensions(),t=_()||!m?e:m;t?.cols&&t?.rows&&(t.cols!==l.cols||t.rows!==l.rows)&&l.resize(t.cols,t.rows)}function ne(){!_()&&c&&(h=!0,ee())}new ResizeObserver(()=>ee()).observe(t),l.textarea?.addEventListener(`focus`,ne);function re(t){let n=()=>{e.dataset.state=t?`open`:`collapsed`,as.set(`wb-terminal-open`,t?`1`:`0`)},r=document.startViewTransition;r&&!matchMedia(`(prefers-reduced-motion: reduce)`).matches?r.call(document,n):n(),requestAnimationFrame(()=>{t&&ne(),ee(),t&&l.focus()})}a.addEventListener(`click`,()=>re(!d())),addEventListener(`keydown`,e=>{e.ctrlKey&&e.key==="`"&&(e.preventDefault(),re(!d()))}),o.addEventListener(`pointerdown`,t=>{t.preventDefault(),o.setPointerCapture(t.pointerId),d()||re(!0);let n=e.querySelector(`.wb-term-bar`).offsetHeight,r=e=>{let t=Math.max(120,Math.min(innerHeight-80,innerHeight-e.clientY-n));document.documentElement.style.setProperty(`--wb-term-h`,`${Math.round(t)}px`)},i=()=>{o.removeEventListener(`pointermove`,r),o.removeEventListener(`pointerup`,i);let e=getComputedStyle(document.documentElement).getPropertyValue(`--wb-term-h`);as.set(`wb-terminal-height`,String(parseInt(e)||``)),ee()};o.addEventListener(`pointermove`,r),o.addEventListener(`pointerup`,i)});let ie=``,ae=Promise.resolve();l.onData(e=>{if(!c)return;ne();let t=c;ie||queueMicrotask(()=>{let e=ie;ie=``,ae=ae.then(()=>cs(os+`/api/terminal/input`,{id:t,data:e})).then(()=>{},()=>{})}),ie+=e});function v(e,t=[]){r.textContent=e,i.replaceChildren(...t.map(([e,t])=>{let n=document.createElement(`button`);return n.type=`button`,n.textContent=e,n.addEventListener(`click`,t),n}))}function oe(){n.replaceChildren(...s.map(e=>{let t=document.createElement(`span`);t.className=`wb-term-tab`,t.dataset.id=e.id,t.classList.toggle(`wb-current`,e.id===c),t.toggleAttribute(`data-exited`,!e.running);let n=document.createElement(`button`);n.type=`button`,n.className=`wb-term-tab-name`,n.textContent=e.label,n.title=e.running?e.label:`${e.label}: exited (${e.exited})`,n.addEventListener(`click`,()=>ce(e.id)),t.append(n);let r=document.createElement(`button`);return r.type=`button`,r.className=`wb-term-tab-close`,r.title=`Close this tab (ends its program)`,r.textContent=`×`,r.addEventListener(`click`,()=>b(e.id)),t.append(r),t})),se()}let y=document.createElement(`button`);y.type=`button`,y.className=`wb-term-add`,y.title=`A new tab with a shell`,y.textContent=`+`,y.addEventListener(`click`,()=>le({})),n.after(y);function se(){let e=s.find(e=>e.id===c);if(!e||e.running)return v(``,[]);v(e.exited==null?`stopped`:`exited (${e.exited})`,[[`Start again`,()=>le({id:e.id,restart:!0})]])}function ce(e){e===c&&S||(c=e,e&&as.set(`wb-terminal-tab`,e),oe(),C()),d()&&l.focus()}async function b(e){await cs(os+`/api/terminal/close`,{id:e}),s=s.filter(t=>t.id!==e),c===e?ce(s.at(-1)?.id??null):oe()}async function le(e){v(`starting…`);let t=await cs(os+`/api/terminal/start`,e),n=await t.json().catch(()=>({}));if(!t.ok)return v(n.error??`could not start`,[[`Try again`,()=>le(e)]]);await x(),d()||re(!0),ce(n.session),l.focus()}async function x(){try{let e=await fetch(os+`/api/terminal/sessions`);e.ok&&({sessions:s}=await e.json())}catch{}oe()}let S=null;function C(){S?.close(),l.reset(),g=``,c||se(),S=new EventSource(`${os}/api/terminal/stream?${c?`id=${encodeURIComponent(c)}&`:``}viewer=${f}`),S.addEventListener(`sessions`,e=>{if(s=JSON.parse(e.data).sessions,c?!s.some(e=>e.id===c):s.length)return ce(s.at(-1)?.id??null);oe()}),S.addEventListener(`none`,()=>{l.reset(),t.querySelectorAll(`.wb-term-placeholder`).forEach(e=>e.remove()),se()}),S.addEventListener(`screen`,e=>{let{d:n,cols:r,rows:i,active:a}=JSON.parse(e.data);l.reset(),m=r&&i?{cols:r,rows:i}:null,p=a??null,m&&l.resize(m.cols,m.rows),l.write(n,()=>{ee(),t.querySelectorAll(`.wb-term-placeholder`).forEach(e=>e.remove())}),se(),d()&&as.get(`wb-terminal-focus`)===`1`&&l.focus()}),S.addEventListener(`data`,e=>l.write(JSON.parse(e.data).d)),S.addEventListener(`navigate`,e=>{let{path:t}=JSON.parse(e.data);typeof t==`string`&&t.startsWith(`/`)&&!t.startsWith(`//`)&&location.assign(os+t)}),S.addEventListener(`size`,e=>{let{cols:t,rows:n,active:r}=JSON.parse(e.data);m={cols:t,rows:n},p=r??null,as.set(`wb-terminal-active`,_()?`1`:`0`),te()}),S.addEventListener(`exit`,e=>{let t=JSON.parse(e.data).code,n=s.find(e=>e.id===c);n&&(n.running=!1,n.exited=t),oe()})}addEventListener(`pagehide`,()=>as.set(`wb-terminal-focus`,e.contains(document.activeElement)?`1`:`0`)),oe(),C()}function cs(e,t){return fetch(e,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)})}const ls=document.getElementById(`wb-terminal`);ls&&ss(ls);
|
|
@@ -31,7 +31,8 @@ function leave(s, viewer) {
|
|
|
31
31
|
*/
|
|
32
32
|
function handOver(s, viewer) {
|
|
33
33
|
if (s.active !== viewer || s.viewers.has(viewer)) return null;
|
|
34
|
-
|
|
34
|
+
let next;
|
|
35
|
+
for (const viewer of s.viewers) if (!next || viewer[1].used > next[1].used) next = viewer;
|
|
35
36
|
s.active = next?.[0] ?? null;
|
|
36
37
|
return next ? {
|
|
37
38
|
cols: next[1].cols,
|
|
@@ -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
|
|
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
|
-
|
|
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
|
+
```
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { builtinPublic } from "../../src/package.js";
|
|
2
|
+
import { html } from "../../src/html.js";
|
|
2
3
|
// plugins/toc/index.ts
|
|
3
4
|
const DOCS = `## Table of contents
|
|
4
5
|
|
|
@@ -9,12 +10,17 @@ in it. A section with an unanswered question or an unread message has a dot.
|
|
|
9
10
|
function toc(options = {}) {
|
|
10
11
|
return {
|
|
11
12
|
name: "toc",
|
|
12
|
-
docs: () => options.always ? DOCS + "\nIn this project every page has it; a page without
|
|
13
|
+
docs: () => options.always ? DOCS + "\nIn this project every page has it; a page goes without with `toc: false` under `plugins:` in its frontmatter:\n\n```markdown\n---\nplugins:\n toc: false\n---\n```\n" : DOCS + "\nA page has it when its frontmatter asks, under `plugins:`:\n\n```markdown\n---\nplugins:\n toc: true\n---\n# A long page\n```\n",
|
|
13
14
|
public: builtinPublic("toc"),
|
|
14
15
|
style: "style.css",
|
|
15
16
|
setup: () => ({
|
|
16
17
|
client: "client.js",
|
|
17
|
-
shell: () => ({ head: `<meta
|
|
18
|
+
shell: () => ({ head: html`<meta
|
|
19
|
+
name="wb-toc"
|
|
20
|
+
content="${options.always ? "always" : "opt-in"}"
|
|
21
|
+
${options.minWidth != null ? html` data-min-width="${String(options.minWidth)}"` : ""}
|
|
22
|
+
${options.maxWidth != null ? html` data-max-width="${String(options.maxWidth)}"` : ""}
|
|
23
|
+
/>` })
|
|
18
24
|
})
|
|
19
25
|
};
|
|
20
26
|
}
|
|
@@ -1 +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>=
|
|
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(){let t=parseFloat(getComputedStyle(e).minWidth)||0;return r.getBoundingClientRect().left>=t+40+16}const c=e=>{let t=/^(\d+(?:\.\d+)?)(px|em|rem|ch|vw)?$/.exec(String(e??``).trim());return t&&Number(t[1])>0?t[1]+(t[2]??`px`):null};function l(){let t=document.querySelector(`meta[name=wb-toc]`),n=d.settings(),r=n&&typeof n==`object`?n:{};for(let[n,i]of[[`minWidth`,`--wb-toc-min-width`],[`maxWidth`,`--wb-toc-max-width`]]){let a=c(r[n])??c(t?.dataset[n]);a?e.style.setProperty(i,a):e.style.removeProperty(i)}}function u(){let t=r.getBoundingClientRect().left;e.style.setProperty(`--wb-toc-right`,`${document.documentElement.clientWidth-t+40}px`),e.style.setProperty(`--wb-toc-room`,`${t-40-16}px`)}let d;function f(){let e=d.settings(),t=document.querySelector(`meta[name=wb-toc]`)?.getAttribute(`content`)===`always`;return e===!1?!1:e===!0||e&&typeof e==`object`?!0:t}function p(){a=f()?[...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;l(),u(),n.hidden=!c||s(),e.hidden=!c||!s()&&!e.classList.contains(`wb-toc-open`),e.classList.toggle(`wb-toc-docked`,s()),h(),g()}function m(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 h(){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(m(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 g(){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 _(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 v=(a,o,s)=>{if(o.kind!==`page`&&o.kind!==`file`)return;d=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(),_(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 c=0,l=e=>()=>{cancelAnimationFrame(c),c=requestAnimationFrame(e)};addEventListener(`scroll`,l(g),{passive:!0}),addEventListener(`resize`,l(p)),i.onRendered(p),o.settings.on(p),i.forms.on(()=>h()),i.events.on(()=>requestAnimationFrame(h)),p()};export{v as default};
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
/* the table of contents (client.ts): in the margin left of the text, or opened from the header */
|
|
2
|
+
/* it fits its items, between a minimum and a maximum (client.ts sets them from the options and the
|
|
3
|
+
page's frontmatter); docked, never wider than the room left of the text */
|
|
2
4
|
.wb-toc {
|
|
3
5
|
position: fixed;
|
|
4
6
|
z-index: var(--layer-aside);
|
|
5
|
-
font: var(--ui-small)/var(--ui-line-height) var(--sans, sans-serif);
|
|
7
|
+
font: var(--ui-small) / var(--ui-line-height) var(--sans, sans-serif);
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
width: max-content;
|
|
10
|
+
min-width: var(--wb-toc-min-width, 160px);
|
|
11
|
+
max-width: var(--wb-toc-max-width, 320px);
|
|
6
12
|
}
|
|
7
13
|
.wb-toc[hidden],
|
|
8
14
|
.wb-toc-toggle[hidden] {
|
|
@@ -10,15 +16,15 @@
|
|
|
10
16
|
}
|
|
11
17
|
.wb-toc-docked {
|
|
12
18
|
top: 72px;
|
|
13
|
-
|
|
14
|
-
width:
|
|
19
|
+
right: var(--wb-toc-right);
|
|
20
|
+
max-width: min(var(--wb-toc-max-width, 320px), var(--wb-toc-room, 320px));
|
|
15
21
|
max-height: calc(100vh - 120px - var(--wb-inset-bottom, 0px));
|
|
16
22
|
overflow: auto;
|
|
17
23
|
}
|
|
18
24
|
.wb-toc-open:not(.wb-toc-docked) {
|
|
19
25
|
top: 52px;
|
|
20
26
|
left: 16px;
|
|
21
|
-
width: min(
|
|
27
|
+
max-width: min(var(--wb-toc-max-width, 320px), 100vw - 32px);
|
|
22
28
|
max-height: calc(100vh - 100px - var(--wb-inset-bottom, 0px));
|
|
23
29
|
overflow: auto;
|
|
24
30
|
padding: var(--space-sm);
|
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
A window: a header with a label, a button that fills the browser window with
|
|
2
2
|
what it shows (the same button, or Esc, puts it back), and one that opens it on
|
|
3
|
-
its own.
|
|
4
|
-
column; `height` (pixels or a CSS length) fixes its height, scrolling inside.
|
|
3
|
+
its own.
|
|
5
4
|
|
|
6
|
-
**
|
|
5
|
+
**Any block goes in one with `compose=window`**: an image, a video, another
|
|
6
|
+
page, a diagram, a grid. Its label is the window's title (or `title="A
|
|
7
|
+
title"`, for a block without a label, such as a fence), and ↗ opens what it
|
|
8
|
+
shows on its own, an image's file or a page's address. `wide` makes it wider
|
|
9
|
+
than the text column.
|
|
10
|
+
|
|
11
|
+
````markdown
|
|
12
|
+
::image[The new onboarding]{src="onboarding.png" compose=window}
|
|
13
|
+
|
|
14
|
+
```mermaid {compose=window title="How a page is served"}
|
|
15
|
+
graph LR; file --> server --> browser
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
:::grid{cols=2 compose=window title="Two options"}
|
|
19
|
+
…
|
|
20
|
+
:::
|
|
21
|
+
````
|
|
22
|
+
|
|
23
|
+
**One image or video**, without it, is just itself:
|
|
7
24
|
|
|
8
25
|
```markdown
|
|
9
26
|
::image[The new onboarding]{src="onboarding.png"}
|
|
@@ -13,17 +30,20 @@ column; `height` (pixels or a CSS length) fixes its height, scrolling inside.
|
|
|
13
30
|
|
|
14
31
|
A video has its controls; `loop`, `autoplay` (which starts it muted, as
|
|
15
32
|
browsers require) and `poster` are as for a `<video>`. A plain markdown image,
|
|
16
|
-
``,
|
|
33
|
+
``, is the same as `::image` without it.
|
|
17
34
|
|
|
18
|
-
**Any markdown**, in `:::window`: a
|
|
19
|
-
|
|
35
|
+
**Any markdown**, in `:::window`: a table, a screenshot with words under it,
|
|
36
|
+
what has no block of its own. When it holds one image or video, ↗ opens that
|
|
37
|
+
file. `height` (pixels or a CSS length) fixes its height, scrolling inside.
|
|
20
38
|
|
|
21
|
-
|
|
22
|
-
:::window[
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
39
|
+
```markdown
|
|
40
|
+
:::window[What each one takes]
|
|
41
|
+
| block | what |
|
|
42
|
+
| --- | --- |
|
|
43
|
+
| `::image` | one image |
|
|
26
44
|
:::
|
|
27
|
-
|
|
45
|
+
```
|
|
28
46
|
|
|
29
|
-
|
|
47
|
+
`compose=window` is this plugin's `compose`: any plugin can compose itself
|
|
48
|
+
around blocks the same way, and a block names several in order:
|
|
49
|
+
`compose=lightbox,window`.
|
|
@@ -15,7 +15,7 @@ function openOf(children) {
|
|
|
15
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
16
|
/** http(s), protocol-relative, or a path on this server; never `javascript:` or `data:`. */
|
|
17
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
|
|
18
|
+
/** ::image[label]{src} and ::video[label]{src loop autoplay muted poster}: one file (in a window with `compose=window`). */
|
|
19
19
|
const media = (kind) => (ctx) => {
|
|
20
20
|
const src = (ctx.attrs.src ?? "").trim();
|
|
21
21
|
if (!src) return html`<pre class="wb-error">
|
|
@@ -24,28 +24,24 @@ ${kind}: needs a src, like ::${kind}[a label]{src="${kind === "image" ? "shot.pn
|
|
|
24
24
|
const alt = ctx.labelText ?? ctx.attrs.alt ?? "";
|
|
25
25
|
const flag = (name) => name in ctx.attrs && raw(` ${name}`);
|
|
26
26
|
const poster = ctx.attrs.poster && safeSrc(ctx.attrs.poster) ? html` poster="${ctx.attrs.poster}"` : "";
|
|
27
|
-
|
|
27
|
+
return kind === "image" ? html`<img src="${src}" alt="${alt}" loading="lazy" />` : html`<video
|
|
28
28
|
src="${src}"
|
|
29
29
|
controls${flag("loop")}${flag("autoplay")}${"autoplay" in ctx.attrs || "muted" in ctx.attrs ? raw(" muted") : ""}
|
|
30
30
|
playsinline
|
|
31
31
|
preload="metadata"
|
|
32
32
|
${poster}${alt ? html` aria-label="${alt}"` : ""}
|
|
33
33
|
></video>`;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
height: height(ctx.attrs.height),
|
|
40
|
-
body
|
|
41
|
-
});
|
|
34
|
+
};
|
|
35
|
+
/** What an image or video shows on its own, for the ↗ of a window around it: its file. */
|
|
36
|
+
const mediaOpen = (ctx) => {
|
|
37
|
+
const src = (ctx.attrs.src ?? "").trim();
|
|
38
|
+
return src && safeSrc(src) ? src : null;
|
|
42
39
|
};
|
|
43
40
|
async function render(ctx) {
|
|
44
41
|
return windowFrame({
|
|
45
42
|
label: ctx.label,
|
|
46
43
|
open: openOf(ctx.children),
|
|
47
44
|
wide: "wide" in ctx.attrs,
|
|
48
|
-
bare: "bare" in ctx.attrs,
|
|
49
45
|
height: height(ctx.attrs.height),
|
|
50
46
|
body: await ctx.toHtml(ctx.children)
|
|
51
47
|
});
|
|
@@ -53,10 +49,22 @@ async function render(ctx) {
|
|
|
53
49
|
function windows() {
|
|
54
50
|
return definePlugin({
|
|
55
51
|
name: "window",
|
|
52
|
+
compose: ({ children, label, open, attrs }) => windowFrame({
|
|
53
|
+
label: attrs.title ? html`${attrs.title}` : label,
|
|
54
|
+
open,
|
|
55
|
+
wide: "wide" in attrs,
|
|
56
|
+
body: children
|
|
57
|
+
}),
|
|
56
58
|
blocks: {
|
|
57
59
|
window: { html: render },
|
|
58
|
-
image: {
|
|
59
|
-
|
|
60
|
+
image: {
|
|
61
|
+
html: media("image"),
|
|
62
|
+
open: mediaOpen
|
|
63
|
+
},
|
|
64
|
+
video: {
|
|
65
|
+
html: media("video"),
|
|
66
|
+
open: mediaOpen
|
|
67
|
+
}
|
|
60
68
|
},
|
|
61
69
|
docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
|
|
62
70
|
});
|
package/dist/src/auth.js
CHANGED
|
@@ -13,12 +13,14 @@ function projectToken(wb) {
|
|
|
13
13
|
fs.writeFileSync(file, token + "\n", { mode: 384 });
|
|
14
14
|
return token;
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
/** `base`: the path the project is served under (see ServerOptions), which its cookie is kept to. */
|
|
17
|
+
function createAuth(wb, base = "") {
|
|
17
18
|
const token = projectToken(wb);
|
|
18
19
|
const same = (a, b) => typeof a === "string" && a.length === b.length && crypto.timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
19
20
|
const cookies = (req) => Object.fromEntries((req.headers.cookie ?? "").split(";").map((c) => c.trim().split("=")).filter(([k]) => k));
|
|
20
|
-
/** Has this request the token, from this origin? */
|
|
21
|
+
/** Has this request the token, from this origin? No request (a page being built) has none. */
|
|
21
22
|
function authorized(req) {
|
|
23
|
+
if (!req) return false;
|
|
22
24
|
const jar = cookies(req);
|
|
23
25
|
if (!(same(jar[COOKIE], token) || same(req.headers["x-whiteboard-token"], token))) return false;
|
|
24
26
|
const origin = req.headers.origin;
|
|
@@ -39,8 +41,8 @@ function createAuth(wb) {
|
|
|
39
41
|
}
|
|
40
42
|
const to = typeof q.to === "string" && q.to.startsWith("/") && !q.to.startsWith("//") ? q.to : "/";
|
|
41
43
|
res.writeHead(302, {
|
|
42
|
-
"set-cookie": `${COOKIE}=${token}; Path
|
|
43
|
-
location: to
|
|
44
|
+
"set-cookie": `${COOKIE}=${token}; Path=${base || "/"}; HttpOnly; SameSite=Lax; Max-Age=31536000`,
|
|
45
|
+
location: base + to
|
|
44
46
|
});
|
|
45
47
|
res.end();
|
|
46
48
|
return true;
|