isorite 0.18.0 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +37 -7
- package/package.json +1 -1
- package/web/_app/immutable/assets/0.i592VXJM.css +1 -0
- package/web/_app/immutable/chunks/Co7i-dcu.js +1 -0
- package/web/_app/immutable/chunks/{CL9QeiGC.js → CqmdC7Q3.js} +2 -2
- package/web/_app/immutable/chunks/D4nFtMQC.js +1 -0
- package/web/_app/immutable/chunks/{DyZdoKBK.js → DdegnILL.js} +1 -1
- package/web/_app/immutable/chunks/DjN194Ef.js +1 -0
- package/web/_app/immutable/chunks/{BFOLKM4z.js → lSTs4h6V.js} +1 -1
- package/web/_app/immutable/chunks/{D7yT4F_8.js → ufOJrCuz.js} +1 -1
- package/web/_app/immutable/entry/{app.CyEmP0i2.js → app.BRzQKhKX.js} +2 -2
- package/web/_app/immutable/entry/start.-f1rSSM0.js +1 -0
- package/web/_app/immutable/nodes/0.i_AjenOL.js +11 -0
- package/web/_app/immutable/nodes/{1.kdx6h8ts.js → 1.D6qHWJUF.js} +1 -1
- package/web/_app/immutable/nodes/2.BPWtlg8V.js +1 -0
- package/web/_app/immutable/nodes/3.DaRPyiq0.js +1 -0
- package/web/_app/immutable/nodes/{4.DzS8oPUH.js → 4.CkZ28L5K.js} +1 -1
- package/web/_app/immutable/nodes/5.6ZCfORwJ.js +22 -0
- package/web/_app/immutable/nodes/6.B9EIxq5B.js +1 -0
- package/web/_app/immutable/nodes/{7.CCNCaItj.js → 7.DGJflKit.js} +1 -1
- package/web/_app/version.json +1 -1
- package/web/index.html +14 -14
- package/web/_app/immutable/assets/0.BGpjfMlq.css +0 -1
- package/web/_app/immutable/chunks/Bg-39frG.js +0 -1
- package/web/_app/immutable/chunks/BleKqNM1.js +0 -1
- package/web/_app/immutable/chunks/DQp-M3XN.js +0 -1
- package/web/_app/immutable/entry/start.BxCHvKWL.js +0 -1
- package/web/_app/immutable/nodes/0.Bkbiw_sA.js +0 -11
- package/web/_app/immutable/nodes/2.CtK7BGB8.js +0 -1
- package/web/_app/immutable/nodes/3.D5PZa2kH.js +0 -1
- package/web/_app/immutable/nodes/5.B-1BDKsL.js +0 -19
- package/web/_app/immutable/nodes/6.DDT1DtCg.js +0 -1
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import{$ as e,A as t,B as n,D as r,E as i,F as a,G as o,H as s,I as c,J as l,M as u,N as d,O as f,P as p,Q as m,R as h,T as g,W as _,Y as v,_t as y,a as b,at as x,ct as ee,d as S,dt as C,et as w,f as T,gt as E,ht as D,i as O,it as k,j as A,k as j,l as te,m as ne,mt as M,n as N,nt as P,ot as F,rt as re,tt as I,u as L,ut as R,v as ie,x as z,y as B,z as V}from"../chunks/Cz6kYWmu.js";import{o as ae,s as oe,t as H}from"../chunks/DQp-M3XN.js";import"../chunks/xihTtKlq.js";import{A as U,C as W,D as G,E as se,M as ce,O as le,S as ue,T as de,_ as fe,a as pe,d as me,f as he,g as ge,h as _e,i as ve,k as ye,l as be,m as xe,n as Se,o as Ce,p as we,r as Te,t as K,v as Ee,w as De,x as Oe,y as ke}from"../chunks/CL9QeiGC.js";import{_ as Ae,a as je,b as Me,c as Ne,d as Pe,f as Fe,h as Ie,i as Le,m as Re,n as ze,o as Be,p as Ve,r as He,s as Ue,t as We,u as Ge,v as Ke,x as qe,y as Je}from"../chunks/D7yT4F_8.js";import{i as Ye}from"../chunks/BleKqNM1.js";import{t as Xe}from"../chunks/DyZdoKBK.js";import{n as Ze,t as Qe}from"../chunks/BFOLKM4z.js";import{B as $e,D as q,E as et,F as J,G as tt,H as nt,I as rt,J as Y,K as it,L as at,M as X,N as Z,P as ot,R as st,S as ct,W as lt,X as ut,Y as dt,at as ft,ct as pt,et as mt,it as ht,lt as gt,mt as _t,n as vt,nt as yt,rt as bt,t as xt,ut as St,v as Ct,w as wt,x as Tt,y as Et}from"../chunks/BxTFtVqu.js";import{i as Dt,l as Ot,n as kt,o as At,r as jt}from"../chunks/yxd8jSz3.js";import{a as Mt,o as Nt,r as Pt,s as Ft,t as It}from"../chunks/CkSjC-iE.js";var Lt=[`kit.js`,`chart.js`,`model.js`,`math.js`,`math.css`,`isorite.css`,`plain.css`,`kit.css`],Rt=e=>e.replace(/"/g,`"`).replace(/'/g,`'`).replace(/</g,`<`).replace(/>/g,`>`).replace(/&/g,`&`);function zt(e,t){for(let n of e.matchAll(/<meta\b[^>]*>/gi)){let e=n[0];if((e.match(/\bname\s*=\s*["']([^"']*)["']/i)?.[1])?.toLowerCase()===t)return Rt(e.match(/\bcontent\s*=\s*"([^"]*)"|\bcontent\s*=\s*'([^']*)'/i)?.slice(1).find(e=>e!==void 0)??``)}return null}function Bt(e){return{title:Rt(e.match(/<title[^>]*>([\s\S]*?)<\/title>/i)?.[1]?.trim()??``),description:zt(e,`description`)??``,author:zt(e,`author`)??``,date:zt(e,`date`)??``,kit:zt(e,`isorite:kit`),uses:(zt(e,`isorite:uses`)??``).split(/[\s,]+/).filter(Boolean)}}function Vt(e){let t=[];/<iso-chart[\s>]|\bPlot\.\w/.test(e)&&t.push(`chart`),/<iso-model[\s>]|<iso-chart3d[\s>]|\bTHREE\.\w/.test(e)&&t.push(`model`);let n=e.replace(/<script\b[\s\S]*?<\/script>/gi,``).replace(/<style\b[\s\S]*?<\/style>/gi,``);return(/<iso-math[\s>]|\biso\.math\(|\$\$[\s\S]+?\$\$|\\\(|\$(?=\S)[^$\n]+?(?<=\S)\$(?!\d)/.test(n)||/\biso\.math\(/.test(e))&&t.push(`math`),t}var Ht=`<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data: blob:; font-src data:; media-src data: blob:; connect-src 'none'">`,Ut=e=>e.replace(/<\/(script|style)/gi,`<\\/$1`),Wt=e=>e.replace(/&/g,`&`).replace(/"/g,`"`).replace(/</g,`<`);function Gt(e,t,n={}){let r=n.look??`isorite`,i=n.ground??`lapis`,a=e.replace(/<link\b[^>]*\bhref\s*=\s*["'](?:\.\/)?kit\/[^"']*["'][^>]*>\s*/gi,``).replace(/<script\b[^>]*\bsrc\s*=\s*["'](?:\.\/)?kit\/[^"']*["'][^>]*>\s*<\/script>\s*/gi,``),o=Object.entries(n.data??{}).map(([e,t])=>typeof t==`string`?`<script type="text/plain" data-path="${Wt(e)}">${Ut(t)}<\/script>`:`<script type="application/octet-stream" data-encoding="base64" data-path="${Wt(e)}">${Kt(t)}<\/script>`),s=Vt(a).map(e=>`${e===`math`?`<style>\n${Ut(t[`math.css`])}\n</style>\n`:``}<script>\n${Ut(t[`${e}.js`])}\n<\/script>`),c=[Ht,`<style data-look="isorite">\n${Ut(t[`isorite.css`])}\n</style>`,`<style data-look="plain">\n${Ut(t[`plain.css`])}\n</style>`,`<style>\n${Ut(t[`kit.css`])}\n</style>`,...o,`<script>\n${Ut(t[`kit.js`])}\n<\/script>`,...s].join(`
|
|
2
|
-
`);return(/<head\b[^>]*>/i.test(a)?a.replace(/<head\b[^>]*>/i,e=>`${e}\n${c}\n`):`<!doctype html><html><head><meta charset="utf-8">\n${c}\n</head><body>${a}</body></html>`).replace(/<html\b([^>]*)>/i,(e,t)=>`<html${t.replace(/\s+data-(?:look|ground)\s*=\s*("[^"]*"|'[^']*'|\S+)/gi,``)} data-look="${r}" data-ground="${i}">`)}function Kt(e){let t=``;for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)}var qt=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?$/,Jt=e=>e===``?null:qt.test(e.trim())?+e:e;function*Yt(e,t){let n=``,r=[],i=!1;for(let a=0;a<e.length;a++){let o=e[a];i?o===`"`?e[a+1]===`"`?(n+=`"`,a++):i=!1:n+=o:o===`"`&&n===``?i=!0:o===t?(r.push(n),n=``):o===`
|
|
3
|
-
`||o===`\r`?(o===`\r`&&e[a+1]===`
|
|
4
|
-
`&&a++,r.push(n),n=``,(r.length>1||r[0]!==``)&&(yield r),r=[]):n+=o}r.push(n),(r.length>1||r[0]!==``)&&(yield r)}function Xt(e,t=`,`){let n=Yt(e.replace(/^/,``),t),r=n.next();if(r.done)return[];let i=r.value.map(e=>e.trim()),a=[];for(let e of n)a.push(Object.fromEntries(i.map((t,n)=>[t,Jt(e[n]??``)])));return a}function Zt(e,t){let n=e.toLowerCase().split(`.`).pop();if(n===`json`){let n=JSON.parse(t);if(Array.isArray(n))return n;let r=n&&typeof n==`object`?Object.values(n).find(Array.isArray):null;if(r)return r;throw Error(`${e}: not an array of rows`)}if(n===`jsonl`||n===`ndjson`)return t.split(/\r?\n/).filter(e=>e.trim()).map(e=>JSON.parse(e));if(n===`tsv`)return Xt(t,` `);if(n===`csv`)return Xt(t,`,`);throw Error(`${e}: the kit reads CSV, TSV, JSON and JSON lines`)}function Qt(e){let t=new Set;for(let n of e.slice(0,1e3))for(let e of Object.keys(n))t.add(e);return[...t]}function $t(e,t,n=5){return{path:e,rows:t.length,head:t.slice(0,n),columns:Qt(t).map(e=>{let n=t.map(t=>t[e]),r=n.filter(e=>e!=null&&e!==``),i=n.length-r.length;if(!r.length)return{name:e,type:`empty`,empty:i};if(r.every(e=>typeof e==`number`)){let t=1/0,n=-1/0,a=0;for(let e of r)e<t&&(t=e),e>n&&(n=e),a+=e;return{name:e,type:`number`,min:t,max:n,mean:a/r.length,empty:i}}if(r.every(e=>typeof e==`boolean`))return{name:e,type:`boolean`,empty:i};let a=[...new Set(r.map(String))];return{name:e,type:`text`,distinct:a.length,values:a.slice(0,12),empty:i}})}}function en(e){let t=e=>String(Number.isInteger(e)?e:+e.toPrecision(4)),n=[`${e.path}: ${e.rows} rows, ${e.columns.length} columns`];for(let r of e.columns){let e=r.empty?`, ${r.empty} empty`:``;r.type===`number`?n.push(`- ${r.name}: number, ${t(r.min)} to ${t(r.max)} (mean ${t(r.mean)})${e}`):r.type===`text`?n.push(`- ${r.name}: text, ${r.distinct} distinct: ${r.values.join(`, `)}${r.distinct>r.values.length?`, …`:``}${e}`):n.push(`- ${r.name}: ${r.type}${e}`)}let r=e.columns.map(e=>e.name);return n.push(`First rows:`,r.join(`,`),...e.head.map(e=>r.map(t=>e[t]??``).join(`,`))),n.join(`
|
|
5
|
-
`)}function tn(e,t=-1){if(typeof e!=`number`||Number.isNaN(e))return`–`;if(!Number.isFinite(e))return e>0?`∞`:`−∞`;if(t>=0)return e.toFixed(t).replace(`-`,`−`);if(e===0)return`0`;let n=Math.abs(e);if(n>=.001&&n<1e6)return Number.isInteger(e)?String(e).replace(`-`,`−`):String(+e.toPrecision(3)).replace(`-`,`−`);let[r,i]=e.toExponential(2).split(`e`);return`${String(+r).replace(`-`,`−`)}×10${(e=>e.replace(/[-+\d]/g,e=>({"-":`⁻`,"+":``})[e]??`⁰¹²³⁴⁵⁶⁷⁸⁹`[+e]))(String(+i))}`}var nn=null;function rn(){return nn??=Promise.all(Lt.map(async e=>{let t=await fetch(ae(`/kit/${e}`));if(!t.ok)throw Error(`the kit's ${e} isn't there (${t.status}): build the app again`);return[e,await t.text()]})).then(e=>Object.fromEntries(e)).catch(e=>{throw nn=null,e}),nn}var an=e=>e.split(`/`).slice(0,-1).join(`/`);function on(e,t){let n=an(e).split(`/`).filter(Boolean);for(let e of t.replace(/^\.\//,``).split(`/`))if(e!==``&&e!==`.`){if(e===`..`){if(!n.length)return null;n.pop()}else n.push(e)}return n.join(`/`)}async function sn(e,t){let n=await e.file(t);if(!n)throw Error(`no artifact at ${t}`);let r=new TextDecoder().decode(n.bytes);return{html:r,manifest:Bt(r)}}async function cn(e,t,n){let r={};for(let i of n){let n=on(t,i),a=n===null?null:await e.file(n);a&&(r[i]=/^(text\/|application\/(json|jsonl|x-ndjson))/.test(a.type)?new TextDecoder().decode(a.bytes):a.bytes)}return r}async function ln(e,t){return Gt(e,await rn(),t)}function un(e,t,n,r,i){let a=(t,n=[])=>e.contentWindow?.postMessage({isorite:0,...t},`*`,n),o=async o=>{if(o.source!==e.contentWindow)return;let s=o.data;if(s&&s.isorite===0){if(s.type===`ready`){let e=i.current();a({type:`ground`,ground:e.ground}),a({type:`look`,look:e.look})}else if(s.type===`file`||s.type===`bytes`){let e=String(s.path??``);if(!r().includes(e)){a({type:`reply`,id:s.id,error:`${e} is not in the artifact's manifest (isorite:uses)`});return}let i=on(n,e);try{let n=i===null?null:await t.file(i);if(!n)a({type:`reply`,id:s.id,error:`${e}: no such file beside the artifact`});else if(s.type===`bytes`){let e=n.bytes.slice().buffer;a({type:`reply`,id:s.id,bytes:e},[e])}else a({type:`reply`,id:s.id,text:new TextDecoder().decode(n.bytes)})}catch(t){a({type:`reply`,id:s.id,error:`${e}: ${t.message}`})}}else s.type===`height`?i.onHeight(Number(s.height)||0):s.type===`error`?i.onError(String(s.message)):s.type===`open`&&i.onOpen(String(s.note))}};return addEventListener(`message`,o),{tell:a,stop:()=>removeEventListener(`message`,o)}}function dn(e,t){let n=e.split(/[#?]/)[0].trim();if(!n||/^[a-z][a-z0-9+.-]*:/i.test(n)||n.startsWith(`//`)||!/\.html?$/i.test(n))return null;let r=n.startsWith(`/`)?n.slice(1):on(`${t}.md`,n);return r?decodeURI(r):null}function fn(){let e=document.documentElement.dataset.ground;return e===`lapis`||e===`quartz`?e:matchMedia(`(prefers-color-scheme: light)`).matches?`quartz`:`lapis`}function pn(e){let t=e.replace(/&/g,`&`).replace(/"/g,`"`).replace(/</g,`<`);return`<!doctype html><html lang="en"><head><meta charset="utf-8"><title>${t}</title><meta name="isorite:kit" content="1"><meta name="isorite:uses" content="${t}"></head><body><iso-model src="${t}" height="440"></iso-model></body></html>`}var mn=a(`<p class="problem svelte-klp1mb" role="alert"> </p>`),hn=a(`<!> <iframe sandbox="allow-scripts" class="svelte-klp1mb"></iframe>`,1);function gn(e,t){C(t,!0);let n=O(t,`look`,3,`isorite`),r=x(void 0),i=x(480),a=x(``),c=x(re(fn()));v(()=>{let e=new MutationObserver(()=>{k(c,fn(),!0)});e.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-ground`]});let t=matchMedia(`(prefers-color-scheme: light)`),n=()=>{k(c,fn(),!0)};return t.addEventListener(`change`,n),()=>{e.disconnect(),t.removeEventListener(`change`,n)}});let u=null;v(()=>s(r)?(u=un(s(r),K.api,t.path,()=>t.uses,{onHeight:e=>{k(i,Math.max(120,Math.min(2e4,Math.ceil(e)+4)),!0)},onError:e=>t.onerror?.(e),onOpen:e=>{Ye.open(e.replace(/^\/+/,``).replace(/\.md$/,``))},current:()=>({ground:s(c),look:n()})}),()=>{u?.stop(),u=null}):void 0),v(()=>{if(!s(r))return;let e=s(r),i=t.html,l=o(()=>({look:n(),ground:s(c)}));k(a,``),ln(i,l).then(t=>{e.srcdoc=t},e=>{k(a,e.message,!0)})}),v(()=>{u?.tell({type:`ground`,ground:s(c)})}),v(()=>{u?.tell({type:`look`,look:n()})});var f=hn(),p=w(f),m=e=>{var t=mn(),n=I(t,!0);l(()=>A(n,s(a))),d(e,t)};j(p,e=>{s(a)&&e(m)});var h=P(p,2);let g;te(h,e=>k(r,e),()=>s(r)),l(()=>{T(h,`title`,t.title),g=ie(h,``,g,{height:`${s(i)??``}px`})}),d(e,f),R()}var _n=a(`<p class="stand svelte-16i7bpz"> </p>`),vn=a(`<span> </span><span class="sep svelte-16i7bpz">/</span>`,1),yn=a(`<a class="br svelte-16i7bpz"> </a>`),bn=a(`<span class="br svelte-16i7bpz"> </span>`),xn=a(`<span class="uses">uses <!></span>`),Sn=a(`<span class="faint"> </span>`),Cn=a(`<button type="button" role="radio" class="svelte-16i7bpz"> </button>`),wn=a(`<span class="tools svelte-16i7bpz"><span class="seg svelte-16i7bpz" role="radiogroup" aria-label="look"></span> <button type="button" class="btn quiet svelte-16i7bpz">standalone</button></span>`),Tn=a(`<p class="said svelte-16i7bpz" role="status"> </p>`),En=a(`<li> </li>`),Dn=a(`<ul class="errors svelte-16i7bpz" role="alert"></ul>`),On=a(`<p class="problem svelte-16i7bpz" role="alert"> </p>`),kn=a(`<img class="picture svelte-16i7bpz"/>`),An=a(`<iframe class="pdf svelte-16i7bpz"></iframe>`),jn=a(`<th> </th>`),Mn=a(`<td> </td>`),Nn=a(`<tr></tr>`),Pn=a(`<p class="faint"> </p>`),Fn=a(`<pre class="shape svelte-16i7bpz"> </pre> <div class="rows svelte-16i7bpz"><table class="svelte-16i7bpz"><thead><tr></tr></thead><tbody></tbody></table></div> <!>`,1),In=a(`<article class="file svelte-16i7bpz"><header><h1 class="serif svelte-16i7bpz"> </h1> <!> <div class="label svelte-16i7bpz"><span class="kind svelte-16i7bpz"><!> </span> <span class="path svelte-16i7bpz"><!><span class="name svelte-16i7bpz"> </span></span> <!> <!> <!></div> <!> <!></header> <!> <!></article>`);function Ln(t,n){C(n,!0);let a=F(()=>W(n.path)??`misc`),o=F(()=>n.path.split(`/`).at(-1)??n.path),c=F(()=>n.path.split(`/`).slice(0,-1)),u=/\.(glb|gltf|stl|obj)$/i,f=/\.(csv|tsv|json|jsonl|ndjson)$/i,m=x(``),h=x(null),g=x(null),_=x(null),y=x(re([])),b=x(`isorite`),ee=x(``);v(()=>{let e=n.path,t=s(a);k(m,``),k(h,null),k(g,null),k(_,null),k(y,[],!0),k(ee,``);let r;return(async()=>{if(t===`artifact`){let{html:t,manifest:n}=await sn(K.api,e);k(h,{html:t,title:n.title||e.split(`/`).at(-1),description:n.description,uses:n.uses});return}if(u.test(e)){k(h,{html:pn(e.split(`/`).at(-1)),title:e.split(`/`).at(-1),description:``,uses:[e.split(`/`).at(-1)]});return}let n=await K.api.file(e);if(!n)throw Error(`no file at ${e}`);if((t===`image`||n.type===`application/pdf`)&&(r=URL.createObjectURL(new Blob([n.bytes],{type:n.type}))),k(g,{size:n.bytes.length,type:n.type,...r?{url:r}:{}}),t===`data`&&f.test(e)){let t=Zt(e,new TextDecoder().decode(n.bytes));k(_,{shape:$t(e,t),rows:t.slice(0,50)})}})().catch(e=>{k(m,e.message,!0)}),()=>{r&&URL.revokeObjectURL(r)}});let S=F(()=>s(h)?.title??s(o)),E=e=>e<1024?`${e} bytes`:e<1024**2?`${(e/1024).toFixed(1)} kB`:`${(e/1024**2).toFixed(1)} MB`,O=e=>typeof e==`number`?tn(e):String(e??``);async function te(){if(s(h))try{let e=await ln(s(h).html,{look:s(b),ground:fn(),data:await cn(K.api,n.path,s(h).uses)}),t=document.createElement(`a`);t.href=URL.createObjectURL(new Blob([e],{type:`text/html`})),t.download=s(o).replace(/\.html?$/i,``)+`.standalone.html`,t.click(),setTimeout(()=>URL.revokeObjectURL(t.href),1e3),k(ee,`saved ${t.download}, ${E(e.length)}`)}catch(e){k(m,e.message,!0)}}let ne=e=>{let t=on(n.path,e);return t===null?null:ve(t)};var N=In(),L=e(N),ie=e(L),z=I(ie,!0),ae=P(ie,2),oe=e=>{var t=_n(),n=I(t,!0);l(()=>A(n,s(h).description)),d(e,t)};j(ae,e=>{s(h)?.description&&e(oe)});var H=P(ae,2),U=e(H),G=e(U);Ue(G,{get kind(){return s(a)}});var se=P(G,1,!0);D(U);var ce=P(U,2),le=e(ce);i(le,16,()=>s(c),e=>e,(e,t)=>{var n=vn(),r=w(n),i=I(r,!0);M(),l(()=>A(i,t)),d(e,n)});var ue=P(le),de=I(ue,!0);D(ce);var fe=P(ce,2),pe=t=>{var n=xn(),r=P(e(n));i(r,16,()=>s(h).uses,e=>e,(e,t)=>{let n=F(()=>ne(t));var r=p(),i=w(r),a=e=>{var r=yn(),i=I(r,!0);l(()=>{T(r,`href`,s(n)),A(i,t)}),d(e,r)},o=e=>{var n=bn(),r=I(n,!0);l(()=>A(r,t)),d(e,n)};j(i,e=>{s(n)?e(a):e(o,-1)}),d(e,r)}),D(n),d(t,n)};j(fe,e=>{s(a)===`artifact`&&s(h)?.uses.length&&e(pe)});var me=P(fe,2),he=e=>{var t=Sn(),n=I(t,!0);l(e=>A(n,e),[()=>E(s(g).size)]),d(e,t)};j(me,e=>{s(g)&&e(he)});var ge=P(me,2),_e=t=>{var n=wn(),r=e(n);i(r,20,()=>[`isorite`,`plain`],e=>e,(e,t)=>{var n=Cn(),r=I(n,!0);l(()=>{T(n,`aria-checked`,s(b)===t),A(r,t)}),V(`click`,n,()=>k(b,t,!0)),d(e,n)}),D(r);var a=P(r,2);D(n),V(`click`,a,()=>void te()),d(t,n)};j(ge,e=>{s(a)===`artifact`&&e(_e)}),D(H);var ye=P(H,2),be=e=>{var t=Tn(),n=I(t,!0);l(()=>A(n,s(ee))),d(e,t)};j(ye,e=>{s(ee)&&e(be)});var xe=P(ye,2),Se=e=>{var t=Dn();i(t,20,()=>s(y),e=>e,(e,t)=>{var n=En(),r=I(n,!0);l(()=>A(r,t)),d(e,n)}),D(t),d(e,t)};j(xe,e=>{s(y).length&&e(Se)}),D(L);var Ce=P(L,2),we=e=>{var t=On(),n=I(t,!0);l(()=>A(n,s(m))),d(e,t)};j(Ce,e=>{s(m)&&e(we)});var Te=P(Ce,2),Ee=e=>{gn(e,{get path(){return n.path},get html(){return s(h).html},get uses(){return s(h).uses},get look(){return s(b)},get title(){return s(S)},onerror:e=>{s(y).includes(e)||k(y,[...s(y),e],!0)}})},De=e=>{var t=kn();l(()=>{T(t,`src`,s(g).url),T(t,`alt`,s(o))}),d(e,t)},Oe=e=>{var t=An();l(()=>{T(t,`src`,s(g).url),T(t,`title`,s(o))}),d(e,t)},ke=t=>{var n=Fn(),a=w(n),o=I(a,!0),c=P(a,2),u=e(c),f=e(u),p=e(f);i(p,21,()=>s(_).shape.columns,e=>e.name,(e,t)=>{var n=jn();let r;var i=I(n,!0);l(()=>{r=B(n,1,`svelte-16i7bpz`,null,r,{n:s(t).type===`number`}),A(i,s(t).name)}),d(e,n)}),D(p),D(f);var m=P(f);i(m,21,()=>s(_).rows,r,(e,t)=>{var n=Nn();i(n,21,()=>s(_).shape.columns,e=>e.name,(e,n)=>{var r=Mn();let i;var a=I(r,!0);l(e=>{i=B(r,1,`svelte-16i7bpz`,null,i,{n:s(n).type===`number`}),A(a,e)},[()=>O(s(t)[s(n).name])]),d(e,r)}),D(n),d(e,n)}),D(m),D(u),D(c);var h=P(c,2),g=e=>{var t=Pn(),n=I(t);l(()=>A(n,`the first ${s(_).rows.length??``} of ${s(_).shape.rows??``} rows`)),d(e,t)};j(h,e=>{s(_).shape.rows>s(_).rows.length&&e(g)}),l(e=>A(o,e),[()=>en({...s(_).shape,head:[]}).split(`
|
|
6
|
-
First rows:`)[0]]),d(t,n)},Ae=e=>{var t=Pn(),n=I(t,!0);l(()=>A(n,s(g).type)),d(e,t)};j(Te,e=>{s(h)?e(Ee):s(a)===`image`&&s(g)?.url?e(De,1):s(g)?.type===`application/pdf`&&s(g).url?e(Oe,2):s(_)?e(ke,3):s(g)&&e(Ae,4)}),D(N),l(()=>{A(z,s(S)),A(se,Ne[s(a)]),A(de,s(o))}),d(t,N),R()}h([`click`]);var Rn=c(`<svg class="logo drawing svelte-1dt0rua" viewBox="-0.4 -6.5 32.4 7"><path pathLength="1" d="M2 0L2 -2L0 -4M2 -2L2 -4L4 -6M5.6 0L6.6 0L7.6 -1L5.6 -3L6.6 -4L7.6 -4M11.2 0L13.2 -2L11.2 -4L9.2 -2ZM14.8 0L14.8 -2L15.8 -3L16.8 -4M14.8 -2L14.8 -4M20.4 0L20.4 -2L18.4 -4M20.4 -2L20.4 -4L22.4 -6M26 0L25 -1L25 -4L24 -4M25 -4L26 -4M25 -4L25 -5M30.6 0L29.6 0L27.6 -2L29.6 -4L31.6 -2L27.6 -2" class="svelte-1dt0rua"></path></svg>`);function zn(e,t){let n=O(t,`width`,3,26),r=O(t,`label`,3,``);var i=Rn();l(()=>{T(i,`width`,n()),T(i,`height`,n()*7/32.4),T(i,`role`,r()?`img`:void 0),T(i,`aria-label`,r()||void 0),T(i,`aria-hidden`,r()?void 0:`true`)}),d(e,i)}var Bn=class{note;#e=x([]);get entries(){return s(this.#e)}set entries(e){k(this.#e,e)}#t=x(null);get failed(){return s(this.#t)}set failed(e){k(this.#t,e)}#n=x(null);get cursor(){return s(this.#n)}set cursor(e){k(this.#n,e)}#r=x(``);get busy(){return s(this.#r)}set busy(e){k(this.#r,e,!0)}#i=x(null);get editing(){return s(this.#i)}set editing(e){k(this.#i,e,!0)}stop=null;constructor(e){this.note=e}#a=F(()=>_e(this.entries));get waiting(){return s(this.#a)}set waiting(e){k(this.#a,e)}#o=F(()=>this.waiting.filter(e=>e.form===`insert`));get proposals(){return s(this.#o)}set proposals(e){k(this.#o,e)}#s=F(()=>{let e=[],t=ke(this.note.text);for(let n of this.waiting)if(n.form===`rewrite`)for(let r of n.open??[]){let i=n.regions[r],a=me(this.note.text,i.old),o=a?this.note.text.slice(0,a.from).split(`
|
|
7
|
-
`).length-1:-1,s=t.find(e=>e.from<=o&&o<e.to);e.push({key:`r:${n.id}:${r}`,proposal:n,k:r,at:a,block:/\n/.test(i.old.text.trim())||/\n/.test(i.new.trim()),code:!!(s&&/^\s*(```|~~~)/.test(s.text))})}return e.sort((e,t)=>(e.at?.from??1/0)-(t.at?.from??1/0))});get changes(){return s(this.#s)}set changes(e){k(this.#s,e)}#c=F(()=>{try{let e=ue(this.note.text)[0];return{lines:e.split(`
|
|
8
|
-
`).length-1,chars:e.length}}catch{return{lines:0,chars:0}}});get head(){return s(this.#c)}set head(e){k(this.#c,e)}get foot(){return this.note.text.split(`
|
|
9
|
-
`).length}placed(e){return we(this.note.text,e)!==null}#l=F(()=>{let e=[];for(let t of this.proposals){let n=we(this.note.text,t);e.push({key:`p:${t.id}`,line:n?.form===`insert`?n.line:this.foot})}this.changes.some(e=>!e.at)&&e.push({key:`lost`,line:this.foot}),this.failed&&e.push({key:`failed`,line:this.failed.line});let t=this.changes.filter(e=>e.at);for(let n of t)n.block&&e.push({key:n.key,line:this.note.text.slice(0,n.at.to).split(`
|
|
10
|
-
`).length});return{blocks:e,old:t.map(e=>e.at),inline:t.filter(e=>!e.block).map(e=>({key:e.key,at:e.at.to}))}});get layout(){return s(this.#l)}set layout(e){k(this.#l,e)}async open(){this.stop=K.on(e=>this.hear(e));try{this.entries=await K.api.journal(this.note.id)}catch{}}close(){this.stop?.()}hear(e){if(e.type!==`journal`||e.id!==this.note.id||this.entries.some(t=>t.id===e.entry.id))return;this.entries=[...this.entries,e.entry];let t=e.entry.kind===`discard`||e.entry.kind===`change`?e.entry.proposal:void 0;t&&this.editing?.id===t&&(this.editing=null)}say(e,t){this.failed={line:e??this.foot,message:t.message}}lineOf(e){return this.layout.blocks.find(t=>t.key===`p:${e.id}`)?.line}edit(e){this.editing={id:e.id,text:e.text}}async done(e){let t=this.editing;if(t?.id===e.id)try{await K.api.revise(this.note.id,e.id,t.text),this.editing=null}catch(t){this.say(this.lineOf(e),t)}}async keep(e){this.busy=e.id;try{await this.note.save(),this.editing?.id===e.id&&await this.done(e),this.note.adopt(await K.api.keep(this.note.id,e.id))}catch(t){this.say(this.lineOf(e),t)}finally{this.busy=``}}async discard(e){this.busy=e.id;try{await K.api.discard(this.note.id,e.id)}catch(t){this.say(this.lineOf(e),t)}finally{this.busy=``}}async keepChange(e){this.busy=e.key;try{await this.note.save(),this.note.adopt(await K.api.keep(this.note.id,e.proposal.id,e.k))}catch(e){this.say(void 0,e)}finally{this.busy=``}}async discardChange(e){this.busy=e.key;try{await K.api.discard(this.note.id,e.proposal.id,e.k)}catch(e){this.say(void 0,e)}finally{this.busy=``}}async settleAll(e){this.busy=`all`;try{e&&await this.note.save();for(let t of[...this.changes].reverse())(!e||t.at)&&(e?this.note.adopt(await K.api.keep(this.note.id,t.proposal.id,t.k)):await K.api.discard(this.note.id,t.proposal.id,t.k))}catch(e){this.say(void 0,e)}finally{this.busy=``}}},Vn=1500,Hn=e=>be(`isorite.draft.${e}`);function Un(e,t){try{if(t===void 0)return JSON.parse(localStorage.getItem(Hn(e))??`null`);t?localStorage.setItem(Hn(e),JSON.stringify(t)):localStorage.removeItem(Hn(e))}catch{}return null}var Wn=e=>typeof e==`string`?e:e==null?``:String(e),Gn=class{id;#e=x(`loading`);get loaded(){return s(this.#e)}set loaded(e){k(this.#e,e,!0)}#t=x(`saved`);get saving(){return s(this.#t)}set saving(e){k(this.#t,e,!0)}#n=x(``);get message(){return s(this.#n)}set message(e){k(this.#n,e,!0)}#r=x(``);get text(){return s(this.#r)}set text(e){k(this.#r,e,!0)}#i=x(void 0);get theirs(){return s(this.#i)}set theirs(e){k(this.#i,e)}#a=x(0);get revision(){return s(this.#a)}set revision(e){k(this.#a,e,!0)}base=``;saved=``;timer=null;inFlight=null;stop=null;constructor(e){this.id=e}#o=F(()=>{try{return ce(this.text)[0]??{}}catch{return null}});get meta(){return s(this.#o)}set meta(e){k(this.#o,e)}#s=F(()=>{let e=this.meta??{};return{title:Wn(e.title),type:Wn(e.type),description:Wn(e.description),tags:Array.isArray(e.tags)?e.tags.map(String).join(`, `):Wn(e.tags)}});get fields(){return s(this.#s)}set fields(e){k(this.#s,e)}#c=F(()=>{try{return ue(this.text)[2]}catch{return this.text}});get body(){return s(this.#c)}set body(e){k(this.#c,e)}async open(){try{let e=await K.api.readNote(this.id),t=Un(this.id);this.take(e),t&&t.text!==e.text&&(this.text=t.text,t.base===e.version?this.changed():(this.theirs=e,this.saving=`conflict`,Un(this.id,t))),this.loaded=`ready`,this.stop=K.on(e=>this.hear(e))}catch(e){this.loaded=e instanceof Ce&&e.status===404?`missing`:`error`,this.message=e.message}}async close(){this.stop?.(),await this.save()}adopt(e){this.take(e)}async restore(e){await this.settle(),this.take(await K.api.restore(this.id,e,this.base))}async move(e){await this.settle();let t=await K.api.moveNote(this.id,e,this.base);return this.stop?.(),t.id}async setDone(e){await this.settle(),this.take(await K.api.setDone(this.id,e,this.base)),await K.refresh()}async remove(){await this.settle(),await K.api.deleteNote(this.id,this.base),this.stop?.()}async settle(){if(this.saving!==`saved`&&await this.save(),this.saving!==`saved`)throw Error(this.message||`the note could not be saved first`)}take(e){this.text=this.saved=e.text,this.base=e.version,this.theirs=void 0,this.saving=`saved`,this.message=``,Un(this.id,null),this.revision++}setText(e){e!==this.text&&(this.text=e,this.changed())}setBody(e){e!==this.body&&this.setText(Oe(this.text,{},e))}setFields(e){let t={};for(let[n,r]of Object.entries(e)){let e=r.trim();t[n]=n===`tags`?e?e.split(`,`).map(e=>e.trim()).filter(Boolean):null:e||null}this.setMeta(t)}setMeta(e){try{this.setText(Oe(this.text,e,null))}catch{}}changed(){Un(this.id,{base:this.base,text:this.text}),this.saving!==`conflict`&&(this.saving=`unsaved`,this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.save()},Vn))}save(){return this.timer&&=(clearTimeout(this.timer),null),this.inFlight=(this.inFlight??Promise.resolve()).then(()=>this.send()),this.inFlight}async send(){if(this.loaded!==`ready`||this.saving===`conflict`||this.text===this.saved)return;let e=this.text;this.saving=`saving`;try{let t=await K.api.saveNote(this.id,{base:this.base,text:e});this.base=t.version,this.saved=e,this.message=``,this.text===e?(this.saving=`saved`,Un(this.id,null)):this.changed()}catch(t){if(t instanceof Ce&&t.status===409&&t.current!==void 0){if(t.current?.text===e)return this.take(t.current);this.theirs=t.current,this.saving=`conflict`}else this.saving=`failed`,this.message=t.message,this.timer=setTimeout(()=>{this.save()},5e3)}}hear(e){e.type===`note-changed`&&e.id===this.id&&e.version!==this.base&&e.version!==he(this.text)&&this.saving===`saved`&&K.api.readNote(this.id).then(e=>{this.saving===`saved`&&e.version!==this.base&&this.take(e)},()=>void 0)}keepMine(){let e=this.theirs;return e===void 0?Promise.resolve():(this.theirs=void 0,this.saving=`unsaved`,e===null?K.api.createNote(this.id,this.text).then(e=>this.take(e),e=>{this.saving=`failed`,this.message=e.message}):(this.base=e.version,this.saved=e.text,this.save()))}keepTheirs(){this.theirs&&this.take(this.theirs)}},Kn=a(`<button type="button" role="radio" data-lustre=""><!> </button>`),qn=a(`<span class="field svelte-ml08v2"><!></span>`),Jn=a(`<button type="button" class="seg svelte-ml08v2"> </button>`),Yn=a(`<input class="name svelte-ml08v2" spellcheck="false" autocomplete="off" aria-label="name"/>`),Xn=a(`<button type="button" class="seg name svelte-ml08v2"> </button>`),Zn=a(`<span class="path svelte-ml08v2"><!> <span class="sep svelte-ml08v2">/</span> <!></span>`),Qn=a(`<button type="button" class="br svelte-ml08v2"> </button>`),$n=a(`<input class="adding svelte-ml08v2" size="10" aria-label="new tag"/>`),er=a(`<button type="button" class="add svelte-ml08v2" aria-label="add a tag">+</button>`),tr=a(`<button type="button" class="x svelte-ml08v2">×</button>`),nr=a(`<a class="br svelte-ml08v2"> </a><!>`,1),rr=a(`<option> </option>`),ir=a(`<input class="adding svelte-ml08v2" list="label-notes" size="18"/> <datalist id="label-notes"></datalist>`,1),ar=a(`<button type="button" class="add svelte-ml08v2">+</button>`),or=a(`<div><span class="word svelte-ml08v2"> </span> <!> <!> <span class="grow svelte-ml08v2"></span> <button type="button"> </button></div>`),sr=a(`<p class="problem svelte-ml08v2" role="alert"> </p>`),cr=a(`<textarea rows="1" aria-label="description"></textarea> <div class="label svelte-ml08v2"><span class="kinds svelte-ml08v2" role="radiogroup" aria-label="kind"></span> <!> <span class="parts svelte-ml08v2"><!> <!></span></div> <!> <!>`,1);function lr(t,r){C(r,!0);let a=F(()=>!r.note.id.startsWith(`@`)),o=x(``),c=[[`note`,`concept`,`Concept`],[`question`,`question`,`Question`],[`problem`,`problem`,`Problem`]];function u(e,t,n){e!==r.kind&&(r.note.setFields({type:t}),_().then(()=>Ae(n,!0)))}let f=e=>e.split(`/`).slice(0,-1).join(`/`),p=e=>e.split(`/`).at(-1),m=x(null),h=x(``);async function g(e,t){let n=e=>e.trim().replace(/^\/+|\/+$/g,``).replace(/\.md$/,``),i=[n(e),n(t)].filter(Boolean).join(`/`);if(k(m,null),n(t)&&i!==r.note.id){k(o,``);try{let e=await r.note.move(i);await K.refresh(),await H(ve(e),{replaceState:!0})}catch(e){k(o,e.message,!0)}}}let v=e=>{let t=e instanceof HTMLInputElement?e:e.querySelector(`input`);t?.focus(),t?.select()},b=F(()=>r.note.fields.tags.split(`,`).map(e=>e.trim()).filter(Boolean)),E=x(!1);function O(e){let t=e.trim();k(E,!1),t&&!s(b).includes(t)&&r.note.setMeta({tags:[...s(b),t]})}let te=e=>r.note.setMeta({tags:s(b).filter(t=>t!==e).length?s(b).filter(t=>t!==e):null}),M=F(()=>r.kind===`note`?null:De[r.kind]),N=F(()=>s(M)?le(r.note.meta?.[s(M)]):[]),re=F(()=>s(M)?[...new Set([...s(N),...K.listing.notes.find(e=>e.id===r.note.id)?.attached??[]])]:[]),L=e=>K.listing.notes.find(t=>t.id===e)?.title??p(e),ie=x(!1);function ae(e){k(ie,!1);let t=e.trim().replace(/^\/+/,``).replace(/\.md$/,``),n=K.listing.notes.find(e=>e.id===t||e.title.toLowerCase()===t.toLowerCase());s(M)&&n&&!s(N).includes(n.id)&&n.id!==r.note.id&&r.note.setMeta({[s(M)]:[...s(N),n.id]})}let oe=e=>{s(M)&&r.note.setMeta({[s(M)]:s(N).filter(t=>t!==e).length?s(N).filter(t=>t!==e):null})};var U=cr(),W=w(U);ee(W);let G;var se=P(W,2),ce=e(se);i(ce,21,()=>c,([e,t,n])=>e,(t,n)=>{var i=F(()=>y(s(n),3));let a=()=>s(i)[0],o=()=>s(i)[1],c=()=>s(i)[2];var f=Kn(),p=e(f);{let e=F(()=>a()===`note`?`concept`:a());Ue(p,{get kind(){return s(e)}})}var m=P(p,1,!0);D(f),l(()=>{B(f,1,`slot ${a()??``}`,`svelte-ml08v2`),T(f,`aria-checked`,r.kind===a()),A(m,o())}),V(`click`,f,e=>u(a(),c(),e.currentTarget)),d(t,f)}),D(ce);var ue=P(ce,2),de=t=>{var i=Zn(),a=e(i),o=t=>{var n=qn(),i=e(n);Qe(i,{id:`note-folder`,quiet:!0,label:`folder`,placeholder:`the top of the base`,onpick:e=>void g(e,p(r.note.id)),onkeydown:e=>{e.key===`Escape`&&k(m,null)},get value(){return s(h)},set value(e){k(h,e,!0)}}),D(n),z(n,e=>v?.(e)),d(t,n)},c=e=>{var t=Jn(),n=I(t,!0);l((e,r)=>{T(t,`aria-label`,e),A(n,r)},[()=>f(r.note.id)?void 0:`the top of the base`,()=>f(r.note.id).replaceAll(`/`,` / `)||`·`]),V(`click`,t,()=>{k(h,f(r.note.id),!0),k(m,`folder`)}),d(e,t)};j(a,e=>{s(m)===`folder`?e(o):e(c,-1)});var u=P(a,4),_=e=>{var t=Yn();S(t),z(t,e=>v?.(e)),l((e,n)=>{ne(t,e),T(t,`size`,n)},[()=>p(r.note.id),()=>Math.max(8,p(r.note.id).length)]),n(`blur`,t,e=>void g(f(r.note.id),e.currentTarget.value)),V(`keydown`,t,e=>{e.key===`Enter`?e.currentTarget.blur():e.key===`Escape`&&k(m,null)}),d(e,t)},y=e=>{var t=Xn(),n=I(t,!0);l(e=>A(n,e),[()=>p(r.note.id)]),V(`click`,t,()=>k(m,`name`)),d(e,t)};j(u,e=>{s(m)===`name`?e(_):e(y,-1)}),D(i),d(t,i)};j(ue,e=>{s(a)&&e(de)});var fe=P(ue,2),pe=e(fe);i(pe,16,()=>s(b),e=>e,(e,t)=>{var n=Qn(),r=I(n,!0);l(()=>{T(n,`aria-label`,`tag ${t??``}: remove`),A(r,t)}),V(`click`,n,()=>te(t)),d(e,n)});var me=P(pe,2),he=e=>{var t=$n();z(t,e=>v?.(e)),n(`blur`,t,e=>O(e.currentTarget.value)),V(`keydown`,t,e=>{e.key===`Enter`?e.currentTarget.blur():e.key===`Escape`&&k(E,!1)}),d(e,t)},ge=e=>{var t=er();V(`click`,t,()=>k(E,!0)),d(e,t)};j(me,e=>{s(E)?e(he):e(ge,-1)}),D(fe),D(se);var _e=P(se,2),ye=t=>{var a=or(),o=e(a),c=I(o,!0),u=P(o,2);i(u,16,()=>s(re),e=>e,(e,t)=>{var n=nr(),r=w(n),i=I(r,!0),a=P(r),o=e=>{var n=tr();l(e=>T(n,`aria-label`,`${e??``}: take away`),[()=>L(t)]),V(`click`,n,()=>oe(t)),d(e,n)},c=F(()=>s(N).includes(t));j(a,e=>{s(c)&&e(o)}),l((e,t)=>{T(r,`href`,e),A(i,t)},[()=>ve(t),()=>L(t)]),d(e,n)});var f=P(u,2),p=e=>{var t=ir(),a=w(t);z(a,e=>v?.(e));var o=P(a,2);i(o,21,()=>K.listing.notes.filter(e=>e.id!==r.note.id&&!e.id.startsWith(`@`)),e=>e.id,(e,t)=>{var n=rr(),r=I(n,!0),i={};l(()=>{A(r,s(t).title),i!==(i=s(t).id)&&(n.value=(n.__value=i)??``)}),d(e,n)}),D(o),l(()=>T(a,`aria-label`,`a note it's ${s(M)===`about`?`about`:`using`}`)),n(`blur`,a,e=>ae(e.currentTarget.value)),V(`keydown`,a,e=>{e.key===`Enter`?e.currentTarget.blur():e.key===`Escape`&&k(ie,!1)}),d(e,t)},m=e=>{var t=ar();l(()=>T(t,`aria-label`,`add a note it's ${s(M)===`about`?`about`:`using`}`)),V(`click`,t,()=>k(ie,!0)),d(e,t)};j(f,e=>{s(ie)?e(p):e(m,-1)});var h=P(f,4);let g;var _=I(h,!0);D(a),l(()=>{B(a,1,`extra ${r.kind??``}`,`svelte-ml08v2`),A(c,s(M)),g=B(h,1,`mark svelte-ml08v2`,null,g,{done:!!r.done}),T(h,`aria-pressed`,!!r.done),h.disabled=r.marking,T(h,`title`,r.done?`since ${r.done}`:void 0),A(_,r.kind===`question`?r.done?`◆ resolved`:`◇ open`:r.done?`◆ solved`:`◇ unsolved`)}),V(`click`,h,function(...e){r.onmark?.apply(this,e)}),d(t,a)};j(_e,e=>{s(M)&&e(ye)});var be=P(_e,2),xe=e=>{var t=sr(),n=I(t,!0);l(()=>A(n,s(o))),d(e,t)};j(be,e=>{s(o)&&e(xe)}),l(()=>{G=B(W,1,`stand serif svelte-ml08v2`,null,G,{empty:!r.note.fields.description}),ne(W,r.note.fields.description)}),V(`input`,W,e=>r.note.setFields({description:e.currentTarget.value.replace(/\s*\n\s*/g,` `)})),V(`keydown`,W,e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())}),d(t,U),R()}h([`input`,`keydown`,`click`]);var ur=a(`<span class="sym svelte-wdtkre"> </span>`),dr=a(`<span class="lines svelte-wdtkre"> </span>`),fr=a(`<span class="why svelte-wdtkre"> </span>`),pr=a(`<span class="ln svelte-wdtkre"></span>`),mr=a(`<span class="pre svelte-wdtkre"></span> <!> <!>`,1),hr=a(`<span data-code-embed=""><span class="head svelte-wdtkre"><a class="file svelte-wdtkre" title="Read the whole file"> </a> <!> <!></span> <!></span>`);function gr(t,n){C(n,!0);let a=x(null),o=x(null),c=x(``);async function u(){try{let e=await K.api.code(n.href);k(a,e),k(o,e.state===`ok`?await Pt(e.text,e.path):null,!0),k(c,``)}catch(e){k(c,e.message,!0)}}v(()=>{n.href,u();let e=()=>{document.visibilityState===`visible`&&u()};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)});let f={"no-repository":`no repository is named for this base's code links`,"no-file":`not in the repository`,"no-symbol":`no longer in the file by that name`,unsupported:`isorite can find symbols in this kind of file only by lines`,"too-large":`too large to show`},p=F(()=>s(a)?.state===`ok`?s(a).start===s(a).end?`line ${s(a).start}`:`lines ${s(a).start}–${s(a).end}`:``);var m=hr();let h;var _=e(m),y=e(_),b=I(y,!0),ee=P(y,2),S=e=>{var t=ur(),n=I(t,!0);l(()=>A(n,s(a).symbol)),d(e,t)};j(ee,e=>{s(a)?.symbol&&e(S)});var E=P(ee,2),O=e=>{var t=dr(),n=I(t,!0);l(()=>A(n,s(p))),d(e,t)};j(E,e=>{s(p)&&e(O)}),D(_);var te=P(_,2),ne=e=>{var t=fr(),n=I(t,!0);l(()=>A(n,s(c))),d(e,t)},M=e=>{var t=fr(),n=I(t,!0);l(()=>A(n,f[s(a).state])),d(e,t)},N=e=>{var t=mr(),n=w(t);let c;i(n,21,()=>s(a).text.split(`
|
|
11
|
-
`),r,(e,t,n)=>{var r=pr();g(r,()=>(s(o)?.split(`
|
|
12
|
-
`)[n]??s(t).replace(/&/g,`&`).replace(/</g,`<`))||` `,!0),D(r),l(()=>T(r,`data-n`,s(a).start+n)),d(e,r)}),D(n);var u=P(n,2),f=e=>{var t=fr(),n=I(t);l(()=>A(n,`… ${s(a).end-s(a).start+1-120} more lines in the file`)),d(e,t)};j(u,e=>{s(a).more&&e(f)});var p=P(u,2),m=e=>{var t=fr(),n=I(t);l(()=>A(n,`${s(a).count??``} declarations of this name: the first is shown`)),d(e,t)};j(p,e=>{s(a).count&&e(m)}),l(()=>c=ie(n,``,c,{"--from":s(a).start})),d(e,t)};j(te,e=>{s(c)?e(ne):s(a)&&s(a).state!==`ok`?e(M,1):s(a)?.state===`ok`&&e(N,2)}),D(m),l((e,t)=>{h=B(m,1,`code svelte-wdtkre`,null,h,{broken:s(a)&&s(a).state!==`ok`}),T(y,`href`,e),A(b,t)},[()=>Se(n.href),()=>s(a)?.path??n.href.slice(5).split(`#`)[0]]),d(t,m),R()}var _r=a(`<span class="problem svelte-zlq7nn"> </span>`),vr=a(`<span class="embed svelte-zlq7nn"><a class="name svelte-zlq7nn"><!> </a> <!> <!></span>`);function yr(t,n){C(n,!0);let r=x(null),a=x(``),o=x(re([]));v(()=>{let e=n.path;sn(K.api,e).then(e=>{k(r,e)},e=>{k(a,e.message,!0)})});var c=vr(),u=e(c),f=e(u);Ue(f,{kind:`artifact`,size:11});var p=P(f,1,!0);D(u);var m=P(u,2),h=e=>{var t=_r(),n=I(t,!0);l(()=>A(n,s(a))),d(e,t)},g=e=>{{let t=F(()=>s(r).manifest.title||n.path);gn(e,{get path(){return n.path},get html(){return s(r).html},get uses(){return s(r).manifest.uses},get title(){return s(t)},onerror:e=>{s(o).includes(e)||k(o,[...s(o),e],!0)}})}};j(m,e=>{s(a)?e(h):s(r)&&e(g,1)});var _=P(m,2);i(_,16,()=>s(o),e=>e,(e,t)=>{var n=_r(),r=I(n,!0);l(()=>A(r,t)),d(e,n)}),D(c),l((e,t)=>{T(u,`href`,e),A(p,t)},[()=>ve(n.path),()=>s(r)?.manifest.title||n.path.split(`/`).at(-1)]),d(t,c),R()}var br=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=Tr(e.state,n.from);return r.line?Sr(e):r.block?wr(e):!1};function xr(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=e(t,n);return i?(r(n.update(i)),!0):!1}}var Sr=xr(Ar,0),Cr=xr(kr,0),wr=xr((e,t)=>kr(e,t,Or(t)),0);function Tr(e,t){let n=e.languageDataAt(`commentTokens`,t,1);return n.length?n[0]:{}}var Er=50;function Dr(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-Er,r),o=e.sliceDoc(i,i+Er),s=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,l=a.length-s;if(a.slice(l-t.length,l)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-s,margin:s&&1},close:{pos:i+c,margin:c&&1}};let u,d;i-r<=100?u=d=e.sliceDoc(r,i):(u=e.sliceDoc(r,r+Er),d=e.sliceDoc(i-Er,i));let f=/^\s*/.exec(u)[0].length,p=/\s*$/.exec(d)[0].length,m=d.length-p-n.length;return u.slice(f,f+t.length)==t&&d.slice(m,m+n.length)==n?{open:{pos:r+f+t.length,margin:+!!/\s/.test(u.charAt(f+t.length))},close:{pos:i-p-n.length,margin:+!!/\s/.test(d.charAt(m-1))}}:null}function Or(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),i=n.to<=r.to?r:e.doc.lineAt(n.to);i.from>r.from&&i.from==n.to&&(i=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=i.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:i.to})}return t}function kr(e,t,n=t.selection.ranges){let r=n.map(e=>Tr(t,e.from).block);if(!r.every(e=>e))return null;let i=n.map((e,n)=>Dr(t,r[n],e.from,e.to));if(e!=2&&!i.every(e=>e))return{changes:t.changes(n.map((e,t)=>i[t]?[]:[{from:e.from,insert:r[t].open+` `},{from:e.to,insert:` `+r[t].close}]))};if(e!=1&&i.some(e=>e)){let e=[];for(let t=0,n;t<i.length;t++)if(n=i[t]){let i=r[t],{open:a,close:o}=n;e.push({from:a.pos-i.open.length,to:a.pos+a.margin},{from:o.pos-o.margin,to:o.pos+i.close.length})}return{changes:e}}return null}function Ar(e,t,n=t.selection.ranges){let r=[],i=-1;ranges:for(let{from:e,to:a}of n){let n=r.length,o=1e9,s;for(let n=e;n<=a;){let c=t.doc.lineAt(n);if(s==null&&(s=Tr(t,c.from).line,!s))continue ranges;if(c.from>i&&(e==a||a>c.from)){i=c.from;let e=/^\s*/.exec(c.text)[0].length,t=e==c.length,n=c.text.slice(e,e+s.length)==s?e:-1;e<c.text.length&&e<o&&(o=e),r.push({line:c,comment:n,token:s,indent:e,empty:t,single:!1})}n=c.to+1}if(o<1e9)for(let e=n;e<r.length;e++)r[e].indent<r[e].line.text.length&&(r[e].indent=o);r.length==n+1&&(r[n].single=!0)}if(e!=2&&r.some(e=>e.comment<0&&(!e.empty||e.single))){let e=[];for(let{line:t,token:n,indent:i,empty:a,single:o}of r)(o||!a)&&e.push({from:t.from+i,insert:n+` `});let n=t.changes(e);return{changes:n,selection:t.selection.map(n,1)}}if(e!=1&&r.some(e=>e.comment>=0)){let e=[];for(let{line:t,comment:n,token:i}of r)if(n>=0){let r=t.from+n,a=r+i.length;t.text[a-t.from]==` `&&a++,e.push({from:r,to:a})}return{changes:e}}return null}var jr=lt.define(),Mr=lt.define(),Nr=ut.define(),Pr=ut.define({combine(e){return pt(e,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,r)=>e(n,r)||t(n,r)})}}),Fr=bt.define({create(){return ei.empty},update(e,t){let n=t.state.facet(Pr),r=t.annotation(jr);if(r){let i=Hr.fromTransaction(t,r.selection),a=r.side,o=a==0?e.undone:e.done;return o=i?Ur(o,o.length,n.minDepth,i):Yr(o,t.startState.selection),new ei(a==0?r.rest:o,a==0?o:r.rest)}let i=t.annotation(Mr);if((i==`full`||i==`before`)&&(e=e.isolate()),t.annotation(ft.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=Hr.fromTransaction(t),o=t.annotation(ft.time),s=t.annotation(ft.userEvent);return a?e=e.addChanges(a,o,s,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,s,n.newGroupDelay)),(i==`full`||i==`after`)&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(e=>e.toJSON()),undone:e.undone.map(e=>e.toJSON())}},fromJSON(e){return new ei(e.done.map(Hr.fromJSON),e.undone.map(Hr.fromJSON))}});function Ir(e={}){return[Fr,Pr.of(e),J.domEventHandlers({beforeinput(e,t){let n=e.inputType==`historyUndo`?Rr:e.inputType==`historyRedo`?zr:null;return n?(e.preventDefault(),n(t)):!1}})]}function Lr(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(Fr,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}var Rr=Lr(0,!1),zr=Lr(1,!1),Br=Lr(0,!0),Vr=Lr(1,!0),Hr=class e{constructor(e,t,n,r,i){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=i}setSelAfter(t){return new e(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){return{changes:this.changes?.toJSON(),mapped:this.mapped?.toJSON(),startSelection:this.startSelection?.toJSON(),selectionsAfter:this.selectionsAfter.map(e=>e.toJSON())}}static fromJSON(t){return new e(t.changes&&it.fromJSON(t.changes),[],t.mapped&&tt.fromJSON(t.mapped),t.startSelection&&Y.fromJSON(t.startSelection),t.selectionsAfter.map(Y.fromJSON))}static fromTransaction(t,n){let r=qr;for(let e of t.startState.facet(Nr)){let n=e(t);n.length&&(r=r.concat(n))}return!r.length&&t.changes.empty?null:new e(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,qr)}static selection(t){return new e(void 0,qr,void 0,void 0,t)}};function Ur(e,t,n,r){let i=t+1>n+20?t-n-1:0,a=e.slice(i,t);return a.push(r),a}function Wr(e,t){let n=[],r=!1;return e.iterChangedRanges((e,t)=>n.push(e,t)),t.iterChangedRanges((e,t,i,a)=>{for(let e=0;e<n.length;){let t=n[e++],o=n[e++];a>=t&&i<=o&&(r=!0)}}),r}function Gr(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((e,n)=>e.empty!=t.ranges[n].empty).length===0}function Kr(e,t){return e.length?t.length?e.concat(t):e:t}var qr=[],Jr=200;function Yr(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-Jr));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),Ur(e,e.length-1,1e9,n.setSelAfter(r)))}return[Hr.selection([t])]}function Xr(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function Zr(e,t){if(!e.length)return e;let n=e.length,r=qr;for(;n;){let i=Qr(e[n-1],t,r);if(i.changes&&!i.changes.empty||i.effects.length){let t=e.slice(0,n);return t[n-1]=i,t}t=i.mapped,n--,r=i.selectionsAfter}return r.length?[Hr.selection(r)]:qr}function Qr(e,t,n){let r=Kr(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):qr,n);if(!e.changes)return Hr.selection(r);let i=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new Hr(i,yt.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}var $r=/^(input\.type|delete)($|\.)/,ei=class e{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new e(this.done,this.undone):this}addChanges(t,n,r,i,a){let o=this.done,s=o[o.length-1];return o=s&&s.changes&&!s.changes.empty&&t.changes&&(!r||$r.test(r))&&(!s.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,Wr(s.changes,t.changes))||r==`input.type.compose`)?Ur(o,o.length-1,i.minDepth,new Hr(t.changes.compose(s.changes),Kr(yt.mapEffects(t.effects,s.changes),s.effects),s.mapped,s.startSelection,qr)):Ur(o,o.length,i.minDepth,t),new e(o,qr,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:qr;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&Gr(a[a.length-1],t)?this:new e(Yr(this.done,t),this.undone,n,r)}addMapping(t){return new e(Zr(this.done,t),Zr(this.undone,t),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=e==0?this.done:this.undone;if(r.length==0)return null;let i=r[r.length-1],a=i.selectionsAfter[0]||(i.startSelection?i.startSelection.map(i.changes.invertedDesc,1):t.selection);if(n&&i.selectionsAfter.length)return t.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:jr.of({side:e,rest:Xr(r),selection:a}),userEvent:e==0?`select.undo`:`select.redo`,scrollIntoView:!0});if(i.changes){let n=r.length==1?qr:r.slice(0,r.length-1);return i.mapped&&(n=Zr(n,i.mapped)),t.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:jr.of({side:e,rest:n,selection:a}),filter:!1,userEvent:e==0?`undo`:`redo`,scrollIntoView:!0})}return null}};ei.empty=new ei(qr,qr);var ti=[{key:`Mod-z`,run:Rr,preventDefault:!0},{key:`Mod-y`,mac:`Mod-Shift-z`,run:zr,preventDefault:!0},{linux:`Ctrl-Shift-z`,run:zr,preventDefault:!0},{key:`Mod-u`,run:Br,preventDefault:!0},{key:`Alt-u`,mac:`Mod-Shift-u`,run:Vr,preventDefault:!0}];function ni(e,t){return Y.create(e.ranges.map(t),e.mainIndex)}function ri(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:`select`})}function ii({state:e,dispatch:t},n){let r=ni(e.selection,n);return!r.eq(e.selection,!0)&&(t(ri(e,r)),!0)}function ai(e,t){return Y.cursor(t?e.to:e.from)}function oi(e,t){return ii(e,n=>n.empty?e.moveByChar(n,t):ai(n,t))}function Q(e){return e.textDirectionAt(e.state.selection.main.head)==ot.LTR}var si=e=>oi(e,!Q(e)),ci=e=>oi(e,Q(e));function li(e,t){return ii(e,n=>n.empty?e.moveByGroup(n,t):ai(n,t))}var ui=e=>li(e,!Q(e)),di=e=>li(e,Q(e));typeof Intl<`u`&&Intl.Segmenter;function fi(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function pi(e,t,n){let r=q(e).resolveInner(t.head),i=n?_t.closedBy:_t.openedBy;for(let a=t.head;;){let t=n?r.childAfter(a):r.childBefore(a);if(!t)break;fi(e,t,i)?r=t:a=n?t.to:t.from}let a=r.type.prop(i),o,s;return s=a&&(o=n?wt(e,r.from,1):wt(e,r.to,-1))&&o.matched?n?o.end.to:o.end.from:n?r.to:r.from,Y.cursor(s,n?-1:1)}var mi=e=>ii(e,t=>pi(e.state,t,!Q(e))),hi=e=>ii(e,t=>pi(e.state,t,Q(e)));function gi(e,t){return ii(e,n=>{if(!n.empty)return ai(n,t);let r=e.moveVertically(n,t);return r.head==n.head?e.moveToLineBoundary(n,t):r})}var _i=e=>gi(e,!1),vi=e=>gi(e,!0);function yi(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,i;if(t){for(let t of e.state.facet(J.scrollMargins)){let i=t(e);i?.top&&(n=Math.max(i?.top,n)),i?.bottom&&(r=Math.max(i?.bottom,r))}i=e.scrollDOM.clientHeight-n-r}else i=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,i-5)}}function bi(e,t){let n=yi(e),{state:r}=e,i=ni(r.selection,r=>r.empty?e.moveVertically(r,t,n.height):ai(r,t));if(i.eq(r.selection))return!1;let a;if(n.selfScroll){let t=e.coordsAtPos(r.selection.main.head),o=e.scrollDOM.getBoundingClientRect(),s=o.top+n.marginTop,c=o.bottom-n.marginBottom;t&&t.top>s&&t.bottom<c&&(a=J.scrollIntoView(i.main.head,{y:`start`,yMargin:t.top-s}))}return e.dispatch(ri(r,i),{effects:a}),!0}var xi=e=>bi(e,!1),Si=e=>bi(e,!0);function Ci(e,t,n){let r=e.lineBlockAt(t.head),i=e.moveToLineBoundary(t,n);if(i.head==t.head&&i.head!=(n?r.to:r.from)&&(i=e.moveToLineBoundary(t,n,!1)),!n&&i.head==r.from&&r.length){let n=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;n&&t.head!=r.from+n&&(i=Y.cursor(r.from+n))}return i}var wi=e=>ii(e,t=>Ci(e,t,!0)),Ti=e=>ii(e,t=>Ci(e,t,!1)),Ei=e=>ii(e,t=>Ci(e,t,!Q(e))),Di=e=>ii(e,t=>Ci(e,t,Q(e))),Oi=e=>ii(e,t=>e.moveToLineBoundary(t,!1,!1)),ki=e=>ii(e,t=>e.moveToLineBoundary(t,!0,!1));function Ai(e,t,n){let r=!1,i=ni(e.selection,t=>{let i=wt(e,t.head,-1)||wt(e,t.head,1)||t.head>0&&wt(e,t.head-1,1)||t.head<e.doc.length&&wt(e,t.head+1,-1);if(!i||!i.end)return t;r=!0;let a=i.start.from==t.head?i.end.to:i.end.from;return n?Y.range(t.anchor,a):Y.cursor(a)});return r?(t(ri(e,i)),!0):!1}var ji=({state:e,dispatch:t})=>Ai(e,t,!1);function $(e,t,n){let r=ni(e.state.selection,e=>{e.undirectional&&e.head>=e.anchor!=t&&(e=Y.range(e.head,e.anchor));let r=n(e);return Y.range(e.anchor,r.head,r.goalColumn,r.bidiLevel||void 0,r.assoc)});return!r.eq(e.state.selection)&&(e.dispatch(ri(e.state,r)),!0)}function Mi(e,t){return $(e,t,n=>e.moveByChar(n,t))}var Ni=e=>Mi(e,!Q(e)),Pi=e=>Mi(e,Q(e));function Fi(e,t){return $(e,t,n=>e.moveByGroup(n,t))}var Ii=e=>Fi(e,!Q(e)),Li=e=>Fi(e,Q(e)),Ri=e=>{let t=!Q(e);return $(e,t,n=>pi(e.state,n,t))},zi=e=>{let t=Q(e);return $(e,t,n=>pi(e.state,n,t))};function Bi(e,t){return $(e,t,n=>e.moveVertically(n,t))}var Vi=e=>Bi(e,!1),Hi=e=>Bi(e,!0);function Ui(e,t){return $(e,t,n=>e.moveVertically(n,t,yi(e).height))}var Wi=e=>Ui(e,!1),Gi=e=>Ui(e,!0),Ki=e=>$(e,!0,t=>Ci(e,t,!0)),qi=e=>$(e,!1,t=>Ci(e,t,!1)),Ji=e=>{let t=!Q(e);return $(e,t,n=>Ci(e,n,t))},Yi=e=>{let t=Q(e);return $(e,t,n=>Ci(e,n,t))},Xi=e=>$(e,!1,t=>Y.cursor(e.lineBlockAt(t.head).from)),Zi=e=>$(e,!0,t=>Y.cursor(e.lineBlockAt(t.head).to)),Qi=({state:e,dispatch:t})=>(t(ri(e,{anchor:0})),!0),$i=({state:e,dispatch:t})=>(t(ri(e,{anchor:e.doc.length})),!0),ea=({state:e,dispatch:t})=>(t(ri(e,{anchor:e.selection.main.anchor,head:0})),!0),ta=({state:e,dispatch:t})=>(t(ri(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),na=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:`select`})),!0),ra=({state:e,dispatch:t})=>{let n=Sa(e).map(({from:t,to:n})=>Y.undirectionalRange(t,Math.min(n+1,e.doc.length)));return t(e.update({selection:Y.create(n),userEvent:`select`})),!0},ia=({state:e,dispatch:t})=>{let n=ni(e.selection,t=>{let n=q(e),r=n.resolveStack(t.from,1);if(t.empty){let e=n.resolveStack(t.from,-1);e.node.from>=r.node.from&&e.node.to<=r.node.to&&(r=e)}for(let e=r;e;e=e.next){let{node:n}=e;if((n.from<t.from&&n.to>=t.to||n.to>t.to&&n.from<=t.from)&&e.next)return Y.undirectionalRange(n.from,n.to)}return t});return!n.eq(e.selection)&&(t(ri(e,n)),!0)};function aa(e,t){let{state:n}=e,r=n.selection,i=n.selection.ranges.slice();for(let r of n.selection.ranges){let a=n.doc.lineAt(r.head);if(t?a.to<e.state.doc.length:a.from>0)for(let n=r;;){let r=e.moveVertically(n,t);if(r.head<a.from||r.head>a.to){i.some(e=>e.head==r.head)||i.push(r);break}if(r.head==n.head)break;n=r}}return i.length!=r.ranges.length&&(e.dispatch(ri(n,Y.create(i,i.length-1))),!0)}var oa=e=>aa(e,!1),sa=e=>aa(e,!0),ca=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=Y.create([n.main]):n.main.empty||(r=Y.create([Y.cursor(n.main.head)])),r?(t(ri(e,r)),!0):!1};function la(e,t){if(e.state.readOnly)return!1;let n=`delete.selection`,{state:r}=e,i=r.changeByRange(r=>{let{from:i,to:a}=r;if(i==a){let o=t(r);o<i?(n=`delete.backward`,o=ua(e,o,!1)):o>i&&(n=`delete.forward`,o=ua(e,o,!0)),i=Math.min(i,o),a=Math.max(a,o)}else i=ua(e,i,!1),a=ua(e,a,!0);return i==a?{range:r}:{changes:{from:i,to:a},range:Y.cursor(i,i<r.head?-1:1)}});return!i.changes.empty&&(e.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:n==`delete.selection`?J.announce.of(r.phrase(`Selection deleted`)):void 0})),!0)}function ua(e,t,n){if(e instanceof J)for(let r of e.state.facet(J.atomicRanges).map(t=>t(e)))r.between(t,t,(e,r)=>{e<t&&r>t&&(t=n?r:e)});return t}var da=(e,t,n)=>la(e,r=>{let i=r.from,{state:a}=e,o=a.doc.lineAt(i),s,c;if(n&&!t&&i>o.from&&i<o.from+200&&!/[^ \t]/.test(s=o.text.slice(0,i-o.from))){if(s[s.length-1]==` `)return i-1;let e=gt(s,a.tabSize)%Ct(a)||Ct(a);for(let t=0;t<e&&s[s.length-1-t]==` `;t++)i--;c=i}else c=St(o.text,i-o.from,t,t)+o.from,c==i&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,i-o.from))&&(c=St(o.text,c-o.from,!1,!1)+o.from);return c}),fa=e=>da(e,!1,!0),pa=e=>da(e,!0,!1),ma=(e,t)=>la(e,n=>{let r=n.head,{state:i}=e,a=i.doc.lineAt(r),o=i.charCategorizer(r);for(let e=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?i.doc.lines:1)&&(r+=t?1:-1);break}let s=St(a.text,r-a.from,t)+a.from,c=a.text.slice(Math.min(r,s)-a.from,Math.max(r,s)-a.from),l=o(c);if(e!=null&&l!=e)break;(c!=` `||r!=n.head)&&(e=l),r=s}return r}),ha=e=>ma(e,!1),ga=e=>ma(e,!0),_a=e=>la(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),va=e=>la(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),ya=e=>la(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),ba=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:ht.of([``,``])},range:Y.cursor(e.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:`input`})),!0},xa=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(t=>{if(!t.empty||t.from==0||t.from==e.doc.length)return{range:t};let n=t.from,r=e.doc.lineAt(n),i=n==r.from?n-1:St(r.text,n-r.from,!1)+r.from,a=n==r.to?n+1:St(r.text,n-r.from,!0)+r.from;return{changes:{from:i,to:a,insert:e.doc.slice(n,a).append(e.doc.slice(i,n))},range:Y.cursor(a)}});return!n.changes.empty&&(t(e.update(n,{scrollIntoView:!0,userEvent:`move.character`})),!0)};function Sa(e){let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=i.number){let e=t[t.length-1];e.to=a.to,e.ranges.push(r)}else t.push({from:i.from,to:a.to,ranges:[r]});n=a.number+1}return t}function Ca(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let t of Sa(e)){if(n?t.to==e.doc.length:t.from==0)continue;let a=e.doc.lineAt(n?t.to+1:t.from-1),o=a.length+1;if(n){r.push({from:t.to,to:a.to},{from:t.from,insert:a.text+e.lineBreak});for(let n of t.ranges)i.push(Y.range(Math.min(e.doc.length,n.anchor+o),Math.min(e.doc.length,n.head+o)))}else{r.push({from:a.from,to:t.from},{from:t.to,insert:e.lineBreak+a.text});for(let e of t.ranges)i.push(Y.range(e.anchor-o,e.head-o))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:Y.create(i,e.selection.mainIndex),userEvent:`move.line`})),!0):!1}var wa=({state:e,dispatch:t})=>Ca(e,t,!1),Ta=({state:e,dispatch:t})=>Ca(e,t,!0);function Ea(e,t,n){if(e.readOnly)return!1;let r=[];for(let t of Sa(e))n?r.push({from:t.from,insert:e.doc.slice(t.from,t.to)+e.lineBreak}):r.push({from:t.to,insert:e.lineBreak+e.doc.slice(t.from,t.to)});let i=e.changes(r);return t(e.update({changes:i,selection:e.selection.map(i,n?1:-1),scrollIntoView:!0,userEvent:`input.copyline`})),!0}var Da=({state:e,dispatch:t})=>Ea(e,t,!1),Oa=({state:e,dispatch:t})=>Ea(e,t,!0),ka=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(Sa(t).map(({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n}))),r=ni(t.selection,t=>{let n;if(e.lineWrapping){let r=e.lineBlockAt(t.head),i=e.coordsAtPos(t.head,t.assoc||1);i&&(n=r.bottom+e.documentTop-i.bottom+e.defaultLineHeight/2)}return e.moveVertically(t,!0,n)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:`delete.line`}),!0};function Aa(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=q(e).resolveInner(t),r=n.childBefore(t),i=n.childAfter(t),a;return r&&i&&r.to<=t&&i.from>=t&&(a=r.type.prop(_t.closedBy))&&a.indexOf(i.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(i.from).from&&!/\S/.test(e.sliceDoc(r.to,i.from))?{from:r.to,to:i.from}:null}var ja=Na(!1),Ma=Na(!0);function Na(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(n=>{let{from:r,to:i}=n,a=t.doc.lineAt(r),o=!e&&r==i&&Aa(t,r);e&&(r=i=(i<=a.to?a:t.doc.lineAt(i)).to);let s=new vt(t,{simulateBreak:r,simulateDoubleBreak:!!o}),c=Et(s,r);for(c??=gt(/^\s*/.exec(t.doc.lineAt(r).text)[0],t.tabSize);i<a.to&&/\s/.test(a.text[i-a.from]);)i++;o?{from:r,to:i}=o:r>a.from&&r<a.from+100&&!/\S/.test(a.text.slice(0,r))&&(r=a.from);let l=[``,Tt(t,c)];return o&&l.push(Tt(t,s.lineIndent(a.from,-1))),{changes:{from:r,to:i,insert:ht.of(l)},range:Y.cursor(r+1+l[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:`input`})),!0}}function Pa(e,t){let n=-1;return e.changeByRange(r=>{let i=[];for(let a=r.from;a<=r.to;){let o=e.doc.lineAt(a);o.number>n&&(r.empty||r.to>o.from)&&(t(o,i,r),n=o.number),a=o.to+1}let a=e.changes(i);return{changes:i,range:Y.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}var Fa=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new vt(e,{overrideIndentation:e=>n[e]??-1}),i=Pa(e,(t,i,a)=>{let o=Et(r,t.from);if(o==null)return;/\S/.test(t.text)||(o=0);let s=/^\s*/.exec(t.text)[0],c=Tt(e,o);(s!=c||a.from<t.from+s.length)&&(n[t.from]=o,i.push({from:t.from,to:t.from+s.length,insert:c}))});return i.changes.empty||t(e.update(i,{userEvent:`indent`})),!0},Ia=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(Pa(e,(t,n)=>{n.push({from:t.from,insert:e.facet(ct)})}),{userEvent:`input.indent`})),!0),La=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(Pa(e,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let i=gt(r,e.tabSize),a=0,o=Tt(e,Math.max(0,i-Ct(e)));for(;a<r.length&&a<o.length&&r.charCodeAt(a)==o.charCodeAt(a);)a++;n.push({from:t.from+a,to:t.from+r.length,insert:o.slice(a)})}),{userEvent:`delete.dedent`})),!0),Ra=e=>(e.setTabFocusMode(),!0),za=[{key:`Ctrl-b`,run:si,shift:Ni,preventDefault:!0},{key:`Ctrl-f`,run:ci,shift:Pi},{key:`Ctrl-p`,run:_i,shift:Vi},{key:`Ctrl-n`,run:vi,shift:Hi},{key:`Ctrl-a`,run:Oi,shift:Xi},{key:`Ctrl-e`,run:ki,shift:Zi},{key:`Ctrl-d`,run:pa},{key:`Ctrl-h`,run:fa},{key:`Ctrl-k`,run:_a},{key:`Ctrl-Alt-h`,run:ha},{key:`Ctrl-o`,run:ba},{key:`Ctrl-t`,run:xa},{key:`Ctrl-v`,run:Si}],Ba=[{key:`ArrowLeft`,run:si,shift:Ni,preventDefault:!0},{key:`Mod-ArrowLeft`,mac:`Alt-ArrowLeft`,run:ui,shift:Ii,preventDefault:!0},{mac:`Cmd-ArrowLeft`,run:Ei,shift:Ji,preventDefault:!0},{key:`ArrowRight`,run:ci,shift:Pi,preventDefault:!0},{key:`Mod-ArrowRight`,mac:`Alt-ArrowRight`,run:di,shift:Li,preventDefault:!0},{mac:`Cmd-ArrowRight`,run:Di,shift:Yi,preventDefault:!0},{key:`ArrowUp`,run:_i,shift:Vi,preventDefault:!0},{mac:`Cmd-ArrowUp`,run:Qi,shift:ea},{mac:`Ctrl-ArrowUp`,run:xi,shift:Wi},{key:`ArrowDown`,run:vi,shift:Hi,preventDefault:!0},{mac:`Cmd-ArrowDown`,run:$i,shift:ta},{mac:`Ctrl-ArrowDown`,run:Si,shift:Gi},{key:`PageUp`,run:xi,shift:Wi},{key:`PageDown`,run:Si,shift:Gi},{key:`Home`,run:Ti,shift:qi,preventDefault:!0},{key:`Mod-Home`,run:Qi,shift:ea},{key:`End`,run:wi,shift:Ki,preventDefault:!0},{key:`Mod-End`,run:$i,shift:ta},{key:`Enter`,run:ja,shift:ja},{key:`Mod-a`,run:na},{key:`Backspace`,run:fa,shift:fa,preventDefault:!0},{key:`Delete`,run:pa,preventDefault:!0},{key:`Mod-Backspace`,mac:`Alt-Backspace`,run:ha,preventDefault:!0},{key:`Mod-Delete`,mac:`Alt-Delete`,run:ga,preventDefault:!0},{mac:`Mod-Backspace`,run:va,preventDefault:!0},{mac:`Mod-Delete`,run:ya,preventDefault:!0}].concat(za.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),Va=[{key:`Alt-ArrowLeft`,mac:`Ctrl-ArrowLeft`,run:mi,shift:Ri},{key:`Alt-ArrowRight`,mac:`Ctrl-ArrowRight`,run:hi,shift:zi},{key:`Alt-ArrowUp`,run:wa},{key:`Shift-Alt-ArrowUp`,run:Da},{key:`Alt-ArrowDown`,run:Ta},{key:`Shift-Alt-ArrowDown`,run:Oa},{key:`Mod-Alt-ArrowUp`,run:oa},{key:`Mod-Alt-ArrowDown`,run:sa},{key:`Escape`,run:ca},{key:`Mod-Enter`,run:Ma},{key:`Alt-l`,mac:`Ctrl-l`,run:ra},{key:`Mod-i`,run:ia,preventDefault:!0},{key:`Mod-[`,run:La},{key:`Mod-]`,run:Ia},{key:`Mod-Alt-\\`,run:Fa},{key:`Shift-Mod-k`,run:ka},{key:`Shift-Mod-\\`,run:ji},{key:`Mod-/`,run:br},{key:`Alt-A`,mac:`Ctrl-A`,run:Cr},{key:`Ctrl-m`,mac:`Shift-Alt-m`,run:Ra}].concat(Ba),Ha={key:`Tab`,run:Ia,shift:La},Ua=ut.define({combine:e=>e[0]??null}),Wa=/^[ \t]*\[\[!([^\]\n]+)\]\][ \t]*$/,Ga={question:`<path d="M8 2.5L13.5 8L8 13.5L2.5 8Z"/>`,problem:`<path d="M8 2.5l5.8 10.5H2.2z"/>`,note:`<rect x="3.5" y="2.5" width="9" height="11"/>`},Ka=`<path d="M3 8.5l3 3 7-7"/>`,qa=class extends at{ref;found;at;constructor(e,t,n){super(),this.ref=e,this.found=t,this.at=n}eq(e){return e.ref===this.ref&&JSON.stringify(e.found)===JSON.stringify(this.found)&&e.at===this.at}toDOM(e){let t=this.found,n=document.createElement(`div`);n.className=`cm-lp-embed${t?` cm-lp-embed-${t.kind}`:` cm-lp-embed-broken`}${t?.done?` cm-lp-embed-done`:``}`,n.title=`[[!${this.ref}]]`;let r=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);r.setAttribute(`viewBox`,`0 0 16 16`),r.setAttribute(`width`,`16`),r.setAttribute(`height`,`16`),r.setAttribute(`aria-hidden`,`true`),r.innerHTML=t?.done?Ka:Ga[t?.kind??`question`];let i=document.createElement(`span`);return i.textContent=t?t.title:this.ref,n.append(r,i),n.addEventListener(`mousedown`,n=>{n.preventDefault(),t&&!n.altKey?e.state.facet(Ua)?.open(t.id):(e.dispatch({selection:{anchor:this.at},scrollIntoView:!0}),e.focus())}),n}ignoreEvent(){return!0}get estimatedHeight(){return 44}},Ja=class extends at{kind;source;at;beneath;constructor(e,t,n,r){super(),this.kind=e,this.source=t,this.at=n,this.beneath=r}eq(e){return e.kind===this.kind&&e.source===this.source&&e.at===this.at&&e.beneath===this.beneath}toDOM(e){let t=document.createElement(`div`);t.className=`cm-lp-block cm-lp-${this.kind}${this.beneath?` cm-lp-beneath`:``}`;let n=document.createElement(`div`);return n.className=`prose`,t.append(n),n.innerHTML=Le(this.source),this.beneath||(t.title=`Click to edit`,t.addEventListener(`mousedown`,t=>{t.preventDefault(),e.dispatch({selection:{anchor:this.at},scrollIntoView:!0}),e.focus()})),t}ignoreEvent(){return!0}get estimatedHeight(){return this.kind===`maths`?60:120}},Ya=new WeakMap,Xa=class extends at{source;at;beneath;constructor(e,t,n){super(),this.source=e,this.at=t,this.beneath=n}eq(e){return e.source===this.source&&e.at===this.at&&e.beneath===this.beneath}toDOM(e){let t=document.createElement(`div`);t.className=`cm-lp-block cm-lp-diagram${this.beneath?` cm-lp-beneath`:``}`;let n=document.createElement(`pre`);n.className=`cm-lp-diagram-src`,n.textContent=this.source;let r=document.createElement(`div`);return r.className=`diagram`,t.append(n,r),Ya.set(t,{mounted:ze(r,this.source,()=>t.classList.add(`cm-lp-broken-diagram`)),source:this.source}),this.beneath||(t.title=`Click to edit`,t.addEventListener(`mousedown`,t=>{t.preventDefault(),e.dispatch({selection:{anchor:this.at},scrollIntoView:!0}),e.focus()})),t}updateDOM(e){let t=Ya.get(e);return!t||!this.beneath||!e.classList.contains(`cm-lp-beneath`)?!1:(t.source!==this.source&&(t.source=this.source,e.classList.remove(`cm-lp-broken-diagram`),e.querySelector(`.cm-lp-diagram-src`).textContent=this.source,t.mounted.then(e=>He(e,this.source))),!0)}ignoreEvent(){return!0}get estimatedHeight(){return 160}},Za=(e,t)=>t!==null&&e.sliceDoc(t.from,t.to).trim().split(/\s/)[0].toLowerCase()===`mermaid`;function Qa(e){let t=[],n=e.selection.ranges;q(e).iterate({enter:r=>{let i=null,a=``;if(r.name===`BlockMath`)i=`maths`,a=e.sliceDoc(r.from,r.to);else if(r.name===`Table`)i=`table`,a=e.sliceDoc(r.from,r.to);else if(r.name===`FencedCode`&&Za(e,r.node.getChild(`CodeInfo`))){let i=r.node.getChild(`CodeText`),a=i?e.sliceDoc(i.from,i.to):``,o=e.doc.lineAt(r.from).from,s=e.doc.lineAt(r.to).to;return n.some(e=>e.to>=o&&e.from<=s)?a.trim()&&t.push(Z.widget({widget:new Xa(a,r.from,!0),block:!0,side:1}).range(s)):t.push(Z.replace({widget:new Xa(a,r.from,!1),block:!0}).range(o,s)),!1}else if(r.name===`Document`||r.name===`Blockquote`||/List|ListItem/.test(r.name))return;if(!i)return!1;let o=e.doc.lineAt(r.from).from,s=e.doc.lineAt(r.to).to;return n.some(e=>e.to>=o&&e.from<=s)?i!==`table`&&a.trim()&&t.push(Z.widget({widget:new Ja(i,a,r.from,!0),block:!0,side:1}).range(s)):t.push(Z.replace({widget:new Ja(i,a,r.from,!1),block:!0}).range(o,s)),!1}});let r=e.facet(Ua);if(r){let i=!1;for(let a=1;a<=e.doc.lines;a++){let o=e.doc.line(a);if(/^\s*(```|~~~)/.test(o.text)){i=!i;continue}let s=i?null:Wa.exec(o.text);if(!s||n.some(e=>e.to>=o.from&&e.from<=o.to))continue;let c=s[1].trim();t.push(Z.replace({widget:new qa(c,r.find(c),o.from),block:!0}).range(o.from,o.to))}}return Z.set(t,!0)}var $a=bt.define({create:Qa,update(e,t){return t.docChanged||t.selection||q(t.startState)!==q(t.state)?Qa(t.state):e},provide:e=>J.decorations.from(e)}),eo=J.theme({".cm-lp-block":{padding:`0`,cursor:`text`},".cm-lp-block .katex-display > .katex":{fontSize:`1.17em`},".cm-lp-block .prose":{maxWidth:`none`},".cm-lp-block .prose > :last-child, .cm-lp-block .table-wrap":{marginBottom:`0`},".cm-lp-block .katex-display":{margin:`0`},".cm-lp-diagram .diagram":{overflowX:`auto`,overflowY:`hidden`},".cm-lp-diagram-src":{display:`none`,margin:`0`,font:`13px/20px var(--font-mono)`,whiteSpace:`pre-wrap`,color:`var(--text-soft)`},".cm-lp-diagram.cm-lp-broken-diagram:not(.cm-lp-beneath) .cm-lp-diagram-src":{display:`block`},".cm-lp-beneath":{borderLeft:`2px solid var(--line)`,paddingLeft:`12px`,marginTop:`4px`,opacity:`.9`},".cm-lp-block:not(.cm-lp-beneath):hover":{outline:`1px dashed var(--line)`,outlineOffset:`2px`},".cm-lp-embed":{display:`flex`,alignItems:`center`,gap:`10px`,padding:`9px 12px`,border:`1px solid var(--rose)`,borderLeftWidth:`3px`,background:`var(--rose-soft)`,fontFamily:`var(--font-text)`,fontSize:`16px`,lineHeight:`1.45`,cursor:`pointer`},".cm-lp-embed svg":{flex:`none`,fill:`none`,stroke:`var(--rose)`,strokeWidth:`1.4`},".cm-lp-embed-problem":{borderColor:`var(--line-strong)`,background:`var(--ground-1)`},".cm-lp-embed-problem svg":{stroke:`var(--text-soft)`},".cm-lp-embed-done":{borderColor:`var(--malachite)`,background:`var(--malachite-soft)`},".cm-lp-embed-done svg":{stroke:`var(--malachite)`},".cm-lp-embed-broken":{borderStyle:`dashed`,borderColor:`var(--line-strong)`,background:`none`,color:`var(--text-faint)`},".cm-lp-embed-broken svg":{stroke:`var(--text-faint)`},".cm-lp-embed:hover":{borderColor:`var(--text-soft)`}});function to(e,t){let{state:n}=e,r=t.length;return e.dispatch(n.changeByRange(e=>{let i=n.sliceDoc(e.from-r,e.from),a=n.sliceDoc(e.to,e.to+r);return i===t&&a===t?{changes:[{from:e.from-r,to:e.from},{from:e.to,to:e.to+r}],range:Y.range(e.from-r,e.to-r)}:{changes:[{from:e.from,insert:t},{from:e.to,insert:t}],range:Y.range(e.from+r,e.to+r)}}),{scrollIntoView:!0,userEvent:`input`}),!0}function no(e){let{state:t}=e,n=new Map;for(let e of t.selection.ranges)for(let r=e.from;r<=e.to;){let e=t.doc.lineAt(r);n.set(e.number,{from:e.from,text:e.text}),r=e.to+1}return[...n.values()]}function ro(e){let t=no(e).map(({from:e,text:t})=>{let n=/^(#{1,6}) /.exec(t),r=n?n[1].length:0,i=r>=3?``:`#`.repeat(r+1)+` `;return{from:e,to:e+(n?n[0].length:0),insert:i}});return e.dispatch({changes:t,scrollIntoView:!0,userEvent:`input`}),!0}function io(e){let t=no(e),n=t.every(({text:e})=>/^\s*[-*+] /.test(e)),r=t.map(({from:e,text:t})=>{if(n){let n=/^(\s*)[-*+] /.exec(t);return{from:e+n[1].length,to:e+n[0].length}}return{from:e+/^\s*/.exec(t)[0].length,insert:`- `}});return e.dispatch({changes:r,scrollIntoView:!0,userEvent:`input`}),!0}function ao(e){let{state:t}=e,n=t.selection.main;if(n.empty)e.dispatch({changes:{from:n.from,insert:`[[]]`},selection:{anchor:n.from+2},userEvent:`input`});else{let r=t.sliceDoc(n.from,n.to);e.dispatch({changes:{from:n.from,to:n.to,insert:`[${r}]()`},selection:{anchor:n.from+r.length+3},userEvent:`input`})}return Ot(e),!0}function oo(e,t){switch(t){case`bold`:return to(e,`**`);case`italic`:return to(e,`*`);case`maths`:return to(e,`$`);case`heading`:return ro(e);case`list`:return io(e);case`link`:return ao(e);case`undo`:return Rr(e);case`redo`:return zr(e)}}var so=[{key:`Mod-b`,preventDefault:!0,run:e=>oo(e,`bold`)},{key:`Mod-i`,preventDefault:!0,run:e=>oo(e,`italic`)},{key:`Mod-k`,preventDefault:!0,run:e=>oo(e,`link`)},{key:`Mod-Shift-m`,preventDefault:!0,run:e=>oo(e,`maths`)},{key:`Mod-Shift-h`,preventDefault:!0,run:e=>oo(e,`heading`)},{key:`Mod-Shift-8`,preventDefault:!0,run:e=>oo(e,`list`)}],co=[`requires`,`uses`,`see also`];function lo(e){if(!e||/^[a-z][a-z0-9+.-]*:/i.test(e)||e.startsWith(`#`))return null;let t=e.split(`#`)[0].split(`?`)[0];return/\.html?$/i.test(t)?`artifact`:/\.(png|jpe?g|gif|svg|webp|avif)$/i.test(t)?`image`:/\.md$/i.test(t)||t.endsWith(`/`)?`note`:null}function uo(e,t){let n=q(e);for(let r of[-1,1])for(let i=n.resolveInner(t,r);i;i=i.parent){if(i.name!==`Link`&&i.name!==`Image`)continue;let t=i.getChild(`URL`);if(!t)break;let n=e.sliceDoc(t.from,t.to),r=lo(n);if(!r)return null;let a=i.getChild(`LinkTitle`),o=a?e.sliceDoc(a.from,a.to):null;return{from:i.from,to:i.to,embed:i.name===`Image`,url:n,urlTo:t.to,title:o===null?null:o.replace(/^["'(]|["')]$/g,``),titleFrom:a?a.from:t.to,titleTo:a?a.to:t.to,kind:r}}return null}var fo=e=>e.kind===`note`||e.kind===`artifact`&&!e.embed;function po(e,t,n){let r=[];return q(e).iterate({from:t,to:n,enter:i=>{if(i.name!==`Link`&&i.name!==`Image`)return;if(i.from<t||i.to>n)return!1;let a=uo(e,i.from+1);return a&&a.from===i.from&&fo(a)&&r.push(a),!1}}),r}var mo=(e,t)=>e.filter(e=>go(e)!==t).map(e=>vo(e,t)),ho=e=>(e??``).trim().toLowerCase().replace(/[-_]/g,` `),go=e=>co.includes(ho(e.title))?ho(e.title):ho(e.title)===`seealso`?`see also`:null,_o=e=>ho(e.title)===`left`?`left`:`center`;function vo(e,t){return t===null?{from:e.urlTo,to:e.titleTo,insert:``}:e.titleFrom===e.titleTo?{from:e.urlTo,insert:` "${t}"`}:{from:e.titleFrom,to:e.titleTo,insert:`"${t}"`}}function yo(e,t){if(e.embed===t)return[];let n=[t?{from:e.from,insert:`!`}:{from:e.from,to:e.from+1,insert:``}];return e.title!==null&&(e.kind===`image`||go(e)!==null)&&n.push(vo(e,null)),n}var bo=(e,t)=>e.dispatch({changes:t,userEvent:`input.link`});function xo(e){let t=[...co.map(t=>({label:t[0].toUpperCase()+t.slice(1),on:go(e)===t,run:(e,n)=>bo(e,vo(n,t)),hint:t===`requires`?`This note cannot be followed without it: it shapes the Atlas and the study order`:t===`uses`?`It draws on it: it shapes the Atlas`:`Related reading: shown, but it does not shape the Atlas`})),{label:`Unrated`,on:go(e)===null,run:(e,t)=>bo(e,vo(t,null)),hint:`No rating: counted as uses`}];if(e.kind===`note`)return t;let n=[{label:`Shown here`,on:e.embed,run:(e,t)=>bo(e,yo(t,!0)),hint:e.kind===`image`?`The picture is shown in the note`:`The artifact is shown in the note, working`},{label:`Link`,on:!e.embed,run:(e,t)=>bo(e,yo(t,!1)),hint:`A link to it; it opens on its own`}];return e.kind===`image`?e.embed?[...n,{label:`Centre`,on:_o(e)===`center`,run:(e,t)=>bo(e,vo(t,null)),hint:`In the middle, 80% of the text's width`},{label:`Left`,on:_o(e)===`left`,run:(e,t)=>bo(e,vo(t,`left`)),hint:`At the left, 80% of the text's width`}]:n:e.embed?n:[...n,...t]}function So(e){let t=t=>e.every(e=>go(e)===t),n=e.length;return[...co.map(e=>({label:e[0].toUpperCase()+e.slice(1),on:t(e),run:t=>bo(t,mo(po(t.state,t.state.selection.main.from,t.state.selection.main.to),e)),hint:`Rate all ${n} links ${e}`})),{label:`Unrated`,on:t(null),run:e=>bo(e,mo(po(e.state,e.state.selection.main.from,e.state.selection.main.to),null)),hint:`Take the rating from all ${n} links`}]}function Co(e){let t=go(e[0]),n=e.every(e=>go(e)===t);return`${e.length} links, ${n?t??`unrated`:`mixed`}`}function wo(e){return e.kind===`note`?go(e)?go(e)[0].toUpperCase()+go(e).slice(1):`Unrated`:e.embed?e.kind===`image`?_o(e)===`left`?`Shown, left`:`Shown, centre`:`Shown here`:go(e)?`Link, ${go(e)}`:`Link`}var To=(e,t)=>e===t||!!e&&!!t&&e.from===t.from&&e.to===t.to&&e.title===t.title&&e.embed===t.embed,Eo=class{view;layer;button;menu;leader;path;link=null;hover=null;many=[];open=!1;at=0;constructor(e){this.view=e,this.layer=document.createElement(`div`),this.layer.className=`cm-link-control`,this.layer.hidden=!0,this.leader=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`),this.leader.setAttribute(`class`,`cm-link-leader`),this.leader.setAttribute(`aria-hidden`,`true`),this.path=document.createElementNS(`http://www.w3.org/2000/svg`,`path`),this.leader.append(this.path),this.button=document.createElement(`button`),this.button.type=`button`,this.button.className=`cm-link-button`,this.button.setAttribute(`aria-haspopup`,`menu`),this.button.addEventListener(`mousedown`,e=>e.preventDefault()),this.button.addEventListener(`click`,()=>this.toggle(!this.open,!1)),this.menu=document.createElement(`div`),this.menu.className=`cm-link-menu`,this.menu.setAttribute(`role`,`menu`),this.menu.hidden=!0,this.menu.tabIndex=-1,this.menu.addEventListener(`keydown`,e=>this.keys(e)),this.layer.append(this.leader,this.button,this.menu),e.dom.append(this.layer),e.dom.addEventListener(`mousemove`,this.onMove),e.dom.addEventListener(`mouseleave`,this.onLeave)}onMove=e=>{if(this.open||this.layer.contains(e.target))return;let t=this.view.posAtCoords({x:e.clientX,y:e.clientY},!1),n=t===null?null:uo(this.view.state,t);To(n,this.hover)||(this.hover=n,this.view.requestMeasure(this.measure))};onLeave=e=>{this.open||this.layer.contains(e.relatedTarget)||this.hover&&(this.hover=null,this.view.requestMeasure(this.measure))};selected(){let e=this.view.state.selection.main;if(e.empty)return[];let t=po(this.view.state,e.from,e.to);return t.length>=2?t:[]}current(){let e=this.view.state.selection.main,t=this.selected();return t.length?t[0]:uo(this.view.state,e.head)??(e.empty?this.hover:null)}update(e){e.docChanged&&(this.hover=null),(e.docChanged||e.selectionSet||e.geometryChanged||e.viewportChanged||e.focusChanged)&&this.view.requestMeasure(this.measure)}measure={key:`link-control`,read:e=>{let t=this.current();if(!t)return null;let n=this.selected(),r=e.dom.getBoundingClientRect(),i=e.contentDOM.getBoundingClientRect(),a=e.coordsAtPos(Math.max(t.from,t.to-1),1)??e.coordsAtPos(t.to,-1);if(n.length){let t=Math.max(r.top,0),i=Math.min(r.bottom,window.innerHeight);a=null;for(let r=n.length-1;r>=0&&!a;r--){let o=e.coordsAtPos(Math.max(n[r].from,n[r].to-1),1);o&&o.top>=t&&o.bottom<=i-34&&(a=o)}a??=e.coordsAtPos(Math.max(n[0].from,n[0].to-1),1)}return a?{l:t,many:n,x:a.right-r.left,y:(a.top+a.bottom)/2-r.top,right:i.right-r.left,width:r.width}:null},write:e=>{if(!e){this.link=null,this.many=[],this.layer.hidden=!0,this.toggle(!1,!1);return}let t=e.many.length?Co(e.many):wo(e.l),n=!To(e.l,this.link)||e.many.length!==this.many.length||t!==this.button.textContent;this.link=e.l,this.many=e.many,this.layer.hidden=!1,this.button.textContent=t,this.button.title=e.many.length?`Rate all the selected links (Alt+L)`:`What this link is (Alt+L)`,this.button.setAttribute(`aria-label`,e.many.length?`${t}. Rate them all`:`This link: ${t}. Change it`);let r=this.button.offsetWidth||90,i=e.width-e.right>=r+20,a=i?e.right+14:Math.max(0,e.width-r-2),o=i?e.y-13:e.y+12;this.button.style.transform=`translate(${Math.round(a)}px, ${Math.round(o)}px)`,this.menu.style.transform=`translate(${Math.round(Math.min(a,e.width-250))}px, ${Math.round(o+30)}px)`;let s=a,c=o+13;this.path.setAttribute(`d`,i?`M${e.x+3} ${e.y} H${Math.max(e.x+3,s-3)}`:`M${e.x+3} ${e.y} V${c} H${s-3}`),n&&this.open&&(this.fill(),this.mark(this.at))}};fill(){let e=this.link;e&&this.menu.replaceChildren(...(this.many.length?So(this.many):xo(e)).map((t,n)=>{let r=document.createElement(`button`);return r.type=`button`,r.tabIndex=-1,r.id=`cm-link-choice-${n}`,r.addEventListener(`mousedown`,e=>e.preventDefault()),r.addEventListener(`mousemove`,()=>this.mark(n)),r.setAttribute(`role`,`menuitemradio`),r.setAttribute(`aria-checked`,String(t.on)),r.title=t.hint,r.innerHTML=`<b></b><span></span>`,r.querySelector(`b`).textContent=t.label,r.querySelector(`span`).textContent=t.hint,r.addEventListener(`click`,()=>{let n=this.current()??e;t.run(this.view,n),this.toggle(!1,!0)}),r}))}toggle(e,t){if(e&&(this.link=this.current()??this.link,this.many=this.selected()),!e||this.link){if(this.open=e,this.menu.hidden=!e,this.layer.classList.toggle(`open`,e),this.button.setAttribute(`aria-expanded`,String(e)),e){this.fill();let e=[...this.menu.querySelectorAll(`button`)];this.mark(Math.max(0,e.findIndex(e=>e.getAttribute(`aria-checked`)===`true`))),this.menu.focus()}else t&&this.view.focus()}}mark(e){let t=[...this.menu.querySelectorAll(`button`)];this.at=t.length?(e+t.length)%t.length:0,t.forEach((e,t)=>e.classList.toggle(`on`,t===this.at)),this.menu.setAttribute(`aria-activedescendant`,t[this.at]?.id??``)}keys(e){let t=[...this.menu.querySelectorAll(`button`)],n=!0;if(e.key===`Escape`)this.toggle(!1,!0);else if(e.key===`Enter`||e.key===` `)t[this.at]?.click();else if(e.key===`ArrowDown`)this.mark(this.at+1);else if(e.key===`ArrowUp`)this.mark(this.at-1);else if(e.key===`Home`)this.mark(0);else if(e.key===`End`)this.mark(t.length-1);else if(e.key===`Tab`)this.toggle(!1,!0);else if(e.key.length===1&&!e.altKey&&!e.ctrlKey&&!e.metaKey){let r=t.findIndex(t=>t.textContent.toLowerCase().startsWith(e.key.toLowerCase()));r>=0?this.mark(r):n=!1}else n=!1;n&&(e.preventDefault(),e.stopPropagation())}destroy(){this.view.dom.removeEventListener(`mousemove`,this.onMove),this.view.dom.removeEventListener(`mouseleave`,this.onLeave),this.layer.remove()}},Do=rt.fromClass(Eo),Oo=e=>t=>{let n=uo(t.state,t.state.selection.main.head);return n?(e(t,n),!0):!1},ko=e=>t=>{let n=t.state.selection.main,r=n.empty?[]:po(t.state,n.from,n.to);return r.length>=2?(bo(t,mo(r,e)),!0):Oo((t,n)=>{fo(n)&&bo(t,vo(n,e))})(t)},Ao=[{key:`Alt-l`,run:e=>{let t=e.plugin(Do);return!t||!t.current()?!1:(t.toggle(!0,!1),!0)}},{key:`Alt-1`,run:ko(`requires`)},{key:`Alt-2`,run:ko(`uses`)},{key:`Alt-3`,run:ko(`see also`)},{key:`Alt-0`,run:ko(null)},{key:`Alt-e`,run:Oo((e,t)=>{t.kind!==`note`&&bo(e,yo(t,!t.embed))})}],jo=[Do,J.baseTheme({"&":{position:`relative`},".cm-link-control":{position:`absolute`,inset:`0`,pointerEvents:`none`,zIndex:`4`,overflow:`visible`},".cm-link-control[hidden]":{display:`none`},".cm-link-leader":{position:`absolute`,left:`0`,top:`0`,width:`100%`,height:`100%`,overflow:`visible`},".cm-link-leader path":{fill:`none`,stroke:`var(--lattice)`,strokeWidth:`1.75`,strokeDasharray:`.1 5`,strokeLinecap:`round`,opacity:`.7`},".cm-link-control:hover .cm-link-leader path, .cm-link-control:focus-within .cm-link-leader path, .cm-link-control.open .cm-link-leader path":{opacity:`1`,animation:`cm-link-run .6s linear infinite`},"@keyframes cm-link-run":{to:{strokeDashoffset:`-5.1`}},"@media (prefers-reduced-motion: reduce)":{".cm-link-leader path":{animation:`none !important`}},".cm-link-button":{position:`absolute`,left:`0`,top:`0`,pointerEvents:`auto`,height:`26px`,padding:`0 9px`,font:`12.5px var(--font-ui)`,whiteSpace:`nowrap`,color:`var(--text)`,background:`var(--ground-1)`,border:`1px solid var(--lattice)`,cursor:`pointer`},".cm-link-button:hover, .cm-link-button[aria-expanded=true]":{background:`var(--lattice-soft)`},".cm-link-button:focus-visible":{outline:`2px solid var(--focus-ring)`,outlineOffset:`2px`},".cm-link-menu":{position:`absolute`,left:`0`,top:`0`,pointerEvents:`auto`,width:`248px`,padding:`4px`,background:`var(--ground-1)`,border:`1px solid var(--line)`,display:`grid`,gap:`1px`},".cm-link-menu[hidden]":{display:`none`},".cm-link-menu button":{display:`grid`,gap:`1px`,textAlign:`left`,padding:`6px 8px 6px 24px`,background:`none`,border:`0`,color:`var(--text)`,font:`13.5px var(--font-ui)`,cursor:`pointer`,position:`relative`},".cm-link-menu button b":{fontWeight:`600`},".cm-link-menu button span":{fontSize:`12px`,color:`var(--text-faint)`,lineHeight:`1.3`},".cm-link-menu button[aria-checked=true]::before":{content:`"●"`,position:`absolute`,left:`8px`,top:`7px`,fontSize:`10px`,color:`var(--lattice)`},".cm-link-menu:focus":{outline:`none`},".cm-link-menu button.on":{background:`var(--lattice-soft)`},".cm-link-menu:focus-visible button.on":{outline:`2px solid var(--focus-ring)`,outlineOffset:`-2px`}}),$e.of(Ao)],Mo=e=>{let t=e.trim().replace(/[-_]+/g,` `).replace(/\s+/g,` `);return t?t[0].toUpperCase()+t.slice(1):``};function No(e,t=null){return n=>{let r=n.matchBefore(/\[\[(?!!)[^\]\n]*$/);if(!r)return null;let i=e().map(e=>({label:e.title,detail:e.folder,apply:(t,n,r,i)=>{let a=`[${e.title}](/${e.id}.md)`,o=r-2,s=t.state.sliceDoc(i,i+2)===`]]`?i+2:i;t.dispatch({changes:{from:o,to:s,insert:a},selection:{anchor:o+a.length}})}})),a=n.state.sliceDoc(r.from+2,n.pos),o=t?.plan(a)??null;return t&&o&&!e().some(e=>e.id===o.id)&&i.push({label:a,detail:`a new note${o.folder?` in ${o.folder}`:``}`,type:`create`,boost:-2,apply:(e,n,r,i)=>{let a=`[${o.title}](/${o.id}.md)`,s=r-2,c=e.state.sliceDoc(i,i+2)===`]]`?i+2:i;e.dispatch({changes:{from:s,to:c,insert:a},selection:{anchor:s+a.length}}),t.make(o)}}),{from:r.from+2,options:i,filter:!0,...t?{}:{validFor:/^[^\]\n]*$/}}}}var Po=e=>e.split(`/`).at(-1).replace(/\.[^.]+$/,``).replace(/[-_]+/g,` `).trim(),Fo=e=>/[\s()<>]/.test(e)?`<${e}>`:e;function Io(e,t){return async n=>{let r=n.matchBefore(/\[\[![^\]\n]*$/);if(!r)return null;let i=(e,t,n,r,i)=>{let a=t-3,o=e.state.sliceDoc(n,n+2)===`]]`?n+2:n;e.dispatch({changes:{from:a,to:o,insert:r},selection:i?{anchor:a+i[0],head:a+i[1]}:{anchor:a+r.length}})},a=t?.here()??``,o=a.includes(`/`)?a.slice(0,a.lastIndexOf(`/`)):``,s=(t?await t.pictures().catch(()=>[]):[]).map(e=>{let t=e.path.includes(`/`)?e.path.slice(0,e.path.lastIndexOf(`/`)):``;return{label:e.path.split(`/`).at(-1),detail:t,picture:e,type:`picture`,boost:t===a?2:+(t===o),info:()=>zo(e),apply:(t,n,r,a)=>{let o=Po(e.path),s=`})`;i(t,r,a,s,[2,2+o.length])}}}),c=e().map(e=>e.id);for(let t of e())t.kind&&s.push({label:t.title,detail:t.kind,boost:-1,apply:(e,n,r,a)=>i(e,r,a,G(t.id,c))});return t&&s.push({label:`Paste or drop a picture to add one`,type:`hint`,boost:-99,apply:()=>void 0}),{from:r.from+3,options:s,filter:!0,validFor:/^[^\]\n]*$/}}}function Lo(e,t){return async n=>{let r=n.matchBefore(/\]\([^)\s]*$/);if(!r)return null;let i=t?await t.pictures().catch(()=>[]):[];return{from:r.from+2,options:[...e().map(e=>({label:`/${e.id}.md`,detail:e.title})),...i.map(e=>({label:`/${e.path}`,detail:`picture`,picture:e,type:`picture`,info:()=>zo(e)}))],validFor:/^[^)\s]*$/}}}function Ro(e,t){e.alt=``,e.decoding=`async`,typeof t.src==`string`?e.src=t.src:t.src.then(t=>{t&&(e.src=t)})}function zo(e){let t=document.createElement(`div`);t.className=`cm-picture-preview`;let n=document.createElement(`img`);Ro(n,e);let r=document.createElement(`div`);return r.className=`cm-picture-size`,r.textContent=e.width&&e.height?`${e.width} × ${e.height}`:``,t.append(n,r),t}function Bo(e,t=null,n=null){return kt({override:[Io(e,t),No(e,n),Lo(e,t)],icons:!1,activateOnTyping:!0,addToOptions:[{position:20,render:e=>{if(!e.picture)return null;let t=document.createElement(`img`);return t.className=`cm-picture-thumb`,t.loading=`lazy`,Ro(t,e.picture),t}}]})}var Vo=36,Ho=92,Uo=40,Wo=/^\$\$([^$]*?[^\\])\$\$/,Go=/^\$((?:[^\s\\])|(?:\S.*?[^\s\\]))\$(?!\d)/,Ko=/^\\\((.+?)\\\)/,qo=/^\$\$([^$]*?[^\\])\$\$(?:[ \t]*\([^)\s]+?\))?(?=[ \t]*(?:\n|$))/,Jo=/^\\\[([\s\S]+?)\\\](?:[ \t]*\([^)$\r\n]+?\))?(?=[ \t]*(?:\n|$))/;function Yo(e,t,n){if(t===Vo){if(n>e.offset&&e.char(n-1)===Ho)return-1;let t=e.slice(n,e.end),r=(t.charCodeAt(1)===Vo?Wo:Go).exec(t);return r?e.addElement(e.elt(`InlineMath`,n,n+r[0].length,[e.elt(`MathMark`,n,n+(r[0].startsWith(`$$`)?2:1)),e.elt(`MathMark`,n+r[0].length-(r[0].startsWith(`$$`)?2:1),n+r[0].length)])):-1}if(t===Ho&&e.char(n+1)===Uo){let t=Ko.exec(e.slice(n,e.end));if(!t)return-1;let r=n+t[0].length;return e.addElement(e.elt(`InlineMath`,n,r,[e.elt(`MathMark`,n,n+2),e.elt(`MathMark`,r-2,r)]))}return-1}var Xo=2e4;function Zo(e,t){let n=t.text.slice(t.pos),r=n.startsWith(`$$`)?qo:n.startsWith(`\\[`)?Jo:null;if(!r)return!1;let i=e.lineStart+t.pos,a=e.input,o=r.exec(a.read(i,Math.min(a.length,i+Xo)));if(!o)return!1;let s=i+o[0].length;for(;e.lineStart+t.text.length<s&&e.nextLine(););return e.addElement(e.elt(`BlockMath`,i,s)),e.nextLine(),!0}var Qo={defineNodes:[{name:`InlineMath`,style:X.special(X.content)},{name:`BlockMath`,block:!0,style:X.special(X.content)},{name:`MathMark`,style:X.processingInstruction}],parseInline:[{name:`InlineMath`,parse:Yo,before:`Escape`}],parseBlock:[{name:`BlockMath`,parse:Zo,before:`FencedCode`}]};function $o(e){let t;return(t=/^\$\$([\s\S]*?)\$\$/.exec(e))||(t=/^\\\[([\s\S]*?)\\\]/.exec(e))?{tex:t[1],display:!0}:(t=/^\\\(([\s\S]*?)\\\)$/.exec(e))||(t=/^\$([\s\S]*?)\$$/.exec(e))?{tex:t[1],display:!1}:{tex:e,display:!1}}var es=class extends at{eq(){return!0}toDOM(){let e=document.createElement(`span`);return e.className=`cm-lp-bullet`,e.textContent=`•`,e}},ts=class extends at{eq(){return!0}toDOM(){let e=document.createElement(`span`);return e.className=`cm-lp-hr`,e}},ns=class extends at{name;constructor(e){super(),this.name=e}eq(e){return e.name===this.name}toDOM(){let e=document.createElement(`span`);return e.className=`cm-lp-lang`,e.textContent=this.name,e}},rs=class extends at{source;constructor(e){super(),this.source=e}eq(e){return e.source===this.source}toDOM(){let e=document.createElement(`span`);e.className=`cm-lp-imaths`;let{tex:t,display:n}=$o(this.source);return e.innerHTML=je.renderToString(t,{displayMode:n,throwOnError:!1}),e}},is=class extends at{key;src;alt;left;constructor(e,t,n,r){super(),this.key=e,this.src=t,this.alt=n,this.left=r}eq(e){return e.key===this.key&&e.alt===this.alt&&e.left===this.left}toDOM(e){let t=document.createElement(`span`);t.className=this.left?`cm-lp-picture cm-lp-picture-left`:`cm-lp-picture`;let n=()=>{t.replaceChildren(),t.classList.add(`cm-lp-picture-broken`),t.textContent=this.key.replace(/^notes:/,``),t.title=this.key.startsWith(`code:`)?`not in the repository`:`not in the notes`,e.requestMeasure()},r=document.createElement(`img`);return r.alt=this.alt,this.alt&&(r.title=this.alt),r.loading=`lazy`,r.decoding=`async`,r.onload=()=>e.requestMeasure(),r.onerror=n,t.append(r),typeof this.src==`string`?r.src=this.src:this.src.then(e=>{e?r.src=e:n()}),t}ignoreEvent(){return!1}},as=class extends at{path;mount;constructor(e,t){super(),this.path=e,this.mount=t}eq(e){return e.path===this.path}stop=null;toDOM(e){let t=document.createElement(`span`);return t.className=`cm-lp-artifact`,this.stop=this.mount(t),new ResizeObserver(()=>e.requestMeasure()).observe(t),t}destroy(){this.stop?.(),this.stop=null}ignoreEvent(){return!0}},os=Z.replace({}),ss=Z.replace({widget:new es}),cs=Z.replace({widget:new ts}),ls=e=>Z.mark({class:e}),us=e=>Z.line({class:e});function ds(e,t){let n=new Set;if(!t)return n;for(let t of e.selection.ranges){let r=e.doc.lineAt(t.from).number,i=e.doc.lineAt(t.to).number;for(let e=r;e<=i;e++)n.add(e)}return n}function fs(e){let{state:t}=e,n=ds(t,e.hasFocus),r=e=>n.has(t.doc.lineAt(e).number),i=[],a=(e,n,r)=>{for(let a=t.doc.lineAt(e).number,o=t.doc.lineAt(n).number;a<=o;a++)i.push(us(r).range(t.doc.line(a).from))},o=e.visibleRanges;if(o.length){let e=o[0].from,s=o[o.length-1].to,c=/^ {0,3}([-*_])(?: *\1){2,} *$/,l=t.doc.lineAt(e).number,u=t.doc.lineAt(s).number,d=e=>e>=1&&e<=t.doc.lines?t.doc.line(e).text:``;for(let e=l;e<=u;e++){let r=t.doc.line(e);if(r.length!==0||/Code|Math|HTML|Comment/.test(q(t).resolveInner(r.from,1).name))continue;let a=e>1&&t.doc.line(e-1).length===0&&!n.has(e),o=c.test(d(e-1))||c.test(d(e+1));i.push(us(a?`cm-lp-gap cm-lp-gap-more`:o?`cm-lp-gap cm-lp-gap-rule`:`cm-lp-gap`).range(r.from))}q(t).iterate({from:e,to:s,enter:e=>{let n=e.name,o=/^(?:ATX|Setext)Heading(\d)$/.exec(n);if(o)a(e.from,e.to,`cm-lp-h${o[1]}`);else switch(n){case`HeaderMark`:{if(r(e.from))break;if((e.node.parent?.name??``).startsWith(`SetextHeading`)){i.push(os.range(t.doc.lineAt(e.from).from,e.to));break}let n=t.sliceDoc(e.to,e.to+1)===` `?e.to+1:e.to;n>e.from&&i.push(os.range(e.from,n));break}case`EmphasisMark`:case`StrikethroughMark`:r(e.from)||i.push(os.range(e.from,e.to));break;case`Emphasis`:i.push(ls(`cm-lp-em`).range(e.from,e.to));break;case`StrongEmphasis`:i.push(ls(`cm-lp-strong`).range(e.from,e.to));break;case`Strikethrough`:i.push(ls(`cm-lp-strike`).range(e.from,e.to));break;case`InlineCode`:if(i.push(ls(`cm-lp-code`).range(e.from,e.to)),!r(e.from)){let t=e.node;for(let e=t.firstChild;e;e=e.nextSibling)e.name===`CodeMark`&&i.push(os.range(e.from,e.to))}return!1;case`InlineMath`:return r(e.from)?i.push(ls(`cm-lp-mathsrc`).range(e.from,e.to)):i.push(Z.replace({widget:new rs(t.sliceDoc(e.from,e.to))}).range(e.from,e.to)),!1;case`BlockMath`:case`Table`:return a(e.from,e.to,`cm-lp-codeblock`),!1;case`Link`:{let n=e.node,a=[],o=!1;for(let e=n.firstChild;e;e=e.nextSibling)e.name===`LinkMark`&&a.push(e),e.name===`URL`&&(o=!0);let s=a[0],c=a[1],l=n.getChild(`URL`),u=l?t.sliceDoc(l.from,l.to):``,d=u.startsWith(`code:`),f=/^https?:/i.test(u),p=n.getChild(`LinkTitle`),m=U(p?t.sliceDoc(p.from+1,p.to-1):null),h=d?t.facet(hs)(u)?`cm-lp-link cm-lp-codelink cm-lp-broken`:`cm-lp-link cm-lp-codelink`:f?`cm-lp-link cm-lp-weblink vein web`:`cm-lp-link vein ${m===`requires`?`requires`:m===`see also`?`also`:`uses`}`;s&&c&&c.from>s.to&&i.push((d?Z.mark({class:h,attributes:{title:t.facet(hs)(u)?`${u.slice(5)}: not in the repository`:u.slice(5)}}):ls(h)).range(s.to,c.from)),!r(e.from)&&o&&s&&c&&(i.push(os.range(s.from,s.to)),i.push(os.range(c.from,e.to)));break}case`Image`:{let n=e.node,a=n.getChild(`URL`),o=n.getChildren(`LinkMark`),s=a?t.facet(ms)(t.sliceDoc(a.from,a.to)):null;if(s&&o.length>=2){let t=new as(s.path,s.mount);return r(e.from)?i.push(Z.widget({widget:t,side:1}).range(e.to)):i.push(Z.replace({widget:t}).range(e.from,e.to)),!1}let c=a?t.facet(ps)(t.sliceDoc(a.from,a.to)):null;if(!c||o.length<2)break;let l=n.getChild(`LinkTitle`),u=l?t.sliceDoc(l.from+1,l.to-1).trim().toLowerCase():``,d=new is(c.key,c.src,t.sliceDoc(o[0].to,o[1].from),u===`left`);return r(e.from)?i.push(Z.widget({widget:d,side:1}).range(e.to)):i.push(Z.replace({widget:d}).range(e.from,e.to)),!1}case`ListMark`:{let n=t.sliceDoc(e.from,e.to);!r(e.from)&&/^[-*+]$/.test(n)?i.push(ss.range(e.from,e.to)):i.push(ls(`cm-lp-listmark`).range(e.from,e.to));break}case`TaskMarker`:i.push(ls(`cm-lp-task`).range(e.from,e.to));break;case`Blockquote`:a(e.from,e.to,`cm-lp-quote`);break;case`QuoteMark`:if(!r(e.from)){let n=t.sliceDoc(e.to,e.to+1)===` `?e.to+1:e.to;i.push(os.range(e.from,n))}break;case`HorizontalRule`:r(e.from)||(i.push(cs.range(e.from,e.to)),a(e.from,e.to,`cm-lp-ruleline`));break;case`FencedCode`:{a(e.from,e.to,`cm-lp-codeblock`);let n=e.node,o=t.doc.lineAt(e.from),s=t.doc.lineAt(e.to),c=n.getChild(`CodeInfo`),l=n.lastChild?.name===`CodeMark`&&n.lastChild.from>=s.from?n.lastChild:null;if(!r(o.from)){i.push(us(`cm-lp-fence`).range(o.from));let e=c?t.sliceDoc(c.from,c.to).trim().split(/\s/)[0]:``;i.push((e?Z.replace({widget:new ns(e)}):os).range(o.from,o.to))}return l&&s.number>o.number&&!r(s.from)&&(i.push(us(`cm-lp-fence`).range(s.from)),s.to>s.from&&i.push(os.range(s.from,s.to))),!1}case`CodeBlock`:return a(e.from,e.to,`cm-lp-codeblock`),!1;case`HTMLBlock`:case`CommentBlock`:return a(e.from,e.to,`cm-lp-codeblock`),!1}}})}i.sort((e,t)=>e.from-t.from||e.value.startSide-t.value.startSide);let s=new mt;for(let e of i)s.add(e.from,e.to,e.value);return s.finish()}var ps=ut.define({combine:e=>e[0]??(()=>null)}),ms=ut.define({combine:e=>e[0]??(()=>null)}),hs=ut.define({combine:e=>e[0]??(()=>!1)}),gs=rt.fromClass(class{decorations;constructor(e){this.decorations=fs(e)}update(e){(e.docChanged||e.viewportChanged||e.selectionSet||e.focusChanged||q(e.startState)!==q(e.state))&&(this.decorations=fs(e.view))}},{decorations:e=>e.decorations}),_s=J.theme({".cm-scroller":{fontFamily:`var(--font-text)`,fontSize:`var(--text-size)`,lineHeight:`1.55`},".cm-lp-gap":{lineHeight:`20px`},".cm-lp-gap-rule":{lineHeight:`10px`},".cm-lp-gap-more":{lineHeight:`4px`},".cm-lp-ruleline":{lineHeight:`12px`},".cm-content":{fontVariationSettings:`"opsz" 18`},".cm-lp-h1, .cm-lp-h2, .cm-lp-h3, .cm-lp-h4, .cm-lp-h5, .cm-lp-h6":{fontWeight:`600`,lineHeight:`1.3`,fontVariationSettings:`"opsz" 36`,paddingTop:`.5em !important`},".cm-lp-h1":{fontSize:`26px`},".cm-lp-artifact":{display:`block`,margin:`8px 0 12px`,fontFamily:`var(--font-ui)`,fontSize:`12px`,lineHeight:`1.4`},".cm-lp-h2":{fontSize:`22px`},".cm-lp-h3":{fontSize:`19px`},".cm-lp-h4":{fontSize:`17px`,fontWeight:`700`},".cm-lp-em":{fontStyle:`italic`},".cm-lp-strong":{fontWeight:`700`},".cm-lp-strike":{textDecoration:`line-through`},".cm-lp-code":{fontFamily:`var(--font-mono)`,fontSize:`.86em`,background:`color-mix(in srgb, var(--text) 8%, transparent)`,padding:`.1em .2em`},".cm-lp-codelink":{color:`var(--lattice)`,fontFamily:`var(--font-mono)`,fontSize:`.86em`,textDecoration:`none`,borderBottom:`1px solid color-mix(in srgb, var(--lattice) 50%, transparent)`},".cm-lp-broken":{color:`var(--rose)`,textDecoration:`line-through`,borderBottomColor:`transparent`},".cm-lp-picture":{display:`block`,margin:`6px auto`,width:`fit-content`,maxWidth:`100%`,lineHeight:`0`},".cm-lp-picture img":{display:`block`,maxWidth:`100%`,height:`auto`},".cm-lp-picture-left":{float:`left`,margin:`4px 16px 4px 0`,maxWidth:`50%`},".cm-lp-picture-broken":{display:`inline-block`,lineHeight:`1.4`,fontFamily:`var(--font-mono)`,fontSize:`.86em`,color:`var(--rose)`,textDecoration:`line-through`,border:`1px dashed color-mix(in srgb, var(--rose) 50%, transparent)`,padding:`6px 10px`,margin:`4px 0`},".cm-lp-bullet":{color:`var(--text-faint)`,display:`inline-block`,minWidth:`1ch`},".cm-lp-listmark, .cm-lp-task":{color:`var(--text-faint)`,fontFamily:`var(--font-mono)`},".cm-lp-quote":{borderLeft:`3px solid var(--lattice)`,paddingLeft:`14px !important`,color:`var(--text-soft)`},".cm-lp-codeblock":{fontFamily:`var(--font-mono)`,fontSize:`13px`,lineHeight:`20px`,background:`color-mix(in srgb, var(--line) 38%, transparent)`,borderLeft:`2px solid var(--line-strong)`,padding:`0 16px !important`},".cm-lp-codeblock.cm-lp-fence":{lineHeight:`12px`,position:`relative`},".cm-lp-lang":{position:`absolute`,top:`8px`,right:`12px`,fontFamily:`var(--font-ui)`,fontSize:`12px`,lineHeight:`16px`,color:`var(--text-faint)`,pointerEvents:`none`},".cm-lp-mathsrc":{fontFamily:`var(--font-mono)`,fontSize:`.86em`,color:`var(--text-soft)`},".cm-lp-imaths .katex":{fontSize:`1.05em`},".cm-lp-imaths .katex-display":{margin:`0`,padding:`6px 0`},".cm-lp-imaths .katex-display > .katex":{fontSize:`1.17em`},".cm-lp-hr":{display:`inline-block`,width:`100%`,borderTop:`1px solid var(--line)`,verticalAlign:`middle`}});function vs(e){let t=e.split(`#`)[0];return t.startsWith(`/`)&&t.endsWith(`.md`)?t.slice(1,-3):null}function ys(e){let t=e.split(/[#?]/)[0];return t.startsWith(`/`)&&!t.startsWith(`//`)&&/\/[^/]*\.[^./]+$/.test(t)&&!t.endsWith(`.md`)?decodeURI(t.slice(1)):null}var bs=yt.define(),xs=yt.define(),Ss=[bt.define({create:()=>Z.none,update(e,t){for(let e of t.effects){if(!e.is(xs))continue;let n=t.state.doc,r=e.value;if(!r)return Z.none;let i=Z.line({class:`cm-touched cm-touched-${r.who}`});return Z.set([...new Set(r.lines)].filter(e=>e>=0&&e<n.lines&&n.line(e+1).text.trim()!==``).sort((e,t)=>e-t).map(e=>i.range(n.line(e+1).from)))}return t.docChanged?e.map(t.changes):e},provide:e=>J.decorations.from(e)}),J.theme({".cm-line.cm-touched-you":{background:`var(--lattice-soft)`,boxShadow:`-10px 0 0 var(--lattice-soft), -13px 0 0 var(--lattice), 10px 0 0 var(--lattice-soft)`},".cm-line.cm-touched-iso":{background:`var(--growth-soft)`,boxShadow:`-10px 0 0 var(--growth-soft), -13px 0 0 var(--growth), 10px 0 0 var(--growth-soft)`}})],Cs=yt.define(),ws=class extends at{key;mount;block;down=null;watch=null;constructor(e,t,n){super(),this.key=e,this.mount=t,this.block=n}eq(e){return e.key===this.key&&e.block===this.block}toDOM(e){let t=document.createElement(this.block?`div`:`span`);return t.className=this.block?`cm-overlay`:`cm-iso-change`,t.contentEditable=`false`,this.down=this.mount(t,this.key),this.watch=new ResizeObserver(()=>e.requestMeasure()),this.watch.observe(t),t}destroy(){this.watch?.disconnect(),this.watch=null,this.down?.(),this.down=null}ignoreEvent(){return!0}get estimatedHeight(){return this.block?120:-1}};function Ts(e){return[bt.define({create:()=>Z.none,update(t,n){for(let t of n.effects){if(!t.is(bs))continue;let r=n.state.doc;return Z.set(t.value.map(t=>{let n=t.line>=r.lines,i=n?r.length:r.line(Math.max(1,t.line+1)).from;return Z.widget({widget:new ws(t.key,e,!0),block:!0,side:n?1:-1}).range(i)}),!0)}return n.docChanged?t.map(n.changes):t},provide:e=>J.decorations.from(e)}),bt.define({create:()=>Z.none,update(t,n){for(let t of n.effects){if(!t.is(Cs))continue;let r=n.state.doc.length,i=[];for(let e of t.value.marks){let t=Math.max(0,Math.min(r,e.from)),n=Math.max(0,Math.min(r,e.to));n>t&&i.push(Z.mark({class:`cm-iso-${e.kind}`}).range(t,n))}for(let n of t.value.inline)i.push(Z.widget({widget:new ws(n.key,e,!1),side:1}).range(Math.max(0,Math.min(r,n.at))));return Z.set(i,!0)}return n.docChanged?t.map(n.changes):t},provide:e=>J.decorations.from(e)}),J.theme({".cm-overlay":{cursor:`default`,userSelect:`text`,padding:`10px 0`,display:`flow-root`,whiteSpace:`normal`},".cm-iso-old":{textDecoration:`line-through`,textDecorationColor:`var(--text-faint)`,color:`var(--text-faint)`},".cm-iso-old *":{color:`var(--text-faint) !important`},".cm-iso-change":{cursor:`default`},".cm-iso-by-iso":{background:`var(--growth-soft)`,boxShadow:`inset 0 -1.5px 0 var(--growth)`},".cm-iso-given":{textDecoration:`underline dashed var(--growth)`,textUnderlineOffset:`4px`,textDecorationThickness:`1.5px`}})]}function Es(e){let t=e.split(`#`)[0].split(`?`)[0];return!t.startsWith(`/`)||t.startsWith(`//`)?null:t.endsWith(`.md`)?{id:decodeURIComponent(t.slice(1,-3)),folder:!1}:t.endsWith(`/`)&&t.length>1?{id:decodeURIComponent(t.slice(1,-1)),folder:!0}:null}var Ds=yt.define(),Os=Z.mark({class:`cm-pointed`});function ks(e,t){if(!t)return Z.none;let n=[];return q(e).iterate({enter:r=>{if(r.name!==`Link`)return;let i=uo(e,r.from+1);return i&&!i.embed&&i.from===r.from&&Es(i.url)?.id===t&&n.push(Os.range(i.from,i.to)),!1}}),Z.set(n)}var As=bt.define({create:()=>({id:``,marks:Z.none}),update(e,t){let n=e.id;for(let e of t.effects)e.is(Ds)&&(n=e.value);return n!==e.id||n&&t.docChanged?{id:n,marks:ks(t.state,n)}:e},provide:e=>J.decorations.from(e,e=>e.marks)}),js=J.theme({".cm-pointed":{backgroundColor:`var(--lattice-soft)`,boxShadow:`0 2px 0 var(--lattice)`}});function Ms(e){if(!e)return[As,js];let t=``,n=n=>{let r=n?`${n.folder?`d`:`n`}:${n.id}`:``;r!==t&&(t=r,e(n))};return[As,js,J.domEventHandlers({pointermove(e,t){if(e.pointerType!==`mouse`)return!1;let r=t.posAtCoords({x:e.clientX,y:e.clientY},!1),i=r===null?null:uo(t.state,r);return n(i&&!i.embed?Es(i.url):null),!1},pointerleave(){return n(null),!1}})]}var Ns=J.theme({".cm-scroller":{fontFamily:`var(--font-mono)`,fontSize:`14px`,lineHeight:`1.6`}}),Ps=J.theme({"&":{color:`var(--text)`,backgroundColor:`transparent`,fontSize:`16px`},"&.cm-focused":{outline:`none`},".cm-scroller":{overflow:`visible`},".cm-content":{padding:`12px 0 40vh`,caretColor:`var(--lattice)`},".cm-line":{padding:`0 2px`},".cm-cursor, .cm-dropCursor":{borderLeftColor:`var(--lattice)`,borderLeftWidth:`2px`},".cm-selectionBackground":{backgroundColor:`color-mix(in srgb, var(--lattice) 22%, transparent) !important`},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-content ::selection":{backgroundColor:`color-mix(in srgb, var(--lattice) 40%, transparent) !important`},".cm-placeholder":{color:`var(--text-faint)`},".cm-tooltip-autocomplete":{background:`var(--ground-1)`,border:`1px solid var(--line-strong)`,fontFamily:`var(--font-ui)`,fontSize:`13px`},".cm-tooltip.cm-tooltip-autocomplete > ul":{fontFamily:`var(--font-ui)`,maxHeight:`16em`},".cm-tooltip-autocomplete > ul > li":{padding:`6px 10px !important`,lineHeight:`1.3`},".cm-picture-thumb":{width:`32px`,height:`32px`,objectFit:`cover`,verticalAlign:`middle`,marginRight:`8px`,background:`var(--ground-2)`},".cm-tooltip-autocomplete > ul > li:has(.cm-picture-thumb)":{padding:`3px 10px !important`},".cm-picture-preview":{padding:`8px`},".cm-picture-preview img":{display:`block`,maxWidth:`240px`,maxHeight:`240px`},".cm-picture-size":{fontFamily:`var(--font-ui)`,fontSize:`12px`,color:`var(--text-faint)`,marginTop:`4px`},".cm-completionInfo":{background:`var(--ground-1)`,border:`1px solid var(--line-strong)`,padding:`0`},".cm-tooltip-autocomplete > ul > li[aria-selected]":{background:`var(--lattice-soft)`,color:`var(--text)`},".cm-completionDetail":{color:`var(--text-faint)`,fontStyle:`normal`,marginLeft:`10px`}}),Fs=xt.define([{tag:X.heading,fontWeight:`700`,color:`var(--text)`},{tag:X.strong,fontWeight:`700`},{tag:X.emphasis,fontStyle:`italic`},{tag:X.strikethrough,textDecoration:`line-through`},{tag:[X.link,X.url],color:`var(--lattice)`},{tag:[X.processingInstruction,X.punctuation,X.contentSeparator],color:`var(--text-faint)`},{tag:X.monospace,color:`var(--text-soft)`},{tag:X.quote,color:`var(--text-soft)`,fontStyle:`italic`}]);function Is(e){let t=e.selection.main;return{line:e.doc.lineAt(t.to).number-1,from:t.from,to:t.to}}function Ls(e){let t=e=>[...e??[]].filter(e=>e.type.startsWith(`image/`));return J.domEventHandlers({paste(n,r){let i=t(n.clipboardData?.files);return i.length?(n.preventDefault(),e(i,r.state.selection.main.head,!0),!0):!1},drop(n,r){let i=t(n.dataTransfer?.files);return i.length?(n.preventDefault(),e(i,r.posAtCoords({x:n.clientX,y:n.clientY})??r.state.selection.main.head,!1),!0):!1}})}function Rs(e,t){let n=dt.create({doc:t.doc,extensions:[Ir(),st(),J.lineWrapping,Nt({base:Ft,extensions:[Qo],completeHTMLTags:!1,codeLanguages:Mt}),et(Fs),et(It),Ps,...t.source?[Ns]:[gs,_s,$a,eo,jo,...t.embeds?[Ua.of(t.embeds)]:[],...t.codeBroken?[hs.of(t.codeBroken)]:[],...t.pictures?[ps.of(t.pictures)]:[],...t.artifacts?[ms.of(t.artifacts)]:[]],jt(),dt.languageData.of(()=>[{closeBrackets:{brackets:[`(`,`[`]}}]),...t.mountOverlay?[Ts(t.mountOverlay)]:[],Ss,Ms(t.onPoint),...t.readOnly?[dt.readOnly.of(!0),J.editable.of(!1)]:[],Bo(t.notes,t.pictureSource??null,t.noteMaker??null),...t.onPictures&&!t.readOnly?[Ls(t.onPictures)]:[],nt(t.placeholder??`Write the note here. # for a heading, [[ to link to another note, [[! to show a picture, $x$ for maths.`),J.contentAttributes.of({"aria-label":t.label,spellcheck:`true`,autocapitalize:`sentences`,autocorrect:`on`}),$e.of([{key:`Mod-s`,preventDefault:!0,run:()=>(t.onSave(),!0)},{key:`Mod-Enter`,preventDefault:!0,run:e=>(t.onAsk?.(Is(e.state)),!!t.onAsk)},...so,...Dt,...At,Ha,...Va,...ti]),J.domEventHandlers({mousedown(e,n){if(!t.onFollow||!(e.ctrlKey||e.metaKey)||e.button!==0)return!1;let r=n.posAtCoords({x:e.clientX,y:e.clientY},!1),i=r===null?null:uo(n.state,r),a=r===null||i?null:zs(n.state,r);if(a&&t.onCode)return e.preventDefault(),t.onCode(a),!0;let o=i?i.embed?ys(i.url):vs(i.url)??ys(i.url):null;return o===null?!i||!t.onCode||!i.url.trim().startsWith(`code:`)?!1:(e.preventDefault(),t.onCode(i.url.trim()),!0):(e.preventDefault(),t.onFollow(o),!0)}}),J.updateListener.of(e=>{e.docChanged&&t.onChange(e.state.doc.toString()),t.onCursor&&(e.selectionSet||e.docChanged)&&t.onCursor(Is(e.state))})]});return new J({state:n,parent:e})}function zs(e,t){let n=q(e);for(let r of[-1,1])for(let i=n.resolveInner(t,r);i;i=i.parent){if(i.name!==`Link`&&i.name!==`Image`)continue;let t=i.getChild(`URL`),n=t?e.sliceDoc(t.from,t.to).trim():``;return n.startsWith(`code:`)?n:null}return null}function Bs(e,t){if(t===e.state.doc.toString())return;let n=Math.min(e.state.selection.main.head,t.length);e.dispatch({changes:{from:0,to:e.state.doc.length,insert:t},selection:{anchor:n}})}var Vs=2e7,Hs={type:`string`};({...Hs}),{...Hs},{...Hs},{...Hs},{...Hs};var Us=`conversations`,Ws={type:`string`},Gs=(e,t,n,r)=>({type:`function`,function:{name:e,description:t,parameters:{type:`object`,properties:n,required:r,additionalProperties:!1}}});({...Ws}),{...Ws};var Ks=Gs(`read_data`,`A data file's shape: its columns with their types and ranges, the row count and the first rows. Read it before writing anything that uses the file, so the column names are real.`,{path:{...Ws,description:`The file's path in the base: folder/name.csv.`}},[`path`]),qs=Gs(`artifact_recipe`,`A recipe for an artifact: a complete working one to start from, the kit's reference, and the rules write_artifact checks. dashboard: numbers, charts and a table of one data file. compare: two data files side by side. simulation: a model with parameters and play. explorable: inputs, derived numbers and linked views. viewer: a 3D model.`,{name:{type:`string`,enum:[`dashboard`,`compare`,`simulation`,`explorable`,`viewer`]}},[`name`]),Js=Gs(`write_artifact`,`Write an artifact: a whole HTML file on the kit. The title, description and uses given here are written into it. It is checked, and run where it can be; the result says what to fix. Nothing is written while a rule is broken.`,{path:{...Ws,description:`Where: folder/name.html, beside the notes it belongs to.`},title:Ws,description:{...Ws,description:`One sentence: what it shows, and what can be done with it.`},uses:{type:`array`,items:Ws,description:`The data or model files it reads, relative to it (runs.csv). Those its markup and script name are added.`},html:{...Ws,description:`The whole file.`}},[`path`,`title`,`description`,`uses`,`html`]),Ys=Gs(`read_artifact`,`An artifact's whole file, to change it and write it again.`,{path:{...Ws,description:`folder/name.html`}},[`path`]);({...Ws}),{...Ws},`${Us}`,new Set([Ks,qs,Ys,Js].map(e=>e.function.name));var Xs=`The change is written at once, under your name: the person sees your words marked in the note, and can undo it from the browser. Use this, never edit or write, for any note of the knowledge base.`;`${Xs}`,`${Xs}`;var Zs=a(`<p class="same svelte-18j5w6l">This picture is already in the notes as <code> </code>.</p>`),Qs=a(`<code> </code> is taken: Enter makes it <code> </code>`,1),$s=a(`<code> </code>`),ec=a(`<label class="svelte-18j5w6l"><span class="svelte-18j5w6l">name</span> <span class="name svelte-18j5w6l"><input class="field mono svelte-18j5w6l" spellcheck="false" autocomplete="off" aria-label="Its name"/><span class="ext svelte-18j5w6l"> </span></span></label> <p><!></p>`,1),tc=a(`<button class="btn" type="button"> </button>`),nc=a(`<div class="picture-name svelte-18j5w6l" role="dialog" aria-label="Name the picture" tabindex="-1"><img alt="" class="svelte-18j5w6l"/> <div class="fields svelte-18j5w6l"><!> <label class="svelte-18j5w6l"><span class="svelte-18j5w6l">what it shows</span> <input class="field" placeholder="Iso reads this, not the picture" aria-label="What it shows" autocomplete="off"/></label> <div class="actions svelte-18j5w6l"><!> <button class="btn" type="button">Cancel</button> <button class="btn primary" type="button"> </button></div></div></div>`);function rc(t,n){C(n,!0);let r=F(()=>({"image/png":`png`,"image/jpeg":`jpg`,"image/gif":`gif`,"image/webp":`webp`,"image/svg+xml":`svg`,"image/avif":`avif`})[n.file.type]??`png`),i=x(re(n.suggested)),a=x(``),o=x(!1),c=x(void 0),u,f=F(()=>Ie(s(i))||`picture`),p=F(()=>`${n.folder?n.folder+`/`:``}${s(f)}.${s(r)}`),m=F(()=>n.taken(s(p))),h=F(()=>{for(let e=2;;e++)if(!n.taken(`${n.folder?n.folder+`/`:``}${s(f)}-${e}.${s(r)}`))return`${s(f)}-${e}`}),g=F(()=>n.same!==null&&!s(o));N(()=>{s(c)?(s(c).focus(),s(c).select()):u.focus()});function _(e){e.key===`Escape`?(e.preventDefault(),n.onDone(null)):e.key===`Enter`&&(e.preventDefault(),v())}function v(){if(!s(g)&&s(m)){k(i,s(h),!0);return}let e=s(g)?n.same:s(p);n.onDone({path:e,alt:s(a).trim()||Po(e),save:!s(g)})}var y=nc();let b;var ee=e(y),E=P(ee,2),O=e(E),ne=t=>{var r=Zs(),i=P(e(r)),a=I(i,!0);M(),D(r),l(()=>A(a,n.same)),d(t,r)},z=t=>{var n=ec(),a=w(n),o=P(e(a),2),u=e(o);S(u),te(u,e=>k(c,e),()=>s(c));var f=P(u),g=I(f);D(o),D(a);var _=P(a,2);let v;var y=e(_),b=e=>{var t=Qs(),n=w(t),i=I(n,!0),a=P(n,2),o=I(a);l(()=>{A(i,s(p)),A(o,`${s(h)??``}.${s(r)??``}`)}),d(e,t)},x=e=>{var t=$s(),n=I(t,!0);l(()=>A(n,s(p))),d(e,t)};j(y,e=>{s(m)?e(b):e(x,-1)}),D(_),l(()=>{A(g,`.${s(r)??``}`),v=B(_,1,`path svelte-18j5w6l`,null,v,{taken:s(m)})}),L(u,()=>s(i),e=>k(i,e)),d(t,n)};j(O,e=>{s(g)?e(ne):e(z,-1)});var ae=P(O,2),oe=P(e(ae),2);S(oe),te(oe,e=>u=e,()=>u),D(ae);var H=P(ae,2),U=e(H),W=e=>{var t=tc(),n=I(t,!0);l(()=>A(n,s(o)?`Use the one there`:`Save a copy`)),V(`click`,t,()=>{k(o,!s(o)),s(o)&&requestAnimationFrame(()=>{s(c)?.focus(),s(c)?.select()})}),d(e,t)};j(U,e=>{n.same!==null&&e(W)});var G=P(U,2),se=P(G,2),ce=I(se,!0);D(H),D(E),D(y),l(()=>{b=ie(y,``,b,{left:`${n.at.left??``}px`,top:`${n.at.top??``}px`}),T(ee,`src`,n.src),A(ce,s(g)?`Show it`:`Save`)}),V(`keydown`,y,_),L(oe,()=>s(a),e=>k(a,e)),V(`click`,G,()=>n.onDone(null)),V(`click`,se,v),d(t,y),R()}h([`keydown`,`click`]);var ic=a(`<div class="between stopped svelte-192cp36" role="alert"><p class="bad svelte-192cp36"> </p> <div class="foot svelte-192cp36"><span class="grow"></span><button class="link svelte-192cp36" type="button">dismiss</button></div></div>`),ac=a(`<p class="soft lost svelte-192cp36"><span class="strike svelte-192cp36"> </span> </p>`),oc=a(`<div class="between stopped svelte-192cp36"><p class="label"> </p> <!> <div class="foot svelte-192cp36"><span class="grow"></span><button class="btn remove" type="button">remove</button></div></div>`),sc=a(`<p class="label">The place this was written for is no longer in the note, so it is shown here. Keeping it adds it at the end.</p>`),cc=a(`<textarea class="revision svelte-192cp36" aria-label="Iso's text, to edit"></textarea>`),lc=a(`<div class="prose said svelte-192cp36"></div>`),uc=a(`<p class="label"> </p>`),dc=a(`<button class="btn edit" type="button">done</button>`),fc=a(`<button class="btn edit" type="button">edit</button>`),pc=a(`<div class="between svelte-192cp36"><!> <!> <!> <div class="foot svelte-192cp36"><i class="dia svelte-192cp36" aria-hidden="true"></i> <span class="grow"></span> <button class="btn keep" type="button">keep</button> <!> <button class="btn remove" type="button">remove</button></div></div>`);function mc(t,n){C(n,!0);let r=O(n,`iso`,7),a=F(()=>n.key.startsWith(`p:`)?r().proposals.find(e=>e.id===n.key.slice(2)):void 0),o=F(()=>s(a)&&r().editing?.id===s(a).id?r().editing:null),c=F(()=>!!s(a)&&r().busy===s(a)?.id),u=F(()=>r().changes.filter(e=>!e.at));var f=p(),m=w(f),h=t=>{var n=ic(),i=e(n),a=I(i,!0),o=P(i,2),s=P(e(o));D(o),D(n),l(()=>A(a,r().failed.message)),V(`click`,s,()=>r().failed=null),d(t,n)},_=t=>{var n=oc(),a=e(n),o=I(a),c=P(a,2);i(c,17,()=>s(u),e=>e.key,(t,n)=>{var r=ac(),i=e(r),a=I(i,!0),o=P(i);D(r),l((e,t)=>{A(a,e),A(o,` → ${t??``}`)},[()=>s(n).proposal.regions[s(n).k].old.text.trim(),()=>s(n).proposal.regions[s(n).k].new.trim()||`(taken out)`]),d(t,r)});var f=P(c,2),p=P(e(f));D(f),D(n),l(()=>A(o,`${s(u).length===1?`One change Iso offered is`:`${s(u).length} changes Iso offered are`} for text that is no longer in the note as it was, so ${s(u).length===1?`it`:`they`} cannot be kept.`)),V(`click`,p,()=>{for(let e of s(u))r().discardChange(e)}),d(t,n)},v=t=>{var n=pc(),i=e(n),u=e=>{var t=sc();d(e,t)},f=F(()=>!r().placed(s(a)));j(i,e=>{s(f)&&e(u)});var p=P(i,2),m=e=>{var t=cc();ee(t),l(e=>T(t,`rows`,e),[()=>Math.max(3,s(o).text.split(`
|
|
13
|
-
`).length+1)]),L(t,()=>s(o).text,e=>s(o).text=e),d(e,t)},h=e=>{var t=lc();g(t,()=>Le(s(a).text),!0),D(t),z(t,(e,t)=>We?.(e,t),()=>({given:s(a).text,copy:!0})),d(e,t)};j(p,e=>{s(o)?e(m):e(h,-1)});var _=P(p,2),v=e=>{var t=uc(),n=I(t,!0);l(()=>A(n,s(a).notice)),d(e,t)};j(_,e=>{s(a).notice&&e(v)});var y=P(_,2),b=P(e(y),4),x=P(b,2),S=e=>{var t=dc();V(`click`,t,()=>r().done(s(a))),d(e,t)},C=e=>{var t=fc();l(()=>t.disabled=s(c)),V(`click`,t,()=>r().edit(s(a))),d(e,t)};j(x,e=>{s(o)?e(S):e(C,-1)});var w=P(x,2);D(y),D(n),l(()=>{T(n,`data-proposal`,s(a).id),b.disabled=s(c),w.disabled=s(c)}),V(`click`,b,()=>r().keep(s(a))),V(`click`,w,()=>r().discard(s(a))),d(t,n)};j(m,e=>{n.key===`failed`&&r().failed?e(h):n.key===`lost`&&s(u).length?e(_,1):s(a)&&e(v,2)}),d(t,f),R()}h([`click`]);var hc=a(`<span class="label who svelte-1o10yjh"> </span>`),gc=a(`<!> <span class="act svelte-1o10yjh"><button class="keep svelte-1o10yjh" type="button" aria-label="Keep this change">keep</button><button class="remove svelte-1o10yjh" type="button" aria-label="Remove this change">remove</button></span>`,1),_c=a(`<span class="gone svelte-1o10yjh">the passage above is taken out</span>`),vc=a(`<pre class="new svelte-1o10yjh"> </pre>`),yc=a(`<div class="new prose svelte-1o10yjh"></div>`),bc=a(`<div><!> <div class="foot svelte-1o10yjh"><i class="dia svelte-1o10yjh" aria-hidden="true"></i><span class="label">in place of the lines struck through above</span><span class="grow"></span><!></div></div>`),xc=a(`<span class="new svelte-1o10yjh"></span>`),Sc=a(`<span class="gone svelte-1o10yjh">taken out</span>`),Cc=a(`<span class="change svelte-1o10yjh"><!> <!></span>`);function wc(t,n){C(n,!0);let r=t=>{var r=gc(),a=w(r),c=e=>{var t=hc(),n=I(t,!0);l(()=>{T(t,`title`,s(i)?.proposal.asked),A(n,s(f))}),d(e,t)};j(a,e=>{s(f)&&e(c)});var u=P(a,2),p=e(u),m=P(p);D(u),l(()=>{p.disabled=s(o),m.disabled=s(o)}),V(`click`,p,()=>s(i)&&n.iso.keepChange(s(i))),V(`click`,m,()=>s(i)&&n.iso.discardChange(s(i))),d(t,r)},i=F(()=>n.iso.changes.find(e=>e.key===n.key)),a=F(()=>s(i)?s(i).proposal.regions[s(i).k].new:``),o=F(()=>n.iso.busy===n.key||n.iso.busy===`all`),c=F(()=>Le(s(a).trim())),u=F(()=>s(c).replace(/^<p>([\s\S]*)<\/p>\s*$/,`$1`)),f=F(()=>s(i)?qe(s(i).proposal.who):``);var m=p(),h=w(m),_=t=>{var o=bc();let u;var f=e(o),p=e=>{var t=_c();d(e,t)},m=F(()=>!s(a).trim()),h=e=>{var t=vc(),n=I(t,!0);l(e=>A(n,e),[()=>s(a).replace(/^\n+|\s+$/g,``)]),d(e,t)},_=e=>{var t=yc();g(t,()=>s(c),!0),D(t),z(t,(e,t)=>We?.(e,t),()=>s(c)),d(e,t)};j(f,e=>{s(m)?e(p):s(i).code?e(h,1):e(_,-1)});var v=P(f,2),y=P(e(v),3);r(y),D(v),D(o),l(()=>{u=B(o,1,`change block svelte-1o10yjh`,null,u,{code:s(i).code}),T(o,`data-change`,n.key)}),d(t,o)},v=t=>{var i=Cc(),o=e(i),c=e=>{var t=xc();g(t,()=>s(u),!0),D(t),d(e,t)},f=F(()=>s(a).trim()),p=e=>{var t=Sc();d(e,t)};j(o,e=>{s(f)?e(c):e(p,-1)});var m=P(o,2);r(m),D(i),l(()=>T(i,`data-change`,n.key)),d(t,i)};j(h,e=>{s(i)?.block?e(_):s(i)&&e(v,1)}),d(t,m),R()}h([`click`]);var Tc=a(`<p class="said svelte-hrl8lz" role="status"> </p>`),Ec=a(`<div></div> <!> <!>`,1);function Dc(e,n){C(n,!0);let r=O(n,`iso`,7),i=O(n,`reading`,3,!1),a=O(n,`touched`,3,null),c=O(n,`lens`,19,()=>[]),f,p=x(void 0),m=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`image/svg+xml`,`image/avif`],h=x(null),g=x(null),_,y=e=>{k(g,e,!0),clearTimeout(_),_=setTimeout(()=>k(g,null),8e3)};async function ee(e,t,r){if(!s(p)||s(h))return;let i=n.note.id,a=!i.startsWith(`@`),o=a?i:`pictures`,c=e=>a&&e.startsWith(`${i}/`)?Fo(e.slice(i.lastIndexOf(`/`)+1)):`/${Fo(e)}`,l=[];try{l=await K.api.pictures()}catch{}let u=new Set(l.map(e=>e.path));for(let n of e){if(!m.includes(n.type)){y(`${n.name||`That`} isn't a picture isorite keeps: png, jpg, gif, webp, svg and avif are.`);continue}if(n.size>2e7){y(`${n.name||`That picture`} is larger than isorite takes (${Vs/1e6} MB).`);continue}let e=new Uint8Array(await n.arrayBuffer()),i=await Pe(e),a=l.find(e=>e.sha256===i)?.path??null,d=URL.createObjectURL(n),g=s(p),_=g.coordsAtPos(Math.min(t,g.state.doc.length)),v=f.getBoundingClientRect(),b=await new Promise(e=>{k(h,{file:n,src:d,folder:o,same:a,onDone:e,suggested:r||!n.name?Fe():Ie(n.name)||`picture`,taken:e=>u.has(e),at:{left:Math.max(16,Math.min(_?.left??v.left,innerWidth-476)),top:Math.min((_?.bottom??v.top)+6,innerHeight-220)}})});if(k(h,null),URL.revokeObjectURL(d),!b)continue;if(b.save)try{let t=await K.api.savePicture(b.path,e);l.push(t),u.add(t.path)}catch(e){y(`It wasn't saved: ${e.message}`);continue}let x=`![${b.alt.replace(/[[\]]/g,``)}](${c(b.path)})`;g.dispatch({changes:{from:t,insert:x},selection:{anchor:t+x.length}}),t+=x.length}s(p).focus()}let S=F(()=>n.source||!r()?{lines:0,chars:0}:r().head),T=F(()=>{if(!r())return{blocks:[],marks:[],inline:[]};let e=e=>t=>({kind:e,from:t.from-s(S).chars,to:t.to-s(S).chars});return{blocks:r().layout.blocks.map(e=>({key:e.key,line:Math.max(0,e.line-s(S).lines)})).sort((e,t)=>e.line-t.line),marks:[...r().layout.old.map(e(`old`)),...c().map(t=>e(t.kind)(t))].filter(e=>e.to>0),inline:r().layout.inline.map(e=>({key:e.key,at:e.at-s(S).chars})).filter(e=>e.at>=0)}});N(()=>{let e=Rs(f,{doc:n.source?n.note.text:n.note.body,source:n.source,readOnly:i(),label:n.source?`The note's file`:`The note`,notes:()=>K.listing.notes.filter(e=>e.id!==n.note.id).map(e=>({id:e.id,title:e.title,folder:e.dir,...e.kind?{kind:e.kind}:{}})),noteMaker:{plan:e=>{let t=Mo(e),r=pe(t);if(!r)return null;let i=n.note.id.startsWith(`@`)||!n.note.id.includes(`/`)?``:n.note.id.slice(0,n.note.id.lastIndexOf(`/`));return{title:t,id:[i,r].filter(Boolean).join(`/`),folder:i}},make:e=>{K.api.createNote(e.id,`---\ntype: Concept\ntitle: ${JSON.stringify(e.title)}\n---\n\n`).then(()=>K.refresh(),t=>y(`${e.title} wasn't made: ${t.message}`))}},onPictures:(e,t,n)=>{ee(e,t,n)},pictureSource:{pictures:async()=>(await K.api.pictures()).map(e=>({path:e.path,width:e.width,height:e.height,src:Re(K.api,{path:e.path,from:`notes`})})),here:()=>n.note.id},onChange:e=>n.source?n.note.setText(e):n.note.setBody(e),onSave:()=>{n.note.save()},onCode:e=>{H(Se(e))},onFollow:e=>{H(ve(e))},embeds:{find:Te,open:e=>{H(ve(e))}},onPoint:e=>Ge.set(`note`,e?{...e,who:`you`}:null),codeBroken:e=>K.listing.notes.find(e=>e.id===n.note.id)?.broken?.includes(e)??!1,pictures:e=>{let t=Ve(e,n.note.id);return t?{key:`${t.from}:${t.path}`,src:Re(K.api,t)}:null},artifacts:e=>{let r=e.trim().startsWith(`code:`)?de(e.trim()):null;if(r&&W(r.path)!==`image`)return{path:e,mount:n=>{let r=t(gr,{target:n,props:{href:e.trim()}});return()=>{u(r)}}};let i=dn(e,n.note.id);return i?{path:i,mount:e=>{let n=t(yr,{target:e,props:{path:i}});return()=>{u(n)}}}:null},...r()?{onAsk:e=>{let t=n.note.text.slice(e.from+s(S).chars,e.to+s(S).chars).trim();t&&Ze.add({kind:`passage`,id:n.note.id,title:n.note.fields.title||n.note.id,text:t}),Ye.to(`iso`),requestAnimationFrame(()=>document.getElementById(`iso-box`)?.focus())},onCursor:e=>{r().cursor={line:e.line+s(S).lines,from:e.from+s(S).chars,to:e.to+s(S).chars}},mountOverlay:(e,n)=>{let i=t(n.startsWith(`r:`)?wc:mc,{target:e,props:{iso:r(),key:n}});return()=>{u(i)}}}:{placeholder:o(()=>n.placeholder)??`Write what you understand, what you do not, and what you want from Iso. [[ links a note it should rest on.`}});return k(p,e),()=>{e.destroy(),Ge.set(`note`,null)}}),v(()=>{n.note.revision,o(()=>{s(p)&&Bs(s(p),n.source?n.note.text:n.note.body)})}),v(()=>{let e=a(),t=s(S).lines;s(p)&&s(p).dispatch({effects:xs.of(e?{who:e.who,lines:e.lines.map(e=>e-t)}:null)})}),v(()=>{let e=Ge.onAtlas;s(p)&&s(p).dispatch({effects:Ds.of(e)})}),v(()=>{let{blocks:e,marks:t,inline:n}=s(T);s(p)&&s(p).dispatch({effects:[bs.of(e),Cs.of({marks:t,inline:n})]})});var E=Ec(),D=w(E);let ne;te(D,e=>f=e,()=>f);var M=P(D,2),re=e=>{rc(e,b(()=>s(h)))};j(M,e=>{s(h)&&e(re)});var L=P(M,2),ie=e=>{var t=Tc(),n=I(t,!0);l(()=>A(n,s(g))),d(e,t)};j(L,e=>{s(g)&&e(ie)}),l(()=>ne=B(D,1,`editor svelte-hrl8lz`,null,ne,{source:n.source})),d(e,E),R()}var Oc=a(`<h1 class="serif title svelte-130pv1o"> </h1>`),kc=a(`<p class="asked svelte-130pv1o"><i class="dia svelte-130pv1o" aria-hidden="true"></i><span> </span></p>`),Ac=a(`<div class="offered svelte-130pv1o" aria-label="What Iso offered"><p class="serif svelte-130pv1o"> </p></div>`),jc=a(`<div class="version svelte-130pv1o"><!> <!> <div class="text svelte-130pv1o"></div> <!></div>`);function Mc(t,n){C(n,!0);let r=F(()=>{try{let[e,t,r]=ue(n.text);return{title:/^title:\s*(.*)$/m.exec(t??``)?.[1]?.trim().replace(/^["']|["']$/g,``)??``,body:r,lines:e.split(`
|
|
14
|
-
`).length-1}}catch{return{title:``,body:n.text,lines:0}}}),i,a=x(void 0);N(()=>(k(a,Rs(i,{doc:s(r).body,onChange:()=>void 0,onSave:()=>void 0,label:`The note as it was`,notes:()=>[],readOnly:!0,pictures:e=>{let t=Ve(e,n.id);return t?{key:`${t.from}:${t.path}`,src:Re(K.api,t)}:null}})),()=>s(a)?.destroy())),v(()=>{let e=n.touched,t=s(r).lines;s(a)?.dispatch({effects:xs.of(e?{who:e.who,lines:e.lines.map(e=>e-t)}:null)})});var o=jc(),c=e(o),u=e=>{var t=Oc(),n=I(t,!0);l(()=>A(n,s(r).title)),d(e,t)};j(c,e=>{s(r).title&&s(r).title!==n.title&&e(u)});var f=P(c,2),p=t=>{var r=kc(),i=P(e(r)),a=I(i,!0);D(r),l(()=>A(a,n.asked)),d(t,r)};j(f,e=>{n.asked!==void 0&&e(p)});var m=P(f,2);te(m,e=>i=e,()=>i);var h=P(m,2),g=t=>{var r=Ac(),i=e(r),a=I(i,!0);D(r),l(()=>A(a,n.offered)),d(t,r)};j(h,e=>{n.offered!==void 0&&e(g)}),D(o),d(t,o),R()}var Nc=(t,n=E,r=E)=>{var i=Ic();let a;var o=e(i),s=e=>{var t=Pc();l(()=>T(t,`fill`,r()?`currentColor`:`none`)),d(e,t)},c=e=>{var t=Fc();l(()=>T(t,`fill`,r()?`currentColor`:`none`)),d(e,t)};j(o,e=>{n()===`question`?e(s):e(c,-1)}),D(i),l(()=>a=B(i,0,`glyph ${n()??``}`,`svelte-18ltlst`,a,{solved:r()})),d(t,i)},Pc=c(`<path d="M8 2.5L13.5 8L8 13.5L2.5 8Z"></path>`),Fc=c(`<path d="M8 2.5l5.8 10.5H2.2z"></path>`),Ic=c(`<svg viewBox="0 0 16 16" width="18" height="18" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.4"><!></svg>`),Lc=a(`<p class="faint"><!></p>`),Rc=a(`<p class="soft">There is no note at <span class="faint"> </span>.</p> <p><a>all notes</a></p>`,1),zc=a(`<p class="bad svelte-18ltlst"> </p>`),Bc=a(`<button class="btn" type="button">take theirs</button>`),Vc=a(`<div class="frame choice svelte-18ltlst" role="alert"><span class="frame-title">changed elsewhere</span> <p> </p> <div class="row svelte-18ltlst"><button class="btn primary" type="button">keep mine</button> <!></div> <p class="faint">Whichever you keep, the other stays in the note's journal.</p></div>`),Hc=a(`<div class="titlerow svelte-18ltlst"><!> <h1 class="serif title read svelte-18ltlst"> </h1></div>`),Uc=a(`<div class="titlerow svelte-18ltlst"><!> <label class="hidden-label" for="title">Title</label> <textarea id="title" class="serif title svelte-18ltlst" rows="1" autocomplete="off"></textarea></div>`),Wc=a(`<span class="grow faint"> </span>`),Gc=a(`<div class="tl-col svelte-18ltlst"><!></div>`),Kc=a(`<span class="bad svelte-18ltlst" role="alert"> </span>`),qc=a(`<div class="atbar svelte-18ltlst" role="status"><span class="label"> </span> <span class="grow"></span> <!> <button class="icon svelte-18ltlst" type="button" aria-label="restore to here" title="restore to here"><svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M3.2 9.5A5 5 0 1 0 4.6 4.3" stroke="currentColor" stroke-width="1.3" fill="none"></path><path d="M3 1.8v3.4h3.4" stroke="currentColor" stroke-width="1.3" fill="none"></path></svg></button> <button class="icon svelte-18ltlst" type="button" aria-label="back to now" title="back to now"><svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M2 8h9M8 4.8 11.2 8 8 11.2" stroke="currentColor" stroke-width="1.3" fill="none"></path><path d="M13.5 3v10" stroke="currentColor" stroke-width="1.3"></path></svg></button></div> <!>`,1),Jc=a(`<span class="toiso svelte-18ltlst" role="group" aria-label="The selected passage"><button type="button" title="Put it above Iso's box, to go with your next message from the pane" class="svelte-18ltlst"><i class="dia svelte-18ltlst" aria-hidden="true">◆</i>add to Iso's message</button> <button type="button" title="Copy it with the note it is from, to paste into an agent in your terminal" class="svelte-18ltlst"> </button></span>`),Yc=c(`<svg class="ok svelte-18ltlst" viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M3 8.5l3 3 7-7"></path></svg>`),Xc=a(`<li><a><!><span class="svelte-18ltlst"> </span><!></a></li>`),Zc=a(`<ul class="attached svelte-18ltlst"></ul>`),Qc=a(`<div class="changes svelte-18ltlst" role="status"><i class="dia svelte-18ltlst" aria-hidden="true"></i> <span class="soft"> </span> <span class="grow"></span> <button class="link svelte-18ltlst" type="button">keep all</button> <button class="link svelte-18ltlst" type="button">remove all</button></div>`),$c=a(`<!> <div class="head svelte-18ltlst"><!> <div class="side svelte-18ltlst"><div class="tools svelte-18ltlst"><button class="btn quiet svelte-18ltlst" type="button" title="The note as it is read, to be read and not edited">read</button> <button class="btn quiet svelte-18ltlst" type="button">source</button></div></div></div> <!> <!> <!> <!> <div class="live"><!></div> <!> <!>`,1),el=a(`<article><!></article>`);function tl(t,r){C(r,!0);let a=new Gn(r.id),o=new Bn(a),c=x(!1),u=F(()=>s(c)||a.meta===null),p=x(!1),h=F(()=>s(p)&&!s(u)),g=F(()=>Ye.on.timeline),y=x(null),b=x(null),S=x(!1),E=x(``),O=F(()=>xe(o.entries)),L=e=>e.who.startsWith(`iso:`)||e.who.startsWith(`agent:`),z=e=>e.flatMap(e=>Array.from({length:e.to-e.from},(t,n)=>e.from+n)),ae=F(()=>{if(!s(g)||s(b)||s(u))return null;let e=s(y)??(s(ce)?void 0:s(O).findLast(e=>L(e)&&(e.what===`kept`||e.what===`edited`)));if(!e)return null;let t=z(fe(o.entries,e.ids).runs);return t.length?{who:L(e)?`iso`:`you`,lines:t}:null}),U=F(()=>{if(!s(b))return null;let e=Me(s(b)),t=ge(o.entries,e);if(t===null)return null;let n=o.entries.filter(t=>t.id<=e),r=o.entries.find(e=>e.id===s(b).ids[0]),i=(s(b).what===`offered`||s(b).what===`discarded`)&&r?.kind===`proposal`?r.form===`insert`?r.text:r.regions.map(e=>e.new).join(`
|
|
15
|
-
|
|
16
|
-
`):void 0;return{text:t,touched:{who:L(s(b))?`iso`:`you`,lines:z(fe(n,s(b).ids).runs)},asked:s(b).asked,offered:i}}),W=()=>Xe.url.searchParams.get(`at`)??new URLSearchParams(location.hash.split(`?`)[1]??``).get(`at`),G=x(re(W()));v(()=>{let e=W();e&&k(G,e,!0)}),v(()=>{if(!s(G))return;let e=s(O).find(e=>e.ids.includes(s(G)));e&&(k(G,null),Ye.flip(`timeline`,!0),k(b,e))});let ce=F(()=>Ye.on.provenance);v(()=>{s(g)||(k(b,null),k(y,null))});let le=F(()=>{if(!s(ce)||a.loaded!==`ready`)return[];let e=[],t=Ee(o.entries),n=a.text.split(`
|
|
17
|
-
`);if(t&&t.length===n.length){let r=0;for(let[i,a]of n.entries()){for(let n of t[i])(n.who.startsWith(`iso:`)||n.who.startsWith(`agent:`))&&n.to<=a.length&&a.slice(n.from,n.to).trim()&&e.push({kind:`by-iso`,from:r+n.from,to:r+n.to});r+=a.length+1}}for(let t of Ze.parts){if(t.kind!==`passage`||t.id!==r.id)continue;let n=a.text.indexOf(t.text);n>=0&&e.push({kind:`given`,from:n,to:n+t.text.length})}return e});function ue(e){k(E,``),k(b,s(b)===e?null:e)}function de(e){if(!s(b))return;let t=s(O).indexOf(s(b))+e;t>=0&&t<s(O).length&&k(b,s(O)[t])}async function me(){if(s(b)){k(S,!0),k(E,``);try{await a.restore(Me(s(b))),k(b,null)}catch(e){k(E,e.message,!0)}finally{k(S,!1)}}}function he(e){!s(b)||e.altKey||e.ctrlKey||e.metaKey||e.target instanceof HTMLElement&&(e.target.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.target.tagName))||(e.key===`ArrowLeft`||e.key===`ArrowUp`?(e.preventDefault(),de(-1)):e.key===`ArrowRight`||e.key===`ArrowDown`?(e.preventDefault(),de(1)):e.key===`Escape`&&(e.preventDefault(),k(b,null)))}N(()=>{K.open=r.id,a.open().then(()=>o.open());let e=()=>{a.save()};return addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,e),()=>{removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,e),o.close(),a.close(),K.here=``,K.open=``,K.saving=null}});async function _e(){let e=r.id.split(`/`).at(-1),t=a.fields.title.trim();if(!/^untitled-(note|question|problem)(-\d+)?$/.test(e)||!t||/^untitled (note|question|problem)( \d+)?$/i.test(t))return;let n=[...r.id.split(`/`).slice(0,-1),pe(t)].filter(Boolean).join(`/`);if(pe(t)&&!K.listing.notes.some(e=>e.id===n))try{let e=await a.move(n);await K.refresh(),await H(ve(e),{replaceState:!0})}catch{}}v(()=>{a.loaded===`ready`&&Ye.fresh===r.id&&(Ye.fresh=``,_().then(()=>{let e=document.getElementById(`title`);e?.focus(),e?.select()}))});let be={saved:`saved`,unsaved:`not saved yet`,saving:`saving`,conflict:`changed elsewhere: choose below`,failed:`not saved`};v(()=>{K.here=a.loaded===`ready`?a.fields.title||r.id.split(`/`).at(-1):``,K.saving=a.loaded===`ready`?{text:a.saving===`failed`?`not saved: ${a.message}`:be[a.saving],bad:a.saving===`failed`||a.saving===`conflict`}:null});let Se=F(()=>[...new Set(o.changes.map(e=>qe(e.proposal.who)||`Iso`))].join(` and `)),Ce=F(()=>ye(String(a.meta?.type??``))),we=F(()=>s(Ce)===`note`?null:se(a.meta??{},s(Ce))),Te=F(()=>K.listing.notes.filter(e=>e.kind&&e.id!==r.id&&e.attached?.includes(r.id)).sort((e,t)=>e.kind===t.kind?0:e.kind===`question`?-1:1)),De=x(!1);async function Oe(){k(De,!0);try{await a.setDone(!s(we))}catch{}finally{k(De,!1)}}let ke=F(()=>o.cursor&&o.cursor.to>o.cursor.from?a.text.slice(o.cursor.from,o.cursor.to).trim():``),Ae=x(void 0),je=x(null);v(()=>{if(o.cursor,!s(ke)||!s(Ae)||s(u)||s(b)){k(je,null);return}let e=requestAnimationFrame(()=>{let e=getSelection(),t=s(Ae).getBoundingClientRect(),n=e?.rangeCount?e.getRangeAt(0).getBoundingClientRect():null;!n||!n.width&&!n.height?k(je,{top:8,left:t.width-140},!0):k(je,{top:Ye.narrow?n.bottom-t.top+30:n.top-t.top-36,left:Math.max(8,Math.min(n.left-t.left,t.width-140))},!0)});return()=>cancelAnimationFrame(e)});let Ne=x(!1);function Pe(){if(!s(ke))return;let e=s(ke).split(`
|
|
18
|
-
`).map(e=>`> ${e}`).join(`
|
|
19
|
-
`);navigator.clipboard?.writeText(`From /${r.id}.md in the notes:\n\n${e}\n`).then(()=>{k(Ne,!0),setTimeout(()=>{k(Ne,!1),k(je,null)},900)},()=>void 0)}function Fe(){s(ke)&&(Ze.add({kind:`passage`,id:r.id,title:a.fields.title||r.id,text:s(ke)}),k(je,null))}var Ie=el();n(`keydown`,m,he);let Le;var Re=e(Ie),ze=t=>{var n=Lc();zn(e(n),{label:`opening`}),D(n),d(t,n)},Ve=t=>{var n=Rc(),i=w(n),a=P(e(i)),o=I(a,!0);M(),D(i);var s=P(i,2),c=I(s);l(e=>{A(o,r.id),T(c,`href`,e)},[()=>oe(`/notes`)]),d(t,n)},He=e=>{var t=zc(),n=I(t,!0);l(()=>A(n,a.message)),d(e,t)},Ue=t=>{var m=$c(),_=w(m),v=t=>{var n=Vc(),r=P(e(n),2),i=I(r,!0),o=P(r,2),s=e(o),c=P(s,2),u=e=>{var t=Bc();V(`click`,t,()=>a.keepTheirs()),d(e,t)};j(c,e=>{a.theirs&&e(u)}),D(o),M(2),D(n),l(()=>A(i,a.theirs===null?`This note was deleted or moved while you were writing.`:`This note was changed somewhere else while you were writing. Nothing here has been saved over it.`)),V(`click`,s,()=>a.keepMine()),d(t,n)};j(_,e=>{a.saving===`conflict`&&e(v)});var x=P(_,2),C=e(x),te=t=>{var n=Hc(),i=e(n),o=e=>{Nc(e,()=>s(Ce),()=>!!s(we))};j(i,e=>{s(Ce)!==`note`&&e(o)});var c=P(i,2),u=I(c,!0);D(n),l(e=>A(u,e),[()=>a.fields.title||r.id.split(`/`).at(-1)]),d(t,n)},N=t=>{var i=Uc(),o=e(i),c=e=>{Nc(e,()=>s(Ce),()=>!!s(we))};j(o,e=>{s(Ce)!==`note`&&e(c)});var u=P(o,4);ee(u),D(i),l(e=>{ne(u,a.fields.title),T(u,`placeholder`,e)},[()=>r.id.split(`/`).at(-1)]),V(`input`,u,e=>a.setFields({title:e.currentTarget.value.replace(/\s*\n\s*/g,` `)})),V(`keydown`,u,e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())}),n(`blur`,u,()=>void _e()),d(t,i)},re=e=>{var t=Wc(),n=I(t);l(()=>A(n,`${r.id??``}.md${a.meta===null?`: the frontmatter cannot be read, so the file is shown as it is`:``}`)),d(e,t)};j(C,e=>{s(h)?e(te):s(u)?e(re,-1):e(N,1)});var L=P(C,2),R=e(L),z=e(R),oe=P(z,2);D(R),D(L),D(x);var H=P(x,2),W=e=>{lr(e,{get note(){return a},get kind(){return s(Ce)},get done(){return s(we)},get marking(){return s(De)},onmark:()=>void Oe()})};j(H,e=>{!s(u)&&!s(h)&&e(W)});var G=P(H,2),se=t=>{var n=Gc(),r=e(n);{let e=F(()=>s(b)?Me(s(b)):null);Be(r,{get moments(){return s(O)},strata:!0,get at(){return s(e)},get pointed(){return s(y)},point:e=>k(y,e),pick:ue})}D(n),d(t,n)};j(G,e=>{s(g)&&!s(u)&&!s(h)&&e(se)});var ce=P(G,2),de=t=>{var n=qc(),r=w(n),i=e(r),o=I(i),c=P(i,4),u=e=>{var t=Kc(),n=I(t,!0);l(()=>A(n,s(E))),d(e,t)};j(c,e=>{s(E)&&e(u)});var p=P(c,2),m=P(p,2);D(r);var h=P(r,2);f(h,()=>Me(s(b)),e=>{Mc(e,{get id(){return a.id},get text(){return s(U).text},get title(){return a.fields.title},get touched(){return s(U).touched},get asked(){return s(U).asked},get offered(){return s(U).offered}})}),l((e,t)=>{A(o,`${e??``} · ${t??``}`),p.disabled=s(S)||s(U).text===a.text},[()=>Je(s(b)),()=>Ke(s(b).at)]),V(`click`,p,me),V(`click`,m,()=>k(b,null)),d(t,n)};j(ce,e=>{s(b)&&s(U)&&e(de)});var fe=P(ce,2),pe=t=>{var n=Jc();let r;var i=e(n),a=P(i,2),o=I(a,!0);D(n),l(()=>{r=ie(n,``,r,{top:`${s(je).top??``}px`,left:`${s(je).left??``}px`}),A(o,s(Ne)?`copied`:`copy for a terminal`)}),V(`pointerdown`,i,e=>{e.preventDefault(),Fe()}),V(`click`,i,e=>{e.detail===0&&Fe()}),V(`pointerdown`,a,e=>{e.preventDefault(),Pe()}),V(`click`,a,e=>{e.detail===0&&Pe()}),d(t,n)};j(fe,e=>{s(je)&&e(pe)});var he=P(fe,2),ge=e(he);f(ge,()=>`${s(u)}${s(h)}`,e=>{Dc(e,{get note(){return a},get iso(){return o},get source(){return s(u)},get reading(){return s(h)},get touched(){return s(ae)},get lens(){return s(le)}})}),D(he);var ye=P(he,2),be=t=>{var n=Zc();i(n,21,()=>s(Te),e=>e.id,(t,n)=>{var r=Xc(),i=e(r);let a;var o=e(i);Nc(o,()=>s(n).kind??`question`,()=>!!s(n).done);var c=P(o),u=I(c,!0),f=P(c),p=e=>{var t=Yc();d(e,t)};j(f,e=>{s(n).done&&e(p)}),D(i),D(r),l(e=>{T(i,`href`,e),a=B(i,1,`svelte-18ltlst`,null,a,{done:!!s(n).done&&s(n).kind===`question`}),A(u,s(n).title)},[()=>ve(s(n).id)]),d(t,r)}),D(n),d(t,n)};j(ye,e=>{s(Te).length&&!s(u)&&!s(b)&&!s(h)&&e(be)});var xe=P(ye,2),K=t=>{var n=Qc(),r=P(e(n),2),i=I(r),a=P(r,4),c=P(a,2);D(n),l(()=>{A(i,`${o.changes.length??``} ${o.changes.length===1?`change`:`changes`} from ${s(Se)??``} waiting`),a.disabled=o.busy===`all`,c.disabled=o.busy===`all`}),V(`click`,a,()=>o.settleAll(!0)),V(`click`,c,()=>o.settleAll(!1)),d(t,n)};j(xe,e=>{o.changes.length&&e(K)}),l(e=>{T(z,`aria-pressed`,s(h)),z.disabled=s(u),T(oe,`aria-pressed`,s(u)),oe.disabled=a.meta===null,T(he,`hidden`,e)},[()=>!!(s(b)&&s(U))]),V(`click`,z,()=>k(p,!s(p))),V(`click`,oe,()=>{k(p,!1),k(c,!s(c))}),d(t,m)};j(Re,e=>{a.loaded===`loading`?e(ze):a.loaded===`missing`?e(Ve,1):a.loaded===`error`?e(He,2):e(Ue,-1)}),D(Ie),te(Ie,e=>k(Ae,e),()=>s(Ae)),l(()=>Le=B(Ie,1,`note svelte-18ltlst`,null,Le,{reading:s(h),timed:s(g)&&a.loaded===`ready`&&!s(u)&&!s(h)})),d(t,Ie),R()}h([`click`,`input`,`keydown`,`pointerdown`]);function nl(e,t){C(t,!0);let n=F(()=>Xe.params.id??``),r=F(()=>!s(n).startsWith(`@`)&&W(s(n))!==null&&!K.listing.notes.some(e=>e.id===s(n)));var i=p(),a=w(i);f(a,()=>s(n),e=>{var t=p(),i=w(t),a=e=>{Ln(e,{get path(){return s(n)}})},o=e=>{tl(e,{get id(){return s(n)}})};j(i,e=>{s(r)?e(a):e(o,-1)}),d(e,t)}),d(e,i),R()}export{nl as component};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"../chunks/Cz6kYWmu.js";import"../chunks/xihTtKlq.js";import{t as e}from"../chunks/Bg-39frG.js";import"../chunks/0qd6IUbO.js";function t(t){e(t,{})}export{t as component};
|