@panphora/clayjs 1.18.1 → 1.20.0

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 (180) hide show
  1. package/README.md +1 -1
  2. package/dist/all.js +1 -1
  3. package/dist/clay-dom.js +1 -1
  4. package/dist/clay-events.js +1 -1
  5. package/dist/clay-internals.js +1 -1
  6. package/dist/clay-options.js +1 -1
  7. package/dist/clay-router.js +1 -1
  8. package/dist/clay-ui.js +1 -1
  9. package/dist/clay-utils.js +1 -1
  10. package/dist/clay.js +1 -1
  11. package/dist/clay.standalone.js +8773 -8444
  12. package/dist/m/attrs/{refetch-on-save-ZUE7PSCI.js → refetch-on-save-DPGJJMGN.js} +1 -1
  13. package/dist/m/attrs/save-freeze-MTFVVYV5.js +1 -0
  14. package/dist/m/{c-KP64LT2A.js → c-2VB555FG.js} +1 -1
  15. package/dist/m/{c-KGHVFRR3.js → c-3AXJDL2P.js} +1 -1
  16. package/dist/m/{c-372N6H3B.js → c-3GJ4XARY.js} +1 -1
  17. package/dist/m/c-3TWCKFOP.js +1 -0
  18. package/dist/m/{c-U7SHNWDH.js → c-3YH6JSIL.js} +1 -1
  19. package/dist/m/{c-AMU3BPPR.js → c-44B5ODN7.js} +2 -2
  20. package/dist/m/{c-S2U6NJU4.js → c-62HZW5DH.js} +1 -1
  21. package/dist/m/{c-ZK4GIZH2.js → c-67ILSNPR.js} +1 -1
  22. package/dist/m/c-67LGZ52V.js +20 -0
  23. package/dist/m/{c-W6DQSHXI.js → c-7SXYQCN4.js} +1 -1
  24. package/dist/m/{c-5OOVFCJM.js → c-AL4RBJF2.js} +1 -1
  25. package/dist/m/{c-L42OLXWM.js → c-ANNFZFLN.js} +1 -1
  26. package/dist/m/{c-QO4HNGCQ.js → c-B4VYNXTQ.js} +1 -1
  27. package/dist/m/{c-7PRJCA3E.js → c-BJPZCWAV.js} +1 -1
  28. package/dist/m/{c-SW4YEG2D.js → c-BTLFLLML.js} +1 -1
  29. package/dist/m/c-C4IIQZGJ.js +1 -0
  30. package/dist/m/{c-5T6NZHNM.js → c-CAWNFER6.js} +1 -1
  31. package/dist/m/c-CSNE5EIF.js +1 -0
  32. package/dist/m/{c-DVYGFTSK.js → c-DDDOKPI6.js} +2 -2
  33. package/dist/m/{c-6DB2OLRJ.js → c-DHXPDLW6.js} +1 -1
  34. package/dist/m/{c-WCXLG3MV.js → c-E4IBSAQM.js} +1 -1
  35. package/dist/m/{c-IVTRVENZ.js → c-EDSPKYMA.js} +1 -1
  36. package/dist/m/{c-UORXLSD3.js → c-EFD6QNTE.js} +1 -1
  37. package/dist/m/{c-7MG5RU63.js → c-EGTIAL6P.js} +1 -1
  38. package/dist/m/{c-SPZPGD3R.js → c-EOCKLMKX.js} +1 -1
  39. package/dist/m/{c-HMV6P4RX.js → c-EOCZ2YVL.js} +1 -1
  40. package/dist/m/{c-B5UJQT7W.js → c-EZ7B5AZT.js} +1 -1
  41. package/dist/m/{c-UPD33ZPE.js → c-FDAXZ2PM.js} +1 -1
  42. package/dist/m/{c-RND3G2S2.js → c-FNVQAACK.js} +1 -1
  43. package/dist/m/c-FSWRGBVQ.js +1 -0
  44. package/dist/m/c-FTWGYI5E.js +1 -0
  45. package/dist/m/{c-CCQ25GFY.js → c-GKEATME6.js} +1 -1
  46. package/dist/m/{c-YBKHUAK7.js → c-GPGYKER7.js} +1 -1
  47. package/dist/m/{c-FWKHM4E7.js → c-GSRLXYWL.js} +1 -1
  48. package/dist/m/{c-B7J4K2AE.js → c-GVPNDIKJ.js} +2 -2
  49. package/dist/m/{c-AMYEFA2E.js → c-I2IFKJX2.js} +1 -1
  50. package/dist/m/c-ICMAOOGK.js +1 -0
  51. package/dist/m/{c-BUAYFEV5.js → c-J3BXFTZS.js} +1 -1
  52. package/dist/m/{c-BIJALSRD.js → c-JDZDF2QM.js} +1 -1
  53. package/dist/m/{c-UDHIVLYH.js → c-JH5FF4NL.js} +1 -1
  54. package/dist/m/{c-OYRZ7XG2.js → c-JHJR5BQX.js} +1 -1
  55. package/dist/m/{c-V44KWI2L.js → c-JOH753EJ.js} +2 -2
  56. package/dist/m/{c-P3OFYUMA.js → c-JUE7B4OX.js} +1 -1
  57. package/dist/m/c-K76AUL4I.js +7 -0
  58. package/dist/m/{c-ZWIOJGMT.js → c-LA2BW7UY.js} +1 -1
  59. package/dist/m/{c-ICJYHABF.js → c-LDUNOR57.js} +1 -1
  60. package/dist/m/{c-C6IPRG34.js → c-LIBE4HPD.js} +1 -1
  61. package/dist/m/c-LPUJXRXW.js +1 -0
  62. package/dist/m/{c-TTB5EK4S.js → c-LQU7TXIH.js} +1 -1
  63. package/dist/m/{c-5ZQV7KC4.js → c-LV5MABYD.js} +1 -1
  64. package/dist/m/{c-URSMSFCB.js → c-M4FSPNQ2.js} +1 -1
  65. package/dist/m/{c-2KIEGNC4.js → c-MEWUGR4D.js} +1 -1
  66. package/dist/m/c-MIL4B2JQ.js +1 -0
  67. package/dist/m/{c-IVMD3FEM.js → c-N7Y52HJH.js} +1 -1
  68. package/dist/m/{c-PLN76GF3.js → c-NFR673TL.js} +2 -2
  69. package/dist/m/{c-T637T7SN.js → c-NLZ5AN4L.js} +1 -1
  70. package/dist/m/{c-OPLUZR3A.js → c-OABVRYOT.js} +1 -1
  71. package/dist/m/c-PIVIYLTY.js +1 -0
  72. package/dist/m/{c-L7JL5TL3.js → c-QY7F6EN6.js} +1 -1
  73. package/dist/m/{c-UY4QX42B.js → c-RG6XUZFA.js} +1 -1
  74. package/dist/m/c-RHMPKZZ7.js +1 -0
  75. package/dist/m/{c-TJAXGIRV.js → c-RQRMPZXD.js} +1 -1
  76. package/dist/m/{c-GY422N3Q.js → c-RS77ODLY.js} +1 -1
  77. package/dist/m/{c-IMZCWYHR.js → c-RT3C74GY.js} +1 -1
  78. package/dist/m/{c-CAS3NND4.js → c-S5IEIZCN.js} +1 -1
  79. package/dist/m/{c-K3ADYNLU.js → c-SBSMJIPC.js} +1 -1
  80. package/dist/m/c-SFKI6OLM.js +2 -0
  81. package/dist/m/{c-4TXNLX4K.js → c-SJPD46ZO.js} +4 -4
  82. package/dist/m/{c-HHGJBU4D.js → c-SO63UGPQ.js} +1 -1
  83. package/dist/m/{c-PLP4JKFC.js → c-TUGVINJR.js} +1 -1
  84. package/dist/m/{c-Q26MME6N.js → c-TWCXBWS3.js} +1 -1
  85. package/dist/m/{c-GNDL3TKB.js → c-U5X57T4L.js} +1 -1
  86. package/dist/m/{c-4YU3BR4D.js → c-UXEVJ63W.js} +1 -1
  87. package/dist/m/{c-KJJPV77R.js → c-V2J5C5MT.js} +1 -1
  88. package/dist/m/{c-6UGWFMQC.js → c-VBLFAQD2.js} +1 -1
  89. package/dist/m/{c-ERQSNR6K.js → c-VQCEOGKH.js} +2 -2
  90. package/dist/m/{c-YVZ2L7CE.js → c-VSPAFOKU.js} +1 -1
  91. package/dist/m/{c-5ONTYIUI.js → c-VY6XRBOW.js} +1 -1
  92. package/dist/m/{c-2KL3BD52.js → c-W23KVGUO.js} +1 -1
  93. package/dist/m/{c-COPTL5WB.js → c-W3K23S72.js} +1 -1
  94. package/dist/m/c-WFMRX5RZ.js +1 -0
  95. package/dist/m/{c-BWFVSBDF.js → c-WN3MXOLT.js} +1 -1
  96. package/dist/m/{c-X5TSXZYJ.js → c-XD5MOROJ.js} +1 -1
  97. package/dist/m/{c-MWXFLW4J.js → c-XQSXKIKM.js} +1 -1
  98. package/dist/m/{c-OTMKN2OO.js → c-Y33LUUIQ.js} +1 -1
  99. package/dist/m/{c-JNLX3RJB.js → c-YQUJ74R3.js} +1 -1
  100. package/dist/m/{c-2GRUM77Q.js → c-YSB6JKV2.js} +2 -2
  101. package/dist/m/{c-WQWIRWO3.js → c-Z32V4MHK.js} +1 -1
  102. package/dist/m/{c-BHZYSHW4.js → c-ZJLU56DV.js} +1 -1
  103. package/dist/m/{c-DKLS74XB.js → c-ZQXNHZZT.js} +2 -2
  104. package/dist/m/{c-TNEM3RNM.js → c-ZSCBEB7I.js} +1 -1
  105. package/dist/m/core/{admin-attrs-YY7T5FGU.js → admin-attrs-ZG7R5V3E.js} +1 -1
  106. package/dist/m/core/{autosave-S6OMNDCK.js → autosave-VPORYJSE.js} +1 -1
  107. package/dist/m/core/{conflict-notice-IWHMHH43.js → conflict-notice-JMAZLVRX.js} +1 -1
  108. package/dist/m/core/{persist-UKXV5KLA.js → persist-3OPWJKZS.js} +1 -1
  109. package/dist/m/core/{save-LYY7K6U7.js → save-AOJBDSOK.js} +1 -1
  110. package/dist/m/core/{save-core-MKRPSEEO.js → save-core-IOCMXO5L.js} +1 -1
  111. package/dist/m/core/{snapshot-NU3YM6GR.js → snapshot-O7II2AGG.js} +1 -1
  112. package/dist/m/core/unsaved-warning-U5VUJFOE.js +1 -0
  113. package/dist/m/events/{index-RN2JNGBV.js → index-B6TGDYMG.js} +1 -1
  114. package/dist/m/internals/{index-TGLQINN3.js → index-HDRANDWE.js} +1 -1
  115. package/dist/m/lib/{cache-bust-MUMFXZK6.js → cache-bust-NH7VBWHO.js} +1 -1
  116. package/dist/m/lib/{region-policy-SB2AWVG5.js → region-policy-KWBPROWF.js} +1 -1
  117. package/dist/m/loader-DZZLUBVB.js +1 -0
  118. package/dist/m/manifest-3AEF5191.js +1 -0
  119. package/dist/m/manifest-edit-29A26F22.js +1 -0
  120. package/dist/m/manifest.json +1336 -1281
  121. package/dist/m/options/{options-EJMS3K24.js → options-55LQHSJ4.js} +1 -1
  122. package/dist/m/page/{editor-6LRB3GE4.js → editor-EY2WAAGB.js} +2 -2
  123. package/dist/m/plugins/{ai-edit-UTV7YO2I.js → ai-edit-J5VLSW5I.js} +1 -1
  124. package/dist/m/plugins/{demo-OYO5GCAO.js → demo-42BSYQ7T.js} +1 -1
  125. package/dist/m/plugins/like-EV7MTZ56.js +1 -0
  126. package/dist/m/plugins/{live-AD4H6XSL.js → live-5EZN2EYP.js} +1 -1
  127. package/dist/m/plugins/menu-KGWKT6CS.js +1 -0
  128. package/dist/m/plugins/{page-MD3T2ZX3.js → page-LVW5DWA4.js} +2 -2
  129. package/dist/m/plugins/{page-view-PAWVZNFY.js → page-view-5KQ76IJB.js} +1 -1
  130. package/dist/m/plugins/{sortable-4S6SQC3D.js → sortable-WJZZBM7R.js} +1 -1
  131. package/dist/m/plugins/{source-TJXOIOYY.js → source-CCEUM3OR.js} +1 -1
  132. package/dist/m/plugins/{undo-NLPGCJQY.js → undo-3JEYK5QY.js} +1 -1
  133. package/dist/m/plugins/{upgrade-HSUNDNJD.js → upgrade-NW556WJD.js} +1 -1
  134. package/dist/m/plugins/{upload-NHGJXZK2.js → upload-TTCQRIM5.js} +1 -1
  135. package/dist/m/plugins/{visitor-drafts-BW43DGY3.js → visitor-drafts-2AWNT23K.js} +2 -2
  136. package/dist/m/plugins/{visitor-drafts-owner-7ODQG7JX.js → visitor-drafts-owner-MZP45XSG.js} +1 -1
  137. package/dist/m/plugins/{wire-VBWXEXU2.js → wire-VRYPY6EJ.js} +1 -1
  138. package/dist/m/{reader-core-4W2KYEWQ.js → reader-core-2GXY7SHY.js} +2 -2
  139. package/dist/m/sync/{live-sync-MO5DH33W.js → live-sync-SKPMFYOO.js} +1 -1
  140. package/dist/m/ui/{index-IVWN2QC4.js → index-QNIPDHXQ.js} +1 -1
  141. package/dist/offline-manifest.json +652 -616
  142. package/docs/guide.md +25 -8
  143. package/package.json +4 -2
  144. package/src/core/conflict-download.js +8 -7
  145. package/src/core/conflict-notice-ui.js +4 -4
  146. package/src/core/copy-content.js +103 -0
  147. package/src/core/download.js +14 -2
  148. package/src/core/save-size-notice.js +2 -2
  149. package/src/core/upgrade-run.js +5 -1
  150. package/src/lib/region-policy.js +1 -1
  151. package/src/loader-logic.js +5 -1
  152. package/src/loader.js +2 -0
  153. package/src/page/features/export-html.js +4 -4
  154. package/src/page/features/export-markdown.js +2 -2
  155. package/src/page/recovery-ui.js +2 -2
  156. package/src/page/save-states.js +4 -4
  157. package/src/plugins/like.js +254 -0
  158. package/src/plugins/menu/actions.js +1 -1
  159. package/src/plugins/page.js +4 -4
  160. package/src/plugins/visitor-drafts/prompt.js +12 -12
  161. package/src/plugins/wire.js +3 -1
  162. package/dist/m/attrs/save-freeze-LWGF6XUN.js +0 -1
  163. package/dist/m/c-D5IKEKXW.js +0 -7
  164. package/dist/m/c-DCFSEJZG.js +0 -1
  165. package/dist/m/c-EVYAISP3.js +0 -1
  166. package/dist/m/c-GRXHHFPO.js +0 -1
  167. package/dist/m/c-HT2DKBV2.js +0 -1
  168. package/dist/m/c-MCOOHCSG.js +0 -1
  169. package/dist/m/c-VILENZTD.js +0 -1
  170. package/dist/m/c-VR2BJ4AN.js +0 -1
  171. package/dist/m/c-WGW764WX.js +0 -1
  172. package/dist/m/c-WNTYKCDG.js +0 -1
  173. package/dist/m/c-YBSS55KU.js +0 -20
  174. package/dist/m/core/unsaved-warning-7QTKEN7Z.js +0 -1
  175. package/dist/m/loader-3BBNZZGM.js +0 -1
  176. package/dist/m/manifest-26C55578.js +0 -1
  177. package/dist/m/manifest-edit-4396A009.js +0 -1
  178. package/dist/m/plugins/menu-M5WW7DBF.js +0 -1
  179. /package/dist/m/{c-QTTJYJMA.js → c-FILLTJA7.js} +0 -0
  180. /package/dist/m/plugins/{people-JCHVPF7P.js → people-C7TVBBMR.js} +0 -0
@@ -1 +1 @@
1
- import{d as b,e as m}from"./c-UPD33ZPE.js";import"./c-L3F5ZLIV.js";import"./c-IW6GGOU2.js";import"./c-HAWFNBYG.js";import{e as h,f as d,g as l,h as w}from"./c-EXKHPOVC.js";import"./c-L5VFATT6.js";import"./c-7K4SCQB7.js";import"./c-WMRJKQ2V.js";import"./c-QIXT3Q7C.js";import"./c-TCCA5BZN.js";import"./c-57XDY6HC.js";import"./c-OYRZ7XG2.js";import"./c-Q26MME6N.js";import"./c-ZWIOJGMT.js";import"./c-IJUK2GPW.js";import{c as T}from"./c-BPF2NSPV.js";import{e as v}from"./c-7MG5RU63.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-VG5XIN4T.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-DCFSEJZG.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";v(b);var x=1,y=class extends Error{constructor(a,n){super(n),this.name="PageCheckpointError",this.code=a}},k=(e,a)=>{throw new y(e,a)},t=(e,a)=>({ok:!1,code:e,message:a}),A=/^[0-9a-f]{64}$/,j=/^[0-9a-f]{32}$/,E=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function I(e){return{v:e.v,g:e.g,y:{...e.y??{}}}}function H(e){let a;try{a=JSON.parse(e)}catch{k("invalid-state","The page state is not JSON")}return(!E(a)||a.v!==1)&&k("invalid-state","Expected a version 1 Yjs page value"),{state:I(a),bytes:d(a)}}var S=e=>e==null?"":String(e);async function N({href:e,etag:a,fetch:n=globalThis.fetch,signal:s=null}={}){if(typeof a!="string"||!a)return t("missing-etag","A conditional read needs the accepted ETag");if(typeof e!="string"||!e)return t("no-page-state","This host names no page-state resource");if(typeof n!="function")return t("unavailable","This tab cannot read the page state");let i=globalThis.location?.href??"http://localhost/",p;try{p=new URL(e,i).href}catch{return t("no-page-state","The page-state resource is not a URL")}let c=T(),o;try{o=await n(p,{method:"GET",credentials:c?"omit":"same-origin",headers:{"If-Match":a,"Document-URL":globalThis.location?.href??i},cache:"no-store",redirect:"manual",signal:s})}catch{return t("unavailable","The page-state request did not complete")}if(!o||typeof o.status!="number")return t("unavailable","The page-state request did not answer");if(o.status===412)return t("etag-mismatch","Another version of this document is stored");if(o.status===428)return t("etag-required","The host needs a condition this read cannot send");if(o.status===404)return t("no-page-state","This host keeps no page state");if(!o.ok)return t("unavailable",`The host answered ${o.status}`);let r;try{r=JSON.parse(await o.text())}catch{return t("invalid-state","The page-state answer is not JSON")}return!E(r)||r.version!==x?t("unsupported-version","Unknown page-state version"):typeof r.tag!="string"||!r.tag?t("invalid-state","The page-state answer carries no page tag"):typeof r.stateHash!="string"||!A.test(r.stateHash)?t("invalid-state","The page-state answer carries no state digest"):typeof r.generation!="string"||!j.test(r.generation)?t("invalid-state","The page-state answer carries no generation"):typeof r.etag!="string"||!r.etag?t("invalid-state","The page-state answer carries no ETag"):Object.hasOwn(r,"documentId")?{ok:!0,version:r.version,documentId:r.documentId,generation:r.generation,etag:r.etag,stateHash:r.stateHash,tag:r.tag}:t("invalid-state","The page-state answer carries no document identity")}async function _(e,{accepted:a,article:n,etag:s}={}){if(!e||e.ok!==!0)return t(e?.code??"unavailable",e?.message??"The page state was not read");let i=a?.authority;if(!(i?.scope==="path"&&e.documentId==null)&&S(e.documentId)!==S(i?.documentId))return t("foreign-document","The page state belongs to another document");if(typeof a?.lineage?.generation!="string"||e.generation!==a.lineage.generation)return t("foreign-generation","The page state belongs to another generation");if(e.etag!==s)return t("etag-mismatch","The page state belongs to another version of this document");let c,o;try{({state:o,bytes:c}=H(e.tag))}catch(u){return t(u?.code??"invalid-state",u?.message??"The page state does not decode")}if(await h(c)!==e.stateHash)return t("state-digest-mismatch","The page state is not the one the host hashed");if(typeof n!="string")return t("missing-article","A proof names the final outgoing article");let r;try{r=m(o)}catch(u){return t("invalid-state",u?.message??"The page state does not project")}return r!==n?t("article-mismatch","The page state does not project to the accepted article"):{ok:!0,state:o,receipt:{file:e.etag,pageState:e.stateHash}}}async function O(e,a){let n=(a||[]).map(({id:s,revision:i})=>({id:s,revision:i}));try{return{ok:!0,proof:e,covered:await w(e,n)}}catch(s){return t(s?.code??"invalid-proof",s?.message??"The proof does not validate")}}async function R({capture:e,records:a=[],accepted:n,article:s,state:i=null,etag:p=null}={}){if(!i)return t("no-capture-state","No page state was pinned to this capture");if(typeof p!="string"||!p)return t("missing-etag","An accepted save with no ETag proves no stored pair");if(typeof s!="string")return t("missing-article","The accepted bytes hold no article");let c,o;try{c=m(i),o=d(i)}catch(u){return t(u?.code??"invalid-state",u?.message??"The pinned page state does not decode")}if(c!==s)return t("article-mismatch","The pinned page state does not project to the accepted article");let r;try{r=await l({capture:e,records:a,accepted:n,article:s,state:i,receipt:{file:p,pageState:await h(o)}})}catch(u){return t(u?.code??"invalid-proof",u?.message??"The proof could not be built")}return O(r,a)}async function B({read:e,capture:a,records:n=[],accepted:s,article:i,etag:p=null}={}){let c=await _(e,{accepted:s,article:i,etag:p});if(!c.ok)return c;let o;try{o=await l({capture:a,records:n,accepted:s,article:i,state:c.state,receipt:c.receipt})}catch(r){return t(r?.code??"invalid-proof",r?.message??"The proof could not be built")}return O(o,n)}async function G({channel:e,records:a=[],capture:n,accepted:s,article:i,state:p=null,etag:c=null,href:o=null,read:r=N,fetch:u}={}){if(!e||typeof e.checkpoint!="function")return{ok:!1,code:"no-channel",retired:[],proof:null};let f=await R({capture:n,records:a,accepted:s,article:i,state:p,etag:c});if(!f.ok){let P=await r({href:o,etag:c,fetch:u});f=await B({read:P,capture:n,records:a,accepted:s,article:i,etag:c})}if(!f.ok)return{ok:!1,code:f.code,retired:[],proof:null};let g=await e.checkpoint({records:f.covered,proof:f.proof});return!g||g.ok!==!0?{ok:!1,code:g?.code??"checkpoint-failed",retired:[],proof:f.proof}:{ok:!0,retired:g.retired??[],proof:f.proof}}export{x as PAGE_STATE_VERSION,y as PageCheckpointError,R as captureProof,G as checkpointAccepted,N as readPageState,B as refetchedProof,_ as verifyPageState};
1
+ import{d as b,e as m}from"./c-FDAXZ2PM.js";import"./c-L3F5ZLIV.js";import"./c-IW6GGOU2.js";import"./c-HAWFNBYG.js";import{e as h,f as d,g as l,h as w}from"./c-EXKHPOVC.js";import"./c-L5VFATT6.js";import"./c-7K4SCQB7.js";import"./c-WMRJKQ2V.js";import"./c-QIXT3Q7C.js";import"./c-TCCA5BZN.js";import"./c-57XDY6HC.js";import"./c-JHJR5BQX.js";import"./c-TWCXBWS3.js";import"./c-LA2BW7UY.js";import"./c-IJUK2GPW.js";import{c as T}from"./c-BPF2NSPV.js";import{e as v}from"./c-EGTIAL6P.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-VG5XIN4T.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";v(b);var x=1,y=class extends Error{constructor(a,n){super(n),this.name="PageCheckpointError",this.code=a}},k=(e,a)=>{throw new y(e,a)},t=(e,a)=>({ok:!1,code:e,message:a}),A=/^[0-9a-f]{64}$/,j=/^[0-9a-f]{32}$/,E=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function I(e){return{v:e.v,g:e.g,y:{...e.y??{}}}}function H(e){let a;try{a=JSON.parse(e)}catch{k("invalid-state","The page state is not JSON")}return(!E(a)||a.v!==1)&&k("invalid-state","Expected a version 1 Yjs page value"),{state:I(a),bytes:d(a)}}var S=e=>e==null?"":String(e);async function N({href:e,etag:a,fetch:n=globalThis.fetch,signal:s=null}={}){if(typeof a!="string"||!a)return t("missing-etag","A conditional read needs the accepted ETag");if(typeof e!="string"||!e)return t("no-page-state","This host names no page-state resource");if(typeof n!="function")return t("unavailable","This tab cannot read the page state");let i=globalThis.location?.href??"http://localhost/",p;try{p=new URL(e,i).href}catch{return t("no-page-state","The page-state resource is not a URL")}let c=T(),o;try{o=await n(p,{method:"GET",credentials:c?"omit":"same-origin",headers:{"If-Match":a,"Document-URL":globalThis.location?.href??i},cache:"no-store",redirect:"manual",signal:s})}catch{return t("unavailable","The page-state request did not complete")}if(!o||typeof o.status!="number")return t("unavailable","The page-state request did not answer");if(o.status===412)return t("etag-mismatch","Another version of this document is stored");if(o.status===428)return t("etag-required","The host needs a condition this read cannot send");if(o.status===404)return t("no-page-state","This host keeps no page state");if(!o.ok)return t("unavailable",`The host answered ${o.status}`);let r;try{r=JSON.parse(await o.text())}catch{return t("invalid-state","The page-state answer is not JSON")}return!E(r)||r.version!==x?t("unsupported-version","Unknown page-state version"):typeof r.tag!="string"||!r.tag?t("invalid-state","The page-state answer carries no page tag"):typeof r.stateHash!="string"||!A.test(r.stateHash)?t("invalid-state","The page-state answer carries no state digest"):typeof r.generation!="string"||!j.test(r.generation)?t("invalid-state","The page-state answer carries no generation"):typeof r.etag!="string"||!r.etag?t("invalid-state","The page-state answer carries no ETag"):Object.hasOwn(r,"documentId")?{ok:!0,version:r.version,documentId:r.documentId,generation:r.generation,etag:r.etag,stateHash:r.stateHash,tag:r.tag}:t("invalid-state","The page-state answer carries no document identity")}async function _(e,{accepted:a,article:n,etag:s}={}){if(!e||e.ok!==!0)return t(e?.code??"unavailable",e?.message??"The page state was not read");let i=a?.authority;if(!(i?.scope==="path"&&e.documentId==null)&&S(e.documentId)!==S(i?.documentId))return t("foreign-document","The page state belongs to another document");if(typeof a?.lineage?.generation!="string"||e.generation!==a.lineage.generation)return t("foreign-generation","The page state belongs to another generation");if(e.etag!==s)return t("etag-mismatch","The page state belongs to another version of this document");let c,o;try{({state:o,bytes:c}=H(e.tag))}catch(u){return t(u?.code??"invalid-state",u?.message??"The page state does not decode")}if(await h(c)!==e.stateHash)return t("state-digest-mismatch","The page state is not the one the host hashed");if(typeof n!="string")return t("missing-article","A proof names the final outgoing article");let r;try{r=m(o)}catch(u){return t("invalid-state",u?.message??"The page state does not project")}return r!==n?t("article-mismatch","The page state does not project to the accepted article"):{ok:!0,state:o,receipt:{file:e.etag,pageState:e.stateHash}}}async function O(e,a){let n=(a||[]).map(({id:s,revision:i})=>({id:s,revision:i}));try{return{ok:!0,proof:e,covered:await w(e,n)}}catch(s){return t(s?.code??"invalid-proof",s?.message??"The proof does not validate")}}async function R({capture:e,records:a=[],accepted:n,article:s,state:i=null,etag:p=null}={}){if(!i)return t("no-capture-state","No page state was pinned to this capture");if(typeof p!="string"||!p)return t("missing-etag","An accepted save with no ETag proves no stored pair");if(typeof s!="string")return t("missing-article","The accepted bytes hold no article");let c,o;try{c=m(i),o=d(i)}catch(u){return t(u?.code??"invalid-state",u?.message??"The pinned page state does not decode")}if(c!==s)return t("article-mismatch","The pinned page state does not project to the accepted article");let r;try{r=await l({capture:e,records:a,accepted:n,article:s,state:i,receipt:{file:p,pageState:await h(o)}})}catch(u){return t(u?.code??"invalid-proof",u?.message??"The proof could not be built")}return O(r,a)}async function B({read:e,capture:a,records:n=[],accepted:s,article:i,etag:p=null}={}){let c=await _(e,{accepted:s,article:i,etag:p});if(!c.ok)return c;let o;try{o=await l({capture:a,records:n,accepted:s,article:i,state:c.state,receipt:c.receipt})}catch(r){return t(r?.code??"invalid-proof",r?.message??"The proof could not be built")}return O(o,n)}async function G({channel:e,records:a=[],capture:n,accepted:s,article:i,state:p=null,etag:c=null,href:o=null,read:r=N,fetch:u}={}){if(!e||typeof e.checkpoint!="function")return{ok:!1,code:"no-channel",retired:[],proof:null};let f=await R({capture:n,records:a,accepted:s,article:i,state:p,etag:c});if(!f.ok){let P=await r({href:o,etag:c,fetch:u});f=await B({read:P,capture:n,records:a,accepted:s,article:i,etag:c})}if(!f.ok)return{ok:!1,code:f.code,retired:[],proof:null};let g=await e.checkpoint({records:f.covered,proof:f.proof});return!g||g.ok!==!0?{ok:!1,code:g?.code??"checkpoint-failed",retired:[],proof:f.proof}:{ok:!0,retired:g.retired??[],proof:f.proof}}export{x as PAGE_STATE_VERSION,y as PageCheckpointError,R as captureProof,G as checkpointAccepted,N as readPageState,B as refetchedProof,_ as verifyPageState};
@@ -1,4 +1,4 @@
1
- import{e as X,f as G,h as J,i as Q,j as P,k as U}from"./c-QIKT6SKM.js";import{a as C,f as L}from"./c-TJAXGIRV.js";import"./c-BWFVSBDF.js";import"./c-L5VFATT6.js";import{a as O,b as N,k as z,l as K,m as j,n as V,v as T}from"./c-WMRJKQ2V.js";import{o as w}from"./c-AMU3BPPR.js";import{b as k,d as H}from"./c-QIXT3Q7C.js";import{b as W}from"./c-GY422N3Q.js";import"./c-7SWMYKAI.js";import"./c-UGHH4MB3.js";import"./c-ZWIOJGMT.js";import{d as q}from"./c-XGH4GS2T.js";import"./c-IJUK2GPW.js";import"./c-3O7OBDCM.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-VG5XIN4T.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-DCFSEJZG.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var ie=128,D=r=>r.depth?r.node(1).attrs.id:null,Z=r=>!!r.depth&&r.node(1).type.name==="table",ce=(r,t,n,e,o)=>O(K(z(r.flow,J(t,n.holes,e,n.visible),o)));function te({pd:r,w:t,doc:n},e){if(!r||!t||!n||!e)return null;if(e instanceof k.TextSelection){let o=e.$anchor,s=e.$head;if(Z(o)||Z(s)){let c=P(n,o.pos),u=P(n,s.pos);return!c||!u||c.table!==u.table||c.row!==u.row||c.col!==u.col?null:{kind:"cell",block:c.table,row:c.row,col:c.col}}let a=Math.min(e.from,e.to),l=c=>{let u=D(c);return u===null?null:{block:u,rel:ce(r,n,t,c.pos,e.empty||c.pos===a?0:-1)}},i=l(o),d=l(s);return i&&d?{kind:"text",anchor:i,head:d}:null}if(e instanceof w||e instanceof k.NodeSelection){let o=[];if(e instanceof w){let{lo:s,hi:a}=e.span();n.forEach((l,i,d)=>{d>=s&&d<=a&&o.push(l.attrs.id)})}else{let s=n.nodeAt(e.from);s&&o.push(s.attrs.id)}if(!o.length)return null;if(o.length>ie){let s=D(e.$from);return s?{kind:"blocks",ids:[s]}:null}return{kind:"blocks",ids:o}}return null}var ue=(r,t)=>{if(!t||typeof t!="object"||typeof t.block!="string"||!t.block||typeof t.rel!="string"||!t.rel)return null;let n;try{n=j(N(t.rel))}catch{return null}let e;try{e=V(n,r.ydoc)}catch{return null}return!e||e.type!==r.flow?null:e.index},fe=(r,t)=>{let n=0;for(let e=r.flow._start;e;e=e.right){let o=n+e.length;if(t<o)return!e.deleted;n=o}return!1},pe=(r,t)=>{for(let n=r.flow._start;n;n=n.right)if(!n.deleted&&n.content instanceof T&&n.content.embed?.b===t)return!0;return!1},de=(r,t)=>{let n=0,e=null,o=0;for(let s=r.flow._start;s;s=s.right)if(s.content instanceof T&&s.content.embed?.b!==void 0&&(e=s.content.embed.b,o=n+s.length),n+=s.length,n>t&&e!==null)return{id:e,offset:t-o};return e===null?null:{id:e,offset:t-o}},me=(r,t,n)=>{let e=null;return r.forEach((o,s)=>{e===null&&o.attrs.id===t&&o.isTextblock&&(e=s+1+Math.min(Math.max(n,0),o.content.size))}),e},ee=({pd:r,w:t,doc:n},e)=>{let o=ue(r,e);if(o===null)return null;let s=Q(n,t.holes,t.tokens,o,t.visible);if(D(n.resolve(s))===e.block)return s;let a=de(r,o);if(a&&a.id===e.block){let l=me(n,e.block,a.offset);if(l!==null)return l}return pe(r,e.block)||!fe(r,o)||t.holes.some(l=>o>=G(t.holes,l.at)&&o<X(t.holes,l.at))?null:n.resolve(s).parent.inlineContent?s:null};function ne({pd:r,w:t,doc:n},e){if(!r||!t||!n||!e||typeof e!="object")return null;if(e.kind==="text"){let o=ee({pd:r,w:t,doc:n},e.anchor),s=ee({pd:r,w:t,doc:n},e.head);return o===null||s===null?null:{kind:"text",from:Math.min(o,s),to:Math.max(o,s)}}if(e.kind==="cell"){let o=U(n,{table:e.block,row:e.row,col:e.col,offset:0});return o?{kind:"cell",from:o.from,to:o.to,block:o.block,row:o.row,col:o.col}:null}if(e.kind==="blocks"){let o=[],s=[];for(let a of Array.isArray(e.ids)?e.ids:[])n.forEach((l,i)=>{l.attrs.id!==a||o.includes(a)||(o.push(a),s.push({from:i,to:i+l.nodeSize}))});return s.length?{kind:"blocks",ids:o,ranges:s}:null}return null}var{Plugin:ge,PluginKey:he}=k,{Decoration:b,DecorationSet:x}=H,y=new he("page-awareness"),oe="page-awareness-style",be=`
1
+ import{e as X,f as G,h as J,i as Q,j as P,k as U}from"./c-QIKT6SKM.js";import{a as C,f as L}from"./c-RQRMPZXD.js";import"./c-WN3MXOLT.js";import"./c-L5VFATT6.js";import{a as O,b as N,k as z,l as K,m as j,n as V,v as T}from"./c-WMRJKQ2V.js";import{o as w}from"./c-44B5ODN7.js";import{b as k,d as H}from"./c-QIXT3Q7C.js";import{b as W}from"./c-RS77ODLY.js";import"./c-7SWMYKAI.js";import"./c-UGHH4MB3.js";import"./c-LA2BW7UY.js";import{d as q}from"./c-XGH4GS2T.js";import"./c-IJUK2GPW.js";import"./c-3O7OBDCM.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-VG5XIN4T.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var ie=128,D=r=>r.depth?r.node(1).attrs.id:null,Z=r=>!!r.depth&&r.node(1).type.name==="table",ce=(r,t,n,e,o)=>O(K(z(r.flow,J(t,n.holes,e,n.visible),o)));function te({pd:r,w:t,doc:n},e){if(!r||!t||!n||!e)return null;if(e instanceof k.TextSelection){let o=e.$anchor,s=e.$head;if(Z(o)||Z(s)){let c=P(n,o.pos),u=P(n,s.pos);return!c||!u||c.table!==u.table||c.row!==u.row||c.col!==u.col?null:{kind:"cell",block:c.table,row:c.row,col:c.col}}let a=Math.min(e.from,e.to),l=c=>{let u=D(c);return u===null?null:{block:u,rel:ce(r,n,t,c.pos,e.empty||c.pos===a?0:-1)}},i=l(o),d=l(s);return i&&d?{kind:"text",anchor:i,head:d}:null}if(e instanceof w||e instanceof k.NodeSelection){let o=[];if(e instanceof w){let{lo:s,hi:a}=e.span();n.forEach((l,i,d)=>{d>=s&&d<=a&&o.push(l.attrs.id)})}else{let s=n.nodeAt(e.from);s&&o.push(s.attrs.id)}if(!o.length)return null;if(o.length>ie){let s=D(e.$from);return s?{kind:"blocks",ids:[s]}:null}return{kind:"blocks",ids:o}}return null}var ue=(r,t)=>{if(!t||typeof t!="object"||typeof t.block!="string"||!t.block||typeof t.rel!="string"||!t.rel)return null;let n;try{n=j(N(t.rel))}catch{return null}let e;try{e=V(n,r.ydoc)}catch{return null}return!e||e.type!==r.flow?null:e.index},fe=(r,t)=>{let n=0;for(let e=r.flow._start;e;e=e.right){let o=n+e.length;if(t<o)return!e.deleted;n=o}return!1},pe=(r,t)=>{for(let n=r.flow._start;n;n=n.right)if(!n.deleted&&n.content instanceof T&&n.content.embed?.b===t)return!0;return!1},de=(r,t)=>{let n=0,e=null,o=0;for(let s=r.flow._start;s;s=s.right)if(s.content instanceof T&&s.content.embed?.b!==void 0&&(e=s.content.embed.b,o=n+s.length),n+=s.length,n>t&&e!==null)return{id:e,offset:t-o};return e===null?null:{id:e,offset:t-o}},me=(r,t,n)=>{let e=null;return r.forEach((o,s)=>{e===null&&o.attrs.id===t&&o.isTextblock&&(e=s+1+Math.min(Math.max(n,0),o.content.size))}),e},ee=({pd:r,w:t,doc:n},e)=>{let o=ue(r,e);if(o===null)return null;let s=Q(n,t.holes,t.tokens,o,t.visible);if(D(n.resolve(s))===e.block)return s;let a=de(r,o);if(a&&a.id===e.block){let l=me(n,e.block,a.offset);if(l!==null)return l}return pe(r,e.block)||!fe(r,o)||t.holes.some(l=>o>=G(t.holes,l.at)&&o<X(t.holes,l.at))?null:n.resolve(s).parent.inlineContent?s:null};function ne({pd:r,w:t,doc:n},e){if(!r||!t||!n||!e||typeof e!="object")return null;if(e.kind==="text"){let o=ee({pd:r,w:t,doc:n},e.anchor),s=ee({pd:r,w:t,doc:n},e.head);return o===null||s===null?null:{kind:"text",from:Math.min(o,s),to:Math.max(o,s)}}if(e.kind==="cell"){let o=U(n,{table:e.block,row:e.row,col:e.col,offset:0});return o?{kind:"cell",from:o.from,to:o.to,block:o.block,row:o.row,col:o.col}:null}if(e.kind==="blocks"){let o=[],s=[];for(let a of Array.isArray(e.ids)?e.ids:[])n.forEach((l,i)=>{l.attrs.id!==a||o.includes(a)||(o.push(a),s.push({from:i,to:i+l.nodeSize}))});return s.length?{kind:"blocks",ids:o,ranges:s}:null}return null}var{Plugin:ge,PluginKey:he}=k,{Decoration:b,DecorationSet:x}=H,y=new he("page-awareness"),oe="page-awareness-style",be=`
2
2
  .page-remote-selection { background-color: color-mix(in srgb, var(--page-remote-color, currentColor) 22%, transparent); }
3
3
  .page-remote-caret { position: relative; display: inline-block; width: 0; height: 1.1em; vertical-align: text-bottom; }
4
4
  .page-remote-caret::before { content: ""; position: absolute; inset-inline-start: -1px; top: 0; bottom: 0; width: 2px; background: var(--page-remote-color, currentColor); }
@@ -0,0 +1 @@
1
+ import{a}from"./c-SFKI6OLM.js";import"./c-Q3XOWZEV.js";import"./c-VHNSBD2M.js";export{a as stripCopyContent};
@@ -1 +1 @@
1
- import{a,b,c,d,e,f}from"./c-5ZQV7KC4.js";import"./c-N326R2JD.js";import"./c-I2SCCUEW.js";import"./c-3O7OBDCM.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-HA6INT6J.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";export{c as beginApply,d as completeApply,f as conflicts,e as failApply,a as loadEdit,b as registerContext};
1
+ import{a,b,c,d,e,f}from"./c-LV5MABYD.js";import"./c-N326R2JD.js";import"./c-I2SCCUEW.js";import"./c-3O7OBDCM.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-HA6INT6J.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";export{c as beginApply,d as completeApply,f as conflicts,e as failApply,a as loadEdit,b as registerContext};
@@ -0,0 +1 @@
1
+ import{b as m}from"./c-PZ4XEPUP.js";import{a as c}from"./c-SFKI6OLM.js";import{a as p,b as y}from"./c-RHMPKZZ7.js";import{K as f,L as d}from"./c-EGTIAL6P.js";function g(e=new Date){let t=r=>String(r).padStart(2,"0");return`${e.getFullYear()}${t(e.getMonth()+1)}${t(e.getDate())}-${t(e.getHours())}${t(e.getMinutes())}${t(e.getSeconds())}`}function h(e,t){let n=`<script type="application/json" id="clay-lost-edits" clay="no-save">${JSON.stringify(t).replace(/</g,"\\u003c")}<\/script>`,s=e.lastIndexOf("</body>");return s>=0?e.slice(0,s)+n+e.slice(s):e+n}function j(e,{refused:t=!1}={}){let r=window.clay?.conflicts||null,n=[],s=new Set;for(let o of e){let a=r?.recoveryOf(o.id);a&&!s.has(a.id)&&(s.add(a.id),n.push(a))}n.sort((o,a)=>(o.ticket||0)-(a.ticket||0));let u=o=>c(f(o.recoveryRoot??o.root,{prepared:o.domain==="save"})),i,l;t||!n.length?(i=c(d()),l=n):(i=u(n[n.length-1]),l=n.slice(0,-1));let w=e.map(o=>{if(o.kind==="apply-incomplete")return{id:o.id,kind:"apply-incomplete",name:"Sync update that did not finish",error:o.error??null};let{id:a,name:$,kind:S,yours:O,now:b,sentence:k}=m(o);return{id:a,name:$,kind:S,yours:O,now:b,sentence:k}}),v={format:"clay-lost-edits",version:1,savedAt:new Date().toISOString(),page:location.href,refused:!!t,edits:w,earlierPages:l.map(o=>({applyId:o.id,source:o.source,html:u(o)}))};return{html:h(i,v),name:`${p()}-${t?"my-version":"my-copy"}-${g()}.html`}}async function I({html:e=null,edits:t=[]}={}){try{let r=c(typeof e=="string"?e:d()),n={format:"clay-lost-edits",version:1,savedAt:new Date().toISOString(),page:location.href,refused:!1,edits:Array.isArray(t)?t:[],earlierPages:[]};return await y({html:h(r,n),name:`${p()}-my-copy-${g()}.html`})}catch(r){return console.error("clayjs: could not build the download",r),!1}}async function C(e,{refused:t=!1}={}){try{let{html:r,name:n}=j(e,{refused:t});return await y({html:r,name:n})}catch(r){return console.error("clayjs: could not build the download",r),!1}}export{I as a,C as b};
@@ -1,3 +1,3 @@
1
- import{a as G}from"./c-CAS3NND4.js";import{b as J}from"./c-3G2DGZUP.js";import{o as z,p as _}from"./c-B7J4K2AE.js";import"./c-ATKAOH23.js";import"./c-EK63G3CG.js";import{a as F}from"./c-NQJRVJ56.js";import"./c-XGH4GS2T.js";import"./c-IJUK2GPW.js";import"./c-3O7OBDCM.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-7MG5RU63.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-VG5XIN4T.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-DCFSEJZG.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var Le=Object.defineProperty,je=(e,t)=>{for(var r in t)Le(e,r,{get:t[r],enumerable:!0})},Ce=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],Me=new Set(Ce),Ue=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),Ie=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),Y=new Set(["checked","selected","disabled","readOnly","paused"]);function Pe(e,t){return t==null?Y.has(e)?!1:"":Y.has(e)?t==="false"?!1:!!t:t}var De={};je(De,{EmptyListInsert:()=>R,MAX_RULE_DEPTH:()=>C,MaxRuleDepthExceeded:()=>V,NoRulesTag:()=>We,RuleTargetReadOnly:()=>fe,RulesParseError:()=>se,ShapeMismatch:()=>ce,UnknownRulesVersion:()=>ue,WriteNotRoundTripped:()=>He,WriteRefused:()=>Be,WriteRejected:()=>Ve});var se=class extends Error{constructor(e,t){super(e),this.name="RulesParseError",this.cause=t}},ue=class extends Error{constructor(e){super(`unknown rules version: ${e}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=e}},C=20,V=class extends Error{constructor(e){super(`rule depth exceeded ${C} at path: ${e.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=e}},ce=class extends Error{constructor(e){super(`shape mismatch: ${e.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=e}},R=class extends Error{constructor(e,t){super(t?`cannot add items to empty list at "${e.join(".")}" \u2014 ${t}`:`cannot add items to empty list at "${e.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=e}},fe=class extends Error{constructor(e){super(`cannot write to read-only DOM property "${e}"`),this.name="RuleTargetReadOnly",this.target=e}},Be=class extends Error{constructor(e){super(`write refused: ${e.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=e}};function qe(e){return e.reduce((t,r)=>typeof r=="number"?`${t}[${r}]`:t?`${t}.${r}`:String(r),"")||"(root)"}var He=class extends Error{constructor(e){super(`write did not round-trip at "${qe(e)}"`),this.name="WriteNotRoundTripped",this.path=e}},We=class extends Error{constructor(e){super(`no <script data-rules-name~="${e}"> rules tag in this document`),this.name="NoRulesTag",this.token=e}},Ve=class extends Error{constructor(e,t){super(`write rejected: ${e.length} unknown key(s), ${t.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=e,this.unmatched=t}};function de(e){let t=0,r=null,l=-1;for(let n=0;n<e.length;n++){let o=e[n];o==="\\"?n++:r?o===r&&(r=null):o==='"'||o==="'"?r=o:o==="["||o==="("?t++:o==="]"||o===")"?t>0&&t--:o==="@"&&t===0&&(l=n)}return l}function pe(e){let t=0,r=null,l=-1,n=!1;for(let o=0;o<e.length;o++){let i=e[o];i==="\\"?o++:r?i===r&&(r=null):i==='"'||i==="'"?r=i:i==="["||i==="("?t++:i==="]"||i===")"?t>0&&t--:t===0&&i===">"?l=o:t===0&&i===","&&(n=!0)}return n||l===-1||!Fe(e,l+1)?null:e.slice(0,l).trim()||null}function Fe(e,t){let r=t,l=e.replace(/\s+$/,"").length;for(;r<l&&/\s/.test(e[r]);)r++;let n=0,o=null;for(;r<l;r++){let i=e[r];if(i==="\\")r++;else if(o)i===o&&(o=null);else if(i==='"'||i==="'")o=i;else if(i==="["||i==="(")n++;else if(i==="]"||i===")")n>0&&n--;else if(n===0&&(i==="+"||i==="~"||/\s/.test(i)))return!1}return!0}var ze=/^--[A-Za-z0-9_-]+$/;function he(e){return typeof e=="string"&&ze.test(e)}function me(e){let t=[],r=[],l=null,n=0;for(let o=0;o<e.length;o++){let i=e[o];if(l){i==="\\"?o++:i===l&&(l=null);continue}if(i==="/"&&e[o+1]==="*"){let a=e.indexOf("*/",o+2);o=a===-1?e.length:a+1;continue}i==='"'||i==="'"?l=i:i==="("?r.push(")"):i==="["?r.push("]"):i==="{"?r.push("}"):(i===")"||i==="]"||i==="}")&&r[r.length-1]===i?r.pop():i===";"&&r.length===0&&(t.push(e.slice(n,o)),n=o+1)}return t.push(e.slice(n)),t}function _e(e){let t="",r=null;for(let l=0;l<e.length;l++){let n=e[l];if(r){t+=n,n==="\\"&&l+1<e.length?t+=e[++l]:n===r&&(r=null);continue}if(n==="/"&&e[l+1]==="*"){let o=e.indexOf("*/",l+2);l=o===-1?e.length:o+1,t+=" ";continue}(n==='"'||n==="'")&&(r=n),t+=n}return t}function ye(e){e=_e(e);let t=e.indexOf(":");if(t===-1)return null;let r=e.slice(0,t).trim(),l=e.slice(t+1).trim(),n=/!\s*important\s*$/i.exec(l);return n&&(l=l.slice(0,n.index).trim()),{name:r,value:l,important:!!n}}function ge(e,t){if(e==null)return null;let r=null;for(let l of me(String(e))){let n=ye(l);!n||n.name!==t||(!r||n.important||!r.important)&&(r=n)}return r?r.value:null}function Je(e,t,r){let l=e==null?"":String(e),n=r==null||r==="",o=me(l),i=o.map(ye),a=i.some(f=>f&&f.name===t&&f.important),s=[],u=!1;o.forEach((f,d)=>{let h=i[d];if(!h||h.name!==t){s.push(f);return}if(n||u)return;let m=/^\s*/.exec(f)[0];s.push(`${m}${t}: ${r}${a?" !important":""}`),u=!0});let c=s.join(";");if(!n&&!u){let f=c.trimEnd();c=f===""?`${t}: ${r}`:`${f}${f.endsWith(";")?" ":"; "}${t}: ${r}`}return c.trim()===""?null:c}function Ge(e,t,r,l){let n=e.attr(t,"style");if((ge(n,r)??"")===l)return;let o=Je(n,r,l);o==null?e.removeAttr(t,"style"):e.attr(t,"style",o)}function we(e,t,r,l={}){if(Object.prototype.hasOwnProperty.call(l,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return P(e,t,r,{depth:0,path:[]},l)}function P(e,t,r,l,n){if(l.depth>C)throw new V(l.path);if(typeof r=="string")return Ye(e,t,r,l,n);if(Array.isArray(r)){let[o,i]=r,a=e.find(t,o,n);return ve(n,l,a),a.map((s,u)=>P(e,s,i,{depth:l.depth+1,path:[...l.path,u]},n))}if(typeof r=="object"&&r!==null){let o={};for(let[i,a]of Object.entries(r))o[i]=P(e,t,a,{depth:l.depth+1,path:[...l.path,i]},n);return o}return null}function Ye(e,t,r,l,n){if(r.endsWith("[]")){let a=r.slice(0,-2),s=e.find(t,a,n);return ve(n,l,s),s.map(u=>e.text(u))}if(r.startsWith("@"))return X(e,t,r.slice(1));let o=de(r);if(o!==-1){let a=r.slice(0,o),s=r.slice(o+1),u=a?e.find(t,a,n):[t];return u.length===0?null:X(e,u[0],s)}if(r===".")return e.text(t);let i=e.find(t,r,n);return i.length===0?null:e.text(i[0])}function ve(e,t,r){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),r)}catch(l){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,l)}}function X(e,t,r){if(he(r))return ge(e.attr(t,"style"),r);if(Me.has(r)){let n=e.prop(t,r);return n==null?null:String(n)}return e.attr(t,r)??null}function Xe(e,t,r,l){let n=e.length,o=t.length,i=new Array(n).fill(-1);if(l){let p=new Set;for(let y=0;y<n;y++){let g=l[y];!(g>=0&&g<o)||p.has(g)||(i[y]=g,p.add(g))}}if(n===0||o===0)return i;let a=e.map(p=>K(p,r)),s=t.map(p=>K(p,r)),u=new Array(o).fill(!1);for(let p of i)p>=0&&(u[p]=!0);let c=new Map;s.forEach((p,y)=>{u[y]||c.set(p,c.has(p)?-1:y)});let f=new Map;a.forEach((p,y)=>{i[y]>=0||f.set(p,(f.get(p)||0)+1)}),a.forEach((p,y)=>{if(i[y]>=0||f.get(p)!==1)return;let g=c.get(p);g===void 0||g===-1||u[g]||(i[y]=g,u[g]=!0)});let d=[];for(let p=0;p<n;p++)i[p]<0&&d.push(p);let h=[];for(let p=0;p<o;p++)u[p]||h.push(p);if(d.length===0||h.length===0)return i;let m=n*o+1,w=Ke(e,t,r),v=(p,y)=>w(p,y)*m+Math.abs(p-y);for(let[p,y]of Ze(d,h,v))i[p]=y;return i}var be=e=>typeof e=="object"&&e!==null;function K(e,t){if(!be(t))return e==null?" null":String(e);let r=Object.keys(t);return JSON.stringify(r.map(l=>{let n=JSON.stringify(e?.[l]);return n===void 0?" undef":n}))}function Ke(e,t,r){if(!be(r))return(a,s)=>e[a]===t[s]?0:1;let l=Object.keys(r),n=a=>l.map(s=>JSON.stringify(a?.[s])),o=e.map(n),i=t.map(n);return(a,s)=>{let u=o[a],c=i[s],f=0;for(let d=0;d<l.length;d++)u[d]!==c[d]&&f++;return f}}function Ze(e,t,r){return e.length<=t.length?Z(e,t,r,!1):Z(t,e,(l,n)=>r(n,l),!0)}function Z(e,t,r,l){let n=e.length,o=t.length,i=[];for(let f=0;f<=n;f++)i.push(new Float64Array(o+1).fill(1/0));let a=[];for(let f=0;f<=n;f++)a.push(new Uint8Array(o+1));for(let f=0;f<=o;f++)i[n][f]=0;for(let f=n-1;f>=0;f--)for(let d=o-1;d>=0;d--){let h=r(e[f],t[d])+i[f+1][d+1],m=i[f][d+1];h<=m?(i[f][d]=h,a[f][d]=1):i[f][d]=m}let s=[],u=0,c=0;for(;u<n&&c<o;)a[u][c]&&(s.push(l?[t[c],e[u]]:[e[u],t[c]]),u++),c++;return s}function xe(e,t,r,l,n,o,i,a={}){let s=e.find(t,r,a);if(n.length===0){s.forEach(b=>e.remove(b)),D(a,"onRowsApplied",o.path,[]);return}let u=n.length>s.length,c=s[0]||null;if(u&&!c&&(c=rt(e,t,r,a),!c))throw new R(o.path);let f=s.map(b=>tt(e,b,l,a)),d=null;if(u&&c){d=e.clone(c),a.templateAttr&&e.removeAttr(d,a.templateAttr);let b=e.stripIds(d);b>0&&console.warn(`[hyper-html-api] stripped ${b} id attribute(s) from cloned template at "${o.path.join(".")||"(root)"}"`)}let h=Xe(n,f,l,Qe(e,s,n,o,a)),m=s.length>0?e.parent(s[0]):it(e,t,r,c,o,a),w=s.length>0?Ae(e,m,s[0]):0,v=ut(e,s),p=new Set,y=[],g=n.map((b,E)=>{let N=h[E];if(N>=0)return p.add(N),y.push(!1),s[N];y.push(!0);let T=e.clone(d);return e.stripIds(T),T});s.forEach((b,E)=>{p.has(E)||e.remove(b)}),v?st(e,m,w,g,y):ct(e,g,y,m,w),et(e,g,l,n,o,i,a),D(a,"onRowsApplied",o.path,g)}function D(e,t,r,l){if(typeof e[t]=="function")try{return e[t](r.slice(),l)}catch(n){console.warn(`[hyper-html-api] ${t} threw at "${r.join(".")||"(root)"}"`,n);return}}function Qe(e,t,r,l,n){let o=D(n,"identifyRows",l.path,r);if(!Array.isArray(o))return null;let i=new Array(r.length).fill(-1),a=new Set,s=new Map(t.map((u,c)=>[e.identity(u),c]));for(let u=0;u<r.length;u++){if(!o[u])continue;let c=s.get(e.identity(o[u]));c===void 0||a.has(c)||(i[u]=c,a.add(c))}return i}function et(e,t,r,l,n,o,i){t.forEach((a,s)=>{if(r===null){let u=l[s],c=u==null?"":String(u);e.text(a)!==c&&e.text(a,c)}else{let u=o(e,a,r,l[s],{depth:n.depth+1,path:[...n.path,s]},i);u&&u!==a&&(t[s]=u)}})}function tt(e,t,r,l){return r===null?e.text(t):we(e,t,r,l.onRowsRead?{...l,onRowsRead:void 0}:l)}function Ae(e,t,r){let l=e.children(t);for(let n=0;n<l.length;n++)if(e.sameNode(l[n],r))return n;return-1}function rt(e,t,r,l){if(!l.templateAttr)return null;let n=/^\s*:scope\s*>\s*/.test(r),o=new RegExp(":not\\(\\["+l.templateAttr.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")+"\\]\\)","g"),i=r.replace(/^\s*:scope\s*>\s*/,"").replace(o,""),a=n?nt(i):0,s=pe(i),u=t;for(;u;){let c=e.find(u,i,{includeRulesTag:!1,templateAttr:null});for(let f of c)if(e.attr(f,l.templateAttr)!=null&&!(n&&!ot(e,t,f,a))&&!(s&&!e.matches(e.parent(f),s)))return f;u=e.parent(u)}return null}function nt(e){let t=0,r=null,l=1;for(let n=0;n<e.length;n++){let o=e[n];if(o==="\\")n++;else if(r)o===r&&(r=null);else if(o==='"'||o==="'")r=o;else if(o==="["||o==="(")t++;else if(o==="]"||o===")")t>0&&t--;else if(t===0&&o===">")l++;else{if(t===0&&(o==="+"||o==="~"))return null;if(t===0&&/\s/.test(o)){if(!lt(e,n))return null;for(;n+1<e.length&&/\s/.test(e[n+1]);)n++}}}return l}function lt(e,t){let r=t;for(;r<e.length&&/\s/.test(e[r]);)r++;let l=t>0?e[t-1]:"",n=r<e.length?e[r]:"";return Q(l)||Q(n)}function Q(e){return e===">"||e==="+"||e==="~"}function ot(e,t,r,l){if(l===null)return!0;let n=r;for(let s=0;s<l;s++)if(n=e.parent(n),!n)return!1;let o=e.prop(t,"tagName");if(!o)return!0;let i=e.prop(n,"tagName");if(!i||String(i).toLowerCase()!==String(o).toLowerCase())return!1;let a=new Set(ee(e,n));return ee(e,t).every(s=>a.has(s))}function ee(e,t){let r=e.attr(t,"class");return r?String(r).split(/\s+/).filter(Boolean):[]}function it(e,t,r,l,n,o){let i=e.parent(l);if(i&&at(e,t,i)&&!re(e,i,o))return i;let a=pe(r);if(!a)throw new R(n.path,`the list selector "${r}" names no container to hold the new rows \u2014 write it as "container > row" (for example "ol.comments > li") so the cloned row lands in the list`);let s=(a===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,a,o)).filter(u=>!re(e,u,o));if(s.length===0)throw new R(n.path,`no container matching "${a}" inside this context to hold the new rows`);if(s.length>1)throw new R(n.path,`"${a}" matches ${s.length} containers inside this context, so the new rows have no single destination`);return s[0]}function at(e,t,r){let l=r;for(;l;){if(e.sameNode(l,t))return!0;l=e.parent(l)}return e.parent(t)?!1:e.find(t,"*",{includeRulesTag:!0,templateAttr:null}).some(n=>e.sameNode(n,r))}var te=["no-data","editor-ui"];function re(e,t,r){let l=t;for(;l;){if(r.templateAttr&&e.attr(l,r.templateAttr)!=null||te.some(o=>e.attr(l,o)!=null))return!0;let n=e.attr(l,"clay");if(n&&n.split(/\s+/).some(o=>te.includes(o)))return!0;l=e.parent(l)}return!1}function st(e,t,r,l,n){let o=e.children(t),i=o.map(s=>e.identity(s)),a=!1;l.forEach((s,u)=>{let c=e.identity(s),f=r+u;if(i[f]===c)return;if(!n[u]){let h=i.indexOf(c);h!==-1&&(i.splice(h,1),o.splice(h,1))}let d=Math.min(f,o.length);d<o.length?e.insertBefore(o[d],s):o.length?a?e.insertAfter(o[o.length-1],s):(e.insertAt(t,s,f),a=!0):e.insertAt(t,s,0),i.splice(d,0,c),o.splice(d,0,s)})}function ut(e,t){if(t.length<=1)return!0;let r=e.parent(t[0]);if(!r)return!1;let l=new Map(e.children(r).map((o,i)=>[e.identity(o),i])),n=[];for(let o of t){let i=l.get(e.identity(o));if(i===void 0)return!1;n.push(i)}return n.sort((o,i)=>o-i),n[n.length-1]-n[0]===n.length-1}function ct(e,t,r,l,n){let o=null,i=n;for(let a=0;a<t.length;a++){if(!r[a]){o=t[a];continue}let s=o?e.parent(o):l;if(!s)continue;let u=o?Ae(e,s,o)+1:i++;e.insertAt(s,t[a],u),o=t[a]}}function ft(e,t,r,l,n={}){if(Object.prototype.hasOwnProperty.call(n,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");let o=[];if(B(r,l,[],o),o.length)throw new ce(o);j(e,t,r,l,{depth:0,path:[]},n)}function j(e,t,r,l,n,o={}){if(n.depth>C)throw new V(n.path);if(l===void 0)return t;if(typeof r=="string")return dt(e,t,r,l,n,o);if(Array.isArray(r)){let[i,a]=r;return xe(e,t,i,a,l,n,j,o),t}if(typeof r=="object"&&r!==null){for(let[i,a]of Object.entries(r)){let s=j(e,t,a,l==null?l:l[i],{depth:n.depth+1,path:[...n.path,i]},o);s&&s!==t&&(t=s)}return t}return t}function dt(e,t,r,l,n,o){if(r.endsWith("[]")){let s=r.slice(0,-2);return xe(e,t,s,null,l,n,j,o),t}if(r.startsWith("@"))return le(e,t,r.slice(1),l);let i=de(r);if(i!==-1){let s=r.slice(0,i),u=r.slice(i+1),c=s?e.find(t,s,o):[t];return c.length===0||le(e,c[0],u,l),t}if(r===".")return ne(e,t,l),t;let a=e.find(t,r,o);return a.length===0||ne(e,a[0],l),t}function ne(e,t,r){let l=r==null?"":String(r);e.text(t)!==l&&e.text(t,l)}function pt(e,t,r,l){if(e.styleVar){e.styleVar(t,r,l);return}Ge(e,t,r,l)}function le(e,t,r,l){if(he(r))return pt(e,t,r,l==null?"":String(l).trim()),t;if(Ie.has(r)){let n=e.prop(t,r);if(n===l||n!=null&&l!=null&&String(n)===String(l))return t;throw new fe(r)}if(r==="outerHTML"){let n=l==null?"":String(l);return e.replaceWith(t,n)}if(Ue.has(r)){let n=Pe(r,l);return e.prop(t,r)!==n&&e.prop(t,r,n),t}if(l==null)e.attr(t,r)!=null&&e.removeAttr(t,r);else{let n=String(l);e.attr(t,r)!==n&&e.attr(t,r,n)}return t}function B(e,t,r,l){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((n,o)=>{typeof n=="object"&&n!==null&&l.push({path:S([...r,o]),expected:"scalar",got:k(n)})}):l.push({path:S(r),expected:"array",got:k(t)});return}t!==null&&typeof t=="object"&&l.push({path:S(r),expected:"scalar",got:k(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){l.push({path:S(r),expected:"array",got:k(t)});return}let n=e[1];t.forEach((o,i)=>B(n,o,[...r,i],l));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){l.push({path:S(r),expected:"object",got:k(t)});return}for(let[n,o]of Object.entries(e))B(o,t[n],[...r,n],l)}}}function k(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function S(e){return e.join(".")}function ht(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function r(n){let o=[],i=0;for(;i<n.length;){let a=n[i];if(/\s/.test(a)){i++;continue}if("{}".includes(a)){o.push({type:a,value:a}),i++;continue}if(a==="["){let f=!1,d=i+1;for(;d<n.length&&/\s/.test(n[d]);)d++;if(d<n.length&&/[a-zA-Z_]/.test(n[d])&&(f=!0),!f){o.push({type:a,value:a}),i++;continue}}if(a==="]"){o.push({type:a,value:a}),i++;continue}if(a===":"){o.push({type:t.COLON,value:a}),i++;continue}if(a===","){o.push({type:t.COMMA,value:a}),i++;continue}if(a==='"'||a==="'"){let f=a,d=i+1;for(;d<n.length&&n[d]!==f;)n[d]==="\\"&&d++,d++;o.push({type:t.STRING,value:n.substring(i+1,d),quoted:!0,sourceQuote:f}),i=d+1;continue}let s=i,u;for(;s<n.length&&!/[{},]/.test(n[s]);)if(n[s]===":"){let f=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],d=!1;for(let h of f){let m=h.substring(1);if(n.substring(s+1,s+1+m.length)===m){d=!0,s+=m.length;break}}if(!d)break}else if(n[s]==="["){for(s++;s<n.length&&n[s]!=="]";){if(n[s]==='"'||n[s]==="'"){let f=n[s];for(s++;s<n.length&&n[s]!==f;)n[s]==="\\"&&s++,s++}s++}s<n.length&&n[s]==="]"&&s++}else s++;u=n.substring(i,s);let c=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(u)?c=t.NUMBER:u==="true"||u==="false"||u==="null"?c=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(u)&&(c=t.SELECTOR),o.push({type:c,value:u,quoted:!1}),i=s}return o}function l(n){let o="";for(let i=0;i<n.length;i++){let a=n[i];if("{}".includes(a.type)||"[]".includes(a.type)){o+=a.value;continue}if(a.type===t.COLON){o+=a.value;continue}if(a.type===t.COMMA){let s=n[i+1];if(s&&(s.type==="}"||s.type==="]"))continue;o+=a.value;continue}if(a.type===t.STRING&&a.quoted){let s=a.value;a.sourceQuote==="'"&&(s=s.replace(/\\'/g,"'"),s=s.replace(/(\\*)"/g,(u,c)=>c.length%2===0?c+'\\"':u)),o+=`"${s}"`;continue}if(a.type===t.NUMBER||a.type===t.BOOLEAN){o+=a.value;continue}if(a.type===t.SELECTOR||a.type===t.IDENTIFIER){o+=`"${a.value}"`;continue}o+=`"${a.value}"`}return o}try{let n=r(e),o=l(n);return JSON.parse(o)}catch(n){throw new se("Invalid extraction rules syntax: "+n.message,n)}}var mt="1";var or=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),ir=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),yt=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);var ar=Object.freeze({refusedRuleForms:["innerHTML","outerHTML"],refusedTargets:["script","style","template","noscript","iframe","object","embed","xmp","plaintext","noembed","noframes","meta","link","base","animate","set","animatemotion","animatetransform"],refusedAttributes:["style","srcdoc","is","http-equiv","sandbox","allow","nonce","integrity","charset","htmlclaytoken","htmlclayid","data-rules-name","data-rules-version","clay","contenteditable",...yt],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"],customPropertyValues:Object.freeze({maxLength:200,refusedCharacters:[";","{","}","<",">","\\"],refusedFunctions:["url","src","image","image-set","-webkit-image-set","cross-fade","element","expression","paint"]})});function gt(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function wt(e){return e?(e.nodeType===9||e.nodeType,e):null}function oe(e,t,r){!e||e.nodeType!==1||(t==="value"&&e.tagName==="INPUT"?e.value=r===null?"":r:t==="checked"&&e.tagName==="INPUT"?e.checked=r!==null:t==="selected"&&e.tagName==="OPTION"&&(e.selected=r!==null))}function vt(e,t){e&&e.tagName==="TEXTAREA"&&(e.value=t)}function bt(e){if(!e||e.nodeType!==1)return;let t=[e,...e.querySelectorAll?e.querySelectorAll("textarea, input, option"):[]];for(let r of t)if(r.tagName==="TEXTAREA")r.value=r.defaultValue;else if(r.tagName==="INPUT"){let l=r.type;l!=="file"&&l!=="checkbox"&&l!=="radio"&&(r.value=r.defaultValue),r.checked=r.defaultChecked}else r.tagName==="OPTION"&&(r.selected=r.defaultSelected)}var xt={semanticExclude:!0,find(e,t,r={}){let l=wt(e);if(!l||!l.querySelectorAll)return[];let n=Array.from(l.querySelectorAll(t));r.includeRulesTag||(n=n.filter(a=>!gt(a)));let o=[];r.skip&&o.push(r.skip);let i=r.templateAttr===null?null:r.templateAttr||"cms-template";if(i&&o.push("["+i+"]"),o.length){let a=o.join(", ");n=n.filter(s=>!s.closest||!s.closest(a))}return n},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},matches(e,t){return!!(e&&e.matches)&&e.matches(t)},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t,vt(e,t)},attr(e,t,r){if(r===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,r),oe(e,t,r)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),oe(e,t,null)},prop(e,t,r){if(r===void 0){let l=e?e[t]:void 0;return l!==void 0?l:null}e[t]=r},clone(e){let t=e.cloneNode(!0);return bt(t),t},insertAt(e,t,r){let l=e.children[r]||null;e.insertBefore(t,l)},insertBefore(e,t){e.parentNode.insertBefore(t,e)},insertAfter(e,t){e.parentNode.insertBefore(t,e.nextSibling)},identity(e){return e||null},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let r=e.ownerDocument.createElement("template");r.innerHTML=t;let l=r.content.firstElementChild;if(!l)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(l,e),l},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(r=>{r.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};var L=xt;var At="hha:upgrade-check:";function x(e,t){let r=e.querySelector(`meta[name="${t}"]`),l=r?r.getAttribute("content"):null;return l&&l.trim()?l.trim():null}function ie(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function Tt(e,t){let r=ie(e),l=ie(t);if(!r||!l)return!1;let n=Math.max(r.length,l.length);for(let o=0;o<n;o++){let i=r[o]||0,a=l[o]||0;if(i!==a)return i>a}return!1}function Ot(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Et(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function Nt({force:e=!1,doc:t,loc:r,fetchFn:l,now:n,ttlMs:o=864e5}={}){if(t=t||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),l=l||(d=>fetch(d)),n=n??Date.now(),!t)return null;let i=x(t,"hyper-source");if(!i)return null;let a=x(t,"hyper-version"),s;try{s=new URL(i,r?r.href:void 0)}catch{return null}if(r&&s.origin===r.origin&&s.pathname===r.pathname)return null;let u=`${At}${s.href}:${a||"none"}`,c,f=e?null:Ot(u);if(f&&typeof f.checkedAt=="number"&&n-f.checkedAt<o)c=f.sourceVersion;else{try{let d=await l(s.href);if(!d.ok)throw new Error(`HTTP ${d.status}`);let h=await d.text(),m=new DOMParser().parseFromString(h,"text/html");c=x(m,"hyper-version")}catch{c=null}Et(u,{checkedAt:n,sourceVersion:c})}return c?{available:Tt(c,a||"0.0.0"),currentVersion:a,sourceVersion:c,sourceUrl:s.href}:null}var kt="script[data-rules-name]";function St(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function Te(e,t){let r=e.find(t,kt,{includeRulesTag:!0}),l=new Set,n=[];for(let o of r){let i=St(e.attr(o,"data-rules-name"));if(!i)continue;if(l.has(i)){console.warn(`hyper-html-api: duplicate rules tag name "${i}"; using the first.`);continue}let a=e.attr(o,"data-rules-version");if(a!==mt)throw new ue(a);l.add(i),n.push({name:i,rules:ht(e.text(o))})}return n}function Oe(e,t){let r={};for(let{name:l,rules:n}of Te(e,t))r[l]=we(e,t,n);return r}function Rt(e){let t=e||document,r=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Oe(L,t),version:x(r,"hyper-version")}}var ae=class extends Error{constructor(e,t){super(`could not fetch upgrade source: ${e}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=e,this.cause=t}},$t=class extends Error{constructor(e){super(`upgrade source has no rules tags; refusing to drop all existing data: ${e}`),this.name="UpgradeSourceHasNoRules",this.sourceUrl=e}},q=class extends Error{constructor(e,t){super(e),this.name="UpgradeTransformInvalid",this.cause=t}},Lt=class extends Error{constructor(e){super(`found ${e} script[type="text/hyper-upgrade"] tags; only one is allowed per document.`),this.name="UpgradeMultipleTransforms",this.count=e}},jt="text/hyper-upgrade";function Ct(e,t){let r=e.find(t,`script[type="${jt}"]`);if(r.length===0)return null;if(r.length>1)throw new Lt(r.length);return e.text(r[0])||null}var Mt=new Function("url","return import(url)");async function Ut(e){let t=new Blob([e],{type:"text/javascript"}),r=URL.createObjectURL(t),l;try{l=await Mt(r)}catch(n){throw new q(`transform failed to load: ${n&&n.message?n.message:n}`,n)}finally{URL.revokeObjectURL(r)}if(typeof l.default!="function")throw new q("transform must `export default` a function");return l.default}function Ee(e,t){let r={carriedOver:0,discarded:0,listItems:0},l=H(t,e,r);return W(t,e,r),{data:l,summary:r}}function H(e,t,r){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(r.listItems+=t.length,r.carriedOver+=t.length,t):void 0:t==null||typeof t=="object"?void 0:(r.carriedOver++,t);if(Array.isArray(e)){let[,l]=e;return Array.isArray(t)?(r.listItems+=t.length,t.map(n=>H(l,n,r))):void 0}if(typeof e=="object"&&e!==null){let l={};for(let[n,o]of Object.entries(e)){let i=H(o,t?.[n],r);i!==void 0&&(l[n]=i)}return l}}function W(e,t,r){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let l=new Set(Object.keys(e));for(let n of Object.keys(t))l.has(n)?W(e[n],t[n],r):r.discarded+=$(t[n]);return}if(Array.isArray(e)&&Array.isArray(t)){let l=e[1];t.forEach(n=>W(l,n,r));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(r.discarded+=$(t))}}function $(e){return e==null?0:Array.isArray(e)?e.reduce((t,r)=>t+$(r),0):typeof e=="object"?Object.values(e).reduce((t,r)=>t+$(r),0):1}function It(e,t,r){let l=Te(e,t),n={carriedOver:0,discarded:0,listItems:0},o={},i=new Set;for(let{name:a,rules:s}of l){if(i.add(a),!Object.prototype.hasOwnProperty.call(r,a)){o[a]={carriedOver:0,discarded:0,listItems:0};continue}let{data:u,summary:c}=Ee(r[a],s);ft(e,t,s,u),o[a]=c,n.carriedOver+=c.carriedOver,n.discarded+=c.discarded,n.listItems+=c.listItems}for(let a of Object.keys(r))i.has(a)||(n.discarded+=$(r[a]));return{totals:n,byName:o,rulesTagCount:l.length}}async function Pt({sourceUrl:e,dataByName:t,fromVersion:r,doc:l,loc:n,fetchFn:o}={}){if(l=l||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(p=>fetch(p)),!l)throw new Error("upgrade.run requires a document context");if(e=e||x(l,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let i=new URL(e,n?n.href:void 0);r=r!==void 0?r:x(l,"hyper-version"),t=t||Oe(L,l);let a;try{a=await o(i.href)}catch(p){throw new ae(i.href,p)}if(!a.ok)throw new ae(i.href,new Error(`HTTP ${a.status}`));let s=await a.text(),u=new DOMParser().parseFromString(s,"text/html"),c=x(u,"hyper-version"),f=t,d=!1,h=Ct(L,u);if(h){let p=await(await Ut(h))(f,{fromVersion:r,toVersion:c});if(!p||typeof p!="object"||Array.isArray(p))throw new q("transform must return a plain object map of { rulesName: data }");f=p,d=!0}let{totals:m,byName:w,rulesTagCount:v}=It(L,u,f);if(v===0&&Object.keys(f).length>0)throw new $t(i.href);return{html:Bt(u),fromVersion:r,toVersion:c,summary:{transformApplied:d,totals:m,byName:w}}}function Dt(e){for(let t of e.querySelectorAll("input")){let r=(t.getAttribute("type")||"").toLowerCase();r!=="file"&&(r==="checkbox"||r==="radio"?t.checked!==t.hasAttribute("checked")&&t.toggleAttribute("checked",t.checked):t.value!==(t.getAttribute("value")??"")&&t.setAttribute("value",t.value))}for(let t of e.querySelectorAll("textarea"))t.value!==t.textContent&&(t.textContent=t.value);for(let t of e.querySelectorAll("select")){let r=[...t.options];if(!t.multiple){let l=r.findIndex(n=>n.hasAttribute("selected"));if(t.selectedIndex===l||l===-1&&t.selectedIndex<=0)continue}for(let l of r)l.selected!==l.hasAttribute("selected")&&l.toggleAttribute("selected",l.selected)}}function Bt(e){return Dt(e),`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
1
+ import{a as G}from"./c-S5IEIZCN.js";import{b as J}from"./c-3G2DGZUP.js";import{o as z,p as _}from"./c-GVPNDIKJ.js";import"./c-ATKAOH23.js";import"./c-EK63G3CG.js";import{a as F}from"./c-NQJRVJ56.js";import"./c-XGH4GS2T.js";import"./c-IJUK2GPW.js";import"./c-3O7OBDCM.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-EGTIAL6P.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-VG5XIN4T.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var Ce=Object.defineProperty,Le=(e,t)=>{for(var r in t)Ce(e,r,{get:t[r],enumerable:!0})},je=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],Me=new Set(je),Ue=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),Ie=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),Y=new Set(["checked","selected","disabled","readOnly","paused"]);function Pe(e,t){return t==null?Y.has(e)?!1:"":Y.has(e)?t==="false"?!1:!!t:t}var De={};Le(De,{EmptyListInsert:()=>R,MAX_RULE_DEPTH:()=>j,MaxRuleDepthExceeded:()=>V,NoRulesTag:()=>We,RuleTargetReadOnly:()=>fe,RulesParseError:()=>se,ShapeMismatch:()=>ce,UnknownRulesVersion:()=>ue,WriteNotRoundTripped:()=>He,WriteRefused:()=>Be,WriteRejected:()=>Ve});var se=class extends Error{constructor(e,t){super(e),this.name="RulesParseError",this.cause=t}},ue=class extends Error{constructor(e){super(`unknown rules version: ${e}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=e}},j=20,V=class extends Error{constructor(e){super(`rule depth exceeded ${j} at path: ${e.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=e}},ce=class extends Error{constructor(e){super(`shape mismatch: ${e.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=e}},R=class extends Error{constructor(e,t){super(t?`cannot add items to empty list at "${e.join(".")}" \u2014 ${t}`:`cannot add items to empty list at "${e.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=e}},fe=class extends Error{constructor(e){super(`cannot write to read-only DOM property "${e}"`),this.name="RuleTargetReadOnly",this.target=e}},Be=class extends Error{constructor(e){super(`write refused: ${e.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=e}};function qe(e){return e.reduce((t,r)=>typeof r=="number"?`${t}[${r}]`:t?`${t}.${r}`:String(r),"")||"(root)"}var He=class extends Error{constructor(e){super(`write did not round-trip at "${qe(e)}"`),this.name="WriteNotRoundTripped",this.path=e}},We=class extends Error{constructor(e){super(`no <script data-rules-name~="${e}"> rules tag in this document`),this.name="NoRulesTag",this.token=e}},Ve=class extends Error{constructor(e,t){super(`write rejected: ${e.length} unknown key(s), ${t.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=e,this.unmatched=t}};function de(e){let t=0,r=null,l=-1;for(let n=0;n<e.length;n++){let o=e[n];o==="\\"?n++:r?o===r&&(r=null):o==='"'||o==="'"?r=o:o==="["||o==="("?t++:o==="]"||o===")"?t>0&&t--:o==="@"&&t===0&&(l=n)}return l}function pe(e){let t=0,r=null,l=-1,n=!1;for(let o=0;o<e.length;o++){let i=e[o];i==="\\"?o++:r?i===r&&(r=null):i==='"'||i==="'"?r=i:i==="["||i==="("?t++:i==="]"||i===")"?t>0&&t--:t===0&&i===">"?l=o:t===0&&i===","&&(n=!0)}return n||l===-1||!Fe(e,l+1)?null:e.slice(0,l).trim()||null}function Fe(e,t){let r=t,l=e.replace(/\s+$/,"").length;for(;r<l&&/\s/.test(e[r]);)r++;let n=0,o=null;for(;r<l;r++){let i=e[r];if(i==="\\")r++;else if(o)i===o&&(o=null);else if(i==='"'||i==="'")o=i;else if(i==="["||i==="(")n++;else if(i==="]"||i===")")n>0&&n--;else if(n===0&&(i==="+"||i==="~"||/\s/.test(i)))return!1}return!0}var ze=/^--[A-Za-z0-9_-]+$/;function he(e){return typeof e=="string"&&ze.test(e)}function me(e){let t=[],r=[],l=null,n=0;for(let o=0;o<e.length;o++){let i=e[o];if(l){i==="\\"?o++:i===l&&(l=null);continue}if(i==="/"&&e[o+1]==="*"){let a=e.indexOf("*/",o+2);o=a===-1?e.length:a+1;continue}i==='"'||i==="'"?l=i:i==="("?r.push(")"):i==="["?r.push("]"):i==="{"?r.push("}"):(i===")"||i==="]"||i==="}")&&r[r.length-1]===i?r.pop():i===";"&&r.length===0&&(t.push(e.slice(n,o)),n=o+1)}return t.push(e.slice(n)),t}function _e(e){let t="",r=null;for(let l=0;l<e.length;l++){let n=e[l];if(r){t+=n,n==="\\"&&l+1<e.length?t+=e[++l]:n===r&&(r=null);continue}if(n==="/"&&e[l+1]==="*"){let o=e.indexOf("*/",l+2);l=o===-1?e.length:o+1,t+=" ";continue}(n==='"'||n==="'")&&(r=n),t+=n}return t}function ye(e){e=_e(e);let t=e.indexOf(":");if(t===-1)return null;let r=e.slice(0,t).trim(),l=e.slice(t+1).trim(),n=/!\s*important\s*$/i.exec(l);return n&&(l=l.slice(0,n.index).trim()),{name:r,value:l,important:!!n}}function ge(e,t){if(e==null)return null;let r=null;for(let l of me(String(e))){let n=ye(l);!n||n.name!==t||(!r||n.important||!r.important)&&(r=n)}return r?r.value:null}function Je(e,t,r){let l=e==null?"":String(e),n=r==null||r==="",o=me(l),i=o.map(ye),a=i.some(f=>f&&f.name===t&&f.important),s=[],u=!1;o.forEach((f,d)=>{let h=i[d];if(!h||h.name!==t){s.push(f);return}if(n||u)return;let m=/^\s*/.exec(f)[0];s.push(`${m}${t}: ${r}${a?" !important":""}`),u=!0});let c=s.join(";");if(!n&&!u){let f=c.trimEnd();c=f===""?`${t}: ${r}`:`${f}${f.endsWith(";")?" ":"; "}${t}: ${r}`}return c.trim()===""?null:c}function Ge(e,t,r,l){let n=e.attr(t,"style");if((ge(n,r)??"")===l)return;let o=Je(n,r,l);o==null?e.removeAttr(t,"style"):e.attr(t,"style",o)}function we(e,t,r,l={}){if(Object.prototype.hasOwnProperty.call(l,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return P(e,t,r,{depth:0,path:[]},l)}function P(e,t,r,l,n){if(l.depth>j)throw new V(l.path);if(typeof r=="string")return Ye(e,t,r,l,n);if(Array.isArray(r)){let[o,i]=r,a=e.find(t,o,n);return ve(n,l,a),a.map((s,u)=>P(e,s,i,{depth:l.depth+1,path:[...l.path,u]},n))}if(typeof r=="object"&&r!==null){let o={};for(let[i,a]of Object.entries(r))o[i]=P(e,t,a,{depth:l.depth+1,path:[...l.path,i]},n);return o}return null}function Ye(e,t,r,l,n){if(r.endsWith("[]")){let a=r.slice(0,-2),s=e.find(t,a,n);return ve(n,l,s),s.map(u=>e.text(u))}if(r.startsWith("@"))return X(e,t,r.slice(1));let o=de(r);if(o!==-1){let a=r.slice(0,o),s=r.slice(o+1),u=a?e.find(t,a,n):[t];return u.length===0?null:X(e,u[0],s)}if(r===".")return e.text(t);let i=e.find(t,r,n);return i.length===0?null:e.text(i[0])}function ve(e,t,r){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),r)}catch(l){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,l)}}function X(e,t,r){if(he(r))return ge(e.attr(t,"style"),r);if(Me.has(r)){let n=e.prop(t,r);return n==null?null:String(n)}return e.attr(t,r)??null}function Xe(e,t,r,l){let n=e.length,o=t.length,i=new Array(n).fill(-1);if(l){let p=new Set;for(let y=0;y<n;y++){let g=l[y];!(g>=0&&g<o)||p.has(g)||(i[y]=g,p.add(g))}}if(n===0||o===0)return i;let a=e.map(p=>K(p,r)),s=t.map(p=>K(p,r)),u=new Array(o).fill(!1);for(let p of i)p>=0&&(u[p]=!0);let c=new Map;s.forEach((p,y)=>{u[y]||c.set(p,c.has(p)?-1:y)});let f=new Map;a.forEach((p,y)=>{i[y]>=0||f.set(p,(f.get(p)||0)+1)}),a.forEach((p,y)=>{if(i[y]>=0||f.get(p)!==1)return;let g=c.get(p);g===void 0||g===-1||u[g]||(i[y]=g,u[g]=!0)});let d=[];for(let p=0;p<n;p++)i[p]<0&&d.push(p);let h=[];for(let p=0;p<o;p++)u[p]||h.push(p);if(d.length===0||h.length===0)return i;let m=n*o+1,w=Ke(e,t,r),v=(p,y)=>w(p,y)*m+Math.abs(p-y);for(let[p,y]of Ze(d,h,v))i[p]=y;return i}var be=e=>typeof e=="object"&&e!==null;function K(e,t){if(!be(t))return e==null?" null":String(e);let r=Object.keys(t);return JSON.stringify(r.map(l=>{let n=JSON.stringify(e?.[l]);return n===void 0?" undef":n}))}function Ke(e,t,r){if(!be(r))return(a,s)=>e[a]===t[s]?0:1;let l=Object.keys(r),n=a=>l.map(s=>JSON.stringify(a?.[s])),o=e.map(n),i=t.map(n);return(a,s)=>{let u=o[a],c=i[s],f=0;for(let d=0;d<l.length;d++)u[d]!==c[d]&&f++;return f}}function Ze(e,t,r){return e.length<=t.length?Z(e,t,r,!1):Z(t,e,(l,n)=>r(n,l),!0)}function Z(e,t,r,l){let n=e.length,o=t.length,i=[];for(let f=0;f<=n;f++)i.push(new Float64Array(o+1).fill(1/0));let a=[];for(let f=0;f<=n;f++)a.push(new Uint8Array(o+1));for(let f=0;f<=o;f++)i[n][f]=0;for(let f=n-1;f>=0;f--)for(let d=o-1;d>=0;d--){let h=r(e[f],t[d])+i[f+1][d+1],m=i[f][d+1];h<=m?(i[f][d]=h,a[f][d]=1):i[f][d]=m}let s=[],u=0,c=0;for(;u<n&&c<o;)a[u][c]&&(s.push(l?[t[c],e[u]]:[e[u],t[c]]),u++),c++;return s}function xe(e,t,r,l,n,o,i,a={}){let s=e.find(t,r,a);if(n.length===0){s.forEach(b=>e.remove(b)),D(a,"onRowsApplied",o.path,[]);return}let u=n.length>s.length,c=s[0]||null;if(u&&!c&&(c=rt(e,t,r,a),!c))throw new R(o.path);let f=s.map(b=>tt(e,b,l,a)),d=null;if(u&&c){d=e.clone(c),a.templateAttr&&e.removeAttr(d,a.templateAttr);let b=e.stripIds(d);b>0&&console.warn(`[hyper-html-api] stripped ${b} id attribute(s) from cloned template at "${o.path.join(".")||"(root)"}"`)}let h=Xe(n,f,l,Qe(e,s,n,o,a)),m=s.length>0?e.parent(s[0]):it(e,t,r,c,o,a),w=s.length>0?Ae(e,m,s[0]):0,v=ut(e,s),p=new Set,y=[],g=n.map((b,E)=>{let N=h[E];if(N>=0)return p.add(N),y.push(!1),s[N];y.push(!0);let T=e.clone(d);return e.stripIds(T),T});s.forEach((b,E)=>{p.has(E)||e.remove(b)}),v?st(e,m,w,g,y):ct(e,g,y,m,w),et(e,g,l,n,o,i,a),D(a,"onRowsApplied",o.path,g)}function D(e,t,r,l){if(typeof e[t]=="function")try{return e[t](r.slice(),l)}catch(n){console.warn(`[hyper-html-api] ${t} threw at "${r.join(".")||"(root)"}"`,n);return}}function Qe(e,t,r,l,n){let o=D(n,"identifyRows",l.path,r);if(!Array.isArray(o))return null;let i=new Array(r.length).fill(-1),a=new Set,s=new Map(t.map((u,c)=>[e.identity(u),c]));for(let u=0;u<r.length;u++){if(!o[u])continue;let c=s.get(e.identity(o[u]));c===void 0||a.has(c)||(i[u]=c,a.add(c))}return i}function et(e,t,r,l,n,o,i){t.forEach((a,s)=>{if(r===null){let u=l[s],c=u==null?"":String(u);e.text(a)!==c&&e.text(a,c)}else{let u=o(e,a,r,l[s],{depth:n.depth+1,path:[...n.path,s]},i);u&&u!==a&&(t[s]=u)}})}function tt(e,t,r,l){return r===null?e.text(t):we(e,t,r,l.onRowsRead?{...l,onRowsRead:void 0}:l)}function Ae(e,t,r){let l=e.children(t);for(let n=0;n<l.length;n++)if(e.sameNode(l[n],r))return n;return-1}function rt(e,t,r,l){if(!l.templateAttr)return null;let n=/^\s*:scope\s*>\s*/.test(r),o=new RegExp(":not\\(\\["+l.templateAttr.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")+"\\]\\)","g"),i=r.replace(/^\s*:scope\s*>\s*/,"").replace(o,""),a=n?nt(i):0,s=pe(i),u=t;for(;u;){let c=e.find(u,i,{includeRulesTag:!1,templateAttr:null});for(let f of c)if(e.attr(f,l.templateAttr)!=null&&!(n&&!ot(e,t,f,a))&&!(s&&!e.matches(e.parent(f),s)))return f;u=e.parent(u)}return null}function nt(e){let t=0,r=null,l=1;for(let n=0;n<e.length;n++){let o=e[n];if(o==="\\")n++;else if(r)o===r&&(r=null);else if(o==='"'||o==="'")r=o;else if(o==="["||o==="(")t++;else if(o==="]"||o===")")t>0&&t--;else if(t===0&&o===">")l++;else{if(t===0&&(o==="+"||o==="~"))return null;if(t===0&&/\s/.test(o)){if(!lt(e,n))return null;for(;n+1<e.length&&/\s/.test(e[n+1]);)n++}}}return l}function lt(e,t){let r=t;for(;r<e.length&&/\s/.test(e[r]);)r++;let l=t>0?e[t-1]:"",n=r<e.length?e[r]:"";return Q(l)||Q(n)}function Q(e){return e===">"||e==="+"||e==="~"}function ot(e,t,r,l){if(l===null)return!0;let n=r;for(let s=0;s<l;s++)if(n=e.parent(n),!n)return!1;let o=e.prop(t,"tagName");if(!o)return!0;let i=e.prop(n,"tagName");if(!i||String(i).toLowerCase()!==String(o).toLowerCase())return!1;let a=new Set(ee(e,n));return ee(e,t).every(s=>a.has(s))}function ee(e,t){let r=e.attr(t,"class");return r?String(r).split(/\s+/).filter(Boolean):[]}function it(e,t,r,l,n,o){let i=e.parent(l);if(i&&at(e,t,i)&&!re(e,i,o))return i;let a=pe(r);if(!a)throw new R(n.path,`the list selector "${r}" names no container to hold the new rows \u2014 write it as "container > row" (for example "ol.comments > li") so the cloned row lands in the list`);let s=(a===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,a,o)).filter(u=>!re(e,u,o));if(s.length===0)throw new R(n.path,`no container matching "${a}" inside this context to hold the new rows`);if(s.length>1)throw new R(n.path,`"${a}" matches ${s.length} containers inside this context, so the new rows have no single destination`);return s[0]}function at(e,t,r){let l=r;for(;l;){if(e.sameNode(l,t))return!0;l=e.parent(l)}return e.parent(t)?!1:e.find(t,"*",{includeRulesTag:!0,templateAttr:null}).some(n=>e.sameNode(n,r))}var te=["no-data","editor-ui"];function re(e,t,r){let l=t;for(;l;){if(r.templateAttr&&e.attr(l,r.templateAttr)!=null||te.some(o=>e.attr(l,o)!=null))return!0;let n=e.attr(l,"clay");if(n&&n.split(/\s+/).some(o=>te.includes(o)))return!0;l=e.parent(l)}return!1}function st(e,t,r,l,n){let o=e.children(t),i=o.map(s=>e.identity(s)),a=!1;l.forEach((s,u)=>{let c=e.identity(s),f=r+u;if(i[f]===c)return;if(!n[u]){let h=i.indexOf(c);h!==-1&&(i.splice(h,1),o.splice(h,1))}let d=Math.min(f,o.length);d<o.length?e.insertBefore(o[d],s):o.length?a?e.insertAfter(o[o.length-1],s):(e.insertAt(t,s,f),a=!0):e.insertAt(t,s,0),i.splice(d,0,c),o.splice(d,0,s)})}function ut(e,t){if(t.length<=1)return!0;let r=e.parent(t[0]);if(!r)return!1;let l=new Map(e.children(r).map((o,i)=>[e.identity(o),i])),n=[];for(let o of t){let i=l.get(e.identity(o));if(i===void 0)return!1;n.push(i)}return n.sort((o,i)=>o-i),n[n.length-1]-n[0]===n.length-1}function ct(e,t,r,l,n){let o=null,i=n;for(let a=0;a<t.length;a++){if(!r[a]){o=t[a];continue}let s=o?e.parent(o):l;if(!s)continue;let u=o?Ae(e,s,o)+1:i++;e.insertAt(s,t[a],u),o=t[a]}}function ft(e,t,r,l,n={}){if(Object.prototype.hasOwnProperty.call(n,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");let o=[];if(B(r,l,[],o),o.length)throw new ce(o);L(e,t,r,l,{depth:0,path:[]},n)}function L(e,t,r,l,n,o={}){if(n.depth>j)throw new V(n.path);if(l===void 0)return t;if(typeof r=="string")return dt(e,t,r,l,n,o);if(Array.isArray(r)){let[i,a]=r;return xe(e,t,i,a,l,n,L,o),t}if(typeof r=="object"&&r!==null){for(let[i,a]of Object.entries(r)){let s=L(e,t,a,l==null?l:l[i],{depth:n.depth+1,path:[...n.path,i]},o);s&&s!==t&&(t=s)}return t}return t}function dt(e,t,r,l,n,o){if(r.endsWith("[]")){let s=r.slice(0,-2);return xe(e,t,s,null,l,n,L,o),t}if(r.startsWith("@"))return le(e,t,r.slice(1),l);let i=de(r);if(i!==-1){let s=r.slice(0,i),u=r.slice(i+1),c=s?e.find(t,s,o):[t];return c.length===0||le(e,c[0],u,l),t}if(r===".")return ne(e,t,l),t;let a=e.find(t,r,o);return a.length===0||ne(e,a[0],l),t}function ne(e,t,r){let l=r==null?"":String(r);e.text(t)!==l&&e.text(t,l)}function pt(e,t,r,l){if(e.styleVar){e.styleVar(t,r,l);return}Ge(e,t,r,l)}function le(e,t,r,l){if(he(r))return pt(e,t,r,l==null?"":String(l).trim()),t;if(Ie.has(r)){let n=e.prop(t,r);if(n===l||n!=null&&l!=null&&String(n)===String(l))return t;throw new fe(r)}if(r==="outerHTML"){let n=l==null?"":String(l);return e.replaceWith(t,n)}if(Ue.has(r)){let n=Pe(r,l);return e.prop(t,r)!==n&&e.prop(t,r,n),t}if(l==null)e.attr(t,r)!=null&&e.removeAttr(t,r);else{let n=String(l);e.attr(t,r)!==n&&e.attr(t,r,n)}return t}function B(e,t,r,l){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((n,o)=>{typeof n=="object"&&n!==null&&l.push({path:S([...r,o]),expected:"scalar",got:k(n)})}):l.push({path:S(r),expected:"array",got:k(t)});return}t!==null&&typeof t=="object"&&l.push({path:S(r),expected:"scalar",got:k(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){l.push({path:S(r),expected:"array",got:k(t)});return}let n=e[1];t.forEach((o,i)=>B(n,o,[...r,i],l));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){l.push({path:S(r),expected:"object",got:k(t)});return}for(let[n,o]of Object.entries(e))B(o,t[n],[...r,n],l)}}}function k(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function S(e){return e.join(".")}function ht(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function r(n){let o=[],i=0;for(;i<n.length;){let a=n[i];if(/\s/.test(a)){i++;continue}if("{}".includes(a)){o.push({type:a,value:a}),i++;continue}if(a==="["){let f=!1,d=i+1;for(;d<n.length&&/\s/.test(n[d]);)d++;if(d<n.length&&/[a-zA-Z_]/.test(n[d])&&(f=!0),!f){o.push({type:a,value:a}),i++;continue}}if(a==="]"){o.push({type:a,value:a}),i++;continue}if(a===":"){o.push({type:t.COLON,value:a}),i++;continue}if(a===","){o.push({type:t.COMMA,value:a}),i++;continue}if(a==='"'||a==="'"){let f=a,d=i+1;for(;d<n.length&&n[d]!==f;)n[d]==="\\"&&d++,d++;o.push({type:t.STRING,value:n.substring(i+1,d),quoted:!0,sourceQuote:f}),i=d+1;continue}let s=i,u;for(;s<n.length&&!/[{},]/.test(n[s]);)if(n[s]===":"){let f=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],d=!1;for(let h of f){let m=h.substring(1);if(n.substring(s+1,s+1+m.length)===m){d=!0,s+=m.length;break}}if(!d)break}else if(n[s]==="["){for(s++;s<n.length&&n[s]!=="]";){if(n[s]==='"'||n[s]==="'"){let f=n[s];for(s++;s<n.length&&n[s]!==f;)n[s]==="\\"&&s++,s++}s++}s<n.length&&n[s]==="]"&&s++}else s++;u=n.substring(i,s);let c=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(u)?c=t.NUMBER:u==="true"||u==="false"||u==="null"?c=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(u)&&(c=t.SELECTOR),o.push({type:c,value:u,quoted:!1}),i=s}return o}function l(n){let o="";for(let i=0;i<n.length;i++){let a=n[i];if("{}".includes(a.type)||"[]".includes(a.type)){o+=a.value;continue}if(a.type===t.COLON){o+=a.value;continue}if(a.type===t.COMMA){let s=n[i+1];if(s&&(s.type==="}"||s.type==="]"))continue;o+=a.value;continue}if(a.type===t.STRING&&a.quoted){let s=a.value;a.sourceQuote==="'"&&(s=s.replace(/\\'/g,"'"),s=s.replace(/(\\*)"/g,(u,c)=>c.length%2===0?c+'\\"':u)),o+=`"${s}"`;continue}if(a.type===t.NUMBER||a.type===t.BOOLEAN){o+=a.value;continue}if(a.type===t.SELECTOR||a.type===t.IDENTIFIER){o+=`"${a.value}"`;continue}o+=`"${a.value}"`}return o}try{let n=r(e),o=l(n);return JSON.parse(o)}catch(n){throw new se("Invalid extraction rules syntax: "+n.message,n)}}var mt="1";var or=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),ir=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),yt=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);var ar=Object.freeze({refusedRuleForms:["innerHTML","outerHTML"],refusedTargets:["script","style","template","noscript","iframe","object","embed","xmp","plaintext","noembed","noframes","meta","link","base","animate","set","animatemotion","animatetransform"],refusedAttributes:["style","srcdoc","is","http-equiv","sandbox","allow","nonce","integrity","charset","htmlclaytoken","htmlclayid","data-rules-name","data-rules-version","clay","contenteditable",...yt],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"],customPropertyValues:Object.freeze({maxLength:200,refusedCharacters:[";","{","}","<",">","\\"],refusedFunctions:["url","src","image","image-set","-webkit-image-set","cross-fade","element","expression","paint"]})});function gt(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function wt(e){return e?(e.nodeType===9||e.nodeType,e):null}function oe(e,t,r){!e||e.nodeType!==1||(t==="value"&&e.tagName==="INPUT"?e.value=r===null?"":r:t==="checked"&&e.tagName==="INPUT"?e.checked=r!==null:t==="selected"&&e.tagName==="OPTION"&&(e.selected=r!==null))}function vt(e,t){e&&e.tagName==="TEXTAREA"&&(e.value=t)}function bt(e){if(!e||e.nodeType!==1)return;let t=[e,...e.querySelectorAll?e.querySelectorAll("textarea, input, option"):[]];for(let r of t)if(r.tagName==="TEXTAREA")r.value=r.defaultValue;else if(r.tagName==="INPUT"){let l=r.type;l!=="file"&&l!=="checkbox"&&l!=="radio"&&(r.value=r.defaultValue),r.checked=r.defaultChecked}else r.tagName==="OPTION"&&(r.selected=r.defaultSelected)}var xt={semanticExclude:!0,find(e,t,r={}){let l=wt(e);if(!l||!l.querySelectorAll)return[];let n=Array.from(l.querySelectorAll(t));r.includeRulesTag||(n=n.filter(a=>!gt(a)));let o=[];r.skip&&o.push(r.skip);let i=r.templateAttr===null?null:r.templateAttr||"cms-template";if(i&&o.push("["+i+"]"),o.length){let a=o.join(", ");n=n.filter(s=>!s.closest||!s.closest(a))}return n},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},matches(e,t){return!!(e&&e.matches)&&e.matches(t)},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t,vt(e,t)},attr(e,t,r){if(r===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,r),oe(e,t,r)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),oe(e,t,null)},prop(e,t,r){if(r===void 0){let l=e?e[t]:void 0;return l!==void 0?l:null}e[t]=r},clone(e){let t=e.cloneNode(!0);return bt(t),t},insertAt(e,t,r){let l=e.children[r]||null;e.insertBefore(t,l)},insertBefore(e,t){e.parentNode.insertBefore(t,e)},insertAfter(e,t){e.parentNode.insertBefore(t,e.nextSibling)},identity(e){return e||null},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let r=e.ownerDocument.createElement("template");r.innerHTML=t;let l=r.content.firstElementChild;if(!l)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(l,e),l},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(r=>{r.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};var C=xt;var At="hha:upgrade-check:";function x(e,t){let r=e.querySelector(`meta[name="${t}"]`),l=r?r.getAttribute("content"):null;return l&&l.trim()?l.trim():null}function ie(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function Tt(e,t){let r=ie(e),l=ie(t);if(!r||!l)return!1;let n=Math.max(r.length,l.length);for(let o=0;o<n;o++){let i=r[o]||0,a=l[o]||0;if(i!==a)return i>a}return!1}function Ot(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Et(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function Nt({force:e=!1,doc:t,loc:r,fetchFn:l,now:n,ttlMs:o=864e5}={}){if(t=t||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),l=l||(d=>fetch(d)),n=n??Date.now(),!t)return null;let i=x(t,"hyper-source");if(!i)return null;let a=x(t,"hyper-version"),s;try{s=new URL(i,r?r.href:void 0)}catch{return null}if(r&&s.origin===r.origin&&s.pathname===r.pathname)return null;let u=`${At}${s.href}:${a||"none"}`,c,f=e?null:Ot(u);if(f&&typeof f.checkedAt=="number"&&n-f.checkedAt<o)c=f.sourceVersion;else{try{let d=await l(s.href);if(!d.ok)throw new Error(`HTTP ${d.status}`);let h=await d.text(),m=new DOMParser().parseFromString(h,"text/html");c=x(m,"hyper-version")}catch{c=null}Et(u,{checkedAt:n,sourceVersion:c})}return c?{available:Tt(c,a||"0.0.0"),currentVersion:a,sourceVersion:c,sourceUrl:s.href}:null}var kt="script[data-rules-name]";function St(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function Te(e,t){let r=e.find(t,kt,{includeRulesTag:!0}),l=new Set,n=[];for(let o of r){let i=St(e.attr(o,"data-rules-name"));if(!i)continue;if(l.has(i)){console.warn(`hyper-html-api: duplicate rules tag name "${i}"; using the first.`);continue}let a=e.attr(o,"data-rules-version");if(a!==mt)throw new ue(a);l.add(i),n.push({name:i,rules:ht(e.text(o))})}return n}function Oe(e,t){let r={};for(let{name:l,rules:n}of Te(e,t))r[l]=we(e,t,n);return r}function Rt(e){let t=e||document,r=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Oe(C,t),version:x(r,"hyper-version")}}var ae=class extends Error{constructor(e,t){super(`could not fetch upgrade source: ${e}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=e,this.cause=t}},$t=class extends Error{constructor(e){super(`upgrade source has no rules tags; refusing to drop all existing data: ${e}`),this.name="UpgradeSourceHasNoRules",this.sourceUrl=e}},q=class extends Error{constructor(e,t){super(e),this.name="UpgradeTransformInvalid",this.cause=t}},Ct=class extends Error{constructor(e){super(`found ${e} script[type="text/hyper-upgrade"] tags; only one is allowed per document.`),this.name="UpgradeMultipleTransforms",this.count=e}},Lt="text/hyper-upgrade";function jt(e,t){let r=e.find(t,`script[type="${Lt}"]`);if(r.length===0)return null;if(r.length>1)throw new Ct(r.length);return e.text(r[0])||null}var Mt=new Function("url","return import(url)");async function Ut(e){let t=new Blob([e],{type:"text/javascript"}),r=URL.createObjectURL(t),l;try{l=await Mt(r)}catch(n){throw new q(`transform failed to load: ${n&&n.message?n.message:n}`,n)}finally{URL.revokeObjectURL(r)}if(typeof l.default!="function")throw new q("transform must `export default` a function");return l.default}function Ee(e,t){let r={carriedOver:0,discarded:0,listItems:0},l=H(t,e,r);return W(t,e,r),{data:l,summary:r}}function H(e,t,r){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(r.listItems+=t.length,r.carriedOver+=t.length,t):void 0:t==null||typeof t=="object"?void 0:(r.carriedOver++,t);if(Array.isArray(e)){let[,l]=e;return Array.isArray(t)?(r.listItems+=t.length,t.map(n=>H(l,n,r))):void 0}if(typeof e=="object"&&e!==null){let l={};for(let[n,o]of Object.entries(e)){let i=H(o,t?.[n],r);i!==void 0&&(l[n]=i)}return l}}function W(e,t,r){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let l=new Set(Object.keys(e));for(let n of Object.keys(t))l.has(n)?W(e[n],t[n],r):r.discarded+=$(t[n]);return}if(Array.isArray(e)&&Array.isArray(t)){let l=e[1];t.forEach(n=>W(l,n,r));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(r.discarded+=$(t))}}function $(e){return e==null?0:Array.isArray(e)?e.reduce((t,r)=>t+$(r),0):typeof e=="object"?Object.values(e).reduce((t,r)=>t+$(r),0):1}function It(e,t,r){let l=Te(e,t),n={carriedOver:0,discarded:0,listItems:0},o={},i=new Set;for(let{name:a,rules:s}of l){if(i.add(a),!Object.prototype.hasOwnProperty.call(r,a)){o[a]={carriedOver:0,discarded:0,listItems:0};continue}let{data:u,summary:c}=Ee(r[a],s);ft(e,t,s,u),o[a]=c,n.carriedOver+=c.carriedOver,n.discarded+=c.discarded,n.listItems+=c.listItems}for(let a of Object.keys(r))i.has(a)||(n.discarded+=$(r[a]));return{totals:n,byName:o,rulesTagCount:l.length}}async function Pt({sourceUrl:e,dataByName:t,fromVersion:r,doc:l,loc:n,fetchFn:o}={}){if(l=l||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(p=>fetch(p)),!l)throw new Error("upgrade.run requires a document context");if(e=e||x(l,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let i=new URL(e,n?n.href:void 0);r=r!==void 0?r:x(l,"hyper-version"),t=t||Oe(C,l);let a;try{a=await o(i.href)}catch(p){throw new ae(i.href,p)}if(!a.ok)throw new ae(i.href,new Error(`HTTP ${a.status}`));let s=await a.text(),u=new DOMParser().parseFromString(s,"text/html"),c=x(u,"hyper-version"),f=t,d=!1,h=jt(C,u);if(h){let p=await(await Ut(h))(f,{fromVersion:r,toVersion:c});if(!p||typeof p!="object"||Array.isArray(p))throw new q("transform must return a plain object map of { rulesName: data }");f=p,d=!0}let{totals:m,byName:w,rulesTagCount:v}=It(C,u,f);if(v===0&&Object.keys(f).length>0)throw new $t(i.href);return{html:Bt(u),fromVersion:r,toVersion:c,summary:{transformApplied:d,totals:m,byName:w}}}function Dt(e){for(let t of e.querySelectorAll("input")){let r=(t.getAttribute("type")||"").toLowerCase();r!=="file"&&(r==="checkbox"||r==="radio"?t.checked!==t.hasAttribute("checked")&&t.toggleAttribute("checked",t.checked):t.value!==(t.getAttribute("value")??"")&&t.setAttribute("value",t.value))}for(let t of e.querySelectorAll("textarea"))t.value!==t.textContent&&(t.textContent=t.value);for(let t of e.querySelectorAll("select")){let r=[...t.options];if(!t.multiple){let l=r.findIndex(n=>n.hasAttribute("selected"));if(t.selectedIndex===l||l===-1&&t.selectedIndex<=0)continue}for(let l of r)l.selected!==l.hasAttribute("selected")&&l.toggleAttribute("selected",l.selected)}}function Bt(e){return Dt(e),`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
2
2
  `+e.documentElement.outerHTML}var M={checkForUpdate:Nt,run:Pt,extractAll:Rt,shapeMatch:Ee};var A="The new version could not be downloaded. Nothing was changed.",U="The upgrade could not be saved. Nothing was changed.",Se="This document changed somewhere else. Reload and try again.",qt="Something else is changing this document. Nothing was changed.",Ht="This document does not say which parts are its data, so it cannot be upgraded safely. Nothing was changed.",Wt="The new version has no place for this page's content. Nothing was changed.";async function Vt(e){let t=globalThis.crypto&&globalThis.crypto.subtle;if(!t)return null;let r=await t.digest("SHA-256",e);return[...new Uint8Array(r)].map(l=>l.toString(16).padStart(2,"0")).join("")}async function Ne(e,t){try{let r=await e(t,{credentials:"omit"});return!r||!r.ok?null:r}catch{return null}}function Ft(e,t,r){if(e&&typeof e.latestUrl=="string"&&e.latestUrl)return e.latestUrl;let l=x(t,"hyper-source");if(!l)return null;try{let n=new URL(l,r?r.href:void 0);return n.pathname=n.pathname.replace(/\.html$/,".json"),n.href}catch{return null}}function zt(e){let t=x(e,"clay-template");if(!t)return null;let[r,l]=t.split(/\s+/);return r&&l?{id:r,variant:l}:null}function I(e,t="",r=[]){if(Array.isArray(e)){for(let l of e)I(l,`${t}[]`,r);return r}if(e&&typeof e=="object"){for(let[l,n]of Object.entries(e))I(n,t?`${t}.${l}`:l,r);return r}return e!=null&&r.push({path:t,value:e}),r}function _t(e,t){let r=[e];for(let l of String(t).split(".")){let n=l.endsWith("[]"),o=n?l.slice(0,-2):l,i=[];for(let a of r){let s=o?a?.[o]:a;n?Array.isArray(s)&&i.push(...s):i.push(s)}r=i}return r}function Jt(e,t,r={}){let l=new Map;for(let{path:o,value:i}of I(t)){let a=`${o}\0${String(i)}`;l.set(a,(l.get(a)||0)+1)}let n=[];for(let{path:o,value:i}of I(e)){let a=`${o}\0${String(i)}`;if(l.get(a)>0){l.set(a,l.get(a)-1);continue}let s=r[o];typeof s=="string"&&_t(t,s).some(u=>u===i)||n.push({path:o,value:i})}return n}async function Gt(e){let t=new Blob([e],{type:"text/javascript"}),r=URL.createObjectURL(t);try{return await new Function("url","return import(url)")(r)}finally{URL.revokeObjectURL(r)}}async function Yt(e){let r=new DOMParser().parseFromString(e,"text/html").querySelector('script[type="text/hyper-upgrade"]');if(!r)return{};let l=await Gt(r.textContent||"");return l&&l.renames&&typeof l.renames=="object"?l.renames:{}}var ke='script[clay~="live"][merge]';function Xt(e,t,r){let l=t.querySelector("article[data-page]");if(!l)return null;l.replaceWith(t.importNode(r,!0));for(let o of e.querySelectorAll(ke)){let i=o.getAttribute("merge");if(i!=="page"&&!i.startsWith("page."))continue;let a=t.importNode(o,!0),s=[...t.querySelectorAll(ke)].find(u=>u.getAttribute("merge")===i);s?s.replaceWith(a):t.querySelector("article[data-page]").after(a)}return(t.doctype?`<!DOCTYPE ${t.doctype.name}>
3
- `:"")+t.documentElement.outerHTML}async function Re(e,{doc:t=document,loc:r=location,fetchFn:l=(n,o)=>fetch(n,o)}={}){if((typeof window<"u"&&window.clay||{}).isDraftMode)return{ok:!1,code:"draft"};if(!e||typeof e.version!="string")return{ok:!1,code:"unavailable",message:A};let o=Ft(e,t,r);if(!o)return{ok:!1,code:"unavailable",message:A};let i=await Ne(l,o);if(!i)return{ok:!1,code:"unavailable",message:A};let a;try{a=await i.json()}catch{return{ok:!1,code:"unavailable",message:A}}if(!a||typeof a!="object")return{ok:!1,code:"unavailable",message:A};let s=zt(t);if(!s||a.id!==s.id||a.variant!==s.variant)return{ok:!1,code:"template",message:"This upgrade is for a different document."};let u=x(t,"hyper-version");if(!u||typeof a.version!="string"||!J(a.version,u))return{ok:!1,code:"not-newer",message:"There is no newer version to install."};if(typeof a.html!="string"||!a.html)return{ok:!1,code:"unavailable",message:A};let c;try{c=new URL(a.html,o).href}catch{return{ok:!1,code:"unavailable",message:A}}if(!/^https:\/\/hyperclay\.com\/templates\//.test(c))return{ok:!1,code:"source",message:"This upgrade is not from the template host."};let f=await Ne(l,c);if(!f)return{ok:!1,code:"unavailable",message:A};let d;try{d=await f.text()}catch{return{ok:!1,code:"unavailable",message:A}}let h=await Vt(new TextEncoder().encode(d));if(!h||h!==String(a.sha256||"").toLowerCase())return{ok:!1,code:"unavailable",message:A};let m,w;try{w=await Yt(d),m=await M.run({sourceUrl:c,doc:t,loc:r,fromVersion:u,fetchFn:async()=>({ok:!0,status:200,text:async()=>d})})}catch(T){return{ok:!1,code:"transform",message:T&&T.message?T.message:A}}let v=new DOMParser().parseFromString(m.html,"text/html"),p=M.extractAll(t).dataByName,y=t.querySelector("article[data-page]");if(!y&&!Object.keys(p||{}).length)return{ok:!1,code:"undeclared",message:Ht};let g=m.html;if(y){let T=Xt(t,v,y);if(!T)return{ok:!1,code:"lost",lost:[],discarded:0,message:Wt};g=T}let b=M.extractAll(v).dataByName,E=Jt(p,b,w),N=m.summary&&m.summary.totals&&m.summary.totals.discarded||0;return E.length||N>0?{ok:!1,code:"lost",lost:E,discarded:N,message:Kt(E,N)}:{ok:!0,html:g,version:m.toVersion||a.version}}function Kt(e,t){let r=e.slice(0,5).map(({path:n})=>n),l=e.length>r.length?` and ${e.length-r.length} more`:"";return r.length?`This upgrade would lose data: ${r.join(", ")}${l}. Nothing was changed.`:`This upgrade would lose ${t} value${t===1?"":"s"}. Nothing was changed.`}function Zt(e){let t=e&&e.state;if(t==="conflict")return{ok:!1,code:"conflict",message:Se};let r=e&&e.message?e.message:"The document could not be saved.";return{ok:!1,code:"flush",state:t||"failed",message:r}}async function $e(e,{doc:t=document,loc:r=location,fetchFn:l=(s,u)=>fetch(s,u),clay:n=typeof window<"u"?window.clay:null,reload:o=()=>window.location.reload(),replace:i=null,etag:a}={}){if((n||{}).isDraftMode)return{ok:!1,code:"draft"};let u=z("upgrade");if(!u)return{ok:!1,code:"busy",message:qt};try{return await Qt(e,{doc:t,loc:r,fetchFn:l,clay:n,reload:o,replace:i,etag:a})}finally{_(u)}}async function Qt(e,{doc:t,loc:r,fetchFn:l,clay:n,reload:o,replace:i,etag:a}){let s=n||{};if(s.isEditMode&&s.save&&typeof s.save.flush=="function"){let h;try{h=await s.save.flush()}catch(m){return Zt(m)}if(h&&typeof h.state=="string"&&h.state!=="saved"&&h.state!=="clean"&&h.state!=="view")return{ok:!1,code:"flush",state:h.state,message:"This document has changes that could not be saved. Nothing was changed."}}let u=t;if(s.isEditMode&&typeof s.getHTML=="function")try{u=new DOMParser().parseFromString(await s.getHTML(),"text/html")}catch{return{ok:!1,code:"failed",message:U}}let c=await Re(e,{doc:u,loc:r,fetchFn:l});if(!c.ok)return c;let f=typeof i=="function"?i:s.save&&typeof s.save.replace=="function"?s.save.replace:G,d;try{d=await f(c.html,{etag:a!==void 0?a:F()})}catch{return{ok:!1,code:"failed",message:U}}if(!d||!d.ok){let h=d&&d.code?d.code:"failed";return h==="conflict"?{ok:!1,code:h,message:Se}:h==="forbidden"?{ok:!1,code:h,message:"You are not allowed to save this document."}:h==="unsupported"?{ok:!1,code:h,message:"This host cannot save the upgrade."}:{ok:!1,code:h,message:U}}return o(),{ok:!0,html:c.html,version:c.version,etag:d.etag}}function O(e,t,r={}){let l=e.createElement(t);l.setAttribute("clay","editor-ui");for(let[n,o]of Object.entries(r))n==="style"?l.setAttribute("style",o):n==="text"?l.textContent=o:l.setAttribute(n,o);return l}function er(e){let r=(e&&e.pathname?e.pathname:"/").split("/").filter(Boolean).pop()||"page.html";try{r=decodeURIComponent(r)}catch{}return/\.html?$/i.test(r)?r:`${r}.html`}async function tr(e,{loc:t=location,fetchFn:r=(l,n)=>fetch(l,n)}={}){if(typeof e.getHTML=="function")return e.getHTML();let l=await r(t.href,{cache:"no-store",credentials:"same-origin"});if(!l.ok)throw new Error(`copy fetch ${l.status}`);return l.text()}async function rr({clay:e,doc:t=document,loc:r=location,fetchFn:l}={}){if(typeof URL>"u"||typeof URL.createObjectURL!="function")return!1;try{let n=await tr(e,{loc:r,fetchFn:l}),o=URL.createObjectURL(new Blob([n],{type:"text/html"})),i=t.createElement("a");return i.setAttribute("clay","editor-ui"),i.href=o,i.download=er(r),i.style.setProperty("display","none","important"),t.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(o),4e4),!0}catch{return!1}}async function nr(e){let t=e&&e.host;if(!t||!t.versions)return!1;try{return await t.versions===!0}catch{return!1}}async function lr(e,t={}){let r=t.doc||document,l=t.clay||(typeof window<"u"?window.clay:null)||{};if(l.isDraftMode||!e||typeof e.version!="string")return null;let n=await nr(l),o=O(r,"div",{role:"dialog","aria-modal":"true","data-clay-upgrade":"",style:"position:fixed;inset:0;z-index:2147483000;display:flex;align-items:center;justify-content:center;padding:16px;background:rgba(15,17,21,.42);font-family:system-ui,-apple-system,'Segoe UI',sans-serif;"}),i=O(r,"div",{style:"width:min(460px,100%);padding:20px;border-radius:14px;background:var(--clay-ui-bg,#fff);color:var(--clay-ui-fg,#1f2328);box-shadow:0 18px 48px -16px rgba(0,0,0,.55);font-size:14px;line-height:1.5;"}),a=O(r,"h2",{text:`Upgrade to version ${e.version}`,style:"margin:0 0 8px;font-size:16px;"}),s=O(r,"p",{text:`Your data moves into version ${e.version}. The page's layout and code are replaced; your current version stays in this document's history.`,style:"margin:0 0 16px;"}),u=O(r,"p",{role:"status",style:"margin:0 0 12px;min-height:1.5em;"}),c=O(r,"div",{style:"display:flex;flex-wrap:wrap;gap:8px;justify-content:flex-end;"}),f="padding:7px 12px;border-radius:8px;border:1px solid rgba(23,28,36,.2);background:transparent;color:inherit;font:inherit;cursor:pointer;",d=O(r,"button",{type:"button",text:"Cancel",style:f}),h=n?null:O(r,"button",{type:"button",text:"Download a copy first",style:f}),m=O(r,"button",{type:"button",text:"Upgrade",style:`${f}border-color:transparent;background:#2f6fed;color:#fff;font-weight:600;`});n||(m.disabled=!0),h&&c.append(h),c.append(d,m),i.append(a,s,u,c),o.append(i),r.body.appendChild(o);let w=!1,v=()=>{w||(w=!0,o.remove())};h&&h.addEventListener("click",async()=>{await rr({clay:l,doc:r,loc:t.loc,fetchFn:t.fetchFn})?(m.disabled=!1,u.textContent="Your copy was downloaded."):u.textContent="The copy could not be downloaded. Nothing was changed."}),d.addEventListener("click",v);let p,y=new Promise(g=>{p=g});return m.addEventListener("click",async()=>{m.disabled=!0,h&&(h.disabled=!0),u.textContent=`Upgrading to version ${e.version}\u2026`;let g=await $e(e,t);if(g.ok){v(),p(g);return}u.textContent=g.message||U,m.disabled=!1,h&&(h.disabled=!1),p(g)}),{root:o,title:a,body:s,status:u,cancel:d,download:h,upgrade:m,close:v,done:y}}export{$e as apply,Re as prepare,lr as start};
3
+ `:"")+t.documentElement.outerHTML}async function Re(e,{doc:t=document,loc:r=location,fetchFn:l=(n,o)=>fetch(n,o)}={}){if((typeof window<"u"&&window.clay||{}).isDraftMode)return{ok:!1,code:"draft"};if(!e||typeof e.version!="string")return{ok:!1,code:"unavailable",message:A};let o=Ft(e,t,r);if(!o)return{ok:!1,code:"unavailable",message:A};let i=await Ne(l,o);if(!i)return{ok:!1,code:"unavailable",message:A};let a;try{a=await i.json()}catch{return{ok:!1,code:"unavailable",message:A}}if(!a||typeof a!="object")return{ok:!1,code:"unavailable",message:A};let s=zt(t);if(!s||a.id!==s.id||a.variant!==s.variant)return{ok:!1,code:"template",message:"This upgrade is for a different document."};let u=x(t,"hyper-version");if(!u||typeof a.version!="string"||!J(a.version,u))return{ok:!1,code:"not-newer",message:"There is no newer version to install."};if(typeof a.html!="string"||!a.html)return{ok:!1,code:"unavailable",message:A};let c;try{c=new URL(a.html,o).href}catch{return{ok:!1,code:"unavailable",message:A}}if(!/^https:\/\/hyperclay\.com\/templates\//.test(c))return{ok:!1,code:"source",message:"This upgrade is not from the template host."};let f=await Ne(l,c);if(!f)return{ok:!1,code:"unavailable",message:A};let d;try{d=await f.text()}catch{return{ok:!1,code:"unavailable",message:A}}let h=await Vt(new TextEncoder().encode(d));if(!h||h!==String(a.sha256||"").toLowerCase())return{ok:!1,code:"unavailable",message:A};let m,w;try{w=await Yt(d),m=await M.run({sourceUrl:c,doc:t,loc:r,fromVersion:u,fetchFn:async()=>({ok:!0,status:200,text:async()=>d})})}catch(T){return{ok:!1,code:"transform",message:T&&T.message?T.message:A}}let v=new DOMParser().parseFromString(m.html,"text/html"),p=M.extractAll(t).dataByName,y=t.querySelector("article[data-page]");if(!y&&!Object.keys(p||{}).length)return{ok:!1,code:"undeclared",message:Ht};let g=m.html;if(y){let T=Xt(t,v,y);if(!T)return{ok:!1,code:"lost",lost:[],discarded:0,message:Wt};g=T}let b=M.extractAll(v).dataByName,E=Jt(p,b,w),N=m.summary&&m.summary.totals&&m.summary.totals.discarded||0;return E.length||N>0?{ok:!1,code:"lost",lost:E,discarded:N,message:Kt(E,N)}:{ok:!0,html:g,version:m.toVersion||a.version}}function Kt(e,t){let r=e.slice(0,5).map(({path:n})=>n),l=e.length>r.length?` and ${e.length-r.length} more`:"";return r.length?`This upgrade would lose data: ${r.join(", ")}${l}. Nothing was changed.`:`This upgrade would lose ${t} value${t===1?"":"s"}. Nothing was changed.`}function Zt(e){let t=e&&e.state;if(t==="conflict")return{ok:!1,code:"conflict",message:Se};let r=e&&e.message?e.message:"The document could not be saved.";return{ok:!1,code:"flush",state:t||"failed",message:r}}async function $e(e,{doc:t=document,loc:r=location,fetchFn:l=(s,u)=>fetch(s,u),clay:n=typeof window<"u"?window.clay:null,reload:o=()=>window.location.reload(),replace:i=null,etag:a}={}){if((n||{}).isDraftMode)return{ok:!1,code:"draft"};let u=z("upgrade");if(!u)return{ok:!1,code:"busy",message:qt};try{return await Qt(e,{doc:t,loc:r,fetchFn:l,clay:n,reload:o,replace:i,etag:a})}finally{_(u)}}async function Qt(e,{doc:t,loc:r,fetchFn:l,clay:n,reload:o,replace:i,etag:a}){let s=n||{};if(s.isEditMode&&s.save&&typeof s.save.flush=="function"){let h;try{h=await s.save.flush()}catch(m){return Zt(m)}if(h&&typeof h.state=="string"&&h.state!=="saved"&&h.state!=="clean"&&h.state!=="view")return{ok:!1,code:"flush",state:h.state,message:"This document has changes that could not be saved. Nothing was changed."}}let u=t;if(s.isEditMode&&typeof s.getHTML=="function")try{u=new DOMParser().parseFromString(await s.getHTML(),"text/html")}catch{return{ok:!1,code:"failed",message:U}}let c=await Re(e,{doc:u,loc:r,fetchFn:l});if(!c.ok)return c;let f=typeof i=="function"?i:s.save&&typeof s.save.replace=="function"?s.save.replace:G,d;try{d=await f(c.html,{etag:a!==void 0?a:F()})}catch{return{ok:!1,code:"failed",message:U}}if(!d||!d.ok){let h=d&&d.code?d.code:"failed";return h==="conflict"?{ok:!1,code:h,message:Se}:h==="forbidden"?{ok:!1,code:h,message:"You are not allowed to save this document."}:h==="unsupported"?{ok:!1,code:h,message:"This host cannot save the upgrade."}:{ok:!1,code:h,message:U}}return o(),{ok:!0,html:c.html,version:c.version,etag:d.etag}}function O(e,t,r={}){let l=e.createElement(t);l.setAttribute("clay","editor-ui");for(let[n,o]of Object.entries(r))n==="style"?l.setAttribute("style",o):n==="text"?l.textContent=o:l.setAttribute(n,o);return l}function er(e){let r=(e&&e.pathname?e.pathname:"/").split("/").filter(Boolean).pop()||"page.html";try{r=decodeURIComponent(r)}catch{}return/\.html?$/i.test(r)?r:`${r}.html`}async function tr(e,{loc:t=location,fetchFn:r=(l,n)=>fetch(l,n)}={}){if(typeof e.getHTML=="function")return e.getHTML();let l=await r(t.href,{cache:"no-store",credentials:"same-origin"});if(!l.ok)throw new Error(`copy fetch ${l.status}`);return l.text()}async function rr({clay:e,doc:t=document,loc:r=location,fetchFn:l}={}){if(typeof URL>"u"||typeof URL.createObjectURL!="function")return!1;try{let n=await tr(e,{loc:r,fetchFn:l});if(typeof n=="string"&&/clay|data-paid-only/i.test(n)){let{stripCopyContent:a}=await import("./c-C4IIQZGJ.js");n=a(n)}let o=URL.createObjectURL(new Blob([n],{type:"text/html"})),i=t.createElement("a");return i.setAttribute("clay","editor-ui"),i.href=o,i.download=er(r),i.style.setProperty("display","none","important"),t.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(o),4e4),!0}catch{return!1}}async function nr(e){let t=e&&e.host;if(!t||!t.versions)return!1;try{return await t.versions===!0}catch{return!1}}async function lr(e,t={}){let r=t.doc||document,l=t.clay||(typeof window<"u"?window.clay:null)||{};if(l.isDraftMode||!e||typeof e.version!="string")return null;let n=await nr(l),o=O(r,"div",{role:"dialog","aria-modal":"true","data-clay-upgrade":"",style:"position:fixed;inset:0;z-index:2147483000;display:flex;align-items:center;justify-content:center;padding:16px;background:rgba(15,17,21,.42);font-family:system-ui,-apple-system,'Segoe UI',sans-serif;"}),i=O(r,"div",{style:"width:min(460px,100%);padding:20px;border-radius:14px;background:var(--clay-ui-bg,#fff);color:var(--clay-ui-fg,#1f2328);box-shadow:0 18px 48px -16px rgba(0,0,0,.55);font-size:14px;line-height:1.5;"}),a=O(r,"h2",{text:`Upgrade to version ${e.version}`,style:"margin:0 0 8px;font-size:16px;"}),s=O(r,"p",{text:`Your data moves into version ${e.version}. The page's layout and code are replaced; your current version stays in this document's history.`,style:"margin:0 0 16px;"}),u=O(r,"p",{role:"status",style:"margin:0 0 12px;min-height:1.5em;"}),c=O(r,"div",{style:"display:flex;flex-wrap:wrap;gap:8px;justify-content:flex-end;"}),f="padding:7px 12px;border-radius:8px;border:1px solid rgba(23,28,36,.2);background:transparent;color:inherit;font:inherit;cursor:pointer;",d=O(r,"button",{type:"button",text:"Cancel",style:f}),h=n?null:O(r,"button",{type:"button",text:"Download a copy first",style:f}),m=O(r,"button",{type:"button",text:"Upgrade",style:`${f}border-color:transparent;background:#2f6fed;color:#fff;font-weight:600;`});n||(m.disabled=!0),h&&c.append(h),c.append(d,m),i.append(a,s,u,c),o.append(i),r.body.appendChild(o);let w=!1,v=()=>{w||(w=!0,o.remove())};h&&h.addEventListener("click",async()=>{await rr({clay:l,doc:r,loc:t.loc,fetchFn:t.fetchFn})?(m.disabled=!1,u.textContent="Your copy was downloaded."):u.textContent="The copy could not be downloaded. Nothing was changed."}),d.addEventListener("click",v);let p,y=new Promise(g=>{p=g});return m.addEventListener("click",async()=>{m.disabled=!0,h&&(h.disabled=!0),u.textContent=`Upgrading to version ${e.version}\u2026`;let g=await $e(e,t);if(g.ok){v(),p(g);return}u.textContent=g.message||U,m.disabled=!1,h&&(h.disabled=!1),p(g)}),{root:o,title:a,body:s,status:u,cancel:d,download:h,upgrade:m,close:v,done:y}}export{$e as apply,Re as prepare,lr as start};
@@ -1 +1 @@
1
- import{d as p}from"./c-XGH4GS2T.js";import{f as u}from"./c-3O7OBDCM.js";var d=window.__clayWorkspaceBackground===!0;document.addEventListener("clay:workspace-background",()=>{d=!0});document.addEventListener("clay:workspace-foreground",()=>{d=!1});var a=()=>document.hidden||d,m=class extends EventTarget{constructor(e,{shared:t=!1,sharedData:i=!1,documentURL:n,lane:s,clientId:o,startupCheck:c=!1,keepAliveWhenHidden:v=!1}={}){super(),this.url=e,this.readyState=0,this.onopen=null,this.onmessage=null,this.onerror=null,this._shared=t&&typeof SharedWorker=="function",this._sharedData=i,this._documentURL=n,this._lane=s,this._clientId=o,this._keepAliveWhenHidden=v,this._since=0,this._closed=!1,this._suspended=!1,this._repair=!1,this._startup=c,this._worker=null,this._source=null,this._visibility=()=>{clearTimeout(this._hiddenTimer),a()?(this._worker&&this._postWorker(this._worker,"hidden"),this._keepAliveWhenHidden||(this._hiddenTimer=setTimeout(()=>this._suspend(),5e3))):this._suspended?this._resume():this._worker&&this._postWorker(this._worker,"visible")},this._pagehide=()=>this._suspend(!0),this._pageshow=()=>{(!a()||this._keepAliveWhenHidden)&&this._resume()},document.addEventListener("visibilitychange",this._visibility),document.addEventListener("clay:workspace-background",this._visibility),document.addEventListener("clay:workspace-foreground",this._visibility),window.addEventListener("pagehide",this._pagehide),window.addEventListener("pageshow",this._pageshow),this._open(),a()&&this._visibility()}_emit(e,t){if(this._closed)return;let i=t===void 0?new Event(e):new MessageEvent(e,{data:t});this.dispatchEvent(i),this[`on${e}`]?.(i)}_postWorker(e,t,i={}){e.port.postMessage({v:this._sharedData?2:1,type:t,...i})}_open(){if(!(this._closed||this._suspended)){if(this.readyState=0,!this._shared)return this._openDirect();try{let e=new SharedWorker(new URL(this._sharedData?"/_/sync/data-worker.js":"/_/sync/worker.js",window.location.origin).href,this._sharedData?"clay-sync-data":"clay-sync");this._worker=e;let t=Date.now(),i=!1;e.onerror=()=>{this._worker===e&&(this._shared=!1,this._repair=!0,this._reopen())},this._startTimer=setTimeout(e.onerror,5e3),e.port.onmessage=({data:s})=>{if(!(this._worker!==e||s?.v!==(this._sharedData?2:1))){if(this._sharedData){if(s.type==="unsupported"){e.onerror();return}if(s.type==="gone"){this.readyState=2,this._emit("error"),this.close();return}if(!i){if(s.type!=="hello")return;if(!Array.isArray(s.features)||!s.features.includes("live-data")){e.onerror();return}i=!0,clearTimeout(this._startTimer),t=Date.now();return}if(s.type==="hello")return}if(t=Date.now(),!this._sharedData&&["status","pong","cursor","frame","gone"].includes(s.type)&&clearTimeout(this._startTimer),s.type==="status")s.state==="open"?(!this._sharedData||this.readyState!==1)&&(this.readyState=1,this._emit("open")):s.state==="connecting"&&(this.readyState=0,this._emit("error"));else if(s.type==="cursor"){clearTimeout(this._startTimer),Number.isSafeInteger(s.seq)&&(this._since=Math.max(this._since,s.seq));let o=s.resync===!0||this._repair,c=this._startup;this._repair=!1,this._startup=!1,this._emit("cursor",JSON.stringify({...s,resync:o,startup:c}))}else if(s.type==="frame"&&typeof s.data=="string")this._remember(s.data),this._emit("message",s.data);else if(this._sharedData&&s.type==="event"&&["data","data-state","data-writer"].includes(s.event)&&s.data!==null&&typeof s.data=="object"&&!Array.isArray(s.data))try{this._emit(s.event,JSON.stringify(s.data))}catch{}else s.type==="gone"&&(this.readyState=2,this._emit("error"),this.close())}},e.port.start(),this._postWorker(e,a()?"hidden":"visible");let n={document:this._documentURL,lane:this._lane,since:this._since};this._sharedData&&this._lane==="live"&&(n.clientId=this._clientId),this._postWorker(e,"subscribe",n),this._pingTimer=setInterval(()=>{this._worker===e&&(Date.now()-t>15e3*3?(this._repair=!0,this._reopen()):this._postWorker(e,"ping"))},15e3)}catch{this._shared=!1,this._reopen()}}}_openDirect(){let e=new EventSource(this.url);this._source=e,e.onopen=()=>{if(this._source===e&&(this.readyState=1,this._emit("open"),this._repair||this._startup)){let t=this._repair,i=this._startup;this._repair=!1,this._startup=!1,this._emit("cursor",JSON.stringify({resync:t,startup:i}))}},e.onerror=()=>{this._source===e&&(this.readyState=e.readyState,this._emit("error"))},e.onmessage=t=>{this._source===e&&(this._remember(t.data),this._emit("message",t.data))};for(let t of["cursor","presence","data","data-state","data-writer"])e.addEventListener(t,i=>{this._source===e&&this._emit(t,i.data)})}_remember(e){try{let{seq:t}=JSON.parse(e);Number.isSafeInteger(t)&&(this._since=Math.max(this._since,t))}catch{}}_disconnect(){if(clearTimeout(this._startTimer),clearInterval(this._pingTimer),this._worker){let e=this._worker;this._worker=null,e.onerror=null,e.port.onmessage=null;try{this._postWorker(e,"unsubscribe")}catch{}e.port.close()}this._source&&(this._source.close(),this._source=null)}_reopen(){let e=(this._sharedData||this._keepAliveWhenHidden)&&this.readyState===1;this.readyState=0,e&&this._emit("error"),this._disconnect(),this._open()}_suspend(e=!1){clearTimeout(this._hiddenTimer),!(this._closed||this._suspended)&&(this._suspended=!0,this._repair=!0,this.readyState=0,e&&this._keepAliveWhenHidden&&this._emit("error"),this._disconnect())}_resume(){clearTimeout(this._hiddenTimer),!(this._closed||!this._suspended)&&(this._suspended=!1,this._open())}close(){this._closed=!0,this.readyState=2,clearTimeout(this._hiddenTimer),this._disconnect(),document.removeEventListener("visibilitychange",this._visibility),document.removeEventListener("clay:workspace-background",this._visibility),document.removeEventListener("clay:workspace-foreground",this._visibility),window.removeEventListener("pagehide",this._pagehide),window.removeEventListener("pageshow",this._pageshow)}};var f="This document was upgraded.",h=!1;function l(r,e){let t=r.querySelector(`meta[name="${e}"]`),i=t?t.getAttribute("content"):null;return i&&i.trim()?i.trim():null}function g(r=document){return l(r,"hyper-version")}function w(r){return typeof r!="string"||!r.includes("hyper-version")?null:l(new DOMParser().parseFromString(r,"text/html"),"hyper-version")}function y(r){let e=g();return!!e&&!!r&&r!==e}function T(r){return h?!0:y(w(r))}function D(r){return h?!0:!r||typeof r.querySelector!="function"?!1:y(l(r,"hyper-version"))}function S(){if(h)return Promise.resolve();h=!0;let r=u?import("./core/save-LYY7K6U7.js").then(i=>i.holdAllSaves(f),()=>{}):Promise.resolve(),e=new CustomEvent("clay:document-upgraded",{detail:{message:f}}),t=u?Promise.resolve():import("./c-D5IKEKXW.js").then(i=>i.start(e),()=>{});return document.dispatchEvent(e),Promise.all([r,t]).then(()=>{})}var _={spec:{name:"spec",relayPath:"/_/sync",documentHeader:"Document-URL",snapshotKey:"snapshot",streamPath:(r,e,t,i)=>`/_/sync?document-url=${encodeURIComponent(r)}&lane=${e}&resume-id=${t}&client-id=${encodeURIComponent(i)}`},legacy:{name:"legacy",relayPath:"/_/live-sync/save",documentHeader:"Page-URL",snapshotKey:"html",streamPath:(r,e,t,i)=>`/_/live-sync/stream?page-url=${encodeURIComponent(r)}&lane=${e}&resume-id=${t}&client-id=${encodeURIComponent(i)}`}};function I(){return p().then(r=>{let e=r?.extensions||[],t=e.includes("sync"),i=e.includes("live-data"),n=e.includes("presence"),s=t&&i&&e.includes("sync-worker-data")&&!n,o=t&&!n&&(s||e.includes("sync-worker")&&!i);return{profile:t?_.spec:_.legacy,sharedSync:o,sharedData:s,liveData:i}}).catch(()=>({profile:_.legacy,sharedSync:!1,sharedData:!1,liveData:!1}))}export{m as a,T as b,D as c,S as d,_ as e,I as f};
1
+ import{d as p}from"./c-XGH4GS2T.js";import{f as u}from"./c-3O7OBDCM.js";var d=window.__clayWorkspaceBackground===!0;document.addEventListener("clay:workspace-background",()=>{d=!0});document.addEventListener("clay:workspace-foreground",()=>{d=!1});var a=()=>document.hidden||d,m=class extends EventTarget{constructor(e,{shared:t=!1,sharedData:i=!1,documentURL:n,lane:s,clientId:o,startupCheck:c=!1,keepAliveWhenHidden:v=!1}={}){super(),this.url=e,this.readyState=0,this.onopen=null,this.onmessage=null,this.onerror=null,this._shared=t&&typeof SharedWorker=="function",this._sharedData=i,this._documentURL=n,this._lane=s,this._clientId=o,this._keepAliveWhenHidden=v,this._since=0,this._closed=!1,this._suspended=!1,this._repair=!1,this._startup=c,this._worker=null,this._source=null,this._visibility=()=>{clearTimeout(this._hiddenTimer),a()?(this._worker&&this._postWorker(this._worker,"hidden"),this._keepAliveWhenHidden||(this._hiddenTimer=setTimeout(()=>this._suspend(),5e3))):this._suspended?this._resume():this._worker&&this._postWorker(this._worker,"visible")},this._pagehide=()=>this._suspend(!0),this._pageshow=()=>{(!a()||this._keepAliveWhenHidden)&&this._resume()},document.addEventListener("visibilitychange",this._visibility),document.addEventListener("clay:workspace-background",this._visibility),document.addEventListener("clay:workspace-foreground",this._visibility),window.addEventListener("pagehide",this._pagehide),window.addEventListener("pageshow",this._pageshow),this._open(),a()&&this._visibility()}_emit(e,t){if(this._closed)return;let i=t===void 0?new Event(e):new MessageEvent(e,{data:t});this.dispatchEvent(i),this[`on${e}`]?.(i)}_postWorker(e,t,i={}){e.port.postMessage({v:this._sharedData?2:1,type:t,...i})}_open(){if(!(this._closed||this._suspended)){if(this.readyState=0,!this._shared)return this._openDirect();try{let e=new SharedWorker(new URL(this._sharedData?"/_/sync/data-worker.js":"/_/sync/worker.js",window.location.origin).href,this._sharedData?"clay-sync-data":"clay-sync");this._worker=e;let t=Date.now(),i=!1;e.onerror=()=>{this._worker===e&&(this._shared=!1,this._repair=!0,this._reopen())},this._startTimer=setTimeout(e.onerror,5e3),e.port.onmessage=({data:s})=>{if(!(this._worker!==e||s?.v!==(this._sharedData?2:1))){if(this._sharedData){if(s.type==="unsupported"){e.onerror();return}if(s.type==="gone"){this.readyState=2,this._emit("error"),this.close();return}if(!i){if(s.type!=="hello")return;if(!Array.isArray(s.features)||!s.features.includes("live-data")){e.onerror();return}i=!0,clearTimeout(this._startTimer),t=Date.now();return}if(s.type==="hello")return}if(t=Date.now(),!this._sharedData&&["status","pong","cursor","frame","gone"].includes(s.type)&&clearTimeout(this._startTimer),s.type==="status")s.state==="open"?(!this._sharedData||this.readyState!==1)&&(this.readyState=1,this._emit("open")):s.state==="connecting"&&(this.readyState=0,this._emit("error"));else if(s.type==="cursor"){clearTimeout(this._startTimer),Number.isSafeInteger(s.seq)&&(this._since=Math.max(this._since,s.seq));let o=s.resync===!0||this._repair,c=this._startup;this._repair=!1,this._startup=!1,this._emit("cursor",JSON.stringify({...s,resync:o,startup:c}))}else if(s.type==="frame"&&typeof s.data=="string")this._remember(s.data),this._emit("message",s.data);else if(this._sharedData&&s.type==="event"&&["data","data-state","data-writer"].includes(s.event)&&s.data!==null&&typeof s.data=="object"&&!Array.isArray(s.data))try{this._emit(s.event,JSON.stringify(s.data))}catch{}else s.type==="gone"&&(this.readyState=2,this._emit("error"),this.close())}},e.port.start(),this._postWorker(e,a()?"hidden":"visible");let n={document:this._documentURL,lane:this._lane,since:this._since};this._sharedData&&this._lane==="live"&&(n.clientId=this._clientId),this._postWorker(e,"subscribe",n),this._pingTimer=setInterval(()=>{this._worker===e&&(Date.now()-t>15e3*3?(this._repair=!0,this._reopen()):this._postWorker(e,"ping"))},15e3)}catch{this._shared=!1,this._reopen()}}}_openDirect(){let e=new EventSource(this.url);this._source=e,e.onopen=()=>{if(this._source===e&&(this.readyState=1,this._emit("open"),this._repair||this._startup)){let t=this._repair,i=this._startup;this._repair=!1,this._startup=!1,this._emit("cursor",JSON.stringify({resync:t,startup:i}))}},e.onerror=()=>{this._source===e&&(this.readyState=e.readyState,this._emit("error"))},e.onmessage=t=>{this._source===e&&(this._remember(t.data),this._emit("message",t.data))};for(let t of["cursor","presence","data","data-state","data-writer"])e.addEventListener(t,i=>{this._source===e&&this._emit(t,i.data)})}_remember(e){try{let{seq:t}=JSON.parse(e);Number.isSafeInteger(t)&&(this._since=Math.max(this._since,t))}catch{}}_disconnect(){if(clearTimeout(this._startTimer),clearInterval(this._pingTimer),this._worker){let e=this._worker;this._worker=null,e.onerror=null,e.port.onmessage=null;try{this._postWorker(e,"unsubscribe")}catch{}e.port.close()}this._source&&(this._source.close(),this._source=null)}_reopen(){let e=(this._sharedData||this._keepAliveWhenHidden)&&this.readyState===1;this.readyState=0,e&&this._emit("error"),this._disconnect(),this._open()}_suspend(e=!1){clearTimeout(this._hiddenTimer),!(this._closed||this._suspended)&&(this._suspended=!0,this._repair=!0,this.readyState=0,e&&this._keepAliveWhenHidden&&this._emit("error"),this._disconnect())}_resume(){clearTimeout(this._hiddenTimer),!(this._closed||!this._suspended)&&(this._suspended=!1,this._open())}close(){this._closed=!0,this.readyState=2,clearTimeout(this._hiddenTimer),this._disconnect(),document.removeEventListener("visibilitychange",this._visibility),document.removeEventListener("clay:workspace-background",this._visibility),document.removeEventListener("clay:workspace-foreground",this._visibility),window.removeEventListener("pagehide",this._pagehide),window.removeEventListener("pageshow",this._pageshow)}};var f="This document was upgraded.",h=!1;function l(r,e){let t=r.querySelector(`meta[name="${e}"]`),i=t?t.getAttribute("content"):null;return i&&i.trim()?i.trim():null}function g(r=document){return l(r,"hyper-version")}function w(r){return typeof r!="string"||!r.includes("hyper-version")?null:l(new DOMParser().parseFromString(r,"text/html"),"hyper-version")}function y(r){let e=g();return!!e&&!!r&&r!==e}function T(r){return h?!0:y(w(r))}function D(r){return h?!0:!r||typeof r.querySelector!="function"?!1:y(l(r,"hyper-version"))}function S(){if(h)return Promise.resolve();h=!0;let r=u?import("./core/save-AOJBDSOK.js").then(i=>i.holdAllSaves(f),()=>{}):Promise.resolve(),e=new CustomEvent("clay:document-upgraded",{detail:{message:f}}),t=u?Promise.resolve():import("./c-K76AUL4I.js").then(i=>i.start(e),()=>{});return document.dispatchEvent(e),Promise.all([r,t]).then(()=>{})}var _={spec:{name:"spec",relayPath:"/_/sync",documentHeader:"Document-URL",snapshotKey:"snapshot",streamPath:(r,e,t,i)=>`/_/sync?document-url=${encodeURIComponent(r)}&lane=${e}&resume-id=${t}&client-id=${encodeURIComponent(i)}`},legacy:{name:"legacy",relayPath:"/_/live-sync/save",documentHeader:"Page-URL",snapshotKey:"html",streamPath:(r,e,t,i)=>`/_/live-sync/stream?page-url=${encodeURIComponent(r)}&lane=${e}&resume-id=${t}&client-id=${encodeURIComponent(i)}`}};function I(){return p().then(r=>{let e=r?.extensions||[],t=e.includes("sync"),i=e.includes("live-data"),n=e.includes("presence"),s=t&&i&&e.includes("sync-worker-data")&&!n,o=t&&!n&&(s||e.includes("sync-worker")&&!i);return{profile:t?_.spec:_.legacy,sharedSync:o,sharedData:s,liveData:i}}).catch(()=>({profile:_.legacy,sharedSync:!1,sharedData:!1,liveData:!1}))}export{m as a,T as b,D as c,S as d,_ as e,I as f};
@@ -1 +1 @@
1
- var o=null,n=()=>o??=import("./c-GRXHHFPO.js"),s=t=>(...i)=>{n().then(e=>(t?e[t]:e.default)(...i))},l=s(null),r=s("toastPersistent"),a=(...t)=>{o&&s("dismissPersistent")(...t)};export{l as a,r as b,a as c};
1
+ var o=null,n=()=>o??=import("./c-MIL4B2JQ.js"),s=t=>(...i)=>{n().then(e=>(t?e[t]:e.default)(...i))},l=s(null),r=s("toastPersistent"),a=(...t)=>{o&&s("dismissPersistent")(...t)};export{l as a,r as b,a as c};
@@ -1 +1 @@
1
- import{b as a}from"./c-PZ4XEPUP.js";import{K as u}from"./c-7MG5RU63.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-VG5XIN4T.js";import"./c-2YYDMLNZ.js";import{i as s}from"./c-HA6INT6J.js";import"./c-DCFSEJZG.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var d=20,i=null,l=!1,c=[];function h(){i||l||(l=!0,import("./c-OIDRZKAF.js").then(e=>{i=e,l=!1,f()},e=>{l=!1,console.error("clayjs: the conflict recovery module could not be downloaded; conflicts stay in this tab only",e)}))}function f(){if(!i){h();return}for(;c.length;){let e=c.shift();try{i.recordConflicts(e)}catch(o){console.error("clayjs: the conflict could not be stored for a later reload; it is still here",o)}}}function m(e,o){let t=null;try{t=a(e)}catch{}let n=r=>r?(r.cutBefore?"\u2026":"")+r.before+r.hit+r.after+(r.cutAfter?"\u2026":""):"";return{id:String(e.id),kind:String(e.kind??""),key:e.recovery?.key==null?"":String(e.recovery.key),name:t?.name?String(t.name):"",sentence:t?.sentence?String(t.sentence):"",yours:n(t?.yours),now:n(t?.now),context:o}}function y(e){try{let t=(e.recoveryRoot??e.root)?.cloneNode?.(!0);if(!t)return null;for(let n of s)t.removeAttribute(n);return u(t,{prepared:e.domain==="save"})}catch(o){return console.error("clayjs: the conflict recovery page could not be serialized; the conflict text is still stored",o),null}}function k({apply:e,records:o}){try{c.push({apply:{id:e.id,source:e.source,domain:e.domain,seq:e.seq,etag:e.etag,ticket:e.ticket},root:y(e),conflicts:o.map(({rec:t,context:n})=>m(t,n))}),c.length>d&&c.shift(),f()}catch(t){console.error("clayjs: the conflict could not be stored for a later reload; it is still here",t)}}function A(e){import("./c-OIDRZKAF.js").then(o=>o.dismissConflicts(e),()=>{}).catch(()=>{})}export{A as dismiss,k as keep};
1
+ import{b as a}from"./c-PZ4XEPUP.js";import{K as u}from"./c-EGTIAL6P.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-VG5XIN4T.js";import"./c-2YYDMLNZ.js";import{i as s}from"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var d=20,i=null,l=!1,c=[];function h(){i||l||(l=!0,import("./c-OIDRZKAF.js").then(e=>{i=e,l=!1,f()},e=>{l=!1,console.error("clayjs: the conflict recovery module could not be downloaded; conflicts stay in this tab only",e)}))}function f(){if(!i){h();return}for(;c.length;){let e=c.shift();try{i.recordConflicts(e)}catch(o){console.error("clayjs: the conflict could not be stored for a later reload; it is still here",o)}}}function m(e,o){let t=null;try{t=a(e)}catch{}let n=r=>r?(r.cutBefore?"\u2026":"")+r.before+r.hit+r.after+(r.cutAfter?"\u2026":""):"";return{id:String(e.id),kind:String(e.kind??""),key:e.recovery?.key==null?"":String(e.recovery.key),name:t?.name?String(t.name):"",sentence:t?.sentence?String(t.sentence):"",yours:n(t?.yours),now:n(t?.now),context:o}}function y(e){try{let t=(e.recoveryRoot??e.root)?.cloneNode?.(!0);if(!t)return null;for(let n of s)t.removeAttribute(n);return u(t,{prepared:e.domain==="save"})}catch(o){return console.error("clayjs: the conflict recovery page could not be serialized; the conflict text is still stored",o),null}}function k({apply:e,records:o}){try{c.push({apply:{id:e.id,source:e.source,domain:e.domain,seq:e.seq,etag:e.etag,ticket:e.ticket},root:y(e),conflicts:o.map(({rec:t,context:n})=>m(t,n))}),c.length>d&&c.shift(),f()}catch(t){console.error("clayjs: the conflict could not be stored for a later reload; it is still here",t)}}function A(e){import("./c-OIDRZKAF.js").then(o=>o.dismissConflicts(e),()=>{}).catch(()=>{})}export{A as dismiss,k as keep};
@@ -1 +1 @@
1
- import{b as $}from"./c-R2XUODVY.js";import{a as k,b as B,c as L}from"./c-GBKB5WDL.js";import{B as M}from"./c-AMU3BPPR.js";import{G as P,J as R,b as O,m as q}from"./c-QIXT3Q7C.js";import"./c-3GJ4SDE2.js";import{a as N}from"./c-3LDGIBMN.js";import"./c-VHNSBD2M.js";var K=16384,G=p=>new TextEncoder().encode(JSON.stringify(p)).length,I=class extends Error{constructor(s,n=s){super(n),this.name="ToolRequestError",this.code=s}};function V(p){let s=N(p);for(Array.isArray(s.tables)||(s.tables=[]),Array.isArray(s.outline)||(s.outline=[]);G(s)>K;){let n=[...s.tables].reverse().find(i=>Array.isArray(i.rows)&&i.rows.length);if(n)n.rows.pop();else if(s.outline.length)s.outline.pop();else break}if(G(s)>K)throw new I("context-too-large");return s}function J({transport:p,newId:s}){let n=null,i=a=>{!a||a.discarded||a.done||(a.discarded=!0,n===a&&(n=null),p.cancel(a.requestId),a.resolve({requestId:a.requestId,code:"discarded",message:"Candidate discarded"}))};return{request(a,r,t=null){let m=V(r);n&&i(n);let c=s(),l={requestId:c,discarded:!1,done:!1};l.promise=new Promise(o=>{l.resolve=o}),n=l;let y={protocol:"page-tool/1",requestId:c,prompt:a,context:m,target:t};l.request=y;let v=o=>{if(!(l.discarded||l.done||o?.requestId!==c))if(l.done=!0,n===l&&(n=null),o?.artifact!==void 0){let d=k(o.artifact),C=B(o.state),w=d.ok?C.ok?null:C:d;l.resolve(w?{requestId:c,code:w.code,message:w.code}:o)}else l.resolve(typeof o?.code=="string"?o:{requestId:c,code:"invalid-result",message:"invalid-result"})};try{Promise.resolve(p.request(y)).then(v,o=>v({requestId:c,code:"transport-error",message:String(o?.message??o)}))}catch(o){v({requestId:c,code:"transport-error",message:String(o?.message??o)})}return l},discard:i,async wait(a,{signal:r}={}){if(r?.aborted)throw new DOMException("Aborted","AbortError");let t,m=await(r?Promise.race([a.promise,new Promise((c,l)=>{t=()=>l(new DOMException("Aborted","AbortError")),r.addEventListener("abort",t,{once:!0})})]).finally(()=>r.removeEventListener("abort",t)):a.promise);if(m?.code)throw new I(m.code,m.message);return m}}}var{Selection:X}=O;function W(p,s){let n=null;return p.forEach((i,a,r)=>{i.attrs.id===s&&(n={node:i,at:a,index:r})}),n}function j(p,s,n){let i=p.state,a=W(i.doc,n?.hostId)??(()=>{let w=Math.min(i.selection.$head.index(0),i.doc.childCount-1),f=0;for(let g=0;g<w;g++)f+=i.doc.child(g).nodeSize;return{node:i.doc.child(w),at:f,index:w}})(),{node:r,at:t,index:m}=a,c=i.doc.maybeChild(m+1),l=r.isTextblock&&(r.content.size===0||n?.hostId===r.attrs.id&&r.textContent===n.slashText),y=l?r.attrs.pos:P(r.attrs.pos,c?.attrs.pos??null),v=q.nodes.tool.create({id:s.id,pos:y,parent:r.attrs.parent??null,artifact:s.artifact,rev:s.rev,state:s.state}),o=l?t:t+r.nodeSize,d=i.tr;if(!l&&n?.hostId===r.attrs.id&&n.slashText&&n.slashOffset>=0){let w=t+1+n.slashOffset,f=w+n.slashText.length;f<=t+r.nodeSize-1&&i.doc.textBetween(w,f)===n.slashText&&d.delete(w,f)}let C=d.mapping.map(o);d.replaceWith(C,l?d.mapping.map(t+r.nodeSize):C,v),d.setSelection(X.near(d.doc.resolve(Math.min(C+v.nodeSize,d.doc.content.size)))),p.dispatch(M(d).scrollIntoView())}function ie({getView:p,store:s,transport:n,acceptState:i=()=>globalThis.clay?.save?.flush?.(),newId:a=R}){let r=n?J({transport:n,newId:()=>a("request")}):null,t=null,m=0,c=()=>{m++,t&&(r?.discard(t.pending),t.preview?.dispose(),t.previewHost?.dispose(),t.element.remove(),t=null)};return{open:({target:y=null,remove:v=null}={})=>{c();let o=p();if(!o)return;let d=o.state.selection,w={hostId:o.state.doc.child(Math.min(d.$head.index(0),o.state.doc.childCount-1))?.attrs.id,slashText:v?o.state.doc.textBetween(v.from,v.to):null,slashOffset:v&&d.$head.depth?v.from-d.$head.before(1)-1:null},f=o.dom.ownerDocument,g=f.createElement("section");g.className="page-ai-panel",g.contentEditable="false",g.setAttribute("role","dialog"),g.setAttribute("aria-label",y?"Revise tool":"Make a tool with AI");let E=f.createElement("textarea");E.setAttribute("aria-label","Describe the tool"),E.placeholder=y?"What should change?":"Describe the tool you want";let A=f.createElement("p");A.className="page-ai-status";let S=f.createElement("div");S.className="page-ai-preview";let T=f.createElement("div");T.className="page-ai-actions",g.append(E,A,S,T),o.dom.parentElement.append(g),t={element:g,input:E,status:A,previewRoot:S,actions:T,target:y,bookmark:w,candidate:null,pending:null,preview:null,previewHost:null,kept:!1,busy:!1};let x=(e,u)=>{let h=f.createElement("button");h.type="button",h.textContent=e,h.addEventListener("click",u),T.append(h)},z=()=>{t&&(t.preview?.dispose(),t.previewHost?.dispose(),t.preview=null,t.previewHost=null,t.previewRoot.replaceChildren(),t.input.hidden=!1,t.actions.replaceChildren(),x("Generate",D),x("Cancel",c),t.input.focus())},_=()=>{let e=t;e.input.hidden=!0,e.status.textContent="",e.previewHost=L({mode:"view"}),e.preview=e.previewHost.mount(e.previewRoot,{id:"preview",rev:"preview",artifact:e.candidate.artifact,seed:e.candidate.state}),e.actions.replaceChildren(),x("Keep",H),x("Revise",z),x("Discard",c)},D=async()=>{let e=t;if(!e||e.busy||!e.input.value.trim())return;if(!r){e.status.textContent="Tool generation is unavailable";return}e.busy=!0,e.status.textContent="Making your tool\u2026",e.actions.replaceChildren(),x("Cancel",c);let u=++m,h=r.request(e.input.value.trim(),$(o.state.doc,f.title),e.target);e.pending=h;try{let b=await r.wait(h);if(t!==e||u!==m)return;e.candidate={artifact:b.artifact,state:b.state,id:null,rev:null},_()}catch(b){if(t!==e||u!==m)return;e.status.textContent=b.message,e.actions.replaceChildren(),x("Generate",D),x("Cancel",c)}finally{e.busy=!1}},H=async()=>{let e=t;if(!e?.candidate||e.busy||e.kept)return;e.busy=!0;let u=e.candidate;u.id??=e.target?.toolId??a("b"),u.rev??=a("rev");try{if(!s)throw new Error("This document can't save tool state");await s.set([u.id,u.rev],u.state);let h=await i();if(h?.ok!==!0&&!["saved","clean"].includes(h?.state))throw new Error(h?.msg??h?.message??"Tool state was not saved");if(t!==e||e.kept)return;if(e.target){let b=W(o.state.doc,e.target.toolId);if(b?.node.type!==q.nodes.tool||b.node.attrs.rev!==e.target.rev){e.status.textContent="This tool changed while you were revising. Keep as a new tool, or discard.",e.target=null,u.id=null,u.rev=null,e.actions.replaceChildren(),x("Keep as new tool",H),x("Discard",c);return}o.dispatch(M(o.state.tr.setNodeMarkup(b.at,null,{...b.node.attrs,artifact:u.artifact,rev:u.rev})))}else j(o,u,e.bookmark);e.kept=!0,c()}catch(h){t===e&&(e.status.textContent=h.message)}finally{e.busy=!1}};return z(),g},dispose:c}}export{ie as createAiTool};
1
+ import{b as $}from"./c-R2XUODVY.js";import{a as k,b as B,c as L}from"./c-GBKB5WDL.js";import{B as M}from"./c-44B5ODN7.js";import{G as P,J as R,b as O,m as q}from"./c-QIXT3Q7C.js";import"./c-3GJ4SDE2.js";import{a as N}from"./c-3LDGIBMN.js";import"./c-VHNSBD2M.js";var K=16384,G=p=>new TextEncoder().encode(JSON.stringify(p)).length,I=class extends Error{constructor(s,n=s){super(n),this.name="ToolRequestError",this.code=s}};function V(p){let s=N(p);for(Array.isArray(s.tables)||(s.tables=[]),Array.isArray(s.outline)||(s.outline=[]);G(s)>K;){let n=[...s.tables].reverse().find(i=>Array.isArray(i.rows)&&i.rows.length);if(n)n.rows.pop();else if(s.outline.length)s.outline.pop();else break}if(G(s)>K)throw new I("context-too-large");return s}function J({transport:p,newId:s}){let n=null,i=a=>{!a||a.discarded||a.done||(a.discarded=!0,n===a&&(n=null),p.cancel(a.requestId),a.resolve({requestId:a.requestId,code:"discarded",message:"Candidate discarded"}))};return{request(a,r,t=null){let m=V(r);n&&i(n);let c=s(),l={requestId:c,discarded:!1,done:!1};l.promise=new Promise(o=>{l.resolve=o}),n=l;let y={protocol:"page-tool/1",requestId:c,prompt:a,context:m,target:t};l.request=y;let v=o=>{if(!(l.discarded||l.done||o?.requestId!==c))if(l.done=!0,n===l&&(n=null),o?.artifact!==void 0){let d=k(o.artifact),C=B(o.state),w=d.ok?C.ok?null:C:d;l.resolve(w?{requestId:c,code:w.code,message:w.code}:o)}else l.resolve(typeof o?.code=="string"?o:{requestId:c,code:"invalid-result",message:"invalid-result"})};try{Promise.resolve(p.request(y)).then(v,o=>v({requestId:c,code:"transport-error",message:String(o?.message??o)}))}catch(o){v({requestId:c,code:"transport-error",message:String(o?.message??o)})}return l},discard:i,async wait(a,{signal:r}={}){if(r?.aborted)throw new DOMException("Aborted","AbortError");let t,m=await(r?Promise.race([a.promise,new Promise((c,l)=>{t=()=>l(new DOMException("Aborted","AbortError")),r.addEventListener("abort",t,{once:!0})})]).finally(()=>r.removeEventListener("abort",t)):a.promise);if(m?.code)throw new I(m.code,m.message);return m}}}var{Selection:X}=O;function W(p,s){let n=null;return p.forEach((i,a,r)=>{i.attrs.id===s&&(n={node:i,at:a,index:r})}),n}function j(p,s,n){let i=p.state,a=W(i.doc,n?.hostId)??(()=>{let w=Math.min(i.selection.$head.index(0),i.doc.childCount-1),f=0;for(let g=0;g<w;g++)f+=i.doc.child(g).nodeSize;return{node:i.doc.child(w),at:f,index:w}})(),{node:r,at:t,index:m}=a,c=i.doc.maybeChild(m+1),l=r.isTextblock&&(r.content.size===0||n?.hostId===r.attrs.id&&r.textContent===n.slashText),y=l?r.attrs.pos:P(r.attrs.pos,c?.attrs.pos??null),v=q.nodes.tool.create({id:s.id,pos:y,parent:r.attrs.parent??null,artifact:s.artifact,rev:s.rev,state:s.state}),o=l?t:t+r.nodeSize,d=i.tr;if(!l&&n?.hostId===r.attrs.id&&n.slashText&&n.slashOffset>=0){let w=t+1+n.slashOffset,f=w+n.slashText.length;f<=t+r.nodeSize-1&&i.doc.textBetween(w,f)===n.slashText&&d.delete(w,f)}let C=d.mapping.map(o);d.replaceWith(C,l?d.mapping.map(t+r.nodeSize):C,v),d.setSelection(X.near(d.doc.resolve(Math.min(C+v.nodeSize,d.doc.content.size)))),p.dispatch(M(d).scrollIntoView())}function ie({getView:p,store:s,transport:n,acceptState:i=()=>globalThis.clay?.save?.flush?.(),newId:a=R}){let r=n?J({transport:n,newId:()=>a("request")}):null,t=null,m=0,c=()=>{m++,t&&(r?.discard(t.pending),t.preview?.dispose(),t.previewHost?.dispose(),t.element.remove(),t=null)};return{open:({target:y=null,remove:v=null}={})=>{c();let o=p();if(!o)return;let d=o.state.selection,w={hostId:o.state.doc.child(Math.min(d.$head.index(0),o.state.doc.childCount-1))?.attrs.id,slashText:v?o.state.doc.textBetween(v.from,v.to):null,slashOffset:v&&d.$head.depth?v.from-d.$head.before(1)-1:null},f=o.dom.ownerDocument,g=f.createElement("section");g.className="page-ai-panel",g.contentEditable="false",g.setAttribute("role","dialog"),g.setAttribute("aria-label",y?"Revise tool":"Make a tool with AI");let E=f.createElement("textarea");E.setAttribute("aria-label","Describe the tool"),E.placeholder=y?"What should change?":"Describe the tool you want";let A=f.createElement("p");A.className="page-ai-status";let S=f.createElement("div");S.className="page-ai-preview";let T=f.createElement("div");T.className="page-ai-actions",g.append(E,A,S,T),o.dom.parentElement.append(g),t={element:g,input:E,status:A,previewRoot:S,actions:T,target:y,bookmark:w,candidate:null,pending:null,preview:null,previewHost:null,kept:!1,busy:!1};let x=(e,u)=>{let h=f.createElement("button");h.type="button",h.textContent=e,h.addEventListener("click",u),T.append(h)},z=()=>{t&&(t.preview?.dispose(),t.previewHost?.dispose(),t.preview=null,t.previewHost=null,t.previewRoot.replaceChildren(),t.input.hidden=!1,t.actions.replaceChildren(),x("Generate",D),x("Cancel",c),t.input.focus())},_=()=>{let e=t;e.input.hidden=!0,e.status.textContent="",e.previewHost=L({mode:"view"}),e.preview=e.previewHost.mount(e.previewRoot,{id:"preview",rev:"preview",artifact:e.candidate.artifact,seed:e.candidate.state}),e.actions.replaceChildren(),x("Keep",H),x("Revise",z),x("Discard",c)},D=async()=>{let e=t;if(!e||e.busy||!e.input.value.trim())return;if(!r){e.status.textContent="Tool generation is unavailable";return}e.busy=!0,e.status.textContent="Making your tool\u2026",e.actions.replaceChildren(),x("Cancel",c);let u=++m,h=r.request(e.input.value.trim(),$(o.state.doc,f.title),e.target);e.pending=h;try{let b=await r.wait(h);if(t!==e||u!==m)return;e.candidate={artifact:b.artifact,state:b.state,id:null,rev:null},_()}catch(b){if(t!==e||u!==m)return;e.status.textContent=b.message,e.actions.replaceChildren(),x("Generate",D),x("Cancel",c)}finally{e.busy=!1}},H=async()=>{let e=t;if(!e?.candidate||e.busy||e.kept)return;e.busy=!0;let u=e.candidate;u.id??=e.target?.toolId??a("b"),u.rev??=a("rev");try{if(!s)throw new Error("This document can't save tool state");await s.set([u.id,u.rev],u.state);let h=await i();if(h?.ok!==!0&&!["saved","clean"].includes(h?.state))throw new Error(h?.msg??h?.message??"Tool state was not saved");if(t!==e||e.kept)return;if(e.target){let b=W(o.state.doc,e.target.toolId);if(b?.node.type!==q.nodes.tool||b.node.attrs.rev!==e.target.rev){e.status.textContent="This tool changed while you were revising. Keep as a new tool, or discard.",e.target=null,u.id=null,u.rev=null,e.actions.replaceChildren(),x("Keep as new tool",H),x("Discard",c);return}o.dispatch(M(o.state.tr.setNodeMarkup(b.at,null,{...b.node.attrs,artifact:u.artifact,rev:u.rev})))}else j(o,u,e.bookmark);e.kept=!0,c()}catch(h){t===e&&(e.status.textContent=h.message)}finally{e.busy=!1}};return z(),g},dispose:c}}export{ie as createAiTool};
@@ -1 +1 @@
1
- import{a as $}from"./c-XQXZAO7N.js";import{e as Y}from"./c-S7LK4KUE.js";import{c as z}from"./c-VG5XIN4T.js";import{b as H,i as I,o as N}from"./c-HA6INT6J.js";import{c as D,h as A,j as T,k,n as C,o as L}from"./c-DCFSEJZG.js";var K=[],i=[],g=new WeakMap,w=null,B=null,b=0;function de(){return b}function V(e){return g.get(e)||null}var M=new WeakMap,v=null;function he(){return v}function me(e){v&&e&&(v.artifact=e)}var R=null,x=new Map;function ye(e){R=e}function ve(e){return e==null?null:x.get(e)??null}function Se(e){return e&&M.get(e)||null}function j(e){e&&(M.delete(e),x.delete(e.captureId))}function W(e){let t=o=>{if(o.hasAttribute("onbeforesave")||o.hasAttribute("onbeforesnapshot"))return!0;let r=o.localName==="template"&&o.content?o.content:o;for(let n of r.children)if(t(n))return!0;return!1};return e.nodeType===1?t(e):!1}function l(e){for(let t of e.querySelectorAll(L))t.remove()}function h(e,t){for(let o of e.querySelectorAll(`[${t}]`))if(l(e),!(o!==e&&!e.contains(o)))try{new Function(o.getAttribute(t)).call(o)}catch(r){console.error(`[${t}] handler failed:`,r)}}var O=null;function Ce(e){O=e}function xe(e){return O?.(e),e}function Ae(e){K.push(e)}function Te(e,{steps:t=null}={}){w=e,B=t}var G="http://www.w3.org/1999/xhtml";function P(e){let t=X(e);if(!t.length)return"<!DOCTYPE html>"+e.outerHTML;let o=J(t),r;try{r="<!DOCTYPE html>"+e.outerHTML}finally{for(let[n,c]of t)n.replaceChildren(...c)}for(let[n,c]of o)r=r.split(n).join(c);return r}function X(e){let t=[],o=r=>{for(let n of r.childNodes)if(n.nodeType===1){if(n.localName==="noscript"&&n.namespaceURI===G){let c=Array.from(n.childNodes);c.length&&c.every(a=>a.nodeType===3)&&t.push([n,c]);continue}o(n.localName==="template"&&n.content?n.content:n)}};return o(e),t}function J(e){let t=Math.random().toString(36).slice(2);return e.map(([o,r],n)=>{let c=`\uE000clay-noscript-${t}-${n}\uE000`;return o.replaceChildren(o.ownerDocument.createTextNode(c)),[c,r.map(a=>a.data).join("")]})}function U(e,t){let o=v;v=e;try{return t()}finally{v=o}}function q(e,t=null){if(t&&R){let r=null;try{r=R(e)}catch{}r&&x.set(t.captureId,r)}let o=P(e);if(!w)return o;try{return U(t,()=>w(e,o))}catch(r){return console.error("clayjs: save renderer failed, sending the full serialization",r),o}}function ge(e){i.push(e)}function d(e,t=!0){let o=window.__preventOnclone;window.__preventOnclone=!0;try{return e.cloneNode(t)}finally{window.__preventOnclone=o}}function E(e,t){let o=g.get(e);o&&g.set(t,o);let r=e.children,n=t.children;for(let c=0;c<r.length;c++)E(r[c],n[c])}function f({flushUndo:e=!0,authored:t=!0,forSave:o=!1,requestRefresh:r=!1,context:n=null}={}){e&&typeof window<"u"&&window.clay?.undo?.flush&&window.clay.undo.flush();let a=$(document.documentElement,{capability:"snapshot",provenance:g}).root;for(let m of K)l(a),m(a,{original:V,forSave:o,requestRefresh:r});return Y(a),O?.(a),l(a),n&&(n.authoredHandlers=W(a)),t&&h(a,"onbeforesnapshot"),l(a),D(a),N(a),H(a),a}function _(e,{authored:t=!0}={}){l(e),t&&h(e,"onbeforesave");for(let o of i)l(e),o(e);l(e);for(let o of e.querySelectorAll(A))o.remove();return F(e),e}function F(e){for(let t of e.querySelectorAll("[sap-error]"))t.removeAttribute("sap-error")}function Q({flushUndo:e=!0,authored:t=!0}={}){return _(f({flushUndo:e,authored:t}),{authored:t})}var Z=["style","class"];function ee(e){z(e);for(let t of Z){e.getAttribute(t)===""&&e.removeAttribute(t);for(let o of e.querySelectorAll(`[${t}=""]`))o.removeAttribute(t)}}function S(e){return ee(e),"<!DOCTYPE html>"+e.outerHTML}function we({flushUndo:e=!0}={}){let t=f({flushUndo:e});h(t,"onbeforesave");for(let o of t.querySelectorAll(T))o.remove();for(let o of i)l(t),o(t);return l(t),S(t)}function Re({flushUndo:e=!0}={}){let t=f({flushUndo:e});h(t,"onbeforesave");for(let o of t.querySelectorAll(C))o.remove();for(let o of i)l(t),o(t);return l(t),S(t)}function Ee({flushUndo:e=!0}={}){let t=f({flushUndo:e});h(t,"onbeforesave");let o=t.querySelector(k)?d(t):null;o&&E(t,o);for(let c of t.querySelectorAll(T))c.remove();for(let c of i)l(t),c(t);l(t);let r=S(t),n=r;if(o){for(let c of o.querySelectorAll(C))c.remove();for(let c of i)l(o),c(o);l(o),n=S(o)}return{forComparison:r,forDirty:n}}function te({emitForSync:e=!0,flushUndo:t=!0,requestRefresh:o=!1,forRequest:r=!1,pageFormatMarker:n=null,sliced:c=!1}={}){if(!Number.isSafeInteger(b+1))throw new Error("Save capture identity exhausted");let a=++b,m=r?{captureId:a,authoredHandlers:!1,artifact:null}:null,u=f({flushUndo:t,forSave:e,requestRefresh:o,context:m});e&&document.dispatchEvent(new CustomEvent("clay:snapshot-ready",{detail:{documentElement:u,forSave:!0,captureId:a,sliced:c}})),h(u,"onbeforesave");let y=d(u);E(u,y);let p=u.querySelector(k)?d(u):null;p&&E(u,p);for(let s of i)l(u),s(u);l(u);for(let s of u.querySelectorAll(A))s.remove();F(u);for(let s of y.querySelectorAll(T))s.remove();for(let s of i)l(y),s(y);if(l(y),p){for(let s of p.querySelectorAll(C))s.remove();for(let s of i)l(p),s(p);l(p)}return{captureId:a,context:m,pageFormatMarker:n,clone:u,compareClone:y,dirtyClone:p,renderer:w,rendererSteps:B,pageStateReader:R,result:null}}function oe(e){if(!e.context||!e.pageStateReader)return;let t=null;try{t=e.pageStateReader(e.clone)}catch{}t&&x.set(e.captureId,t)}function re(e,{forSave:t,forComparison:o,forDirty:r}){let n={forSave:t,forComparison:o,forDirty:r,captureId:e.captureId};return e.context&&e.context.artifact&&M.set(n,e.context.artifact),e.result=n,n}function ne(e){j(e.result),x.delete(e.captureId),e.context&&(e.context.artifact=null),e.clone=e.compareClone=e.dirtyClone=null,e.result=null}function _e(e={}){let t=te(e);try{oe(t);let o=P(t.clone),r=t.compareClone?S(t.compareClone):null,n=t.dirtyClone?S(t.dirtyClone):r,c=t.renderer?U(t.context,()=>t.renderer(t.clone,o)):o;return re(t,{forSave:c,forComparison:r,forDirty:n})}catch(o){throw ne(t),o}}function ke(){let e=f({flushUndo:!1});h(e,"onbeforesave");let t=d(e),o=new WeakMap;(function r(n,c){o.set(n,c);let a=n.children,m=c.children;for(let u=0;u<a.length;u++)r(a[u],m[u])})(t,e);for(let r of i)l(e),r(e);l(e);for(let r of e.querySelectorAll(A))r.remove();F(e);for(let r of t.querySelectorAll(C))r.remove();for(let r of i)l(t),r(t);return l(t),{saveClone:e,compareClone:t,pairMap:o}}function ce({emitForSync:e=!0}={}){let t=f();return e&&document.dispatchEvent(new CustomEvent("clay:snapshot-ready",{detail:{documentElement:t}})),q(_(t))}function be(e){let t=d(e,!1);for(let n of I)t.removeAttribute(n);let o=t.outerHTML,r=`</${t.localName}>`;return"<!DOCTYPE html>"+o.slice(0,o.length-r.length)+e.innerHTML+r}function Me(e){return d(e)}function Oe(){return f().querySelector("body").innerHTML}function Pe({transform:e=null,flushUndo:t=!0}={}){if(!e&&t)return ce({emitForSync:!1});let o=f({flushUndo:t});if(e){let r=e(o);if(r&&typeof r.then=="function")throw new TypeError("getHTML: the transform must be synchronous")}return q(_(o))}function qe(e,{prepared:t=!1}={}){let o=d(e);return P(t?o:_(o,{authored:!1}))}function Fe(){return q(Q({flushUndo:!1,authored:!1}))}export{de as a,V as b,he as c,me as d,ye as e,ve as f,Se as g,j as h,Ce as i,xe as j,Ae as k,Te as l,P as m,X as n,J as o,U as p,ge as q,d as r,f as s,Q as t,ee as u,S as v,we as w,Re as x,Ee as y,te as z,oe as A,re as B,ne as C,_e as D,ke as E,ce as F,be as G,Me as H,Oe as I,Pe as J,qe as K,Fe as L};
1
+ import{a as $}from"./c-XQXZAO7N.js";import{e as Y}from"./c-S7LK4KUE.js";import{c as z}from"./c-VG5XIN4T.js";import{b as H,i as I,o as N}from"./c-HA6INT6J.js";import{c as D,h as A,j as T,k,n as C,o as L}from"./c-ICMAOOGK.js";var K=[],i=[],g=new WeakMap,w=null,B=null,b=0;function de(){return b}function V(e){return g.get(e)||null}var M=new WeakMap,v=null;function he(){return v}function me(e){v&&e&&(v.artifact=e)}var R=null,x=new Map;function ye(e){R=e}function ve(e){return e==null?null:x.get(e)??null}function Se(e){return e&&M.get(e)||null}function j(e){e&&(M.delete(e),x.delete(e.captureId))}function W(e){let t=o=>{if(o.hasAttribute("onbeforesave")||o.hasAttribute("onbeforesnapshot"))return!0;let r=o.localName==="template"&&o.content?o.content:o;for(let n of r.children)if(t(n))return!0;return!1};return e.nodeType===1?t(e):!1}function l(e){for(let t of e.querySelectorAll(L))t.remove()}function h(e,t){for(let o of e.querySelectorAll(`[${t}]`))if(l(e),!(o!==e&&!e.contains(o)))try{new Function(o.getAttribute(t)).call(o)}catch(r){console.error(`[${t}] handler failed:`,r)}}var O=null;function Ce(e){O=e}function xe(e){return O?.(e),e}function Ae(e){K.push(e)}function Te(e,{steps:t=null}={}){w=e,B=t}var G="http://www.w3.org/1999/xhtml";function P(e){let t=X(e);if(!t.length)return"<!DOCTYPE html>"+e.outerHTML;let o=J(t),r;try{r="<!DOCTYPE html>"+e.outerHTML}finally{for(let[n,c]of t)n.replaceChildren(...c)}for(let[n,c]of o)r=r.split(n).join(c);return r}function X(e){let t=[],o=r=>{for(let n of r.childNodes)if(n.nodeType===1){if(n.localName==="noscript"&&n.namespaceURI===G){let c=Array.from(n.childNodes);c.length&&c.every(a=>a.nodeType===3)&&t.push([n,c]);continue}o(n.localName==="template"&&n.content?n.content:n)}};return o(e),t}function J(e){let t=Math.random().toString(36).slice(2);return e.map(([o,r],n)=>{let c=`\uE000clay-noscript-${t}-${n}\uE000`;return o.replaceChildren(o.ownerDocument.createTextNode(c)),[c,r.map(a=>a.data).join("")]})}function U(e,t){let o=v;v=e;try{return t()}finally{v=o}}function q(e,t=null){if(t&&R){let r=null;try{r=R(e)}catch{}r&&x.set(t.captureId,r)}let o=P(e);if(!w)return o;try{return U(t,()=>w(e,o))}catch(r){return console.error("clayjs: save renderer failed, sending the full serialization",r),o}}function ge(e){i.push(e)}function d(e,t=!0){let o=window.__preventOnclone;window.__preventOnclone=!0;try{return e.cloneNode(t)}finally{window.__preventOnclone=o}}function E(e,t){let o=g.get(e);o&&g.set(t,o);let r=e.children,n=t.children;for(let c=0;c<r.length;c++)E(r[c],n[c])}function f({flushUndo:e=!0,authored:t=!0,forSave:o=!1,requestRefresh:r=!1,context:n=null}={}){e&&typeof window<"u"&&window.clay?.undo?.flush&&window.clay.undo.flush();let a=$(document.documentElement,{capability:"snapshot",provenance:g}).root;for(let m of K)l(a),m(a,{original:V,forSave:o,requestRefresh:r});return Y(a),O?.(a),l(a),n&&(n.authoredHandlers=W(a)),t&&h(a,"onbeforesnapshot"),l(a),D(a),N(a),H(a),a}function _(e,{authored:t=!0}={}){l(e),t&&h(e,"onbeforesave");for(let o of i)l(e),o(e);l(e);for(let o of e.querySelectorAll(A))o.remove();return F(e),e}function F(e){for(let t of e.querySelectorAll("[sap-error]"))t.removeAttribute("sap-error")}function Q({flushUndo:e=!0,authored:t=!0}={}){return _(f({flushUndo:e,authored:t}),{authored:t})}var Z=["style","class"];function ee(e){z(e);for(let t of Z){e.getAttribute(t)===""&&e.removeAttribute(t);for(let o of e.querySelectorAll(`[${t}=""]`))o.removeAttribute(t)}}function S(e){return ee(e),"<!DOCTYPE html>"+e.outerHTML}function we({flushUndo:e=!0}={}){let t=f({flushUndo:e});h(t,"onbeforesave");for(let o of t.querySelectorAll(T))o.remove();for(let o of i)l(t),o(t);return l(t),S(t)}function Re({flushUndo:e=!0}={}){let t=f({flushUndo:e});h(t,"onbeforesave");for(let o of t.querySelectorAll(C))o.remove();for(let o of i)l(t),o(t);return l(t),S(t)}function Ee({flushUndo:e=!0}={}){let t=f({flushUndo:e});h(t,"onbeforesave");let o=t.querySelector(k)?d(t):null;o&&E(t,o);for(let c of t.querySelectorAll(T))c.remove();for(let c of i)l(t),c(t);l(t);let r=S(t),n=r;if(o){for(let c of o.querySelectorAll(C))c.remove();for(let c of i)l(o),c(o);l(o),n=S(o)}return{forComparison:r,forDirty:n}}function te({emitForSync:e=!0,flushUndo:t=!0,requestRefresh:o=!1,forRequest:r=!1,pageFormatMarker:n=null,sliced:c=!1}={}){if(!Number.isSafeInteger(b+1))throw new Error("Save capture identity exhausted");let a=++b,m=r?{captureId:a,authoredHandlers:!1,artifact:null}:null,u=f({flushUndo:t,forSave:e,requestRefresh:o,context:m});e&&document.dispatchEvent(new CustomEvent("clay:snapshot-ready",{detail:{documentElement:u,forSave:!0,captureId:a,sliced:c}})),h(u,"onbeforesave");let y=d(u);E(u,y);let p=u.querySelector(k)?d(u):null;p&&E(u,p);for(let s of i)l(u),s(u);l(u);for(let s of u.querySelectorAll(A))s.remove();F(u);for(let s of y.querySelectorAll(T))s.remove();for(let s of i)l(y),s(y);if(l(y),p){for(let s of p.querySelectorAll(C))s.remove();for(let s of i)l(p),s(p);l(p)}return{captureId:a,context:m,pageFormatMarker:n,clone:u,compareClone:y,dirtyClone:p,renderer:w,rendererSteps:B,pageStateReader:R,result:null}}function oe(e){if(!e.context||!e.pageStateReader)return;let t=null;try{t=e.pageStateReader(e.clone)}catch{}t&&x.set(e.captureId,t)}function re(e,{forSave:t,forComparison:o,forDirty:r}){let n={forSave:t,forComparison:o,forDirty:r,captureId:e.captureId};return e.context&&e.context.artifact&&M.set(n,e.context.artifact),e.result=n,n}function ne(e){j(e.result),x.delete(e.captureId),e.context&&(e.context.artifact=null),e.clone=e.compareClone=e.dirtyClone=null,e.result=null}function _e(e={}){let t=te(e);try{oe(t);let o=P(t.clone),r=t.compareClone?S(t.compareClone):null,n=t.dirtyClone?S(t.dirtyClone):r,c=t.renderer?U(t.context,()=>t.renderer(t.clone,o)):o;return re(t,{forSave:c,forComparison:r,forDirty:n})}catch(o){throw ne(t),o}}function ke(){let e=f({flushUndo:!1});h(e,"onbeforesave");let t=d(e),o=new WeakMap;(function r(n,c){o.set(n,c);let a=n.children,m=c.children;for(let u=0;u<a.length;u++)r(a[u],m[u])})(t,e);for(let r of i)l(e),r(e);l(e);for(let r of e.querySelectorAll(A))r.remove();F(e);for(let r of t.querySelectorAll(C))r.remove();for(let r of i)l(t),r(t);return l(t),{saveClone:e,compareClone:t,pairMap:o}}function ce({emitForSync:e=!0}={}){let t=f();return e&&document.dispatchEvent(new CustomEvent("clay:snapshot-ready",{detail:{documentElement:t}})),q(_(t))}function be(e){let t=d(e,!1);for(let n of I)t.removeAttribute(n);let o=t.outerHTML,r=`</${t.localName}>`;return"<!DOCTYPE html>"+o.slice(0,o.length-r.length)+e.innerHTML+r}function Me(e){return d(e)}function Oe(){return f().querySelector("body").innerHTML}function Pe({transform:e=null,flushUndo:t=!0}={}){if(!e&&t)return ce({emitForSync:!1});let o=f({flushUndo:t});if(e){let r=e(o);if(r&&typeof r.then=="function")throw new TypeError("getHTML: the transform must be synchronous")}return q(_(o))}function qe(e,{prepared:t=!1}={}){let o=d(e);return P(t?o:_(o,{authored:!1}))}function Fe(){return q(Q({flushUndo:!1,authored:!1}))}export{de as a,V as b,he as c,me as d,ye as e,ve as f,Se as g,j as h,Ce as i,xe as j,Ae as k,Te as l,P as m,X as n,J as o,U as p,ge as q,d as r,f as s,Q as t,ee as u,S as v,we as w,Re as x,Ee as y,te as z,oe as A,re as B,ne as C,_e as D,ke as E,ce as F,be as G,Me as H,Oe as I,Pe as J,qe as K,Fe as L};
@@ -1 +1 @@
1
- import{c as M,g as _,h as A,w as q}from"./c-4TXNLX4K.js";import{B as G}from"./c-AMU3BPPR.js";import{D as O,G as $,I as y,J as B,M as R,Z as j,_ as U,b as z,m as p,na as F}from"./c-QIXT3Q7C.js";import{a as x}from"./c-WCXLG3MV.js";import{a as K}from"./c-I2SCCUEW.js";var{TextSelection:J}=z,S=new WeakMap,D=new Set;function g(n,t){let e=null;return n.forEach(s=>{s.type===p.nodes.table&&s.attrs.id===t&&(e=s)}),e}function N(n){return n?F({[n.attrs.id]:R(n)})[0]:null}function Q(n,t,e){let s=y(n.attrs.cols);if(!s.length)return null;let i=M(n),a=s.filter(r=>r!==s[0]&&i[r]==="number");return a.length?{id:B(),pos:t,parent:e,source:n.attrs.id,kind:"bar",x:s[0],series:a,title:"",highlight:null}:null}function wt(n,t){let e=n.state.doc,s=e.nodeAt(t);if(s?.type!==p.nodes.table)return!1;let i=t+s.nodeSize,a=e.maybeChild(e.resolve(i).index(0)),r=Q(s,$(s.attrs.pos,a?.attrs.pos??null),s.attrs.parent);return r?(D.add(r.id),n.dispatch(n.state.tr.insert(i,p.nodes.chart.create(r))),!0):(x("This table has no number column to chart yet."),!0)}function W(n,t,e,s){let i=n.state.tr;if(s&&i.delete(s.from,s.to),!g(i.doc,e.attrs.id)||t>=i.doc.childCount)return!1;let a=0;for(let m=0;m<t;m++)a+=i.doc.child(m).nodeSize;let r=i.doc.child(t),c=r.isTextblock&&r.content.size===0,h=i.doc.maybeChild(t+1),f=c?r.attrs.pos:$(r.attrs.pos,h?.attrs.pos??null),d=Q(e,f,r.attrs.parent??null);if(!d)return s&&n.dispatch(n.state.tr.delete(s.from,s.to)),x("This table has no number column to chart yet."),!0;let w=p.nodes.chart.create(d);return i=c?i.replaceWith(a,a+r.nodeSize,w):i.insert(a+r.nodeSize,w),D.add(d.id),n.dispatch(i.scrollIntoView()),!0}var X=n=>y(n.attrs.cols).map(t=>n.attrs.cols[t].name||"Untitled").join(", ");function kt(n,t,e=null){let s=_(n.state.doc);if(!s.length)return e&&n.dispatch(n.state.tr.delete(e.from,e.to)),x("Add a table first: a chart plots the numbers in a table on this page."),!0;if(s.length===1)return W(n,t,s[0],e);let i=n.state.doc,a=n.nodeDOM(i.resolve(n.state.selection.head).before(1))??n.dom;return q(n,a,s.map(r=>({label:A(i,r.attrs.id)??"",description:`${r.childCount} ${r.childCount===1?"row":"rows"} \xB7 ${X(r)}`,icon:"\u25A6",run:()=>W(n,t,r,e)})))}var V=n=>`<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${n}</svg>`,Z=V('<rect x="2.5" y="3" width="11" height="10" rx="1.5"/><path d="M2.5 6.5h11M6 6.5V13"/>'),tt=V('<g transform="scale(0.6667)" stroke-width="2.25"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></g>'),et=V('<path d="M2.75 4.5h10.5M6.25 4.5V2.75h3.5V4.5M4.25 4.5l.6 8.75h6.3l.6-8.75"/>'),st=[["bar","Bar"],["line","Line"],["pie","Pie"]],it="Untitled chart";function nt(n,t){let e=null;return n.forEach((s,i)=>{e===null&&s.type===p.nodes.table&&s.attrs.id===t&&(e=i)}),e}function E(n){let t=[];return n.forEach(e=>{e.type===p.nodes.table&&y(e.attrs.cols).length>1&&t.push(e)}),t.map(e=>({id:e.attrs.id,name:A(n,e.attrs.id),rows:e.childCount}))}function at(n){let t=y(n.attrs.cols);if(!t.length)return null;let e=M(n),s=t.find(a=>e[a]!=="number")??t[0],i=t.filter(a=>a!==s&&e[a]==="number");return{x:s,series:i.length?i:t.filter(a=>a!==s).slice(0,1)}}function l(n,t,e,s=null){let i=n.createElement(t);return e&&(i.className=e),s!==null&&(i.textContent=s),i}function C(n,t,e,s=!1){let i=l(n,"option","",e);return i.value=t,i.selected=s,i}function T(n,t,e){let s=l(n,"select","page-chart-select");return s.dataset.field=t,s.setAttribute("aria-label",e),s}var Y=class{constructor(t,e,s){this.node=t,this.view=e,this.getPos=s,this.source=void 0,this.tables=null,this.frame=null,this.unsaved=null,this.titleInput=null;let i=e.dom.ownerDocument;this.doc=i,this.dom=i.createElement("figure"),this.dom.className="page-chart",this.dom.dataset.id=t.attrs.id??"",this.dom.dataset.type="chart",this.head=l(i,"div","page-chart-head"),this.head.contentEditable="false",this.title=l(i,"span","page-chart-title"),this.chip=l(i,"button","page-chart-source"),this.chip.type="button",this.chip.contentEditable="false",this.chip.setAttribute("aria-label","Go to source table"),this.chip.innerHTML=Z,this.chipName=l(i,"span","page-chart-source-name"),this.chip.append(this.chipName),this.chip.addEventListener("click",()=>this.goToSource()),this.edit=l(i,"button","page-chart-edit"),this.edit.type="button",this.edit.contentEditable="false",this.edit.setAttribute("aria-haspopup","dialog"),this.edit.setAttribute("aria-expanded","false"),this.edit.innerHTML=tt,this.edit.append("Edit chart"),this.edit.addEventListener("click",()=>this.panel.isConnected?this.closePanel(!0):this.openPanel()),this.head.append(this.title,this.chip,this.edit),this.plot=l(i,"div","page-chart-plot"),this.broken=l(i,"div","page-chart-broken"),this.broken.hidden=!0,this.broken.contentEditable="false",this.brokenKey=null,this.brokenSelect=null,this.broken.addEventListener("click",a=>this.brokenClick(a)),this.panel=l(i,"div","page-chart-panel"),this.panel.tabIndex=-1,this.panel.contentEditable="false",this.panel.setAttribute("role","dialog"),this.panel.setAttribute("aria-label","Chart settings"),this.panel.addEventListener("click",a=>this.panelClick(a)),this.panel.addEventListener("change",a=>this.panelChange(a)),this.panel.addEventListener("mousedown",a=>{a.target.closest?.("button")&&a.preventDefault()}),this.outside=a=>{!this.panel.isConnected||this.dom.contains(a.target)||(this.commitTitle(),this.closePanel())},this.escape=a=>{!this.panel.isConnected||a.key!=="Escape"||(a.preventDefault(),a.stopPropagation(),this.closePanel(!0))},i.addEventListener("mousedown",this.outside,!0),i.addEventListener("keydown",this.escape,!0),this.dom.append(this.head,this.plot,this.broken),S.has(e)||S.set(e,new Set),S.get(e).add(this),this.refresh(),D.delete(t.attrs.id)&&this.openSoon()}refresh(){this.renderHead(),this.panel.isConnected&&this.panelKey()!==this.renderedKey&&this.redrawPanel();let t=this.view.state.doc,e=g(t,this.node.attrs.source),s=E(t).map(i=>`${i.id}:${i.name}:${i.rows}`).join("|");e===this.source&&s===this.tables||(this.source=e,this.tables=s,this.schedule())}schedule(){if(this.frame!==null)return;let t=this.dom.ownerDocument.defaultView,e=t.requestAnimationFrame?.bind(t)??(s=>t.setTimeout(s,0));this.frame=e(()=>{this.frame=null,this.draw()})}draw(){let t=this.node.attrs,e=j({id:t.id,type:t.kind,x:t.x,series:t.series,title:t.title,highlight:t.highlight},N(this.source));this.plot.innerHTML=U(e,{width:640,height:320,narrow:this.dom.getBoundingClientRect().width<480}),this.renderBroken(e)}renderBroken(t){let e=t.state==="missing"&&t.reason==="table";if(this.plot.hidden=e,this.broken.hidden=!e,!e){this.brokenKey!==null&&(this.broken.textContent="",this.brokenKey=null,this.brokenSelect=null);return}let s=E(this.view.state.doc),i=s.map(h=>`${h.id}:${h.name}:${h.rows}`).join("|");if(this.brokenKey===i)return;this.brokenKey=i,this.brokenSelect=null;let a=this.doc;this.broken.textContent="",this.broken.append(l(a,"div","page-chart-broken-head","This chart's table was deleted"),l(a,"p","page-chart-broken-text","Pick another table in this document, or delete the chart. Undo brings the table back."));let r=l(a,"div","page-chart-broken-actions");if(s.length){let h=T(a,"rescue","Source table");for(let d of s)h.append(C(a,d.id,`${d.name} (${d.rows} ${d.rows===1?"row":"rows"})`));this.brokenSelect=h;let f=l(a,"button","page-chart-use","Use this table");f.type="button",f.dataset.action="use",r.append(h,f)}let c=l(a,"button","page-chart-delete","Delete chart");c.type="button",c.dataset.action="delete",r.append(c),this.broken.append(r)}brokenClick(t){let e=t.target.closest?.("button[data-action]");e&&(e.dataset.action==="delete"?this.removeChart():e.dataset.action==="use"&&this.switchSource(this.brokenSelect?.value??""))}openSoon(){let t=this.dom.ownerDocument.defaultView;(t.requestAnimationFrame?.bind(t)??(s=>t.setTimeout(s,0)))(()=>{!this.view.isDestroyed&&this.dom.isConnected&&this.openPanel()})}renderHead(){let t=this.node.attrs,e=A(this.view.state.doc,t.source),s=!g(this.view.state.doc,t.source);this.title.textContent=t.title||it,this.title.classList.toggle("is-empty",!t.title),this.chipName.textContent=s?"No table":e??"",this.chip.disabled=s}setAttrs(t){let e=this.getPos();if(e==null)return;let s=this.view.state.doc.nodeAt(e);s?.type===p.nodes.chart&&this.view.dispatch(this.view.state.tr.setNodeMarkup(e,null,{...s.attrs,...t}))}row(t,...e){let s=l(this.doc,"div","page-chart-row");return t&&s.append(l(this.doc,"span","page-chart-label",t)),s.append(...e),s}panelKey(){let t=this.view.state.doc,e=E(t).map(s=>`${s.id}:${s.name}:${s.rows}`).join("|");return JSON.stringify([this.node.attrs,e,N(g(t,this.node.attrs.source))])}redrawPanel(){let t=this.doc.activeElement,e=t&&this.panel.contains(t)?t.dataset??{}:null,s=this.titleInput,i=s&&s.value!==this.renderedTitle?{value:s.value,start:s.selectionStart,end:s.selectionEnd}:null;if(this.renderPanel(),i&&this.titleInput&&(this.titleInput.value=i.value),!e)return;let a=[...this.panel.querySelectorAll("button, input, select")].find(r=>["field","kind","col","action"].every(c=>r.dataset[c]===e[c]));if(!a)return this.panel.focus();a.focus(),i&&a===this.titleInput&&a.setSelectionRange?.(i.start,i.end)}renderPanel(){let t=this.doc;this.renderedKey=this.panelKey(),this.renderedTitle=this.node.attrs.title??"";let e=this.node.attrs,s=N(this.source),i=s?.cols??[],a=s?.rows??[],r=e.kind==="pie";this.unsaved?.dispose(),this.unsaved=null,this.titleInput=null,this.panel.textContent="";let c=l(t,"div","page-chart-types");for(let[o,P]of st){let b=l(t,"button","page-chart-type",P);b.type="button",b.dataset.kind=o,b.setAttribute("aria-pressed",String(e.kind===o)),c.append(b)}this.panel.append(this.row("Chart type",c));let h=T(t,"source","Source table");for(let o of E(this.view.state.doc))h.append(C(t,o.id,`${o.name} (${o.rows} ${o.rows===1?"row":"rows"})`,o.id===e.source));this.panel.append(this.row("Source table",h));let f=T(t,"labels","Labels column");for(let o of i)f.append(C(t,o.id,o.name||o.id,o.id===e.x));this.panel.append(this.row("Labels column",f));let d=l(t,"div","page-chart-values");i.filter(o=>o.id!==e.x).forEach((o,P)=>{let b=l(t,"label","page-chart-value"),v=l(t,"input");v.type="checkbox",v.dataset.field="series",v.dataset.col=o.id,v.checked=e.series.includes(o.id);let I=l(t,"span","page-chart-swatch");I.style.background=`var(--chart-${P%6+1})`,I.setAttribute("aria-hidden","true"),b.append(v,I,l(t,"span","page-chart-value-name",o.name||o.id)),d.append(b)});let w=this.row(r?"Value column":"Value columns",d);r&&w.append(l(t,"span","page-chart-hint","Pie charts plot the first value column across rows.")),this.panel.append(w);let m=T(t,"highlight","Highlight row");m.append(C(t,"","None",!e.highlight));for(let o of a)m.append(C(t,o.id,O(o.cells?.[e.x])||o.id,o.id===e.highlight));this.panel.append(this.row("Highlight row",m));let u=l(t,"input","page-chart-title-input");u.type="text",u.dataset.field="title",u.setAttribute("aria-label","Chart title"),u.value=e.title??"",u.addEventListener("keydown",o=>{o.isComposing||o.keyCode===229||o.key==="Enter"&&(o.preventDefault(),o.stopPropagation(),this.commitTitle())}),u.addEventListener("change",()=>this.commitTitle()),u.addEventListener("blur",()=>this.commitTitle()),this.titleInput=u,this.panel.append(this.row("Chart title",u));let H=l(t,"div","page-chart-foot"),k=l(t,"button","page-chart-remove");k.type="button",k.dataset.action="remove",k.innerHTML=et,k.append("Remove");let L=l(t,"button","page-chart-done","Done");L.type="button",L.dataset.action="done",H.append(k,L),this.panel.append(H),this.unsaved=K({id:"chart-title",isPending:()=>u.isConnected&&u.value!==(this.node.attrs.title??"")})}openPanel(){this.panel.isConnected||(this.renderPanel(),this.dom.append(this.panel),this.edit.setAttribute("aria-expanded","true"),this.panel.focus())}closePanel(t=!1){this.panel.isConnected&&(this.unsaved?.dispose(),this.unsaved=null,this.titleInput=null,this.panel.remove(),this.edit.setAttribute("aria-expanded","false"),t&&this.edit.focus())}panelClick(t){let e=t.target.closest?.("button");e&&(e.dataset.action==="done"?(this.commitTitle(),this.closePanel(!0)):e.dataset.action==="remove"?this.removeChart():e.dataset.kind&&this.setAttrs({kind:e.dataset.kind}))}panelChange(t){let e=t.target;if(e?.dataset){if(e.dataset.field==="source")this.switchSource(e.value);else if(e.dataset.field==="labels")this.setAttrs({x:e.value,series:this.node.attrs.series.filter(s=>s!==e.value)});else if(e.dataset.field==="highlight")this.setAttrs({highlight:e.value||null});else if(e.dataset.field==="series"){let s=this.node.attrs.series.filter(i=>i!==e.dataset.col);this.setAttrs({series:e.checked?[...s,e.dataset.col]:s})}}}switchSource(t){let e=g(this.view.state.doc,t),s=e?at(e):null;s&&this.setAttrs({source:t,x:s.x,series:s.series})}commitTitle(){let t=this.titleInput;!t||t.value===(this.node.attrs.title??"")||this.setAttrs({title:t.value})}goToSource(){let t=this.view.state.doc,e=nt(t,this.node.attrs.source),s=e===null?null:t.nodeAt(e);if(!s?.childCount||!s.child(0).childCount)return;let i=e+3;this.view.dispatch(this.view.state.tr.setSelection(J.create(t,i)).scrollIntoView()),this.view.focus?.()}removeChart(){let t=this.getPos();if(t==null)return;let e=this.view.state.doc.nodeAt(t);if(e?.type!==p.nodes.chart)return;this.closePanel();let s=this.view.state.tr.delete(t,t+e.nodeSize);s.setSelection(J.near(s.doc.resolve(Math.min(t,s.doc.content.size)),-1)),this.view.dispatch(G(s).scrollIntoView())}update(t){if(t.type!==p.nodes.chart)return!1;let e=!t.sameMarkup(this.node);return this.node=t,this.dom.dataset.id=t.attrs.id??"",e&&(this.source=g(this.view.state.doc,t.attrs.source),this.renderHead(),this.schedule()),!0}stopEvent(t){return!!t.target.closest?.(".page-chart-head, .page-chart-panel")}destroy(){if(this.unsaved?.dispose(),this.unsaved=null,this.doc.removeEventListener("mousedown",this.outside,!0),this.doc.removeEventListener("keydown",this.escape,!0),S.get(this.view)?.delete(this),this.frame!==null){let t=this.dom.ownerDocument.defaultView;t.cancelAnimationFrame?t.cancelAnimationFrame(this.frame):t.clearTimeout(this.frame)}}};function vt(n){for(let t of S.get(n)??[])t.refresh()}export{wt as a,X as b,kt as c,Y as d,vt as e};
1
+ import{c as M,g as _,h as A,w as q}from"./c-SJPD46ZO.js";import{B as G}from"./c-44B5ODN7.js";import{D as O,G as $,I as y,J as B,M as R,Z as j,_ as U,b as z,m as p,na as F}from"./c-QIXT3Q7C.js";import{a as x}from"./c-E4IBSAQM.js";import{a as K}from"./c-I2SCCUEW.js";var{TextSelection:J}=z,S=new WeakMap,D=new Set;function g(n,t){let e=null;return n.forEach(s=>{s.type===p.nodes.table&&s.attrs.id===t&&(e=s)}),e}function N(n){return n?F({[n.attrs.id]:R(n)})[0]:null}function Q(n,t,e){let s=y(n.attrs.cols);if(!s.length)return null;let i=M(n),a=s.filter(r=>r!==s[0]&&i[r]==="number");return a.length?{id:B(),pos:t,parent:e,source:n.attrs.id,kind:"bar",x:s[0],series:a,title:"",highlight:null}:null}function wt(n,t){let e=n.state.doc,s=e.nodeAt(t);if(s?.type!==p.nodes.table)return!1;let i=t+s.nodeSize,a=e.maybeChild(e.resolve(i).index(0)),r=Q(s,$(s.attrs.pos,a?.attrs.pos??null),s.attrs.parent);return r?(D.add(r.id),n.dispatch(n.state.tr.insert(i,p.nodes.chart.create(r))),!0):(x("This table has no number column to chart yet."),!0)}function W(n,t,e,s){let i=n.state.tr;if(s&&i.delete(s.from,s.to),!g(i.doc,e.attrs.id)||t>=i.doc.childCount)return!1;let a=0;for(let m=0;m<t;m++)a+=i.doc.child(m).nodeSize;let r=i.doc.child(t),c=r.isTextblock&&r.content.size===0,h=i.doc.maybeChild(t+1),f=c?r.attrs.pos:$(r.attrs.pos,h?.attrs.pos??null),d=Q(e,f,r.attrs.parent??null);if(!d)return s&&n.dispatch(n.state.tr.delete(s.from,s.to)),x("This table has no number column to chart yet."),!0;let w=p.nodes.chart.create(d);return i=c?i.replaceWith(a,a+r.nodeSize,w):i.insert(a+r.nodeSize,w),D.add(d.id),n.dispatch(i.scrollIntoView()),!0}var X=n=>y(n.attrs.cols).map(t=>n.attrs.cols[t].name||"Untitled").join(", ");function kt(n,t,e=null){let s=_(n.state.doc);if(!s.length)return e&&n.dispatch(n.state.tr.delete(e.from,e.to)),x("Add a table first: a chart plots the numbers in a table on this page."),!0;if(s.length===1)return W(n,t,s[0],e);let i=n.state.doc,a=n.nodeDOM(i.resolve(n.state.selection.head).before(1))??n.dom;return q(n,a,s.map(r=>({label:A(i,r.attrs.id)??"",description:`${r.childCount} ${r.childCount===1?"row":"rows"} \xB7 ${X(r)}`,icon:"\u25A6",run:()=>W(n,t,r,e)})))}var V=n=>`<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${n}</svg>`,Z=V('<rect x="2.5" y="3" width="11" height="10" rx="1.5"/><path d="M2.5 6.5h11M6 6.5V13"/>'),tt=V('<g transform="scale(0.6667)" stroke-width="2.25"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></g>'),et=V('<path d="M2.75 4.5h10.5M6.25 4.5V2.75h3.5V4.5M4.25 4.5l.6 8.75h6.3l.6-8.75"/>'),st=[["bar","Bar"],["line","Line"],["pie","Pie"]],it="Untitled chart";function nt(n,t){let e=null;return n.forEach((s,i)=>{e===null&&s.type===p.nodes.table&&s.attrs.id===t&&(e=i)}),e}function E(n){let t=[];return n.forEach(e=>{e.type===p.nodes.table&&y(e.attrs.cols).length>1&&t.push(e)}),t.map(e=>({id:e.attrs.id,name:A(n,e.attrs.id),rows:e.childCount}))}function at(n){let t=y(n.attrs.cols);if(!t.length)return null;let e=M(n),s=t.find(a=>e[a]!=="number")??t[0],i=t.filter(a=>a!==s&&e[a]==="number");return{x:s,series:i.length?i:t.filter(a=>a!==s).slice(0,1)}}function l(n,t,e,s=null){let i=n.createElement(t);return e&&(i.className=e),s!==null&&(i.textContent=s),i}function C(n,t,e,s=!1){let i=l(n,"option","",e);return i.value=t,i.selected=s,i}function T(n,t,e){let s=l(n,"select","page-chart-select");return s.dataset.field=t,s.setAttribute("aria-label",e),s}var Y=class{constructor(t,e,s){this.node=t,this.view=e,this.getPos=s,this.source=void 0,this.tables=null,this.frame=null,this.unsaved=null,this.titleInput=null;let i=e.dom.ownerDocument;this.doc=i,this.dom=i.createElement("figure"),this.dom.className="page-chart",this.dom.dataset.id=t.attrs.id??"",this.dom.dataset.type="chart",this.head=l(i,"div","page-chart-head"),this.head.contentEditable="false",this.title=l(i,"span","page-chart-title"),this.chip=l(i,"button","page-chart-source"),this.chip.type="button",this.chip.contentEditable="false",this.chip.setAttribute("aria-label","Go to source table"),this.chip.innerHTML=Z,this.chipName=l(i,"span","page-chart-source-name"),this.chip.append(this.chipName),this.chip.addEventListener("click",()=>this.goToSource()),this.edit=l(i,"button","page-chart-edit"),this.edit.type="button",this.edit.contentEditable="false",this.edit.setAttribute("aria-haspopup","dialog"),this.edit.setAttribute("aria-expanded","false"),this.edit.innerHTML=tt,this.edit.append("Edit chart"),this.edit.addEventListener("click",()=>this.panel.isConnected?this.closePanel(!0):this.openPanel()),this.head.append(this.title,this.chip,this.edit),this.plot=l(i,"div","page-chart-plot"),this.broken=l(i,"div","page-chart-broken"),this.broken.hidden=!0,this.broken.contentEditable="false",this.brokenKey=null,this.brokenSelect=null,this.broken.addEventListener("click",a=>this.brokenClick(a)),this.panel=l(i,"div","page-chart-panel"),this.panel.tabIndex=-1,this.panel.contentEditable="false",this.panel.setAttribute("role","dialog"),this.panel.setAttribute("aria-label","Chart settings"),this.panel.addEventListener("click",a=>this.panelClick(a)),this.panel.addEventListener("change",a=>this.panelChange(a)),this.panel.addEventListener("mousedown",a=>{a.target.closest?.("button")&&a.preventDefault()}),this.outside=a=>{!this.panel.isConnected||this.dom.contains(a.target)||(this.commitTitle(),this.closePanel())},this.escape=a=>{!this.panel.isConnected||a.key!=="Escape"||(a.preventDefault(),a.stopPropagation(),this.closePanel(!0))},i.addEventListener("mousedown",this.outside,!0),i.addEventListener("keydown",this.escape,!0),this.dom.append(this.head,this.plot,this.broken),S.has(e)||S.set(e,new Set),S.get(e).add(this),this.refresh(),D.delete(t.attrs.id)&&this.openSoon()}refresh(){this.renderHead(),this.panel.isConnected&&this.panelKey()!==this.renderedKey&&this.redrawPanel();let t=this.view.state.doc,e=g(t,this.node.attrs.source),s=E(t).map(i=>`${i.id}:${i.name}:${i.rows}`).join("|");e===this.source&&s===this.tables||(this.source=e,this.tables=s,this.schedule())}schedule(){if(this.frame!==null)return;let t=this.dom.ownerDocument.defaultView,e=t.requestAnimationFrame?.bind(t)??(s=>t.setTimeout(s,0));this.frame=e(()=>{this.frame=null,this.draw()})}draw(){let t=this.node.attrs,e=j({id:t.id,type:t.kind,x:t.x,series:t.series,title:t.title,highlight:t.highlight},N(this.source));this.plot.innerHTML=U(e,{width:640,height:320,narrow:this.dom.getBoundingClientRect().width<480}),this.renderBroken(e)}renderBroken(t){let e=t.state==="missing"&&t.reason==="table";if(this.plot.hidden=e,this.broken.hidden=!e,!e){this.brokenKey!==null&&(this.broken.textContent="",this.brokenKey=null,this.brokenSelect=null);return}let s=E(this.view.state.doc),i=s.map(h=>`${h.id}:${h.name}:${h.rows}`).join("|");if(this.brokenKey===i)return;this.brokenKey=i,this.brokenSelect=null;let a=this.doc;this.broken.textContent="",this.broken.append(l(a,"div","page-chart-broken-head","This chart's table was deleted"),l(a,"p","page-chart-broken-text","Pick another table in this document, or delete the chart. Undo brings the table back."));let r=l(a,"div","page-chart-broken-actions");if(s.length){let h=T(a,"rescue","Source table");for(let d of s)h.append(C(a,d.id,`${d.name} (${d.rows} ${d.rows===1?"row":"rows"})`));this.brokenSelect=h;let f=l(a,"button","page-chart-use","Use this table");f.type="button",f.dataset.action="use",r.append(h,f)}let c=l(a,"button","page-chart-delete","Delete chart");c.type="button",c.dataset.action="delete",r.append(c),this.broken.append(r)}brokenClick(t){let e=t.target.closest?.("button[data-action]");e&&(e.dataset.action==="delete"?this.removeChart():e.dataset.action==="use"&&this.switchSource(this.brokenSelect?.value??""))}openSoon(){let t=this.dom.ownerDocument.defaultView;(t.requestAnimationFrame?.bind(t)??(s=>t.setTimeout(s,0)))(()=>{!this.view.isDestroyed&&this.dom.isConnected&&this.openPanel()})}renderHead(){let t=this.node.attrs,e=A(this.view.state.doc,t.source),s=!g(this.view.state.doc,t.source);this.title.textContent=t.title||it,this.title.classList.toggle("is-empty",!t.title),this.chipName.textContent=s?"No table":e??"",this.chip.disabled=s}setAttrs(t){let e=this.getPos();if(e==null)return;let s=this.view.state.doc.nodeAt(e);s?.type===p.nodes.chart&&this.view.dispatch(this.view.state.tr.setNodeMarkup(e,null,{...s.attrs,...t}))}row(t,...e){let s=l(this.doc,"div","page-chart-row");return t&&s.append(l(this.doc,"span","page-chart-label",t)),s.append(...e),s}panelKey(){let t=this.view.state.doc,e=E(t).map(s=>`${s.id}:${s.name}:${s.rows}`).join("|");return JSON.stringify([this.node.attrs,e,N(g(t,this.node.attrs.source))])}redrawPanel(){let t=this.doc.activeElement,e=t&&this.panel.contains(t)?t.dataset??{}:null,s=this.titleInput,i=s&&s.value!==this.renderedTitle?{value:s.value,start:s.selectionStart,end:s.selectionEnd}:null;if(this.renderPanel(),i&&this.titleInput&&(this.titleInput.value=i.value),!e)return;let a=[...this.panel.querySelectorAll("button, input, select")].find(r=>["field","kind","col","action"].every(c=>r.dataset[c]===e[c]));if(!a)return this.panel.focus();a.focus(),i&&a===this.titleInput&&a.setSelectionRange?.(i.start,i.end)}renderPanel(){let t=this.doc;this.renderedKey=this.panelKey(),this.renderedTitle=this.node.attrs.title??"";let e=this.node.attrs,s=N(this.source),i=s?.cols??[],a=s?.rows??[],r=e.kind==="pie";this.unsaved?.dispose(),this.unsaved=null,this.titleInput=null,this.panel.textContent="";let c=l(t,"div","page-chart-types");for(let[o,P]of st){let b=l(t,"button","page-chart-type",P);b.type="button",b.dataset.kind=o,b.setAttribute("aria-pressed",String(e.kind===o)),c.append(b)}this.panel.append(this.row("Chart type",c));let h=T(t,"source","Source table");for(let o of E(this.view.state.doc))h.append(C(t,o.id,`${o.name} (${o.rows} ${o.rows===1?"row":"rows"})`,o.id===e.source));this.panel.append(this.row("Source table",h));let f=T(t,"labels","Labels column");for(let o of i)f.append(C(t,o.id,o.name||o.id,o.id===e.x));this.panel.append(this.row("Labels column",f));let d=l(t,"div","page-chart-values");i.filter(o=>o.id!==e.x).forEach((o,P)=>{let b=l(t,"label","page-chart-value"),v=l(t,"input");v.type="checkbox",v.dataset.field="series",v.dataset.col=o.id,v.checked=e.series.includes(o.id);let I=l(t,"span","page-chart-swatch");I.style.background=`var(--chart-${P%6+1})`,I.setAttribute("aria-hidden","true"),b.append(v,I,l(t,"span","page-chart-value-name",o.name||o.id)),d.append(b)});let w=this.row(r?"Value column":"Value columns",d);r&&w.append(l(t,"span","page-chart-hint","Pie charts plot the first value column across rows.")),this.panel.append(w);let m=T(t,"highlight","Highlight row");m.append(C(t,"","None",!e.highlight));for(let o of a)m.append(C(t,o.id,O(o.cells?.[e.x])||o.id,o.id===e.highlight));this.panel.append(this.row("Highlight row",m));let u=l(t,"input","page-chart-title-input");u.type="text",u.dataset.field="title",u.setAttribute("aria-label","Chart title"),u.value=e.title??"",u.addEventListener("keydown",o=>{o.isComposing||o.keyCode===229||o.key==="Enter"&&(o.preventDefault(),o.stopPropagation(),this.commitTitle())}),u.addEventListener("change",()=>this.commitTitle()),u.addEventListener("blur",()=>this.commitTitle()),this.titleInput=u,this.panel.append(this.row("Chart title",u));let H=l(t,"div","page-chart-foot"),k=l(t,"button","page-chart-remove");k.type="button",k.dataset.action="remove",k.innerHTML=et,k.append("Remove");let L=l(t,"button","page-chart-done","Done");L.type="button",L.dataset.action="done",H.append(k,L),this.panel.append(H),this.unsaved=K({id:"chart-title",isPending:()=>u.isConnected&&u.value!==(this.node.attrs.title??"")})}openPanel(){this.panel.isConnected||(this.renderPanel(),this.dom.append(this.panel),this.edit.setAttribute("aria-expanded","true"),this.panel.focus())}closePanel(t=!1){this.panel.isConnected&&(this.unsaved?.dispose(),this.unsaved=null,this.titleInput=null,this.panel.remove(),this.edit.setAttribute("aria-expanded","false"),t&&this.edit.focus())}panelClick(t){let e=t.target.closest?.("button");e&&(e.dataset.action==="done"?(this.commitTitle(),this.closePanel(!0)):e.dataset.action==="remove"?this.removeChart():e.dataset.kind&&this.setAttrs({kind:e.dataset.kind}))}panelChange(t){let e=t.target;if(e?.dataset){if(e.dataset.field==="source")this.switchSource(e.value);else if(e.dataset.field==="labels")this.setAttrs({x:e.value,series:this.node.attrs.series.filter(s=>s!==e.value)});else if(e.dataset.field==="highlight")this.setAttrs({highlight:e.value||null});else if(e.dataset.field==="series"){let s=this.node.attrs.series.filter(i=>i!==e.dataset.col);this.setAttrs({series:e.checked?[...s,e.dataset.col]:s})}}}switchSource(t){let e=g(this.view.state.doc,t),s=e?at(e):null;s&&this.setAttrs({source:t,x:s.x,series:s.series})}commitTitle(){let t=this.titleInput;!t||t.value===(this.node.attrs.title??"")||this.setAttrs({title:t.value})}goToSource(){let t=this.view.state.doc,e=nt(t,this.node.attrs.source),s=e===null?null:t.nodeAt(e);if(!s?.childCount||!s.child(0).childCount)return;let i=e+3;this.view.dispatch(this.view.state.tr.setSelection(J.create(t,i)).scrollIntoView()),this.view.focus?.()}removeChart(){let t=this.getPos();if(t==null)return;let e=this.view.state.doc.nodeAt(t);if(e?.type!==p.nodes.chart)return;this.closePanel();let s=this.view.state.tr.delete(t,t+e.nodeSize);s.setSelection(J.near(s.doc.resolve(Math.min(t,s.doc.content.size)),-1)),this.view.dispatch(G(s).scrollIntoView())}update(t){if(t.type!==p.nodes.chart)return!1;let e=!t.sameMarkup(this.node);return this.node=t,this.dom.dataset.id=t.attrs.id??"",e&&(this.source=g(this.view.state.doc,t.attrs.source),this.renderHead(),this.schedule()),!0}stopEvent(t){return!!t.target.closest?.(".page-chart-head, .page-chart-panel")}destroy(){if(this.unsaved?.dispose(),this.unsaved=null,this.doc.removeEventListener("mousedown",this.outside,!0),this.doc.removeEventListener("keydown",this.escape,!0),S.get(this.view)?.delete(this),this.frame!==null){let t=this.dom.ownerDocument.defaultView;t.cancelAnimationFrame?t.cancelAnimationFrame(this.frame):t.clearTimeout(this.frame)}}};function vt(n){for(let t of S.get(n)??[])t.refresh()}export{wt as a,X as b,kt as c,Y as d,vt as e};
@@ -1 +1 @@
1
- import{c as A}from"./c-KBS3UV6B.js";import{j as b}from"./c-4TXNLX4K.js";import"./c-EXKHPOVC.js";import"./c-L5VFATT6.js";import"./c-MWXFLW4J.js";import"./c-ZK4GIZH2.js";import"./c-W4JCVLAB.js";import"./c-7K4SCQB7.js";import"./c-WMRJKQ2V.js";import{B as x}from"./c-AMU3BPPR.js";import{b as h}from"./c-QIXT3Q7C.js";import"./c-WCXLG3MV.js";import"./c-57XDY6HC.js";import"./c-VHNSBD2M.js";function S(o){let s=String(o??""),n=typeof Intl<"u"&&typeof Intl.Segmenter=="function"?new Intl.Segmenter("en",{granularity:"grapheme"}):null;return n?[...n.segment(s)].map(a=>a.segment):[...s]}var I=o=>S(o).length===1&&!/^\s*$/.test(String(o??""));function L(o){let s=[];for(let[n,a]of Object.entries(o??{}))for(let u of Array.isArray(a)?a:[]){let[f,m,d=""]=u??[];typeof f!="string"||typeof m!="string"||s.push({id:`${n}:${m}`,char:f,name:`${f} ${m}`,keywords:`${m} ${d}`})}return s}var P=(o,s)=>{let n=String(s??"").trim().toLowerCase();return n?o.filter(a=>a.char===n||a.keywords.toLowerCase().includes(n)):o};function T(o=()=>import("./c-SZGYW5HT.js")){let s=null;return()=>(s??=Promise.resolve().then(()=>o()).then(n=>L(n.EMOJI)).catch(n=>{throw s=null,n}),s)}function w({view:o=null,load:s=()=>import("./c-SZGYW5HT.js")}={}){if(!o)return{run:()=>({ok:!1,code:"not-editing"}),dispose(){}};let n=o.dom.ownerDocument,a=T(s),u=null;function f(t){let e=o.state,r=e.selection;if(r.from!==t.from||r.to!==t.to||t.from<0||t.to>e.doc.content.size)return null;let c=e.doc.resolve(t.from),i=e.doc.resolve(t.to);return!c.parent.isTextblock||c.parent!==i.parent?null:{from:t.from,to:t.to}}function m(t){try{let e=o.dom.parentElement?.getBoundingClientRect?.()??{left:0,top:0},r=o.coordsAtPos(t.from);return{x:Math.max(8,r.left-e.left),y:r.bottom+6-e.top}}catch{return null}}function d(t){let e=t.picker.activeId();e?o.dom.setAttribute("aria-activedescendant",e):o.dom.getAttribute("aria-activedescendant")?.startsWith(t.picker.el.id)&&o.dom.removeAttribute("aria-activedescendant")}function l(){let t=u;if(t){u=null;for(let[e,r,c,i]of t.listen)e.removeEventListener(r,c,i);o.dom.getAttribute("aria-activedescendant")?.startsWith(`${t.picker.el.id}-`)&&o.dom.removeAttribute("aria-activedescendant"),t.picker.destroy()}}function j(t,e){let r=o.state.tr.insertText(e,t.from,t.to);return r.setSelection(h.TextSelection.create(r.doc,t.from+e.length)),o.dispatch(x(r)),o.focus(),{ok:!0,emoji:e}}function p(t){let e=u;if(!e)return{ok:!1,code:"not-editing"};let r=e.picker.personAt(t),c=f(e);return!r||c===null||!I(r.char)?(l(),r?c===null?{ok:!1,code:"stale-target"}:{ok:!1,code:"invalid-emoji"}:{ok:!1,code:"no-emoji"}):(l(),j(c,r.char))}function E(t){let e=u;if(!e||b(t,o))return;let r=()=>{t.preventDefault(),t.stopPropagation()};t.key==="ArrowDown"||t.key==="ArrowUp"?(r(),e.picker.move(t.key==="ArrowDown"?1:-1),d(e)):t.key==="Enter"?(r(),p(e.picker.index())):(t.key==="Escape"||t.key==="Tab")&&(r(),l())}async function $(t={}){l();let e={from:o.state.selection.from,to:o.state.selection.to,picker:null,listen:[]};e.picker=A({document:n,label:"Insert an emoji",empty:"No emoji found",onPick:i=>p(i)}),u=e;let r=(i,k,g,y)=>{i.addEventListener(k,g,y),e.listen.push([i,k,g,y])};r(n,"keydown",i=>E(i),!0),r(o.dom,"input",()=>l()),r(n,"mousedown",i=>{e.picker.el.contains(i.target)||l()},!0),(o.dom.parentElement??n.body).appendChild(e.picker.el);let c;try{c=await a()}catch(i){return l(),{ok:!1,code:"unavailable",error:i}}return u!==e?{ok:!1,code:"not-editing"}:f(e)===null?(l(),{ok:!1,code:"stale-target"}):(e.picker.show(P(c,t?.query),m(e)),d(e),{ok:!0,picker:!0})}return{async run(t){return $(t)},dispose(){l()}}}export{w as createFeature,L as emojiEntries,T as emojiLibrary,P as filterEmoji,S as graphemes,I as isEmojiText};
1
+ import{c as A}from"./c-KBS3UV6B.js";import{j as b}from"./c-SJPD46ZO.js";import"./c-EXKHPOVC.js";import"./c-L5VFATT6.js";import"./c-XQSXKIKM.js";import"./c-67ILSNPR.js";import"./c-W4JCVLAB.js";import"./c-7K4SCQB7.js";import"./c-WMRJKQ2V.js";import{B as x}from"./c-44B5ODN7.js";import{b as h}from"./c-QIXT3Q7C.js";import"./c-E4IBSAQM.js";import"./c-57XDY6HC.js";import"./c-VHNSBD2M.js";function S(o){let s=String(o??""),n=typeof Intl<"u"&&typeof Intl.Segmenter=="function"?new Intl.Segmenter("en",{granularity:"grapheme"}):null;return n?[...n.segment(s)].map(a=>a.segment):[...s]}var I=o=>S(o).length===1&&!/^\s*$/.test(String(o??""));function L(o){let s=[];for(let[n,a]of Object.entries(o??{}))for(let u of Array.isArray(a)?a:[]){let[f,m,d=""]=u??[];typeof f!="string"||typeof m!="string"||s.push({id:`${n}:${m}`,char:f,name:`${f} ${m}`,keywords:`${m} ${d}`})}return s}var P=(o,s)=>{let n=String(s??"").trim().toLowerCase();return n?o.filter(a=>a.char===n||a.keywords.toLowerCase().includes(n)):o};function T(o=()=>import("./c-SZGYW5HT.js")){let s=null;return()=>(s??=Promise.resolve().then(()=>o()).then(n=>L(n.EMOJI)).catch(n=>{throw s=null,n}),s)}function w({view:o=null,load:s=()=>import("./c-SZGYW5HT.js")}={}){if(!o)return{run:()=>({ok:!1,code:"not-editing"}),dispose(){}};let n=o.dom.ownerDocument,a=T(s),u=null;function f(t){let e=o.state,r=e.selection;if(r.from!==t.from||r.to!==t.to||t.from<0||t.to>e.doc.content.size)return null;let c=e.doc.resolve(t.from),i=e.doc.resolve(t.to);return!c.parent.isTextblock||c.parent!==i.parent?null:{from:t.from,to:t.to}}function m(t){try{let e=o.dom.parentElement?.getBoundingClientRect?.()??{left:0,top:0},r=o.coordsAtPos(t.from);return{x:Math.max(8,r.left-e.left),y:r.bottom+6-e.top}}catch{return null}}function d(t){let e=t.picker.activeId();e?o.dom.setAttribute("aria-activedescendant",e):o.dom.getAttribute("aria-activedescendant")?.startsWith(t.picker.el.id)&&o.dom.removeAttribute("aria-activedescendant")}function l(){let t=u;if(t){u=null;for(let[e,r,c,i]of t.listen)e.removeEventListener(r,c,i);o.dom.getAttribute("aria-activedescendant")?.startsWith(`${t.picker.el.id}-`)&&o.dom.removeAttribute("aria-activedescendant"),t.picker.destroy()}}function j(t,e){let r=o.state.tr.insertText(e,t.from,t.to);return r.setSelection(h.TextSelection.create(r.doc,t.from+e.length)),o.dispatch(x(r)),o.focus(),{ok:!0,emoji:e}}function p(t){let e=u;if(!e)return{ok:!1,code:"not-editing"};let r=e.picker.personAt(t),c=f(e);return!r||c===null||!I(r.char)?(l(),r?c===null?{ok:!1,code:"stale-target"}:{ok:!1,code:"invalid-emoji"}:{ok:!1,code:"no-emoji"}):(l(),j(c,r.char))}function E(t){let e=u;if(!e||b(t,o))return;let r=()=>{t.preventDefault(),t.stopPropagation()};t.key==="ArrowDown"||t.key==="ArrowUp"?(r(),e.picker.move(t.key==="ArrowDown"?1:-1),d(e)):t.key==="Enter"?(r(),p(e.picker.index())):(t.key==="Escape"||t.key==="Tab")&&(r(),l())}async function $(t={}){l();let e={from:o.state.selection.from,to:o.state.selection.to,picker:null,listen:[]};e.picker=A({document:n,label:"Insert an emoji",empty:"No emoji found",onPick:i=>p(i)}),u=e;let r=(i,k,g,y)=>{i.addEventListener(k,g,y),e.listen.push([i,k,g,y])};r(n,"keydown",i=>E(i),!0),r(o.dom,"input",()=>l()),r(n,"mousedown",i=>{e.picker.el.contains(i.target)||l()},!0),(o.dom.parentElement??n.body).appendChild(e.picker.el);let c;try{c=await a()}catch(i){return l(),{ok:!1,code:"unavailable",error:i}}return u!==e?{ok:!1,code:"not-editing"}:f(e)===null?(l(),{ok:!1,code:"stale-target"}):(e.picker.show(P(c,t?.query),m(e)),d(e),{ok:!0,picker:!0})}return{async run(t){return $(t)},dispose(){l()}}}export{w as createFeature,L as emojiEntries,T as emojiLibrary,P as filterEmoji,S as graphemes,I as isEmojiText};
@@ -1 +1 @@
1
- import"./c-LKSL4AUJ.js";import{b as s,d as c,f as p,h as l}from"./c-EK63G3CG.js";import{f as i}from"./c-XGH4GS2T.js";import"./c-3O7OBDCM.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-HA6INT6J.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var u="page-format-activation-failed";function d(){let e=document.querySelector(`meta[name="${s}"]`);return e?p(e.outerHTML):0}var F=async e=>(await import("./core/save-LYY7K6U7.js")).savePageForce(()=>{},e),P=4,g=1e4,f=e=>e?.ok===!1&&e?.msgType==="skipped"&&/in progress/i.test(e?.msg??""),w=async()=>{let{isSaveInProgress:e}=await import("./core/save-core-MKRPSEEO.js"),r=Date.now()+g;for(;e()&&Date.now()<r;)await new Promise(n=>setTimeout(n,50))};function v({save:e=F,settles:r=w,supported:n=()=>i().then(a=>a===1)}={}){return{read(){return{floor:Math.max(l(),d()),revision:null}},capabilities(){return[]},supported:n,async activate({floor:a=1}={}){let t;try{t=await e({pageFormatFloor:a});for(let o=1;o<P&&f(t);o+=1)await r(),t=await e({pageFormatFloor:a})}catch(o){return{accepted:!1,code:o?.code??u}}return t?.ok?{accepted:!0,revision:null,receipt:t.receipt??t.etag??null}:t?.code===c?{accepted:!1,code:c}:{accepted:!1,code:t?.code??u}}}}export{v as createFormatHost};
1
+ import"./c-LKSL4AUJ.js";import{b as s,d as c,f as p,h as l}from"./c-EK63G3CG.js";import{f as i}from"./c-XGH4GS2T.js";import"./c-3O7OBDCM.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-HA6INT6J.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var u="page-format-activation-failed";function d(){let e=document.querySelector(`meta[name="${s}"]`);return e?p(e.outerHTML):0}var F=async e=>(await import("./core/save-AOJBDSOK.js")).savePageForce(()=>{},e),P=4,g=1e4,f=e=>e?.ok===!1&&e?.msgType==="skipped"&&/in progress/i.test(e?.msg??""),w=async()=>{let{isSaveInProgress:e}=await import("./core/save-core-IOCMXO5L.js"),r=Date.now()+g;for(;e()&&Date.now()<r;)await new Promise(n=>setTimeout(n,50))};function v({save:e=F,settles:r=w,supported:n=()=>i().then(a=>a===1)}={}){return{read(){return{floor:Math.max(l(),d()),revision:null}},capabilities(){return[]},supported:n,async activate({floor:a=1}={}){let t;try{t=await e({pageFormatFloor:a});for(let o=1;o<P&&f(t);o+=1)await r(),t=await e({pageFormatFloor:a})}catch(o){return{accepted:!1,code:o?.code??u}}return t?.ok?{accepted:!0,revision:null,receipt:t.receipt??t.etag??null}:t?.code===c?{accepted:!1,code:c}:{accepted:!1,code:t?.code??u}}}}export{v as createFormatHost};
@@ -1 +1 @@
1
- import{b as x}from"./c-L3F5ZLIV.js";import{a as T,d as h}from"./c-IW6GGOU2.js";import{b as y}from"./c-HAWFNBYG.js";import{n as d}from"./c-EXKHPOVC.js";import{na as s,qa as m,ra as p,sa as g}from"./c-QIXT3Q7C.js";import{a as c}from"./c-TCCA5BZN.js";import{q as f}from"./c-7MG5RU63.js";var v="article[data-page]",O=/^page(\.[0-9]+)?$/;function S(t){return[...t.querySelectorAll('script[merge][clay~="live"]')].filter(e=>O.test(e.getAttribute("merge")))}var i=null;function b(t){let e=t.join("\0");if(i&&i.key===e)return i;let r=t.map(l=>{try{return c(l)}catch{throw new d("invalid-json","Cannot read the page data as JSON")}}),n=x(r),o=s(n);return i={key:e,html:g(o,{fallbackOf:l=>{let u=n[l]?.artifact?.fallbackHtml;return typeof u=="string"?u:""},clean:p(document)}),rev:m(o),model:o,title:y(o)},i}function k(t){let e=t.querySelector(v);if(!e)return;let r=S(t);if(!r.length)return;let{html:n,rev:o,title:a}=b(r.map(l=>l.textContent));e.innerHTML!==n&&(e.innerHTML=n),e.setAttribute("data-rev",o),T(t)||h(t,a)}function A(t){let e=S(t);if(e.length!==1)return null;let r;try{r=c(e[0].textContent)}catch{return null}let{v:n,g:o,y:a}=r??{};return n!==1||!a||typeof a!="object"||Array.isArray(a)?null:{v:n,g:o,y:{...a}}}function M(t){return b([typeof t=="string"?t:JSON.stringify(t)]).html}function D(t){if(typeof t!="string")return null;try{let e=new DOMParser().parseFromString(t,"text/html"),r=A(e),n=e.querySelector(v);if(!r||!n)return null;let o=e.createElement("article");return o.innerHTML=M(r),n.innerHTML===o.innerHTML?r:null}catch{return null}}f(k);export{v as a,S as b,b as c,A as d,M as e,D as f};
1
+ import{b as x}from"./c-L3F5ZLIV.js";import{a as T,d as h}from"./c-IW6GGOU2.js";import{b as y}from"./c-HAWFNBYG.js";import{n as d}from"./c-EXKHPOVC.js";import{na as s,qa as m,ra as p,sa as g}from"./c-QIXT3Q7C.js";import{a as c}from"./c-TCCA5BZN.js";import{q as f}from"./c-EGTIAL6P.js";var v="article[data-page]",O=/^page(\.[0-9]+)?$/;function S(t){return[...t.querySelectorAll('script[merge][clay~="live"]')].filter(e=>O.test(e.getAttribute("merge")))}var i=null;function b(t){let e=t.join("\0");if(i&&i.key===e)return i;let r=t.map(l=>{try{return c(l)}catch{throw new d("invalid-json","Cannot read the page data as JSON")}}),n=x(r),o=s(n);return i={key:e,html:g(o,{fallbackOf:l=>{let u=n[l]?.artifact?.fallbackHtml;return typeof u=="string"?u:""},clean:p(document)}),rev:m(o),model:o,title:y(o)},i}function k(t){let e=t.querySelector(v);if(!e)return;let r=S(t);if(!r.length)return;let{html:n,rev:o,title:a}=b(r.map(l=>l.textContent));e.innerHTML!==n&&(e.innerHTML=n),e.setAttribute("data-rev",o),T(t)||h(t,a)}function A(t){let e=S(t);if(e.length!==1)return null;let r;try{r=c(e[0].textContent)}catch{return null}let{v:n,g:o,y:a}=r??{};return n!==1||!a||typeof a!="object"||Array.isArray(a)?null:{v:n,g:o,y:{...a}}}function M(t){return b([typeof t=="string"?t:JSON.stringify(t)]).html}function D(t){if(typeof t!="string")return null;try{let e=new DOMParser().parseFromString(t,"text/html"),r=A(e),n=e.querySelector(v);if(!r||!n)return null;let o=e.createElement("article");return o.innerHTML=M(r),n.innerHTML===o.innerHTML?r:null}catch{return null}}f(k);export{v as a,S as b,b as c,A as d,M as e,D as f};