isorite 0.16.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +1634 -62
- package/package.json +4 -1
- package/web/_app/immutable/assets/0.BGpjfMlq.css +1 -0
- package/web/_app/immutable/assets/4.Dn5sJ8uq.css +1 -0
- package/web/_app/immutable/assets/5.DJhOSn7C.css +1 -0
- package/web/_app/immutable/assets/NoteList.Wxp_AH0Y.css +1 -0
- package/web/_app/immutable/chunks/{BQeONalw.js → -_CDfwKC.js} +1 -1
- package/web/_app/immutable/chunks/{BtcGx-KQ.js → -oRvYXNk.js} +1 -1
- package/web/_app/immutable/chunks/0qd6IUbO.js +1 -0
- package/web/_app/immutable/chunks/{DbtvzL7r.js → 7faei0hL.js} +1 -1
- package/web/_app/immutable/chunks/{zasx25UV.js → BArcFmbE.js} +3 -3
- package/web/_app/immutable/chunks/BF1TezEe.js +1 -0
- package/web/_app/immutable/chunks/{Kem7IXj7.js → BF3mdiSX.js} +1 -1
- package/web/_app/immutable/chunks/BFOLKM4z.js +1 -0
- package/web/_app/immutable/chunks/{BPpUSQ2Y.js → BezGs1Zj.js} +1 -1
- package/web/_app/immutable/chunks/Bg-39frG.js +1 -0
- package/web/_app/immutable/chunks/BleKqNM1.js +1 -0
- package/web/_app/immutable/chunks/{e7GRa0yc.js → BpHE30PI.js} +1 -1
- package/web/_app/immutable/chunks/{DAVMwq6b.js → BtF1frCE.js} +1 -1
- package/web/_app/immutable/chunks/{0B47b24t.js → BuNfZSU6.js} +1 -1
- package/web/_app/immutable/chunks/{BAVnZFPa.js → BubCsN15.js} +1 -1
- package/web/_app/immutable/chunks/{CcE14TDI.js → BvhVny3O.js} +1 -1
- package/web/_app/immutable/chunks/{C9Qdslk3.js → Bvs-JCN-.js} +1 -1
- package/web/_app/immutable/chunks/{DFo4P1vU.js → C-F98t31.js} +1 -1
- package/web/_app/immutable/chunks/{Cpjqsnqr.js → C1OaBy7n.js} +1 -1
- package/web/_app/immutable/chunks/{C8FxuPry.js → C4SqDe8e.js} +1 -1
- package/web/_app/immutable/chunks/{D9uNsgxP.js → C74H8jNb.js} +1 -1
- package/web/_app/immutable/chunks/{CUNetmvQ.js → C7bouMY8.js} +1 -1
- package/web/_app/immutable/chunks/{BiHyHFlW.js → C8IrXs1w.js} +1 -1
- package/web/_app/immutable/chunks/{MrW4zd8l.js → CGGjDDVZ.js} +1 -1
- package/web/_app/immutable/chunks/{Wv-ICQRy.js → CL9QeiGC.js} +85 -85
- package/web/_app/immutable/chunks/{BLzZIf7l.js → CMAnq3x6.js} +1 -1
- package/web/_app/immutable/chunks/{OG9GsKke.js → CMe14KUo.js} +1 -1
- package/web/_app/immutable/chunks/{DW5uy3Jw.js → CXc9Iibq.js} +1 -1
- package/web/_app/immutable/chunks/Cb-KPahQ.js +1 -0
- package/web/_app/immutable/chunks/{DWwu8a1P.js → Cf13Ew0A.js} +1 -1
- package/web/_app/immutable/chunks/CkSjC-iE.js +9 -0
- package/web/_app/immutable/chunks/{DY0M2GMn.js → Cn8Mg7_E.js} +1 -1
- package/web/_app/immutable/chunks/{f7mFVWQS.js → CoeYsgbS.js} +1 -1
- package/web/_app/immutable/chunks/{CZSmkKvQ.js → CrqOdm1D.js} +1 -1
- package/web/_app/immutable/chunks/{CVqwkR8N.js → CyJXJYoE.js} +1 -1
- package/web/_app/immutable/chunks/{AnnzTlE8.js → Cz6kYWmu.js} +1 -1
- package/web/_app/immutable/chunks/{ZTEErEOd.js → CzbFy3_5.js} +1 -1
- package/web/_app/immutable/chunks/{Ih6r6QR2.js → D-9suc4b.js} +1 -1
- package/web/_app/immutable/chunks/{BZX8cNYL.js → D37hxBaz.js} +1 -1
- package/web/_app/immutable/chunks/D7yT4F_8.js +517 -0
- package/web/_app/immutable/chunks/{DxRGLDbV.js → DNs5kWvM.js} +1 -1
- package/web/_app/immutable/chunks/DQp-M3XN.js +1 -0
- package/web/_app/immutable/chunks/{D7jLdCNu.js → DR5d84Z7.js} +1 -1
- package/web/_app/immutable/chunks/{DH_19--P.js → DaEL1AOW.js} +1 -1
- package/web/_app/immutable/chunks/{CSKABQj2.js → Dazeexma.js} +1 -1
- package/web/_app/immutable/chunks/{mhWk5y4o.js → Dc2_04md.js} +1 -1
- package/web/_app/immutable/chunks/{1j--pDqt.js → Dcjgv4h2.js} +1 -1
- package/web/_app/immutable/chunks/{CSTv2fL0.js → DgI3Vj5v.js} +1 -1
- package/web/_app/immutable/chunks/{B7LnLClC.js → Dgko1xMH.js} +1 -1
- package/web/_app/immutable/chunks/{DEQsS4Ez.js → DlgOmQ_G.js} +1 -1
- package/web/_app/immutable/chunks/{BLe29cGh.js → DmS5Qyvl.js} +1 -1
- package/web/_app/immutable/chunks/{CglDFp51.js → DqnDX3G8.js} +1 -1
- package/web/_app/immutable/chunks/{CTuuQ66F.js → DyZdoKBK.js} +1 -1
- package/web/_app/immutable/chunks/{CUB9vnd0.js → DzAOHjhV.js} +1 -1
- package/web/_app/immutable/chunks/{DJT73ARj.js → Iqegk1SI.js} +1 -1
- package/web/_app/immutable/chunks/{Mwr1r9aw.js → ONqdwA3r.js} +1 -1
- package/web/_app/immutable/chunks/{Bytzbt5l.js → Oikibjm2.js} +1 -1
- package/web/_app/immutable/chunks/{C1FDDux-.js → T3u7Skc8.js} +1 -1
- package/web/_app/immutable/chunks/{Ch5Z7cbP.js → cWWhqL1F.js} +1 -1
- package/web/_app/immutable/chunks/{CwHHpacD.js → fRXyV4Ec.js} +1 -1
- package/web/_app/immutable/chunks/{CWc-mNzo.js → jAC4YCqW.js} +1 -1
- package/web/_app/immutable/chunks/{hjSZ041d.js → kFEqmLql.js} +1 -1
- package/web/_app/immutable/chunks/{BtYMl4bD.js → y0C1JQ1v.js} +1 -1
- package/web/_app/immutable/chunks/{DJQ6favH.js → yvD4_bP8.js} +1 -1
- package/web/_app/immutable/entry/app.CyEmP0i2.js +2 -0
- package/web/_app/immutable/entry/start.BxCHvKWL.js +1 -0
- package/web/_app/immutable/nodes/0.Bkbiw_sA.js +11 -0
- package/web/_app/immutable/nodes/1.kdx6h8ts.js +1 -0
- package/web/_app/immutable/nodes/2.CtK7BGB8.js +1 -0
- package/web/_app/immutable/nodes/3.D5PZa2kH.js +1 -0
- package/web/_app/immutable/nodes/4.DzS8oPUH.js +3 -0
- package/web/_app/immutable/nodes/5.B-1BDKsL.js +19 -0
- package/web/_app/immutable/nodes/6.DDT1DtCg.js +1 -0
- package/web/_app/immutable/nodes/7.CCNCaItj.js +1 -0
- package/web/_app/immutable/workers/worker-C_nKscAW.js +1 -0
- package/web/_app/version.json +1 -1
- package/web/fonts/LythMono-LICENSE.md +112 -0
- package/web/fonts/lyth-mono-latin-bold.woff2 +0 -0
- package/web/fonts/lyth-mono-latin-bolditalic.woff2 +0 -0
- package/web/fonts/lyth-mono-latin-italic.woff2 +0 -0
- package/web/fonts/lyth-mono-latin-regular.woff2 +0 -0
- package/web/index.html +19 -17
- package/web/_app/immutable/assets/0.BEFtmzIh.css +0 -1
- package/web/_app/immutable/assets/4.LR47AJKA.css +0 -1
- package/web/_app/immutable/assets/NoteList.C2GYAaLW.css +0 -1
- package/web/_app/immutable/chunks/BHORylQC.js +0 -1
- package/web/_app/immutable/chunks/BMijTvgG.js +0 -1
- package/web/_app/immutable/chunks/C7qBBO-i.js +0 -1
- package/web/_app/immutable/chunks/CA-rzUq8.js +0 -524
- package/web/_app/immutable/chunks/DtEVmiYo.js +0 -1
- package/web/_app/immutable/chunks/Qej0SEux.js +0 -1
- package/web/_app/immutable/chunks/TmxIGCN3.js +0 -1
- package/web/_app/immutable/entry/app.B9TPZNFw.js +0 -2
- package/web/_app/immutable/entry/start.WU9HKeyT.js +0 -1
- package/web/_app/immutable/nodes/0.C9NFEqJd.js +0 -3
- package/web/_app/immutable/nodes/1.B5PJwWOG.js +0 -1
- package/web/_app/immutable/nodes/2.DRtC7zjs.js +0 -1
- package/web/_app/immutable/nodes/3.EEMisvUL.js +0 -1
- package/web/_app/immutable/nodes/4.DthmsFQC.js +0 -19
- package/web/_app/immutable/nodes/5.CEu0DlpQ.js +0 -1
- package/web/_app/immutable/nodes/6.DzvF0ZPt.js +0 -1
- package/web/_app/immutable/workers/worker-CWkpeSVG.js +0 -1
- /package/web/_app/immutable/assets/{6.C00vyVPo.css → 7.C00vyVPo.css} +0 -0
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import{$ as e,A as t,D as n,E as r,F as i,K as a,L as o,M as s,N as c,O as l,P as u,Q as d,R as f,T as p,U as m,V as h,W as g,X as _,Z as v,_ as y,a as b,b as x,ct as S,d as C,et as w,f as T,ft as E,ht as D,i as O,it as k,j as A,k as j,l as M,lt as N,mt as P,n as F,nt as I,ot as ee,p as te,pt as L,q as R,rt as z,tt as ne,u as B,v as V,w as H,z as re}from"../chunks/AnnzTlE8.js";import{o as ie,s as ae,t as oe}from"../chunks/BMijTvgG.js";import"../chunks/xihTtKlq.js";import{A as U,D as se,E as W,F as ce,M as le,N as ue,O as de,S as fe,T as pe,_ as me,a as G,b as he,c as ge,f as _e,g as ve,h as ye,i as be,j as xe,k as Se,l as Ce,m as we,o as Te,s as Ee,v as De,w as Oe,x as ke,y as Ae}from"../chunks/Wv-ICQRy.js";import{D as je,E as Me,O as Ne,S as Pe,T as Fe,_ as Ie,a as Le,b as Re,c as ze,d as Be,f as Ve,g as He,i as Ue,l as We,m as Ge,n as Ke,o as qe,p as Je,r as Ye,s as Xe,t as Ze,v as Qe,w as $e,x as et,y as tt}from"../chunks/CA-rzUq8.js";import{t as nt}from"../chunks/CTuuQ66F.js";import{B as rt,D as K,E as it,F as q,G as at,H as ot,I as st,J,K as ct,L as lt,M as Y,N as X,P as ut,R as dt,S as ft,W as pt,X as mt,Y as ht,at as gt,ct as _t,et as vt,it as yt,lt as bt,mt as xt,n as St,nt as Ct,rt as wt,t as Tt,ut as Et,v as Dt,w as Ot,x as kt,y as At}from"../chunks/BxTFtVqu.js";import{i as jt,l as Mt,n as Nt,o as Pt,r as Ft}from"../chunks/yxd8jSz3.js";import{t as It}from"../chunks/TmxIGCN3.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(ie(`/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=u(`<p class="problem svelte-klp1mb" role="alert"> </p>`),hn=u(`<!> <iframe sandbox="allow-scripts" class="svelte-klp1mb"></iframe>`,1);function gn(n,r){N(r,!0);let i=O(r,`look`,3,`isorite`),o=z(void 0),c=z(480),u=z(``),f=z(ne(fn()));R(()=>{let e=new MutationObserver(()=>{I(f,fn(),!0)});e.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-ground`]});let t=matchMedia(`(prefers-color-scheme: light)`),n=()=>{I(f,fn(),!0)};return t.addEventListener(`change`,n),()=>{e.disconnect(),t.removeEventListener(`change`,n)}});let p=null;R(()=>h(o)?(p=un(h(o),G.api,r.path,()=>r.uses,{onHeight:e=>{I(c,Math.max(120,Math.min(2e4,Math.ceil(e)+4)),!0)},onError:e=>r.onerror?.(e),onOpen:e=>{be.open(e.replace(/^\/+/,``).replace(/\.md$/,``))},current:()=>({ground:h(f),look:i()})}),()=>{p?.stop(),p=null}):void 0),R(()=>{if(!h(o))return;let e=h(o),t=r.html,n=g(()=>({look:i(),ground:h(f)}));I(u,``),ln(t,n).then(t=>{e.srcdoc=t},e=>{I(u,e.message,!0)})}),R(()=>{p?.tell({type:`ground`,ground:h(f)})}),R(()=>{p?.tell({type:`look`,look:i()})});var m=hn(),_=d(m),v=n=>{var r=mn(),i=e(r,!0);a(()=>t(i,h(u))),s(n,r)};l(_,e=>{h(u)&&e(v)});var b=w(_,2);let x;M(b,e=>I(o,e),()=>h(o)),a(()=>{T(b,`title`,r.title),x=y(b,``,x,{height:`${h(c)??``}px`})}),s(n,m),S()}var _n=u(`<p class="stand svelte-16i7bpz"> </p>`),vn=u(`<span> </span><span class="sep svelte-16i7bpz">/</span>`,1),yn=u(`<a class="br svelte-16i7bpz"> </a>`),bn=u(`<span class="br svelte-16i7bpz"> </span>`),xn=u(`<span class="uses">uses <!></span>`),Sn=u(`<span class="faint"> </span>`),Cn=u(`<button type="button" role="radio" class="svelte-16i7bpz"> </button>`),wn=u(`<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=u(`<p class="said svelte-16i7bpz" role="status"> </p>`),En=u(`<li> </li>`),Dn=u(`<ul class="errors svelte-16i7bpz" role="alert"></ul>`),On=u(`<p class="problem svelte-16i7bpz" role="alert"> </p>`),kn=u(`<img class="picture svelte-16i7bpz"/>`),An=u(`<iframe class="pdf svelte-16i7bpz"></iframe>`),jn=u(`<th> </th>`),Mn=u(`<td> </td>`),Nn=u(`<tr></tr>`),Pn=u(`<p class="faint"> </p>`),Fn=u(`<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=u(`<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(n,i){N(i,!0);let o=k(()=>W(i.path)??`misc`),u=k(()=>i.path.split(`/`).at(-1)??i.path),m=k(()=>i.path.split(`/`).slice(0,-1)),g=/\.(glb|gltf|stl|obj)$/i,_=/\.(csv|tsv|json|jsonl|ndjson)$/i,y=z(``),b=z(null),x=z(null),C=z(null),D=z(ne([])),O=z(`isorite`),A=z(``);R(()=>{let e=i.path,t=h(o);I(y,``),I(b,null),I(x,null),I(C,null),I(D,[],!0),I(A,``);let n;return(async()=>{if(t===`artifact`){let{html:t,manifest:n}=await sn(G.api,e);I(b,{html:t,title:n.title||e.split(`/`).at(-1),description:n.description,uses:n.uses});return}if(g.test(e)){I(b,{html:pn(e.split(`/`).at(-1)),title:e.split(`/`).at(-1),description:``,uses:[e.split(`/`).at(-1)]});return}let r=await G.api.file(e);if(!r)throw Error(`no file at ${e}`);if((t===`image`||r.type===`application/pdf`)&&(n=URL.createObjectURL(new Blob([r.bytes],{type:r.type}))),I(x,{size:r.bytes.length,type:r.type,...n?{url:n}:{}}),t===`data`&&_.test(e)){let t=Zt(e,new TextDecoder().decode(r.bytes));I(C,{shape:$t(e,t),rows:t.slice(0,50)})}})().catch(e=>{I(y,e.message,!0)}),()=>{n&&URL.revokeObjectURL(n)}});let j=k(()=>h(b)?.title??h(u)),M=e=>e<1024?`${e} bytes`:e<1024**2?`${(e/1024).toFixed(1)} kB`:`${(e/1024**2).toFixed(1)} MB`,P=e=>typeof e==`number`?tn(e):String(e??``);async function F(){if(h(b))try{let e=await ln(h(b).html,{look:h(O),ground:fn(),data:await cn(G.api,i.path,h(b).uses)}),t=document.createElement(`a`);t.href=URL.createObjectURL(new Blob([e],{type:`text/html`})),t.download=h(u).replace(/\.html?$/i,``)+`.standalone.html`,t.click(),setTimeout(()=>URL.revokeObjectURL(t.href),1e3),I(A,`saved ${t.download}, ${M(e.length)}`)}catch(e){I(y,e.message,!0)}}let ee=e=>{let t=on(i.path,e);return t===null?null:Ee(t)};var te=In(),B=v(te),H=v(B),re=e(H,!0),ie=w(H,2),ae=n=>{var r=_n(),i=e(r,!0);a(()=>t(i,h(b).description)),s(n,r)};l(ie,e=>{h(b)?.description&&e(ae)});var oe=w(ie,2),U=v(oe),se=v(U);Je(se,{get kind(){return h(o)}});var ce=w(se,1,!0);L(U);var le=w(U,2),ue=v(le);p(ue,16,()=>h(m),e=>e,(n,r)=>{var i=vn(),o=d(i),c=e(o,!0);E(),a(()=>t(c,r)),s(n,i)});var de=w(ue),fe=e(de,!0);L(le);var pe=w(le,2),me=n=>{var r=xn(),i=w(v(r));p(i,16,()=>h(b).uses,e=>e,(n,r)=>{let i=k(()=>ee(r));var o=c(),u=d(o),f=n=>{var o=yn(),c=e(o,!0);a(()=>{T(o,`href`,h(i)),t(c,r)}),s(n,o)},p=n=>{var i=bn(),o=e(i,!0);a(()=>t(o,r)),s(n,i)};l(u,e=>{h(i)?e(f):e(p,-1)}),s(n,o)}),L(r),s(n,r)};l(pe,e=>{h(o)===`artifact`&&h(b)?.uses.length&&e(me)});var he=w(pe,2),ge=n=>{var r=Sn(),i=e(r,!0);a(e=>t(i,e),[()=>M(h(x).size)]),s(n,r)};l(he,e=>{h(x)&&e(ge)});var _e=w(he,2),ve=n=>{var r=wn(),i=v(r);p(i,20,()=>[`isorite`,`plain`],e=>e,(n,r)=>{var i=Cn(),o=e(i,!0);a(()=>{T(i,`aria-checked`,h(O)===r),t(o,r)}),f(`click`,i,()=>I(O,r,!0)),s(n,i)}),L(i);var o=w(i,2);L(r),f(`click`,o,()=>void F()),s(n,r)};l(_e,e=>{h(o)===`artifact`&&e(ve)}),L(oe);var ye=w(oe,2),be=n=>{var r=Tn(),i=e(r,!0);a(()=>t(i,h(A))),s(n,r)};l(ye,e=>{h(A)&&e(be)});var xe=w(ye,2),Se=n=>{var r=Dn();p(r,20,()=>h(D),e=>e,(n,r)=>{var i=En(),o=e(i,!0);a(()=>t(o,r)),s(n,i)}),L(r),s(n,r)};l(xe,e=>{h(D).length&&e(Se)}),L(B);var Ce=w(B,2),we=n=>{var r=On(),i=e(r,!0);a(()=>t(i,h(y))),s(n,r)};l(Ce,e=>{h(y)&&e(we)});var Te=w(Ce,2),De=e=>{gn(e,{get path(){return i.path},get html(){return h(b).html},get uses(){return h(b).uses},get look(){return h(O)},get title(){return h(j)},onerror:e=>{h(D).includes(e)||I(D,[...h(D),e],!0)}})},Oe=e=>{var t=kn();a(()=>{T(t,`src`,h(x).url),T(t,`alt`,h(u))}),s(e,t)},ke=e=>{var t=An();a(()=>{T(t,`src`,h(x).url),T(t,`title`,h(u))}),s(e,t)},Ae=n=>{var i=Fn(),o=d(i),c=e(o,!0),u=w(o,2),f=v(u),m=v(f),g=v(m);p(g,21,()=>h(C).shape.columns,e=>e.name,(n,r)=>{var i=jn();let o;var c=e(i,!0);a(()=>{o=V(i,1,`svelte-16i7bpz`,null,o,{n:h(r).type===`number`}),t(c,h(r).name)}),s(n,i)}),L(g),L(m);var _=w(m);p(_,21,()=>h(C).rows,r,(n,r)=>{var i=Nn();p(i,21,()=>h(C).shape.columns,e=>e.name,(n,i)=>{var o=Mn();let c;var l=e(o,!0);a(e=>{c=V(o,1,`svelte-16i7bpz`,null,c,{n:h(i).type===`number`}),t(l,e)},[()=>P(h(r)[h(i).name])]),s(n,o)}),L(i),s(n,i)}),L(_),L(f),L(u);var y=w(u,2),b=n=>{var r=Pn(),i=e(r);a(()=>t(i,`the first ${h(C).rows.length??``} of ${h(C).shape.rows??``} rows`)),s(n,r)};l(y,e=>{h(C).shape.rows>h(C).rows.length&&e(b)}),a(e=>t(c,e),[()=>en({...h(C).shape,head:[]}).split(`
|
|
6
|
-
First rows:`)[0]]),s(n,i)},je=n=>{var r=Pn(),i=e(r,!0);a(()=>t(i,h(x).type)),s(n,r)};l(Te,e=>{h(b)?e(De):h(o)===`image`&&h(x)?.url?e(Oe,1):h(x)?.type===`application/pdf`&&h(x).url?e(ke,2):h(C)?e(Ae,3):h(x)&&e(je,4)}),L(te),a(()=>{t(re,h(j)),t(ce,Ge[h(o)]),t(fe,h(u))}),s(n,te),S()}o([`click`]);var Rn=i(`<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();a(()=>{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`)}),s(e,i)}var Bn=class{note;#e=z([]);get entries(){return h(this.#e)}set entries(e){I(this.#e,e)}#t=z(null);get failed(){return h(this.#t)}set failed(e){I(this.#t,e)}#n=z(null);get cursor(){return h(this.#n)}set cursor(e){I(this.#n,e)}#r=z(``);get busy(){return h(this.#r)}set busy(e){I(this.#r,e,!0)}#i=z(null);get editing(){return h(this.#i)}set editing(e){I(this.#i,e,!0)}stop=null;constructor(e){this.note=e}#a=k(()=>De(this.entries));get waiting(){return h(this.#a)}set waiting(e){I(this.#a,e)}#o=k(()=>this.waiting.filter(e=>e.form===`insert`));get proposals(){return h(this.#o)}set proposals(e){I(this.#o,e)}#s=k(()=>{let e=[],t=fe(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=we(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 h(this.#s)}set changes(e){I(this.#s,e)}#c=k(()=>{try{let e=pe(this.note.text)[0];return{lines:e.split(`
|
|
8
|
-
`).length-1,chars:e.length}}catch{return{lines:0,chars:0}}});get head(){return h(this.#c)}set head(e){I(this.#c,e)}get foot(){return this.note.text.split(`
|
|
9
|
-
`).length}placed(e){return ve(this.note.text,e)!==null}#l=k(()=>{let e=[];for(let t of this.proposals){let n=ve(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 h(this.#l)}set layout(e){I(this.#l,e)}async open(){this.stop=G.on(e=>this.hear(e));try{this.entries=await G.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 G.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 G.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 G.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 G.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 G.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 G.api.keep(this.note.id,t.proposal.id,t.k)):await G.api.discard(this.note.id,t.proposal.id,t.k))}catch(e){this.say(void 0,e)}finally{this.busy=``}}},Vn=1500,Hn=e=>_e(`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=z(`loading`);get loaded(){return h(this.#e)}set loaded(e){I(this.#e,e,!0)}#t=z(`saved`);get saving(){return h(this.#t)}set saving(e){I(this.#t,e,!0)}#n=z(``);get message(){return h(this.#n)}set message(e){I(this.#n,e,!0)}#r=z(``);get text(){return h(this.#r)}set text(e){I(this.#r,e,!0)}#i=z(void 0);get theirs(){return h(this.#i)}set theirs(e){I(this.#i,e)}#a=z(0);get revision(){return h(this.#a)}set revision(e){I(this.#a,e,!0)}base=``;saved=``;timer=null;inFlight=null;stop=null;constructor(e){this.id=e}#o=k(()=>{try{return ce(this.text)[0]??{}}catch{return null}});get meta(){return h(this.#o)}set meta(e){I(this.#o,e)}#s=k(()=>{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 h(this.#s)}set fields(e){I(this.#s,e)}#c=k(()=>{try{return pe(this.text)[2]}catch{return this.text}});get body(){return h(this.#c)}set body(e){I(this.#c,e)}async open(){try{let e=await G.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=G.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 G.api.restore(this.id,e,this.base))}async move(e){await this.settle();let t=await G.api.moveNote(this.id,e,this.base);return this.stop?.(),t.id}async setDone(e){await this.settle(),this.take(await G.api.setDone(this.id,e,this.base)),await G.refresh()}async remove(){await this.settle(),await G.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 G.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!==ye(this.text)&&this.saving===`saved`&&G.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?G.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=u(`<button type="button" role="radio" data-lustre=""><!> </button>`),qn=u(`<span class="field svelte-ml08v2"><!></span>`),Jn=u(`<button type="button" class="seg svelte-ml08v2"> </button>`),Yn=u(`<input class="name svelte-ml08v2" spellcheck="false" autocomplete="off" aria-label="name"/>`),Xn=u(`<button type="button" class="seg name svelte-ml08v2"> </button>`),Zn=u(`<span class="path svelte-ml08v2"><!> <span class="sep svelte-ml08v2">/</span> <!></span>`),Qn=u(`<button type="button" class="br svelte-ml08v2"> </button>`),$n=u(`<input class="adding svelte-ml08v2" size="10" aria-label="new tag"/>`),er=u(`<button type="button" class="add svelte-ml08v2" aria-label="add a tag">+</button>`),tr=u(`<button type="button" class="x svelte-ml08v2">×</button>`),nr=u(`<a class="br svelte-ml08v2"> </a><!>`,1),rr=u(`<option> </option>`),ir=u(`<input class="adding svelte-ml08v2" list="label-notes" size="18"/> <datalist id="label-notes"></datalist>`,1),ar=u(`<button type="button" class="add svelte-ml08v2">+</button>`),or=u(`<div><span class="word svelte-ml08v2"> </span> <!> <!> <span class="grow svelte-ml08v2"></span> <button type="button"> </button></div>`),sr=u(`<p class="problem svelte-ml08v2" role="alert"> </p>`),cr=u(`<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(n,r){N(r,!0);let i=k(()=>!r.note.id.startsWith(`@`)),o=z(``),c=[[`note`,`concept`,`Concept`],[`question`,`question`,`Question`],[`problem`,`problem`,`Problem`]];function u(e,t,n){e!==r.kind&&(r.note.setFields({type:t}),m().then(()=>$e(n,!0)))}let g=e=>e.split(`/`).slice(0,-1).join(`/`),_=e=>e.split(`/`).at(-1),y=z(null),b=z(``);async function E(e,t){let n=e=>e.trim().replace(/^\/+|\/+$/g,``).replace(/\.md$/,``),i=[n(e),n(t)].filter(Boolean).join(`/`);if(I(y,null),n(t)&&i!==r.note.id){I(o,``);try{let e=await r.note.move(i);await G.refresh(),await oe(Ee(e),{replaceState:!0})}catch(e){I(o,e.message,!0)}}}let O=e=>{let t=e instanceof HTMLInputElement?e:e.querySelector(`input`);t?.focus(),t?.select()},A=k(()=>r.note.fields.tags.split(`,`).map(e=>e.trim()).filter(Boolean)),j=z(!1);function M(e){let t=e.trim();I(j,!1),t&&!h(A).includes(t)&&r.note.setMeta({tags:[...h(A),t]})}let P=e=>r.note.setMeta({tags:h(A).filter(t=>t!==e).length?h(A).filter(t=>t!==e):null}),F=k(()=>r.kind===`note`?null:se[r.kind]),R=k(()=>h(F)?xe(r.note.meta?.[h(F)]):[]),ne=k(()=>h(F)?[...new Set([...h(R),...G.listing.notes.find(e=>e.id===r.note.id)?.attached??[]])]:[]),B=e=>G.listing.notes.find(t=>t.id===e)?.title??_(e),H=z(!1);function ie(e){I(H,!1);let t=e.trim().replace(/^\/+/,``).replace(/\.md$/,``),n=G.listing.notes.find(e=>e.id===t||e.title.toLowerCase()===t.toLowerCase());h(F)&&n&&!h(R).includes(n.id)&&n.id!==r.note.id&&r.note.setMeta({[h(F)]:[...h(R),n.id]})}let ae=e=>{h(F)&&r.note.setMeta({[h(F)]:h(R).filter(t=>t!==e).length?h(R).filter(t=>t!==e):null})};var U=cr(),W=d(U);ee(W);let ce;var le=w(W,2),ue=v(le);p(ue,21,()=>c,([e,t,n])=>e,(e,n)=>{var i=k(()=>D(h(n),3));let o=()=>h(i)[0],c=()=>h(i)[1],l=()=>h(i)[2];var d=Kn(),p=v(d);{let e=k(()=>o()===`note`?`concept`:o());Je(p,{get kind(){return h(e)}})}var m=w(p,1,!0);L(d),a(()=>{V(d,1,`slot ${o()??``}`,`svelte-ml08v2`),T(d,`aria-checked`,r.kind===o()),t(m,c())}),f(`click`,d,e=>u(o(),l(),e.currentTarget)),s(e,d)}),L(ue);var de=w(ue,2),fe=n=>{var i=Zn(),o=v(i),c=e=>{var t=qn(),n=v(t);It(n,{id:`note-folder`,quiet:!0,label:`folder`,placeholder:`the top of the base`,onpick:e=>void E(e,_(r.note.id)),onkeydown:e=>{e.key===`Escape`&&I(y,null)},get value(){return h(b)},set value(e){I(b,e,!0)}}),L(t),x(t,e=>O?.(e)),s(e,t)},u=n=>{var i=Jn(),o=e(i,!0);a((e,n)=>{T(i,`aria-label`,e),t(o,n)},[()=>g(r.note.id)?void 0:`the top of the base`,()=>g(r.note.id).replaceAll(`/`,` / `)||`·`]),f(`click`,i,()=>{I(b,g(r.note.id),!0),I(y,`folder`)}),s(n,i)};l(o,e=>{h(y)===`folder`?e(c):e(u,-1)});var d=w(o,4),p=e=>{var t=Yn();C(t),x(t,e=>O?.(e)),a((e,n)=>{te(t,e),T(t,`size`,n)},[()=>_(r.note.id),()=>Math.max(8,_(r.note.id).length)]),re(`blur`,t,e=>void E(g(r.note.id),e.currentTarget.value)),f(`keydown`,t,e=>{e.key===`Enter`?e.currentTarget.blur():e.key===`Escape`&&I(y,null)}),s(e,t)},m=n=>{var i=Xn(),o=e(i,!0);a(e=>t(o,e),[()=>_(r.note.id)]),f(`click`,i,()=>I(y,`name`)),s(n,i)};l(d,e=>{h(y)===`name`?e(p):e(m,-1)}),L(i),s(n,i)};l(de,e=>{h(i)&&e(fe)});var pe=w(de,2),me=v(pe);p(me,16,()=>h(A),e=>e,(n,r)=>{var i=Qn(),o=e(i,!0);a(()=>{T(i,`aria-label`,`tag ${r??``}: remove`),t(o,r)}),f(`click`,i,()=>P(r)),s(n,i)});var he=w(me,2),ge=e=>{var t=$n();x(t,e=>O?.(e)),re(`blur`,t,e=>M(e.currentTarget.value)),f(`keydown`,t,e=>{e.key===`Enter`?e.currentTarget.blur():e.key===`Escape`&&I(j,!1)}),s(e,t)},_e=e=>{var t=er();f(`click`,t,()=>I(j,!0)),s(e,t)};l(he,e=>{h(j)?e(ge):e(_e,-1)}),L(pe),L(le);var ve=w(le,2),ye=n=>{var i=or(),o=v(i),c=e(o,!0),u=w(o,2);p(u,16,()=>h(ne),e=>e,(n,r)=>{var i=nr(),o=d(i),c=e(o,!0),u=w(o),p=e=>{var t=tr();a(e=>T(t,`aria-label`,`${e??``}: take away`),[()=>B(r)]),f(`click`,t,()=>ae(r)),s(e,t)},m=k(()=>h(R).includes(r));l(u,e=>{h(m)&&e(p)}),a((e,n)=>{T(o,`href`,e),t(c,n)},[()=>Ee(r),()=>B(r)]),s(n,i)});var m=w(u,2),g=n=>{var i=ir(),o=d(i);x(o,e=>O?.(e));var c=w(o,2);p(c,21,()=>G.listing.notes.filter(e=>e.id!==r.note.id&&!e.id.startsWith(`@`)),e=>e.id,(n,r)=>{var i=rr(),o=e(i,!0),c={};a(()=>{t(o,h(r).title),c!==(c=h(r).id)&&(i.value=(i.__value=c)??``)}),s(n,i)}),L(c),a(()=>T(o,`aria-label`,`a note it's ${h(F)===`about`?`about`:`using`}`)),re(`blur`,o,e=>ie(e.currentTarget.value)),f(`keydown`,o,e=>{e.key===`Enter`?e.currentTarget.blur():e.key===`Escape`&&I(H,!1)}),s(n,i)},_=e=>{var t=ar();a(()=>T(t,`aria-label`,`add a note it's ${h(F)===`about`?`about`:`using`}`)),f(`click`,t,()=>I(H,!0)),s(e,t)};l(m,e=>{h(H)?e(g):e(_,-1)});var y=w(m,4);let b;var S=e(y,!0);L(i),a(()=>{V(i,1,`extra ${r.kind??``}`,`svelte-ml08v2`),t(c,h(F)),b=V(y,1,`mark svelte-ml08v2`,null,b,{done:!!r.done}),T(y,`aria-pressed`,!!r.done),y.disabled=r.marking,T(y,`title`,r.done?`since ${r.done}`:void 0),t(S,r.kind===`question`?r.done?`◆ resolved`:`◇ open`:r.done?`◆ solved`:`◇ unsolved`)}),f(`click`,y,function(...e){r.onmark?.apply(this,e)}),s(n,i)};l(ve,e=>{h(F)&&e(ye)});var be=w(ve,2),Se=n=>{var r=sr(),i=e(r,!0);a(()=>t(i,h(o))),s(n,r)};l(be,e=>{h(o)&&e(Se)}),a(()=>{ce=V(W,1,`stand serif svelte-ml08v2`,null,ce,{empty:!r.note.fields.description}),te(W,r.note.fields.description)}),f(`input`,W,e=>r.note.setFields({description:e.currentTarget.value.replace(/\s*\n\s*/g,` `)})),f(`keydown`,W,e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())}),s(n,U),S()}o([`input`,`keydown`,`click`]);var ur=u(`<span class="sym svelte-wdtkre"> </span>`),dr=u(`<span class="lines svelte-wdtkre"> </span>`),fr=u(`<span class="why svelte-wdtkre"> </span>`),pr=u(`<span class="ln svelte-wdtkre"></span>`),mr=u(`<span class="pre svelte-wdtkre"></span> <!> <!>`,1),hr=u(`<span data-code-embed=""><span class="head svelte-wdtkre"><span class="file svelte-wdtkre"> </span> <!> <!></span> <!></span>`);function gr(n,i){N(i,!0);let o=z(null),c=z(null),u=z(``);async function f(){try{let e=await G.api.code(i.href);I(o,e),I(c,e.state===`ok`?await qe(e.text,e.path):null,!0),I(u,``)}catch(e){I(u,e.message,!0)}}R(()=>{i.href,f();let e=()=>{document.visibilityState===`visible`&&f()};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)});let m={"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`},g=k(()=>h(o)?.state===`ok`?h(o).start===h(o).end?`line ${h(o).start}`:`lines ${h(o).start}–${h(o).end}`:``);var _=hr();let b;var x=v(_),C=v(x),E=e(C,!0),D=w(C,2),O=n=>{var r=ur(),i=e(r,!0);a(()=>t(i,h(o).symbol)),s(n,r)};l(D,e=>{h(o)?.symbol&&e(O)});var A=w(D,2),j=n=>{var r=dr(),i=e(r,!0);a(()=>t(i,h(g))),s(n,r)};l(A,e=>{h(g)&&e(j)}),L(x);var M=w(x,2),P=n=>{var r=fr(),i=e(r,!0);a(()=>t(i,h(u))),s(n,r)},F=n=>{var r=fr(),i=e(r,!0);a(()=>t(i,m[h(o).state])),s(n,r)},ee=n=>{var i=mr(),u=d(i);let f;p(u,21,()=>h(o).text.split(`
|
|
11
|
-
`),r,(e,t,n)=>{var r=pr();H(r,()=>(h(c)?.split(`
|
|
12
|
-
`)[n]??h(t).replace(/&/g,`&`).replace(/</g,`<`))||` `,!0),L(r),a(()=>T(r,`data-n`,h(o).start+n)),s(e,r)}),L(u);var m=w(u,2),g=n=>{var r=fr(),i=e(r);a(()=>t(i,`… ${h(o).end-h(o).start+1-120} more lines in the file`)),s(n,r)};l(m,e=>{h(o).more&&e(g)});var _=w(m,2),v=n=>{var r=fr(),i=e(r);a(()=>t(i,`${h(o).count??``} declarations of this name: the first is shown`)),s(n,r)};l(_,e=>{h(o).count&&e(v)}),a(()=>f=y(u,``,f,{"--from":h(o).start})),s(n,i)};l(M,e=>{h(u)?e(P):h(o)&&h(o).state!==`ok`?e(F,1):h(o)?.state===`ok`&&e(ee,2)}),L(_),a(e=>{b=V(_,1,`code svelte-wdtkre`,null,b,{broken:h(o)&&h(o).state!==`ok`}),t(E,e)},[()=>h(o)?.path??i.href.slice(5).split(`#`)[0]]),s(n,_),S()}var _r=u(`<span class="problem svelte-zlq7nn"> </span>`),vr=u(`<span class="embed svelte-zlq7nn"><a class="name svelte-zlq7nn"><!> </a> <!> <!></span>`);function yr(n,r){N(r,!0);let i=z(null),o=z(``),c=z(ne([]));R(()=>{let e=r.path;sn(G.api,e).then(e=>{I(i,e)},e=>{I(o,e.message,!0)})});var u=vr(),d=v(u),f=v(d);Je(f,{kind:`artifact`,size:11});var m=w(f,1,!0);L(d);var g=w(d,2),_=n=>{var r=_r(),i=e(r,!0);a(()=>t(i,h(o))),s(n,r)},y=e=>{{let t=k(()=>h(i).manifest.title||r.path);gn(e,{get path(){return r.path},get html(){return h(i).html},get uses(){return h(i).manifest.uses},get title(){return h(t)},onerror:e=>{h(c).includes(e)||I(c,[...h(c),e],!0)}})}};l(g,e=>{h(o)?e(_):h(i)&&e(y,1)});var b=w(g,2);p(b,16,()=>h(c),e=>e,(n,r)=>{var i=_r(),o=e(i,!0);a(()=>t(o,r)),s(n,i)}),L(u),a((e,n)=>{T(d,`href`,e),t(m,n)},[()=>Ee(r.path),()=>h(i)?.manifest.title||r.path.split(`/`).at(-1)]),s(n,u),S()}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=pt.define(),Mr=pt.define(),Nr=mt.define(),Pr=mt.define({combine(e){return _t(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=wt.define({create(){return $r.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):Jr(o,t.startState.selection),new $r(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(gt.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=Hr.fromTransaction(t),o=t.annotation(gt.time),s=t.annotation(gt.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 $r(e.done.map(Hr.fromJSON),e.undone.map(Hr.fromJSON))}});function Ir(e={}){return[Fr,Pr.of(e),q.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&&ct.fromJSON(t.changes),[],t.mapped&&at.fromJSON(t.mapped),t.startSelection&&J.fromJSON(t.startSelection),t.selectionsAfter.map(J.fromJSON))}static fromTransaction(t,n){let r=Z;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,Z)}static selection(t){return new e(void 0,Z,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 Z=[],qr=200;function Jr(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-qr));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 Yr(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 Xr(e,t){if(!e.length)return e;let n=e.length,r=Z;for(;n;){let i=Zr(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)]:Z}function Zr(e,t,n){let r=Kr(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):Z,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,Ct.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}var Qr=/^(input\.type|delete)($|\.)/,$r=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||Qr.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(Ct.mapEffects(t.effects,s.changes),s.effects),s.mapped,s.startSelection,Z)):Ur(o,o.length,i.minDepth,t),new e(o,Z,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:Z;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&Gr(a[a.length-1],t)?this:new e(Jr(this.done,t),this.undone,n,r)}addMapping(t){return new e(Xr(this.done,t),Xr(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:Yr(r),selection:a}),userEvent:e==0?`select.undo`:`select.redo`,scrollIntoView:!0});if(i.changes){let n=r.length==1?Z:r.slice(0,r.length-1);return i.mapped&&(n=Xr(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}};$r.empty=new $r(Z,Z);var ei=[{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 ti(e,t){return J.create(e.ranges.map(t),e.mainIndex)}function ni(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:`select`})}function ri({state:e,dispatch:t},n){let r=ti(e.selection,n);return!r.eq(e.selection,!0)&&(t(ni(e,r)),!0)}function ii(e,t){return J.cursor(t?e.to:e.from)}function ai(e,t){return ri(e,n=>n.empty?e.moveByChar(n,t):ii(n,t))}function Q(e){return e.textDirectionAt(e.state.selection.main.head)==ut.LTR}var oi=e=>ai(e,!Q(e)),si=e=>ai(e,Q(e));function ci(e,t){return ri(e,n=>n.empty?e.moveByGroup(n,t):ii(n,t))}var li=e=>ci(e,!Q(e)),ui=e=>ci(e,Q(e));typeof Intl<`u`&&Intl.Segmenter;function di(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 fi(e,t,n){let r=K(e).resolveInner(t.head),i=n?xt.closedBy:xt.openedBy;for(let a=t.head;;){let t=n?r.childAfter(a):r.childBefore(a);if(!t)break;di(e,t,i)?r=t:a=n?t.to:t.from}let a=r.type.prop(i),o,s;return s=a&&(o=n?Ot(e,r.from,1):Ot(e,r.to,-1))&&o.matched?n?o.end.to:o.end.from:n?r.to:r.from,J.cursor(s,n?-1:1)}var pi=e=>ri(e,t=>fi(e.state,t,!Q(e))),mi=e=>ri(e,t=>fi(e.state,t,Q(e)));function hi(e,t){return ri(e,n=>{if(!n.empty)return ii(n,t);let r=e.moveVertically(n,t);return r.head==n.head?e.moveToLineBoundary(n,t):r})}var gi=e=>hi(e,!1),_i=e=>hi(e,!0);function vi(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,i;if(t){for(let t of e.state.facet(q.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 yi(e,t){let n=vi(e),{state:r}=e,i=ti(r.selection,r=>r.empty?e.moveVertically(r,t,n.height):ii(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=q.scrollIntoView(i.main.head,{y:`start`,yMargin:t.top-s}))}return e.dispatch(ni(r,i),{effects:a}),!0}var bi=e=>yi(e,!1),xi=e=>yi(e,!0);function Si(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=J.cursor(r.from+n))}return i}var Ci=e=>ri(e,t=>Si(e,t,!0)),wi=e=>ri(e,t=>Si(e,t,!1)),Ti=e=>ri(e,t=>Si(e,t,!Q(e))),Ei=e=>ri(e,t=>Si(e,t,Q(e))),Di=e=>ri(e,t=>e.moveToLineBoundary(t,!1,!1)),Oi=e=>ri(e,t=>e.moveToLineBoundary(t,!0,!1));function ki(e,t,n){let r=!1,i=ti(e.selection,t=>{let i=Ot(e,t.head,-1)||Ot(e,t.head,1)||t.head>0&&Ot(e,t.head-1,1)||t.head<e.doc.length&&Ot(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?J.range(t.anchor,a):J.cursor(a)});return r?(t(ni(e,i)),!0):!1}var Ai=({state:e,dispatch:t})=>ki(e,t,!1);function $(e,t,n){let r=ti(e.state.selection,e=>{e.undirectional&&e.head>=e.anchor!=t&&(e=J.range(e.head,e.anchor));let r=n(e);return J.range(e.anchor,r.head,r.goalColumn,r.bidiLevel||void 0,r.assoc)});return!r.eq(e.state.selection)&&(e.dispatch(ni(e.state,r)),!0)}function ji(e,t){return $(e,t,n=>e.moveByChar(n,t))}var Mi=e=>ji(e,!Q(e)),Ni=e=>ji(e,Q(e));function Pi(e,t){return $(e,t,n=>e.moveByGroup(n,t))}var Fi=e=>Pi(e,!Q(e)),Ii=e=>Pi(e,Q(e)),Li=e=>{let t=!Q(e);return $(e,t,n=>fi(e.state,n,t))},Ri=e=>{let t=Q(e);return $(e,t,n=>fi(e.state,n,t))};function zi(e,t){return $(e,t,n=>e.moveVertically(n,t))}var Bi=e=>zi(e,!1),Vi=e=>zi(e,!0);function Hi(e,t){return $(e,t,n=>e.moveVertically(n,t,vi(e).height))}var Ui=e=>Hi(e,!1),Wi=e=>Hi(e,!0),Gi=e=>$(e,!0,t=>Si(e,t,!0)),Ki=e=>$(e,!1,t=>Si(e,t,!1)),qi=e=>{let t=!Q(e);return $(e,t,n=>Si(e,n,t))},Ji=e=>{let t=Q(e);return $(e,t,n=>Si(e,n,t))},Yi=e=>$(e,!1,t=>J.cursor(e.lineBlockAt(t.head).from)),Xi=e=>$(e,!0,t=>J.cursor(e.lineBlockAt(t.head).to)),Zi=({state:e,dispatch:t})=>(t(ni(e,{anchor:0})),!0),Qi=({state:e,dispatch:t})=>(t(ni(e,{anchor:e.doc.length})),!0),$i=({state:e,dispatch:t})=>(t(ni(e,{anchor:e.selection.main.anchor,head:0})),!0),ea=({state:e,dispatch:t})=>(t(ni(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),ta=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:`select`})),!0),na=({state:e,dispatch:t})=>{let n=xa(e).map(({from:t,to:n})=>J.undirectionalRange(t,Math.min(n+1,e.doc.length)));return t(e.update({selection:J.create(n),userEvent:`select`})),!0},ra=({state:e,dispatch:t})=>{let n=ti(e.selection,t=>{let n=K(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 J.undirectionalRange(n.from,n.to)}return t});return!n.eq(e.selection)&&(t(ni(e,n)),!0)};function ia(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(ni(n,J.create(i,i.length-1))),!0)}var aa=e=>ia(e,!1),oa=e=>ia(e,!0),sa=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=J.create([n.main]):n.main.empty||(r=J.create([J.cursor(n.main.head)])),r?(t(ni(e,r)),!0):!1};function ca(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=la(e,o,!1)):o>i&&(n=`delete.forward`,o=la(e,o,!0)),i=Math.min(i,o),a=Math.max(a,o)}else i=la(e,i,!1),a=la(e,a,!0);return i==a?{range:r}:{changes:{from:i,to:a},range:J.cursor(i,i<r.head?-1:1)}});return!i.changes.empty&&(e.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:n==`delete.selection`?q.announce.of(r.phrase(`Selection deleted`)):void 0})),!0)}function la(e,t,n){if(e instanceof q)for(let r of e.state.facet(q.atomicRanges).map(t=>t(e)))r.between(t,t,(e,r)=>{e<t&&r>t&&(t=n?r:e)});return t}var ua=(e,t,n)=>ca(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=bt(s,a.tabSize)%Dt(a)||Dt(a);for(let t=0;t<e&&s[s.length-1-t]==` `;t++)i--;c=i}else c=Et(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=Et(o.text,c-o.from,!1,!1)+o.from);return c}),da=e=>ua(e,!1,!0),fa=e=>ua(e,!0,!1),pa=(e,t)=>ca(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=Et(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}),ma=e=>pa(e,!1),ha=e=>pa(e,!0),ga=e=>ca(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),_a=e=>ca(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),va=e=>ca(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),ya=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:yt.of([``,``])},range:J.cursor(e.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:`input`})),!0},ba=({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:Et(r.text,n-r.from,!1)+r.from,a=n==r.to?n+1:Et(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:J.cursor(a)}});return!n.changes.empty&&(t(e.update(n,{scrollIntoView:!0,userEvent:`move.character`})),!0)};function xa(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 Sa(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let t of xa(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(J.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(J.range(e.anchor-o,e.head-o))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:J.create(i,e.selection.mainIndex),userEvent:`move.line`})),!0):!1}var Ca=({state:e,dispatch:t})=>Sa(e,t,!1),wa=({state:e,dispatch:t})=>Sa(e,t,!0);function Ta(e,t,n){if(e.readOnly)return!1;let r=[];for(let t of xa(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 Ea=({state:e,dispatch:t})=>Ta(e,t,!1),Da=({state:e,dispatch:t})=>Ta(e,t,!0),Oa=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(xa(t).map(({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n}))),r=ti(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 ka(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=K(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(xt.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 Aa=Ma(!1),ja=Ma(!0);function Ma(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&&ka(t,r);e&&(r=i=(i<=a.to?a:t.doc.lineAt(i)).to);let s=new St(t,{simulateBreak:r,simulateDoubleBreak:!!o}),c=At(s,r);for(c??=bt(/^\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=[``,kt(t,c)];return o&&l.push(kt(t,s.lineIndent(a.from,-1))),{changes:{from:r,to:i,insert:yt.of(l)},range:J.cursor(r+1+l[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:`input`})),!0}}function Na(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:J.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}var Pa=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new St(e,{overrideIndentation:e=>n[e]??-1}),i=Na(e,(t,i,a)=>{let o=At(r,t.from);if(o==null)return;/\S/.test(t.text)||(o=0);let s=/^\s*/.exec(t.text)[0],c=kt(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},Fa=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(Na(e,(t,n)=>{n.push({from:t.from,insert:e.facet(ft)})}),{userEvent:`input.indent`})),!0),Ia=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(Na(e,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let i=bt(r,e.tabSize),a=0,o=kt(e,Math.max(0,i-Dt(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),La=e=>(e.setTabFocusMode(),!0),Ra=[{key:`Ctrl-b`,run:oi,shift:Mi,preventDefault:!0},{key:`Ctrl-f`,run:si,shift:Ni},{key:`Ctrl-p`,run:gi,shift:Bi},{key:`Ctrl-n`,run:_i,shift:Vi},{key:`Ctrl-a`,run:Di,shift:Yi},{key:`Ctrl-e`,run:Oi,shift:Xi},{key:`Ctrl-d`,run:fa},{key:`Ctrl-h`,run:da},{key:`Ctrl-k`,run:ga},{key:`Ctrl-Alt-h`,run:ma},{key:`Ctrl-o`,run:ya},{key:`Ctrl-t`,run:ba},{key:`Ctrl-v`,run:xi}],za=[{key:`ArrowLeft`,run:oi,shift:Mi,preventDefault:!0},{key:`Mod-ArrowLeft`,mac:`Alt-ArrowLeft`,run:li,shift:Fi,preventDefault:!0},{mac:`Cmd-ArrowLeft`,run:Ti,shift:qi,preventDefault:!0},{key:`ArrowRight`,run:si,shift:Ni,preventDefault:!0},{key:`Mod-ArrowRight`,mac:`Alt-ArrowRight`,run:ui,shift:Ii,preventDefault:!0},{mac:`Cmd-ArrowRight`,run:Ei,shift:Ji,preventDefault:!0},{key:`ArrowUp`,run:gi,shift:Bi,preventDefault:!0},{mac:`Cmd-ArrowUp`,run:Zi,shift:$i},{mac:`Ctrl-ArrowUp`,run:bi,shift:Ui},{key:`ArrowDown`,run:_i,shift:Vi,preventDefault:!0},{mac:`Cmd-ArrowDown`,run:Qi,shift:ea},{mac:`Ctrl-ArrowDown`,run:xi,shift:Wi},{key:`PageUp`,run:bi,shift:Ui},{key:`PageDown`,run:xi,shift:Wi},{key:`Home`,run:wi,shift:Ki,preventDefault:!0},{key:`Mod-Home`,run:Zi,shift:$i},{key:`End`,run:Ci,shift:Gi,preventDefault:!0},{key:`Mod-End`,run:Qi,shift:ea},{key:`Enter`,run:Aa,shift:Aa},{key:`Mod-a`,run:ta},{key:`Backspace`,run:da,shift:da,preventDefault:!0},{key:`Delete`,run:fa,preventDefault:!0},{key:`Mod-Backspace`,mac:`Alt-Backspace`,run:ma,preventDefault:!0},{key:`Mod-Delete`,mac:`Alt-Delete`,run:ha,preventDefault:!0},{mac:`Mod-Backspace`,run:_a,preventDefault:!0},{mac:`Mod-Delete`,run:va,preventDefault:!0}].concat(Ra.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),Ba=[{key:`Alt-ArrowLeft`,mac:`Ctrl-ArrowLeft`,run:pi,shift:Li},{key:`Alt-ArrowRight`,mac:`Ctrl-ArrowRight`,run:mi,shift:Ri},{key:`Alt-ArrowUp`,run:Ca},{key:`Shift-Alt-ArrowUp`,run:Ea},{key:`Alt-ArrowDown`,run:wa},{key:`Shift-Alt-ArrowDown`,run:Da},{key:`Mod-Alt-ArrowUp`,run:aa},{key:`Mod-Alt-ArrowDown`,run:oa},{key:`Escape`,run:sa},{key:`Mod-Enter`,run:ja},{key:`Alt-l`,mac:`Ctrl-l`,run:na},{key:`Mod-i`,run:ra,preventDefault:!0},{key:`Mod-[`,run:Ia},{key:`Mod-]`,run:Fa},{key:`Mod-Alt-\\`,run:Pa},{key:`Shift-Mod-k`,run:Oa},{key:`Shift-Mod-\\`,run:Ai},{key:`Mod-/`,run:br},{key:`Alt-A`,mac:`Ctrl-A`,run:Cr},{key:`Ctrl-m`,mac:`Shift-Alt-m`,run:La}].concat(za),Va={key:`Tab`,run:Fa,shift:Ia},Ha=mt.define({combine:e=>e[0]??null}),Ua=/^[ \t]*\[\[!([^\]\n]+)\]\][ \t]*$/,Wa={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"/>`},Ga=`<path d="M3 8.5l3 3 7-7"/>`,Ka=class extends lt{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?Ga:Wa[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(Ha)?.open(t.id):(e.dispatch({selection:{anchor:this.at},scrollIntoView:!0}),e.focus())}),n}ignoreEvent(){return!0}get estimatedHeight(){return 44}},qa=class extends lt{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=Ue(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}},Ja=new WeakMap,Ya=class extends lt{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),Ja.set(t,{mounted:Ke(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=Ja.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=>Ye(e,this.source))),!0)}ignoreEvent(){return!0}get estimatedHeight(){return 160}},Xa=(e,t)=>t!==null&&e.sliceDoc(t.from,t.to).trim().split(/\s/)[0].toLowerCase()===`mermaid`;function Za(e){let t=[],n=e.selection.ranges;K(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`&&Xa(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(X.widget({widget:new Ya(a,r.from,!0),block:!0,side:1}).range(s)):t.push(X.replace({widget:new Ya(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(X.widget({widget:new qa(i,a,r.from,!0),block:!0,side:1}).range(s)):t.push(X.replace({widget:new qa(i,a,r.from,!1),block:!0}).range(o,s)),!1}});let r=e.facet(Ha);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:Ua.exec(o.text);if(!s||n.some(e=>e.to>=o.from&&e.from<=o.to))continue;let c=s[1].trim();t.push(X.replace({widget:new Ka(c,r.find(c),o.from),block:!0}).range(o.from,o.to))}}return X.set(t,!0)}var Qa=wt.define({create:Za,update(e,t){return t.docChanged||t.selection||K(t.startState)!==K(t.state)?Za(t.state):e},provide:e=>q.decorations.from(e)}),$a=q.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 eo(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:J.range(e.from-r,e.to-r)}:{changes:[{from:e.from,insert:t},{from:e.to,insert:t}],range:J.range(e.from+r,e.to+r)}}),{scrollIntoView:!0,userEvent:`input`}),!0}function to(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 no(e){let t=to(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 ro(e){let t=to(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 io(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 Mt(e),!0}function ao(e,t){switch(t){case`bold`:return eo(e,`**`);case`italic`:return eo(e,`*`);case`maths`:return eo(e,`$`);case`heading`:return no(e);case`list`:return ro(e);case`link`:return io(e);case`undo`:return Rr(e);case`redo`:return zr(e)}}var oo=[{key:`Mod-b`,preventDefault:!0,run:e=>ao(e,`bold`)},{key:`Mod-i`,preventDefault:!0,run:e=>ao(e,`italic`)},{key:`Mod-k`,preventDefault:!0,run:e=>ao(e,`link`)},{key:`Mod-Shift-m`,preventDefault:!0,run:e=>ao(e,`maths`)},{key:`Mod-Shift-h`,preventDefault:!0,run:e=>ao(e,`heading`)},{key:`Mod-Shift-8`,preventDefault:!0,run:e=>ao(e,`list`)}],so=[`requires`,`uses`,`see also`];function co(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 lo(e,t){let n=K(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=co(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 uo=e=>e.kind===`note`||e.kind===`artifact`&&!e.embed;function fo(e,t,n){let r=[];return K(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=lo(e,i.from+1);return a&&a.from===i.from&&uo(a)&&r.push(a),!1}}),r}var po=(e,t)=>e.filter(e=>ho(e)!==t).map(e=>_o(e,t)),mo=e=>(e??``).trim().toLowerCase().replace(/[-_]/g,` `),ho=e=>so.includes(mo(e.title))?mo(e.title):mo(e.title)===`seealso`?`see also`:null,go=e=>mo(e.title)===`left`?`left`:`center`;function _o(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 vo(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`||ho(e)!==null)&&n.push(_o(e,null)),n}var yo=(e,t)=>e.dispatch({changes:t,userEvent:`input.link`});function bo(e){let t=[...so.map(t=>({label:t[0].toUpperCase()+t.slice(1),on:ho(e)===t,run:(e,n)=>yo(e,_o(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:ho(e)===null,run:(e,t)=>yo(e,_o(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)=>yo(e,vo(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)=>yo(e,vo(t,!1)),hint:`A link to it; it opens on its own`}];return e.kind===`image`?e.embed?[...n,{label:`Centre`,on:go(e)===`center`,run:(e,t)=>yo(e,_o(t,null)),hint:`In the middle, 80% of the text's width`},{label:`Left`,on:go(e)===`left`,run:(e,t)=>yo(e,_o(t,`left`)),hint:`At the left, 80% of the text's width`}]:n:e.embed?n:[...n,...t]}function xo(e){let t=t=>e.every(e=>ho(e)===t),n=e.length;return[...so.map(e=>({label:e[0].toUpperCase()+e.slice(1),on:t(e),run:t=>yo(t,po(fo(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=>yo(e,po(fo(e.state,e.state.selection.main.from,e.state.selection.main.to),null)),hint:`Take the rating from all ${n} links`}]}function So(e){let t=ho(e[0]),n=e.every(e=>ho(e)===t);return`${e.length} links, ${n?t??`unrated`:`mixed`}`}function Co(e){return e.kind===`note`?ho(e)?ho(e)[0].toUpperCase()+ho(e).slice(1):`Unrated`:e.embed?e.kind===`image`?go(e)===`left`?`Shown, left`:`Shown, centre`:`Shown here`:ho(e)?`Link, ${ho(e)}`:`Link`}var wo=(e,t)=>e===t||!!e&&!!t&&e.from===t.from&&e.to===t.to&&e.title===t.title&&e.embed===t.embed,To=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:lo(this.view.state,t);wo(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=fo(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]:lo(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?So(e.many):Co(e.l),n=!wo(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?xo(this.many):bo(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()}},Eo=st.fromClass(To),Do=e=>t=>{let n=lo(t.state,t.state.selection.main.head);return n?(e(t,n),!0):!1},Oo=e=>t=>{let n=t.state.selection.main,r=n.empty?[]:fo(t.state,n.from,n.to);return r.length>=2?(yo(t,po(r,e)),!0):Do((t,n)=>{uo(n)&&yo(t,_o(n,e))})(t)},ko=[{key:`Alt-l`,run:e=>{let t=e.plugin(Eo);return!t||!t.current()?!1:(t.toggle(!0,!1),!0)}},{key:`Alt-1`,run:Oo(`requires`)},{key:`Alt-2`,run:Oo(`uses`)},{key:`Alt-3`,run:Oo(`see also`)},{key:`Alt-0`,run:Oo(null)},{key:`Alt-e`,run:Do((e,t)=>{t.kind!==`note`&&yo(e,vo(t,!t.embed))})}],Ao=[Eo,q.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`}}),rt.of(ko)];function jo(e){return t=>{let n=t.matchBefore(/\[\[(?!!)[^\]\n]*$/);if(!n)return null;let r=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}})}}));return{from:n.from+2,options:r,filter:!0,validFor:/^[^\]\n]*$/}}}var Mo=e=>e.split(`/`).at(-1).replace(/\.[^.]+$/,``).replace(/[-_]+/g,` `).trim(),No=e=>/[\s()<>]/.test(e)?`<${e}>`:e;function Po(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:()=>Lo(e),apply:(t,n,r,a)=>{let o=Mo(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,U(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 Fo(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:()=>Lo(e)}))],validFor:/^[^)\s]*$/}}}function Io(e,t){e.alt=``,e.decoding=`async`,typeof t.src==`string`?e.src=t.src:t.src.then(t=>{t&&(e.src=t)})}function Lo(e){let t=document.createElement(`div`);t.className=`cm-picture-preview`;let n=document.createElement(`img`);Io(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 Ro(e,t=null){return Nt({override:[Po(e,t),jo(e),Fo(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`,Io(t,e.picture),t}}]})}var zo=36,Bo=92,Vo=40,Ho=/^\$\$([^$]*?[^\\])\$\$/,Uo=/^\$((?:[^\s\\])|(?:\S.*?[^\s\\]))\$(?!\d)/,Wo=/^\\\((.+?)\\\)/,Go=/^\$\$([^$]*?[^\\])\$\$(?:[ \t]*\([^)\s]+?\))?(?=[ \t]*(?:\n|$))/,Ko=/^\\\[([\s\S]+?)\\\](?:[ \t]*\([^)$\r\n]+?\))?(?=[ \t]*(?:\n|$))/;function qo(e,t,n){if(t===zo){if(n>e.offset&&e.char(n-1)===Bo)return-1;let t=e.slice(n,e.end),r=(t.charCodeAt(1)===zo?Ho:Uo).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===Bo&&e.char(n+1)===Vo){let t=Wo.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 Jo=2e4;function Yo(e,t){let n=t.text.slice(t.pos),r=n.startsWith(`$$`)?Go:n.startsWith(`\\[`)?Ko: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+Jo)));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 Xo={defineNodes:[{name:`InlineMath`,style:Y.special(Y.content)},{name:`BlockMath`,block:!0,style:Y.special(Y.content)},{name:`MathMark`,style:Y.processingInstruction}],parseInline:[{name:`InlineMath`,parse:qo,before:`Escape`}],parseBlock:[{name:`BlockMath`,parse:Yo,before:`FencedCode`}]};function Zo(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 Qo=class extends lt{eq(){return!0}toDOM(){let e=document.createElement(`span`);return e.className=`cm-lp-bullet`,e.textContent=`•`,e}},$o=class extends lt{eq(){return!0}toDOM(){let e=document.createElement(`span`);return e.className=`cm-lp-hr`,e}},es=class extends lt{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}},ts=class extends lt{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}=Zo(this.source);return e.innerHTML=Be.renderToString(t,{displayMode:n,throwOnError:!1}),e}},ns=class extends lt{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}},rs=class extends lt{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}},is=X.replace({}),as=X.replace({widget:new Qo}),os=X.replace({widget:new $o}),ss=e=>X.mark({class:e}),cs=e=>X.line({class:e});function ls(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 us(e){let{state:t}=e,n=ls(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(cs(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(K(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(cs(a?`cm-lp-gap cm-lp-gap-more`:o?`cm-lp-gap cm-lp-gap-rule`:`cm-lp-gap`).range(r.from))}K(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(is.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(is.range(e.from,n));break}case`EmphasisMark`:case`StrikethroughMark`:r(e.from)||i.push(is.range(e.from,e.to));break;case`Emphasis`:i.push(ss(`cm-lp-em`).range(e.from,e.to));break;case`StrongEmphasis`:i.push(ss(`cm-lp-strong`).range(e.from,e.to));break;case`Strikethrough`:i.push(ss(`cm-lp-strike`).range(e.from,e.to));break;case`InlineCode`:if(i.push(ss(`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(is.range(e.from,e.to))}return!1;case`InlineMath`:return r(e.from)?i.push(ss(`cm-lp-mathsrc`).range(e.from,e.to)):i.push(X.replace({widget:new ts(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=ue(p?t.sliceDoc(p.from+1,p.to-1):null),h=d?t.facet(ps)(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?X.mark({class:h,attributes:{title:t.facet(ps)(u)?`${u.slice(5)}: not in the repository`:u.slice(5)}}):ss(h)).range(s.to,c.from)),!r(e.from)&&o&&s&&c&&(i.push(is.range(s.from,s.to)),i.push(is.range(c.from,e.to)));break}case`Image`:{let n=e.node,a=n.getChild(`URL`),o=n.getChildren(`LinkMark`),s=a?t.facet(fs)(t.sliceDoc(a.from,a.to)):null;if(s&&o.length>=2){let t=new rs(s.path,s.mount);return r(e.from)?i.push(X.widget({widget:t,side:1}).range(e.to)):i.push(X.replace({widget:t}).range(e.from,e.to)),!1}let c=a?t.facet(ds)(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 ns(c.key,c.src,t.sliceDoc(o[0].to,o[1].from),u===`left`);return r(e.from)?i.push(X.widget({widget:d,side:1}).range(e.to)):i.push(X.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(as.range(e.from,e.to)):i.push(ss(`cm-lp-listmark`).range(e.from,e.to));break}case`TaskMarker`:i.push(ss(`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(is.range(e.from,n))}break;case`HorizontalRule`:r(e.from)||(i.push(os.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(cs(`cm-lp-fence`).range(o.from));let e=c?t.sliceDoc(c.from,c.to).trim().split(/\s/)[0]:``;i.push((e?X.replace({widget:new es(e)}):is).range(o.from,o.to))}return l&&s.number>o.number&&!r(s.from)&&(i.push(cs(`cm-lp-fence`).range(s.from)),s.to>s.from&&i.push(is.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 vt;for(let e of i)s.add(e.from,e.to,e.value);return s.finish()}var ds=mt.define({combine:e=>e[0]??(()=>null)}),fs=mt.define({combine:e=>e[0]??(()=>null)}),ps=mt.define({combine:e=>e[0]??(()=>!1)}),ms=st.fromClass(class{decorations;constructor(e){this.decorations=us(e)}update(e){(e.docChanged||e.viewportChanged||e.selectionSet||e.focusChanged||K(e.startState)!==K(e.state))&&(this.decorations=us(e.view))}},{decorations:e=>e.decorations}),hs=q.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 gs(e){let t=e.split(`#`)[0];return t.startsWith(`/`)&&t.endsWith(`.md`)?t.slice(1,-3):null}function _s(e){let t=e.split(/[#?]/)[0];return t.startsWith(`/`)&&!t.startsWith(`//`)&&/\/[^/]*\.[^./]+$/.test(t)&&!t.endsWith(`.md`)?decodeURI(t.slice(1)):null}var vs=Ct.define(),ys=Ct.define(),bs=[wt.define({create:()=>X.none,update(e,t){for(let e of t.effects){if(!e.is(ys))continue;let n=t.state.doc,r=e.value;if(!r)return X.none;let i=X.line({class:`cm-touched cm-touched-${r.who}`});return X.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=>q.decorations.from(e)}),q.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)`}})],xs=Ct.define(),Ss=class extends lt{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 Cs(e){return[wt.define({create:()=>X.none,update(t,n){for(let t of n.effects){if(!t.is(vs))continue;let r=n.state.doc;return X.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 X.widget({widget:new Ss(t.key,e,!0),block:!0,side:n?1:-1}).range(i)}),!0)}return n.docChanged?t.map(n.changes):t},provide:e=>q.decorations.from(e)}),wt.define({create:()=>X.none,update(t,n){for(let t of n.effects){if(!t.is(xs))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(X.mark({class:`cm-iso-${e.kind}`}).range(t,n))}for(let n of t.value.inline)i.push(X.widget({widget:new Ss(n.key,e,!1),side:1}).range(Math.max(0,Math.min(r,n.at))));return X.set(i,!0)}return n.docChanged?t.map(n.changes):t},provide:e=>q.decorations.from(e)}),q.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 ws(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 Ts=Ct.define(),Es=X.mark({class:`cm-pointed`});function Ds(e,t){if(!t)return X.none;let n=[];return K(e).iterate({enter:r=>{if(r.name!==`Link`)return;let i=lo(e,r.from+1);return i&&!i.embed&&i.from===r.from&&ws(i.url)?.id===t&&n.push(Es.range(i.from,i.to)),!1}}),X.set(n)}var Os=wt.define({create:()=>({id:``,marks:X.none}),update(e,t){let n=e.id;for(let e of t.effects)e.is(Ts)&&(n=e.value);return n!==e.id||n&&t.docChanged?{id:n,marks:Ds(t.state,n)}:e},provide:e=>q.decorations.from(e,e=>e.marks)}),ks=q.theme({".cm-pointed":{backgroundColor:`var(--lattice-soft)`,boxShadow:`0 2px 0 var(--lattice)`}});function As(e){if(!e)return[Os,ks];let t=``,n=n=>{let r=n?`${n.folder?`d`:`n`}:${n.id}`:``;r!==t&&(t=r,e(n))};return[Os,ks,q.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:lo(t.state,r);return n(i&&!i.embed?ws(i.url):null),!1},pointerleave(){return n(null),!1}})]}var js=q.theme({".cm-scroller":{fontFamily:`var(--font-mono)`,fontSize:`14px`,lineHeight:`1.6`}}),Ms=q.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`}}),Ns=Tt.define([{tag:Y.heading,fontWeight:`700`,color:`var(--text)`},{tag:Y.strong,fontWeight:`700`},{tag:Y.emphasis,fontStyle:`italic`},{tag:Y.strikethrough,textDecoration:`line-through`},{tag:[Y.link,Y.url],color:`var(--lattice)`},{tag:[Y.processingInstruction,Y.punctuation,Y.contentSeparator],color:`var(--text-faint)`},{tag:Y.monospace,color:`var(--text-soft)`},{tag:Y.quote,color:`var(--text-soft)`,fontStyle:`italic`}]);function Ps(e){let t=e.selection.main;return{line:e.doc.lineAt(t.to).number-1,from:t.from,to:t.to}}function Fs(e){let t=e=>[...e??[]].filter(e=>e.type.startsWith(`image/`));return q.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 Is(e,t){let n=ht.create({doc:t.doc,extensions:[Ir(),dt(),q.lineWrapping,ze({base:We,extensions:[Xo],completeHTMLTags:!1,codeLanguages:Xe}),it(Ns),it(Le),Ms,...t.source?[js]:[ms,hs,Qa,$a,Ao,...t.embeds?[Ha.of(t.embeds)]:[],...t.codeBroken?[ps.of(t.codeBroken)]:[],...t.pictures?[ds.of(t.pictures)]:[],...t.artifacts?[fs.of(t.artifacts)]:[]],Ft(),ht.languageData.of(()=>[{closeBrackets:{brackets:[`(`,`[`]}}]),...t.mountOverlay?[Cs(t.mountOverlay)]:[],bs,As(t.onPoint),...t.readOnly?[ht.readOnly.of(!0),q.editable.of(!1)]:[],Ro(t.notes,t.pictureSource??null),...t.onPictures&&!t.readOnly?[Fs(t.onPictures)]:[],ot(t.placeholder??`Write the note here. # for a heading, [[ to link to another note, [[! to show a picture, $x$ for maths.`),q.contentAttributes.of({"aria-label":t.label,spellcheck:`true`,autocapitalize:`sentences`,autocorrect:`on`}),rt.of([{key:`Mod-s`,preventDefault:!0,run:()=>(t.onSave(),!0)},{key:`Mod-Enter`,preventDefault:!0,run:e=>(t.onAsk?.(Ps(e.state)),!!t.onAsk)},...oo,...jt,...Pt,Va,...Ba,...ei]),q.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:lo(n.state,r),a=i?i.embed?_s(i.url):gs(i.url)??_s(i.url):null;return a!==null&&(e.preventDefault(),t.onFollow(a),!0)}}),q.updateListener.of(e=>{e.docChanged&&t.onChange(e.state.doc.toString()),t.onCursor&&(e.selectionSet||e.docChanged)&&t.onCursor(Ps(e.state))})]});return new q({state:n,parent:e})}function Ls(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 Rs=2e7,zs={type:`string`};({...zs}),{...zs},{...zs},{...zs},{...zs};var Bs=`conversations`,Vs={type:`string`},Hs=(e,t,n,r)=>({type:`function`,function:{name:e,description:t,parameters:{type:`object`,properties:n,required:r,additionalProperties:!1}}});({...Vs}),{...Vs};var Us=Hs(`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:{...Vs,description:`The file's path in the base: folder/name.csv.`}},[`path`]),Ws=Hs(`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`]),Gs=Hs(`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:{...Vs,description:`Where: folder/name.html, beside the notes it belongs to.`},title:Vs,description:{...Vs,description:`One sentence: what it shows, and what can be done with it.`},uses:{type:`array`,items:Vs,description:`The data or model files it reads, relative to it (runs.csv). Those its markup and script name are added.`},html:{...Vs,description:`The whole file.`}},[`path`,`title`,`description`,`uses`,`html`]),Ks=Hs(`read_artifact`,`An artifact's whole file, to change it and write it again.`,{path:{...Vs,description:`folder/name.html`}},[`path`]);({...Vs}),{...Vs},`${Bs}`,new Set([Us,Ws,Ks,Gs].map(e=>e.function.name));var qs=`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.`;`${qs}`,`${qs}`;var Js=u(`<p class="same svelte-18j5w6l">This picture is already in the notes as <code> </code>.</p>`),Ys=u(`<code> </code> is taken: Enter makes it <code> </code>`,1),Xs=u(`<code> </code>`),Zs=u(`<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),Qs=u(`<button class="btn" type="button"> </button>`),$s=u(`<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 ec(n,r){N(r,!0);let i=k(()=>({"image/png":`png`,"image/jpeg":`jpg`,"image/gif":`gif`,"image/webp":`webp`,"image/svg+xml":`svg`,"image/avif":`avif`})[r.file.type]??`png`),o=z(ne(r.suggested)),c=z(``),u=z(!1),p=z(void 0),m,g=k(()=>Pe(h(o))||`picture`),_=k(()=>`${r.folder?r.folder+`/`:``}${h(g)}.${h(i)}`),b=k(()=>r.taken(h(_))),x=k(()=>{for(let e=2;;e++)if(!r.taken(`${r.folder?r.folder+`/`:``}${h(g)}-${e}.${h(i)}`))return`${h(g)}-${e}`}),D=k(()=>r.same!==null&&!h(u));F(()=>{h(p)?(h(p).focus(),h(p).select()):m.focus()});function O(e){e.key===`Escape`?(e.preventDefault(),r.onDone(null)):e.key===`Enter`&&(e.preventDefault(),A())}function A(){if(!h(D)&&h(b)){I(o,h(x),!0);return}let e=h(D)?r.same:h(_);r.onDone({path:e,alt:h(c).trim()||Mo(e),save:!h(D)})}var j=$s();let P;var ee=v(j),te=w(ee,2),R=v(te),H=n=>{var i=Js(),o=w(v(i)),c=e(o,!0);E(),L(i),a(()=>t(c,r.same)),s(n,i)},re=n=>{var r=Zs(),c=d(r),u=w(v(c),2),f=v(u);C(f),M(f,e=>I(p,e),()=>h(p));var m=w(f),g=e(m);L(u),L(c);var y=w(c,2);let S;var T=v(y),E=n=>{var r=Ys(),o=d(r),c=e(o,!0),l=w(o,2),u=e(l);a(()=>{t(c,h(_)),t(u,`${h(x)??``}.${h(i)??``}`)}),s(n,r)},D=n=>{var r=Xs(),i=e(r,!0);a(()=>t(i,h(_))),s(n,r)};l(T,e=>{h(b)?e(E):e(D,-1)}),L(y),a(()=>{t(g,`.${h(i)??``}`),S=V(y,1,`path svelte-18j5w6l`,null,S,{taken:h(b)})}),B(f,()=>h(o),e=>I(o,e)),s(n,r)};l(R,e=>{h(D)?e(H):e(re,-1)});var ie=w(R,2),ae=w(v(ie),2);C(ae),M(ae,e=>m=e,()=>m),L(ie);var oe=w(ie,2),U=v(oe),se=n=>{var r=Qs(),i=e(r,!0);a(()=>t(i,h(u)?`Use the one there`:`Save a copy`)),f(`click`,r,()=>{I(u,!h(u)),h(u)&&requestAnimationFrame(()=>{h(p)?.focus(),h(p)?.select()})}),s(n,r)};l(U,e=>{r.same!==null&&e(se)});var W=w(U,2),ce=w(W,2),le=e(ce,!0);L(oe),L(te),L(j),a(()=>{P=y(j,``,P,{left:`${r.at.left??``}px`,top:`${r.at.top??``}px`}),T(ee,`src`,r.src),t(le,h(D)?`Show it`:`Save`)}),f(`keydown`,j,O),B(ae,()=>h(c),e=>I(c,e)),f(`click`,W,()=>r.onDone(null)),f(`click`,ce,A),s(n,j),S()}o([`keydown`,`click`]);var tc=u(`<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>`),nc=u(`<p class="soft lost svelte-192cp36"><span class="strike svelte-192cp36"> </span> </p>`),rc=u(`<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>`),ic=u(`<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>`),ac=u(`<textarea class="revision svelte-192cp36" aria-label="Iso's text, to edit"></textarea>`),oc=u(`<div class="prose said svelte-192cp36"></div>`),sc=u(`<p class="label"> </p>`),cc=u(`<button class="btn edit" type="button">done</button>`),lc=u(`<button class="btn edit" type="button">edit</button>`),uc=u(`<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 dc(n,r){N(r,!0);let i=O(r,`iso`,7),o=k(()=>r.key.startsWith(`p:`)?i().proposals.find(e=>e.id===r.key.slice(2)):void 0),u=k(()=>h(o)&&i().editing?.id===h(o).id?i().editing:null),m=k(()=>!!h(o)&&i().busy===h(o)?.id),g=k(()=>i().changes.filter(e=>!e.at));var _=c(),y=d(_),b=n=>{var r=tc(),o=v(r),c=e(o,!0),l=w(o,2),u=w(v(l));L(l),L(r),a(()=>t(c,i().failed.message)),f(`click`,u,()=>i().failed=null),s(n,r)},C=n=>{var r=rc(),o=v(r),c=e(o),l=w(o,2);p(l,17,()=>h(g),e=>e.key,(n,r)=>{var i=nc(),o=v(i),c=e(o,!0),l=w(o);L(i),a((e,n)=>{t(c,e),t(l,` → ${n??``}`)},[()=>h(r).proposal.regions[h(r).k].old.text.trim(),()=>h(r).proposal.regions[h(r).k].new.trim()||`(taken out)`]),s(n,i)});var u=w(l,2),d=w(v(u));L(u),L(r),a(()=>t(c,`${h(g).length===1?`One change Iso offered is`:`${h(g).length} changes Iso offered are`} for text that is no longer in the note as it was, so ${h(g).length===1?`it`:`they`} cannot be kept.`)),f(`click`,d,()=>{for(let e of h(g))i().discardChange(e)}),s(n,r)},E=n=>{var r=uc(),c=v(r),d=e=>{var t=ic();s(e,t)},p=k(()=>!i().placed(h(o)));l(c,e=>{h(p)&&e(d)});var g=w(c,2),_=e=>{var t=ac();ee(t),a(e=>T(t,`rows`,e),[()=>Math.max(3,h(u).text.split(`
|
|
13
|
-
`).length+1)]),B(t,()=>h(u).text,e=>h(u).text=e),s(e,t)},y=e=>{var t=oc();H(t,()=>Ue(h(o).text),!0),L(t),x(t,(e,t)=>Ze?.(e,t),()=>({given:h(o).text,copy:!0})),s(e,t)};l(g,e=>{h(u)?e(_):e(y,-1)});var b=w(g,2),S=n=>{var r=sc(),i=e(r,!0);a(()=>t(i,h(o).notice)),s(n,r)};l(b,e=>{h(o).notice&&e(S)});var C=w(b,2),E=w(v(C),4),D=w(E,2),O=e=>{var t=cc();f(`click`,t,()=>i().done(h(o))),s(e,t)},A=e=>{var t=lc();a(()=>t.disabled=h(m)),f(`click`,t,()=>i().edit(h(o))),s(e,t)};l(D,e=>{h(u)?e(O):e(A,-1)});var j=w(D,2);L(C),L(r),a(()=>{T(r,`data-proposal`,h(o).id),E.disabled=h(m),j.disabled=h(m)}),f(`click`,E,()=>i().keep(h(o))),f(`click`,j,()=>i().discard(h(o))),s(n,r)};l(y,e=>{r.key===`failed`&&i().failed?e(b):r.key===`lost`&&h(g).length?e(C,1):h(o)&&e(E,2)}),s(n,_),S()}o([`click`]);var fc=u(`<span class="label who svelte-1o10yjh"> </span>`),pc=u(`<!> <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),mc=u(`<span class="gone svelte-1o10yjh">the passage above is taken out</span>`),hc=u(`<pre class="new svelte-1o10yjh"> </pre>`),gc=u(`<div class="new prose svelte-1o10yjh"></div>`),_c=u(`<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>`),vc=u(`<span class="new svelte-1o10yjh"></span>`),yc=u(`<span class="gone svelte-1o10yjh">taken out</span>`),bc=u(`<span class="change svelte-1o10yjh"><!> <!></span>`);function xc(n,r){N(r,!0);let i=n=>{var i=pc(),c=d(i),u=n=>{var r=fc(),i=e(r,!0);a(()=>{T(r,`title`,h(o)?.proposal.asked),t(i,h(_))}),s(n,r)};l(c,e=>{h(_)&&e(u)});var m=w(c,2),g=v(m),y=w(g);L(m),a(()=>{g.disabled=h(p),y.disabled=h(p)}),f(`click`,g,()=>h(o)&&r.iso.keepChange(h(o))),f(`click`,y,()=>h(o)&&r.iso.discardChange(h(o))),s(n,i)},o=k(()=>r.iso.changes.find(e=>e.key===r.key)),u=k(()=>h(o)?h(o).proposal.regions[h(o).k].new:``),p=k(()=>r.iso.busy===r.key||r.iso.busy===`all`),m=k(()=>Ue(h(u).trim())),g=k(()=>h(m).replace(/^<p>([\s\S]*)<\/p>\s*$/,`$1`)),_=k(()=>h(o)?Ne(h(o).proposal.who):``);var y=c(),b=d(y),C=n=>{var c=_c();let d;var f=v(c),p=e=>{var t=mc();s(e,t)},g=k(()=>!h(u).trim()),_=n=>{var r=hc(),i=e(r,!0);a(e=>t(i,e),[()=>h(u).replace(/^\n+|\s+$/g,``)]),s(n,r)},y=e=>{var t=gc();H(t,()=>h(m),!0),L(t),x(t,(e,t)=>Ze?.(e,t),()=>h(m)),s(e,t)};l(f,e=>{h(g)?e(p):h(o).code?e(_,1):e(y,-1)});var b=w(f,2),S=w(v(b),3);i(S),L(b),L(c),a(()=>{d=V(c,1,`change block svelte-1o10yjh`,null,d,{code:h(o).code}),T(c,`data-change`,r.key)}),s(n,c)},E=e=>{var t=bc(),n=v(t),o=e=>{var t=vc();H(t,()=>h(g),!0),L(t),s(e,t)},c=k(()=>h(u).trim()),d=e=>{var t=yc();s(e,t)};l(n,e=>{h(c)?e(o):e(d,-1)});var f=w(n,2);i(f),L(t),a(()=>T(t,`data-change`,r.key)),s(e,t)};l(b,e=>{h(o)?.block?e(C):h(o)&&e(E,1)}),s(n,y),S()}o([`click`]);var Sc=u(`<p class="said svelte-hrl8lz" role="status"> </p>`),Cc=u(`<div></div> <!> <!>`,1);function wc(n,r){N(r,!0);let i=O(r,`iso`,7),o=O(r,`reading`,3,!1),c=O(r,`touched`,3,null),u=O(r,`lens`,19,()=>[]),f,p=z(void 0),m=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`image/svg+xml`,`image/avif`],_=z(null),v=z(null),y,x=e=>{I(v,e,!0),clearTimeout(y),y=setTimeout(()=>I(v,null),8e3)};async function C(e,t,n){if(!h(p)||h(_))return;let i=r.note.id,a=!i.startsWith(`@`),o=a?i:`pictures`,s=e=>a&&e.startsWith(`${i}/`)?No(e.slice(i.lastIndexOf(`/`)+1)):`/${No(e)}`,c=[];try{c=await G.api.pictures()}catch{}let l=new Set(c.map(e=>e.path));for(let r of e){if(!m.includes(r.type)){x(`${r.name||`That`} isn't a picture isorite keeps: png, jpg, gif, webp, svg and avif are.`);continue}if(r.size>2e7){x(`${r.name||`That picture`} is larger than isorite takes (${Rs/1e6} MB).`);continue}let e=new Uint8Array(await r.arrayBuffer()),i=await Qe(e),a=c.find(e=>e.sha256===i)?.path??null,u=URL.createObjectURL(r),d=h(p),g=d.coordsAtPos(Math.min(t,d.state.doc.length)),v=f.getBoundingClientRect(),y=await new Promise(e=>{I(_,{file:r,src:u,folder:o,same:a,onDone:e,suggested:n||!r.name?tt():Pe(r.name)||`picture`,taken:e=>l.has(e),at:{left:Math.max(16,Math.min(g?.left??v.left,innerWidth-476)),top:Math.min((g?.bottom??v.top)+6,innerHeight-220)}})});if(I(_,null),URL.revokeObjectURL(u),!y)continue;if(y.save)try{let t=await G.api.savePicture(y.path,e);c.push(t),l.add(t.path)}catch(e){x(`It wasn't saved: ${e.message}`);continue}let b=`![${y.alt.replace(/[[\]]/g,``)}](${s(y.path)})`;d.dispatch({changes:{from:t,insert:b},selection:{anchor:t+b.length}}),t+=b.length}h(p).focus()}let T=k(()=>r.source||!i()?{lines:0,chars:0}:i().head),E=k(()=>{if(!i())return{blocks:[],marks:[],inline:[]};let e=e=>t=>({kind:e,from:t.from-h(T).chars,to:t.to-h(T).chars});return{blocks:i().layout.blocks.map(e=>({key:e.key,line:Math.max(0,e.line-h(T).lines)})).sort((e,t)=>e.line-t.line),marks:[...i().layout.old.map(e(`old`)),...u().map(t=>e(t.kind)(t))].filter(e=>e.to>0),inline:i().layout.inline.map(e=>({key:e.key,at:e.at-h(T).chars})).filter(e=>e.at>=0)}});F(()=>{let e=Is(f,{doc:r.source?r.note.text:r.note.body,source:r.source,readOnly:o(),label:r.source?`The note's file`:`The note`,notes:()=>G.listing.notes.filter(e=>e.id!==r.note.id).map(e=>({id:e.id,title:e.title,folder:e.dir,...e.kind?{kind:e.kind}:{}})),onPictures:(e,t,n)=>{C(e,t,n)},pictureSource:{pictures:async()=>(await G.api.pictures()).map(e=>({path:e.path,width:e.width,height:e.height,src:et(G.api,{path:e.path,from:`notes`})})),here:()=>r.note.id},onChange:e=>r.source?r.note.setText(e):r.note.setBody(e),onSave:()=>{r.note.save()},onFollow:e=>{oe(Ee(e))},embeds:{find:Te,open:e=>{oe(Ee(e))}},onPoint:e=>He.set(`note`,e?{...e,who:`you`}:null),codeBroken:e=>G.listing.notes.find(e=>e.id===r.note.id)?.broken?.includes(e)??!1,pictures:e=>{let t=Re(e,r.note.id);return t?{key:`${t.from}:${t.path}`,src:et(G.api,t)}:null},artifacts:e=>{let t=e.trim().startsWith(`code:`)?de(e.trim()):null;if(t&&W(t.path)!==`image`)return{path:e,mount:t=>{let n=j(gr,{target:t,props:{href:e.trim()}});return()=>{A(n)}}};let n=dn(e,r.note.id);return n?{path:n,mount:e=>{let t=j(yr,{target:e,props:{path:n}});return()=>{A(t)}}}:null},...i()?{onAsk:e=>{let t=r.note.text.slice(e.from+h(T).chars,e.to+h(T).chars).trim();t&&Ie.add({kind:`passage`,id:r.note.id,title:r.note.fields.title||r.note.id,text:t}),be.to(`iso`),requestAnimationFrame(()=>document.getElementById(`iso-box`)?.focus())},onCursor:e=>{i().cursor={line:e.line+h(T).lines,from:e.from+h(T).chars,to:e.to+h(T).chars}},mountOverlay:(e,t)=>{let n=j(t.startsWith(`r:`)?xc:dc,{target:e,props:{iso:i(),key:t}});return()=>{A(n)}}}:{placeholder:g(()=>r.placeholder)??`Write what you understand, what you do not, and what you want from Iso. [[ links a note it should rest on.`}});return I(p,e),()=>{e.destroy(),He.set(`note`,null)}}),R(()=>{r.note.revision,g(()=>{h(p)&&Ls(h(p),r.source?r.note.text:r.note.body)})}),R(()=>{let e=c(),t=h(T).lines;h(p)&&h(p).dispatch({effects:ys.of(e?{who:e.who,lines:e.lines.map(e=>e-t)}:null)})}),R(()=>{let e=He.onAtlas;h(p)&&h(p).dispatch({effects:Ts.of(e)})}),R(()=>{let{blocks:e,marks:t,inline:n}=h(E);h(p)&&h(p).dispatch({effects:[vs.of(e),xs.of({marks:t,inline:n})]})});var D=Cc(),P=d(D);let ee;M(P,e=>f=e,()=>f);var te=w(P,2),L=e=>{ec(e,b(()=>h(_)))};l(te,e=>{h(_)&&e(L)});var ne=w(te,2),B=n=>{var r=Sc(),i=e(r,!0);a(()=>t(i,h(v))),s(n,r)};l(ne,e=>{h(v)&&e(B)}),a(()=>ee=V(P,1,`editor svelte-hrl8lz`,null,ee,{source:r.source})),s(n,D),S()}var Tc=u(`<h1 class="serif title svelte-130pv1o"> </h1>`),Ec=u(`<p class="asked svelte-130pv1o"><i class="dia svelte-130pv1o" aria-hidden="true"></i><span> </span></p>`),Dc=u(`<div class="offered svelte-130pv1o" aria-label="What Iso offered"><p class="serif svelte-130pv1o"> </p></div>`),Oc=u(`<div class="version svelte-130pv1o"><!> <!> <div class="text svelte-130pv1o"></div> <!></div>`);function kc(n,r){N(r,!0);let i=k(()=>{try{let[e,t,n]=pe(r.text);return{title:/^title:\s*(.*)$/m.exec(t??``)?.[1]?.trim().replace(/^["']|["']$/g,``)??``,body:n,lines:e.split(`
|
|
14
|
-
`).length-1}}catch{return{title:``,body:r.text,lines:0}}}),o,c=z(void 0);F(()=>(I(c,Is(o,{doc:h(i).body,onChange:()=>void 0,onSave:()=>void 0,label:`The note as it was`,notes:()=>[],readOnly:!0,pictures:e=>{let t=Re(e,r.id);return t?{key:`${t.from}:${t.path}`,src:et(G.api,t)}:null}})),()=>h(c)?.destroy())),R(()=>{let e=r.touched,t=h(i).lines;h(c)?.dispatch({effects:ys.of(e?{who:e.who,lines:e.lines.map(e=>e-t)}:null)})});var u=Oc(),d=v(u),f=n=>{var r=Tc(),o=e(r,!0);a(()=>t(o,h(i).title)),s(n,r)};l(d,e=>{h(i).title&&h(i).title!==r.title&&e(f)});var p=w(d,2),m=n=>{var i=Ec(),o=w(v(i)),c=e(o,!0);L(i),a(()=>t(c,r.asked)),s(n,i)};l(p,e=>{r.asked!==void 0&&e(m)});var g=w(p,2);M(g,e=>o=e,()=>o);var _=w(g,2),y=n=>{var i=Dc(),o=v(i),c=e(o,!0);L(i),a(()=>t(c,r.offered)),s(n,i)};l(_,e=>{r.offered!==void 0&&e(y)}),L(u),s(n,u),S()}var Ac=(e,t=P,n=P)=>{var r=Nc();let i;var o=v(r),c=e=>{var t=jc();a(()=>T(t,`fill`,n()?`currentColor`:`none`)),s(e,t)},u=e=>{var t=Mc();a(()=>T(t,`fill`,n()?`currentColor`:`none`)),s(e,t)};l(o,e=>{t()===`question`?e(c):e(u,-1)}),L(r),a(()=>i=V(r,0,`glyph ${t()??``}`,`svelte-18ltlst`,i,{solved:n()})),s(e,r)},jc=i(`<path d="M8 2.5L13.5 8L8 13.5L2.5 8Z"></path>`),Mc=i(`<path d="M8 2.5l5.8 10.5H2.2z"></path>`),Nc=i(`<svg viewBox="0 0 16 16" width="18" height="18" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.4"><!></svg>`),Pc=u(`<p class="faint"><!></p>`),Fc=u(`<p class="soft">There is no note at <span class="faint"> </span>.</p> <p><a>all notes</a></p>`,1),Ic=u(`<p class="bad svelte-18ltlst"> </p>`),Lc=u(`<button class="btn" type="button">take theirs</button>`),Rc=u(`<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>`),zc=u(`<div class="titlerow svelte-18ltlst"><!> <h1 class="serif title read svelte-18ltlst"> </h1></div>`),Bc=u(`<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>`),Vc=u(`<span class="grow faint"> </span>`),Hc=u(`<div class="tl-col svelte-18ltlst"><!></div>`),Uc=u(`<span class="bad svelte-18ltlst" role="alert"> </span>`),Wc=u(`<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),Gc=u(`<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>`),Kc=i(`<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>`),qc=u(`<li><a><!><span class="svelte-18ltlst"> </span><!></a></li>`),Jc=u(`<ul class="attached svelte-18ltlst"></ul>`),Yc=u(`<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>`),Xc=u(`<!> <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),Zc=u(`<article><!></article>`);function Qc(r,i){N(i,!0);let o=new Gn(i.id),c=new Bn(o),u=z(!1),g=k(()=>h(u)||o.meta===null),b=z(!1),x=k(()=>h(b)&&!h(g)),C=k(()=>be.on.timeline),D=z(null),O=z(null),A=z(!1),j=z(``),P=k(()=>me(c.entries)),B=e=>e.who.startsWith(`iso:`)||e.who.startsWith(`agent:`),H=e=>e.flatMap(e=>Array.from({length:e.to-e.from},(t,n)=>e.from+n)),ie=k(()=>{if(!h(C)||h(O)||h(g))return null;let e=h(D)??(h(ce)?void 0:h(P).findLast(e=>B(e)&&(e.what===`kept`||e.what===`edited`)));if(!e)return null;let t=H(he(c.entries,e.ids).runs);return t.length?{who:B(e)?`iso`:`you`,lines:t}:null}),U=k(()=>{if(!h(O))return null;let e=je(h(O)),t=Ae(c.entries,e);if(t===null)return null;let n=c.entries.filter(t=>t.id<=e),r=c.entries.find(e=>e.id===h(O).ids[0]),i=(h(O).what===`offered`||h(O).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:B(h(O))?`iso`:`you`,lines:H(he(n,h(O).ids).runs)},asked:h(O).asked,offered:i}}),se=()=>nt.url.searchParams.get(`at`)??new URLSearchParams(location.hash.split(`?`)[1]??``).get(`at`),W=z(ne(se()));R(()=>{let e=se();e&&I(W,e,!0)}),R(()=>{if(!h(W))return;let e=h(P).find(e=>e.ids.includes(h(W)));e&&(I(W,null),be.flip(`timeline`,!0),I(O,e))});let ce=k(()=>be.on.provenance);R(()=>{h(C)||(I(O,null),I(D,null))});let ue=k(()=>{if(!h(ce)||o.loaded!==`ready`)return[];let e=[],t=ke(c.entries),n=o.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 Ie.parts){if(t.kind!==`passage`||t.id!==i.id)continue;let n=o.text.indexOf(t.text);n>=0&&e.push({kind:`given`,from:n,to:n+t.text.length})}return e});function de(e){I(j,``),I(O,h(O)===e?null:e)}function fe(e){if(!h(O))return;let t=h(P).indexOf(h(O))+e;t>=0&&t<h(P).length&&I(O,h(P)[t])}async function pe(){if(h(O)){I(A,!0),I(j,``);try{await o.restore(je(h(O))),I(O,null)}catch(e){I(j,e.message,!0)}finally{I(A,!1)}}}function _e(e){!h(O)||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(),fe(-1)):e.key===`ArrowRight`||e.key===`ArrowDown`?(e.preventDefault(),fe(1)):e.key===`Escape`&&(e.preventDefault(),I(O,null)))}F(()=>{G.open=i.id,o.open().then(()=>c.open());let e=()=>{o.save()};return addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,e),()=>{removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,e),c.close(),o.close(),G.here=``,G.open=``,G.saving=null}});async function ve(){let e=i.id.split(`/`).at(-1),t=o.fields.title.trim();if(!/^untitled-(note|question|problem)(-\d+)?$/.test(e)||!t||/^untitled (note|question|problem)( \d+)?$/i.test(t))return;let n=[...i.id.split(`/`).slice(0,-1),ge(t)].filter(Boolean).join(`/`);if(ge(t)&&!G.listing.notes.some(e=>e.id===n))try{let e=await o.move(n);await G.refresh(),await oe(Ee(e),{replaceState:!0})}catch{}}R(()=>{o.loaded===`ready`&&be.fresh===i.id&&(be.fresh=``,m().then(()=>{let e=document.getElementById(`title`);e?.focus(),e?.select()}))});let ye={saved:`saved`,unsaved:`not saved yet`,saving:`saving`,conflict:`changed elsewhere: choose below`,failed:`not saved`};R(()=>{G.here=o.loaded===`ready`?o.fields.title||i.id.split(`/`).at(-1):``,G.saving=o.loaded===`ready`?{text:o.saving===`failed`?`not saved: ${o.message}`:ye[o.saving],bad:o.saving===`failed`||o.saving===`conflict`}:null});let xe=k(()=>[...new Set(c.changes.map(e=>Ne(e.proposal.who)||`Iso`))].join(` and `)),Ce=k(()=>le(String(o.meta?.type??``))),we=k(()=>h(Ce)===`note`?null:Se(o.meta??{},h(Ce))),Te=k(()=>G.listing.notes.filter(e=>e.kind&&e.id!==i.id&&e.attached?.includes(i.id)).sort((e,t)=>e.kind===t.kind?0:e.kind===`question`?-1:1)),De=z(!1);async function Oe(){I(De,!0);try{await o.setDone(!h(we))}catch{}finally{I(De,!1)}}let Pe=k(()=>c.cursor&&c.cursor.to>c.cursor.from?o.text.slice(c.cursor.from,c.cursor.to).trim():``),Le=z(void 0),Re=z(null);R(()=>{if(c.cursor,!h(Pe)||!h(Le)||h(g)||h(O)){I(Re,null);return}let e=requestAnimationFrame(()=>{let e=getSelection(),t=h(Le).getBoundingClientRect(),n=e?.rangeCount?e.getRangeAt(0).getBoundingClientRect():null;!n||!n.width&&!n.height?I(Re,{top:8,left:t.width-140},!0):I(Re,{top:be.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 ze=z(!1);function Be(){if(!h(Pe))return;let e=h(Pe).split(`
|
|
18
|
-
`).map(e=>`> ${e}`).join(`
|
|
19
|
-
`);navigator.clipboard?.writeText(`From /${i.id}.md in the notes:\n\n${e}\n`).then(()=>{I(ze,!0),setTimeout(()=>{I(ze,!1),I(Re,null)},900)},()=>void 0)}function He(){h(Pe)&&(Ie.add({kind:`passage`,id:i.id,title:o.fields.title||i.id,text:h(Pe)}),I(Re,null))}var Ue=Zc();re(`keydown`,_,_e);let We;var Ge=v(Ue),Ke=e=>{var t=Pc();zn(v(t),{label:`opening`}),L(t),s(e,t)},qe=n=>{var r=Fc(),o=d(r),c=w(v(o)),l=e(c,!0);E(),L(o);var u=w(o,2),f=e(u);a(e=>{t(l,i.id),T(f,`href`,e)},[()=>ae(`/notes`)]),s(n,r)},Je=n=>{var r=Ic(),i=e(r,!0);a(()=>t(i,o.message)),s(n,r)},Ye=r=>{var m=Xc(),_=d(m),S=n=>{var r=Rc(),i=w(v(r),2),c=e(i,!0),u=w(i,2),d=v(u),p=w(d,2),m=e=>{var t=Lc();f(`click`,t,()=>o.keepTheirs()),s(e,t)};l(p,e=>{o.theirs&&e(m)}),L(u),E(2),L(r),a(()=>t(c,o.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.`)),f(`click`,d,()=>o.keepMine()),s(n,r)};l(_,e=>{o.saving===`conflict`&&e(S)});var M=w(_,2),N=v(M),F=n=>{var r=zc(),c=v(r),u=e=>{Ac(e,()=>h(Ce),()=>!!h(we))};l(c,e=>{h(Ce)!==`note`&&e(u)});var d=w(c,2),f=e(d,!0);L(r),a(e=>t(f,e),[()=>o.fields.title||i.id.split(`/`).at(-1)]),s(n,r)},R=e=>{var t=Bc(),n=v(t),r=e=>{Ac(e,()=>h(Ce),()=>!!h(we))};l(n,e=>{h(Ce)!==`note`&&e(r)});var c=w(n,4);ee(c),L(t),a(e=>{te(c,o.fields.title),T(c,`placeholder`,e)},[()=>i.id.split(`/`).at(-1)]),f(`input`,c,e=>o.setFields({title:e.currentTarget.value.replace(/\s*\n\s*/g,` `)})),f(`keydown`,c,e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())}),re(`blur`,c,()=>void ve()),s(e,t)},z=n=>{var r=Vc(),c=e(r);a(()=>t(c,`${i.id??``}.md${o.meta===null?`: the frontmatter cannot be read, so the file is shown as it is`:``}`)),s(n,r)};l(N,e=>{h(x)?e(F):h(g)?e(z,-1):e(R,1)});var ne=w(N,2),B=v(ne),H=v(B),ae=w(H,2);L(B),L(ne),L(M);var oe=w(M,2),se=e=>{lr(e,{get note(){return o},get kind(){return h(Ce)},get done(){return h(we)},get marking(){return h(De)},onmark:()=>void Oe()})};l(oe,e=>{!h(g)&&!h(x)&&e(se)});var W=w(oe,2),ce=e=>{var t=Hc(),n=v(t);{let e=k(()=>h(O)?je(h(O)):null);Ve(n,{get moments(){return h(P)},strata:!0,get at(){return h(e)},get pointed(){return h(D)},point:e=>I(D,e),pick:de})}L(t),s(e,t)};l(W,e=>{h(C)&&!h(g)&&!h(x)&&e(ce)});var le=w(W,2),fe=r=>{var i=Wc(),c=d(i),u=v(c),p=e(u),m=w(u,4),g=n=>{var r=Uc(),i=e(r,!0);a(()=>t(i,h(j))),s(n,r)};l(m,e=>{h(j)&&e(g)});var _=w(m,2),y=w(_,2);L(c);var b=w(c,2);n(b,()=>je(h(O)),e=>{kc(e,{get id(){return o.id},get text(){return h(U).text},get title(){return o.fields.title},get touched(){return h(U).touched},get asked(){return h(U).asked},get offered(){return h(U).offered}})}),a((e,n)=>{t(p,`${e??``} · ${n??``}`),_.disabled=h(A)||h(U).text===o.text},[()=>Me(h(O)),()=>Fe(h(O).at)]),f(`click`,_,pe),f(`click`,y,()=>I(O,null)),s(r,i)};l(le,e=>{h(O)&&h(U)&&e(fe)});var me=w(le,2),G=n=>{var r=Gc();let i;var o=v(r),c=w(o,2),l=e(c,!0);L(r),a(()=>{i=y(r,``,i,{top:`${h(Re).top??``}px`,left:`${h(Re).left??``}px`}),t(l,h(ze)?`copied`:`copy for a terminal`)}),f(`pointerdown`,o,e=>{e.preventDefault(),He()}),f(`click`,o,e=>{e.detail===0&&He()}),f(`pointerdown`,c,e=>{e.preventDefault(),Be()}),f(`click`,c,e=>{e.detail===0&&Be()}),s(n,r)};l(me,e=>{h(Re)&&e(G)});var he=w(me,2),ge=v(he);n(ge,()=>`${h(g)}${h(x)}`,e=>{wc(e,{get note(){return o},get iso(){return c},get source(){return h(g)},get reading(){return h(x)},get touched(){return h(ie)},get lens(){return h(ue)}})}),L(he);var _e=w(he,2),ye=n=>{var r=Jc();p(r,21,()=>h(Te),e=>e.id,(n,r)=>{var i=qc(),o=v(i);let c;var u=v(o);Ac(u,()=>h(r).kind??`question`,()=>!!h(r).done);var d=w(u),f=e(d,!0),p=w(d),m=e=>{var t=Kc();s(e,t)};l(p,e=>{h(r).done&&e(m)}),L(o),L(i),a(e=>{T(o,`href`,e),c=V(o,1,`svelte-18ltlst`,null,c,{done:!!h(r).done&&h(r).kind===`question`}),t(f,h(r).title)},[()=>Ee(h(r).id)]),s(n,i)}),L(r),s(n,r)};l(_e,e=>{h(Te).length&&!h(g)&&!h(O)&&!h(x)&&e(ye)});var be=w(_e,2),Se=n=>{var r=Yc(),i=w(v(r),2),o=e(i),l=w(i,4),u=w(l,2);L(r),a(()=>{t(o,`${c.changes.length??``} ${c.changes.length===1?`change`:`changes`} from ${h(xe)??``} waiting`),l.disabled=c.busy===`all`,u.disabled=c.busy===`all`}),f(`click`,l,()=>c.settleAll(!0)),f(`click`,u,()=>c.settleAll(!1)),s(n,r)};l(be,e=>{c.changes.length&&e(Se)}),a(e=>{T(H,`aria-pressed`,h(x)),H.disabled=h(g),T(ae,`aria-pressed`,h(g)),ae.disabled=o.meta===null,T(he,`hidden`,e)},[()=>!!(h(O)&&h(U))]),f(`click`,H,()=>I(b,!h(b))),f(`click`,ae,()=>{I(b,!1),I(u,!h(u))}),s(r,m)};l(Ge,e=>{o.loaded===`loading`?e(Ke):o.loaded===`missing`?e(qe,1):o.loaded===`error`?e(Je,2):e(Ye,-1)}),L(Ue),M(Ue,e=>I(Le,e),()=>h(Le)),a(()=>We=V(Ue,1,`note svelte-18ltlst`,null,We,{reading:h(x),timed:h(C)&&o.loaded===`ready`&&!h(g)&&!h(x)})),s(r,Ue),S()}o([`click`,`input`,`keydown`,`pointerdown`]);function $c(e,t){N(t,!0);let r=k(()=>nt.params.id??``),i=k(()=>!h(r).startsWith(`@`)&&W(h(r))!==null&&!G.listing.notes.some(e=>e.id===h(r)));var a=c(),o=d(a);n(o,()=>h(r),e=>{var t=c(),n=d(t),a=e=>{Ln(e,{get path(){return h(r)}})},o=e=>{Qc(e,{get id(){return h(r)}})};l(n,e=>{h(i)?e(a):e(o,-1)}),s(e,t)}),s(e,a),S()}export{$c as component};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"../chunks/AnnzTlE8.js";import"../chunks/xihTtKlq.js";import{t as e}from"../chunks/BHORylQC.js";import"../chunks/C7qBBO-i.js";function t(t){e(t,{})}export{t as component};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,A as t,F as n,K as r,L as i,M as a,P as o,Q as s,R as c,T as l,V as u,Z as d,_ as f,ct as p,et as m,f as h,ft as g,ht as _,i as v,it as y,lt as b,pt as x,s as S,v as C}from"../chunks/AnnzTlE8.js";import"../chunks/xihTtKlq.js";import{a as w,i as T,n as E}from"../chunks/CSTv2fL0.js";import"../chunks/C7qBBO-i.js";var D=n(`<svg class="logo" viewBox="-0.4 -9.5 32.4 9.9" role="img" aria-label="isorite"><path 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"></path><path class="iso" d="M2 -9.05l1.2 1.2l-1.2 1.2l-1.2 -1.2z"></path><path class="right" d="M20.4 -9.05l1.2 1.2l-1.2 1.2l-1.2 -1.2z"></path></svg>`);function O(e,t){let n=v(t,`width`,3,72);var i=D();r(()=>{h(i,`width`,n()),h(i,`height`,n()*9.9/32.4)}),a(e,i)}var k=o(`<button type="button" role="radio"> </button>`),A=o(`<div class="swatch svelte-h119xx"><i class="svelte-h119xx"></i><span> </span></div>`),j=o(`<div class="swatch svelte-h119xx"><i class="svelte-h119xx"></i><span> </span></div> <div class="swatch svelte-h119xx"><i class="svelte-h119xx"></i><span> </span></div>`,1),M=o(`<!><!>`,1),N=o(`<div class="parts svelte-h119xx"><section class="svelte-h119xx"><h2 class="label svelte-h119xx">the ground</h2> <div class="row svelte-h119xx" role="radiogroup" aria-label="Ground"></div></section> <section class="svelte-h119xx"><h2 class="label svelte-h119xx">the name</h2> <div class="row svelte-h119xx"><!><!></div></section> <section class="svelte-h119xx"><h2 class="label svelte-h119xx">colour</h2> <div class="swatches svelte-h119xx"></div> <div class="swatches svelte-h119xx"></div> <div class="swatches svelte-h119xx"></div></section> <section class="svelte-h119xx"><h2 class="label svelte-h119xx">type</h2> <p class="pixel">Departure Mono, for display</p> <p>Ioskeley Mono, for the interface. <b>Bold.</b> <i>Italic.</i> 0123456789</p> <p class="serif">Charter, for what is read: the entropy of a source is the average surprise of its symbols. <b>Bold</b>, <i>italic</i>.</p></section> <section class="svelte-h119xx"><h2 class="label svelte-h119xx">buttons and chips</h2> <div class="row svelte-h119xx"><button class="btn" type="button">plain</button> <button class="btn primary" type="button">primary</button> <button class="btn danger" type="button">delete</button> <button class="btn quiet" type="button">quiet</button> <button class="btn" type="button" disabled="">off</button> <button class="btn tall primary" type="button">tall</button></div> <div class="row svelte-h119xx"><button class="btn keep" type="button">keep</button> <button class="btn edit" type="button">edit</button> <button class="btn remove" type="button">remove</button></div> <div class="row svelte-h119xx"><span class="chip">plain</span><span class="chip lattice">lattice</span><span class="chip growth">growth</span> <span class="chip malachite">malachite</span><span class="chip rose">rose</span></div></section> <section class="svelte-h119xx"><h2 class="label svelte-h119xx">crystals (M24, I): growing while Iso works, at 28 and 88; at rest, a conversation's mark</h2> <div class="row crystals svelte-h119xx"><!><!><!><!></div> <div class="row crystals rest svelte-h119xx"></div></section> <section class="svelte-h119xx"><h2 class="label svelte-h119xx">a frame, a field, the marks</h2> <div class="frame box svelte-h119xx"><span class="frame-title">a frame</span> <input class="field" placeholder="a field" aria-label="A field"/> <div class="row svelte-h119xx"><i class="sq"></i><span>you</span><i class="sq empty"></i><span>not yet</span><i class="dia"></i><span>Iso</span><i class="dia open"></i><span>Iso, unkept</span></div></div> <div class="dots ground svelte-h119xx"></div></section></div>`);function P(n,i){b(i,!1);let o=[`ground-0`,`ground-1`,`ground-2`,`ground-3`,`line`,`line-strong`],v=[`text`,`text-soft`,`text-faint`],D=[`lattice`,`growth`,`malachite`,`rose`];S();var P=N(),F=d(P),I=m(d(F),2);l(I,5,()=>E,([e,t])=>e,(n,i)=>{var o=y(()=>_(u(i),2));let s=()=>u(o)[0],l=()=>u(o)[1];var d=k();let f;var p=e(d,!0);r(()=>{f=C(d,1,`btn`,null,f,{primary:T.chosen===s()}),h(d,`aria-checked`,T.chosen===s()),t(p,l())}),c(`click`,d,()=>T.choose(s())),a(n,d)}),x(I),x(F);var L=m(F,2),R=m(d(L),2),z=d(R);O(z,{width:216}),O(m(z),{}),x(R),x(L);var B=m(L,2),V=m(d(B),2);l(V,5,()=>o,e=>e,(n,i)=>{var o=A(),s=d(o);let c;var l=m(s),p=e(l,!0);x(o),r(()=>{c=f(s,``,c,{background:`var(--${u(i)})`}),t(p,u(i))}),a(n,o)}),x(V);var H=m(V,2);l(H,5,()=>v,e=>e,(n,i)=>{var o=A(),s=d(o);let c;var l=m(s),p=e(l,!0);x(o),r(()=>{c=f(s,``,c,{background:`var(--${u(i)})`}),t(p,u(i))}),a(n,o)}),x(H);var U=m(H,2);l(U,5,()=>D,e=>e,(n,i)=>{var o=j(),c=s(o),l=d(c);let p;var h=m(l),g=e(h,!0);x(c);var _=m(c,2),v=d(_);let y;var b=m(v),S=e(b);x(_),r(()=>{p=f(l,``,p,{background:`var(--${u(i)})`}),t(g,u(i)),y=f(v,``,y,{background:`var(--${u(i)}-soft)`}),t(S,`${u(i)??``}-soft`)}),a(n,o)}),x(U),x(B);var W=m(B,2),G=m(d(W),2);f(G,``,{},{"font-size":`22px`});var K=m(G,4);f(K,``,{},{"font-size":`18px`}),x(W);var q=m(W,4),J=m(d(q),2),Y=d(J);w(Y,{id:`a`,size:28,growing:!0});var X=m(Y);w(X,{id:`a`,size:88,growing:!0});var Z=m(X);w(Z,{id:`b`,size:88,growing:!0});var Q=m(Z);w(Q,{id:`c`,size:88,growing:!0}),x(J);var $=m(J,2);l($,4,()=>[`a`,`b`,`c`,`d`,`e`,`f`,`g`,`h`],e=>e,(e,t)=>{var n=M(),r=s(n);w(r,{get id(){return t},size:44});var i=m(r);w(i,{get id(){return t},size:20}),a(e,n)}),x($),x(q),g(2),x(P),a(n,P),p()}i([`click`]);export{P as component};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(){function e(e){let{W:t,H:n,items:r}=e,i=new Int8Array(t*n),a=new Uint8Array(t*n),o=new Int32Array(t*n).fill(-1),s=new Int32Array(t*n).fill(-1),c=r.map((e,t)=>t).filter(e=>r[e].kind===`folder`).sort((e,t)=>r[e].depth-r[t].depth||e-t);for(let e of c){let n=r[e];for(let r=n.gy;r<n.gy+n.h;r++)for(let a=n.gx;a<n.gx+n.w;a++)i[r*t+a]=n.depth,o[r*t+a]=e}r.forEach((e,n)=>{if(e.kind===`note`)for(let r=e.gy;r<e.gy+e.h;r++)for(let i=e.gx;i<e.gx+e.w;i++)a[r*t+i]=1,s[r*t+i]=n});let l=new Uint8Array(t*n),u=e.keep??2,d=(e,r,i,a)=>{for(let o=Math.max(0,r);o<Math.min(n,a);o++)for(let n=Math.max(0,e);n<Math.min(t,i);n++)l[o*t+n]=1};for(let e of r)e.kind===`note`?d(e.gx-u,e.gy-u,e.gx+e.w+u,e.gy+e.h+u):(d(e.gx-u,e.gy-u,e.gx+e.w+u,e.gy+u),d(e.gx-u,e.gy+e.h-u,e.gx+e.w+u,e.gy+e.h+u),d(e.gx-u,e.gy-u,e.gx+u,e.gy+e.h+u),d(e.gx+e.w-u,e.gy-u,e.gx+e.w+u,e.gy+e.h+u));return{W:t,H:n,elev:i,blocked:a,owner:o,noteAt:s,close:l}}function t(e,t){let n=e[t].kind===`folder`?[t]:[];for(let r=e[t].parent;r>=0;r=e[r].parent)n.push(r);return n}let n={bend:4,flow:1,area:.01,aspect:1,shape:1,effort:1e3,seed:0,cross:20,stay:5};function r(e,t,r,c,l={}){let{bend:u,flow:d,area:f,aspect:p,shape:m,effort:h,seed:g,cross:_,stay:v}={...n,...l},y=e.length,b=e.map(e=>e[0]),x=e.map(e=>e[1]);if(!y)return{x:[],y:[],w:0,h:0};let S=Array.from({length:y},(e,t)=>Array.from({length:y},(e,n)=>r(t,n))),C=new Float64Array(y),w=new Float64Array(y),T=[...Array(y).keys()],E=[...T],D=new Int32Array(y),O=new Int32Array(y),k=0,A=0,j=()=>{T.forEach((e,t)=>{D[e]=t}),E.forEach((e,t)=>{O[e]=t}),k=0,A=0;for(let e=0;e<y;e++){let t=T[e],n=0,r=0;for(let i=0;i<e;i++){let e=T[i];O[e]<O[t]?n=Math.max(n,C[e]+b[e]+S[e][t]):r=Math.max(r,w[e]+x[e]+S[e][t])}C[t]=n,w[t]=r,k=Math.max(k,n+b[t]),A=Math.max(A,r+x[t])}},M=e=>[C[e]+b[e]/2,w[e]+x[e]/2],N=()=>{j();let e=0;for(let[n,r,i]of t){let t=Math.max(0,C[r]-C[n]-b[n],C[n]-C[r]-b[r]),a=Math.max(0,w[r]-w[n]-x[n],w[n]-w[r]-x[r]);e+=i*(Math.max(t,a)+.414*Math.min(t,a)+(t>0&&a>0?u:0));let o=c===`right`?C[n]+b[n]/2-(C[r]+b[r]/2):w[r]+x[r]/2-(w[n]+x[n]/2);o>0&&(e+=d*i*o)}if(_)for(let n=0;n<t.length;n++)for(let r=n+1;r<t.length;r++){let[i,o,s]=t[n],[c,l,u]=t[r];i!==c&&i!==l&&o!==c&&o!==l&&a(M(i),M(o),M(c),M(l))&&(e+=_*Math.min(s,u))}if(F)for(let t=0;t<y;t++)for(let n=t+1;n<y;n++)(D[t]<D[n]!=F[0][t]<F[0][n]||O[t]<O[n]!=F[1][t]<F[1][n])&&(e+=v);let n=Math.log(k/A/m);return e+f*k*A*(1+p*n*n)},P=i(y,t);if(T.sort((e,t)=>P[e]-P[t]),E.splice(0,y,...T),c===`up`&&T.reverse(),l.pair)return T.splice(0,y,...l.pair[0]),E.splice(0,y,...l.pair[1]),j(),{x:[...C],y:[...w],w:k,h:A,pair:l.pair};let F=null;l.start&&(T.splice(0,y,...l.start[0]),E.splice(0,y,...l.start[1]),F=[new Int32Array(y),new Int32Array(y)],T.forEach((e,t)=>{F[0][e]=t}),E.forEach((e,t)=>{F[1][e]=t}));let I=N(),L=I,R=[...T],z=[...E];if(y<2)return j(),{x:[...C],y:[...w],w:k,h:A,pair:[[...T],[...E]]};let B=s(o(e,t)^g),V=h*y,H=l.start?Math.max(.5,I*.002):Math.max(1,I*.05),U=.001**(1/V);for(let e=0;e<V;e++,H*=U){let e=Math.floor(B()*y),t=(e+1+Math.floor(B()*(y-1)))%y,n=B(),r=n=>{let r=n[e];n[e]=n[t],n[t]=r};if(n<.4)r(T);else if(n<.8)r(E);else{let n=T.indexOf(E[e]),i=T.indexOf(E[t]);r(E);let a=T[n];T[n]=T[i],T[i]=a}let i=N();if(i<=I||B()<Math.exp((I-i)/H))I=i,I<L&&(L=I,R=[...T],z=[...E]);else if(n<.4)r(T);else if(n<.8)r(E);else{let n=T.indexOf(E[e]),i=T.indexOf(E[t]);r(E);let a=T[n];T[n]=T[i],T[i]=a}}return T.splice(0,y,...R),E.splice(0,y,...z),j(),{x:[...C],y:[...w],w:k,h:A,cost:L,pair:[R,z]}}function i(e,t){let n=Array(e).fill(0);for(let[e,r,i]of t)n[e]+=i,n[r]-=i;let r=[...Array(e).keys()].sort((e,t)=>n[t]-n[e]||e-t),i=Array(e);return r.forEach((e,t)=>{i[e]=t}),i}function a(e,t,n,r){let i=(e,t,n)=>(t[0]-e[0])*(n[1]-e[1])-(t[1]-e[1])*(n[0]-e[0]);return i(e,t,n)*i(e,t,r)<0&&i(n,r,e)*i(n,r,t)<0}function o(e,t){let n=2166136261;for(let r of[...e.flat(),...t.flat()])n^=r|0,n=Math.imul(n,16777619);return n>>>0}function s(e){return()=>{e|=0,e=e+1831565813|0;let t=Math.imul(e^e>>>15,1|e);return t=t+Math.imul(t^t>>>7,61|t)^t,((t^t>>>14)>>>0)/4294967296}}let c={cell:7,note:[18,11],gap:6,gapFolders:8,channel:6,channelFolders:8,pad:6,head:2,margin:8,minFolder:12,slant:8,keep:2},l={fine:c,coarse:{cell:14,note:[9,6],gap:3,gapFolders:6,channel:3,channelFolders:6,pad:3,head:1,margin:6,minFolder:6,slant:4,keep:1},coarser:{cell:18,note:[7,4],gap:2,gapFolders:5,channel:2,channelFolders:5,pad:2,head:1,margin:5,minFolder:5,slant:3,keep:1}};c.pad;let u=1.4,d=c.note,f=0,p=0,m=0,h=0,g=0,_=0,v=0,y=0,b=0,x=2,S=0,C=0;function w(e){({note:d,gap:f,gapFolders:p,channel:m,channelFolders:h,head:g,margin:_,minFolder:v,slant:y,pad:b,keep:x}=e),S=d[0]+f,C=3*S}function T(e,{flow:t=`up`,grain:i=`fine`,plan:a=!1,planCosts:o={},planned:s=null,from:T=null}={}){let O=l[i]??c;w(O);let k=e=>e.kind===`dir`,A=/* @__PURE__ */ new Map,j=/* @__PURE__ */ new Map,M=[e.root];for(let e=0;e<M.length;e++)for(let t of M[e].children||[])A.set(t,M[e]),k(t)?M.push(t):j.set(t.ref,t);let N=e=>{let t=[];for(let n=e;n;n=A.get(n))t.push(n);return t.reverse()},P=new Map(M.map(e=>[e,/* @__PURE__ */ new Map])),F=/* @__PURE__ */ new Map;for(let e of M){F.set(e,F.size);for(let t of e.children||[])k(t)||F.set(t,F.size)}let I=new Map(j);if(e.code)for(let t of M)t!==e.root&&!I.has(t.ref)&&I.set(t.ref,t);for(let[t,n,r]of e.edges){if(r<2)continue;let e=I.get(t),i=I.get(n);if(!e||!i||e===i)continue;let a=N(e),o=N(i),s=0;for(;a[s+1]&&a[s+1]===o[s+1];)s++;if(!a[s+1]||!o[s+1])continue;let c=P.get(a[s]),l=o[s+1],u=a[s+1],d=F.get(l)+`|`+F.get(u),f=c.get(d)||{p:l,q:u,weight:0,count:0};f.weight+=r,f.count++,c.set(d,f)}let L=/* @__PURE__ */ new Map,R=/* @__PURE__ */ new Map,z={},B=/* @__PURE__ */ new Map,V=e=>e===`up`?`right`:`up`,H=(t,n)=>{let r=t.children||[];for(let e of r)k(e)?H(e,V(n)):L.set(e,{w:d[0],h:d[1]});let i=r.length?U(t,r,n):{w:0,h:0};L.set(t,t===e.root?i:r.length?{w:Math.max(v,i.w+2*b),h:i.h+b+g+b}:{w:v,h:g+2*b})};function U(e,t,n){if(a&&t.some(k))return W(e,t,n);let r=new Map(t.map(e=>[e,e])),i=e=>{for(;r.get(e)!==e;)e=r.get(e);return e};for(let t of P.get(e).values()){let e=i(t.p),n=i(t.q);e!==n&&r.set(n,e)}let o=/* @__PURE__ */ new Map,s=new Set([...P.get(e).values()].flatMap(e=>[e.p,e.q]));for(let e of t){let t=s.has(e)?i(e):null;o.set(t,[...o.get(t)||[],e])}if(o.size<2){let r=G(e,t,n);return B.set(e,r.out),{w:r.w,h:r.h}}let c=[...o].map(([t,r],i)=>({list:r,loose:t===null,k:i,...G(e,r,n)}));c.sort((e,t)=>e.loose-t.loose||t.w*t.h-e.w*e.h||e.k-t.k);let l=t.some(k)?p:f,d=c.reduce((e,t)=>e+(t.w+l)*(t.h+l),0),m=Math.max(Math.ceil(Math.sqrt(d*u)),...c.map(e=>e.w)),h=0,g=0,_=0,v=0,y=[];for(let e of c){h&&h+e.w>m&&(h=0,g+=_+l,_=0);for(let t of e.list){let e=L.get(t);e.x+=h,e.y+=g}for(let t of e.out)y.push({...t,pts:t.pts&&t.pts.map(([e,t])=>[e+h,t+g])});v=Math.max(v,h+e.w),_=Math.max(_,e.h),h+=e.w+l}return B.set(e,y),{w:v,h:g+_}}function W(t,i,a){let c=new Map(i.map((e,t)=>[e,t])),l=[...P.get(t).values()].filter(e=>c.has(e.p)&&c.has(e.q)),u=t===e.root?``:t.ref,d=s?.get(u),m=(e,t)=>d?.wider.get([i[e].ref,i[t].ref].sort().join(`|`))??0,h=(e,t)=>(k(i[e])||k(i[t])?p:f)+m(e,t),g=i.map(e=>[L.get(e).w,L.get(e).h]),_=t===e.root&&a===`up`?1/n.shape:n.shape,v,y=!d&&T?.[u];if(y){let e=new Map(i.map((e,t)=>[e.ref,t])),t=i.map((e,t)=>t).filter(e=>!y[0].includes(i[e].ref));v=y.map(n=>[...n.filter(t=>e.has(t)).map(t=>e.get(t)),...t])}let b=r(g,l.map(e=>[c.get(e.p),c.get(e.q),e.count]),h,a,{shape:_,...o,pair:d?.pair,start:v});R.set(u,b.pair),z[u]=b.pair.map(e=>e.map(e=>i[e].ref)),i.forEach((e,t)=>Object.assign(L.get(e),{x:b.x[t],y:b.y[t]}));let x=e=>a===`right`?b.x[e]+g[e][0]/2:-(b.y[e]+g[e][1]/2),S=/* @__PURE__ */ new Map;for(let e of l)S.set(e.p,[...S.get(e.p)||[],e.q]);let C=(e,t)=>{let n=/* @__PURE__ */ new Set,r=(S.get(e)||[]).filter(e=>e!==t);for(;r.length;){let e=r.pop();if(e===t)return!0;n.has(e)||(n.add(e),r.push(...S.get(e)||[]))}return!1};return B.set(t,l.map(e=>({p:e.p,q:e.q,count:e.count,back:x(c.get(e.p))>x(c.get(e.q)),implied:!k(e.p)&&!k(e.q)&&C(e.p,e.q),pts:null}))),{w:b.w,h:b.h}}function G(e,t,n){let r=t.length,i=new Map(t.map((e,t)=>[e,t])),a=n===`up`,o=t.some(k)?p:f,s=t.map(e=>a?L.get(e).h:L.get(e).w),c=t.map(e=>a?L.get(e).w:L.get(e).h),l=[...P.get(e).values()].filter(e=>i.has(e.p)&&i.has(e.q)).map(e=>({...e,p:i.get(e.p),q:i.get(e.q)})),d=D(r,l.map(e=>[e.p,e.q,e.weight]));for(let e of l)e.back=d[e.p]>d[e.q],e.u=e.back?e.q:e.p,e.v=e.back?e.p:e.q;let g=l.filter(e=>!e.back),_=Array(r).fill(0),v=t.map(()=>[]),b=t.map(()=>[]);for(let e of l)v[e.v].push(e.u),b[e.u].push(e.v);let w=t.map(()=>[]);for(let e of g)w[e.p].push(e.q);for(let e of[...Array(r).keys()].sort((e,t)=>d[e]-d[t]))for(let t of v[e])_[e]=Math.max(_[e],_[t]+1);for(let e=0;e<r;e++)!v[e].length&&b[e].length&&(_[e]=Math.min(...b[e].map(e=>_[e]))-1);let T=(e,t,n)=>{let r=/* @__PURE__ */ new Set,i=w[e].filter(e=>e!==n);for(;i.length;){let e=i.pop();if(e===t)return!0;r.has(e)||(r.add(e),i.push(...w[e]))}return!1};for(let e of g)e.implied=!k(t[e.p])&&!k(t[e.q])&&T(e.p,e.q,e.q);let E=l.filter(e=>!e.implied).sort((e,t)=>t.weight-e.weight||e.p-t.p||e.q-t.q),O=t.reduce((e,t,n)=>e+(c[n]+o)*(s[n]+m),0),A=Math.max(Math.ceil(Math.sqrt(a?O*u:O/u)),...c),j=[],M=Array(r),N=Array(r).fill(!1);for(let e of l)N[e.p]=!0,N[e.q]=!0;let F=N.some(Boolean)&&N.some(e=>!e),I=e=>{let t=e.reduce((e,t)=>e+c[t]+o,0),n=Math.max(1,Math.ceil((t-o)/A)),r=t/n,i=null,a=0;for(let t of e)(!i||a+c[t]>A||j.length-R<n&&a>=r)&&(i=[],j.push(i),a=0),M[t]=j.length-1,i.push(t),a+=c[t]+o},R=0,z=e=>v[e].length?+!!b[e].length:2,B=e=>e.length?e.reduce((e,t)=>e+d[t],0)/e.length:0;for(let e=0;e<=Math.max(..._);e++){let t=[...Array(r).keys()].filter(t=>_[t]===e&&(N[t]||!F));t.reduce((e,t)=>e+c[t]+o,0)-o>A&&t.sort((e,t)=>z(e)-z(t)||B(v[e])-B(v[t])||e-t),R=j.length,I(t)}F&&(R=j.length,I([...Array(r).keys()].filter(e=>!N[e])));let V=[...c],H=t.map(()=>[]),U=t.map(()=>[]),W=/* @__PURE__ */ new Map,G=/* @__PURE__ */ new Map,K=[],q=/* @__PURE__ */ new Set,ee=/* @__PURE__ */ new Map;for(let e of E){let t=[e.u];for(let n=M[e.u]+1;n<M[e.v];n++){let r=e.u+`|`+n;W.has(r)||(W.set(r,V.length),G.set(V.length,e.u),V.push(1),H.push([]),U.push([]),M.push(n),j[n].push(V.length-1)),t.push(W.get(r))}t.push(e.v);for(let e=1;e<t.length;e++){let n=t[e-1],r=t[e];q.has(n+`|`+r)||(q.add(n+`|`+r),K.push([n,r]),U[n].push(r),H[r].push(n))}ee.set(e,t)}let J=e=>e>=r,Y=Array(V.length);j.forEach(e=>e.forEach((e,t)=>{Y[e]=t}));let X=(e,t)=>{let n=new Map(j[e].map(e=>[e,t[e].length?t[e].reduce((e,t)=>e+Y[t],0)/t[e].length:Y[e]]));j[e].sort((e,t)=>n.get(e)-n.get(t)||Y[e]-Y[t]),j[e].forEach((e,t)=>{Y[e]=t})},te=()=>{let e=0;for(let t=0;t<j.length-1;t++){let n=[];for(let e of j[t])for(let t of U[e])n.push([Y[e],Y[t]]);for(let t=0;t<n.length;t++)for(let r=t+1;r<n.length;r++)(n[t][0]-n[r][0])*(n[t][1]-n[r][1])<0&&e++}return e},Z=()=>{let e=(e,t,n)=>{let r=0;for(let i of n[e])for(let e of n[t])r+=Y[i]>Y[e]?1:Y[i]<Y[e]?-1:0;return r};for(let t=!0,n=0;t&&n<8;n++){t=!1;for(let n of j)for(let r=0;r+1<n.length;r++){let i=n[r],a=n[r+1];e(i,a,H)+e(i,a,U)>0&&(n[r]=a,n[r+1]=i,Y[i]=r+1,Y[a]=r,t=!0)}}},ne=j.map(e=>[...e]),re=(e,t)=>(J(e)?d[G.get(e)]:d[e])-(J(t)?d[G.get(t)]:d[t])||e-t,ie=null,ae=1/0;for(let e of[e=>e,e=>[...e].sort(re),e=>[...e].reverse()]){j.forEach((t,n)=>{t.splice(0,t.length,...e(ne[n])),t.forEach((e,t)=>{Y[e]=t})});let t=1/0,n=0;for(let e=0;e<24&&n<4&&ae>0;e++,n++){if(e%2==0)for(let e=1;e<j.length;e++)X(e,H);else for(let e=j.length-2;e>=0;e--)X(e,U);Z();let r=te();r<t&&(t=r,n=0),r<ae&&(ae=r,ie=j.map(e=>[...e]))}}ie&&j.forEach((e,t)=>{e.splice(0,e.length,...ie[t]),e.forEach((e,t)=>{Y[e]=t})});let Q=(e,t)=>J(e)&&J(t)?1:J(e)||J(t)?x:o,$=Array(V.length).fill(0);for(let e of j){let t=0;e.forEach((n,r)=>{r&&(t+=Q(e[r-1],n)),$[n]=t,t+=V[n]})}let oe=e=>e.length?$[e[e.length-1]]+V[e[e.length-1]]:0,se=Math.max(...j.map(oe));for(let e of j){let t=(se-oe(e))/2;for(let n of e)$[n]+=t}let ce=e=>$[e]+V[e]/2;for(let e=0;e<12;e++)for(let t of e%2?[...j].reverse():j){if(!t.length)continue;let e=t.map(e=>{let t=[...H[e],...U[e]];return(t.length?t.reduce((e,t)=>e+ce(t),0)/t.length:ce(e))-V[e]/2}),n=[],r=[];t.forEach((r,i)=>{n[i]=i?Math.max(e[i],n[i-1]+V[t[i-1]]+Q(t[i-1],r)):e[i]});for(let n=t.length-1;n>=0;n--)r[n]=n<t.length-1?Math.min(e[n],r[n+1]-V[t[n]]-Q(t[n],t[n+1])):e[n];t.forEach((e,t)=>{$[e]=(n[t]+r[t])/2})}let le=e=>Math.floor((V[e]-1)/2),ue=Array(V.length).fill(-1),de=Array(V.length).fill(-1);for(let e of[!0,!1])for(let t=1;t<j.length;t++){let n=j[t].filter(e=>ue[e]>=0).map(e=>[Y[ue[e]],Y[e]]);for(let r of j[t]){if(ue[r]>=0||!H[r].length)continue;let t=[...H[r]].sort((e,t)=>Y[e]-Y[t]),i=(t.length-1)/2,a=t.map((e,t)=>[e,Math.abs(t-i)]).filter(([t])=>de[t]<0&&(!e||J(t)&&J(r))&&Math.abs($[t]+le(t)-$[r]-le(r))<=(e?C:S)).sort((e,t)=>e[1]-t[1]||Y[e[0]]-Y[t[0]]);for(let[e]of a)if(!n.some(([t,n])=>t<Y[e]!=n<Y[r])){ue[r]=e,de[e]=r,n.push([Y[e],Y[r]]);break}}}let fe=Array(V.length).fill(-1),pe=0;for(let e=0;e<V.length;e++)if(ue[e]<0){for(let t=e;t>=0;t=de[t])fe[t]=pe;pe++}let me=Array.from({length:pe},()=>[]);fe.forEach((e,t)=>me[e].push(t));let he=(e,t)=>V[e]-le(e)+Q(e,t)+le(t),ge=Array(V.length).fill(-1),_e=Array(V.length).fill(-1);for(let e of j)e.forEach((t,n)=>{n&&(ge[t]=e[n-1],_e[e[n-1]]=t)});let ve=Array(pe).fill(0),ye=!1;for(let e=0;e<=pe&&!ye;e++){ye=!0;for(let e of j)for(let t=1;t<e.length;t++){let n=ve[fe[e[t-1]]]+he(e[t-1],e[t]);ve[fe[e[t]]]<n&&(ve[fe[e[t]]]=n,ye=!1)}}if(ye){let e=me.map(e=>Math.round(e.reduce((e,t)=>e+$[t]+le(t),0)/e.length)),t=Math.min(...e.map((e,t)=>e-ve[t])),n=[...Array(pe).keys()].sort((t,n)=>e[n]-e[t]||t-n);for(let r=0;r<24;r++){let i=!1;for(let a of r%2?[...n].reverse():n){let n=-1/0,r=1/0;for(let e of me[a])ge[e]>=0&&(n=Math.max(n,ve[fe[ge[e]]]+he(ge[e],e))),_e[e]>=0&&(r=Math.min(r,ve[fe[_e[e]]]-he(e,_e[e])));let o=Math.max(n,Math.min(r,e[a]-t));o!==ve[a]&&(ve[a]=o,i=!0)}if(!i)break}for(let e=0;e<V.length;e++)$[e]=ve[fe[e]]-le(e)}else for(let e of j)e.forEach((t,n)=>{$[t]=n?Math.max(Math.round($[t]),$[e[n-1]]+V[e[n-1]]+Q(e[n-1],t)):Math.round($[t])});let be=Math.min(...$);for(let e=0;e<$.length;e++)$[e]-=be;let xe=Math.max(...$.map((e,t)=>e+V[t])),Se=e=>$[e]+Math.floor((V[e]-1)/2)+.5,Ce=/* @__PURE__ */ new Map;for(let e=0;e<V.length;e++){let t=[...H[e]].sort((e,t)=>Se(e)-Se(t)),n=$[e]+.5,r=$[e]+V[e]-.5;if(t.length>V[e]){t.forEach((r,i)=>Ce.set(r+`|`+e,n+Math.min(V[e]-1,Math.floor(i*V[e]/t.length))));continue}let i=t.map(e=>Math.max(n,Math.min(r,Se(e))));for(let e=1;e<i.length;e++)i[e]=Math.max(i[e],i[e-1]+1);for(let e=i.length-1;e>=0;e--)i[e]=Math.min(i[e],e===i.length-1?r:i[e+1]-1);t.forEach((t,n)=>Ce.set(t+`|`+e,i[n]))}let we=(e,t)=>{let n=Ce.get(e+`|`+t);return n>=$[e]+.5&&n<=$[e]+V[e]-.5},Te=Array(V.length);for(let e=0;e<V.length;e++){let t=U[e].filter(t=>!we(e,t)).map(t=>Ce.get(e+`|`+t)).sort((e,t)=>e-t);Te[e]=t.length?Math.max($[e]+.5,Math.min($[e]+V[e]-.5,t[t.length-1>>1])):Se(e)}let Ee=(e,t)=>we(e,t)?Ce.get(e+`|`+t):Te[e],De=(e,t)=>{let n=Ee(e,t),r=Ce.get(e+`|`+t);return[Math.min(n,r),Math.max(n,r)]},Oe=/* @__PURE__ */ new Set,ke=j.map(()=>0);for(let[e,t]of K){if(we(e,t))continue;let[n,r]=De(e,t),i=Ce.get(e+`|`+t)>Te[e];r-n>y||K.every(([a,o])=>{if(M[a]!==M[e]||a===e&&o===t)return!0;let[s,c]=De(a,o);return a===e?i?c<=n:s>=r:c<n-1||s>r+1})&&(Oe.add(e+`|`+t),ke[M[e]]=Math.max(ke[M[e]],r-n))}let Ae=/* @__PURE__ */ new Map;for(let[e,t]of K){if(we(e,t)||Oe.has(e+`|`+t))continue;let n=Ce.get(e+`|`+t),r=Ae.get(e)||{u:e,lo:Te[e],hi:Te[e],track:0};r.lo=Math.min(r.lo,n),r.hi=Math.max(r.hi,n),Ae.set(e,r)}let je=j.map(()=>0);j.forEach((e,t)=>{let n=[...Ae.values()].filter(e=>M[e.u]===t&&e.hi>e.lo).sort((e,t)=>e.lo-t.lo||e.hi-t.hi||e.u-t.u),r=n.map(e=>U[e.u].filter(t=>!we(e.u,t)&&!Oe.has(e.u+`|`+t)).map(t=>Ce.get(e.u+`|`+t))),i=(e,t)=>!(n[e].hi<n[t].lo-1||n[t].hi<n[e].lo-1),a=(e,t)=>+(Te[n[t].u]>n[e].lo&&Te[n[t].u]<n[e].hi)+r[e].filter(e=>e>n[t].lo&&e<n[t].hi).length,o=[];for(let e=0;e<n.length;e++)for(let t=e+1;t<n.length;t++){if(!i(e,t))continue;let n=a(t,e)-a(e,t);n>0?o.push([e,t,n]):n<0&&o.push([t,e,-n])}let s=D(n.length,o),c=[];for(let e of[...n.keys()].sort((e,t)=>s[e]-s[t]))n[e].track=Math.max(0,...c.filter(t=>i(e,t)).map(e=>n[e].track+1)),c.push(e);je[t]=Math.max(0,...n.map(e=>e.track+1))});let Me=j.map(e=>Math.max(0,...e.filter(e=>!J(e)).map(e=>s[e]))),Ne=[],Pe=[],Fe=[],Ie=0;j.forEach((e,n)=>{Ne[n]=Ie,Ie+=Me[n];let r=Math.max(t.some(k)?h:m,je[n]+2*x,ke[n]+2);Pe[n]=Ie+Math.max(x,Math.floor((r-je[n])/2));let i=Ie;Fe[n]=e=>i+Math.floor((r-e)/2),n<j.length-1&&(Ie+=r)});let Le=Ie,Re=e=>Ne[M[e]]+Math.floor((Me[M[e]]-s[e])/2),ze=(e,t)=>a?[t,Le-e]:[e,t];t.forEach((e,t)=>Object.assign(L.get(e),a?{x:$[t],y:Le-Re(t)-s[t]}:{x:Re(t),y:$[t]}));let Be=[];for(let e of l){let n=ee.get(e),r=null;if(n){r=[ze(Re(e.u)+s[e.u],Ee(e.u,n[1]))];for(let e=1;e<n.length;e++){let t=n[e-1],i=n[e],a=Ce.get(t+`|`+i);if(Oe.has(t+`|`+i)){let e=Math.abs(a-Te[t]),n=Fe[M[t]](e);r.push(ze(n,Te[t]),ze(n+e,a));continue}let o=Pe[M[t]]+(Ae.get(t)?.track||0)+.5;r.push(ze(o,Ee(t,i)),ze(o,a))}r.push(ze(Re(e.v),Ce.get(n[n.length-2]+`|`+e.v))),r=r.filter((e,t)=>!t||e[0]!==r[t-1][0]||e[1]!==r[t-1][1]),e.back&&r.reverse()}Be.push({p:t[e.p],q:t[e.q],count:e.count,back:e.back,implied:!!e.implied,pts:r})}return a?{w:xe,h:Le,out:Be}:{w:Le,h:xe,out:Be}}H(e.root,t);let K=[],q=/* @__PURE__ */ new Map,ee=/* @__PURE__ */ new Map([[e.root,[_,_]]]);for(let t of M){let[n,r]=ee.get(t),i=t===e.root?-1:q.get(t),a=N(t).length;for(let e of t.children||[]){let t=L.get(e);q.set(e,K.length),K.push({id:e.id,ref:e.ref,kind:k(e)?`folder`:`note`,parent:i,depth:a,gx:n+t.x,gy:r+t.y,w:t.w,h:t.h}),k(e)&&ee.set(e,[n+t.x+b,r+t.y+g+b])}}let J=[],Y=/* @__PURE__ */ new Set;for(let e of M){let[t,n]=ee.get(e);for(let r of B.get(e)||[]){let e=q.get(r.q),i=q.get(r.p);r.back&&Y.add(e+`|`+i),J.push({a:e,b:i,count:r.count,back:r.back,implied:r.implied,pts:r.pts&&r.pts.map(([e,r])=>[e+t,r+n])})}}let X=E(K,e.edges,new Map([...j].map(([e,t])=>[e,q.get(t)]))),te=(e,t)=>{for(;K[e].parent!==t;)e=K[e].parent;return e};for(let e of X)e.placed=e.s>=2&&!Y.has(te(e.a,e.level)+`|`+te(e.b,e.level));let Z=L.get(e.root);return{W:Z.w+2*_,H:Z.h+2*_,flow:t,cell:O.cell,keep:O.keep,margin:_,items:K,links:X,trunks:J,pairs:R,orders:z}}function E(e,t,n){let r=t=>{let n=[];for(let r=e[t].parent;r>=0;r=e[r].parent)n.push(r);return n},i=[];for(let[e,a,o]of t){let t=n.get(e),s=n.get(a);if(t===void 0||s===void 0||t===s)continue;let c=new Set(r(s));i.push({a:t,b:s,s:o,level:r(t).find(e=>c.has(e))??-1,placed:!1})}return i}function D(e,t){let n=Array.from({length:e},()=>/* @__PURE__ */ new Map),r=Array.from({length:e},()=>/* @__PURE__ */ new Map);for(let[e,i,a]of t)e!==i&&(n[e].set(i,(n[e].get(i)||0)+a),r[i].set(e,(r[i].get(e)||0)+a));let i=e=>{let t=0;for(let n of e.values())t+=n;return t},a=/* @__PURE__ */ new Set([...Array(e).keys()]),o=[],s=[],c=(e,t)=>{a.delete(e),t.push(e);for(let t of n[e].keys())r[t].delete(e);for(let t of r[e].keys())n[t].delete(e)};for(;a.size;){let e=!0;for(;e;){e=!1;for(let t of[...a])r[t].size?n[t].size||(c(t,s),e=!0):(c(t,o),e=!0)}if(!a.size)break;let t=-1,l=-1/0;for(let e of a){let a=i(n[e])-i(r[e]);a>l&&(l=a,t=e)}c(t,o)}let l=Array(e);return[...o,...s.reverse()].forEach((e,t)=>{l[e]=t}),l}let O={climb:5,turn45:1.5,turn90:3,foreign:2.5,crowd:.2,near:0,hug:2.5,haste:3.2},k=[1,1,0,-1,-1,-1,0,1],A=[0,1,1,1,0,-1,-1,-1];function j(e,n,r={}){let{climb:i,turn45:a,turn90:o,foreign:s,crowd:c,near:l,hug:u,haste:d}={...O,...r},{W:f,H:p,elev:m,blocked:h,owner:g}=n,_=n.close||new Uint8Array(f*p),v=f*p,y=e.items,b=new Uint16Array(v),x=new Uint16Array(v),S=new Float32Array(v*9),C=new Int32Array(v*9),w=new Uint32Array(v*9),T=new Uint32Array(y.length),E=v*9,D=0,j=/* @__PURE__ */ new Float32Array(4096),M=/* @__PURE__ */ new Float32Array(4096),N=/* @__PURE__ */ new Int32Array(4096),P=0,F=(e,t,n)=>{if(P===j.length){let e=(e,t)=>{let n=new t(e.length*2);return n.set(e),n};j=e(j,Float32Array),M=e(M,Float32Array),N=e(N,Int32Array)}let r=P++;for(;r>0;){let t=r-1>>1;if(j[t]<=e)break;j[r]=j[t],M[r]=M[t],N[r]=N[t],r=t}j[r]=e,M[r]=t,N[r]=n},I=()=>{L=M[0],R=N[0];let e=j[--P],t=M[P],n=N[P],r=0;for(;;){let t=2*r+1;if(t>=P||(t+1<P&&j[t+1]<j[t]&&t++,j[t]>=e))break;j[r]=j[t],M[r]=M[t],N[r]=N[t],r=t}j[r]=e,M[r]=t,N[r]=n},L=0,R=0,z=(e,t)=>{b[e]+=t;let n=e%f,r=e/f|0;for(let e=Math.max(0,r-1);e<=Math.min(p-1,r+1);e++)for(let i=Math.max(0,n-1);i<=Math.min(f-1,n+1);i++)(i!==n||e!==r)&&(x[e*f+i]+=t)},B=e=>{let t=[],n=(e,n,r,i)=>{e>=0&&n>=0&&e<f&&n<p&&!h[n*f+e]&&t.push([n*f+e,r,i])};for(let t=e.gx;t<e.gx+e.w;t++)n(t,e.gy-1,t+.5,e.gy),n(t,e.gy+e.h,t+.5,e.gy+e.h);for(let t=e.gy;t<e.gy+e.h;t++)n(e.gx-1,t,e.gx,t+.5),n(e.gx+e.w,t,e.gx+e.w,t+.5);return t};function V(e,n,r,p,v,O,j=null){D++,P=0;for(let n of t(y,e))T[n]=D;if(j){T[j.folder]=D;for(let e of t(y,j.folder))T[e]=D}else for(let e of t(y,n))T[e]=D;let M=y[e],N=j?null:y[n],V=j?j.ends:new Map(B(N).map(e=>[e[0],e])),H,U,W,G;if(j?.toward!==void 0)H=U=j.toward%f,W=G=j.toward/f|0;else if(j){H=W=1/0,U=G=-1/0;for(let e of V.keys()){let t=e%f,n=e/f|0;H=Math.min(H,t),U=Math.max(U,t),W=Math.min(W,n),G=Math.max(G,n)}}else H=N.gx-1,U=N.gx+N.w,W=N.gy-1,G=N.gy+N.h;let K=(e,t)=>{let n=Math.max(H-e,e-U,0),r=Math.max(W-t,t-G,0);return d*(Math.max(n,r)+.414*Math.min(n,r))},q=/* @__PURE__ */ new Map;for(let e of B(M)){let t=e[0],n=t*9+8,r=Math.fround(1+c*Math.min(b[t],3));w[n]===D&&S[n]<=r||(w[n]=D,S[n]=r,C[n]=-1,F(r+K(t%f,t/f|0),r,n),q.set(t,e))}let ee=!!j?.strict,J=-1;for(;P;){I();let e=R,t=L;if(e>=E){J=e-E;break}if(t!==S[e])continue;let n=e/9|0,d=e%9,y=V.get(n);if(y){if(!y[3]){J=e;break}F(Math.fround(t+y[3]),Math.fround(t+y[3]),E+e)}let M=n%f,N=n/f|0;for(let y=0;y<8;y++){let E=M+k[y],P=N+A[y];if(E<r||P<p||E>v||P>O)continue;let I=P*f+E;if(h[I]||ee&&g[I]!==j.folder)continue;if(k[y]&&A[y]){let e=N*f+E,t=P*f+M;if(h[e]||h[t]||m[e]!==m[n]||m[t]!==m[n]||m[I]!==m[n])continue}let L=(k[y]&&A[y]?1.414:1)*(1+c*Math.min(b[I],3)+l*Math.min(x[I],3))+i*Math.abs(m[I]-m[n]);if(d!==8&&d!==y){let e=Math.min((y-d+8)%8,(d-y+8)%8);L+=e===1?a:o*(e>=3?2:1)}g[I]>=0&&T[g[I]]!==D&&(L+=s),_[I]&&(L+=u);let R=I*9+y,z=Math.fround(t+L);w[R]===D&&S[R]<=z||(w[R]=D,S[R]=z,C[R]=e,F(z+K(E,P),z,R))}}if(J<0)return null;let Y=[];for(let e=J;e!==-1;e=C[e])Y.push(e/9|0);Y.reverse();for(let e of Y)z(e,1);let X=q.get(Y[0]),te=V.get(Y[Y.length-1]),Z=[[X[1],X[2]]];for(let e of Y)Z.push([e%f+.5,(e/f|0)+.5]);return Z.push([te[1],te[2]]),{cells:Int32Array.from(Y),pts:Z}}function H(e,t){let n=y[e],r=y[t],i=Math.max(Math.abs(n.gx-r.gx),Math.abs(n.gy-r.gy)),a=Math.max(12,Math.ceil(i*.4)),o=Math.max(0,Math.min(n.gx,r.gx)-a),s=Math.max(0,Math.min(n.gy,r.gy)-a),c=Math.min(f-1,Math.max(n.gx+n.w,r.gx+r.w)+a),l=Math.min(p-1,Math.max(n.gy+n.h,r.gy+r.h)+a);return V(e,t,o,s,c,l)||(o||s||c<f-1||l<p-1?V(e,t,0,0,f-1,p-1):null)}function U(e,t){return y[e],y[t.folder],W(e,{...t,strict:!0})||W(e,t)}function W(e,t){let n=y[e],r=y[t.folder];return V(e,-1,Math.max(0,Math.min(n.gx,r.gx)-2),Math.max(0,Math.min(n.gy,r.gy)-2),Math.min(f-1,Math.max(n.gx+n.w,r.gx+r.w)+2),Math.min(p-1,Math.max(n.gy+n.h,r.gy+r.h)+2),t)}function G(e){let t=/* @__PURE__ */ new Set;for(let n=1;n<e.length;n++){let[r,i]=e[n-1],[a,o]=e[n],s=Math.max(1,Math.ceil(Math.max(Math.abs(a-r),Math.abs(o-i))*2));for(let e=0;e<=s;e++){let n=Math.floor(r+(a-r)*e/s),c=Math.floor(i+(o-i)*e/s);n<0||c<0||n>=f||c>=p||h[c*f+n]||t.has(c*f+n)||(t.add(c*f+n),z(c*f+n,1))}}}return{route:H,routeTo:U,occupy:G,release:e=>{for(let t of e.cells)z(t,-1)},hold:e=>{for(let t of e.cells)z(t,1)}}}let M=[0,1,-1,2,-2,3,-3];function N(e,t){let n=/* @__PURE__ */ new Map;e.forEach((e,r)=>{e.edges=/* @__PURE__ */ new Set;for(let i=1;i<e.cells.length;i++){let a=e.cells[i-1],o=e.cells[i],s=a<o?a*t+o:o*t+a;e.edges.add(s),n.has(s)||n.set(s,[]),n.get(s).push(r)}}),e.forEach((t,r)=>{let i=/* @__PURE__ */ new Set;for(let a of t.edges)for(let t of n.get(a))t<r&&i.add(e[t].lane);t.lane=M.find(e=>!i.has(e))??0,delete t.edges})}let P=(e,t,n,r)=>{let i=(e,t,n)=>(t[0]-e[0])*(n[1]-e[1])-(t[1]-e[1])*(n[0]-e[0]);return i(e,t,n)*i(e,t,r)<0&&i(n,r,e)*i(n,r,t)<0};function F(e,t){let n=/* @__PURE__ */ new Map;e.forEach((e,t)=>{for(let r of e.cells)n.has(r)||n.set(r,/* @__PURE__ */ new Set),n.get(r).add(t)});let r=0,i=0;e.forEach((e,a)=>{for(let o of e.cells){r++;let e=!1,s=o%t;for(let r=-1;r<=1&&!e;r++)for(let i=-1;i<=1&&!e;i++){if(s+i<0||s+i>=t)continue;let c=n.get(o+r*t+i);if(c){for(let t of c)if(t!==a){e=!0;break}}}e||i++}});let a=e.map((e,t)=>{let n=[t*.618%1*.02-.01,t*.414%1*.02-.01],r=e.pts;return r.filter((e,t)=>t===0||t===r.length-1||Math.abs((e[0]-r[t-1][0])*(r[t+1][1]-e[1])-(e[1]-r[t-1][1])*(r[t+1][0]-e[0]))>1e-6).map(e=>[e[0]+n[0],e[1]+n[1]])}),o=0;for(let t=0;t<e.length;t++)for(let n=t+1;n<e.length;n++){let r=e[t],i=e[n];if(r.a!==i.a&&r.a!==i.b&&r.b!==i.a&&r.b!==i.b)for(let e=1;e<a[t].length;e++)for(let r=1;r<a[n].length;r++)P(a[t][e-1],a[t][e],a[n][r-1],a[n][r])&&o++}return{routes:e.length,crossings:o,length:r,beside:r?1-i/r:0}}function I(e,t,n,r,i=t.length<=100?2:+(t.length<=300)){let a=t.map(({a:t,b:n})=>{let r=e.route(t,n);return r&&{a:t,b:n,...r}});for(let t=0;t<i;t++)a.forEach((t,n)=>{if(!t)return;e.release(t);let r=e.route(t.a,t.b);r?Object.assign(t,r):e.hold(t)});let o=a.filter(Boolean);N(o,n*r);let s={...F(o,n),lost:a.length-o.length};for(let t of o)e.release(t);return{routes:a.map(e=>e&&{pts:e.pts,lane:e.lane}),measures:s}}let L=[1,1,0,-1,-1,-1,0,1],R=[0,1,1,1,0,-1,-1,-1],z={turn45:1.5,turn90:3,diag:1.3,hug:1,share:.35,centre:.3,gather:224};function B(t,n=e(t),r={}){let{turn45:i,turn90:a,diag:o,hug:s,share:c,centre:l,gather:u}={...z,...r},{items:d,trunks:f}=t,{W:p,H:m,blocked:h,owner:g}=n,_=p*m,v=Math.max(2,Math.round(28/(t.cell??7))),y=Y(n,v),b=v,x=new Uint8Array(_),S=10/(t.cell??7),C=(e,t)=>e>=0&&t>=0&&e<p&&t<m,w=(e,t,n)=>C(e,t)&&!h[t*p+e]&&g[t*p+e]===n;function T(e,t,n){let[r,i]=e,[a,o]=t,s=n?a-r:o-i,c=n?o-i:a-r,l=Math.sign(s),u=Math.sign(c),d=Math.abs(s),f=Math.abs(c),p=[];if(d>=f){let e=Math.floor((d-f)/2);for(let t=0;t<e;t++)p.push([l,0]);for(let e=0;e<f;e++)p.push([l,u]);for(let t=0;t<d-f-e;t++)p.push([l,0])}else{let e=Math.floor(d/2);for(let t=0;t<e;t++)p.push([l,u]);for(let e=0;e<f-d;e++)p.push([0,u]);for(let t=0;t<d-e;t++)p.push([l,u])}let m=[[r,i]],h=r,g=i;for(let[e,t]of p)n?(h+=e,g+=t):(h+=t,g+=e),m.push([h,g]);return m}function E(e,t,n,r,i){let a=Math.max(e.gx-(t.gx+t.w),t.gx-(e.gx+e.w)),o=Math.max(e.gy-(t.gy+t.h),t.gy-(e.gy+e.h)),s=a>=o;if((s?a:o)<1)return null;let[c,l]=s?t.gx<e.gx?[3,2]:[2,3]:t.gy<e.gy?[1,0]:[0,1];if(i&&i.side!==c||r&&r.side!==l)return null;let u=J(t)[c],d=J(e)[l],f=s?Math.max(e.gy,t.gy):Math.max(e.gx,t.gx),m=s?Math.min(e.gy+e.h,t.gy+t.h):Math.min(e.gx+e.w,t.gx+t.w),h=e=>Math.floor(e.mid-.5+1e-9),g=e=>e>=f&&e<m,_=r||i?[[i?i.t:g(r.t)?r.t:h(u),r?r.t:g(i.t)?i.t:h(d),0]]:m-f>=1?X(f,m).map(e=>[e,e,Math.abs(e+.5-(f+m)/2)]):[[h(u),h(d),0]],x=null;for(let[r,i,a]of _){if(V(t,c,r,S)||V(e,l,i,S))continue;let o=T(s?[c===3?t.gx+t.w:t.gx-1,r]:[r,c===1?t.gy+t.h:t.gy-1],s?[l===2?e.gx-1:e.gx+e.w,i]:[i,l===0?e.gy-1:e.gy+e.h],s);if(!o.every(([e,t])=>w(e,t,n)))continue;let u=o.slice(v,o.length-v),d=u.length?Math.min(...u.map(([e,t])=>y[t*p+e])):v;d<b||(!x||d>x.least||d===x.least&&a<x.off)&&(x={least:d,off:a,tb:r,ta:i,way:o})}return x?[u.wall(x.tb),...x.way.map(([e,t])=>[e+.5,t+.5]),d.wall(x.ta)]:null}let D=new Float32Array(_+1),O=new Int32Array(_+1),k=new Uint8Array(_+1),A=new Uint32Array(_+1),j=0,M=[],N=(e,t)=>{M.push([e,t]);let n=M.length-1;for(;n>0;){let t=n-1>>1;if(M[t][0]<=e)break;[M[t],M[n]]=[M[n],M[t]],n=t}},P=()=>{let e=M[0],t=M.pop();if(M.length){M[0]=t;let e=0;for(;;){let t=2*e+1;if(t>=M.length||(t+1<M.length&&M[t+1][0]<M[t][0]&&t++,M[t][0]>=M[e][0]))break;[M[t],M[e]]=[M[e],M[t]],e=t}}return e},F=(e,t)=>{if(e===8||e===t)return 0;let n=Math.min((t-e+8)%8,(e-t+8)%8);return n===1?i:a*(n>=3?2:1)};function I(e,t,n,r,i){j++,M.length=0;let a=_,u=/* @__PURE__ */ new Map,d=(e,t,n)=>!e||e.side===t&&e.t===n;if(J(e).forEach((t,i)=>t.cells.forEach(([a,o])=>{let s=t.dir===6||t.dir===2?a:o;w(a,o,n)&&d(r,i,s)&&!V(e,i,s,S)&&u.set(o*p+a,[(t.dir+4)%8,l*Math.abs(s+.5-t.mid),t.wall(s)])})),!r)for(let t of H(e,S))w(...t.out,n)&&u.set(t.out[1]*p+t.out[0],[(t.dir+4)%8,l*Math.min(e.w,e.h)/2,t.pt]);if(!u.size)return null;let f=e.gx-1,m=e.gx+e.w,h=e.gy-1,g=e.gy+e.h,b=(e,t)=>{let n=Math.max(f-e,e-m,0),r=Math.max(h-t,t-g,0);return Math.max(n,r)+.414*Math.min(n,r)},C=/* @__PURE__ */ new Map,T=(e,t,n,r)=>{A[e]===j&&D[e]<=t||(A[e]=j,D[e]=t,O[e]=-1,k[e]=n,C.set(e,r),N(t+b(e%p,e/p|0),e))};if(J(t).forEach((e,r)=>e.cells.forEach(([a,o])=>{let s=e.dir===6||e.dir===2?a:o;w(a,o,n)&&d(i,r,s)&&!V(t,r,s,S)&&T(o*p+a,l*Math.abs(s+.5-e.mid),e.dir,e.wall(s))})),!i)for(let e of H(t,S))w(...e.out,n)&&T(e.out[1]*p+e.out[0],l*Math.min(t.w,t.h)/2,e.dir,e.pt);for(;M.length;){let[e,t]=P();if(t===a)break;let r=D[t];if(e-b(t%p,t/p|0)>r+1e-4)continue;let i=u.get(t);if(i){let e=r+i[1]+F(k[t],i[0]);(A[a]!==j||e<D[a])&&(A[a]=j,D[a]=e,O[a]=t,N(e,a))}let l=t%p,d=t/p|0;for(let e=0;e<8;e++){let i=l+L[e],a=d+R[e];if(!w(i,a,n)||L[e]&&R[e]&&(!w(i,d,n)||!w(l,a,n)))continue;let u=a*p+i,f=r+(L[e]&&R[e]?Math.SQRT2*o:1)*(x[u]?1-c:1)+s*(v-y[u])+F(k[t],e);A[u]===j&&D[u]<=f||(A[u]=j,D[u]=f,O[u]=t,k[u]=e,N(f+b(i,a),u))}}if(A[a]!==j)return null;let E=[];for(let e=O[a];e!==-1;e=O[e])E.push(e);return E.reverse(),[C.get(E[0]),...E.map(e=>[e%p+.5,Math.floor(e/p)+.5]),u.get(E.at(-1))[2]]}let B=f.map((e,t)=>t).sort((e,t)=>f[t].count-f[e].count||e-t),K=f.map(e=>({a:e.a,b:e.b,count:e.count,back:e.back,implied:e.implied})),q=e=>G(e,(e,t)=>{C(e,t)&&!h[t*p+e]&&(x[t*p+e]=1)}),ee=(e,t,n)=>{let r=f[e],i=d[r.a],a=d[r.b];return E(i,a,i.parent,t,n)??I(i,a,i.parent,t,n)};for(let e of B){let t=ee(e);t&&(K[e].pts=t,q(t))}let te=u/(t.cell??7),Z=/* @__PURE__ */ new Map;K.forEach((e,t)=>{if(e.pts)for(let[n,r,i]of[[`b`,e.b,e.pts[0]],[`a`,e.a,e.pts.at(-1)]]){let a=d[r];if(a.kind!==`folder`||!U(a,i))continue;let o=W(a,i),s=`${r}|${o}`;Z.set(s,[...Z.get(s)||[],{k:t,end:n,t:Math.floor(o<2?i[0]:i[1]),count:e.count}])}});let ne=/* @__PURE__ */ new Map;for(let[e,t]of Z){let[n,r]=e.split(`|`).map(Number),i=d[n];J(i)[r],r<2?i.gx:i.gy,t.sort((e,t)=>e.t-t.t);for(let e=0;e<t.length;){let n=e+1;for(;n<t.length&&t[n].t-t[n-1].t<=te;)n++;let a=t.slice(e,n);if(e=n,a.length<2||a.every(e=>e.t===a[0].t))continue;let o=/* @__PURE__ */ new Map;for(let e of a)o.set(e.t,(o.get(e.t)||0)+e.count);let s=(a[0].t+a.at(-1).t)/2,c=[...o].filter(([e])=>!V(i,r,e,S)).reduce((e,t)=>t[1]>e[1]||t[1]===e[1]&&Math.abs(t[0]-s)<Math.abs(e[0]-s)?t:e)[0];for(let e of a)e.t!==c&&ne.set(e.k,{...ne.get(e.k),[e.end]:{side:r,t:c}})}}if(ne.size){x.fill(0),K.forEach((e,t)=>{e.pts&&!ne.has(t)&&q(e.pts)});for(let e of B){let t=ne.get(e);if(!t)continue;let n=K[e],r=(e,t)=>{if(!U(d[e],t))return;let n=W(d[e],t);return{side:n,t:Math.floor(n<2?t[0]:t[1])}},i=ee(e,t.a??r(n.a,n.pts.at(-1)),t.b??r(n.b,n.pts[0]));i&&(K[e].pts=i),q(K[e].pts)}}return K}function V(e,t,n,r){if(e.kind!==`folder`)return!1;let i=t<2?e.gx:e.gy,a=i+(t<2?e.w:e.h);return n+.5-i<r||a-(n+.5)<r}function H(e,t){return e.kind===`folder`?[[e.gx,e.gy,1,1,5],[e.gx+e.w,e.gy,-1,1,7],[e.gx+e.w,e.gy+e.h,-1,-1,1],[e.gx,e.gy+e.h,1,-1,3]].map(([e,n,r,i,a])=>({out:[Math.floor(e-r*.5),Math.floor(n-i*.5)],in:[Math.floor(e+r*.5),Math.floor(n+i*.5)],dir:a,pt:[e+r*t/2,n+i*t/2]})):[]}function U(e,[t,n]){let r=(e,t)=>Math.abs(e-t)<1e-6;return(r(t,e.gx)||r(t,e.gx+e.w))&&n>=e.gy-1e-6&&n<=e.gy+e.h+1e-6||(r(n,e.gy)||r(n,e.gy+e.h))&&t>=e.gx-1e-6&&t<=e.gx+e.w+1e-6}function W(e,[t,n]){let r=(e,t)=>Math.abs(e-t)<1e-6;return r(n,e.gy)?0:r(n,e.gy+e.h)?1:r(t,e.gx)?2:3}function G(e,t){for(let n=1;n<e.length;n++){let[r,i]=e[n-1],[a,o]=e[n],s=Math.max(1,Math.ceil(Math.max(Math.abs(a-r),Math.abs(o-i))*2));for(let e=0;e<=s;e++)t(Math.floor(r+(a-r)*e/s),Math.floor(i+(o-i)*e/s))}}let K={turn45:1.5,turn90:3,diag:1.3,hug:1,centre:1,join:.5,cross:1,haste:1.5,hasteNote:4};function q(t,n,r=e(t),i={}){let{turn45:a,turn90:o,diag:s,hug:c,centre:l,join:u,cross:d,haste:f,hasteNote:p}={...K,...i},{items:m,links:h}=t,{W:g,H:_,blocked:v,owner:y}=r,b=g*_,x=Math.max(2,Math.round(28/(t.cell??7))),S=Y(r,x),C=10/(t.cell??7),w=new Uint8Array(b);for(let e of n)e.pts&&G(e.pts,(e,t)=>{e>=0&&t>=0&&e<g&&t<_&&(w[t*g+e]=1)});let T=(e,t)=>e>=0&&t>=0&&e<g&&t<_,E=(e,t)=>{for(;m[e].parent!==t;)e=m[e].parent;return e},D=(e,[t,n])=>{let r=(e,t)=>Math.abs(e-t)<1e-6;if(!U(e,[t,n])){let i=H(e,C).find(e=>r(e.pt[0],t)&&r(e.pt[1],n));if(i)return[...i.in,i.dir]}return r(t,e.gx)?[e.gx,Math.floor(n),4]:r(t,e.gx+e.w)?[e.gx+e.w-1,Math.floor(n),0]:r(n,e.gy)?[Math.floor(t),e.gy,6]:[Math.floor(t),e.gy+e.h-1,2]},O=(e,t)=>(L[e]&&R[e]?Math.SQRT2*s:1)+c*(x-S[t]),k=(e,t)=>{if(e===8||e===t)return 0;let n=Math.min((t-e+8)%8,(e-t+8)%8);return n===1?a:o*(n>=3?2:1)},A=new Float32Array(b*9+1),j=new Int32Array(b*9+1),M=new Uint32Array(b*9+1),P=b*9,F=0,I=/* @__PURE__ */ new Float64Array(4096),z=/* @__PURE__ */ new Float64Array(4096),B=/* @__PURE__ */ new Int32Array(4096),W=0,q=0,X=0,te=(e,t,n)=>{if(W===I.length){let e=(e,t)=>{let n=new t(e.length*2);return n.set(e),n};I=e(I,Float64Array),z=e(z,Float64Array),B=e(B,Int32Array)}let r=W++;for(;r>0;){let t=r-1>>1;if(I[t]<=e)break;I[r]=I[t],z[r]=z[t],B[r]=B[t],r=t}I[r]=e,z[r]=t,B[r]=n},Z=()=>{I[0],q=z[0],X=B[0];let e=I[--W],t=z[W],n=B[W],r=0;for(;;){let t=2*r+1;if(t>=W||(t+1<W&&I[t+1]<I[t]&&t++,I[t]>=e))break;I[r]=I[t],z[r]=z[t],B[r]=B[t],r=t}I[r]=e,z[r]=t,B[r]=n};function ne(e,t,n,r,i){F++,W=0;let a=(e,t)=>T(e,t)&&!v[t*g+e]&&y[t*g+e]===n,o=r%g,s=r/g|0,f=(e,t)=>{let n=Math.abs(e-o),r=Math.abs(t-s);return i*(1-u)*(Math.max(n,r)+.414*Math.min(n,r))},p=/* @__PURE__ */ new Map;if(e.kind===`folder`)for(let t of H(e,C)){let[n,r]=t.out;if(!a(n,r))continue;let i=r*g+n,o=i*9+t.dir,s=Math.fround(l*Math.min(e.w,e.h)/2+c*(x-S[i]));M[o]===F&&A[o]<=s||(M[o]=F,A[o]=s,j[o]=-1,p.set(i,t.pt),te(s+f(n,r),s,o))}for(J(e).forEach((t,n)=>t.cells.forEach(([r,i])=>{if(!a(r,i)||V(e,n,t.dir===6||t.dir===2?r:i,C))return;let o=t.dir===6||t.dir===2?r:i,s=i*g+r,u=s*9+t.dir,d=Math.fround(l*Math.abs(o+.5-t.mid)+c*(x-S[s]));M[u]===F&&A[u]<=d||(M[u]=F,A[u]=d,j[u]=-1,p.set(s,t.wall(o)),te(d+f(r,i),d,u))}));W;){Z();let e=X,n=q;if(e===P)break;if(n!==A[e])continue;let r=e/9|0,i=e%9,o=r%g,s=r/g|0,c=t.get(r);if(c){let t=n+c.rest+k(i,c.dir);(M[P]!==F||t<A[P])&&(M[P]=F,A[P]=t,j[P]=e,te(t,t,P))}for(let t=0;t<8;t++){let r=o+L[t],c=s+R[t];if(!a(r,c)||L[t]&&R[t]&&(!a(r,s)||!a(o,c)))continue;let l=c*g+r,u=l*9+t,p=Math.fround(n+O(t,l)+(w[l]?d:0)+k(i,t));M[u]===F&&A[u]<=p||(M[u]=F,A[u]=p,j[u]=e,te(p+f(r,c),p,u))}}if(M[P]!==F)return null;let m=[];for(let e=j[P];e!==-1;e=j[e])m.push(e/9|0);return m.reverse(),{cells:m,pts:[p.get(m[0]),...m.map(e=>[e%g+.5,Math.floor(e/g)+.5]),t.get(m.at(-1)).pt]}}let re=[];n.forEach((e,t)=>{if(!e.pts)return;let n=m[e.a].parent,r=h.filter(t=>t.s>=2&&t.level===n&&E(t.a,n)===e.a&&E(t.b,n)===e.b);m[e.a].kind===`folder`&&re.push({folder:e.a,at:e.pts[e.pts.length-1],notes:r.map(e=>e.a),trunk:t}),m[e.b].kind===`folder`&&re.push({folder:e.b,at:e.pts[0],notes:r.map(e=>e.b),trunk:t})});let ie=[],ae=e=>m[e].kind===`note`,Q=/* @__PURE__ */ new Map;for(let e=0;e<re.length;e++){let{folder:t,at:n,notes:r,trunk:i}=re[e],[a,o,l]=D(m[t],n);if(!T(a,o)||v[o*g+a])continue;let d=o*g+a,h={dir:l,rest:0,pt:n};Q.has(d)||Q.set(d,{ends:/* @__PURE__ */ new Map([[d,h]]),endsAny:/* @__PURE__ */ new Map([[d,h]]),owners:/* @__PURE__ */ new Map([[d,-1]]),exits:/* @__PURE__ */ new Map});let{ends:_,endsAny:y,owners:b,exits:C}=Q.get(d),w=/* @__PURE__ */ new Map;for(let e of r){let n=E(e,t);w.set(n,[...w.get(n)||[],e])}for(let[e,n]of[...w].sort((e,t)=>ae(e[0])-ae(t[0])||t[1].length-e[1].length||e[0]-t[0])){let r=ae(e),a=C.get(e),o=r?y:_,l=a&&o.has(a.cell)?{cells:[a.cell],pts:[a.wall,o.get(a.cell).pt,o.get(a.cell).pt]}:ne(m[e],o,t,d,r?p:f);if(!l)continue;a||C.set(e,{cell:l.cells[0],wall:l.pts[0]});let h=ie.length,v=l.cells.at(-1);ie.push({item:e,folder:t,trunk:i,count:n.length,pts:l.pts,cells:l.cells,leaf:r,via:b.get(v)??-1});let w=new Float32Array(l.cells.length);w[w.length-1]=y.get(v).rest;for(let e=l.cells.length-2;e>=0;e--){let t=l.cells[e],n=l.cells[e+1],r=t%g!==n%g&&Math.floor(t/g)!==Math.floor(n/g);w[e]=w[e+1]+(1-u)*((r?Math.SQRT2*s:1)+c*(x-S[n]))}for(let[e,t]of l.cells.entries()){if(y.has(t))continue;let n=l.cells[e+1],i={dir:n===void 0?y.get(v).dir:ee(n%g-t%g,Math.floor(n/g)-Math.floor(t/g)),rest:w[e],pt:[t%g+.5,Math.floor(t/g)+.5]};y.set(t,i),b.set(t,h),r||_.set(t,i)}r||re.push({folder:e,at:l.pts[0],notes:n,trunk:i})}}return N(ie,b),ie.map(({item:e,folder:t,trunk:n,count:r,pts:i,lane:a,leaf:o,via:s})=>({item:e,folder:t,trunk:n,count:r,pts:i,lane:a,leaf:o,via:s}))}let ee=(e,t)=>L.findIndex((n,r)=>n===Math.sign(e)&&R[r]===Math.sign(t));function J(e){return[{dir:6,cells:X(e.gx,e.gx+e.w).map(t=>[t,e.gy-1]),mid:e.gx+e.w/2,wall:t=>[t+.5,e.gy]},{dir:2,cells:X(e.gx,e.gx+e.w).map(t=>[t,e.gy+e.h]),mid:e.gx+e.w/2,wall:t=>[t+.5,e.gy+e.h]},{dir:4,cells:X(e.gy,e.gy+e.h).map(t=>[e.gx-1,t]),mid:e.gy+e.h/2,wall:t=>[e.gx,t+.5]},{dir:0,cells:X(e.gy,e.gy+e.h).map(t=>[e.gx+e.w,t]),mid:e.gy+e.h/2,wall:t=>[e.gx+e.w,t+.5]}]}function Y({W:e,H:t,blocked:n,owner:r},i){let a=e*t,o=new Uint8Array(a).fill(i),s=new Int32Array(a),c=0,l=0;for(let i=0;i<a;i++){if(n[i]){o[i]=0;continue}let a=i%e,c=i/e|0;for(let u=0;u<8;u++){let d=a+L[u],f=c+R[u];if(d<0||f<0||d>=e||f>=t)continue;let p=f*e+d;if(n[p]||r[p]!==r[i]){o[i]=1,s[l++]=i;break}}}for(;c<l;){let a=s[c++],u=a%e,d=a/e|0;if(!(o[a]+1>=i))for(let i=0;i<8;i++){let c=u+L[i],f=d+R[i];if(c<0||f<0||c>=e||f>=t)continue;let p=f*e+c;o[p]>o[a]+1&&!n[p]&&r[p]===r[a]&&(o[p]=o[a]+1,s[l++]=p)}}return o}let X=(e,t)=>Array.from({length:Math.max(0,t-e)},(t,n)=>e+n);function te(e,t){let n=10/(e.cell??7),r=e.items.filter(e=>e.kind===`folder`),i=(e,t)=>Math.abs(e-t)<1e-6,a=(e,t)=>{for(let a of r){let r=i(e[0],a.gx)||i(e[0],a.gx+a.w),o=i(e[1],a.gy)||i(e[1],a.gy+a.h);if(!(r&&e[1]>=a.gy-1e-6&&e[1]<=a.gy+a.h+1e-6)&&!(o&&e[0]>=a.gx-1e-6&&e[0]<=a.gx+a.w+1e-6))continue;let s=e[0]-a.gx<a.w/2?1:-1,c=e[1]-a.gy<a.h/2?1:-1,l=s>0?a.gx:a.gx+a.w,u=c>0?a.gy:a.gy+a.h;if(Math.abs(e[0]-l)+Math.abs(e[1]-u)>=n-1e-6)return null;let d=[l+s*n/2,u+c*n/2],f=t[0]>a.gx&&t[0]<a.gx+a.w&&t[1]>a.gy&&t[1]<a.gy+a.h?[s,c]:[-s,-c],p=t[0]-d[0],m=t[1]-d[1];if(Math.abs(Math.abs(p)-Math.abs(m))<1e-6&&p*f[0]>0)return[d];let h=[p/f[0],m/f[1]].filter(e=>e>1e-6).sort((e,t)=>e-t);return h.length?[d,[d[0]+f[0]*h[0],d[1]+f[1]*h[0]]]:null}return null};for(let e of t){if(!e.pts||e.pts.length<2)continue;let t=a(e.pts[0],e.pts[1]);t&&(e.pts=[...t,...e.pts.slice(1)]);let n=a(e.pts.at(-1),e.pts.at(-2));n&&(e.pts=[...e.pts.slice(0,-1),...n.reverse()])}return t}function Z(t,n){let r={flow:n.gridFlow===`right`?`right`:`up`,grain:ae(n),plan:!!n.blocks,from:n.from??null},i=T(t,r);if(n.blocks){let n=ne(i,B(i,e(i)));[...n.values()].some(e=>e.wider.size)&&(i=T(t,{...r,planned:n}))}i.feeders=re(i);let a=e(i),o=B(i,a),s=q(i,o,a);return te(i,[...o,...s]),i.highways={trunks:o,feeders:s},i}function ne(e,t){let{items:n}=e,r=e.cell>7?2:3,i=/* @__PURE__ */ new Map;for(let[a,o]of e.pairs??[]){let e=a===``?-1:n.findIndex(e=>e.kind===`folder`&&e.ref===a),s=n.map((e,t)=>t).filter(t=>n[t].parent===e),c=t.filter(t=>t.pts&&n[t.a].parent===e),l=/* @__PURE__ */ new Map;for(let e of s)for(let t of s){if(e>=t)continue;let i=n[e],a=n[t],[o,s]=i.gx<=a.gx?[i,a]:[a,i],[u,d]=i.gy<=a.gy?[i,a]:[a,i],f=s.gx-(o.gx+o.w),p=d.gy-(u.gy+u.h),m=null,h=!1;if(f>0&&f<=16&&Math.min(i.gy+i.h,a.gy+a.h)-Math.max(i.gy,a.gy)>=4?(m=[o.gx+o.w,Math.max(i.gy,a.gy),s.gx,Math.min(i.gy+i.h,a.gy+a.h)],h=!0):p>0&&p<=16&&Math.min(i.gx+i.w,a.gx+a.w)-Math.max(i.gx,a.gx)>=4&&(m=[Math.max(i.gx,a.gx),u.gy+u.h,Math.min(i.gx+i.w,a.gx+a.w),d.gy]),!m)continue;let g=/* @__PURE__ */ new Map;for(let e of c)for(let t=1;t<e.pts.length;t++){let[n,r]=e.pts[t-1],[i,a]=e.pts[t],o=Math.max(1,Math.ceil(Math.max(Math.abs(i-n),Math.abs(a-r))));for(let e=0;e<=o;e++){let t=Math.floor(n+(i-n)*e/o),s=Math.floor(r+(a-r)*e/o);if(t<m[0]||t>=m[2]||s<m[1]||s>=m[3])continue;let c=h?t:s;g.has(c)||g.set(c,/* @__PURE__ */ new Set),g.get(c).add(h?s:t)}}let _=[...g.values()].filter(e=>e.size>=4).length;_>1&&l.set([i.ref,a.ref].sort().join(`|`),r*(_-1))}i.set(a,{pair:o,wider:l})}return i}function re(t,n=t.trunks){let{items:r,links:i,W:a}=t;if(!n.some(e=>e.pts&&(r[e.a].kind===`folder`||r[e.b].kind===`folder`)))return[];let o=e(t),s=j(t,o,{crowd:1,haste:1.5});for(let e of n)e.pts&&s.occupy(e.pts);let c=(e,t)=>{for(;r[e].parent!==t;)e=r[e].parent;return e},l=(e,[t,n])=>{let i=r[e],a=(e,t)=>Math.abs(e-t)<1e-6;return a(t,i.gx)?[i.gx,Math.floor(n)]:a(t,i.gx+i.w)?[i.gx+i.w-1,Math.floor(n)]:a(n,i.gy)?[Math.floor(t),i.gy]:[Math.floor(t),i.gy+i.h-1]},u=[];n.forEach((e,t)=>{if(!e.pts)return;let n=r[e.a].parent,a=i.filter(t=>t.s>=2&&t.level===n&&c(t.a,n)===e.a&&c(t.b,n)===e.b);r[e.a].kind===`folder`&&u.push({folder:e.a,at:e.pts[e.pts.length-1],notes:a.map(e=>e.a),trunk:t}),r[e.b].kind===`folder`&&u.push({folder:e.b,at:e.pts[0],notes:a.map(e=>e.b),trunk:t})});let d=[];for(let e=0;e<u.length;e++){let{folder:t,at:n,notes:i,trunk:f}=u[e],[p,m]=l(t,n);if(p<0||m<0||p>=a||o.blocked[m*a+p])continue;let h=/* @__PURE__ */ new Map;for(let e of i){let n=c(e,t);h.set(n,[...h.get(n)||[],e])}let g=m*a+p,_=e=>r[e].kind===`note`,v=/* @__PURE__ */ new Map([[g,[g,n[0],n[1]]]]),y=new Map(v),b=/* @__PURE__ */ new Map([[g,-1]]);for(let[e,n]of[...h].sort((e,t)=>_(e[0])-_(t[0])||t[1].length-e[1].length||e[0]-t[0])){let r=_(e),i=s.routeTo(e,{ends:r?y:v,folder:t,toward:g});if(!i)continue;let c=d.length;d.push({item:e,folder:t,trunk:f,count:n.length,pts:i.pts,cells:i.cells,leaf:r,via:b.get(i.cells[i.cells.length-1])??-1});let l=new Float32Array(i.cells.length);l[l.length-1]=y.get(i.cells[i.cells.length-1])?.[3]??0;for(let e=i.cells.length-2;e>=0;e--){let t=i.cells[e],n=i.cells[e+1];l[e]=l[e+1]+(t%a!==n%a&&Math.floor(t/a)!==Math.floor(n/a)?Math.SQRT2:1)+(o.close[n]?O.hug:0)}for(let[e,t]of i.cells.entries()){if(y.has(t))continue;let n=[t,t%a+.5,Math.floor(t/a)+.5,l[e]];y.set(t,n),b.set(t,c),r||v.set(t,n)}r||u.push({folder:e,at:i.pts[0],notes:n,trunk:f})}}return N(d,o.W*o.H),d.map(({item:e,folder:t,trunk:n,count:r,pts:i,lane:a,leaf:o,via:s})=>({item:e,folder:t,trunk:n,count:r,pts:i,lane:a,leaf:o,via:s}))}function ie(t){let n=e(t),r=j(t,n);return e=>I(r,e,n.W,n.H)}let ae=e=>e.grain===`coarse`||e.grain===`coarser`?e.grain:`fine`,Q=null;self.onmessage=({data:e})=>{try{if(`layout`in e){self.postMessage({id:e.id,result:Z(e.layout.model,e.layout.o)});return}let{key:t,layout:n,asks:r}=e.routes;if(Q?.key!==t){if(!n)throw Error(`no layout for these routes`);Q={key:t,run:ie(n)}}self.postMessage({id:e.id,result:Q.run(r)})}catch(t){self.postMessage({id:e.id,error:String(t?.message??t)})}}})();
|
|
File without changes
|