graview 0.1.55 → 0.1.57
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.XSMXSNDR.js → chunk.2PWVDUOU.js} +1 -1
- package/dist/preview/{chunk.AFK5HHLL.js → chunk.33PZEW5A.js} +1 -1
- package/dist/preview/{chunk.SUGOENC4.js → chunk.3DPTDMJ7.js} +1 -1
- package/dist/preview/chunk.47T3KUAA.js +1 -0
- package/dist/preview/{chunk.XUHY4XO2.js → chunk.4BRM5SGO.js} +1 -1
- package/dist/preview/{chunk.4TLWZVVG.js → chunk.4HFCOMR3.js} +1 -1
- package/dist/preview/{chunk.5MCXTY2P.js → chunk.4HPP35XQ.js} +1 -1
- package/dist/preview/chunk.4JDHBNEA.js +104 -0
- package/dist/preview/{chunk.QWICAV2C.js → chunk.4K6VAC2S.js} +2 -2
- package/dist/preview/{chunk.ZXOD5GM3.js → chunk.4L4F47QP.js} +1 -1
- package/dist/preview/{chunk.SIABGHF2.js → chunk.4NPXMYA5.js} +1 -1
- package/dist/preview/{chunk.354A4QCG.js → chunk.4OP4IEEY.js} +1 -1
- package/dist/preview/chunk.4SBYXHCQ.js +1 -0
- package/dist/preview/{chunk.LYVRXRIH.js → chunk.4UQBMFJZ.js} +1 -1
- package/dist/preview/{chunk.7WEQHJ3N.js → chunk.4W5GCPAP.js} +1 -1
- package/dist/preview/{chunk.TT6GKRBE.js → chunk.4XKRCAJZ.js} +1 -1
- package/dist/preview/{chunk.HXHFWZ2U.js → chunk.534TBZJ3.js} +2 -2
- package/dist/preview/{chunk.JRRVLGEK.js → chunk.53U6E5LD.js} +1 -1
- package/dist/preview/{chunk.HXR7EEXR.js → chunk.547FQPYG.js} +1 -1
- package/dist/preview/{chunk.O752PM42.js → chunk.57BKS5KD.js} +1 -1
- package/dist/preview/chunk.57KRCHQT.js +1 -0
- package/dist/preview/{chunk.KVQZ5FR6.js → chunk.5BPRGXIW.js} +1 -1
- package/dist/preview/{chunk.TAQB64FZ.js → chunk.5GTOF5D5.js} +1 -1
- package/dist/preview/{chunk.KY7QD22S.js → chunk.5IEFTFKQ.js} +1 -1
- package/dist/preview/chunk.5NZDFT6R.js +1 -0
- package/dist/preview/{chunk.AFEEXRN3.js → chunk.66LWZIY5.js} +1 -1
- package/dist/preview/{chunk.USJ4J3GL.js → chunk.6AH26OL7.js} +2 -2
- package/dist/preview/{chunk.PIQ52FCI.js → chunk.6SD7YZ4U.js} +2 -2
- package/dist/preview/{chunk.AVVNQKA7.js → chunk.72IHABM5.js} +1 -1
- package/dist/preview/chunk.7INWDFNG.js +1 -0
- package/dist/preview/{chunk.FUZWXKTN.js → chunk.7IXTNST2.js} +1 -1
- package/dist/preview/{chunk.6UAUME5U.js → chunk.7ML2BWSP.js} +1 -1
- package/dist/preview/chunk.7UBABS2T.js +1 -0
- package/dist/preview/{chunk.CM2ETM2A.js → chunk.7VIFAN3O.js} +1 -1
- package/dist/preview/chunk.7VZA34T4.js +1 -0
- package/dist/preview/{chunk.EJXUOL2C.js → chunk.AD3EC5DU.js} +1 -1
- package/dist/preview/{chunk.BRCKXL7B.js → chunk.BCE6LIDR.js} +1 -1
- package/dist/preview/chunk.BPEUHOKH.js +1 -0
- package/dist/preview/{chunk.KHJ2MCMS.js → chunk.BUSFJM6P.js} +1 -1
- package/dist/preview/{chunk.2HANQ737.js → chunk.BZEJM2PY.js} +1 -1
- package/dist/preview/{chunk.YGZGMRDC.js → chunk.C5EFUODO.js} +1 -1
- package/dist/preview/{chunk.ATXSLBE3.js → chunk.C7EJPV2N.js} +1 -1
- package/dist/preview/chunk.CMLNBJZG.js +3 -0
- package/dist/preview/{chunk.NXM73RZA.js → chunk.CUKRUQQ2.js} +1 -1
- package/dist/preview/chunk.CXB4BSI4.js +1 -0
- package/dist/preview/{chunk.5EOSEVZB.js → chunk.D3LQJXVP.js} +1 -1
- package/dist/preview/{chunk.YOBRVKJT.js → chunk.D4EP7FEC.js} +1 -1
- package/dist/preview/{chunk.WSMYFEGU.js → chunk.DBMZ3AQB.js} +1 -1
- package/dist/preview/chunk.DIFR37EZ.js +5 -0
- package/dist/preview/chunk.DJ4A76SX.js +1 -0
- package/dist/preview/{chunk.O7RMVGAB.js → chunk.DM5X3JBH.js} +1 -1
- package/dist/preview/chunk.DQUISKTC.js +1 -0
- package/dist/preview/chunk.DSLGMCB6.js +1 -0
- package/dist/preview/chunk.DSWMXM57.js +1 -0
- package/dist/preview/{chunk.DB3HOKZD.js → chunk.DWLKJGVT.js} +1 -1
- package/dist/preview/{chunk.2KH2LWZL.js → chunk.EQAAKYLA.js} +1 -1
- package/dist/preview/{chunk.4OMSQFIY.js → chunk.EXZLG3HK.js} +1 -1
- package/dist/preview/{chunk.QJ42D5GM.js → chunk.EZ4NUZWX.js} +1 -1
- package/dist/preview/{chunk.WUFCRE7O.js → chunk.EZ4TZUMM.js} +1 -1
- package/dist/preview/chunk.FJTWAU7N.js +1 -0
- package/dist/preview/{chunk.WVKXELAF.js → chunk.FLMNWVSY.js} +2 -2
- package/dist/preview/{chunk.K5WPS4RR.js → chunk.FLVE6IBM.js} +1 -1
- package/dist/preview/chunk.FPGU43SC.js +1 -0
- package/dist/preview/{chunk.5DPFAVCZ.js → chunk.FRERJWZJ.js} +1 -1
- package/dist/preview/{chunk.OT6EWYK2.js → chunk.G3BDQ6EA.js} +1 -1
- package/dist/preview/chunk.GBAUQXXD.js +1 -0
- package/dist/preview/{chunk.5SANELJT.js → chunk.H5CRRBNU.js} +1 -1
- package/dist/preview/{chunk.7Y6NK5CT.js → chunk.HFSG3F5Z.js} +1 -1
- package/dist/preview/chunk.I2NI7CT7.js +1 -0
- package/dist/preview/{chunk.ZAHVKXYQ.js → chunk.I5PSHASU.js} +1 -1
- package/dist/preview/{chunk.TDV7JGIQ.js → chunk.I636CZE4.js} +1 -1
- package/dist/preview/chunk.I6H3HRWT.js +1 -0
- package/dist/preview/{chunk.62LPYPP3.js → chunk.IRQOJATD.js} +1 -1
- package/dist/preview/chunk.IV7AUO53.js +1 -0
- package/dist/preview/{chunk.RZQKCLTW.js → chunk.IX63LTRQ.js} +1 -1
- package/dist/preview/{chunk.IXHLP2CL.js → chunk.JBSW7ZNH.js} +1 -1
- package/dist/preview/chunk.JD5HSAMC.js +18 -0
- package/dist/preview/{chunk.ZOW7AC7U.js → chunk.JETT6ELP.js} +1 -1
- package/dist/preview/{chunk.LQCH2NFE.js → chunk.JNNBHD4Z.js} +1 -1
- package/dist/preview/{chunk.LMXNHBGH.js → chunk.JQFIZRAZ.js} +2 -2
- package/dist/preview/chunk.KNYLY7MH.js +1 -0
- package/dist/preview/chunk.KO7IOFNY.js +1 -0
- package/dist/preview/{chunk.EGSE6NNE.js → chunk.KPIDJYIU.js} +1 -1
- package/dist/preview/{chunk.YRFN4VDD.js → chunk.KTV24HY7.js} +1 -1
- package/dist/preview/{chunk.6JYNNPAI.js → chunk.KYOI7BG3.js} +1 -1
- package/dist/preview/{chunk.PHLMQO7V.js → chunk.LE2KAR25.js} +1 -1
- package/dist/preview/{chunk.UE5GAP67.js → chunk.LHIT3EZD.js} +2 -2
- package/dist/preview/{chunk.DBCVZGCC.js → chunk.LKJ6FD6Y.js} +1 -1
- package/dist/preview/chunk.LUIRQ5UF.js +2 -0
- package/dist/preview/chunk.LWRXCO2Z.js +1 -0
- package/dist/preview/{chunk.YYWANGIC.js → chunk.M72JKVHP.js} +4 -4
- package/dist/preview/{chunk.6NQQUIBX.js → chunk.MAZFQIL5.js} +1 -1
- package/dist/preview/{chunk.CPNE6HPQ.js → chunk.MBLFZF5R.js} +1 -1
- package/dist/preview/{chunk.PSLCI3GO.js → chunk.MRHPOUA4.js} +1 -1
- package/dist/preview/{chunk.PIHCXN5U.js → chunk.MWWOI5PW.js} +1 -1
- package/dist/preview/{chunk.35O5H5L7.js → chunk.N2DM42SG.js} +2 -2
- package/dist/preview/chunk.N33WUCAN.js +3 -0
- package/dist/preview/{chunk.PCKX2FHR.js → chunk.N5MQARN6.js} +1 -1
- package/dist/preview/{chunk.G5XTASMO.js → chunk.NF72Z2HG.js} +1 -1
- package/dist/preview/{chunk.RNYLNBIB.js → chunk.NGK6IRV3.js} +1 -1
- package/dist/preview/chunk.NL3AJZ3N.js +1 -0
- package/dist/preview/chunk.NUS5K56R.js +21 -0
- package/dist/preview/{chunk.XTP5DGPJ.js → chunk.NX7CR4AE.js} +1 -1
- package/dist/preview/chunk.NZDWXX6H.js +1 -0
- package/dist/preview/{chunk.5L4J2XAI.js → chunk.O47MN7E5.js} +1 -1
- package/dist/preview/chunk.OYUDK3LK.js +1 -0
- package/dist/preview/chunk.PF5P5YVD.js +1 -0
- package/dist/preview/{chunk.V6X3U3JF.js → chunk.PHC2MI4C.js} +1 -1
- package/dist/preview/{chunk.U5AX4DD5.js → chunk.PQMMISCQ.js} +1 -1
- package/dist/preview/{chunk.TUBAFVV4.js → chunk.Q6OZLBNL.js} +1 -1
- package/dist/preview/{chunk.ZPXAKRKG.js → chunk.QMYHXMRV.js} +1 -1
- package/dist/preview/chunk.QPL3OXW3.js +1 -0
- package/dist/preview/{chunk.V5PAFSWP.js → chunk.QS6YW7UY.js} +1 -1
- package/dist/preview/chunk.QUJS63OJ.js +13 -0
- package/dist/preview/{chunk.EKP3HQAX.js → chunk.RALAID6N.js} +1 -1
- package/dist/preview/chunk.RQX4CQJN.js +1 -0
- package/dist/preview/{chunk.PM64C5PX.js → chunk.RVR6FWAF.js} +1 -1
- package/dist/preview/{chunk.MFCBAQS3.js → chunk.S5ECRIG5.js} +1 -1
- package/dist/preview/{chunk.DNJM6WQO.js → chunk.SAJLIA5M.js} +1 -1
- package/dist/preview/{chunk.RPVJ5IXD.js → chunk.TBRXNU6T.js} +1 -1
- package/dist/preview/{chunk.Y3BEKXYB.js → chunk.TVURUMU4.js} +1 -1
- package/dist/preview/chunk.UBNZDSS7.js +1 -0
- package/dist/preview/chunk.UDCDK7XJ.js +4 -0
- package/dist/preview/{chunk.6ZJE5M2A.js → chunk.UGOKORIF.js} +1 -1
- package/dist/preview/{chunk.NDLQXQV2.js → chunk.UV3U4FRT.js} +1 -1
- package/dist/preview/{chunk.QBMIET7P.js → chunk.UWQ3I5OW.js} +1 -1
- package/dist/preview/chunk.V6FUYRZI.js +1 -0
- package/dist/preview/{chunk.2SWQI4HF.js → chunk.VDS3IOTK.js} +1 -1
- package/dist/preview/chunk.VHPGGC2P.js +1 -0
- package/dist/preview/chunk.VSGTNYM2.js +1 -0
- package/dist/preview/{chunk.FUS2FJS3.js → chunk.VW4JAQCH.js} +1 -1
- package/dist/preview/{chunk.OS5EALHY.js → chunk.WASWMHND.js} +1 -1
- package/dist/preview/chunk.WYPL2QUA.js +1 -0
- package/dist/preview/{chunk.MFOSEOF4.js → chunk.XTBS64IT.js} +1 -1
- package/dist/preview/chunk.XVN3CQKH.js +2 -0
- package/dist/preview/{chunk.27ZSRO3O.js → chunk.Y3EOGXRS.js} +1 -1
- package/dist/preview/chunk.Y4KNR76Z.js +1 -0
- package/dist/preview/chunk.YDTXCVBU.js +1 -0
- package/dist/preview/{chunk.DH4AC7TC.js → chunk.YPP7FSEZ.js} +1 -1
- package/dist/preview/{chunk.FTW3K3G6.js → chunk.YQXA4WAM.js} +2 -2
- package/dist/preview/{chunk.4BFJWNVM.js → chunk.YR75TWDV.js} +1 -1
- package/dist/preview/{chunk.QIAH7HHO.js → chunk.YS5U3DUX.js} +1 -1
- package/dist/preview/chunk.Z5UVYOGC.js +1 -0
- package/dist/preview/{chunk.P4ZZSFOQ.js → chunk.ZNXRHOUI.js} +1 -1
- package/dist/preview/index.html +50 -50
- package/dist/preview/page.js +2 -2
- package/package.json +6 -6
- package/dist/preview/chunk.2ORJGMRT.js +0 -104
- package/dist/preview/chunk.3IZOXNJH.js +0 -1
- package/dist/preview/chunk.5D6SIBOK.js +0 -1
- package/dist/preview/chunk.5EZDXWOE.js +0 -1
- package/dist/preview/chunk.5MSNKSTE.js +0 -1
- package/dist/preview/chunk.5XUVCM7X.js +0 -1
- package/dist/preview/chunk.6NGSR2ZQ.js +0 -1
- package/dist/preview/chunk.7KERB5CH.js +0 -1
- package/dist/preview/chunk.AVNOLMCV.js +0 -1
- package/dist/preview/chunk.AZ6Q3WT2.js +0 -1
- package/dist/preview/chunk.DKJK2MMV.js +0 -2
- package/dist/preview/chunk.DU75P3Y7.js +0 -1
- package/dist/preview/chunk.DVG47BK3.js +0 -1
- package/dist/preview/chunk.DXJFAAOI.js +0 -1
- package/dist/preview/chunk.F5RN6YXG.js +0 -4
- package/dist/preview/chunk.FVOFTM5J.js +0 -1
- package/dist/preview/chunk.G2XDQPE4.js +0 -1
- package/dist/preview/chunk.H536YUAZ.js +0 -3
- package/dist/preview/chunk.HNJFBI7J.js +0 -1
- package/dist/preview/chunk.HUABTCQE.js +0 -1
- package/dist/preview/chunk.INBHY3SA.js +0 -1
- package/dist/preview/chunk.KIMIPHAI.js +0 -1
- package/dist/preview/chunk.KXNWZ33P.js +0 -1
- package/dist/preview/chunk.LEPKPNPA.js +0 -1
- package/dist/preview/chunk.LLXEWLIP.js +0 -1
- package/dist/preview/chunk.LWLI5PI4.js +0 -1
- package/dist/preview/chunk.MIQMPOWF.js +0 -2
- package/dist/preview/chunk.MNSKBGRM.js +0 -1
- package/dist/preview/chunk.MSM6E6JK.js +0 -1
- package/dist/preview/chunk.NS6KWKF5.js +0 -1
- package/dist/preview/chunk.OIMYSR2J.js +0 -1
- package/dist/preview/chunk.OL2N5NUV.js +0 -1
- package/dist/preview/chunk.QQ3YWKWU.js +0 -1
- package/dist/preview/chunk.R3ZS4QO6.js +0 -18
- package/dist/preview/chunk.SG67ID6C.js +0 -1
- package/dist/preview/chunk.SYX7AEHU.js +0 -1
- package/dist/preview/chunk.T66UK7PQ.js +0 -3
- package/dist/preview/chunk.TEE23CVQ.js +0 -1
- package/dist/preview/chunk.TZTRGNAA.js +0 -1
- package/dist/preview/chunk.UADL2LHO.js +0 -1
- package/dist/preview/chunk.URDCHVH3.js +0 -21
- package/dist/preview/chunk.WR63RQGU.js +0 -5
- package/dist/preview/chunk.XE72DFBV.js +0 -13
- package/dist/preview/chunk.XEHLSKHP.js +0 -1
- package/dist/preview/chunk.YG2WZO53.js +0 -1
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{a as ar,b as ue,c as Fe,d as zn,f as $e,g as dr,h as Le,i as Nn,j as ci}from"./chunk.FQLNBIQ5.js";var ur="en-US",sn=/^\d{4}-\d{2}-\d{2}$/,ft=/^\d{4}(-\d\d){2}[T ]\d\d:\d\d(:[\d.]+)?(Z|[+-][\d:]+)?$/,rh=n=>!Number.isNaN(Date.parse(n)),ee=(n,e=Date.now())=>{let t=pt(n);return t?lr(e,t).day:new Date(e).toISOString().slice(0,10)},pt=n=>on(n)??rn,In,Tn,jn,rn;function wc(n){In=Dn(n.reader),Tn=Dn(n.app),jn=on(n.readerTimeZone),rn=on(n.appTimeZone)}function kc(n,e){let t=[In,Tn,jn,rn];n.reader!==void 0&&(In=Dn(n.reader)),n.app!==void 0&&(Tn=Dn(n.app)),n.readerTimeZone!==void 0&&(jn=on(n.readerTimeZone)),n.appTimeZone!==void 0&&(rn=on(n.appTimeZone));try{return e()}finally{[In,Tn,jn,rn]=t}}var ui=n=>In??Dn(n)??Tn??ur,ht=n=>jn??on(n)??rn,Sc=n=>ht(n)??Intl.DateTimeFormat().resolvedOptions().timeZone??"UTC",$c=/^\s*([+\-−]|\d)/;var cr=new Map;function on(n){if(n&&!cr.has(n)){let e=!1;try{new Intl.DateTimeFormat(ur,{timeZone:n}),e=!$c.test(n)}catch{}cr.set(n,e)}return n&&cr.get(n)?n:void 0}var Ze=new Map;function Dn(n){if(n&&!Ze.has(n)){let e=!1;try{e=Intl.DateTimeFormat.supportedLocalesOf(n).length>0}catch{}Ze.set(n,e)}return n&&Ze.get(n)?n:void 0}function Re(n,e,t,r){let o=`${t=ui(t)}${r?"#":"@"}${JSON.stringify(e)}`,i=Ze.get(o);return i||Ze.set(o,i=r?new Intl.NumberFormat(t,e):new Intl.DateTimeFormat(t,e)),i.format(n).replace(/ /g," ")}var Ce="UTC",gt=n=>Date.UTC(+n.slice(0,4),+n.slice(5,7)-1,+n.slice(8,10));function Ae(n,e){return sn.test(n)?Re(gt(n),{year:"numeric",month:"short",day:"numeric",timeZone:Ce},e):n}function lr(n,e){let t=`wall@${e??""}`,r=Ze.get(t);r||Ze.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 li(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=lr(i,t);return Rc(s.day,s.minutes)-Math.floor(i/6e4)*6e4};return r-o(r-o(r))}var Rc=(n,e)=>Date.UTC(+n.slice(0,4),+n.slice(5,7)-1,+n.slice(8,10),0,e),fi=n=>/[Z+-][\d:]*$/.test(n.slice(16));function pi(n,e,t,r,o=!1){if(!ft.test(n))return n;let i=fi(n),s=Date.parse(n.replace(" ","T")+(i?"":"Z"));if(Number.isNaN(s))return n;let a=i?ht(r):Ce;return Re(s,{...e,hour:"numeric",minute:"2-digit",...i&&o?{timeZoneName:"short"}:{},...a?{timeZone:a}:{}},t)}var fr=(n,e,t)=>pi(n,{year:"numeric",month:"short",day:"numeric"},e,t,!0),Ac=(n,e,t)=>pi(n,{},e,t);function _c(n,e){if(sn.test(n))return n;if(!ft.test(n))return;if(!fi(n))return n.slice(0,10);let t=Date.parse(n.replace(" ","T"));return Number.isNaN(t)?void 0:lr(t,ht(e)).day}function me(n,e,t={maximumFractionDigits:2}){return Number.isFinite(n)?Re(n,t,e,!0):String(n)}function Oc(n,e={},t){return sn.test(n)?Re(gt(n),{weekday:e.weekday??"long",month:"short",day:"numeric",...e.year?{year:"numeric"}:{},timeZone:Ce},t):n}function Pc(n,e){return sn.test(n)?Re(gt(n),{month:"short",day:"numeric",timeZone:Ce},e):n}function Ec(n,e={},t){if(!/^\d{4}-\d{2}/.test(n))return n;let r=e.year??!e.short;return Re(gt(`${n.slice(0,7)}-01`),{month:e.short?"short":"long",...r?{year:e.short?"2-digit":"numeric"}:{},timeZone:Ce},t)}var Mc=(n,e="short",t)=>Re(Date.UTC(1970,0,4+n),{weekday:e,timeZone:Ce},t),zc=(n,e)=>Re(Date.UTC(1970,0,1,0,Math.round(n)),{hour:"numeric",minute:"2-digit",timeZone:Ce},e),Nc=/(?<![\w-])(\d{4}-\d{2}-\d{2})(?![\w-]|:)/g;function pr(n,e){return n.includes("-")?n.replace(Nc,t=>Ae(t,e)):n}var Fn=n=>n.charAt(0).toUpperCase()+n.slice(1),hi=n=>/^.\p{Lu}/u.test(n)?n:n.charAt(0).toLowerCase()+n.slice(1),gi=(n,e="and")=>n.length>1?`${n.slice(0,-1).join(", ")} ${e} ${n.at(-1)}`:n[0]??"";function Ic(n,e){return{...e,kind:n,edges:e.edges??{}}}function hr(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??ee()):!r.retired.includes(o)}function C(n,e){if(n?.label)return n.label(e);let t=e.label;return typeof t=="string"&&t.length>0?t:e.id}function Tc(n){return n.title??V(n.name)}function V(n){let e=n.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").trim().toLowerCase();return Fn(e.replace(/\b[a-z]+\b/g,t=>mi.has(t)?t.toUpperCase():t.endsWith("s")&&mi.has(t.slice(0,-1))?`${t.slice(0,-1).toUpperCase()}s`:t))}var mi=new Set("id url uri api ip ioc cve cvss cwe cpe sku vat iban isbn pdf csv json html css sla kpi roi faq ssn ein vin gps sms crm erp seo utm ui ux ai dns ssl tls http https sql uuid mfa sso cto ceo cfo coo rsvp eta".split(" "));function jc(n,e,t){let r=n.tryDefinition(e);return`${me(t)} ${t===1?H(r,e):se(n,e).toLowerCase()}`}function se(n,e){return n.tryDefinition(e)?.plural??`${V(e).toLowerCase()}s`}function Dc(n,e){return Fn(se(n,e))}function Fc(n,e){let t=se(n,e);return`All ${/^[A-Z][a-z]/.test(t)?t.charAt(0).toLowerCase()+t.slice(1):t}`}function mt(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":V(e))}var Lc=/^(u[nt]i|use|usu|uti|ubiq|eu|ewe|one|once)/,Zc=/^(hour|honest|hono[ur]r?|heir)/;function yi(n){let e=V(n).toLowerCase();return Zc.test(e)?"an":Lc.test(e)?"a":/^[aeiou]/.test(e)?"an":"a"}function an(n){return`${yi(n)} ${V(n).toLowerCase()}`}function H(n,e){return n?.noun??V(e).toLowerCase()}function yr(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 br(n,e="|"){return n.map(t=>Sr(t)).join(e)}function vi(n,e){return typeof e=="bigint"?e.toString():e}var mr=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 xi(n){return new mr(n)}function wi(n){return n==null}function vr(n){let e=n.startsWith("^")?1:0,t=n.endsWith("$")?n.length-1:n.length;return n.slice(e,t)}function ki(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 bi=Symbol("evaluating");function Si(n,e,t){let r;Object.defineProperty(n,e,{get(){if(r!==bi)return r===void 0&&(r=bi,r=t()),r},set(o){Object.defineProperty(n,e,{value:o})},configurable:!0})}function bt(n,e,t){Object.defineProperty(n,e,{value:t,writable:!0,enumerable:!0,configurable:!0})}function $i(n){let e=Object.getOwnPropertyDescriptor(n,"shape");return e?.get?e.get.raw:e?.value}function xr(n){return $i(n._zod.def)??n._zod.def.shape}function Ri(n,e,t){Object.defineProperty(n,e,{get(){let r=t();return bt(this,e,r),r},enumerable:!0,configurable:!0})}function Ai(n,e,t){e in n?bt(n,e,t):n[e]=t}function Cc(n,e,t,r){let o=xr(e);for(let i of t){let s=Object.getOwnPropertyDescriptor(o,i);s.enumerable&&(s.get?Ri(n,i,()=>{let a=e._zod.def.shape[i];return r?r(a,i):a}):Ai(n,i,r?r(s.value,i):s.value))}}function Gc(n,e){for(let t of Reflect.ownKeys(e)){let r=Object.getOwnPropertyDescriptor(e,t);r.enumerable&&(r.get?Ri(n,t,()=>e[t]):Ai(n,t,r.value))}}function _i(...n){let e={};for(let t of n){let r=Object.getOwnPropertyDescriptors(t);Object.assign(e,r)}return Object.defineProperties({},e)}var wr="captureStackTrace"in Error?Error.captureStackTrace:(...n)=>{};function yt(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function kr(n){if(yt(n)===!1)return!1;let e=n.constructor;if(e===void 0||typeof e!="function")return!0;let t=e.prototype;return!(yt(t)===!1||Object.prototype.hasOwnProperty.call(t,"isPrototypeOf")===!1)}var Oi=new Set(["string","number","symbol"]);function Zn(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function dn(n,e,t){let r=new n._zod.constr(e??n._zod.def);return(!e||t?.parent)&&(r._zod.parent=n),r}function N(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 Sr(n){return typeof n=="bigint"?n.toString()+"n":typeof n=="string"?`"${n}"`:`${n}`}function Pi(n){return Object.keys(n).filter(e=>n[e]._zod.optin!==void 0&&n[e]._zod.optout==="optional")}var Ei={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 Mi(n,e){if(!kr(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=xr(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 dn(n,_i(n._zod.def,{shape:Kc(n,e)}))}function Kc(n,e){let t={};return Cc(t,n,Reflect.ownKeys(xr(n))),Gc(t,e),t}function ye(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 zi(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 Oe(n,e){return e.map(t=>{var r;return(r=t).path??(r.path=[]),t.path.unshift(n),t})}function Ln(n){return typeof n=="string"?n:n?.message}function $r(n,e,t){var r;for(let o=e;o<n.length;o++)(r=n[o]).schema??(r.schema=t)}function be(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:Ln(n.inst?._zod.def?.error?.(n))??Ln(i?.(n))??Ln(e?.error?.(n))??Ln(t.customError?.(n))??Ln(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 Vc=/[\uD800-\uDBFF]/;function Rr(n){let e=n.length;if(!Vc.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 Ar(n){return Array.isArray(n)?"array":typeof n=="string"?"string":"unknown"}function Ni(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 Cn(...n){let[e,t,r]=n;return typeof e=="string"?{message:e,code:"custom",input:t,inst:r}:{...e}}function Ii(n,e){for(let t in e){let r=Object.getOwnPropertyDescriptor(e,t);r.get?Object.defineProperty(n,t,{...r,enumerable:!1}):Bc(n,t,r.value)}}function Ge(n,e,t,r=!0){return Object.defineProperty(n,e,{configurable:!0,writable:!0,enumerable:r,value:t}),t}function _r(n,e,t){return Ge(n,e,t,!1)}function Bc(n,e,t){Object.defineProperty(n,e,{configurable:!0,get(){return this==null?t:Ge(this,e,t.bind(this))},set(r){Ge(this,e,r)}})}function Uc(n,e){let t=Object.getPrototypeOf(n);return e in t?void 0:t}var gr,_e=!1,Wc={configurable:!0,get(){_e=!0}};function J(n,e,t){let r=Object.getPrototypeOf(n._zod);if(e in r&&gr!==n._zod){gr=void 0;return}gr=n._zod,Object.defineProperty(r,e,{configurable:!0,get(){Object.defineProperty(this,e,Wc);let o=_e;_e=!1;try{let i=t(this);return _e?delete this[e]:Object.defineProperty(this,e,{configurable:!0,writable:!0,value:i}),_e=_e||o,i}catch(i){throw delete this[e],_e=_e||o,i}},set(o){Object.defineProperty(this,e,{configurable:!0,writable:!0,value:o})}})}function Ti(n,e,t,r){let o=Uc(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 ji;var Or={value:void 0,enumerable:!1},Di="captureStackTrace"in Error?Error:null;function qc(n){let e=Di;if(e){let t=e.stackTraceLimit;if(typeof t=="number"){try{e.stackTraceLimit=0}catch{return Di=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,f){if(u._zod){if(u._zod.traits.has(n))return}else{Or.value=new i(f);try{Object.defineProperty(u,"_zod",Or)}finally{Or.value=void 0}}if(u._zod.traits.add(n),e(u,f),a){let g=Object.getPrototypeOf(u),x=u._zod.constr.prototype,m=g;for(;m&&m!==x;)m=Object.getPrototypeOf(m);let k=m??g;a.has(k)||(a.add(k),Ii(k,s))}let h=p.prototype;for(let g in h)Object.prototype.hasOwnProperty.call(h,g)&&(g in u||(u[g]=h[g].bind(u)))}let l=r?.Parent??Object;class c extends l{}Object.defineProperty(c,"name",{value:n});function p(u){let f=r?.Parent?qc(c):this;d(f,u);let h=f._zod.deferred;if(h){for(let x of h)x();f._zod.deferred=void 0}let g=globalThis.__zod_globalConfig?.postProcessor;return g&&g(f),f}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 xe=class extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}};(ji=globalThis).__zod_globalConfig??(ji.__zod_globalConfig={});var cn=globalThis.__zod_globalConfig;function ne(n){return n&&Object.assign(cn,n),cn}function Hc(){let n=this._zod;return n.message??(n.message=JSON.stringify(n.def,vi,2)),n.message}function Jc(n){this._zod.message=n}var Yc={get:Hc,set:Jc,enumerable:!0,configurable:!0},Er={value:void 0,enumerable:!1},Fi=new WeakSet([Object.prototype,Error.prototype]),Li=(n,e)=>{n.name="$ZodError",Er.value=e,Object.defineProperty(n,"issues",Er),Er.value=void 0,Object.defineProperty(n,"message",Yc);let t=Object.getPrototypeOf(n);Fi.has(t)||(Fi.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})}}))},lh=O("$ZodError",Li),Gn=O("$ZodError",Li,void 0,{Parent:Error});var Qc=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 xe;if(a.issues.length){let d=new(i?.Err??n)(a.issues.map(l=>be(l,s,ne())));throw wr(d,i?.callee??e),d}return a.value};return e},Mr=Qc(Gn),eu=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(l=>be(l,s,ne())));throw wr(d,i?.callee??e),d}return a.value};return e},zr=eu(Gn),nu=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 xe;return i.issues.length?Zi(n,i.issues,o):{success:!0,data:i.value}},Nr=nu(Gn);function Zi(n,e,t){let r;return{success:!1,get error(){return r||(r=new n(e.map(o=>be(o,t,ne()))),e=void 0,t=void 0),r},set error(o){r=o,e=void 0,t=void 0}}}var tu=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?Zi(n,i.issues,o):{success:!0,data:i.value}},Ir=tu(Gn);var Ci=/^(?:[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 Gi=/^https?$/;var Ki=/^[\s\S]{0,}$/;var Tr=/^-?\d+(?:\.\d+)?$/,Vi=/^(?:true|false)$/i,Bi=/^null$/i;var te=O("$ZodCheck",(n,e)=>{var t;n._zod??(n._zod={}),n._zod.def=e,(t=n._zod).onattach??(t.onattach=[])});var Ui=n=>{let e=n.value;return!wi(e)&&e.length!==void 0},vt={number:"number",bigint:"bigint",object:"date"},Wi=O("$ZodCheckLessThan",(n,e)=>{te.init(n,e);let t=vt[typeof e.value];n._zod.check=r=>{(e.inclusive?r.value<=e.value:r.value<e.value)||r.issues.push({origin:vt[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})}}),qi=O("$ZodCheckGreaterThan",(n,e)=>{te.init(n,e);let t=vt[typeof e.value];n._zod.check=r=>{(e.inclusive?r.value>=e.value:r.value>e.value)||r.issues.push({origin:vt[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})}}),Hi=O("$ZodCheckMultipleOf",(n,e)=>{te.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):ki(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})}}),Ji=O("$ZodCheckNumberFormat",(n,e)=>{te.init(n,e),e.format=e.format||"float64";let t=e.format?.includes("int"),r=t?"int":"number",[o,i]=Ei[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 Yi=O("$ZodCheckMaxLength",(n,e)=>{var t;te.init(n,e),(t=n._zod.def).when??(t.when=Ui),n._zod.check=r=>{let o=r.value,i=o.length;if((typeof o=="string"&&i>e.maximum?Rr(o):i)<=e.maximum)return;let a=Ar(o);r.issues.push({origin:a,code:"too_big",maximum:e.maximum,inclusive:!0,input:o,inst:n,continue:!e.abort})}}),Xi=O("$ZodCheckMinLength",(n,e)=>{var t;te.init(n,e),(t=n._zod.def).when??(t.when=Ui),n._zod.check=r=>{let o=r.value,i=o.length;if((typeof o=="string"&&i>=e.minimum&&i<e.minimum*2?Rr(o):i)>=e.minimum)return;let a=Ar(o);r.issues.push({origin:a,code:"too_small",minimum:e.minimum,inclusive:!0,input:o,inst:n,continue:!e.abort})}});var Dr=O("$ZodCheckStringFormat",(n,e)=>{var t,r;te.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=()=>{})}),Qi=O("$ZodCheckRegex",(n,e)=>{Dr.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 ns={major:4,minor:6,patch:5};var B=O("$ZodType",(n,e)=>{var t;n??(n={}),n._zod.def=e,n._zod.bag=n._zod.bag||{},n._zod.version=ns;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,l)=>{if(a.memo)return a;let c=ye(a),p;for(let u of d){if(u._zod.def.when){if(zi(a)||!u._zod.def.when(a))continue}else if(c)continue;let f=a.issues.length,h=u._zod.check(a);if(h instanceof Promise&&l?.async===!1)throw new xe;if(p||h instanceof Promise)p=(p??Promise.resolve()).then(async()=>{await h,a.issues.length!==f&&($r(a.issues,f,n),c||(c=ye(a,f)))});else{if(a.issues.length===f)continue;$r(a.issues,f,n),c||(c=ye(a,f))}}return p?p.then(()=>a):a},s=(a,d,l)=>{if(ye(a))return a.aborted=!0,a;let c=i(d,o,l);if(c instanceof Promise){if(l.async===!1)throw new xe;return c.then(p=>n._zod.parse(p,l))}return n._zod.parse(c,l)};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 l=n._zod.parse(a,d);if(l instanceof Promise){if(d.async===!1)throw new xe;return l.then(c=>i(c,o,d))}return i(l,o,d)}}},{get"~standard"(){return _r(this,"~standard",ou(this))},set"~standard"(n){Ge(this,"~standard",n)}}),as=(n,e)=>n.issues.length?{issues:n.issues.map(t=>be(t,e,ne()))}:{value:n.value};async function ru(n,e){let t={async:!0};return as(await n._zod.run({value:e,issues:[]},t),t)}function ou(n){return{validate:e=>{let t={async:!1};try{let r=n._zod.run({value:e,issues:[]},t);if(!(r instanceof Promise))return as(r,t)}catch{}return ru(n,e)},vendor:"zod",version:1}}var Fr=O("$ZodString",(n,e)=>{B.init(n,e),n._zod.pattern=e.pattern??Ki,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}}),kt=O("$ZodStringFormat",(n,e)=>{Dr.init(n,e),Fr.init(n,e)});var ds=O("$ZodEmail",(n,e)=>{e.pattern??(e.pattern=Ci),kt.init(n,e)}),cs=1,xt=2;function iu(n){try{return typeof URL<"u"&&typeof URL.canParse=="function"?URL.canParse(n):(new URL(n),!0)}catch{return!1}}function su(n,e){return!("normalize"in e)&&!("hostname"in e)&&!("protocol"in e)?iu(n)||xt:au(n,e)}function au(n,e){if(!e.normalize&&e.protocol?.source===Gi.source&&!/^https?:\/\//i.test(n))return cs;try{if(typeof URL<"u"){let t=URL;if(typeof t.parse=="function")return t.parse(n)??xt}return new URL(n)}catch{return xt}}var du=/[\t\n\r]/g;function ts(n){return n.replace(du,"")}function cu(n,e){return e.lastIndex=0,e.test(n.hostname)}function uu(n,e){return e.lastIndex=0,e.test(n.protocol.endsWith(":")?n.protocol.slice(0,-1):n.protocol)}var us=O("$ZodURL",(n,e)=>{kt.init(n,e),n._zod.check=t=>{try{let r=t.value.trim(),o=su(r,e);if(o===cs){t.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:t.value,inst:n,continue:!e.abort});return}if(o===xt){t.issues.push({code:"invalid_format",format:"url",input:t.value,inst:n,continue:!e.abort});return}if(o===!0){t.value=ts(r);return}e.hostname&&!cu(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&&!uu(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:ts(r);return}catch{t.issues.push({code:"invalid_format",format:"url",input:t.value,inst:n,continue:!e.abort})}}});var Lr=O("$ZodNumber",(n,e)=>{B.init(n,e),n._zod.pattern=Tr,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}}),ls=O("$ZodNumberFormat",(n,e)=>{Ji.init(n,e),Lr.init(n,e)}),fs=O("$ZodBoolean",(n,e)=>{B.init(n,e),n._zod.pattern=Vi,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 ps=O("$ZodNull",(n,e)=>{B.init(n,e),n._zod.pattern=Bi,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 hs=O("$ZodUnknown",(n,e)=>{B.init(n,e),n._zod.parse=t=>t}),gs=O("$ZodNever",(n,e)=>{B.init(n,e),n._zod.parse=(t,r)=>(t.issues.push({expected:"never",code:"invalid_type",input:t.value,inst:n}),t)});function rs(n,e,t){n.issues.length&&e.issues.push(...Oe(t,n.issues)),e.value[t]=n.value}var ms=O("$ZodArray",(n,e)=>{B.init(n,e);let t=cn.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 l=i[d],c=e.element._zod.run({value:l,issues:[]},o);if(c instanceof Promise)s.push(c.then(p=>rs(p,r,d)));else if(rs(c,r,d),a&&c.issues.length!==0&&ye(c))break}return s.length?Promise.all(s).then(()=>r):r}});function wt(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(...Oe(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 lu=[];function fu(n){let e=Object.keys(n.shape),t=Object.getOwnPropertySymbols(n.shape),r=t.length?t:lu,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=Pi(n.shape);return{...n,allKeys:o,symbolKeys:r,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(i)}}function pu(n,e,t,r,o,i,s){let a=[],d=o.keySet,l=o.catchall._zod,c=l.def.type,p=l.optin,u=l.optout,f=0;for(let h in e){if(s&&t.issues.length!==f){if(ye(t,f))break;f=t.issues.length}if(d.has(h))continue;if(h==="__proto__"){c==="never"&&a.push(h);continue}if(c==="never"){a.push(h);continue}let g=l.run({value:e[h],issues:[]},r);g instanceof Promise?n.push(g.then(x=>wt(x,t,h,e,p,u))):wt(g,t,h,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 ys=O("$ZodObject",(n,e)=>{B.init(n,e);let t=Object.getOwnPropertyDescriptor(e,"shape"),r=t?.get?t.get.raw:e.shape??{};if(r){let l=()=>{let c={...r};return Object.defineProperty(e,"shape",{value:c}),l.raw=c,c};l.raw=r,Object.defineProperty(e,"shape",{get:l})}let o=xi(()=>fu(e));J(n,"propValues",l=>{let c=l.def.shape,p={};for(let u in c){let f=c[u]._zod;if(f.values){Object.prototype.hasOwnProperty.call(p,u)||bt(p,u,new Set);for(let h of f.values)p[u].add(h);f.optin!==void 0&&p[u].add(void 0)}}return p});let i=yt,s=e.catchall,a,d=cn.memoizer;d?.attach(n),n._zod.parse=(l,c)=>{a??(a=o.value);let p=l.value;if(!i(p))return l.issues.push({expected:"object",code:"invalid_type",input:p,inst:n}),l;l.value=d?d.alloc(n,l,{},c):{};let u=[],f=a.shape,h=c?.abortEarly,g=l.issues.length;for(let x of a.allKeys){if(h&&l.issues.length!==g){if(ye(l,g))break;g=l.issues.length}if(x==="__proto__")continue;let m=f[x],k=m._zod.optin,A=m._zod.optout,S=m._zod.run({value:p[x],issues:[]},c);S instanceof Promise?u.push(S.then(_=>wt(_,l,x,p,k,A))):wt(S,l,x,p,k,A)}return s?pu(u,p,l,c,o.value,n,h===!0):u.length?Promise.all(u).then(()=>l):l}});function os(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=>!ye(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=>be(s,r,ne())))}),e)}var bs=O("$ZodUnion",(n,e)=>{B.init(n,e),J(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),J(n,"optout",r=>r.def.options.some(o=>o._zod.optout==="optional")?"optional":void 0),J(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)))}),J(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=>vr(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=>os(a,r,n,o)):os(s,r,n,o)}});var vs=O("$ZodRecord",(n,e)=>{B.init(n,e);let t=cn.memoizer;t?.attach(n),n._zod.parse=(r,o)=>{let i=r.value;if(!kr(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(h=>be(h,o,ne())),input:c,path:[c],inst:n});continue}let u=p.value;if(u==="__proto__")continue;let f=e.valueType._zod.run({value:i[c],issues:[]},o);f instanceof Promise?s.push(f.then(h=>{h.issues.length&&r.issues.push(...Oe(c,h.issues)),r.value[u]=h.value})):(f.issues.length&&r.issues.push(...Oe(c,f.issues)),r.value[u]=f.value)}let l;for(let c in i)if(!d.has(c))if(e.mode==="loose"){if(c==="__proto__")continue;r.value[c]=i[c]}else l=l??[],l.push(c);l&&l.length>0&&r.issues.push({code:"unrecognized_keys",input:i,inst:n,keys:l,continue:!0})}else{r.value=t?t.alloc(n,r,{},o):{};let d;for(let l of Reflect.ownKeys(i)){if(l==="__proto__"||!Object.prototype.propertyIsEnumerable.call(i,l))continue;let c=e.keyType._zod.run({value:l,issues:[]},o);if(c instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(typeof l=="string"&&Tr.test(l)&&c.issues.length){let h=e.keyType._zod.run({value:Number(l),issues:[]},o);if(h instanceof Promise)throw new Error("Async schemas not supported in object keys currently");h.issues.length===0&&(c=h)}if(c.issues.length){e.mode==="loose"?r.value[l]=i[l]:a?(d=d??[],d.push(l)):r.issues.push({code:"invalid_key",origin:"record",issues:c.issues.map(h=>be(h,o,ne())),input:l,path:[l],inst:n});continue}let u=c.value;if(u==="__proto__")continue;let f=e.valueType._zod.run({value:i[l],issues:[]},o);f instanceof Promise?s.push(f.then(h=>{h.issues.length&&r.issues.push(...Oe(l,h.issues)),r.value[u]=h.value})):(f.issues.length&&r.issues.push(...Oe(l,f.issues)),r.value[u]=f.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 xs=O("$ZodEnum",(n,e)=>{B.init(n,e);let t=yr(e.entries),r=new Set(t);n._zod.values=r,J(n,"pattern",o=>{let i=yr(o.def.entries).filter(s=>Oi.has(typeof s));return new RegExp(i.length?`^(${i.map(s=>Zn(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}}),ws=O("$ZodLiteral",(n,e)=>{B.init(n,e);let t=new Set(e.values);n._zod.values=t,J(n,"pattern",r=>{let o=r.def.values;return new RegExp(o.length?`^(${o.map(i=>typeof i=="string"?Zn(i):i?Zn(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 is(n,e){return n.value=e.issues.length?void 0:e.value,n}var ks=O("$ZodOptional",(n,e)=>{B.init(n,e),J(n,"optin",t=>t.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),n._zod.optout="optional",J(n,"values",t=>{let r=t.def.innerType._zod.values;return r?new Set([...r,void 0]):void 0}),J(n,"pattern",t=>{let r=t.def.innerType._zod.pattern;return r?new RegExp(`^(${vr(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=>is(t,i)):is(t,o)}return e.innerType._zod.run(t,r)}});var Ss=O("$ZodLazy",(n,e)=>{B.init(n,e),Si(n._zod,"innerType",()=>{let t=e;return t._cachedInner||(t._cachedInner=e.getter()),t._cachedInner}),J(n,"pattern",t=>t.innerType?._zod?.pattern),J(n,"propValues",t=>t.innerType?._zod?.propValues),J(n,"optin",t=>t.innerType?._zod?.optin??void 0),J(n,"optout",t=>t.innerType?._zod?.optout??void 0),n._zod.parse=(t,r)=>n._zod.innerType._zod.run(t,r)}),$s=O("$ZodCustom",(n,e)=>{te.init(n,e),B.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=>ss(i,t,r,n));ss(o,t,r,n)}});function ss(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(Cn(o))}}var hu=()=>{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=Ni(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 ${Sr(i.values[0])}`:`Invalid option: expected one of ${br(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":""}: ${br(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 Rs(){return{localeError:hu()}}var As;var Zr=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 _s(){return new Zr}(As=globalThis).__zod_globalRegistry??(As.__zod_globalRegistry=_s());var un=globalThis.__zod_globalRegistry;function Os(n){return n.checks&&(n.checks=[...n.checks]),n}function Ps(n,e){return new n(Os({type:"string",...N(e)}))}function Es(n,e){return new n({type:"string",format:"email",check:"string_format",abort:!1,...N(e)})}function Ms(n,e){return new n({type:"string",format:"url",check:"string_format",abort:!1,...N(e)})}function zs(n,e){return new n(Os({type:"number",checks:[],...N(e)}))}function Ns(n,e){return new n({type:"number",check:"number_format",abort:!1,format:"safeint",...N(e)})}function Is(n,e){return new n({type:"boolean",...N(e)})}function Ts(n,e){return new n({type:"null",...N(e)})}function js(n){return new n({type:"unknown"})}function Ds(n,e){return new n({type:"never",...N(e)})}function Fs(n,e){return new Wi({check:"less_than",...N(e),value:n,inclusive:!0})}function Ls(n,e){return new qi({check:"greater_than",...N(e),value:n,inclusive:!0})}function bu(n,e){return new Hi({check:"multiple_of",...N(e),value:n})}function Cr(n,e){return new Yi({check:"max_length",...N(e),maximum:n})}function Kn(n,e){return new Xi({check:"min_length",...N(e),minimum:n})}function Vn(n,e){return new Qi({check:"string_format",format:"regex",...N(e),pattern:n})}function Zs(n,e,t){return new n({type:"custom",check:"custom",fn:e,...N(t)})}function Cs(n,e){let t=vu(r=>(r.addIssue=o=>{if(typeof o=="string")r.issues.push(Cn(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(Cn(i))}},n(r.value,r)),e);return t}function vu(n,e){let t=new te({check:"custom",...N(e)});return t._zod.check=n,t}function Gs(n){let e=new te({check:"describe"});return e._zod.onattach=[t=>{let r=un.get(t)??{};un.add(t,{...r,description:n})}],e._zod.check=()=>{},e}var Y=O("ZodMiniType",(n,e)=>{if(!n._zod)throw new Error("Uninitialized schema in ZodMiniType.");B.init(n,e),n.def=e,n.type=e.type},{get with(){return this.check},set with(n){Ge(this,"with",n)},parse(n,e){return Mr(this,n,e,{callee:this.parse})},parseAsync(n,e){return zr(this,n,e,{callee:this.parseAsync})},safeParse(n,e){return Nr(this,n,e)},safeParseAsync(n,e){return Ir(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 dn(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)}}),Vs=O("ZodMiniString",(n,e)=>{Fr.init(n,e),Y.init(n,e)});function L(n){return Ps(Vs,n)}var Bs=O("ZodMiniStringFormat",(n,e)=>{kt.init(n,e),Vs.init(n,e)}),ku=O("ZodMiniEmail",(n,e)=>{ds.init(n,e),Bs.init(n,e)});function py(n){return Es(ku,n)}var Su=O("ZodMiniURL",(n,e)=>{us.init(n,e),Bs.init(n,e)});function hy(n){return Ms(Su,n)}var Us=O("ZodMiniNumber",(n,e)=>{Lr.init(n,e),Y.init(n,e)});function Ke(n){return zs(Us,n)}var $u=O("ZodMiniNumberFormat",(n,e)=>{ls.init(n,e),Us.init(n,e)});function gy(n){return Ns($u,n)}var Ru=O("ZodMiniBoolean",(n,e)=>{fs.init(n,e),Y.init(n,e)});function my(n){return Is(Ru,n)}var Au=O("ZodMiniNull",(n,e)=>{ps.init(n,e),Y.init(n,e)});function yy(n){return Ts(Au,n)}var _u=O("ZodMiniUnknown",(n,e)=>{hs.init(n,e),Y.init(n,e)});function Gr(){return js(_u)}var Ou=O("ZodMiniNever",(n,e)=>{gs.init(n,e),Y.init(n,e)});function Pu(n){return Ds(Ou,n)}var Eu=O("ZodMiniArray",(n,e)=>{ms.init(n,e),Y.init(n,e)});function by(n,e){return new Eu({type:"array",element:n,...N(e)})}var Kr=O("ZodMiniObject",(n,e)=>{ys.init(n,e),Y.init(n,e),Ti(n,"shape",t=>t._zod.def.shape,!1)});function Pe(n,e){let t={type:"object",shape:n??{},...N(e)};return new Kr(t)}function ln(n,e){return new Kr({type:"object",shape:n,catchall:Pu(),...N(e)})}function vy(n,e){return new Kr({type:"object",shape:n,catchall:Gr(),...N(e)})}function Ws(n,e){return Mi(n,e)}var Mu=O("ZodMiniUnion",(n,e)=>{bs.init(n,e),Y.init(n,e)});function xy(n,e){return new Mu({type:"union",options:n,...N(e)})}var Ks=O("ZodMiniRecord",(n,e)=>{vs.init(n,e),Y.init(n,e)});function wy(n,e,t){return!e||!e._zod?new Ks({type:"record",keyType:L(),valueType:n,...N(e)}):new Ks({type:"record",keyType:n,valueType:e,...N(t)})}var zu=O("ZodMiniEnum",(n,e)=>{xs.init(n,e),Y.init(n,e),n.options=[...n._zod.values]});function qs(n,e){let t=Array.isArray(n)?Object.fromEntries(n.map(r=>[r,r])):n;return new zu({type:"enum",entries:t,...N(e)})}var Nu=O("ZodMiniLiteral",(n,e)=>{ws.init(n,e),Y.init(n,e)});function Hs(n,e){return new Nu({type:"literal",values:Array.isArray(n)?n:[n],...N(e)})}var Iu=O("ZodMiniOptional",(n,e)=>{ks.init(n,e),Y.init(n,e)});function X(n){return new Iu({type:"optional",innerType:n})}var Tu=O("ZodMiniLazy",(n,e)=>{Ss.init(n,e),Y.init(n,e)});function ky(n){return new Tu({type:"lazy",getter:n})}var ju=O("ZodMiniCustom",(n,e)=>{$s.init(n,e),Y.init(n,e)});function St(n,e={}){return Zs(ju,n,e)}function Sy(n,e){return Cs(n,e)}var $y=Gs;ne().localeError||ne(Rs());var j=n=>typeof n=="object"&&n!==null?n._zod?.def:void 0,Du=n=>{if(typeof n!="object"||n===null||!("_zod"in n))return;let e=un.get(n)?.description;return typeof e=="string"?e:void 0};var Fu=(n,e)=>n?.src?.(e)??e,$t=n=>typeof n=="string"&&n.length<2049&&/^(?![^/?#]*:|\/\/)(?!(?:.*\/)?\.\.?(?:[/?#]|$))(?!.*%2e)[^\\\s]+$/i.test(n),Vr=(n,e=1)=>e>0&&n===void 0||Number.isInteger(n)&&n>=e;function Br(n){let e=n??{};return $t(e.href)&&typeof e.name=="string"&&/^.{1,255}$/s.test(e.name)&&/^[\w.+-]{1,60}\/[\w.+-]{1,60}$/.test(e.type)&&Vr(e.bytes,0)&&Vr(e.width)&&Vr(e.height)&&(e.caption===void 0||typeof e.caption=="string"&&e.caption.length<501)&&(e.poster===void 0||$t(e.poster))&&(e.captions===void 0||$t(e.captions))&&(e.duration===void 0||typeof e.duration=="number"&&Number.isFinite(e.duration)&&e.duration>0)&&(e.at===void 0||Js(e.at)!==void 0)}function Js(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 Ys=n=>n.type.startsWith("image/"),Xs=n=>n.type.startsWith("video/");function Lu(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 Zu=(n,e)=>e==="image"?Ys(n):e==="video"?Xs(n):!0,Cu=n=>`${n==="image"?"an image":n==="video"?"a video":"a file"} the host stored, at a path on this host`,Bn=n=>(Array.isArray(n)?n:[n]).filter(Br),Qs=Symbol.for("@graview/core:file"),Gu=(n,e)=>(Object.defineProperty(j(n),Qs,{value:e,enumerable:!0}),n);function ea(n){let e=j(n);return e?.[Qs]??(e?.innerType?ea(e.innerType):void 0)}var Ku=()=>({href:L(),name:L(),type:L(),bytes:Ke(),width:X(Ke()),height:X(Ke()),caption:X(L()),poster:X(L()),duration:X(Ke()),captions:X(L()),at:X(L())});function Rb(n){return Gu(Pe(Ku()).check(St(e=>Br(e)&&Zu(e,n),Cu(n))),n)}var Rt=/^(?:https?:\/\/[^\s<>"'`\\]+|@?[A-Za-z0-9][\w.~-]*(?:\/[\w.~-]+)*)$/,At=n=>typeof n=="string"&&n.length<501&&Rt.test(n);var na=n=>typeof n=="object"&&n!==null?n._zod?.def:void 0,Vu=/^@(?:https?:\/\/[^\s<>"'`\\#?]+|[A-Za-z0-9][\w.~-]*(?:\/[\w.~-]+)*)\/[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;function ta(n){if(typeof n!="string"||!n.startsWith("@")||!Vu.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 At(o)?{address:o,kind:r}:void 0}var Bu=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*:\S[^\n]{0,199}$/,Uu=n=>`${n.kind}:${n.id}`;function ra(n,e){if(typeof n!="string"||!Bu.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 Wu(n,e){return(Array.isArray(n)?n:n==null?[]:[n]).flatMap(r=>{let o=ra(r,e);return o?[o]:[]})}var oa=Symbol.for("@graview/core:linked"),Pb=(n,e)=>(Object.defineProperty(na(n),oa,{value:e,enumerable:!0}),n);function Un(n){let e=na(n);return e?e[oa]??Un(e.innerType):void 0}function qu(n){let e=n?.fields?.shape??{},t=new Map;for(let[r,o]of Object.entries(e)){let i=Un(o);i&&t.set(r,i)}return t}function Hu(n){if(n.to==="*"||n.to.length===0)return;let e=n.to.map(ta);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 Ju=n=>n.to!=="*"&&n.to.some(e=>typeof e=="string"&&e.startsWith("@"));function Eb(n){return Object.fromEntries(Object.entries(n??{}).filter(([,e])=>!Ju(e)))}function Mb(n){let e=new Map;for(let[t,r]of Object.entries(n??{})){let o=Hu(r);o&&e.set(t,o)}return e}var Ur=new WeakMap;function Yu(n,e){e?Ur.set(n,e):Ur.delete(n)}var ia=n=>Ur.get(n);var _t=["sun","mon","tue","wed","thu","fri","sat"],Xu=["day","week","month","year"],pn=n=>`${n}Repeat`,qn=n=>n.endsWith("Repeat")&&n.length>6?n.slice(0,-6):void 0,da=/^\d{4}-\d{2}-\d{2}$/,ca=Symbol.for("@graview/core:repeat");function Ot(n){let e=j(n);return!!e&&(e[ca]===1||Ot(e.innerType))}var Qu=n=>(Object.defineProperty(j(n),ca,{value:1,enumerable:!0}),n),Wr=(n,e,t)=>n===void 0||Number.isInteger(n)&&n>=e&&n<=t,sa=(n,e)=>n===void 0||Array.isArray(n)&&n.length<=e&&n.every(t=>typeof t=="string"&&da.test(t)),el=["every","interval","on","until","count","except","continues"],ua=n=>hn(n)&&Object.keys(n).every(e=>el.includes(e))&&Wr(n.interval,1,99)&&Wr(n.count,1,1e3)&&sa(n.until===void 0?void 0:[n.until],1)&&sa(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"?_t.includes(e):n.every==="month"&&e!==0&&Wr(e,-1,31))),Ib=()=>Qu(Gr().check(St(n=>n===null||ua(n),"how a date repeats, or null"))),Wn=n=>Date.UTC(+n.slice(0,4),+n.slice(5,7)-1,+n.slice(8,10)),la=n=>new Date(n).toISOString().slice(0,10),qr=(n,e)=>la(Wn(n)+e*864e5),aa=(n,e,t)=>{let r=new Date(Date.UTC(n,e+1,0)).getUTCDate();return la(Date.UTC(n,e,t<0||t>r?r:t))},hn=n=>typeof n=="object"&&n!==null&&Xu.includes(n.every);function fn(n,e,t={}){let r=n.slice(0,10),o=n.slice(10),i=[];if(!da.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,l=[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),f=+r.slice(5,7)-1,h=+r.slice(8,10),g=qr(r,-new Date(Wn(r)).getUTCDay()),x=(e.on?.length?e.on:[a==="week"?_t[new Date(Wn(r)).getUTCDay()]:h]).map(_=>typeof _=="string"?_t.indexOf(_):_),m=a==="day"?1:a==="week"?7:0,k=(+d.slice(0,4)-u)*12+(+d.slice(5,7)-1-f),A=e.count?0:Math.max(0,Math.floor((m?(Wn(d)-Wn(m===7?g:r))/864e5/m:a==="month"?k:k/12)/s)-1),S=0;for(let _=0;_<5e4&&i.length<c;_++,A++){let y=A*s,b=a==="day"?[qr(r,y)]:a==="week"?x.map(w=>qr(g,y*7+w)):a==="month"?x.map(w=>aa(u,f+y,w)):[aa(u+y,f,h)];for(let w of[...new Set(b)].sort())if(!(w<r)&&(l&&w>l||e.count&&S>=e.count||(S++,w>=d&&!p.has(w)&&i.push(w+o),i.length>=c)))return i}return i}function fa(n,e,t){if(!hn(e)||typeof n!="string")return n;let r=fn(n,e,{from:t,limit:1})[0];if(r)return r;let o=e.until||e.count?fn(n,e):[];return o[o.length-1]??n}function nl(n,e,t){let r=n[e],o=n[pn(e)];return typeof r=="string"&&hn(o)?fa(r,o,t):r}var Pt=["human","visitor","agent","rule","system"],tl=new Set(Pt);function Hr(n){return tl.has(n?.kind)?n.kind:"system"}function Hn(n,e){if(n.onBehalfOf){let{onBehalfOf:s,...a}=n;return`${Hn(a,e)}, for ${Hn(s,e)}`}let t=Hr(n);if(n.id===void 0)return n.name??(t==="agent"?"an agent":t==="visitor"?"a visitor":t);let r=e.graph.getNode(n.id);if(r)return C(e.schema.tryDefinition(r.kind),r);let o=e.seats?.find(s=>s.principal.id===n.id);if(o)return o.label;let i=e.people?.find(s=>s.id===n.id&&(s.kind===void 0||s.kind===n.kind));return i?i.name:n.name?n.name:/(^|:)migration$/.test(n.id)?"the upgrade":n.id.startsWith("form:")?"a visitor via a form":/[:_/]/.test(n.id)?{human:"somebody",visitor:"a visitor",agent:"an agent",rule:"a rule",system:"the system"}[t]:n.id}var gn="$archived",Ve=n=>n?.[gn]===!0,Zb=(n,e=!1)=>e==="all"||Ve(n)===e,Jr=n=>n===!0||n==="true"?!0:n==="all"?"all":!1,Jn="$leftAlone",Et=new Set([gn,Jn]);var de=class extends Error{constructor(t,r){super(r?`${t}
|
|
2
|
-
\u2192 ${r}`:t);this.hint=r;this.name="SchemaError"}};function rl(n,e){let t=n,r=new Map;for(let a of t){if(r.has(a.kind))throw new de(`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,l]of Object.entries(a.edges)){if(l.to!=="*"){for(let p of l.to)if(!r.has(p))throw new de(`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:l})}let i=new Map;for(let[a,{from:d,decl:l}]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:l.cardinality??"many",...l.description===void 0?{}:{description:l.description}})}let s=new Map;for(let a of t)s.set(a.kind,Ws(a.fields,{id:L().check(Kn(1)),kind:Hs(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 de(`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,l){let c=r.get(d)?.edges[a];return c?c.to==="*"||c.to.includes(l):!1},parseNode(a){let d=a?.kind;if(typeof d!="string")throw new de("Node is missing a `kind`");let l=s.get(d);if(!l)throw new de(`Unknown node kind "${d}"`,`Declared kinds: ${[...r.keys()].join(", ")}`);let c={},p={};for(let[f,h]of Object.entries(a))Et.has(f)?h===!0&&(p[f]=!0):c[f]=h;let u=l.parse(c);return Object.keys(p).length>0?{...u,...p}:u},__node:void 0}}var Yr="0.1.55";var mn={snapshot:1,op:3},yn=class extends Error{constructor(t,r,o,i,s){super(s!==void 0?`This ${t} holds a ${s} that @graview ${Yr} does not know: upgrade the framework to read it.`:`This ${t} is in a newer format (${r}${i?`, written by @graview ${i}`:""}) than @graview ${Yr} reads (${o}). `+(t==="snapshot"?"Refold it from the log, or upgrade the framework.":"Upgrade the framework to read it."));this.what=t;this.found=r;this.supported=o;this.writtenBy=i;this.unknown=s;this.name="NewerFormatError"}},Xr=["add-node","remove-node","patch-node","add-edge","remove-edge","splice-text"],ol=new Set(Xr);function Qr(n){throw new yn("op",mn.op+1,mn.op,void 0,`primitive "${n?.op}"`)}var eo=new Set;function no(n){for(let e in n){let t=n[e]?.$type;if(t!==void 0&&!eo.has(t))throw new yn("op",mn.op+1,mn.op,void 0,`value type "${t}" in "${e}"`)}}function pa(n){for(let e of n.primitives)ol.has(e?.op)||Qr(e)}function z(n){return`${n.kind}\0${n.from}\0${n.to}`}var Yn={addedNodes:[],removedNodes:[],changedNodes:[],addedEdges:[],removedEdges:[],touched:[]};function ha(n){return n.addedNodes.length===0&&n.removedNodes.length===0&&n.changedNodes.length===0&&n.addedEdges.length===0&&n.removedEdges.length===0}function il(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 Ee(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 f=r.get(u.id);if(!f||f===u)continue;let h=il(u,f);h.length>0&&s.push({before:u,after:f,fields:h})}let a=new Map(n.edges.map(u=>[z(u),u])),d=new Map(e.edges.map(u=>[z(u),u])),l=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[...l,...c])p.add(u.from),p.add(u.to);return{addedNodes:o,removedNodes:i,changedNodes:s,addedEdges:l,removedEdges:c,touched:[...p].sort()}}function Me(n,e,t){let r=new Set(t.flatMap(i=>i.op==="patch-node"||i.op==="splice-text"?[i.id]:"node"in i?[i.node.id]:[i.edge.from,i.edge.to]));if(r.size===0)return Yn;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 Ee(o(n),o(e))}var Mt={idLength:200,dataLength:4096,sameKindPerPair:1};function ga({id:n,data:e}){if(n!==void 0&&!(typeof n=="string"&&n.length<=Mt.idLength&&/^[^\s\p{Cc}]+$/u.test(n)))return`A link's id is 1\u2013${Mt.idLength} characters with no space`;if(e!==void 0&&!(e&&typeof e=="object"&&!Array.isArray(e)&&JSON.stringify(e).length<=Mt.dataLength))return`A link's data is a JSON object of at most ${Mt.dataLength} characters`}function sl(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?V(String(t.path.at(-1))):null,o=t.message??"is not what the declaration allows";return r?`${r}: ${o}`:o}).join("; ")}var M=class extends Error{constructor(t,r){super(r?`${t}
|
|
3
|
-
${r}`:t);this.hint=r;this.name="GraphError"}},U=class extends M{constructor(t,r){super(r);this.id=t;this.name="MissingRecordError"}};function zt(n,e){try{n.parseNode(e);return}catch(t){if(t instanceof de)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 to="n\0",ro="e\0",Q=class n{constructor(e,t={}){this.schema=e;this.validate=t.validate??!0}nodes=new Map;edges=new Map;linkIds=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=Ee(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)}linkById(e){return this.edges.get(this.linkIds.get(e))}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=Me(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){let t=new Map([...this.lapsed,...this.ranks]);for(let o of[this.nodes,this.edges,this.linkIds,this.outIndex,this.inIndex,this.ranks,this.lapsed,this.counts,this.archived])o.clear();this.reordered=!1;for(let o of e.nodes)this.insertNode(o,!0);for(let o of e.edges)this.insertEdge(o,!0);let r=[...this.ranks.keys()];if(r.every((o,i)=>t.get(o)>(o[0]===r[i-1]?.[0]?t.get(r[i-1]):0))){for(let[o,i]of t)(this.ranks.has(o)?this.ranks:this.lapsed).set(o,i);for(;this.lapsed.size>4096;)this.lapsed.delete(this.lapsed.keys().next().value)}}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(to));this.nodes.clear();for(let[o,i]of t)this.nodes.set(o,i);let r=[...this.edges.entries()].sort(e(ro));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":no(e.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 U(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(to+o),this.outIndex.delete(o),this.inIndex.delete(o);return}case"patch-node":{let o=this.nodes.get(e.id);if(!o)throw new U(e.id,`Cannot patch missing node "${e.id}"`);no(e.after);let i={...o};for(let[a,d]of Object.entries(e.after))Fe(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[Ve(s)?"add":"delete"](e.id),s.kind!==o.kind&&(this.tally(o.kind,-1),this.tally(s.kind,1));return}case"splice-text":{let o=this.nodes.get(e.id);if(!o)throw new U(e.id,`Cannot splice the text of missing node "${e.id}"`);let i=o[e.field],s;try{typeof i=="string"&&e.field!=="id"&&e.field!=="kind"&&(s=ar(i,e))}catch{}if(s===void 0)throw new M(`Cannot splice ${e.id}.${e.field}: it does not hold ${JSON.stringify(e.removed)} at ${e.at}`,"A corrupt op: the text it was made against is not the text the log folds to.");let a={...o,[e.field]:s};this.nodes.set(e.id,t?a:this.checkPatch(o,a,[e.field]));return}case"add-edge":this.insertEdge(e.edge,t,r);return;case"remove-edge":{let o=e.edge.id===void 0?e.edge:this.linkById(e.edge.id);if(!o||!this.edges.has(z(o)))throw new U(e.edge.id??z(e.edge),`Cannot remove missing edge ${e.edge.id??z(e.edge)}`);this.deleteEdge(o);return}default:Qr(e)}}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"||Et.has(a))continue;let d=o[a];if(!d){delete t[a];continue}let l=d.safeParse(t[a]);l.success&&(l.data===void 0?delete t[a]:t[a]=l.data)}let i=zt(this.schema,t);if(i===void 0)return t;let s=zt(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 de)return t;{let r=e?.id??"?",o=e?.kind??"?",i=this.schema.tryDefinition(o),s=i&&e&&typeof e=="object"?C(i,e):r;return new M(`${s} does not match what ${o} declares`,sl(t))}}insertNode(e,t,r=!1){if(this.nodes.has(e.id))throw new M(`Duplicate node id "${e.id}"`);this.nodes.set(e.id,t?e:this.check(e)),Ve(e)&&this.archived.add(e.id),this.tally(e.kind,1),this.place(to+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 U(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 M(`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);if(!t&&(e.id!==void 0||e.data!==void 0)){let a=this.edges.get(s),d=ga(e)??(a&&e.id!==void 0&&a.id!==e.id?`A second "${e.kind}" link between two records is not allowed yet`:(this.linkIds.get(e.id)??s)!==s?`Link id "${e.id}" is already taken`:void 0);if(d)throw new M(d)}this.edges.has(s)||(this.edges.set(s,e),e.id!==void 0&&this.linkIds.set(e.id,s),this.place(ro+s,r),this.index(this.outIndex,e.from,s),this.index(this.inIndex,e.to,s))}deleteEdge(e){let t=z(e),r=this.edges.get(t)?.id;r!==void 0&&this.linkIds.delete(r),this.edges.delete(t),this.lapse(ro+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 Nt=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 al(n,e){return{...e,name:n}}var It=class extends Error{constructor(e){super(e),this.name="RuleBudgetError"}};function ma(n,e,t){try{return e().map(r=>r.status?r:{...r,status:"violated"})}catch(r){let o=r instanceof It,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 bn(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(...ma(u,()=>u.evaluate({graph:n,subject:void 0,context:r,...o}),void 0));let d=e.filter(u=>u.scope!=="graph"),l=new Map;for(let u of d){let f=u.scope.kind,h=l.get(f);h?h.push(u):l.set(f,[u])}for(let u of n.allNodes()){let f=n.schema.tryDefinition(u.kind),h=f?.requiresInvariant?.(u)??null;if(t.subjectFilter&&!t.subjectFilter(u,r))continue;if(h!==null&&!s.has(h)){if(i==="throw")throw new Nt(h,u.id);continue}let g=!hr(f,u,t.today);for(let x of l.get(u.kind)??[]){if(g&&x.judgesPast!==!0)continue;let m=x.scope.match;m&&!m(u)||a.push(...ma(x,()=>x.evaluate({graph:n,subject:u,context:r,...o}),u.id))}}let c=new Set,p=a.filter(u=>{let f=`${u.message}|${[...u.nodeIds].sort().join(",")}`;return c.has(f)?!1:(c.add(f),!0)}).map(u=>{let f=pr(u.message);return f===u.message?u:{...u,message:f}});return oo?oo(n,e,p,t.today):p}var oo;function cv(n){oo=n}function dl(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 cl(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 Tt="type-text",re={};var jt=(n,e)=>n==="*"||n.includes(e);function D(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 W=n=>n.kind==="system"&&n.onBehalfOf===void 0,ze=(n,e)=>n.roles==="*"||(e.roles??[]).some(t=>n.roles.includes(t));function ya(n){return gi(n.map(e=>an(V(e).toLowerCase())),"or")}function Ne(n,e,t,r,o,i,s={},a,d,l){if(!n)return{ok:!0};if(W(e))return{ok:!0};if(e=D(e),o!==void 0){if(Ne(n,e,t,r,void 0,i).ok)return{ok:!0};let f=!1;if(o.some(m=>Ne(n,e,m,r,void 0,i).ok)){if(!d||i===void 0||e.id!==void 0&&d()===e.id||!l&&n.grants.some(m=>m.roles!=="*"&&ze(m,e)&&o.some(k=>jt(m.mutations,k))))return{ok:!0};f=!0}let h=f?[t]:[t,...o],g=[...new Set(h.flatMap(m=>io(n,m,r)))].sort(),x=(f?"only on what you made; ":"")+(g.length===0?o.length===0?"no declared act creates or changes it, so no role can":"no role can":`${ya(g)} can`);return{ok:!1,refusal:{mutation:t,...r===void 0?{}:{kind:r},wouldNeed:g,message:ba(n,h,r,x,s)}}}let c=!1;for(let f of n.grants){if(!ze(f,e)||!jt(f.mutations,t)||f.kinds!==void 0&&f.kinds!=="*"&&(r===void 0||!f.kinds.includes(r))||f.self&&(i===void 0||e.id===void 0||i!==e.id))continue;let h=f.ownEnd?a?.()??[]:[e.id];if(!h.length||h.some(g=>g!==e.id)){c=!0;continue}return{ok:!0}}let p=io(n,t,r),u=c?"only on your own end of the link":p.length===0?"no role can":`${ya(p)} can`;return{ok:!1,refusal:{mutation:t,...r===void 0?{}:{kind:r},wouldNeed:p,message:ba(n,[t],r,u,s)}}}function ba(n,e,t,r,o){let i=[...new Set(e.flatMap(a=>va(n,a,t)))],s=o.act?.(e[0]);return`Not permitted: ${s?`\u201C${s}\u201D`:e[0]}${t?` on ${an(o.noun?.(t)??t)}`:""} \u2014 ${r}.`+(i.length>0?` ${i.join(" ")}`:"")}function va(n,e,t){return[...new Set(xa(n,e,t).flatMap(r=>r.describe||[]))]}var xa=(n,e,t)=>n.grants.filter(r=>jt(r.mutations,e)&&(t===void 0||jt(r.kinds??"*",t)));function io(n,e,t){let r=xa(n,e,t);return r.some(o=>o.roles==="*")?[]:[...new Set(r.flatMap(o=>o.roles))].sort()}function so(n,e,t){return n?t.filter(r=>{let o=D(e).id;return ao(r).some(i=>Ne(n,e,r.name,i,void 0,o,void 0,()=>[o??[]].flat()).ok)}):t}var ao=n=>n.subject&&n.subject.kinds!=="*"?n.subject.kinds:[void 0];var oe=class extends Error{constructor(t,r="refused"){super(t);this.sentence=t;this.reason=r;this.name="ActRefusal"}};var Xn=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.op==="splice-text"?e.id:"";if(r===""||this.unversioned?.has(r))return;let o=e.op==="add-node"?Object.keys(e.node):e.op==="splice-text"?[e.field]: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,wa(t,e.before));return}case"splice-text":{let t=this.unversioned?.has(e.id)?void 0:this.node(e.id);t&&this.setNode(e.id,dr(t,e,!0));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,wa(t,e.after));return}case"splice-text":{let t=this.unversioned?.has(e.id)?void 0:this.node(e.id);t&&this.setNode(e.id,dr(t,e));return}case"add-edge":this.setEdge(e.edge,!0);return;case"remove-edge":this.setEdge(e.edge,!1);return}}};function wa(n,e){let t={...n};for(let[r,o]of Object.entries(e))Fe(o)?delete t[r]:t[r]=o;return t}var ul=n=>n.op==="add-node"||n.op==="remove-node"?n.node.id:n.op==="patch-node"||n.op==="splice-text"?n.id:void 0;function co(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=ul(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),l=d?t.served(d,e.writerOf(i)):void 0;if(!a&&!l)return{primitives:[],faithful:!1};if(!a&&l){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"&&l===n.node&&c.length===0;return{primitives:p?[n]:[{op:"add-node",node:l},...c],faithful:p}}if(a&&!l){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,f)=>h=>h in u==(f!==void 0&&h in f);if(Object.keys(n.after).every(u=>c(a,s)(u)&&c(l,d)(u)))return{primitives:[n],faithful:!0};let p=u=>Object.fromEntries(Object.keys(n.after).map(f=>[f,f in u?u[f]:ue]));return{primitives:[{op:"patch-node",id:i,before:p(a),after:p(l)}],faithful:!1}}if(n.op==="splice-text"){let c=n.field;if(a[c]===s[c]&&l[c]===d[c])return{primitives:[n],faithful:!0};let p=u=>({[c]:c in u?u[c]:ue});return{primitives:[{op:"patch-node",id:i,before:p(a),after:p(l)}],faithful:!1}}return{primitives:[{op:"remove-node",node:a},{op:"add-node",node:l}],faithful:!1}}function ka(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 Xn(e.present,e);if(!i)return s.begin(e.log.length??o+r.length),n.map(u=>{let f=D(u.author).id,h=u.primitives.map(g=>co(g,s,t,()=>f));return{op:u,primitives:h.flatMap(g=>g.primitives),faithful:h.every(g=>g.faithful)}});let a=new Set(n.map(u=>u.seq)),d=Number.POSITIVE_INFINITY,l=Number.NEGATIVE_INFINITY;for(let u of a)u<d&&(d=u),u>l&&(l=u);d-=o,l-=o;let c=ll(r,d,e.present,t),p=c?new Xn(e.present,e,c.unversioned):s;for(let u=r.length-1;u>=d;u--){let f=r[u].primitives;for(let h=f.length-1;h>=0;h--)p.undo(f[h])}return fl(n,r,d,l,a,p,c?.judge??t,e)}function ll(n,e,t,r){let{sees:o,names:i}=r;if(!o||!i)return;let s=new Set,a=new Set,d=new Set,l=(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"?l(u.node.id,u.node):u.op==="patch-node"?(l(u.id,u.before),l(u.id,u.after)):u.op==="splice-text"&&(l(u.id,{}),s.has(u.id)||(a.add(u.id),d.delete(u.id)));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 fl(n,e,t,r,o,i,s,a){let d=new Map;for(let l=t;l<=r;l++){let c=e[l];if(i.begin(c.seq),!o.has(c.seq)){for(let f of c.primitives)i.apply(f);continue}let p=(f,h)=>a.writers?.writerAt(f,h,c.seq+1),u=c.primitives.map(f=>co(f,i,s,p));d.set(c.seq,{op:c,primitives:u.flatMap(f=>f.primitives),faithful:u.every(f=>f.faithful)})}return n.map(l=>d.get(l.seq))}function xv(n,e,t,r){let o=new Xn(e.present,e);return o.begin(e.log.length??e.log.all().length),n.flatMap(i=>co(i,o,t,()=>r).primitives)}var $a="A change you cannot see",Ra={kind:"system",id:"withheld",name:"Someone"};function vn(n){return n.withheld===!0}var Qn=$e,Aa=(n,e)=>Object.entries(n).some(([t,r])=>t!=="id"&&t!=="kind"&&I(r,e));function _a(n){if(typeof n!="function")return n;let e=n,t=r=>e(r.id)&&!Aa(r,e)?r:void 0;return{sees:e,shows:e,served:t,servedWith:t,optional:()=>!1,kindOf:()=>{}}}function I(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(I(n[t],e))return!0;return!1}for(let t in n)if(Object.hasOwn(n,t)&&(!e(t)||I(n[t],e)))return!0;return!1}function Oa(n,e){let t=r=>!e(r);return n.primitives.some(r=>Qn(r).some(t))||[...n.writes,...n.reads].some(t)||n.mutation!==null&&I(n.mutation.args,e)}function pl(n,e){if(Qn(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 Aa(t,e.sees)?{op:"remove-node",node:Object.fromEntries(Object.entries(t).filter(([r,o])=>r==="id"||r==="kind"||!I(o,e.sees)))}:n}case"patch-node":{let t=e.kindOf(n.id),r={};for(let[i,s]of Object.entries(n.after))if(!I(s,e.sees))r[i]=s;else if(t!==void 0&&e.optional(t,i))r[i]=ue;else return;let o=Object.fromEntries(Object.entries(n.before).filter(([,i])=>!I(i,e.sees)));return{op:"patch-node",id:n.id,before:o,after:r}}case"add-edge":case"remove-edge":return I(n.edge,e.sees)?void 0:n;case"splice-text":return I(n.removed,e.sees)||I(n.inserted,e.sees)?void 0:n}}function uo(n,e,t){let r=_a(e),o=i=>r.shows(i)&&Pa(r,i);return{id:n.id,seq:n.seq,batch:n.batch,author:Ra,intent:$a,mutation:null,primitives:t??n.primitives.flatMap(i=>{let s=pl(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 xn(n,e){let t=_a(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=>!I(i,r.sees),sees:r.sees,names:i=>I(i,r.sees)};return ka(n,r.timeline,o).map(({op:i,primitives:s,faithful:a})=>(!i.withheld&&a?Sa(i,r,s):void 0)??uo(i,r,s))}return n.map(o=>(!o.withheld&&!Oa(o,r.shows)?Sa(o,r):void 0)??uo(o,r))}function Sa(n,e,t){let r=n.inverse??n.primitives;if(t&&t.length<n.primitives.length){if(!t.length)return;r=r.filter(g=>Qn(g).every(e.shows));let{inverse:f,...h}=n;n={...h,primitives:t}}let o=f=>e.sees(f)&&Pa(e,f),i=n.reads.filter(o),s=new Set(n.primitives.flatMap(Qn)),a=n.writes.filter(f=>o(f)||e.sees(f)&&s.has(f)),d=i.length===n.reads.length&&a.length===n.writes.length?n:{...n,reads:i,writes:a},l=e.actor!==void 0&&D(n.author).id===e.actor;if(!l&&n.described?.some(f=>!e.sees(f)))return;if(!I(n,e.sees))return d;let c=new Set,p=f=>{if(typeof f=="string")c.add(f);else if(Array.isArray(f))for(let h of f)p(h);else if(f!==null&&typeof f=="object")for(let[h,g]of Object.entries(f))c.add(h),p(g)};t&&p(t);let u=f=>e.sees(f)||c.has(f);if(!I(r,u))return l&&n.mutation&&p(n.mutation.args),I({...d,primitives:[],inverse:[]},l?u:e.sees)?void 0:d}function Pa(n,e){return n.timeline===void 0||n.kindOf(e)!==void 0}var Be=class extends M{constructor(t){super(t.message);this.check=t;this.name="UndoBlockedError"}get blockedBy(){return this.check.blockedBy}};function et(n,e){let t=new Set(e),r=n.undoneIds(),o=n.all().filter(h=>t.has(h.batch)&&!r.has(h.id)),i=[...n.epochs()].reverse().find(h=>h.horizon);if(i){let h=new Set(n.all().map(x=>x.batch)),g=e.filter(x=>!h.has(x));if(g.length>0)return{ok:!1,ops:o,blockedBy:[],includeBatches:[],reason:"missing",message:`Cannot undo ${g.map(x=>`batch ${x}`).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(vn))return{ok:!1,ops:o,blockedBy:[],includeBatches:[],reason:"forbidden",message:o.every(vn)?"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(h=>h.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 h of o)for(let g of h.writes)s.add(g);let a=Math.min(...o.map(h=>h.seq)),d=n.epochs().find(h=>h.change!==void 0&&h.seq>a);if(d){let h=o.find(g=>g.seq<d.seq);return{ok:!1,ops:o,blockedBy:[],includeBatches:[],message:`Cannot undo "${h.intent}": ${h.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 l=new Map(n.all().map(h=>[h.id,h.seq])),c=o.flatMap(h=>h.primitives),p=[];for(let h of n.all()){if(h.seq<=a||t.has(h.batch)||r.has(h.id)||h.undoes!==void 0&&(l.get(h.undoes)??-1)>a)continue;let g=re.aside?.(c,h);if(g===!0)continue;let x=[...new Set([...h.reads.filter(m=>s.has(m)),...g??[]])];x.length>0&&p.push({op:h,overlap:x})}if(p.length===0)return{ok:!0,ops:o};let u=p.filter(h=>!vn(h.op)).map(h=>`"${h.op.intent}" (op ${h.op.id}, read ${h.overlap.join(", ")})`).join("; ");if(p.some(h=>vn(h.op)))return{ok:!1,ops:o,blockedBy:p,includeBatches:[],message:`Cannot undo on its own \u2014 ${u?`a later operation depends on it: ${u}; and `:""}a later change you cannot see depends on it, which only somebody who can see it can take back.`};let f=[...new Set(p.map(h=>h.op.batch))];return{ok:!1,ops:o,blockedBy:p,includeBatches:f,message:`Cannot undo on its own \u2014 a later operation depends on it: ${u}. Include ${f.map(h=>`batch ${h}`).join(", ")} to undo them together.`}}function Ea(n,e){return e?lo(e,n).flatMap(t=>[...t.primitives]):[...n].sort((t,r)=>r.seq-t.seq).flatMap(t=>Le(t))}function lo(n,e){return re.undone?re.undone(n,e):[...e].sort((t,r)=>r.seq-t.seq).map(t=>({op:t,primitives:Le(t)}))}var Ue=class extends Error{refusal;constructor(e){super(e.message),this.name="PermissionDeniedError",this.refusal=e}};function hl(n){let e=n instanceof Error?n.message:String(n);if(n instanceof Ue){let t=n.refusal.wouldNeed;return{reason:"forbidden",sentence:e,...t.length>0?{wouldNeed:[...t]}:{}}}return n instanceof U?{reason:"missing",sentence:e}:n instanceof oe?{reason:n.reason,sentence:n.sentence}:n instanceof Be?{reason:n.check.reason??"invalid",sentence:e}:{reason:"invalid",sentence:e}}var fe=class extends M{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"}};var gl=["edit","remove","archive","unarchive","merge","leave-alone","allow-tidying"];var Lv=n=>gl.map(e=>`${e}-${n}`);function za(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 fo=["connect","disconnect"],Na=n=>n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),po=(n,e,t)=>`${n}-${e}-${Na(t)}`;function Zv(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}-${Na(i)}`)return{act:t[1],kind:r,relation:i}}}}var Cv=n=>[...n].flatMap(([e,t])=>[...t].flatMap(r=>fo.map(o=>po(o,e,r)))),Ma=n=>`${/^[aeiou]/i.test(n)?"an":"a"} ${n}`;function Ia(n,e){let t=e.also?` (${e.also})`:"";return{title:`${e.one?`${n==="connect"?"Set":"Clear"} the ${e.to}`:`${n==="connect"?"Link":"Unlink"} ${Ma(e.to)}`}${t}`,fromTheOtherEnd:`${n==="connect"?"Link":"Unlink"} ${Ma(e.from)}${t}`}}function Ta(n,e,t,r){if(t.cardinality!=="one"||t.to==="*"||t.to.length!==1||t.to[0]!==n)return;let o=t.description?.trim().replace(/\.$/,"");return o&&/^the\s+\S/i.test(o)&&!/[.;:!?,()]/.test(o)&&o.split(/\s+/).length<=8?{to:o.replace(/^the\s+/i,"")}:{also:r(e)}}var We=n=>n.trim().replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").replace(/-+/g,"-").toLowerCase();function Dt(n,e){let t=We(n),r=[...e];if(r.includes(n))return n;let o=r.filter(i=>We(i)===t);return o.length===1?o[0]:void 0}function ml(n,e){let t=Array.from({length:e.length+1},(r,o)=>o);for(let r=1;r<=n.length;r+=1){let o=[r];for(let i=1;i<=e.length;i+=1)o[i]=Math.min(t[i]+1,o[i-1]+1,t[i-1]+(n[r-1]===e[i-1]?0:1));t=o}return t[e.length]}function ho(n,e){let t=[...e],r=Dt(n,t);if(r)return r;let o=We(n);if(o==="")return;let i,s=!1;for(let a of t){let d=ml(o,We(a));d>Math.max(2,Math.floor(Math.max(o.length,a.length)/3))||(!i||d<i.far?(i={act:a,far:d},s=!1):d===i.far&&(s=!0))}return i&&!s?i.act:void 0}var yl=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 })`,wn=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?yl(e):`Op "${e.id}" has seq ${e.seq} but the log is ${this.length} long`);pa(e),this.ops.push(Nn(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 qe(this.ops)}opsInBatch(e){return this.ops.filter(t=>t.batch===e)}batches(){return go(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=Q.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)))bl(i,a);return i}toJSON(){return[...this.ops]}};function bl(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 qe(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 go(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 mo(n){return n?.automated===!0&&n.kind!=="human"&&n.kind!=="rule"}var Da=n=>n?.[Jn]===!0,vl=(n,e)=>Da(("graph"in n?n.graph:n).getNode(e));function ja(n,e,t){let r=n.tryDefinition(e);return t===void 0?r?.tidying:r?.edges?.[t]?.tidying}var xl=n=>JSON.stringify(n,(e,t)=>t&&typeof t=="object"&&!Array.isArray(t)?Object.fromEntries(Object.entries(t).sort()):t);var wl=/^(archive|unarchive|remove|leave-alone|allow-tidying)$/;function kl(n,e){let t=We(n.name),r=e?.act(n.name),o=n.args??{},i=r?r.derived:za(t),{id:s}=o;if(i&&typeof s=="string"){if(wl.test(i.act))return[i.act,s];if(i.act==="merge")return["merge",...[s,o.into].sort()];if(i.relation)return[i.act,i.relation,s,o.to]}let a=r?.subject?.arg??"id",[d,l]=Object.keys(o).filter(c=>c!==a);return r?.connects?.length===1&&d&&!l&&e.has(o[a])&&e.has(o[d])?["connect",r.connects[0],o[a],o[d]]:[t,r?.creates?.length&&typeof s=="string"&&!e.has(s)?{...o,id:0}:o]}var Fa=(n,e)=>`\u2248${xl(n.map(t=>kl(t,e)))}`;function La(n,e,t){let r=Sl(n,t);return[e,...e.map(o=>[o])].map(o=>r.get(Fa(o,t))).find(Boolean)}function Sl(n,e){let t=qe(n),r=new Map(n.map(i=>[i.id,i])),o=new Map;for(let i of n){let s=i.undoes!==void 0&&!t.has(i.id)&&!i.withheld?r.get(i.undoes):void 0,a=s?.suggests??(s?.mutation&&(s.lineage||i.undoneLineage)?[s.mutation]:[]);if(a.length>0)for(let d of[a,...a.map(l=>[l])])o.set(Fa(d,e),i)}return o}function Za(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,l=(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 l){if(!c)continue;if(Da(c))return s(`change \u201C${C(n.tryDefinition(c.kind),c)}\u201D`,"a person said to leave it alone");if(!i)continue;let p=ja(n,c.kind);if(p==="never")return s(`change ${se(n,c.kind)} on its own`,"the app says they are never tidied");if(d&&p==="no-links")return s(`link or unlink ${se(n,c.kind)} on its own`,"the app says they are never linked automatically")}if(d&&i&&l[0]&&ja(n,l[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 $l(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 Ft={scene:0,overview:10,rail:20,popover:30,dialog:40,toast:50},Rl={plots:0,stage:1,tag:2,ties:2,lines:3,tieLabels:4,occupants:6,seatMarks:7,zoom:8,card:10,opened:11},Al={under:0,raised:1,over:2},yo=n=>`--graview-layer-${n}`,_l=n=>`var(${yo(n)}, ${Ft[n]})`;function Ol(){return Object.keys(Ft).map(n=>` ${yo(n)}: ${Ft[n]};`).join(`
|
|
4
|
-
`)}function Pl(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 Ca(){return`sub_${(globalThis.crypto?.randomUUID?.()??`${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`).replace(/-/g,"").slice(0,20)}`}function Ga(n){return{...n,id:n.id??Ca(),at:n.at??new Date().toISOString()}}function El(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=Ga(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 bo=(n,e)=>`${n}\0${e}`,Ka=new WeakMap;function Ml(n,e){let t=new Map;for(let[o,i]of Object.entries(e??{}))for(let[s,a]of Object.entries(i))t.set(bo(o,s),[{seq:n-1,by:a}]);return{base:n,end:n,read:[],fields:t,written:[],seqOf:new Map,writers:{writerAt:(o,i,s)=>{let a=t.get(bo(o,i));if(!a)return;let d=0,l=a.length;for(;d<l;){let c=d+l>>1;a[c].seq<s?d=c+1:l=c}return d===0?void 0:a[d-1].by}}}}function zl(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=>!Fe(n.after[e]))];if(n.op==="splice-text")return[n.id,[n.field]]}function Nl(n,e){let t=n.end,r=D(e.author).id,o=e.undoes!==void 0?n.seqOf.get(e.undoes):void 0,i=[];for(let s of e.primitives){let a=zl(s);if(!a)continue;let[d,l]=a;for(let c of l){let p=e.undoes===void 0?r:o!==void 0?n.writers.writerAt(d,c,o):void 0,u=bo(d,c),f=n.fields.get(u);f||n.fields.set(u,f=[]),f.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 Il(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 nt(n){let e=n.all(),t=typeof n.length=="number"?n.length:e.length,r=t-e.length,o=Ka.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&&Il(o,i),r>o.base&&(o.read=o.read.slice(r-o.base),o.base=r))}else o=void 0;o||Ka.set(n,o=Ml(r,r>0?[...n.epochs?.()??[]].reverse().find(i=>i.horizon)?.writers:void 0));for(let i=o.end;i<t;i++)Nl(o,e[i-r]);return o.writers}function Va(n,e,t,r){let o=nt(n),i={};for(let s of t)for(let a in s){if(!Object.hasOwn(s,a)||a==="id"||a==="kind"||!r(s[a]))continue;let d=o.writerAt(s.id,a,e);d!==void 0&&((i[s.id]??={})[a]=d)}return i}var He={served:new WeakSet},tt=n=>n.fields!==void 0||(n.hide?.length??0)>0,Ie=n=>He.on===!0||He.served.has(n);var vo=new WeakMap;function Tl(n,e){let t=new Map(Object.entries(e?.removed??{})),r=new Map(Object.entries(e?.creators??{})),o=n===0||e?.removed!==void 0;return{base:n,end:n,read:[],kinds:t,creators:r,entries:[],records:{kindOf:i=>t.get(i),creatorOf:i=>r.get(i),knowsAll:o}}}function jl(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=D(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 Dl(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 pe(n){let e=n.all(),t=typeof n.length=="number"?n.length:e.length,r=t-e.length,o=vo.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&&Dl(o,i),r>o.base&&(o.read=o.read.slice(r-o.base),o.base=r))}else o=void 0;o||vo.set(n,o=Tl(r,r>0?Fl(n,r):void 0));for(let i=o.end;i<t;i++)jl(o,e[i-r]);return o.records}function Fl(n,e){let t=[...n.epochs?.()??[]].reverse().find(r=>r.horizon);return t?.seq===e?t:void 0}function Ba(n,e,t){pe(n);let r=vo.get(n),o=[new Set,new Set];for(let a=r.entries.length-1;a>=0&&r.entries[a].seq>=e;a--)o[+r.entries[a].creator].add(r.entries[a].id);let i={},s={};for(let[a,d]of r.creators)o[1].has(a)||(i[a]=d);for(let[a,d]of r.kinds)!o[0].has(a)&&!t(a)&&(s[a]=d);return r.records.knowsAll?{creators:i,removed:s}:{creators:i}}function kn(n,e,t,r,o,i=He.on===!0){if(!n?.sees?.length||W(e))return!0;let s=n.sees.filter(a=>a.kinds.includes(t.kind)&&(i||!tt(a)));return s.length===0?!1:(e=D(e),s.some(a=>{if(!ze(a,e))return!1;if(!a.own&&!a.via)return!0;let d=e.id;if(d===void 0)return!1;let l=c=>c.id===d;return a.via?r.out(t.id,a.via).some(l)||r.in(t.id,a.via).some(l):t.id===d||r.out(t.id).some(l)||r.in(t.id).some(l)||o?.creatorOf(t.id)===d}))}var Lt="publish",xo=n=>n?.mode==="on-publish",wo=(n,e,t)=>xo(n)&&!W(e)&&(t==="published"||!(D(e).roles??[]).some(r=>n.working.includes(r))),ae=globalThis[Symbol.for("@graview/core:publishing")]??={};ae.input=()=>Pe({through:X(Ke())});var So=new Set;function Zt(n,e){return W(e)?So:n.modules?.disabledKinds??So}function Je(n,e){return W(e)?!1:(n.policy?.sees?.length??0)>0||Zt(n,e).size>0}function Ha(n,e){if(!Je(n,e))return()=>!0;let t=n.modules?.disabledKinds??So,r=n.policy?.sees??[],o=D(e),i=Ie(n),s=d=>!t.has(d)&&(r.length===0||r.some(l=>l.kinds.includes(d)&&ze(l,o)&&!l.own&&!l.via&&(i||!tt(l)))),a=n.schema.kinds.every(s);return d=>a||d!==void 0&&s(d)}function Sn(n,e){return t=>{let r=Zt(n,e);if(!n.policy?.sees?.length&&r.size===0)return!0;let o=pe(n.log),i=n.graph.getNode(t);if(i)return!r.has(i.kind)&&kn(n.policy,e,i,n.graph,o,Ie(n));let s=o.kindOf(t)??Ja(n,o,t);return s===void 0?!0:!r.has(s)&&kn(n.policy,e,{id:t,kind:s},{out:()=>[],in:()=>[]},o,Ie(n))}}var Ll={out:()=>[],in:()=>[]};function Ja(n,e,t){if(e.knowsAll||He.served.has(n))return;let r=t.indexOf(":");if(r<=0)return;let o=t.slice(0,r);return n.schema?.tryDefinition(o)?o:void 0}function Zl(n,e,t=new Map,r){let o=Zt(n,e);if(!n.policy?.sees?.length&&o.size===0)return()=>!0;let i=pe(n.log);return s=>{let a=t.get(s);if(a!==void 0)return a;let d,l=n.graph.getNode(s);if(l)d=!o.has(l.kind)&&kn(n.policy,e,l,n.graph,i,Ie(n));else{let c=i.kindOf(s)??Ja(n,i,s);if(c===void 0)return r?.add(s),!0;d=!o.has(c)&&kn(n.policy,e,{id:s,kind:c},Ll,i,Ie(n))}return t.set(s,d),d}}function Cl(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 Ct(n,e){return Ya(n,e).lens}var $o=()=>({judged:new Map,shown:new Map});function Ya(n,e){let t=Cl(n.schema),r=W(e)?void 0:D(e).id,o=()=>n.log.length??n.log.all().length,i=new WeakMap,s=n.graph,a=(c,p,u,f,h)=>{let g=(w,R)=>{if(!c(w.id))return;let v;for(let T in w)if(!(!Object.hasOwn(w,T)||T==="id"||T==="kind"||!I(w[T],c))&&!(r!==void 0&&R(T)===r)){if(!t(w.kind,T))return;(v??=[]).push(T)}if(!v)return w;let $=v.join("\0"),P=i.get(w);if(P?.without===$)return P.node;let E=Object.fromEntries(Object.entries(w).filter(([T])=>!v.includes(T)));return i.set(w,{without:$,node:E}),E},x=w=>{let R=u();return g(w,v=>p().writerAt(w.id,v,R))},m=new WeakMap,k=h?w=>{let R=m.get(w);return R||m.set(w,R={node:x(w)}),R.node}:x,A=w=>{if(!c(w))return!1;let R=s.getNode(w);return R===void 0||k(R)!==void 0},S=h?.shown??new Map,_=h?w=>{let R=S.get(w);return R===void 0&&S.set(w,R=A(w)),R}:A,y=s.outEdges&&s.inEdges?{present:{getNode:w=>s.getNode(w),outEdges:w=>s.outEdges(w),inEdges:w=>s.inEdges(w)},log:n.log,get writers(){return p()}}:void 0,b={sees:c,shows:_,served:k,servedWith:g,optional:t,kindOf:f,...r!==void 0?{actor:r}:{},...y?{timeline:y}:{},hides:()=>Je(n,e),pin:h?()=>b:()=>d($o())};return He.lens?.(b,n,e)??b};function d(c){let p,u=o(),f=pe(n.log);return a(Zl(n,e,c.judged,c.unnamed),()=>p??=nt(n.log),()=>u,h=>s.getNode(h)?.kind??f.kindOf(h),c)}return{lens:a(Sn(n,e),()=>nt(n.log),o,c=>s.getNode(c)?.kind??pe(n.log).kindOf(c)),pinWith:d}}var Ua=new WeakMap,Wa=new WeakMap,Gl=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"||r.op==="splice-text"?e.add(r.id):(e.add(r.edge.from),e.add(r.edge.to));return e};function Xa(n,e){if(!Je(n,e))return n.log.all();let t=n.log.all(),r=n.log.length??t.length,o=r-t.length,i=[...Zt(n,e)].sort().join("\0"),s=Qa(e),a=Ua.get(n.log);a||Ua.set(n.log,a=new Map);let d=a.get(s),{pinWith:l}=Ya(n,e),c=Wa.get(n.log);c||Wa.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 h=t.slice(d.length-o),g=l($o()),x=!0,m=Gl(h);for(let k of m){let A=d.judgments.judged.get(k),S=d.judgments.shown.get(k);if(A!==void 0&&g.sees(k)!==A||S!==void 0&&g.shows(k)!==S){x=!1;break}}if(x){for(let k of m)if(c.has(k)){x=!1;break}}if(x){let k=[...d.ops,...xn(h,l(d.judgments))],A={horizon:o,off:i,length:r,last:t.at(-1),ops:k,judgments:d.judgments};return a.set(s,A),k}}let u={...$o(),unnamed:c},f=xn(t,l(u));return a.set(s,{horizon:o,off:i,length:r,last:t.at(-1),ops:f,judgments:u}),f}function Kl(n,e,t){return(t.subjectId===void 0||!e(t.subjectId)||n.shows(t.subjectId))&&t.nodeIds.every(r=>!e(r)||n.shows(r))&&!I(t,n.sees)}function Ro(n,e){return{all:()=>n,undoneIds:()=>qe(n),epochs:e}}var qa=new WeakMap;function Qa(n){let e=W(n)?n:D(n);return`${n.kind}|${e.id??""}|${(e.roles??[]).join(",")}|${n.onBehalfOf?`for:${n.id??""}`:""}`}var ed=(n,e)=>`${Qa(n)}@${e}`,ko=(n,e)=>{let t=Reflect.get(n,e,n);return typeof t=="function"?t.bind(n):t},Vl=Symbol.for("@graview/core:seat");function $n(n,e,t={}){if(wo(n.publishing,e,t.as)){if(ae.served)return ae.served(n,e);throw new Error("Load @graview/core/publishing to serve a reader of an app that publishes.")}return td(n,e)}var Bl=()=>ae.served!==void 0;function nd(n){let e=qa.get(n);return e||qa.set(n,e=new Map),e}function td(n,e){if(!Je(n,e))return n;let t=ed(e,"head"),r=nd(n),o=r.get(t);if(o)return o;let i=n.graph,s=Ct(n,e),a=S=>{let _=v=>v===void 0?void 0:S.served(v),y=v=>_(v)!==void 0,b=v=>y(i.getNode(v));return{served:_,seenNode:y,seenId:b,seenEdge:v=>b(v.from)&&b(v.to)&&!I(v,S.sees),servedAll:v=>v.flatMap($=>_($)??[])}},{served:d,seenId:l}=a(s),c=()=>a(s.pin?.()??s),p=(S,_)=>{let y=nt(n.log),b=s.pin?.()??s,w=S.nodes.flatMap(v=>b.servedWith(v,$=>y.writerAt(v.id,$,_))??[]),R=new Set(w.map(v=>v.id));return{nodes:w,edges:S.edges.filter(v=>R.has(v.from)&&R.has(v.to)&&!I(v,b.sees))}},u=S=>{let{removed:_,writers:y,...b}=S,w=p(S.base,S.seq);if(!S.creators)return{...b,base:w};let R=new Set(w.nodes.map($=>$.id)),v=Object.fromEntries(Object.entries(S.creators).filter(([$,P])=>R.has($)&&!I(P,s.sees)));return{...b,base:w,creators:v}},f=S=>S&&u(S),h=()=>Xa(n,e),g=()=>Ro(h(),()=>n.log.epochs()),x=new Proxy(i,{get(S,_){switch(_){case"getNode":return y=>d(S.getNode(y));case"has":return l;case"allNodes":case"nodesOfKind":return(...y)=>c().servedAll(S[_](...y));case"count":return(...y)=>c().servedAll(S.nodesOfKind(...y)).length;case"allEdges":case"edgesOfKind":case"outEdges":case"inEdges":return(...y)=>S[_](...y).filter(c().seenEdge);case"out":case"in":case"neighbors":return(y,...b)=>{let w=c();return w.seenId(y)?w.servedAll(S[_](y,...b)):[]};case"snapshot":return()=>{let y=S.snapshot(),b=c();return{...y,nodes:b.servedAll(y.nodes),edges:y.edges.filter(b.seenEdge)}};case"size":{let y=c();return{nodes:y.servedAll(S.allNodes({archived:"all"})).length,edges:S.allEdges({archived:"all"}).filter(y.seenEdge).length}}default:return ko(S,_)}}}),m=()=>{let S=h();return go(S,qe(S))},k=new Proxy(n.log,{get(S,_){switch(_){case"all":case"toJSON":return()=>[...h()];case"epochs":return()=>S.epochs().map(u);case"lastEpoch":return()=>f(S.lastEpoch());case"live":return()=>{let y=h(),b=qe(y);return y.filter(w=>!b.has(w.id))};case"get":return y=>h().find(b=>b.id===y);case"opsInBatch":return y=>h().filter(b=>b.batch===y);case"batches":return m;default:return ko(S,_)}}}),A=new Proxy(n,{get(S,_){switch(_){case Vl:return{store:S,principal:e};case"graph":return x;case"log":return k;case"snapshot":return x.snapshot;case"batches":return m;case"canUndo":return y=>et(g(),typeof y=="string"?[y]:y);case"violations":return y=>S.violations(y,x).filter(b=>Kl(s,w=>i.has(w),b));case"findings":return()=>S.findings().filter(y=>(y.id.includes("->")?y.id.split("->").map((w,R)=>R===0?w.slice(w.indexOf(":")+1):w):[y.id]).every(w=>!i.has(w)||l(w))&&!I(y,s.sees));case"wouldChange":return y=>S.wouldChange(y,e);case"preview":return(y,b,w)=>S.preview(y,b,{author:e,...w});case"seenBy":return(y,b)=>$n(S,y,b);case"seenFor":return e;case"servedSeq":return S.servedSeq;case"checkpoint":return y=>f(S.checkpoint(y));default:return ko(S,_)}}});return r.set(t,A),A}ae.kit={seatView:td,viewsOf:nd,viewKey:ed,diff:Ee,reads:wo};var Ao=new Set;function _o(n,e){if(!n||e===void 0)return{enabled:new Set(Object.keys(n??{})),disabledKinds:Ao,disabledMutations:Ao,disabledInvariants:Ao,administered:rd(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 l of d.kinds??[])o.add(l);for(let l of d.mutations??[])i.add(l);for(let l of d.invariants??[])s.add(l)}for(let a of t){let d=n[a];for(let l of d?.kinds??[])o.delete(l);for(let l of d?.mutations??[])i.delete(l);for(let l of d?.invariants??[])s.delete(l)}return{enabled:t,disabledKinds:o,disabledMutations:i,disabledInvariants:s,administered:rd(n,t)}}function rd(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 od(n){return n.normalize("NFKD").replace(/\p{M}/gu,"").toLowerCase().trim().replace(/\s+/g," ")}var Gt=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=od(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=Oo(a.sorted,r);d<a.sorted.length&&a.sorted[d].startsWith(r);d+=1){let l=[...a.ids.get(a.sorted[d])??[]];s.push(...l),a.sorted[d]===r&&i.push(...l)}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=C(this.graph.schema.tryDefinition(e.kind),e),r=od(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(Oo(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=Oo(r.sorted,t.key);r.sorted[i]===t.key&&r.sorted.splice(i,1)}};function Oo(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 Ul(n,e){return e.includes("*")?"record":e.map(t=>H(n.tryDefinition(t),t)).join(" or ")}function id(n,e,t,r){let o=Ul(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 ad=Symbol.for("@graview/core:node-ref"),sd=n=>typeof n=="object"&&n!==null?n[ad]:void 0;function Te(n="*"){return Wl(L().check(Kn(1)),n)}function Wl(n,e){let t=Object.freeze(e==="*"?["*"]:[...e]),r=o=>{o&&Object.defineProperty(o,ad,{value:t,enumerable:!0,configurable:!0})};return r(n),r(j(n)),n}function Po(n){if(typeof n!="object"||n===null)return;let e=sd(n);if(e)return e;let t=j(n),r=sd(t);if(r)return r;let o=t?.innerType;return o?Po(o):void 0}function rt(n){let e=n.shape;if(!e)return[];let t=[];for(let[r,o]of Object.entries(e)){let i=Po(o);i&&t.push({name:r,kinds:i,optional:o.safeParse(void 0).success})}return t}function Eo(n){if(n===null||typeof n!="object")return JSON.stringify(n)??"null";if(Array.isArray(n))return`[${n.map(r=>r===void 0?"null":Eo(r)).join(",")}]`;let e=n;return`{${Object.keys(e).filter(r=>e[r]!==void 0).sort().map(r=>`${JSON.stringify(r)}:${Eo(e[r])}`).join(",")}}`}var dd=(n,e)=>n.key<e.key?-1:n.key>e.key?1:0;function ql(n){let e=n.nodes.map(r=>({key:r.id,value:r})).sort(dd),t=n.edges.map(r=>({key:z(r),value:{kind:r.kind,from:r.from,to:r.to,id:r.id,data:r.data}})).sort(dd);return Eo({nodes:e.map(r=>r.value),edges:t.map(r=>r.value)})}function Rn(n){return`sha256:${ud(ql(n))}`}function cd(n,e,t,r={}){let o=r.validate??!0,i=r.base??{nodes:[],edges:[]},s=Rn(t),a=Q.from(n,i,{validate:o});for(let[g,x]of e.entries())try{a.applyPrimitives(x.primitives)}catch(m){let k=e[g-1];return{ok:!1,expected:Rn(a.snapshot()),actual:s,...k?{divergedAfter:k.id}:{},reason:`The log does not fold: op "${x.id}" (${x.intent}) could not be applied. ${m instanceof Error?m.message:String(m)}`}}let d=Rn(a.snapshot());if(d===s)return{ok:!0,hash:s};let l=g=>{let x=Q.from(n,i,{validate:o});for(let m=0;m<=g;m++)x.applyPrimitives(e[m].primitives);return Rn(x.snapshot())},c=g=>{try{let x=Q.from(n,t,{validate:o});for(let m=e.length-1;m>g;m--)x.applyPrimitives(Le(e[m]));return Rn(x.snapshot())}catch{return}},p=g=>{let x=c(g);return x!==void 0&&x!==l(g)},u=-1,f=e.length-1;for(;u<f;){let g=Math.floor((u+f)/2);p(g)?f=g:u=g+1}let h=f>=0?e[f]:void 0;return{ok:!1,expected:d,actual:s,...h?{divergedAfter:h.id}:{},reason:h?`The graph and the fold of its log part after op "${h.id}" (${h.intent}).`:"The graph and the fold of its log disagree before any op: the base it folds from does not match."}}var Hl=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]),Jl=new TextEncoder,Yl=new Uint32Array(64),Xl=new Uint32Array(8),Kt=Array.from({length:256},(n,e)=>e.toString(16).padStart(2,"0"));function ud(n){let e=Jl.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=Xl;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=Yl;for(let d=0;d<r.length;d+=64){for(let m=0;m<16;m++)s[m]=o.getUint32(d+m*4);for(let m=16;m<64;m++){let k=s[m-15],A=s[m-2],S=(k>>>7|k<<25)^(k>>>18|k<<14)^k>>>3,_=(A>>>17|A<<15)^(A>>>19|A<<13)^A>>>10;s[m]=s[m-16]+S+s[m-7]+_>>>0}let l=i[0],c=i[1],p=i[2],u=i[3],f=i[4],h=i[5],g=i[6],x=i[7];for(let m=0;m<64;m++){let k=(f>>>6|f<<26)^(f>>>11|f<<21)^(f>>>25|f<<7),A=f&h^~f&g,S=x+k+A+Hl[m]+s[m]>>>0,_=(l>>>2|l<<30)^(l>>>13|l<<19)^(l>>>22|l<<10),y=l&c^l&p^c&p,b=_+y>>>0;x=g,g=h,h=f,f=u+S>>>0,u=p,p=c,c=l,l=S+b>>>0}i[0]=i[0]+l>>>0,i[1]=i[1]+c>>>0,i[2]=i[2]+p>>>0,i[3]=i[3]+u>>>0,i[4]=i[4]+f>>>0,i[5]=i[5]+h>>>0,i[6]=i[6]+g>>>0,i[7]=i[7]+x>>>0}let a="";for(let d=0;d<8;d++){let l=i[d];a+=Kt[l>>>24]+Kt[l>>>16&255]+Kt[l>>>8&255]+Kt[l&255]}return a}var ot=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 Ql(n,e){return{...e,name:n}}function Mo(n){if(!n.creates?.length)return!1;let e=n.input.shape;return e===void 0||!("id"in e)}function hd(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 Mo(n)?[...r,"id"]:r}var ld=(n,e,t={})=>{let r=n.filter(s=>t[s]?.length),o=n.filter(s=>!t[s]?.length);return`${[...o.length>0?[`does not take ${o.map(s=>`"${s}"`).join(", ")}`]:[],...r.map(s=>`${s} is set by ${t[s].join(" or ")}`)].join("; ")}; it takes ${e.length>0?e.map(s=>`"${s}"`).join(", "):"nothing"}`};function ef(n){let e=n?._zod?.def;for(let t=0;e?.innerType&&t<8;t++)e=e.innerType._zod?.def;return e}var nf=/^-?(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][+-]?\d+)?$/;function gd(n,e){let t=n?.shape;if(!t||typeof e!="object"||e===null||Array.isArray(e))return e;let r;for(let[o,i]of Object.entries(e)){if(typeof i!="string"||!nf.test(i)||ef(t[o])?.type!=="number")continue;let s=Number(i);Number.isFinite(s)&&(r??={...e},r[o]=s)}return r??e}var md=n=>typeof n=="string"&&n.length<=200&&/^[^\s\p{Cc}]+$/u.test(n);function tf(n){if(typeof n!="object"||n===null)return;let e=n.id;if(e!==void 0){if(!md(e))throw new M("An id is 1\u2013200 characters with no space",`Got ${JSON.stringify(e)}.`);return e}}function rf(n){let{id:e,...t}=n;return t}function fd(n){return n.normalize("NFKD").replace(/\p{M}/gu,"").toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"")||"item"}function zo(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 of(n,e){if(e.limited&&e.me===void 0)return pd(n,e.held);let t=e.limited?`${n}.${zo(e.me)}`:n,r=t;for(let o=2;e.seen(r);o++)r=`${t}-${o}`;return e.held(r)?pd(t,e.held):r}function pd(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=Mo(e)?tf(t):void 0,i=gd(e.input,o===void 0?t:rf(t)),s=hd(e);if(s&&typeof i=="object"&&i!==null&&!Array.isArray(i)){let y=Object.keys(i).filter(b=>!s.includes(b)&&i[b]!==void 0);if(y.length>0)throw new fe(e.name,[{path:[],message:ld(y,s,e.writtenBy)}])}let a=e.input.safeParse(i);if(!a.success){let y=Object.keys(e.input.shape??{});throw new fe(e.name,a.error.issues.map(b=>b.code==="unrecognized_keys"&&y.length>0?{...b,message:ld(b.keys,y,e.writtenBy)}:b))}let d=a.data,l=new ot(r.seen??n),c=[],p=new Set,u=r.me===void 0?void 0:`.${zo(r.me)}`,f=y=>!r.seesInFull||r.seesInFull()||u!==void 0&&new RegExp(`\\${u}(-[0-9a-z]+)?$`).test(y),h=y=>l.has(y)||n.has(y)||p.has(y),g,x=y=>{let b=new Set([...n.outEdges(y),...n.inEdges(y)]);for(let w of b)l.getNode(w.from),l.getNode(w.to),c.push({op:"remove-edge",edge:w});return b},m={graph:l,schema:n.schema,me:r.me,emit(y){c.push(y)},addNode(y){c.push({op:"add-node",node:y})},removeNode(y){let b=l.getNode(y)&&n.getNode(y);if(!b)throw new U(y,`Cannot remove missing node "${y}"`);x(y),c.push({op:"remove-node",node:b})},patchNode(y,b){let w=l.getNode(y)&&n.getNode(y);if(!w)throw new U(y,`Cannot patch missing node "${y}"`);let R={},v={};for(let[$,P]of Object.entries(b)){let E=w[$];JSON.stringify(E)===JSON.stringify(P)&&!r.keepUnchanged?.(P,$,w)||(R[$]=E,v[$]=P)}Object.keys(v).length!==0&&c.push({op:"patch-node",id:y,before:R,after:v})},archiveNode:y=>m.patchNode(y,{[gn]:!0}),unarchiveNode:y=>m.patchNode(y,{[gn]:void 0}),mergeNode(y,b){let w=l.getNode(b)&&n.getNode(b);if(!w)throw new U(b,`Cannot merge into missing node "${b}"`);if(y===b||Ve(w))throw new M(y===b?"Cannot merge a record into itself":"Cannot merge into an archived record");let R=new Set([...n.outEdges(b),...n.inEdges(b)].map(z));for(let v of x(y)){let $={...v,from:v.from===y?b:v.from,to:v.to===y?b:v.to};$.from!==$.to&&!R.has(z($))&&(R.add(z($)),c.push({op:"add-edge",edge:$}))}m.archiveNode(y),g=b},addEdge(y){c.push({op:"add-edge",edge:y})},removeEdge(y){c.push({op:"remove-edge",edge:y.id!==void 0&&n.linkById(y.id)||y})},setSingleSource(y,b,w){n.inEdges(b,y).some(R=>R.from===w)||c.push({op:"add-edge",edge:{kind:y,from:w,to:b}});for(let R of n.inEdges(b,y))l.getNode(R.from),R.from!==w&&c.push({op:"remove-edge",edge:R})},freshId(y,b){if(o!==void 0&&!p.has(o)){if(!f(o))throw new M(`"${e.name}" makes its own id here`,`Leave id out${u?`, or end it "${u}"`:""}.`);if(h(o))throw new M(`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=r.hint;if(o===void 0&&!p.size&&md(w)&&f(w)&&!h(w))return p.add(w),w;let R=b?`${b}:${fd(y)}`:fd(y),$=of(R,{seen:P=>(r.seen?r.seen.has(P):n.has(P))||p.has(P),held:h,limited:r.seesInFull!==void 0&&!r.seesInFull(b),me:r.me});return p.add($),$}};if(e.apply(m,d),o!==void 0&&!p.has(o))throw new M(`"${e.name}" did not make a record with id "${o}": it names what it makes itself`);let k=r.check?.(c,e),A=new Set(c.flatMap($e)),S=new ot(r.seen??n),_=e.describe?.(d,S)??`${e.name}(${Object.entries(d).map(([y,b])=>`${y}=${JSON.stringify(b)}`).join(", ")})`;return{primitives:c,reads:[...new Set([...l.reads(),...S.reads()])],...e.describe?{described:[...S.reads(),...k??[]]}:{},writes:[...A],intent:_,...g!==void 0?{mergedInto:g}:{},...p.size>0?{firstMinted:p.values().next().value}:{}}}var yd=Symbol.for("@graview/core:amount"),Dx=(n,e)=>(Object.defineProperty(j(n),yd,{value:e,enumerable:!0}),n);function No(n,e=!0){let t=j(n);return t?.[yd]??(e&&t?.innerType?No(t.innerType):void 0)}function bd(n,e={}){let t=Number.isInteger(n),r={maximumFractionDigits:t?0:2,minimumFractionDigits:t?0:2};try{return me(n,e.locale,e.currency?{style:"currency",currency:e.currency,...r}:r)}catch{return me(n,e.locale,r)}}function vd(n,{format:e,unit:t,currency:r,locale:o}){let i=/^[A-Z]{3}$/.test(t??"");return e==="money"||!e&&i?bd(n,{...o?{locale:o}:{},...(i?t:r)?{currency:i?t:r}:{}}):e==="percent"?me(n,o,{style:"percent",maximumFractionDigits:0}):me(n,o)+(t?` ${t}`:"")}var sf=Symbol.for("@graview/core:typed-field");function Io(n){let e=j(n);return e?e[sf]??Io(e.innerType):void 0}var af=/^[("'“‘]*(?:(?:[a-z]{1,3}\.){2,}|(?:dr|mr|mrs|ms|mx|st|mt|vs|jr|sr|prof|no|fig|approx)\.)$/i;function df(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]==="."&&af.test(r))&&!(t.split(" ").length<3&&e.index+1<n.length))return t}}function xd(n,e=140){let t=n.replace(/^[#>\s]+|\*\*|`|\](\([^)\s]*\))?|\[/gm,"").replace(/\s+/g," ").trim(),r=df(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 cf(n){let e=n.fields.shape;return Object.keys(e).flatMap(t=>{let r=Ot(e[t])?qn(t):void 0;return r&&e[r]?[r]:[]})}var uf=[["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 wd(n,e){let t=new Set(e.map(o=>o.name)),r=[];for(let o of n.definitions){let i=cf(o);if(i.length===0)continue;let s=o.kind,a=o.fields.shape,d=Object.keys(a).filter(c=>!(c in(o.fixed??{}))),l=c=>C(o,c);for(let[c,p,u,f]of uf){let h=`${c}-${s}`;t.has(h)||r.push({name:h,derived:{kind:s,act:c},title:p,description:u,subject:{kinds:[s],arg:"id"},writes:i.map(pn),...c==="skip"?{}:{creates:[s]},input:ln({id:Te([s]),on:L().check(Vn(/^\d{4}-\d{2}-\d{2}$/,"a day, like 2026-10-21")),...i.length>1?{field:X(qs(i))}:{},...c==="skip"?{}:Object.fromEntries(d.map(g=>[g,X(a[g])]))}),describe:(g,x)=>f.replace("{}",l(x.getNode(String(g.id))??{id:g.id}))+Ae(String(g.on)),apply(g,x){let m=g.graph.getNode(String(x.id)),k=String(x.field??i[0]),A=m?.[k],S=m?.[pn(k)],_=String(x.on);if(typeof A!="string"||!hn(S))throw new oe(`${l(m??{id:x.id})} does not repeat`,"refused");let y=fn(A,S,{from:_,to:_})[0];if(!y)throw new oe(`${l(m)} does not fall on ${Ae(_)}`,"refused");let b=String(m.id),w=Object.fromEntries(d.filter(q=>x[q]!==void 0).map(q=>[q,x[q]])),R=pn(k),v=q=>{let Z=Object.fromEntries(Object.entries({...m,...q,...w}).filter(([F,Mn])=>Mn!=null&&F!=="id")),ce=g.freshId(l(Z));g.addNode({...Z,id:ce,kind:s});for(let F of Object.keys(o.edges??{}))for(let Mn of g.graph.out(b,F))g.addEdge({kind:F,from:ce,to:Mn.id})};if(c!=="split"){g.patchNode(b,{[R]:{...S,except:[...new Set([...S.except??[],_])].sort()}}),c==="detach"&&v({[k]:y,[R]:null});return}if(Object.keys(w).length===0)throw new oe(`Nothing to change: give ${l(m)} from ${Ae(_)} something new`,"invalid");if(_<=A.slice(0,10))return g.patchNode(b,w);let $=new Date(Date.parse(`${_}T00:00:00Z`)-864e5).toISOString().slice(0,10),P=S.count?fn(A,{...S,except:[]},{to:$}).length:0,{count:E,except:T,...K}=S,De=q=>T?.some(q)?{except:T.filter(q)}:{};g.patchNode(b,{[R]:{...K,until:$,...De(q=>q<_),...E?{count:P}:{}}}),v({[k]:y,[R]:{...K,...De(q=>q>=_),...E?{count:E-P}:{},continues:b}})}})}}return r}function kd(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,l)=>{let c=d.getNode(String(l));return c?C(n.tryDefinition(c.kind),c):String(l)};for(let d of n.definitions){let l=d.kind,c=Object.entries(d.edges??{}),p=u=>u.to==="*"?"record":u.to.map(f=>H(n.tryDefinition(f),f)).join(" or ");for(let[u,f]of c){let h=p(f),g=f.cardinality==="one",x=c.some(([_,y])=>_!==u&&p(y)===h),m=_=>V(_).toLowerCase(),k=Ta(l,u,f,m),A={to:k&&"to"in k?k.to:h,from:H(d,l),one:g,also:k&&"also"in k?k.also:x&&!k?m(u):void 0},S=A.from;for(let _ of fo){let y=po(_,l,u);if(t.has(y)||f.acts==="none"||(_==="connect"?o.has(u):i.has(u)||f.appendOnly))continue;let{title:b,fromTheOtherEnd:w}=Ia(_,A),R=f.description?`: ${f.description.replace(/\.$/,"")}`:"";s.push({name:y,derived:{kind:l,act:_,relation:u},title:b,fromTheOtherEnd:w,description:_==="connect"?`Link this ${S} to ${/^[aeiou]/i.test(h)?"an":"a"} ${h}${R}.${g?" It has one, so this replaces the one it has.":""}`:`Take away the link between this ${S} and ${/^[aeiou]/i.test(h)?"an":"a"} ${h}${R}. Undo puts it back.`,subject:{kinds:[l],arg:"id"},..._==="connect"?{connects:[u]}:{severs:[u],destructive:!0},idempotent:!0,input:ln({id:Te([l]),to:Te(f.to==="*"?"*":f.to)}),describe:(v,$)=>_==="disconnect"?`Unlink ${a($,v.id)} from ${a($,v.to)}`:g?`Set the ${h} of ${a($,v.id)} to ${a($,v.to)}`:`Link ${a($,v.id)} to ${a($,v.to)}`,apply(v,$){let P=String($.id),E=String($.to);for(let K of[P,E])if(!v.graph.getNode(K))throw new oe(`there is no record "${K}"`,"invalid");let T=v.graph.out(P,u).some(K=>K.id===E);if(_==="disconnect"){if(!T)throw new oe(`${a(v.graph,P)} is not linked to ${a(v.graph,E)}`,"invalid");v.removeEdge({kind:u,from:P,to:E});return}if(g)for(let K of v.graph.out(P,u))K.id!==E&&v.removeEdge({kind:u,from:P,to:K.id});T||v.addEdge({kind:u,from:P,to:E})}})}}}return s}function lf(n){let e=new Set(n.declared),t=[...new Set([...(n.paged??[]).filter(o=>e.has(o)),...n.declared])],r=(n.naming??[]).filter(o=>e.has(o));return[...new Set([...r,...t.filter(n.must),...t])]}var To=n=>`\xA7${n}\xA7`;function ff(n,e){if(n.label)try{let r={id:To(e.length),kind:n.kind};e.forEach((s,a)=>r[s]=To(a));let o=String(n.label(r)),i=e.map((s,a)=>[s,o.indexOf(To(a))]).filter(([,s])=>s>=0);if(i.length>0)return i.sort((s,a)=>s[1]-a[1]).map(([s])=>s)}catch{}let t=["name","title","label"].find(r=>e.includes(r));return t?[t]:[]}var Sd=new WeakMap;function Vt(n){let e=Sd.get(n);if(e)return e;let t=n.fields.shape??{},r=Object.keys(t),o=n.display?.page,i=lf({declared:r,paged:[...o?.fields??[],...(o?.groups??[]).flatMap(s=>s.fields)],must:s=>t[s]?.safeParse?.(void 0).success===!1&&!Object.hasOwn(n.defaults??{},s),naming:ff(n,r)});return Sd.set(n,i),i}function pf(n,e){let t=e.subject?.kinds,r=e.creates?.[0]??e.derived?.kind??(t!==void 0&&t!=="*"&&t.length===1?t[0]:void 0);return r===void 0?void 0:n.tryDefinition(r)}function hf(n,e){let t=Object.keys(e.input?.shape??{}),r=n?pf(n,e):void 0;if(!r)return t;let o=Vt(r),i=d=>d!==e.subject?.arg&&o.includes(d),s=t.filter(i).sort((d,l)=>o.indexOf(d)-o.indexOf(l)),a=0;return t.map(d=>i(d)?s[a++]:d)}function jo(n,e,t=r=>r.name){let r=o=>{let i=e.indexOf(t(o));return i<0?e.length:i};return[...n].sort((o,i)=>r(o)-r(i))}function Do(n){let e=n.fields.shape;return Object.keys(e).filter(t=>!(t in(n.fixed??{})))}function Fo(n,e){let t=e.subject;return t?t.kinds==="*"?n.kinds:t.kinds:[]}function Lo(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(rt(n.input).map(s=>s.name));return Object.keys(o).filter(s=>s!==t.arg&&r.has(s)&&!i.has(s))}function Zo(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 Fo(n,o)){let s=n.tryDefinition(i);if(s)for(let a of Lo(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 $d(n,e,t){let r=n.tryDefinition(t);if(!r)return[];let o=Zo(n,e).get(t);return Do(r).filter(i=>!o?.has(i))}var Rd=n=>`edit-${n}`;function Ad(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),Fo(n,i).includes(t)&&Lo(i,r).length>0&&o.add(i.name));return[...o]}function _d(n,e){let t=new Set(e.map(o=>o.name)),r=[];for(let o of n.definitions){let i=o.kind,s=Rd(i);if(t.has(s))continue;let a=jo($d(n,e,i),Vt(o),f=>f);if(a.length===0)continue;let d=Zo(n,e).get(i),l=Object.fromEntries(Do(o).flatMap(f=>d?.get(f)?.length?[[f,d.get(f)]]:[])),c=o.fields.shape,p=H(o,i),u=a.map(f=>mt(o,f).toLowerCase());r.push({name:s,derived:{kind:i,act:"edit"},idempotent:!0,title:`Change the ${p}`,description:`Change what was set when this ${p} was made: ${u.join(", ")}.`,subject:{kinds:[i],arg:"id"},writes:a,...Object.keys(l).length>0?{writtenBy:l}:{},input:ln({id:Te([i]),...Object.fromEntries(a.map(f=>[f,X(yf(c[f]))]))}),describe:(f,h)=>gf(o,c,a,f,h),apply(f,h){let g={};for(let x of a){let m=h[x];m!==void 0&&(g[x]=m)}if(Object.keys(g).length===0)throw new oe(`Nothing to change \u2014 give at least one of ${u.join(", ")} a value.`,"invalid");f.patchNode(h.id,g)}})}return r}function gf(n,e,t,r,o){let i=o.getNode(r.id),s=i?C(n,i):"a record",a=t.filter(d=>r[d]!==void 0).map((d,l)=>{let c=r[d],p=qn(d),u=p!==void 0&&p in e,f=mt(n,u?p:d);return`the ${f===f.toUpperCase()?f:hi(f)}${l===0?` of ${s}`:""} to ${u?c?`repeat ${mf(c)}`:"stop repeating":Od(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 mf=n=>`every ${(n.interval??1)>1?`${n.interval} ${n.every}s`:n.every}`;function Od(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(Bn(r).length>0)return Bn(r).map(i=>i.name).join(", ");if(Un(e))return Array.isArray(r)&&r.length>1?`${r.length} linked records`:"a linked record";if(Array.isArray(r))return r.map(i=>Od(n,e,t,i)).join(", ");if(typeof r=="boolean")return r?"yes":"no";if(typeof r=="number"){let i=No(e);return i?vd(r,i):Io(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(sn.test(r))return Ae(r);if(ft.test(r))return fr(r);for(let i=j(e);i;i=j(i.innerType))if(i.type==="enum")return V(r);return`\u201C${xd(r,60)}\u201D`}function yf(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 Pd(n,e){return n.filter(t=>!t.derived&&(t.creates??[]).includes(e)).map(t=>t.name)}function Bt(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"?Ad(n,e,t.derived.kind):Pd(e,t.derived.kind)}function bf(n,e){let t=new Set(e.map(o=>o.name)),r=[];for(let o of n.definitions){let i=o.kind,s=H(o,i),a=(l,c)=>{let p=l.getNode(String(c));return p?C(o,p):String(c)},d=Te([i]);for(let[l,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 f=`${l}-${i}`,h=l==="leave-alone"||l==="allow-tidying";t.has(f)||!h&&l!=="remove"&&o.archives===!1||h&&o.tidying==="never"||r.push({name:f,derived:{kind:i,act:l},title:p,description:u,subject:{kinds:[i],arg:"id"},...l==="remove"?{destructive:!0}:{},idempotent:!0,input:Pe(l==="merge"?{id:d,into:d}:{id:d}),describe:(g,x)=>{let m=l==="remove"&&x.getNode(String(g.id)),k=m?new Set(Object.values(m).flatMap(A=>Bn(A).map(S=>S.href))).size:0;return`${c} ${a(x,g.id)}${l==="merge"?` into ${a(x,g.into)}`:""}${k?` and its ${k} file${k>1?"s":""}`:""}`},apply:h?(g,x)=>g.patchNode(String(x.id),{[Jn]:l==="leave-alone"?!0:void 0}):(g,x)=>g[`${l}Node`](x.id,x.into)})}}return r}function Co(n,e){return[..._d(n,e),...bf(n,e),...wd(n,e),...kd(n,e)]}var vf=n=>({$made:n}),Ut=n=>typeof n=="object"&&n!==null&&Object.keys(n).join()==="$made"&&Number.isInteger(n.$made)&&n.$made>=0,xf=(n,e)=>Object.fromEntries(Object.entries(n.args??{}).map(([t,r])=>[t,Array.isArray(r)?r.map(e):e(r)])),Ed=n=>Object.values(n.args??{}).some(e=>Ut(e)||Array.isArray(e)&&e.some(Ut)),Md=(n,e,t)=>({...n,args:xf(n,r=>{if(!Ut(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 wf=500,kf=120,Sf=50,zd=4e3,$f=["model","suggestion","interaction","actor","run"],Nd=n=>typeof n=="string"&&n.length>0&&n.length<=kf,Rf=n=>{let e=JSON.stringify(n);return e===void 0?void 0:JSON.parse(e)};function it(n){if(n===void 0)return;let e=n&&typeof n=="object"&&!Array.isArray(n)?n:{},t=typeof e.basis=="string"?e.basis.trim():"",r={basis:t},o=t!==""&&t.length<=wf;for(let i of Object.keys(e)){let s=e[i];i==="basis"||s===void 0||(i==="model"&&typeof s=="string"&&(s=s.trim()),i==="confidence"?o&&=typeof s=="number"&&s>=0&&s<=1:$f.includes(i)?o&&=Nd(s):i==="evidence"?o&&=Array.isArray(s)&&s.length<=Sf&&s.every(Nd):o&&=i!=="__proto__"&&i!=="constructor"&&i!=="prototype"&&(s=Rf(s))!==void 0,o&&(r[i]=s))}if(!o)throw new M("A lineage is { basis: 1 to 500 characters, confidence?: 0 to 1, model?, suggestion?, interaction?, actor?, run?: 1 to 120 characters, evidence?: up to 50 ids }");if(JSON.stringify(r).length>zd)throw new M(`A lineage is at most ${zd} characters written out.`);return r}var _n="keep-link";function Id(n){let e=(t,r)=>{let o=t.getNode(r);return o?C(n.tryDefinition(o.kind),o):r};return{name:_n,title:"Keep this link",input:Pe({kind:L(),from:L(),to:L()}),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 d=z({kind:o,from:i,to:s});throw new U(d,`Cannot remove missing edge ${d}`)}let a=t.graph.edgesOfKind(o,{archived:"all"}).find(d=>d.from===i&&d.to===s)??{kind:o,from:i,to:s};t.removeEdge(a),t.addEdge(a)}}}var Td=(n,e)=>[...n].filter(t=>!t.derived&&t.name!==_n&&typeof e=="string"&&(t.connects?.includes(e)||t.severs?.includes(e))).map(t=>t.name);var jd=["kind-unknown","node-shape","edge-dangling","edge-disallowed","rule-error","rule-budget"];function Dd(n,e){let t=zt(n,e);return t&&[...t.fields].filter(Boolean)}function Af(n,e,t){return n.tryDefinition(e)?.fields?.shape?.[t]}function Wt(n,e){try{return C(n.tryDefinition(e.kind),e)}catch{return typeof e.label=="string"?e.label:"A record"}}var _f=n=>`${n.kind}:${n.from}->${n.to}`,qt=(n,e)=>n<e?-1:n>e?1:0;function Fd(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(f=>f.from===u||f.to===u),a=u=>({action:"drop",primitives:[...s(u.id).filter(f=>i.has(f.from)&&i.has(f.to)).map(f=>({op:"remove-edge",edge:f})),{op:"remove-node",node:u}]}),d=new Set;for(let u of[...i.values()].sort((f,h)=>qt(f.id,h.id))){if(!r.tryDefinition(u.kind)){d.add(u.id),o.push({code:"kind-unknown",id:u.id,message:`${Wt(r,u)} is a kind of record this app no longer has`,repair:a(u)});continue}let f=Dd(r,u);if(f===void 0)continue;let h=Wt(r,u),g=new Map,x=f.length>0;for(let m of f){if(m==="id"||m==="kind"){x=!1;continue}let k=Af(r,u.kind,m),A=k?k.safeParse(void 0):{success:!0,data:void 0},S=r.tryDefinition(u.kind)?.defaults;!A.success&&k&&S&&Object.hasOwn(S,m)&&(A=k.safeParse(S[m])),A.success?A.data===void 0?g.set(m,{action:"clear",value:ue}):g.set(m,{action:"coerce",value:A.data}):x=!1}if(x){let m={...u};for(let[k,A]of g)A.value===ue?delete m[k]:m[k]=A.value;Dd(r,m)!==void 0&&(x=!1)}if(f.length===0){o.push({code:"node-shape",id:u.id,message:`${h} does not fit what ${u.kind} declares`,repair:a(u)});continue}for(let m of f){let k=g.get(m),A=x&&k?{action:k.action,primitives:[{op:"patch-node",id:u.id,before:{[m]:u[m]===void 0?ue:u[m]},after:{[m]:k.value}}]}:a(u);o.push({code:"node-shape",id:u.id,detail:m,message:`${h}: ${V(m)} does not fit what ${u.kind} declares`,repair:A})}}let l=new Set,c=[];for(let u of[...e.edges].sort((f,h)=>qt(z(f),z(h)))){if(l.has(z(u)))continue;l.add(z(u));let f=_f(u),h=i.get(u.from),g=i.get(u.to);if(!h||!g){o.push({code:"edge-dangling",id:f,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(h.id)||d.has(g.id))&&(r.edgeAllowed(u.kind,h.kind,g.kind)||o.push({code:"edge-disallowed",id:f,message:`${Wt(r,h)} \u2192 ${Wt(r,g)}: 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=Q.from(r,{nodes:[...i.values()],edges:c},{validate:!1}),f=new Set,h;try{h=bn(u,p,t.invariantOptions??{})}catch{h=[{invariant:"rules",status:"could-not-judge",label:"The rules",message:"The rules could not be judged",nodeIds:[],repairs:[]}]}for(let g of h){let x=g.status==="could-not-judge"?"rule-error":g.status==="over-budget"?"rule-budget":void 0;if(!x)continue;let m=g.subjectId??g.invariant,k=`${x}|${m}|${g.invariant}`;f.has(k)||(f.add(k),o.push({code:x,id:m,detail:g.invariant,message:g.message}))}}return o.sort((u,f)=>jd.indexOf(u.code)-jd.indexOf(f.code)||qt(u.id,f.id)||qt(u.detail??"",f.detail??""))}var st=()=>globalThis.__graviewWatch;function Ld(n){st()?.store?.(n)}function Ht(n){n!==void 0&&st()?.learn?.({ids:[n],words:[]})}function Zd(n,e){st()?.refused?.({...n,...e===void 0?{}:{author:e}})}function Go(n,e){let t=st();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 Of(n,e){n instanceof fe&&Go(n,e)}function Pf(n,e,t){st()?.seat?.(n,e,t)}function Vo(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 ee(e,t)}var Ko=15*6e4;function Cd(n=Date.now(),e){let t=new Date(n).getTime(),r=pt(e),o=ee(r,t),i=new Date(Date.parse(`${o}T00:00:00Z`));if(i.setUTCDate(i.getUTCDate()+1),!r)return i.getTime()-t;let s=li(i.toISOString().slice(0,10),0,r);for(;ee(r,s)===o;)s+=Ko;for(;ee(r,s-Ko)!==o;)s-=Ko;return s-t}function Ef(n,e){let t,r=()=>{t=setTimeout(()=>{let o=n.tick(new Date);r(),e?.(o)},Cd(Date.now(),n.timeZone)+1e3),t.unref?.()};return r(),()=>clearTimeout(t)}var Jt=class extends M{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"}},Bo="preview",G=(n,e)=>e===void 0?{}:{[n]:e},Ye={kind:"human"},Gd={kind:"system"},Bd={kind:"system",id:"modules",name:"Modules"},Kd=n=>n.mutation===null&&n.undoes===void 0;function Uo(n,e){return`${n.invariant}|${n.subjectId??""}|${n.line||e?.has(n.invariant)?n.label:n.message}`}var Mf=new Set(["remove","archive","unarchive","merge"]),zf={has:()=>!0},Ud=n=>new Set(n.filter(e=>e.shape).map(e=>e.name));function Wd(n,e,t){let r=Ud(n),o=p=>Uo(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 l=p=>p.subjectId&&Uo(p,zf),c=d.map(l);return{introduces:a.filter(p=>{let u=l(p)?c.indexOf(l(p)):-1;return u<0||(c[u]=null,!1)}),resolves:d.filter((p,u)=>c[u]!==null)}}var On=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"}},Yt=class extends M{constructor(t,r){let o=ho(t,r);super(`Unknown mutation "${t}"${o?` \u2014 did you mean "${o}"?`:""}`,`Registered: ${r.join(", ")||"(none)"}`);this.mutation=t;this.name="UnknownMutationError",this.nearest=o}nearest},Vd=n=>new Map(n.map(e=>[e.id,e.batch]));function Nf(){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 Wo=class n{schema;graph;log;mutations=new Map;keeper;typer;invariants;invariantOptions;policy;publishing;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:ee(this.timeZone),on:ee(this.timeZone)}),this.policy=e.policy,this.publishing=e.publishing,this.by=e.principal??Ye,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=Nf();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 M(`Duplicate mutation "${i.name}"`);this.mutations.set(i.name,i)}for(let i of e.past?[]:Co(e.schema,e.mutations??[]))this.mutations.set(i.name,i);!e.past&&!this.mutations.has(_n)&&(this.keeper=Id(e.schema),this.mutations.set(_n,this.keeper));let r=G("horizon",e.horizon),o={validate:this.validate};if(e.log){this.log=wn.from(e.log,e.epochs,r);let i=this.log.lastEpoch();this.graph=e.snapshot?Q.from(e.schema,e.snapshot,o):this.log.fold(e.schema,{...o,...i?{from:i}:{}})}else this.log=wn.from([],e.epochs??(e.snapshot?[{seq:e.horizon??0,base:e.snapshot}]:[]),r),this.graph=Q.from(e.schema,e.snapshot??{nodes:[],edges:[]},o);e.past||(this.countPastTheLog(),Ld(this))}stillNow(){if(this.past)throw new Jt(this.past)}countPastTheLog(){this.countPast(this.log.all())}countPast(e){let t=r=>{let o=/(\d+)$/.exec(r);return o?Number(o[1]):0};for(let r of e)this.counter=Math.max(this.counter,t(r.batch)),this.opCount=Math.max(this.opCount,t(r.id));this.log.horizon>0&&(this.opCount=Math.max(this.opCount,this.log.length))}get servedSeq(){return this.log.length}get publishedSeq(){return ae.seq?.(this)}get publisher(){return ae.act?.(this,this.mutations)}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:_o(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=_o(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(f=>se(this.schema,f)).join(", "):p}).join(", "),d=[i.length>0?`Turn off ${a(i)}`:"",s.length>0?`turn on ${a(s)}`:""].filter(Boolean).join("; "),l={id:this.nextId(),seq:this.log.length,batch:t.batch??this.mintBatch("batch"),author:Bd,intent:Fn(d),mutation:null,primitives:[],reads:[],writes:[],at:this.now(),...G("via",t.via),enabledModules:[...o].sort()};return this.log.append(l),this.notify(Yn,[l]),l}mutation(e){let t=this.mutations.get(this.spelled(e))??(e===Lt?this.publisher:void 0);if(!t)throw new Yt(e,[...this.mutations.keys()]);if(this.mutationDisabled(t))throw new M(`Mutation "${e}" belongs to a module this workspace has turned off`,`Enabled modules: ${[...this.modules.enabled].join(", ")||"(none)"}`);return t}spelled(e){return e===Tt&&!this.typer&&re.typeText&&!this.past&&!this.mutations.has(e)&&this.mutations.set(e,this.typer=re.typeText(this)),this.mutations.has(e)?e:Dt(e,this.mutations.keys())??e}spelledCall(e){let t=this.spelled(e.name);return t===e.name?e:{...e,name: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(),...this.publisher?[this.publisher]:[]].filter(e=>e!==this.keeper&&e!==this.typer&&!this.mutationDisabled(e))}viaOf(e,t,r){if(e!==void 0&&e===this.keeper){let o=Td(this.mutations.values(),t?.args.kind);if(o.length>0)return o;let i=[...this.mutations.values()];return[...new Set(i.filter(s=>s.derived?.relation===t?.args.kind).flatMap(s=>Bt(this.schema,i,s)??[]))]}if(e!==void 0&&e===this.typer)return re.via(this.schema,[...this.mutations.values()],this.subjectKindOf(t,r),t?.args.field);if(e?.derived)return Bt(this.schema,[...this.mutations.values()],e)}moved(e,t){return Wd(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=Ye){if(e=this.spelledCall(e),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)??(e.name===Lt?this.publisher:void 0);if(o&&o===this.publisher)return ae.verdict(this,t);let i=o?.subject&&e.args[o.subject.arg];return Ne(this.policy,t,e.name,this.subjectKindOf(e,t),this.viaOf(o,e,t),typeof i=="string"?i:void 0,this.words,()=>{let s=D(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!==void 0&&(o.derived!==void 0||o===this.typer)?()=>pe(this.log).creatorOf(i):void 0,o?.derived!==void 0&&Mf.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]]:[],...rt(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&&Zd(e,t),new Ue(e)}get words(){return{act:e=>this.mutations.get(e)?.title,noun:e=>H(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=Gd){let r=this.modules.disabledKinds;if(r.size===0||!W(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&&D(e).id};if(e===void 0||!Je(this,e))return t;let r=Sn(this,e);return{...t,seen:$n(this,e).graph,keepUnchanged:o=>I(o,r),seesInFull:Ha(this,e)}}collaborative(e,t){return re.collaborative?.(this.schema,this.graph.getNode(e)?.kind,t)??!1}asSplices(e,t){return re.asSplices?re.asSplices(this,e,t):e}missingFor(e,t=Ye){e=this.spelledCall(e);let r=this.mutations.get(e.name),o=new Set(this.namedIn(e));if(!r||o.size===0)return;let i=$n(this,t).graph;for(let s of o)if(!i.has(s))return new U(s,`\u201C${r.title??e.name}\u201D names a record that is not there.`)}mayAdminister(e,t=Ye){let r=this.modules.administered.get(e);return r?(r.mutations??[]).some(o=>{let i=this.mutations.get(o);return!!i&&ao(i).some(s=>Ne(this.policy,t,o,s,this.viaOf(i)).ok)}):!1}seenBy(e,t){return $n(this,e,t)}sees(e,t){return this.graph.has(t)&&Sn(this,e)(t)}labels;resolveRef(e,t,r=Ye){let o=(this.policy?.sees?.length??0)>0,i=u=>!o||this.sees(r,u),s=this.graph.getNode(t);if(this.labels??=new Gt(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 f=u.filter(h=>!this.graph.isArchived(h));return f.length?f:u},l=d(a.exact.filter(i)),c=l.length>0,p=(c?l:d(a.prefix.filter(i))).map(u=>({id:u,kind:this.graph.getNode(u).kind,label:this.labels.labelOf(u)??u})).sort((u,f)=>u.label<f.label?-1:u.label>f.label?1:u.id<f.id?-1:1);return p.length===1?{ok:!0,id:p[0].id,label:p[0].label,by:c?"label":"prefix"}:id(this.schema,e,t,p)}kindsKeptFrom(e=Ye){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&&!W(e)){let o=new Set(this.permittedMutations(e).flatMap(s=>s.creates??[])),i=Ie(this);for(let s of this.schema.kinds)!r.some(d=>d.kinds.includes(s)&&ze(d,e)&&(!d.own&&!d.via||e.id!==void 0)&&(i||!tt(d)))&&!o.has(s)&&t.add(s)}return t}permittedMutations(e=Ye){let t=this.allMutations(),r=so(this.policy,e,t.filter(s=>!s.derived&&s!==this.publisher)),o=this.publisher&&ae.verdict(this,e).ok?[this.publisher]:[],i=t.filter(s=>s.derived!==void 0&&Ne(this.policy,e,s.name,s.derived.kind,this.viaOf(s),D(e).id).ok);return[...r,...o,...i]}subjectKindOf(e,t=Gd){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(!(!W(t)&&!Sn(this,t)(i)))return this.graph.getNode(i)?.kind}today(){return this.pinned()??(this.ticked&&this.ticked.on===ee(this.timeZone)?this.ticked.day:void 0)??(this.timeZone?ee(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=ia(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=Vo(e,this.timeZone),o=ee(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(Yn,[]);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(Yn,[])}violations(e,t=this.graph){return bn(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={}){e=this.spelledCall(e);let o=this.mutation(e.name),i=An(this.graph,o,e.args,this.sighted(r.author));return this.previewPrimitives(this.asSplices(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;Object.assign(e,{graph:Q.from(this.schema,this.graph.snapshot(),{validate:this.validate}),log:wn.from(this.log.all(),this.log.epochs(),{horizon:this.log.horizon}),listeners:new Set,labels:void 0,nextId:()=>`${Bo}:${++t}`,mintBatch:()=>Bo,rehearsing:!0});let r=this.typer&&re.typeText(e);return Object.assign(e,{typer:r,mutations:r?new Map(this.mutations).set(Tt,r):new Map(this.mutations)}),e}previewPrimitives(e,t){let r=this.violations(t.context),o=Q.from(this.schema,this.graph.snapshot()),i=o.applyPrimitives(e,{restoring:t.restoring===!0}),s=bn(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){let o=e.map(v=>this.spelledCall(v));this.stillNow();let i=t.batch??this.mintBatch("batch"),s=t.author??this.by,a=it(t.lineage),d=[],l=[],c=new Set,p=new Set,u=[],f=this.violations(r),h=this.graph.snapshot(),g=this.log.length,x=v=>{let $=this.policy||this.publisher&&v.name===Lt?this.permits(v,s):void 0;$&&!$.ok&&this.refuse($.refusal,s.id)},m=v=>{let $=this.refusesAgent(v,s)??this.namesTurnedOff(v,s);$&&this.refuse($,s.id)},k=o.map(Ed);o.forEach((v,$)=>k[$]||x(v)),o.forEach((v,$)=>k[$]||m(v));let A=mo(s);A&&this.refuseDeclined(o,s),this.rehearsing||Ht(s.id);let S=[],_=[],y=new Map,b=v=>typeof v=="string"?y.get(v)??v:Array.isArray(v)?v.map(b):v;try{for(let[v,$]of o.entries()){let{mintedHint:P,...E}=$,T=y.size?{...E,args:Object.fromEntries(Object.entries(E.args).map(([F,Mn])=>[F,b(Mn)]))}:E,K=k[v]?Md(T,S,v):T;k[v]&&(x(K),m(K));let De=this.mutation(K.name);if(De===this.publisher){let F=ae.op(this,{id:this.nextId(),at:this.now()},K,i,s,t);d.push(F),u.push(F.intent);continue}let q=this.missingFor(K,s);if(q)throw q;let Z;try{Z=An(this.graph,De,K.args,{...this.sighted(s),hint:P})}catch(F){throw F instanceof fe&&!this.rehearsing&&Go(F,s.id),F}if(P!==void 0&&Z.firstMinted!==void 0&&Z.firstMinted!==P&&y.set(P,Z.firstMinted),A){let F=Za(this.schema,this.graph,Z.primitives,this.authorName(s),{declaration:!this.suggesting});F&&this.refuse({mutation:K.name,message:F,wouldNeed:[]},s.id)}if(Z.primitives.length===0)continue;_[v]=Z.firstMinted,S[v]=Z.primitives.find(F=>F.op==="add-node")?.node.id;let ce={id:this.nextId(),seq:this.log.length,batch:i,author:s,intent:De.describe!==void 0?Z.intent:t.intent??Z.intent,...G("batchIntent",t.intent),mutation:K,primitives:this.asSplices(Z.primitives,t.base).map(zn),reads:Z.reads,writes:Z.writes,...De.describe!==void 0&&Z.described&&Z.described.length>0?{described:Z.described}:{},...G("mergedInto",Z.mergedInto),at:this.now(),...G("via",t.via),...G("lineage",a)};this.graph.applyPrimitives(ce.primitives),this.log.append(ce),d.push(ce),l.push(...ce.primitives);for(let F of ce.reads)c.add(F);for(let F of ce.writes)p.add(F);u.push(ce.intent)}}catch(v){throw this.putBack(h,g),v}let w=Me(h,this.graph.snapshot(),l);this.admitted(t,d,l,w,h,g);let R=this.violations(r);return this.notify(w,d),{batch:i,ops:d,..._.length>0?{minted:_}:{},diff:w,primitives:l,reads:[...c],writes:[...p],intent:t.intent??u.join("; "),...this.moved(f,R),violationsAfter:R}}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(l){throw this.graph.load(i),new On(d,l)}let a=this.log.length;for(let[d,l]of o.entries()){let c=Nn({...l,seq:a+d});this.log.append(c),s.push(c)}return this.countPast(s),this.notify(Me(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 l=a.primitives.map(zn),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,...G("batchIntent",a.batchIntent),mutation:a.mutation??null,primitives:l,reads:a.reads??[],writes:a.writes??[...new Set(l.flatMap($e))],at:a.at??this.now(),...G("undoes",a.undoes),...G("via",a.via),...G("lineage",it(a.lineage))};if(r.has(c.id))throw new M(`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 On(a,d)}for(let a of i)this.log.append(a);this.countPast(i);for(let a of i)Ht(a.author.id);return this.notify(Me(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=it(t.lineage),l=this.asSplices(e,t.base).map(zn),c=[];if(l.length>0){let f={id:this.nextId(),seq:this.log.length,batch:r,author:o,intent:a,mutation:null,primitives:l,reads:[],writes:[...new Set(l.flatMap($e))],at:this.now(),...G("via",t.via),...G("lineage",d)};this.graph.applyPrimitives(f.primitives),this.log.append(f),c.push(f),Ht(o.id)}let p=this.violations(),u=Me(s,this.graph.snapshot(),l);return this.notify(u,c),{batch:r,ops:c,diff:u,primitives:l,reads:[],writes:c[0]?.writes??[],intent:a,...this.moved(i,p),violationsAfter:p}}findings(){return Fd({schema:this.schema,invariants:this.allInvariants()},this.graph.snapshot(),{invariantOptions:this.invariantOptions})}batches(){return this.log.batches()}canUndo(e){return et(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=Ea(r.ops,this.log.all()),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(Kd),...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&&!W(o);if(i){let g=et(Ro(xn(this.log.all(),Ct(this,o)),()=>this.log.epochs()),r);if(!g.ok)throw new Be(g)}let s=this.canUndo(r);if(!s.ok)throw new Be(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=it(t.lineage);if(this.policy||this.publisher)for(let g of s.ops){if(!g.mutation)continue;let x=D(g.author).id,m=A=>JSON.stringify(A).includes(JSON.stringify(x)),k=x!==void 0&&x!==D(o).id&&!W(o)&&!m(g.mutation.args)&&m(g.primitives)?{ok:!1,refusal:{mutation:g.mutation.name,wouldNeed:[],message:"it was done as somebody else."}}:this.permits(g.mutation,o);k.ok||this.refuse({...k.refusal,message:`Not permitted to undo "${g.intent}": ${k.refusal.message}`},o.id,!0)}let l=this.graph.snapshot(),c=this.violations(),p=[],u=this.log.length;for(let{op:g,primitives:x}of lo(this.log.all(),s.ops)){let m={id:this.nextId(),seq:this.log.length,batch:a,author:o,intent:`Undo: ${g.intent}`,...G("batchIntent",t.intent),mutation:null,primitives:x,reads:g.reads,writes:g.writes,at:this.now(),undoes:g.id,...G("via",t.via),...G("lineage",d),...G("undoneLineage",g.lineage)};this.graph.applyPrimitives(m.primitives,{restoring:Kd(g)}),this.log.append(m),p.push(m)}let f=Me(l,this.graph.snapshot(),p.flatMap(g=>[...g.primitives]));this.admitted(t,p,p.flatMap(g=>[...g.primitives]),f,l,u);let h=this.violations();return this.notify(f,p),{batch:a,ops:p,diff:f,primitives:p.flatMap(g=>[...g.primitives]),reads:[...new Set(p.flatMap(g=>[...g.reads]))],writes:[...new Set(p.flatMap(g=>[...g.writes]))],intent:t.intent??p.map(g=>g.intent).join("; "),...this.moved(c,h),violationsAfter:h}}authorName(e){return Hn(e,{graph:this.graph,schema:this.schema})}actMeanings(){return{act:e=>this.mutations.get(this.spelled(e)),has:e=>this.graph.has(e)}}refuseDeclined(e,t){let r=La(this.log.all(),e,this.actMeanings());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&&ha(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(g=>t.has(g.batch)),i=r.slice(o<0?r.length:o),s=this.log.horizon+(o<0?r.length:o),a=i.find(g=>!t.has(g.batch));if(a)throw new M(`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 M(`Cannot rebase across an epoch: one begins at seq ${d.seq}, after pending op "${i[0].id}"`);let l=this.graph.snapshot(),c=[],p=[],u=[];this.quiet++;try{for(let k of[...i].reverse())this.graph.applyPrimitives(Le(k),{restoring:!0,inPlace:!0});this.log.truncate(s);let g=new Set(this.log.all().map(k=>k.id));for(let k of e.confirmed){if(g.has(k.id))continue;try{this.graph.applyPrimitives(k.primitives,{restoring:k.undoes!==void 0})}catch(S){throw new On(k,S)}let A=Nn({...k,seq:this.log.length});this.log.append(A),g.add(k.id),c.push(A)}this.countPast(c);let x=re.carried?.(i,c,e.pending),m=Vd(i);for(let k of e.pending){let A=i.filter(S=>S.batch===k);if(A.length!==0)try{p.push(...this.replay(k,A,x?.get(k),m))}catch(S){u.push({batch:k,error:S})}}}catch(g){this.log.truncate(s);for(let x of i)this.log.append(x);throw this.graph.load(l),g}finally{this.quiet--}let f=Ee(l,this.graph.snapshot()),h=[...c,...p];return this.notify(f,h),{diff:f,confirmed:c,pending:p,refused:u}}adopt(e){this.stillNow();let t=new Set(e.drop??[]),r=(e.pending??[]).filter(f=>!t.has(f)),o=this.log.all(),i=this.graph.snapshot(),s={ops:[...o],epochs:[...this.log.epochs()],horizon:this.log.horizon},a=new Set(o.map(f=>f.id)),d=new Map(r.map(f=>[f,o.filter(h=>h.batch===f)]));if(e.log.length>0)this.log.replace(e.log,e.epochs,G("horizon",e.horizon));else{let f=e.horizon??0;this.log.replace([],e.epochs??[{seq:f,base:e.snapshot}],{horizon:f})}let l=[],c=[];this.quiet++;try{this.graph.load(e.snapshot),this.projected=void 0,this.countPastTheLog();for(let f of r){let h=d.get(f)??[];if(h.length!==0)try{l.push(...this.replay(f,h,void 0,Vd(o)))}catch(g){c.push({batch:f,error:g})}}}catch(f){throw this.log.replace(s.ops,s.epochs,{horizon:s.horizon}),this.graph.load(i),this.projected=void 0,f}finally{this.quiet--}let p=this.log.all().filter(f=>!a.has(f.id)&&!l.includes(f)),u=Ee(i,this.graph.snapshot());return this.notify(u,[...p,...l]),{diff:u,adopted:p,pending:l,refused:c}}replay(e,t,r,o=new Map){let i=t[0],s={author:i.author,batch:e,...G("intent",i.batchIntent),...G("via",i.via),...G("lineage",i.lineage)};if(i.undoes!==void 0){let a=t.map(l=>this.log.get(l.undoes??"")?.batch??o.get(l.undoes??"")),d=t.find((l,c)=>a[c]===void 0||!this.log.all().some(p=>p.batch===a[c]));if(d)throw new M(`What "${d.intent}" took back is no longer in the log`);return this.undoing([...new Set(a)],s).ops}return r?this.applying(r,s).ops:t.every(a=>a.mutation!==null)?this.applying(t.map(a=>a.mutation),s).ops:this.append(t.map(({seq:a,...d})=>d))}snapshot(){return this.graph.snapshot()}verify(){let e=this.log.lastEpoch();return cd(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 m=this.log.length-(e.keepOps??1e3),A=Date.parse(e.now??this.now())-(e.keepDays??90)*864e5,S=t.find(y=>Date.parse(y.at)>A),_=S?S.seq:this.log.length;r=Math.min(m,_)}let o=xo(this.publishing)?[this.publishedSeq??0]:[],i=[...e.pins??[],...o].filter(m=>Number.isInteger(m));for(i.length>0&&(r=Math.min(r,...i)),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 s=this.verify();if(!s.ok)throw new M(`Cannot compact a store that does not verify: ${s.reason}`);let{creators:a,removed:d,writers:l,...c}=this.log.checkpointAt(this.schema,r,{validate:this.validate}),p=new Set(c.base.nodes.map(m=>m.id)),{creators:u,removed:f}=Ba(this.log,r,m=>p.has(m)),h=pe(this.log),g=Va(this.log,r,c.base.nodes,m=>I(m,k=>!p.has(k)&&h.kindOf(k)===void 0)),x=m=>m&&Object.keys(m).length>0;return{...c,...x(u)&&{creators:u},...f&&{removed:f},...x(g)&&{writers:g}}}compact(e){return this.stillNow(),this.log.compact(e)}};var If=n=>`lens:${n}`,Tf={hidden:[],removed:[],may:{views:!1,lenses:!1}};function jf(n,e,t){return n.name!==void 0&&e.may.views?"view":n.declared&&e.may.lenses&&t.lens?"lens":null}var qd=["full","summary","glyph"],at="view:",Ho=(n,e)=>n.as===e.as&&(n.over??[n.kind]).includes(e.kind),Df=n=>n.filter((e,t)=>!n.slice(0,t).some(r=>Ho(r,e))),Ff=n=>n.filter(e=>!e.hidden);function we(n){return n.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function dt(n,e){return`/${we(n.tryDefinition(e)?.plural??`${e}s`)}`}function Lf(n,e,t){return`${dt(n,e)}/${encodeURIComponent(t)}`}function Zf(n,e){return`/places/${encodeURIComponent(n)}${e?`?of=${encodeURIComponent(e)}`:""}`}function Hd(n,e){return e.some(t=>t.as===n.as&&!Ho(n,t))}function Cf(n,e,t){return Hd(n,e)?`${n.title} \xB7 ${(t.tryDefinition(n.kind)?.plural??`${n.kind}s`).toLowerCase()}`:n.title}var Xe=(n,e,t="")=>`${n}|${e.cardinality}|${e.fidelity}|${t}`;function qo(n){switch(n){case"full":return["full","summary","glyph"];case"summary":return["summary","full","glyph"];case"glyph":return["glyph","summary","full"]}}function Gf(n){let e=new Map,t=[],r=[],o,i=[],s={arrange(a){return a!==void 0&&(o=a),s},arrangement:()=>o,home(a,d){return a!==void 0&&i.push({view:a,...d?.name!==void 0?{name:d.name}:{}}),s},homeView:()=>i.at(-1)?.view,homes:()=>i,register(a,d,l,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:l,...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(Xe(a,d),u),c?.title){let f=we(c.title);e.set(Xe(a,d,f),u),d.cardinality==="many"&&!t.some(h=>h.kind===a&&h.as===f)&&t.push({kind:a,title:c.title,as:f,...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 qd)e.delete(Xe(a,{cardinality:"many",fidelity:c},d));let l=t.findIndex(c=>c.kind===a&&c.as===d);return l>=0&&t.splice(l,1),s},lookup(a,d){return e.get(Xe(a,d))?.view},resolve(a,d,l){if(l)for(let c of qo(d.fidelity)){let p=e.get(Xe(a,{cardinality:d.cardinality,fidelity:c},l));if(p)return p}for(let c of qo(d.fidelity)){let p=e.get(Xe(a,{cardinality:d.cardinality,fidelity:c}));if(p)return p}if(d.cardinality==="one")for(let c of qo(d.fidelity)){let p=e.get(Xe(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 Kf=["day","week","month","year","decade"];function Jd(n){let e={};n.q&&n.q.trim().length>0&&(e.query=n.q);let t=Jr(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,...Kf.includes(o)?{bucket:o}:{}})}return e}function Jo(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 Xt(n,e,t){let r=Jo(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 Vf(n,e,t){let r=Jo(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 ct={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"]}},Bf=20,Xd=Object.keys(ct),Uf=(n,e,t,r=ct[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.`}),Qd=n=>Object.hasOwn(ct,n);function Yo(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 Pn=n=>typeof n=="object"&&n!==null&&!Array.isArray(n);function Yd(n,e,t){let r=n.tryDefinition(e)?.fields.shape,o=j(r?.[t]);for(;o&&(o.type==="optional"||o.type==="default"||o.type==="nullable"||o.type==="prefault");)o=j(o.innerType);return o?.type!=="enum"?[]:(o.entries?Object.values(o.entries):o.values??[]).filter(s=>typeof s=="string")}function Wf(n){let e=[],t=[],r=[],o=new Set(n.schema.kinds),i=new Set;for(let d of o)for(let l of Object.keys(n.schema.tryDefinition(d)?.edges??{}))i.add(l);let s=d=>Object.keys(n.schema.tryDefinition(d)?.fields.shape??{}),a=new Map;return(n.lenses??[]).forEach((d,l)=>{let c=`lenses.${l}`,p=typeof d.title=="string"&&d.title.trim().length>0?d.title.trim():void 0,u=(b,w)=>{t.push({index:l,name:d.name,...p?{title:p}:{},why:b}),w&&r.push({severity:"warning",...w})};if(!Qd(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 ${Xd.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 f=ct[d.name],h=Pn(d.options)?d.options:{};if(d.options!==void 0&&!Pn(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 b of Object.keys(h))f.options.includes(b)||r.push({severity:"warning",code:"lens-option-unknown",path:`${c}.options.${b}`,...Uf(d.name,b,p,f.options)});let g={};for(let b of f.options)h[b]!==void 0&&(g[b]=h[b]);d.arrangedBy&&(g.arrangedBy=Jd(d.arrangedBy));let x=Pn(d.bindings)?d.bindings:{},m=[],k,A=(b,w,R)=>u(w,{code:"lens-cannot-draw",path:b,message:`"${p}" cannot draw: ${w}.`,fix:R});if(f.binds==="fields"){let b=Object.keys(x).filter(R=>Pn(x[R])),w=b.filter(R=>!o.has(R));if(b.length===0)return A(`${c}.bindings`,"it binds no kind",`Bind a kind's fields: "bindings": { "<kind>": { ${f.requiredRoles.map(R=>`"${R}": "<field>"`).join(", ")} } }.`);if(w.length>0)return;if(g.bindings=x,m=b,d.name==="timeline"){let R=h.columns;if(Array.isArray(R))g.columns=R.map(v=>typeof v=="string"?{id:v,label:v}:v);else{let v=b.flatMap(P=>{let E=x[P],T=typeof E.column=="string"?E.column:typeof E.columns=="string"?E.columns:void 0;return T?Yd(n.schema,P,T):[]}),$=[...new Set(v)];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].');g.columns=$.map(P=>({id:P,label:P.toUpperCase()}))}g.extent===void 0&&(g.extent=1440)}if(d.name==="columns"){if(g.sort!==void 0){let v=b.map($=>Xt(g.sort,s($),$)).find(Boolean);v&&(r.push({severity:"warning",code:"lens-sort",path:`${c}.options.sort`,message:`"${p}" cannot order its cards: ${v}.`,fix:'Write { "by": "<a field>", "direction": "asc" }, or drop it.'}),delete g.sort)}let R=new Set;for(let v of b){let $=x[v].column;if(typeof $!="string"||!s(v).includes($))return;let P=Yd(n.schema,v,$);if(P.length===0)return A(`${c}.bindings.${v}.column`,`its column field "${$}" is not a choice`,`Bind "column" to a choice field of ${v}, like a status.`);for(let E of P)R.add(E)}typeof g.move!="boolean"&&delete g.move,Number.isInteger(g.cap)&&g.cap>=1&&g.cap<=500||delete g.cap;for(let v of["collapsed","hidden"])Yo(g,v,$=>R.has($))}if(d.name==="calendar"&&g.today!==void 0&&!(typeof g.today=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(g.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"&&g.horizon!==void 0){let R=g.horizon,v=E=>E===void 0||Number.isInteger(E)&&E>=1&&E<=9999,$=typeof R=="number"?{years:R,title:"Years"}:R;Pn($)&&Number.isInteger($.years)&&$.years>=1&&$.years<=200&&typeof $.title=="string"&&$.title.trim().length>0&&v($.from)&&v($.to)&&Object.keys($).every(E=>["years","title","from","to"].includes(E))&&!(typeof $.from=="number"&&typeof $.to=="number"&&$.to<$.from)?g.horizon=$:(delete g.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"&&g.range!==void 0&&!["day","week","month","quarter","year","years","agenda"].includes(g.range))return A(`${c}.options.range`,`its range "${String(g.range)}" is not one a calendar opens at`,"Use one of: day, week, month, quarter, year, agenda.")}else if(f.binds==="entities"){let b=v=>{let $=x[v];if(Pn($)){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 v of f.requiredRoles)if(b(v)===void 0)return;let w=d.name==="coverage"?"rows":d.name==="board"?"slots":"regions",R=b(w);if(!o.has(R))return;if(d.name==="coverage"){let v=b("columns");if(!o.has(v))return;let $=b("link");if(typeof $=="string"&&!i.has($))return;Object.assign(g,{rows:R,columns:v,link:$}),v!==R&&(k=v);for(let[P,E]of[["sort",R],["columnSort",v]]){if(g[P]===void 0)continue;let T=Xt(g[P],s(E),E);T&&(r.push({severity:"warning",code:"lens-sort",path:`${c}.options.${P}`,message:`"${p}" cannot order its ${P==="sort"?"rows":"columns"}: ${T}.`,fix:`Write { "by": "<a field of ${E}>", "direction": "asc" }, or drop it.`}),delete g[P])}}else if(d.name==="board"){Object.assign(g,{slots:R,x:b("x"),y:b("y"),fill:b("fill")});for(let v of["x","y"])if(!s(R).includes(g[v]))return}else{Object.assign(g,{regions:R,outline:b("outline")});for(let v of["markers","at","within","nests","regionKind","markerKind"]){let $=b(v);typeof $=="string"&&(g[v]=$)}}m=[R]}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(g.blocks)||g.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 b=["user","person","member"].find(w=>o.has(w));if(!d.on&&!b)return A(`${c}.on`,"it does not say which kind it stands on",'Say "on": "<the kind whose records are the people>".');m=b?[b]:[]}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(m=[d.on],d.name==="coverage"){let b=[g.rows,g.columns].find(w=>w!==d.on);k=typeof b=="string"?b:void 0}}let S=typeof g.rows=="string"?g.rows:m[0];if(S!==void 0){let b=["label",...s(S)],w=new Set(["is",...b,...Object.keys(n.schema.tryDefinition(S)?.edges??{})]);Yo(g,"search",R=>b.includes(R)),Yo(g,"filters",R=>w.has(R.split(".")[0]))}let _=we(p);if(_.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 b of m){let w=`${b}|${_}`;if(a.has(w))return u(`another lens on ${b} is already called "${p}"`,{code:"lens-title-taken",path:`${c}.title`,message:`"${p}" is the title of lenses.${a.get(w)} too, on the same kind, so one address would name two pictures.`,fix:"Give each its own title."})}for(let b of m)a.set(`${b}|${_}`,l);let y=d.create;y!==void 0&&typeof y!="boolean"&&r.push({severity:"warning",code:"lens-create",path:`${c}.create`,message:`"${p}" says create ${JSON.stringify(y)}, 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:l,lens:d.name,title:p,as:_,kinds:m,...k?{across:k}:{},options:g,...d.hidden===!0?{hidden:!0}:{},...y===!1?{create:!1}:{}})}),{drawn:e,undrawn:t,findings:r}}var qf=6;function Hf(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 Jf(n,e,t){if(!n?.primary)return;let r=new Set(n.primary.map(we));return{kinds:new Set(e.kinds.filter(o=>r.has(we(o))||r.has(dt(e,o).slice(1)))),places:new Set(t.filter(o=>r.has(o.as)||r.has(we(o.title))||o.name!==void 0&&n.primary.includes(at+o.name)).map(o=>`${o.kind}|${o.as}`))}}var ec="overview",Yf=`/places/${ec}`;function Xf(n){let e=n?.scene?.trim();return e||"Scene"}function Qf(n){let e=n?.pages?.trim();return e||"Pages"}function ep(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 nc(n){return n.startsWith(at)&&n.slice(at.length).trim()||void 0}function np(n,e,t){let r=[],o=new Set;for(let i of e??[]){let s=nc(i),a=s===void 0?void 0:t.find(d=>d.name===s&&n.includes(d.kind));a?r.some(d=>d.view===a)||r.push({kind:a.kind,view:a}):s===void 0&&n.includes(i)&&!o.has(i)&&(o.add(i),r.push({kind:i}))}for(let i of n)o.has(i)||r.push({kind:i});return r}function tp(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=we(r),i=t.find(d=>d.title===r||at+d.name===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=>dt(e,d).slice(1)===o);return a?{to:"kind",kind:a}:void 0}function Xo(n){let e=(n??"").replace(/\/+$/,"");return e===""?"":e.startsWith("/")?e:`/${e}`}function rp(n,e={}){let t=typeof n=="string"?n:n.address,r=Xo(e.basePath),o=t.startsWith("/")?t:`/${t}`;return r===""?o:o==="/"?r:o.startsWith("/?")||o.startsWith("/#")?`${r}${o.slice(1)}`:`${r}${o}`}function op(n,e){let t=Xo(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 Qt=2500,ip=Qt*4;function sp(n){let e=n.name??"";return e&&n.onBehalfOfName?`${e}, for ${n.onBehalfOfName}`:e}function Qo(n,e,t=Qt){return n.held==="socket"?!0:n.until!==void 0?e<Date.parse(n.until):e-Date.parse(n.at)<t}var jk=new Set(Pt);function ap(n){return`${n.kind}:${n.id??""}:${n.session??""}`}function dp(n,e,t,r=Qt,o){let i=new Map;for(let[s,a]of n)Qo(a,t,r)&&i.set(s,a);for(let s of e){if(!Qo(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 cp(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)&&JSON.stringify(n.caret)===JSON.stringify(e.caret)}var tc=Symbol.for("@graview/core:app-link"),up=n=>(Object.defineProperty(j(n),tc,{value:1,enumerable:!0}),n);function rc(n){let e=j(n);return!!e&&(e[tc]===1||rc(e.innerType))}var Zk=()=>up(L().check(Cr(500),Vn(Rt,"another app's address")));var er=(n,e)=>`${e.kind}\0${e.id??""}\0${n.address}\0${n.kind}\0${n.id}`;function lp(n,e,t=()=>{}){let r=new Map,o=new Map,i=s=>{let a=er(s,e),d=r.get(a);return d||(d=Promise.resolve().then(()=>n.resolve(s,e)).then(l=>fp(l)?l:null,()=>null).then(l=>(r.get(a)===d&&(o.set(a,l),t(s)),l)),r.set(a,d)),d};return{read(s){let a=er(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(er(s,e)),forget(s){if(!s){r.clear(),o.clear();return}let a=er(s,e);r.delete(a),o.delete(a)}}}function fp(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 pp=1;var nr=(n,e)=>`${n}\0${e}`;function ni(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]):n.op==="splice-text"?[[n.id,n.field]]:[]}var ei=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 ni(r)){let s=nr(o,i);(this.revs.get(s)??this.floor)<t.seq&&this.revs.set(s,t.seq)}}of(e,t){return this.revs.get(nr(e,t))??this.floor}baseFor(e,t=new Set,r){let o=new Set,i=new Map;for(let s of e)for(let a of s.primitives)if(a.op==="add-node"&&o.add(a.node.id),!(a.op!=="patch-node"||o.has(a.id)||t.has(a.id)))for(let d of Object.keys(a.after)){let l=nr(a.id,d);t.has(l)||i.has(l)||r?.(a.id,d)||i.set(l,{node:a.id,field:d,rev:this.of(a.id,d)})}return[...i.values()]}stale(e){return e.filter(t=>this.of(t.node,t.field)>t.rev)}};function hp(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 ni(r))e.add(nr(o,i))}return e}var qk=Symbol.for("@graview/core:collaborative"),Hk=n=>typeof n=="object"&&n!==null?n._zod?.def:void 0;var gp=/^#([0-9a-f]{3,8})$/i,mp=/(rgba?|hsla?)\(([^)]+)\)/gi;function yp(n){let e=gp.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 bp(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,l,c,p]=r;return d===void 0||l===void 0||c===void 0?null:{r:d,g:l,b:c,a:p??1}}let[o,i,s,a]=r;return o===void 0||i===void 0||s===void 0?null:{...ic(o,i>1?i/100:i,s>1?s/100:s),a:a??1}}function Qe(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 ke(n,e,t){return{...ic(n,e,t),a:1}}function ic(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],l=t-r/2;return{r:Math.round((s+l)*255),g:Math.round((a+l)*255),b:Math.round((d+l)*255)}}function ie(n){let e=[];for(let t of n.matchAll(mp)){let r=bp(t[0]);r&&e.push(r)}for(let t of n.matchAll(/#[0-9a-fA-F]{3,8}\b/g)){let r=yp(t[0]);r&&e.push(r)}return e}function ut(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 ti(n){let e=n/255;return e<=.03928?e/12.92:((e+.055)/1.055)**2.4}function oc(n){return .2126*ti(n.r)+.7152*ti(n.g)+.0722*ti(n.b)}function Se(n,e){let[t,r]=[oc(n),oc(e)].sort((o,i)=>i-o);return(t+.05)/(r+.05)}var tr=(n,e)=>`rgba(${Math.round(n.r)}, ${Math.round(n.g)}, ${Math.round(n.b)}, ${e})`,sc={r:0,g:0,b:0,a:1},rr={r:255,g:255,b:255,a:1};function or(n){let e=ie(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=Qe(e);for(let s of["dark","light"]){let a=n.base[s],d=ie(a.ground)[0]??(s==="dark"?sc:rr),l=ut(ie(a.panel)[0]??rr,d),c=kp(i,[l,d],s,4.5);c?Math.abs(c.l-i.l)>wp&&(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=ke(p.h,p.s,p.l),f=n.accentInk?.[s]??(Se(rr,u)>=Se(sc,u)?"#ffffff":"#000000"),h=Se(ie(f)[0]??rr,u);h+.005<4.5&&(r.add(`accentInk (${s})`),o.push(`neither black nor white clears 4.5:1 on the accent (best ${h.toFixed(2)}:1), so text on a filled button has to be given`)),t[s]={...a,accent:tr(u,1),accentDim:tr(u,s==="dark"?.35:.22),accentInk:f,glow:tr(u,s==="dark"?.28:.1),edgeBright:tr(u,vp(u,l,s==="dark"?.55:.42,3)),...n.warn?.[s]?{warn:n.warn[s]}:{}};let g=ie(t[s].warn)[0];g&&xp(Qe(g).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 vp(n,e,t,r){for(let o=Math.round(t*100);o<=100;o++){let i=o/100;if(Se(ut({...n,a:i},e),e)>=r)return i}return 1}function xp(n,e){let t=Math.abs(n-e)%360;return t>180?360-t:t}var wp=.3;function kp(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(l=>Se(ke(n.h,n.s,d),l)>=r))return{...n,l:d}}return null}function Sp(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 en=Object.freeze({navy:"#001769",turquoise:"#00e5b9",paper:"#f7f7f2",ink:"#18213a",muted:"#586174"}),ri="Montserrat",oi=Object.freeze({display:550,body:450,label:600}),ii=Object.freeze({display:600,body:400,label:600}),$p="-0.025em",Rp=Object.freeze({minWidth:140,clearSpace:.5,microMax:24,regularMin:32,microBelow:28});var ac={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:en.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},dc={ground:en.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:en.ink,inkMuted:en.muted,inkFaint:"#626b7d",accent:en.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},he={dark:ac,light:dc};var je=Object.freeze({radius:8,density:1,radiusSmall:.72,radiusSmallFloor:2,pad:15,padSmall:10,gap:7}),nn=Object.freeze({body:`"${ri}", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif`,mono:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace'});function Ap(n){let e=n?.shape?.radius??je.radius,t=n?.shape?.density??je.density;return Object.freeze({radius:e,radiusSmall:Math.max(je.radiusSmallFloor,Math.round(e*je.radiusSmall)),pad:Math.round(je.pad*t),padSmall:Math.round(je.padSmall*t),gap:Math.round(je.gap*t)})}function _p(n){let e=n?.typography?.body??nn.body,t=n?.typography?.display??e,o=e===nn.body&&t===nn.body?oi:ii,i=n?.typography?.weights;return Object.freeze({body:e,display:t,mono:n?.typography?.mono??nn.mono,weights:Object.freeze({display:i?.display??o.display,body:i?.body??o.body,label:i?.label??o.label})})}var iS=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 uc(n){return/^\s*(<\?xml[^>]*>\s*)?(<!--[\s\S]*?-->\s*)*(<!DOCTYPE svg[^>]*>\s*)?<svg[\s>/]/i.test(n)}var lc="http://www.w3.org/2000/svg",Op=["http://www.w3.org/1999/xhtml","http://www.w3.org/1998/Math/MathML",lc],Pp=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(" ")),Ep=new Set(["title","desc"]),lt="it embeds a page or media",Mp={script:"it has a script in it",foreignobject:"it embeds HTML (foreignObject)",iframe:lt,embed:lt,object:lt,audio:lt,video:lt,style:"it has a style sheet in it; a mark is styled by its attributes",a:"it links to something (an <a> element)"},zp={amp:"&",lt:"<",gt:">",quot:'"',apos:"'"};function Np(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=zp[o.toLowerCase()];return i===void 0&&(e=!0),i??""});return e?null:t}function Ip(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 Tp(n,e,t){let r=Np(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===lc?null:"it changes what its elements are (another xmlns)";if(e.startsWith("xmlns:"))return Op.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 Ip(r)?null:o==="style"?"its style loads something outside itself":"it loads or links to something outside itself"}var cc=/^\s+([A-Za-z_][A-Za-z0-9_.:-]*)\s*=\s*(?:"([^"<]*)"|'([^'<]*)')/;function fc(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 f=o.indexOf("-->",4);if(f<0)return"it has a comment that never ends";let h=o.slice(4,f);if(/^-?>/.test(h)||h.includes("--")||h.includes("<!")||h.endsWith("-"))return"it has a comment the page and the picture read differently";r+=f+3;continue}if(/^<!DOCTYPE/i.test(o)){let f=/^<!DOCTYPE\s+svg\b[^<>[\]]*>/i.exec(o);if(!f||e.length>0||t)return"it declares XML entities";r+=f[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],l=Mp[d.toLowerCase()];if(l)return l;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(!Pp.has(d))return`it has a <${d}> element, which a picture does not need`;let c=e[e.length-1];if(c&&Ep.has(c))return`it has an element inside a <${c}>, which the page reads as HTML`;let p=a[0].length;for(let f=cc.exec(o.slice(p));f;f=cc.exec(o.slice(p))){let h=Tp(d,f[1],f[2]??f[3]??"");if(h)return h;p+=f[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 pc(n){if(n){if(!uc(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 fc(n)===null?`data:image/svg+xml,${encodeURIComponent(n.trim())}`:void 0}}var ir;function jp(){if(ir===void 0)try{ir=new RegExp("^\\p{RGI_Emoji}$","v")}catch{ir=null}return ir}function Dp(n){return/\p{Extended_Pictographic}|\p{Regional_Indicator}|⃣/u.test(n)}function si(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(Dp).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=jp();return r&&!r.test(n)?"it is not one of the standard emoji every emoji set draws":null}function ai(n){return typeof n=="object"&&n!==null&&typeof n.emoji=="string"?n.emoji:void 0}function hc(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 Fp(n){let e=n?.favicon;if(typeof e=="object"&&e!==null){let t=ai(e);return t!==void 0&&si(t)===null?`data:image/svg+xml,${encodeURIComponent(hc(t))}`:void 0}return pc(e)}function Lp(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 Zp(n){if(n?.logo)return;let e=ai(n?.favicon);return e!==void 0&&si(e)===null?e:void 0}var gc={"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":nn.mono},Cp=["serif","sans-serif","monospace","cursive","fantasy","system-ui","math","emoji","-apple-system","BlinkMacSystemFont"],mc=["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 Gp=n=>new Set(n.map(e=>e.toLowerCase()));function Kp(n){return Gp([...Cp,...mc]).has(n.toLowerCase())||n.toLowerCase().startsWith("ui-")}function Vp(n){return gc[n]??n}var yc=4.5,bc={r:255,g:255,b:255,a:1},Bp={r:0,g:0,b:0,a:1},En=n=>`#${[n.r,n.g,n.b].map(e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0")).join("")}`,tn=(n,e)=>`rgba(${Math.round(n.r)}, ${Math.round(n.g)}, ${Math.round(n.b)}, ${e})`,di=(n,e,t)=>({r:n.r+(e.r-n.r)*t,g:n.g+(e.g-n.g)*t,b:n.b+(e.b-n.b)*t,a:1});function Up(n){return typeof n=="string"?{light:n}:{...n.light?{light:n.light}:{},...n.dark?{dark:n.dark}:{}}}function Wp(n){let e=ie(n)[0];if(!e)return;let{h:t,s:r}=Qe(e);return En(ke(t,Math.min(r,.45),.08))}function qp(n,e,t){let{h:r,s:o}=Qe(t),i=di(t,bc,.8);return{...n,ground:e,groundDeep:En(di(t,Bp,.04)),panel:En(i),panelMuted:En(di(t,bc,.55)),edge:tn(ke(r,Math.min(o,.5),.14),.14),bar:tn(i,.96),float:En(i)}}function Hp(n,e,t){let{h:r,s:o,l:i}=Qe(t),s=a=>ke(r,o,Math.min(1,i+a));return{...n,ground:e,groundDeep:En(ke(r,o,i*.6)),panel:tn(s(.07),.96),panelMuted:tn(s(.035),.94),edge:tn(ke(r,Math.min(o,.45),.75),.18),bar:tn(t,.96),float:tn(s(.05),.98)}}function vc(n){if(n===void 0)return he;let e=Up(n),t=e.dark??(e.light?Wp(e.light):void 0),r=e.light?ie(e.light)[0]:void 0,o=t?ie(t)[0]:void 0;return{light:r?qp(he.light,e.light,r):he.light,dark:o?Hp(he.dark,t,o):he.dark}}function fS(n,e){for(let t of["light","dark"]){let r=n[t],o=ie(r.ground)[0],i=ut(ie(r.panel)[0],o),s=[["ink",r.ink],["muted ink",r.inkMuted],["the accent",t==="light"&&e?e:r.accent]];for(let[a,d]of s){let l=ie(d)[0],c=Se(l,o),p=Se(l,i);if(c<yc)return{scheme:t,what:a,text:l,ground:o,ratio:c};if(p<yc)return{scheme:t,what:a,text:l,ground:o,card:i,ratio:p}}}return null}function yS(n,e){let t=vc(e),r=or({accent:n,base:t});return r.ok||!r.missing.every(o=>o.startsWith("warn"))?r:or({accent:n,base:t,warn:{light:he.light.bad,dark:he.dark.bad}})}function Jp(n,e,t){if(t.rows===0)return;let r=se(n,e.rows).toLowerCase(),o=se(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=H(n.tryDefinition(e.rows),e.rows);return i?`No ${a} is linked to another yet: ${s}.`:`No ${a} is linked to ${an(H(n.tryDefinition(e.columns),e.columns))} yet: ${s}.`}var ge={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 Yp(n){return n?{connectors:{all:{...ge.connectors.all,...n.connectors?.all??{}},byEdge:{...ge.connectors.byEdge,...n.connectors?.byEdge??{}}},captions:{...ge.captions,...n.captions??{}},grid:{...ge.grid,...n.grid??{}},lattice:{...ge.lattice,...n.lattice??{}},tags:{...ge.tags,...n.tags??{}},emphasis:{...ge.emphasis,...n.emphasis??{}},marks:{...ge.marks,...n.marks??{}}}:ge}function Xp(n,e){return{...n.connectors.all,...n.connectors.byEdge[e]??{}}}function Qp(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
|
-
`)}var xc=n=>n?.kind==="visitor"||n?.onBehalfOf?.kind==="visitor",sr=new WeakMap;function eh(n,e){e?sr.set(n,e):sr.delete(n)}function nh(n,e,t){if(!n||xc(t))return;let r=sr.get(n)??sr.get(ci(n)?.store??{});if(r)try{r(e,t)}catch{}}function th(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,l=new Set;for(let c of r){if(a.includes(c))for(let p of d)l.add(p);if(s.to==="*"||d.includes(c))for(let p of a)l.add(p)}if(l.size===0)return{ok:!1,at:o};r=l}return{ok:!0,reached:r}}export{un as a,Fs as b,Ls as c,bu as d,Cr as e,Kn as f,Vn as g,L as h,py as i,hy as j,Ke as k,gy as l,my as m,yy as n,Gr as o,by as p,Pe as q,ln as r,vy as s,xy as t,wy as u,qs as v,Hs as w,X as x,ky as y,St as z,Sy as A,$y as B,j as C,Du as D,ur as E,sn as F,ft as G,rh as H,ee as I,wc as J,kc as K,ui as L,ht as M,Sc as N,Ae as O,lr as P,li as Q,fr as R,Ac as S,_c as T,me as U,Oc as V,Pc as W,Ec as X,Mc as Y,zc as Z,Fn as _,hi as $,gi as aa,Ic as ba,hr as ca,C as da,Tc as ea,V as fa,jc as ga,se as ha,Dc as ia,Fc as ja,mt as ka,an as la,H as ma,Fu as na,$t as oa,Br as pa,Js as qa,Ys as ra,Xs as sa,Lu as ta,Bn as ua,ea as va,Rb as wa,At as xa,rc as ya,Zk as za,Vu as Aa,Uu as Ba,ra as Ca,Wu as Da,Pb as Ea,Un as Fa,qu as Ga,Ju as Ha,Eb as Ia,Mb as Ja,Yu as Ka,ia as La,lp as Ma,_t as Na,Xu as Oa,pn as Pa,qn as Qa,Ot as Ra,Ib as Sa,hn as Ta,fn as Ua,fa as Va,nl as Wa,Hr as Xa,Hn as Ya,Ve as Za,Zb as _a,Jr as $a,Et as ab,rl as bb,mn as cb,z as db,Yn as eb,M as fb,U as gb,Q as hb,al as ib,It as jb,cv as kb,dl as lb,cl as mb,pp as nb,Tt as ob,re as pb,D as qb,W as rb,ze as sb,Ne as tb,xv as ub,$a as vb,vn as wb,I as xb,xn as yb,Ue as zb,oe as Ab,hl as Bb,fe as Cb,Ql as Db,Mo as Eb,hd as Fb,An as Gb,Dx as Hb,No as Ib,bd as Jb,vd as Kb,Io as Lb,Te as Mb,Po as Nb,rt as Ob,df as Pb,xd as Qb,Lv as Rb,za as Sb,Zv as Tb,Cv as Ub,lf as Vb,hf as Wb,jo as Xb,Fo as Yb,Lo as Zb,Zo as _b,_d as $b,Bt as ac,vf as bc,Ut as cc,qe as dc,ei as ec,hp as fc,it as gc,_n as hc,qk as ic,Hk as jc,Dt as kc,ho as lc,mo as mc,Da as nc,vl as oc,Fa as pc,$l as qc,Sp as rc,ri as sc,$p as tc,he as uc,nn as vc,Ap as wc,_p as xc,uc as yc,fc as zc,pc as Ac,Fp as Bc,Lp as Cc,Zp as Dc,Kp as Ec,Vp as Fc,vc as Gc,fS as Hc,yS as Ic,Jo as Jc,Vf as Kc,Jp as Lc,Yp as Mc,Xp as Nc,Qp as Oc,Rl as Pc,Al as Qc,_l as Rc,Ol as Sc,He as Tc,tt as Uc,pe as Vc,nt as Wc,Je as Xc,Sn as Yc,Ct as Zc,$n as _c,Bl as $c,Pl as ad,El as bd,xc as cd,eh as dd,nh as ed,th as fd,Of as gd,Pf as hd,ud as id,Ef as jd,Wd as kd,On as ld,Wo as md,If as nd,Tf as od,jf as pd,qd,Ho as rd,Df as sd,Ff as td,we as ud,dt as vd,Lf as wd,Zf as xd,Hd as yd,Cf as zd,Gf as Ad,Jd as Bd,ct as Cd,Bf as Dd,Xd as Ed,Qd as Fd,Wf as Gd,qf as Hd,Hf as Id,Jf as Jd,ec as Kd,Yf as Ld,Xf as Md,Qf as Nd,ep as Od,np as Pd,tp as Qd,Xo as Rd,rp as Sd,op as Td,ip as Ud,sp as Vd,ap as Wd,dp as Xd,cp as Yd};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import{a as _,b as C,c as I,d as j,e as P,f as F,g as T,i as M}from"./chunk.F5RN6YXG.js";import"./chunk.AJZBJBMO.js";var J=0,q=1,Q=2,Z=3,H=1,ee=2,B=3,te=1,ne=3,re=8,G="~",N=r=>typeof r=="object"&&r!==null&&!Array.isArray(r),U=new Set(["input","select","textarea","option"]),oe=new Set(["value","checked","selected"]),V=["aria-label","aria-labelledby","title"],ie=r=>V.some(t=>(r.getAttribute(t)??"").trim()!=="");function W(r,t){let u=r.ownerDocument??r,p=t.maxNodes??5e3,g=[],m=new Map,w=new WeakMap,k={dom:r,name:"div",namespace:"html",children:[],id:G};m.set(G,k);let x=0,D=!1,O=new WeakMap,R=new Map,n=e=>{g.push(e),g.length>200&&g.shift(),t.onRefused?.(e)},a=()=>({dom:u.createComment(""),children:[],refused:!0}),f=(e,l)=>{if(e.namespace==="html"&&e.name&&U.has(e.name))return e.dom;if(l?.namespace==="html"&&l.name==="textarea")return l.dom},E=(e,l)=>{let d=e.dom,s=O.get(d)??d.getAttribute("role");if(s===null||!s.split(/\s+/).some(i=>_.includes(i.toLowerCase())))return void O.delete(d);if(ie(d)){O.delete(d),d.getAttribute("role")!==s&&d.setAttribute("role",s);return}O.set(d,s),d.removeAttribute("role"),l&&n({reason:"value",element:e.name,name:"role"})},b=(e,l,d,s=!0)=>{let i=e.dom;if(d!=null&&typeof d!="string")return n({reason:"value",element:e.name,name:l});let o=M(e.namespace,e.name,l,d??null,t);if("refused"in o){let S=M(e.namespace,e.name,l,null,t);return"refused"in S||i.removeAttribute(S.name),!("refused"in S)&&S.name==="role"&&O.delete(i),n(o.refused)}for(let S of o.dropped??[])n(S);let v=e.namespace==="html"&&oe.has(o.name)&&U.has(e.name),c=i,y=v?o.name==="value"?c.value:o.name==="checked"?c.checked:c.selected:void 0;o.name==="role"&&O.delete(i),o.value===null?i.removeAttribute(o.name):i.setAttribute(o.name,o.value),s&&(o.name==="role"||V.includes(o.name))&&E(e,o.name==="role"),t.onAttribute?.(i,o.name),v&&(o.name==="value"&&"value"in c?(c.value=o.value??"",y!==c.value&&t.onFieldSet?.(i)):o.name==="checked"&&"checked"in c?(c.checked=o.value!==null,y!==c.checked&&t.onFieldSet?.(i)):o.name==="selected"&&"selected"in c&&(c.selected=o.value!==null,y!==c.selected&&t.onFieldSet?.(i.parentElement?.closest("select")??i)))},h=e=>{if(!e.refused){x-=1,e.id!==void 0&&m.delete(e.id);for(let l of e.children)h(l)}},A=(e,l)=>{if(!N(e)||typeof e.id!="string"||m.has(e.id))return n({reason:"record"}),a();if(x>=p)return n({reason:"budget"}),D||(D=!0,t.onOverBudget?.()),a();let d=e.id;if(e.type===re)return a();if(e.type===ne){if(T(l.namespace,l.name))return n({reason:"child",element:l.name}),a();let c=u.createTextNode(String(e.data??"").slice(0,C)),y={dom:c,children:[],text:!0,id:d,parent:l};return m.set(d,y),w.set(c,d),x+=1,y}if(e.type!==te)return n({reason:"record"}),a();let s=String(e.element);if(T(l.namespace,l.name))return n({reason:"child",element:s}),a();let i=F(s,l.namespace);if("refused"in i)return n(i.refused),a();let o=u.createElementNS(i.namespace==="svg"?j:I,i.name);i.as&&o.setAttribute("data-graview-as",i.as),i.namespace==="html"&&i.name==="img"&&o.setAttribute("referrerpolicy","no-referrer"),i.namespace==="html"&&i.name==="a"&&(o.setAttribute("target","_blank"),o.setAttribute("rel","noopener noreferrer"),o.setAttribute("referrerpolicy","no-referrer"));let v={dom:o,name:i.name,namespace:i.namespace,children:[],id:d,parent:l};if(m.set(d,v),w.set(o,d),x+=1,N(e.attributes)){for(let[c,y]of Object.entries(e.attributes))b(v,c,y,!1);E(v,!0)}if(t.decorate?.(o,i.name,i.namespace),N(e.properties))for(let c of Object.keys(e.properties))n({reason:"attribute",element:i.name,name:c});if(N(e.eventListeners))for(let c of Object.keys(e.eventListeners))e.eventListeners[c]!=null&&n({reason:"attribute",element:i.name,name:`on${c}`});if(Array.isArray(e.children))for(let c of e.children){let y=A(c,v);v.children.push(y),o.appendChild(y.dom)}return v},L=e=>{if(!Array.isArray(e))return n({reason:"record"});let[l,d]=e,s=typeof d=="string"?m.get(d):void 0;if(!s)return n({reason:"record"});switch(l){case J:{if(s.text)return n({reason:"record"});let i=Number(e[3]),o=Number.isInteger(i)&&i>=0&&i<=s.children.length?i:s.children.length,v=e[2],c=N(v)&&typeof v.id=="string"?R.get(v.id):void 0,y;c&&c.parent?.namespace===s.namespace&&!T(s.namespace,s.name)?(R.delete(v.id),c.parent=s,y=c):y=A(v,s),s.dom.insertBefore(y.dom,s.children[o]?.dom??null),s.children.splice(o,0,y),s.namespace==="html"&&s.name==="textarea"&&t.onFieldSet?.(s.dom);return}case q:{let i=Number(e[2]),o=s.children[i];if(!o)return n({reason:"record"});s.children.splice(i,1),o.dom.parentNode?.removeChild(o.dom),o.id!==void 0&&!o.refused?R.set(o.id,o):h(o);return}case Q:{if(!s.text)return n({reason:"record"});s.dom.data=String(e[2]??"").slice(0,C);let i=f(s,s.parent);i&&t.onFieldSet?.(i);return}case Z:{if(s===k||s.text)return n({reason:"record"});let i=String(e[2]),o=e[4]??H;return o===ee?b(s,i,e[3]):n(o===H||o===B?{reason:"attribute",element:s.name,name:o===B?`on${i}`:i}:{reason:"record"})}default:return n({reason:"record"})}};return{apply(e,l){if(!Array.isArray(e))return n({reason:"record"}),!0;try{for(let d=0;d<e.length;d+=1){if(l&&d%32===0&&l())return!1;L(e[d])}return!0}finally{for(let d of R.values())h(d);R.clear()}},get refused(){return g},get size(){return x},idOf:e=>w.get(e),elementOf(e){let l=m.get(e);return l&&!l.text&&l!==k?l.dom:void 0},dispose(){for(let e of k.children)h(e);for(k.children.length=0;r.firstChild;)r.removeChild(r.firstChild)}}}var $=["https:","mailto:","tel:"];function K(r){if(!(typeof r!="string"||r.length>2e3||/[\s<>"]/.test(r.trim())||r.trim()!==r))try{let t=new URL(r);return!$.includes(t.protocol)||t.protocol==="https:"&&(t.hostname===""||t.username!==""||t.password!=="")?void 0:t.href}catch{return}}function ae(r){let t=new Set,u=p=>{if(typeof p!="string"||!/^(https|mailto|tel):/i.test(p))return;let g=K(p);g&&t.add(g)};for(let p of[...r?.node?[r.node]:[],...r?.nodes??[]])for(let[g,m]of Object.entries(p))g==="id"||g==="kind"||(Array.isArray(m)?m.forEach(u):u(m));return t}function z(r){return(r??[]).flatMap(t=>{try{let u=new URL(t);return u.protocol==="https:"&&u.hostname!==""&&u.username===""&&u.password===""?[u.origin]:[]}catch{return[]}})}function se(r,t){let u=K(r);if(u&&(t.handed.has(u)||u.startsWith("https:")&&z(t.origins).includes(new URL(u).origin)))return u}function de(r,t){let u=r.length>120?`${r.slice(0,119)}\u2026`:r,p="";try{p=new URL(r).protocol}catch{p=""}if(!$.includes(p))return`The link "${u}" was not drawn: a view links only to an https:, mailto: or tel: address.`;let g=z(t);return`The link "${u}" was not drawn: it is no address this view was handed. A view links out only to an address a record it was shown holds (a url field), as the record holds it${g.length>0?`, or an https: address on ${g.join(", ")}`:""}; a record or a place of this app is <a data-record> or <a data-place>.`}var le=`
|
|
2
|
-
:host { display: block; position: relative; contain: layout paint style; isolation: isolate; overflow: clip; min-width: 0; }
|
|
3
|
-
:host(:focus-within) { overflow-clip-margin: var(--graview-ring-reach, 4px); }
|
|
4
|
-
[data-graview-view-root] { display: flow-root; color: var(--graview-ink, CanvasText); font-family: var(--graview-font-body, system-ui, sans-serif); line-height: 1.45; }
|
|
5
|
-
:where([data-graview-view-root]) :where(button) { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; text-align: inherit; appearance: none; cursor: pointer; }
|
|
6
|
-
:where([data-graview-view-root]) :where(a[data-graview-link]) { color: inherit; text-decoration: none; }
|
|
7
|
-
[data-graview-view-root] :is([data-graview-link], [data-graview-press]) { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: rgb(128 128 128 / 0.16); }
|
|
8
|
-
[data-graview-view-root] :focus-visible { outline: max(2px, var(--graview-focus-width, 2px)) solid var(--graview-focus-color, var(--graview-accent, Highlight)) !important; outline-offset: var(--graview-focus-offset, 2px) !important; }
|
|
9
|
-
[data-graview-view-root] [data-graview-ring-inside]:focus-visible { outline-offset: calc(-1 * max(2px, var(--graview-focus-width, 2px))) !important; }
|
|
10
|
-
[data-graview-view-root] .graview-sr { position: absolute !important; width: 1px !important; height: 1px !important; margin: -1px !important; padding: 0 !important; border: 0 !important; overflow: hidden !important; clip-path: inset(50%) !important; white-space: nowrap !important; }
|
|
11
|
-
[data-graview-view-root] a[href]:not([data-graview-link])::after { content: " \u2197" !important; content: " \u2197" / " (opens in a new tab)" !important; }
|
|
12
|
-
@layer graview-motion { @media (prefers-reduced-motion: reduce) { [data-graview-view-root] *, [data-graview-view-root] ::before, [data-graview-view-root] ::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; animation-timeline: auto !important; transition-duration: 1ms !important; scroll-behavior: auto !important; } } }
|
|
13
|
-
`,X=4,ce=16;function ue(r){let t=r.ownerDocument.defaultView?.getComputedStyle(r);if(!t)return X;let u=Number.parseFloat(t.outlineWidth)||0,p=Math.max(0,Number.parseFloat(t.outlineOffset)||0);return Math.min(ce,Math.max(X,Math.ceil(u+p)))}var fe=new Set(["Enter"," ","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"]),Y=["click","input","change","keydown"];function we(r,t){let u=r.ownerDocument,p=u.createElement("style");p.setAttribute("data-graview-region",""),p.textContent=le;let g=u.createElement("style");g.setAttribute("data-graview-view-style","");let m=u.createElement("div");m.setAttribute("data-graview-view-root",""),r.append(p,g,m);let w=W(m,{origin:t.origin,...t.asset?{asset:t.asset}:{},...t.imageOrigins?{imageOrigins:t.imageOrigins}:{},...t.picture?{picture:t.picture}:{},...t.link?{link:t.link}:{},...t.onRefused?{onRefused:t.onRefused}:{},...t.maxNodes!==void 0?{maxNodes:t.maxNodes}:{},...t.onOverBudget?{onOverBudget:t.onOverBudget}:{},decorate:(n,a,f)=>{f==="html"&&a==="button"&&n.setAttribute("type","button"),f==="html"&&(a==="input"||a==="textarea"||a==="select")&&n.setAttribute("autocomplete","off"),t.decorate?.(n,a,f)},...t.onFieldSet?{onFieldSet:t.onFieldSet}:{},...t.onAttribute?{onAttribute:t.onAttribute}:{}}),k=[],x="",D=n=>{for(let a=n.composedPath()[0];a&&a!==m&&a!==r;a=a.parentNode)if(a.nodeType===1&&w.idOf(a)!==void 0)return a},O=n=>{let a=D(n);if(!a||n.type==="keydown"&&!fe.has(n.key))return;let f=t.before?.(n,a,m);if(f===!1)return;let E=a,b=a.namespaceURI==="http://www.w3.org/1999/xhtml"&&["input","select","textarea"].includes(a.localName);t.send({type:"dom-event",target:w.idOf(a),event:n.type,...b?{value:String(E.value??"")}:{},...b&&(E.type==="checkbox"||E.type==="radio")?{checked:E.checked}:{},...n.type==="keydown"?{key:n.key}:{},...f??{}});let h=n.type==="keydown"?n.key:void 0;(h==="Enter"||h===" ")&&a.hasAttribute("data-graview-press")&&n.composedPath()[0]===a&&(n.preventDefault(),t.send({type:"dom-event",target:w.idOf(a),event:"click"}))};for(let n of Y)r.addEventListener(n,O);r.addEventListener("toggle",O,!0);let R=typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("overflow-clip-margin","4px");return r.addEventListener("focusin",n=>{let a=n.composedPath()[0],f=r.host;if(!a||a.nodeType!==1||!m.contains(a))return;let E=ue(a);if(R){f.style.setProperty("--graview-ring-reach",`${E}px`);return}let b=f.getBoundingClientRect(),h=a.getBoundingClientRect(),A=E*(f.offsetWidth>0?b.width/f.offsetWidth:1),L=h.left-b.left<A||b.right-h.right<A||h.top-b.top<A||b.bottom-h.bottom<A;a.toggleAttribute("data-graview-ring-inside",L)}),{apply(n,a){let f=r.activeElement,E=f?w.idOf(f):void 0,b=w.apply(n,a);if(E!==void 0&&r.activeElement!==f){let h=w.elementOf(E);h?.isConnected&&typeof h.focus=="function"&&h.focus({preventScroll:!0})}return b},style(n){let a=P(n);k.length=0;for(let f of a.refused)k.push({reason:"css",name:"stylesheet",css:f}),k.length>200&&k.shift();x=a.css,g.textContent=x},renderer:w,get refused(){return[...w.refused,...k]},get css(){return x},dispose(){for(let n of Y)r.removeEventListener(n,O);r.removeEventListener("toggle",O,!0),w.dispose(),r.replaceChildren()}}}export{le as REGION_CSS,we as createOpenDrawing,ae as handedLinks,se as judgeLink,de as linkRefusedWords,ue as ringReach};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as I,b as H,c as T,e as D,h as V,i as R,j as A,k,l as x,n as Y,o as Z}from"./chunk.MSM6E6JK.js";import{b as U}from"./chunk.MIQMPOWF.js";import{I as C,O as G,Wa as F,X as M,_a as B,da as W,fa as j}from"./chunk.WR63RQGU.js";function re(e,r){return e===void 0||e===!0?!0:e===!1?!1:e[r]!==!1}function te(e){let r={};return e.query&&e.query.trim().length>0&&(r.q=e.query),e.archived!==void 0&&e.archived!==!1&&(r.archived=String(e.archived)),e.sort&&(r.sort=e.sort.direction==="desc"?`${e.sort.by}:desc`:e.sort.by),e.filter?.length&&(r.filter=e.filter.map(n=>`${n.key}:${n.value}`).join(",")),e.group&&(r.group=e.group.bucket?`${e.group.by}:${e.group.bucket}`:e.group.by),r}function ne(e,r){let n=[],s={};if(e.query&&(s.query=e.query),e.archived!==void 0&&e.archived!==!1&&(s.archived=e.archived),e.sort&&(r.sorts.some(u=>u.key===e.sort.by)?s.sort=e.sort:n.push(`sort ${e.sort.by}`)),e.filter){let u=e.filter.filter(c=>r.filters.find(f=>f.key===c.key)?!0:(n.push(`filter ${c.key}`),!1));u.length>0&&(s.filter=u)}return e.group&&(r.groups.some(u=>u.key===e.group.by)?s.group=e.group:n.push(`group ${e.group.by}`)),{arrangement:s,dropped:n}}function S(e,r){return W(e.schema.tryDefinition(r.kind),A(r))}var oe=(e,r)=>e==null?r==null?0:1:r==null?-1:typeof e=="number"&&typeof r=="number"?e-r:typeof e=="boolean"&&typeof r=="boolean"?e===r?0:e?1:-1:String(e).localeCompare(String(r),void 0,{numeric:!0,sensitivity:"base"});function ie(e,r,n){if(n==="label")return S(e,r);let s=e.schema.tryDefinition(r.kind);return s&&n in(s.fields.shape??{})?F(R(r),n,e.today??C()):s?.computed?.[n]!==void 0?e.read?.(r,n):k(e.graph,r.id,n).map(c=>S(e,c)).sort()[0]}var se=/^(\d{4})-(\d{2})-(\d{2})/;function _(e,r){let n=se.exec(e);if(!n)return;let[,s,u,c]=n;if(r==="day")return`${s}-${u}-${c}`;if(r==="month")return`${s}-${u}-01`;if(r==="year")return`${s}-01-01`;if(r==="decade")return`${String(Number(s)-Number(s)%10).padStart(4,"0")}-01-01`;let a=new Date(Date.UTC(Number(s),Number(u)-1,Number(c))),f=(a.getUTCDay()+6)%7;return a.setUTCDate(a.getUTCDate()-f),a.toISOString().slice(0,10)}function de(e,r){return r==="month"?M(e):r==="week"?`Week of ${G(e)}`:r==="year"?e.slice(0,4):r==="decade"?`The ${e.slice(0,4)}s`:G(e)}function ue(e,r,n){return z(e,n)(r)}function z(e,r){let{words:n,conditions:s}=Y(r);if(n.length===0&&s.length===0)return()=>!0;let u=new Map,c=a=>{let f=u.get(a);return f||(f=new Set(D(e.schema,a).filters.map(d=>d.key)),u.set(a,f)),f};return a=>{let f=c(a.kind),d=s.filter(i=>f.has(i.key));return d.every(i=>x(e,a,i))?n.length>0?Z(e.schema.tryDefinition(a.kind),A(a),n,e.searchIn)!==void 0:d.length>0:!1}}function ae(e,r,n){let s=r.query?.trim(),u=r.archived===void 0?e:e.filter(t=>B(t,r.archived)),c=s?u.filter(z(n,s)):u,a=r.filter?.length?c.filter(t=>r.filter.every(l=>x(n,t,l))):[...c],f=[];for(let t=r.sort;t&&f.length<4;t=t.then)f.push(t);let d=f.length>0?a.map((t,l)=>({node:t,index:l,values:f.map(o=>ie(n,t,o.by))})).sort((t,l)=>{for(let[o,p]of f.entries()){let[h,K]=[t.values[o],l.values[o]],v=oe(h,K),E=p.direction==="desc"&&v!==0&&h!==void 0&&K!==void 0?-v:v;if(E!==0)return E}return t.index-l.index}).map(t=>t.node):a,i=r.group;if(!i)return{nodes:d,groups:[{key:"",label:"",nodes:d}],grouped:!1};let y=new Map,g=(t,l,o)=>{let p=y.get(t)??{label:l,nodes:[]};p.nodes.push(o),y.set(t,p)},N=d[0],m=N?n.schema.tryDefinition(N.kind):void 0,O=m?.fields.shape??{},J=m?I(m,i.by):j(i.by),$=i.by in O,b=$?H(O[i.by]):void 0,X=T(n.schema,N?.kind??"").find(t=>t.key===i.by)?.label,L=$?`No ${J.toLowerCase()}`:`Without ${(X??j(i.by)).toLowerCase()}`,q=$?new Map:U([...new Map(d.flatMap(t=>k(n.graph,t.id,i.by)).map(t=>[t.id,t])).values()].map(A),t=>n.schema.tryDefinition(t));for(let t of d){if($){let o=F(R(t),i.by,n.today??C());if(o==null||o==="")g("",L,t);else if(b==="date"){let p=i.bucket??"day",h=_(String(o),p);h?g(h,de(h,p),t):g("",L,t)}else if(b==="boolean")g(o?"1":"0",o?"Yes":"No",t);else{let p=m?.display?.format?.[i.by];g(String(o),p?p(o):String(o),t)}continue}let l=k(n.graph,t.id,i.by).map(o=>({id:o.id,label:q.has(o.id)?`${S(n,o)} \xB7 ${q.get(o.id)}`:S(n,o)})).sort((o,p)=>o.label.localeCompare(p.label));l.length===0?g("",L,t):g(l.map(o=>o.id).join(","),l.map(o=>o.label).join(", "),t)}let w=b==="choice"?V(O[i.by]):void 0,ee=[...y.entries()].sort(([t,l],[o,p])=>t===""?1:o===""?-1:w?w.indexOf(t)-w.indexOf(o):b==="boolean"?o.localeCompare(t):b==="date"?t.localeCompare(o):l.label.localeCompare(p.label)).map(([t,l])=>({key:t,label:l.label,nodes:l.nodes}));return{nodes:d,groups:ee,grouped:!0}}function P(e){if(e===void 0)return;if(typeof e=="string")return{by:e,direction:"asc"};let r=e.then===void 0?void 0:typeof e.then=="string"?{by:e.then,direction:"asc"}:{by:e.then.by,direction:e.then.direction??"asc"};return{by:e.by,direction:e.direction??"asc",...r?{then:r}:{}}}function Q(e){if(e!==void 0)return typeof e=="string"?{by:e}:e}function fe(e){let r=P(e?.sort),n=Q(e?.group);if(!(!r&&!n))return{...r?{sort:r}:{},...n?{group:{by:n.by}}:{}}}var le=(e,r)=>r?e==="1"?"true":"false":e;function ce(e,r,n){let s=n.type==="boolean",u=s?["true","false"]:n.options??[],c=[...new Set([...(r.order??[]).filter(d=>u.includes(d)),...u])],a=r.closed??[],f=d=>{if(d.key==="")return[1,0];let i=le(d.key,s);if(a.includes(i))return[2,a.indexOf(i)];let y=c.indexOf(i);return[0,y<0?c.length:y]};return e.map((d,i)=>({group:d,at:i,rank:f(d)})).sort((d,i)=>d.rank[0]-i.rank[0]||d.rank[1]-i.rank[1]||d.at-i.at).map(({group:d,rank:i})=>({...d,closed:i[0]===2}))}export{Q as a,fe as b,ce as c,re as d,te as e,ne as f,ue as g,ae as h};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{k as a,l as b,m as c,n as d,o as e,p as f,q as g,r as h,s as i}from"./chunk.35O5H5L7.js";import"./chunk.BJUUSIQY.js";import"./chunk.BRCKXL7B.js";import"./chunk.CPNE6HPQ.js";import"./chunk.EKP3HQAX.js";import"./chunk.XOZU4OFA.js";import"./chunk.QQ3YWKWU.js";import"./chunk.IXHLP2CL.js";import"./chunk.DXJFAAOI.js";import"./chunk.5EZDXWOE.js";import"./chunk.MIQMPOWF.js";import"./chunk.T66UK7PQ.js";import"./chunk.LMXNHBGH.js";import"./chunk.DBCVZGCC.js";import"./chunk.WSMYFEGU.js";import"./chunk.SDO3U72B.js";import"./chunk.WR63RQGU.js";import"./chunk.FQLNBIQ5.js";import"./chunk.AJZBJBMO.js";export{i as GhostTray,h as InlineAiMenu,g as askAgain,c as askInline,a as askOf,b as drawPanel,d as heldSuggestion,e as suggestOnce,f as takeOffer};
|