graview 0.1.42 → 0.1.43
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.
- package/dist/preview/chunk.22E4GKYU.js +1 -0
- package/dist/preview/chunk.25VAWLKJ.js +1 -0
- package/dist/preview/chunk.26SI4K3P.js +35 -0
- package/dist/preview/chunk.27QYTMXP.js +1 -0
- package/dist/preview/chunk.2AZTW66C.js +1 -0
- package/dist/preview/chunk.2JMJTREH.js +1 -0
- package/dist/preview/chunk.3B47UX2J.js +2 -0
- package/dist/preview/{chunk.37NF3YXZ.js → chunk.3GQL4K3Q.js} +1 -1
- package/dist/preview/chunk.3HLNRVFY.js +1 -0
- package/dist/preview/chunk.4C65DXZB.js +1 -0
- package/dist/preview/{chunk.HQMGTPDC.js → chunk.4HAGPMY6.js} +3 -3
- package/dist/preview/{chunk.LQGXUMUX.js → chunk.4IDXQVSW.js} +1 -1
- package/dist/preview/{chunk.SUQU4AXG.js → chunk.4P3LS2OE.js} +1 -1
- package/dist/preview/{chunk.6HUS5UHZ.js → chunk.4YLBGGWT.js} +1 -1
- package/dist/preview/chunk.4ZHUGSJL.js +1 -0
- package/dist/preview/{chunk.2ZGICECC.js → chunk.4ZSHTUNK.js} +1 -1
- package/dist/preview/chunk.5BJW4IPW.js +1 -0
- package/dist/preview/{chunk.L6HKDIZB.js → chunk.5J2HETUO.js} +1 -1
- package/dist/preview/{chunk.U3MQUIJL.js → chunk.5TBK44MK.js} +1 -1
- package/dist/preview/chunk.63DI7XNE.js +21 -0
- package/dist/preview/{chunk.X2M7IOQA.js → chunk.64MP7636.js} +1 -1
- package/dist/preview/chunk.6AYTF53S.js +1 -0
- package/dist/preview/chunk.6BU3GCHK.js +1 -0
- package/dist/preview/{chunk.P6J6VFF5.js → chunk.6IEDQHKI.js} +1 -1
- package/dist/preview/chunk.6K4JBLOP.js +1 -0
- package/dist/preview/{chunk.KSXB4LDF.js → chunk.6PF5LWRK.js} +1 -1
- package/dist/preview/{chunk.27P37343.js → chunk.6ROYIMQ2.js} +1 -1
- package/dist/preview/{chunk.QHP7AJUV.js → chunk.6XEATXZC.js} +1 -1
- package/dist/preview/chunk.7IXLH7PR.js +1 -0
- package/dist/preview/chunk.7L6LYXCV.js +25 -0
- package/dist/preview/chunk.7MQ7UWVW.js +5 -0
- package/dist/preview/{chunk.7EB6SDUQ.js → chunk.7MXQRSNR.js} +1 -1
- package/dist/preview/{chunk.5NDYYTT4.js → chunk.7ROWZZN5.js} +1 -1
- package/dist/preview/chunk.7TU2PDYW.js +1 -0
- package/dist/preview/{chunk.57R4ZUMM.js → chunk.7XCBIID7.js} +1 -1
- package/dist/preview/{chunk.5FHH5NR6.js → chunk.A3WOUDOG.js} +1 -1
- package/dist/preview/{chunk.VO6DBVZR.js → chunk.AXJJUCWT.js} +1 -1
- package/dist/preview/chunk.B2KDYES6.js +1 -0
- package/dist/preview/{chunk.V3K32XD7.js → chunk.BT6FUNQI.js} +1 -1
- package/dist/preview/chunk.BYVE2NQY.js +1 -0
- package/dist/preview/chunk.BYVLGDVJ.js +1 -0
- package/dist/preview/{chunk.ROHM3ETN.js → chunk.C3DX4LWD.js} +1 -1
- package/dist/preview/chunk.C3X3R7LP.js +9 -0
- package/dist/preview/{chunk.I7QCXRP7.js → chunk.C5NOO4CC.js} +1 -1
- package/dist/preview/{chunk.EC2T2UVH.js → chunk.CO2ZPX3D.js} +2 -2
- package/dist/preview/{chunk.ARTJL3X2.js → chunk.CTSPNTDX.js} +1 -1
- package/dist/preview/{chunk.K63BUJBF.js → chunk.CW6IPHRR.js} +2 -2
- package/dist/preview/chunk.CXJXVBGF.js +1 -0
- package/dist/preview/{chunk.B6DKKNVR.js → chunk.DJ3BD7AZ.js} +1 -1
- package/dist/preview/{chunk.PACJFDDU.js → chunk.DQR45N7V.js} +1 -1
- package/dist/preview/{chunk.PCTVLNOS.js → chunk.DYW4D74X.js} +1 -1
- package/dist/preview/chunk.DZN26GKS.js +1 -0
- package/dist/preview/chunk.E2AJ7U5Z.js +1 -0
- package/dist/preview/chunk.E5PHLNXR.js +1 -0
- package/dist/preview/{chunk.HG2IO5NS.js → chunk.EBTYR5CZ.js} +1 -1
- package/dist/preview/chunk.EPPAFWP7.js +5 -0
- package/dist/preview/{chunk.NS3Z7QNP.js → chunk.F6CPM7SL.js} +1 -1
- package/dist/preview/chunk.FCPH4YZN.js +1 -0
- package/dist/preview/{chunk.PH5ITX3N.js → chunk.FKLEIR4Y.js} +1 -1
- package/dist/preview/chunk.FLMNHV6A.js +19 -0
- package/dist/preview/chunk.FTF67QE2.js +1 -0
- package/dist/preview/chunk.GNPYSMHA.js +1 -0
- package/dist/preview/chunk.GSZYT6GF.js +1 -0
- package/dist/preview/{chunk.X5WIS4BC.js → chunk.GZA5ZNLJ.js} +1 -1
- package/dist/preview/chunk.HMABYAZR.js +1 -0
- package/dist/preview/chunk.I4HUBO22.js +1 -0
- package/dist/preview/chunk.IJ2AF3AW.js +1 -0
- package/dist/preview/{chunk.HOTOH7ZB.js → chunk.IJU322EP.js} +1 -1
- package/dist/preview/chunk.IWUSCCZN.js +1 -0
- package/dist/preview/{chunk.B7DCQJXV.js → chunk.JNCSGUO3.js} +1 -1
- package/dist/preview/{chunk.LZH65VSN.js → chunk.K6SPN4D6.js} +1 -1
- package/dist/preview/chunk.KBMVUIWR.js +6 -0
- package/dist/preview/{chunk.HAY22FPJ.js → chunk.KG5R4GTK.js} +1 -1
- package/dist/preview/chunk.KR3J27IA.js +88 -0
- package/dist/preview/chunk.KWQ67UK2.js +1 -0
- package/dist/preview/chunk.LBIDNJ6G.js +1 -0
- package/dist/preview/{chunk.ILPD5CZG.js → chunk.LDU25CCL.js} +1 -1
- package/dist/preview/{chunk.CAZX6OPN.js → chunk.MBOOUJOE.js} +1 -1
- package/dist/preview/{chunk.J7ZMNAWB.js → chunk.MI2HL3LQ.js} +1 -1
- package/dist/preview/chunk.MXU3VQSQ.js +1 -0
- package/dist/preview/{chunk.KZDLDXLB.js → chunk.N3FONYEP.js} +2 -2
- package/dist/preview/chunk.NH6D6TWY.js +1 -0
- package/dist/preview/chunk.NQTCOBOQ.js +1 -0
- package/dist/preview/chunk.O4X5WJIC.js +1 -0
- package/dist/preview/chunk.OH2N3SX7.js +1 -0
- package/dist/preview/chunk.OIJP6PQV.js +1 -0
- package/dist/preview/{chunk.CSWX7YGI.js → chunk.ONSG3OIL.js} +1 -1
- package/dist/preview/chunk.ORKXXLWD.js +1 -0
- package/dist/preview/chunk.OUN2H3TR.js +1 -0
- package/dist/preview/{chunk.AQTCN7KQ.js → chunk.OWL5GZ6U.js} +1 -1
- package/dist/preview/chunk.PEXPTDX7.js +1 -0
- package/dist/preview/chunk.PWYMZWAN.js +1 -0
- package/dist/preview/{chunk.V5VQCANB.js → chunk.Q5XICUDZ.js} +1 -1
- package/dist/preview/chunk.QJUFVEAU.js +1 -0
- package/dist/preview/{chunk.WVN62OMH.js → chunk.QWY54AVN.js} +1 -1
- package/dist/preview/{chunk.Y2QDZLSY.js → chunk.QXTLZSBL.js} +1 -1
- package/dist/preview/{chunk.XDPIS7RS.js → chunk.R2B2ZAWI.js} +1 -1
- package/dist/preview/{chunk.VTUMPH4Z.js → chunk.R7F6UJVG.js} +1 -1
- package/dist/preview/chunk.RDXDEFOC.js +1 -0
- package/dist/preview/{chunk.WUQOSVQU.js → chunk.RPDTWQKA.js} +3 -3
- package/dist/preview/{chunk.4YBP552Z.js → chunk.RQBX7M7Q.js} +2 -2
- package/dist/preview/{chunk.LFJH6X6O.js → chunk.RSYFIL2Z.js} +1 -1
- package/dist/preview/{chunk.WZEA2UK6.js → chunk.RY4E4JRI.js} +1 -1
- package/dist/preview/{chunk.VEP4EJ2N.js → chunk.S2MP53RO.js} +1 -1
- package/dist/preview/{chunk.IWLVZGW5.js → chunk.S6BZXNMV.js} +1 -1
- package/dist/preview/{chunk.WERBD5ZR.js → chunk.SGRKCQ2X.js} +1 -1
- package/dist/preview/chunk.SKB4XSDG.js +1 -0
- package/dist/preview/chunk.T4M4MLOS.js +1 -0
- package/dist/preview/{chunk.BZ4VZ6WQ.js → chunk.T4Q6OLZU.js} +1 -1
- package/dist/preview/{chunk.QHLD4TZW.js → chunk.T4QT5SZY.js} +1 -1
- package/dist/preview/{chunk.VKJAGZNU.js → chunk.TMBFLZNH.js} +1 -1
- package/dist/preview/chunk.TX65ZO27.js +1 -0
- package/dist/preview/chunk.U3ETEQDO.js +1 -0
- package/dist/preview/chunk.VCOIFBUE.js +1 -0
- package/dist/preview/{chunk.4QEDYRES.js → chunk.VP35BUUZ.js} +5 -5
- package/dist/preview/{chunk.VMBIFUYX.js → chunk.WH2RYGXR.js} +1 -1
- package/dist/preview/{chunk.P7ISPJAQ.js → chunk.WWR7Y2KE.js} +1 -1
- package/dist/preview/chunk.X5WB4GJ4.js +1 -0
- package/dist/preview/chunk.XAXZCOZK.js +1 -0
- package/dist/preview/chunk.XBV4WO7D.js +1 -0
- package/dist/preview/chunk.XFQUVMRI.js +1 -0
- package/dist/preview/{chunk.QXMTGLHR.js → chunk.XGRMQUFB.js} +1 -1
- package/dist/preview/{chunk.O7VHAKSA.js → chunk.XVWJD2DG.js} +1 -1
- package/dist/preview/{chunk.LWAZ6ZO6.js → chunk.YKN2VWWQ.js} +2 -2
- package/dist/preview/{chunk.ZRIDKFTV.js → chunk.YPEZZLOY.js} +1 -1
- package/dist/preview/chunk.YQDIVHCH.js +1 -0
- package/dist/preview/{chunk.ZQCGDTQ3.js → chunk.Z56L6V6Z.js} +1 -1
- package/dist/preview/{chunk.KMGGP6XT.js → chunk.ZE4U4JBF.js} +2 -2
- package/dist/preview/chunk.ZE6LJVVN.js +1 -0
- package/dist/preview/{chunk.U6YOAS4X.js → chunk.ZEC64CK6.js} +1 -1
- package/dist/preview/chunk.ZHRW2UF4.js +1 -0
- package/dist/preview/{chunk.XNW7PUAF.js → chunk.ZRICIE6T.js} +1 -1
- package/dist/preview/chunk.ZUJZVK2X.js +1 -0
- package/dist/preview/index.html +46 -45
- package/dist/preview/page.js +6 -6
- package/package.json +6 -6
- package/dist/preview/chunk.22QEYFWI.js +0 -1
- package/dist/preview/chunk.35FR36BQ.js +0 -1
- package/dist/preview/chunk.36LP3I7Z.js +0 -21
- package/dist/preview/chunk.3K2KBIRG.js +0 -1
- package/dist/preview/chunk.3SKUJWFC.js +0 -1
- package/dist/preview/chunk.3WABA2WQ.js +0 -1
- package/dist/preview/chunk.4NBB44YU.js +0 -1
- package/dist/preview/chunk.4YRCKOX2.js +0 -1
- package/dist/preview/chunk.6MLAJKYM.js +0 -1
- package/dist/preview/chunk.6NF32PAT.js +0 -1
- package/dist/preview/chunk.6WB24MS3.js +0 -1
- package/dist/preview/chunk.7HZVCW3Q.js +0 -1
- package/dist/preview/chunk.7MJM3OVC.js +0 -1
- package/dist/preview/chunk.7OSL64QH.js +0 -1
- package/dist/preview/chunk.7XDNCCLG.js +0 -6
- package/dist/preview/chunk.7Z2GTKA4.js +0 -1
- package/dist/preview/chunk.AOC2KUFE.js +0 -1
- package/dist/preview/chunk.AWSUMY3D.js +0 -1
- package/dist/preview/chunk.B65HPL4I.js +0 -1
- package/dist/preview/chunk.BJET6KOG.js +0 -1
- package/dist/preview/chunk.D3ELYLME.js +0 -1
- package/dist/preview/chunk.DNMBZONP.js +0 -1
- package/dist/preview/chunk.DXAUXGNN.js +0 -1
- package/dist/preview/chunk.EHMCRUYR.js +0 -1
- package/dist/preview/chunk.EQIQPY4O.js +0 -1
- package/dist/preview/chunk.ETWOZQWL.js +0 -1
- package/dist/preview/chunk.EVHXF7LZ.js +0 -19
- package/dist/preview/chunk.FFRWSODT.js +0 -1
- package/dist/preview/chunk.G4AY6NGN.js +0 -1
- package/dist/preview/chunk.GN2SZEFH.js +0 -1
- package/dist/preview/chunk.GXWOEOUY.js +0 -1
- package/dist/preview/chunk.IGA7OD3L.js +0 -1
- package/dist/preview/chunk.IXS5XBG6.js +0 -1
- package/dist/preview/chunk.JCTT2LAK.js +0 -1
- package/dist/preview/chunk.JE4QQEJE.js +0 -25
- package/dist/preview/chunk.JEBB3WM7.js +0 -1
- package/dist/preview/chunk.JPD2I4Z7.js +0 -1
- package/dist/preview/chunk.LKGDN25E.js +0 -1
- package/dist/preview/chunk.LMUFLZYT.js +0 -1
- package/dist/preview/chunk.MUBZIU6F.js +0 -1
- package/dist/preview/chunk.MZ6I2Q4E.js +0 -1
- package/dist/preview/chunk.NTJNBKWC.js +0 -1
- package/dist/preview/chunk.OMCXJGDI.js +0 -1
- package/dist/preview/chunk.OTHGZPUC.js +0 -1
- package/dist/preview/chunk.P6FGIYWP.js +0 -35
- package/dist/preview/chunk.PYFQGBU3.js +0 -1
- package/dist/preview/chunk.RFCTUGMU.js +0 -1
- package/dist/preview/chunk.RR4RZH4S.js +0 -1
- package/dist/preview/chunk.S5K4FLLG.js +0 -1
- package/dist/preview/chunk.SZKVNPEF.js +0 -1
- package/dist/preview/chunk.T3F6BKIO.js +0 -1
- package/dist/preview/chunk.UG727PEE.js +0 -5
- package/dist/preview/chunk.VXZFW52D.js +0 -1
- package/dist/preview/chunk.VYPR2MZO.js +0 -1
- package/dist/preview/chunk.W77OH637.js +0 -1
- package/dist/preview/chunk.WODEO2JF.js +0 -9
- package/dist/preview/chunk.XPML6T3P.js +0 -1
- package/dist/preview/chunk.YJM23BJL.js +0 -88
- package/dist/preview/chunk.YLGSXLXF.js +0 -1
- package/dist/preview/chunk.YLI6I6XP.js +0 -1
- package/dist/preview/chunk.YRYEWVNP.js +0 -1
- package/dist/preview/chunk.Z2TYCMBT.js +0 -5
- package/dist/preview/chunk.ZAFIZXGX.js +0 -1
- package/dist/preview/chunk.ZBYLAC3B.js +0 -2
- package/dist/preview/chunk.ZOS5APMD.js +0 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{a as pe,b as De,c as qn,e as $e,f as Re,g as hn}from"./chunk.2AZTW66C.js";var Ft="en-US",Le=/^\d{4}-\d{2}-\d{2}$/,Hn=/^\d{4}(-\d\d){2}[T ]\d\d:\d\d(:[\d.]+)?(Z|[+-][\d:]+)?$/,zf=n=>!Number.isNaN(Date.parse(n)),H=(n,e=Date.now())=>{let t=Yn(n);return t?Zt(e,t).day:new Date(e).toISOString().slice(0,10)},Yn=n=>Ze(n)??Fe,gn,mn,yn,Fe;function wd(n){gn=bn(n.reader),mn=bn(n.app),yn=Ze(n.readerTimeZone),Fe=Ze(n.appTimeZone)}function kd(n,e){let t=[gn,mn,yn,Fe];n.reader!==void 0&&(gn=bn(n.reader)),n.app!==void 0&&(mn=bn(n.app)),n.readerTimeZone!==void 0&&(yn=Ze(n.readerTimeZone)),n.appTimeZone!==void 0&&(Fe=Ze(n.appTimeZone));try{return e()}finally{[gn,mn,yn,Fe]=t}}var Ao=n=>gn??bn(n)??mn??Ft,Jn=n=>yn??Ze(n)??Fe,Sd=n=>Jn(n)??Intl.DateTimeFormat().resolvedOptions().timeZone??"UTC",$d=/^\s*([+\-−]|\d)/;var Dt=new Map;function Ze(n){if(n&&!Dt.has(n)){let e=!1;try{new Intl.DateTimeFormat(Ft,{timeZone:n}),e=!$d.test(n)}catch{}Dt.set(n,e)}return n&&Dt.get(n)?n:void 0}var _e=new Map;function bn(n){if(n&&!_e.has(n)){let e=!1;try{e=Intl.DateTimeFormat.supportedLocalesOf(n).length>0}catch{}_e.set(n,e)}return n&&_e.get(n)?n:void 0}function he(n,e,t,r){let o=`${t=Ao(t)}${r?"#":"@"}${JSON.stringify(e)}`,i=_e.get(o);return i||_e.set(o,i=r?new Intl.NumberFormat(t,e):new Intl.DateTimeFormat(t,e)),i.format(n).replace(/ /g," ")}var Ae="UTC",Xn=n=>Date.UTC(+n.slice(0,4),+n.slice(5,7)-1,+n.slice(8,10));function ge(n,e){return Le.test(n)?he(Xn(n),{year:"numeric",month:"short",day:"numeric",timeZone:Ae},e):n}function Zt(n,e){let t=`wall@${e??""}`,r=_e.get(t);r||_e.set(t,r=new Intl.DateTimeFormat("en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23",...e?{timeZone:e}:{}}));let o=Object.fromEntries(r.formatToParts(n).map(i=>[i.type,i.value]));return{day:`${o.year}-${o.month}-${o.day}`,minutes:Number(o.hour)%24*60+Number(o.minute)}}function Oo(n,e,t){let r=Date.UTC(+n.slice(0,4),+n.slice(5,7)-1,+n.slice(8,10),0,e),o=i=>{let s=Zt(i,t);return Rd(s.day,s.minutes)-Math.floor(i/6e4)*6e4};return r-o(r-o(r))}var Rd=(n,e)=>Date.UTC(+n.slice(0,4),+n.slice(5,7)-1,+n.slice(8,10),0,e),Eo=n=>/[Z+-][\d:]*$/.test(n.slice(16));function Po(n,e,t,r,o=!1){if(!Hn.test(n))return n;let i=Eo(n),s=Date.parse(n.replace(" ","T")+(i?"":"Z"));if(Number.isNaN(s))return n;let a=i?Jn(r):Ae;return he(s,{...e,hour:"numeric",minute:"2-digit",...i&&o?{timeZoneName:"short"}:{},...a?{timeZone:a}:{}},t)}var Lt=(n,e,t)=>Po(n,{year:"numeric",month:"short",day:"numeric"},e,t,!0),_d=(n,e,t)=>Po(n,{},e,t);function Ad(n,e){if(Le.test(n))return n;if(!Hn.test(n))return;if(!Eo(n))return n.slice(0,10);let t=Date.parse(n.replace(" ","T"));return Number.isNaN(t)?void 0:Zt(t,Jn(e)).day}function ie(n,e,t={maximumFractionDigits:2}){return Number.isFinite(n)?he(n,t,e,!0):String(n)}function Od(n,e={},t){return Le.test(n)?he(Xn(n),{weekday:e.weekday??"long",month:"short",day:"numeric",...e.year?{year:"numeric"}:{},timeZone:Ae},t):n}function Ed(n,e){return Le.test(n)?he(Xn(n),{month:"short",day:"numeric",timeZone:Ae},e):n}function Pd(n,e={},t){if(!/^\d{4}-\d{2}/.test(n))return n;let r=e.year??!e.short;return he(Xn(`${n.slice(0,7)}-01`),{month:e.short?"short":"long",...r?{year:e.short?"2-digit":"numeric"}:{},timeZone:Ae},t)}var zd=(n,e="short",t)=>he(Date.UTC(1970,0,4+n),{weekday:e,timeZone:Ae},t),Md=(n,e)=>he(Date.UTC(1970,0,1,0,Math.round(n)),{hour:"numeric",minute:"2-digit",timeZone:Ae},e),Nd=/(?<![\w-])(\d{4}-\d{2}-\d{2})(?![\w-]|:)/g;function Ct(n,e){return n.includes("-")?n.replace(Nd,t=>ge(t,e)):n}var vn=n=>n.charAt(0).toUpperCase()+n.slice(1),zo=(n,e="and")=>n.length>1?`${n.slice(0,-1).join(", ")} ${e} ${n.at(-1)}`:n[0]??"";function Id(n,e){return{...e,kind:n,edges:e.edges??{}}}function Gt(n,e,t){let r=n?.lifecycle;if(!r)return!0;let o=e[r.field];return r.retired==="date"?typeof o!="string"||o.length===0?!0:o>=(t??H()):!r.retired.includes(o)}function F(n,e){if(n?.label)return n.label(e);let t=e.label;return typeof t=="string"&&t.length>0?t:e.id}function jd(n){return n.title??C(n.name)}function C(n){let e=n.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").trim().toLowerCase();return vn(e)}function Td(n,e,t){let r=n.tryDefinition(e);return`${ie(t)} ${t===1?K(r,e):ne(n,e).toLowerCase()}`}function ne(n,e){return n.tryDefinition(e)?.plural??`${C(e).toLowerCase()}s`}function Dd(n,e){return vn(ne(n,e))}function Fd(n,e){let t=ne(n,e);return`All ${/^[A-Z][a-z]/.test(t)?t.charAt(0).toLowerCase()+t.slice(1):t}`}function Qn(n,e){let t=n?.computed&&Object.hasOwn(n.computed,e)?n.computed[e]:void 0;return n?.display?.labels?.[e]??(typeof t=="object"?t.label:void 0)??(e==="label"?"Name":C(e))}var Zd=/^(u[nt]i|use|usu|uti|ubiq|eu|ewe|one|once)/,Ld=/^(hour|honest|hono[ur]r?|heir)/;function Mo(n){let e=C(n).toLowerCase();return Ld.test(e)?"an":Zd.test(e)?"a":/^[aeiou]/.test(e)?"an":"a"}function Ce(n){return`${Mo(n)} ${C(n).toLowerCase()}`}function K(n,e){return n?.noun??C(e).toLowerCase()}function Ut(n){let e=Object.values(n).filter(r=>typeof r=="number");return Object.entries(n).filter(([r,o])=>e.indexOf(+r)===-1).map(([r,o])=>o)}function Vt(n,e="|"){return n.map(t=>Jt(t)).join(e)}function Io(n,e){return typeof e=="bigint"?e.toString():e}var Kt=class{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;return e!==void 0&&(this._value=e(),this._getter=void 0),this._value}};function jo(n){return new Kt(n)}function To(n){return n==null}function Wt(n){let e=n.startsWith("^")?1:0,t=n.endsWith("$")?n.length-1:n.length;return n.slice(e,t)}function Do(n,e){let t=n/e,r=Math.round(t),o=4*Number.EPSILON*Math.max(Math.abs(t),1);return Math.abs(t-r)<o?0:t-r}var No=Symbol("evaluating");function Fo(n,e,t){let r;Object.defineProperty(n,e,{get(){if(r!==No)return r===void 0&&(r=No,r=t()),r},set(o){Object.defineProperty(n,e,{value:o})},configurable:!0})}function nt(n,e,t){Object.defineProperty(n,e,{value:t,writable:!0,enumerable:!0,configurable:!0})}function Zo(n){let e=Object.getOwnPropertyDescriptor(n,"shape");return e?.get?e.get.raw:e?.value}function qt(n){return Zo(n._zod.def)??n._zod.def.shape}function Lo(n,e,t){Object.defineProperty(n,e,{get(){let r=t();return nt(this,e,r),r},enumerable:!0,configurable:!0})}function Co(n,e,t){e in n?nt(n,e,t):n[e]=t}function Cd(n,e,t,r){let o=qt(e);for(let i of t){let s=Object.getOwnPropertyDescriptor(o,i);s.enumerable&&(s.get?Lo(n,i,()=>{let a=e._zod.def.shape[i];return r?r(a,i):a}):Co(n,i,r?r(s.value,i):s.value))}}function Gd(n,e){for(let t of Reflect.ownKeys(e)){let r=Object.getOwnPropertyDescriptor(e,t);r.enumerable&&(r.get?Lo(n,t,()=>e[t]):Co(n,t,r.value))}}function Go(...n){let e={};for(let t of n){let r=Object.getOwnPropertyDescriptors(t);Object.assign(e,r)}return Object.defineProperties({},e)}var Ht="captureStackTrace"in Error?Error.captureStackTrace:(...n)=>{};function et(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function Yt(n){if(et(n)===!1)return!1;let e=n.constructor;if(e===void 0||typeof e!="function")return!0;let t=e.prototype;return!(et(t)===!1||Object.prototype.hasOwnProperty.call(t,"isPrototypeOf")===!1)}var Bo=new Set(["string","number","symbol"]);function wn(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ge(n,e,t){let r=new n._zod.constr(e??n._zod.def);return(!e||t?.parent)&&(r._zod.parent=n),r}function M(n){let e=n;if(!e)return{};if(typeof e=="string")return{error:()=>e};if(e?.message!==void 0){if(e?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");e.error=e.message}return delete e.message,typeof e.error=="string"?{...e,error:()=>e.error}:e}function Jt(n){return typeof n=="bigint"?n.toString()+"n":typeof n=="string"?`"${n}"`:`${n}`}function Ko(n){return Object.keys(n).filter(e=>n[e]._zod.optin!==void 0&&n[e]._zod.optout==="optional")}var Uo={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Vo(n,e){if(!Yt(e))throw new Error("Invalid input to extend: expected a plain object");let t=n._zod.def.checks;if(t&&t.length>0){let o=qt(n);for(let i of Reflect.ownKeys(e))if(Object.getOwnPropertyDescriptor(o,i)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return Ge(n,Go(n._zod.def,{shape:Bd(n,e)}))}function Bd(n,e){let t={};return Cd(t,n,Reflect.ownKeys(qt(n))),Gd(t,e),t}function se(n,e=0){if(n.aborted===!0)return!0;for(let t=e;t<n.issues.length;t++)if(n.issues[t]?.continue!==!0)return!0;return!1}function Wo(n,e=0){if(n.aborted===!0)return!0;for(let t=e;t<n.issues.length;t++)if(n.issues[t]?.continue===!1)return!0;return!1}function ye(n,e){return e.map(t=>{var r;return(r=t).path??(r.path=[]),t.path.unshift(n),t})}function xn(n){return typeof n=="string"?n:n?.message}function Xt(n,e,t){var r;for(let o=e;o<n.length;o++)(r=n[o]).schema??(r.schema=t)}function ae(n,e,t){var r;let o=n.inst?._zod?.traits;o?.has("$ZodType")&&(o.has("$ZodCheck")?(r=n).schema??(r.schema=n.inst):n.schema=n.inst);let i=n.schema!==n.inst?n.schema?._zod.def?.error:void 0,s=n.message?n.message:xn(n.inst?._zod.def?.error?.(n))??xn(i?.(n))??xn(e?.error?.(n))??xn(t.customError?.(n))??xn(t.localeError?.(n))??"Invalid input",a={};for(let d of Object.keys(n))d==="inst"||d==="schema"||d==="continue"||d==="input"||d==="__proto__"||(a[d]=n[d]);return a.path??(a.path=[]),a.message=s,e?.reportInput&&(a.input=n.input),a}var Kd=/[\uD800-\uDBFF]/;function Qt(n){let e=n.length;if(!Kd.test(n))return e;let t=e;for(let r=0;r<e-1;r++)(n.charCodeAt(r)&64512)===55296&&(n.charCodeAt(r+1)&64512)===56320&&(t--,r++);return t}function er(n){return Array.isArray(n)?"array":typeof n=="string"?"string":"unknown"}function qo(n){let e=typeof n;switch(e){case"number":return Number.isNaN(n)?"nan":"number";case"object":{if(n===null)return"null";if(Array.isArray(n))return"array";let t=n;if(t&&Object.getPrototypeOf(t)!==Object.prototype&&"constructor"in t&&t.constructor)return t.constructor.name}}return e}function kn(...n){let[e,t,r]=n;return typeof e=="string"?{message:e,code:"custom",input:t,inst:r}:{...e}}function Ho(n,e){for(let t in e){let r=Object.getOwnPropertyDescriptor(e,t);r.get?Object.defineProperty(n,t,{...r,enumerable:!1}):Ud(n,t,r.value)}}function Oe(n,e,t,r=!0){return Object.defineProperty(n,e,{configurable:!0,writable:!0,enumerable:r,value:t}),t}function nr(n,e,t){return Oe(n,e,t,!1)}function Ud(n,e,t){Object.defineProperty(n,e,{configurable:!0,get(){return this==null?t:Oe(this,e,t.bind(this))},set(r){Oe(this,e,r)}})}function Vd(n,e){let t=Object.getPrototypeOf(n);return e in t?void 0:t}var Bt,me=!1,Wd={configurable:!0,get(){me=!0}};function U(n,e,t){let r=Object.getPrototypeOf(n._zod);if(e in r&&Bt!==n._zod){Bt=void 0;return}Bt=n._zod,Object.defineProperty(r,e,{configurable:!0,get(){Object.defineProperty(this,e,Wd);let o=me;me=!1;try{let i=t(this);return me?delete this[e]:Object.defineProperty(this,e,{configurable:!0,writable:!0,value:i}),me=me||o,i}catch(i){throw delete this[e],me=me||o,i}},set(o){Object.defineProperty(this,e,{configurable:!0,writable:!0,value:o})}})}function Yo(n,e,t,r){let o=Vd(n,e);o&&Object.defineProperty(o,e,{configurable:!0,get(){let i={configurable:!0,writable:!0,enumerable:r,value:void 0};return Object.defineProperty(this,e,i),i.value=t(this),Object.defineProperty(this,e,i),i.value},set(i){Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:r,value:i})}})}var Jo;var tr={value:void 0,enumerable:!1},Xo="captureStackTrace"in Error?Error:null;function qd(n){let e=Xo;if(e){let t=e.stackTraceLimit;if(typeof t=="number"){try{e.stackTraceLimit=0}catch{return Xo=null,new n}try{return new n}finally{e.stackTraceLimit=t}}}return new n}function O(n,e,t,r){let o={};function i(u){this.def=u,this.constr=p,this.traits=new Set}i.prototype=o;let s=t,a=s&&new WeakSet;function d(u,l){if(u._zod){if(u._zod.traits.has(n))return}else{tr.value=new i(l);try{Object.defineProperty(u,"_zod",tr)}finally{tr.value=void 0}}if(u._zod.traits.add(n),e(u,l),a){let h=Object.getPrototypeOf(u),v=u._zod.constr.prototype,y=h;for(;y&&y!==v;)y=Object.getPrototypeOf(y);let S=y??h;a.has(S)||(a.add(S),Ho(S,s))}let g=p.prototype;for(let h in g)Object.prototype.hasOwnProperty.call(g,h)&&(h in u||(u[h]=g[h].bind(u)))}let f=r?.Parent??Object;class c extends f{}Object.defineProperty(c,"name",{value:n});function p(u){let l=r?.Parent?qd(c):this;d(l,u);let g=l._zod.deferred;if(g){for(let v of g)v();l._zod.deferred=void 0}let h=globalThis.__zod_globalConfig?.postProcessor;return h&&h(l),l}return Object.defineProperty(p,"init",{value:d}),Object.defineProperty(p,Symbol.hasInstance,{value:u=>r?.Parent&&u instanceof r.Parent?!0:u?._zod?.traits?.has(n)}),Object.defineProperty(p,"name",{value:n}),p}var ce=class extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}};(Jo=globalThis).__zod_globalConfig??(Jo.__zod_globalConfig={});var Be=globalThis.__zod_globalConfig;function J(n){return n&&Object.assign(Be,n),Be}function Hd(){let n=this._zod;return n.message??(n.message=JSON.stringify(n.def,Io,2)),n.message}function Yd(n){this._zod.message=n}var Jd={get:Hd,set:Yd,enumerable:!0,configurable:!0},or={value:void 0,enumerable:!1},Qo=new WeakSet([Object.prototype,Error.prototype]),ei=(n,e)=>{n.name="$ZodError",or.value=e,Object.defineProperty(n,"issues",or),or.value=void 0,Object.defineProperty(n,"message",Jd);let t=Object.getPrototypeOf(n);Qo.has(t)||(Qo.add(t),Object.defineProperty(t,"toString",{configurable:!0,enumerable:!1,get(){let r=()=>this.message;return Object.defineProperty(this,"toString",{value:r,configurable:!0,writable:!0}),r},set(r){Object.defineProperty(this,"toString",{value:r,configurable:!0,writable:!0})}}))},Zf=O("$ZodError",ei),Sn=O("$ZodError",ei,void 0,{Parent:Error});var Qd=n=>{let e=(t,r,o,i)=>{let s=o?{...o,async:!1}:{async:!1},a=t._zod.run({value:r,issues:[]},s);if(a instanceof Promise)throw new ce;if(a.issues.length){let d=new(i?.Err??n)(a.issues.map(f=>ae(f,s,J())));throw Ht(d,i?.callee??e),d}return a.value};return e},ir=Qd(Sn),ec=n=>{let e=async(t,r,o,i)=>{let s=o?{...o,async:!0}:{async:!0},a=t._zod.run({value:r,issues:[]},s);if(a instanceof Promise&&(a=await a),a.issues.length){let d=new(i?.Err??n)(a.issues.map(f=>ae(f,s,J())));throw Ht(d,i?.callee??e),d}return a.value};return e},sr=ec(Sn),nc=n=>(e,t,r)=>{let o=r?{...r,async:!1}:{async:!1},i=e._zod.run({value:t,issues:[]},o);if(i instanceof Promise)throw new ce;return i.issues.length?ni(n,i.issues,o):{success:!0,data:i.value}},ar=nc(Sn);function ni(n,e,t){let r;return{success:!1,get error(){return r||(r=new n(e.map(o=>ae(o,t,J()))),e=void 0,t=void 0),r},set error(o){r=o,e=void 0,t=void 0}}}var tc=n=>async(e,t,r)=>{let o=r?{...r,async:!0}:{async:!0},i=e._zod.run({value:t,issues:[]},o);return i instanceof Promise&&(i=await i),i.issues.length?ni(n,i.issues,o):{success:!0,data:i.value}},dr=tc(Sn);var ti=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var ri=/^https?$/;var oi=/^[\s\S]{0,}$/;var cr=/^-?\d+(?:\.\d+)?$/,ii=/^(?:true|false)$/i,si=/^null$/i;var X=O("$ZodCheck",(n,e)=>{var t;n._zod??(n._zod={}),n._zod.def=e,(t=n._zod).onattach??(t.onattach=[])});var ai=n=>{let e=n.value;return!To(e)&&e.length!==void 0},tt={number:"number",bigint:"bigint",object:"date"},di=O("$ZodCheckLessThan",(n,e)=>{X.init(n,e);let t=tt[typeof e.value];n._zod.check=r=>{(e.inclusive?r.value<=e.value:r.value<e.value)||r.issues.push({origin:tt[typeof r.value]??t,code:"too_big",maximum:typeof e.value=="object"?e.value.getTime():e.value,input:r.value,inclusive:e.inclusive,inst:n,continue:!e.abort})}}),ci=O("$ZodCheckGreaterThan",(n,e)=>{X.init(n,e);let t=tt[typeof e.value];n._zod.check=r=>{(e.inclusive?r.value>=e.value:r.value>e.value)||r.issues.push({origin:tt[typeof r.value]??t,code:"too_small",minimum:typeof e.value=="object"?e.value.getTime():e.value,input:r.value,inclusive:e.inclusive,inst:n,continue:!e.abort})}}),ui=O("$ZodCheckMultipleOf",(n,e)=>{X.init(n,e),n._zod.check=t=>{if(typeof t.value!=typeof e.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof t.value=="bigint"?e.value!==BigInt(0)&&t.value%e.value===BigInt(0):Do(t.value,e.value)===0)||t.issues.push({origin:typeof t.value,code:"not_multiple_of",divisor:e.value,input:t.value,inst:n,continue:!e.abort})}}),li=O("$ZodCheckNumberFormat",(n,e)=>{X.init(n,e),e.format=e.format||"float64";let t=e.format?.includes("int"),r=t?"int":"number",[o,i]=Uo[e.format];n._zod.check=s=>{let a=s.value;if(t){if(!Number.isInteger(a)){s.issues.push({expected:r,format:e.format,code:"invalid_type",continue:!1,input:a,inst:n});return}if(!Number.isSafeInteger(a)){a>0?s.issues.push({input:a,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:n,origin:r,inclusive:!0,continue:!e.abort}):s.issues.push({input:a,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:n,origin:r,inclusive:!0,continue:!e.abort});return}}a<o&&s.issues.push({origin:"number",input:a,code:"too_small",minimum:o,inclusive:!0,inst:n,continue:!e.abort}),a>i&&s.issues.push({origin:"number",input:a,code:"too_big",maximum:i,inclusive:!0,inst:n,continue:!e.abort})}});var fi=O("$ZodCheckMaxLength",(n,e)=>{var t;X.init(n,e),(t=n._zod.def).when??(t.when=ai),n._zod.check=r=>{let o=r.value,i=o.length;if((typeof o=="string"&&i>e.maximum?Qt(o):i)<=e.maximum)return;let a=er(o);r.issues.push({origin:a,code:"too_big",maximum:e.maximum,inclusive:!0,input:o,inst:n,continue:!e.abort})}}),pi=O("$ZodCheckMinLength",(n,e)=>{var t;X.init(n,e),(t=n._zod.def).when??(t.when=ai),n._zod.check=r=>{let o=r.value,i=o.length;if((typeof o=="string"&&i>=e.minimum&&i<e.minimum*2?Qt(o):i)>=e.minimum)return;let a=er(o);r.issues.push({origin:a,code:"too_small",minimum:e.minimum,inclusive:!0,input:o,inst:n,continue:!e.abort})}});var lr=O("$ZodCheckStringFormat",(n,e)=>{var t,r;X.init(n,e),e.pattern?(t=n._zod).check??(t.check=o=>{e.pattern.lastIndex=0,!e.pattern.test(o.value)&&o.issues.push({origin:"string",code:"invalid_format",format:e.format,input:o.value,...e.pattern?{pattern:e.pattern.toString()}:{},inst:n,continue:!e.abort})}):(r=n._zod).check??(r.check=()=>{})}),hi=O("$ZodCheckRegex",(n,e)=>{lr.init(n,e),n._zod.check=t=>{e.pattern.lastIndex=0,!e.pattern.test(t.value)&&t.issues.push({origin:"string",code:"invalid_format",format:"regex",input:t.value,pattern:e.pattern.toString(),inst:n,continue:!e.abort})}});var mi={major:4,minor:6,patch:5};var G=O("$ZodType",(n,e)=>{var t;n??(n={}),n._zod.def=e,n._zod.bag=n._zod.bag||{},n._zod.version=mi;let r=n._zod.def.checks,o=n._zod.traits.has("$ZodCheck")?[n,...r??[]]:r?.length?[...r]:[];for(let i of o)for(let s of i._zod.onattach)s(n);if(o.length===0)(t=n._zod).deferred??(t.deferred=[]),n._zod.deferred?.push(()=>{n._zod.run=n._zod.parse});else{let i=(a,d,f)=>{if(a.memo)return a;let c=se(a),p;for(let u of d){if(u._zod.def.when){if(Wo(a)||!u._zod.def.when(a))continue}else if(c)continue;let l=a.issues.length,g=u._zod.check(a);if(g instanceof Promise&&f?.async===!1)throw new ce;if(p||g instanceof Promise)p=(p??Promise.resolve()).then(async()=>{await g,a.issues.length!==l&&(Xt(a.issues,l,n),c||(c=se(a,l)))});else{if(a.issues.length===l)continue;Xt(a.issues,l,n),c||(c=se(a,l))}}return p?p.then(()=>a):a},s=(a,d,f)=>{if(se(a))return a.aborted=!0,a;let c=i(d,o,f);if(c instanceof Promise){if(f.async===!1)throw new ce;return c.then(p=>n._zod.parse(p,f))}return n._zod.parse(c,f)};n._zod.run=(a,d)=>{if(d.skipChecks)return n._zod.parse(a,d);if(d.direction==="backward"){let c=n._zod.parse({value:a.value,issues:[]},{...d,skipChecks:!0});return c instanceof Promise?c.then(p=>s(p,a,d)):s(c,a,d)}let f=n._zod.parse(a,d);if(f instanceof Promise){if(d.async===!1)throw new ce;return f.then(c=>i(c,o,d))}return i(f,o,d)}}},{get"~standard"(){return nr(this,"~standard",oc(this))},set"~standard"(n){Oe(this,"~standard",n)}}),ki=(n,e)=>n.issues.length?{issues:n.issues.map(t=>ae(t,e,J()))}:{value:n.value};async function rc(n,e){let t={async:!0};return ki(await n._zod.run({value:e,issues:[]},t),t)}function oc(n){return{validate:e=>{let t={async:!1};try{let r=n._zod.run({value:e,issues:[]},t);if(!(r instanceof Promise))return ki(r,t)}catch{}return rc(n,e)},vendor:"zod",version:1}}var fr=O("$ZodString",(n,e)=>{G.init(n,e),n._zod.pattern=e.pattern??oi,n._zod.parse=(t,r)=>{if(e.coerce)try{t.value=String(t.value)}catch{}return typeof t.value=="string"||t.issues.push({expected:"string",code:"invalid_type",input:t.value,inst:n}),t}}),it=O("$ZodStringFormat",(n,e)=>{lr.init(n,e),fr.init(n,e)});var Si=O("$ZodEmail",(n,e)=>{e.pattern??(e.pattern=ti),it.init(n,e)}),$i=1,rt=2;function ic(n){try{return typeof URL<"u"&&typeof URL.canParse=="function"?URL.canParse(n):(new URL(n),!0)}catch{return!1}}function sc(n,e){return!("normalize"in e)&&!("hostname"in e)&&!("protocol"in e)?ic(n)||rt:ac(n,e)}function ac(n,e){if(!e.normalize&&e.protocol?.source===ri.source&&!/^https?:\/\//i.test(n))return $i;try{if(typeof URL<"u"){let t=URL;if(typeof t.parse=="function")return t.parse(n)??rt}return new URL(n)}catch{return rt}}var dc=/[\t\n\r]/g;function yi(n){return n.replace(dc,"")}function cc(n,e){return e.lastIndex=0,e.test(n.hostname)}function uc(n,e){return e.lastIndex=0,e.test(n.protocol.endsWith(":")?n.protocol.slice(0,-1):n.protocol)}var Ri=O("$ZodURL",(n,e)=>{it.init(n,e),n._zod.check=t=>{try{let r=t.value.trim(),o=sc(r,e);if(o===$i){t.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:t.value,inst:n,continue:!e.abort});return}if(o===rt){t.issues.push({code:"invalid_format",format:"url",input:t.value,inst:n,continue:!e.abort});return}if(o===!0){t.value=yi(r);return}e.hostname&&!cc(o,e.hostname)&&t.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:e.hostname.source,input:t.value,inst:n,continue:!e.abort}),e.protocol&&!uc(o,e.protocol)&&t.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:e.protocol.source,input:t.value,inst:n,continue:!e.abort}),t.value=e.normalize?o.href:yi(r);return}catch{t.issues.push({code:"invalid_format",format:"url",input:t.value,inst:n,continue:!e.abort})}}});var pr=O("$ZodNumber",(n,e)=>{G.init(n,e),n._zod.pattern=cr,n._zod.parse=(t,r)=>{if(e.coerce)try{t.value=Number(t.value)}catch{}let o=t.value;if(typeof o=="number"&&!Number.isNaN(o)&&Number.isFinite(o))return t;let i=typeof o=="number"?Number.isNaN(o)?"NaN":Number.isFinite(o)?void 0:String(o):void 0;return t.issues.push({expected:"number",code:"invalid_type",input:o,inst:n,...i?{received:i}:{}}),t}}),_i=O("$ZodNumberFormat",(n,e)=>{li.init(n,e),pr.init(n,e)}),Ai=O("$ZodBoolean",(n,e)=>{G.init(n,e),n._zod.pattern=ii,n._zod.parse=(t,r)=>{if(e.coerce)try{t.value=!!t.value}catch{}let o=t.value;return typeof o=="boolean"||t.issues.push({expected:"boolean",code:"invalid_type",input:o,inst:n}),t}});var Oi=O("$ZodNull",(n,e)=>{G.init(n,e),n._zod.pattern=si,n._zod.values=new Set([null]),n._zod.parse=(t,r)=>{let o=t.value;return o===null||t.issues.push({expected:"null",code:"invalid_type",input:o,inst:n}),t}});var Ei=O("$ZodUnknown",(n,e)=>{G.init(n,e),n._zod.parse=t=>t}),Pi=O("$ZodNever",(n,e)=>{G.init(n,e),n._zod.parse=(t,r)=>(t.issues.push({expected:"never",code:"invalid_type",input:t.value,inst:n}),t)});function bi(n,e,t){n.issues.length&&e.issues.push(...ye(t,n.issues)),e.value[t]=n.value}var zi=O("$ZodArray",(n,e)=>{G.init(n,e);let t=Be.memoizer;t?.attach(n),n._zod.parse=(r,o)=>{let i=r.value;if(!Array.isArray(i))return r.issues.push({expected:"array",code:"invalid_type",input:i,inst:n}),r;r.value=t?t.alloc(n,r,Array(i.length),o):Array(i.length);let s=[],a=o?.abortEarly;for(let d=0;d<i.length;d++){let f=i[d],c=e.element._zod.run({value:f,issues:[]},o);if(c instanceof Promise)s.push(c.then(p=>bi(p,r,d)));else if(bi(c,r,d),a&&c.issues.length!==0&&se(c))break}return s.length?Promise.all(s).then(()=>r):r}});function ot(n,e,t,r,o,i){let s=t in r,a=i==="optional";if(!(!s&&a&&o==="optional")){if(n.issues.length){if(o!==void 0&&a&&!s)return;e.issues.push(...ye(t,n.issues))}if(!s&&o===void 0){n.issues.length||e.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[t]});return}n.value===void 0?(s||o==="defaulted"&&!a)&&(e.value[t]=void 0):e.value[t]=n.value}}var lc=[];function fc(n){let e=Object.keys(n.shape),t=Object.getOwnPropertySymbols(n.shape),r=t.length?t:lc,o=r.length?[...e,...r]:e;for(let s of o)if(!n.shape?.[s]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${String(s)}": expected a Zod schema`);let i=Ko(n.shape);return{...n,allKeys:o,symbolKeys:r,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(i)}}function pc(n,e,t,r,o,i,s){let a=[],d=o.keySet,f=o.catchall._zod,c=f.def.type,p=f.optin,u=f.optout,l=0;for(let g in e){if(s&&t.issues.length!==l){if(se(t,l))break;l=t.issues.length}if(d.has(g))continue;if(g==="__proto__"){c==="never"&&a.push(g);continue}if(c==="never"){a.push(g);continue}let h=f.run({value:e[g],issues:[]},r);h instanceof Promise?n.push(h.then(v=>ot(v,t,g,e,p,u))):ot(h,t,g,e,p,u)}return a.length&&t.issues.push({code:"unrecognized_keys",keys:a,input:e,inst:i,continue:!0}),n.length?Promise.all(n).then(()=>t):t}var Mi=O("$ZodObject",(n,e)=>{G.init(n,e);let t=Object.getOwnPropertyDescriptor(e,"shape"),r=t?.get?t.get.raw:e.shape??{};if(r){let f=()=>{let c={...r};return Object.defineProperty(e,"shape",{value:c}),f.raw=c,c};f.raw=r,Object.defineProperty(e,"shape",{get:f})}let o=jo(()=>fc(e));U(n,"propValues",f=>{let c=f.def.shape,p={};for(let u in c){let l=c[u]._zod;if(l.values){Object.prototype.hasOwnProperty.call(p,u)||nt(p,u,new Set);for(let g of l.values)p[u].add(g);l.optin!==void 0&&p[u].add(void 0)}}return p});let i=et,s=e.catchall,a,d=Be.memoizer;d?.attach(n),n._zod.parse=(f,c)=>{a??(a=o.value);let p=f.value;if(!i(p))return f.issues.push({expected:"object",code:"invalid_type",input:p,inst:n}),f;f.value=d?d.alloc(n,f,{},c):{};let u=[],l=a.shape,g=c?.abortEarly,h=f.issues.length;for(let v of a.allKeys){if(g&&f.issues.length!==h){if(se(f,h))break;h=f.issues.length}if(v==="__proto__")continue;let y=l[v],S=y._zod.optin,A=y._zod.optout,m=y._zod.run({value:p[v],issues:[]},c);m instanceof Promise?u.push(m.then(k=>ot(k,f,v,p,S,A))):ot(m,f,v,p,S,A)}return s?pc(u,p,f,c,o.value,n,g===!0):u.length?Promise.all(u).then(()=>f):f}});function vi(n,e,t,r){for(let i of n)if(i.issues.length===0)return e.value=i.value,e;let o=n.filter(i=>!se(i));return o.length===1?(e.value=o[0].value,o[0]):(e.issues.push({code:"invalid_union",input:e.value,inst:t,errors:n.map(i=>i.issues.map(s=>ae(s,r,J())))}),e)}var Ni=O("$ZodUnion",(n,e)=>{G.init(n,e),U(n,"optin",r=>r.def.options.some(o=>o._zod.optin==="defaulted")?"defaulted":r.def.options.some(o=>o._zod.optin!==void 0)?"optional":void 0),U(n,"optout",r=>r.def.options.some(o=>o._zod.optout==="optional")?"optional":void 0),U(n,"values",r=>{if(r.def.options.every(o=>o._zod.values))return new Set(r.def.options.flatMap(o=>Array.from(o._zod.values)))}),U(n,"pattern",r=>{if(r.def.options.every(o=>o._zod.pattern)){let o=r.def.options.map(i=>i._zod.pattern);return new RegExp(`^(${o.map(i=>Wt(i.source)).join("|")})$`)}});let t=e.options.length===1?e.options[0]._zod.run:null;n._zod.parse=(r,o)=>{if(t)return t(r,o);let i=!1,s=[];for(let a of e.options){let d=a._zod.run({value:r.value,issues:[]},o);if(d instanceof Promise)s.push(d),i=!0;else{if(d.issues.length===0)return d;s.push(d)}}return i?Promise.all(s).then(a=>vi(a,r,n,o)):vi(s,r,n,o)}});var Ii=O("$ZodRecord",(n,e)=>{G.init(n,e);let t=Be.memoizer;t?.attach(n),n._zod.parse=(r,o)=>{let i=r.value;if(!Yt(i))return r.issues.push({expected:"record",code:"invalid_type",input:i,inst:n}),r;let s=[],a=e.keyType._zod.values;if(a&&!e.partial){r.value=t?t.alloc(n,r,{},o):{};let d=new Set;for(let c of a)if(typeof c=="string"||typeof c=="number"||typeof c=="symbol"){if(d.add(typeof c=="number"?c.toString():c),c==="__proto__")continue;let p=e.keyType._zod.run({value:c,issues:[]},o);if(p instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(p.issues.length){r.issues.push({code:"invalid_key",origin:"record",issues:p.issues.map(g=>ae(g,o,J())),input:c,path:[c],inst:n});continue}let u=p.value;if(u==="__proto__")continue;let l=e.valueType._zod.run({value:i[c],issues:[]},o);l instanceof Promise?s.push(l.then(g=>{g.issues.length&&r.issues.push(...ye(c,g.issues)),r.value[u]=g.value})):(l.issues.length&&r.issues.push(...ye(c,l.issues)),r.value[u]=l.value)}let f;for(let c in i)if(!d.has(c))if(e.mode==="loose"){if(c==="__proto__")continue;r.value[c]=i[c]}else f=f??[],f.push(c);f&&f.length>0&&r.issues.push({code:"unrecognized_keys",input:i,inst:n,keys:f,continue:!0})}else{r.value=t?t.alloc(n,r,{},o):{};let d;for(let f of Reflect.ownKeys(i)){if(f==="__proto__"||!Object.prototype.propertyIsEnumerable.call(i,f))continue;let c=e.keyType._zod.run({value:f,issues:[]},o);if(c instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(typeof f=="string"&&cr.test(f)&&c.issues.length){let g=e.keyType._zod.run({value:Number(f),issues:[]},o);if(g instanceof Promise)throw new Error("Async schemas not supported in object keys currently");g.issues.length===0&&(c=g)}if(c.issues.length){e.mode==="loose"?r.value[f]=i[f]:a?(d=d??[],d.push(f)):r.issues.push({code:"invalid_key",origin:"record",issues:c.issues.map(g=>ae(g,o,J())),input:f,path:[f],inst:n});continue}let u=c.value;if(u==="__proto__")continue;let l=e.valueType._zod.run({value:i[f],issues:[]},o);l instanceof Promise?s.push(l.then(g=>{g.issues.length&&r.issues.push(...ye(f,g.issues)),r.value[u]=g.value})):(l.issues.length&&r.issues.push(...ye(f,l.issues)),r.value[u]=l.value)}d&&d.length>0&&r.issues.push({code:"unrecognized_keys",input:i,inst:n,keys:d,continue:!0})}return s.length?Promise.all(s).then(()=>r):r}});var ji=O("$ZodEnum",(n,e)=>{G.init(n,e);let t=Ut(e.entries),r=new Set(t);n._zod.values=r,U(n,"pattern",o=>{let i=Ut(o.def.entries).filter(s=>Bo.has(typeof s));return new RegExp(i.length?`^(${i.map(s=>wn(s.toString())).join("|")})$`:"^[^\\s\\S]$")}),n._zod.parse=(o,i)=>{let s=o.value;return r.has(s)||o.issues.push({code:"invalid_value",values:t,input:s,inst:n}),o}}),Ti=O("$ZodLiteral",(n,e)=>{G.init(n,e);let t=new Set(e.values);n._zod.values=t,U(n,"pattern",r=>{let o=r.def.values;return new RegExp(o.length?`^(${o.map(i=>typeof i=="string"?wn(i):i?wn(i.toString()):String(i)).join("|")})$`:"^[^\\s\\S]$")}),n._zod.parse=(r,o)=>{let i=r.value;return t.has(i)||r.issues.push({code:"invalid_value",values:e.values,input:i,inst:n}),r}});function xi(n,e){return n.value=e.issues.length?void 0:e.value,n}var Di=O("$ZodOptional",(n,e)=>{G.init(n,e),U(n,"optin",t=>t.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),n._zod.optout="optional",U(n,"values",t=>{let r=t.def.innerType._zod.values;return r?new Set([...r,void 0]):void 0}),U(n,"pattern",t=>{let r=t.def.innerType._zod.pattern;return r?new RegExp(`^(${Wt(r.source)})?$`):void 0}),n._zod.parse=(t,r)=>{if(t.value===void 0){if(e.innerType._zod.optin!=="defaulted")return t;let o=e.innerType._zod.run({value:t.value,issues:[]},r);return o instanceof Promise?o.then(i=>xi(t,i)):xi(t,o)}return e.innerType._zod.run(t,r)}});var Fi=O("$ZodLazy",(n,e)=>{G.init(n,e),Fo(n._zod,"innerType",()=>{let t=e;return t._cachedInner||(t._cachedInner=e.getter()),t._cachedInner}),U(n,"pattern",t=>t.innerType?._zod?.pattern),U(n,"propValues",t=>t.innerType?._zod?.propValues),U(n,"optin",t=>t.innerType?._zod?.optin??void 0),U(n,"optout",t=>t.innerType?._zod?.optout??void 0),n._zod.parse=(t,r)=>n._zod.innerType._zod.run(t,r)}),Zi=O("$ZodCustom",(n,e)=>{X.init(n,e),G.init(n,e),n._zod.parse=(t,r)=>t,n._zod.check=t=>{let r=t.value,o=e.fn(r);if(o instanceof Promise)return o.then(i=>wi(i,t,r,n));wi(o,t,r,n)}});function wi(n,e,t,r){if(!n){let o={code:"custom",input:t,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(o.params=r._zod.def.params),e.issues.push(kn(o))}}var hc=()=>{let n={string:{unit:"characters",verb:"to have"},file:{unit:"bytes",verb:"to have"},array:{unit:"items",verb:"to have"},set:{unit:"items",verb:"to have"},map:{unit:"entries",verb:"to have"}};function e(i){return n[i]??null}let t={regex:"input",email:"email address",url:"URL",emoji:"emoji",uuid:"UUID",uuidv4:"UUIDv4",uuidv6:"UUIDv6",nanoid:"nanoid",guid:"GUID",cuid:"cuid",cuid2:"cuid2",ulid:"ULID",xid:"XID",ksuid:"KSUID",datetime:"ISO datetime",date:"ISO date",time:"ISO time",duration:"ISO duration",ipv4:"IPv4 address",ipv6:"IPv6 address",mac:"MAC address",cidrv4:"IPv4 range",cidrv6:"IPv6 range",base64:"base64-encoded string",base64url:"base64url-encoded string",json_string:"JSON string",e164:"E.164 number",currency_code:"currency code",credit_card:"credit card number",iban:"IBAN",jwt:"JWT",template_literal:"input"},r={nan:"NaN"};function o(i,s){return i==="number"&&typeof s=="number"&&!Number.isFinite(s)?String(s):r[i]??i}return i=>{switch(i.code){case"invalid_type":{let s=o(i.expected),a=qo(i.input),d=o(a,i.input);return`Invalid input: expected ${s}, received ${d}`}case"invalid_value":return i.values.length===1?`Invalid input: expected ${Jt(i.values[0])}`:`Invalid option: expected one of ${Vt(i.values,"|")}`;case"too_big":{let s=i.exact?"exactly ":i.inclusive?"<=":"<",a=e(i.origin);return a?`Too big: expected ${i.origin??"value"} to have ${s}${i.maximum.toString()} ${a.unit??"elements"}`:`Too big: expected ${i.origin??"value"} to be ${s}${i.maximum.toString()}`}case"too_small":{let s=i.exact?"exactly ":i.inclusive?">=":">",a=e(i.origin);return a?`Too small: expected ${i.origin} to have ${s}${i.minimum.toString()} ${a.unit}`:`Too small: expected ${i.origin} to be ${s}${i.minimum.toString()}`}case"invalid_format":{let s=i;return s.format==="starts_with"?`Invalid string: must start with "${s.prefix}"`:s.format==="ends_with"?`Invalid string: must end with "${s.suffix}"`:s.format==="includes"?`Invalid string: must include "${s.includes}"`:s.format==="regex"?`Invalid string: must match pattern ${s.pattern}`:`Invalid ${t[s.format]??i.format}`}case"not_multiple_of":return`Invalid number: must be a multiple of ${i.divisor}`;case"unrecognized_keys":return`Unrecognized key${i.keys.length>1?"s":""}: ${Vt(i.keys,", ")}`;case"invalid_key":return`Invalid key in ${i.origin}`;case"invalid_union":return i.options&&Array.isArray(i.options)&&i.options.length>0?`Invalid discriminator value. Expected ${i.options.map(a=>`'${a}'`).join(" | ")}`:i.inclusive===!1?"Invalid input: more than one option matched":"Invalid input";case"invalid_element":return`Invalid value in ${i.origin}`;default:return"Invalid input"}}};function Li(){return{localeError:hc()}}var Ci;var hr=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let r=t[0];return this._map.set(e,r),r&&typeof r=="object"&&"id"in r&&this._idmap.set(r.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t=="object"&&"id"in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let r={...this.get(t)??{}};delete r.id;let o={...r,...this._map.get(e)};return Object.keys(o).length?o:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function Gi(){return new hr}(Ci=globalThis).__zod_globalRegistry??(Ci.__zod_globalRegistry=Gi());var Ke=globalThis.__zod_globalRegistry;function Bi(n){return n.checks&&(n.checks=[...n.checks]),n}function Ki(n,e){return new n(Bi({type:"string",...M(e)}))}function Ui(n,e){return new n({type:"string",format:"email",check:"string_format",abort:!1,...M(e)})}function Vi(n,e){return new n({type:"string",format:"url",check:"string_format",abort:!1,...M(e)})}function Wi(n,e){return new n(Bi({type:"number",checks:[],...M(e)}))}function qi(n,e){return new n({type:"number",check:"number_format",abort:!1,format:"safeint",...M(e)})}function Hi(n,e){return new n({type:"boolean",...M(e)})}function Yi(n,e){return new n({type:"null",...M(e)})}function Ji(n){return new n({type:"unknown"})}function Xi(n,e){return new n({type:"never",...M(e)})}function Qi(n,e){return new di({check:"less_than",...M(e),value:n,inclusive:!0})}function es(n,e){return new ci({check:"greater_than",...M(e),value:n,inclusive:!0})}function bc(n,e){return new ui({check:"multiple_of",...M(e),value:n})}function gr(n,e){return new fi({check:"max_length",...M(e),maximum:n})}function $n(n,e){return new pi({check:"min_length",...M(e),minimum:n})}function Rn(n,e){return new hi({check:"string_format",format:"regex",...M(e),pattern:n})}function ns(n,e,t){return new n({type:"custom",check:"custom",fn:e,...M(t)})}function ts(n,e){let t=vc(r=>(r.addIssue=o=>{if(typeof o=="string")r.issues.push(kn(o,r.value,t._zod.def));else{let i=o;i.fatal&&(i.continue=!1),i.code??(i.code="custom"),"input"in i||(i.input=r.value),i.inst??(i.inst=t),i.continue??(i.continue=!t._zod.def.abort),r.issues.push(kn(i))}},n(r.value,r)),e);return t}function vc(n,e){let t=new X({check:"custom",...M(e)});return t._zod.check=n,t}function rs(n){let e=new X({check:"describe"});return e._zod.onattach=[t=>{let r=Ke.get(t)??{};Ke.add(t,{...r,description:n})}],e._zod.check=()=>{},e}var V=O("ZodMiniType",(n,e)=>{if(!n._zod)throw new Error("Uninitialized schema in ZodMiniType.");G.init(n,e),n.def=e,n.type=e.type},{get with(){return this.check},set with(n){Oe(this,"with",n)},parse(n,e){return ir(this,n,e,{callee:this.parse})},parseAsync(n,e){return sr(this,n,e,{callee:this.parseAsync})},safeParse(n,e){return ar(this,n,e)},safeParseAsync(n,e){return dr(this,n,e)},check(...n){let e=this.def;return this.clone({...e,checks:[...e.checks??[],...n.map(t=>typeof t=="function"?{_zod:{check:t,def:{check:"custom"},onattach:[]}}:t)]},{parent:!0})},clone(n,e){return Ge(this,n,e)},brand(){return this},register(n,e){return n.add(this,e),this},apply(n,...e){return e.length===0?n(this):n(this,...e)}}),is=O("ZodMiniString",(n,e)=>{fr.init(n,e),V.init(n,e)});function D(n){return Ki(is,n)}var ss=O("ZodMiniStringFormat",(n,e)=>{it.init(n,e),is.init(n,e)}),kc=O("ZodMiniEmail",(n,e)=>{Si.init(n,e),ss.init(n,e)});function Cg(n){return Ui(kc,n)}var Sc=O("ZodMiniURL",(n,e)=>{Ri.init(n,e),ss.init(n,e)});function Gg(n){return Vi(Sc,n)}var as=O("ZodMiniNumber",(n,e)=>{pr.init(n,e),V.init(n,e)});function _n(n){return Wi(as,n)}var $c=O("ZodMiniNumberFormat",(n,e)=>{_i.init(n,e),as.init(n,e)});function Bg(n){return qi($c,n)}var Rc=O("ZodMiniBoolean",(n,e)=>{Ai.init(n,e),V.init(n,e)});function Kg(n){return Hi(Rc,n)}var _c=O("ZodMiniNull",(n,e)=>{Oi.init(n,e),V.init(n,e)});function Ug(n){return Yi(_c,n)}var Ac=O("ZodMiniUnknown",(n,e)=>{Ei.init(n,e),V.init(n,e)});function mr(){return Ji(Ac)}var Oc=O("ZodMiniNever",(n,e)=>{Pi.init(n,e),V.init(n,e)});function Ec(n){return Xi(Oc,n)}var Pc=O("ZodMiniArray",(n,e)=>{zi.init(n,e),V.init(n,e)});function Vg(n,e){return new Pc({type:"array",element:n,...M(e)})}var yr=O("ZodMiniObject",(n,e)=>{Mi.init(n,e),V.init(n,e),Yo(n,"shape",t=>t._zod.def.shape,!1)});function Ue(n,e){let t={type:"object",shape:n??{},...M(e)};return new yr(t)}function Ve(n,e){return new yr({type:"object",shape:n,catchall:Ec(),...M(e)})}function Wg(n,e){return new yr({type:"object",shape:n,catchall:mr(),...M(e)})}function ds(n,e){return Vo(n,e)}var zc=O("ZodMiniUnion",(n,e)=>{Ni.init(n,e),V.init(n,e)});function qg(n,e){return new zc({type:"union",options:n,...M(e)})}var os=O("ZodMiniRecord",(n,e)=>{Ii.init(n,e),V.init(n,e)});function Hg(n,e,t){return!e||!e._zod?new os({type:"record",keyType:D(),valueType:n,...M(e)}):new os({type:"record",keyType:n,valueType:e,...M(t)})}var Mc=O("ZodMiniEnum",(n,e)=>{ji.init(n,e),V.init(n,e),n.options=[...n._zod.values]});function cs(n,e){let t=Array.isArray(n)?Object.fromEntries(n.map(r=>[r,r])):n;return new Mc({type:"enum",entries:t,...M(e)})}var Nc=O("ZodMiniLiteral",(n,e)=>{Ti.init(n,e),V.init(n,e)});function us(n,e){return new Nc({type:"literal",values:Array.isArray(n)?n:[n],...M(e)})}var Ic=O("ZodMiniOptional",(n,e)=>{Di.init(n,e),V.init(n,e)});function Q(n){return new Ic({type:"optional",innerType:n})}var jc=O("ZodMiniLazy",(n,e)=>{Fi.init(n,e),V.init(n,e)});function Yg(n){return new jc({type:"lazy",getter:n})}var Tc=O("ZodMiniCustom",(n,e)=>{Zi.init(n,e),V.init(n,e)});function st(n,e={}){return ns(Tc,n,e)}function Jg(n,e){return ts(n,e)}var Xg=rs;J().localeError||J(Li());var I=n=>typeof n=="object"&&n!==null?n._zod?.def:void 0,Dc=n=>{if(typeof n!="object"||n===null||!("_zod"in n))return;let e=Ke.get(n)?.description;return typeof e=="string"?e:void 0};var Fc=(n,e)=>n?.src?.(e)??e,at=n=>typeof n=="string"&&n.length<2049&&/^(?![^/?#]*:|\/\/)(?!(?:.*\/)?\.\.?(?:[/?#]|$))(?!.*%2e)[^\\\s]+$/i.test(n),br=(n,e=1)=>e>0&&n===void 0||Number.isInteger(n)&&n>=e;function vr(n){let e=n??{};return at(e.href)&&typeof e.name=="string"&&/^.{1,255}$/s.test(e.name)&&/^[\w.+-]{1,60}\/[\w.+-]{1,60}$/.test(e.type)&&br(e.bytes,0)&&br(e.width)&&br(e.height)&&(e.caption===void 0||typeof e.caption=="string"&&e.caption.length<501)&&(e.poster===void 0||at(e.poster))&&(e.captions===void 0||at(e.captions))&&(e.duration===void 0||typeof e.duration=="number"&&Number.isFinite(e.duration)&&e.duration>0)&&(e.at===void 0||ls(e.at)!==void 0)}function ls(n){return typeof n=="string"&&n.length<41&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?(Z|[+-]\d{2}:?\d{2})$/.test(n)&&Number.isFinite(Date.parse(n))?n:void 0}var fs=n=>n.type.startsWith("image/"),ps=n=>n.type.startsWith("video/");function Zc(n){let e=n.duration===void 0?0:Math.round(n.duration);if(e<1)return"a video";if(e<60)return`a ${e}-second video`;let t=Math.round(e/60);return t<60?`a ${t}-minute video`:`a ${Math.floor(t/60)}-hour${t%60>0?` ${t%60}-minute`:""} video`}var Lc=(n,e)=>e==="image"?fs(n):e==="video"?ps(n):!0,Cc=n=>`${n==="image"?"an image":n==="video"?"a video":"a file"} the host stored, at a path on this host`,An=n=>(Array.isArray(n)?n:[n]).filter(vr),hs=Symbol.for("@graview/core:file"),Gc=(n,e)=>(Object.defineProperty(I(n),hs,{value:e,enumerable:!0}),n);function gs(n){let e=I(n);return e?.[hs]??(e?.innerType?gs(e.innerType):void 0)}var Bc=()=>({href:D(),name:D(),type:D(),bytes:_n(),width:Q(_n()),height:Q(_n()),caption:Q(D()),poster:Q(D()),duration:Q(_n()),captions:Q(D()),at:Q(D())});function Qm(n){return Gc(Ue(Bc()).check(st(e=>vr(e)&&Lc(e,n),Cc(n))),n)}var dt=/^(?:https?:\/\/[^\s<>"'`\\]+|@?[A-Za-z0-9][\w.~-]*(?:\/[\w.~-]+)*)$/,ct=n=>typeof n=="string"&&n.length<501&&dt.test(n);var ms=n=>typeof n=="object"&&n!==null?n._zod?.def:void 0,Kc=/^@(?:https?:\/\/[^\s<>"'`\\#?]+|[A-Za-z0-9][\w.~-]*(?:\/[\w.~-]+)*)\/[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;function ys(n){if(typeof n!="string"||!n.startsWith("@")||!Kc.test(n))return;let e=n.lastIndexOf("/"),t=n.slice(0,e),r=n.slice(e+1),o=/^@https?:\/\//.test(t)||!t.includes("/")?t.slice(1):t;return ct(o)?{address:o,kind:r}:void 0}var Uc=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*:\S[^\n]{0,199}$/,Vc=n=>`${n.kind}:${n.id}`;function bs(n,e){if(typeof n!="string"||!Uc.test(n))return;let t=n.indexOf(":"),r=n.slice(0,t);return e.kinds.includes(r)?{address:e.address,kind:r,id:n.slice(t+1)}:void 0}function Wc(n,e){return(Array.isArray(n)?n:n==null?[]:[n]).flatMap(r=>{let o=bs(r,e);return o?[o]:[]})}var vs=Symbol.for("@graview/core:linked"),ry=(n,e)=>(Object.defineProperty(ms(n),vs,{value:e,enumerable:!0}),n);function On(n){let e=ms(n);return e?e[vs]??On(e.innerType):void 0}function qc(n){let e=n?.fields?.shape??{},t=new Map;for(let[r,o]of Object.entries(e)){let i=On(o);i&&t.set(r,i)}return t}function Hc(n){if(n.to==="*"||n.to.length===0)return;let e=n.to.map(ys);if(e.some(r=>!r))return;let t=e[0].address;if(!e.some(r=>r.address!==t))return{address:t,kinds:[...new Set(e.map(r=>r.kind))],cardinality:n.cardinality??"many",...n.description?{description:n.description}:{}}}var Yc=n=>n.to!=="*"&&n.to.some(e=>typeof e=="string"&&e.startsWith("@"));function oy(n){return Object.fromEntries(Object.entries(n??{}).filter(([,e])=>!Yc(e)))}function iy(n){let e=new Map;for(let[t,r]of Object.entries(n??{})){let o=Hc(r);o&&e.set(t,o)}return e}var xr=new WeakMap;function Jc(n,e){e?xr.set(n,e):xr.delete(n)}var xs=n=>xr.get(n);var ut=["sun","mon","tue","wed","thu","fri","sat"],Xc=["day","week","month","year"],qe=n=>`${n}Repeat`,Pn=n=>n.endsWith("Repeat")&&n.length>6?n.slice(0,-6):void 0,Ss=/^\d{4}-\d{2}-\d{2}$/,$s=Symbol.for("@graview/core:repeat");function lt(n){let e=I(n);return!!e&&(e[$s]===1||lt(e.innerType))}var Qc=n=>(Object.defineProperty(I(n),$s,{value:1,enumerable:!0}),n),wr=(n,e,t)=>n===void 0||Number.isInteger(n)&&n>=e&&n<=t,ws=(n,e)=>n===void 0||Array.isArray(n)&&n.length<=e&&n.every(t=>typeof t=="string"&&Ss.test(t)),eu=["every","interval","on","until","count","except","continues"],Rs=n=>He(n)&&Object.keys(n).every(e=>eu.includes(e))&&wr(n.interval,1,99)&&wr(n.count,1,1e3)&&ws(n.until===void 0?void 0:[n.until],1)&&ws(n.except,500)&&(n.continues===void 0||typeof n.continues=="string"&&n.continues.length<=200)&&(n.on===void 0||Array.isArray(n.on)&&n.on.length>0&&n.on.length<=31&&n.on.every(e=>n.every==="week"?ut.includes(e):n.every==="month"&&e!==0&&wr(e,-1,31))),dy=()=>Qc(mr().check(st(n=>n===null||Rs(n),"how a date repeats, or null"))),En=n=>Date.UTC(+n.slice(0,4),+n.slice(5,7)-1,+n.slice(8,10)),_s=n=>new Date(n).toISOString().slice(0,10),kr=(n,e)=>_s(En(n)+e*864e5),ks=(n,e,t)=>{let r=new Date(Date.UTC(n,e+1,0)).getUTCDate();return _s(Date.UTC(n,e,t<0||t>r?r:t))},He=n=>typeof n=="object"&&n!==null&&Xc.includes(n.every);function We(n,e,t={}){let r=n.slice(0,10),o=n.slice(10),i=[];if(!Ss.test(r))return i;let s=Math.max(1,e.interval??1),a=e.every,d=t.from&&t.from>r?t.from.slice(0,10):r,f=[e.until,t.to?.slice(0,10)].filter(Boolean).sort()[0],c=t.limit??1e3,p=new Set(e.except??[]),u=+r.slice(0,4),l=+r.slice(5,7)-1,g=+r.slice(8,10),h=kr(r,-new Date(En(r)).getUTCDay()),v=(e.on?.length?e.on:[a==="week"?ut[new Date(En(r)).getUTCDay()]:g]).map(k=>typeof k=="string"?ut.indexOf(k):k),y=a==="day"?1:a==="week"?7:0,S=(+d.slice(0,4)-u)*12+(+d.slice(5,7)-1-l),A=e.count?0:Math.max(0,Math.floor((y?(En(d)-En(y===7?h:r))/864e5/y:a==="month"?S:S/12)/s)-1),m=0;for(let k=0;k<5e4&&i.length<c;k++,A++){let w=A*s,x=a==="day"?[kr(r,w)]:a==="week"?v.map(b=>kr(h,w*7+b)):a==="month"?v.map(b=>ks(u,l+w,b)):[ks(u+w,l,g)];for(let b of[...new Set(x)].sort())if(!(b<r)&&(f&&b>f||e.count&&m>=e.count||(m++,b>=d&&!p.has(b)&&i.push(b+o),i.length>=c)))return i}return i}function As(n,e,t){if(!He(e)||typeof n!="string")return n;let r=We(n,e,{from:t,limit:1})[0];if(r)return r;let o=e.until||e.count?We(n,e):[];return o[o.length-1]??n}function nu(n,e,t){let r=n[e],o=n[qe(e)];return typeof r=="string"&&He(o)?As(r,o,t):r}function zn(n,e){if(n.onBehalfOf){let{onBehalfOf:i,...s}=n;return`${zn(s,e)}, for ${zn(i,e)}`}if(n.id===void 0)return n.name??(n.kind==="agent"?"an agent":n.kind);let t=e.graph.getNode(n.id);if(t)return F(e.schema.tryDefinition(t.kind),t);let r=e.seats?.find(i=>i.principal.id===n.id);if(r)return r.label;let o=e.people?.find(i=>i.id===n.id&&(i.kind===void 0||i.kind===n.kind));return o?o.name:n.name?n.name:/(^|:)migration$/.test(n.id)?"the upgrade":/[:_/]/.test(n.id)?{human:"somebody",agent:"an agent",rule:"a rule",system:"the system"}[n.kind]:n.id}var Ye="$archived",Ee=n=>n?.[Ye]===!0,fy=(n,e=!1)=>e==="all"||Ee(n)===e,Sr=n=>n===!0||n==="true"?!0:n==="all"?"all":!1,Mn="$leftAlone",ft=new Set([Ye,Mn]);var te=class extends Error{constructor(t,r){super(r?`${t}
|
|
2
|
+
\u2192 ${r}`:t);this.hint=r;this.name="SchemaError"}};function tu(n,e){let t=n,r=new Map;for(let a of t){if(r.has(a.kind))throw new te(`Duplicate node kind "${a.kind}"`,"Each kind may be declared once; merge the two defineNode calls.");r.set(a.kind,a)}let o=new Map;for(let a of t)for(let[d,f]of Object.entries(a.edges)){if(f.to!=="*"){for(let p of f.to)if(!r.has(p))throw new te(`Edge "${d}" on "${a.kind}" points at undeclared kind "${p}"`,`Declared kinds: ${[...r.keys()].join(", ")}`)}let c=o.get(d);c?c.from.push(a.kind):o.set(d,{from:[a.kind],decl:f})}let i=new Map;for(let[a,{from:d,decl:f}]of o){let c=d.map(p=>r.get(p).edges[a].to);i.set(a,{kind:a,from:d,to:c.includes("*")?"*":[...new Set(c.flat())],cardinality:f.cardinality??"many",...f.description===void 0?{}:{description:f.description}})}let s=new Map;for(let a of t)s.set(a.kind,ds(a.fields,{id:D().check($n(1)),kind:us(a.kind)}));return{definitions:t,computed:e,kinds:t.map(a=>a.kind),edgeKinds:[...i.keys()],definition(a){let d=r.get(a);if(!d)throw new te(`Unknown node kind "${String(a)}"`,`Declared kinds: ${[...r.keys()].join(", ")}`);return d},tryDefinition(a){return r.get(a)},edge(a){return i.get(a)},edgeAllowed(a,d,f){let c=r.get(d)?.edges[a];return c?c.to==="*"||c.to.includes(f):!1},parseNode(a){let d=a?.kind;if(typeof d!="string")throw new te("Node is missing a `kind`");let f=s.get(d);if(!f)throw new te(`Unknown node kind "${d}"`,`Declared kinds: ${[...r.keys()].join(", ")}`);let c={},p={};for(let[l,g]of Object.entries(a))ft.has(l)?g===!0&&(p[l]=!0):c[l]=g;let u=f.parse(c);return Object.keys(p).length>0?{...u,...p}:u},__node:void 0}}function z(n){return`${n.kind}\0${n.from}\0${n.to}`}var Nn={addedNodes:[],removedNodes:[],changedNodes:[],addedEdges:[],removedEdges:[],touched:[]};function Os(n){return n.addedNodes.length===0&&n.removedNodes.length===0&&n.changedNodes.length===0&&n.addedEdges.length===0&&n.removedEdges.length===0}function ru(n,e){let t=new Set([...Object.keys(n),...Object.keys(e)]),r=[];for(let o of t){let i=n[o],s=e[o];JSON.stringify(i)!==JSON.stringify(s)&&r.push(o)}return r.sort()}function Je(n,e){let t=new Map(n.nodes.map(u=>[u.id,u])),r=new Map(e.nodes.map(u=>[u.id,u])),o=e.nodes.filter(u=>!t.has(u.id)),i=n.nodes.filter(u=>!r.has(u.id)),s=[];for(let u of n.nodes){let l=r.get(u.id);if(!l||l===u)continue;let g=ru(u,l);g.length>0&&s.push({before:u,after:l,fields:g})}let a=new Map(n.edges.map(u=>[z(u),u])),d=new Map(e.edges.map(u=>[z(u),u])),f=e.edges.filter(u=>!a.has(z(u))),c=n.edges.filter(u=>!d.has(z(u))),p=new Set;for(let u of o)p.add(u.id);for(let u of i)p.add(u.id);for(let u of s)p.add(u.after.id);for(let u of[...f,...c])p.add(u.from),p.add(u.to);return{addedNodes:o,removedNodes:i,changedNodes:s,addedEdges:f,removedEdges:c,touched:[...p].sort()}}function be(n,e,t){let r=new Set(t.flatMap(i=>i.op==="patch-node"?[i.id]:"node"in i?[i.node.id]:[i.edge.from,i.edge.to]));if(r.size===0)return Nn;let o=i=>({nodes:i.nodes.filter(s=>r.has(s.id)),edges:i.edges.filter(s=>r.has(s.from)||r.has(s.to))});return Je(o(n),o(e))}function ou(n){let e=n?.issues;return!Array.isArray(e)||e.length===0?n instanceof Error?n.message:String(n):e.map(t=>{let r=t.path?.length?C(String(t.path.at(-1))):null,o=t.message??"is not what the declaration allows";return r?`${r}: ${o}`:o}).join("; ")}var N=class extends Error{constructor(t,r){super(r?`${t}
|
|
3
|
+
${r}`:t);this.hint=r;this.name="GraphError"}},B=class extends N{constructor(t,r){super(r);this.id=t;this.name="MissingRecordError"}};function pt(n,e){try{n.parseNode(e);return}catch(t){if(t instanceof te)throw t;let r=t.issues??[];return{fields:new Set(r.flatMap(i=>i.code==="unrecognized_keys"&&i.keys?[...i.keys]:typeof i.path?.[0]=="string"?[i.path[0]]:[""])),error:t}}}var $r="n\0",Rr="e\0",W=class n{constructor(e,t={}){this.schema=e;this.validate=t.validate??!0}nodes=new Map;edges=new Map;outIndex=new Map;inIndex=new Map;rank=0;ranks=new Map;lapsed=new Map;reordered=!1;counts=new Map;archived=new Set;listeners=new Set;validate;static from(e,t,r={}){let o=new n(e,r);return o.load(t),o}load(e){let t=this.snapshot();this.restore(e);let r=Je(t,this.snapshot());return this.emit(r),r}getNode(e){return this.nodes.get(e)}has(e){return this.nodes.has(e)}allNodes(e){return this.reach([...this.nodes.values()],e,this.held)}count(e,t){return t||this.archived.size?this.nodesOfKind(e,t).length:this.counts.get(e)??0}allEdges(e){return this.reach([...this.edges.values()],e,t=>this.archived.has(t.from)||this.archived.has(t.to))}nodesOfKind(e,t){return this.allNodes(t).filter(r=>r.kind===e)}edgesOfKind(e,t){return this.allEdges(t).filter(r=>r.kind===e)}out(e,t,r){return this.reach(this.resolve(this.outIndex.get(e),t,"to"),r,this.held)}in(e,t,r){return this.reach(this.resolve(this.inIndex.get(e),t,"from"),r,this.held)}neighbors(e,t){let r=new Map;for(let o of[...this.out(e,void 0,t),...this.in(e,void 0,t)])r.set(o.id,o);return[...r.values()]}isArchived(e){return this.archived.has(e)}outEdges(e,t){return this.edgesFrom(this.outIndex.get(e),t)}inEdges(e,t){return this.edgesFrom(this.inIndex.get(e),t)}snapshot(){return{nodes:[...this.nodes.values()],edges:[...this.edges.values()]}}get size(){return{nodes:this.nodes.size,edges:this.edges.size}}applyPrimitives(e,t={}){let r=this.snapshot();try{for(let i of e)this.applyOne(i,t.restoring===!0,t.inPlace===!0);this.settleOrder()}catch(i){throw this.restore(r),i}let o=be(r,this.snapshot(),e);return this.emit(o),o}preview(e,t={}){return n.from(this.schema,this.snapshot(),{validate:this.validate}).applyPrimitives(e,t)}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}restore(e){for(let t of[this.nodes,this.edges,this.outIndex,this.inIndex,this.ranks,this.lapsed,this.counts,this.archived])t.clear();this.reordered=!1;for(let t of e.nodes)this.insertNode(t,!0);for(let t of e.edges)this.insertEdge(t,!0)}tally(e,t){this.counts.set(e,(this.counts.get(e)??0)+t)}place(e,t){let r=t?this.lapsed.get(e):void 0;if(r===void 0){this.ranks.set(e,++this.rank);return}this.ranks.set(e,r),this.lapsed.delete(e),this.reordered=!0}lapse(e){let t=this.ranks.get(e);t!==void 0&&(this.ranks.delete(e),this.lapsed.set(e,t),this.lapsed.size>4096&&this.lapsed.delete(this.lapsed.keys().next().value))}settleOrder(){if(!this.reordered)return;this.reordered=!1;let e=o=>(i,s)=>this.ranks.get(o+i[0])-this.ranks.get(o+s[0]),t=[...this.nodes.entries()].sort(e($r));this.nodes.clear();for(let[o,i]of t)this.nodes.set(o,i);let r=[...this.edges.entries()].sort(e(Rr));this.edges.clear();for(let[o,i]of r)this.edges.set(o,i)}emit(e){if(!(e.addedNodes.length===0&&e.removedNodes.length===0&&e.changedNodes.length===0&&e.addedEdges.length===0&&e.removedEdges.length===0))for(let t of this.listeners)t(e)}applyOne(e,t,r){switch(e.op){case"add-node":this.insertNode(e.node,t,r);return;case"remove-node":{let o=e.node.id,i=this.nodes.get(o);if(!i)throw new B(o,`Cannot remove missing node "${o}"`);for(let s of[...this.outEdges(o),...this.inEdges(o)])this.deleteEdge(s);this.tally(i.kind,-1),this.archived.delete(o),this.nodes.delete(o),this.lapse($r+o),this.outIndex.delete(o),this.inIndex.delete(o);return}case"patch-node":{let o=this.nodes.get(e.id);if(!o)throw new B(e.id,`Cannot patch missing node "${e.id}"`);let i={...o};for(let[a,d]of Object.entries(e.after))De(d)?delete i[a]:i[a]=d;let s=t?i:this.checkPatch(o,i,Object.keys(e.after));this.nodes.set(e.id,s),this.archived[Ee(s)?"add":"delete"](e.id),s.kind!==o.kind&&(this.tally(o.kind,-1),this.tally(s.kind,1));return}case"add-edge":this.insertEdge(e.edge,t,r);return;case"remove-edge":{if(!this.edges.has(z(e.edge)))throw new B(z(e.edge),`Cannot remove missing edge ${z(e.edge)}`);this.deleteEdge(e.edge);return}}}check(e){if(!this.validate)return e;try{return this.schema.parseNode(e)}catch(t){throw this.refusal(e,t)}}checkPatch(e,t,r){if(!this.validate)return t;let o=this.schema.tryDefinition(String(t.kind))?.fields?.shape;if(!o)return this.check(t);for(let a of r){if(a==="id"||a==="kind"||ft.has(a))continue;let d=o[a];if(!d){delete t[a];continue}let f=d.safeParse(t[a]);f.success&&(f.data===void 0?delete t[a]:t[a]=f.data)}let i=pt(this.schema,t);if(i===void 0)return t;let s=pt(this.schema,e)?.fields??new Set;if([...i.fields].some(a=>r.includes(a)||!s.has(a)))throw this.refusal(t,i.error);return t}refusal(e,t){if(t instanceof te)return t;{let r=e?.id??"?",o=e?.kind??"?",i=this.schema.tryDefinition(o),s=i&&e&&typeof e=="object"?F(i,e):r;return new N(`${s} does not match what ${o} declares`,ou(t))}}insertNode(e,t,r=!1){if(this.nodes.has(e.id))throw new N(`Duplicate node id "${e.id}"`);this.nodes.set(e.id,t?e:this.check(e)),Ee(e)&&this.archived.add(e.id),this.tally(e.kind,1),this.place($r+e.id,r)}insertEdge(e,t,r=!1){let o=this.nodes.get(e.from),i=this.nodes.get(e.to);if(!o||!i){let a=o?e.to:e.from;throw new B(a,`Edge "${e.kind}" references missing node "${a}"`)}if(this.validate&&!t&&!this.schema.edgeAllowed(e.kind,o.kind,i.kind)){let a=this.schema.edge(e.kind);throw new N(`Edge "${e.kind}" is not declared from ${o.kind} to ${i.kind}`,a?`Declared: ${a.from.join("|")} -> ${a.to==="*"?"*":a.to.join("|")}`:`No edge kind "${e.kind}" is declared in this schema`)}let s=z(e);this.edges.has(s)||(this.edges.set(s,e),this.place(Rr+s,r),this.index(this.outIndex,e.from,s),this.index(this.inIndex,e.to,s))}deleteEdge(e){let t=z(e);this.edges.delete(t),this.lapse(Rr+t),this.outIndex.get(e.from)?.delete(t),this.inIndex.get(e.to)?.delete(t)}index(e,t,r){(e.get(t)??e.set(t,new Set).get(t)).add(r)}edgesFrom(e,t){if(!e)return[];let r=[];for(let o of e){let i=this.edges.get(o);i&&(t===void 0||i.kind===t)&&r.push(i)}return r}resolve(e,t,r){let o=[];for(let i of this.edgesFrom(e,t)){let s=this.nodes.get(i[r]);s&&o.push(s)}return o}held=e=>this.archived.has(e.id);reach(e,t,r){let o=t?.archived??!1;return o==="all"||!o&&!this.archived.size?e:e.filter(i=>r(i)===o)}};var ht=class extends Error{constructor(t,r){super(`No invariant registered under "${t}" (required by node "${r}")`);this.invariant=t;this.nodeId=r;this.name="UnregisteredInvariantError"}};function iu(n,e){return{...e,name:n}}var gt=class extends Error{constructor(e){super(e),this.name="RuleBudgetError"}};function Es(n,e,t){try{return e().map(r=>r.status?r:{...r,status:"violated"})}catch(r){let o=r instanceof gt,i=r instanceof Error?r.message:String(r),s=n.label??n.name.replace(/-/g," ");return[{invariant:n.name,status:o?"over-budget":"could-not-judge",...t!==void 0?{subjectId:t}:{},label:s,message:`${s} could not be judged: ${i}`,nodeIds:t!==void 0?[t]:[],repairs:[]}]}}function Xe(n,e,t={}){let r=t.context??{},o=t.today===void 0?{}:{today:t.today},i=t.onUnregistered??"skip",s=new Set(e.map(u=>u.name)),a=[];for(let u of e)u.scope==="graph"&&a.push(...Es(u,()=>u.evaluate({graph:n,subject:void 0,context:r,...o}),void 0));let d=e.filter(u=>u.scope!=="graph"),f=new Map;for(let u of d){let l=u.scope.kind,g=f.get(l);g?g.push(u):f.set(l,[u])}for(let u of n.allNodes()){let l=n.schema.tryDefinition(u.kind),g=l?.requiresInvariant?.(u)??null;if(t.subjectFilter&&!t.subjectFilter(u,r))continue;if(g!==null&&!s.has(g)){if(i==="throw")throw new ht(g,u.id);continue}let h=!Gt(l,u,t.today);for(let v of f.get(u.kind)??[]){if(h&&v.judgesPast!==!0)continue;let y=v.scope.match;y&&!y(u)||a.push(...Es(v,()=>v.evaluate({graph:n,subject:u,context:r,...o}),u.id))}}let c=new Set,p=a.filter(u=>{let l=`${u.message}|${[...u.nodeIds].sort().join(",")}`;return c.has(l)?!1:(c.add(l),!0)}).map(u=>{let l=Ct(u.message);return l===u.message?u:{...u,message:l}});return _r?_r(n,e,p,t.today):p}var _r;function Oy(n){_r=n}function su(n,e){let t=new Set(e);return n.filter(r=>r.nodeIds.some(o=>t.has(o))||r.subjectId!==void 0&&t.has(r.subjectId))}function au(n){let e=new Set(n.map(r=>r.invariant)).size;if(e===0)return"All rules hold";let t=`${e} ${e===1?"rule":"rules"} broken`;return n.length>e?`${t} in ${n.length} places`:t}var mt=(n,e)=>n==="*"||n.includes(e);function T(n){let e=n.onBehalfOf;if(!e)return n;let t=e.roles??[],r=n.roles===void 0?t:n.roles.filter(o=>t.includes(o));return{...n,...e.id!==void 0?{id:e.id}:{},roles:r}}var q=n=>n.kind==="system"&&n.onBehalfOf===void 0,ve=(n,e)=>n.roles==="*"||(e.roles??[]).some(t=>n.roles.includes(t));function Ps(n){return zo(n.map(e=>Ce(C(e).toLowerCase())),"or")}function xe(n,e,t,r,o,i,s={},a,d,f){if(!n)return{ok:!0};if(q(e))return{ok:!0};if(e=T(e),o!==void 0){if(xe(n,e,t,r,void 0,i).ok)return{ok:!0};let l=!1;if(o.some(y=>xe(n,e,y,r,void 0,i).ok)){if(!d||i===void 0||e.id!==void 0&&d()===e.id||!f&&n.grants.some(y=>y.roles!=="*"&&ve(y,e)&&o.some(S=>mt(y.mutations,S))))return{ok:!0};l=!0}let g=l?[t]:[t,...o],h=[...new Set(g.flatMap(y=>Ar(n,y,r)))].sort(),v=(l?"only on what you made; ":"")+(h.length===0?o.length===0?"no declared act creates or changes it, so no role can":"no role can":`${Ps(h)} can`);return{ok:!1,refusal:{mutation:t,...r===void 0?{}:{kind:r},wouldNeed:h,message:zs(n,g,r,v,s)}}}let c=!1;for(let l of n.grants){if(!ve(l,e)||!mt(l.mutations,t)||l.kinds!==void 0&&l.kinds!=="*"&&(r===void 0||!l.kinds.includes(r))||l.self&&(i===void 0||e.id===void 0||i!==e.id))continue;let g=l.ownEnd?a?.()??[]:[e.id];if(!g.length||g.some(h=>h!==e.id)){c=!0;continue}return{ok:!0}}let p=Ar(n,t,r),u=c?"only on your own end of the link":p.length===0?"no role can":`${Ps(p)} can`;return{ok:!1,refusal:{mutation:t,...r===void 0?{}:{kind:r},wouldNeed:p,message:zs(n,[t],r,u,s)}}}function zs(n,e,t,r,o){let i=[...new Set(e.flatMap(a=>Ms(n,a,t)))],s=o.act?.(e[0]);return`Not permitted: ${s?`\u201C${s}\u201D`:e[0]}${t?` on ${Ce(o.noun?.(t)??t)}`:""} \u2014 ${r}.`+(i.length>0?` ${i.join(" ")}`:"")}function Ms(n,e,t){return[...new Set(Ns(n,e,t).flatMap(r=>r.describe||[]))]}var Ns=(n,e,t)=>n.grants.filter(r=>mt(r.mutations,e)&&(t===void 0||mt(r.kinds??"*",t)));function Ar(n,e,t){let r=Ns(n,e,t);return r.some(o=>o.roles==="*")?[]:[...new Set(r.flatMap(o=>o.roles))].sort()}function Or(n,e,t){return n?t.filter(r=>{let o=T(e).id;return Er(r).some(i=>xe(n,e,r.name,i,void 0,o,void 0,()=>[o??[]].flat()).ok)}):t}var Er=n=>n.subject&&n.subject.kinds!=="*"?n.subject.kinds:[void 0];var ee=class extends Error{constructor(t,r="refused"){super(t);this.sentence=t;this.reason=r;this.name="ActRefusal"}};var In=class{constructor(e,t,r){this.present=e;this.timeline=t;this.unversioned=r}nodes=new Map;edges=new Map;touching=new Map;seq=Number.MAX_SAFE_INTEGER;wrote=new Map;begin(e){this.seq=e,this.wrote.clear()}writerOf(e){return t=>{let r=`${e}\0${t}`;return this.wrote.has(r)?this.wrote.get(r):this.timeline?.writers?.writerAt(e,t,this.seq)}}note(e,t){let r=e.op==="add-node"?e.node.id:e.op==="patch-node"?e.id:"";if(r===""||this.unversioned?.has(r))return;let o=e.op==="add-node"?Object.keys(e.node):Object.keys(e.after);for(let i of o)i!=="id"&&i!=="kind"&&this.wrote.set(`${r}\0${i}`,t(r,i))}node(e){return this.nodes.has(e)?this.nodes.get(e)??void 0:this.present.getNode(e)}setNode(e,t){this.nodes.set(e,t)}setEdge(e,t){let r=z(e);this.edges.set(r,t?e:null);for(let o of[e.from,e.to]){let i=this.touching.get(o);i||this.touching.set(o,i=new Set),i.add(r)}}incident(e){let t=new Map;for(let r of[...this.present.outEdges(e),...this.present.inEdges(e)]){let o=z(r);this.edges.has(o)||t.set(o,r)}for(let r of this.touching.get(e)??[]){let o=this.edges.get(r);o&&t.set(r,o)}return[...t.values()]}undo(e){switch(e.op){case"add-node":this.setNode(e.node.id,null);return;case"remove-node":this.setNode(e.node.id,e.node);return;case"patch-node":{if(this.unversioned?.has(e.id))return;let t=this.node(e.id);if(!t)return;this.setNode(e.id,Is(t,e.before));return}case"add-edge":this.setEdge(e.edge,!1);return;case"remove-edge":this.setEdge(e.edge,!0);return}}apply(e){switch(e.op){case"add-node":this.setNode(e.node.id,e.node);return;case"remove-node":for(let t of this.incident(e.node.id))this.setEdge(t,!1);this.setNode(e.node.id,null);return;case"patch-node":{if(this.unversioned?.has(e.id))return;let t=this.node(e.id);if(!t)return;this.setNode(e.id,Is(t,e.after));return}case"add-edge":this.setEdge(e.edge,!0);return;case"remove-edge":this.setEdge(e.edge,!1);return}}};function Is(n,e){let t={...n};for(let[r,o]of Object.entries(e))De(o)?delete t[r]:t[r]=o;return t}var du=n=>n.op==="add-node"||n.op==="remove-node"?n.node.id:n.op==="patch-node"?n.id:void 0;function Pr(n,e,t,r){let o=c=>{let p=e.node(c);return p?t.served(p,e.writerOf(c))!==void 0:t.sees?.(c)??!1},i=du(n);if(i===void 0){let c=n.edge,p=t.edgeClean(c)&&o(c.from)&&o(c.to);return e.apply(n),{primitives:p?[n]:[],faithful:!0}}let s=e.node(i),a=s?t.served(s,e.writerOf(i)):void 0;e.apply(n),e.note(n,r);let d=e.node(i),f=d?t.served(d,e.writerOf(i)):void 0;if(!a&&!f)return{primitives:[],faithful:!1};if(!a&&f){let c=e.incident(i).filter(u=>t.edgeClean(u)&&o(u.from===i?u.to:u.from)).map(u=>({op:"add-edge",edge:u})),p=n.op==="add-node"&&f===n.node&&c.length===0;return{primitives:p?[n]:[{op:"add-node",node:f},...c],faithful:p}}if(a&&!f){let c=n.op==="remove-node"&&a===s;return{primitives:c?[n]:[{op:"remove-node",node:a}],faithful:c}}if(n.op==="patch-node"){let c=(u,l)=>g=>g in u==(l!==void 0&&g in l);if(Object.keys(n.after).every(u=>c(a,s)(u)&&c(f,d)(u)))return{primitives:[n],faithful:!0};let p=u=>Object.fromEntries(Object.keys(n.after).map(l=>[l,l in u?u[l]:pe]));return{primitives:[{op:"patch-node",id:i,before:p(a),after:p(f)}],faithful:!1}}return{primitives:[{op:"remove-node",node:a},{op:"add-node",node:f}],faithful:!1}}function js(n,e,t){if(n.length===0)return[];let r=e.log.all(),o=r[0]?.seq??0,i=n.every(u=>r[u.seq-o]?.id===u.id),s=new In(e.present,e);if(!i)return s.begin(e.log.length??o+r.length),n.map(u=>{let l=T(u.author).id,g=u.primitives.map(h=>Pr(h,s,t,()=>l));return{op:u,primitives:g.flatMap(h=>h.primitives),faithful:g.every(h=>h.faithful)}});let a=new Set(n.map(u=>u.seq)),d=Number.POSITIVE_INFINITY,f=Number.NEGATIVE_INFINITY;for(let u of a)u<d&&(d=u),u>f&&(f=u);d-=o,f-=o;let c=cu(r,d,e.present,t),p=c?new In(e.present,e,c.unversioned):s;for(let u=r.length-1;u>=d;u--){let l=r[u].primitives;for(let g=l.length-1;g>=0;g--)p.undo(l[g])}return uu(n,r,d,f,a,p,c?.judge??t,e)}function cu(n,e,t,r){let{sees:o,names:i}=r;if(!o||!i)return;let s=new Set,a=new Set,d=new Set,f=(p,u)=>{s.has(p)||a.has(p)||(o(p)?i(u)?(a.add(p),d.delete(p)):d.add(p):(s.add(p),d.delete(p)))};for(let p=e;p<n.length;p++)for(let u of n[p].primitives)u.op==="add-node"||u.op==="remove-node"?f(u.node.id,u.node):u.op==="patch-node"&&(f(u.id,u.before),f(u.id,u.after));for(let p of d){let u=t.getNode(p);u&&i(u)&&(d.delete(p),a.add(p))}return{unversioned:new Set([...d,...s]),judge:{...r,served:(p,u)=>d.has(p.id)?p:s.has(p.id)?void 0:r.served(p,u)}}}function uu(n,e,t,r,o,i,s,a){let d=new Map;for(let f=t;f<=r;f++){let c=e[f];if(i.begin(c.seq),!o.has(c.seq)){for(let l of c.primitives)i.apply(l);continue}let p=(l,g)=>a.writers?.writerAt(l,g,c.seq+1),u=c.primitives.map(l=>Pr(l,i,s,p));d.set(c.seq,{op:c,primitives:u.flatMap(l=>l.primitives),faithful:u.every(l=>l.faithful)})}return n.map(f=>d.get(f.seq))}function Fy(n,e,t,r){let o=new In(e.present,e);return o.begin(e.log.length??e.log.all().length),n.flatMap(i=>Pr(i,o,t,()=>r).primitives)}var Ds="A change you cannot see",Fs={kind:"system",id:"withheld",name:"Someone"};function Qe(n){return n.withheld===!0}var jn=$e,Zs=(n,e)=>Object.entries(n).some(([t,r])=>t!=="id"&&t!=="kind"&&j(r,e));function Ls(n){if(typeof n!="function")return n;let e=n,t=r=>e(r.id)&&!Zs(r,e)?r:void 0;return{sees:e,shows:e,served:t,servedWith:t,optional:()=>!1,kindOf:()=>{}}}function j(n,e){if(typeof n=="string")return!e(n);if(n===null||typeof n!="object")return!1;if(Array.isArray(n)){for(let t=0;t<n.length;t++)if(j(n[t],e))return!0;return!1}for(let t in n)if(Object.hasOwn(n,t)&&(!e(t)||j(n[t],e)))return!0;return!1}function Cs(n,e){let t=r=>!e(r);return n.primitives.some(r=>jn(r).some(t))||[...n.writes,...n.reads].some(t)||n.mutation!==null&&j(n.mutation.args,e)}function lu(n,e){if(jn(n).every(e.shows))switch(n.op){case"add-node":{let t=e.served(n.node);return t?t===n.node?n:{op:"add-node",node:t}:void 0}case"remove-node":{let t=n.node;return Zs(t,e.sees)?{op:"remove-node",node:Object.fromEntries(Object.entries(t).filter(([r,o])=>r==="id"||r==="kind"||!j(o,e.sees)))}:n}case"patch-node":{let t=e.kindOf(n.id),r={};for(let[i,s]of Object.entries(n.after))if(!j(s,e.sees))r[i]=s;else if(t!==void 0&&e.optional(t,i))r[i]=pe;else return;let o=Object.fromEntries(Object.entries(n.before).filter(([,i])=>!j(i,e.sees)));return{op:"patch-node",id:n.id,before:o,after:r}}case"add-edge":case"remove-edge":return j(n.edge,e.sees)?void 0:n}}function zr(n,e,t){let r=Ls(e),o=i=>r.shows(i)&&Gs(r,i);return{id:n.id,seq:n.seq,batch:n.batch,author:Fs,intent:Ds,mutation:null,primitives:t??n.primitives.flatMap(i=>{let s=lu(i,r);return s?[s]:[]}),reads:n.reads.filter(o),writes:n.writes.filter(o),at:n.at,...n.undoes!==void 0?{undoes:n.undoes}:{},withheld:!0}}function en(n,e){let t=Ls(e);if(t.hides?.()===!1)return[...n];let r=t.pin?.()??t;if(r.redact)return r.redact(n);if(r.timeline){let o={served:(i,s)=>r.servedWith(i,s),edgeClean:i=>!j(i,r.sees),sees:r.sees,names:i=>j(i,r.sees)};return js(n,r.timeline,o).map(({op:i,primitives:s,faithful:a})=>(!i.withheld&&a?Ts(i,r,s):void 0)??zr(i,r,s))}return n.map(o=>(!o.withheld&&!Cs(o,r.shows)?Ts(o,r):void 0)??zr(o,r))}function Ts(n,e,t){let r=n.inverse??n.primitives;if(t&&t.length<n.primitives.length){if(!t.length)return;r=r.filter(h=>jn(h).every(e.shows));let{inverse:l,...g}=n;n={...g,primitives:t}}let o=l=>e.sees(l)&&Gs(e,l),i=n.reads.filter(o),s=new Set(n.primitives.flatMap(jn)),a=n.writes.filter(l=>o(l)||e.sees(l)&&s.has(l)),d=i.length===n.reads.length&&a.length===n.writes.length?n:{...n,reads:i,writes:a},f=e.actor!==void 0&&T(n.author).id===e.actor;if(!f&&n.described?.some(l=>!e.sees(l)))return;if(!j(n,e.sees))return d;let c=new Set,p=l=>{if(typeof l=="string")c.add(l);else if(Array.isArray(l))for(let g of l)p(g);else if(l!==null&&typeof l=="object")for(let[g,h]of Object.entries(l))c.add(g),p(h)};t&&p(t);let u=l=>e.sees(l)||c.has(l);if(!j(r,u))return f&&n.mutation&&p(n.mutation.args),j({...d,primitives:[],inverse:[]},f?u:e.sees)?void 0:d}function Gs(n,e){return n.timeline===void 0||n.kindOf(e)!==void 0}var Pe=class extends N{constructor(t){super(t.message);this.check=t;this.name="UndoBlockedError"}get blockedBy(){return this.check.blockedBy}};function Tn(n,e){let t=new Set(e),r=n.undoneIds(),o=n.all().filter(l=>t.has(l.batch)&&!r.has(l.id)),i=[...n.epochs()].reverse().find(l=>l.horizon);if(i){let l=new Set(n.all().map(h=>h.batch)),g=e.filter(h=>!l.has(h));if(g.length>0)return{ok:!1,ops:o,blockedBy:[],includeBatches:[],reason:"missing",message:`Cannot undo ${g.map(h=>`batch ${h}`).join(", ")}: it is not after the undo horizon at op ${i.seq}${i.at?` (${i.at})`:""}. What was done before the horizon is archived, and undo does not reach behind it.`}}if(o.length===0)return{ok:!1,ops:o,blockedBy:[],includeBatches:[],reason:"missing",message:e.length===0?"No batch given to undo":`Nothing live to undo in ${e.join(", ")} \u2014 already undone, or never applied`};if(o.some(Qe))return{ok:!1,ops:o,blockedBy:[],includeBatches:[],reason:"forbidden",message:o.every(Qe)?"Cannot undo a change you cannot see: only somebody who can see it can take it back.":"Cannot undo this here: part of it is a change you cannot see, and only somebody who can see it can take it back."};if(o.some(l=>l.enabledModules!==void 0))return{ok:!1,ops:o,blockedBy:[],includeBatches:[],message:"Cannot undo turning a module off or on: it is changed by turning the module the other way."};let s=new Set;for(let l of o)for(let g of l.writes)s.add(g);let a=Math.min(...o.map(l=>l.seq)),d=n.epochs().find(l=>l.change!==void 0&&l.seq>a);if(d){let l=o.find(g=>g.seq<d.seq);return{ok:!1,ops:o,blockedBy:[],includeBatches:[],message:`Cannot undo "${l.intent}": ${l.intent===d.change?"it changed the declaration":`it was done before the declaration changed (${d.change})`}, and undo does not reach back across that change.`}}let f=new Map(n.all().map(l=>[l.id,l.seq])),c=[];for(let l of n.all()){if(l.seq<=a||t.has(l.batch)||r.has(l.id)||l.undoes!==void 0&&(f.get(l.undoes)??-1)>a)continue;let g=l.reads.filter(h=>s.has(h));g.length>0&&c.push({op:l,overlap:g})}if(c.length===0)return{ok:!0,ops:o};let p=c.filter(l=>!Qe(l.op)).map(l=>`"${l.op.intent}" (op ${l.op.id}, read ${l.overlap.join(", ")})`).join("; ");if(c.some(l=>Qe(l.op)))return{ok:!1,ops:o,blockedBy:c,includeBatches:[],message:`Cannot undo on its own \u2014 ${p?`a later operation depends on it: ${p}; and `:""}a later change you cannot see depends on it, which only somebody who can see it can take back.`};let u=[...new Set(c.map(l=>l.op.batch))];return{ok:!1,ops:o,blockedBy:c,includeBatches:u,message:`Cannot undo on its own \u2014 a later operation depends on it: ${p}. Include ${u.map(l=>`batch ${l}`).join(", ")} to undo them together.`}}function Bs(n){return[...n].sort((e,t)=>t.seq-e.seq).flatMap(e=>Re(e))}var ze=class extends Error{refusal;constructor(e){super(e.message),this.name="PermissionDeniedError",this.refusal=e}};function fu(n){let e=n instanceof Error?n.message:String(n);if(n instanceof ze){let t=n.refusal.wouldNeed;return{reason:"forbidden",sentence:e,...t.length>0?{wouldNeed:[...t]}:{}}}return n instanceof B?{reason:"missing",sentence:e}:n instanceof ee?{reason:n.reason,sentence:n.sentence}:n instanceof Pe?{reason:n.check.reason??"invalid",sentence:e}:{reason:"invalid",sentence:e}}var re=class extends N{constructor(t,r){super(`Invalid arguments for mutation "${t}"`,r.map(o=>`${o.path.map(String).join(".")||"(root)"}: ${o.message}`).join("; "));this.mutation=t;this.issues=r;this.name="InvalidArguments"}};function tb(n){let e=/^(edit|remove|archive|unarchive|merge|leave-alone|allow-tidying|skip|detach|split)-(.+)$/.exec(n);return e?{act:e[1],kind:e[2]}:void 0}var Us=["connect","disconnect"],Vs=n=>n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),Ws=(n,e,t)=>`${n}-${e}-${Vs(t)}`;function rb(n,e){let t=/^(connect|disconnect)-(.+)$/.exec(n);if(t){for(let[r,o]of e)if(t[2].startsWith(`${r}-`)){for(let i of o)if(t[2]===`${r}-${Vs(i)}`)return{act:t[1],kind:r,relation:i}}}}var Ks=n=>`${/^[aeiou]/i.test(n)?"an":"a"} ${n}`;function qs(n,e){let t=e.also?` (${e.also})`:"";return{title:`${e.one?`${n==="connect"?"Set":"Clear"} the ${e.to}`:`${n==="connect"?"Link":"Unlink"} ${Ks(e.to)}`}${t}`,fromTheOtherEnd:`${n==="connect"?"Link":"Unlink"} ${Ks(e.from)}${t}`}}var pu=n=>`Op "${n.id}" has seq ${n.seq}, so the log begins at seq ${n.seq}: a log that begins past 0 begins at its undo horizon, and none was given (a checkpoint epoch, or { horizon })`,nn=class n{ops=[];marks=[];start=0;get length(){return this.start+this.ops.length}get horizon(){return this.start}all(){return this.ops}opsFrom(e){return this.ops.slice(Math.max(0,e-this.start))}append(e){if(e.seq!==this.length)throw new Error(this.length===0&&e.seq>0?pu(e):`Op "${e.id}" has seq ${e.seq} but the log is ${this.length} long`);this.ops.push(hn(e))}static from(e,t=[],r={}){let o=new n,i=[...t].reverse().find(d=>d.horizon),s=r.horizon??i?.seq??0;if(!Number.isInteger(s)||s<0)throw new Error(`A log cannot begin at seq ${s}`);if(i&&r.horizon!==void 0&&i.seq!==r.horizon)throw new Error(`A log said to begin at seq ${r.horizon} has its checkpoint at seq ${i.seq}`);let a=e[0];if(a&&s>0&&a.seq!==s)throw new Error(`A log compacted at seq ${s} begins with op "${a.id}" at seq ${a.seq}`);o.start=s;for(let d of e)o.append(d);for(let d of t)o.markEpoch(d);return o}replace(e,t=[],r={}){let o=n.from(e,t,r);this.ops=o.ops,this.marks=o.marks,this.start=o.start}epochs(){return this.marks}lastEpoch(){return this.marks.at(-1)}markEpoch(e){if(!Number.isInteger(e.seq)||e.seq<0||e.seq>this.length)throw new Error(`An epoch at seq ${e.seq} starts past the end of a log ${this.length} long`);if(e.seq<this.start)throw new Error(`An epoch at seq ${e.seq} is behind the horizon at seq ${this.start}: it went to the archive with the ops before it`);let t=this.lastEpoch();if(t&&e.seq<t.seq)throw new Error(`An epoch at seq ${e.seq} comes before the last one, at seq ${t.seq}`);this.marks.push(e)}truncate(e){if(!Number.isInteger(e)||e<this.start||e>this.length)throw new Error(`Cannot cut a log ${this.length} long back to ${e}`);let t=this.lastEpoch();if(t&&t.seq>e)throw new Error(`Cannot cut the log back to ${e}: an epoch begins at seq ${t.seq}`);return this.ops.splice(e-this.start)}checkpointAt(e,t,r={}){if(!Number.isInteger(t)||t<this.start||t>this.length)throw new Error(`No checkpoint at seq ${t}: this log holds seqs ${this.start} to ${this.length}`);let o=[...this.marks].reverse().find(a=>a.seq<=t);if(o?.seq===t)return{...o,horizon:!0};let i=this.fold(e,{...r,...o?{from:o}:{},to:t}).snapshot(),s=this.ops[t-1-this.start]?.at??o?.at;return{seq:t,base:i,...o?.version!==void 0?{version:o.version}:{},...s!==void 0?{at:s}:{},horizon:!0}}compact(e){if(!Number.isInteger(e.seq)||e.seq<this.start||e.seq>this.length)throw new Error(`Cannot compact at seq ${e.seq}: this log holds seqs ${this.start} to ${this.length}`);let t=this.ops.slice(0,e.seq-this.start),r=this.marks.filter(o=>o.seq<e.seq);return this.ops=this.ops.slice(e.seq-this.start),this.marks=[{...e,horizon:!0},...this.marks.filter(o=>o.seq>e.seq)],this.start=e.seq,{ops:t,epochs:r}}get(e){return this.ops.find(t=>t.id===e)}live(){let e=this.undoneIds();return this.ops.filter(t=>!e.has(t.id))}undoneIds(){return Me(this.ops)}opsInBatch(e){return this.ops.filter(t=>t.batch===e)}batches(){return Mr(this.ops,this.undoneIds())}fold(e,t={}){let r=t.from?.seq??0;if(r<this.start)throw new Error(t.from?`An epoch at seq ${r} is behind the horizon at seq ${this.start}: fold from the checkpoint`:`A log compacted at seq ${this.start} does not fold from empty: fold from its checkpoint`);let o=t.from?.base??{nodes:[],edges:[]},i=W.from(e,o,t.validate!==void 0?{validate:t.validate}:{}),s=t.to??this.length;for(let a of this.ops.slice(r-this.start,Math.max(0,s-this.start)))hu(i,a);return i}toJSON(){return[...this.ops]}};function hu(n,e){if(e.undoes!==void 0){n.applyPrimitives(e.primitives,{restoring:!0});return}try{n.applyPrimitives(e.primitives)}catch{n.applyPrimitives(e.primitives,{restoring:!0})}}function Me(n){let e=new Map;for(let r of n){if(!r.undoes)continue;let o=e.get(r.undoes);o?o.push(r.id):e.set(r.undoes,[r.id])}let t=new Map;for(let r=n.length-1;r>=0;r--){let o=n[r],i=e.get(o.id)??[];t.set(o.id,!i.some(s=>t.get(s)===!0))}return new Set(n.filter(r=>t.get(r.id)===!1).map(r=>r.id))}function Mr(n,e){let t=[],r=new Map;for(let o of n){let i=r.get(o.batch);i?i.push(o):(r.set(o.batch,[o]),t.push(o.batch))}return t.map(o=>{let i=r.get(o)??[],s=i[0];return{id:o,author:s.author,intent:s.batchIntent??s.intent,at:s.at,...s.lineage?{lineage:s.lineage}:{},ops:i,undone:i.every(a=>e.has(a.id))}})}function Nr(n){return n?.automated===!0&&n.kind!=="human"&&n.kind!=="rule"}var Ys=n=>n?.[Mn]===!0,gu=(n,e)=>Ys(("graph"in n?n.graph:n).getNode(e));function Hs(n,e,t){let r=n.tryDefinition(e);return t===void 0?r?.tidying:r?.edges?.[t]?.tidying}var Js=n=>JSON.stringify(n.map(e=>[e.name,e.args]),(e,t)=>t&&typeof t=="object"&&!Array.isArray(t)?Object.fromEntries(Object.entries(t).sort()):t);function Xs(n,e){let t=mu(n);return[e,...e.map(r=>[r])].map(r=>t.get(Js(r))).find(Boolean)}function mu(n){let e=Me(n),t=new Map(n.map(o=>[o.id,o])),r=new Map;for(let o of n){let i=o.undoes!==void 0&&!e.has(o.id)&&!o.withheld?t.get(o.undoes):void 0,s=i?.suggests??(i?.mutation&&(i.lineage||o.undoneLineage)?[i.mutation]:[]);if(s.length>0)for(let a of[s,...s.map(d=>[d])])r.set(Js(a),o)}return r}function Qs(n,e,t,r,o={}){let i=o.declaration!==!1,s=(a,d)=>`${r} may not ${a}: ${d}.`;for(let a of t){let d="edge"in a?a.edge:void 0,f=(d?[d.from,d.to]:["id"in a?a.id:a.node.id]).map(c=>e.getNode(c)??("node"in a?a.node:void 0));for(let c of f){if(!c)continue;if(Ys(c))return s(`change \u201C${F(n.tryDefinition(c.kind),c)}\u201D`,"a person said to leave it alone");if(!i)continue;let p=Hs(n,c.kind);if(p==="never")return s(`change ${ne(n,c.kind)} on its own`,"the app says they are never tidied");if(d&&p==="no-links")return s(`link or unlink ${ne(n,c.kind)} on its own`,"the app says they are never linked automatically")}if(d&&i&&f[0]&&Hs(n,f[0].kind,d.kind)==="never")return s(`${a.op==="add-edge"?"make":"break"} a \u201C${d.kind}\u201D link on its own`,"the app says that relation is never tidied")}}function yu(n,e){if(!e||n.length===0)return null;let t=e.roles,r=o=>t?o.wouldNeed.some(i=>t.includes(i)):o.wouldNeed.length>0;return n.every(({refusal:o})=>r(o))?e:null}var yt={scene:0,overview:10,rail:20,popover:30,dialog:40,toast:50},bu={plots:0,stage:1,tag:2,ties:2,lines:3,tieLabels:4,occupants:6,seatMarks:7,zoom:8,card:10,opened:11},vu={under:0,raised:1,over:2},Ir=n=>`--graview-layer-${n}`,xu=n=>`var(${Ir(n)}, ${yt[n]})`;function wu(){return Object.keys(yt).map(n=>` ${Ir(n)}: ${yt[n]};`).join(`
|
|
4
|
+
`)}function ku(n){let e=n.onBehalfOf??n;return{kind:e.kind,...e.id!==void 0?{id:e.id}:{},...e.name!==void 0?{name:e.name}:{},...e.roles!==void 0?{roles:e.roles}:{}}}function ea(){return`sub_${(globalThis.crypto?.randomUUID?.()??`${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`).replace(/-/g,"").slice(0,20)}`}function na(n){return{...n,id:n.id??ea(),at:n.at??new Date().toISOString()}}function Su(n=[]){let e=[...n],t=new Set,r=()=>{for(let o of t)o()};return{list:o=>o===void 0?e:e.filter(i=>i.who.id===o),add(o){let i=na(o);return e=[...e.filter(s=>s.id!==i.id),i],r(),i},remove(o){let i=e.length;e=e.filter(a=>a.id!==o);let s=e.length<i;return s&&r(),s},onChange(o){return t.add(o),()=>t.delete(o)}}}var ra=(n,e)=>`${n}\0${e}`,ta=new WeakMap;function $u(n){let e=new Map;return{base:n,end:n,read:[],fields:e,written:[],seqOf:new Map,writers:{writerAt:(r,o,i)=>{let s=e.get(ra(r,o));if(!s)return;let a=0,d=s.length;for(;a<d;){let f=a+d>>1;s[f].seq<i?a=f+1:d=f}return a===0?void 0:s[a-1].by}}}}function Ru(n){if(n.op==="add-node")return[n.node.id,Object.keys(n.node).filter(e=>e!=="id"&&e!=="kind")];if(n.op==="patch-node")return[n.id,Object.keys(n.after).filter(e=>!De(n.after[e]))]}function _u(n,e){let t=n.end,r=T(e.author).id,o=e.undoes!==void 0?n.seqOf.get(e.undoes):void 0,i=[];for(let s of e.primitives){let a=Ru(s);if(!a)continue;let[d,f]=a;for(let c of f){let p=e.undoes===void 0?r:o!==void 0?n.writers.writerAt(d,c,o):void 0,u=ra(d,c),l=n.fields.get(u);l||n.fields.set(u,l=[]),l.push({seq:t,by:p}),i.push(u)}}n.written.push({seq:t,keys:i}),n.seqOf.set(e.id,t),n.read.push(e),n.end++}function Au(n,e){for(;n.written.length>0&&n.written.at(-1).seq>=e;){let{keys:t}=n.written.pop();for(let r of t)n.fields.get(r)?.pop()}for(let t of n.read.slice(e-n.base))n.seqOf.delete(t.id);n.read.length=e-n.base,n.end=e}function bt(n){let e=n.all(),t=typeof n.length=="number"?n.length:e.length,r=t-e.length,o=ta.get(n);if(o&&o.base<=r&&r<=o.end){let i=Math.min(o.end,t);for(;i>r&&e[i-1-r]!==o.read[i-1-o.base];)i--;i===r&&r>o.base&&i<o.end?o=void 0:(i<o.end&&Au(o,i),r>o.base&&(o.read=o.read.slice(r-o.base),o.base=r))}else o=void 0;o||ta.set(n,o=$u(r));for(let i=o.end;i<t;i++)_u(o,e[i-r]);return o.writers}var tn={served:new WeakSet},Dn=n=>n.fields!==void 0||(n.hide?.length??0)>0,we=n=>tn.on===!0||tn.served.has(n);var jr=new WeakMap;function Ou(n,e){let t=new Map,r=new Map(Object.entries(e??{}));return{base:n,end:n,read:[],kinds:t,creators:r,entries:[],records:{kindOf:o=>t.get(o),creatorOf:o=>r.get(o)}}}function Eu(n,e){let t=n.end;for(let r of e.primitives){if(r.op!=="add-node"&&r.op!=="remove-node")continue;let{id:o,kind:i}=r.node;if(n.kinds.has(o)||(n.kinds.set(o,i),n.entries.push({seq:t,id:o,creator:!1})),r.op!=="add-node"||n.creators.has(o)||e.undoes!==void 0)continue;let s=T(e.author).id;s!==void 0&&(n.creators.set(o,s),n.entries.push({seq:t,id:o,creator:!0}))}n.read.push(e),n.end++}function Pu(n,e){for(;n.entries.length>0&&n.entries.at(-1).seq>=e;){let t=n.entries.pop();(t.creator?n.creators:n.kinds).delete(t.id)}n.read.length=e-n.base,n.end=e}function le(n){let e=n.all(),t=typeof n.length=="number"?n.length:e.length,r=t-e.length,o=jr.get(n);if(o&&o.base<=r&&r<=o.end){let i=Math.min(o.end,t);for(;i>r&&e[i-1-r]!==o.read[i-1-o.base];)i--;i===r&&r>o.base&&i<o.end?o=void 0:(i<o.end&&Pu(o,i),r>o.base&&(o.read=o.read.slice(r-o.base),o.base=r))}else o=void 0;o||jr.set(n,o=Ou(r,r>0?zu(n,r)?.creators:void 0));for(let i=o.end;i<t;i++)Eu(o,e[i-r]);return o.records}function zu(n,e){let t=[...n.epochs?.()??[]].reverse().find(r=>r.horizon);return t?.seq===e?t:void 0}function oa(n,e){le(n);let t=jr.get(n),r=new Set;for(let i=t.entries.length-1;i>=0&&t.entries[i].seq>=e;i--)t.entries[i].creator&&r.add(t.entries[i].id);let o={};for(let[i,s]of t.creators)r.has(i)||(o[i]=s);return o}function rn(n,e,t,r,o,i=tn.on===!0){if(!n?.sees?.length||q(e))return!0;let s=n.sees.filter(a=>a.kinds.includes(t.kind)&&(i||!Dn(a)));return s.length===0?!1:(e=T(e),s.some(a=>{if(!ve(a,e))return!1;if(!a.own&&!a.via)return!0;let d=e.id;if(d===void 0)return!1;let f=c=>c.id===d;return a.via?r.out(t.id,a.via).some(f)||r.in(t.id,a.via).some(f):t.id===d||r.out(t.id).some(f)||r.in(t.id).some(f)||o?.creatorOf(t.id)===d}))}var Dr=new Set;function vt(n,e){return q(e)?Dr:n.modules?.disabledKinds??Dr}function on(n,e){return q(e)?!1:(n.policy?.sees?.length??0)>0||vt(n,e).size>0}function da(n,e){if(!on(n,e))return()=>!0;let t=n.modules?.disabledKinds??Dr,r=n.policy?.sees??[],o=T(e),i=we(n),s=d=>!t.has(d)&&(r.length===0||r.some(f=>f.kinds.includes(d)&&ve(f,o)&&!f.own&&!f.via&&(i||!Dn(f)))),a=n.schema.kinds.every(s);return d=>a||d!==void 0&&s(d)}function Fn(n,e){return t=>{let r=vt(n,e);if(!n.policy?.sees?.length&&r.size===0)return!0;let o=le(n.log),i=n.graph.getNode(t);if(i)return!r.has(i.kind)&&rn(n.policy,e,i,n.graph,o,we(n));let s=o.kindOf(t);return s===void 0?!0:!r.has(s)&&rn(n.policy,e,{id:t,kind:s},{out:()=>[],in:()=>[]},o,we(n))}}var Mu={out:()=>[],in:()=>[]};function Nu(n,e,t=new Map,r){let o=vt(n,e);if(!n.policy?.sees?.length&&o.size===0)return()=>!0;let i=le(n.log);return s=>{let a=t.get(s);if(a!==void 0)return a;let d,f=n.graph.getNode(s);if(f)d=!o.has(f.kind)&&rn(n.policy,e,f,n.graph,i,we(n));else{let c=i.kindOf(s);if(c===void 0)return r?.add(s),!0;d=!o.has(c)&&rn(n.policy,e,{id:s,kind:c},Mu,i,we(n))}return t.set(s,d),d}}function Iu(n){let e=new Map;return(t,r)=>{let o=`${t}\0${r}`,i=e.get(o);if(i===void 0){let s=n?.tryDefinition(t)?.fields?.shape,a=s?.[r];i=s!==void 0&&(a===void 0||a.safeParse?.(void 0).success===!0),e.set(o,i)}return i}}function Zr(n,e){return ca(n,e).lens}var Fr=()=>({judged:new Map,shown:new Map});function ca(n,e){let t=Iu(n.schema),r=q(e)?void 0:T(e).id,o=()=>n.log.length??n.log.all().length,i=new WeakMap,s=n.graph,a=(c,p,u,l,g)=>{let h=(b,$)=>{if(!c(b.id))return;let R;for(let L in b)if(!(!Object.hasOwn(b,L)||L==="id"||L==="kind"||!j(b[L],c))&&!(r!==void 0&&$(L)===r)){if(!t(b.kind,L))return;(R??=[]).push(L)}if(!R)return b;let _=R.join("\0"),P=i.get(b);if(P?.without===_)return P.node;let E=Object.fromEntries(Object.entries(b).filter(([L])=>!R.includes(L)));return i.set(b,{without:_,node:E}),E},v=b=>{let $=u();return h(b,R=>p().writerAt(b.id,R,$))},y=new WeakMap,S=g?b=>{let $=y.get(b);return $||y.set(b,$={node:v(b)}),$.node}:v,A=b=>{if(!c(b))return!1;let $=s.getNode(b);return $===void 0||S($)!==void 0},m=g?.shown??new Map,k=g?b=>{let $=m.get(b);return $===void 0&&m.set(b,$=A(b)),$}:A,w=s.outEdges&&s.inEdges?{present:{getNode:b=>s.getNode(b),outEdges:b=>s.outEdges(b),inEdges:b=>s.inEdges(b)},log:n.log,get writers(){return p()}}:void 0,x={sees:c,shows:k,served:S,servedWith:h,optional:t,kindOf:l,...r!==void 0?{actor:r}:{},...w?{timeline:w}:{},hides:()=>on(n,e),pin:g?()=>x:()=>d(Fr())};return tn.lens?.(x,n,e)??x};function d(c){let p,u=o(),l=le(n.log);return a(Nu(n,e,c.judged,c.unnamed),()=>p??=bt(n.log),()=>u,g=>s.getNode(g)?.kind??l.kindOf(g),c)}return{lens:a(Fn(n,e),()=>bt(n.log),o,c=>s.getNode(c)?.kind??le(n.log).kindOf(c)),pinWith:d}}var ia=new WeakMap,sa=new WeakMap,ju=n=>{let e=new Set;for(let t of n)for(let r of t.primitives)r.op==="add-node"||r.op==="remove-node"?e.add(r.node.id):r.op==="patch-node"?e.add(r.id):(e.add(r.edge.from),e.add(r.edge.to));return e};function Tu(n,e){if(!on(n,e))return n.log.all();let t=n.log.all(),r=n.log.length??t.length,o=r-t.length,i=[...vt(n,e)].sort().join("\0"),s=ua(e),a=ia.get(n.log);a||ia.set(n.log,a=new Map);let d=a.get(s),{pinWith:f}=ca(n,e),c=sa.get(n.log);c||sa.set(n.log,c=new Set);let p=d!==void 0&&d.horizon===o&&d.off===i&&d.length<=r&&(d.length===o||t[d.length-1-o]===d.last);if(d&&p){if(d.length===r)return d.ops;let g=t.slice(d.length-o),h=f(Fr()),v=!0,y=ju(g);for(let S of y){let A=d.judgments.judged.get(S),m=d.judgments.shown.get(S);if(A!==void 0&&h.sees(S)!==A||m!==void 0&&h.shows(S)!==m){v=!1;break}}if(v){for(let S of y)if(c.has(S)){v=!1;break}}if(v){let S=[...d.ops,...en(g,f(d.judgments))],A={horizon:o,off:i,length:r,last:t.at(-1),ops:S,judgments:d.judgments};return a.set(s,A),S}}let u={...Fr(),unnamed:c},l=en(t,f(u));return a.set(s,{horizon:o,off:i,length:r,last:t.at(-1),ops:l,judgments:u}),l}function Du(n,e,t){return(t.subjectId===void 0||!e(t.subjectId)||n.shows(t.subjectId))&&t.nodeIds.every(r=>!e(r)||n.shows(r))&&!j(t,n.sees)}function Lr(n,e){return{all:()=>n,undoneIds:()=>Me(n),epochs:e}}var aa=new WeakMap;function ua(n){let e=q(n)?n:T(n);return`${n.kind}|${e.id??""}|${(e.roles??[]).join(",")}|${n.onBehalfOf?"for":""}`}var Tr=(n,e)=>{let t=Reflect.get(n,e,n);return typeof t=="function"?t.bind(n):t},Fu=Symbol.for("@graview/core:seat");function Zn(n,e){if(!on(n,e))return n;let t=ua(e),r=aa.get(n);r||aa.set(n,r=new Map);let o=r.get(t);if(o)return o;let i=n.graph,s=Zr(n,e),a=m=>{let k=R=>R===void 0?void 0:m.served(R),w=R=>k(R)!==void 0,x=R=>w(i.getNode(R));return{served:k,seenNode:w,seenId:x,seenEdge:R=>x(R.from)&&x(R.to)&&!j(R,m.sees),servedAll:R=>R.flatMap(_=>k(_)??[])}},{served:d,seenId:f}=a(s),c=()=>a(s.pin?.()??s),p=(m,k)=>{let w=bt(n.log),x=s.pin?.()??s,b=m.nodes.flatMap(R=>x.servedWith(R,_=>w.writerAt(R.id,_,k))??[]),$=new Set(b.map(R=>R.id));return{nodes:b,edges:m.edges.filter(R=>$.has(R.from)&&$.has(R.to)&&!j(R,x.sees))}},u=m=>{let k=p(m.base,m.seq);if(!m.creators)return{...m,base:k};let w=new Set(k.nodes.map(b=>b.id)),x=Object.fromEntries(Object.entries(m.creators).filter(([b,$])=>w.has(b)&&!j($,s.sees)));return{...m,base:k,creators:x}},l=m=>m&&u(m),g=()=>Tu(n,e),h=()=>Lr(g(),()=>n.log.epochs()),v=new Proxy(i,{get(m,k){switch(k){case"getNode":return w=>d(m.getNode(w));case"has":return f;case"allNodes":case"nodesOfKind":return(...w)=>c().servedAll(m[k](...w));case"count":return(...w)=>c().servedAll(m.nodesOfKind(...w)).length;case"allEdges":case"edgesOfKind":case"outEdges":case"inEdges":return(...w)=>m[k](...w).filter(c().seenEdge);case"out":case"in":case"neighbors":return(w,...x)=>{let b=c();return b.seenId(w)?b.servedAll(m[k](w,...x)):[]};case"snapshot":return()=>{let w=m.snapshot(),x=c();return{...w,nodes:x.servedAll(w.nodes),edges:w.edges.filter(x.seenEdge)}};case"size":{let w=c();return{nodes:w.servedAll(m.allNodes({archived:"all"})).length,edges:m.allEdges({archived:"all"}).filter(w.seenEdge).length}}default:return Tr(m,k)}}}),y=()=>{let m=g();return Mr(m,Me(m))},S=new Proxy(n.log,{get(m,k){switch(k){case"all":case"toJSON":return()=>[...g()];case"epochs":return()=>m.epochs().map(u);case"lastEpoch":return()=>l(m.lastEpoch());case"live":return()=>{let w=g(),x=Me(w);return w.filter(b=>!x.has(b.id))};case"get":return w=>g().find(x=>x.id===w);case"opsInBatch":return w=>g().filter(x=>x.batch===w);case"batches":return y;default:return Tr(m,k)}}}),A=new Proxy(n,{get(m,k){switch(k){case Fu:return{store:m,principal:e};case"graph":return v;case"log":return S;case"snapshot":return v.snapshot;case"batches":return y;case"canUndo":return w=>Tn(h(),typeof w=="string"?[w]:w);case"violations":return w=>m.violations(w,v).filter(x=>Du(s,b=>i.has(b),x));case"findings":return()=>m.findings().filter(w=>(w.id.includes("->")?w.id.split("->").map((b,$)=>$===0?b.slice(b.indexOf(":")+1):b):[w.id]).every(b=>!i.has(b)||f(b))&&!j(w,s.sees));case"wouldChange":return w=>m.wouldChange(w,e);case"preview":return(w,x,b)=>m.preview(w,x,{author:e,...b});case"seenBy":return w=>Zn(m,w);case"seenFor":return e;case"checkpoint":return w=>l(m.checkpoint(w));default:return Tr(m,k)}}});return r.set(t,A),A}var Cr=new Set;function Gr(n,e){if(!n||e===void 0)return{enabled:new Set(Object.keys(n??{})),disabledKinds:Cr,disabledMutations:Cr,disabledInvariants:Cr,administered:la(n,new Set(Object.keys(n??{})))};let t=new Set,r=a=>{if(!(t.has(a)||!(a in n))){t.add(a);for(let d of n[a]?.requires??[])r(d)}};for(let a of e)r(a);for(let[a,d]of Object.entries(n))d.required&&r(a);let o=new Set,i=new Set,s=new Set;for(let[a,d]of Object.entries(n))if(!t.has(a)){for(let f of d.kinds??[])o.add(f);for(let f of d.mutations??[])i.add(f);for(let f of d.invariants??[])s.add(f)}for(let a of t){let d=n[a];for(let f of d?.kinds??[])o.delete(f);for(let f of d?.mutations??[])i.delete(f);for(let f of d?.invariants??[])s.delete(f)}return{enabled:t,disabledKinds:o,disabledMutations:i,disabledInvariants:s,administered:la(n,t)}}function la(n,e){let t=new Map;for(let[r,o]of Object.entries(n??{}))e.has(r)&&o.visibility==="admin"&&t.set(r,o);return t}function fa(n){return n.normalize("NFKD").replace(/\p{M}/gu,"").toLowerCase().trim().replace(/\s+/g," ")}var xt=class{constructor(e){this.graph=e;for(let t of e.allNodes({archived:"all"}))this.file(t);e.subscribe(t=>this.follow(t))}kinds=new Map;filed=new Map;labelOf(e){return this.filed.get(e)?.label}lookup(e,t){let r=fa(t);if(r.length===0)return{exact:[],prefix:[]};let o=e.includes("*")?[...this.kinds.values()]:e.flatMap(a=>this.kinds.get(a)??[]),i=[],s=[];for(let a of o)for(let d=Br(a.sorted,r);d<a.sorted.length&&a.sorted[d].startsWith(r);d+=1){let f=[...a.ids.get(a.sorted[d])??[]];s.push(...f),a.sorted[d]===r&&i.push(...f)}return{exact:i,prefix:s}}follow(e){for(let t of e.removedNodes)this.unfile(t.id);for(let t of e.changedNodes)this.unfile(t.after.id),this.file(t.after);for(let t of e.addedNodes)this.file(t)}file(e){let t=F(this.graph.schema.tryDefinition(e.kind),e),r=fa(t);this.filed.set(e.id,{kind:e.kind,key:r,label:t});let o=this.kinds.get(e.kind);o||this.kinds.set(e.kind,o={ids:new Map,sorted:[]});let i=o.ids.get(r);i?i.add(e.id):(o.ids.set(r,new Set([e.id])),o.sorted.splice(Br(o.sorted,r),0,r))}unfile(e){let t=this.filed.get(e);if(!t)return;this.filed.delete(e);let r=this.kinds.get(t.kind),o=r?.ids.get(t.key);if(!r||!o||(o.delete(e),o.size>0))return;r.ids.delete(t.key);let i=Br(r.sorted,t.key);r.sorted[i]===t.key&&r.sorted.splice(i,1)}};function Br(n,e){let t=0,r=n.length;for(;t<r;){let o=t+r>>>1;n[o]<e?t=o+1:r=o}return t}function Zu(n,e){return e.includes("*")?"record":e.map(t=>K(n.tryDefinition(t),t)).join(" or ")}function pa(n,e,t,r){let o=Zu(n,e.kinds);if(r.length===0)return{ok:!1,reason:"none",candidates:r,message:`There is no ${o} called "${t}".`};let i=r.slice(0,10).map(a=>`${a.label} (${a.id})`),s=r.length>i.length?`, and ${r.length-i.length} more`:"";return{ok:!1,reason:"ambiguous",candidates:r,message:`"${t}" names more than one ${o}: ${i.join(", ")}${s}. Pass the id of the one you mean as ${e.name}.`}}var ga=Symbol.for("@graview/core:node-ref"),ha=n=>typeof n=="object"&&n!==null?n[ga]:void 0;function ke(n="*"){return Lu(D().check($n(1)),n)}function Lu(n,e){let t=Object.freeze(e==="*"?["*"]:[...e]),r=o=>{o&&Object.defineProperty(o,ga,{value:t,enumerable:!0,configurable:!0})};return r(n),r(I(n)),n}function Kr(n){if(typeof n!="object"||n===null)return;let e=ha(n);if(e)return e;let t=I(n),r=ha(t);if(r)return r;let o=t?.innerType;return o?Kr(o):void 0}function Ln(n){let e=n.shape;if(!e)return[];let t=[];for(let[r,o]of Object.entries(e)){let i=Kr(o);i&&t.push({name:r,kinds:i,optional:o.safeParse(void 0).success})}return t}function Ur(n){if(n===null||typeof n!="object")return JSON.stringify(n)??"null";if(Array.isArray(n))return`[${n.map(r=>r===void 0?"null":Ur(r)).join(",")}]`;let e=n;return`{${Object.keys(e).filter(r=>e[r]!==void 0).sort().map(r=>`${JSON.stringify(r)}:${Ur(e[r])}`).join(",")}}`}var ma=(n,e)=>n.key<e.key?-1:n.key>e.key?1:0;function Cu(n){let e=n.nodes.map(r=>({key:r.id,value:r})).sort(ma),t=n.edges.map(r=>({key:z(r),value:{kind:r.kind,from:r.from,to:r.to}})).sort(ma);return Ur({nodes:e.map(r=>r.value),edges:t.map(r=>r.value)})}function sn(n){return`sha256:${ba(Cu(n))}`}function ya(n,e,t,r={}){let o=r.validate??!0,i=r.base??{nodes:[],edges:[]},s=sn(t),a=W.from(n,i,{validate:o});for(let[h,v]of e.entries())try{a.applyPrimitives(v.primitives)}catch(y){let S=e[h-1];return{ok:!1,expected:sn(a.snapshot()),actual:s,...S?{divergedAfter:S.id}:{},reason:`The log does not fold: op "${v.id}" (${v.intent}) could not be applied. ${y instanceof Error?y.message:String(y)}`}}let d=sn(a.snapshot());if(d===s)return{ok:!0,hash:s};let f=h=>{let v=W.from(n,i,{validate:o});for(let y=0;y<=h;y++)v.applyPrimitives(e[y].primitives);return sn(v.snapshot())},c=h=>{try{let v=W.from(n,t,{validate:o});for(let y=e.length-1;y>h;y--)v.applyPrimitives(Re(e[y]));return sn(v.snapshot())}catch{return}},p=h=>{let v=c(h);return v!==void 0&&v!==f(h)},u=-1,l=e.length-1;for(;u<l;){let h=Math.floor((u+l)/2);p(h)?l=h:u=h+1}let g=l>=0?e[l]:void 0;return{ok:!1,expected:d,actual:s,...g?{divergedAfter:g.id}:{},reason:g?`The graph and the fold of its log part after op "${g.id}" (${g.intent}).`:"The graph and the fold of its log disagree before any op: the base it folds from does not match."}}var Gu=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Bu=new TextEncoder,Ku=new Uint32Array(64),Uu=new Uint32Array(8),wt=Array.from({length:256},(n,e)=>e.toString(16).padStart(2,"0"));function ba(n){let e=Bu.encode(n),t=e.length*8,r=new Uint8Array(e.length+9+63>>6<<6);r.set(e),r[e.length]=128;let o=new DataView(r.buffer);o.setUint32(r.length-8,Math.floor(t/2**32)),o.setUint32(r.length-4,t>>>0);let i=Uu;i[0]=1779033703,i[1]=3144134277,i[2]=1013904242,i[3]=2773480762,i[4]=1359893119,i[5]=2600822924,i[6]=528734635,i[7]=1541459225;let s=Ku;for(let d=0;d<r.length;d+=64){for(let y=0;y<16;y++)s[y]=o.getUint32(d+y*4);for(let y=16;y<64;y++){let S=s[y-15],A=s[y-2],m=(S>>>7|S<<25)^(S>>>18|S<<14)^S>>>3,k=(A>>>17|A<<15)^(A>>>19|A<<13)^A>>>10;s[y]=s[y-16]+m+s[y-7]+k>>>0}let f=i[0],c=i[1],p=i[2],u=i[3],l=i[4],g=i[5],h=i[6],v=i[7];for(let y=0;y<64;y++){let S=(l>>>6|l<<26)^(l>>>11|l<<21)^(l>>>25|l<<7),A=l&g^~l&h,m=v+S+A+Gu[y]+s[y]>>>0,k=(f>>>2|f<<30)^(f>>>13|f<<19)^(f>>>22|f<<10),w=f&c^f&p^c&p,x=k+w>>>0;v=h,h=g,g=l,l=u+m>>>0,u=p,p=c,c=f,f=m+x>>>0}i[0]=i[0]+f>>>0,i[1]=i[1]+c>>>0,i[2]=i[2]+p>>>0,i[3]=i[3]+u>>>0,i[4]=i[4]+l>>>0,i[5]=i[5]+g>>>0,i[6]=i[6]+h>>>0,i[7]=i[7]+v>>>0}let a="";for(let d=0;d<8;d++){let f=i[d];a+=wt[f>>>24]+wt[f>>>16&255]+wt[f>>>8&255]+wt[f&255]}return a}var Cn=class{constructor(e){this.inner=e}seen=new Set;reads(){return[...this.seen]}markAll(e){for(let t of e)this.seen.add(t.id);return e}markEdges(e){for(let t of e)this.seen.add(t.from),this.seen.add(t.to);return e}getNode(e){return this.seen.add(e),this.inner.getNode(e)}has(e){return this.seen.add(e),this.inner.has(e)}allNodes(e){return this.markAll(this.inner.allNodes(e))}allEdges(e){return this.markEdges(this.inner.allEdges(e))}nodesOfKind(e,t){return this.markAll(this.inner.nodesOfKind(e,t))}edgesOfKind(e,t){return this.markEdges(this.inner.edgesOfKind(e,t))}out(e,t,r){return this.seen.add(e),this.markAll(this.inner.out(e,t,r))}in(e,t,r){return this.seen.add(e),this.markAll(this.inner.in(e,t,r))}neighbors(e,t){return this.seen.add(e),this.markAll(this.inner.neighbors(e,t))}};function Vu(n,e){return{...e,name:n}}function Vr(n){if(!n.creates?.length)return!1;let e=n.input.shape;return e===void 0||!("id"in e)}function ka(n){let e=n.input,t=e._zod?.def;if(t?.type!=="object"||t.catchall!==void 0||!e.shape)return;let r=Object.keys(e.shape);return Vr(n)?[...r,"id"]:r}var va=(n,e)=>`does not take ${n.map(t=>`"${t}"`).join(", ")}; it takes ${e.length>0?e.map(t=>`"${t}"`).join(", "):"nothing"}`;function Wu(n){if(typeof n!="object"||n===null)return;let e=n.id;if(e!==void 0){if(typeof e!="string"||e.trim().length===0)throw new N("An id must be a non-empty string",`Got ${JSON.stringify(e)}.`);return e}}function qu(n){let{id:e,...t}=n;return t}function xa(n){return n.normalize("NFKD").replace(/\p{M}/gu,"").toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"")||"item"}function Sa(n){let e=2166136261;for(let t=0;t<n.length;t++)e=Math.imul(e^n.charCodeAt(t),16777619);return(e>>>0).toString(36).padStart(7,"0")}function Hu(n,e){if(e.limited&&e.me===void 0)return wa(n,e.held);let t=e.limited?`${n}.${Sa(e.me)}`:n,r=t;for(let o=2;e.seen(r);o++)r=`${t}-${o}`;return e.held(r)?wa(t,e.held):r}function wa(n,e){let t;do t=`${n}-${Math.floor(Math.random()*36**6).toString(36).padStart(6,"0")}`;while(e(t));return t}function an(n,e,t,r={}){let o=Vr(e)?Wu(t):void 0,i=o===void 0?t:qu(t),s=ka(e);if(s&&typeof i=="object"&&i!==null&&!Array.isArray(i)){let m=Object.keys(i).filter(k=>!s.includes(k)&&i[k]!==void 0);if(m.length>0)throw new re(e.name,[{path:[],message:va(m,s)}])}let a=e.input.safeParse(i);if(!a.success){let m=Object.keys(e.input.shape??{});throw new re(e.name,a.error.issues.map(k=>k.code==="unrecognized_keys"&&m.length>0?{...k,message:va(k.keys,m)}:k))}let d=a.data,f=new Cn(r.seen??n),c=[],p=new Set,u=m=>f.has(m)||n.has(m)||p.has(m),l,g=m=>{let k=new Set([...n.outEdges(m),...n.inEdges(m)]);for(let w of k)f.getNode(w.from),f.getNode(w.to),c.push({op:"remove-edge",edge:w});return k},h={graph:f,schema:n.schema,me:r.me,emit(m){c.push(m)},addNode(m){c.push({op:"add-node",node:m})},removeNode(m){let k=f.getNode(m)&&n.getNode(m);if(!k)throw new B(m,`Cannot remove missing node "${m}"`);g(m),c.push({op:"remove-node",node:k})},patchNode(m,k){let w=f.getNode(m)&&n.getNode(m);if(!w)throw new B(m,`Cannot patch missing node "${m}"`);let x={},b={};for(let[$,R]of Object.entries(k)){let _=w[$];JSON.stringify(_)===JSON.stringify(R)&&!r.keepUnchanged?.(R,$,w)||(x[$]=_,b[$]=R)}Object.keys(b).length!==0&&c.push({op:"patch-node",id:m,before:x,after:b})},archiveNode:m=>h.patchNode(m,{[Ye]:!0}),unarchiveNode:m=>h.patchNode(m,{[Ye]:void 0}),mergeNode(m,k){let w=f.getNode(k)&&n.getNode(k);if(!w)throw new B(k,`Cannot merge into missing node "${k}"`);if(m===k||Ee(w))throw new N(m===k?"Cannot merge a record into itself":"Cannot merge into an archived record");let x=new Set([...n.outEdges(k),...n.inEdges(k)].map(z));for(let b of g(m)){let $={kind:b.kind,from:b.from===m?k:b.from,to:b.to===m?k:b.to};$.from!==$.to&&!x.has(z($))&&(x.add(z($)),c.push({op:"add-edge",edge:$}))}h.archiveNode(m),l=k},addEdge(m){c.push({op:"add-edge",edge:m})},removeEdge(m){c.push({op:"remove-edge",edge:m})},setSingleSource(m,k,w){n.inEdges(k,m).some(x=>x.from===w)||c.push({op:"add-edge",edge:{kind:m,from:w,to:k}});for(let x of n.inEdges(k,m))f.getNode(x.from),x.from!==w&&c.push({op:"remove-edge",edge:x})},freshId(m,k){if(o!==void 0&&!p.has(o)){if(r.seesInFull&&!r.seesInFull())throw new N(`"${e.name}" makes its own id here`,"Leave id out: the answer says the id it made.");if(u(o))throw new N(`Id "${o}" is already taken`,`"${e.name}" was asked to make a node with that id, and the graph has one. Pick another, or leave id out and let the act mint one.`);return p.add(o),o}let w=k?`${k}:${xa(m)}`:xa(m),b=Hu(w,{seen:$=>(r.seen?r.seen.has($):n.has($))||p.has($),held:u,limited:r.seesInFull!==void 0&&!r.seesInFull(k),me:r.me});return p.add(b),b}};e.apply(h,d);let v=r.check?.(c,e),y=new Set(c.flatMap($e)),S=new Cn(r.seen??n),A=e.describe?.(d,S)??`${e.name}(${Object.entries(d).map(([m,k])=>`${m}=${JSON.stringify(k)}`).join(", ")})`;return{primitives:c,reads:[...new Set([...f.reads(),...S.reads()])],...e.describe?{described:[...S.reads(),...v??[]]}:{},writes:[...y],intent:A,...l!==void 0?{mergedInto:l}:{}}}var $a=Symbol.for("@graview/core:amount"),Ub=(n,e)=>(Object.defineProperty(I(n),$a,{value:e,enumerable:!0}),n);function Wr(n,e=!0){let t=I(n);return t?.[$a]??(e&&t?.innerType?Wr(t.innerType):void 0)}function Ra(n,e={}){let t=Number.isInteger(n),r={maximumFractionDigits:t?0:2,minimumFractionDigits:t?0:2};try{return ie(n,e.locale,e.currency?{style:"currency",currency:e.currency,...r}:r)}catch{return ie(n,e.locale,r)}}function _a(n,{format:e,unit:t,currency:r,locale:o}){let i=/^[A-Z]{3}$/.test(t??"");return e==="money"||!e&&i?Ra(n,{...o?{locale:o}:{},...(i?t:r)?{currency:i?t:r}:{}}):e==="percent"?ie(n,o,{style:"percent",maximumFractionDigits:0}):ie(n,o)+(t?` ${t}`:"")}var Yu=Symbol.for("@graview/core:typed-field");function qr(n){let e=I(n);return e?e[Yu]??qr(e.innerType):void 0}var Ju=/^[("'“‘]*(?:(?:[a-z]{1,3}\.){2,}|(?:dr|mr|mrs|ms|mx|st|mt|vs|jr|sr|prof|no|fig|approx)\.)$/i;function Xu(n){for(let e of n.matchAll(/[.!?](?=\s|$)/g)){let t=n.slice(0,e.index+1),r=/\S+$/.exec(t)?.[0]??"";if(!(e[0]==="."&&Ju.test(r))&&!(t.split(" ").length<3&&e.index+1<n.length))return t}}function Aa(n,e=140){let t=n.replace(/^[#>\s]+|\*\*|`|\](\([^)\s]*\))?|\[/gm,"").replace(/\s+/g," ").trim(),r=Xu(t);return r&&r.length<=e?r:t.length<=e?t:`${(t.slice(0,e+1).replace(/\s+\S*$/,"")||t.slice(0,e)).replace(/[\s,;:.—-]+$/,"")}\u2026`}function Qu(n){let e=n.fields.shape;return Object.keys(e).flatMap(t=>{let r=lt(e[t])?Pn(t):void 0;return r&&e[r]?[r]:[]})}var el=[["skip","Skip this one","Leave one day out of the series; the rest stay as they are.","Skip {} on "],["detach","Change just this one","Make one day of the series a record of its own, to change apart from the rest.","Change {} only on "],["split","Change from here","End the series the day before, and start it again from that day with what changes.","Change {} from "]];function Oa(n,e){let t=new Set(e.map(o=>o.name)),r=[];for(let o of n.definitions){let i=Qu(o);if(i.length===0)continue;let s=o.kind,a=o.fields.shape,d=Object.keys(a).filter(c=>!(c in(o.fixed??{}))),f=c=>F(o,c);for(let[c,p,u,l]of el){let g=`${c}-${s}`;t.has(g)||r.push({name:g,derived:{kind:s,act:c},title:p,description:u,subject:{kinds:[s],arg:"id"},writes:i.map(qe),...c==="skip"?{}:{creates:[s]},input:Ve({id:ke([s]),on:D().check(Rn(/^\d{4}-\d{2}-\d{2}$/,"a day, like 2026-10-21")),...i.length>1?{field:Q(cs(i))}:{},...c==="skip"?{}:Object.fromEntries(d.map(h=>[h,Q(a[h])]))}),describe:(h,v)=>l.replace("{}",f(v.getNode(String(h.id))??{id:h.id}))+ge(String(h.on)),apply(h,v){let y=h.graph.getNode(String(v.id)),S=String(v.field??i[0]),A=y?.[S],m=y?.[qe(S)],k=String(v.on);if(typeof A!="string"||!He(m))throw new ee(`${f(y??{id:v.id})} does not repeat`,"refused");let w=We(A,m,{from:k,to:k})[0];if(!w)throw new ee(`${f(y)} does not fall on ${ge(k)}`,"refused");let x=String(y.id),b=Object.fromEntries(d.filter(Y=>v[Y]!==void 0).map(Y=>[Y,v[Y]])),$=qe(S),R=Y=>{let Ro=Object.fromEntries(Object.entries({...y,...Y,...b}).filter(([Wn,Tt])=>Tt!=null&&Wn!=="id")),_o=h.freshId(f(Ro));h.addNode({...Ro,id:_o,kind:s});for(let Wn of Object.keys(o.edges??{}))for(let Tt of h.graph.out(x,Wn))h.addEdge({kind:Wn,from:_o,to:Tt.id})};if(c!=="split"){h.patchNode(x,{[$]:{...m,except:[...new Set([...m.except??[],k])].sort()}}),c==="detach"&&R({[S]:w,[$]:null});return}if(Object.keys(b).length===0)throw new ee(`Nothing to change: give ${f(y)} from ${ge(k)} something new`,"invalid");if(k<=A.slice(0,10))return h.patchNode(x,b);let _=new Date(Date.parse(`${k}T00:00:00Z`)-864e5).toISOString().slice(0,10),P=m.count?We(A,{...m,except:[]},{to:_}).length:0,{count:E,except:L,...So}=m,$o=Y=>L?.some(Y)?{except:L.filter(Y)}:{};h.patchNode(x,{[$]:{...So,until:_,...$o(Y=>Y<k),...E?{count:P}:{}}}),R({[S]:w,[$]:{...So,...$o(Y=>Y>=k),...E?{count:E-P}:{},continues:x}})}})}}return r}function Ea(n,e){let t=new Set(e.map(d=>d.name)),r=e.filter(d=>!d.derived),o=new Set(r.flatMap(d=>d.connects??[])),i=new Set(r.flatMap(d=>d.severs??[])),s=[],a=(d,f)=>{let c=d.getNode(String(f));return c?F(n.tryDefinition(c.kind),c):String(f)};for(let d of n.definitions){let f=d.kind,c=Object.entries(d.edges??{}),p=u=>u.to==="*"?"record":u.to.map(l=>K(n.tryDefinition(l),l)).join(" or ");for(let[u,l]of c){let g=p(l),h=l.cardinality==="one",v=c.some(([A,m])=>A!==u&&p(m)===g),y={to:g,from:K(d,f),one:h,also:v?C(u).toLowerCase():void 0},S=y.from;for(let A of Us){let m=Ws(A,f,u);if(t.has(m)||l.acts==="none"||(A==="connect"?o.has(u):i.has(u)||l.appendOnly))continue;let{title:k,fromTheOtherEnd:w}=qs(A,y),x=l.description?`: ${l.description.replace(/\.$/,"")}`:"";s.push({name:m,derived:{kind:f,act:A,relation:u},title:k,fromTheOtherEnd:w,description:A==="connect"?`Link this ${S} to ${/^[aeiou]/i.test(g)?"an":"a"} ${g}${x}.${h?" It has one, so this replaces the one it has.":""}`:`Take away the link between this ${S} and ${/^[aeiou]/i.test(g)?"an":"a"} ${g}${x}. Undo puts it back.`,subject:{kinds:[f],arg:"id"},...A==="connect"?{connects:[u]}:{severs:[u],destructive:!0},idempotent:!0,input:Ve({id:ke([f]),to:ke(l.to==="*"?"*":l.to)}),describe:(b,$)=>A==="disconnect"?`Unlink ${a($,b.id)} from ${a($,b.to)}`:h?`Set the ${g} of ${a($,b.id)} to ${a($,b.to)}`:`Link ${a($,b.id)} to ${a($,b.to)}`,apply(b,$){let R=String($.id),_=String($.to);for(let E of[R,_])if(!b.graph.getNode(E))throw new ee(`there is no record "${E}"`,"invalid");let P=b.graph.out(R,u).some(E=>E.id===_);if(A==="disconnect"){if(!P)throw new ee(`${a(b.graph,R)} is not linked to ${a(b.graph,_)}`,"invalid");b.removeEdge({kind:u,from:R,to:_});return}if(h)for(let E of b.graph.out(R,u))E.id!==_&&b.removeEdge({kind:u,from:R,to:E.id});P||b.addEdge({kind:u,from:R,to:_})}})}}}return s}function Pa(n){let e=n.fields.shape;return Object.keys(e).filter(t=>!(t in(n.fixed??{})))}function Hr(n,e){let t=e.subject;return t?t.kinds==="*"?n.kinds:t.kinds:[]}function Yr(n,e){let t=n.subject;if(!t||!n.writes&&n.creates?.length)return[];let r=new Set(Object.keys(e.fields.shape));if(n.writes)return n.writes.filter(s=>r.has(s));let o=n.input.shape??{},i=new Set(Ln(n.input).map(s=>s.name));return Object.keys(o).filter(s=>s!==t.arg&&r.has(s)&&!i.has(s))}function za(n,e){let t=new Map,r=(o,i,s)=>{let a=t.get(o)??new Map;a.get(i)?.includes(s)||(a.set(i,[...a.get(i)??[],s]),t.set(o,a))};for(let o of e){for(let i of Hr(n,o)){let s=n.tryDefinition(i);if(s)for(let a of Yr(o,s))r(i,a,o.name)}for(let[i,s]of Object.entries(o.writesOther??{})){let a=n.tryDefinition(i)?.fields.shape;if(a)for(let d of s)d in a&&r(i,d,o.name)}}return t}function Ma(n,e,t){let r=n.tryDefinition(t);if(!r)return[];let o=za(n,e).get(t);return Pa(r).filter(i=>!o?.has(i))}var Na=n=>`edit-${n}`;function Ia(n,e,t){let r=n.tryDefinition(t);if(!r)return[];let o=new Set;for(let i of e)i.derived||((i.creates??[]).includes(t)&&o.add(i.name),Hr(n,i).includes(t)&&Yr(i,r).length>0&&o.add(i.name));return[...o]}function ja(n,e){let t=new Set(e.map(o=>o.name)),r=[];for(let o of n.definitions){let i=o.kind,s=Na(i);if(t.has(s))continue;let a=Ma(n,e,i);if(a.length===0)continue;let d=o.fields.shape,f=K(o,i),c=a.map(p=>Qn(o,p).toLowerCase());r.push({name:s,derived:{kind:i,act:"edit"},idempotent:!0,title:`Change the ${f}`,description:`Change what was set when this ${f} was made: ${c.join(", ")}.`,subject:{kinds:[i],arg:"id"},writes:a,input:Ve({id:ke([i]),...Object.fromEntries(a.map(p=>[p,Q(rl(d[p]))]))}),describe:(p,u)=>nl(o,d,a,p,u),apply(p,u){let l={};for(let g of a){let h=u[g];h!==void 0&&(l[g]=h)}if(Object.keys(l).length===0)throw new ee(`Nothing to change \u2014 give at least one of ${c.join(", ")} a value.`,"invalid");p.patchNode(u.id,l)}})}return r}function nl(n,e,t,r,o){let i=o.getNode(r.id),s=i?F(n,i):"a record",a=t.filter(d=>r[d]!==void 0).map((d,f)=>{let c=r[d],p=Pn(d),u=p!==void 0&&p in e,l=Qn(n,u?p:d);return`the ${l===l.toUpperCase()?l:l.charAt(0).toLowerCase()+l.slice(1)}${f===0?` of ${s}`:""} to ${u?c?`repeat ${tl(c)}`:"stop repeating":Ta(n,e[d],d,c)}`});return a.length===0?`Changed nothing on ${s}`:`Changed ${a.length>1?`${a.slice(0,-1).join(", ")} and ${a.at(-1)}`:a[0]}`}var tl=n=>`every ${(n.interval??1)>1?`${n.interval} ${n.every}s`:n.every}`;function Ta(n,e,t,r){if(r===null||r===""||Array.isArray(r)&&r.length===0)return"nothing";let o=n.display?.format?.[t];try{if(o)return String(o(r))}catch{}if(An(r).length>0)return An(r).map(i=>i.name).join(", ");if(On(e))return Array.isArray(r)&&r.length>1?`${r.length} linked records`:"a linked record";if(Array.isArray(r))return r.map(i=>Ta(n,e,t,i)).join(", ");if(typeof r=="boolean")return r?"yes":"no";if(typeof r=="number"){let i=Wr(e);return i?_a(r,i):qr(e)==="duration"?`${r>=60?`${Math.floor(r/60)} h `:""}${r%60||r<60?`${r%60} min`:""}`.trim():String(r)}if(typeof r!="string")return"a new value";if(Le.test(r))return ge(r);if(Hn.test(r))return Lt(r);for(let i=I(e);i;i=I(i.innerType))if(i.type==="enum")return C(r);return`\u201C${Aa(r,60)}\u201D`}function rl(n){let e=n;for(let t=0;t<4;t++){let r=e._zod?.def;if((r?.type==="default"||r?.type==="prefault")&&r.innerType)e=r.innerType;else break}return e}function Da(n,e){return n.filter(t=>!t.derived&&(t.creates??[]).includes(e)).map(t=>t.name)}function kt(n,e,t){if(!t.derived)return;let r=t.derived.act;return r==="edit"||r==="skip"||r==="detach"||r==="split"||r==="connect"||r==="disconnect"?Ia(n,e,t.derived.kind):Da(e,t.derived.kind)}function ol(n,e){let t=new Set(e.map(o=>o.name)),r=[];for(let o of n.definitions){let i=o.kind,s=K(o,i),a=(f,c)=>{let p=f.getNode(String(c));return p?F(o,p):String(c)},d=ke([i]);for(let[f,c,p,u]of[["remove","Remove",`Remove the ${s}`,`Take this ${s} out of the graph, with every tie it has. Undo puts it back.`],["archive","Archive",`Archive the ${s}`,`Set this ${s} aside, with its ties and history kept.`],["unarchive","Bring back","Bring it back",`Bring this archived ${s} back.`],["merge","Merge",`Merge into another ${s}`,`The other takes this ${s}'s ties, and this one is archived.`],["leave-alone","Leave alone","Leave this one alone",`Nothing automated changes this ${s}: tidying passes it by until you allow it again.`],["allow-tidying","Allow tidying of","Allow tidying again",`Let tidying change this ${s} again.`]]){let l=`${f}-${i}`,g=f==="leave-alone"||f==="allow-tidying";t.has(l)||!g&&f!=="remove"&&o.archives===!1||g&&o.tidying==="never"||r.push({name:l,derived:{kind:i,act:f},title:p,description:u,subject:{kinds:[i],arg:"id"},...f==="remove"?{destructive:!0}:{},idempotent:!0,input:Ue(f==="merge"?{id:d,into:d}:{id:d}),describe:(h,v)=>{let y=f==="remove"&&v.getNode(String(h.id)),S=y?new Set(Object.values(y).flatMap(A=>An(A).map(m=>m.href))).size:0;return`${c} ${a(v,h.id)}${f==="merge"?` into ${a(v,h.into)}`:""}${S?` and its ${S} file${S>1?"s":""}`:""}`},apply:g?(h,v)=>h.patchNode(String(v.id),{[Mn]:f==="leave-alone"?!0:void 0}):(h,v)=>h[`${f}Node`](v.id,v.into)})}}return r}function Jr(n,e){return[...ja(n,e),...ol(n,e),...Oa(n,e),...Ea(n,e)]}var il=n=>({$made:n}),St=n=>typeof n=="object"&&n!==null&&Object.keys(n).join()==="$made"&&Number.isInteger(n.$made)&&n.$made>=0,sl=(n,e)=>Object.fromEntries(Object.entries(n.args??{}).map(([t,r])=>[t,Array.isArray(r)?r.map(e):e(r)])),Fa=n=>Object.values(n.args??{}).some(e=>St(e)||Array.isArray(e)&&e.some(St)),Za=(n,e,t)=>({...n,args:sl(n,r=>{if(!St(r))return r;let o=r.$made<t?e[r.$made]:void 0;if(o===void 0)throw new Error(`\u201C${n.name}\u201D names the record call ${r.$made+1} makes, and no call before it made that record.`);return o})});var al=500,Xr=120;function Gn(n){if(n===void 0)return;let{basis:e,confidence:t,model:r,suggestion:o,interaction:i}=n??{},s=typeof e=="string"?e.trim():"",a=typeof r=="string"?r.trim():"";if(!s||s.length>al||t!==void 0&&!(typeof t=="number"&&t>=0&&t<=1)||r!==void 0&&!(a&&a.length<=Xr)||o!==void 0&&!(typeof o=="string"&&o.length>0&&o.length<=Xr)||i!==void 0&&!(typeof i=="string"&&i.length>0&&i.length<=Xr))throw new N("A lineage is { basis: 1\u2013500 characters, confidence?: 0\u20131, model?: 1\u2013120 characters, suggestion?: an op id, interaction?: an AI interaction's id }");return{basis:s,...t!==void 0?{confidence:t}:{},...a?{model:a}:{},...typeof o=="string"?{suggestion:o}:{},...typeof i=="string"?{interaction:i}:{}}}var dn="keep-link";function La(n){let e=(t,r)=>{let o=t.getNode(r);return o?F(n.tryDefinition(o.kind),o):r};return{name:dn,title:"Keep this link",input:Ue({kind:D(),from:D(),to:D()}),describe:(t,r)=>`Keep the link from ${e(r,t.from)} to ${e(r,t.to)}`,apply(t,r){let{kind:o,from:i,to:s}=r;if(!t.graph.getNode(i)||!t.graph.getNode(s)){let a=z({kind:o,from:i,to:s});throw new B(a,`Cannot remove missing edge ${a}`)}t.removeEdge({kind:o,from:i,to:s}),t.addEdge({kind:o,from:i,to:s})}}}var Ca=(n,e)=>[...n].filter(t=>!t.derived&&t.name!==dn&&typeof e=="string"&&(t.connects?.includes(e)||t.severs?.includes(e))).map(t=>t.name);var Ga=["kind-unknown","node-shape","edge-dangling","edge-disallowed","rule-error","rule-budget"];function Ba(n,e){let t=pt(n,e);return t&&[...t.fields].filter(Boolean)}function dl(n,e,t){return n.tryDefinition(e)?.fields?.shape?.[t]}function $t(n,e){try{return F(n.tryDefinition(e.kind),e)}catch{return typeof e.label=="string"?e.label:"A record"}}var cl=n=>`${n.kind}:${n.from}->${n.to}`,Rt=(n,e)=>n<e?-1:n>e?1:0;function Ka(n,e,t={}){let{schema:r}=n,o=[],i=new Map;for(let u of e.nodes)i.has(u.id)||i.set(u.id,u);let s=u=>e.edges.filter(l=>l.from===u||l.to===u),a=u=>({action:"drop",primitives:[...s(u.id).filter(l=>i.has(l.from)&&i.has(l.to)).map(l=>({op:"remove-edge",edge:l})),{op:"remove-node",node:u}]}),d=new Set;for(let u of[...i.values()].sort((l,g)=>Rt(l.id,g.id))){if(!r.tryDefinition(u.kind)){d.add(u.id),o.push({code:"kind-unknown",id:u.id,message:`${$t(r,u)} is a kind of record this app no longer has`,repair:a(u)});continue}let l=Ba(r,u);if(l===void 0)continue;let g=$t(r,u),h=new Map,v=l.length>0;for(let y of l){if(y==="id"||y==="kind"){v=!1;continue}let S=dl(r,u.kind,y),A=S?S.safeParse(void 0):{success:!0,data:void 0},m=r.tryDefinition(u.kind)?.defaults;!A.success&&S&&m&&Object.hasOwn(m,y)&&(A=S.safeParse(m[y])),A.success?A.data===void 0?h.set(y,{action:"clear",value:pe}):h.set(y,{action:"coerce",value:A.data}):v=!1}if(v){let y={...u};for(let[S,A]of h)A.value===pe?delete y[S]:y[S]=A.value;Ba(r,y)!==void 0&&(v=!1)}if(l.length===0){o.push({code:"node-shape",id:u.id,message:`${g} does not fit what ${u.kind} declares`,repair:a(u)});continue}for(let y of l){let S=h.get(y),A=v&&S?{action:S.action,primitives:[{op:"patch-node",id:u.id,before:{[y]:u[y]===void 0?pe:u[y]},after:{[y]:S.value}}]}:a(u);o.push({code:"node-shape",id:u.id,detail:y,message:`${g}: ${C(y)} does not fit what ${u.kind} declares`,repair:A})}}let f=new Set,c=[];for(let u of[...e.edges].sort((l,g)=>Rt(z(l),z(g)))){if(f.has(z(u)))continue;f.add(z(u));let l=cl(u),g=i.get(u.from),h=i.get(u.to);if(!g||!h){o.push({code:"edge-dangling",id:l,message:"A link points at a record that is not there",repair:{action:"drop",primitives:[{op:"remove-edge",edge:u}]}});continue}c.push(u),!(d.has(g.id)||d.has(h.id))&&(r.edgeAllowed(u.kind,g.kind,h.kind)||o.push({code:"edge-disallowed",id:l,message:`${$t(r,g)} \u2192 ${$t(r,h)}: this app does not allow that link between them`,repair:{action:"drop",primitives:[{op:"remove-edge",edge:u}]}}))}let p=n.invariants??[];if(p.length>0){let u=W.from(r,{nodes:[...i.values()],edges:c},{validate:!1}),l=new Set,g;try{g=Xe(u,p,t.invariantOptions??{})}catch{g=[{invariant:"rules",status:"could-not-judge",label:"The rules",message:"The rules could not be judged",nodeIds:[],repairs:[]}]}for(let h of g){let v=h.status==="could-not-judge"?"rule-error":h.status==="over-budget"?"rule-budget":void 0;if(!v)continue;let y=h.subjectId??h.invariant,S=`${v}|${y}|${h.invariant}`;l.has(S)||(l.add(S),o.push({code:v,id:y,detail:h.invariant,message:h.message}))}}return o.sort((u,l)=>Ga.indexOf(u.code)-Ga.indexOf(l.code)||Rt(u.id,l.id)||Rt(u.detail??"",l.detail??""))}var Bn=()=>globalThis.__graviewWatch;function Ua(n){Bn()?.store?.(n)}function _t(n){n!==void 0&&Bn()?.learn?.({ids:[n],words:[]})}function Va(n,e){Bn()?.refused?.({...n,...e===void 0?{}:{author:e}})}function Qr(n,e){let t=Bn();if(!t?.refusedInput)return;let r=n.issues.map(o=>`${o.path.map(String).join(".")}: ${o.message}`).join("; ");t.refusedInput({mutation:n.mutation,message:r,...e===void 0?{}:{author:e}})}function ul(n,e){n instanceof re&&Qr(n,e)}function ll(n,e,t){Bn()?.seat?.(n,e,t)}function no(n,e){if(typeof n=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(n))return n;let t=new Date(n).getTime();if(Number.isNaN(t))throw new Error(`Not a day: ${String(n)}`);return H(e,t)}var eo=15*6e4;function Wa(n=Date.now(),e){let t=new Date(n).getTime(),r=Yn(e),o=H(r,t),i=new Date(Date.parse(`${o}T00:00:00Z`));if(i.setUTCDate(i.getUTCDate()+1),!r)return i.getTime()-t;let s=Oo(i.toISOString().slice(0,10),0,r);for(;H(r,s)===o;)s+=eo;for(;H(r,s-eo)!==o;)s-=eo;return s-t}function fl(n,e){let t,r=()=>{t=setTimeout(()=>{let o=n.tick(new Date);r(),e?.(o)},Wa(Date.now(),n.timeZone)+1e3),t.unref?.()};return r(),()=>clearTimeout(t)}var At=class extends N{constructor(e){super(`This is the app as it stood${e.at?` at ${e.at}`:" at the start"}: the past is read, never changed`),this.name="PastError"}},to="preview",Z=(n,e)=>e===void 0?{}:{[n]:e},Ne={kind:"human"},qa={kind:"system"},Ya={kind:"system",id:"modules",name:"Modules"},Ha=n=>n.mutation===null&&n.undoes===void 0;function ro(n,e){return`${n.invariant}|${n.subjectId??""}|${n.line||e?.has(n.invariant)?n.label:n.message}`}var pl=new Set(["remove","archive","unarchive","merge"]),hl={has:()=>!0},Ja=n=>new Set(n.filter(e=>e.shape).map(e=>e.name));function Xa(n,e,t){let r=Ja(n),o=p=>ro(p,r),i=new Set(e.map(o)),s=new Set(t.map(o)),a=t.filter(p=>!i.has(o(p))),d=e.filter(p=>!s.has(o(p)));if(a.length===0||d.length===0)return{introduces:a,resolves:d};let f=p=>p.subjectId&&ro(p,hl),c=d.map(f);return{introduces:a.filter(p=>{let u=f(p)?c.indexOf(f(p)):-1;return u<0||(c[u]=null,!1)}),resolves:d.filter((p,u)=>c[u]!==null)}}var cn=class extends Error{constructor(t,r){super(`Op "${t.id}" (${t.intent}) could not be applied: ${r instanceof Error?r.message:String(r)}`,{cause:r});this.op=t;this.name="ReceiveError"}},Ot=class extends N{constructor(t,r){super(`Unknown mutation "${t}"`,`Registered: ${r.join(", ")||"(none)"}`);this.mutation=t;this.name="UnknownMutationError"}};function gl(){let n=globalThis.crypto,e=new Uint8Array(6);if(n?.getRandomValues)n.getRandomValues(e);else for(let t=0;t<e.length;t++)e[t]=Math.floor(Math.random()*256);return[...e].map(t=>t.toString(36).padStart(2,"0")).join("")}var oo=class n{schema;graph;log;mutations=new Map;keeper;invariants;invariantOptions;policy;intelligence;may=new Map;by;declaredModules;startingModules;projected;nextId;now;validate;mintBatch;batchTag;counter=0;opCount=0;quiet=0;rehearsing=!1;suggesting=!1;ticked;timeZone;past;pastEvery;listeners=new Set;constructor(e){this.pastEvery=Math.max(1,e.pastEvery??64),this.past=e.past,this.schema=e.schema,this.invariants=e.invariants??[],this.invariantOptions=e.invariantOptions??{},this.timeZone=e.timeZone,this.timeZone&&(this.ticked={day:H(this.timeZone),on:H(this.timeZone)}),this.policy=e.policy,this.by=e.principal??Ne,this.intelligence=e.intelligence??[];for(let i of e.intelligence??[])i.may&&this.may.set(i.name,new Set(i.may));this.declaredModules=e.modules,this.startingModules=e.enabledModules,this.nextId=e.ids??(()=>`op${++this.opCount}`),this.now=e.now??(()=>new Date().toISOString()),this.validate=e.validate??!0;let t=gl();this.batchTag=e.batchIds?void 0:t,this.mintBatch=e.batchIds??(i=>`${i}:${t}:${++this.counter}`);for(let i of e.past?[]:e.mutations??[]){if(this.mutations.has(i.name))throw new N(`Duplicate mutation "${i.name}"`);this.mutations.set(i.name,i)}for(let i of e.past?[]:Jr(e.schema,e.mutations??[]))this.mutations.set(i.name,i);!e.past&&!this.mutations.has(dn)&&(this.keeper=La(e.schema),this.mutations.set(dn,this.keeper));let r=Z("horizon",e.horizon),o={validate:this.validate};if(e.log){this.log=nn.from(e.log,e.epochs,r);let i=this.log.lastEpoch();this.graph=e.snapshot?W.from(e.schema,e.snapshot,o):this.log.fold(e.schema,{...o,...i?{from:i}:{}})}else this.log=nn.from([],e.epochs??(e.snapshot?[{seq:e.horizon??0,base:e.snapshot}]:[]),r),this.graph=W.from(e.schema,e.snapshot??{nodes:[],edges:[]},o);e.past||(this.countPastTheLog(),Ua(this))}stillNow(){if(this.past)throw new At(this.past)}countPastTheLog(){let e=t=>{let r=/(\d+)$/.exec(t);return r?Number(r[1]):0};for(let t of this.log.all())this.counter=Math.max(this.counter,e(t.batch)),this.opCount=Math.max(this.opCount,e(t.id));this.log.horizon>0&&(this.opCount=Math.max(this.opCount,this.log.length))}get modules(){let e=this.log.all(),t=e.at(-1)?.id,r=this.projected;if(r&&r.length===e.length&&r.last===t)return r.projection;let o,i=0;r&&r.length<=e.length&&(r.length===0||e[r.length-1]?.id===r.last)&&(o=r.said,i=r.length);for(let a=e.length-1;a>=i;a--){let d=e[a].enabledModules;if(d!==void 0){o=d;break}}let s=r&&o===r.said?r.projection:Gr(this.declaredModules,o??this.startingModules);return this.projected={projection:s,length:e.length,last:t,said:o},s}setEnabledModules(e,t={}){this.stillNow();let r=this.modules.enabled,o=Gr(this.declaredModules,e).enabled,i=[...r].filter(c=>!o.has(c)),s=[...o].filter(c=>!r.has(c));if(i.length===0&&s.length===0)return;let a=c=>c.map(p=>{let u=this.declaredModules?.[p]?.kinds??[];return u.length>0?u.map(l=>ne(this.schema,l)).join(", "):p}).join(", "),d=[i.length>0?`Turn off ${a(i)}`:"",s.length>0?`turn on ${a(s)}`:""].filter(Boolean).join("; "),f={id:this.nextId(),seq:this.log.length,batch:t.batch??this.mintBatch("batch"),author:Ya,intent:vn(d),mutation:null,primitives:[],reads:[],writes:[],at:this.now(),...Z("via",t.via),enabledModules:[...o].sort()};return this.log.append(f),this.notify(Nn,[f]),f}mutation(e){let t=this.mutations.get(e);if(!t)throw new Ot(e,[...this.mutations.keys()]);if(this.mutationDisabled(t))throw new N(`Mutation "${e}" belongs to a module this workspace has turned off`,`Enabled modules: ${[...this.modules.enabled].join(", ")||"(none)"}`);return t}mutationDisabled(e){return this.modules.disabledMutations.has(e.name)?!0:e.derived!==void 0&&this.modules.disabledKinds.has(e.derived.kind)}allMutations(){return[...this.mutations.values()].filter(e=>e!==this.keeper&&!this.mutationDisabled(e))}viaOf(e,t){if(e!==void 0&&e===this.keeper){let r=Ca(this.mutations.values(),t?.args.kind);if(r.length>0)return r;let o=[...this.mutations.values()];return[...new Set(o.filter(i=>i.derived?.relation===t?.args.kind).flatMap(i=>kt(this.schema,o,i)??[]))]}if(e?.derived)return kt(this.schema,[...this.mutations.values()],e)}moved(e,t){return Xa(this.allInvariants(),e,t)}allInvariants(){return this.invariants.filter(e=>this.invariantEnabled(e))}invariantEnabled(e){if(this.modules.disabledInvariants.has(e.name))return!1;if(e.scope!=="graph"){let t=e.scope.kind;if(this.modules.disabledKinds.has(t))return!1}return!0}permits(e,t=Ne){if(this.past)return{ok:!1,refusal:{mutation:e.name,wouldNeed:[],message:"Nothing changes while you look back."}};let r=this.refusesAgent(e,t)??this.namesTurnedOff(e,t);if(r)return{ok:!1,refusal:r};let o=this.mutations.get(e.name),i=o?.subject&&e.args[o.subject.arg];return xe(this.policy,t,e.name,this.subjectKindOf(e,t),this.viaOf(o,e),typeof i=="string"?i:void 0,this.words,()=>{let s=T(t).id,a=this.namedIn(e,!1);try{for(let d of an(this.graph,o,e.args,this.sighted(t)).primitives)"edge"in d&&d.edge.from!==s&&d.edge.to!==s&&a.push(d.edge.to)}catch{}return a},o?.derived&&(()=>le(this.log).creatorOf(i)),o?.derived!==void 0&&pl.has(o.derived.act))}namedIn(e,t=!0){let r=this.mutations.get(e.name);if(!r)return[];let o=r.subject?.arg;return[...t&&o?[e.args[o]]:[],...Ln(r.input).flatMap(s=>s.name===o?[]:[e.args[s.name]])].flat().filter(s=>typeof s=="string")}refuse(e,t,r=!this.rehearsing){throw r&&Va(e,t),new ze(e)}get words(){return{act:e=>this.mutations.get(e)?.title,noun:e=>K(this.schema.tryDefinition(e),e)}}refusesAgent(e,t){if(t.kind!=="agent"||t.id===void 0)return;let r=this.may.get(t.id);if(!r||r.has(e.name))return;let o=s=>`\u201C${this.mutations.get(s)?.title??s}\u201D`,i=[...r].map(o);return{mutation:e.name,message:`${t.id} may not ${o(e.name)} here: it was declared able to ${i.length===0?"do nothing else":i.join(", ")}.`,wouldNeed:[]}}namesTurnedOff(e,t=qa){let r=this.modules.disabledKinds;if(r.size===0||!q(t))return;let o=this.mutations.get(e.name);if(!(!o||!this.namedIn(e).some(i=>r.has(this.graph.getNode(i)?.kind))))return{mutation:e.name,message:`\u201C${o.title??e.name}\u201D names a record of a module this workspace has turned off.`,wouldNeed:[]}}sighted(e){let t={me:e&&T(e).id};if(e===void 0||!on(this,e))return t;let r=Fn(this,e);return{...t,seen:Zn(this,e).graph,keepUnchanged:o=>j(o,r),seesInFull:da(this,e)}}missingFor(e,t=Ne){let r=this.mutations.get(e.name),o=new Set(this.namedIn(e));if(!r||o.size===0)return;let i=Zn(this,t).graph;for(let s of o)if(!i.has(s))return new B(s,`\u201C${r.title??e.name}\u201D names a record that is not there.`)}mayAdminister(e,t=Ne){let r=this.modules.administered.get(e);return r?(r.mutations??[]).some(o=>{let i=this.mutations.get(o);return!!i&&Er(i).some(s=>xe(this.policy,t,o,s,this.viaOf(i)).ok)}):!1}seenBy(e){return Zn(this,e)}sees(e,t){return this.graph.has(t)&&Fn(this,e)(t)}labels;resolveRef(e,t,r=Ne){let o=(this.policy?.sees?.length??0)>0,i=u=>!o||this.sees(r,u),s=this.graph.getNode(t);if(this.labels??=new xt(this.graph),s&&i(t))return{ok:!0,id:t,label:this.labels.labelOf(t)??t,by:"id"};let a=this.labels.lookup(e.kinds,t),d=u=>{let l=u.filter(g=>!this.graph.isArchived(g));return l.length?l:u},f=d(a.exact.filter(i)),c=f.length>0,p=(c?f:d(a.prefix.filter(i))).map(u=>({id:u,kind:this.graph.getNode(u).kind,label:this.labels.labelOf(u)??u})).sort((u,l)=>u.label<l.label?-1:u.label>l.label?1:u.id<l.id?-1:1);return p.length===1?{ok:!0,id:p[0].id,label:p[0].label,by:c?"label":"prefix"}:pa(this.schema,e,t,p)}kindsKeptFrom(e=Ne){let t=new Set;for(let[o,i]of this.modules.administered)if(!this.mayAdminister(o,e))for(let s of i.kinds??[])t.add(s);let r=this.policy?.sees??[];if(r.length>0&&!q(e)){let o=new Set(this.permittedMutations(e).flatMap(s=>s.creates??[])),i=we(this);for(let s of this.schema.kinds)!r.some(d=>d.kinds.includes(s)&&ve(d,e)&&(!d.own&&!d.via||e.id!==void 0)&&(i||!Dn(d)))&&!o.has(s)&&t.add(s)}return t}permittedMutations(e=Ne){let t=this.allMutations(),r=Or(this.policy,e,t.filter(i=>!i.derived)),o=t.filter(i=>i.derived!==void 0&&xe(this.policy,e,i.name,i.derived.kind,this.viaOf(i),T(e).id).ok);return[...r,...o]}subjectKindOf(e,t=qa){let o=this.mutations.get(e.name)?.subject;if(!o)return;let i=e.args[o.arg];if(typeof i!="string")return o.kinds!=="*"&&o.kinds.length===1?o.kinds[0]:void 0;if(!(!q(t)&&!Fn(this,t)(i)))return this.graph.getNode(i)?.kind}today(){return this.pinned()??(this.ticked&&this.ticked.on===H(this.timeZone)?this.ticked.day:void 0)??(this.timeZone?H(this.timeZone):void 0)}pinned(){let e=this.invariantOptions.context,t=this.invariantOptions.today??e?.today;return typeof t=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t)?t:void 0}judging(e){let t=this.today(),r=xs(this.graph),o=e??this.invariantOptions.context,i=r&&!(o&&"linked"in o)?{...o,linked:r}:e,s=i??o,a=this.timeZone&&t!==void 0&&e===void 0&&!(s&&"today"in s)?{...s,today:t}:i;return{...this.invariantOptions,...a===void 0?{}:{context:a},...t===void 0?{}:{today:t}}}tick(e=new Date){let t=this.pinned();if(t!==void 0)return{day:t,was:t,appeared:[],cleared:[]};let r=no(e,this.timeZone),o=H(this.timeZone);this.ticked&&(this.ticked={day:this.ticked.day,on:o});let i=this.today(),s=this.violations();this.ticked={day:r,on:o};let a=this.moved(s,this.violations());if(r!==i&&!this.rehearsing&&this.quiet===0)for(let d of this.listeners)d(Nn,[]);return{day:r,...i===void 0?{}:{was:i},appeared:a.introduces,cleared:a.resolves}}reread(){if(!(this.rehearsing||this.quiet>0))for(let e of this.listeners)e(Nn,[])}violations(e,t=this.graph){return Xe(t,this.allInvariants(),this.judging(e)).map(r=>this.asking(r))}required=new Map;asking(e){if(!e.repairs.some(o=>o.missing===void 0))return e;let t=!1,r=e.repairs.map(o=>{if(o.missing!==void 0)return o;let i=this.requiredOf(o.mutation).filter(s=>o.args?.[s]===void 0);return i.length===0?o:(t=!0,{...o,missing:i})});return t?{...e,repairs:r}:e}requiredOf(e){let t=this.required.get(e);if(t)return t;let r=this.mutations.get(e)?.input?.shape??{},o=Object.entries(r).filter(([,i])=>typeof i?.safeParse=="function"&&!i.safeParse(void 0).success).map(([i])=>i);return this.required.set(e,o),o}wouldChange(e,t){try{return an(this.graph,this.mutation(e.name),e.args,this.sighted(t)).primitives.length>0}catch{return!0}}preview(e,t,r={}){let o=this.mutation(e.name),i=an(this.graph,o,e.args,this.sighted(r.author));return this.previewPrimitives(i.primitives,{reads:i.reads,writes:i.writes,intent:i.intent,context:t})}previewAll(e,t={}){let{context:r,...o}=t;return{...this.rehearsal().applying(e,o,r),kept:!1}}rehearsal(){let e=Object.assign(Object.create(n.prototype),this),t=0;return Object.assign(e,{graph:W.from(this.schema,this.graph.snapshot(),{validate:this.validate}),log:nn.from(this.log.all(),this.log.epochs(),{horizon:this.log.horizon}),listeners:new Set,labels:void 0,nextId:()=>`${to}:${++t}`,mintBatch:()=>to,rehearsing:!0}),e}previewPrimitives(e,t){let r=this.violations(t.context),o=W.from(this.schema,this.graph.snapshot()),i=o.applyPrimitives(e,{restoring:t.restoring===!0}),s=Xe(o,this.allInvariants(),this.judging(t.context));return{diff:i,primitives:e,reads:t.reads,writes:t.writes,intent:t.intent,...this.moved(r,s),violationsAfter:s}}apply(e,t={}){return this.applyAll([e],t)}applyAll(e,t={}){return this.applying(e,t)}applying(e,t,r){this.stillNow();let o=t.batch??this.mintBatch("batch"),i=t.author??this.by,s=Gn(t.lineage),a=[],d=[],f=new Set,c=new Set,p=[],u=this.violations(r),l=this.graph.snapshot(),g=this.log.length,h=w=>{let x=this.policy?this.permits(w,i):void 0;x&&!x.ok&&this.refuse(x.refusal,i.id)},v=w=>{let x=this.refusesAgent(w,i)??this.namesTurnedOff(w,i);x&&this.refuse(x,i.id)},y=e.map(Fa);e.forEach((w,x)=>y[x]||h(w)),e.forEach((w,x)=>y[x]||v(w));let S=Nr(i);S&&this.refuseDeclined(e,i),this.rehearsing||_t(i.id);let A=[];try{for(let[w,x]of e.entries()){let b=y[w]?Za(x,A,w):x;y[w]&&(h(b),v(b));let $=this.mutation(b.name),R=this.missingFor(b,i);if(R)throw R;let _;try{_=an(this.graph,$,b.args,this.sighted(i))}catch(E){throw E instanceof re&&!this.rehearsing&&Qr(E,i.id),E}if(S){let E=Qs(this.schema,this.graph,_.primitives,this.authorName(i),{declaration:!this.suggesting});E&&this.refuse({mutation:b.name,message:E,wouldNeed:[]},i.id)}if(_.primitives.length===0)continue;A[w]=_.primitives.find(E=>E.op==="add-node")?.node.id;let P={id:this.nextId(),seq:this.log.length,batch:o,author:i,intent:$.describe!==void 0?_.intent:t.intent??_.intent,...Z("batchIntent",t.intent),mutation:b,primitives:_.primitives.map(qn),reads:_.reads,writes:_.writes,...$.describe!==void 0&&_.described&&_.described.length>0?{described:_.described}:{},...Z("mergedInto",_.mergedInto),at:this.now(),...Z("via",t.via),...Z("lineage",s)};this.graph.applyPrimitives(P.primitives),this.log.append(P),a.push(P),d.push(...P.primitives);for(let E of P.reads)f.add(E);for(let E of P.writes)c.add(E);p.push(P.intent)}}catch(w){throw this.putBack(l,g),w}let m=be(l,this.graph.snapshot(),d);this.admitted(t,a,d,m,l,g);let k=this.violations(r);return this.notify(m,a),{batch:o,ops:a,diff:m,primitives:d,reads:[...f],writes:[...c],intent:t.intent??p.join("; "),...this.moved(u,k),violationsAfter:k}}receive(e,t={}){this.stillNow();let r=new Set(this.log.all().map(d=>d.id)),o=e.filter(d=>!r.has(d.id));if(o.length===0)return[];let i=this.graph.snapshot(),s=[];if(!t.applied)for(let d of o)try{this.graph.applyPrimitives(d.primitives,{restoring:d.undoes!==void 0})}catch(f){throw this.graph.load(i),new cn(d,f)}let a=this.log.length;for(let[d,f]of o.entries()){let c=hn({...f,seq:a+d});this.log.append(c),s.push(c)}return this.notify(be(i,this.graph.snapshot(),o.flatMap(d=>d.primitives)),s),s}append(e,t={}){if(this.stillNow(),e.length===0)return[];let r=new Set(this.log.all().map(a=>a.id)),o,i=e.map((a,d)=>{let f=a.primitives.map(qn),c={id:a.id??this.nextId(),seq:this.log.length+d,batch:a.batch??t.batch??(o??=this.mintBatch("batch")),author:a.author,intent:a.intent,...Z("batchIntent",a.batchIntent),mutation:a.mutation??null,primitives:f,reads:a.reads??[],writes:a.writes??[...new Set(f.flatMap($e))],at:a.at??this.now(),...Z("undoes",a.undoes),...Z("via",a.via),...Z("lineage",Gn(a.lineage))};if(r.has(c.id))throw new N(`Op "${c.id}" (${c.intent}) is already in the log`,"A host-made op needs an id of its own; leave `id` out and the store mints one.");return r.add(c.id),c}),s=this.graph.snapshot();for(let a of i)try{this.graph.applyPrimitives(a.primitives,{restoring:a.undoes!==void 0})}catch(d){throw this.graph.load(s),new cn(a,d)}for(let a of i)this.log.append(a);for(let a of i)_t(a.author.id);return this.notify(be(s,this.graph.snapshot(),i.flatMap(a=>a.primitives)),i),i}applyPrimitives(e,t={}){this.stillNow();let r=t.batch??this.mintBatch("batch"),o=t.author??this.by,i=this.violations(),s=this.graph.snapshot(),a=t.intent??"Apply a change",d=Gn(t.lineage),f=e.map(qn),c=[];if(f.length>0){let l={id:this.nextId(),seq:this.log.length,batch:r,author:o,intent:a,mutation:null,primitives:f,reads:[],writes:[...new Set(f.flatMap($e))],at:this.now(),...Z("via",t.via),...Z("lineage",d)};this.graph.applyPrimitives(l.primitives),this.log.append(l),c.push(l),_t(o.id)}let p=this.violations(),u=be(s,this.graph.snapshot(),f);return this.notify(u,c),{batch:r,ops:c,diff:u,primitives:f,reads:[],writes:c[0]?.writes??[],intent:a,...this.moved(i,p),violationsAfter:p}}findings(){return Ka({schema:this.schema,invariants:this.allInvariants()},this.graph.snapshot(),{invariantOptions:this.invariantOptions})}batches(){return this.log.batches()}canUndo(e){return Tn(this.log,typeof e=="string"?[e]:e)}previewUndo(e,t){let r=this.canUndo(e);if(!r.ok)return{ok:!1,check:r};let o=Bs(r.ops),i=new Set;for(let s of r.ops)for(let a of s.writes)i.add(a);return{ok:!0,check:r,...this.previewPrimitives(o,{reads:[...new Set(r.ops.flatMap(s=>[...s.reads]))],writes:[...i],intent:`Undo: ${r.ops.map(s=>s.intent).join("; ")}`,restoring:r.ops.every(Ha),...t===void 0?{}:{context:t}})}}undo(e,t={}){return this.undoing(e,t)}undoing(e,t){this.stillNow();let r=typeof e=="string"?[e]:e,o=t.author??this.by,i=(this.policy?.sees?.length??0)>0&&!q(o);if(i){let h=Tn(Lr(en(this.log.all(),Zr(this,o)),()=>this.log.epochs()),r);if(!h.ok)throw new Pe(h)}let s=this.canUndo(r);if(!s.ok)throw new Pe(i?{ok:!1,ops:[],blockedBy:[],includeBatches:[],message:"Cannot undo on its own \u2014 a later change you cannot see depends on it, which only somebody who can see it can take back."}:s);let a=t.batch??this.mintBatch("undo"),d=Gn(t.lineage);if(this.policy)for(let h of s.ops){if(!h.mutation)continue;let v=T(h.author).id,y=A=>JSON.stringify(A).includes(JSON.stringify(v)),S=v!==void 0&&v!==T(o).id&&!q(o)&&!y(h.mutation.args)&&y(h.primitives)?{ok:!1,refusal:{mutation:h.mutation.name,wouldNeed:[],message:"it was done as somebody else."}}:this.permits(h.mutation,o);S.ok||this.refuse({...S.refusal,message:`Not permitted to undo "${h.intent}": ${S.refusal.message}`},o.id,!0)}let f=this.graph.snapshot(),c=this.violations(),p=[],u=this.log.length;for(let h of[...s.ops].sort((v,y)=>y.seq-v.seq)){let v={id:this.nextId(),seq:this.log.length,batch:a,author:o,intent:`Undo: ${h.intent}`,...Z("batchIntent",t.intent),mutation:null,primitives:Re(h),reads:h.reads,writes:h.writes,at:this.now(),undoes:h.id,...Z("via",t.via),...Z("lineage",d),...Z("undoneLineage",h.lineage)};this.graph.applyPrimitives(v.primitives,{restoring:Ha(h)}),this.log.append(v),p.push(v)}let l=be(f,this.graph.snapshot(),p.flatMap(h=>[...h.primitives]));this.admitted(t,p,p.flatMap(h=>[...h.primitives]),l,f,u);let g=this.violations();return this.notify(l,p),{batch:a,ops:p,diff:l,primitives:p.flatMap(h=>[...h.primitives]),reads:[...new Set(p.flatMap(h=>[...h.reads]))],writes:[...new Set(p.flatMap(h=>[...h.writes]))],intent:t.intent??p.map(h=>h.intent).join("; "),...this.moved(c,g),violationsAfter:g}}authorName(e){return zn(e,{graph:this.graph,schema:this.schema})}refuseDeclined(e,t){let r=Xs(this.log.all(),e);r&&this.refuse({mutation:e[0].name,message:`${this.authorName(t)} may not make this again: a person declined it on ${r.at.slice(0,10)}.`,wouldNeed:[]},t.id)}putBack(e,t){this.graph.load(e),this.log.length>t&&this.log.truncate(t)}admitted(e,t,r,o,i,s){if(!e.admit||t.length===0)return;let a=this.graph.size;try{e.admit({ops:t,primitives:r,added:{nodes:o.addedNodes.length,edges:o.addedEdges.length},removed:{nodes:o.removedNodes.length,edges:o.removedEdges.length},changed:{nodes:o.changedNodes.length},nodesAfter:a.nodes,edgesAfter:a.edges})}catch(d){throw this.putBack(i,s),d}}redo(e,t={}){return this.undo(e,t)}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(e,t){if(!(this.quiet>0)&&!(t.length===0&&Os(e)))for(let r of this.listeners)r(e,t)}rebase(e){this.stillNow();let t=new Set([...e.pending,...e.drop??[]]),r=this.log.all(),o=r.findIndex(h=>t.has(h.batch)),i=r.slice(o<0?r.length:o),s=this.log.horizon+(o<0?r.length:o),a=i.find(h=>!t.has(h.batch));if(a)throw new N(`Cannot rebase: op "${a.id}" (${a.intent}) comes after a pending batch and is neither pending nor dropped`,"While anything is pending, land the server's ops through rebase, so the log stays confirmed ops then pending ones.");let d=this.log.lastEpoch();if(d&&d.seq>s)throw new N(`Cannot rebase across an epoch: one begins at seq ${d.seq}, after pending op "${i[0].id}"`);let f=this.graph.snapshot(),c=[],p=[],u=[];this.quiet++;try{for(let v of[...i].reverse())this.graph.applyPrimitives(Re(v),{restoring:!0,inPlace:!0});this.log.truncate(s);let h=new Set(this.log.all().map(v=>v.id));for(let v of e.confirmed){if(h.has(v.id))continue;try{this.graph.applyPrimitives(v.primitives,{restoring:v.undoes!==void 0})}catch(S){throw new cn(v,S)}let y=hn({...v,seq:this.log.length});this.log.append(y),h.add(v.id),c.push(y)}for(let v of e.pending){let y=i.filter(S=>S.batch===v);if(y.length!==0)try{p.push(...this.replay(v,y))}catch(S){u.push({batch:v,error:S})}}}catch(h){this.log.truncate(s);for(let v of i)this.log.append(v);throw this.graph.load(f),h}finally{this.quiet--}let l=Je(f,this.graph.snapshot()),g=[...c,...p];return this.notify(l,g),{diff:l,confirmed:c,pending:p,refused:u}}adopt(e){this.stillNow();let t=new Set(e.drop??[]),r=(e.pending??[]).filter(l=>!t.has(l)),o=this.log.all(),i=this.graph.snapshot(),s={ops:[...o],epochs:[...this.log.epochs()],horizon:this.log.horizon},a=new Set(o.map(l=>l.id)),d=new Map(r.map(l=>[l,o.filter(g=>g.batch===l)]));if(e.log.length>0)this.log.replace(e.log,e.epochs,Z("horizon",e.horizon));else{let l=e.horizon??0;this.log.replace([],e.epochs??[{seq:l,base:e.snapshot}],{horizon:l})}let f=[],c=[];this.quiet++;try{this.graph.load(e.snapshot),this.projected=void 0,this.countPastTheLog();for(let l of r){let g=d.get(l)??[];if(g.length!==0)try{f.push(...this.replay(l,g))}catch(h){c.push({batch:l,error:h})}}}catch(l){throw this.log.replace(s.ops,s.epochs,{horizon:s.horizon}),this.graph.load(i),this.projected=void 0,l}finally{this.quiet--}let p=this.log.all().filter(l=>!a.has(l.id)&&!f.includes(l)),u=Je(i,this.graph.snapshot());return this.notify(u,[...p,...f]),{diff:u,adopted:p,pending:f,refused:c}}replay(e,t){let r=t[0],o={author:r.author,batch:e,...Z("intent",r.batchIntent),...Z("via",r.via),...Z("lineage",r.lineage)};if(r.undoes!==void 0){let i=t.map(a=>this.log.get(a.undoes??"")),s=t.find((a,d)=>i[d]===void 0);if(s)throw new N(`What "${s.intent}" took back is no longer in the log`);return this.undoing([...new Set(i.map(a=>a.batch))],o).ops}return t.every(i=>i.mutation!==null)?this.applying(t.map(i=>i.mutation),o).ops:this.append(t.map(({seq:i,...s})=>s))}snapshot(){return this.graph.snapshot()}verify(){let e=this.log.lastEpoch();return ya(this.schema,this.log.opsFrom(e?.seq??0),this.graph.snapshot(),{validate:this.validate,...e?{base:e.base}:{}})}checkpoint(e={}){let t=this.log.all(),r;if(e.seq!==void 0)r=e.seq;else{let a=this.log.length-(e.keepOps??1e3),f=Date.parse(e.now??this.now())-(e.keepDays??90)*864e5,c=t.find(u=>Date.parse(u.at)>f),p=c?c.seq:this.log.length;r=Math.min(a,p)}for(r=Math.min(Math.max(r,this.log.horizon),this.log.length);r>this.log.horizon&&r<this.log.length&&t[r-this.log.horizon].batch===t[r-1-this.log.horizon].batch;)r--;if(r<=this.log.horizon)return;let o=this.verify();if(!o.ok)throw new N(`Cannot compact a store that does not verify: ${o.reason}`);let i=this.log.checkpointAt(this.schema,r,{validate:this.validate}),s=oa(this.log,r);return Object.keys(s).length>0?{...i,creators:s}:i}compact(e){return this.stillNow(),this.log.compact(e)}};var ml=n=>`lens:${n}`,yl={hidden:[],removed:[],may:{views:!1,lenses:!1}};function bl(n,e,t){return n.name!==void 0&&e.may.views?"view":n.declared&&e.may.lenses&&t.lens?"lens":null}var Qa=["full","summary","glyph"],so=(n,e)=>n.as===e.as&&(n.over??[n.kind]).includes(e.kind),vl=n=>n.filter((e,t)=>!n.slice(0,t).some(r=>so(r,e)));function fe(n){return n.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function Kn(n,e){return`/${fe(n.tryDefinition(e)?.plural??`${e}s`)}`}function xl(n,e,t){return`${Kn(n,e)}/${encodeURIComponent(t)}`}function wl(n,e){return`/places/${encodeURIComponent(n)}${e?`?of=${encodeURIComponent(e)}`:""}`}function ed(n,e){return e.some(t=>t.as===n.as&&!so(n,t))}function kl(n,e,t){return ed(n,e)?`${n.title} \xB7 ${(t.tryDefinition(n.kind)?.plural??`${n.kind}s`).toLowerCase()}`:n.title}var Ie=(n,e,t="")=>`${n}|${e.cardinality}|${e.fidelity}|${t}`;function io(n){switch(n){case"full":return["full","summary","glyph"];case"summary":return["summary","full","glyph"];case"glyph":return["glyph","summary","full"]}}function Sl(n){let e=new Map,t=[],r=[],o,i,s={arrange(a){return a!==void 0&&(o=a),s},arrangement:()=>o,home(a){return a!==void 0&&(i=a),s},homeView:()=>i,register(a,d,f,c){let p={...c?.over?.[1]?{over:c.over}:{},...c?.hidden?{hidden:!0}:{},...c?.name?{name:c.name}:{},...c?.declared?{declared:!0}:{}},u={kind:a,cardinality:d.cardinality,fidelity:d.fidelity,view:f,...c?.title?{title:c.title}:{},...c?.across?{across:c.across}:{},...c?.beside?{beside:!0}:{},...p};if(r.push(u),!c?.beside&&!p.hidden&&e.set(Ie(a,d),u),c?.title){let l=fe(c.title);e.set(Ie(a,d,l),u),d.cardinality==="many"&&!t.some(g=>g.kind===a&&g.as===l)&&t.push({kind:a,title:c.title,as:l,...c.across?{across:c.across}:{},...p,...c.lens?{lens:c.lens}:{},...c.reads?.length?{reads:c.reads}:{}})}return s},places:()=>t,forget(a,d){for(let c of Qa)e.delete(Ie(a,{cardinality:"many",fidelity:c},d));let f=t.findIndex(c=>c.kind===a&&c.as===d);return f>=0&&t.splice(f,1),s},lookup(a,d){return e.get(Ie(a,d))?.view},resolve(a,d,f){if(f)for(let c of io(d.fidelity)){let p=e.get(Ie(a,{cardinality:d.cardinality,fidelity:c},f));if(p)return p}for(let c of io(d.fidelity)){let p=e.get(Ie(a,{cardinality:d.cardinality,fidelity:c}));if(p)return p}if(d.cardinality==="one")for(let c of io(d.fidelity)){let p=e.get(Ie(a,{cardinality:"many",fidelity:c}));if(p)return p}},registrations:()=>r,all(){return[...e.values()]},kindsWithViews(){return[...new Set([...e.values()].map(a=>a.kind))]}};return s}var $l=["day","week","month","year","decade"];function nd(n){let e={};n.q&&n.q.trim().length>0&&(e.query=n.q);let t=Sr(n.archived);if(t&&(e.archived=t),n.sort){let[r,o]=n.sort.split(":");r&&(e.sort={by:r,direction:o==="desc"?"desc":"asc"})}if(n.filter){let r=[];for(let o of n.filter.split(",")){let i=o.indexOf(":");i<=0||r.push({key:o.slice(0,i),value:o.slice(i+1)})}r.length>0&&(e.filter=r)}if(n.group){let[r,o]=n.group.split(":");r&&(e.group={by:r,...$l.includes(o)?{bucket:o}:{}})}return e}function ao(n){if(typeof n=="string"&&n.length>0)return{by:n,direction:"asc"};if(typeof n!="object"||n===null)return;let{by:e,direction:t}=n;if(!(typeof e!="string"||e.length===0))return{by:e,direction:t==="desc"?"desc":"asc"}}function Et(n,e,t){let r=ao(n);if(!r)return'an order is a field, like "released", or { "by": "released", "direction": "asc" | "desc" }';let o=typeof n=="object"&&n!==null?n.direction:void 0;if(o!==void 0&&o!=="asc"&&o!=="desc")return`an order runs "asc" or "desc", not "${String(o)}"`;if(r.by!=="label"&&!e.includes(r.by))return`${t} has no field "${r.by}" to order by (it has ${e.length>0?e.map(i=>`"${i}"`).join(", "):"none"}, and "label", its name)`}function Rl(n,e,t){let r=ao(e);if(!r)return n;let o=r.direction==="desc"?-1:1;return n.map((i,s)=>({item:i,at:s,value:t(i,r.by)})).sort((i,s)=>{let a=(i.value===void 0||i.value===null||i.value===""?1:0)-(s.value===void 0||s.value===null||s.value===""?1:0);if(a!==0)return a;if(i.value===s.value||i.value===void 0||i.value===null)return i.at-s.at;let d=typeof i.value=="number"&&typeof s.value=="number"?i.value-s.value:String(i.value).localeCompare(String(s.value),void 0,{numeric:!0});return d===0?i.at-s.at:d*o}).map(i=>i.item)}var Un={timeline:{binds:"fields",requiredRoles:["start","end"],options:["columns","extent","tick","minWindow","arranging"]},calendar:{binds:"fields",requiredRoles:["start"],options:["today","range","weekStartsOn","perCell","horizon","arranging","search","filters"]},coverage:{binds:"entities",requiredRoles:["rows","columns","link"],options:["rowRef","rowGroup","groupOrder","requiredGroups","requiredVia","badge","columnGroup","sort","columnSort","search","filters"]},board:{binds:"entities",requiredRoles:["slots","x","y","fill"],options:["fillFrom","slotCode","zones","aspect","emptyLabel","pickTarget","arranging","arrange"]},plan:{binds:"entities",requiredRoles:["regions","outline"],options:["hues","aspect","undrawnLabel","strayLabel","draw","place","help"]},reach:{binds:"nothing",requiredRoles:[],options:[]},blocks:{binds:"nothing",requiredRoles:[],options:["blocks"]},columns:{binds:"fields",requiredRoles:["column"],options:["sort","search","filters","move","collapsed","cap","hidden"]}},_l=20,rd=Object.keys(Un),Al=(n,e,t,r=Un[n].options)=>({message:`The ${n} lens takes no option "${e}", so "${t}" ignores it.`,fix:r.length?`Use one of: ${r.join(", ")}.`:`The ${n} lens takes no options; drop it.`}),od=n=>Object.hasOwn(Un,n);function co(n,e,t){let r=n[e],o=Array.isArray(r)?r.filter(i=>typeof i=="string"&&t(i)):[];o.length>0?n[e]=o:delete n[e]}var un=n=>typeof n=="object"&&n!==null&&!Array.isArray(n);function td(n,e,t){let r=n.tryDefinition(e)?.fields.shape,o=I(r?.[t]);for(;o&&(o.type==="optional"||o.type==="default"||o.type==="nullable"||o.type==="prefault");)o=I(o.innerType);return o?.type!=="enum"?[]:(o.entries?Object.values(o.entries):o.values??[]).filter(s=>typeof s=="string")}function Ol(n){let e=[],t=[],r=[],o=new Set(n.schema.kinds),i=new Set;for(let d of o)for(let f of Object.keys(n.schema.tryDefinition(d)?.edges??{}))i.add(f);let s=d=>Object.keys(n.schema.tryDefinition(d)?.fields.shape??{}),a=new Map;return(n.lenses??[]).forEach((d,f)=>{let c=`lenses.${f}`,p=typeof d.title=="string"&&d.title.trim().length>0?d.title.trim():void 0,u=(x,b)=>{t.push({index:f,name:d.name,...p?{title:p}:{},why:x}),b&&r.push({severity:"warning",...b})};if(!od(d.name)){p?u(`"${d.name}" is not a lens this framework draws`,{code:"lens-not-shipped",path:`${c}.name`,message:`"${p}" names the lens "${d.name}", which the framework does not ship, so nothing draws it.`,fix:`Name one of ${rd.join(", ")} \u2014 or register the view yourself and drop the title.`}):u("it is a lens this app wrote, drawn by the app's own views");return}if(!p)return u("it has no title, so it is bindings the checker holds and no place");let l=Un[d.name],g=un(d.options)?d.options:{};if(d.options!==void 0&&!un(d.options))return u("its options are not an object",{code:"lens-options-not-an-object",path:`${c}.options`,message:`"${p}" has options that are not an object.`,fix:'Write them as { "<option>": <value> }, or drop them.'});for(let x of Object.keys(g))l.options.includes(x)||r.push({severity:"warning",code:"lens-option-unknown",path:`${c}.options.${x}`,...Al(d.name,x,p,l.options)});let h={};for(let x of l.options)g[x]!==void 0&&(h[x]=g[x]);d.arrangedBy&&(h.arrangedBy=nd(d.arrangedBy));let v=un(d.bindings)?d.bindings:{},y=[],S,A=(x,b,$)=>u(b,{code:"lens-cannot-draw",path:x,message:`"${p}" cannot draw: ${b}.`,fix:$});if(l.binds==="fields"){let x=Object.keys(v).filter($=>un(v[$])),b=x.filter($=>!o.has($));if(x.length===0)return A(`${c}.bindings`,"it binds no kind",`Bind a kind's fields: "bindings": { "<kind>": { ${l.requiredRoles.map($=>`"${$}": "<field>"`).join(", ")} } }.`);if(b.length>0)return;if(h.bindings=v,y=x,d.name==="timeline"){let $=g.columns;if(Array.isArray($))h.columns=$.map(R=>typeof R=="string"?{id:R,label:R}:R);else{let R=x.flatMap(P=>{let E=v[P],L=typeof E.column=="string"?E.column:typeof E.columns=="string"?E.columns:void 0;return L?td(n.schema,P,L):[]}),_=[...new Set(R)];if(_.length===0)return A(`${c}.options.columns`,"it has no columns \u2014 no option names them and no `column` role is bound to a field of set values",'Bind "column" to a field whose values are the columns, or say "columns": ["mon", "tue", \u2026].');h.columns=_.map(P=>({id:P,label:P.toUpperCase()}))}h.extent===void 0&&(h.extent=1440)}if(d.name==="columns"){if(h.sort!==void 0){let R=x.map(_=>Et(h.sort,s(_),_)).find(Boolean);R&&(r.push({severity:"warning",code:"lens-sort",path:`${c}.options.sort`,message:`"${p}" cannot order its cards: ${R}.`,fix:'Write { "by": "<a field>", "direction": "asc" }, or drop it.'}),delete h.sort)}let $=new Set;for(let R of x){let _=v[R].column;if(typeof _!="string"||!s(R).includes(_))return;let P=td(n.schema,R,_);if(P.length===0)return A(`${c}.bindings.${R}.column`,`its column field "${_}" is not a choice`,`Bind "column" to a choice field of ${R}, like a status.`);for(let E of P)$.add(E)}typeof h.move!="boolean"&&delete h.move,Number.isInteger(h.cap)&&h.cap>=1&&h.cap<=500||delete h.cap;for(let R of["collapsed","hidden"])co(h,R,_=>$.has(_))}if(d.name==="calendar"&&h.today!==void 0&&!(typeof h.today=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(h.today)))return A(`${c}.options.today`,"its today is not a date",'Write it as "YYYY-MM-DD", or leave it out and the calendar opens on the day it is drawn.');if(d.name==="calendar"&&h.horizon!==void 0){let $=h.horizon,R=E=>E===void 0||Number.isInteger(E)&&E>=1&&E<=9999,_=typeof $=="number"?{years:$,title:"Years"}:$;un(_)&&Number.isInteger(_.years)&&_.years>=1&&_.years<=200&&typeof _.title=="string"&&_.title.trim().length>0&&R(_.from)&&R(_.to)&&Object.keys(_).every(E=>["years","title","from","to"].includes(E))&&!(typeof _.from=="number"&&typeof _.to=="number"&&_.to<_.from)?h.horizon=_:(delete h.horizon,r.push({severity:"warning",code:"lens-horizon",path:`${c}.options.horizon`,message:`"${p}" has a horizon that is not a span of years, so it offers no span of years.`,fix:'Write { "years": 30, "title": "The career" } \u2014 "from" and "to" (years, like 1962 and 2023) only to pin its ends, which otherwise reach the first and last of its records.'}))}if(d.name==="calendar"&&h.range!==void 0&&!["day","week","month","quarter","year","years","agenda"].includes(h.range))return A(`${c}.options.range`,`its range "${String(h.range)}" is not one a calendar opens at`,"Use one of: day, week, month, quarter, year, agenda.")}else if(l.binds==="entities"){let x=R=>{let _=v[R];if(un(_)){if(typeof _.kind=="string")return _.kind;if(typeof _.edge=="string")return _.edge;if(Array.isArray(_.path))return{path:_.path};if(typeof _.field=="string")return _.field}};for(let R of l.requiredRoles)if(x(R)===void 0)return;let b=d.name==="coverage"?"rows":d.name==="board"?"slots":"regions",$=x(b);if(!o.has($))return;if(d.name==="coverage"){let R=x("columns");if(!o.has(R))return;let _=x("link");if(typeof _=="string"&&!i.has(_))return;Object.assign(h,{rows:$,columns:R,link:_}),R!==$&&(S=R);for(let[P,E]of[["sort",$],["columnSort",R]]){if(h[P]===void 0)continue;let L=Et(h[P],s(E),E);L&&(r.push({severity:"warning",code:"lens-sort",path:`${c}.options.${P}`,message:`"${p}" cannot order its ${P==="sort"?"rows":"columns"}: ${L}.`,fix:`Write { "by": "<a field of ${E}>", "direction": "asc" }, or drop it.`}),delete h[P])}}else if(d.name==="board"){Object.assign(h,{slots:$,x:x("x"),y:x("y"),fill:x("fill")});for(let R of["x","y"])if(!s($).includes(h[R]))return}else{Object.assign(h,{regions:$,outline:x("outline")});for(let R of["markers","at","within","nests","regionKind","markerKind"]){let _=x(R);typeof _=="string"&&(h[R]=_)}}y=[$]}else if(d.name==="blocks"){if(!d.on)return A(`${c}.on`,"it does not say which kind it stands on",'Say "on": "<the kind it is a place of>".');if(!Array.isArray(h.blocks)||h.blocks.length===0)return A(`${c}.options.blocks`,"it has no blocks to draw",`Say "options": { "blocks": [{ "headline": "\u2026" }, { "list": "all('<kind>')", "as": "card" }] }.`)}else{let x=["user","person","member"].find(b=>o.has(b));if(!d.on&&!x)return A(`${c}.on`,"it does not say which kind it stands on",'Say "on": "<the kind whose records are the people>".');y=x?[x]:[]}if(d.on!==void 0){if(typeof d.on!="string"||!o.has(d.on))return A(`${c}.on`,`it stands on "${String(d.on)}", which is not a kind`,`Use one of: ${[...o].join(", ")}.`);if(y=[d.on],d.name==="coverage"){let x=[h.rows,h.columns].find(b=>b!==d.on);S=typeof x=="string"?x:void 0}}let m=typeof h.rows=="string"?h.rows:y[0];if(m!==void 0){let x=["label",...s(m)],b=new Set(["is",...x,...Object.keys(n.schema.tryDefinition(m)?.edges??{})]);co(h,"search",$=>x.includes($)),co(h,"filters",$=>b.has($.split(".")[0]))}let k=fe(p);if(k.length===0)return A(`${c}.title`,"its title has no letters or digits to make an address of","Give it a title a person would say.");for(let x of y){let b=`${x}|${k}`;if(a.has(b))return u(`another lens on ${x} is already called "${p}"`,{code:"lens-title-taken",path:`${c}.title`,message:`"${p}" is the title of lenses.${a.get(b)} too, on the same kind, so one address would name two pictures.`,fix:"Give each its own title."})}for(let x of y)a.set(`${x}|${k}`,f);let w=d.create;w!==void 0&&typeof w!="boolean"&&r.push({severity:"warning",code:"lens-create",path:`${c}.create`,message:`"${p}" says create ${JSON.stringify(w)}, which is neither true nor false, so its page keeps the forms that begin its kind.`,fix:'Say "create": false to leave them off, or drop it.'}),e.push({index:f,lens:d.name,title:p,as:k,kinds:y,...S?{across:S}:{},options:h,...d.hidden===!0?{hidden:!0}:{},...w===!1?{create:!1}:{}})}),{drawn:e,undrawn:t,findings:r}}var El=6;function Pl(n,e,t=[]){let r=n.kinds,o=s=>Object.values(n.tryDefinition(s)?.edges??{}).map(a=>(a.to==="*"?r:a.to).filter(d=>d!==s)),i=new Set(r.flatMap(s=>o(s).flat()));return new Set([...e?.hide??[],...t,...r.filter(s=>!i.has(s)&&o(s).length>0&&o(s).every(a=>a.length>=2))])}function zl(n,e,t){if(!n?.primary)return;let r=new Set(n.primary.map(fe));return{kinds:new Set(e.kinds.filter(o=>r.has(fe(o))||r.has(Kn(e,o).slice(1)))),places:new Set(t.filter(o=>r.has(o.as)||r.has(fe(o.title))).map(o=>`${o.kind}|${o.as}`))}}var id="overview",Ml=`/places/${id}`;function Nl(n){let e=n?.scene?.trim();return e||"Scene"}function Il(n){let e=n?.pages?.trim();return e||"Pages"}function jl(n,e){if(!e||e.length===0)return n;let t=e.filter(r=>n.includes(r));return[...new Set(t),...n.filter(r=>!t.includes(r))]}function Tl(n,e,t){if(n===void 0)return;let r=n.trim();if(r==="")return;if(r.toLowerCase()==="home"||r==="/")return{to:"home"};let o=fe(r),i=t.find(d=>d.title===r)??t.find(d=>d.as===o);if(i)return{to:"place",place:i};let s=e.kinds,a=s.find(d=>d===r)??s.find(d=>Kn(e,d).slice(1)===o);return a?{to:"kind",kind:a}:void 0}function uo(n){let e=(n??"").replace(/\/+$/,"");return e===""?"":e.startsWith("/")?e:`/${e}`}function Dl(n,e={}){let t=typeof n=="string"?n:n.address,r=uo(e.basePath),o=t.startsWith("/")?t:`/${t}`;return r===""?o:o==="/"?r:o.startsWith("/?")||o.startsWith("/#")?`${r}${o.slice(1)}`:`${r}${o}`}function Fl(n,e){let t=uo(e);if(t==="")return n.startsWith("/")?n:`/${n}`;if(!n.toLowerCase().startsWith(t.toLowerCase()))return null;let r=n.slice(t.length);return r===""||r==="/"?"/":r.startsWith("/")?r:null}var sd=Symbol.for("@graview/core:app-link"),Zl=n=>(Object.defineProperty(I(n),sd,{value:1,enumerable:!0}),n);function ad(n){let e=I(n);return!!e&&(e[sd]===1||ad(e.innerType))}var Fx=()=>Zl(D().check(gr(500),Rn(dt,"another app's address")));var Pt=(n,e)=>`${e.kind}\0${e.id??""}\0${n.address}\0${n.kind}\0${n.id}`;function Ll(n,e,t=()=>{}){let r=new Map,o=new Map,i=s=>{let a=Pt(s,e),d=r.get(a);return d||(d=Promise.resolve().then(()=>n.resolve(s,e)).then(f=>Cl(f)?f:null,()=>null).then(f=>(r.get(a)===d&&(o.set(a,f),t(s)),f)),r.set(a,d)),d};return{read(s){let a=Pt(s,e);if(o.has(a)){let d=o.get(a);return d===null?{unread:!0}:"denied"in d?{denied:!0}:{record:d}}return i(s),{unread:!0}},ask:i,answered:s=>o.get(Pt(s,e)),forget(s){if(!s){r.clear(),o.clear();return}let a=Pt(s,e);r.delete(a),o.delete(a)}}}function Cl(n){if(n===null)return!0;if(typeof n!="object"||n===void 0)return!1;if(n.denied===!0)return!0;let e=n;return typeof e.label=="string"&&typeof e.id=="string"&&typeof e.kind=="string"&&typeof e.fields=="object"&&e.fields!==null}var Gl={snapshot:1,op:2};var Bl=1;var zt=(n,e)=>`${n}\0${e}`;function fo(n){return n.op==="add-node"?Object.keys(n.node).filter(e=>e!=="id"&&e!=="kind").map(e=>[n.node.id,e]):n.op==="patch-node"?Object.keys(n.after).map(e=>[n.id,e]):[]}var lo=class n{revs=new Map;floor;constructor(e=0){this.floor=Math.max(0,Math.floor(e))-1}static of(e,t={}){let r=new n(t.horizon);return r.note(e),r}note(e){for(let t of e)for(let r of t.primitives)for(let[o,i]of fo(r)){let s=zt(o,i);(this.revs.get(s)??this.floor)<t.seq&&this.revs.set(s,t.seq)}}of(e,t){return this.revs.get(zt(e,t))??this.floor}baseFor(e,t=new Set){let r=new Set,o=new Map;for(let i of e)for(let s of i.primitives)if(s.op==="add-node"&&r.add(s.node.id),!(s.op!=="patch-node"||r.has(s.id)||t.has(s.id)))for(let a of Object.keys(s.after)){let d=zt(s.id,a);t.has(d)||o.has(d)||o.set(d,{node:s.id,field:a,rev:this.of(s.id,a)})}return[...o.values()]}stale(e){return e.filter(t=>this.of(t.node,t.field)>t.rev)}};function Kl(n){let e=new Set;for(let t of n)for(let r of t.primitives){r.op==="add-node"&&e.add(r.node.id);for(let[o,i]of fo(r))e.add(zt(o,i))}return e}var Ul=/^#([0-9a-f]{3,8})$/i,Vl=/(rgba?|hsla?)\(([^)]+)\)/gi;function Wl(n){let e=Ul.exec(n.trim());if(!e)return null;let t=e[1];if((t.length===3||t.length===4)&&(t=[...t].map(i=>i+i).join("")),t.length!==6&&t.length!==8)return null;let r=Number.parseInt(t.slice(0,6),16),o=t.length===8?Number.parseInt(t.slice(6,8),16)/255:1;return{r:r>>16&255,g:r>>8&255,b:r&255,a:o}}function ql(n){let e=n.slice(0,n.indexOf("(")).toLowerCase(),r=n.slice(n.indexOf("(")+1,n.lastIndexOf(")")).split(/[,\s/]+/).filter(Boolean).map(d=>d.endsWith("%")?Number.parseFloat(d)/100:Number.parseFloat(d));if(r.some(Number.isNaN))return null;if(e.startsWith("rgb")){let[d,f,c,p]=r;return d===void 0||f===void 0||c===void 0?null:{r:d,g:f,b:c,a:p??1}}let[o,i,s,a]=r;return o===void 0||i===void 0||s===void 0?null:{...cd(o,i>1?i/100:i,s>1?s/100:s),a:a??1}}function ho(n){let e=n.r/255,t=n.g/255,r=n.b/255,o=Math.max(e,t,r),i=Math.min(e,t,r),s=(o+i)/2;if(o===i)return{h:0,s:0,l:s};let a=o-i,d=a/(1-Math.abs(2*s-1));return{h:((o===e?60*((t-r)/a%6):o===t?60*((r-e)/a+2):60*((e-t)/a+4))+360)%360,s:d,l:s}}function go(n,e,t){return{...cd(n,e,t),a:1}}function cd(n,e,t){let r=(1-Math.abs(2*t-1))*e,o=(n%360+360)%360/60,i=r*(1-Math.abs(o%2-1)),[s,a,d]=o<1?[r,i,0]:o<2?[i,r,0]:o<3?[0,r,i]:o<4?[0,i,r]:o<5?[i,0,r]:[r,0,i],f=t-r/2;return{r:Math.round((s+f)*255),g:Math.round((a+f)*255),b:Math.round((d+f)*255)}}function ln(n){let e=[];for(let t of n.matchAll(Vl)){let r=ql(t[0]);r&&e.push(r)}for(let t of n.matchAll(/#[0-9a-fA-F]{3,8}\b/g)){let r=Wl(t[0]);r&&e.push(r)}return e}function mo(n,e){let t=n.a+e.a*(1-n.a);if(t===0)return{r:0,g:0,b:0,a:0};let r=(o,i)=>(o*n.a+i*e.a*(1-n.a))/t;return{r:r(n.r,e.r),g:r(n.g,e.g),b:r(n.b,e.b),a:t}}function po(n){let e=n/255;return e<=.03928?e/12.92:((e+.055)/1.055)**2.4}function dd(n){return .2126*po(n.r)+.7152*po(n.g)+.0722*po(n.b)}function fn(n,e){let[t,r]=[dd(n),dd(e)].sort((o,i)=>i-o);return(t+.05)/(r+.05)}var Mt=(n,e)=>`rgba(${Math.round(n.r)}, ${Math.round(n.g)}, ${Math.round(n.b)}, ${e})`,ud={r:0,g:0,b:0,a:1},Nt={r:255,g:255,b:255,a:1};function It(n){let e=ln(n.accent)[0];if(!e)return{ok:!1,missing:["accent"],why:`"${n.accent}" is not a color this can read. Use a hex, rgb() or hsl() value.`};let t={},r=new Set,o=[],i=ho(e);for(let s of["dark","light"]){let a=n.base[s],d=ln(a.ground)[0]??(s==="dark"?ud:Nt),f=mo(ln(a.panel)[0]??Nt,d),c=Xl(i,[f,d],s,4.5);c?Math.abs(c.l-i.l)>Jl&&(r.add(`accent (${s})`),o.push(`reaching 4.5:1 on the ${s} panel would move the accent's lightness by ${Math.round(Math.abs(c.l-i.l)*100)} points, which is far enough that it stops being the same color \u2014 supply one for ${s}`)):(r.add(`accent (${s})`),o.push(`no lightness of this hue clears 4.5:1 as text on the ${s} panel, so ${s} needs an accent of its own`));let p=c??i,u=go(p.h,p.s,p.l),l=n.accentInk?.[s]??(fn(Nt,u)>=fn(ud,u)?"#ffffff":"#000000"),g=fn(ln(l)[0]??Nt,u);g+.005<4.5&&(r.add(`accentInk (${s})`),o.push(`neither black nor white clears 4.5:1 on the accent (best ${g.toFixed(2)}:1), so text on a filled button has to be given`)),t[s]={...a,accent:Mt(u,1),accentDim:Mt(u,s==="dark"?.35:.22),accentInk:l,glow:Mt(u,s==="dark"?.28:.1),edgeBright:Mt(u,Hl(u,f,s==="dark"?.55:.42,3)),...n.warn?.[s]?{warn:n.warn[s]}:{}};let h=ln(t[s].warn)[0];h&&Yl(ho(h).h,p.h)<25&&(r.add(`warn (${s})`),o.push(`the warning color shares the accent's hue in ${s}, so "something is broken" looks like "this is selected"`))}return r.size>0?{ok:!1,missing:[...r].sort(),why:o.join("; ")}:{ok:!0,schemes:t}}function Hl(n,e,t,r){for(let o=Math.round(t*100);o<=100;o++){let i=o/100;if(fn(mo({...n,a:i},e),e)>=r)return i}return 1}function Yl(n,e){let t=Math.abs(n-e)%360;return t>180?360-t:t}var Jl=.3;function Xl(n,e,t,r){let o=t==="dark";for(let i=0;i<=100;i++){let s=o?n.l+i/100:n.l-i/100,a=o?n.l-i/100:n.l+i/100;for(let d of[s,a])if(!(d<0||d>1)&&e.every(f=>fn(go(n.h,n.s,d),f)>=r))return{...n,l:d}}return null}function Ql(n,e){let t=e?.[n];if(t!==void 0)return(t%360+360)%360;let r=2166136261;for(let o=0;o<n.length;o++)r^=n.charCodeAt(o),r=Math.imul(r,16777619);return(r>>>0)%360}var je=Object.freeze({navy:"#001769",turquoise:"#00e5b9",paper:"#f7f7f2",ink:"#18213a",muted:"#586174"}),yo="Montserrat",bo=Object.freeze({display:550,body:450,label:600}),vo=Object.freeze({display:600,body:400,label:600}),ef="-0.025em",nf=Object.freeze({minWidth:140,clearSpace:.5,microMax:24,regularMin:32,microBelow:28});var ld={ground:"#0a0f1f",groundDeep:"#060914",wash:"none",panel:"rgba(19, 27, 52, 0.96)",panelMuted:"rgba(14, 21, 42, 0.94)",panelWarning:"rgba(48, 33, 18, 0.95)",edge:"rgba(164, 178, 222, 0.18)",edgeBright:"rgba(154, 171, 255, 0.6)",ink:"#eef0f6",inkMuted:"#aab2c6",inkFaint:"#97a0b6",accent:"#9aabff",accentDim:"rgba(154, 171, 255, 0.32)",accentInk:je.navy,warn:"#f0a868",good:"#8fdcaa",bad:"#ffa3a3",glow:"rgba(154, 171, 255, 0.18)",bar:"rgba(10, 15, 31, 0.96)",float:"rgba(16, 23, 45, 0.98)",liftLow:"0 14px 36px -22px #000",liftHigh:"0 28px 64px -30px #000",tintAlpha:.2,tintLightness:52,gridAlpha:.35},fd={ground:je.paper,groundDeep:"#efefe8",wash:"none",panel:"#ffffff",panelMuted:"#fafaf6",panelWarning:"#fdf4ea",edge:"rgba(24, 33, 58, 0.12)",edgeBright:"rgba(0, 23, 105, 0.6)",ink:je.ink,inkMuted:je.muted,inkFaint:"#626b7d",accent:je.navy,accentDim:"rgba(0, 23, 105, 0.16)",accentInk:"#ffffff",warn:"#9a5312",good:"#1b6436",bad:"#a1232d",glow:"rgba(0, 23, 105, 0.08)",bar:"rgba(255, 255, 255, 0.96)",float:"#ffffff",liftLow:"0 1px 2px rgba(24,33,58,0.06), 0 8px 24px -12px rgba(24,33,58,0.16)",liftHigh:"0 2px 6px rgba(24,33,58,0.08), 0 24px 56px -24px rgba(24,33,58,0.26)",tintAlpha:.16,tintLightness:46,gridAlpha:.5},pn={dark:ld,light:fd};var Se=Object.freeze({radius:8,density:1,radiusSmall:.72,radiusSmallFloor:2,pad:15,padSmall:10,gap:7}),Te=Object.freeze({body:`"${yo}", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif`,mono:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace'});function tf(n){let e=n?.shape?.radius??Se.radius,t=n?.shape?.density??Se.density;return Object.freeze({radius:e,radiusSmall:Math.max(Se.radiusSmallFloor,Math.round(e*Se.radiusSmall)),pad:Math.round(Se.pad*t),padSmall:Math.round(Se.padSmall*t),gap:Math.round(Se.gap*t)})}function rf(n){let e=n?.typography?.body??Te.body,t=n?.typography?.display??e,o=e===Te.body&&t===Te.body?bo:vo,i=n?.typography?.weights;return Object.freeze({body:e,display:t,mono:n?.typography?.mono??Te.mono,weights:Object.freeze({display:i?.display??o.display,body:i?.body??o.body,label:i?.label??o.label})})}var Qx=Object.freeze({light:Object.freeze({roof:Object.freeze({saturation:48,lightness:82}),right:Object.freeze({saturation:40,lightness:66}),left:Object.freeze({saturation:34,lightness:55}),roofEdge:"rgba(255,255,255,0.75)",plot:Object.freeze({saturation:45,lightness:58,alpha:.12}),plotEdge:Object.freeze({saturation:40,lightness:48,alpha:.55})}),dark:Object.freeze({roof:Object.freeze({saturation:42,lightness:32}),right:Object.freeze({saturation:40,lightness:21}),left:Object.freeze({saturation:38,lightness:13}),roofEdge:"rgba(255,255,255,0.14)",plot:Object.freeze({saturation:45,lightness:48,alpha:.2}),plotEdge:Object.freeze({saturation:40,lightness:62,alpha:.55})})});function hd(n){return/^\s*(<\?xml[^>]*>\s*)?(<!--[\s\S]*?-->\s*)*(<!DOCTYPE svg[^>]*>\s*)?<svg[\s>/]/i.test(n)}var gd="http://www.w3.org/2000/svg",of=["http://www.w3.org/1999/xhtml","http://www.w3.org/1998/Math/MathML",gd],sf=new Set("svg g defs symbol use title desc path rect circle ellipse line polyline polygon text tspan textPath linearGradient radialGradient stop pattern clipPath mask marker image filter feBlend feColorMatrix feComponentTransfer feComposite feDropShadow feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feMerge feMergeNode feMorphology feOffset feTile feTurbulence".split(" ")),af=new Set(["title","desc"]),Vn="it embeds a page or media",df={script:"it has a script in it",foreignobject:"it embeds HTML (foreignObject)",iframe:Vn,embed:Vn,object:Vn,audio:Vn,video:Vn,style:"it has a style sheet in it; a mark is styled by its attributes",a:"it links to something (an <a> element)"},cf={amp:"&",lt:"<",gt:">",quot:'"',apos:"'"};function uf(n){let e=!1,t=n.replace(/&(#x[0-9a-f]+|#[0-9]+|[a-z][a-z0-9]*);?/gi,(r,o)=>{if(o[0]==="#"){let s=o[1]==="x"||o[1]==="X"?parseInt(o.slice(2),16):parseInt(o.slice(1),10);return s>0&&s<=1114111?String.fromCodePoint(s):"\uFFFD"}let i=cf[o.toLowerCase()];return i===void 0&&(e=!0),i??""});return e?null:t}function lf(n){if(/\\|@|expression\s*\(|(?:image-set|cross-fade|image|element|src)\s*\(/i.test(n))return!1;for(let[,e]of n.matchAll(/url\s*\(\s*["']?\s*([^)]*)/gi))if(!e.startsWith("#"))return!1;return!0}function ff(n,e,t){let r=uf(t);if(r===null)return"it declares XML entities";let o=(e.includes(":")?e.slice(e.indexOf(":")+1):e).toLowerCase();if(o.startsWith("on"))return"it has an event handler (an on\u2026 attribute)";if(e==="xml:base")return"it loads or links to something outside itself";if(e==="xmlns")return r===gd?null:"it changes what its elements are (another xmlns)";if(e.startsWith("xmlns:"))return of.includes(r)?"it changes what its elements are (another xmlns)":null;if(o==="href"||o==="src"){let i=r.replace(/[\u0000- ]+/g,"");return i.startsWith("#")||n==="image"&&/^data:image\/(png|jpe?g|gif|webp|avif);/i.test(i)?null:"it loads or links to something outside itself"}return lf(r)?null:o==="style"?"its style loads something outside itself":"it loads or links to something outside itself"}var pd=/^\s+([A-Za-z_][A-Za-z0-9_.:-]*)\s*=\s*(?:"([^"<]*)"|'([^'<]*)')/;function md(n){if(/<!ENTITY/i.test(n))return"it declares XML entities";if(/<!\[CDATA\[/i.test(n))return"it has a CDATA section, which the page and the picture read differently";let e=[],t=!1,r=/^\s*(<\?xml\s[^?<>]*\?>)?/.exec(n)[0].length;for(;r<n.length;){let o=n.slice(r),i=/^[^<]+/.exec(o);if(i){if(e.length===0&&i[0].trim()!=="")return"it is not one SVG: there is text outside it";r+=i[0].length;continue}if(o.startsWith("<!--")){let l=o.indexOf("-->",4);if(l<0)return"it has a comment that never ends";let g=o.slice(4,l);if(/^-?>/.test(g)||g.includes("--")||g.includes("<!")||g.endsWith("-"))return"it has a comment the page and the picture read differently";r+=l+3;continue}if(/^<!DOCTYPE/i.test(o)){let l=/^<!DOCTYPE\s+svg\b[^<>[\]]*>/i.exec(o);if(!l||e.length>0||t)return"it declares XML entities";r+=l[0].length;continue}let s=/^<\/([A-Za-z][A-Za-z0-9_.:-]*)\s*>/.exec(o);if(s){if(e.pop()!==s[1])return`it is not one SVG: </${s[1]}> closes what is not open`;e.length===0&&(t=!0),r+=s[0].length;continue}let a=/^<([A-Za-z][A-Za-z0-9_.:-]*)/.exec(o);if(!a)return"it is not one SVG: it has markup a picture cannot hold";let d=a[1],f=df[d.toLowerCase()];if(f)return f;if(t)return`it is not one SVG: <${d}> comes after it ends`;if(e.length===0&&d!=="svg")return"it is not one SVG";if(d.includes(":"))return`it has an element of another kind (<${d}>)`;if(!sf.has(d))return`it has a <${d}> element, which a picture does not need`;let c=e[e.length-1];if(c&&af.has(c))return`it has an element inside a <${c}>, which the page reads as HTML`;let p=a[0].length;for(let l=pd.exec(o.slice(p));l;l=pd.exec(o.slice(p))){let g=ff(d,l[1],l[2]??l[3]??"");if(g)return g;p+=l[0].length}let u=/^\s*(\/?)>/.exec(o.slice(p));if(!u)return/(?:^|[\s/"'])on[a-z]+\s*=/i.test(o.slice(p,p+400))?"it has an event handler (an on\u2026 attribute)":`it is not one SVG: <${d}>'s attributes are not each quoted and apart`;u[1]!=="/"?e.push(d):e.length===0&&(t=!0),r+=p+u[0].length}return e.length>0?`it is not one SVG: <${e[e.length-1]}> is never closed`:t?null:"it is not one SVG"}function yd(n){if(n){if(!hd(n)){if(/^\s*</.test(n))return;let e=/^\s*([a-z][a-z0-9+.-]*):/i.exec(n)?.[1]?.toLowerCase();return e===void 0||e==="http"||e==="https"||e==="data"&&/^\s*data:image\//i.test(n)?n:void 0}return md(n)===null?`data:image/svg+xml,${encodeURIComponent(n.trim())}`:void 0}}var jt;function pf(){if(jt===void 0)try{jt=new RegExp("^\\p{RGI_Emoji}$","v")}catch{jt=null}return jt}function hf(n){return/\p{Extended_Pictographic}|\p{Regional_Indicator}|⃣/u.test(n)}function xo(n){if(typeof n!="string"||n.trim()==="")return"it is empty; give one emoji, like \u{1F3E1}";let e=[...new Intl.Segmenter("en",{granularity:"grapheme"}).segment(n)].map(o=>o.segment),t=e.filter(hf).length;if(t===0)return"it is not an emoji; give one emoji, like \u{1F3E1}";if(e.length>1)return t===e.length?`it is ${e.length} emoji, and a mark is one`:"it has other characters beside the emoji; give the emoji alone";let r=pf();return r&&!r.test(n)?"it is not one of the standard emoji every emoji set draws":null}function wo(n){return typeof n=="object"&&n!==null&&typeof n.emoji=="string"?n.emoji:void 0}function bd(n){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text x="50" y="50" dy=".35em" font-size="88" text-anchor="middle">${n}</text></svg>`}function gf(n){let e=n?.favicon;if(typeof e=="object"&&e!==null){let t=wo(e);return t!==void 0&&xo(t)===null?`data:image/svg+xml,${encodeURIComponent(bd(t))}`:void 0}return yd(e)}function mf(n){let e=n?.logo;return typeof e=="string"?e===""?void 0:{light:e}:e&&typeof e.light=="string"&&e.light!==""?e:void 0}function yf(n){if(n?.logo)return;let e=wo(n?.favicon);return e!==void 0&&xo(e)===null?e:void 0}var vd={"system-sans":'ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif',"system-serif":'ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, Cambria, "Times New Roman", serif',"system-mono":Te.mono},bf=["serif","sans-serif","monospace","cursive","fantasy","system-ui","math","emoji","-apple-system","BlinkMacSystemFont"],xd=["Georgia","Times New Roman","Times","Iowan Old Style","Palatino","Palatino Linotype","Charter","Cambria","Baskerville","Optima","Helvetica","Helvetica Neue","Arial","Verdana","Segoe UI","Roboto","Avenir","Avenir Next","Gill Sans","Menlo","Monaco","Consolas","SF Mono","SFMono-Regular","Courier New"];var vf=n=>new Set(n.map(e=>e.toLowerCase()));function xf(n){return vf([...bf,...xd]).has(n.toLowerCase())||n.toLowerCase().startsWith("ui-")}function wf(n){return vd[n]??n}function sw(n){let e=It({accent:n,base:pn});return e.ok||!e.missing.every(t=>t.startsWith("warn"))?e:It({accent:n,base:pn,warn:{light:pn.light.bad,dark:pn.dark.bad}})}function kf(n,e,t){if(t.rows===0)return;let r=ne(n,e.rows).toLowerCase(),o=ne(n,e.columns).toLowerCase(),i=e.rows===e.columns,s=i?`link ${r} to each other`:`link ${r} to ${o}`;if(t.columns===0)return`No ${o} yet: ${s}.`;if(t.cells>0||typeof e.link=="object"&&e.link!==null)return;let a=K(n.tryDefinition(e.rows),e.rows);return i?`No ${a} is linked to another yet: ${s}.`:`No ${a} is linked to ${Ce(K(n.tryDefinition(e.columns),e.columns))} yet: ${s}.`}var oe={connectors:{all:{route:"curve",visible:!0},byEdge:{}},captions:{visible:!0},grid:{visible:!0,size:64},lattice:{visible:!0,size:46},tags:{visible:!0},emphasis:{rest:.34,dim:.12},marks:{flag:"\u26A0"}};function Sf(n){return n?{connectors:{all:{...oe.connectors.all,...n.connectors?.all??{}},byEdge:{...oe.connectors.byEdge,...n.connectors?.byEdge??{}}},captions:{...oe.captions,...n.captions??{}},grid:{...oe.grid,...n.grid??{}},lattice:{...oe.lattice,...n.lattice??{}},tags:{...oe.tags,...n.tags??{}},emphasis:{...oe.emphasis,...n.emphasis??{}},marks:{...oe.marks,...n.marks??{}}}:oe}function $f(n,e){return{...n.connectors.all,...n.connectors.byEdge[e]??{}}}function Rf(n){return[` --graview-kit-grid: ${n.grid.visible?1:0};`,` --graview-kit-grid-size: ${n.grid.size}px;`,` --graview-kit-lattice: ${n.lattice.visible?1:0};`,` --graview-kit-lattice-size: ${n.lattice.size}px;`,` --graview-kit-tags: ${n.tags.visible?"inline-flex":"none"};`,` --graview-kit-captions: ${n.captions.visible?"block":"none"};`,` --graview-kit-rest: ${n.emphasis.rest};`,` --graview-kit-dim: ${n.emphasis.dim};`,` --graview-kit-flag: "${n.marks.flag.replace(/"/g,"'")}";`].join(`
|
|
5
|
+
`)}function _f(n,e,t){let r=new Set([e]);for(let[o,i]of t.entries()){let s=n.edge(i);if(!s)return{ok:!1,at:o};let a=s.from,d=s.to==="*"?n.kinds:s.to,f=new Set;for(let c of r){if(a.includes(c))for(let p of d)f.add(p);if(s.to==="*"||d.includes(c))for(let p of a)f.add(p)}if(f.size===0)return{ok:!1,at:o};r=f}return{ok:!0,reached:r}}function Af(n){let e=n.name??"";return e&&n.onBehalfOfName?`${e}, for ${n.onBehalfOfName}`:e}function ko(n,e,t=2500){return n.held==="socket"?!0:n.until!==void 0?e<Date.parse(n.until):e-Date.parse(n.at)<t}function Of(n){return`${n.kind}:${n.id??""}:${n.session??""}`}function Ef(n,e,t,r=2500,o){let i=new Map;for(let[s,a]of n)ko(a,t,r)&&i.set(s,a);for(let s of e){if(!ko(s,t,r)){i.delete(s.participant);continue}let a=i.get(s.participant);(!a||Date.parse(a.at)<=Date.parse(s.at))&&i.set(s.participant,s)}return o!==void 0&&i.delete(o),i}function Pf(n,e){return!n||!e?n===e:n.participant===e.participant&&n.kind===e.kind&&n.name===e.name&&n.onBehalfOf===e.onBehalfOf&&n.onBehalfOfName===e.onBehalfOfName&&n.until===e.until&&n.held===e.held&&n.hue===e.hue&&n.stop===e.stop&&(n.over??null)===(e.over??null)&&(n.robot?.at??null)===(e.robot?.at??null)&&(n.robot?.mode??null)===(e.robot?.mode??null)}export{Ke as a,Qi as b,es as c,bc as d,gr as e,$n as f,Rn as g,D as h,Cg as i,Gg as j,_n as k,Bg as l,Kg as m,Ug as n,mr as o,Vg as p,Ue as q,Ve as r,Wg as s,qg as t,Hg as u,cs as v,us as w,Q as x,Yg as y,st as z,Jg as A,Xg as B,I as C,Dc as D,Ft as E,Le as F,Hn as G,zf as H,H as I,wd as J,kd as K,Ao as L,Jn as M,Sd as N,ge as O,Zt as P,Oo as Q,Lt as R,_d as S,Ad as T,ie as U,Od as V,Ed as W,Pd as X,zd as Y,Md as Z,vn as _,zo as $,Id as aa,Gt as ba,F as ca,jd as da,C as ea,Td as fa,ne as ga,Dd as ha,Fd as ia,Qn as ja,Ce as ka,K as la,Fc as ma,at as na,vr as oa,ls as pa,fs as qa,ps as ra,Zc as sa,An as ta,gs as ua,Qm as va,ct as wa,ad as xa,Fx as ya,Kc as za,Vc as Aa,bs as Ba,Wc as Ca,ry as Da,On as Ea,qc as Fa,Yc as Ga,oy as Ha,iy as Ia,Jc as Ja,xs as Ka,Ll as La,ut as Ma,Xc as Na,qe as Oa,Pn as Pa,lt as Qa,dy as Ra,He as Sa,We as Ta,As as Ua,nu as Va,zn as Wa,Ee as Xa,fy as Ya,Sr as Za,ft as _a,tu as $a,z as ab,N as bb,W as cb,iu as db,gt as eb,Oy as fb,su as gb,au as hb,Gl as ib,Bl as jb,T as kb,q as lb,ve as mb,xe as nb,Fy as ob,Ds as pb,Qe as qb,j as rb,en as sb,ze as tb,ee as ub,fu as vb,re as wb,Vu as xb,Vr as yb,ka as zb,an as Ab,Ub as Bb,Wr as Cb,Ra as Db,_a as Eb,qr as Fb,ke as Gb,Kr as Hb,Ln as Ib,Xu as Jb,Aa as Kb,tb as Lb,rb as Mb,Hr as Nb,Yr as Ob,za as Pb,ja as Qb,il as Rb,St as Sb,Me as Tb,lo as Ub,Kl as Vb,dn as Wb,Nr as Xb,Ys as Yb,gu as Zb,yu as _b,Ql as $b,yo as ac,ef as bc,pn as cc,Te as dc,tf as ec,rf as fc,hd as gc,md as hc,yd as ic,gf as jc,mf as kc,yf as lc,xf as mc,wf as nc,sw as oc,Rl as pc,kf as qc,Sf as rc,$f as sc,Rf as tc,bu as uc,vu as vc,xu as wc,wu as xc,tn as yc,Dn as zc,le as Ac,bt as Bc,on as Cc,Fn as Dc,Zr as Ec,Zn as Fc,ku as Gc,Su as Hc,_f as Ic,ul as Jc,ll as Kc,ba as Lc,fl as Mc,Xa as Nc,cn as Oc,oo as Pc,ml as Qc,yl as Rc,bl as Sc,Qa as Tc,so as Uc,vl as Vc,fe as Wc,Kn as Xc,xl as Yc,wl as Zc,ed as _c,kl as $c,Sl as ad,nd as bd,Un as cd,_l as dd,rd as ed,od as fd,Ol as gd,El as hd,Pl as id,zl as jd,id as kd,Ml as ld,Nl as md,Il as nd,jl as od,Tl as pd,uo as qd,Dl as rd,Fl as sd,Af as td,Of as ud,Ef as vd,Pf as wd};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as o,l as u}from"./chunk.
|
|
1
|
+
import{g as o,l as u}from"./chunk.7L6LYXCV.js";function c(t,n,i){let e=r=>encodeURIComponent(r);return`${o}${e(t)}:${e(n)}:${e(i)}`}function S(t,n,i){let e=new Set(t.shown??[]);if(i?e.add(n):e.delete(n),e.size===0){let{shown:r,...w}=t;return w}return{...t,shown:[...e].sort()}}function l(t,n){if(n===null||n.trim().length===0){let{q:i,...e}=t;return e}return{...t,q:n}}function p(t){let n=t.q!==void 0&&t.within?.q===t.q;return l(n?u(t,"q",null):t,null)}function h(t,n){if(!n){let{past:i,...e}=t;return e}return{...t,past:!0}}function f(t,n){if(n===null||n.x===0&&n.y===0){let{pan:i,...e}=t;return e}return{...t,pan:n}}function d(t,n,i){let e={...t.pins};return i===null?delete e[n]:e[n]=i,{...t,pins:e}}export{c as a,S as b,l as c,p as d,h as e,f,d as g};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{f as k,h,i as b,n as S,o as w,p as I}from"./chunk.
|
|
1
|
+
import{f as k,h,i as b,n as S,o as w,p as I}from"./chunk.YKN2VWWQ.js";import"./chunk.Q5XICUDZ.js";import"./chunk.UT6642FC.js";import"./chunk.SGRKCQ2X.js";import"./chunk.KG5R4GTK.js";import{a as A}from"./chunk.ZEC64CK6.js";import"./chunk.TI4OSTQV.js";import"./chunk.T4Q6OLZU.js";import"./chunk.RSYFIL2Z.js";import"./chunk.R7F6UJVG.js";import"./chunk.DYW4D74X.js";import"./chunk.VP35BUUZ.js";import{G as M,R as f}from"./chunk.7L6LYXCV.js";import"./chunk.SDO3U72B.js";import"./chunk.7MQ7UWVW.js";import"./chunk.2AZTW66C.js";import{b as d}from"./chunk.AJZBJBMO.js";var n=d(M(),1);var r=d(f(),1),C="several";function q({chosen:c,acts:p,onAct:N}){let t=A(),u=(0,n.useMemo)(()=>[...c].sort(),[c]),i=u.join(`
|
|
2
2
|
`),o=(0,n.useMemo)(()=>({on:"selection",ids:u}),[i]),l=(0,n.useMemo)(()=>p.filter(e=>e.open.length===0&&!e.more&&!e.destructive),[p]),g=(0,n.useMemo)(()=>new Map(l.map(e=>[h(e.id),e])),[l]),v=S(t,o,C),[y,x]=(0,n.useState)(null);(0,n.useEffect)(()=>{if(v!==void 0)return;let e=!0;return w(t,o,{by:C,ask:()=>b(t.ai,{store:t.store,target:o,principal:t.principal,interaction:k(),places:t.places,selection:t.selection,...t.place?{place:t.place}:{},shared:l.map(a=>({id:a.id,label:a.label,mutation:a.mutation,args:a.args}))})}).then(a=>{e&&x({key:i,result:a})}),()=>{e=!1}},[i]);let s=v??(y?.key===i?y.result:void 0);if(s===void 0)return(0,r.jsx)("span",{role:"status",className:"graview-several-quiet","data-testid":"several-ai-thinking",style:{textDecoration:"none"},children:"AI: thinking\u2026"});let m=s.offers.filter(e=>e.type!=="act"||g.has(e.id));if(m.length===0)return null;let E=e=>{let a=g.get(e.id);if(a){t.desk.record({...s.interaction,outcome:"accepted",accepted:[e.id]}),N(a);return}I(t,s,e)};return(0,r.jsx)("div",{role:"group","aria-label":"Suggested by AI",className:"graview-several-acts","data-testid":"several-ai",children:m.map(e=>(0,r.jsxs)("button",{type:"button",className:"graview-several-act","data-testid":"several-ai-offer","data-ai-offer":e.id,"data-ai-offer-type":e.type,onClick:()=>E(e),children:[e.label,(0,r.jsx)("span",{style:{color:"var(--graview-ink-faint)",fontWeight:400},children:" \xB7 suggested"})]},e.id))})}export{q as SeveralAi};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as xe}from"./chunk.HJCQ6I3S.js";import{a as je,b as Ee,c as Ie,d as Re}from"./chunk.A3WOUDOG.js";import"./chunk.TKUNRFDE.js";import{c as he}from"./chunk.WH2RYGXR.js";import"./chunk.RSYFIL2Z.js";import"./chunk.R7F6UJVG.js";import"./chunk.DYW4D74X.js";import{G as Ke,R as Pe}from"./chunk.7L6LYXCV.js";import"./chunk.SDO3U72B.js";import"./chunk.7MQ7UWVW.js";import"./chunk.2AZTW66C.js";import{b as pe}from"./chunk.AJZBJBMO.js";var P=pe(Ke(),1);var E=.5,fe=1,ye=.76,Le=3,We=3,Ae=.6;function Oe(c){let{ribbons:m,plots:u,cell:i}=c,a=c.tilt??.5,g=c.labels??[],b=[...u.values()],k=new Map;if(b.length===0||i<=0)return k;let L=Math.min(...b.map(n=>n.col))-3,A=Math.min(...b.map(n=>n.row))-3,G=Math.max(...b.map(n=>n.col+n.side))+3,ce=Math.max(...b.map(n=>n.row+n.side))+3,h=Math.round((G-L)/E)+1,p=Math.round((ce-A)/E)+1,N=n=>L+n*E,B=n=>A+n*E,I=4,_=!0,C=(n,e)=>{if(!_)return!1;let t=he(n,e,i,a);return g.some(s=>t.x>s.x-I&&t.x<s.x+s.width+I&&t.y>s.y-I&&t.y<s.y+s.height+I)},H=(n,e)=>b.some(t=>n>t.col-ye&&n<t.col+t.side+ye&&e>t.row-ye&&e<t.row+t.side+ye),F=new Uint8Array(h*p),J=new Uint8Array(h*p);for(let n=0;n<h;n++)for(let e=0;e<p;e++){let t=N(n),s=B(e);J[e*h+n]=H(t,s)?0:1,F[e*h+n]=J[e*h+n]&&!C(t,s)?1:0}let Q=F,se=new Float32Array(h*p);for(let n=0;n<h;n++)for(let e=0;e<p;e++){let t=N(n),s=B(e);se[e*h+n]=Math.min(...b.map(o=>Math.max(0,o.col-t,t-(o.col+o.side),o.row-s,s-(o.row+o.side))))}let Z=(n,e,t,s)=>{let o=N(n)+t*E/2,l=B(e)+s*E/2;return!H(o,l)&&!C(o,l)},ue=n=>{let e=[],t=(o,l)=>{let w=[],d=Math.min(1,l/3);for(let y=Math.ceil((o+d)/E-1e-9)*E;y<=o+l-d+1e-9;y+=E)w.push(y);return w},s=(o,l,w,d)=>{let y=Math.round((o-L)/E),r=Math.round((l-A)/E);y>=0&&r>=0&&y<h&&r<p&&Q[r*h+y]&&e.push({i:y,j:r,out:w,curb:d})};for(let o of t(n.row,n.side))s(n.col-fe,o,1,{col:n.col,row:o}),s(n.col+n.side+fe,o,0,{col:n.col+n.side,row:o});for(let o of t(n.col,n.side))s(o,n.row-fe,3,{col:o,row:n.row}),s(o,n.row+n.side+fe,2,{col:o,row:n.row+n.side});return e},ee=new Map,V=(n,e,t,s)=>n<t||n===t&&e<s?`${n},${e}-${t},${s}`:`${t},${s}-${n},${e}`,de=[[1,0],[-1,0],[0,1],[0,-1]],X=new Map;for(let n of m){let e=u.get(n.from),t=u.get(n.to);if(!e||!t||e===t)continue;let s=-1,o=[],l=new Map,w=new Int32Array(0),d=1/0,y=[];for(let f of[!0,!1]){s=-1,d=1/0,_=f,Q=f?F:J,o=ue(e);let W=ue(t);if(o.length===0||W.length===0){y.push({reached:-1,starts:o,goal:l,back:w,best:d});continue}l=new Map(W.map(j=>[j.j*h+j.i,j]));let ne=(j,R)=>{let re=N(j),ae=B(R);return(Math.max(0,t.col-re,re-(t.col+t.side))+Math.max(0,t.row-ae,ae-(t.row+t.side)))*Ae},oe=h*p*4,ie=new Float64Array(oe).fill(1/0);w=new Int32Array(oe).fill(-1);let le=new ke;for(let j of o){let R=(j.j*h+j.i)*4+j.out;ie[R]=0,le.push(R,ne(j.i,j.j))}let Ce=[1,0,3,2];for(;le.size>0&&!(le.peekKey()>=d);){let R=le.pop(),re=Math.floor(R/4),ae=R%4,ge=re%h,we=Math.floor(re/h),ve=l.get(re);if(ve){let q=ie[R]+(ae===Ce[ve.out]?0:Le);q<d&&(d=q,s=R);continue}for(let q=0;q<4;q++){let[Me,$e]=de[q],U=ge+Me,z=we+$e;if(U<0||z<0||U>=h||z>=p||!Q[z*h+U]||!Z(ge,we,Me,$e))continue;let Te=E*(ee.has(V(ge,we,U,z))?Ae:1)*(1+Math.max(0,se[z*h+U]-We))+(q===ae?0:Le),me=(z*h+U)*4+q,be=ie[R]+Te;be<ie[me]&&(ie[me]=be,w[me]=R,le.push(me,be+ne(U,z)))}}y.push({reached:s,starts:o,goal:l,back:w,best:d})}_=!0,Q=F;let[r,v]=y,M=r&&r.reached!==-1&&(!v||v.reached===-1||r.best<=1.3*v.best+2)?r:v;if(!M||M.reached===-1)continue;({reached:s,starts:o,goal:l,back:w}=M);let x=[];for(let f=s;f!==-1;f=w[f]){let W=Math.floor(f/4),ne=x[x.length-1],oe={i:W%h,j:Math.floor(W/h)};(!ne||ne.i!==oe.i||ne.j!==oe.j)&&x.push(oe)}x.reverse();for(let f=1;f<x.length;f++){let W=V(x[f-1].i,x[f-1].j,x[f].i,x[f].j);ee.set(W,[...ee.get(W)??[],n.key])}let D=o.find(f=>f.i===x[0].i&&f.j===x[0].j),$=l.get(x[x.length-1].j*h+x[x.length-1].i);X.set(n.key,{cells:x,start:D.curb,end:$.curb})}let O=new Map(m.map(n=>[n.key,n.width])),T=new Map(m.map((n,e)=>[n.key,e])),te=i*a/Math.sqrt(1+a*a),Y=(n,e)=>n==="col"?`r${e.row.toFixed(2)}`:`c${e.col.toFixed(2)}`,K=new Map;for(let[n,e]of X)for(let t=1;t<e.cells.length;t++){let s=e.cells[t-1],o=e.cells[t],l=Y(s.i!==o.i?"col":"row",{col:N(s.i),row:B(s.j)});K.set(l,(K.get(l)??new Set).add(n))}for(let[n,e]of X){let t=[e.start,...e.cells.map(r=>({col:N(r.i),row:B(r.j)})),e.end],s=r=>r>=2&&r<=e.cells.length?V(e.cells[r-2].i,e.cells[r-2].j,e.cells[r-1].i,e.cells[r-1].j):null,o=[];for(let r=1;r<t.length;r++){let v=Math.abs(t[r].col-t[r-1].col)>1e-9?"col":"row",M=o[o.length-1];M&&M.axis===v?M.to=r:o.push({from:r-1,to:r,axis:v})}if(o.length===0)continue;let l=o.map(r=>{if(!Array.from({length:r.to-r.from},($,f)=>s(r.from+1+f)).some($=>$!==null))return 0;let v=K.get(Y(r.axis,t[r.from]))??new Set;if(!v.has(n))return 0;let M=[...v].sort(($,f)=>(T.get($)??0)-(T.get(f)??0)),D=-(M.reduce(($,f)=>$+(O.get(f)??2)+2,0)-2)/2;for(let $ of M){if($===n)return(D+(O.get($)??2)/2)/te;D+=(O.get($)??2)+2}return 0}),w=r=>{let v=o[r],M=t[v.from];return v.axis==="col"?{row:M.row+l[r]}:{col:M.col+l[r]}},d=(r,v,M)=>({col:r.col??v.col??M.col,row:r.row??v.row??M.row}),y=[d(w(0),{},t[0])];for(let r=0;r+1<o.length;r++)y.push(d(w(r),w(r+1),t[o[r].to]));y.push(d(w(o.length-1),{},t[t.length-1])),k.set(n,y.map(r=>he(r.col,r.row,i,a)))}return k}var ke=class{items=[];keys=[];get size(){return this.items.length}peekKey(){return this.keys[0]??1/0}push(m,u){this.items.push(m),this.keys.push(u);let i=this.items.length-1;for(;i>0;){let a=i-1>>1;if(this.keys[a]<=this.keys[i])break;this.swap(i,a),i=a}}pop(){let m=this.items[0],u=this.items.pop(),i=this.keys.pop();if(this.items.length>0){this.items[0]=u,this.keys[0]=i;let a=0;for(;;){let g=2*a+1,b=g+1,k=a;if(g<this.items.length&&this.keys[g]<this.keys[k]&&(k=g),b<this.items.length&&this.keys[b]<this.keys[k]&&(k=b),k===a)break;this.swap(a,k),a=k}}return m}swap(m,u){[this.items[m],this.items[u]]=[this.items[u],this.items[m]],[this.keys[m],this.keys[u]]=[this.keys[u],this.keys[m]]}};function Se(c,m){let u=c.col+c.side,i=u+.25+.22*Math.max(0,m),a=c.row+c.side*Math.max(.1,.3-.06*m),g=c.row+c.side*Math.min(.9,.7+.06*m);return[{col:u,row:a},{col:i,row:a},{col:i,row:g},{col:u,row:g}]}function Be(c,m){return c.map(u=>he(u.col,u.row,m.cell,m.tilt))}function Fe(c){return c.map((m,u)=>`${u===0?"M":"L"} ${m.x.toFixed(1)} ${m.y.toFixed(1)}`).join(" ")}function Ne(c){if(c.length===0)return{x:0,y:0};let m=0;for(let i=1;i<c.length;i++)m+=Math.hypot(c[i].x-c[i-1].x,c[i].y-c[i-1].y);let u=m/2;for(let i=1;i<c.length;i++){let a=c[i-1],g=c[i],b=Math.hypot(g.x-a.x,g.y-a.y);if(b>=u&&b>0)return{x:a.x+(g.x-a.x)*u/b,y:a.y+(g.y-a.y)*u/b};u-=b}return c[c.length-1]}var S=pe(Pe(),1);function Ue({frame:c,width:m,height:u,pan:i,store:a,graphVersion:g,selection:b,view:k,emphasis:L,hiddenKinds:A,drawn:G}){let[ce,h]=(0,P.useState)(null),p=c.city,N=e=>a.graph.getNode(e)?.kind,B=(0,P.useMemo)(()=>je(a.graph.allEdges(),e=>a.graph.getNode(e)?.kind),[a,g]),I=new Map;for(let e of c.nodes){let t=e.id.startsWith("kind:")?Ie(e.id):null;t!==null&&e.plot&&Math.round(e.plane)===2&&I.set(t,e.plot)}let _=[...I].map(([e,t])=>`${e}:${t.col},${t.row},${t.side}`).join(";"),C=p?.cell??0,H=B.filter(e=>I.has(e.from)&&I.has(e.to)&&!A.has(e.from)&&!A.has(e.to)&&G(e.edge)),F=p?.tilt??.5,[J,Q]=(0,P.useState)([]),se=J.map(e=>`${Math.round(e.x)},${Math.round(e.y)},${Math.round(e.width)},${Math.round(e.height)}`).join(";"),[Z,ue]=(0,P.useState)(null),ee=c.t>=1;(0,P.useLayoutEffect)(()=>{let e=Z?.parentElement;if(!e||!p||!ee)return;let t=e.getBoundingClientRect(),s=p.originX+i.x,o=p.originY+i.y,l=[...e.querySelectorAll('[data-graview-view^="kind:"] .graview-kind-face')].flatMap(d=>{let y=d.getBoundingClientRect();return y.width>0&&y.height>0?[{x:y.left-t.left-s,y:y.top-t.top-o,width:y.width,height:y.height}]:[]});l.map(d=>`${Math.round(d.x)},${Math.round(d.y)},${Math.round(d.width)},${Math.round(d.height)}`).join(";")!==se&&Q(l)},[Z,ee,_,C,F]);let V=(0,P.useMemo)(()=>{if(C===0)return[];let e=new Map,t=Math.max(0,...H.map(o=>o.links)),s=Oe({ribbons:H.map(o=>({key:o.key,from:o.from,to:o.to,width:xe(o.links,t)})),plots:I,cell:C,tilt:F,labels:J});return H.flatMap(o=>{let l;if(o.from===o.to){let w=e.get(o.from)??0;e.set(o.from,w+1),l=Be(Se(I.get(o.from),w),{cell:C,tilt:F})}else l=s.get(o.key);return!l||l.length<2?[]:[{ribbon:o,points:l,d:Fe(l),middle:Ne(l),width:xe(o.links,t)}]})},[C,F,_,B,G,A,se]),de=(0,P.useRef)([]),X=(0,P.useRef)({x:0,y:0});if(X.current=p?{x:p.originX+i.x,y:p.originY+i.y}:{x:0,y:0},(0,P.useEffect)(()=>{let e=Z?.parentElement;if(!e||typeof window>"u")return;let t=0,s=null,o=()=>{t=0;let d=s;if(!d)return;let y=d.target;if(d.pointerType==="touch"||d.buttons!==0||y?.closest("[data-graview-view], button, a, input, select, textarea, [data-graview-overlay], [data-graview-offstage]")){h(null);return}let r=e.getBoundingClientRect(),v=d.clientX-r.left-X.current.x,M=d.clientY-r.top-X.current.y,x=null,D=1/0;for(let $ of de.current){let f=qe($.points,v,M);f<=$.reach&&f<D&&(D=f,x=$.key)}h(x)},l=d=>{s=d,t===0&&(t=requestAnimationFrame(o))},w=()=>h(null);return e.addEventListener("pointermove",l,{passive:!0}),e.addEventListener("pointerleave",w),()=>{t!==0&&cancelAnimationFrame(t),e.removeEventListener("pointermove",l),e.removeEventListener("pointerleave",w)}},[Z]),!p||!k.overview||V.length===0)return null;let O=Ee(b,k,N);if(O.records.length>0||O.lens!==null)return null;let T=O.districts.length>0?V.filter(({ribbon:e})=>O.districts.includes(e.from)||O.districts.includes(e.to)):V;if(T.length===0)return null;let te=L??null,Y=T.find(({ribbon:e})=>e.key===ce);de.current=T.map(({ribbon:e,points:t,width:s})=>({key:e.key,points:t,reach:s/2+6}));let K={x:p.originX+i.x,y:p.originY+i.y},n=`translate(${K.x.toFixed(1)} ${K.y.toFixed(1)})`;return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("svg",{ref:ue,className:"graview-ribbons","aria-hidden":"true","data-graview-world":"","data-graview-ribbons":T.length,width:m,height:u,style:{position:"absolute",left:0,top:0,pointerEvents:"none",overflow:"visible"},children:(0,S.jsx)("g",{transform:n,children:T.map(({ribbon:e,d:t,width:s})=>{let o=ce===e.key||te!==null&&te===e.edge||O.districts.length>0,l=te!==null&&te!==e.edge;return(0,S.jsx)("g",{className:"graview-ribbon","data-graview-ribbon":e.edge,"data-graview-from":`kind:${e.from}`,"data-graview-to":`kind:${e.to}`,"data-graview-links":e.links,"data-graview-lit":o&&!l?"":void 0,"data-graview-receded":l?"":void 0,children:(0,S.jsx)("path",{className:"graview-ribbon-band",d:t,style:{strokeWidth:s}})},e.key)})})}),Y?(0,S.jsx)("div",{className:"graview-ribbon-said","data-graview-world":"","data-testid":"ribbon-said",role:"status",style:{position:"absolute",left:K.x+Y.middle.x,top:K.y+Y.middle.y,pointerEvents:"none"},children:Re(a.schema,Y.ribbon)}):null]})}function qe(c,m,u){let i=1/0;for(let a=1;a<c.length;a++){let g=c[a-1],b=c[a],k=b.x-g.x,L=b.y-g.y,A=k*k+L*L,G=A===0?0:Math.max(0,Math.min(1,((m-g.x)*k+(u-g.y)*L)/A));i=Math.min(i,Math.hypot(m-(g.x+G*k),u-(g.y+G*L)))}return i}export{Ue as Ribbons,qe as distanceTo};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as a}from"./chunk.
|
|
1
|
+
import{g as a}from"./chunk.MI2HL3LQ.js";import{c as p}from"./chunk.TMBFLZNH.js";import{Fa as d}from"./chunk.7MQ7UWVW.js";function k(n){let r=new Map;for(let i of n.kinds){let e=n.tryDefinition(i),o=a(e),s=d(e);r.set(i,{fields:new Set(Object.keys(e?.fields?.shape??{})),edges:new Map(Object.entries(e?.edges??{}).map(([l,h])=>[l,h.cardinality??"many"])),...o?{computed:o}:{},...s.size>0?{linked:s}:{}})}let t=a(n);return t&&r.set(p,{computed:t}),r}export{k as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as u}from"./chunk.
|
|
1
|
+
import{c as u}from"./chunk.DYW4D74X.js";import{fa as l}from"./chunk.7MQ7UWVW.js";function a(e,n){let s=new Map;for(let o of e){let t=n(o.from),i=n(o.to);if(t===void 0||i===void 0)continue;let d=`${o.kind}|${t}|${i}`,r=s.get(d);r||s.set(d,r={edge:o.kind,from:t,to:i,links:0,froms:new Set,tos:new Set}),r.links+=1,r.froms.add(o.from),r.tos.add(o.to)}return[...s.entries()].sort(([o],[t])=>o<t?-1:o>t?1:0).map(([o,t])=>({key:o,edge:t.edge,from:t.from,to:t.to,links:t.links,fromCount:t.froms.size,toCount:t.tos.size}))}function m(e,n,s){let o=[],t=[];for(let d of e){let r=f(d);if(r!==null){o.includes(r)||o.push(r);continue}s(d)!==void 0&&t.push(d)}let i=n.overview&&n.focusId!==null?f(n.focusId):null;return n.beside&&n.overview&&i===null&&n.focusId!==null&&t.length===0&&o.length===0&&s(n.focusId)!==void 0&&t.push(n.focusId),{districts:o,records:t,lens:i}}function f(e){return e.startsWith("kind:")?e.slice(5)||null:e.startsWith("aggregate:")&&!e.includes("|")&&e.slice(10)||null}function y(e,n){let s=u(e,n.from,n.edge,"out"),o=n.from===n.to?" of their own":"";return`${l(e,n.from,n.fromCount)} \u2192 ${l(e,n.to,n.toCount)}${o}, ${s}`}export{a,m as b,f as c,y as d};
|