graview 0.1.50 → 0.1.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/dist/preview/{chunk.V5IWJ3ZV.js → chunk.2534FLZZ.js} +1 -1
  2. package/dist/preview/{chunk.QSZLY62B.js → chunk.2VJ52LGS.js} +1 -1
  3. package/dist/preview/{chunk.U2M4SGUU.js → chunk.2W2YVB6X.js} +1 -1
  4. package/dist/preview/{chunk.ECSWXLBI.js → chunk.2W45NM7Q.js} +2 -2
  5. package/dist/preview/chunk.32BOL7OL.js +1 -0
  6. package/dist/preview/chunk.34HGT7HQ.js +1 -0
  7. package/dist/preview/{chunk.YUV7HZYG.js → chunk.353CGK6C.js} +1 -1
  8. package/dist/preview/{chunk.64TFAR5Z.js → chunk.3H7YIKKC.js} +1 -1
  9. package/dist/preview/{chunk.Q7RI4SI4.js → chunk.3MU37W5D.js} +1 -1
  10. package/dist/preview/chunk.3SBTQ66X.js +1 -0
  11. package/dist/preview/{chunk.L5MDUZLQ.js → chunk.3TVAE7LE.js} +1 -1
  12. package/dist/preview/{chunk.ETX4QMM2.js → chunk.4EZFOZBA.js} +1 -1
  13. package/dist/preview/chunk.4N5R4K6O.js +1 -0
  14. package/dist/preview/{chunk.KGGWFL54.js → chunk.4T67XS2D.js} +1 -1
  15. package/dist/preview/chunk.5ON3JSAK.js +1 -0
  16. package/dist/preview/{chunk.YEKHDZ45.js → chunk.5ZAK57JA.js} +2 -2
  17. package/dist/preview/chunk.6KYWJXZR.js +1 -0
  18. package/dist/preview/{chunk.BJAQRV2R.js → chunk.76QSPWSJ.js} +1 -1
  19. package/dist/preview/{chunk.3SY6WWWQ.js → chunk.7G4M2PX3.js} +2 -2
  20. package/dist/preview/{chunk.XWLGHTH6.js → chunk.7GAC7U34.js} +1 -1
  21. package/dist/preview/{chunk.GDYI5QDS.js → chunk.7NQROWHU.js} +1 -1
  22. package/dist/preview/{chunk.LGHMUUTG.js → chunk.7RIFDWDF.js} +1 -1
  23. package/dist/preview/{chunk.MQISKON2.js → chunk.ACB4TD4W.js} +1 -1
  24. package/dist/preview/chunk.AJAMTRZ3.js +1 -0
  25. package/dist/preview/chunk.AL45OI4A.js +1 -0
  26. package/dist/preview/{chunk.WGRF6EHC.js → chunk.AL7LFNOS.js} +1 -1
  27. package/dist/preview/{chunk.ZBBCUK2K.js → chunk.ALCH5H7U.js} +1 -1
  28. package/dist/preview/{chunk.UOC3SIYT.js → chunk.APFRPN5S.js} +1 -1
  29. package/dist/preview/{chunk.ODHCSYXX.js → chunk.AZOW57MT.js} +1 -1
  30. package/dist/preview/chunk.B4PUI3GO.js +1 -0
  31. package/dist/preview/chunk.B6LKLV32.js +1 -0
  32. package/dist/preview/{chunk.UDTBFAS5.js → chunk.B7LBG4UP.js} +1 -1
  33. package/dist/preview/{chunk.YCJ74LZS.js → chunk.BV6HKTHK.js} +1 -1
  34. package/dist/preview/{chunk.UN2OB6OD.js → chunk.BYY7YXBI.js} +1 -1
  35. package/dist/preview/{chunk.7QW6JYGP.js → chunk.CI4DEKPX.js} +1 -1
  36. package/dist/preview/{chunk.ZOQ3OKKI.js → chunk.CMEETACI.js} +1 -1
  37. package/dist/preview/{chunk.O6SKKF4V.js → chunk.CQPNDJAC.js} +1 -1
  38. package/dist/preview/{chunk.FFPG4PHX.js → chunk.CTOBNZLM.js} +1 -1
  39. package/dist/preview/chunk.CUB4IAUJ.js +1 -0
  40. package/dist/preview/chunk.CUN4VN42.js +1 -0
  41. package/dist/preview/chunk.CV55N3Y6.js +1 -0
  42. package/dist/preview/{chunk.M55U47A6.js → chunk.CXC5FOIO.js} +1 -1
  43. package/dist/preview/{chunk.DUJUJN35.js → chunk.DEH6O3K4.js} +1 -1
  44. package/dist/preview/chunk.DQNN5FE5.js +1 -0
  45. package/dist/preview/{chunk.4SHSEIHT.js → chunk.DUY27OJV.js} +1 -1
  46. package/dist/preview/chunk.E2R6VFZX.js +1 -0
  47. package/dist/preview/{chunk.KZ3UPV2L.js → chunk.EA2NMVRE.js} +1 -1
  48. package/dist/preview/chunk.ESK3UZRC.js +1 -0
  49. package/dist/preview/{chunk.IMFAPZ6J.js → chunk.ESSENNHM.js} +2 -2
  50. package/dist/preview/{chunk.5DZR46YG.js → chunk.ET3XJDPX.js} +1 -1
  51. package/dist/preview/chunk.FEIJ7ETK.js +1 -0
  52. package/dist/preview/{chunk.4XOSDCCE.js → chunk.FFCUZPTC.js} +1 -1
  53. package/dist/preview/chunk.FG5ZFYYL.js +1 -0
  54. package/dist/preview/{chunk.KFHXTHIY.js → chunk.FKJ3HIA5.js} +1 -1
  55. package/dist/preview/chunk.FTBH7CPZ.js +1 -0
  56. package/dist/preview/{chunk.LDE5HLTM.js → chunk.FU4YSVWX.js} +1 -1
  57. package/dist/preview/{chunk.A53G42QO.js → chunk.FYDDFOSD.js} +1 -1
  58. package/dist/preview/{chunk.ETWREHXF.js → chunk.GJQF7I22.js} +1 -1
  59. package/dist/preview/{chunk.6SHF6IL5.js → chunk.GLTWLQ6L.js} +1 -1
  60. package/dist/preview/chunk.GMAXA5GV.js +1 -0
  61. package/dist/preview/{chunk.SRU2YDTJ.js → chunk.GRYS6VSF.js} +1 -1
  62. package/dist/preview/{chunk.ZK446PSX.js → chunk.GYTVL6GR.js} +3 -3
  63. package/dist/preview/chunk.HASVT7IC.js +1 -0
  64. package/dist/preview/{chunk.RK6BK5FD.js → chunk.HFKGND5Q.js} +1 -1
  65. package/dist/preview/{chunk.JJP5OL5E.js → chunk.HVX7LFWR.js} +1 -1
  66. package/dist/preview/chunk.IBJBCZKG.js +1 -0
  67. package/dist/preview/{chunk.CDZVUCEK.js → chunk.IE4ZJQV3.js} +1 -1
  68. package/dist/preview/chunk.IFL2MYTQ.js +1 -0
  69. package/dist/preview/{chunk.F7AFJRPP.js → chunk.IUIDDNN3.js} +1 -1
  70. package/dist/preview/{chunk.RXJBYP7B.js → chunk.JBR66TUP.js} +1 -1
  71. package/dist/preview/chunk.JG2FGZF2.js +18 -0
  72. package/dist/preview/{chunk.7VX6TBNY.js → chunk.JI2UVZUU.js} +1 -1
  73. package/dist/preview/{chunk.OB7XLVK6.js → chunk.JMDKAP23.js} +1 -1
  74. package/dist/preview/{chunk.IDQHSAAQ.js → chunk.JX2C3HVD.js} +1 -1
  75. package/dist/preview/{chunk.FKUVIG6D.js → chunk.K7ECYKZL.js} +1 -1
  76. package/dist/preview/{chunk.UGJ32SEL.js → chunk.K7RKWB2K.js} +1 -1
  77. package/dist/preview/{chunk.S64LCR23.js → chunk.KK46XLGU.js} +1 -1
  78. package/dist/preview/chunk.KOBCLWPC.js +1 -0
  79. package/dist/preview/chunk.KRODTMGR.js +1 -0
  80. package/dist/preview/chunk.KYKHZZT7.js +1 -0
  81. package/dist/preview/chunk.LYIHPVDZ.js +1 -0
  82. package/dist/preview/{chunk.JLPBXG4P.js → chunk.MG3DMURZ.js} +1 -1
  83. package/dist/preview/{chunk.YG3BLY67.js → chunk.MMVCZOEX.js} +1 -1
  84. package/dist/preview/{chunk.BBNF52IB.js → chunk.MN6WHE4B.js} +1 -1
  85. package/dist/preview/{chunk.UJTRKSCK.js → chunk.MRXQBEPQ.js} +1 -1
  86. package/dist/preview/{chunk.NB6WN4DO.js → chunk.MX3Y3LPH.js} +1 -1
  87. package/dist/preview/{chunk.LJXAZ5TF.js → chunk.MY5OXSS7.js} +1 -1
  88. package/dist/preview/chunk.N5XONWU2.js +1 -0
  89. package/dist/preview/chunk.NNUUD26E.js +1 -0
  90. package/dist/preview/{chunk.ZITDUHX3.js → chunk.NQ26KMSQ.js} +1 -1
  91. package/dist/preview/{chunk.QFI4L2HK.js → chunk.NVRK6A7T.js} +1 -1
  92. package/dist/preview/{chunk.DUIKIJKC.js → chunk.NZDHXREL.js} +1 -1
  93. package/dist/preview/chunk.OHDJYGH7.js +2 -0
  94. package/dist/preview/{chunk.GZEZMU2T.js → chunk.OJ64WTLW.js} +2 -2
  95. package/dist/preview/{chunk.OUNLAMBA.js → chunk.OPCBZNKF.js} +1 -1
  96. package/dist/preview/{chunk.UCS3CBT4.js → chunk.OU5TRY4N.js} +1 -1
  97. package/dist/preview/chunk.OW72XZF4.js +1 -0
  98. package/dist/preview/chunk.P4CLT32V.js +5 -0
  99. package/dist/preview/chunk.PFXGWY3P.js +1 -0
  100. package/dist/preview/{chunk.GPJFNLEJ.js → chunk.PMV6XVVZ.js} +1 -1
  101. package/dist/preview/{chunk.2P66HH5Y.js → chunk.PPZ2TOB5.js} +1 -1
  102. package/dist/preview/{chunk.JC5NXMG3.js → chunk.PYRJDTVS.js} +1 -1
  103. package/dist/preview/chunk.QEQQXWYU.js +1 -0
  104. package/dist/preview/chunk.QPAJCRFB.js +1 -0
  105. package/dist/preview/chunk.R5R7CLOU.js +1 -0
  106. package/dist/preview/{chunk.SWLDDQJS.js → chunk.RMMJQYJJ.js} +1 -1
  107. package/dist/preview/{chunk.FDFVGHQE.js → chunk.RNOBACJ6.js} +1 -1
  108. package/dist/preview/{chunk.4BQNG3W3.js → chunk.S32AGJ3W.js} +1 -1
  109. package/dist/preview/chunk.S4CKKT3C.js +1 -0
  110. package/dist/preview/{chunk.KOPRZLJH.js → chunk.SJKHVIHA.js} +2 -2
  111. package/dist/preview/chunk.SJYQ72EC.js +1 -0
  112. package/dist/preview/chunk.SKG4IHT5.js +88 -0
  113. package/dist/preview/chunk.SLBWPVIY.js +1 -0
  114. package/dist/preview/{chunk.YZ6UKKEL.js → chunk.SPU3BVAO.js} +1 -1
  115. package/dist/preview/{chunk.VVRI7DNK.js → chunk.SRFZKDQ6.js} +1 -1
  116. package/dist/preview/{chunk.MRUDTYOL.js → chunk.SSAY4ITS.js} +2 -2
  117. package/dist/preview/{chunk.TY6VILZB.js → chunk.T3RTFTOZ.js} +1 -1
  118. package/dist/preview/{chunk.73BJYIYS.js → chunk.TBSPEO2L.js} +1 -1
  119. package/dist/preview/chunk.TMYGLXR6.js +25 -0
  120. package/dist/preview/{chunk.GTUBIJTP.js → chunk.TNL2BVCH.js} +1 -1
  121. package/dist/preview/{chunk.QAUZDLDA.js → chunk.TVWN5I4M.js} +1 -1
  122. package/dist/preview/{chunk.MCPLU2U4.js → chunk.U7SNDY3F.js} +1 -1
  123. package/dist/preview/chunk.UCUWEYKM.js +1 -0
  124. package/dist/preview/{chunk.T4UYLB3Y.js → chunk.UIWI4GKW.js} +1 -1
  125. package/dist/preview/{chunk.HGP3Q7QX.js → chunk.UK5F3S2N.js} +1 -1
  126. package/dist/preview/{chunk.ZKDJQDKX.js → chunk.UVAWWCFW.js} +1 -1
  127. package/dist/preview/{chunk.L2AV6JRA.js → chunk.UWFEXEY3.js} +1 -1
  128. package/dist/preview/chunk.V4GAOZAW.js +1 -0
  129. package/dist/preview/{chunk.TT6QBWRA.js → chunk.VICCAWAN.js} +1 -1
  130. package/dist/preview/{chunk.AXMC6XVT.js → chunk.W2DKFQ6R.js} +1 -1
  131. package/dist/preview/{chunk.53BGPCM6.js → chunk.WESWDXRW.js} +1 -1
  132. package/dist/preview/{chunk.QZMBEG4E.js → chunk.WFHFWJ6E.js} +1 -1
  133. package/dist/preview/{chunk.AXCRFJDL.js → chunk.WQLAIEWJ.js} +1 -1
  134. package/dist/preview/{chunk.JYJNRCK5.js → chunk.XCCBUWMC.js} +1 -1
  135. package/dist/preview/{chunk.GQX57JIE.js → chunk.XCQ7ZPR5.js} +1 -1
  136. package/dist/preview/chunk.XWXYC3BJ.js +1 -0
  137. package/dist/preview/chunk.XZVPVAIS.js +1 -0
  138. package/dist/preview/chunk.Y2ZBVWII.js +1 -0
  139. package/dist/preview/chunk.Y3LTHEN7.js +1 -0
  140. package/dist/preview/{chunk.TL7UGUY4.js → chunk.Y5AMZBHA.js} +2 -2
  141. package/dist/preview/{chunk.CR5MQMOL.js → chunk.Z7N3MJ36.js} +1 -1
  142. package/dist/preview/{chunk.SVH3OMU2.js → chunk.ZJXUWOG3.js} +1 -1
  143. package/dist/preview/{chunk.BORCUDGS.js → chunk.ZZODDJYK.js} +1 -1
  144. package/dist/preview/index.html +51 -51
  145. package/dist/preview/page.js +2 -2
  146. package/package.json +6 -6
  147. package/dist/preview/chunk.24MUPV4Y.js +0 -1
  148. package/dist/preview/chunk.2VZSC2MB.js +0 -1
  149. package/dist/preview/chunk.3L5USMQD.js +0 -1
  150. package/dist/preview/chunk.3O3H37WD.js +0 -1
  151. package/dist/preview/chunk.4VJARLJ5.js +0 -1
  152. package/dist/preview/chunk.5RNB6IC5.js +0 -1
  153. package/dist/preview/chunk.6BMCZPT6.js +0 -1
  154. package/dist/preview/chunk.6VA5XFRR.js +0 -1
  155. package/dist/preview/chunk.7PJVMADH.js +0 -2
  156. package/dist/preview/chunk.ATWNWPME.js +0 -1
  157. package/dist/preview/chunk.AVCW7C6V.js +0 -1
  158. package/dist/preview/chunk.BLS2G3CD.js +0 -5
  159. package/dist/preview/chunk.BNQL37AC.js +0 -88
  160. package/dist/preview/chunk.CBJHYNNT.js +0 -1
  161. package/dist/preview/chunk.EF3UB7US.js +0 -1
  162. package/dist/preview/chunk.EJUZGIQ5.js +0 -1
  163. package/dist/preview/chunk.F5FJHKWV.js +0 -1
  164. package/dist/preview/chunk.GQI53L5P.js +0 -1
  165. package/dist/preview/chunk.HG34MT7C.js +0 -1
  166. package/dist/preview/chunk.IATLUWAD.js +0 -1
  167. package/dist/preview/chunk.JLR74UFP.js +0 -1
  168. package/dist/preview/chunk.K4ITS63T.js +0 -1
  169. package/dist/preview/chunk.KT2LXHSI.js +0 -1
  170. package/dist/preview/chunk.M5RHVUZ6.js +0 -1
  171. package/dist/preview/chunk.MBZ6N5SO.js +0 -1
  172. package/dist/preview/chunk.N7FIUTVY.js +0 -1
  173. package/dist/preview/chunk.NPU4WYRB.js +0 -1
  174. package/dist/preview/chunk.OHAWUOUN.js +0 -1
  175. package/dist/preview/chunk.OKQ4JXTW.js +0 -1
  176. package/dist/preview/chunk.OYQ6ZA6T.js +0 -1
  177. package/dist/preview/chunk.Q7UQ5OXA.js +0 -1
  178. package/dist/preview/chunk.ROJZLOKZ.js +0 -1
  179. package/dist/preview/chunk.S7OFTGBQ.js +0 -18
  180. package/dist/preview/chunk.SGMVLKZO.js +0 -25
  181. package/dist/preview/chunk.SJRXBTGP.js +0 -1
  182. package/dist/preview/chunk.THTHNY4N.js +0 -1
  183. package/dist/preview/chunk.U6FGWVGB.js +0 -1
  184. package/dist/preview/chunk.UEL7FLL7.js +0 -1
  185. package/dist/preview/chunk.VM43YREJ.js +0 -1
  186. package/dist/preview/chunk.YAS6LXQ7.js +0 -1
  187. package/dist/preview/chunk.YEMNR4WU.js +0 -1
  188. package/dist/preview/chunk.YYS45ZGQ.js +0 -1
  189. package/dist/preview/chunk.ZI66HRES.js +0 -1
  190. package/dist/preview/chunk.ZVETGRUM.js +0 -1
  191. package/dist/preview/chunk.ZVOP2HHI.js +0 -1
@@ -1,5 +0,0 @@
1
- import{a as oi,b as pe,c as Ye,d as st,f as Ne,g as er,h as Ie,i as On}from"./chunk.EJUZGIQ5.js";var tr="en-US",Qe=/^\d{4}-\d{2}-\d{2}$/,at=/^\d{4}(-\d\d){2}[T ]\d\d:\d\d(:[\d.]+)?(Z|[+-][\d:]+)?$/,Lp=n=>!Number.isNaN(Date.parse(n)),ee=(n,e=Date.now())=>{let t=dt(n);return t?rr(e,t).day:new Date(e).toISOString().slice(0,10)},dt=n=>Xe(n)??Je,Pn,En,Mn,Je;function lc(n){Pn=zn(n.reader),En=zn(n.app),Mn=Xe(n.readerTimeZone),Je=Xe(n.appTimeZone)}function fc(n,e){let t=[Pn,En,Mn,Je];n.reader!==void 0&&(Pn=zn(n.reader)),n.app!==void 0&&(En=zn(n.app)),n.readerTimeZone!==void 0&&(Mn=Xe(n.readerTimeZone)),n.appTimeZone!==void 0&&(Je=Xe(n.appTimeZone));try{return e()}finally{[Pn,En,Mn,Je]=t}}var ii=n=>Pn??zn(n)??En??tr,ct=n=>Mn??Xe(n)??Je,pc=n=>ct(n)??Intl.DateTimeFormat().resolvedOptions().timeZone??"UTC",hc=/^\s*([+\-−]|\d)/;var nr=new Map;function Xe(n){if(n&&!nr.has(n)){let e=!1;try{new Intl.DateTimeFormat(tr,{timeZone:n}),e=!hc.test(n)}catch{}nr.set(n,e)}return n&&nr.get(n)?n:void 0}var je=new Map;function zn(n){if(n&&!je.has(n)){let e=!1;try{e=Intl.DateTimeFormat.supportedLocalesOf(n).length>0}catch{}je.set(n,e)}return n&&je.get(n)?n:void 0}function xe(n,e,t,r){let o=`${t=ii(t)}${r?"#":"@"}${JSON.stringify(e)}`,i=je.get(o);return i||je.set(o,i=r?new Intl.NumberFormat(t,e):new Intl.DateTimeFormat(t,e)),i.format(n).replace(/ /g," ")}var Te="UTC",ut=n=>Date.UTC(+n.slice(0,4),+n.slice(5,7)-1,+n.slice(8,10));function we(n,e){return Qe.test(n)?xe(ut(n),{year:"numeric",month:"short",day:"numeric",timeZone:Te},e):n}function rr(n,e){let t=`wall@${e??""}`,r=je.get(t);r||je.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 si(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=rr(i,t);return gc(s.day,s.minutes)-Math.floor(i/6e4)*6e4};return r-o(r-o(r))}var gc=(n,e)=>Date.UTC(+n.slice(0,4),+n.slice(5,7)-1,+n.slice(8,10),0,e),ai=n=>/[Z+-][\d:]*$/.test(n.slice(16));function di(n,e,t,r,o=!1){if(!at.test(n))return n;let i=ai(n),s=Date.parse(n.replace(" ","T")+(i?"":"Z"));if(Number.isNaN(s))return n;let a=i?ct(r):Te;return xe(s,{...e,hour:"numeric",minute:"2-digit",...i&&o?{timeZoneName:"short"}:{},...a?{timeZone:a}:{}},t)}var or=(n,e,t)=>di(n,{year:"numeric",month:"short",day:"numeric"},e,t,!0),mc=(n,e,t)=>di(n,{},e,t);function yc(n,e){if(Qe.test(n))return n;if(!at.test(n))return;if(!ai(n))return n.slice(0,10);let t=Date.parse(n.replace(" ","T"));return Number.isNaN(t)?void 0:rr(t,ct(e)).day}function he(n,e,t={maximumFractionDigits:2}){return Number.isFinite(n)?xe(n,t,e,!0):String(n)}function bc(n,e={},t){return Qe.test(n)?xe(ut(n),{weekday:e.weekday??"long",month:"short",day:"numeric",...e.year?{year:"numeric"}:{},timeZone:Te},t):n}function vc(n,e){return Qe.test(n)?xe(ut(n),{month:"short",day:"numeric",timeZone:Te},e):n}function xc(n,e={},t){if(!/^\d{4}-\d{2}/.test(n))return n;let r=e.year??!e.short;return xe(ut(`${n.slice(0,7)}-01`),{month:e.short?"short":"long",...r?{year:e.short?"2-digit":"numeric"}:{},timeZone:Te},t)}var wc=(n,e="short",t)=>xe(Date.UTC(1970,0,4+n),{weekday:e,timeZone:Te},t),kc=(n,e)=>xe(Date.UTC(1970,0,1,0,Math.round(n)),{hour:"numeric",minute:"2-digit",timeZone:Te},e),Sc=/(?<![\w-])(\d{4}-\d{2}-\d{2})(?![\w-]|:)/g;function ir(n,e){return n.includes("-")?n.replace(Sc,t=>we(t,e)):n}var Nn=n=>n.charAt(0).toUpperCase()+n.slice(1),ci=n=>/^.\p{Lu}/u.test(n)?n:n.charAt(0).toLowerCase()+n.slice(1),ui=(n,e="and")=>n.length>1?`${n.slice(0,-1).join(", ")} ${e} ${n.at(-1)}`:n[0]??"";function $c(n,e){return{...e,kind:n,edges:e.edges??{}}}function sr(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 Rc(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 Nn(e.replace(/\b[a-z]+\b/g,t=>li.has(t)?t.toUpperCase():t.endsWith("s")&&li.has(t.slice(0,-1))?`${t.slice(0,-1).toUpperCase()}s`:t))}var li=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 Ac(n,e,t){let r=n.tryDefinition(e);return`${he(t)} ${t===1?H(r,e):oe(n,e).toLowerCase()}`}function oe(n,e){return n.tryDefinition(e)?.plural??`${V(e).toLowerCase()}s`}function _c(n,e){return Nn(oe(n,e))}function Oc(n,e){let t=oe(n,e);return`All ${/^[A-Z][a-z]/.test(t)?t.charAt(0).toLowerCase()+t.slice(1):t}`}function lt(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 Pc=/^(u[nt]i|use|usu|uti|ubiq|eu|ewe|one|once)/,Ec=/^(hour|honest|hono[ur]r?|heir)/;function fi(n){let e=V(n).toLowerCase();return Ec.test(e)?"an":Pc.test(e)?"a":/^[aeiou]/.test(e)?"an":"a"}function en(n){return`${fi(n)} ${V(n).toLowerCase()}`}function H(n,e){return n?.noun??V(e).toLowerCase()}function cr(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 ur(n,e="|"){return n.map(t=>gr(t)).join(e)}function hi(n,e){return typeof e=="bigint"?e.toString():e}var dr=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 gi(n){return new dr(n)}function mi(n){return n==null}function lr(n){let e=n.startsWith("^")?1:0,t=n.endsWith("$")?n.length-1:n.length;return n.slice(e,t)}function yi(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 pi=Symbol("evaluating");function bi(n,e,t){let r;Object.defineProperty(n,e,{get(){if(r!==pi)return r===void 0&&(r=pi,r=t()),r},set(o){Object.defineProperty(n,e,{value:o})},configurable:!0})}function pt(n,e,t){Object.defineProperty(n,e,{value:t,writable:!0,enumerable:!0,configurable:!0})}function vi(n){let e=Object.getOwnPropertyDescriptor(n,"shape");return e?.get?e.get.raw:e?.value}function fr(n){return vi(n._zod.def)??n._zod.def.shape}function xi(n,e,t){Object.defineProperty(n,e,{get(){let r=t();return pt(this,e,r),r},enumerable:!0,configurable:!0})}function wi(n,e,t){e in n?pt(n,e,t):n[e]=t}function Mc(n,e,t,r){let o=fr(e);for(let i of t){let s=Object.getOwnPropertyDescriptor(o,i);s.enumerable&&(s.get?xi(n,i,()=>{let a=e._zod.def.shape[i];return r?r(a,i):a}):wi(n,i,r?r(s.value,i):s.value))}}function zc(n,e){for(let t of Reflect.ownKeys(e)){let r=Object.getOwnPropertyDescriptor(e,t);r.enumerable&&(r.get?xi(n,t,()=>e[t]):wi(n,t,r.value))}}function ki(...n){let e={};for(let t of n){let r=Object.getOwnPropertyDescriptors(t);Object.assign(e,r)}return Object.defineProperties({},e)}var pr="captureStackTrace"in Error?Error.captureStackTrace:(...n)=>{};function ft(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function hr(n){if(ft(n)===!1)return!1;let e=n.constructor;if(e===void 0||typeof e!="function")return!0;let t=e.prototype;return!(ft(t)===!1||Object.prototype.hasOwnProperty.call(t,"isPrototypeOf")===!1)}var Si=new Set(["string","number","symbol"]);function jn(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function nn(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 gr(n){return typeof n=="bigint"?n.toString()+"n":typeof n=="string"?`"${n}"`:`${n}`}function $i(n){return Object.keys(n).filter(e=>n[e]._zod.optin!==void 0&&n[e]._zod.optout==="optional")}var Ri={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 Ai(n,e){if(!hr(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=fr(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 nn(n,ki(n._zod.def,{shape:Nc(n,e)}))}function Nc(n,e){let t={};return Mc(t,n,Reflect.ownKeys(fr(n))),zc(t,e),t}function ge(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 _i(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 Se(n,e){return e.map(t=>{var r;return(r=t).path??(r.path=[]),t.path.unshift(n),t})}function In(n){return typeof n=="string"?n:n?.message}function mr(n,e,t){var r;for(let o=e;o<n.length;o++)(r=n[o]).schema??(r.schema=t)}function me(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:In(n.inst?._zod.def?.error?.(n))??In(i?.(n))??In(e?.error?.(n))??In(t.customError?.(n))??In(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 Ic=/[\uD800-\uDBFF]/;function yr(n){let e=n.length;if(!Ic.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 br(n){return Array.isArray(n)?"array":typeof n=="string"?"string":"unknown"}function Oi(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 Tn(...n){let[e,t,r]=n;return typeof e=="string"?{message:e,code:"custom",input:t,inst:r}:{...e}}function Pi(n,e){for(let t in e){let r=Object.getOwnPropertyDescriptor(e,t);r.get?Object.defineProperty(n,t,{...r,enumerable:!1}):jc(n,t,r.value)}}function De(n,e,t,r=!0){return Object.defineProperty(n,e,{configurable:!0,writable:!0,enumerable:r,value:t}),t}function vr(n,e,t){return De(n,e,t,!1)}function jc(n,e,t){Object.defineProperty(n,e,{configurable:!0,get(){return this==null?t:De(this,e,t.bind(this))},set(r){De(this,e,r)}})}function Tc(n,e){let t=Object.getPrototypeOf(n);return e in t?void 0:t}var ar,ke=!1,Dc={configurable:!0,get(){ke=!0}};function Y(n,e,t){let r=Object.getPrototypeOf(n._zod);if(e in r&&ar!==n._zod){ar=void 0;return}ar=n._zod,Object.defineProperty(r,e,{configurable:!0,get(){Object.defineProperty(this,e,Dc);let o=ke;ke=!1;try{let i=t(this);return ke?delete this[e]:Object.defineProperty(this,e,{configurable:!0,writable:!0,value:i}),ke=ke||o,i}catch(i){throw delete this[e],ke=ke||o,i}},set(o){Object.defineProperty(this,e,{configurable:!0,writable:!0,value:o})}})}function Ei(n,e,t,r){let o=Tc(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 Mi;var xr={value:void 0,enumerable:!1},zi="captureStackTrace"in Error?Error:null;function Fc(n){let e=zi;if(e){let t=e.stackTraceLimit;if(typeof t=="number"){try{e.stackTraceLimit=0}catch{return zi=null,new n}try{return new n}finally{e.stackTraceLimit=t}}}return new n}function O(n,e,t,r){let o={};function i(c){this.def=c,this.constr=p,this.traits=new Set}i.prototype=o;let s=t,a=s&&new WeakSet;function d(c,f){if(c._zod){if(c._zod.traits.has(n))return}else{xr.value=new i(f);try{Object.defineProperty(c,"_zod",xr)}finally{xr.value=void 0}}if(c._zod.traits.add(n),e(c,f),a){let g=Object.getPrototypeOf(c),b=c._zod.constr.prototype,m=g;for(;m&&m!==b;)m=Object.getPrototypeOf(m);let k=m??g;a.has(k)||(a.add(k),Pi(k,s))}let h=p.prototype;for(let g in h)Object.prototype.hasOwnProperty.call(h,g)&&(g in c||(c[g]=h[g].bind(c)))}let l=r?.Parent??Object;class u extends l{}Object.defineProperty(u,"name",{value:n});function p(c){let f=r?.Parent?Fc(u):this;d(f,c);let h=f._zod.deferred;if(h){for(let b of h)b();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:c=>r?.Parent&&c instanceof r.Parent?!0:c?._zod?.traits?.has(n)}),Object.defineProperty(p,"name",{value:n}),p}var be=class extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}};(Mi=globalThis).__zod_globalConfig??(Mi.__zod_globalConfig={});var tn=globalThis.__zod_globalConfig;function ne(n){return n&&Object.assign(tn,n),tn}function Lc(){let n=this._zod;return n.message??(n.message=JSON.stringify(n.def,hi,2)),n.message}function Zc(n){this._zod.message=n}var Cc={get:Lc,set:Zc,enumerable:!0,configurable:!0},kr={value:void 0,enumerable:!1},Ni=new WeakSet([Object.prototype,Error.prototype]),Ii=(n,e)=>{n.name="$ZodError",kr.value=e,Object.defineProperty(n,"issues",kr),kr.value=void 0,Object.defineProperty(n,"message",Cc);let t=Object.getPrototypeOf(n);Ni.has(t)||(Ni.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})}}))},Wp=O("$ZodError",Ii),Dn=O("$ZodError",Ii,void 0,{Parent:Error});var Kc=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 be;if(a.issues.length){let d=new(i?.Err??n)(a.issues.map(l=>me(l,s,ne())));throw pr(d,i?.callee??e),d}return a.value};return e},Sr=Kc(Dn),Vc=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=>me(l,s,ne())));throw pr(d,i?.callee??e),d}return a.value};return e},$r=Vc(Dn),Bc=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 be;return i.issues.length?ji(n,i.issues,o):{success:!0,data:i.value}},Rr=Bc(Dn);function ji(n,e,t){let r;return{success:!1,get error(){return r||(r=new n(e.map(o=>me(o,t,ne()))),e=void 0,t=void 0),r},set error(o){r=o,e=void 0,t=void 0}}}var Uc=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?ji(n,i.issues,o):{success:!0,data:i.value}},Ar=Uc(Dn);var Ti=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var Di=/^https?$/;var Fi=/^[\s\S]{0,}$/;var _r=/^-?\d+(?:\.\d+)?$/,Li=/^(?:true|false)$/i,Zi=/^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 Ci=n=>{let e=n.value;return!mi(e)&&e.length!==void 0},ht={number:"number",bigint:"bigint",object:"date"},Gi=O("$ZodCheckLessThan",(n,e)=>{te.init(n,e);let t=ht[typeof e.value];n._zod.check=r=>{(e.inclusive?r.value<=e.value:r.value<e.value)||r.issues.push({origin:ht[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})}}),Ki=O("$ZodCheckGreaterThan",(n,e)=>{te.init(n,e);let t=ht[typeof e.value];n._zod.check=r=>{(e.inclusive?r.value>=e.value:r.value>e.value)||r.issues.push({origin:ht[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})}}),Vi=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):yi(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})}}),Bi=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]=Ri[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 Ui=O("$ZodCheckMaxLength",(n,e)=>{var t;te.init(n,e),(t=n._zod.def).when??(t.when=Ci),n._zod.check=r=>{let o=r.value,i=o.length;if((typeof o=="string"&&i>e.maximum?yr(o):i)<=e.maximum)return;let a=br(o);r.issues.push({origin:a,code:"too_big",maximum:e.maximum,inclusive:!0,input:o,inst:n,continue:!e.abort})}}),Wi=O("$ZodCheckMinLength",(n,e)=>{var t;te.init(n,e),(t=n._zod.def).when??(t.when=Ci),n._zod.check=r=>{let o=r.value,i=o.length;if((typeof o=="string"&&i>=e.minimum&&i<e.minimum*2?yr(o):i)>=e.minimum)return;let a=br(o);r.issues.push({origin:a,code:"too_small",minimum:e.minimum,inclusive:!0,input:o,inst:n,continue:!e.abort})}});var Pr=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)=>{Pr.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 Yi={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=Yi;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 u=ge(a),p;for(let c of d){if(c._zod.def.when){if(_i(a)||!c._zod.def.when(a))continue}else if(u)continue;let f=a.issues.length,h=c._zod.check(a);if(h instanceof Promise&&l?.async===!1)throw new be;if(p||h instanceof Promise)p=(p??Promise.resolve()).then(async()=>{await h,a.issues.length!==f&&(mr(a.issues,f,n),u||(u=ge(a,f)))});else{if(a.issues.length===f)continue;mr(a.issues,f,n),u||(u=ge(a,f))}}return p?p.then(()=>a):a},s=(a,d,l)=>{if(ge(a))return a.aborted=!0,a;let u=i(d,o,l);if(u instanceof Promise){if(l.async===!1)throw new be;return u.then(p=>n._zod.parse(p,l))}return n._zod.parse(u,l)};n._zod.run=(a,d)=>{if(d.skipChecks)return n._zod.parse(a,d);if(d.direction==="backward"){let u=n._zod.parse({value:a.value,issues:[]},{...d,skipChecks:!0});return u instanceof Promise?u.then(p=>s(p,a,d)):s(u,a,d)}let l=n._zod.parse(a,d);if(l instanceof Promise){if(d.async===!1)throw new be;return l.then(u=>i(u,o,d))}return i(l,o,d)}}},{get"~standard"(){return vr(this,"~standard",qc(this))},set"~standard"(n){De(this,"~standard",n)}}),ts=(n,e)=>n.issues.length?{issues:n.issues.map(t=>me(t,e,ne()))}:{value:n.value};async function Wc(n,e){let t={async:!0};return ts(await n._zod.run({value:e,issues:[]},t),t)}function qc(n){return{validate:e=>{let t={async:!1};try{let r=n._zod.run({value:e,issues:[]},t);if(!(r instanceof Promise))return ts(r,t)}catch{}return Wc(n,e)},vendor:"zod",version:1}}var Er=O("$ZodString",(n,e)=>{B.init(n,e),n._zod.pattern=e.pattern??Fi,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}}),yt=O("$ZodStringFormat",(n,e)=>{Pr.init(n,e),Er.init(n,e)});var rs=O("$ZodEmail",(n,e)=>{e.pattern??(e.pattern=Ti),yt.init(n,e)}),os=1,gt=2;function Hc(n){try{return typeof URL<"u"&&typeof URL.canParse=="function"?URL.canParse(n):(new URL(n),!0)}catch{return!1}}function Yc(n,e){return!("normalize"in e)&&!("hostname"in e)&&!("protocol"in e)?Hc(n)||gt:Jc(n,e)}function Jc(n,e){if(!e.normalize&&e.protocol?.source===Di.source&&!/^https?:\/\//i.test(n))return os;try{if(typeof URL<"u"){let t=URL;if(typeof t.parse=="function")return t.parse(n)??gt}return new URL(n)}catch{return gt}}var Xc=/[\t\n\r]/g;function Ji(n){return n.replace(Xc,"")}function Qc(n,e){return e.lastIndex=0,e.test(n.hostname)}function eu(n,e){return e.lastIndex=0,e.test(n.protocol.endsWith(":")?n.protocol.slice(0,-1):n.protocol)}var is=O("$ZodURL",(n,e)=>{yt.init(n,e),n._zod.check=t=>{try{let r=t.value.trim(),o=Yc(r,e);if(o===os){t.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:t.value,inst:n,continue:!e.abort});return}if(o===gt){t.issues.push({code:"invalid_format",format:"url",input:t.value,inst:n,continue:!e.abort});return}if(o===!0){t.value=Ji(r);return}e.hostname&&!Qc(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&&!eu(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:Ji(r);return}catch{t.issues.push({code:"invalid_format",format:"url",input:t.value,inst:n,continue:!e.abort})}}});var Mr=O("$ZodNumber",(n,e)=>{B.init(n,e),n._zod.pattern=_r,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}}),ss=O("$ZodNumberFormat",(n,e)=>{Bi.init(n,e),Mr.init(n,e)}),as=O("$ZodBoolean",(n,e)=>{B.init(n,e),n._zod.pattern=Li,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 ds=O("$ZodNull",(n,e)=>{B.init(n,e),n._zod.pattern=Zi,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 cs=O("$ZodUnknown",(n,e)=>{B.init(n,e),n._zod.parse=t=>t}),us=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 Xi(n,e,t){n.issues.length&&e.issues.push(...Se(t,n.issues)),e.value[t]=n.value}var ls=O("$ZodArray",(n,e)=>{B.init(n,e);let t=tn.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],u=e.element._zod.run({value:l,issues:[]},o);if(u instanceof Promise)s.push(u.then(p=>Xi(p,r,d)));else if(Xi(u,r,d),a&&u.issues.length!==0&&ge(u))break}return s.length?Promise.all(s).then(()=>r):r}});function mt(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(...Se(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 nu=[];function tu(n){let e=Object.keys(n.shape),t=Object.getOwnPropertySymbols(n.shape),r=t.length?t:nu,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=$i(n.shape);return{...n,allKeys:o,symbolKeys:r,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(i)}}function ru(n,e,t,r,o,i,s){let a=[],d=o.keySet,l=o.catchall._zod,u=l.def.type,p=l.optin,c=l.optout,f=0;for(let h in e){if(s&&t.issues.length!==f){if(ge(t,f))break;f=t.issues.length}if(d.has(h))continue;if(h==="__proto__"){u==="never"&&a.push(h);continue}if(u==="never"){a.push(h);continue}let g=l.run({value:e[h],issues:[]},r);g instanceof Promise?n.push(g.then(b=>mt(b,t,h,e,p,c))):mt(g,t,h,e,p,c)}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 fs=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 u={...r};return Object.defineProperty(e,"shape",{value:u}),l.raw=u,u};l.raw=r,Object.defineProperty(e,"shape",{get:l})}let o=gi(()=>tu(e));Y(n,"propValues",l=>{let u=l.def.shape,p={};for(let c in u){let f=u[c]._zod;if(f.values){Object.prototype.hasOwnProperty.call(p,c)||pt(p,c,new Set);for(let h of f.values)p[c].add(h);f.optin!==void 0&&p[c].add(void 0)}}return p});let i=ft,s=e.catchall,a,d=tn.memoizer;d?.attach(n),n._zod.parse=(l,u)=>{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,{},u):{};let c=[],f=a.shape,h=u?.abortEarly,g=l.issues.length;for(let b of a.allKeys){if(h&&l.issues.length!==g){if(ge(l,g))break;g=l.issues.length}if(b==="__proto__")continue;let m=f[b],k=m._zod.optin,_=m._zod.optout,$=m._zod.run({value:p[b],issues:[]},u);$ instanceof Promise?c.push($.then(A=>mt(A,l,b,p,k,_))):mt($,l,b,p,k,_)}return s?ru(c,p,l,u,o.value,n,h===!0):c.length?Promise.all(c).then(()=>l):l}});function Qi(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=>!ge(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=>me(s,r,ne())))}),e)}var ps=O("$ZodUnion",(n,e)=>{B.init(n,e),Y(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),Y(n,"optout",r=>r.def.options.some(o=>o._zod.optout==="optional")?"optional":void 0),Y(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)))}),Y(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=>lr(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=>Qi(a,r,n,o)):Qi(s,r,n,o)}});var hs=O("$ZodRecord",(n,e)=>{B.init(n,e);let t=tn.memoizer;t?.attach(n),n._zod.parse=(r,o)=>{let i=r.value;if(!hr(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 u of a)if(typeof u=="string"||typeof u=="number"||typeof u=="symbol"){if(d.add(typeof u=="number"?u.toString():u),u==="__proto__")continue;let p=e.keyType._zod.run({value:u,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=>me(h,o,ne())),input:u,path:[u],inst:n});continue}let c=p.value;if(c==="__proto__")continue;let f=e.valueType._zod.run({value:i[u],issues:[]},o);f instanceof Promise?s.push(f.then(h=>{h.issues.length&&r.issues.push(...Se(u,h.issues)),r.value[c]=h.value})):(f.issues.length&&r.issues.push(...Se(u,f.issues)),r.value[c]=f.value)}let l;for(let u in i)if(!d.has(u))if(e.mode==="loose"){if(u==="__proto__")continue;r.value[u]=i[u]}else l=l??[],l.push(u);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 u=e.keyType._zod.run({value:l,issues:[]},o);if(u instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(typeof l=="string"&&_r.test(l)&&u.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&&(u=h)}if(u.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:u.issues.map(h=>me(h,o,ne())),input:l,path:[l],inst:n});continue}let c=u.value;if(c==="__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(...Se(l,h.issues)),r.value[c]=h.value})):(f.issues.length&&r.issues.push(...Se(l,f.issues)),r.value[c]=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 gs=O("$ZodEnum",(n,e)=>{B.init(n,e);let t=cr(e.entries),r=new Set(t);n._zod.values=r,Y(n,"pattern",o=>{let i=cr(o.def.entries).filter(s=>Si.has(typeof s));return new RegExp(i.length?`^(${i.map(s=>jn(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}}),ms=O("$ZodLiteral",(n,e)=>{B.init(n,e);let t=new Set(e.values);n._zod.values=t,Y(n,"pattern",r=>{let o=r.def.values;return new RegExp(o.length?`^(${o.map(i=>typeof i=="string"?jn(i):i?jn(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 es(n,e){return n.value=e.issues.length?void 0:e.value,n}var ys=O("$ZodOptional",(n,e)=>{B.init(n,e),Y(n,"optin",t=>t.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),n._zod.optout="optional",Y(n,"values",t=>{let r=t.def.innerType._zod.values;return r?new Set([...r,void 0]):void 0}),Y(n,"pattern",t=>{let r=t.def.innerType._zod.pattern;return r?new RegExp(`^(${lr(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=>es(t,i)):es(t,o)}return e.innerType._zod.run(t,r)}});var bs=O("$ZodLazy",(n,e)=>{B.init(n,e),bi(n._zod,"innerType",()=>{let t=e;return t._cachedInner||(t._cachedInner=e.getter()),t._cachedInner}),Y(n,"pattern",t=>t.innerType?._zod?.pattern),Y(n,"propValues",t=>t.innerType?._zod?.propValues),Y(n,"optin",t=>t.innerType?._zod?.optin??void 0),Y(n,"optout",t=>t.innerType?._zod?.optout??void 0),n._zod.parse=(t,r)=>n._zod.innerType._zod.run(t,r)}),vs=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=>ns(i,t,r,n));ns(o,t,r,n)}});function ns(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(Tn(o))}}var ou=()=>{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=Oi(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 ${gr(i.values[0])}`:`Invalid option: expected one of ${ur(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":""}: ${ur(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 xs(){return{localeError:ou()}}var ws;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 ks(){return new zr}(ws=globalThis).__zod_globalRegistry??(ws.__zod_globalRegistry=ks());var rn=globalThis.__zod_globalRegistry;function Ss(n){return n.checks&&(n.checks=[...n.checks]),n}function $s(n,e){return new n(Ss({type:"string",...N(e)}))}function Rs(n,e){return new n({type:"string",format:"email",check:"string_format",abort:!1,...N(e)})}function As(n,e){return new n({type:"string",format:"url",check:"string_format",abort:!1,...N(e)})}function _s(n,e){return new n(Ss({type:"number",checks:[],...N(e)}))}function Os(n,e){return new n({type:"number",check:"number_format",abort:!1,format:"safeint",...N(e)})}function Ps(n,e){return new n({type:"boolean",...N(e)})}function Es(n,e){return new n({type:"null",...N(e)})}function Ms(n){return new n({type:"unknown"})}function zs(n,e){return new n({type:"never",...N(e)})}function Ns(n,e){return new Gi({check:"less_than",...N(e),value:n,inclusive:!0})}function Is(n,e){return new Ki({check:"greater_than",...N(e),value:n,inclusive:!0})}function du(n,e){return new Vi({check:"multiple_of",...N(e),value:n})}function Nr(n,e){return new Ui({check:"max_length",...N(e),maximum:n})}function Fn(n,e){return new Wi({check:"min_length",...N(e),minimum:n})}function Ln(n,e){return new qi({check:"string_format",format:"regex",...N(e),pattern:n})}function js(n,e,t){return new n({type:"custom",check:"custom",fn:e,...N(t)})}function Ts(n,e){let t=cu(r=>(r.addIssue=o=>{if(typeof o=="string")r.issues.push(Tn(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(Tn(i))}},n(r.value,r)),e);return t}function cu(n,e){let t=new te({check:"custom",...N(e)});return t._zod.check=n,t}function Ds(n){let e=new te({check:"describe"});return e._zod.onattach=[t=>{let r=rn.get(t)??{};rn.add(t,{...r,description:n})}],e._zod.check=()=>{},e}var J=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){De(this,"with",n)},parse(n,e){return Sr(this,n,e,{callee:this.parse})},parseAsync(n,e){return $r(this,n,e,{callee:this.parseAsync})},safeParse(n,e){return Rr(this,n,e)},safeParseAsync(n,e){return Ar(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 nn(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)}}),Ls=O("ZodMiniString",(n,e)=>{Er.init(n,e),J.init(n,e)});function L(n){return $s(Ls,n)}var Zs=O("ZodMiniStringFormat",(n,e)=>{yt.init(n,e),Ls.init(n,e)}),fu=O("ZodMiniEmail",(n,e)=>{rs.init(n,e),Zs.init(n,e)});function Hm(n){return Rs(fu,n)}var pu=O("ZodMiniURL",(n,e)=>{is.init(n,e),Zs.init(n,e)});function Ym(n){return As(pu,n)}var Cs=O("ZodMiniNumber",(n,e)=>{Mr.init(n,e),J.init(n,e)});function Fe(n){return _s(Cs,n)}var hu=O("ZodMiniNumberFormat",(n,e)=>{ss.init(n,e),Cs.init(n,e)});function Jm(n){return Os(hu,n)}var gu=O("ZodMiniBoolean",(n,e)=>{as.init(n,e),J.init(n,e)});function Xm(n){return Ps(gu,n)}var mu=O("ZodMiniNull",(n,e)=>{ds.init(n,e),J.init(n,e)});function Qm(n){return Es(mu,n)}var yu=O("ZodMiniUnknown",(n,e)=>{cs.init(n,e),J.init(n,e)});function Ir(){return Ms(yu)}var bu=O("ZodMiniNever",(n,e)=>{us.init(n,e),J.init(n,e)});function vu(n){return zs(bu,n)}var xu=O("ZodMiniArray",(n,e)=>{ls.init(n,e),J.init(n,e)});function ey(n,e){return new xu({type:"array",element:n,...N(e)})}var jr=O("ZodMiniObject",(n,e)=>{fs.init(n,e),J.init(n,e),Ei(n,"shape",t=>t._zod.def.shape,!1)});function $e(n,e){let t={type:"object",shape:n??{},...N(e)};return new jr(t)}function on(n,e){return new jr({type:"object",shape:n,catchall:vu(),...N(e)})}function ny(n,e){return new jr({type:"object",shape:n,catchall:Ir(),...N(e)})}function Gs(n,e){return Ai(n,e)}var wu=O("ZodMiniUnion",(n,e)=>{ps.init(n,e),J.init(n,e)});function ty(n,e){return new wu({type:"union",options:n,...N(e)})}var Fs=O("ZodMiniRecord",(n,e)=>{hs.init(n,e),J.init(n,e)});function ry(n,e,t){return!e||!e._zod?new Fs({type:"record",keyType:L(),valueType:n,...N(e)}):new Fs({type:"record",keyType:n,valueType:e,...N(t)})}var ku=O("ZodMiniEnum",(n,e)=>{gs.init(n,e),J.init(n,e),n.options=[...n._zod.values]});function Ks(n,e){let t=Array.isArray(n)?Object.fromEntries(n.map(r=>[r,r])):n;return new ku({type:"enum",entries:t,...N(e)})}var Su=O("ZodMiniLiteral",(n,e)=>{ms.init(n,e),J.init(n,e)});function Vs(n,e){return new Su({type:"literal",values:Array.isArray(n)?n:[n],...N(e)})}var $u=O("ZodMiniOptional",(n,e)=>{ys.init(n,e),J.init(n,e)});function X(n){return new $u({type:"optional",innerType:n})}var Ru=O("ZodMiniLazy",(n,e)=>{bs.init(n,e),J.init(n,e)});function oy(n){return new Ru({type:"lazy",getter:n})}var Au=O("ZodMiniCustom",(n,e)=>{vs.init(n,e),J.init(n,e)});function bt(n,e={}){return js(Au,n,e)}function iy(n,e){return Ts(n,e)}var sy=Ds;ne().localeError||ne(xs());var T=n=>typeof n=="object"&&n!==null?n._zod?.def:void 0,_u=n=>{if(typeof n!="object"||n===null||!("_zod"in n))return;let e=rn.get(n)?.description;return typeof e=="string"?e:void 0};var Ou=(n,e)=>n?.src?.(e)??e,vt=n=>typeof n=="string"&&n.length<2049&&/^(?![^/?#]*:|\/\/)(?!(?:.*\/)?\.\.?(?:[/?#]|$))(?!.*%2e)[^\\\s]+$/i.test(n),Tr=(n,e=1)=>e>0&&n===void 0||Number.isInteger(n)&&n>=e;function Dr(n){let e=n??{};return vt(e.href)&&typeof e.name=="string"&&/^.{1,255}$/s.test(e.name)&&/^[\w.+-]{1,60}\/[\w.+-]{1,60}$/.test(e.type)&&Tr(e.bytes,0)&&Tr(e.width)&&Tr(e.height)&&(e.caption===void 0||typeof e.caption=="string"&&e.caption.length<501)&&(e.poster===void 0||vt(e.poster))&&(e.captions===void 0||vt(e.captions))&&(e.duration===void 0||typeof e.duration=="number"&&Number.isFinite(e.duration)&&e.duration>0)&&(e.at===void 0||Bs(e.at)!==void 0)}function Bs(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 Us=n=>n.type.startsWith("image/"),Ws=n=>n.type.startsWith("video/");function Pu(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 Eu=(n,e)=>e==="image"?Us(n):e==="video"?Ws(n):!0,Mu=n=>`${n==="image"?"an image":n==="video"?"a video":"a file"} the host stored, at a path on this host`,Zn=n=>(Array.isArray(n)?n:[n]).filter(Dr),qs=Symbol.for("@graview/core:file"),zu=(n,e)=>(Object.defineProperty(T(n),qs,{value:e,enumerable:!0}),n);function Hs(n){let e=T(n);return e?.[qs]??(e?.innerType?Hs(e.innerType):void 0)}var Nu=()=>({href:L(),name:L(),type:L(),bytes:Fe(),width:X(Fe()),height:X(Fe()),caption:X(L()),poster:X(L()),duration:X(Fe()),captions:X(L()),at:X(L())});function ab(n){return zu($e(Nu()).check(bt(e=>Dr(e)&&Eu(e,n),Mu(n))),n)}var xt=/^(?:https?:\/\/[^\s<>"'`\\]+|@?[A-Za-z0-9][\w.~-]*(?:\/[\w.~-]+)*)$/,wt=n=>typeof n=="string"&&n.length<501&&xt.test(n);var Ys=n=>typeof n=="object"&&n!==null?n._zod?.def:void 0,Iu=/^@(?:https?:\/\/[^\s<>"'`\\#?]+|[A-Za-z0-9][\w.~-]*(?:\/[\w.~-]+)*)\/[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;function Js(n){if(typeof n!="string"||!n.startsWith("@")||!Iu.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 wt(o)?{address:o,kind:r}:void 0}var ju=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*:\S[^\n]{0,199}$/,Tu=n=>`${n.kind}:${n.id}`;function Xs(n,e){if(typeof n!="string"||!ju.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 Du(n,e){return(Array.isArray(n)?n:n==null?[]:[n]).flatMap(r=>{let o=Xs(r,e);return o?[o]:[]})}var Qs=Symbol.for("@graview/core:linked"),lb=(n,e)=>(Object.defineProperty(Ys(n),Qs,{value:e,enumerable:!0}),n);function Cn(n){let e=Ys(n);return e?e[Qs]??Cn(e.innerType):void 0}function Fu(n){let e=n?.fields?.shape??{},t=new Map;for(let[r,o]of Object.entries(e)){let i=Cn(o);i&&t.set(r,i)}return t}function Lu(n){if(n.to==="*"||n.to.length===0)return;let e=n.to.map(Js);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 Zu=n=>n.to!=="*"&&n.to.some(e=>typeof e=="string"&&e.startsWith("@"));function fb(n){return Object.fromEntries(Object.entries(n??{}).filter(([,e])=>!Zu(e)))}function pb(n){let e=new Map;for(let[t,r]of Object.entries(n??{})){let o=Lu(r);o&&e.set(t,o)}return e}var Fr=new WeakMap;function Cu(n,e){e?Fr.set(n,e):Fr.delete(n)}var ea=n=>Fr.get(n);var kt=["sun","mon","tue","wed","thu","fri","sat"],Gu=["day","week","month","year"],an=n=>`${n}Repeat`,Kn=n=>n.endsWith("Repeat")&&n.length>6?n.slice(0,-6):void 0,ra=/^\d{4}-\d{2}-\d{2}$/,oa=Symbol.for("@graview/core:repeat");function St(n){let e=T(n);return!!e&&(e[oa]===1||St(e.innerType))}var Ku=n=>(Object.defineProperty(T(n),oa,{value:1,enumerable:!0}),n),Lr=(n,e,t)=>n===void 0||Number.isInteger(n)&&n>=e&&n<=t,na=(n,e)=>n===void 0||Array.isArray(n)&&n.length<=e&&n.every(t=>typeof t=="string"&&ra.test(t)),Vu=["every","interval","on","until","count","except","continues"],ia=n=>dn(n)&&Object.keys(n).every(e=>Vu.includes(e))&&Lr(n.interval,1,99)&&Lr(n.count,1,1e3)&&na(n.until===void 0?void 0:[n.until],1)&&na(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"?kt.includes(e):n.every==="month"&&e!==0&&Lr(e,-1,31))),mb=()=>Ku(Ir().check(bt(n=>n===null||ia(n),"how a date repeats, or null"))),Gn=n=>Date.UTC(+n.slice(0,4),+n.slice(5,7)-1,+n.slice(8,10)),sa=n=>new Date(n).toISOString().slice(0,10),Zr=(n,e)=>sa(Gn(n)+e*864e5),ta=(n,e,t)=>{let r=new Date(Date.UTC(n,e+1,0)).getUTCDate();return sa(Date.UTC(n,e,t<0||t>r?r:t))},dn=n=>typeof n=="object"&&n!==null&&Gu.includes(n.every);function sn(n,e,t={}){let r=n.slice(0,10),o=n.slice(10),i=[];if(!ra.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],u=t.limit??1e3,p=new Set(e.except??[]),c=+r.slice(0,4),f=+r.slice(5,7)-1,h=+r.slice(8,10),g=Zr(r,-new Date(Gn(r)).getUTCDay()),b=(e.on?.length?e.on:[a==="week"?kt[new Date(Gn(r)).getUTCDay()]:h]).map(A=>typeof A=="string"?kt.indexOf(A):A),m=a==="day"?1:a==="week"?7:0,k=(+d.slice(0,4)-c)*12+(+d.slice(5,7)-1-f),_=e.count?0:Math.max(0,Math.floor((m?(Gn(d)-Gn(m===7?g:r))/864e5/m:a==="month"?k:k/12)/s)-1),$=0;for(let A=0;A<5e4&&i.length<u;A++,_++){let y=_*s,v=a==="day"?[Zr(r,y)]:a==="week"?b.map(w=>Zr(g,y*7+w)):a==="month"?b.map(w=>ta(c,f+y,w)):[ta(c+y,f,h)];for(let w of[...new Set(v)].sort())if(!(w<r)&&(l&&w>l||e.count&&$>=e.count||($++,w>=d&&!p.has(w)&&i.push(w+o),i.length>=u)))return i}return i}function aa(n,e,t){if(!dn(e)||typeof n!="string")return n;let r=sn(n,e,{from:t,limit:1})[0];if(r)return r;let o=e.until||e.count?sn(n,e):[];return o[o.length-1]??n}function Bu(n,e,t){let r=n[e],o=n[an(e)];return typeof r=="string"&&dn(o)?aa(r,o,t):r}var $t=["human","visitor","agent","rule","system"],Uu=new Set($t);function Cr(n){return Uu.has(n?.kind)?n.kind:"system"}function Vn(n,e){if(n.onBehalfOf){let{onBehalfOf:s,...a}=n;return`${Vn(a,e)}, for ${Vn(s,e)}`}let t=Cr(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 cn="$archived",Le=n=>n?.[cn]===!0,kb=(n,e=!1)=>e==="all"||Le(n)===e,Gr=n=>n===!0||n==="true"?!0:n==="all"?"all":!1,Bn="$leftAlone",Rt=new Set([cn,Bn]);var ae=class extends Error{constructor(t,r){super(r?`${t}
2
- \u2192 ${r}`:t);this.hint=r;this.name="SchemaError"}};function Wu(n,e){let t=n,r=new Map;for(let a of t){if(r.has(a.kind))throw new ae(`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 ae(`Edge "${d}" on "${a.kind}" points at undeclared kind "${p}"`,`Declared kinds: ${[...r.keys()].join(", ")}`)}let u=o.get(d);u?u.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 u=d.map(p=>r.get(p).edges[a].to);i.set(a,{kind:a,from:d,to:u.includes("*")?"*":[...new Set(u.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,Gs(a.fields,{id:L().check(Fn(1)),kind:Vs(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 ae(`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 u=r.get(d)?.edges[a];return u?u.to==="*"||u.to.includes(l):!1},parseNode(a){let d=a?.kind;if(typeof d!="string")throw new ae("Node is missing a `kind`");let l=s.get(d);if(!l)throw new ae(`Unknown node kind "${d}"`,`Declared kinds: ${[...r.keys()].join(", ")}`);let u={},p={};for(let[f,h]of Object.entries(a))Rt.has(f)?h===!0&&(p[f]=!0):u[f]=h;let c=l.parse(u);return Object.keys(p).length>0?{...c,...p}:c},__node:void 0}}var Kr="0.1.50";var un={snapshot:1,op:3},ln=class extends Error{constructor(t,r,o,i,s){super(s!==void 0?`This ${t} holds a ${s} that @graview ${Kr} does not know: upgrade the framework to read it.`:`This ${t} is in a newer format (${r}${i?`, written by @graview ${i}`:""}) than @graview ${Kr} 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"}},Vr=["add-node","remove-node","patch-node","add-edge","remove-edge","splice-text"],qu=new Set(Vr);function Br(n){throw new ln("op",un.op+1,un.op,void 0,`primitive "${n?.op}"`)}var Ur=new Set;function Wr(n){for(let e in n){let t=n[e]?.$type;if(t!==void 0&&!Ur.has(t))throw new ln("op",un.op+1,un.op,void 0,`value type "${t}" in "${e}"`)}}function da(n){for(let e of n.primitives)qu.has(e?.op)||Br(e)}function z(n){return`${n.kind}\0${n.from}\0${n.to}`}var Un={addedNodes:[],removedNodes:[],changedNodes:[],addedEdges:[],removedEdges:[],touched:[]};function ca(n){return n.addedNodes.length===0&&n.removedNodes.length===0&&n.changedNodes.length===0&&n.addedEdges.length===0&&n.removedEdges.length===0}function Hu(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 Re(n,e){let t=new Map(n.nodes.map(c=>[c.id,c])),r=new Map(e.nodes.map(c=>[c.id,c])),o=e.nodes.filter(c=>!t.has(c.id)),i=n.nodes.filter(c=>!r.has(c.id)),s=[];for(let c of n.nodes){let f=r.get(c.id);if(!f||f===c)continue;let h=Hu(c,f);h.length>0&&s.push({before:c,after:f,fields:h})}let a=new Map(n.edges.map(c=>[z(c),c])),d=new Map(e.edges.map(c=>[z(c),c])),l=e.edges.filter(c=>!a.has(z(c))),u=n.edges.filter(c=>!d.has(z(c))),p=new Set;for(let c of o)p.add(c.id);for(let c of i)p.add(c.id);for(let c of s)p.add(c.after.id);for(let c of[...l,...u])p.add(c.from),p.add(c.to);return{addedNodes:o,removedNodes:i,changedNodes:s,addedEdges:l,removedEdges:u,touched:[...p].sort()}}function Ae(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 Un;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 Re(o(n),o(e))}var At={idLength:200,dataLength:4096,sameKindPerPair:1};function ua({id:n,data:e}){if(n!==void 0&&!(typeof n=="string"&&n.length<=At.idLength&&/^[^\s\p{Cc}]+$/u.test(n)))return`A link's id is 1\u2013${At.idLength} characters with no space`;if(e!==void 0&&!(e&&typeof e=="object"&&!Array.isArray(e)&&JSON.stringify(e).length<=At.dataLength))return`A link's data is a JSON object of at most ${At.dataLength} characters`}function Yu(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 _t(n,e){try{n.parseNode(e);return}catch(t){if(t instanceof ae)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 qr="n\0",Hr="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=Re(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=Ae(r,this.snapshot(),e);return this.emit(o),o}preview(e,t={}){return n.from(this.schema,this.snapshot(),{validate:this.validate}).applyPrimitives(e,t)}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}restore(e){for(let t of[this.nodes,this.edges,this.linkIds,this.outIndex,this.inIndex,this.ranks,this.lapsed,this.counts,this.archived])t.clear();this.reordered=!1;for(let t of e.nodes)this.insertNode(t,!0);for(let t of e.edges)this.insertEdge(t,!0)}tally(e,t){this.counts.set(e,(this.counts.get(e)??0)+t)}place(e,t){let r=t?this.lapsed.get(e):void 0;if(r===void 0){this.ranks.set(e,++this.rank);return}this.ranks.set(e,r),this.lapsed.delete(e),this.reordered=!0}lapse(e){let t=this.ranks.get(e);t!==void 0&&(this.ranks.delete(e),this.lapsed.set(e,t),this.lapsed.size>4096&&this.lapsed.delete(this.lapsed.keys().next().value))}settleOrder(){if(!this.reordered)return;this.reordered=!1;let e=o=>(i,s)=>this.ranks.get(o+i[0])-this.ranks.get(o+s[0]),t=[...this.nodes.entries()].sort(e(qr));this.nodes.clear();for(let[o,i]of t)this.nodes.set(o,i);let r=[...this.edges.entries()].sort(e(Hr));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":Wr(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(qr+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}"`);Wr(e.after);let i={...o};for(let[a,d]of Object.entries(e.after))Ye(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[Le(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=oi(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:Br(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"||Rt.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=_t(this.schema,t);if(i===void 0)return t;let s=_t(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 ae)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`,Yu(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)),Le(e)&&this.archived.add(e.id),this.tally(e.kind,1),this.place(qr+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=ua(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(Hr+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(Hr+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 Ot=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 Ju(n,e){return{...e,name:n}}var Pt=class extends Error{constructor(e){super(e),this.name="RuleBudgetError"}};function la(n,e,t){try{return e().map(r=>r.status?r:{...r,status:"violated"})}catch(r){let o=r instanceof Pt,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 fn(n,e,t={}){let r=t.context??{},o=t.today===void 0?{}:{today:t.today},i=t.onUnregistered??"skip",s=new Set(e.map(c=>c.name)),a=[];for(let c of e)c.scope==="graph"&&a.push(...la(c,()=>c.evaluate({graph:n,subject:void 0,context:r,...o}),void 0));let d=e.filter(c=>c.scope!=="graph"),l=new Map;for(let c of d){let f=c.scope.kind,h=l.get(f);h?h.push(c):l.set(f,[c])}for(let c of n.allNodes()){let f=n.schema.tryDefinition(c.kind),h=f?.requiresInvariant?.(c)??null;if(t.subjectFilter&&!t.subjectFilter(c,r))continue;if(h!==null&&!s.has(h)){if(i==="throw")throw new Ot(h,c.id);continue}let g=!sr(f,c,t.today);for(let b of l.get(c.kind)??[]){if(g&&b.judgesPast!==!0)continue;let m=b.scope.match;m&&!m(c)||a.push(...la(b,()=>b.evaluate({graph:n,subject:c,context:r,...o}),c.id))}}let u=new Set,p=a.filter(c=>{let f=`${c.message}|${[...c.nodeIds].sort().join(",")}`;return u.has(f)?!1:(u.add(f),!0)}).map(c=>{let f=ir(c.message);return f===c.message?c:{...c,message:f}});return Yr?Yr(n,e,p,t.today):p}var Yr;function Bb(n){Yr=n}function Xu(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 Qu(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 Et=(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,_e=(n,e)=>n.roles==="*"||(e.roles??[]).some(t=>n.roles.includes(t));function fa(n){return ui(n.map(e=>en(V(e).toLowerCase())),"or")}function Oe(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(Oe(n,e,t,r,void 0,i).ok)return{ok:!0};let f=!1;if(o.some(m=>Oe(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!=="*"&&_e(m,e)&&o.some(k=>Et(m.mutations,k))))return{ok:!0};f=!0}let h=f?[t]:[t,...o],g=[...new Set(h.flatMap(m=>Jr(n,m,r)))].sort(),b=(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":`${fa(g)} can`);return{ok:!1,refusal:{mutation:t,...r===void 0?{}:{kind:r},wouldNeed:g,message:pa(n,h,r,b,s)}}}let u=!1;for(let f of n.grants){if(!_e(f,e)||!Et(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)){u=!0;continue}return{ok:!0}}let p=Jr(n,t,r),c=u?"only on your own end of the link":p.length===0?"no role can":`${fa(p)} can`;return{ok:!1,refusal:{mutation:t,...r===void 0?{}:{kind:r},wouldNeed:p,message:pa(n,[t],r,c,s)}}}function pa(n,e,t,r,o){let i=[...new Set(e.flatMap(a=>ha(n,a,t)))],s=o.act?.(e[0]);return`Not permitted: ${s?`\u201C${s}\u201D`:e[0]}${t?` on ${en(o.noun?.(t)??t)}`:""} \u2014 ${r}.`+(i.length>0?` ${i.join(" ")}`:"")}function ha(n,e,t){return[...new Set(ga(n,e,t).flatMap(r=>r.describe||[]))]}var ga=(n,e,t)=>n.grants.filter(r=>Et(r.mutations,e)&&(t===void 0||Et(r.kinds??"*",t)));function Jr(n,e,t){let r=ga(n,e,t);return r.some(o=>o.roles==="*")?[]:[...new Set(r.flatMap(o=>o.roles))].sort()}function Xr(n,e,t){return n?t.filter(r=>{let o=D(e).id;return Qr(r).some(i=>Oe(n,e,r.name,i,void 0,o,void 0,()=>[o??[]].flat()).ok)}):t}var Qr=n=>n.subject&&n.subject.kinds!=="*"?n.subject.kinds:[void 0];var re=class extends Error{constructor(t,r="refused"){super(t);this.sentence=t;this.reason=r;this.name="ActRefusal"}};var eo="type-text",ie={};var Wn=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,ma(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,er(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,ma(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,er(t,e));return}case"add-edge":this.setEdge(e.edge,!0);return;case"remove-edge":this.setEdge(e.edge,!1);return}}};function ma(n,e){let t={...n};for(let[r,o]of Object.entries(e))Ye(o)?delete t[r]:t[r]=o;return t}var el=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 no(n,e,t,r){let o=u=>{let p=e.node(u);return p?t.served(p,e.writerOf(u))!==void 0:t.sees?.(u)??!1},i=el(n);if(i===void 0){let u=n.edge,p=t.edgeClean(u)&&o(u.from)&&o(u.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 u=e.incident(i).filter(c=>t.edgeClean(c)&&o(c.from===i?c.to:c.from)).map(c=>({op:"add-edge",edge:c})),p=n.op==="add-node"&&l===n.node&&u.length===0;return{primitives:p?[n]:[{op:"add-node",node:l},...u],faithful:p}}if(a&&!l){let u=n.op==="remove-node"&&a===s;return{primitives:u?[n]:[{op:"remove-node",node:a}],faithful:u}}if(n.op==="patch-node"){let u=(c,f)=>h=>h in c==(f!==void 0&&h in f);if(Object.keys(n.after).every(c=>u(a,s)(c)&&u(l,d)(c)))return{primitives:[n],faithful:!0};let p=c=>Object.fromEntries(Object.keys(n.after).map(f=>[f,f in c?c[f]:pe]));return{primitives:[{op:"patch-node",id:i,before:p(a),after:p(l)}],faithful:!1}}if(n.op==="splice-text"){let u=n.field;if(a[u]===s[u]&&l[u]===d[u])return{primitives:[n],faithful:!0};let p=c=>({[u]:u in c?c[u]:pe});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 ya(n,e,t){if(n.length===0)return[];let r=e.log.all(),o=r[0]?.seq??0,i=n.every(c=>r[c.seq-o]?.id===c.id),s=new Wn(e.present,e);if(!i)return s.begin(e.log.length??o+r.length),n.map(c=>{let f=D(c.author).id,h=c.primitives.map(g=>no(g,s,t,()=>f));return{op:c,primitives:h.flatMap(g=>g.primitives),faithful:h.every(g=>g.faithful)}});let a=new Set(n.map(c=>c.seq)),d=Number.POSITIVE_INFINITY,l=Number.NEGATIVE_INFINITY;for(let c of a)c<d&&(d=c),c>l&&(l=c);d-=o,l-=o;let u=nl(r,d,e.present,t),p=u?new Wn(e.present,e,u.unversioned):s;for(let c=r.length-1;c>=d;c--){let f=r[c].primitives;for(let h=f.length-1;h>=0;h--)p.undo(f[h])}return tl(n,r,d,l,a,p,u?.judge??t,e)}function nl(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,c)=>{s.has(p)||a.has(p)||(o(p)?i(c)?(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 c of n[p].primitives)c.op==="add-node"||c.op==="remove-node"?l(c.node.id,c.node):c.op==="patch-node"?(l(c.id,c.before),l(c.id,c.after)):c.op==="splice-text"&&(l(c.id,{}),s.has(c.id)||(a.add(c.id),d.delete(c.id)));for(let p of d){let c=t.getNode(p);c&&i(c)&&(d.delete(p),a.add(p))}return{unversioned:new Set([...d,...s]),judge:{...r,served:(p,c)=>d.has(p.id)?p:s.has(p.id)?void 0:r.served(p,c)}}}function tl(n,e,t,r,o,i,s,a){let d=new Map;for(let l=t;l<=r;l++){let u=e[l];if(i.begin(u.seq),!o.has(u.seq)){for(let f of u.primitives)i.apply(f);continue}let p=(f,h)=>a.writers?.writerAt(f,h,u.seq+1),c=u.primitives.map(f=>no(f,i,s,p));d.set(u.seq,{op:u,primitives:c.flatMap(f=>f.primitives),faithful:c.every(f=>f.faithful)})}return n.map(l=>d.get(l.seq))}function tv(n,e,t,r){let o=new Wn(e.present,e);return o.begin(e.log.length??e.log.all().length),n.flatMap(i=>no(i,o,t,()=>r).primitives)}var va="A change you cannot see",xa={kind:"system",id:"withheld",name:"Someone"};function pn(n){return n.withheld===!0}var qn=Ne,wa=(n,e)=>Object.entries(n).some(([t,r])=>t!=="id"&&t!=="kind"&&I(r,e));function ka(n){if(typeof n!="function")return n;let e=n,t=r=>e(r.id)&&!wa(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 Sa(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 rl(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 wa(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]=pe;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 to(n,e,t){let r=ka(e),o=i=>r.shows(i)&&$a(r,i);return{id:n.id,seq:n.seq,batch:n.batch,author:xa,intent:va,mutation:null,primitives:t??n.primitives.flatMap(i=>{let s=rl(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 hn(n,e){let t=ka(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 ya(n,r.timeline,o).map(({op:i,primitives:s,faithful:a})=>(!i.withheld&&a?ba(i,r,s):void 0)??to(i,r,s))}return n.map(o=>(!o.withheld&&!Sa(o,r.shows)?ba(o,r):void 0)??to(o,r))}function ba(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)&&$a(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 u=new Set,p=f=>{if(typeof f=="string")u.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))u.add(h),p(g)};t&&p(t);let c=f=>e.sees(f)||u.has(f);if(!I(r,c))return l&&n.mutation&&p(n.mutation.args),I({...d,primitives:[],inverse:[]},l?c:e.sees)?void 0:d}function $a(n,e){return n.timeline===void 0||n.kindOf(e)!==void 0}var Ze=class extends M{constructor(t){super(t.message);this.check=t;this.name="UndoBlockedError"}get blockedBy(){return this.check.blockedBy}};function Hn(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(b=>b.batch)),g=e.filter(b=>!h.has(b));if(g.length>0)return{ok:!1,ops:o,blockedBy:[],includeBatches:[],reason:"missing",message:`Cannot undo ${g.map(b=>`batch ${b}`).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(pn))return{ok:!1,ops:o,blockedBy:[],includeBatches:[],reason:"forbidden",message:o.every(pn)?"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])),u=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=ie.aside?.(u,h);if(g===!0)continue;let b=[...new Set([...h.reads.filter(m=>s.has(m)),...g??[]])];b.length>0&&p.push({op:h,overlap:b})}if(p.length===0)return{ok:!0,ops:o};let c=p.filter(h=>!pn(h.op)).map(h=>`"${h.op.intent}" (op ${h.op.id}, read ${h.overlap.join(", ")})`).join("; ");if(p.some(h=>pn(h.op)))return{ok:!1,ops:o,blockedBy:p,includeBatches:[],message:`Cannot undo on its own \u2014 ${c?`a later operation depends on it: ${c}; 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: ${c}. Include ${f.map(h=>`batch ${h}`).join(", ")} to undo them together.`}}function Ra(n,e){return e?ro(e,n).flatMap(t=>[...t.primitives]):[...n].sort((t,r)=>r.seq-t.seq).flatMap(t=>Ie(t))}function ro(n,e){return ie.undone?ie.undone(n,e):[...e].sort((t,r)=>r.seq-t.seq).map(t=>({op:t,primitives:Ie(t)}))}var Ce=class extends Error{refusal;constructor(e){super(e.message),this.name="PermissionDeniedError",this.refusal=e}};function ol(n){let e=n instanceof Error?n.message:String(n);if(n instanceof Ce){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 re?{reason:n.reason,sentence:n.sentence}:n instanceof Ze?{reason:n.check.reason??"invalid",sentence:e}:{reason:"invalid",sentence:e}}var ue=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 il=["edit","remove","archive","unarchive","merge","leave-alone","allow-tidying"];var wv=n=>il.map(e=>`${e}-${n}`);function _a(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 oo=["connect","disconnect"],Oa=n=>n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),io=(n,e,t)=>`${n}-${e}-${Oa(t)}`;function kv(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}-${Oa(i)}`)return{act:t[1],kind:r,relation:i}}}}var Sv=n=>[...n].flatMap(([e,t])=>[...t].flatMap(r=>oo.map(o=>io(o,e,r)))),Aa=n=>`${/^[aeiou]/i.test(n)?"an":"a"} ${n}`;function Pa(n,e){let t=e.also?` (${e.also})`:"";return{title:`${e.one?`${n==="connect"?"Set":"Clear"} the ${e.to}`:`${n==="connect"?"Link":"Unlink"} ${Aa(e.to)}`}${t}`,fromTheOtherEnd:`${n==="connect"?"Link":"Unlink"} ${Aa(e.from)}${t}`}}function Ea(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 Ge=n=>n.trim().replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").replace(/-+/g,"-").toLowerCase();function Mt(n,e){let t=Ge(n),r=[...e];if(r.includes(n))return n;let o=r.filter(i=>Ge(i)===t);return o.length===1?o[0]:void 0}function sl(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 so(n,e){let t=[...e],r=Mt(n,t);if(r)return r;let o=Ge(n);if(o==="")return;let i,s=!1;for(let a of t){let d=sl(o,Ge(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 al=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 })`,gn=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?al(e):`Op "${e.id}" has seq ${e.seq} but the log is ${this.length} long`);da(e),this.ops.push(On(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 Ke(this.ops)}opsInBatch(e){return this.ops.filter(t=>t.batch===e)}batches(){return ao(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)))dl(i,a);return i}toJSON(){return[...this.ops]}};function dl(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 Ke(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 ao(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 co(n){return n?.automated===!0&&n.kind!=="human"&&n.kind!=="rule"}var za=n=>n?.[Bn]===!0,cl=(n,e)=>za(("graph"in n?n.graph:n).getNode(e));function Ma(n,e,t){let r=n.tryDefinition(e);return t===void 0?r?.tidying:r?.edges?.[t]?.tidying}var ul=n=>JSON.stringify(n,(e,t)=>t&&typeof t=="object"&&!Array.isArray(t)?Object.fromEntries(Object.entries(t).sort()):t);var ll=/^(archive|unarchive|remove|leave-alone|allow-tidying)$/;function fl(n,e){let t=Ge(n.name),r=e?.act(n.name),o=n.args??{},i=r?r.derived:_a(t),{id:s}=o;if(i&&typeof s=="string"){if(ll.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(u=>u!==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 Na=(n,e)=>`\u2248${ul(n.map(t=>fl(t,e)))}`;function Ia(n,e,t){let r=pl(n,t);return[e,...e.map(o=>[o])].map(o=>r.get(Na(o,t))).find(Boolean)}function pl(n,e){let t=Ke(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(Na(d,e),i)}return o}function ja(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(u=>e.getNode(u)??("node"in a?a.node:void 0));for(let u of l){if(!u)continue;if(za(u))return s(`change \u201C${C(n.tryDefinition(u.kind),u)}\u201D`,"a person said to leave it alone");if(!i)continue;let p=Ma(n,u.kind);if(p==="never")return s(`change ${oe(n,u.kind)} on its own`,"the app says they are never tidied");if(d&&p==="no-links")return s(`link or unlink ${oe(n,u.kind)} on its own`,"the app says they are never linked automatically")}if(d&&i&&l[0]&&Ma(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 hl(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 zt={scene:0,overview:10,rail:20,popover:30,dialog:40,toast:50},gl={plots:0,stage:1,tag:2,ties:2,lines:3,tieLabels:4,occupants:6,seatMarks:7,zoom:8,card:10,opened:11},ml={under:0,raised:1,over:2},uo=n=>`--graview-layer-${n}`,yl=n=>`var(${uo(n)}, ${zt[n]})`;function bl(){return Object.keys(zt).map(n=>` ${uo(n)}: ${zt[n]};`).join(`
4
- `)}function vl(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 Ta(){return`sub_${(globalThis.crypto?.randomUUID?.()??`${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`).replace(/-/g,"").slice(0,20)}`}function Da(n){return{...n,id:n.id??Ta(),at:n.at??new Date().toISOString()}}function xl(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=Da(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 lo=(n,e)=>`${n}\0${e}`,Fa=new WeakMap;function wl(n,e){let t=new Map;for(let[o,i]of Object.entries(e??{}))for(let[s,a]of Object.entries(i))t.set(lo(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(lo(o,i));if(!a)return;let d=0,l=a.length;for(;d<l;){let u=d+l>>1;a[u].seq<s?d=u+1:l=u}return d===0?void 0:a[d-1].by}}}}function kl(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=>!Ye(n.after[e]))];if(n.op==="splice-text")return[n.id,[n.field]]}function Sl(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=kl(s);if(!a)continue;let[d,l]=a;for(let u of l){let p=e.undoes===void 0?r:o!==void 0?n.writers.writerAt(d,u,o):void 0,c=lo(d,u),f=n.fields.get(c);f||n.fields.set(c,f=[]),f.push({seq:t,by:p}),i.push(c)}}n.written.push({seq:t,keys:i}),n.seqOf.set(e.id,t),n.read.push(e),n.end++}function $l(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 Yn(n){let e=n.all(),t=typeof n.length=="number"?n.length:e.length,r=t-e.length,o=Fa.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&&$l(o,i),r>o.base&&(o.read=o.read.slice(r-o.base),o.base=r))}else o=void 0;o||Fa.set(n,o=wl(r,r>0?[...n.epochs?.()??[]].reverse().find(i=>i.horizon)?.writers:void 0));for(let i=o.end;i<t;i++)Sl(o,e[i-r]);return o.writers}function La(n,e,t,r){let o=Yn(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 Ve={served:new WeakSet},Jn=n=>n.fields!==void 0||(n.hide?.length??0)>0,Pe=n=>Ve.on===!0||Ve.served.has(n);var fo=new WeakMap;function Rl(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 Al(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 _l(n,e){for(;n.entries.length>0&&n.entries.at(-1).seq>=e;){let t=n.entries.pop();(t.creator?n.creators:n.kinds).delete(t.id)}n.read.length=e-n.base,n.end=e}function le(n){let e=n.all(),t=typeof n.length=="number"?n.length:e.length,r=t-e.length,o=fo.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&&_l(o,i),r>o.base&&(o.read=o.read.slice(r-o.base),o.base=r))}else o=void 0;o||fo.set(n,o=Rl(r,r>0?Ol(n,r):void 0));for(let i=o.end;i<t;i++)Al(o,e[i-r]);return o.records}function Ol(n,e){let t=[...n.epochs?.()??[]].reverse().find(r=>r.horizon);return t?.seq===e?t:void 0}function Za(n,e,t){le(n);let r=fo.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 mn(n,e,t,r,o,i=Ve.on===!0){if(!n?.sees?.length||W(e))return!0;let s=n.sees.filter(a=>a.kinds.includes(t.kind)&&(i||!Jn(a)));return s.length===0?!1:(e=D(e),s.some(a=>{if(!_e(a,e))return!1;if(!a.own&&!a.via)return!0;let d=e.id;if(d===void 0)return!1;let l=u=>u.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 Nt="publish",po=n=>n?.mode==="on-publish",ho=(n,e,t)=>po(n)&&!W(e)&&(t==="published"||!(D(e).roles??[]).some(r=>n.working.includes(r))),se=globalThis[Symbol.for("@graview/core:publishing")]??={};se.input=()=>$e({through:X(Fe())});var mo=new Set;function It(n,e){return W(e)?mo:n.modules?.disabledKinds??mo}function Be(n,e){return W(e)?!1:(n.policy?.sees?.length??0)>0||It(n,e).size>0}function Va(n,e){if(!Be(n,e))return()=>!0;let t=n.modules?.disabledKinds??mo,r=n.policy?.sees??[],o=D(e),i=Pe(n),s=d=>!t.has(d)&&(r.length===0||r.some(l=>l.kinds.includes(d)&&_e(l,o)&&!l.own&&!l.via&&(i||!Jn(l)))),a=n.schema.kinds.every(s);return d=>a||d!==void 0&&s(d)}function yn(n,e){return t=>{let r=It(n,e);if(!n.policy?.sees?.length&&r.size===0)return!0;let o=le(n.log),i=n.graph.getNode(t);if(i)return!r.has(i.kind)&&mn(n.policy,e,i,n.graph,o,Pe(n));let s=o.kindOf(t)??Ba(n,o,t);return s===void 0?!0:!r.has(s)&&mn(n.policy,e,{id:t,kind:s},{out:()=>[],in:()=>[]},o,Pe(n))}}var Pl={out:()=>[],in:()=>[]};function Ba(n,e,t){if(e.knowsAll||Ve.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 El(n,e,t=new Map,r){let o=It(n,e);if(!n.policy?.sees?.length&&o.size===0)return()=>!0;let i=le(n.log);return s=>{let a=t.get(s);if(a!==void 0)return a;let d,l=n.graph.getNode(s);if(l)d=!o.has(l.kind)&&mn(n.policy,e,l,n.graph,i,Pe(n));else{let u=i.kindOf(s)??Ba(n,i,s);if(u===void 0)return r?.add(s),!0;d=!o.has(u)&&mn(n.policy,e,{id:s,kind:u},Pl,i,Pe(n))}return t.set(s,d),d}}function Ml(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 jt(n,e){return Ua(n,e).lens}var yo=()=>({judged:new Map,shown:new Map});function Ua(n,e){let t=Ml(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=(u,p,c,f,h)=>{let g=(w,R)=>{if(!u(w.id))return;let x;for(let j in w)if(!(!Object.hasOwn(w,j)||j==="id"||j==="kind"||!I(w[j],u))&&!(r!==void 0&&R(j)===r)){if(!t(w.kind,j))return;(x??=[]).push(j)}if(!x)return w;let S=x.join("\0"),P=i.get(w);if(P?.without===S)return P.node;let E=Object.fromEntries(Object.entries(w).filter(([j])=>!x.includes(j)));return i.set(w,{without:S,node:E}),E},b=w=>{let R=c();return g(w,x=>p().writerAt(w.id,x,R))},m=new WeakMap,k=h?w=>{let R=m.get(w);return R||m.set(w,R={node:b(w)}),R.node}:b,_=w=>{if(!u(w))return!1;let R=s.getNode(w);return R===void 0||k(R)!==void 0},$=h?.shown??new Map,A=h?w=>{let R=$.get(w);return R===void 0&&$.set(w,R=_(w)),R}:_,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,v={sees:u,shows:A,served:k,servedWith:g,optional:t,kindOf:f,...r!==void 0?{actor:r}:{},...y?{timeline:y}:{},hides:()=>Be(n,e),pin:h?()=>v:()=>d(yo())};return Ve.lens?.(v,n,e)??v};function d(u){let p,c=o(),f=le(n.log);return a(El(n,e,u.judged,u.unnamed),()=>p??=Yn(n.log),()=>c,h=>s.getNode(h)?.kind??f.kindOf(h),u)}return{lens:a(yn(n,e),()=>Yn(n.log),o,u=>s.getNode(u)?.kind??le(n.log).kindOf(u)),pinWith:d}}var Ca=new WeakMap,Ga=new WeakMap,zl=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 Wa(n,e){if(!Be(n,e))return n.log.all();let t=n.log.all(),r=n.log.length??t.length,o=r-t.length,i=[...It(n,e)].sort().join("\0"),s=qa(e),a=Ca.get(n.log);a||Ca.set(n.log,a=new Map);let d=a.get(s),{pinWith:l}=Ua(n,e),u=Ga.get(n.log);u||Ga.set(n.log,u=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(yo()),b=!0,m=zl(h);for(let k of m){let _=d.judgments.judged.get(k),$=d.judgments.shown.get(k);if(_!==void 0&&g.sees(k)!==_||$!==void 0&&g.shows(k)!==$){b=!1;break}}if(b){for(let k of m)if(u.has(k)){b=!1;break}}if(b){let k=[...d.ops,...hn(h,l(d.judgments))],_={horizon:o,off:i,length:r,last:t.at(-1),ops:k,judgments:d.judgments};return a.set(s,_),k}}let c={...yo(),unnamed:u},f=hn(t,l(c));return a.set(s,{horizon:o,off:i,length:r,last:t.at(-1),ops:f,judgments:c}),f}function Nl(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 bo(n,e){return{all:()=>n,undoneIds:()=>Ke(n),epochs:e}}var Ka=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 Ha=(n,e)=>`${qa(n)}@${e}`,go=(n,e)=>{let t=Reflect.get(n,e,n);return typeof t=="function"?t.bind(n):t},Il=Symbol.for("@graview/core:seat");function bn(n,e,t={}){if(ho(n.publishing,e,t.as)){if(se.served)return se.served(n,e);throw new Error("Load @graview/core/publishing to serve a reader of an app that publishes.")}return Ja(n,e)}var jl=()=>se.served!==void 0;function Ya(n){let e=Ka.get(n);return e||Ka.set(n,e=new Map),e}function Ja(n,e){if(!Be(n,e))return n;let t=Ha(e,"head"),r=Ya(n),o=r.get(t);if(o)return o;let i=n.graph,s=jt(n,e),a=$=>{let A=x=>x===void 0?void 0:$.served(x),y=x=>A(x)!==void 0,v=x=>y(i.getNode(x));return{served:A,seenNode:y,seenId:v,seenEdge:x=>v(x.from)&&v(x.to)&&!I(x,$.sees),servedAll:x=>x.flatMap(S=>A(S)??[])}},{served:d,seenId:l}=a(s),u=()=>a(s.pin?.()??s),p=($,A)=>{let y=Yn(n.log),v=s.pin?.()??s,w=$.nodes.flatMap(x=>v.servedWith(x,S=>y.writerAt(x.id,S,A))??[]),R=new Set(w.map(x=>x.id));return{nodes:w,edges:$.edges.filter(x=>R.has(x.from)&&R.has(x.to)&&!I(x,v.sees))}},c=$=>{let{removed:A,writers:y,...v}=$,w=p($.base,$.seq);if(!$.creators)return{...v,base:w};let R=new Set(w.nodes.map(S=>S.id)),x=Object.fromEntries(Object.entries($.creators).filter(([S,P])=>R.has(S)&&!I(P,s.sees)));return{...v,base:w,creators:x}},f=$=>$&&c($),h=()=>Wa(n,e),g=()=>bo(h(),()=>n.log.epochs()),b=new Proxy(i,{get($,A){switch(A){case"getNode":return y=>d($.getNode(y));case"has":return l;case"allNodes":case"nodesOfKind":return(...y)=>u().servedAll($[A](...y));case"count":return(...y)=>u().servedAll($.nodesOfKind(...y)).length;case"allEdges":case"edgesOfKind":case"outEdges":case"inEdges":return(...y)=>$[A](...y).filter(u().seenEdge);case"out":case"in":case"neighbors":return(y,...v)=>{let w=u();return w.seenId(y)?w.servedAll($[A](y,...v)):[]};case"snapshot":return()=>{let y=$.snapshot(),v=u();return{...y,nodes:v.servedAll(y.nodes),edges:y.edges.filter(v.seenEdge)}};case"size":{let y=u();return{nodes:y.servedAll($.allNodes({archived:"all"})).length,edges:$.allEdges({archived:"all"}).filter(y.seenEdge).length}}default:return go($,A)}}}),m=()=>{let $=h();return ao($,Ke($))},k=new Proxy(n.log,{get($,A){switch(A){case"all":case"toJSON":return()=>[...h()];case"epochs":return()=>$.epochs().map(c);case"lastEpoch":return()=>f($.lastEpoch());case"live":return()=>{let y=h(),v=Ke(y);return y.filter(w=>!v.has(w.id))};case"get":return y=>h().find(v=>v.id===y);case"opsInBatch":return y=>h().filter(v=>v.batch===y);case"batches":return m;default:return go($,A)}}}),_=new Proxy(n,{get($,A){switch(A){case Il:return{store:$,principal:e};case"graph":return b;case"log":return k;case"snapshot":return b.snapshot;case"batches":return m;case"canUndo":return y=>Hn(g(),typeof y=="string"?[y]:y);case"violations":return y=>$.violations(y,b).filter(v=>Nl(s,w=>i.has(w),v));case"findings":return()=>$.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=>$.wouldChange(y,e);case"preview":return(y,v,w)=>$.preview(y,v,{author:e,...w});case"seenBy":return(y,v)=>bn($,y,v);case"seenFor":return e;case"servedSeq":return $.servedSeq;case"checkpoint":return y=>f($.checkpoint(y));default:return go($,A)}}});return r.set(t,_),_}se.kit={seatView:Ja,viewsOf:Ya,viewKey:Ha,diff:Re,reads:ho};var vo=new Set;function xo(n,e){if(!n||e===void 0)return{enabled:new Set(Object.keys(n??{})),disabledKinds:vo,disabledMutations:vo,disabledInvariants:vo,administered:Xa(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:Xa(n,t)}}function Xa(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 Qa(n){return n.normalize("NFKD").replace(/\p{M}/gu,"").toLowerCase().trim().replace(/\s+/g," ")}var Tt=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=Qa(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=wo(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=Qa(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(wo(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=wo(r.sorted,t.key);r.sorted[i]===t.key&&r.sorted.splice(i,1)}};function wo(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 Tl(n,e){return e.includes("*")?"record":e.map(t=>H(n.tryDefinition(t),t)).join(" or ")}function ed(n,e,t,r){let o=Tl(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 td=Symbol.for("@graview/core:node-ref"),nd=n=>typeof n=="object"&&n!==null?n[td]:void 0;function Ee(n="*"){return Dl(L().check(Fn(1)),n)}function Dl(n,e){let t=Object.freeze(e==="*"?["*"]:[...e]),r=o=>{o&&Object.defineProperty(o,td,{value:t,enumerable:!0,configurable:!0})};return r(n),r(T(n)),n}function ko(n){if(typeof n!="object"||n===null)return;let e=nd(n);if(e)return e;let t=T(n),r=nd(t);if(r)return r;let o=t?.innerType;return o?ko(o):void 0}function Xn(n){let e=n.shape;if(!e)return[];let t=[];for(let[r,o]of Object.entries(e)){let i=ko(o);i&&t.push({name:r,kinds:i,optional:o.safeParse(void 0).success})}return t}function So(n){if(n===null||typeof n!="object")return JSON.stringify(n)??"null";if(Array.isArray(n))return`[${n.map(r=>r===void 0?"null":So(r)).join(",")}]`;let e=n;return`{${Object.keys(e).filter(r=>e[r]!==void 0).sort().map(r=>`${JSON.stringify(r)}:${So(e[r])}`).join(",")}}`}var rd=(n,e)=>n.key<e.key?-1:n.key>e.key?1:0;function Fl(n){let e=n.nodes.map(r=>({key:r.id,value:r})).sort(rd),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(rd);return So({nodes:e.map(r=>r.value),edges:t.map(r=>r.value)})}function vn(n){return`sha256:${id(Fl(n))}`}function od(n,e,t,r={}){let o=r.validate??!0,i=r.base??{nodes:[],edges:[]},s=vn(t),a=Q.from(n,i,{validate:o});for(let[g,b]of e.entries())try{a.applyPrimitives(b.primitives)}catch(m){let k=e[g-1];return{ok:!1,expected:vn(a.snapshot()),actual:s,...k?{divergedAfter:k.id}:{},reason:`The log does not fold: op "${b.id}" (${b.intent}) could not be applied. ${m instanceof Error?m.message:String(m)}`}}let d=vn(a.snapshot());if(d===s)return{ok:!0,hash:s};let l=g=>{let b=Q.from(n,i,{validate:o});for(let m=0;m<=g;m++)b.applyPrimitives(e[m].primitives);return vn(b.snapshot())},u=g=>{try{let b=Q.from(n,t,{validate:o});for(let m=e.length-1;m>g;m--)b.applyPrimitives(Ie(e[m]));return vn(b.snapshot())}catch{return}},p=g=>{let b=u(g);return b!==void 0&&b!==l(g)},c=-1,f=e.length-1;for(;c<f;){let g=Math.floor((c+f)/2);p(g)?f=g:c=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 Ll=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]),Zl=new TextEncoder,Cl=new Uint32Array(64),Gl=new Uint32Array(8),Dt=Array.from({length:256},(n,e)=>e.toString(16).padStart(2,"0"));function id(n){let e=Zl.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=Gl;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=Cl;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],_=s[m-2],$=(k>>>7|k<<25)^(k>>>18|k<<14)^k>>>3,A=(_>>>17|_<<15)^(_>>>19|_<<13)^_>>>10;s[m]=s[m-16]+$+s[m-7]+A>>>0}let l=i[0],u=i[1],p=i[2],c=i[3],f=i[4],h=i[5],g=i[6],b=i[7];for(let m=0;m<64;m++){let k=(f>>>6|f<<26)^(f>>>11|f<<21)^(f>>>25|f<<7),_=f&h^~f&g,$=b+k+_+Ll[m]+s[m]>>>0,A=(l>>>2|l<<30)^(l>>>13|l<<19)^(l>>>22|l<<10),y=l&u^l&p^u&p,v=A+y>>>0;b=g,g=h,h=f,f=c+$>>>0,c=p,p=u,u=l,l=$+v>>>0}i[0]=i[0]+l>>>0,i[1]=i[1]+u>>>0,i[2]=i[2]+p>>>0,i[3]=i[3]+c>>>0,i[4]=i[4]+f>>>0,i[5]=i[5]+h>>>0,i[6]=i[6]+g>>>0,i[7]=i[7]+b>>>0}let a="";for(let d=0;d<8;d++){let l=i[d];a+=Dt[l>>>24]+Dt[l>>>16&255]+Dt[l>>>8&255]+Dt[l&255]}return a}var Qn=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 Kl(n,e){return{...e,name:n}}function $o(n){if(!n.creates?.length)return!1;let e=n.input.shape;return e===void 0||!("id"in e)}function cd(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 $o(n)?[...r,"id"]:r}var sd=(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 Vl(n){let e=n?._zod?.def;for(let t=0;e?.innerType&&t<8;t++)e=e.innerType._zod?.def;return e}var Bl=/^-?(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][+-]?\d+)?$/;function ud(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"||!Bl.test(i)||Vl(t[o])?.type!=="number")continue;let s=Number(i);Number.isFinite(s)&&(r??={...e},r[o]=s)}return r??e}var ld=n=>typeof n=="string"&&n.length<=200&&/^[^\s\p{Cc}]+$/u.test(n);function Ul(n){if(typeof n!="object"||n===null)return;let e=n.id;if(e!==void 0){if(!ld(e))throw new M("An id is 1\u2013200 characters with no space",`Got ${JSON.stringify(e)}.`);return e}}function Wl(n){let{id:e,...t}=n;return t}function ad(n){return n.normalize("NFKD").replace(/\p{M}/gu,"").toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"")||"item"}function Ro(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 ql(n,e){if(e.limited&&e.me===void 0)return dd(n,e.held);let t=e.limited?`${n}.${Ro(e.me)}`:n,r=t;for(let o=2;e.seen(r);o++)r=`${t}-${o}`;return e.held(r)?dd(t,e.held):r}function dd(n,e){let t;do t=`${n}-${Math.floor(Math.random()*36**6).toString(36).padStart(6,"0")}`;while(e(t));return t}function xn(n,e,t,r={}){let o=$o(e)?Ul(t):void 0,i=ud(e.input,o===void 0?t:Wl(t)),s=cd(e);if(s&&typeof i=="object"&&i!==null&&!Array.isArray(i)){let y=Object.keys(i).filter(v=>!s.includes(v)&&i[v]!==void 0);if(y.length>0)throw new ue(e.name,[{path:[],message:sd(y,s,e.writtenBy)}])}let a=e.input.safeParse(i);if(!a.success){let y=Object.keys(e.input.shape??{});throw new ue(e.name,a.error.issues.map(v=>v.code==="unrecognized_keys"&&y.length>0?{...v,message:sd(v.keys,y,e.writtenBy)}:v))}let d=a.data,l=new Qn(r.seen??n),u=[],p=new Set,c=r.me===void 0?void 0:`.${Ro(r.me)}`,f=y=>!r.seesInFull||r.seesInFull()||c!==void 0&&new RegExp(`\\${c}(-[0-9a-z]+)?$`).test(y),h=y=>l.has(y)||n.has(y)||p.has(y),g,b=y=>{let v=new Set([...n.outEdges(y),...n.inEdges(y)]);for(let w of v)l.getNode(w.from),l.getNode(w.to),u.push({op:"remove-edge",edge:w});return v},m={graph:l,schema:n.schema,me:r.me,emit(y){u.push(y)},addNode(y){u.push({op:"add-node",node:y})},removeNode(y){let v=l.getNode(y)&&n.getNode(y);if(!v)throw new U(y,`Cannot remove missing node "${y}"`);b(y),u.push({op:"remove-node",node:v})},patchNode(y,v){let w=l.getNode(y)&&n.getNode(y);if(!w)throw new U(y,`Cannot patch missing node "${y}"`);let R={},x={};for(let[S,P]of Object.entries(v)){let E=w[S];JSON.stringify(E)===JSON.stringify(P)&&!r.keepUnchanged?.(P,S,w)||(R[S]=E,x[S]=P)}Object.keys(x).length!==0&&u.push({op:"patch-node",id:y,before:R,after:x})},archiveNode:y=>m.patchNode(y,{[cn]:!0}),unarchiveNode:y=>m.patchNode(y,{[cn]:void 0}),mergeNode(y,v){let w=l.getNode(v)&&n.getNode(v);if(!w)throw new U(v,`Cannot merge into missing node "${v}"`);if(y===v||Le(w))throw new M(y===v?"Cannot merge a record into itself":"Cannot merge into an archived record");let R=new Set([...n.outEdges(v),...n.inEdges(v)].map(z));for(let x of b(y)){let S={...x,from:x.from===y?v:x.from,to:x.to===y?v:x.to};S.from!==S.to&&!R.has(z(S))&&(R.add(z(S)),u.push({op:"add-edge",edge:S}))}m.archiveNode(y),g=v},addEdge(y){u.push({op:"add-edge",edge:y})},removeEdge(y){u.push({op:"remove-edge",edge:y.id!==void 0&&n.linkById(y.id)||y})},setSingleSource(y,v,w){n.inEdges(v,y).some(R=>R.from===w)||u.push({op:"add-edge",edge:{kind:y,from:w,to:v}});for(let R of n.inEdges(v,y))l.getNode(R.from),R.from!==w&&u.push({op:"remove-edge",edge:R})},freshId(y,v){if(o!==void 0&&!p.has(o)){if(!f(o))throw new M(`"${e.name}" makes its own id here`,`Leave id out${c?`, or end it "${c}"`:""}.`);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&&ld(w)&&f(w)&&!h(w))return p.add(w),w;let R=v?`${v}:${ad(y)}`:ad(y),S=ql(R,{seen:P=>(r.seen?r.seen.has(P):n.has(P))||p.has(P),held:h,limited:r.seesInFull!==void 0&&!r.seesInFull(v),me:r.me});return p.add(S),S}};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?.(u,e),_=new Set(u.flatMap(Ne)),$=new Qn(r.seen??n),A=e.describe?.(d,$)??`${e.name}(${Object.entries(d).map(([y,v])=>`${y}=${JSON.stringify(v)}`).join(", ")})`;return{primitives:u,reads:[...new Set([...l.reads(),...$.reads()])],...e.describe?{described:[...$.reads(),...k??[]]}:{},writes:[..._],intent:A,...g!==void 0?{mergedInto:g}:{},...p.size>0?{firstMinted:p.values().next().value}:{}}}var fd=Symbol.for("@graview/core:amount"),vx=(n,e)=>(Object.defineProperty(T(n),fd,{value:e,enumerable:!0}),n);function Ao(n,e=!0){let t=T(n);return t?.[fd]??(e&&t?.innerType?Ao(t.innerType):void 0)}function pd(n,e={}){let t=Number.isInteger(n),r={maximumFractionDigits:t?0:2,minimumFractionDigits:t?0:2};try{return he(n,e.locale,e.currency?{style:"currency",currency:e.currency,...r}:r)}catch{return he(n,e.locale,r)}}function hd(n,{format:e,unit:t,currency:r,locale:o}){let i=/^[A-Z]{3}$/.test(t??"");return e==="money"||!e&&i?pd(n,{...o?{locale:o}:{},...(i?t:r)?{currency:i?t:r}:{}}):e==="percent"?he(n,o,{style:"percent",maximumFractionDigits:0}):he(n,o)+(t?` ${t}`:"")}var Hl=Symbol.for("@graview/core:typed-field");function _o(n){let e=T(n);return e?e[Hl]??_o(e.innerType):void 0}var Yl=/^[("'“‘]*(?:(?:[a-z]{1,3}\.){2,}|(?:dr|mr|mrs|ms|mx|st|mt|vs|jr|sr|prof|no|fig|approx)\.)$/i;function Jl(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]==="."&&Yl.test(r))&&!(t.split(" ").length<3&&e.index+1<n.length))return t}}function gd(n,e=140){let t=n.replace(/^[#>\s]+|\*\*|`|\](\([^)\s]*\))?|\[/gm,"").replace(/\s+/g," ").trim(),r=Jl(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 Xl(n){let e=n.fields.shape;return Object.keys(e).flatMap(t=>{let r=St(e[t])?Kn(t):void 0;return r&&e[r]?[r]:[]})}var Ql=[["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 md(n,e){let t=new Set(e.map(o=>o.name)),r=[];for(let o of n.definitions){let i=Xl(o);if(i.length===0)continue;let s=o.kind,a=o.fields.shape,d=Object.keys(a).filter(u=>!(u in(o.fixed??{}))),l=u=>C(o,u);for(let[u,p,c,f]of Ql){let h=`${u}-${s}`;t.has(h)||r.push({name:h,derived:{kind:s,act:u},title:p,description:c,subject:{kinds:[s],arg:"id"},writes:i.map(an),...u==="skip"?{}:{creates:[s]},input:on({id:Ee([s]),on:L().check(Ln(/^\d{4}-\d{2}-\d{2}$/,"a day, like 2026-10-21")),...i.length>1?{field:X(Ks(i))}:{},...u==="skip"?{}:Object.fromEntries(d.map(g=>[g,X(a[g])]))}),describe:(g,b)=>f.replace("{}",l(b.getNode(String(g.id))??{id:g.id}))+we(String(g.on)),apply(g,b){let m=g.graph.getNode(String(b.id)),k=String(b.field??i[0]),_=m?.[k],$=m?.[an(k)],A=String(b.on);if(typeof _!="string"||!dn($))throw new re(`${l(m??{id:b.id})} does not repeat`,"refused");let y=sn(_,$,{from:A,to:A})[0];if(!y)throw new re(`${l(m)} does not fall on ${we(A)}`,"refused");let v=String(m.id),w=Object.fromEntries(d.filter(q=>b[q]!==void 0).map(q=>[q,b[q]])),R=an(k),x=q=>{let Z=Object.fromEntries(Object.entries({...m,...q,...w}).filter(([F,_n])=>_n!=null&&F!=="id")),de=g.freshId(l(Z));g.addNode({...Z,id:de,kind:s});for(let F of Object.keys(o.edges??{}))for(let _n of g.graph.out(v,F))g.addEdge({kind:F,from:de,to:_n.id})};if(u!=="split"){g.patchNode(v,{[R]:{...$,except:[...new Set([...$.except??[],A])].sort()}}),u==="detach"&&x({[k]:y,[R]:null});return}if(Object.keys(w).length===0)throw new re(`Nothing to change: give ${l(m)} from ${we(A)} something new`,"invalid");if(A<=_.slice(0,10))return g.patchNode(v,w);let S=new Date(Date.parse(`${A}T00:00:00Z`)-864e5).toISOString().slice(0,10),P=$.count?sn(_,{...$,except:[]},{to:S}).length:0,{count:E,except:j,...K}=$,ze=q=>j?.some(q)?{except:j.filter(q)}:{};g.patchNode(v,{[R]:{...K,until:S,...ze(q=>q<A),...E?{count:P}:{}}}),x({[k]:y,[R]:{...K,...ze(q=>q>=A),...E?{count:E-P}:{},continues:v}})}})}}return r}function yd(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 u=d.getNode(String(l));return u?C(n.tryDefinition(u.kind),u):String(l)};for(let d of n.definitions){let l=d.kind,u=Object.entries(d.edges??{}),p=c=>c.to==="*"?"record":c.to.map(f=>H(n.tryDefinition(f),f)).join(" or ");for(let[c,f]of u){let h=p(f),g=f.cardinality==="one",b=u.some(([A,y])=>A!==c&&p(y)===h),m=A=>V(A).toLowerCase(),k=Ea(l,c,f,m),_={to:k&&"to"in k?k.to:h,from:H(d,l),one:g,also:k&&"also"in k?k.also:b&&!k?m(c):void 0},$=_.from;for(let A of oo){let y=io(A,l,c);if(t.has(y)||f.acts==="none"||(A==="connect"?o.has(c):i.has(c)||f.appendOnly))continue;let{title:v,fromTheOtherEnd:w}=Pa(A,_),R=f.description?`: ${f.description.replace(/\.$/,"")}`:"";s.push({name:y,derived:{kind:l,act:A,relation:c},title:v,fromTheOtherEnd:w,description:A==="connect"?`Link this ${$} 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 ${$} and ${/^[aeiou]/i.test(h)?"an":"a"} ${h}${R}. Undo puts it back.`,subject:{kinds:[l],arg:"id"},...A==="connect"?{connects:[c]}:{severs:[c],destructive:!0},idempotent:!0,input:on({id:Ee([l]),to:Ee(f.to==="*"?"*":f.to)}),describe:(x,S)=>A==="disconnect"?`Unlink ${a(S,x.id)} from ${a(S,x.to)}`:g?`Set the ${h} of ${a(S,x.id)} to ${a(S,x.to)}`:`Link ${a(S,x.id)} to ${a(S,x.to)}`,apply(x,S){let P=String(S.id),E=String(S.to);for(let K of[P,E])if(!x.graph.getNode(K))throw new re(`there is no record "${K}"`,"invalid");let j=x.graph.out(P,c).some(K=>K.id===E);if(A==="disconnect"){if(!j)throw new re(`${a(x.graph,P)} is not linked to ${a(x.graph,E)}`,"invalid");x.removeEdge({kind:c,from:P,to:E});return}if(g)for(let K of x.graph.out(P,c))K.id!==E&&x.removeEdge({kind:c,from:P,to:K.id});j||x.addEdge({kind:c,from:P,to:E})}})}}}return s}function ef(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 Oo=n=>`\xA7${n}\xA7`;function nf(n,e){if(n.label)try{let r={id:Oo(e.length),kind:n.kind};e.forEach((s,a)=>r[s]=Oo(a));let o=String(n.label(r)),i=e.map((s,a)=>[s,o.indexOf(Oo(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 bd=new WeakMap;function Ft(n){let e=bd.get(n);if(e)return e;let t=n.fields.shape??{},r=Object.keys(t),o=n.display?.page,i=ef({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:nf(n,r)});return bd.set(n,i),i}function tf(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 rf(n,e){let t=Object.keys(e.input?.shape??{}),r=n?tf(n,e):void 0;if(!r)return t;let o=Ft(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 Po(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 Eo(n){let e=n.fields.shape;return Object.keys(e).filter(t=>!(t in(n.fixed??{})))}function Mo(n,e){let t=e.subject;return t?t.kinds==="*"?n.kinds:t.kinds:[]}function zo(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(Xn(n.input).map(s=>s.name));return Object.keys(o).filter(s=>s!==t.arg&&r.has(s)&&!i.has(s))}function No(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 Mo(n,o)){let s=n.tryDefinition(i);if(s)for(let a of zo(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 vd(n,e,t){let r=n.tryDefinition(t);if(!r)return[];let o=No(n,e).get(t);return Eo(r).filter(i=>!o?.has(i))}var xd=n=>`edit-${n}`;function wd(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),Mo(n,i).includes(t)&&zo(i,r).length>0&&o.add(i.name));return[...o]}function kd(n,e){let t=new Set(e.map(o=>o.name)),r=[];for(let o of n.definitions){let i=o.kind,s=xd(i);if(t.has(s))continue;let a=Po(vd(n,e,i),Ft(o),f=>f);if(a.length===0)continue;let d=No(n,e).get(i),l=Object.fromEntries(Eo(o).flatMap(f=>d?.get(f)?.length?[[f,d.get(f)]]:[])),u=o.fields.shape,p=H(o,i),c=a.map(f=>lt(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: ${c.join(", ")}.`,subject:{kinds:[i],arg:"id"},writes:a,...Object.keys(l).length>0?{writtenBy:l}:{},input:on({id:Ee([i]),...Object.fromEntries(a.map(f=>[f,X(af(u[f]))]))}),describe:(f,h)=>of(o,u,a,f,h),apply(f,h){let g={};for(let b of a){let m=h[b];m!==void 0&&(g[b]=m)}if(Object.keys(g).length===0)throw new re(`Nothing to change \u2014 give at least one of ${c.join(", ")} a value.`,"invalid");f.patchNode(h.id,g)}})}return r}function of(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 u=r[d],p=Kn(d),c=p!==void 0&&p in e,f=lt(n,c?p:d);return`the ${f===f.toUpperCase()?f:ci(f)}${l===0?` of ${s}`:""} to ${c?u?`repeat ${sf(u)}`:"stop repeating":Sd(n,e[d],d,u)}`});return a.length===0?`Changed nothing on ${s}`:`Changed ${a.length>1?`${a.slice(0,-1).join(", ")} and ${a.at(-1)}`:a[0]}`}var sf=n=>`every ${(n.interval??1)>1?`${n.interval} ${n.every}s`:n.every}`;function Sd(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(Zn(r).length>0)return Zn(r).map(i=>i.name).join(", ");if(Cn(e))return Array.isArray(r)&&r.length>1?`${r.length} linked records`:"a linked record";if(Array.isArray(r))return r.map(i=>Sd(n,e,t,i)).join(", ");if(typeof r=="boolean")return r?"yes":"no";if(typeof r=="number"){let i=Ao(e);return i?hd(r,i):_o(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(Qe.test(r))return we(r);if(at.test(r))return or(r);for(let i=T(e);i;i=T(i.innerType))if(i.type==="enum")return V(r);return`\u201C${gd(r,60)}\u201D`}function af(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 $d(n,e){return n.filter(t=>!t.derived&&(t.creates??[]).includes(e)).map(t=>t.name)}function Lt(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"?wd(n,e,t.derived.kind):$d(e,t.derived.kind)}function df(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,u)=>{let p=l.getNode(String(u));return p?C(o,p):String(u)},d=Ee([i]);for(let[l,u,p,c]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:c,subject:{kinds:[i],arg:"id"},...l==="remove"?{destructive:!0}:{},idempotent:!0,input:$e(l==="merge"?{id:d,into:d}:{id:d}),describe:(g,b)=>{let m=l==="remove"&&b.getNode(String(g.id)),k=m?new Set(Object.values(m).flatMap(_=>Zn(_).map($=>$.href))).size:0;return`${u} ${a(b,g.id)}${l==="merge"?` into ${a(b,g.into)}`:""}${k?` and its ${k} file${k>1?"s":""}`:""}`},apply:h?(g,b)=>g.patchNode(String(b.id),{[Bn]:l==="leave-alone"?!0:void 0}):(g,b)=>g[`${l}Node`](b.id,b.into)})}}return r}function Io(n,e){return[...kd(n,e),...df(n,e),...md(n,e),...yd(n,e)]}var cf=n=>({$made:n}),Zt=n=>typeof n=="object"&&n!==null&&Object.keys(n).join()==="$made"&&Number.isInteger(n.$made)&&n.$made>=0,uf=(n,e)=>Object.fromEntries(Object.entries(n.args??{}).map(([t,r])=>[t,Array.isArray(r)?r.map(e):e(r)])),Rd=n=>Object.values(n.args??{}).some(e=>Zt(e)||Array.isArray(e)&&e.some(Zt)),Ad=(n,e,t)=>({...n,args:uf(n,r=>{if(!Zt(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 lf=500,ff=120,pf=50,_d=4e3,hf=["model","suggestion","interaction","actor","run"],Od=n=>typeof n=="string"&&n.length>0&&n.length<=ff,gf=n=>{let e=JSON.stringify(n);return e===void 0?void 0:JSON.parse(e)};function et(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<=lf;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:hf.includes(i)?o&&=Od(s):i==="evidence"?o&&=Array.isArray(s)&&s.length<=pf&&s.every(Od):o&&=i!=="__proto__"&&i!=="constructor"&&i!=="prototype"&&(s=gf(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>_d)throw new M(`A lineage is at most ${_d} characters written out.`);return r}var wn="keep-link";function Pd(n){let e=(t,r)=>{let o=t.getNode(r);return o?C(n.tryDefinition(o.kind),o):r};return{name:wn,title:"Keep this link",input:$e({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 Ed=(n,e)=>[...n].filter(t=>!t.derived&&t.name!==wn&&typeof e=="string"&&(t.connects?.includes(e)||t.severs?.includes(e))).map(t=>t.name);var Md=["kind-unknown","node-shape","edge-dangling","edge-disallowed","rule-error","rule-budget"];function zd(n,e){let t=_t(n,e);return t&&[...t.fields].filter(Boolean)}function mf(n,e,t){return n.tryDefinition(e)?.fields?.shape?.[t]}function Ct(n,e){try{return C(n.tryDefinition(e.kind),e)}catch{return typeof e.label=="string"?e.label:"A record"}}var yf=n=>`${n.kind}:${n.from}->${n.to}`,Gt=(n,e)=>n<e?-1:n>e?1:0;function Nd(n,e,t={}){let{schema:r}=n,o=[],i=new Map;for(let c of e.nodes)i.has(c.id)||i.set(c.id,c);let s=c=>e.edges.filter(f=>f.from===c||f.to===c),a=c=>({action:"drop",primitives:[...s(c.id).filter(f=>i.has(f.from)&&i.has(f.to)).map(f=>({op:"remove-edge",edge:f})),{op:"remove-node",node:c}]}),d=new Set;for(let c of[...i.values()].sort((f,h)=>Gt(f.id,h.id))){if(!r.tryDefinition(c.kind)){d.add(c.id),o.push({code:"kind-unknown",id:c.id,message:`${Ct(r,c)} is a kind of record this app no longer has`,repair:a(c)});continue}let f=zd(r,c);if(f===void 0)continue;let h=Ct(r,c),g=new Map,b=f.length>0;for(let m of f){if(m==="id"||m==="kind"){b=!1;continue}let k=mf(r,c.kind,m),_=k?k.safeParse(void 0):{success:!0,data:void 0},$=r.tryDefinition(c.kind)?.defaults;!_.success&&k&&$&&Object.hasOwn($,m)&&(_=k.safeParse($[m])),_.success?_.data===void 0?g.set(m,{action:"clear",value:pe}):g.set(m,{action:"coerce",value:_.data}):b=!1}if(b){let m={...c};for(let[k,_]of g)_.value===pe?delete m[k]:m[k]=_.value;zd(r,m)!==void 0&&(b=!1)}if(f.length===0){o.push({code:"node-shape",id:c.id,message:`${h} does not fit what ${c.kind} declares`,repair:a(c)});continue}for(let m of f){let k=g.get(m),_=b&&k?{action:k.action,primitives:[{op:"patch-node",id:c.id,before:{[m]:c[m]===void 0?pe:c[m]},after:{[m]:k.value}}]}:a(c);o.push({code:"node-shape",id:c.id,detail:m,message:`${h}: ${V(m)} does not fit what ${c.kind} declares`,repair:_})}}let l=new Set,u=[];for(let c of[...e.edges].sort((f,h)=>Gt(z(f),z(h)))){if(l.has(z(c)))continue;l.add(z(c));let f=yf(c),h=i.get(c.from),g=i.get(c.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:c}]}});continue}u.push(c),!(d.has(h.id)||d.has(g.id))&&(r.edgeAllowed(c.kind,h.kind,g.kind)||o.push({code:"edge-disallowed",id:f,message:`${Ct(r,h)} \u2192 ${Ct(r,g)}: this app does not allow that link between them`,repair:{action:"drop",primitives:[{op:"remove-edge",edge:c}]}}))}let p=n.invariants??[];if(p.length>0){let c=Q.from(r,{nodes:[...i.values()],edges:u},{validate:!1}),f=new Set,h;try{h=fn(c,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 b=g.status==="could-not-judge"?"rule-error":g.status==="over-budget"?"rule-budget":void 0;if(!b)continue;let m=g.subjectId??g.invariant,k=`${b}|${m}|${g.invariant}`;f.has(k)||(f.add(k),o.push({code:b,id:m,detail:g.invariant,message:g.message}))}}return o.sort((c,f)=>Md.indexOf(c.code)-Md.indexOf(f.code)||Gt(c.id,f.id)||Gt(c.detail??"",f.detail??""))}var nt=()=>globalThis.__graviewWatch;function Id(n){nt()?.store?.(n)}function Kt(n){n!==void 0&&nt()?.learn?.({ids:[n],words:[]})}function jd(n,e){nt()?.refused?.({...n,...e===void 0?{}:{author:e}})}function jo(n,e){let t=nt();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 bf(n,e){n instanceof ue&&jo(n,e)}function vf(n,e,t){nt()?.seat?.(n,e,t)}function Do(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 To=15*6e4;function Td(n=Date.now(),e){let t=new Date(n).getTime(),r=dt(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=si(i.toISOString().slice(0,10),0,r);for(;ee(r,s)===o;)s+=To;for(;ee(r,s-To)!==o;)s-=To;return s-t}function xf(n,e){let t,r=()=>{t=setTimeout(()=>{let o=n.tick(new Date);r(),e?.(o)},Td(Date.now(),n.timeZone)+1e3),t.unref?.()};return r(),()=>clearTimeout(t)}var Vt=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"}},Fo="preview",G=(n,e)=>e===void 0?{}:{[n]:e},Ue={kind:"human"},Dd={kind:"system"},Ld={kind:"system",id:"modules",name:"Modules"},Fd=n=>n.mutation===null&&n.undoes===void 0;function Lo(n,e){return`${n.invariant}|${n.subjectId??""}|${n.line||e?.has(n.invariant)?n.label:n.message}`}var wf=new Set(["remove","archive","unarchive","merge"]),kf={has:()=>!0},Zd=n=>new Set(n.filter(e=>e.shape).map(e=>e.name));function Cd(n,e,t){let r=Zd(n),o=p=>Lo(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&&Lo(p,kf),u=d.map(l);return{introduces:a.filter(p=>{let c=l(p)?u.indexOf(l(p)):-1;return c<0||(u[c]=null,!1)}),resolves:d.filter((p,c)=>u[c]!==null)}}var kn=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"}},Bt=class extends M{constructor(t,r){let o=so(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};function Sf(){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 Zo=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??Ue,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=Sf();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?[]:Io(e.schema,e.mutations??[]))this.mutations.set(i.name,i);!e.past&&!this.mutations.has(wn)&&(this.keeper=Pd(e.schema),this.mutations.set(wn,this.keeper));let r=G("horizon",e.horizon),o={validate:this.validate};if(e.log){this.log=gn.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=gn.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(),Id(this))}stillNow(){if(this.past)throw new Vt(this.past)}countPastTheLog(){let e=t=>{let r=/(\d+)$/.exec(t);return r?Number(r[1]):0};for(let t of this.log.all())this.counter=Math.max(this.counter,e(t.batch)),this.opCount=Math.max(this.opCount,e(t.id));this.log.horizon>0&&(this.opCount=Math.max(this.opCount,this.log.length))}get servedSeq(){return this.log.length}get publishedSeq(){return se.seq?.(this)}get publisher(){return se.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:xo(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=xo(this.declaredModules,e).enabled,i=[...r].filter(u=>!o.has(u)),s=[...o].filter(u=>!r.has(u));if(i.length===0&&s.length===0)return;let a=u=>u.map(p=>{let c=this.declaredModules?.[p]?.kinds??[];return c.length>0?c.map(f=>oe(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:Ld,intent:Nn(d),mutation:null,primitives:[],reads:[],writes:[],at:this.now(),...G("via",t.via),enabledModules:[...o].sort()};return this.log.append(l),this.notify(Un,[l]),l}mutation(e){let t=this.mutations.get(this.spelled(e))??(e===Nt?this.publisher:void 0);if(!t)throw new Bt(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===eo&&!this.typer&&ie.typeText&&!this.past&&!this.mutations.has(e)&&this.mutations.set(e,this.typer=ie.typeText(this)),this.mutations.has(e)?e:Mt(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=Ed(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=>Lt(this.schema,i,s)??[]))]}if(e!==void 0&&e===this.typer)return ie.via(this.schema,[...this.mutations.values()],this.subjectKindOf(t,r),t?.args.field);if(e?.derived)return Lt(this.schema,[...this.mutations.values()],e)}moved(e,t){return Cd(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=Ue){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===Nt?this.publisher:void 0);if(o&&o===this.publisher)return se.verdict(this,t);let i=o?.subject&&e.args[o.subject.arg];return Oe(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 xn(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)?()=>le(this.log).creatorOf(i):void 0,o?.derived!==void 0&&wf.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]]:[],...Xn(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&&jd(e,t),new Ce(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=Dd){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||!Be(this,e))return t;let r=yn(this,e);return{...t,seen:bn(this,e).graph,keepUnchanged:o=>I(o,r),seesInFull:Va(this,e)}}collaborative(e,t){return ie.collaborative?.(this.schema,this.graph.getNode(e)?.kind,t)??!1}asSplices(e,t){return ie.asSplices?ie.asSplices(this,e,t):e}missingFor(e,t=Ue){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=bn(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=Ue){let r=this.modules.administered.get(e);return r?(r.mutations??[]).some(o=>{let i=this.mutations.get(o);return!!i&&Qr(i).some(s=>Oe(this.policy,t,o,s,this.viaOf(i)).ok)}):!1}seenBy(e,t){return bn(this,e,t)}sees(e,t){return this.graph.has(t)&&yn(this,e)(t)}labels;resolveRef(e,t,r=Ue){let o=(this.policy?.sees?.length??0)>0,i=c=>!o||this.sees(r,c),s=this.graph.getNode(t);if(this.labels??=new Tt(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=c=>{let f=c.filter(h=>!this.graph.isArchived(h));return f.length?f:c},l=d(a.exact.filter(i)),u=l.length>0,p=(u?l:d(a.prefix.filter(i))).map(c=>({id:c,kind:this.graph.getNode(c).kind,label:this.labels.labelOf(c)??c})).sort((c,f)=>c.label<f.label?-1:c.label>f.label?1:c.id<f.id?-1:1);return p.length===1?{ok:!0,id:p[0].id,label:p[0].label,by:u?"label":"prefix"}:ed(this.schema,e,t,p)}kindsKeptFrom(e=Ue){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=Pe(this);for(let s of this.schema.kinds)!r.some(d=>d.kinds.includes(s)&&_e(d,e)&&(!d.own&&!d.via||e.id!==void 0)&&(i||!Jn(d)))&&!o.has(s)&&t.add(s)}return t}permittedMutations(e=Ue){let t=this.allMutations(),r=Xr(this.policy,e,t.filter(s=>!s.derived&&s!==this.publisher)),o=this.publisher&&se.verdict(this,e).ok?[this.publisher]:[],i=t.filter(s=>s.derived!==void 0&&Oe(this.policy,e,s.name,s.derived.kind,this.viaOf(s),D(e).id).ok);return[...r,...o,...i]}subjectKindOf(e,t=Dd){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)&&!yn(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=ea(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=Do(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(Un,[]);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(Un,[])}violations(e,t=this.graph){return fn(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 xn(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=xn(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:gn.from(this.log.all(),this.log.epochs(),{horizon:this.log.horizon}),listeners:new Set,labels:void 0,nextId:()=>`${Fo}:${++t}`,mintBatch:()=>Fo,rehearsing:!0});let r=this.typer&&ie.typeText(e);return Object.assign(e,{typer:r,mutations:r?new Map(this.mutations).set(eo,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=fn(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(x=>this.spelledCall(x));this.stillNow();let i=t.batch??this.mintBatch("batch"),s=t.author??this.by,a=et(t.lineage),d=[],l=[],u=new Set,p=new Set,c=[],f=this.violations(r),h=this.graph.snapshot(),g=this.log.length,b=x=>{let S=this.policy||this.publisher&&x.name===Nt?this.permits(x,s):void 0;S&&!S.ok&&this.refuse(S.refusal,s.id)},m=x=>{let S=this.refusesAgent(x,s)??this.namesTurnedOff(x,s);S&&this.refuse(S,s.id)},k=o.map(Rd);o.forEach((x,S)=>k[S]||b(x)),o.forEach((x,S)=>k[S]||m(x));let _=co(s);_&&this.refuseDeclined(o,s),this.rehearsing||Kt(s.id);let $=[],A=[],y=new Map,v=x=>typeof x=="string"?y.get(x)??x:Array.isArray(x)?x.map(v):x;try{for(let[x,S]of o.entries()){let{mintedHint:P,...E}=S,j=y.size?{...E,args:Object.fromEntries(Object.entries(E.args).map(([F,_n])=>[F,v(_n)]))}:E,K=k[x]?Ad(j,$,x):j;k[x]&&(b(K),m(K));let ze=this.mutation(K.name);if(ze===this.publisher){let F=se.op(this,{id:this.nextId(),at:this.now()},K,i,s,t);d.push(F),c.push(F.intent);continue}let q=this.missingFor(K,s);if(q)throw q;let Z;try{Z=xn(this.graph,ze,K.args,{...this.sighted(s),hint:P})}catch(F){throw F instanceof ue&&!this.rehearsing&&jo(F,s.id),F}if(P!==void 0&&Z.firstMinted!==void 0&&Z.firstMinted!==P&&y.set(P,Z.firstMinted),_){let F=ja(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;A[x]=Z.firstMinted,$[x]=Z.primitives.find(F=>F.op==="add-node")?.node.id;let de={id:this.nextId(),seq:this.log.length,batch:i,author:s,intent:ze.describe!==void 0?Z.intent:t.intent??Z.intent,...G("batchIntent",t.intent),mutation:K,primitives:this.asSplices(Z.primitives,t.base).map(st),reads:Z.reads,writes:Z.writes,...ze.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(de.primitives),this.log.append(de),d.push(de),l.push(...de.primitives);for(let F of de.reads)u.add(F);for(let F of de.writes)p.add(F);c.push(de.intent)}}catch(x){throw this.putBack(h,g),x}let w=Ae(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,...A.length>0?{minted:A}:{},diff:w,primitives:l,reads:[...u],writes:[...p],intent:t.intent??c.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 kn(d,l)}let a=this.log.length;for(let[d,l]of o.entries()){let u=On({...l,seq:a+d});this.log.append(u),s.push(u)}return this.notify(Ae(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(st),u={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(Ne))],at:a.at??this.now(),...G("undoes",a.undoes),...G("via",a.via),...G("lineage",et(a.lineage))};if(r.has(u.id))throw new M(`Op "${u.id}" (${u.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(u.id),u}),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 kn(a,d)}for(let a of i)this.log.append(a);for(let a of i)Kt(a.author.id);return this.notify(Ae(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=et(t.lineage),l=this.asSplices(e,t.base).map(st),u=[];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(Ne))],at:this.now(),...G("via",t.via),...G("lineage",d)};this.graph.applyPrimitives(f.primitives),this.log.append(f),u.push(f),Kt(o.id)}let p=this.violations(),c=Ae(s,this.graph.snapshot(),l);return this.notify(c,u),{batch:r,ops:u,diff:c,primitives:l,reads:[],writes:u[0]?.writes??[],intent:a,...this.moved(i,p),violationsAfter:p}}findings(){return Nd({schema:this.schema,invariants:this.allInvariants()},this.graph.snapshot(),{invariantOptions:this.invariantOptions})}batches(){return this.log.batches()}canUndo(e){return Hn(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=Ra(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(Fd),...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=Hn(bo(hn(this.log.all(),jt(this,o)),()=>this.log.epochs()),r);if(!g.ok)throw new Ze(g)}let s=this.canUndo(r);if(!s.ok)throw new Ze(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=et(t.lineage);if(this.policy||this.publisher)for(let g of s.ops){if(!g.mutation)continue;let b=D(g.author).id,m=_=>JSON.stringify(_).includes(JSON.stringify(b)),k=b!==void 0&&b!==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(),u=this.violations(),p=[],c=this.log.length;for(let{op:g,primitives:b}of ro(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:b,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:Fd(g)}),this.log.append(m),p.push(m)}let f=Ae(l,this.graph.snapshot(),p.flatMap(g=>[...g.primitives]));this.admitted(t,p,p.flatMap(g=>[...g.primitives]),f,l,c);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(u,h),violationsAfter:h}}authorName(e){return Vn(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=Ia(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&&ca(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(),u=[],p=[],c=[];this.quiet++;try{for(let b of[...i].reverse())this.graph.applyPrimitives(Ie(b),{restoring:!0,inPlace:!0});this.log.truncate(s);let g=new Set(this.log.all().map(b=>b.id));for(let b of e.confirmed){if(g.has(b.id))continue;try{this.graph.applyPrimitives(b.primitives,{restoring:b.undoes!==void 0})}catch(k){throw new kn(b,k)}let m=On({...b,seq:this.log.length});this.log.append(m),g.add(b.id),u.push(m)}for(let b of e.pending){let m=i.filter(k=>k.batch===b);if(m.length!==0)try{p.push(...this.replay(b,m))}catch(k){c.push({batch:b,error:k})}}}catch(g){this.log.truncate(s);for(let b of i)this.log.append(b);throw this.graph.load(l),g}finally{this.quiet--}let f=Re(l,this.graph.snapshot()),h=[...u,...p];return this.notify(f,h),{diff:f,confirmed:u,pending:p,refused:c}}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=[],u=[];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))}catch(g){u.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)),c=Re(i,this.graph.snapshot());return this.notify(c,[...p,...l]),{diff:c,adopted:p,pending:l,refused:u}}replay(e,t){let r=t[0],o={author:r.author,batch:e,...G("intent",r.batchIntent),...G("via",r.via),...G("lineage",r.lineage)};if(r.undoes!==void 0){let i=t.map(a=>this.log.get(a.undoes??"")),s=t.find((a,d)=>i[d]===void 0);if(s)throw new M(`What "${s.intent}" took back is no longer in the log`);return this.undoing([...new Set(i.map(a=>a.batch))],o).ops}return t.every(i=>i.mutation!==null)?this.applying(t.map(i=>i.mutation),o).ops:this.append(t.map(({seq:i,...s})=>s))}snapshot(){return this.graph.snapshot()}verify(){let e=this.log.lastEpoch();return od(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),_=Date.parse(e.now??this.now())-(e.keepDays??90)*864e5,$=t.find(y=>Date.parse(y.at)>_),A=$?$.seq:this.log.length;r=Math.min(m,A)}let o=po(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,...u}=this.log.checkpointAt(this.schema,r,{validate:this.validate}),p=new Set(u.base.nodes.map(m=>m.id)),{creators:c,removed:f}=Za(this.log,r,m=>p.has(m)),h=le(this.log),g=La(this.log,r,u.base.nodes,m=>I(m,k=>!p.has(k)&&h.kindOf(k)===void 0)),b=m=>m&&Object.keys(m).length>0;return{...u,...b(c)&&{creators:c},...f&&{removed:f},...b(g)&&{writers:g}}}compact(e){return this.stillNow(),this.log.compact(e)}};var $f=n=>`lens:${n}`,Rf={hidden:[],removed:[],may:{views:!1,lenses:!1}};function Af(n,e,t){return n.name!==void 0&&e.may.views?"view":n.declared&&e.may.lenses&&t.lens?"lens":null}var Gd=["full","summary","glyph"],tt="view:",Go=(n,e)=>n.as===e.as&&(n.over??[n.kind]).includes(e.kind),_f=n=>n.filter((e,t)=>!n.slice(0,t).some(r=>Go(r,e)));function ve(n){return n.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function rt(n,e){return`/${ve(n.tryDefinition(e)?.plural??`${e}s`)}`}function Of(n,e,t){return`${rt(n,e)}/${encodeURIComponent(t)}`}function Pf(n,e){return`/places/${encodeURIComponent(n)}${e?`?of=${encodeURIComponent(e)}`:""}`}function Kd(n,e){return e.some(t=>t.as===n.as&&!Go(n,t))}function Ef(n,e,t){return Kd(n,e)?`${n.title} \xB7 ${(t.tryDefinition(n.kind)?.plural??`${n.kind}s`).toLowerCase()}`:n.title}var We=(n,e,t="")=>`${n}|${e.cardinality}|${e.fidelity}|${t}`;function Co(n){switch(n){case"full":return["full","summary","glyph"];case"summary":return["summary","full","glyph"];case"glyph":return["glyph","summary","full"]}}function Mf(n){let e=new Map,t=[],r=[],o,i,s={arrange(a){return a!==void 0&&(o=a),s},arrangement:()=>o,home(a){return a!==void 0&&(i=a),s},homeView:()=>i,register(a,d,l,u){let p={...u?.over?.[1]?{over:u.over}:{},...u?.hidden?{hidden:!0}:{},...u?.name?{name:u.name}:{},...u?.declared?{declared:!0}:{}},c={kind:a,cardinality:d.cardinality,fidelity:d.fidelity,view:l,...u?.title?{title:u.title}:{},...u?.across?{across:u.across}:{},...u?.beside?{beside:!0}:{},...p};if(r.push(c),!u?.beside&&!p.hidden&&e.set(We(a,d),c),u?.title){let f=ve(u.title);e.set(We(a,d,f),c),d.cardinality==="many"&&!t.some(h=>h.kind===a&&h.as===f)&&t.push({kind:a,title:u.title,as:f,...u.across?{across:u.across}:{},...p,...u.lens?{lens:u.lens}:{},...u.reads?.length?{reads:u.reads}:{}})}return s},places:()=>t,forget(a,d){for(let u of Gd)e.delete(We(a,{cardinality:"many",fidelity:u},d));let l=t.findIndex(u=>u.kind===a&&u.as===d);return l>=0&&t.splice(l,1),s},lookup(a,d){return e.get(We(a,d))?.view},resolve(a,d,l){if(l)for(let u of Co(d.fidelity)){let p=e.get(We(a,{cardinality:d.cardinality,fidelity:u},l));if(p)return p}for(let u of Co(d.fidelity)){let p=e.get(We(a,{cardinality:d.cardinality,fidelity:u}));if(p)return p}if(d.cardinality==="one")for(let u of Co(d.fidelity)){let p=e.get(We(a,{cardinality:"many",fidelity:u}));if(p)return p}},registrations:()=>r,all(){return[...e.values()]},kindsWithViews(){return[...new Set([...e.values()].map(a=>a.kind))]}};return s}var zf=["day","week","month","year","decade"];function Vd(n){let e={};n.q&&n.q.trim().length>0&&(e.query=n.q);let t=Gr(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,...zf.includes(o)?{bucket:o}:{}})}return e}function Ko(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 Ut(n,e,t){let r=Ko(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 Nf(n,e,t){let r=Ko(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 ot={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"]}},If=20,Ud=Object.keys(ot),jf=(n,e,t,r=ot[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.`}),Wd=n=>Object.hasOwn(ot,n);function Vo(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 Sn=n=>typeof n=="object"&&n!==null&&!Array.isArray(n);function Bd(n,e,t){let r=n.tryDefinition(e)?.fields.shape,o=T(r?.[t]);for(;o&&(o.type==="optional"||o.type==="default"||o.type==="nullable"||o.type==="prefault");)o=T(o.innerType);return o?.type!=="enum"?[]:(o.entries?Object.values(o.entries):o.values??[]).filter(s=>typeof s=="string")}function Tf(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 u=`lenses.${l}`,p=typeof d.title=="string"&&d.title.trim().length>0?d.title.trim():void 0,c=(v,w)=>{t.push({index:l,name:d.name,...p?{title:p}:{},why:v}),w&&r.push({severity:"warning",...w})};if(!Wd(d.name)){p?c(`"${d.name}" is not a lens this framework draws`,{code:"lens-not-shipped",path:`${u}.name`,message:`"${p}" names the lens "${d.name}", which the framework does not ship, so nothing draws it.`,fix:`Name one of ${Ud.join(", ")} \u2014 or register the view yourself and drop the title.`}):c("it is a lens this app wrote, drawn by the app's own views");return}if(!p)return c("it has no title, so it is bindings the checker holds and no place");let f=ot[d.name],h=Sn(d.options)?d.options:{};if(d.options!==void 0&&!Sn(d.options))return c("its options are not an object",{code:"lens-options-not-an-object",path:`${u}.options`,message:`"${p}" has options that are not an object.`,fix:'Write them as { "<option>": <value> }, or drop them.'});for(let v of Object.keys(h))f.options.includes(v)||r.push({severity:"warning",code:"lens-option-unknown",path:`${u}.options.${v}`,...jf(d.name,v,p,f.options)});let g={};for(let v of f.options)h[v]!==void 0&&(g[v]=h[v]);d.arrangedBy&&(g.arrangedBy=Vd(d.arrangedBy));let b=Sn(d.bindings)?d.bindings:{},m=[],k,_=(v,w,R)=>c(w,{code:"lens-cannot-draw",path:v,message:`"${p}" cannot draw: ${w}.`,fix:R});if(f.binds==="fields"){let v=Object.keys(b).filter(R=>Sn(b[R])),w=v.filter(R=>!o.has(R));if(v.length===0)return _(`${u}.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=b,m=v,d.name==="timeline"){let R=h.columns;if(Array.isArray(R))g.columns=R.map(x=>typeof x=="string"?{id:x,label:x}:x);else{let x=v.flatMap(P=>{let E=b[P],j=typeof E.column=="string"?E.column:typeof E.columns=="string"?E.columns:void 0;return j?Bd(n.schema,P,j):[]}),S=[...new Set(x)];if(S.length===0)return _(`${u}.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=S.map(P=>({id:P,label:P.toUpperCase()}))}g.extent===void 0&&(g.extent=1440)}if(d.name==="columns"){if(g.sort!==void 0){let x=v.map(S=>Ut(g.sort,s(S),S)).find(Boolean);x&&(r.push({severity:"warning",code:"lens-sort",path:`${u}.options.sort`,message:`"${p}" cannot order its cards: ${x}.`,fix:'Write { "by": "<a field>", "direction": "asc" }, or drop it.'}),delete g.sort)}let R=new Set;for(let x of v){let S=b[x].column;if(typeof S!="string"||!s(x).includes(S))return;let P=Bd(n.schema,x,S);if(P.length===0)return _(`${u}.bindings.${x}.column`,`its column field "${S}" is not a choice`,`Bind "column" to a choice field of ${x}, 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 x of["collapsed","hidden"])Vo(g,x,S=>R.has(S))}if(d.name==="calendar"&&g.today!==void 0&&!(typeof g.today=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(g.today)))return _(`${u}.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,x=E=>E===void 0||Number.isInteger(E)&&E>=1&&E<=9999,S=typeof R=="number"?{years:R,title:"Years"}:R;Sn(S)&&Number.isInteger(S.years)&&S.years>=1&&S.years<=200&&typeof S.title=="string"&&S.title.trim().length>0&&x(S.from)&&x(S.to)&&Object.keys(S).every(E=>["years","title","from","to"].includes(E))&&!(typeof S.from=="number"&&typeof S.to=="number"&&S.to<S.from)?g.horizon=S:(delete g.horizon,r.push({severity:"warning",code:"lens-horizon",path:`${u}.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 _(`${u}.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 v=x=>{let S=b[x];if(Sn(S)){if(typeof S.kind=="string")return S.kind;if(typeof S.edge=="string")return S.edge;if(Array.isArray(S.path))return{path:S.path};if(typeof S.field=="string")return S.field}};for(let x of f.requiredRoles)if(v(x)===void 0)return;let w=d.name==="coverage"?"rows":d.name==="board"?"slots":"regions",R=v(w);if(!o.has(R))return;if(d.name==="coverage"){let x=v("columns");if(!o.has(x))return;let S=v("link");if(typeof S=="string"&&!i.has(S))return;Object.assign(g,{rows:R,columns:x,link:S}),x!==R&&(k=x);for(let[P,E]of[["sort",R],["columnSort",x]]){if(g[P]===void 0)continue;let j=Ut(g[P],s(E),E);j&&(r.push({severity:"warning",code:"lens-sort",path:`${u}.options.${P}`,message:`"${p}" cannot order its ${P==="sort"?"rows":"columns"}: ${j}.`,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:v("x"),y:v("y"),fill:v("fill")});for(let x of["x","y"])if(!s(R).includes(g[x]))return}else{Object.assign(g,{regions:R,outline:v("outline")});for(let x of["markers","at","within","nests","regionKind","markerKind"]){let S=v(x);typeof S=="string"&&(g[x]=S)}}m=[R]}else if(d.name==="blocks"){if(!d.on)return _(`${u}.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 _(`${u}.options.blocks`,"it has no blocks to draw",`Say "options": { "blocks": [{ "headline": "\u2026" }, { "list": "all('<kind>')", "as": "card" }] }.`)}else{let v=["user","person","member"].find(w=>o.has(w));if(!d.on&&!v)return _(`${u}.on`,"it does not say which kind it stands on",'Say "on": "<the kind whose records are the people>".');m=v?[v]:[]}if(d.on!==void 0){if(typeof d.on!="string"||!o.has(d.on))return _(`${u}.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 v=[g.rows,g.columns].find(w=>w!==d.on);k=typeof v=="string"?v:void 0}}let $=typeof g.rows=="string"?g.rows:m[0];if($!==void 0){let v=["label",...s($)],w=new Set(["is",...v,...Object.keys(n.schema.tryDefinition($)?.edges??{})]);Vo(g,"search",R=>v.includes(R)),Vo(g,"filters",R=>w.has(R.split(".")[0]))}let A=ve(p);if(A.length===0)return _(`${u}.title`,"its title has no letters or digits to make an address of","Give it a title a person would say.");for(let v of m){let w=`${v}|${A}`;if(a.has(w))return c(`another lens on ${v} is already called "${p}"`,{code:"lens-title-taken",path:`${u}.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 v of m)a.set(`${v}|${A}`,l);let y=d.create;y!==void 0&&typeof y!="boolean"&&r.push({severity:"warning",code:"lens-create",path:`${u}.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:A,kinds:m,...k?{across:k}:{},options:g,...d.hidden===!0?{hidden:!0}:{},...y===!1?{create:!1}:{}})}),{drawn:e,undrawn:t,findings:r}}var Df=6;function Ff(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 Lf(n,e,t){if(!n?.primary)return;let r=new Set(n.primary.map(ve));return{kinds:new Set(e.kinds.filter(o=>r.has(ve(o))||r.has(rt(e,o).slice(1)))),places:new Set(t.filter(o=>r.has(o.as)||r.has(ve(o.title))||o.name!==void 0&&n.primary.includes(tt+o.name)).map(o=>`${o.kind}|${o.as}`))}}var qd="overview",Zf=`/places/${qd}`;function Cf(n){let e=n?.scene?.trim();return e||"Scene"}function Gf(n){let e=n?.pages?.trim();return e||"Pages"}function Kf(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 Hd(n){return n.startsWith(tt)&&n.slice(tt.length).trim()||void 0}function Vf(n,e,t){let r=[],o=new Set;for(let i of e??[]){let s=Hd(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 Bf(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=ve(r),i=t.find(d=>d.title===r||tt+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=>rt(e,d).slice(1)===o);return a?{to:"kind",kind:a}:void 0}function Bo(n){let e=(n??"").replace(/\/+$/,"");return e===""?"":e.startsWith("/")?e:`/${e}`}function Uf(n,e={}){let t=typeof n=="string"?n:n.address,r=Bo(e.basePath),o=t.startsWith("/")?t:`/${t}`;return r===""?o:o==="/"?r:o.startsWith("/?")||o.startsWith("/#")?`${r}${o.slice(1)}`:`${r}${o}`}function Wf(n,e){let t=Bo(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 Yd=Symbol.for("@graview/core:app-link"),qf=n=>(Object.defineProperty(T(n),Yd,{value:1,enumerable:!0}),n);function Jd(n){let e=T(n);return!!e&&(e[Yd]===1||Jd(e.innerType))}var vk=()=>qf(L().check(Nr(500),Ln(xt,"another app's address")));var Wt=(n,e)=>`${e.kind}\0${e.id??""}\0${n.address}\0${n.kind}\0${n.id}`;function Hf(n,e,t=()=>{}){let r=new Map,o=new Map,i=s=>{let a=Wt(s,e),d=r.get(a);return d||(d=Promise.resolve().then(()=>n.resolve(s,e)).then(l=>Yf(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=Wt(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(Wt(s,e)),forget(s){if(!s){r.clear(),o.clear();return}let a=Wt(s,e);r.delete(a),o.delete(a)}}}function Yf(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 Jf=1;var qt=(n,e)=>`${n}\0${e}`;function Wo(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 Uo=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 Wo(r)){let s=qt(o,i);(this.revs.get(s)??this.floor)<t.seq&&this.revs.set(s,t.seq)}}of(e,t){return this.revs.get(qt(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=qt(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 Xf(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 Wo(r))e.add(qt(o,i))}return e}var Qf=/^#([0-9a-f]{3,8})$/i,ep=/(rgba?|hsla?)\(([^)]+)\)/gi;function np(n){let e=Qf.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 tp(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,u,p]=r;return d===void 0||l===void 0||u===void 0?null:{r:d,g:l,b:u,a:p??1}}let[o,i,s,a]=r;return o===void 0||i===void 0||s===void 0?null:{...Qd(o,i>1?i/100:i,s>1?s/100:s),a:a??1}}function Ho(n){let e=n.r/255,t=n.g/255,r=n.b/255,o=Math.max(e,t,r),i=Math.min(e,t,r),s=(o+i)/2;if(o===i)return{h:0,s:0,l:s};let a=o-i,d=a/(1-Math.abs(2*s-1));return{h:((o===e?60*((t-r)/a%6):o===t?60*((r-e)/a+2):60*((e-t)/a+4))+360)%360,s:d,l:s}}function Yo(n,e,t){return{...Qd(n,e,t),a:1}}function Qd(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 $n(n){let e=[];for(let t of n.matchAll(ep)){let r=tp(t[0]);r&&e.push(r)}for(let t of n.matchAll(/#[0-9a-fA-F]{3,8}\b/g)){let r=np(t[0]);r&&e.push(r)}return e}function Jo(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 qo(n){let e=n/255;return e<=.03928?e/12.92:((e+.055)/1.055)**2.4}function Xd(n){return .2126*qo(n.r)+.7152*qo(n.g)+.0722*qo(n.b)}function Rn(n,e){let[t,r]=[Xd(n),Xd(e)].sort((o,i)=>i-o);return(t+.05)/(r+.05)}var Ht=(n,e)=>`rgba(${Math.round(n.r)}, ${Math.round(n.g)}, ${Math.round(n.b)}, ${e})`,ec={r:0,g:0,b:0,a:1},Yt={r:255,g:255,b:255,a:1};function Jt(n){let e=$n(n.accent)[0];if(!e)return{ok:!1,missing:["accent"],why:`"${n.accent}" is not a color this can read. Use a hex, rgb() or hsl() value.`};let t={},r=new Set,o=[],i=Ho(e);for(let s of["dark","light"]){let a=n.base[s],d=$n(a.ground)[0]??(s==="dark"?ec:Yt),l=Jo($n(a.panel)[0]??Yt,d),u=sp(i,[l,d],s,4.5);u?Math.abs(u.l-i.l)>ip&&(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(u.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=u??i,c=Yo(p.h,p.s,p.l),f=n.accentInk?.[s]??(Rn(Yt,c)>=Rn(ec,c)?"#ffffff":"#000000"),h=Rn($n(f)[0]??Yt,c);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:Ht(c,1),accentDim:Ht(c,s==="dark"?.35:.22),accentInk:f,glow:Ht(c,s==="dark"?.28:.1),edgeBright:Ht(c,rp(c,l,s==="dark"?.55:.42,3)),...n.warn?.[s]?{warn:n.warn[s]}:{}};let g=$n(t[s].warn)[0];g&&op(Ho(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 rp(n,e,t,r){for(let o=Math.round(t*100);o<=100;o++){let i=o/100;if(Rn(Jo({...n,a:i},e),e)>=r)return i}return 1}function op(n,e){let t=Math.abs(n-e)%360;return t>180?360-t:t}var ip=.3;function sp(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=>Rn(Yo(n.h,n.s,d),l)>=r))return{...n,l:d}}return null}function ap(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 qe=Object.freeze({navy:"#001769",turquoise:"#00e5b9",paper:"#f7f7f2",ink:"#18213a",muted:"#586174"}),Xo="Montserrat",Qo=Object.freeze({display:550,body:450,label:600}),ei=Object.freeze({display:600,body:400,label:600}),dp="-0.025em",cp=Object.freeze({minWidth:140,clearSpace:.5,microMax:24,regularMin:32,microBelow:28});var nc={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:qe.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},tc={ground:qe.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:qe.ink,inkMuted:qe.muted,inkFaint:"#626b7d",accent:qe.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},An={dark:nc,light:tc};var Me=Object.freeze({radius:8,density:1,radiusSmall:.72,radiusSmallFloor:2,pad:15,padSmall:10,gap:7}),He=Object.freeze({body:`"${Xo}", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif`,mono:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace'});function up(n){let e=n?.shape?.radius??Me.radius,t=n?.shape?.density??Me.density;return Object.freeze({radius:e,radiusSmall:Math.max(Me.radiusSmallFloor,Math.round(e*Me.radiusSmall)),pad:Math.round(Me.pad*t),padSmall:Math.round(Me.padSmall*t),gap:Math.round(Me.gap*t)})}function lp(n){let e=n?.typography?.body??He.body,t=n?.typography?.display??e,o=e===He.body&&t===He.body?Qo:ei,i=n?.typography?.weights;return Object.freeze({body:e,display:t,mono:n?.typography?.mono??He.mono,weights:Object.freeze({display:i?.display??o.display,body:i?.body??o.body,label:i?.label??o.label})})}var jk=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 oc(n){return/^\s*(<\?xml[^>]*>\s*)?(<!--[\s\S]*?-->\s*)*(<!DOCTYPE svg[^>]*>\s*)?<svg[\s>/]/i.test(n)}var ic="http://www.w3.org/2000/svg",fp=["http://www.w3.org/1999/xhtml","http://www.w3.org/1998/Math/MathML",ic],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(" ")),hp=new Set(["title","desc"]),it="it embeds a page or media",gp={script:"it has a script in it",foreignobject:"it embeds HTML (foreignObject)",iframe:it,embed:it,object:it,audio:it,video:it,style:"it has a style sheet in it; a mark is styled by its attributes",a:"it links to something (an <a> element)"},mp={amp:"&",lt:"<",gt:">",quot:'"',apos:"'"};function yp(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=mp[o.toLowerCase()];return i===void 0&&(e=!0),i??""});return e?null:t}function bp(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 vp(n,e,t){let r=yp(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===ic?null:"it changes what its elements are (another xmlns)";if(e.startsWith("xmlns:"))return fp.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 bp(r)?null:o==="style"?"its style loads something outside itself":"it loads or links to something outside itself"}var rc=/^\s+([A-Za-z_][A-Za-z0-9_.:-]*)\s*=\s*(?:"([^"<]*)"|'([^'<]*)')/;function sc(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=gp[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 u=e[e.length-1];if(u&&hp.has(u))return`it has an element inside a <${u}>, which the page reads as HTML`;let p=a[0].length;for(let f=rc.exec(o.slice(p));f;f=rc.exec(o.slice(p))){let h=vp(d,f[1],f[2]??f[3]??"");if(h)return h;p+=f[0].length}let c=/^\s*(\/?)>/.exec(o.slice(p));if(!c)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`;c[1]!=="/"?e.push(d):e.length===0&&(t=!0),r+=p+c[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 ac(n){if(n){if(!oc(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 sc(n)===null?`data:image/svg+xml,${encodeURIComponent(n.trim())}`:void 0}}var Xt;function xp(){if(Xt===void 0)try{Xt=new RegExp("^\\p{RGI_Emoji}$","v")}catch{Xt=null}return Xt}function wp(n){return/\p{Extended_Pictographic}|\p{Regional_Indicator}|⃣/u.test(n)}function ni(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(wp).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=xp();return r&&!r.test(n)?"it is not one of the standard emoji every emoji set draws":null}function ti(n){return typeof n=="object"&&n!==null&&typeof n.emoji=="string"?n.emoji:void 0}function dc(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 kp(n){let e=n?.favicon;if(typeof e=="object"&&e!==null){let t=ti(e);return t!==void 0&&ni(t)===null?`data:image/svg+xml,${encodeURIComponent(dc(t))}`:void 0}return ac(e)}function Sp(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 $p(n){if(n?.logo)return;let e=ti(n?.favicon);return e!==void 0&&ni(e)===null?e:void 0}var cc={"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":He.mono},Rp=["serif","sans-serif","monospace","cursive","fantasy","system-ui","math","emoji","-apple-system","BlinkMacSystemFont"],uc=["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 Ap=n=>new Set(n.map(e=>e.toLowerCase()));function _p(n){return Ap([...Rp,...uc]).has(n.toLowerCase())||n.toLowerCase().startsWith("ui-")}function Op(n){return cc[n]??n}function Gk(n){let e=Jt({accent:n,base:An});return e.ok||!e.missing.every(t=>t.startsWith("warn"))?e:Jt({accent:n,base:An,warn:{light:An.light.bad,dark:An.dark.bad}})}function Pp(n,e,t){if(t.rows===0)return;let r=oe(n,e.rows).toLowerCase(),o=oe(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 ${en(H(n.tryDefinition(e.columns),e.columns))} yet: ${s}.`}var fe={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 Ep(n){return n?{connectors:{all:{...fe.connectors.all,...n.connectors?.all??{}},byEdge:{...fe.connectors.byEdge,...n.connectors?.byEdge??{}}},captions:{...fe.captions,...n.captions??{}},grid:{...fe.grid,...n.grid??{}},lattice:{...fe.lattice,...n.lattice??{}},tags:{...fe.tags,...n.tags??{}},emphasis:{...fe.emphasis,...n.emphasis??{}},marks:{...fe.marks,...n.marks??{}}}:fe}function Mp(n,e){return{...n.connectors.all,...n.connectors.byEdge[e]??{}}}function zp(n){return[` --graview-kit-grid: ${n.grid.visible?1:0};`,` --graview-kit-grid-size: ${n.grid.size}px;`,` --graview-kit-lattice: ${n.lattice.visible?1:0};`,` --graview-kit-lattice-size: ${n.lattice.size}px;`,` --graview-kit-tags: ${n.tags.visible?"inline-flex":"none"};`,` --graview-kit-captions: ${n.captions.visible?"block":"none"};`,` --graview-kit-rest: ${n.emphasis.rest};`,` --graview-kit-dim: ${n.emphasis.dim};`,` --graview-kit-flag: "${n.marks.flag.replace(/"/g,"'")}";`].join(`
5
- `)}function Np(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 u of r){if(a.includes(u))for(let p of d)l.add(p);if(s.to==="*"||d.includes(u))for(let p of a)l.add(p)}if(l.size===0)return{ok:!1,at:o};r=l}return{ok:!0,reached:r}}var Qt=2500,Ip=Qt*4;function jp(n){let e=n.name??"";return e&&n.onBehalfOfName?`${e}, for ${n.onBehalfOfName}`:e}function ri(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 Hk=new Set($t);function Tp(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)ri(a,t,r)&&i.set(s,a);for(let s of e){if(!ri(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 Fp(n,e){return!n||!e?n===e:n.participant===e.participant&&n.kind===e.kind&&n.name===e.name&&n.onBehalfOf===e.onBehalfOf&&n.onBehalfOfName===e.onBehalfOfName&&n.until===e.until&&n.held===e.held&&n.hue===e.hue&&n.stop===e.stop&&(n.over??null)===(e.over??null)&&(n.robot?.at??null)===(e.robot?.at??null)&&(n.robot?.mode??null)===(e.robot?.mode??null)}export{rn as a,Ns as b,Is as c,du as d,Nr as e,Fn as f,Ln as g,L as h,Hm as i,Ym as j,Fe as k,Jm as l,Xm as m,Qm as n,Ir as o,ey as p,$e as q,on as r,ny as s,ty as t,ry as u,Ks as v,Vs as w,X as x,oy as y,bt as z,iy as A,sy as B,T as C,_u as D,tr as E,Qe as F,at as G,Lp as H,ee as I,lc as J,fc as K,ii as L,ct as M,pc as N,we as O,rr as P,si as Q,or as R,mc as S,yc as T,he as U,bc as V,vc as W,xc as X,wc as Y,kc as Z,Nn as _,ci as $,ui as aa,$c as ba,sr as ca,C as da,Rc as ea,V as fa,Ac as ga,oe as ha,_c as ia,Oc as ja,lt as ka,en as la,H as ma,Ou as na,vt as oa,Dr as pa,Bs as qa,Us as ra,Ws as sa,Pu as ta,Zn as ua,Hs as va,ab as wa,wt as xa,Jd as ya,vk as za,Iu as Aa,Tu as Ba,Xs as Ca,Du as Da,lb as Ea,Cn as Fa,Fu as Ga,Zu as Ha,fb as Ia,pb as Ja,Cu as Ka,ea as La,Hf as Ma,kt as Na,Gu as Oa,an as Pa,Kn as Qa,St as Ra,mb as Sa,dn as Ta,sn as Ua,aa as Va,Bu as Wa,Cr as Xa,Vn as Ya,Le as Za,kb as _a,Gr as $a,Rt as ab,Wu as bb,un as cb,z as db,Un as eb,M as fb,Q as gb,Ju as hb,Pt as ib,Bb as jb,Xu as kb,Qu as lb,Jf as mb,D as nb,W as ob,_e as pb,Oe as qb,tv as rb,va as sb,pn as tb,I as ub,hn as vb,Ce as wb,re as xb,ol as yb,ue as zb,Kl as Ab,$o as Bb,cd as Cb,xn as Db,vx as Eb,Ao as Fb,pd as Gb,hd as Hb,_o as Ib,Ee as Jb,ko as Kb,Xn as Lb,Jl as Mb,gd as Nb,wv as Ob,_a as Pb,kv as Qb,Sv as Rb,ef as Sb,rf as Tb,Po as Ub,Mo as Vb,zo as Wb,No as Xb,kd as Yb,cf as Zb,Zt as _b,Ke as $b,Uo as ac,Xf as bc,et as cc,wn as dc,Mt as ec,so as fc,co as gc,za as hc,cl as ic,Na as jc,hl as kc,ap as lc,Xo as mc,dp as nc,An as oc,He as pc,up as qc,lp as rc,oc as sc,sc as tc,ac as uc,kp as vc,Sp as wc,$p as xc,_p as yc,Op as zc,Gk as Ac,Nf as Bc,Pp as Cc,Ep as Dc,Mp as Ec,zp as Fc,gl as Gc,ml as Hc,yl as Ic,bl as Jc,Ve as Kc,Jn as Lc,le as Mc,Yn as Nc,Be as Oc,yn as Pc,jt as Qc,bn as Rc,jl as Sc,vl as Tc,xl as Uc,Np as Vc,bf as Wc,vf as Xc,id as Yc,xf as Zc,Cd as _c,kn as $c,Zo as ad,$f as bd,Rf as cd,Af as dd,Gd as ed,Go as fd,_f as gd,ve as hd,rt as id,Of as jd,Pf as kd,Kd as ld,Ef as md,Mf as nd,Vd as od,ot as pd,If as qd,Ud as rd,Wd as sd,Tf as td,Df as ud,Ff as vd,Lf as wd,qd as xd,Zf as yd,Cf as zd,Gf as Ad,Kf as Bd,Vf as Cd,Bf as Dd,Bo as Ed,Uf as Fd,Wf as Gd,Ip as Hd,jp as Id,Tp as Jd,Dp as Kd,Fp as Ld};