graview 0.1.28 → 0.1.29

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 (167) hide show
  1. package/dist/preview/chunk.2643W7FT.js +1 -0
  2. package/dist/preview/chunk.2CLPRG3I.js +1 -0
  3. package/dist/preview/chunk.2IZFIORK.js +1 -0
  4. package/dist/preview/chunk.2NCTM5K2.js +2 -0
  5. package/dist/preview/{chunk.EYF6ONTA.js → chunk.3G5MQFZK.js} +1 -1
  6. package/dist/preview/chunk.3JM2TNDD.js +2 -0
  7. package/dist/preview/chunk.44FVJOK4.js +28 -0
  8. package/dist/preview/chunk.4GGAPOMK.js +2 -0
  9. package/dist/preview/chunk.5AT4O4BN.js +1 -0
  10. package/dist/preview/chunk.5JXUAMKI.js +1 -0
  11. package/dist/preview/chunk.5R66YTET.js +2 -0
  12. package/dist/preview/chunk.64P76WK4.js +1 -0
  13. package/dist/preview/chunk.7D77HEIJ.js +1 -0
  14. package/dist/preview/chunk.7DNFXJH3.js +1 -0
  15. package/dist/preview/{chunk.SBHVVJY7.js → chunk.7PRFYYVM.js} +1 -1
  16. package/dist/preview/chunk.AE5GKL4C.js +1 -0
  17. package/dist/preview/chunk.ARR75WBP.js +35 -0
  18. package/dist/preview/chunk.AVUS5LMG.js +3 -0
  19. package/dist/preview/chunk.BKPGDEES.js +1 -0
  20. package/dist/preview/chunk.BZ5OJYHU.js +1 -0
  21. package/dist/preview/chunk.CK7QWLMX.js +1 -0
  22. package/dist/preview/chunk.COTG2IG5.js +1 -0
  23. package/dist/preview/chunk.D4GOVA25.js +1 -0
  24. package/dist/preview/chunk.DAA6XWLF.js +1 -0
  25. package/dist/preview/chunk.DKTCRFMS.js +1 -0
  26. package/dist/preview/chunk.DLGTFXGM.js +1 -0
  27. package/dist/preview/chunk.DN7SN6ZR.js +1 -0
  28. package/dist/preview/chunk.G4WQGTZR.js +3 -0
  29. package/dist/preview/chunk.GDA3G4U2.js +6 -0
  30. package/dist/preview/chunk.GS4T26WW.js +328 -0
  31. package/dist/preview/chunk.GZH6PTXN.js +1 -0
  32. package/dist/preview/chunk.HFKMHLJ3.js +1 -0
  33. package/dist/preview/chunk.HGAMNIST.js +1 -0
  34. package/dist/preview/chunk.HJCQ6I3S.js +1 -0
  35. package/dist/preview/chunk.HKBKH7EK.js +1 -0
  36. package/dist/preview/chunk.HLLWKSZB.js +5 -0
  37. package/dist/preview/chunk.HONUT6OG.js +1 -0
  38. package/dist/preview/chunk.HRWLR7T4.js +1 -0
  39. package/dist/preview/chunk.HV6I74DF.js +1 -0
  40. package/dist/preview/chunk.IPBXAAQV.js +17 -0
  41. package/dist/preview/chunk.IWYUFYDJ.js +1 -0
  42. package/dist/preview/chunk.IZW7DBK4.js +1 -0
  43. package/dist/preview/chunk.J46KDTEZ.js +10 -0
  44. package/dist/preview/chunk.JNGUSAWX.js +70 -0
  45. package/dist/preview/chunk.JU2ZVKMT.js +2 -0
  46. package/dist/preview/chunk.K4ZUVH2G.js +1 -0
  47. package/dist/preview/chunk.KC6UZHBM.js +1 -0
  48. package/dist/preview/chunk.KLITC55P.js +1 -0
  49. package/dist/preview/chunk.KZ2376BD.js +19 -0
  50. package/dist/preview/chunk.LYJAVUST.js +1 -0
  51. package/dist/preview/chunk.MB7LKKUD.js +1 -0
  52. package/dist/preview/chunk.MOUGB4H6.js +1 -0
  53. package/dist/preview/chunk.MYFWM572.js +1 -0
  54. package/dist/preview/chunk.N4FBDA2W.js +1 -0
  55. package/dist/preview/chunk.O42YET3W.js +1 -0
  56. package/dist/preview/chunk.O4QPITBD.js +9 -0
  57. package/dist/preview/{chunk.5BGA2VUS.js → chunk.OGXE2RHC.js} +4 -4
  58. package/dist/preview/chunk.OHE5AMHH.js +0 -0
  59. package/dist/preview/chunk.ONGVH3ZM.js +1076 -0
  60. package/dist/preview/chunk.OQDETV4X.js +1 -0
  61. package/dist/preview/chunk.OWBEV6FR.js +1 -0
  62. package/dist/preview/chunk.OWE6OJ4P.js +1 -0
  63. package/dist/preview/chunk.OYJSFO3A.js +1 -0
  64. package/dist/preview/chunk.P62SKNJS.js +27 -0
  65. package/dist/preview/chunk.PA5HYAEO.js +1 -0
  66. package/dist/preview/{chunk.IDI2BQ7Y.js → chunk.PMEDLEZY.js} +2 -2
  67. package/dist/preview/chunk.PTXQHHKF.js +1 -0
  68. package/dist/preview/chunk.Q5WEOX3Q.js +1 -0
  69. package/dist/preview/chunk.QNHECGMH.js +1 -0
  70. package/dist/preview/chunk.QSDT2RLY.js +1 -0
  71. package/dist/preview/chunk.R2D373VG.js +1 -0
  72. package/dist/preview/chunk.RB4RTBRZ.js +1 -0
  73. package/dist/preview/chunk.RCLJ4H52.js +116 -0
  74. package/dist/preview/chunk.RKRSRKF3.js +1 -0
  75. package/dist/preview/chunk.RWGLKDWH.js +1 -0
  76. package/dist/preview/chunk.SIL4KD3K.js +1 -0
  77. package/dist/preview/chunk.SS76EIMI.js +1 -0
  78. package/dist/preview/{chunk.IKT7JQUW.js → chunk.T4LY5QXO.js} +1 -1
  79. package/dist/preview/chunk.UIIVEQAT.js +1 -0
  80. package/dist/preview/chunk.UT6642FC.js +1 -0
  81. package/dist/preview/chunk.UTHHX2TJ.js +1 -0
  82. package/dist/preview/chunk.UWNYT7PF.js +1 -0
  83. package/dist/preview/chunk.V6TK4LHW.js +6 -0
  84. package/dist/preview/chunk.VNBO2RXD.js +1 -0
  85. package/dist/preview/chunk.VPPUTA74.js +1 -0
  86. package/dist/preview/chunk.WKXNBHTL.js +4 -0
  87. package/dist/preview/chunk.WLRTPFAC.js +1 -0
  88. package/dist/preview/chunk.X53HI436.js +1 -0
  89. package/dist/preview/chunk.XAXJHEMD.js +1 -0
  90. package/dist/preview/chunk.XDYAG276.js +1 -0
  91. package/dist/preview/chunk.XDZSTIS6.js +88 -0
  92. package/dist/preview/chunk.XXHNV24G.js +1 -0
  93. package/dist/preview/chunk.YCA7P5MK.js +1 -0
  94. package/dist/preview/chunk.YRQZZH5V.js +1 -0
  95. package/dist/preview/chunk.YUWRZWGX.js +1 -0
  96. package/dist/preview/chunk.Z2RGLFLS.js +1 -0
  97. package/dist/preview/chunk.Z56B2JR2.js +25 -0
  98. package/dist/preview/chunk.Z5V23DQN.js +3 -0
  99. package/dist/preview/chunk.ZBXOX3W3.js +1 -0
  100. package/dist/preview/chunk.ZEGSQCSD.js +1 -0
  101. package/dist/preview/chunk.ZEVVWWNA.js +44 -0
  102. package/dist/preview/chunk.ZS4DJ76C.js +1 -0
  103. package/dist/preview/chunk.ZSKP6UQS.js +3 -0
  104. package/dist/preview/page.js +6 -6
  105. package/package.json +6 -6
  106. package/dist/preview/chunk.22H4JXTH.js +0 -8
  107. package/dist/preview/chunk.25OYH6MY.js +0 -1
  108. package/dist/preview/chunk.2GBQJXJH.js +0 -19
  109. package/dist/preview/chunk.2VUG6EAN.js +0 -1
  110. package/dist/preview/chunk.337WDTG3.js +0 -2
  111. package/dist/preview/chunk.3HLLQ5CJ.js +0 -1
  112. package/dist/preview/chunk.46KUPBQC.js +0 -1
  113. package/dist/preview/chunk.4H7CQE56.js +0 -1
  114. package/dist/preview/chunk.4HGBVU5B.js +0 -1
  115. package/dist/preview/chunk.4RO5DA22.js +0 -1
  116. package/dist/preview/chunk.4TUNX4WM.js +0 -29
  117. package/dist/preview/chunk.6LJ66MB7.js +0 -1
  118. package/dist/preview/chunk.6R4EI47C.js +0 -1
  119. package/dist/preview/chunk.7S22MBNN.js +0 -1
  120. package/dist/preview/chunk.A73BXXE4.js +0 -3
  121. package/dist/preview/chunk.AHDOKM4O.js +0 -1
  122. package/dist/preview/chunk.ARE3MEDN.js +0 -1
  123. package/dist/preview/chunk.ASFZTYFO.js +0 -1
  124. package/dist/preview/chunk.BBJZ6O7J.js +0 -1
  125. package/dist/preview/chunk.BCBH6WJF.js +0 -1
  126. package/dist/preview/chunk.CAZAB352.js +0 -1
  127. package/dist/preview/chunk.CY7MDLRS.js +0 -1
  128. package/dist/preview/chunk.DAVRLRGB.js +0 -1
  129. package/dist/preview/chunk.DCIC3YHX.js +0 -1
  130. package/dist/preview/chunk.EW4JFOJY.js +0 -1
  131. package/dist/preview/chunk.FP27W5MU.js +0 -1
  132. package/dist/preview/chunk.G2OOBROL.js +0 -1040
  133. package/dist/preview/chunk.GCKSQ52O.js +0 -1
  134. package/dist/preview/chunk.GE5EAN36.js +0 -2
  135. package/dist/preview/chunk.HOPIZMJR.js +0 -2
  136. package/dist/preview/chunk.IBGO4BUF.js +0 -1
  137. package/dist/preview/chunk.IH42QTOM.js +0 -1
  138. package/dist/preview/chunk.ISRS7GOT.js +0 -321
  139. package/dist/preview/chunk.J6CBMLGR.js +0 -1
  140. package/dist/preview/chunk.JRCV6HVV.js +0 -1
  141. package/dist/preview/chunk.KWW3YHQ4.js +0 -23
  142. package/dist/preview/chunk.MKNXV4TM.js +0 -8
  143. package/dist/preview/chunk.MRK6QJV5.js +0 -25
  144. package/dist/preview/chunk.MVNIKZIC.js +0 -1
  145. package/dist/preview/chunk.N2WTNKEV.js +0 -1
  146. package/dist/preview/chunk.N7HCALRK.js +0 -61
  147. package/dist/preview/chunk.NRRUGG22.js +0 -1
  148. package/dist/preview/chunk.OGL4PHTY.js +0 -1
  149. package/dist/preview/chunk.PFQFPJ5L.js +0 -16
  150. package/dist/preview/chunk.PN2H6X7O.js +0 -1
  151. package/dist/preview/chunk.PWHJHFC4.js +0 -1
  152. package/dist/preview/chunk.Q3HVA6L4.js +0 -1
  153. package/dist/preview/chunk.RZLNDVGN.js +0 -107
  154. package/dist/preview/chunk.SNBIZ3B6.js +0 -1
  155. package/dist/preview/chunk.TBG2QBOS.js +0 -1
  156. package/dist/preview/chunk.VR735ZQL.js +0 -1
  157. package/dist/preview/chunk.VSXCXPK2.js +0 -1
  158. package/dist/preview/chunk.W3LDQ6B2.js +0 -1
  159. package/dist/preview/chunk.WCNONCTL.js +0 -6
  160. package/dist/preview/chunk.WHTNSETN.js +0 -1
  161. package/dist/preview/chunk.XG67BWH6.js +0 -1
  162. package/dist/preview/chunk.XRM6WXPW.js +0 -1
  163. package/dist/preview/chunk.Y5LPZLDE.js +0 -1
  164. package/dist/preview/chunk.YETBY2LM.js +0 -1
  165. package/dist/preview/chunk.YSYT3ASK.js +0 -1
  166. package/dist/preview/chunk.ZEUBAAVQ.js +0 -1
  167. package/dist/preview/chunk.ZJDRD6PO.js +0 -1
@@ -0,0 +1,6 @@
1
+ import{a as k}from"./chunk.G4JJXA63.js";import{a as Q}from"./chunk.YRQZZH5V.js";import{a as Y}from"./chunk.COTG2IG5.js";import{a as X}from"./chunk.DAA6XWLF.js";import{c as _}from"./chunk.2NCTM5K2.js";import{La as q,Ma as z,gc as G,hc as H,ic as P,jc as J}from"./chunk.HLLWKSZB.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()} `,x=(e,n)=>e.includes(` ${n} `),E=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===E(t)||y(i.name)===E(t))??o.find(i=>t.split(" ").some(s=>s.length>2&&(i.words.split(" ").includes(s)||i.words.split(" ").includes(E(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===E(t)||s.plural===t||y(i)===E(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=>x(n,l.words)||x(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===E(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=>x(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=>x(n,s.toLowerCase())||x(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 F(e,n){let r=o=>o.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,""),t=new Set(["home","overview",...Y(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 xe(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=xe(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 Ee(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 C(e,n,r,t,o){let i=Re(e,n),s=e.title??o??F(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 C(o?{...e,title:F(`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=>x(t,l.words)))-Number(s.fields.some(l=>x(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=C(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:F(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 C(R(b),i,o,l)}if(d){let g=Te(d,a,i,s);if(g)return C(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
+ `)}var Ce=['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
+ `);function Fe(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):",Ce,"",r?`The view on screen now:
4
+ ${JSON.stringify(r.lens)}
5
+ Change it as asked, and keep everything not asked about.`:"",`Asked: ${JSON.stringify(e)}`,'Answer with ONE JSON object: {"title": "<a few words, like Deliverables by status>", "lens": \u2026, "on": \u2026, "bindings"?: \u2026, "options"?: \u2026}. Name only the kinds, fields and relations listed above. If it cannot be drawn from them, answer {"failed": "<one sentence saying why>"}.'].filter(t=>t!=="").join(`
6
+ `)}async function le(e,n,r){let t=n.lastGood?{lastGood:n.lastGood}:{},o=I(L(n.app.schema,n.sight)),i;try{i=await n.complete(Fe(e,o,r))}catch{return{failed:"Couldn't draw that: the model did not answer.",...t}}let s=Q(i);if(typeof s!="object"||s===null||Array.isArray(s))return{failed:"Couldn't draw that: the model's answer was not a view.",...t};let a=s;if(typeof a.failed=="string")return{failed:`Couldn't draw that: ${a.failed.replace(/^Couldn't draw that:\s*/i,"").replace(/\.$/,"")}.`,...t};let l=de(a);if(!P(l.name))return{failed:`Couldn't draw that: "${l.name}" is not a picture the seat can draw.`,...t};let d=l.title?l.title.slice(0,80):r?.title??k(e.trim()).slice(0,80),c={...l,title:r&&r.title===d?d:F(d,n.app)},u=T(n.app,c,n.sight);return u.ok?{...W(n.app,c,u.drawn,n.sight,"model"),asks:[e]}:{failed:u.failed,...t}}function Qe(e,n,r){let t=[...e.lenses??[]];for(let o of n){let i={name:o.lens,title:o.title,on:o.on,...o.bindings?{bindings:o.bindings}:{},...o.options?{options:o.options}:{}};if(t.some(a=>a.title===i.title))continue;T({...e,lenses:t},i,r).ok&&(t=[...t,i])}return t.length===(e.lenses??[]).length?e:{...e,lenses:t}}async function Ze(e,n,r){let{app:t,drafts:o}=r,i=ue(t,r.principal),s=c=>{let u=de(c);return{lens:u,verdict:T(t,u,i)}};if(e==="keep_lens"){let{lens:c,verdict:u}=s(n);if(!u.ok)return{ok:!1,error:u.failed,reason:"invalid"};if(!o?.keep)return{ok:!1,error:"This app's declaration cannot be written from here."};let p=K(c),g=await o.keep(p);return g.ok?{ok:!0,data:{kept:p,said:g.said??`Adds \u201C${p.title}\u201D to the places.`,undo:Ee(p)}}:{ok:!1,error:g.error}}if(n.lens!==void 0){let{lens:c,verdict:u}=s(n.lens);return u.ok?{ok:!0,data:te(W(t,c,u.drawn,i,"model"))}:{ok:!1,error:u.failed,reason:"invalid"}}let a={app:t,sight:i,...o?.complete?{complete:o.complete}:{}},l=String(n.ask??""),d;if(n.current!==void 0){let{lens:c,verdict:u}=s(n.current);if(!u.ok)return{ok:!1,error:u.failed,reason:"invalid"};d=await je(W(t,c,u.drawn,i,"model"),l,a)}else d=await Oe(l,a);return O(d)?{ok:!1,error:d.failed,reason:"invalid"}:{ok:!0,data:te(d)}}export{O as a,ue as b,T as c,K as d,Ee as e,de as f,ve as g,W as h,te as i,Ye as j,Ie as k,Oe as l,je as m,Qe as n,Ze as o};
@@ -0,0 +1 @@
1
+ import{b as m}from"./chunk.VPPUTA74.js";import{a as W}from"./chunk.UT6642FC.js";import{c}from"./chunk.2CLPRG3I.js";import{h as x}from"./chunk.ZS4DJ76C.js";import{h as T}from"./chunk.GS4T26WW.js";import{F as z,M as C,U as f,W as b,la as L,oa as R}from"./chunk.Z56B2JR2.js";import{Ra as k,Y as A,wa as I}from"./chunk.HLLWKSZB.js";import{b as w}from"./chunk.AJZBJBMO.js";var u=w(z(),1);var e=w(C(),1);function H(n=4){let{store:i}=f(),p=b();return(0,u.useMemo)(()=>[...i.batches()].reverse().slice(0,n).map(a=>({intent:a.intent,author:a.author.kind,...a.author.id?{authorId:a.author.id}:{},by:a.author,...a.ops[0]?.via?{via:a.ops[0].via}:{},...a.lineage?{basis:W(a.lineage)}:{},touched:[...new Set(a.ops.filter(o=>!k(o)).flatMap(o=>o.writes))],batch:a.id,...a.ops.every(k)?{withheld:!0}:{}})),[i,p,n])}function O({batch:n}){let{store:i,principal:p,noteSeat:a}=f(),o=b(),[h,y]=(0,u.useState)(null),l=(0,u.useMemo)(()=>i.canUndo(n),[i,n,o]);if(!l.ok&&l.ops.length===0)return null;let s=!l.ok,g=s?l.includeBatches:[];return(0,e.jsxs)("span",{style:{marginLeft:"auto",flex:"0 0 auto",display:"grid",justifyItems:"end",gap:2},children:[(0,e.jsx)("button",{type:"button","data-testid":"undo-turn",title:s?`${l.message} \u2014 undo those too`:"Take this back, keeping everything since",onClick:()=>{y(null);try{let d=i.log.all().find(t=>t.batch===n&&t.author.kind==="agent");i.undo(s?[n,...g]:n,{author:p}),d&&a({type:"home",author:d.author})}catch(d){y(d instanceof Error?d.message:String(d))}},style:{display:"inline-flex",alignItems:"center",minHeight:24,minWidth:24,padding:"1px 8px",fontSize:"0.75rem",...s?{borderColor:"var(--graview-warn)",color:"var(--graview-warn)"}:{}},children:s?`undo +${g.length}`:"undo"}),h?(0,e.jsx)("span",{"data-testid":"undo-refused",role:"alert",style:{fontSize:"0.75rem",lineHeight:1.4,color:"var(--graview-warn)",maxWidth:260,textAlign:"right"},children:h}):null]})}function E(){let n=()=>{let i=new URL(window.location.href);return i.searchParams.set("fresh","1"),i.toString()};return(0,e.jsx)("a",{href:"#fresh","data-testid":"start-fresh",title:"Forget every edit made in this browser and return to the example",onClick:i=>{i.preventDefault(),window.location.assign(n())},style:{display:"inline-flex",alignItems:"center",minHeight:24,minWidth:24,fontSize:"0.8125rem",color:"var(--graview-ink-muted)",textDecoration:"underline",textDecorationColor:"var(--graview-edge-bright)",textUnderlineOffset:3},children:"Start fresh"})}function F({calls:n,seat:i,remembers:p=!1}){let a=H(),{store:o,principal:h,seats:y,people:l}=f(),s=n.some(t=>t.phase==="running"),g=R("activity"),d=g.open;return i===void 0&&n.length===0&&a.length===0&&!p?null:(0,e.jsxs)("div",{style:{position:"relative"},children:[(0,e.jsxs)("button",{type:"button","data-testid":"activity-button",...g.trigger,onClick:g.toggle,title:s?"An agent is working":"What has happened",style:{display:"inline-flex",alignItems:"center",gap:6,minHeight:30,padding:"0 8px",borderRadius:8,border:"1px solid transparent",background:"transparent",boxShadow:"none",fontSize:"0.875rem",whiteSpace:"nowrap",color:s?"var(--graview-accent)":"var(--graview-ink-muted)"},children:[s?(0,e.jsx)("span",{"aria-hidden":"true",style:{width:6,height:6,borderRadius:999,background:"var(--graview-accent)"}}):null,a.length>0?a.length:"",(0,e.jsxs)("svg",{className:"graview-activity-mark",width:"15",height:"15",viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",style:{display:"var(--graview-activity-mark, none)"},children:[(0,e.jsx)("circle",{cx:"8",cy:"8",r:"5.75",fill:"none",stroke:"currentColor",strokeWidth:"1.4"}),(0,e.jsx)("path",{d:"M8 4.75 V8 L10.25 9.5",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]}),(0,e.jsx)("span",{className:"graview-activity-word",children:" Activity"})]}),!d&&i!==void 0?(0,e.jsx)("div",{hidden:!0,"data-testid":"agent-seat-seated",children:i}):null,d?(0,e.jsxs)("section",{...g.pane,"aria-label":"Activity","data-testid":"activity","data-graview-offstage":"",style:{...L,width:300,maxHeight:"min(52cqh, 460px)",overflow:"auto",display:"flex",flexDirection:"column",gap:9,padding:12,borderRadius:10,border:"1px solid var(--graview-edge)",background:"var(--graview-float)",boxShadow:"var(--graview-lift-high)"},children:[(0,e.jsx)("h2",{style:{...T,margin:0},children:"Activity"}),i!==void 0?(0,e.jsxs)("div",{"data-testid":"agent-seat-row",style:{display:"grid",gap:5,paddingBottom:n.length>0||a.length>0?9:0,...n.length>0||a.length>0?{borderBottom:"1px solid var(--graview-edge)"}:{}},children:[(0,e.jsx)("span",{style:{fontSize:"0.75rem",letterSpacing:"0.14em",textTransform:"uppercase",color:"var(--graview-ink-faint)"},children:"The agent's seat"}),i]}):null,n.length>0?(0,e.jsx)("ol",{style:{margin:0,padding:0,listStyle:"none",display:"grid",gap:7},children:n.slice(0,6).map((t,v)=>(0,e.jsxs)("li",{style:{display:"grid",gap:2,fontSize:"0.8125rem",lineHeight:1.45},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:6},children:[(0,e.jsx)("span",{"aria-hidden":"true",style:{width:6,height:6,borderRadius:999,flex:"0 0 auto",background:t.phase==="running"?"var(--graview-accent)":t.phase==="failed"?"var(--graview-warn)":"var(--graview-edge-bright)"}}),(0,e.jsxs)("span",{style:{color:"var(--graview-ink)"},children:[t.mutating?"changed":"read"," \xB7"," ",o.allMutations().find(r=>r.name===t.name)?.title??A(t.name)]})]}),!t.mutating&&t.reads&&t.reads.length>0?(0,e.jsxs)("div",{"data-testid":"activity-reads",style:{display:"flex",flexWrap:"wrap",gap:4,paddingLeft:12},children:[[...new Set(t.reads)].slice(0,3).map(r=>(0,e.jsx)(c,{label:m(o,r),pickId:r},r)),new Set(t.reads).size>3?(0,e.jsxs)("span",{style:{color:"var(--graview-ink-muted)"},children:["+",new Set(t.reads).size-3]}):null]}):Object.values(t.args).some(r=>typeof r=="string")?(0,e.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:4,paddingLeft:12},children:Object.entries(t.args).filter(r=>typeof r[1]=="string").slice(0,3).map(([r,S])=>(0,e.jsx)(c,{label:m(o,S),pickId:S},r))}):null,t.error?(0,e.jsx)("div",{style:{paddingLeft:12,color:"var(--graview-warn)"},children:t.error}):null]},`${t.at}:${v}`))}):null,a.length>0?(0,e.jsx)("ol",{"data-testid":"diff-log",style:{margin:0,padding:0,listStyle:"none",display:"grid",gap:6,fontSize:"0.8125rem"},children:a.map((t,v)=>t.withheld?(0,e.jsx)("li",{"data-testid":"withheld-change",style:{display:"grid",gap:3,lineHeight:1.45},children:(0,e.jsx)("span",{"data-touched":"",style:{color:"var(--graview-ink-muted)",fontStyle:"italic"},children:t.intent})},`change:${v}`):(0,e.jsxs)("li",{style:{display:"grid",gap:3,lineHeight:1.45},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:6},children:[(0,e.jsxs)("span",{style:{minWidth:0},children:[(0,e.jsxs)("strong",{style:{fontWeight:600},children:[t.author==="human"&&t.by?.onBehalfOf===void 0&&(t.authorId===void 0||h.id===void 0||t.authorId===h.id)?"you":I(t.by??{kind:t.author,id:t.authorId},{graph:o.graph,schema:o.schema,seats:y,people:l}),x(t.via)?(0,e.jsxs)("span",{style:{fontWeight:400,color:"var(--graview-ink-muted)"},children:[", ",x(t.via)]}):null]})," ",(0,e.jsx)("span",{style:{color:"var(--graview-ink-muted)"},children:t.intent}),t.basis?(0,e.jsxs)("span",{"data-graview-lineage":"",style:{color:"var(--graview-ink-faint)"},children:[" \xB7 ",t.basis]}):null]}),t.batch?(0,e.jsx)(O,{batch:t.batch}):null]}),(0,e.jsx)("div",{"data-touched":t.touched.join(" "),style:{display:"flex",flexWrap:"wrap",gap:4},children:t.touched.slice(0,4).map(r=>(0,e.jsx)(c,{label:m(o,r),pickId:r},r))})]},`change:${v}`))}):null,p?(0,e.jsxs)("div",{"data-testid":"remembered",style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:10,paddingTop:8,borderTop:"1px solid var(--graview-edge)",fontSize:"0.8125rem",color:"var(--graview-ink-faint)"},children:[(0,e.jsx)("span",{children:"Remembered in this browser"}),(0,e.jsx)(E,{})]}):null]}):null]})}export{F as a};
@@ -0,0 +1 @@
1
+ import{a as X}from"./chunk.HGAMNIST.js";import{f as J,i as h,k as Q}from"./chunk.ZS4DJ76C.js";import{b as Y}from"./chunk.5R66YTET.js";import{c as U,g as V}from"./chunk.G4WQGTZR.js";import{F as ne,M as G,V as _,h as q,u as B}from"./chunk.Z56B2JR2.js";import{W as T,Y as j,ca as M}from"./chunk.HLLWKSZB.js";import{b as W}from"./chunk.AJZBJBMO.js";var i=W(ne(),1),a=W(G(),1);function fe({affordance:o,onApply:r,onCancel:m,store:w}){let b=_(),l=w??b?.store,[O,P]=(0,i.useState)({}),[f,N]=(0,i.useState)(""),[$,H]=(0,i.useState)(Z),L=(0,i.useId)(),D=(0,i.useRef)(null),k=o.open.filter(e=>!(e.name in O)),s=k[0];if((0,i.useEffect)(()=>N(""),[s?.name]),(0,i.useEffect)(()=>{D.current?.scrollIntoView?.({block:"nearest",inline:"nearest"})},[s?.name]),(0,i.useLayoutEffect)(()=>{let e=D.current,n=typeof document>"u"?null:document.activeElement;if(!e||n&&n!==document.body&&!e.contains(n))return;let u=e.querySelector("form input, [role=group] button:not([disabled])");u&&u!==n&&u.focus()},[s?.name]),!s)return null;let y=e=>{let n={...O,[s.name]:e};if(o.open.filter(c=>!(c.name in n)).length===0){let c=r(Object.fromEntries(Object.entries(n).filter(([,I])=>I!==void 0)));c&&c.length>0&&P(Object.fromEntries(Object.entries(n).filter(([I])=>!c.includes(I))))}else P(n)},z=s.optional?(0,a.jsx)("button",{type:"button",onClick:()=>y(void 0),style:{fontSize:"0.8125rem"},children:"Skip"}):null,t=s.shape??{type:"unknown"},d=t.type==="number"?t.amount:void 0,p=oe(s,t),g=J(l.schema,l.allMutations().find(e=>e.name===o.mutation),s.name),[C,ee]=(0,i.useState)(""),R=(0,i.useMemo)(()=>{let e=p.map(n=>l.graph.getNode(n)).filter(n=>n!==void 0);return Y(e,n=>l.schema.tryDefinition(n))},[p,l]),E=e=>{let n=ae(l,t,e),u=t.type==="choice"||t.type==="several"&&t.of.type==="choice"?g.option(e):n,c=R.get(e);return c?`${u} \xB7 ${c}`:u},x=(0,i.useMemo)(()=>{let e=C.trim().toLowerCase();return e===""?p:p.filter(n=>E(n).toLowerCase().includes(e))},[p,C,l,t,R]),v=t.type==="several",K=t.type==="file"?t:t.type==="several"&&t.of.type==="file"?t.of:void 0,F=v&&p.length===0,S=s.kinds&&s.kinds.length>0&&!s.kinds.includes("*")?s.kinds.map(e=>j(M(l.schema.tryDefinition(e),e))).join(" or "):g.label,te=o.open.length>1?`${S} \xB7 ${o.open.length-k.length+1} of ${o.open.length}`:S;return(0,a.jsxs)("div",{ref:D,"data-graview-asking":o.id,style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr)",gap:4,padding:"5px 0 2px"},children:[o.open.length>1||p.length>0?(0,a.jsx)("span",{id:L,style:{fontSize:"0.75rem",color:"var(--graview-ink-faint)"},children:te}):null,p.length>A?(0,a.jsx)("input",{type:"search",value:C,onChange:e=>ee(e.target.value),placeholder:`Filter ${p.length}\u2026`,"aria-label":`Filter ${S}`,"data-testid":"ask-filter",style:{font:"inherit",fontSize:"0.8125rem",minWidth:0,padding:"3px 7px"}}):null,K?(0,a.jsxs)("div",{style:{display:"grid",gap:4},children:[(0,a.jsx)(X,{as:"control",value:void 0,onChange:y,several:v,image:K.image===!0,label:g.label}),z]}):p.length>0?(0,a.jsxs)("div",{role:"group","aria-labelledby":L,style:{display:"flex",flexWrap:"wrap",gap:4},children:[x.slice(0,A).map(e=>{let n=$.includes(e);return(0,a.jsx)("button",{type:"button","aria-label":`${S}: ${E(e)}`,...v?{"aria-pressed":n}:{},style:{padding:"3px 9px",fontSize:"0.8125rem",...n?{borderColor:"var(--graview-accent)",color:"var(--graview-accent)"}:{}},onClick:()=>v?H(u=>u.includes(e)?u.filter(c=>c!==e):[...u,e]):y(t.type==="boolean"?e==="yes":e),children:E(e)},e)}),x.length>A?(0,a.jsxs)("span",{"data-testid":"ask-more",style:{alignSelf:"center",fontSize:"0.75rem",color:"var(--graview-ink-faint)"},children:[x.length-A," more \u2014 type to narrow"]}):null,x.length===0?(0,a.jsxs)("span",{"data-testid":"ask-none",style:{alignSelf:"center",fontSize:"0.75rem",color:"var(--graview-ink-faint)"},children:["None of the ",p.length," match that."]}):null,v?(0,a.jsx)("button",{type:"button",disabled:$.length===0,style:{fontSize:"0.8125rem"},onClick:()=>{let e=$;H(Z),y(e)},children:k.length>1?"Next":"Apply"}):null,z]}):(0,a.jsxs)("form",{style:{display:"flex",flexWrap:"wrap",gap:4},onSubmit:e=>{if(e.preventDefault(),F){y(f.split(/[,\n]/).map(n=>n.trim()).filter(Boolean));return}if(f.trim().length!==0){if(d){let n=Q(f,d);n!==void 0&&y(n);return}y(t.type==="number"?t.duration?V(f)??f:Number(f):f)}},children:[t.type==="text"&&t.long?(0,a.jsx)("textarea",{autoFocus:!0,name:s.name,"aria-label":g.label,placeholder:g.label,value:f,rows:4,onChange:e=>N(e.target.value),onKeyDown:e=>{e.key==="Escape"?m():e.key==="Enter"&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),e.currentTarget.form?.requestSubmit())},style:{flex:"1 1 100%",minWidth:0,font:"inherit",fontSize:"0.875rem",lineHeight:1.45,padding:"5px 8px",borderRadius:7,border:"1px solid var(--graview-edge)",background:"var(--graview-panel)",color:"var(--graview-ink)",resize:"vertical",fieldSizing:"content",minHeight:"5.5em",maxHeight:"40vh"}}):(0,a.jsx)("input",{autoFocus:!0,type:t.type==="date"?t.time?"datetime-local":"date":t.type==="number"&&!t.duration&&!d?"number":t.type==="text"&&t.holds==="phone"?"tel":"text",...d?{inputMode:"decimal","data-graview-amount":d.format??"unit"}:{},name:s.name,"aria-label":g.label,placeholder:F?`${g.label}, separated by commas`:d?`${g.label}, ${h(d).hint} \u2014 ${h(d).prefix??""}${h(d).placeholder}${h(d).suffix?` ${h(d).suffix}`:""}`:g.label,value:f,...t.type==="number"&&t.min!==void 0?{min:t.min}:{},...t.type==="number"&&t.max!==void 0?{max:t.max}:{},...t.type==="number"&&t.step!==void 0?{step:t.step}:{},onChange:e=>N(e.target.value),onKeyDown:e=>{e.key==="Escape"&&m()},style:{flex:1,minWidth:0,font:"inherit",fontSize:"0.875rem",padding:"5px 8px",borderRadius:7,border:"1px solid var(--graview-edge)",background:"var(--graview-panel)",color:"var(--graview-ink)"}}),(0,a.jsx)("button",{type:"submit",disabled:!F&&f.trim().length===0,style:{fontSize:"0.8125rem"},children:k.length>1?"Next":"Apply"}),z]})]})}var Z=[],A=10;function oe(o,r){return o.candidates&&o.candidates.length>0?o.candidates:r.type==="choice"?r.options:r.type==="several"&&r.of.type==="choice"?r.of.options:r.type==="boolean"?re:[]}var re=["yes","no"];function ae(o,r,m){return r.type==="boolean"||r.type==="choice"||r.type==="several"&&r.of.type==="choice"?m:ie(o,m)}function ie(o,r){let m=q(r);if(m){let l=U(o.schema,o.graph.getNode(m.from)?.kind??"",m.kind,"out");return l.charAt(0).toUpperCase()+l.slice(1)}let w=B(r);if(w.length>0)return w.map(l=>o.schema.tryDefinition(l)?.plural??`${l}s`).join(" + ");let b=o.graph.getNode(r);return b?T(o.schema.tryDefinition(b.kind),b):r}export{fe as a,ie as b};
@@ -0,0 +1,4 @@
1
+ import{a as vr,b as kr,c as Sr}from"./chunk.OWE6OJ4P.js";import{a as At,f as Lt,g as an}from"./chunk.QNHECGMH.js";import{e as xr}from"./chunk.RKRSRKF3.js";import{e as yr,o as An,p as pr}from"./chunk.KC6UZHBM.js";import{b as sn}from"./chunk.ZBXOX3W3.js";import{a as Le,b as po,c as Ut,d as br,e as xo}from"./chunk.5AT4O4BN.js";import{a as wr}from"./chunk.X53HI436.js";import{b as dr,d as lr}from"./chunk.UT6642FC.js";import{a as cr,c as ho,d as fo,g as mo,h as go,i as yo,j as ur,k as _t,l as Gt,p as Ot,q as Kt,r as mr,s as gr}from"./chunk.OYJSFO3A.js";import{a as hr,b as fr}from"./chunk.HV6I74DF.js";import{a as ir,b as ze,c as En,d as ar,f as On,g as on,h as rn,i as zt,j as uo}from"./chunk.OQDETV4X.js";import{c as sr}from"./chunk.G4WQGTZR.js";import{a as Jt}from"./chunk.GS4T26WW.js";import{A as ot,B as Mn,C as Vt,F as Te,H as oo,J as ft,M as Oe,N as ro,R as io,S as Rn,T as Mt,U as ge,W as Rt,_ as Yt,a as Qn,aa as rr,b as Zn,c as Jn,d as tr,e as nr,f as kn,h as kt,ha as ao,ia as so,j as ut,ja as Et,k as eo,l as Sn,la as lo,m as en,oa as co,p as to,pa as nn,r as be,s as Re,t as or,u as tn,v as Ee,w as St,x as ht,y as no}from"./chunk.Z56B2JR2.js";import{$ as Wt,Fb as Ie,V as Xo,W as vn,Y as Ft,Z as jt,_ as vt,aa as qo,ca as Qo,ob as Zt,oc as Zo,rc as Jo,wc as er}from"./chunk.HLLWKSZB.js";import{b as se}from"./chunk.AJZBJBMO.js";var Mr={width:1200,height:760,focusSize:{width:1200,height:420},relationSize:{width:240,height:140},contextSize:{width:300,height:104},gap:16,unit:16};var Rr=(e,t)=>e?`${e.edgeKind}|${e.direction}`:`raised|${t}`,It=(e,t,n)=>`${Mn}${e}|${t}|${n}`;function zi(e,t){if(!Vt(e))return null;let[n="",r="",o="",a=""]=e.slice(Mn.length).split("|"),i=t.definitions.find(x=>x.kind===n),l=Wt(t,n),u=r==="raised"?null:(()=>{let x=i?.edges[r]??t.definitions.map(p=>p.edges[r]).find(Boolean);return((o==="in"?x?.inverse:x?.description)??Ft(r)).toLowerCase()})(),[s="",d=""]=a.split("="),c=s.split(":")[0],h=a===""||a==="kind"||a.startsWith("more")?null:`${qo(i,c).toLowerCase()}: ${d==="none"?"none":d}`;return[a.startsWith("more")?`More ${l.toLowerCase()}`:l,[u,h].filter(Boolean).join(", ")].filter(Boolean).join(" \u2014 ")}function Ln(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 wo(e){return Rr(e.via,e.node.kind)}function In(e,t){let n=[],r=0;return e.forEach((o,a)=>{if(o<=0)return;if(n.length>0&&o<=r){for(let l=0;l<o;l++)n[n.length-1].push(a);r-=o;return}let i=o;for(;i>0;){let l=Math.min(t,i);n.push(Array.from({length:l},()=>a)),i-=l,r=t-l}}),n}function vo(e,t,n){let r=Ln(e,t*n);for(;In(r,t).length>n;){let o=-1;if(r.forEach((a,i)=>{a>1&&(o<0||a>r[o])&&(o=i)}),o<0)break;r[o]=r[o]-1}return r}function _i(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 Gi=5,Ki=(e,t)=>{for(let n=0;n<e.length;n++)if(e[n]!==t[n])return e[n]<t[n];return!1};function Er(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 yr(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 d=xr(e,{group:l},o).groups;if(d.length<2||d.length>t)return;let h=d.filter(x=>x.key!=="").reduce((x,f)=>x+f.nodes.length,0)/e.length;if(h<.5||d.some(x=>x.nodes.length>e.length*.75))return;let y=[-Math.round(h*100),Math.abs(d.length-Gi),u];(!i||Ki(y,i.score))&&(i={grouping:{by:l.by,...l.bucket?{bucket:l.bucket}:{},groups:d},score:y})}),i?.grouping}function ko(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=Rr(f.via,f.node.kind),b=o.get(p);b?b.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(b=>b.node.kind))],members:[],whole:!1,extra:0})),i=Ln(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),s=Math.max(l.length,t.budget-u);for(let f of l){f.members=_i(f.run.map(b=>b.node),r,t.graph);let p=s-(l.length-1);f.kinds.length>1&&f.kinds.length<=p?f.byKind=!0:f.kinds.length===1&&(f.grouping=Er(f.members,p,{schema:t.schema,graph:t.graph,...f.via?{exclude:f.via.edgeKind}:{},...t.today?{today:t.today}:{}}))}let d=f=>f.byKind?f.kinds.length:f.grouping?f.grouping.groups.length:1;for(;l.reduce((f,p)=>f+d(p),0)>s;){let f=[...l].filter(p=>d(p)>1).sort((p,b)=>d(b)-d(p))[0];if(!f)break;f.grouping=void 0,f.byKind=!1}s-=l.reduce((f,p)=>f+d(p),0);let c=f=>f.byKind?f.kinds.some(p=>t.expanded.has(It(p,f.key,"kind"))):f.grouping?.groups.some(p=>t.expanded.has(It(f.kinds[0],f.key,bo(f.grouping,p.key)))),h=l.filter(f=>!f.grouping&&!f.byKind?!0:c(f)),y=Ln(h.map(f=>f.members.length),Math.max(0,s));h.forEach((f,p)=>f.extra=s>0?y[p]:0);let x=[];for(let f of a){let{key:p,via:b}=f;if(f.whole){x.push(...f.run.map(n));continue}let g=v=>({id:v.id,kind:v.kind,node:v,...b?{via:b}:{}}),O=new Map(f.run.map((v,M)=>[v.node.id,M])),I=(v,M,w)=>{let E=[...v.slice(0,M)].sort((N,H)=>O.get(N.id)-O.get(H.id));x.push(...E.map(g));let V=v.slice(M);if(V.length===0)return;let A=V[0].kind;x.push({id:It(A,p,w?`more:${w}`:"more"),kind:A,...b?{via:b}:{},aggregate:{kind:A,memberIds:V.map(N=>N.id),label:M>0?`${V.length} more ${t.plural(A).toLowerCase()}`:`${V.length} ${t.plural(A).toLowerCase()}`,opens:{in:"picture",focus:Ee(A),within:w?{filter:w}:{}}}})},L=b&&t.focusId?`${b.edgeKind}:${t.focusId}`:void 0;if(f.byKind){let v=f.kinds.find(M=>t.expanded.has(It(M,p,"kind")));for(let M of f.kinds){let w=f.members.filter(E=>E.kind===M);if(M===v){let E=f.extra+1;w.length<=E?x.push(...w.map(g)):I(w,E-1,L);continue}x.push({id:It(M,p,"kind"),kind:M,...b?{via:b}:{},aggregate:{kind:M,memberIds:w.map(E=>E.id),label:t.plural(M),opens:{in:"place"}}})}continue}let C=f.grouping;if(!C){I(f.members,f.extra,L);continue}let Z=f.kinds[0],q=C.groups.find(v=>t.expanded.has(It(Z,p,bo(C,v.key))));for(let v of C.groups){if(v===q){let M=f.members.filter(E=>v.nodes.includes(E)),w=f.extra+1;if(M.length<=w)x.push(...M.map(g));else{let E=v.key!==""&&!v.key.includes(",")&&!C.bucket,V=[L,E?`${C.by}:${v.key}`:void 0].filter(Boolean).join(",")||void 0;I(M,w-1,V)}continue}x.push({id:It(Z,p,bo(C,v.key)),kind:Z,...b?{via:b}:{},aggregate:{kind:Z,memberIds:f.members.filter(M=>v.nodes.includes(M)).map(M=>M.id),label:v.label.charAt(0).toUpperCase()+v.label.slice(1),opens:{in:"place"}}})}}return x}var bo=(e,t)=>`${e.by}${e.bucket?`:${e.bucket}`:""}=${t||"none"}`;function Ar(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 Ct(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 So=(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},dn=4,Or=.45;function Mo(e,t,n,r={},o={}){let a={};for(let k of e)a[k.kind]=k.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,s=k=>k.nameplate??{width:120,height:34,short:{width:90,height:20}},d=k=>e.map(R=>{let $=k.get(R.kind);return{card:R,plot:$,center:Ut($.col+$.side/2,$.row+$.side/2,1,u)}}),c=(k,R)=>{let $=1/0,Y=-1/0,j=1/0,S=-1/0;for(let{card:T,plot:B,center:W}of k){let z=W.x*R,K=W.y*R,D=B.side*R/2,re=T.opened>0?s(T).width:s(T).short.width;$=Math.min($,z-Math.max(D+(T.count>12?30:0),re/2)),Y=Math.max(Y,z+Math.max(D,re/2)),j=Math.min(j,K-D*u-R*Or),S=Math.max(S,K+D*u+dn+s(T).short.height)}return{minX:$,maxX:Y,minY:j,maxY:S}},h=k=>{let R=4,$=160;for(let Y=0;Y<24;Y++){let j=(R+$)/2,S=c(k,j);S.maxX-S.minX<=i.width&&S.maxY-S.minY<=i.height?R=j:$=j}return R},y=k=>{let R={...o.order?{order:o.order}:{},counts:a,...o.plots?{plots:o.plots}:{},pitch:k},$=po(t,R),Y=po(t,{...R,upright:!0}),j=h(d($)),S=h(d(Y)),T=n.height>n.width&&S>=j?Y:$;return{map:T,fitted:T===Y?S:j}},x=[],f=new Map,p=0,b=(k,R={x:0,y:0})=>{let $=c(x,k),Y=i.x+i.width/2-($.minX+$.maxX)/2+R.x,j=i.y+i.height/2-($.minY+$.maxY)/2+R.y;return{originX:Y,originY:j,cell:k}},g=k=>{let{originX:R,originY:$,cell:Y}=k,j=x.map(({center:B})=>B.y),S=Math.max(...j),T=Math.min(...j);return x.map(({card:B,plot:W,center:z})=>{let K=R+z.x*Y,D=$+z.y*Y,re=W.side*Y/2,G=re*u,we=S===T?.5:(z.y-T)/(S-T);return{card:B,plot:W,x:K,y:D,halfW:re,halfH:G,depth:1-we*.65}})},O=(k,R=!0)=>{let $=[];return[...k].sort((j,S)=>(S.card.weight??S.card.count)-(j.card.weight??j.card.count)||e.indexOf(j.card)-e.indexOf(S.card)).filter(j=>[s(j.card),s(j.card).short].some(S=>{let T=C(j,S),B=(!R||T.x>=0&&T.y>=0&&T.x+T.width<=n.width&&T.y+T.height<=n.height)&&!$.some(W=>Ct(T,W,4))&&!k.some(W=>W!==j&&So(T,W,W.halfW,W.halfH))&&!l.some(W=>Ct(T,W,0));return B&&$.push(T),B})).length},I=k=>k.card.marquee?{x:k.x-k.card.marquee.width/2,y:k.y+k.halfH+dn+s(k.card).height,width:k.card.marquee.width,height:k.card.marquee.height}:null,L=(k,R,$)=>$.some(Y=>{if(Y===R)return!1;let j=I(Y);return j!==null&&Ct(k,j,4)}),C=(k,R,$="under")=>$==="aside"?{x:k.x+k.halfW+dn,y:k.y-R.height/2,width:R.width,height:R.height}:$==="above"?{x:k.x-R.width/2,y:k.y-k.halfH-dn-Or*M.cell-R.height,width:R.width,height:R.height}:{x:k.x-R.width/2,y:k.y+k.halfH+dn,width:R.width,height:R.height},Z=k=>k.some(R=>l.some($=>So($,R,R.halfW,R.halfH)||Ct($,C(R,s(R.card).short),0))),q=k=>k.every(R=>{let $=C(R,s(R.card).short);return R.x-R.halfW>=0&&R.x+R.halfW<=n.width&&R.y-R.halfH>=0&&$.x>=0&&$.x+$.width<=n.width&&$.y+$.height<=n.height}),v={pitch:Le,said:-1};for(let k of[Le,Le+1,Le+2,Le+3,Le+5,Le+7]){({map:f,fitted:p}=y(k)),x=d(f);let R=O(g(b(p)));if(R>v.said&&(v={pitch:k,said:R}),R===e.length)break}(v.pitch!==Le+7||v.said!==e.length)&&({map:f,fitted:p}=y(v.pitch),x=d(f));let M=b(p);if(l.length>0&&Z(g(M))){let k;for(let R=1;R>=.3&&!k;R-=.05){let $=p*R,Y=Math.max(...l.map(S=>S.width))/2+$,j=Math.max(...l.map(S=>S.height))/2+$/2;for(let S of[0,.5,.75,1,1.25]){for(let[T,B]of[[1,0],[-1,0],[0,1],[0,-1],[1,1],[-1,1],[1,-1],[-1,-1]]){let W=b($,{x:T*Y*S,y:B*j*S}),z=g(W);if(!Z(z)&&q(z)){k=W;break}if(S===0)break}if(k)break}}k&&(M=k)}let w=(k,R)=>{let $={x:n.width/2,y:n.height/2};return{cell:k.cell*R,originX:$.x+(k.originX-$.x)*R,originY:$.y+(k.originY-$.y)*R}},E=1;if(O(g(M))<e.length){let k={said:O(g(M),!1),area:1/0,pitch:-1,by:1},R={map:f,shape:x,fitted:p,where:M};for(let Y of[Le,Le+1,Le+2,Le+3,Le+5,Le+7]){({map:f,fitted:p}=y(Y)),x=d(f);let j=b(p);for(let S=1;S<=3.001;S+=.1){let T=O(g(w(j,S)),!1),B=c(x,p*S),W=(B.maxX-B.minX)*(B.maxY-B.minY);if((T>k.said||T===k.said&&W<k.area)&&(k={said:T,area:W,pitch:Y,by:S}),T===e.length)break}}k.pitch<0?{map:f,shape:x,fitted:p,where:M}=R:({map:f,fitted:p}=y(k.pitch),x=d(f),E=k.by,M=w(b(p),E));let $=g(M).filter(Y=>o.keep?.includes(Y.card.kind));if($.length>0){let Y=$.flatMap(z=>[{x:z.x-z.halfW,y:z.y-z.halfH,width:z.halfW*2,height:z.halfH*2},C(z,s(z.card))]),j=Math.min(...Y.map(z=>z.x)),S=Math.max(...Y.map(z=>z.x+z.width)),T=Math.min(...Y.map(z=>z.y)),B=Math.max(...Y.map(z=>z.y+z.height)),W=(z,K,D)=>K-z>D-16?D/2-(z+K)/2:z<8?8-z:K>D-8?D-8-K:0;M={...M,originX:M.originX+W(j,S,n.width),originY:M.originY+W(T,B,n.height)}}}let V=o.zoom&&o.zoom!==1?o.zoom:1;V!==1&&(M=w(M,V));let A=g(M),N=[],H=new Map,U=[...A].sort((k,R)=>(R.card.weight??R.card.count)-(k.card.weight??k.card.count)||e.indexOf(k.card)-e.indexOf(R.card));for(let k of U){let R=[["full",s(k.card),"under"],["short",s(k.card).short,"under"]],$="none",Y=k===U[0],j=(T,B)=>R.filter(([W])=>W.startsWith(B)).map(([W,z,K])=>[W,z,K,T]),S=Y?[...j(!1,"full"),...j(!1,"short"),...j(!0,"full"),...j(!0,"short")]:R.map(([T,B,W])=>[T,B,W,!1]);for(let[T,B,W,z]of S){let K=C(k,B,W);if((V!==1||E!==1||K.x>=0&&K.y>=0&&K.x+K.width<=n.width&&K.y+K.height<=n.height)&&!N.some(G=>Ct(K,G,4))&&(z||!A.some(G=>G!==k&&So(K,G,G.halfW,G.halfH)))&&!L(K,k,A)&&!l.some(G=>Ct(K,G,0))){$=T,N.push(K);break}}H.set(k.card.id,$)}let X=A.map(k=>({id:k.card.id,x:k.x-k.halfW,y:k.y-k.halfH,width:k.halfW*2,height:k.halfH*2+(k.card.opened>0?Math.max(k.card.openedMin??0,k.card.opened):0),depth:k.depth,plot:k.plot,nameplate:H.get(k.card.id)??"none"})),de=c(x,M.cell),le={cell:M.cell,originX:M.originX,originY:M.originY,pan:o.pan??{x:0,y:0},extent:{x:M.originX+de.minX,y:M.originY+de.minY,width:de.maxX-de.minX,height:de.maxY-de.minY},openedShare:1,...u!==.5?{tilt:u}:{},...A.some(k=>k.card.marquee)?{showings:A.flatMap(k=>{let R=I(k);return R?[{id:k.card.id,x:R.x-(k.x-k.halfW),y:R.y-(k.y-k.halfH),width:R.width,height:R.height}]:[]})}:{}};return{placed:X,frame:le,map:f}}function mt(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 Cn=48;function Ro(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",s=u?Math.max(0,Math.min(n,i)):Math.max(0,Math.min(t,a)),d=(y,x)=>y<x/4?x/4-y:y>x*3/4?x*3/4-y:0,c=(y,x)=>y<Cn?Cn-y:y>x-Cn?x-Cn-y:0,h=u?{x:d(a,t),y:c(i,n)}:{x:c(a,t),y:d(i,n)};r.push({id:o.id,kind:o.id.slice(5),side:l,along:s,by:h})}return r}function Eo(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 Ui={rankOf:()=>{},parentOf:()=>{}};function Lr(e,t){if(t.size===0)return Ui;let n=e.kinds,r=new Map,o=(s,d)=>{s!==d&&((r.get(s)??r.set(s,new Set).get(s)).add(d),(r.get(d)??r.set(d,new Set).get(d)).add(s))};for(let s of n){let d=e.tryDefinition(s);if(d)for(let c of Object.values(d.edges??{})){let h=c.to==="*"?n:c.to;for(let y of h)o(s,y)}}let a=new Map,i=new Map,l=[...t].filter(s=>n.includes(s));for(let s of l)a.set(s,0);let u=0;for(;l.length>0;){u+=1;let s=[];for(let d of[...l].sort((c,h)=>n.indexOf(c)-n.indexOf(h)))for(let c of[...r.get(d)??[]].sort((h,y)=>n.indexOf(h)-n.indexOf(y)))a.has(c)||(a.set(c,u),u===2&&i.set(c,d),s.push(c));l=s}return{rankOf:s=>{let d=a.get(s);if(d!==0)return d===1?"primary":"secondary"},parentOf:s=>i.get(s)}}function Ir(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 s=i.from===n.id?"out":"in",d=s==="out"?n.kind:u.kind,c=Xi(t,d,i.kind,s);a.set(l,{node:u,via:{edgeKind:i.kind,direction:s,...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)||ot(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 s=e.getNode(u);s&&(r&&r!=="judges"&&s.kind!==r||(i.add(u),l.push({node:s,via:{edgeKind:"judges",direction:"out",description:"what it finds wrong"}})))}if(l.length>0)return l.sort((u,s)=>ot(u.node,s.node))}return r?e.allNodes().filter(a=>a.kind===r).sort(ot).map(a=>({node:a})):[]}function Xi(e,t,n,r){let a=e.tryDefinition(t)?.edges?.[n];return r==="out"?a?.description:a?.inverse}function Cr(e,t,n){let r=new Map,o=[...t.values()].sort((s,d)=>s.plane-d.plane);for(let s of o)for(let d of s.aggregate?.memberIds??[])!t.has(d)&&!r.has(d)&&r.set(d,s.id);let a=s=>t.get(s)??t.get(r.get(s)??""),i=new Map,l=new Map,u=new Map;for(let s of e.allEdges()){let d=a(s.from),c=a(s.to);if(!d||!c||d.id===c.id&&!(n.overview&&d.aggregate&&d.plane===2))continue;let h=`${s.kind}:${d.id}:${c.id}`,y=i.get(h);if(y){let x=`${s.from}
2
+ ${s.to}`,f=l.get(h);if(f.has(x))continue;if(f.add(x),u.get(h).push({from:s.from,to:s.to}),y.single){let{single:p,...b}=y;i.set(h,b)}continue}l.set(h,new Set([`${s.from}
3
+ ${s.to}`])),u.set(h,[{from:s.from,to:s.to}]),i.set(h,{id:h,kind:s.kind,from:d.id,to:c.id,edges:[{from:s.from,to:s.to}],single:{from:s.from,to:s.to},...d.id===c.id?{loop:!0}:{},x1:d.x+d.width/2,y1:d.y+d.height/2,x2:c.x+c.width/2,y2:c.y+c.height/2})}return[...i.values()].map(s=>({...s,edges:u.get(s.id)})).sort(ot)}var Pr=.85,qi=60,Oo=160;function Qi(e,t,n,r,o,a=Pr){let i=e*t.width+Math.max(0,e-1)*n,l=Math.max(n,(r-i)/2);return Array.from({length:e},(u,s)=>({x:l+s*(t.width+n),y:o,depth:a}))}function Zi(e,t,n,r,o){let a=e*t.width+Math.max(0,e-1)*n,i=Math.max(n,(r-a)/2);return Array.from({length:e},(l,u)=>({x:i+u*(t.width+n),y:o}))}function Pn(e,t,n,r={}){let o={...Mr,...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,s=o.width-l-i-(o.inset?.right??0),d=[],c=new Map,h=m=>n.past===!0||Xo(t.tryDefinition(m.kind),m,o.today),y=new Set(r.hiddenKinds??[]),x=m=>!y.has(m.kind),f=n.focusId?ht(n.focusId).filter(m=>t.tryDefinition(m)!==void 0).filter(m=>!y.has(m)):[];n.focusId&&ht(n.focusId).length>0&&f.length===0&&(n={...n,focusId:null});let p=n.focusId?e.getNode(n.focusId):void 0;p&&!x(p)&&(n={...n,focusId:null},f=[]);let b=f.length>0?[...e.allNodes()].filter(m=>f.includes(m.kind)).sort(ot):[],g=b.filter(x).filter(h),O=b.length-g.length,I=n.focusId&&f.length===0?e.getNode(n.focusId):void 0,L=n.zoom===!0&&!n.overview&&n.focusId!==null,C=Math.max(56,o.height*.062),Z=Math.min(o.height*.895,o.height-C),q=L?I!==void 0?{focusY:o.height*.03,focusH:o.height*.58,relationY:o.height*.645,relationH:o.height*.2,contextY:Z,contextH:C}:{focusY:o.height*.03,focusH:o.height*.71,relationY:o.height*.765,relationH:o.height*.1,contextY:Z,contextH:C}:I===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,F=m*.04,_=Math.max(m*.42,Math.min(m*.56,300)),ee=F+_+m*.06;return{focusY:F,focusH:_,relationY:ee,relationH:Math.max(m*.12,m*.878-m*.068-ee),contextY:m*.878,contextH:m*.092}})(),v=m=>Math.min(o.gap*m,Math.round(s*.1)),M=L?Math.min(880,s-v(5)):Math.min(700,s-v(6)),w=L?s-v(5):Math.min(o.focusSize.width,s-v(6)),E=(m,F,_)=>({width:m===0?F:Math.min(F,(s-o.gap*(m+1))/m),height:_}),V=(m,F,_)=>{let ee=E(m,F,_),xe=Math.min(F,Oo*a,s-o.gap*2);return ee.width>=xe?ee:{width:xe,height:_}},A=m=>Math.max(1,Math.floor((s-o.gap)/(Math.min(m,Oo*a,s-o.gap*2)+o.gap))),N=new Set(n.expanded),H=n.overview?[]:Ir(e,t,I,n.relation,o.judged).filter(m=>x(m.node)).filter(m=>h(m.node)),U=H.length>0?q.focusH:q.contextY-q.focusY-o.gap*2,X=w,de=o.height,le=Math.min(s*.5/X,o.height*.48/de),k=X*le,R=de*le,$=new Set(r.plainGroups??[]),Y=n.overview&&!I&&f.length>0&&n.focusId!==null,j=Y&&f.length>0&&f.every(m=>$.has(m));if(Y)for(let m of f)j&&r.besideTheMap!==!0?N.add(be(m)):N.delete(be(m));let S=Y&&!j&&f.length===1?f[0]:void 0,T=S!==void 0&&(r.screens?.[S]?.length??0)>0,B,W=n.overview===!0&&I!==void 0&&r.besideTheMap===!0;n.overview&&(I||f.length>0)&&n.focusId&&!j&&!T&&!(Y&&r.besideTheMap===!0)&&!W?(B={x:i+(s-k)/2,y:o.height*.53-R/2,width:k,height:R},Qt({id:n.focusId,kind:I?I.kind:f[0],plane:0,x:B.x,y:B.y,width:k,height:R,natural:{width:X,height:de},...I?{}:{aggregate:{kind:f.join("+"),memberIds:g.map(m=>m.id),label:r.plurals?.[n.focusId]??f.map(m=>vt(t,m)).join(" and "),...O>0?{retired:O}:{}}}})):n.overview||(I?Qt({id:I.id,kind:I.kind,plane:0,x:i+(s-M)/2,y:q.focusY,width:M,height:U}):f.length>0&&n.focusId&&Qt({id:n.focusId,kind:f[0],plane:0,x:i+(s-w)/2,y:q.focusY,width:w,height:U,aggregate:{kind:f.join("+"),memberIds:g.map(m=>m.id),label:r.plurals?.[n.focusId]??f.map(m=>vt(t,m)).join(" and "),...O>0?{retired:O}:{}}}));let z=26,K=52,D=22,re=Math.round(o.relationSize.width*.75),G=Math.max(1,Math.floor((s-o.gap)/(re+o.gap))),we=o.unit/16,Ce=Math.max(2,Math.floor((q.relationH+o.gap)/(z*we+o.gap))),Je=H.length>G*Ce,at={schema:t,graph:e,focusId:I?.id,expanded:N,...o.relevance?{relevance:o.relevance}:{},...n.selection?{selection:n.selection}:{},plural:m=>vt(t,m),...o.today?{today:o.today}:{}},Ue=Je?Math.max(o.gap,D*we):o.gap,Ve,te;if(!Je)Ve=H.map(m=>({id:m.node.id,kind:m.node.kind,node:m.node,...m.via?{via:m.via}:{}})),te=Array.from({length:Math.max(1,Math.ceil(Ve.length/G))},(m,F)=>Array.from({length:Math.min(G,Ve.length-F*G)},(_,ee)=>F*G+ee));else{let m=Math.max(1,Math.floor((q.relationH+Ue)/(K*we+Ue))),F=new Map;for(let ce of H){let Me=wo(ce),wt=F.get(Me);wt?wt.push(ce):F.set(Me,[ce])}let _=vo([...F.values()].map(ce=>ce.length),G,m),ee=[...F.values()].map((ce,Me)=>ko(ce,{...at,budget:_[Me]}));Ve=ee.flat();let xe=ee.map((ce,Me)=>ee.slice(0,Me).reduce((wt,qn)=>wt+qn.length,0)),Ye=ee.map(()=>0);te=In(ee.map(ce=>ce.length),G).map(ce=>ce.map(Me=>xe[Me]+Ye[Me]++))}let st=te.length,Ht=st===1?q.relationH:(q.relationH-Ue*(st-1))/st,dt=E(Math.max(...te.map(m=>m.length),1),Ve.length<=2?Math.round(o.relationSize.width*1.35):o.relationSize.width,Ht),et=[];te.forEach((m,F)=>{let _=Zi(m.length,dt,o.gap,s,q.relationY+F*(Ht+Ue));m.forEach((ee,xe)=>et[ee]={..._[xe],x:_[xe].x+i})}),Ve.forEach((m,F)=>{let _=et[F];Qt({id:m.id,kind:m.kind,plane:1,x:_.x,y:_.y,width:dt.width,height:dt.height,...m.via?{via:m.via}:{},...m.aggregate?{aggregate:m.aggregate}:{},...Je&&!m.aggregate?{compact:!0}:{}})});let lt=new Set(c.keys());for(let m of g)lt.add(m.id);let ke=new Map;for(let m of e.allNodes()){let F=ke.get(m.kind);F?F.push(m):ke.set(m.kind,[m])}let pt=new Set(f.length>0?f:I?[I.kind]:[]),Be=[];for(let m of t.kinds){if(y.has(m))continue;let F=ke.get(m)??[],_=F.filter(h);Be.push({id:be(m),kind:m,members:_.sort(ot),retired:F.length-_.length,...pt.has(m)?{focused:!0}:{}})}for(let m of Be)m.kind===n.relation&&(m.raised=!0);Be.sort(ot);let Xe=Lr(t,pt),qe=!n.overview&&t.kinds.some(m=>Xe.rankOf(m)==="primary"),Se=[];for(let m of Be)if(!n.overview&&N.has(m.id)&&m.members.length>0)for(let F of m.members)Se.push({id:F.id,kind:F.kind});else{let F=qe?Xe.rankOf(m.kind):void 0,_=F==="secondary"?Xe.parentOf(m.kind):void 0;Se.push({id:m.id,kind:m.kind,...m.raised?{raised:!0}:{},...m.focused?{focused:!0}:{},...n.overview&&N.has(m.id)?{opened:!0}:{},...F?{rank:F}:{},..._&&!N.has(be(_))?{nestedUnder:be(_)}:{},aggregate:{kind:m.kind,memberIds:m.members.map(ee=>ee.id),label:r.plurals?.[m.kind]??vt(t,m.kind),...m.retired>0?{retired:m.retired}:{}}})}let Qe=2;if(Se.length<=A((L?240:o.contextSize.width)*a))for(let m of Se)delete m.nestedUnder;let ct=new Map;for(let m of Se){if(m.nestedUnder===void 0)continue;let F=ct.get(m.nestedUnder)??0;F>=Qe?delete m.nestedUnder:ct.set(m.nestedUnder,F+1)}let tt=Se.filter(m=>m.nestedUnder!==void 0),Pe=Se.filter(m=>m.nestedUnder===void 0),bt=A((L?240:o.contextSize.width)*a),Fe=!n.overview&&Pe.length>bt,ne=Math.max(0,bt-1),ve=m=>m.focused?0:m.raised?1:2,nt=new Set([...Pe].map((m,F)=>({item:m,at:F})).sort((m,F)=>ve(m.item)-ve(F.item)||m.at-F.at).slice(0,ne).map(({item:m})=>m.id)),P=new Set(Fe?Pe.filter(m=>!nt.has(m.id)).map(m=>m.id):[]),oe=tt.filter(m=>!P.has(m.nestedUnder)),he=tt.filter(m=>P.has(m.nestedUnder)),fe=Fe?[...Pe.filter(m=>nt.has(m.id)),{id:or,kind:"",beyond:[...Pe.filter(m=>P.has(m.id)),...he].map(m=>m.kind)}]:Pe,Ae=n.overview?{width:Math.min(220,s/6.5),height:Math.min(92,o.height*.125)}:V(fe.length,(L?240:o.contextSize.width)*a,q.contextH),Dt=o.relevance?.flagged,gn=(m,F)=>{let _=xo(t,m);if(!_)return{};let ee=_.values.map(()=>0),xe=0;for(let Ye of F){let ce=_.values.indexOf(e.getNode(Ye)?.[_.field]);ce<0?xe++:ee[ce]++}return{states:{field:_.field,values:[..._.values.map((Ye,ce)=>({value:Ye,tier:_.tiers[ce],count:ee[ce]})),...xe>0?[{value:null,tier:"waiting",count:xe}]:[]]}}},Ne=n.overview?Mo(fe.map(m=>{let F=m.aggregate?.memberIds??[],_=Dt?F.filter(ee=>Dt.has(ee)).length:0;return{id:m.id,kind:m.kind,count:F.length,opened:N.has(m.id)?Gt(_t(F.length))*a:0,openedMin:N.has(m.id)?Gt(Math.min(yo,_t(F.length)))*a:0,nameplate:Ar(m.aggregate?.label??vt(t,m.kind),F.length,_,xo(t,m.kind)!==void 0,a),weight:_*1e3+F.length,...f.includes(m.kind)&&(r.screens?.[m.kind]?.length??0)>0?{marquee:{width:fo+12,height:mo(r.screens[m.kind].map(ee=>ee.title),fo,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)]:W&&m===I?.id?[I.kind]:[]),...r.tilt!==void 0?{tilt:r.tilt}:{},pan:{x:n.pan?.x??0,y:n.pan?.y??0},...B||o.chrome?.length?{avoid:[...B?[B]:[],...o.chrome??[]]}:{}}):null,yn=new Map(Ne?.placed.map(m=>[m.id,m.plot])??[]),pn=new Map(Ne?.placed.map(m=>[m.id,m.nameplate])??[]),Bt=Ne?Ne.placed.map(({x:m,y:F,depth:_,width:ee,height:xe})=>({x:m,y:F,depth:_,width:ee,height:xe})):Qi(fe.length,Ae,o.gap,s,q.contextY,L?.97:Pr).map(m=>({...m,x:m.x+i})),Wi=.74,xn=.8,Vi=52*a,Yi=86*a,Kn=(m,F)=>Math.min(1,m+(1-m)*F),Un=new Map;fe.forEach((m,F)=>{let _=Bt[F],ee=_.width??Ae.width,xe=_.height??Ae.height,Ye=m.rank==="secondary"?Wi:1,ce=Ne?ee:Math.max(Math.min(ee,Oo*a),ee*Ye),Me=Ne?xe:Math.max(qi*a,xe*Ye);Un.set(m.id,{x:_.x+(ee-ce)/2,y:_.y+(xe-Me),depth:m.rank==="secondary"?Kn(_.depth,.5):_.depth,width:ce,height:Me})});let bn=[],wn=Bt[Bt.length-1],Xn=new Map;for(let m of oe)Xn.set(m.nestedUnder,(Xn.get(m.nestedUnder)??0)+1);let Uo=new Map;for(let m of oe){let F=Un.get(m.nestedUnder);if(F){let _=Xn.get(m.nestedUnder)??1,ee=Uo.get(m.nestedUnder)??0;Uo.set(m.nestedUnder,ee+1);let xe=.98,Ye=Ae.width*xn,ce=Math.max(Yi,Math.min(Ye,F.width/(xe*(_-1)+1))),Me=Math.max(Vi,Ae.height*xn*(ce/Ye)),wt=ce*xe,qn=(_-1)*wt+ce;bn.push({...m,x:F.x+(F.width-qn)/2+ee*wt,y:Math.max(0,F.y-Me+Math.min(Me*.5,16)),width:ce,height:Me,depth:Kn(F.depth,.8)})}else if(wn){let _=Ae.width*xn,ee=Ae.height*xn;bn.push({...m,x:wn.x,y:wn.y,width:_,height:ee,depth:Kn(wn.depth??1,.8)})}}for(let m of fe)bn.push({...m,...Un.get(m.id)});return bn.forEach(m=>{Qt({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(Gt(Math.min(yo,_t(m.aggregate?.memberIds.length??0))),Gt(_t(m.aggregate?.memberIds.length??0))*(Ne?.frame.openedShare??1))-ur)/go))}:{},...m.rank?{rank:m.rank}:{},...m.nestedUnder?{nestedUnder:m.nestedUnder}:{},...m.beyond?{beyond:m.beyond}:{},...yn.has(m.id)?{plot:yn.get(m.id)}:{},...pn.has(m.id)?{nameplate:pn.get(m.id)}:{},...Ne&&m.aggregate?gn(m.kind,m.aggregate.memberIds):{},depth:m.depth})}),{nodes:d,connectors:Cr(e,c,n),width:o.width,height:o.height,...Ne?{city:Ne.frame}:{},...l>0||u>0?{visible:{width:o.width-l,height:o.height-u}}:{}};function Qt(m){let F=n.overview&&Re(m.id)!==null?void 0:n.pins[m.id],_=F?{...m,x:F.x,y:F.y,pinned:!0}:{...m,pinned:!1},ee=n.pan?{..._,x:_.x+n.pan.x,y:_.y+n.pan.y}:_;d.push(ee),c.set(ee.id,ee)}}function Ao(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 Lo(e,t){return t.x===0&&t.y===0?e:{...e,nodes:e.nodes.map(n=>({...n,x:n.x+t.x,y:n.y+t.y})),connectors:e.connectors.map(n=>({...n,x1:n.x1+t.x,y1:n.y1+t.y,x2:n.x2+t.x,y2:n.y2+t.y})),...e.city?{city:{...e.city,pan:{x:t.x,y:t.y}}}:{}}}var ye=(e,t,n)=>e+(t-e)*n;function Nr(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}var Tr=new WeakMap;function Ji(e){let t=Tr.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},Tr.set(e,t),t}var $r=new WeakMap;function Hr(e,t){let n=$r.get(t);if(n||$r.set(t,n=new WeakMap),n.has(e))return n.get(e);let r=ea(e,t);return n.set(e,r),r}function ea(e,t){let{byId:n,groupsOf:r}=Ji(t);if(e.screenOf!==void 0){let i=n.get(be(e.screenOf));if(i)return{...e,x:i.x,y:i.y,width:i.width,height:i.height}}if(St(e.id)||Re(e.id)!==null){let i=(e.aggregate?.memberIds??[]).map(d=>n.get(d)).filter(d=>d!==void 0);if(i.length===0)return null;let l=i.map(Nr),u=l.reduce((d,c)=>d+c.x,0)/l.length,s=l.reduce((d,c)=>d+c.y,0)/l.length;return{...e,x:u-e.width/2,y:s-e.height/2}}let o=r.get(e.id)?.find(i=>i.id===be(e.kind)||i.id===Ee(e.kind));if(!o)return null;let a=Nr(o);return{...e,x:a.x-e.width/2,y:a.y-e.height/2}}function Pt(e,t,n){let r=Math.max(0,Math.min(1,n)),o=new Map(e.nodes.map(d=>[d.id,d])),a=new Map(t.nodes.map(d=>[d.id,d])),i=[];for(let[d,c]of o){let h=a.get(d);if(h){i.push(Io(c,h,r,1));continue}let y=Hr(c,t)??c;i.push(Io(c,y,r,1-r))}for(let[d,c]of a){if(o.has(d))continue;let h=Hr(c,e)??c;i.push(Io(h,c,r,r))}let l=new Map(e.connectors.map(d=>[d.id,d])),u=new Map(t.connectors.map(d=>[d.id,d])),s=[];for(let[d,c]of l){let h=u.get(d);s.push(h?{...ta(c,h,r),opacity:1}:{...c,opacity:1-r})}for(let[d,c]of u)l.has(d)||s.push({...c,opacity:r});return{nodes:i.filter(d=>d.opacity>0).sort((d,c)=>d.id<c.id?-1:d.id>c.id?1:0),connectors:s.filter(d=>d.opacity>0).sort((d,c)=>d.id<c.id?-1:d.id>c.id?1:0),width:ye(e.width,t.width,r),height:ye(e.height,t.height,r),t:r,...Dr(e.city,t.city,r)?{city:Dr(e.city,t.city,r)}:{}}}function Dr(e,t,n){return e?t?{cell:ye(e.cell,t.cell,n),...e.tilt!==void 0||t.tilt!==void 0?{tilt:ye(e.tilt??.5,t.tilt??.5,n)}:{},originX:ye(e.originX,t.originX,n),originY:ye(e.originY,t.originY,n),pan:{x:ye(e.pan.x,t.pan.x,n),y:ye(e.pan.y,t.pan.y,n)},extent:{x:ye(e.extent.x,t.extent.x,n),y:ye(e.extent.y,t.extent.y,n),width:ye(e.extent.width,t.extent.width,n),height:ye(e.extent.height,t.extent.height,n)}}:e:t}function Io(e,t,n,r){return{id:t.id,kind:t.kind,plane:ye(e.plane,t.plane,n),x:ye(e.x,t.x,n),y:ye(e.y,t.y,n),width:ye(e.width,t.width,n),height:ye(e.height,t.height,n),pinned:t.pinned,opacity:r,...t.aggregate?{aggregate:t.aggregate}:{},...t.via?{via:t.via}:{},...t.raised?{raised:!0}:{},...t.focused?{focused:!0}:{},...t.opened?{opened:!0}:{},...t.openedRows!==void 0?{openedRows:t.openedRows}:{},...t.compact?{compact:!0}:{},...t.rank?{rank:t.rank}:{},...t.nestedUnder?{nestedUnder:t.nestedUnder}:{},...t.beyond?{beyond:t.beyond}:{},...t.plot?{plot:t.plot}:{},...t.nameplate?{nameplate:t.nameplate}:{},...t.states?{states:t.states}:{},...t.screenOf?{screenOf:t.screenOf}:{},...t.depth===void 0?{}:{depth:ye(e.depth??1,t.depth,n)},...t.natural?{natural:t.natural}:{}}}function ta(e,t,n){return{...t,x1:ye(e.x1,t.x1,n),y1:ye(e.y1,t.y1,n),x2:ye(e.x2,t.x2,n),y2:ye(e.y2,t.y2,n)}}function Nn(e){let t=Math.max(0,Math.min(1,e));return t<.5?4*t*t*t:1-(-2*t+2)**3/2}function na(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 oa(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 ra(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 ia(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 aa(e,t){let{room:n,height:r,size:o,floor:a,measure:i=ho,lines:l=2}=t,u=(f,p)=>f.every(b=>i(b,p)<=n)&&f.length*p*1.15<=r;if(u([e],o))return{lines:[e],fontSize:o,whole:!0};let s=e.split(/\s+/);if(l>1&&s.length>1){let f=1,p=1/0,b=0;for(let O=0;O<s.length-1;O+=1){b+=s[O].length+1;let I=Math.abs(b-e.length/2);I<p&&(p=I,f=O+1)}let g=[s.slice(0,f).join(" "),s.slice(f).join(" ")];if(u(g,o))return{lines:g,fontSize:o,whole:!0};for(let O=o;O>=a;O-=o*.06)if(u(g,O))return{lines:g,fontSize:O,whole:!0}}for(let f=o;f>=a;f-=o*.06)if(u([e],f))return{lines:[e],fontSize:f,whole:!0};let d=i(e,a)/Math.max(1,e.length),c=Math.floor(n/d)-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 sa=(e,t)=>e.x0<t.x1&&t.x0<e.x1&&e.y0<t.y1&&t.y0<e.y1;var J=se(Te(),1);var $e=se(Te(),1);var da=520;function la(){return typeof window>"u"||!window.matchMedia?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches}function Br(e,t={}){let n=t.duration??da,r=(t.enabled??!0)&&!la(),o=(0,$e.useRef)(e),[a,i]=(0,$e.useState)(()=>Pt(e,e,1)),l=(0,$e.useRef)(a),u=(0,$e.useRef)(null),s=(0,$e.useRef)(null);return(0,$e.useEffect)(()=>{if(!r||typeof requestAnimationFrame>"u"){o.current=e;let p=Pt(e,e,1);if(l.current=p,i(p),typeof requestAnimationFrame>"u")return;let b=requestAnimationFrame(()=>{let g=Pt(e,e,1);l.current=g,i(g)});return()=>cancelAnimationFrame(b)}let d=performance.now(),h=s.current!==null&&l.current.t<1&&d-s.current<n?s.current:d;s.current=h;let y=Nn(Math.min(1,(d-h)/n)),x=o.current,f=p=>{let b=Math.min(1,(p-h)/n),g=y>=1?1:(Nn(b)-y)/(1-y),O=Pt(x,e,Math.max(0,g));l.current=O,i(O),b<1?u.current=requestAnimationFrame(f):(s.current=null,o.current=e,u.current=requestAnimationFrame(()=>{let I=Pt(e,e,1);l.current=I,i(I),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(b=>({...b,plane:Math.round(b.plane)})),connectors:p.connectors}}},[e,n,r]),a}function Fr(e=1100){let{store:t}=ge(),[n,r]=(0,$e.useState)(()=>new Set);return(0,$e.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 ca={marks:new Map,acts:[]};function jr(e=4e3){let{store:t}=ge(),[n,r]=(0,$e.useState)(ca);return(0,$e.useEffect)(()=>{let o=null,a=t.subscribe((i,l)=>{r(u=>{let s=new Map(u.marks),d=[...u.acts];for(let c of l){if(c.undoes!==void 0){let x=d.find(p=>p.batch===c.undoes||p.wrote.length>0),f=d.filter(p=>c.writes.some(b=>p.wrote.includes(b)));for(let p of f.length>0?f:x?[x]:[]){for(let b of p.wrote)s.delete(b);d=d.filter(b=>b.batch!==p.batch)}continue}if(c.author.kind!=="agent")continue;let h=c.author.id??"the seat";for(let x of c.writes)s.set(x,h);d.find(x=>x.batch===c.batch)?d=d.map(x=>x.batch===c.batch?{...x,wrote:[...new Set([...x.wrote,...c.writes])]}:x):d=[{batch:c.batch,who:h,intent:c.batchIntent??c.intent,at:c.at,wrote:[...c.writes]},...d].slice(0,12)}return s.size===u.marks.size&&d===u.acts&&s.size===0?u:{marks:s,acts:d}}),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 Nt=se(Oe(),1),_e=16;function Wr({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[d,c]of e){let h=null;if(i&&l&&typeof CSS<"u"){let p=i.querySelector(`[data-graview-pick="${CSS.escape(d)}"]`)?.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(d),!h)continue;let y=Math.min(Math.max(h.x+h.width-_e/2,_e/2),o-_e/2),x=Math.min(Math.max(h.y-_e/4,_e/2),a-_e/2);u.push({id:d,who:c,x:y,y:x})}let s=[];for(let d of t){let c=n(d.id);c&&s.push({...d,x:Math.min(Math.max(c.x+c.width/2,_e),o-_e),y:Math.min(Math.max(c.y-_e/2,_e),a-_e)})}return u.length===0&&s.length===0?null:(0,Nt.jsxs)("div",{className:"graview-seat-marks","data-testid":"seat-marks","data-graview-seat-marks":u.length,children:[u.map(({id:d,who:c,x:h,y})=>(0,Nt.jsx)("span",{className:"graview-seat-mark","data-testid":"seat-mark","data-graview-seat-mark":d,"data-graview-seat-who":c,title:`${c} just changed this`,"aria-hidden":"true",style:{left:h,top:y,"--graview-hue":Zt(c)},children:"\u25C6"},d)),s.map(d=>(0,Nt.jsxs)("span",{className:"graview-seat-asking","data-testid":"seat-question","data-graview-seat-asking":d.id,title:d.asks,style:{left:d.x,top:d.y},children:[(0,Nt.jsx)("span",{"aria-hidden":"true",children:"?"}),(0,Nt.jsx)("span",{className:"graview-seat-asking-said",children:d.asks})]},`asking:${d.id}`))]})}var Q=se(Oe(),1);function ua({hue:e,mode:t}){let n=t==="docked";return(0,Q.jsxs)("svg",{viewBox:"0 0 32 38","aria-hidden":"true",children:[(0,Q.jsxs)("g",{fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinejoin:"round",strokeLinecap:"round",children:[(0,Q.jsx)("line",{x1:"16",y1:"3.5",x2:"16",y2:"7"}),(0,Q.jsx)("circle",{cx:"16",cy:"2.6",r:"1.5",fill:"none"}),(0,Q.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,Q.jsx)("line",{x1:"11",y1:"12.5",x2:"21",y2:"12.5",strokeWidth:"2"}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.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,Q.jsx)("circle",{cx:"13.4",cy:"12.5",r:"1.25",fill:"currentColor",stroke:"none",opacity:n?.45:1}),(0,Q.jsx)("circle",{cx:"18.6",cy:"12.5",r:"1.25",fill:"currentColor",stroke:"none",opacity:n?.45:1}),t==="reading"?(0,Q.jsx)("line",{x1:"10.2",y1:"12.5",x2:"21.8",y2:"12.5",strokeWidth:"0.8",opacity:"0.7"}):null]}),(0,Q.jsx)("line",{x1:"16",y1:"16",x2:"16",y2:"18.5"}),(0,Q.jsx)("polygon",{points:"16,18.5 24,22.5 16,26.5 8,22.5",fill:"currentColor",fillOpacity:"0.22"}),(0,Q.jsx)("polygon",{points:"8,22.5 16,26.5 16,33.5 8,29.5",fill:"currentColor",fillOpacity:"0.08"}),(0,Q.jsx)("polygon",{points:"24,22.5 16,26.5 16,33.5 24,29.5",fill:"currentColor",fillOpacity:"0.3"}),t==="writing"?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)("polyline",{points:"24,24 28.5,20.5"}),(0,Q.jsx)("line",{x1:"27.5",y1:"19",x2:"30",y2:"21.5",strokeWidth:"1.8"})]}):(0,Q.jsx)("line",{x1:"24",y1:"24",x2:"26.5",y2:"29"}),(0,Q.jsx)("line",{x1:"8",y1:"24",x2:"5.5",y2:"29"}),(0,Q.jsx)("path",{d:"M9.5 33.5 v2.2 h4"}),(0,Q.jsx)("path",{d:"M22.5 33.5 v2.2 h-4"})]}),(0,Q.jsx)("title",{children:`robot, ${t}`})]})}function ha({hue:e}){return(0,Q.jsxs)("svg",{viewBox:"0 0 22 24","aria-hidden":"true",style:{color:`hsl(${Math.round(e)} 50% 48%)`},children:[(0,Q.jsxs)("g",{fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinejoin:"round",strokeLinecap:"round",children:[(0,Q.jsx)("circle",{cx:"11",cy:"6",r:"4.2"}),(0,Q.jsx)("path",{d:"M3 23 C3 15.5 6 13 11 13 C16 13 19 15.5 19 23"})]}),(0,Q.jsx)("title",{children:"somebody"})]})}function Vr({width:e,whereIs:t}){let{who:n,following:r,follow:o}=ge(),a=mr([...n.values()],t,e);return a.length===0?null:(0,Q.jsx)("div",{className:"graview-occupants","data-testid":"occupants","data-graview-occupants":a.length,children:a.map((i,l)=>{if(i.kind==="over")return(0,Q.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,Q.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,s=er(i.presence)||"somebody";if(i.kind==="edge")return(0,Q.jsxs)("button",{type:"button",className:"graview-figure-edge","data-testid":"presence-edge","data-graview-person":i.presence.participant,style:{left:Math.max(8,i.point.x-120),top:i.point.y},onClick:()=>o(i.presence.participant),"aria-label":`${s} is somewhere else \u2014 press to go where they are`,children:["\u2192 ",s]},`edge:${i.presence.participant}`);if(i.kind==="robot")return(0,Q.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,Q.jsx)("span",{className:"graview-figure-body",role:"img","aria-label":`${s}'s agent \u2014 ${i.mode}`,style:{cursor:"default"},children:(0,Q.jsx)(ua,{hue:u,mode:i.mode})}),(0,Q.jsxs)("span",{className:"graview-figure-name",children:[s,"'s agent"]})]},`robot:${i.presence.participant}`);let d=r?.participant===i.presence.participant;return(0,Q.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":d?"":void 0,style:{transform:`translate(${i.point.x.toFixed(1)}px, ${i.point.y.toFixed(1)}px)`,"--graview-hue":u},children:[(0,Q.jsx)("button",{type:"button",className:"graview-figure-body","aria-label":`${s} is here${d?". Press to stop following":". Press to go where they go"}`,"aria-pressed":d,onClick:c=>{c.stopPropagation(),o(d?null:i.presence.participant)},onPointerDown:c=>c.stopPropagation(),children:(0,Q.jsx)(ha,{hue:u})}),(0,Q.jsx)("span",{className:"graview-figure-name",children:s})]},`person:${i.presence.participant}`)})})}var ln=se(Oe(),1),Yr={left:"\u2190",right:"\u2192",top:"\u2191",bottom:"\u2193"},Tn=36,$n=56;function zr({result:e,schema:t,onGo:n}){let r=Ro(e);if(r.length===0)return null;let o=(e.city?.showings??[]).flatMap(i=>{let l=e.nodes.find(u=>u.id===i.id);return l?[{left:l.x+i.x,top:l.y+i.y,right:l.x+i.x+i.width,bottom:l.y+i.y+i.height}]:[]}),a=[];for(let i of["left","right","top","bottom"]){let l=e.visible??e,u=i==="left"||i==="right"?l.height:l.width,s=-1/0,d=r.filter(c=>c.side===i).sort((c,h)=>c.along-h.along);for(let c of d){let h=Wt(t,c.kind),{at:y,inset:x}=ma(o,i,Math.max($n,Math.min(u-$n,Math.max(c.along,s+Tn))),fa(h),l,u);s=y;let f=i==="left"?{left:x,top:y,transform:"translateY(-50%)"}:i==="right"?{right:`calc(${x}px + var(--graview-dock, 0px))`,top:y,transform:"translateY(-50%)"}:i==="top"?{top:x,left:y,transform:"translateX(-50%)"}:{bottom:`calc(${x}px + var(--graview-sheet, 0px))`,left:y,transform:"translateX(-50%)"};a.push((0,ln.jsx)("button",{type:"button",className:"graview-edge-sign","data-graview-past-edge":c.id,"aria-label":`${h}, past the ${i} edge \u2014 bring it into view`,title:`${h} is past the ${i} edge`,tabIndex:-1,onPointerDown:p=>p.stopPropagation(),onClick:p=>{p.stopPropagation(),n(c.by)},style:{...ga,...f},children:i==="right"||i==="bottom"?`${h} ${Yr[i]}`:`${Yr[i]} ${h}`},c.id))}}return(0,ln.jsx)(ln.Fragment,{children:a})}var fa=e=>(e.length+2)*7.4+22,Co=Tn/2,je=6;function ma(e,t,n,r,o,a){let i=t==="left"||t==="right",l=x=>i?{left:t==="left"?je:o.width-je-r,right:t==="left"?je+r:o.width-je,top:x-Co,bottom:x+Co}:{left:x-r/2,right:x+r/2,top:t==="top"?je:o.height-je-Tn,bottom:t==="top"?je+Tn:o.height-je},u=x=>e.find(f=>{let p=l(x);return p.left<f.right&&f.left<p.right&&p.top<f.bottom&&f.top<p.bottom}),s=u(n);if(!s)return{at:n,inset:je};let d=i?Co:r/2,c=(i?s.bottom:s.right)+d+4,h=(i?s.top:s.left)-d-4;if(c<=a-$n&&!u(c))return{at:c,inset:je};if(h>=$n&&!u(h))return{at:h,inset:je};let y=t==="left"?s.right:t==="right"?o.width-s.left:t==="top"?s.bottom:o.height-s.top;return{at:n,inset:Math.max(je,y+4)}}var ga={position:"absolute",zIndex:Ie.lines,minHeight:28,maxWidth:"40%",padding:"3px 10px",font:"inherit",fontSize:"0.75rem",letterSpacing:"0.04em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",color:"var(--graview-ink)",background:"var(--graview-panel)",border:"1px solid var(--graview-edge)",borderRadius:6,boxShadow:"0 2px 8px rgb(0 0 0 / 0.12)",cursor:"pointer"};var gt=se(Te(),1),ya=180;function _r({view:e,result:t,frame:n,panned:r,closer:o,screenId:a,setCamera:i}){let l=(0,gt.useRef)(new Map),u=Math.round((t.nodes.find(c=>c.id===a)?.height??0)/16),s=(0,gt.useRef)(e.overview??!1),d=(0,gt.useRef)(null);if((0,gt.useEffect)(()=>{if(!e.overview||!a||!t.city){if(s.current&&!e.overview)return;i(C=>C.x===0&&C.y===0?C:{x:0,y:0});return}let c=t.nodes.find(C=>C.id===a);if(!c)return;let h=o>1&&c.screenOf?t.nodes.find(C=>C.id===be(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=(C,Z,q)=>C<f?f-C:C+Z>q-f?q-f-(C+Z):0,b=mt(t),g=e.pan??{x:0,y:0},O=h?r.x+(t.width/2-(y.x+y.width/2)):r.x+p(y.x,y.width,t.width),I=t.height/2-(y.y+y.height/2),L=h?r.y+(c.y+I<f?f-c.y:I):r.y+p(y.y,y.height,t.height);i({x:(h?O:Math.max(-b.x,Math.min(b.x,O)))-g.x,y:(h?L:Math.max(-b.y,Math.min(b.y,L)))-g.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=Ut(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,gt.useEffect)(()=>{let c=e.overview??!1,h=s.current&&!c;if(s.current=c,c&&d.current&&(clearTimeout(d.current),d.current=null),!h)return;let y=e.focusId?ht(e.focusId)[0]:void 0,x=y?l.current.get(be(y)):void 0,f=t.nodes.find(p=>p.id===e.focusId);if(!x||!f){i({x:0,y:0});return}i({x:x.x-(f.x+f.width/2),y:x.y-(f.y+f.height/2)}),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{d.current=null,i({x:0,y:0})},ya)},[e.overview]),(0,gt.useEffect)(()=>()=>{d.current&&clearTimeout(d.current)},[]),{gliding:()=>d.current!==null}}var Dn=se(Te(),1),Hn="[data-graview-view]";function pa(e,t){let n=null;for(let r=e?.closest(Hn)??null;r&&t.contains(r);r=r.parentElement?.closest(Hn)??null)n=r;return n}function Gr(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 Kr(e,t,n){let r=(0,Dn.useRef)({dock:t,reveal:n});r.current={dock:t,reveal:n},(0,Dn.useEffect)(()=>{let o=e.current;if(!o)return;let a=u=>{let{dock:s}=r.current;if(u.key!=="Tab"||u.defaultPrevented||s.right<=0&&s.bottom<=0)return;let d=Gr(o,s),c=[];for(let h of o.querySelectorAll(Hn)){if(h.parentElement?.closest(Hn)||h.inert||h.contains(document.activeElement))continue;let y=h.getBoundingClientRect(),x=Math.max(y.left,d.box.left),f=Math.min(y.right,d.box.right),p=Math.max(y.top,d.box.top),b=Math.min(y.bottom,d.box.bottom);f<=x||b<=p||!(s.right>0&&x>=d.right-1||s.bottom>0&&p>=d.bottom-1)||(h.inert=!0,c.push(h))}c.length!==0&&setTimeout(()=>{for(let h of c)h.inert=!1},0)},i=u=>{let s=u.target,d=pa(s,o);if(!d)return;let c=!0;try{c=s?.matches(":focus-visible")??!0}catch{}requestAnimationFrame(()=>{for(let h=d.parentElement;h;h=h===o?null:h.parentElement)h.scrollTop!==0&&(h.scrollTop=0),h.scrollLeft!==0&&(h.scrollLeft=0);c&&d.isConnected&&l(d)})},l=u=>{let s=Gr(o,r.current.dock),d=u.getBoundingClientRect(),c=12,h=(f,p,b,g)=>g-b>p-f-2*c||b<f+c?f+c-b:g>p-c?p-c-g:0,y=h(s.left,s.right,d.left,d.right),x=h(s.top,s.bottom,d.top,d.bottom);(Math.abs(y)>=1||Math.abs(x)>=1)&&r.current.reveal(Math.round(y),Math.round(x))};return document.addEventListener("keydown",a,!0),o.addEventListener("focusin",i),()=>{document.removeEventListener("keydown",a,!0),o.removeEventListener("focusin",i)}},[e])}var ie=se(Te(),1);function Ur(){let e=(0,ie.useRef)(null),[t,n]=(0,ie.useState)({right:0,bottom:0});return(0,ie.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 Xr(){let[e,t]=(0,ie.useState)(null),n=(0,ie.useRef)(null),r=(0,ie.useRef)(0),o=(0,ie.useCallback)(i=>{n.current=i,r.current===0&&(r.current=requestAnimationFrame(()=>{r.current=0,t(n.current)}))},[]),a=(0,ie.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 qr({stage:e,pan:t,setView:n,settled:r}){let o=(0,ie.useRef)({x:0,y:0}),a=(0,ie.useRef)(0),i=(0,ie.useRef)(!1),l=(0,ie.useRef)(r);l.current=r;let u=(0,ie.useCallback)(()=>[...e.current?.querySelectorAll("[data-graview-world]")??[]],[e]),s=(0,ie.useCallback)(()=>{a.current===0&&(a.current=requestAnimationFrame(()=>{a.current=0;let{x,y:f}=o.current,p=x===0&&f===0?"":`translate3d(${x}px, ${f}px, 0)`;for(let b of u())b.style.transform=p}))},[u]),d=(0,ie.useCallback)(()=>{i.current=!1;for(let x of u())x.style.transform="";l.current()},[u]),c=(0,ie.useCallback)((x,f)=>{o.current={x:x.x-f.x,y:x.y-f.y},s()},[s]),h=(0,ie.useCallback)(()=>{let{x,y:f}=o.current;return x===0&&f===0?!1:(o.current={x:0,y:0},i.current=!0,n(p=>{let b=p.pan??{x:0,y:0};return Lt(p,{x:b.x+x,y:b.y+f})}),window.setTimeout(()=>{i.current&&d()},300),!0)},[n,d]);(0,ie.useLayoutEffect)(()=>{i.current&&d()},[t,d]);let y=(0,ie.useCallback)(()=>o.current,[]);return{shiftTo:c,settle:h,settling:i,offset:y}}var xa=4;function Qr({view:e,panned:t,limit:n,panWithin:r,moveByTransform:o,setView:a,setDragging:i,noteMoved:l,shift:u,district:s}){let d=(0,ie.useRef)(!1),c=(0,ie.useRef)(null),h=b=>{let g=e.pan??{x:0,y:0};c.current={kind:"pan",fromX:b.clientX,fromY:b.clientY,baseX:g.x,baseY:g.y,moved:!1}};return{onGroundDown:b=>{b.button===0&&(b.target.closest("[data-graview-view]")||h(b))},onCardDown:(b,g)=>{if(g.button===0){if(b.screenOf!==void 0&&!g.target.closest("[data-graview-grip]")){h(g);return}if(e.overview&&Re(b.id)!==null){h(g);return}c.current={kind:"card",id:b.id,fromX:g.clientX,fromY:g.clientY,baseX:b.x-t.x,baseY:b.y-t.y,moved:!1}}},onDragMove:b=>{let g=c.current;if(!g)return;let O=b.clientX-g.fromX,I=b.clientY-g.fromY;if(!g.moved){if(Math.hypot(O,I)<xa)return;g.moved=!0,i(!0),b.currentTarget.setPointerCapture(b.pointerId)}if(g.kind==="pan"){let L=r(n(),{x:g.baseX+O,y:g.baseY+I});o?u.shiftTo(L,e.pan??{x:0,y:0}):a(C=>Lt(C,L))}else g.id&&s.place({id:g.id,x:g.baseX+O,y:g.baseY+I})},onDragUp:()=>{u.settle();let b=s.release();b&&a(g=>an(g,b.id,{x:b.x,y:b.y})),c.current?.moved&&(d.current=!0,setTimeout(()=>d.current=!1,0),l()),c.current=null,!u.settling.current&&i(!1)},swallow:d}}function Zr({stage:e,view:t,setView:n}){let r=(0,ie.useRef)({view:t,charge:0,coolUntil:0,lastScale:1});r.current.view=t;let o=(0,ie.useRef)(()=>{}),a=(0,ie.useRef)(()=>{});return(0,ie.useEffect)(()=>{let i=e.current;if(!i)return;let l=(c,h)=>{let y=r.current;if(h<y.coolUntil)return;let x=y.view.overview??!1;c!==x&&(y.coolUntil=h+600,y.charge=0,n(en(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))},s=c=>{c.preventDefault(),r.current.lastScale=1},d=c=>{c.preventDefault();let h=r.current,y=c.scale??1;if(!(h.view.overview??!1)){y<.72&&l(!0,performance.now());return}let x=y/(h.lastScale||1);h.lastScale=y;let f=c;o.current(x,f.clientX,f.clientY)};return i.addEventListener("wheel",u,{passive:!1}),i.addEventListener("gesturestart",s),i.addEventListener("gesturechange",d),()=>{i.removeEventListener("wheel",u),i.removeEventListener("gesturestart",s),i.removeEventListener("gesturechange",d)}},[n,e]),{zoomAbout:o,panBy:a}}var Jr={directed:"You",autonomous:"An agent","co-edited":"You and an agent",rule:"A rule"};function Po(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 No(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 To(e){return e.edgeChosen?.9:e.lit?.78:e.own*(e.anyLit?e.kit.dim:e.kit.rest)}function Ze(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?ze(n,t):En(ze(n,t),ze(r,t),e.plane-n);return{x:e.x,y:e.y,width:e.width*o,height:e.height*o}}function cn(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 s=getComputedStyle(l);if(s.overflowX!=="visible"||s.overflowY!=="visible"){let d=l.getBoundingClientRect();s.overflowX!=="visible"&&(n=Math.max(n,d.left),o=Math.min(o,d.right)),s.overflowY!=="visible"&&(r=Math.max(r,d.top),a=Math.min(a,d.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 He(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 cn(a,e)}function Bn(e,t,n,r,o){let a=s=>e.nodes.find(d=>d.id===s);if(o.startsWith("screen:")){let s=e.nodes.find(d=>d.id===be(o.slice(7)));return s?He(t,s.id,!0)??Ze(s,n):null}let i=a(o),l=Re(o);if(!i&&l!==null&&(i=a(Ee(l))),!i&&St(o)){let[s]=ht(o);s&&(i=a(be(s)))}if(!i){let s=r.places().find(d=>d.as===o);s&&(i=a(Ee(s.kind))??a(be(s.kind)))}if(i||(i=[...e.nodes].filter(s=>s.aggregate?.memberIds.includes(o)).sort((s,d)=>s.plane-d.plane)[0]),!i)return null;let u=e.city!==void 0;return He(t,i.id,u&&i.aggregate!==void 0&&Math.round(i.plane)===2)??Ze(i,n)}var rt=se(Te(),1);var ae=se(Oe(),1);function ti({kinds:e}){let{store:t}=ge(),{view:n,go:r}=so(),o=(0,rt.useRef)(null),a=co("districts",{align:"start"}),i=a.open,l=h=>Wt(t.schema,h),u=h=>t.graph.allNodes().filter(y=>y.kind===h).length,s=h=>!n.overview&&n.focusId===Ee(h),d=e.filter(h=>!s(h)),c=h=>{a.setOpen(!1);let y=o.current?.querySelector(".graview-beyond-more")??null;s(h)||r(ut(n,Ee(h))),y?.focus({preventScroll:!0});let x=`[data-graview-view="${Ee(h)}"][tabindex], [data-graview-view="${be(h)}"][tabindex]`,f=40,p=()=>{let b=document.querySelector(x);b?b.focus({preventScroll:!0}):--f>0&&requestAnimationFrame(p)};requestAnimationFrame(p)};return(0,ae.jsxs)("div",{ref:o,className:"graview-beyond","data-graview-beyond":e.length,"data-graview-beyond-open":i?"":void 0,children:[(0,ae.jsxs)("button",{type:"button",className:"graview-beyond-more","data-testid":"beyond-more",...a.trigger,"aria-haspopup":"menu",title:`${d.length} more district${d.length===1?"":"s"} \u2014 press to see them`,onPointerDown:h=>h.stopPropagation(),onClick:h=>{h.stopPropagation(),a.toggle()},children:[(0,ae.jsxs)("span",{className:"graview-beyond-count",children:["+",d.length]}),(0,ae.jsx)("span",{className:"graview-beyond-word",children:"more"}),(0,ae.jsx)("span",{className:"graview-beyond-chevron","aria-hidden":"true",children:i?"\u25BE":"\u25B4"})]}),i?(0,ae.jsx)("ul",{...a.pane,className:"graview-beyond-list",role:"menu","aria-label":"The other districts","data-testid":"beyond-list",style:lo,onPointerDown:h=>h.stopPropagation(),children:e.map(h=>(0,ae.jsx)("li",{role:"none",children:(0,ae.jsxs)("button",{type:"button",role:"menuitem","data-graview-pick":be(h),"aria-current":s(h)?"location":void 0,title:s(h)?`${l(h)} \u2014 where you are`:`Go to ${l(h)}`,onPointerDown:y=>y.stopPropagation(),onClick:y=>{y.stopPropagation(),c(h)},children:[(0,ae.jsx)("span",{className:"graview-beyond-name",children:l(h)}),(0,ae.jsx)("span",{className:"graview-beyond-tally",children:s(h)?"here":u(h)})]})},h))}):null]})}function ba(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"||Ho(e[r],t[r]))}function Ho(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(!Ho(e[a],o[a]))return!1;return!0}let r=Object.keys(e);return r.length!==Object.keys(t).length?!1:r.every(o=>Ho(e[o],t[o]))}var ni=(0,rt.memo)(oi,(e,t)=>e.mode===t.mode&&e.selected===t.selected&&e.fidelity===t.fidelity&&ba(e.node,t.node));function oi({node:e,mode:t,selected:n,fidelity:r}){let{store:o,views:a,view:i}=ge(),l=Rt(),u=fr(),s=hr(),d=e.aggregate||St(e.id)||Re(e.id)!==null?"many":"one",c={cardinality:d,fidelity:r??ir[va(e.plane)].fidelity},h=d==="many"&&e.id===i.focusId?i.within?.view:void 0,y=a.resolve(e.kind,c,h),x=y?.view,f=a.resolve(e.kind,{cardinality:"many",fidelity:"full"})?.view,p=f!==void 0&&f.generic!==!0,b=e.aggregate?.memberIds,g=(0,rt.useMemo)(()=>(b??[]).map(L=>o.graph.getNode(L)).filter(L=>L!==void 0),[b,o,l]),O={...e.aggregate?{nodes:g,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:s,...e.raised?{raised:!0}:{},...e.focused?{focused:!0}:{},...e.opened?{opened:!0}:{},...e.openedRows!==void 0?{openedRows:e.openedRows}:{},...e.plot?{plot:e.plot}:{},...e.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(!x)return(0,ae.jsx)(ka,{node:e,props:O});let I=[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(L=>L.count).join(","):"",e.aggregate?$o(e.aggregate.memberIds):"",e.aggregate?.retired??"",u?$o(u):"",s?$o(s):"",p].join("|");return(0,ae.jsx)(ro,{mode:t,children:(0,ae.jsx)(gr,{kind:O.label??e.kind,...y?.title?{view:y.title}:{},children:(0,ae.jsx)(wa,{signature:I,graph:l,draw:()=>(0,ae.jsx)(x,{...O})})},`${e.id}|${y?.title??""}`)})}var wa=(0,rt.memo)(function({draw:t}){return(0,ae.jsx)(ae.Fragment,{children:t()})},(e,t)=>e.signature===t.signature&&e.graph===t.graph);function va(e){return Math.max(0,Math.min(2,Math.round(e)))}function ka({node:e,props:t}){return(0,ae.jsxs)("div",{style:{padding:8,font:"13px/1.4 system-ui",overflow:"hidden"},children:[(0,ae.jsx)("strong",{children:t.label??e.kind}),t.nodes?(0,ae.jsxs)("div",{children:[t.nodes.length," items"]}):(0,ae.jsx)("div",{children:e.id})]})}var ri=(0,rt.memo)(function({node:t}){let{store:n}=ge(),r=Mt(),o=t.aggregate,a=o.opens,i=o.memberIds.length,l=jt(n.schema,o.kind,i),u=o.memberIds.slice(0,3).map(h=>{let y=n.graph.getNode(h),x=y?n.schema.tryDefinition(y.kind):void 0;return y?x?.label?x.label(y):String(y.label??h):h}),s=o.memberIds,d=(0,rt.useMemo)(()=>{let h=r?Rn(r):null;return h?s.filter(y=>h.has(y)).length:0},[r,s]),c=a.in==="picture";return(0,ae.jsxs)("div",{className:"graview-band-group","data-graview-band":a.in,"data-graview-band-count":i,"data-graview-emphasis":r?d>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,ae.jsxs)("span",{className:"graview-band-group-head",children:[(0,ae.jsx)("span",{className:"graview-band-group-name",children:o.label}),(0,ae.jsx)("span",{className:"graview-band-group-open","aria-hidden":"true",children:c?"\u2197":"\u25BE"})]}),(0,ae.jsxs)("span",{className:"graview-band-group-names",children:[c?null:(0,ae.jsxs)("span",{className:"graview-band-group-count",children:[l,d>0?` \xB7 ${d} match`:""," \xB7 "]}),u.join(" \xB7 "),i>u.length?" \u2026":""]})]})}),ei=new WeakMap;function $o(e){let t=ei.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 ei.set(e,r),r}var yt=se(Te(),1);function Do(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 ii(){let[e,t]=(0,yt.useState)(16);return(0,yt.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 ai(e){let[t,n]=(0,yt.useState)(null);return(0,yt.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,yt.useEffect)(()=>{let r=e.current;if(!r||typeof ResizeObserver>"u")return;let o=l=>{!l||l.width===0||l.height===0||n(u=>{let s={width:Math.round(l.width),height:Math.round(l.height)};return u&&u.width===s.width&&u.height===s.height?u:s})},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 si(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 di(e){return`matrix3d(${e.join(",")})`}var pe=se(Te(),1);var Bo=(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 Fo(e,t){let n=[],r=[];for(let a=0;a<e.length-1;a++){let i=e[a],l=e[a+1],u=!Bo(i,t);u&&r.length===0&&r.push(i);for(let s=1;s<=48;s++){let d=s/48,c={x:i.x+(l.x-i.x)*d,y:i.y+(l.y-i.y)*d},h=!Bo(c,t);if(h===u)continue;let y=(s-1)/48,x=d;for(let b=0;b<10;b++){let g=(y+x)/2,O={x:i.x+(l.x-i.x)*g,y:i.y+(l.y-i.y)*g};!Bo(O,t)===u?y=g:x=g}let f=(y+x)/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 un(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 We=e=>Math.round(e*100)/100,Tt=e=>e.map(t=>t.map((n,r)=>`${r===0?"M":"L"} ${We(n.x)} ${We(n.y)}`).join(" ")).join(" ");function Fn(e,t){if(e.length<3)return Tt([e]);let n=[`M ${We(e[0].x)} ${We(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),s=Math.hypot(l.x-i.x,l.y-i.y),d=Math.min(t,u/2,s/2),c={x:i.x+(a.x-i.x)/(u||1)*d,y:i.y+(a.y-i.y)/(u||1)*d},h={x:i.x+(l.x-i.x)/(s||1)*d,y:i.y+(l.y-i.y)/(s||1)*d};n.push(`L ${We(c.x)} ${We(c.y)} Q ${We(i.x)} ${We(i.y)} ${We(h.x)} ${We(h.y)}`)}let r=e[e.length-1];return n.push(`L ${We(r.x)} ${We(r.y)}`),n.join(" ")}function li(e,t,n){if(e==="orthogonal"){let l=un(t.p0,t.p1),u=l.slice(1).map((c,h)=>Math.hypot(c.x-l[h].x,c.y-l[h].y)),s=u.reduce((c,h)=>c+h,0)||1,d=n*s;for(let c=0;c<u.length;c++){let h=u[c];if(d<=h||c===u.length-1){let y=h===0?0:Math.min(1,d/h),x=l[c],f=l[c+1];return{x:x.x+(f.x-x.x)*y,y:x.y+(f.y-x.y)*y}}d-=h}return t.p1}let r=e==="straight"?{x:(t.p0.x+t.p1.x)/2,y:(t.p0.y+t.p1.y)/2}:t.c,o=(1-n)*(1-n),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 jn(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 ci(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 ui(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 hn=(e,t)=>e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height,Wo=(e,t)=>e.findIndex(n=>n.boxes.some(r=>hn(r,t)));function hi(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 Yo(e,t){let n=[{from:-1/0,to:1/0}];for(let a of e){let i=[],l=-1/0;for(let s of a.boxes)i.push({from:l,to:s.x-12}),l=Math.max(l,s.x+s.width+12);i.push({from:l,to:1/0});let u=[];for(let s of n)for(let d of i){let c=Math.max(s.from,d.from),h=Math.min(s.to,d.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 Ge=e=>({x:e.x,y:-(e.y+e.height),width:e.width,height:e.height}),Wn=e=>e.map(t=>({x:t.x,y:-t.y}));function Vo(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 zo(e,t,n){let r=e.boxes.filter(s=>!hn(s,t)&&s.y+s.height<=t.y+1&&s.x<t.x+t.width&&s.x+s.width>t.x),o=[{from:t.x+6,to:t.x+t.width-6}];for(let s of r)o=o.flatMap(d=>[{from:d.from,to:Math.min(d.to,s.x-12/2)},{from:Math.max(d.from,s.x+s.width+12/2),to:d.to}]).filter(d=>d.to>=d.from);let a=null;for(let s of o){let d=Math.min(Math.max(n,s.from),s.to);(a===null||Math.abs(d-n)<Math.abs(a-n))&&(a=d)}if(a!==null)return{x:a,tail:[{x:a,y:t.y}]};let i=n<t.x+t.width/2,l=Yo([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 jo(e,t,n){let r=zo({top:-e.bottom,bottom:-e.top,boxes:e.boxes.map(Ge)},Ge(t),n);return{x:r.x,head:Wn(r.tail).reverse()}}function fi(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 mi=(e,t)=>(e%3-1)*Math.max(0,Math.min(4,t/2-3));function gi(e,t,n,r,o,a,i,l){let u=f=>f<0?e[0].top-n:e[f+1].top-e[f].bottom,s=f=>(f<0?(n+e[0].top)/2:hi(e,f,f+1))+mi(l,u(f)),d=zo(e[a],o,i),c=fi(e,a,d.x,t+1),h=s(t);if(c===t+1)return Vo([...r.head,{x:r.x,y:h},{x:d.x,y:h},...d.tail]);let y=Yo(e.slice(t+1,c),d.x),x=s(c-1);return Vo([...r.head,{x:r.x,y:h},{x:y,y:h},{x:y,y:x},{x:d.x,y:x},...d.tail])}function Xt(e,t,n,r=0){let o=ui(n.some(d=>hn(d,e))&&n.some(d=>hn(d,t))?n:[...n,e,t]),a=Wo(o,e),i=Wo(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 Wn(Xt(Ge(e),Ge(t),n.map(Ge),r));let c=hi(o,a,a+1)+mi(r,a<o.length-1?o[a+1].top-o[a].bottom:2*12),h=jo(o[a],e,u),y=jo(o[a],t,l);return Vo([...h.head,{x:h.x,y:c},{x:y.x,y:c},...[...y.head].reverse()])}if(i<a)return Wn(Xt(Ge(e),Ge(t),n.map(Ge),r));let s=jo(o[a],e,u);return gi(o,a,o[a].bottom,s,t,i,l,r)}function _o(e,t,n,r=0){if(t.y+t.height<=e.y){let y=_o(Ge(e),Ge(t),n.map(Ge),r);return y?Wn(y):null}let o=e.y+e.height;if(t.y<o)return null;let a=ui([...n.filter(y=>y.y>=o&&!hn(y,t)),t]),i=Wo(a,t),l=t.x+t.width/2,u=zo(a[i],t,l),s=fi(a,i,u.x,0),d=s===0?u.x:Yo(a.slice(0,s),u.x),c=Math.min(12,e.width/2),h=Math.min(Math.max(d,e.x+c),e.x+e.width-c);return gi(a,-1,o,{x:h,head:[{x:h,y:o}]},t,i,l,r)}function yi(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 De=se(Oe(),1);function Yn(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 x={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:x,to:f,control:{x:Math.max(x.x,f.x)+18,y:(x.y+f.y)/2},mode:"stacked"}}if(a){let x={x:e.x+e.width/2,y:e.y},f={x:t.x+t.width/2,y:t.y};return{from:x,to:f,control:{x:(x.x+f.x)/2,y:Math.min(x.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=Vn(e,i),s=Vn(t,l),d=Math.hypot(s.x-u.x,s.y-u.y);if(d<8)return null;let c=Math.min(36,d*.12),h=-(s.y-u.y)/d,y=(s.x-u.x)/d;return{from:u,to:s,control:{x:(u.x+s.x)/2+h*c,y:(u.y+s.y)/2+y*c},mode:"direct"}}function Vn(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),s=Math.max(0,u*.98);return{x:n+o*s,y:r+a*s}}function Sa(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 Ma=()=>({clips:new Map,members:new Map,marks:new Map});function xi(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 Ra(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 Ea(e,t,n){let r=e.parentElement;for(;r!==null;){let o=Ra(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 fn(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 u of xi(t,r).get(n)??[]){if(u.closest("[data-graview-offstage]"))continue;let s=u.getBoundingClientRect();s.width<=2||s.height<=2||Ea(u,s,r)&&l.push({x:s.left-i.left,y:s.top-i.top,width:s.width,height:s.height})}return l.sort((u,s)=>u.width*u.height-s.width*s.height),o.set(n,l),l}function zn(e,t,n,r,o){let a=new Map(e.map(g=>[g.id,g])),i=Ma(),l=new Map,u=g=>{if(!n||typeof document>"u")return null;let O=l.get(g);return O===void 0&&(O=n.querySelector(`[data-graview-view="${CSS.escape(g)}"]`),l.set(g,O)),O},s=new Map;for(let g of e){let O=He(n,g.id,r)??Ze(g,o);O&&s.set(g.id,O)}let d=new Map;if(n&&typeof document<"u"){let g=n.getBoundingClientRect();for(let O of n.querySelectorAll("[data-graview-pick], [data-graview-slot]")){if(O.closest("[data-graview-offstage]"))continue;let I=O.getAttribute("data-graview-pick")??O.getAttribute("data-graview-slot");if(I===null)continue;let L=O.getBoundingClientRect();if(L.width<=2||L.height<=2||L.width>g.width*.6&&L.height>g.height*.6)continue;let C=d.get(I),Z={x:L.left-g.left,y:L.top-g.top,width:L.width,height:L.height};C?C.push(Z):d.set(I,[Z])}}let c=(g,O)=>{let I=[];for(let[L,C]of s)L!==g&&L!==O&&I.push(C);for(let[L,C]of d)L!==g&&L!==O&&I.push(...C);return I},h=g=>Math.round(a.get(g)?.plane??-1)===1,y=[];for(let g of e){let O=s.get(g.id);O&&Math.round(g.plane)===1&&y.push(O)}if(!r&&n&&typeof document<"u"){let g=n.getBoundingClientRect();for(let O of n.querySelectorAll("[data-graview-relation] > span")){let I=O.getBoundingClientRect();I.width>0&&I.height>0&&y.push({x:I.left-g.left,y:I.top-g.top,width:I.width,height:I.height})}}let x=(g,O)=>!r&&h(g)&&h(O)?y:void 0,f=r?void 0:e.find(g=>Math.round(g.plane)===0&&!g.aggregate),p=(g,O,I,L)=>{if(!f)return{};let C=g.to===f.id&&I===f.id;if(!C&&!(g.from===f.id&&O===f.id))return{};let Z=C?g.from:g.to,q=s.get(f.id),v=s.get(Z);if(Z===f.id||!h(Z)||!q||!v)return{};let M=u(f.id),w=A=>M!==null&&xi(M,i).get(A)?.some(N=>!N.closest("[data-graview-offstage]"))===!0,E=L.map(A=>A.from===f.id?A.to:A.from),V=E.length>0&&E.every(w);return{band:y,tie:{card:q,chip:v,cardIsTo:C,toward:Z,holds:a.get(Z)?.aggregate?.memberIds??[Z]},...V?{said:E}:{}}},b=[];for(let g of t){if(!Sa(g,a,r))continue;let O=s.get(g.from),I=s.get(g.to);if(!O||!I)continue;let L=c(g.from,g.to),C=g.edges,Z=r&&C.some(M=>M.from!==g.from&&fn(n,u(g.from),M.from,i).length>0||M.to!==g.to&&fn(n,u(g.to),M.to,i).length>0),q=x(g.from,g.to);if(r&&!Z||g.loop||C.length===0){b.push({key:g.id,connector:g,edges:C,fromBox:O,toBox:I,fromAnchor:g.from,toAnchor:g.to,obstacles:L,hosts:[],...q?{band:q}:{},...p(g,g.from,g.to,C)});continue}let v=new Map;for(let M of C){let w=M.from===g.from?[]:fn(n,u(g.from),M.from,i),E=M.to===g.to?[]:fn(n,u(g.to),M.to,i),V=[g.from,g.to].find(Y=>Math.round(a.get(Y)?.plane??-1)===0);if(!r&&V!==void 0&&(V===g.from?M.from!==g.from:M.to!==g.to)&&fn(n,u(V),V===g.from?M.to:M.from,i).length>0)continue;let A=V!==void 0?a.get(V):void 0;if(!r&&A?.aggregate&&n&&(V===g.from?M.from!==g.from&&w.length===0:M.to!==g.to&&E.length===0))continue;let N=w.length>0?M.from:g.from,H=E.length>0?M.to:g.to,U=`${g.id}|${N}|${H}`,X=v.get(U);if(X){X.edges.push(M);continue}let de=w.length>0?w:[O],le=E.length>0?E:[I],k=de[0],R=le[0],$=1/0;for(let Y of de)for(let j of le){let S=Math.hypot(Y.x+Y.width/2-(j.x+j.width/2),Y.y+Y.height/2-(j.y+j.height/2));S<$&&($=S,k=Y,R=j)}v.set(U,{edges:[M],fromBox:k,toBox:R,fromAnchor:N,toAnchor:H})}for(let[M,w]of v)b.push({key:M,connector:g,obstacles:L,hosts:[...w.fromAnchor!==g.from?[O]:[],...w.toAnchor!==g.to?[I]:[]],...q?{band:q}:{},...w,...p(g,w.fromAnchor,w.toAnchor,w.edges)})}return b}function bi(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 s=a(i.fromBox,l),d=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?s:y===i.toBox?d:i.tie&&y===i.tie.chip?c.chip:y;return{...i,fromBox:s,toBox:d,...c?{tie:c}:{},...i.band?{band:i.band.map(h)}:{}}})}function Go(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 pi(e,t,n){let r=(1-t)*(1-n),o=(1-t)*n+t*(1-n),a=t*n;return{p0:Go(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:Go(e,n)}}function mn(e,t){let n=s=>t.some(d=>s.x>d.x&&s.x<d.x+d.width&&s.y>d.y&&s.y<d.y+d.height),r=s=>!n(Go(e,s)),a=(s,d,c)=>{for(let h=0;h<10;h++){let y=(s+d)/2;r(y)===c?s=y:d=y}return(s+d)/2},i=[],l=null,u=r(0);u&&(l=0);for(let s=1;s<=64;s++){let d=s/64,c=r(d);if(c===u)continue;let h=a((s-1)/64,d,u);c?l=h:l!==null&&(h-l>.001&&i.push(pi(e,l,h)),l=null),u=c}return l!==null&&1-l>.001&&i.push(pi(e,l,1)),i}function wi({strands:e,result:t,scheme:n,overview:r,selection:o,emphasis:a,stageRef:i,liveOf:l,onPickEdge:u,provisional:s,pointed:d=null}){let c=Ot(),h=new Set(t.nodes.filter(v=>v.plot!==void 0&&Math.round(v.plane)===2).map(v=>v.id)),y=v=>r&&t.city!==void 0&&h.has(v.from)&&h.has(v.to),x=Po(t.nodes,o),f=v=>x.size===0||x.has(v.from)||x.has(v.to),p=new Set(o.filter(v=>kt(v)===null)),b=r?t.nodes.find(v=>Math.round(v.plane)===0):void 0,g=b?He(i.current,b.id,!1)??Ze(b,n):null;if(e.length===0)return null;let O=v=>v.edges.some(M=>p.has(M.from)||p.has(M.to)),I=p.size>0&&e.some(O),L=new Map;for(let v of e)L.set(v.connector.id,(L.get(v.connector.id)??0)+1);let C=yi(e.map(v=>({key:v.key,a:v.fromAnchor,b:v.toAnchor}))),Z=new Set,q=e.map((v,M)=>{let{connector:w,fromBox:E,toBox:V}=v,A={x:E.x+E.width/2,y:E.y+E.height/2},N={x:V.x+V.width/2,y:V.y+V.height/2},H=r?Vn(E,N):A,U=r?Vn(V,A):N,X=w.loop===!0,{connector:de,style:le}=Kt(c,w.kind);if(!de.visible)return null;let k=X?Math.max(22,Math.min(E.width,E.height)*.3):0,R=X?{x:A.x+E.width*.22,y:A.y-E.height/2-k+7}:H,$=(H.x+U.x)/2,Y=(H.y+U.y)/2,j=Math.hypot(U.x-H.x,U.y-H.y),S=Math.min(r?40:90,j*(r?.09:.16)),T=0,B=0;if(j>0){T=-(U.y-H.y)/j,B=(U.x-H.x)/j;let ne=$-t.width/2,ve=Y-t.height/2;if(g&&!X){let nt=g.x+g.width/2,P=g.y+g.height/2;ne=$-nt,ve=Y-P;let oe=Math.abs(T*(nt-H.x)+B*(P-H.y)),he=Math.hypot(g.width/2,g.height/2)*.85+24,fe=((nt-H.x)*(U.x-H.x)+(P-H.y)*(U.y-H.y))/(j*j);oe<he&&fe>.1&&fe<.9&&(S=Math.min(180,Math.max(S,(he-oe)*2)))}T*ne+B*ve<0&&(T=-T,B=-B)}S+=2*(C.get(v.key)??0);let W=jn(de.route,{p0:H,c:{x:$+T*S,y:Y+B*S},p1:U}),z=y(w),K=de.route==="orthogonal"||z,D=(ne,ve)=>z?ci(ne,ve):un(ne,ve),re=!X&&v.tie?_o(v.tie.card,v.tie.chip,v.band??[],M):null,G=re?v.tie.cardIsTo?re.reverse():re:!X&&v.band?Xt(E,V,v.band,M):null,we=X||K||G?[]:mn(W,[E,V,...v.obstacles]),Ce=G?[G]:!X&&K?Fo(D(H,U),[E,V,...v.obstacles]):[];if(!X&&we.length===0&&Ce.length===0)return null;let Je=Ce[Ce.length-1],at=K||G?Ce[0]?.[0]:we[0]?.p0,Ue=K||G?Je?.[Je.length-1]:we[we.length-1]?.p1,Ve=ne=>ne.map(ve=>`M ${ve.p0.x} ${ve.p0.y} Q ${ve.c.x} ${ve.c.y} ${ve.p1.x} ${ve.p1.y}`).join(" "),te=`M ${R.x-k} ${R.y} A ${k} ${k} 0 1 1 ${R.x+k} ${R.y} A ${k} ${k} 0 0 1 ${R.x-k} ${R.y}`,st=X?te:G?Fn(G,10):K?Tt(Ce):Ve(we),Ht=ne=>({x:ne.x-8,y:ne.y-8,width:ne.width+16,height:ne.height+16}),dt=[E,V,...v.hosts,...v.obstacles].map(Ht),et=X?te:G?Tt(Ce):K?Tt(Fo(D(H,U),dt)):Ve(mn(W,dt)),lt=v.edges.length===1?v.edges[0]:null,ke=lt?At(w.kind,lt.from,lt.to):null,pt=ke!==null&&o.includes(ke),Be=ke!==null?s?.get(ke):void 0,Xe=v.edges.some(ne=>p.has(ne.from)||p.has(ne.to)),qe=v.tie?.toward??"",Se=v.tie!==void 0&&(d!==null&&(qe===d||v.tie.holds.includes(d)||v.said?.includes(d)===!0)||p.has(qe))&&!Z.has(qe);Se&&Z.add(qe);let Qe=!r&&p.size>0&&Xe||Se,xt=a!==null&&w.kind===a||pt,ct=l?.(w)!==void 0;if(r&&!ct||!r&&!ct&&p.size>0&&!Xe&&!xt&&!Se||v.said!==void 0&&!Se&&!v.said.some(ne=>p.has(ne))&&!xt)return null;let tt=r?No({emphasized:a!==null,stressed:xt,anyChosen:I,mine:Xe,touches:f(w),siblings:L.get(w.id)??1}):To({edgeChosen:pt,lit:Qe,anyLit:I||a!==null,own:le.opacity,kit:c.emphasis}),Pe=Qe&&at&&Ue?v.tie?v.tie.cardIsTo?at:Ue:v.edges.some(ne=>p.has(ne.from))?Ue:at:null,bt=(0,De.jsxs)("g",{children:[(0,De.jsx)("path",{"data-graview-connector":w.kind,"data-graview-edges":v.edges.length,"data-graview-from":v.fromAnchor,"data-graview-to":v.toAnchor,"data-graview-lit":Qe||void 0,"data-graview-activity":l?.(w)?.manner,"data-graview-provisional":Be!==void 0||void 0,opacity:tt*(w.opacity??1)*(Be!==void 0?rn:1),d:st,fill:"none",stroke:zt(le),strokeWidth:(Qe?Math.max(1.6,uo(le,r)):uo(le,r))+(xt?.6:0),strokeDasharray:Be!==void 0?on:On[le.pattern],strokeLinecap:"round"}),Pe?(0,De.jsx)("circle",{cx:Pe.x,cy:Pe.y,r:2.6,fill:zt(le),opacity:tt}):null,X&&r?(0,De.jsx)("text",{x:R.x,y:R.y-k-5,textAnchor:"middle",opacity:tt,style:{font:"9px var(--graview-font-body, system-ui)",letterSpacing:"0.09em",textTransform:"uppercase",fill:"var(--graview-ink-faint)"},children:Ft(w.kind).toLowerCase()}):null]},v.key),Fe=null;return ke&&u&&!X&&tt>=.2&&(Fe=(0,De.jsx)("path",{"data-graview-edge":ke,className:"graview-edge-hit",d:et,fill:"none",pathLength:1,strokeDasharray:"0.86",strokeDashoffset:-.07,stroke:"transparent",strokeWidth:14,style:{pointerEvents:"stroke",cursor:"pointer"},onClick:ne=>{ne.stopPropagation(),u(ke,{x:ne.clientX,y:ne.clientY})},onContextMenu:ne=>{ne.preventDefault(),ne.stopPropagation(),u(ke,{x:ne.clientX,y:ne.clientY})},children:Be!==void 0?(0,De.jsx)("title",{children:Be}):null},`hit:${v.key}`)),{key:v.key,line:bt,hit:Fe}});return(0,De.jsxs)(De.Fragment,{children:[(0,De.jsx)("svg",{"aria-hidden":"true","data-graview-world":"",width:t.width,height:t.height,style:{position:"absolute",left:0,top:0,pointerEvents:"none",zIndex:Ie.ties},children:q.map(v=>v?.line)}),q.some(v=>v?.hit)?(0,De.jsx)("svg",{"data-graview-world":"",width:t.width,height:t.height,style:{position:"absolute",left:0,top:0,pointerEvents:"none",zIndex:Ie.tieLabels},children:q.map(v=>v?.hit)}):null]})}var Oa=e=>e.length*8.4+16;function vi(e,t){let n=new Map;for(let a of e){let i=n.get(a.key);i?i.push(a):n.set(a.key,[a])}let r=[...n.values()].map(a=>{let i=Math.min(...a.map(u=>u.top)),l=a.filter(u=>u.top-i<=12);return{key:a[0].key,text:a[0].text,left:Math.min(...l.map(u=>u.left)),right:Math.max(...l.map(u=>u.right)),top:i}});r.sort((a,i)=>a.top-i.top||a.left-i.left);let o=r.map(a=>{let i=Math.max(a.right-a.left,Math.min(300,Oa(a.text))),l=(a.left+a.right)/2;return{left:l-i/2,right:l+i/2}});return r.map((a,i)=>{let l=r.map((b,g)=>({other:b,at:g})).filter(({other:b})=>b!==a&&Math.abs(b.top-a.top)<=12),u=l.filter(({other:b})=>b.right<=a.left).map(({other:b,at:g})=>o[g].right+8<=(b.right+a.left)/2?o[g].right+8:(b.right+a.left+8)/2),s=l.filter(({other:b})=>b.left>=a.right).map(({other:b,at:g})=>o[g].left-8>=(a.right+b.left)/2?o[g].left-8:(a.right+b.left-8)/2),d=Math.max(t.left,...u),c=Math.min(t.right,...s),h=a.right-a.left,y=o[i].right-o[i].left,x=Math.max(h,Math.min(y,c-d)),f=(a.left+a.right)/2,p=h>=x?a.left:Math.max(d,Math.min(f-x/2,c-x));return{key:a.key,text:a.text,left:p,width:x,top:a.top}})}function _n(e){return e<640?{left:8,right:56}:{left:8,right:Math.round(Math.min(128,e*.107))}}var me=se(Oe(),1);function Si(e){let t=lr(e);return t.length>0?new Map(t.map(n=>[At(n.edge.kind,n.edge.from,n.edge.to),dr(n)])):void 0}function Mi({frame:e,width:t,height:n,scheme:r,overview:o,selection:a,emphasis:i,stageRef:l,store:u,graphNodes:s,onPickEdge:d,liveOf:c,holding:h=!1,provisional:y,focusId:x=null,beside:f=!1}){let[p,b]=(0,pe.useState)(0),[g,O]=(0,pe.useState)(null),I=e.t<1,L=(0,pe.useRef)(""),C=(0,pe.useRef)([]),Z=()=>[...l.current?.querySelectorAll("[data-graview-relation] > span")??[]].map(A=>{let N=A.getBoundingClientRect();return`${Math.round(N.left)},${Math.round(N.top)},${Math.round(N.width)}`}).join(" ");(0,pe.useLayoutEffect)(()=>{I||h||(L.current=Z(),C.current=e.nodes,O(zn(e.nodes,e.connectors,l.current,o,r)))},[e,I,h,a,o,s,r,p,l]),(0,pe.useEffect)(()=>{if(I||h||o||typeof requestAnimationFrame>"u")return;let A=requestAnimationFrame(()=>{Z()!==L.current&&b(N=>N+1)});return()=>cancelAnimationFrame(A)},[g]);let q=e.nodes.map(A=>A.id).join(`
4
+ `);(0,pe.useLayoutEffect)(()=>{let A=l.current;if(A===null||typeof window>"u")return;let N=0,H=()=>{N===0&&(N=requestAnimationFrame(()=>{N=0,b(X=>X+1)}))};A.addEventListener("scroll",H,{capture:!0,passive:!0}),window.addEventListener("resize",H,{passive:!0});let U=typeof ResizeObserver>"u"?null:new ResizeObserver(H);if(U){U.observe(A);for(let X of A.querySelectorAll("[data-graview-view]"))U.observe(X)}return()=>{N!==0&&cancelAnimationFrame(N),A.removeEventListener("scroll",H,{capture:!0}),window.removeEventListener("resize",H),U?.disconnect()}},[l,q]);let[v,M]=(0,pe.useState)(null),w=(g??[]).some(A=>A.tie!==void 0);if((0,pe.useEffect)(()=>{let A=l.current;if(!w||A===null)return;let N=U=>{let X=U.target?.closest?.("[data-graview-pick], [data-graview-view]");M(X?.getAttribute("data-graview-pick")??X?.getAttribute("data-graview-view")??null)},H=()=>M(null);return A.addEventListener("pointerover",N),A.addEventListener("focusin",N),A.addEventListener("pointerleave",H),A.addEventListener("focusout",H),()=>{A.removeEventListener("pointerover",N),A.removeEventListener("focusin",N),A.removeEventListener("pointerleave",H),A.removeEventListener("focusout",H)}},[w,l]),I)return null;let E=(g&&h?bi(g,C.current,e.nodes):g)??zn(e.nodes,e.connectors,null,o,r),V=new Set;for(let A of E){if(A.edges.length!==1)continue;let N=A.edges[0];V.add(`${A.connector.kind}|${N.from}|${N.to}`)}return(0,me.jsxs)(me.Fragment,{children:[(0,me.jsx)(wi,{strands:E,result:e,scheme:r,overview:o,selection:a,emphasis:i,stageRef:l,onPickEdge:d,liveOf:c,pointed:v,...y?{provisional:y}:{}}),o&&sn(a,{overview:o,focusId:x,beside:f},A=>u.graph.getNode(A)?.kind).records.length>0?(0,me.jsx)(pe.Suspense,{fallback:null,children:(0,me.jsx)(La,{frame:e,width:t,height:n,stageRef:l,tick:p,store:u,graphVersion:s,selection:a,view:{overview:o,focusId:x,beside:f},rulers:y?{...ki,unsureOf:(A,N,H)=>y.get(At(A,N,H))}:ki})}):null,o?null:(0,me.jsx)(Ia,{...y?{provisional:y}:{},stageRef:l,nodes:e.nodes,scheme:r,selection:a,store:u,graphNodes:s,overview:o,width:t,height:n,onPickEdge:d,alreadyDrawn:V,tick:p})]})}var ki={visibleRect:cn,clipQuadratic:mn,unsureDash:on,unsureOpacity:rn},Aa=nn(Jt(()=>import("./chunk.ZSKP6UQS.js"))),La=Aa.part((e,t)=>(0,me.jsx)(e.RecordLinks,{...t}),{what:"The links",quiet:!0});function Ia({stageRef:e,nodes:t,scheme:n,selection:r,store:o,graphNodes:a,overview:i,width:l,height:u,onPickEdge:s,alreadyDrawn:d,tick:c,provisional:h}){let y=Ot(),x=(0,pe.useMemo)(()=>{if(r.length===0||r.length>4)return[];let g=new Set(r),O=[];for(let L of r){let C=kt(L);C&&O.push({kind:C.kind,self:C.from,other:C.to})}for(let L of o.graph.allEdges()){let C=g.has(L.from)?L.from:g.has(L.to)?L.to:null;if(!C)continue;let Z=C===L.from?L.to:L.from;g.has(Z)||O.push({kind:L.kind,self:C,other:Z})}if(O.length<=14)return O;let I=new Set(t.map(L=>L.id));return O.map((L,C)=>({tie:L,index:C,real:I.has(L.other)?0:1})).sort((L,C)=>L.real-C.real||L.index-C.index).slice(0,14).map(({tie:L})=>L)},[o,r,a,t]),f=()=>{if(x.length===0||typeof document>"u")return[];let g=e.current?.getBoundingClientRect();if(!g)return[];let O=[...e.current?.querySelectorAll("[data-graview-joins]")??[]].find(w=>{if(w.closest("[data-graview-offstage]"))return!1;try{let E=JSON.parse(w.getAttribute("data-graview-joins")??"[]");return E.length===r.length&&E.every(V=>r.includes(V))}catch{return!1}});if(O){let w=cn(O,e.current);if(!w)return[];let E=[];for(let V of r){let A=t.find(X=>X.id===V);if(!A)continue;let N=He(e.current,A.id,i)??Ze(A,n),H=N?Yn(w,N):null;if(!N||!H)continue;let U=[...o.graph.allEdges()].find(X=>X.from===V&&r.includes(X.to)||X.to===V&&r.includes(X.from));E.push({key:`join:${V}`,self:V,other:"",others:1,kind:U?.kind??"",endX:H.to.x,endY:H.to.y,...H,fromBox:w,toBox:N,proxy:!1,edgeId:U?At(U.kind,U.from,U.to):null})}return E}let I=(w,E)=>{let V=e.current?.querySelectorAll(`[data-graview-pick="${CSS.escape(w)}"], [data-graview-slot="${CSS.escape(w)}"]`),A=[];for(let N of V??[]){if(N.closest("[data-graview-offstage]")||E(N)||N.closest("[data-graview-mark]"))continue;let H=cn(N,e.current);H&&A.push(H)}return A.sort((N,H)=>N.width*N.height-H.width*H.height)},L=w=>t.find(E=>E.id===w)??t.find(E=>E.aggregate?.memberIds.includes(w)),C=w=>`[data-graview-pick="${CSS.escape(w)}"], [data-graview-slot="${CSS.escape(w)}"]`,Z=(w,E)=>{let V=e.current;if(!V)return!1;for(let A of V.querySelectorAll("[data-graview-view]")){let N=A.querySelector(C(w));if(N===null||N.closest("[data-graview-offstage]"))continue;let H=A.querySelector(C(E));if(H!==null&&!H.closest("[data-graview-offstage]"))return!0}return!1},q=[];if(!i&&e.current){for(let w of t){if(Math.round(w.plane)!==1)continue;let E=He(e.current,w.id,!1);E&&q.push(E)}for(let w of e.current.querySelectorAll("[data-graview-relation] > span")){let E=w.getBoundingClientRect();E.width>0&&E.height>0&&q.push({x:E.left-g.left,y:E.top-g.top,width:E.width,height:E.height})}}let v=new Map,M=[];for(let w of x){if(Z(w.self,w.other))continue;let E=L(w.self),V=E?e.current?.querySelector(`[data-graview-view="${CSS.escape(E.id)}"]`):null,A=!i&&E?.id===w.self&&Math.round(E.plane)===1?He(e.current,E.id,!1):null,N=A?[A]:I(w.self,()=>!1);if(!(N.length>0)&&E){let D=He(e.current,E.id,!1)??Ze(E,n);D&&N.push(D)}let U=t.find(D=>D.id===w.other),X=[],de=!1;if(U){let D=He(e.current,U.id,i)??Ze(U,n);D&&X.push(D)}else if(X.push(...I(w.other,D=>V?V.contains(D):!1)),X.length===0){let D=L(w.other);if(D&&(!E||D.id!==E.id)){let re=He(e.current,D.id,i)??Ze(D,n);re&&(X.push(re),de=!0)}}if(N.length===0||X.length===0||de&&i)continue;let le=N[0],k=X[0],R=1/0;for(let D of N)for(let re of X){let G=Math.hypot(D.x+D.width/2-(re.x+re.width/2),D.y+D.height/2-(re.y+re.height/2));G<R&&(R=G,le=D,k=re)}if(d?.has(`${w.kind}|${w.self}|${w.other}`)||d?.has(`${w.kind}|${w.other}|${w.self}`))continue;let $=`${w.kind}:${Math.round(le.x)},${Math.round(le.y)}:${Math.round(k.x)},${Math.round(k.y)}`,Y=v.get($);if(Y){Y.others+=1;continue}let j=Yn(le,k);if(!j)continue;let{from:S,control:T}=j,B=A&&le===A?Xt(le,k,q,M.length):void 0,W=B?B[B.length-1]:j.to,z=[...o.graph.allEdges()].find(D=>D.kind===w.kind&&(D.from===w.self&&D.to===w.other||D.from===w.other&&D.to===w.self)),K={key:`${w.kind}:${w.self}:${w.other}`,self:w.self,other:w.other,others:1,kind:w.kind,endX:W.x,endY:W.y,from:S,to:W,control:T,fromBox:le,toBox:k,...B?{points:B}:{},proxy:de,edgeId:z?At(z.kind,z.from,z.to):null};v.set($,K),M.push(K)}for(let w of M){let E=[...o.graph.allEdges()].find(U=>U.kind===w.kind&&(U.from===w.self&&U.to===w.other||U.from===w.other&&U.to===w.self)),V=o.graph.getNode(w.self),A=o.graph.getNode(w.other);if(!E||!V||!A)continue;let N=E.from===w.self?"out":"in",H=sr(o.schema,N==="out"?V.kind:A.kind,w.kind,N);w.said=w.proxy?`${H}: ${jt(o.schema,A.kind,w.others)}`:`${H}: ${vn(o.schema.tryDefinition(A.kind),A)}`}return M},[p,b]=(0,pe.useState)([]);return(0,pe.useLayoutEffect)(()=>{b(f())},[x,t,i,n,l,u,d,c,e]),p.length===0?null:(0,me.jsxs)(me.Fragment,{children:[(0,me.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:Ie.lines},children:p.map(g=>{let{connector:O,style:I}=Kt(y,g.kind);if(!O.visible)return null;let L=g.edgeId?h?.get(g.edgeId):void 0,C={p0:g.from,c:g.control,p1:g.to},Z=g.points?Fn(g.points,10):O.route==="orthogonal"?Tt([un(g.from,g.to)]):(({p0:v,c:M,p1:w})=>`M ${v.x} ${v.y} Q ${M.x} ${M.y} ${w.x} ${w.y}`)(jn(O.route,C)),q=null;if(g.edgeId&&s&&!g.proxy){let v=(w,E)=>E.x>=w.x&&E.x<=w.x+w.width&&E.y>=w.y&&E.y<=w.y+w.height,M=g.points?[...g.points]:[];for(let w=0;w<=(g.points?-1:40);w++){let E=li(O.route,C,w/40);v(g.fromBox,E)||v(g.toBox,E)||M.push(E)}M.length>=2&&(q=(0,me.jsx)("path",{"data-graview-edge":g.edgeId,className:"graview-edge-hit",d:`M ${M[0].x} ${M[0].y} ${M.slice(1).map(w=>`L ${w.x} ${w.y}`).join(" ")}`,fill:"none",pathLength:1,strokeDasharray:"0.86",strokeDashoffset:-.07,stroke:"transparent",strokeWidth:14,style:{pointerEvents:"stroke",cursor:"pointer"},onClick:w=>{w.stopPropagation(),s(g.edgeId,{x:w.clientX,y:w.clientY})},onContextMenu:w=>{w.preventDefault(),w.stopPropagation(),s(g.edgeId,{x:w.clientX,y:w.clientY})},children:L!==void 0?(0,me.jsx)("title",{children:L}):null}))}return(0,me.jsxs)("g",{opacity:(g.proxy?.32:.72)*(L!==void 0?rn:1),children:[(0,me.jsx)("path",{"data-graview-tie":g.kind,"data-graview-tie-proxy":g.proxy||void 0,"data-graview-provisional":L!==void 0||void 0,d:Z,fill:"none",stroke:zt(I),strokeWidth:g.proxy?1.1:1.6,strokeDasharray:L!==void 0?on:On[I.pattern],strokeLinecap:"round"}),(0,me.jsx)("circle",{cx:g.endX,cy:g.endY,r:g.proxy?2:2.6,fill:zt(I)}),q]},g.key)})}),(0,me.jsx)("div",{"aria-hidden":"true","data-graview-world":"",style:{position:"absolute",inset:0,pointerEvents:"none",zIndex:Ie.tieLabels},children:p.map(g=>g.said?(0,me.jsx)("span",{className:"graview-record-link-said","data-graview-link-said":g.kind,"data-graview-lands":g.proxy?"district":"record",style:{position:"absolute",left:g.endX,top:g.endY-26},children:g.said},g.key):null)})]})}function Ri({nodes:e,scheme:t,width:n,stageRef:r,moving:o=!1,holding:a=!1}){let i=Ot(),[l,u]=(0,pe.useState)([]);(0,pe.useLayoutEffect)(()=>{o||a||u(s())},[e,o,a,t,n,r]);function s(){let d=[];for(let h of e){if(!h.via||Math.round(h.plane)!==1)continue;let y=He(r.current,h.id,!1,!0),{scale:x}=ze(1,t);d.push({key:`${h.via.edgeKind}|${h.via.direction}`,text:h.via.description??`${h.via.direction==="in"?"\u2190":"\u2192"} ${Ft(h.via.edgeKind).toLowerCase()}`,left:y?.x??h.x,right:y?y.x+y.width:h.x+h.width*x,top:y?.y??h.y})}let c=_n(n);return vi(d,{left:c.left,right:n-c.right})}return l.length===0||!i.captions.visible||o?null:(0,me.jsx)("div",{"aria-hidden":"true",style:{position:"absolute",inset:0,pointerEvents:"none",zIndex:Ie.lines},children:l.map(d=>{let{left:c,width:h}=d;return(0,me.jsx)("div",{"data-graview-relation":d.key,title:d.text,style:{position:"absolute",left:c,width:h,textAlign:"center",top:Math.max(0,d.top-19),fontSize:"0.75rem",letterSpacing:"0.09em",textTransform:"uppercase",color:"var(--graview-ink-faint)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:(0,me.jsx)("span",{style:{background:"var(--graview-ground)",padding:"1px 7px",borderRadius:4},children:d.text})},d.key)})})}var $t=se(Te(),1);var Pa=new Set;function Ei(e,t,n,r,o,a,i){let{store:l,views:u,hiddenKinds:s}=ge(),d=Mt(),c=(0,$t.useContext)(Yt),h=ao(),y=(0,$t.useMemo)(()=>{let p={};for(let b of h){if(b.subjectId===void 0)continue;let g=p[b.subjectId]??=[];for(let O of b.nodeIds)O!==b.subjectId&&!g.includes(O)&&g.push(O)}return p},[h]),x=(0,$t.useMemo)(()=>({flagged:new Set(h.flatMap(p=>p.nodeIds)),touched:An(l.log.all())}),[h,l,i]),f=(0,$t.useMemo)(()=>({hits:d?Rn(d):Pa,...x}),[d,x]);return(0,$t.useMemo)(()=>({...e,cityZoom:o,...c?{besideTheMap:!0}:{},...s.size>0?{hiddenKinds:[...s].sort()}:{},...Object.keys(y).length>0?{judged:y}:{},relevance:f,inset:{..._n((t?.width??1200)-a.right),top:8,bottom:r?0:56},chrome:[{x:(t?.width??1200)-a.right-176,y:0,width:176,height:100}],...a.right>0||a.bottom>0?{dock:a}:{},unit:n,plainGroups:l.schema.kinds.filter(p=>rr(u.lookup(p,{cardinality:"many",fidelity:"full"}))),cityOrder:Jo(wr({name:"scene",schema:l.schema,mutations:l.allMutations().filter(p=>!p.derived)}).order.map(p=>p.kind),u.arrangement?.()?.order),screens:u.places().reduce((p,b)=>((p[b.kind]??=[]).push({as:b.as,title:b.title,...b.across?{across:b.across}:{}}),p),{}),...t?{width:t.width,height:r?Math.max(0,t.height-64):t.height}:{}}),[e,t,n,l,u,s,y,f,o,r,c,a.right,a.bottom])}var it=se(Te(),1);var Oi=se(Te(),1);function Gn(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 Ai(e){(0,Oi.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&&Ta(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 Na=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 Ta(e){return Na.has(e.localName.toLowerCase())}var qt=se(Oe(),1);function Li({node:e,useDom:t,touched:n,frontY:r,centerY:o,screen:a,onDrawnHeight:i,crowded:l,activity:u,scheme:s,canvasWidth:d,canvasHeight:c,selected:h,onSelect:y,onPick:x,onTravel:f,onMenu:p,selection:b,onJackIn:g,onDragStart:O,onDragMove:I,onDragEnd:L,swallowClick:C,children:Z}){let{brand:q,store:v,actsDoor:M}=ge(),w=e.beyond?`${e.beyond.length} more district${e.beyond.length===1?"":"s"}`:e.aggregate?.opens?.in==="place"?`${e.aggregate.label}, ${jt(v.schema,e.aggregate.kind,e.aggregate.memberIds.length)}`:e.aggregate?e.aggregate.label:(()=>{let S=v.graph.getNode(e.id);return S?vn(v.schema.tryDefinition(e.kind),S):e.id})(),[E,V]=(0,it.useState)(null),A=Math.round(e.plane)===0&&!e.aggregate;(0,it.useLayoutEffect)(()=>{if(!A)return;let S=k.current;if(!S)return;let T=()=>{let W=[...S.children].find(G=>G.dataset.graviewKindtag===void 0);if(!W)return;let z=S.getBoundingClientRect(),K=W.getBoundingClientRect(),D=S.offsetWidth>0?z.width/S.offsetWidth:1,re={top:Math.round((K.top-z.top)/D)-9,right:Math.round((z.right-K.right)/D)+14};V(G=>G&&G.top===re.top&&G.right===re.right?G:re)};if(typeof ResizeObserver>"u"){T();return}let B=new ResizeObserver(T);B.observe(S);for(let W of S.children)B.observe(W);return()=>B.disconnect()},[A,e.id]);let N=r!==void 0?0:e.plane-(1-(e.depth??1))*.55,H=Math.max(0,Math.min(2,Math.floor(N))),U=Math.max(0,Math.min(2,Math.ceil(N))),X=H===U?ze(H,s):En(ze(H,s),ze(U,s),N-H),de=ar(X,e.x,e.y,d,c),le=ze(Math.max(0,Math.min(2,Math.round(N))),s).blur,k=(0,it.useRef)(null);Ai(k);let R=e.natural,$=R?Math.min(e.width/R.width,e.height/R.height):1,Y=(0,it.useRef)(null);(0,it.useEffect)(()=>{if(!a||!i)return;let S=Y.current;if(!S||typeof ResizeObserver>"u")return;let T=()=>{let D=0,re=0;for(let G of S.children)if(!(!(G instanceof HTMLElement)||G.classList.contains("graview-screen-fullscreen"))){D=Math.max(D,G.offsetTop+G.offsetHeight);for(let we of[G,...G.querySelectorAll("*")]){let Ce=getComputedStyle(we).overflowY;(Ce==="auto"||Ce==="scroll")&&(re+=we.scrollHeight-we.clientHeight)}}i(D+re)},B=0,W=()=>{B||(B=requestAnimationFrame(()=>{B=0,T()}))};T();let z=new ResizeObserver(W);z.observe(S);for(let D of S.children)z.observe(D);let K=new MutationObserver(W);return K.observe(S,{childList:!0,subtree:!0,characterData:!0,attributes:!0}),()=>{B&&cancelAnimationFrame(B),z.disconnect(),K.disconnect(),i(void 0)}},[a,i,e.id]);let j=t?{transform:di(de),transformOrigin:"0 0",filter:le>0?`blur(${le}px)`:void 0,opacity:(1-X.falloff*.55)*(e.opacity??1),"--graview-lift-low":si(X.shadow,s),...r!==void 0?{"--graview-front-y":`${r.toFixed(1)}px`}:{},...o!==void 0?{"--graview-center-y":`${o.toFixed(1)}px`}:{}}:{};return(0,qt.jsxs)("div",{ref:k,"data-graview-view":e.id,"data-graview-plane":Math.round(e.plane),"data-graview-selected":h||void 0,"data-graview-touched":n||void 0,"data-graview-plot":r!==void 0?"":void 0,"data-graview-screen":a?"":void 0,"data-graview-record-focus":Math.round(e.plane)===0&&!e.aggregate&&!R&&!a?"":void 0,"data-graview-nested":e.nestedUnder??void 0,"data-graview-crowded":l||void 0,"data-graview-pinned":e.pinned||void 0,"data-graview-activity":u?u.manner:void 0,"data-graview-wrote":u?.wrote||void 0,"data-graview-read":u&&!u.wrote?!0:void 0,"data-graview-broke":u?.broke||void 0,title:u?`${Jr[u.manner]} ${u.wrote?"changed this":"read this"}: ${u.intent}`:e.aggregate&&Math.round(e.plane)!==0?`Open ${e.aggregate.label}`:void 0,role:"group","aria-label":w,"aria-keyshortcuts":M&&!e.beyond?M.key:void 0,tabIndex:0,onPointerDown:O,onPointerMove:I,onPointerUp:L,onPointerCancel:L,onClick:S=>{if(C.current)return;let T=S.target?.closest("input, textarea, select, button, a[href], [contenteditable='true']");if(T&&!T.hasAttribute("data-graview-pick"))return;let B=S.metaKey||S.shiftKey,W=ft(S.target);if(W&&W!==e.id){S.stopPropagation(),x(W,B,Gn(S.target)??void 0);return}y(B)},onKeyDown:S=>{if(M&&!e.beyond&&S.key.toLowerCase()===M.key.toLowerCase()&&!S.metaKey&&!S.ctrlKey&&!S.altKey&&!S.target?.closest("input, textarea, select, [contenteditable='true']")){S.preventDefault(),S.stopPropagation();let K=ft(S.target)??e.id;b.includes(K)||x(K,!1),M.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 B=ft(S.target);if(S.preventDefault(),S.stopPropagation(),!B||B===e.id){b.length===1&&b[0]===e.id&&!S.metaKey&&!S.shiftKey?g():y(S.metaKey||S.shiftKey);return}let W=Gn(S.target);(W?b.length===W.length&&W.every(K=>b.includes(K)):b.length===1&&b[0]===B)&&!S.metaKey&&!S.shiftKey?f(B):x(B,S.metaKey||S.shiftKey,W??void 0)},onContextMenu:S=>{let T=ft(S.target);S.preventDefault(),S.stopPropagation();let B=T&&T!==e.id?T:e.id;x(B,!1,(B===T?Gn(S.target):null)??void 0),p({x:S.clientX,y:S.clientY,on:B})},onDoubleClick:S=>{let T=ft(S.target);if(T&&T!==e.id){S.stopPropagation(),f(T);return}g()},style:{position:"absolute",...t?{}:{pointerEvents:"none"},zIndex:e.opened?Ie.opened:Ie.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",...j},children:[R?(0,qt.jsx)("div",{ref:Y,"data-graview-natural":`${Math.round(R.width)}x${Math.round(R.height)}`,style:{position:"absolute",left:"50%",top:"50%",width:R.width,height:R.height,transform:`translate(-50%, -50%) scale(${$})`,transformOrigin:"50% 50%",display:"flex",flexDirection:"column"},children:Z}):Z,Math.round(e.plane)===0&&!e.aggregate?(0,qt.jsxs)("span",{"data-graview-kindtag":"",className:"graview-kind-tag","aria-hidden":"true",style:{...E??{},"--graview-hue":Math.round(Zt(e.kind,q?.accents))},children:[(0,qt.jsx)("span",{style:{width:9,height:6,clipPath:"polygon(50% 0, 100% 50%, 50% 100%, 0 50%)",flex:"0 0 auto",background:`hsl(${Math.round(Zt(e.kind,q?.accents))} 55% var(--graview-tint-lightness) / 0.9)`}}),Qo(v.schema.tryDefinition(e.kind),e.kind)]}):null]})}var ue=se(Oe(),1);io({search:pr,touchWeights:An});var $a=e=>e?{activity:e}:{},Ha=e=>`${Math.round(e.x)} ${Math.round(e.y)}`,Ii=e=>e.stopPropagation(),Ti=.6,$i=3,Da=80,Ci=e=>Math.round(e.plane)===1&&(e.compact===!0||e.width<175||e.height<Da);function Ba(e){let[t,n]=(0,J.useState)(1),r=(0,J.useRef)(1);return(0,J.useEffect)(()=>{e||(r.current=1,n(1))},[e]),[t,r,n]}function Fa(e){let[t,n]=(0,J.useState)({x:0,y:0}),r=(0,J.useMemo)(()=>({x:(e.pan?.x??0)+t.x,y:(e.pan?.y??0)+t.y}),[e.pan,t]),o=(0,J.useMemo)(()=>t.x===0&&t.y===0?e:Lt(e,r),[e,t,r]),a=(0,J.useRef)(t);a.current=t;let i=(0,J.useCallback)((l,u)=>{let s=a.current,d=(c,h,y)=>Math.max(Math.min(-c,h),Math.min(Math.max(c,h),y+h))-h;return{x:d(l.x,s.x,u.x),y:d(l.y,s.y,u.y)}},[]);return[r,o,i,a,n]}function ja(e,t,n,r,o,a){let i=n!==null&&!t.overview,l=i?null:n,u=(0,J.useMemo)(()=>{let h=t.pan?{...t,pan:void 0}:t;return l?an(h,l.id,{x:l.x,y:l.y}):h},[t,l]),s=(0,J.useMemo)(()=>Pn(e.graph,e.schema,u,r),[e,u,r,o]),d=(0,J.useMemo)(()=>n&&i?Ao(s,n.id,{x:n.x,y:n.y})??Pn(e.graph,e.schema,an(u,n.id,{x:n.x,y:n.y}),r):s,[s,n,i,e,u,r]);return[(0,J.useMemo)(()=>Lo(d,a??{x:0,y:0}),[d,a]),i]}function Wa(){let[e,t]=(0,J.useState)(!1),[n,r]=(0,J.useState)(!1),o=(0,J.useRef)(null),a=(0,J.useRef)(()=>!1),i=(0,J.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 Va(e){let t=(0,J.useRef)(!1),n=e!==null&&!t.current;return(0,J.useEffect)(()=>{e!==null&&(t.current=!0)},[e]),n}function Ya({registerScene:e,scheme:t,views:n},r,o){let a=(0,J.useRef)(r);a.current=r,(0,J.useEffect)(()=>(e({whereIs:i=>Bn(a.current,o.current,t,n,i)}),()=>e(null)),[e,t,n])}function za(e,t){(0,J.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 _a(e,t,n,r,o){(0,J.useEffect)(()=>{if(e==="dom")return;let a=n.current;if(!a||!t)return;let i=new Set;for(let u of r.nodes)(o.has(u.id)||u.aggregate?.memberIds.some(s=>o.has(s)))&&i.add(u.id);let l=t({canvas:a,layout:r,dirty:i,hostOf:u=>a.querySelector(`[data-graview-view="${CSS.escape(u)}"]`)});return()=>{l?.()}},[e,t,r,o])}function Ga(){let e=cr();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 s=e.get(u);s&&(a||=s.wrote,i||=s.read,l||=s.broke,(!o||s.at>o.at||s.at===o.at&&s.wrote&&!o.wrote)&&(o=s))}return o?{...o,wrote:a,read:i,broke:l}:void 0}}var Pi=(e,t)=>e.includes(t)?e.filter(n=>n!==t):[...e,t];function Ka(){let{views:e,view:t,setView:n,setSelection:r}=ge(),o=Mt(),a=(0,J.useContext)(Yt),i=l=>{if(Re(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(Vt(l.id)){r(d=>u?Pi(d,l.id):[l.id]);return}let s=l.aggregate?tn(l.id):[];if(t.overview){r(d=>u?[...new Set([...d,l.id])]:[l.id]);return}if(s.length===1&&!u&&Math.round(l.plane)!==0){let d=s[0];n(c=>eo(c,c.relation===d?null:d));return}r(d=>Do(l,d,u))},onPick:(u,s,d)=>r(c=>d?s?[...new Set([...c,...d])]:[...d]:s?Pi(c,u):[u]),onTravel:u=>{n(s=>({...ut(s,u),relation:null})),r([u])},onJackIn:()=>{let u=l.aggregate?.opens;if(u){u.in==="place"?n(c=>to(c,l.id)):n(c=>Object.entries(u.within).reduce((h,[y,x])=>Sn(h,y,x),ut(en(c,!1),u.focus))),r([]);return}let s=Re(l.id),d=s!==null&&(o?.byKind[s]??0)>0;if(a&&s!==null&&t.overview&&!i(l)&&!(d&&t.q)){n(c=>Sn({...ut(c,`aggregate:${s}`),relation:null},"view",null)),r([]);return}n(c=>no(c,l.id,{ownPicture:i(l),...d&&c.q?{carry:c.q}:{}})),r(l.aggregate?[]:[l.id])}})}var Ua=nn(Jt(()=>import("./chunk.5JXUAMKI.js"))),Xa=Ua.part((e,t)=>(0,ue.jsx)(e.Ribbons,{...t}),{what:"The relations",quiet:!0}),Ni="graview:map-from-above";function qa(){let[e,t]=(0,J.useState)(()=>{try{return globalThis.localStorage?.getItem(Ni)==="1"}catch{return!1}}),n=(0,J.useCallback)(r=>{t(r);try{globalThis.localStorage?.setItem(Ni,r?"1":"0")}catch{}},[]);return[e,n]}var Qa=nn(Jt(()=>import("./chunk.44FVJOK4.js"))),Za=Qa.part((e,t)=>(0,ue.jsx)(e.Plots,{...t}),{quiet:!0});function Ja({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:Ii,onClick:Ii,children:[o("out","\u2212",1/1.25,e<=Ti+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>=$i-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 es({options:e,renderer:t="auto",attachRenderer:n,className:r,style:o,animate:a=!0,children:i}){let l=ge(),{store:u,scheme:s,views:d,view:c,setView:h,selection:y,setSelection:x,setMenuAt:f,emphasis:p,brand:b,noteMoved:g,robots:O,seatTalk:I,motion:L}=l,C=(0,J.useContext)(Yt),Z=oo(I),q=(0,J.useRef)(null),v=(0,J.useRef)(null),M=ai(v),w=ii(),{zoomAbout:E,panBy:V}=Zr({stage:v,view:c,setView:h}),A=Rt(),N=1,[H,U,X]=Ba(c.overview),[de,le]=qa(),k=(0,J.useMemo)(()=>de?{...e,tilt:br}:e,[e,de]),{probe:R,dock:$}=Ur(),Y=Ei(k,M,w,Z,N*H,$,A),[j,S,T,B,W]=Fa(c),z=(0,J.useMemo)(()=>new Set(Object.keys(c.pins).filter(P=>Re(P)===null)),[c.pins]),K=Xr(),[D,re]=ja(u,c,K.held,Y,A,S.pan),[G,we,Ce,Je,at,Ue]=Wa(),Ve=Va(M),te=Br(D,{enabled:a&&!G&&!we&&M!==null&&!Ve});(0,J.useEffect)(()=>L.set(G||we||te.t<1),[L,G,we,te]);let st=Fr(),Ht=jr(),dt=_r({view:c,result:D,frame:te,panned:j,closer:N,screenId:null,setCamera:W});Ya(l,te,v),za(l.pointer,v),_a(t,n,q,te,st);let et=t==="dom"||t==="auto"&&!n,lt=Ga(),ke=qr({stage:v,pan:c.pan,setView:h,settled:Ue});at.current=ke.settle;let{onGroundDown:pt,onCardDown:Be,onDragMove:Xe,onDragUp:qe,swallow:Se}=Qr({view:c,panned:j,limit:()=>mt(D),panWithin:T,moveByTransform:et,setView:h,setDragging:Ce,noteMoved:g,shift:ke,district:K});E.current=(P,oe,he)=>{if(!c.overview)return;at.current();let fe=U.current,Ae=Math.max(Ti,Math.min($i,fe*P));if(Math.abs(Ae-fe)<1e-4)return;U.current=Ae,Je(),X(Ae);let Dt=v.current?.getBoundingClientRect(),gn=D.visible??D,Ne={x:gn.width/2,y:gn.height/2},yn=Dt&&oe!==void 0&&he!==void 0?{x:oe-Dt.left,y:he-Dt.top}:Ne,pn=Ae/fe;h(Bt=>Lt(Bt,Eo(Bt.pan??{x:0,y:0},B.current,yn,Ne,pn))),g()};let Qe=(P,oe,he=mt(D))=>h(fe=>Lt(fe,T(he,{x:(fe.pan?.x??0)+P,y:(fe.pan?.y??0)+oe})));Kr(v,$,(P,oe)=>Qe(P,oe)),V.current=(P,oe)=>{Je();let he=mt(D),fe=c.pan??{x:0,y:0};if(et){let Ae=ke.offset();ke.shiftTo(T(he,{x:fe.x+Ae.x+P,y:fe.y+Ae.y+oe}),fe)}else Qe(P,oe,he);g()};let xt=Ka(),ct=Ot(),tt=(0,J.useCallback)(P=>Kt(ct,P).connector.visible,[ct]),Pe=P=>lt(te.nodes.find(oe=>oe.id===P)),bt=(P,oe,he,fe)=>P.originY+j.y+Ut(he.col+he.side/fe,he.row+he.side/fe,P.cell,P.tilt).y-oe.y,Fe={width:D.width,height:D.height},ne={position:"relative",zIndex:Ie.stage,...Fe},ve=P=>Bn(te,v.current,s,d,P),nt=te.nodes.filter(P=>P.screenOf===void 0).map(P=>(0,ue.jsx)(Li,{node:P,crowded:Ci(P),useDom:et,...P.plot&&te.city&&Math.round(P.plane)===2?{frontY:bt(te.city,P,P.plot,1),centerY:bt(te.city,P,P.plot,2)}:{},touched:st.has(P.id),...$a(lt(P)),scheme:s,canvasWidth:D.width,canvasHeight:D.height,selected:y.includes(P.id),...xt(P),onMenu:f,selection:y,onDragStart:oe=>Be(P,oe),onDragMove:Xe,onDragEnd:qe,swallowClick:Se,children:P.beyond?(0,ue.jsx)(ti,{kinds:P.beyond}):P.aggregate?.opens?(0,ue.jsx)(ri,{node:P}):(0,ue.jsx)(ni,{node:P,mode:"scene",selected:y.includes(P.id),...Ci(P)?{fidelity:"glyph"}:{}})},P.id));return(0,ue.jsxs)("div",{ref:v,className:`graview-ground${r?` ${r}`:""}`,"data-graview-altitude":c.overview?"":void 0,"data-graview-reach":te.city?Ha(mt(D)):void 0,"data-graview-settled":te.t>=1&&!dt.gliding()?"":void 0,"data-graview-box":M?`${M.width}x${M.height}`:void 0,onPointerDown:pt,onPointerMove:Xe,onPointerUp:qe,onPointerCancel:qe,onClick:P=>{Se.current||P.target.closest("[data-graview-view], button, aside, section[aria-label], [data-graview-offstage], a, input, select")||(x([]),f(null))},style:{position:"relative",width:"100%",height:"100%",cursor:G?"grabbing":"grab",touchAction:"none","--graview-altitude":c.overview?1:0,...te.city?{"--graview-lattice-cell":`${te.city.cell.toFixed(2)}px`,"--graview-lattice-tilt":(te.city.tilt??.5).toFixed(3),"--graview-lattice-x":`${(te.city.originX+te.city.pan.x).toFixed(1)}px`,"--graview-lattice-y":`${(te.city.originY+te.city.pan.y).toFixed(1)}px`}:{},...G?{userSelect:"none"}:{},overflow:"hidden",...o},children:[c.overview&&te.city?(0,ue.jsx)(J.Suspense,{fallback:null,children:(0,ue.jsx)(Xa,{frame:te,...Fe,pan:te.city.pan,store:u,graphVersion:A,selection:y,view:{overview:c.overview,focusId:c.focusId,beside:C},emphasis:p,hiddenKinds:l.hiddenKinds,drawn:tt})}):null,(0,ue.jsx)("div",{ref:R,"aria-hidden":"true",style:{position:"absolute",top:0,right:0,width:"var(--graview-dock, 0px)",height:"var(--graview-sheet, 0px)",visibility:"hidden",pointerEvents:"none"}}),te.city?(0,ue.jsx)(J.Suspense,{fallback:null,children:(0,ue.jsx)(Za,{frame:te,...Fe,pan:te.city?te.city.pan:j,brand:b,pinned:z,close:N*H>1.2,swallowed:Se,...c.overview?{chosen:sn(y,{overview:c.overview,focusId:c.focusId,beside:C},P=>u.graph.getNode(P)?.kind).records}:{},onFocus:P=>{let oe=Re(P);oe!==null&&h(he=>ut(he,Ee(oe)))}})}):null,et?(0,ue.jsx)("div",{"data-graview-stage":"dom","data-graview-world":"",style:{...ne,overflow:"hidden"},children:nt}):(0,ue.jsx)("canvas",{ref:q,"data-graview-stage":"gpu",layoutsubtree:"",...Fe,style:{display:"block",...ne},children:nt}),c.overview&&!G?(0,ue.jsx)(zr,{result:D,schema:u.schema,onGo:P=>{Qe(P.x,P.y),g()}}):null,c.overview?(0,ue.jsx)(Ja,{zoom:H,zoomBy:P=>E.current(P),above:de,setAbove:le}):null,(0,ue.jsx)(Mi,{frame:te,focusId:c.focusId,beside:C,holding:re,...Fe,scheme:s,overview:!!c.overview,selection:y,emphasis:p,stageRef:v,store:u,graphNodes:A,...(P=>P?{provisional:P}:{})(Si(u)),onPickEdge:(P,oe)=>{Se.current||(x([P]),f(oe?{...oe,on:P}:null))},liveOf:P=>{let oe=Pe(P.from),he=Pe(P.to);return oe?.wrote&&he?.wrote?oe.at>he.at?oe:he:void 0}}),(0,ue.jsx)(Vr,{width:D.width,whereIs:ve}),(0,ue.jsx)(Wr,{marks:Ht.marks,questions:[...O.values()].filter(P=>P.mode==="asking"&&P.at!==null&&P.say).map(P=>({id:P.at,who:P.who,asks:P.say})),whereIs:ve,stageRef:v,...Fe}),(0,ue.jsx)(Ri,{nodes:te.nodes,moving:te.t<1,holding:re,scheme:s,width:D.width,stageRef:v}),i]})}var Ke=se(Te(),1);function ts(){return Fi(),null}var Bi=()=>window.location.pathname.endsWith(Zo),Hi=()=>(Bi()?tr:Jn)(window.location.hash),ns=e=>(Bi()?nr:Zn)(e);function Fi(){let{view:e,setView:t,views:n,principal:r}=ge(),o=JSON.stringify(r),a=(0,Ke.useCallback)(d=>{let c=d.within?.view;if(c===void 0||d.focusId)return d;let h=n.places().find(y=>y.as===c);return h?{...d,focusId:Ee(h.kind)}:d},[n]),i=(0,Ke.useRef)(!1);(0,Ke.useEffect)(()=>{if(typeof window>"u")return;let d=a(Hi());!kn(d,Qn)&&!kn(d,e)&&(i.current=!0,t(d))},[]),(0,Ke.useEffect)(()=>{if(typeof window>"u")return;let d=()=>t(a(Hi()));return window.addEventListener("popstate",d),window.addEventListener("hashchange",d),()=>{window.removeEventListener("popstate",d),window.removeEventListener("hashchange",d)}},[t,a]);let l=(0,Ke.useRef)(!1),u=(0,Ke.useRef)(null),s=(0,Ke.useRef)(o);(0,Ke.useEffect)(()=>{if(typeof window>"u")return;if(i.current){i.current=!1;return}let d=s.current!==o;s.current=o;let c=ns(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:Et.at},"",h);return}if(d||ji(u.current,e)){window.history.replaceState({graview:Et.at},"",h),u.current=e;return}u.current=e,window.history.pushState({graview:++Et.at},"",h),Et.depth=Et.at,Et.tell()},[e,o])}function ji(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(",")&&os(e.within,t.within):!1}function os(e,t){let n=r=>Object.entries(r??{}).sort(([o],[a])=>o.localeCompare(a)).map(([o,a])=>`${o}=${a}`).join("&");return n(Di(e))===n(Di(t))}function Di(e){if(!e||!("q"in e))return e;let{q:t,...n}=e;return n}var Ko=se(Te(),1);function rs(e={}){let{store:t,selection:n,principal:r,providers:o}=ge(),{about:a,...i}=e,l=a??n,u=Rt();return(0,Ko.useMemo)(()=>{let s=[...new Set(l.flatMap(c=>tn(c)))],d=l.map(c=>kt(c)).filter(c=>c!==null);return vr(t,l,{principal:r,kindSelection:s,edgeSelection:d,...o?{providers:o}:{},...i})},[t,l,e,u,r,o])}function is(){let{store:e,principal:t}=ge();return(0,Ko.useMemo)(()=>({preview:(n,r)=>Sr(e,n,r??{}),apply:(n,r)=>kr(e,n,r??{},{author:t})}),[e,t])}export{zi as a,na as b,oa as c,ra as d,ia as e,aa as f,sa as g,es as h,ts as i,rs as j,is as k};
@@ -0,0 +1 @@
1
+ import{a as v,c as w}from"./chunk.XXHNV24G.js";import{D as S}from"./chunk.Z56B2JR2.js";var x="graview:pins",f={pinned:[],unpinned:[]},g=e=>Array.isArray(e)?e.filter(n=>typeof n=="string"):[];function L(){try{let e=globalThis.localStorage?.getItem(x);if(!e)return f;let n=JSON.parse(e);if(Array.isArray(n))return{pinned:g(n),unpinned:[]};if(typeof n=="object"&&n!==null){let r=n;return{pinned:g(r.pinned),unpinned:g(r.unpinned)}}return f}catch{return f}}function P(e){try{globalThis.localStorage?.setItem(x,JSON.stringify(e))}catch{}}function b(e,n,r=!1){let o=s=>s.filter(p=>p!==n),i=r?e.unpinned.includes(n)?{pinned:o(e.pinned),unpinned:o(e.unpinned)}:{pinned:o(e.pinned),unpinned:[...e.unpinned,n]}:e.pinned.includes(n)?{pinned:o(e.pinned),unpinned:o(e.unpinned)}:{pinned:[...e.pinned,n],unpinned:o(e.unpinned)};return P(i),i}var C=e=>`ai:${e.name??(e.complete||e.turn?"model":"on-device")}`;var A="Llama-3.2-3B-Instruct-q4f16_1-MLC",R=new Map;function E(e={}){let n=e.load?null:e.model??A,r=n?R.get(n)??R.set(n,{engine:null,failed:null}).get(n):{engine:null,failed:null},o=r.engine,i=!1,s=t=>e.onStatus?.(t),p=async()=>{if(e.load)return e.load();let t=globalThis.LanguageModel;if(t){let m=await t.create();return{chat:{completions:{create:async({messages:h})=>({choices:[{message:{content:await m.prompt(h[h.length-1]?.content??"")}}]})}}}}if(!globalThis.navigator?.gpu)throw new Error("this browser has no WebGPU, which the local model needs");return(await import("https://esm.run/@mlc-ai/web-llm")).CreateMLCEngine(e.model??A,{initProgressCallback:m=>s({state:"warming",progress:m.progress,detail:m.text})})},a=Promise.resolve();return{complete:async t=>{if(o=r.engine??o,!o)throw new Error("The local model is not warm yet");let l=(await o.chat.completions.create({messages:[{role:"user",content:t}]})).choices?.[0]?.message?.content;if(typeof l!="string")throw new Error("The local model answered with no content");return l},ready:()=>(r.engine??o)!==null,warm:()=>(o=r.engine??o,o?Promise.resolve():i?a:r.failed!==null?(s({state:"failed",detail:r.failed}),Promise.resolve()):(i=!0,s({state:"warming"}),a=p().then(t=>{o=t,r.engine=t,s({state:"ready"})}).catch(t=>{r.failed=t instanceof Error?t.message:String(t),s({state:"failed",detail:r.failed})}).finally(()=>{i=!1}),a)),failed:()=>r.failed}}function T(e,n={}){return O(e,n)?.complete}function O(e,n){let r=e.turn,o=e.complete??(r?p=>r({system:"",messages:[{role:"user",content:p}],tools:[],call:async()=>({error:"No tools here."})}):void 0);if(o)return{complete:o,ready:()=>!0,warm:()=>Promise.resolve(),failed:()=>null};if(!e.onDevice)return;let i=typeof e.onDevice=="object"?e.onDevice.model:void 0,s=E({...i?{model:i}:{},...n.onStatus?{onStatus:n.onStatus}:{}});return{complete:async p=>(s.ready()||s.warm(),s.complete(p)),ready:s.ready,warm:s.warm,failed:s.failed}}function D(e,n={}){let r=n.floor??v(),o=(a,c,d)=>r(d?.principal?a.seenBy(d.principal):a,c,d),i=O(e,n);if(!i)return async(a,c,d)=>{let t=await o(a,c,d);return t.unsure?{...t,say:e.withoutModel??S}:t};let s=w({complete:i.complete,...e.turn?{turn:e.turn}:{}}),p=C(e);return async(a,c,d)=>{let t=await o(a,c,d);if(t.grounded)return t;if(!i.ready()){if(await Promise.race([i.warm(),new Promise(l=>setTimeout(l,100))]),i.failed()!==null)return y(t,"(AI isn't available in this browser, so this is from the app alone.)");if(!i.ready())return y(t,"(AI is still getting ready on this device, so this is from the app alone.)")}let u;try{let l=await s(a,c,{...d,...t.proposals.length>0?{reading:t.proposals}:{}});if(!l.unsure)return l.proposals.length===0&&t.proposals.length>0?t:{...l,via:p}}catch(l){u=j(l)}return y(t,u?`(AI didn't answer just now: ${u}. This is from the app alone.)`:"(AI didn't answer just now, so this is from the app alone.)")}}var j=e=>{if(!(e instanceof Error)||e.name!=="Error")return;let n=e.message.replace(/[()]/g,"").replace(/\s+/g," ").trim().replace(/[.!]+$/,"");return n&&n.length<=160?n:void 0};function y(e,n){return{...e,say:`${e.say} ${n}`}}export{L as a,b,T as c,D as d};
@@ -0,0 +1 @@
1
+ import{eb as w,kb as S}from"./chunk.HLLWKSZB.js";function B(s){return[...s.mutations??[],...S(s.schema,s.mutations??[])]}function b(s){let i=[...s.schema.kinds],a=B(s),d=new Map,c=new Map;for(let n of a){c.set(n.name,n.creates??[]);let e=w(n.input).filter(t=>!t.optional&&!t.kinds.includes("*")).flatMap(t=>t.kinds);d.set(n.name,[...new Set(e)])}let g=new Map;for(let n of i)g.set(n,[]);for(let n of a)for(let e of c.get(n.name)??[])g.get(e)?.push(n.name);let p=new Map,l=new Set;for(let n=0;;n+=1){let e=[];for(let t of a)if((d.get(t.name)??[]).every(o=>l.has(o)))for(let o of c.get(t.name)??[])l.has(o)||e.push(o);if(e.length===0)break;for(let t of e)l.add(t),p.set(t,n)}let h=n=>{let e=g.get(n)??[];if(e.length===0)return[];let t=e.map(r=>d.get(r)??[]).sort((r,o)=>r.length-o.length)[0];return[...new Set(t)].filter(r=>r!==n)},y=new Map,u=n=>{let e=y.get(n);if(e)return e;let t=new Set;y.set(n,t);for(let r of h(n)){t.add(r);for(let o of u(r))t.add(o)}return t.delete(n),t},f=new Map(i.map(n=>[n,0]));for(let n of i)for(let e of u(n))f.set(e,(f.get(e)??0)+1);let m=i.map(n=>({kind:n,madeBy:[...g.get(n)??[]].sort(),needs:[...h(n)].sort(),depth:p.get(n)??null})).sort((n,e)=>(n.depth??Number.MAX_SAFE_INTEGER)-(e.depth??Number.MAX_SAFE_INTEGER)||(f.get(e.kind)??0)-(f.get(n.kind)??0)||n.kind.localeCompare(e.kind)),k=m.filter(n=>n.depth===0).map(n=>n.kind),A=[...new Set(a.filter(n=>(d.get(n.name)??[]).length===0).filter(n=>(c.get(n.name)??[]).length>0).map(n=>n.name))].sort(),M=m.filter(n=>n.depth===null).map(n=>({kind:n.kind,why:n.madeBy.length===0?"no act declares that it creates this kind":`every act that makes it needs ${n.needs.map(e=>`"${e}"`).join(", ")}, which nothing can make first`}));return{order:m,roots:k,doors:A,unreachable:M}}export{b as a};
@@ -0,0 +1 @@
1
+ import{C as G,s as O,u as v,v as C,w as S}from"./chunk.GS4T26WW.js";import{F as I,U as m,c as V,j as g,l as p,m as y,n as u,o as D,v as B,z as E}from"./chunk.Z56B2JR2.js";import{$ as M,$b as k,_b as P,bc as R,cc as T}from"./chunk.HLLWKSZB.js";import{b as A}from"./chunk.AJZBJBMO.js";var W=A(I(),1);function j(e,t){try{t.length===0?localStorage.removeItem(v(e)):localStorage.setItem(v(e),JSON.stringify(t))}catch{}}function F(e,t){j(e,[...S(e).filter(n=>n.title!==t.title),t])}function H(e,t){j(e,S(e).filter(n=>n.title!==t))}function J(e,t){for(let n of e.places().filter(o=>o.title===t))e.forget?.(n.kind,n.as)}var U=e=>e===!0?{written:!0}:typeof e=="object"&&e!==null?{written:e.kept===!0,...e.said?{said:e.said}:{}}:{written:!1},N=e=>({title:e.title,lens:e.lens,on:e.on,...e.bindings?{bindings:e.bindings}:{},...e.options?{options:e.options}:{}});function Z(e,t){let n=o=>t.some(r=>r.title===o||r.as===P(o));if(!n(e))return e;for(let o=2;;o++)if(!n(`${e} ${o}`))return`${e} ${o}`}function ie(e){let{store:t,views:n,brand:o,seatTalk:r,onKeepLens:d}=m(),h=(0,W.useContext)(O),L=C(o,t.schema),b=async f=>{let{edit:i}=f;if(f.written&&d)try{await d({op:"remove-lens",title:i.title,on:i.on})}catch{}H(L,i.title),J(n,i.title),h?.dismiss(`kept:${i.title}`),r.setTurns(l=>[...l.map(s=>s.kept&&s.kept.edit.title===i.title&&!s.kept.taken?{...s,kept:{...s.kept,taken:!0}}:s),{role:"seat",text:`Took \u201C${i.title}\u201D back out of the places.`}]);let a=M(t.schema,i.on);e({to:"kind",kind:i.on,title:a,address:k(t.schema,i.on),said:`Went to ${a}.`})};return{keep:async f=>{let i=Z(f.edit.title,n.places()),a={...f.edit,title:i},l=!1,s;if(d)try{({written:l,said:s}=U(await d(a)))}catch{l=!1}l||F(L,N(a)),G(n,t.schema,[N(a)]);let K=n.places(),c=K.find(w=>w.title===i),x=s??(l?`Kept \u201C${i}\u201D as a lens: it is in the places now.`:d?`Kept \u201C${i}\u201D as your own lens. Ask the owner to keep it for everyone.`:`Kept \u201C${i}\u201D as your own lens.`),$={edit:a,written:l};r.setDraft(null),r.setTurns(w=>[...w,{role:"seat",text:x,kept:$}]),r.get().open||h?.notify({kind:"toast",id:`kept:${i}`,sentence:x,timeout:1e4,action:{label:"Take back",onSelect:()=>void b($)}}),c&&e({to:"picture",kind:c.kind,as:c.as,title:i,address:R(c.as,T(c,K)?k(t.schema,c.kind).slice(1):void 0),said:`Went to ${i}.`})},takeBack:b}}var q=A(I(),1);function _(e,t){switch(t.to){case"place":return{view:V("#")};case"picture":return{view:u(E(p(e,"filter",null),t.kind,t.as),[])};case"kind":{let n=D(y({...g(e,B(t.kind)),relation:null},!1),!0);return{view:u(p(p(n,"view",null),"filter",t.filter??null),[])}}case"record":return{view:u(g(y(p(p(e,"view",null),"filter",null),!1),t.id),[t.id])};case"problems":return{pane:"problems"}}}function z(e){let t=typeof document>"u"?null:document.querySelector('[data-testid="standing"]');t&&t.getAttribute("aria-expanded")==="true"!==e&&t.click()}function ae(){let{setView:e,seatTalk:t}=m();return(0,q.useCallback)(n=>{t.get().draft&&t.setDraft(null),z(n.to==="problems"),n.to!=="problems"&&e(o=>{let r=_(o,n);return"view"in r?r.view:o})},[e,t])}export{ie as a,z as b,ae as c};
@@ -0,0 +1 @@
1
+ function w(e){let t=e+1;return t*t-g(t).length}function g(e){if(e<3)return[];if(e%2===1){let i=(e-1)/2;return[[i,i]]}let t=e/2-1,r=e/2;return[[t,t],[r,t],[t,r],[r,r]]}function p(e){let t=2166136261;for(let r=0;r<e.length;r++)t=Math.imul(t^e.charCodeAt(r),16777619);return(t>>>0)%1e3/1e3}function M(e,t){let r=e.side+1,i=new Set(g(r).map(([o,n])=>`${o},${n}`)),a=e.side/r,d=[];for(let o=0;o<r;o++)for(let n=0;n<r;n++)i.has(`${n},${o}`)||d.push([n,o]);d.sort((o,n)=>o[0]+o[1]-(n[0]+n[1])||o[0]-n[0]);let c=t.slice(0,d.length);return{buildings:c.map((o,n)=>{let[u,m]=d[n];return{id:o,col:e.col+(u+.5)*a,row:e.row+(m+.5)*a,footprint:a*.62,height:.55+p(o)*.7}}),rest:Math.max(0,t.length-c.length)}}var b={done:.12,waiting:.55,active:1.05};function k(e,t,r=[]){let i=e.side,a=i/Math.max(1,t.length),d=Math.max(1,...t.map(s=>s.length)),c=a;for(let s=1;a/s>=i/8-1e-9&&(c=a/s,!(s*Math.floor(i/c+1e-9)>=d));s++);let f=Math.max(1,Math.floor(a/c+1e-9)),o=Math.max(1,Math.floor(i/c+1e-9)),n=i/o,u=[],m=[];return t.forEach((s,l)=>{let h=s.slice(0,f*o);h.forEach((x,y)=>{u.push({id:x,lane:l,col:e.col+(y%o+.5)*n,row:e.row+l*a+(Math.floor(y/o)+.5)*c,footprint:Math.min(n,c)*.66,height:r[l]??b.waiting})}),s.length>h.length&&m.push({lane:l,count:s.length-h.length,col:e.col-.15,row:e.row+(l+.5)*a})}),u.sort((s,l)=>s.col+s.row-(l.col+l.row)||s.col-l.col),{blocks:u,rests:m}}export{w as a,p as b,M as c,b as d,k as e};