graview 0.1.22 → 0.1.24

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 (80) hide show
  1. package/dist/preview/chunk.2STFOAXA.js +1 -0
  2. package/dist/preview/chunk.2VX6H2LL.js +1 -0
  3. package/dist/preview/chunk.33C6VZAD.js +1 -0
  4. package/dist/preview/{chunk.L5G5DTFX.js → chunk.3O2QU7LU.js} +1 -1
  5. package/dist/preview/chunk.3TNQPFIK.js +1 -0
  6. package/dist/preview/{chunk.SQD7ZPEJ.js → chunk.42U4UBDE.js} +1 -1
  7. package/dist/preview/{chunk.Q7WQ5UIE.js → chunk.47GRZWQN.js} +1 -1
  8. package/dist/preview/{chunk.HCK6IHGP.js → chunk.53RZI5PM.js} +1 -1
  9. package/dist/preview/{chunk.DO4P2UK4.js → chunk.54NSG7BX.js} +1 -1
  10. package/dist/preview/{chunk.6C7SJJQO.js → chunk.6MCK7K3M.js} +1 -1
  11. package/dist/preview/{chunk.DAKED3WK.js → chunk.6O67NOZR.js} +1 -1
  12. package/dist/preview/{chunk.ENMNLR73.js → chunk.6XBLDV4A.js} +1 -1
  13. package/dist/preview/chunk.7EN53F4Q.js +9 -0
  14. package/dist/preview/chunk.7Q7S7YCA.js +1 -0
  15. package/dist/preview/{chunk.BQV62QEL.js → chunk.7U7Q3HIS.js} +1 -1
  16. package/dist/preview/{chunk.6CLHFNDM.js → chunk.AKOC43TV.js} +14 -14
  17. package/dist/preview/{chunk.7YCQZJGB.js → chunk.AXACXB4D.js} +1 -1
  18. package/dist/preview/{chunk.ZKUXPS44.js → chunk.BLAODPYJ.js} +1 -1
  19. package/dist/preview/chunk.BNSY25SG.js +1 -0
  20. package/dist/preview/{chunk.XYZ7KAMZ.js → chunk.C7KLA2MW.js} +1 -1
  21. package/dist/preview/{chunk.WGNF4E67.js → chunk.D3CYTXNZ.js} +1 -1
  22. package/dist/preview/chunk.DQL3WKR3.js +1 -0
  23. package/dist/preview/chunk.EUCXNNCZ.js +107 -0
  24. package/dist/preview/{chunk.VVZ2Z7OS.js → chunk.FKQTQ3FV.js} +1 -1
  25. package/dist/preview/{chunk.DJ26NOOW.js → chunk.FRNIWOKD.js} +1 -1
  26. package/dist/preview/chunk.GDIRDJF3.js +1 -0
  27. package/dist/preview/chunk.H3HRTEW7.js +1 -0
  28. package/dist/preview/{chunk.SCLIBKLS.js → chunk.HAQ4KHRY.js} +1 -1
  29. package/dist/preview/{chunk.JE4VH767.js → chunk.HDEQXJWX.js} +1 -1
  30. package/dist/preview/chunk.HH6WIUK3.js +8 -0
  31. package/dist/preview/{chunk.ZFUQA3KT.js → chunk.ISAMJ7AK.js} +1 -1
  32. package/dist/preview/{chunk.FLDFRFDH.js → chunk.KKTHQJ6F.js} +2 -2
  33. package/dist/preview/chunk.KWSXL3A2.js +1 -0
  34. package/dist/preview/{chunk.LGUV2J6Q.js → chunk.LW7KV5SL.js} +1 -1
  35. package/dist/preview/{chunk.R5K7NK4U.js → chunk.MYCTNK6D.js} +1 -1
  36. package/dist/preview/chunk.NRWJ6PLU.js +1 -0
  37. package/dist/preview/{chunk.M4XNUM2A.js → chunk.OXODTBOP.js} +1 -1
  38. package/dist/preview/{chunk.ACZGK7LQ.js → chunk.PRXKRG6O.js} +1 -1
  39. package/dist/preview/{chunk.EQOU4POV.js → chunk.RGXNZ7PN.js} +1 -1
  40. package/dist/preview/chunk.RT3XFR6E.js +20 -0
  41. package/dist/preview/{chunk.ELEHYYCN.js → chunk.S4FO7Y2Q.js} +1 -1
  42. package/dist/preview/{chunk.3MLQ3Q5X.js → chunk.TDW6QEG4.js} +1 -1
  43. package/dist/preview/{chunk.VNC6H6IM.js → chunk.TWFYXD3P.js} +1 -1
  44. package/dist/preview/{chunk.AZG6V3PF.js → chunk.TWGB347L.js} +1 -1
  45. package/dist/preview/chunk.UEBBASQW.js +1 -0
  46. package/dist/preview/chunk.UIZWVBJ7.js +1 -0
  47. package/dist/preview/{chunk.FLJP3BGP.js → chunk.UM5IPM22.js} +1 -1
  48. package/dist/preview/{chunk.NOXC454O.js → chunk.VLNI5U6H.js} +1 -1
  49. package/dist/preview/{chunk.CJQL7AHT.js → chunk.VTBAKTFP.js} +2 -2
  50. package/dist/preview/{chunk.UNRYIETM.js → chunk.WEGBBWWK.js} +1 -1
  51. package/dist/preview/{chunk.LZQZP2PD.js → chunk.WOTNMTIY.js} +1 -1
  52. package/dist/preview/{chunk.THBP5EES.js → chunk.XCOPECOJ.js} +1 -1
  53. package/dist/preview/chunk.XDPRWUCJ.js +1 -0
  54. package/dist/preview/{chunk.3HEJZPJM.js → chunk.XDVKD6VX.js} +1 -1
  55. package/dist/preview/{chunk.YAONM74M.js → chunk.XJNXSQT4.js} +1 -1
  56. package/dist/preview/{chunk.ZQZ557VR.js → chunk.XUXCDUKC.js} +1 -1
  57. package/dist/preview/chunk.Y4R77MKX.js +1 -0
  58. package/dist/preview/chunk.ZQ4HFIIS.js +8 -0
  59. package/dist/preview/page.js +2 -2
  60. package/package.json +6 -6
  61. package/dist/preview/chunk.2F7OKRDK.js +0 -9
  62. package/dist/preview/chunk.4CDEIDKB.js +0 -1
  63. package/dist/preview/chunk.4JSMCNF7.js +0 -1
  64. package/dist/preview/chunk.4UQLZ7VW.js +0 -1
  65. package/dist/preview/chunk.5MAMCKVU.js +0 -1
  66. package/dist/preview/chunk.75WDSWXL.js +0 -20
  67. package/dist/preview/chunk.7YC34AIK.js +0 -1
  68. package/dist/preview/chunk.AZYJTNSM.js +0 -107
  69. package/dist/preview/chunk.DN4D4HGX.js +0 -1
  70. package/dist/preview/chunk.K7UJG5II.js +0 -1
  71. package/dist/preview/chunk.KFLY4MAT.js +0 -1
  72. package/dist/preview/chunk.KWYU5NPM.js +0 -1
  73. package/dist/preview/chunk.LSLFKW4M.js +0 -1
  74. package/dist/preview/chunk.OR6ZWN76.js +0 -1
  75. package/dist/preview/chunk.PC6FAJF5.js +0 -1
  76. package/dist/preview/chunk.VRXWNUDR.js +0 -1
  77. package/dist/preview/chunk.WTF3CP76.js +0 -1
  78. package/dist/preview/chunk.XEJS2VS5.js +0 -8
  79. package/dist/preview/chunk.Y235YZSZ.js +0 -8
  80. package/dist/preview/chunk.YU64JSAL.js +0 -1
@@ -1 +1 @@
1
- import{e as ge}from"./chunk.ZFUQA3KT.js";import{I as _,Ja as G,K as M,L as J,N as re,O as se,Q as W,R as ae,S as B,T as K,Ua as pe,W as de,ea as ce,fa as P,ga as le,ha as j,ia as ue,ua as fe,zb as he}from"./chunk.Y235YZSZ.js";function me(e){let t=new Set;for(let n=e;n;n=n.onBehalfOf)n.id!==void 0&&t.add(`${n.kind}:${n.id}`);return t}function F(e,t){let n=me(t),u=p=>{if(p.kind==="rule")return!1;let d=me(p);if(d.size===0)return!1;for(let g of d)if(n.has(g))return!1;return!0},f,c=()=>{if(f)return f;f=new Map;for(let p of e.log.live()){if(p.undoes!==void 0)continue;let d=u(p.author)?p.author:void 0;for(let g of p.primitives){g.op==="remove-node"&&f.delete(g.node.id);let s=g.op==="add-node"?g.node.id:g.op==="patch-node"?g.id:void 0;if(s===void 0)continue;let a=g.op==="add-node"?Object.keys(g.node):Object.keys(g.after),h=f.get(s);(g.op==="add-node"||!h)&&f.set(s,h=new Map);for(let y of a)y==="id"||y==="kind"||(d?h.set(y,d):h.delete(y))}}return f},S=e.schema,v=new Map,i=(p,d)=>{let g=`${p}\0${d}`,s=v.get(g);if(s===void 0){let a=S.tryDefinition(p)?.fields?.shape;s=a!==void 0&&d in a&&le(a[d]).type==="text",v.set(g,s)}return s},l=p=>e.graph.getNode(p)?.kind;return{prose:i,say:p=>de(p,{graph:e.graph,schema:S}),fieldBy(p,d){let g=l(p);if(!(g===void 0||!i(g,d)))return c().get(p)?.get(d)},recordBy(p){let d=l(p),g=c().get(p);if(d===void 0||!g)return;let s;for(let[a,h]of g)i(d,a)&&(s=h);return s}}}var E=(e,t,n)=>({untrusted:!0,authoredBy:n.say(t),text:e});function z(e,t){let n;for(let[u,f]of Object.entries(e)){if(typeof f!="string"||u==="id"||u==="kind")continue;let c=t.fieldBy(e.id,u);c&&(n??={...e},n[u]=E(f,c,t))}return n??e}function ye(e,t,n){let u=f=>{if(Array.isArray(f))return f.map(u);if(f!==null&&typeof f=="object"&&"id"in f&&"label"in f){let c=f,S=n.recordBy(c.id);return S?{...c,label:E(c.label,S,n)}:c}if(typeof f=="string"){let c=n.recordBy(e);return c?E(f,c,n):f}return f};return Object.fromEntries(Object.entries(t).map(([f,c])=>[f,u(c)]))}function ke(e,t){return{...e,nodes:e.nodes.map(n=>z(n,t))}}function we(e,t){return{...e,hits:e.hits.map(n=>{if(n.about!=="node")return n;let u=t.recordBy(n.id);if(!u)return n;let f=t.prose(n.kind,n.why.field)?t.fieldBy(n.id,n.why.field):u;return{...n,label:E(n.label,u,t),...n.apart!==void 0?{apart:E(n.apart,u,t)}:{},why:f?{...n.why,fragment:E(n.why.fragment,f,t)}:n.why}})}}function be(){return{name:"insight",derive({store:e,nodes:t,kindSelection:n}){let u=[],f=c=>_(e.schema.tryDefinition(c.kind),c);for(let c of t){if([...e.schema.edgeKinds].reduce((v,i)=>v+e.graph.out(c.id,i).length+e.graph.in(c.id,i).length,0)===0){u.push({id:`insight:island:${c.id}`,text:`${f(c)} is connected to nothing yet`,nodeIds:[c.id]});continue}for(let v of e.schema.edgeKinds){let i=e.graph.in(c.id,v).length;if(i<3)continue;let l=[...e.graph.allEdges()].filter(d=>d.kind===v),p=l.length;p>=4&&i/p>.6&&u.push({id:`insight:load:${c.id}:${v}`,text:`${f(c)} ${Ee(e,l,v,i)}`,nodeIds:[c.id]})}}for(let c of n){if(e.graph.nodesOfKind(c).length>0)continue;let S=e.schema.definitions.filter(v=>v.kind!==c).filter(v=>Object.values(v.edges).some(i=>i.to!=="*"&&i.to.includes(c))).map(v=>v.plural??`${v.kind}s`);S.length>0&&u.push({id:`insight:gap:${c}`,text:`Nothing here yet, though ${S.join(" and ")} expect to connect to these`,nodeIds:[]})}return{observations:u}}}}function Ee(e,t,n,u){let f=new Set(t.map(l=>e.graph.getNode(l.from)?.kind).filter(l=>l!==void 0)),c=f.size===1?[...f][0]:void 0,S=t.length,v=W(e.schema,c??[...f][0]??"",n,"in"),i=l=>c?re(e.schema,c,l):String(l);return u===S?`${v}: all ${i(u)}`:`${v}: ${u} of the ${i(S)}`}function ve(e){let t=new Map;if(e.length===0)return t;let n=e.slice(-512),u=new Set;for(let c of n)c.undoes&&u.add(c.undoes);let f=e[e.length-1].seq;for(let c of n){if(!c.mutation||u.has(c.id))continue;let S=Math.pow(.5,(f-c.seq)/64);t.set(c.mutation.name,(t.get(c.mutation.name)??0)+S)}return t}function Se(e){return 8*(e/(e+1))}var Ce=100;function Ae(){return{name:"invariant",derive({store:e,selection:t,nodes:n,violations:u}){let f=l=>_(e.schema.tryDefinition(l.kind),l),c=new Set(t),S=u.filter(l=>l.nodeIds.some(p=>c.has(p))||l.subjectId!==void 0&&c.has(l.subjectId)),v=[],i=[];S.forEach((l,p)=>{i.push({id:`violation:${l.invariant}:${p}`,text:l.message,nodeIds:l.nodeIds}),l.repairs.forEach((d,g)=>{v.push({id:`invariant:${l.invariant}:${p}:${g}`,label:d.label,provider:"invariant",mutation:d.mutation,args:d.args??{},open:(d.missing??[]).map(s=>{let a=e.allMutations().find(o=>o.name===d.mutation);if(!a)return{name:s};let h=P(a.input).find(o=>o.name===s),y=h?h.kinds.includes("*")?e.graph.allNodes().map(o=>o.id):h.kinds.flatMap(o=>e.graph.nodesOfKind(o).map(r=>r.id)):void 0;return{name:s,shape:j(a.input,s),...h?{kinds:h.kinds}:{},...y?{candidates:y}:{}}}),score:Ce-g-(d.missing?.length??0),why:l.message,nodeIds:l.nodeIds,...l.subjectId===void 0?{}:{subjectId:l.subjectId}})})});for(let l of n){let p=e.allInvariants().filter(d=>{if(d.scope==="graph")return!1;let g=d.scope;return g.kind!==l.kind?!1:g.match?g.match(l):!0});p.length!==0&&(S.some(d=>d.subjectId===l.id||d.nodeIds.includes(l.id))||i.push({id:`holds:${l.id}`,text:`${f(l)} holds \u2014 nothing currently breaks ${p.length===1?"it":`any of its ${p.length} rules`}`,nodeIds:[l.id]}))}return{affordances:v,observations:i}}}}var Z=40;function $e(){return{name:"schema",derive({store:e,selection:t,nodes:n,kindSelection:u,edgeSelection:f}){let c=[];if(n.length===0&&f.length>0){for(let i of f){let l=e.graph.getNode(i.from),p=e.graph.getNode(i.to);if(!(!l||!p))for(let d of e.allMutations()){let g=(d.connects??[]).includes(i.kind),s=(d.severs??[]).includes(i.kind);if(!g&&!s)continue;let a={},h=[],y=P(d.input);for(let r of y){let w=r.kinds.includes("*")||r.kinds.includes(l.kind),b=r.kinds.includes("*")||r.kinds.includes(p.kind),A=w&&!y.some(k=>k!==r&&(k.kinds.includes(l.kind)||k.kinds.includes("*")));w&&!b?a[r.name]=i.from:b&&!w?a[r.name]=i.to:w&&b&&A?a[r.name]=i.from:h.push({name:r.name,kinds:r.kinds,candidates:[i.from,i.to],shape:j(d.input,r.name)})}for(let r of q(d.input,""))r in a||h.some(w=>w.name===r)||h.push({name:r,shape:j(d.input,r)});h.every(r=>r.optional===!0?!0:r.kinds!==void 0?(r.candidates?.length??0)>0:(r.candidates?.length??0)>0||r.shape!==void 0&&r.shape.type!=="unknown")&&(g&&!s&&h.length===0||c.push({id:`schema:edge:${d.name}:${i.kind}:${i.from}:${i.to}`,label:M(d),provider:"schema",mutation:d.name,args:a,open:h,...d.destructive?{destructive:!0}:{},score:(s?62:58)-h.length,why:`this line is "${W(e.schema,e.graph.getNode(i.from)?.kind??"",i.kind,"out")}"`,nodeIds:[i.from,i.to]}))}}return{affordances:c}}if(n.length===0&&u.length>0){let i=new Set(u),l=[];for(let p of e.allMutations()){if(!(p.creates??[]).some(s=>i.has(s)))continue;let d=[];for(let s of P(p.input)){let a=s.kinds.includes("*")?e.graph.allNodes().map(h=>h.id):s.kinds.flatMap(h=>e.graph.nodesOfKind(h).map(y=>y.id));d.push({name:s.name,kinds:s.kinds,candidates:a,shape:j(p.input,s.name),...s.optional?{optional:!0}:{}})}for(let s of q(p.input,""))d.some(a=>a.name===s)||d.push({name:s,shape:j(p.input,s)});if(!d.every(s=>s.optional===!0?!0:s.kinds!==void 0?(s.candidates?.length??0)>0:(s.candidates?.length??0)>0||s.shape!==void 0&&s.shape.type!=="unknown")){let s=d.filter(a=>a.optional!==!0&&a.kinds!==void 0&&!a.kinds.includes("*")&&(a.candidates?.length??0)===0);if(s.length>0){let a=[...new Set(s.flatMap(h=>h.kinds??[]))].map(h=>B(K(e.schema.tryDefinition(h),h)));l.push({id:`schema:waits:${p.name}`,text:`"${p.title??p.name}" cannot begin until there is ${a.length===1?a[0]:`${a.slice(0,-1).join(", ")} and ${a[a.length-1]}`}.`,nodeIds:[]})}continue}c.push({id:`schema:add:${p.name}`,label:M(p),provider:"schema",mutation:p.name,args:{},open:d,score:Z-d.length,why:`this makes ${(p.creates??[]).filter(s=>i.has(s)).map(s=>B(K(e.schema.tryDefinition(s),s))).join(", ")}`,nodeIds:[]})}return{affordances:c,observations:l}}if(n.length===0)return{};let S=new Set(n.map(i=>i.kind)),v=(i,l,p)=>{let d=[];for(let g of e.graph.allEdges()){if(!l.includes(g.kind))continue;let s=g.from===i?g.to:g.to===i?g.from:null;if(!s)continue;let a=e.graph.getNode(s);a&&(!p.includes("*")&&!p.includes(a.kind)||d.includes(s)||d.push(s))}return d};for(let i of e.allMutations()){let l=i.subject;if(!l||!(l.kinds==="*"?!0:[...S].every(o=>l.kinds.includes(o))))continue;let d=n.length===1?n[0].id:null,g=i.severs??[],s=i.connects??[];if(d&&g.length>0&&s.length===0&&v(d,g,["*"]).length===0)continue;let a=[];for(let o of P(i.input)){if(o.name===l.arg)continue;let r=o.kinds.includes("*")?e.graph.allNodes().map(w=>w.id):o.kinds.flatMap(w=>e.graph.nodesOfKind(w).map(b=>b.id));if(d&&s.length>0){let w=new Set(v(d,s,o.kinds));r=r.filter(b=>!w.has(b))}else d&&g.length>0&&(r=v(d,g,o.kinds));a.push({name:o.name,kinds:o.kinds,candidates:r.filter(w=>!t.includes(w)),shape:j(i.input,o.name),...o.optional?{optional:!0}:{}})}for(let o of q(i.input,l.arg))a.some(r=>r.name===o)||a.push({name:o,shape:j(i.input,o)});if(a.length===0&&d){let o=He(i.input,l.arg);if(o.length>0&&!Le(e,i.name,{[l.arg]:d}))for(let r of o){let w=P(i.input).find(b=>b.name===r);a.push({name:r,optional:!0,...w?{kinds:w.kinds}:{},shape:j(i.input,r)})}}if(!a.every(o=>o.optional===!0?!0:o.kinds!==void 0?(o.candidates?.length??0)>0:(o.candidates?.length??0)>0||o.shape!==void 0&&o.shape.type!=="unknown"))continue;let y=n.map(o=>({[l.arg]:o.id}));a.length===0&&!y.some(o=>e.wouldChange({name:i.name,args:o}))||c.push({id:`schema:${i.name}`,label:n.length>1?`${M(i)} (${n.length})`:M(i),provider:"schema",mutation:i.name,args:y[0]??{},open:a,...i.destructive?{destructive:!0}:{},...g.length>0||s.length>0?{ties:!0}:{},...n.length>1?{batch:y}:{},score:Z-a.length,why:n.length>1?`all ${n.length} selected nodes are ${[...S].map(o=>se(e.schema,o).toLowerCase()).join(" or ")}`:`this is ${B(K(e.schema.tryDefinition(n[0].kind),n[0].kind))}`,nodeIds:n.map(o=>o.id)})}if(n.length===1){let i=n[0];for(let l of e.allMutations()){let p=l.subject,d=l.severs??[],g=l.connects??[];if(!p||d.length===0&&g.length===0)continue;let s=p.kinds==="*"?"*":p.kinds;if(s==="*"||s.includes(i.kind))continue;let a=P(l.input),h=a.find(k=>k.name!==p.arg&&(k.kinds.includes("*")||k.kinds.includes(i.kind)));if(!h)continue;let y=s,o=y.includes("*")?e.graph.allNodes().map(k=>k.id):y.flatMap(k=>e.graph.nodesOfKind(k).map(R=>R.id)),r=new Set(v(i.id,g.length>0?g:d,y)),w=g.length>0?o.filter(k=>!r.has(k)):o.filter(k=>r.has(k));if(w.length===0)continue;let b=[{name:p.arg,kinds:y,candidates:w,shape:j(l.input,p.arg)}];for(let k of a){if(k.name===h.name||k.name===p.arg)continue;let R=k.kinds.includes("*")?e.graph.allNodes().map(x=>x.id):k.kinds.flatMap(x=>e.graph.nodesOfKind(x).map(O=>O.id));b.push({name:k.name,kinds:k.kinds,candidates:R,shape:j(l.input,k.name),...k.optional?{optional:!0}:{}})}for(let k of q(l.input,h.name))k===p.arg||b.some(R=>R.name===k)||b.push({name:k,shape:j(l.input,k)});b.every(k=>k.optional===!0?!0:k.kinds!==void 0?(k.candidates?.length??0)>0:(k.candidates?.length??0)>0||k.shape!==void 0&&k.shape.type!=="unknown")&&c.push({id:`schema:tie:${l.name}:${i.id}`,label:l.fromTheOtherEnd??M(l),provider:"schema",mutation:l.name,args:{[h.name]:i.id},open:b,ties:!0,...l.destructive?{destructive:!0}:{},score:Z-b.length+2,why:`${d.length>0?"this one is on":"this one could join"} ${b[0].candidates.length===1?"it":"one of these"}`,nodeIds:[i.id]})}}return{affordances:c}}}}function He(e,t){let n=e.shape;return n?Object.entries(n).filter(([u,f])=>u!==t&&f.safeParse(void 0).success).map(([u])=>u):[]}function Le(e,t,n){try{return e.preview({name:t,args:n}),!0}catch{return!1}}function q(e,t){let n=e.shape;return n?Object.entries(n).filter(([u,f])=>u!==t&&!f.safeParse(void 0).success).map(([u])=>u):[]}var We=70,Be=80,Ke=new Set(["id","kind"]);function Oe(){return{name:"structure",derive({store:e,nodes:t}){let n=i=>_(e.schema.tryDefinition(i.kind),i);if(t.length<2)return{};let u=[],f=[],c=t.map(i=>i.id);for(let i of e.schema.edgeKinds){let l=Ge(t.map(d=>new Set([...e.graph.out(d.id,i).map(g=>g.id),...e.graph.in(d.id,i).map(g=>g.id)])));for(let d of l){let g=e.graph.getNode(d);g&&u.push({id:`shared:${i}:${d}`,text:`all ${t.length} share "${n(g)}" (${J(i).toLowerCase()})`,nodeIds:[...c,d]})}let p=new Map;for(let d of t)for(let g of[...e.graph.out(d.id,i),...e.graph.in(d.id,i)])p.set(g.id,(p.get(g.id)??0)+1);for(let[d,g]of p){if(g!==t.length-1||t.length<3)continue;let s=e.graph.getNode(d);if(!s)continue;let a=t.find(h=>![...e.graph.out(h.id,i),...e.graph.in(h.id,i)].some(y=>y.id===d));if(a){u.push({id:`near-shared:${i}:${d}`,text:`all but "${n(a)}" share "${n(s)}" (${J(i).toLowerCase()})`,nodeIds:[...c,d]});for(let h of e.allMutations()){let y=h.subject;if(!y||y.kinds!=="*"&&!y.kinds.includes(a.kind))continue;let o=Fe(h.input,s.kind);o&&f.push({id:`structure:join:${h.name}:${a.id}:${d}`,label:`${M(h)}: bring "${n(a)}" in line with the others`,provider:"structure",mutation:h.name,args:{[y.arg]:a.id,[o]:d},open:[],score:We,why:`every other selected node is connected to "${n(s)}"`,nodeIds:[a.id,d]})}}}}let S=new Set;for(let i of t)for(let l of Object.keys(i))Ke.has(l)||S.add(l);let v=i=>e.schema.definitions.find(l=>l.kind===i);for(let i of[...S].sort()){let l=v(t[0].kind),p=ae(l,i).toLowerCase(),d=l?.display?.format?.[i],g=A=>{if(!d)return A;try{return String(d(JSON.parse(A)))}catch{return A}},s=t.map(A=>A[i]),a=new Map;if(s.forEach((A,k)=>{let R=JSON.stringify(A??null),x=a.get(R);x?x.push(t[k]):a.set(R,[t[k]])}),a.size===1){let A=[...a.keys()][0];if(A==="null")continue;u.push({id:`agree:${i}`,text:`all ${t.length} share the ${p} ${g(A)}`,nodeIds:c});continue}if(t.length<3||a.size!==2)continue;let h=[...a.entries()].sort((A,k)=>k[1].length-A[1].length),[y,o]=h[0],[,r]=h[1];if(r.length!==1||y==="null")continue;let w=r[0],b=JSON.parse(y);u.push({id:`odd-one-out:${i}`,text:`${o.length} share the ${p} ${g(y)}; "${n(w)}" does not`,nodeIds:c});for(let A of e.allMutations()){let k=A.subject;if(!k||k.kinds!=="*"&&!k.kinds.includes(w.kind))continue;let R=Re(A.input);if(!R||!(i in R))continue;let x={[k.arg]:w.id,[i]:b},O=!0;for(let[D,U]of Object.entries(R)){if(D in x||U.safeParse(void 0).success)continue;let C=w[D];if(C===void 0){O=!1;break}x[D]=C}O&&f.push({id:`structure:align:${A.name}:${i}:${w.id}`,label:`Align the ${p} of "${n(w)}" with the other ${o.length}`,provider:"structure",mutation:A.name,args:x,open:[],score:Be,why:`${o.length} of ${t.length} share the ${p} ${g(y)}`,nodeIds:c})}}return{affordances:f,observations:u}}}}function Ge(e){if(e.length===0)return[];let[t,...n]=e;return[...t].filter(u=>n.every(f=>f.has(u))).sort()}function Re(e){return e.shape??null}function Fe(e,t){let n=Re(e);if(!n)return null;for(let[u]of Object.entries(n)){let f=ce(n[u]);if(f&&(f.includes("*")||f.includes(t)))return u}return null}function qe(){return[Ae(),Oe(),$e(),be()]}function je(e,t,n={}){let u=xe(),f=n.providers??qe(),c=t.map(m=>e.graph.getNode(m)).filter(m=>m!==void 0),S={store:e,selection:t,nodes:c,kindSelection:n.kindSelection??[],edgeSelection:n.edgeSelection??[],violations:e.violations(n.context),context:n.context??{}},v=[],i=[];for(let m of f){let $=m.derive(S);v.push(...$.affordances??[]),i.push(...$.observations??[])}let l=new Set(e.allMutations().filter(m=>m.pinned).map(m=>m.name)),p=new Set(n.pins?.pinned??[]),d=new Set(n.pins?.unpinned??[]),g=m=>p.has(m.mutation)?"user":l.has(m.mutation)&&!d.has(m.mutation)?"declared":void 0,s=m=>{let $=g(m);return $?{...m,pinned:$}:m},a=new Map;for(let[m,$]of ve(e.log.all()))a.set(m,Se($));let h=m=>m.pinned==="user"?0:m.pinned==="declared"?1:2,y=m=>m.score+(a.get(m.mutation)??0),o=new Map(e.allMutations().map(m=>[m.name,m])),r=new Map,w=m=>{let $=o.get(m.mutation);if(!$)return[];let N=r.get(m.mutation);N||(N=P($.input).map(V=>V.name),r.set(m.mutation,N));let H=[];for(let V of m.batch??[m.args])for(let ie of N){let oe=V[ie]??m.args[ie];typeof oe=="string"&&H.push(oe)}return H},b=n.focus,A=4,k=m=>m.open.length>0?1:0,R=m=>{if(b===void 0)return A;let $=w(m);return $.length>0?$.includes(b)?x(m,0):A:m.nodeIds.includes(b)||m.subjectId===b?x(m,1):A},x=(m,$)=>m.provider==="invariant"?$:2+k(m),O=Ue(v).map(s),D=new Map(O.map((m,$)=>[m,$])),U=O.sort((m,$)=>{let N=Number(m.destructive??!1)-Number($.destructive??!1);if(N!==0)return N;let H=R(m)-R($);return H!==0?H:R(m)<2?D.get(m)-D.get($):+($.provider==="invariant")-+(m.provider==="invariant")||h(m)-h($)||y($)-y(m)||m.id.localeCompare($.id)}),C=n.principal??{kind:"human"},L=[],ne=[];for(let m of U){let $=e.permits({name:m.mutation,args:{...m.args,...m.batch?.[0]??{}}},C);if($.ok)L.push(m);else{let N=ze(e,m,C);if(N==="done")continue;N?L.push(N):ne.push({...m,refusal:$.refusal})}}let te=L.map((m,$)=>({...m,rank:$})),_e=ne.map((m,$)=>({...m,rank:L.length+$}));return{affordances:n.limit===void 0?te:te.slice(0,n.limit),withheld:_e,observations:Ve(i),ms:xe()-u}}function Ue(e){let t=new Map;for(let n of e){let u=[n.mutation,JSON.stringify(n.args),JSON.stringify(n.batch??null)].join("|"),f=t.get(u);(!f||n.score>f.score)&&t.set(u,n)}return[...t.values()]}function Ve(e){let t=new Map;for(let n of e)t.set(n.text,n);return[...t.values()]}function xe(){return typeof performance<"u"?performance.now():Date.now()}function Je(e,t,n={},u={}){let f=(t.batch??[t.args]).map(S=>({name:t.mutation,args:{...t.args,...S,...n}})),c=e.allMutations().find(S=>S.name===t.mutation);return e.applyAll(f,{...c?.describe?{}:{intent:t.label},...u.author?{author:u.author}:{}})}function Rn(e,t,n={}){return e.preview({name:t.mutation,args:{...t.args,...n}})}function ze(e,t,n){let u=e.allMutations().find(i=>i.name===t.mutation)?.subject;if(!u||t.args[u.arg]!==void 0)return;let f=t.open.find(i=>i.name===u.arg);if(!f?.candidates)return;let c=i=>e.permits({name:t.mutation,args:{...t.args,...t.batch?.[0]??{},[u.arg]:i}},n).ok,S=f.candidates.filter(c),v=n.id===void 0?void 0:e.graph.getNode(n.id);return S.length===0?v!==void 0&&(u.kinds==="*"||u.kinds.includes(v.kind))&&c(v.id)?"done":void 0:S.length===1&&S[0]===n.id?{...t,args:{...t.args,[u.arg]:n.id},open:t.open.filter(i=>i!==f)}:{...t,open:t.open.map(i=>i===f?{...i,candidates:S}:i)}}var Pe,Ze=()=>Pe??=import("./chunk.7YC34AIK.js").catch(e=>{throw Pe=void 0,e}),Xe=()=>import("./chunk.5MAMCKVU.js").catch(()=>{}),Ye=async()=>{(await Xe())?.judgeWithLines()},Ne,Qe=()=>Ne??=import("./chunk.M4XNUM2A.js").catch(e=>{throw Ne=void 0,e}),T=e=>({title:e,readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}),X=[{name:"search_graph",title:"Find by name",description:"Find things by name: records whose name or readable fields carry the words, and the kinds, places and rules the words name \u2014 each with why it matched. Reach for this before get_graph when you know what something is called. Words match the start of words, case and accents aside; key:value tokens narrow as a list's filter does (done:false, is:any for past records, kind:<kind>). Pass subject (a node id) to get the acts you may run on it as hits too.",inputSchema:{type:"object",properties:{query:{type:"string",description:"Words, with optional key:value conditions."},limit:{type:"number",description:"Most hits to return; 20 when unsaid."},subject:{type:"string",description:"A node id whose acts to include."}},required:["query"],additionalProperties:!1},mutating:!1,annotations:T("Find by name")},{name:"get_graph",title:"Read the whole graph",description:"Read the whole graph: every node with its fields, and every edge. Start here when you need the shape of the domain rather than one thing in it.",inputSchema:{type:"object",properties:{},additionalProperties:!1},mutating:!1,annotations:T("Read the whole graph")},{name:"get_node",title:"Read one node",description:"Read one node, its edges, and the violations that implicate it, with its computed values: read-only fields worked out from what you can see, which no act sets. Use this to check a thing before you change it.",inputSchema:{type:"object",properties:{id:{type:"string",description:"A node's id, or its name."}},required:["id"],additionalProperties:!1},mutating:!1,annotations:T("Read one node")},{name:"get_violations",title:"List the problems",description:"List every invariant violation the graph currently has, with the repairs that would resolve each one. Read this before proposing work: a rule that is already broken is more urgent than anything you could add.",inputSchema:{type:"object",properties:{context:{type:"object",description:"Evaluation context, e.g. { weekStart }."}},additionalProperties:!1},mutating:!1,annotations:T("List the problems")},{name:"get_affordances",title:"Ask what can be done",description:"Ask what can legally be done with a selection, ranked. Prefer these over composing a mutation by hand: they are derived from the schema, the invariants and the shape of the graph, so they cannot name an action that does not exist.",inputSchema:{type:"object",properties:{selection:{type:"array",items:{type:"string"},description:"Node ids."},context:{type:"object"}},required:["selection"],additionalProperties:!1},mutating:!1,annotations:T("Ask what can be done")},{name:"describe_place",title:"Say what a place shows",description:`Say what one place of the app shows you, as a person in your seat would see it: its headings, its figures as drawn, its lists with each record's title and what its card or row says, the headings a list is grouped under, what an empty list says, and any block that could not be worked out. Pass a place's slug ("home", a lens's address like "the-offers", a kind's like "offers") or a record's id, and width 390 for a phone. Use it after a change to check what somebody now sees, instead of guessing.`,inputSchema:{type:"object",properties:{place:{type:"string",description:`"home", a place's slug, or a record's id.`},width:{type:"number",description:"The screen's width in CSS pixels; 390 is a phone, 1440 when unsaid."}},required:["place"],additionalProperties:!1},mutating:!1,annotations:T("Say what a place shows")},{name:"preview_mutation",title:"Try an act without applying it",description:"Try a mutation without applying it: get back the diff it would produce and any invariant it would break. Do this when you are unsure, rather than applying and undoing.",inputSchema:{type:"object",properties:{mutation:{type:"string"},args:{type:"object"}},required:["mutation","args"],additionalProperties:!1},mutating:!1,annotations:T("Try an act without applying it")},{name:"undo_batch",title:"Undo a batch",description:"Undo one batch of operations. Fails, naming the blocking operation, when a later operation read what it wrote.",inputSchema:{type:"object",properties:{batch:{type:"string"},include:{type:"array",items:{type:"string"}}},required:["batch"],additionalProperties:!1},mutating:!0,annotations:{title:"Undo a batch",readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1}}],Y={type:"object",description:"A lens, as draft_view returns one.",properties:{title:{type:"string"},lens:{type:"string"},on:{type:"string"},bindings:{type:"object"},options:{type:"object"}},required:["title","lens","on"]},Q={name:"draft_view",title:"Draw a view",description:'Draw a view of the data from words ("a board of tasks by status", "who covers what") as a lens the app could keep; or check a lens you wrote (lens); or change the one on screen (current, with ask: "only this month"). Returns the lens and its add-lens edit, or one sentence saying why not. Writes nothing.',inputSchema:{type:"object",properties:{ask:{type:"string",description:"What to see, in words."},lens:Y,current:Y},additionalProperties:!1},mutating:!1,annotations:T("Draw a view")},De={name:"keep_lens",title:"Keep a view as a lens",description:"Keep a lens draft_view drew as one of the app's places: checked again, then written as the add-lens edit. Returns the remove-lens edit that takes it back.",inputSchema:{...Y,additionalProperties:!1},mutating:!0,annotations:{title:"Keep a view as a lens",readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}};function en(e,t){return e===void 0?[]:e==="keep"&&!t?[Q,De]:[Q]}var nn="An argument that names a record takes its id or its name.",Te=[...X.map(e=>e.name),Q.name,De.name],Ie=64;function I(e){let{line:t,...n}=e;return n}function Me(e){return{...e,...e.introduces?{introduces:e.introduces.map(I)}:{},...e.resolves?{resolves:e.resolves.map(I)}:{},...e.violationsAfter?{violationsAfter:e.violationsAfter.map(I)}:{}}}function tn(e){let t=e.normalize("NFKD").replace(/\p{M}/gu,"").replace(/[^A-Za-z0-9_-]/g,"_");return t.length===0&&(t="act"),/^[A-Za-z_]/.test(t)||(t=`act_${t}`),t.slice(0,Ie)}function on(e){let t=new Set(Te),n=new Map;for(let u of e){let f=tn(u),c=f;for(let S=2;t.has(c);S+=1)c=`${f.slice(0,Ie-`_${S}`.length)}_${S}`;t.add(c),n.set(u,c)}return n}function rn(e,t){let n=ue(e),u=M(e),f=n.nodeRefs.length>0?`${n.description}${/[.!?]$/.test(n.description)?"":"."} ${nn}`:n.description;return{name:t,title:u,description:f,inputSchema:n.inputSchema,mutating:!0,annotations:{title:u,readOnlyHint:!1,destructiveHint:e.destructive===!0||(e.severs?.length??0)>0,idempotentHint:e.idempotent===!0,openWorldHint:!1},act:e.name}}function ee(e){if(e===null||typeof e!="object")return JSON.stringify(e)??"null";if(Array.isArray(e))return`[${e.map(ee).join(",")}]`;let t=e;return`{${Object.keys(t).filter(n=>t[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${ee(t[n])}`).join(",")}}`}function sn(e){return`sha256:${he(ee(e))}`}function an(e,t,n,u){let f=on(e.map(v=>v.name)),c=en(u,n);return{definitions:n?[...X.filter(v=>!v.mutating),...c]:[...X,...c,...e.filter(v=>t.has(v.name)).map(v=>rn(v,f.get(v.name)))],names:f}}function Cn(e,t={}){let n=t.author??{kind:"agent"},u=e.allMutations(),f=new Set(e.permittedMutations(n).map(s=>s.name)),{definitions:c,names:S}=an(u,f,t.readOnly===!0,t.drafts?t.drafts.keep?"keep":"draw":void 0),v=sn(c),i=s=>{if(!Te.includes(s)){for(let[a,h]of S)if(h===s)return a;return S.has(s)?s:void 0}},l=(s,a)=>{let h=u.find(r=>r.name===s);if(!h)return{args:a,resolved:[]};let y={...a},o=[];for(let r of P(h.input)){let w=y[r.name];if(typeof w!="string"||w.trim()==="")continue;let b=e.resolveRef(r,w,n);if(!b.ok){let A=b.reason==="none"?` Nothing was changed. Use search_graph to look it up, then pass its id as ${r.name}.`:" Nothing was changed.";return{ok:!1,error:`${b.message}${A}`,argument:r.name,candidates:b.candidates}}b.by!=="id"&&(y[r.name]=b.id,o.push({argument:r.name,given:w,id:b.id,label:b.label}))}return{args:y,resolved:o}},p=async(s,a)=>{try{await Ye();let h=c.find(o=>o.name===s)??c.find(o=>o.act===s);if(!h){let o=i(s);if(o){let r=e.permits({name:o,args:a},n);if(!r.ok)return{ok:!1,error:r.refusal.message,reason:"forbidden"}}return{ok:!1,error:`Unknown tool "${s}". Available: ${c.map(r=>r.name).join(", ")}`}}if(h.mutating&&t.readOnly)return{ok:!1,error:`"${s}" changes the graph, and this seat is read-only.`,reason:"forbidden"};if(h.act!==void 0){let o=l(h.act,a);if("ok"in o)return o;let r=G(e,n,e.apply({name:h.act,args:o.args},{...t.author?{author:t.author}:{},...dn(t.via)}));return{ok:!0,data:{batch:r.batch,intent:r.intent,introduces:r.introduces.map(I),resolves:r.resolves.map(I),...o.resolved.length>0?{resolved:o.resolved}:{}},diff:r.diff}}let y=e.seenBy(n);switch(h.name){case"search_graph":{let o=typeof t.places=="function"?t.places():t.places,r=typeof a.subject=="string"?a.subject:void 0,w=pe(y,String(a.query??""),{principal:n,limit:typeof a.limit=="number"?a.limit:20,...o?{places:o}:{},...r?{subject:r,from:[r]}:{}});return{ok:!0,data:we(w,F(y,n)),reads:w.hits.flatMap(b=>b.about==="node"?[b.id]:[])}}case"get_graph":{let o=y.graph.snapshot();return{ok:!0,data:ke(o,F(y,n)),reads:o.nodes.map(r=>r.id)}}case"get_node":{let o=String(a.id??""),r=o,w;if(!y.graph.getNode(o)){let O=o.trim()===""?void 0:e.resolveRef({name:"id",kinds:["*"]},o,n);if(O?.ok)r=O.id,w={argument:"id",given:o,id:r,label:O.label};else return O?.reason==="ambiguous"?{ok:!1,error:O.message,argument:"id",candidates:O.candidates}:{ok:!1,error:`No node "${o}".`}}let b=y.graph.getNode(r),A=y.graph.outEdges(r),k=y.graph.inEdges(r),R=F(y,n),x=ge(y.schema,y.graph,b);return{ok:!0,data:{node:z(b,R),...Object.keys(x.values).length>0?{computed:ye(r,x.values,R)}:{},...Object.keys(x.refused).length>0?{uncomputed:x.refused}:{},out:A,in:k,violations:y.violations().filter(O=>O.nodeIds.includes(r)).map(I),...w?{resolved:[w]}:{}},reads:[r,...A.map(O=>O.to),...k.map(O=>O.from)]}}case"describe_place":{let o=t.app??{name:"",schema:e.schema},r=typeof a.width=="number"&&Number.isFinite(a.width)&&a.width>0?a.width:1440,{describePlace:w}=await Ze(),b=w(e,n,String(a.place??""),{app:o,width:r});if(!b.ok)return{ok:!1,error:`${b.error} The places are: ${b.places.join(", ")}.`};let A=new Set,k=R=>{for(let x of R)for(let O of x.groups??[])for(let D of O.items)A.add(D.id),k(D.parts)};return k(b.description.parts),{ok:!0,data:b.description,reads:[...A]}}case"draft_view":case"keep_lens":{let o=t.app??{name:"",schema:e.schema};return(await Qe()).runDraftTool(h.name,a,{app:o,principal:n,...t.drafts?{drafts:t.drafts}:{}})}case"get_violations":{let o=y.violations(a.context);return{ok:!0,data:o.map(I),reads:[...new Set(o.flatMap(r=>r.nodeIds))]}}case"get_affordances":{let o=a.selection??[];return{ok:!0,data:je(y,o,{...typeof t.derive=="function"?t.derive():t.derive,...t.author?{principal:t.author}:{},...a.context?{context:a.context}:{}}),reads:o.filter(w=>y.graph.has(w))}}case"preview_mutation":{let o=String(a.mutation),r=i(o)??o,w=l(r,a.args??{});if("ok"in w)return w;let b=e.missingFor({name:r,args:w.args},n);if(b)return{ok:!1,error:b.message,reason:"missing"};let A=G(e,n,e.preview({name:r,args:w.args},void 0,{author:n})),k=Me(A);return{ok:!0,data:w.resolved.length>0?{...k,resolved:w.resolved}:k}}case"undo_batch":{let o=String(a.batch),r=a.include??[],w=y.canUndo([o,...r]);if(!w.ok)return{ok:!1,error:w.message};let b=G(e,n,e.undo([o,...r],{...t.author?{author:t.author}:{}}));return{ok:!0,data:Me(b),diff:b.diff}}default:return{ok:!1,error:`Unknown tool "${s}".`}}}catch(h){let{reason:y,wouldNeed:o}=fe(h);return{ok:!1,error:h instanceof Error?h.message:String(h),reason:y,...o?{wouldNeed:o}:{}}}},d=new Set,g=s=>{for(let a of d)a(s)};return{definitions:c,hash:v,...t.author?{author:t.author}:{},onDiff(s){return e.subscribe(s)},onCall(s){return d.add(s),()=>d.delete(s)},async call(s,a){let h=(c.find(r=>r.name===s)??c.find(r=>r.act===s))?.mutating??!1,y={name:s,args:a,mutating:h,at:new Date().toISOString()};return g({...y,phase:"running"}),(r=>(g(r.ok?{...y,phase:"ok",...!h&&r.reads?{reads:r.reads}:{}}:{...y,phase:"failed",error:r.error}),r))(await p(s,a))}}}function dn(e){let t=typeof e=="function"?e():e;return t?{via:t}:{}}export{je as a,Je as b,Rn as c,Cn as d};
1
+ import{e as ge}from"./chunk.ISAMJ7AK.js";import{Cb as he,I as _,K as M,L as J,La as G,N as re,O as se,Q as W,R as ae,S as B,T as K,W as de,Xa as pe,ga as ce,ha as P,ia as le,ja as j,ka as ue,wa as fe}from"./chunk.ZQ4HFIIS.js";function me(e){let t=new Set;for(let n=e;n;n=n.onBehalfOf)n.id!==void 0&&t.add(`${n.kind}:${n.id}`);return t}function F(e,t){let n=me(t),u=p=>{if(p.kind==="rule")return!1;let d=me(p);if(d.size===0)return!1;for(let g of d)if(n.has(g))return!1;return!0},f,c=()=>{if(f)return f;f=new Map;for(let p of e.log.live()){if(p.undoes!==void 0)continue;let d=u(p.author)?p.author:void 0;for(let g of p.primitives){g.op==="remove-node"&&f.delete(g.node.id);let s=g.op==="add-node"?g.node.id:g.op==="patch-node"?g.id:void 0;if(s===void 0)continue;let a=g.op==="add-node"?Object.keys(g.node):Object.keys(g.after),h=f.get(s);(g.op==="add-node"||!h)&&f.set(s,h=new Map);for(let y of a)y==="id"||y==="kind"||(d?h.set(y,d):h.delete(y))}}return f},S=e.schema,v=new Map,i=(p,d)=>{let g=`${p}\0${d}`,s=v.get(g);if(s===void 0){let a=S.tryDefinition(p)?.fields?.shape;s=a!==void 0&&d in a&&le(a[d]).type==="text",v.set(g,s)}return s},l=p=>e.graph.getNode(p)?.kind;return{prose:i,say:p=>de(p,{graph:e.graph,schema:S}),fieldBy(p,d){let g=l(p);if(!(g===void 0||!i(g,d)))return c().get(p)?.get(d)},recordBy(p){let d=l(p),g=c().get(p);if(d===void 0||!g)return;let s;for(let[a,h]of g)i(d,a)&&(s=h);return s}}}var E=(e,t,n)=>({untrusted:!0,authoredBy:n.say(t),text:e});function z(e,t){let n;for(let[u,f]of Object.entries(e)){if(typeof f!="string"||u==="id"||u==="kind")continue;let c=t.fieldBy(e.id,u);c&&(n??={...e},n[u]=E(f,c,t))}return n??e}function ye(e,t,n){let u=f=>{if(Array.isArray(f))return f.map(u);if(f!==null&&typeof f=="object"&&"id"in f&&"label"in f){let c=f,S=n.recordBy(c.id);return S?{...c,label:E(c.label,S,n)}:c}if(typeof f=="string"){let c=n.recordBy(e);return c?E(f,c,n):f}return f};return Object.fromEntries(Object.entries(t).map(([f,c])=>[f,u(c)]))}function ke(e,t){return{...e,nodes:e.nodes.map(n=>z(n,t))}}function we(e,t){return{...e,hits:e.hits.map(n=>{if(n.about!=="node")return n;let u=t.recordBy(n.id);if(!u)return n;let f=t.prose(n.kind,n.why.field)?t.fieldBy(n.id,n.why.field):u;return{...n,label:E(n.label,u,t),...n.apart!==void 0?{apart:E(n.apart,u,t)}:{},why:f?{...n.why,fragment:E(n.why.fragment,f,t)}:n.why}})}}function be(){return{name:"insight",derive({store:e,nodes:t,kindSelection:n}){let u=[],f=c=>_(e.schema.tryDefinition(c.kind),c);for(let c of t){if([...e.schema.edgeKinds].reduce((v,i)=>v+e.graph.out(c.id,i).length+e.graph.in(c.id,i).length,0)===0){u.push({id:`insight:island:${c.id}`,text:`${f(c)} is connected to nothing yet`,nodeIds:[c.id]});continue}for(let v of e.schema.edgeKinds){let i=e.graph.in(c.id,v).length;if(i<3)continue;let l=[...e.graph.allEdges()].filter(d=>d.kind===v),p=l.length;p>=4&&i/p>.6&&u.push({id:`insight:load:${c.id}:${v}`,text:`${f(c)} ${Ee(e,l,v,i)}`,nodeIds:[c.id]})}}for(let c of n){if(e.graph.nodesOfKind(c).length>0)continue;let S=e.schema.definitions.filter(v=>v.kind!==c).filter(v=>Object.values(v.edges).some(i=>i.to!=="*"&&i.to.includes(c))).map(v=>v.plural??`${v.kind}s`);S.length>0&&u.push({id:`insight:gap:${c}`,text:`Nothing here yet, though ${S.join(" and ")} expect to connect to these`,nodeIds:[]})}return{observations:u}}}}function Ee(e,t,n,u){let f=new Set(t.map(l=>e.graph.getNode(l.from)?.kind).filter(l=>l!==void 0)),c=f.size===1?[...f][0]:void 0,S=t.length,v=W(e.schema,c??[...f][0]??"",n,"in"),i=l=>c?re(e.schema,c,l):String(l);return u===S?`${v}: all ${i(u)}`:`${v}: ${u} of the ${i(S)}`}function ve(e){let t=new Map;if(e.length===0)return t;let n=e.slice(-512),u=new Set;for(let c of n)c.undoes&&u.add(c.undoes);let f=e[e.length-1].seq;for(let c of n){if(!c.mutation||u.has(c.id))continue;let S=Math.pow(.5,(f-c.seq)/64);t.set(c.mutation.name,(t.get(c.mutation.name)??0)+S)}return t}function Se(e){return 8*(e/(e+1))}var Ce=100;function Ae(){return{name:"invariant",derive({store:e,selection:t,nodes:n,violations:u}){let f=l=>_(e.schema.tryDefinition(l.kind),l),c=new Set(t),S=u.filter(l=>l.nodeIds.some(p=>c.has(p))||l.subjectId!==void 0&&c.has(l.subjectId)),v=[],i=[];S.forEach((l,p)=>{i.push({id:`violation:${l.invariant}:${p}`,text:l.message,nodeIds:l.nodeIds}),l.repairs.forEach((d,g)=>{v.push({id:`invariant:${l.invariant}:${p}:${g}`,label:d.label,provider:"invariant",mutation:d.mutation,args:d.args??{},open:(d.missing??[]).map(s=>{let a=e.allMutations().find(o=>o.name===d.mutation);if(!a)return{name:s};let h=P(a.input).find(o=>o.name===s),y=h?h.kinds.includes("*")?e.graph.allNodes().map(o=>o.id):h.kinds.flatMap(o=>e.graph.nodesOfKind(o).map(r=>r.id)):void 0;return{name:s,shape:j(a.input,s),...h?{kinds:h.kinds}:{},...y?{candidates:y}:{}}}),score:Ce-g-(d.missing?.length??0),why:l.message,nodeIds:l.nodeIds,...l.subjectId===void 0?{}:{subjectId:l.subjectId}})})});for(let l of n){let p=e.allInvariants().filter(d=>{if(d.scope==="graph")return!1;let g=d.scope;return g.kind!==l.kind?!1:g.match?g.match(l):!0});p.length!==0&&(S.some(d=>d.subjectId===l.id||d.nodeIds.includes(l.id))||i.push({id:`holds:${l.id}`,text:`${f(l)} holds \u2014 nothing currently breaks ${p.length===1?"it":`any of its ${p.length} rules`}`,nodeIds:[l.id]}))}return{affordances:v,observations:i}}}}var Z=40;function $e(){return{name:"schema",derive({store:e,selection:t,nodes:n,kindSelection:u,edgeSelection:f}){let c=[];if(n.length===0&&f.length>0){for(let i of f){let l=e.graph.getNode(i.from),p=e.graph.getNode(i.to);if(!(!l||!p))for(let d of e.allMutations()){let g=(d.connects??[]).includes(i.kind),s=(d.severs??[]).includes(i.kind);if(!g&&!s)continue;let a={},h=[],y=P(d.input);for(let r of y){let w=r.kinds.includes("*")||r.kinds.includes(l.kind),b=r.kinds.includes("*")||r.kinds.includes(p.kind),A=w&&!y.some(k=>k!==r&&(k.kinds.includes(l.kind)||k.kinds.includes("*")));w&&!b?a[r.name]=i.from:b&&!w?a[r.name]=i.to:w&&b&&A?a[r.name]=i.from:h.push({name:r.name,kinds:r.kinds,candidates:[i.from,i.to],shape:j(d.input,r.name)})}for(let r of q(d.input,""))r in a||h.some(w=>w.name===r)||h.push({name:r,shape:j(d.input,r)});h.every(r=>r.optional===!0?!0:r.kinds!==void 0?(r.candidates?.length??0)>0:(r.candidates?.length??0)>0||r.shape!==void 0&&r.shape.type!=="unknown")&&(g&&!s&&h.length===0||c.push({id:`schema:edge:${d.name}:${i.kind}:${i.from}:${i.to}`,label:M(d),provider:"schema",mutation:d.name,args:a,open:h,...d.destructive?{destructive:!0}:{},score:(s?62:58)-h.length,why:`this line is "${W(e.schema,e.graph.getNode(i.from)?.kind??"",i.kind,"out")}"`,nodeIds:[i.from,i.to]}))}}return{affordances:c}}if(n.length===0&&u.length>0){let i=new Set(u),l=[];for(let p of e.allMutations()){if(!(p.creates??[]).some(s=>i.has(s)))continue;let d=[];for(let s of P(p.input)){let a=s.kinds.includes("*")?e.graph.allNodes().map(h=>h.id):s.kinds.flatMap(h=>e.graph.nodesOfKind(h).map(y=>y.id));d.push({name:s.name,kinds:s.kinds,candidates:a,shape:j(p.input,s.name),...s.optional?{optional:!0}:{}})}for(let s of q(p.input,""))d.some(a=>a.name===s)||d.push({name:s,shape:j(p.input,s)});if(!d.every(s=>s.optional===!0?!0:s.kinds!==void 0?(s.candidates?.length??0)>0:(s.candidates?.length??0)>0||s.shape!==void 0&&s.shape.type!=="unknown")){let s=d.filter(a=>a.optional!==!0&&a.kinds!==void 0&&!a.kinds.includes("*")&&(a.candidates?.length??0)===0);if(s.length>0){let a=[...new Set(s.flatMap(h=>h.kinds??[]))].map(h=>B(K(e.schema.tryDefinition(h),h)));l.push({id:`schema:waits:${p.name}`,text:`"${p.title??p.name}" cannot begin until there is ${a.length===1?a[0]:`${a.slice(0,-1).join(", ")} and ${a[a.length-1]}`}.`,nodeIds:[]})}continue}c.push({id:`schema:add:${p.name}`,label:M(p),provider:"schema",mutation:p.name,args:{},open:d,score:Z-d.length,why:`this makes ${(p.creates??[]).filter(s=>i.has(s)).map(s=>B(K(e.schema.tryDefinition(s),s))).join(", ")}`,nodeIds:[]})}return{affordances:c,observations:l}}if(n.length===0)return{};let S=new Set(n.map(i=>i.kind)),v=(i,l,p)=>{let d=[];for(let g of e.graph.allEdges()){if(!l.includes(g.kind))continue;let s=g.from===i?g.to:g.to===i?g.from:null;if(!s)continue;let a=e.graph.getNode(s);a&&(!p.includes("*")&&!p.includes(a.kind)||d.includes(s)||d.push(s))}return d};for(let i of e.allMutations()){let l=i.subject;if(!l||!(l.kinds==="*"?!0:[...S].every(o=>l.kinds.includes(o))))continue;let d=n.length===1?n[0].id:null,g=i.severs??[],s=i.connects??[];if(d&&g.length>0&&s.length===0&&v(d,g,["*"]).length===0)continue;let a=[];for(let o of P(i.input)){if(o.name===l.arg)continue;let r=o.kinds.includes("*")?e.graph.allNodes().map(w=>w.id):o.kinds.flatMap(w=>e.graph.nodesOfKind(w).map(b=>b.id));if(d&&s.length>0){let w=new Set(v(d,s,o.kinds));r=r.filter(b=>!w.has(b))}else d&&g.length>0&&(r=v(d,g,o.kinds));a.push({name:o.name,kinds:o.kinds,candidates:r.filter(w=>!t.includes(w)),shape:j(i.input,o.name),...o.optional?{optional:!0}:{}})}for(let o of q(i.input,l.arg))a.some(r=>r.name===o)||a.push({name:o,shape:j(i.input,o)});if(a.length===0&&d){let o=He(i.input,l.arg);if(o.length>0&&!Le(e,i.name,{[l.arg]:d}))for(let r of o){let w=P(i.input).find(b=>b.name===r);a.push({name:r,optional:!0,...w?{kinds:w.kinds}:{},shape:j(i.input,r)})}}if(!a.every(o=>o.optional===!0?!0:o.kinds!==void 0?(o.candidates?.length??0)>0:(o.candidates?.length??0)>0||o.shape!==void 0&&o.shape.type!=="unknown"))continue;let y=n.map(o=>({[l.arg]:o.id}));a.length===0&&!y.some(o=>e.wouldChange({name:i.name,args:o}))||c.push({id:`schema:${i.name}`,label:n.length>1?`${M(i)} (${n.length})`:M(i),provider:"schema",mutation:i.name,args:y[0]??{},open:a,...i.destructive?{destructive:!0}:{},...g.length>0||s.length>0?{ties:!0}:{},...n.length>1?{batch:y}:{},score:Z-a.length,why:n.length>1?`all ${n.length} selected nodes are ${[...S].map(o=>se(e.schema,o).toLowerCase()).join(" or ")}`:`this is ${B(K(e.schema.tryDefinition(n[0].kind),n[0].kind))}`,nodeIds:n.map(o=>o.id)})}if(n.length===1){let i=n[0];for(let l of e.allMutations()){let p=l.subject,d=l.severs??[],g=l.connects??[];if(!p||d.length===0&&g.length===0)continue;let s=p.kinds==="*"?"*":p.kinds;if(s==="*"||s.includes(i.kind))continue;let a=P(l.input),h=a.find(k=>k.name!==p.arg&&(k.kinds.includes("*")||k.kinds.includes(i.kind)));if(!h)continue;let y=s,o=y.includes("*")?e.graph.allNodes().map(k=>k.id):y.flatMap(k=>e.graph.nodesOfKind(k).map(R=>R.id)),r=new Set(v(i.id,g.length>0?g:d,y)),w=g.length>0?o.filter(k=>!r.has(k)):o.filter(k=>r.has(k));if(w.length===0)continue;let b=[{name:p.arg,kinds:y,candidates:w,shape:j(l.input,p.arg)}];for(let k of a){if(k.name===h.name||k.name===p.arg)continue;let R=k.kinds.includes("*")?e.graph.allNodes().map(x=>x.id):k.kinds.flatMap(x=>e.graph.nodesOfKind(x).map(O=>O.id));b.push({name:k.name,kinds:k.kinds,candidates:R,shape:j(l.input,k.name),...k.optional?{optional:!0}:{}})}for(let k of q(l.input,h.name))k===p.arg||b.some(R=>R.name===k)||b.push({name:k,shape:j(l.input,k)});b.every(k=>k.optional===!0?!0:k.kinds!==void 0?(k.candidates?.length??0)>0:(k.candidates?.length??0)>0||k.shape!==void 0&&k.shape.type!=="unknown")&&c.push({id:`schema:tie:${l.name}:${i.id}`,label:l.fromTheOtherEnd??M(l),provider:"schema",mutation:l.name,args:{[h.name]:i.id},open:b,ties:!0,...l.destructive?{destructive:!0}:{},score:Z-b.length+2,why:`${d.length>0?"this one is on":"this one could join"} ${b[0].candidates.length===1?"it":"one of these"}`,nodeIds:[i.id]})}}return{affordances:c}}}}function He(e,t){let n=e.shape;return n?Object.entries(n).filter(([u,f])=>u!==t&&f.safeParse(void 0).success).map(([u])=>u):[]}function Le(e,t,n){try{return e.preview({name:t,args:n}),!0}catch{return!1}}function q(e,t){let n=e.shape;return n?Object.entries(n).filter(([u,f])=>u!==t&&!f.safeParse(void 0).success).map(([u])=>u):[]}var We=70,Be=80,Ke=new Set(["id","kind"]);function Oe(){return{name:"structure",derive({store:e,nodes:t}){let n=i=>_(e.schema.tryDefinition(i.kind),i);if(t.length<2)return{};let u=[],f=[],c=t.map(i=>i.id);for(let i of e.schema.edgeKinds){let l=Ge(t.map(d=>new Set([...e.graph.out(d.id,i).map(g=>g.id),...e.graph.in(d.id,i).map(g=>g.id)])));for(let d of l){let g=e.graph.getNode(d);g&&u.push({id:`shared:${i}:${d}`,text:`all ${t.length} share "${n(g)}" (${J(i).toLowerCase()})`,nodeIds:[...c,d]})}let p=new Map;for(let d of t)for(let g of[...e.graph.out(d.id,i),...e.graph.in(d.id,i)])p.set(g.id,(p.get(g.id)??0)+1);for(let[d,g]of p){if(g!==t.length-1||t.length<3)continue;let s=e.graph.getNode(d);if(!s)continue;let a=t.find(h=>![...e.graph.out(h.id,i),...e.graph.in(h.id,i)].some(y=>y.id===d));if(a){u.push({id:`near-shared:${i}:${d}`,text:`all but "${n(a)}" share "${n(s)}" (${J(i).toLowerCase()})`,nodeIds:[...c,d]});for(let h of e.allMutations()){let y=h.subject;if(!y||y.kinds!=="*"&&!y.kinds.includes(a.kind))continue;let o=Fe(h.input,s.kind);o&&f.push({id:`structure:join:${h.name}:${a.id}:${d}`,label:`${M(h)}: bring "${n(a)}" in line with the others`,provider:"structure",mutation:h.name,args:{[y.arg]:a.id,[o]:d},open:[],score:We,why:`every other selected node is connected to "${n(s)}"`,nodeIds:[a.id,d]})}}}}let S=new Set;for(let i of t)for(let l of Object.keys(i))Ke.has(l)||S.add(l);let v=i=>e.schema.definitions.find(l=>l.kind===i);for(let i of[...S].sort()){let l=v(t[0].kind),p=ae(l,i).toLowerCase(),d=l?.display?.format?.[i],g=A=>{if(!d)return A;try{return String(d(JSON.parse(A)))}catch{return A}},s=t.map(A=>A[i]),a=new Map;if(s.forEach((A,k)=>{let R=JSON.stringify(A??null),x=a.get(R);x?x.push(t[k]):a.set(R,[t[k]])}),a.size===1){let A=[...a.keys()][0];if(A==="null")continue;u.push({id:`agree:${i}`,text:`all ${t.length} share the ${p} ${g(A)}`,nodeIds:c});continue}if(t.length<3||a.size!==2)continue;let h=[...a.entries()].sort((A,k)=>k[1].length-A[1].length),[y,o]=h[0],[,r]=h[1];if(r.length!==1||y==="null")continue;let w=r[0],b=JSON.parse(y);u.push({id:`odd-one-out:${i}`,text:`${o.length} share the ${p} ${g(y)}; "${n(w)}" does not`,nodeIds:c});for(let A of e.allMutations()){let k=A.subject;if(!k||k.kinds!=="*"&&!k.kinds.includes(w.kind))continue;let R=Re(A.input);if(!R||!(i in R))continue;let x={[k.arg]:w.id,[i]:b},O=!0;for(let[D,U]of Object.entries(R)){if(D in x||U.safeParse(void 0).success)continue;let C=w[D];if(C===void 0){O=!1;break}x[D]=C}O&&f.push({id:`structure:align:${A.name}:${i}:${w.id}`,label:`Align the ${p} of "${n(w)}" with the other ${o.length}`,provider:"structure",mutation:A.name,args:x,open:[],score:Be,why:`${o.length} of ${t.length} share the ${p} ${g(y)}`,nodeIds:c})}}return{affordances:f,observations:u}}}}function Ge(e){if(e.length===0)return[];let[t,...n]=e;return[...t].filter(u=>n.every(f=>f.has(u))).sort()}function Re(e){return e.shape??null}function Fe(e,t){let n=Re(e);if(!n)return null;for(let[u]of Object.entries(n)){let f=ce(n[u]);if(f&&(f.includes("*")||f.includes(t)))return u}return null}function qe(){return[Ae(),Oe(),$e(),be()]}function je(e,t,n={}){let u=xe(),f=n.providers??qe(),c=t.map(m=>e.graph.getNode(m)).filter(m=>m!==void 0),S={store:e,selection:t,nodes:c,kindSelection:n.kindSelection??[],edgeSelection:n.edgeSelection??[],violations:e.violations(n.context),context:n.context??{}},v=[],i=[];for(let m of f){let $=m.derive(S);v.push(...$.affordances??[]),i.push(...$.observations??[])}let l=new Set(e.allMutations().filter(m=>m.pinned).map(m=>m.name)),p=new Set(n.pins?.pinned??[]),d=new Set(n.pins?.unpinned??[]),g=m=>p.has(m.mutation)?"user":l.has(m.mutation)&&!d.has(m.mutation)?"declared":void 0,s=m=>{let $=g(m);return $?{...m,pinned:$}:m},a=new Map;for(let[m,$]of ve(e.log.all()))a.set(m,Se($));let h=m=>m.pinned==="user"?0:m.pinned==="declared"?1:2,y=m=>m.score+(a.get(m.mutation)??0),o=new Map(e.allMutations().map(m=>[m.name,m])),r=new Map,w=m=>{let $=o.get(m.mutation);if(!$)return[];let N=r.get(m.mutation);N||(N=P($.input).map(V=>V.name),r.set(m.mutation,N));let H=[];for(let V of m.batch??[m.args])for(let ie of N){let oe=V[ie]??m.args[ie];typeof oe=="string"&&H.push(oe)}return H},b=n.focus,A=4,k=m=>m.open.length>0?1:0,R=m=>{if(b===void 0)return A;let $=w(m);return $.length>0?$.includes(b)?x(m,0):A:m.nodeIds.includes(b)||m.subjectId===b?x(m,1):A},x=(m,$)=>m.provider==="invariant"?$:2+k(m),O=Ue(v).map(s),D=new Map(O.map((m,$)=>[m,$])),U=O.sort((m,$)=>{let N=Number(m.destructive??!1)-Number($.destructive??!1);if(N!==0)return N;let H=R(m)-R($);return H!==0?H:R(m)<2?D.get(m)-D.get($):+($.provider==="invariant")-+(m.provider==="invariant")||h(m)-h($)||y($)-y(m)||m.id.localeCompare($.id)}),C=n.principal??{kind:"human"},L=[],ne=[];for(let m of U){let $=e.permits({name:m.mutation,args:{...m.args,...m.batch?.[0]??{}}},C);if($.ok)L.push(m);else{let N=ze(e,m,C);if(N==="done")continue;N?L.push(N):ne.push({...m,refusal:$.refusal})}}let te=L.map((m,$)=>({...m,rank:$})),_e=ne.map((m,$)=>({...m,rank:L.length+$}));return{affordances:n.limit===void 0?te:te.slice(0,n.limit),withheld:_e,observations:Ve(i),ms:xe()-u}}function Ue(e){let t=new Map;for(let n of e){let u=[n.mutation,JSON.stringify(n.args),JSON.stringify(n.batch??null)].join("|"),f=t.get(u);(!f||n.score>f.score)&&t.set(u,n)}return[...t.values()]}function Ve(e){let t=new Map;for(let n of e)t.set(n.text,n);return[...t.values()]}function xe(){return typeof performance<"u"?performance.now():Date.now()}function Je(e,t,n={},u={}){let f=(t.batch??[t.args]).map(S=>({name:t.mutation,args:{...t.args,...S,...n}})),c=e.allMutations().find(S=>S.name===t.mutation);return e.applyAll(f,{...c?.describe?{}:{intent:t.label},...u.author?{author:u.author}:{}})}function Rn(e,t,n={}){return e.preview({name:t.mutation,args:{...t.args,...n}})}function ze(e,t,n){let u=e.allMutations().find(i=>i.name===t.mutation)?.subject;if(!u||t.args[u.arg]!==void 0)return;let f=t.open.find(i=>i.name===u.arg);if(!f?.candidates)return;let c=i=>e.permits({name:t.mutation,args:{...t.args,...t.batch?.[0]??{},[u.arg]:i}},n).ok,S=f.candidates.filter(c),v=n.id===void 0?void 0:e.graph.getNode(n.id);return S.length===0?v!==void 0&&(u.kinds==="*"||u.kinds.includes(v.kind))&&c(v.id)?"done":void 0:S.length===1&&S[0]===n.id?{...t,args:{...t.args,[u.arg]:n.id},open:t.open.filter(i=>i!==f)}:{...t,open:t.open.map(i=>i===f?{...i,candidates:S}:i)}}var Pe,Ze=()=>Pe??=import("./chunk.3TNQPFIK.js").catch(e=>{throw Pe=void 0,e}),Xe=()=>import("./chunk.KWSXL3A2.js").catch(()=>{}),Ye=async()=>{(await Xe())?.judgeWithLines()},Ne,Qe=()=>Ne??=import("./chunk.OXODTBOP.js").catch(e=>{throw Ne=void 0,e}),T=e=>({title:e,readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}),X=[{name:"search_graph",title:"Find by name",description:"Find things by name: records whose name or readable fields carry the words, and the kinds, places and rules the words name \u2014 each with why it matched. Reach for this before get_graph when you know what something is called. Words match the start of words, case and accents aside; key:value tokens narrow as a list's filter does (done:false, is:any for past records, kind:<kind>). Pass subject (a node id) to get the acts you may run on it as hits too.",inputSchema:{type:"object",properties:{query:{type:"string",description:"Words, with optional key:value conditions."},limit:{type:"number",description:"Most hits to return; 20 when unsaid."},subject:{type:"string",description:"A node id whose acts to include."}},required:["query"],additionalProperties:!1},mutating:!1,annotations:T("Find by name")},{name:"get_graph",title:"Read the whole graph",description:"Read the whole graph: every node with its fields, and every edge. Start here when you need the shape of the domain rather than one thing in it.",inputSchema:{type:"object",properties:{},additionalProperties:!1},mutating:!1,annotations:T("Read the whole graph")},{name:"get_node",title:"Read one node",description:"Read one node, its edges, and the violations that implicate it, with its computed values: read-only fields worked out from what you can see, which no act sets. Use this to check a thing before you change it.",inputSchema:{type:"object",properties:{id:{type:"string",description:"A node's id, or its name."}},required:["id"],additionalProperties:!1},mutating:!1,annotations:T("Read one node")},{name:"get_violations",title:"List the problems",description:"List every invariant violation the graph currently has, with the repairs that would resolve each one. Read this before proposing work: a rule that is already broken is more urgent than anything you could add.",inputSchema:{type:"object",properties:{context:{type:"object",description:"Evaluation context, e.g. { weekStart }."}},additionalProperties:!1},mutating:!1,annotations:T("List the problems")},{name:"get_affordances",title:"Ask what can be done",description:"Ask what can legally be done with a selection, ranked. Prefer these over composing a mutation by hand: they are derived from the schema, the invariants and the shape of the graph, so they cannot name an action that does not exist.",inputSchema:{type:"object",properties:{selection:{type:"array",items:{type:"string"},description:"Node ids."},context:{type:"object"}},required:["selection"],additionalProperties:!1},mutating:!1,annotations:T("Ask what can be done")},{name:"describe_place",title:"Say what a place shows",description:`Say what one place of the app shows you, as a person in your seat would see it: its headings, its figures as drawn, its lists with each record's title and what its card or row says, the headings a list is grouped under, what an empty list says, and any block that could not be worked out. Pass a place's slug ("home", a lens's address like "the-offers", a kind's like "offers") or a record's id, and width 390 for a phone. Use it after a change to check what somebody now sees, instead of guessing.`,inputSchema:{type:"object",properties:{place:{type:"string",description:`"home", a place's slug, or a record's id.`},width:{type:"number",description:"The screen's width in CSS pixels; 390 is a phone, 1440 when unsaid."}},required:["place"],additionalProperties:!1},mutating:!1,annotations:T("Say what a place shows")},{name:"preview_mutation",title:"Try an act without applying it",description:"Try a mutation without applying it: get back the diff it would produce and any invariant it would break. Do this when you are unsure, rather than applying and undoing.",inputSchema:{type:"object",properties:{mutation:{type:"string"},args:{type:"object"}},required:["mutation","args"],additionalProperties:!1},mutating:!1,annotations:T("Try an act without applying it")},{name:"undo_batch",title:"Undo a batch",description:"Undo one batch of operations. Fails, naming the blocking operation, when a later operation read what it wrote.",inputSchema:{type:"object",properties:{batch:{type:"string"},include:{type:"array",items:{type:"string"}}},required:["batch"],additionalProperties:!1},mutating:!0,annotations:{title:"Undo a batch",readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1}}],Y={type:"object",description:"A lens, as draft_view returns one.",properties:{title:{type:"string"},lens:{type:"string"},on:{type:"string"},bindings:{type:"object"},options:{type:"object"}},required:["title","lens","on"]},Q={name:"draft_view",title:"Draw a view",description:'Draw a view of the data from words ("a board of tasks by status", "who covers what") as a lens the app could keep; or check a lens you wrote (lens); or change the one on screen (current, with ask: "only this month"). Returns the lens and its add-lens edit, or one sentence saying why not. Writes nothing.',inputSchema:{type:"object",properties:{ask:{type:"string",description:"What to see, in words."},lens:Y,current:Y},additionalProperties:!1},mutating:!1,annotations:T("Draw a view")},De={name:"keep_lens",title:"Keep a view as a lens",description:"Keep a lens draft_view drew as one of the app's places: checked again, then written as the add-lens edit. Returns the remove-lens edit that takes it back.",inputSchema:{...Y,additionalProperties:!1},mutating:!0,annotations:{title:"Keep a view as a lens",readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1}};function en(e,t){return e===void 0?[]:e==="keep"&&!t?[Q,De]:[Q]}var nn="An argument that names a record takes its id or its name.",Te=[...X.map(e=>e.name),Q.name,De.name],Ie=64;function I(e){let{line:t,...n}=e;return n}function Me(e){return{...e,...e.introduces?{introduces:e.introduces.map(I)}:{},...e.resolves?{resolves:e.resolves.map(I)}:{},...e.violationsAfter?{violationsAfter:e.violationsAfter.map(I)}:{}}}function tn(e){let t=e.normalize("NFKD").replace(/\p{M}/gu,"").replace(/[^A-Za-z0-9_-]/g,"_");return t.length===0&&(t="act"),/^[A-Za-z_]/.test(t)||(t=`act_${t}`),t.slice(0,Ie)}function on(e){let t=new Set(Te),n=new Map;for(let u of e){let f=tn(u),c=f;for(let S=2;t.has(c);S+=1)c=`${f.slice(0,Ie-`_${S}`.length)}_${S}`;t.add(c),n.set(u,c)}return n}function rn(e,t){let n=ue(e),u=M(e),f=n.nodeRefs.length>0?`${n.description}${/[.!?]$/.test(n.description)?"":"."} ${nn}`:n.description;return{name:t,title:u,description:f,inputSchema:n.inputSchema,mutating:!0,annotations:{title:u,readOnlyHint:!1,destructiveHint:e.destructive===!0||(e.severs?.length??0)>0,idempotentHint:e.idempotent===!0,openWorldHint:!1},act:e.name}}function ee(e){if(e===null||typeof e!="object")return JSON.stringify(e)??"null";if(Array.isArray(e))return`[${e.map(ee).join(",")}]`;let t=e;return`{${Object.keys(t).filter(n=>t[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${ee(t[n])}`).join(",")}}`}function sn(e){return`sha256:${he(ee(e))}`}function an(e,t,n,u){let f=on(e.map(v=>v.name)),c=en(u,n);return{definitions:n?[...X.filter(v=>!v.mutating),...c]:[...X,...c,...e.filter(v=>t.has(v.name)).map(v=>rn(v,f.get(v.name)))],names:f}}function Cn(e,t={}){let n=t.author??{kind:"agent"},u=e.allMutations(),f=new Set(e.permittedMutations(n).map(s=>s.name)),{definitions:c,names:S}=an(u,f,t.readOnly===!0,t.drafts?t.drafts.keep?"keep":"draw":void 0),v=sn(c),i=s=>{if(!Te.includes(s)){for(let[a,h]of S)if(h===s)return a;return S.has(s)?s:void 0}},l=(s,a)=>{let h=u.find(r=>r.name===s);if(!h)return{args:a,resolved:[]};let y={...a},o=[];for(let r of P(h.input)){let w=y[r.name];if(typeof w!="string"||w.trim()==="")continue;let b=e.resolveRef(r,w,n);if(!b.ok){let A=b.reason==="none"?` Nothing was changed. Use search_graph to look it up, then pass its id as ${r.name}.`:" Nothing was changed.";return{ok:!1,error:`${b.message}${A}`,argument:r.name,candidates:b.candidates}}b.by!=="id"&&(y[r.name]=b.id,o.push({argument:r.name,given:w,id:b.id,label:b.label}))}return{args:y,resolved:o}},p=async(s,a)=>{try{await Ye();let h=c.find(o=>o.name===s)??c.find(o=>o.act===s);if(!h){let o=i(s);if(o){let r=e.permits({name:o,args:a},n);if(!r.ok)return{ok:!1,error:r.refusal.message,reason:"forbidden"}}return{ok:!1,error:`Unknown tool "${s}". Available: ${c.map(r=>r.name).join(", ")}`}}if(h.mutating&&t.readOnly)return{ok:!1,error:`"${s}" changes the graph, and this seat is read-only.`,reason:"forbidden"};if(h.act!==void 0){let o=l(h.act,a);if("ok"in o)return o;let r=G(e,n,e.apply({name:h.act,args:o.args},{...t.author?{author:t.author}:{},...dn(t.via)}));return{ok:!0,data:{batch:r.batch,intent:r.intent,introduces:r.introduces.map(I),resolves:r.resolves.map(I),...o.resolved.length>0?{resolved:o.resolved}:{}},diff:r.diff}}let y=e.seenBy(n);switch(h.name){case"search_graph":{let o=typeof t.places=="function"?t.places():t.places,r=typeof a.subject=="string"?a.subject:void 0,w=pe(y,String(a.query??""),{principal:n,limit:typeof a.limit=="number"?a.limit:20,...o?{places:o}:{},...r?{subject:r,from:[r]}:{}});return{ok:!0,data:we(w,F(y,n)),reads:w.hits.flatMap(b=>b.about==="node"?[b.id]:[])}}case"get_graph":{let o=y.graph.snapshot();return{ok:!0,data:ke(o,F(y,n)),reads:o.nodes.map(r=>r.id)}}case"get_node":{let o=String(a.id??""),r=o,w;if(!y.graph.getNode(o)){let O=o.trim()===""?void 0:e.resolveRef({name:"id",kinds:["*"]},o,n);if(O?.ok)r=O.id,w={argument:"id",given:o,id:r,label:O.label};else return O?.reason==="ambiguous"?{ok:!1,error:O.message,argument:"id",candidates:O.candidates}:{ok:!1,error:`No node "${o}".`}}let b=y.graph.getNode(r),A=y.graph.outEdges(r),k=y.graph.inEdges(r),R=F(y,n),x=ge(y.schema,y.graph,b);return{ok:!0,data:{node:z(b,R),...Object.keys(x.values).length>0?{computed:ye(r,x.values,R)}:{},...Object.keys(x.refused).length>0?{uncomputed:x.refused}:{},out:A,in:k,violations:y.violations().filter(O=>O.nodeIds.includes(r)).map(I),...w?{resolved:[w]}:{}},reads:[r,...A.map(O=>O.to),...k.map(O=>O.from)]}}case"describe_place":{let o=t.app??{name:"",schema:e.schema},r=typeof a.width=="number"&&Number.isFinite(a.width)&&a.width>0?a.width:1440,{describePlace:w}=await Ze(),b=w(e,n,String(a.place??""),{app:o,width:r});if(!b.ok)return{ok:!1,error:`${b.error} The places are: ${b.places.join(", ")}.`};let A=new Set,k=R=>{for(let x of R)for(let O of x.groups??[])for(let D of O.items)A.add(D.id),k(D.parts)};return k(b.description.parts),{ok:!0,data:b.description,reads:[...A]}}case"draft_view":case"keep_lens":{let o=t.app??{name:"",schema:e.schema};return(await Qe()).runDraftTool(h.name,a,{app:o,principal:n,...t.drafts?{drafts:t.drafts}:{}})}case"get_violations":{let o=y.violations(a.context);return{ok:!0,data:o.map(I),reads:[...new Set(o.flatMap(r=>r.nodeIds))]}}case"get_affordances":{let o=a.selection??[];return{ok:!0,data:je(y,o,{...typeof t.derive=="function"?t.derive():t.derive,...t.author?{principal:t.author}:{},...a.context?{context:a.context}:{}}),reads:o.filter(w=>y.graph.has(w))}}case"preview_mutation":{let o=String(a.mutation),r=i(o)??o,w=l(r,a.args??{});if("ok"in w)return w;let b=e.missingFor({name:r,args:w.args},n);if(b)return{ok:!1,error:b.message,reason:"missing"};let A=G(e,n,e.preview({name:r,args:w.args},void 0,{author:n})),k=Me(A);return{ok:!0,data:w.resolved.length>0?{...k,resolved:w.resolved}:k}}case"undo_batch":{let o=String(a.batch),r=a.include??[],w=y.canUndo([o,...r]);if(!w.ok)return{ok:!1,error:w.message};let b=G(e,n,e.undo([o,...r],{...t.author?{author:t.author}:{}}));return{ok:!0,data:Me(b),diff:b.diff}}default:return{ok:!1,error:`Unknown tool "${s}".`}}}catch(h){let{reason:y,wouldNeed:o}=fe(h);return{ok:!1,error:h instanceof Error?h.message:String(h),reason:y,...o?{wouldNeed:o}:{}}}},d=new Set,g=s=>{for(let a of d)a(s)};return{definitions:c,hash:v,...t.author?{author:t.author}:{},onDiff(s){return e.subscribe(s)},onCall(s){return d.add(s),()=>d.delete(s)},async call(s,a){let h=(c.find(r=>r.name===s)??c.find(r=>r.act===s))?.mutating??!1,y={name:s,args:a,mutating:h,at:new Date().toISOString()};return g({...y,phase:"running"}),(r=>(g(r.ok?{...y,phase:"ok",...!h&&r.reads?{reads:r.reads}:{}}:{...y,phase:"failed",error:r.error}),r))(await p(s,a))}}}function dn(e){let t=typeof e=="function"?e():e;return t?{via:t}:{}}export{je as a,Je as b,Rn as c,Cn as d};
@@ -0,0 +1 @@
1
+ import{a as x,c as P}from"./chunk.Y4R77MKX.js";import{S as w}from"./chunk.2VX6H2LL.js";var v="graview:pins",m={pinned:[],unpinned:[]},g=e=>Array.isArray(e)?e.filter(n=>typeof n=="string"):[];function O(){try{let e=globalThis.localStorage?.getItem(v);if(!e)return m;let n=JSON.parse(e);if(Array.isArray(n))return{pinned:g(n),unpinned:[]};if(typeof n=="object"&&n!==null){let r=n;return{pinned:g(r.pinned),unpinned:g(r.unpinned)}}return m}catch{return m}}function S(e){try{globalThis.localStorage?.setItem(v,JSON.stringify(e))}catch{}}function C(e,n,r=!1){let o=s=>s.filter(l=>l!==n),i=r?e.unpinned.includes(n)?{pinned:o(e.pinned),unpinned:o(e.unpinned)}:{pinned:o(e.pinned),unpinned:[...e.unpinned,n]}:e.pinned.includes(n)?{pinned:o(e.pinned),unpinned:o(e.unpinned)}:{pinned:[...e.pinned,n],unpinned:o(e.unpinned)};return S(i),i}var E=e=>`ai:${e.name??(e.complete||e.turn?"model":"on-device")}`;var A="Llama-3.2-3B-Instruct-q4f16_1-MLC",L=new Map;function R(e={}){let n=e.load?null:e.model??A,r=n?L.get(n)??L.set(n,{engine:null,failed:null}).get(n):{engine:null,failed:null},o=r.engine,i=!1,s=t=>e.onStatus?.(t),l=async()=>{if(e.load)return e.load();let t=globalThis.LanguageModel;if(t){let u=await t.create();return{chat:{completions:{create:async({messages:h})=>({choices:[{message:{content:await u.prompt(h[h.length-1]?.content??"")}}]})}}}}if(!globalThis.navigator?.gpu)throw new Error("this browser has no WebGPU, which the local model needs");return(await import("https://esm.run/@mlc-ai/web-llm")).CreateMLCEngine(e.model??A,{initProgressCallback:u=>s({state:"warming",progress:u.progress,detail:u.text})})},a=Promise.resolve();return{complete:async t=>{if(o=r.engine??o,!o)throw new Error("The local model is not warm yet");let f=(await o.chat.completions.create({messages:[{role:"user",content:t}]})).choices?.[0]?.message?.content;if(typeof f!="string")throw new Error("The local model answered with no content");return f},ready:()=>(r.engine??o)!==null,warm:()=>(o=r.engine??o,o?Promise.resolve():i?a:r.failed!==null?(s({state:"failed",detail:r.failed}),Promise.resolve()):(i=!0,s({state:"warming"}),a=l().then(t=>{o=t,r.engine=t,s({state:"ready"})}).catch(t=>{r.failed=t instanceof Error?t.message:String(t),s({state:"failed",detail:r.failed})}).finally(()=>{i=!1}),a)),failed:()=>r.failed}}function T(e,n={}){return b(e,n)?.complete}function b(e,n){let r=e.turn,o=e.complete??(r?l=>r({system:"",messages:[{role:"user",content:l}],tools:[],call:async()=>({error:"No tools here."})}):void 0);if(o)return{complete:o,ready:()=>!0,warm:()=>Promise.resolve(),failed:()=>null};if(!e.onDevice)return;let i=typeof e.onDevice=="object"?e.onDevice.model:void 0,s=R({...i?{model:i}:{},...n.onStatus?{onStatus:n.onStatus}:{}});return{complete:async l=>(s.ready()||s.warm(),s.complete(l)),ready:s.ready,warm:s.warm,failed:s.failed}}function D(e,n={}){let r=n.floor??x(),o=(a,d,p)=>r(p?.principal?a.seenBy(p.principal):a,d,p),i=b(e,n);if(!i)return async(a,d,p)=>{let t=await o(a,d,p);return t.unsure?{...t,say:e.withoutModel??w}:t};let s=P({complete:i.complete,...e.turn?{turn:e.turn}:{}}),l=E(e);return async(a,d,p)=>{let t=await o(a,d,p);if(t.grounded)return t;if(!i.ready()){if(await Promise.race([i.warm(),new Promise(c=>setTimeout(c,100))]),i.failed()!==null)return y(t,"(AI isn't available in this browser, so this is from the app alone.)");if(!i.ready())return y(t,"(AI is still getting ready on this device, so this is from the app alone.)")}try{let c=await s(a,d,{...p,...t.proposals.length>0?{reading:t.proposals}:{}});return c.proposals.length===0&&t.proposals.length>0?t:{...c,via:l}}catch{return y(t,"(AI didn't answer just now, so this is from the app alone.)")}}}function y(e,n){return{...e,say:`${e.say} ${n}`}}export{O as a,C as b,T as c,D as d};
@@ -0,0 +1 @@
1
+ import{c as a,l as o}from"./chunk.VTBAKTFP.js";import"./chunk.7U7Q3HIS.js";import"./chunk.6O67NOZR.js";import"./chunk.WWRWXFYR.js";import"./chunk.ISAMJ7AK.js";import"./chunk.54NSG7BX.js";import"./chunk.6KJSFIO7.js";import"./chunk.UM5IPM22.js";import"./chunk.6XBLDV4A.js";import"./chunk.WOTNMTIY.js";import"./chunk.HAQ4KHRY.js";import"./chunk.PRXKRG6O.js";import"./chunk.AHDOKM4O.js";import"./chunk.TDW6QEG4.js";import"./chunk.LW7KV5SL.js";import{la as n}from"./chunk.2VX6H2LL.js";import"./chunk.ZQ4HFIIS.js";import"./chunk.MRK6QJV5.js";import"./chunk.AJZBJBMO.js";var w=new WeakMap;function p(e,i){let t=w.get(e);t||w.set(e,t=new Map);let r=t.get(i);return r||t.set(i,r=o(a(e,n(e)),e,i)),r}export{p as frameworkViews};
@@ -1 +1 @@
1
- import{a as p}from"./chunk.AHDOKM4O.js";import{ab as u}from"./chunk.Y235YZSZ.js";import{b as c}from"./chunk.MRK6QJV5.js";import{b as h}from"./chunk.AJZBJBMO.js";var s={person:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><circle cx="11.6" cy="5.4" r="2.5"/><path d="M7.9 12.4c0-2.1 1.7-3.8 3.7-3.8s3.7 1.7 3.7 3.8v3.2H7.9z"/><path d="M8 12.6 6.4 17.2"/><path d="M15.2 12.6 16.8 17.2"/><path d="M9.8 15.6v5"/><path d="M13.4 15.6v5"/></svg>',plot:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M2.6 9.4 12 4.6l9.4 4.8-9.4 4.8z"/><path d="M2.6 9.4v4.4l9.4 4.8 9.4-4.8V9.4"/><path d="M12 14.2v4.4"/><path d="M7 11.9v3"/><path d="M17 11.9v3"/></svg>',box:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M3.4 7.9 12 3.6l8.6 4.3-8.6 4.3z"/><path d="M3.4 7.9v8.2L12 20.4l8.6-4.3V7.9"/><path d="M12 12.2v8.2"/></svg>',task:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M4.4 6.6 12 2.9l7.6 3.7v9.5L12 19.8 4.4 16.1z"/><path d="M12 12.4v7.4"/><path d="M4.4 6.6 12 10.3l7.6-3.7"/><path d="M8 9.6l2.4 2.4L16 8.4"/></svg>',shift:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M3.2 8.2 12 4l8.8 4.2-8.8 4.2z"/><path d="M3.2 8.2v7.2L12 19.6l8.8-4.2V8.2"/><path d="M12 12.4v7.2"/><path d="M6.6 10.8v3.4"/><path d="M9.3 12v3.4"/></svg>',list:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M2.8 10.4 12 6l9.2 4.4-9.2 4.4z"/><path d="M2.8 10.4v3.2L12 18l9.2-4.4v-3.2"/><path d="M6.6 8.6 15.8 13"/><path d="M9.4 7.2 18.6 11.6"/></svg>',vehicle:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M2.8 14.2 5 9.4l8.6-1.6 5.4 3-1 3.6z"/><path d="M2.8 14.2v2.2h2.4"/><path d="M18 16.4h1.9l.1-2.2"/><circle cx="7.6" cy="16.6" r="1.9"/><circle cx="16.1" cy="16.6" r="1.9"/><path d="M8.6 8.2 9.8 12l7.2-1"/></svg>',rule:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M5.4 19.4V6.6l12 12.8z"/><path d="M5.4 6.6 7.6 5.5l12 12.8-2.2 1.1"/><path d="M5.4 19.4 7.6 18.3h12"/><path d="M5.4 10.1h1.7"/><path d="M5.4 13.3h1.7"/><path d="M5.4 16.5h1.7"/></svg>',note:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M6.2 6.2 14.8 10.5v9L6.2 15.2z"/><path d="M12.4 9.3 14.8 10.5l-.6 2.3"/><path d="M8.2 10.6 12.8 12.9"/><path d="M8.2 13.2 11.4 14.8"/></svg>'},v=Object.keys(s);function i(e){if(e)return s[e]??(e.trimStart().startsWith("<svg")?e:void 0)}var a=h(c(),1);function B({kind:e,schema:o,brand:n,size:r=16,title:t}){let f=o?.tryDefinition?.(e)?.figure,d=i(n?.figures?.[e]??f),l=Math.round(u(e,n?.accents)),g=p(d);return d?(0,a.jsx)("span",{"aria-hidden":t===void 0?"true":void 0,...t===void 0?{}:{role:"img","aria-label":t},"data-graview-figure":e,"data-graview-figure-kind":"figure",dangerouslySetInnerHTML:g,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:r,height:r,flex:"0 0 auto",color:`hsl(${l} 55% 52%)`,"--graview-figure-size":`${r}px`}}):(0,a.jsx)("span",{"aria-hidden":t===void 0?"true":void 0,...t===void 0?{}:{role:"img","aria-label":t},"data-graview-figure":e,"data-graview-figure-kind":"dot",style:{display:"inline-block",width:Math.round(r*.8),height:Math.round(r*.5),flex:"0 0 auto",background:`hsl(${l} 55% 52%)`,clipPath:"polygon(50% 0, 100% 50%, 50% 100%, 0 50%)"}})}function A(e,o,n){return i(n?.figures?.[e]??o?.tryDefinition?.(e)?.figure)!==void 0}export{B as a,A as b};
1
+ import{a as p}from"./chunk.AHDOKM4O.js";import{db as u}from"./chunk.ZQ4HFIIS.js";import{b as c}from"./chunk.MRK6QJV5.js";import{b as h}from"./chunk.AJZBJBMO.js";var s={person:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><circle cx="11.6" cy="5.4" r="2.5"/><path d="M7.9 12.4c0-2.1 1.7-3.8 3.7-3.8s3.7 1.7 3.7 3.8v3.2H7.9z"/><path d="M8 12.6 6.4 17.2"/><path d="M15.2 12.6 16.8 17.2"/><path d="M9.8 15.6v5"/><path d="M13.4 15.6v5"/></svg>',plot:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M2.6 9.4 12 4.6l9.4 4.8-9.4 4.8z"/><path d="M2.6 9.4v4.4l9.4 4.8 9.4-4.8V9.4"/><path d="M12 14.2v4.4"/><path d="M7 11.9v3"/><path d="M17 11.9v3"/></svg>',box:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M3.4 7.9 12 3.6l8.6 4.3-8.6 4.3z"/><path d="M3.4 7.9v8.2L12 20.4l8.6-4.3V7.9"/><path d="M12 12.2v8.2"/></svg>',task:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M4.4 6.6 12 2.9l7.6 3.7v9.5L12 19.8 4.4 16.1z"/><path d="M12 12.4v7.4"/><path d="M4.4 6.6 12 10.3l7.6-3.7"/><path d="M8 9.6l2.4 2.4L16 8.4"/></svg>',shift:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M3.2 8.2 12 4l8.8 4.2-8.8 4.2z"/><path d="M3.2 8.2v7.2L12 19.6l8.8-4.2V8.2"/><path d="M12 12.4v7.2"/><path d="M6.6 10.8v3.4"/><path d="M9.3 12v3.4"/></svg>',list:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M2.8 10.4 12 6l9.2 4.4-9.2 4.4z"/><path d="M2.8 10.4v3.2L12 18l9.2-4.4v-3.2"/><path d="M6.6 8.6 15.8 13"/><path d="M9.4 7.2 18.6 11.6"/></svg>',vehicle:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M2.8 14.2 5 9.4l8.6-1.6 5.4 3-1 3.6z"/><path d="M2.8 14.2v2.2h2.4"/><path d="M18 16.4h1.9l.1-2.2"/><circle cx="7.6" cy="16.6" r="1.9"/><circle cx="16.1" cy="16.6" r="1.9"/><path d="M8.6 8.2 9.8 12l7.2-1"/></svg>',rule:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M5.4 19.4V6.6l12 12.8z"/><path d="M5.4 6.6 7.6 5.5l12 12.8-2.2 1.1"/><path d="M5.4 19.4 7.6 18.3h12"/><path d="M5.4 10.1h1.7"/><path d="M5.4 13.3h1.7"/><path d="M5.4 16.5h1.7"/></svg>',note:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M6.2 6.2 14.8 10.5v9L6.2 15.2z"/><path d="M12.4 9.3 14.8 10.5l-.6 2.3"/><path d="M8.2 10.6 12.8 12.9"/><path d="M8.2 13.2 11.4 14.8"/></svg>'},v=Object.keys(s);function i(e){if(e)return s[e]??(e.trimStart().startsWith("<svg")?e:void 0)}var a=h(c(),1);function B({kind:e,schema:o,brand:n,size:r=16,title:t}){let f=o?.tryDefinition?.(e)?.figure,d=i(n?.figures?.[e]??f),l=Math.round(u(e,n?.accents)),g=p(d);return d?(0,a.jsx)("span",{"aria-hidden":t===void 0?"true":void 0,...t===void 0?{}:{role:"img","aria-label":t},"data-graview-figure":e,"data-graview-figure-kind":"figure",dangerouslySetInnerHTML:g,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:r,height:r,flex:"0 0 auto",color:`hsl(${l} 55% 52%)`,"--graview-figure-size":`${r}px`}}):(0,a.jsx)("span",{"aria-hidden":t===void 0?"true":void 0,...t===void 0?{}:{role:"img","aria-label":t},"data-graview-figure":e,"data-graview-figure-kind":"dot",style:{display:"inline-block",width:Math.round(r*.8),height:Math.round(r*.5),flex:"0 0 auto",background:`hsl(${l} 55% 52%)`,clipPath:"polygon(50% 0, 100% 50%, 50% 100%, 0 50%)"}})}function A(e,o,n){return i(n?.figures?.[e]??o?.tryDefinition?.(e)?.figure)!==void 0}export{B as a,A as b};
@@ -1,4 +1,4 @@
1
- import{c as E,d as I}from"./chunk.YAONM74M.js";import"./chunk.3MLQ3Q5X.js";import"./chunk.LGUV2J6Q.js";import"./chunk.4JSMCNF7.js";import{I as A,M as k}from"./chunk.Y235YZSZ.js";import{a as F,b as S}from"./chunk.MRK6QJV5.js";import{b as f}from"./chunk.AJZBJBMO.js";var v=f(F(),1);var a=f(S(),1),C=40,O=60;function D(l,i,p){return l.allNodes().filter(o=>o.kind===i).map(o=>o[p])}function G(l){if(l.length<2)return[];let i=[...l].sort((n,d)=>n-d),p=i[i.length-1]-i[0];if(p<=0)return[];let o=Math.max(1,10**Math.floor(Math.log10(p/4))),e=p/4>=o*5?o*5:o,r=n=>Math.round(n/e)*e;return[...new Set([.2,.4,.6,.8].map(n=>r(i[Math.floor(n*(i.length-1))])))].filter(n=>n>0)}function T(l,i,p){let o=p.far??[],e=new Map,r=new Set(o);for(let t of i.allNodes())r.has(t.kind)&&e.set(t.id,A(l.tryDefinition(t.kind),t));let n=[...e.entries()].map(([t,g])=>({id:t,label:g}));return(n.length<=C?n:n.map(t=>({end:t,ties:i.out(t.id).length+i.in(t.id).length})).sort((t,g)=>g.ties-t.ties||t.end.label.localeCompare(g.end.label)).slice(0,C).map(t=>t.end)).sort((t,g)=>t.label.localeCompare(g.label))}function R(l,i,p){let o=[];for(let e of p.filters)if(e.about==="is")for(let r of e.options??[])o.push({value:`is:${r}`,label:r,group:e.label,condition:{key:"is",value:r}});else if(e.about==="edge"){o.push({value:`${e.key}:*`,label:"anything",group:e.label,condition:{key:e.key,value:"*"}}),o.push({value:`${e.key}:none`,label:"nothing",group:e.label,condition:{key:e.key,value:"none"}});for(let r of T(l,i,e))o.push({value:`${e.key}:${r.id}`,label:r.label,group:e.label,condition:{key:e.key,value:r.id}})}else if(e.type==="date")for(let r of["before","after","on"])o.push({value:`${e.key}:${r}`,label:`${r}\u2026`,group:e.label,ask:{key:e.key,op:r,label:e.label}});else if(e.type==="number"){let r=l.tryDefinition(p.kind),n=G(D(i,p.kind,e.key).filter(d=>typeof d=="number"));for(let d of["at-most","at-least"])for(let t of d==="at-most"?n:[...n].reverse())o.push({value:`${e.key}:${d}:${t}`,label:`${d==="at-most"?"at most":"at least"} ${k(r,e.key,t)}`,group:e.label,condition:{key:e.key,value:`${d}:${t}`}})}else if(e.type==="text"){let r=[...new Set(D(i,p.kind,e.key).filter(n=>typeof n=="string"&&n.length>0&&!n.includes(",")))].sort((n,d)=>n.localeCompare(d));if(r.length>=2&&r.length<=O)for(let n of r)o.push({value:`${e.key}:${n}`,label:n,group:e.label,condition:{key:e.key,value:n}})}else if(e.type==="boolean")o.push({value:`${e.key}:true`,label:"yes",group:e.label,condition:{key:e.key,value:"true"}}),o.push({value:`${e.key}:false`,label:"no",group:e.label,condition:{key:e.key,value:"false"}});else for(let r of e.options??[])o.push({value:`${e.key}:${r}`,label:k(l.tryDefinition(p.kind),e.key,r),group:e.label,condition:{key:e.key,value:r}});return o}var H=["day","week","month","year","decade"];function K(l){let{which:i,schema:p,graph:o,offers:e,arrangement:r,set:n,toggle:d,has:t,done:g}=l,y=l.testId,h=(0,v.useRef)(null);(0,v.useEffect)(()=>{let u=h.current?.closest("[data-graview-popover]");!u||document.activeElement!==u||(u.querySelector('[aria-pressed="true"]')??u.querySelector("button, input"))?.focus({preventScroll:!0})},[]);let L=r.sort?e.sorts.find(u=>u.key===r.sort.by):void 0,P=r.group?e.groups.find(u=>u.key===r.group.by):void 0,M=I(L),m=e.natural?e.sorts.find(u=>u.key===e.natural.by):void 0,N=i==="filter"||i==="all"&&l.parts?.filter?R(p,o,e):[],w=u=>(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{children:"Sort by"}),(0,a.jsx)(c,{testId:`${y}-sort-default`,value:"",on:!r.sort,onPress:()=>(n({sort:void 0}),u()),children:m?`As declared (${E(m.label)})`:"As they were added"}),e.sorts.map(s=>(0,a.jsx)(c,{value:s.key,on:r.sort?.by===s.key,onPress:()=>(n({sort:{by:s.key,direction:r.sort?.direction??"asc"}}),u()),children:s.label},s.key)),r.sort?(0,a.jsxs)("div",{role:"group","aria-label":"Order","data-testid":`${y}-direction`,children:[(0,a.jsx)("p",{"aria-hidden":"true",children:"Order"}),["asc","desc"].map(s=>(0,a.jsx)(c,{testId:`${y}-direction-${s}`,value:s,on:r.sort.direction===s,onPress:()=>(n({sort:{by:r.sort.by,direction:s}}),u()),children:M[s]},s))]}):null]}),x=u=>(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{children:"Group by"}),(0,a.jsx)(c,{testId:`${y}-group-none`,value:"",on:!r.group,onPress:()=>(n({group:void 0}),u()),children:"Not grouped"}),e.groups.map(s=>(0,a.jsx)(c,{value:s.key,on:r.group?.by===s.key,onPress:()=>(n({group:{by:s.key}}),u()),children:s.label},s.key)),r.group&&P?.buckets?(0,a.jsxs)("div",{role:"group","aria-label":"How wide a group is","data-testid":`${y}-bucket`,children:[(0,a.jsx)("p",{"aria-hidden":"true",children:"Each group"}),H.map(s=>(0,a.jsx)(c,{testId:`${y}-bucket-${s}`,value:s,on:(r.group.bucket??"day")===s,onPress:()=>(n({group:{by:r.group.by,bucket:s}}),u()),children:`A ${s}`},s))]}):null]}),$=u=>(0,a.jsx)(z,{entries:N,has:t,testId:y,onToggle:s=>(d(s),u())}),b=l.parts??{sort:!0,group:!0,filter:!0};return(0,a.jsxs)("div",{ref:h,style:{display:"contents"},children:[(0,a.jsx)("style",{children:W}),i==="sort"?w(g):i==="group"?x(g):i==="filter"?$(g):(0,a.jsxs)(a.Fragment,{children:[b.sort?(0,a.jsx)("div",{role:"group","aria-label":"Sort",children:w(g)}):null,b.group?(0,a.jsx)("div",{role:"group","aria-label":"Group",children:x(g)}):null,b.filter?(0,a.jsx)("div",{role:"group","aria-label":"Filter",children:$(g)}):null]})]})}function c({value:l,on:i,onPress:p,testId:o,children:e}){return(0,a.jsx)("button",{type:"button",className:"graview-arrange-item",value:l,"data-value":l,"aria-pressed":i,onClick:p,...o?{"data-testid":o}:{},children:e})}function z({entries:l,has:i,testId:p,onToggle:o}){let[e,r]=(0,v.useState)(null);if(e)return(0,a.jsx)(B,{ask:e,testId:p,onDay:d=>o({key:e.key,value:`${e.op}:${d}`}),onCancel:()=>r(null)});let n=[...new Set(l.map(d=>d.group))];return(0,a.jsx)(a.Fragment,{children:n.map(d=>(0,a.jsxs)("div",{role:"group","aria-label":d,children:[(0,a.jsx)("p",{"aria-hidden":"true",children:d}),l.filter(t=>t.group===d).map(t=>(0,a.jsx)(c,{value:t.value,on:t.condition?i(t.condition):!1,onPress:()=>t.condition?o(t.condition):r(t.ask),children:t.label},t.value))]},d))})}function B({ask:l,testId:i,onDay:p,onCancel:o}){let[e,r]=(0,v.useState)(""),n=/^\d{4}-\d{2}-\d{2}$/.test(e)&&Number(e.slice(0,4))>=1e3,d=()=>{n&&p(e)};return(0,a.jsxs)("div",{role:"group","aria-label":`${l.label} ${l.op} which day`,"data-testid":`${i}-ask-day`,className:"graview-arrange-ask",children:[(0,a.jsx)("p",{"aria-hidden":"true",children:`${l.label} ${l.op}`}),(0,a.jsx)("input",{type:"date","data-testid":`${i}-day`,"aria-label":`${l.label} ${l.op} which day`,autoFocus:!0,value:e,onChange:t=>r(t.target.value),onKeyDown:t=>{t.key==="Enter"?(t.preventDefault(),d()):t.key==="Escape"&&(t.preventDefault(),t.stopPropagation(),t.nativeEvent.stopImmediatePropagation(),o())}}),(0,a.jsxs)("span",{children:[(0,a.jsx)("button",{type:"button","data-testid":`${i}-day-add`,disabled:!n,onClick:d,children:"Add"}),(0,a.jsx)("button",{type:"button",onClick:o,children:"Never mind"})]})]})}var W=`
1
+ import{c as E,d as I}from"./chunk.XJNXSQT4.js";import"./chunk.TDW6QEG4.js";import"./chunk.LW7KV5SL.js";import"./chunk.2VX6H2LL.js";import{I as A,M as k}from"./chunk.ZQ4HFIIS.js";import{a as F,b as S}from"./chunk.MRK6QJV5.js";import{b as f}from"./chunk.AJZBJBMO.js";var v=f(F(),1);var a=f(S(),1),C=40,O=60;function D(l,i,p){return l.allNodes().filter(o=>o.kind===i).map(o=>o[p])}function G(l){if(l.length<2)return[];let i=[...l].sort((n,d)=>n-d),p=i[i.length-1]-i[0];if(p<=0)return[];let o=Math.max(1,10**Math.floor(Math.log10(p/4))),e=p/4>=o*5?o*5:o,r=n=>Math.round(n/e)*e;return[...new Set([.2,.4,.6,.8].map(n=>r(i[Math.floor(n*(i.length-1))])))].filter(n=>n>0)}function T(l,i,p){let o=p.far??[],e=new Map,r=new Set(o);for(let t of i.allNodes())r.has(t.kind)&&e.set(t.id,A(l.tryDefinition(t.kind),t));let n=[...e.entries()].map(([t,g])=>({id:t,label:g}));return(n.length<=C?n:n.map(t=>({end:t,ties:i.out(t.id).length+i.in(t.id).length})).sort((t,g)=>g.ties-t.ties||t.end.label.localeCompare(g.end.label)).slice(0,C).map(t=>t.end)).sort((t,g)=>t.label.localeCompare(g.label))}function R(l,i,p){let o=[];for(let e of p.filters)if(e.about==="is")for(let r of e.options??[])o.push({value:`is:${r}`,label:r,group:e.label,condition:{key:"is",value:r}});else if(e.about==="edge"){o.push({value:`${e.key}:*`,label:"anything",group:e.label,condition:{key:e.key,value:"*"}}),o.push({value:`${e.key}:none`,label:"nothing",group:e.label,condition:{key:e.key,value:"none"}});for(let r of T(l,i,e))o.push({value:`${e.key}:${r.id}`,label:r.label,group:e.label,condition:{key:e.key,value:r.id}})}else if(e.type==="date")for(let r of["before","after","on"])o.push({value:`${e.key}:${r}`,label:`${r}\u2026`,group:e.label,ask:{key:e.key,op:r,label:e.label}});else if(e.type==="number"){let r=l.tryDefinition(p.kind),n=G(D(i,p.kind,e.key).filter(d=>typeof d=="number"));for(let d of["at-most","at-least"])for(let t of d==="at-most"?n:[...n].reverse())o.push({value:`${e.key}:${d}:${t}`,label:`${d==="at-most"?"at most":"at least"} ${k(r,e.key,t)}`,group:e.label,condition:{key:e.key,value:`${d}:${t}`}})}else if(e.type==="text"){let r=[...new Set(D(i,p.kind,e.key).filter(n=>typeof n=="string"&&n.length>0&&!n.includes(",")))].sort((n,d)=>n.localeCompare(d));if(r.length>=2&&r.length<=O)for(let n of r)o.push({value:`${e.key}:${n}`,label:n,group:e.label,condition:{key:e.key,value:n}})}else if(e.type==="boolean")o.push({value:`${e.key}:true`,label:"yes",group:e.label,condition:{key:e.key,value:"true"}}),o.push({value:`${e.key}:false`,label:"no",group:e.label,condition:{key:e.key,value:"false"}});else for(let r of e.options??[])o.push({value:`${e.key}:${r}`,label:k(l.tryDefinition(p.kind),e.key,r),group:e.label,condition:{key:e.key,value:r}});return o}var H=["day","week","month","year","decade"];function K(l){let{which:i,schema:p,graph:o,offers:e,arrangement:r,set:n,toggle:d,has:t,done:g}=l,y=l.testId,h=(0,v.useRef)(null);(0,v.useEffect)(()=>{let u=h.current?.closest("[data-graview-popover]");!u||document.activeElement!==u||(u.querySelector('[aria-pressed="true"]')??u.querySelector("button, input"))?.focus({preventScroll:!0})},[]);let L=r.sort?e.sorts.find(u=>u.key===r.sort.by):void 0,P=r.group?e.groups.find(u=>u.key===r.group.by):void 0,M=I(L),m=e.natural?e.sorts.find(u=>u.key===e.natural.by):void 0,N=i==="filter"||i==="all"&&l.parts?.filter?R(p,o,e):[],w=u=>(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{children:"Sort by"}),(0,a.jsx)(c,{testId:`${y}-sort-default`,value:"",on:!r.sort,onPress:()=>(n({sort:void 0}),u()),children:m?`As declared (${E(m.label)})`:"As they were added"}),e.sorts.map(s=>(0,a.jsx)(c,{value:s.key,on:r.sort?.by===s.key,onPress:()=>(n({sort:{by:s.key,direction:r.sort?.direction??"asc"}}),u()),children:s.label},s.key)),r.sort?(0,a.jsxs)("div",{role:"group","aria-label":"Order","data-testid":`${y}-direction`,children:[(0,a.jsx)("p",{"aria-hidden":"true",children:"Order"}),["asc","desc"].map(s=>(0,a.jsx)(c,{testId:`${y}-direction-${s}`,value:s,on:r.sort.direction===s,onPress:()=>(n({sort:{by:r.sort.by,direction:s}}),u()),children:M[s]},s))]}):null]}),x=u=>(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{children:"Group by"}),(0,a.jsx)(c,{testId:`${y}-group-none`,value:"",on:!r.group,onPress:()=>(n({group:void 0}),u()),children:"Not grouped"}),e.groups.map(s=>(0,a.jsx)(c,{value:s.key,on:r.group?.by===s.key,onPress:()=>(n({group:{by:s.key}}),u()),children:s.label},s.key)),r.group&&P?.buckets?(0,a.jsxs)("div",{role:"group","aria-label":"How wide a group is","data-testid":`${y}-bucket`,children:[(0,a.jsx)("p",{"aria-hidden":"true",children:"Each group"}),H.map(s=>(0,a.jsx)(c,{testId:`${y}-bucket-${s}`,value:s,on:(r.group.bucket??"day")===s,onPress:()=>(n({group:{by:r.group.by,bucket:s}}),u()),children:`A ${s}`},s))]}):null]}),$=u=>(0,a.jsx)(z,{entries:N,has:t,testId:y,onToggle:s=>(d(s),u())}),b=l.parts??{sort:!0,group:!0,filter:!0};return(0,a.jsxs)("div",{ref:h,style:{display:"contents"},children:[(0,a.jsx)("style",{children:W}),i==="sort"?w(g):i==="group"?x(g):i==="filter"?$(g):(0,a.jsxs)(a.Fragment,{children:[b.sort?(0,a.jsx)("div",{role:"group","aria-label":"Sort",children:w(g)}):null,b.group?(0,a.jsx)("div",{role:"group","aria-label":"Group",children:x(g)}):null,b.filter?(0,a.jsx)("div",{role:"group","aria-label":"Filter",children:$(g)}):null]})]})}function c({value:l,on:i,onPress:p,testId:o,children:e}){return(0,a.jsx)("button",{type:"button",className:"graview-arrange-item",value:l,"data-value":l,"aria-pressed":i,onClick:p,...o?{"data-testid":o}:{},children:e})}function z({entries:l,has:i,testId:p,onToggle:o}){let[e,r]=(0,v.useState)(null);if(e)return(0,a.jsx)(B,{ask:e,testId:p,onDay:d=>o({key:e.key,value:`${e.op}:${d}`}),onCancel:()=>r(null)});let n=[...new Set(l.map(d=>d.group))];return(0,a.jsx)(a.Fragment,{children:n.map(d=>(0,a.jsxs)("div",{role:"group","aria-label":d,children:[(0,a.jsx)("p",{"aria-hidden":"true",children:d}),l.filter(t=>t.group===d).map(t=>(0,a.jsx)(c,{value:t.value,on:t.condition?i(t.condition):!1,onPress:()=>t.condition?o(t.condition):r(t.ask),children:t.label},t.value))]},d))})}function B({ask:l,testId:i,onDay:p,onCancel:o}){let[e,r]=(0,v.useState)(""),n=/^\d{4}-\d{2}-\d{2}$/.test(e)&&Number(e.slice(0,4))>=1e3,d=()=>{n&&p(e)};return(0,a.jsxs)("div",{role:"group","aria-label":`${l.label} ${l.op} which day`,"data-testid":`${i}-ask-day`,className:"graview-arrange-ask",children:[(0,a.jsx)("p",{"aria-hidden":"true",children:`${l.label} ${l.op}`}),(0,a.jsx)("input",{type:"date","data-testid":`${i}-day`,"aria-label":`${l.label} ${l.op} which day`,autoFocus:!0,value:e,onChange:t=>r(t.target.value),onKeyDown:t=>{t.key==="Enter"?(t.preventDefault(),d()):t.key==="Escape"&&(t.preventDefault(),t.stopPropagation(),t.nativeEvent.stopImmediatePropagation(),o())}}),(0,a.jsxs)("span",{children:[(0,a.jsx)("button",{type:"button","data-testid":`${i}-day-add`,disabled:!n,onClick:d,children:"Add"}),(0,a.jsx)("button",{type:"button",onClick:o,children:"Never mind"})]})]})}var W=`
2
2
  .graview-arrange-list{display:grid;align-content:start;width:min(300px,calc(100vw - 24px));height:auto;max-height:min(70vh,520px);overflow:auto;margin:0;padding:6px;border-radius:10px;border:1px solid var(--graview-edge);background:var(--graview-float);box-shadow:var(--graview-lift-high);color:var(--graview-ink);font-size:.875rem;line-height:1.3}
3
3
  .graview-arrange-list [role=group]{display:grid}
4
4
  .graview-arrange-list p{margin:8px 8px 2px;font-size:.6875rem;font-weight:600;letter-spacing:.06em;text-transform:uppercase;color:var(--graview-ink-muted)}
@@ -0,0 +1,8 @@
1
+ import{a as hr,b as fr,c as yr}from"./chunk.FRNIWOKD.js";import{a as ar,e as sr,f as dr,i as wn,j as lr,l as en,m as bn,n as cr,o as ur}from"./chunk.6O67NOZR.js";import{a as or,b as Ue,c as pn,d as rr,f as xn,g as Xt,h as ao}from"./chunk.PRXKRG6O.js";import{d as ir}from"./chunk.LW7KV5SL.js";import{A as er,B as Jt,C as Ee,D as Et,E as xt,F as Qn,H as dt,I as yn,J as Gt,L as Ut,M as gn,N as Zn,O as tr,P as Pt,Q as Ct,R as Jn,V as eo,X as At,Y as to,aa as mn,b as zn,ba as Lt,c as Kn,ca as le,d as Gn,e as Zo,ea as It,f as Jo,g as fn,h as Yt,i as Rt,j as Ot,ja as nr,k as Un,l as Xn,m as zt,qa as no,ra as oo,sa as Nt,t as qn,u as pt,ua as ro,w as Kt,xa as io,y as ce,z as $e}from"./chunk.2VX6H2LL.js";import{Ea as Ko,G as Wo,I as _o,L as Vt,N as hn,O as Wt,Ob as Uo,P as _t,R as Yo,Rb as Xo,T as zo,Wa as Go,Xb as qo,Yb as Qo,db as Mt,vb as Te}from"./chunk.ZQ4HFIIS.js";import{a as He,b as be}from"./chunk.MRK6QJV5.js";import{b as ee}from"./chunk.AJZBJBMO.js";var vn=(e,t)=>e<t?-1:e>t?1:0;function mr(e){return!e||e<=1?1:Math.min(4,Math.ceil(Math.sqrt(e)))}function pr(e,t,n){if(t===n)return 0;let r=e.kinds,o=0;for(let[i,a]of[[t,n],[n,t]]){let l=e.tryDefinition(i);for(let c of Object.values(l?.edges??{}))(c.to==="*"?r:c.to).includes(a)&&(o+=1)}return o}var gr=(e,t)=>`${Math.floor(e/5)},${Math.floor(t/5)}`;function $i(e,t,n){if(n===0)return[{col:e,row:t}];let r=[];for(let o=0;o<n;o++)r.push({col:e+(n-o)*5,row:t+o*5}),r.push({col:e-o*5,row:t+(n-o)*5}),r.push({col:e-(n-o)*5,row:t-o*5}),r.push({col:e+o*5,row:t-(n-o)*5});return r}function so(e,t={}){let n=[...e.kinds],r=[...(t.order??[]).filter(l=>n.includes(l)),...n.filter(l=>!(t.order??[]).includes(l)).sort(vn)].filter((l,c,s)=>s.indexOf(l)===c),o=new Map,i=new Set,a=(l,c,s)=>{o.set(l,{col:c,row:s,side:mr(t.counts?.[l])}),i.add(gr(c,s))};for(let l of r){let c=e.tryDefinition(l)?.plot??t.plots?.[l];c&&a(l,c.col,c.row)}for(let l of r){if(o.has(l))continue;if(o.size===0){a(l,0,0);continue}let c,s=0;for(let h of[...o.keys()].sort(vn)){let g=pr(e,l,h);(g>s||g===s&&g>0&&c!==void 0&&vn(h,c)<0)&&(s=g,c=h)}let d=c?o.get(c):o.get(r.find(h=>o.has(h))),u;for(let h=1;!u&&h<64;h++)u=$i(d.col,d.row,h).find(g=>!i.has(gr(g.col,g.row)));a(l,u?.col??d.col+5*o.size,u?.row??d.row)}return o}function lo(e,t){let n=[...t.keys()].sort(vn),r=[];for(let o=0;o<n.length;o++)for(let i=o+1;i<n.length;i++){let a=n[o],l=n[i],c=[];for(let[s,d]of[[a,l],[l,a]]){let u=e.tryDefinition(s);for(let[h,g]of Object.entries(u?.edges??{}))(g.to==="*"?e.kinds:g.to).includes(d)&&c.push(h)}c.length>0&&r.push({from:a,to:l,edges:c})}return r}function co(e){let t=1/0,n=1/0,r=-1/0,o=-1/0;for(let i of e.values())t=Math.min(t,i.col),n=Math.min(n,i.row),r=Math.max(r,i.col+i.side),o=Math.max(o,i.row+i.side);return e.size===0?{minCol:0,minRow:0,maxCol:1,maxRow:1}:{minCol:t,minRow:n,maxCol:r,maxRow:o}}function ve(e,t,n){return{x:(e-t)*n/2,y:(e+t)*n/4}}function Hi(e){if(e<3)return[];if(e%2===1){let r=(e-1)/2;return[[r,r]]}let t=e/2-1,n=e/2;return[[t,t],[n,t],[t,n],[n,n]]}function xr(e){let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return(t>>>0)%1e3/1e3}function uo(e,t){let n=e.side+1,r=new Set(Hi(n).map(([c,s])=>`${c},${s}`)),o=e.side/n,i=[];for(let c=0;c<n;c++)for(let s=0;s<n;s++)r.has(`${s},${c}`)||i.push([s,c]);i.sort((c,s)=>c[0]+c[1]-(s[0]+s[1])||c[0]-s[0]);let a=t.slice(0,i.length);return{buildings:a.map((c,s)=>{let[d,u]=i[s];return{id:c,col:e.col+(d+.5)*o,row:e.row+(u+.5)*o,footprint:o*.62,height:.55+xr(c)*.7}}),rest:Math.max(0,t.length-a.length)}}var wr={width:1200,height:760,focusSize:{width:1200,height:420},relationSize:{width:240,height:140},contextSize:{width:300,height:104},gap:16,unit:16};var br=(e,t)=>e?`${e.edgeKind}|${e.direction}`:`raised|${t}`,Tt=(e,t,n)=>`${yn}${e}|${t}|${n}`;function Di(e,t){if(!Gt(e))return null;let[n="",r="",o="",i=""]=e.slice(yn.length).split("|"),a=t.definitions.find(x=>x.kind===n),l=_t(t,n),c=r==="raised"?null:(()=>{let x=a?.edges[r]??t.definitions.map(f=>f.edges[r]).find(Boolean);return((o==="in"?x?.inverse:x?.description)??Vt(r)).toLowerCase()})(),[s="",d=""]=i.split("="),u=s.split(":")[0],h=i===""||i==="kind"||i.startsWith("more")?null:`${Yo(a,u).toLowerCase()}: ${d==="none"?"none":d}`;return[i.startsWith("more")?`More ${l.toLowerCase()}`:l,[c,h].filter(Boolean).join(", ")].filter(Boolean).join(" \u2014 ")}function kn(e,t){let n=e.map(()=>0),r=e.map((a,l)=>({size:a,index:l})).sort((a,l)=>a.size-l.size||a.index-l.index),o=Math.max(t,e.length),i=e.length;for(let{size:a,index:l}of r){let c=Math.max(1,Math.floor(o/i));n[l]=Math.min(a,c),o-=n[l],i-=1}return n}function fo(e){return br(e.via,e.node.kind)}function Sn(e,t){let n=[],r=0;return e.forEach((o,i)=>{if(o<=0)return;if(n.length>0&&o<=r){for(let l=0;l<o;l++)n[n.length-1].push(i);r-=o;return}let a=o;for(;a>0;){let l=Math.min(t,a);n.push(Array.from({length:l},()=>i)),a-=l,r=t-l}}),n}function yo(e,t,n){let r=kn(e,t*n);for(;Sn(r,t).length>n;){let o=-1;if(r.forEach((i,a)=>{i>1&&(o<0||i>r[o])&&(o=a)}),o<0)break;r[o]=r[o]-1}return r}function Fi(e,t,n){let r=o=>[t.chosen?.has(o.id)?0:1,t.hits?.has(o.id)?0:1,t.flagged?.has(o.id)?0:1,-(t.touched?.get(o.id)??0),-n.neighbors(o.id).length];return e.map((o,i)=>({node:o,index:i,key:r(o)})).sort((o,i)=>{for(let a=0;a<o.key.length;a++)if(o.key[a]!==i.key[a])return o.key[a]-i.key[a];return o.index-i.index}).map(o=>o.node)}var Bi=5,ji=(e,t)=>{for(let n=0;n<e.length;n++)if(e[n]!==t[n])return e[n]<t[n];return!1};function vr(e,t,n){if(e.length===0||t<2)return;let r=e[0].kind,o={schema:n.schema,graph:n.graph,...n.today?{today:n.today}:{}},i=[];for(let l of Ko(n.schema,r).groups)if(l.key!==n.exclude)if(l.buckets)for(let c of["decade","year","month"])i.push({by:l.key,bucket:c});else i.push({by:l.key});let a;return i.forEach((l,c)=>{let d=ir(e,{group:l},o).groups;if(d.length<2||d.length>t)return;let h=d.filter(x=>x.key!=="").reduce((x,p)=>x+p.nodes.length,0)/e.length;if(h<.5||d.some(x=>x.nodes.length>e.length*.75))return;let g=[-Math.round(h*100),Math.abs(d.length-Bi),c];(!a||ji(g,a.score))&&(a={grouping:{by:l.by,...l.bucket?{bucket:l.bucket}:{},groups:d},score:g})}),a?.grouping}function go(e,t){let n=p=>({id:p.node.id,kind:p.node.kind,node:p.node,...p.via?{via:p.via}:{}});if(e.length<=t.budget)return e.map(n);let r={...t.relevance,chosen:new Set([...t.relevance?.chosen??[],...t.selection??[]])},o=new Map;for(let p of e){let f=br(p.via,p.node.kind),m=o.get(f);m?m.push(p):o.set(f,[p])}let i=[...o.entries()].map(([p,f])=>({key:p,run:f,via:f[0].via,kinds:[...new Set(f.map(m=>m.node.kind))],members:[],whole:!1,extra:0})),a=kn(i.map(p=>p.run.length),t.budget);i.forEach((p,f)=>p.whole=p.run.length<=a[f]);let l=i.filter(p=>!p.whole),c=i.filter(p=>p.whole).reduce((p,f)=>p+f.run.length,0),s=Math.max(l.length,t.budget-c);for(let p of l){p.members=Fi(p.run.map(m=>m.node),r,t.graph);let f=s-(l.length-1);p.kinds.length>1&&p.kinds.length<=f?p.byKind=!0:p.kinds.length===1&&(p.grouping=vr(p.members,f,{schema:t.schema,graph:t.graph,...p.via?{exclude:p.via.edgeKind}:{},...t.today?{today:t.today}:{}}))}let d=p=>p.byKind?p.kinds.length:p.grouping?p.grouping.groups.length:1;for(;l.reduce((p,f)=>p+d(f),0)>s;){let p=[...l].filter(f=>d(f)>1).sort((f,m)=>d(m)-d(f))[0];if(!p)break;p.grouping=void 0,p.byKind=!1}s-=l.reduce((p,f)=>p+d(f),0);let u=p=>p.byKind?p.kinds.some(f=>t.expanded.has(Tt(f,p.key,"kind"))):p.grouping?.groups.some(f=>t.expanded.has(Tt(p.kinds[0],p.key,ho(p.grouping,f.key)))),h=l.filter(p=>!p.grouping&&!p.byKind?!0:u(p)),g=kn(h.map(p=>p.members.length),Math.max(0,s));h.forEach((p,f)=>p.extra=s>0?g[f]:0);let x=[];for(let p of i){let{key:f,via:m}=p;if(p.whole){x.push(...p.run.map(n));continue}let b=w=>({id:w.id,kind:w.kind,node:w,...m?{via:m}:{}}),R=new Map(p.run.map((w,M)=>[w.node.id,M])),O=(w,M,C)=>{let B=[...w.slice(0,M)].sort((D,H)=>R.get(D.id)-R.get(H.id));x.push(...B.map(b));let A=w.slice(M);if(A.length===0)return;let $=A[0].kind;x.push({id:Tt($,f,C?`more:${C}`:"more"),kind:$,...m?{via:m}:{},aggregate:{kind:$,memberIds:A.map(D=>D.id),label:M>0?`${A.length} more ${t.plural($).toLowerCase()}`:`${A.length} ${t.plural($).toLowerCase()}`,opens:{in:"picture",focus:Ee($),within:C?{filter:C}:{}}}})},E=m&&t.focusId?`${m.edgeKind}:${t.focusId}`:void 0;if(p.byKind){let w=p.kinds.find(M=>t.expanded.has(Tt(M,f,"kind")));for(let M of p.kinds){let C=p.members.filter(B=>B.kind===M);if(M===w){let B=p.extra+1;C.length<=B?x.push(...C.map(b)):O(C,B-1,E);continue}x.push({id:Tt(M,f,"kind"),kind:M,...m?{via:m}:{},aggregate:{kind:M,memberIds:C.map(B=>B.id),label:t.plural(M),opens:{in:"place"}}})}continue}let S=p.grouping;if(!S){O(p.members,p.extra,E);continue}let j=p.kinds[0],k=S.groups.find(w=>t.expanded.has(Tt(j,f,ho(S,w.key))));for(let w of S.groups){if(w===k){let M=p.members.filter(B=>w.nodes.includes(B)),C=p.extra+1;if(M.length<=C)x.push(...M.map(b));else{let B=w.key!==""&&!w.key.includes(",")&&!S.bucket,A=[E,B?`${S.by}:${w.key}`:void 0].filter(Boolean).join(",")||void 0;O(M,C-1,A)}continue}x.push({id:Tt(j,f,ho(S,w.key)),kind:j,...m?{via:m}:{},aggregate:{kind:j,memberIds:p.members.filter(M=>w.nodes.includes(M)).map(M=>M.id),label:w.label.charAt(0).toUpperCase()+w.label.slice(1),opens:{in:"place"}}})}}return x}var ho=(e,t)=>`${e.by}${e.bucket?`:${e.bucket}`:""}=${t||"none"}`;function mo(e,t,n=6){return e.x<t.x+t.width+n&&t.x<e.x+e.width+n&&e.y<t.y+t.height+n&&t.y<e.y+e.height+n}var kr=(e,t)=>ve(e.col+e.side/2,e.row+e.side/2,t);function po(e,t,n,r,o={},i={}){let a={};for(let L of e)a[L.kind]=L.count;let l=so(t,{...i.order?{order:i.order}:{},counts:a,...i.plots?{plots:i.plots}:{}}),c=o.left??0,s=r.width-c-(o.right??0),d=c+s/2,u=r.height*.53,h=co(l),g=[ve(h.minCol,h.minRow,1),ve(h.maxCol,h.minRow,1),ve(h.minCol,h.maxRow,1),ve(h.maxCol,h.maxRow,1)],x=Math.min(...g.map(L=>L.x)),p=Math.max(...g.map(L=>L.x)),f=Math.min(...g.map(L=>L.y)),m=Math.max(...g.map(L=>L.y)),b={x:Math.max(1,p-x),y:Math.max(.5,m-f)},R=Math.max(40,s-n.width*1.1),O=Math.max(24,r.height*.62-n.height*1.1),E=Math.max(18,Math.min(160,R/b.x,O/b.y)),S=i.scale??1,j=i.minHeight??0,k=i.avoid??[],w=0,M=(L,z,v=1,N={x:0,y:0})=>{let T=d-(x+p)/2*L+N.x+w,G=u-(f+m)/2*L+N.y,F={width:n.width*z,height:n.height*z},re=e.map(J=>kr(l.get(J.kind),L).y),ie=Math.max(...re),de=Math.min(...re);return e.map(J=>{let Ae=l.get(J.kind),Se=kr(Ae,L),et=ie===de?.5:(Se.y-de)/(ie-de),Ye=.85+et*.45,U=F.width*Ye,Le=Math.max(j,F.height*Ye),tt=Le+(J.marquee??0)+(J.opened>0?Math.max(J.openedMin??0,J.opened*v):0);return{id:J.id,x:T+Se.x-U/2,y:G+Se.y-Le/2,width:U,height:tt,depth:1-et*.65,plot:Ae}})},C=L=>L.some((z,v)=>L.some((N,T)=>T!==v&&mo(z,N)))||L.some(z=>k.some(v=>mo(z,v))),B=L=>{if(k.length===0)return[{x:0,y:0}];let z=Math.max(...k.map(T=>T.width))/2+L,v=Math.max(...k.map(T=>T.height))/2+L/2,N=[{x:0,y:0}];for(let T of[.5,.75,1,1.25]){let G=z*T,F=v*T;N.push({x:G,y:0},{x:-G,y:0},{x:0,y:F},{x:0,y:-F},{x:G,y:F},{x:-G,y:F},{x:G,y:-F},{x:-G,y:-F})}return N},A=r.width-(o.right??0),$=L=>L.reduce((z,v)=>{let N=Math.max(0,Math.min(v.x+v.width,r.width)-Math.max(v.x,0)),T=Math.max(0,Math.min(v.y+v.height,r.height)-Math.max(v.y,0));return z+v.width*v.height-N*T},0),D=(L,z,v)=>{let N,T;for(let G of B(L)){let F=M(L,z,v,G);if(C(F)){T??={placed:F,shift:G};continue}let re=$(F);(!N||re<N.off-.5)&&(N={placed:F,shift:G,off:re})}return N??T},H=E,Y=S,K=1,W=D(H,Y,K);for(;C(W.placed)&&Y>1.001;)Y=Math.max(1,Y-.05),W=D(H,Y,K);for(;C(W.placed)&&K>.3;)K=Math.max(.3,K-.1),W=D(H,Y,K);if(C(W.placed)||$(W.placed)>0){let L=C(W.placed)?void 0:{cell:H,settled:W,off:$(W.placed)};for(let z=.9;z>=.3;z-=.1){let v=E*z,N=D(v,Y,K);if(C(N.placed))continue;let T=$(N.placed);if((!L||T<L.off-.5)&&(L={cell:v,settled:N,off:T}),T===0)break}L&&(H=L.cell,W=L.settled)}for(let L=0;C(W.placed)&&L<80;L++)H*=1.06,W=D(H,Y,K);if(k.length===0){let L=Math.min(...W.placed.map(N=>N.x)),z=Math.max(...W.placed.map(N=>N.x+N.width)),v=z-L>A-c?0:L<c?c-L:z>A?A-z:0;if(v!==0){w=v;let N=M(H,Y,K,W.shift);C(N)?w=0:W={placed:N,shift:W.shift}}}i.zoom&&i.zoom!==1&&(H*=i.zoom,w*=i.zoom,W=D(H,Y,K));let ge=W.placed,me=d-(x+p)/2*H+W.shift.x+w,X=u-(f+m)/2*H+W.shift.y,oe={cell:H,originX:me,originY:X,pan:i.pan??{x:0,y:0},extent:{x:me+x*H,y:X+f*H,width:b.x*H,height:b.y*H},openedShare:K};return{placed:ge,frame:oe,map:l}}function wt(e){let t={x:e.width*.45,y:e.height*.45};if(!e.city)return t;let{extent:n}=e.city,r=24;return{x:Math.max(t.x,n.x+n.width-e.width+r,-n.x+r),y:Math.max(t.y,n.y+n.height-e.height+r,-n.y+r)}}var Mn=48;function xo(e){if(!e.city)return[];let{width:t,height:n}=e,r=[];for(let o of e.nodes){if(!o.id.startsWith("kind:")||Math.round(o.plane)!==2)continue;let i=o.x+o.width/2,a=o.y+o.height/2,l=i<0?"left":i>t?"right":a<0?"top":a>n?"bottom":null;if(!l)continue;let c=l==="left"||l==="right",s=c?Math.max(0,Math.min(n,a)):Math.max(0,Math.min(t,i)),d=(g,x)=>g<x/4?x/4-g:g>x*3/4?x*3/4-g:0,u=(g,x)=>g<Mn?Mn-g:g>x-Mn?x-Mn-g:0,h=c?{x:d(i,t),y:u(a,n)}:{x:u(i,t),y:d(a,n)};r.push({id:o.id,kind:o.id.slice(5),side:l,along:s,by:h})}return r}function wo(e,t,n,r,o){return{x:e.x+(n.x-e.x-t.x-r.x)*(1-o),y:e.y+(n.y-e.y-t.y-r.y)*(1-o)}}var Vi={rankOf:()=>{},parentOf:()=>{}};function Sr(e,t){if(t.size===0)return Vi;let n=e.kinds,r=new Map,o=(s,d)=>{s!==d&&((r.get(s)??r.set(s,new Set).get(s)).add(d),(r.get(d)??r.set(d,new Set).get(d)).add(s))};for(let s of n){let d=e.tryDefinition(s);if(d)for(let u of Object.values(d.edges??{})){let h=u.to==="*"?n:u.to;for(let g of h)o(s,g)}}let i=new Map,a=new Map,l=[...t].filter(s=>n.includes(s));for(let s of l)i.set(s,0);let c=0;for(;l.length>0;){c+=1;let s=[];for(let d of[...l].sort((u,h)=>n.indexOf(u)-n.indexOf(h)))for(let u of[...r.get(d)??[]].sort((h,g)=>n.indexOf(h)-n.indexOf(g)))i.has(u)||(i.set(u,c),c===2&&a.set(u,d),s.push(u));l=s}return{rankOf:s=>{let d=i.get(s);if(d!==0)return d===1?"primary":"secondary"},parentOf:s=>a.get(s)}}function Mr(e,t,n,r,o={}){if(n){let i=new Map;for(let a of e.allEdges()){if(r&&a.kind!==r)continue;let l=a.from===n.id?a.to:a.to===n.id?a.from:null;if(l===null||l===n.id)continue;let c=e.getNode(l);if(!c||i.has(l))continue;let s=a.from===n.id?"out":"in",d=s==="out"?n.kind:c.kind,u=Wi(t,d,a.kind,s);i.set(l,{node:c,via:{edgeKind:a.kind,direction:s,...u?{description:u}:{}}})}if(i.size>0){let a=l=>`${l.via.edgeKind}|${l.via.description??""}`;return[...i.values()].sort((l,c)=>(a(l)<a(c)?-1:a(l)>a(c)?1:0)||dt(l.node,c.node))}}if(n){let i=o[n.id]??[],a=new Set,l=[];for(let c of i){if(c===n.id||a.has(c))continue;let s=e.getNode(c);s&&(r&&r!=="judges"&&s.kind!==r||(a.add(c),l.push({node:s,via:{edgeKind:"judges",direction:"out",description:"what it finds wrong"}})))}if(l.length>0)return l.sort((c,s)=>dt(c.node,s.node))}return r?e.allNodes().filter(i=>i.kind===r).sort(dt).map(i=>({node:i})):[]}function Wi(e,t,n,r){let i=e.tryDefinition(t)?.edges?.[n];return r==="out"?i?.description:i?.inverse}function Rr(e,t,n){let r=new Map,o=[...t.values()].sort((s,d)=>s.plane-d.plane);for(let s of o)for(let d of s.aggregate?.memberIds??[])!t.has(d)&&!r.has(d)&&r.set(d,s.id);let i=s=>t.get(s)??t.get(r.get(s)??""),a=new Map,l=new Map,c=new Map;for(let s of e.allEdges()){let d=i(s.from),u=i(s.to);if(!d||!u||d.id===u.id&&!(n.overview&&d.aggregate&&d.plane===2))continue;let h=`${s.kind}:${d.id}:${u.id}`,g=a.get(h);if(g){let x=`${s.from}
2
+ ${s.to}`,p=l.get(h);if(p.has(x))continue;if(p.add(x),c.get(h).push({from:s.from,to:s.to}),g.single){let{single:f,...m}=g;a.set(h,m)}continue}l.set(h,new Set([`${s.from}
3
+ ${s.to}`])),c.set(h,[{from:s.from,to:s.to}]),a.set(h,{id:h,kind:s.kind,from:d.id,to:u.id,edges:[{from:s.from,to:s.to}],single:{from:s.from,to:s.to},...d.id===u.id?{loop:!0}:{},x1:d.x+d.width/2,y1:d.y+d.height/2,x2:u.x+u.width/2,y2:u.y+u.height/2})}return[...a.values()].map(s=>({...s,edges:c.get(s.id)})).sort(dt)}var Pr=.85,Or=60,Rn=160,Cr=2,Yi=240,zi=300,Ki=52,Er=60;function Gi(e,t,n,r,o,i=Pr){let a=e*t.width+Math.max(0,e-1)*n,l=Math.max(n,(r-a)/2);return Array.from({length:e},(c,s)=>({x:l+s*(t.width+n),y:o,depth:i}))}function Ui(e,t,n,r,o){let i=e*t.width+Math.max(0,e-1)*n,a=Math.max(n,(r-i)/2);return Array.from({length:e},(l,c)=>({x:a+c*(t.width+n),y:o}))}function On(e,t,n,r={}){let o={...wr,...r},i=Math.max(8,o.unit??16)/16,a=o.inset?.left??0,l=o.width-a-(o.inset?.right??0),c=[],s=new Map,d=y=>n.past===!0||Wo(t.tryDefinition(y.kind),y,o.today),u=new Set(r.hiddenKinds??[]),h=y=>!u.has(y.kind),g=n.focusId?xt(n.focusId).filter(y=>t.tryDefinition(y)!==void 0).filter(y=>!u.has(y)):[];n.focusId&&xt(n.focusId).length>0&&g.length===0&&(n={...n,focusId:null});let x=n.focusId?e.getNode(n.focusId):void 0;x&&!h(x)&&(n={...n,focusId:null},g=[]);let p=g.length>0?[...e.allNodes()].filter(y=>g.includes(y.kind)).sort(dt):[],f=p.filter(h).filter(d),m=p.length-f.length,b=n.focusId&&g.length===0?e.getNode(n.focusId):void 0,R=n.zoom===!0&&!n.overview&&n.focusId!==null,O=Math.max(56,o.height*.062),E=Math.min(o.height*.895,o.height-O),S=R?b!==void 0?{focusY:o.height*.03,focusH:o.height*.58,relationY:o.height*.645,relationH:o.height*.2,contextY:E,contextH:O}:{focusY:o.height*.03,focusH:o.height*.71,relationY:o.height*.765,relationH:o.height*.1,contextY:E,contextH:O}:b===void 0?{focusY:o.height*.045,focusH:o.height*.62,relationY:o.height*.68,relationH:o.height*.2,contextY:o.height*.918,contextH:o.height*.082}:(()=>{let y=o.height,I=y*.04,_=Math.max(y*.42,Math.min(y*.56,300)),Q=I+_+y*.06;return{focusY:I,focusH:_,relationY:Q,relationH:Math.max(y*.12,y*.878-y*.068-Q),contextY:y*.878,contextH:y*.092}})(),j=y=>Math.min(o.gap*y,Math.round(l*.1)),k=R?Math.min(880,l-j(5)):Math.min(700,l-j(6)),w=R?l-j(5):Math.min(o.focusSize.width,l-j(6)),M=(y,I,_)=>({width:y===0?I:Math.min(I,(l-o.gap*(y+1))/y),height:_}),C=(y,I,_)=>{let Q=M(y,I,_),we=Math.min(I,Rn*i,l-o.gap*2);return Q.width>=we?Q:{width:we,height:_}},B=y=>Math.max(1,Math.floor((l-o.gap)/(Math.min(y,Rn*i,l-o.gap*2)+o.gap))),A=new Set(n.expanded),$=n.overview?[]:Mr(e,t,b,n.relation,o.judged).filter(y=>h(y.node)).filter(y=>d(y.node)),D=$.length>0?S.focusH:S.contextY-S.focusY-o.gap*2,H=w,Y=o.height,K=Math.min(l*.5/H,o.height*.48/Y),W=H*K,ge=Y*K,me=new Set(r.plainGroups??[]),X=n.overview&&!b&&g.length>0&&n.focusId!==null,oe=X&&g.length>0&&g.every(y=>me.has(y));if(X)for(let y of g)oe?A.add(ce(y)):A.delete(ce(y));let L=X&&!oe&&g.length===1?g[0]:void 0,z=L?r.screens?.[L]??[]:[],v=z.find(y=>y.as===n.within?.view)??z[0],N=L!==void 0&&v!==void 0,T;n.overview&&(b||g.length>0)&&n.focusId&&!oe?(T={x:a+(l-W)/2,y:o.height*.53-ge/2,width:W,height:ge},Zt({id:n.focusId,kind:b?b.kind:g[0],plane:0,x:T.x,y:T.y,width:W,height:ge,natural:{width:H,height:Y},...b?{}:{aggregate:{kind:g.join("+"),memberIds:f.map(y=>y.id),label:r.plurals?.[n.focusId]??g.map(y=>Wt(t,y)).join(" and "),...m>0?{retired:m}:{}}}})):n.overview||(b?Zt({id:b.id,kind:b.kind,plane:0,x:a+(l-k)/2,y:S.focusY,width:k,height:D}):g.length>0&&n.focusId&&Zt({id:n.focusId,kind:g[0],plane:0,x:a+(l-w)/2,y:S.focusY,width:w,height:D,aggregate:{kind:g.join("+"),memberIds:f.map(y=>y.id),label:r.plurals?.[n.focusId]??g.map(y=>Wt(t,y)).join(" and "),...m>0?{retired:m}:{}}}));let G=26,F=52,re=22,ie=Math.round(o.relationSize.width*.75),de=Math.max(1,Math.floor((l-o.gap)/(ie+o.gap))),J=o.unit/16,Ae=Math.max(2,Math.floor((S.relationH+o.gap)/(G*J+o.gap))),Se=$.length>de*Ae,et={schema:t,graph:e,focusId:b?.id,expanded:A,...o.relevance?{relevance:o.relevance}:{},...n.selection?{selection:n.selection}:{},plural:y=>Wt(t,y),...o.today?{today:o.today}:{}},Ye=Se?Math.max(o.gap,re*J):o.gap,U,Le;if(!Se)U=$.map(y=>({id:y.node.id,kind:y.node.kind,node:y.node,...y.via?{via:y.via}:{}})),Le=Array.from({length:Math.max(1,Math.ceil(U.length/de))},(y,I)=>Array.from({length:Math.min(de,U.length-I*de)},(_,Q)=>I*de+Q));else{let y=Math.max(1,Math.floor((S.relationH+Ye)/(F*J+Ye))),I=new Map;for(let fe of $){let pe=fo(fe),Ge=I.get(pe);Ge?Ge.push(fe):I.set(pe,[fe])}let _=yo([...I.values()].map(fe=>fe.length),de,y),Q=[...I.values()].map((fe,pe)=>go(fe,{...et,budget:_[pe]}));U=Q.flat();let we=Q.map((fe,pe)=>Q.slice(0,pe).reduce((Ge,Bt)=>Ge+Bt.length,0)),st=Q.map(()=>0);Le=Sn(Q.map(fe=>fe.length),de).map(fe=>fe.map(pe=>we[pe]+st[pe]++))}let tt=Le.length,nt=tt===1?S.relationH:(S.relationH-Ye*(tt-1))/tt,Fe=M(Math.max(...Le.map(y=>y.length),1),U.length<=2?Math.round(o.relationSize.width*1.35):o.relationSize.width,nt),Je=[];Le.forEach((y,I)=>{let _=Ui(y.length,Fe,o.gap,l,S.relationY+I*(nt+Ye));y.forEach((Q,we)=>Je[Q]={..._[we],x:_[we].x+a})}),U.forEach((y,I)=>{let _=Je[I];Zt({id:y.id,kind:y.kind,plane:1,x:_.x,y:_.y,width:Fe.width,height:Fe.height,...y.via?{via:y.via}:{},...y.aggregate?{aggregate:y.aggregate}:{},...Se&&!y.aggregate?{compact:!0}:{}})});let ht=new Set(s.keys());for(let y of f)ht.add(y.id);let Ne=new Map;for(let y of e.allNodes()){let I=Ne.get(y.kind);I?I.push(y):Ne.set(y.kind,[y])}let ft=new Set(g.length>0?g:b?[b.kind]:[]),yt=[];for(let y of t.kinds){if(u.has(y))continue;let I=Ne.get(y)??[],_=I.filter(d);yt.push({id:ce(y),kind:y,members:_.sort(dt),retired:I.length-_.length,...ft.has(y)?{focused:!0}:{}})}for(let y of yt)y.kind===n.relation&&(y.raised=!0);yt.sort(dt);let ze=Sr(t,ft),ot=!n.overview&&t.kinds.some(y=>ze.rankOf(y)==="primary"),Ie=[];for(let y of yt)if(!n.overview&&A.has(y.id)&&y.members.length>0)for(let I of y.members)Ie.push({id:I.id,kind:I.kind});else{let I=ot?ze.rankOf(y.kind):void 0,_=I==="secondary"?ze.parentOf(y.kind):void 0;Ie.push({id:y.id,kind:y.kind,...y.raised?{raised:!0}:{},...y.focused?{focused:!0}:{},...n.overview&&A.has(y.id)?{opened:!0}:{},...I?{rank:I}:{},..._&&!A.has(ce(_))?{nestedUnder:ce(_)}:{},aggregate:{kind:y.kind,memberIds:y.members.map(Q=>Q.id),label:r.plurals?.[y.kind]??Wt(t,y.kind),...y.retired>0?{retired:y.retired}:{}}})}let kt=2;if(Ie.length<=B((R?240:o.contextSize.width)*i))for(let y of Ie)delete y.nestedUnder;let xe=new Map;for(let y of Ie){if(y.nestedUnder===void 0)continue;let I=xe.get(y.nestedUnder)??0;I>=kt?delete y.nestedUnder:xe.set(y.nestedUnder,I+1)}let rt=Ie.filter(y=>y.nestedUnder!==void 0),Me=Ie.filter(y=>y.nestedUnder===void 0),gt=B((R?240:o.contextSize.width)*i),mt=!n.overview&&Me.length>gt,St=Math.max(0,gt-1),P=y=>y.focused?0:y.raised?1:2,ae=new Set([...Me].map((y,I)=>({item:y,at:I})).sort((y,I)=>P(y.item)-P(I.item)||y.at-I.at).slice(0,St).map(({item:y})=>y.id)),he=new Set(mt?Me.filter(y=>!ae.has(y.id)).map(y=>y.id):[]),Re=rt.filter(y=>!he.has(y.nestedUnder)),it=rt.filter(y=>he.has(y.nestedUnder)),at=mt?[...Me.filter(y=>ae.has(y.id)),{id:er,kind:"",beyond:[...Me.filter(y=>he.has(y.id)),...it].map(y=>y.kind)}]:Me,Ke=n.overview?{width:Math.min(220,l/6.5),height:Math.min(92,o.height*.125)}:C(at.length,(R?240:o.contextSize.width)*i,S.contextH),Be=n.overview?po(at.map(y=>({id:y.id,kind:y.kind,count:y.aggregate?.memberIds.length??0,opened:A.has(y.id)?Ct(Pt(y.aggregate?.memberIds.length??0))*i:0,openedMin:A.has(y.id)?Ct(Math.min(Zn,Pt(y.aggregate?.memberIds.length??0)))*i:0,...(r.screens?.[y.kind]?.length??0)>0?{marquee:Ut((r.screens?.[y.kind]??[]).map(I=>I.title),Rn*i,r.nameWidth)*i}:{}})),t,Ke,{width:o.width,height:o.height},o.inset??{},{...o.cityOrder?{order:o.cityOrder}:{},...o.plots?{plots:o.plots}:{},scale:i,minHeight:Or*i,...r.cityZoom&&r.cityZoom!==1?{zoom:r.cityZoom}:{},pan:{x:n.pan?.x??0,y:n.pan?.y??0},...T&&!N?{avoid:[T]}:{}}):null,an=new Map(Be?.placed.map(y=>[y.id,y.plot])??[]),Ft=Be?Be.placed.map(({x:y,y:I,depth:_,width:Q,height:we})=>({x:y,y:I,depth:_,width:Q,height:we})):Gi(at.length,Ke,o.gap,l,S.contextY,R?.97:Pr).map(y=>({...y,x:y.x+a})),Ci=.74,sn=.8,Ai=52*i,Li=86*i,jn=(y,I)=>Math.min(1,y+(1-y)*I),Vn=new Map;at.forEach((y,I)=>{let _=Ft[I],Q=_.width??Ke.width,we=_.height??Ke.height,st=y.rank==="secondary"?Ci:1,fe=Math.max(Math.min(Q,Rn*i),Q*st),pe=Math.max(Or*i,we*st);Vn.set(y.id,{x:_.x+(Q-fe)/2,y:_.y+(we-pe),depth:y.rank==="secondary"?jn(_.depth,.5):_.depth,width:fe,height:pe})});let dn=[],ln=Ft[Ft.length-1],Wn=new Map;for(let y of Re)Wn.set(y.nestedUnder,(Wn.get(y.nestedUnder)??0)+1);let $o=new Map;for(let y of Re){let I=Vn.get(y.nestedUnder);if(I){let _=Wn.get(y.nestedUnder)??1,Q=$o.get(y.nestedUnder)??0;$o.set(y.nestedUnder,Q+1);let we=.98,st=Ke.width*sn,fe=Math.max(Li,Math.min(st,I.width/(we*(_-1)+1))),pe=Math.max(Ai,Ke.height*sn*(fe/st)),Ge=fe*we,Bt=(_-1)*Ge+fe;dn.push({...y,x:I.x+(I.width-Bt)/2+Q*Ge,y:Math.max(0,I.y-pe+Math.min(pe*.5,16)),width:fe,height:pe,depth:jn(I.depth,.8)})}else if(ln){let _=Ke.width*sn,Q=Ke.height*sn;dn.push({...y,x:ln.x,y:ln.y,width:_,height:Q,depth:jn(ln.depth??1,.8)})}}for(let y of at)dn.push({...y,...Vn.get(y.id)});if(dn.forEach(y=>{Zt({id:y.id,kind:y.kind,plane:2,x:y.x,y:y.y,width:y.width,height:y.height,...y.aggregate?{aggregate:y.aggregate}:{},...y.raised?{raised:!0}:{},...y.focused?{focused:!0}:{},...y.opened?{opened:!0}:{},...y.opened?{openedRows:Math.max(1,Math.floor((Math.max(Ct(Math.min(Zn,Pt(y.aggregate?.memberIds.length??0))),Ct(Pt(y.aggregate?.memberIds.length??0))*(Be?.frame.openedShare??1))-tr)/gn))}:{},...y.rank?{rank:y.rank}:{},...y.nestedUnder?{nestedUnder:y.nestedUnder}:{},...y.beyond?{beyond:y.beyond}:{},...an.has(y.id)?{plot:an.get(y.id)}:{},depth:y.depth})}),N&&Be&&T&&n.focusId){let y=Be.frame,I=Be.map.get(L),_=v?.across?Be.map.get(v.across):void 0;if(I){let we=(Z=>{let Pe=ve(Z.col,Z.row,y.cell),Oe=ve(Z.col+Z.side/2,Z.row+Z.side/2,y.cell);return{top:{x:y.originX+Pe.x,y:y.originY+Pe.y},center:{x:y.originX+Oe.x,y:y.originY+Oe.y}}})(I),st=we.center.x,fe=we.top.y+y.cell*.1,pe=o.screenHeight!==void 0&&o.screenHeight>0?Math.min(Y,Math.max(Yi,Math.round(o.screenHeight))):Y,Ge=pe/H,Bt=Math.max(1,(r.cityZoom??1)/1.5),Ii=l*.78*Bt,Ho=o.height*.72*Bt,_n=Math.min(zi*i,l*.5),cn=Math.max(_n,Math.min(Ii,I.side*y.cell*2.4));cn*Ge>Ho&&(cn=Ho/Ge);let Ni=[...s.values()].filter(Z=>Z.plane===2&&Z.id!==ce(L)),Do=Z=>{let Pe=Z*Ge,Oe=fe-Pe;return{x:st-Z/2,y:Oe,width:Z,height:Pe}},jt=Do(cn),Ti=Z=>Ni.some(Pe=>{let Oe={x:Pe.x-(n.pan?.x??0)-Er*i,y:Pe.y-(n.pan?.y??0),width:Pe.width+Er*i*2,height:Pe.height+Ki*i};return Z.x<Oe.x+Oe.width&&Oe.x<Z.x+Z.width&&Z.y<Oe.y+Oe.height&&Oe.y<Z.y+Z.height});for(let Z=cn;Ti(jt)&&Z>_n+1;Z=Math.max(_n,Z*.92))jt=Do(Z);let un=c.findIndex(Z=>Z.id===n.focusId);if(un!==-1){let Z={x:jt.x,y:jt.y},Pe=n.pins[c[un].id],Oe=Pe?{x:Pe.x-Z.x,y:Pe.y-Z.y}:{x:0,y:0},Fo=Math.hypot(Oe.x,Oe.y),Bo=Cr*y.cell,jo=Fo>Bo?Bo/Fo:1,Vo={x:Z.x+Oe.x*jo,y:Z.y+Oe.y*jo},Yn={...c[un],x:Vo.x+(n.pan?.x??0),y:Vo.y+(n.pan?.y??0),width:jt.width,height:jt.height,natural:{width:H,height:pe},screenOf:L,...Pe?{pinned:!0}:{}};c[un]=Yn,s.set(Yn.id,Yn)}}}return{nodes:c,connectors:Rr(e,s,n),width:o.width,height:o.height,...Be?{city:Be.frame}:{}};function Zt(y){let I=n.pins[y.id],_=I?{...y,x:I.x,y:I.y,pinned:!0}:{...y,pinned:!1},Q=n.pan?{..._,x:_.x+n.pan.x,y:_.y+n.pan.y}:_;c.push(Q),s.set(Q.id,Q)}}function bo(e,t,n){let r=e.nodes.find(l=>l.id===t);if(!r||r.screenOf!==void 0)return null;let o={...r,x:n.x,y:n.y,pinned:!0},i=o.x+o.width/2,a=o.y+o.height/2;return{...e,nodes:e.nodes.map(l=>l.id===t?o:l),connectors:e.connectors.map(l=>l.from===t?{...l,x1:i,y1:a}:l.to===t?{...l,x2:i,y2:a}:l)}}function vo(e,t){return t.x===0&&t.y===0?e:{...e,nodes:e.nodes.map(n=>({...n,x:n.x+t.x,y:n.y+t.y})),connectors:e.connectors.map(n=>({...n,x1:n.x1+t.x,y1:n.y1+t.y,x2:n.x2+t.x,y2:n.y2+t.y})),...e.city?{city:{...e.city,pan:{x:t.x,y:t.y}}}:{}}}var ye=(e,t,n)=>e+(t-e)*n;function Ar(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}var Lr=new WeakMap;function Xi(e){let t=Lr.get(e);if(t)return t;let n=new Map,r=new Map;for(let o of e.nodes){n.set(o.id,o);for(let i of o.aggregate?.memberIds??[]){let a=r.get(i);a?a.push(o):r.set(i,[o])}}return t={byId:n,groupsOf:r},Lr.set(e,t),t}var Ir=new WeakMap;function Nr(e,t){let n=Ir.get(t);if(n||Ir.set(t,n=new WeakMap),n.has(e))return n.get(e);let r=qi(e,t);return n.set(e,r),r}function qi(e,t){let{byId:n,groupsOf:r}=Xi(t);if(e.screenOf!==void 0){let a=n.get(ce(e.screenOf));if(a)return{...e,x:a.x,y:a.y,width:a.width,height:a.height}}if(Et(e.id)||$e(e.id)!==null){let a=(e.aggregate?.memberIds??[]).map(d=>n.get(d)).filter(d=>d!==void 0);if(a.length===0)return null;let l=a.map(Ar),c=l.reduce((d,u)=>d+u.x,0)/l.length,s=l.reduce((d,u)=>d+u.y,0)/l.length;return{...e,x:c-e.width/2,y:s-e.height/2}}let o=r.get(e.id)?.find(a=>a.id===ce(e.kind)||a.id===Ee(e.kind));if(!o)return null;let i=Ar(o);return{...e,x:i.x-e.width/2,y:i.y-e.height/2}}function $t(e,t,n){let r=Math.max(0,Math.min(1,n)),o=new Map(e.nodes.map(d=>[d.id,d])),i=new Map(t.nodes.map(d=>[d.id,d])),a=[];for(let[d,u]of o){let h=i.get(d);if(h){a.push(ko(u,h,r,1));continue}let g=Nr(u,t)??u;a.push(ko(u,g,r,1-r))}for(let[d,u]of i){if(o.has(d))continue;let h=Nr(u,e)??u;a.push(ko(h,u,r,r))}let l=new Map(e.connectors.map(d=>[d.id,d])),c=new Map(t.connectors.map(d=>[d.id,d])),s=[];for(let[d,u]of l){let h=c.get(d);s.push(h?{...Qi(u,h,r),opacity:1}:{...u,opacity:1-r})}for(let[d,u]of c)l.has(d)||s.push({...u,opacity:r});return{nodes:a.filter(d=>d.opacity>0).sort((d,u)=>d.id<u.id?-1:d.id>u.id?1:0),connectors:s.filter(d=>d.opacity>0).sort((d,u)=>d.id<u.id?-1:d.id>u.id?1:0),width:ye(e.width,t.width,r),height:ye(e.height,t.height,r),t:r,...Tr(e.city,t.city,r)?{city:Tr(e.city,t.city,r)}:{}}}function Tr(e,t,n){return e?t?{cell:ye(e.cell,t.cell,n),originX:ye(e.originX,t.originX,n),originY:ye(e.originY,t.originY,n),pan:{x:ye(e.pan.x,t.pan.x,n),y:ye(e.pan.y,t.pan.y,n)},extent:{x:ye(e.extent.x,t.extent.x,n),y:ye(e.extent.y,t.extent.y,n),width:ye(e.extent.width,t.extent.width,n),height:ye(e.extent.height,t.extent.height,n)}}:e:t}function ko(e,t,n,r){return{id:t.id,kind:t.kind,plane:ye(e.plane,t.plane,n),x:ye(e.x,t.x,n),y:ye(e.y,t.y,n),width:ye(e.width,t.width,n),height:ye(e.height,t.height,n),pinned:t.pinned,opacity:r,...t.aggregate?{aggregate:t.aggregate}:{},...t.via?{via:t.via}:{},...t.raised?{raised:!0}:{},...t.focused?{focused:!0}:{},...t.opened?{opened:!0}:{},...t.openedRows!==void 0?{openedRows:t.openedRows}:{},...t.compact?{compact:!0}:{},...t.rank?{rank:t.rank}:{},...t.nestedUnder?{nestedUnder:t.nestedUnder}:{},...t.beyond?{beyond:t.beyond}:{},...t.plot?{plot:t.plot}:{},...t.screenOf?{screenOf:t.screenOf}:{},...t.depth===void 0?{}:{depth:ye(e.depth??1,t.depth,n)},...t.natural?{natural:t.natural}:{}}}function Qi(e,t,n){return{...t,x1:ye(e.x1,t.x1,n),y1:ye(e.y1,t.y1,n),x2:ye(e.x2,t.x2,n),y2:ye(e.y2,t.y2,n)}}function En(e){let t=Math.max(0,Math.min(1,e));return t<.5?4*t*t*t:1-(-2*t+2)**3/2}function Zi(e,t){let n=[];for(let o=0;o<e.length;o+=1){let i=e[o],a=e[(o+1)%e.length];if(i.y===a.y)continue;let l=Math.min(i.y,a.y),c=Math.max(i.y,a.y);t<l||t>=c||n.push(i.x+(t-i.y)/(a.y-i.y)*(a.x-i.x))}n.sort((o,i)=>o-i);let r={x0:0,x1:0};for(let o=0;o+1<n.length;o+=2){let i={x0:n[o],x1:n[o+1]};i.x1-i.x0>r.x1-r.x0&&(r=i)}return r}function Ji(e){let t=1/0,n=-1/0;for(let r of e)r.y<t&&(t=r.y),r.y>n&&(n=r.y);return{top:t,bottom:n}}function ea(e){let t=0;for(let n=0;n<e.length;n+=1){let r=e[n],o=e[(n+1)%e.length];t+=r.x*o.y-o.x*r.y}return Math.abs(t)/2}function ta(e){let t=0,n=0,r=0;for(let o=0;o<e.length;o+=1){let i=e[o],a=e[(o+1)%e.length],l=i.x*a.y-a.x*i.y;t+=l,n+=(i.x+a.x)*l,r+=(i.y+a.y)*l}if(Math.abs(t)<1e-9){let o=e.reduce((i,a)=>({x:i.x+a.x,y:i.y+a.y}),{x:0,y:0});return{x:o.x/e.length,y:o.y/e.length}}return{x:n/(3*t),y:r/(3*t)}}function na(e,t){let{room:n,height:r,size:o,floor:i,measure:a=Jn,lines:l=2}=t,c=(p,f)=>p.every(m=>a(m,f)<=n)&&p.length*f*1.15<=r;if(c([e],o))return{lines:[e],fontSize:o,whole:!0};let s=e.split(/\s+/);if(l>1&&s.length>1){let p=1,f=1/0,m=0;for(let R=0;R<s.length-1;R+=1){m+=s[R].length+1;let O=Math.abs(m-e.length/2);O<f&&(f=O,p=R+1)}let b=[s.slice(0,p).join(" "),s.slice(p).join(" ")];if(c(b,o))return{lines:b,fontSize:o,whole:!0};for(let R=o;R>=i;R-=o*.06)if(c(b,R))return{lines:b,fontSize:R,whole:!0}}for(let p=o;p>=i;p-=o*.06)if(c([e],p))return{lines:[e],fontSize:p,whole:!0};let d=a(e,i)/Math.max(1,e.length),u=Math.floor(n/d)-1;if(u<4||i*1.15>r)return null;let h=e.slice(0,u),g=h.lastIndexOf(" ");return{lines:[`${g>3?h.slice(0,g):h}\u2026`],fontSize:i,whole:!1}}var oa=(e,t)=>e.x0<t.x1&&t.x0<e.x1&&e.y0<t.y1&&t.y0<e.y1;var q=ee(He(),1);var De=ee(He(),1);var ra=520;function ia(){return typeof window>"u"||!window.matchMedia?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches}function $r(e,t={}){let n=t.duration??ra,r=(t.enabled??!0)&&!ia(),o=(0,De.useRef)(e),[i,a]=(0,De.useState)(()=>$t(e,e,1)),l=(0,De.useRef)(i),c=(0,De.useRef)(null),s=(0,De.useRef)(null);return(0,De.useEffect)(()=>{if(!r||typeof requestAnimationFrame>"u"){o.current=e;let f=$t(e,e,1);if(l.current=f,a(f),typeof requestAnimationFrame>"u")return;let m=requestAnimationFrame(()=>{let b=$t(e,e,1);l.current=b,a(b)});return()=>cancelAnimationFrame(m)}let d=performance.now(),h=s.current!==null&&l.current.t<1&&d-s.current<n?s.current:d;s.current=h;let g=En(Math.min(1,(d-h)/n)),x=o.current,p=f=>{let m=Math.min(1,(f-h)/n),b=g>=1?1:(En(m)-g)/(1-g),R=$t(x,e,Math.max(0,b));l.current=R,a(R),m<1?c.current=requestAnimationFrame(p):(s.current=null,o.current=e,c.current=requestAnimationFrame(()=>{let O=$t(e,e,1);l.current=O,a(O),c.current=null}))};return c.current=requestAnimationFrame(p),()=>{c.current!==null&&cancelAnimationFrame(c.current);let f=l.current;o.current={...e,...f.city?{city:f.city}:{},nodes:f.nodes.map(m=>({...m,plane:Math.round(m.plane)})),connectors:f.connectors}}},[e,n,r]),i}function Hr(e=1100){let{store:t}=le(),[n,r]=(0,De.useState)(()=>new Set);return(0,De.useEffect)(()=>{let o=null,i=t.subscribe(a=>{r(new Set(a.touched)),o&&clearTimeout(o),o=setTimeout(()=>r(new Set),e)});return()=>{i(),o&&clearTimeout(o)}},[t,e]),n}var aa={marks:new Map,acts:[]};function Dr(e=4e3){let{store:t}=le(),[n,r]=(0,De.useState)(aa);return(0,De.useEffect)(()=>{let o=null,i=t.subscribe((a,l)=>{r(c=>{let s=new Map(c.marks),d=[...c.acts];for(let u of l){if(u.undoes!==void 0){let x=d.find(f=>f.batch===u.undoes||f.wrote.length>0),p=d.filter(f=>u.writes.some(m=>f.wrote.includes(m)));for(let f of p.length>0?p:x?[x]:[]){for(let m of f.wrote)s.delete(m);d=d.filter(m=>m.batch!==f.batch)}continue}if(u.author.kind!=="agent")continue;let h=u.author.id??"the seat";for(let x of u.writes)s.set(x,h);d.find(x=>x.batch===u.batch)?d=d.map(x=>x.batch===u.batch?{...x,wrote:[...new Set([...x.wrote,...u.writes])]}:x):d=[{batch:u.batch,who:h,intent:u.batchIntent??u.intent,at:u.at,wrote:[...u.writes]},...d].slice(0,12)}return s.size===c.marks.size&&d===c.acts&&s.size===0?c:{marks:s,acts:d}}),o&&clearTimeout(o),o=setTimeout(()=>r(c=>c.marks.size===0?c:{...c,marks:new Map}),e)});return()=>{i(),o&&clearTimeout(o)}},[t,e]),n}var Ht=ee(be(),1),Xe=16;function Fr({marks:e,questions:t=[],whereIs:n,stageRef:r,width:o,height:i}){if(e.size===0&&t.length===0)return null;let a=r.current,l=a?.getBoundingClientRect()??null,c=[];for(let[d,u]of e){let h=null;if(a&&l&&typeof CSS<"u"){let f=a.querySelector(`[data-graview-pick="${CSS.escape(d)}"]`)?.getBoundingClientRect();f&&f.width>0&&f.height>0&&(h={x:f.left-l.left,y:f.top-l.top,width:f.width,height:f.height})}if(h??=n(d),!h)continue;let g=Math.min(Math.max(h.x+h.width-Xe/2,Xe/2),o-Xe/2),x=Math.min(Math.max(h.y-Xe/4,Xe/2),i-Xe/2);c.push({id:d,who:u,x:g,y:x})}let s=[];for(let d of t){let u=n(d.id);u&&s.push({...d,x:Math.min(Math.max(u.x+u.width/2,Xe),o-Xe),y:Math.min(Math.max(u.y-Xe/2,Xe),i-Xe)})}return c.length===0&&s.length===0?null:(0,Ht.jsxs)("div",{className:"graview-seat-marks","data-testid":"seat-marks","data-graview-seat-marks":c.length,children:[c.map(({id:d,who:u,x:h,y:g})=>(0,Ht.jsx)("span",{className:"graview-seat-mark","data-testid":"seat-mark","data-graview-seat-mark":d,"data-graview-seat-who":u,title:`${u} just changed this`,"aria-hidden":"true",style:{left:h,top:g,"--graview-hue":Mt(u)},children:"\u25C6"},d)),s.map(d=>(0,Ht.jsxs)("span",{className:"graview-seat-asking","data-testid":"seat-question","data-graview-seat-asking":d.id,title:d.asks,style:{left:d.x,top:d.y},children:[(0,Ht.jsx)("span",{"aria-hidden":"true",children:"?"}),(0,Ht.jsx)("span",{className:"graview-seat-asking-said",children:d.asks})]},`asking:${d.id}`))]})}var lt=ee(He(),1);var ke=ee(be(),1);function sa(e,t,n={x:0,y:0}){let r=(o,i)=>{let a=ve(o,i,t.cell);return{x:t.originX+n.x+a.x,y:t.originY+n.y+a.y}};return[r(e.col,e.row),r(e.col+e.side,e.row),r(e.col+e.side,e.row+e.side),r(e.col,e.row+e.side)]}var An=e=>e.map(t=>`${t.x.toFixed(1)},${t.y.toFixed(1)}`).join(" ");function Br({frame:e,width:t,height:n,pan:r,brand:o,pinned:i,swallowed:a,onFocus:l}){let{selection:c,store:s,emphasis:d}=le(),u=wn(),h=e.city,g=e.nodes.filter(k=>k.plot!==void 0&&Math.round(k.plane)===2),x=h?.cell??0,p=(0,lt.useRef)(l);p.current=l;let f=(0,lt.useCallback)(k=>!p.current||a?.current?!1:(p.current(k),!0),[a]),m=`${x}|${g.map(k=>`${k.id}:${k.plot.col},${k.plot.row},${k.plot.side}`).join(";")}`,b=(0,lt.useMemo)(()=>{if(!h)return[];let k={cell:x,originX:0,originY:0},w=new Map;for(let M of g){let C=$e(M.id);C!==null&&M.plot&&w.set(C,M.plot)}return lo(s.schema,w).map(M=>({...M,d:ha(w.get(M.from),w.get(M.to),k,{x:0,y:0}).map((C,B)=>`${B===0?"M":"L"} ${C.x.toFixed(1)} ${C.y.toFixed(1)}`).join(" ")}))},[m,s.schema]),R=(0,lt.useRef)(new Map),O=new Map;for(let k of g){let w=k.aggregate?.memberIds??[],M=`${x}|${k.plot.col},${k.plot.row},${k.plot.side}|${w.join(",")}`,C=R.current.get(k.id);if(C&&C.key===M){O.set(k.id,C);continue}let B={cell:x,originX:0,originY:0},A={x:0,y:0},{buildings:$,rest:D}=uo(k.plot,w),H=sa(k.plot,B,A);O.set(k.id,{key:M,tile:An(H),front:H[2],rest:D,buildings:$.map(Y=>({id:Y.id,...la(Y,B,A)}))})}if(R.current=O,!h)return null;let E={position:"absolute",left:0,top:0,pointerEvents:"none",overflow:"visible"},S=c.join(`
4
+ `),j=u.join(`
5
+ `);return(0,ke.jsx)("svg",{className:"graview-plots","aria-hidden":"true","data-graview-world":"",width:t,height:n,style:E,"data-graview-plots":g.length,children:(0,ke.jsxs)("g",{transform:`translate(${(h.originX+r.x).toFixed(1)} ${(h.originY+r.y).toFixed(1)})`,children:[(0,ke.jsx)("g",{className:"graview-roads","data-graview-roads":b.length,children:b.map(k=>k.d.includes("L")?(0,ke.jsxs)("g",{className:"graview-road","data-graview-road":k.edges.join(","),"data-graview-from":ce(k.from),"data-graview-to":ce(k.to),"data-graview-lit":d!==null&&k.edges.includes(d)?"":void 0,children:[(0,ke.jsx)("path",{className:"graview-road-edge",d:k.d}),(0,ke.jsx)("path",{className:"graview-road-bed",d:k.d})]},`${k.from}|${k.to}`):null)}),g.map(k=>(0,ke.jsx)(da,{id:k.id,hue:Math.round(Mt(k.kind,o?.accents)),drawing:O.get(k.id),pinned:i?.has(k.id)??!1,chosenKey:S,flaggedKey:j,press:f},k.id))]})})}var da=(0,lt.memo)(function({id:t,hue:n,drawing:r,pinned:o,chosenKey:i,flaggedKey:a,press:l}){let c=new Set(i.split(`
6
+ `)),s=new Set(a.split(`
7
+ `));return(0,ke.jsxs)("g",{className:"graview-plot","data-graview-plot":t,"data-graview-pinned":o?"":void 0,style:{"--graview-hue":n},children:[(0,ke.jsx)("polygon",{className:"graview-plot-tile",points:r.tile,onClick:d=>{l(t)&&d.stopPropagation()}}),r.buildings.length>0?(0,ke.jsxs)("g",{className:"graview-village","data-graview-village":r.buildings.length,"data-graview-rest":r.rest||void 0,children:[r.buildings.map(d=>(0,ke.jsxs)("g",{className:"graview-building","data-graview-building":d.id,"data-graview-flagged":s.has(d.id)?"":void 0,"data-graview-selected":c.has(d.id)?"":void 0,children:[(0,ke.jsx)("polygon",{className:"graview-iso-left",points:d.left}),(0,ke.jsx)("polygon",{className:"graview-iso-right",points:d.right}),(0,ke.jsx)("polygon",{className:"graview-iso-roof",points:d.roof})]},d.id)),r.rest>0?(0,ke.jsxs)("text",{className:"graview-village-rest",x:r.front.x,y:r.front.y-4,textAnchor:"middle",children:["+",r.rest]}):null]}):null]})});function la(e,t,n){let r=e.footprint/2,o=(g,x,p=0)=>{let f=ve(g,x,t.cell);return{x:t.originX+n.x+f.x,y:t.originY+n.y+f.y-p}},i=e.footprint*t.cell*.5*e.height,a=o(e.col-r,e.row-r,i),l=o(e.col+r,e.row-r,i),c=o(e.col+r,e.row+r,i),s=o(e.col-r,e.row+r,i),d=o(e.col+r,e.row+r),u=o(e.col-r,e.row+r),h=o(e.col+r,e.row-r);return{roof:An([a,l,c,s]),left:An([s,c,d,u]),right:An([c,l,h,d]),top:a}}function ca(e,t,n){let r=e.x-t.originX-n.x,o=e.y-t.originY-n.y;return{col:r/t.cell+2*o/t.cell,row:2*o/t.cell-r/t.cell}}var Pn=(e,t,n,r)=>{let{col:o,row:i}=ca(e,n,r);return o>=t.col&&o<=t.col+t.side&&i>=t.row&&i<=t.row+t.side},Cn=(e,t,n)=>({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n});function ua(e,t){let n=e.col+e.side/2,r=e.row+e.side/2,o=t.col+t.side/2,i=t.row+t.side/2,a=f=>Math.floor(f.row/5),l=f=>Math.floor(f.col/5),c=a(e),s=a(t),d=l(e),u=l(t),h=s>c?c*5+5-.5:s<c?c*5-.5:c*5+5-.5,g=u>d?u*5-.5:u<d?u*5+5-.5:u*5-.5,x=[{col:n,row:r},{col:n,row:h},{col:g,row:h},{col:g,row:i},{col:o,row:i}],p=[];for(let f of x){let m=p[p.length-1];m&&Math.abs(m.col-f.col)<1e-9&&Math.abs(m.row-f.row)<1e-9||p.push(f)}for(let f=p.length-2;f>0;f--){let m=p[f-1],b=p[f],R=p[f+1],O=Math.abs(m.col-b.col)<1e-9&&Math.abs(b.col-R.col)<1e-9,E=Math.abs(m.row-b.row)<1e-9&&Math.abs(b.row-R.row)<1e-9;(O||E)&&p.splice(f,1)}return p}function ha(e,t,n,r){let o=ua(e,t).map(l=>{let c=ve(l.col,l.row,n.cell);return{x:n.originX+r.x+c.x,y:n.originY+r.y+c.y}}),i=[],a=!1;for(let l=0;l<o.length-1;l++){let c=o[l],s=o[l+1];if(!a){if(Pn(s,e,n,r))continue;let d=0,u=1;for(let h=0;h<12;h++){let g=(d+u)/2;Pn(Cn(c,s,g),e,n,r)?d=g:u=g}i.push(Cn(c,s,u)),a=!0}if(Pn(s,t,n,r)){let d=0,u=1;for(let h=0;h<12;h++){let g=(d+u)/2;Pn(Cn(c,s,g),t,n,r)?u=g:d=g}return i.push(Cn(c,s,d)),i}i.push(s)}return i}var V=ee(be(),1);function fa({hue:e,mode:t}){let n=t==="docked";return(0,V.jsxs)("svg",{viewBox:"0 0 32 38","aria-hidden":"true",children:[(0,V.jsxs)("g",{fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinejoin:"round",strokeLinecap:"round",children:[(0,V.jsx)("line",{x1:"16",y1:"3.5",x2:"16",y2:"7"}),(0,V.jsx)("circle",{cx:"16",cy:"2.6",r:"1.5",fill:"none"}),(0,V.jsx)("path",{d:"M8 16 V12.5 C8 8.5 11.5 7 16 7 C20.5 7 24 8.5 24 12.5 V16 Z",fill:"currentColor",fillOpacity:"0.1"}),t==="refused"?(0,V.jsx)("line",{x1:"11",y1:"12.5",x2:"21",y2:"12.5",strokeWidth:"2"}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)("rect",{x:"10.2",y:"10.2",width:"11.6",height:"4.6",rx:"2.3",fill:"currentColor",fillOpacity:"0.14",strokeWidth:"1"}),(0,V.jsx)("circle",{cx:"13.4",cy:"12.5",r:"1.25",fill:"currentColor",stroke:"none",opacity:n?.45:1}),(0,V.jsx)("circle",{cx:"18.6",cy:"12.5",r:"1.25",fill:"currentColor",stroke:"none",opacity:n?.45:1}),t==="reading"?(0,V.jsx)("line",{x1:"10.2",y1:"12.5",x2:"21.8",y2:"12.5",strokeWidth:"0.8",opacity:"0.7"}):null]}),(0,V.jsx)("line",{x1:"16",y1:"16",x2:"16",y2:"18.5"}),(0,V.jsx)("polygon",{points:"16,18.5 24,22.5 16,26.5 8,22.5",fill:"currentColor",fillOpacity:"0.22"}),(0,V.jsx)("polygon",{points:"8,22.5 16,26.5 16,33.5 8,29.5",fill:"currentColor",fillOpacity:"0.08"}),(0,V.jsx)("polygon",{points:"24,22.5 16,26.5 16,33.5 24,29.5",fill:"currentColor",fillOpacity:"0.3"}),t==="writing"?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)("polyline",{points:"24,24 28.5,20.5"}),(0,V.jsx)("line",{x1:"27.5",y1:"19",x2:"30",y2:"21.5",strokeWidth:"1.8"})]}):(0,V.jsx)("line",{x1:"24",y1:"24",x2:"26.5",y2:"29"}),(0,V.jsx)("line",{x1:"8",y1:"24",x2:"5.5",y2:"29"}),(0,V.jsx)("path",{d:"M9.5 33.5 v2.2 h4"}),(0,V.jsx)("path",{d:"M22.5 33.5 v2.2 h-4"})]}),(0,V.jsx)("title",{children:`robot, ${t}`})]})}function ya({hue:e}){return(0,V.jsxs)("svg",{viewBox:"0 0 22 24","aria-hidden":"true",style:{color:`hsl(${Math.round(e)} 50% 48%)`},children:[(0,V.jsxs)("g",{fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinejoin:"round",strokeLinecap:"round",children:[(0,V.jsx)("circle",{cx:"11",cy:"6",r:"4.2"}),(0,V.jsx)("path",{d:"M3 23 C3 15.5 6 13 11 13 C16 13 19 15.5 19 23"})]}),(0,V.jsx)("title",{children:"somebody"})]})}function jr({width:e,whereIs:t}){let{who:n,following:r,follow:o}=le(),i=cr([...n.values()],t,e);return i.length===0?null:(0,V.jsx)("div",{className:"graview-occupants","data-testid":"occupants","data-graview-occupants":i.length,children:i.map((a,l)=>{if(a.kind==="over")return(0,V.jsx)("div",{className:"graview-presence-over","data-testid":"presence-over","data-graview-over-by":a.presence.participant,style:{left:a.box.x-3,top:a.box.y-3,width:a.box.width+6,height:a.box.height+6,"--graview-hue":a.presence.hue}},`over:${a.presence.participant}`);if(a.kind==="count")return(0,V.jsxs)("span",{className:"graview-figure-count","data-testid":"presence-count","data-graview-at":a.at,style:{left:a.point.x,top:a.point.y},title:`${a.n} more here`,children:["+",a.n]},`count:${a.at}:${l}`);let c=a.presence.hue,s=Qo(a.presence)||"somebody";if(a.kind==="edge")return(0,V.jsxs)("button",{type:"button",className:"graview-figure-edge","data-testid":"presence-edge","data-graview-person":a.presence.participant,style:{left:Math.max(8,a.point.x-120),top:a.point.y},onClick:()=>o(a.presence.participant),"aria-label":`${s} is somewhere else \u2014 press to go where they are`,children:["\u2192 ",s]},`edge:${a.presence.participant}`);if(a.kind==="robot")return(0,V.jsxs)("div",{className:"graview-figure","data-graview-figure":`theirs:${a.presence.participant}`,"data-graview-theirs":"","data-graview-mode":a.mode,"data-graview-at":a.presence.robot?.at??"",style:{transform:`translate(${a.point.x.toFixed(1)}px, ${a.point.y.toFixed(1)}px)`,"--graview-hue":c},children:[(0,V.jsx)("span",{className:"graview-figure-body",role:"img","aria-label":`${s}'s agent \u2014 ${a.mode}`,style:{cursor:"default"},children:(0,V.jsx)(fa,{hue:c,mode:a.mode})}),(0,V.jsxs)("span",{className:"graview-figure-name",children:[s,"'s agent"]})]},`robot:${a.presence.participant}`);let d=r?.participant===a.presence.participant;return(0,V.jsxs)("div",{className:"graview-figure","data-graview-figure":a.presence.participant,"data-graview-person":"","data-graview-at":a.at,"data-graview-audience":a.audience?"":void 0,"data-graview-followed":d?"":void 0,style:{transform:`translate(${a.point.x.toFixed(1)}px, ${a.point.y.toFixed(1)}px)`,"--graview-hue":c},children:[(0,V.jsx)("button",{type:"button",className:"graview-figure-body","aria-label":`${s} is here${d?". Press to stop following":". Press to go where they go"}`,"aria-pressed":d,onClick:u=>{u.stopPropagation(),o(d?null:a.presence.participant)},onPointerDown:u=>u.stopPropagation(),children:(0,V.jsx)(ya,{hue:c})}),(0,V.jsx)("span",{className:"graview-figure-name",children:s})]},`person:${a.presence.participant}`)})})}var tn=ee(be(),1),Vr={left:"\u2190",right:"\u2192",top:"\u2191",bottom:"\u2193"},ga=36,Wr=56;function _r({result:e,schema:t,onGo:n}){let r=xo(e);if(r.length===0)return null;let o=[];for(let i of["left","right","top","bottom"]){let a=i==="left"||i==="right"?e.height:e.width,l=-1/0,c=r.filter(s=>s.side===i).sort((s,d)=>s.along-d.along);for(let s of c){let d=Math.max(Wr,Math.min(a-Wr,Math.max(s.along,l+ga)));l=d;let u=_t(t,s.kind),h=i==="left"?{left:6,top:d,transform:"translateY(-50%)"}:i==="right"?{right:6,top:d,transform:"translateY(-50%)"}:i==="top"?{top:6,left:d,transform:"translateX(-50%)"}:{bottom:6,left:d,transform:"translateX(-50%)"};o.push((0,tn.jsx)("button",{type:"button",className:"graview-edge-sign","data-graview-past-edge":s.id,"aria-label":`${u}, past the ${i} edge \u2014 bring it into view`,title:`${u} is past the ${i} edge`,tabIndex:-1,onPointerDown:g=>g.stopPropagation(),onClick:g=>{g.stopPropagation(),n(s.by)},style:{...ma,...h},children:i==="right"||i==="bottom"?`${u} ${Vr[i]}`:`${Vr[i]} ${u}`},s.id))}}return(0,tn.jsx)(tn.Fragment,{children:o})}var ma={position:"absolute",zIndex:Te.lines,minHeight:28,maxWidth:"40%",padding:"3px 10px",font:"inherit",fontSize:"0.75rem",letterSpacing:"0.04em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",color:"var(--graview-ink)",background:"var(--graview-panel)",border:"1px solid var(--graview-edge)",borderRadius:6,boxShadow:"0 2px 8px rgb(0 0 0 / 0.12)",cursor:"pointer"};var bt=ee(He(),1),pa=180;function Yr({view:e,result:t,frame:n,panned:r,closer:o,screenId:i,setCamera:a}){let l=(0,bt.useRef)(new Map),c=(0,bt.useRef)(e.overview??!1),s=(0,bt.useRef)(null);if((0,bt.useEffect)(()=>{if(!e.overview||!i||!t.city){if(c.current&&!e.overview)return;a(E=>E.x===0&&E.y===0?E:{x:0,y:0});return}let d=t.nodes.find(E=>E.id===i);if(!d)return;let u=o>1&&d.screenOf?t.nodes.find(E=>E.id===ce(d.screenOf)):void 0,h=u?{x:Math.min(d.x,u.x),y:Math.min(d.y,u.y),width:Math.max(d.x+d.width,u.x+u.width)-Math.min(d.x,u.x),height:Math.max(d.y+d.height,u.y+u.height)-Math.min(d.y,u.y)}:d;if(h.x>=0&&h.y>=0&&h.x+h.width<=t.width&&h.y+h.height<=t.height&&!u)return;let x=24,p=(E,S,j)=>E<x?x-E:E+S>j-x?j-x-(E+S):0,f=wt(t),m=e.pan??{x:0,y:0},b=u?r.x+(t.width/2-(h.x+h.width/2)):r.x+p(h.x,h.width,t.width),R=t.height/2-(h.y+h.height/2),O=u?r.y+(d.y+R<x?x-d.y:R):r.y+p(h.y,h.height,t.height);a({x:(u?b:Math.max(-f.x,Math.min(f.x,b)))-m.x,y:(u?O:Math.max(-f.y,Math.min(f.y,O)))-m.y})},[i,e.overview,o]),n.city){let d=new Map;for(let u of n.nodes){if(!u.plot||Math.round(u.plane)!==2)continue;let h=ve(u.plot.col+u.plot.side/2,u.plot.row+u.plot.side/2,n.city.cell);d.set(u.id,{x:n.city.originX+r.x+h.x,y:n.city.originY+r.y+h.y})}l.current=d}return(0,bt.useEffect)(()=>{let d=e.overview??!1,u=c.current&&!d;if(c.current=d,d&&s.current&&(clearTimeout(s.current),s.current=null),!u)return;let h=e.focusId?xt(e.focusId)[0]:void 0,g=h?l.current.get(ce(h)):void 0,x=t.nodes.find(p=>p.id===e.focusId);if(!g||!x){a({x:0,y:0});return}a({x:g.x-(x.x+x.width/2),y:g.y-(x.y+x.height/2)}),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{s.current=null,a({x:0,y:0})},pa)},[e.overview]),(0,bt.useEffect)(()=>()=>{s.current&&clearTimeout(s.current)},[]),{gliding:()=>s.current!==null}}var se=ee(He(),1);function zr(){let[e,t]=(0,se.useState)(null),n=(0,se.useRef)(null),r=(0,se.useRef)(0),o=(0,se.useCallback)(a=>{n.current=a,r.current===0&&(r.current=requestAnimationFrame(()=>{r.current=0,t(n.current)}))},[]),i=(0,se.useCallback)(()=>{r.current!==0&&cancelAnimationFrame(r.current),r.current=0;let a=n.current;return n.current=null,a&&t(null),a},[]);return{held:e,place:o,release:i}}function Kr({stage:e,pan:t,setView:n,settled:r}){let o=(0,se.useRef)({x:0,y:0}),i=(0,se.useRef)(0),a=(0,se.useRef)(!1),l=(0,se.useRef)(r);l.current=r;let c=(0,se.useCallback)(()=>[...e.current?.querySelectorAll("[data-graview-world]")??[]],[e]),s=(0,se.useCallback)(()=>{i.current===0&&(i.current=requestAnimationFrame(()=>{i.current=0;let{x,y:p}=o.current,f=x===0&&p===0?"":`translate3d(${x}px, ${p}px, 0)`;for(let m of c())m.style.transform=f}))},[c]),d=(0,se.useCallback)(()=>{a.current=!1;for(let x of c())x.style.transform="";l.current()},[c]),u=(0,se.useCallback)((x,p)=>{o.current={x:x.x-p.x,y:x.y-p.y},s()},[s]),h=(0,se.useCallback)(()=>{let{x,y:p}=o.current;return x===0&&p===0?!1:(o.current={x:0,y:0},a.current=!0,n(f=>{let m=f.pan??{x:0,y:0};return pt(f,{x:m.x+x,y:m.y+p})}),window.setTimeout(()=>{a.current&&d()},300),!0)},[n,d]);(0,se.useLayoutEffect)(()=>{a.current&&d()},[t,d]);let g=(0,se.useCallback)(()=>o.current,[]);return{shiftTo:u,settle:h,settling:a,offset:g}}var xa=4;function Gr({view:e,panned:t,limit:n,panWithin:r,moveByTransform:o,setView:i,setDragging:a,noteMoved:l,shift:c,district:s}){let d=(0,se.useRef)(!1),u=(0,se.useRef)(null),h=m=>{let b=e.pan??{x:0,y:0};u.current={kind:"pan",fromX:m.clientX,fromY:m.clientY,baseX:b.x,baseY:b.y,moved:!1}};return{onGroundDown:m=>{m.button===0&&(m.target.closest("[data-graview-view]")||h(m))},onCardDown:(m,b)=>{if(b.button===0){if(m.screenOf!==void 0&&!b.target.closest("[data-graview-grip]")){h(b);return}u.current={kind:"card",id:m.id,fromX:b.clientX,fromY:b.clientY,baseX:m.x-t.x,baseY:m.y-t.y,moved:!1}}},onDragMove:m=>{let b=u.current;if(!b)return;let R=m.clientX-b.fromX,O=m.clientY-b.fromY;if(!b.moved){if(Math.hypot(R,O)<xa)return;b.moved=!0,a(!0),m.currentTarget.setPointerCapture(m.pointerId)}if(b.kind==="pan"){let E=r(n(),{x:b.baseX+R,y:b.baseY+O});o?c.shiftTo(E,e.pan??{x:0,y:0}):i(S=>pt(S,E))}else b.id&&s.place({id:b.id,x:b.baseX+R,y:b.baseY+O})},onDragUp:()=>{c.settle();let m=s.release();m&&i(b=>Kt(b,m.id,{x:m.x,y:m.y})),u.current?.moved&&(d.current=!0,setTimeout(()=>d.current=!1,0),l()),u.current=null,!c.settling.current&&a(!1)},swallow:d}}function Ur({stage:e,view:t,setView:n}){let r=(0,se.useRef)({view:t,charge:0,coolUntil:0,lastScale:1});r.current.view=t;let o=(0,se.useRef)(()=>{}),i=(0,se.useRef)(()=>{});return(0,se.useEffect)(()=>{let a=e.current;if(!a)return;let l=(u,h)=>{let g=r.current;if(h<g.coolUntil)return;let x=g.view.overview??!1;u!==x&&(g.coolUntil=h+600,g.charge=0,n(zt(g.view,u)))},c=u=>{let h=r.current,g=h.view.overview??!1;if(u.ctrlKey){if(u.preventDefault(),!g){if(h.charge+=u.deltaY,Math.abs(h.charge)<60)return;h.charge>0?l(!0,performance.now()):h.charge=0;return}o.current(Math.exp(-u.deltaY*.004),u.clientX,u.clientY);return}!g||u.target?.closest("[data-graview-view], .graview-scroll, [data-graview-overlay], .graview-zoom")||(u.preventDefault(),i.current(-u.deltaX,-u.deltaY))},s=u=>{u.preventDefault(),r.current.lastScale=1},d=u=>{u.preventDefault();let h=r.current,g=u.scale??1;if(!(h.view.overview??!1)){g<.72&&l(!0,performance.now());return}let x=g/(h.lastScale||1);h.lastScale=g;let p=u;o.current(x,p.clientX,p.clientY)};return a.addEventListener("wheel",c,{passive:!1}),a.addEventListener("gesturestart",s),a.addEventListener("gesturechange",d),()=>{a.removeEventListener("wheel",c),a.removeEventListener("gesturestart",s),a.removeEventListener("gesturechange",d)}},[n,e]),{zoomAbout:o,panBy:i}}var Xr={directed:"You",autonomous:"An agent","co-edited":"You and an agent",rule:"A rule"};function So(e,t){let n=new Set(e.map(o=>o.id)),r=new Set;for(let o of t){if(n.has(o)){r.add(o);continue}let i=e.find(a=>a.aggregate?.memberIds.includes(o));i&&r.add(i.id)}return r}function Mo(e){return e.emphasized?e.stressed?.95:.08:e.anyChosen?e.mine?.9:.12:e.touches?Math.max(.34,.9-.09*Math.max(0,(e.siblings??1)-1)):.12}function Ro(e){return e.edgeChosen?.9:e.lit?.78:e.own*(e.anyLit?e.kit.dim:e.kit.rest)}function qe(e,t){if(!e)return null;let n=Math.max(0,Math.min(2,Math.floor(e.plane))),r=Math.max(0,Math.min(2,Math.ceil(e.plane))),{scale:o}=n===r?Ue(n,t):pn(Ue(n,t),Ue(r,t),e.plane-n);return{x:e.x,y:e.y,width:e.width*o,height:e.height*o}}function Ln(e,t){if(typeof getComputedStyle>"u"||getComputedStyle(e).visibility==="hidden")return null;let n=-1/0,r=-1/0,o=1/0,i=1/0,a=e.getBoundingClientRect();n=Math.max(n,a.left),r=Math.max(r,a.top),o=Math.min(o,a.right),i=Math.min(i,a.bottom);let l=e.parentElement;for(;l&&l!==t;){let s=getComputedStyle(l);if(s.overflowX!=="visible"||s.overflowY!=="visible"){let d=l.getBoundingClientRect();s.overflowX!=="visible"&&(n=Math.max(n,d.left),o=Math.min(o,d.right)),s.overflowY!=="visible"&&(r=Math.max(r,d.top),i=Math.min(i,d.bottom))}l=l.parentElement}if(o-n<=2||i-r<=2)return null;let c=t.getBoundingClientRect();return{x:n-c.left,y:r-c.top,width:o-n,height:i-r}}function Qe(e,t,n){if(!e||typeof document>"u")return null;let r=e.querySelector(`[data-graview-view="${CSS.escape(t)}"]`);if(!r)return null;let o=(n?r.querySelector(".graview-kind-block"):null)??r.querySelector('[data-graview-primitive="panel"], .graview-kind-face, .graview-kind-card')??r;return Ln(o,e)}function In(e,t,n,r,o){let i=s=>e.nodes.find(d=>d.id===s);if(o.startsWith("screen:")){let s=o.slice(7),d=e.nodes.find(f=>f.screenOf===s);if(!d)return null;let u=Qe(t,d.id,!1)??qe(d,n);if(!u)return null;let h=e.nodes.find(f=>f.id===ce(s)),g=h?qe(h,n):null,x=u.y+u.height,p=g?Math.max(20,g.y-x):Math.max(20,u.height*.18);return{x:u.x,y:x,width:u.width,height:p}}let a=i(o),l=$e(o);if(!a&&l!==null&&(a=i(Ee(l))),!a&&Et(o)){let[s]=xt(o);s&&(a=i(ce(s)))}if(!a){let s=r.places().find(d=>d.as===o);s&&(a=i(Ee(s.kind))??i(ce(s.kind)))}if(a||(a=[...e.nodes].filter(s=>s.aggregate?.memberIds.includes(o)).sort((s,d)=>s.plane-d.plane)[0]),!a)return null;let c=e.city!==void 0;return Qe(t,a.id,c&&a.aggregate!==void 0&&Math.round(a.plane)===2)??qe(a,n)}var ct=ee(He(),1);var te=ee(be(),1);function Qr({kinds:e}){let{store:t}=le(),{view:n,go:r}=oo(),o=(0,ct.useRef)(null),i=io("districts",{align:"start"}),a=i.open,l=h=>_t(t.schema,h),c=h=>t.graph.allNodes().filter(g=>g.kind===h).length,s=h=>!n.overview&&n.focusId===Ee(h),d=e.filter(h=>!s(h)),u=h=>{i.setOpen(!1);let g=o.current?.querySelector(".graview-beyond-more")??null;s(h)||r(Ot(n,Ee(h))),g?.focus({preventScroll:!0});let x=`[data-graview-view="${Ee(h)}"][tabindex], [data-graview-view="${ce(h)}"][tabindex]`,p=40,f=()=>{let m=document.querySelector(x);m?m.focus({preventScroll:!0}):--p>0&&requestAnimationFrame(f)};requestAnimationFrame(f)};return(0,te.jsxs)("div",{ref:o,className:"graview-beyond","data-graview-beyond":e.length,"data-graview-beyond-open":a?"":void 0,children:[(0,te.jsxs)("button",{type:"button",className:"graview-beyond-more","data-testid":"beyond-more",...i.trigger,"aria-haspopup":"menu",title:`${d.length} more district${d.length===1?"":"s"} \u2014 press to see them`,onPointerDown:h=>h.stopPropagation(),onClick:h=>{h.stopPropagation(),i.toggle()},children:[(0,te.jsxs)("span",{className:"graview-beyond-count",children:["+",d.length]}),(0,te.jsx)("span",{className:"graview-beyond-word",children:"more"}),(0,te.jsx)("span",{className:"graview-beyond-chevron","aria-hidden":"true",children:a?"\u25BE":"\u25B4"})]}),a?(0,te.jsx)("ul",{...i.pane,className:"graview-beyond-list",role:"menu","aria-label":"The other districts","data-testid":"beyond-list",style:ro,onPointerDown:h=>h.stopPropagation(),children:e.map(h=>(0,te.jsx)("li",{role:"none",children:(0,te.jsxs)("button",{type:"button",role:"menuitem","data-graview-pick":ce(h),"aria-current":s(h)?"location":void 0,title:s(h)?`${l(h)} \u2014 where you are`:`Go to ${l(h)}`,onPointerDown:g=>g.stopPropagation(),onClick:g=>{g.stopPropagation(),u(h)},children:[(0,te.jsx)("span",{className:"graview-beyond-name",children:l(h)}),(0,te.jsx)("span",{className:"graview-beyond-tally",children:s(h)?"here":c(h)})]})},h))}):null]})}function wa(e,t){if(e===t)return!0;let n=Object.keys(e);return n.length!==Object.keys(t).length?!1:n.every(r=>r==="x"||r==="y"||Eo(e[r],t[r]))}function Eo(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||typeof t!="object"||e===null||t===null||Array.isArray(e)!==Array.isArray(t)||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t))return!1;let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==Array.prototype)return!1;if(Array.isArray(e)){let o=t;if(e.length!==o.length)return!1;for(let i=0;i<e.length;i++)if(!Eo(e[i],o[i]))return!1;return!0}let r=Object.keys(e);return r.length!==Object.keys(t).length?!1:r.every(o=>Eo(e[o],t[o]))}var Zr=(0,ct.memo)(Jr,(e,t)=>e.mode===t.mode&&e.selected===t.selected&&e.fidelity===t.fidelity&&wa(e.node,t.node));function Jr({node:e,mode:t,selected:n,fidelity:r}){let{store:o,views:i,view:a}=le(),l=It(),c=lr(),s=wn(),d=e.aggregate||Et(e.id)||$e(e.id)!==null?"many":"one",u={cardinality:d,fidelity:r??or[va(e.plane)].fidelity},h=d==="many"&&e.id===a.focusId?a.within?.view:void 0,g=i.resolve(e.kind,u,h),x=g?.view,p=i.resolve(e.kind,{cardinality:"many",fidelity:"full"})?.view,f=p!==void 0&&p.generic!==!0,m=e.aggregate?.memberIds,b=(0,ct.useMemo)(()=>(m??[]).map(E=>o.graph.getNode(E)).filter(E=>E!==void 0),[m,o,l]),R={...e.aggregate?{nodes:b,label:g?.title??e.aggregate.label}:{node:o.graph.getNode(e.id)},fidelity:u.fidelity,cardinality:u.cardinality,mode:t,selected:n,implicated:c,flagged:s,...e.raised?{raised:!0}:{},...e.focused?{focused:!0}:{},...e.opened?{opened:!0}:{},...e.openedRows!==void 0?{openedRows:e.openedRows}:{},...e.plot?{plot:e.plot}:{},...e.aggregate?.retired?{retired:e.aggregate.retired}:{},...e.rank?{rank:e.rank}:{},...e.nestedUnder?{nestedUnder:e.nestedUnder}:{},...f?{hasOwnView:!0}:{}};if(!x)return(0,te.jsx)(ka,{node:e,props:R});let O=[e.id,g?.title??"",u.fidelity,u.cardinality,t,n,e.raised??!1,e.focused??!1,e.opened??!1,e.openedRows??"",e.rank??"",e.nestedUnder??"",e.plot?`${e.plot.col},${e.plot.row},${e.plot.side}`:"",e.aggregate?Oo(e.aggregate.memberIds):"",e.aggregate?.retired??"",c?Oo(c):"",s?Oo(s):"",f].join("|");return(0,te.jsx)(to,{mode:t,children:(0,te.jsx)(ur,{kind:R.label??e.kind,...g?.title?{view:g.title}:{},children:(0,te.jsx)(ba,{signature:O,graph:l,draw:()=>(0,te.jsx)(x,{...R})})},`${e.id}|${g?.title??""}`)})}var ba=(0,ct.memo)(function({draw:t}){return(0,te.jsx)(te.Fragment,{children:t()})},(e,t)=>e.signature===t.signature&&e.graph===t.graph);function va(e){return Math.max(0,Math.min(2,Math.round(e)))}function ka({node:e,props:t}){return(0,te.jsxs)("div",{style:{padding:8,font:"13px/1.4 system-ui",overflow:"hidden"},children:[(0,te.jsx)("strong",{children:t.label??e.kind}),t.nodes?(0,te.jsxs)("div",{children:[t.nodes.length," items"]}):(0,te.jsx)("div",{children:e.id})]})}var ei=(0,ct.memo)(function({node:t}){let{store:n}=le(),r=Lt(),o=t.aggregate,i=o.opens,a=o.memberIds.length,l=hn(n.schema,o.kind,a),c=o.memberIds.slice(0,3).map(h=>{let g=n.graph.getNode(h),x=g?n.schema.tryDefinition(g.kind):void 0;return g?x?.label?x.label(g):String(g.label??h):h}),s=o.memberIds,d=(0,ct.useMemo)(()=>{let h=r?mn(r):null;return h?s.filter(g=>h.has(g)).length:0},[r,s]),u=i.in==="picture";return(0,te.jsxs)("div",{className:"graview-band-group","data-graview-band":i.in,"data-graview-band-count":a,"data-graview-emphasis":r?d>0?"lit":"dimmed":void 0,title:u?`${o.label} \u2014 press twice to see them all, arranged`:`${o.label}: ${l} \u2014 press twice to open`,children:[(0,te.jsxs)("span",{className:"graview-band-group-head",children:[(0,te.jsx)("span",{className:"graview-band-group-name",children:o.label}),(0,te.jsx)("span",{className:"graview-band-group-open","aria-hidden":"true",children:u?"\u2197":"\u25BE"})]}),(0,te.jsxs)("span",{className:"graview-band-group-names",children:[u?null:(0,te.jsxs)("span",{className:"graview-band-group-count",children:[l,d>0?` \xB7 ${d} match`:""," \xB7 "]}),c.join(" \xB7 "),a>c.length?" \u2026":""]})]})}),qr=new WeakMap;function Oo(e){let t=qr.get(e);if(t!==void 0)return t;let n=2166136261;for(let o of e){for(let i=0;i<o.length;i++)n=Math.imul(n^o.charCodeAt(i),16777619);n=Math.imul(n^44,16777619)}let r=`${e.length}:${(n>>>0).toString(36)}`;return qr.set(e,r),r}var vt=ee(He(),1);function Po(e,t,n){let r=e.aggregate?[...e.aggregate.memberIds]:[e.id];return n?r.every(i=>t.includes(i))?t.filter(i=>!r.includes(i)):[...t,...r.filter(i=>!t.includes(i))]:r}function ti(){let[e,t]=(0,vt.useState)(16);return(0,vt.useEffect)(()=>{if(typeof window>"u")return;let n=document.documentElement,r=()=>{let i=parseFloat(getComputedStyle(n).fontSize);Number.isFinite(i)&&t(a=>Math.abs(a-i)<.5?a:i)};r();let o=new MutationObserver(r);return o.observe(n,{attributes:!0,attributeFilter:["style"]}),window.addEventListener("resize",r),()=>{o.disconnect(),window.removeEventListener("resize",r)}},[]),e}function ni(e){let[t,n]=(0,vt.useState)(null);return(0,vt.useLayoutEffect)(()=>{let r=e.current?.getBoundingClientRect();!r||r.width===0||r.height===0||n(o=>o??{width:Math.round(r.width),height:Math.round(r.height)})},[e]),(0,vt.useEffect)(()=>{let r=e.current;if(!r||typeof ResizeObserver>"u")return;let o=new ResizeObserver(i=>{let a=i[0]?.contentRect;!a||a.width===0||a.height===0||n(l=>{let c={width:Math.round(a.width),height:Math.round(a.height)};return l&&l.width===c.width&&l.height===c.height?l:c})});return o.observe(r),()=>o.disconnect()},[e]),t}function oi(e,t){if(t==="dark")return`0 ${(10*e).toFixed(1)}px ${(34*e).toFixed(1)}px rgba(0,0,0,${(e+.12).toFixed(2)})`;let n=`0 ${(1+2*e).toFixed(1)}px ${(2+5*e).toFixed(1)}px rgba(20,30,32,${(.03+.06*e).toFixed(3)})`,r=`0 ${(6+26*e).toFixed(1)}px ${(18+60*e).toFixed(1)}px -${(10+10*e).toFixed(1)}px rgba(20,30,32,${(.1+.3*e).toFixed(3)})`;return`${n}, ${r}`}function ri(e){return`matrix3d(${e.join(",")})`}var _e=ee(He(),1);var Co=(e,t)=>t.some(n=>e.x>n.x&&e.x<n.x+n.width&&e.y>n.y&&e.y<n.y+n.height);function Ao(e,t){let n=[],r=[];for(let i=0;i<e.length-1;i++){let a=e[i],l=e[i+1],c=!Co(a,t);c&&r.length===0&&r.push(a);for(let s=1;s<=48;s++){let d=s/48,u={x:a.x+(l.x-a.x)*d,y:a.y+(l.y-a.y)*d},h=!Co(u,t);if(h===c)continue;let g=(s-1)/48,x=d;for(let m=0;m<10;m++){let b=(g+x)/2,R={x:a.x+(l.x-a.x)*b,y:a.y+(l.y-a.y)*b};!Co(R,t)===c?g=b:x=b}let p=(g+x)/2,f={x:a.x+(l.x-a.x)*p,y:a.y+(l.y-a.y)*p};h?r=[f]:(r.push(f),r.length>=2&&n.push(r),r=[]),c=h}c&&r.push(l)}return r.length>=2&&n.push(r),n}function nn(e,t){let n=Math.abs(t.x-e.x);if(Math.abs(t.y-e.y)>n){if(n<2)return[e,t];let i=(e.y+t.y)/2;return[e,{x:e.x,y:i},{x:t.x,y:i},t]}let o=(e.x+t.x)/2;return Math.abs(t.x-e.x)<2?[e,t]:[e,{x:o,y:e.y},{x:o,y:t.y},t]}var Ve=e=>Math.round(e*100)/100,Dt=e=>e.map(t=>t.map((n,r)=>`${r===0?"M":"L"} ${Ve(n.x)} ${Ve(n.y)}`).join(" ")).join(" ");function ii(e,t){if(e.length<3)return Dt([e]);let n=[`M ${Ve(e[0].x)} ${Ve(e[0].y)}`];for(let o=1;o<e.length-1;o++){let i=e[o-1],a=e[o],l=e[o+1],c=Math.hypot(a.x-i.x,a.y-i.y),s=Math.hypot(l.x-a.x,l.y-a.y),d=Math.min(t,c/2,s/2),u={x:a.x+(i.x-a.x)/(c||1)*d,y:a.y+(i.y-a.y)/(c||1)*d},h={x:a.x+(l.x-a.x)/(s||1)*d,y:a.y+(l.y-a.y)/(s||1)*d};n.push(`L ${Ve(u.x)} ${Ve(u.y)} Q ${Ve(a.x)} ${Ve(a.y)} ${Ve(h.x)} ${Ve(h.y)}`)}let r=e[e.length-1];return n.push(`L ${Ve(r.x)} ${Ve(r.y)}`),n.join(" ")}function ai(e,t,n){if(e==="orthogonal"){let l=nn(t.p0,t.p1),c=l.slice(1).map((u,h)=>Math.hypot(u.x-l[h].x,u.y-l[h].y)),s=c.reduce((u,h)=>u+h,0)||1,d=n*s;for(let u=0;u<c.length;u++){let h=c[u];if(d<=h||u===c.length-1){let g=h===0?0:Math.min(1,d/h),x=l[u],p=l[u+1];return{x:x.x+(p.x-x.x)*g,y:x.y+(p.y-x.y)*g}}d-=h}return t.p1}let r=e==="straight"?{x:(t.p0.x+t.p1.x)/2,y:(t.p0.y+t.p1.y)/2}:t.c,o=(1-n)*(1-n),i=2*(1-n)*n,a=n*n;return{x:o*t.p0.x+i*r.x+a*t.p1.x,y:o*t.p0.y+i*r.y+a*t.p1.y}}function Nn(e,t){return e!=="straight"?t:{...t,c:{x:(t.p0.x+t.p1.x)/2,y:(t.p0.y+t.p1.y)/2}}}function si(e,t){let n=t.x-e.x,r=t.y-e.y,o=(n/2+r)/2,i=(r-n/2)/2;if(Math.abs(o)<1||Math.abs(i)<1)return[e,t];let a={x:e.x+2*o,y:e.y+o};return[e,a,t]}function Sa(e){let t=[...e].sort((r,o)=>r.y-o.y||r.x-o.x),n=[];for(let r of t){let o=n.find(i=>r.y<i.bottom&&r.y+r.height>i.top);o?(o.boxes.push(r),o.top=Math.min(o.top,r.y),o.bottom=Math.max(o.bottom,r.y+r.height)):n.push({top:r.y,bottom:r.y+r.height,boxes:[r]})}for(let r of n)r.boxes.sort((o,i)=>o.x-i.x);return n.sort((r,o)=>r.top-o.top)}var Lo=(e,t)=>e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height,di=(e,t)=>e.findIndex(n=>n.boxes.some(r=>Lo(r,t)));function qt(e,t,n){return t<0?e[0].top-12*2:n>=e.length?e[e.length-1].bottom+12*2:(e[t].bottom+e[n].top)/2}function Ma(e,t){let n=[{from:-1/0,to:1/0}];for(let i of e){let a=[],l=-1/0;for(let s of i.boxes)a.push({from:l,to:s.x-12}),l=s.x+s.width+12;a.push({from:l,to:1/0});let c=[];for(let s of n)for(let d of a){let u=Math.max(s.from,d.from),h=Math.min(s.to,d.to);h-u>=0&&c.push({from:u,to:h})}n=c}let r=t,o=1/0;for(let i of n){let a=Math.min(Math.max(t,i.from),i.to),l=i.from===-1/0||i.to===1/0,c=Math.abs(a-t)+(l?60:0);c<o&&(o=c,r=a)}return r}function li(e,t,n,r=0){let o=Sa(n.some(b=>Lo(b,e))&&n.some(b=>Lo(b,t))?n:[...n,e,t]),i=di(o,e),a=di(o,t),l=e.x+e.width/2,c=t.x+t.width/2,s=(r%3-1)*4;if(i===a){let b=i<o.length-1||o.length===1,R=(b?qt(o,i,i+1):qt(o,i-1,i))+s,O=b?e.y+e.height:e.y,E=b?t.y+t.height:t.y;return[{x:l,y:O},{x:l,y:R},{x:c,y:R},{x:c,y:E}]}let d=a>i,u=d?1:-1,h={x:l,y:d?e.y+e.height:e.y},g={x:c,y:d?t.y:t.y+t.height},x=(d?qt(o,i,i+1):qt(o,i-1,i))+s,p=(d?qt(o,a-1,a):qt(o,a,a+1))+s;if(Math.abs(a-i)===1)return[h,{x:l,y:x},{x:c,y:x},g];let f=[];for(let b=i+u;b!==a;b+=u)f.push(o[b]);let m=Ma(f,c);return[h,{x:l,y:x},{x:m,y:x},{x:m,y:p},{x:c,y:p},g]}function ci(e,t=16){let n=new Map;for(let o of e){let i=o.a<o.b?`${o.a}\0${o.b}`:`${o.b}\0${o.a}`,a=n.get(i);a?a.push(o.key):n.set(i,[o.key])}let r=new Map;for(let o of n.values())o.forEach((i,a)=>r.set(i,(a-(o.length-1)/2)*t));return r}var We=ee(be(),1);function $n(e,t){let n=Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x),r=Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y);if(n>0&&r>0)return null;let o=n>.5*Math.min(e.width,t.width),i=!o&&r>.5*Math.min(e.height,t.height);if(o){let x={x:e.x+e.width,y:e.y+e.height/2},p={x:t.x+t.width,y:t.y+t.height/2};return{from:x,to:p,control:{x:Math.max(x.x,p.x)+18,y:(x.y+p.y)/2},mode:"stacked"}}if(i){let x={x:e.x+e.width/2,y:e.y},p={x:t.x+t.width/2,y:t.y};return{from:x,to:p,control:{x:(x.x+p.x)/2,y:Math.min(x.y,p.y)-18},mode:"abreast"}}let a={x:t.x+t.width/2,y:t.y+t.height/2},l={x:e.x+e.width/2,y:e.y+e.height/2},c=Tn(e,a),s=Tn(t,l),d=Math.hypot(s.x-c.x,s.y-c.y);if(d<8)return null;let u=Math.min(36,d*.12),h=-(s.y-c.y)/d,g=(s.x-c.x)/d;return{from:c,to:s,control:{x:(c.x+s.x)/2+h*u,y:(c.y+s.y)/2+g*u},mode:"direct"}}function Tn(e,t){let n=e.x+e.width/2,r=e.y+e.height/2,o=t.x-n,i=t.y-r;if(o===0&&i===0)return{x:n,y:r};let a=o===0?1/0:e.width/2/Math.abs(o),l=i===0?1/0:e.height/2/Math.abs(i),c=Math.min(a,l),s=Math.max(0,c*.98);return{x:n+o*s,y:r+i*s}}function Ra(e,t,n){let r=t.get(e.from),o=t.get(e.to);if(!r||!o)return!1;if(n)return!0;let i=Math.round(r.plane)===1||Math.round(o.plane)===1,a=l=>!!l.aggregate&&Math.round(l.plane)===2;return i&&!a(r)&&!a(o)}var Oa=()=>({clips:new Map,members:new Map,marks:new Map});function Ea(e,t){let n=t.marks.get(e);if(n)return n;n=new Map;for(let r of e.querySelectorAll("[data-graview-pick], [data-graview-slot]"))for(let o of new Set([r.getAttribute("data-graview-pick"),r.getAttribute("data-graview-slot")])){if(o===null)continue;let i=n.get(o);i?i.push(r):n.set(o,[r])}return t.marks.set(e,n),n}function Pa(e,t){let n=t.clips.get(e);if(n===void 0){let r=getComputedStyle(e);n=r.overflow!=="visible"||r.overflowX!=="visible"||r.overflowY!=="visible"?e.getBoundingClientRect():null,t.clips.set(e,n)}return n}function Ca(e,t,n){let r=e.parentElement;for(;r!==null;){let o=Pa(r,n);if(o&&!(t.right>o.left+1&&t.left<o.right-1&&t.bottom>o.top+1&&t.top<o.bottom-1))return!1;if(r.hasAttribute("data-graview-view"))break;r=r.parentElement}return!0}function on(e,t,n,r){if(!e||!t||typeof document>"u")return[];let o=r.members.get(t);o||r.members.set(t,o=new Map);let i=o.get(n);if(i)return i;let a=e.getBoundingClientRect(),l=[];for(let c of Ea(t,r).get(n)??[]){if(c.closest("[data-graview-offstage]"))continue;let s=c.getBoundingClientRect();s.width<=2||s.height<=2||Ca(c,s,r)&&l.push({x:s.left-a.left,y:s.top-a.top,width:s.width,height:s.height})}return l.sort((c,s)=>c.width*c.height-s.width*s.height),o.set(n,l),l}function Hn(e,t,n,r,o){let i=new Map(e.map(f=>[f.id,f])),a=Oa(),l=new Map,c=f=>{if(!n||typeof document>"u")return null;let m=l.get(f);return m===void 0&&(m=n.querySelector(`[data-graview-view="${CSS.escape(f)}"]`),l.set(f,m)),m},s=new Map;for(let f of e){let m=Qe(n,f.id,r)??qe(f,o);m&&s.set(f.id,m)}let d=new Map;if(n&&typeof document<"u"){let f=n.getBoundingClientRect();for(let m of n.querySelectorAll("[data-graview-pick], [data-graview-slot]")){if(m.closest("[data-graview-offstage]"))continue;let b=m.getAttribute("data-graview-pick")??m.getAttribute("data-graview-slot");if(b===null)continue;let R=m.getBoundingClientRect();if(R.width<=2||R.height<=2||R.width>f.width*.6&&R.height>f.height*.6)continue;let O=d.get(b),E={x:R.left-f.left,y:R.top-f.top,width:R.width,height:R.height};O?O.push(E):d.set(b,[E])}}let u=(f,m)=>{let b=[];for(let[R,O]of s)R!==f&&R!==m&&b.push(O);for(let[R,O]of d)R!==f&&R!==m&&b.push(...O);return b},h=f=>Math.round(i.get(f)?.plane??-1)===1,g=[];for(let f of e){let m=s.get(f.id);m&&Math.round(f.plane)===1&&g.push(m)}let x=(f,m)=>!r&&h(f)&&h(m)?g:void 0,p=[];for(let f of t){if(!Ra(f,i,r))continue;let m=s.get(f.from),b=s.get(f.to);if(!m||!b)continue;let R=u(f.from,f.to),O=f.edges,E=r&&O.some(k=>k.from!==f.from&&on(n,c(f.from),k.from,a).length>0||k.to!==f.to&&on(n,c(f.to),k.to,a).length>0),S=x(f.from,f.to);if(r&&!E||f.loop||O.length===0){p.push({key:f.id,connector:f,edges:O,fromBox:m,toBox:b,fromAnchor:f.from,toAnchor:f.to,obstacles:R,hosts:[],...S?{band:S}:{}});continue}let j=new Map;for(let k of O){let w=k.from===f.from?[]:on(n,c(f.from),k.from,a),M=k.to===f.to?[]:on(n,c(f.to),k.to,a),C=[f.from,f.to].find(X=>Math.round(i.get(X)?.plane??-1)===0);if(!r&&C!==void 0&&(k.from!==f.from||k.to!==f.to)&&on(n,c(C),C===f.from?k.to:k.from,a).length>0)continue;let B=C!==void 0?i.get(C):void 0;if(!r&&B?.aggregate&&n&&(C===f.from?k.from!==f.from&&w.length===0:k.to!==f.to&&M.length===0))continue;let A=w.length>0?k.from:f.from,$=M.length>0?k.to:f.to,D=`${f.id}|${A}|${$}`,H=j.get(D);if(H){H.edges.push(k);continue}let Y=w.length>0?w:[m],K=M.length>0?M:[b],W=Y[0],ge=K[0],me=1/0;for(let X of Y)for(let oe of K){let L=Math.hypot(X.x+X.width/2-(oe.x+oe.width/2),X.y+X.height/2-(oe.y+oe.height/2));L<me&&(me=L,W=X,ge=oe)}j.set(D,{edges:[k],fromBox:W,toBox:ge,fromAnchor:A,toAnchor:$})}for(let[k,w]of j)p.push({key:k,connector:f,obstacles:R,hosts:[...w.fromAnchor!==f.from?[m]:[],...w.toAnchor!==f.to?[b]:[]],...S?{band:S}:{},...w})}return p}function Io(e,t){let n=(1-t)*(1-t),r=2*(1-t)*t,o=t*t;return{x:n*e.p0.x+r*e.c.x+o*e.p1.x,y:n*e.p0.y+r*e.c.y+o*e.p1.y}}function ui(e,t,n){let r=(1-t)*(1-n),o=(1-t)*n+t*(1-n),i=t*n;return{p0:Io(e,t),c:{x:r*e.p0.x+o*e.c.x+i*e.p1.x,y:r*e.p0.y+o*e.c.y+i*e.p1.y},p1:Io(e,n)}}function No(e,t){let n=s=>t.some(d=>s.x>d.x&&s.x<d.x+d.width&&s.y>d.y&&s.y<d.y+d.height),r=s=>!n(Io(e,s)),i=(s,d,u)=>{for(let h=0;h<10;h++){let g=(s+d)/2;r(g)===u?s=g:d=g}return(s+d)/2},a=[],l=null,c=r(0);c&&(l=0);for(let s=1;s<=64;s++){let d=s/64,u=r(d);if(u===c)continue;let h=i((s-1)/64,d,c);u?l=h:l!==null&&(h-l>.001&&a.push(ui(e,l,h)),l=null),c=u}return l!==null&&1-l>.001&&a.push(ui(e,l,1)),a}function hi({strands:e,result:t,scheme:n,overview:r,selection:o,emphasis:i,stageRef:a,liveOf:l,onPickEdge:c}){let s=en(),d=new Set(t.nodes.filter(S=>S.plot!==void 0&&Math.round(S.plane)===2).map(S=>S.id)),u=S=>r&&t.city!==void 0&&d.has(S.from)&&d.has(S.to),h=So(t.nodes,o),g=S=>h.size===0||h.has(S.from)||h.has(S.to),x=new Set(o.filter(S=>Rt(S)===null)),p=r?t.nodes.find(S=>Math.round(S.plane)===0):void 0,f=p?Qe(a.current,p.id,!1)??qe(p,n):null;if(e.length===0)return null;let m=S=>S.edges.some(j=>x.has(j.from)||x.has(j.to)),b=x.size>0&&e.some(m),R=new Map;for(let S of e)R.set(S.connector.id,(R.get(S.connector.id)??0)+1);let O=ci(e.map(S=>({key:S.key,a:S.fromAnchor,b:S.toAnchor}))),E=e.map((S,j)=>{let{connector:k,fromBox:w,toBox:M}=S,C={x:w.x+w.width/2,y:w.y+w.height/2},B={x:M.x+M.width/2,y:M.y+M.height/2},A=r?Tn(w,B):C,$=r?Tn(M,C):B,D=k.loop===!0,{connector:H,style:Y}=bn(s,k.kind);if(!H.visible)return null;let K=D?Math.max(22,Math.min(w.width,w.height)*.3):0,W=D?{x:C.x+w.width*.22,y:C.y-w.height/2-K+7}:A,ge=(A.x+$.x)/2,me=(A.y+$.y)/2,X=Math.hypot($.x-A.x,$.y-A.y),oe=Math.min(r?40:90,X*(r?.09:.16)),L=0,z=0;if(X>0){L=-($.y-A.y)/X,z=($.x-A.x)/X;let ne=ge-t.width/2,xe=me-t.height/2;if(f&&!D){let rt=f.x+f.width/2,Me=f.y+f.height/2;ne=ge-rt,xe=me-Me;let gt=Math.abs(L*(rt-A.x)+z*(Me-A.y)),mt=Math.hypot(f.width/2,f.height/2)*.85+24,St=((rt-A.x)*($.x-A.x)+(Me-A.y)*($.y-A.y))/(X*X);gt<mt&&St>.1&&St<.9&&(oe=Math.min(180,Math.max(oe,(mt-gt)*2)))}L*ne+z*xe<0&&(L=-L,z=-z)}oe+=2*(O.get(S.key)??0);let v=Nn(H.route,{p0:A,c:{x:ge+L*oe,y:me+z*oe},p1:$}),N=u(k),T=H.route==="orthogonal"||N,G=(ne,xe)=>N?si(ne,xe):nn(ne,xe),F=!D&&S.band?li(w,M,S.band,j):null,re=D||T||F?[]:No(v,[w,M,...S.obstacles]),ie=F?[F]:!D&&T?Ao(G(A,$),[w,M,...S.obstacles]):[];if(!D&&re.length===0&&ie.length===0)return null;let de=ie[ie.length-1],J=T||F?ie[0]?.[0]:re[0]?.p0,Ae=T||F?de?.[de.length-1]:re[re.length-1]?.p1,Se=ne=>ne.map(xe=>`M ${xe.p0.x} ${xe.p0.y} Q ${xe.c.x} ${xe.c.y} ${xe.p1.x} ${xe.p1.y}`).join(" "),et=`M ${W.x-K} ${W.y} A ${K} ${K} 0 1 1 ${W.x+K} ${W.y} A ${K} ${K} 0 0 1 ${W.x-K} ${W.y}`,Ye=D?et:F?ii(F,10):T?Dt(ie):Se(re),U=ne=>({x:ne.x-8,y:ne.y-8,width:ne.width+16,height:ne.height+16}),Le=[w,M,...S.hosts,...S.obstacles].map(U),tt=D?et:F?Dt(ie):T?Dt(Ao(G(A,$),Le)):Se(No(v,Le)),nt=S.edges.length===1?S.edges[0]:null,Fe=nt?Yt(k.kind,nt.from,nt.to):null,Je=Fe!==null&&o.includes(Fe),ht=S.edges.some(ne=>x.has(ne.from)||x.has(ne.to)),Ne=!r&&x.size>0&&ht,ft=i!==null&&k.kind===i||Je,yt=l?.(k)!==void 0;if(r&&!ft&&!ht&&!(h.size>0&&g(k))&&!yt)return null;let ze=r?Mo({emphasized:i!==null,stressed:ft,anyChosen:b,mine:ht,touches:g(k),siblings:R.get(k.id)??1}):Ro({edgeChosen:Je,lit:Ne,anyLit:b||i!==null,own:Y.opacity,kit:s.emphasis}),ot=Ne&&J&&Ae?S.edges.some(ne=>x.has(ne.from))?Ae:J:null,Ie=(0,We.jsxs)("g",{children:[(0,We.jsx)("path",{"data-graview-connector":k.kind,"data-graview-edges":S.edges.length,"data-graview-from":S.fromAnchor,"data-graview-to":S.toAnchor,"data-graview-lit":Ne||void 0,"data-graview-activity":l?.(k)?.manner,opacity:ze*(k.opacity??1),d:Ye,fill:"none",stroke:Xt(Y),strokeWidth:(Ne?Math.max(1.6,ao(Y,r)):ao(Y,r))+(ft?.6:0),strokeDasharray:xn[Y.pattern],strokeLinecap:"round"}),ot?(0,We.jsx)("circle",{cx:ot.x,cy:ot.y,r:2.6,fill:Xt(Y),opacity:ze}):null,D&&r?(0,We.jsx)("text",{x:W.x,y:W.y-K-5,textAnchor:"middle",opacity:ze,style:{font:"9px var(--graview-font-body, system-ui)",letterSpacing:"0.09em",textTransform:"uppercase",fill:"var(--graview-ink-faint)"},children:Vt(k.kind).toLowerCase()}):null]},S.key),kt=null;return Fe&&c&&!D&&ze>=.2&&(kt=(0,We.jsx)("path",{"data-graview-edge":Fe,className:"graview-edge-hit",d:tt,fill:"none",pathLength:1,strokeDasharray:"0.86",strokeDashoffset:-.07,stroke:"transparent",strokeWidth:14,style:{pointerEvents:"stroke",cursor:"pointer"},onClick:ne=>{ne.stopPropagation(),c(Fe,{x:ne.clientX,y:ne.clientY})},onContextMenu:ne=>{ne.preventDefault(),ne.stopPropagation(),c(Fe,{x:ne.clientX,y:ne.clientY})}},`hit:${S.key}`)),{key:S.key,line:Ie,hit:kt}});return(0,We.jsxs)(We.Fragment,{children:[(0,We.jsx)("svg",{"aria-hidden":"true","data-graview-world":"",width:t.width,height:t.height,style:{position:"absolute",left:0,top:0,pointerEvents:"none",zIndex:Te.ties},children:E.map(S=>S?.line)}),E.some(S=>S?.hit)?(0,We.jsx)("svg",{"data-graview-world":"",width:t.width,height:t.height,style:{position:"absolute",left:0,top:0,pointerEvents:"none",zIndex:Te.tieLabels},children:E.map(S=>S?.hit)}):null]})}var Aa=e=>e.length*8.4+16;function fi(e,t){let n=new Map;for(let i of e){let a=n.get(i.key);a?a.push(i):n.set(i.key,[i])}let r=[...n.values()].map(i=>{let a=Math.min(...i.map(c=>c.top)),l=i.filter(c=>c.top-a<=12);return{key:i[0].key,text:i[0].text,left:Math.min(...l.map(c=>c.left)),right:Math.max(...l.map(c=>c.right)),top:a}});r.sort((i,a)=>i.top-a.top||i.left-a.left);let o=r.map(i=>{let a=Math.max(i.right-i.left,Math.min(300,Aa(i.text))),l=(i.left+i.right)/2;return{left:l-a/2,right:l+a/2}});return r.map((i,a)=>{let l=r.map((m,b)=>({other:m,at:b})).filter(({other:m})=>m!==i&&Math.abs(m.top-i.top)<=12),c=l.filter(({other:m})=>m.right<=i.left).map(({other:m,at:b})=>o[b].right+8<=(m.right+i.left)/2?o[b].right+8:(m.right+i.left+8)/2),s=l.filter(({other:m})=>m.left>=i.right).map(({other:m,at:b})=>o[b].left-8>=(i.right+m.left)/2?o[b].left-8:(i.right+m.left-8)/2),d=Math.max(t.left,...c),u=Math.min(t.right,...s),h=i.right-i.left,g=o[a].right-o[a].left,x=Math.max(h,Math.min(g,u-d)),p=(i.left+i.right)/2,f=h>=x?i.left:Math.max(d,Math.min(p-x/2,u-x));return{key:i.key,text:i.text,left:f,width:x,top:i.top}})}function Dn(e){return e<640?{left:8,right:56}:{left:8,right:Math.round(Math.min(128,e*.107))}}var Ce=ee(be(),1);function yi({frame:e,width:t,height:n,scheme:r,overview:o,selection:i,emphasis:a,stageRef:l,store:c,graphNodes:s,onPickEdge:d,liveOf:u,holding:h=!1}){let[g,x]=(0,_e.useState)(0),[p,f]=(0,_e.useState)(null),m=e.t<1;(0,_e.useLayoutEffect)(()=>{m||h||f(Hn(e.nodes,e.connectors,l.current,o,r))},[e,m,h,i,o,s,r,g,l]);let b=e.nodes.map(E=>E.id).join(`
8
+ `);if((0,_e.useLayoutEffect)(()=>{let E=l.current;if(E===null||typeof window>"u")return;let S=0,j=()=>{S===0&&(S=requestAnimationFrame(()=>{S=0,x(w=>w+1)}))};E.addEventListener("scroll",j,{capture:!0,passive:!0}),window.addEventListener("resize",j,{passive:!0});let k=typeof ResizeObserver>"u"?null:new ResizeObserver(j);if(k){k.observe(E);for(let w of E.querySelectorAll("[data-graview-view]"))k.observe(w)}return()=>{S!==0&&cancelAnimationFrame(S),E.removeEventListener("scroll",j,{capture:!0}),window.removeEventListener("resize",j),k?.disconnect()}},[l,b]),m)return null;let R=(h?null:p)??Hn(e.nodes,e.connectors,null,o,r),O=new Set;for(let E of R){if(E.edges.length!==1)continue;let S=E.edges[0];O.add(`${E.connector.kind}|${S.from}|${S.to}`)}return(0,Ce.jsxs)(Ce.Fragment,{children:[(0,Ce.jsx)(hi,{strands:R,result:e,scheme:r,overview:o,selection:i,emphasis:a,stageRef:l,onPickEdge:d,liveOf:u}),(0,Ce.jsx)(La,{stageRef:l,nodes:e.nodes,scheme:r,selection:i,store:c,graphNodes:s,overview:o,width:t,height:n,onPickEdge:d,alreadyDrawn:O,tick:g})]})}function La({stageRef:e,nodes:t,scheme:n,selection:r,store:o,graphNodes:i,overview:a,width:l,height:c,onPickEdge:s,alreadyDrawn:d,tick:u}){let h=en(),g=(0,_e.useMemo)(()=>{if(r.length===0||r.length>4)return[];let m=new Set(r),b=[];for(let O of r){let E=Rt(O);E&&b.push({kind:E.kind,self:E.from,other:E.to})}for(let O of o.graph.allEdges()){let E=m.has(O.from)?O.from:m.has(O.to)?O.to:null;if(!E)continue;let S=E===O.from?O.to:O.from;m.has(S)||b.push({kind:O.kind,self:E,other:S})}if(b.length<=14)return b;let R=new Set(t.map(O=>O.id));return b.map((O,E)=>({tie:O,index:E,real:R.has(O.other)?0:1})).sort((O,E)=>O.real-E.real||O.index-E.index).slice(0,14).map(({tie:O})=>O)},[o,r,i,t]),x=()=>{if(g.length===0||typeof document>"u")return[];if(!e.current?.getBoundingClientRect())return[];let b=[...e.current?.querySelectorAll("[data-graview-joins]")??[]].find(w=>{if(w.closest("[data-graview-offstage]"))return!1;try{let M=JSON.parse(w.getAttribute("data-graview-joins")??"[]");return M.length===r.length&&M.every(C=>r.includes(C))}catch{return!1}});if(b){let w=Ln(b,e.current);if(!w)return[];let M=[];for(let C of r){let B=t.find(H=>H.id===C);if(!B)continue;let A=Qe(e.current,B.id,a)??qe(B,n),$=A?$n(w,A):null;if(!A||!$)continue;let D=[...o.graph.allEdges()].find(H=>H.from===C&&r.includes(H.to)||H.to===C&&r.includes(H.from));M.push({key:`join:${C}`,kind:D?.kind??"",endX:$.to.x,endY:$.to.y,...$,fromBox:w,toBox:A,proxy:!1,edgeId:D?Yt(D.kind,D.from,D.to):null})}return M}let R=(w,M)=>{let C=e.current?.querySelectorAll(`[data-graview-pick="${CSS.escape(w)}"], [data-graview-slot="${CSS.escape(w)}"]`),B=[];for(let A of C??[]){if(A.closest("[data-graview-offstage]")||M(A)||A.closest("[data-graview-mark]"))continue;let $=Ln(A,e.current);$&&B.push($)}return B.sort((A,$)=>A.width*A.height-$.width*$.height)},O=w=>t.find(M=>M.id===w)??t.find(M=>M.aggregate?.memberIds.includes(w)),E=w=>`[data-graview-pick="${CSS.escape(w)}"], [data-graview-slot="${CSS.escape(w)}"]`,S=(w,M)=>{let C=e.current;if(!C)return!1;for(let B of C.querySelectorAll("[data-graview-view]")){let A=B.querySelector(E(w));if(A===null||A.closest("[data-graview-offstage]"))continue;let $=B.querySelector(E(M));if($!==null&&!$.closest("[data-graview-offstage]"))return!0}return!1},j=new Set,k=[];for(let w of g){if(S(w.self,w.other))continue;let M=O(w.self),C=M?e.current?.querySelector(`[data-graview-view="${CSS.escape(M.id)}"]`):null,B=R(w.self,()=>!1);if(!(B.length>0)&&M){let v=Qe(e.current,M.id,!1)??qe(M,n);v&&B.push(v)}let $=t.find(v=>v.id===w.other),D=[],H=!1;if($){let v=Qe(e.current,$.id,a)??qe($,n);v&&D.push(v)}else if(D.push(...R(w.other,v=>C?C.contains(v):!1)),D.length===0){let v=O(w.other);if(v&&(!M||v.id!==M.id)){let N=Qe(e.current,v.id,a)??qe(v,n);N&&(D.push(N),H=!0)}}if(B.length===0||D.length===0||H&&a)continue;let Y=B[0],K=D[0],W=1/0;for(let v of B)for(let N of D){let T=Math.hypot(v.x+v.width/2-(N.x+N.width/2),v.y+v.height/2-(N.y+N.height/2));T<W&&(W=T,Y=v,K=N)}if(d?.has(`${w.kind}|${w.self}|${w.other}`)||d?.has(`${w.kind}|${w.other}|${w.self}`))continue;let ge=`${w.kind}:${Math.round(Y.x)},${Math.round(Y.y)}:${Math.round(K.x)},${Math.round(K.y)}`;if(j.has(ge))continue;j.add(ge);let me=$n(Y,K);if(!me)continue;let{from:X,to:oe,control:L}=me,z=[...o.graph.allEdges()].find(v=>v.kind===w.kind&&(v.from===w.self&&v.to===w.other||v.from===w.other&&v.to===w.self));k.push({key:`${w.kind}:${w.self}:${w.other}`,kind:w.kind,endX:oe.x,endY:oe.y,from:X,to:oe,control:L,fromBox:Y,toBox:K,proxy:H,edgeId:z?Yt(z.kind,z.from,z.to):null})}return k},[p,f]=(0,_e.useState)([]);return(0,_e.useLayoutEffect)(()=>{f(x())},[g,t,a,n,l,c,d,u,e]),p.length===0?null:(0,Ce.jsx)("svg",{"aria-hidden":p.some(m=>m.edgeId)?void 0:!0,"data-graview-ties":p.length,"data-graview-world":"",width:l,height:c,style:{position:"absolute",left:0,top:0,pointerEvents:"none",zIndex:Te.lines},children:p.map(m=>{let{connector:b,style:R}=bn(h,m.kind);if(!b.visible)return null;let O={p0:m.from,c:m.control,p1:m.to},E=b.route==="orthogonal"?Dt([nn(m.from,m.to)]):(({p0:j,c:k,p1:w})=>`M ${j.x} ${j.y} Q ${k.x} ${k.y} ${w.x} ${w.y}`)(Nn(b.route,O)),S=null;if(m.edgeId&&s&&!m.proxy){let j=(w,M)=>M.x>=w.x&&M.x<=w.x+w.width&&M.y>=w.y&&M.y<=w.y+w.height,k=[];for(let w=0;w<=40;w++){let M=ai(b.route,O,w/40);j(m.fromBox,M)||j(m.toBox,M)||k.push(M)}k.length>=2&&(S=(0,Ce.jsx)("path",{"data-graview-edge":m.edgeId,className:"graview-edge-hit",d:`M ${k[0].x} ${k[0].y} ${k.slice(1).map(w=>`L ${w.x} ${w.y}`).join(" ")}`,fill:"none",pathLength:1,strokeDasharray:"0.86",strokeDashoffset:-.07,stroke:"transparent",strokeWidth:14,style:{pointerEvents:"stroke",cursor:"pointer"},onClick:w=>{w.stopPropagation(),s(m.edgeId,{x:w.clientX,y:w.clientY})},onContextMenu:w=>{w.preventDefault(),w.stopPropagation(),s(m.edgeId,{x:w.clientX,y:w.clientY})}}))}return(0,Ce.jsxs)("g",{opacity:m.proxy?.32:.72,children:[(0,Ce.jsx)("path",{"data-graview-tie":m.kind,"data-graview-tie-proxy":m.proxy||void 0,d:E,fill:"none",stroke:Xt(R),strokeWidth:m.proxy?1.1:1.6,strokeDasharray:xn[R.pattern],strokeLinecap:"round"}),(0,Ce.jsx)("circle",{cx:m.endX,cy:m.endY,r:m.proxy?2:2.6,fill:Xt(R)}),S]},m.key)})})}function gi({nodes:e,scheme:t,width:n,stageRef:r,moving:o=!1,holding:i=!1}){let a=en(),[l,c]=(0,_e.useState)([]);(0,_e.useLayoutEffect)(()=>{o||i||c(s())},[e,o,i,t,n,r]);function s(){let d=[];for(let h of e){if(!h.via||Math.round(h.plane)!==1)continue;let g=Qe(r.current,h.id,!1),{scale:x}=Ue(1,t);d.push({key:`${h.via.edgeKind}|${h.via.direction}`,text:h.via.description??`${h.via.direction==="in"?"\u2190":"\u2192"} ${Vt(h.via.edgeKind).toLowerCase()}`,left:g?.x??h.x,right:g?g.x+g.width:h.x+h.width*x,top:g?.y??h.y})}let u=Dn(n);return fi(d,{left:u.left,right:n-u.right})}return l.length===0||!a.captions.visible||o?null:(0,Ce.jsx)("div",{"aria-hidden":"true",style:{position:"absolute",inset:0,pointerEvents:"none",zIndex:Te.lines},children:l.map(d=>{let{left:u,width:h}=d;return(0,Ce.jsx)("div",{"data-graview-relation":d.key,title:d.text,style:{position:"absolute",left:u,width:h,textAlign:"center",top:Math.max(0,d.top-19),fontSize:"0.75rem",letterSpacing:"0.09em",textTransform:"uppercase",color:"var(--graview-ink-faint)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:(0,Ce.jsx)("span",{style:{background:"var(--graview-ground)",padding:"1px 7px",borderRadius:4},children:d.text})},d.key)})})}var rn=ee(He(),1);var Na=new Set;function mi(e,t,n,r,o,i,a,l){let{store:c,views:s,hiddenKinds:d}=le(),u=Lt(),h=no(),g=(0,rn.useMemo)(()=>{let f={};for(let m of h){if(m.subjectId===void 0)continue;let b=f[m.subjectId]??=[];for(let R of m.nodeIds)R!==m.subjectId&&!b.includes(R)&&b.push(R)}return f},[h]),x=(0,rn.useMemo)(()=>({flagged:new Set(h.flatMap(f=>f.nodeIds)),touched:Go(c.log.all())}),[h,c,l]),p=(0,rn.useMemo)(()=>({hits:u?mn(u):Na,...x}),[u,x]);return(0,rn.useMemo)(()=>({...e,cityZoom:i,...a!==void 0?{screenHeight:a}:{},...d.size>0?{hiddenKinds:[...d].sort()}:{},...Object.keys(g).length>0?{judged:g}:{},relevance:p,inset:Dn(t?.width??1200),unit:n,plainGroups:c.schema.kinds.filter(f=>nr(s.lookup(f,{cardinality:"many",fidelity:"full"}))),cityOrder:Xo(qo({name:"scene",schema:c.schema,mutations:c.allMutations().filter(f=>!f.derived)}).order.map(f=>f.kind),s.arrangement?.()?.order),screens:s.places().reduce((f,m)=>((f[m.kind]??=[]).push({as:m.as,title:m.title,...m.across?{across:m.across}:{}}),f),{}),nameWidth:r,...t?{width:t.width,height:o?Math.max(0,t.height-64):t.height}:{}}),[e,t,n,c,s,d,g,p,i,a,r,o])}var ut=ee(He(),1);var pi=ee(He(),1);function Fn(e){let t=e?.closest?.("[data-graview-pick]")?.getAttribute("data-graview-joins");if(!t)return null;try{let n=JSON.parse(t);return Array.isArray(n)&&n.length>0&&n.every(r=>typeof r=="string")?n:null}catch{return null}}function xi(e){(0,pi.useEffect)(()=>{let t=e.current;if(!t)return;let n=()=>{for(let i of t.querySelectorAll("[data-graview-pick]"))i.getAttribute("tabindex")===null&&i.setAttribute("tabindex","0"),i.getAttribute("role")===null&&$a(i)&&i.setAttribute("role","button")};if(n(),typeof MutationObserver>"u")return;let r=0,o=new MutationObserver(()=>{r===0&&(r=typeof requestAnimationFrame>"u"?0:requestAnimationFrame(()=>{r=0,n()}),r===0&&n())});return o.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-graview-pick"]}),()=>{o.disconnect(),r!==0&&cancelAnimationFrame(r)}},[e])}var Ta=new Set(["div","span","p","figure","img","td","output","b","i","em","strong","small","canvas","g","polygon","circle","rect","path","ellipse","polyline","line","use"]);function $a(e){return Ta.has(e.localName.toLowerCase())}var Qt=ee(be(),1);function wi({node:e,useDom:t,touched:n,frontY:r,centerY:o,screen:i,onDrawnHeight:a,crowded:l,activity:c,scheme:s,canvasWidth:d,canvasHeight:u,selected:h,onSelect:g,onPick:x,onTravel:p,onMenu:f,selection:m,onJackIn:b,onDragStart:R,onDragMove:O,onDragEnd:E,swallowClick:S,children:j}){let{brand:k,store:w,actsDoor:M}=le(),C=e.beyond?`${e.beyond.length} more district${e.beyond.length===1?"":"s"}`:e.aggregate?.opens?.in==="place"?`${e.aggregate.label}, ${hn(w.schema,e.aggregate.kind,e.aggregate.memberIds.length)}`:e.aggregate?e.aggregate.label:(()=>{let v=w.graph.getNode(e.id);return v?_o(w.schema.tryDefinition(e.kind),v):e.id})(),[B,A]=(0,ut.useState)(null),$=Math.round(e.plane)===0&&!e.aggregate;(0,ut.useLayoutEffect)(()=>{if(!$)return;let v=me.current;if(!v)return;let N=()=>{let G=[...v.children].find(J=>J.dataset.graviewKindtag===void 0);if(!G)return;let F=v.getBoundingClientRect(),re=G.getBoundingClientRect(),ie=v.offsetWidth>0?F.width/v.offsetWidth:1,de={top:Math.round((re.top-F.top)/ie)-9,right:Math.round((F.right-re.right)/ie)+14};A(J=>J&&J.top===de.top&&J.right===de.right?J:de)};if(typeof ResizeObserver>"u"){N();return}let T=new ResizeObserver(N);T.observe(v);for(let G of v.children)T.observe(G);return()=>T.disconnect()},[$,e.id]);let D=e.plane-(1-(e.depth??1))*.55,H=Math.max(0,Math.min(2,Math.floor(D))),Y=Math.max(0,Math.min(2,Math.ceil(D))),K=H===Y?Ue(H,s):pn(Ue(H,s),Ue(Y,s),D-H),W=rr(K,e.x,e.y,d,u),ge=Ue(Math.max(0,Math.min(2,Math.round(D))),s).blur,me=(0,ut.useRef)(null);xi(me);let X=e.natural,oe=X?Math.min(e.width/X.width,e.height/X.height):1,L=(0,ut.useRef)(null);(0,ut.useEffect)(()=>{if(!i||!a)return;let v=L.current;if(!v||typeof ResizeObserver>"u")return;let N=()=>{let ie=0,de=0;for(let J of v.children)if(!(!(J instanceof HTMLElement)||J.classList.contains("graview-screen-fullscreen"))){ie=Math.max(ie,J.offsetTop+J.offsetHeight);for(let Ae of[J,...J.querySelectorAll("*")]){let Se=getComputedStyle(Ae).overflowY;(Se==="auto"||Se==="scroll")&&(de+=Ae.scrollHeight-Ae.clientHeight)}}a(ie+de)},T=0,G=()=>{T||(T=requestAnimationFrame(()=>{T=0,N()}))};N();let F=new ResizeObserver(G);F.observe(v);for(let ie of v.children)F.observe(ie);let re=new MutationObserver(G);return re.observe(v,{childList:!0,subtree:!0,characterData:!0,attributes:!0}),()=>{T&&cancelAnimationFrame(T),F.disconnect(),re.disconnect(),a(void 0)}},[i,a,e.id]);let z=t?{transform:ri(W),transformOrigin:"0 0",filter:ge>0?`blur(${ge}px)`:void 0,opacity:(1-K.falloff*.55)*(e.opacity??1),"--graview-lift-low":oi(K.shadow,s),...r!==void 0?{"--graview-front-y":`${r.toFixed(1)}px`}:{},...o!==void 0?{"--graview-center-y":`${o.toFixed(1)}px`}:{}}:{};return(0,Qt.jsxs)("div",{ref:me,"data-graview-view":e.id,"data-graview-plane":Math.round(e.plane),"data-graview-selected":h||void 0,"data-graview-touched":n||void 0,"data-graview-plot":r!==void 0?"":void 0,"data-graview-screen":i?"":void 0,"data-graview-record-focus":Math.round(e.plane)===0&&!e.aggregate&&!X&&!i?"":void 0,"data-graview-nested":e.nestedUnder??void 0,"data-graview-crowded":l||void 0,"data-graview-pinned":e.pinned||void 0,"data-graview-activity":c?c.manner:void 0,"data-graview-wrote":c?.wrote||void 0,"data-graview-read":c&&!c.wrote?!0:void 0,"data-graview-broke":c?.broke||void 0,title:c?`${Xr[c.manner]} ${c.wrote?"changed this":"read this"}: ${c.intent}`:e.aggregate&&Math.round(e.plane)!==0?`Open ${e.aggregate.label}`:void 0,role:"group","aria-label":C,"aria-keyshortcuts":M&&!e.beyond?M.key:void 0,tabIndex:0,onPointerDown:R,onPointerMove:O,onPointerUp:E,onPointerCancel:E,onClick:v=>{if(S.current)return;let N=v.target?.closest("input, textarea, select, button, a[href], [contenteditable='true']");if(N&&!N.hasAttribute("data-graview-pick"))return;let T=v.metaKey||v.shiftKey,G=At(v.target);if(G&&G!==e.id){v.stopPropagation(),x(G,T,Fn(v.target)??void 0);return}g(T)},onKeyDown:v=>{if(M&&!e.beyond&&v.key.toLowerCase()===M.key.toLowerCase()&&!v.metaKey&&!v.ctrlKey&&!v.altKey&&!v.target?.closest("input, textarea, select, [contenteditable='true']")){v.preventDefault(),v.stopPropagation();let re=At(v.target)??e.id;m.includes(re)||x(re,!1),M.open(v.target instanceof HTMLElement?v.target:v.currentTarget);return}if(v.key!=="Enter"&&v.key!==" "||v.target?.closest("input, textarea, select, button, [contenteditable='true']"))return;let T=At(v.target);if(v.preventDefault(),v.stopPropagation(),!T||T===e.id){m.length===1&&m[0]===e.id&&!v.metaKey&&!v.shiftKey?b():g(v.metaKey||v.shiftKey);return}let G=Fn(v.target);(G?m.length===G.length&&G.every(re=>m.includes(re)):m.length===1&&m[0]===T)&&!v.metaKey&&!v.shiftKey?p(T):x(T,v.metaKey||v.shiftKey,G??void 0)},onContextMenu:v=>{let N=At(v.target);v.preventDefault(),v.stopPropagation();let T=N&&N!==e.id?N:e.id;x(T,!1,(T===N?Fn(v.target):null)??void 0),f({x:v.clientX,y:v.clientY,on:T})},onDoubleClick:v=>{let N=At(v.target);if(N&&N!==e.id){v.stopPropagation(),p(N);return}b()},style:{position:"absolute",...t?{}:{pointerEvents:"none"},zIndex:e.opened?Te.opened:Te.card-Math.round(e.plane),left:t?0:Math.round(e.x),top:t?0:Math.round(e.y),width:Math.round(e.width),height:Math.round(e.height),boxSizing:"border-box",display:"flex",flexDirection:"column",justifyContent:"center",...z},children:[X?(0,Qt.jsx)("div",{ref:L,"data-graview-natural":`${Math.round(X.width)}x${Math.round(X.height)}`,style:{position:"absolute",left:"50%",top:"50%",width:X.width,height:X.height,transform:`translate(-50%, -50%) scale(${oe})`,transformOrigin:"50% 50%",display:"flex",flexDirection:"column"},children:j}):j,Math.round(e.plane)===0&&!e.aggregate?(0,Qt.jsxs)("span",{"data-graview-kindtag":"",className:"graview-kind-tag","aria-hidden":"true",style:{...B??{},"--graview-hue":Math.round(Mt(e.kind,k?.accents))},children:[(0,Qt.jsx)("span",{style:{width:9,height:6,clipPath:"polygon(50% 0, 100% 50%, 50% 100%, 0 50%)",flex:"0 0 auto",background:`hsl(${Math.round(Mt(e.kind,k?.accents))} 55% var(--graview-tint-lightness) / 0.9)`}}),zo(w.schema.tryDefinition(e.kind),e.kind)]}):null]})}var ue=ee(be(),1);var Ha=e=>e?{activity:e}:{},Da=e=>`${Math.round(e.x)} ${Math.round(e.y)}`,Bn=e=>e.stopPropagation(),ki=.6,Si=3,Fa=80,bi=e=>Math.round(e.plane)===1&&(e.compact===!0||e.width<175||e.height<Fa);function Ba(e){let[t,n]=(0,q.useState)(1),r=(0,q.useRef)(1);return(0,q.useEffect)(()=>{e||(r.current=1,n(1))},[e]),[t,r,n]}function ja(){let[e,t]=(0,q.useState)(void 0),n=(0,q.useCallback)(r=>t(r&&Math.round(r)),[]);return[e,n]}function Va(e){let[t,n]=(0,q.useState)({x:0,y:0}),r=(0,q.useMemo)(()=>({x:(e.pan?.x??0)+t.x,y:(e.pan?.y??0)+t.y}),[e.pan,t]),o=(0,q.useMemo)(()=>t.x===0&&t.y===0?e:pt(e,r),[e,t,r]),i=(0,q.useRef)(t);i.current=t;let a=(0,q.useCallback)((l,c)=>{let s=i.current,d=(u,h,g)=>Math.max(Math.min(-u,h),Math.min(Math.max(u,h),g+h))-h;return{x:d(l.x,s.x,c.x),y:d(l.y,s.y,c.y)}},[]);return[r,o,a,i,n]}function Wa(e,t,n,r,o,i){let a=n!==null&&!t.overview,l=a?null:n,c=(0,q.useMemo)(()=>{let h=t.pan?{...t,pan:void 0}:t;return l?Kt(h,l.id,{x:l.x,y:l.y}):h},[t,l]),s=(0,q.useMemo)(()=>On(e.graph,e.schema,c,r),[e,c,r,o]),d=(0,q.useMemo)(()=>n&&a?bo(s,n.id,{x:n.x,y:n.y})??On(e.graph,e.schema,Kt(c,n.id,{x:n.x,y:n.y}),r):s,[s,n,a,e,c,r]);return[(0,q.useMemo)(()=>vo(d,i??{x:0,y:0}),[d,i]),a]}function _a(){let[e,t]=(0,q.useState)(!1),[n,r]=(0,q.useState)(!1),o=(0,q.useRef)(null),i=(0,q.useRef)(()=>!1),a=(0,q.useCallback)(()=>{r(!0),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{o.current=null,!i.current()&&r(!1)},160)},[]);return[e,n,t,a,i,()=>{t(!1),r(!1)}]}function Ya(e){let t=(0,q.useRef)(!1),n=e!==null&&!t.current;return(0,q.useEffect)(()=>{e!==null&&(t.current=!0)},[e]),n}function za({registerScene:e,scheme:t,views:n},r,o){let i=(0,q.useRef)(r);i.current=r,(0,q.useEffect)(()=>(e({whereIs:a=>In(i.current,o.current,t,n,a)}),()=>e(null)),[e,t,n])}function Ka(e,t){(0,q.useEffect)(()=>{let n;return e.onActive(r=>{let o=t.current;if(!o)return;let i=l=>{let c=o.getBoundingClientRect();e.set({x:l.clientX-c.left,y:l.clientY-c.top})},a=()=>e.set(null);r?(o.addEventListener("pointermove",i),o.addEventListener("pointerleave",a),n=()=>{o.removeEventListener("pointermove",i),o.removeEventListener("pointerleave",a)}):(n?.(),n=void 0)})},[e])}function Ga(e,t,n,r,o){(0,q.useEffect)(()=>{if(e==="dom")return;let i=n.current;if(!i||!t)return;let a=new Set;for(let c of r.nodes)(o.has(c.id)||c.aggregate?.memberIds.some(s=>o.has(s)))&&a.add(c.id);let l=t({canvas:i,layout:r,dirty:a,hostOf:c=>i.querySelector(`[data-graview-view="${CSS.escape(c)}"]`)});return()=>{l?.()}},[e,t,r,o])}function Ua(){let e=ar();return t=>{let n=t?e.get(t.id):void 0,r=t?.aggregate?.memberIds??[];if(!n&&r.length===0)return;let o=n,i=n?.wrote??!1,a=n?.read??!1,l=n?.broke??!1;for(let c of r){let s=e.get(c);s&&(i||=s.wrote,a||=s.read,l||=s.broke,(!o||s.at>o.at||s.at===o.at&&s.wrote&&!o.wrote)&&(o=s))}return o?{...o,wrote:i,read:a,broke:l}:void 0}}var vi=(e,t)=>e.includes(t)?e.filter(n=>n!==t):[...e,t];function Xa(){let{views:e,view:t,setView:n,setSelection:r}=le(),o=Lt(),i=a=>{if($e(a.id)===null&&!a.aggregate)return!1;let l=e.resolve(a.kind,{cardinality:"many",fidelity:"full"})?.view;return l!==void 0&&l.generic!==!0};return a=>({onSelect:l=>{if(Gt(a.id)){r(s=>l?vi(s,a.id):[a.id]);return}let c=a.aggregate?Jt(a.id):[];if(t.overview){r(s=>l?[...new Set([...s,a.id])]:[a.id]);return}if(c.length===1&&!l&&Math.round(a.plane)!==0){let s=c[0];n(d=>Un(d,d.relation===s?null:s));return}r(s=>Po(a,s,l))},onPick:(l,c,s)=>r(d=>s?c?[...new Set([...d,...s])]:[...s]:c?vi(d,l):[l]),onTravel:l=>{n(c=>({...Ot(c,l),relation:null})),r([l])},onJackIn:()=>{let l=a.aggregate?.opens;if(l){l.in==="place"?n(d=>qn(d,a.id)):n(d=>Object.entries(l.within).reduce((u,[h,g])=>Xn(u,h,g),Ot(zt(d,!1),l.focus))),r([]);return}let c=$e(a.id),s=c!==null&&(o?.byKind[c]??0)>0;n(d=>Qn(d,a.id,{ownPicture:i(a),...s&&d.q?{carry:d.q}:{}})),r(a.aggregate?[]:[a.id])}})}function qa({node:e}){let{views:t,view:n,setView:r}=le();return(0,ue.jsxs)("div",{className:"graview-screen-grip","data-graview-grip":e.id,"data-testid":"screen-grip",title:"Move this picture \u2014 it stays by its own village",children:[(0,ue.jsx)("span",{className:"graview-screen-title","aria-hidden":"true",children:t.places().find(o=>o.as===n.within?.view&&o.kind===e.screenOf)?.title??""}),(0,ue.jsx)("button",{type:"button",className:"graview-screen-fullscreen","data-testid":"screen-fullscreen",title:"Open this picture on its own \u2014 leave the graview with it",onClick:o=>{o.stopPropagation(),r(i=>zt(i,!1))},onPointerDown:Bn,onDoubleClick:Bn,children:"Open \u2197"})]})}function Qa({zoom:e,zoomBy:t}){let n=(r,o,i,a)=>(0,ue.jsx)("button",{type:"button",className:"graview-zoom-button","data-testid":`zoom-${r}`,"aria-label":`Zoom ${r}`,title:`Zoom ${r} \u2014 or pinch, or ctrl+wheel`,disabled:a,onClick:()=>t(i),children:o});return(0,ue.jsxs)("div",{className:"graview-zoom","data-graview-foot":"",role:"group","aria-label":"Zoom",onPointerDown:Bn,onClick:Bn,children:[n("out","\u2212",1/1.25,e<=ki+1e-6),(0,ue.jsxs)("span",{className:"graview-zoom-level","data-testid":"zoom-level","aria-live":"polite",children:[Math.round(e*100),"%"]}),n("in","+",1.25,e>=Si-1e-6)]})}function Za({options:e,renderer:t="auto",attachRenderer:n,className:r,style:o,animate:i=!0,children:a}){let l=le(),{store:c,scheme:s,views:d,view:u,setView:h,selection:g,setSelection:x,setMenuAt:p,emphasis:f,brand:m,noteMoved:b,robots:R,seatTalk:O,motion:E}=l,S=eo(O),j=(0,q.useRef)(null),k=(0,q.useRef)(null),w=ni(k),M=ti(),C=sr(k,M,m),B=(0,q.useMemo)(()=>P=>Ut(P,132,C),[C]),{zoomAbout:A,panBy:$}=Ur({stage:k,view:u,setView:h}),D=It(),H=u.overview&&u.within?.view!==void 0?1.5:1,[Y,K,W]=Ba(u.overview),[ge,me]=ja(),X=mi(e,w,M,C,S,H*Y,ge,D),[oe,L,z,v,N]=Va(u),T=(0,q.useMemo)(()=>new Set(Object.keys(u.pins)),[u.pins]),G=zr(),[F,re]=Wa(c,u,G.held,X,D,L.pan),[ie,de,J,Ae,Se,et]=_a(),Ye=Ya(w),U=$r(F,{enabled:i&&!ie&&!de&&w!==null&&!Ye});(0,q.useEffect)(()=>E.set(ie||de||U.t<1),[E,ie,de,U]);let Le=Hr(),tt=Dr(),nt=F.nodes.find(P=>P.screenOf!==void 0)?.id??null,Fe=Yr({view:u,result:F,frame:U,panned:oe,closer:H,screenId:nt,setCamera:N});za(l,U,k),Ka(l.pointer,k),Ga(t,n,j,U,Le);let Je=t==="dom"||t==="auto"&&!n,ht=Ua(),Ne=Kr({stage:k,pan:u.pan,setView:h,settled:et});Se.current=Ne.settle;let{onGroundDown:ft,onCardDown:yt,onDragMove:ze,onDragUp:ot,swallow:Ie}=Gr({view:u,panned:oe,limit:()=>wt(F),panWithin:z,moveByTransform:Je,setView:h,setDragging:J,noteMoved:b,shift:Ne,district:G});A.current=(P,ae,he)=>{if(!u.overview)return;Se.current();let Re=K.current,it=Math.max(ki,Math.min(Si,Re*P));if(Math.abs(it-Re)<1e-4)return;K.current=it,Ae(),W(it);let at=k.current?.getBoundingClientRect(),Ke={x:F.width/2,y:F.height/2},Be=at&&ae!==void 0&&he!==void 0?{x:ae-at.left,y:he-at.top}:Ke,an=it/Re;h(Ft=>pt(Ft,wo(Ft.pan??{x:0,y:0},v.current,Be,Ke,an))),b()};let kt=(P,ae,he=wt(F))=>h(Re=>pt(Re,z(he,{x:(Re.pan?.x??0)+P,y:(Re.pan?.y??0)+ae})));$.current=(P,ae)=>{Ae();let he=wt(F),Re=u.pan??{x:0,y:0};if(Je){let it=Ne.offset();Ne.shiftTo(z(he,{x:Re.x+it.x+P,y:Re.y+it.y+ae}),Re)}else kt(P,ae,he);b()};let ne=Xa(),xe=P=>ht(U.nodes.find(ae=>ae.id===P)),rt=(P,ae,he,Re)=>P.originY+oe.y+ve(he.col+he.side/2,he.row+he.side/Re,P.cell).y-ae.y,Me={width:F.width,height:F.height},gt={position:"relative",zIndex:Te.stage,...Me},mt=P=>In(U,k.current,s,d,P),St=U.nodes.map(P=>(0,ue.jsxs)(wi,{node:P,crowded:bi(P),useDom:Je,...P.plot&&U.city&&Math.round(P.plane)===2?{frontY:rt(U.city,P,P.plot,1),centerY:rt(U.city,P,P.plot,2)}:{},...P.screenOf!==void 0?{screen:!0,...P.id===nt?{onDrawnHeight:me}:{}}:{},touched:Le.has(P.id),...Ha(ht(P)),scheme:s,canvasWidth:F.width,canvasHeight:F.height,selected:g.includes(P.id),...ne(P),onMenu:p,selection:g,onDragStart:ae=>yt(P,ae),onDragMove:ze,onDragEnd:ot,swallowClick:Ie,children:[P.screenOf!==void 0?(0,ue.jsx)(qa,{node:P}):null,P.beyond?(0,ue.jsx)(Qr,{kinds:P.beyond}):P.aggregate?.opens?(0,ue.jsx)(ei,{node:P}):(0,ue.jsx)(Zr,{node:P,mode:"scene",selected:g.includes(P.id),...bi(P)?{fidelity:"glyph"}:{}})]},P.id));return(0,ue.jsx)(dr.Provider,{value:B,children:(0,ue.jsxs)("div",{ref:k,className:`graview-ground${r?` ${r}`:""}`,"data-graview-altitude":u.overview?"":void 0,"data-graview-reach":U.city?Da(wt(F)):void 0,"data-graview-settled":U.t>=1&&!Fe.gliding()?"":void 0,onPointerDown:ft,onPointerMove:ze,onPointerUp:ot,onPointerCancel:ot,onClick:P=>{Ie.current||P.target.closest("[data-graview-view], button, aside, section[aria-label], [data-graview-offstage], a, input, select")||(x([]),p(null))},style:{position:"relative",width:"100%",height:"100%",cursor:ie?"grabbing":"grab",touchAction:"none","--graview-altitude":u.overview?1:0,...U.city?{"--graview-lattice-cell":`${U.city.cell.toFixed(2)}px`,"--graview-lattice-x":`${(U.city.originX+U.city.pan.x).toFixed(1)}px`,"--graview-lattice-y":`${(U.city.originY+U.city.pan.y).toFixed(1)}px`}:{},...ie?{userSelect:"none"}:{},overflow:"hidden",...o},children:[(0,ue.jsx)(Br,{frame:U,...Me,pan:U.city?U.city.pan:oe,brand:m,pinned:T,swallowed:Ie,onFocus:P=>{let ae=$e(P);ae!==null&&h(he=>Ot(he,Ee(ae)))}}),Je?(0,ue.jsx)("div",{"data-graview-stage":"dom","data-graview-world":"",style:{...gt,overflow:"hidden"},children:St}):(0,ue.jsx)("canvas",{ref:j,"data-graview-stage":"gpu",layoutsubtree:"",...Me,style:{display:"block",...gt},children:St}),u.overview&&!ie?(0,ue.jsx)(_r,{result:F,schema:c.schema,onGo:P=>{kt(P.x,P.y),b()}}):null,u.overview?(0,ue.jsx)(Qa,{zoom:Y,zoomBy:P=>A.current(P)}):null,(0,ue.jsx)(yi,{frame:U,holding:re,...Me,scheme:s,overview:!!u.overview,selection:g,emphasis:f,stageRef:k,store:c,graphNodes:D,onPickEdge:(P,ae)=>{Ie.current||(x([P]),p(ae?{...ae,on:P}:null))},liveOf:P=>{let ae=xe(P.from),he=xe(P.to);return ae?.wrote&&he?.wrote?ae.at>he.at?ae:he:void 0}}),(0,ue.jsx)(jr,{width:F.width,whereIs:mt}),(0,ue.jsx)(Fr,{marks:tt.marks,questions:[...R.values()].filter(P=>P.mode==="asking"&&P.at!==null&&P.say).map(P=>({id:P.at,who:P.who,asks:P.say})),whereIs:mt,stageRef:k,...Me}),(0,ue.jsx)(gi,{nodes:U.nodes,moving:U.t<1,holding:re,scheme:s,width:F.width,stageRef:k}),a]})})}var Ze=ee(He(),1);function Ja(){return Ei(),null}var Oi=()=>window.location.pathname.endsWith(Uo),Mi=()=>(Oi()?Zo:Gn)(window.location.hash),es=e=>(Oi()?Jo:Kn)(e);function Ei(){let{view:e,setView:t,views:n,principal:r}=le(),o=JSON.stringify(r),i=(0,Ze.useCallback)(d=>{let u=d.within?.view;if(u===void 0||d.focusId)return d;let h=n.places().find(g=>g.as===u);return h?{...d,focusId:Ee(h.kind)}:d},[n]),a=(0,Ze.useRef)(!1);(0,Ze.useEffect)(()=>{if(typeof window>"u")return;let d=i(Mi());!fn(d,zn)&&!fn(d,e)&&(a.current=!0,t(d))},[]),(0,Ze.useEffect)(()=>{if(typeof window>"u")return;let d=()=>t(i(Mi()));return window.addEventListener("popstate",d),window.addEventListener("hashchange",d),()=>{window.removeEventListener("popstate",d),window.removeEventListener("hashchange",d)}},[t,i]);let l=(0,Ze.useRef)(!1),c=(0,Ze.useRef)(null),s=(0,Ze.useRef)(o);(0,Ze.useEffect)(()=>{if(typeof window>"u")return;if(a.current){a.current=!1;return}let d=s.current!==o;s.current=o;let u=es(e),h=u||`${window.location.pathname}${window.location.search}`;if((window.location.hash||(window.location.href.includes("#")?"#":""))===u){l.current=!0,c.current=e;return}if(!l.current){l.current=!0,c.current=e,window.history.replaceState({graview:Nt.at},"",h);return}if(d||Pi(c.current,e)){window.history.replaceState({graview:Nt.at},"",h),c.current=e;return}c.current=e,window.history.pushState({graview:++Nt.at},"",h),Nt.depth=Nt.at,Nt.tell()},[e,o])}function Pi(e,t){return e?e.focusId===t.focusId&&e.relation===t.relation&&(e.overview??!1)===(t.overview??!1)&&(e.zoom??!1)===(t.zoom??!1)&&(e.past??!1)===(t.past??!1)&&e.expanded.join(",")===t.expanded.join(",")&&(e.shown??[]).join(",")===(t.shown??[]).join(",")&&ts(e.within,t.within):!1}function ts(e,t){let n=r=>Object.entries(r??{}).sort(([o],[i])=>o.localeCompare(i)).map(([o,i])=>`${o}=${i}`).join("&");return n(Ri(e))===n(Ri(t))}function Ri(e){if(!e||!("q"in e))return e;let{q:t,...n}=e;return n}var To=ee(He(),1);function ns(e={}){let{store:t,selection:n,principal:r,providers:o}=le(),{about:i,...a}=e,l=i??n,c=It();return(0,To.useMemo)(()=>{let s=[...new Set(l.flatMap(u=>Jt(u)))],d=l.map(u=>Rt(u)).filter(u=>u!==null);return hr(t,l,{principal:r,kindSelection:s,edgeSelection:d,...o?{providers:o}:{},...a})},[t,l,e,c,r,o])}function os(){let{store:e,principal:t}=le();return(0,To.useMemo)(()=>({preview:(n,r)=>yr(e,n,r??{}),apply:(n,r)=>fr(e,n,r??{},{author:t})}),[e,t])}export{Di as a,Zi as b,Ji as c,ea as d,ta as e,na as f,oa as g,Za as h,Ja as i,ns as j,os as k};