graview 0.1.39 → 0.1.40

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 (173) hide show
  1. package/dist/preview/{chunk.WQPNGBR7.js → chunk.242EUAPE.js} +1 -1
  2. package/dist/preview/chunk.2CF2XKOS.js +1 -0
  3. package/dist/preview/chunk.2FGYWAID.js +1 -0
  4. package/dist/preview/{chunk.NSNGPQGT.js → chunk.2FLPDPEL.js} +1 -1
  5. package/dist/preview/{chunk.ZTMDU3OH.js → chunk.2GDXNTY5.js} +1 -1
  6. package/dist/preview/{chunk.C4CFYTCW.js → chunk.2JB4Y2ET.js} +1 -1
  7. package/dist/preview/chunk.2NXH7VAI.js +1 -0
  8. package/dist/preview/chunk.2OSNYF5C.js +1 -0
  9. package/dist/preview/{chunk.Z7JRBKA7.js → chunk.2RVUDRRY.js} +1 -1
  10. package/dist/preview/{chunk.5OJJ2TKZ.js → chunk.2WACBAUN.js} +2 -2
  11. package/dist/preview/chunk.35PHXNOC.js +1 -0
  12. package/dist/preview/{chunk.WJQY4E45.js → chunk.3Q75TIGL.js} +1 -1
  13. package/dist/preview/{chunk.HHUCPVG5.js → chunk.42XSBKPO.js} +1 -1
  14. package/dist/preview/{chunk.6CFP5UYP.js → chunk.47KHZCNG.js} +1 -1
  15. package/dist/preview/{chunk.U7QMA4H7.js → chunk.4QPVS2ZM.js} +1 -1
  16. package/dist/preview/{chunk.NG3YMQ36.js → chunk.4VG2KN7G.js} +1 -1
  17. package/dist/preview/{chunk.6XU2CXRZ.js → chunk.5RABSIF7.js} +1 -1
  18. package/dist/preview/{chunk.7EFNLMKU.js → chunk.67WWRC6Y.js} +1 -1
  19. package/dist/preview/{chunk.QMFUPTR4.js → chunk.6AVZWLRF.js} +1 -1
  20. package/dist/preview/{chunk.C2OAKTZX.js → chunk.6CRRPXKP.js} +1 -1
  21. package/dist/preview/{chunk.WXYUWBKX.js → chunk.6FNMDAX5.js} +1 -1
  22. package/dist/preview/{chunk.U4E5GQTK.js → chunk.6J37UQKG.js} +1 -1
  23. package/dist/preview/chunk.6JEU3ZNE.js +1 -0
  24. package/dist/preview/{chunk.RXSHFG6S.js → chunk.6PSWHBL2.js} +1 -1
  25. package/dist/preview/chunk.74NOI7QN.js +1 -0
  26. package/dist/preview/{chunk.VC4JPG7O.js → chunk.7LIKEE5Z.js} +1 -1
  27. package/dist/preview/{chunk.2NSTEREJ.js → chunk.7WPCP2LZ.js} +1 -1
  28. package/dist/preview/{chunk.JEZTPXEB.js → chunk.ACBUAIDF.js} +1 -1
  29. package/dist/preview/{chunk.EWWJMS6G.js → chunk.AKQXF7GW.js} +1 -1
  30. package/dist/preview/chunk.AUBGUDO5.js +1 -0
  31. package/dist/preview/{chunk.G46WGK5E.js → chunk.AVKDWISO.js} +1 -1
  32. package/dist/preview/{chunk.5JPRFXYQ.js → chunk.AWX7GP72.js} +1 -1
  33. package/dist/preview/chunk.BFNVG5JE.js +1 -0
  34. package/dist/preview/chunk.BNVMMOOY.js +1 -0
  35. package/dist/preview/{chunk.5XNVN4HE.js → chunk.BSAXZQSY.js} +1 -1
  36. package/dist/preview/{chunk.B7TB6YRZ.js → chunk.BXT6FDT4.js} +1 -1
  37. package/dist/preview/{chunk.FCXBCKED.js → chunk.C2PECN4C.js} +1 -1
  38. package/dist/preview/{chunk.OJKS3UQS.js → chunk.CL2ZS5EQ.js} +1 -1
  39. package/dist/preview/chunk.CN5WAKHJ.js +5 -0
  40. package/dist/preview/{chunk.I7CU2E3C.js → chunk.CNFL5IN5.js} +1 -1
  41. package/dist/preview/{chunk.M5QFUGGG.js → chunk.D25XEVKO.js} +1 -1
  42. package/dist/preview/{chunk.P3JYH6HO.js → chunk.DL26BKT7.js} +1 -1
  43. package/dist/preview/{chunk.23WYWIAJ.js → chunk.DPZTW24D.js} +1 -1
  44. package/dist/preview/chunk.ESSSNLEO.js +1 -0
  45. package/dist/preview/chunk.ETOGQE2V.js +1 -0
  46. package/dist/preview/{chunk.XLZ2QRRS.js → chunk.FDE3TSTK.js} +1 -1
  47. package/dist/preview/{chunk.37ASLBGE.js → chunk.FFZBOP65.js} +1 -1
  48. package/dist/preview/chunk.FOQZADMA.js +25 -0
  49. package/dist/preview/{chunk.5R4E5C76.js → chunk.G6VZNRQ5.js} +1 -1
  50. package/dist/preview/{chunk.OM5CDW2S.js → chunk.GT2BITLW.js} +1 -1
  51. package/dist/preview/{chunk.CF7DHTKL.js → chunk.GTV2VZAS.js} +2 -2
  52. package/dist/preview/{chunk.IXYBIDAN.js → chunk.GY6RYJHM.js} +1 -1
  53. package/dist/preview/chunk.GZIVMOY4.js +117 -0
  54. package/dist/preview/{chunk.UIUHGA6W.js → chunk.H5ADMSE7.js} +1 -1
  55. package/dist/preview/{chunk.XBOZTQQA.js → chunk.H5HWN7A2.js} +1 -1
  56. package/dist/preview/{chunk.7WSXVXP3.js → chunk.H6XKMLDQ.js} +1 -1
  57. package/dist/preview/{chunk.OYMM2UWE.js → chunk.H7POIT3V.js} +1 -1
  58. package/dist/preview/{chunk.CMN6VVK2.js → chunk.HB7ELBVK.js} +1 -1
  59. package/dist/preview/{chunk.IAZRY42B.js → chunk.HPAGOEZG.js} +1 -1
  60. package/dist/preview/{chunk.4BBJ62ZO.js → chunk.I7XSDXQ3.js} +1 -1
  61. package/dist/preview/{chunk.WTZOOAIW.js → chunk.IDUPJMJO.js} +1 -1
  62. package/dist/preview/chunk.IFTWVUJO.js +2 -0
  63. package/dist/preview/{chunk.FMN5XDLE.js → chunk.ISXFH3CK.js} +1 -1
  64. package/dist/preview/chunk.J4IULZFD.js +1 -0
  65. package/dist/preview/chunk.JACGQ2PR.js +4 -0
  66. package/dist/preview/{chunk.YXGI7H4Y.js → chunk.JDRLSVOI.js} +1 -1
  67. package/dist/preview/chunk.JLDBFX6O.js +1 -0
  68. package/dist/preview/{chunk.LCYMYLOP.js → chunk.JQEYZB5I.js} +1 -1
  69. package/dist/preview/{chunk.ZR5KVYWZ.js → chunk.L3A6YLMT.js} +2 -2
  70. package/dist/preview/chunk.LLEFYJPJ.js +344 -0
  71. package/dist/preview/chunk.LOZJQ5ZX.js +1 -0
  72. package/dist/preview/{chunk.GXKECZ4S.js → chunk.LPBM5AES.js} +1 -1
  73. package/dist/preview/{chunk.QEXXLWEU.js → chunk.LPE4FLC6.js} +2 -2
  74. package/dist/preview/{chunk.TU4KG22J.js → chunk.MIM2QLF5.js} +2 -2
  75. package/dist/preview/{chunk.P4WYBSYA.js → chunk.N2K25KH3.js} +1 -1
  76. package/dist/preview/{chunk.KJNUZYXS.js → chunk.N6MVK3KD.js} +1 -1
  77. package/dist/preview/{chunk.3ZNQ5YKX.js → chunk.NGDXH66B.js} +1 -1
  78. package/dist/preview/chunk.O5JKDFDH.js +1 -0
  79. package/dist/preview/chunk.O6F3K6CU.js +1 -0
  80. package/dist/preview/{chunk.HA3PPIEQ.js → chunk.OW7NSJ4H.js} +1 -1
  81. package/dist/preview/chunk.P5ODICND.js +32 -0
  82. package/dist/preview/{chunk.67USHK26.js → chunk.PPG2SEIY.js} +1 -1
  83. package/dist/preview/chunk.PYNYHNDS.js +1 -0
  84. package/dist/preview/{chunk.JBTU2PJ4.js → chunk.Q4TZHWQX.js} +1 -1
  85. package/dist/preview/chunk.QCWZSSNC.js +1 -0
  86. package/dist/preview/chunk.QIV65FWE.js +1 -0
  87. package/dist/preview/chunk.R5WY567U.js +88 -0
  88. package/dist/preview/{chunk.GP2F7TIN.js → chunk.RCM7NOPF.js} +2 -1
  89. package/dist/preview/{chunk.F5UVEF2R.js → chunk.S2U5CEP4.js} +1 -1
  90. package/dist/preview/chunk.S356ACK2.js +1 -0
  91. package/dist/preview/{chunk.W4OX4BMP.js → chunk.SIGC3G7S.js} +1 -1
  92. package/dist/preview/{chunk.LP3QUPCE.js → chunk.STI447YW.js} +1 -1
  93. package/dist/preview/chunk.T3TYD7QI.js +1 -0
  94. package/dist/preview/{chunk.BYKR7NEE.js → chunk.T73RB7LC.js} +1 -1
  95. package/dist/preview/chunk.TD2LNFUB.js +1 -0
  96. package/dist/preview/{chunk.2BJRS3YJ.js → chunk.TGVUIFKD.js} +1 -1
  97. package/dist/preview/{chunk.AYHCQWSU.js → chunk.TIH2PDFH.js} +1 -1
  98. package/dist/preview/chunk.TKUNRFDE.js +1 -0
  99. package/dist/preview/{chunk.6DHHUBSC.js → chunk.TNESS3LQ.js} +1 -1
  100. package/dist/preview/chunk.UHI3D7JC.js +1 -0
  101. package/dist/preview/{chunk.XLI44BBI.js → chunk.UOPKRN55.js} +1 -1
  102. package/dist/preview/{chunk.RM7NVN7B.js → chunk.UTCB3CE7.js} +2 -2
  103. package/dist/preview/{chunk.H5CZZZLX.js → chunk.UUBYFBPN.js} +1 -1
  104. package/dist/preview/{chunk.ROINZMNO.js → chunk.UWW6ZEPY.js} +2 -2
  105. package/dist/preview/chunk.V5MYKNL7.js +5 -0
  106. package/dist/preview/{chunk.DYNBWIPF.js → chunk.VDAMCTNL.js} +1 -1
  107. package/dist/preview/{chunk.ROKRQRID.js → chunk.VF7P3ZVZ.js} +1 -1
  108. package/dist/preview/chunk.VIYECFKZ.js +6 -0
  109. package/dist/preview/{chunk.ITEF3U2E.js → chunk.VJXXCUKS.js} +1 -1
  110. package/dist/preview/{chunk.EBHKKOPO.js → chunk.VNUHESMZ.js} +1 -1
  111. package/dist/preview/chunk.VZYCILPJ.js +1 -0
  112. package/dist/preview/chunk.W4HBRXMY.js +1 -0
  113. package/dist/preview/chunk.W7R2GFBW.js +47 -0
  114. package/dist/preview/chunk.WBLHCH5M.js +1 -0
  115. package/dist/preview/{chunk.CC47O2DW.js → chunk.WVDKYUF3.js} +1 -1
  116. package/dist/preview/{chunk.BEC5ZH2L.js → chunk.XEKLEHC3.js} +1 -1
  117. package/dist/preview/{chunk.FILCNVGH.js → chunk.XFZKP4IF.js} +1 -1
  118. package/dist/preview/{chunk.CAMQ7MYJ.js → chunk.XQHDP5C3.js} +1 -1
  119. package/dist/preview/{chunk.UB3O3QJQ.js → chunk.XRYTJNA7.js} +1 -1
  120. package/dist/preview/chunk.YO24NALN.js +1 -0
  121. package/dist/preview/{chunk.4PNFX3TX.js → chunk.YWNHCZQ5.js} +1 -1
  122. package/dist/preview/{chunk.4ECICQ2S.js → chunk.YYFLTMNN.js} +1 -1
  123. package/dist/preview/{chunk.CTK2P4JV.js → chunk.YYIKSH2F.js} +2 -2
  124. package/dist/preview/{chunk.B2IRADR2.js → chunk.Z5AB2DBF.js} +1 -1
  125. package/dist/preview/{chunk.C6X7CKU6.js → chunk.Z7LDT55A.js} +1 -1
  126. package/dist/preview/{chunk.EDC4EMIX.js → chunk.ZGCRMNER.js} +1 -1
  127. package/dist/preview/{chunk.2IX3CZNP.js → chunk.ZHLQWMV5.js} +1 -1
  128. package/dist/preview/{chunk.2GGDOFTF.js → chunk.ZJMDLRC5.js} +1 -1
  129. package/dist/preview/{chunk.N2SV3KX7.js → chunk.ZK3X23EU.js} +1 -1
  130. package/dist/preview/{chunk.JCR3ECUM.js → chunk.ZOR6FKNI.js} +1 -1
  131. package/dist/preview/{chunk.STBJV6HJ.js → chunk.ZRLXVYPG.js} +1 -1
  132. package/dist/preview/index.html +45 -43
  133. package/dist/preview/page.js +8 -8
  134. package/package.json +6 -6
  135. package/dist/preview/chunk.2HF54MYG.js +0 -1
  136. package/dist/preview/chunk.2RCNSHXK.js +0 -1
  137. package/dist/preview/chunk.546WEHEX.js +0 -47
  138. package/dist/preview/chunk.57OPL5WD.js +0 -1
  139. package/dist/preview/chunk.5ZMENPY4.js +0 -5
  140. package/dist/preview/chunk.6HBEYRJU.js +0 -1
  141. package/dist/preview/chunk.6L7IDF3J.js +0 -1
  142. package/dist/preview/chunk.ALDLAQ7V.js +0 -1
  143. package/dist/preview/chunk.BCHHBGM6.js +0 -1
  144. package/dist/preview/chunk.BL4S3I2N.js +0 -1
  145. package/dist/preview/chunk.BS3FX4PX.js +0 -1
  146. package/dist/preview/chunk.BTSXYZ6Z.js +0 -25
  147. package/dist/preview/chunk.BZSU4HH2.js +0 -1
  148. package/dist/preview/chunk.DAA7IDQ4.js +0 -1
  149. package/dist/preview/chunk.E3HXXUKY.js +0 -1
  150. package/dist/preview/chunk.EM4Y4YAD.js +0 -2
  151. package/dist/preview/chunk.FGDHEVH4.js +0 -1
  152. package/dist/preview/chunk.FJBQ4UP3.js +0 -32
  153. package/dist/preview/chunk.G23VFYGF.js +0 -88
  154. package/dist/preview/chunk.HFDYFPMJ.js +0 -1
  155. package/dist/preview/chunk.HGS32FT2.js +0 -1
  156. package/dist/preview/chunk.J3M2MZHG.js +0 -1
  157. package/dist/preview/chunk.KIJCOW25.js +0 -1
  158. package/dist/preview/chunk.L7DQKPJV.js +0 -117
  159. package/dist/preview/chunk.LP2DJ5ZB.js +0 -6
  160. package/dist/preview/chunk.N7N5OFPL.js +0 -1
  161. package/dist/preview/chunk.ORXFUK6F.js +0 -344
  162. package/dist/preview/chunk.OXTUXWMU.js +0 -1
  163. package/dist/preview/chunk.P5325GYR.js +0 -1
  164. package/dist/preview/chunk.PMER4LVT.js +0 -1
  165. package/dist/preview/chunk.PONWLTTB.js +0 -1
  166. package/dist/preview/chunk.QCF6Z2AZ.js +0 -1
  167. package/dist/preview/chunk.RWB4235L.js +0 -1
  168. package/dist/preview/chunk.SK33IHL2.js +0 -4
  169. package/dist/preview/chunk.TCUB6IDY.js +0 -1
  170. package/dist/preview/chunk.TJCTTJWE.js +0 -1
  171. package/dist/preview/chunk.UCZR33MK.js +0 -1
  172. package/dist/preview/chunk.UGCNMAPC.js +0 -1
  173. package/dist/preview/chunk.XDYAG276.js +0 -1
@@ -1,4 +1,4 @@
1
- import{a as k}from"./chunk.G4JJXA63.js";import{a as Q}from"./chunk.B2IRADR2.js";import{a as Y}from"./chunk.IAZRY42B.js";import{a as X}from"./chunk.4BBJ62ZO.js";import{c as _}from"./chunk.2IX3CZNP.js";import{_c as G,ad as H,bd as P,cd as J,ib as q,jb as z}from"./chunk.5ZMENPY4.js";var O=e=>"failed"in e;function ue(e,n){let r=e.schema.kinds,t=e.policy?.sees;if(!t?.length||z(n))return{kinds:r};let o=q(n).roles??[],i=new Set(t.filter(s=>s.roles==="*"||o.some(a=>s.roles.includes(a))).flatMap(s=>s.kinds));return{kinds:r.filter(s=>i.has(s))}}function L(e,n){if(!n)return e;let r=new Set(n.kinds.filter(i=>e.tryDefinition(i)!==void 0));if(r.size===e.kinds.length)return e;let t=new Map,o=i=>{if(r.has(i)){if(!t.has(i)){let s=e.tryDefinition(i),a=Object.fromEntries(Object.entries(s?.edges??{}).flatMap(([l,d])=>{if(d.to==="*")return[[l,d]];let c=d.to.filter(u=>r.has(u));return c.length>0?[[l,{...d,to:c}]]:[]}));t.set(i,{...s,edges:a})}return t.get(i)}};return{...e,definitions:e.definitions.filter(i=>r.has(i.kind)),kinds:e.kinds.filter(i=>r.has(i)),tryDefinition:o,definition:i=>{let s=o(i);if(!s)throw new Error(`Unknown node kind "${i}"`);return s}}}var fe=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),y=e=>fe(e).replace(/[-_]+/g," ").trim();function I(e){let n=[];for(let t of e.kinds){let o=e.tryDefinition(t);if(!o)continue;let i=o.display?.labels??{},s=Object.entries(o.fields?.shape??{}).filter(([d])=>d!=="id"&&d!=="kind").map(([d,c])=>{let u=X(c);return{name:d,type:u?.type,...u?.options?{options:u.options}:{},words:(i[d]??y(d)).toLowerCase()}}),a=Object.entries(o.edges??{}).map(([d,c])=>({name:d,from:t,to:c.to==="*"?e.kinds.filter(u=>u!==t):c.to,words:y(d)})),l=(o.plural??`${y(t)}s`).toLowerCase();n.push({kind:t,plural:l,noun:(o.noun??y(t)).toLowerCase(),fields:s,roles:o.fieldRoles??{},edges:a})}let r=new Map(n.map(t=>[t.kind,t]));return{schema:e,kinds:n,info:t=>r.get(t)}}var $=(e,n)=>n===void 0?void 0:e.fields.find(r=>r.name===n),A=e=>e?.type==="date"||e?.type==="datetime",N=e=>e?.type==="number"||e?.type==="integer"||e?.type==="duration",re=e=>` ${e.toLowerCase().replace(/[“”"’‘]/g,"'").replace(/[^\p{L}\p{N}' -]+/gu," ").replace(/\s+/g," ").trim()} `,E=(e,n)=>e.includes(` ${n} `),x=e=>e.endsWith("ies")?`${e.slice(0,-3)}y`:e.endsWith("ses")?e.slice(0,-2):e.endsWith("s")?e.slice(0,-1):e;function pe(e,n){let r=[];for(let t of n.kinds){let o=new Set([t.plural,t.noun,`${t.noun}s`,y(t.kind),`${y(t.kind)}s`]),i=-1;for(let s of o){let a=e.indexOf(` ${s} `);a>=0&&(i<0||a<i)&&(i=a)}i>=0&&r.push({info:t,at:i})}return r.sort((t,o)=>t.at-o.at).map(t=>t.info)}function v(e,n,r){let t=n.trim().toLowerCase();if(t.length===0)return;let o=e.fields.filter(i=>!r||r(i));return o.find(i=>i.words===t||y(i.name)===t||i.name.toLowerCase()===t)??o.find(i=>i.words===x(t)||y(i.name)===x(t))??o.find(i=>t.split(" ").some(s=>s.length>2&&(i.words.split(" ").includes(s)||i.words.split(" ").includes(x(s)))))}function oe(e,n,r){let t=n.trim().toLowerCase();if(t.length!==0)return e.edges.find(o=>o.words===t||o.name.toLowerCase()===t)??e.edges.find(o=>o.to.some(i=>{let s=r.info(i);return s!==void 0&&(s.noun===x(t)||s.plural===t||y(i)===x(t))}))??e.edges.find(o=>t.split(" ").some(i=>i.length>2&&o.words.split(" ").includes(i)))}function U(e){return/ (?:grouped |group |split |sorted |organi[sz]ed )?by ([\p{L}\p{N}' -]+?)(?= (?:and|with|for|in|on|only|where|from|this|that|as|sorted|grouped) |\s*$)/u.exec(e)?.[1]?.trim()}var me=/\bwho\b.*\b(covers?|cover|tends?|owns?|handles?|does|works? on|looks? after|is on|is assigned|staffs?|runs?)\b|\bcoverage\b|\bmatrix\b|\bwho covers\b/,ge=/\bcalendar\b|\bmonth\b|\bagenda\b|\bschedule\b|\bdue\b|\bdeadlines?\b|\bdates?\b|\bwhen\b/,ye=/\btimeline\b|\bover time\b|\bgantt\b|\bspans?\b|\bweek\b/,he=/\bboard\b|\bkanban\b|\bcolumns?\b|\bpipeline\b|\bstages?\b|\bstatus\b/,be=/\blaid out\b|\blayout\b|\bseating\b|\bwhere (?:they|it|each) (?:sits?|lies?|stands?)\b|\bfloor\b/,we=/\bplan\b|\bmap\b|\bregions?\b/,ke=/\blist\b|\btable\b|\bgroup(?:ed)? by\b|\bsort(?:ed)? by\b|\bonly\b|\bjust the\b/;function $e(e){let n=[];return/\blist\b|\btable\b/.test(e)&&n.push("blocks"),me.test(e)&&n.push("coverage"),be.test(e)&&n.push("board"),(/\bfloor plan\b/.test(e)||we.test(e))&&n.push("plan"),ye.test(e)&&n.push("timeline"),ge.test(e)&&n.push("calendar"),he.test(e)&&n.push("columns"),ke.test(e)&&!n.includes("blocks")&&n.push("blocks"),n.length===0&&U(e)&&n.push("columns"),n}var se=e=>{let n=r=>r?` and not ${r}`:"";if(/\boverdue\b|\blate\b|\bpast due\b/.test(e))return{cond:(r,t)=>`days(today(), ${r}) < 0${n(t)}`,says:r=>`overdue by ${r.words}`};if(/\btoday\b/.test(e))return{range:"day",cond:r=>`days(today(), ${r}) == 0`,says:r=>`with ${r.words} today`};if(/\bthis week\b|\bnext 7 days\b|\bnext week\b/.test(e))return{range:"week",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 6`,says:r=>`with ${r.words} in the next week`};if(/\bthis month\b|\bnext 30 days\b|\bnext month\b/.test(e))return{range:"month",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 30`,says:r=>`with ${r.words} in the next month`};if(/\blast month\b|\bpast month\b/.test(e))return{range:"month",cond:r=>`days(today(), ${r}) >= -30 and days(today(), ${r}) <= 0`,says:r=>`with ${r.words} in the last month`};if(/\bthis year\b/.test(e))return{range:"year",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 365`,says:r=>`with ${r.words} in the next year`};if(/\bquarter\b/.test(e))return{range:"quarter",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 91`,says:r=>`with ${r.words} in the next quarter`}},M=e=>{if(/\bagenda\b|\bin order\b/.test(e))return"agenda";if(/\btoday\b|\bday\b/.test(e))return"day";if(/\bweek\b/.test(e))return"week";if(/\bquarter\b/.test(e))return"quarter";if(/\byears\b/.test(e))return"years";if(/\byear\b/.test(e))return"year";if(/\bmonth\b/.test(e))return"month"},Z=/^(user|person|people|member|staff|gardener|volunteer|owner|agent|employee|worker|team|player|customer|client|contact|party|attendee|guest)s?$/,j=class extends Error{},h=e=>{throw new j(e)};function Se(e,n){let r=e.fields.filter(i=>i.type==="enum");if(n){let i=v(e,n);if(i&&i.type==="enum")return i;i&&h(`${e.plural}' ${i.words} is not a choice, so it has no columns`)}let t=$(e,e.roles.status??e.roles.column);if(t?.type==="enum")return t;let o=r.find(i=>/^(status|stage|state|phase)$/.test(i.name));return o||(r[0]?r[0]:h(`${e.plural} have no choice field to put in columns`))}function ee(e,n){let r=e.fields.filter(A),t=l=>{let d=$(e,e.roles[l]);return A(d)?d:void 0},i=r.find(l=>E(n,l.words)||E(n,y(l.name)))??t("start")??r.find(l=>/^(due|date|on|at|start|starts|begins|from|sown|when)/i.test(l.name))??r[0];if(!i)return h(`no date field on ${e.plural}`);let s=t("end")??r.find(l=>l!==i&&/^(end|ends|until|to|finish|finished|harvested|due|closes|through)/i.test(l.name)),a=e.fields.find(l=>l.type==="boolean"&&/^(done|finished|complete|completed|closed)$/.test(l.name));return{start:i,...s&&s!==i?{end:s}:{},...a?{done:a}:{}}}function ie(e){let n=$(e,e.roles.start),r=$(e,e.roles.end),t=$(e,e.roles.column??e.roles.day??e.roles.columns);if(N(n)&&N(r)&&t?.type==="enum")return{start:n,end:r,column:t}}function De(e,n,r,t){let o=[];for(let s of e.kinds)for(let a of s.edges)for(let l of a.to){let d=e.info(l);if(!d||d.kind===s.kind)continue;let c=0;n.includes(s)&&(c+=4),n.includes(d)&&(c+=4),(Z.test(d.kind)||Z.test(d.noun))&&(c+=3),t&&(a.words.includes(t)||d.noun===x(t))&&(c+=5),a.words.split(" ").some(u=>u.length>2&&r.includes(` ${u}`))&&(c+=2),o.push({rows:s,across:d,link:a,score:c})}let i=o.sort((s,a)=>a.score-s.score)[0];return i||h(n[0]?`${n[0].plural} are joined to nothing else, so there is no who-covers-what to draw`:"nothing here is joined to anything else, so there is no who-covers-what to draw")}function ae(e,n,r,t,o){let i=U(t);switch(e){case"columns":{if(i){let s=v(n,i);if(!s||s.type!=="enum"){let a=oe(n,i,r);if(a){let l=r.info(a.to[0]);return{lens:"coverage",kind:n.kind,across:l.kind,link:a.name}}}}return{lens:"columns",kind:n.kind,column:Se(n,i).name}}case"calendar":{let s=ee(n,t),a=M(t);return{lens:"calendar",kind:n.kind,start:s.start.name,...s.end?{end:s.end.name}:{},...s.done?{done:s.done.name}:{},...a?{range:a}:{}}}case"timeline":{let s=ie(n);if(s&&!/\bdates?\b|\bdue\b|\bdeadlines?\b|\bmonths?\b|\byears?\b/.test(t))return{lens:"timeline",kind:n.kind,start:s.start.name,end:s.end.name,column:s.column.name};let a=ee(n,t);return{lens:"calendar",kind:n.kind,start:a.start.name,...a.end?{end:a.end.name}:{},...a.done?{done:a.done.name}:{},range:M(t)??"quarter"}}case"coverage":{let s=De(r,o,t,i);return{lens:"coverage",kind:s.rows.kind,across:s.across.kind,link:s.link.name}}case"board":{let s=$(n,n.roles.x)??n.fields.find(c=>c.name==="x"),a=$(n,n.roles.y)??n.fields.find(c=>c.name==="y");if(!N(s)||!N(a))return h(`${n.plural} have no x and y to be laid out by`);let d=r.kinds.flatMap(c=>c.edges.filter(u=>u.to.includes(n.kind)&&c.kind!==n.kind))[0]??n.edges[0];return d?{lens:"board",kind:n.kind,x:s.name,y:a.name,fill:d.name,...d.from!==n.kind?{fillFrom:"occupant"}:{}}:h(`nothing is joined to ${n.plural} to fill them`)}case"plan":{let s=$(n,n.roles.outline)??n.fields.find(a=>a.name==="outline");return s?{lens:"plan",kind:n.kind,outline:s.name}:h(`${n.plural} have no outline to draw a plan from`)}case"blocks":{let s={lens:"blocks",kind:n.kind,as:/\bcards?\b/.test(t)?"card":"row"},a=/ group(?:ed)? by ([\p{L}\p{N} -]+?)(?= (?:and|only|sorted|with)|\s*$)/u.exec(t)?.[1]??(i&&!/ sort(?:ed)? by /.test(t)?i:void 0);if(a){let c=v(n,a);if(!c||c.type!=="enum")return h(c?`${n.plural}' ${c.words} is not a choice, so they cannot be grouped by it`:`${n.plural} have nothing called ${a} to group by`);s.group=c.name}let l=/ sort(?:ed)? by ([\p{L}\p{N} -]+?)(?= (?:and|only|grouped|with)|\s*$)/u.exec(t)?.[1];if(l){let c=v(n,l);if(!c)return h(`${n.plural} have nothing called ${l} to sort by`);s.sort={by:c.name,.../\b(newest|latest|desc|descending|most)\b/.test(t)?{direction:"desc"}:{}}}let d=V(n,t);return d.length>0&&(s.where=d),s}}}function V(e,n){let r=[],t=se(n);if(t){let o=e.fields.filter(A),i=$(e,e.roles.start),s=o.find(l=>E(n,l.words))??(A(i)?i:void 0)??o[0];(!s||!A(s))&&h(`no date field on ${e.plural}`);let a=e.fields.find(l=>l.type==="boolean"&&/^(done|finished|complete|completed|closed)$/.test(l.name));r.push({expr:t.cond(s.name,/\boverdue\b|\blate\b|\bpast due\b/.test(n)?a?.name:void 0),says:t.says(s)})}if(/\bonly\b|\bjust\b|\bthat are\b|\bwhich are\b/.test(n)){for(let o of e.fields){if(o.type!=="enum")continue;let i=o.options?.find(s=>E(n,s.toLowerCase())||E(n,y(s)));i&&r.push({expr:`${o.name} == '${i.replace(/'/g,"")}'`,says:`that are ${y(i)}`})}if(/\bnot done\b|\bundone\b|\bunfinished\b|\bopen ones\b|\bstill to do\b/.test(n)){let o=e.fields.find(i=>i.type==="boolean"&&/^(done|finished|complete|completed)$/.test(i.name));o&&r.push({expr:`not ${o.name}`,says:`not ${o.words}`})}}return r}var B={columns:"A board",calendar:"A calendar",timeline:"A timeline",coverage:"A grid",board:"A layout",plan:"A plan",blocks:"A list",reach:"A picture"};function Re(e,n){let r=n.info(e.kind),t=o=>o?$(r,o)?.words??y(o):"";switch(e.lens){case"columns":return{title:`${k(r.plural)} by ${t(e.column)}`,detail:`of ${r.plural} by ${t(e.column)}`};case"calendar":{let o=e.range??"month";if(o==="agenda")return{title:`${k(r.plural)} in date order`,detail:`of ${r.plural} in order of ${t(e.start)}`};let i=o==="years"?"year":o;return{title:`${k(r.plural)} by ${i}`,detail:`of ${r.plural} by ${t(e.start)}, a ${i} at a time`}}case"timeline":return{title:`${k(r.plural)} over the ${t(e.column)}`,detail:`of ${r.plural} from ${t(e.start)} to ${t(e.end)}, by ${t(e.column)}`};case"coverage":{let o=n.info(e.across);return{title:`${k(r.plural)} by ${o.noun}`,detail:`of which ${o.noun} covers which ${r.noun}`}}case"board":return{title:`${k(r.plural)} where they stand`,detail:`of ${r.plural} where they stand`};case"plan":return{title:`${k(r.plural)} on a plan`,detail:`of ${r.plural}`};default:{let o=[e.where?.map(i=>i.says).join(" and "),e.group?`by ${t(e.group)}`:void 0,e.sort?`in order of ${t(e.sort.by)}`:void 0].filter(i=>!!i);return{title:[k(r.plural),...o].join(" "),detail:[`of ${r.plural}`,...o].join(" ")}}}}function Ae(e,n){let r={title:n,on:e.kind};switch(e.lens){case"columns":return{name:"columns",...r,bindings:{[e.kind]:{column:e.column}}};case"calendar":return{name:"calendar",...r,bindings:{[e.kind]:{start:e.start,...e.end?{end:e.end}:{},...e.done?{done:e.done}:{}}},...e.range?{options:{range:e.range}}:{}};case"timeline":return{name:"timeline",...r,bindings:{[e.kind]:{start:e.start,end:e.end,column:e.column}}};case"coverage":return{name:"coverage",...r,bindings:{rows:{kind:e.kind},columns:{kind:e.across},link:{edge:e.link}}};case"board":return{name:"board",...r,bindings:{slots:{kind:e.kind},x:{field:e.x,on:"slots"},y:{field:e.y,on:"slots"},fill:{edge:e.fill}},...e.fillFrom?{options:{fillFrom:e.fillFrom}}:{}};case"plan":return{name:"plan",...r,bindings:{regions:{kind:e.kind},outline:{field:e.outline,on:"regions"}}};default:{let t=e.where?.length?` where ${e.where.map(i=>e.where.length>1?`(${i.expr})`:i.expr).join(" and ")}`:"",o={list:`all('${e.kind}')${t}`,as:e.as??"row"};return e.group&&(o.group=e.group),e.sort&&(o.sort=e.sort.direction?{by:e.sort.by,direction:e.sort.direction}:e.sort.by),o.empty="Nothing here yet.",{name:"blocks",...r,options:{blocks:[o]}}}}}function C(e,n){let r=o=>o.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,""),t=new Set(["home","overview",...Q(n).map(o=>o.slug),...(n.lenses??[]).flatMap(o=>o.title?[r(o.title)]:[])]);if(!t.has(r(e)))return e;for(let o=2;;o++)if(!t.has(r(`${e} ${o}`)))return`${e} ${o}`}var ne={title:[],headline:[],text:["tone"],figure:["as","currency","label"],list:["sort","limit","group","empty","as"],progress:["label"],group:["direction"],when:["show"],divider:[]};function Ee(e,n){if(!Array.isArray(n)||n.length===0)return"it has no blocks to draw";if(n.length>40)return"it has more blocks than a place draws";let r=(s,a)=>{if(typeof s!="string"||s.trim()==="")return`its ${a} says nothing`;try{return _(s)}catch(l){return`its ${a} does not read: ${l instanceof Error?l.message.replace(/ \(at character.*$/,""):String(l)}`}},t=s=>{if(s.t==="where")return t(s.set);if(s.t==="call"&&s.fn==="all"){let a=s.args[0];return a?.t==="lit"&&typeof a.value=="string"?e.info(a.value)??null:void 0}},o=(s,a)=>{switch(s.t){case"lit":return;case"ident":return a&&!a.fields.some(l=>l.name===s.name)&&!a.edges.some(l=>l.name===s.name)?`${a.plural} have nothing called ${s.name}`:void 0;case"member":return o(s.object,a);case"list":return s.items.map(l=>o(l,a)).find(Boolean);case"unary":return o(s.operand,a);case"binary":return o(s.left,a)??o(s.right,a);case"where":{let l=t(s.set);return l===null?"Nothing by that name here":o(s.set,a)??o(s.filter,l??void 0)}case"call":return s.fn==="all"?t(s)===null?"Nothing by that name here":void 0:s.args.map(l=>o(l,a)).find(Boolean)}},i=(s,a)=>{if(a>4)return"its blocks nest deeper than a place draws";for(let l of s){if(!w(l))return"a block is not an object";let d=Object.keys(ne).find(p=>p in l);if(!d)return`"${Object.keys(l)[0]??""}" is not a block a place draws`;let c=Object.keys(l).find(p=>p!==d&&p!=="key"&&!ne[d].includes(p));if(c)return`a ${d} block takes no "${c}"`;let u=l[d];if(d==="list"||d==="figure"||d==="when"){if(d==="figure"&&u===!0)continue;let p=r(u,d);if(typeof p=="string")return p;let g=o(p,void 0);if(g)return g;if(d==="list"){let f=t(p);if(f==null)return f===null?"Nothing by that name here":"its list does not say which records it lists, like all('task')";for(let m of["group","sort"]){let b=l[m],S=typeof b=="string"?b:w(b)&&typeof b.by=="string"?b.by:void 0;if(b===void 0)continue;let D=S?f.fields.find(ce=>ce.name===S):void 0;if(!D)return`${f.plural} have nothing called ${String(S??b)} to ${m} by`;if(m==="group"&&D.type!=="enum")return`${f.plural}' ${D.words} is not a choice, so they cannot be grouped by it`}}if(d==="when"){let f=l.show;if(!Array.isArray(f))return"a when block shows a list of blocks";let m=i(f,a+1);if(m)return m}}else if(d==="group"){if(!Array.isArray(u))return"a group block holds a list of blocks";let p=i(u,a+1);if(p)return p}else{if(d!=="divider"&&typeof u!="string")return`a ${d} block says words`;if(typeof u=="string")for(let p of u.matchAll(/\{([^{}]*)\}/g)){let g=p[1].split(/\|(?![|])/)[0],f=r(g,`${d}'s braces`);if(typeof f=="string")return f;let m=o(f,void 0);if(m)return m}}}};return i(n,1)}function T(e,n,r){let t=L(e.schema,r),o=f=>({ok:!1,failed:`Couldn't draw that: ${f.replace(/\.$/,"")}.`});if(!P(n.name)||n.name==="reach")return o(`"${String(n.name)}" is not a picture the seat can draw; it draws ${H.filter(f=>f!=="reach").join(", ")}`);if(typeof n.title!="string"||n.title.trim().length===0||n.title.length>80)return o("it needs a title of a few words");if(typeof n.on!="string"||!t.tryDefinition(n.on))return o("Nothing by that name here");let i=G[n.name],s=n.bindings??{};if(i.binds==="fields")for(let[f,m]of Object.entries(s)){if(!t.tryDefinition(f))return o("Nothing by that name here");let b=Object.keys(t.tryDefinition(f).fields?.shape??{});for(let[S,D]of Object.entries(m??{}))if(typeof D!="string"||!b.includes(D))return o(`${y(f)} has no field "${String(D)}" for its ${S}`);for(let S of i.requiredRoles)if(!(S in(m??{})))return o(`a ${n.name} needs ${y(f)}'s ${S}`)}else if(i.binds==="entities")for(let f of i.requiredRoles){let m=s[f];if(!m)return o(`a ${n.name} needs its ${f}`);if(typeof m.kind=="string"&&!t.tryDefinition(m.kind))return o("Nothing by that name here")}let a={...e,schema:t,lenses:[...e.lenses??[],n]},l=a.lenses.length-1,d=J(a),c=`lenses.${l}`,u=d.findings.find(f=>f.path===c||f.path.startsWith(`${c}.`));if(u)return o(u.message.replace(/^"[^"]*" /,"it "));let p=d.undrawn.find(f=>f.index===l);if(p)return o(p.why);let g=d.drawn.find(f=>f.index===l);if(!g)return o("its bindings name something the app does not have");if(g.as==="overview")return o(`"${n.title}" is the scene's own address; give it another title`);if(n.name==="blocks"){let f=Ee(I(t),n.options?.blocks);if(f)return o(f)}return{ok:!0,drawn:g}}function K(e){return{op:"add-lens",title:e.title,lens:e.name,on:e.on,...e.bindings?{bindings:e.bindings}:{},...e.options?{options:e.options}:{}}}function xe(e){return{op:"remove-lens",title:e.title,on:e.on}}var w=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function de(e){let n=w(e)?e:{},r=String(n.lens??n.name??""),t=n.bindings,o=typeof n.on=="string"?n.on:w(t)&&G[r]?.binds==="fields"?Object.keys(t)[0]??"":"";return{name:r,title:typeof n.title=="string"?n.title.trim():"",on:o,...w(t)?{bindings:t}:{},...w(n.options)?{options:n.options}:{}}}function ve(e){let n=o=>w(e.bindings?.[o])?e.bindings[o]:{},r=o=>typeof o=="string"?o:void 0,t=n(e.on);switch(e.name){case"columns":return r(t.column)?{lens:"columns",kind:e.on,column:t.column}:void 0;case"calendar":{let o=r(e.options?.range);return r(t.start)?{lens:"calendar",kind:e.on,start:t.start,...r(t.end)?{end:t.end}:{},...r(t.done)?{done:t.done}:{},...o?{range:o}:{}}:void 0}case"timeline":return r(t.start)&&r(t.end)&&r(t.column)?{lens:"timeline",kind:e.on,start:t.start,end:t.end,column:t.column}:void 0;case"coverage":{let o=w(e.bindings?.columns)?r(e.bindings.columns.kind):void 0,i=w(e.bindings?.link)?r(e.bindings.link.edge):void 0;return o&&i?{lens:"coverage",kind:e.on,across:o,link:i}:void 0}case"blocks":{let o=e.options?.blocks;if(!Array.isArray(o)||o.length!==1||!w(o[0]))return;let i=o[0],s=new RegExp(`^all\\('${e.on}'\\)(?: where (.+))?$`).exec(String(i.list??""));if(!s)return;let a=i.sort;return{lens:"blocks",kind:e.on,as:i.as==="card"?"card":"row",...typeof i.group=="string"?{group:i.group}:{},...typeof a=="string"?{sort:{by:a}}:w(a)&&typeof a.by=="string"?{sort:{by:a.by,...a.direction==="desc"?{direction:"desc"}:{}}}:{},...s[1]?{where:[{expr:s[1],says:"as asked"}]}:{}}}default:return}}function W(e,n,r,t,o){let i=I(L(e.schema,t)).info(n.on),s=ve(n);return{title:n.title,said:`${B[n.name]??"A picture"} of ${i?.plural??y(n.on)}.`,kind:n.on,lens:n,drawn:r,edit:K(n),by:o,asks:[],...s?{recipe:s}:{}}}function te(e){return{title:e.title,said:e.said,lens:{title:e.lens.title,lens:e.lens.name,on:e.lens.on,...e.lens.bindings?{bindings:e.lens.bindings}:{},...e.lens.options?{options:e.lens.options}:{}},edit:e.edit,by:e.by,check:"It draws, and graview check would take it."}}function F(e,n,r,t,o){let i=Re(e,n),s=e.title??o??C(i.title,r.app),a=Ae(e,s),l=T(r.app,a,r.sight);return l.ok?{title:s,said:`${B[e.lens]} ${i.detail}.`,kind:e.kind,lens:a,drawn:l.drawn,edit:K(a),by:"template",asks:t,recipe:e}:{failed:l.failed,...r.lastGood?{lastGood:r.lastGood}:{}}}function Ye(e,n){let r=I(L(n.app.schema,n.sight)),t=r.info(e.kind);if(!t)return{failed:"Couldn't draw that: Nothing by that name here."};let o=e.lens==="blocks"&&!e.group&&!e.sort&&!e.where?.length&&e.title===void 0;return F(o?{...e,title:C(`Every ${t.noun}`,n.app)}:e,r,n,[])}function Le(e,n,r,t){if(r.length>0)return r;let o=s=>{switch(e){case"columns":return s.fields.some(a=>a.type==="enum");case"calendar":return s.fields.some(A);case"timeline":return ie(s)!==void 0||s.fields.some(A);case"coverage":return s.edges.some(a=>a.to.some(l=>l!==s.kind));case"board":return s.fields.some(a=>a.name==="x")&&s.fields.some(a=>a.name==="y");case"plan":return s.fields.some(a=>a.name==="outline")||s.roles.outline!==void 0;default:return!0}};return[...n.kinds.filter(o)].sort((s,a)=>Number(a.fields.some(l=>E(t,l.words)))-Number(s.fields.some(l=>E(t,l.words))))}function Ie(e,n){let r=I(L(n.app.schema,n.sight)),t=re(e),o=$e(t);if(o.length===0)return;let i=pe(t,r),s;for(let a of o){let l=a==="coverage"?[i[0]??r.kinds[0]].filter(d=>!!d):Le(a,r,i,t);for(let d of l)try{let c=ae(a,d,r,t,i),u=F(c,r,n,[e]);if(!O(u))return u;s??=u.failed}catch(c){if(!(c instanceof j))throw c;s??=`Couldn't draw that: ${c.message}.`}l.length===0&&i.length===0&&(s??=`Couldn't draw that: nothing here has what ${B[a].toLowerCase()} needs.`)}return{failed:s??"Couldn't draw that: Nothing by that name here.",...n.lastGood?{lastGood:n.lastGood}:{}}}async function Oe(e,n){let r=n.lastGood?{lastGood:n.lastGood}:{};if(e.trim().length===0)return{failed:"Say what you would like to see, like \u201Ca board of tasks by status\u201D.",...r};let t=Ie(e,n);if(t&&!O(t))return t;if(!n.complete)return t??{failed:"Couldn't draw that: drawing freely needs AI, which isn't on here. Ask for a board, a calendar, a timeline, a list or who covers what.",...r};let o=await le(e,n,void 0);return O(o)&&t?t:o}async function je(e,n,r){let t={lastGood:e},o={...r,lastGood:e},i=I(L(r.app.schema,r.sight)),s=re(n),a=i.info(e.kind),l=[...e.asks,n];if(!a)return{failed:"Couldn't change that: Nothing by that name here.",...t};let d=e.recipe,c=/^ (?:call|name|title) (?:it|this)? ?(.+?) $/.exec(s)??/ (?:call|name) it (.+?) $/.exec(s);try{if(c){let g=n.replace(/^.*?\b(?:call|name|title)\b\s*(?:it|this)?\s*/i,"").replace(/^["“']|["”']$/g,"").trim();if(g.length===0)return{failed:"Couldn't change that: say what to call it.",...t};let f={...e.lens,title:C(g,r.app)},m=T(r.app,f,r.sight);return m.ok?{...e,title:f.title,lens:f,drawn:m.drawn,edit:K(f),asks:l,...d?{recipe:{...d,title:f.title}}:{}}:{failed:m.failed,...t}}let p=/ as (?:a |an )?(board|kanban|calendar|timeline|list|table|cards|rows|grid|plan|layout)\b/.exec(s);if(p){let g=p[1]==="board"||p[1]==="kanban"?"columns":p[1]==="calendar"?"calendar":p[1]==="timeline"?"timeline":p[1]==="grid"?"coverage":p[1]==="plan"?"plan":p[1]==="layout"?"board":"blocks",f=ae(g,a,i,s,[a]),m=p[1]==="cards"?"card":p[1]==="rows"?"row":void 0,b=g==="blocks"&&d?.lens==="blocks"?{...d,...m?{as:m}:{}}:g==="blocks"&&d?.lens==="columns"?{...f,group:d.column,...m?{as:m}:{}}:f;return F(R(b),i,o,l)}if(d){let g=Te(d,a,i,s);if(g)return F(g,i,o,l)}}catch(p){if(!(p instanceof j))throw p;return{failed:`Couldn't change that: ${p.message}.`,...t}}if(!r.complete)return{failed:"Couldn't change that: changing it freely needs AI, which isn't on here. Try \u201Cgroup by status\u201D, \u201Conly this month\u201D or \u201Cas a calendar\u201D.",...t};let u=await le(n,o,e);return O(u)?u:{...u,asks:l}}var R=e=>{let{title:n,...r}=e;return r};function Te(e,n,r,t){let o=/ (?:group(?:ed)?|split|organi[sz]ed?|put them|columns) by ([\p{L}\p{N} -]+?)(?= (?:and|only|with)|\s*$)/u.exec(t)?.[1]??(/^ by /.test(t)?U(t):void 0);if(o){let d=v(n,o);if(d?.type==="enum")return e.lens==="blocks"?{...R(e),group:d.name}:{lens:"columns",kind:e.kind,column:d.name};let c=oe(n,o,r);return c?{lens:"coverage",kind:e.kind,across:c.to[0],link:c.name}:h(d?`${n.plural}' ${d.words} is not a choice, so they cannot be grouped by it`:`${n.plural} have nothing called ${o} to group by`)}let i=/ (?:sort(?:ed)?|order(?:ed)?) by ([\p{L}\p{N} -]+?)(?= (?:and|only|with)|\s*$)/u.exec(t)?.[1];if(i){let d=v(n,i);return d?{...e.lens==="blocks"?R(e):{lens:"blocks",kind:e.kind,as:"row",...e.lens==="columns"?{group:e.column}:{}},sort:{by:d.name,.../\b(newest|latest|desc|descending|most)\b/.test(t)?{direction:"desc"}:{}}}:h(`${n.plural} have nothing called ${i} to sort by`)}if(/\b(?:all of them|everything|show all|clear the filter|no filter|without the filter)\b/.test(t)){if(e.lens!=="blocks"||!e.where)return h("it already shows all of them");let{where:d,...c}=R(e);return c}let s=se(t);if(s&&e.lens==="calendar"&&s.range)return{...R(e),range:s.range};if(s&&e.lens==="calendar"&&!s.range)return{lens:"blocks",kind:e.kind,as:"row",sort:{by:e.start},where:V(n,t)};let a=V(n,t);if(a.length>0){let d=e.lens==="blocks"?R(e):{lens:"blocks",kind:e.kind,as:"row",...e.lens==="columns"?{group:e.column}:{}};return{...d,where:[...d.where??[],...a]}}let l=e.lens==="calendar"?M(t):void 0;if(l)return{...R(e),range:l}}function Ne(e){return e.kinds.map(n=>{let r=n.fields.map(i=>`${i.name} (${i.type??"value"}${i.options?`: ${i.options.join(" | ")}`:""})`).join(", "),t=n.edges.map(i=>`${i.name} \u2192 ${i.to.join(" | ")}`).join(", "),o=Object.entries(n.roles).map(([i,s])=>`${i}=${s}`).join(", ");return`- ${n.kind} ("${n.plural}"): ${r}${t?`; relations: ${t}`:""}${o?`; roles: ${o}`:""}`}).join(`
1
+ import{a as k}from"./chunk.G4JJXA63.js";import{a as Q}from"./chunk.Z5AB2DBF.js";import{a as Y}from"./chunk.HPAGOEZG.js";import{a as X}from"./chunk.I7XSDXQ3.js";import{c as _}from"./chunk.ZHLQWMV5.js";import{ad as G,cd as H,dd as P,ed as J,jb as q,kb as z}from"./chunk.V5MYKNL7.js";var O=e=>"failed"in e;function ue(e,n){let r=e.schema.kinds,t=e.policy?.sees;if(!t?.length||z(n))return{kinds:r};let o=q(n).roles??[],i=new Set(t.filter(s=>s.roles==="*"||o.some(a=>s.roles.includes(a))).flatMap(s=>s.kinds));return{kinds:r.filter(s=>i.has(s))}}function L(e,n){if(!n)return e;let r=new Set(n.kinds.filter(i=>e.tryDefinition(i)!==void 0));if(r.size===e.kinds.length)return e;let t=new Map,o=i=>{if(r.has(i)){if(!t.has(i)){let s=e.tryDefinition(i),a=Object.fromEntries(Object.entries(s?.edges??{}).flatMap(([l,d])=>{if(d.to==="*")return[[l,d]];let c=d.to.filter(u=>r.has(u));return c.length>0?[[l,{...d,to:c}]]:[]}));t.set(i,{...s,edges:a})}return t.get(i)}};return{...e,definitions:e.definitions.filter(i=>r.has(i.kind)),kinds:e.kinds.filter(i=>r.has(i)),tryDefinition:o,definition:i=>{let s=o(i);if(!s)throw new Error(`Unknown node kind "${i}"`);return s}}}var fe=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),y=e=>fe(e).replace(/[-_]+/g," ").trim();function I(e){let n=[];for(let t of e.kinds){let o=e.tryDefinition(t);if(!o)continue;let i=o.display?.labels??{},s=Object.entries(o.fields?.shape??{}).filter(([d])=>d!=="id"&&d!=="kind").map(([d,c])=>{let u=X(c);return{name:d,type:u?.type,...u?.options?{options:u.options}:{},words:(i[d]??y(d)).toLowerCase()}}),a=Object.entries(o.edges??{}).map(([d,c])=>({name:d,from:t,to:c.to==="*"?e.kinds.filter(u=>u!==t):c.to,words:y(d)})),l=(o.plural??`${y(t)}s`).toLowerCase();n.push({kind:t,plural:l,noun:(o.noun??y(t)).toLowerCase(),fields:s,roles:o.fieldRoles??{},edges:a})}let r=new Map(n.map(t=>[t.kind,t]));return{schema:e,kinds:n,info:t=>r.get(t)}}var $=(e,n)=>n===void 0?void 0:e.fields.find(r=>r.name===n),A=e=>e?.type==="date"||e?.type==="datetime",N=e=>e?.type==="number"||e?.type==="integer"||e?.type==="duration",re=e=>` ${e.toLowerCase().replace(/[“”"’‘]/g,"'").replace(/[^\p{L}\p{N}' -]+/gu," ").replace(/\s+/g," ").trim()} `,E=(e,n)=>e.includes(` ${n} `),x=e=>e.endsWith("ies")?`${e.slice(0,-3)}y`:e.endsWith("ses")?e.slice(0,-2):e.endsWith("s")?e.slice(0,-1):e;function pe(e,n){let r=[];for(let t of n.kinds){let o=new Set([t.plural,t.noun,`${t.noun}s`,y(t.kind),`${y(t.kind)}s`]),i=-1;for(let s of o){let a=e.indexOf(` ${s} `);a>=0&&(i<0||a<i)&&(i=a)}i>=0&&r.push({info:t,at:i})}return r.sort((t,o)=>t.at-o.at).map(t=>t.info)}function v(e,n,r){let t=n.trim().toLowerCase();if(t.length===0)return;let o=e.fields.filter(i=>!r||r(i));return o.find(i=>i.words===t||y(i.name)===t||i.name.toLowerCase()===t)??o.find(i=>i.words===x(t)||y(i.name)===x(t))??o.find(i=>t.split(" ").some(s=>s.length>2&&(i.words.split(" ").includes(s)||i.words.split(" ").includes(x(s)))))}function oe(e,n,r){let t=n.trim().toLowerCase();if(t.length!==0)return e.edges.find(o=>o.words===t||o.name.toLowerCase()===t)??e.edges.find(o=>o.to.some(i=>{let s=r.info(i);return s!==void 0&&(s.noun===x(t)||s.plural===t||y(i)===x(t))}))??e.edges.find(o=>t.split(" ").some(i=>i.length>2&&o.words.split(" ").includes(i)))}function U(e){return/ (?:grouped |group |split |sorted |organi[sz]ed )?by ([\p{L}\p{N}' -]+?)(?= (?:and|with|for|in|on|only|where|from|this|that|as|sorted|grouped) |\s*$)/u.exec(e)?.[1]?.trim()}var me=/\bwho\b.*\b(covers?|cover|tends?|owns?|handles?|does|works? on|looks? after|is on|is assigned|staffs?|runs?)\b|\bcoverage\b|\bmatrix\b|\bwho covers\b/,ge=/\bcalendar\b|\bmonth\b|\bagenda\b|\bschedule\b|\bdue\b|\bdeadlines?\b|\bdates?\b|\bwhen\b/,ye=/\btimeline\b|\bover time\b|\bgantt\b|\bspans?\b|\bweek\b/,he=/\bboard\b|\bkanban\b|\bcolumns?\b|\bpipeline\b|\bstages?\b|\bstatus\b/,be=/\blaid out\b|\blayout\b|\bseating\b|\bwhere (?:they|it|each) (?:sits?|lies?|stands?)\b|\bfloor\b/,we=/\bplan\b|\bmap\b|\bregions?\b/,ke=/\blist\b|\btable\b|\bgroup(?:ed)? by\b|\bsort(?:ed)? by\b|\bonly\b|\bjust the\b/;function $e(e){let n=[];return/\blist\b|\btable\b/.test(e)&&n.push("blocks"),me.test(e)&&n.push("coverage"),be.test(e)&&n.push("board"),(/\bfloor plan\b/.test(e)||we.test(e))&&n.push("plan"),ye.test(e)&&n.push("timeline"),ge.test(e)&&n.push("calendar"),he.test(e)&&n.push("columns"),ke.test(e)&&!n.includes("blocks")&&n.push("blocks"),n.length===0&&U(e)&&n.push("columns"),n}var se=e=>{let n=r=>r?` and not ${r}`:"";if(/\boverdue\b|\blate\b|\bpast due\b/.test(e))return{cond:(r,t)=>`days(today(), ${r}) < 0${n(t)}`,says:r=>`overdue by ${r.words}`};if(/\btoday\b/.test(e))return{range:"day",cond:r=>`days(today(), ${r}) == 0`,says:r=>`with ${r.words} today`};if(/\bthis week\b|\bnext 7 days\b|\bnext week\b/.test(e))return{range:"week",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 6`,says:r=>`with ${r.words} in the next week`};if(/\bthis month\b|\bnext 30 days\b|\bnext month\b/.test(e))return{range:"month",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 30`,says:r=>`with ${r.words} in the next month`};if(/\blast month\b|\bpast month\b/.test(e))return{range:"month",cond:r=>`days(today(), ${r}) >= -30 and days(today(), ${r}) <= 0`,says:r=>`with ${r.words} in the last month`};if(/\bthis year\b/.test(e))return{range:"year",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 365`,says:r=>`with ${r.words} in the next year`};if(/\bquarter\b/.test(e))return{range:"quarter",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 91`,says:r=>`with ${r.words} in the next quarter`}},M=e=>{if(/\bagenda\b|\bin order\b/.test(e))return"agenda";if(/\btoday\b|\bday\b/.test(e))return"day";if(/\bweek\b/.test(e))return"week";if(/\bquarter\b/.test(e))return"quarter";if(/\byears\b/.test(e))return"years";if(/\byear\b/.test(e))return"year";if(/\bmonth\b/.test(e))return"month"},Z=/^(user|person|people|member|staff|gardener|volunteer|owner|agent|employee|worker|team|player|customer|client|contact|party|attendee|guest)s?$/,j=class extends Error{},h=e=>{throw new j(e)};function Se(e,n){let r=e.fields.filter(i=>i.type==="enum");if(n){let i=v(e,n);if(i&&i.type==="enum")return i;i&&h(`${e.plural}' ${i.words} is not a choice, so it has no columns`)}let t=$(e,e.roles.status??e.roles.column);if(t?.type==="enum")return t;let o=r.find(i=>/^(status|stage|state|phase)$/.test(i.name));return o||(r[0]?r[0]:h(`${e.plural} have no choice field to put in columns`))}function ee(e,n){let r=e.fields.filter(A),t=l=>{let d=$(e,e.roles[l]);return A(d)?d:void 0},i=r.find(l=>E(n,l.words)||E(n,y(l.name)))??t("start")??r.find(l=>/^(due|date|on|at|start|starts|begins|from|sown|when)/i.test(l.name))??r[0];if(!i)return h(`no date field on ${e.plural}`);let s=t("end")??r.find(l=>l!==i&&/^(end|ends|until|to|finish|finished|harvested|due|closes|through)/i.test(l.name)),a=e.fields.find(l=>l.type==="boolean"&&/^(done|finished|complete|completed|closed)$/.test(l.name));return{start:i,...s&&s!==i?{end:s}:{},...a?{done:a}:{}}}function ie(e){let n=$(e,e.roles.start),r=$(e,e.roles.end),t=$(e,e.roles.column??e.roles.day??e.roles.columns);if(N(n)&&N(r)&&t?.type==="enum")return{start:n,end:r,column:t}}function De(e,n,r,t){let o=[];for(let s of e.kinds)for(let a of s.edges)for(let l of a.to){let d=e.info(l);if(!d||d.kind===s.kind)continue;let c=0;n.includes(s)&&(c+=4),n.includes(d)&&(c+=4),(Z.test(d.kind)||Z.test(d.noun))&&(c+=3),t&&(a.words.includes(t)||d.noun===x(t))&&(c+=5),a.words.split(" ").some(u=>u.length>2&&r.includes(` ${u}`))&&(c+=2),o.push({rows:s,across:d,link:a,score:c})}let i=o.sort((s,a)=>a.score-s.score)[0];return i||h(n[0]?`${n[0].plural} are joined to nothing else, so there is no who-covers-what to draw`:"nothing here is joined to anything else, so there is no who-covers-what to draw")}function ae(e,n,r,t,o){let i=U(t);switch(e){case"columns":{if(i){let s=v(n,i);if(!s||s.type!=="enum"){let a=oe(n,i,r);if(a){let l=r.info(a.to[0]);return{lens:"coverage",kind:n.kind,across:l.kind,link:a.name}}}}return{lens:"columns",kind:n.kind,column:Se(n,i).name}}case"calendar":{let s=ee(n,t),a=M(t);return{lens:"calendar",kind:n.kind,start:s.start.name,...s.end?{end:s.end.name}:{},...s.done?{done:s.done.name}:{},...a?{range:a}:{}}}case"timeline":{let s=ie(n);if(s&&!/\bdates?\b|\bdue\b|\bdeadlines?\b|\bmonths?\b|\byears?\b/.test(t))return{lens:"timeline",kind:n.kind,start:s.start.name,end:s.end.name,column:s.column.name};let a=ee(n,t);return{lens:"calendar",kind:n.kind,start:a.start.name,...a.end?{end:a.end.name}:{},...a.done?{done:a.done.name}:{},range:M(t)??"quarter"}}case"coverage":{let s=De(r,o,t,i);return{lens:"coverage",kind:s.rows.kind,across:s.across.kind,link:s.link.name}}case"board":{let s=$(n,n.roles.x)??n.fields.find(c=>c.name==="x"),a=$(n,n.roles.y)??n.fields.find(c=>c.name==="y");if(!N(s)||!N(a))return h(`${n.plural} have no x and y to be laid out by`);let d=r.kinds.flatMap(c=>c.edges.filter(u=>u.to.includes(n.kind)&&c.kind!==n.kind))[0]??n.edges[0];return d?{lens:"board",kind:n.kind,x:s.name,y:a.name,fill:d.name,...d.from!==n.kind?{fillFrom:"occupant"}:{}}:h(`nothing is joined to ${n.plural} to fill them`)}case"plan":{let s=$(n,n.roles.outline)??n.fields.find(a=>a.name==="outline");return s?{lens:"plan",kind:n.kind,outline:s.name}:h(`${n.plural} have no outline to draw a plan from`)}case"blocks":{let s={lens:"blocks",kind:n.kind,as:/\bcards?\b/.test(t)?"card":"row"},a=/ group(?:ed)? by ([\p{L}\p{N} -]+?)(?= (?:and|only|sorted|with)|\s*$)/u.exec(t)?.[1]??(i&&!/ sort(?:ed)? by /.test(t)?i:void 0);if(a){let c=v(n,a);if(!c||c.type!=="enum")return h(c?`${n.plural}' ${c.words} is not a choice, so they cannot be grouped by it`:`${n.plural} have nothing called ${a} to group by`);s.group=c.name}let l=/ sort(?:ed)? by ([\p{L}\p{N} -]+?)(?= (?:and|only|grouped|with)|\s*$)/u.exec(t)?.[1];if(l){let c=v(n,l);if(!c)return h(`${n.plural} have nothing called ${l} to sort by`);s.sort={by:c.name,.../\b(newest|latest|desc|descending|most)\b/.test(t)?{direction:"desc"}:{}}}let d=V(n,t);return d.length>0&&(s.where=d),s}}}function V(e,n){let r=[],t=se(n);if(t){let o=e.fields.filter(A),i=$(e,e.roles.start),s=o.find(l=>E(n,l.words))??(A(i)?i:void 0)??o[0];(!s||!A(s))&&h(`no date field on ${e.plural}`);let a=e.fields.find(l=>l.type==="boolean"&&/^(done|finished|complete|completed|closed)$/.test(l.name));r.push({expr:t.cond(s.name,/\boverdue\b|\blate\b|\bpast due\b/.test(n)?a?.name:void 0),says:t.says(s)})}if(/\bonly\b|\bjust\b|\bthat are\b|\bwhich are\b/.test(n)){for(let o of e.fields){if(o.type!=="enum")continue;let i=o.options?.find(s=>E(n,s.toLowerCase())||E(n,y(s)));i&&r.push({expr:`${o.name} == '${i.replace(/'/g,"")}'`,says:`that are ${y(i)}`})}if(/\bnot done\b|\bundone\b|\bunfinished\b|\bopen ones\b|\bstill to do\b/.test(n)){let o=e.fields.find(i=>i.type==="boolean"&&/^(done|finished|complete|completed)$/.test(i.name));o&&r.push({expr:`not ${o.name}`,says:`not ${o.words}`})}}return r}var B={columns:"A board",calendar:"A calendar",timeline:"A timeline",coverage:"A grid",board:"A layout",plan:"A plan",blocks:"A list",reach:"A picture"};function Re(e,n){let r=n.info(e.kind),t=o=>o?$(r,o)?.words??y(o):"";switch(e.lens){case"columns":return{title:`${k(r.plural)} by ${t(e.column)}`,detail:`of ${r.plural} by ${t(e.column)}`};case"calendar":{let o=e.range??"month";if(o==="agenda")return{title:`${k(r.plural)} in date order`,detail:`of ${r.plural} in order of ${t(e.start)}`};let i=o==="years"?"year":o;return{title:`${k(r.plural)} by ${i}`,detail:`of ${r.plural} by ${t(e.start)}, a ${i} at a time`}}case"timeline":return{title:`${k(r.plural)} over the ${t(e.column)}`,detail:`of ${r.plural} from ${t(e.start)} to ${t(e.end)}, by ${t(e.column)}`};case"coverage":{let o=n.info(e.across);return{title:`${k(r.plural)} by ${o.noun}`,detail:`of which ${o.noun} covers which ${r.noun}`}}case"board":return{title:`${k(r.plural)} where they stand`,detail:`of ${r.plural} where they stand`};case"plan":return{title:`${k(r.plural)} on a plan`,detail:`of ${r.plural}`};default:{let o=[e.where?.map(i=>i.says).join(" and "),e.group?`by ${t(e.group)}`:void 0,e.sort?`in order of ${t(e.sort.by)}`:void 0].filter(i=>!!i);return{title:[k(r.plural),...o].join(" "),detail:[`of ${r.plural}`,...o].join(" ")}}}}function Ae(e,n){let r={title:n,on:e.kind};switch(e.lens){case"columns":return{name:"columns",...r,bindings:{[e.kind]:{column:e.column}}};case"calendar":return{name:"calendar",...r,bindings:{[e.kind]:{start:e.start,...e.end?{end:e.end}:{},...e.done?{done:e.done}:{}}},...e.range?{options:{range:e.range}}:{}};case"timeline":return{name:"timeline",...r,bindings:{[e.kind]:{start:e.start,end:e.end,column:e.column}}};case"coverage":return{name:"coverage",...r,bindings:{rows:{kind:e.kind},columns:{kind:e.across},link:{edge:e.link}}};case"board":return{name:"board",...r,bindings:{slots:{kind:e.kind},x:{field:e.x,on:"slots"},y:{field:e.y,on:"slots"},fill:{edge:e.fill}},...e.fillFrom?{options:{fillFrom:e.fillFrom}}:{}};case"plan":return{name:"plan",...r,bindings:{regions:{kind:e.kind},outline:{field:e.outline,on:"regions"}}};default:{let t=e.where?.length?` where ${e.where.map(i=>e.where.length>1?`(${i.expr})`:i.expr).join(" and ")}`:"",o={list:`all('${e.kind}')${t}`,as:e.as??"row"};return e.group&&(o.group=e.group),e.sort&&(o.sort=e.sort.direction?{by:e.sort.by,direction:e.sort.direction}:e.sort.by),o.empty="Nothing here yet.",{name:"blocks",...r,options:{blocks:[o]}}}}}function C(e,n){let r=o=>o.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,""),t=new Set(["home","overview",...Q(n).map(o=>o.slug),...(n.lenses??[]).flatMap(o=>o.title?[r(o.title)]:[])]);if(!t.has(r(e)))return e;for(let o=2;;o++)if(!t.has(r(`${e} ${o}`)))return`${e} ${o}`}var ne={title:[],headline:[],text:["tone"],figure:["as","currency","label"],list:["sort","limit","group","empty","as"],progress:["label"],group:["direction"],when:["show"],divider:[]};function Ee(e,n){if(!Array.isArray(n)||n.length===0)return"it has no blocks to draw";if(n.length>40)return"it has more blocks than a place draws";let r=(s,a)=>{if(typeof s!="string"||s.trim()==="")return`its ${a} says nothing`;try{return _(s)}catch(l){return`its ${a} does not read: ${l instanceof Error?l.message.replace(/ \(at character.*$/,""):String(l)}`}},t=s=>{if(s.t==="where")return t(s.set);if(s.t==="call"&&s.fn==="all"){let a=s.args[0];return a?.t==="lit"&&typeof a.value=="string"?e.info(a.value)??null:void 0}},o=(s,a)=>{switch(s.t){case"lit":return;case"ident":return a&&!a.fields.some(l=>l.name===s.name)&&!a.edges.some(l=>l.name===s.name)?`${a.plural} have nothing called ${s.name}`:void 0;case"member":return o(s.object,a);case"list":return s.items.map(l=>o(l,a)).find(Boolean);case"unary":return o(s.operand,a);case"binary":return o(s.left,a)??o(s.right,a);case"where":{let l=t(s.set);return l===null?"Nothing by that name here":o(s.set,a)??o(s.filter,l??void 0)}case"call":return s.fn==="all"?t(s)===null?"Nothing by that name here":void 0:s.args.map(l=>o(l,a)).find(Boolean)}},i=(s,a)=>{if(a>4)return"its blocks nest deeper than a place draws";for(let l of s){if(!w(l))return"a block is not an object";let d=Object.keys(ne).find(p=>p in l);if(!d)return`"${Object.keys(l)[0]??""}" is not a block a place draws`;let c=Object.keys(l).find(p=>p!==d&&p!=="key"&&!ne[d].includes(p));if(c)return`a ${d} block takes no "${c}"`;let u=l[d];if(d==="list"||d==="figure"||d==="when"){if(d==="figure"&&u===!0)continue;let p=r(u,d);if(typeof p=="string")return p;let g=o(p,void 0);if(g)return g;if(d==="list"){let f=t(p);if(f==null)return f===null?"Nothing by that name here":"its list does not say which records it lists, like all('task')";for(let m of["group","sort"]){let b=l[m],S=typeof b=="string"?b:w(b)&&typeof b.by=="string"?b.by:void 0;if(b===void 0)continue;let D=S?f.fields.find(ce=>ce.name===S):void 0;if(!D)return`${f.plural} have nothing called ${String(S??b)} to ${m} by`;if(m==="group"&&D.type!=="enum")return`${f.plural}' ${D.words} is not a choice, so they cannot be grouped by it`}}if(d==="when"){let f=l.show;if(!Array.isArray(f))return"a when block shows a list of blocks";let m=i(f,a+1);if(m)return m}}else if(d==="group"){if(!Array.isArray(u))return"a group block holds a list of blocks";let p=i(u,a+1);if(p)return p}else{if(d!=="divider"&&typeof u!="string")return`a ${d} block says words`;if(typeof u=="string")for(let p of u.matchAll(/\{([^{}]*)\}/g)){let g=p[1].split(/\|(?![|])/)[0],f=r(g,`${d}'s braces`);if(typeof f=="string")return f;let m=o(f,void 0);if(m)return m}}}};return i(n,1)}function T(e,n,r){let t=L(e.schema,r),o=f=>({ok:!1,failed:`Couldn't draw that: ${f.replace(/\.$/,"")}.`});if(!P(n.name)||n.name==="reach")return o(`"${String(n.name)}" is not a picture the seat can draw; it draws ${H.filter(f=>f!=="reach").join(", ")}`);if(typeof n.title!="string"||n.title.trim().length===0||n.title.length>80)return o("it needs a title of a few words");if(typeof n.on!="string"||!t.tryDefinition(n.on))return o("Nothing by that name here");let i=G[n.name],s=n.bindings??{};if(i.binds==="fields")for(let[f,m]of Object.entries(s)){if(!t.tryDefinition(f))return o("Nothing by that name here");let b=Object.keys(t.tryDefinition(f).fields?.shape??{});for(let[S,D]of Object.entries(m??{}))if(typeof D!="string"||!b.includes(D))return o(`${y(f)} has no field "${String(D)}" for its ${S}`);for(let S of i.requiredRoles)if(!(S in(m??{})))return o(`a ${n.name} needs ${y(f)}'s ${S}`)}else if(i.binds==="entities")for(let f of i.requiredRoles){let m=s[f];if(!m)return o(`a ${n.name} needs its ${f}`);if(typeof m.kind=="string"&&!t.tryDefinition(m.kind))return o("Nothing by that name here")}let a={...e,schema:t,lenses:[...e.lenses??[],n]},l=a.lenses.length-1,d=J(a),c=`lenses.${l}`,u=d.findings.find(f=>f.path===c||f.path.startsWith(`${c}.`));if(u)return o(u.message.replace(/^"[^"]*" /,"it "));let p=d.undrawn.find(f=>f.index===l);if(p)return o(p.why);let g=d.drawn.find(f=>f.index===l);if(!g)return o("its bindings name something the app does not have");if(g.as==="overview")return o(`"${n.title}" is the scene's own address; give it another title`);if(n.name==="blocks"){let f=Ee(I(t),n.options?.blocks);if(f)return o(f)}return{ok:!0,drawn:g}}function K(e){return{op:"add-lens",title:e.title,lens:e.name,on:e.on,...e.bindings?{bindings:e.bindings}:{},...e.options?{options:e.options}:{}}}function xe(e){return{op:"remove-lens",title:e.title,on:e.on}}var w=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function de(e){let n=w(e)?e:{},r=String(n.lens??n.name??""),t=n.bindings,o=typeof n.on=="string"?n.on:w(t)&&G[r]?.binds==="fields"?Object.keys(t)[0]??"":"";return{name:r,title:typeof n.title=="string"?n.title.trim():"",on:o,...w(t)?{bindings:t}:{},...w(n.options)?{options:n.options}:{}}}function ve(e){let n=o=>w(e.bindings?.[o])?e.bindings[o]:{},r=o=>typeof o=="string"?o:void 0,t=n(e.on);switch(e.name){case"columns":return r(t.column)?{lens:"columns",kind:e.on,column:t.column}:void 0;case"calendar":{let o=r(e.options?.range);return r(t.start)?{lens:"calendar",kind:e.on,start:t.start,...r(t.end)?{end:t.end}:{},...r(t.done)?{done:t.done}:{},...o?{range:o}:{}}:void 0}case"timeline":return r(t.start)&&r(t.end)&&r(t.column)?{lens:"timeline",kind:e.on,start:t.start,end:t.end,column:t.column}:void 0;case"coverage":{let o=w(e.bindings?.columns)?r(e.bindings.columns.kind):void 0,i=w(e.bindings?.link)?r(e.bindings.link.edge):void 0;return o&&i?{lens:"coverage",kind:e.on,across:o,link:i}:void 0}case"blocks":{let o=e.options?.blocks;if(!Array.isArray(o)||o.length!==1||!w(o[0]))return;let i=o[0],s=new RegExp(`^all\\('${e.on}'\\)(?: where (.+))?$`).exec(String(i.list??""));if(!s)return;let a=i.sort;return{lens:"blocks",kind:e.on,as:i.as==="card"?"card":"row",...typeof i.group=="string"?{group:i.group}:{},...typeof a=="string"?{sort:{by:a}}:w(a)&&typeof a.by=="string"?{sort:{by:a.by,...a.direction==="desc"?{direction:"desc"}:{}}}:{},...s[1]?{where:[{expr:s[1],says:"as asked"}]}:{}}}default:return}}function W(e,n,r,t,o){let i=I(L(e.schema,t)).info(n.on),s=ve(n);return{title:n.title,said:`${B[n.name]??"A picture"} of ${i?.plural??y(n.on)}.`,kind:n.on,lens:n,drawn:r,edit:K(n),by:o,asks:[],...s?{recipe:s}:{}}}function te(e){return{title:e.title,said:e.said,lens:{title:e.lens.title,lens:e.lens.name,on:e.lens.on,...e.lens.bindings?{bindings:e.lens.bindings}:{},...e.lens.options?{options:e.lens.options}:{}},edit:e.edit,by:e.by,check:"It draws, and graview check would take it."}}function F(e,n,r,t,o){let i=Re(e,n),s=e.title??o??C(i.title,r.app),a=Ae(e,s),l=T(r.app,a,r.sight);return l.ok?{title:s,said:`${B[e.lens]} ${i.detail}.`,kind:e.kind,lens:a,drawn:l.drawn,edit:K(a),by:"template",asks:t,recipe:e}:{failed:l.failed,...r.lastGood?{lastGood:r.lastGood}:{}}}function Ye(e,n){let r=I(L(n.app.schema,n.sight)),t=r.info(e.kind);if(!t)return{failed:"Couldn't draw that: Nothing by that name here."};let o=e.lens==="blocks"&&!e.group&&!e.sort&&!e.where?.length&&e.title===void 0;return F(o?{...e,title:C(`Every ${t.noun}`,n.app)}:e,r,n,[])}function Le(e,n,r,t){if(r.length>0)return r;let o=s=>{switch(e){case"columns":return s.fields.some(a=>a.type==="enum");case"calendar":return s.fields.some(A);case"timeline":return ie(s)!==void 0||s.fields.some(A);case"coverage":return s.edges.some(a=>a.to.some(l=>l!==s.kind));case"board":return s.fields.some(a=>a.name==="x")&&s.fields.some(a=>a.name==="y");case"plan":return s.fields.some(a=>a.name==="outline")||s.roles.outline!==void 0;default:return!0}};return[...n.kinds.filter(o)].sort((s,a)=>Number(a.fields.some(l=>E(t,l.words)))-Number(s.fields.some(l=>E(t,l.words))))}function Ie(e,n){let r=I(L(n.app.schema,n.sight)),t=re(e),o=$e(t);if(o.length===0)return;let i=pe(t,r),s;for(let a of o){let l=a==="coverage"?[i[0]??r.kinds[0]].filter(d=>!!d):Le(a,r,i,t);for(let d of l)try{let c=ae(a,d,r,t,i),u=F(c,r,n,[e]);if(!O(u))return u;s??=u.failed}catch(c){if(!(c instanceof j))throw c;s??=`Couldn't draw that: ${c.message}.`}l.length===0&&i.length===0&&(s??=`Couldn't draw that: nothing here has what ${B[a].toLowerCase()} needs.`)}return{failed:s??"Couldn't draw that: Nothing by that name here.",...n.lastGood?{lastGood:n.lastGood}:{}}}async function Oe(e,n){let r=n.lastGood?{lastGood:n.lastGood}:{};if(e.trim().length===0)return{failed:"Say what you would like to see, like \u201Ca board of tasks by status\u201D.",...r};let t=Ie(e,n);if(t&&!O(t))return t;if(!n.complete)return t??{failed:"Couldn't draw that: drawing freely needs AI, which isn't on here. Ask for a board, a calendar, a timeline, a list or who covers what.",...r};let o=await le(e,n,void 0);return O(o)&&t?t:o}async function je(e,n,r){let t={lastGood:e},o={...r,lastGood:e},i=I(L(r.app.schema,r.sight)),s=re(n),a=i.info(e.kind),l=[...e.asks,n];if(!a)return{failed:"Couldn't change that: Nothing by that name here.",...t};let d=e.recipe,c=/^ (?:call|name|title) (?:it|this)? ?(.+?) $/.exec(s)??/ (?:call|name) it (.+?) $/.exec(s);try{if(c){let g=n.replace(/^.*?\b(?:call|name|title)\b\s*(?:it|this)?\s*/i,"").replace(/^["“']|["”']$/g,"").trim();if(g.length===0)return{failed:"Couldn't change that: say what to call it.",...t};let f={...e.lens,title:C(g,r.app)},m=T(r.app,f,r.sight);return m.ok?{...e,title:f.title,lens:f,drawn:m.drawn,edit:K(f),asks:l,...d?{recipe:{...d,title:f.title}}:{}}:{failed:m.failed,...t}}let p=/ as (?:a |an )?(board|kanban|calendar|timeline|list|table|cards|rows|grid|plan|layout)\b/.exec(s);if(p){let g=p[1]==="board"||p[1]==="kanban"?"columns":p[1]==="calendar"?"calendar":p[1]==="timeline"?"timeline":p[1]==="grid"?"coverage":p[1]==="plan"?"plan":p[1]==="layout"?"board":"blocks",f=ae(g,a,i,s,[a]),m=p[1]==="cards"?"card":p[1]==="rows"?"row":void 0,b=g==="blocks"&&d?.lens==="blocks"?{...d,...m?{as:m}:{}}:g==="blocks"&&d?.lens==="columns"?{...f,group:d.column,...m?{as:m}:{}}:f;return F(R(b),i,o,l)}if(d){let g=Te(d,a,i,s);if(g)return F(g,i,o,l)}}catch(p){if(!(p instanceof j))throw p;return{failed:`Couldn't change that: ${p.message}.`,...t}}if(!r.complete)return{failed:"Couldn't change that: changing it freely needs AI, which isn't on here. Try \u201Cgroup by status\u201D, \u201Conly this month\u201D or \u201Cas a calendar\u201D.",...t};let u=await le(n,o,e);return O(u)?u:{...u,asks:l}}var R=e=>{let{title:n,...r}=e;return r};function Te(e,n,r,t){let o=/ (?:group(?:ed)?|split|organi[sz]ed?|put them|columns) by ([\p{L}\p{N} -]+?)(?= (?:and|only|with)|\s*$)/u.exec(t)?.[1]??(/^ by /.test(t)?U(t):void 0);if(o){let d=v(n,o);if(d?.type==="enum")return e.lens==="blocks"?{...R(e),group:d.name}:{lens:"columns",kind:e.kind,column:d.name};let c=oe(n,o,r);return c?{lens:"coverage",kind:e.kind,across:c.to[0],link:c.name}:h(d?`${n.plural}' ${d.words} is not a choice, so they cannot be grouped by it`:`${n.plural} have nothing called ${o} to group by`)}let i=/ (?:sort(?:ed)?|order(?:ed)?) by ([\p{L}\p{N} -]+?)(?= (?:and|only|with)|\s*$)/u.exec(t)?.[1];if(i){let d=v(n,i);return d?{...e.lens==="blocks"?R(e):{lens:"blocks",kind:e.kind,as:"row",...e.lens==="columns"?{group:e.column}:{}},sort:{by:d.name,.../\b(newest|latest|desc|descending|most)\b/.test(t)?{direction:"desc"}:{}}}:h(`${n.plural} have nothing called ${i} to sort by`)}if(/\b(?:all of them|everything|show all|clear the filter|no filter|without the filter)\b/.test(t)){if(e.lens!=="blocks"||!e.where)return h("it already shows all of them");let{where:d,...c}=R(e);return c}let s=se(t);if(s&&e.lens==="calendar"&&s.range)return{...R(e),range:s.range};if(s&&e.lens==="calendar"&&!s.range)return{lens:"blocks",kind:e.kind,as:"row",sort:{by:e.start},where:V(n,t)};let a=V(n,t);if(a.length>0){let d=e.lens==="blocks"?R(e):{lens:"blocks",kind:e.kind,as:"row",...e.lens==="columns"?{group:e.column}:{}};return{...d,where:[...d.where??[],...a]}}let l=e.lens==="calendar"?M(t):void 0;if(l)return{...R(e),range:l}}function Ne(e){return e.kinds.map(n=>{let r=n.fields.map(i=>`${i.name} (${i.type??"value"}${i.options?`: ${i.options.join(" | ")}`:""})`).join(", "),t=n.edges.map(i=>`${i.name} \u2192 ${i.to.join(" | ")}`).join(", "),o=Object.entries(n.roles).map(([i,s])=>`${i}=${s}`).join(", ");return`- ${n.kind} ("${n.plural}"): ${r}${t?`; relations: ${t}`:""}${o?`; roles: ${o}`:""}`}).join(`
2
2
  `)}var Fe=['columns \u2014 a board, records in columns by one choice field: {"lens": "columns", "on": K, "bindings": {K: {"column": "<enum field>"}}}','calendar \u2014 records on a calendar by a date: {"lens": "calendar", "on": K, "bindings": {K: {"start": "<date field>", "end"?: "<date field>", "done"?: "<boolean field>"}}, "options": {"range"?: "day" | "week" | "month" | "quarter" | "year" | "agenda"}}','timeline \u2014 minutes of a day in columns: {"lens": "timeline", "on": K, "bindings": {K: {"start": "<number field>", "end": "<number field>", "column": "<enum field>"}}}','coverage \u2014 who covers what, a grid of two kinds joined by a relation: {"lens": "coverage", "on": K, "bindings": {"rows": {"kind": K}, "columns": {"kind": J}, "link": {"edge": "<relation of K to J>"}}}',`blocks \u2014 anything else, as blocks: {"lens": "blocks", "on": K, "options": {"blocks": [{"headline": "words"}, {"list": "all('K') where <condition>", "group"?: "<enum field>", "sort"?: "<field>" | {"by": "<field>", "direction": "desc"}, "as"?: "row" | "card", "empty"?: "words"}, {"figure": "count(all('K'))", "label": "words"}]}}. Conditions read a record's own fields: status == 'open', not done, days(today(), due) <= 7.`].join(`
3
3
  `);function Ce(e,n,r){return["You draw a view of an app's data as JSON \u2014 never code. The app's kinds, their fields (with types) and relations:",Ne(n),"","The lenses you may use (prefer the first four; use blocks only when none of them fits):",Fe,"",r?`The view on screen now:
4
4
  ${JSON.stringify(r.lens)}
@@ -0,0 +1 @@
1
+ import{h as n}from"./chunk.VZYCILPJ.js";import"./chunk.4QPVS2ZM.js";import"./chunk.RCM7NOPF.js";import"./chunk.Z7LDT55A.js";import"./chunk.ZJMDLRC5.js";import"./chunk.2GDXNTY5.js";import"./chunk.ETOGQE2V.js";import"./chunk.O5JKDFDH.js";import"./chunk.YYIKSH2F.js";import"./chunk.5RABSIF7.js";import"./chunk.NGDXH66B.js";import"./chunk.67WWRC6Y.js";import"./chunk.WVUJXDXZ.js";import{e as p}from"./chunk.N6MVK3KD.js";import"./chunk.I7XSDXQ3.js";import"./chunk.UHI3D7JC.js";import"./chunk.WVDKYUF3.js";import"./chunk.ZHLQWMV5.js";import"./chunk.TNESS3LQ.js";import"./chunk.GZHZLJBF.js";import"./chunk.42XSBKPO.js";import"./chunk.OJGHDWI6.js";import"./chunk.6FNMDAX5.js";import"./chunk.2FLPDPEL.js";import"./chunk.UUBYFBPN.js";import"./chunk.2RVUDRRY.js";import"./chunk.LLEFYJPJ.js";import{R as m}from"./chunk.FOQZADMA.js";import"./chunk.SDO3U72B.js";import"./chunk.V5MYKNL7.js";import{b as t}from"./chunk.AJZBJBMO.js";var i=t(m(),1),a=new WeakMap;function s(o){let e=a.get(o);if(!e){let r=p(o);e=c=>c.mode==="fullscreen"?(0,i.jsx)(n,{blocks:r,slot:"home",heading:2,firstHeading:1}):(0,i.jsx)(n,{blocks:r,slot:"home",heading:3,firstHeading:2}),a.set(o,e)}return e}export{s as homeView};
@@ -1 +1 @@
1
- import{a as ot}from"./chunk.KSXB4LDF.js";import"./chunk.3ZNQ5YKX.js";import{e as V,l as ue,m as G,q as st}from"./chunk.7EFNLMKU.js";import{a as ee}from"./chunk.G4JJXA63.js";import"./chunk.ITEF3U2E.js";import{b as nt}from"./chunk.B2IRADR2.js";import{d as tt}from"./chunk.IAZRY42B.js";import"./chunk.FMN5XDLE.js";import"./chunk.B7TB6YRZ.js";import"./chunk.NSNGPQGT.js";import{d as et}from"./chunk.H5CZZZLX.js";import{c as Ze}from"./chunk.Z7JRBKA7.js";import{H as ze,Tc as Ne,U as Je,Uc as Xe,ba as Ye,fa as qe,fb as Ve,gb as Qe,ja as Ae,ka as F}from"./chunk.5ZMENPY4.js";import"./chunk.AJZBJBMO.js";var At="Nothing by that name here.",$=o=>o.normalize("NFD").replace(/\p{M}+/gu,"").toLowerCase().replace(/[’']/g,"'").replace(/[^\p{L}\p{N}' ]+/gu," ").replace(/\s+/g," ").trim(),Nt=/^(?:(?:can you |could you |please )?(?:go|take me|bring me|head|jump|navigate|switch|get me)(?: back)? to|(?:please )?(?:open|show(?: me)?|bring up|let me see|view)) (.+)$/,St=/^(?:(?:can you |could you |please )?tell me (?:about|of)|what(?: is|'s| are) (?:in |on )?|describe|explain|who(?: is|'s)) (.+)$/,Ot=/^(?:what(?: is|'s| am i looking at| do i see)(?: (?:here|this|on (?:this|the) (?:page|screen)|in view|this place|this page))?|where am i|describe (?:this|here|this place|this page)|tell me about (?:this|here|this place|this page))$/,rt=new Set(["here","this","this place","this page","on this page","on the page","on this screen","in view"]),Ct=/^(?:date|day|when|on|at|the date|the day)$/,jt=/^(?:what(?: is|'s) (?:wrong|broken|the (?:problem|matter|trouble))|what needs (?:fixing|attention|doing)|any (?:problems|issues|trouble)|(?:show(?: me)? |go to |open )?(?:the )?(?:problems|issues|trouble|standing|what's wrong)|is (?:anything|something) (?:wrong|broken)|are there (?:any )?(?:problems|issues))(?: (?:with|about|on|in) (.+))?$/,z=o=>o.replace(/^(?:the|a|an|my|our) /,""),te=new Set(["the","a","an","my","our","all","any","of","that","which","who","are","is","be","what","whats","what's","with","me","show","list","every","there","do","i","have","we","due","for","please","were","was","by","from","in","on"]),ft=864e5,he=o=>Date.UTC(Number(o.slice(0,4)),Number(o.slice(5,7))-1,Number(o.slice(8,10))),xe=o=>new Date(o).toISOString().slice(0,10),C=(o,i)=>xe(he(o)+i*ft),xt=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"],Mt=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Wt="(monday|tuesday|tues|wednesday|thursday|thurs|friday|saturday|sunday)",it="(january|february|march|april|may|june|july|august|september|october|november|december|jan|feb|mar|apr|jun|jul|aug|sept|sep|oct|nov|dec)",at="(\\d{1,2})(?:st|nd|rd|th)?",Dt=o=>xt.findIndex(i=>i.startsWith(o.slice(0,3))),dt=o=>Mt.findIndex(i=>o.startsWith(i.toLowerCase()));function Rt(o,i){return Je(o,{year:o.slice(0,4)!==i.slice(0,4)})}function Se(o,i,y){if(o<0||i<1||i>31)return;let f=Number(y.slice(0,4)),c=k=>{let j=Date.UTC(k,o,i);return new Date(j).getUTCMonth()===o?xe(j):void 0},p=c(f);if(p)return he(p)<he(y)-183*ft?c(f+1):p}function Oe(o,i,y){let f=new Date(he(i)).getUTCDay(),c=u=>{let S=(f-y+7)%7,w=C(i,-S+u*7);return{from:w,to:C(w,6)}},p=()=>{let u=`${i.slice(0,8)}01`,S=new Date(Date.UTC(Number(i.slice(0,4)),Number(i.slice(5,7)),1));return{from:u,to:C(xe(S.getTime()),-1)}},k=u=>u?{from:u,to:u,day:Rt(u,i)}:void 0,j=(u,S)=>{let w=Dt(S);return k(u==="this"||u==="next"?C(c(u==="next"?1:0).from,(w-y+7)%7):u==="last"?C(i,-((f-w+6)%7+1)):C(i,(w-f+7)%7))},J=u=>{let S=C(i,f===0?-1:6-f);return{from:C(S,u*7),to:C(S,u*7+1)}},B="\\b(?:(?:due |for |on |by )(?:the )?)?",P=[[/\b(?:overdue|past due|late)\b/,()=>({overdue:!0,to:C(i,-1)})],[/\b(?:due |for |on )?today\b/,()=>({from:i,to:i})],[/\b(?:due |for |on )?tomorrow\b/,()=>k(C(i,1))],[/\b(?:due |for |on )?yesterday\b/,()=>k(C(i,-1))],[/\b(?:due |for |on )?this week\b/,()=>c(0)],[/\b(?:due |for |on )?next week\b/,()=>c(1)],[/\b(?:due |for |on )?(?:last|previous) week\b/,()=>c(-1)],[/\b(?:due |for |on )?next weekend\b/,()=>J(1)],[/\b(?:due |for |on )?(?:this |the )?weekend\b/,()=>J(0)],[/\b(?:due |for |on )?this month\b/,()=>p()],[new RegExp(`${B}(\\d{4}) (\\d{2}) (\\d{2})\\b`),u=>k(Se(Number(u[2])-1,Number(u[3]),`${u[1]}-01-01`))],[new RegExp(`${B}${at} (?:of )?${it}\\b`),u=>k(Se(dt(u[2]),Number(u[1]),i))],[new RegExp(`${B}${it} (?:the )?${at}\\b`),u=>k(Se(dt(u[1]),Number(u[2]),i))],[new RegExp(`${B}(?:(this|next|last|coming) )?${Wt}\\b`),u=>j(u[1],u[2])]];for(let[u,S]of P){let w=o.match(u);if(!w)continue;let N=S(w);if(N)return{ask:{words:w[0],...N},rest:o.replace(w[0]," ").replace(/\s+/g," ").trim()}}}function ht(o,i,y={}){let f=y.principal??{kind:"human"},c=o.seenBy(f),p=c.schema,k=y.today??o.today?.()??ze(),j=y.weekStartsOn??1,J=o.kindsKeptFrom(f),B=o.modules.disabledKinds,P=p.kinds.filter(e=>!J.has(e)&&!B.has(e)),u=new Set(P),S=(y.places??[]).filter(e=>e.kind===null||u.has(e.kind)),w=c.graph,N=$(i).replace(/[?.!]+$/,"").trim();if(N.length===0)return{unresolved:!0};let M=e=>p.tryDefinition(e),H=e=>Ye(M(e.kind),e),I=e=>qe(p,e),se=e=>S.find(t=>t.kind===e&&t.address===Ne(p,e))?.address??Ne(p,e),ge=e=>Xe(p,e.kind,e.id),Me=e=>({to:"record",id:e.id,kind:e.kind,label:H(e),address:ge(e),said:`Went to ${H(e)}.`}),We=e=>{let t=`Went to ${e.title}.`;return e.kind===null?{to:"place",slug:e.slug,title:e.title,address:e.address,...e.slug==="overview"?{face:"scene"}:{},said:t}:e.lens||e.address.startsWith("/places/")?{to:"picture",kind:e.kind,as:e.slug,title:e.title,address:e.address,said:t}:{to:"kind",kind:e.kind,title:e.title,address:e.address,said:t}},De=()=>({unresolved:!0,say:At}),oe=e=>{let t=M(e.kind),s=et(e,t,{limit:3,excerpt:!0}).map(r=>r.alone.startsWith(r.label)?r.alone:`${r.label.toLowerCase()} ${r.alone}`).join(", "),n=c.violations().filter(r=>r.nodeIds.includes(e.id));return[`${H(e)} \u2014 ${Ae(F(t,e.kind))}${s?` (${s})`:""}.`,n.length>0?`Trouble: ${n.map(r=>r.message).join("; ")}.`:""].filter(Boolean).join(" ")},re=e=>{let t=new Set([G(e),G(z(e))]);for(let n of[" page"," view"," lens"," place"," picture"," list"])e.endsWith(n)&&(t.add(G(e.slice(0,-n.length))),t.add(G(z(e.slice(0,-n.length)))));t.delete("");let s=n=>t.has(G(n.title))||t.has(G(z($(n.title))))||t.has(G(n.slug));return S.find(n=>n.kind!==null&&n.address.startsWith("/places/")&&s(n))??S.find(s)},pe=e=>{let t=st(o,e,{principal:f,today:k,limit:6,near:!1,...y.selection?{from:y.selection}:{}}),s=t.hits.filter(r=>r.about==="node"&&u.has(r.kind)&&w.getNode(r.id)!==void 0),n=s.filter(r=>r.why.field==="label"&&r.why.strength==="exact");return n.length===1?{one:w.getNode(n[0].id),picks:s}:n.length>1?{picks:n}:s.length===1&&t.total===1?{one:w.getNode(s[0].id),picks:s}:{picks:s}},Re=e=>{let t=e.map(s=>`${s.label} (${F(M(s.kind),s.kind)})`);return`${e.length===1?"One thing matches":`${e.length} things match`}: ${t.join("; ")}.`},Ee=(e,t)=>{if(rt.has(e))return Le();let s=t?pe(z(e)||e):void 0,n=s?.one&&$(H(s.one))===$(z(e)||e)?void 0:re(e);if(n){let l=We(n);return{about:"place",say:t?`${l.said} ${me(n)}`:l.said,moves:[l],subject:n.slug}}let r=pe(z(e)||e);if(r.one){let l=Me(r.one);return{about:t?"describe":"record",say:t?`${l.said} ${oe(r.one)}`:l.said,moves:[l],subject:r.one.id}}if(r.picks.length>0)return{about:"picks",say:Re(r.picks),moves:[],picks:r.picks};let h=ae(e);if(h)return h;let d=Pe(e);if(d){if(d.rest.split(" ").every(l=>l===""||te.has(l))){let l=I(d.kind),v={to:"kind",kind:d.kind,title:l,address:se(d.kind),said:`Went to the ${l.toLowerCase()}.`};return{about:"kind",say:v.said,moves:[v]}}return{unresolved:!0}}return De()},me=e=>{if(e.kind===null){let h=P.map(l=>({kind:l,count:w.nodesOfKind(l).length})).filter(l=>l.count>0).map(l=>`${l.count} ${(l.count===1?F(M(l.kind),l.kind):I(l.kind)).toLowerCase()}`),d=c.violations().length;return[h.length>0?`It holds ${fe(h)}.`:"It holds nothing yet.",d>0?`${d===1?"One problem":`${d} problems`} to see to.`:""].filter(Boolean).join(" ")}let t=w.nodesOfKind(e.kind).length,s=I(e.kind).toLowerCase(),n=new Set(c.violations().flatMap(h=>h.nodeIds)),r=w.nodesOfKind(e.kind).filter(h=>n.has(h.id)).length;return[e.lens?`It draws the ${s} as ${Ae(e.lens)}${t>0?` \u2014 ${t} of them`:""}.`:`${t===0?"No":t} ${t===1?F(M(e.kind),e.kind):s} ${t===1?"is":"are"} here.`,r>0?`${r} ${r===1?"has":"have"} a problem.`:""].filter(Boolean).join(" ")},Le=()=>{let e=(y.selection??[]).map(s=>w.getNode(s)).find(s=>s!==void 0);if(e)return{about:"here",say:oe(e),moves:[],subject:e.id};let t=S.find(s=>s.slug===y.place)??S.find(s=>s.slug==="home");return t?{about:"here",say:`${t.title}. ${me(t)}`,moves:[],subject:t.slug}:{about:"here",say:me({slug:"home",title:"Home",kind:null,cardinality:"many",address:"/",stop:"#"}),moves:[]}},Pe=e=>{let t=P.flatMap(s=>[I(s),F(M(s),s),s].map(n=>({kind:s,name:$(n)}))).filter(s=>s.name.length>0).sort((s,n)=>n.name.length-s.name.length);for(let{kind:s,name:n}of t)if(!(` ${e} `.indexOf(` ${n} `)<0))return{kind:s,rest:` ${e} `.replace(` ${n} `," ").replace(/\s+/g," ").trim()}},ie=(e,t)=>{let s=V(p,e).filters.filter(d=>d.about==="field"&&d.type==="date");if(s.length===0)return;let n=s.find(d=>t.some(l=>$(d.key)===l||$(d.label)===l));if(n)return n;let r=M(e)?.fieldRoles??{};for(let d of["due","deadline","date","when","start","end"]){let l=r[d],v=l?s.find(x=>x.key===l):void 0;if(v)return v}return s.find(d=>["due","deadline","date","when","on","at"].includes(d.key.toLowerCase()))??(s.length===1?s[0]:void 0)},He=e=>{let t=M(e),s=V(p,e).filters;if(t?.lifecycle)return{conditions:[{key:"is",value:"current"}],holds:d=>ue(be,d,{key:"is",value:"current"})};let r=s.find(d=>d.about==="field"&&d.type==="boolean"&&ne.has($(d.key)));if(r)return{conditions:[{key:r.key,value:"false"}],holds:d=>d[r.key]!==!0};let h=s.find(d=>d.about==="field"&&d.type==="choice"&&(d.options??[]).some(l=>ne.has($(l))));if(h){let d=new Set((h.options??[]).filter(v=>ne.has($(v)))),l=(h.options??[]).filter(v=>!d.has(v));return l.length===1?{conditions:[{key:h.key,value:l[0]}],holds:v=>v[h.key]===l[0]}:"unsayable"}return{conditions:[],holds:()=>!0}},Ie=(e,t)=>{let s=e.words.startsWith("due")||$(t.key)==="due",n=Ct.test($(t.label));if(e.day)return s?`due ${e.day}`:n?`on ${e.day}`:`${t.label.toLowerCase()} on ${e.day}`;let r=e.words.replace(/^(?:due|for|on|by) (?:the )?/,"");return s?`due ${r}`:n?r:`${t.label.toLowerCase()} ${r}`},ye=new Set(c.violations().flatMap(e=>e.nodeIds)),be={schema:p,graph:c.graph,flagged:ye,today:k},ae=e=>{let t=Oe(e,k,j),s=Pe(t?.rest??e),n=s?.kind,r=(s?.rest??t?.rest??e).split(" ").filter(Boolean);if(!n&&t){let g=e.split(" "),m=P.filter(L=>ie(L,g)!==void 0),E=m.filter(L=>{let b=ie(L,g);return g.some(O=>$(b.key)===O||$(b.label)===O)}),U=m.length===1?m:E;if(U.length!==1)return;n=U[0]}if(!n)return;let h=V(p,n).filters,d=[],l=[],v=[],x=[],q=!1,de=[];for(let g=0;g<r.length;g++){let m=r[g],E=g>0&&(r[g-1]==="not"||r[g-1]==="un"),U=h.find(b=>b.about==="field"&&b.type==="choice"&&(b.options??[]).some(O=>$(O)===m));if(U&&!E){let b=(U.options??[]).find(O=>$(O)===m);d.push({key:U.key,value:b}),l.push(b);continue}let L=h.find(b=>b.about==="field"&&b.type==="boolean"&&[$(b.key),$(b.label)].some(O=>O===m||O===m.replace(/^un/,"")));if(L){let b=!E&&!(m.startsWith("un")&&!$(L.key).startsWith("un"));d.push({key:L.key,value:String(b)}),l.push(b?m:`not ${m.replace(/^un/,"")}`);continue}if(Pt.has(m)&&!E){let b=He(n);b==="unsayable"?(q=!0,x.push(O=>!ut(p,O))):(d.push(...b.conditions),x.push(b.holds)),l.push(m);continue}m==="not"||m==="un"||t&&h.some(b=>b.type==="date"&&($(b.key)===m||$(b.label)===m))||de.push(m)}if(r=de,r.some(g=>!te.has(g))||!t&&d.length===0&&x.length===0)return;let T=I(n).toLowerCase(),Q=I(n);if(t){let g=ie(n,e.split(" "));if(!g){let m={to:"kind",kind:n,title:Q,address:se(n),said:`Went to the ${T}.`};return{about:"kind",say:`${ee(Q)} carry no date, so I can't tell which are ${/^(?:due|for|on|overdue|past due|late)\b/.test(t.ask.words)?t.ask.words:`due ${t.ask.words}`}. ${m.said}`,moves:[m]}}if(t.ask.from&&d.push({key:g.key,value:`after:${C(t.ask.from,-1)}`}),t.ask.to&&d.push({key:g.key,value:`before:${C(t.ask.to,1)}`}),t.ask.overdue){let m=He(n);m==="unsayable"?(q=!0,x.push(E=>!ut(p,E))):(d.push(...m.conditions),x.push(m.holds))}t.ask.overdue?l.push("overdue"):v.push(Ie(t.ask,g))}let R=w.nodesOfKind(n).filter(g=>d.every(m=>ue(be,g,m))&&x.every(m=>m(g))),K=[...l,...v].join(" and "),Y=[...l,T,...v].join(" "),W=R.slice(0,6).map(g=>({about:"node",id:g.id,kind:n,label:H(g),why:{field:d[0]?.key??"label",reading:d[0]?.key??"Name",fragment:K,strength:"field"},current:!0,flagged:ye.has(g.id),address:ge(g)})),X=R.length===0?`No ${T} are ${K}.`:`${R.length===1?`One ${F(M(n),n)} is`:`${R.length} ${T} are`} ${K}: ${fe(R.slice(0,6).map(H))}${R.length>6?`, and ${R.length-6} more`:""}.`;if(q)return{about:"kind",say:X,moves:[],picks:W,offer:{draft:Y,label:"Show as a view"}};let Z=d.map(g=>`${g.key}:${g.value}`).join(","),we=`${se(n)}?${new URLSearchParams({filter:Z}).toString()}`,_={to:"kind",kind:n,title:ee(Y),filter:Z,address:we,said:`Went to the ${Y}.`};return{about:"kind",say:`${_.said} ${X}`,moves:[_],picks:W}},Te=e=>M(e)?.figure==="person"?!0:[e,F(M(e),e),I(e)].some(s=>$(s).split(" ").some(n=>Et.has(n))),pt=e=>{let t=[],s=n=>M(n)?.edges??{};for(let[n,r]of Object.entries(s(e)))for(let h of r.to??[])u.has(h)&&t.push({key:n,direction:"out",far:h,words:ct(`${r.description??""} ${n}`)});for(let n of P)for(let[r,h]of Object.entries(s(n)))(h.to??[]).includes(e)&&t.push({key:r,direction:"in",far:n,words:ct(`${h.inverse??""} ${r}`)});return t},mt=e=>{let t=e.match(/^(who|which|what)\b/)?.[1];if(!t)return;let s=Oe(e,k,j);if(!s||s.ask.overdue)return;let n=s.rest.split(" ").filter(Boolean),r=P.flatMap(a=>[I(a),F(M(a),a),a].map(A=>({kind:a,name:$(A)}))).filter(a=>a.name.length>0).sort((a,A)=>A.name.length-a.name.length),h=` ${n.join(" ")} `,d=[];for(let{kind:a,name:A}of r)h.includes(` ${A} `)&&(h=h.replace(` ${A} `," "),d.includes(a)||d.push(a));let l=h.match(/\b(?:is|are|was|were)\b|'s\b/)?.[0],v=h.replace(/'s\b/g," ").split(" ").filter(a=>a.length>0&&!te.has(a)&&!Ce.has(a)),x=t==="who"?d.find(Te):d[0];if(!x&&t!=="who")return;let q=d.find(a=>a!==x),de=v.flatMap(a=>[je(a),...lt.has(je(a))?[...lt]:[]]),T=P.filter(a=>q?a===q:a!==x).flatMap(a=>{let A=ie(a,e.split(" "))??V(p,a).filters.find(D=>D.about==="field"&&D.type==="date");return A?pt(a).filter(D=>(x?D.far===x:Te(D.far))&&D.far!==a).map(D=>({kind:a,field:A,relation:D,said:v.length===0||de.some(ve=>D.words.some(vt=>Lt(vt,ve)))})):[]}).filter(a=>a.said);if(T.length===0)return;let Q=T.filter(a=>n.some(A=>$(a.field.key)===A||$(a.field.label)===A)),R=T.length===1?T[0]:Q.length===1?Q[0]:void 0;if(!R)return;let{kind:K,field:Y,relation:W}=R,X=[...s.ask.from?[{key:Y.key,value:`after:${C(s.ask.from,-1)}`}]:[],...s.ask.to?[{key:Y.key,value:`before:${C(s.ask.to,1)}`}]:[]],Z=w.nodesOfKind(K).filter(a=>X.every(A=>ue(be,a,A))),we=a=>(W.direction==="out"?c.graph.out(a.id,W.key):c.graph.in(a.id,W.key)).filter(A=>A.kind===W.far&&u.has(W.far)),_=[],g=[];for(let a of Z){let A=we(a);A.length===0&&g.push(a);for(let D of A)_.some(ve=>ve.id===D.id)||_.push(D)}let m=Ie(s.ask,Y),E=s.ask.day?`On ${s.ask.day}`:ee(s.ask.words.replace(/^(?:due|for|on|by) (?:the )?/,"")),U=I(K).toLowerCase(),L=X.map(a=>`${a.key}:${a.value}`).join(","),b=`${U} ${m}`,O={to:"kind",kind:K,title:ee(b),filter:L,address:`${se(K)}?${new URLSearchParams({filter:L}).toString()}`,said:`Went to the ${b}.`};if(Z.length===0)return{about:"related",say:`No ${b}. ${O.said}`,moves:[O]};let le=v.join(" "),yt=l==="was"||l==="were",Ge=a=>yt?a===1?"was":"were":a===1?"is":"are",ce=_.map(H),bt=ce.length>8?[...ce.slice(0,8),`${ce.length-8} more`]:ce,kt=_.length===0?`${E}: nobody ${Ge(1)}${le?` ${le}`:""}.`:`${E}: ${fe(bt)}${le?` ${Ge(_.length)} ${le}`:""}.`,$t=t==="who"&&g.length>0?`${fe(g.slice(0,4).map(H))}${g.length>4?` and ${g.length-4} more`:""} ${g.length===1?"has":"have"} nobody.`:"",wt=_.slice(0,8).map(a=>({about:"node",id:a.id,kind:a.kind,label:H(a),why:{field:W.key,reading:Ze(p,W.direction==="out"?K:W.far,W.key,W.direction==="out"?"out":"in"),fragment:m,strength:"field"},current:!0,flagged:ye.has(a.id),address:ge(a)}));return{about:"related",say:[kt,$t,O.said].filter(Boolean).join(" "),moves:[O],picks:wt}},Ke=N.match(jt);if(Ke){let e=Ke[1];if(e&&!rt.has(e)&&!/^(?:it|this|that)$/.test(e)){let n=re(e),r=n?void 0:pe(z(e)||e);if(r?.one){let h=Me(r.one);return{about:"describe",say:`${h.said} ${oe(r.one)}`,moves:[h],subject:r.one.id}}if(!n)return r&&r.picks.length>0?{about:"picks",say:Re(r.picks),moves:[],picks:r.picks}:De()}if(e&&/^(?:it|this|that)$|^(?:here|this place|this page)$/.test(e)){let n=(y.selection??[]).map(r=>w.getNode(r)).find(r=>r!==void 0);if(n)return{about:"describe",say:oe(n),moves:[],subject:n.id}}let t=c.violations();if(t.length===0)return{about:"problems",say:"Nothing is wrong \u2014 every rule holds.",moves:[]};let s={to:"problems",address:"/problems",said:"Went to the problems."};return{about:"problems",say:`${s.said} ${Qe(t)}: ${t.slice(0,4).map(n=>n.message).join("; ")}${t.length>4?"\u2026":"."}`,moves:[s]}}if(Ot.test(N))return Le();let _e=mt(N);if(_e)return _e;let ke=Oe(N,k,j);if(ke&&!re(z(ke.ask.words))&&ke.rest.replace(/'s\b/g,"").split(" ").every(e=>e===""||te.has(e)||Ce.has(e))){let e=ae(N);if(e)return e}if(/^open /.test(N)){let e=ae(N);if(e)return e}let Fe=N.match(Nt)??N.match(/^(?:go|take me|head|get me)(?: back)? (home)$/);if(Fe)return Ee(Fe[1].trim(),!1);let Be=N.match(St);if(Be){let e=Ee(Be[1].trim(),!0);return"unresolved"in e&&e.unresolved&&!/^tell me|^describe/.test(N)?{unresolved:!0}:e}let $e=re(N);if($e){let e=We($e);return{about:"place",say:e.said,moves:[e],subject:$e.slug}}let Ue=ae(N);return Ue||{unresolved:!0}}var Ce=new Set(["who","whom","whose","which","what","whats","what's","who's"]),Et=new Set(["person","people","user","users","member","members","volunteer","volunteers","gardener","gardeners","player","players","staff","worker","workers","employee","employees","owner","owners","assignee","assignees","helper","helpers","student","students","teacher","teachers","customer","customers","client","clients","contact","contacts","author","authors"]),lt=new Set(["work","cover","staff","assign","do","run","schedul","roster","book","duty","serv","help"]);function je(o){let i=o.toLowerCase().replace(/'s$/,"");for(let y of["ing","ed","es","s"])if(i.length>y.length+2&&i.endsWith(y)){let f=i.slice(0,-y.length);return f.length>3&&f[f.length-1]===f[f.length-2]?f.slice(0,-1):f}return i}function ct(o){return o.toLowerCase().split(/[^a-z']+/).filter(i=>i.length>1&&!te.has(i)&&!Ce.has(i)&&!["it","they","them","their","its","this","here","to","at"].includes(i)).map(je)}var Lt=(o,i)=>o===i||o.length>=4&&i.length>=4&&(o.startsWith(i)||i.startsWith(o)),ne=new Set(["done","finished","complete","completed","closed","resolved","agreed","canceled","archived","shipped","delivered"]),Pt=new Set(["open","unfinished","outstanding","pending","remaining","undone","incomplete"]);function ut(o,i){return V(o,i.kind).filters.some(f=>f.about==="field"&&(f.type==="boolean"&&ne.has(f.key.toLowerCase())&&i[f.key]===!0||f.type==="choice"&&typeof i[f.key]=="string"&&ne.has(String(i[f.key]).toLowerCase())))}function fe(o){return o.length<=1?o[0]??"":`${o.slice(0,-1).join(", ")} and ${o[o.length-1]}`}function zt(o,i,y={}){let f=y.scene!==void 0?{...y.pages,scene:y.scene}:y.pages;return[...nt(o,i,f?{pages:f}:{})].map(({first:c,hidden:p,lens:k,...j})=>j)}function gt(o,i){return{...o.principal?{principal:o.principal}:{},...o.places?{places:o.places}:{},...o.selection?{selection:o.selection}:{},...o.place?{place:o.place}:{},...i??o.today?{today:i??o.today}:{},...o.weekStartsOn!==void 0?{weekStartsOn:o.weekStartsOn}:{}}}function Jt(o,i,y,f){let c=ht(o,i,gt(y,f));if(c.unresolved)return c.say?{reply:{say:c.say,proposals:[],grounded:!0}}:{};if(c.about==="picks")return{};let p=c.moves.length>0?{moves:c.moves}:{},k=c.subject?o.graph.getNode(c.subject):void 0;if(c.about==="problems")return{...p,problems:!0};if(k&&(c.about==="describe"||c.about==="here"))return{...p,told:k.id};let j=k?tt(o,ot(Ve(o.violations(),[k.id])).slice(0,3)):[];return{reply:{say:c.say,proposals:j,grounded:!0,...p,...c.picks&&c.picks.length>0?{picks:c.picks}:{},...c.offer?{offer:c.offer}:{}}}}function Yt(o,i,y={}){let f=gt(y),c=[];for(let p of i){let k=typeof p=="string"?p:typeof p=="object"&&p!==null&&typeof p.to=="string"?p.to:void 0;if(!k||k.trim().length===0)continue;let j=ht(o,/^(?:go|take me|open|show)\b/i.test(k.trim())?k:`go to ${k}`,f);if("moves"in j)for(let J of j.moves)c.some(B=>B.address===J.address)||c.push(J)}return c}export{At as NOTHING_BY_THAT_NAME,gt as askContextOf,Jt as goingFrom,Yt as movesFromNames,zt as placesFromViews,ht as resolveAsk};
1
+ import{a as ot}from"./chunk.KSXB4LDF.js";import"./chunk.NGDXH66B.js";import{e as V,l as ue,m as G,q as st}from"./chunk.67WWRC6Y.js";import{a as ee}from"./chunk.G4JJXA63.js";import"./chunk.VJXXCUKS.js";import{b as nt}from"./chunk.Z5AB2DBF.js";import{d as tt}from"./chunk.HPAGOEZG.js";import"./chunk.ISXFH3CK.js";import"./chunk.BXT6FDT4.js";import"./chunk.2FLPDPEL.js";import{d as et}from"./chunk.UUBYFBPN.js";import{c as Ze}from"./chunk.2RVUDRRY.js";import{H as ze,U as Je,Vc as Ne,Wc as Xe,ba as Ye,fa as qe,gb as Ve,hb as Qe,ja as Ae,ka as F}from"./chunk.V5MYKNL7.js";import"./chunk.AJZBJBMO.js";var At="Nothing by that name here.",$=o=>o.normalize("NFD").replace(/\p{M}+/gu,"").toLowerCase().replace(/[’']/g,"'").replace(/[^\p{L}\p{N}' ]+/gu," ").replace(/\s+/g," ").trim(),Nt=/^(?:(?:can you |could you |please )?(?:go|take me|bring me|head|jump|navigate|switch|get me)(?: back)? to|(?:please )?(?:open|show(?: me)?|bring up|let me see|view)) (.+)$/,St=/^(?:(?:can you |could you |please )?tell me (?:about|of)|what(?: is|'s| are) (?:in |on )?|describe|explain|who(?: is|'s)) (.+)$/,Ot=/^(?:what(?: is|'s| am i looking at| do i see)(?: (?:here|this|on (?:this|the) (?:page|screen)|in view|this place|this page))?|where am i|describe (?:this|here|this place|this page)|tell me about (?:this|here|this place|this page))$/,rt=new Set(["here","this","this place","this page","on this page","on the page","on this screen","in view"]),Ct=/^(?:date|day|when|on|at|the date|the day)$/,jt=/^(?:what(?: is|'s) (?:wrong|broken|the (?:problem|matter|trouble))|what needs (?:fixing|attention|doing)|any (?:problems|issues|trouble)|(?:show(?: me)? |go to |open )?(?:the )?(?:problems|issues|trouble|standing|what's wrong)|is (?:anything|something) (?:wrong|broken)|are there (?:any )?(?:problems|issues))(?: (?:with|about|on|in) (.+))?$/,z=o=>o.replace(/^(?:the|a|an|my|our) /,""),te=new Set(["the","a","an","my","our","all","any","of","that","which","who","are","is","be","what","whats","what's","with","me","show","list","every","there","do","i","have","we","due","for","please","were","was","by","from","in","on"]),ft=864e5,he=o=>Date.UTC(Number(o.slice(0,4)),Number(o.slice(5,7))-1,Number(o.slice(8,10))),xe=o=>new Date(o).toISOString().slice(0,10),C=(o,i)=>xe(he(o)+i*ft),xt=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"],Mt=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Wt="(monday|tuesday|tues|wednesday|thursday|thurs|friday|saturday|sunday)",it="(january|february|march|april|may|june|july|august|september|october|november|december|jan|feb|mar|apr|jun|jul|aug|sept|sep|oct|nov|dec)",at="(\\d{1,2})(?:st|nd|rd|th)?",Dt=o=>xt.findIndex(i=>i.startsWith(o.slice(0,3))),dt=o=>Mt.findIndex(i=>o.startsWith(i.toLowerCase()));function Rt(o,i){return Je(o,{year:o.slice(0,4)!==i.slice(0,4)})}function Se(o,i,y){if(o<0||i<1||i>31)return;let f=Number(y.slice(0,4)),c=k=>{let j=Date.UTC(k,o,i);return new Date(j).getUTCMonth()===o?xe(j):void 0},p=c(f);if(p)return he(p)<he(y)-183*ft?c(f+1):p}function Oe(o,i,y){let f=new Date(he(i)).getUTCDay(),c=u=>{let S=(f-y+7)%7,w=C(i,-S+u*7);return{from:w,to:C(w,6)}},p=()=>{let u=`${i.slice(0,8)}01`,S=new Date(Date.UTC(Number(i.slice(0,4)),Number(i.slice(5,7)),1));return{from:u,to:C(xe(S.getTime()),-1)}},k=u=>u?{from:u,to:u,day:Rt(u,i)}:void 0,j=(u,S)=>{let w=Dt(S);return k(u==="this"||u==="next"?C(c(u==="next"?1:0).from,(w-y+7)%7):u==="last"?C(i,-((f-w+6)%7+1)):C(i,(w-f+7)%7))},J=u=>{let S=C(i,f===0?-1:6-f);return{from:C(S,u*7),to:C(S,u*7+1)}},B="\\b(?:(?:due |for |on |by )(?:the )?)?",P=[[/\b(?:overdue|past due|late)\b/,()=>({overdue:!0,to:C(i,-1)})],[/\b(?:due |for |on )?today\b/,()=>({from:i,to:i})],[/\b(?:due |for |on )?tomorrow\b/,()=>k(C(i,1))],[/\b(?:due |for |on )?yesterday\b/,()=>k(C(i,-1))],[/\b(?:due |for |on )?this week\b/,()=>c(0)],[/\b(?:due |for |on )?next week\b/,()=>c(1)],[/\b(?:due |for |on )?(?:last|previous) week\b/,()=>c(-1)],[/\b(?:due |for |on )?next weekend\b/,()=>J(1)],[/\b(?:due |for |on )?(?:this |the )?weekend\b/,()=>J(0)],[/\b(?:due |for |on )?this month\b/,()=>p()],[new RegExp(`${B}(\\d{4}) (\\d{2}) (\\d{2})\\b`),u=>k(Se(Number(u[2])-1,Number(u[3]),`${u[1]}-01-01`))],[new RegExp(`${B}${at} (?:of )?${it}\\b`),u=>k(Se(dt(u[2]),Number(u[1]),i))],[new RegExp(`${B}${it} (?:the )?${at}\\b`),u=>k(Se(dt(u[1]),Number(u[2]),i))],[new RegExp(`${B}(?:(this|next|last|coming) )?${Wt}\\b`),u=>j(u[1],u[2])]];for(let[u,S]of P){let w=o.match(u);if(!w)continue;let N=S(w);if(N)return{ask:{words:w[0],...N},rest:o.replace(w[0]," ").replace(/\s+/g," ").trim()}}}function ht(o,i,y={}){let f=y.principal??{kind:"human"},c=o.seenBy(f),p=c.schema,k=y.today??o.today?.()??ze(),j=y.weekStartsOn??1,J=o.kindsKeptFrom(f),B=o.modules.disabledKinds,P=p.kinds.filter(e=>!J.has(e)&&!B.has(e)),u=new Set(P),S=(y.places??[]).filter(e=>e.kind===null||u.has(e.kind)),w=c.graph,N=$(i).replace(/[?.!]+$/,"").trim();if(N.length===0)return{unresolved:!0};let M=e=>p.tryDefinition(e),H=e=>Ye(M(e.kind),e),I=e=>qe(p,e),se=e=>S.find(t=>t.kind===e&&t.address===Ne(p,e))?.address??Ne(p,e),ge=e=>Xe(p,e.kind,e.id),Me=e=>({to:"record",id:e.id,kind:e.kind,label:H(e),address:ge(e),said:`Went to ${H(e)}.`}),We=e=>{let t=`Went to ${e.title}.`;return e.kind===null?{to:"place",slug:e.slug,title:e.title,address:e.address,...e.slug==="overview"?{face:"scene"}:{},said:t}:e.lens||e.address.startsWith("/places/")?{to:"picture",kind:e.kind,as:e.slug,title:e.title,address:e.address,said:t}:{to:"kind",kind:e.kind,title:e.title,address:e.address,said:t}},De=()=>({unresolved:!0,say:At}),oe=e=>{let t=M(e.kind),s=et(e,t,{limit:3,excerpt:!0}).map(r=>r.alone.startsWith(r.label)?r.alone:`${r.label.toLowerCase()} ${r.alone}`).join(", "),n=c.violations().filter(r=>r.nodeIds.includes(e.id));return[`${H(e)} \u2014 ${Ae(F(t,e.kind))}${s?` (${s})`:""}.`,n.length>0?`Trouble: ${n.map(r=>r.message).join("; ")}.`:""].filter(Boolean).join(" ")},re=e=>{let t=new Set([G(e),G(z(e))]);for(let n of[" page"," view"," lens"," place"," picture"," list"])e.endsWith(n)&&(t.add(G(e.slice(0,-n.length))),t.add(G(z(e.slice(0,-n.length)))));t.delete("");let s=n=>t.has(G(n.title))||t.has(G(z($(n.title))))||t.has(G(n.slug));return S.find(n=>n.kind!==null&&n.address.startsWith("/places/")&&s(n))??S.find(s)},pe=e=>{let t=st(o,e,{principal:f,today:k,limit:6,near:!1,...y.selection?{from:y.selection}:{}}),s=t.hits.filter(r=>r.about==="node"&&u.has(r.kind)&&w.getNode(r.id)!==void 0),n=s.filter(r=>r.why.field==="label"&&r.why.strength==="exact");return n.length===1?{one:w.getNode(n[0].id),picks:s}:n.length>1?{picks:n}:s.length===1&&t.total===1?{one:w.getNode(s[0].id),picks:s}:{picks:s}},Re=e=>{let t=e.map(s=>`${s.label} (${F(M(s.kind),s.kind)})`);return`${e.length===1?"One thing matches":`${e.length} things match`}: ${t.join("; ")}.`},Ee=(e,t)=>{if(rt.has(e))return Le();let s=t?pe(z(e)||e):void 0,n=s?.one&&$(H(s.one))===$(z(e)||e)?void 0:re(e);if(n){let l=We(n);return{about:"place",say:t?`${l.said} ${me(n)}`:l.said,moves:[l],subject:n.slug}}let r=pe(z(e)||e);if(r.one){let l=Me(r.one);return{about:t?"describe":"record",say:t?`${l.said} ${oe(r.one)}`:l.said,moves:[l],subject:r.one.id}}if(r.picks.length>0)return{about:"picks",say:Re(r.picks),moves:[],picks:r.picks};let h=ae(e);if(h)return h;let d=Pe(e);if(d){if(d.rest.split(" ").every(l=>l===""||te.has(l))){let l=I(d.kind),v={to:"kind",kind:d.kind,title:l,address:se(d.kind),said:`Went to the ${l.toLowerCase()}.`};return{about:"kind",say:v.said,moves:[v]}}return{unresolved:!0}}return De()},me=e=>{if(e.kind===null){let h=P.map(l=>({kind:l,count:w.nodesOfKind(l).length})).filter(l=>l.count>0).map(l=>`${l.count} ${(l.count===1?F(M(l.kind),l.kind):I(l.kind)).toLowerCase()}`),d=c.violations().length;return[h.length>0?`It holds ${fe(h)}.`:"It holds nothing yet.",d>0?`${d===1?"One problem":`${d} problems`} to see to.`:""].filter(Boolean).join(" ")}let t=w.nodesOfKind(e.kind).length,s=I(e.kind).toLowerCase(),n=new Set(c.violations().flatMap(h=>h.nodeIds)),r=w.nodesOfKind(e.kind).filter(h=>n.has(h.id)).length;return[e.lens?`It draws the ${s} as ${Ae(e.lens)}${t>0?` \u2014 ${t} of them`:""}.`:`${t===0?"No":t} ${t===1?F(M(e.kind),e.kind):s} ${t===1?"is":"are"} here.`,r>0?`${r} ${r===1?"has":"have"} a problem.`:""].filter(Boolean).join(" ")},Le=()=>{let e=(y.selection??[]).map(s=>w.getNode(s)).find(s=>s!==void 0);if(e)return{about:"here",say:oe(e),moves:[],subject:e.id};let t=S.find(s=>s.slug===y.place)??S.find(s=>s.slug==="home");return t?{about:"here",say:`${t.title}. ${me(t)}`,moves:[],subject:t.slug}:{about:"here",say:me({slug:"home",title:"Home",kind:null,cardinality:"many",address:"/",stop:"#"}),moves:[]}},Pe=e=>{let t=P.flatMap(s=>[I(s),F(M(s),s),s].map(n=>({kind:s,name:$(n)}))).filter(s=>s.name.length>0).sort((s,n)=>n.name.length-s.name.length);for(let{kind:s,name:n}of t)if(!(` ${e} `.indexOf(` ${n} `)<0))return{kind:s,rest:` ${e} `.replace(` ${n} `," ").replace(/\s+/g," ").trim()}},ie=(e,t)=>{let s=V(p,e).filters.filter(d=>d.about==="field"&&d.type==="date");if(s.length===0)return;let n=s.find(d=>t.some(l=>$(d.key)===l||$(d.label)===l));if(n)return n;let r=M(e)?.fieldRoles??{};for(let d of["due","deadline","date","when","start","end"]){let l=r[d],v=l?s.find(x=>x.key===l):void 0;if(v)return v}return s.find(d=>["due","deadline","date","when","on","at"].includes(d.key.toLowerCase()))??(s.length===1?s[0]:void 0)},He=e=>{let t=M(e),s=V(p,e).filters;if(t?.lifecycle)return{conditions:[{key:"is",value:"current"}],holds:d=>ue(be,d,{key:"is",value:"current"})};let r=s.find(d=>d.about==="field"&&d.type==="boolean"&&ne.has($(d.key)));if(r)return{conditions:[{key:r.key,value:"false"}],holds:d=>d[r.key]!==!0};let h=s.find(d=>d.about==="field"&&d.type==="choice"&&(d.options??[]).some(l=>ne.has($(l))));if(h){let d=new Set((h.options??[]).filter(v=>ne.has($(v)))),l=(h.options??[]).filter(v=>!d.has(v));return l.length===1?{conditions:[{key:h.key,value:l[0]}],holds:v=>v[h.key]===l[0]}:"unsayable"}return{conditions:[],holds:()=>!0}},Ie=(e,t)=>{let s=e.words.startsWith("due")||$(t.key)==="due",n=Ct.test($(t.label));if(e.day)return s?`due ${e.day}`:n?`on ${e.day}`:`${t.label.toLowerCase()} on ${e.day}`;let r=e.words.replace(/^(?:due|for|on|by) (?:the )?/,"");return s?`due ${r}`:n?r:`${t.label.toLowerCase()} ${r}`},ye=new Set(c.violations().flatMap(e=>e.nodeIds)),be={schema:p,graph:c.graph,flagged:ye,today:k},ae=e=>{let t=Oe(e,k,j),s=Pe(t?.rest??e),n=s?.kind,r=(s?.rest??t?.rest??e).split(" ").filter(Boolean);if(!n&&t){let g=e.split(" "),m=P.filter(L=>ie(L,g)!==void 0),E=m.filter(L=>{let b=ie(L,g);return g.some(O=>$(b.key)===O||$(b.label)===O)}),U=m.length===1?m:E;if(U.length!==1)return;n=U[0]}if(!n)return;let h=V(p,n).filters,d=[],l=[],v=[],x=[],q=!1,de=[];for(let g=0;g<r.length;g++){let m=r[g],E=g>0&&(r[g-1]==="not"||r[g-1]==="un"),U=h.find(b=>b.about==="field"&&b.type==="choice"&&(b.options??[]).some(O=>$(O)===m));if(U&&!E){let b=(U.options??[]).find(O=>$(O)===m);d.push({key:U.key,value:b}),l.push(b);continue}let L=h.find(b=>b.about==="field"&&b.type==="boolean"&&[$(b.key),$(b.label)].some(O=>O===m||O===m.replace(/^un/,"")));if(L){let b=!E&&!(m.startsWith("un")&&!$(L.key).startsWith("un"));d.push({key:L.key,value:String(b)}),l.push(b?m:`not ${m.replace(/^un/,"")}`);continue}if(Pt.has(m)&&!E){let b=He(n);b==="unsayable"?(q=!0,x.push(O=>!ut(p,O))):(d.push(...b.conditions),x.push(b.holds)),l.push(m);continue}m==="not"||m==="un"||t&&h.some(b=>b.type==="date"&&($(b.key)===m||$(b.label)===m))||de.push(m)}if(r=de,r.some(g=>!te.has(g))||!t&&d.length===0&&x.length===0)return;let T=I(n).toLowerCase(),Q=I(n);if(t){let g=ie(n,e.split(" "));if(!g){let m={to:"kind",kind:n,title:Q,address:se(n),said:`Went to the ${T}.`};return{about:"kind",say:`${ee(Q)} carry no date, so I can't tell which are ${/^(?:due|for|on|overdue|past due|late)\b/.test(t.ask.words)?t.ask.words:`due ${t.ask.words}`}. ${m.said}`,moves:[m]}}if(t.ask.from&&d.push({key:g.key,value:`after:${C(t.ask.from,-1)}`}),t.ask.to&&d.push({key:g.key,value:`before:${C(t.ask.to,1)}`}),t.ask.overdue){let m=He(n);m==="unsayable"?(q=!0,x.push(E=>!ut(p,E))):(d.push(...m.conditions),x.push(m.holds))}t.ask.overdue?l.push("overdue"):v.push(Ie(t.ask,g))}let R=w.nodesOfKind(n).filter(g=>d.every(m=>ue(be,g,m))&&x.every(m=>m(g))),K=[...l,...v].join(" and "),Y=[...l,T,...v].join(" "),W=R.slice(0,6).map(g=>({about:"node",id:g.id,kind:n,label:H(g),why:{field:d[0]?.key??"label",reading:d[0]?.key??"Name",fragment:K,strength:"field"},current:!0,flagged:ye.has(g.id),address:ge(g)})),X=R.length===0?`No ${T} are ${K}.`:`${R.length===1?`One ${F(M(n),n)} is`:`${R.length} ${T} are`} ${K}: ${fe(R.slice(0,6).map(H))}${R.length>6?`, and ${R.length-6} more`:""}.`;if(q)return{about:"kind",say:X,moves:[],picks:W,offer:{draft:Y,label:"Show as a view"}};let Z=d.map(g=>`${g.key}:${g.value}`).join(","),we=`${se(n)}?${new URLSearchParams({filter:Z}).toString()}`,_={to:"kind",kind:n,title:ee(Y),filter:Z,address:we,said:`Went to the ${Y}.`};return{about:"kind",say:`${_.said} ${X}`,moves:[_],picks:W}},Te=e=>M(e)?.figure==="person"?!0:[e,F(M(e),e),I(e)].some(s=>$(s).split(" ").some(n=>Et.has(n))),pt=e=>{let t=[],s=n=>M(n)?.edges??{};for(let[n,r]of Object.entries(s(e)))for(let h of r.to??[])u.has(h)&&t.push({key:n,direction:"out",far:h,words:ct(`${r.description??""} ${n}`)});for(let n of P)for(let[r,h]of Object.entries(s(n)))(h.to??[]).includes(e)&&t.push({key:r,direction:"in",far:n,words:ct(`${h.inverse??""} ${r}`)});return t},mt=e=>{let t=e.match(/^(who|which|what)\b/)?.[1];if(!t)return;let s=Oe(e,k,j);if(!s||s.ask.overdue)return;let n=s.rest.split(" ").filter(Boolean),r=P.flatMap(a=>[I(a),F(M(a),a),a].map(A=>({kind:a,name:$(A)}))).filter(a=>a.name.length>0).sort((a,A)=>A.name.length-a.name.length),h=` ${n.join(" ")} `,d=[];for(let{kind:a,name:A}of r)h.includes(` ${A} `)&&(h=h.replace(` ${A} `," "),d.includes(a)||d.push(a));let l=h.match(/\b(?:is|are|was|were)\b|'s\b/)?.[0],v=h.replace(/'s\b/g," ").split(" ").filter(a=>a.length>0&&!te.has(a)&&!Ce.has(a)),x=t==="who"?d.find(Te):d[0];if(!x&&t!=="who")return;let q=d.find(a=>a!==x),de=v.flatMap(a=>[je(a),...lt.has(je(a))?[...lt]:[]]),T=P.filter(a=>q?a===q:a!==x).flatMap(a=>{let A=ie(a,e.split(" "))??V(p,a).filters.find(D=>D.about==="field"&&D.type==="date");return A?pt(a).filter(D=>(x?D.far===x:Te(D.far))&&D.far!==a).map(D=>({kind:a,field:A,relation:D,said:v.length===0||de.some(ve=>D.words.some(vt=>Lt(vt,ve)))})):[]}).filter(a=>a.said);if(T.length===0)return;let Q=T.filter(a=>n.some(A=>$(a.field.key)===A||$(a.field.label)===A)),R=T.length===1?T[0]:Q.length===1?Q[0]:void 0;if(!R)return;let{kind:K,field:Y,relation:W}=R,X=[...s.ask.from?[{key:Y.key,value:`after:${C(s.ask.from,-1)}`}]:[],...s.ask.to?[{key:Y.key,value:`before:${C(s.ask.to,1)}`}]:[]],Z=w.nodesOfKind(K).filter(a=>X.every(A=>ue(be,a,A))),we=a=>(W.direction==="out"?c.graph.out(a.id,W.key):c.graph.in(a.id,W.key)).filter(A=>A.kind===W.far&&u.has(W.far)),_=[],g=[];for(let a of Z){let A=we(a);A.length===0&&g.push(a);for(let D of A)_.some(ve=>ve.id===D.id)||_.push(D)}let m=Ie(s.ask,Y),E=s.ask.day?`On ${s.ask.day}`:ee(s.ask.words.replace(/^(?:due|for|on|by) (?:the )?/,"")),U=I(K).toLowerCase(),L=X.map(a=>`${a.key}:${a.value}`).join(","),b=`${U} ${m}`,O={to:"kind",kind:K,title:ee(b),filter:L,address:`${se(K)}?${new URLSearchParams({filter:L}).toString()}`,said:`Went to the ${b}.`};if(Z.length===0)return{about:"related",say:`No ${b}. ${O.said}`,moves:[O]};let le=v.join(" "),yt=l==="was"||l==="were",Ge=a=>yt?a===1?"was":"were":a===1?"is":"are",ce=_.map(H),bt=ce.length>8?[...ce.slice(0,8),`${ce.length-8} more`]:ce,kt=_.length===0?`${E}: nobody ${Ge(1)}${le?` ${le}`:""}.`:`${E}: ${fe(bt)}${le?` ${Ge(_.length)} ${le}`:""}.`,$t=t==="who"&&g.length>0?`${fe(g.slice(0,4).map(H))}${g.length>4?` and ${g.length-4} more`:""} ${g.length===1?"has":"have"} nobody.`:"",wt=_.slice(0,8).map(a=>({about:"node",id:a.id,kind:a.kind,label:H(a),why:{field:W.key,reading:Ze(p,W.direction==="out"?K:W.far,W.key,W.direction==="out"?"out":"in"),fragment:m,strength:"field"},current:!0,flagged:ye.has(a.id),address:ge(a)}));return{about:"related",say:[kt,$t,O.said].filter(Boolean).join(" "),moves:[O],picks:wt}},Ke=N.match(jt);if(Ke){let e=Ke[1];if(e&&!rt.has(e)&&!/^(?:it|this|that)$/.test(e)){let n=re(e),r=n?void 0:pe(z(e)||e);if(r?.one){let h=Me(r.one);return{about:"describe",say:`${h.said} ${oe(r.one)}`,moves:[h],subject:r.one.id}}if(!n)return r&&r.picks.length>0?{about:"picks",say:Re(r.picks),moves:[],picks:r.picks}:De()}if(e&&/^(?:it|this|that)$|^(?:here|this place|this page)$/.test(e)){let n=(y.selection??[]).map(r=>w.getNode(r)).find(r=>r!==void 0);if(n)return{about:"describe",say:oe(n),moves:[],subject:n.id}}let t=c.violations();if(t.length===0)return{about:"problems",say:"Nothing is wrong \u2014 every rule holds.",moves:[]};let s={to:"problems",address:"/problems",said:"Went to the problems."};return{about:"problems",say:`${s.said} ${Qe(t)}: ${t.slice(0,4).map(n=>n.message).join("; ")}${t.length>4?"\u2026":"."}`,moves:[s]}}if(Ot.test(N))return Le();let _e=mt(N);if(_e)return _e;let ke=Oe(N,k,j);if(ke&&!re(z(ke.ask.words))&&ke.rest.replace(/'s\b/g,"").split(" ").every(e=>e===""||te.has(e)||Ce.has(e))){let e=ae(N);if(e)return e}if(/^open /.test(N)){let e=ae(N);if(e)return e}let Fe=N.match(Nt)??N.match(/^(?:go|take me|head|get me)(?: back)? (home)$/);if(Fe)return Ee(Fe[1].trim(),!1);let Be=N.match(St);if(Be){let e=Ee(Be[1].trim(),!0);return"unresolved"in e&&e.unresolved&&!/^tell me|^describe/.test(N)?{unresolved:!0}:e}let $e=re(N);if($e){let e=We($e);return{about:"place",say:e.said,moves:[e],subject:$e.slug}}let Ue=ae(N);return Ue||{unresolved:!0}}var Ce=new Set(["who","whom","whose","which","what","whats","what's","who's"]),Et=new Set(["person","people","user","users","member","members","volunteer","volunteers","gardener","gardeners","player","players","staff","worker","workers","employee","employees","owner","owners","assignee","assignees","helper","helpers","student","students","teacher","teachers","customer","customers","client","clients","contact","contacts","author","authors"]),lt=new Set(["work","cover","staff","assign","do","run","schedul","roster","book","duty","serv","help"]);function je(o){let i=o.toLowerCase().replace(/'s$/,"");for(let y of["ing","ed","es","s"])if(i.length>y.length+2&&i.endsWith(y)){let f=i.slice(0,-y.length);return f.length>3&&f[f.length-1]===f[f.length-2]?f.slice(0,-1):f}return i}function ct(o){return o.toLowerCase().split(/[^a-z']+/).filter(i=>i.length>1&&!te.has(i)&&!Ce.has(i)&&!["it","they","them","their","its","this","here","to","at"].includes(i)).map(je)}var Lt=(o,i)=>o===i||o.length>=4&&i.length>=4&&(o.startsWith(i)||i.startsWith(o)),ne=new Set(["done","finished","complete","completed","closed","resolved","agreed","canceled","archived","shipped","delivered"]),Pt=new Set(["open","unfinished","outstanding","pending","remaining","undone","incomplete"]);function ut(o,i){return V(o,i.kind).filters.some(f=>f.about==="field"&&(f.type==="boolean"&&ne.has(f.key.toLowerCase())&&i[f.key]===!0||f.type==="choice"&&typeof i[f.key]=="string"&&ne.has(String(i[f.key]).toLowerCase())))}function fe(o){return o.length<=1?o[0]??"":`${o.slice(0,-1).join(", ")} and ${o[o.length-1]}`}function zt(o,i,y={}){let f=y.scene!==void 0?{...y.pages,scene:y.scene}:y.pages;return[...nt(o,i,f?{pages:f}:{})].map(({first:c,hidden:p,lens:k,...j})=>j)}function gt(o,i){return{...o.principal?{principal:o.principal}:{},...o.places?{places:o.places}:{},...o.selection?{selection:o.selection}:{},...o.place?{place:o.place}:{},...i??o.today?{today:i??o.today}:{},...o.weekStartsOn!==void 0?{weekStartsOn:o.weekStartsOn}:{}}}function Jt(o,i,y,f){let c=ht(o,i,gt(y,f));if(c.unresolved)return c.say?{reply:{say:c.say,proposals:[],grounded:!0}}:{};if(c.about==="picks")return{};let p=c.moves.length>0?{moves:c.moves}:{},k=c.subject?o.graph.getNode(c.subject):void 0;if(c.about==="problems")return{...p,problems:!0};if(k&&(c.about==="describe"||c.about==="here"))return{...p,told:k.id};let j=k?tt(o,ot(Ve(o.violations(),[k.id])).slice(0,3)):[];return{reply:{say:c.say,proposals:j,grounded:!0,...p,...c.picks&&c.picks.length>0?{picks:c.picks}:{},...c.offer?{offer:c.offer}:{}}}}function Yt(o,i,y={}){let f=gt(y),c=[];for(let p of i){let k=typeof p=="string"?p:typeof p=="object"&&p!==null&&typeof p.to=="string"?p.to:void 0;if(!k||k.trim().length===0)continue;let j=ht(o,/^(?:go|take me|open|show)\b/i.test(k.trim())?k:`go to ${k}`,f);if("moves"in j)for(let J of j.moves)c.some(B=>B.address===J.address)||c.push(J)}return c}export{At as NOTHING_BY_THAT_NAME,gt as askContextOf,Jt as goingFrom,Yt as movesFromNames,zt as placesFromViews,ht as resolveAsk};
@@ -1,4 +1,4 @@
1
- var __graviewPreload=(base,files)=>{if(typeof document>"u")return;const asked=globalThis.__graviewPreloaded??=new Set;for(const file of files){const href=new URL(file,base).href;if(asked.has(href))continue;asked.add(href);const link=document.createElement("link");link.rel="modulepreload";link.href=href;document.head.append(link)}};import{a as Qe,b as we}from"./chunk.HFYUAK5Z.js";import{g as Xe}from"./chunk.GAFYE37S.js";import{e as Je}from"./chunk.STBJV6HJ.js";import{c as qe,f as Ye,g as ve}from"./chunk.F5UVEF2R.js";import{a as he,d as Fe,e as ze,f as Ze,g as et,h as tt,i as rt,j as nt}from"./chunk.OYMM2UWE.js";import{b as ne,d as se}from"./chunk.FGDHEVH4.js";import{a as re,f as Be,h as $e}from"./chunk.M5QFUGGG.js";import"./chunk.PXQVXBNG.js";import{a as $}from"./chunk.SDO3U72B.js";import"./chunk.5ZMENPY4.js";import"./chunk.AJZBJBMO.js";var st=["good","warn","bad","neutral","accent"],ot=["value","max","aria-label","placeholder","disabled"],it=["click","change"],be=["_blank","_self"],at=["section","div","span","strong","p","hr","a","button","input","progress"],oe={type:{oneOf:st}},ke={"gv-card":{host:"section",properties:{tone:oe},events:{},children:"any"},"gv-group":{host:"div",properties:{direction:{type:{oneOf:["row","column"]}}},events:{},children:"any"},"gv-title":{host:"strong",properties:{},events:{},children:"text"},"gv-text":{host:"p",properties:{tone:oe},events:{},children:"text"},"gv-badge":{host:"span",properties:{tone:oe},events:{},children:"text"},"gv-field":{host:"div",properties:{label:{type:"string"}},events:{},children:"text"},"gv-progress":{host:"progress",properties:{value:{type:"number",as:"value"},max:{type:"number",as:"max"},label:{type:"string",as:"aria-label"}},events:{},children:"none"},"gv-divider":{host:"hr",properties:{},events:{},children:"none"},"gv-link":{host:"a",properties:{href:{type:"url"}},events:{},children:"text"},"gv-button":{host:"button",properties:{tone:oe,disabled:{type:"boolean",as:"disabled"}},events:{press:{from:"click"}},children:"text"},"gv-input":{host:"input",properties:{label:{type:"string",as:"aria-label"},value:{type:"string",as:"value"},placeholder:{type:"string",as:"placeholder"}},events:{change:{from:"change",detail:"value"}},children:"none"}},xe=1e4;var kt=0,xt=1,St=2,Tt=3,lt=1,Mt=2,Et=3,Kt=1,Rt=3,Gt=8,Se="~",Te=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),Y=n=>typeof n=="object"&&n!==null&&!Array.isArray(n);function dt(n,e){return e.type==="url"?"href":e.as??`data-gv-${n.toLowerCase()}`}var Wt=2e3;function ut(n,e){if(e==null)return{ok:!0,value:null};let o=n.type;if(o==="boolean")return typeof e=="boolean"?{ok:!0,value:e}:{ok:!1,reason:"value"};if(o==="number")return typeof e=="number"&&Number.isFinite(e)?{ok:!0,value:String(e)}:{ok:!1,reason:"value"};if(typeof e!="string"||e.length>Wt)return{ok:!1,reason:o==="url"?"url":"value"};if(typeof o=="object")return o.oneOf.includes(e)?{ok:!0,value:e}:{ok:!1,reason:"value"};if(o==="url"){let p;try{p=new URL(e)}catch{return{ok:!1,reason:"url"}}return p.protocol!=="https:"||p.hostname===""||!/^https:\/\//i.test(e)?{ok:!1,reason:"url"}:{ok:!0,value:p.href}}return{ok:!0,value:e}}function _t(n){let e=n.host==="a";return at.includes(n.host)&&(n.target===void 0||e&&be.includes(n.target))&&Object.values(n.properties).every(o=>o.type!=="url"||e)&&Object.values(n.properties).every(o=>o.as===void 0||o.type!=="url"&&ot.includes(o.as))&&Object.values(n.events).every(o=>it.includes(o.from))}function Me(n,e){let o=e.kit??ke,p=e.maxNodes??2e3,s=n.ownerDocument,g=[],k=new Map,G={dom:n,name:Se,component:{host:"div",properties:{},events:{},children:"any"},children:[],listeners:new Map,id:Se};k.set(Se,G);let E=e.links?new Set(e.links.origins.flatMap(t=>{try{let d=new URL(t);return d.protocol==="https:"&&d.hostname!==""?[d.origin]:[]}catch{return[]}})):void 0,A=0,S=0,N=!1,c=t=>{g.push(t),g.length>200&&g.shift()},T=()=>({dom:s.createComment(""),children:[],refused:!0,listeners:new Map}),M=(t,d,h)=>{let i=t.component;if(!Te(i.properties,d))return c({reason:"property",element:t.name,name:d});let r=i.properties[d],f=ut(r,h),w=f.ok&&r.type==="url"&&E&&typeof f.value=="string"&&!E.has(new URL(f.value).origin)?{ok:!1,reason:"url"}:f,y=t.dom,b=dt(d,r);if(!w.ok)return y.removeAttribute(b),c({reason:w.reason,element:t.name,name:d});let W=w.value;W===null||W===!1?y.removeAttribute(b):y.setAttribute(b,W===!0?"":W),b==="value"&&"value"in y&&(y.value=typeof W=="string"?W:""),b==="disabled"&&"disabled"in y&&(y.disabled=W!==null&&W!==!1)},x=(t,d,h)=>{let i=t.component;if(!Te(i.events,d))return c({reason:"event",element:t.name,name:d});let r=t.listeners.get(d);if(r&&(r(),t.listeners.delete(d),S-=1),h==null)return;if(!Y(h)||typeof h.listener!="number")return c({reason:"value",element:t.name,name:d});let f=h.listener,w=i.events[d],y=t.dom,b=()=>e.onEvent(f,w.detail==="value"?String(y.value??""):void 0);y.addEventListener(w.from,b),t.listeners.set(d,()=>y.removeEventListener(w.from,b)),S+=1},v=t=>{if(!t.refused){A-=1,t.id!==void 0&&k.delete(t.id);for(let d of t.listeners.values())d();S-=t.listeners.size,t.listeners.clear();for(let d of t.children)v(d)}},_=(t,d)=>{if(!Y(t)||typeof t.id!="string"||k.has(t.id))return c({reason:"record"}),T();if(A>=p)return c({reason:"budget"}),N||(N=!0,e.onOverBudget?.()),T();let h=t.id,i=d.component.children;if(t.type===Gt)return T();if(t.type===Rt){if(i==="none")return c({reason:"child",element:d.name}),T();let b={dom:s.createTextNode(String(t.data??"").slice(0,xe)),children:[],text:!0,listeners:new Map,id:h};return k.set(h,b),A+=1,b}if(t.type!==Kt)return c({reason:"record"}),T();let r=String(t.element);if(!Te(o,r)||!_t(o[r]))return c({reason:"element",element:r}),T();if(i!=="any")return c({reason:"child",element:r}),T();let f=o[r],w=s.createElement(f.host);w.setAttribute("data-gv",r.replace(/^gv-/,"")),w.className=`graview-guest-${r.replace(/^gv-/,"")}`,f.host==="a"&&(w.setAttribute("rel","noopener noreferrer"),w.setAttribute("target",f.target??"_blank"),w.setAttribute("referrerpolicy","no-referrer")),f.host==="button"&&w.setAttribute("type","button");let y={dom:w,name:r,component:f,children:[],listeners:new Map,id:h};if(k.set(h,y),A+=1,Y(t.properties))for(let[b,W]of Object.entries(t.properties))M(y,b,W);if(Y(t.attributes))for(let b of Object.keys(t.attributes))c({reason:"attribute",element:r,name:b});if(Y(t.eventListeners))for(let[b,W]of Object.entries(t.eventListeners))x(y,b,W);if(Array.isArray(t.children))for(let b of t.children){let W=_(b,y);y.children.push(W),w.appendChild(W.dom)}return y},P=t=>{if(!Array.isArray(t))return c({reason:"record"});let[d,h]=t,i=typeof h=="string"?k.get(h):void 0;if(!i)return c({reason:"record"});switch(d){case kt:{if(i.text)return c({reason:"record"});let r=Number(t[3]),f=Number.isInteger(r)&&r>=0&&r<=i.children.length?r:i.children.length,w=_(t[2],i);i.dom.insertBefore(w.dom,i.children[f]?.dom??null),i.children.splice(f,0,w);return}case xt:{let r=Number(t[2]),f=i.children[r];if(!f)return c({reason:"record"});i.children.splice(r,1),f.dom.parentNode?.removeChild(f.dom),v(f);return}case St:if(!i.text)return c({reason:"record"});i.dom.data=String(t[2]??"").slice(0,xe);return;case Tt:{if(i===G||i.text)return c({reason:"record"});let r=String(t[2]),f=t[4]??lt;return f===lt?M(i,r,t[3]):f===Et?x(i,r,t[3]):c(f===Mt?{reason:"attribute",element:i.name,name:r}:{reason:"record"})}default:return c({reason:"record"})}};return{apply(t,d){if(!Array.isArray(t))return c({reason:"record"}),!0;for(let h=0;h<t.length;h+=1){if(d&&h%32===0&&d())return!1;P(t[h])}return!0},get refused(){return g},get size(){return A},get listening(){return S},dispose(){for(let t of G.children)v(t);G.children.length=0,n.replaceChildren()}}}var Ee=`
1
+ var __graviewPreload=(base,files)=>{if(typeof document>"u")return;const asked=globalThis.__graviewPreloaded??=new Set;for(const file of files){const href=new URL(file,base).href;if(asked.has(href))continue;asked.add(href);const link=document.createElement("link");link.rel="modulepreload";link.href=href;document.head.append(link)}};import{a as Qe,b as we}from"./chunk.HFYUAK5Z.js";import{g as Xe}from"./chunk.GAFYE37S.js";import{e as Je}from"./chunk.ZRLXVYPG.js";import{c as qe,f as Ye,g as ve}from"./chunk.S2U5CEP4.js";import{a as he,d as Fe,e as ze,f as Ze,g as et,h as tt,i as rt,j as nt}from"./chunk.H7POIT3V.js";import{b as ne,d as se}from"./chunk.W4HBRXMY.js";import{a as re,f as Be,h as $e}from"./chunk.D25XEVKO.js";import"./chunk.PXQVXBNG.js";import{a as $}from"./chunk.SDO3U72B.js";import"./chunk.V5MYKNL7.js";import"./chunk.AJZBJBMO.js";var st=["good","warn","bad","neutral","accent"],ot=["value","max","aria-label","placeholder","disabled"],it=["click","change"],be=["_blank","_self"],at=["section","div","span","strong","p","hr","a","button","input","progress"],oe={type:{oneOf:st}},ke={"gv-card":{host:"section",properties:{tone:oe},events:{},children:"any"},"gv-group":{host:"div",properties:{direction:{type:{oneOf:["row","column"]}}},events:{},children:"any"},"gv-title":{host:"strong",properties:{},events:{},children:"text"},"gv-text":{host:"p",properties:{tone:oe},events:{},children:"text"},"gv-badge":{host:"span",properties:{tone:oe},events:{},children:"text"},"gv-field":{host:"div",properties:{label:{type:"string"}},events:{},children:"text"},"gv-progress":{host:"progress",properties:{value:{type:"number",as:"value"},max:{type:"number",as:"max"},label:{type:"string",as:"aria-label"}},events:{},children:"none"},"gv-divider":{host:"hr",properties:{},events:{},children:"none"},"gv-link":{host:"a",properties:{href:{type:"url"}},events:{},children:"text"},"gv-button":{host:"button",properties:{tone:oe,disabled:{type:"boolean",as:"disabled"}},events:{press:{from:"click"}},children:"text"},"gv-input":{host:"input",properties:{label:{type:"string",as:"aria-label"},value:{type:"string",as:"value"},placeholder:{type:"string",as:"placeholder"}},events:{change:{from:"change",detail:"value"}},children:"none"}},xe=1e4;var kt=0,xt=1,St=2,Tt=3,lt=1,Mt=2,Et=3,Kt=1,Rt=3,Gt=8,Se="~",Te=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),Y=n=>typeof n=="object"&&n!==null&&!Array.isArray(n);function dt(n,e){return e.type==="url"?"href":e.as??`data-gv-${n.toLowerCase()}`}var Wt=2e3;function ut(n,e){if(e==null)return{ok:!0,value:null};let o=n.type;if(o==="boolean")return typeof e=="boolean"?{ok:!0,value:e}:{ok:!1,reason:"value"};if(o==="number")return typeof e=="number"&&Number.isFinite(e)?{ok:!0,value:String(e)}:{ok:!1,reason:"value"};if(typeof e!="string"||e.length>Wt)return{ok:!1,reason:o==="url"?"url":"value"};if(typeof o=="object")return o.oneOf.includes(e)?{ok:!0,value:e}:{ok:!1,reason:"value"};if(o==="url"){let p;try{p=new URL(e)}catch{return{ok:!1,reason:"url"}}return p.protocol!=="https:"||p.hostname===""||!/^https:\/\//i.test(e)?{ok:!1,reason:"url"}:{ok:!0,value:p.href}}return{ok:!0,value:e}}function _t(n){let e=n.host==="a";return at.includes(n.host)&&(n.target===void 0||e&&be.includes(n.target))&&Object.values(n.properties).every(o=>o.type!=="url"||e)&&Object.values(n.properties).every(o=>o.as===void 0||o.type!=="url"&&ot.includes(o.as))&&Object.values(n.events).every(o=>it.includes(o.from))}function Me(n,e){let o=e.kit??ke,p=e.maxNodes??2e3,s=n.ownerDocument,g=[],k=new Map,G={dom:n,name:Se,component:{host:"div",properties:{},events:{},children:"any"},children:[],listeners:new Map,id:Se};k.set(Se,G);let E=e.links?new Set(e.links.origins.flatMap(t=>{try{let d=new URL(t);return d.protocol==="https:"&&d.hostname!==""?[d.origin]:[]}catch{return[]}})):void 0,A=0,S=0,N=!1,c=t=>{g.push(t),g.length>200&&g.shift()},T=()=>({dom:s.createComment(""),children:[],refused:!0,listeners:new Map}),M=(t,d,h)=>{let i=t.component;if(!Te(i.properties,d))return c({reason:"property",element:t.name,name:d});let r=i.properties[d],f=ut(r,h),w=f.ok&&r.type==="url"&&E&&typeof f.value=="string"&&!E.has(new URL(f.value).origin)?{ok:!1,reason:"url"}:f,y=t.dom,b=dt(d,r);if(!w.ok)return y.removeAttribute(b),c({reason:w.reason,element:t.name,name:d});let W=w.value;W===null||W===!1?y.removeAttribute(b):y.setAttribute(b,W===!0?"":W),b==="value"&&"value"in y&&(y.value=typeof W=="string"?W:""),b==="disabled"&&"disabled"in y&&(y.disabled=W!==null&&W!==!1)},x=(t,d,h)=>{let i=t.component;if(!Te(i.events,d))return c({reason:"event",element:t.name,name:d});let r=t.listeners.get(d);if(r&&(r(),t.listeners.delete(d),S-=1),h==null)return;if(!Y(h)||typeof h.listener!="number")return c({reason:"value",element:t.name,name:d});let f=h.listener,w=i.events[d],y=t.dom,b=()=>e.onEvent(f,w.detail==="value"?String(y.value??""):void 0);y.addEventListener(w.from,b),t.listeners.set(d,()=>y.removeEventListener(w.from,b)),S+=1},v=t=>{if(!t.refused){A-=1,t.id!==void 0&&k.delete(t.id);for(let d of t.listeners.values())d();S-=t.listeners.size,t.listeners.clear();for(let d of t.children)v(d)}},_=(t,d)=>{if(!Y(t)||typeof t.id!="string"||k.has(t.id))return c({reason:"record"}),T();if(A>=p)return c({reason:"budget"}),N||(N=!0,e.onOverBudget?.()),T();let h=t.id,i=d.component.children;if(t.type===Gt)return T();if(t.type===Rt){if(i==="none")return c({reason:"child",element:d.name}),T();let b={dom:s.createTextNode(String(t.data??"").slice(0,xe)),children:[],text:!0,listeners:new Map,id:h};return k.set(h,b),A+=1,b}if(t.type!==Kt)return c({reason:"record"}),T();let r=String(t.element);if(!Te(o,r)||!_t(o[r]))return c({reason:"element",element:r}),T();if(i!=="any")return c({reason:"child",element:r}),T();let f=o[r],w=s.createElement(f.host);w.setAttribute("data-gv",r.replace(/^gv-/,"")),w.className=`graview-guest-${r.replace(/^gv-/,"")}`,f.host==="a"&&(w.setAttribute("rel","noopener noreferrer"),w.setAttribute("target",f.target??"_blank"),w.setAttribute("referrerpolicy","no-referrer")),f.host==="button"&&w.setAttribute("type","button");let y={dom:w,name:r,component:f,children:[],listeners:new Map,id:h};if(k.set(h,y),A+=1,Y(t.properties))for(let[b,W]of Object.entries(t.properties))M(y,b,W);if(Y(t.attributes))for(let b of Object.keys(t.attributes))c({reason:"attribute",element:r,name:b});if(Y(t.eventListeners))for(let[b,W]of Object.entries(t.eventListeners))x(y,b,W);if(Array.isArray(t.children))for(let b of t.children){let W=_(b,y);y.children.push(W),w.appendChild(W.dom)}return y},P=t=>{if(!Array.isArray(t))return c({reason:"record"});let[d,h]=t,i=typeof h=="string"?k.get(h):void 0;if(!i)return c({reason:"record"});switch(d){case kt:{if(i.text)return c({reason:"record"});let r=Number(t[3]),f=Number.isInteger(r)&&r>=0&&r<=i.children.length?r:i.children.length,w=_(t[2],i);i.dom.insertBefore(w.dom,i.children[f]?.dom??null),i.children.splice(f,0,w);return}case xt:{let r=Number(t[2]),f=i.children[r];if(!f)return c({reason:"record"});i.children.splice(r,1),f.dom.parentNode?.removeChild(f.dom),v(f);return}case St:if(!i.text)return c({reason:"record"});i.dom.data=String(t[2]??"").slice(0,xe);return;case Tt:{if(i===G||i.text)return c({reason:"record"});let r=String(t[2]),f=t[4]??lt;return f===lt?M(i,r,t[3]):f===Et?x(i,r,t[3]):c(f===Mt?{reason:"attribute",element:i.name,name:r}:{reason:"record"})}default:return c({reason:"record"})}};return{apply(t,d){if(!Array.isArray(t))return c({reason:"record"}),!0;for(let h=0;h<t.length;h+=1){if(d&&h%32===0&&d())return!1;P(t[h])}return!0},get refused(){return g},get size(){return A},get listening(){return S},dispose(){for(let t of G.children)v(t);G.children.length=0,n.replaceChildren()}}}var Ee=`
2
2
  .graview-guest { display: flex; flex-direction: column; gap: 8px; min-width: 0; color: var(--graview-ink, inherit); font: inherit; }
3
3
  .graview-guest-card { display: flex; flex-direction: column; gap: 6px; padding: 12px; border: 1px solid var(--graview-edge, #d0d0d0); border-radius: 10px; background: var(--graview-panel, transparent); }
4
4
  .graview-guest-group { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
@@ -18,4 +18,4 @@ var __graviewPreload=(base,files)=>{if(typeof document>"u")return;const asked=gl
18
18
  .graview-guest [data-gv-tone="warn"] { color: var(--graview-warn, inherit); }
19
19
  .graview-guest [data-gv-tone="accent"] { color: var(--graview-accent, inherit); }
20
20
  .graview-guest [data-gv-tone="neutral"] { color: var(--graview-ink-muted, inherit); }
21
- `;var ct=new WeakSet;function Lt(n,e){if(n.startsWith("blob:"))return"blob:";try{return new URL(n,e.location.href).origin}catch{return n}}function pt(n,e,o){let p=Lt(e,n),s=`this page's Content-Security-Policy${o?` (${o})`:""} does not allow a worker from ${p}: it needs worker-src ${p}`;return ct.has(n)||(ct.add(n),n.console?.warn?.(`Graview: worker views cannot start on this page, because ${s}. A host that will not allow ${p} serves each view's whole script from its own origin and passes worker: { url } (the @graview/guest README, "What the host page allows").`)),s}function At(n,e){return n===""?!0:e.startsWith("blob:")?n.startsWith("blob"):e.startsWith(n)||n.startsWith(e)}function ie(n,e){let o="script"in e.source?n.URL.createObjectURL(new n.Blob([e.source.script],{type:"text/javascript"})):void 0,p="script"in e.source?o:e.source.url,s,g,k=!1,G=!1,E=0,A=0,S="",N=0,c=0,T=n.performance,M=T.now(),x,v=i=>{let r=i,f=String(r.effectiveDirective||r.violatedDirective||"").split(" ")[0];/^(worker-src|script-src|script-src-elem|child-src|default-src)$/.test(f)&&At(String(r.blockedURI??""),p)&&(x=f)},_=n.document;_?.addEventListener("securitypolicyviolation",v);let P=()=>_?.removeEventListener("securitypolicyviolation",v),t=()=>{G||(G=!0,g?.close(),s?.terminate(),s=void 0,n.clearTimeout(E),n.clearInterval(A),P(),o&&n.URL.revokeObjectURL(o))},d=(i,r)=>{G||(t(),e.onStop(i,r))},h=()=>{n.clearTimeout(E),P(),S=ze();let i=new n.MessageChannel;g=i.port1;let r=Math.max(1,e.silentMs),f=Math.max(10,Math.min(1e3,Math.floor(r/4)));M=T.now();let w=M;A=n.setInterval(()=>{let b=T.now();if(b-w>f*2&&(M+=b-w-f),w=b,b-M>=r)return d("silent");N+=1,i.port1.postMessage({type:"heartbeat",beat:N})},f);let y={graview:"host-hello",protocol:1,nonce:S,view:e.name};s.postMessage(y,[i.port2]),e.onReady(S,i.port1)};try{s=new n.Worker(p,{name:e.name})}catch(i){s=void 0;let r=i,f=r?.name==="SecurityError"?pt(n,p,x):`the worker could not be made: ${String(r?.message??i)}`;queueMicrotask(()=>d("start",f))}return s&&(E=n.setTimeout(()=>d("start",`it never said it was ready in ${e.readyMs.toLocaleString("en-US")} ms`),e.readyMs),s.onerror=i=>{let r=typeof i.message=="string"&&i.message!==""?i.message:void 0;if(k)return void e.onError?.(r??"an error");n.clearTimeout(E),n.setTimeout(()=>!k&&d("start",x?pt(n,p,x):r?`it failed before it said ready: ${r}`:"it failed before it said ready, and the engine gave no reason (a page policy that refuses it, or a script that does not load)"),0)},s.onmessage=i=>{if(!e.limiter.message()||k||!Fe(i.data)||i.data.protocol!==1){e.onDropped();return}k=!0,h()}),{get worker(){return s},answer(i){let r=i;return typeof r!="object"||r===null||r.type!=="heartbeat"||r.nonce!==S?!1:(typeof r.beat=="number"&&r.beat>c&&r.beat<=N&&(c=r.beat,M=T.now()),!0)},stop:t}}function ae(n,e){let o=e(),p=0;return{draw(s){let g=e();g-o>=1e3&&(o=g,p=0);let k=s(()=>p+(e()-g)>=n);return p+=e()-g,k&&p<n}}}var Ot=$(()=>(__graviewPreload(import.meta.url,["./chunk.GAFYE37S.js","./chunk.AJZBJBMO.js"]),import("./chunk.YWVOACSX.js"))),It=$(()=>(__graviewPreload(import.meta.url,["./chunk.STBJV6HJ.js","./chunk.F5UVEF2R.js","./chunk.FGDHEVH4.js","./chunk.5ZMENPY4.js","./chunk.AJZBJBMO.js"]),import("./chunk.XBOZTQQA.js"))),Nt=$(()=>(__graviewPreload(import.meta.url,["./chunk.AJZBJBMO.js"]),import("./chunk.SHNYYBNW.js"))),Pt=$(()=>(__graviewPreload(import.meta.url,["./chunk.WVUJXDXZ.js","./chunk.KJNUZYXS.js","./chunk.4BBJ62ZO.js","./chunk.UCZR33MK.js","./chunk.CC47O2DW.js","./chunk.2IX3CZNP.js","./chunk.6DHHUBSC.js","./chunk.Z7JRBKA7.js","./chunk.5ZMENPY4.js","./chunk.AJZBJBMO.js"]),import("./chunk.WJQY4E45.js"))),Dt=$(()=>(__graviewPreload(import.meta.url,["./chunk.F5UVEF2R.js","./chunk.FGDHEVH4.js","./chunk.5ZMENPY4.js","./chunk.AJZBJBMO.js"]),import("./chunk.LP2DJ5ZB.js")));function Vt(n,e,o){switch(n){case"manifest":return o??"Its manifest names something this app does not have.";case"source":return o??`Its code is longer than the ${e.maxSourceBytes.toLocaleString("en-US")} bytes a view may be.`;case"start":return`It could not start${o?`: ${o}.`:"."}`;case"error":return`It failed before it drew anything${o?`: ${o}`:"."}`;case"silent":return`It stopped answering for ${e.silentMs.toLocaleString("en-US")} ms.`;case"nodes":return`It drew more than the ${e.maxNodes.toLocaleString("en-US")} things a view may draw.`;case"flood":return`It sent more than ${e.messages} messages in ${e.messageWindowMs.toLocaleString("en-US")} ms.`;case"slow":return`It took longer than ${e.pushMs.toLocaleString("en-US")} ms to draw what it was shown.`}}function Ct(n,e){let o=n.ownerDocument,p=o.defaultView,{manifest:s}=e,g=o.createElement("div");g.className="graview-worker-view",g.setAttribute("role","region"),g.setAttribute("aria-label",s.title??s.name),g.setAttribute("data-worker-view",s.name),g.style.cssText="display:block;position:relative;contain:layout paint style;isolation:isolate;overflow:clip;min-width:0",n.appendChild(g);let k=g.attachShadow({mode:"open"}),G=e.author?o.createElement("p"):void 0;G&&(G.className="graview-worker-view-author",G.setAttribute("data-worker-view-author",s.name),G.style.cssText="margin:4px 0 0;font-size:0.75rem;color:var(--graview-ink-muted, inherit)",G.textContent=e.author,n.appendChild(G));let E={applied:0,refused:0,dropped:0},A=ne(e.limits),S={maxSourceBytes:e.limits?.maxSourceBytes??256e3,maxNodes:e.limits?.maxNodes??5e3,messages:e.limits?.messages??120,messageWindowMs:e.limits?.messageWindowMs??1e3,pushMs:e.limits?.pushMs??1e3,silentMs:e.limits?.silentMs??5e3,drawMs:e.limits?.drawMs??100},N,c,T,M,x=!1,v={applied:0,refused:0,dropped:0},_=[],P=()=>{if(!c)return;let a=c.stats;E.applied+=a.applied-v.applied,E.refused+=a.refused-v.refused,E.dropped+=a.dropped-v.dropped,v={...a}},t=()=>{},d=0,h=()=>{},i=()=>{h(),h=()=>{},P(),c?.dispose(),c=void 0,T?.stop(),t(),p.clearInterval(d)},r=(a,m)=>{if(x)return;x=!0,i(),M?.dispose();let K=Vt(a,S,m);g.removeAttribute("data-worker-view-drawn"),g.setAttribute("data-worker-view-failed",a),e.fallback!==!1&&(e.fallback??f)(g,a,K),e.onFailure?.(a,K)},f=(a,m,K)=>{let O=N??(()=>{try{return ve(e.store,e.principal,{manifest:s,...e.input?{input:e.input()}:{}})}catch{return}})(),l=o.createElement("div");l.setAttribute("data-graview-fallback",m),l.style.cssText="padding:12px;display:grid;gap:6px;color:var(--graview-ink, inherit);font-family:var(--graview-font-body, inherit)";let I=o.createElement("strong");I.textContent=s.title??s.name;let L=o.createElement("ul");L.style.cssText="margin:0;padding-left:1.2em";for(let B of[...O?.node?[O.node]:[],...O?.nodes??[]]){let q=o.createElement("li");q.textContent=B.label??B.id,L.appendChild(q)}let U=o.createElement("p");U.style.cssText="margin:0;font-size:0.8125rem;color:var(--graview-ink-muted, inherit)",U.textContent=`This view was stopped. ${K}`,l.append(I,L,U),k.replaceChildren(l)},w=Ye(s,e.store);if(w.length>0)return queueMicrotask(()=>r("manifest",w.join(" "))),ee();let y=e.worker;if(("source"in y?new TextEncoder().encode(y.source).length:"script"in y?new TextEncoder().encode(y.script).length:0)>S.maxSourceBytes)return queueMicrotask(()=>r("source")),ee();let W="source"in y?Qe(y.source):[];if(W.length>0)return queueMicrotask(()=>r("source",W.join(" "))),ee();let Ke=nt(p,()=>Ge(),"blob"),le=()=>rt(()=>e.theme?.()??et(g),e.brand,Ke),Re="",de=()=>{Re=JSON.stringify(le()),c?.push()},Ge=()=>{c&&JSON.stringify(le())!==Re&&de()},mt=tt(o,Ge),H,j,We=s.pictures?Nt().then(({createGuestPictures:a})=>{x||(H=a(p,{as:"blob",view:`"${s.title??s.name}"`,pictures:s.pictures,...e.limits?{limits:e.limits}:{},...e.file?{file:e.file}:{},moved:()=>c?.push(),onLeft:m=>{V?.postMessage({type:"notice",text:m}),e.onProblem?.(m)}}))}):Promise.resolve();t=()=>{mt(),Ke.dispose(),H?.dispose(),X?.dispose(),j?.dispose()};let V,ue=a=>V?.postMessage(a),_e=!1,Le=!1,J=()=>g.toggleAttribute("data-worker-view-drawn",!x&&Le&&M!==void 0&&_.length===0&&z.size===0&&!H?.waiting()&&!(j?.waiting??0)),F=p.performance,z=new Map,Q=F.now(),ce=Math.max(10,Math.min(250,Math.floor(S.pushMs/4))),gt=()=>{d||(Q=F.now(),d=p.setInterval(()=>{let a=F.now(),m=a-Q>ce*2?a-Q-ce:0;Q=a;for(let[K,O]of z){let l=O+m;if(z.set(K,l),a-l>=S.pushMs)return r("slow")}},ce))},yt=ae(S.drawMs,()=>F.now()),Ae=()=>{},pe=a=>{if(x)return;if(!M)return void _.push(a);let m=M;if(!yt.draw(O=>a[0]==="render"?m.apply(a[1],O):(m.style(a[1]),!0)))return r("slow");a[0]==="render"&&Ae()},Oe=()=>Be(e.store.schema,new Set([...e.store.kindsKeptFrom(e.principal),...e.store.modules.disabledKinds])),Z=$e({sees:a=>e.store.seenBy(e.principal).graph.has(a),places:()=>re(e.places?.()??[]),lists:Oe,schema:e.store.schema,...e.onNavigate?{onNavigate:e.onNavigate}:e.goTo?{onNavigate:a=>Ze(e.goTo(),a)}:{},onLost:a=>{V?.postMessage({type:"notice",text:a}),e.onProblem?.(a)}}),C=new Set,Ie=new Set,X,Ne=!1,Pe=()=>{Ne||(Ne=!0,Pt().then(({createGuestMedia:a})=>{x||(X=a(p,{view:`"${s.title??s.name}"`,pictures:s.pictures!==void 0,shown:()=>N,...e.file?{file:e.file}:{},onProblem:m=>{V?.postMessage({type:"notice",text:m}),e.onProblem?.(m)}}),X.refresh(k))},()=>e.onProblem?.(`The view "${s.title??s.name}" places a video or a full-screen viewer, and the host's player could not be loaded.`)))},De=!1,Ve=!1,fe=new Map,Ce=()=>{De||!s.accepts?.length||(De=!0,Dt().then(({createGuestDrops:a})=>{x||(j=a(p,{shadow:k,manifest:s,store:e.store,principal:e.principal,files:()=>e.files?.(),shown:()=>C,hears:()=>Ve,idOf:m=>M?.renderer.idOf(m),send:ue,change:(m,K)=>{if(!c)return{ok:!1,reason:"refused",message:"The view has gone."};let O=c.change(m,K);return P(),O},handed:m=>fe.set(m.href,m),onProblem:m=>{V?.postMessage({type:"notice",text:m}),e.onProblem?.(m)},onBusy:()=>J()}),j.refresh())},()=>e.onProblem?.(`The view "${s.title??s.name}" takes files, and the host's drop could not be loaded.`)))},ht=a=>{let m=e.store.seenBy(e.principal).graph;for(let K of C){let O=m.getNode(K);for(let l of Object.values(O??{}))for(let I of qe(l))if(I.href===a)return I}},He=a=>{if(a.localName==="graview-video")return Pe();a.hasAttribute("data-lightbox")&&(a.setAttribute("aria-haspopup","dialog"),Pe())};Promise.all([Ot(),It()]).then(([{createOpenDrawing:a},{createPressReader:m,createSaver:K,fillPrefills:O,judgePress:l,prefillOf:I}])=>{if(x)return;let L=m(),U=(u,R)=>{let D=M?.renderer.idOf(u);D!==void 0&&ue({type:"dom-event",target:D,event:"acted",pressed:R})},B=K({reader:L,save:(u,R)=>{if(!c)return;let D=c.pressed(l(e.store,s,C,u));P(),U(R,{as:u.as,...D})}}),q=()=>B.flush();p.addEventListener("pagehide",q),h=()=>{p.removeEventListener("pagehide",q),B.flush()};let vt=new WeakSet;Ae=()=>{O(k,L,vt,u=>I(e.store,e.principal,s,C,u)),X?.refresh(k),j?.refresh()},M=a(k,{origin:e.origin??p.location.origin,...e.asset?{asset:e.asset}:{},...e.images?{imageOrigins:e.images.origins}:{},...s.pictures?{picture:u=>H?.drawn(u)}:{},onRefused:u=>{if(u.reason!=="url"||u.element!=="img"||u.address===void 0||Ie.has(u.address))return;Ie.add(u.address);let R=Xe(u.address,{...e.images?{origins:e.images.origins}:{},assets:e.asset!==void 0},u.length);V?.postMessage({type:"notice",text:R}),e.onProblem?.(R)},...e.limits?.maxNodes!==void 0?{maxNodes:e.limits.maxNodes}:{},onOverBudget:()=>r("nodes"),send:ue,onFieldSet:u=>L.filled(u),onAttribute:(u,R)=>{u.localName==="a"&&(R==="data-record"||R==="data-place")&&Z.link(u),R==="data-lightbox"&&He(u),R==="data-drop"&&Ce()},decorate:u=>{u.localName==="a"&&Z.link(u),He(u),u.hasAttribute("data-drop")&&Ce()},before:(u,R,D)=>{L.heard(u,R),B.heard(u,R,D);let ge=R.closest("a[data-graview-link]");ge&&D.contains(ge)&&(u.type==="click"||u.type==="keydown"&&u.key==="Enter")&&(u.preventDefault(),u.stopPropagation(),Z.follow(ge));let te=R.closest("[data-lightbox]"),je=u.type==="keydown"?u.key:void 0;if(te&&D.contains(te)&&u.isTrusted&&(u.type==="click"||(je==="Enter"||je===" ")&&te.localName!=="button")&&(u.preventDefault(),u.stopPropagation(),X?.open(te)),j?.before(u,R,D))return!1;let ye=L.press(u,R,D);if(!ye||!c)return;u.stopPropagation();let wt=c.pressed(l(e.store,s,C,ye));P();let Ue={as:ye.as,...wt},bt=R.closest("[data-act]");return queueMicrotask(()=>U(bt,Ue)),{pressed:Ue}}});for(let u of _.splice(0))pe(u);J()},()=>r("start","the view's drawing could not be loaded"));let me=a=>T=ie(p,{source:a,name:s.name,limiter:A,readyMs:e.limits?.readyMs??5e3,silentMs:e.limits?.silentMs??5e3,onDropped:()=>E.dropped+=1,onStop:(m,K)=>r(m,K),onError:m=>{_e||r("error",m)},onReady:(m,K)=>{V=K,gt();let O=se({store:e.store,principal:e.principal,view:s.name,nonce:m,send:l=>{l.type==="props"&&typeof l.push=="number"&&(z.set(l.push,F.now()),J()),K.postMessage(l)},props:()=>{let l=ve(e.store,e.principal,{manifest:s,...e.input?{input:e.input()}:{},theme:le(),...e.places?{places:re(e.places())}:{}});return C=new Set([...l.node?[l.node.id]:[],...(l.nodes??[]).map(I=>I.id)]),N=l,l},...H?{hand:H.hand}:{},judgeAct:(l,I)=>Je(e.store,s,l,I,{shown:C,file:L=>fe.get(L)??ht(L),dropped:L=>fe.has(L)}),onHears:l=>{l.includes("drop")&&(Ve=!0)},onRender:l=>{_e=!0,pe(["render",l])},onPushed:(l,I)=>{if(z.delete(l),I>=S.pushMs)return r("slow");Le=!0,J()},onFlood:()=>r("flood"),onStyle:l=>pe(["style",l]),places:()=>[...new Set([...re(e.places?.()??[]).map(l=>l.as),...Oe().map(l=>l.slug)])],...e.limits?{limits:e.limits}:{},limiter:A});c=O,K.onmessage=({data:l})=>{if(!T?.answer(l)&&(O.receive(l),P(),!x&&l?.nonce===m&&l.type==="navigate")){let I={...l.where!==void 0?{where:l.where}:{},...l.section!==void 0?{section:l.section}:{}},L=typeof l.place=="string"?{place:l.place,...I}:typeof l.to=="string"&&{record:l.to,...I};L&&Z.go(L)}},de()}});return"source"in y?(s.pictures?Promise.all([we(y.source),We]).then(([a])=>a):we(y.source)).then(a=>{x||me({script:a})},()=>r("start","the view's runtime could not be loaded")):s.pictures?We.then(()=>{x||me(y)},()=>r("start","the view's pictures could not be loaded")):me(y),ee();function ee(){return{element:g,shadow:k,get worker(){return T?.worker},update:()=>{c&&de()},get stats(){return P(),E},get refused(){return M?.refused??[]},dispose(){x=!0,i(),M?.dispose(),g.remove(),G?.remove()}}}}var ft="graview-guest-kit";function fr(n,e){let o=n.ownerDocument,p=o.defaultView;if(!o.getElementById(ft)){let v=o.createElement("style");v.id=ft,v.textContent=Ee,o.head.appendChild(v)}let s=o.createElement("div");s.className="graview-guest",s.setAttribute("role","group"),s.setAttribute("aria-label",e.title??e.view),s.setAttribute("data-guest-view",e.view),n.appendChild(s);let g={applied:0,refused:0,dropped:0},k=ne(e.limits),G=ae(e.limits?.drawMs??100,()=>p.performance.now()),E,A,S,N=!1,c={applied:0,refused:0,dropped:0},T=()=>{if(!E)return;let v=E.stats;g.applied+=v.applied-c.applied,g.refused+=v.refused-c.refused,g.dropped+=v.dropped-c.dropped,c={...v}},M=()=>{T(),E?.dispose(),E=void 0,S?.stop()},x=(v,_)=>{N||(N=!0,M(),A?.dispose(),e.onFailure?.(v,_))};return S=ie(p,{source:e.worker,name:e.view,limiter:k,readyMs:e.limits?.readyMs??5e3,silentMs:e.limits?.silentMs??5e3,onDropped:()=>g.dropped+=1,onStop:(v,_)=>x(v,_),onReady:(v,_)=>{let P=Me(s,{...e.kit?{kit:e.kit}:{},...e.links?{links:e.links}:{},onEvent:(d,h)=>_.postMessage({type:"event",listener:d,...h!==void 0?{detail:h}:{}}),...e.limits?.maxNodes!==void 0?{maxNodes:e.limits.maxNodes}:{},onOverBudget:()=>x("budget")});A=P;let t=se({store:e.store,principal:e.principal,view:e.view,nonce:v,send:d=>_.postMessage(d),onRender:d=>{G.draw(h=>P.apply(d,h))||x("slow")},...e.input?{input:e.input}:{},...e.onNavigate?{onNavigate:e.onNavigate}:{},onSize:e.onSize??(d=>s.style.minHeight=`${d}px`),...e.limits?{limits:e.limits}:{},limiter:k});E=t,_.onmessage=d=>{S?.answer(d.data)||(t.receive(d.data),T())},t.push()}}),{element:s,get worker(){return S?.worker},update:()=>E?.push(),get stats(){return T(),g},get refused(){return A?.refused??[]},dispose(){N=!0,M(),A?.dispose(),s.remove()}}}export{ke as GUEST_KIT,Ee as GUEST_KIT_CSS,be as KIT_LINK_TARGETS,st as KIT_TONES,Me as createKitRenderer,dt as hostAttribute,ut as kitValue,fr as mountGuestWorker,Ct as mountWorkerView};
21
+ `;var ct=new WeakSet;function Lt(n,e){if(n.startsWith("blob:"))return"blob:";try{return new URL(n,e.location.href).origin}catch{return n}}function pt(n,e,o){let p=Lt(e,n),s=`this page's Content-Security-Policy${o?` (${o})`:""} does not allow a worker from ${p}: it needs worker-src ${p}`;return ct.has(n)||(ct.add(n),n.console?.warn?.(`Graview: worker views cannot start on this page, because ${s}. A host that will not allow ${p} serves each view's whole script from its own origin and passes worker: { url } (the @graview/guest README, "What the host page allows").`)),s}function At(n,e){return n===""?!0:e.startsWith("blob:")?n.startsWith("blob"):e.startsWith(n)||n.startsWith(e)}function ie(n,e){let o="script"in e.source?n.URL.createObjectURL(new n.Blob([e.source.script],{type:"text/javascript"})):void 0,p="script"in e.source?o:e.source.url,s,g,k=!1,G=!1,E=0,A=0,S="",N=0,c=0,T=n.performance,M=T.now(),x,v=i=>{let r=i,f=String(r.effectiveDirective||r.violatedDirective||"").split(" ")[0];/^(worker-src|script-src|script-src-elem|child-src|default-src)$/.test(f)&&At(String(r.blockedURI??""),p)&&(x=f)},_=n.document;_?.addEventListener("securitypolicyviolation",v);let P=()=>_?.removeEventListener("securitypolicyviolation",v),t=()=>{G||(G=!0,g?.close(),s?.terminate(),s=void 0,n.clearTimeout(E),n.clearInterval(A),P(),o&&n.URL.revokeObjectURL(o))},d=(i,r)=>{G||(t(),e.onStop(i,r))},h=()=>{n.clearTimeout(E),P(),S=ze();let i=new n.MessageChannel;g=i.port1;let r=Math.max(1,e.silentMs),f=Math.max(10,Math.min(1e3,Math.floor(r/4)));M=T.now();let w=M;A=n.setInterval(()=>{let b=T.now();if(b-w>f*2&&(M+=b-w-f),w=b,b-M>=r)return d("silent");N+=1,i.port1.postMessage({type:"heartbeat",beat:N})},f);let y={graview:"host-hello",protocol:1,nonce:S,view:e.name};s.postMessage(y,[i.port2]),e.onReady(S,i.port1)};try{s=new n.Worker(p,{name:e.name})}catch(i){s=void 0;let r=i,f=r?.name==="SecurityError"?pt(n,p,x):`the worker could not be made: ${String(r?.message??i)}`;queueMicrotask(()=>d("start",f))}return s&&(E=n.setTimeout(()=>d("start",`it never said it was ready in ${e.readyMs.toLocaleString("en-US")} ms`),e.readyMs),s.onerror=i=>{let r=typeof i.message=="string"&&i.message!==""?i.message:void 0;if(k)return void e.onError?.(r??"an error");n.clearTimeout(E),n.setTimeout(()=>!k&&d("start",x?pt(n,p,x):r?`it failed before it said ready: ${r}`:"it failed before it said ready, and the engine gave no reason (a page policy that refuses it, or a script that does not load)"),0)},s.onmessage=i=>{if(!e.limiter.message()||k||!Fe(i.data)||i.data.protocol!==1){e.onDropped();return}k=!0,h()}),{get worker(){return s},answer(i){let r=i;return typeof r!="object"||r===null||r.type!=="heartbeat"||r.nonce!==S?!1:(typeof r.beat=="number"&&r.beat>c&&r.beat<=N&&(c=r.beat,M=T.now()),!0)},stop:t}}function ae(n,e){let o=e(),p=0;return{draw(s){let g=e();g-o>=1e3&&(o=g,p=0);let k=s(()=>p+(e()-g)>=n);return p+=e()-g,k&&p<n}}}var Ot=$(()=>(__graviewPreload(import.meta.url,["./chunk.GAFYE37S.js","./chunk.AJZBJBMO.js"]),import("./chunk.YWVOACSX.js"))),It=$(()=>(__graviewPreload(import.meta.url,["./chunk.ZRLXVYPG.js","./chunk.S2U5CEP4.js","./chunk.W4HBRXMY.js","./chunk.V5MYKNL7.js","./chunk.AJZBJBMO.js"]),import("./chunk.H5HWN7A2.js"))),Nt=$(()=>(__graviewPreload(import.meta.url,["./chunk.AJZBJBMO.js"]),import("./chunk.SHNYYBNW.js"))),Pt=$(()=>(__graviewPreload(import.meta.url,["./chunk.WVUJXDXZ.js","./chunk.N6MVK3KD.js","./chunk.I7XSDXQ3.js","./chunk.UHI3D7JC.js","./chunk.WVDKYUF3.js","./chunk.ZHLQWMV5.js","./chunk.TNESS3LQ.js","./chunk.2RVUDRRY.js","./chunk.V5MYKNL7.js","./chunk.AJZBJBMO.js"]),import("./chunk.3Q75TIGL.js"))),Dt=$(()=>(__graviewPreload(import.meta.url,["./chunk.S2U5CEP4.js","./chunk.W4HBRXMY.js","./chunk.V5MYKNL7.js","./chunk.AJZBJBMO.js"]),import("./chunk.VIYECFKZ.js")));function Vt(n,e,o){switch(n){case"manifest":return o??"Its manifest names something this app does not have.";case"source":return o??`Its code is longer than the ${e.maxSourceBytes.toLocaleString("en-US")} bytes a view may be.`;case"start":return`It could not start${o?`: ${o}.`:"."}`;case"error":return`It failed before it drew anything${o?`: ${o}`:"."}`;case"silent":return`It stopped answering for ${e.silentMs.toLocaleString("en-US")} ms.`;case"nodes":return`It drew more than the ${e.maxNodes.toLocaleString("en-US")} things a view may draw.`;case"flood":return`It sent more than ${e.messages} messages in ${e.messageWindowMs.toLocaleString("en-US")} ms.`;case"slow":return`It took longer than ${e.pushMs.toLocaleString("en-US")} ms to draw what it was shown.`}}function Ct(n,e){let o=n.ownerDocument,p=o.defaultView,{manifest:s}=e,g=o.createElement("div");g.className="graview-worker-view",g.setAttribute("role","region"),g.setAttribute("aria-label",s.title??s.name),g.setAttribute("data-worker-view",s.name),g.style.cssText="display:block;position:relative;contain:layout paint style;isolation:isolate;overflow:clip;min-width:0",n.appendChild(g);let k=g.attachShadow({mode:"open"}),G=e.author?o.createElement("p"):void 0;G&&(G.className="graview-worker-view-author",G.setAttribute("data-worker-view-author",s.name),G.style.cssText="margin:4px 0 0;font-size:0.75rem;color:var(--graview-ink-muted, inherit)",G.textContent=e.author,n.appendChild(G));let E={applied:0,refused:0,dropped:0},A=ne(e.limits),S={maxSourceBytes:e.limits?.maxSourceBytes??256e3,maxNodes:e.limits?.maxNodes??5e3,messages:e.limits?.messages??120,messageWindowMs:e.limits?.messageWindowMs??1e3,pushMs:e.limits?.pushMs??1e3,silentMs:e.limits?.silentMs??5e3,drawMs:e.limits?.drawMs??100},N,c,T,M,x=!1,v={applied:0,refused:0,dropped:0},_=[],P=()=>{if(!c)return;let a=c.stats;E.applied+=a.applied-v.applied,E.refused+=a.refused-v.refused,E.dropped+=a.dropped-v.dropped,v={...a}},t=()=>{},d=0,h=()=>{},i=()=>{h(),h=()=>{},P(),c?.dispose(),c=void 0,T?.stop(),t(),p.clearInterval(d)},r=(a,m)=>{if(x)return;x=!0,i(),M?.dispose();let K=Vt(a,S,m);g.removeAttribute("data-worker-view-drawn"),g.setAttribute("data-worker-view-failed",a),e.fallback!==!1&&(e.fallback??f)(g,a,K),e.onFailure?.(a,K)},f=(a,m,K)=>{let O=N??(()=>{try{return ve(e.store,e.principal,{manifest:s,...e.input?{input:e.input()}:{}})}catch{return}})(),l=o.createElement("div");l.setAttribute("data-graview-fallback",m),l.style.cssText="padding:12px;display:grid;gap:6px;color:var(--graview-ink, inherit);font-family:var(--graview-font-body, inherit)";let I=o.createElement("strong");I.textContent=s.title??s.name;let L=o.createElement("ul");L.style.cssText="margin:0;padding-left:1.2em";for(let B of[...O?.node?[O.node]:[],...O?.nodes??[]]){let q=o.createElement("li");q.textContent=B.label??B.id,L.appendChild(q)}let U=o.createElement("p");U.style.cssText="margin:0;font-size:0.8125rem;color:var(--graview-ink-muted, inherit)",U.textContent=`This view was stopped. ${K}`,l.append(I,L,U),k.replaceChildren(l)},w=Ye(s,e.store);if(w.length>0)return queueMicrotask(()=>r("manifest",w.join(" "))),ee();let y=e.worker;if(("source"in y?new TextEncoder().encode(y.source).length:"script"in y?new TextEncoder().encode(y.script).length:0)>S.maxSourceBytes)return queueMicrotask(()=>r("source")),ee();let W="source"in y?Qe(y.source):[];if(W.length>0)return queueMicrotask(()=>r("source",W.join(" "))),ee();let Ke=nt(p,()=>Ge(),"blob"),le=()=>rt(()=>e.theme?.()??et(g),e.brand,Ke),Re="",de=()=>{Re=JSON.stringify(le()),c?.push()},Ge=()=>{c&&JSON.stringify(le())!==Re&&de()},mt=tt(o,Ge),H,j,We=s.pictures?Nt().then(({createGuestPictures:a})=>{x||(H=a(p,{as:"blob",view:`"${s.title??s.name}"`,pictures:s.pictures,...e.limits?{limits:e.limits}:{},...e.file?{file:e.file}:{},moved:()=>c?.push(),onLeft:m=>{V?.postMessage({type:"notice",text:m}),e.onProblem?.(m)}}))}):Promise.resolve();t=()=>{mt(),Ke.dispose(),H?.dispose(),X?.dispose(),j?.dispose()};let V,ue=a=>V?.postMessage(a),_e=!1,Le=!1,J=()=>g.toggleAttribute("data-worker-view-drawn",!x&&Le&&M!==void 0&&_.length===0&&z.size===0&&!H?.waiting()&&!(j?.waiting??0)),F=p.performance,z=new Map,Q=F.now(),ce=Math.max(10,Math.min(250,Math.floor(S.pushMs/4))),gt=()=>{d||(Q=F.now(),d=p.setInterval(()=>{let a=F.now(),m=a-Q>ce*2?a-Q-ce:0;Q=a;for(let[K,O]of z){let l=O+m;if(z.set(K,l),a-l>=S.pushMs)return r("slow")}},ce))},yt=ae(S.drawMs,()=>F.now()),Ae=()=>{},pe=a=>{if(x)return;if(!M)return void _.push(a);let m=M;if(!yt.draw(O=>a[0]==="render"?m.apply(a[1],O):(m.style(a[1]),!0)))return r("slow");a[0]==="render"&&Ae()},Oe=()=>Be(e.store.schema,new Set([...e.store.kindsKeptFrom(e.principal),...e.store.modules.disabledKinds])),Z=$e({sees:a=>e.store.seenBy(e.principal).graph.has(a),places:()=>re(e.places?.()??[]),lists:Oe,schema:e.store.schema,...e.onNavigate?{onNavigate:e.onNavigate}:e.goTo?{onNavigate:a=>Ze(e.goTo(),a)}:{},onLost:a=>{V?.postMessage({type:"notice",text:a}),e.onProblem?.(a)}}),C=new Set,Ie=new Set,X,Ne=!1,Pe=()=>{Ne||(Ne=!0,Pt().then(({createGuestMedia:a})=>{x||(X=a(p,{view:`"${s.title??s.name}"`,pictures:s.pictures!==void 0,shown:()=>N,...e.file?{file:e.file}:{},onProblem:m=>{V?.postMessage({type:"notice",text:m}),e.onProblem?.(m)}}),X.refresh(k))},()=>e.onProblem?.(`The view "${s.title??s.name}" places a video or a full-screen viewer, and the host's player could not be loaded.`)))},De=!1,Ve=!1,fe=new Map,Ce=()=>{De||!s.accepts?.length||(De=!0,Dt().then(({createGuestDrops:a})=>{x||(j=a(p,{shadow:k,manifest:s,store:e.store,principal:e.principal,files:()=>e.files?.(),shown:()=>C,hears:()=>Ve,idOf:m=>M?.renderer.idOf(m),send:ue,change:(m,K)=>{if(!c)return{ok:!1,reason:"refused",message:"The view has gone."};let O=c.change(m,K);return P(),O},handed:m=>fe.set(m.href,m),onProblem:m=>{V?.postMessage({type:"notice",text:m}),e.onProblem?.(m)},onBusy:()=>J()}),j.refresh())},()=>e.onProblem?.(`The view "${s.title??s.name}" takes files, and the host's drop could not be loaded.`)))},ht=a=>{let m=e.store.seenBy(e.principal).graph;for(let K of C){let O=m.getNode(K);for(let l of Object.values(O??{}))for(let I of qe(l))if(I.href===a)return I}},He=a=>{if(a.localName==="graview-video")return Pe();a.hasAttribute("data-lightbox")&&(a.setAttribute("aria-haspopup","dialog"),Pe())};Promise.all([Ot(),It()]).then(([{createOpenDrawing:a},{createPressReader:m,createSaver:K,fillPrefills:O,judgePress:l,prefillOf:I}])=>{if(x)return;let L=m(),U=(u,R)=>{let D=M?.renderer.idOf(u);D!==void 0&&ue({type:"dom-event",target:D,event:"acted",pressed:R})},B=K({reader:L,save:(u,R)=>{if(!c)return;let D=c.pressed(l(e.store,s,C,u));P(),U(R,{as:u.as,...D})}}),q=()=>B.flush();p.addEventListener("pagehide",q),h=()=>{p.removeEventListener("pagehide",q),B.flush()};let vt=new WeakSet;Ae=()=>{O(k,L,vt,u=>I(e.store,e.principal,s,C,u)),X?.refresh(k),j?.refresh()},M=a(k,{origin:e.origin??p.location.origin,...e.asset?{asset:e.asset}:{},...e.images?{imageOrigins:e.images.origins}:{},...s.pictures?{picture:u=>H?.drawn(u)}:{},onRefused:u=>{if(u.reason!=="url"||u.element!=="img"||u.address===void 0||Ie.has(u.address))return;Ie.add(u.address);let R=Xe(u.address,{...e.images?{origins:e.images.origins}:{},assets:e.asset!==void 0},u.length);V?.postMessage({type:"notice",text:R}),e.onProblem?.(R)},...e.limits?.maxNodes!==void 0?{maxNodes:e.limits.maxNodes}:{},onOverBudget:()=>r("nodes"),send:ue,onFieldSet:u=>L.filled(u),onAttribute:(u,R)=>{u.localName==="a"&&(R==="data-record"||R==="data-place")&&Z.link(u),R==="data-lightbox"&&He(u),R==="data-drop"&&Ce()},decorate:u=>{u.localName==="a"&&Z.link(u),He(u),u.hasAttribute("data-drop")&&Ce()},before:(u,R,D)=>{L.heard(u,R),B.heard(u,R,D);let ge=R.closest("a[data-graview-link]");ge&&D.contains(ge)&&(u.type==="click"||u.type==="keydown"&&u.key==="Enter")&&(u.preventDefault(),u.stopPropagation(),Z.follow(ge));let te=R.closest("[data-lightbox]"),je=u.type==="keydown"?u.key:void 0;if(te&&D.contains(te)&&u.isTrusted&&(u.type==="click"||(je==="Enter"||je===" ")&&te.localName!=="button")&&(u.preventDefault(),u.stopPropagation(),X?.open(te)),j?.before(u,R,D))return!1;let ye=L.press(u,R,D);if(!ye||!c)return;u.stopPropagation();let wt=c.pressed(l(e.store,s,C,ye));P();let Ue={as:ye.as,...wt},bt=R.closest("[data-act]");return queueMicrotask(()=>U(bt,Ue)),{pressed:Ue}}});for(let u of _.splice(0))pe(u);J()},()=>r("start","the view's drawing could not be loaded"));let me=a=>T=ie(p,{source:a,name:s.name,limiter:A,readyMs:e.limits?.readyMs??5e3,silentMs:e.limits?.silentMs??5e3,onDropped:()=>E.dropped+=1,onStop:(m,K)=>r(m,K),onError:m=>{_e||r("error",m)},onReady:(m,K)=>{V=K,gt();let O=se({store:e.store,principal:e.principal,view:s.name,nonce:m,send:l=>{l.type==="props"&&typeof l.push=="number"&&(z.set(l.push,F.now()),J()),K.postMessage(l)},props:()=>{let l=ve(e.store,e.principal,{manifest:s,...e.input?{input:e.input()}:{},theme:le(),...e.places?{places:re(e.places())}:{}});return C=new Set([...l.node?[l.node.id]:[],...(l.nodes??[]).map(I=>I.id)]),N=l,l},...H?{hand:H.hand}:{},judgeAct:(l,I)=>Je(e.store,s,l,I,{shown:C,file:L=>fe.get(L)??ht(L),dropped:L=>fe.has(L)}),onHears:l=>{l.includes("drop")&&(Ve=!0)},onRender:l=>{_e=!0,pe(["render",l])},onPushed:(l,I)=>{if(z.delete(l),I>=S.pushMs)return r("slow");Le=!0,J()},onFlood:()=>r("flood"),onStyle:l=>pe(["style",l]),places:()=>[...new Set([...re(e.places?.()??[]).map(l=>l.as),...Oe().map(l=>l.slug)])],...e.limits?{limits:e.limits}:{},limiter:A});c=O,K.onmessage=({data:l})=>{if(!T?.answer(l)&&(O.receive(l),P(),!x&&l?.nonce===m&&l.type==="navigate")){let I={...l.where!==void 0?{where:l.where}:{},...l.section!==void 0?{section:l.section}:{}},L=typeof l.place=="string"?{place:l.place,...I}:typeof l.to=="string"&&{record:l.to,...I};L&&Z.go(L)}},de()}});return"source"in y?(s.pictures?Promise.all([we(y.source),We]).then(([a])=>a):we(y.source)).then(a=>{x||me({script:a})},()=>r("start","the view's runtime could not be loaded")):s.pictures?We.then(()=>{x||me(y)},()=>r("start","the view's pictures could not be loaded")):me(y),ee();function ee(){return{element:g,shadow:k,get worker(){return T?.worker},update:()=>{c&&de()},get stats(){return P(),E},get refused(){return M?.refused??[]},dispose(){x=!0,i(),M?.dispose(),g.remove(),G?.remove()}}}}var ft="graview-guest-kit";function fr(n,e){let o=n.ownerDocument,p=o.defaultView;if(!o.getElementById(ft)){let v=o.createElement("style");v.id=ft,v.textContent=Ee,o.head.appendChild(v)}let s=o.createElement("div");s.className="graview-guest",s.setAttribute("role","group"),s.setAttribute("aria-label",e.title??e.view),s.setAttribute("data-guest-view",e.view),n.appendChild(s);let g={applied:0,refused:0,dropped:0},k=ne(e.limits),G=ae(e.limits?.drawMs??100,()=>p.performance.now()),E,A,S,N=!1,c={applied:0,refused:0,dropped:0},T=()=>{if(!E)return;let v=E.stats;g.applied+=v.applied-c.applied,g.refused+=v.refused-c.refused,g.dropped+=v.dropped-c.dropped,c={...v}},M=()=>{T(),E?.dispose(),E=void 0,S?.stop()},x=(v,_)=>{N||(N=!0,M(),A?.dispose(),e.onFailure?.(v,_))};return S=ie(p,{source:e.worker,name:e.view,limiter:k,readyMs:e.limits?.readyMs??5e3,silentMs:e.limits?.silentMs??5e3,onDropped:()=>g.dropped+=1,onStop:(v,_)=>x(v,_),onReady:(v,_)=>{let P=Me(s,{...e.kit?{kit:e.kit}:{},...e.links?{links:e.links}:{},onEvent:(d,h)=>_.postMessage({type:"event",listener:d,...h!==void 0?{detail:h}:{}}),...e.limits?.maxNodes!==void 0?{maxNodes:e.limits.maxNodes}:{},onOverBudget:()=>x("budget")});A=P;let t=se({store:e.store,principal:e.principal,view:e.view,nonce:v,send:d=>_.postMessage(d),onRender:d=>{G.draw(h=>P.apply(d,h))||x("slow")},...e.input?{input:e.input}:{},...e.onNavigate?{onNavigate:e.onNavigate}:{},onSize:e.onSize??(d=>s.style.minHeight=`${d}px`),...e.limits?{limits:e.limits}:{},limiter:k});E=t,_.onmessage=d=>{S?.answer(d.data)||(t.receive(d.data),T())},t.push()}}),{element:s,get worker(){return S?.worker},update:()=>E?.push(),get stats(){return T(),g},get refused(){return A?.refused??[]},dispose(){N=!0,M(),A?.dispose(),s.remove()}}}export{ke as GUEST_KIT,Ee as GUEST_KIT_CSS,be as KIT_LINK_TARGETS,st as KIT_TONES,Me as createKitRenderer,dt as hostAttribute,ut as kitValue,fr as mountGuestWorker,Ct as mountWorkerView};