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.
Files changed (109) hide show
  1. package/dist/main.js +1634 -62
  2. package/package.json +4 -1
  3. package/web/_app/immutable/assets/0.BGpjfMlq.css +1 -0
  4. package/web/_app/immutable/assets/4.Dn5sJ8uq.css +1 -0
  5. package/web/_app/immutable/assets/5.DJhOSn7C.css +1 -0
  6. package/web/_app/immutable/assets/NoteList.Wxp_AH0Y.css +1 -0
  7. package/web/_app/immutable/chunks/{BQeONalw.js → -_CDfwKC.js} +1 -1
  8. package/web/_app/immutable/chunks/{BtcGx-KQ.js → -oRvYXNk.js} +1 -1
  9. package/web/_app/immutable/chunks/0qd6IUbO.js +1 -0
  10. package/web/_app/immutable/chunks/{DbtvzL7r.js → 7faei0hL.js} +1 -1
  11. package/web/_app/immutable/chunks/{zasx25UV.js → BArcFmbE.js} +3 -3
  12. package/web/_app/immutable/chunks/BF1TezEe.js +1 -0
  13. package/web/_app/immutable/chunks/{Kem7IXj7.js → BF3mdiSX.js} +1 -1
  14. package/web/_app/immutable/chunks/BFOLKM4z.js +1 -0
  15. package/web/_app/immutable/chunks/{BPpUSQ2Y.js → BezGs1Zj.js} +1 -1
  16. package/web/_app/immutable/chunks/Bg-39frG.js +1 -0
  17. package/web/_app/immutable/chunks/BleKqNM1.js +1 -0
  18. package/web/_app/immutable/chunks/{e7GRa0yc.js → BpHE30PI.js} +1 -1
  19. package/web/_app/immutable/chunks/{DAVMwq6b.js → BtF1frCE.js} +1 -1
  20. package/web/_app/immutable/chunks/{0B47b24t.js → BuNfZSU6.js} +1 -1
  21. package/web/_app/immutable/chunks/{BAVnZFPa.js → BubCsN15.js} +1 -1
  22. package/web/_app/immutable/chunks/{CcE14TDI.js → BvhVny3O.js} +1 -1
  23. package/web/_app/immutable/chunks/{C9Qdslk3.js → Bvs-JCN-.js} +1 -1
  24. package/web/_app/immutable/chunks/{DFo4P1vU.js → C-F98t31.js} +1 -1
  25. package/web/_app/immutable/chunks/{Cpjqsnqr.js → C1OaBy7n.js} +1 -1
  26. package/web/_app/immutable/chunks/{C8FxuPry.js → C4SqDe8e.js} +1 -1
  27. package/web/_app/immutable/chunks/{D9uNsgxP.js → C74H8jNb.js} +1 -1
  28. package/web/_app/immutable/chunks/{CUNetmvQ.js → C7bouMY8.js} +1 -1
  29. package/web/_app/immutable/chunks/{BiHyHFlW.js → C8IrXs1w.js} +1 -1
  30. package/web/_app/immutable/chunks/{MrW4zd8l.js → CGGjDDVZ.js} +1 -1
  31. package/web/_app/immutable/chunks/{Wv-ICQRy.js → CL9QeiGC.js} +85 -85
  32. package/web/_app/immutable/chunks/{BLzZIf7l.js → CMAnq3x6.js} +1 -1
  33. package/web/_app/immutable/chunks/{OG9GsKke.js → CMe14KUo.js} +1 -1
  34. package/web/_app/immutable/chunks/{DW5uy3Jw.js → CXc9Iibq.js} +1 -1
  35. package/web/_app/immutable/chunks/Cb-KPahQ.js +1 -0
  36. package/web/_app/immutable/chunks/{DWwu8a1P.js → Cf13Ew0A.js} +1 -1
  37. package/web/_app/immutable/chunks/CkSjC-iE.js +9 -0
  38. package/web/_app/immutable/chunks/{DY0M2GMn.js → Cn8Mg7_E.js} +1 -1
  39. package/web/_app/immutable/chunks/{f7mFVWQS.js → CoeYsgbS.js} +1 -1
  40. package/web/_app/immutable/chunks/{CZSmkKvQ.js → CrqOdm1D.js} +1 -1
  41. package/web/_app/immutable/chunks/{CVqwkR8N.js → CyJXJYoE.js} +1 -1
  42. package/web/_app/immutable/chunks/{AnnzTlE8.js → Cz6kYWmu.js} +1 -1
  43. package/web/_app/immutable/chunks/{ZTEErEOd.js → CzbFy3_5.js} +1 -1
  44. package/web/_app/immutable/chunks/{Ih6r6QR2.js → D-9suc4b.js} +1 -1
  45. package/web/_app/immutable/chunks/{BZX8cNYL.js → D37hxBaz.js} +1 -1
  46. package/web/_app/immutable/chunks/D7yT4F_8.js +517 -0
  47. package/web/_app/immutable/chunks/{DxRGLDbV.js → DNs5kWvM.js} +1 -1
  48. package/web/_app/immutable/chunks/DQp-M3XN.js +1 -0
  49. package/web/_app/immutable/chunks/{D7jLdCNu.js → DR5d84Z7.js} +1 -1
  50. package/web/_app/immutable/chunks/{DH_19--P.js → DaEL1AOW.js} +1 -1
  51. package/web/_app/immutable/chunks/{CSKABQj2.js → Dazeexma.js} +1 -1
  52. package/web/_app/immutable/chunks/{mhWk5y4o.js → Dc2_04md.js} +1 -1
  53. package/web/_app/immutable/chunks/{1j--pDqt.js → Dcjgv4h2.js} +1 -1
  54. package/web/_app/immutable/chunks/{CSTv2fL0.js → DgI3Vj5v.js} +1 -1
  55. package/web/_app/immutable/chunks/{B7LnLClC.js → Dgko1xMH.js} +1 -1
  56. package/web/_app/immutable/chunks/{DEQsS4Ez.js → DlgOmQ_G.js} +1 -1
  57. package/web/_app/immutable/chunks/{BLe29cGh.js → DmS5Qyvl.js} +1 -1
  58. package/web/_app/immutable/chunks/{CglDFp51.js → DqnDX3G8.js} +1 -1
  59. package/web/_app/immutable/chunks/{CTuuQ66F.js → DyZdoKBK.js} +1 -1
  60. package/web/_app/immutable/chunks/{CUB9vnd0.js → DzAOHjhV.js} +1 -1
  61. package/web/_app/immutable/chunks/{DJT73ARj.js → Iqegk1SI.js} +1 -1
  62. package/web/_app/immutable/chunks/{Mwr1r9aw.js → ONqdwA3r.js} +1 -1
  63. package/web/_app/immutable/chunks/{Bytzbt5l.js → Oikibjm2.js} +1 -1
  64. package/web/_app/immutable/chunks/{C1FDDux-.js → T3u7Skc8.js} +1 -1
  65. package/web/_app/immutable/chunks/{Ch5Z7cbP.js → cWWhqL1F.js} +1 -1
  66. package/web/_app/immutable/chunks/{CwHHpacD.js → fRXyV4Ec.js} +1 -1
  67. package/web/_app/immutable/chunks/{CWc-mNzo.js → jAC4YCqW.js} +1 -1
  68. package/web/_app/immutable/chunks/{hjSZ041d.js → kFEqmLql.js} +1 -1
  69. package/web/_app/immutable/chunks/{BtYMl4bD.js → y0C1JQ1v.js} +1 -1
  70. package/web/_app/immutable/chunks/{DJQ6favH.js → yvD4_bP8.js} +1 -1
  71. package/web/_app/immutable/entry/app.CyEmP0i2.js +2 -0
  72. package/web/_app/immutable/entry/start.BxCHvKWL.js +1 -0
  73. package/web/_app/immutable/nodes/0.Bkbiw_sA.js +11 -0
  74. package/web/_app/immutable/nodes/1.kdx6h8ts.js +1 -0
  75. package/web/_app/immutable/nodes/2.CtK7BGB8.js +1 -0
  76. package/web/_app/immutable/nodes/3.D5PZa2kH.js +1 -0
  77. package/web/_app/immutable/nodes/4.DzS8oPUH.js +3 -0
  78. package/web/_app/immutable/nodes/5.B-1BDKsL.js +19 -0
  79. package/web/_app/immutable/nodes/6.DDT1DtCg.js +1 -0
  80. package/web/_app/immutable/nodes/7.CCNCaItj.js +1 -0
  81. package/web/_app/immutable/workers/worker-C_nKscAW.js +1 -0
  82. package/web/_app/version.json +1 -1
  83. package/web/fonts/LythMono-LICENSE.md +112 -0
  84. package/web/fonts/lyth-mono-latin-bold.woff2 +0 -0
  85. package/web/fonts/lyth-mono-latin-bolditalic.woff2 +0 -0
  86. package/web/fonts/lyth-mono-latin-italic.woff2 +0 -0
  87. package/web/fonts/lyth-mono-latin-regular.woff2 +0 -0
  88. package/web/index.html +19 -17
  89. package/web/_app/immutable/assets/0.BEFtmzIh.css +0 -1
  90. package/web/_app/immutable/assets/4.LR47AJKA.css +0 -1
  91. package/web/_app/immutable/assets/NoteList.C2GYAaLW.css +0 -1
  92. package/web/_app/immutable/chunks/BHORylQC.js +0 -1
  93. package/web/_app/immutable/chunks/BMijTvgG.js +0 -1
  94. package/web/_app/immutable/chunks/C7qBBO-i.js +0 -1
  95. package/web/_app/immutable/chunks/CA-rzUq8.js +0 -524
  96. package/web/_app/immutable/chunks/DtEVmiYo.js +0 -1
  97. package/web/_app/immutable/chunks/Qej0SEux.js +0 -1
  98. package/web/_app/immutable/chunks/TmxIGCN3.js +0 -1
  99. package/web/_app/immutable/entry/app.B9TPZNFw.js +0 -2
  100. package/web/_app/immutable/entry/start.WU9HKeyT.js +0 -1
  101. package/web/_app/immutable/nodes/0.C9NFEqJd.js +0 -3
  102. package/web/_app/immutable/nodes/1.B5PJwWOG.js +0 -1
  103. package/web/_app/immutable/nodes/2.DRtC7zjs.js +0 -1
  104. package/web/_app/immutable/nodes/3.EEMisvUL.js +0 -1
  105. package/web/_app/immutable/nodes/4.DthmsFQC.js +0 -19
  106. package/web/_app/immutable/nodes/5.CEu0DlpQ.js +0 -1
  107. package/web/_app/immutable/nodes/6.DzvF0ZPt.js +0 -1
  108. package/web/_app/immutable/workers/worker-CWkpeSVG.js +0 -1
  109. /package/web/_app/immutable/assets/{6.C00vyVPo.css → 7.C00vyVPo.css} +0 -0
@@ -0,0 +1,19 @@
1
+ import{$ as e,A as t,B as n,D as r,E as i,F as a,G as o,H as s,I as c,J as l,M as u,N as d,O as f,P as p,Q as m,R as h,T as g,W as _,Y as v,_t as y,a as b,at as x,ct as ee,d as S,dt as C,et as w,f as T,gt as E,ht as D,i as O,it as k,j as A,k as j,l as te,m as ne,mt as M,n as N,nt as P,ot as F,rt as re,tt as I,u as L,ut as R,v as ie,x as z,y as B,z as V}from"../chunks/Cz6kYWmu.js";import{o as ae,s as oe,t as H}from"../chunks/DQp-M3XN.js";import"../chunks/xihTtKlq.js";import{A as U,C as W,D as G,E as se,M as ce,O as le,S as ue,T as de,_ as fe,a as pe,d as me,f as he,g as ge,h as _e,i as ve,k as ye,l as be,m as xe,n as Se,o as Ce,p as we,r as Te,t as K,v as Ee,w as De,x as Oe,y as ke}from"../chunks/CL9QeiGC.js";import{_ as Ae,a as je,b as Me,c as Ne,d as Pe,f as Fe,h as Ie,i as Le,m as Re,n as ze,o as Be,p as Ve,r as He,s as Ue,t as We,u as Ge,v as Ke,x as qe,y as Je}from"../chunks/D7yT4F_8.js";import{i as Ye}from"../chunks/BleKqNM1.js";import{t as Xe}from"../chunks/DyZdoKBK.js";import{n as Ze,t as Qe}from"../chunks/BFOLKM4z.js";import{B as $e,D as q,E as et,F as J,G as tt,H as nt,I as rt,J as Y,K as it,L as at,M as X,N as Z,P as ot,R as st,S as ct,W as lt,X as ut,Y as dt,at as ft,ct as pt,et as mt,it as ht,lt as gt,mt as _t,n as vt,nt as yt,rt as bt,t as xt,ut as St,v as Ct,w as wt,x as Tt,y as Et}from"../chunks/BxTFtVqu.js";import{i as Dt,l as Ot,n as kt,o as At,r as jt}from"../chunks/yxd8jSz3.js";import{a as Mt,o as Nt,r as Pt,s as Ft,t as It}from"../chunks/CkSjC-iE.js";var Lt=[`kit.js`,`chart.js`,`model.js`,`math.js`,`math.css`,`isorite.css`,`plain.css`,`kit.css`],Rt=e=>e.replace(/&quot;/g,`"`).replace(/&#39;/g,`'`).replace(/&lt;/g,`<`).replace(/&gt;/g,`>`).replace(/&amp;/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,`&amp;`).replace(/"/g,`&quot;`).replace(/</g,`&lt;`);function Gt(e,t,n={}){let r=n.look??`isorite`,i=n.ground??`lapis`,a=e.replace(/<link\b[^>]*\bhref\s*=\s*["'](?:\.\/)?kit\/[^"']*["'][^>]*>\s*/gi,``).replace(/<script\b[^>]*\bsrc\s*=\s*["'](?:\.\/)?kit\/[^"']*["'][^>]*>\s*<\/script>\s*/gi,``),o=Object.entries(n.data??{}).map(([e,t])=>typeof t==`string`?`<script type="text/plain" data-path="${Wt(e)}">${Ut(t)}<\/script>`:`<script type="application/octet-stream" data-encoding="base64" data-path="${Wt(e)}">${Kt(t)}<\/script>`),s=Vt(a).map(e=>`${e===`math`?`<style>\n${Ut(t[`math.css`])}\n</style>\n`:``}<script>\n${Ut(t[`${e}.js`])}\n<\/script>`),c=[Ht,`<style data-look="isorite">\n${Ut(t[`isorite.css`])}\n</style>`,`<style data-look="plain">\n${Ut(t[`plain.css`])}\n</style>`,`<style>\n${Ut(t[`kit.css`])}\n</style>`,...o,`<script>\n${Ut(t[`kit.js`])}\n<\/script>`,...s].join(`
2
+ `);return(/<head\b[^>]*>/i.test(a)?a.replace(/<head\b[^>]*>/i,e=>`${e}\n${c}\n`):`<!doctype html><html><head><meta charset="utf-8">\n${c}\n</head><body>${a}</body></html>`).replace(/<html\b([^>]*)>/i,(e,t)=>`<html${t.replace(/\s+data-(?:look|ground)\s*=\s*("[^"]*"|'[^']*'|\S+)/gi,``)} data-look="${r}" data-ground="${i}">`)}function Kt(e){let t=``;for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)}var qt=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?$/,Jt=e=>e===``?null:qt.test(e.trim())?+e:e;function*Yt(e,t){let n=``,r=[],i=!1;for(let a=0;a<e.length;a++){let o=e[a];i?o===`"`?e[a+1]===`"`?(n+=`"`,a++):i=!1:n+=o:o===`"`&&n===``?i=!0:o===t?(r.push(n),n=``):o===`
3
+ `||o===`\r`?(o===`\r`&&e[a+1]===`
4
+ `&&a++,r.push(n),n=``,(r.length>1||r[0]!==``)&&(yield r),r=[]):n+=o}r.push(n),(r.length>1||r[0]!==``)&&(yield r)}function Xt(e,t=`,`){let n=Yt(e.replace(/^/,``),t),r=n.next();if(r.done)return[];let i=r.value.map(e=>e.trim()),a=[];for(let e of n)a.push(Object.fromEntries(i.map((t,n)=>[t,Jt(e[n]??``)])));return a}function Zt(e,t){let n=e.toLowerCase().split(`.`).pop();if(n===`json`){let n=JSON.parse(t);if(Array.isArray(n))return n;let r=n&&typeof n==`object`?Object.values(n).find(Array.isArray):null;if(r)return r;throw Error(`${e}: not an array of rows`)}if(n===`jsonl`||n===`ndjson`)return t.split(/\r?\n/).filter(e=>e.trim()).map(e=>JSON.parse(e));if(n===`tsv`)return Xt(t,` `);if(n===`csv`)return Xt(t,`,`);throw Error(`${e}: the kit reads CSV, TSV, JSON and JSON lines`)}function Qt(e){let t=new Set;for(let n of e.slice(0,1e3))for(let e of Object.keys(n))t.add(e);return[...t]}function $t(e,t,n=5){return{path:e,rows:t.length,head:t.slice(0,n),columns:Qt(t).map(e=>{let n=t.map(t=>t[e]),r=n.filter(e=>e!=null&&e!==``),i=n.length-r.length;if(!r.length)return{name:e,type:`empty`,empty:i};if(r.every(e=>typeof e==`number`)){let t=1/0,n=-1/0,a=0;for(let e of r)e<t&&(t=e),e>n&&(n=e),a+=e;return{name:e,type:`number`,min:t,max:n,mean:a/r.length,empty:i}}if(r.every(e=>typeof e==`boolean`))return{name:e,type:`boolean`,empty:i};let a=[...new Set(r.map(String))];return{name:e,type:`text`,distinct:a.length,values:a.slice(0,12),empty:i}})}}function en(e){let t=e=>String(Number.isInteger(e)?e:+e.toPrecision(4)),n=[`${e.path}: ${e.rows} rows, ${e.columns.length} columns`];for(let r of e.columns){let e=r.empty?`, ${r.empty} empty`:``;r.type===`number`?n.push(`- ${r.name}: number, ${t(r.min)} to ${t(r.max)} (mean ${t(r.mean)})${e}`):r.type===`text`?n.push(`- ${r.name}: text, ${r.distinct} distinct: ${r.values.join(`, `)}${r.distinct>r.values.length?`, …`:``}${e}`):n.push(`- ${r.name}: ${r.type}${e}`)}let r=e.columns.map(e=>e.name);return n.push(`First rows:`,r.join(`,`),...e.head.map(e=>r.map(t=>e[t]??``).join(`,`))),n.join(`
5
+ `)}function tn(e,t=-1){if(typeof e!=`number`||Number.isNaN(e))return`–`;if(!Number.isFinite(e))return e>0?`∞`:`−∞`;if(t>=0)return e.toFixed(t).replace(`-`,`−`);if(e===0)return`0`;let n=Math.abs(e);if(n>=.001&&n<1e6)return Number.isInteger(e)?String(e).replace(`-`,`−`):String(+e.toPrecision(3)).replace(`-`,`−`);let[r,i]=e.toExponential(2).split(`e`);return`${String(+r).replace(`-`,`−`)}×10${(e=>e.replace(/[-+\d]/g,e=>({"-":`⁻`,"+":``})[e]??`⁰¹²³⁴⁵⁶⁷⁸⁹`[+e]))(String(+i))}`}var nn=null;function rn(){return nn??=Promise.all(Lt.map(async e=>{let t=await fetch(ae(`/kit/${e}`));if(!t.ok)throw Error(`the kit's ${e} isn't there (${t.status}): build the app again`);return[e,await t.text()]})).then(e=>Object.fromEntries(e)).catch(e=>{throw nn=null,e}),nn}var an=e=>e.split(`/`).slice(0,-1).join(`/`);function on(e,t){let n=an(e).split(`/`).filter(Boolean);for(let e of t.replace(/^\.\//,``).split(`/`))if(e!==``&&e!==`.`){if(e===`..`){if(!n.length)return null;n.pop()}else n.push(e)}return n.join(`/`)}async function sn(e,t){let n=await e.file(t);if(!n)throw Error(`no artifact at ${t}`);let r=new TextDecoder().decode(n.bytes);return{html:r,manifest:Bt(r)}}async function cn(e,t,n){let r={};for(let i of n){let n=on(t,i),a=n===null?null:await e.file(n);a&&(r[i]=/^(text\/|application\/(json|jsonl|x-ndjson))/.test(a.type)?new TextDecoder().decode(a.bytes):a.bytes)}return r}async function ln(e,t){return Gt(e,await rn(),t)}function un(e,t,n,r,i){let a=(t,n=[])=>e.contentWindow?.postMessage({isorite:0,...t},`*`,n),o=async o=>{if(o.source!==e.contentWindow)return;let s=o.data;if(s&&s.isorite===0){if(s.type===`ready`){let e=i.current();a({type:`ground`,ground:e.ground}),a({type:`look`,look:e.look})}else if(s.type===`file`||s.type===`bytes`){let e=String(s.path??``);if(!r().includes(e)){a({type:`reply`,id:s.id,error:`${e} is not in the artifact's manifest (isorite:uses)`});return}let i=on(n,e);try{let n=i===null?null:await t.file(i);if(!n)a({type:`reply`,id:s.id,error:`${e}: no such file beside the artifact`});else if(s.type===`bytes`){let e=n.bytes.slice().buffer;a({type:`reply`,id:s.id,bytes:e},[e])}else a({type:`reply`,id:s.id,text:new TextDecoder().decode(n.bytes)})}catch(t){a({type:`reply`,id:s.id,error:`${e}: ${t.message}`})}}else s.type===`height`?i.onHeight(Number(s.height)||0):s.type===`error`?i.onError(String(s.message)):s.type===`open`&&i.onOpen(String(s.note))}};return addEventListener(`message`,o),{tell:a,stop:()=>removeEventListener(`message`,o)}}function dn(e,t){let n=e.split(/[#?]/)[0].trim();if(!n||/^[a-z][a-z0-9+.-]*:/i.test(n)||n.startsWith(`//`)||!/\.html?$/i.test(n))return null;let r=n.startsWith(`/`)?n.slice(1):on(`${t}.md`,n);return r?decodeURI(r):null}function fn(){let e=document.documentElement.dataset.ground;return e===`lapis`||e===`quartz`?e:matchMedia(`(prefers-color-scheme: light)`).matches?`quartz`:`lapis`}function pn(e){let t=e.replace(/&/g,`&amp;`).replace(/"/g,`&quot;`).replace(/</g,`&lt;`);return`<!doctype html><html lang="en"><head><meta charset="utf-8"><title>${t}</title><meta name="isorite:kit" content="1"><meta name="isorite:uses" content="${t}"></head><body><iso-model src="${t}" height="440"></iso-model></body></html>`}var mn=a(`<p class="problem svelte-klp1mb" role="alert"> </p>`),hn=a(`<!> <iframe sandbox="allow-scripts" class="svelte-klp1mb"></iframe>`,1);function gn(e,t){C(t,!0);let n=O(t,`look`,3,`isorite`),r=x(void 0),i=x(480),a=x(``),c=x(re(fn()));v(()=>{let e=new MutationObserver(()=>{k(c,fn(),!0)});e.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-ground`]});let t=matchMedia(`(prefers-color-scheme: light)`),n=()=>{k(c,fn(),!0)};return t.addEventListener(`change`,n),()=>{e.disconnect(),t.removeEventListener(`change`,n)}});let u=null;v(()=>s(r)?(u=un(s(r),K.api,t.path,()=>t.uses,{onHeight:e=>{k(i,Math.max(120,Math.min(2e4,Math.ceil(e)+4)),!0)},onError:e=>t.onerror?.(e),onOpen:e=>{Ye.open(e.replace(/^\/+/,``).replace(/\.md$/,``))},current:()=>({ground:s(c),look:n()})}),()=>{u?.stop(),u=null}):void 0),v(()=>{if(!s(r))return;let e=s(r),i=t.html,l=o(()=>({look:n(),ground:s(c)}));k(a,``),ln(i,l).then(t=>{e.srcdoc=t},e=>{k(a,e.message,!0)})}),v(()=>{u?.tell({type:`ground`,ground:s(c)})}),v(()=>{u?.tell({type:`look`,look:n()})});var f=hn(),p=w(f),m=e=>{var t=mn(),n=I(t,!0);l(()=>A(n,s(a))),d(e,t)};j(p,e=>{s(a)&&e(m)});var h=P(p,2);let g;te(h,e=>k(r,e),()=>s(r)),l(()=>{T(h,`title`,t.title),g=ie(h,``,g,{height:`${s(i)??``}px`})}),d(e,f),R()}var _n=a(`<p class="stand svelte-16i7bpz"> </p>`),vn=a(`<span> </span><span class="sep svelte-16i7bpz">/</span>`,1),yn=a(`<a class="br svelte-16i7bpz"> </a>`),bn=a(`<span class="br svelte-16i7bpz"> </span>`),xn=a(`<span class="uses">uses <!></span>`),Sn=a(`<span class="faint"> </span>`),Cn=a(`<button type="button" role="radio" class="svelte-16i7bpz"> </button>`),wn=a(`<span class="tools svelte-16i7bpz"><span class="seg svelte-16i7bpz" role="radiogroup" aria-label="look"></span> <button type="button" class="btn quiet svelte-16i7bpz">standalone</button></span>`),Tn=a(`<p class="said svelte-16i7bpz" role="status"> </p>`),En=a(`<li> </li>`),Dn=a(`<ul class="errors svelte-16i7bpz" role="alert"></ul>`),On=a(`<p class="problem svelte-16i7bpz" role="alert"> </p>`),kn=a(`<img class="picture svelte-16i7bpz"/>`),An=a(`<iframe class="pdf svelte-16i7bpz"></iframe>`),jn=a(`<th> </th>`),Mn=a(`<td> </td>`),Nn=a(`<tr></tr>`),Pn=a(`<p class="faint"> </p>`),Fn=a(`<pre class="shape svelte-16i7bpz"> </pre> <div class="rows svelte-16i7bpz"><table class="svelte-16i7bpz"><thead><tr></tr></thead><tbody></tbody></table></div> <!>`,1),In=a(`<article class="file svelte-16i7bpz"><header><h1 class="serif svelte-16i7bpz"> </h1> <!> <div class="label svelte-16i7bpz"><span class="kind svelte-16i7bpz"><!> </span> <span class="path svelte-16i7bpz"><!><span class="name svelte-16i7bpz"> </span></span> <!> <!> <!></div> <!> <!></header> <!> <!></article>`);function Ln(t,n){C(n,!0);let a=F(()=>W(n.path)??`misc`),o=F(()=>n.path.split(`/`).at(-1)??n.path),c=F(()=>n.path.split(`/`).slice(0,-1)),u=/\.(glb|gltf|stl|obj)$/i,f=/\.(csv|tsv|json|jsonl|ndjson)$/i,m=x(``),h=x(null),g=x(null),_=x(null),y=x(re([])),b=x(`isorite`),ee=x(``);v(()=>{let e=n.path,t=s(a);k(m,``),k(h,null),k(g,null),k(_,null),k(y,[],!0),k(ee,``);let r;return(async()=>{if(t===`artifact`){let{html:t,manifest:n}=await sn(K.api,e);k(h,{html:t,title:n.title||e.split(`/`).at(-1),description:n.description,uses:n.uses});return}if(u.test(e)){k(h,{html:pn(e.split(`/`).at(-1)),title:e.split(`/`).at(-1),description:``,uses:[e.split(`/`).at(-1)]});return}let n=await K.api.file(e);if(!n)throw Error(`no file at ${e}`);if((t===`image`||n.type===`application/pdf`)&&(r=URL.createObjectURL(new Blob([n.bytes],{type:n.type}))),k(g,{size:n.bytes.length,type:n.type,...r?{url:r}:{}}),t===`data`&&f.test(e)){let t=Zt(e,new TextDecoder().decode(n.bytes));k(_,{shape:$t(e,t),rows:t.slice(0,50)})}})().catch(e=>{k(m,e.message,!0)}),()=>{r&&URL.revokeObjectURL(r)}});let S=F(()=>s(h)?.title??s(o)),E=e=>e<1024?`${e} bytes`:e<1024**2?`${(e/1024).toFixed(1)} kB`:`${(e/1024**2).toFixed(1)} MB`,O=e=>typeof e==`number`?tn(e):String(e??``);async function te(){if(s(h))try{let e=await ln(s(h).html,{look:s(b),ground:fn(),data:await cn(K.api,n.path,s(h).uses)}),t=document.createElement(`a`);t.href=URL.createObjectURL(new Blob([e],{type:`text/html`})),t.download=s(o).replace(/\.html?$/i,``)+`.standalone.html`,t.click(),setTimeout(()=>URL.revokeObjectURL(t.href),1e3),k(ee,`saved ${t.download}, ${E(e.length)}`)}catch(e){k(m,e.message,!0)}}let ne=e=>{let t=on(n.path,e);return t===null?null:ve(t)};var N=In(),L=e(N),ie=e(L),z=I(ie,!0),ae=P(ie,2),oe=e=>{var t=_n(),n=I(t,!0);l(()=>A(n,s(h).description)),d(e,t)};j(ae,e=>{s(h)?.description&&e(oe)});var H=P(ae,2),U=e(H),G=e(U);Ue(G,{get kind(){return s(a)}});var se=P(G,1,!0);D(U);var ce=P(U,2),le=e(ce);i(le,16,()=>s(c),e=>e,(e,t)=>{var n=vn(),r=w(n),i=I(r,!0);M(),l(()=>A(i,t)),d(e,n)});var ue=P(le),de=I(ue,!0);D(ce);var fe=P(ce,2),pe=t=>{var n=xn(),r=P(e(n));i(r,16,()=>s(h).uses,e=>e,(e,t)=>{let n=F(()=>ne(t));var r=p(),i=w(r),a=e=>{var r=yn(),i=I(r,!0);l(()=>{T(r,`href`,s(n)),A(i,t)}),d(e,r)},o=e=>{var n=bn(),r=I(n,!0);l(()=>A(r,t)),d(e,n)};j(i,e=>{s(n)?e(a):e(o,-1)}),d(e,r)}),D(n),d(t,n)};j(fe,e=>{s(a)===`artifact`&&s(h)?.uses.length&&e(pe)});var me=P(fe,2),he=e=>{var t=Sn(),n=I(t,!0);l(e=>A(n,e),[()=>E(s(g).size)]),d(e,t)};j(me,e=>{s(g)&&e(he)});var ge=P(me,2),_e=t=>{var n=wn(),r=e(n);i(r,20,()=>[`isorite`,`plain`],e=>e,(e,t)=>{var n=Cn(),r=I(n,!0);l(()=>{T(n,`aria-checked`,s(b)===t),A(r,t)}),V(`click`,n,()=>k(b,t,!0)),d(e,n)}),D(r);var a=P(r,2);D(n),V(`click`,a,()=>void te()),d(t,n)};j(ge,e=>{s(a)===`artifact`&&e(_e)}),D(H);var ye=P(H,2),be=e=>{var t=Tn(),n=I(t,!0);l(()=>A(n,s(ee))),d(e,t)};j(ye,e=>{s(ee)&&e(be)});var xe=P(ye,2),Se=e=>{var t=Dn();i(t,20,()=>s(y),e=>e,(e,t)=>{var n=En(),r=I(n,!0);l(()=>A(r,t)),d(e,n)}),D(t),d(e,t)};j(xe,e=>{s(y).length&&e(Se)}),D(L);var Ce=P(L,2),we=e=>{var t=On(),n=I(t,!0);l(()=>A(n,s(m))),d(e,t)};j(Ce,e=>{s(m)&&e(we)});var Te=P(Ce,2),Ee=e=>{gn(e,{get path(){return n.path},get html(){return s(h).html},get uses(){return s(h).uses},get look(){return s(b)},get title(){return s(S)},onerror:e=>{s(y).includes(e)||k(y,[...s(y),e],!0)}})},De=e=>{var t=kn();l(()=>{T(t,`src`,s(g).url),T(t,`alt`,s(o))}),d(e,t)},Oe=e=>{var t=An();l(()=>{T(t,`src`,s(g).url),T(t,`title`,s(o))}),d(e,t)},ke=t=>{var n=Fn(),a=w(n),o=I(a,!0),c=P(a,2),u=e(c),f=e(u),p=e(f);i(p,21,()=>s(_).shape.columns,e=>e.name,(e,t)=>{var n=jn();let r;var i=I(n,!0);l(()=>{r=B(n,1,`svelte-16i7bpz`,null,r,{n:s(t).type===`number`}),A(i,s(t).name)}),d(e,n)}),D(p),D(f);var m=P(f);i(m,21,()=>s(_).rows,r,(e,t)=>{var n=Nn();i(n,21,()=>s(_).shape.columns,e=>e.name,(e,n)=>{var r=Mn();let i;var a=I(r,!0);l(e=>{i=B(r,1,`svelte-16i7bpz`,null,i,{n:s(n).type===`number`}),A(a,e)},[()=>O(s(t)[s(n).name])]),d(e,r)}),D(n),d(e,n)}),D(m),D(u),D(c);var h=P(c,2),g=e=>{var t=Pn(),n=I(t);l(()=>A(n,`the first ${s(_).rows.length??``} of ${s(_).shape.rows??``} rows`)),d(e,t)};j(h,e=>{s(_).shape.rows>s(_).rows.length&&e(g)}),l(e=>A(o,e),[()=>en({...s(_).shape,head:[]}).split(`
6
+ First rows:`)[0]]),d(t,n)},Ae=e=>{var t=Pn(),n=I(t,!0);l(()=>A(n,s(g).type)),d(e,t)};j(Te,e=>{s(h)?e(Ee):s(a)===`image`&&s(g)?.url?e(De,1):s(g)?.type===`application/pdf`&&s(g).url?e(Oe,2):s(_)?e(ke,3):s(g)&&e(Ae,4)}),D(N),l(()=>{A(z,s(S)),A(se,Ne[s(a)]),A(de,s(o))}),d(t,N),R()}h([`click`]);var Rn=c(`<svg class="logo drawing svelte-1dt0rua" viewBox="-0.4 -6.5 32.4 7"><path pathLength="1" d="M2 0L2 -2L0 -4M2 -2L2 -4L4 -6M5.6 0L6.6 0L7.6 -1L5.6 -3L6.6 -4L7.6 -4M11.2 0L13.2 -2L11.2 -4L9.2 -2ZM14.8 0L14.8 -2L15.8 -3L16.8 -4M14.8 -2L14.8 -4M20.4 0L20.4 -2L18.4 -4M20.4 -2L20.4 -4L22.4 -6M26 0L25 -1L25 -4L24 -4M25 -4L26 -4M25 -4L25 -5M30.6 0L29.6 0L27.6 -2L29.6 -4L31.6 -2L27.6 -2" class="svelte-1dt0rua"></path></svg>`);function zn(e,t){let n=O(t,`width`,3,26),r=O(t,`label`,3,``);var i=Rn();l(()=>{T(i,`width`,n()),T(i,`height`,n()*7/32.4),T(i,`role`,r()?`img`:void 0),T(i,`aria-label`,r()||void 0),T(i,`aria-hidden`,r()?void 0:`true`)}),d(e,i)}var Bn=class{note;#e=x([]);get entries(){return s(this.#e)}set entries(e){k(this.#e,e)}#t=x(null);get failed(){return s(this.#t)}set failed(e){k(this.#t,e)}#n=x(null);get cursor(){return s(this.#n)}set cursor(e){k(this.#n,e)}#r=x(``);get busy(){return s(this.#r)}set busy(e){k(this.#r,e,!0)}#i=x(null);get editing(){return s(this.#i)}set editing(e){k(this.#i,e,!0)}stop=null;constructor(e){this.note=e}#a=F(()=>_e(this.entries));get waiting(){return s(this.#a)}set waiting(e){k(this.#a,e)}#o=F(()=>this.waiting.filter(e=>e.form===`insert`));get proposals(){return s(this.#o)}set proposals(e){k(this.#o,e)}#s=F(()=>{let e=[],t=ke(this.note.text);for(let n of this.waiting)if(n.form===`rewrite`)for(let r of n.open??[]){let i=n.regions[r],a=me(this.note.text,i.old),o=a?this.note.text.slice(0,a.from).split(`
7
+ `).length-1:-1,s=t.find(e=>e.from<=o&&o<e.to);e.push({key:`r:${n.id}:${r}`,proposal:n,k:r,at:a,block:/\n/.test(i.old.text.trim())||/\n/.test(i.new.trim()),code:!!(s&&/^\s*(```|~~~)/.test(s.text))})}return e.sort((e,t)=>(e.at?.from??1/0)-(t.at?.from??1/0))});get changes(){return s(this.#s)}set changes(e){k(this.#s,e)}#c=F(()=>{try{let e=ue(this.note.text)[0];return{lines:e.split(`
8
+ `).length-1,chars:e.length}}catch{return{lines:0,chars:0}}});get head(){return s(this.#c)}set head(e){k(this.#c,e)}get foot(){return this.note.text.split(`
9
+ `).length}placed(e){return we(this.note.text,e)!==null}#l=F(()=>{let e=[];for(let t of this.proposals){let n=we(this.note.text,t);e.push({key:`p:${t.id}`,line:n?.form===`insert`?n.line:this.foot})}this.changes.some(e=>!e.at)&&e.push({key:`lost`,line:this.foot}),this.failed&&e.push({key:`failed`,line:this.failed.line});let t=this.changes.filter(e=>e.at);for(let n of t)n.block&&e.push({key:n.key,line:this.note.text.slice(0,n.at.to).split(`
10
+ `).length});return{blocks:e,old:t.map(e=>e.at),inline:t.filter(e=>!e.block).map(e=>({key:e.key,at:e.at.to}))}});get layout(){return s(this.#l)}set layout(e){k(this.#l,e)}async open(){this.stop=K.on(e=>this.hear(e));try{this.entries=await K.api.journal(this.note.id)}catch{}}close(){this.stop?.()}hear(e){if(e.type!==`journal`||e.id!==this.note.id||this.entries.some(t=>t.id===e.entry.id))return;this.entries=[...this.entries,e.entry];let t=e.entry.kind===`discard`||e.entry.kind===`change`?e.entry.proposal:void 0;t&&this.editing?.id===t&&(this.editing=null)}say(e,t){this.failed={line:e??this.foot,message:t.message}}lineOf(e){return this.layout.blocks.find(t=>t.key===`p:${e.id}`)?.line}edit(e){this.editing={id:e.id,text:e.text}}async done(e){let t=this.editing;if(t?.id===e.id)try{await K.api.revise(this.note.id,e.id,t.text),this.editing=null}catch(t){this.say(this.lineOf(e),t)}}async keep(e){this.busy=e.id;try{await this.note.save(),this.editing?.id===e.id&&await this.done(e),this.note.adopt(await K.api.keep(this.note.id,e.id))}catch(t){this.say(this.lineOf(e),t)}finally{this.busy=``}}async discard(e){this.busy=e.id;try{await K.api.discard(this.note.id,e.id)}catch(t){this.say(this.lineOf(e),t)}finally{this.busy=``}}async keepChange(e){this.busy=e.key;try{await this.note.save(),this.note.adopt(await K.api.keep(this.note.id,e.proposal.id,e.k))}catch(e){this.say(void 0,e)}finally{this.busy=``}}async discardChange(e){this.busy=e.key;try{await K.api.discard(this.note.id,e.proposal.id,e.k)}catch(e){this.say(void 0,e)}finally{this.busy=``}}async settleAll(e){this.busy=`all`;try{e&&await this.note.save();for(let t of[...this.changes].reverse())(!e||t.at)&&(e?this.note.adopt(await K.api.keep(this.note.id,t.proposal.id,t.k)):await K.api.discard(this.note.id,t.proposal.id,t.k))}catch(e){this.say(void 0,e)}finally{this.busy=``}}},Vn=1500,Hn=e=>be(`isorite.draft.${e}`);function Un(e,t){try{if(t===void 0)return JSON.parse(localStorage.getItem(Hn(e))??`null`);t?localStorage.setItem(Hn(e),JSON.stringify(t)):localStorage.removeItem(Hn(e))}catch{}return null}var Wn=e=>typeof e==`string`?e:e==null?``:String(e),Gn=class{id;#e=x(`loading`);get loaded(){return s(this.#e)}set loaded(e){k(this.#e,e,!0)}#t=x(`saved`);get saving(){return s(this.#t)}set saving(e){k(this.#t,e,!0)}#n=x(``);get message(){return s(this.#n)}set message(e){k(this.#n,e,!0)}#r=x(``);get text(){return s(this.#r)}set text(e){k(this.#r,e,!0)}#i=x(void 0);get theirs(){return s(this.#i)}set theirs(e){k(this.#i,e)}#a=x(0);get revision(){return s(this.#a)}set revision(e){k(this.#a,e,!0)}base=``;saved=``;timer=null;inFlight=null;stop=null;constructor(e){this.id=e}#o=F(()=>{try{return ce(this.text)[0]??{}}catch{return null}});get meta(){return s(this.#o)}set meta(e){k(this.#o,e)}#s=F(()=>{let e=this.meta??{};return{title:Wn(e.title),type:Wn(e.type),description:Wn(e.description),tags:Array.isArray(e.tags)?e.tags.map(String).join(`, `):Wn(e.tags)}});get fields(){return s(this.#s)}set fields(e){k(this.#s,e)}#c=F(()=>{try{return ue(this.text)[2]}catch{return this.text}});get body(){return s(this.#c)}set body(e){k(this.#c,e)}async open(){try{let e=await K.api.readNote(this.id),t=Un(this.id);this.take(e),t&&t.text!==e.text&&(this.text=t.text,t.base===e.version?this.changed():(this.theirs=e,this.saving=`conflict`,Un(this.id,t))),this.loaded=`ready`,this.stop=K.on(e=>this.hear(e))}catch(e){this.loaded=e instanceof Ce&&e.status===404?`missing`:`error`,this.message=e.message}}async close(){this.stop?.(),await this.save()}adopt(e){this.take(e)}async restore(e){await this.settle(),this.take(await K.api.restore(this.id,e,this.base))}async move(e){await this.settle();let t=await K.api.moveNote(this.id,e,this.base);return this.stop?.(),t.id}async setDone(e){await this.settle(),this.take(await K.api.setDone(this.id,e,this.base)),await K.refresh()}async remove(){await this.settle(),await K.api.deleteNote(this.id,this.base),this.stop?.()}async settle(){if(this.saving!==`saved`&&await this.save(),this.saving!==`saved`)throw Error(this.message||`the note could not be saved first`)}take(e){this.text=this.saved=e.text,this.base=e.version,this.theirs=void 0,this.saving=`saved`,this.message=``,Un(this.id,null),this.revision++}setText(e){e!==this.text&&(this.text=e,this.changed())}setBody(e){e!==this.body&&this.setText(Oe(this.text,{},e))}setFields(e){let t={};for(let[n,r]of Object.entries(e)){let e=r.trim();t[n]=n===`tags`?e?e.split(`,`).map(e=>e.trim()).filter(Boolean):null:e||null}this.setMeta(t)}setMeta(e){try{this.setText(Oe(this.text,e,null))}catch{}}changed(){Un(this.id,{base:this.base,text:this.text}),this.saving!==`conflict`&&(this.saving=`unsaved`,this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.save()},Vn))}save(){return this.timer&&=(clearTimeout(this.timer),null),this.inFlight=(this.inFlight??Promise.resolve()).then(()=>this.send()),this.inFlight}async send(){if(this.loaded!==`ready`||this.saving===`conflict`||this.text===this.saved)return;let e=this.text;this.saving=`saving`;try{let t=await K.api.saveNote(this.id,{base:this.base,text:e});this.base=t.version,this.saved=e,this.message=``,this.text===e?(this.saving=`saved`,Un(this.id,null)):this.changed()}catch(t){if(t instanceof Ce&&t.status===409&&t.current!==void 0){if(t.current?.text===e)return this.take(t.current);this.theirs=t.current,this.saving=`conflict`}else this.saving=`failed`,this.message=t.message,this.timer=setTimeout(()=>{this.save()},5e3)}}hear(e){e.type===`note-changed`&&e.id===this.id&&e.version!==this.base&&e.version!==he(this.text)&&this.saving===`saved`&&K.api.readNote(this.id).then(e=>{this.saving===`saved`&&e.version!==this.base&&this.take(e)},()=>void 0)}keepMine(){let e=this.theirs;return e===void 0?Promise.resolve():(this.theirs=void 0,this.saving=`unsaved`,e===null?K.api.createNote(this.id,this.text).then(e=>this.take(e),e=>{this.saving=`failed`,this.message=e.message}):(this.base=e.version,this.saved=e.text,this.save()))}keepTheirs(){this.theirs&&this.take(this.theirs)}},Kn=a(`<button type="button" role="radio" data-lustre=""><!> </button>`),qn=a(`<span class="field svelte-ml08v2"><!></span>`),Jn=a(`<button type="button" class="seg svelte-ml08v2"> </button>`),Yn=a(`<input class="name svelte-ml08v2" spellcheck="false" autocomplete="off" aria-label="name"/>`),Xn=a(`<button type="button" class="seg name svelte-ml08v2"> </button>`),Zn=a(`<span class="path svelte-ml08v2"><!> <span class="sep svelte-ml08v2">/</span> <!></span>`),Qn=a(`<button type="button" class="br svelte-ml08v2"> </button>`),$n=a(`<input class="adding svelte-ml08v2" size="10" aria-label="new tag"/>`),er=a(`<button type="button" class="add svelte-ml08v2" aria-label="add a tag">+</button>`),tr=a(`<button type="button" class="x svelte-ml08v2">×</button>`),nr=a(`<a class="br svelte-ml08v2"> </a><!>`,1),rr=a(`<option> </option>`),ir=a(`<input class="adding svelte-ml08v2" list="label-notes" size="18"/> <datalist id="label-notes"></datalist>`,1),ar=a(`<button type="button" class="add svelte-ml08v2">+</button>`),or=a(`<div><span class="word svelte-ml08v2"> </span> <!> <!> <span class="grow svelte-ml08v2"></span> <button type="button"> </button></div>`),sr=a(`<p class="problem svelte-ml08v2" role="alert"> </p>`),cr=a(`<textarea rows="1" aria-label="description"></textarea> <div class="label svelte-ml08v2"><span class="kinds svelte-ml08v2" role="radiogroup" aria-label="kind"></span> <!> <span class="parts svelte-ml08v2"><!> <!></span></div> <!> <!>`,1);function lr(t,r){C(r,!0);let a=F(()=>!r.note.id.startsWith(`@`)),o=x(``),c=[[`note`,`concept`,`Concept`],[`question`,`question`,`Question`],[`problem`,`problem`,`Problem`]];function u(e,t,n){e!==r.kind&&(r.note.setFields({type:t}),_().then(()=>Ae(n,!0)))}let f=e=>e.split(`/`).slice(0,-1).join(`/`),p=e=>e.split(`/`).at(-1),m=x(null),h=x(``);async function g(e,t){let n=e=>e.trim().replace(/^\/+|\/+$/g,``).replace(/\.md$/,``),i=[n(e),n(t)].filter(Boolean).join(`/`);if(k(m,null),n(t)&&i!==r.note.id){k(o,``);try{let e=await r.note.move(i);await K.refresh(),await H(ve(e),{replaceState:!0})}catch(e){k(o,e.message,!0)}}}let v=e=>{let t=e instanceof HTMLInputElement?e:e.querySelector(`input`);t?.focus(),t?.select()},b=F(()=>r.note.fields.tags.split(`,`).map(e=>e.trim()).filter(Boolean)),E=x(!1);function O(e){let t=e.trim();k(E,!1),t&&!s(b).includes(t)&&r.note.setMeta({tags:[...s(b),t]})}let te=e=>r.note.setMeta({tags:s(b).filter(t=>t!==e).length?s(b).filter(t=>t!==e):null}),M=F(()=>r.kind===`note`?null:De[r.kind]),N=F(()=>s(M)?le(r.note.meta?.[s(M)]):[]),re=F(()=>s(M)?[...new Set([...s(N),...K.listing.notes.find(e=>e.id===r.note.id)?.attached??[]])]:[]),L=e=>K.listing.notes.find(t=>t.id===e)?.title??p(e),ie=x(!1);function ae(e){k(ie,!1);let t=e.trim().replace(/^\/+/,``).replace(/\.md$/,``),n=K.listing.notes.find(e=>e.id===t||e.title.toLowerCase()===t.toLowerCase());s(M)&&n&&!s(N).includes(n.id)&&n.id!==r.note.id&&r.note.setMeta({[s(M)]:[...s(N),n.id]})}let oe=e=>{s(M)&&r.note.setMeta({[s(M)]:s(N).filter(t=>t!==e).length?s(N).filter(t=>t!==e):null})};var U=cr(),W=w(U);ee(W);let G;var se=P(W,2),ce=e(se);i(ce,21,()=>c,([e,t,n])=>e,(t,n)=>{var i=F(()=>y(s(n),3));let a=()=>s(i)[0],o=()=>s(i)[1],c=()=>s(i)[2];var f=Kn(),p=e(f);{let e=F(()=>a()===`note`?`concept`:a());Ue(p,{get kind(){return s(e)}})}var m=P(p,1,!0);D(f),l(()=>{B(f,1,`slot ${a()??``}`,`svelte-ml08v2`),T(f,`aria-checked`,r.kind===a()),A(m,o())}),V(`click`,f,e=>u(a(),c(),e.currentTarget)),d(t,f)}),D(ce);var ue=P(ce,2),de=t=>{var i=Zn(),a=e(i),o=t=>{var n=qn(),i=e(n);Qe(i,{id:`note-folder`,quiet:!0,label:`folder`,placeholder:`the top of the base`,onpick:e=>void g(e,p(r.note.id)),onkeydown:e=>{e.key===`Escape`&&k(m,null)},get value(){return s(h)},set value(e){k(h,e,!0)}}),D(n),z(n,e=>v?.(e)),d(t,n)},c=e=>{var t=Jn(),n=I(t,!0);l((e,r)=>{T(t,`aria-label`,e),A(n,r)},[()=>f(r.note.id)?void 0:`the top of the base`,()=>f(r.note.id).replaceAll(`/`,` / `)||`·`]),V(`click`,t,()=>{k(h,f(r.note.id),!0),k(m,`folder`)}),d(e,t)};j(a,e=>{s(m)===`folder`?e(o):e(c,-1)});var u=P(a,4),_=e=>{var t=Yn();S(t),z(t,e=>v?.(e)),l((e,n)=>{ne(t,e),T(t,`size`,n)},[()=>p(r.note.id),()=>Math.max(8,p(r.note.id).length)]),n(`blur`,t,e=>void g(f(r.note.id),e.currentTarget.value)),V(`keydown`,t,e=>{e.key===`Enter`?e.currentTarget.blur():e.key===`Escape`&&k(m,null)}),d(e,t)},y=e=>{var t=Xn(),n=I(t,!0);l(e=>A(n,e),[()=>p(r.note.id)]),V(`click`,t,()=>k(m,`name`)),d(e,t)};j(u,e=>{s(m)===`name`?e(_):e(y,-1)}),D(i),d(t,i)};j(ue,e=>{s(a)&&e(de)});var fe=P(ue,2),pe=e(fe);i(pe,16,()=>s(b),e=>e,(e,t)=>{var n=Qn(),r=I(n,!0);l(()=>{T(n,`aria-label`,`tag ${t??``}: remove`),A(r,t)}),V(`click`,n,()=>te(t)),d(e,n)});var me=P(pe,2),he=e=>{var t=$n();z(t,e=>v?.(e)),n(`blur`,t,e=>O(e.currentTarget.value)),V(`keydown`,t,e=>{e.key===`Enter`?e.currentTarget.blur():e.key===`Escape`&&k(E,!1)}),d(e,t)},ge=e=>{var t=er();V(`click`,t,()=>k(E,!0)),d(e,t)};j(me,e=>{s(E)?e(he):e(ge,-1)}),D(fe),D(se);var _e=P(se,2),ye=t=>{var a=or(),o=e(a),c=I(o,!0),u=P(o,2);i(u,16,()=>s(re),e=>e,(e,t)=>{var n=nr(),r=w(n),i=I(r,!0),a=P(r),o=e=>{var n=tr();l(e=>T(n,`aria-label`,`${e??``}: take away`),[()=>L(t)]),V(`click`,n,()=>oe(t)),d(e,n)},c=F(()=>s(N).includes(t));j(a,e=>{s(c)&&e(o)}),l((e,t)=>{T(r,`href`,e),A(i,t)},[()=>ve(t),()=>L(t)]),d(e,n)});var f=P(u,2),p=e=>{var t=ir(),a=w(t);z(a,e=>v?.(e));var o=P(a,2);i(o,21,()=>K.listing.notes.filter(e=>e.id!==r.note.id&&!e.id.startsWith(`@`)),e=>e.id,(e,t)=>{var n=rr(),r=I(n,!0),i={};l(()=>{A(r,s(t).title),i!==(i=s(t).id)&&(n.value=(n.__value=i)??``)}),d(e,n)}),D(o),l(()=>T(a,`aria-label`,`a note it's ${s(M)===`about`?`about`:`using`}`)),n(`blur`,a,e=>ae(e.currentTarget.value)),V(`keydown`,a,e=>{e.key===`Enter`?e.currentTarget.blur():e.key===`Escape`&&k(ie,!1)}),d(e,t)},m=e=>{var t=ar();l(()=>T(t,`aria-label`,`add a note it's ${s(M)===`about`?`about`:`using`}`)),V(`click`,t,()=>k(ie,!0)),d(e,t)};j(f,e=>{s(ie)?e(p):e(m,-1)});var h=P(f,4);let g;var _=I(h,!0);D(a),l(()=>{B(a,1,`extra ${r.kind??``}`,`svelte-ml08v2`),A(c,s(M)),g=B(h,1,`mark svelte-ml08v2`,null,g,{done:!!r.done}),T(h,`aria-pressed`,!!r.done),h.disabled=r.marking,T(h,`title`,r.done?`since ${r.done}`:void 0),A(_,r.kind===`question`?r.done?`◆ resolved`:`◇ open`:r.done?`◆ solved`:`◇ unsolved`)}),V(`click`,h,function(...e){r.onmark?.apply(this,e)}),d(t,a)};j(_e,e=>{s(M)&&e(ye)});var be=P(_e,2),xe=e=>{var t=sr(),n=I(t,!0);l(()=>A(n,s(o))),d(e,t)};j(be,e=>{s(o)&&e(xe)}),l(()=>{G=B(W,1,`stand serif svelte-ml08v2`,null,G,{empty:!r.note.fields.description}),ne(W,r.note.fields.description)}),V(`input`,W,e=>r.note.setFields({description:e.currentTarget.value.replace(/\s*\n\s*/g,` `)})),V(`keydown`,W,e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())}),d(t,U),R()}h([`input`,`keydown`,`click`]);var ur=a(`<span class="sym svelte-wdtkre"> </span>`),dr=a(`<span class="lines svelte-wdtkre"> </span>`),fr=a(`<span class="why svelte-wdtkre"> </span>`),pr=a(`<span class="ln svelte-wdtkre"></span>`),mr=a(`<span class="pre svelte-wdtkre"></span> <!> <!>`,1),hr=a(`<span data-code-embed=""><span class="head svelte-wdtkre"><a class="file svelte-wdtkre" title="Read the whole file"> </a> <!> <!></span> <!></span>`);function gr(t,n){C(n,!0);let a=x(null),o=x(null),c=x(``);async function u(){try{let e=await K.api.code(n.href);k(a,e),k(o,e.state===`ok`?await Pt(e.text,e.path):null,!0),k(c,``)}catch(e){k(c,e.message,!0)}}v(()=>{n.href,u();let e=()=>{document.visibilityState===`visible`&&u()};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)});let f={"no-repository":`no repository is named for this base's code links`,"no-file":`not in the repository`,"no-symbol":`no longer in the file by that name`,unsupported:`isorite can find symbols in this kind of file only by lines`,"too-large":`too large to show`},p=F(()=>s(a)?.state===`ok`?s(a).start===s(a).end?`line ${s(a).start}`:`lines ${s(a).start}–${s(a).end}`:``);var m=hr();let h;var _=e(m),y=e(_),b=I(y,!0),ee=P(y,2),S=e=>{var t=ur(),n=I(t,!0);l(()=>A(n,s(a).symbol)),d(e,t)};j(ee,e=>{s(a)?.symbol&&e(S)});var E=P(ee,2),O=e=>{var t=dr(),n=I(t,!0);l(()=>A(n,s(p))),d(e,t)};j(E,e=>{s(p)&&e(O)}),D(_);var te=P(_,2),ne=e=>{var t=fr(),n=I(t,!0);l(()=>A(n,s(c))),d(e,t)},M=e=>{var t=fr(),n=I(t,!0);l(()=>A(n,f[s(a).state])),d(e,t)},N=e=>{var t=mr(),n=w(t);let c;i(n,21,()=>s(a).text.split(`
11
+ `),r,(e,t,n)=>{var r=pr();g(r,()=>(s(o)?.split(`
12
+ `)[n]??s(t).replace(/&/g,`&amp;`).replace(/</g,`&lt;`))||` `,!0),D(r),l(()=>T(r,`data-n`,s(a).start+n)),d(e,r)}),D(n);var u=P(n,2),f=e=>{var t=fr(),n=I(t);l(()=>A(n,`… ${s(a).end-s(a).start+1-120} more lines in the file`)),d(e,t)};j(u,e=>{s(a).more&&e(f)});var p=P(u,2),m=e=>{var t=fr(),n=I(t);l(()=>A(n,`${s(a).count??``} declarations of this name: the first is shown`)),d(e,t)};j(p,e=>{s(a).count&&e(m)}),l(()=>c=ie(n,``,c,{"--from":s(a).start})),d(e,t)};j(te,e=>{s(c)?e(ne):s(a)&&s(a).state!==`ok`?e(M,1):s(a)?.state===`ok`&&e(N,2)}),D(m),l((e,t)=>{h=B(m,1,`code svelte-wdtkre`,null,h,{broken:s(a)&&s(a).state!==`ok`}),T(y,`href`,e),A(b,t)},[()=>Se(n.href),()=>s(a)?.path??n.href.slice(5).split(`#`)[0]]),d(t,m),R()}var _r=a(`<span class="problem svelte-zlq7nn"> </span>`),vr=a(`<span class="embed svelte-zlq7nn"><a class="name svelte-zlq7nn"><!> </a> <!> <!></span>`);function yr(t,n){C(n,!0);let r=x(null),a=x(``),o=x(re([]));v(()=>{let e=n.path;sn(K.api,e).then(e=>{k(r,e)},e=>{k(a,e.message,!0)})});var c=vr(),u=e(c),f=e(u);Ue(f,{kind:`artifact`,size:11});var p=P(f,1,!0);D(u);var m=P(u,2),h=e=>{var t=_r(),n=I(t,!0);l(()=>A(n,s(a))),d(e,t)},g=e=>{{let t=F(()=>s(r).manifest.title||n.path);gn(e,{get path(){return n.path},get html(){return s(r).html},get uses(){return s(r).manifest.uses},get title(){return s(t)},onerror:e=>{s(o).includes(e)||k(o,[...s(o),e],!0)}})}};j(m,e=>{s(a)?e(h):s(r)&&e(g,1)});var _=P(m,2);i(_,16,()=>s(o),e=>e,(e,t)=>{var n=_r(),r=I(n,!0);l(()=>A(r,t)),d(e,n)}),D(c),l((e,t)=>{T(u,`href`,e),A(p,t)},[()=>ve(n.path),()=>s(r)?.manifest.title||n.path.split(`/`).at(-1)]),d(t,c),R()}var br=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=Tr(e.state,n.from);return r.line?Sr(e):r.block?wr(e):!1};function xr(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=e(t,n);return i?(r(n.update(i)),!0):!1}}var Sr=xr(Ar,0),Cr=xr(kr,0),wr=xr((e,t)=>kr(e,t,Or(t)),0);function Tr(e,t){let n=e.languageDataAt(`commentTokens`,t,1);return n.length?n[0]:{}}var Er=50;function Dr(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-Er,r),o=e.sliceDoc(i,i+Er),s=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,l=a.length-s;if(a.slice(l-t.length,l)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-s,margin:s&&1},close:{pos:i+c,margin:c&&1}};let u,d;i-r<=100?u=d=e.sliceDoc(r,i):(u=e.sliceDoc(r,r+Er),d=e.sliceDoc(i-Er,i));let f=/^\s*/.exec(u)[0].length,p=/\s*$/.exec(d)[0].length,m=d.length-p-n.length;return u.slice(f,f+t.length)==t&&d.slice(m,m+n.length)==n?{open:{pos:r+f+t.length,margin:+!!/\s/.test(u.charAt(f+t.length))},close:{pos:i-p-n.length,margin:+!!/\s/.test(d.charAt(m-1))}}:null}function Or(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),i=n.to<=r.to?r:e.doc.lineAt(n.to);i.from>r.from&&i.from==n.to&&(i=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=i.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:i.to})}return t}function kr(e,t,n=t.selection.ranges){let r=n.map(e=>Tr(t,e.from).block);if(!r.every(e=>e))return null;let i=n.map((e,n)=>Dr(t,r[n],e.from,e.to));if(e!=2&&!i.every(e=>e))return{changes:t.changes(n.map((e,t)=>i[t]?[]:[{from:e.from,insert:r[t].open+` `},{from:e.to,insert:` `+r[t].close}]))};if(e!=1&&i.some(e=>e)){let e=[];for(let t=0,n;t<i.length;t++)if(n=i[t]){let i=r[t],{open:a,close:o}=n;e.push({from:a.pos-i.open.length,to:a.pos+a.margin},{from:o.pos-o.margin,to:o.pos+i.close.length})}return{changes:e}}return null}function Ar(e,t,n=t.selection.ranges){let r=[],i=-1;ranges:for(let{from:e,to:a}of n){let n=r.length,o=1e9,s;for(let n=e;n<=a;){let c=t.doc.lineAt(n);if(s==null&&(s=Tr(t,c.from).line,!s))continue ranges;if(c.from>i&&(e==a||a>c.from)){i=c.from;let e=/^\s*/.exec(c.text)[0].length,t=e==c.length,n=c.text.slice(e,e+s.length)==s?e:-1;e<c.text.length&&e<o&&(o=e),r.push({line:c,comment:n,token:s,indent:e,empty:t,single:!1})}n=c.to+1}if(o<1e9)for(let e=n;e<r.length;e++)r[e].indent<r[e].line.text.length&&(r[e].indent=o);r.length==n+1&&(r[n].single=!0)}if(e!=2&&r.some(e=>e.comment<0&&(!e.empty||e.single))){let e=[];for(let{line:t,token:n,indent:i,empty:a,single:o}of r)(o||!a)&&e.push({from:t.from+i,insert:n+` `});let n=t.changes(e);return{changes:n,selection:t.selection.map(n,1)}}if(e!=1&&r.some(e=>e.comment>=0)){let e=[];for(let{line:t,comment:n,token:i}of r)if(n>=0){let r=t.from+n,a=r+i.length;t.text[a-t.from]==` `&&a++,e.push({from:r,to:a})}return{changes:e}}return null}var jr=lt.define(),Mr=lt.define(),Nr=ut.define(),Pr=ut.define({combine(e){return pt(e,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,r)=>e(n,r)||t(n,r)})}}),Fr=bt.define({create(){return ei.empty},update(e,t){let n=t.state.facet(Pr),r=t.annotation(jr);if(r){let i=Hr.fromTransaction(t,r.selection),a=r.side,o=a==0?e.undone:e.done;return o=i?Ur(o,o.length,n.minDepth,i):Yr(o,t.startState.selection),new ei(a==0?r.rest:o,a==0?o:r.rest)}let i=t.annotation(Mr);if((i==`full`||i==`before`)&&(e=e.isolate()),t.annotation(ft.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=Hr.fromTransaction(t),o=t.annotation(ft.time),s=t.annotation(ft.userEvent);return a?e=e.addChanges(a,o,s,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,s,n.newGroupDelay)),(i==`full`||i==`after`)&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(e=>e.toJSON()),undone:e.undone.map(e=>e.toJSON())}},fromJSON(e){return new ei(e.done.map(Hr.fromJSON),e.undone.map(Hr.fromJSON))}});function Ir(e={}){return[Fr,Pr.of(e),J.domEventHandlers({beforeinput(e,t){let n=e.inputType==`historyUndo`?Rr:e.inputType==`historyRedo`?zr:null;return n?(e.preventDefault(),n(t)):!1}})]}function Lr(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(Fr,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}var Rr=Lr(0,!1),zr=Lr(1,!1),Br=Lr(0,!0),Vr=Lr(1,!0),Hr=class e{constructor(e,t,n,r,i){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=i}setSelAfter(t){return new e(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){return{changes:this.changes?.toJSON(),mapped:this.mapped?.toJSON(),startSelection:this.startSelection?.toJSON(),selectionsAfter:this.selectionsAfter.map(e=>e.toJSON())}}static fromJSON(t){return new e(t.changes&&it.fromJSON(t.changes),[],t.mapped&&tt.fromJSON(t.mapped),t.startSelection&&Y.fromJSON(t.startSelection),t.selectionsAfter.map(Y.fromJSON))}static fromTransaction(t,n){let r=qr;for(let e of t.startState.facet(Nr)){let n=e(t);n.length&&(r=r.concat(n))}return!r.length&&t.changes.empty?null:new e(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,qr)}static selection(t){return new e(void 0,qr,void 0,void 0,t)}};function Ur(e,t,n,r){let i=t+1>n+20?t-n-1:0,a=e.slice(i,t);return a.push(r),a}function Wr(e,t){let n=[],r=!1;return e.iterChangedRanges((e,t)=>n.push(e,t)),t.iterChangedRanges((e,t,i,a)=>{for(let e=0;e<n.length;){let t=n[e++],o=n[e++];a>=t&&i<=o&&(r=!0)}}),r}function Gr(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((e,n)=>e.empty!=t.ranges[n].empty).length===0}function Kr(e,t){return e.length?t.length?e.concat(t):e:t}var qr=[],Jr=200;function Yr(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-Jr));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),Ur(e,e.length-1,1e9,n.setSelAfter(r)))}return[Hr.selection([t])]}function Xr(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function Zr(e,t){if(!e.length)return e;let n=e.length,r=qr;for(;n;){let i=Qr(e[n-1],t,r);if(i.changes&&!i.changes.empty||i.effects.length){let t=e.slice(0,n);return t[n-1]=i,t}t=i.mapped,n--,r=i.selectionsAfter}return r.length?[Hr.selection(r)]:qr}function Qr(e,t,n){let r=Kr(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):qr,n);if(!e.changes)return Hr.selection(r);let i=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new Hr(i,yt.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}var $r=/^(input\.type|delete)($|\.)/,ei=class e{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new e(this.done,this.undone):this}addChanges(t,n,r,i,a){let o=this.done,s=o[o.length-1];return o=s&&s.changes&&!s.changes.empty&&t.changes&&(!r||$r.test(r))&&(!s.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,Wr(s.changes,t.changes))||r==`input.type.compose`)?Ur(o,o.length-1,i.minDepth,new Hr(t.changes.compose(s.changes),Kr(yt.mapEffects(t.effects,s.changes),s.effects),s.mapped,s.startSelection,qr)):Ur(o,o.length,i.minDepth,t),new e(o,qr,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:qr;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&Gr(a[a.length-1],t)?this:new e(Yr(this.done,t),this.undone,n,r)}addMapping(t){return new e(Zr(this.done,t),Zr(this.undone,t),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=e==0?this.done:this.undone;if(r.length==0)return null;let i=r[r.length-1],a=i.selectionsAfter[0]||(i.startSelection?i.startSelection.map(i.changes.invertedDesc,1):t.selection);if(n&&i.selectionsAfter.length)return t.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:jr.of({side:e,rest:Xr(r),selection:a}),userEvent:e==0?`select.undo`:`select.redo`,scrollIntoView:!0});if(i.changes){let n=r.length==1?qr:r.slice(0,r.length-1);return i.mapped&&(n=Zr(n,i.mapped)),t.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:jr.of({side:e,rest:n,selection:a}),filter:!1,userEvent:e==0?`undo`:`redo`,scrollIntoView:!0})}return null}};ei.empty=new ei(qr,qr);var ti=[{key:`Mod-z`,run:Rr,preventDefault:!0},{key:`Mod-y`,mac:`Mod-Shift-z`,run:zr,preventDefault:!0},{linux:`Ctrl-Shift-z`,run:zr,preventDefault:!0},{key:`Mod-u`,run:Br,preventDefault:!0},{key:`Alt-u`,mac:`Mod-Shift-u`,run:Vr,preventDefault:!0}];function ni(e,t){return Y.create(e.ranges.map(t),e.mainIndex)}function ri(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:`select`})}function ii({state:e,dispatch:t},n){let r=ni(e.selection,n);return!r.eq(e.selection,!0)&&(t(ri(e,r)),!0)}function ai(e,t){return Y.cursor(t?e.to:e.from)}function oi(e,t){return ii(e,n=>n.empty?e.moveByChar(n,t):ai(n,t))}function Q(e){return e.textDirectionAt(e.state.selection.main.head)==ot.LTR}var si=e=>oi(e,!Q(e)),ci=e=>oi(e,Q(e));function li(e,t){return ii(e,n=>n.empty?e.moveByGroup(n,t):ai(n,t))}var ui=e=>li(e,!Q(e)),di=e=>li(e,Q(e));typeof Intl<`u`&&Intl.Segmenter;function fi(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function pi(e,t,n){let r=q(e).resolveInner(t.head),i=n?_t.closedBy:_t.openedBy;for(let a=t.head;;){let t=n?r.childAfter(a):r.childBefore(a);if(!t)break;fi(e,t,i)?r=t:a=n?t.to:t.from}let a=r.type.prop(i),o,s;return s=a&&(o=n?wt(e,r.from,1):wt(e,r.to,-1))&&o.matched?n?o.end.to:o.end.from:n?r.to:r.from,Y.cursor(s,n?-1:1)}var mi=e=>ii(e,t=>pi(e.state,t,!Q(e))),hi=e=>ii(e,t=>pi(e.state,t,Q(e)));function gi(e,t){return ii(e,n=>{if(!n.empty)return ai(n,t);let r=e.moveVertically(n,t);return r.head==n.head?e.moveToLineBoundary(n,t):r})}var _i=e=>gi(e,!1),vi=e=>gi(e,!0);function yi(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,i;if(t){for(let t of e.state.facet(J.scrollMargins)){let i=t(e);i?.top&&(n=Math.max(i?.top,n)),i?.bottom&&(r=Math.max(i?.bottom,r))}i=e.scrollDOM.clientHeight-n-r}else i=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,i-5)}}function bi(e,t){let n=yi(e),{state:r}=e,i=ni(r.selection,r=>r.empty?e.moveVertically(r,t,n.height):ai(r,t));if(i.eq(r.selection))return!1;let a;if(n.selfScroll){let t=e.coordsAtPos(r.selection.main.head),o=e.scrollDOM.getBoundingClientRect(),s=o.top+n.marginTop,c=o.bottom-n.marginBottom;t&&t.top>s&&t.bottom<c&&(a=J.scrollIntoView(i.main.head,{y:`start`,yMargin:t.top-s}))}return e.dispatch(ri(r,i),{effects:a}),!0}var xi=e=>bi(e,!1),Si=e=>bi(e,!0);function Ci(e,t,n){let r=e.lineBlockAt(t.head),i=e.moveToLineBoundary(t,n);if(i.head==t.head&&i.head!=(n?r.to:r.from)&&(i=e.moveToLineBoundary(t,n,!1)),!n&&i.head==r.from&&r.length){let n=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;n&&t.head!=r.from+n&&(i=Y.cursor(r.from+n))}return i}var wi=e=>ii(e,t=>Ci(e,t,!0)),Ti=e=>ii(e,t=>Ci(e,t,!1)),Ei=e=>ii(e,t=>Ci(e,t,!Q(e))),Di=e=>ii(e,t=>Ci(e,t,Q(e))),Oi=e=>ii(e,t=>e.moveToLineBoundary(t,!1,!1)),ki=e=>ii(e,t=>e.moveToLineBoundary(t,!0,!1));function Ai(e,t,n){let r=!1,i=ni(e.selection,t=>{let i=wt(e,t.head,-1)||wt(e,t.head,1)||t.head>0&&wt(e,t.head-1,1)||t.head<e.doc.length&&wt(e,t.head+1,-1);if(!i||!i.end)return t;r=!0;let a=i.start.from==t.head?i.end.to:i.end.from;return n?Y.range(t.anchor,a):Y.cursor(a)});return r?(t(ri(e,i)),!0):!1}var ji=({state:e,dispatch:t})=>Ai(e,t,!1);function $(e,t,n){let r=ni(e.state.selection,e=>{e.undirectional&&e.head>=e.anchor!=t&&(e=Y.range(e.head,e.anchor));let r=n(e);return Y.range(e.anchor,r.head,r.goalColumn,r.bidiLevel||void 0,r.assoc)});return!r.eq(e.state.selection)&&(e.dispatch(ri(e.state,r)),!0)}function Mi(e,t){return $(e,t,n=>e.moveByChar(n,t))}var Ni=e=>Mi(e,!Q(e)),Pi=e=>Mi(e,Q(e));function Fi(e,t){return $(e,t,n=>e.moveByGroup(n,t))}var Ii=e=>Fi(e,!Q(e)),Li=e=>Fi(e,Q(e)),Ri=e=>{let t=!Q(e);return $(e,t,n=>pi(e.state,n,t))},zi=e=>{let t=Q(e);return $(e,t,n=>pi(e.state,n,t))};function Bi(e,t){return $(e,t,n=>e.moveVertically(n,t))}var Vi=e=>Bi(e,!1),Hi=e=>Bi(e,!0);function Ui(e,t){return $(e,t,n=>e.moveVertically(n,t,yi(e).height))}var Wi=e=>Ui(e,!1),Gi=e=>Ui(e,!0),Ki=e=>$(e,!0,t=>Ci(e,t,!0)),qi=e=>$(e,!1,t=>Ci(e,t,!1)),Ji=e=>{let t=!Q(e);return $(e,t,n=>Ci(e,n,t))},Yi=e=>{let t=Q(e);return $(e,t,n=>Ci(e,n,t))},Xi=e=>$(e,!1,t=>Y.cursor(e.lineBlockAt(t.head).from)),Zi=e=>$(e,!0,t=>Y.cursor(e.lineBlockAt(t.head).to)),Qi=({state:e,dispatch:t})=>(t(ri(e,{anchor:0})),!0),$i=({state:e,dispatch:t})=>(t(ri(e,{anchor:e.doc.length})),!0),ea=({state:e,dispatch:t})=>(t(ri(e,{anchor:e.selection.main.anchor,head:0})),!0),ta=({state:e,dispatch:t})=>(t(ri(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),na=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:`select`})),!0),ra=({state:e,dispatch:t})=>{let n=Sa(e).map(({from:t,to:n})=>Y.undirectionalRange(t,Math.min(n+1,e.doc.length)));return t(e.update({selection:Y.create(n),userEvent:`select`})),!0},ia=({state:e,dispatch:t})=>{let n=ni(e.selection,t=>{let n=q(e),r=n.resolveStack(t.from,1);if(t.empty){let e=n.resolveStack(t.from,-1);e.node.from>=r.node.from&&e.node.to<=r.node.to&&(r=e)}for(let e=r;e;e=e.next){let{node:n}=e;if((n.from<t.from&&n.to>=t.to||n.to>t.to&&n.from<=t.from)&&e.next)return Y.undirectionalRange(n.from,n.to)}return t});return!n.eq(e.selection)&&(t(ri(e,n)),!0)};function aa(e,t){let{state:n}=e,r=n.selection,i=n.selection.ranges.slice();for(let r of n.selection.ranges){let a=n.doc.lineAt(r.head);if(t?a.to<e.state.doc.length:a.from>0)for(let n=r;;){let r=e.moveVertically(n,t);if(r.head<a.from||r.head>a.to){i.some(e=>e.head==r.head)||i.push(r);break}if(r.head==n.head)break;n=r}}return i.length!=r.ranges.length&&(e.dispatch(ri(n,Y.create(i,i.length-1))),!0)}var oa=e=>aa(e,!1),sa=e=>aa(e,!0),ca=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=Y.create([n.main]):n.main.empty||(r=Y.create([Y.cursor(n.main.head)])),r?(t(ri(e,r)),!0):!1};function la(e,t){if(e.state.readOnly)return!1;let n=`delete.selection`,{state:r}=e,i=r.changeByRange(r=>{let{from:i,to:a}=r;if(i==a){let o=t(r);o<i?(n=`delete.backward`,o=ua(e,o,!1)):o>i&&(n=`delete.forward`,o=ua(e,o,!0)),i=Math.min(i,o),a=Math.max(a,o)}else i=ua(e,i,!1),a=ua(e,a,!0);return i==a?{range:r}:{changes:{from:i,to:a},range:Y.cursor(i,i<r.head?-1:1)}});return!i.changes.empty&&(e.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:n==`delete.selection`?J.announce.of(r.phrase(`Selection deleted`)):void 0})),!0)}function ua(e,t,n){if(e instanceof J)for(let r of e.state.facet(J.atomicRanges).map(t=>t(e)))r.between(t,t,(e,r)=>{e<t&&r>t&&(t=n?r:e)});return t}var da=(e,t,n)=>la(e,r=>{let i=r.from,{state:a}=e,o=a.doc.lineAt(i),s,c;if(n&&!t&&i>o.from&&i<o.from+200&&!/[^ \t]/.test(s=o.text.slice(0,i-o.from))){if(s[s.length-1]==` `)return i-1;let e=gt(s,a.tabSize)%Ct(a)||Ct(a);for(let t=0;t<e&&s[s.length-1-t]==` `;t++)i--;c=i}else c=St(o.text,i-o.from,t,t)+o.from,c==i&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,i-o.from))&&(c=St(o.text,c-o.from,!1,!1)+o.from);return c}),fa=e=>da(e,!1,!0),pa=e=>da(e,!0,!1),ma=(e,t)=>la(e,n=>{let r=n.head,{state:i}=e,a=i.doc.lineAt(r),o=i.charCategorizer(r);for(let e=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?i.doc.lines:1)&&(r+=t?1:-1);break}let s=St(a.text,r-a.from,t)+a.from,c=a.text.slice(Math.min(r,s)-a.from,Math.max(r,s)-a.from),l=o(c);if(e!=null&&l!=e)break;(c!=` `||r!=n.head)&&(e=l),r=s}return r}),ha=e=>ma(e,!1),ga=e=>ma(e,!0),_a=e=>la(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),va=e=>la(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),ya=e=>la(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),ba=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:ht.of([``,``])},range:Y.cursor(e.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:`input`})),!0},xa=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(t=>{if(!t.empty||t.from==0||t.from==e.doc.length)return{range:t};let n=t.from,r=e.doc.lineAt(n),i=n==r.from?n-1:St(r.text,n-r.from,!1)+r.from,a=n==r.to?n+1:St(r.text,n-r.from,!0)+r.from;return{changes:{from:i,to:a,insert:e.doc.slice(n,a).append(e.doc.slice(i,n))},range:Y.cursor(a)}});return!n.changes.empty&&(t(e.update(n,{scrollIntoView:!0,userEvent:`move.character`})),!0)};function Sa(e){let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=i.number){let e=t[t.length-1];e.to=a.to,e.ranges.push(r)}else t.push({from:i.from,to:a.to,ranges:[r]});n=a.number+1}return t}function Ca(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let t of Sa(e)){if(n?t.to==e.doc.length:t.from==0)continue;let a=e.doc.lineAt(n?t.to+1:t.from-1),o=a.length+1;if(n){r.push({from:t.to,to:a.to},{from:t.from,insert:a.text+e.lineBreak});for(let n of t.ranges)i.push(Y.range(Math.min(e.doc.length,n.anchor+o),Math.min(e.doc.length,n.head+o)))}else{r.push({from:a.from,to:t.from},{from:t.to,insert:e.lineBreak+a.text});for(let e of t.ranges)i.push(Y.range(e.anchor-o,e.head-o))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:Y.create(i,e.selection.mainIndex),userEvent:`move.line`})),!0):!1}var wa=({state:e,dispatch:t})=>Ca(e,t,!1),Ta=({state:e,dispatch:t})=>Ca(e,t,!0);function Ea(e,t,n){if(e.readOnly)return!1;let r=[];for(let t of Sa(e))n?r.push({from:t.from,insert:e.doc.slice(t.from,t.to)+e.lineBreak}):r.push({from:t.to,insert:e.lineBreak+e.doc.slice(t.from,t.to)});let i=e.changes(r);return t(e.update({changes:i,selection:e.selection.map(i,n?1:-1),scrollIntoView:!0,userEvent:`input.copyline`})),!0}var Da=({state:e,dispatch:t})=>Ea(e,t,!1),Oa=({state:e,dispatch:t})=>Ea(e,t,!0),ka=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(Sa(t).map(({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n}))),r=ni(t.selection,t=>{let n;if(e.lineWrapping){let r=e.lineBlockAt(t.head),i=e.coordsAtPos(t.head,t.assoc||1);i&&(n=r.bottom+e.documentTop-i.bottom+e.defaultLineHeight/2)}return e.moveVertically(t,!0,n)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:`delete.line`}),!0};function Aa(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=q(e).resolveInner(t),r=n.childBefore(t),i=n.childAfter(t),a;return r&&i&&r.to<=t&&i.from>=t&&(a=r.type.prop(_t.closedBy))&&a.indexOf(i.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(i.from).from&&!/\S/.test(e.sliceDoc(r.to,i.from))?{from:r.to,to:i.from}:null}var ja=Na(!1),Ma=Na(!0);function Na(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(n=>{let{from:r,to:i}=n,a=t.doc.lineAt(r),o=!e&&r==i&&Aa(t,r);e&&(r=i=(i<=a.to?a:t.doc.lineAt(i)).to);let s=new vt(t,{simulateBreak:r,simulateDoubleBreak:!!o}),c=Et(s,r);for(c??=gt(/^\s*/.exec(t.doc.lineAt(r).text)[0],t.tabSize);i<a.to&&/\s/.test(a.text[i-a.from]);)i++;o?{from:r,to:i}=o:r>a.from&&r<a.from+100&&!/\S/.test(a.text.slice(0,r))&&(r=a.from);let l=[``,Tt(t,c)];return o&&l.push(Tt(t,s.lineIndent(a.from,-1))),{changes:{from:r,to:i,insert:ht.of(l)},range:Y.cursor(r+1+l[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:`input`})),!0}}function Pa(e,t){let n=-1;return e.changeByRange(r=>{let i=[];for(let a=r.from;a<=r.to;){let o=e.doc.lineAt(a);o.number>n&&(r.empty||r.to>o.from)&&(t(o,i,r),n=o.number),a=o.to+1}let a=e.changes(i);return{changes:i,range:Y.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}var Fa=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new vt(e,{overrideIndentation:e=>n[e]??-1}),i=Pa(e,(t,i,a)=>{let o=Et(r,t.from);if(o==null)return;/\S/.test(t.text)||(o=0);let s=/^\s*/.exec(t.text)[0],c=Tt(e,o);(s!=c||a.from<t.from+s.length)&&(n[t.from]=o,i.push({from:t.from,to:t.from+s.length,insert:c}))});return i.changes.empty||t(e.update(i,{userEvent:`indent`})),!0},Ia=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(Pa(e,(t,n)=>{n.push({from:t.from,insert:e.facet(ct)})}),{userEvent:`input.indent`})),!0),La=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(Pa(e,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let i=gt(r,e.tabSize),a=0,o=Tt(e,Math.max(0,i-Ct(e)));for(;a<r.length&&a<o.length&&r.charCodeAt(a)==o.charCodeAt(a);)a++;n.push({from:t.from+a,to:t.from+r.length,insert:o.slice(a)})}),{userEvent:`delete.dedent`})),!0),Ra=e=>(e.setTabFocusMode(),!0),za=[{key:`Ctrl-b`,run:si,shift:Ni,preventDefault:!0},{key:`Ctrl-f`,run:ci,shift:Pi},{key:`Ctrl-p`,run:_i,shift:Vi},{key:`Ctrl-n`,run:vi,shift:Hi},{key:`Ctrl-a`,run:Oi,shift:Xi},{key:`Ctrl-e`,run:ki,shift:Zi},{key:`Ctrl-d`,run:pa},{key:`Ctrl-h`,run:fa},{key:`Ctrl-k`,run:_a},{key:`Ctrl-Alt-h`,run:ha},{key:`Ctrl-o`,run:ba},{key:`Ctrl-t`,run:xa},{key:`Ctrl-v`,run:Si}],Ba=[{key:`ArrowLeft`,run:si,shift:Ni,preventDefault:!0},{key:`Mod-ArrowLeft`,mac:`Alt-ArrowLeft`,run:ui,shift:Ii,preventDefault:!0},{mac:`Cmd-ArrowLeft`,run:Ei,shift:Ji,preventDefault:!0},{key:`ArrowRight`,run:ci,shift:Pi,preventDefault:!0},{key:`Mod-ArrowRight`,mac:`Alt-ArrowRight`,run:di,shift:Li,preventDefault:!0},{mac:`Cmd-ArrowRight`,run:Di,shift:Yi,preventDefault:!0},{key:`ArrowUp`,run:_i,shift:Vi,preventDefault:!0},{mac:`Cmd-ArrowUp`,run:Qi,shift:ea},{mac:`Ctrl-ArrowUp`,run:xi,shift:Wi},{key:`ArrowDown`,run:vi,shift:Hi,preventDefault:!0},{mac:`Cmd-ArrowDown`,run:$i,shift:ta},{mac:`Ctrl-ArrowDown`,run:Si,shift:Gi},{key:`PageUp`,run:xi,shift:Wi},{key:`PageDown`,run:Si,shift:Gi},{key:`Home`,run:Ti,shift:qi,preventDefault:!0},{key:`Mod-Home`,run:Qi,shift:ea},{key:`End`,run:wi,shift:Ki,preventDefault:!0},{key:`Mod-End`,run:$i,shift:ta},{key:`Enter`,run:ja,shift:ja},{key:`Mod-a`,run:na},{key:`Backspace`,run:fa,shift:fa,preventDefault:!0},{key:`Delete`,run:pa,preventDefault:!0},{key:`Mod-Backspace`,mac:`Alt-Backspace`,run:ha,preventDefault:!0},{key:`Mod-Delete`,mac:`Alt-Delete`,run:ga,preventDefault:!0},{mac:`Mod-Backspace`,run:va,preventDefault:!0},{mac:`Mod-Delete`,run:ya,preventDefault:!0}].concat(za.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),Va=[{key:`Alt-ArrowLeft`,mac:`Ctrl-ArrowLeft`,run:mi,shift:Ri},{key:`Alt-ArrowRight`,mac:`Ctrl-ArrowRight`,run:hi,shift:zi},{key:`Alt-ArrowUp`,run:wa},{key:`Shift-Alt-ArrowUp`,run:Da},{key:`Alt-ArrowDown`,run:Ta},{key:`Shift-Alt-ArrowDown`,run:Oa},{key:`Mod-Alt-ArrowUp`,run:oa},{key:`Mod-Alt-ArrowDown`,run:sa},{key:`Escape`,run:ca},{key:`Mod-Enter`,run:Ma},{key:`Alt-l`,mac:`Ctrl-l`,run:ra},{key:`Mod-i`,run:ia,preventDefault:!0},{key:`Mod-[`,run:La},{key:`Mod-]`,run:Ia},{key:`Mod-Alt-\\`,run:Fa},{key:`Shift-Mod-k`,run:ka},{key:`Shift-Mod-\\`,run:ji},{key:`Mod-/`,run:br},{key:`Alt-A`,mac:`Ctrl-A`,run:Cr},{key:`Ctrl-m`,mac:`Shift-Alt-m`,run:Ra}].concat(Ba),Ha={key:`Tab`,run:Ia,shift:La},Ua=ut.define({combine:e=>e[0]??null}),Wa=/^[ \t]*\[\[!([^\]\n]+)\]\][ \t]*$/,Ga={question:`<path d="M8 2.5L13.5 8L8 13.5L2.5 8Z"/>`,problem:`<path d="M8 2.5l5.8 10.5H2.2z"/>`,note:`<rect x="3.5" y="2.5" width="9" height="11"/>`},Ka=`<path d="M3 8.5l3 3 7-7"/>`,qa=class extends at{ref;found;at;constructor(e,t,n){super(),this.ref=e,this.found=t,this.at=n}eq(e){return e.ref===this.ref&&JSON.stringify(e.found)===JSON.stringify(this.found)&&e.at===this.at}toDOM(e){let t=this.found,n=document.createElement(`div`);n.className=`cm-lp-embed${t?` cm-lp-embed-${t.kind}`:` cm-lp-embed-broken`}${t?.done?` cm-lp-embed-done`:``}`,n.title=`[[!${this.ref}]]`;let r=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);r.setAttribute(`viewBox`,`0 0 16 16`),r.setAttribute(`width`,`16`),r.setAttribute(`height`,`16`),r.setAttribute(`aria-hidden`,`true`),r.innerHTML=t?.done?Ka:Ga[t?.kind??`question`];let i=document.createElement(`span`);return i.textContent=t?t.title:this.ref,n.append(r,i),n.addEventListener(`mousedown`,n=>{n.preventDefault(),t&&!n.altKey?e.state.facet(Ua)?.open(t.id):(e.dispatch({selection:{anchor:this.at},scrollIntoView:!0}),e.focus())}),n}ignoreEvent(){return!0}get estimatedHeight(){return 44}},Ja=class extends at{kind;source;at;beneath;constructor(e,t,n,r){super(),this.kind=e,this.source=t,this.at=n,this.beneath=r}eq(e){return e.kind===this.kind&&e.source===this.source&&e.at===this.at&&e.beneath===this.beneath}toDOM(e){let t=document.createElement(`div`);t.className=`cm-lp-block cm-lp-${this.kind}${this.beneath?` cm-lp-beneath`:``}`;let n=document.createElement(`div`);return n.className=`prose`,t.append(n),n.innerHTML=Le(this.source),this.beneath||(t.title=`Click to edit`,t.addEventListener(`mousedown`,t=>{t.preventDefault(),e.dispatch({selection:{anchor:this.at},scrollIntoView:!0}),e.focus()})),t}ignoreEvent(){return!0}get estimatedHeight(){return this.kind===`maths`?60:120}},Ya=new WeakMap,Xa=class extends at{source;at;beneath;constructor(e,t,n){super(),this.source=e,this.at=t,this.beneath=n}eq(e){return e.source===this.source&&e.at===this.at&&e.beneath===this.beneath}toDOM(e){let t=document.createElement(`div`);t.className=`cm-lp-block cm-lp-diagram${this.beneath?` cm-lp-beneath`:``}`;let n=document.createElement(`pre`);n.className=`cm-lp-diagram-src`,n.textContent=this.source;let r=document.createElement(`div`);return r.className=`diagram`,t.append(n,r),Ya.set(t,{mounted:ze(r,this.source,()=>t.classList.add(`cm-lp-broken-diagram`)),source:this.source}),this.beneath||(t.title=`Click to edit`,t.addEventListener(`mousedown`,t=>{t.preventDefault(),e.dispatch({selection:{anchor:this.at},scrollIntoView:!0}),e.focus()})),t}updateDOM(e){let t=Ya.get(e);return!t||!this.beneath||!e.classList.contains(`cm-lp-beneath`)?!1:(t.source!==this.source&&(t.source=this.source,e.classList.remove(`cm-lp-broken-diagram`),e.querySelector(`.cm-lp-diagram-src`).textContent=this.source,t.mounted.then(e=>He(e,this.source))),!0)}ignoreEvent(){return!0}get estimatedHeight(){return 160}},Za=(e,t)=>t!==null&&e.sliceDoc(t.from,t.to).trim().split(/\s/)[0].toLowerCase()===`mermaid`;function Qa(e){let t=[],n=e.selection.ranges;q(e).iterate({enter:r=>{let i=null,a=``;if(r.name===`BlockMath`)i=`maths`,a=e.sliceDoc(r.from,r.to);else if(r.name===`Table`)i=`table`,a=e.sliceDoc(r.from,r.to);else if(r.name===`FencedCode`&&Za(e,r.node.getChild(`CodeInfo`))){let i=r.node.getChild(`CodeText`),a=i?e.sliceDoc(i.from,i.to):``,o=e.doc.lineAt(r.from).from,s=e.doc.lineAt(r.to).to;return n.some(e=>e.to>=o&&e.from<=s)?a.trim()&&t.push(Z.widget({widget:new Xa(a,r.from,!0),block:!0,side:1}).range(s)):t.push(Z.replace({widget:new Xa(a,r.from,!1),block:!0}).range(o,s)),!1}else if(r.name===`Document`||r.name===`Blockquote`||/List|ListItem/.test(r.name))return;if(!i)return!1;let o=e.doc.lineAt(r.from).from,s=e.doc.lineAt(r.to).to;return n.some(e=>e.to>=o&&e.from<=s)?i!==`table`&&a.trim()&&t.push(Z.widget({widget:new Ja(i,a,r.from,!0),block:!0,side:1}).range(s)):t.push(Z.replace({widget:new Ja(i,a,r.from,!1),block:!0}).range(o,s)),!1}});let r=e.facet(Ua);if(r){let i=!1;for(let a=1;a<=e.doc.lines;a++){let o=e.doc.line(a);if(/^\s*(```|~~~)/.test(o.text)){i=!i;continue}let s=i?null:Wa.exec(o.text);if(!s||n.some(e=>e.to>=o.from&&e.from<=o.to))continue;let c=s[1].trim();t.push(Z.replace({widget:new qa(c,r.find(c),o.from),block:!0}).range(o.from,o.to))}}return Z.set(t,!0)}var $a=bt.define({create:Qa,update(e,t){return t.docChanged||t.selection||q(t.startState)!==q(t.state)?Qa(t.state):e},provide:e=>J.decorations.from(e)}),eo=J.theme({".cm-lp-block":{padding:`0`,cursor:`text`},".cm-lp-block .katex-display > .katex":{fontSize:`1.17em`},".cm-lp-block .prose":{maxWidth:`none`},".cm-lp-block .prose > :last-child, .cm-lp-block .table-wrap":{marginBottom:`0`},".cm-lp-block .katex-display":{margin:`0`},".cm-lp-diagram .diagram":{overflowX:`auto`,overflowY:`hidden`},".cm-lp-diagram-src":{display:`none`,margin:`0`,font:`13px/20px var(--font-mono)`,whiteSpace:`pre-wrap`,color:`var(--text-soft)`},".cm-lp-diagram.cm-lp-broken-diagram:not(.cm-lp-beneath) .cm-lp-diagram-src":{display:`block`},".cm-lp-beneath":{borderLeft:`2px solid var(--line)`,paddingLeft:`12px`,marginTop:`4px`,opacity:`.9`},".cm-lp-block:not(.cm-lp-beneath):hover":{outline:`1px dashed var(--line)`,outlineOffset:`2px`},".cm-lp-embed":{display:`flex`,alignItems:`center`,gap:`10px`,padding:`9px 12px`,border:`1px solid var(--rose)`,borderLeftWidth:`3px`,background:`var(--rose-soft)`,fontFamily:`var(--font-text)`,fontSize:`16px`,lineHeight:`1.45`,cursor:`pointer`},".cm-lp-embed svg":{flex:`none`,fill:`none`,stroke:`var(--rose)`,strokeWidth:`1.4`},".cm-lp-embed-problem":{borderColor:`var(--line-strong)`,background:`var(--ground-1)`},".cm-lp-embed-problem svg":{stroke:`var(--text-soft)`},".cm-lp-embed-done":{borderColor:`var(--malachite)`,background:`var(--malachite-soft)`},".cm-lp-embed-done svg":{stroke:`var(--malachite)`},".cm-lp-embed-broken":{borderStyle:`dashed`,borderColor:`var(--line-strong)`,background:`none`,color:`var(--text-faint)`},".cm-lp-embed-broken svg":{stroke:`var(--text-faint)`},".cm-lp-embed:hover":{borderColor:`var(--text-soft)`}});function to(e,t){let{state:n}=e,r=t.length;return e.dispatch(n.changeByRange(e=>{let i=n.sliceDoc(e.from-r,e.from),a=n.sliceDoc(e.to,e.to+r);return i===t&&a===t?{changes:[{from:e.from-r,to:e.from},{from:e.to,to:e.to+r}],range:Y.range(e.from-r,e.to-r)}:{changes:[{from:e.from,insert:t},{from:e.to,insert:t}],range:Y.range(e.from+r,e.to+r)}}),{scrollIntoView:!0,userEvent:`input`}),!0}function no(e){let{state:t}=e,n=new Map;for(let e of t.selection.ranges)for(let r=e.from;r<=e.to;){let e=t.doc.lineAt(r);n.set(e.number,{from:e.from,text:e.text}),r=e.to+1}return[...n.values()]}function ro(e){let t=no(e).map(({from:e,text:t})=>{let n=/^(#{1,6}) /.exec(t),r=n?n[1].length:0,i=r>=3?``:`#`.repeat(r+1)+` `;return{from:e,to:e+(n?n[0].length:0),insert:i}});return e.dispatch({changes:t,scrollIntoView:!0,userEvent:`input`}),!0}function io(e){let t=no(e),n=t.every(({text:e})=>/^\s*[-*+] /.test(e)),r=t.map(({from:e,text:t})=>{if(n){let n=/^(\s*)[-*+] /.exec(t);return{from:e+n[1].length,to:e+n[0].length}}return{from:e+/^\s*/.exec(t)[0].length,insert:`- `}});return e.dispatch({changes:r,scrollIntoView:!0,userEvent:`input`}),!0}function ao(e){let{state:t}=e,n=t.selection.main;if(n.empty)e.dispatch({changes:{from:n.from,insert:`[[]]`},selection:{anchor:n.from+2},userEvent:`input`});else{let r=t.sliceDoc(n.from,n.to);e.dispatch({changes:{from:n.from,to:n.to,insert:`[${r}]()`},selection:{anchor:n.from+r.length+3},userEvent:`input`})}return Ot(e),!0}function oo(e,t){switch(t){case`bold`:return to(e,`**`);case`italic`:return to(e,`*`);case`maths`:return to(e,`$`);case`heading`:return ro(e);case`list`:return io(e);case`link`:return ao(e);case`undo`:return Rr(e);case`redo`:return zr(e)}}var so=[{key:`Mod-b`,preventDefault:!0,run:e=>oo(e,`bold`)},{key:`Mod-i`,preventDefault:!0,run:e=>oo(e,`italic`)},{key:`Mod-k`,preventDefault:!0,run:e=>oo(e,`link`)},{key:`Mod-Shift-m`,preventDefault:!0,run:e=>oo(e,`maths`)},{key:`Mod-Shift-h`,preventDefault:!0,run:e=>oo(e,`heading`)},{key:`Mod-Shift-8`,preventDefault:!0,run:e=>oo(e,`list`)}],co=[`requires`,`uses`,`see also`];function lo(e){if(!e||/^[a-z][a-z0-9+.-]*:/i.test(e)||e.startsWith(`#`))return null;let t=e.split(`#`)[0].split(`?`)[0];return/\.html?$/i.test(t)?`artifact`:/\.(png|jpe?g|gif|svg|webp|avif)$/i.test(t)?`image`:/\.md$/i.test(t)||t.endsWith(`/`)?`note`:null}function uo(e,t){let n=q(e);for(let r of[-1,1])for(let i=n.resolveInner(t,r);i;i=i.parent){if(i.name!==`Link`&&i.name!==`Image`)continue;let t=i.getChild(`URL`);if(!t)break;let n=e.sliceDoc(t.from,t.to),r=lo(n);if(!r)return null;let a=i.getChild(`LinkTitle`),o=a?e.sliceDoc(a.from,a.to):null;return{from:i.from,to:i.to,embed:i.name===`Image`,url:n,urlTo:t.to,title:o===null?null:o.replace(/^["'(]|["')]$/g,``),titleFrom:a?a.from:t.to,titleTo:a?a.to:t.to,kind:r}}return null}var fo=e=>e.kind===`note`||e.kind===`artifact`&&!e.embed;function po(e,t,n){let r=[];return q(e).iterate({from:t,to:n,enter:i=>{if(i.name!==`Link`&&i.name!==`Image`)return;if(i.from<t||i.to>n)return!1;let a=uo(e,i.from+1);return a&&a.from===i.from&&fo(a)&&r.push(a),!1}}),r}var mo=(e,t)=>e.filter(e=>go(e)!==t).map(e=>vo(e,t)),ho=e=>(e??``).trim().toLowerCase().replace(/[-_]/g,` `),go=e=>co.includes(ho(e.title))?ho(e.title):ho(e.title)===`seealso`?`see also`:null,_o=e=>ho(e.title)===`left`?`left`:`center`;function vo(e,t){return t===null?{from:e.urlTo,to:e.titleTo,insert:``}:e.titleFrom===e.titleTo?{from:e.urlTo,insert:` "${t}"`}:{from:e.titleFrom,to:e.titleTo,insert:`"${t}"`}}function yo(e,t){if(e.embed===t)return[];let n=[t?{from:e.from,insert:`!`}:{from:e.from,to:e.from+1,insert:``}];return e.title!==null&&(e.kind===`image`||go(e)!==null)&&n.push(vo(e,null)),n}var bo=(e,t)=>e.dispatch({changes:t,userEvent:`input.link`});function xo(e){let t=[...co.map(t=>({label:t[0].toUpperCase()+t.slice(1),on:go(e)===t,run:(e,n)=>bo(e,vo(n,t)),hint:t===`requires`?`This note cannot be followed without it: it shapes the Atlas and the study order`:t===`uses`?`It draws on it: it shapes the Atlas`:`Related reading: shown, but it does not shape the Atlas`})),{label:`Unrated`,on:go(e)===null,run:(e,t)=>bo(e,vo(t,null)),hint:`No rating: counted as uses`}];if(e.kind===`note`)return t;let n=[{label:`Shown here`,on:e.embed,run:(e,t)=>bo(e,yo(t,!0)),hint:e.kind===`image`?`The picture is shown in the note`:`The artifact is shown in the note, working`},{label:`Link`,on:!e.embed,run:(e,t)=>bo(e,yo(t,!1)),hint:`A link to it; it opens on its own`}];return e.kind===`image`?e.embed?[...n,{label:`Centre`,on:_o(e)===`center`,run:(e,t)=>bo(e,vo(t,null)),hint:`In the middle, 80% of the text's width`},{label:`Left`,on:_o(e)===`left`,run:(e,t)=>bo(e,vo(t,`left`)),hint:`At the left, 80% of the text's width`}]:n:e.embed?n:[...n,...t]}function So(e){let t=t=>e.every(e=>go(e)===t),n=e.length;return[...co.map(e=>({label:e[0].toUpperCase()+e.slice(1),on:t(e),run:t=>bo(t,mo(po(t.state,t.state.selection.main.from,t.state.selection.main.to),e)),hint:`Rate all ${n} links ${e}`})),{label:`Unrated`,on:t(null),run:e=>bo(e,mo(po(e.state,e.state.selection.main.from,e.state.selection.main.to),null)),hint:`Take the rating from all ${n} links`}]}function Co(e){let t=go(e[0]),n=e.every(e=>go(e)===t);return`${e.length} links, ${n?t??`unrated`:`mixed`}`}function wo(e){return e.kind===`note`?go(e)?go(e)[0].toUpperCase()+go(e).slice(1):`Unrated`:e.embed?e.kind===`image`?_o(e)===`left`?`Shown, left`:`Shown, centre`:`Shown here`:go(e)?`Link, ${go(e)}`:`Link`}var To=(e,t)=>e===t||!!e&&!!t&&e.from===t.from&&e.to===t.to&&e.title===t.title&&e.embed===t.embed,Eo=class{view;layer;button;menu;leader;path;link=null;hover=null;many=[];open=!1;at=0;constructor(e){this.view=e,this.layer=document.createElement(`div`),this.layer.className=`cm-link-control`,this.layer.hidden=!0,this.leader=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`),this.leader.setAttribute(`class`,`cm-link-leader`),this.leader.setAttribute(`aria-hidden`,`true`),this.path=document.createElementNS(`http://www.w3.org/2000/svg`,`path`),this.leader.append(this.path),this.button=document.createElement(`button`),this.button.type=`button`,this.button.className=`cm-link-button`,this.button.setAttribute(`aria-haspopup`,`menu`),this.button.addEventListener(`mousedown`,e=>e.preventDefault()),this.button.addEventListener(`click`,()=>this.toggle(!this.open,!1)),this.menu=document.createElement(`div`),this.menu.className=`cm-link-menu`,this.menu.setAttribute(`role`,`menu`),this.menu.hidden=!0,this.menu.tabIndex=-1,this.menu.addEventListener(`keydown`,e=>this.keys(e)),this.layer.append(this.leader,this.button,this.menu),e.dom.append(this.layer),e.dom.addEventListener(`mousemove`,this.onMove),e.dom.addEventListener(`mouseleave`,this.onLeave)}onMove=e=>{if(this.open||this.layer.contains(e.target))return;let t=this.view.posAtCoords({x:e.clientX,y:e.clientY},!1),n=t===null?null:uo(this.view.state,t);To(n,this.hover)||(this.hover=n,this.view.requestMeasure(this.measure))};onLeave=e=>{this.open||this.layer.contains(e.relatedTarget)||this.hover&&(this.hover=null,this.view.requestMeasure(this.measure))};selected(){let e=this.view.state.selection.main;if(e.empty)return[];let t=po(this.view.state,e.from,e.to);return t.length>=2?t:[]}current(){let e=this.view.state.selection.main,t=this.selected();return t.length?t[0]:uo(this.view.state,e.head)??(e.empty?this.hover:null)}update(e){e.docChanged&&(this.hover=null),(e.docChanged||e.selectionSet||e.geometryChanged||e.viewportChanged||e.focusChanged)&&this.view.requestMeasure(this.measure)}measure={key:`link-control`,read:e=>{let t=this.current();if(!t)return null;let n=this.selected(),r=e.dom.getBoundingClientRect(),i=e.contentDOM.getBoundingClientRect(),a=e.coordsAtPos(Math.max(t.from,t.to-1),1)??e.coordsAtPos(t.to,-1);if(n.length){let t=Math.max(r.top,0),i=Math.min(r.bottom,window.innerHeight);a=null;for(let r=n.length-1;r>=0&&!a;r--){let o=e.coordsAtPos(Math.max(n[r].from,n[r].to-1),1);o&&o.top>=t&&o.bottom<=i-34&&(a=o)}a??=e.coordsAtPos(Math.max(n[0].from,n[0].to-1),1)}return a?{l:t,many:n,x:a.right-r.left,y:(a.top+a.bottom)/2-r.top,right:i.right-r.left,width:r.width}:null},write:e=>{if(!e){this.link=null,this.many=[],this.layer.hidden=!0,this.toggle(!1,!1);return}let t=e.many.length?Co(e.many):wo(e.l),n=!To(e.l,this.link)||e.many.length!==this.many.length||t!==this.button.textContent;this.link=e.l,this.many=e.many,this.layer.hidden=!1,this.button.textContent=t,this.button.title=e.many.length?`Rate all the selected links (Alt+L)`:`What this link is (Alt+L)`,this.button.setAttribute(`aria-label`,e.many.length?`${t}. Rate them all`:`This link: ${t}. Change it`);let r=this.button.offsetWidth||90,i=e.width-e.right>=r+20,a=i?e.right+14:Math.max(0,e.width-r-2),o=i?e.y-13:e.y+12;this.button.style.transform=`translate(${Math.round(a)}px, ${Math.round(o)}px)`,this.menu.style.transform=`translate(${Math.round(Math.min(a,e.width-250))}px, ${Math.round(o+30)}px)`;let s=a,c=o+13;this.path.setAttribute(`d`,i?`M${e.x+3} ${e.y} H${Math.max(e.x+3,s-3)}`:`M${e.x+3} ${e.y} V${c} H${s-3}`),n&&this.open&&(this.fill(),this.mark(this.at))}};fill(){let e=this.link;e&&this.menu.replaceChildren(...(this.many.length?So(this.many):xo(e)).map((t,n)=>{let r=document.createElement(`button`);return r.type=`button`,r.tabIndex=-1,r.id=`cm-link-choice-${n}`,r.addEventListener(`mousedown`,e=>e.preventDefault()),r.addEventListener(`mousemove`,()=>this.mark(n)),r.setAttribute(`role`,`menuitemradio`),r.setAttribute(`aria-checked`,String(t.on)),r.title=t.hint,r.innerHTML=`<b></b><span></span>`,r.querySelector(`b`).textContent=t.label,r.querySelector(`span`).textContent=t.hint,r.addEventListener(`click`,()=>{let n=this.current()??e;t.run(this.view,n),this.toggle(!1,!0)}),r}))}toggle(e,t){if(e&&(this.link=this.current()??this.link,this.many=this.selected()),!e||this.link){if(this.open=e,this.menu.hidden=!e,this.layer.classList.toggle(`open`,e),this.button.setAttribute(`aria-expanded`,String(e)),e){this.fill();let e=[...this.menu.querySelectorAll(`button`)];this.mark(Math.max(0,e.findIndex(e=>e.getAttribute(`aria-checked`)===`true`))),this.menu.focus()}else t&&this.view.focus()}}mark(e){let t=[...this.menu.querySelectorAll(`button`)];this.at=t.length?(e+t.length)%t.length:0,t.forEach((e,t)=>e.classList.toggle(`on`,t===this.at)),this.menu.setAttribute(`aria-activedescendant`,t[this.at]?.id??``)}keys(e){let t=[...this.menu.querySelectorAll(`button`)],n=!0;if(e.key===`Escape`)this.toggle(!1,!0);else if(e.key===`Enter`||e.key===` `)t[this.at]?.click();else if(e.key===`ArrowDown`)this.mark(this.at+1);else if(e.key===`ArrowUp`)this.mark(this.at-1);else if(e.key===`Home`)this.mark(0);else if(e.key===`End`)this.mark(t.length-1);else if(e.key===`Tab`)this.toggle(!1,!0);else if(e.key.length===1&&!e.altKey&&!e.ctrlKey&&!e.metaKey){let r=t.findIndex(t=>t.textContent.toLowerCase().startsWith(e.key.toLowerCase()));r>=0?this.mark(r):n=!1}else n=!1;n&&(e.preventDefault(),e.stopPropagation())}destroy(){this.view.dom.removeEventListener(`mousemove`,this.onMove),this.view.dom.removeEventListener(`mouseleave`,this.onLeave),this.layer.remove()}},Do=rt.fromClass(Eo),Oo=e=>t=>{let n=uo(t.state,t.state.selection.main.head);return n?(e(t,n),!0):!1},ko=e=>t=>{let n=t.state.selection.main,r=n.empty?[]:po(t.state,n.from,n.to);return r.length>=2?(bo(t,mo(r,e)),!0):Oo((t,n)=>{fo(n)&&bo(t,vo(n,e))})(t)},Ao=[{key:`Alt-l`,run:e=>{let t=e.plugin(Do);return!t||!t.current()?!1:(t.toggle(!0,!1),!0)}},{key:`Alt-1`,run:ko(`requires`)},{key:`Alt-2`,run:ko(`uses`)},{key:`Alt-3`,run:ko(`see also`)},{key:`Alt-0`,run:ko(null)},{key:`Alt-e`,run:Oo((e,t)=>{t.kind!==`note`&&bo(e,yo(t,!t.embed))})}],jo=[Do,J.baseTheme({"&":{position:`relative`},".cm-link-control":{position:`absolute`,inset:`0`,pointerEvents:`none`,zIndex:`4`,overflow:`visible`},".cm-link-control[hidden]":{display:`none`},".cm-link-leader":{position:`absolute`,left:`0`,top:`0`,width:`100%`,height:`100%`,overflow:`visible`},".cm-link-leader path":{fill:`none`,stroke:`var(--lattice)`,strokeWidth:`1.75`,strokeDasharray:`.1 5`,strokeLinecap:`round`,opacity:`.7`},".cm-link-control:hover .cm-link-leader path, .cm-link-control:focus-within .cm-link-leader path, .cm-link-control.open .cm-link-leader path":{opacity:`1`,animation:`cm-link-run .6s linear infinite`},"@keyframes cm-link-run":{to:{strokeDashoffset:`-5.1`}},"@media (prefers-reduced-motion: reduce)":{".cm-link-leader path":{animation:`none !important`}},".cm-link-button":{position:`absolute`,left:`0`,top:`0`,pointerEvents:`auto`,height:`26px`,padding:`0 9px`,font:`12.5px var(--font-ui)`,whiteSpace:`nowrap`,color:`var(--text)`,background:`var(--ground-1)`,border:`1px solid var(--lattice)`,cursor:`pointer`},".cm-link-button:hover, .cm-link-button[aria-expanded=true]":{background:`var(--lattice-soft)`},".cm-link-button:focus-visible":{outline:`2px solid var(--focus-ring)`,outlineOffset:`2px`},".cm-link-menu":{position:`absolute`,left:`0`,top:`0`,pointerEvents:`auto`,width:`248px`,padding:`4px`,background:`var(--ground-1)`,border:`1px solid var(--line)`,display:`grid`,gap:`1px`},".cm-link-menu[hidden]":{display:`none`},".cm-link-menu button":{display:`grid`,gap:`1px`,textAlign:`left`,padding:`6px 8px 6px 24px`,background:`none`,border:`0`,color:`var(--text)`,font:`13.5px var(--font-ui)`,cursor:`pointer`,position:`relative`},".cm-link-menu button b":{fontWeight:`600`},".cm-link-menu button span":{fontSize:`12px`,color:`var(--text-faint)`,lineHeight:`1.3`},".cm-link-menu button[aria-checked=true]::before":{content:`"●"`,position:`absolute`,left:`8px`,top:`7px`,fontSize:`10px`,color:`var(--lattice)`},".cm-link-menu:focus":{outline:`none`},".cm-link-menu button.on":{background:`var(--lattice-soft)`},".cm-link-menu:focus-visible button.on":{outline:`2px solid var(--focus-ring)`,outlineOffset:`-2px`}}),$e.of(Ao)],Mo=e=>{let t=e.trim().replace(/[-_]+/g,` `).replace(/\s+/g,` `);return t?t[0].toUpperCase()+t.slice(1):``};function No(e,t=null){return n=>{let r=n.matchBefore(/\[\[(?!!)[^\]\n]*$/);if(!r)return null;let i=e().map(e=>({label:e.title,detail:e.folder,apply:(t,n,r,i)=>{let a=`[${e.title}](/${e.id}.md)`,o=r-2,s=t.state.sliceDoc(i,i+2)===`]]`?i+2:i;t.dispatch({changes:{from:o,to:s,insert:a},selection:{anchor:o+a.length}})}})),a=n.state.sliceDoc(r.from+2,n.pos),o=t?.plan(a)??null;return t&&o&&!e().some(e=>e.id===o.id)&&i.push({label:a,detail:`a new note${o.folder?` in ${o.folder}`:``}`,type:`create`,boost:-2,apply:(e,n,r,i)=>{let a=`[${o.title}](/${o.id}.md)`,s=r-2,c=e.state.sliceDoc(i,i+2)===`]]`?i+2:i;e.dispatch({changes:{from:s,to:c,insert:a},selection:{anchor:s+a.length}}),t.make(o)}}),{from:r.from+2,options:i,filter:!0,...t?{}:{validFor:/^[^\]\n]*$/}}}}var Po=e=>e.split(`/`).at(-1).replace(/\.[^.]+$/,``).replace(/[-_]+/g,` `).trim(),Fo=e=>/[\s()<>]/.test(e)?`<${e}>`:e;function Io(e,t){return async n=>{let r=n.matchBefore(/\[\[![^\]\n]*$/);if(!r)return null;let i=(e,t,n,r,i)=>{let a=t-3,o=e.state.sliceDoc(n,n+2)===`]]`?n+2:n;e.dispatch({changes:{from:a,to:o,insert:r},selection:i?{anchor:a+i[0],head:a+i[1]}:{anchor:a+r.length}})},a=t?.here()??``,o=a.includes(`/`)?a.slice(0,a.lastIndexOf(`/`)):``,s=(t?await t.pictures().catch(()=>[]):[]).map(e=>{let t=e.path.includes(`/`)?e.path.slice(0,e.path.lastIndexOf(`/`)):``;return{label:e.path.split(`/`).at(-1),detail:t,picture:e,type:`picture`,boost:t===a?2:+(t===o),info:()=>zo(e),apply:(t,n,r,a)=>{let o=Po(e.path),s=`![${o}](/${Fo(e.path)})`;i(t,r,a,s,[2,2+o.length])}}}),c=e().map(e=>e.id);for(let t of e())t.kind&&s.push({label:t.title,detail:t.kind,boost:-1,apply:(e,n,r,a)=>i(e,r,a,G(t.id,c))});return t&&s.push({label:`Paste or drop a picture to add one`,type:`hint`,boost:-99,apply:()=>void 0}),{from:r.from+3,options:s,filter:!0,validFor:/^[^\]\n]*$/}}}function Lo(e,t){return async n=>{let r=n.matchBefore(/\]\([^)\s]*$/);if(!r)return null;let i=t?await t.pictures().catch(()=>[]):[];return{from:r.from+2,options:[...e().map(e=>({label:`/${e.id}.md`,detail:e.title})),...i.map(e=>({label:`/${e.path}`,detail:`picture`,picture:e,type:`picture`,info:()=>zo(e)}))],validFor:/^[^)\s]*$/}}}function Ro(e,t){e.alt=``,e.decoding=`async`,typeof t.src==`string`?e.src=t.src:t.src.then(t=>{t&&(e.src=t)})}function zo(e){let t=document.createElement(`div`);t.className=`cm-picture-preview`;let n=document.createElement(`img`);Ro(n,e);let r=document.createElement(`div`);return r.className=`cm-picture-size`,r.textContent=e.width&&e.height?`${e.width} × ${e.height}`:``,t.append(n,r),t}function Bo(e,t=null,n=null){return kt({override:[Io(e,t),No(e,n),Lo(e,t)],icons:!1,activateOnTyping:!0,addToOptions:[{position:20,render:e=>{if(!e.picture)return null;let t=document.createElement(`img`);return t.className=`cm-picture-thumb`,t.loading=`lazy`,Ro(t,e.picture),t}}]})}var Vo=36,Ho=92,Uo=40,Wo=/^\$\$([^$]*?[^\\])\$\$/,Go=/^\$((?:[^\s\\])|(?:\S.*?[^\s\\]))\$(?!\d)/,Ko=/^\\\((.+?)\\\)/,qo=/^\$\$([^$]*?[^\\])\$\$(?:[ \t]*\([^)\s]+?\))?(?=[ \t]*(?:\n|$))/,Jo=/^\\\[([\s\S]+?)\\\](?:[ \t]*\([^)$\r\n]+?\))?(?=[ \t]*(?:\n|$))/;function Yo(e,t,n){if(t===Vo){if(n>e.offset&&e.char(n-1)===Ho)return-1;let t=e.slice(n,e.end),r=(t.charCodeAt(1)===Vo?Wo:Go).exec(t);return r?e.addElement(e.elt(`InlineMath`,n,n+r[0].length,[e.elt(`MathMark`,n,n+(r[0].startsWith(`$$`)?2:1)),e.elt(`MathMark`,n+r[0].length-(r[0].startsWith(`$$`)?2:1),n+r[0].length)])):-1}if(t===Ho&&e.char(n+1)===Uo){let t=Ko.exec(e.slice(n,e.end));if(!t)return-1;let r=n+t[0].length;return e.addElement(e.elt(`InlineMath`,n,r,[e.elt(`MathMark`,n,n+2),e.elt(`MathMark`,r-2,r)]))}return-1}var Xo=2e4;function Zo(e,t){let n=t.text.slice(t.pos),r=n.startsWith(`$$`)?qo:n.startsWith(`\\[`)?Jo:null;if(!r)return!1;let i=e.lineStart+t.pos,a=e.input,o=r.exec(a.read(i,Math.min(a.length,i+Xo)));if(!o)return!1;let s=i+o[0].length;for(;e.lineStart+t.text.length<s&&e.nextLine(););return e.addElement(e.elt(`BlockMath`,i,s)),e.nextLine(),!0}var Qo={defineNodes:[{name:`InlineMath`,style:X.special(X.content)},{name:`BlockMath`,block:!0,style:X.special(X.content)},{name:`MathMark`,style:X.processingInstruction}],parseInline:[{name:`InlineMath`,parse:Yo,before:`Escape`}],parseBlock:[{name:`BlockMath`,parse:Zo,before:`FencedCode`}]};function $o(e){let t;return(t=/^\$\$([\s\S]*?)\$\$/.exec(e))||(t=/^\\\[([\s\S]*?)\\\]/.exec(e))?{tex:t[1],display:!0}:(t=/^\\\(([\s\S]*?)\\\)$/.exec(e))||(t=/^\$([\s\S]*?)\$$/.exec(e))?{tex:t[1],display:!1}:{tex:e,display:!1}}var es=class extends at{eq(){return!0}toDOM(){let e=document.createElement(`span`);return e.className=`cm-lp-bullet`,e.textContent=`•`,e}},ts=class extends at{eq(){return!0}toDOM(){let e=document.createElement(`span`);return e.className=`cm-lp-hr`,e}},ns=class extends at{name;constructor(e){super(),this.name=e}eq(e){return e.name===this.name}toDOM(){let e=document.createElement(`span`);return e.className=`cm-lp-lang`,e.textContent=this.name,e}},rs=class extends at{source;constructor(e){super(),this.source=e}eq(e){return e.source===this.source}toDOM(){let e=document.createElement(`span`);e.className=`cm-lp-imaths`;let{tex:t,display:n}=$o(this.source);return e.innerHTML=je.renderToString(t,{displayMode:n,throwOnError:!1}),e}},is=class extends at{key;src;alt;left;constructor(e,t,n,r){super(),this.key=e,this.src=t,this.alt=n,this.left=r}eq(e){return e.key===this.key&&e.alt===this.alt&&e.left===this.left}toDOM(e){let t=document.createElement(`span`);t.className=this.left?`cm-lp-picture cm-lp-picture-left`:`cm-lp-picture`;let n=()=>{t.replaceChildren(),t.classList.add(`cm-lp-picture-broken`),t.textContent=this.key.replace(/^notes:/,``),t.title=this.key.startsWith(`code:`)?`not in the repository`:`not in the notes`,e.requestMeasure()},r=document.createElement(`img`);return r.alt=this.alt,this.alt&&(r.title=this.alt),r.loading=`lazy`,r.decoding=`async`,r.onload=()=>e.requestMeasure(),r.onerror=n,t.append(r),typeof this.src==`string`?r.src=this.src:this.src.then(e=>{e?r.src=e:n()}),t}ignoreEvent(){return!1}},as=class extends at{path;mount;constructor(e,t){super(),this.path=e,this.mount=t}eq(e){return e.path===this.path}stop=null;toDOM(e){let t=document.createElement(`span`);return t.className=`cm-lp-artifact`,this.stop=this.mount(t),new ResizeObserver(()=>e.requestMeasure()).observe(t),t}destroy(){this.stop?.(),this.stop=null}ignoreEvent(){return!0}},os=Z.replace({}),ss=Z.replace({widget:new es}),cs=Z.replace({widget:new ts}),ls=e=>Z.mark({class:e}),us=e=>Z.line({class:e});function ds(e,t){let n=new Set;if(!t)return n;for(let t of e.selection.ranges){let r=e.doc.lineAt(t.from).number,i=e.doc.lineAt(t.to).number;for(let e=r;e<=i;e++)n.add(e)}return n}function fs(e){let{state:t}=e,n=ds(t,e.hasFocus),r=e=>n.has(t.doc.lineAt(e).number),i=[],a=(e,n,r)=>{for(let a=t.doc.lineAt(e).number,o=t.doc.lineAt(n).number;a<=o;a++)i.push(us(r).range(t.doc.line(a).from))},o=e.visibleRanges;if(o.length){let e=o[0].from,s=o[o.length-1].to,c=/^ {0,3}([-*_])(?: *\1){2,} *$/,l=t.doc.lineAt(e).number,u=t.doc.lineAt(s).number,d=e=>e>=1&&e<=t.doc.lines?t.doc.line(e).text:``;for(let e=l;e<=u;e++){let r=t.doc.line(e);if(r.length!==0||/Code|Math|HTML|Comment/.test(q(t).resolveInner(r.from,1).name))continue;let a=e>1&&t.doc.line(e-1).length===0&&!n.has(e),o=c.test(d(e-1))||c.test(d(e+1));i.push(us(a?`cm-lp-gap cm-lp-gap-more`:o?`cm-lp-gap cm-lp-gap-rule`:`cm-lp-gap`).range(r.from))}q(t).iterate({from:e,to:s,enter:e=>{let n=e.name,o=/^(?:ATX|Setext)Heading(\d)$/.exec(n);if(o)a(e.from,e.to,`cm-lp-h${o[1]}`);else switch(n){case`HeaderMark`:{if(r(e.from))break;if((e.node.parent?.name??``).startsWith(`SetextHeading`)){i.push(os.range(t.doc.lineAt(e.from).from,e.to));break}let n=t.sliceDoc(e.to,e.to+1)===` `?e.to+1:e.to;n>e.from&&i.push(os.range(e.from,n));break}case`EmphasisMark`:case`StrikethroughMark`:r(e.from)||i.push(os.range(e.from,e.to));break;case`Emphasis`:i.push(ls(`cm-lp-em`).range(e.from,e.to));break;case`StrongEmphasis`:i.push(ls(`cm-lp-strong`).range(e.from,e.to));break;case`Strikethrough`:i.push(ls(`cm-lp-strike`).range(e.from,e.to));break;case`InlineCode`:if(i.push(ls(`cm-lp-code`).range(e.from,e.to)),!r(e.from)){let t=e.node;for(let e=t.firstChild;e;e=e.nextSibling)e.name===`CodeMark`&&i.push(os.range(e.from,e.to))}return!1;case`InlineMath`:return r(e.from)?i.push(ls(`cm-lp-mathsrc`).range(e.from,e.to)):i.push(Z.replace({widget:new rs(t.sliceDoc(e.from,e.to))}).range(e.from,e.to)),!1;case`BlockMath`:case`Table`:return a(e.from,e.to,`cm-lp-codeblock`),!1;case`Link`:{let n=e.node,a=[],o=!1;for(let e=n.firstChild;e;e=e.nextSibling)e.name===`LinkMark`&&a.push(e),e.name===`URL`&&(o=!0);let s=a[0],c=a[1],l=n.getChild(`URL`),u=l?t.sliceDoc(l.from,l.to):``,d=u.startsWith(`code:`),f=/^https?:/i.test(u),p=n.getChild(`LinkTitle`),m=U(p?t.sliceDoc(p.from+1,p.to-1):null),h=d?t.facet(hs)(u)?`cm-lp-link cm-lp-codelink cm-lp-broken`:`cm-lp-link cm-lp-codelink`:f?`cm-lp-link cm-lp-weblink vein web`:`cm-lp-link vein ${m===`requires`?`requires`:m===`see also`?`also`:`uses`}`;s&&c&&c.from>s.to&&i.push((d?Z.mark({class:h,attributes:{title:t.facet(hs)(u)?`${u.slice(5)}: not in the repository`:u.slice(5)}}):ls(h)).range(s.to,c.from)),!r(e.from)&&o&&s&&c&&(i.push(os.range(s.from,s.to)),i.push(os.range(c.from,e.to)));break}case`Image`:{let n=e.node,a=n.getChild(`URL`),o=n.getChildren(`LinkMark`),s=a?t.facet(ms)(t.sliceDoc(a.from,a.to)):null;if(s&&o.length>=2){let t=new as(s.path,s.mount);return r(e.from)?i.push(Z.widget({widget:t,side:1}).range(e.to)):i.push(Z.replace({widget:t}).range(e.from,e.to)),!1}let c=a?t.facet(ps)(t.sliceDoc(a.from,a.to)):null;if(!c||o.length<2)break;let l=n.getChild(`LinkTitle`),u=l?t.sliceDoc(l.from+1,l.to-1).trim().toLowerCase():``,d=new is(c.key,c.src,t.sliceDoc(o[0].to,o[1].from),u===`left`);return r(e.from)?i.push(Z.widget({widget:d,side:1}).range(e.to)):i.push(Z.replace({widget:d}).range(e.from,e.to)),!1}case`ListMark`:{let n=t.sliceDoc(e.from,e.to);!r(e.from)&&/^[-*+]$/.test(n)?i.push(ss.range(e.from,e.to)):i.push(ls(`cm-lp-listmark`).range(e.from,e.to));break}case`TaskMarker`:i.push(ls(`cm-lp-task`).range(e.from,e.to));break;case`Blockquote`:a(e.from,e.to,`cm-lp-quote`);break;case`QuoteMark`:if(!r(e.from)){let n=t.sliceDoc(e.to,e.to+1)===` `?e.to+1:e.to;i.push(os.range(e.from,n))}break;case`HorizontalRule`:r(e.from)||(i.push(cs.range(e.from,e.to)),a(e.from,e.to,`cm-lp-ruleline`));break;case`FencedCode`:{a(e.from,e.to,`cm-lp-codeblock`);let n=e.node,o=t.doc.lineAt(e.from),s=t.doc.lineAt(e.to),c=n.getChild(`CodeInfo`),l=n.lastChild?.name===`CodeMark`&&n.lastChild.from>=s.from?n.lastChild:null;if(!r(o.from)){i.push(us(`cm-lp-fence`).range(o.from));let e=c?t.sliceDoc(c.from,c.to).trim().split(/\s/)[0]:``;i.push((e?Z.replace({widget:new ns(e)}):os).range(o.from,o.to))}return l&&s.number>o.number&&!r(s.from)&&(i.push(us(`cm-lp-fence`).range(s.from)),s.to>s.from&&i.push(os.range(s.from,s.to))),!1}case`CodeBlock`:return a(e.from,e.to,`cm-lp-codeblock`),!1;case`HTMLBlock`:case`CommentBlock`:return a(e.from,e.to,`cm-lp-codeblock`),!1}}})}i.sort((e,t)=>e.from-t.from||e.value.startSide-t.value.startSide);let s=new mt;for(let e of i)s.add(e.from,e.to,e.value);return s.finish()}var ps=ut.define({combine:e=>e[0]??(()=>null)}),ms=ut.define({combine:e=>e[0]??(()=>null)}),hs=ut.define({combine:e=>e[0]??(()=>!1)}),gs=rt.fromClass(class{decorations;constructor(e){this.decorations=fs(e)}update(e){(e.docChanged||e.viewportChanged||e.selectionSet||e.focusChanged||q(e.startState)!==q(e.state))&&(this.decorations=fs(e.view))}},{decorations:e=>e.decorations}),_s=J.theme({".cm-scroller":{fontFamily:`var(--font-text)`,fontSize:`var(--text-size)`,lineHeight:`1.55`},".cm-lp-gap":{lineHeight:`20px`},".cm-lp-gap-rule":{lineHeight:`10px`},".cm-lp-gap-more":{lineHeight:`4px`},".cm-lp-ruleline":{lineHeight:`12px`},".cm-content":{fontVariationSettings:`"opsz" 18`},".cm-lp-h1, .cm-lp-h2, .cm-lp-h3, .cm-lp-h4, .cm-lp-h5, .cm-lp-h6":{fontWeight:`600`,lineHeight:`1.3`,fontVariationSettings:`"opsz" 36`,paddingTop:`.5em !important`},".cm-lp-h1":{fontSize:`26px`},".cm-lp-artifact":{display:`block`,margin:`8px 0 12px`,fontFamily:`var(--font-ui)`,fontSize:`12px`,lineHeight:`1.4`},".cm-lp-h2":{fontSize:`22px`},".cm-lp-h3":{fontSize:`19px`},".cm-lp-h4":{fontSize:`17px`,fontWeight:`700`},".cm-lp-em":{fontStyle:`italic`},".cm-lp-strong":{fontWeight:`700`},".cm-lp-strike":{textDecoration:`line-through`},".cm-lp-code":{fontFamily:`var(--font-mono)`,fontSize:`.86em`,background:`color-mix(in srgb, var(--text) 8%, transparent)`,padding:`.1em .2em`},".cm-lp-codelink":{color:`var(--lattice)`,fontFamily:`var(--font-mono)`,fontSize:`.86em`,textDecoration:`none`,borderBottom:`1px solid color-mix(in srgb, var(--lattice) 50%, transparent)`},".cm-lp-broken":{color:`var(--rose)`,textDecoration:`line-through`,borderBottomColor:`transparent`},".cm-lp-picture":{display:`block`,margin:`6px auto`,width:`fit-content`,maxWidth:`100%`,lineHeight:`0`},".cm-lp-picture img":{display:`block`,maxWidth:`100%`,height:`auto`},".cm-lp-picture-left":{float:`left`,margin:`4px 16px 4px 0`,maxWidth:`50%`},".cm-lp-picture-broken":{display:`inline-block`,lineHeight:`1.4`,fontFamily:`var(--font-mono)`,fontSize:`.86em`,color:`var(--rose)`,textDecoration:`line-through`,border:`1px dashed color-mix(in srgb, var(--rose) 50%, transparent)`,padding:`6px 10px`,margin:`4px 0`},".cm-lp-bullet":{color:`var(--text-faint)`,display:`inline-block`,minWidth:`1ch`},".cm-lp-listmark, .cm-lp-task":{color:`var(--text-faint)`,fontFamily:`var(--font-mono)`},".cm-lp-quote":{borderLeft:`3px solid var(--lattice)`,paddingLeft:`14px !important`,color:`var(--text-soft)`},".cm-lp-codeblock":{fontFamily:`var(--font-mono)`,fontSize:`13px`,lineHeight:`20px`,background:`color-mix(in srgb, var(--line) 38%, transparent)`,borderLeft:`2px solid var(--line-strong)`,padding:`0 16px !important`},".cm-lp-codeblock.cm-lp-fence":{lineHeight:`12px`,position:`relative`},".cm-lp-lang":{position:`absolute`,top:`8px`,right:`12px`,fontFamily:`var(--font-ui)`,fontSize:`12px`,lineHeight:`16px`,color:`var(--text-faint)`,pointerEvents:`none`},".cm-lp-mathsrc":{fontFamily:`var(--font-mono)`,fontSize:`.86em`,color:`var(--text-soft)`},".cm-lp-imaths .katex":{fontSize:`1.05em`},".cm-lp-imaths .katex-display":{margin:`0`,padding:`6px 0`},".cm-lp-imaths .katex-display > .katex":{fontSize:`1.17em`},".cm-lp-hr":{display:`inline-block`,width:`100%`,borderTop:`1px solid var(--line)`,verticalAlign:`middle`}});function vs(e){let t=e.split(`#`)[0];return t.startsWith(`/`)&&t.endsWith(`.md`)?t.slice(1,-3):null}function ys(e){let t=e.split(/[#?]/)[0];return t.startsWith(`/`)&&!t.startsWith(`//`)&&/\/[^/]*\.[^./]+$/.test(t)&&!t.endsWith(`.md`)?decodeURI(t.slice(1)):null}var bs=yt.define(),xs=yt.define(),Ss=[bt.define({create:()=>Z.none,update(e,t){for(let e of t.effects){if(!e.is(xs))continue;let n=t.state.doc,r=e.value;if(!r)return Z.none;let i=Z.line({class:`cm-touched cm-touched-${r.who}`});return Z.set([...new Set(r.lines)].filter(e=>e>=0&&e<n.lines&&n.line(e+1).text.trim()!==``).sort((e,t)=>e-t).map(e=>i.range(n.line(e+1).from)))}return t.docChanged?e.map(t.changes):e},provide:e=>J.decorations.from(e)}),J.theme({".cm-line.cm-touched-you":{background:`var(--lattice-soft)`,boxShadow:`-10px 0 0 var(--lattice-soft), -13px 0 0 var(--lattice), 10px 0 0 var(--lattice-soft)`},".cm-line.cm-touched-iso":{background:`var(--growth-soft)`,boxShadow:`-10px 0 0 var(--growth-soft), -13px 0 0 var(--growth), 10px 0 0 var(--growth-soft)`}})],Cs=yt.define(),ws=class extends at{key;mount;block;down=null;watch=null;constructor(e,t,n){super(),this.key=e,this.mount=t,this.block=n}eq(e){return e.key===this.key&&e.block===this.block}toDOM(e){let t=document.createElement(this.block?`div`:`span`);return t.className=this.block?`cm-overlay`:`cm-iso-change`,t.contentEditable=`false`,this.down=this.mount(t,this.key),this.watch=new ResizeObserver(()=>e.requestMeasure()),this.watch.observe(t),t}destroy(){this.watch?.disconnect(),this.watch=null,this.down?.(),this.down=null}ignoreEvent(){return!0}get estimatedHeight(){return this.block?120:-1}};function Ts(e){return[bt.define({create:()=>Z.none,update(t,n){for(let t of n.effects){if(!t.is(bs))continue;let r=n.state.doc;return Z.set(t.value.map(t=>{let n=t.line>=r.lines,i=n?r.length:r.line(Math.max(1,t.line+1)).from;return Z.widget({widget:new ws(t.key,e,!0),block:!0,side:n?1:-1}).range(i)}),!0)}return n.docChanged?t.map(n.changes):t},provide:e=>J.decorations.from(e)}),bt.define({create:()=>Z.none,update(t,n){for(let t of n.effects){if(!t.is(Cs))continue;let r=n.state.doc.length,i=[];for(let e of t.value.marks){let t=Math.max(0,Math.min(r,e.from)),n=Math.max(0,Math.min(r,e.to));n>t&&i.push(Z.mark({class:`cm-iso-${e.kind}`}).range(t,n))}for(let n of t.value.inline)i.push(Z.widget({widget:new ws(n.key,e,!1),side:1}).range(Math.max(0,Math.min(r,n.at))));return Z.set(i,!0)}return n.docChanged?t.map(n.changes):t},provide:e=>J.decorations.from(e)}),J.theme({".cm-overlay":{cursor:`default`,userSelect:`text`,padding:`10px 0`,display:`flow-root`,whiteSpace:`normal`},".cm-iso-old":{textDecoration:`line-through`,textDecorationColor:`var(--text-faint)`,color:`var(--text-faint)`},".cm-iso-old *":{color:`var(--text-faint) !important`},".cm-iso-change":{cursor:`default`},".cm-iso-by-iso":{background:`var(--growth-soft)`,boxShadow:`inset 0 -1.5px 0 var(--growth)`},".cm-iso-given":{textDecoration:`underline dashed var(--growth)`,textUnderlineOffset:`4px`,textDecorationThickness:`1.5px`}})]}function Es(e){let t=e.split(`#`)[0].split(`?`)[0];return!t.startsWith(`/`)||t.startsWith(`//`)?null:t.endsWith(`.md`)?{id:decodeURIComponent(t.slice(1,-3)),folder:!1}:t.endsWith(`/`)&&t.length>1?{id:decodeURIComponent(t.slice(1,-1)),folder:!0}:null}var Ds=yt.define(),Os=Z.mark({class:`cm-pointed`});function ks(e,t){if(!t)return Z.none;let n=[];return q(e).iterate({enter:r=>{if(r.name!==`Link`)return;let i=uo(e,r.from+1);return i&&!i.embed&&i.from===r.from&&Es(i.url)?.id===t&&n.push(Os.range(i.from,i.to)),!1}}),Z.set(n)}var As=bt.define({create:()=>({id:``,marks:Z.none}),update(e,t){let n=e.id;for(let e of t.effects)e.is(Ds)&&(n=e.value);return n!==e.id||n&&t.docChanged?{id:n,marks:ks(t.state,n)}:e},provide:e=>J.decorations.from(e,e=>e.marks)}),js=J.theme({".cm-pointed":{backgroundColor:`var(--lattice-soft)`,boxShadow:`0 2px 0 var(--lattice)`}});function Ms(e){if(!e)return[As,js];let t=``,n=n=>{let r=n?`${n.folder?`d`:`n`}:${n.id}`:``;r!==t&&(t=r,e(n))};return[As,js,J.domEventHandlers({pointermove(e,t){if(e.pointerType!==`mouse`)return!1;let r=t.posAtCoords({x:e.clientX,y:e.clientY},!1),i=r===null?null:uo(t.state,r);return n(i&&!i.embed?Es(i.url):null),!1},pointerleave(){return n(null),!1}})]}var Ns=J.theme({".cm-scroller":{fontFamily:`var(--font-mono)`,fontSize:`14px`,lineHeight:`1.6`}}),Ps=J.theme({"&":{color:`var(--text)`,backgroundColor:`transparent`,fontSize:`16px`},"&.cm-focused":{outline:`none`},".cm-scroller":{overflow:`visible`},".cm-content":{padding:`12px 0 40vh`,caretColor:`var(--lattice)`},".cm-line":{padding:`0 2px`},".cm-cursor, .cm-dropCursor":{borderLeftColor:`var(--lattice)`,borderLeftWidth:`2px`},".cm-selectionBackground":{backgroundColor:`color-mix(in srgb, var(--lattice) 22%, transparent) !important`},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-content ::selection":{backgroundColor:`color-mix(in srgb, var(--lattice) 40%, transparent) !important`},".cm-placeholder":{color:`var(--text-faint)`},".cm-tooltip-autocomplete":{background:`var(--ground-1)`,border:`1px solid var(--line-strong)`,fontFamily:`var(--font-ui)`,fontSize:`13px`},".cm-tooltip.cm-tooltip-autocomplete > ul":{fontFamily:`var(--font-ui)`,maxHeight:`16em`},".cm-tooltip-autocomplete > ul > li":{padding:`6px 10px !important`,lineHeight:`1.3`},".cm-picture-thumb":{width:`32px`,height:`32px`,objectFit:`cover`,verticalAlign:`middle`,marginRight:`8px`,background:`var(--ground-2)`},".cm-tooltip-autocomplete > ul > li:has(.cm-picture-thumb)":{padding:`3px 10px !important`},".cm-picture-preview":{padding:`8px`},".cm-picture-preview img":{display:`block`,maxWidth:`240px`,maxHeight:`240px`},".cm-picture-size":{fontFamily:`var(--font-ui)`,fontSize:`12px`,color:`var(--text-faint)`,marginTop:`4px`},".cm-completionInfo":{background:`var(--ground-1)`,border:`1px solid var(--line-strong)`,padding:`0`},".cm-tooltip-autocomplete > ul > li[aria-selected]":{background:`var(--lattice-soft)`,color:`var(--text)`},".cm-completionDetail":{color:`var(--text-faint)`,fontStyle:`normal`,marginLeft:`10px`}}),Fs=xt.define([{tag:X.heading,fontWeight:`700`,color:`var(--text)`},{tag:X.strong,fontWeight:`700`},{tag:X.emphasis,fontStyle:`italic`},{tag:X.strikethrough,textDecoration:`line-through`},{tag:[X.link,X.url],color:`var(--lattice)`},{tag:[X.processingInstruction,X.punctuation,X.contentSeparator],color:`var(--text-faint)`},{tag:X.monospace,color:`var(--text-soft)`},{tag:X.quote,color:`var(--text-soft)`,fontStyle:`italic`}]);function Is(e){let t=e.selection.main;return{line:e.doc.lineAt(t.to).number-1,from:t.from,to:t.to}}function Ls(e){let t=e=>[...e??[]].filter(e=>e.type.startsWith(`image/`));return J.domEventHandlers({paste(n,r){let i=t(n.clipboardData?.files);return i.length?(n.preventDefault(),e(i,r.state.selection.main.head,!0),!0):!1},drop(n,r){let i=t(n.dataTransfer?.files);return i.length?(n.preventDefault(),e(i,r.posAtCoords({x:n.clientX,y:n.clientY})??r.state.selection.main.head,!1),!0):!1}})}function Rs(e,t){let n=dt.create({doc:t.doc,extensions:[Ir(),st(),J.lineWrapping,Nt({base:Ft,extensions:[Qo],completeHTMLTags:!1,codeLanguages:Mt}),et(Fs),et(It),Ps,...t.source?[Ns]:[gs,_s,$a,eo,jo,...t.embeds?[Ua.of(t.embeds)]:[],...t.codeBroken?[hs.of(t.codeBroken)]:[],...t.pictures?[ps.of(t.pictures)]:[],...t.artifacts?[ms.of(t.artifacts)]:[]],jt(),dt.languageData.of(()=>[{closeBrackets:{brackets:[`(`,`[`]}}]),...t.mountOverlay?[Ts(t.mountOverlay)]:[],Ss,Ms(t.onPoint),...t.readOnly?[dt.readOnly.of(!0),J.editable.of(!1)]:[],Bo(t.notes,t.pictureSource??null,t.noteMaker??null),...t.onPictures&&!t.readOnly?[Ls(t.onPictures)]:[],nt(t.placeholder??`Write the note here. # for a heading, [[ to link to another note, [[! to show a picture, $x$ for maths.`),J.contentAttributes.of({"aria-label":t.label,spellcheck:`true`,autocapitalize:`sentences`,autocorrect:`on`}),$e.of([{key:`Mod-s`,preventDefault:!0,run:()=>(t.onSave(),!0)},{key:`Mod-Enter`,preventDefault:!0,run:e=>(t.onAsk?.(Is(e.state)),!!t.onAsk)},...so,...Dt,...At,Ha,...Va,...ti]),J.domEventHandlers({mousedown(e,n){if(!t.onFollow||!(e.ctrlKey||e.metaKey)||e.button!==0)return!1;let r=n.posAtCoords({x:e.clientX,y:e.clientY},!1),i=r===null?null:uo(n.state,r),a=r===null||i?null:zs(n.state,r);if(a&&t.onCode)return e.preventDefault(),t.onCode(a),!0;let o=i?i.embed?ys(i.url):vs(i.url)??ys(i.url):null;return o===null?!i||!t.onCode||!i.url.trim().startsWith(`code:`)?!1:(e.preventDefault(),t.onCode(i.url.trim()),!0):(e.preventDefault(),t.onFollow(o),!0)}}),J.updateListener.of(e=>{e.docChanged&&t.onChange(e.state.doc.toString()),t.onCursor&&(e.selectionSet||e.docChanged)&&t.onCursor(Is(e.state))})]});return new J({state:n,parent:e})}function zs(e,t){let n=q(e);for(let r of[-1,1])for(let i=n.resolveInner(t,r);i;i=i.parent){if(i.name!==`Link`&&i.name!==`Image`)continue;let t=i.getChild(`URL`),n=t?e.sliceDoc(t.from,t.to).trim():``;return n.startsWith(`code:`)?n:null}return null}function Bs(e,t){if(t===e.state.doc.toString())return;let n=Math.min(e.state.selection.main.head,t.length);e.dispatch({changes:{from:0,to:e.state.doc.length,insert:t},selection:{anchor:n}})}var Vs=2e7,Hs={type:`string`};({...Hs}),{...Hs},{...Hs},{...Hs},{...Hs};var Us=`conversations`,Ws={type:`string`},Gs=(e,t,n,r)=>({type:`function`,function:{name:e,description:t,parameters:{type:`object`,properties:n,required:r,additionalProperties:!1}}});({...Ws}),{...Ws};var Ks=Gs(`read_data`,`A data file's shape: its columns with their types and ranges, the row count and the first rows. Read it before writing anything that uses the file, so the column names are real.`,{path:{...Ws,description:`The file's path in the base: folder/name.csv.`}},[`path`]),qs=Gs(`artifact_recipe`,`A recipe for an artifact: a complete working one to start from, the kit's reference, and the rules write_artifact checks. dashboard: numbers, charts and a table of one data file. compare: two data files side by side. simulation: a model with parameters and play. explorable: inputs, derived numbers and linked views. viewer: a 3D model.`,{name:{type:`string`,enum:[`dashboard`,`compare`,`simulation`,`explorable`,`viewer`]}},[`name`]),Js=Gs(`write_artifact`,`Write an artifact: a whole HTML file on the kit. The title, description and uses given here are written into it. It is checked, and run where it can be; the result says what to fix. Nothing is written while a rule is broken.`,{path:{...Ws,description:`Where: folder/name.html, beside the notes it belongs to.`},title:Ws,description:{...Ws,description:`One sentence: what it shows, and what can be done with it.`},uses:{type:`array`,items:Ws,description:`The data or model files it reads, relative to it (runs.csv). Those its markup and script name are added.`},html:{...Ws,description:`The whole file.`}},[`path`,`title`,`description`,`uses`,`html`]),Ys=Gs(`read_artifact`,`An artifact's whole file, to change it and write it again.`,{path:{...Ws,description:`folder/name.html`}},[`path`]);({...Ws}),{...Ws},`${Us}`,new Set([Ks,qs,Ys,Js].map(e=>e.function.name));var Xs=`The change is written at once, under your name: the person sees your words marked in the note, and can undo it from the browser. Use this, never edit or write, for any note of the knowledge base.`;`${Xs}`,`${Xs}`;var Zs=a(`<p class="same svelte-18j5w6l">This picture is already in the notes as <code> </code>.</p>`),Qs=a(`<code> </code> is taken: Enter makes it <code> </code>`,1),$s=a(`<code> </code>`),ec=a(`<label class="svelte-18j5w6l"><span class="svelte-18j5w6l">name</span> <span class="name svelte-18j5w6l"><input class="field mono svelte-18j5w6l" spellcheck="false" autocomplete="off" aria-label="Its name"/><span class="ext svelte-18j5w6l"> </span></span></label> <p><!></p>`,1),tc=a(`<button class="btn" type="button"> </button>`),nc=a(`<div class="picture-name svelte-18j5w6l" role="dialog" aria-label="Name the picture" tabindex="-1"><img alt="" class="svelte-18j5w6l"/> <div class="fields svelte-18j5w6l"><!> <label class="svelte-18j5w6l"><span class="svelte-18j5w6l">what it shows</span> <input class="field" placeholder="Iso reads this, not the picture" aria-label="What it shows" autocomplete="off"/></label> <div class="actions svelte-18j5w6l"><!> <button class="btn" type="button">Cancel</button> <button class="btn primary" type="button"> </button></div></div></div>`);function rc(t,n){C(n,!0);let r=F(()=>({"image/png":`png`,"image/jpeg":`jpg`,"image/gif":`gif`,"image/webp":`webp`,"image/svg+xml":`svg`,"image/avif":`avif`})[n.file.type]??`png`),i=x(re(n.suggested)),a=x(``),o=x(!1),c=x(void 0),u,f=F(()=>Ie(s(i))||`picture`),p=F(()=>`${n.folder?n.folder+`/`:``}${s(f)}.${s(r)}`),m=F(()=>n.taken(s(p))),h=F(()=>{for(let e=2;;e++)if(!n.taken(`${n.folder?n.folder+`/`:``}${s(f)}-${e}.${s(r)}`))return`${s(f)}-${e}`}),g=F(()=>n.same!==null&&!s(o));N(()=>{s(c)?(s(c).focus(),s(c).select()):u.focus()});function _(e){e.key===`Escape`?(e.preventDefault(),n.onDone(null)):e.key===`Enter`&&(e.preventDefault(),v())}function v(){if(!s(g)&&s(m)){k(i,s(h),!0);return}let e=s(g)?n.same:s(p);n.onDone({path:e,alt:s(a).trim()||Po(e),save:!s(g)})}var y=nc();let b;var ee=e(y),E=P(ee,2),O=e(E),ne=t=>{var r=Zs(),i=P(e(r)),a=I(i,!0);M(),D(r),l(()=>A(a,n.same)),d(t,r)},z=t=>{var n=ec(),a=w(n),o=P(e(a),2),u=e(o);S(u),te(u,e=>k(c,e),()=>s(c));var f=P(u),g=I(f);D(o),D(a);var _=P(a,2);let v;var y=e(_),b=e=>{var t=Qs(),n=w(t),i=I(n,!0),a=P(n,2),o=I(a);l(()=>{A(i,s(p)),A(o,`${s(h)??``}.${s(r)??``}`)}),d(e,t)},x=e=>{var t=$s(),n=I(t,!0);l(()=>A(n,s(p))),d(e,t)};j(y,e=>{s(m)?e(b):e(x,-1)}),D(_),l(()=>{A(g,`.${s(r)??``}`),v=B(_,1,`path svelte-18j5w6l`,null,v,{taken:s(m)})}),L(u,()=>s(i),e=>k(i,e)),d(t,n)};j(O,e=>{s(g)?e(ne):e(z,-1)});var ae=P(O,2),oe=P(e(ae),2);S(oe),te(oe,e=>u=e,()=>u),D(ae);var H=P(ae,2),U=e(H),W=e=>{var t=tc(),n=I(t,!0);l(()=>A(n,s(o)?`Use the one there`:`Save a copy`)),V(`click`,t,()=>{k(o,!s(o)),s(o)&&requestAnimationFrame(()=>{s(c)?.focus(),s(c)?.select()})}),d(e,t)};j(U,e=>{n.same!==null&&e(W)});var G=P(U,2),se=P(G,2),ce=I(se,!0);D(H),D(E),D(y),l(()=>{b=ie(y,``,b,{left:`${n.at.left??``}px`,top:`${n.at.top??``}px`}),T(ee,`src`,n.src),A(ce,s(g)?`Show it`:`Save`)}),V(`keydown`,y,_),L(oe,()=>s(a),e=>k(a,e)),V(`click`,G,()=>n.onDone(null)),V(`click`,se,v),d(t,y),R()}h([`keydown`,`click`]);var ic=a(`<div class="between stopped svelte-192cp36" role="alert"><p class="bad svelte-192cp36"> </p> <div class="foot svelte-192cp36"><span class="grow"></span><button class="link svelte-192cp36" type="button">dismiss</button></div></div>`),ac=a(`<p class="soft lost svelte-192cp36"><span class="strike svelte-192cp36"> </span> </p>`),oc=a(`<div class="between stopped svelte-192cp36"><p class="label"> </p> <!> <div class="foot svelte-192cp36"><span class="grow"></span><button class="btn remove" type="button">remove</button></div></div>`),sc=a(`<p class="label">The place this was written for is no longer in the note, so it is shown here. Keeping it adds it at the end.</p>`),cc=a(`<textarea class="revision svelte-192cp36" aria-label="Iso's text, to edit"></textarea>`),lc=a(`<div class="prose said svelte-192cp36"></div>`),uc=a(`<p class="label"> </p>`),dc=a(`<button class="btn edit" type="button">done</button>`),fc=a(`<button class="btn edit" type="button">edit</button>`),pc=a(`<div class="between svelte-192cp36"><!> <!> <!> <div class="foot svelte-192cp36"><i class="dia svelte-192cp36" aria-hidden="true"></i> <span class="grow"></span> <button class="btn keep" type="button">keep</button> <!> <button class="btn remove" type="button">remove</button></div></div>`);function mc(t,n){C(n,!0);let r=O(n,`iso`,7),a=F(()=>n.key.startsWith(`p:`)?r().proposals.find(e=>e.id===n.key.slice(2)):void 0),o=F(()=>s(a)&&r().editing?.id===s(a).id?r().editing:null),c=F(()=>!!s(a)&&r().busy===s(a)?.id),u=F(()=>r().changes.filter(e=>!e.at));var f=p(),m=w(f),h=t=>{var n=ic(),i=e(n),a=I(i,!0),o=P(i,2),s=P(e(o));D(o),D(n),l(()=>A(a,r().failed.message)),V(`click`,s,()=>r().failed=null),d(t,n)},_=t=>{var n=oc(),a=e(n),o=I(a),c=P(a,2);i(c,17,()=>s(u),e=>e.key,(t,n)=>{var r=ac(),i=e(r),a=I(i,!0),o=P(i);D(r),l((e,t)=>{A(a,e),A(o,` → ${t??``}`)},[()=>s(n).proposal.regions[s(n).k].old.text.trim(),()=>s(n).proposal.regions[s(n).k].new.trim()||`(taken out)`]),d(t,r)});var f=P(c,2),p=P(e(f));D(f),D(n),l(()=>A(o,`${s(u).length===1?`One change Iso offered is`:`${s(u).length} changes Iso offered are`} for text that is no longer in the note as it was, so ${s(u).length===1?`it`:`they`} cannot be kept.`)),V(`click`,p,()=>{for(let e of s(u))r().discardChange(e)}),d(t,n)},v=t=>{var n=pc(),i=e(n),u=e=>{var t=sc();d(e,t)},f=F(()=>!r().placed(s(a)));j(i,e=>{s(f)&&e(u)});var p=P(i,2),m=e=>{var t=cc();ee(t),l(e=>T(t,`rows`,e),[()=>Math.max(3,s(o).text.split(`
13
+ `).length+1)]),L(t,()=>s(o).text,e=>s(o).text=e),d(e,t)},h=e=>{var t=lc();g(t,()=>Le(s(a).text),!0),D(t),z(t,(e,t)=>We?.(e,t),()=>({given:s(a).text,copy:!0})),d(e,t)};j(p,e=>{s(o)?e(m):e(h,-1)});var _=P(p,2),v=e=>{var t=uc(),n=I(t,!0);l(()=>A(n,s(a).notice)),d(e,t)};j(_,e=>{s(a).notice&&e(v)});var y=P(_,2),b=P(e(y),4),x=P(b,2),S=e=>{var t=dc();V(`click`,t,()=>r().done(s(a))),d(e,t)},C=e=>{var t=fc();l(()=>t.disabled=s(c)),V(`click`,t,()=>r().edit(s(a))),d(e,t)};j(x,e=>{s(o)?e(S):e(C,-1)});var w=P(x,2);D(y),D(n),l(()=>{T(n,`data-proposal`,s(a).id),b.disabled=s(c),w.disabled=s(c)}),V(`click`,b,()=>r().keep(s(a))),V(`click`,w,()=>r().discard(s(a))),d(t,n)};j(m,e=>{n.key===`failed`&&r().failed?e(h):n.key===`lost`&&s(u).length?e(_,1):s(a)&&e(v,2)}),d(t,f),R()}h([`click`]);var hc=a(`<span class="label who svelte-1o10yjh"> </span>`),gc=a(`<!> <span class="act svelte-1o10yjh"><button class="keep svelte-1o10yjh" type="button" aria-label="Keep this change">keep</button><button class="remove svelte-1o10yjh" type="button" aria-label="Remove this change">remove</button></span>`,1),_c=a(`<span class="gone svelte-1o10yjh">the passage above is taken out</span>`),vc=a(`<pre class="new svelte-1o10yjh"> </pre>`),yc=a(`<div class="new prose svelte-1o10yjh"></div>`),bc=a(`<div><!> <div class="foot svelte-1o10yjh"><i class="dia svelte-1o10yjh" aria-hidden="true"></i><span class="label">in place of the lines struck through above</span><span class="grow"></span><!></div></div>`),xc=a(`<span class="new svelte-1o10yjh"></span>`),Sc=a(`<span class="gone svelte-1o10yjh">taken out</span>`),Cc=a(`<span class="change svelte-1o10yjh"><!> <!></span>`);function wc(t,n){C(n,!0);let r=t=>{var r=gc(),a=w(r),c=e=>{var t=hc(),n=I(t,!0);l(()=>{T(t,`title`,s(i)?.proposal.asked),A(n,s(f))}),d(e,t)};j(a,e=>{s(f)&&e(c)});var u=P(a,2),p=e(u),m=P(p);D(u),l(()=>{p.disabled=s(o),m.disabled=s(o)}),V(`click`,p,()=>s(i)&&n.iso.keepChange(s(i))),V(`click`,m,()=>s(i)&&n.iso.discardChange(s(i))),d(t,r)},i=F(()=>n.iso.changes.find(e=>e.key===n.key)),a=F(()=>s(i)?s(i).proposal.regions[s(i).k].new:``),o=F(()=>n.iso.busy===n.key||n.iso.busy===`all`),c=F(()=>Le(s(a).trim())),u=F(()=>s(c).replace(/^<p>([\s\S]*)<\/p>\s*$/,`$1`)),f=F(()=>s(i)?qe(s(i).proposal.who):``);var m=p(),h=w(m),_=t=>{var o=bc();let u;var f=e(o),p=e=>{var t=_c();d(e,t)},m=F(()=>!s(a).trim()),h=e=>{var t=vc(),n=I(t,!0);l(e=>A(n,e),[()=>s(a).replace(/^\n+|\s+$/g,``)]),d(e,t)},_=e=>{var t=yc();g(t,()=>s(c),!0),D(t),z(t,(e,t)=>We?.(e,t),()=>s(c)),d(e,t)};j(f,e=>{s(m)?e(p):s(i).code?e(h,1):e(_,-1)});var v=P(f,2),y=P(e(v),3);r(y),D(v),D(o),l(()=>{u=B(o,1,`change block svelte-1o10yjh`,null,u,{code:s(i).code}),T(o,`data-change`,n.key)}),d(t,o)},v=t=>{var i=Cc(),o=e(i),c=e=>{var t=xc();g(t,()=>s(u),!0),D(t),d(e,t)},f=F(()=>s(a).trim()),p=e=>{var t=Sc();d(e,t)};j(o,e=>{s(f)?e(c):e(p,-1)});var m=P(o,2);r(m),D(i),l(()=>T(i,`data-change`,n.key)),d(t,i)};j(h,e=>{s(i)?.block?e(_):s(i)&&e(v,1)}),d(t,m),R()}h([`click`]);var Tc=a(`<p class="said svelte-hrl8lz" role="status"> </p>`),Ec=a(`<div></div> <!> <!>`,1);function Dc(e,n){C(n,!0);let r=O(n,`iso`,7),i=O(n,`reading`,3,!1),a=O(n,`touched`,3,null),c=O(n,`lens`,19,()=>[]),f,p=x(void 0),m=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`image/svg+xml`,`image/avif`],h=x(null),g=x(null),_,y=e=>{k(g,e,!0),clearTimeout(_),_=setTimeout(()=>k(g,null),8e3)};async function ee(e,t,r){if(!s(p)||s(h))return;let i=n.note.id,a=!i.startsWith(`@`),o=a?i:`pictures`,c=e=>a&&e.startsWith(`${i}/`)?Fo(e.slice(i.lastIndexOf(`/`)+1)):`/${Fo(e)}`,l=[];try{l=await K.api.pictures()}catch{}let u=new Set(l.map(e=>e.path));for(let n of e){if(!m.includes(n.type)){y(`${n.name||`That`} isn't a picture isorite keeps: png, jpg, gif, webp, svg and avif are.`);continue}if(n.size>2e7){y(`${n.name||`That picture`} is larger than isorite takes (${Vs/1e6} MB).`);continue}let e=new Uint8Array(await n.arrayBuffer()),i=await Pe(e),a=l.find(e=>e.sha256===i)?.path??null,d=URL.createObjectURL(n),g=s(p),_=g.coordsAtPos(Math.min(t,g.state.doc.length)),v=f.getBoundingClientRect(),b=await new Promise(e=>{k(h,{file:n,src:d,folder:o,same:a,onDone:e,suggested:r||!n.name?Fe():Ie(n.name)||`picture`,taken:e=>u.has(e),at:{left:Math.max(16,Math.min(_?.left??v.left,innerWidth-476)),top:Math.min((_?.bottom??v.top)+6,innerHeight-220)}})});if(k(h,null),URL.revokeObjectURL(d),!b)continue;if(b.save)try{let t=await K.api.savePicture(b.path,e);l.push(t),u.add(t.path)}catch(e){y(`It wasn't saved: ${e.message}`);continue}let x=`![${b.alt.replace(/[[\]]/g,``)}](${c(b.path)})`;g.dispatch({changes:{from:t,insert:x},selection:{anchor:t+x.length}}),t+=x.length}s(p).focus()}let S=F(()=>n.source||!r()?{lines:0,chars:0}:r().head),T=F(()=>{if(!r())return{blocks:[],marks:[],inline:[]};let e=e=>t=>({kind:e,from:t.from-s(S).chars,to:t.to-s(S).chars});return{blocks:r().layout.blocks.map(e=>({key:e.key,line:Math.max(0,e.line-s(S).lines)})).sort((e,t)=>e.line-t.line),marks:[...r().layout.old.map(e(`old`)),...c().map(t=>e(t.kind)(t))].filter(e=>e.to>0),inline:r().layout.inline.map(e=>({key:e.key,at:e.at-s(S).chars})).filter(e=>e.at>=0)}});N(()=>{let e=Rs(f,{doc:n.source?n.note.text:n.note.body,source:n.source,readOnly:i(),label:n.source?`The note's file`:`The note`,notes:()=>K.listing.notes.filter(e=>e.id!==n.note.id).map(e=>({id:e.id,title:e.title,folder:e.dir,...e.kind?{kind:e.kind}:{}})),noteMaker:{plan:e=>{let t=Mo(e),r=pe(t);if(!r)return null;let i=n.note.id.startsWith(`@`)||!n.note.id.includes(`/`)?``:n.note.id.slice(0,n.note.id.lastIndexOf(`/`));return{title:t,id:[i,r].filter(Boolean).join(`/`),folder:i}},make:e=>{K.api.createNote(e.id,`---\ntype: Concept\ntitle: ${JSON.stringify(e.title)}\n---\n\n`).then(()=>K.refresh(),t=>y(`${e.title} wasn't made: ${t.message}`))}},onPictures:(e,t,n)=>{ee(e,t,n)},pictureSource:{pictures:async()=>(await K.api.pictures()).map(e=>({path:e.path,width:e.width,height:e.height,src:Re(K.api,{path:e.path,from:`notes`})})),here:()=>n.note.id},onChange:e=>n.source?n.note.setText(e):n.note.setBody(e),onSave:()=>{n.note.save()},onCode:e=>{H(Se(e))},onFollow:e=>{H(ve(e))},embeds:{find:Te,open:e=>{H(ve(e))}},onPoint:e=>Ge.set(`note`,e?{...e,who:`you`}:null),codeBroken:e=>K.listing.notes.find(e=>e.id===n.note.id)?.broken?.includes(e)??!1,pictures:e=>{let t=Ve(e,n.note.id);return t?{key:`${t.from}:${t.path}`,src:Re(K.api,t)}:null},artifacts:e=>{let r=e.trim().startsWith(`code:`)?de(e.trim()):null;if(r&&W(r.path)!==`image`)return{path:e,mount:n=>{let r=t(gr,{target:n,props:{href:e.trim()}});return()=>{u(r)}}};let i=dn(e,n.note.id);return i?{path:i,mount:e=>{let n=t(yr,{target:e,props:{path:i}});return()=>{u(n)}}}:null},...r()?{onAsk:e=>{let t=n.note.text.slice(e.from+s(S).chars,e.to+s(S).chars).trim();t&&Ze.add({kind:`passage`,id:n.note.id,title:n.note.fields.title||n.note.id,text:t}),Ye.to(`iso`),requestAnimationFrame(()=>document.getElementById(`iso-box`)?.focus())},onCursor:e=>{r().cursor={line:e.line+s(S).lines,from:e.from+s(S).chars,to:e.to+s(S).chars}},mountOverlay:(e,n)=>{let i=t(n.startsWith(`r:`)?wc:mc,{target:e,props:{iso:r(),key:n}});return()=>{u(i)}}}:{placeholder:o(()=>n.placeholder)??`Write what you understand, what you do not, and what you want from Iso. [[ links a note it should rest on.`}});return k(p,e),()=>{e.destroy(),Ge.set(`note`,null)}}),v(()=>{n.note.revision,o(()=>{s(p)&&Bs(s(p),n.source?n.note.text:n.note.body)})}),v(()=>{let e=a(),t=s(S).lines;s(p)&&s(p).dispatch({effects:xs.of(e?{who:e.who,lines:e.lines.map(e=>e-t)}:null)})}),v(()=>{let e=Ge.onAtlas;s(p)&&s(p).dispatch({effects:Ds.of(e)})}),v(()=>{let{blocks:e,marks:t,inline:n}=s(T);s(p)&&s(p).dispatch({effects:[bs.of(e),Cs.of({marks:t,inline:n})]})});var E=Ec(),D=w(E);let ne;te(D,e=>f=e,()=>f);var M=P(D,2),re=e=>{rc(e,b(()=>s(h)))};j(M,e=>{s(h)&&e(re)});var L=P(M,2),ie=e=>{var t=Tc(),n=I(t,!0);l(()=>A(n,s(g))),d(e,t)};j(L,e=>{s(g)&&e(ie)}),l(()=>ne=B(D,1,`editor svelte-hrl8lz`,null,ne,{source:n.source})),d(e,E),R()}var Oc=a(`<h1 class="serif title svelte-130pv1o"> </h1>`),kc=a(`<p class="asked svelte-130pv1o"><i class="dia svelte-130pv1o" aria-hidden="true"></i><span> </span></p>`),Ac=a(`<div class="offered svelte-130pv1o" aria-label="What Iso offered"><p class="serif svelte-130pv1o"> </p></div>`),jc=a(`<div class="version svelte-130pv1o"><!> <!> <div class="text svelte-130pv1o"></div> <!></div>`);function Mc(t,n){C(n,!0);let r=F(()=>{try{let[e,t,r]=ue(n.text);return{title:/^title:\s*(.*)$/m.exec(t??``)?.[1]?.trim().replace(/^["']|["']$/g,``)??``,body:r,lines:e.split(`
14
+ `).length-1}}catch{return{title:``,body:n.text,lines:0}}}),i,a=x(void 0);N(()=>(k(a,Rs(i,{doc:s(r).body,onChange:()=>void 0,onSave:()=>void 0,label:`The note as it was`,notes:()=>[],readOnly:!0,pictures:e=>{let t=Ve(e,n.id);return t?{key:`${t.from}:${t.path}`,src:Re(K.api,t)}:null}})),()=>s(a)?.destroy())),v(()=>{let e=n.touched,t=s(r).lines;s(a)?.dispatch({effects:xs.of(e?{who:e.who,lines:e.lines.map(e=>e-t)}:null)})});var o=jc(),c=e(o),u=e=>{var t=Oc(),n=I(t,!0);l(()=>A(n,s(r).title)),d(e,t)};j(c,e=>{s(r).title&&s(r).title!==n.title&&e(u)});var f=P(c,2),p=t=>{var r=kc(),i=P(e(r)),a=I(i,!0);D(r),l(()=>A(a,n.asked)),d(t,r)};j(f,e=>{n.asked!==void 0&&e(p)});var m=P(f,2);te(m,e=>i=e,()=>i);var h=P(m,2),g=t=>{var r=Ac(),i=e(r),a=I(i,!0);D(r),l(()=>A(a,n.offered)),d(t,r)};j(h,e=>{n.offered!==void 0&&e(g)}),D(o),d(t,o),R()}var Nc=(t,n=E,r=E)=>{var i=Ic();let a;var o=e(i),s=e=>{var t=Pc();l(()=>T(t,`fill`,r()?`currentColor`:`none`)),d(e,t)},c=e=>{var t=Fc();l(()=>T(t,`fill`,r()?`currentColor`:`none`)),d(e,t)};j(o,e=>{n()===`question`?e(s):e(c,-1)}),D(i),l(()=>a=B(i,0,`glyph ${n()??``}`,`svelte-18ltlst`,a,{solved:r()})),d(t,i)},Pc=c(`<path d="M8 2.5L13.5 8L8 13.5L2.5 8Z"></path>`),Fc=c(`<path d="M8 2.5l5.8 10.5H2.2z"></path>`),Ic=c(`<svg viewBox="0 0 16 16" width="18" height="18" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.4"><!></svg>`),Lc=a(`<p class="faint"><!></p>`),Rc=a(`<p class="soft">There is no note at <span class="faint"> </span>.</p> <p><a>all notes</a></p>`,1),zc=a(`<p class="bad svelte-18ltlst"> </p>`),Bc=a(`<button class="btn" type="button">take theirs</button>`),Vc=a(`<div class="frame choice svelte-18ltlst" role="alert"><span class="frame-title">changed elsewhere</span> <p> </p> <div class="row svelte-18ltlst"><button class="btn primary" type="button">keep mine</button> <!></div> <p class="faint">Whichever you keep, the other stays in the note's journal.</p></div>`),Hc=a(`<div class="titlerow svelte-18ltlst"><!> <h1 class="serif title read svelte-18ltlst"> </h1></div>`),Uc=a(`<div class="titlerow svelte-18ltlst"><!> <label class="hidden-label" for="title">Title</label> <textarea id="title" class="serif title svelte-18ltlst" rows="1" autocomplete="off"></textarea></div>`),Wc=a(`<span class="grow faint"> </span>`),Gc=a(`<div class="tl-col svelte-18ltlst"><!></div>`),Kc=a(`<span class="bad svelte-18ltlst" role="alert"> </span>`),qc=a(`<div class="atbar svelte-18ltlst" role="status"><span class="label"> </span> <span class="grow"></span> <!> <button class="icon svelte-18ltlst" type="button" aria-label="restore to here" title="restore to here"><svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M3.2 9.5A5 5 0 1 0 4.6 4.3" stroke="currentColor" stroke-width="1.3" fill="none"></path><path d="M3 1.8v3.4h3.4" stroke="currentColor" stroke-width="1.3" fill="none"></path></svg></button> <button class="icon svelte-18ltlst" type="button" aria-label="back to now" title="back to now"><svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M2 8h9M8 4.8 11.2 8 8 11.2" stroke="currentColor" stroke-width="1.3" fill="none"></path><path d="M13.5 3v10" stroke="currentColor" stroke-width="1.3"></path></svg></button></div> <!>`,1),Jc=a(`<span class="toiso svelte-18ltlst" role="group" aria-label="The selected passage"><button type="button" title="Put it above Iso's box, to go with your next message from the pane" class="svelte-18ltlst"><i class="dia svelte-18ltlst" aria-hidden="true">◆</i>add to Iso's message</button> <button type="button" title="Copy it with the note it is from, to paste into an agent in your terminal" class="svelte-18ltlst"> </button></span>`),Yc=c(`<svg class="ok svelte-18ltlst" viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M3 8.5l3 3 7-7"></path></svg>`),Xc=a(`<li><a><!><span class="svelte-18ltlst"> </span><!></a></li>`),Zc=a(`<ul class="attached svelte-18ltlst"></ul>`),Qc=a(`<div class="changes svelte-18ltlst" role="status"><i class="dia svelte-18ltlst" aria-hidden="true"></i> <span class="soft"> </span> <span class="grow"></span> <button class="link svelte-18ltlst" type="button">keep all</button> <button class="link svelte-18ltlst" type="button">remove all</button></div>`),$c=a(`<!> <div class="head svelte-18ltlst"><!> <div class="side svelte-18ltlst"><div class="tools svelte-18ltlst"><button class="btn quiet svelte-18ltlst" type="button" title="The note as it is read, to be read and not edited">read</button> <button class="btn quiet svelte-18ltlst" type="button">source</button></div></div></div> <!> <!> <!> <!> <div class="live"><!></div> <!> <!>`,1),el=a(`<article><!></article>`);function tl(t,r){C(r,!0);let a=new Gn(r.id),o=new Bn(a),c=x(!1),u=F(()=>s(c)||a.meta===null),p=x(!1),h=F(()=>s(p)&&!s(u)),g=F(()=>Ye.on.timeline),y=x(null),b=x(null),S=x(!1),E=x(``),O=F(()=>xe(o.entries)),L=e=>e.who.startsWith(`iso:`)||e.who.startsWith(`agent:`),z=e=>e.flatMap(e=>Array.from({length:e.to-e.from},(t,n)=>e.from+n)),ae=F(()=>{if(!s(g)||s(b)||s(u))return null;let e=s(y)??(s(ce)?void 0:s(O).findLast(e=>L(e)&&(e.what===`kept`||e.what===`edited`)));if(!e)return null;let t=z(fe(o.entries,e.ids).runs);return t.length?{who:L(e)?`iso`:`you`,lines:t}:null}),U=F(()=>{if(!s(b))return null;let e=Me(s(b)),t=ge(o.entries,e);if(t===null)return null;let n=o.entries.filter(t=>t.id<=e),r=o.entries.find(e=>e.id===s(b).ids[0]),i=(s(b).what===`offered`||s(b).what===`discarded`)&&r?.kind===`proposal`?r.form===`insert`?r.text:r.regions.map(e=>e.new).join(`
15
+
16
+ `):void 0;return{text:t,touched:{who:L(s(b))?`iso`:`you`,lines:z(fe(n,s(b).ids).runs)},asked:s(b).asked,offered:i}}),W=()=>Xe.url.searchParams.get(`at`)??new URLSearchParams(location.hash.split(`?`)[1]??``).get(`at`),G=x(re(W()));v(()=>{let e=W();e&&k(G,e,!0)}),v(()=>{if(!s(G))return;let e=s(O).find(e=>e.ids.includes(s(G)));e&&(k(G,null),Ye.flip(`timeline`,!0),k(b,e))});let ce=F(()=>Ye.on.provenance);v(()=>{s(g)||(k(b,null),k(y,null))});let le=F(()=>{if(!s(ce)||a.loaded!==`ready`)return[];let e=[],t=Ee(o.entries),n=a.text.split(`
17
+ `);if(t&&t.length===n.length){let r=0;for(let[i,a]of n.entries()){for(let n of t[i])(n.who.startsWith(`iso:`)||n.who.startsWith(`agent:`))&&n.to<=a.length&&a.slice(n.from,n.to).trim()&&e.push({kind:`by-iso`,from:r+n.from,to:r+n.to});r+=a.length+1}}for(let t of Ze.parts){if(t.kind!==`passage`||t.id!==r.id)continue;let n=a.text.indexOf(t.text);n>=0&&e.push({kind:`given`,from:n,to:n+t.text.length})}return e});function ue(e){k(E,``),k(b,s(b)===e?null:e)}function de(e){if(!s(b))return;let t=s(O).indexOf(s(b))+e;t>=0&&t<s(O).length&&k(b,s(O)[t])}async function me(){if(s(b)){k(S,!0),k(E,``);try{await a.restore(Me(s(b))),k(b,null)}catch(e){k(E,e.message,!0)}finally{k(S,!1)}}}function he(e){!s(b)||e.altKey||e.ctrlKey||e.metaKey||e.target instanceof HTMLElement&&(e.target.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.target.tagName))||(e.key===`ArrowLeft`||e.key===`ArrowUp`?(e.preventDefault(),de(-1)):e.key===`ArrowRight`||e.key===`ArrowDown`?(e.preventDefault(),de(1)):e.key===`Escape`&&(e.preventDefault(),k(b,null)))}N(()=>{K.open=r.id,a.open().then(()=>o.open());let e=()=>{a.save()};return addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,e),()=>{removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,e),o.close(),a.close(),K.here=``,K.open=``,K.saving=null}});async function _e(){let e=r.id.split(`/`).at(-1),t=a.fields.title.trim();if(!/^untitled-(note|question|problem)(-\d+)?$/.test(e)||!t||/^untitled (note|question|problem)( \d+)?$/i.test(t))return;let n=[...r.id.split(`/`).slice(0,-1),pe(t)].filter(Boolean).join(`/`);if(pe(t)&&!K.listing.notes.some(e=>e.id===n))try{let e=await a.move(n);await K.refresh(),await H(ve(e),{replaceState:!0})}catch{}}v(()=>{a.loaded===`ready`&&Ye.fresh===r.id&&(Ye.fresh=``,_().then(()=>{let e=document.getElementById(`title`);e?.focus(),e?.select()}))});let be={saved:`saved`,unsaved:`not saved yet`,saving:`saving`,conflict:`changed elsewhere: choose below`,failed:`not saved`};v(()=>{K.here=a.loaded===`ready`?a.fields.title||r.id.split(`/`).at(-1):``,K.saving=a.loaded===`ready`?{text:a.saving===`failed`?`not saved: ${a.message}`:be[a.saving],bad:a.saving===`failed`||a.saving===`conflict`}:null});let Se=F(()=>[...new Set(o.changes.map(e=>qe(e.proposal.who)||`Iso`))].join(` and `)),Ce=F(()=>ye(String(a.meta?.type??``))),we=F(()=>s(Ce)===`note`?null:se(a.meta??{},s(Ce))),Te=F(()=>K.listing.notes.filter(e=>e.kind&&e.id!==r.id&&e.attached?.includes(r.id)).sort((e,t)=>e.kind===t.kind?0:e.kind===`question`?-1:1)),De=x(!1);async function Oe(){k(De,!0);try{await a.setDone(!s(we))}catch{}finally{k(De,!1)}}let ke=F(()=>o.cursor&&o.cursor.to>o.cursor.from?a.text.slice(o.cursor.from,o.cursor.to).trim():``),Ae=x(void 0),je=x(null);v(()=>{if(o.cursor,!s(ke)||!s(Ae)||s(u)||s(b)){k(je,null);return}let e=requestAnimationFrame(()=>{let e=getSelection(),t=s(Ae).getBoundingClientRect(),n=e?.rangeCount?e.getRangeAt(0).getBoundingClientRect():null;!n||!n.width&&!n.height?k(je,{top:8,left:t.width-140},!0):k(je,{top:Ye.narrow?n.bottom-t.top+30:n.top-t.top-36,left:Math.max(8,Math.min(n.left-t.left,t.width-140))},!0)});return()=>cancelAnimationFrame(e)});let Ne=x(!1);function Pe(){if(!s(ke))return;let e=s(ke).split(`
18
+ `).map(e=>`> ${e}`).join(`
19
+ `);navigator.clipboard?.writeText(`From /${r.id}.md in the notes:\n\n${e}\n`).then(()=>{k(Ne,!0),setTimeout(()=>{k(Ne,!1),k(je,null)},900)},()=>void 0)}function Fe(){s(ke)&&(Ze.add({kind:`passage`,id:r.id,title:a.fields.title||r.id,text:s(ke)}),k(je,null))}var Ie=el();n(`keydown`,m,he);let Le;var Re=e(Ie),ze=t=>{var n=Lc();zn(e(n),{label:`opening`}),D(n),d(t,n)},Ve=t=>{var n=Rc(),i=w(n),a=P(e(i)),o=I(a,!0);M(),D(i);var s=P(i,2),c=I(s);l(e=>{A(o,r.id),T(c,`href`,e)},[()=>oe(`/notes`)]),d(t,n)},He=e=>{var t=zc(),n=I(t,!0);l(()=>A(n,a.message)),d(e,t)},Ue=t=>{var m=$c(),_=w(m),v=t=>{var n=Vc(),r=P(e(n),2),i=I(r,!0),o=P(r,2),s=e(o),c=P(s,2),u=e=>{var t=Bc();V(`click`,t,()=>a.keepTheirs()),d(e,t)};j(c,e=>{a.theirs&&e(u)}),D(o),M(2),D(n),l(()=>A(i,a.theirs===null?`This note was deleted or moved while you were writing.`:`This note was changed somewhere else while you were writing. Nothing here has been saved over it.`)),V(`click`,s,()=>a.keepMine()),d(t,n)};j(_,e=>{a.saving===`conflict`&&e(v)});var x=P(_,2),C=e(x),te=t=>{var n=Hc(),i=e(n),o=e=>{Nc(e,()=>s(Ce),()=>!!s(we))};j(i,e=>{s(Ce)!==`note`&&e(o)});var c=P(i,2),u=I(c,!0);D(n),l(e=>A(u,e),[()=>a.fields.title||r.id.split(`/`).at(-1)]),d(t,n)},N=t=>{var i=Uc(),o=e(i),c=e=>{Nc(e,()=>s(Ce),()=>!!s(we))};j(o,e=>{s(Ce)!==`note`&&e(c)});var u=P(o,4);ee(u),D(i),l(e=>{ne(u,a.fields.title),T(u,`placeholder`,e)},[()=>r.id.split(`/`).at(-1)]),V(`input`,u,e=>a.setFields({title:e.currentTarget.value.replace(/\s*\n\s*/g,` `)})),V(`keydown`,u,e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())}),n(`blur`,u,()=>void _e()),d(t,i)},re=e=>{var t=Wc(),n=I(t);l(()=>A(n,`${r.id??``}.md${a.meta===null?`: the frontmatter cannot be read, so the file is shown as it is`:``}`)),d(e,t)};j(C,e=>{s(h)?e(te):s(u)?e(re,-1):e(N,1)});var L=P(C,2),R=e(L),z=e(R),oe=P(z,2);D(R),D(L),D(x);var H=P(x,2),W=e=>{lr(e,{get note(){return a},get kind(){return s(Ce)},get done(){return s(we)},get marking(){return s(De)},onmark:()=>void Oe()})};j(H,e=>{!s(u)&&!s(h)&&e(W)});var G=P(H,2),se=t=>{var n=Gc(),r=e(n);{let e=F(()=>s(b)?Me(s(b)):null);Be(r,{get moments(){return s(O)},strata:!0,get at(){return s(e)},get pointed(){return s(y)},point:e=>k(y,e),pick:ue})}D(n),d(t,n)};j(G,e=>{s(g)&&!s(u)&&!s(h)&&e(se)});var ce=P(G,2),de=t=>{var n=qc(),r=w(n),i=e(r),o=I(i),c=P(i,4),u=e=>{var t=Kc(),n=I(t,!0);l(()=>A(n,s(E))),d(e,t)};j(c,e=>{s(E)&&e(u)});var p=P(c,2),m=P(p,2);D(r);var h=P(r,2);f(h,()=>Me(s(b)),e=>{Mc(e,{get id(){return a.id},get text(){return s(U).text},get title(){return a.fields.title},get touched(){return s(U).touched},get asked(){return s(U).asked},get offered(){return s(U).offered}})}),l((e,t)=>{A(o,`${e??``} · ${t??``}`),p.disabled=s(S)||s(U).text===a.text},[()=>Je(s(b)),()=>Ke(s(b).at)]),V(`click`,p,me),V(`click`,m,()=>k(b,null)),d(t,n)};j(ce,e=>{s(b)&&s(U)&&e(de)});var fe=P(ce,2),pe=t=>{var n=Jc();let r;var i=e(n),a=P(i,2),o=I(a,!0);D(n),l(()=>{r=ie(n,``,r,{top:`${s(je).top??``}px`,left:`${s(je).left??``}px`}),A(o,s(Ne)?`copied`:`copy for a terminal`)}),V(`pointerdown`,i,e=>{e.preventDefault(),Fe()}),V(`click`,i,e=>{e.detail===0&&Fe()}),V(`pointerdown`,a,e=>{e.preventDefault(),Pe()}),V(`click`,a,e=>{e.detail===0&&Pe()}),d(t,n)};j(fe,e=>{s(je)&&e(pe)});var he=P(fe,2),ge=e(he);f(ge,()=>`${s(u)}${s(h)}`,e=>{Dc(e,{get note(){return a},get iso(){return o},get source(){return s(u)},get reading(){return s(h)},get touched(){return s(ae)},get lens(){return s(le)}})}),D(he);var ye=P(he,2),be=t=>{var n=Zc();i(n,21,()=>s(Te),e=>e.id,(t,n)=>{var r=Xc(),i=e(r);let a;var o=e(i);Nc(o,()=>s(n).kind??`question`,()=>!!s(n).done);var c=P(o),u=I(c,!0),f=P(c),p=e=>{var t=Yc();d(e,t)};j(f,e=>{s(n).done&&e(p)}),D(i),D(r),l(e=>{T(i,`href`,e),a=B(i,1,`svelte-18ltlst`,null,a,{done:!!s(n).done&&s(n).kind===`question`}),A(u,s(n).title)},[()=>ve(s(n).id)]),d(t,r)}),D(n),d(t,n)};j(ye,e=>{s(Te).length&&!s(u)&&!s(b)&&!s(h)&&e(be)});var xe=P(ye,2),K=t=>{var n=Qc(),r=P(e(n),2),i=I(r),a=P(r,4),c=P(a,2);D(n),l(()=>{A(i,`${o.changes.length??``} ${o.changes.length===1?`change`:`changes`} from ${s(Se)??``} waiting`),a.disabled=o.busy===`all`,c.disabled=o.busy===`all`}),V(`click`,a,()=>o.settleAll(!0)),V(`click`,c,()=>o.settleAll(!1)),d(t,n)};j(xe,e=>{o.changes.length&&e(K)}),l(e=>{T(z,`aria-pressed`,s(h)),z.disabled=s(u),T(oe,`aria-pressed`,s(u)),oe.disabled=a.meta===null,T(he,`hidden`,e)},[()=>!!(s(b)&&s(U))]),V(`click`,z,()=>k(p,!s(p))),V(`click`,oe,()=>{k(p,!1),k(c,!s(c))}),d(t,m)};j(Re,e=>{a.loaded===`loading`?e(ze):a.loaded===`missing`?e(Ve,1):a.loaded===`error`?e(He,2):e(Ue,-1)}),D(Ie),te(Ie,e=>k(Ae,e),()=>s(Ae)),l(()=>Le=B(Ie,1,`note svelte-18ltlst`,null,Le,{reading:s(h),timed:s(g)&&a.loaded===`ready`&&!s(u)&&!s(h)})),d(t,Ie),R()}h([`click`,`input`,`keydown`,`pointerdown`]);function nl(e,t){C(t,!0);let n=F(()=>Xe.params.id??``),r=F(()=>!s(n).startsWith(`@`)&&W(s(n))!==null&&!K.listing.notes.some(e=>e.id===s(n)));var i=p(),a=w(i);f(a,()=>s(n),e=>{var t=p(),i=w(t),a=e=>{Ln(e,{get path(){return s(n)}})},o=e=>{tl(e,{get id(){return s(n)}})};j(i,e=>{s(r)?e(a):e(o,-1)}),d(e,t)}),d(e,i),R()}export{nl as component};
@@ -0,0 +1 @@
1
+ import"../chunks/Cz6kYWmu.js";import"../chunks/xihTtKlq.js";import{t as e}from"../chunks/Bg-39frG.js";import"../chunks/0qd6IUbO.js";function t(t){e(t,{})}export{t as component};
@@ -0,0 +1 @@
1
+ import{$ as e,E as t,F as n,H as r,I as i,J as a,N as o,R as s,_t as c,dt as l,et as u,f as d,ht as f,i as p,j as m,mt as h,nt as g,ot as _,s as v,tt as y,ut as b,v as x,y as S,z as C}from"../chunks/Cz6kYWmu.js";import"../chunks/xihTtKlq.js";import{a as w,i as T,n as E}from"../chunks/DgI3Vj5v.js";import"../chunks/0qd6IUbO.js";var D=i(`<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=p(t,`width`,3,72);var r=D();a(()=>{d(r,`width`,n()),d(r,`height`,n()*9.9/32.4)}),o(e,r)}var k=n(`<button type="button" role="radio"> </button>`),A=n(`<div class="swatch svelte-h119xx"><i class="svelte-h119xx"></i><span> </span></div>`),j=n(`<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=n(`<!><!>`,1),N=n(`<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">Lyth Mono, for display</p> <p>Lyth 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){l(i,!1);let s=[`ground-0`,`ground-1`,`ground-2`,`ground-3`,`line`,`line-strong`],p=[`text`,`text-soft`,`text-faint`],D=[`lattice`,`growth`,`malachite`,`rose`];v();var P=N(),F=e(P),I=g(e(F),2);t(I,5,()=>E,([e,t])=>e,(e,t)=>{var n=_(()=>c(r(t),2));let i=()=>r(n)[0],s=()=>r(n)[1];var l=k();let u;var f=y(l,!0);a(()=>{u=S(l,1,`btn`,null,u,{primary:T.chosen===i()}),d(l,`aria-checked`,T.chosen===i()),m(f,s())}),C(`click`,l,()=>T.choose(i())),o(e,l)}),f(I),f(F);var L=g(F,2),R=g(e(L),2),z=e(R);O(z,{width:216}),O(g(z),{}),f(R),f(L);var B=g(L,2),V=g(e(B),2);t(V,5,()=>s,e=>e,(t,n)=>{var i=A(),s=e(i);let c;var l=g(s),u=y(l,!0);f(i),a(()=>{c=x(s,``,c,{background:`var(--${r(n)})`}),m(u,r(n))}),o(t,i)}),f(V);var H=g(V,2);t(H,5,()=>p,e=>e,(t,n)=>{var i=A(),s=e(i);let c;var l=g(s),u=y(l,!0);f(i),a(()=>{c=x(s,``,c,{background:`var(--${r(n)})`}),m(u,r(n))}),o(t,i)}),f(H);var U=g(H,2);t(U,5,()=>D,e=>e,(t,n)=>{var i=j(),s=u(i),c=e(s);let l;var d=g(c),p=y(d,!0);f(s);var h=g(s,2),_=e(h);let v;var b=g(_),S=y(b);f(h),a(()=>{l=x(c,``,l,{background:`var(--${r(n)})`}),m(p,r(n)),v=x(_,``,v,{background:`var(--${r(n)}-soft)`}),m(S,`${r(n)??``}-soft`)}),o(t,i)}),f(U),f(B);var W=g(B,2),G=g(e(W),2);x(G,``,{},{"font-size":`22px`});var K=g(G,4);x(K,``,{},{"font-size":`18px`}),f(W);var q=g(W,4),J=g(e(q),2),Y=e(J);w(Y,{id:`a`,size:28,growing:!0});var X=g(Y);w(X,{id:`a`,size:88,growing:!0});var Z=g(X);w(Z,{id:`b`,size:88,growing:!0});var Q=g(Z);w(Q,{id:`c`,size:88,growing:!0}),f(J);var $=g(J,2);t($,4,()=>[`a`,`b`,`c`,`d`,`e`,`f`,`g`,`h`],e=>e,(e,t)=>{var n=M(),r=u(n);w(r,{get id(){return t},size:44});var i=g(r);w(i,{get id(){return t},size:20}),o(e,n)}),f($),f(q),h(2),f(P),o(n,P),b()}s([`click`]);export{P as component};
@@ -0,0 +1 @@
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:Math.max(v,d[0]+2*b),h:d[1]+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)})}}})();
@@ -1 +1 @@
1
- {"version":"1793616076710"}
1
+ {"version":"1793933745371"}
@@ -0,0 +1,112 @@
1
+ Copyright (c) 2015-2026, Renzhi Li (aka. Belleve Invis, belleve@typeof.net)
2
+
3
+ Build configuration (c) 2026, Yuri Turov
4
+
5
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
6
+
7
+ This license is copied below, and is also available with a FAQ at:
8
+ http://scripts.sil.org/OFL
9
+
10
+ --------------------------
11
+
12
+
13
+ SIL Open Font License v1.1
14
+ ====================================================
15
+
16
+
17
+ Preamble
18
+ ----------
19
+
20
+ The goals of the Open Font License (OFL) are to stimulate worldwide
21
+ development of collaborative font projects, to support the font creation
22
+ efforts of academic and linguistic communities, and to provide a free and
23
+ open framework in which fonts may be shared and improved in partnership
24
+ with others.
25
+
26
+ The OFL allows the licensed fonts to be used, studied, modified and
27
+ redistributed freely as long as they are not sold by themselves. The
28
+ fonts, including any derivative works, can be bundled, embedded,
29
+ redistributed and/or sold with any software provided that any reserved
30
+ names are not used by derivative works. The fonts and derivatives,
31
+ however, cannot be released under any other type of license. The
32
+ requirement for fonts to remain under this license does not apply
33
+ to any document created using the fonts or their derivatives.
34
+
35
+
36
+ Definitions
37
+ -------------
38
+
39
+ `"Font Software"` refers to the set of files released by the Copyright
40
+ Holder(s) under this license and clearly marked as such. This may
41
+ include source files, build scripts and documentation.
42
+
43
+ `"Reserved Font Name"` refers to any names specified as such after the
44
+ copyright statement(s).
45
+
46
+ `"Original Version"` refers to the collection of Font Software components as
47
+ distributed by the Copyright Holder(s).
48
+
49
+ `"Modified Version"` refers to any derivative made by adding to, deleting,
50
+ or substituting -- in part or in whole -- any of the components of the
51
+ Original Version, by changing formats or by porting the Font Software to a
52
+ new environment.
53
+
54
+ `"Author"` refers to any designer, engineer, programmer, technical
55
+ writer or other person who contributed to the Font Software.
56
+
57
+
58
+ Permission & Conditions
59
+ ------------------------
60
+
61
+ Permission is hereby granted, free of charge, to any person obtaining
62
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
63
+ redistribute, and sell modified and unmodified copies of the Font
64
+ Software, subject to the following conditions:
65
+
66
+ 1. Neither the Font Software nor any of its individual components,
67
+ in Original or Modified Versions, may be sold by itself.
68
+
69
+ 2. Original or Modified Versions of the Font Software may be bundled,
70
+ redistributed and/or sold with any software, provided that each copy
71
+ contains the above copyright notice and this license. These can be
72
+ included either as stand-alone text files, human-readable headers or
73
+ in the appropriate machine-readable metadata fields within text or
74
+ binary files as long as those fields can be easily viewed by the user.
75
+
76
+ 3. No Modified Version of the Font Software may use the Reserved Font
77
+ Name(s) unless explicit written permission is granted by the corresponding
78
+ Copyright Holder. This restriction only applies to the primary font name as
79
+ presented to the users.
80
+
81
+ 4. The name(s) of the Copyright Holder(s) or the Author(s) of the Font
82
+ Software shall not be used to promote, endorse or advertise any
83
+ Modified Version, except to acknowledge the contribution(s) of the
84
+ Copyright Holder(s) and the Author(s) or with their explicit written
85
+ permission.
86
+
87
+ 5. The Font Software, modified or unmodified, in part or in whole,
88
+ must be distributed entirely under this license, and must not be
89
+ distributed under any other license. The requirement for fonts to
90
+ remain under this license does not apply to any document created
91
+ using the Font Software.
92
+
93
+
94
+
95
+ Termination
96
+ -----------
97
+
98
+ This license becomes null and void if any of the above conditions are
99
+ not met.
100
+
101
+
102
+ DISCLAIMER
103
+
104
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
105
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
106
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
107
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
108
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
109
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
110
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
111
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
112
+ OTHER DEALINGS IN THE FONT SOFTWARE.