graview 0.1.39 → 0.1.41

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 (174) hide show
  1. package/dist/preview/{chunk.WQPNGBR7.js → chunk.242EUAPE.js} +1 -1
  2. package/dist/preview/chunk.2FGYWAID.js +1 -0
  3. package/dist/preview/{chunk.NSNGPQGT.js → chunk.2FLPDPEL.js} +1 -1
  4. package/dist/preview/{chunk.RXSHFG6S.js → chunk.2GQPLTV3.js} +1 -1
  5. package/dist/preview/chunk.2NB7U4EW.js +88 -0
  6. package/dist/preview/{chunk.Z7JRBKA7.js → chunk.2RVUDRRY.js} +1 -1
  7. package/dist/preview/{chunk.I7CU2E3C.js → chunk.33KXSD6F.js} +1 -1
  8. package/dist/preview/{chunk.WJQY4E45.js → chunk.3Q75TIGL.js} +1 -1
  9. package/dist/preview/{chunk.7WSXVXP3.js → chunk.3ZILIZZ6.js} +1 -1
  10. package/dist/preview/{chunk.HHUCPVG5.js → chunk.42XSBKPO.js} +1 -1
  11. package/dist/preview/chunk.4EEWBCT2.js +1 -0
  12. package/dist/preview/{chunk.23WYWIAJ.js → chunk.4Q7XJJZY.js} +1 -1
  13. package/dist/preview/{chunk.U7QMA4H7.js → chunk.4QPVS2ZM.js} +1 -1
  14. package/dist/preview/chunk.53CDFJNM.js +1 -0
  15. package/dist/preview/{chunk.CAMQ7MYJ.js → chunk.57R2GXXN.js} +1 -1
  16. package/dist/preview/chunk.5P556A7W.js +1 -0
  17. package/dist/preview/{chunk.5R4E5C76.js → chunk.5QXWMC6C.js} +1 -1
  18. package/dist/preview/{chunk.6XU2CXRZ.js → chunk.5RABSIF7.js} +1 -1
  19. package/dist/preview/{chunk.7EFNLMKU.js → chunk.67WWRC6Y.js} +1 -1
  20. package/dist/preview/{chunk.C2OAKTZX.js → chunk.6CRRPXKP.js} +1 -1
  21. package/dist/preview/{chunk.WXYUWBKX.js → chunk.6FNMDAX5.js} +1 -1
  22. package/dist/preview/chunk.6RID3OWK.js +1 -0
  23. package/dist/preview/{chunk.GXKECZ4S.js → chunk.6YPLZNVT.js} +1 -1
  24. package/dist/preview/{chunk.VC4JPG7O.js → chunk.7LIKEE5Z.js} +1 -1
  25. package/dist/preview/{chunk.LCYMYLOP.js → chunk.7YIFF6BF.js} +1 -1
  26. package/dist/preview/chunk.A4UIM35E.js +1 -0
  27. package/dist/preview/{chunk.2GGDOFTF.js → chunk.AIZQBPGU.js} +1 -1
  28. package/dist/preview/{chunk.EWWJMS6G.js → chunk.AKQXF7GW.js} +1 -1
  29. package/dist/preview/{chunk.N2SV3KX7.js → chunk.B5724ULM.js} +1 -1
  30. package/dist/preview/{chunk.CTK2P4JV.js → chunk.BELCPW66.js} +2 -2
  31. package/dist/preview/chunk.BFNVG5JE.js +1 -0
  32. package/dist/preview/{chunk.LP3QUPCE.js → chunk.BK6RWVRE.js} +1 -1
  33. package/dist/preview/{chunk.6CFP5UYP.js → chunk.BQRAIU5R.js} +1 -1
  34. package/dist/preview/{chunk.B7TB6YRZ.js → chunk.BXT6FDT4.js} +1 -1
  35. package/dist/preview/{chunk.FCXBCKED.js → chunk.C2PECN4C.js} +1 -1
  36. package/dist/preview/{chunk.QEXXLWEU.js → chunk.C4TSM4W5.js} +2 -2
  37. package/dist/preview/chunk.C7JKMOFC.js +1 -0
  38. package/dist/preview/{chunk.M5QFUGGG.js → chunk.D25XEVKO.js} +1 -1
  39. package/dist/preview/{chunk.EDC4EMIX.js → chunk.DGCMEDQA.js} +1 -1
  40. package/dist/preview/{chunk.P3JYH6HO.js → chunk.DL26BKT7.js} +1 -1
  41. package/dist/preview/{chunk.UB3O3QJQ.js → chunk.DMF35E7D.js} +1 -1
  42. package/dist/preview/{chunk.XLI44BBI.js → chunk.EAH47SCN.js} +1 -1
  43. package/dist/preview/{chunk.U4E5GQTK.js → chunk.EQ4UAWRB.js} +1 -1
  44. package/dist/preview/chunk.F2MQJH6Y.js +1 -0
  45. package/dist/preview/{chunk.37ASLBGE.js → chunk.FFZBOP65.js} +1 -1
  46. package/dist/preview/chunk.FOQZADMA.js +25 -0
  47. package/dist/preview/{chunk.OM5CDW2S.js → chunk.GT2BITLW.js} +1 -1
  48. package/dist/preview/{chunk.UIUHGA6W.js → chunk.H5ADMSE7.js} +1 -1
  49. package/dist/preview/{chunk.XBOZTQQA.js → chunk.H5HWN7A2.js} +1 -1
  50. package/dist/preview/{chunk.OYMM2UWE.js → chunk.H7POIT3V.js} +1 -1
  51. package/dist/preview/{chunk.CMN6VVK2.js → chunk.HB7ELBVK.js} +1 -1
  52. package/dist/preview/{chunk.WTZOOAIW.js → chunk.HEVC6HHP.js} +1 -1
  53. package/dist/preview/{chunk.CF7DHTKL.js → chunk.HI7X6PLZ.js} +2 -2
  54. package/dist/preview/{chunk.IXYBIDAN.js → chunk.HKCK3JI4.js} +1 -1
  55. package/dist/preview/{chunk.IAZRY42B.js → chunk.HPAGOEZG.js} +1 -1
  56. package/dist/preview/chunk.HPUN5DKZ.js +117 -0
  57. package/dist/preview/chunk.I4JBWTZM.js +2 -0
  58. package/dist/preview/{chunk.4BBJ62ZO.js → chunk.I7XSDXQ3.js} +1 -1
  59. package/dist/preview/{chunk.FMN5XDLE.js → chunk.ISXFH3CK.js} +1 -1
  60. package/dist/preview/chunk.J4IULZFD.js +1 -0
  61. package/dist/preview/chunk.JACGQ2PR.js +4 -0
  62. package/dist/preview/{chunk.YXGI7H4Y.js → chunk.JDRLSVOI.js} +1 -1
  63. package/dist/preview/chunk.JHEVGLKB.js +345 -0
  64. package/dist/preview/chunk.JLBGJSCZ.js +1 -0
  65. package/dist/preview/chunk.JYJ4LZJJ.js +5 -0
  66. package/dist/preview/{chunk.ZR5KVYWZ.js → chunk.L3A6YLMT.js} +2 -2
  67. package/dist/preview/{chunk.5JPRFXYQ.js → chunk.L4STJLUV.js} +1 -1
  68. package/dist/preview/{chunk.JEZTPXEB.js → chunk.LOCSF3BR.js} +1 -1
  69. package/dist/preview/{chunk.XLZ2QRRS.js → chunk.LOSMUESM.js} +1 -1
  70. package/dist/preview/chunk.LOZJQ5ZX.js +1 -0
  71. package/dist/preview/{chunk.TU4KG22J.js → chunk.LPNIEPYI.js} +2 -2
  72. package/dist/preview/{chunk.OJKS3UQS.js → chunk.LPYVOBWB.js} +1 -1
  73. package/dist/preview/{chunk.2NSTEREJ.js → chunk.M4T377LG.js} +1 -1
  74. package/dist/preview/{chunk.G46WGK5E.js → chunk.MSP73H5Z.js} +1 -1
  75. package/dist/preview/chunk.MUKDKVVC.js +1 -0
  76. package/dist/preview/chunk.MUPO5S2A.js +47 -0
  77. package/dist/preview/{chunk.P4WYBSYA.js → chunk.N2K25KH3.js} +1 -1
  78. package/dist/preview/{chunk.KJNUZYXS.js → chunk.N6MVK3KD.js} +1 -1
  79. package/dist/preview/{chunk.3ZNQ5YKX.js → chunk.NGDXH66B.js} +1 -1
  80. package/dist/preview/chunk.O6F3K6CU.js +1 -0
  81. package/dist/preview/chunk.O75JKQPF.js +1 -0
  82. package/dist/preview/{chunk.KSXB4LDF.js → chunk.OF34OZ4V.js} +1 -1
  83. package/dist/preview/chunk.OVTCW3AI.js +1 -0
  84. package/dist/preview/{chunk.HA3PPIEQ.js → chunk.OW7NSJ4H.js} +1 -1
  85. package/dist/preview/{chunk.ROKRQRID.js → chunk.PMDNFN7Z.js} +1 -1
  86. package/dist/preview/chunk.PMGXASFI.js +32 -0
  87. package/dist/preview/{chunk.JBTU2PJ4.js → chunk.Q4TZHWQX.js} +1 -1
  88. package/dist/preview/chunk.QHYXXZRD.js +1 -0
  89. package/dist/preview/chunk.QIV65FWE.js +1 -0
  90. package/dist/preview/{chunk.GP2F7TIN.js → chunk.RCM7NOPF.js} +2 -1
  91. package/dist/preview/{chunk.NG3YMQ36.js → chunk.RQGTHRRJ.js} +1 -1
  92. package/dist/preview/{chunk.F5UVEF2R.js → chunk.S2U5CEP4.js} +1 -1
  93. package/dist/preview/chunk.SADG5RMV.js +1 -0
  94. package/dist/preview/chunk.SCYQSXW4.js +1 -0
  95. package/dist/preview/{chunk.W4OX4BMP.js → chunk.SIGC3G7S.js} +1 -1
  96. package/dist/preview/chunk.T3BWINOF.js +1 -0
  97. package/dist/preview/{chunk.2BJRS3YJ.js → chunk.TGVUIFKD.js} +1 -1
  98. package/dist/preview/{chunk.AYHCQWSU.js → chunk.TIH2PDFH.js} +1 -1
  99. package/dist/preview/chunk.TKUNRFDE.js +1 -0
  100. package/dist/preview/{chunk.5XNVN4HE.js → chunk.TN5PYGU7.js} +1 -1
  101. package/dist/preview/{chunk.6DHHUBSC.js → chunk.TNESS3LQ.js} +1 -1
  102. package/dist/preview/{chunk.QMFUPTR4.js → chunk.UEXIKCLF.js} +1 -1
  103. package/dist/preview/chunk.UHI3D7JC.js +1 -0
  104. package/dist/preview/chunk.USZPOOLZ.js +1 -0
  105. package/dist/preview/chunk.UTWPZULC.js +1 -0
  106. package/dist/preview/{chunk.H5CZZZLX.js → chunk.UUBYFBPN.js} +1 -1
  107. package/dist/preview/{chunk.ROINZMNO.js → chunk.UWW6ZEPY.js} +2 -2
  108. package/dist/preview/{chunk.ZTMDU3OH.js → chunk.V3V47QRE.js} +1 -1
  109. package/dist/preview/{chunk.BYKR7NEE.js → chunk.V4KLBSC4.js} +1 -1
  110. package/dist/preview/chunk.V5MYKNL7.js +5 -0
  111. package/dist/preview/{chunk.C4CFYTCW.js → chunk.VCX3HEIE.js} +1 -1
  112. package/dist/preview/{chunk.DYNBWIPF.js → chunk.VDAMCTNL.js} +1 -1
  113. package/dist/preview/chunk.VIYECFKZ.js +6 -0
  114. package/dist/preview/{chunk.ITEF3U2E.js → chunk.VJXXCUKS.js} +1 -1
  115. package/dist/preview/{chunk.EBHKKOPO.js → chunk.VNUHESMZ.js} +1 -1
  116. package/dist/preview/{chunk.67USHK26.js → chunk.W3FTEJH5.js} +1 -1
  117. package/dist/preview/chunk.W4HBRXMY.js +1 -0
  118. package/dist/preview/{chunk.5OJJ2TKZ.js → chunk.WUKHYLQT.js} +2 -2
  119. package/dist/preview/{chunk.CC47O2DW.js → chunk.WVDKYUF3.js} +1 -1
  120. package/dist/preview/{chunk.BEC5ZH2L.js → chunk.XEKLEHC3.js} +1 -1
  121. package/dist/preview/{chunk.FILCNVGH.js → chunk.XFZKP4IF.js} +1 -1
  122. package/dist/preview/chunk.XOYJ26YB.js +1 -0
  123. package/dist/preview/{chunk.4PNFX3TX.js → chunk.YWNHCZQ5.js} +1 -1
  124. package/dist/preview/{chunk.4ECICQ2S.js → chunk.YYFLTMNN.js} +1 -1
  125. package/dist/preview/{chunk.B2IRADR2.js → chunk.Z5AB2DBF.js} +1 -1
  126. package/dist/preview/chunk.Z7BCIYDW.js +1 -0
  127. package/dist/preview/{chunk.C6X7CKU6.js → chunk.Z7LDT55A.js} +1 -1
  128. package/dist/preview/{chunk.2IX3CZNP.js → chunk.ZHLQWMV5.js} +1 -1
  129. package/dist/preview/{chunk.JCR3ECUM.js → chunk.ZOR6FKNI.js} +1 -1
  130. package/dist/preview/{chunk.STBJV6HJ.js → chunk.ZRLXVYPG.js} +1 -1
  131. package/dist/preview/{chunk.RM7NVN7B.js → chunk.ZRYSVOLA.js} +2 -2
  132. package/dist/preview/chunk.ZTMEESII.js +1 -0
  133. package/dist/preview/index.html +45 -43
  134. package/dist/preview/page.js +8 -8
  135. package/package.json +6 -6
  136. package/dist/preview/chunk.2HF54MYG.js +0 -1
  137. package/dist/preview/chunk.2RCNSHXK.js +0 -1
  138. package/dist/preview/chunk.546WEHEX.js +0 -47
  139. package/dist/preview/chunk.57OPL5WD.js +0 -1
  140. package/dist/preview/chunk.5ZMENPY4.js +0 -5
  141. package/dist/preview/chunk.6HBEYRJU.js +0 -1
  142. package/dist/preview/chunk.6L7IDF3J.js +0 -1
  143. package/dist/preview/chunk.ALDLAQ7V.js +0 -1
  144. package/dist/preview/chunk.BCHHBGM6.js +0 -1
  145. package/dist/preview/chunk.BL4S3I2N.js +0 -1
  146. package/dist/preview/chunk.BS3FX4PX.js +0 -1
  147. package/dist/preview/chunk.BTSXYZ6Z.js +0 -25
  148. package/dist/preview/chunk.BZSU4HH2.js +0 -1
  149. package/dist/preview/chunk.DAA7IDQ4.js +0 -1
  150. package/dist/preview/chunk.E3HXXUKY.js +0 -1
  151. package/dist/preview/chunk.EM4Y4YAD.js +0 -2
  152. package/dist/preview/chunk.FGDHEVH4.js +0 -1
  153. package/dist/preview/chunk.FJBQ4UP3.js +0 -32
  154. package/dist/preview/chunk.G23VFYGF.js +0 -88
  155. package/dist/preview/chunk.HFDYFPMJ.js +0 -1
  156. package/dist/preview/chunk.HGS32FT2.js +0 -1
  157. package/dist/preview/chunk.J3M2MZHG.js +0 -1
  158. package/dist/preview/chunk.KIJCOW25.js +0 -1
  159. package/dist/preview/chunk.L7DQKPJV.js +0 -117
  160. package/dist/preview/chunk.LP2DJ5ZB.js +0 -6
  161. package/dist/preview/chunk.N7N5OFPL.js +0 -1
  162. package/dist/preview/chunk.ORXFUK6F.js +0 -344
  163. package/dist/preview/chunk.OXTUXWMU.js +0 -1
  164. package/dist/preview/chunk.P5325GYR.js +0 -1
  165. package/dist/preview/chunk.PMER4LVT.js +0 -1
  166. package/dist/preview/chunk.PONWLTTB.js +0 -1
  167. package/dist/preview/chunk.QCF6Z2AZ.js +0 -1
  168. package/dist/preview/chunk.RWB4235L.js +0 -1
  169. package/dist/preview/chunk.SK33IHL2.js +0 -4
  170. package/dist/preview/chunk.TCUB6IDY.js +0 -1
  171. package/dist/preview/chunk.TJCTTJWE.js +0 -1
  172. package/dist/preview/chunk.UCZR33MK.js +0 -1
  173. package/dist/preview/chunk.UGCNMAPC.js +0 -1
  174. package/dist/preview/chunk.XDYAG276.js +0 -1
@@ -0,0 +1,4 @@
1
+ var __graviewPreload=(base,files)=>{if(typeof document>"u")return;const asked=globalThis.__graviewPreloaded??=new Set;for(const file of files){const href=new URL(file,base).href;if(asked.has(href))continue;asked.add(href);const link=document.createElement("link");link.rel="modulepreload";link.href=href;document.head.append(link)}};import{a as Bt,f as $t,g as bn}from"./chunk.Z7LDT55A.js";import{b as wn}from"./chunk.VNUHESMZ.js";import{a as Ne,b as No,c as Zt,d as ni,e as Bo}from"./chunk.N2K25KH3.js";import{h as ti}from"./chunk.NGDXH66B.js";import{e as Jr,p as Yn,q as ei}from"./chunk.67WWRC6Y.js";import{a as Zr}from"./chunk.VJXXCUKS.js";import{a as Xr,b as qr,c as Qr}from"./chunk.QIV65FWE.js";import{b as Wr,d as Vr}from"./chunk.UT6642FC.js";import{a as Yr,b as Lo,c as Io,f as To,g as Po,h as Co,i as zr,j as Xt,k as qt,o as Nt,p as Qt,q as Kr,r as Ur}from"./chunk.42XSBKPO.js";import{A as Fr,f as Lr,g as Kt,h as Ir,i as Tr,j as Pr,k as Cr,m as Vn,n as gn,o as xn,p as Ut,q as Ao,v as Nr,w as Br,x as $r,y as Hr,z as Dr}from"./chunk.OJGHDWI6.js";import{a as Gr,b as _r}from"./chunk.6FNMDAX5.js";import{c as jr}from"./chunk.2RVUDRRY.js";import{A as dt,Aa as Eo,B as vo,Ba as Ct,C as pn,Da as Ro,G as Ce,Ha as Oo,K as gt,R as Ie,T as ko,X as So,Y as Wn,Z as Tt,_ as ye,a as po,aa as Pt,b as yo,c as go,d as Er,e as Rr,f as Fn,h as Lt,ha as _t,j as pt,ja as Ar,k as xo,l as jn,m as fn,p as bo,r as we,s as Ae,t as Or,u as mn,ua as yn,v as Le,w as It,x as yt,y as wo,za as Mo}from"./chunk.FOQZADMA.js";import{a as Gt}from"./chunk.SDO3U72B.js";import{_b as hn,aa as wr,ba as Dn,da as cn,ea as zt,fa as At,ga as un,jd as kr,ka as vr,md as Sr,rd as Mr,sc as He}from"./chunk.V5MYKNL7.js";import{b as se}from"./chunk.AJZBJBMO.js";var oi={width:1200,height:760,focusSize:{width:1200,height:420},relationSize:{width:240,height:140},contextSize:{width:300,height:104},gap:16,unit:16};var ri=(e,t)=>e?`${e.edgeKind}|${e.direction}`:`raised|${t}`,Ht=(e,t,n)=>`${vo}${e}|${t}|${n}`;function zn(e,t){let n=e.map(()=>0),r=e.map((i,l)=>({size:i,index:l})).sort((i,l)=>i.size-l.size||i.index-l.index),o=Math.max(t,e.length),a=e.length;for(let{size:i,index:l}of r){let u=Math.max(1,Math.floor(o/a));n[l]=Math.min(i,u),o-=n[l],a-=1}return n}function Ho(e){return ri(e.via,e.node.kind)}function Jt(e,t,n=[]){let r=[],o=0;return e.forEach((a,i)=>{if(a<=0)return;let l=Math.min(t,Math.max(1,n[i]??1)),u=Math.max(a,l);if(r.length>0&&a<=t&&u<=o){r[r.length-1].push({run:i,cards:a,slots:u}),o-=u;return}let d=a,s=!0;for(;d>0;){let c=Math.min(t,d),h=s?Math.max(c,l):c;r.push([{run:i,cards:c,slots:h}]),d-=c,o=t-h,s=!1}}),r}function Do(e,t,n,r=[]){let o=zn(e,t*n);for(;Jt(o,t,r).length>n;){let a=-1;if(o.forEach((i,l)=>{i>1&&(a<0||i>o[a])&&(a=l)}),a<0)break;o[a]=o[a]-1}return o}function Va(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,a)=>({node:o,index:a,key:r(o)})).sort((o,a)=>{for(let i=0;i<o.key.length;i++)if(o.key[i]!==a.key[i])return o.key[i]-a.key[i];return o.index-a.index}).map(o=>o.node)}var Ya=5,za=(e,t)=>{for(let n=0;n<e.length;n++)if(e[n]!==t[n])return e[n]<t[n];return!1};function ii(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}:{}},a=[];for(let l of Jr(n.schema,r).groups)if(l.key!==n.exclude)if(l.buckets)for(let u of["decade","year","month"])a.push({by:l.key,bucket:u});else a.push({by:l.key});let i;return a.forEach((l,u)=>{let s=ti(e,{group:l},o).groups;if(s.length<2||s.length>t)return;let h=s.filter(w=>w.key!=="").reduce((w,f)=>w+f.nodes.length,0)/e.length;if(h<.5||s.some(w=>w.nodes.length>e.length*.75))return;let y=[-Math.round(h*100),Math.abs(s.length-Ya),u];(!i||za(y,i.score))&&(i={grouping:{by:l.by,...l.bucket?{bucket:l.bucket}:{},groups:s},score:y})}),i?.grouping}function Fo(e,t){let n=f=>({id:f.node.id,kind:f.node.kind,node:f.node,...f.via?{via:f.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 f of e){let p=ri(f.via,f.node.kind),v=o.get(p);v?v.push(f):o.set(p,[f])}let a=[...o.entries()].map(([f,p])=>({key:f,run:p,via:p[0].via,kinds:[...new Set(p.map(v=>v.node.kind))],members:[],whole:!1,extra:0})),i=zn(a.map(f=>f.run.length),t.budget);a.forEach((f,p)=>f.whole=f.run.length<=i[p]);let l=a.filter(f=>!f.whole),u=a.filter(f=>f.whole).reduce((f,p)=>f+p.run.length,0),d=Math.max(l.length,t.budget-u);for(let f of l){f.members=Va(f.run.map(v=>v.node),r,t.graph);let p=d-(l.length-1);f.kinds.length>1&&f.kinds.length<=p?f.byKind=!0:f.kinds.length===1&&(f.grouping=ii(f.members,p,{schema:t.schema,graph:t.graph,...f.via?{exclude:f.via.edgeKind}:{},...t.today?{today:t.today}:{}}))}let s=f=>f.byKind?f.kinds.length:f.grouping?f.grouping.groups.length:1;for(;l.reduce((f,p)=>f+s(p),0)>d;){let f=[...l].filter(p=>s(p)>1).sort((p,v)=>s(v)-s(p))[0];if(!f)break;f.grouping=void 0,f.byKind=!1}d-=l.reduce((f,p)=>f+s(p),0);let c=f=>f.byKind?f.kinds.some(p=>t.expanded.has(Ht(p,f.key,"kind"))):f.grouping?.groups.some(p=>t.expanded.has(Ht(f.kinds[0],f.key,$o(f.grouping,p.key)))),h=l.filter(f=>!f.grouping&&!f.byKind?!0:c(f)),y=zn(h.map(f=>f.members.length),Math.max(0,d));h.forEach((f,p)=>f.extra=d>0?y[p]:0);let w=[];for(let f of a){let{key:p,via:v}=f;if(f.whole){w.push(...f.run.map(n));continue}let k=g=>({id:g.id,kind:g.kind,node:g,...v?{via:v}:{}}),x=new Map(f.run.map((g,E)=>[g.node.id,E])),O=(g,E,I)=>{let A=[...g.slice(0,E)].sort((N,$)=>x.get(N.id)-x.get($.id));w.push(...A.map(k));let j=g.slice(E);if(j.length===0)return;let K=j[0].kind;w.push({id:Ht(K,p,I?`more:${I}`:"more"),kind:K,...v?{via:v}:{},aggregate:{kind:K,memberIds:j.map(N=>N.id),label:E>0?`${j.length} more ${t.plural(K).toLowerCase()}`:`${j.length} ${t.plural(K).toLowerCase()}`,opens:{in:"picture",focus:Le(K),within:I?{filter:I}:{}}}})},G=v&&t.focusId?`${v.edgeKind}:${t.focusId}`:void 0;if(f.byKind){let g=f.kinds.find(E=>t.expanded.has(Ht(E,p,"kind")));for(let E of f.kinds){let I=f.members.filter(A=>A.kind===E);if(E===g){let A=f.extra+1;I.length<=A?w.push(...I.map(k)):O(I,A-1,G);continue}w.push({id:Ht(E,p,"kind"),kind:E,...v?{via:v}:{},aggregate:{kind:E,memberIds:I.map(A=>A.id),label:t.plural(E),opens:{in:"place"}}})}continue}let F=f.grouping;if(!F){O(f.members,f.extra,G);continue}let Q=f.kinds[0],z=F.groups.find(g=>t.expanded.has(Ht(Q,p,$o(F,g.key))));for(let g of F.groups){if(g===z){let E=f.members.filter(A=>g.nodes.includes(A)),I=f.extra+1;if(E.length<=I)w.push(...E.map(k));else{let A=g.key!==""&&!g.key.includes(",")&&!F.bucket,j=[G,A?`${F.by}:${g.key}`:void 0].filter(Boolean).join(",")||void 0;O(E,I-1,j)}continue}w.push({id:Ht(Q,p,$o(F,g.key)),kind:Q,...v?{via:v}:{},aggregate:{kind:Q,memberIds:f.members.filter(E=>g.nodes.includes(E)).map(E=>E.id),label:g.label.charAt(0).toUpperCase()+g.label.slice(1),opens:{in:"place"}}})}}return w}var $o=(e,t)=>`${e.by}${e.bucket?`:${e.bucket}`:""}=${t||"none"}`;var Gn=300,ai=12,en=8,jo=19;var _n=(e,t=1)=>(e.length*8.4+16)*t;function vn(e){return e.description??`${e.direction==="in"?"\u2190":"\u2192"} ${cn(e.edgeKind).toLowerCase()}`}function Wo(e,t,n=1){let r=l=>_n(l,n),o=new Map;for(let l of e){let u=o.get(l.key);u?u.push(l):o.set(l.key,[l])}let a=[...o.values()].map(l=>{let u=Math.min(...l.map(s=>s.top)),d=l.filter(s=>s.top-u<=ai);return{key:l[0].key,text:l[0].text,left:Math.min(...d.map(s=>s.left)),right:Math.max(...d.map(s=>s.right)),top:u}});a.sort((l,u)=>l.top-u.top||l.left-u.left);let i=a.map(l=>{let u=Math.max(l.right-l.left,Math.min(Gn,r(l.text))),d=(l.left+l.right)/2;return{left:d-u/2,right:d+u/2}});return a.map((l,u)=>{let d=a.map((x,O)=>({other:x,at:O})).filter(({other:x})=>x!==l&&Math.abs(x.top-l.top)<=ai),s=d.filter(({other:x})=>x.right<=l.left).map(({other:x,at:O})=>i[O].right+en<=(x.right+l.left)/2?i[O].right+en:(x.right+l.left+en)/2),c=d.filter(({other:x})=>x.left>=l.right).map(({other:x,at:O})=>i[O].left-en>=(l.right+x.left)/2?i[O].left-en:(l.right+x.left-en)/2),h=Math.max(t.left,...s),y=Math.min(t.right,...c),w=l.right-l.left,f=i[u].right-i[u].left,p=Math.max(w,Math.min(f,y-h)),v=(l.left+l.right)/2,k=w>=p?l.left:Math.max(h,Math.min(v-p/2,y-p));return{key:l.key,text:l.text,left:k,width:p,top:l.top}})}function di(e,t,n,r,o=1){let a=l=>String(l).length*7.4,i=e.length*8.6+6+a(t)+14+(n>0?22+a(n):0);return{width:Math.max(i,r?184:0)*o,height:(r?38:22)*o,short:{width:i*o,height:22*o}}}function Dt(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 Vo=(e,t,n,r)=>{let o=Math.max(e.x,Math.min(t.x,e.x+e.width)),a=Math.max(e.y,Math.min(t.y,e.y+e.height));return Math.abs(o-t.x)/n+Math.abs(a-t.y)/r<.92},kn=4,si=.45;function Yo(e,t,n,r={},o={}){let a={};for(let b of e)a[b.kind]=b.count;let i={x:(r.left??0)+8,y:(r.top??0)+8,width:n.width-(r.left??0)-(r.right??0)-16,height:n.height-(r.top??0)-(r.bottom??0)-16},l=o.avoid??[],u=o.tilt??.5,d=b=>b.nameplate??{width:120,height:34,short:{width:90,height:20}},s=b=>e.map(M=>{let T=b.get(M.kind);return{card:M,plot:T,center:Zt(T.col+T.side/2,T.row+T.side/2,1,u)}}),c=(b,M)=>{let T=1/0,S=-1/0,P=1/0,L=-1/0;for(let{card:H,plot:Z,center:U}of b){let V=U.x*M,ne=U.y*M,X=Z.side*M/2,ce=H.opened>0?d(H).width:d(H).short.width;T=Math.min(T,V-Math.max(X+(H.count>12?30:0),ce/2)),S=Math.max(S,V+Math.max(X,ce/2)),P=Math.min(P,ne-X*u-M*si),L=Math.max(L,ne+X*u+kn+d(H).short.height)}return{minX:T,maxX:S,minY:P,maxY:L}},h=b=>{let M=4,T=160;for(let S=0;S<24;S++){let P=(M+T)/2,L=c(b,P);L.maxX-L.minX<=i.width&&L.maxY-L.minY<=i.height?M=P:T=P}return M},y=b=>{let M={...o.order?{order:o.order}:{},counts:a,...o.plots?{plots:o.plots}:{},pitch:b},T=No(t,M),S=No(t,{...M,upright:!0}),P=h(s(T)),L=h(s(S)),H=n.height>n.width&&L>=P?S:T;return{map:H,fitted:H===S?L:P}},w=[],f=new Map,p=0,v=(b,M={x:0,y:0})=>{let T=c(w,b),S=i.x+i.width/2-(T.minX+T.maxX)/2+M.x,P=i.y+i.height/2-(T.minY+T.maxY)/2+M.y;return{originX:S,originY:P,cell:b}},k=b=>{let{originX:M,originY:T,cell:S}=b,P=w.map(({center:Z})=>Z.y),L=Math.max(...P),H=Math.min(...P);return w.map(({card:Z,plot:U,center:V})=>{let ne=M+V.x*S,X=T+V.y*S,ce=U.side*S/2,ae=ce*u,Se=L===H?.5:(V.y-H)/(L-H);return{card:Z,plot:U,x:ne,y:X,halfW:ce,halfH:ae,depth:1-Se*.65}})},x=(b,M=!0)=>{let T=[];return[...b].sort((P,L)=>(L.card.weight??L.card.count)-(P.card.weight??P.card.count)||e.indexOf(P.card)-e.indexOf(L.card)).filter(P=>[d(P.card),d(P.card).short].some(L=>{let H=F(P,L),Z=(!M||H.x>=0&&H.y>=0&&H.x+H.width<=n.width&&H.y+H.height<=n.height)&&!T.some(U=>Dt(H,U,4))&&!b.some(U=>U!==P&&Vo(H,U,U.halfW,U.halfH))&&!l.some(U=>Dt(H,U,0));return Z&&T.push(H),Z})).length},O=b=>b.card.marquee?{x:b.x-b.card.marquee.width/2,y:b.y+b.halfH+kn+d(b.card).height,width:b.card.marquee.width,height:b.card.marquee.height}:null,G=(b,M,T)=>T.some(S=>{if(S===M)return!1;let P=O(S);return P!==null&&Dt(b,P,4)}),F=(b,M,T="under")=>T==="aside"?{x:b.x+b.halfW+kn,y:b.y-M.height/2,width:M.width,height:M.height}:T==="above"?{x:b.x-M.width/2,y:b.y-b.halfH-kn-si*E.cell-M.height,width:M.width,height:M.height}:{x:b.x-M.width/2,y:b.y+b.halfH+kn,width:M.width,height:M.height},Q=b=>b.some(M=>l.some(T=>Vo(T,M,M.halfW,M.halfH)||Dt(T,F(M,d(M.card).short),0))),z=b=>b.every(M=>{let T=F(M,d(M.card).short);return M.x-M.halfW>=0&&M.x+M.halfW<=n.width&&M.y-M.halfH>=0&&T.x>=0&&T.x+T.width<=n.width&&T.y+T.height<=n.height}),g={pitch:Ne,said:-1};for(let b of[Ne,Ne+1,Ne+2,Ne+3,Ne+5,Ne+7]){({map:f,fitted:p}=y(b)),w=s(f);let M=x(k(v(p)));if(M>g.said&&(g={pitch:b,said:M}),M===e.length)break}(g.pitch!==Ne+7||g.said!==e.length)&&({map:f,fitted:p}=y(g.pitch),w=s(f));let E=v(p);if(l.length>0&&Q(k(E))){let b;for(let M=1;M>=.3&&!b;M-=.05){let T=p*M,S=Math.max(...l.map(L=>L.width))/2+T,P=Math.max(...l.map(L=>L.height))/2+T/2;for(let L of[0,.5,.75,1,1.25]){for(let[H,Z]of[[1,0],[-1,0],[0,1],[0,-1],[1,1],[-1,1],[1,-1],[-1,-1]]){let U=v(T,{x:H*S*L,y:Z*P*L}),V=k(U);if(!Q(V)&&z(V)){b=U;break}if(L===0)break}if(b)break}}b&&(E=b)}let I=(b,M)=>{let T={x:n.width/2,y:n.height/2};return{cell:b.cell*M,originX:T.x+(b.originX-T.x)*M,originY:T.y+(b.originY-T.y)*M}},A=1;if(x(k(E))<e.length){let b={said:x(k(E),!1),area:1/0,pitch:-1,by:1},M={map:f,shape:w,fitted:p,where:E};for(let S of[Ne,Ne+1,Ne+2,Ne+3,Ne+5,Ne+7]){({map:f,fitted:p}=y(S)),w=s(f);let P=v(p);for(let L=1;L<=3.001;L+=.1){let H=x(k(I(P,L)),!1),Z=c(w,p*L),U=(Z.maxX-Z.minX)*(Z.maxY-Z.minY);if((H>b.said||H===b.said&&U<b.area)&&(b={said:H,area:U,pitch:S,by:L}),H===e.length)break}}b.pitch<0?{map:f,shape:w,fitted:p,where:E}=M:({map:f,fitted:p}=y(b.pitch),w=s(f),A=b.by,E=I(v(p),A));let T=k(E).filter(S=>o.keep?.includes(S.card.kind));if(T.length>0){let S=T.flatMap(V=>[{x:V.x-V.halfW,y:V.y-V.halfH,width:V.halfW*2,height:V.halfH*2},F(V,d(V.card))]),P=Math.min(...S.map(V=>V.x)),L=Math.max(...S.map(V=>V.x+V.width)),H=Math.min(...S.map(V=>V.y)),Z=Math.max(...S.map(V=>V.y+V.height)),U=(V,ne,X)=>ne-V>X-16?X/2-(V+ne)/2:V<8?8-V:ne>X-8?X-8-ne:0;E={...E,originX:E.originX+U(P,L,n.width),originY:E.originY+U(H,Z,n.height)}}}let j=o.zoom&&o.zoom!==1?o.zoom:1;j!==1&&(E=I(E,j));let K=k(E),N=[],$=new Map,Y=new Map,B=[...K].sort((b,M)=>(M.card.weight??M.card.count)-(b.card.weight??b.card.count)||e.indexOf(b.card)-e.indexOf(M.card));for(let b of B){let M=[["full",d(b.card),"under"],["short",d(b.card).short,"under"]],T="none",S=b===B[0],P=(H,Z)=>M.filter(([U])=>U.startsWith(Z)).map(([U,V,ne])=>[U,V,ne,H]),L=S?[...P(!1,"full"),...P(!1,"short"),...P(!0,"full"),...P(!0,"short")]:M.map(([H,Z,U])=>[H,Z,U,!1]);for(let[H,Z,U,V]of L){let ne=F(b,Z,U);if((j!==1||A!==1||ne.x>=0&&ne.y>=0&&ne.x+ne.width<=n.width&&ne.y+ne.height<=n.height)&&!N.some(ae=>Dt(ne,ae,4))&&(V||!K.some(ae=>ae!==b&&Vo(ne,ae,ae.halfW,ae.halfH)))&&!G(ne,b,K)&&!l.some(ae=>Dt(ne,ae,0))){T=H,N.push(ne),Y.set(b.card.id,ne);break}}$.set(b.card.id,T)}let J=K.map(b=>({id:b.card.id,x:b.x-b.halfW,y:b.y-b.halfH,width:b.halfW*2,height:b.halfH*2+(b.card.opened>0?Math.max(b.card.openedMin??0,b.card.opened):0),depth:b.depth,plot:b.plot,nameplate:$.get(b.card.id)??"none"})),R=c(w,E.cell),D={cell:E.cell,originX:E.originX,originY:E.originY,pan:o.pan??{x:0,y:0},extent:{x:E.originX+R.minX,y:E.originY+R.minY,width:R.maxX-R.minX,height:R.maxY-R.minY},openedShare:1,...u!==.5?{tilt:u}:{},...Y.size>0?{nameplates:K.flatMap(b=>{let M=Y.get(b.card.id);return M?[{id:b.card.id,x:M.x-(b.x-b.halfW),y:M.y-(b.y-b.halfH),width:M.width,height:M.height}]:[]})}:{},...K.some(b=>b.card.marquee)?{showings:K.flatMap(b=>{let M=O(b);return M?[{id:b.card.id,x:M.x-(b.x-b.halfW),y:M.y-(b.y-b.halfH),width:M.width,height:M.height}]:[]})}:{}};return{placed:J,frame:D,map:f}}function xt(e){let{width:t,height:n}=e.visible??e,r={x:t*.45,y:n*.45};if(!e.city)return r;let{extent:o}=e.city,a=24;return{x:Math.max(r.x,o.x+o.width-t+a,-o.x+a),y:Math.max(r.y,o.y+o.height-n+a,-o.y+a)}}var Kn=48;function zo(e){if(!e.city)return[];let{width:t,height:n}=e.visible??e,r=[];for(let o of e.nodes){if(!o.id.startsWith("kind:")||Math.round(o.plane)!==2)continue;let a=o.x+o.width/2,i=o.y+o.height/2,l=a<0?"left":a>t?"right":i<0?"top":i>n?"bottom":null;if(!l)continue;let u=l==="left"||l==="right",d=u?Math.max(0,Math.min(n,i)):Math.max(0,Math.min(t,a)),s=(y,w)=>y<w/4?w/4-y:y>w*3/4?w*3/4-y:0,c=(y,w)=>y<Kn?Kn-y:y>w-Kn?w-Kn-y:0,h=u?{x:s(a,t),y:c(i,n)}:{x:c(a,t),y:s(i,n)};r.push({id:o.id,kind:o.id.slice(5),side:l,along:d,by:h})}return r}function Go(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 Ga={rankOf:()=>{},parentOf:()=>{}};function li(e,t){if(t.size===0)return Ga;let n=e.kinds,r=new Map,o=(d,s)=>{d!==s&&((r.get(d)??r.set(d,new Set).get(d)).add(s),(r.get(s)??r.set(s,new Set).get(s)).add(d))};for(let d of n){let s=e.tryDefinition(d);if(s)for(let c of Object.values(s.edges??{})){let h=c.to==="*"?n:c.to;for(let y of h)o(d,y)}}let a=new Map,i=new Map,l=[...t].filter(d=>n.includes(d));for(let d of l)a.set(d,0);let u=0;for(;l.length>0;){u+=1;let d=[];for(let s of[...l].sort((c,h)=>n.indexOf(c)-n.indexOf(h)))for(let c of[...r.get(s)??[]].sort((h,y)=>n.indexOf(h)-n.indexOf(y)))a.has(c)||(a.set(c,u),u===2&&i.set(c,s),d.push(c));l=d}return{rankOf:d=>{let s=a.get(d);if(s!==0)return s===1?"primary":"secondary"},parentOf:d=>i.get(d)}}function ci(e,t,n,r,o={}){if(n){let a=new Map;for(let i of e.allEdges()){if(r&&i.kind!==r)continue;let l=i.from===n.id?i.to:i.to===n.id?i.from:null;if(l===null||l===n.id)continue;let u=e.getNode(l);if(!u||a.has(l))continue;let d=i.from===n.id?"out":"in",s=d==="out"?n.kind:u.kind,c=_a(t,s,i.kind,d);a.set(l,{node:u,via:{edgeKind:i.kind,direction:d,...c?{description:c}:{}}})}if(a.size>0){let i=l=>`${l.via.edgeKind}|${l.via.description??""}`;return[...a.values()].sort((l,u)=>(i(l)<i(u)?-1:i(l)>i(u)?1:0)||dt(l.node,u.node))}}if(n){let a=o[n.id]??[],i=new Set,l=[];for(let u of a){if(u===n.id||i.has(u))continue;let d=e.getNode(u);d&&(r&&r!=="judges"&&d.kind!==r||(i.add(u),l.push({node:d,via:{edgeKind:"judges",direction:"out",description:"what it finds wrong"}})))}if(l.length>0)return l.sort((u,d)=>dt(u.node,d.node))}return r?e.allNodes().filter(a=>a.kind===r).sort(dt).map(a=>({node:a})):[]}function _a(e,t,n,r){let a=e.tryDefinition(t)?.edges?.[n];return r==="out"?a?.description:a?.inverse}function ui(e,t,n){let r=new Map,o=[...t.values()].sort((d,s)=>d.plane-s.plane);for(let d of o)for(let s of d.aggregate?.memberIds??[])!t.has(s)&&!r.has(s)&&r.set(s,d.id);let a=d=>t.get(d)??t.get(r.get(d)??""),i=new Map,l=new Map,u=new Map;for(let d of e.allEdges()){let s=a(d.from),c=a(d.to);if(!s||!c||s.id===c.id&&!(n.overview&&s.aggregate&&s.plane===2))continue;let h=`${d.kind}:${s.id}:${c.id}`,y=i.get(h);if(y){let w=`${d.from}
2
+ ${d.to}`,f=l.get(h);if(f.has(w))continue;if(f.add(w),u.get(h).push({from:d.from,to:d.to}),y.single){let{single:p,...v}=y;i.set(h,v)}continue}l.set(h,new Set([`${d.from}
3
+ ${d.to}`])),u.set(h,[{from:d.from,to:d.to}]),i.set(h,{id:h,kind:d.kind,from:s.id,to:c.id,edges:[{from:d.from,to:d.to}],single:{from:d.from,to:d.to},...s.id===c.id?{loop:!0}:{},x1:s.x+s.width/2,y1:s.y+s.height/2,x2:c.x+c.width/2,y2:c.y+c.height/2})}return[...i.values()].map(d=>({...d,edges:u.get(d.id)})).sort(dt)}var fi=.85,hi=60,_o=160;function Ka(e,t,n,r,o,a=fi){let i=e*t.width+Math.max(0,e-1)*n,l=Math.max(n,(r-i)/2);return Array.from({length:e},(u,d)=>({x:l+d*(t.width+n),y:o,depth:a}))}function Un(e,t,n,r={}){let o={...oi,...r},a=Math.max(8,o.unit??16)/16,i=o.inset?.left??0,l=n.overview?Math.max(0,o.dock?.right??0):0,u=n.overview?Math.max(0,o.dock?.bottom??0):0,d=o.width-l-i-(o.inset?.right??0),s=[],c=new Map,h=m=>n.past===!0||wr(t.tryDefinition(m.kind),m,o.today),y=new Set(r.hiddenKinds??[]),w=m=>!y.has(m.kind),f=n.focusId?yt(n.focusId).filter(m=>t.tryDefinition(m)!==void 0).filter(m=>!y.has(m)):[];n.focusId&&yt(n.focusId).length>0&&f.length===0&&(n={...n,focusId:null});let p=n.focusId?e.getNode(n.focusId):void 0;p&&!w(p)&&(n={...n,focusId:null},f=[]);let v=f.length>0?[...e.allNodes()].filter(m=>f.includes(m.kind)).sort(dt):[],k=v.filter(w).filter(h),x=v.length-k.length,O=n.focusId&&f.length===0?e.getNode(n.focusId):void 0,G=n.zoom===!0&&!n.overview&&n.focusId!==null,F=Math.max(56,o.height*.062),Q=Math.min(o.height*.895,o.height-F),z=G?O!==void 0?{focusY:o.height*.03,focusH:o.height*.58,relationY:o.height*.645,relationH:o.height*.2,contextY:Q,contextH:F}:{focusY:o.height*.03,focusH:o.height*.71,relationY:o.height*.765,relationH:o.height*.1,contextY:Q,contextH:F}:O===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 m=o.height,W=m*.04,_=Math.max(m*.42,Math.min(m*.56,300)),oe=W+_+m*.06;return{focusY:W,focusH:_,relationY:oe,relationH:Math.max(m*.12,m*.878-m*.068-oe),contextY:m*.878,contextH:m*.092}})(),g=Math.min(o.headroom??0,z.focusY+z.focusH*.2),E=g>z.focusY?{...z,focusY:g,focusH:z.focusH-(g-z.focusY)}:z,I=m=>Math.min(o.gap*m,Math.round(d*.1)),A=G?Math.min(880,d-I(5)):Math.min(700,d-I(6)),j=G?d-I(5):Math.min(o.focusSize.width,d-I(6)),K=(m,W,_)=>({width:m===0?W:Math.min(W,(d-o.gap*(m+1))/m),height:_}),N=(m,W,_)=>{let oe=K(m,W,_),be=Math.min(W,_o*a,d-o.gap*2);return oe.width>=be?oe:{width:be,height:_}},$=m=>Math.max(1,Math.floor((d-o.gap)/(Math.min(m,_o*a,d-o.gap*2)+o.gap))),Y=new Set(n.expanded),B=n.overview?[]:ci(e,t,O,n.relation,o.judged).filter(m=>w(m.node)).filter(m=>h(m.node)),J=n.overview?0:Math.max(0,hi*a-E.contextH),R=B.length>0?E.focusH:E.contextY-E.focusY-o.gap*2-J,D=j,b=o.height,M=Math.min(d*.5/D,o.height*.48/b),T=D*M,S=b*M,P=new Set(r.plainGroups??[]),L=n.overview&&!O&&f.length>0&&n.focusId!==null,H=L&&f.length>0&&f.every(m=>P.has(m));if(L)for(let m of f)H&&r.besideTheMap!==!0?Y.add(we(m)):Y.delete(we(m));let Z=L&&!H&&f.length===1?f[0]:void 0,U=Z!==void 0&&(r.screens?.[Z]?.length??0)>0,V,ne=n.overview===!0&&O!==void 0&&r.besideTheMap===!0;n.overview&&(O||f.length>0)&&n.focusId&&!H&&!U&&!(L&&r.besideTheMap===!0)&&!ne?(V={x:i+(d-T)/2,y:o.height*.53-S/2,width:T,height:S},ln({id:n.focusId,kind:O?O.kind:f[0],plane:0,x:V.x,y:V.y,width:T,height:S,natural:{width:D,height:b},...O?{}:{aggregate:{kind:f.join("+"),memberIds:k.map(m=>m.id),label:r.plurals?.[n.focusId]??f.map(m=>At(t,m)).join(" and "),...x>0?{retired:x}:{}}}})):n.overview||(O?ln({id:O.id,kind:O.kind,plane:0,x:i+(d-A)/2,y:E.focusY,width:A,height:R}):f.length>0&&n.focusId&&ln({id:n.focusId,kind:f[0],plane:0,x:i+(d-j)/2,y:E.focusY,width:j,height:R,aggregate:{kind:f.join("+"),memberIds:k.map(m=>m.id),label:r.plurals?.[n.focusId]??f.map(m=>At(t,m)).join(" and "),...x>0?{retired:x}:{}}}));let X=26,ce=52,ae=22,Se=Math.round(o.relationSize.width*.75),ke=Math.max(1,Math.floor((d-o.gap)/(Se+o.gap))),Re=o.unit/16,Te=new Map;for(let m of B){let W=Ho(m),_=Te.get(W);_?_.push(m):Te.set(W,[m])}let Pe=[...Te.values()],re=Pe.length>1,ee=Math.max(o.gap,ae*Re),et=re?ee:o.gap,St=Math.max(2,Math.floor((E.relationH+et)/(X*Re+et))),an=Math.min(o.relationSize.width,(d-o.gap*(ke+1))/ke)+o.gap,_e=Pe.map(m=>{let W=m[0].via;return!re||!W?1:Math.ceil((Math.min(Gn*Re,_n(vn(W),Re))+o.gap)/an)}),Be=Pe.map(m=>m.length),ut=Jt(Be,ke,_e),Ke=B.length>ke*St||ut.length>St,tt={schema:t,graph:e,focusId:O?.id,expanded:Y,...o.relevance?{relevance:o.relevance}:{},...n.selection?{selection:n.selection}:{},plural:m=>At(t,m),...o.today?{today:o.today}:{}},Oe=Ke||re?ee:o.gap,Ye,$e;if(!Ke)Ye=Pe.flat().map(m=>({id:m.node.id,kind:m.node.kind,node:m.node,...m.via?{via:m.via}:{}})),$e=ut;else{let m=Math.max(1,Math.floor((E.relationH+Oe)/(ce*Re+Oe))),_=Jt(Be.map(()=>1),ke,_e).length<=m?_e:[],oe=Do(Be,ke,m,_),be=Pe.map((me,Ee)=>Fo(me,{...tt,budget:oe[Ee]}));Ye=be.flat(),$e=Jt(be.map(me=>me.length),ke,_)}let Fe=$e.length,Mt=Fe===1?E.relationH:(E.relationH-Oe*(Fe-1))/Fe,Ue=K(Math.max(...$e.map(m=>m.reduce((W,_)=>W+_.slots,0)),1),Ye.length<=2?Math.round(o.relationSize.width*1.35):o.relationSize.width,Mt),it=[];{let m=Ue.width+o.gap,W=[],_=0,oe=new Map;for(let me of $e.flat())oe.set(me.run,(oe.get(me.run)??0)+me.cards);for(let me=0;me<Pe.length;me++)W[me]=_,_+=oe.get(me)??0;let be=Pe.map(()=>0);$e.forEach((me,Ee)=>{let st=me.reduce((mt,fo)=>mt+fo.slots,0),$n=st*Ue.width+Math.max(0,st-1)*o.gap,Hn=i+Math.max(o.gap,(d-$n)/2),Fa=E.relationY+Ee*(Mt+Oe);for(let mt of me){let fo=mt.slots*m-o.gap,ja=mt.cards*m-o.gap,Wa=Hn+(fo-ja)/2;for(let mo=0;mo<mt.cards;mo++)it[W[mt.run]+be[mt.run]++]={x:Wa+mo*m,y:Fa};Hn+=mt.slots*m}})}Ye.forEach((m,W)=>{let _=it[W];ln({id:m.id,kind:m.kind,plane:1,x:_.x,y:_.y,width:Ue.width,height:Ue.height,...m.via?{via:m.via}:{},...m.aggregate?{aggregate:m.aggregate}:{},...Ke&&!m.aggregate?{compact:!0}:{}})});let Et=new Set(c.keys());for(let m of k)Et.add(m.id);let Xe=new Map;for(let m of e.allNodes()){let W=Xe.get(m.kind);W?W.push(m):Xe.set(m.kind,[m])}let ie=new Set(f.length>0?f:O?[O.kind]:[]),ve=[];for(let m of t.kinds){if(y.has(m))continue;let W=Xe.get(m)??[],_=W.filter(h);ve.push({id:we(m),kind:m,members:_.sort(dt),retired:W.length-_.length,...ie.has(m)?{focused:!0}:{}})}for(let m of ve)m.kind===n.relation&&(m.raised=!0);ve.sort(dt);let nt=li(t,ie),Rt=!n.overview&&t.kinds.some(m=>nt.rankOf(m)==="primary"),je=[];for(let m of ve)if(!n.overview&&Y.has(m.id)&&m.members.length>0)for(let W of m.members)je.push({id:W.id,kind:W.kind});else{let W=Rt?nt.rankOf(m.kind):void 0,_=W==="secondary"?nt.parentOf(m.kind):void 0;je.push({id:m.id,kind:m.kind,...m.raised?{raised:!0}:{},...m.focused?{focused:!0}:{},...n.overview&&Y.has(m.id)?{opened:!0}:{},...W?{rank:W}:{},..._&&!Y.has(we(_))?{nestedUnder:we(_)}:{},aggregate:{kind:m.kind,memberIds:m.members.map(oe=>oe.id),label:r.plurals?.[m.kind]??At(t,m.kind),...m.retired>0?{retired:m.retired}:{}}})}let Ot=2;if(je.length<=$((G?240:o.contextSize.width)*a))for(let m of je)delete m.nestedUnder;let sn=new Map;for(let m of je){if(m.nestedUnder===void 0)continue;let W=sn.get(m.nestedUnder)??0;W>=Ot?delete m.nestedUnder:sn.set(m.nestedUnder,W+1)}let dn=je.filter(m=>m.nestedUnder!==void 0),ht=je.filter(m=>m.nestedUnder===void 0),Vt=$((G?240:o.contextSize.width)*a),C=!n.overview&&ht.length>Vt,he=Math.max(0,Vt-1),xe=m=>m.focused?0:m.raised?1:2,Me=new Set([...ht].map((m,W)=>({item:m,at:W})).sort((m,W)=>xe(m.item)-xe(W.item)||m.at-W.at).slice(0,he).map(({item:m})=>m.id)),qe=new Set(C?ht.filter(m=>!Me.has(m.id)).map(m=>m.id):[]),Yt=dn.filter(m=>!qe.has(m.nestedUnder)),In=dn.filter(m=>qe.has(m.nestedUnder)),ft=C?[...ht.filter(m=>Me.has(m.id)),{id:Or,kind:"",beyond:[...ht.filter(m=>qe.has(m.id)),...In].map(m=>m.kind)}]:ht,at=n.overview?{width:Math.min(220,d/6.5),height:Math.min(92,o.height*.125)}:N(ft.length,(G?240:o.contextSize.width)*a,E.contextH),Tn=o.relevance?.flagged,Pn=(m,W)=>{let _=Bo(t,m);if(!_)return{};let oe=_.values.map(()=>0),be=0;for(let me of W){let Ee=_.values.indexOf(e.getNode(me)?.[_.field]);Ee<0?be++:oe[Ee]++}return{states:{field:_.field,values:[..._.values.map((me,Ee)=>({value:me,tier:_.tiers[Ee],count:oe[Ee]})),...be>0?[{value:null,tier:"waiting",count:be}]:[]]}}},ot=n.overview?Yo(ft.map(m=>{let W=m.aggregate?.memberIds??[],_=Tn?W.filter(oe=>Tn.has(oe)).length:0;return{id:m.id,kind:m.kind,count:W.length,opened:Y.has(m.id)?qt(Xt(W.length))*a:0,openedMin:Y.has(m.id)?qt(Math.min(Co,Xt(W.length)))*a:0,nameplate:di(m.aggregate?.label??At(t,m.kind),W.length,_,Bo(t,m.kind)!==void 0,a),weight:_*1e3+W.length,...f.includes(m.kind)&&(r.screens?.[m.kind]?.length??0)>0?{marquee:{width:Io+12,height:To(r.screens[m.kind].map(oe=>oe.title),Io,r.nameWidth)+8}}:{}}}),t,{width:o.width-l,height:o.height-u},o.chrome?{...o.inset,right:Math.min(o.inset?.right??0,8)}:o.inset??{},{...o.cityOrder?{order:o.cityOrder}:{},...o.plots?{plots:o.plots}:{},...r.cityZoom&&r.cityZoom!==1?{zoom:r.cityZoom}:{},keep:[...n.selection??[],...n.focusId?[n.focusId]:[]].flatMap(m=>m.startsWith("kind:")?[m.slice(5)]:m.startsWith("aggregate:")&&!m.includes("|")?[m.slice(10)]:ne&&m===O?.id?[O.kind]:[]),...r.tilt!==void 0?{tilt:r.tilt}:{},pan:{x:n.pan?.x??0,y:n.pan?.y??0},...V||o.chrome?.length?{avoid:[...V?[V]:[],...o.chrome??[]]}:{}}):null,gr=new Map(ot?.placed.map(m=>[m.id,m.plot])??[]),xr=new Map(ot?.placed.map(m=>[m.id,m.nameplate])??[]),lo=ot?ot.placed.map(({x:m,y:W,depth:_,width:oe,height:be})=>({x:m,y:W,depth:_,width:oe,height:be})):Ka(ft.length,at,o.gap,d,E.contextY,G?.97:fi).map(m=>({...m,x:m.x+i})),$a=.74,Cn=.8,Ha=52*a,Da=86*a,co=(m,W)=>Math.min(1,m+(1-m)*W),uo=new Map;ft.forEach((m,W)=>{let _=lo[W],oe=_.width??at.width,be=_.height??at.height,me=m.rank==="secondary"?$a:1,Ee=ot?oe:Math.max(Math.min(oe,_o*a),oe*me),st=ot?be:Math.max(hi*a,be*me);uo.set(m.id,{x:_.x+(oe-Ee)/2,y:_.y+(be-st),depth:m.rank==="secondary"?co(_.depth,.5):_.depth,width:Ee,height:st})});let Nn=[],Bn=lo[lo.length-1],ho=new Map;for(let m of Yt)ho.set(m.nestedUnder,(ho.get(m.nestedUnder)??0)+1);let br=new Map;for(let m of Yt){let W=uo.get(m.nestedUnder);if(W){let _=ho.get(m.nestedUnder)??1,oe=br.get(m.nestedUnder)??0;br.set(m.nestedUnder,oe+1);let be=.98,me=at.width*Cn,Ee=Math.max(Da,Math.min(me,W.width/(be*(_-1)+1))),st=Math.max(Ha,at.height*Cn*(Ee/me)),$n=Ee*be,Hn=(_-1)*$n+Ee;Nn.push({...m,x:W.x+(W.width-Hn)/2+oe*$n,y:Math.max(0,W.y-st+Math.min(st*.5,16)),width:Ee,height:st,depth:co(W.depth,.8)})}else if(Bn){let _=at.width*Cn,oe=at.height*Cn;Nn.push({...m,x:Bn.x,y:Bn.y,width:_,height:oe,depth:co(Bn.depth??1,.8)})}}for(let m of ft)Nn.push({...m,...uo.get(m.id)});return Nn.forEach(m=>{ln({id:m.id,kind:m.kind,plane:2,x:m.x,y:m.y,width:m.width,height:m.height,...m.aggregate?{aggregate:m.aggregate}:{},...m.raised?{raised:!0}:{},...m.focused?{focused:!0}:{},...m.opened?{opened:!0}:{},...m.opened?{openedRows:Math.max(1,Math.floor((Math.max(qt(Math.min(Co,Xt(m.aggregate?.memberIds.length??0))),qt(Xt(m.aggregate?.memberIds.length??0))*(ot?.frame.openedShare??1))-zr)/Po))}:{},...m.rank?{rank:m.rank}:{},...m.nestedUnder?{nestedUnder:m.nestedUnder}:{},...m.beyond?{beyond:m.beyond}:{},...gr.has(m.id)?{plot:gr.get(m.id)}:{},...xr.has(m.id)?{nameplate:xr.get(m.id)}:{},...ot&&m.aggregate?Pn(m.kind,m.aggregate.memberIds):{},depth:m.depth})}),{nodes:s,connectors:ui(e,c,n),width:o.width,height:o.height,...ot?{city:ot.frame}:{},...l>0||u>0?{visible:{width:o.width-l,height:o.height-u}}:{}};function ln(m){let W=n.overview&&Ae(m.id)!==null?void 0:n.pins[m.id],_=W?{...m,x:W.x,y:W.y,pinned:!0}:{...m,pinned:!1},oe=n.pan?{..._,x:_.x+n.pan.x,y:_.y+n.pan.y}:_;s.push(oe),c.set(oe.id,oe)}}function Ko(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},a=o.x+o.width/2,i=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:a,y1:i}:l.to===t?{...l,x2:a,y2:i}:l)}}function Uo(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 ge=(e,t,n)=>e+(t-e)*n;function mi(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}var pi=new WeakMap;function Ua(e){let t=pi.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 a of o.aggregate?.memberIds??[]){let i=r.get(a);i?i.push(o):r.set(a,[o])}}return t={byId:n,groupsOf:r},pi.set(e,t),t}var yi=new WeakMap;function gi(e,t){let n=yi.get(t);if(n||yi.set(t,n=new WeakMap),n.has(e))return n.get(e);let r=Xa(e,t);return n.set(e,r),r}function Xa(e,t){let{byId:n,groupsOf:r}=Ua(t);if(e.screenOf!==void 0){let i=n.get(we(e.screenOf));if(i)return{...e,x:i.x,y:i.y,width:i.width,height:i.height}}if(It(e.id)||Ae(e.id)!==null){let i=(e.aggregate?.memberIds??[]).map(s=>n.get(s)).filter(s=>s!==void 0);if(i.length===0)return null;let l=i.map(mi),u=l.reduce((s,c)=>s+c.x,0)/l.length,d=l.reduce((s,c)=>s+c.y,0)/l.length;return{...e,x:u-e.width/2,y:d-e.height/2}}let o=r.get(e.id)?.find(i=>i.id===we(e.kind)||i.id===Le(e.kind));if(!o)return null;let a=mi(o);return{...e,x:a.x-e.width/2,y:a.y-e.height/2}}function Ft(e,t,n){let r=Math.max(0,Math.min(1,n)),o=new Map(e.nodes.map(s=>[s.id,s])),a=new Map(t.nodes.map(s=>[s.id,s])),i=[];for(let[s,c]of o){let h=a.get(s);if(h){i.push(Xo(c,h,r,1));continue}let y=gi(c,t)??c;i.push(Xo(c,y,r,1-r))}for(let[s,c]of a){if(o.has(s))continue;let h=gi(c,e)??c;i.push(Xo(h,c,r,r))}let l=new Map(e.connectors.map(s=>[s.id,s])),u=new Map(t.connectors.map(s=>[s.id,s])),d=[];for(let[s,c]of l){let h=u.get(s);d.push(h?{...qa(c,h,r),opacity:1}:{...c,opacity:1-r})}for(let[s,c]of u)l.has(s)||d.push({...c,opacity:r});return{nodes:i.filter(s=>s.opacity>0).sort((s,c)=>s.id<c.id?-1:s.id>c.id?1:0),connectors:d.filter(s=>s.opacity>0).sort((s,c)=>s.id<c.id?-1:s.id>c.id?1:0),width:ge(e.width,t.width,r),height:ge(e.height,t.height,r),t:r,...xi(e.city,t.city,r)?{city:xi(e.city,t.city,r)}:{}}}function xi(e,t,n){return e?t?{cell:ge(e.cell,t.cell,n),...e.tilt!==void 0||t.tilt!==void 0?{tilt:ge(e.tilt??.5,t.tilt??.5,n)}:{},originX:ge(e.originX,t.originX,n),originY:ge(e.originY,t.originY,n),pan:{x:ge(e.pan.x,t.pan.x,n),y:ge(e.pan.y,t.pan.y,n)},extent:{x:ge(e.extent.x,t.extent.x,n),y:ge(e.extent.y,t.extent.y,n),width:ge(e.extent.width,t.extent.width,n),height:ge(e.extent.height,t.extent.height,n)}}:e:t}function Xo(e,t,n,r){return{id:t.id,kind:t.kind,plane:ge(e.plane,t.plane,n),x:ge(e.x,t.x,n),y:ge(e.y,t.y,n),width:ge(e.width,t.width,n),height:ge(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.nameplate?{nameplate:t.nameplate}:{},...t.states?{states:t.states}:{},...t.screenOf?{screenOf:t.screenOf}:{},...t.depth===void 0?{}:{depth:ge(e.depth??1,t.depth,n)},...t.natural?{natural:t.natural}:{}}}function qa(e,t,n){return{...t,x1:ge(e.x1,t.x1,n),y1:ge(e.y1,t.y1,n),x2:ge(e.x2,t.x2,n),y2:ge(e.y2,t.y2,n)}}function Xn(e){let t=Math.max(0,Math.min(1,e));return t<.5?4*t*t*t:1-(-2*t+2)**3/2}function Qa(e,t){let n=[];for(let o=0;o<e.length;o+=1){let a=e[o],i=e[(o+1)%e.length];if(a.y===i.y)continue;let l=Math.min(a.y,i.y),u=Math.max(a.y,i.y);t<l||t>=u||n.push(a.x+(t-a.y)/(i.y-a.y)*(i.x-a.x))}n.sort((o,a)=>o-a);let r={x0:0,x1:0};for(let o=0;o+1<n.length;o+=2){let a={x0:n[o],x1:n[o+1]};a.x1-a.x0>r.x1-r.x0&&(r=a)}return r}function Za(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 Ja(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 es(e){let t=0,n=0,r=0;for(let o=0;o<e.length;o+=1){let a=e[o],i=e[(o+1)%e.length],l=a.x*i.y-i.x*a.y;t+=l,n+=(a.x+i.x)*l,r+=(a.y+i.y)*l}if(Math.abs(t)<1e-9){let o=e.reduce((a,i)=>({x:a.x+i.x,y:a.y+i.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 ts(e,t){let{room:n,height:r,size:o,floor:a,measure:i=Lo,lines:l=2}=t,u=(f,p)=>f.every(v=>i(v,p)<=n)&&f.length*p*1.15<=r;if(u([e],o))return{lines:[e],fontSize:o,whole:!0};let d=e.split(/\s+/);if(l>1&&d.length>1){let f=1,p=1/0,v=0;for(let x=0;x<d.length-1;x+=1){v+=d[x].length+1;let O=Math.abs(v-e.length/2);O<p&&(p=O,f=x+1)}let k=[d.slice(0,f).join(" "),d.slice(f).join(" ")];if(u(k,o))return{lines:k,fontSize:o,whole:!0};for(let x=o;x>=a;x-=o*.06)if(u(k,x))return{lines:k,fontSize:x,whole:!0}}for(let f=o;f>=a;f-=o*.06)if(u([e],f))return{lines:[e],fontSize:f,whole:!0};let s=i(e,a)/Math.max(1,e.length),c=Math.floor(n/s)-1;if(c<4||a*1.15>r)return null;let h=e.slice(0,c),y=h.lastIndexOf(" ");return{lines:[`${y>3?h.slice(0,y):h}\u2026`],fontSize:a,whole:!1}}var ns=(e,t)=>e.x0<t.x1&&t.x0<e.x1&&e.y0<t.y1&&t.y0<e.y1;var q=se(Ce(),1);var bt=se(Ce(),1);function bi(e){let[t,n]=(0,bt.useState)(()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia(e).matches);return(0,bt.useEffect)(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;let r=window.matchMedia(e),o=()=>n(r.matches);return o(),r.addEventListener("change",o),()=>r.removeEventListener("change",o)},[e]),t}function os(){let e=()=>typeof document>"u"?null:document.documentElement.getAttribute("data-graview-motion"),[t,n]=(0,bt.useState)(e);return(0,bt.useEffect)(()=>{if(typeof document>"u"||typeof MutationObserver>"u")return;let r=new MutationObserver(()=>n(e()));return r.observe(document.documentElement,{attributes:!0,attributeFilter:["data-graview-motion"]}),n(e()),()=>r.disconnect()},[]),t}function wi(e){let t=bi("(prefers-reduced-motion: reduce)"),n=bi("(prefers-reduced-transparency: reduce)"),r=os();return Dr({off:!e,reducedMotion:r==="reduce"||r!=="full"&&t,reducedTransparency:n})}var rs=Nr*1.5,is=30;function vi(e,t){let[n,r]=(0,bt.useState)(!1),o=e&&!n;return(0,bt.useEffect)(()=>{if(!o||!t||typeof requestAnimationFrame>"u")return;let a=[],i=0,l=0,u=d=>{if(i>0&&a.push(d-i),i=d,a.length>=is){if(!Fr(a,rs)){r(!0);return}a.length=0}l=requestAnimationFrame(u)};return l=requestAnimationFrame(u),()=>cancelAnimationFrame(l)},[o,t]),o}var We=se(Ce(),1);var as=520;function ss(){return typeof window>"u"||!window.matchMedia?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches}function ki(e,t={}){let n=t.duration??as,r=(t.enabled??!0)&&!ss(),o=(0,We.useRef)(e),[a,i]=(0,We.useState)(()=>Ft(e,e,1)),l=(0,We.useRef)(a),u=(0,We.useRef)(null),d=(0,We.useRef)(null);return(0,We.useEffect)(()=>{if(!r||typeof requestAnimationFrame>"u"){o.current=e;let p=Ft(e,e,1);if(l.current=p,i(p),typeof requestAnimationFrame>"u")return;let v=requestAnimationFrame(()=>{let k=Ft(e,e,1);l.current=k,i(k)});return()=>cancelAnimationFrame(v)}let s=performance.now(),h=d.current!==null&&l.current.t<1&&s-d.current<n?d.current:s;d.current=h;let y=Xn(Math.min(1,(s-h)/n)),w=o.current,f=p=>{let v=Math.min(1,(p-h)/n),k=y>=1?1:(Xn(v)-y)/(1-y),x=Ft(w,e,Math.max(0,k));l.current=x,i(x),v<1?u.current=requestAnimationFrame(f):(d.current=null,o.current=e,u.current=requestAnimationFrame(()=>{let O=Ft(e,e,1);l.current=O,i(O),u.current=null}))};return u.current=requestAnimationFrame(f),()=>{u.current!==null&&cancelAnimationFrame(u.current);let p=l.current;o.current={...e,...p.city?{city:p.city}:{},nodes:p.nodes.map(v=>({...v,plane:Math.round(v.plane)})),connectors:p.connectors}}},[e,n,r]),a}function Si(e=1100){let{store:t}=ye(),[n,r]=(0,We.useState)(()=>new Set);return(0,We.useEffect)(()=>{let o=null,a=t.subscribe(i=>{r(new Set(i.touched)),o&&clearTimeout(o),o=setTimeout(()=>r(new Set),e)});return()=>{a(),o&&clearTimeout(o)}},[t,e]),n}var ds={marks:new Map,acts:[]};function Mi(e=4e3){let{store:t}=ye(),[n,r]=(0,We.useState)(ds);return(0,We.useEffect)(()=>{let o=null,a=t.subscribe((i,l)=>{r(u=>{let d=new Map(u.marks),s=[...u.acts];for(let c of l){if(c.undoes!==void 0){let w=s.find(p=>p.batch===c.undoes||p.wrote.length>0),f=s.filter(p=>c.writes.some(v=>p.wrote.includes(v)));for(let p of f.length>0?f:w?[w]:[]){for(let v of p.wrote)d.delete(v);s=s.filter(v=>v.batch!==p.batch)}continue}if(c.author.kind!=="agent")continue;let h=c.author.id??"the seat";for(let w of c.writes)d.set(w,h);s.find(w=>w.batch===c.batch)?s=s.map(w=>w.batch===c.batch?{...w,wrote:[...new Set([...w.wrote,...c.writes])]}:w):s=[{batch:c.batch,who:h,intent:c.batchIntent??c.intent,at:c.at,wrote:[...c.writes]},...s].slice(0,12)}return d.size===u.marks.size&&s===u.acts&&d.size===0?u:{marks:d,acts:s}}),o&&clearTimeout(o),o=setTimeout(()=>r(u=>u.marks.size===0?u:{...u,marks:new Map}),e)});return()=>{a(),o&&clearTimeout(o)}},[t,e]),n}var jt=se(Ie(),1),Qe=16;function Ei({marks:e,questions:t=[],whereIs:n,stageRef:r,width:o,height:a}){if(e.size===0&&t.length===0)return null;let i=r.current,l=i?.getBoundingClientRect()??null,u=[];for(let[s,c]of e){let h=null;if(i&&l&&typeof CSS<"u"){let p=i.querySelector(`[data-graview-pick="${CSS.escape(s)}"]`)?.getBoundingClientRect();p&&p.width>0&&p.height>0&&(h={x:p.left-l.left,y:p.top-l.top,width:p.width,height:p.height})}if(h??=n(s),!h)continue;let y=Math.min(Math.max(h.x+h.width-Qe/2,Qe/2),o-Qe/2),w=Math.min(Math.max(h.y-Qe/4,Qe/2),a-Qe/2);u.push({id:s,who:c,x:y,y:w})}let d=[];for(let s of t){let c=n(s.id);c&&d.push({...s,x:Math.min(Math.max(c.x+c.width/2,Qe),o-Qe),y:Math.min(Math.max(c.y-Qe/2,Qe),a-Qe)})}return u.length===0&&d.length===0?null:(0,jt.jsxs)("div",{className:"graview-seat-marks","data-testid":"seat-marks","data-graview-seat-marks":u.length,children:[u.map(({id:s,who:c,x:h,y})=>(0,jt.jsx)("span",{className:"graview-seat-mark","data-testid":"seat-mark","data-graview-seat-mark":s,"data-graview-seat-who":c,title:`${c} just changed this`,"aria-hidden":"true",style:{left:h,top:y,"--graview-hue":hn(c)},children:"\u25C6"},s)),d.map(s=>(0,jt.jsxs)("span",{className:"graview-seat-asking","data-testid":"seat-question","data-graview-seat-asking":s.id,title:s.asks,style:{left:s.x,top:s.y},children:[(0,jt.jsx)("span",{"aria-hidden":"true",children:"?"}),(0,jt.jsx)("span",{className:"graview-seat-asking-said",children:s.asks})]},`asking:${s.id}`))]})}var te=se(Ie(),1);function ls({hue:e,mode:t}){let n=t==="docked";return(0,te.jsxs)("svg",{viewBox:"0 0 32 38","aria-hidden":"true",children:[(0,te.jsxs)("g",{fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinejoin:"round",strokeLinecap:"round",children:[(0,te.jsx)("line",{x1:"16",y1:"3.5",x2:"16",y2:"7"}),(0,te.jsx)("circle",{cx:"16",cy:"2.6",r:"1.5",fill:"none"}),(0,te.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,te.jsx)("line",{x1:"11",y1:"12.5",x2:"21",y2:"12.5",strokeWidth:"2"}):(0,te.jsxs)(te.Fragment,{children:[(0,te.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,te.jsx)("circle",{cx:"13.4",cy:"12.5",r:"1.25",fill:"currentColor",stroke:"none",opacity:n?.45:1}),(0,te.jsx)("circle",{cx:"18.6",cy:"12.5",r:"1.25",fill:"currentColor",stroke:"none",opacity:n?.45:1}),t==="reading"?(0,te.jsx)("line",{x1:"10.2",y1:"12.5",x2:"21.8",y2:"12.5",strokeWidth:"0.8",opacity:"0.7"}):null]}),(0,te.jsx)("line",{x1:"16",y1:"16",x2:"16",y2:"18.5"}),(0,te.jsx)("polygon",{points:"16,18.5 24,22.5 16,26.5 8,22.5",fill:"currentColor",fillOpacity:"0.22"}),(0,te.jsx)("polygon",{points:"8,22.5 16,26.5 16,33.5 8,29.5",fill:"currentColor",fillOpacity:"0.08"}),(0,te.jsx)("polygon",{points:"24,22.5 16,26.5 16,33.5 24,29.5",fill:"currentColor",fillOpacity:"0.3"}),t==="writing"?(0,te.jsxs)(te.Fragment,{children:[(0,te.jsx)("polyline",{points:"24,24 28.5,20.5"}),(0,te.jsx)("line",{x1:"27.5",y1:"19",x2:"30",y2:"21.5",strokeWidth:"1.8"})]}):(0,te.jsx)("line",{x1:"24",y1:"24",x2:"26.5",y2:"29"}),(0,te.jsx)("line",{x1:"8",y1:"24",x2:"5.5",y2:"29"}),(0,te.jsx)("path",{d:"M9.5 33.5 v2.2 h4"}),(0,te.jsx)("path",{d:"M22.5 33.5 v2.2 h-4"})]}),(0,te.jsx)("title",{children:`robot, ${t}`})]})}function cs({hue:e}){return(0,te.jsxs)("svg",{viewBox:"0 0 22 24","aria-hidden":"true",style:{color:`hsl(${Math.round(e)} 50% 48%)`},children:[(0,te.jsxs)("g",{fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinejoin:"round",strokeLinecap:"round",children:[(0,te.jsx)("circle",{cx:"11",cy:"6",r:"4.2"}),(0,te.jsx)("path",{d:"M3 23 C3 15.5 6 13 11 13 C16 13 19 15.5 19 23"})]}),(0,te.jsx)("title",{children:"somebody"})]})}function Ri({width:e,whereIs:t}){let{who:n,following:r,follow:o}=ye(),a=Kr([...n.values()],t,e);return a.length===0?null:(0,te.jsx)("div",{className:"graview-occupants","data-testid":"occupants","data-graview-occupants":a.length,children:a.map((i,l)=>{if(i.kind==="over")return(0,te.jsx)("div",{className:"graview-presence-over","data-testid":"presence-over","data-graview-over-by":i.presence.participant,style:{left:i.box.x-3,top:i.box.y-3,width:i.box.width+6,height:i.box.height+6,"--graview-hue":i.presence.hue}},`over:${i.presence.participant}`);if(i.kind==="count")return(0,te.jsxs)("span",{className:"graview-figure-count","data-testid":"presence-count","data-graview-at":i.at,style:{left:i.point.x,top:i.point.y},title:`${i.n} more here`,children:["+",i.n]},`count:${i.at}:${l}`);let u=i.presence.hue,d=Mr(i.presence)||"somebody";if(i.kind==="edge")return(0,te.jsxs)("button",{type:"button",className:"graview-figure-edge","data-testid":"presence-edge","data-graview-person":i.presence.participant,style:{right:`calc(${Math.max(8,e-i.point.x)}px + var(--graview-dock, 0px))`,top:i.point.y},onClick:()=>o(i.presence.participant),"aria-label":`${d} is somewhere else \u2014 press to go where they are`,children:["\u2192 ",d]},`edge:${i.presence.participant}`);if(i.kind==="robot")return(0,te.jsxs)("div",{className:"graview-figure","data-graview-figure":`theirs:${i.presence.participant}`,"data-graview-theirs":"","data-graview-mode":i.mode,"data-graview-at":i.presence.robot?.at??"",style:{transform:`translate(${i.point.x.toFixed(1)}px, ${i.point.y.toFixed(1)}px)`,"--graview-hue":u},children:[(0,te.jsx)("span",{className:"graview-figure-body",role:"img","aria-label":`${d}'s agent \u2014 ${i.mode}`,style:{cursor:"default"},children:(0,te.jsx)(ls,{hue:u,mode:i.mode})}),(0,te.jsxs)("span",{className:"graview-figure-name",children:[d,"'s agent"]})]},`robot:${i.presence.participant}`);let s=r?.participant===i.presence.participant;return(0,te.jsxs)("div",{className:"graview-figure","data-graview-figure":i.presence.participant,"data-graview-person":"","data-graview-at":i.at,"data-graview-audience":i.audience?"":void 0,"data-graview-followed":s?"":void 0,style:{transform:`translate(${i.point.x.toFixed(1)}px, ${i.point.y.toFixed(1)}px)`,"--graview-hue":u},children:[(0,te.jsx)("button",{type:"button",className:"graview-figure-body","aria-label":`${d} is here${s?". Press to stop following":". Press to go where they go"}`,"aria-pressed":s,onClick:c=>{c.stopPropagation(),o(s?null:i.presence.participant)},onPointerDown:c=>c.stopPropagation(),children:(0,te.jsx)(cs,{hue:u})}),(0,te.jsx)("span",{className:"graview-figure-name",children:d})]},`person:${i.presence.participant}`)})})}var Qn=se(Ce(),1),En=se(Ie(),1),Oi={left:"\u2190",right:"\u2192",top:"\u2191",bottom:"\u2193"},qo=36,Mn=56;function Ai({result:e,schema:t,chrome:n=[],onGo:r}){let o=zo(e);if(o.length===0)return null;let a=s=>(s??[]).flatMap(c=>{let h=e.nodes.find(y=>y.id===c.id);return h?[{left:h.x+c.x,top:h.y+c.y,right:h.x+c.x+c.width,bottom:h.y+c.y+c.height}]:[]}),i=a(e.city?.showings),l=a(e.city?.nameplates),u=[...i,...l,...n.map(s=>({left:s.x,top:s.y,right:s.x+s.width,bottom:s.y+s.height}))],d=[];for(let s of["left","right","top","bottom"]){let c=e.visible??e,h=s==="left"||s==="right"?c.height:c.width,y=s==="left"||s==="right",w=s==="bottom"?fs:s==="top"?Mn:ms+Mn/2,f=-1/0,p=[],v=o.filter(k=>k.side===s).sort((k,x)=>k.along-x.along);for(let k of v){let x=un(t,k.kind),O=us(x),G=y?qn:O/2,F=h-w-(y?0:G),Q=Math.max(Mn,k.along,f+G+hs);if(Q>F)continue;let{at:z,inset:g}=ps([...u,...p],s,Q,O,c,h);if(z>F+.5)continue;f=z+G,p.push(Li(s,z,O,c,g));let E=s==="left"?{left:g,top:z,transform:"translateY(-50%)"}:s==="right"?{right:`calc(${g}px + var(--graview-dock, 0px))`,top:z,transform:"translateY(-50%)"}:s==="top"?{top:g,left:z,transform:"translateX(-50%)"}:{bottom:`calc(${g}px + var(--graview-scene-foot, var(--graview-sheet, 0px)))`,left:z,transform:"translateX(-50%)"};d.push((0,En.jsx)("button",{type:"button",className:"graview-edge-sign","data-graview-past-edge":k.id,"aria-label":`${x}, past the ${s} edge \u2014 bring it into view`,title:`${x} is past the ${s} edge`,tabIndex:-1,onPointerDown:I=>I.stopPropagation(),onClick:I=>{I.stopPropagation(),r(k.by)},style:{...ys,...E},children:s==="right"||s==="bottom"?`${x} ${Oi[s]}`:`${Oi[s]} ${x}`},k.id))}}return(0,En.jsx)(En.Fragment,{children:d})}var us=e=>(e.length+2)*7.4+22,qn=qo/2,Sn=6,hs=6,fs=236,ms=56;function Li(e,t,n,r,o=Sn){return e==="left"||e==="right"?{left:e==="left"?o:r.width-o-n,right:e==="left"?o+n:r.width-o,top:t-qn,bottom:t+qn}:{left:t-n/2,right:t+n/2,top:e==="top"?o:r.height-o-qo,bottom:e==="top"?o+qo:r.height-o}}function ps(e,t,n,r,o,a){let i=t==="left"||t==="right",l=f=>Li(t,f,r,o),u=f=>e.find(p=>{let v=l(f);return v.left<p.right&&p.left<v.right&&v.top<p.bottom&&p.top<v.bottom}),d=u(n);if(!d)return{at:n,inset:Sn};let s=i?qn:r/2,c=f=>{let p=n;for(let v=0;v<12;v++){let k=u(p);if(!k)return p;if(p=f>0?(i?k.bottom:k.right)+s+4:(i?k.top:k.left)-s-4,p>a-Mn||p<Mn)return null}return null},h=c(1);if(h!==null)return{at:h,inset:Sn};let y=c(-1);if(y!==null)return{at:y,inset:Sn};let w=t==="left"?d.right:t==="right"?o.width-d.left:t==="top"?d.bottom:o.height-d.top;return{at:n,inset:Math.max(Sn,w+4)}}var ys={position:"absolute",zIndex:He.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"};function Ii(e){let[t,n]=(0,Qn.useState)(null);return(0,Qn.useLayoutEffect)(()=>{let r=e.current,o=null;for(let l=r?.parentElement??null,u=0;l&&!o&&u<4;l=l.parentElement,u++)o=l.querySelector(":scope > [data-graview-scene-trail]");if(!r||!o)return;let a=()=>{let l=r.getBoundingClientRect(),u=o.getBoundingClientRect(),d=u.width>0&&u.height>0?{x:u.left-l.left,y:u.top-l.top,width:u.width,height:u.height}:null;n(s=>s===d||s&&d&&s.x===d.x&&s.y===d.y&&s.width===d.width&&s.height===d.height?s:d)};if(a(),typeof ResizeObserver>"u")return;let i=new ResizeObserver(a);return i.observe(o),()=>i.disconnect()},[e]),t}var wt=se(Ce(),1),gs=180;function Ti({view:e,result:t,frame:n,panned:r,closer:o,screenId:a,setCamera:i}){let l=(0,wt.useRef)(new Map),u=Math.round((t.nodes.find(c=>c.id===a)?.height??0)/16),d=(0,wt.useRef)(e.overview??!1),s=(0,wt.useRef)(null);if((0,wt.useEffect)(()=>{if(!e.overview||!a||!t.city){if(d.current&&!e.overview)return;i(F=>F.x===0&&F.y===0?F:{x:0,y:0});return}let c=t.nodes.find(F=>F.id===a);if(!c)return;let h=o>1&&c.screenOf?t.nodes.find(F=>F.id===we(c.screenOf)):void 0,y=h?{x:Math.min(c.x,h.x),y:Math.min(c.y,h.y),width:Math.max(c.x+c.width,h.x+h.width)-Math.min(c.x,h.x),height:Math.max(c.y+c.height,h.y+h.height)-Math.min(c.y,h.y)}:c;if(y.x>=0&&y.y>=0&&y.x+y.width<=t.width&&y.y+y.height<=t.height&&!h)return;let f=24,p=(F,Q,z)=>F<f?f-F:F+Q>z-f?z-f-(F+Q):0,v=xt(t),k=e.pan??{x:0,y:0},x=h?r.x+(t.width/2-(y.x+y.width/2)):r.x+p(y.x,y.width,t.width),O=t.height/2-(y.y+y.height/2),G=h?r.y+(c.y+O<f?f-c.y:O):r.y+p(y.y,y.height,t.height);i({x:(h?x:Math.max(-v.x,Math.min(v.x,x)))-k.x,y:(h?G:Math.max(-v.y,Math.min(v.y,G)))-k.y})},[a,e.overview,o,e.within?.view,u]),n.city){let c=new Map;for(let h of n.nodes){if(!h.plot||Math.round(h.plane)!==2)continue;let y=Zt(h.plot.col+h.plot.side/2,h.plot.row+h.plot.side/2,n.city.cell,n.city.tilt);c.set(h.id,{x:n.city.originX+r.x+y.x,y:n.city.originY+r.y+y.y})}l.current=c}return(0,wt.useEffect)(()=>{let c=e.overview??!1,h=d.current&&!c;if(d.current=c,c&&s.current&&(clearTimeout(s.current),s.current=null),!h)return;let y=e.focusId?yt(e.focusId)[0]:void 0,w=y?l.current.get(we(y)):void 0,f=t.nodes.find(p=>p.id===e.focusId);if(!w||!f){i({x:0,y:0});return}i({x:w.x-(f.x+f.width/2),y:w.y-(f.y+f.height/2)}),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{s.current=null,i({x:0,y:0})},gs)},[e.overview]),(0,wt.useEffect)(()=>()=>{s.current&&clearTimeout(s.current)},[]),{gliding:()=>s.current!==null}}var Jn=se(Ce(),1),Zn="[data-graview-view]";function xs(e,t){let n=null;for(let r=e?.closest(Zn)??null;r&&t.contains(r);r=r.parentElement?.closest(Zn)??null)n=r;return n}function Pi(e,t){let n=e.getBoundingClientRect();return{left:n.left,top:n.top,right:n.right-t.right,bottom:n.bottom-t.bottom,box:n}}function Ci(e,t,n){let r=(0,Jn.useRef)({dock:t,reveal:n});r.current={dock:t,reveal:n},(0,Jn.useEffect)(()=>{let o=e.current;if(!o)return;let a=u=>{let{dock:d}=r.current;if(u.key!=="Tab"||u.defaultPrevented||d.right<=0&&d.bottom<=0)return;let s=Pi(o,d),c=[];for(let h of o.querySelectorAll(Zn)){if(h.parentElement?.closest(Zn)||h.inert||h.contains(document.activeElement))continue;let y=h.getBoundingClientRect(),w=Math.max(y.left,s.box.left),f=Math.min(y.right,s.box.right),p=Math.max(y.top,s.box.top),v=Math.min(y.bottom,s.box.bottom);f<=w||v<=p||!(d.right>0&&w>=s.right-1||d.bottom>0&&p>=s.bottom-1)||(h.inert=!0,c.push(h))}c.length!==0&&setTimeout(()=>{for(let h of c)h.inert=!1},0)},i=u=>{let d=u.target,s=xs(d,o);if(!s)return;let c=!0;try{c=d?.matches(":focus-visible")??!0}catch{}requestAnimationFrame(()=>{for(let h=s.parentElement;h;h=h===o?null:h.parentElement)h.scrollTop!==0&&(h.scrollTop=0),h.scrollLeft!==0&&(h.scrollLeft=0);c&&s.isConnected&&l(s)})},l=u=>{let d=Pi(o,r.current.dock),s=u.getBoundingClientRect(),c=12,h=(f,p,v,k)=>k-v>p-f-2*c||v<f+c?f+c-v:k>p-c?p-c-k:0,y=h(d.left,d.right,s.left,s.right),w=h(d.top,d.bottom,s.top,s.bottom);(Math.abs(y)>=1||Math.abs(w)>=1)&&r.current.reveal(Math.round(y),Math.round(w))};return document.addEventListener("keydown",a,!0),o.addEventListener("focusin",i),()=>{document.removeEventListener("keydown",a,!0),o.removeEventListener("focusin",i)}},[e])}var de=se(Ce(),1);function Ni(){let e=(0,de.useRef)(null),[t,n]=(0,de.useState)({right:0,bottom:0});return(0,de.useLayoutEffect)(()=>{let r=e.current;if(!r)return;let o=()=>{let i=r.getBoundingClientRect(),l={right:Math.round(i.width),bottom:Math.round(i.height)};n(u=>u.right===l.right&&u.bottom===l.bottom?u:l)};if(o(),typeof ResizeObserver>"u")return;let a=new ResizeObserver(o);return a.observe(r),()=>a.disconnect()},[]),{probe:e,dock:t}}function Bi(){let[e,t]=(0,de.useState)(null),n=(0,de.useRef)(null),r=(0,de.useRef)(0),o=(0,de.useCallback)(i=>{n.current=i,r.current===0&&(r.current=requestAnimationFrame(()=>{r.current=0,t(n.current)}))},[]),a=(0,de.useCallback)(()=>{r.current!==0&&cancelAnimationFrame(r.current),r.current=0;let i=n.current;return n.current=null,i&&t(null),i},[]);return{held:e,place:o,release:a}}function $i({stage:e,pan:t,setView:n,settled:r}){let o=(0,de.useRef)({x:0,y:0}),a=(0,de.useRef)(0),i=(0,de.useRef)(!1),l=(0,de.useRef)(r);l.current=r;let u=(0,de.useCallback)(()=>[...e.current?.querySelectorAll("[data-graview-world]")??[]],[e]),d=(0,de.useCallback)(()=>{a.current===0&&(a.current=requestAnimationFrame(()=>{a.current=0;let{x:w,y:f}=o.current,p=w===0&&f===0?"":`translate3d(${w}px, ${f}px, 0)`;for(let v of u())v.style.transform=p}))},[u]),s=(0,de.useCallback)(()=>{i.current=!1;for(let w of u())w.style.transform="";l.current()},[u]),c=(0,de.useCallback)((w,f)=>{o.current={x:w.x-f.x,y:w.y-f.y},d()},[d]),h=(0,de.useCallback)(()=>{let{x:w,y:f}=o.current;return w===0&&f===0?!1:(o.current={x:0,y:0},i.current=!0,n(p=>{let v=p.pan??{x:0,y:0};return $t(p,{x:v.x+w,y:v.y+f})}),window.setTimeout(()=>{i.current&&s()},300),!0)},[n,s]);(0,de.useLayoutEffect)(()=>{i.current&&s()},[t,s]);let y=(0,de.useCallback)(()=>o.current,[]);return{shiftTo:c,settle:h,settling:i,offset:y}}var bs=4;function Hi({view:e,panned:t,limit:n,panWithin:r,moveByTransform:o,setView:a,setDragging:i,noteMoved:l,shift:u,district:d}){let s=(0,de.useRef)(!1),c=(0,de.useRef)(null),h=v=>{let k=e.pan??{x:0,y:0};c.current={kind:"pan",fromX:v.clientX,fromY:v.clientY,baseX:k.x,baseY:k.y,moved:!1}};return{onGroundDown:v=>{v.button===0&&(v.target.closest("[data-graview-view]")||h(v))},onCardDown:(v,k)=>{if(k.button===0){if(v.screenOf!==void 0&&!k.target.closest("[data-graview-grip]")){h(k);return}if(e.overview&&Ae(v.id)!==null){h(k);return}c.current={kind:"card",id:v.id,fromX:k.clientX,fromY:k.clientY,baseX:v.x-t.x,baseY:v.y-t.y,moved:!1}}},onDragMove:v=>{let k=c.current;if(!k)return;let x=v.clientX-k.fromX,O=v.clientY-k.fromY;if(!k.moved){if(Math.hypot(x,O)<bs)return;k.moved=!0,i(!0),v.currentTarget.setPointerCapture(v.pointerId)}if(k.kind==="pan"){let G=r(n(),{x:k.baseX+x,y:k.baseY+O});o?u.shiftTo(G,e.pan??{x:0,y:0}):a(F=>$t(F,G))}else k.id&&d.place({id:k.id,x:k.baseX+x,y:k.baseY+O})},onDragUp:()=>{u.settle();let v=d.release();v&&a(k=>bn(k,v.id,{x:v.x,y:v.y})),c.current?.moved&&(s.current=!0,setTimeout(()=>s.current=!1,0),l()),c.current=null,!u.settling.current&&i(!1)},swallow:s}}function Di({stage:e,view:t,setView:n}){let r=(0,de.useRef)({view:t,charge:0,coolUntil:0,lastScale:1});r.current.view=t;let o=(0,de.useRef)(()=>{}),a=(0,de.useRef)(()=>{});return(0,de.useEffect)(()=>{let i=e.current;if(!i)return;let l=(c,h)=>{let y=r.current;if(h<y.coolUntil)return;let w=y.view.overview??!1;c!==w&&(y.coolUntil=h+600,y.charge=0,n(fn(y.view,c)))},u=c=>{let h=r.current,y=h.view.overview??!1;if(c.ctrlKey){if(c.preventDefault(),!y){if(h.charge+=c.deltaY,Math.abs(h.charge)<60)return;h.charge>0?l(!0,performance.now()):h.charge=0;return}o.current(Math.exp(-c.deltaY*.004),c.clientX,c.clientY);return}!y||c.target?.closest("[data-graview-view], .graview-scroll, [data-graview-overlay], .graview-zoom")||(c.preventDefault(),a.current(-c.deltaX,-c.deltaY))},d=c=>{c.preventDefault(),r.current.lastScale=1},s=c=>{c.preventDefault();let h=r.current,y=c.scale??1;if(!(h.view.overview??!1)){y<.72&&l(!0,performance.now());return}let w=y/(h.lastScale||1);h.lastScale=y;let f=c;o.current(w,f.clientX,f.clientY)};return i.addEventListener("wheel",u,{passive:!1}),i.addEventListener("gesturestart",d),i.addEventListener("gesturechange",s),()=>{i.removeEventListener("wheel",u),i.removeEventListener("gesturestart",d),i.removeEventListener("gesturechange",s)}},[n,e]),{zoomAbout:o,panBy:a}}var Fi={directed:"You",autonomous:"An agent","co-edited":"You and an agent",rule:"A rule"};function Qo(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 a=e.find(i=>i.aggregate?.memberIds.includes(o));a&&r.add(a.id)}return r}function Zo(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 Jo(e){return e.edgeChosen?.9:e.lit?.78:e.own*(e.anyLit?e.kit.dim:e.kit.rest)}function rt(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?Kt(n,t):Ir(Kt(n,t),Kt(r,t),e.plane-n);return{x:e.x,y:e.y,width:e.width*o,height:e.height*o}}function tn(e,t){if(typeof getComputedStyle>"u"||getComputedStyle(e).visibility==="hidden")return null;let n=-1/0,r=-1/0,o=1/0,a=1/0,i=e.getBoundingClientRect();n=Math.max(n,i.left),r=Math.max(r,i.top),o=Math.min(o,i.right),a=Math.min(a,i.bottom);let l=e.parentElement;for(;l&&l!==t;){let d=getComputedStyle(l);if(d.overflowX!=="visible"||d.overflowY!=="visible"){let s=l.getBoundingClientRect();d.overflowX!=="visible"&&(n=Math.max(n,s.left),o=Math.min(o,s.right)),d.overflowY!=="visible"&&(r=Math.max(r,s.top),a=Math.min(a,s.bottom))}l=l.parentElement}if(o-n<=2||a-r<=2)return null;let u=t.getBoundingClientRect();return{x:n-u.left,y:r-u.top,width:o-n,height:a-r}}function De(e,t,n,r=!1){if(!e||typeof document>"u")return null;let o=e.querySelector(`[data-graview-view="${CSS.escape(t)}"]`);if(!o)return null;let a=(n?o.querySelector(".graview-kind-block"):null)??o.querySelector('[data-graview-primitive="panel"], .graview-kind-face, .graview-kind-card')??(r?null:o.querySelector(':scope > [data-graview-primitive="chip"]'))??o;return tn(a,e)}function eo(e,t,n,r,o){let a=d=>e.nodes.find(s=>s.id===d);if(o.startsWith("screen:")){let d=e.nodes.find(s=>s.id===we(o.slice(7)));return d?De(t,d.id,!0)??rt(d,n):null}let i=a(o),l=Ae(o);if(!i&&l!==null&&(i=a(Le(l))),!i&&It(o)){let[d]=yt(o);d&&(i=a(we(d)))}if(!i){let d=r.places().find(s=>s.as===o);d&&(i=a(Le(d.kind))??a(we(d.kind)))}if(i||(i=[...e.nodes].filter(d=>d.aggregate?.memberIds.includes(o)).sort((d,s)=>d.plane-s.plane)[0]),!i)return null;let u=e.city!==void 0;return De(t,i.id,u&&i.aggregate!==void 0&&Math.round(i.plane)===2)??rt(i,n)}var lt=se(Ce(),1);var le=se(Ie(),1);function Wi({kinds:e}){let{store:t}=ye(),{view:n,go:r}=Eo(),o=(0,lt.useRef)(null),a=Oo("districts",{align:"start"}),i=a.open,l=h=>un(t.schema,h),u=h=>t.graph.allNodes().filter(y=>y.kind===h).length,d=h=>!n.overview&&n.focusId===Le(h),s=e.filter(h=>!d(h)),c=h=>{a.setOpen(!1);let y=o.current?.querySelector(".graview-beyond-more")??null;d(h)||r(pt(n,Le(h))),y?.focus({preventScroll:!0});let w=`[data-graview-view="${Le(h)}"][tabindex], [data-graview-view="${we(h)}"][tabindex]`,f=40,p=()=>{let v=document.querySelector(w);v?v.focus({preventScroll:!0}):--f>0&&requestAnimationFrame(p)};requestAnimationFrame(p)};return(0,le.jsxs)("div",{ref:o,className:"graview-beyond","data-graview-beyond":e.length,"data-graview-beyond-open":i?"":void 0,children:[(0,le.jsxs)("button",{type:"button",className:"graview-beyond-more","data-testid":"beyond-more",...a.trigger,"aria-haspopup":"menu",title:`${s.length} more district${s.length===1?"":"s"} \u2014 press to see them`,onPointerDown:h=>h.stopPropagation(),onClick:h=>{h.stopPropagation(),a.toggle()},children:[(0,le.jsxs)("span",{className:"graview-beyond-count",children:["+",s.length]}),(0,le.jsx)("span",{className:"graview-beyond-word",children:"more"}),(0,le.jsx)("span",{className:"graview-beyond-chevron","aria-hidden":"true",children:i?"\u25BE":"\u25B4"})]}),i?(0,le.jsx)("ul",{...a.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,le.jsx)("li",{role:"none",children:(0,le.jsxs)("button",{type:"button",role:"menuitem","data-graview-pick":we(h),"aria-current":d(h)?"location":void 0,title:d(h)?`${l(h)} \u2014 where you are`:`Go to ${l(h)}`,onPointerDown:y=>y.stopPropagation(),onClick:y=>{y.stopPropagation(),c(h)},children:[(0,le.jsx)("span",{className:"graview-beyond-name",children:l(h)}),(0,le.jsx)("span",{className:"graview-beyond-tally",children:d(h)?"here":u(h)})]})},h))}):null]})}function ws(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"||tr(e[r],t[r]))}function tr(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 a=0;a<e.length;a++)if(!tr(e[a],o[a]))return!1;return!0}let r=Object.keys(e);return r.length!==Object.keys(t).length?!1:r.every(o=>tr(e[o],t[o]))}var Vi=(0,lt.memo)(Yi,(e,t)=>e.mode===t.mode&&e.selected===t.selected&&e.fidelity===t.fidelity&&ws(e.node,t.node));function Yi({node:e,mode:t,selected:n,fidelity:r}){let{store:o,views:a,view:i}=ye(),l=Pt(),u=_r(),d=Gr(),s=e.aggregate||It(e.id)||Ae(e.id)!==null?"many":"one",c={cardinality:s,fidelity:r??Lr[ks(e.plane)].fidelity},h=s==="many"&&e.id===i.focusId?i.within?.view:void 0,y=a.resolve(e.kind,c,h),w=y?.view,f=a.resolve(e.kind,{cardinality:"many",fidelity:"full"})?.view,p=f!==void 0&&f.generic!==!0,v=e.aggregate?.memberIds,k=(0,lt.useMemo)(()=>(v??[]).map(G=>o.graph.getNode(G)).filter(G=>G!==void 0),[v,o,l]),x={...e.aggregate?{nodes:k,label:y?.title??e.aggregate.label}:{node:o.graph.getNode(e.id)},fidelity:c.fidelity,cardinality:c.cardinality,mode:t,selected:n,implicated:u,flagged:d,...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.nameplate?{nameplate:e.nameplate}:{},...e.states?{states:e.states}:{},...e.aggregate?.retired?{retired:e.aggregate.retired}:{},...e.rank?{rank:e.rank}:{},...e.nestedUnder?{nestedUnder:e.nestedUnder}:{},...p?{hasOwnView:!0}:{}};if(!w)return(0,le.jsx)(Ss,{node:e,props:x});let O=[e.id,y?.title??"",c.fidelity,c.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.nameplate??"",e.states?e.states.values.map(G=>G.count).join(","):"",e.aggregate?er(e.aggregate.memberIds):"",e.aggregate?.retired??"",u?er(u):"",d?er(d):"",p].join("|");return(0,le.jsx)(ko,{mode:t,children:(0,le.jsx)(Ur,{kind:x.label??e.kind,...y?.title?{view:y.title}:{},children:(0,le.jsx)(vs,{signature:O,graph:l,draw:()=>(0,le.jsx)(w,{...x})})},`${e.id}|${y?.title??""}`)})}var vs=(0,lt.memo)(function({draw:t}){return(0,le.jsx)(le.Fragment,{children:t()})},(e,t)=>e.signature===t.signature&&e.graph===t.graph);function ks(e){return Math.max(0,Math.min(2,Math.round(e)))}function Ss({node:e,props:t}){return(0,le.jsxs)("div",{style:{padding:8,font:"13px/1.4 system-ui",overflow:"hidden"},children:[(0,le.jsx)("strong",{children:t.label??e.kind}),t.nodes?(0,le.jsxs)("div",{children:[t.nodes.length," items"]}):(0,le.jsx)("div",{children:e.id})]})}var zi=(0,lt.memo)(function({node:t}){let{store:n}=ye(),r=Tt(),o=t.aggregate,a=o.opens,i=o.memberIds.length,l=zt(n.schema,o.kind,i),u=o.memberIds.slice(0,3).map(h=>{let y=n.graph.getNode(h),w=y?n.schema.tryDefinition(y.kind):void 0;return y?w?.label?w.label(y):String(y.label??h):h}),d=o.memberIds,s=(0,lt.useMemo)(()=>{let h=r?Wn(r):null;return h?d.filter(y=>h.has(y)).length:0},[r,d]),c=a.in==="picture";return(0,le.jsxs)("div",{className:"graview-band-group","data-graview-band":a.in,"data-graview-band-count":i,"data-graview-emphasis":r?s>0?"lit":"dimmed":void 0,title:c?`${o.label} \u2014 press twice to see them all, arranged`:`${o.label}: ${l} \u2014 press twice to open`,children:[(0,le.jsxs)("span",{className:"graview-band-group-head",children:[(0,le.jsx)("span",{className:"graview-band-group-name",children:o.label}),(0,le.jsx)("span",{className:"graview-band-group-open","aria-hidden":"true",children:c?"\u2197":"\u25BE"})]}),(0,le.jsxs)("span",{className:"graview-band-group-names",children:[c?null:(0,le.jsxs)("span",{className:"graview-band-group-count",children:[l,s>0?` \xB7 ${s} match`:""," \xB7 "]}),u.join(" \xB7 "),i>u.length?" \u2026":""]})]})}),ji=new WeakMap;function er(e){let t=ji.get(e);if(t!==void 0)return t;let n=2166136261;for(let o of e){for(let a=0;a<o.length;a++)n=Math.imul(n^o.charCodeAt(a),16777619);n=Math.imul(n^44,16777619)}let r=`${e.length}:${(n>>>0).toString(36)}`;return ji.set(e,r),r}var vt=se(Ce(),1);function nr(e,t,n){let r=e.aggregate?[...e.aggregate.memberIds]:[e.id];return n?r.every(a=>t.includes(a))?t.filter(a=>!r.includes(a)):[...t,...r.filter(a=>!t.includes(a))]:r}function Gi(){let[e,t]=(0,vt.useState)(16);return(0,vt.useEffect)(()=>{if(typeof window>"u")return;let n=document.documentElement,r=()=>{let a=parseFloat(getComputedStyle(n).fontSize);Number.isFinite(a)&&t(i=>Math.abs(i-a)<.5?i:a)};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 _i(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=l=>{!l||l.width===0||l.height===0||n(u=>{let d={width:Math.round(l.width),height:Math.round(l.height)};return u&&u.width===d.width&&u.height===d.height?u:d})},a=new ResizeObserver(l=>o(l[0]?.contentRect)),i=()=>o(r.getBoundingClientRect());return a.observe(r),addEventListener("resize",i),()=>{a.disconnect(),removeEventListener("resize",i)}},[e]),t}function or(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 Ki(e){return`matrix3d(${e.join(",")})`}var fe=se(Ce(),1);var rr=(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 ir(e,t){let n=[],r=[];for(let a=0;a<e.length-1;a++){let i=e[a],l=e[a+1],u=!rr(i,t);u&&r.length===0&&r.push(i);for(let d=1;d<=48;d++){let s=d/48,c={x:i.x+(l.x-i.x)*s,y:i.y+(l.y-i.y)*s},h=!rr(c,t);if(h===u)continue;let y=(d-1)/48,w=s;for(let v=0;v<10;v++){let k=(y+w)/2,x={x:i.x+(l.x-i.x)*k,y:i.y+(l.y-i.y)*k};!rr(x,t)===u?y=k:w=k}let f=(y+w)/2,p={x:i.x+(l.x-i.x)*f,y:i.y+(l.y-i.y)*f};h?r=[p]:(r.push(p),r.length>=2&&n.push(r),r=[]),u=h}u&&r.push(l)}return r.length>=2&&n.push(r),n}function Rn(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 a=(e.y+t.y)/2;return[e,{x:e.x,y:a},{x:t.x,y:a},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 Ge=e=>Math.round(e*100)/100,kt=e=>e.map(t=>t.map((n,r)=>`${r===0?"M":"L"} ${Ge(n.x)} ${Ge(n.y)}`).join(" ")).join(" ");function ar(e,t){if(e.length<3)return kt([e]);let n=[`M ${Ge(e[0].x)} ${Ge(e[0].y)}`];for(let o=1;o<e.length-1;o++){let a=e[o-1],i=e[o],l=e[o+1],u=Math.hypot(i.x-a.x,i.y-a.y),d=Math.hypot(l.x-i.x,l.y-i.y),s=Math.min(t,u/2,d/2),c={x:i.x+(a.x-i.x)/(u||1)*s,y:i.y+(a.y-i.y)/(u||1)*s},h={x:i.x+(l.x-i.x)/(d||1)*s,y:i.y+(l.y-i.y)/(d||1)*s};n.push(`L ${Ge(c.x)} ${Ge(c.y)} Q ${Ge(i.x)} ${Ge(i.y)} ${Ge(h.x)} ${Ge(h.y)}`)}let r=e[e.length-1];return n.push(`L ${Ge(r.x)} ${Ge(r.y)}`),n.join(" ")}function Ui(e,t){return t==="orthogonal"?kt([e]):ar(e,10)}function Xi(e,t,n){if(e==="orthogonal"){let l=Rn(t.p0,t.p1),u=l.slice(1).map((c,h)=>Math.hypot(c.x-l[h].x,c.y-l[h].y)),d=u.reduce((c,h)=>c+h,0)||1,s=n*d;for(let c=0;c<u.length;c++){let h=u[c];if(s<=h||c===u.length-1){let y=h===0?0:Math.min(1,s/h),w=l[c],f=l[c+1];return{x:w.x+(f.x-w.x)*y,y:w.y+(f.y-w.y)*y}}s-=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),a=2*(1-n)*n,i=n*n;return{x:o*t.p0.x+a*r.x+i*t.p1.x,y:o*t.p0.y+a*r.y+i*t.p1.y}}function to(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 qi(e,t){let n=t.x-e.x,r=t.y-e.y,o=(n/2+r)/2,a=(r-n/2)/2;if(Math.abs(o)<1||Math.abs(a)<1)return[e,t];let i={x:e.x+2*o,y:e.y+o};return[e,i,t]}function Qi(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(a=>r.y<a.bottom+3&&r.y+r.height>a.top-3);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,a)=>o.x-a.x);return n.sort((r,o)=>r.top-o.top)}var On=(e,t)=>e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height,dr=(e,t)=>e.findIndex(n=>n.boxes.some(r=>On(r,t)));function Zi(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 cr(e,t){let n=[{from:-1/0,to:1/0}];for(let a of e){let i=[],l=-1/0;for(let d of a.boxes)i.push({from:l,to:d.x-12}),l=Math.max(l,d.x+d.width+12);i.push({from:l,to:1/0});let u=[];for(let d of n)for(let s of i){let c=Math.max(d.from,s.from),h=Math.min(d.to,s.to);h-c>=0&&u.push({from:c,to:h})}n=u}let r=t,o=1/0;for(let a of n){let i=Math.min(Math.max(t,a.from),a.to),l=a.from===-1/0||a.to===1/0,u=Math.abs(i-t)+(l?60:0);u<o&&(o=u,r=i)}return r}var Ze=e=>({x:e.x,y:-(e.y+e.height),width:e.width,height:e.height}),no=e=>e.map(t=>({x:t.x,y:-t.y}));function lr(e){let t=(r,o)=>Math.abs(r-o)<.5,n=e.filter((r,o)=>o===0||!(t(r.x,e[o-1].x)&&t(r.y,e[o-1].y)));return n.filter((r,o)=>{let a=n[o-1],i=n[o+1];return!a||!i||!(t(a.x,r.x)&&t(r.x,i.x)||t(a.y,r.y)&&t(r.y,i.y))})}function ur(e,t,n){let r=e.boxes.filter(d=>!On(d,t)&&d.y+d.height<=t.y+1&&d.x<t.x+t.width&&d.x+d.width>t.x),o=[{from:t.x+6,to:t.x+t.width-6}];for(let d of r)o=o.flatMap(s=>[{from:s.from,to:Math.min(s.to,d.x-12/2)},{from:Math.max(s.from,d.x+d.width+12/2),to:s.to}]).filter(s=>s.to>=s.from);let a=null;for(let d of o){let s=Math.min(Math.max(n,d.from),d.to);(a===null||Math.abs(s-n)<Math.abs(a-n))&&(a=s)}if(a!==null)return{x:a,tail:[{x:a,y:t.y}]};let i=n<t.x+t.width/2,l=cr([e],i?t.x-12:t.x+t.width+12),u=t.y+t.height/2;return{x:l,tail:[{x:l,y:u},{x:l<t.x?t.x:t.x+t.width,y:u}]}}function sr(e,t,n){let r=ur({top:-e.bottom,bottom:-e.top,boxes:e.boxes.map(Ze)},Ze(t),n);return{x:r.x,head:no(r.tail).reverse()}}function Ji(e,t,n,r){let o=t;for(;o>r&&!e[o-1].boxes.some(a=>n>a.x-12/2&&n<a.x+a.width+12/2);)o--;return o}var ea=(e,t)=>(e%3-1)*Math.max(0,Math.min(4,t/2-3));function ta(e,t,n,r,o,a,i,l){let u=f=>f<0?e[0].top-n:e[f+1].top-e[f].bottom,d=f=>(f<0?(n+e[0].top)/2:Zi(e,f,f+1))+ea(l,u(f)),s=ur(e[a],o,i),c=Ji(e,a,s.x,t+1),h=d(t);if(c===t+1)return lr([...r.head,{x:r.x,y:h},{x:s.x,y:h},...s.tail]);let y=cr(e.slice(t+1,c),s.x),w=d(c-1);return lr([...r.head,{x:r.x,y:h},{x:y,y:h},{x:y,y:w},{x:s.x,y:w},...s.tail])}function nn(e,t,n,r=0){let o=Qi(n.some(s=>On(s,e))&&n.some(s=>On(s,t))?n:[...n,e,t]),a=dr(o,e),i=dr(o,t),l=e.x+e.width/2,u=t.x+t.width/2;if(a===i){if(!(a<o.length-1||o.length===1))return no(nn(Ze(e),Ze(t),n.map(Ze),r));let c=Zi(o,a,a+1)+ea(r,a<o.length-1?o[a+1].top-o[a].bottom:2*12),h=sr(o[a],e,u),y=sr(o[a],t,l);return lr([...h.head,{x:h.x,y:c},{x:y.x,y:c},...[...y.head].reverse()])}if(i<a)return no(nn(Ze(e),Ze(t),n.map(Ze),r));let d=sr(o[a],e,u);return ta(o,a,o[a].bottom,d,t,i,l,r)}function hr(e,t,n,r=0){if(t.y+t.height<=e.y){let y=hr(Ze(e),Ze(t),n.map(Ze),r);return y?no(y):null}let o=e.y+e.height;if(t.y<o)return null;let a=Qi([...n.filter(y=>y.y>=o&&!On(y,t)),t]),i=dr(a,t),l=t.x+t.width/2,u=ur(a[i],t,l),d=Ji(a,i,u.x,0),s=d===0?u.x:cr(a.slice(0,d),u.x),c=Math.min(12,e.width/2),h=Math.min(Math.max(s,e.x+c),e.x+e.width-c);return ta(a,-1,o,{x:h,head:[{x:h,y:o}]},t,i,l,r)}function na(e,t=16){let n=new Map;for(let o of e){let a=o.a<o.b?`${o.a}\0${o.b}`:`${o.b}\0${o.a}`,i=n.get(a);i?i.push(o.key):n.set(a,[o.key])}let r=new Map;for(let o of n.values())o.forEach((a,i)=>r.set(a,(i-(o.length-1)/2)*t));return r}var Ve=se(Ie(),1);function mr(e,t,n,r){let o=[];for(let a of e.querySelectorAll("[data-graview-relation] > span")){let i=a.getBoundingClientRect();if(i.width<=0||i.height<=0)continue;let l=i.top-t.top,u=a.parentElement?.getAttribute("data-graview-relation"),d=1/0;for(let s of n){if(Math.round(s.plane)!==1||!s.via||`${s.via.edgeKind}|${s.via.direction}`!==u)continue;let c=r(s.id);c&&c.y>=l+i.height-1&&(d=Math.min(d,c.y))}o.push({x:i.left-t.left,y:l,width:i.width,height:d-l<=i.height*4?d-l:i.height})}return o}function ro(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),a=!o&&r>.5*Math.min(e.height,t.height);if(o){let w={x:e.x+e.width,y:e.y+e.height/2},f={x:t.x+t.width,y:t.y+t.height/2};return{from:w,to:f,control:{x:Math.max(w.x,f.x)+18,y:(w.y+f.y)/2},mode:"stacked"}}if(a){let w={x:e.x+e.width/2,y:e.y},f={x:t.x+t.width/2,y:t.y};return{from:w,to:f,control:{x:(w.x+f.x)/2,y:Math.min(w.y,f.y)-18},mode:"abreast"}}let i={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},u=oo(e,i),d=oo(t,l),s=Math.hypot(d.x-u.x,d.y-u.y);if(s<8)return null;let c=Math.min(36,s*.12),h=-(d.y-u.y)/s,y=(d.x-u.x)/s;return{from:u,to:d,control:{x:(u.x+d.x)/2+h*c,y:(u.y+d.y)/2+y*c},mode:"direct"}}function oo(e,t){let n=e.x+e.width/2,r=e.y+e.height/2,o=t.x-n,a=t.y-r;if(o===0&&a===0)return{x:n,y:r};let i=o===0?1/0:e.width/2/Math.abs(o),l=a===0?1/0:e.height/2/Math.abs(a),u=Math.min(i,l),d=Math.max(0,u*.98);return{x:n+o*d,y:r+a*d}}function Ms(e,t,n){let r=t.get(e.from),o=t.get(e.to);if(!r||!o)return!1;if(n)return!0;let a=Math.round(r.plane)===1||Math.round(o.plane)===1,i=l=>!!l.aggregate&&Math.round(l.plane)===2;return a&&!i(r)&&!i(o)}var ra=e=>({clips:new Map,members:new Map,marks:new Map,...e?{owed:e}:{}});function ia(e,t){let n=ra();for(let[r,o]of t){let a=e.querySelector(`[data-graview-view="${CSS.escape(r)}"]`);if(a!==null){for(let i of o)if(on(e,a,i,n).length>0)return!0}}return!1}function aa(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 a=n.get(o);a?a.push(r):n.set(o,[r])}return t.marks.set(e,n),n}function Es(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 Rs(e,t,n){let r=e.parentElement;for(;r!==null;){let o=Es(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 a=o.get(n);if(a)return a;let i=e.getBoundingClientRect(),l=[];for(let d of aa(t,r).get(n)??[]){if(d.closest("[data-graview-offstage]"))continue;let s=d.getBoundingClientRect();s.width<=2||s.height<=2||Rs(d,s,r)&&l.push({x:s.left-i.left,y:s.top-i.top,width:s.width,height:s.height})}l.sort((d,s)=>d.width*d.height-s.width*s.height),o.set(n,l);let u=t.getAttribute("data-graview-view");return l.length===0&&r.owed&&u!==null&&r.owed.set(u,(r.owed.get(u)??new Set).add(n)),l}function io(e,t,n,r,o,a){let i=new Map(e.map(x=>[x.id,x])),l=ra(a),u=new Map,d=x=>{if(!n||typeof document>"u")return null;let O=u.get(x);return O===void 0&&(O=n.querySelector(`[data-graview-view="${CSS.escape(x)}"]`),u.set(x,O)),O},s=new Map;for(let x of e){let O=De(n,x.id,r)??rt(x,o);O&&s.set(x.id,O)}let c=new Map;if(n&&typeof document<"u"){let x=n.getBoundingClientRect();for(let O of n.querySelectorAll("[data-graview-pick], [data-graview-slot]")){if(O.closest("[data-graview-offstage]"))continue;let G=O.getAttribute("data-graview-pick")??O.getAttribute("data-graview-slot");if(G===null)continue;let F=O.getBoundingClientRect();if(F.width<=2||F.height<=2||F.width>x.width*.6&&F.height>x.height*.6)continue;let Q=c.get(G),z={x:F.left-x.left,y:F.top-x.top,width:F.width,height:F.height};Q?Q.push(z):c.set(G,[z])}}let h=(x,O)=>{let G=[];for(let[F,Q]of s)F!==x&&F!==O&&G.push(Q);for(let[F,Q]of c)F!==x&&F!==O&&G.push(...Q);return G},y=x=>Math.round(i.get(x)?.plane??-1)===1,w=[];for(let x of e){let O=s.get(x.id);O&&Math.round(x.plane)===1&&w.push(O)}if(!r&&n&&typeof document<"u"){let x=n.getBoundingClientRect();w.push(...mr(n,x,e,O=>s.get(O)))}let f=(x,O)=>!r&&y(x)&&y(O)?w:void 0,p=r?void 0:e.find(x=>Math.round(x.plane)===0&&!x.aggregate),v=(x,O,G,F)=>{if(!p)return{};let Q=x.to===p.id&&G===p.id;if(!Q&&!(x.from===p.id&&O===p.id))return{};let z=Q?x.from:x.to,g=s.get(p.id),E=s.get(z);if(z===p.id||!y(z)||!g||!E)return{};let I=d(p.id),A=N=>I!==null&&aa(I,l).get(N)?.some($=>!$.closest("[data-graview-offstage]"))===!0,j=F.map(N=>N.from===p.id?N.to:N.from),K=j.length>0&&j.every(A);return{band:w,tie:{card:g,chip:E,cardIsTo:Q,toward:z,holds:i.get(z)?.aggregate?.memberIds??[z]},...K?{said:j}:{}}},k=[];for(let x of t){if(!Ms(x,i,r))continue;let O=s.get(x.from),G=s.get(x.to);if(!O||!G)continue;let F=h(x.from,x.to),Q=x.edges,z=r&&Q.some(I=>I.from!==x.from&&on(n,d(x.from),I.from,l).length>0||I.to!==x.to&&on(n,d(x.to),I.to,l).length>0),g=f(x.from,x.to);if(r&&!z||x.loop||Q.length===0){k.push({key:x.id,connector:x,edges:Q,fromBox:O,toBox:G,fromAnchor:x.from,toAnchor:x.to,obstacles:F,hosts:[],...g?{band:g}:{},...v(x,x.from,x.to,Q)});continue}let E=new Map;for(let I of Q){let A=I.from===x.from?[]:on(n,d(x.from),I.from,l),j=I.to===x.to?[]:on(n,d(x.to),I.to,l),K=[x.from,x.to].find(S=>Math.round(i.get(S)?.plane??-1)===0);if(!r&&K!==void 0&&(K===x.from?I.from!==x.from:I.to!==x.to)&&on(n,d(K),K===x.from?I.to:I.from,l).length>0)continue;let N=K!==void 0?i.get(K):void 0;if(!r&&N?.aggregate&&n&&(K===x.from?I.from!==x.from&&A.length===0:I.to!==x.to&&j.length===0))continue;let $=A.length>0?I.from:x.from,Y=j.length>0?I.to:x.to,B=`${x.id}|${$}|${Y}`,J=E.get(B);if(J){J.edges.push(I);continue}let R=A.length>0?A:[O],D=j.length>0?j:[G],b=R[0],M=D[0],T=1/0;for(let S of R)for(let P of D){let L=Math.hypot(S.x+S.width/2-(P.x+P.width/2),S.y+S.height/2-(P.y+P.height/2));L<T&&(T=L,b=S,M=P)}E.set(B,{edges:[I],fromBox:b,toBox:M,fromAnchor:$,toAnchor:Y})}for(let[I,A]of E)k.push({key:I,connector:x,obstacles:F,hosts:[...A.fromAnchor!==x.from?[O]:[],...A.toAnchor!==x.to?[G]:[]],...g?{band:g}:{},...A,...v(x,A.fromAnchor,A.toAnchor,A.edges)})}return k}function sa(e,t,n){let r=new Map(t.map(i=>[i.id,i])),o=new Map;for(let i of n){let l=r.get(i.id);l&&(l.x!==i.x||l.y!==i.y)&&o.set(i.id,{x:i.x-l.x,y:i.y-l.y})}if(o.size===0)return[...e];let a=(i,l)=>{let u=o.get(l);return u?{...i,x:i.x+u.x,y:i.y+u.y}:i};return e.map(i=>{let{from:l,to:u}=i.connector;if(!o.has(l)&&!o.has(u))return i;let d=a(i.fromBox,l),s=a(i.toBox,u),c=i.tie&&{...i.tie,card:a(i.tie.card,i.tie.cardIsTo?u:l),chip:a(i.tie.chip,i.tie.toward)},h=y=>y===i.fromBox?d:y===i.toBox?s:i.tie&&y===i.tie.chip?c.chip:y;return{...i,fromBox:d,toBox:s,...c?{tie:c}:{},...i.band?{band:i.band.map(h)}:{}}})}function fr(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 oa(e,t,n){let r=(1-t)*(1-n),o=(1-t)*n+t*(1-n),a=t*n;return{p0:fr(e,t),c:{x:r*e.p0.x+o*e.c.x+a*e.p1.x,y:r*e.p0.y+o*e.c.y+a*e.p1.y},p1:fr(e,n)}}function An(e,t){let n=d=>t.some(s=>d.x>s.x&&d.x<s.x+s.width&&d.y>s.y&&d.y<s.y+s.height),r=d=>!n(fr(e,d)),a=(d,s,c)=>{for(let h=0;h<10;h++){let y=(d+s)/2;r(y)===c?d=y:s=y}return(d+s)/2},i=[],l=null,u=r(0);u&&(l=0);for(let d=1;d<=64;d++){let s=d/64,c=r(s);if(c===u)continue;let h=a((d-1)/64,s,u);c?l=h:l!==null&&(h-l>.001&&i.push(oa(e,l,h)),l=null),u=c}return l!==null&&1-l>.001&&i.push(oa(e,l,1)),i}function da({strands:e,result:t,scheme:n,overview:r,selection:o,emphasis:a,stageRef:i,liveOf:l,onPickEdge:u,provisional:d,pointed:s=null}){let c=Nt(),h=new Set(t.nodes.filter(g=>g.plot!==void 0&&Math.round(g.plane)===2).map(g=>g.id)),y=g=>r&&t.city!==void 0&&h.has(g.from)&&h.has(g.to),w=Qo(t.nodes,o),f=g=>w.size===0||w.has(g.from)||w.has(g.to),p=new Set(o.filter(g=>Lt(g)===null)),v=r?t.nodes.find(g=>Math.round(g.plane)===0):void 0,k=v?De(i.current,v.id,!1)??rt(v,n):null;if(e.length===0)return null;let x=g=>g.edges.some(E=>p.has(E.from)||p.has(E.to)),O=p.size>0&&e.some(x),G=new Map;for(let g of e)G.set(g.connector.id,(G.get(g.connector.id)??0)+1);let F=na(e.map(g=>({key:g.key,a:g.fromAnchor,b:g.toAnchor}))),Q=new Set,z=e.map((g,E)=>{let{connector:I,fromBox:A,toBox:j}=g,K={x:A.x+A.width/2,y:A.y+A.height/2},N={x:j.x+j.width/2,y:j.y+j.height/2},$=r?oo(A,N):K,Y=r?oo(j,K):N,B=I.loop===!0,{connector:J,style:R}=Qt(c,I.kind);if(!J.visible)return null;let D=B?Math.max(22,Math.min(A.width,A.height)*.3):0,b=B?{x:K.x+A.width*.22,y:K.y-A.height/2-D+7}:$,M=($.x+Y.x)/2,T=($.y+Y.y)/2,S=Math.hypot(Y.x-$.x,Y.y-$.y),P=Math.min(r?40:90,S*(r?.09:.16)),L=0,H=0;if(S>0){L=-(Y.y-$.y)/S,H=(Y.x-$.x)/S;let ie=M-t.width/2,ve=T-t.height/2;if(k&&!B){let nt=k.x+k.width/2,Rt=k.y+k.height/2;ie=M-nt,ve=T-Rt;let je=Math.abs(L*(nt-$.x)+H*(Rt-$.y)),Ot=Math.hypot(k.width/2,k.height/2)*.85+24,ze=((nt-$.x)*(Y.x-$.x)+(Rt-$.y)*(Y.y-$.y))/(S*S);je<Ot&&ze>.1&&ze<.9&&(P=Math.min(180,Math.max(P,(Ot-je)*2)))}L*ie+H*ve<0&&(L=-L,H=-H)}P+=2*(F.get(g.key)??0);let Z=to(J.route,{p0:$,c:{x:M+L*P,y:T+H*P},p1:Y}),U=y(I),V=J.route==="orthogonal"||U,ne=(ie,ve)=>U?qi(ie,ve):Rn(ie,ve),X=!B&&g.tie?hr(g.tie.card,g.tie.chip,g.band??[],E):null,ce=X?g.tie.cardIsTo?X.reverse():X:!B&&g.band?nn(A,j,g.band,E):null,ae=B||V||ce?[]:An(Z,[A,j,...g.obstacles]),Se=ce?[ce]:!B&&V?ir(ne($,Y),[A,j,...g.obstacles]):[];if(!B&&ae.length===0&&Se.length===0)return null;let ke=Se[Se.length-1],Re=V||ce?Se[0]?.[0]:ae[0]?.p0,Te=V||ce?ke?.[ke.length-1]:ae[ae.length-1]?.p1,Pe=ie=>ie.map(ve=>`M ${ve.p0.x} ${ve.p0.y} Q ${ve.c.x} ${ve.c.y} ${ve.p1.x} ${ve.p1.y}`).join(" "),re=`M ${b.x-D} ${b.y} A ${D} ${D} 0 1 1 ${b.x+D} ${b.y} A ${D} ${D} 0 0 1 ${b.x-D} ${b.y}`,ee=B?re:ce?Ui(ce,J.route):V?kt(Se):Pe(ae),et=ie=>({x:ie.x-8,y:ie.y-8,width:ie.width+16,height:ie.height+16}),St=[A,j,...g.hosts,...g.obstacles].map(et),an=B?re:ce?kt(Se):V?kt(ir(ne($,Y),St)):Pe(An(Z,St)),_e=g.edges.length===1?g.edges[0]:null,Be=_e?Bt(I.kind,_e.from,_e.to):null,ut=Be!==null&&o.includes(Be),Ke=Be!==null?d?.get(Be):void 0,tt=g.edges.some(ie=>p.has(ie.from)||p.has(ie.to)),Oe=g.tie?.toward??"",Ye=g.tie!==void 0&&(s!==null&&(Oe===s||g.tie.holds.includes(s)||g.said?.includes(s)===!0)||p.has(Oe))&&!Q.has(Oe);Ye&&Q.add(Oe);let $e=!r&&p.size>0&&tt||Ye,Fe=a!==null&&I.kind===a||ut,Mt=l?.(I)!==void 0;if(r&&!Mt||!r&&!Mt&&p.size>0&&!tt&&!Fe&&!Ye||g.said!==void 0&&!Ye&&!g.said.some(ie=>p.has(ie))&&!Fe)return null;let Ue=r?Zo({emphasized:a!==null,stressed:Fe,anyChosen:O,mine:tt,touches:f(I),siblings:G.get(I.id)??1}):Jo({edgeChosen:ut,lit:$e,anyLit:O||a!==null,own:R.opacity,kit:c.emphasis}),it=$e&&Re&&Te?g.tie?g.tie.cardIsTo?Re:Te:g.edges.some(ie=>p.has(ie.from))?Te:Re:null,Et=(0,Ve.jsxs)("g",{children:[(0,Ve.jsx)("path",{"data-graview-connector":I.kind,"data-graview-edges":g.edges.length,"data-graview-from":g.fromAnchor,"data-graview-to":g.toAnchor,"data-graview-lit":$e||void 0,"data-graview-activity":l?.(I)?.manner,"data-graview-provisional":Ke!==void 0||void 0,opacity:Ue*(I.opacity??1)*(Ke!==void 0?xn:1),d:ee,fill:"none",stroke:Ut(R),strokeWidth:($e?Math.max(1.6,Ao(R,r)):Ao(R,r))+(Fe?.6:0),strokeDasharray:Ke!==void 0?gn:Vn[R.pattern],strokeLinecap:"round"}),it?(0,Ve.jsx)("circle",{cx:it.x,cy:it.y,r:2.6,fill:Ut(R),opacity:Ue}):null,B&&r?(0,Ve.jsx)("text",{x:b.x,y:b.y-D-5,textAnchor:"middle",opacity:Ue,style:{font:"9px var(--graview-font-body, system-ui)",letterSpacing:"0.09em",textTransform:"uppercase",fill:"var(--graview-ink-faint)"},children:cn(I.kind).toLowerCase()}):null]},g.key),Xe=null;return Be&&u&&!B&&Ue>=.2&&(Xe=(0,Ve.jsx)("path",{"data-graview-edge":Be,className:"graview-edge-hit",d:an,fill:"none",pathLength:1,strokeDasharray:"0.86",strokeDashoffset:-.07,stroke:"transparent",strokeWidth:14,style:{pointerEvents:"stroke",cursor:"pointer"},onClick:ie=>{ie.stopPropagation(),u(Be,{x:ie.clientX,y:ie.clientY})},onContextMenu:ie=>{ie.preventDefault(),ie.stopPropagation(),u(Be,{x:ie.clientX,y:ie.clientY})},children:Ke!==void 0?(0,Ve.jsx)("title",{children:Ke}):null},`hit:${g.key}`)),{key:g.key,line:Et,hit:Xe}});return(0,Ve.jsxs)(Ve.Fragment,{children:[(0,Ve.jsx)("svg",{"aria-hidden":"true","data-graview-world":"",width:t.width,height:t.height,style:{position:"absolute",left:0,top:0,pointerEvents:"none",zIndex:He.ties},children:z.map(g=>g?.line)}),z.some(g=>g?.hit)?(0,Ve.jsx)("svg",{"data-graview-world":"",width:t.width,height:t.height,style:{position:"absolute",left:0,top:0,pointerEvents:"none",zIndex:He.tieLabels},children:z.map(g=>g?.hit)}):null]})}function la(e,t,n){if(t.size===0||typeof MutationObserver>"u")return()=>{};let r=0,o=()=>{r=0,ia(e,t)&&n()},a=()=>{r===0&&(r=requestAnimationFrame(o))},i=({target:u})=>{for(let d=u instanceof Element?u:u.parentElement;d&&d!==e;d=d.parentElement)if(t.has(d.getAttribute("data-graview-view")??""))return!0;return!1},l=new MutationObserver(u=>{u.some(i)&&a()});return l.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-graview-pick","data-graview-slot","data-graview-offstage"]}),a(),()=>{l.disconnect(),cancelAnimationFrame(r)}}function ao(e){return e<640?{left:8,right:56}:{left:8,right:Math.round(Math.min(128,e*.107))}}function Os(e){return Math.min(260,16+e.length*6.6)}var Ln=(e,t)=>Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x))*Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));function ua(e,t,n){let r=new Map;for(let i of e){let l=r.get(i.said);l?l.push(i):r.set(i.said,[i])}let o=[],a=[];for(let[i,l]of r){let u=l[0],d=Os(i),{end:s,far:c}=u,h=p=>Math.max(0,Math.min(n.width-d,p)),y=[{x:h(s.x-d/2),y:c.y-22-6,width:d,height:22},{x:h(s.x-d/2),y:c.y+c.height+6,width:d,height:22},{x:c.x+c.width+6,y:s.y-22/2,width:d,height:22},{x:c.x-d-6,y:s.y-22/2,width:d,height:22}],w=y[0],f=1/0;for(let p of y){let k=p.x<0||p.y<0||p.x+p.width>n.width||p.y+p.height>n.height?1e9:0;for(let x of t)k+=Ln(p,x.title)*100+Ln(p,x.box);for(let x of o)k+=Ln(p,x)*100;if(k<f&&(f=k,w=p),k===0)break}o.push(w),a.push({said:i,keys:l.map(p=>p.key),...w})}return a}var ca=(e,t,n=2)=>t.x>=e.x-n&&t.x<=e.x+e.width+n&&t.y>=e.y-n&&t.y<=e.y+e.height+n;function pr(e,t){let n=new Set;for(let r of e)(t.edgeId&&r.edgeId===t.edgeId||t.point&&(ca(r.fromBox,t.point)||ca(r.toBox,t.point))||t.ids?.some(o=>r.ids.includes(o))||t.box&&(Ln(t.box,r.fromBox)>0||Ln(t.box,r.toBox)>0))&&n.add(r.key);return n}var pe=se(Ie(),1);function ma(e){let t=Vr(e);return t.length>0?new Map(t.map(n=>[Bt(n.edge.kind,n.edge.from,n.edge.to),Wr(n)])):void 0}function pa({frame:e,width:t,height:n,scheme:r,overview:o,selection:a,emphasis:i,stageRef:l,store:u,graphNodes:d,onPickEdge:s,liveOf:c,holding:h=!1,provisional:y,focusId:w=null,beside:f=!1}){let[p,v]=(0,fe.useState)(0),[k,x]=(0,fe.useState)(null),O=e.t<1,G=(0,fe.useRef)(""),F=(0,fe.useRef)([]),Q=(0,fe.useRef)(new Map),z=()=>[...l.current?.querySelectorAll("[data-graview-relation] > span")??[]].map(N=>{let $=N.getBoundingClientRect();return`${Math.round($.left)},${Math.round($.top)},${Math.round($.width)}`}).join(" ");(0,fe.useLayoutEffect)(()=>{if(O||h)return;G.current=z(),F.current=e.nodes;let N=new Map;x(io(e.nodes,e.connectors,l.current,o,r,N)),Q.current=N},[e,O,h,a,o,d,r,p,l]),(0,fe.useEffect)(()=>{let N=l.current;if(!(O||h||N===null))return la(N,Q.current,()=>v($=>$+1))},[k,O,h,l]),(0,fe.useEffect)(()=>{if(O||h||o||typeof requestAnimationFrame>"u")return;let N=requestAnimationFrame(()=>{z()!==G.current&&v($=>$+1)});return()=>cancelAnimationFrame(N)},[k]);let g=e.nodes.map(N=>N.id).join(`
4
+ `);(0,fe.useLayoutEffect)(()=>{let N=l.current;if(N===null||typeof window>"u")return;let $=0,Y=()=>{$===0&&($=requestAnimationFrame(()=>{$=0,v(J=>J+1)}))};N.addEventListener("scroll",Y,{capture:!0,passive:!0}),window.addEventListener("resize",Y,{passive:!0});let B=typeof ResizeObserver>"u"?null:new ResizeObserver(Y);if(B){B.observe(N);for(let J of N.querySelectorAll("[data-graview-view]"))B.observe(J)}return()=>{$!==0&&cancelAnimationFrame($),N.removeEventListener("scroll",Y,{capture:!0}),window.removeEventListener("resize",Y),B?.disconnect()}},[l,g]);let[E,I]=(0,fe.useState)(null),A=(k??[]).some(N=>N.tie!==void 0);if((0,fe.useEffect)(()=>{let N=l.current;if(!A||N===null)return;let $=B=>{let J=B.target?.closest?.("[data-graview-pick], [data-graview-view]");I(J?.getAttribute("data-graview-pick")??J?.getAttribute("data-graview-view")??null)},Y=()=>I(null);return N.addEventListener("pointerover",$),N.addEventListener("focusin",$),N.addEventListener("pointerleave",Y),N.addEventListener("focusout",Y),()=>{N.removeEventListener("pointerover",$),N.removeEventListener("focusin",$),N.removeEventListener("pointerleave",Y),N.removeEventListener("focusout",Y)}},[A,l]),O)return null;let j=(k&&h?sa(k,F.current,e.nodes):k)??io(e.nodes,e.connectors,null,o,r),K=new Set;for(let N of j){if(N.edges.length===1){let $=N.edges[0];K.add(`${N.connector.kind}|${$.from}|${$.to}`);continue}for(let $ of N.edges)(N.connector.from===$.from||N.connector.to===$.to)&&K.add(`${N.connector.kind}|${$.from}|${$.to}`)}return(0,pe.jsxs)(pe.Fragment,{children:[(0,pe.jsx)(da,{strands:j,result:e,scheme:r,overview:o,selection:a,emphasis:i,stageRef:l,onPickEdge:s,liveOf:c,pointed:E,...y?{provisional:y}:{}}),o&&wn(a,{overview:o,focusId:w,beside:f},N=>u.graph.getNode(N)?.kind).records.length>0?(0,pe.jsx)(fe.Suspense,{fallback:null,children:(0,pe.jsx)(Ls,{frame:e,width:t,height:n,stageRef:l,tick:p,store:u,graphVersion:d,selection:a,view:{overview:o,focusId:w,beside:f},rulers:y?{...ha,unsureOf:(N,$,Y)=>y.get(Bt(N,$,Y))}:ha})}):null,o?null:(0,pe.jsx)(Ts,{...y?{provisional:y}:{},stageRef:l,nodes:e.nodes,scheme:r,selection:a,store:u,graphNodes:d,overview:o,width:t,height:n,onPickEdge:s,alreadyDrawn:K,tick:p})]})}var ha={visibleRect:tn,clipQuadratic:An,unsureDash:gn,unsureOpacity:xn},As=yn(Gt(()=>(__graviewPreload(import.meta.url,["./chunk.VNUHESMZ.js","./chunk.2FLPDPEL.js","./chunk.UUBYFBPN.js","./chunk.2RVUDRRY.js","./chunk.FOQZADMA.js","./chunk.SDO3U72B.js","./chunk.V5MYKNL7.js","./chunk.AJZBJBMO.js"]),import("./chunk.TGVUIFKD.js")))),Ls=As.part((e,t)=>(0,pe.jsx)(e.RecordLinks,{...t}),{what:"The links",quiet:!0}),Is=44;function Ts({stageRef:e,nodes:t,scheme:n,selection:r,store:o,graphNodes:a,overview:i,width:l,height:u,onPickEdge:d,alreadyDrawn:s,tick:c,provisional:h}){let y=Nt(),w=(0,fe.useMemo)(()=>{if(r.length===0||r.length>4)return[];let g=new Set(r),E=[];for(let A of r){let j=Lt(A);j&&E.push({kind:j.kind,self:j.from,other:j.to})}for(let A of o.graph.allEdges()){let j=g.has(A.from)?A.from:g.has(A.to)?A.to:null;if(!j)continue;let K=j===A.from?A.to:A.from;g.has(K)||E.push({kind:A.kind,self:j,other:K})}if(E.length<=14)return E;let I=new Set(t.map(A=>A.id));return E.map((A,j)=>({tie:A,index:j,real:I.has(A.other)?0:1})).sort((A,j)=>A.real-j.real||A.index-j.index).slice(0,14).map(({tie:A})=>A)},[o,r,a,t]),f=()=>{if(w.length===0||typeof document>"u")return[];let g=e.current?.getBoundingClientRect();if(!g)return[];let E=[...e.current?.querySelectorAll("[data-graview-joins]")??[]].find(R=>{if(R.closest("[data-graview-offstage]"))return!1;try{let D=JSON.parse(R.getAttribute("data-graview-joins")??"[]");return D.length===r.length&&D.every(b=>r.includes(b))}catch{return!1}});if(E){let R=tn(E,e.current);if(!R)return[];let D=[];for(let b of r){let M=t.find(L=>L.id===b);if(!M)continue;let T=De(e.current,M.id,i)??rt(M,n),S=T?ro(R,T):null;if(!T||!S)continue;let P=[...o.graph.allEdges()].find(L=>L.from===b&&r.includes(L.to)||L.to===b&&r.includes(L.from));D.push({key:`join:${b}`,self:b,other:"",others:1,kind:P?.kind??"",endX:S.to.x,endY:S.to.y,...S,fromBox:R,toBox:T,proxy:!1,edgeId:P?Bt(P.kind,P.from,P.to):null})}return D}let I=(R,D)=>{let b=e.current?.querySelectorAll(`[data-graview-pick="${CSS.escape(R)}"], [data-graview-slot="${CSS.escape(R)}"]`),M=[];for(let T of b??[]){if(T.closest("[data-graview-offstage]")||D(T)||T.closest("[data-graview-mark]"))continue;let S=tn(T,e.current);S&&M.push(S)}return M.sort((T,S)=>T.width*T.height-S.width*S.height)},A=R=>t.find(D=>D.id===R)??t.find(D=>D.aggregate?.memberIds.includes(R)),j=R=>`[data-graview-pick="${CSS.escape(R)}"], [data-graview-slot="${CSS.escape(R)}"]`,K=(R,D)=>{let b=e.current;if(!b)return!1;for(let M of b.querySelectorAll("[data-graview-view]")){let T=M.querySelector(j(R));if(T===null||T.closest("[data-graview-offstage]"))continue;let S=M.querySelector(j(D));if(S!==null&&!S.closest("[data-graview-offstage]"))return!0}return!1},N=[];if(!i&&e.current){for(let D of t){if(Math.round(D.plane)!==1)continue;let b=De(e.current,D.id,!1);b&&N.push(b)}let R=e.current;N.push(...mr(R,g,t,D=>De(R,D,!1)))}let $=new Map,Y=[];for(let R of w){if(K(R.self,R.other))continue;let D=A(R.self),b=D?e.current?.querySelector(`[data-graview-view="${CSS.escape(D.id)}"]`):null,M=!i&&D?.id===R.self&&Math.round(D.plane)===1?De(e.current,D.id,!1):null,T=M?[M]:I(R.self,()=>!1);if(!(T.length>0)&&D){let re=De(e.current,D.id,!1)??rt(D,n);re&&T.push(re)}let P=t.find(re=>re.id===R.other),L=[],H=!1;if(P){let re=De(e.current,P.id,i)??rt(P,n);re&&L.push(re)}else if(L.push(...I(R.other,re=>b?b.contains(re):!1)),L.length===0){let re=A(R.other);if(re&&(!D||re.id!==D.id)){let ee=De(e.current,re.id,i)??rt(re,n);ee&&(L.push(ee),H=!0)}}if(T.length===0||L.length===0||H&&i)continue;let Z=T[0],U=L[0],V=1/0;for(let re of T)for(let ee of L){let et=Math.hypot(re.x+re.width/2-(ee.x+ee.width/2),re.y+re.height/2-(ee.y+ee.height/2));et<V&&(V=et,Z=re,U=ee)}if(s?.has(`${R.kind}|${R.self}|${R.other}`)||s?.has(`${R.kind}|${R.other}|${R.self}`))continue;let ne=`${R.kind}:${Math.round(Z.x)},${Math.round(Z.y)}:${Math.round(U.x)},${Math.round(U.y)}`,X=$.get(ne);if(X){X.others+=1;continue}let ce=ro(Z,U);if(!ce)continue;let{from:ae,control:Se}=ce,ke=M&&Z===M?nn(Z,U,N,Y.length):void 0,Re=ke?ke[ke.length-1]:ce.to,Te=[...o.graph.allEdges()].find(re=>re.kind===R.kind&&(re.from===R.self&&re.to===R.other||re.from===R.other&&re.to===R.self)),Pe={key:`${R.kind}:${R.self}:${R.other}`,self:R.self,other:R.other,others:1,kind:R.kind,endX:Re.x,endY:Re.y,from:ae,to:Re,control:Se,fromBox:Z,toBox:U,...ke?{points:ke}:{},proxy:H,edgeId:Te?Bt(Te.kind,Te.from,Te.to):null};$.set(ne,Pe),Y.push(Pe)}let B=i?void 0:t.find(R=>Math.round(R.plane)===0&&!R.aggregate),J=R=>{let D=t.find(b=>b.id===R.other)??t.find(b=>b.aggregate?.memberIds.includes(R.other));return D!==void 0&&Math.round(D.plane)===1&&D.via?.edgeKind===R.kind};for(let R of Y){if(B&&(R.self!==B.id||J(R)))continue;let D=[...o.graph.allEdges()].find(L=>L.kind===R.kind&&(L.from===R.self&&L.to===R.other||L.from===R.other&&L.to===R.self)),b=o.graph.getNode(R.self),M=o.graph.getNode(R.other);if(!D||!b||!M)continue;let T=D.from===R.self?"out":"in",S=jr(o.schema,T==="out"?b.kind:M.kind,R.kind,T),P=R.proxy?(T==="out"?o.graph.out(R.self,R.kind):o.graph.in(R.self,R.kind)).filter(L=>L.kind===M.kind).length:1;R.said=R.proxy?`${S}: ${zt(o.schema,M.kind,Math.max(P,R.others))}`:`${S}: ${Dn(o.schema.tryDefinition(M.kind),M)}`}return Y},[p,v]=(0,fe.useState)([]),[k,x]=(0,fe.useState)([]);(0,fe.useLayoutEffect)(()=>{let g=f();v(g),x(g.some(E=>E.said)?O(g):[])},[w,t,i,n,l,u,s,c,e]);let O=g=>{let E=e.current;if(!E)return[];let I=[];for(let A of E.querySelectorAll("[data-graview-view]")){let j=[...A.children].find(N=>!N.classList.contains("graview-kind-tag")),K=j?tn(j,E):null;K&&I.push({box:K,title:{...K,height:Math.min(K.height,Is)}})}return ua(g.flatMap(A=>A.said?[{key:A.key,said:A.said,end:{x:A.endX,y:A.endY},far:A.toBox}]:[]),I,{width:l,height:u})},[G,F]=(0,fe.useState)(()=>new Set),Q=(0,fe.useRef)([]);Q.current=p.map(g=>({key:g.key,fromBox:g.fromBox,toBox:g.toBox,ids:[g.self,g.other],edgeId:g.edgeId}));let z=k.length>0;return(0,fe.useEffect)(()=>{let g=e.current;if(!g||!z)return;let E=B=>F(J=>J.size===B.size&&[...B].every(R=>J.has(R))?J:B),I=0,A=null,j=()=>{if(I=0,!A)return;let B=g.getBoundingClientRect(),J=A.target instanceof Element?A.target:null;E(pr(Q.current,{point:{x:A.clientX-B.left,y:A.clientY-B.top},edgeId:J?.closest("[data-graview-edge]")?.getAttribute("data-graview-edge")??null}))},K=B=>{A=B,I||(I=requestAnimationFrame(j))},N=()=>{A=null,E(new Set)},$=B=>{let J=B.target instanceof Element?B.target:null;if(!J)return;let R=g.getBoundingClientRect(),D=J.getBoundingClientRect(),b=J.closest("[data-graview-pick]")?.getAttribute("data-graview-pick")??J.closest("[data-graview-view]")?.getAttribute("data-graview-view");E(pr(Q.current,{...b?{ids:[b]}:{},box:{x:D.left-R.left,y:D.top-R.top,width:D.width,height:D.height}}))},Y=B=>{B.relatedTarget instanceof Node&&g.contains(B.relatedTarget)||E(new Set)};return g.addEventListener("pointermove",K,{passive:!0}),g.addEventListener("pointerleave",N),g.addEventListener("focusin",$),g.addEventListener("focusout",Y),()=>{I&&cancelAnimationFrame(I),g.removeEventListener("pointermove",K),g.removeEventListener("pointerleave",N),g.removeEventListener("focusin",$),g.removeEventListener("focusout",Y)}},[e,z]),p.length===0?null:(0,pe.jsxs)(pe.Fragment,{children:[(0,pe.jsx)("svg",{"aria-hidden":p.some(g=>g.edgeId)?void 0:!0,"data-graview-ties":p.length,"data-graview-world":"",width:l,height:u,style:{position:"absolute",left:0,top:0,pointerEvents:"none",zIndex:He.lines},children:p.map(g=>{let{connector:E,style:I}=Qt(y,g.kind);if(!E.visible)return null;let A=g.edgeId?h?.get(g.edgeId):void 0,j={p0:g.from,c:g.control,p1:g.to},K=g.points?ar(g.points,10):E.route==="orthogonal"?kt([Rn(g.from,g.to)]):(({p0:$,c:Y,p1:B})=>`M ${$.x} ${$.y} Q ${Y.x} ${Y.y} ${B.x} ${B.y}`)(to(E.route,j)),N=null;if(g.edgeId&&d&&!g.proxy){let $=(B,J)=>J.x>=B.x&&J.x<=B.x+B.width&&J.y>=B.y&&J.y<=B.y+B.height,Y=g.points?[...g.points]:[];for(let B=0;B<=(g.points?-1:40);B++){let J=Xi(E.route,j,B/40);$(g.fromBox,J)||$(g.toBox,J)||Y.push(J)}Y.length>=2&&(N=(0,pe.jsx)("path",{"data-graview-edge":g.edgeId,className:"graview-edge-hit",d:`M ${Y[0].x} ${Y[0].y} ${Y.slice(1).map(B=>`L ${B.x} ${B.y}`).join(" ")}`,fill:"none",pathLength:1,strokeDasharray:"0.86",strokeDashoffset:-.07,stroke:"transparent",strokeWidth:14,style:{pointerEvents:"stroke",cursor:"pointer"},onClick:B=>{B.stopPropagation(),d(g.edgeId,{x:B.clientX,y:B.clientY})},onContextMenu:B=>{B.preventDefault(),B.stopPropagation(),d(g.edgeId,{x:B.clientX,y:B.clientY})},children:A!==void 0?(0,pe.jsx)("title",{children:A}):null}))}return(0,pe.jsxs)("g",{opacity:(g.proxy?.32:.72)*(A!==void 0?xn:1),children:[(0,pe.jsx)("path",{"data-graview-tie":g.kind,"data-graview-tie-proxy":g.proxy||void 0,"data-graview-provisional":A!==void 0||void 0,d:K,fill:"none",stroke:Ut(I),strokeWidth:g.proxy?1.1:1.6,strokeDasharray:A!==void 0?gn:Vn[I.pattern],strokeLinecap:"round"}),(0,pe.jsx)("circle",{cx:g.endX,cy:g.endY,r:g.proxy?2:2.6,fill:Ut(I)}),N]},g.key)})}),(0,pe.jsx)("div",{"aria-hidden":"true","data-graview-world":"",style:{position:"absolute",inset:0,pointerEvents:"none",zIndex:He.tieLabels},children:k.map(g=>{let E=p.find(I=>I.key===g.keys[0]);return(0,pe.jsx)("span",{className:"graview-record-link-said","data-graview-link-said":E?.kind,"data-graview-lands":E?.proxy?"district":"record","data-graview-said-for":g.keys.length,"data-graview-tie-said":g.keys.some(I=>G.has(I))?"shown":"waiting",style:{position:"absolute",left:g.x,top:g.y,transform:`translateX(min(0px, calc(${Math.round(l-g.x-8)}px - 100%)))`},children:g.said},g.said)})})]})}function fa(){return typeof document>"u"?1:parseFloat(getComputedStyle(document.documentElement).fontSize)/16||1}function ya({nodes:e,scheme:t,width:n,stageRef:r,moving:o=!1,holding:a=!1}){let i=Nt(),[l,u]=(0,fe.useState)([]);(0,fe.useLayoutEffect)(()=>{o||a||u(d())},[e,o,a,t,n,r]);function d(){let c=[],h=[];for(let p of e){if(!p.via||Math.round(p.plane)!==1)continue;let v=De(r.current,p.id,!1,!0),{scale:k}=Kt(1,t);c.push({key:`${p.via.edgeKind}|${p.via.direction}`,text:vn(p.via),left:v?.x??p.x,right:v?v.x+v.width:p.x+p.width*k,top:v?.y??p.y}),h.push(Math.round(p.y))}let y=new Map;c.forEach((p,v)=>y.set(h[v],Math.min(y.get(h[v])??1/0,p.top)));let w=c.map((p,v)=>({...p,top:y.get(h[v])??p.top})),f=ao(n);return Wo(w,{left:f.left,right:n-f.right},fa())}if(l.length===0||!i.captions.visible||o)return null;let s=jo*fa();return(0,pe.jsx)("div",{"aria-hidden":"true",style:{position:"absolute",inset:0,pointerEvents:"none",zIndex:He.lines},children:l.map(c=>{let{left:h,width:y}=c;return(0,pe.jsx)("div",{"data-graview-relation":c.key,title:c.text,style:{position:"absolute",left:h,width:y,textAlign:"center",top:Math.max(0,c.top-s),fontSize:"0.75rem",letterSpacing:"0.09em",textTransform:"uppercase",color:"var(--graview-ink-faint)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:(0,pe.jsx)("span",{style:{background:"var(--graview-ground)",padding:"1px 7px",borderRadius:4},children:c.text})},c.key)})})}var Wt=se(Ce(),1);var Cs=new Set;function xa(e,t,n,r,o,a,i=0,l=0){let{store:u,views:d,hiddenKinds:s}=ye(),c=Tt(),h=(0,Wt.useContext)(_t),y=Mo(),w=(0,Wt.useMemo)(()=>{let v={};for(let k of y){if(k.subjectId===void 0)continue;let x=v[k.subjectId]??=[];for(let O of k.nodeIds)O!==k.subjectId&&!x.includes(O)&&x.push(O)}return v},[y]),f=(0,Wt.useMemo)(()=>({flagged:new Set(y.flatMap(v=>v.nodeIds)),touched:Yn(u.log.all())}),[y,u,a]),p=(0,Wt.useMemo)(()=>({hits:c?Wn(c):Cs,...f}),[c,f]);return(0,Wt.useMemo)(()=>({...e,cityZoom:r,...h?{besideTheMap:!0}:{},...s.size>0?{hiddenKinds:[...s].sort()}:{},...Object.keys(w).length>0?{judged:w}:{},relevance:p,inset:{...ao((t?.width??1200)-o.right),top:8,bottom:0},chrome:[{x:(t?.width??1200)-o.right-176,y:0,width:176,height:100},Ns(t,o)],...o.right>0||o.bottom>0?{dock:o}:{},...i>0?{headroom:i}:{},unit:n,plainGroups:u.schema.kinds.filter(v=>Ar(d.lookup(v,{cardinality:"many",fidelity:"full"}))),cityOrder:Sr(Zr({name:"scene",schema:u.schema,mutations:u.allMutations().filter(v=>!v.derived)}).order.map(v=>v.kind),d.arrangement?.()?.order),screens:d.places().reduce((v,k)=>((v[k.kind]??=[]).push({as:k.as,title:k.title,...k.across?{across:k.across}:{}}),v),{}),...t?{width:t.width,height:Math.max(0,t.height-Math.max(64,l))}:{}}),[e,t,n,u,d,s,w,p,r,h,o.right,o.bottom,i,l])}var ga=224;function Ns(e,t){let n=e?.width??1200,r=e?.height??800,o=58;return{x:n-t.right-ga,y:r-t.bottom-o,width:ga,height:o}}var ct=se(Ce(),1);var ba=se(Ce(),1);function so(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 wa(e){(0,ba.useEffect)(()=>{let t=e.current;if(!t)return;let n=()=>{for(let a of t.querySelectorAll("[data-graview-pick]"))a.getAttribute("tabindex")===null&&a.setAttribute("tabindex","0"),a.getAttribute("role")===null&&$s(a)&&a.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 Bs=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 $s(e){return Bs.has(e.localName.toLowerCase())}var rn=se(Ie(),1);function va({node:e,useDom:t,blur:n,touched:r,frontY:o,centerY:a,screen:i,onDrawnHeight:l,crowded:u,activity:d,scheme:s,canvasWidth:c,canvasHeight:h,selected:y,onSelect:w,onPick:f,onTravel:p,onMenu:v,selection:k,onJackIn:x,onDragStart:O,onDragMove:G,onDragEnd:F,swallowClick:Q,children:z}){let{brand:g,store:E,actsDoor:I}=ye(),A=e.beyond?`${e.beyond.length} more district${e.beyond.length===1?"":"s"}`:e.aggregate?.opens?.in==="place"?`${e.aggregate.label}, ${zt(E.schema,e.aggregate.kind,e.aggregate.memberIds.length)}`:e.aggregate?e.aggregate.label:(()=>{let S=E.graph.getNode(e.id);return S?Dn(E.schema.tryDefinition(e.kind),S):e.id})(),[j,K]=(0,ct.useState)(null),N=Math.round(e.plane)===0&&!e.aggregate;(0,ct.useLayoutEffect)(()=>{if(!N)return;let S=R.current;if(!S)return;let P=()=>{let H=[...S.children].find(X=>X.dataset.graviewKindtag===void 0);if(!H)return;let Z=S.getBoundingClientRect(),U=H.getBoundingClientRect(),V=S.offsetWidth>0?Z.width/S.offsetWidth:1,ne={top:Math.round((U.top-Z.top)/V)-9,right:Math.round((Z.right-U.right)/V)+14};K(X=>X&&X.top===ne.top&&X.right===ne.right?X:ne)};if(typeof ResizeObserver>"u"){P();return}let L=new ResizeObserver(P);L.observe(S);for(let H of S.children)L.observe(H);return()=>L.disconnect()},[N,e.id]);let $=Pr({plane:e.plane,...e.depth!==void 0?{depth:e.depth}:{},onPlot:o!==void 0},s),Y=$.style,B=Tr(Y,e.x,e.y,c,h),J=n?$.blur:0,R=(0,ct.useRef)(null);wa(R);let D=e.natural,b=D?Math.min(e.width/D.width,e.height/D.height):1,M=(0,ct.useRef)(null);(0,ct.useEffect)(()=>{if(!i||!l)return;let S=M.current;if(!S||typeof ResizeObserver>"u")return;let P=()=>{let V=0,ne=0;for(let X of S.children)if(!(!(X instanceof HTMLElement)||X.classList.contains("graview-screen-fullscreen"))){V=Math.max(V,X.offsetTop+X.offsetHeight);for(let ce of[X,...X.querySelectorAll("*")]){let ae=getComputedStyle(ce).overflowY;(ae==="auto"||ae==="scroll")&&(ne+=ce.scrollHeight-ce.clientHeight)}}l(V+ne)},L=0,H=()=>{L||(L=requestAnimationFrame(()=>{L=0,P()}))};P();let Z=new ResizeObserver(H);Z.observe(S);for(let V of S.children)Z.observe(V);let U=new MutationObserver(H);return U.observe(S,{childList:!0,subtree:!0,characterData:!0,attributes:!0}),()=>{L&&cancelAnimationFrame(L),Z.disconnect(),U.disconnect(),l(void 0)}},[i,l,e.id]);let T=t?{transform:Ki(B),transformOrigin:"0 0",filter:J>0?`blur(${J}px)`:void 0,opacity:Cr(Y)*(e.opacity??1),"--graview-lift-low":or(Y.shadow,s),...o!==void 0?{"--graview-front-y":`${o.toFixed(1)}px`}:{},...a!==void 0?{"--graview-center-y":`${a.toFixed(1)}px`}:{}}:{"--graview-lift-low":or(Y.shadow,s)};return(0,rn.jsxs)("div",{ref:R,"data-graview-view":e.id,...t?{}:{drawable:""},"data-graview-plane":Math.round(e.plane),"data-graview-selected":y||void 0,"data-graview-touched":r||void 0,"data-graview-plot":o!==void 0?"":void 0,"data-graview-screen":i?"":void 0,"data-graview-record-focus":Math.round(e.plane)===0&&!e.aggregate&&!D&&!i?"":void 0,"data-graview-nested":e.nestedUnder??void 0,"data-graview-crowded":u||void 0,"data-graview-pinned":e.pinned||void 0,"data-graview-activity":d?d.manner:void 0,"data-graview-wrote":d?.wrote||void 0,"data-graview-read":d&&!d.wrote?!0:void 0,"data-graview-broke":d?.broke||void 0,title:d?`${Fi[d.manner]} ${d.wrote?"changed this":"read this"}: ${d.intent}`:e.aggregate&&Math.round(e.plane)!==0?`Open ${e.aggregate.label}`:void 0,role:"group","aria-label":A,"aria-keyshortcuts":I&&!e.beyond?I.key:void 0,tabIndex:0,onPointerDown:O,onPointerMove:G,onPointerUp:F,onPointerCancel:F,onClick:S=>{if(Q.current)return;let P=S.target?.closest("input, textarea, select, button, a[href], [contenteditable='true']");if(P&&!P.hasAttribute("data-graview-pick"))return;let L=S.metaKey||S.shiftKey,H=gt(S.target);if(H&&H!==e.id){S.stopPropagation(),f(H,L,so(S.target)??void 0);return}w(L)},onKeyDown:S=>{if(I&&!e.beyond&&S.key.toLowerCase()===I.key.toLowerCase()&&!S.metaKey&&!S.ctrlKey&&!S.altKey&&!S.target?.closest("input, textarea, select, [contenteditable='true']")){S.preventDefault(),S.stopPropagation();let U=gt(S.target)??e.id;k.includes(U)||f(U,!1),I.open(S.target instanceof HTMLElement?S.target:S.currentTarget);return}if(S.key!=="Enter"&&S.key!==" "||S.target?.closest("input, textarea, select, button, [contenteditable='true']"))return;let L=gt(S.target);if(S.preventDefault(),S.stopPropagation(),!L||L===e.id){k.length===1&&k[0]===e.id&&!S.metaKey&&!S.shiftKey?x():w(S.metaKey||S.shiftKey);return}let H=so(S.target);(H?k.length===H.length&&H.every(U=>k.includes(U)):k.length===1&&k[0]===L)&&!S.metaKey&&!S.shiftKey?p(L):f(L,S.metaKey||S.shiftKey,H??void 0)},onContextMenu:S=>{let P=gt(S.target);S.preventDefault(),S.stopPropagation();let L=P&&P!==e.id?P:e.id;f(L,!1,(L===P?so(S.target):null)??void 0),v({x:S.clientX,y:S.clientY,on:L})},onDoubleClick:S=>{let P=gt(S.target);if(P&&P!==e.id){S.stopPropagation(),p(P);return}x()},style:{position:"absolute",...t?{}:{pointerEvents:"none"},zIndex:e.opened?He.opened:He.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",...T},children:[D?(0,rn.jsx)("div",{ref:M,"data-graview-natural":`${Math.round(D.width)}x${Math.round(D.height)}`,style:{position:"absolute",left:"50%",top:"50%",width:D.width,height:D.height,transform:`translate(-50%, -50%) scale(${b})`,transformOrigin:"50% 50%",display:"flex",flexDirection:"column"},children:z}):z,Math.round(e.plane)===0&&!e.aggregate?(0,rn.jsxs)("span",{"data-graview-kindtag":"",className:"graview-kind-tag","aria-hidden":"true",style:{...j??{},"--graview-hue":Math.round(hn(e.kind,g?.accents))},children:[(0,rn.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(hn(e.kind,g?.accents))} 55% var(--graview-tint-lightness) / 0.9)`}}),vr(E.schema.tryDefinition(e.kind),e.kind)]}):null]})}var ue=se(Ie(),1);So({search:ei,touchWeights:Yn});var Hs=e=>e?{activity:e}:{},Ds=e=>`${Math.round(e.x)} ${Math.round(e.y)}`,ka=e=>e.stopPropagation(),Ra=.6,Oa=3,Fs=80,Sa=e=>Math.round(e.plane)===1&&(e.compact===!0||e.width<175||e.height<Fs);function js(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 Ws(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:$t(e,r),[e,t,r]),a=(0,q.useRef)(t);a.current=t;let i=(0,q.useCallback)((l,u)=>{let d=a.current,s=(c,h,y)=>Math.max(Math.min(-c,h),Math.min(Math.max(c,h),y+h))-h;return{x:s(l.x,d.x,u.x),y:s(l.y,d.y,u.y)}},[]);return[r,o,i,a,n]}function Vs(e,t,n,r,o,a){let i=n!==null&&!t.overview,l=i?null:n,u=(0,q.useMemo)(()=>{let h=t.pan?{...t,pan:void 0}:t;return l?bn(h,l.id,{x:l.x,y:l.y}):h},[t,l]),d=(0,q.useMemo)(()=>Un(e.graph,e.schema,u,r),[e,u,r,o]),s=(0,q.useMemo)(()=>n&&i?Ko(d,n.id,{x:n.x,y:n.y})??Un(e.graph,e.schema,bn(u,n.id,{x:n.x,y:n.y}),r):d,[d,n,i,e,u,r]);return[(0,q.useMemo)(()=>Uo(s,a??{x:0,y:0}),[s,a]),i]}function Ys(){let[e,t]=(0,q.useState)(!1),[n,r]=(0,q.useState)(!1),o=(0,q.useRef)(null),a=(0,q.useRef)(()=>!1),i=(0,q.useCallback)(()=>{r(!0),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{o.current=null,!a.current()&&r(!1)},160)},[]);return[e,n,t,i,a,()=>{t(!1),r(!1)}]}function zs(e){let t=(0,q.useRef)(!1),n=e!==null&&!t.current;return(0,q.useEffect)(()=>{e!==null&&(t.current=!0)},[e]),n}function Gs({registerScene:e,scheme:t,views:n},r,o){let a=(0,q.useRef)(r);a.current=r,(0,q.useEffect)(()=>(e({whereIs:i=>eo(a.current,o.current,t,n,i)}),()=>e(null)),[e,t,n])}function _s(e,t){(0,q.useEffect)(()=>{let n;return e.onActive(r=>{let o=t.current;if(!o)return;let a=l=>{let u=o.getBoundingClientRect();e.set({x:l.clientX-u.left,y:l.clientY-u.top})},i=()=>e.set(null);r?(o.addEventListener("pointermove",a),o.addEventListener("pointerleave",i),n=()=>{o.removeEventListener("pointermove",a),o.removeEventListener("pointerleave",i)}):(n?.(),n=void 0)})},[e])}function Ks(e,t,n,r,o,a,i,l){(0,q.useEffect)(()=>{let u=t.current;if(!u||!e)return;let d=new Set;for(let c of n.nodes)(r.has(c.id)||c.aggregate?.memberIds.some(h=>r.has(h)))&&d.add(c.id);let s=e({canvas:u,layout:n,dirty:d,hostOf:c=>(u.parentElement??u).querySelector(`[data-graview-view="${CSS.escape(c)}"]`),drawOnDom:o,blur:a,scheme:i,fallBack:l});return()=>{s?.()}},[e,n,r,o,a,i,l])}var Us=Gt(()=>(__graviewPreload(import.meta.url,["./chunk.OJGHDWI6.js","./chunk.V5MYKNL7.js","./chunk.AJZBJBMO.js"]),import("./chunk.YWNHCZQ5.js")));function Xs(e,t){let[n]=(0,q.useState)(()=>{let s=Br();return t?e==="dom"||e==="auto"&&s==="dom"?"dom":"gpu":Hr(e,{operator:s,present:$r()})}),[r,o]=(0,q.useState)(!1),a=(0,q.useCallback)(()=>o(!0),[]),[i,l]=(0,q.useState)(null),u=n==="gpu"&&!t&&!r&&i===null;return(0,q.useEffect)(()=>{if(!u)return;let s=!0;return Us().then(c=>{s&&l(()=>c.attachGpu())},()=>{s&&o(!0)}),()=>{s=!1}},[u]),{attach:(n==="gpu"&&!r?t??i:null)??null,fallBack:a}}function qs(){let[e,t]=(0,q.useState)(()=>new Set),n=(0,q.useCallback)(r=>{t(o=>o.size===r.size&&[...r].every(a=>o.has(a))?o:new Set(r))},[]);return[e,n]}function Qs(){let e=Yr();return t=>{let n=t?e.get(t.id):void 0,r=t?.aggregate?.memberIds??[];if(!n&&r.length===0)return;let o=n,a=n?.wrote??!1,i=n?.read??!1,l=n?.broke??!1;for(let u of r){let d=e.get(u);d&&(a||=d.wrote,i||=d.read,l||=d.broke,(!o||d.at>o.at||d.at===o.at&&d.wrote&&!o.wrote)&&(o=d))}return o?{...o,wrote:a,read:i,broke:l}:void 0}}var Ma=(e,t)=>e.includes(t)?e.filter(n=>n!==t):[...e,t];function Zs(){let{views:e,view:t,setView:n,setSelection:r}=ye(),o=Tt(),a=(0,q.useContext)(_t),i=l=>{if(Ae(l.id)===null&&!l.aggregate)return!1;let u=e.resolve(l.kind,{cardinality:"many",fidelity:"full"})?.view;return u!==void 0&&u.generic!==!0};return l=>({onSelect:u=>{if(pn(l.id)){r(s=>u?Ma(s,l.id):[l.id]);return}let d=l.aggregate?mn(l.id):[];if(t.overview){r(s=>u?[...new Set([...s,l.id])]:[l.id]);return}if(d.length===1&&!u&&Math.round(l.plane)!==0){let s=d[0];n(c=>xo(c,c.relation===s?null:s));return}r(s=>nr(l,s,u))},onPick:(u,d,s)=>r(c=>s?d?[...new Set([...c,...s])]:[...s]:d?Ma(c,u):[u]),onTravel:u=>{n(d=>({...pt(d,u),relation:null})),r([u])},onJackIn:()=>{let u=l.aggregate?.opens;if(u){u.in==="place"?n(c=>bo(c,l.id)):n(c=>Object.entries(u.within).reduce((h,[y,w])=>jn(h,y,w),pt(fn(c,!1),u.focus))),r([]);return}let d=Ae(l.id),s=d!==null&&(o?.byKind[d]??0)>0;if(a&&d!==null&&t.overview&&!i(l)&&!(s&&t.q)){n(c=>jn({...pt(c,`aggregate:${d}`),relation:null},"view",null)),r([]);return}n(c=>wo(c,l.id,{ownPicture:i(l),...s&&c.q?{carry:c.q}:{}})),r(l.aggregate?[]:[l.id])}})}var Js=yn(Gt(()=>(__graviewPreload(import.meta.url,["./chunk.HJCQ6I3S.js","./chunk.VNUHESMZ.js","./chunk.TKUNRFDE.js","./chunk.N2K25KH3.js","./chunk.2FLPDPEL.js","./chunk.UUBYFBPN.js","./chunk.2RVUDRRY.js","./chunk.FOQZADMA.js","./chunk.SDO3U72B.js","./chunk.V5MYKNL7.js","./chunk.AJZBJBMO.js"]),import("./chunk.7LIKEE5Z.js")))),ed=Js.part((e,t)=>(0,ue.jsx)(e.Ribbons,{...t}),{what:"The relations",quiet:!0}),Ea="graview:map-from-above";function td(){let[e,t]=(0,q.useState)(()=>{try{return globalThis.localStorage?.getItem(Ea)==="1"}catch{return!1}}),n=(0,q.useCallback)(r=>{t(r);try{globalThis.localStorage?.setItem(Ea,r?"1":"0")}catch{}},[]);return[e,n]}var nd=yn(Gt(()=>(__graviewPreload(import.meta.url,["./chunk.TKUNRFDE.js","./chunk.N2K25KH3.js","./chunk.6FNMDAX5.js","./chunk.FOQZADMA.js","./chunk.SDO3U72B.js","./chunk.V5MYKNL7.js","./chunk.AJZBJBMO.js"]),import("./chunk.UWW6ZEPY.js")))),od=nd.part((e,t)=>(0,ue.jsx)(e.Plots,{...t}),{quiet:!0});function rd({zoom:e,zoomBy:t,above:n,setAbove:r}){let o=(a,i,l,u)=>(0,ue.jsx)("button",{type:"button",className:"graview-zoom-button","data-testid":`zoom-${a}`,"aria-label":`Zoom ${a}`,title:`Zoom ${a} \u2014 or pinch, or ctrl+wheel`,disabled:u,onClick:()=>t(l),children:i});return(0,ue.jsxs)("div",{className:"graview-zoom","data-graview-foot":"",role:"group","aria-label":"Zoom",onPointerDown:ka,onClick:ka,children:[o("out","\u2212",1/1.25,e<=Ra+1e-6),(0,ue.jsxs)("span",{className:"graview-zoom-level","data-testid":"zoom-level","aria-live":"polite",children:[Math.round(e*100),"%"]}),o("in","+",1.25,e>=Oa-1e-6),(0,ue.jsx)("button",{type:"button",className:"graview-zoom-button graview-zoom-above","data-testid":"from-above","aria-pressed":n,title:n?"See the city at an angle again":"See the city from straight above",onClick:()=>r(!n),children:"From above"})]})}function id({options:e,renderer:t="auto",attachRenderer:n,blur:r=!0,className:o,style:a,animate:i=!0,children:l}){let u=ye(),{store:d,scheme:s,views:c,view:h,setView:y,selection:w,setSelection:f,setMenuAt:p,emphasis:v,brand:k,noteMoved:x,robots:O,motion:G}=u,F=(0,q.useContext)(_t),Q=(0,q.useRef)(null),z=(0,q.useRef)(null),g=_i(z),E=Gi(),{zoomAbout:I,panBy:A}=Di({stage:z,view:h,setView:y}),j=Pt(),K=1,[N,$,Y]=js(h.overview),[B,J]=td(),R=(0,q.useMemo)(()=>B?{...e,tilt:ni}:e,[e,B]),{probe:D,dock:b}=Ni(),M=!h.overview&&(h.zoom||h.past||h.relation)?Math.ceil(14+34*E/16+6):0,T=xa(R,g,E,K*N,b,j,M,h.overview?0:b.bottom),S=Ii(z),[P,L,H,Z,U]=Ws(h),V=(0,q.useMemo)(()=>new Set(Object.keys(h.pins).filter(C=>Ae(C)===null)),[h.pins]),ne=Bi(),[X,ce]=Vs(d,h,ne.held,T,j,L.pan),[ae,Se,ke,Re,Te,Pe]=Ys(),re=zs(g),ee=ki(X,{enabled:i&&!ae&&!Se&&g!==null&&!re});(0,q.useEffect)(()=>G.set(ae||Se||ee.t<1),[G,ae,Se,ee]);let et=Si(),St=Mi(),an=Ti({view:h,result:X,frame:ee,panned:P,closer:K,screenId:null,setCamera:U});Gs(u,ee,z),_s(u.pointer,z);let[_e,Be]=qs(),{attach:ut,fallBack:Ke}=Xs(t,n),tt=wi(r);Ks(ut,Q,ee,et,Be,tt,s,Ke);let Oe=ut===null,Ye=vi(tt&&Oe,ae||Se||ee.t<1),$e=Qs(),Fe=$i({stage:z,pan:h.pan,setView:y,settled:Pe});Te.current=Fe.settle;let{onGroundDown:Mt,onCardDown:Ue,onDragMove:it,onDragUp:Et,swallow:Xe}=Hi({view:h,panned:P,limit:()=>xt(X),panWithin:H,moveByTransform:!0,setView:y,setDragging:ke,noteMoved:x,shift:Fe,district:ne});I.current=(C,he,xe)=>{if(!h.overview)return;Te.current();let Me=$.current,qe=Math.max(Ra,Math.min(Oa,Me*C));if(Math.abs(qe-Me)<1e-4)return;$.current=qe,Re(),Y(qe);let Yt=z.current?.getBoundingClientRect(),In=X.visible??X,ft={x:In.width/2,y:In.height/2},at=Yt&&he!==void 0&&xe!==void 0?{x:he-Yt.left,y:xe-Yt.top}:ft,Tn=qe/Me;y(Pn=>$t(Pn,Go(Pn.pan??{x:0,y:0},Z.current,at,ft,Tn))),x()};let ie=(C,he,xe=xt(X))=>y(Me=>$t(Me,H(xe,{x:(Me.pan?.x??0)+C,y:(Me.pan?.y??0)+he})));Ci(z,b,(C,he)=>ie(C,he)),A.current=(C,he)=>{Re();let xe=xt(X),Me=h.pan??{x:0,y:0},qe=Fe.offset();Fe.shiftTo(H(xe,{x:Me.x+qe.x+C,y:Me.y+qe.y+he}),Me),x()};let ve=Zs(),nt=Nt(),Rt=(0,q.useCallback)(C=>Qt(nt,C).connector.visible,[nt]),je=C=>$e(ee.nodes.find(he=>he.id===C)),Ot=(C,he,xe,Me)=>C.originY+P.y+Zt(xe.col+xe.side/Me,xe.row+xe.side/Me,C.cell,C.tilt).y-he.y,ze={width:X.width,height:X.height},sn={position:"relative",zIndex:He.stage,...ze},dn=C=>eo(ee,z.current,s,c,C),ht=C=>Oe||_e.has(C),Vt=ee.nodes.filter(C=>C.screenOf===void 0).map(C=>(0,ue.jsx)(va,{node:C,crowded:Sa(C),useDom:ht(C.id),blur:Ye||!Oe&&tt,...C.plot&&ee.city&&Math.round(C.plane)===2?{frontY:Ot(ee.city,C,C.plot,1),centerY:Ot(ee.city,C,C.plot,2)}:{},touched:et.has(C.id),...Hs($e(C)),scheme:s,canvasWidth:X.width,canvasHeight:X.height,selected:w.includes(C.id),...ve(C),onMenu:p,selection:w,onDragStart:he=>Ue(C,he),onDragMove:it,onDragEnd:Et,swallowClick:Xe,children:C.beyond?(0,ue.jsx)(Wi,{kinds:C.beyond}):C.aggregate?.opens?(0,ue.jsx)(zi,{node:C}):(0,ue.jsx)(Vi,{node:C,mode:"scene",selected:w.includes(C.id),...Sa(C)?{fidelity:"glyph"}:{}})},C.id));return(0,ue.jsxs)("div",{ref:z,className:`graview-ground${o?` ${o}`:""}`,"data-graview-altitude":h.overview?"":void 0,"data-graview-reach":ee.city?Ds(xt(X)):void 0,"data-graview-settled":ee.t>=1&&!an.gliding()?"":void 0,"data-graview-box":g?`${g.width}x${g.height}`:void 0,"data-graview-renderer":Oe?"dom":"gpu","data-graview-blur":(Oe?Ye:tt)?"":void 0,onPointerDown:Mt,onPointerMove:it,onPointerUp:Et,onPointerCancel:Et,onClick:C=>{Xe.current||C.target.closest("[data-graview-view], button, aside, section[aria-label], [data-graview-offstage], a, input, select")||(f([]),p(null))},style:{position:"relative",width:"100%",height:"100%",cursor:ae?"grabbing":"grab",touchAction:"none","--graview-altitude":h.overview?1:0,...ee.city?{"--graview-lattice-cell":`${ee.city.cell.toFixed(2)}px`,"--graview-lattice-tilt":(ee.city.tilt??.5).toFixed(3),"--graview-lattice-x":`${(ee.city.originX+ee.city.pan.x).toFixed(1)}px`,"--graview-lattice-y":`${(ee.city.originY+ee.city.pan.y).toFixed(1)}px`}:{},...ae?{userSelect:"none"}:{},overflow:"hidden",...a},children:[h.overview&&ee.city?(0,ue.jsx)(q.Suspense,{fallback:null,children:(0,ue.jsx)(ed,{frame:ee,...ze,pan:ee.city.pan,store:d,graphVersion:j,selection:w,view:{overview:h.overview,focusId:h.focusId,beside:F},emphasis:v,hiddenKinds:u.hiddenKinds,drawn:Rt})}):null,(0,ue.jsx)("div",{ref:D,"aria-hidden":"true",style:{position:"absolute",top:0,right:0,width:"var(--graview-dock, 0px)",height:"var(--graview-sheet, 0px)",visibility:"hidden",pointerEvents:"none"}}),ee.city?(0,ue.jsx)(q.Suspense,{fallback:null,children:(0,ue.jsx)(od,{frame:ee,...ze,pan:ee.city?ee.city.pan:P,brand:k,pinned:V,close:K*N>1.2,swallowed:Xe,...h.overview?{chosen:wn(w,{overview:h.overview,focusId:h.focusId,beside:F},C=>d.graph.getNode(C)?.kind).records}:{},onFocus:C=>{let he=Ae(C);he!==null&&y(xe=>pt(xe,Le(he)))}})}):null,Oe?(0,ue.jsx)("div",{"data-graview-stage":"dom","data-graview-world":"",style:{...sn,overflow:"hidden"},children:Vt}):(0,ue.jsxs)("div",{"data-graview-world":"",style:sn,children:[(0,ue.jsx)("div",{"data-graview-stage":"dom","data-graview-under-canvas":"",style:{position:"absolute",left:0,top:0,...ze,overflow:"hidden"},children:Vt.filter(C=>_e.has(String(C.key)))}),(0,ue.jsx)("canvas",{ref:Q,"data-graview-stage":"gpu",content:"drawable",layoutsubtree:"",...ze,style:{display:"block",position:"relative",...ze},children:Vt.filter(C=>!_e.has(String(C.key)))})]}),h.overview&&!ae?(0,ue.jsx)(Ai,{result:X,schema:d.schema,chrome:S?[...T.chrome??[],S]:T.chrome??[],onGo:C=>{ie(C.x,C.y),x()}}):null,h.overview?(0,ue.jsx)(rd,{zoom:N,zoomBy:C=>I.current(C),above:B,setAbove:J}):null,(0,ue.jsx)(pa,{frame:ee,focusId:h.focusId,beside:F,holding:ce,...ze,scheme:s,overview:!!h.overview,selection:w,emphasis:v,stageRef:z,store:d,graphNodes:j,...(C=>C?{provisional:C}:{})(ma(d)),onPickEdge:(C,he)=>{Xe.current||(f([C]),p(he?{...he,on:C}:null))},liveOf:C=>{let he=je(C.from),xe=je(C.to);return he?.wrote&&xe?.wrote?he.at>xe.at?he:xe:void 0}}),(0,ue.jsx)(Ri,{width:X.width,whereIs:dn}),(0,ue.jsx)(Ei,{marks:St.marks,questions:[...O.values()].filter(C=>C.mode==="asking"&&C.at!==null&&C.say).map(C=>({id:C.at,who:C.who,asks:C.say})),whereIs:dn,stageRef:z,...ze}),(0,ue.jsx)(ya,{nodes:ee.nodes,moving:ee.t<1,holding:ce,scheme:s,width:X.width,stageRef:z}),l]})}var Je=se(Ce(),1);function ad(){return Ta(),null}var Ia=()=>window.location.pathname.endsWith(kr),Aa=()=>(Ia()?Er:go)(window.location.hash),sd=e=>(Ia()?Rr:yo)(e);function Ta(){let{view:e,setView:t,views:n,principal:r}=ye(),o=JSON.stringify(r),a=(0,Je.useCallback)(s=>{let c=s.within?.view;if(c===void 0||s.focusId)return s;let h=n.places().find(y=>y.as===c);return h?{...s,focusId:Le(h.kind)}:s},[n]),i=(0,Je.useRef)(!1);(0,Je.useEffect)(()=>{if(typeof window>"u")return;let s=a(Aa());!Fn(s,po)&&!Fn(s,e)&&(i.current=!0,t(s))},[]),(0,Je.useEffect)(()=>{if(typeof window>"u")return;let s=()=>t(a(Aa()));return window.addEventListener("popstate",s),window.addEventListener("hashchange",s),()=>{window.removeEventListener("popstate",s),window.removeEventListener("hashchange",s)}},[t,a]);let l=(0,Je.useRef)(!1),u=(0,Je.useRef)(null),d=(0,Je.useRef)(o);(0,Je.useEffect)(()=>{if(typeof window>"u")return;if(i.current){i.current=!1;return}let s=d.current!==o;d.current=o;let c=sd(e),h=c||`${window.location.pathname}${window.location.search}`;if((window.location.hash||(window.location.href.includes("#")?"#":""))===c){l.current=!0,u.current=e;return}if(!l.current){l.current=!0,u.current=e,window.history.replaceState({graview:Ct.at},"",h);return}if(s||Pa(u.current,e)){window.history.replaceState({graview:Ct.at},"",h),u.current=e;return}u.current=e,window.history.pushState({graview:++Ct.at},"",h),Ct.depth=Ct.at,Ct.tell()},[e,o])}function Pa(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(",")&&dd(e.within,t.within):!1}function dd(e,t){let n=r=>Object.entries(r??{}).sort(([o],[a])=>o.localeCompare(a)).map(([o,a])=>`${o}=${a}`).join("&");return n(La(e))===n(La(t))}function La(e){if(!e||!("q"in e))return e;let{q:t,...n}=e;return n}var yr=se(Ce(),1);var Ca=new WeakMap,ld=64,Na=new WeakMap,cd=0,ud=e=>{if(e===void 0)return 0;let t=Na.get(e);return t===void 0&&Na.set(e,t=cd+=1),t};function Ba(e,t,n,r={}){let o=()=>{let d=[...new Set(t.flatMap(c=>mn(c)))],s=t.map(c=>Lt(c)).filter(c=>c!==null);return Xr(e,t,{...n.principal?{principal:n.principal}:{},kindSelection:d,edgeSelection:s,...n.providers?{providers:n.providers}:{},...n.pins?{pins:n.pins}:{},...n.focus!==void 0?{focus:n.focus}:{},...r})};if(Object.keys(r).length>0)return o();let a=Ca.get(e);if(!a){let d={kept:new Map,at:e.log.length};Ca.set(e,a=d),e.subscribe(()=>d.kept.clear())}a.at!==e.log.length&&(a.kept.clear(),a.at=e.log.length);let i=JSON.stringify([t,n.principal??null,ud(n.providers),n.pins??null,n.focus??null]),l=a.kept.get(i);if(l)return l;let u=o();return a.kept.set(i,u),a.kept.size>ld&&a.kept.delete(a.kept.keys().next().value),u}function hd(e,t,n={}){return Ba(e,t,n)}function fd(e={}){let{store:t,selection:n,principal:r,providers:o}=ye(),{about:a,principal:i=r,providers:l=o,pins:u,focus:d,...s}=e,c=a??n,h=Pt();return(0,yr.useMemo)(()=>Ba(t,c,{principal:i,providers:l,pins:u,focus:d},s),[t,c,e,h,i,l])}function md(){let{store:e,principal:t}=ye();return(0,yr.useMemo)(()=>({preview:(n,r)=>Qr(e,n,r??{},{pressed:t?{author:t}:{}}),apply:(n,r)=>qr(e,n,r??{},{author:t})}),[e,t])}export{Qa as a,Za as b,Ja as c,es as d,ts as e,ns as f,id as g,ad as h,hd as i,fd as j,md as k};
@@ -1,4 +1,4 @@
1
- import{a as k}from"./chunk.G4JJXA63.js";import{a as Q}from"./chunk.B2IRADR2.js";import{a as Y}from"./chunk.IAZRY42B.js";import{a as X}from"./chunk.4BBJ62ZO.js";import{c as _}from"./chunk.2IX3CZNP.js";import{_c as G,ad as H,bd as P,cd as J,ib as q,jb as z}from"./chunk.5ZMENPY4.js";var O=e=>"failed"in e;function ue(e,n){let r=e.schema.kinds,t=e.policy?.sees;if(!t?.length||z(n))return{kinds:r};let o=q(n).roles??[],i=new Set(t.filter(s=>s.roles==="*"||o.some(a=>s.roles.includes(a))).flatMap(s=>s.kinds));return{kinds:r.filter(s=>i.has(s))}}function L(e,n){if(!n)return e;let r=new Set(n.kinds.filter(i=>e.tryDefinition(i)!==void 0));if(r.size===e.kinds.length)return e;let t=new Map,o=i=>{if(r.has(i)){if(!t.has(i)){let s=e.tryDefinition(i),a=Object.fromEntries(Object.entries(s?.edges??{}).flatMap(([l,d])=>{if(d.to==="*")return[[l,d]];let c=d.to.filter(u=>r.has(u));return c.length>0?[[l,{...d,to:c}]]:[]}));t.set(i,{...s,edges:a})}return t.get(i)}};return{...e,definitions:e.definitions.filter(i=>r.has(i.kind)),kinds:e.kinds.filter(i=>r.has(i)),tryDefinition:o,definition:i=>{let s=o(i);if(!s)throw new Error(`Unknown node kind "${i}"`);return s}}}var fe=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),y=e=>fe(e).replace(/[-_]+/g," ").trim();function I(e){let n=[];for(let t of e.kinds){let o=e.tryDefinition(t);if(!o)continue;let i=o.display?.labels??{},s=Object.entries(o.fields?.shape??{}).filter(([d])=>d!=="id"&&d!=="kind").map(([d,c])=>{let u=X(c);return{name:d,type:u?.type,...u?.options?{options:u.options}:{},words:(i[d]??y(d)).toLowerCase()}}),a=Object.entries(o.edges??{}).map(([d,c])=>({name:d,from:t,to:c.to==="*"?e.kinds.filter(u=>u!==t):c.to,words:y(d)})),l=(o.plural??`${y(t)}s`).toLowerCase();n.push({kind:t,plural:l,noun:(o.noun??y(t)).toLowerCase(),fields:s,roles:o.fieldRoles??{},edges:a})}let r=new Map(n.map(t=>[t.kind,t]));return{schema:e,kinds:n,info:t=>r.get(t)}}var $=(e,n)=>n===void 0?void 0:e.fields.find(r=>r.name===n),A=e=>e?.type==="date"||e?.type==="datetime",N=e=>e?.type==="number"||e?.type==="integer"||e?.type==="duration",re=e=>` ${e.toLowerCase().replace(/[“”"’‘]/g,"'").replace(/[^\p{L}\p{N}' -]+/gu," ").replace(/\s+/g," ").trim()} `,E=(e,n)=>e.includes(` ${n} `),x=e=>e.endsWith("ies")?`${e.slice(0,-3)}y`:e.endsWith("ses")?e.slice(0,-2):e.endsWith("s")?e.slice(0,-1):e;function pe(e,n){let r=[];for(let t of n.kinds){let o=new Set([t.plural,t.noun,`${t.noun}s`,y(t.kind),`${y(t.kind)}s`]),i=-1;for(let s of o){let a=e.indexOf(` ${s} `);a>=0&&(i<0||a<i)&&(i=a)}i>=0&&r.push({info:t,at:i})}return r.sort((t,o)=>t.at-o.at).map(t=>t.info)}function v(e,n,r){let t=n.trim().toLowerCase();if(t.length===0)return;let o=e.fields.filter(i=>!r||r(i));return o.find(i=>i.words===t||y(i.name)===t||i.name.toLowerCase()===t)??o.find(i=>i.words===x(t)||y(i.name)===x(t))??o.find(i=>t.split(" ").some(s=>s.length>2&&(i.words.split(" ").includes(s)||i.words.split(" ").includes(x(s)))))}function oe(e,n,r){let t=n.trim().toLowerCase();if(t.length!==0)return e.edges.find(o=>o.words===t||o.name.toLowerCase()===t)??e.edges.find(o=>o.to.some(i=>{let s=r.info(i);return s!==void 0&&(s.noun===x(t)||s.plural===t||y(i)===x(t))}))??e.edges.find(o=>t.split(" ").some(i=>i.length>2&&o.words.split(" ").includes(i)))}function U(e){return/ (?:grouped |group |split |sorted |organi[sz]ed )?by ([\p{L}\p{N}' -]+?)(?= (?:and|with|for|in|on|only|where|from|this|that|as|sorted|grouped) |\s*$)/u.exec(e)?.[1]?.trim()}var me=/\bwho\b.*\b(covers?|cover|tends?|owns?|handles?|does|works? on|looks? after|is on|is assigned|staffs?|runs?)\b|\bcoverage\b|\bmatrix\b|\bwho covers\b/,ge=/\bcalendar\b|\bmonth\b|\bagenda\b|\bschedule\b|\bdue\b|\bdeadlines?\b|\bdates?\b|\bwhen\b/,ye=/\btimeline\b|\bover time\b|\bgantt\b|\bspans?\b|\bweek\b/,he=/\bboard\b|\bkanban\b|\bcolumns?\b|\bpipeline\b|\bstages?\b|\bstatus\b/,be=/\blaid out\b|\blayout\b|\bseating\b|\bwhere (?:they|it|each) (?:sits?|lies?|stands?)\b|\bfloor\b/,we=/\bplan\b|\bmap\b|\bregions?\b/,ke=/\blist\b|\btable\b|\bgroup(?:ed)? by\b|\bsort(?:ed)? by\b|\bonly\b|\bjust the\b/;function $e(e){let n=[];return/\blist\b|\btable\b/.test(e)&&n.push("blocks"),me.test(e)&&n.push("coverage"),be.test(e)&&n.push("board"),(/\bfloor plan\b/.test(e)||we.test(e))&&n.push("plan"),ye.test(e)&&n.push("timeline"),ge.test(e)&&n.push("calendar"),he.test(e)&&n.push("columns"),ke.test(e)&&!n.includes("blocks")&&n.push("blocks"),n.length===0&&U(e)&&n.push("columns"),n}var se=e=>{let n=r=>r?` and not ${r}`:"";if(/\boverdue\b|\blate\b|\bpast due\b/.test(e))return{cond:(r,t)=>`days(today(), ${r}) < 0${n(t)}`,says:r=>`overdue by ${r.words}`};if(/\btoday\b/.test(e))return{range:"day",cond:r=>`days(today(), ${r}) == 0`,says:r=>`with ${r.words} today`};if(/\bthis week\b|\bnext 7 days\b|\bnext week\b/.test(e))return{range:"week",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 6`,says:r=>`with ${r.words} in the next week`};if(/\bthis month\b|\bnext 30 days\b|\bnext month\b/.test(e))return{range:"month",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 30`,says:r=>`with ${r.words} in the next month`};if(/\blast month\b|\bpast month\b/.test(e))return{range:"month",cond:r=>`days(today(), ${r}) >= -30 and days(today(), ${r}) <= 0`,says:r=>`with ${r.words} in the last month`};if(/\bthis year\b/.test(e))return{range:"year",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 365`,says:r=>`with ${r.words} in the next year`};if(/\bquarter\b/.test(e))return{range:"quarter",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 91`,says:r=>`with ${r.words} in the next quarter`}},M=e=>{if(/\bagenda\b|\bin order\b/.test(e))return"agenda";if(/\btoday\b|\bday\b/.test(e))return"day";if(/\bweek\b/.test(e))return"week";if(/\bquarter\b/.test(e))return"quarter";if(/\byears\b/.test(e))return"years";if(/\byear\b/.test(e))return"year";if(/\bmonth\b/.test(e))return"month"},Z=/^(user|person|people|member|staff|gardener|volunteer|owner|agent|employee|worker|team|player|customer|client|contact|party|attendee|guest)s?$/,j=class extends Error{},h=e=>{throw new j(e)};function Se(e,n){let r=e.fields.filter(i=>i.type==="enum");if(n){let i=v(e,n);if(i&&i.type==="enum")return i;i&&h(`${e.plural}' ${i.words} is not a choice, so it has no columns`)}let t=$(e,e.roles.status??e.roles.column);if(t?.type==="enum")return t;let o=r.find(i=>/^(status|stage|state|phase)$/.test(i.name));return o||(r[0]?r[0]:h(`${e.plural} have no choice field to put in columns`))}function ee(e,n){let r=e.fields.filter(A),t=l=>{let d=$(e,e.roles[l]);return A(d)?d:void 0},i=r.find(l=>E(n,l.words)||E(n,y(l.name)))??t("start")??r.find(l=>/^(due|date|on|at|start|starts|begins|from|sown|when)/i.test(l.name))??r[0];if(!i)return h(`no date field on ${e.plural}`);let s=t("end")??r.find(l=>l!==i&&/^(end|ends|until|to|finish|finished|harvested|due|closes|through)/i.test(l.name)),a=e.fields.find(l=>l.type==="boolean"&&/^(done|finished|complete|completed|closed)$/.test(l.name));return{start:i,...s&&s!==i?{end:s}:{},...a?{done:a}:{}}}function ie(e){let n=$(e,e.roles.start),r=$(e,e.roles.end),t=$(e,e.roles.column??e.roles.day??e.roles.columns);if(N(n)&&N(r)&&t?.type==="enum")return{start:n,end:r,column:t}}function De(e,n,r,t){let o=[];for(let s of e.kinds)for(let a of s.edges)for(let l of a.to){let d=e.info(l);if(!d||d.kind===s.kind)continue;let c=0;n.includes(s)&&(c+=4),n.includes(d)&&(c+=4),(Z.test(d.kind)||Z.test(d.noun))&&(c+=3),t&&(a.words.includes(t)||d.noun===x(t))&&(c+=5),a.words.split(" ").some(u=>u.length>2&&r.includes(` ${u}`))&&(c+=2),o.push({rows:s,across:d,link:a,score:c})}let i=o.sort((s,a)=>a.score-s.score)[0];return i||h(n[0]?`${n[0].plural} are joined to nothing else, so there is no who-covers-what to draw`:"nothing here is joined to anything else, so there is no who-covers-what to draw")}function ae(e,n,r,t,o){let i=U(t);switch(e){case"columns":{if(i){let s=v(n,i);if(!s||s.type!=="enum"){let a=oe(n,i,r);if(a){let l=r.info(a.to[0]);return{lens:"coverage",kind:n.kind,across:l.kind,link:a.name}}}}return{lens:"columns",kind:n.kind,column:Se(n,i).name}}case"calendar":{let s=ee(n,t),a=M(t);return{lens:"calendar",kind:n.kind,start:s.start.name,...s.end?{end:s.end.name}:{},...s.done?{done:s.done.name}:{},...a?{range:a}:{}}}case"timeline":{let s=ie(n);if(s&&!/\bdates?\b|\bdue\b|\bdeadlines?\b|\bmonths?\b|\byears?\b/.test(t))return{lens:"timeline",kind:n.kind,start:s.start.name,end:s.end.name,column:s.column.name};let a=ee(n,t);return{lens:"calendar",kind:n.kind,start:a.start.name,...a.end?{end:a.end.name}:{},...a.done?{done:a.done.name}:{},range:M(t)??"quarter"}}case"coverage":{let s=De(r,o,t,i);return{lens:"coverage",kind:s.rows.kind,across:s.across.kind,link:s.link.name}}case"board":{let s=$(n,n.roles.x)??n.fields.find(c=>c.name==="x"),a=$(n,n.roles.y)??n.fields.find(c=>c.name==="y");if(!N(s)||!N(a))return h(`${n.plural} have no x and y to be laid out by`);let d=r.kinds.flatMap(c=>c.edges.filter(u=>u.to.includes(n.kind)&&c.kind!==n.kind))[0]??n.edges[0];return d?{lens:"board",kind:n.kind,x:s.name,y:a.name,fill:d.name,...d.from!==n.kind?{fillFrom:"occupant"}:{}}:h(`nothing is joined to ${n.plural} to fill them`)}case"plan":{let s=$(n,n.roles.outline)??n.fields.find(a=>a.name==="outline");return s?{lens:"plan",kind:n.kind,outline:s.name}:h(`${n.plural} have no outline to draw a plan from`)}case"blocks":{let s={lens:"blocks",kind:n.kind,as:/\bcards?\b/.test(t)?"card":"row"},a=/ group(?:ed)? by ([\p{L}\p{N} -]+?)(?= (?:and|only|sorted|with)|\s*$)/u.exec(t)?.[1]??(i&&!/ sort(?:ed)? by /.test(t)?i:void 0);if(a){let c=v(n,a);if(!c||c.type!=="enum")return h(c?`${n.plural}' ${c.words} is not a choice, so they cannot be grouped by it`:`${n.plural} have nothing called ${a} to group by`);s.group=c.name}let l=/ sort(?:ed)? by ([\p{L}\p{N} -]+?)(?= (?:and|only|grouped|with)|\s*$)/u.exec(t)?.[1];if(l){let c=v(n,l);if(!c)return h(`${n.plural} have nothing called ${l} to sort by`);s.sort={by:c.name,.../\b(newest|latest|desc|descending|most)\b/.test(t)?{direction:"desc"}:{}}}let d=V(n,t);return d.length>0&&(s.where=d),s}}}function V(e,n){let r=[],t=se(n);if(t){let o=e.fields.filter(A),i=$(e,e.roles.start),s=o.find(l=>E(n,l.words))??(A(i)?i:void 0)??o[0];(!s||!A(s))&&h(`no date field on ${e.plural}`);let a=e.fields.find(l=>l.type==="boolean"&&/^(done|finished|complete|completed|closed)$/.test(l.name));r.push({expr:t.cond(s.name,/\boverdue\b|\blate\b|\bpast due\b/.test(n)?a?.name:void 0),says:t.says(s)})}if(/\bonly\b|\bjust\b|\bthat are\b|\bwhich are\b/.test(n)){for(let o of e.fields){if(o.type!=="enum")continue;let i=o.options?.find(s=>E(n,s.toLowerCase())||E(n,y(s)));i&&r.push({expr:`${o.name} == '${i.replace(/'/g,"")}'`,says:`that are ${y(i)}`})}if(/\bnot done\b|\bundone\b|\bunfinished\b|\bopen ones\b|\bstill to do\b/.test(n)){let o=e.fields.find(i=>i.type==="boolean"&&/^(done|finished|complete|completed)$/.test(i.name));o&&r.push({expr:`not ${o.name}`,says:`not ${o.words}`})}}return r}var B={columns:"A board",calendar:"A calendar",timeline:"A timeline",coverage:"A grid",board:"A layout",plan:"A plan",blocks:"A list",reach:"A picture"};function Re(e,n){let r=n.info(e.kind),t=o=>o?$(r,o)?.words??y(o):"";switch(e.lens){case"columns":return{title:`${k(r.plural)} by ${t(e.column)}`,detail:`of ${r.plural} by ${t(e.column)}`};case"calendar":{let o=e.range??"month";if(o==="agenda")return{title:`${k(r.plural)} in date order`,detail:`of ${r.plural} in order of ${t(e.start)}`};let i=o==="years"?"year":o;return{title:`${k(r.plural)} by ${i}`,detail:`of ${r.plural} by ${t(e.start)}, a ${i} at a time`}}case"timeline":return{title:`${k(r.plural)} over the ${t(e.column)}`,detail:`of ${r.plural} from ${t(e.start)} to ${t(e.end)}, by ${t(e.column)}`};case"coverage":{let o=n.info(e.across);return{title:`${k(r.plural)} by ${o.noun}`,detail:`of which ${o.noun} covers which ${r.noun}`}}case"board":return{title:`${k(r.plural)} where they stand`,detail:`of ${r.plural} where they stand`};case"plan":return{title:`${k(r.plural)} on a plan`,detail:`of ${r.plural}`};default:{let o=[e.where?.map(i=>i.says).join(" and "),e.group?`by ${t(e.group)}`:void 0,e.sort?`in order of ${t(e.sort.by)}`:void 0].filter(i=>!!i);return{title:[k(r.plural),...o].join(" "),detail:[`of ${r.plural}`,...o].join(" ")}}}}function Ae(e,n){let r={title:n,on:e.kind};switch(e.lens){case"columns":return{name:"columns",...r,bindings:{[e.kind]:{column:e.column}}};case"calendar":return{name:"calendar",...r,bindings:{[e.kind]:{start:e.start,...e.end?{end:e.end}:{},...e.done?{done:e.done}:{}}},...e.range?{options:{range:e.range}}:{}};case"timeline":return{name:"timeline",...r,bindings:{[e.kind]:{start:e.start,end:e.end,column:e.column}}};case"coverage":return{name:"coverage",...r,bindings:{rows:{kind:e.kind},columns:{kind:e.across},link:{edge:e.link}}};case"board":return{name:"board",...r,bindings:{slots:{kind:e.kind},x:{field:e.x,on:"slots"},y:{field:e.y,on:"slots"},fill:{edge:e.fill}},...e.fillFrom?{options:{fillFrom:e.fillFrom}}:{}};case"plan":return{name:"plan",...r,bindings:{regions:{kind:e.kind},outline:{field:e.outline,on:"regions"}}};default:{let t=e.where?.length?` where ${e.where.map(i=>e.where.length>1?`(${i.expr})`:i.expr).join(" and ")}`:"",o={list:`all('${e.kind}')${t}`,as:e.as??"row"};return e.group&&(o.group=e.group),e.sort&&(o.sort=e.sort.direction?{by:e.sort.by,direction:e.sort.direction}:e.sort.by),o.empty="Nothing here yet.",{name:"blocks",...r,options:{blocks:[o]}}}}}function C(e,n){let r=o=>o.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,""),t=new Set(["home","overview",...Q(n).map(o=>o.slug),...(n.lenses??[]).flatMap(o=>o.title?[r(o.title)]:[])]);if(!t.has(r(e)))return e;for(let o=2;;o++)if(!t.has(r(`${e} ${o}`)))return`${e} ${o}`}var ne={title:[],headline:[],text:["tone"],figure:["as","currency","label"],list:["sort","limit","group","empty","as"],progress:["label"],group:["direction"],when:["show"],divider:[]};function Ee(e,n){if(!Array.isArray(n)||n.length===0)return"it has no blocks to draw";if(n.length>40)return"it has more blocks than a place draws";let r=(s,a)=>{if(typeof s!="string"||s.trim()==="")return`its ${a} says nothing`;try{return _(s)}catch(l){return`its ${a} does not read: ${l instanceof Error?l.message.replace(/ \(at character.*$/,""):String(l)}`}},t=s=>{if(s.t==="where")return t(s.set);if(s.t==="call"&&s.fn==="all"){let a=s.args[0];return a?.t==="lit"&&typeof a.value=="string"?e.info(a.value)??null:void 0}},o=(s,a)=>{switch(s.t){case"lit":return;case"ident":return a&&!a.fields.some(l=>l.name===s.name)&&!a.edges.some(l=>l.name===s.name)?`${a.plural} have nothing called ${s.name}`:void 0;case"member":return o(s.object,a);case"list":return s.items.map(l=>o(l,a)).find(Boolean);case"unary":return o(s.operand,a);case"binary":return o(s.left,a)??o(s.right,a);case"where":{let l=t(s.set);return l===null?"Nothing by that name here":o(s.set,a)??o(s.filter,l??void 0)}case"call":return s.fn==="all"?t(s)===null?"Nothing by that name here":void 0:s.args.map(l=>o(l,a)).find(Boolean)}},i=(s,a)=>{if(a>4)return"its blocks nest deeper than a place draws";for(let l of s){if(!w(l))return"a block is not an object";let d=Object.keys(ne).find(p=>p in l);if(!d)return`"${Object.keys(l)[0]??""}" is not a block a place draws`;let c=Object.keys(l).find(p=>p!==d&&p!=="key"&&!ne[d].includes(p));if(c)return`a ${d} block takes no "${c}"`;let u=l[d];if(d==="list"||d==="figure"||d==="when"){if(d==="figure"&&u===!0)continue;let p=r(u,d);if(typeof p=="string")return p;let g=o(p,void 0);if(g)return g;if(d==="list"){let f=t(p);if(f==null)return f===null?"Nothing by that name here":"its list does not say which records it lists, like all('task')";for(let m of["group","sort"]){let b=l[m],S=typeof b=="string"?b:w(b)&&typeof b.by=="string"?b.by:void 0;if(b===void 0)continue;let D=S?f.fields.find(ce=>ce.name===S):void 0;if(!D)return`${f.plural} have nothing called ${String(S??b)} to ${m} by`;if(m==="group"&&D.type!=="enum")return`${f.plural}' ${D.words} is not a choice, so they cannot be grouped by it`}}if(d==="when"){let f=l.show;if(!Array.isArray(f))return"a when block shows a list of blocks";let m=i(f,a+1);if(m)return m}}else if(d==="group"){if(!Array.isArray(u))return"a group block holds a list of blocks";let p=i(u,a+1);if(p)return p}else{if(d!=="divider"&&typeof u!="string")return`a ${d} block says words`;if(typeof u=="string")for(let p of u.matchAll(/\{([^{}]*)\}/g)){let g=p[1].split(/\|(?![|])/)[0],f=r(g,`${d}'s braces`);if(typeof f=="string")return f;let m=o(f,void 0);if(m)return m}}}};return i(n,1)}function T(e,n,r){let t=L(e.schema,r),o=f=>({ok:!1,failed:`Couldn't draw that: ${f.replace(/\.$/,"")}.`});if(!P(n.name)||n.name==="reach")return o(`"${String(n.name)}" is not a picture the seat can draw; it draws ${H.filter(f=>f!=="reach").join(", ")}`);if(typeof n.title!="string"||n.title.trim().length===0||n.title.length>80)return o("it needs a title of a few words");if(typeof n.on!="string"||!t.tryDefinition(n.on))return o("Nothing by that name here");let i=G[n.name],s=n.bindings??{};if(i.binds==="fields")for(let[f,m]of Object.entries(s)){if(!t.tryDefinition(f))return o("Nothing by that name here");let b=Object.keys(t.tryDefinition(f).fields?.shape??{});for(let[S,D]of Object.entries(m??{}))if(typeof D!="string"||!b.includes(D))return o(`${y(f)} has no field "${String(D)}" for its ${S}`);for(let S of i.requiredRoles)if(!(S in(m??{})))return o(`a ${n.name} needs ${y(f)}'s ${S}`)}else if(i.binds==="entities")for(let f of i.requiredRoles){let m=s[f];if(!m)return o(`a ${n.name} needs its ${f}`);if(typeof m.kind=="string"&&!t.tryDefinition(m.kind))return o("Nothing by that name here")}let a={...e,schema:t,lenses:[...e.lenses??[],n]},l=a.lenses.length-1,d=J(a),c=`lenses.${l}`,u=d.findings.find(f=>f.path===c||f.path.startsWith(`${c}.`));if(u)return o(u.message.replace(/^"[^"]*" /,"it "));let p=d.undrawn.find(f=>f.index===l);if(p)return o(p.why);let g=d.drawn.find(f=>f.index===l);if(!g)return o("its bindings name something the app does not have");if(g.as==="overview")return o(`"${n.title}" is the scene's own address; give it another title`);if(n.name==="blocks"){let f=Ee(I(t),n.options?.blocks);if(f)return o(f)}return{ok:!0,drawn:g}}function K(e){return{op:"add-lens",title:e.title,lens:e.name,on:e.on,...e.bindings?{bindings:e.bindings}:{},...e.options?{options:e.options}:{}}}function xe(e){return{op:"remove-lens",title:e.title,on:e.on}}var w=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function de(e){let n=w(e)?e:{},r=String(n.lens??n.name??""),t=n.bindings,o=typeof n.on=="string"?n.on:w(t)&&G[r]?.binds==="fields"?Object.keys(t)[0]??"":"";return{name:r,title:typeof n.title=="string"?n.title.trim():"",on:o,...w(t)?{bindings:t}:{},...w(n.options)?{options:n.options}:{}}}function ve(e){let n=o=>w(e.bindings?.[o])?e.bindings[o]:{},r=o=>typeof o=="string"?o:void 0,t=n(e.on);switch(e.name){case"columns":return r(t.column)?{lens:"columns",kind:e.on,column:t.column}:void 0;case"calendar":{let o=r(e.options?.range);return r(t.start)?{lens:"calendar",kind:e.on,start:t.start,...r(t.end)?{end:t.end}:{},...r(t.done)?{done:t.done}:{},...o?{range:o}:{}}:void 0}case"timeline":return r(t.start)&&r(t.end)&&r(t.column)?{lens:"timeline",kind:e.on,start:t.start,end:t.end,column:t.column}:void 0;case"coverage":{let o=w(e.bindings?.columns)?r(e.bindings.columns.kind):void 0,i=w(e.bindings?.link)?r(e.bindings.link.edge):void 0;return o&&i?{lens:"coverage",kind:e.on,across:o,link:i}:void 0}case"blocks":{let o=e.options?.blocks;if(!Array.isArray(o)||o.length!==1||!w(o[0]))return;let i=o[0],s=new RegExp(`^all\\('${e.on}'\\)(?: where (.+))?$`).exec(String(i.list??""));if(!s)return;let a=i.sort;return{lens:"blocks",kind:e.on,as:i.as==="card"?"card":"row",...typeof i.group=="string"?{group:i.group}:{},...typeof a=="string"?{sort:{by:a}}:w(a)&&typeof a.by=="string"?{sort:{by:a.by,...a.direction==="desc"?{direction:"desc"}:{}}}:{},...s[1]?{where:[{expr:s[1],says:"as asked"}]}:{}}}default:return}}function W(e,n,r,t,o){let i=I(L(e.schema,t)).info(n.on),s=ve(n);return{title:n.title,said:`${B[n.name]??"A picture"} of ${i?.plural??y(n.on)}.`,kind:n.on,lens:n,drawn:r,edit:K(n),by:o,asks:[],...s?{recipe:s}:{}}}function te(e){return{title:e.title,said:e.said,lens:{title:e.lens.title,lens:e.lens.name,on:e.lens.on,...e.lens.bindings?{bindings:e.lens.bindings}:{},...e.lens.options?{options:e.lens.options}:{}},edit:e.edit,by:e.by,check:"It draws, and graview check would take it."}}function F(e,n,r,t,o){let i=Re(e,n),s=e.title??o??C(i.title,r.app),a=Ae(e,s),l=T(r.app,a,r.sight);return l.ok?{title:s,said:`${B[e.lens]} ${i.detail}.`,kind:e.kind,lens:a,drawn:l.drawn,edit:K(a),by:"template",asks:t,recipe:e}:{failed:l.failed,...r.lastGood?{lastGood:r.lastGood}:{}}}function Ye(e,n){let r=I(L(n.app.schema,n.sight)),t=r.info(e.kind);if(!t)return{failed:"Couldn't draw that: Nothing by that name here."};let o=e.lens==="blocks"&&!e.group&&!e.sort&&!e.where?.length&&e.title===void 0;return F(o?{...e,title:C(`Every ${t.noun}`,n.app)}:e,r,n,[])}function Le(e,n,r,t){if(r.length>0)return r;let o=s=>{switch(e){case"columns":return s.fields.some(a=>a.type==="enum");case"calendar":return s.fields.some(A);case"timeline":return ie(s)!==void 0||s.fields.some(A);case"coverage":return s.edges.some(a=>a.to.some(l=>l!==s.kind));case"board":return s.fields.some(a=>a.name==="x")&&s.fields.some(a=>a.name==="y");case"plan":return s.fields.some(a=>a.name==="outline")||s.roles.outline!==void 0;default:return!0}};return[...n.kinds.filter(o)].sort((s,a)=>Number(a.fields.some(l=>E(t,l.words)))-Number(s.fields.some(l=>E(t,l.words))))}function Ie(e,n){let r=I(L(n.app.schema,n.sight)),t=re(e),o=$e(t);if(o.length===0)return;let i=pe(t,r),s;for(let a of o){let l=a==="coverage"?[i[0]??r.kinds[0]].filter(d=>!!d):Le(a,r,i,t);for(let d of l)try{let c=ae(a,d,r,t,i),u=F(c,r,n,[e]);if(!O(u))return u;s??=u.failed}catch(c){if(!(c instanceof j))throw c;s??=`Couldn't draw that: ${c.message}.`}l.length===0&&i.length===0&&(s??=`Couldn't draw that: nothing here has what ${B[a].toLowerCase()} needs.`)}return{failed:s??"Couldn't draw that: Nothing by that name here.",...n.lastGood?{lastGood:n.lastGood}:{}}}async function Oe(e,n){let r=n.lastGood?{lastGood:n.lastGood}:{};if(e.trim().length===0)return{failed:"Say what you would like to see, like \u201Ca board of tasks by status\u201D.",...r};let t=Ie(e,n);if(t&&!O(t))return t;if(!n.complete)return t??{failed:"Couldn't draw that: drawing freely needs AI, which isn't on here. Ask for a board, a calendar, a timeline, a list or who covers what.",...r};let o=await le(e,n,void 0);return O(o)&&t?t:o}async function je(e,n,r){let t={lastGood:e},o={...r,lastGood:e},i=I(L(r.app.schema,r.sight)),s=re(n),a=i.info(e.kind),l=[...e.asks,n];if(!a)return{failed:"Couldn't change that: Nothing by that name here.",...t};let d=e.recipe,c=/^ (?:call|name|title) (?:it|this)? ?(.+?) $/.exec(s)??/ (?:call|name) it (.+?) $/.exec(s);try{if(c){let g=n.replace(/^.*?\b(?:call|name|title)\b\s*(?:it|this)?\s*/i,"").replace(/^["“']|["”']$/g,"").trim();if(g.length===0)return{failed:"Couldn't change that: say what to call it.",...t};let f={...e.lens,title:C(g,r.app)},m=T(r.app,f,r.sight);return m.ok?{...e,title:f.title,lens:f,drawn:m.drawn,edit:K(f),asks:l,...d?{recipe:{...d,title:f.title}}:{}}:{failed:m.failed,...t}}let p=/ as (?:a |an )?(board|kanban|calendar|timeline|list|table|cards|rows|grid|plan|layout)\b/.exec(s);if(p){let g=p[1]==="board"||p[1]==="kanban"?"columns":p[1]==="calendar"?"calendar":p[1]==="timeline"?"timeline":p[1]==="grid"?"coverage":p[1]==="plan"?"plan":p[1]==="layout"?"board":"blocks",f=ae(g,a,i,s,[a]),m=p[1]==="cards"?"card":p[1]==="rows"?"row":void 0,b=g==="blocks"&&d?.lens==="blocks"?{...d,...m?{as:m}:{}}:g==="blocks"&&d?.lens==="columns"?{...f,group:d.column,...m?{as:m}:{}}:f;return F(R(b),i,o,l)}if(d){let g=Te(d,a,i,s);if(g)return F(g,i,o,l)}}catch(p){if(!(p instanceof j))throw p;return{failed:`Couldn't change that: ${p.message}.`,...t}}if(!r.complete)return{failed:"Couldn't change that: changing it freely needs AI, which isn't on here. Try \u201Cgroup by status\u201D, \u201Conly this month\u201D or \u201Cas a calendar\u201D.",...t};let u=await le(n,o,e);return O(u)?u:{...u,asks:l}}var R=e=>{let{title:n,...r}=e;return r};function Te(e,n,r,t){let o=/ (?:group(?:ed)?|split|organi[sz]ed?|put them|columns) by ([\p{L}\p{N} -]+?)(?= (?:and|only|with)|\s*$)/u.exec(t)?.[1]??(/^ by /.test(t)?U(t):void 0);if(o){let d=v(n,o);if(d?.type==="enum")return e.lens==="blocks"?{...R(e),group:d.name}:{lens:"columns",kind:e.kind,column:d.name};let c=oe(n,o,r);return c?{lens:"coverage",kind:e.kind,across:c.to[0],link:c.name}:h(d?`${n.plural}' ${d.words} is not a choice, so they cannot be grouped by it`:`${n.plural} have nothing called ${o} to group by`)}let i=/ (?:sort(?:ed)?|order(?:ed)?) by ([\p{L}\p{N} -]+?)(?= (?:and|only|with)|\s*$)/u.exec(t)?.[1];if(i){let d=v(n,i);return d?{...e.lens==="blocks"?R(e):{lens:"blocks",kind:e.kind,as:"row",...e.lens==="columns"?{group:e.column}:{}},sort:{by:d.name,.../\b(newest|latest|desc|descending|most)\b/.test(t)?{direction:"desc"}:{}}}:h(`${n.plural} have nothing called ${i} to sort by`)}if(/\b(?:all of them|everything|show all|clear the filter|no filter|without the filter)\b/.test(t)){if(e.lens!=="blocks"||!e.where)return h("it already shows all of them");let{where:d,...c}=R(e);return c}let s=se(t);if(s&&e.lens==="calendar"&&s.range)return{...R(e),range:s.range};if(s&&e.lens==="calendar"&&!s.range)return{lens:"blocks",kind:e.kind,as:"row",sort:{by:e.start},where:V(n,t)};let a=V(n,t);if(a.length>0){let d=e.lens==="blocks"?R(e):{lens:"blocks",kind:e.kind,as:"row",...e.lens==="columns"?{group:e.column}:{}};return{...d,where:[...d.where??[],...a]}}let l=e.lens==="calendar"?M(t):void 0;if(l)return{...R(e),range:l}}function Ne(e){return e.kinds.map(n=>{let r=n.fields.map(i=>`${i.name} (${i.type??"value"}${i.options?`: ${i.options.join(" | ")}`:""})`).join(", "),t=n.edges.map(i=>`${i.name} \u2192 ${i.to.join(" | ")}`).join(", "),o=Object.entries(n.roles).map(([i,s])=>`${i}=${s}`).join(", ");return`- ${n.kind} ("${n.plural}"): ${r}${t?`; relations: ${t}`:""}${o?`; roles: ${o}`:""}`}).join(`
1
+ import{a as k}from"./chunk.G4JJXA63.js";import{a as Q}from"./chunk.Z5AB2DBF.js";import{a as Y}from"./chunk.HPAGOEZG.js";import{a as X}from"./chunk.I7XSDXQ3.js";import{c as _}from"./chunk.ZHLQWMV5.js";import{ad as G,cd as H,dd as P,ed as J,jb as q,kb as z}from"./chunk.V5MYKNL7.js";var O=e=>"failed"in e;function ue(e,n){let r=e.schema.kinds,t=e.policy?.sees;if(!t?.length||z(n))return{kinds:r};let o=q(n).roles??[],i=new Set(t.filter(s=>s.roles==="*"||o.some(a=>s.roles.includes(a))).flatMap(s=>s.kinds));return{kinds:r.filter(s=>i.has(s))}}function L(e,n){if(!n)return e;let r=new Set(n.kinds.filter(i=>e.tryDefinition(i)!==void 0));if(r.size===e.kinds.length)return e;let t=new Map,o=i=>{if(r.has(i)){if(!t.has(i)){let s=e.tryDefinition(i),a=Object.fromEntries(Object.entries(s?.edges??{}).flatMap(([l,d])=>{if(d.to==="*")return[[l,d]];let c=d.to.filter(u=>r.has(u));return c.length>0?[[l,{...d,to:c}]]:[]}));t.set(i,{...s,edges:a})}return t.get(i)}};return{...e,definitions:e.definitions.filter(i=>r.has(i.kind)),kinds:e.kinds.filter(i=>r.has(i)),tryDefinition:o,definition:i=>{let s=o(i);if(!s)throw new Error(`Unknown node kind "${i}"`);return s}}}var fe=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),y=e=>fe(e).replace(/[-_]+/g," ").trim();function I(e){let n=[];for(let t of e.kinds){let o=e.tryDefinition(t);if(!o)continue;let i=o.display?.labels??{},s=Object.entries(o.fields?.shape??{}).filter(([d])=>d!=="id"&&d!=="kind").map(([d,c])=>{let u=X(c);return{name:d,type:u?.type,...u?.options?{options:u.options}:{},words:(i[d]??y(d)).toLowerCase()}}),a=Object.entries(o.edges??{}).map(([d,c])=>({name:d,from:t,to:c.to==="*"?e.kinds.filter(u=>u!==t):c.to,words:y(d)})),l=(o.plural??`${y(t)}s`).toLowerCase();n.push({kind:t,plural:l,noun:(o.noun??y(t)).toLowerCase(),fields:s,roles:o.fieldRoles??{},edges:a})}let r=new Map(n.map(t=>[t.kind,t]));return{schema:e,kinds:n,info:t=>r.get(t)}}var $=(e,n)=>n===void 0?void 0:e.fields.find(r=>r.name===n),A=e=>e?.type==="date"||e?.type==="datetime",N=e=>e?.type==="number"||e?.type==="integer"||e?.type==="duration",re=e=>` ${e.toLowerCase().replace(/[“”"’‘]/g,"'").replace(/[^\p{L}\p{N}' -]+/gu," ").replace(/\s+/g," ").trim()} `,E=(e,n)=>e.includes(` ${n} `),x=e=>e.endsWith("ies")?`${e.slice(0,-3)}y`:e.endsWith("ses")?e.slice(0,-2):e.endsWith("s")?e.slice(0,-1):e;function pe(e,n){let r=[];for(let t of n.kinds){let o=new Set([t.plural,t.noun,`${t.noun}s`,y(t.kind),`${y(t.kind)}s`]),i=-1;for(let s of o){let a=e.indexOf(` ${s} `);a>=0&&(i<0||a<i)&&(i=a)}i>=0&&r.push({info:t,at:i})}return r.sort((t,o)=>t.at-o.at).map(t=>t.info)}function v(e,n,r){let t=n.trim().toLowerCase();if(t.length===0)return;let o=e.fields.filter(i=>!r||r(i));return o.find(i=>i.words===t||y(i.name)===t||i.name.toLowerCase()===t)??o.find(i=>i.words===x(t)||y(i.name)===x(t))??o.find(i=>t.split(" ").some(s=>s.length>2&&(i.words.split(" ").includes(s)||i.words.split(" ").includes(x(s)))))}function oe(e,n,r){let t=n.trim().toLowerCase();if(t.length!==0)return e.edges.find(o=>o.words===t||o.name.toLowerCase()===t)??e.edges.find(o=>o.to.some(i=>{let s=r.info(i);return s!==void 0&&(s.noun===x(t)||s.plural===t||y(i)===x(t))}))??e.edges.find(o=>t.split(" ").some(i=>i.length>2&&o.words.split(" ").includes(i)))}function U(e){return/ (?:grouped |group |split |sorted |organi[sz]ed )?by ([\p{L}\p{N}' -]+?)(?= (?:and|with|for|in|on|only|where|from|this|that|as|sorted|grouped) |\s*$)/u.exec(e)?.[1]?.trim()}var me=/\bwho\b.*\b(covers?|cover|tends?|owns?|handles?|does|works? on|looks? after|is on|is assigned|staffs?|runs?)\b|\bcoverage\b|\bmatrix\b|\bwho covers\b/,ge=/\bcalendar\b|\bmonth\b|\bagenda\b|\bschedule\b|\bdue\b|\bdeadlines?\b|\bdates?\b|\bwhen\b/,ye=/\btimeline\b|\bover time\b|\bgantt\b|\bspans?\b|\bweek\b/,he=/\bboard\b|\bkanban\b|\bcolumns?\b|\bpipeline\b|\bstages?\b|\bstatus\b/,be=/\blaid out\b|\blayout\b|\bseating\b|\bwhere (?:they|it|each) (?:sits?|lies?|stands?)\b|\bfloor\b/,we=/\bplan\b|\bmap\b|\bregions?\b/,ke=/\blist\b|\btable\b|\bgroup(?:ed)? by\b|\bsort(?:ed)? by\b|\bonly\b|\bjust the\b/;function $e(e){let n=[];return/\blist\b|\btable\b/.test(e)&&n.push("blocks"),me.test(e)&&n.push("coverage"),be.test(e)&&n.push("board"),(/\bfloor plan\b/.test(e)||we.test(e))&&n.push("plan"),ye.test(e)&&n.push("timeline"),ge.test(e)&&n.push("calendar"),he.test(e)&&n.push("columns"),ke.test(e)&&!n.includes("blocks")&&n.push("blocks"),n.length===0&&U(e)&&n.push("columns"),n}var se=e=>{let n=r=>r?` and not ${r}`:"";if(/\boverdue\b|\blate\b|\bpast due\b/.test(e))return{cond:(r,t)=>`days(today(), ${r}) < 0${n(t)}`,says:r=>`overdue by ${r.words}`};if(/\btoday\b/.test(e))return{range:"day",cond:r=>`days(today(), ${r}) == 0`,says:r=>`with ${r.words} today`};if(/\bthis week\b|\bnext 7 days\b|\bnext week\b/.test(e))return{range:"week",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 6`,says:r=>`with ${r.words} in the next week`};if(/\bthis month\b|\bnext 30 days\b|\bnext month\b/.test(e))return{range:"month",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 30`,says:r=>`with ${r.words} in the next month`};if(/\blast month\b|\bpast month\b/.test(e))return{range:"month",cond:r=>`days(today(), ${r}) >= -30 and days(today(), ${r}) <= 0`,says:r=>`with ${r.words} in the last month`};if(/\bthis year\b/.test(e))return{range:"year",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 365`,says:r=>`with ${r.words} in the next year`};if(/\bquarter\b/.test(e))return{range:"quarter",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 91`,says:r=>`with ${r.words} in the next quarter`}},M=e=>{if(/\bagenda\b|\bin order\b/.test(e))return"agenda";if(/\btoday\b|\bday\b/.test(e))return"day";if(/\bweek\b/.test(e))return"week";if(/\bquarter\b/.test(e))return"quarter";if(/\byears\b/.test(e))return"years";if(/\byear\b/.test(e))return"year";if(/\bmonth\b/.test(e))return"month"},Z=/^(user|person|people|member|staff|gardener|volunteer|owner|agent|employee|worker|team|player|customer|client|contact|party|attendee|guest)s?$/,j=class extends Error{},h=e=>{throw new j(e)};function Se(e,n){let r=e.fields.filter(i=>i.type==="enum");if(n){let i=v(e,n);if(i&&i.type==="enum")return i;i&&h(`${e.plural}' ${i.words} is not a choice, so it has no columns`)}let t=$(e,e.roles.status??e.roles.column);if(t?.type==="enum")return t;let o=r.find(i=>/^(status|stage|state|phase)$/.test(i.name));return o||(r[0]?r[0]:h(`${e.plural} have no choice field to put in columns`))}function ee(e,n){let r=e.fields.filter(A),t=l=>{let d=$(e,e.roles[l]);return A(d)?d:void 0},i=r.find(l=>E(n,l.words)||E(n,y(l.name)))??t("start")??r.find(l=>/^(due|date|on|at|start|starts|begins|from|sown|when)/i.test(l.name))??r[0];if(!i)return h(`no date field on ${e.plural}`);let s=t("end")??r.find(l=>l!==i&&/^(end|ends|until|to|finish|finished|harvested|due|closes|through)/i.test(l.name)),a=e.fields.find(l=>l.type==="boolean"&&/^(done|finished|complete|completed|closed)$/.test(l.name));return{start:i,...s&&s!==i?{end:s}:{},...a?{done:a}:{}}}function ie(e){let n=$(e,e.roles.start),r=$(e,e.roles.end),t=$(e,e.roles.column??e.roles.day??e.roles.columns);if(N(n)&&N(r)&&t?.type==="enum")return{start:n,end:r,column:t}}function De(e,n,r,t){let o=[];for(let s of e.kinds)for(let a of s.edges)for(let l of a.to){let d=e.info(l);if(!d||d.kind===s.kind)continue;let c=0;n.includes(s)&&(c+=4),n.includes(d)&&(c+=4),(Z.test(d.kind)||Z.test(d.noun))&&(c+=3),t&&(a.words.includes(t)||d.noun===x(t))&&(c+=5),a.words.split(" ").some(u=>u.length>2&&r.includes(` ${u}`))&&(c+=2),o.push({rows:s,across:d,link:a,score:c})}let i=o.sort((s,a)=>a.score-s.score)[0];return i||h(n[0]?`${n[0].plural} are joined to nothing else, so there is no who-covers-what to draw`:"nothing here is joined to anything else, so there is no who-covers-what to draw")}function ae(e,n,r,t,o){let i=U(t);switch(e){case"columns":{if(i){let s=v(n,i);if(!s||s.type!=="enum"){let a=oe(n,i,r);if(a){let l=r.info(a.to[0]);return{lens:"coverage",kind:n.kind,across:l.kind,link:a.name}}}}return{lens:"columns",kind:n.kind,column:Se(n,i).name}}case"calendar":{let s=ee(n,t),a=M(t);return{lens:"calendar",kind:n.kind,start:s.start.name,...s.end?{end:s.end.name}:{},...s.done?{done:s.done.name}:{},...a?{range:a}:{}}}case"timeline":{let s=ie(n);if(s&&!/\bdates?\b|\bdue\b|\bdeadlines?\b|\bmonths?\b|\byears?\b/.test(t))return{lens:"timeline",kind:n.kind,start:s.start.name,end:s.end.name,column:s.column.name};let a=ee(n,t);return{lens:"calendar",kind:n.kind,start:a.start.name,...a.end?{end:a.end.name}:{},...a.done?{done:a.done.name}:{},range:M(t)??"quarter"}}case"coverage":{let s=De(r,o,t,i);return{lens:"coverage",kind:s.rows.kind,across:s.across.kind,link:s.link.name}}case"board":{let s=$(n,n.roles.x)??n.fields.find(c=>c.name==="x"),a=$(n,n.roles.y)??n.fields.find(c=>c.name==="y");if(!N(s)||!N(a))return h(`${n.plural} have no x and y to be laid out by`);let d=r.kinds.flatMap(c=>c.edges.filter(u=>u.to.includes(n.kind)&&c.kind!==n.kind))[0]??n.edges[0];return d?{lens:"board",kind:n.kind,x:s.name,y:a.name,fill:d.name,...d.from!==n.kind?{fillFrom:"occupant"}:{}}:h(`nothing is joined to ${n.plural} to fill them`)}case"plan":{let s=$(n,n.roles.outline)??n.fields.find(a=>a.name==="outline");return s?{lens:"plan",kind:n.kind,outline:s.name}:h(`${n.plural} have no outline to draw a plan from`)}case"blocks":{let s={lens:"blocks",kind:n.kind,as:/\bcards?\b/.test(t)?"card":"row"},a=/ group(?:ed)? by ([\p{L}\p{N} -]+?)(?= (?:and|only|sorted|with)|\s*$)/u.exec(t)?.[1]??(i&&!/ sort(?:ed)? by /.test(t)?i:void 0);if(a){let c=v(n,a);if(!c||c.type!=="enum")return h(c?`${n.plural}' ${c.words} is not a choice, so they cannot be grouped by it`:`${n.plural} have nothing called ${a} to group by`);s.group=c.name}let l=/ sort(?:ed)? by ([\p{L}\p{N} -]+?)(?= (?:and|only|grouped|with)|\s*$)/u.exec(t)?.[1];if(l){let c=v(n,l);if(!c)return h(`${n.plural} have nothing called ${l} to sort by`);s.sort={by:c.name,.../\b(newest|latest|desc|descending|most)\b/.test(t)?{direction:"desc"}:{}}}let d=V(n,t);return d.length>0&&(s.where=d),s}}}function V(e,n){let r=[],t=se(n);if(t){let o=e.fields.filter(A),i=$(e,e.roles.start),s=o.find(l=>E(n,l.words))??(A(i)?i:void 0)??o[0];(!s||!A(s))&&h(`no date field on ${e.plural}`);let a=e.fields.find(l=>l.type==="boolean"&&/^(done|finished|complete|completed|closed)$/.test(l.name));r.push({expr:t.cond(s.name,/\boverdue\b|\blate\b|\bpast due\b/.test(n)?a?.name:void 0),says:t.says(s)})}if(/\bonly\b|\bjust\b|\bthat are\b|\bwhich are\b/.test(n)){for(let o of e.fields){if(o.type!=="enum")continue;let i=o.options?.find(s=>E(n,s.toLowerCase())||E(n,y(s)));i&&r.push({expr:`${o.name} == '${i.replace(/'/g,"")}'`,says:`that are ${y(i)}`})}if(/\bnot done\b|\bundone\b|\bunfinished\b|\bopen ones\b|\bstill to do\b/.test(n)){let o=e.fields.find(i=>i.type==="boolean"&&/^(done|finished|complete|completed)$/.test(i.name));o&&r.push({expr:`not ${o.name}`,says:`not ${o.words}`})}}return r}var B={columns:"A board",calendar:"A calendar",timeline:"A timeline",coverage:"A grid",board:"A layout",plan:"A plan",blocks:"A list",reach:"A picture"};function Re(e,n){let r=n.info(e.kind),t=o=>o?$(r,o)?.words??y(o):"";switch(e.lens){case"columns":return{title:`${k(r.plural)} by ${t(e.column)}`,detail:`of ${r.plural} by ${t(e.column)}`};case"calendar":{let o=e.range??"month";if(o==="agenda")return{title:`${k(r.plural)} in date order`,detail:`of ${r.plural} in order of ${t(e.start)}`};let i=o==="years"?"year":o;return{title:`${k(r.plural)} by ${i}`,detail:`of ${r.plural} by ${t(e.start)}, a ${i} at a time`}}case"timeline":return{title:`${k(r.plural)} over the ${t(e.column)}`,detail:`of ${r.plural} from ${t(e.start)} to ${t(e.end)}, by ${t(e.column)}`};case"coverage":{let o=n.info(e.across);return{title:`${k(r.plural)} by ${o.noun}`,detail:`of which ${o.noun} covers which ${r.noun}`}}case"board":return{title:`${k(r.plural)} where they stand`,detail:`of ${r.plural} where they stand`};case"plan":return{title:`${k(r.plural)} on a plan`,detail:`of ${r.plural}`};default:{let o=[e.where?.map(i=>i.says).join(" and "),e.group?`by ${t(e.group)}`:void 0,e.sort?`in order of ${t(e.sort.by)}`:void 0].filter(i=>!!i);return{title:[k(r.plural),...o].join(" "),detail:[`of ${r.plural}`,...o].join(" ")}}}}function Ae(e,n){let r={title:n,on:e.kind};switch(e.lens){case"columns":return{name:"columns",...r,bindings:{[e.kind]:{column:e.column}}};case"calendar":return{name:"calendar",...r,bindings:{[e.kind]:{start:e.start,...e.end?{end:e.end}:{},...e.done?{done:e.done}:{}}},...e.range?{options:{range:e.range}}:{}};case"timeline":return{name:"timeline",...r,bindings:{[e.kind]:{start:e.start,end:e.end,column:e.column}}};case"coverage":return{name:"coverage",...r,bindings:{rows:{kind:e.kind},columns:{kind:e.across},link:{edge:e.link}}};case"board":return{name:"board",...r,bindings:{slots:{kind:e.kind},x:{field:e.x,on:"slots"},y:{field:e.y,on:"slots"},fill:{edge:e.fill}},...e.fillFrom?{options:{fillFrom:e.fillFrom}}:{}};case"plan":return{name:"plan",...r,bindings:{regions:{kind:e.kind},outline:{field:e.outline,on:"regions"}}};default:{let t=e.where?.length?` where ${e.where.map(i=>e.where.length>1?`(${i.expr})`:i.expr).join(" and ")}`:"",o={list:`all('${e.kind}')${t}`,as:e.as??"row"};return e.group&&(o.group=e.group),e.sort&&(o.sort=e.sort.direction?{by:e.sort.by,direction:e.sort.direction}:e.sort.by),o.empty="Nothing here yet.",{name:"blocks",...r,options:{blocks:[o]}}}}}function C(e,n){let r=o=>o.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,""),t=new Set(["home","overview",...Q(n).map(o=>o.slug),...(n.lenses??[]).flatMap(o=>o.title?[r(o.title)]:[])]);if(!t.has(r(e)))return e;for(let o=2;;o++)if(!t.has(r(`${e} ${o}`)))return`${e} ${o}`}var ne={title:[],headline:[],text:["tone"],figure:["as","currency","label"],list:["sort","limit","group","empty","as"],progress:["label"],group:["direction"],when:["show"],divider:[]};function Ee(e,n){if(!Array.isArray(n)||n.length===0)return"it has no blocks to draw";if(n.length>40)return"it has more blocks than a place draws";let r=(s,a)=>{if(typeof s!="string"||s.trim()==="")return`its ${a} says nothing`;try{return _(s)}catch(l){return`its ${a} does not read: ${l instanceof Error?l.message.replace(/ \(at character.*$/,""):String(l)}`}},t=s=>{if(s.t==="where")return t(s.set);if(s.t==="call"&&s.fn==="all"){let a=s.args[0];return a?.t==="lit"&&typeof a.value=="string"?e.info(a.value)??null:void 0}},o=(s,a)=>{switch(s.t){case"lit":return;case"ident":return a&&!a.fields.some(l=>l.name===s.name)&&!a.edges.some(l=>l.name===s.name)?`${a.plural} have nothing called ${s.name}`:void 0;case"member":return o(s.object,a);case"list":return s.items.map(l=>o(l,a)).find(Boolean);case"unary":return o(s.operand,a);case"binary":return o(s.left,a)??o(s.right,a);case"where":{let l=t(s.set);return l===null?"Nothing by that name here":o(s.set,a)??o(s.filter,l??void 0)}case"call":return s.fn==="all"?t(s)===null?"Nothing by that name here":void 0:s.args.map(l=>o(l,a)).find(Boolean)}},i=(s,a)=>{if(a>4)return"its blocks nest deeper than a place draws";for(let l of s){if(!w(l))return"a block is not an object";let d=Object.keys(ne).find(p=>p in l);if(!d)return`"${Object.keys(l)[0]??""}" is not a block a place draws`;let c=Object.keys(l).find(p=>p!==d&&p!=="key"&&!ne[d].includes(p));if(c)return`a ${d} block takes no "${c}"`;let u=l[d];if(d==="list"||d==="figure"||d==="when"){if(d==="figure"&&u===!0)continue;let p=r(u,d);if(typeof p=="string")return p;let g=o(p,void 0);if(g)return g;if(d==="list"){let f=t(p);if(f==null)return f===null?"Nothing by that name here":"its list does not say which records it lists, like all('task')";for(let m of["group","sort"]){let b=l[m],S=typeof b=="string"?b:w(b)&&typeof b.by=="string"?b.by:void 0;if(b===void 0)continue;let D=S?f.fields.find(ce=>ce.name===S):void 0;if(!D)return`${f.plural} have nothing called ${String(S??b)} to ${m} by`;if(m==="group"&&D.type!=="enum")return`${f.plural}' ${D.words} is not a choice, so they cannot be grouped by it`}}if(d==="when"){let f=l.show;if(!Array.isArray(f))return"a when block shows a list of blocks";let m=i(f,a+1);if(m)return m}}else if(d==="group"){if(!Array.isArray(u))return"a group block holds a list of blocks";let p=i(u,a+1);if(p)return p}else{if(d!=="divider"&&typeof u!="string")return`a ${d} block says words`;if(typeof u=="string")for(let p of u.matchAll(/\{([^{}]*)\}/g)){let g=p[1].split(/\|(?![|])/)[0],f=r(g,`${d}'s braces`);if(typeof f=="string")return f;let m=o(f,void 0);if(m)return m}}}};return i(n,1)}function T(e,n,r){let t=L(e.schema,r),o=f=>({ok:!1,failed:`Couldn't draw that: ${f.replace(/\.$/,"")}.`});if(!P(n.name)||n.name==="reach")return o(`"${String(n.name)}" is not a picture the seat can draw; it draws ${H.filter(f=>f!=="reach").join(", ")}`);if(typeof n.title!="string"||n.title.trim().length===0||n.title.length>80)return o("it needs a title of a few words");if(typeof n.on!="string"||!t.tryDefinition(n.on))return o("Nothing by that name here");let i=G[n.name],s=n.bindings??{};if(i.binds==="fields")for(let[f,m]of Object.entries(s)){if(!t.tryDefinition(f))return o("Nothing by that name here");let b=Object.keys(t.tryDefinition(f).fields?.shape??{});for(let[S,D]of Object.entries(m??{}))if(typeof D!="string"||!b.includes(D))return o(`${y(f)} has no field "${String(D)}" for its ${S}`);for(let S of i.requiredRoles)if(!(S in(m??{})))return o(`a ${n.name} needs ${y(f)}'s ${S}`)}else if(i.binds==="entities")for(let f of i.requiredRoles){let m=s[f];if(!m)return o(`a ${n.name} needs its ${f}`);if(typeof m.kind=="string"&&!t.tryDefinition(m.kind))return o("Nothing by that name here")}let a={...e,schema:t,lenses:[...e.lenses??[],n]},l=a.lenses.length-1,d=J(a),c=`lenses.${l}`,u=d.findings.find(f=>f.path===c||f.path.startsWith(`${c}.`));if(u)return o(u.message.replace(/^"[^"]*" /,"it "));let p=d.undrawn.find(f=>f.index===l);if(p)return o(p.why);let g=d.drawn.find(f=>f.index===l);if(!g)return o("its bindings name something the app does not have");if(g.as==="overview")return o(`"${n.title}" is the scene's own address; give it another title`);if(n.name==="blocks"){let f=Ee(I(t),n.options?.blocks);if(f)return o(f)}return{ok:!0,drawn:g}}function K(e){return{op:"add-lens",title:e.title,lens:e.name,on:e.on,...e.bindings?{bindings:e.bindings}:{},...e.options?{options:e.options}:{}}}function xe(e){return{op:"remove-lens",title:e.title,on:e.on}}var w=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function de(e){let n=w(e)?e:{},r=String(n.lens??n.name??""),t=n.bindings,o=typeof n.on=="string"?n.on:w(t)&&G[r]?.binds==="fields"?Object.keys(t)[0]??"":"";return{name:r,title:typeof n.title=="string"?n.title.trim():"",on:o,...w(t)?{bindings:t}:{},...w(n.options)?{options:n.options}:{}}}function ve(e){let n=o=>w(e.bindings?.[o])?e.bindings[o]:{},r=o=>typeof o=="string"?o:void 0,t=n(e.on);switch(e.name){case"columns":return r(t.column)?{lens:"columns",kind:e.on,column:t.column}:void 0;case"calendar":{let o=r(e.options?.range);return r(t.start)?{lens:"calendar",kind:e.on,start:t.start,...r(t.end)?{end:t.end}:{},...r(t.done)?{done:t.done}:{},...o?{range:o}:{}}:void 0}case"timeline":return r(t.start)&&r(t.end)&&r(t.column)?{lens:"timeline",kind:e.on,start:t.start,end:t.end,column:t.column}:void 0;case"coverage":{let o=w(e.bindings?.columns)?r(e.bindings.columns.kind):void 0,i=w(e.bindings?.link)?r(e.bindings.link.edge):void 0;return o&&i?{lens:"coverage",kind:e.on,across:o,link:i}:void 0}case"blocks":{let o=e.options?.blocks;if(!Array.isArray(o)||o.length!==1||!w(o[0]))return;let i=o[0],s=new RegExp(`^all\\('${e.on}'\\)(?: where (.+))?$`).exec(String(i.list??""));if(!s)return;let a=i.sort;return{lens:"blocks",kind:e.on,as:i.as==="card"?"card":"row",...typeof i.group=="string"?{group:i.group}:{},...typeof a=="string"?{sort:{by:a}}:w(a)&&typeof a.by=="string"?{sort:{by:a.by,...a.direction==="desc"?{direction:"desc"}:{}}}:{},...s[1]?{where:[{expr:s[1],says:"as asked"}]}:{}}}default:return}}function W(e,n,r,t,o){let i=I(L(e.schema,t)).info(n.on),s=ve(n);return{title:n.title,said:`${B[n.name]??"A picture"} of ${i?.plural??y(n.on)}.`,kind:n.on,lens:n,drawn:r,edit:K(n),by:o,asks:[],...s?{recipe:s}:{}}}function te(e){return{title:e.title,said:e.said,lens:{title:e.lens.title,lens:e.lens.name,on:e.lens.on,...e.lens.bindings?{bindings:e.lens.bindings}:{},...e.lens.options?{options:e.lens.options}:{}},edit:e.edit,by:e.by,check:"It draws, and graview check would take it."}}function F(e,n,r,t,o){let i=Re(e,n),s=e.title??o??C(i.title,r.app),a=Ae(e,s),l=T(r.app,a,r.sight);return l.ok?{title:s,said:`${B[e.lens]} ${i.detail}.`,kind:e.kind,lens:a,drawn:l.drawn,edit:K(a),by:"template",asks:t,recipe:e}:{failed:l.failed,...r.lastGood?{lastGood:r.lastGood}:{}}}function Ye(e,n){let r=I(L(n.app.schema,n.sight)),t=r.info(e.kind);if(!t)return{failed:"Couldn't draw that: Nothing by that name here."};let o=e.lens==="blocks"&&!e.group&&!e.sort&&!e.where?.length&&e.title===void 0;return F(o?{...e,title:C(`Every ${t.noun}`,n.app)}:e,r,n,[])}function Le(e,n,r,t){if(r.length>0)return r;let o=s=>{switch(e){case"columns":return s.fields.some(a=>a.type==="enum");case"calendar":return s.fields.some(A);case"timeline":return ie(s)!==void 0||s.fields.some(A);case"coverage":return s.edges.some(a=>a.to.some(l=>l!==s.kind));case"board":return s.fields.some(a=>a.name==="x")&&s.fields.some(a=>a.name==="y");case"plan":return s.fields.some(a=>a.name==="outline")||s.roles.outline!==void 0;default:return!0}};return[...n.kinds.filter(o)].sort((s,a)=>Number(a.fields.some(l=>E(t,l.words)))-Number(s.fields.some(l=>E(t,l.words))))}function Ie(e,n){let r=I(L(n.app.schema,n.sight)),t=re(e),o=$e(t);if(o.length===0)return;let i=pe(t,r),s;for(let a of o){let l=a==="coverage"?[i[0]??r.kinds[0]].filter(d=>!!d):Le(a,r,i,t);for(let d of l)try{let c=ae(a,d,r,t,i),u=F(c,r,n,[e]);if(!O(u))return u;s??=u.failed}catch(c){if(!(c instanceof j))throw c;s??=`Couldn't draw that: ${c.message}.`}l.length===0&&i.length===0&&(s??=`Couldn't draw that: nothing here has what ${B[a].toLowerCase()} needs.`)}return{failed:s??"Couldn't draw that: Nothing by that name here.",...n.lastGood?{lastGood:n.lastGood}:{}}}async function Oe(e,n){let r=n.lastGood?{lastGood:n.lastGood}:{};if(e.trim().length===0)return{failed:"Say what you would like to see, like \u201Ca board of tasks by status\u201D.",...r};let t=Ie(e,n);if(t&&!O(t))return t;if(!n.complete)return t??{failed:"Couldn't draw that: drawing freely needs AI, which isn't on here. Ask for a board, a calendar, a timeline, a list or who covers what.",...r};let o=await le(e,n,void 0);return O(o)&&t?t:o}async function je(e,n,r){let t={lastGood:e},o={...r,lastGood:e},i=I(L(r.app.schema,r.sight)),s=re(n),a=i.info(e.kind),l=[...e.asks,n];if(!a)return{failed:"Couldn't change that: Nothing by that name here.",...t};let d=e.recipe,c=/^ (?:call|name|title) (?:it|this)? ?(.+?) $/.exec(s)??/ (?:call|name) it (.+?) $/.exec(s);try{if(c){let g=n.replace(/^.*?\b(?:call|name|title)\b\s*(?:it|this)?\s*/i,"").replace(/^["“']|["”']$/g,"").trim();if(g.length===0)return{failed:"Couldn't change that: say what to call it.",...t};let f={...e.lens,title:C(g,r.app)},m=T(r.app,f,r.sight);return m.ok?{...e,title:f.title,lens:f,drawn:m.drawn,edit:K(f),asks:l,...d?{recipe:{...d,title:f.title}}:{}}:{failed:m.failed,...t}}let p=/ as (?:a |an )?(board|kanban|calendar|timeline|list|table|cards|rows|grid|plan|layout)\b/.exec(s);if(p){let g=p[1]==="board"||p[1]==="kanban"?"columns":p[1]==="calendar"?"calendar":p[1]==="timeline"?"timeline":p[1]==="grid"?"coverage":p[1]==="plan"?"plan":p[1]==="layout"?"board":"blocks",f=ae(g,a,i,s,[a]),m=p[1]==="cards"?"card":p[1]==="rows"?"row":void 0,b=g==="blocks"&&d?.lens==="blocks"?{...d,...m?{as:m}:{}}:g==="blocks"&&d?.lens==="columns"?{...f,group:d.column,...m?{as:m}:{}}:f;return F(R(b),i,o,l)}if(d){let g=Te(d,a,i,s);if(g)return F(g,i,o,l)}}catch(p){if(!(p instanceof j))throw p;return{failed:`Couldn't change that: ${p.message}.`,...t}}if(!r.complete)return{failed:"Couldn't change that: changing it freely needs AI, which isn't on here. Try \u201Cgroup by status\u201D, \u201Conly this month\u201D or \u201Cas a calendar\u201D.",...t};let u=await le(n,o,e);return O(u)?u:{...u,asks:l}}var R=e=>{let{title:n,...r}=e;return r};function Te(e,n,r,t){let o=/ (?:group(?:ed)?|split|organi[sz]ed?|put them|columns) by ([\p{L}\p{N} -]+?)(?= (?:and|only|with)|\s*$)/u.exec(t)?.[1]??(/^ by /.test(t)?U(t):void 0);if(o){let d=v(n,o);if(d?.type==="enum")return e.lens==="blocks"?{...R(e),group:d.name}:{lens:"columns",kind:e.kind,column:d.name};let c=oe(n,o,r);return c?{lens:"coverage",kind:e.kind,across:c.to[0],link:c.name}:h(d?`${n.plural}' ${d.words} is not a choice, so they cannot be grouped by it`:`${n.plural} have nothing called ${o} to group by`)}let i=/ (?:sort(?:ed)?|order(?:ed)?) by ([\p{L}\p{N} -]+?)(?= (?:and|only|with)|\s*$)/u.exec(t)?.[1];if(i){let d=v(n,i);return d?{...e.lens==="blocks"?R(e):{lens:"blocks",kind:e.kind,as:"row",...e.lens==="columns"?{group:e.column}:{}},sort:{by:d.name,.../\b(newest|latest|desc|descending|most)\b/.test(t)?{direction:"desc"}:{}}}:h(`${n.plural} have nothing called ${i} to sort by`)}if(/\b(?:all of them|everything|show all|clear the filter|no filter|without the filter)\b/.test(t)){if(e.lens!=="blocks"||!e.where)return h("it already shows all of them");let{where:d,...c}=R(e);return c}let s=se(t);if(s&&e.lens==="calendar"&&s.range)return{...R(e),range:s.range};if(s&&e.lens==="calendar"&&!s.range)return{lens:"blocks",kind:e.kind,as:"row",sort:{by:e.start},where:V(n,t)};let a=V(n,t);if(a.length>0){let d=e.lens==="blocks"?R(e):{lens:"blocks",kind:e.kind,as:"row",...e.lens==="columns"?{group:e.column}:{}};return{...d,where:[...d.where??[],...a]}}let l=e.lens==="calendar"?M(t):void 0;if(l)return{...R(e),range:l}}function Ne(e){return e.kinds.map(n=>{let r=n.fields.map(i=>`${i.name} (${i.type??"value"}${i.options?`: ${i.options.join(" | ")}`:""})`).join(", "),t=n.edges.map(i=>`${i.name} \u2192 ${i.to.join(" | ")}`).join(", "),o=Object.entries(n.roles).map(([i,s])=>`${i}=${s}`).join(", ");return`- ${n.kind} ("${n.plural}"): ${r}${t?`; relations: ${t}`:""}${o?`; roles: ${o}`:""}`}).join(`
2
2
  `)}var Fe=['columns \u2014 a board, records in columns by one choice field: {"lens": "columns", "on": K, "bindings": {K: {"column": "<enum field>"}}}','calendar \u2014 records on a calendar by a date: {"lens": "calendar", "on": K, "bindings": {K: {"start": "<date field>", "end"?: "<date field>", "done"?: "<boolean field>"}}, "options": {"range"?: "day" | "week" | "month" | "quarter" | "year" | "agenda"}}','timeline \u2014 minutes of a day in columns: {"lens": "timeline", "on": K, "bindings": {K: {"start": "<number field>", "end": "<number field>", "column": "<enum field>"}}}','coverage \u2014 who covers what, a grid of two kinds joined by a relation: {"lens": "coverage", "on": K, "bindings": {"rows": {"kind": K}, "columns": {"kind": J}, "link": {"edge": "<relation of K to J>"}}}',`blocks \u2014 anything else, as blocks: {"lens": "blocks", "on": K, "options": {"blocks": [{"headline": "words"}, {"list": "all('K') where <condition>", "group"?: "<enum field>", "sort"?: "<field>" | {"by": "<field>", "direction": "desc"}, "as"?: "row" | "card", "empty"?: "words"}, {"figure": "count(all('K'))", "label": "words"}]}}. Conditions read a record's own fields: status == 'open', not done, days(today(), due) <= 7.`].join(`
3
3
  `);function Ce(e,n,r){return["You draw a view of an app's data as JSON \u2014 never code. The app's kinds, their fields (with types) and relations:",Ne(n),"","The lenses you may use (prefer the first four; use blocks only when none of them fits):",Fe,"",r?`The view on screen now:
4
4
  ${JSON.stringify(r.lens)}