graview 0.1.48 → 0.1.49

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 (171) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +6 -6
  3. package/dist/index.js.map +1 -1
  4. package/dist/preview/{chunk.TKMQROXF.js → chunk.2CO2EJQA.js} +1 -1
  5. package/dist/preview/{chunk.D5ETRTAF.js → chunk.2N6RQ427.js} +1 -1
  6. package/dist/preview/{chunk.FOP5RBGF.js → chunk.2OLZ6BYI.js} +1 -1
  7. package/dist/preview/{chunk.X7N3JUO4.js → chunk.2OXXGN7C.js} +2 -2
  8. package/dist/preview/{chunk.QII2C5OV.js → chunk.2QKSWK4U.js} +1 -1
  9. package/dist/preview/chunk.35FUGOSG.js +1 -0
  10. package/dist/preview/{chunk.X7JMJSLU.js → chunk.3EW6L5DY.js} +1 -1
  11. package/dist/preview/chunk.3NEALGMI.js +1 -0
  12. package/dist/preview/{chunk.2UIUMG23.js → chunk.423SZS7C.js} +3 -3
  13. package/dist/preview/{chunk.HKA5T7DL.js → chunk.4D26JY5U.js} +1 -1
  14. package/dist/preview/{chunk.5A4AOFOA.js → chunk.4HUB3N7I.js} +1 -1
  15. package/dist/preview/chunk.4K7I7WYF.js +1 -0
  16. package/dist/preview/{chunk.OZGETOTK.js → chunk.4OTESF7W.js} +1 -1
  17. package/dist/preview/{chunk.NWT5FPEK.js → chunk.4Q5KWYVY.js} +18 -18
  18. package/dist/preview/{chunk.LNON6P7K.js → chunk.4QINLTDZ.js} +1 -1
  19. package/dist/preview/{chunk.UJRBOUGC.js → chunk.4SEY7VWZ.js} +1 -1
  20. package/dist/preview/{chunk.37CJSWLL.js → chunk.4XKACWLT.js} +1 -1
  21. package/dist/preview/chunk.52QB4YW2.js +1 -0
  22. package/dist/preview/{chunk.HG4DDNPG.js → chunk.54PZWX23.js} +1 -1
  23. package/dist/preview/{chunk.FPYL6REZ.js → chunk.5YFO6D7J.js} +1 -1
  24. package/dist/preview/chunk.6EGHJCEM.js +1 -0
  25. package/dist/preview/{chunk.XTMOFRHL.js → chunk.6EHE26ZS.js} +1 -1
  26. package/dist/preview/{chunk.3BAHAK6W.js → chunk.6RLFO5GA.js} +1 -1
  27. package/dist/preview/chunk.6WRA3Y7D.js +1 -0
  28. package/dist/preview/{chunk.BDHKWVNX.js → chunk.7C4IR4S7.js} +1 -1
  29. package/dist/preview/{chunk.MZLWLIKR.js → chunk.7JLYEZW4.js} +1 -1
  30. package/dist/preview/{chunk.GACKGEUY.js → chunk.7JW5SHRR.js} +1 -1
  31. package/dist/preview/{chunk.I7QIHN66.js → chunk.7MJGZHTS.js} +1 -1
  32. package/dist/preview/{chunk.KW65F4WA.js → chunk.7MWLDDFL.js} +1 -1
  33. package/dist/preview/{chunk.IRHSTUZM.js → chunk.7SGQ3HFG.js} +1 -1
  34. package/dist/preview/{chunk.N4M54YK6.js → chunk.A7HMVWMG.js} +1 -1
  35. package/dist/preview/{chunk.UGJSMNVO.js → chunk.AGVFW6WC.js} +1 -1
  36. package/dist/preview/{chunk.NQZ73QV7.js → chunk.AOEXSQDG.js} +1 -1
  37. package/dist/preview/{chunk.GUMJEVVP.js → chunk.AP22NNIM.js} +1 -1
  38. package/dist/preview/{chunk.PPRSGM64.js → chunk.AVDXG57A.js} +1 -1
  39. package/dist/preview/{chunk.EMQ5POGB.js → chunk.B2BLZDBD.js} +1 -1
  40. package/dist/preview/chunk.B445DZOY.js +1 -0
  41. package/dist/preview/{chunk.GNBN3BK7.js → chunk.BH365UJ5.js} +1 -1
  42. package/dist/preview/{chunk.PMJUGHW4.js → chunk.BJR6E2CT.js} +1 -1
  43. package/dist/preview/{chunk.GT3F6FQ6.js → chunk.BNU3KXKL.js} +1 -1
  44. package/dist/preview/{chunk.GH2SWMCW.js → chunk.BTORFVKO.js} +1 -1
  45. package/dist/preview/{chunk.76W2FXEC.js → chunk.BU6V76EF.js} +1 -1
  46. package/dist/preview/{chunk.QQTRAY5W.js → chunk.BVXOLZQ3.js} +1 -1
  47. package/dist/preview/{chunk.VQAQQW4Q.js → chunk.C75I24Z5.js} +1 -1
  48. package/dist/preview/{chunk.J6ANRF6E.js → chunk.CXIIRL67.js} +1 -1
  49. package/dist/preview/{chunk.SKJJBLXF.js → chunk.D25QV6DK.js} +1 -1
  50. package/dist/preview/{chunk.TMDI7KRS.js → chunk.D4IKO5YA.js} +3 -3
  51. package/dist/preview/{chunk.MAFFUPCR.js → chunk.D4K23FUB.js} +1 -1
  52. package/dist/preview/{chunk.ZH4NWRWB.js → chunk.D53IGR45.js} +1 -1
  53. package/dist/preview/chunk.D66RI4QS.js +1 -0
  54. package/dist/preview/{chunk.KVEDIBXS.js → chunk.DFGXNFFE.js} +1 -1
  55. package/dist/preview/{chunk.QPICKSSM.js → chunk.DSNHE4MZ.js} +1 -1
  56. package/dist/preview/{chunk.NFDLCUCC.js → chunk.DTRNDSMS.js} +1 -1
  57. package/dist/preview/{chunk.4KX53HCV.js → chunk.DV4GSLGX.js} +2 -2
  58. package/dist/preview/{chunk.DPHTUTOS.js → chunk.EJAVIZ7Y.js} +1 -1
  59. package/dist/preview/{chunk.YDL5BSTG.js → chunk.EM5CGFNB.js} +1 -1
  60. package/dist/preview/chunk.EPTUOPPC.js +1 -0
  61. package/dist/preview/{chunk.44G5A53D.js → chunk.ERWBI2NK.js} +1 -1
  62. package/dist/preview/chunk.EYSQPXVE.js +2 -0
  63. package/dist/preview/{chunk.DAUC2DFY.js → chunk.FIS27KW4.js} +1 -1
  64. package/dist/preview/chunk.FNK2ZZ5E.js +1 -0
  65. package/dist/preview/{chunk.RQBEQYB2.js → chunk.FOYVTN5B.js} +1 -1
  66. package/dist/preview/{chunk.I5TOMBIF.js → chunk.FUMQLGNM.js} +1 -1
  67. package/dist/preview/chunk.G25JEYCC.js +1 -0
  68. package/dist/preview/{chunk.2VTMTW7K.js → chunk.G3Q5CYEM.js} +1 -1
  69. package/dist/preview/{chunk.7LL7OSBY.js → chunk.GEY4MA4D.js} +2 -2
  70. package/dist/preview/{chunk.KVJFY7N5.js → chunk.GRLPNTUW.js} +1 -1
  71. package/dist/preview/{chunk.6TKILWRM.js → chunk.H42WBU5C.js} +1 -1
  72. package/dist/preview/{chunk.TBRJOKIK.js → chunk.IQHVVQEA.js} +1 -1
  73. package/dist/preview/{chunk.DWPU56S5.js → chunk.IVHPJUFM.js} +1 -1
  74. package/dist/preview/{chunk.QO7MDWID.js → chunk.IWEPDTVG.js} +1 -1
  75. package/dist/preview/{chunk.PVEPU6EA.js → chunk.IYLOA3MV.js} +1 -1
  76. package/dist/preview/chunk.JBG5UQLM.js +1 -0
  77. package/dist/preview/{chunk.DOBQ4LO4.js → chunk.KDTNKKOY.js} +1 -1
  78. package/dist/preview/chunk.KJBXNMIU.js +21 -0
  79. package/dist/preview/chunk.KLAEKRCA.js +1 -0
  80. package/dist/preview/{chunk.Z4UM4CMT.js → chunk.KQSD5MLY.js} +1 -1
  81. package/dist/preview/{chunk.ETR6AV47.js → chunk.KVEDMKUN.js} +1 -1
  82. package/dist/preview/{chunk.5Y3Q7ONN.js → chunk.LD6S2FL5.js} +1 -1
  83. package/dist/preview/{chunk.DFK2NA6L.js → chunk.LUL6PFIQ.js} +1 -1
  84. package/dist/preview/chunk.MCFLCC42.js +12 -0
  85. package/dist/preview/{chunk.2GLJH253.js → chunk.MJ4XTNTL.js} +1 -1
  86. package/dist/preview/{chunk.CJ23XTSW.js → chunk.MU5WUTVF.js} +1 -1
  87. package/dist/preview/{chunk.P6FQAILU.js → chunk.MUHFZXPS.js} +1 -1
  88. package/dist/preview/{chunk.NLBIX7LH.js → chunk.N2S3TMBC.js} +1 -1
  89. package/dist/preview/{chunk.DUWYF7BO.js → chunk.N2S45SSL.js} +1 -1
  90. package/dist/preview/{chunk.PCEYZQAW.js → chunk.NBJ4C33P.js} +1 -1
  91. package/dist/preview/{chunk.E5GM2SMO.js → chunk.NQ7SRWXA.js} +1 -1
  92. package/dist/preview/chunk.NQDGUIUQ.js +1 -0
  93. package/dist/preview/{chunk.QQCDCRR2.js → chunk.NUUT37ER.js} +1 -1
  94. package/dist/preview/{chunk.LXCJVZF3.js → chunk.O3ONLQUF.js} +1 -1
  95. package/dist/preview/{chunk.QGE6YKSU.js → chunk.OFBESPHJ.js} +1 -1
  96. package/dist/preview/chunk.OKHEZJBX.js +1 -0
  97. package/dist/preview/{chunk.LPD74WBI.js → chunk.OL5D7YTW.js} +1 -1
  98. package/dist/preview/{chunk.ENPCLMP2.js → chunk.ON35FJ5H.js} +1 -1
  99. package/dist/preview/{chunk.GVNYPFIM.js → chunk.OS75HEZP.js} +1 -1
  100. package/dist/preview/{chunk.6VAFNCR4.js → chunk.OTF3NNTI.js} +1 -1
  101. package/dist/preview/{chunk.OVO6L5IP.js → chunk.P2AC6JRL.js} +1 -1
  102. package/dist/preview/chunk.PBCT33FF.js +1 -0
  103. package/dist/preview/{chunk.PTXLOFQW.js → chunk.PCVU3LY3.js} +1 -1
  104. package/dist/preview/chunk.PFEKS3KO.js +5 -0
  105. package/dist/preview/chunk.PFR3FQBR.js +1 -0
  106. package/dist/preview/{chunk.NTLHEHOM.js → chunk.Q4KNNJFL.js} +1 -1
  107. package/dist/preview/{chunk.PQVUQVRL.js → chunk.QBHVBL42.js} +1 -1
  108. package/dist/preview/{chunk.G7WDMUDV.js → chunk.QPNFWP4Z.js} +1 -1
  109. package/dist/preview/{chunk.OFRGDJYX.js → chunk.QQE7N7LB.js} +1 -1
  110. package/dist/preview/{chunk.MVRG75ZD.js → chunk.QQRLUBWQ.js} +1 -1
  111. package/dist/preview/{chunk.2QNGGF55.js → chunk.QWX2N2VD.js} +2 -2
  112. package/dist/preview/chunk.R5IRHCLZ.js +1 -0
  113. package/dist/preview/{chunk.YVOABA2U.js → chunk.REANMQ6K.js} +1 -1
  114. package/dist/preview/{chunk.MVSV7T6E.js → chunk.RI624PFK.js} +1 -1
  115. package/dist/preview/{chunk.W72TTRLX.js → chunk.RMWLV3PR.js} +6 -6
  116. package/dist/preview/{chunk.DHAK6PPX.js → chunk.RSR2M7ZO.js} +2 -2
  117. package/dist/preview/{chunk.EXEZBZGW.js → chunk.SGJSJGSR.js} +1 -1
  118. package/dist/preview/{chunk.NR5ODXMO.js → chunk.SIVMZNHZ.js} +1 -1
  119. package/dist/preview/{chunk.4VW6THJF.js → chunk.SPZVEQC5.js} +1 -1
  120. package/dist/preview/chunk.SR2345SW.js +1 -0
  121. package/dist/preview/chunk.ST4JHXPS.js +1 -0
  122. package/dist/preview/{chunk.KTFUVR4V.js → chunk.TABIRLQS.js} +1 -1
  123. package/dist/preview/{chunk.SFAAM4KE.js → chunk.TBA4GF34.js} +1 -1
  124. package/dist/preview/{chunk.HDE2MGGU.js → chunk.THENABJU.js} +1 -1
  125. package/dist/preview/{chunk.KA44WNB4.js → chunk.TM6JVVGW.js} +1 -1
  126. package/dist/preview/{chunk.CH5ROV7N.js → chunk.TSHBXCMU.js} +1 -1
  127. package/dist/preview/{chunk.J2V76Z6G.js → chunk.UL43GFVC.js} +1 -1
  128. package/dist/preview/{chunk.5IPH2SCE.js → chunk.UTRIPGW6.js} +1 -1
  129. package/dist/preview/{chunk.Y4MQGEUS.js → chunk.VSWEKNKS.js} +2 -2
  130. package/dist/preview/chunk.VV3PNZPI.js +1 -0
  131. package/dist/preview/chunk.W6CGAPNQ.js +1 -0
  132. package/dist/preview/{chunk.V2GSBYDK.js → chunk.WQN7EFW3.js} +2 -2
  133. package/dist/preview/{chunk.ODRL5OWR.js → chunk.X4MTZKL3.js} +1 -1
  134. package/dist/preview/{chunk.3UD7GG5B.js → chunk.XJ7YGW6Y.js} +1 -1
  135. package/dist/preview/{chunk.5IM645XQ.js → chunk.XMOIMPUC.js} +1 -1
  136. package/dist/preview/{chunk.7VT3TRHR.js → chunk.XN7PIWVC.js} +1 -1
  137. package/dist/preview/{chunk.3RP3N2JP.js → chunk.XXZFWZ4C.js} +1 -1
  138. package/dist/preview/{chunk.V4BCB7N2.js → chunk.YECMUK4X.js} +1 -1
  139. package/dist/preview/{chunk.SA34Y3X5.js → chunk.YSFNPYCD.js} +1 -1
  140. package/dist/preview/{chunk.RLXKDXPB.js → chunk.YXOJKGRC.js} +1 -1
  141. package/dist/preview/{chunk.EZJNUFNQ.js → chunk.ZBL47SFK.js} +1 -1
  142. package/dist/preview/{chunk.HC5N3CT2.js → chunk.ZILULTJJ.js} +1 -1
  143. package/dist/preview/index.html +49 -49
  144. package/dist/preview/page.js +2 -2
  145. package/package.json +6 -6
  146. package/dist/preview/chunk.4GQA3AJU.js +0 -1
  147. package/dist/preview/chunk.4TJOS4C7.js +0 -5
  148. package/dist/preview/chunk.664PBQAQ.js +0 -1
  149. package/dist/preview/chunk.72OZLWJL.js +0 -1
  150. package/dist/preview/chunk.72W6S746.js +0 -1
  151. package/dist/preview/chunk.7FRPNQU4.js +0 -1
  152. package/dist/preview/chunk.7QZYFLBS.js +0 -1
  153. package/dist/preview/chunk.B2IIEVBF.js +0 -21
  154. package/dist/preview/chunk.DQ7M3LFV.js +0 -1
  155. package/dist/preview/chunk.FQYOTK34.js +0 -1
  156. package/dist/preview/chunk.GTPC6JOW.js +0 -2
  157. package/dist/preview/chunk.ILZYRJDS.js +0 -1
  158. package/dist/preview/chunk.LGSFGNWE.js +0 -1
  159. package/dist/preview/chunk.MTXEURFE.js +0 -1
  160. package/dist/preview/chunk.NX7IIZLO.js +0 -1
  161. package/dist/preview/chunk.O45VO36H.js +0 -1
  162. package/dist/preview/chunk.OAIWGWGU.js +0 -3
  163. package/dist/preview/chunk.SAHNXAV3.js +0 -1
  164. package/dist/preview/chunk.SUPWMV2F.js +0 -1
  165. package/dist/preview/chunk.TPG6IY4M.js +0 -1
  166. package/dist/preview/chunk.V3N34DSU.js +0 -1
  167. package/dist/preview/chunk.X5G7FOPY.js +0 -12
  168. package/dist/preview/chunk.YEVA72L2.js +0 -1
  169. package/dist/preview/chunk.YLWON7X3.js +0 -1
  170. package/dist/preview/chunk.YUH43J2K.js +0 -1
  171. package/dist/preview/chunk.ZXZNAG35.js +0 -1
@@ -1,2 +1,2 @@
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 Mt,b as Gn,c as Un,d as Kn,e as Jn,f as Vt,g as Yn,h as Dt}from"./chunk.J6ANRF6E.js";import{a as zr}from"./chunk.V4BCB7N2.js";import{a as Ht,b as Zn,c as Xn,d as er,e as Bt,f as tr,g as nr,h as rr,i as or,j as ar,k as ir,l as sr,m as dr,n as _e}from"./chunk.QO7MDWID.js";import{b as Qn}from"./chunk.FOP5RBGF.js";import{a as kt}from"./chunk.Q5WEOX3Q.js";import{a as Et,g as bn}from"./chunk.HG4DDNPG.js";import{k as tt}from"./chunk.KTFUVR4V.js";import{C as _n,H as jn,L as qn,M as zn,j as qr,k as Wn,n as ot,o as Nn,q as $n,u as In,z as at}from"./chunk.2UIUMG23.js";import{Aa as Vn,Ca as Dn,Da as Lt,G as Ct,Ha as Hn,Ia as Bn,La as rt,R as kn,W as En,a as Sn,b as Ft,c as nt,da as An,ea as Rn,j as Pn,m as Ot,sa as Tn,ta as xn,ua as Fn,va as On,wa as Cn,xa as Ln,za as Mn}from"./chunk.KA44WNB4.js";import{a as be}from"./chunk.SDO3U72B.js";import{Ad as xt,Pc as mn,Rc as hn,Sc as yn,Uc as et,Vb as At,Wb as fn,jb as Ie,kb as Xe,od as ve,pd as gn,qd as wn,vd as Rt,wb as un,wd as Tt,zc as pn,zd as vn}from"./chunk.4TJOS4C7.js";import"./chunk.2AZTW66C.js";import{b as Fe}from"./chunk.AJZBJBMO.js";async function it(e,n={}){let o=e.compiled===void 0||!Ur(e.compiled,e.document)?void 0:bn(e.compiled,n);if(o?.ok)return o;let{compileDocumentWithoutCheck:a}=await Gr();return a(e.document,n)}var cr,Gr=()=>cr??=(__graviewPreload(import.meta.url,["./chunk.4GQA3AJU.js","./chunk.HG4DDNPG.js","./chunk.X7JMJSLU.js","./chunk.5Y3Q7ONN.js","./chunk.KTFUVR4V.js","./chunk.4TJOS4C7.js","./chunk.2AZTW66C.js","./chunk.AJZBJBMO.js"]),import("./chunk.7QZYFLBS.js")).catch(e=>{throw cr=void 0,e});function Ur(e,n){let o=typeof e=="object"&&e!==null?e.document:void 0,a=n;if(typeof a=="string")try{a=JSON.parse(a)}catch{return!1}return o!==void 0&&kt(Et(o).document)===kt(Et(a).document)}var c=Fe(Ct(),1);var dt=Fe(Ct(),1),Wt="data-graview-drawn",Kr=200,lr=50,Jr=1e4,st=()=>typeof performance<"u"?performance.now():Date.now();function Yr(e){let n=[...e.querySelectorAll("img")];for(let o of e.querySelectorAll("[data-worker-view]"))o.shadowRoot&&n.push(...o.shadowRoot.querySelectorAll("img"));return n}function Qr(e,n){if(e.ownerDocument.fonts?.status==="loading"||xn()>0||Ln(n)>0||e.querySelector('[aria-busy="true"]')||Yr(e).some(a=>!a.complete&&a.loading!=="lazy"))return!1;for(let a of e.querySelectorAll("[data-worker-view-place]"))if(!a.querySelector("[data-worker-view][data-worker-view-drawn], [data-worker-view][data-worker-view-failed]"))return!1;return!0}function ur(e){let n=e.querySelector("[data-embed-content]"),o=[...e.querySelectorAll("[data-worker-view]")].map(a=>`${a.offsetWidth}x${a.offsetHeight}`);return`${e.scrollWidth}x${e.scrollHeight}|${n?`${n.scrollWidth}x${n.scrollHeight}`:""}|${o.join(",")}`}function Zr(e,n,o,a){e.removeAttribute(Wt);let d=e.ownerDocument.defaultView;if(!d)return()=>{};let l=st(),b=l,p=ur(e),g=!1,A,T=typeof MutationObserver>"u"?void 0:new MutationObserver(S=>{S.some(N=>!(N.target===e&&N.attributeName===Wt))&&(b=st())});T?.observe(e,{childList:!0,subtree:!0,characterData:!0,attributes:!0});let v=()=>{g=!0,T?.disconnect(),A!==void 0&&clearTimeout(A)},P=S=>{let N=!1,ne=()=>{N||(N=!0,S())};typeof d.requestAnimationFrame=="function"&&d.requestAnimationFrame(()=>setTimeout(ne,0)),setTimeout(ne,100)},C=()=>{if(g)return;let S=ur(e);S!==p&&(p=S,b=st());let N=st();if(Qr(e,a)&&N-b>=Kr||N-l>=Jr){P(()=>{g||(v(),e.setAttribute(Wt,n),Vn(),o())});return}A=setTimeout(C,lr)};return A=setTimeout(C,lr),v}function fr(e,n,o,a,d){Mn();let l=(0,dt.useRef)({place:o,onDrawn:a});l.current={place:o,onDrawn:a},(0,dt.useLayoutEffect)(()=>{d&&Cn(d);let b=A=>Zr(A,l.current.place.path,()=>l.current.onDrawn?.(l.current.place),d);if(e.current)return b(e.current);let p,g=!1;return queueMicrotask(()=>{!g&&e.current&&(p=b(e.current))}),()=>{g=!0,p?.()}},[n,e,d])}var ye=Fe(Ct(),1),je,Xr=be(()=>(__graviewPreload(import.meta.url,["./chunk.2VTMTW7K.js","./chunk.ETR6AV47.js","./chunk.I5TOMBIF.js","./chunk.QQTRAY5W.js","./chunk.DOBQ4LO4.js","./chunk.KA44WNB4.js","./chunk.SDO3U72B.js","./chunk.4TJOS4C7.js","./chunk.2AZTW66C.js","./chunk.AJZBJBMO.js"]),import("./chunk.PCEYZQAW.js"))),pr=()=>Xr().then(e=>void(je=e),()=>new Promise(e=>setTimeout(e,2e3)).then(pr)),Nt=Tn(pr),mr=e=>!!e&&je===void 0;function $t({onReady:e,fetch:n}){return(0,ye.useLayoutEffect)(()=>void n().then(e),[e,n]),null}var eo=0;function hr(e){let[n,o]=(0,ye.useState)(()=>je);(0,ye.useEffect)(()=>{if(!e||n)return;let l=!1;return Nt().then(()=>{l||o(je)}),()=>{l=!0}},[e,n]);let a=(0,ye.useMemo)(()=>eo+=1,[e]);return{over:(0,ye.useMemo)(()=>{let l=n??je;if(!e||!l)return;let{source:b,worker:p,...g}=e,A={...g,worker:p??{source:b},draft:!0};return{name:e.manifest.name,home:e.manifest.attach==="home",register:T=>l.registerWorkerView(T,A)}},[e,n]),n:a}}var wr=Fe(zr(),1),j=Fe(qr(),1);var h=Fe(kn(),1);function ct(e,n={}){let o=Lt(e);return{Face:o.part((d,l)=>(0,c.createElement)(d,l),n),fetch:()=>o.load().then(()=>{}),here:()=>o.current!==void 0||o.failed}}var jt=e=>Promise.all([e,qn()]).then(([n])=>n),vr=be(()=>(__graviewPreload(import.meta.url,["./chunk.EXEZBZGW.js","./chunk.NTLHEHOM.js","./chunk.V2GSBYDK.js","./chunk.NLBIX7LH.js","./chunk.GACKGEUY.js","./chunk.HJCQ6I3S.js","./chunk.KVEDIBXS.js","./chunk.7VT3TRHR.js","./chunk.VQAQQW4Q.js","./chunk.DWPU56S5.js","./chunk.7FRPNQU4.js","./chunk.BDHKWVNX.js","./chunk.ZH4NWRWB.js","./chunk.GUMJEVVP.js","./chunk.SAHNXAV3.js","./chunk.UGJSMNVO.js","./chunk.NR5ODXMO.js","./chunk.E5GM2SMO.js","./chunk.NQZ73QV7.js","./chunk.O45VO36H.js","./chunk.UT6642FC.js","./chunk.QO7MDWID.js","./chunk.FOP5RBGF.js","./chunk.TI4OSTQV.js","./chunk.MAFFUPCR.js","./chunk.GZHZLJBF.js","./chunk.RQBEQYB2.js","./chunk.OJGHDWI6.js","./chunk.6VAFNCR4.js","./chunk.N4M54YK6.js","./chunk.KVJFY7N5.js","./chunk.DPHTUTOS.js","./chunk.2UIUMG23.js","./chunk.KA44WNB4.js","./chunk.SDO3U72B.js","./chunk.4TJOS4C7.js","./chunk.2AZTW66C.js","./chunk.AJZBJBMO.js"]),import("./chunk.NWT5FPEK.js"))),to=be(()=>(__graviewPreload(import.meta.url,["./chunk.TMDI7KRS.js","./chunk.I7QIHN66.js","./chunk.2QNGGF55.js","./chunk.PMJUGHW4.js","./chunk.Y4MQGEUS.js","./chunk.UGFDSE37.js","./chunk.EXEZBZGW.js","./chunk.X7N3JUO4.js","./chunk.NTLHEHOM.js","./chunk.GNBN3BK7.js","./chunk.XTMOFRHL.js","./chunk.NLBIX7LH.js","./chunk.GACKGEUY.js","./chunk.PXQVXBNG.js","./chunk.UJRBOUGC.js","./chunk.DWPU56S5.js","./chunk.ZH4NWRWB.js","./chunk.2GLJH253.js","./chunk.GUMJEVVP.js","./chunk.4VW6THJF.js","./chunk.SAHNXAV3.js","./chunk.DHAK6PPX.js","./chunk.YDL5BSTG.js","./chunk.DUWYF7BO.js","./chunk.UGJSMNVO.js","./chunk.NR5ODXMO.js","./chunk.O45VO36H.js","./chunk.UT6642FC.js","./chunk.XOZU4OFA.js","./chunk.SUPWMV2F.js","./chunk.MB7LKKUD.js","./chunk.WVUJXDXZ.js","./chunk.TPG6IY4M.js","./chunk.NFDLCUCC.js","./chunk.X7JMJSLU.js","./chunk.PPRSGM64.js","./chunk.5Y3Q7ONN.js","./chunk.KTFUVR4V.js","./chunk.GZHZLJBF.js","./chunk.RQBEQYB2.js","./chunk.OJGHDWI6.js","./chunk.6VAFNCR4.js","./chunk.N4M54YK6.js","./chunk.KVJFY7N5.js","./chunk.DPHTUTOS.js","./chunk.2UIUMG23.js","./chunk.KA44WNB4.js","./chunk.SDO3U72B.js","./chunk.4TJOS4C7.js","./chunk.2AZTW66C.js","./chunk.AJZBJBMO.js"]),import("./chunk.664PBQAQ.js"))),no=be(()=>(__graviewPreload(import.meta.url,["./chunk.TMDI7KRS.js","./chunk.I7QIHN66.js","./chunk.2QNGGF55.js","./chunk.PMJUGHW4.js","./chunk.Y4MQGEUS.js","./chunk.UGFDSE37.js","./chunk.EXEZBZGW.js","./chunk.X7N3JUO4.js","./chunk.NTLHEHOM.js","./chunk.GNBN3BK7.js","./chunk.XTMOFRHL.js","./chunk.NLBIX7LH.js","./chunk.GACKGEUY.js","./chunk.PXQVXBNG.js","./chunk.UJRBOUGC.js","./chunk.DWPU56S5.js","./chunk.ZH4NWRWB.js","./chunk.2GLJH253.js","./chunk.GUMJEVVP.js","./chunk.4VW6THJF.js","./chunk.SAHNXAV3.js","./chunk.DHAK6PPX.js","./chunk.YDL5BSTG.js","./chunk.DUWYF7BO.js","./chunk.UGJSMNVO.js","./chunk.NR5ODXMO.js","./chunk.O45VO36H.js","./chunk.UT6642FC.js","./chunk.XOZU4OFA.js","./chunk.SUPWMV2F.js","./chunk.MB7LKKUD.js","./chunk.WVUJXDXZ.js","./chunk.TPG6IY4M.js","./chunk.NFDLCUCC.js","./chunk.X7JMJSLU.js","./chunk.PPRSGM64.js","./chunk.5Y3Q7ONN.js","./chunk.KTFUVR4V.js","./chunk.GZHZLJBF.js","./chunk.RQBEQYB2.js","./chunk.OJGHDWI6.js","./chunk.6VAFNCR4.js","./chunk.N4M54YK6.js","./chunk.KVJFY7N5.js","./chunk.DPHTUTOS.js","./chunk.2UIUMG23.js","./chunk.KA44WNB4.js","./chunk.SDO3U72B.js","./chunk.4TJOS4C7.js","./chunk.2AZTW66C.js","./chunk.AJZBJBMO.js"]),import("./chunk.YUH43J2K.js"))),br=ct(()=>jt(vr().then(e=>e.SceneFace)),{what:"This view"}),Sr=ct(()=>vr().then(e=>e.SceneKeeping),{quiet:!0}),Pr=ct(()=>jt(to().then(e=>e.PagesContent)),{what:"This page"}),kr=ct(()=>jt(no().then(e=>e.PictureFace)),{what:"This picture"}),ro=br.Face,oo=Sr.Face,ao=Pr.Face,io=kr.Face;function Oe(...e){let n=e.length>0?e:["scene","pages","picture"],o=new Set(n.flatMap(Er));return Promise.all([...[...o].map(a=>a.fetch()),$n()]).then(()=>{},()=>{})}var Er=e=>e==="pages"?[Pr]:e==="picture"?[kr]:[br,Sr],Ar=e=>Er(e).every(n=>n.here()),so=150,It=0;function yr(e,n){if(Ar(e))return n();let o=++It,a=()=>{o===It&&(It+=1,n())};Oe(e).then(a),setTimeout(a,so)}var co=768;function lo(e,n){let o=n!==null&&n>=co;(0,c.useEffect)(()=>{if(!o||e==="picture")return;let a=e==="pages"?"scene":"pages";if(Ar(a))return;let d=globalThis,l=()=>void Oe(a),b=()=>{},p=Dn(()=>{if(d.requestIdleCallback&&d.cancelIdleCallback){let g=d.requestIdleCallback(l,{timeout:4e3});b=()=>d.cancelIdleCallback?.(g)}else{let g=setTimeout(l,1500);b=()=>clearTimeout(g)}});return()=>(p(),b())},[e,o])}function uo({asked:e,shown:n,onDrawn:o}){return(0,c.useLayoutEffect)(()=>o(e,n),[e,n,o]),null}function fo({auto:e,scene:n}){return(0,h.jsx)("div",{"data-embed-content":"","aria-busy":"true",style:{flex:e?n?`0 0 ${Bt}px`:"0 0 auto":"1 1 auto",minHeight:0,background:"var(--graview-ground)"}})}var po=Lt(be(()=>(__graviewPreload(import.meta.url,["./chunk.AJZBJBMO.js"]),import("./chunk.5JNXQHN4.js")))).part((e,n)=>(0,h.jsx)(e.StudioPlace,{...n}),{quiet:!0});function Rr(e,n,o,a,d){return Vt(e,Jn(n?nt(n):d??Sn,a),o)}function qt(e){return e&&nt(e).overview?"graview":"scene"}function gr(e,n){if(n.homeView?.()===void 0)return!1;let o=e.pages?.first?.trim();return o===void 0||o===""||o==="/"||o.toLowerCase()==="home"}function Tr(e){let[,n]=(0,c.useState)(!1),o=(0,c.useCallback)(()=>n(!0),[]),a=(0,c.useRef)(!1);return e.at&&!lt?(0,h.jsx)($t,{onReady:o,fetch:zt}):!a.current&&mr(e.draftView)?(0,h.jsx)($t,{onReady:o,fetch:Nt}):(a.current=!0,(0,h.jsx)(mo,{...e}))}function mo(e){let{app:n,stop:o,bar:a=!0,standing:d="Everything is in order",principal:l,heading:b=2}=e,{rootRef:p,scope:g,css:A,scheme:T,store:v,presence:P,brand:C,auto:S,height:N}=tr(e),ne=hr(e.draftView),V=Xn(e,zn,ne.over),[Z]=(0,c.useState)(On),u=e.basePath===void 0?{}:{basePath:e.basePath},[D]=(0,c.useState)(ot),q=e.notices??D,K=m=>Rt(m,u),x={...e.routing?{routing:e.routing}:{},...u},[de]=(0,c.useState)(()=>{let m=e.at?.face;if(m)return m;let F=o===void 0&&gr(n,V)?"pages":qt(o),me=Mt({...x,face:F});return e.face===void 0&&e.onOpening?.(me),me}),[$,O]=(0,c.useState)(()=>e.face!==void 0&&e.face!=="pages"&&!e.at&&o===void 0&&Gn(x)&&gr(n,V)),Pe=(0,c.useRef)(e.onFace);Pe.current=e.onFace,(0,c.useLayoutEffect)(()=>{$&&(Pe.current?.("pages"),O(!1))},[$]);let k=$?"pages":e.face??de,te=n.schema.kinds,R=e.routing==="address",J=(0,c.useMemo)(()=>e.at?lt.settleAt(e,v.seenBy(l??{kind:"human"}),V.places()):void 0,[]),B=(0,c.useMemo)(()=>Rn(V,n.schema),[V,n.schema]),ce=(0,c.useMemo)(()=>{let m=J?.stop??(R?Un(e.basePath):void 0)??o;return k==="scene"&&m===void 0&&B===void 0&&(e.path===void 0||_t(e.path))?Dt(void 0):Rr(k,m,te,V.places(),B)},[]),[we]=(0,c.useState)(k);(0,c.useEffect)(()=>{we!=="pages"&&An(V)},[we,V]);let W=(0,c.useRef)(void 0),z=m=>m===void 0||_t(m)?"/":m;W.current??={path:z(J?.path??(R?k==="pages"?(Tt(window.location.pathname,e.basePath)??"/")+window.location.search:"/":e.path)),asked:e.path},e.path!==W.current.asked&&(W.current={path:z(e.path),asked:e.path});let I=(0,c.useRef)(e.onNavigate);I.current=e.onNavigate;let le=(0,c.useCallback)((m,F)=>{W.current.path=m,I.current?.(m,F)},[]),{at:L,setAt:ke,steering:Y,steer:X}=ir(W.current.path),M=(0,c.useContext)(xr);M&&(M.pages=()=>W.current.path);let Ee=(0,c.useRef)(void 0),ue=(0,c.useCallback)(m=>void(W.current.path=m),[]),re=Wn(p),[Q,ze]=(0,c.useState)(!1),Ae=e.pagesBelow!==void 0&&re!==null&&re<e.pagesBelow&&(k==="scene"||k==="graview")&&!Q,E=Ae?"pages":k,Re=(0,c.useRef)(!1);Re.current=Q&&e.pagesBelow!==void 0&&re!==null&&re<e.pagesBelow&&(k==="scene"||k==="graview"),M&&(M.shown=E);let fe=(0,c.useRef)(k==="graview"?"graview":"scene");(E==="scene"||E==="graview")&&(fe.current=E),(0,c.useState)(()=>{if(!R||typeof window>"u"||E==="pages"||E==="picture")return;let{pathname:m,search:F,hash:me}=window.location;Tt(m,e.basePath)==="/"&&window.history.replaceState(window.history.state,"",`${K(ve)}${F}${me}`)}),er(p,E,e.onIntrinsicHeight),lo(E,re);let oe=sr(e.onError,E),He=dr(e.onReady,E),Te=(0,c.useRef)(e.onFaceDrawn);Te.current=e.onFaceDrawn;let pt=(0,c.useCallback)((m,F)=>{He(F),Te.current?.(m)},[He]),[mt,ht]=(0,c.useState)(null),G=V.places(),ee=(0,c.useRef)({shown:E,onFace:e.onFace});ee.current={shown:E,onFace:e.onFace};let U=(0,c.useCallback)((m,F,me)=>{if(R){Ee.current?.(m,F,me);return}ee.current.onFace?.(m),I.current?.(m==="pages"?F??W.current.path:ve,"push")},[R]),[Be,pe]=(0,c.useState)(void 0);(0,c.useEffect)(()=>{E==="pages"&&pe(void 0)},[E]);let Ge=(0,c.useRef)(o);(0,c.useEffect)(()=>{Ge.current!==o&&(Ge.current=o,pe(void 0))},[o]);let We=(0,c.useCallback)(m=>{if(ee.current.shown==="pages"){if(ze(!0),pe(m),k==="scene"||k==="graview"){yr(k,()=>{R?window.history.pushState(null,"",`${K(ve)}${m??""}`):I.current?.(ve,"push")});return}yr(fe.current,()=>U(fe.current,void 0,m))}},[R,k,e.basePath,U]),ae=(0,c.useCallback)(m=>{if(ee.current.shown==="pages"){Y.go.current||(W.current.path=m),X(m);return}if(W.current.path=m,ke(m),Re.current){ze(!1),R?window.history.pushState(null,"",K(m)):I.current?.(m,"push");return}U("pages",m)},[Y,X,ke,U,R,e.basePath]),Le=V.arrangement?.(),xe=E==="pages",_=e.hrefOf,ie=_??(R?K:void 0),Ue=(0,c.useMemo)(()=>({open:ae,..._?{href:_}:R?{href:m=>Rt(m,e.basePath===void 0?{}:{basePath:e.basePath})}:{}}),[ae,R,e.basePath,_]);return(0,h.jsxs)("section",{ref:p,className:g,"aria-label":e.label??n.name,"data-graview-embed":E,"data-graview-scheme":T,...Ae?{"data-graview-embed-narrow":""}:{},style:{position:"relative",isolation:"isolate",height:N,minHeight:S?0:320,display:"flex",flexDirection:"column",overflow:"hidden",borderRadius:"var(--graview-radius, 12px)"},children:[(0,h.jsx)("style",{children:A}),(0,h.jsxs)(Bn.Provider,{value:oe,children:[(0,h.jsx)(nr,{rootRef:p,board:q}),(0,h.jsx)(Zn,{rootRef:p,firstLook:e.firstLook,app:_n(C??{name:n.name},n.schema)}),(0,h.jsx)(_e,{module:"@graview/react",report:oe,content:!0,children:(0,h.jsx)(Fn.Provider,{value:Z,children:(0,h.jsx)(En,{store:v,views:V,initialView:ce,scheme:T,...rr(e,P,C),...e.onSeat?{onSeat:e.onSeat}:{},children:(0,h.jsxs)(Nn.Provider,{value:q,children:[(0,h.jsx)(wo,{face:E,stop:Be??o,kinds:te,places:G,opens:B}),M?(0,h.jsx)(ho,{into:M}):null,(0,h.jsx)(yo,{rootRef:p,face:k,shown:E,path:L,stop:o,draft:ne.n,onDrawn:e.onDrawn,parts:Z}),R?(0,h.jsx)(Kn,{pagesWere:J?.path,basePath:e.basePath,shown:E,onFace:e.onFace,toggle:Ee,kinds:te,places:G,opens:B,landed:ue}):null,a&&E!=="picture"?(0,h.jsx)(_e,{module:"@graview/embed",report:oe,children:(0,h.jsx)(or,{name:C?.name??n.name,heading:b,named:Ht(a).name!==!1,faces:Ht(a).faces===!1?void 0:{scene:{label:gn(Le),current:!xe,go:()=>We(),reach:()=>void Oe(fe.current)},pages:{label:wn(Le),current:xe,go:()=>ae(W.current.path),reach:()=>void Oe("pages")}},at:xe?L:null,without:e.pages?.without(),home:{...ie?.("/")!==void 0?{href:ie("/")}:{},go:()=>ae("/"),current:xe&&L.split("?")[0]==="/"},reach:{...ie?{href:ie}:{},go:m=>ae(m.path)},standing:d,hostActions:e.hostActions,keeping:xe?void 0:(0,h.jsx)(vo,{app:n,studio:e.studio,report:oe}),onFind:ht,switch:e.switch})}):null,(0,h.jsx)(In.Provider,{value:mt,children:(0,h.jsx)(_e,{module:E==="pages"||E==="picture"?"@graview/pages":"@graview/react",report:oe,content:!0,children:(0,h.jsxs)(c.Suspense,{fallback:(0,h.jsx)(fo,{auto:S,scene:E!=="pages"&&E!=="picture"}),children:[E==="picture"?(0,h.jsx)(io,{scope:g,store:v,views:V,as:(o?nt(o).within?.view:void 0)??""}):E==="pages"?(0,h.jsx)(ao,{store:v,views:V,presence:P,auto:S,brand:C,steering:Y,overview:We,scope:g,titleLevel:ar(b),quickAsk:at(e.quickAsk),props:{...e,onNavigate:le,...R?{}:{path:W.current.path}}}):(0,h.jsx)(Hn.Provider,{value:Ue,children:(0,h.jsx)(ro,{address:R,auto:S,scheme:T,scope:g,quickAsk:at(e.quickAsk)})}),(0,h.jsx)(uo,{asked:k,shown:E,onDrawn:pt})]})},E)})]})})})})]})]})}var _t=e=>e.split(/[?#]/)[0]===ve,xr=(0,c.createContext)(null);function ho({into:e}){return e.view=rt().view,null}function yo({rootRef:e,face:n,shown:o,path:a,stop:d,draft:l,onDrawn:b,parts:p}){let{view:g}=rt(),A=o==="scene"||o==="graview",T=Ft(g),v={face:n,path:A?ve:o==="picture"?d??"#":a,stop:T};return fr(e,`${o} ${A?T:v.path} ${l}`,v,b,p),null}var lt,go=be(()=>(__graviewPreload(import.meta.url,["./chunk.J6ANRF6E.js","./chunk.2UIUMG23.js","./chunk.KA44WNB4.js","./chunk.SDO3U72B.js","./chunk.4TJOS4C7.js","./chunk.2AZTW66C.js","./chunk.AJZBJBMO.js"]),import("./chunk.YVOABA2U.js"))),zt=()=>go().then(e=>void(lt=e),()=>new Promise(e=>{let n=()=>{window.removeEventListener("online",n),clearTimeout(o),e()},o=setTimeout(n,1e4);window.addEventListener("online",n)}).then(zt));function wo({face:e,stop:n,kinds:o,places:a,opens:d}){let{view:l,go:b}=rt(),p=(0,c.useRef)({face:e,stop:n});return(0,c.useLayoutEffect)(()=>{let g=p.current.stop!==n,A=p.current.face!==e,T=p.current.face==="pages";if(p.current={face:e,stop:n},!g&&!A||e==="pages"||e==="picture")return;let v=(g||T)&&n!==void 0?Rr(e,n,o,a):T&&Yn(l)?Vt(e,Dt(d),o):e==="graview"?Ot(l,!0):l.overview?Pn(Ot(l,!1),jn(l,o)):l;b(v)},[e,n,o,l,b,d]),null}function vo({app:e,studio:n,report:o}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(c.Suspense,{fallback:null,children:(0,h.jsx)(oo,{})}),n!==!1?(0,h.jsx)(_e,{module:"@graview/studio",report:o,children:(0,h.jsx)(bo,{app:e,studio:n})}):null]})}function bo({app:e,studio:n}){let o={app:e,within:"box",...n?{onApply:n.onApply}:{},...n?.landmark?{landmark:n.landmark}:{},...n?.offered!==void 0?{offered:n.offered}:{}},a=n?.place;return a?(0,h.jsx)(a,{...o}):(0,h.jsx)(c.Suspense,{fallback:null,children:(0,h.jsx)(po,{...o})})}function So({path:e,stop:n,...o},a){return{...o,app:a.app,at:a.at,...a.remote.presence?{presence:a.remote.presence}:{}}}function Gt(e,n){let o=n.store??n.remote?.store??Qn(n.app,n.seed),a=n.notices??ot(),d=null,l={},b=0,p=n.label,g=n.app,A=Promise.resolve(),T=n.at?.face??n.face,v=T===void 0?void 0:Mt({...n,face:T}),P=v??qt(n.stop),C=null,S=[],N=u=>{if(C=u,u!==P)return;let D=S;S=[];for(let q of D)q()};function ne(){let[u,D]=(0,c.useState)(v),[q,K]=(0,c.useState)(n.stop),[x,de]=(0,c.useState)(n.path),[$,O]=(0,c.useState)(n.scheme??"auto"),[Pe,k]=(0,c.useState)(n.principal),[te,R]=(0,c.useState)(n.seats),[J,B]=(0,c.useState)(n.quickAsk),[ce,we]=(0,c.useState)(n.people),[W,z]=(0,c.useState)(n.hostContext),[I,le]=(0,c.useState)(n.brand),[L,ke]=(0,c.useState)(n.label),[Y,X]=(0,c.useState)(n.hostActions),[M,Ee]=(0,c.useState)(void 0),[ue,re]=(0,c.useState)(n.draftView);return d={app:Q=>{Ee(Q),de(void 0),K(void 0)},face:D,stop:K,path:de,scheme:O,seat:k,seats:R,quickAsk:B,people:we,hostContext:z,brand:le,label:ke,hostActions:X,draft:re},(0,h.jsx)(xr.Provider,{value:l,children:(0,h.jsx)(Tr,{...M?So(n,M):n,store:o,notices:a,...u!==void 0?{face:u}:{},onOpening:Q=>{P=Q},...q!==void 0?{stop:q}:{},...x!==void 0?{path:x}:{},...Pe?{principal:Pe}:{},...te?{seats:te}:{},...J!==void 0?{quickAsk:J}:{},...ce?{people:ce}:{},...W?{hostContext:W}:{},...I?{brand:I}:{},label:L,hostActions:Y,draftView:ue,scheme:$,onFace:Q=>{P=Q,D(Q)},onSeat:k,onFaceDrawn:N},M?.n??0)})}let V=()=>{let u=l.view?.focusId,D=u?o.graph.getNode(u)?.kind:void 0,q=(l.shown??P)==="scene"||(l.shown??P)==="graview";return{face:P,path:q?ve:l.pages?.()??n.path??"/",stop:l.view?Ft(l.view):n.stop??"#",...D?{kind:D}:{}}},Z=(0,wr.createRoot)(e);return(0,j.flushSync)(()=>Z.render((0,h.jsx)(ne,{}))),{get store(){return o},where:V,setApp:(u,D,q)=>{let K="graph"in D?{store:D}:D,x=()=>{let de=V();o=K.store,p=q?.label??(p===g.name?u.name:p),g=u,(0,j.flushSync)(()=>{d?.label(p),d?.app({app:u,remote:K,at:de,n:++b})})};lt?x():A=A.then(zt).then(x)},setFace:u=>{P=u,(0,j.flushSync)(()=>d?.face(u))},setStop:u=>(0,j.flushSync)(()=>d?.stop(u)),setPath:u=>(0,j.flushSync)(()=>{if(_t(u)){(P==="pages"||P==="picture")&&(P="scene",d?.face("scene"));return}d?.path(u),P!=="pages"&&(P="pages",d?.face("pages"))}),setScheme:u=>(0,j.flushSync)(()=>d?.scheme(u)),setSeat:u=>(0,j.flushSync)(()=>d?.seat(u)),setSeats:u=>(0,j.flushSync)(()=>d?.seats(u)),setQuickAsk:u=>(0,j.flushSync)(()=>d?.quickAsk(u)),setPeople:u=>(0,j.flushSync)(()=>d?.people(u)),setHostContext:u=>(0,j.flushSync)(()=>d?.hostContext(u)),setBrand:u=>(0,j.flushSync)(()=>d?.brand(u)),setDraftView:u=>(0,j.flushSync)(()=>d?.draft(u)),setLabel:u=>{p=u,(0,j.flushSync)(()=>d?.label(u))},setHostActions:u=>(0,j.flushSync)(()=>d?.hostActions(u)),drawn:()=>A.then(()=>C===P?void 0:new Promise(u=>S.push(u))),notify:u=>{let D;return(0,j.flushSync)(()=>{D=a.notify(u)}),D},unmount:()=>Z.unmount()}}var Fr="/graview/live",Ut="graview.ship",Kt=`${Ut}.${Xe}`;var ge={seat:"x-graview-seat",roles:"x-graview-roles",kind:"x-graview-kind",name:"x-graview-name",for:"x-graview-for",forRoles:"x-graview-for-roles",forName:"x-graview-for-name",via:"x-graview-via"};var Ve=class extends Error{constructor(n){super(n),this.name="Superseded"}},Se=e=>e?.lineage?{lineage:e.lineage}:{},Po=(e,n)=>`${e.calls.map(o=>o.name.replace(/-/g," ")).join(", ")} (${n instanceof Error?n.message.split(`
2
- `)[0]??"":String(n)})`;function ko(e){if(!e)return[];try{let n=e.storage.getItem(e.key);if(n===null)return[];e.storage.removeItem(e.key);let o=JSON.parse(n);return Array.isArray(o)?o.filter(a=>!!a&&Array.isArray(a.calls)):[]}catch{return[]}}var De=class extends Error{constructor(o){super(o.sentence);this.refusal=o;this.name="RemoteRefusedError"}},Eo={401:"forbidden",403:"forbidden",404:"missing",413:"limit"},Ce=class extends Error{constructor(o,a){super(o);this.conflicts=a;this.name="StaleWrite"}},qe=class extends Error{constructor(n){super(n),this.name="Unreached"}},Ao=new Set([502,503,504]);async function Ro(e){try{return(await e.clone().json()).reason==="unavailable"}catch{return!1}}function To(){let e=Math.random().toString(36).slice(2,8),n=0;return()=>`local-${e}-${++n}`}var xo=1,Fo=()=>({refusals:new Set,conflicts:new Set,statuses:new Set,helds:new Set,builds:new Set,who:new Set,declarations:new Set,tally:{reconnects:0,rebases:0,conflicts:0,resyncs:0}});async function ut(e){return(await Cr(e,ko(e.carry),"This app was updated while your changes were on the way.",Fo())).remote}async function Cr(e,n,o,a){let d=e.fetch??fetch,l={"content-type":"application/json",...e.headers??{}},b={...ft(e.principal),[ge.via]:e.via??"web"};Object.assign(l,b);let p=e.live===!0,g=e.presenceEveryMs,A=e.visible??Lo,T="connecting",v=a.statuses,P=a.tally,C=[],S,N=[],ne=()=>T==="online"&&S!==void 0?"held":T,V=()=>{let t=ne();if(a.told!==t){a.told=t;for(let r of[...v])r(t)}},Z=t=>{if(!(t===T||se)&&(T==="offline"&&t==="online"&&P.reconnects++,T=t,V(),t==="online"))for(let r of C.splice(0))r.again()},u=t=>{if(se)return;let r=typeof t=="string"&&t.length>0?t:void 0,s=r!==S;if(S=r,D(),!!s&&(V(),r===void 0)){for(let i of N.splice(0))i();F&&clearTimeout(F),me()}},D=()=>{if(a.toldHeld!==S){a.toldHeld=S;for(let t of[...a.helds])t(S??null)}},q=async(t,r)=>{let s;try{s=await d(t,r)}catch(i){throw _()||Z("offline"),new qe(i instanceof Error?i.message:String(i))}if(s.status===503&&await Ro(s))return Z("online"),s;if(Ao.has(s.status))throw _()||Z("offline"),new qe(`The server is away (${s.status})`);return Z("online"),s},K=async(t=!1)=>{let r=`${e.url}/graview/state?opFormat=${Ie.op}`,s=t?await d(r,{headers:l}):await q(r,{headers:l});if(!s.ok)throw new Error((await s.json().catch(()=>({}))).error??`The server refused (${s.status})`);return await s.json()},x=e.state??await K(!0);p||(T="online"),S=typeof x.held=="string"&&x.held.length>0?x.held:void 0,D();let de=x.enabledModules??e.enabledModules,$=e.localApp?e.localApp(e.app):e.app,O=new yn({schema:$.schema,mutations:$.mutations??[],invariants:$.invariants??[],...$.policy?{policy:$.policy}:{},...$.modules?{modules:$.modules}:{},...de?{enabledModules:de}:{},...$.intelligence?{intelligence:$.intelligence}:{},...$.brand?.timeZone?{timeZone:$.brand.timeZone}:{},snapshot:x.snapshot,log:x.log,...x.horizon!==void 0?{horizon:x.horizon}:{},ids:To(),...e.storeOptions??{}});pn.served.add(O);let Pe=mn(O),k=x.log.at(-1)?.seq??(x.horizon??0)-1,te=At.of(x.log,{horizon:x.horizon??0}),R=null,J,B=new Map,ce=a.who,we=!1,W=t=>{if(se)return;we=!0;let r=vn(new Map,t,Date.now(),1e4,R?.participant);J!==void 0&&r.delete(J);let s=r.size!==B.size;if(!s)for(let[i,f]of r)xt(f,B.get(i))||(s=!0);if(B=r,!!s)for(let i of[...ce])i([...B.values()])},z=[],I=new Set,le=t=>{let r=z.indexOf(t);r>=0&&z.splice(r,1)},L=new Map,ke=(t,r)=>{let s=L.get(t);s&&(L.delete(t),s.resolve({ops:r.filter(i=>i.batch===t),batch:t}))},Y,X=[],M=(t,r=[])=>{if(t.length===0&&r.length===0)return[];if(Y)return X.push({ops:t,drop:r}),[];let s=Math.min(...t.filter(w=>w.seq>k).map(w=>w.seq));if(Number.isFinite(s)&&s>k+1)return X.push({ops:t,drop:r}),Ee(),[];let i=z.filter(w=>t.some($e=>$e.batch===w)),f=[...new Set([...r,...i])].filter(w=>I.has(w)),y,H=z.filter(w=>!i.includes(w));try{y=O.rebase({confirmed:t,pending:H,drop:f}).confirmed}catch(w){if(!(w instanceof hn))throw w;return X.push({ops:t,drop:r}),Ee(),[]}for(let w of i)le(w);t.some(w=>w.seq>k)&&H.some(w=>!f.includes(w))&&P.rebases++,t.length>0&&(k=Math.max(k,...t.map(w=>w.seq)),te.note(t));for(let w of f)I.delete(w);for(let w of i)ke(w,t);return y},Ee=()=>{Y||(Y=oe(K().then(t=>{if(ue(t)){X=[];return}let r=new Set(t.log.map(f=>f.batch)),s=z.filter(f=>r.has(f));for(let f of s)le(f);let i=O.adopt({snapshot:t.snapshot,log:t.log,...t.horizon!==void 0?{horizon:t.horizon}:{},pending:[...z],drop:[...I].filter(f=>!z.includes(f))});I.clear();for(let f of i.pending)I.add(f.batch);k=t.log.at(-1)?.seq??(t.horizon??0)-1,te=At.of(t.log,{horizon:t.horizon??0}),P.resyncs++;for(let f of s)ke(f,t.log)}).then(()=>{Y=void 0;let t=X;X=[];for(let{ops:r,drop:s}of t)M(r,s)},()=>{Y=void 0,X=[]})))},ue=t=>(typeof t.build=="string"&&en(t.build),typeof t.version=="number"&&u(t.held),typeof t.version!="number"||t.version===x.version?!1:(vt(t.version),!0)),re=async t=>{let s=await(await q(`${e.url}/graview/since?seq=${t}&opFormat=${Ie.op}`,{headers:l})).json();return ue(s)?[]:s.ops??[]},Q=async()=>{let t=await ze();return Y&&await Y,t},ze=async()=>{if(R&&!_()&&A()){let r=await(await q(`${e.url}/graview/here`,{method:"POST",headers:l,body:JSON.stringify({presence:R,seq:k})})).json();return ue(r)?[]:(typeof r.participant=="string"&&(J=r.participant),W(r.who??[]),M(r.ops??[]))}return M(await re(k))},Ae=new Map,E=new Map,Re=new Map,fe=new Set,oe=t=>(fe.add(t),t.finally(()=>fe.delete(t)).catch(()=>{}),t),He=Promise.resolve(),Te=0,pt=(t,r)=>{let s=He.then(()=>ht(t,r));return He=s.catch(()=>{}),s},mt=()=>new Promise((t,r)=>C.push({again:t,give:r})),ht=async(t,r)=>{let s,i;for(;;){try{s=await q(`${e.url}/graview/ops`,{method:"POST",headers:l,body:JSON.stringify({...t,opFormat:Ie.op})})}catch(w){if(!(w instanceof qe)||U)throw w;if(await mt(),_())return Ke(t,r);continue}if(i=await s.json().catch(()=>({})),s.status===503&&i.reason==="unavailable"&&typeof i.held=="string"&&!U){if(typeof i.version=="number"?ue(i):(u(i.held),!1))break;if(S!==void 0&&(Pt>0||p)){if(await new Promise(w=>N.push(w)),U)throw new Ve("The client closed.");if(_())return Ke(t,r);continue}}let H;if(s.status===503&&i.reason==="unavailable"&&!U)H=Jt(e.backoff,Te++);else{if(Te=0,s.status!==429||U)break;H=Oo(s.headers.get("retry-after"),i.retryAfter)}if(await new Promise(w=>setTimeout(w,H)),_())return Ke(t,r)}if(se||ue(i))throw new Ve("The app was changed.");if(!s.ok){let H=i.error??`The server refused (${s.status})`;throw i.conflict?new Ce(H,i.conflicts??[]):new De({reason:i.reason??Eo[s.status]??"invalid",sentence:H,...i.wouldNeed?.length?{wouldNeed:i.wouldNeed}:{}})}let f=i.ops??[],y=f[0]?.seq;return y!==void 0&&y>k+1&&(f=await re(k)),r!==void 0&&(i.batch&&Ae.set(r,i.batch),le(r)),M(f,r!==void 0?[r]:[]),{ops:i.ops??[],...i.batch?{batch:i.batch}:{}}},G,ee=!1,U=!1,Be=0,pe,Ge=0,We=0,ae=null,Le=()=>{},xe=new Promise(t=>{Le=t}),_=()=>p&&ee&&G?.readyState===xo,ie=t=>{if(!_())return!1;try{return G.send(JSON.stringify(t)),!0}catch{return!1}},Ue=(t=!1)=>{!R||!_()||!A()||!t&&ae&&xt(R,ae)&&(g===void 0||Date.now()-We<g)||ie({t:"here",presence:R})&&(ae=R,We=Date.now())},m=new Set,F,me=()=>{if(F=void 0,S!==void 0)return;let t=[...L.entries()].filter(([r])=>m.has(r));m.clear();for(let[,r]of t)ie(r.message)},Xt=(t,r)=>{L.has(t)&&(m.add(t),F&&clearTimeout(F),F=setTimeout(me,Math.max(0,r)))},Vr=t=>{L.has(t)&&m.add(t)},Ke=(t,r)=>new Promise((s,i)=>{let f=r??`send-${++Ge}`,y=t.undo?{t:"undo",cid:f,batches:t.undo,...t.intent?{intent:t.intent}:{},...t.batch?{batch:t.batch}:{},...t.via?{via:t.via}:{},...Se(t)}:{t:"call",cid:f,calls:t.calls??[],...t.intent?{intent:t.intent}:{},...t.batch?{batch:t.batch}:{},...t.base?.length?{base:t.base}:{},...t.via?{via:t.via}:{},...Se(t)};if(L.set(f,{message:y,...r!==void 0?{mine:r}:{},resolve:s,reject:i}),m.size>0||S!==void 0){m.add(f);return}ie(y)}),yt=(t,r)=>_()?Ke(t,r):pt(t,r),Dr=t=>{switch(t.t){case"welcome":{if(en(t.build),typeof t.version=="number"&&t.version!==x.version){vt(t.version);return}if(ee=!0,Be=0,typeof t.participant=="string"&&(J=t.participant),u(t.held),M(t.ops??[]),m.clear(),F&&clearTimeout(F),F=void 0,S!==void 0)for(let r of L.keys())m.add(r);else for(let r of L.values())ie(r.message);Ue(!0),Z("online"),Le();return}case"ops":M(t.ops??[]);return;case"ack":{let r=L.get(t.cid);if(!r){M(t.ops??[]);return}L.delete(t.cid),Te=0,r.mine!==void 0&&(Ae.set(r.mine,t.batch),le(r.mine)),M(t.ops??[],r.mine!==void 0?[r.mine]:[]),r.resolve({ops:t.ops??[],batch:t.batch});return}case"refused":case"conflict":{let r=L.get(t.cid);if(!r)return;if(t.t==="refused"&&t.reason==="unavailable"){S!==void 0?Vr(t.cid):Xt(t.cid,Jt(e.backoff,Te++));return}L.delete(t.cid),r.reject(t.t==="conflict"?new Ce(t.sentence,t.conflicts??[]):new De({reason:t.reason??"invalid",sentence:t.sentence,...t.wouldNeed?.length?{wouldNeed:[...t.wouldNeed]}:{}}));return}case"busy":typeof t.cid=="string"&&Xt(t.cid,typeof t.retryAfter=="number"?t.retryAfter:1e3);return;case"presence":W(t.who??[]);return;case"held":u(t.sentence);return;case"declaration":typeof t.version=="number"&&t.version!==x.version&&vt(t.version);return;case"reload":on(typeof t.reason=="string"?t.reason:"This app was updated.");return;case"error":if(t.reopen===!0&&G){let r=G;sn(r);try{r.close(1e3,"Opening again.")}catch{}}return;default:return}},se=!1,gt=a.declarations,wt=a.builds,en=t=>{if(!(se||a.otherBuild!==void 0||!e.build||typeof t!="string"||t.length===0||t===e.build)){a.otherBuild=t;for(let r of[...wt])r(t)}},tn=()=>{let t=[],r=0;for(let s of z){let i=Re.get(s);i?t.push({calls:i.calls,...i.intent?{intent:i.intent}:{},...i.via?{via:i.via}:{},...Se(i),batch:s}):r++}return{carried:t,undos:r}},nn=(t,r)=>`${r} while ${t===1?"an undo of yours was":"undos of yours were"} on the way; ${t===1?"it was":"they were"} not made.`,rn=t=>{se=!0,R=null;let r=new Ve(t);for(let i of L.values())i.reject(r);L.clear(),Qe&&clearInterval(Qe),U=!0,pe&&clearTimeout(pe),F&&clearTimeout(F),he&&clearTimeout(he);for(let i of C.splice(0))i.give(r);for(let i of N.splice(0))i();let s=G;G=void 0,ee=!1;try{s?.close(1e3,t)}catch{}Le()};async function vt(t){if(se)return;if(!e.resolveApp){on(`This app was changed on its server (version ${t}); reload the page to carry on.`);return}let{carried:r,undos:s}=tn(),i=e.resolveApp,f=R;rn("The app was changed.");try{let y=await i(t),{state:H,...w}=e,$e=await Cr({...w,app:y},r,"The app was changed while your changes were on the way.",a);f&&$e.remote.presence.here(f);for(let Ze of[...gt])Ze($e.remote,t);let _r=[...s>0?[Je(nn(s,"The app was changed"))]:[],...$e.unheard()];for(let Ze of _r)for(let jr of Me)jr(Ze.sentence,Ze)}catch(y){let H=`The app was changed, but the new version could not be opened: ${y instanceof Error?y.message:String(y)}`;for(let w of Me)w(H,Je(H))}}function on(t){if(se)return;let{carried:r,undos:s}=tn();rn(t);let i=!1;if(e.carry&&r.length>0)try{e.carry.storage.setItem(e.carry.key,JSON.stringify(r)),i=!0}catch{}let f=[];!i&&r.length>0&&f.push(`${t} ${r.length===1?"A change of yours was":`${r.length} changes of yours were`} not sent; make ${r.length===1?"it":"them"} again after the page reloads.`),s>0&&f.push(nn(s,"This app was updated"));for(let y of f)for(let H of Me)H(y,Je(y));(e.reloadPage??Co)()}let an=()=>{if(U||!p)return;let t=`${e.url.replace(/^http/,"ws").replace(/\/$/,"")}${Fr}`,{"content-type":r,...s}=l,i;try{i=e.socket?e.socket(t,s,[Kt]):Ir(t,s)}catch{return dn()}G=i,ee=!1,i.onopen=()=>{G===i&&i.send(JSON.stringify({t:"hello",seq:k,protocol:Xe,wire:Ut,opFormat:Ie.op,...e.build?{build:e.build.slice(0,64)}:{},...e.hostProtocol!==void 0?{hostProtocol:e.hostProtocol}:{}}))},i.onmessage=f=>{if(G!==i)return;let y;try{y=JSON.parse(String(f.data))}catch{return}Dr(y)},i.onclose=()=>sn(i),i.onerror=()=>{}},he,Hr=()=>{we=!1,he&&clearTimeout(he),he=setTimeout(()=>{if(he=void 0,we||U)return;let t=new Map([...B].filter(([,r])=>r.held!=="socket"));if(t.size!==B.size){B=t;for(let r of ce)r([...B.values()])}},1e4),he.unref?.()};function sn(t){if(G!==t)return;let r=ee;G=void 0,ee=!1,ae=null,r&&(Z("offline"),Hr()),dn()}let dn=()=>{if(U)return;let t=Jt(e.backoff,Be);Be++,pe=setTimeout(an,t)},Br=O.applyAll.bind(O),Wr=O.undo.bind(O),Nr=O.previewAll.bind(O);O.previewAll=(t,r)=>Nr(t,{...e.principal?{author:e.principal}:{},...r});let Me=a.refusals,Ne=[],Je=t=>({reason:"invalid",sentence:t}),Ye=a.conflicts,bt=!1,cn=async(t,r)=>{if(r instanceof Ve||se)return;let s=r instanceof De?r.refusal:un(r),i=s.sentence;le(t);try{M([],[t])}catch{}let f=Re.get(t);if(Re.delete(t),r instanceof Ce&&P.conflicts++,r instanceof Ce&&!_()&&await Q().catch(()=>[]),r instanceof Ce&&Ye.size>0){let y=!1,H={sentence:i,conflicts:r.conflicts,keepTheirs(){y=!0},useMine(){if(!(y||!f)){y=!0,bt=!0;try{O.applyAll(f.calls,{...f.intent?{intent:f.intent}:{},...f.via?{via:f.via}:{},...Se(f)})}finally{bt=!1}}}};for(let w of Ye)w(H);return}for(let y of Me)y(i,s)};O.applyAll=(t,r)=>{let s=fn(O.log.all().filter(y=>I.has(y.batch))),i=Br(t,{...e.principal?{author:e.principal}:{},...r});z.push(i.batch),I.add(i.batch),Re.set(i.batch,{calls:t,...r?.intent?{intent:r.intent}:{},...r?.via?{via:r.via}:{},...Se(r)});let f=bt?[]:te.baseFor(i.ops,s);return E.set(i.batch,oe(yt({calls:t,...r?.intent?{intent:r.intent}:{},batch:i.batch,...f.length>0?{base:f}:{},...r?.via?{via:r.via}:{},...Se(r)},i.batch).catch(y=>cn(i.batch,y)))),i},O.apply=(t,r)=>O.applyAll([t],r),O.undo=(t,r)=>{let s=typeof t=="string"?[t]:t,i=Wr(s.map(y=>Ae.get(y)??y),{...e.principal?{author:e.principal}:{},...r});z.push(i.batch),I.add(i.batch);let f=Promise.allSettled(s.map(y=>E.get(y)));return E.set(i.batch,oe(f.then(()=>yt({undo:s.map(y=>Ae.get(y)??y),...r?.intent?{intent:r.intent}:{},batch:i.batch,...r?.via?{via:r.via}:{},...Se(r)},i.batch)).catch(y=>cn(i.batch,y)))),i};let $r=async(t,r={})=>{St++;try{return(await oe(yt({calls:t,...r}))).ops}finally{St--}},St=0,ln={here(t){R=t,Ue()},onWho(t){return ce.add(t),B.size>0&&t([...B.values()]),()=>{ce.delete(t)}},leave(){if(!R)return;let t=JSON.stringify({participant:J??R.participant});if(R=null,ie({t:"bye"}))return;let r=globalThis.navigator?.sendBeacon;r?r.call(globalThis.navigator,`${e.url}/graview/leave`,t):d(`${e.url}/graview/leave`,{method:"POST",headers:l,body:t}).catch(()=>{})}},Pt=e.pollMs??800,Qe=Pt>0&&typeof setInterval=="function"?setInterval(()=>{_()||Q().catch(()=>{})},Pt):null;if(p){an();let t;await Promise.race([xe,new Promise(r=>t=setTimeout(r,e.openTimeoutMs??3e3))]),clearTimeout(t)}if(n.length>0&&!se){let t=[],r=new Set(O.log.all().map(s=>s.batch));for(let s of n)if(!(s.batch!==void 0&&r.has(s.batch)))try{O.applyAll(s.calls,{...s.intent?{intent:s.intent}:{},...s.batch?{batch:s.batch}:{},...s.via?{via:s.via}:{},...Se(s)})}catch(i){t.push(Po(s,i))}t.length>0&&Ne.push(Je(`${o} ${t.length===1?"One no longer fits and was not made":`${t.length} no longer fit and were not made`}: ${t.join("; ")}.`))}return{remote:{store:O,version:x.version,migrated:x.migrated??[],send:$r,pull:Q,onRefusal(t){Me.add(t);let r=Ne;Ne=[];for(let s of r)t(s.sentence,s);return()=>Me.delete(t)},onDeclaration(t){return gt.add(t),()=>gt.delete(t)},onBuild(t){return wt.add(t),a.otherBuild!==void 0&&t(a.otherBuild),()=>wt.delete(t)},onConflict(t){return Ye.add(t),()=>Ye.delete(t)},revision:(t,r)=>te.of(t,r),seq:()=>k,participant:()=>J,transport:()=>_()?"socket":"poll",status:ne,onStatus(t){return v.add(t),()=>v.delete(t)},held:()=>S,onHeld(t){return a.helds.add(t),S!==void 0&&t(S),()=>a.helds.delete(t)},counters:()=>({...P}),who:()=>[...B.values()],pending:()=>z.length+St,async settled(){for(;fe.size>0;)await Promise.allSettled([...fe])},presence:ln,close(){Qe&&clearInterval(Qe),Pe(),ln.leave(),U=!0,pe&&clearTimeout(pe),F&&clearTimeout(F),he&&clearTimeout(he);for(let r of C.splice(0))r.give(new Error("The client closed before the server could be reached."));for(let r of N.splice(0))r();let t=G;G=void 0,ee=!1;try{t?.close(1e3,"Closed.")}catch{}}},unheard(){let t=Ne;return Ne=[],t}};function Ir(t,r){let s=globalThis.WebSocket;if(!s)throw new Error("This runtime has no WebSocket; the client polls instead.");let i=typeof globalThis.document<"u",f=e.subprotocol?[Kt]:[];if(!i)try{return new s(t,{headers:r,...f.length>0?{protocols:f}:{}})}catch{}let y=new URL(t);for(let[H,w]of Object.entries(b))y.searchParams.set(H,w);return f.length>0?new s(y.toString(),f):new s(y.toString())}}function Oo(e,n,o=Date.now()){let a,d=e?.trim();if(d)if(/^\d+(\.\d+)?$/.test(d))a=Number(d)*1e3;else{let p=Date.parse(d);Number.isFinite(p)&&(a=Math.max(0,p-o))}let l=typeof n=="number"&&Number.isFinite(n)&&n>=0?n:void 0,b=l!==void 0&&l<50&&a!==void 0&&Math.abs(l*1e3-a)<1e3;return l!==void 0&&!b?l:a??1e3}function Co(){globalThis.location?.reload?.()}function Lo(){return globalThis.document?.visibilityState!=="hidden"}function Jt(e,n){if(typeof e=="function")return Math.max(0,e(n));let{min:o=250,max:a=1e4,factor:d=2}=e??{};return Math.min(a,o*d**n)*(.75+Math.random()*.5)}function ft(e){let n={};if(!e)return n;e.id&&(n[ge.seat]=e.id),e.roles?.length&&(n[ge.roles]=e.roles.join(",")),e.kind!=="human"&&(n[ge.kind]=e.kind),e.name&&(n[ge.name]=encodeURIComponent(e.name));let o=e.onBehalfOf;return o?.id&&(n[ge.for]=o.id),o?.roles?.length&&(n[ge.forRoles]=o.roles.join(",")),o?.name&&(n[ge.forName]=encodeURIComponent(o.name)),n}var Lr="/graview/views";function Yt(e){let n=e.fetch??fetch,o=e.url.replace(/\/$/,""),a={"content-type":"application/json",...e.principal?ft(e.principal):{},...e.headers??{}},d=e.state?{hidden:e.state.hidden??[],removed:e.state.removed??[],may:e.state.may??et.may}:et,l=new Set,b=v=>{if(JSON.stringify(v)!==JSON.stringify(d)){d=v;for(let P of l)P()}},p=async(v,P)=>{let C=await n(`${o}${e.path??Lr}`,{method:v,headers:a,...P!==void 0?{body:JSON.stringify(P)}:{}}),S=await C.json();if(!C.ok)throw new Error(S.error??`The store answered ${C.status}.`);b({hidden:S.hidden??[],removed:S.removed??[],may:S.may??et.may})},g=()=>p("GET"),A=e.state?Promise.resolve():g().catch(()=>{}),T=e.pollMs?setInterval(()=>void g().catch(()=>{}),e.pollMs):void 0;return{ready:A,refresh:g,close:()=>clearInterval(T),current:()=>d,onChange(v){return l.add(v),()=>void l.delete(v)},hide:v=>p("POST",{hide:v}),show:v=>p("POST",{show:v}),remove:(v,P)=>p("POST",{remove:v,...P?{about:P}:{}}),async restore(v){let P=d.removed.find(C=>C.name===v)?.lens;await p("POST",{restore:v}),P&&await e.onDeclaration?.()},async lens(v){await p("POST",{lens:v}),await e.onDeclaration?.()}}}var Zt=document.getElementById("graview-app"),Qt=/^\/forms\/([^/]+)\/?$/.exec(location.pathname),Mr=Qt?(__graviewPreload(import.meta.url,["./chunk.2QNGGF55.js","./chunk.Y4MQGEUS.js","./chunk.UGFDSE37.js","./chunk.EXEZBZGW.js","./chunk.X7N3JUO4.js","./chunk.NTLHEHOM.js","./chunk.GNBN3BK7.js","./chunk.XTMOFRHL.js","./chunk.NLBIX7LH.js","./chunk.GACKGEUY.js","./chunk.UJRBOUGC.js","./chunk.DWPU56S5.js","./chunk.ZH4NWRWB.js","./chunk.2GLJH253.js","./chunk.GUMJEVVP.js","./chunk.4VW6THJF.js","./chunk.SAHNXAV3.js","./chunk.DHAK6PPX.js","./chunk.YDL5BSTG.js","./chunk.DUWYF7BO.js","./chunk.UGJSMNVO.js","./chunk.NR5ODXMO.js","./chunk.XOZU4OFA.js","./chunk.SUPWMV2F.js","./chunk.MB7LKKUD.js","./chunk.V4BCB7N2.js","./chunk.FOP5RBGF.js","./chunk.WVUJXDXZ.js","./chunk.TPG6IY4M.js","./chunk.NFDLCUCC.js","./chunk.X7JMJSLU.js","./chunk.PPRSGM64.js","./chunk.5Y3Q7ONN.js","./chunk.KTFUVR4V.js","./chunk.GZHZLJBF.js","./chunk.RQBEQYB2.js","./chunk.OJGHDWI6.js","./chunk.6VAFNCR4.js","./chunk.N4M54YK6.js","./chunk.KVJFY7N5.js","./chunk.DPHTUTOS.js","./chunk.2UIUMG23.js","./chunk.KA44WNB4.js","./chunk.SDO3U72B.js","./chunk.4TJOS4C7.js","./chunk.2AZTW66C.js","./chunk.AJZBJBMO.js"]),import("./chunk.FPYL6REZ.js")):Oe("pages");try{Qt?await Mo(decodeURIComponent(Qt[1])):await Vo()}catch(e){let n=document.createElement("pre");n.setAttribute("role","alert"),n.style.cssText="margin:2rem;font:14px/1.5 ui-monospace,monospace;white-space:pre-wrap",n.textContent=e instanceof Error?e.message:String(e),Zt.replaceChildren(n),window.__graviewFailed=n.textContent}async function Mo(e){let n=await fetch(`/graview/document?form=${encodeURIComponent(e)}`),o=await n.json();if(!n.ok)throw new Error(o.error??`The preview server did not hand over the form (${n.status}).`);let a=await it(o);if(!a.ok)throw new Error(tt(a.findings));let d=a.app,l=o.principal,b=await ut({app:d,url:location.origin,principal:l,...o.state?{state:o.state,openTimeoutMs:0}:{openTimeoutMs:3e3}});document.title=d.forms?.[e]?.title??d.name;let{mount:p}=await Mr;window.__graview=p(Zt,{app:d,form:e,principal:l,remote:b,height:"100dvh",onSubmitted:()=>window.__graviewSubmitted=!0}),window.__graviewReady=!0}async function Vo(){let e=await fetch("/graview/document");if(!e.ok)throw new Error(`The preview server did not hand over the document (${e.status}).`);let n=await e.json(),a=await(async g=>{if(typeof g.module=="string")return(await import(g.module)).app;let A=await it(g);if(!A.ok)throw new Error(tt(A.findings));return A.app})(n);if(!a||typeof a!="object"||!("schema"in a))throw new Error("The app module the preview server handed does not export an app.");let d=n.principal,l=await ut({app:a,url:location.origin,principal:d,live:!0,subprotocol:!0,pollMs:1200,...n.state?{state:n.state,openTimeoutMs:0}:{openTimeoutMs:3e3}});document.title=a.name;let b,p=Yt({url:location.origin,principal:d,...n.views?{state:n.views}:{},onDeclaration:async()=>{let g=await(await fetch("/graview/document")).json();if(typeof g.module=="string")return;let A=await it(g);A.ok&&b?.setApp(A.app,l)}});await Promise.all([Mr,p.ready]),b=Gt(Zt,{app:a,remote:l,principal:d,studio:!1,face:"pages",routing:"address",bar:!0,height:"100dvh",label:a.name,heading:1,keptViews:p,...n.draftView?{draftView:n.draftView}:{}}),window.__graview=b,b.drawn().then(()=>{window.__graviewReady=!0})}
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 Mt,b as Gn,c as Un,d as Kn,e as Jn,f as Vt,g as Yn,h as Dt}from"./chunk.CXIIRL67.js";import{a as zr}from"./chunk.YECMUK4X.js";import{a as Ht,b as Zn,c as Xn,d as er,e as Bt,f as tr,g as nr,h as rr,i as or,j as ar,k as ir,l as sr,m as dr,n as _e}from"./chunk.IWEPDTVG.js";import{b as Qn}from"./chunk.2OLZ6BYI.js";import{a as kt}from"./chunk.Q5WEOX3Q.js";import{a as Et,g as bn}from"./chunk.54PZWX23.js";import{k as tt}from"./chunk.TABIRLQS.js";import{C as _n,H as jn,L as qn,M as zn,j as qr,k as Wn,n as ot,o as Nn,q as $n,u as In,z as at}from"./chunk.423SZS7C.js";import{Aa as Vn,Ca as Dn,Da as Lt,G as Ct,Ha as Hn,Ia as Bn,La as rt,R as kn,W as En,a as Sn,b as Ft,c as nt,da as An,ea as Rn,j as Pn,m as Ot,sa as Tn,ta as xn,ua as Fn,va as On,wa as Cn,xa as Ln,za as Mn}from"./chunk.TM6JVVGW.js";import{a as be}from"./chunk.SDO3U72B.js";import{$b as At,Dd as Rt,Ed as Tt,Hd as vn,Id as xt,Jc as pn,Xc as mn,Zc as hn,_c as yn,ac as fn,ad as et,kb as Ie,lb as Xe,wd as ve,xb as un,xd as gn,yd as wn}from"./chunk.PFEKS3KO.js";import"./chunk.2AZTW66C.js";import{b as Fe}from"./chunk.AJZBJBMO.js";async function it(e,n={}){let o=e.compiled===void 0||!Ur(e.compiled,e.document)?void 0:bn(e.compiled,n);if(o?.ok)return o;let{compileDocumentWithoutCheck:a}=await Gr();return a(e.document,n)}var cr,Gr=()=>cr??=(__graviewPreload(import.meta.url,["./chunk.JBG5UQLM.js","./chunk.54PZWX23.js","./chunk.3EW6L5DY.js","./chunk.LD6S2FL5.js","./chunk.TABIRLQS.js","./chunk.PFEKS3KO.js","./chunk.2AZTW66C.js","./chunk.AJZBJBMO.js"]),import("./chunk.VV3PNZPI.js")).catch(e=>{throw cr=void 0,e});function Ur(e,n){let o=typeof e=="object"&&e!==null?e.document:void 0,a=n;if(typeof a=="string")try{a=JSON.parse(a)}catch{return!1}return o!==void 0&&kt(Et(o).document)===kt(Et(a).document)}var c=Fe(Ct(),1);var dt=Fe(Ct(),1),Wt="data-graview-drawn",Kr=200,lr=50,Jr=1e4,st=()=>typeof performance<"u"?performance.now():Date.now();function Yr(e){let n=[...e.querySelectorAll("img")];for(let o of e.querySelectorAll("[data-worker-view]"))o.shadowRoot&&n.push(...o.shadowRoot.querySelectorAll("img"));return n}function Qr(e,n){if(e.ownerDocument.fonts?.status==="loading"||xn()>0||Ln(n)>0||e.querySelector('[aria-busy="true"]')||Yr(e).some(a=>!a.complete&&a.loading!=="lazy"))return!1;for(let a of e.querySelectorAll("[data-worker-view-place]"))if(!a.querySelector("[data-worker-view][data-worker-view-drawn], [data-worker-view][data-worker-view-failed]"))return!1;return!0}function ur(e){let n=e.querySelector("[data-embed-content]"),o=[...e.querySelectorAll("[data-worker-view]")].map(a=>`${a.offsetWidth}x${a.offsetHeight}`);return`${e.scrollWidth}x${e.scrollHeight}|${n?`${n.scrollWidth}x${n.scrollHeight}`:""}|${o.join(",")}`}function Zr(e,n,o,a){e.removeAttribute(Wt);let d=e.ownerDocument.defaultView;if(!d)return()=>{};let l=st(),b=l,p=ur(e),g=!1,A,T=typeof MutationObserver>"u"?void 0:new MutationObserver(S=>{S.some(N=>!(N.target===e&&N.attributeName===Wt))&&(b=st())});T?.observe(e,{childList:!0,subtree:!0,characterData:!0,attributes:!0});let v=()=>{g=!0,T?.disconnect(),A!==void 0&&clearTimeout(A)},P=S=>{let N=!1,ne=()=>{N||(N=!0,S())};typeof d.requestAnimationFrame=="function"&&d.requestAnimationFrame(()=>setTimeout(ne,0)),setTimeout(ne,100)},C=()=>{if(g)return;let S=ur(e);S!==p&&(p=S,b=st());let N=st();if(Qr(e,a)&&N-b>=Kr||N-l>=Jr){P(()=>{g||(v(),e.setAttribute(Wt,n),Vn(),o())});return}A=setTimeout(C,lr)};return A=setTimeout(C,lr),v}function fr(e,n,o,a,d){Mn();let l=(0,dt.useRef)({place:o,onDrawn:a});l.current={place:o,onDrawn:a},(0,dt.useLayoutEffect)(()=>{d&&Cn(d);let b=A=>Zr(A,l.current.place.path,()=>l.current.onDrawn?.(l.current.place),d);if(e.current)return b(e.current);let p,g=!1;return queueMicrotask(()=>{!g&&e.current&&(p=b(e.current))}),()=>{g=!0,p?.()}},[n,e,d])}var ye=Fe(Ct(),1),je,Xr=be(()=>(__graviewPreload(import.meta.url,["./chunk.G3Q5CYEM.js","./chunk.KVEDMKUN.js","./chunk.FUMQLGNM.js","./chunk.BVXOLZQ3.js","./chunk.KDTNKKOY.js","./chunk.TM6JVVGW.js","./chunk.SDO3U72B.js","./chunk.PFEKS3KO.js","./chunk.2AZTW66C.js","./chunk.AJZBJBMO.js"]),import("./chunk.NBJ4C33P.js"))),pr=()=>Xr().then(e=>void(je=e),()=>new Promise(e=>setTimeout(e,2e3)).then(pr)),Nt=Tn(pr),mr=e=>!!e&&je===void 0;function $t({onReady:e,fetch:n}){return(0,ye.useLayoutEffect)(()=>void n().then(e),[e,n]),null}var eo=0;function hr(e){let[n,o]=(0,ye.useState)(()=>je);(0,ye.useEffect)(()=>{if(!e||n)return;let l=!1;return Nt().then(()=>{l||o(je)}),()=>{l=!0}},[e,n]);let a=(0,ye.useMemo)(()=>eo+=1,[e]);return{over:(0,ye.useMemo)(()=>{let l=n??je;if(!e||!l)return;let{source:b,worker:p,...g}=e,A={...g,worker:p??{source:b},draft:!0};return{name:e.manifest.name,home:e.manifest.attach==="home",register:T=>l.registerWorkerView(T,A)}},[e,n]),n:a}}var wr=Fe(zr(),1),j=Fe(qr(),1);var h=Fe(kn(),1);function ct(e,n={}){let o=Lt(e);return{Face:o.part((d,l)=>(0,c.createElement)(d,l),n),fetch:()=>o.load().then(()=>{}),here:()=>o.current!==void 0||o.failed}}var jt=e=>Promise.all([e,qn()]).then(([n])=>n),vr=be(()=>(__graviewPreload(import.meta.url,["./chunk.SGJSJGSR.js","./chunk.Q4KNNJFL.js","./chunk.WQN7EFW3.js","./chunk.N2S3TMBC.js","./chunk.7JW5SHRR.js","./chunk.HJCQ6I3S.js","./chunk.DFGXNFFE.js","./chunk.XN7PIWVC.js","./chunk.C75I24Z5.js","./chunk.IVHPJUFM.js","./chunk.W6CGAPNQ.js","./chunk.7C4IR4S7.js","./chunk.D53IGR45.js","./chunk.AP22NNIM.js","./chunk.FNK2ZZ5E.js","./chunk.AGVFW6WC.js","./chunk.SIVMZNHZ.js","./chunk.NQ7SRWXA.js","./chunk.AOEXSQDG.js","./chunk.3NEALGMI.js","./chunk.UT6642FC.js","./chunk.IWEPDTVG.js","./chunk.2OLZ6BYI.js","./chunk.TI4OSTQV.js","./chunk.D4K23FUB.js","./chunk.GZHZLJBF.js","./chunk.FOYVTN5B.js","./chunk.OJGHDWI6.js","./chunk.OTF3NNTI.js","./chunk.A7HMVWMG.js","./chunk.GRLPNTUW.js","./chunk.EJAVIZ7Y.js","./chunk.423SZS7C.js","./chunk.TM6JVVGW.js","./chunk.SDO3U72B.js","./chunk.PFEKS3KO.js","./chunk.2AZTW66C.js","./chunk.AJZBJBMO.js"]),import("./chunk.4Q5KWYVY.js"))),to=be(()=>(__graviewPreload(import.meta.url,["./chunk.D4IKO5YA.js","./chunk.7MJGZHTS.js","./chunk.QWX2N2VD.js","./chunk.BJR6E2CT.js","./chunk.VSWEKNKS.js","./chunk.UGFDSE37.js","./chunk.SGJSJGSR.js","./chunk.2OXXGN7C.js","./chunk.Q4KNNJFL.js","./chunk.BH365UJ5.js","./chunk.6EHE26ZS.js","./chunk.N2S3TMBC.js","./chunk.7JW5SHRR.js","./chunk.PXQVXBNG.js","./chunk.4SEY7VWZ.js","./chunk.IVHPJUFM.js","./chunk.D53IGR45.js","./chunk.MJ4XTNTL.js","./chunk.AP22NNIM.js","./chunk.SPZVEQC5.js","./chunk.FNK2ZZ5E.js","./chunk.RSR2M7ZO.js","./chunk.EM5CGFNB.js","./chunk.N2S45SSL.js","./chunk.AGVFW6WC.js","./chunk.SIVMZNHZ.js","./chunk.3NEALGMI.js","./chunk.UT6642FC.js","./chunk.XOZU4OFA.js","./chunk.35FUGOSG.js","./chunk.MB7LKKUD.js","./chunk.WVUJXDXZ.js","./chunk.NQDGUIUQ.js","./chunk.DTRNDSMS.js","./chunk.3EW6L5DY.js","./chunk.AVDXG57A.js","./chunk.LD6S2FL5.js","./chunk.TABIRLQS.js","./chunk.GZHZLJBF.js","./chunk.FOYVTN5B.js","./chunk.OJGHDWI6.js","./chunk.OTF3NNTI.js","./chunk.A7HMVWMG.js","./chunk.GRLPNTUW.js","./chunk.EJAVIZ7Y.js","./chunk.423SZS7C.js","./chunk.TM6JVVGW.js","./chunk.SDO3U72B.js","./chunk.PFEKS3KO.js","./chunk.2AZTW66C.js","./chunk.AJZBJBMO.js"]),import("./chunk.6WRA3Y7D.js"))),no=be(()=>(__graviewPreload(import.meta.url,["./chunk.D4IKO5YA.js","./chunk.7MJGZHTS.js","./chunk.QWX2N2VD.js","./chunk.BJR6E2CT.js","./chunk.VSWEKNKS.js","./chunk.UGFDSE37.js","./chunk.SGJSJGSR.js","./chunk.2OXXGN7C.js","./chunk.Q4KNNJFL.js","./chunk.BH365UJ5.js","./chunk.6EHE26ZS.js","./chunk.N2S3TMBC.js","./chunk.7JW5SHRR.js","./chunk.PXQVXBNG.js","./chunk.4SEY7VWZ.js","./chunk.IVHPJUFM.js","./chunk.D53IGR45.js","./chunk.MJ4XTNTL.js","./chunk.AP22NNIM.js","./chunk.SPZVEQC5.js","./chunk.FNK2ZZ5E.js","./chunk.RSR2M7ZO.js","./chunk.EM5CGFNB.js","./chunk.N2S45SSL.js","./chunk.AGVFW6WC.js","./chunk.SIVMZNHZ.js","./chunk.3NEALGMI.js","./chunk.UT6642FC.js","./chunk.XOZU4OFA.js","./chunk.35FUGOSG.js","./chunk.MB7LKKUD.js","./chunk.WVUJXDXZ.js","./chunk.NQDGUIUQ.js","./chunk.DTRNDSMS.js","./chunk.3EW6L5DY.js","./chunk.AVDXG57A.js","./chunk.LD6S2FL5.js","./chunk.TABIRLQS.js","./chunk.GZHZLJBF.js","./chunk.FOYVTN5B.js","./chunk.OJGHDWI6.js","./chunk.OTF3NNTI.js","./chunk.A7HMVWMG.js","./chunk.GRLPNTUW.js","./chunk.EJAVIZ7Y.js","./chunk.423SZS7C.js","./chunk.TM6JVVGW.js","./chunk.SDO3U72B.js","./chunk.PFEKS3KO.js","./chunk.2AZTW66C.js","./chunk.AJZBJBMO.js"]),import("./chunk.6EGHJCEM.js"))),br=ct(()=>jt(vr().then(e=>e.SceneFace)),{what:"This view"}),Sr=ct(()=>vr().then(e=>e.SceneKeeping),{quiet:!0}),Pr=ct(()=>jt(to().then(e=>e.PagesContent)),{what:"This page"}),kr=ct(()=>jt(no().then(e=>e.PictureFace)),{what:"This picture"}),ro=br.Face,oo=Sr.Face,ao=Pr.Face,io=kr.Face;function Oe(...e){let n=e.length>0?e:["scene","pages","picture"],o=new Set(n.flatMap(Er));return Promise.all([...[...o].map(a=>a.fetch()),$n()]).then(()=>{},()=>{})}var Er=e=>e==="pages"?[Pr]:e==="picture"?[kr]:[br,Sr],Ar=e=>Er(e).every(n=>n.here()),so=150,It=0;function yr(e,n){if(Ar(e))return n();let o=++It,a=()=>{o===It&&(It+=1,n())};Oe(e).then(a),setTimeout(a,so)}var co=768;function lo(e,n){let o=n!==null&&n>=co;(0,c.useEffect)(()=>{if(!o||e==="picture")return;let a=e==="pages"?"scene":"pages";if(Ar(a))return;let d=globalThis,l=()=>void Oe(a),b=()=>{},p=Dn(()=>{if(d.requestIdleCallback&&d.cancelIdleCallback){let g=d.requestIdleCallback(l,{timeout:4e3});b=()=>d.cancelIdleCallback?.(g)}else{let g=setTimeout(l,1500);b=()=>clearTimeout(g)}});return()=>(p(),b())},[e,o])}function uo({asked:e,shown:n,onDrawn:o}){return(0,c.useLayoutEffect)(()=>o(e,n),[e,n,o]),null}function fo({auto:e,scene:n}){return(0,h.jsx)("div",{"data-embed-content":"","aria-busy":"true",style:{flex:e?n?`0 0 ${Bt}px`:"0 0 auto":"1 1 auto",minHeight:0,background:"var(--graview-ground)"}})}var po=Lt(be(()=>(__graviewPreload(import.meta.url,["./chunk.AJZBJBMO.js"]),import("./chunk.5JNXQHN4.js")))).part((e,n)=>(0,h.jsx)(e.StudioPlace,{...n}),{quiet:!0});function Rr(e,n,o,a,d){return Vt(e,Jn(n?nt(n):d??Sn,a),o)}function qt(e){return e&&nt(e).overview?"graview":"scene"}function gr(e,n){if(n.homeView?.()===void 0)return!1;let o=e.pages?.first?.trim();return o===void 0||o===""||o==="/"||o.toLowerCase()==="home"}function Tr(e){let[,n]=(0,c.useState)(!1),o=(0,c.useCallback)(()=>n(!0),[]),a=(0,c.useRef)(!1);return e.at&&!lt?(0,h.jsx)($t,{onReady:o,fetch:zt}):!a.current&&mr(e.draftView)?(0,h.jsx)($t,{onReady:o,fetch:Nt}):(a.current=!0,(0,h.jsx)(mo,{...e}))}function mo(e){let{app:n,stop:o,bar:a=!0,standing:d="Everything is in order",principal:l,heading:b=2}=e,{rootRef:p,scope:g,css:A,scheme:T,store:v,presence:P,brand:C,auto:S,height:N}=tr(e),ne=hr(e.draftView),V=Xn(e,zn,ne.over),[Z]=(0,c.useState)(On),u=e.basePath===void 0?{}:{basePath:e.basePath},[D]=(0,c.useState)(ot),q=e.notices??D,K=m=>Rt(m,u),x={...e.routing?{routing:e.routing}:{},...u},[de]=(0,c.useState)(()=>{let m=e.at?.face;if(m)return m;let F=o===void 0&&gr(n,V)?"pages":qt(o),me=Mt({...x,face:F});return e.face===void 0&&e.onOpening?.(me),me}),[$,O]=(0,c.useState)(()=>e.face!==void 0&&e.face!=="pages"&&!e.at&&o===void 0&&Gn(x)&&gr(n,V)),Pe=(0,c.useRef)(e.onFace);Pe.current=e.onFace,(0,c.useLayoutEffect)(()=>{$&&(Pe.current?.("pages"),O(!1))},[$]);let k=$?"pages":e.face??de,te=n.schema.kinds,R=e.routing==="address",J=(0,c.useMemo)(()=>e.at?lt.settleAt(e,v.seenBy(l??{kind:"human"}),V.places()):void 0,[]),B=(0,c.useMemo)(()=>Rn(V,n.schema),[V,n.schema]),ce=(0,c.useMemo)(()=>{let m=J?.stop??(R?Un(e.basePath):void 0)??o;return k==="scene"&&m===void 0&&B===void 0&&(e.path===void 0||_t(e.path))?Dt(void 0):Rr(k,m,te,V.places(),B)},[]),[we]=(0,c.useState)(k);(0,c.useEffect)(()=>{we!=="pages"&&An(V)},[we,V]);let W=(0,c.useRef)(void 0),z=m=>m===void 0||_t(m)?"/":m;W.current??={path:z(J?.path??(R?k==="pages"?(Tt(window.location.pathname,e.basePath)??"/")+window.location.search:"/":e.path)),asked:e.path},e.path!==W.current.asked&&(W.current={path:z(e.path),asked:e.path});let I=(0,c.useRef)(e.onNavigate);I.current=e.onNavigate;let le=(0,c.useCallback)((m,F)=>{W.current.path=m,I.current?.(m,F)},[]),{at:L,setAt:ke,steering:Y,steer:X}=ir(W.current.path),M=(0,c.useContext)(xr);M&&(M.pages=()=>W.current.path);let Ee=(0,c.useRef)(void 0),ue=(0,c.useCallback)(m=>void(W.current.path=m),[]),re=Wn(p),[Q,ze]=(0,c.useState)(!1),Ae=e.pagesBelow!==void 0&&re!==null&&re<e.pagesBelow&&(k==="scene"||k==="graview")&&!Q,E=Ae?"pages":k,Re=(0,c.useRef)(!1);Re.current=Q&&e.pagesBelow!==void 0&&re!==null&&re<e.pagesBelow&&(k==="scene"||k==="graview"),M&&(M.shown=E);let fe=(0,c.useRef)(k==="graview"?"graview":"scene");(E==="scene"||E==="graview")&&(fe.current=E),(0,c.useState)(()=>{if(!R||typeof window>"u"||E==="pages"||E==="picture")return;let{pathname:m,search:F,hash:me}=window.location;Tt(m,e.basePath)==="/"&&window.history.replaceState(window.history.state,"",`${K(ve)}${F}${me}`)}),er(p,E,e.onIntrinsicHeight),lo(E,re);let oe=sr(e.onError,E),He=dr(e.onReady,E),Te=(0,c.useRef)(e.onFaceDrawn);Te.current=e.onFaceDrawn;let pt=(0,c.useCallback)((m,F)=>{He(F),Te.current?.(m)},[He]),[mt,ht]=(0,c.useState)(null),G=V.places(),ee=(0,c.useRef)({shown:E,onFace:e.onFace});ee.current={shown:E,onFace:e.onFace};let U=(0,c.useCallback)((m,F,me)=>{if(R){Ee.current?.(m,F,me);return}ee.current.onFace?.(m),I.current?.(m==="pages"?F??W.current.path:ve,"push")},[R]),[Be,pe]=(0,c.useState)(void 0);(0,c.useEffect)(()=>{E==="pages"&&pe(void 0)},[E]);let Ge=(0,c.useRef)(o);(0,c.useEffect)(()=>{Ge.current!==o&&(Ge.current=o,pe(void 0))},[o]);let We=(0,c.useCallback)(m=>{if(ee.current.shown==="pages"){if(ze(!0),pe(m),k==="scene"||k==="graview"){yr(k,()=>{R?window.history.pushState(null,"",`${K(ve)}${m??""}`):I.current?.(ve,"push")});return}yr(fe.current,()=>U(fe.current,void 0,m))}},[R,k,e.basePath,U]),ae=(0,c.useCallback)(m=>{if(ee.current.shown==="pages"){Y.go.current||(W.current.path=m),X(m);return}if(W.current.path=m,ke(m),Re.current){ze(!1),R?window.history.pushState(null,"",K(m)):I.current?.(m,"push");return}U("pages",m)},[Y,X,ke,U,R,e.basePath]),Le=V.arrangement?.(),xe=E==="pages",_=e.hrefOf,ie=_??(R?K:void 0),Ue=(0,c.useMemo)(()=>({open:ae,..._?{href:_}:R?{href:m=>Rt(m,e.basePath===void 0?{}:{basePath:e.basePath})}:{}}),[ae,R,e.basePath,_]);return(0,h.jsxs)("section",{ref:p,className:g,"aria-label":e.label??n.name,"data-graview-embed":E,"data-graview-scheme":T,...Ae?{"data-graview-embed-narrow":""}:{},style:{position:"relative",isolation:"isolate",height:N,minHeight:S?0:320,display:"flex",flexDirection:"column",overflow:"hidden",borderRadius:"var(--graview-radius, 12px)"},children:[(0,h.jsx)("style",{children:A}),(0,h.jsxs)(Bn.Provider,{value:oe,children:[(0,h.jsx)(nr,{rootRef:p,board:q}),(0,h.jsx)(Zn,{rootRef:p,firstLook:e.firstLook,app:_n(C??{name:n.name},n.schema)}),(0,h.jsx)(_e,{module:"@graview/react",report:oe,content:!0,children:(0,h.jsx)(Fn.Provider,{value:Z,children:(0,h.jsx)(En,{store:v,views:V,initialView:ce,scheme:T,...rr(e,P,C),...e.onSeat?{onSeat:e.onSeat}:{},children:(0,h.jsxs)(Nn.Provider,{value:q,children:[(0,h.jsx)(wo,{face:E,stop:Be??o,kinds:te,places:G,opens:B}),M?(0,h.jsx)(ho,{into:M}):null,(0,h.jsx)(yo,{rootRef:p,face:k,shown:E,path:L,stop:o,draft:ne.n,onDrawn:e.onDrawn,parts:Z}),R?(0,h.jsx)(Kn,{pagesWere:J?.path,basePath:e.basePath,shown:E,onFace:e.onFace,toggle:Ee,kinds:te,places:G,opens:B,landed:ue}):null,a&&E!=="picture"?(0,h.jsx)(_e,{module:"@graview/embed",report:oe,children:(0,h.jsx)(or,{name:C?.name??n.name,heading:b,named:Ht(a).name!==!1,faces:Ht(a).faces===!1?void 0:{scene:{label:gn(Le),current:!xe,go:()=>We(),reach:()=>void Oe(fe.current)},pages:{label:wn(Le),current:xe,go:()=>ae(W.current.path),reach:()=>void Oe("pages")}},at:xe?L:null,without:e.pages?.without(),home:{...ie?.("/")!==void 0?{href:ie("/")}:{},go:()=>ae("/"),current:xe&&L.split("?")[0]==="/"},reach:{...ie?{href:ie}:{},go:m=>ae(m.path)},standing:d,hostActions:e.hostActions,keeping:xe?void 0:(0,h.jsx)(vo,{app:n,studio:e.studio,report:oe}),onFind:ht,switch:e.switch})}):null,(0,h.jsx)(In.Provider,{value:mt,children:(0,h.jsx)(_e,{module:E==="pages"||E==="picture"?"@graview/pages":"@graview/react",report:oe,content:!0,children:(0,h.jsxs)(c.Suspense,{fallback:(0,h.jsx)(fo,{auto:S,scene:E!=="pages"&&E!=="picture"}),children:[E==="picture"?(0,h.jsx)(io,{scope:g,store:v,views:V,as:(o?nt(o).within?.view:void 0)??""}):E==="pages"?(0,h.jsx)(ao,{store:v,views:V,presence:P,auto:S,brand:C,steering:Y,overview:We,scope:g,titleLevel:ar(b),quickAsk:at(e.quickAsk),props:{...e,onNavigate:le,...R?{}:{path:W.current.path}}}):(0,h.jsx)(Hn.Provider,{value:Ue,children:(0,h.jsx)(ro,{address:R,auto:S,scheme:T,scope:g,quickAsk:at(e.quickAsk)})}),(0,h.jsx)(uo,{asked:k,shown:E,onDrawn:pt})]})},E)})]})})})})]})]})}var _t=e=>e.split(/[?#]/)[0]===ve,xr=(0,c.createContext)(null);function ho({into:e}){return e.view=rt().view,null}function yo({rootRef:e,face:n,shown:o,path:a,stop:d,draft:l,onDrawn:b,parts:p}){let{view:g}=rt(),A=o==="scene"||o==="graview",T=Ft(g),v={face:n,path:A?ve:o==="picture"?d??"#":a,stop:T};return fr(e,`${o} ${A?T:v.path} ${l}`,v,b,p),null}var lt,go=be(()=>(__graviewPreload(import.meta.url,["./chunk.CXIIRL67.js","./chunk.423SZS7C.js","./chunk.TM6JVVGW.js","./chunk.SDO3U72B.js","./chunk.PFEKS3KO.js","./chunk.2AZTW66C.js","./chunk.AJZBJBMO.js"]),import("./chunk.REANMQ6K.js"))),zt=()=>go().then(e=>void(lt=e),()=>new Promise(e=>{let n=()=>{window.removeEventListener("online",n),clearTimeout(o),e()},o=setTimeout(n,1e4);window.addEventListener("online",n)}).then(zt));function wo({face:e,stop:n,kinds:o,places:a,opens:d}){let{view:l,go:b}=rt(),p=(0,c.useRef)({face:e,stop:n});return(0,c.useLayoutEffect)(()=>{let g=p.current.stop!==n,A=p.current.face!==e,T=p.current.face==="pages";if(p.current={face:e,stop:n},!g&&!A||e==="pages"||e==="picture")return;let v=(g||T)&&n!==void 0?Rr(e,n,o,a):T&&Yn(l)?Vt(e,Dt(d),o):e==="graview"?Ot(l,!0):l.overview?Pn(Ot(l,!1),jn(l,o)):l;b(v)},[e,n,o,l,b,d]),null}function vo({app:e,studio:n,report:o}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(c.Suspense,{fallback:null,children:(0,h.jsx)(oo,{})}),n!==!1?(0,h.jsx)(_e,{module:"@graview/studio",report:o,children:(0,h.jsx)(bo,{app:e,studio:n})}):null]})}function bo({app:e,studio:n}){let o={app:e,within:"box",...n?{onApply:n.onApply}:{},...n?.landmark?{landmark:n.landmark}:{},...n?.offered!==void 0?{offered:n.offered}:{}},a=n?.place;return a?(0,h.jsx)(a,{...o}):(0,h.jsx)(c.Suspense,{fallback:null,children:(0,h.jsx)(po,{...o})})}function So({path:e,stop:n,...o},a){return{...o,app:a.app,at:a.at,...a.remote.presence?{presence:a.remote.presence}:{}}}function Gt(e,n){let o=n.store??n.remote?.store??Qn(n.app,n.seed),a=n.notices??ot(),d=null,l={},b=0,p=n.label,g=n.app,A=Promise.resolve(),T=n.at?.face??n.face,v=T===void 0?void 0:Mt({...n,face:T}),P=v??qt(n.stop),C=null,S=[],N=u=>{if(C=u,u!==P)return;let D=S;S=[];for(let q of D)q()};function ne(){let[u,D]=(0,c.useState)(v),[q,K]=(0,c.useState)(n.stop),[x,de]=(0,c.useState)(n.path),[$,O]=(0,c.useState)(n.scheme??"auto"),[Pe,k]=(0,c.useState)(n.principal),[te,R]=(0,c.useState)(n.seats),[J,B]=(0,c.useState)(n.quickAsk),[ce,we]=(0,c.useState)(n.people),[W,z]=(0,c.useState)(n.hostContext),[I,le]=(0,c.useState)(n.brand),[L,ke]=(0,c.useState)(n.label),[Y,X]=(0,c.useState)(n.hostActions),[M,Ee]=(0,c.useState)(void 0),[ue,re]=(0,c.useState)(n.draftView);return d={app:Q=>{Ee(Q),de(void 0),K(void 0)},face:D,stop:K,path:de,scheme:O,seat:k,seats:R,quickAsk:B,people:we,hostContext:z,brand:le,label:ke,hostActions:X,draft:re},(0,h.jsx)(xr.Provider,{value:l,children:(0,h.jsx)(Tr,{...M?So(n,M):n,store:o,notices:a,...u!==void 0?{face:u}:{},onOpening:Q=>{P=Q},...q!==void 0?{stop:q}:{},...x!==void 0?{path:x}:{},...Pe?{principal:Pe}:{},...te?{seats:te}:{},...J!==void 0?{quickAsk:J}:{},...ce?{people:ce}:{},...W?{hostContext:W}:{},...I?{brand:I}:{},label:L,hostActions:Y,draftView:ue,scheme:$,onFace:Q=>{P=Q,D(Q)},onSeat:k,onFaceDrawn:N},M?.n??0)})}let V=()=>{let u=l.view?.focusId,D=u?o.graph.getNode(u)?.kind:void 0,q=(l.shown??P)==="scene"||(l.shown??P)==="graview";return{face:P,path:q?ve:l.pages?.()??n.path??"/",stop:l.view?Ft(l.view):n.stop??"#",...D?{kind:D}:{}}},Z=(0,wr.createRoot)(e);return(0,j.flushSync)(()=>Z.render((0,h.jsx)(ne,{}))),{get store(){return o},where:V,setApp:(u,D,q)=>{let K="graph"in D?{store:D}:D,x=()=>{let de=V();o=K.store,p=q?.label??(p===g.name?u.name:p),g=u,(0,j.flushSync)(()=>{d?.label(p),d?.app({app:u,remote:K,at:de,n:++b})})};lt?x():A=A.then(zt).then(x)},setFace:u=>{P=u,(0,j.flushSync)(()=>d?.face(u))},setStop:u=>(0,j.flushSync)(()=>d?.stop(u)),setPath:u=>(0,j.flushSync)(()=>{if(_t(u)){(P==="pages"||P==="picture")&&(P="scene",d?.face("scene"));return}d?.path(u),P!=="pages"&&(P="pages",d?.face("pages"))}),setScheme:u=>(0,j.flushSync)(()=>d?.scheme(u)),setSeat:u=>(0,j.flushSync)(()=>d?.seat(u)),setSeats:u=>(0,j.flushSync)(()=>d?.seats(u)),setQuickAsk:u=>(0,j.flushSync)(()=>d?.quickAsk(u)),setPeople:u=>(0,j.flushSync)(()=>d?.people(u)),setHostContext:u=>(0,j.flushSync)(()=>d?.hostContext(u)),setBrand:u=>(0,j.flushSync)(()=>d?.brand(u)),setDraftView:u=>(0,j.flushSync)(()=>d?.draft(u)),setLabel:u=>{p=u,(0,j.flushSync)(()=>d?.label(u))},setHostActions:u=>(0,j.flushSync)(()=>d?.hostActions(u)),drawn:()=>A.then(()=>C===P?void 0:new Promise(u=>S.push(u))),notify:u=>{let D;return(0,j.flushSync)(()=>{D=a.notify(u)}),D},unmount:()=>Z.unmount()}}var Fr="/graview/live",Ut="graview.ship",Kt=`${Ut}.${Xe}`;var ge={seat:"x-graview-seat",roles:"x-graview-roles",kind:"x-graview-kind",name:"x-graview-name",for:"x-graview-for",forRoles:"x-graview-for-roles",forName:"x-graview-for-name",via:"x-graview-via"};var Ve=class extends Error{constructor(n){super(n),this.name="Superseded"}},Se=e=>e?.lineage?{lineage:e.lineage}:{},Po=(e,n)=>`${e.calls.map(o=>o.name.replace(/-/g," ")).join(", ")} (${n instanceof Error?n.message.split(`
2
+ `)[0]??"":String(n)})`;function ko(e){if(!e)return[];try{let n=e.storage.getItem(e.key);if(n===null)return[];e.storage.removeItem(e.key);let o=JSON.parse(n);return Array.isArray(o)?o.filter(a=>!!a&&Array.isArray(a.calls)):[]}catch{return[]}}var De=class extends Error{constructor(o){super(o.sentence);this.refusal=o;this.name="RemoteRefusedError"}},Eo={401:"forbidden",403:"forbidden",404:"missing",413:"limit"},Ce=class extends Error{constructor(o,a){super(o);this.conflicts=a;this.name="StaleWrite"}},qe=class extends Error{constructor(n){super(n),this.name="Unreached"}},Ao=new Set([502,503,504]);async function Ro(e){try{return(await e.clone().json()).reason==="unavailable"}catch{return!1}}function To(){let e=Math.random().toString(36).slice(2,8),n=0;return()=>`local-${e}-${++n}`}var xo=1,Fo=()=>({refusals:new Set,conflicts:new Set,statuses:new Set,helds:new Set,builds:new Set,who:new Set,declarations:new Set,tally:{reconnects:0,rebases:0,conflicts:0,resyncs:0}});async function ut(e){return(await Cr(e,ko(e.carry),"This app was updated while your changes were on the way.",Fo())).remote}async function Cr(e,n,o,a){let d=e.fetch??fetch,l={"content-type":"application/json",...e.headers??{}},b={...ft(e.principal),[ge.via]:e.via??"web"};Object.assign(l,b);let p=e.live===!0,g=e.presenceEveryMs,A=e.visible??Lo,T="connecting",v=a.statuses,P=a.tally,C=[],S,N=[],ne=()=>T==="online"&&S!==void 0?"held":T,V=()=>{let t=ne();if(a.told!==t){a.told=t;for(let r of[...v])r(t)}},Z=t=>{if(!(t===T||se)&&(T==="offline"&&t==="online"&&P.reconnects++,T=t,V(),t==="online"))for(let r of C.splice(0))r.again()},u=t=>{if(se)return;let r=typeof t=="string"&&t.length>0?t:void 0,s=r!==S;if(S=r,D(),!!s&&(V(),r===void 0)){for(let i of N.splice(0))i();F&&clearTimeout(F),me()}},D=()=>{if(a.toldHeld!==S){a.toldHeld=S;for(let t of[...a.helds])t(S??null)}},q=async(t,r)=>{let s;try{s=await d(t,r)}catch(i){throw _()||Z("offline"),new qe(i instanceof Error?i.message:String(i))}if(s.status===503&&await Ro(s))return Z("online"),s;if(Ao.has(s.status))throw _()||Z("offline"),new qe(`The server is away (${s.status})`);return Z("online"),s},K=async(t=!1)=>{let r=`${e.url}/graview/state?opFormat=${Ie.op}`,s=t?await d(r,{headers:l}):await q(r,{headers:l});if(!s.ok)throw new Error((await s.json().catch(()=>({}))).error??`The server refused (${s.status})`);return await s.json()},x=e.state??await K(!0);p||(T="online"),S=typeof x.held=="string"&&x.held.length>0?x.held:void 0,D();let de=x.enabledModules??e.enabledModules,$=e.localApp?e.localApp(e.app):e.app,O=new yn({schema:$.schema,mutations:$.mutations??[],invariants:$.invariants??[],...$.policy?{policy:$.policy}:{},...$.modules?{modules:$.modules}:{},...de?{enabledModules:de}:{},...$.intelligence?{intelligence:$.intelligence}:{},...$.brand?.timeZone?{timeZone:$.brand.timeZone}:{},snapshot:x.snapshot,log:x.log,...x.horizon!==void 0?{horizon:x.horizon}:{},ids:To(),...e.storeOptions??{}});pn.served.add(O);let Pe=mn(O),k=x.log.at(-1)?.seq??(x.horizon??0)-1,te=At.of(x.log,{horizon:x.horizon??0}),R=null,J,B=new Map,ce=a.who,we=!1,W=t=>{if(se)return;we=!0;let r=vn(new Map,t,Date.now(),1e4,R?.participant);J!==void 0&&r.delete(J);let s=r.size!==B.size;if(!s)for(let[i,f]of r)xt(f,B.get(i))||(s=!0);if(B=r,!!s)for(let i of[...ce])i([...B.values()])},z=[],I=new Set,le=t=>{let r=z.indexOf(t);r>=0&&z.splice(r,1)},L=new Map,ke=(t,r)=>{let s=L.get(t);s&&(L.delete(t),s.resolve({ops:r.filter(i=>i.batch===t),batch:t}))},Y,X=[],M=(t,r=[])=>{if(t.length===0&&r.length===0)return[];if(Y)return X.push({ops:t,drop:r}),[];let s=Math.min(...t.filter(w=>w.seq>k).map(w=>w.seq));if(Number.isFinite(s)&&s>k+1)return X.push({ops:t,drop:r}),Ee(),[];let i=z.filter(w=>t.some($e=>$e.batch===w)),f=[...new Set([...r,...i])].filter(w=>I.has(w)),y,H=z.filter(w=>!i.includes(w));try{y=O.rebase({confirmed:t,pending:H,drop:f}).confirmed}catch(w){if(!(w instanceof hn))throw w;return X.push({ops:t,drop:r}),Ee(),[]}for(let w of i)le(w);t.some(w=>w.seq>k)&&H.some(w=>!f.includes(w))&&P.rebases++,t.length>0&&(k=Math.max(k,...t.map(w=>w.seq)),te.note(t));for(let w of f)I.delete(w);for(let w of i)ke(w,t);return y},Ee=()=>{Y||(Y=oe(K().then(t=>{if(ue(t)){X=[];return}let r=new Set(t.log.map(f=>f.batch)),s=z.filter(f=>r.has(f));for(let f of s)le(f);let i=O.adopt({snapshot:t.snapshot,log:t.log,...t.horizon!==void 0?{horizon:t.horizon}:{},pending:[...z],drop:[...I].filter(f=>!z.includes(f))});I.clear();for(let f of i.pending)I.add(f.batch);k=t.log.at(-1)?.seq??(t.horizon??0)-1,te=At.of(t.log,{horizon:t.horizon??0}),P.resyncs++;for(let f of s)ke(f,t.log)}).then(()=>{Y=void 0;let t=X;X=[];for(let{ops:r,drop:s}of t)M(r,s)},()=>{Y=void 0,X=[]})))},ue=t=>(typeof t.build=="string"&&en(t.build),typeof t.version=="number"&&u(t.held),typeof t.version!="number"||t.version===x.version?!1:(vt(t.version),!0)),re=async t=>{let s=await(await q(`${e.url}/graview/since?seq=${t}&opFormat=${Ie.op}`,{headers:l})).json();return ue(s)?[]:s.ops??[]},Q=async()=>{let t=await ze();return Y&&await Y,t},ze=async()=>{if(R&&!_()&&A()){let r=await(await q(`${e.url}/graview/here`,{method:"POST",headers:l,body:JSON.stringify({presence:R,seq:k})})).json();return ue(r)?[]:(typeof r.participant=="string"&&(J=r.participant),W(r.who??[]),M(r.ops??[]))}return M(await re(k))},Ae=new Map,E=new Map,Re=new Map,fe=new Set,oe=t=>(fe.add(t),t.finally(()=>fe.delete(t)).catch(()=>{}),t),He=Promise.resolve(),Te=0,pt=(t,r)=>{let s=He.then(()=>ht(t,r));return He=s.catch(()=>{}),s},mt=()=>new Promise((t,r)=>C.push({again:t,give:r})),ht=async(t,r)=>{let s,i;for(;;){try{s=await q(`${e.url}/graview/ops`,{method:"POST",headers:l,body:JSON.stringify({...t,opFormat:Ie.op})})}catch(w){if(!(w instanceof qe)||U)throw w;if(await mt(),_())return Ke(t,r);continue}if(i=await s.json().catch(()=>({})),s.status===503&&i.reason==="unavailable"&&typeof i.held=="string"&&!U){if(typeof i.version=="number"?ue(i):(u(i.held),!1))break;if(S!==void 0&&(Pt>0||p)){if(await new Promise(w=>N.push(w)),U)throw new Ve("The client closed.");if(_())return Ke(t,r);continue}}let H;if(s.status===503&&i.reason==="unavailable"&&!U)H=Jt(e.backoff,Te++);else{if(Te=0,s.status!==429||U)break;H=Oo(s.headers.get("retry-after"),i.retryAfter)}if(await new Promise(w=>setTimeout(w,H)),_())return Ke(t,r)}if(se||ue(i))throw new Ve("The app was changed.");if(!s.ok){let H=i.error??`The server refused (${s.status})`;throw i.conflict?new Ce(H,i.conflicts??[]):new De({reason:i.reason??Eo[s.status]??"invalid",sentence:H,...i.wouldNeed?.length?{wouldNeed:i.wouldNeed}:{}})}let f=i.ops??[],y=f[0]?.seq;return y!==void 0&&y>k+1&&(f=await re(k)),r!==void 0&&(i.batch&&Ae.set(r,i.batch),le(r)),M(f,r!==void 0?[r]:[]),{ops:i.ops??[],...i.batch?{batch:i.batch}:{}}},G,ee=!1,U=!1,Be=0,pe,Ge=0,We=0,ae=null,Le=()=>{},xe=new Promise(t=>{Le=t}),_=()=>p&&ee&&G?.readyState===xo,ie=t=>{if(!_())return!1;try{return G.send(JSON.stringify(t)),!0}catch{return!1}},Ue=(t=!1)=>{!R||!_()||!A()||!t&&ae&&xt(R,ae)&&(g===void 0||Date.now()-We<g)||ie({t:"here",presence:R})&&(ae=R,We=Date.now())},m=new Set,F,me=()=>{if(F=void 0,S!==void 0)return;let t=[...L.entries()].filter(([r])=>m.has(r));m.clear();for(let[,r]of t)ie(r.message)},Xt=(t,r)=>{L.has(t)&&(m.add(t),F&&clearTimeout(F),F=setTimeout(me,Math.max(0,r)))},Vr=t=>{L.has(t)&&m.add(t)},Ke=(t,r)=>new Promise((s,i)=>{let f=r??`send-${++Ge}`,y=t.undo?{t:"undo",cid:f,batches:t.undo,...t.intent?{intent:t.intent}:{},...t.batch?{batch:t.batch}:{},...t.via?{via:t.via}:{},...Se(t)}:{t:"call",cid:f,calls:t.calls??[],...t.intent?{intent:t.intent}:{},...t.batch?{batch:t.batch}:{},...t.base?.length?{base:t.base}:{},...t.via?{via:t.via}:{},...Se(t)};if(L.set(f,{message:y,...r!==void 0?{mine:r}:{},resolve:s,reject:i}),m.size>0||S!==void 0){m.add(f);return}ie(y)}),yt=(t,r)=>_()?Ke(t,r):pt(t,r),Dr=t=>{switch(t.t){case"welcome":{if(en(t.build),typeof t.version=="number"&&t.version!==x.version){vt(t.version);return}if(ee=!0,Be=0,typeof t.participant=="string"&&(J=t.participant),u(t.held),M(t.ops??[]),m.clear(),F&&clearTimeout(F),F=void 0,S!==void 0)for(let r of L.keys())m.add(r);else for(let r of L.values())ie(r.message);Ue(!0),Z("online"),Le();return}case"ops":M(t.ops??[]);return;case"ack":{let r=L.get(t.cid);if(!r){M(t.ops??[]);return}L.delete(t.cid),Te=0,r.mine!==void 0&&(Ae.set(r.mine,t.batch),le(r.mine)),M(t.ops??[],r.mine!==void 0?[r.mine]:[]),r.resolve({ops:t.ops??[],batch:t.batch});return}case"refused":case"conflict":{let r=L.get(t.cid);if(!r)return;if(t.t==="refused"&&t.reason==="unavailable"){S!==void 0?Vr(t.cid):Xt(t.cid,Jt(e.backoff,Te++));return}L.delete(t.cid),r.reject(t.t==="conflict"?new Ce(t.sentence,t.conflicts??[]):new De({reason:t.reason??"invalid",sentence:t.sentence,...t.wouldNeed?.length?{wouldNeed:[...t.wouldNeed]}:{}}));return}case"busy":typeof t.cid=="string"&&Xt(t.cid,typeof t.retryAfter=="number"?t.retryAfter:1e3);return;case"presence":W(t.who??[]);return;case"held":u(t.sentence);return;case"declaration":typeof t.version=="number"&&t.version!==x.version&&vt(t.version);return;case"reload":on(typeof t.reason=="string"?t.reason:"This app was updated.");return;case"error":if(t.reopen===!0&&G){let r=G;sn(r);try{r.close(1e3,"Opening again.")}catch{}}return;default:return}},se=!1,gt=a.declarations,wt=a.builds,en=t=>{if(!(se||a.otherBuild!==void 0||!e.build||typeof t!="string"||t.length===0||t===e.build)){a.otherBuild=t;for(let r of[...wt])r(t)}},tn=()=>{let t=[],r=0;for(let s of z){let i=Re.get(s);i?t.push({calls:i.calls,...i.intent?{intent:i.intent}:{},...i.via?{via:i.via}:{},...Se(i),batch:s}):r++}return{carried:t,undos:r}},nn=(t,r)=>`${r} while ${t===1?"an undo of yours was":"undos of yours were"} on the way; ${t===1?"it was":"they were"} not made.`,rn=t=>{se=!0,R=null;let r=new Ve(t);for(let i of L.values())i.reject(r);L.clear(),Qe&&clearInterval(Qe),U=!0,pe&&clearTimeout(pe),F&&clearTimeout(F),he&&clearTimeout(he);for(let i of C.splice(0))i.give(r);for(let i of N.splice(0))i();let s=G;G=void 0,ee=!1;try{s?.close(1e3,t)}catch{}Le()};async function vt(t){if(se)return;if(!e.resolveApp){on(`This app was changed on its server (version ${t}); reload the page to carry on.`);return}let{carried:r,undos:s}=tn(),i=e.resolveApp,f=R;rn("The app was changed.");try{let y=await i(t),{state:H,...w}=e,$e=await Cr({...w,app:y},r,"The app was changed while your changes were on the way.",a);f&&$e.remote.presence.here(f);for(let Ze of[...gt])Ze($e.remote,t);let _r=[...s>0?[Je(nn(s,"The app was changed"))]:[],...$e.unheard()];for(let Ze of _r)for(let jr of Me)jr(Ze.sentence,Ze)}catch(y){let H=`The app was changed, but the new version could not be opened: ${y instanceof Error?y.message:String(y)}`;for(let w of Me)w(H,Je(H))}}function on(t){if(se)return;let{carried:r,undos:s}=tn();rn(t);let i=!1;if(e.carry&&r.length>0)try{e.carry.storage.setItem(e.carry.key,JSON.stringify(r)),i=!0}catch{}let f=[];!i&&r.length>0&&f.push(`${t} ${r.length===1?"A change of yours was":`${r.length} changes of yours were`} not sent; make ${r.length===1?"it":"them"} again after the page reloads.`),s>0&&f.push(nn(s,"This app was updated"));for(let y of f)for(let H of Me)H(y,Je(y));(e.reloadPage??Co)()}let an=()=>{if(U||!p)return;let t=`${e.url.replace(/^http/,"ws").replace(/\/$/,"")}${Fr}`,{"content-type":r,...s}=l,i;try{i=e.socket?e.socket(t,s,[Kt]):Ir(t,s)}catch{return dn()}G=i,ee=!1,i.onopen=()=>{G===i&&i.send(JSON.stringify({t:"hello",seq:k,protocol:Xe,wire:Ut,opFormat:Ie.op,...e.build?{build:e.build.slice(0,64)}:{},...e.hostProtocol!==void 0?{hostProtocol:e.hostProtocol}:{}}))},i.onmessage=f=>{if(G!==i)return;let y;try{y=JSON.parse(String(f.data))}catch{return}Dr(y)},i.onclose=()=>sn(i),i.onerror=()=>{}},he,Hr=()=>{we=!1,he&&clearTimeout(he),he=setTimeout(()=>{if(he=void 0,we||U)return;let t=new Map([...B].filter(([,r])=>r.held!=="socket"));if(t.size!==B.size){B=t;for(let r of ce)r([...B.values()])}},1e4),he.unref?.()};function sn(t){if(G!==t)return;let r=ee;G=void 0,ee=!1,ae=null,r&&(Z("offline"),Hr()),dn()}let dn=()=>{if(U)return;let t=Jt(e.backoff,Be);Be++,pe=setTimeout(an,t)},Br=O.applyAll.bind(O),Wr=O.undo.bind(O),Nr=O.previewAll.bind(O);O.previewAll=(t,r)=>Nr(t,{...e.principal?{author:e.principal}:{},...r});let Me=a.refusals,Ne=[],Je=t=>({reason:"invalid",sentence:t}),Ye=a.conflicts,bt=!1,cn=async(t,r)=>{if(r instanceof Ve||se)return;let s=r instanceof De?r.refusal:un(r),i=s.sentence;le(t);try{M([],[t])}catch{}let f=Re.get(t);if(Re.delete(t),r instanceof Ce&&P.conflicts++,r instanceof Ce&&!_()&&await Q().catch(()=>[]),r instanceof Ce&&Ye.size>0){let y=!1,H={sentence:i,conflicts:r.conflicts,keepTheirs(){y=!0},useMine(){if(!(y||!f)){y=!0,bt=!0;try{O.applyAll(f.calls,{...f.intent?{intent:f.intent}:{},...f.via?{via:f.via}:{},...Se(f)})}finally{bt=!1}}}};for(let w of Ye)w(H);return}for(let y of Me)y(i,s)};O.applyAll=(t,r)=>{let s=fn(O.log.all().filter(y=>I.has(y.batch))),i=Br(t,{...e.principal?{author:e.principal}:{},...r});z.push(i.batch),I.add(i.batch),Re.set(i.batch,{calls:t,...r?.intent?{intent:r.intent}:{},...r?.via?{via:r.via}:{},...Se(r)});let f=bt?[]:te.baseFor(i.ops,s);return E.set(i.batch,oe(yt({calls:t,...r?.intent?{intent:r.intent}:{},batch:i.batch,...f.length>0?{base:f}:{},...r?.via?{via:r.via}:{},...Se(r)},i.batch).catch(y=>cn(i.batch,y)))),i},O.apply=(t,r)=>O.applyAll([t],r),O.undo=(t,r)=>{let s=typeof t=="string"?[t]:t,i=Wr(s.map(y=>Ae.get(y)??y),{...e.principal?{author:e.principal}:{},...r});z.push(i.batch),I.add(i.batch);let f=Promise.allSettled(s.map(y=>E.get(y)));return E.set(i.batch,oe(f.then(()=>yt({undo:s.map(y=>Ae.get(y)??y),...r?.intent?{intent:r.intent}:{},batch:i.batch,...r?.via?{via:r.via}:{},...Se(r)},i.batch)).catch(y=>cn(i.batch,y)))),i};let $r=async(t,r={})=>{St++;try{return(await oe(yt({calls:t,...r}))).ops}finally{St--}},St=0,ln={here(t){R=t,Ue()},onWho(t){return ce.add(t),B.size>0&&t([...B.values()]),()=>{ce.delete(t)}},leave(){if(!R)return;let t=JSON.stringify({participant:J??R.participant});if(R=null,ie({t:"bye"}))return;let r=globalThis.navigator?.sendBeacon;r?r.call(globalThis.navigator,`${e.url}/graview/leave`,t):d(`${e.url}/graview/leave`,{method:"POST",headers:l,body:t}).catch(()=>{})}},Pt=e.pollMs??800,Qe=Pt>0&&typeof setInterval=="function"?setInterval(()=>{_()||Q().catch(()=>{})},Pt):null;if(p){an();let t;await Promise.race([xe,new Promise(r=>t=setTimeout(r,e.openTimeoutMs??3e3))]),clearTimeout(t)}if(n.length>0&&!se){let t=[],r=new Set(O.log.all().map(s=>s.batch));for(let s of n)if(!(s.batch!==void 0&&r.has(s.batch)))try{O.applyAll(s.calls,{...s.intent?{intent:s.intent}:{},...s.batch?{batch:s.batch}:{},...s.via?{via:s.via}:{},...Se(s)})}catch(i){t.push(Po(s,i))}t.length>0&&Ne.push(Je(`${o} ${t.length===1?"One no longer fits and was not made":`${t.length} no longer fit and were not made`}: ${t.join("; ")}.`))}return{remote:{store:O,version:x.version,migrated:x.migrated??[],send:$r,pull:Q,onRefusal(t){Me.add(t);let r=Ne;Ne=[];for(let s of r)t(s.sentence,s);return()=>Me.delete(t)},onDeclaration(t){return gt.add(t),()=>gt.delete(t)},onBuild(t){return wt.add(t),a.otherBuild!==void 0&&t(a.otherBuild),()=>wt.delete(t)},onConflict(t){return Ye.add(t),()=>Ye.delete(t)},revision:(t,r)=>te.of(t,r),seq:()=>k,participant:()=>J,transport:()=>_()?"socket":"poll",status:ne,onStatus(t){return v.add(t),()=>v.delete(t)},held:()=>S,onHeld(t){return a.helds.add(t),S!==void 0&&t(S),()=>a.helds.delete(t)},counters:()=>({...P}),who:()=>[...B.values()],pending:()=>z.length+St,async settled(){for(;fe.size>0;)await Promise.allSettled([...fe])},presence:ln,close(){Qe&&clearInterval(Qe),Pe(),ln.leave(),U=!0,pe&&clearTimeout(pe),F&&clearTimeout(F),he&&clearTimeout(he);for(let r of C.splice(0))r.give(new Error("The client closed before the server could be reached."));for(let r of N.splice(0))r();let t=G;G=void 0,ee=!1;try{t?.close(1e3,"Closed.")}catch{}}},unheard(){let t=Ne;return Ne=[],t}};function Ir(t,r){let s=globalThis.WebSocket;if(!s)throw new Error("This runtime has no WebSocket; the client polls instead.");let i=typeof globalThis.document<"u",f=e.subprotocol?[Kt]:[];if(!i)try{return new s(t,{headers:r,...f.length>0?{protocols:f}:{}})}catch{}let y=new URL(t);for(let[H,w]of Object.entries(b))y.searchParams.set(H,w);return f.length>0?new s(y.toString(),f):new s(y.toString())}}function Oo(e,n,o=Date.now()){let a,d=e?.trim();if(d)if(/^\d+(\.\d+)?$/.test(d))a=Number(d)*1e3;else{let p=Date.parse(d);Number.isFinite(p)&&(a=Math.max(0,p-o))}let l=typeof n=="number"&&Number.isFinite(n)&&n>=0?n:void 0,b=l!==void 0&&l<50&&a!==void 0&&Math.abs(l*1e3-a)<1e3;return l!==void 0&&!b?l:a??1e3}function Co(){globalThis.location?.reload?.()}function Lo(){return globalThis.document?.visibilityState!=="hidden"}function Jt(e,n){if(typeof e=="function")return Math.max(0,e(n));let{min:o=250,max:a=1e4,factor:d=2}=e??{};return Math.min(a,o*d**n)*(.75+Math.random()*.5)}function ft(e){let n={};if(!e)return n;e.id&&(n[ge.seat]=e.id),e.roles?.length&&(n[ge.roles]=e.roles.join(",")),e.kind!=="human"&&(n[ge.kind]=e.kind),e.name&&(n[ge.name]=encodeURIComponent(e.name));let o=e.onBehalfOf;return o?.id&&(n[ge.for]=o.id),o?.roles?.length&&(n[ge.forRoles]=o.roles.join(",")),o?.name&&(n[ge.forName]=encodeURIComponent(o.name)),n}var Lr="/graview/views";function Yt(e){let n=e.fetch??fetch,o=e.url.replace(/\/$/,""),a={"content-type":"application/json",...e.principal?ft(e.principal):{},...e.headers??{}},d=e.state?{hidden:e.state.hidden??[],removed:e.state.removed??[],may:e.state.may??et.may}:et,l=new Set,b=v=>{if(JSON.stringify(v)!==JSON.stringify(d)){d=v;for(let P of l)P()}},p=async(v,P)=>{let C=await n(`${o}${e.path??Lr}`,{method:v,headers:a,...P!==void 0?{body:JSON.stringify(P)}:{}}),S=await C.json();if(!C.ok)throw new Error(S.error??`The store answered ${C.status}.`);b({hidden:S.hidden??[],removed:S.removed??[],may:S.may??et.may})},g=()=>p("GET"),A=e.state?Promise.resolve():g().catch(()=>{}),T=e.pollMs?setInterval(()=>void g().catch(()=>{}),e.pollMs):void 0;return{ready:A,refresh:g,close:()=>clearInterval(T),current:()=>d,onChange(v){return l.add(v),()=>void l.delete(v)},hide:v=>p("POST",{hide:v}),show:v=>p("POST",{show:v}),remove:(v,P)=>p("POST",{remove:v,...P?{about:P}:{}}),async restore(v){let P=d.removed.find(C=>C.name===v)?.lens;await p("POST",{restore:v}),P&&await e.onDeclaration?.()},async lens(v){await p("POST",{lens:v}),await e.onDeclaration?.()}}}var Zt=document.getElementById("graview-app"),Qt=/^\/forms\/([^/]+)\/?$/.exec(location.pathname),Mr=Qt?(__graviewPreload(import.meta.url,["./chunk.QWX2N2VD.js","./chunk.VSWEKNKS.js","./chunk.UGFDSE37.js","./chunk.SGJSJGSR.js","./chunk.2OXXGN7C.js","./chunk.Q4KNNJFL.js","./chunk.BH365UJ5.js","./chunk.6EHE26ZS.js","./chunk.N2S3TMBC.js","./chunk.7JW5SHRR.js","./chunk.4SEY7VWZ.js","./chunk.IVHPJUFM.js","./chunk.D53IGR45.js","./chunk.MJ4XTNTL.js","./chunk.AP22NNIM.js","./chunk.SPZVEQC5.js","./chunk.FNK2ZZ5E.js","./chunk.RSR2M7ZO.js","./chunk.EM5CGFNB.js","./chunk.N2S45SSL.js","./chunk.AGVFW6WC.js","./chunk.SIVMZNHZ.js","./chunk.XOZU4OFA.js","./chunk.35FUGOSG.js","./chunk.MB7LKKUD.js","./chunk.YECMUK4X.js","./chunk.2OLZ6BYI.js","./chunk.WVUJXDXZ.js","./chunk.NQDGUIUQ.js","./chunk.DTRNDSMS.js","./chunk.3EW6L5DY.js","./chunk.AVDXG57A.js","./chunk.LD6S2FL5.js","./chunk.TABIRLQS.js","./chunk.GZHZLJBF.js","./chunk.FOYVTN5B.js","./chunk.OJGHDWI6.js","./chunk.OTF3NNTI.js","./chunk.A7HMVWMG.js","./chunk.GRLPNTUW.js","./chunk.EJAVIZ7Y.js","./chunk.423SZS7C.js","./chunk.TM6JVVGW.js","./chunk.SDO3U72B.js","./chunk.PFEKS3KO.js","./chunk.2AZTW66C.js","./chunk.AJZBJBMO.js"]),import("./chunk.5YFO6D7J.js")):Oe("pages");try{Qt?await Mo(decodeURIComponent(Qt[1])):await Vo()}catch(e){let n=document.createElement("pre");n.setAttribute("role","alert"),n.style.cssText="margin:2rem;font:14px/1.5 ui-monospace,monospace;white-space:pre-wrap",n.textContent=e instanceof Error?e.message:String(e),Zt.replaceChildren(n),window.__graviewFailed=n.textContent}async function Mo(e){let n=await fetch(`/graview/document?form=${encodeURIComponent(e)}`),o=await n.json();if(!n.ok)throw new Error(o.error??`The preview server did not hand over the form (${n.status}).`);let a=await it(o);if(!a.ok)throw new Error(tt(a.findings));let d=a.app,l=o.principal,b=await ut({app:d,url:location.origin,principal:l,...o.state?{state:o.state,openTimeoutMs:0}:{openTimeoutMs:3e3}});document.title=d.forms?.[e]?.title??d.name;let{mount:p}=await Mr;window.__graview=p(Zt,{app:d,form:e,principal:l,remote:b,height:"100dvh",onSubmitted:()=>window.__graviewSubmitted=!0}),window.__graviewReady=!0}async function Vo(){let e=await fetch("/graview/document");if(!e.ok)throw new Error(`The preview server did not hand over the document (${e.status}).`);let n=await e.json(),a=await(async g=>{if(typeof g.module=="string")return(await import(g.module)).app;let A=await it(g);if(!A.ok)throw new Error(tt(A.findings));return A.app})(n);if(!a||typeof a!="object"||!("schema"in a))throw new Error("The app module the preview server handed does not export an app.");let d=n.principal,l=await ut({app:a,url:location.origin,principal:d,live:!0,subprotocol:!0,pollMs:1200,...n.state?{state:n.state,openTimeoutMs:0}:{openTimeoutMs:3e3}});document.title=a.name;let b,p=Yt({url:location.origin,principal:d,...n.views?{state:n.views}:{},onDeclaration:async()=>{let g=await(await fetch("/graview/document")).json();if(typeof g.module=="string")return;let A=await it(g);A.ok&&b?.setApp(A.app,l)}});await Promise.all([Mr,p.ready]),b=Gt(Zt,{app:a,remote:l,principal:d,studio:!1,face:"pages",routing:"address",bar:!0,height:"100dvh",label:a.name,heading:1,keptViews:p,...n.draftView?{draftView:n.draftView}:{}}),window.__graview=b,b.drawn().then(()=>{window.__graviewReady=!0})}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graview",
3
- "version": "0.1.48",
3
+ "version": "0.1.49",
4
4
  "type": "module",
5
5
  "description": "The Graview command line: start a product, check its declaration, write its agent docs, serve its store, preview a document with no product and photograph its places, say whether a product is on one release, host it for an agent over MCP, apply an act to it, sync its seed, install the authoring skills. The tool; @graview/* is the framework.",
6
6
  "keywords": [
@@ -29,11 +29,11 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@graview/core": "0.1.48",
33
- "@graview/skills": "0.1.48",
34
- "@graview/guest": "0.1.48",
35
- "@graview/tools": "0.1.48",
36
- "@graview/ship": "0.1.48"
32
+ "@graview/core": "0.1.49",
33
+ "@graview/ship": "0.1.49",
34
+ "@graview/skills": "0.1.49",
35
+ "@graview/tools": "0.1.49",
36
+ "@graview/guest": "0.1.49"
37
37
  },
38
38
  "engines": {
39
39
  "node": ">=22"
@@ -1 +0,0 @@
1
- import{a as Se,b as Ke,c as Me,d as le,e as R,f as pe,h as Te}from"./chunk.HG4DDNPG.js";import{h as Ge,i as Ce,j as _e}from"./chunk.X7JMJSLU.js";import{a as oe,b as se,c as H,d as Pe,e as Y,g as ee,h as Ne}from"./chunk.5Y3Q7ONN.js";import{c as Fe,h as z,i as De,j as de}from"./chunk.KTFUVR4V.js";import{A as xe,Aa as Ee,Ha as Ae,Ia as Q,Ja as ae,Mb as ce,Nb as Re,b as U,c as B,e as je,f as Oe,g as q,h as O,k as C,l as J,m as _,n as ve,o as L,p as K,r as $,s as X,t as x,u as E,v as V,w as T,x as n,y as M,z as W}from"./chunk.4TJOS4C7.js";var rn=e=>Object.entries(e).map(([s,r])=>[s,Object.keys(Q(r?.edges))]),fe=(e,s)=>Re(e,rn(s));var ge="graview-document",ze=1,ye=256*1024,ne=64*1024,ue=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,me=/^[a-z][A-Za-z0-9]*$/,an=new Set(["id","kind"]),cn=/^(?:[a-z][a-z0-9]*(?:-[a-z0-9]+)*|[a-z][A-Za-z0-9]*)$/,dn=["string","text","number","integer","boolean","date","datetime","enum","list","url","email","image","video","file","app-link","phone","place","duration"];function ln(){let e=k=>k in Object.prototype,s=W(k=>!e(k),"every object already has this name \u2014 choose another"),r=(k,N)=>[...k===void 0?[]:[Oe(k)],...N===void 0?[]:[je(N)]],t=(k,N)=>O().check(...r(k,N)),a=(k,N,sn)=>K(k).check(...r(N,sn)),d=k=>O().check(q(ue,`${k} names are kebab-case, lower-case words joined by hyphens like "tool-note" (field and relation names are camelCase, like "supersededBy")`)),u=O().check(q(cn,'relation names are one camelCase word, like "supersededBy" (kind names are kebab-case, like "tool-note")'),s),f=O().check(q(me,'field names are one word or camelCase, like "dueDate", so rules say them bare (kind names are kebab-case, like "tool-note")'),W(k=>!an.has(k),'a field cannot be called "id" or "kind" \u2014 the framework keeps those; try "type" or "category"'),s),h=t(1,500),i=t(1,2e3),o=t(1,300),p=$({type:V(dn),required:n(_()),description:n(h),label:n(t(1,60)),options:n(a(t(1,80),1,100)),of:n(V(["string","number","date","image","video","file"])),default:n(L()),unit:n(t(void 0,12)),format:n(V(["money","percent","duration","markdown"])),min:n(C()),max:n(C()),step:n(C()),renamedFrom:n(O().check(q(me))),repeats:n(_())}).check(xe((k,N)=>{k.type==="enum"&&!k.options&&N.addIssue({code:"custom",message:'an enum field lists its "options"',path:["options"]}),k.type!=="enum"&&k.options&&N.addIssue({code:"custom",message:'"options" belongs only on an enum field',path:["options"]}),k.type!=="list"&&k.of&&N.addIssue({code:"custom",message:'"of" belongs only on a list field',path:["of"]}),k.repeats&&k.type!=="date"&&k.type!=="datetime"&&N.addIssue({code:"custom",message:'"repeats" belongs only on a date or datetime field',path:["repeats"]})})),w=O().check(q(new RegExp(`${ue.source}|${Ee.source}`),'a relation goes to a kind of this document, like "house", or of another app, like "@nick/house/house"')),m=$({to:x([a(w,1),T("*")]),cardinality:n(V(["one","many"])),description:n(h),inverse:n(t(1,80)),appendOnly:n(_()),renamedFrom:n(O()),tidying:n(T("never"))}),l=x([i,$({expr:i,label:n(t(1,60)),description:n(h)})]),c=$({noun:n(t(1,40)),plural:n(t(1,40)),description:n(h),fields:E(f,p).check(W(k=>Object.keys(k).length>0,"a kind has at least one field")),label:n(o),describe:n(o),lifecycle:n($({field:f,retired:a(x([O(),C(),_()]),1)})),figure:n(t(void 0,2e4)),glance:n(a(f,1,20)),page:n($({fields:n(a(f,1,40)),groups:n(a($({title:t(1,60),fields:a(f,1,40)}),1,12))})),edges:n(E(u,m)),computed:n(E(O(),l).check(W(k=>Object.keys(k).length<=20,"a kind works out at most 20 computed fields"))),fieldRoles:n(E(O(),O())),renamedFrom:n(O().check(q(ue))),people:n(_()),archives:n(T(!1)),tidying:n(V(["never","no-links"]))}),j=x([O(),C(),_(),ve(),K(L()),$({expr:i})]),y=O().check(q(/^\$[A-Za-z][A-Za-z0-9]*$/,'a reference is "$" and a name, like "$subject" or "$new"')),S=x([$({create:d("kind"),as:n(O().check(q(me))),set:n(E(f,j))}),$({set:E(f,j),target:n(y)}),$({connect:u,from:y,to:y}),$({sever:u,from:y,to:y}),$({remove:y})]),A=$({title:n(t(1,80)),description:n(h),fromTheOtherEnd:n(t(1,80)),on:n(x([d("kind"),a(d("kind"),1)])),creates:n(d("kind")),sets:n(E(f,j)),writes:n(a(f,1)),connects:n(u),severs:n(u),setsOther:n(E(f,j)),replaces:n(x([T(!0),a(u,1,10)])),removes:n(T(!0)),args:n(E(f,p)),effects:n(a(S,1,20)),allowedWhen:n(i),refusal:n(o),destructive:n(_())}),b=$({act:d("act"),label:n(t(1,80)),args:n(E(O(),j))}),G=$({title:n(t(1,120)),description:n(h),over:x([T("graph"),d("kind")]),when:n(i),require:i,says:n(o),repairs:n(a(b,void 0,10))}),F=$({roles:x([a(d("role"),1),T("*")]),mutations:x([a(d("act"),1),T("*")]),kinds:n(x([K(d("kind")),T("*")])),describe:n(h),self:n(_()),ownEnd:n(_())}),g=n(a(d("field"),1)),v=$({roles:x([a(d("role"),1),T("*")]),kinds:a(d("kind"),1),own:n(_()),via:n(u),fields:g,hide:g}),D=$({grants:K(F),sees:n(K(v))}),te=$({accent:n(O().check(q(/^#[0-9a-fA-F]{6}$/,'an accent is a color like "#c2577a"'))),name:n(t(1,60)),currency:n(O().check(q(/^[A-Z]{3}$/,'a currency is its three-letter code, like "USD" or "EUR"'))),locale:n(t(2,35)),timeZone:n(t(1,64)),logo:n(x([t(1,ne),$({src:t(1,ne),alt:n(t(1,120))}),$({light:t(1,ne),dark:n(t(1,ne)),alt:n(t(1,120)),darkFallback:n(T("invert"))})])),favicon:n(x([t(1,ne),$({emoji:O()})])),typography:n($({display:n(t(1,200)),body:n(t(1,200)),mono:n(t(1,200))})),shape:n($({radius:n(C().check(B(0),U(32))),density:n(C().check(B(.75),U(1.5)))})),accents:n(E(O(),C().check(B(0),U(360)))),scheme:n(V(["light","dark","auto"])),subtitle:n(T(!1))}),I=E(O(),L()),Z=x([t(1,120),$({by:t(1,120),direction:n(V(["asc","desc"]))})]),$e=C().check(J(),B(1),U(9999)),Xe=X({create:n(_()),options:n(X({sort:n(Z),columnSort:n(Z),search:n(a(t(1,120),void 0,40)),filters:n(a(t(1,120),void 0,40)),horizon:n(x([C().check(J(),B(1),U(200)),X({years:C().check(J(),B(1),U(200)),title:t(1,80),from:n($e),to:n($e)})]))}))}),Qe=$({card:n(K(L())),row:n(K(L())),page:n(K(L()))}),en=()=>{let k=n(V(["asc","desc"]));return x([t(1,120),$({by:t(1,120),direction:k,then:n(x([t(1,120),$({by:t(1,120),direction:k})]))})])},nn=()=>x([t(1,120),$({by:t(1,120),order:n(a(t(1,80),void 0,40)),closed:n(a(t(1,80),void 0,40))})]),we=X({order:n(K(O())),hide:n(K(O())),first:n(O()),primary:n(a(t(1,80),void 0,40)),scene:n(t(1,40)),pages:n(t(1,40)),lists:n(E(O(),$({filters:n(a(t(1,120),void 0,40)),sort:n(en()),group:n(nn())})))}),tn=$({act:d("act"),title:n(t(1,80)),intro:n(h),fields:n(a(f,1,40)),say:n(h),submit:n(t(1,80)),role:n(d("role"))}),on=$({$schema:n(O()),format:T(ge),formatVersion:T(ze),name:t(1,80),description:n(h),version:n(C().check(J(),B(1))),kinds:E(d("kind"),c).check(W(k=>Object.keys(k).length>0,"a document declares at least one kind"),W(k=>Object.keys(k).length<=40,"a document declares at most 40 kinds")),computed:n(E(O(),l)),acts:n(E(d("act"),A)),rules:n(E(d("rule"),G)),roles:n(K(d("role"))),policy:n(D),modules:n(I),lenses:n(K(Xe)),pages:n(we),views:n(E(O(),x([Qe,K(L())]))),brand:n(te),settings:n(K(I)),migrations:n(K(I)),connections:n(E(d("connection"),I)),forms:n(E(d("form"),tn))});return{FieldSpec:p,EdgeSpec:m,ComputedSpec:l,KindSpec:c,ValueSpec:j,EffectSpec:S,ActSpec:A,RepairSpec:b,RuleSpec:G,GrantSpec:F,SightSpec:v,PolicySpec:D,BrandSpec:te,PagesSpec:we,DocumentSpec:on}}var pn,P=()=>pn??=ln(),vn=M(()=>P().FieldSpec),xn=M(()=>P().EdgeSpec),En=M(()=>P().ComputedSpec),An=M(()=>P().KindSpec),Rn=M(()=>P().ValueSpec),Fn=M(()=>P().EffectSpec),Dn=M(()=>P().ActSpec),Kn=M(()=>P().RepairSpec),Mn=M(()=>P().RuleSpec),Tn=M(()=>P().GrantSpec),Pn=M(()=>P().SightSpec),Gn=M(()=>P().PolicySpec),Cn=M(()=>P().BrandSpec),_n=M(()=>P().PagesSpec),qe=M(()=>P().DocumentSpec);var fn={};function Ie(e,s=fn,r=ze){let{document:t,respelled:a}=Se(e),d=a.length>0?{respelled:a}:{};if(!t||typeof t!="object"||Array.isArray(t))return{document:t};let u=t;if(u.format!==ge||typeof u.formatVersion!="number"||u.formatVersion>=r)return{document:t,...d};let f=u.formatVersion,h=structuredClone(u);for(let i=f;i<r;i++){let o=s[i];if(!o)throw new Error(`there is no upgrade from format ${i} to ${i+1}`);h={...o(h),formatVersion:i+1}}return{document:h,from:f,...d}}function Ve(e,s,r){let t=Object.keys(e).filter(f=>e[f].edges?.[s]!==void 0);if(t.length===0)return;let a=t.map(f=>e[f].edges[s].to),d=a.some(f=>f==="*")?"*":[...new Set(a.flatMap(f=>f))];if(r.length===0||r.some(f=>t.includes(f)))return{reversed:!1,kinds:d};let u=t.filter(f=>{let h=e[f].edges[s].to;return h==="*"||r.every(i=>h.includes(i))});return u.length>0?{reversed:!0,kinds:u}:{reversed:!1,kinds:d}}var Ue=(e,s)=>{let r=e?.fields[s];return r!==void 0&&(r.type==="duration"||(r.type==="number"||r.type==="integer")&&r.format==="duration")};function Be(e,s,r,t){if(t==="out"){let a=e[s]?.edges?.[r]?.to;return a===void 0?[]:a==="*"?Object.keys(e):a}return Object.entries(e).filter(([,a])=>{let d=a.edges?.[r]?.to;return d!==void 0&&(d==="*"||d.includes(s))}).map(([a])=>a)}function he(e,s,r){if(r.t==="ident")return e[s]?.edges?.[r.name]?Be(e,s,r.name,"out"):void 0;if(r.t==="where")return he(e,s,r.set);if(r.t==="call"&&(r.fn==="out"||r.fn==="in")&&r.args[0]?.t==="lit"&&typeof r.args[0].value=="string")return Be(e,s,r.args[0].value,r.fn)}var Le=(e,s,r)=>{let t=s.filter(a=>e[a]?.fields[r]!==void 0);return t.length>0&&t.every(a=>Ue(e[a],r))};function We(e,s,r){let t=e.kinds,a=t[s],d=new Map(r),u=new Map,f=(i,o)=>{if(o>8)return!1;switch(i.t){case"ident":return Ue(a,i.name)||h(i.name,o+1);case"member":{let p=he(t,s,i.object);return p!==void 0&&Le(t,p,i.name)}case"call":{if(i.fn!=="sum"&&i.fn!=="min"&&i.fn!=="max")return!1;let[p,w]=i.args,m=p&&he(t,s,p);return m!==void 0&&w?.t==="ident"&&Le(t,m,w.name)}case"binary":return(i.op==="+"||i.op==="-")&&f(i.left,o)&&f(i.right,o);case"unary":return i.op==="-"&&f(i.operand,o);default:return!1}},h=(i,o)=>{if(a?.computed?.[i]===void 0)return!1;if(u.has(i))return u.get(i);u.set(i,!1);let p=d.get(i),w=p!==void 0&&f(p,o);return u.set(i,w),w};return r.map(([i])=>i).filter(i=>h(i,0))}function Ze(e,s,r=`kinds.${e}.page`){let t=s.page;if(!t)return[];let a=[],d=[...Object.keys(s.fields),...Object.keys(s.computed??{})],u=new Set,f=(i,o)=>{d.includes(i)?u.has(i)&&a.push(z("page-field-twice",o,`"${i}" is on ${e}'s page twice; name each field once`)):a.push(z("page-field",o,`${e}'s page is to show "${i}", and ${e} has no field or computed field called that`,`use one of: ${d.join(", ")}`)),u.add(i)};(t.fields??[]).forEach((i,o)=>f(i,`${r}.fields.${o}`));let h=new Set;return(t.groups??[]).forEach((i,o)=>{let p=i.title.trim().toLowerCase();h.has(p)&&a.push(z("page-group-twice",`${r}.groups.${o}.title`,`${e}'s page has two groups called "${i.title}"; give each its own title`)),h.add(p),i.fields.forEach((w,m)=>f(w,`${r}.groups.${o}.fields.${m}`))}),a}function He(e,s=[]){let r=Object.keys(e.fields),t=[...e.page?.fields??[],...(e.page?.groups??[]).flatMap(f=>f.fields)].filter(f=>Object.hasOwn(e.fields,f)),a=[...new Set([...t,...r])],d=f=>!!e.fields[f].required&&e.fields[f].default===void 0,u=s.filter(f=>Object.hasOwn(e.fields,f));return[...new Set([...u,...a.filter(d),...a])]}var un=new Set(["subject","now","today","me"]);function mn(e){if((typeof e=="string"?e:JSON.stringify(e??null)).length>ye)return{findings:[z("too-large","",`a document may be at most ${ye/1024} KB`)]};if(typeof e=="string")try{e=JSON.parse(e)}catch(t){return{findings:[z("not-json","",`this is not JSON: ${t.message}`)]}}try{e=Ie(e).document}catch(t){return{findings:[z("format","formatVersion",t.message)]}}let s=qe.safeParse(e);if(!s.success)return{findings:s.error.issues.map(t=>{let a=t.path.map(String).join(".");if(t.code==="unrecognized_keys")return z("unknown-key",a,`${t.keys.map(d=>`"${d}"`).join(", ")} ${t.keys.length===1?"is":"are"} not part of a Graview document here`,"check the spelling against docs/declaration-document.md");if(t.code==="invalid_union"&&/\.effects\.\d+$/.test(a))return z("effect-shape",a,"this effect is not one Graview knows",'an effect is one of {"create": kind, "as"?: name, "set"?: {field: value}}, {"set": {field: value, \u2026}, "target"?: "$ref"}, {"connect"|"sever": relation, "from": "$ref", "to": "$ref"}, {"remove": "$ref"}');if(t.code==="invalid_key"){let d=t.issues?.[0]?.message;return z("shape",a,`the name "${String(t.path.at(-1))}" is not allowed here${d?`: ${d}`:""}`)}return z("shape",a,t.message)})};let r=s.data;return{document:r,findings:gn(r)}}var re=e=>[e??[]].flat();function Ye(e){let s=new Map;for(let[r,t]of Object.entries(e.kinds))for(let[a,d]of Object.entries(Q(t.edges))){let u=s.get(a);s.set(a,{name:a,from:[...u?.from??[],r],to:d.to==="*"||u?.to==="*"?"*":[...new Set([...u?.to??[],...d.to])],cardinality:d.cardinality??"many"})}return s}function ut(e){let s=new Map;for(let[t,a]of Object.entries(e.kinds)){let d=ee(a),u=ae(a.edges);s.set(t,{fields:new Set([...Object.keys(a.fields),...u.keys()]),edges:new Map(Object.entries(Q(a.edges)).map(([f,h])=>[f,h.cardinality??"many"])),...d?{computed:d}:{},...u.size>0?{linked:u}:{}})}let r=ee(e);return r&&s.set(Fe,{computed:r}),s}function Je(e,s){let r=[],t=re(e.on),a=(d,u)=>{let f=Ve(s.kinds,d,t)?.reversed===!0,[h,i]=f?["$to","$subject"]:["$subject","$to"];return u==="connect"?{connect:d,from:h,to:i}:{sever:d,from:h,to:i}};if(e.creates){let d=s.kinds[e.creates],u={};for(let f of Object.keys(d?.fields??{}))u[f]=`$${f}`;for(let f of e.effects??[])"set"in f&&!("create"in f)&&R(f.target)==="new"&&Object.assign(u,f.set);r.push({create:e.creates,as:"new",set:u})}return e.sets&&r.push({set:e.sets}),e.writes&&!(e.creates&&e.on===void 0)&&r.push({set:Object.fromEntries(e.writes.map(d=>[d,`$${d}`]))}),e.connects&&(e.replaces&&r.push({replace:e.replaces===!0?[e.connects]:[...e.replaces],keep:e.connects}),r.push(a(e.connects,"connect"))),e.severs&&r.push(a(e.severs,"sever")),e.setsOther&&(e.connects||e.severs)&&r.push({set:e.setsOther,target:"$to"}),e.removes&&r.push({remove:"$subject"}),e.effects&&r.push(...e.effects.filter(d=>!(e.creates&&"set"in d&&!("create"in d)&&R(d.target)==="new"))),r}function be(e,s,r){try{let t=H(e),a=oe(t);for(let d of a.unknownFunctions)r.push(z("unknown-function",s,`"${d}" is not a function the rule language knows`,"see docs/declaration-document.md#expression-language"));return t}catch(t){if(t instanceof se){r.push(z("expression",s,t.sentence+` (at character ${t.at+1})`));return}throw t}}function ke(e,s,r){try{return Y(e)}catch(t){if(t instanceof Pe||t instanceof se){r.push(z("template",s,(t instanceof se,t.sentence)));return}throw t}}function gn(e){let s=[],r=new Set(Object.keys(e.kinds)),t=Ye(e),a=e.acts??{},d=new Set(e.roles??[]),u=(i,o)=>ae(e.kinds[i]?.edges).has(o),f=i=>Object.keys(e.kinds).some(o=>u(o,i));for(let[i,o]of Object.entries(e.kinds)){let p=`kinds.${i}`;for(let[m,l]of Object.entries(o.edges??{})){if(!Ae(l)&&l.to!=="*")for(let c of l.to)r.has(c)||s.push(z("edge-target",`${p}.edges.${m}.to`,`"${c}" is not a kind this document declares`));o.fields[m]&&s.push(z("edge-field-clash",`${p}.edges.${m}`,`"${m}" is both a field and a relation of ${i}`,"rename one of them"))}o.lifecycle&&!o.fields[o.lifecycle.field]&&s.push(z("lifecycle-field",`${p}.lifecycle.field`,`${i} has no field "${o.lifecycle.field}"`));let w=m=>o.computed!==void 0&&Object.hasOwn(o.computed,m);for(let m of o.glance??[])!o.fields[m]&&!w(m)&&s.push(z("glance-field",`${p}.glance`,`a glance at ${i} is to say "${m}", and ${i} has no field or computed field called that`,`use one of: ${[...Object.keys(o.fields),...Object.keys(o.computed??{})].join(", ")}`));s.push(...Ze(i,o));for(let m of["label","describe"]){let l=o[m];if(!l)continue;let c=ke(l,`${p}.${m}`,s);for(let j of c??[])if(j.expr){for(let y of oe(j.expr).names)if(!o.fields[y]){if(w(y)){Ne(o,y)||s.push(z("template-field",`${p}.${m}`,`${i}'s ${y} is worked out from beyond the record, and a ${m} is said with no graph to read`,`show it in a view instead, or name a computed field worked out from ${i}'s own fields`));continue}s.push(z("template-field",`${p}.${m}`,`${i} has no field "${y}" for its ${m} to show`,m==="label"?"a label can only show the record's own fields and what they work out":void 0))}}}for(let[m,l]of Object.entries(o.fields)){l.default!==void 0&&l.type==="enum"&&!l.options?.includes(String(l.default))&&s.push(z("default-option",`${p}.fields.${m}.default`,`"${String(l.default)}" is not one of ${m}'s options`));let c=`${m}Repeat`;l.repeats&&(o.fields[c]||o.edges?.[c]||o.computed?.[c])&&s.push(z("repeat-clash",`${p}.fields.${m}.repeats`,`${i} already has "${c}", where how ${m} repeats is kept`))}}for(let[i,o]of Object.entries(a)){let p=`acts.${i}`;for(let c of re(o.on))r.has(c)||s.push(z("act-kind",`${p}.on`,`"${c}" is not a kind this document declares`));let w=re(o.on),m=Je(o,e);if(o.creates&&o.on===void 0&&o.writes&&r.has(o.creates)){for(let c of o.writes)if(!e.kinds[o.creates].fields[c])if(e.kinds[o.creates].computed?.[c]!==void 0)s.push(z("computed-written",`${p}.writes`,`${o.creates}'s ${c} is worked out, not written: no act can set it`,"write the stored fields it is worked out from"));else{if(u(o.creates,c))continue;s.push(z("act-field",`${p}.writes`,`${o.creates} has no field "${c}"`))}}m.length===0&&s.push(z("act-empty",p,`"${i}" does nothing`,"give it effects or a shorthand such as sets or creates"));let l=new Map;m.forEach((c,j)=>{let y=m.length-(o.effects?.length??0),S=o.effects&&j>=y?`${p}.effects.${j-y}`:p;if("create"in c){if(!r.has(c.create))s.push(z("act-kind",`${S}.create`,`"${c.create}" is not a kind this document declares`));else for(let b of Object.keys(c.set??{}))e.kinds[c.create].fields[b]||(e.kinds[c.create].computed?.[b]!==void 0?s.push(z("computed-written",`${S}.set.${b}`,`${c.create}'s ${b} is worked out, not written: no act can set it`,"set the stored fields it is worked out from")):s.push(z("act-field",`${S}.set.${b}`,`${c.create} has no field "${b}"`)));c.as&&l.set(c.as,c.create)}else if("connect"in c||"sever"in c){let b="connect"in c?c.connect:c.sever;!t.has(b)&&!f(b)&&s.push(z("act-edge",`${S}.${"connect"in c?"connect":"sever"}`,`"${b}" is not a relation any kind declares`)),R(c.from)==="subject"&&w.length===0&&s.push(z("act-subject",`${p}.on`,`"${i}" acts on "$subject" but does not say which kinds it is "on"`))}else if("set"in c){let b=R(c.target??"$subject"),G=b==="subject"?w:l.has(b??"")?[l.get(b)]:[];b==="subject"&&w.length===0&&s.push(z("act-subject",`${p}.on`,`"${i}" changes "$subject" but does not say which kinds it is "on"`));for(let F of Object.keys(c.set))for(let g of G)if(!(!r.has(g)||e.kinds[g].fields[F]))if(e.kinds[g].computed?.[F]!==void 0)s.push(z("computed-written",`${S}.set.${F}`,`${g}'s ${F} is worked out, not written: no act can set it`,"set the stored fields it is worked out from"));else{if(u(g,F))continue;s.push(z("act-field",`${S}.set.${F}`,`${g} has no field "${F}"`))}}else"remove"in c&&R(c.remove)==="subject"&&w.length===0&&s.push(z("act-subject",`${p}.on`,`"${i}" removes "$subject" but does not say which kinds it is "on"`));("set"in c&&c.set?Object.values(c.set):[]).forEach(b=>{b&&typeof b=="object"&&!Array.isArray(b)&&"expr"in b&&be(b.expr,`${S}.set`,s)})}),o.allowedWhen&&be(o.allowedWhen,`${p}.allowedWhen`,s),o.refusal&&ke(o.refusal,`${p}.refusal`,s)}for(let[i,o]of Object.entries(e.rules??{})){let p=`rules.${i}`;o.over!=="graph"&&!r.has(o.over)&&s.push(z("rule-kind",`${p}.over`,`"${o.over}" is not a kind this document declares`));let w=o.over==="graph"?void 0:e.kinds[o.over];for(let m of["when","require"]){let l=o[m];if(!l)continue;let c=be(l,`${p}.${m}`,s);if(!c)continue;let j=oe(c);for(let y of j.names)if(o.over==="graph")s.push(z("rule-name",`${p}.${m}`,`"${y}" means nothing in a rule over the whole graph`,`name a kind in "over", or use all('kind')`));else if(w&&!w.fields[y]&&!w.edges?.[y]&&w.computed?.[y]===void 0){let S=Object.keys(w.edges??{}).find(A=>A.includes("-")&&A.split("-").includes(y));s.push(z("rule-name",`${p}.${m}`,`${o.over} has no field or relation called "${y}"`,S?`"${S}" reads as a subtraction in a rule; rename the relation to one camelCase word, like "${S.replace(/-([a-z0-9])/g,(A,b)=>b.toUpperCase())}"`:void 0))}for(let y of j.edges)!t.has(y)&&!f(y)&&s.push(z("rule-edge",`${p}.${m}`,`"${y}" is not a relation any kind declares`));for(let y of j.sweeps)r.has(y)?o.over!=="graph"&&s.push(De("rule-cost",`${p}.${m}`,`this rule looks at every ${y} for every ${o.over}, which grows slowly as the app grows`,"walk a relation with out()/in() instead of all() where you can")):s.push(z("rule-kind",`${p}.${m}`,`"${y}" is not a kind this document declares`))}o.says&&ke(o.says,`${p}.says`,s),(o.repairs??[]).forEach((m,l)=>{!a[m.act]&&!ce(m.act)&&!fe(m.act,e.kinds)&&s.push(z("repair-act",`${p}.repairs.${l}.act`,`"${m.act}" is not an act this document declares`))})}let h=e.policy;return h&&(h.grants.forEach((i,o)=>{if(i.roles!=="*"&&d.size>0)for(let p of i.roles)d.has(p)||s.push(z("grant-role",`policy.grants.${o}.roles`,`"${p}" is not one of the document's roles`));if(i.mutations!=="*")for(let p of i.mutations)!a[p]&&!ce(p)&&!fe(p,e.kinds)&&s.push(z("grant-act",`policy.grants.${o}.mutations`,`"${p}" is not an act this document declares`))}),(h.sees??[]).forEach((i,o)=>{for(let p of i.kinds)r.has(p)||s.push(z("sight-kind",`policy.sees.${o}.kinds`,`"${p}" is not a kind this document declares`));if(i.roles!=="*"&&d.size>0)for(let p of i.roles)d.has(p)||s.push(z("sight-role",`policy.sees.${o}.roles`,`"${p}" is not one of the document's roles`))})),s.push(..._e(e)),s}function zn(e){return e.label?[...e.label.matchAll(/\{\s*([A-Za-z_][A-Za-z0-9_]*)/g)].map(s=>s[1]):[pe(e)??[]].flat()}function yn(e,s,r,t){let a=new Map,d=re(e.on),u=new Map,f=new Map;(d.length>0||s.some(l=>"remove"in l&&R(l.remove)==="subject"||"from"in l&&(R(l.from)==="subject"||R(l.to)==="subject")||"set"in l&&!("create"in l)&&R(l.target??"$subject")==="subject"))&&a.set(le,{ref:d.length>0?d:"*",required:!0});let i=e.args??{},o=e.writes?.length===1,p=(l,c)=>c&&l.type===c.type&&l.min===void 0&&l.max===void 0&&l.step===void 0?{...l,...c.min===void 0?{}:{min:c.min},...c.max===void 0?{}:{max:c.max},...c.step===void 0?{}:{step:c.step}}:l,w=(l,c)=>c&&l.type===c.type&&l.format===void 0&&l.unit===void 0?{...p(l,c),...c.format?{format:c.format}:{},...c.unit?{unit:c.unit}:{}}:p(l,c),m=(l,c,j)=>{if(l===le||un.has(l)||u.has(l)||a.has(l))return;let y=i[l]?w(i[l],j):void 0;a.set(l,y?{field:y,optional:!y.required,required:!!y.required}:c())};for(let l of s)if("create"in l){let c=r.kinds[l.create],j=c?He(c,zn(c)):[],y=S=>j.includes(S)?j.indexOf(S):j.length;for(let[S,A]of Object.entries(l.set??{}).sort(([b],[G])=>y(b)-y(G))){let b=R(A),G=c?.fields[S];if(b&&G){let F=!!G.required&&G.default===void 0;m(b,()=>({field:G,optional:!F,required:F}),G)}}l.as&&u.set(l.as,l.create)}else if("connect"in l||"sever"in l){let c=t.get("connect"in l?l.connect:l.sever);for(let[j,y]of[["from",l.from],["to",l.to]]){let S=R(y);if(!S)continue;let A=j==="to"?c?.to??"*":c?.from??"*";A!=="*"&&!f.has(S)&&f.set(S,A),m(S,()=>({ref:A,required:!0}))}}else if("set"in l){let c=R(l.target??"$subject"),j=c==="subject"?d[0]:u.get(c??"")??f.get(c??"")?.[0];c&&c!=="subject"&&!u.has(c)&&m(c,()=>({ref:"*",required:!0}));for(let[y,S]of Object.entries(l.set)){let A=R(S);if(!A)continue;let b=j?r.kinds[j]?.fields[y]:void 0;m(A,()=>b?{field:b,optional:!o,required:o}:{any:!0,required:!1},b)}}else if("remove"in l){let c=R(l.remove);c&&m(c,()=>({ref:"*",required:!0}))}for(let[l,c]of Object.entries(i))a.has(l)||a.set(l,{field:c,optional:!c.required,required:!!c.required});return a}function mt(e,s={}){let r=mn(e);if(!r.document||de(r.findings))return{ok:!1,findings:r.findings};let t=r.document,a=[...r.findings];s.previous&&a.push(...bn(t,s.previous));let d=hn(t,a);return de(d.findings)?{ok:!1,findings:d.findings}:Te(d,s)}function ie(e,s){return e.map(r=>{let t=!r.format&&r.expr?.t==="ident"?s?.[r.expr.name]?.format:void 0;return t==="money"||t==="percent"?{...r,format:t}:r})}function hn(e,s){let r=Ye(e),t={};for(let[i,o]of Object.entries(e.kinds)){let p=pe(o),w=o.label??(p?`{${p}}`:void 0),m=ee(o),l=m?We(e,i,[...m]):[];t[i]={...w?{label:ie(Y(w),o.fields)}:{},...o.describe?{describe:ie(Y(o.describe),o.fields)}:{},...m?{computed:[...m]}:{},...l.length>0?{durations:l}:{}}}let a={};for(let[i,o]of Object.entries(e.acts??{})){let p=Je(o,e),w=yn(o,p,e,r),m=o.destructive??p.some(g=>"remove"in g||"sever"in g||"replace"in g),l=[...new Set(p.flatMap(g=>"create"in g?[g.create]:[]))],c=[...new Set(p.flatMap(g=>"connect"in g?[g.connect]:[]))],j=[...new Set(p.flatMap(g=>"sever"in g?[g.sever]:"replace"in g?g.replace:[]))],y=[...new Set(p.flatMap(g=>"set"in g&&!("create"in g)&&R(g.target??"$subject")==="subject"?Object.keys(g.set):[]))],S=new Map;for(let g of p){if(!("connect"in g)&&!("sever"in g))continue;let v=r.get("connect"in g?g.connect:g.sever);for(let[D,te]of[["from",g.from],["to",g.to]]){let I=R(te),Z=D==="to"?v?.to:v?.from;I&&I!=="subject"&&Z&&Z!=="*"&&S.set(I,[...new Set([...S.get(I)??[],...Z])])}}let A={};for(let g of p){if(!("set"in g)||"create"in g)continue;let v=R(g.target??"$subject");for(let D of v&&v!=="subject"&&S.get(v)||[])A[D]=[...new Set([...A[D]??[],...Object.keys(g.set)])]}let b={};for(let g of p)if(!(!("set"in g)||"create"in g||R(g.target??"$subject")!=="subject"))for(let[v,D]of Object.entries(g.set??{}))typeof D=="string"&&R(D)===void 0||typeof D=="number"||typeof D=="boolean"?b[v]=typeof D=="string"&&D.startsWith("$$")?D.slice(1):D:delete b[v];let G=l.length===0&&p.every(g=>!("set"in g)||!g.set||Object.values(g.set).every(v=>!(v&&typeof v=="object"&&!Array.isArray(v)&&"expr"in v))),F=new Map;for(let g of p)if(!(!("set"in g)||!g.set))for(let v of Object.values(g.set))v&&typeof v=="object"&&!Array.isArray(v)&&"expr"in v&&F.set(v.expr,H(v.expr));a[i]={title:o.title??i.replace(/-/g," "),effects:p,args:[...w],...o.allowedWhen?{guard:H(o.allowedWhen)}:{},...o.refusal?{refusal:ie(Y(o.refusal),e.kinds[[o.on??[]].flat()[0]??""]?.fields)}:{},exprs:[...F],destructive:m,idempotent:G,creates:l,connects:c,severs:j,writes:y,writesOther:A,sets:b}}let d={};for(let[i,o]of Object.entries(e.rules??{}))d[i]={title:o.title??i.replace(/-/g," "),require:H(o.require),...o.when?{when:H(o.when)}:{},...o.says?{says:ie(Y(o.says),e.kinds[o.over]?.fields)}:{}};let u=Ke(e,s),f=Ge(e),h=Ce(e);return{format:Me,document:e,findings:s,kinds:t,...e.computed?{facts:[...ee(e)??[]]}:{},edges:[...r].map(([i,{from:o,to:p,cardinality:w}])=>[i,{from:o,to:p,cardinality:w}]),acts:a,rules:d,brand:u,...Object.keys(f).length>0?{viewSpecs:f}:{},...h?{home:h}:{}}}function gt(e,s,r){let t=/^defineNode\("([^"]+)"\)/.exec(s)?.[1],a=t?r.kinds[t]:void 0;if(!t||!a)return e;let d=Object.keys(a.fields).filter(u=>u!=="label").slice(0,3);return{...e,path:`kinds.${t}.glance`,fix:`Say which: "glance": [${d.map(u=>`"${u}"`).join(", ")}] on kinds.${t} \u2014 the facts a person compares one by, at a glance.`}}function bn(e,s){let r=[],t=new Set(Object.values(s.kinds).flatMap(a=>Object.keys(a.edges??{})));for(let[a,d]of Object.entries(e.kinds)){let u=d.renamedFrom;u&&!s.kinds[u]&&r.push(z("renamed-from-nothing",`kinds.${a}.renamedFrom`,`${a} says it was ${u}, and the previous version has no kind called ${u}`,"name the kind it was, or drop renamedFrom"));let f=s.kinds[u??a];for(let[h,i]of Object.entries(d.fields)){let o=i.renamedFrom;o&&!f?.fields[o]&&r.push(z("renamed-from-nothing",`kinds.${a}.fields.${h}.renamedFrom`,`${h} says it was ${o}, and the previous ${u??a} has no field called ${o}`,"name the field it was, or drop renamedFrom"))}for(let[h,i]of Object.entries(d.edges??{})){let o=i.renamedFrom;o&&!t.has(o)&&r.push(z("renamed-from-nothing",`kinds.${a}.edges.${h}.renamedFrom`,`${h} says it was ${o}, and the previous version has no relation called ${o}`,"name the relation it was, or drop renamedFrom"))}}return r}export{mn as a,ut as b,Je as c,mt as d,gt as e};