@bigmistqke/whiteboard 0.6.1 → 0.8.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 +23 -216
- package/bin/whiteboard.ts +82 -239
- package/dist/bin/whiteboard.js +70 -200
- package/dist/client/runtime.js +297 -61
- package/dist/plugins/badge/README.md +3 -1
- package/dist/plugins/badge/public/style.css +17 -0
- package/dist/plugins/chat/public/client.js +2 -2
- package/dist/plugins/chat/public/style.css +19 -6
- package/dist/plugins/code/README.md +10 -0
- package/dist/plugins/code/index.js +31 -22
- package/dist/plugins/code/public/client.js +1 -0
- package/dist/plugins/code/public/style.css +33 -2
- package/dist/plugins/comments/public/client.js +7 -2
- package/dist/plugins/comments/public/style.css +4 -0
- package/dist/plugins/form/public/style.css +2 -0
- package/dist/plugins/grid/public/style.css +0 -5
- package/dist/plugins/iframe/index.js +2 -2
- package/dist/plugins/index.js +5 -1
- package/dist/plugins/lightbox/public/client.js +1 -1
- package/dist/plugins/terminal/index.js +7 -9
- package/dist/plugins/terminal/public/client.js +1 -1
- package/dist/plugins/terminal/public/style.css +3 -3
- package/dist/plugins/timeline/README.md +40 -0
- package/dist/plugins/timeline/index.js +82 -0
- package/dist/plugins/timeline/public/style.css +118 -0
- package/dist/plugins/toc/README.md +13 -13
- package/dist/plugins/toc/index.js +6 -4
- package/dist/plugins/toc/public/client.js +1 -1
- package/dist/plugins/toc/public/style.css +19 -2
- package/dist/plugins/window/index.js +4 -4
- package/dist/solid/index.js +2 -1
- package/dist/src/auth.js +7 -3
- package/dist/src/build.js +159 -0
- package/dist/src/client/page/base.css +74 -35
- package/dist/src/client/page/main.js +16 -5
- package/dist/src/document.js +93 -0
- package/dist/src/events.js +7 -15
- package/dist/src/hub.js +90 -53
- package/dist/src/listen.js +100 -0
- package/dist/src/listeners.js +67 -0
- package/dist/src/pages/index.js +1 -1
- package/dist/src/pages/markdown.js +23 -11
- package/dist/src/pages/render.js +13 -8
- package/dist/src/serve.js +2 -0
- package/dist/src/server.js +204 -514
- package/dist/src/site.js +173 -0
- package/dist/src/status.js +63 -1
- package/dist/src/ws.js +128 -0
- package/package.json +1 -1
- package/plugins/README.md +258 -0
- package/plugins/badge/README.md +3 -1
- package/plugins/badge/public/style.css +17 -0
- package/plugins/chat/client.tsx +34 -6
- package/plugins/chat/public/style.css +19 -6
- package/plugins/code/README.md +10 -0
- package/plugins/code/client.ts +73 -0
- package/plugins/code/index.ts +38 -26
- package/plugins/code/public/style.css +33 -2
- package/plugins/comments/client.ts +56 -6
- package/plugins/comments/public/style.css +4 -0
- package/plugins/form/public/style.css +2 -0
- package/plugins/grid/public/style.css +0 -5
- package/plugins/iframe/index.ts +2 -2
- package/plugins/index.ts +6 -1
- package/plugins/lightbox/client.ts +13 -3
- package/plugins/terminal/client.ts +10 -2
- package/plugins/terminal/index.ts +8 -6
- package/plugins/terminal/public/style.css +3 -3
- package/plugins/timeline/README.md +40 -0
- package/plugins/timeline/index.ts +92 -0
- package/plugins/timeline/public/style.css +118 -0
- package/plugins/toc/README.md +13 -13
- package/plugins/toc/client.ts +58 -32
- package/plugins/toc/index.ts +13 -13
- package/plugins/toc/public/style.css +19 -2
- package/plugins/window/index.ts +4 -4
- package/skills/whiteboard/SKILL.md +3 -1
- package/solid/index.tsx +3 -0
- package/src/auth.ts +7 -2
- package/src/build.ts +213 -0
- package/src/client/forms.ts +102 -5
- package/src/client/page/base.css +74 -35
- package/src/client/page/elsewhere.ts +14 -4
- package/src/client/page/waiting.ts +10 -5
- package/src/client/read.ts +16 -3
- package/src/client/runtime.ts +219 -52
- package/src/client/toast.ts +36 -6
- package/src/define.ts +44 -18
- package/src/document.ts +191 -0
- package/src/events.ts +18 -17
- package/src/hub.ts +102 -56
- package/src/listen.ts +125 -0
- package/src/listeners.ts +95 -0
- package/src/pages/index.ts +1 -1
- package/src/pages/markdown.ts +29 -18
- package/src/pages/render.ts +13 -8
- package/src/serve.ts +2 -0
- package/src/server.ts +223 -611
- package/src/site.ts +165 -0
- package/src/status.ts +100 -0
- package/src/ws.ts +155 -0
|
@@ -13,19 +13,17 @@ const STYLE = "style.css";
|
|
|
13
13
|
* render, and each session's screen is in it as HTML, so a page shows it from its first render on;
|
|
14
14
|
* client.js puts the live terminal in its place.
|
|
15
15
|
*/
|
|
16
|
-
const drawer = (state, screens
|
|
16
|
+
const drawer = (state, screens) => html(_templateObject || (_templateObject = _taggedTemplateLiteral([
|
|
17
17
|
"<aside id=\"wb-terminal\" aria-label=\"Terminal\" data-sessions=\"",
|
|
18
18
|
"\">\n <div class=\"wb-term-grip\" title=\"drag to resize\"></div>\n <div class=\"wb-term-bar\">\n <button type=\"button\" class=\"wb-term-toggle\" title=\"Toggle the terminal (Ctrl+`)\">\n <span class=\"wb-term-chevron\"></span>terminal</button\n ><span class=\"wb-term-status\"></span><span class=\"wb-term-actions\"></span\n ><span class=\"wb-term-tabs\"\n >",
|
|
19
19
|
"</span\n >\n </div>\n <div class=\"wb-term-screen\">\n ",
|
|
20
|
-
"\n </div>\n </aside>\n <script>\n try {\n const t = document.getElementById('wb-terminal'),\n s = sessionStorage,\n o = new URLSearchParams(location.search).get('terminal') === 'open' || s.getItem('wb-terminal-open') === '1'\n t.dataset.state = o ? 'open' : 'collapsed'\n const h = +s.getItem('wb-terminal-height')\n if (h) document.documentElement.style.setProperty('--wb-term-h', h + 'px')\n const tabs = [...t.querySelectorAll('.wb-term-tab')],\n k = s.getItem('wb-terminal-tab'),\n a = tabs.find(b => b.dataset.id === k) ?? tabs[0]\n if (a) {\n t.dataset.tab = a.dataset.id\n a.classList.add('wb-current')\n t.querySelector('.wb-term-placeholder[data-id=\"' + a.dataset.id + '\"]')?.classList.add('wb-current')\n }\n } catch {}\n <\/script
|
|
21
|
-
"\"><\/script>"
|
|
20
|
+
"\n </div>\n </aside>\n <script>\n try {\n const t = document.getElementById('wb-terminal'),\n s = sessionStorage,\n o = new URLSearchParams(location.search).get('terminal') === 'open' || s.getItem('wb-terminal-open') === '1'\n t.dataset.state = o ? 'open' : 'collapsed'\n const h = +s.getItem('wb-terminal-height')\n if (h) document.documentElement.style.setProperty('--wb-term-h', h + 'px')\n const tabs = [...t.querySelectorAll('.wb-term-tab')],\n k = s.getItem('wb-terminal-tab'),\n a = tabs.find(b => b.dataset.id === k) ?? tabs[0]\n if (a) {\n t.dataset.tab = a.dataset.id\n a.classList.add('wb-current')\n t.querySelector('.wb-term-placeholder[data-id=\"' + a.dataset.id + '\"]')?.classList.add('wb-current')\n }\n } catch {}\n <\/script>"
|
|
22
21
|
], [
|
|
23
22
|
"<aside id=\"wb-terminal\" aria-label=\"Terminal\" data-sessions=\"",
|
|
24
23
|
"\">\n <div class=\"wb-term-grip\" title=\"drag to resize\"></div>\n <div class=\"wb-term-bar\">\n <button type=\"button\" class=\"wb-term-toggle\" title=\"Toggle the terminal (Ctrl+\\`)\">\n <span class=\"wb-term-chevron\"></span>terminal</button\n ><span class=\"wb-term-status\"></span><span class=\"wb-term-actions\"></span\n ><span class=\"wb-term-tabs\"\n >",
|
|
25
24
|
"</span\n >\n </div>\n <div class=\"wb-term-screen\">\n ",
|
|
26
|
-
"\n </div>\n </aside>\n <script>\n try {\n const t = document.getElementById('wb-terminal'),\n s = sessionStorage,\n o = new URLSearchParams(location.search).get('terminal') === 'open' || s.getItem('wb-terminal-open') === '1'\n t.dataset.state = o ? 'open' : 'collapsed'\n const h = +s.getItem('wb-terminal-height')\n if (h) document.documentElement.style.setProperty('--wb-term-h', h + 'px')\n const tabs = [...t.querySelectorAll('.wb-term-tab')],\n k = s.getItem('wb-terminal-tab'),\n a = tabs.find(b => b.dataset.id === k) ?? tabs[0]\n if (a) {\n t.dataset.tab = a.dataset.id\n a.classList.add('wb-current')\n t.querySelector('.wb-term-placeholder[data-id=\"' + a.dataset.id + '\"]')?.classList.add('wb-current')\n }\n } catch {}\n <\/script
|
|
27
|
-
|
|
28
|
-
])), JSON.stringify(state), state.sessions.map((s) => html`<button type="button" class="wb-term-tab" data-id="${s.id}">${s.label}</button>`), 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>`), client);
|
|
25
|
+
"\n </div>\n </aside>\n <script>\n try {\n const t = document.getElementById('wb-terminal'),\n s = sessionStorage,\n o = new URLSearchParams(location.search).get('terminal') === 'open' || s.getItem('wb-terminal-open') === '1'\n t.dataset.state = o ? 'open' : 'collapsed'\n const h = +s.getItem('wb-terminal-height')\n if (h) document.documentElement.style.setProperty('--wb-term-h', h + 'px')\n const tabs = [...t.querySelectorAll('.wb-term-tab')],\n k = s.getItem('wb-terminal-tab'),\n a = tabs.find(b => b.dataset.id === k) ?? tabs[0]\n if (a) {\n t.dataset.tab = a.dataset.id\n a.classList.add('wb-current')\n t.querySelector('.wb-term-placeholder[data-id=\"' + a.dataset.id + '\"]')?.classList.add('wb-current')\n }\n } catch {}\n <\/script>"
|
|
26
|
+
])), JSON.stringify(state), state.sessions.map((s) => html`<button type="button" class="wb-term-tab" data-id="${s.id}">${s.label}</button>`), 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>`));
|
|
29
27
|
function terminal() {
|
|
30
28
|
return {
|
|
31
29
|
name: "terminal",
|
|
@@ -36,8 +34,8 @@ function terminal() {
|
|
|
36
34
|
dir: ctx.project.dir,
|
|
37
35
|
home: ctx.dataDir
|
|
38
36
|
});
|
|
39
|
-
const client = ctx.asset(CLIENT);
|
|
40
37
|
return {
|
|
38
|
+
client: CLIENT,
|
|
41
39
|
routes: {
|
|
42
40
|
"GET /sessions": {
|
|
43
41
|
description: "the sessions (the drawer's tabs): id, label, whether each runs",
|
|
@@ -106,10 +104,10 @@ function terminal() {
|
|
|
106
104
|
run: ({ body }) => term.open(body.id, body.path)
|
|
107
105
|
}
|
|
108
106
|
},
|
|
109
|
-
async
|
|
107
|
+
async slots(req) {
|
|
110
108
|
if (!ctx.authorized(req)) return null;
|
|
111
109
|
const state = await term.sessions();
|
|
112
|
-
return {
|
|
110
|
+
return { bottom: drawer(state, await term.screens(state.sessions)) };
|
|
113
111
|
}
|
|
114
112
|
};
|
|
115
113
|
},
|
|
@@ -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{}}},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=
|
|
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=(e,t,n)=>{n.slot(`bottom`,e=>{let t=e.querySelector(`#wb-terminal`);t&&ss(t)})};export{ls as default};
|
|
@@ -303,10 +303,10 @@
|
|
|
303
303
|
--wb-term-h: 320px;
|
|
304
304
|
--wb-term-bar: 34px;
|
|
305
305
|
}
|
|
306
|
-
:root:has(
|
|
306
|
+
:root:has(#wb-terminal) {
|
|
307
307
|
--wb-inset-bottom: var(--wb-term-bar);
|
|
308
308
|
}
|
|
309
|
-
:root:has(
|
|
309
|
+
:root:has(#wb-terminal[data-state='open']) {
|
|
310
310
|
--wb-inset-bottom: calc(var(--wb-term-bar) + var(--wb-term-h));
|
|
311
311
|
}
|
|
312
312
|
|
|
@@ -328,7 +328,7 @@
|
|
|
328
328
|
system-ui,
|
|
329
329
|
sans-serif;
|
|
330
330
|
}
|
|
331
|
-
body:has(
|
|
331
|
+
body:has(#wb-terminal) {
|
|
332
332
|
padding-bottom: var(--wb-inset-bottom);
|
|
333
333
|
}
|
|
334
334
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Steps in order down a line, a dot per step: what was done and what it showed.
|
|
2
|
+
Each step has room for full sentences, unlike a diagram's boxes.
|
|
3
|
+
|
|
4
|
+
A heading starts a step, titled by it: the shallowest headings in the block are
|
|
5
|
+
its steps, whatever their level. Deeper headings are the step's own and stay
|
|
6
|
+
headings in its body ("What it does", "Result"). A step's body is any markdown,
|
|
7
|
+
blocks too: a takeaway that should stand out can be a `:::callout` (the
|
|
8
|
+
timeline around it then takes four colons, `::::timeline`). A `---` starts an
|
|
9
|
+
untitled step. A badge ending a step's heading sits at its right. A
|
|
10
|
+
`:when[2026-11-21 10:43]` in a step's heading is when it happened: shown above
|
|
11
|
+
the title, as written.
|
|
12
|
+
|
|
13
|
+
**Sub steps.** A timeline inside a step is that step's sub steps: drawn a level
|
|
14
|
+
in, on a thinner line, and a timeline inside one of those again a level
|
|
15
|
+
further, to any depth. The outer timeline then needs more colons than the inner
|
|
16
|
+
one (`::::timeline` around `:::timeline`). That is also how steps are grouped:
|
|
17
|
+
a step for the group, its steps in a timeline inside it.
|
|
18
|
+
|
|
19
|
+
````markdown
|
|
20
|
+
::::timeline[Steps so far]
|
|
21
|
+
### :when[2026-11-21 10:43] Made a minimal repro :badge[done]
|
|
22
|
+
A chain of 6,400 closures overflows the stack: the crash is the chain, not
|
|
23
|
+
Solid.
|
|
24
|
+
|
|
25
|
+
### Counted the visits
|
|
26
|
+
5,150 visits for 100 links: each link walks the whole chain again.
|
|
27
|
+
|
|
28
|
+
:::timeline
|
|
29
|
+
### With the probe off
|
|
30
|
+
#### What it does
|
|
31
|
+
Runs the same chain with the probe switched off.
|
|
32
|
+
|
|
33
|
+
#### Result
|
|
34
|
+
The same 5,150: the probe isn't what walks it.
|
|
35
|
+
|
|
36
|
+
### With the cache on
|
|
37
|
+
100 visits: one per link.
|
|
38
|
+
:::
|
|
39
|
+
::::
|
|
40
|
+
````
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { builtinPublic } from "../../src/package.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { definePlugin, html, raw } from "@bigmistqke/whiteboard";
|
|
4
|
+
// plugins/timeline/index.ts
|
|
5
|
+
const text = (node) => node.value ?? (node.children ?? []).map(text).join("");
|
|
6
|
+
/** A when's text. Its `:59` in `19:59` parses as a directive named `59`: put it back as written. */
|
|
7
|
+
const whenText = (node) => (node.children ?? []).map((n) => n.type === "textDirective" ? `:${n.name}${n.children?.length ? `[${text(n)}]` : ""}` : text(n)).join("");
|
|
8
|
+
/** Takes a `:when[…]` out of a heading: its text, and the heading without it. */
|
|
9
|
+
function when(title) {
|
|
10
|
+
const found = title.find((n) => n.type === "textDirective" && n.name === "when");
|
|
11
|
+
if (!found) return {
|
|
12
|
+
when: null,
|
|
13
|
+
title
|
|
14
|
+
};
|
|
15
|
+
const rest = title.filter((n) => n !== found);
|
|
16
|
+
const last = rest[rest.length - 1];
|
|
17
|
+
if (last?.type === "text" && last.value) last.value = last.value.trimEnd();
|
|
18
|
+
const first = rest[0];
|
|
19
|
+
if (first?.type === "text" && first.value) first.value = first.value.trimStart();
|
|
20
|
+
return {
|
|
21
|
+
when: whenText(found).trim(),
|
|
22
|
+
title: rest
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Splits the block's content into steps: a heading at the shallowest level in it starts one, titled
|
|
27
|
+
* by it, and so does a `---`, untitled. Deeper headings are part of a step's body. Content before
|
|
28
|
+
* the first heading is an untitled step.
|
|
29
|
+
*/
|
|
30
|
+
function parse(children) {
|
|
31
|
+
const depth = Math.min(...children.filter((n) => n.type === "heading").map((n) => n.depth));
|
|
32
|
+
const steps = [];
|
|
33
|
+
for (const node of children) if (node.type === "heading" && node.depth === depth) steps.push({
|
|
34
|
+
title: node.children ?? [],
|
|
35
|
+
body: []
|
|
36
|
+
});
|
|
37
|
+
else if (node.type === "thematicBreak") steps.push({
|
|
38
|
+
title: null,
|
|
39
|
+
body: []
|
|
40
|
+
});
|
|
41
|
+
else {
|
|
42
|
+
if (!steps.length) steps.push({
|
|
43
|
+
title: null,
|
|
44
|
+
body: []
|
|
45
|
+
});
|
|
46
|
+
steps[steps.length - 1].body.push(node);
|
|
47
|
+
}
|
|
48
|
+
return steps;
|
|
49
|
+
}
|
|
50
|
+
/** A step: when, title and body; a timeline in its body (its sub steps) renders as its own block. */
|
|
51
|
+
async function renderStep(ctx, step) {
|
|
52
|
+
const split = step.title ? when(step.title) : {
|
|
53
|
+
when: null,
|
|
54
|
+
title: null
|
|
55
|
+
};
|
|
56
|
+
const title = split.title && await ctx.toHtml(split.title);
|
|
57
|
+
const body = await ctx.toHtml(step.body);
|
|
58
|
+
return html`<li class="wb-tl-step">
|
|
59
|
+
${split.when && html`<time class="wb-tl-when">${split.when}</time>`}
|
|
60
|
+
${title && html`<div class="wb-tl-title" data-wb-title>${raw(title)}</div>`}
|
|
61
|
+
${body.trim() && html`<div class="wb-tl-body">${raw(body)}</div>`}
|
|
62
|
+
</li>`;
|
|
63
|
+
}
|
|
64
|
+
async function render(ctx) {
|
|
65
|
+
const steps = await Promise.all(parse(ctx.children).map((step) => renderStep(ctx, step)));
|
|
66
|
+
return html`<div class="wb-timeline">
|
|
67
|
+
${ctx.label && html`<div class="wb-tl-caption">${raw(ctx.label)}</div>`}
|
|
68
|
+
<ol class="wb-tl-steps">
|
|
69
|
+
${steps}
|
|
70
|
+
</ol>
|
|
71
|
+
</div>`;
|
|
72
|
+
}
|
|
73
|
+
function timeline() {
|
|
74
|
+
return definePlugin({
|
|
75
|
+
name: "timeline",
|
|
76
|
+
public: builtinPublic("timeline"),
|
|
77
|
+
style: "style.css",
|
|
78
|
+
blocks: { timeline: { html: render } },
|
|
79
|
+
docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
export { timeline as default, parse, when };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
.wb-timeline {
|
|
2
|
+
margin: 3em 0;
|
|
3
|
+
text-align: left;
|
|
4
|
+
}
|
|
5
|
+
.wb-tl-caption {
|
|
6
|
+
font-family: var(--sans);
|
|
7
|
+
font-size: var(--ui-small);
|
|
8
|
+
color: var(--muted);
|
|
9
|
+
text-transform: uppercase;
|
|
10
|
+
letter-spacing: 0.06em;
|
|
11
|
+
margin-bottom: var(--space-2xl);
|
|
12
|
+
}
|
|
13
|
+
.wb-tl-steps {
|
|
14
|
+
list-style: none;
|
|
15
|
+
margin: 0;
|
|
16
|
+
padding: 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/* a line down the left, a dot per step */
|
|
20
|
+
.wb-tl-steps {
|
|
21
|
+
position: relative;
|
|
22
|
+
padding-left: 28px;
|
|
23
|
+
}
|
|
24
|
+
.wb-tl-steps::before {
|
|
25
|
+
content: '';
|
|
26
|
+
position: absolute;
|
|
27
|
+
left: 7px;
|
|
28
|
+
top: 6px;
|
|
29
|
+
bottom: 6px;
|
|
30
|
+
width: 2px;
|
|
31
|
+
background: var(--border);
|
|
32
|
+
}
|
|
33
|
+
.wb-tl-step {
|
|
34
|
+
position: relative;
|
|
35
|
+
padding-bottom: var(--space-2xl);
|
|
36
|
+
}
|
|
37
|
+
.wb-tl-step:last-child {
|
|
38
|
+
padding-bottom: 0;
|
|
39
|
+
}
|
|
40
|
+
/* the dot sits on the title's first line; a step without a title has it at its top */
|
|
41
|
+
.wb-tl-step:has(> .wb-tl-title)::before {
|
|
42
|
+
display: none;
|
|
43
|
+
}
|
|
44
|
+
.wb-tl-title {
|
|
45
|
+
position: relative;
|
|
46
|
+
}
|
|
47
|
+
.wb-tl-step::before,
|
|
48
|
+
.wb-tl-title::before {
|
|
49
|
+
content: '';
|
|
50
|
+
position: absolute;
|
|
51
|
+
left: -27px;
|
|
52
|
+
top: 0.45em;
|
|
53
|
+
width: 12px;
|
|
54
|
+
height: 12px;
|
|
55
|
+
border-radius: 50%;
|
|
56
|
+
background: var(--bg);
|
|
57
|
+
border: 2px solid var(--accent);
|
|
58
|
+
box-sizing: border-box;
|
|
59
|
+
}
|
|
60
|
+
.wb-tl-when {
|
|
61
|
+
display: block;
|
|
62
|
+
font-family: var(--mono);
|
|
63
|
+
font-size: var(--ui-tiny);
|
|
64
|
+
color: var(--muted);
|
|
65
|
+
line-height: 1.4;
|
|
66
|
+
}
|
|
67
|
+
/* centred on the title's first line (line-height 1.4: its middle is 0.7em down) */
|
|
68
|
+
.wb-tl-title::before {
|
|
69
|
+
top: calc(0.7em - 6px);
|
|
70
|
+
}
|
|
71
|
+
.wb-tl-title {
|
|
72
|
+
font-weight: 600;
|
|
73
|
+
line-height: 1.4;
|
|
74
|
+
}
|
|
75
|
+
.wb-tl-body {
|
|
76
|
+
font-size: var(--ui-text);
|
|
77
|
+
line-height: 1.6;
|
|
78
|
+
margin-top: var(--space-xs);
|
|
79
|
+
}
|
|
80
|
+
.wb-timeline .wb-tl-body > * {
|
|
81
|
+
margin-top: var(--space-md);
|
|
82
|
+
margin-bottom: 0;
|
|
83
|
+
}
|
|
84
|
+
.wb-timeline .wb-tl-body > :first-child {
|
|
85
|
+
margin-top: 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* a timeline inside a step is its sub steps: a level in, a thinner line and smaller rings, the
|
|
89
|
+
same at every depth */
|
|
90
|
+
.wb-tl-body .wb-timeline {
|
|
91
|
+
margin: var(--space-md) 0 0;
|
|
92
|
+
}
|
|
93
|
+
.wb-tl-body .wb-tl-steps {
|
|
94
|
+
padding-left: 20px;
|
|
95
|
+
}
|
|
96
|
+
.wb-tl-body .wb-tl-steps::before {
|
|
97
|
+
left: 4px;
|
|
98
|
+
width: 1px;
|
|
99
|
+
}
|
|
100
|
+
.wb-tl-body .wb-tl-step {
|
|
101
|
+
padding-bottom: var(--space-md);
|
|
102
|
+
}
|
|
103
|
+
.wb-tl-body .wb-tl-step:last-child {
|
|
104
|
+
padding-bottom: 0;
|
|
105
|
+
}
|
|
106
|
+
.wb-tl-body .wb-tl-step::before,
|
|
107
|
+
.wb-tl-body .wb-tl-title::before {
|
|
108
|
+
left: -20px;
|
|
109
|
+
width: 9px;
|
|
110
|
+
height: 9px;
|
|
111
|
+
border-width: 1.5px;
|
|
112
|
+
}
|
|
113
|
+
.wb-tl-body .wb-tl-title::before {
|
|
114
|
+
top: calc(0.7em - 4.5px);
|
|
115
|
+
}
|
|
116
|
+
.wb-tl-body .wb-tl-title {
|
|
117
|
+
font-size: var(--ui-text);
|
|
118
|
+
}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
A table of contents beside the page, from its `##`
|
|
2
|
-
numbered as the page numbers them
|
|
1
|
+
A table of contents beside the page, from its headings (`##` down to
|
|
2
|
+
`######`), numbered as the page numbers them, each section's subsections on a
|
|
3
|
+
line under it. The section being read is marked, a click
|
|
3
4
|
goes to a section, and a section with an unanswered question or an unread
|
|
4
5
|
message has a dot. It sits in the margin left of the text when the window has
|
|
5
|
-
room; else a button in the header opens it.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import toc from '@bigmistqke/whiteboard/toc'
|
|
9
|
-
export default defineConfig({ plugins: [toc()] })
|
|
10
|
-
```
|
|
11
|
-
|
|
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):
|
|
6
|
+
room; else a button in the header opens it. It is built in: a page has it
|
|
7
|
+
when its frontmatter asks, under `plugins:` (where every plugin's settings for
|
|
8
|
+
a page go, by the plugin's name):
|
|
14
9
|
|
|
15
10
|
```markdown
|
|
16
11
|
---
|
|
@@ -20,8 +15,13 @@ plugins:
|
|
|
20
15
|
# A long page
|
|
21
16
|
```
|
|
22
17
|
|
|
23
|
-
To have it on every page,
|
|
24
|
-
with `toc: false` there
|
|
18
|
+
To have it on every page, replace the built-in one in the config; a page then
|
|
19
|
+
goes without with `toc: false` there:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import toc from '@bigmistqke/whiteboard/toc'
|
|
23
|
+
export default defineConfig({ plugins: [toc({ always: true })] })
|
|
24
|
+
```
|
|
25
25
|
|
|
26
26
|
The panel fits its items, between a minimum and a maximum width (160px and
|
|
27
27
|
320px by default). A project sets its own in the options, and a page in its
|
|
@@ -3,9 +3,11 @@ import { html } from "../../src/html.js";
|
|
|
3
3
|
// plugins/toc/index.ts
|
|
4
4
|
const DOCS = `## Table of contents
|
|
5
5
|
|
|
6
|
-
Pages here have a table of contents beside them, made from their
|
|
7
|
-
|
|
8
|
-
in it.
|
|
6
|
+
Pages here have a table of contents beside them, made from their headings,
|
|
7
|
+
\`##\` down to \`######\`: give a long page headings, and the reader can find
|
|
8
|
+
their way in it. Each section's subsections hang on a line under it, so the
|
|
9
|
+
nesting shows. A section with an unanswered question or an unread message has
|
|
10
|
+
a dot.
|
|
9
11
|
`;
|
|
10
12
|
function toc(options = {}) {
|
|
11
13
|
return {
|
|
@@ -15,7 +17,7 @@ function toc(options = {}) {
|
|
|
15
17
|
style: "style.css",
|
|
16
18
|
setup: () => ({
|
|
17
19
|
client: "client.js",
|
|
18
|
-
|
|
20
|
+
slots: () => ({ head: html`<meta
|
|
19
21
|
name="wb-toc"
|
|
20
22
|
content="${options.always ? "always" : "opt-in"}"
|
|
21
23
|
${options.minWidth != null ? html` data-min-width="${String(options.minWidth)}"` : ""}
|
|
@@ -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(){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
|
|
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.setAttribute(`aria-expanded`,`false`),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(t){e.classList.toggle(`wb-toc-open`,t),e.hidden=!t,n.setAttribute(`aria-expanded`,String(t))}function p(){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 m(e){let t=e.cloneNode(!0);return t.querySelectorAll(`.wb-badge`).forEach(e=>e.remove()),t.textContent?.trim()??``}function h(){a=p()?[...r.querySelectorAll(`:scope > :is(h2, h3, h4, h5, h6)`)]:[];let i=[0,0,0,0,0],o=[{level:1,list:t}];t.replaceChildren(),a.forEach((e,t)=>{let n=Number(e.tagName[1]);for(i[n-2]++,i.fill(0,n-1);o.length>1&&o.at(-1).level>=n;)o.pop();let r=o.at(-1);r.item&&!r.item.querySelector(`:scope > ol`)&&r.item.append(document.createElement(`ol`));let a=r.item?r.item.querySelector(`:scope > ol`):r.list,s=document.createElement(`li`);s.dataset.level=String(n);let c=document.createElement(`a`);c.href=`#`,c.dataset.index=String(t),c.innerHTML=`<span class="wb-toc-number"></span><span class="wb-toc-text"></span>`,c.querySelector(`.wb-toc-number`).textContent=i.slice(0,n-1).join(`.`),c.querySelector(`.wb-toc-text`).textContent=m(e),s.append(c),a.append(s),o.push({level:n,list:a,item:s})});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()),_(),v()}function g(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 _(){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(g(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 v(){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 y(e){let t=a[e];t&&(scrollTo({top:Math.max(0,scrollY+t.getBoundingClientRect().top-o()-12),behavior:`smooth`}),s()||f(!1))}const b=(a,o,s)=>{if(o.kind!==`page`&&o.kind!==`file`)return;d=o,r=a.querySelector(`#wb-main`)??a,i=s,s.slot(`aside`,t=>(t.append(e),()=>e.remove())),s.slot(`header`,e=>(e.append(n),()=>n.remove())),t.addEventListener(`click`,e=>{let t=e.target.closest(`a[data-index]`);t&&(e.preventDefault(),y(Number(t.dataset.index)))}),n.addEventListener(`click`,()=>f(!e.classList.contains(`wb-toc-open`))),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(v),{passive:!0}),addEventListener(`resize`,l(h)),i.onRendered(h),o.settings.on(h),i.forms.on(()=>_()),i.events.on(()=>requestAnimationFrame(_)),h()};export{b as default};
|
|
@@ -38,8 +38,19 @@
|
|
|
38
38
|
margin: 0;
|
|
39
39
|
padding: 0;
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
/* the same space above every item, also the first of a nested list (the page's li + li alone
|
|
42
|
+
would leave that one tight against its section) */
|
|
43
|
+
.wb-toc li {
|
|
44
|
+
margin-top: 0.8em;
|
|
45
|
+
}
|
|
46
|
+
.wb-toc > ol > li:first-child {
|
|
47
|
+
margin-top: 0;
|
|
48
|
+
}
|
|
49
|
+
/* a section's subsections hang on a rail under its number, one rail per level */
|
|
50
|
+
.wb-toc ol ol {
|
|
51
|
+
margin-left: var(--space-md);
|
|
52
|
+
padding-left: var(--space-sm);
|
|
53
|
+
border-left: var(--hairline) solid var(--border, #e3e5e9);
|
|
43
54
|
}
|
|
44
55
|
.wb-toc a {
|
|
45
56
|
display: flex;
|
|
@@ -97,3 +108,9 @@
|
|
|
97
108
|
color: var(--text, CanvasText);
|
|
98
109
|
border-color: var(--muted, #696e76);
|
|
99
110
|
}
|
|
111
|
+
/* the panel is open from it */
|
|
112
|
+
.wb-toc-toggle[aria-expanded='true'] {
|
|
113
|
+
color: var(--accent, #1d5bbf);
|
|
114
|
+
border-color: var(--accent, #1d5bbf);
|
|
115
|
+
background: color-mix(in srgb, var(--accent, #1d5bbf) var(--tint-faint), transparent);
|
|
116
|
+
}
|
|
@@ -23,9 +23,9 @@ ${kind}: needs a src, like ::${kind}[a label]{src="${kind === "image" ? "shot.pn
|
|
|
23
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
24
|
const alt = ctx.labelText ?? ctx.attrs.alt ?? "";
|
|
25
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
|
-
return kind === "image" ? html`<img src="${src}" alt="${alt}" loading="lazy" />` : html`<video
|
|
28
|
-
src="${src}"
|
|
26
|
+
const poster = ctx.attrs.poster && safeSrc(ctx.attrs.poster) ? html` poster="${ctx.fileUrl(ctx.attrs.poster)}"` : "";
|
|
27
|
+
return kind === "image" ? html`<img src="${ctx.fileUrl(src)}" alt="${alt}" loading="lazy" />` : html`<video
|
|
28
|
+
src="${ctx.fileUrl(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"
|
|
@@ -35,7 +35,7 @@ ${kind}: needs a src, like ::${kind}[a label]{src="${kind === "image" ? "shot.pn
|
|
|
35
35
|
/** What an image or video shows on its own, for the ↗ of a window around it: its file. */
|
|
36
36
|
const mediaOpen = (ctx) => {
|
|
37
37
|
const src = (ctx.attrs.src ?? "").trim();
|
|
38
|
-
return src && safeSrc(src) ? src : null;
|
|
38
|
+
return src && safeSrc(src) ? ctx.fileUrl(src) : null;
|
|
39
39
|
};
|
|
40
40
|
async function render(ctx) {
|
|
41
41
|
return windowFrame({
|
package/dist/solid/index.js
CHANGED
package/dist/src/auth.js
CHANGED
|
@@ -13,6 +13,11 @@ function projectToken(wb) {
|
|
|
13
13
|
fs.writeFileSync(file, token + "\n", { mode: 384 });
|
|
14
14
|
return token;
|
|
15
15
|
}
|
|
16
|
+
/** From a page of a whiteboard server on this machine, or from no page at all (the command line)? */
|
|
17
|
+
const sameSite = (req) => {
|
|
18
|
+
const origin = req.headers.origin;
|
|
19
|
+
return !origin || /^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(origin);
|
|
20
|
+
};
|
|
16
21
|
/** `base`: the path the project is served under (see ServerOptions), which its cookie is kept to. */
|
|
17
22
|
function createAuth(wb, base = "") {
|
|
18
23
|
const token = projectToken(wb);
|
|
@@ -23,8 +28,7 @@ function createAuth(wb, base = "") {
|
|
|
23
28
|
if (!req) return false;
|
|
24
29
|
const jar = cookies(req);
|
|
25
30
|
if (!(same(jar[COOKIE], token) || same(req.headers["x-whiteboard-token"], token))) return false;
|
|
26
|
-
|
|
27
|
-
if (origin && !/^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(origin)) return false;
|
|
31
|
+
if (!sameSite(req)) return false;
|
|
28
32
|
const site = req.headers["sec-fetch-site"];
|
|
29
33
|
if (site && site !== "same-origin" && site !== "none" && !opensPage(req)) return false;
|
|
30
34
|
return true;
|
|
@@ -53,4 +57,4 @@ function createAuth(wb, base = "") {
|
|
|
53
57
|
token
|
|
54
58
|
};
|
|
55
59
|
}
|
|
56
|
-
export { createAuth, projectToken };
|
|
60
|
+
export { createAuth, projectToken, sameSite };
|