@panphora/clayjs 1.24.1 → 1.25.1

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 (275) hide show
  1. package/dist/all.js +1 -1
  2. package/dist/clay-dom.js +1 -1
  3. package/dist/clay-events.js +1 -1
  4. package/dist/clay-internals.js +1 -1
  5. package/dist/clay-options.js +1 -1
  6. package/dist/clay-router.js +1 -1
  7. package/dist/clay-ui.js +1 -1
  8. package/dist/clay-utils.js +1 -1
  9. package/dist/clay.js +1 -1
  10. package/dist/clay.standalone.js +6060 -4662
  11. package/dist/m/attrs/{refetch-on-save-DPGJJMGN.js → refetch-on-save-5CBFUJUF.js} +1 -1
  12. package/dist/m/attrs/save-freeze-PUYX32AK.js +1 -0
  13. package/dist/m/{c-HIX5H5L7.js → c-2A2ATCIH.js} +1 -1
  14. package/dist/m/{c-BOMQIQ3V.js → c-2EFMJYGJ.js} +1 -1
  15. package/dist/m/{c-MP6S4AZU.js → c-2GB34XL4.js} +2 -2
  16. package/dist/m/c-2TJCFPX4.js +4 -0
  17. package/dist/m/c-33SS5A4Y.js +1 -0
  18. package/dist/m/{c-PCNJETUA.js → c-34J5HC7N.js} +1 -1
  19. package/dist/m/{c-AT7GLQGV.js → c-3AAQJAKJ.js} +1 -1
  20. package/dist/m/c-3F3AADKG.js +1 -0
  21. package/dist/m/{c-HL6BLJNA.js → c-3WX5FABT.js} +1 -1
  22. package/dist/m/c-3XNTQQEJ.js +1 -0
  23. package/dist/m/{c-ZRGEN6QQ.js → c-3Y234AUB.js} +2 -2
  24. package/dist/m/{c-SUXHUL7U.js → c-42RLKGEY.js} +1 -1
  25. package/dist/m/{c-2BLVA6IN.js → c-44WITKWQ.js} +1 -1
  26. package/dist/m/c-47M4QHCK.js +1 -0
  27. package/dist/m/{c-UOUUI265.js → c-4M2T676V.js} +1 -1
  28. package/dist/m/{c-SXGEWPFC.js → c-4NAYDOWH.js} +1 -1
  29. package/dist/m/{c-OCYG4NBQ.js → c-4OZZ7ENT.js} +2 -2
  30. package/dist/m/{c-UOOIF2AL.js → c-5IIEOPIV.js} +1 -1
  31. package/dist/m/{c-YDW4VCHP.js → c-755ZOHOM.js} +1 -1
  32. package/dist/m/c-7Q4XYDF4.js +1 -0
  33. package/dist/m/c-7RHOMAMR.js +1 -0
  34. package/dist/m/{c-7V6MGMX2.js → c-7Z2625LX.js} +1 -1
  35. package/dist/m/{c-CTGRDT6E.js → c-A3OKSYRI.js} +1 -1
  36. package/dist/m/{c-GNI7WHKF.js → c-A5IYL7JI.js} +1 -1
  37. package/dist/m/c-A5LASUEZ.js +1 -0
  38. package/dist/m/c-AQVQKFKB.js +1 -0
  39. package/dist/m/{c-FLEIU6CG.js → c-ASGHHLFX.js} +1 -1
  40. package/dist/m/c-ASMLERFA.js +7 -0
  41. package/dist/m/{c-LUXAB2XI.js → c-AZM34SPO.js} +1 -1
  42. package/dist/m/{c-ZFO5RW6G.js → c-BHLYQGTA.js} +1 -1
  43. package/dist/m/{c-C5AKJVRH.js → c-BJ2RRQBQ.js} +1 -1
  44. package/dist/m/{c-FVPNX2GO.js → c-C27EVUQ6.js} +1 -1
  45. package/dist/m/{c-DFKBGSN2.js → c-C5UGNOC2.js} +1 -1
  46. package/dist/m/c-C6DXZIXD.js +1 -0
  47. package/dist/m/{c-EDE45NM7.js → c-C7SUMNMI.js} +1 -1
  48. package/dist/m/{c-STRI73GQ.js → c-CL5LSATX.js} +1 -1
  49. package/dist/m/c-CPRGR2II.js +1 -0
  50. package/dist/m/{c-NFQFV7OP.js → c-D2OPWOWO.js} +1 -1
  51. package/dist/m/{c-ZKKAF4UT.js → c-D4N4UJCQ.js} +2 -2
  52. package/dist/m/{c-6LEYVQJK.js → c-DAUQ6JZ3.js} +1 -1
  53. package/dist/m/{c-ZGCO4J3H.js → c-DDCYVLGG.js} +1 -1
  54. package/dist/m/{c-KQKKIVLW.js → c-DVMDYRAE.js} +1 -1
  55. package/dist/m/{c-OG6GFSUX.js → c-DYTBSJBI.js} +1 -1
  56. package/dist/m/{c-P2HKMJAW.js → c-EAV7A6BT.js} +1 -1
  57. package/dist/m/{c-X75G43SZ.js → c-EEWPNUM2.js} +1 -1
  58. package/dist/m/c-EHAR4RJJ.js +3 -0
  59. package/dist/m/c-EIDZHQHZ.js +1 -0
  60. package/dist/m/c-ELXMSEN5.js +1 -0
  61. package/dist/m/{c-QQFHEODI.js → c-EQ5NBOGA.js} +1 -1
  62. package/dist/m/c-FC5RUFPR.js +1 -0
  63. package/dist/m/{c-ND3Q2G2I.js → c-GFASNR55.js} +1 -1
  64. package/dist/m/{c-A4L7APIU.js → c-GNFDX6SU.js} +1 -1
  65. package/dist/m/{c-LATNQ6Q5.js → c-H3M6UDNV.js} +1 -1
  66. package/dist/m/{c-YLHTD3KX.js → c-H4M2T4A6.js} +1 -1
  67. package/dist/m/{c-DDS23EY6.js → c-HXGNH6GY.js} +1 -1
  68. package/dist/m/{c-PDBNCJCT.js → c-HYNM5U6B.js} +1 -1
  69. package/dist/m/c-J2YYLEVM.js +1 -0
  70. package/dist/m/c-J2ZW4HMR.js +1 -0
  71. package/dist/m/{c-WCG6AKA7.js → c-JC4RZW4E.js} +1 -1
  72. package/dist/m/c-K2ZHQMPF.js +1 -0
  73. package/dist/m/{c-6IJEVE6B.js → c-KU3PX7LL.js} +1 -1
  74. package/dist/m/{c-YYMZWQLR.js → c-L6KVXPBO.js} +1 -1
  75. package/dist/m/{c-CV4T65JE.js → c-LUBZU4AZ.js} +4 -4
  76. package/dist/m/{c-5FXEKU4Y.js → c-LYNLY3MR.js} +1 -1
  77. package/dist/m/{c-NQAPWM7O.js → c-MHTO3QAD.js} +1 -1
  78. package/dist/m/{c-HDVH3MVC.js → c-MKAUC6DB.js} +1 -1
  79. package/dist/m/c-MLMJUNRV.js +1 -0
  80. package/dist/m/c-MMEVDN6D.js +1 -0
  81. package/dist/m/c-MOP5KBWZ.js +1 -0
  82. package/dist/m/{c-LA2BW7UY.js → c-MZCOGNZL.js} +1 -1
  83. package/dist/m/{c-XW5TIYYB.js → c-N4GEJMXW.js} +1 -1
  84. package/dist/m/{c-RS77ODLY.js → c-NL4I4KNG.js} +1 -1
  85. package/dist/m/{c-2PVGJFI5.js → c-NW4ZFKCY.js} +1 -1
  86. package/dist/m/{c-PYG2NGWU.js → c-O3DPFZCE.js} +1 -1
  87. package/dist/m/c-O4YIDULY.js +1 -0
  88. package/dist/m/{c-LTSPHVAK.js → c-OBMZASYQ.js} +1 -1
  89. package/dist/m/c-OZOACVUD.js +1 -0
  90. package/dist/m/{c-YK2L436K.js → c-OZVK3TFI.js} +1 -1
  91. package/dist/m/c-P73XPAOA.js +1 -0
  92. package/dist/m/c-PP3CUF3U.js +1 -0
  93. package/dist/m/{c-B7GOFGQR.js → c-Q2CB57UG.js} +1 -1
  94. package/dist/m/{c-TWCXBWS3.js → c-QCDVDZIR.js} +1 -1
  95. package/dist/m/{c-LSVN3OLG.js → c-QL4NYM2L.js} +1 -1
  96. package/dist/m/c-RES2S5Q3.js +1 -0
  97. package/dist/m/c-RFGELYEU.js +2 -0
  98. package/dist/m/c-RGFPLQGV.js +1 -0
  99. package/dist/m/c-SMLAJASY.js +1 -0
  100. package/dist/m/{c-MQKSKQHG.js → c-STAPQ2X6.js} +1 -1
  101. package/dist/m/c-SYVF6ZMF.js +1 -0
  102. package/dist/m/{c-SE3SIY7Y.js → c-T5IWJOMW.js} +1 -1
  103. package/dist/m/{c-DD26VXAP.js → c-T7LOTEWO.js} +1 -1
  104. package/dist/m/{c-47IBJGPQ.js → c-TWB5ZQU4.js} +1 -1
  105. package/dist/m/c-U35T5NAY.js +1 -0
  106. package/dist/m/c-U4TWEIKZ.js +1 -0
  107. package/dist/m/c-UW6MMZ4V.js +1 -0
  108. package/dist/m/{c-JWDCQL6J.js → c-V5L6HWVL.js} +1 -1
  109. package/dist/m/c-VGG3UR7I.js +1 -0
  110. package/dist/m/{c-CZHTXGJS.js → c-VO6RSFCO.js} +1 -1
  111. package/dist/m/c-VU4WEWPH.js +4 -0
  112. package/dist/m/c-W7LWCJHD.js +1 -0
  113. package/dist/m/c-WOJ2RTV4.js +1 -0
  114. package/dist/m/{c-T3P3AXEW.js → c-WOWGGNCJ.js} +1 -1
  115. package/dist/m/{c-6RGEQNVV.js → c-XCOQNISP.js} +1 -1
  116. package/dist/m/{c-SGGGCIVD.js → c-XS7G6U3Z.js} +1 -1
  117. package/dist/m/{c-4PO3YGDC.js → c-Y3J5LDKB.js} +1 -1
  118. package/dist/m/c-Y3MPVURA.js +1 -0
  119. package/dist/m/c-Y6HH7LTM.js +1 -0
  120. package/dist/m/{c-RO73MKKR.js → c-YRDKVEGR.js} +1 -1
  121. package/dist/m/{c-FEC6LGFF.js → c-YZGWSCMT.js} +1 -1
  122. package/dist/m/{c-7CM4GMTS.js → c-ZJ7726FO.js} +1 -1
  123. package/dist/m/{c-SKMIR5HQ.js → c-ZPI7M5U5.js} +1 -1
  124. package/dist/m/core/{admin-attrs-ONRWVXPK.js → admin-attrs-43JBA6JB.js} +1 -1
  125. package/dist/m/core/{autosave-TBKAAAFB.js → autosave-HD7Y7UNV.js} +1 -1
  126. package/dist/m/core/{conflict-notice-FOEE6I7E.js → conflict-notice-Y2NTMDGJ.js} +1 -1
  127. package/dist/m/core/draft-mode-M5XNYBMY.js +1 -0
  128. package/dist/m/core/{host-permission-X4BENZEU.js → host-permission-5BYP24GC.js} +1 -1
  129. package/dist/m/core/{is-edit-mode-FFHCQ5DR.js → is-edit-mode-73OXKK5H.js} +1 -1
  130. package/dist/m/core/{persist-6ILUR34S.js → persist-MX3VYVBN.js} +1 -1
  131. package/dist/m/core/{recovery-APWADU4K.js → recovery-VZF7RJZF.js} +1 -1
  132. package/dist/m/core/{save-6HT2LABE.js → save-JZ7R4ET2.js} +1 -1
  133. package/dist/m/core/{save-core-EVMNZQ4V.js → save-core-I4N6S4ED.js} +1 -1
  134. package/dist/m/core/{site-edits-G4BOZMV4.js → site-edits-TIJDPG6H.js} +1 -1
  135. package/dist/m/core/{snapshot-FJP5IJL3.js → snapshot-N5MKDGNI.js} +1 -1
  136. package/dist/m/core/unsaved-warning-BP6ZY3PG.js +1 -0
  137. package/dist/m/events/{index-B6TGDYMG.js → index-YKQIBZE5.js} +1 -1
  138. package/dist/m/internals/index-3LAVREAU.js +1 -0
  139. package/dist/m/lib/{cache-bust-NH7VBWHO.js → cache-bust-BL4KUQAJ.js} +1 -1
  140. package/dist/m/{loader-GLLVDUZA.js → loader-7ORQVRCK.js} +1 -1
  141. package/dist/m/manifest-A27A4278.js +1 -0
  142. package/dist/m/manifest-edit-E8A61EB4.js +1 -0
  143. package/dist/m/manifest.json +1608 -1498
  144. package/dist/m/options/{options-55LQHSJ4.js → options-LKIZ7YTG.js} +1 -1
  145. package/dist/m/page/{editor-KAZDJNND.js → editor-HS2CAV3W.js} +5 -5
  146. package/dist/m/plugins/{ai-edit-LABECCSN.js → ai-edit-WDV2GLDU.js} +2 -2
  147. package/dist/m/plugins/{cms-T2HLI7JG.js → cms-4KET6RZT.js} +9 -9
  148. package/dist/m/plugins/{demo-T7B4RIKL.js → demo-LMCMBILC.js} +1 -1
  149. package/dist/m/plugins/{derive-6LPJOCAV.js → derive-R4USHZ7P.js} +1 -1
  150. package/dist/m/plugins/{indicator-J4ABFARX.js → indicator-OLPZ4WFI.js} +1 -1
  151. package/dist/m/plugins/{live-PGBIEMGB.js → live-CO4VJS46.js} +1 -1
  152. package/dist/m/plugins/{menu-YZL3X2AJ.js → menu-ESEFQARM.js} +1 -1
  153. package/dist/m/plugins/{page-WOCNX2IN.js → page-L3VKIQU2.js} +2 -2
  154. package/dist/m/plugins/{page-view-SJODOOGE.js → page-view-6KNTXABH.js} +1 -1
  155. package/dist/m/plugins/{people-C4TCWFOQ.js → people-EBWE337I.js} +1 -1
  156. package/dist/m/plugins/quickcrop-VNRXGRPC.js +26 -0
  157. package/dist/m/plugins/{richclay-Y2NV44NA.js → richclay-V6WKJTUF.js} +17 -17
  158. package/dist/m/plugins/sortable-BAG3MSWS.js +1 -0
  159. package/dist/m/plugins/{source-YK7MO23W.js → source-OYHDXKTB.js} +1 -1
  160. package/dist/m/plugins/undo-WUK2NLBA.js +1 -0
  161. package/dist/m/plugins/{upgrade-NNTJBSK2.js → upgrade-SZQJYEQQ.js} +1 -1
  162. package/dist/m/plugins/{upload-ZKKJV76X.js → upload-NZET3DNQ.js} +1 -1
  163. package/dist/m/plugins/visitor-drafts-ZE6PCAFP.js +20 -0
  164. package/dist/m/plugins/{visitor-drafts-owner-LHUHFU3L.js → visitor-drafts-owner-TLECTYWS.js} +1 -1
  165. package/dist/m/plugins/{visitor-menu-FY4KM2SW.js → visitor-menu-5XY57JQA.js} +1 -1
  166. package/dist/m/plugins/wire-S5ATC4QI.js +1 -0
  167. package/dist/m/reader-core-AHOAP5DH.js +77 -0
  168. package/dist/m/sync/live-sync-DX4K5GDB.js +1 -0
  169. package/dist/m/ui/index-G7ZJXNMG.js +1 -0
  170. package/dist/m/vendor/sap-core.vendor-5TWOJYVM.js +7 -0
  171. package/dist/offline-manifest.json +844 -784
  172. package/dist/server/core.cjs +4245 -2614
  173. package/dist/server/markdown.cjs +1 -0
  174. package/dist/server/markdown.mjs +7 -0
  175. package/docs/guide.md +27 -37
  176. package/entries/clay-data.js +1 -1
  177. package/entries/sap.js +6 -5
  178. package/package.json +6 -2
  179. package/packed-contract.json +3 -0
  180. package/src/attrs/save-freeze.js +1 -1
  181. package/src/core/admin-contenteditable.js +1 -1
  182. package/src/core/admin-inputs.js +1 -1
  183. package/src/core/admin-onclick.js +1 -1
  184. package/src/core/admin-resources.js +5 -2
  185. package/src/core/conflict-notice-ui.js +59 -34
  186. package/src/core/draft-mode.js +5 -0
  187. package/src/core/save-core.js +10 -10
  188. package/src/core/save.js +10 -10
  189. package/src/core/snapshot.js +56 -43
  190. package/src/core/stale-host-notice.js +20 -7
  191. package/src/lib/dirty-gate.js +19 -0
  192. package/src/page/editor.js +10 -4
  193. package/src/page/import-markdown.js +22 -8
  194. package/src/page/save-projection.js +1 -1
  195. package/src/plugins/menu/visitor.js +33 -1
  196. package/src/plugins/quickcrop.js +128 -69
  197. package/src/plugins/sortable.js +25 -9
  198. package/src/plugins/visitor-drafts/commit.js +50 -3
  199. package/src/plugins/visitor-drafts/idb.js +8 -2
  200. package/src/plugins/visitor-drafts/recovery-menu.js +118 -0
  201. package/src/plugins/visitor-drafts/recovery.js +64 -0
  202. package/src/plugins/visitor-drafts/session.js +61 -13
  203. package/src/plugins/visitor-drafts/store.js +44 -8
  204. package/src/plugins/visitor-drafts.js +34 -5
  205. package/src/server/markdown/index.js +23 -0
  206. package/src/sync/conflicts.js +3 -1
  207. package/src/sync/data-guard-notice.js +137 -18
  208. package/src/sync/live-sync.js +1 -1
  209. package/src/sync/wire-profile.js +9 -4
  210. package/src/ui/bevel-controls.js +4 -1
  211. package/src/ui/dialogs.js +11 -7
  212. package/src/ui/modal.js +9 -7
  213. package/src/ui/toast.js +67 -32
  214. package/src/vendor/hyper-html-api-data.vendor.js +1 -1
  215. package/src/vendor/hyper-html-api-upgrade.vendor.js +2 -2
  216. package/src/vendor/hyper-undo.vendor.js +1 -1
  217. package/src/vendor/hypercms.vendor.js +7 -7
  218. package/src/vendor/richclay.vendor.js +16 -16
  219. package/src/vendor/sap-core.vendor.js +6 -5
  220. package/src/vendor/sap-ownership.vendor.js +181 -11
  221. package/tool-generation/context.md +69 -0
  222. package/tool-generation/system.md +2 -2
  223. package/dist/m/attrs/save-freeze-JZHKRQLR.js +0 -1
  224. package/dist/m/c-277QP5ET.js +0 -1
  225. package/dist/m/c-3UW5EJ77.js +0 -1
  226. package/dist/m/c-42ZNV7LI.js +0 -7
  227. package/dist/m/c-6Q6RGFBF.js +0 -1
  228. package/dist/m/c-APGHGDZM.js +0 -1
  229. package/dist/m/c-BGN7RCTJ.js +0 -1
  230. package/dist/m/c-CJ7QYEWI.js +0 -1
  231. package/dist/m/c-CVSWLX3X.js +0 -1
  232. package/dist/m/c-DXPOFLEJ.js +0 -1
  233. package/dist/m/c-EILLN2H2.js +0 -1
  234. package/dist/m/c-EODTTNVA.js +0 -1
  235. package/dist/m/c-ESK4S67I.js +0 -1
  236. package/dist/m/c-FDWR3FL7.js +0 -1
  237. package/dist/m/c-FYDKYW6E.js +0 -1
  238. package/dist/m/c-HKSLOVU4.js +0 -1
  239. package/dist/m/c-HTLYXCUH.js +0 -1
  240. package/dist/m/c-IUL7PU4P.js +0 -1
  241. package/dist/m/c-JQF2EUCG.js +0 -1
  242. package/dist/m/c-MFOSMAVM.js +0 -3
  243. package/dist/m/c-MQYEDF3Q.js +0 -1
  244. package/dist/m/c-MR75YPRT.js +0 -1
  245. package/dist/m/c-NHXOBD6A.js +0 -1
  246. package/dist/m/c-NVU3DORS.js +0 -1
  247. package/dist/m/c-OYHI67B6.js +0 -1
  248. package/dist/m/c-PWJSJEJU.js +0 -1
  249. package/dist/m/c-QENKN7QI.js +0 -1
  250. package/dist/m/c-R23UHMXG.js +0 -1
  251. package/dist/m/c-SGH3UTF3.js +0 -1
  252. package/dist/m/c-SXNSSHPP.js +0 -1
  253. package/dist/m/c-TFLRT5JX.js +0 -1
  254. package/dist/m/c-U4NTUVDZ.js +0 -1
  255. package/dist/m/c-V2U3F4QX.js +0 -1
  256. package/dist/m/c-VG5XIN4T.js +0 -1
  257. package/dist/m/c-VHSMPITY.js +0 -1
  258. package/dist/m/c-Z4G2UK6T.js +0 -4
  259. package/dist/m/core/draft-mode-4MCL3LYI.js +0 -1
  260. package/dist/m/core/unsaved-warning-ITZDIZ2I.js +0 -1
  261. package/dist/m/internals/index-HS3CQDFW.js +0 -1
  262. package/dist/m/manifest-50FF1C45.js +0 -1
  263. package/dist/m/manifest-edit-BE1A621D.js +0 -1
  264. package/dist/m/plugins/quickcrop-X5MRIBAP.js +0 -26
  265. package/dist/m/plugins/sortable-XCHQG65Z.js +0 -1
  266. package/dist/m/plugins/undo-VLRBQNPN.js +0 -1
  267. package/dist/m/plugins/visitor-drafts-RTZNONHT.js +0 -20
  268. package/dist/m/plugins/wire-M2NR354P.js +0 -1
  269. package/dist/m/reader-core-T2S3JC4E.js +0 -77
  270. package/dist/m/sync/live-sync-Z64YREWQ.js +0 -1
  271. package/dist/m/ui/index-MGTWOW2C.js +0 -1
  272. package/dist/m/vendor/sap-core.vendor-QAEPMETX.js +0 -6
  273. /package/dist/m/{c-QTTJYJMA.js → c-FILLTJA7.js} +0 -0
  274. /package/dist/m/plugins/{quickcrop-X5MRIBAP.js.LEGAL.txt → quickcrop-VNRXGRPC.js.LEGAL.txt} +0 -0
  275. /package/dist/m/plugins/{richclay-Y2NV44NA.js.LEGAL.txt → richclay-V6WKJTUF.js.LEGAL.txt} +0 -0
@@ -1,4 +1,4 @@
1
1
  // GENERATED — do not edit. Vendored from
2
2
  // hyper-html-api/dist/hyper-html-api.engine.esm.js via hyper-html-api
3
3
  // `npm run copy-to-clayjs`. Edit the hyper-html-api source and re-run.
4
- var At=Object.defineProperty;var Et=(e,t)=>{for(var n in t)At(e,n,{get:t[n],enumerable:!0})};var re=["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"],ie=new Set(re),he=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),B=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),$e=new Set(["checked","selected","disabled","readOnly","paused"]);function pe(e,t){return t==null?$e.has(e)?!1:"":$e.has(e)?t==="false"?!1:!!t:t}var R={};Et(R,{CodecRefused:()=>ge,EmptyListInsert:()=>P,MAX_RULE_DEPTH:()=>M,MaxRuleDepthExceeded:()=>_,NoRulesTag:()=>me,RuleTargetReadOnly:()=>z,RulesParseError:()=>C,ShapeMismatch:()=>U,UnknownCodec:()=>K,UnknownRulesVersion:()=>H,WriteNotRoundTripped:()=>oe,WriteRefused:()=>F,WriteRejected:()=>ye});var C=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},H=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1" and "2".`),this.name="UnknownRulesVersion",this.version=t}},M=20,_=class extends Error{constructor(t){super(`rule depth exceeded ${M} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},U=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},P=class extends Error{constructor(t,n){super(n?`cannot add items to empty list at "${t.join(".")}" \u2014 ${n}`:`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},z=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},F=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}};function Tt(e){return e.reduce((n,i)=>typeof i=="number"?`${n}[${i}]`:n?`${n}.${i}`:String(i),"")||"(root)"}var oe=class extends Error{constructor(t){super(`write did not round-trip at "${Tt(t)}"`),this.name="WriteNotRoundTripped",this.path=t}},me=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},ye=class extends Error{constructor(t,n){super(`write rejected: ${t.length} unknown key(s), ${n.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=t,this.unmatched=n}},K=class extends Error{constructor(t){super(`unknown codec "${t}": no codec by that name is given to this call`),this.name="UnknownCodec",this.code="unknown-codec",this.codec=t}},ge=class extends Error{constructor(t,n){super(n),this.name="CodecRefused",this.code=t}};function N(e){let t=0,n=null,i=-1;for(let r=0;r<e.length;r++){let o=e[r];o==="\\"?r++:n?o===n&&(n=null):o==='"'||o==="'"?n=o:o==="["||o==="("?t++:o==="]"||o===")"?t>0&&t--:o==="@"&&t===0&&(i=r)}return i}var je="[*]";function b(e){let t=N(e),n=t===-1?e:e.slice(0,t),i=n.endsWith(je),r={selector:i?n.slice(0,-je.length):n,prop:t===-1?null:e.slice(t+1)||null};return i&&(r.all=!0),r}function we(e){let t=0,n=null,i=-1,r=!1;for(let o=0;o<e.length;o++){let c=e[o];c==="\\"?o++:n?c===n&&(n=null):c==='"'||c==="'"?n=c:c==="["||c==="("?t++:c==="]"||c===")"?t>0&&t--:t===0&&c===">"?i=o:t===0&&c===","&&(r=!0)}return r||i===-1||!Ot(e,i+1)?null:e.slice(0,i).trim()||null}function Ot(e,t){let n=t,i=e.replace(/\s+$/,"").length;for(;n<i&&/\s/.test(e[n]);)n++;let r=0,o=null;for(;n<i;n++){let c=e[n];if(c==="\\")n++;else if(o)c===o&&(o=null);else if(c==='"'||c==="'")o=c;else if(c==="["||c==="(")r++;else if(c==="]"||c===")")r>0&&r--;else if(r===0&&(c==="+"||c==="~"||/\s/.test(c)))return!1}return!0}var St=/^codec\(([a-z][a-z0-9-]*)\)$/;function $(e){if(typeof e!="string")return null;let t=N(e);if(t===-1)return null;let n=St.exec(e.slice(t+1));if(!n)return null;let{selector:i,all:r}=b(e);if(r)throw new C("A @codec(name) rule cannot use [*].");return{selector:i,name:n[1]}}var xt=/^--[A-Za-z0-9_-]+$/;function k(e){return typeof e=="string"&&xt.test(e)}function De(e){let t=[],n=[],i=null,r=0;for(let o=0;o<e.length;o++){let c=e[o];if(i){c==="\\"?o++:c===i&&(i=null);continue}if(c==="/"&&e[o+1]==="*"){let l=e.indexOf("*/",o+2);o=l===-1?e.length:l+1;continue}c==='"'||c==="'"?i=c:c==="("?n.push(")"):c==="["?n.push("]"):c==="{"?n.push("}"):(c===")"||c==="]"||c==="}")&&n[n.length-1]===c?n.pop():c===";"&&n.length===0&&(t.push(e.slice(r,o)),r=o+1)}return t.push(e.slice(r)),t}function bt(e){let t="",n=null;for(let i=0;i<e.length;i++){let r=e[i];if(n){t+=r,r==="\\"&&i+1<e.length?t+=e[++i]:r===n&&(n=null);continue}if(r==="/"&&e[i+1]==="*"){let o=e.indexOf("*/",i+2);i=o===-1?e.length:o+1,t+=" ";continue}(r==='"'||r==="'")&&(n=r),t+=r}return t}function ve(e){e=bt(e);let t=e.indexOf(":");if(t===-1)return null;let n=e.slice(0,t).trim(),i=e.slice(t+1).trim(),r=/!\s*important\s*$/i.exec(i);return r&&(i=i.slice(0,r.index).trim()),{name:n,value:i,important:!!r}}function v(e,t){if(e==null)return null;let n=null;for(let i of De(String(e))){let r=ve(i);!r||r.name!==t||(!n||r.important||!n.important)&&(n=r)}return n?n.value:null}function We(e,t,n){let i=e==null?"":String(e),r=n==null||n==="",o=De(i),c=o.map(ve),l=c.some(d=>d&&d.name===t&&d.important),s=[],f=!1;o.forEach((d,h)=>{let A=c[h];if(!A||A.name!==t){s.push(d);return}if(r||f)return;let a=/^\s*/.exec(d)[0];s.push(`${a}${t}: ${n}${l?" !important":""}`),f=!0});let u=s.join(";");if(!r&&!f){let d=u.trimEnd();u=d===""?`${t}: ${n}`:`${d}${d.endsWith(";")?" ":"; "}${t}: ${n}`}return u.trim()===""?null:u}function se(e,t,n,i){let r=e.attr(t,"style");if((v(r,n)??"")===i)return;let o=We(r,n,i);o==null?e.removeAttr(t,"style"):e.attr(t,"style",o)}var qe=/^[a-z][a-z0-9-]*$/,Ae=new Map;function Ee(e,t){if(typeof e!="string"||!qe.test(e))throw new Error(`hyper-html-api: invalid codec name ${JSON.stringify(e)} (must match ${qe})`);if(!t||typeof t.read!="function"||typeof t.write!="function"||typeof t.same!="function")throw new Error(`hyper-html-api: codec "${e}" needs read, write and same functions`);Ae.set(e,t)}function Te(e){return Ae.get(e)??null}function Oe(){return Object.fromEntries(Ae)}var Rt='The @codec(name) rule form needs a rules tag with data-rules-version="2".',Ct="A @codec(name) rule must be the value of a top level key.";function ce(e,t){let n=$(e);return n?{...n,codec:t.codecs[n.name]}:null}function j(e,t={}){let n=t.version??"1",i=t.codecs??{};r(e,0);function r(o,c){if(!(c>M)){if(typeof o=="string"){let l=$(o);if(!l)return;if(n!=="2")throw new C(Rt);if(c!==1)throw new C(Ct);if(!Object.prototype.hasOwnProperty.call(i,l.name))throw new K(l.name);return}if(Array.isArray(o)){r(o[1],c+1);return}if(o&&typeof o=="object")for(let l of Object.values(o))r(l,c+1)}}}function L(e,t,n,i={}){if(Object.prototype.hasOwnProperty.call(i,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return j(n,i),xe(e,t,n,{depth:0,path:[]},i)}function xe(e,t,n,i,r){if(i.depth>M)throw new _(i.path);if(typeof n=="string")return Nt(e,t,n,i,r);if(Array.isArray(n)){let[o,c]=n,l=e.find(t,o,r);return Ve(r,i,l),l.map((s,f)=>xe(e,s,c,{depth:i.depth+1,path:[...i.path,f]},r))}if(typeof n=="object"&&n!==null){let o={};for(let[c,l]of Object.entries(n))o[c]=xe(e,t,l,{depth:i.depth+1,path:[...i.path,c]},r);return o}return null}function Nt(e,t,n,i,r){if(n.endsWith("[]")){let u=n.slice(0,-2),d=e.find(t,u,r);return Ve(r,i,d),d.map(h=>e.text(h))}let o=ce(n,r);if(o)return Pt(e,t,o,r);if(n.startsWith("@"))return Se(e,t,n.slice(1));let c=N(n);if(c!==-1){let{selector:u,all:d}=b(n),h=n.slice(c+1),A=u?e.find(t,u,r):[t];return d&&r.allMatches?A.map(a=>Se(e,a,h)):A.length===0?null:Se(e,A[0],h)}if(n===".")return e.text(t);let{selector:l,all:s}=b(n),f=e.find(t,l,r);return s&&r.allMatches?f.map(u=>e.text(u)):f.length===0?null:e.text(f[0])}function Pt(e,t,{selector:n,codec:i},r){let o=n?e.find(t,n,r):[t];return o.length===0?null:i.read(e,o[0],{query:r.query,view:r.view,region:r.region})}function Ve(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(i){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,i)}}function Se(e,t,n){if(k(n))return v(e.attr(t,"style"),n);if(ie.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let i=e.attr(t,n);return i??null}function Ue(e,t,n,i){let r=e.length,o=t.length,c=new Array(r).fill(-1);if(i){let p=new Set;for(let y=0;y<r;y++){let w=i[y];!(w>=0&&w<o)||p.has(w)||(c[y]=w,p.add(w))}}if(r===0||o===0)return c;let l=e.map(p=>Be(p,n)),s=t.map(p=>Be(p,n)),f=new Array(o).fill(!1);for(let p of c)p>=0&&(f[p]=!0);let u=new Map;s.forEach((p,y)=>{f[y]||u.set(p,u.has(p)?-1:y)});let d=new Map;l.forEach((p,y)=>{c[y]>=0||d.set(p,(d.get(p)||0)+1)}),l.forEach((p,y)=>{if(c[y]>=0||d.get(p)!==1)return;let w=u.get(p);w===void 0||w===-1||f[w]||(c[y]=w,f[w]=!0)});let h=[];for(let p=0;p<r;p++)c[p]<0&&h.push(p);let A=[];for(let p=0;p<o;p++)f[p]||A.push(p);if(h.length===0||A.length===0)return c;let a=r*o+1,m=Mt(e,t,n),g=(p,y)=>m(p,y)*a+Math.abs(p-y);for(let[p,y]of kt(h,A,g))c[p]=y;return c}var ze=e=>typeof e=="object"&&e!==null;function Be(e,t){if(!ze(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(i=>{let r=JSON.stringify(e?.[i]);return r===void 0?" undef":r}))}function Mt(e,t,n){if(!ze(n))return(l,s)=>e[l]===t[s]?0:1;let i=Object.keys(n),r=l=>i.map(s=>JSON.stringify(l?.[s])),o=e.map(r),c=t.map(r);return(l,s)=>{let f=o[l],u=c[s],d=0;for(let h=0;h<i.length;h++)f[h]!==u[h]&&d++;return d}}function kt(e,t,n){return e.length<=t.length?He(e,t,n,!1):He(t,e,(i,r)=>n(r,i),!0)}function He(e,t,n,i){let r=e.length,o=t.length,c=[];for(let d=0;d<=r;d++)c.push(new Float64Array(o+1).fill(1/0));let l=[];for(let d=0;d<=r;d++)l.push(new Uint8Array(o+1));for(let d=0;d<=o;d++)c[r][d]=0;for(let d=r-1;d>=0;d--)for(let h=o-1;h>=0;h--){let A=n(e[d],t[h])+c[d+1][h+1],a=c[d][h+1];A<=a?(c[d][h]=A,l[d][h]=1):c[d][h]=a}let s=[],f=0,u=0;for(;f<r&&u<o;)l[f][u]&&(s.push(i?[t[u],e[f]]:[e[f],t[u]]),f++),u++;return s}function Re(e,t,n,i,r,o,c,l={}){let s=e.find(t,n,l);if(r.length===0){s.forEach(E=>e.remove(E)),be(l,"onRowsApplied",o.path,[]);return}let f=r.length>s.length,u=s[0]||null;if(f&&!u&&(u=$t(e,t,n,l),!u))throw new P(o.path);let d=s.map(E=>_t(e,E,i,l)),h=null;if(f&&u){h=e.clone(u),l.templateAttr&&e.removeAttr(h,l.templateAttr);let E=e.stripIds(h);E>0&&console.warn(`[hyper-html-api] stripped ${E} id attribute(s) from cloned template at "${o.path.join(".")||"(root)"}"`)}let A=Ue(r,d,i,Lt(e,s,r,o,l)),a=s.length>0?e.parent(s[0]):Wt(e,t,n,u,o,l),m=s.length>0?Ye(e,a,s[0]):0,g=Bt(e,s),p=new Set,y=[],w=r.map((E,x)=>{let O=A[x];if(O>=0)return p.add(O),y.push(!1),s[O];y.push(!0);let T=e.clone(h);return e.stripIds(T),T});s.forEach((E,x)=>{p.has(x)||e.remove(E)}),g?Vt(e,a,m,w,y):Ht(e,w,y,a,m),It(e,w,i,r,o,c,l),be(l,"onRowsApplied",o.path,w)}function be(e,t,n,i){if(typeof e[t]=="function")try{return e[t](n.slice(),i)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function Lt(e,t,n,i,r){let o=be(r,"identifyRows",i.path,n);if(!Array.isArray(o))return null;let c=new Array(n.length).fill(-1),l=new Set,s=new Map(t.map((f,u)=>[e.identity(f),u]));for(let f=0;f<n.length;f++){if(!o[f])continue;let u=s.get(e.identity(o[f]));u===void 0||l.has(u)||(c[f]=u,l.add(u))}return c}function It(e,t,n,i,r,o,c){t.forEach((l,s)=>{if(n===null){let f=i[s],u=f==null?"":String(f);e.text(l)!==u&&e.text(l,u)}else{let f=o(e,l,n,i[s],{depth:r.depth+1,path:[...r.path,s]},c);f&&f!==l&&(t[s]=f)}})}function _t(e,t,n,i){return n===null?e.text(t):L(e,t,n,i.onRowsRead?{...i,onRowsRead:void 0}:i)}function Ye(e,t,n){let i=e.children(t);for(let r=0;r<i.length;r++)if(e.sameNode(i[r],n))return r;return-1}function $t(e,t,n,i){if(!i.templateAttr)return null;let r=/^\s*:scope\s*>\s*/.test(n),o=new RegExp(":not\\(\\["+i.templateAttr.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")+"\\]\\)","g"),c=n.replace(/^\s*:scope\s*>\s*/,"").replace(o,""),l=r?jt(c):0,s=we(c),f=t;for(;f;){let u=e.find(f,c,{includeRulesTag:!1,templateAttr:null});for(let d of u)if(e.attr(d,i.templateAttr)!=null&&!(r&&!vt(e,t,d,l))&&!(s&&!e.matches(e.parent(d),s)))return d;f=e.parent(f)}return null}function jt(e){let t=0,n=null,i=1;for(let r=0;r<e.length;r++){let o=e[r];if(o==="\\")r++;else if(n)o===n&&(n=null);else if(o==='"'||o==="'")n=o;else if(o==="["||o==="(")t++;else if(o==="]"||o===")")t>0&&t--;else if(t===0&&o===">")i++;else{if(t===0&&(o==="+"||o==="~"))return null;if(t===0&&/\s/.test(o)){if(!Dt(e,r))return null;for(;r+1<e.length&&/\s/.test(e[r+1]);)r++}}}return i}function Dt(e,t){let n=t;for(;n<e.length&&/\s/.test(e[n]);)n++;let i=t>0?e[t-1]:"",r=n<e.length?e[n]:"";return Fe(i)||Fe(r)}function Fe(e){return e===">"||e==="+"||e==="~"}function vt(e,t,n,i){if(i===null)return!0;let r=n;for(let s=0;s<i;s++)if(r=e.parent(r),!r)return!1;let o=e.prop(t,"tagName");if(!o)return!0;let c=e.prop(r,"tagName");if(!c||String(c).toLowerCase()!==String(o).toLowerCase())return!1;let l=new Set(Ke(e,r));return Ke(e,t).every(s=>l.has(s))}function Ke(e,t){let n=e.attr(t,"class");return n?String(n).split(/\s+/).filter(Boolean):[]}function Wt(e,t,n,i,r,o){let c=e.parent(i);if(c&&qt(e,t,c)&&!Xe(e,c,o))return c;let l=we(n);if(!l)throw new P(r.path,`the list selector "${n}" 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 f=(l===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,l,o)).filter(u=>!Xe(e,u,o));if(f.length===0)throw new P(r.path,`no container matching "${l}" inside this context to hold the new rows`);if(f.length>1)throw new P(r.path,`"${l}" matches ${f.length} containers inside this context, so the new rows have no single destination`);return f[0]}function qt(e,t,n){let i=n;for(;i;){if(e.sameNode(i,t))return!0;i=e.parent(i)}return e.parent(t)?!1:e.find(t,"*",{includeRulesTag:!0,templateAttr:null}).some(r=>e.sameNode(r,n))}var Je=["no-data","editor-ui"];function Xe(e,t,n){let i=t;for(;i;){if(n.templateAttr&&e.attr(i,n.templateAttr)!=null||Je.some(o=>e.attr(i,o)!=null))return!0;let r=e.attr(i,"clay");if(r&&r.split(/\s+/).some(o=>Je.includes(o)))return!0;i=e.parent(i)}return!1}function Vt(e,t,n,i,r){let o=e.children(t),c=o.map(s=>e.identity(s)),l=!1;i.forEach((s,f)=>{let u=e.identity(s),d=n+f;if(c[d]===u)return;if(!r[f]){let A=c.indexOf(u);A!==-1&&(c.splice(A,1),o.splice(A,1))}let h=Math.min(d,o.length);h<o.length?e.insertBefore(o[h],s):o.length?l?e.insertAfter(o[o.length-1],s):(e.insertAt(t,s,d),l=!0):e.insertAt(t,s,0),c.splice(h,0,u),o.splice(h,0,s)})}function Bt(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let i=new Map(e.children(n).map((o,c)=>[e.identity(o),c])),r=[];for(let o of t){let c=i.get(e.identity(o));if(c===void 0)return!1;r.push(c)}return r.sort((o,c)=>o-c),r[r.length-1]-r[0]===r.length-1}function Ht(e,t,n,i,r){let o=null,c=r;for(let l=0;l<t.length;l++){if(!n[l]){o=t[l];continue}let s=o?e.parent(o):i;if(!s)continue;let f=o?Ye(e,s,o)+1:c++;e.insertAt(s,t[l],f),o=t[l]}}function D(e,t,n,i,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");j(n,r);let o=[];if(Ce(n,i,[],o),o.length)throw new U(o);le(e,t,n,i,{depth:0,path:[]},r)}function le(e,t,n,i,r,o={}){if(r.depth>M)throw new _(r.path);if(i===void 0)return t;if(typeof n=="string")return Ut(e,t,n,i,r,o);if(Array.isArray(n)){let[c,l]=n;return Re(e,t,c,l,i,r,le,o),t}if(typeof n=="object"&&n!==null){for(let[c,l]of Object.entries(n)){let s=le(e,t,l,i==null?i:i[c],{depth:r.depth+1,path:[...r.path,c]},o);s&&s!==t&&(t=s)}return t}return t}function Ut(e,t,n,i,r,o){if(n.endsWith("[]")){let d=n.slice(0,-2);return Re(e,t,d,null,i,r,le,o),t}let c=ce(n,o);if(c){let d=c.selector?e.find(t,c.selector,o):[t];return d.length&&c.codec.write(e,d[0],i,{query:o.query}),t}if(n.startsWith("@"))return Ze(e,t,n.slice(1),i);let l=N(n);if(l!==-1){let{selector:d,all:h}=b(n),A=n.slice(l+1),a=d?e.find(t,d,o):[t];for(let m of h?a:a.slice(0,1))Ze(e,m,A,i);return t}if(n===".")return Ge(e,t,i),t;let{selector:s,all:f}=b(n),u=e.find(t,s,o);for(let d of f?u:u.slice(0,1))Ge(e,d,i);return t}function Ge(e,t,n){let i=n==null?"":String(n);e.text(t)!==i&&e.text(t,i)}function zt(e,t,n,i){if(e.styleVar){e.styleVar(t,n,i);return}se(e,t,n,i)}function Ze(e,t,n,i){if(k(n))return zt(e,t,n,i==null?"":String(i).trim()),t;if(B.has(n)){let r=e.prop(t,n);if(r===i||r!=null&&i!=null&&String(r)===String(i))return t;throw new z(n)}if(n==="outerHTML"){let r=i==null?"":String(i);return e.replaceWith(t,r)}if(he.has(n)){let r=pe(n,i);return e.prop(t,n)!==r&&e.prop(t,n,r),t}if(i==null)e.attr(t,n)!=null&&e.removeAttr(t,n);else{let r=String(i);e.attr(t,n)!==r&&e.attr(t,n,r)}return t}function Ce(e,t,n,i){if(t!==void 0){if(typeof e=="string"){if($(e))return;if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,o)=>{typeof r=="object"&&r!==null&&i.push({path:X([...n,o]),expected:"scalar",got:J(r)})}):i.push({path:X(n),expected:"array",got:J(t)});return}t!==null&&typeof t=="object"&&i.push({path:X(n),expected:"scalar",got:J(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){i.push({path:X(n),expected:"array",got:J(t)});return}let r=e[1];t.forEach((o,c)=>Ce(r,o,[...n,c],i));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){i.push({path:X(n),expected:"object",got:J(t)});return}for(let[r,o]of Object.entries(e))Ce(o,t[r],[...n,r],i)}}}function J(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function X(e){return e.join(".")}function Ne(e){try{return JSON.parse(e)}catch(t){throw new C(`Invalid strict JSON: ${t.message}`,t)}}function Y(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 n(r){let o=[],c=0;for(;c<r.length;){let l=r[c];if(/\s/.test(l)){c++;continue}if("{}".includes(l)){o.push({type:l,value:l}),c++;continue}if(l==="["){let d=!1,h=c+1;for(;h<r.length&&/\s/.test(r[h]);)h++;if(h<r.length&&/[a-zA-Z_]/.test(r[h])&&(d=!0),!d){o.push({type:l,value:l}),c++;continue}}if(l==="]"){o.push({type:l,value:l}),c++;continue}if(l===":"){o.push({type:t.COLON,value:l}),c++;continue}if(l===","){o.push({type:t.COMMA,value:l}),c++;continue}if(l==='"'||l==="'"){let d=l,h=c+1;for(;h<r.length&&r[h]!==d;)r[h]==="\\"&&h++,h++;o.push({type:t.STRING,value:r.substring(c+1,h),quoted:!0,sourceQuote:d}),c=h+1;continue}let s=c,f;for(;s<r.length&&!/[{},]/.test(r[s]);)if(r[s]===":"){let d=[":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"],h=!1;for(let A of d){let a=A.substring(1);if(r.substring(s+1,s+1+a.length)===a){h=!0,s+=a.length;break}}if(!h)break}else if(r[s]==="["){for(s++;s<r.length&&r[s]!=="]";){if(r[s]==='"'||r[s]==="'"){let d=r[s];for(s++;s<r.length&&r[s]!==d;)r[s]==="\\"&&s++,s++}s++}s<r.length&&r[s]==="]"&&s++}else s++;f=r.substring(c,s);let u=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(f)?u=t.NUMBER:f==="true"||f==="false"||f==="null"?u=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(f)&&(u=t.SELECTOR),o.push({type:u,value:f,quoted:!1}),c=s}return o}function i(r){let o="";for(let c=0;c<r.length;c++){let l=r[c];if("{}".includes(l.type)||"[]".includes(l.type)){o+=l.value;continue}if(l.type===t.COLON){o+=l.value;continue}if(l.type===t.COMMA){let s=r[c+1];if(s&&(s.type==="}"||s.type==="]"))continue;o+=l.value;continue}if(l.type===t.STRING&&l.quoted){let s=l.value;l.sourceQuote==="'"&&(s=s.replace(/\\'/g,"'"),s=s.replace(/(\\*)"/g,(f,u)=>u.length%2===0?u+'\\"':f)),o+=`"${s}"`;continue}if(l.type===t.NUMBER||l.type===t.BOOLEAN){o+=l.value;continue}if(l.type===t.SELECTOR||l.type===t.IDENTIFIER){o+=`"${l.value}"`;continue}o+=`"${l.value}"`}return o}try{let r=n(e),o=i(r);return JSON.parse(o)}catch(r){throw new C("Invalid extraction rules syntax: "+r.message,r)}}var et=["1","2"],Qe=/^[a-zA-Z0-9_-]+$/;function W(e,t,n){let i;if(n===void 0)i="script[data-rules-name]";else{if(typeof n!="string"||!Qe.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${Qe})`);i=`script[data-rules-name~="${n}"]`}let r=e.find(t,i,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let o=r[0],c=e.attr(o,"data-rules-version");if(!et.includes(c))throw new H(c);return{rules:Y(e.text(o)),tagNode:o,version:c}}var fe=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"]})}),Ft=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),tt=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);function G(e,t){if(!e||e.nodeType!==1)return!1;let n=e.getAttribute?.("clay");return!!(n&&n.split(/\s+/).includes(t)||e.hasAttribute?.(t))}function Pe(e,t){if(G(e,t))return!0;for(let[n,i]of Object.entries(Ft))if(i.includes(t)&&G(e,n))return!0;return!1}function Z(e){let t=fe[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function Kt(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let i=fe[t];if(!i)throw new Error(`Unknown region capability: ${t}`);if(i.tokens.some(r=>Pe(n,r))||i.bundles.some(r=>G(n,r)))return n;n=n.parentElement}return null}function nt(e,t){return!!Kt(e,t)}var ue=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",...tt],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"]})}),Jt=new Set(["textContent","innerText"]);function rt(e){let n=String(e).replace(/^[\u0000- ]+|[\u0000- ]+$/g,"").replace(/[\t\n\r]/g,"").match(/^([a-zA-Z][a-zA-Z0-9+.-]*):/);return n?n[1].toLowerCase():null}var Xt=/^[^\t\n\f\r "'>/=\u0000-\u001f\u007f]+$/;function it(e,t,n=ue){if(!Xt.test(String(e)))return`attribute name ${JSON.stringify(String(e))} is not valid`;let i=String(e).toLowerCase();if(n.refusedAttributePrefixes.some(r=>i.startsWith(r)))return`attribute "${i}" can run script`;if(n.refusedAttributes.includes(i))return`attribute "${i}" is not content`;if(n.urlAttributes.includes(i)&&t!=null){let r=i==="srcset"?String(t).split(",").map(o=>o.trim().split(/\s+/)[0]).filter(Boolean):[String(t)];for(let o of r){let c=rt(o);if(c&&n.refusedSchemes.includes(c))return`"${c}:" URLs are not allowed in "${i}"`}}return null}function Me(e,t){let n=e.prop(t,"tagName");return n?String(n).toLowerCase():""}function Yt(e,t){let n=Me(e,t)||"node",i=e.attr(t,"id");return i?`<${n}#${i}>`:`<${n}>`}function Gt(e,t,n){let i=t;for(;i;){let r=Me(e,i);if(r&&n.refusedTargets.includes(r))return r;i=e.parent(i)}return null}function ot(e,t){return e.find(t,"script[data-rules-name]",{includeRulesTag:!0,templateAttr:null}).length>0}function Zt(e,t){return Me(e,t)==="script"&&e.attr(t,"data-rules-name")!=null?!0:ot(e,t)}function Qt(e){if(/[\u0000-\u001f\u007f]/.test(e))return"control characters are not allowed in a custom property value";let t=[],n=null;for(let i=0;i<e.length;i++){let r=e[i];if(n){r===n&&(n=null);continue}if(r==='"'||r==="'")n=r;else{if(r==="/"&&e[i+1]==="*")return"comments are not allowed in a custom property value";if(r==="(")t.push(")");else if(r==="[")t.push("]");else if((r===")"||r==="]")&&t.pop()!==r)return`"${r}" does not close anything in this custom property value`}}return n?"a custom property value must close its quotes":t.length?"a custom property value must close its brackets":null}function st(e,t=ue){let n=t.customPropertyValues,i=String(e);if(i.length>n.maxLength)return`custom property values are limited to ${n.maxLength} characters`;let r=n.refusedCharacters.find(s=>i.includes(s));if(r)return`${JSON.stringify(r)} is not allowed in a custom property value`;let o=Qt(i);if(o)return o;let c=i.toLowerCase(),l=n.refusedFunctions.find(s=>new RegExp(`(^|[^a-z0-9_-])${s.replace(/[-]/g,"\\-")}\\s*\\(`).test(c));return l?`"${l}()" is not allowed in a custom property value`:null}function ae(e,t=ue){let n=[],i=(s,f)=>(n.push({target:Yt(e,s),reason:f}),!1),r=s=>{let f=Gt(e,s,t);return f?i(s,`inside <${f}>, which is not content`):!0},o=s=>r(s)?ot(e,s)?i(s,"a text write here would delete the data rules tag"):!0:!1,c=(s,f,u)=>{if(!r(s))return!1;let d=it(f,u,t);return d?i(s,d):!0};return{...e,text(s,f){if(f===void 0)return e.text(s);o(s)&&e.text(s,f)},attr(s,f,u){if(u===void 0)return e.attr(s,f);c(s,f,u)&&e.attr(s,f,u)},removeAttr(s,f){c(s,f,null)&&e.removeAttr(s,f)},styleVar(s,f,u){if((v(e.attr(s,"style"),f)??"")!==u&&r(s)){if(!k(f))return i(s,`"${f}" is not a custom property`);if(u!==""){let d=st(u,t);if(d)return i(s,d)}se(e,s,f,u)}},prop(s,f,u){if(u===void 0)return e.prop(s,f);if(t.refusedRuleForms.includes(f))return i(s,`"@${f}" writes HTML, only text is allowed`);if(Jt.has(f)){o(s)&&e.prop(s,f,u);return}c(s,f==="className"?"class":f,u)&&e.prop(s,f,u)},remove(s){if(Zt(e,s)){i(s,"removing this would delete the data rules tag");return}e.remove(s)},replaceWith(s,f){return f===e.prop(s,"outerHTML")||i(s,'"@outerHTML" writes HTML, only text is allowed'),s},refusals:n,assertClean(){if(n.length)throw new F(n.slice())}}}function Q(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function ct(e){return e.reduce((t,n)=>typeof n=="number"?`${t}[${n}]`:t?`${t}.${n}`:n,"")}function ke(e,t,n,i,r={}){j(n,r);let o=[],c=[];function l(f,u,d){if(Array.isArray(f)){let[,h]=f;if(!Array.isArray(u)||!Q(h))return;u.forEach((A,a)=>l(h,A,[...d,a]));return}if(!(!Q(f)||!Q(u)))for(let h of Object.keys(u))Object.prototype.hasOwnProperty.call(f,h)?l(f[h],u[h],[...d,h]):o.push(ct([...d,h]))}function s(f,u,d,h){if(d!==void 0){if(typeof u=="string"){if(u.endsWith("[]")||u==="."||u.startsWith("@"))return;let{selector:A}=b(u);if(!A)return;e.find(f,A,r).length===0&&c.push({path:ct(h),selector:A});return}if(!Array.isArray(u)&&Q(u)&&Q(d))for(let[A,a]of Object.entries(u))s(f,a,d[A],[...h,A])}}return l(n,i,[]),s(t,n,i,[]),{unknownKeys:o,unmatched:c}}function Le(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null,version:"1"};if(typeof n=="string"){let i=t&&t.ownerDocument?t.ownerDocument:t;return W(e,i,n)}return null}var tn=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function nn(e,t){if(!/^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(e.tagName||""))return;let n=(e.getAttribute?.("type")||"").toLowerCase();"value"in e&&"value"in t&&e.tagName!=="OPTION"&&n!=="checkbox"&&n!=="radio"&&n!=="file"&&(t.value=e.value),e.tagName==="INPUT"&&(n==="checkbox"||n==="radio")&&(t.checked=e.checked),e.tagName==="OPTION"&&(t.selected=e.selected),"indeterminate"in e&&"indeterminate"in t&&(t.indeterminate=e.indeterminate)}function lt(e,t,n,i){if(i)return!!e.closest?.(t);let r=e;for(;r?.nodeType===1;){if(r.matches(t))return!0;if(r===n)break;r=r.parentElement}return!1}function ft(e,t,n,i,r,o){return(o?nt(e,t):lt(e,n,r,!1))||!!(i&&(o&&e!==r?e.matches(i):lt(e,i,r,o)))}function rn(e,t){let n=fe[t];return n.tokens.some(i=>Pe(e,i))||n.bundles.some(i=>G(e,i))}var on=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function ut(e,t,n,i){if(e.nodeType===1&&i(e)){n.dropped.push(t);return}n.cloneToLive.set(t,e),n.liveToClone.set(e,t);let r=e,o=t;if(e.nodeType===1){if(on.has(e.tagName)&&n.controls.push(e,t),e.tagName==="TEMPLATE"){for(;t.firstChild;)t.removeChild(t.firstChild);r=e.content,o=t.content,n.cloneToLive.set(o,r),n.liveToClone.set(r,o)}}else if(e.nodeType!==11)return;let c=o.firstChild;for(let l=r.firstChild;l&&c;l=l.nextSibling)ut(l,c,n,i),c=c.nextSibling}function ee(e,{capability:t="data",exclude:n=null,inherit:i=!0,provenance:r=null}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let o=e.nodeType===9?e:e.ownerDocument;if(!o?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let c=o.implementation.createHTMLDocument(""),l=r||new WeakMap,s=new WeakMap,f=e.nodeType===9?e.documentElement:e;n&&c.documentElement.matches(n);let u=Z(t),d=i?a=>rn(a,t)||!!(n&&a.matches(n)):a=>ft(a,t,u,n,f,!1),h=null;if(f.nodeType!==1||!ft(f,t,u,n,f,i)){h=c.importNode(f,!0);let a={cloneToLive:l,liveToClone:s,dropped:[],controls:[]};ut(f,h,a,d);for(let m of a.dropped)m.remove();for(let m=0;m<a.controls.length;m+=2)nn(a.controls[m],a.controls[m+1])}e.nodeType===9&&h&&(c.replaceChild(h,c.documentElement),s.set(e,c),l.set(c,e));let A=a=>{if(tn.test(a))throw new Error(`Filtered content queries do not support stateful selector: ${a}`)};return{root:h,document:c,capability:t,selector:Z(t),cloneToLive:l,liveToClone:s,original(a){return l.get(a)||null},cloneOf(a){return s.get(a)||null},query(a,m=h){return A(a),Array.from(m.querySelectorAll(a),g=>l.get(g)||g)},text(a=h){return(a===h?h:s.get(a))?.textContent||""},html(a=h){return(a===h?h:s.get(a))?.innerHTML??""},clone(a=h){let m=a===h?h:s.get(a);return m?c.importNode(m,!0):null}}}function dt(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function sn(e){return e?(e.nodeType===9||e.nodeType===11,e):null}function at(e,t,n){!e||e.nodeType!==1||(t==="value"&&e.tagName==="INPUT"?e.value=n===null?"":n:t==="checked"&&e.tagName==="INPUT"?e.checked=n!==null:t==="selected"&&e.tagName==="OPTION"&&(e.selected=n!==null))}function ht(e,t){e&&e.tagName==="TEXTAREA"&&(e.value=t)}function pt(e){if(!e||e.nodeType!==1)return;let t=[e,...e.querySelectorAll?e.querySelectorAll("textarea, input, option"):[]];for(let n of t)if(n.tagName==="TEXTAREA")n.value=n.defaultValue;else if(n.tagName==="INPUT"){let i=n.type;i!=="file"&&i!=="checkbox"&&i!=="radio"&&(n.value=n.defaultValue),n.checked=n.defaultChecked}else n.tagName==="OPTION"&&(n.selected=n.defaultSelected)}var S={semanticExclude:!0,find(e,t,n={}){let i=sn(e);if(!i||!i.querySelectorAll)return[];let r=Array.from(i.querySelectorAll(t));n.includeRulesTag||(r=r.filter(l=>!dt(l)));let o=[];n.skip&&o.push(n.skip);let c=n.templateAttr===null?null:n.templateAttr||"cms-template";if(c&&o.push("["+c+"]"),o.length){let l=o.join(", ");r=r.filter(s=>!s.closest||!s.closest(l))}return r},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,ht(e,t)},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n),at(e,t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),at(e,t,null)},prop(e,t,n){if(n===void 0){let i=e?e[t]:void 0;return i!==void 0?i:null}e[t]=n},clone(e){let t=e.cloneNode(!0);return pt(t),t},insertAt(e,t,n){let i=e.children[n]||null;e.insertBefore(t,i)},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 i=e.ownerDocument.createElement("template");i.innerHTML=t;let r=i.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(i=>{i.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function I(e,t={}){if(t.exclude===null)return S;let n=[Z("data"),t.exclude].filter(Boolean).join(", "),i=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!i?.querySelector?.(n))return S;let o=e.nodeType===9||!e.isConnected?e:e.ownerDocument,c=e.nodeType===9?e:e.ownerDocument,l=null,s=()=>l||(l=ee(o,{capability:"data",exclude:t.exclude||null})),f=a=>{let m=s();return a===e?m.cloneOf(e):m.cloneOf(a)||a},u=a=>l?.original(a)||a,d=(a,m)=>{s().liveToClone.set(a,m),s().cloneToLive.set(m,a);let g=a.childNodes||[],p=m.childNodes||[];for(let y=0;y<Math.min(g.length,p.length);y++)d(g[y],p[y])},h=(a,m,g,p)=>{let y=Array.from(a.childNodes).filter(T=>l.cloneOf(T)),E=y[0];for(;E&&y.includes(E);)E=E.nextSibling;for(let T of y)T.remove();if(g==="innerHTML"){let T=c.createElement("template");T.innerHTML=p;for(let V of Array.from(T.content.childNodes))a.insertBefore(V,E||null)}else a.insertBefore(c.createTextNode(p),E||null),ht(a,p);let x=ee(a,{capability:"data",exclude:t.exclude||null});m.replaceChildren(...Array.from(x.root?.childNodes||[]));let O=T=>{let V=x.original(T);V&&(l.liveToClone.set(V,T),l.cloneToLive.set(T,V));for(let wt of Array.from(T.childNodes||[]))O(wt)};for(let T of Array.from(m.childNodes))O(T)},A={...S,find(a,m,g={}){let p=f(a);if(!p?.querySelectorAll)return[];let y=s().query(m,p);g.includeRulesTag||(y=y.filter(x=>!dt(x)));let w=[];g.skip&&w.push(g.skip);let E=g.templateAttr===null?null:g.templateAttr||"cms-template";if(E&&w.push(`[${E}]`),w.length){let x=w.join(", ");y=y.filter(O=>!O.closest?.(x))}return y},parent(a){let m=f(a)?.parentElement;return m?u(m):null},children(a){return Array.from(f(a)?.children||[],u)},text(a,m){if(m===void 0){let y=u(a);return!y?.matches?.(n)&&!y?.querySelector?.(n)?S.text(y):(f(a)?.textContent||"").trim()}let g=u(a);if(!g?.matches?.(n)&&!g?.querySelector?.(n)&&!l){S.text(g,m);return}let p=s().cloneOf(g);p?h(g,p,"textContent",m):S.text(g,m)},attr(a,m,g){let p=u(a);if(g===void 0)return S.attr(p,m);S.attr(p,m,g);let y=l?.cloneOf(p);y&&(S.attr(y,m,g),ee(p,{capability:"data",exclude:t.exclude||null}).root===null&&(y.remove(),l.liveToClone.delete(p),l.cloneToLive.delete(y)))},removeAttr(a,m){let g=u(a);S.removeAttr(g,m);let p=l?.cloneOf(g);p&&S.removeAttr(p,m)},prop(a,m,g){let p=u(a);if(g===void 0)return m==="innerHTML"||m==="outerHTML"||m==="textContent"||m==="innerText"?S.prop(f(p),m):S.prop(p,m);let y=m==="innerHTML"||m==="textContent"||m==="innerText",w=y?s().cloneOf(p):l?.cloneOf(p);w&&y?h(p,w,m,g):(S.prop(p,m,g),w&&S.prop(w,m,g))},clone(a){let m=f(a);if(m===a)return S.clone(a);let g=c.importNode(m,!0);return pt(g),g},insertAt(a,m,g){let p=u(a),w=A.children(p)[g]||(()=>{for(let O=p.children.length-1;O>=0;O--){let T=p.children[O];if(s().cloneOf(T))return T.nextElementSibling}return p.firstElementChild})(),E=u(m);p.insertBefore(E,w||null);let x=s().cloneOf(p);if(x){let O=s().cloneOf(E);O||(O=c.importNode(E,!0),d(E,O));let T=Array.from(x.children);x.insertBefore(O,T[g]||null)}},insertBefore(a,m){let g=u(a),p=u(m);g.parentNode.insertBefore(p,g);let y=s().cloneOf(g.parentNode);if(y){let w=s().cloneOf(p);w||(w=c.importNode(p,!0),d(p,w));let E=s().cloneOf(g);E?E.before(w):y.appendChild(w)}},insertAfter(a,m){let g=u(a),p=u(m);g.parentNode.insertBefore(p,g.nextSibling);let y=s().cloneOf(g.parentNode);if(y){let w=s().cloneOf(p);w||(w=c.importNode(p,!0),d(p,w));let E=s().cloneOf(g);E?E.after(w):y.appendChild(w)}},identity(a){return u(a)||null},remove(a){let m=u(a),g=s().cloneOf(m);S.remove(m),g&&S.remove(g)},replaceWith(a,m){let g=u(a),p=s().cloneOf(g),y=S.replaceWith(g,m);if(p){let w=ee(y,{capability:"data",exclude:t.exclude||null});if(!w.root)p.remove();else{p.replaceWith(w.root);let E=x=>{let O=w.original(x);O&&(l.liveToClone.set(O,x),l.cloneToLive.set(x,O));for(let T of Array.from(x.childNodes||[]))E(T)};E(w.root)}}return y}};return A}var te=S;var ne=e=>({codecs:Oe(),...e}),de={extract:(e,t,n={})=>L(I(e,n),e,t,ne(n)),apply:(e,t,n,i={})=>D(I(e,{...i,_write:!0}),e,t,n,ne(i)),findRulesIn:(e,t)=>W(te,e,t),findRules:(e,t)=>Le(te,e,t),bind:(e,t,n={})=>{let i=Le(te,e,t);if(!i){let o=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${o}`)}let r=ne({version:i.version,...n});return{...i,get:()=>L(I(e,n),e,i.rules,r),set:o=>D(I(e,{...n,_write:!0}),e,i.rules,o,r)}},codecs:{register:Ee,get:Te},parseStrict:Ne,parseRelaxed:Y,ruleAttrIndex:N,splitRule:b,errors:R,DOM_PROPERTIES:re},Ie=e=>!!e&&typeof e.nodeType=="number";function mt(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=W(te,t,"api");if(!n)throw new R.NoRulesTag("api");return{rules:n.rules,version:n.version}}function cn(e){if(e.nodeType===9)return e;let t=e.ownerDocument?.documentElement;if(t?.contains(e))return t;let n=e;for(;n.parentNode;)n=n.parentNode;return n}function ln(e){if(e.nodeType!==11||!e.host)return e.cloneNode(!0);let t=e.ownerDocument.createDocumentFragment();for(let n of e.childNodes)t.appendChild(n.cloneNode(!0));return t}function fn(e,t){let n=[];for(;t!==e;){let i=t.parentNode;n.push(Array.prototype.indexOf.call(i.childNodes,t)),t=i}return n.reverse()}function un(e,t){return t.reduce((n,i)=>n.childNodes[i],e)}function q(e,t){let n=e.querySelectorAll?Array.from(e.querySelectorAll(t)):[];return e.matches?.(t)&&n.unshift(e),n}function an(e,t){let n=q(e,"option"),i=q(t,"option");n.forEach((s,f)=>i[f].selected=s.selected);let r=q(e,"input"),o=q(t,"input");r.forEach((s,f)=>{let u=s.type.toLowerCase();u!=="file"&&(o[f].value=s.value),(u==="checkbox"||u==="radio")&&(o[f].checked=s.checked)});let c=q(e,"textarea"),l=q(t,"textarea");c.forEach((s,f)=>l[f].value=s.value)}function _e(e,t){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]"))return;let n=e.startsWith("@")?0:N(e);if(n===-1)return;let i=e.slice(n+1);if(B.has(i))throw new R.RuleTargetReadOnly(i);return}if(Array.isArray(e)){if(!Array.isArray(t))return;t.forEach(n=>_e(e[1],n));return}if(e&&typeof e=="object"&&t&&typeof t=="object"&&!Array.isArray(t))for(let[n,i]of Object.entries(e))_e(i,t[n])}}function dn(e,t,n,i){let r=ne({templateAttr:"cms-template",version:i}),o=cn(e),c=fn(o,e),l=ln(o);an(o,l);let s=un(l,c),f=I(l,{...r,_write:!0}),u=ke(f,s,t,n,r);if(u.unknownKeys.length||u.unmatched.length)throw new R.WriteRejected(u.unknownKeys,u.unmatched);let d=ae(f);D(d,s,t,n,r),d.assertClean(),_e(t,n);let h=ae(I(o,{...r,_write:!0}));D(h,e,t,n,r),h.assertClean()}function hn(e){if(!(e instanceof Error))return e;let n=e instanceof R.UnknownCodec||e instanceof R.CodecRefused?e.code:e.name||"Error";try{e.code=n}catch{Object.defineProperty(e,"code",{value:n,configurable:!0,enumerable:!0})}return e instanceof R.WriteRefused?e.details=e.refusals:e instanceof R.WriteRejected?e.details={unknownKeys:e.unknownKeys,unmatched:e.unmatched}:e instanceof R.ShapeMismatch?e.details=e.mismatches:Array.isArray(e.path)?e.details={path:e.path}:typeof e.target=="string"?e.details={target:e.target}:e.token!==void 0?e.details={token:e.token}:e.version!==void 0?e.details={version:e.version}:e.details={},e}function yt(e,t){let n=Ie(e)?e:document,i=Ie(e)?t:e;if(i===void 0){let{rules:r,version:o}=mt(n);return L(I(n),n,r,ne({version:o}))}return de.bind(n,i).get()}function gt(e,t,n){try{if(!Ie(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");let{rules:i,version:r}=n===void 0?mt(e):de.bind(e,n);dn(e,i,t,r)}catch(i){throw hn(i)}return e}var pn={engine:de,extractData:yt,applyData:gt},$r=pn;export{gt as applyData,$r as default,de as engine,yt as extractData};
4
+ var At=Object.defineProperty;var Et=(e,t)=>{for(var n in t)At(e,n,{get:t[n],enumerable:!0})};var re=["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"],ie=new Set(re),he=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),B=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),$e=new Set(["checked","selected","disabled","readOnly","paused"]);function pe(e,t){return t==null?$e.has(e)?!1:"":$e.has(e)?t==="false"?!1:!!t:t}var R={};Et(R,{CodecRefused:()=>ge,EmptyListInsert:()=>P,MAX_RULE_DEPTH:()=>M,MaxRuleDepthExceeded:()=>_,NoRulesTag:()=>me,RuleTargetReadOnly:()=>z,RulesParseError:()=>C,ShapeMismatch:()=>U,UnknownCodec:()=>K,UnknownRulesVersion:()=>H,WriteNotRoundTripped:()=>oe,WriteRefused:()=>F,WriteRejected:()=>ye});var C=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},H=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1" and "2".`),this.name="UnknownRulesVersion",this.version=t}},M=20,_=class extends Error{constructor(t){super(`rule depth exceeded ${M} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},U=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},P=class extends Error{constructor(t,n){super(n?`cannot add items to empty list at "${t.join(".")}" \u2014 ${n}`:`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},z=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},F=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}};function Tt(e){return e.reduce((n,i)=>typeof i=="number"?`${n}[${i}]`:n?`${n}.${i}`:String(i),"")||"(root)"}var oe=class extends Error{constructor(t){super(`write did not round-trip at "${Tt(t)}"`),this.name="WriteNotRoundTripped",this.path=t}},me=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},ye=class extends Error{constructor(t,n){super(`write rejected: ${t.length} unknown key(s), ${n.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=t,this.unmatched=n}},K=class extends Error{constructor(t){super(`unknown codec "${t}": no codec by that name is given to this call`),this.name="UnknownCodec",this.code="unknown-codec",this.codec=t}},ge=class extends Error{constructor(t,n){super(n),this.name="CodecRefused",this.code=t}};function N(e){let t=0,n=null,i=-1;for(let r=0;r<e.length;r++){let o=e[r];o==="\\"?r++:n?o===n&&(n=null):o==='"'||o==="'"?n=o:o==="["||o==="("?t++:o==="]"||o===")"?t>0&&t--:o==="@"&&t===0&&(i=r)}return i}var je="[*]";function b(e){let t=N(e),n=t===-1?e:e.slice(0,t),i=n.endsWith(je),r={selector:i?n.slice(0,-je.length):n,prop:t===-1?null:e.slice(t+1)||null};return i&&(r.all=!0),r}function we(e){let t=0,n=null,i=-1,r=!1;for(let o=0;o<e.length;o++){let c=e[o];c==="\\"?o++:n?c===n&&(n=null):c==='"'||c==="'"?n=c:c==="["||c==="("?t++:c==="]"||c===")"?t>0&&t--:t===0&&c===">"?i=o:t===0&&c===","&&(r=!0)}return r||i===-1||!Ot(e,i+1)?null:e.slice(0,i).trim()||null}function Ot(e,t){let n=t,i=e.replace(/\s+$/,"").length;for(;n<i&&/\s/.test(e[n]);)n++;let r=0,o=null;for(;n<i;n++){let c=e[n];if(c==="\\")n++;else if(o)c===o&&(o=null);else if(c==='"'||c==="'")o=c;else if(c==="["||c==="(")r++;else if(c==="]"||c===")")r>0&&r--;else if(r===0&&(c==="+"||c==="~"||/\s/.test(c)))return!1}return!0}var St=/^codec\(([a-z][a-z0-9-]*)\)$/;function $(e){if(typeof e!="string")return null;let t=N(e);if(t===-1)return null;let n=St.exec(e.slice(t+1));if(!n)return null;let{selector:i,all:r}=b(e);if(r)throw new C("A @codec(name) rule cannot use [*].");return{selector:i,name:n[1]}}var xt=/^--[A-Za-z0-9_-]+$/;function k(e){return typeof e=="string"&&xt.test(e)}function De(e){let t=[],n=[],i=null,r=0;for(let o=0;o<e.length;o++){let c=e[o];if(i){c==="\\"?o++:c===i&&(i=null);continue}if(c==="/"&&e[o+1]==="*"){let l=e.indexOf("*/",o+2);o=l===-1?e.length:l+1;continue}c==='"'||c==="'"?i=c:c==="("?n.push(")"):c==="["?n.push("]"):c==="{"?n.push("}"):(c===")"||c==="]"||c==="}")&&n[n.length-1]===c?n.pop():c===";"&&n.length===0&&(t.push(e.slice(r,o)),r=o+1)}return t.push(e.slice(r)),t}function bt(e){let t="",n=null;for(let i=0;i<e.length;i++){let r=e[i];if(n){t+=r,r==="\\"&&i+1<e.length?t+=e[++i]:r===n&&(n=null);continue}if(r==="/"&&e[i+1]==="*"){let o=e.indexOf("*/",i+2);i=o===-1?e.length:o+1,t+=" ";continue}(r==='"'||r==="'")&&(n=r),t+=r}return t}function ve(e){e=bt(e);let t=e.indexOf(":");if(t===-1)return null;let n=e.slice(0,t).trim(),i=e.slice(t+1).trim(),r=/!\s*important\s*$/i.exec(i);return r&&(i=i.slice(0,r.index).trim()),{name:n,value:i,important:!!r}}function v(e,t){if(e==null)return null;let n=null;for(let i of De(String(e))){let r=ve(i);!r||r.name!==t||(!n||r.important||!n.important)&&(n=r)}return n?n.value:null}function We(e,t,n){let i=e==null?"":String(e),r=n==null||n==="",o=De(i),c=o.map(ve),l=c.some(d=>d&&d.name===t&&d.important),s=[],f=!1;o.forEach((d,h)=>{let A=c[h];if(!A||A.name!==t){s.push(d);return}if(r||f)return;let a=/^\s*/.exec(d)[0];s.push(`${a}${t}: ${n}${l?" !important":""}`),f=!0});let u=s.join(";");if(!r&&!f){let d=u.trimEnd();u=d===""?`${t}: ${n}`:`${d}${d.endsWith(";")?" ":"; "}${t}: ${n}`}return u.trim()===""?null:u}function se(e,t,n,i){let r=e.attr(t,"style");if((v(r,n)??"")===i)return;let o=We(r,n,i);o==null?e.removeAttr(t,"style"):e.attr(t,"style",o)}var qe=/^[a-z][a-z0-9-]*$/,Ae=new Map;function Ee(e,t){if(typeof e!="string"||!qe.test(e))throw new Error(`hyper-html-api: invalid codec name ${JSON.stringify(e)} (must match ${qe})`);if(!t||typeof t.read!="function"||typeof t.write!="function"||typeof t.same!="function")throw new Error(`hyper-html-api: codec "${e}" needs read, write and same functions`);Ae.set(e,t)}function Te(e){return Ae.get(e)??null}function Oe(){return Object.fromEntries(Ae)}var Rt='The @codec(name) rule form needs a rules tag with data-rules-version="2".',Ct="A @codec(name) rule must be the value of a top level key.";function ce(e,t){let n=$(e);return n?{...n,codec:t.codecs[n.name]}:null}function j(e,t={}){let n=t.version??"1",i=t.codecs??{};r(e,0);function r(o,c){if(!(c>M)){if(typeof o=="string"){let l=$(o);if(!l)return;if(n!=="2")throw new C(Rt);if(c!==1)throw new C(Ct);if(!Object.prototype.hasOwnProperty.call(i,l.name))throw new K(l.name);return}if(Array.isArray(o)){r(o[1],c+1);return}if(o&&typeof o=="object")for(let l of Object.values(o))r(l,c+1)}}}function L(e,t,n,i={}){if(Object.prototype.hasOwnProperty.call(i,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return j(n,i),xe(e,t,n,{depth:0,path:[]},i)}function xe(e,t,n,i,r){if(i.depth>M)throw new _(i.path);if(typeof n=="string")return Nt(e,t,n,i,r);if(Array.isArray(n)){let[o,c]=n,l=e.find(t,o,r);return Ve(r,i,l),l.map((s,f)=>xe(e,s,c,{depth:i.depth+1,path:[...i.path,f]},r))}if(typeof n=="object"&&n!==null){let o={};for(let[c,l]of Object.entries(n))o[c]=xe(e,t,l,{depth:i.depth+1,path:[...i.path,c]},r);return o}return null}function Nt(e,t,n,i,r){if(n.endsWith("[]")){let u=n.slice(0,-2),d=e.find(t,u,r);return Ve(r,i,d),d.map(h=>e.text(h))}let o=ce(n,r);if(o)return Pt(e,t,o,r);if(n.startsWith("@"))return Se(e,t,n.slice(1));let c=N(n);if(c!==-1){let{selector:u,all:d}=b(n),h=n.slice(c+1),A=u?e.find(t,u,r):[t];return d&&r.allMatches?A.map(a=>Se(e,a,h)):A.length===0?null:Se(e,A[0],h)}if(n===".")return e.text(t);let{selector:l,all:s}=b(n),f=e.find(t,l,r);return s&&r.allMatches?f.map(u=>e.text(u)):f.length===0?null:e.text(f[0])}function Pt(e,t,{selector:n,codec:i},r){let o=n?e.find(t,n,r):[t];return o.length===0?null:i.read(e,o[0],{query:r.query,view:r.view,region:r.region})}function Ve(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(i){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,i)}}function Se(e,t,n){if(k(n))return v(e.attr(t,"style"),n);if(ie.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let i=e.attr(t,n);return i??null}function Ue(e,t,n,i){let r=e.length,o=t.length,c=new Array(r).fill(-1);if(i){let p=new Set;for(let y=0;y<r;y++){let w=i[y];!(w>=0&&w<o)||p.has(w)||(c[y]=w,p.add(w))}}if(r===0||o===0)return c;let l=e.map(p=>Be(p,n)),s=t.map(p=>Be(p,n)),f=new Array(o).fill(!1);for(let p of c)p>=0&&(f[p]=!0);let u=new Map;s.forEach((p,y)=>{f[y]||u.set(p,u.has(p)?-1:y)});let d=new Map;l.forEach((p,y)=>{c[y]>=0||d.set(p,(d.get(p)||0)+1)}),l.forEach((p,y)=>{if(c[y]>=0||d.get(p)!==1)return;let w=u.get(p);w===void 0||w===-1||f[w]||(c[y]=w,f[w]=!0)});let h=[];for(let p=0;p<r;p++)c[p]<0&&h.push(p);let A=[];for(let p=0;p<o;p++)f[p]||A.push(p);if(h.length===0||A.length===0)return c;let a=r*o+1,m=Mt(e,t,n),g=(p,y)=>m(p,y)*a+Math.abs(p-y);for(let[p,y]of kt(h,A,g))c[p]=y;return c}var ze=e=>typeof e=="object"&&e!==null;function Be(e,t){if(!ze(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(i=>{let r=JSON.stringify(e?.[i]);return r===void 0?" undef":r}))}function Mt(e,t,n){if(!ze(n))return(l,s)=>e[l]===t[s]?0:1;let i=Object.keys(n),r=l=>i.map(s=>JSON.stringify(l?.[s])),o=e.map(r),c=t.map(r);return(l,s)=>{let f=o[l],u=c[s],d=0;for(let h=0;h<i.length;h++)f[h]!==u[h]&&d++;return d}}function kt(e,t,n){return e.length<=t.length?He(e,t,n,!1):He(t,e,(i,r)=>n(r,i),!0)}function He(e,t,n,i){let r=e.length,o=t.length,c=[];for(let d=0;d<=r;d++)c.push(new Float64Array(o+1).fill(1/0));let l=[];for(let d=0;d<=r;d++)l.push(new Uint8Array(o+1));for(let d=0;d<=o;d++)c[r][d]=0;for(let d=r-1;d>=0;d--)for(let h=o-1;h>=0;h--){let A=n(e[d],t[h])+c[d+1][h+1],a=c[d][h+1];A<=a?(c[d][h]=A,l[d][h]=1):c[d][h]=a}let s=[],f=0,u=0;for(;f<r&&u<o;)l[f][u]&&(s.push(i?[t[u],e[f]]:[e[f],t[u]]),f++),u++;return s}function Re(e,t,n,i,r,o,c,l={}){let s=e.find(t,n,l);if(r.length===0){s.forEach(E=>e.remove(E)),be(l,"onRowsApplied",o.path,[]);return}let f=r.length>s.length,u=s[0]||null;if(f&&!u&&(u=$t(e,t,n,l),!u))throw new P(o.path);let d=s.map(E=>_t(e,E,i,l)),h=null;if(f&&u){h=e.clone(u);let E=l.templateAttr&&e.attr(u,l.templateAttr)!=null;l.templateAttr&&e.removeAttr(h,l.templateAttr),E&&e.removeAttr(h,"hidden");let O=e.stripIds(h);O>0&&console.warn(`[hyper-html-api] stripped ${O} id attribute(s) from cloned template at "${o.path.join(".")||"(root)"}"`)}let A=Ue(r,d,i,Lt(e,s,r,o,l)),a=s.length>0?e.parent(s[0]):Wt(e,t,n,u,o,l),m=s.length>0?Ye(e,a,s[0]):0,g=Bt(e,s),p=new Set,y=[],w=r.map((E,O)=>{let S=A[O];if(S>=0)return p.add(S),y.push(!1),s[S];y.push(!0);let T=e.clone(h);return e.stripIds(T),T});s.forEach((E,O)=>{p.has(O)||e.remove(E)}),g?Vt(e,a,m,w,y):Ht(e,w,y,a,m),It(e,w,i,r,o,c,l),be(l,"onRowsApplied",o.path,w)}function be(e,t,n,i){if(typeof e[t]=="function")try{return e[t](n.slice(),i)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function Lt(e,t,n,i,r){let o=be(r,"identifyRows",i.path,n);if(!Array.isArray(o))return null;let c=new Array(n.length).fill(-1),l=new Set,s=new Map(t.map((f,u)=>[e.identity(f),u]));for(let f=0;f<n.length;f++){if(!o[f])continue;let u=s.get(e.identity(o[f]));u===void 0||l.has(u)||(c[f]=u,l.add(u))}return c}function It(e,t,n,i,r,o,c){t.forEach((l,s)=>{if(n===null){let f=i[s],u=f==null?"":String(f);e.text(l)!==u&&e.text(l,u)}else{let f=o(e,l,n,i[s],{depth:r.depth+1,path:[...r.path,s]},c);f&&f!==l&&(t[s]=f)}})}function _t(e,t,n,i){return n===null?e.text(t):L(e,t,n,i.onRowsRead?{...i,onRowsRead:void 0}:i)}function Ye(e,t,n){let i=e.children(t);for(let r=0;r<i.length;r++)if(e.sameNode(i[r],n))return r;return-1}function $t(e,t,n,i){if(!i.templateAttr)return null;let r=/^\s*:scope\s*>\s*/.test(n),o=new RegExp(":not\\(\\["+i.templateAttr.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")+"\\]\\)","g"),c=n.replace(/^\s*:scope\s*>\s*/,"").replace(o,""),l=r?jt(c):0,s=we(c),f=t;for(;f;){let u=e.find(f,c,{includeRulesTag:!1,templateAttr:null});for(let d of u)if(e.attr(d,i.templateAttr)!=null&&!(r&&!vt(e,t,d,l))&&!(s&&!e.matches(e.parent(d),s)))return d;f=e.parent(f)}return null}function jt(e){let t=0,n=null,i=1;for(let r=0;r<e.length;r++){let o=e[r];if(o==="\\")r++;else if(n)o===n&&(n=null);else if(o==='"'||o==="'")n=o;else if(o==="["||o==="(")t++;else if(o==="]"||o===")")t>0&&t--;else if(t===0&&o===">")i++;else{if(t===0&&(o==="+"||o==="~"))return null;if(t===0&&/\s/.test(o)){if(!Dt(e,r))return null;for(;r+1<e.length&&/\s/.test(e[r+1]);)r++}}}return i}function Dt(e,t){let n=t;for(;n<e.length&&/\s/.test(e[n]);)n++;let i=t>0?e[t-1]:"",r=n<e.length?e[n]:"";return Fe(i)||Fe(r)}function Fe(e){return e===">"||e==="+"||e==="~"}function vt(e,t,n,i){if(i===null)return!0;let r=n;for(let s=0;s<i;s++)if(r=e.parent(r),!r)return!1;let o=e.prop(t,"tagName");if(!o)return!0;let c=e.prop(r,"tagName");if(!c||String(c).toLowerCase()!==String(o).toLowerCase())return!1;let l=new Set(Ke(e,r));return Ke(e,t).every(s=>l.has(s))}function Ke(e,t){let n=e.attr(t,"class");return n?String(n).split(/\s+/).filter(Boolean):[]}function Wt(e,t,n,i,r,o){let c=e.parent(i);if(c&&qt(e,t,c)&&!Xe(e,c,o))return c;let l=we(n);if(!l)throw new P(r.path,`the list selector "${n}" 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 f=(l===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,l,o)).filter(u=>!Xe(e,u,o));if(f.length===0)throw new P(r.path,`no container matching "${l}" inside this context to hold the new rows`);if(f.length>1)throw new P(r.path,`"${l}" matches ${f.length} containers inside this context, so the new rows have no single destination`);return f[0]}function qt(e,t,n){let i=n;for(;i;){if(e.sameNode(i,t))return!0;i=e.parent(i)}return e.parent(t)?!1:e.find(t,"*",{includeRulesTag:!0,templateAttr:null}).some(r=>e.sameNode(r,n))}var Je=["no-data","editor-ui"];function Xe(e,t,n){let i=t;for(;i;){if(n.templateAttr&&e.attr(i,n.templateAttr)!=null||Je.some(o=>e.attr(i,o)!=null))return!0;let r=e.attr(i,"clay");if(r&&r.split(/\s+/).some(o=>Je.includes(o)))return!0;i=e.parent(i)}return!1}function Vt(e,t,n,i,r){let o=e.children(t),c=o.map(s=>e.identity(s)),l=!1;i.forEach((s,f)=>{let u=e.identity(s),d=n+f;if(c[d]===u)return;if(!r[f]){let A=c.indexOf(u);A!==-1&&(c.splice(A,1),o.splice(A,1))}let h=Math.min(d,o.length);h<o.length?e.insertBefore(o[h],s):o.length?l?e.insertAfter(o[o.length-1],s):(e.insertAt(t,s,d),l=!0):e.insertAt(t,s,0),c.splice(h,0,u),o.splice(h,0,s)})}function Bt(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let i=new Map(e.children(n).map((o,c)=>[e.identity(o),c])),r=[];for(let o of t){let c=i.get(e.identity(o));if(c===void 0)return!1;r.push(c)}return r.sort((o,c)=>o-c),r[r.length-1]-r[0]===r.length-1}function Ht(e,t,n,i,r){let o=null,c=r;for(let l=0;l<t.length;l++){if(!n[l]){o=t[l];continue}let s=o?e.parent(o):i;if(!s)continue;let f=o?Ye(e,s,o)+1:c++;e.insertAt(s,t[l],f),o=t[l]}}function D(e,t,n,i,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");j(n,r);let o=[];if(Ce(n,i,[],o),o.length)throw new U(o);le(e,t,n,i,{depth:0,path:[]},r)}function le(e,t,n,i,r,o={}){if(r.depth>M)throw new _(r.path);if(i===void 0)return t;if(typeof n=="string")return Ut(e,t,n,i,r,o);if(Array.isArray(n)){let[c,l]=n;return Re(e,t,c,l,i,r,le,o),t}if(typeof n=="object"&&n!==null){for(let[c,l]of Object.entries(n)){let s=le(e,t,l,i==null?i:i[c],{depth:r.depth+1,path:[...r.path,c]},o);s&&s!==t&&(t=s)}return t}return t}function Ut(e,t,n,i,r,o){if(n.endsWith("[]")){let d=n.slice(0,-2);return Re(e,t,d,null,i,r,le,o),t}let c=ce(n,o);if(c){let d=c.selector?e.find(t,c.selector,o):[t];return d.length&&c.codec.write(e,d[0],i,{query:o.query}),t}if(n.startsWith("@"))return Ze(e,t,n.slice(1),i);let l=N(n);if(l!==-1){let{selector:d,all:h}=b(n),A=n.slice(l+1),a=d?e.find(t,d,o):[t];for(let m of h?a:a.slice(0,1))Ze(e,m,A,i);return t}if(n===".")return Ge(e,t,i),t;let{selector:s,all:f}=b(n),u=e.find(t,s,o);for(let d of f?u:u.slice(0,1))Ge(e,d,i);return t}function Ge(e,t,n){let i=n==null?"":String(n);e.text(t)!==i&&e.text(t,i)}function zt(e,t,n,i){if(e.styleVar){e.styleVar(t,n,i);return}se(e,t,n,i)}function Ze(e,t,n,i){if(k(n))return zt(e,t,n,i==null?"":String(i).trim()),t;if(B.has(n)){let r=e.prop(t,n);if(r===i||r!=null&&i!=null&&String(r)===String(i))return t;throw new z(n)}if(n==="outerHTML"){let r=i==null?"":String(i);return e.replaceWith(t,r)}if(he.has(n)){let r=pe(n,i);return e.prop(t,n)!==r&&e.prop(t,n,r),t}if(i==null)e.attr(t,n)!=null&&e.removeAttr(t,n);else{let r=String(i);e.attr(t,n)!==r&&e.attr(t,n,r)}return t}function Ce(e,t,n,i){if(t!==void 0){if(typeof e=="string"){if($(e))return;if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,o)=>{typeof r=="object"&&r!==null&&i.push({path:X([...n,o]),expected:"scalar",got:J(r)})}):i.push({path:X(n),expected:"array",got:J(t)});return}t!==null&&typeof t=="object"&&i.push({path:X(n),expected:"scalar",got:J(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){i.push({path:X(n),expected:"array",got:J(t)});return}let r=e[1];t.forEach((o,c)=>Ce(r,o,[...n,c],i));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){i.push({path:X(n),expected:"object",got:J(t)});return}for(let[r,o]of Object.entries(e))Ce(o,t[r],[...n,r],i)}}}function J(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function X(e){return e.join(".")}function Ne(e){try{return JSON.parse(e)}catch(t){throw new C(`Invalid strict JSON: ${t.message}`,t)}}function Y(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 n(r){let o=[],c=0;for(;c<r.length;){let l=r[c];if(/\s/.test(l)){c++;continue}if("{}".includes(l)){o.push({type:l,value:l}),c++;continue}if(l==="["){let d=!1,h=c+1;for(;h<r.length&&/\s/.test(r[h]);)h++;if(h<r.length&&/[a-zA-Z_]/.test(r[h])&&(d=!0),!d){o.push({type:l,value:l}),c++;continue}}if(l==="]"){o.push({type:l,value:l}),c++;continue}if(l===":"){o.push({type:t.COLON,value:l}),c++;continue}if(l===","){o.push({type:t.COMMA,value:l}),c++;continue}if(l==='"'||l==="'"){let d=l,h=c+1;for(;h<r.length&&r[h]!==d;)r[h]==="\\"&&h++,h++;o.push({type:t.STRING,value:r.substring(c+1,h),quoted:!0,sourceQuote:d}),c=h+1;continue}let s=c,f;for(;s<r.length&&!/[{},]/.test(r[s]);)if(r[s]===":"){let d=[":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"],h=!1;for(let A of d){let a=A.substring(1);if(r.substring(s+1,s+1+a.length)===a){h=!0,s+=a.length;break}}if(!h)break}else if(r[s]==="["){for(s++;s<r.length&&r[s]!=="]";){if(r[s]==='"'||r[s]==="'"){let d=r[s];for(s++;s<r.length&&r[s]!==d;)r[s]==="\\"&&s++,s++}s++}s<r.length&&r[s]==="]"&&s++}else s++;f=r.substring(c,s);let u=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(f)?u=t.NUMBER:f==="true"||f==="false"||f==="null"?u=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(f)&&(u=t.SELECTOR),o.push({type:u,value:f,quoted:!1}),c=s}return o}function i(r){let o="";for(let c=0;c<r.length;c++){let l=r[c];if("{}".includes(l.type)||"[]".includes(l.type)){o+=l.value;continue}if(l.type===t.COLON){o+=l.value;continue}if(l.type===t.COMMA){let s=r[c+1];if(s&&(s.type==="}"||s.type==="]"))continue;o+=l.value;continue}if(l.type===t.STRING&&l.quoted){let s=l.value;l.sourceQuote==="'"&&(s=s.replace(/\\'/g,"'"),s=s.replace(/(\\*)"/g,(f,u)=>u.length%2===0?u+'\\"':f)),o+=`"${s}"`;continue}if(l.type===t.NUMBER||l.type===t.BOOLEAN){o+=l.value;continue}if(l.type===t.SELECTOR||l.type===t.IDENTIFIER){o+=`"${l.value}"`;continue}o+=`"${l.value}"`}return o}try{let r=n(e),o=i(r);return JSON.parse(o)}catch(r){throw new C("Invalid extraction rules syntax: "+r.message,r)}}var et=["1","2"],Qe=/^[a-zA-Z0-9_-]+$/;function W(e,t,n){let i;if(n===void 0)i="script[data-rules-name]";else{if(typeof n!="string"||!Qe.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${Qe})`);i=`script[data-rules-name~="${n}"]`}let r=e.find(t,i,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let o=r[0],c=e.attr(o,"data-rules-version");if(!et.includes(c))throw new H(c);return{rules:Y(e.text(o)),tagNode:o,version:c}}var fe=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"]})}),Ft=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),tt=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);function G(e,t){if(!e||e.nodeType!==1)return!1;let n=e.getAttribute?.("clay");return!!(n&&n.split(/\s+/).includes(t)||e.hasAttribute?.(t))}function Pe(e,t){if(G(e,t))return!0;for(let[n,i]of Object.entries(Ft))if(i.includes(t)&&G(e,n))return!0;return!1}function Z(e){let t=fe[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function Kt(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let i=fe[t];if(!i)throw new Error(`Unknown region capability: ${t}`);if(i.tokens.some(r=>Pe(n,r))||i.bundles.some(r=>G(n,r)))return n;n=n.parentElement}return null}function nt(e,t){return!!Kt(e,t)}var ue=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",...tt],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"]})}),Jt=new Set(["textContent","innerText"]);function rt(e){let n=String(e).replace(/^[\u0000- ]+|[\u0000- ]+$/g,"").replace(/[\t\n\r]/g,"").match(/^([a-zA-Z][a-zA-Z0-9+.-]*):/);return n?n[1].toLowerCase():null}var Xt=/^[^\t\n\f\r "'>/=\u0000-\u001f\u007f]+$/;function it(e,t,n=ue){if(!Xt.test(String(e)))return`attribute name ${JSON.stringify(String(e))} is not valid`;let i=String(e).toLowerCase();if(n.refusedAttributePrefixes.some(r=>i.startsWith(r)))return`attribute "${i}" can run script`;if(n.refusedAttributes.includes(i))return`attribute "${i}" is not content`;if(n.urlAttributes.includes(i)&&t!=null){let r=i==="srcset"?String(t).split(",").map(o=>o.trim().split(/\s+/)[0]).filter(Boolean):[String(t)];for(let o of r){let c=rt(o);if(c&&n.refusedSchemes.includes(c))return`"${c}:" URLs are not allowed in "${i}"`}}return null}function Me(e,t){let n=e.prop(t,"tagName");return n?String(n).toLowerCase():""}function Yt(e,t){let n=Me(e,t)||"node",i=e.attr(t,"id");return i?`<${n}#${i}>`:`<${n}>`}function Gt(e,t,n){let i=t;for(;i;){let r=Me(e,i);if(r&&n.refusedTargets.includes(r))return r;i=e.parent(i)}return null}function ot(e,t){return e.find(t,"script[data-rules-name]",{includeRulesTag:!0,templateAttr:null}).length>0}function Zt(e,t){return Me(e,t)==="script"&&e.attr(t,"data-rules-name")!=null?!0:ot(e,t)}function Qt(e){if(/[\u0000-\u001f\u007f]/.test(e))return"control characters are not allowed in a custom property value";let t=[],n=null;for(let i=0;i<e.length;i++){let r=e[i];if(n){r===n&&(n=null);continue}if(r==='"'||r==="'")n=r;else{if(r==="/"&&e[i+1]==="*")return"comments are not allowed in a custom property value";if(r==="(")t.push(")");else if(r==="[")t.push("]");else if((r===")"||r==="]")&&t.pop()!==r)return`"${r}" does not close anything in this custom property value`}}return n?"a custom property value must close its quotes":t.length?"a custom property value must close its brackets":null}function st(e,t=ue){let n=t.customPropertyValues,i=String(e);if(i.length>n.maxLength)return`custom property values are limited to ${n.maxLength} characters`;let r=n.refusedCharacters.find(s=>i.includes(s));if(r)return`${JSON.stringify(r)} is not allowed in a custom property value`;let o=Qt(i);if(o)return o;let c=i.toLowerCase(),l=n.refusedFunctions.find(s=>new RegExp(`(^|[^a-z0-9_-])${s.replace(/[-]/g,"\\-")}\\s*\\(`).test(c));return l?`"${l}()" is not allowed in a custom property value`:null}function ae(e,t=ue){let n=[],i=(s,f)=>(n.push({target:Yt(e,s),reason:f}),!1),r=s=>{let f=Gt(e,s,t);return f?i(s,`inside <${f}>, which is not content`):!0},o=s=>r(s)?ot(e,s)?i(s,"a text write here would delete the data rules tag"):!0:!1,c=(s,f,u)=>{if(!r(s))return!1;let d=it(f,u,t);return d?i(s,d):!0};return{...e,text(s,f){if(f===void 0)return e.text(s);o(s)&&e.text(s,f)},attr(s,f,u){if(u===void 0)return e.attr(s,f);c(s,f,u)&&e.attr(s,f,u)},removeAttr(s,f){c(s,f,null)&&e.removeAttr(s,f)},styleVar(s,f,u){if((v(e.attr(s,"style"),f)??"")!==u&&r(s)){if(!k(f))return i(s,`"${f}" is not a custom property`);if(u!==""){let d=st(u,t);if(d)return i(s,d)}se(e,s,f,u)}},prop(s,f,u){if(u===void 0)return e.prop(s,f);if(t.refusedRuleForms.includes(f))return i(s,`"@${f}" writes HTML, only text is allowed`);if(Jt.has(f)){o(s)&&e.prop(s,f,u);return}c(s,f==="className"?"class":f,u)&&e.prop(s,f,u)},remove(s){if(Zt(e,s)){i(s,"removing this would delete the data rules tag");return}e.remove(s)},replaceWith(s,f){return f===e.prop(s,"outerHTML")||i(s,'"@outerHTML" writes HTML, only text is allowed'),s},refusals:n,assertClean(){if(n.length)throw new F(n.slice())}}}function Q(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function ct(e){return e.reduce((t,n)=>typeof n=="number"?`${t}[${n}]`:t?`${t}.${n}`:n,"")}function ke(e,t,n,i,r={}){j(n,r);let o=[],c=[];function l(f,u,d){if(Array.isArray(f)){let[,h]=f;if(!Array.isArray(u)||!Q(h))return;u.forEach((A,a)=>l(h,A,[...d,a]));return}if(!(!Q(f)||!Q(u)))for(let h of Object.keys(u))Object.prototype.hasOwnProperty.call(f,h)?l(f[h],u[h],[...d,h]):o.push(ct([...d,h]))}function s(f,u,d,h){if(d!==void 0){if(typeof u=="string"){if(u.endsWith("[]")||u==="."||u.startsWith("@"))return;let{selector:A}=b(u);if(!A)return;e.find(f,A,r).length===0&&c.push({path:ct(h),selector:A});return}if(!Array.isArray(u)&&Q(u)&&Q(d))for(let[A,a]of Object.entries(u))s(f,a,d[A],[...h,A])}}return l(n,i,[]),s(t,n,i,[]),{unknownKeys:o,unmatched:c}}function Le(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null,version:"1"};if(typeof n=="string"){let i=t&&t.ownerDocument?t.ownerDocument:t;return W(e,i,n)}return null}var tn=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function nn(e,t){if(!/^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(e.tagName||""))return;let n=(e.getAttribute?.("type")||"").toLowerCase();"value"in e&&"value"in t&&e.tagName!=="OPTION"&&n!=="checkbox"&&n!=="radio"&&n!=="file"&&(t.value=e.value),e.tagName==="INPUT"&&(n==="checkbox"||n==="radio")&&(t.checked=e.checked),e.tagName==="OPTION"&&(t.selected=e.selected),"indeterminate"in e&&"indeterminate"in t&&(t.indeterminate=e.indeterminate)}function lt(e,t,n,i){if(i)return!!e.closest?.(t);let r=e;for(;r?.nodeType===1;){if(r.matches(t))return!0;if(r===n)break;r=r.parentElement}return!1}function ft(e,t,n,i,r,o){return(o?nt(e,t):lt(e,n,r,!1))||!!(i&&(o&&e!==r?e.matches(i):lt(e,i,r,o)))}function rn(e,t){let n=fe[t];return n.tokens.some(i=>Pe(e,i))||n.bundles.some(i=>G(e,i))}var on=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function ut(e,t,n,i){if(e.nodeType===1&&i(e)){n.dropped.push(t);return}n.cloneToLive.set(t,e),n.liveToClone.set(e,t);let r=e,o=t;if(e.nodeType===1){if(on.has(e.tagName)&&n.controls.push(e,t),e.tagName==="TEMPLATE"){for(;t.firstChild;)t.removeChild(t.firstChild);r=e.content,o=t.content,n.cloneToLive.set(o,r),n.liveToClone.set(r,o)}}else if(e.nodeType!==11)return;let c=o.firstChild;for(let l=r.firstChild;l&&c;l=l.nextSibling)ut(l,c,n,i),c=c.nextSibling}function ee(e,{capability:t="data",exclude:n=null,inherit:i=!0,provenance:r=null}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let o=e.nodeType===9?e:e.ownerDocument;if(!o?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let c=o.implementation.createHTMLDocument(""),l=r||new WeakMap,s=new WeakMap,f=e.nodeType===9?e.documentElement:e;n&&c.documentElement.matches(n);let u=Z(t),d=i?a=>rn(a,t)||!!(n&&a.matches(n)):a=>ft(a,t,u,n,f,!1),h=null;if(f.nodeType!==1||!ft(f,t,u,n,f,i)){h=c.importNode(f,!0);let a={cloneToLive:l,liveToClone:s,dropped:[],controls:[]};ut(f,h,a,d);for(let m of a.dropped)m.remove();for(let m=0;m<a.controls.length;m+=2)nn(a.controls[m],a.controls[m+1])}e.nodeType===9&&h&&(c.replaceChild(h,c.documentElement),s.set(e,c),l.set(c,e));let A=a=>{if(tn.test(a))throw new Error(`Filtered content queries do not support stateful selector: ${a}`)};return{root:h,document:c,capability:t,selector:Z(t),cloneToLive:l,liveToClone:s,original(a){return l.get(a)||null},cloneOf(a){return s.get(a)||null},query(a,m=h){return A(a),Array.from(m.querySelectorAll(a),g=>l.get(g)||g)},text(a=h){return(a===h?h:s.get(a))?.textContent||""},html(a=h){return(a===h?h:s.get(a))?.innerHTML??""},clone(a=h){let m=a===h?h:s.get(a);return m?c.importNode(m,!0):null}}}function dt(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function sn(e){return e?(e.nodeType===9||e.nodeType===11,e):null}function at(e,t,n){!e||e.nodeType!==1||(t==="value"&&e.tagName==="INPUT"?e.value=n===null?"":n:t==="checked"&&e.tagName==="INPUT"?e.checked=n!==null:t==="selected"&&e.tagName==="OPTION"&&(e.selected=n!==null))}function ht(e,t){e&&e.tagName==="TEXTAREA"&&(e.value=t)}function pt(e){if(!e||e.nodeType!==1)return;let t=[e,...e.querySelectorAll?e.querySelectorAll("textarea, input, option"):[]];for(let n of t)if(n.tagName==="TEXTAREA")n.value=n.defaultValue;else if(n.tagName==="INPUT"){let i=n.type;i!=="file"&&i!=="checkbox"&&i!=="radio"&&(n.value=n.defaultValue),n.checked=n.defaultChecked}else n.tagName==="OPTION"&&(n.selected=n.defaultSelected)}var x={semanticExclude:!0,find(e,t,n={}){let i=sn(e);if(!i||!i.querySelectorAll)return[];let r=Array.from(i.querySelectorAll(t));n.includeRulesTag||(r=r.filter(l=>!dt(l)));let o=[];n.skip&&o.push(n.skip);let c=n.templateAttr===null?null:n.templateAttr||"cms-template";if(c&&o.push("["+c+"]"),o.length){let l=o.join(", ");r=r.filter(s=>!s.closest||!s.closest(l))}return r},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,ht(e,t)},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n),at(e,t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),at(e,t,null)},prop(e,t,n){if(n===void 0){let i=e?e[t]:void 0;return i!==void 0?i:null}e[t]=n},clone(e){let t=e.cloneNode(!0);return pt(t),t},insertAt(e,t,n){let i=e.children[n]||null;e.insertBefore(t,i)},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 i=e.ownerDocument.createElement("template");i.innerHTML=t;let r=i.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(i=>{i.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function I(e,t={}){if(t.exclude===null)return x;let n=[Z("data"),t.exclude].filter(Boolean).join(", "),i=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!i?.querySelector?.(n))return x;let o=e.nodeType===9||!e.isConnected?e:e.ownerDocument,c=e.nodeType===9?e:e.ownerDocument,l=null,s=()=>l||(l=ee(o,{capability:"data",exclude:t.exclude||null})),f=a=>{let m=s();return a===e?m.cloneOf(e):m.cloneOf(a)||a},u=a=>l?.original(a)||a,d=(a,m)=>{s().liveToClone.set(a,m),s().cloneToLive.set(m,a);let g=a.childNodes||[],p=m.childNodes||[];for(let y=0;y<Math.min(g.length,p.length);y++)d(g[y],p[y])},h=(a,m,g,p)=>{let y=Array.from(a.childNodes).filter(T=>l.cloneOf(T)),E=y[0];for(;E&&y.includes(E);)E=E.nextSibling;for(let T of y)T.remove();if(g==="innerHTML"){let T=c.createElement("template");T.innerHTML=p;for(let V of Array.from(T.content.childNodes))a.insertBefore(V,E||null)}else a.insertBefore(c.createTextNode(p),E||null),ht(a,p);let O=ee(a,{capability:"data",exclude:t.exclude||null});m.replaceChildren(...Array.from(O.root?.childNodes||[]));let S=T=>{let V=O.original(T);V&&(l.liveToClone.set(V,T),l.cloneToLive.set(T,V));for(let wt of Array.from(T.childNodes||[]))S(wt)};for(let T of Array.from(m.childNodes))S(T)},A={...x,find(a,m,g={}){let p=f(a);if(!p?.querySelectorAll)return[];let y=s().query(m,p);g.includeRulesTag||(y=y.filter(O=>!dt(O)));let w=[];g.skip&&w.push(g.skip);let E=g.templateAttr===null?null:g.templateAttr||"cms-template";if(E&&w.push(`[${E}]`),w.length){let O=w.join(", ");y=y.filter(S=>!S.closest?.(O))}return y},parent(a){let m=f(a)?.parentElement;return m?u(m):null},children(a){return Array.from(f(a)?.children||[],u)},text(a,m){if(m===void 0){let y=u(a);return!y?.matches?.(n)&&!y?.querySelector?.(n)?x.text(y):(f(a)?.textContent||"").trim()}let g=u(a);if(!g?.matches?.(n)&&!g?.querySelector?.(n)&&!l){x.text(g,m);return}let p=s().cloneOf(g);p?h(g,p,"textContent",m):x.text(g,m)},attr(a,m,g){let p=u(a);if(g===void 0)return x.attr(p,m);x.attr(p,m,g);let y=l?.cloneOf(p);y&&(x.attr(y,m,g),ee(p,{capability:"data",exclude:t.exclude||null}).root===null&&(y.remove(),l.liveToClone.delete(p),l.cloneToLive.delete(y)))},removeAttr(a,m){let g=u(a);x.removeAttr(g,m);let p=l?.cloneOf(g);p&&x.removeAttr(p,m)},prop(a,m,g){let p=u(a);if(g===void 0)return m==="innerHTML"||m==="outerHTML"||m==="textContent"||m==="innerText"?x.prop(f(p),m):x.prop(p,m);let y=m==="innerHTML"||m==="textContent"||m==="innerText",w=y?s().cloneOf(p):l?.cloneOf(p);w&&y?h(p,w,m,g):(x.prop(p,m,g),w&&x.prop(w,m,g))},clone(a){let m=f(a);if(m===a)return x.clone(a);let g=c.importNode(m,!0);return pt(g),g},insertAt(a,m,g){let p=u(a),w=A.children(p)[g]||(()=>{for(let S=p.children.length-1;S>=0;S--){let T=p.children[S];if(s().cloneOf(T))return T.nextElementSibling}return p.firstElementChild})(),E=u(m);p.insertBefore(E,w||null);let O=s().cloneOf(p);if(O){let S=s().cloneOf(E);S||(S=c.importNode(E,!0),d(E,S));let T=Array.from(O.children);O.insertBefore(S,T[g]||null)}},insertBefore(a,m){let g=u(a),p=u(m);g.parentNode.insertBefore(p,g);let y=s().cloneOf(g.parentNode);if(y){let w=s().cloneOf(p);w||(w=c.importNode(p,!0),d(p,w));let E=s().cloneOf(g);E?E.before(w):y.appendChild(w)}},insertAfter(a,m){let g=u(a),p=u(m);g.parentNode.insertBefore(p,g.nextSibling);let y=s().cloneOf(g.parentNode);if(y){let w=s().cloneOf(p);w||(w=c.importNode(p,!0),d(p,w));let E=s().cloneOf(g);E?E.after(w):y.appendChild(w)}},identity(a){return u(a)||null},remove(a){let m=u(a),g=s().cloneOf(m);x.remove(m),g&&x.remove(g)},replaceWith(a,m){let g=u(a),p=s().cloneOf(g),y=x.replaceWith(g,m);if(p){let w=ee(y,{capability:"data",exclude:t.exclude||null});if(!w.root)p.remove();else{p.replaceWith(w.root);let E=O=>{let S=w.original(O);S&&(l.liveToClone.set(S,O),l.cloneToLive.set(O,S));for(let T of Array.from(O.childNodes||[]))E(T)};E(w.root)}}return y}};return A}var te=x;var ne=e=>({codecs:Oe(),...e}),de={extract:(e,t,n={})=>L(I(e,n),e,t,ne(n)),apply:(e,t,n,i={})=>D(I(e,{...i,_write:!0}),e,t,n,ne(i)),findRulesIn:(e,t)=>W(te,e,t),findRules:(e,t)=>Le(te,e,t),bind:(e,t,n={})=>{let i=Le(te,e,t);if(!i){let o=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${o}`)}let r=ne({version:i.version,...n});return{...i,get:()=>L(I(e,n),e,i.rules,r),set:o=>D(I(e,{...n,_write:!0}),e,i.rules,o,r)}},codecs:{register:Ee,get:Te},parseStrict:Ne,parseRelaxed:Y,ruleAttrIndex:N,splitRule:b,errors:R,DOM_PROPERTIES:re},Ie=e=>!!e&&typeof e.nodeType=="number";function mt(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=W(te,t,"api");if(!n)throw new R.NoRulesTag("api");return{rules:n.rules,version:n.version}}function cn(e){if(e.nodeType===9)return e;let t=e.ownerDocument?.documentElement;if(t?.contains(e))return t;let n=e;for(;n.parentNode;)n=n.parentNode;return n}function ln(e){if(e.nodeType!==11||!e.host)return e.cloneNode(!0);let t=e.ownerDocument.createDocumentFragment();for(let n of e.childNodes)t.appendChild(n.cloneNode(!0));return t}function fn(e,t){let n=[];for(;t!==e;){let i=t.parentNode;n.push(Array.prototype.indexOf.call(i.childNodes,t)),t=i}return n.reverse()}function un(e,t){return t.reduce((n,i)=>n.childNodes[i],e)}function q(e,t){let n=e.querySelectorAll?Array.from(e.querySelectorAll(t)):[];return e.matches?.(t)&&n.unshift(e),n}function an(e,t){let n=q(e,"option"),i=q(t,"option");n.forEach((s,f)=>i[f].selected=s.selected);let r=q(e,"input"),o=q(t,"input");r.forEach((s,f)=>{let u=s.type.toLowerCase();u!=="file"&&(o[f].value=s.value),(u==="checkbox"||u==="radio")&&(o[f].checked=s.checked)});let c=q(e,"textarea"),l=q(t,"textarea");c.forEach((s,f)=>l[f].value=s.value)}function _e(e,t){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]"))return;let n=e.startsWith("@")?0:N(e);if(n===-1)return;let i=e.slice(n+1);if(B.has(i))throw new R.RuleTargetReadOnly(i);return}if(Array.isArray(e)){if(!Array.isArray(t))return;t.forEach(n=>_e(e[1],n));return}if(e&&typeof e=="object"&&t&&typeof t=="object"&&!Array.isArray(t))for(let[n,i]of Object.entries(e))_e(i,t[n])}}function dn(e,t,n,i){let r=ne({templateAttr:"cms-template",version:i}),o=cn(e),c=fn(o,e),l=ln(o);an(o,l);let s=un(l,c),f=I(l,{...r,_write:!0}),u=ke(f,s,t,n,r);if(u.unknownKeys.length||u.unmatched.length)throw new R.WriteRejected(u.unknownKeys,u.unmatched);let d=ae(f);D(d,s,t,n,r),d.assertClean(),_e(t,n);let h=ae(I(o,{...r,_write:!0}));D(h,e,t,n,r),h.assertClean()}function hn(e){if(!(e instanceof Error))return e;let n=e instanceof R.UnknownCodec||e instanceof R.CodecRefused?e.code:e.name||"Error";try{e.code=n}catch{Object.defineProperty(e,"code",{value:n,configurable:!0,enumerable:!0})}return e instanceof R.WriteRefused?e.details=e.refusals:e instanceof R.WriteRejected?e.details={unknownKeys:e.unknownKeys,unmatched:e.unmatched}:e instanceof R.ShapeMismatch?e.details=e.mismatches:Array.isArray(e.path)?e.details={path:e.path}:typeof e.target=="string"?e.details={target:e.target}:e.token!==void 0?e.details={token:e.token}:e.version!==void 0?e.details={version:e.version}:e.details={},e}function yt(e,t){let n=Ie(e)?e:document,i=Ie(e)?t:e;if(i===void 0){let{rules:r,version:o}=mt(n);return L(I(n),n,r,ne({version:o}))}return de.bind(n,i).get()}function gt(e,t,n){try{if(!Ie(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");let{rules:i,version:r}=n===void 0?mt(e):de.bind(e,n);dn(e,i,t,r)}catch(i){throw hn(i)}return e}var pn={engine:de,extractData:yt,applyData:gt},$r=pn;export{gt as applyData,$r as default,de as engine,yt as extractData};
@@ -1,5 +1,5 @@
1
1
  // GENERATED — do not edit. Vendored from
2
2
  // hyper-html-api/src/upgrade.js via hyper-html-api
3
3
  // `npm run copy-to-clayjs`. Edit the hyper-html-api source and re-run.
4
- var bt=Object.defineProperty;var Rt=(e,t)=>{for(var n in t)bt(e,n,{get:t[n],enumerable:!0})};var ne=["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"],re=new Set(ne),ge=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),W=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),He=new Set(["checked","selected","disabled","readOnly","paused"]);function we(e,t){return t==null?He.has(e)?!1:"":He.has(e)?t==="false"?!1:!!t:t}var se={};Rt(se,{CodecRefused:()=>xe,EmptyListInsert:()=>I,MAX_RULE_DEPTH:()=>L,MaxRuleDepthExceeded:()=>$,NoRulesTag:()=>Ae,RuleTargetReadOnly:()=>z,RulesParseError:()=>C,ShapeMismatch:()=>B,UnknownCodec:()=>F,UnknownRulesVersion:()=>j,WriteNotRoundTripped:()=>ie,WriteRefused:()=>oe,WriteRejected:()=>Te});var C=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},j=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1" and "2".`),this.name="UnknownRulesVersion",this.version=t}},L=20,$=class extends Error{constructor(t){super(`rule depth exceeded ${L} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},B=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},I=class extends Error{constructor(t,n){super(n?`cannot add items to empty list at "${t.join(".")}" \u2014 ${n}`:`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},z=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},oe=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}};function Ct(e){return e.reduce((n,o)=>typeof o=="number"?`${n}[${o}]`:n?`${n}.${o}`:String(o),"")||"(root)"}var ie=class extends Error{constructor(t){super(`write did not round-trip at "${Ct(t)}"`),this.name="WriteNotRoundTripped",this.path=t}},Ae=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},Te=class extends Error{constructor(t,n){super(`write rejected: ${t.length} unknown key(s), ${n.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=t,this.unmatched=n}},F=class extends Error{constructor(t){super(`unknown codec "${t}": no codec by that name is given to this call`),this.name="UnknownCodec",this.code="unknown-codec",this.codec=t}},xe=class extends Error{constructor(t,n){super(n),this.name="CodecRefused",this.code=t}};function b(e){let t=0,n=null,o=-1;for(let r=0;r<e.length;r++){let i=e[r];i==="\\"?r++:n?i===n&&(n=null):i==='"'||i==="'"?n=i:i==="["||i==="("?t++:i==="]"||i===")"?t>0&&t--:i==="@"&&t===0&&(o=r)}return o}var qe="[*]";function R(e){let t=b(e),n=t===-1?e:e.slice(0,t),o=n.endsWith(qe),r={selector:o?n.slice(0,-qe.length):n,prop:t===-1?null:e.slice(t+1)||null};return o&&(r.all=!0),r}function Oe(e){let t=0,n=null,o=-1,r=!1;for(let i=0;i<e.length;i++){let s=e[i];s==="\\"?i++:n?s===n&&(n=null):s==='"'||s==="'"?n=s:s==="["||s==="("?t++:s==="]"||s===")"?t>0&&t--:t===0&&s===">"?o=i:t===0&&s===","&&(r=!0)}return r||o===-1||!Nt(e,o+1)?null:e.slice(0,o).trim()||null}function Nt(e,t){let n=t,o=e.replace(/\s+$/,"").length;for(;n<o&&/\s/.test(e[n]);)n++;let r=0,i=null;for(;n<o;n++){let s=e[n];if(s==="\\")n++;else if(i)s===i&&(i=null);else if(s==='"'||s==="'")i=s;else if(s==="["||s==="(")r++;else if(s==="]"||s===")")r>0&&r--;else if(r===0&&(s==="+"||s==="~"||/\s/.test(s)))return!1}return!0}var kt=/^codec\(([a-z][a-z0-9-]*)\)$/;function P(e){if(typeof e!="string")return null;let t=b(e);if(t===-1)return null;let n=kt.exec(e.slice(t+1));if(!n)return null;let{selector:o,all:r}=R(e);if(r)throw new C("A @codec(name) rule cannot use [*].");return{selector:o,name:n[1]}}var Pt=/^--[A-Za-z0-9_-]+$/;function _(e){return typeof e=="string"&&Pt.test(e)}function Ve(e){let t=[],n=[],o=null,r=0;for(let i=0;i<e.length;i++){let s=e[i];if(o){s==="\\"?i++:s===o&&(o=null);continue}if(s==="/"&&e[i+1]==="*"){let c=e.indexOf("*/",i+2);i=c===-1?e.length:c+1;continue}s==='"'||s==="'"?o=s:s==="("?n.push(")"):s==="["?n.push("]"):s==="{"?n.push("}"):(s===")"||s==="]"||s==="}")&&n[n.length-1]===s?n.pop():s===";"&&n.length===0&&(t.push(e.slice(r,i)),r=i+1)}return t.push(e.slice(r)),t}function Mt(e){let t="",n=null;for(let o=0;o<e.length;o++){let r=e[o];if(n){t+=r,r==="\\"&&o+1<e.length?t+=e[++o]:r===n&&(n=null);continue}if(r==="/"&&e[o+1]==="*"){let i=e.indexOf("*/",o+2);o=i===-1?e.length:i+1,t+=" ";continue}(r==='"'||r==="'")&&(n=r),t+=r}return t}function Be(e){e=Mt(e);let t=e.indexOf(":");if(t===-1)return null;let n=e.slice(0,t).trim(),o=e.slice(t+1).trim(),r=/!\s*important\s*$/i.exec(o);return r&&(o=o.slice(0,r.index).trim()),{name:n,value:o,important:!!r}}function K(e,t){if(e==null)return null;let n=null;for(let o of Ve(String(e))){let r=Be(o);!r||r.name!==t||(!n||r.important||!n.important)&&(n=r)}return n?n.value:null}function ze(e,t,n){let o=e==null?"":String(e),r=n==null||n==="",i=Ve(o),s=i.map(Be),c=s.some(d=>d&&d.name===t&&d.important),l=[],p=!1;i.forEach((d,h)=>{let A=s[h];if(!A||A.name!==t){l.push(d);return}if(r||p)return;let f=/^\s*/.exec(d)[0];l.push(`${f}${t}: ${n}${c?" !important":""}`),p=!0});let u=l.join(";");if(!r&&!p){let d=u.trimEnd();u=d===""?`${t}: ${n}`:`${d}${d.endsWith(";")?" ":"; "}${t}: ${n}`}return u.trim()===""?null:u}function Ee(e,t,n,o){let r=e.attr(t,"style");if((K(r,n)??"")===o)return;let i=ze(r,n,o);i==null?e.removeAttr(t,"style"):e.attr(t,"style",i)}var Fe=/^[a-z][a-z0-9-]*$/,Se=new Map;function be(e,t){if(typeof e!="string"||!Fe.test(e))throw new Error(`hyper-html-api: invalid codec name ${JSON.stringify(e)} (must match ${Fe})`);if(!t||typeof t.read!="function"||typeof t.write!="function"||typeof t.same!="function")throw new Error(`hyper-html-api: codec "${e}" needs read, write and same functions`);Se.set(e,t)}function Re(e){return Se.get(e)??null}function Ce(){return Object.fromEntries(Se)}var It='The @codec(name) rule form needs a rules tag with data-rules-version="2".',Lt="A @codec(name) rule must be the value of a top level key.";function ce(e,t){let n=P(e);return n?{...n,codec:t.codecs[n.name]}:null}function H(e,t={}){let n=t.version??"1",o=t.codecs??{};r(e,0);function r(i,s){if(!(s>L)){if(typeof i=="string"){let c=P(i);if(!c)return;if(n!=="2")throw new C(It);if(s!==1)throw new C(Lt);if(!Object.prototype.hasOwnProperty.call(o,c.name))throw new F(c.name);return}if(Array.isArray(i)){r(i[1],s+1);return}if(i&&typeof i=="object")for(let c of Object.values(i))r(c,s+1)}}}function M(e,t,n,o={}){if(Object.prototype.hasOwnProperty.call(o,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return H(n,o),ke(e,t,n,{depth:0,path:[]},o)}function ke(e,t,n,o,r){if(o.depth>L)throw new $(o.path);if(typeof n=="string")return jt(e,t,n,o,r);if(Array.isArray(n)){let[i,s]=n,c=e.find(t,i,r);return Ke(r,o,c),c.map((l,p)=>ke(e,l,s,{depth:o.depth+1,path:[...o.path,p]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[s,c]of Object.entries(n))i[s]=ke(e,t,c,{depth:o.depth+1,path:[...o.path,s]},r);return i}return null}function jt(e,t,n,o,r){if(n.endsWith("[]")){let u=n.slice(0,-2),d=e.find(t,u,r);return Ke(r,o,d),d.map(h=>e.text(h))}let i=ce(n,r);if(i)return $t(e,t,i,r);if(n.startsWith("@"))return Ne(e,t,n.slice(1));let s=b(n);if(s!==-1){let{selector:u,all:d}=R(n),h=n.slice(s+1),A=u?e.find(t,u,r):[t];return d&&r.allMatches?A.map(f=>Ne(e,f,h)):A.length===0?null:Ne(e,A[0],h)}if(n===".")return e.text(t);let{selector:c,all:l}=R(n),p=e.find(t,c,r);return l&&r.allMatches?p.map(u=>e.text(u)):p.length===0?null:e.text(p[0])}function $t(e,t,{selector:n,codec:o},r){let i=n?e.find(t,n,r):[t];return i.length===0?null:o.read(e,i[0],{query:r.query,view:r.view,region:r.region})}function Ke(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(o){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,o)}}function Ne(e,t,n){if(_(n))return K(e.attr(t,"style"),n);if(re.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o??null}function Xe(e,t,n,o){let r=e.length,i=t.length,s=new Array(r).fill(-1);if(o){let a=new Set;for(let y=0;y<r;y++){let w=o[y];!(w>=0&&w<i)||a.has(w)||(s[y]=w,a.add(w))}}if(r===0||i===0)return s;let c=e.map(a=>Je(a,n)),l=t.map(a=>Je(a,n)),p=new Array(i).fill(!1);for(let a of s)a>=0&&(p[a]=!0);let u=new Map;l.forEach((a,y)=>{p[y]||u.set(a,u.has(a)?-1:y)});let d=new Map;c.forEach((a,y)=>{s[y]>=0||d.set(a,(d.get(a)||0)+1)}),c.forEach((a,y)=>{if(s[y]>=0||d.get(a)!==1)return;let w=u.get(a);w===void 0||w===-1||p[w]||(s[y]=w,p[w]=!0)});let h=[];for(let a=0;a<r;a++)s[a]<0&&h.push(a);let A=[];for(let a=0;a<i;a++)p[a]||A.push(a);if(h.length===0||A.length===0)return s;let f=r*i+1,m=_t(e,t,n),g=(a,y)=>m(a,y)*f+Math.abs(a-y);for(let[a,y]of Dt(h,A,g))s[a]=y;return s}var Ge=e=>typeof e=="object"&&e!==null;function Je(e,t){if(!Ge(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(o=>{let r=JSON.stringify(e?.[o]);return r===void 0?" undef":r}))}function _t(e,t,n){if(!Ge(n))return(c,l)=>e[c]===t[l]?0:1;let o=Object.keys(n),r=c=>o.map(l=>JSON.stringify(c?.[l])),i=e.map(r),s=t.map(r);return(c,l)=>{let p=i[c],u=s[l],d=0;for(let h=0;h<o.length;h++)p[h]!==u[h]&&d++;return d}}function Dt(e,t,n){return e.length<=t.length?Ye(e,t,n,!1):Ye(t,e,(o,r)=>n(r,o),!0)}function Ye(e,t,n,o){let r=e.length,i=t.length,s=[];for(let d=0;d<=r;d++)s.push(new Float64Array(i+1).fill(1/0));let c=[];for(let d=0;d<=r;d++)c.push(new Uint8Array(i+1));for(let d=0;d<=i;d++)s[r][d]=0;for(let d=r-1;d>=0;d--)for(let h=i-1;h>=0;h--){let A=n(e[d],t[h])+s[d+1][h+1],f=s[d][h+1];A<=f?(s[d][h]=A,c[d][h]=1):s[d][h]=f}let l=[],p=0,u=0;for(;p<r&&u<i;)c[p][u]&&(l.push(o?[t[u],e[p]]:[e[p],t[u]]),p++),u++;return l}function Me(e,t,n,o,r,i,s,c={}){let l=e.find(t,n,c);if(r.length===0){l.forEach(T=>e.remove(T)),Pe(c,"onRowsApplied",i.path,[]);return}let p=r.length>l.length,u=l[0]||null;if(p&&!u&&(u=Ht(e,t,n,c),!u))throw new I(i.path);let d=l.map(T=>Wt(e,T,o,c)),h=null;if(p&&u){h=e.clone(u),c.templateAttr&&e.removeAttr(h,c.templateAttr);let T=e.stripIds(h);T>0&&console.warn(`[hyper-html-api] stripped ${T} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let A=Xe(r,d,o,vt(e,l,r,i,c)),f=l.length>0?e.parent(l[0]):zt(e,t,n,u,i,c),m=l.length>0?nt(e,f,l[0]):0,g=Jt(e,l),a=new Set,y=[],w=r.map((T,S)=>{let O=A[S];if(O>=0)return a.add(O),y.push(!1),l[O];y.push(!0);let x=e.clone(h);return e.stripIds(x),x});l.forEach((T,S)=>{a.has(S)||e.remove(T)}),g?Kt(e,f,m,w,y):Yt(e,w,y,f,m),Ut(e,w,o,r,i,s,c),Pe(c,"onRowsApplied",i.path,w)}function Pe(e,t,n,o){if(typeof e[t]=="function")try{return e[t](n.slice(),o)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function vt(e,t,n,o,r){let i=Pe(r,"identifyRows",o.path,n);if(!Array.isArray(i))return null;let s=new Array(n.length).fill(-1),c=new Set,l=new Map(t.map((p,u)=>[e.identity(p),u]));for(let p=0;p<n.length;p++){if(!i[p])continue;let u=l.get(e.identity(i[p]));u===void 0||c.has(u)||(s[p]=u,c.add(u))}return s}function Ut(e,t,n,o,r,i,s){t.forEach((c,l)=>{if(n===null){let p=o[l],u=p==null?"":String(p);e.text(c)!==u&&e.text(c,u)}else{let p=i(e,c,n,o[l],{depth:r.depth+1,path:[...r.path,l]},s);p&&p!==c&&(t[l]=p)}})}function Wt(e,t,n,o){return n===null?e.text(t):M(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function nt(e,t,n){let o=e.children(t);for(let r=0;r<o.length;r++)if(e.sameNode(o[r],n))return r;return-1}function Ht(e,t,n,o){if(!o.templateAttr)return null;let r=/^\s*:scope\s*>\s*/.test(n),i=new RegExp(":not\\(\\["+o.templateAttr.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")+"\\]\\)","g"),s=n.replace(/^\s*:scope\s*>\s*/,"").replace(i,""),c=r?qt(s):0,l=Oe(s),p=t;for(;p;){let u=e.find(p,s,{includeRulesTag:!1,templateAttr:null});for(let d of u)if(e.attr(d,o.templateAttr)!=null&&!(r&&!Bt(e,t,d,c))&&!(l&&!e.matches(e.parent(d),l)))return d;p=e.parent(p)}return null}function qt(e){let t=0,n=null,o=1;for(let r=0;r<e.length;r++){let i=e[r];if(i==="\\")r++;else if(n)i===n&&(n=null);else if(i==='"'||i==="'")n=i;else if(i==="["||i==="(")t++;else if(i==="]"||i===")")t>0&&t--;else if(t===0&&i===">")o++;else{if(t===0&&(i==="+"||i==="~"))return null;if(t===0&&/\s/.test(i)){if(!Vt(e,r))return null;for(;r+1<e.length&&/\s/.test(e[r+1]);)r++}}}return o}function Vt(e,t){let n=t;for(;n<e.length&&/\s/.test(e[n]);)n++;let o=t>0?e[t-1]:"",r=n<e.length?e[n]:"";return Ze(o)||Ze(r)}function Ze(e){return e===">"||e==="+"||e==="~"}function Bt(e,t,n,o){if(o===null)return!0;let r=n;for(let l=0;l<o;l++)if(r=e.parent(r),!r)return!1;let i=e.prop(t,"tagName");if(!i)return!0;let s=e.prop(r,"tagName");if(!s||String(s).toLowerCase()!==String(i).toLowerCase())return!1;let c=new Set(Qe(e,r));return Qe(e,t).every(l=>c.has(l))}function Qe(e,t){let n=e.attr(t,"class");return n?String(n).split(/\s+/).filter(Boolean):[]}function zt(e,t,n,o,r,i){let s=e.parent(o);if(s&&Ft(e,t,s)&&!tt(e,s,i))return s;let c=Oe(n);if(!c)throw new I(r.path,`the list selector "${n}" 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 p=(c===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,c,i)).filter(u=>!tt(e,u,i));if(p.length===0)throw new I(r.path,`no container matching "${c}" inside this context to hold the new rows`);if(p.length>1)throw new I(r.path,`"${c}" matches ${p.length} containers inside this context, so the new rows have no single destination`);return p[0]}function Ft(e,t,n){let o=n;for(;o;){if(e.sameNode(o,t))return!0;o=e.parent(o)}return e.parent(t)?!1:e.find(t,"*",{includeRulesTag:!0,templateAttr:null}).some(r=>e.sameNode(r,n))}var et=["no-data","editor-ui"];function tt(e,t,n){let o=t;for(;o;){if(n.templateAttr&&e.attr(o,n.templateAttr)!=null||et.some(i=>e.attr(o,i)!=null))return!0;let r=e.attr(o,"clay");if(r&&r.split(/\s+/).some(i=>et.includes(i)))return!0;o=e.parent(o)}return!1}function Kt(e,t,n,o,r){let i=e.children(t),s=i.map(l=>e.identity(l)),c=!1;o.forEach((l,p)=>{let u=e.identity(l),d=n+p;if(s[d]===u)return;if(!r[p]){let A=s.indexOf(u);A!==-1&&(s.splice(A,1),i.splice(A,1))}let h=Math.min(d,i.length);h<i.length?e.insertBefore(i[h],l):i.length?c?e.insertAfter(i[i.length-1],l):(e.insertAt(t,l,d),c=!0):e.insertAt(t,l,0),s.splice(h,0,u),i.splice(h,0,l)})}function Jt(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let o=new Map(e.children(n).map((i,s)=>[e.identity(i),s])),r=[];for(let i of t){let s=o.get(e.identity(i));if(s===void 0)return!1;r.push(s)}return r.sort((i,s)=>i-s),r[r.length-1]-r[0]===r.length-1}function Yt(e,t,n,o,r){let i=null,s=r;for(let c=0;c<t.length;c++){if(!n[c]){i=t[c];continue}let l=i?e.parent(i):o;if(!l)continue;let p=i?nt(e,l,i)+1:s++;e.insertAt(l,t[c],p),i=t[c]}}function D(e,t,n,o,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");H(n,r);let i=[];if(Ie(n,o,[],i),i.length)throw new B(i);le(e,t,n,o,{depth:0,path:[]},r)}function le(e,t,n,o,r,i={}){if(r.depth>L)throw new $(r.path);if(o===void 0)return t;if(typeof n=="string")return Xt(e,t,n,o,r,i);if(Array.isArray(n)){let[s,c]=n;return Me(e,t,s,c,o,r,le,i),t}if(typeof n=="object"&&n!==null){for(let[s,c]of Object.entries(n)){let l=le(e,t,c,o==null?o:o[s],{depth:r.depth+1,path:[...r.path,s]},i);l&&l!==t&&(t=l)}return t}return t}function Xt(e,t,n,o,r,i){if(n.endsWith("[]")){let d=n.slice(0,-2);return Me(e,t,d,null,o,r,le,i),t}let s=ce(n,i);if(s){let d=s.selector?e.find(t,s.selector,i):[t];return d.length&&s.codec.write(e,d[0],o,{query:i.query}),t}if(n.startsWith("@"))return ot(e,t,n.slice(1),o);let c=b(n);if(c!==-1){let{selector:d,all:h}=R(n),A=n.slice(c+1),f=d?e.find(t,d,i):[t];for(let m of h?f:f.slice(0,1))ot(e,m,A,o);return t}if(n===".")return rt(e,t,o),t;let{selector:l,all:p}=R(n),u=e.find(t,l,i);for(let d of p?u:u.slice(0,1))rt(e,d,o);return t}function rt(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function Gt(e,t,n,o){if(e.styleVar){e.styleVar(t,n,o);return}Ee(e,t,n,o)}function ot(e,t,n,o){if(_(n))return Gt(e,t,n,o==null?"":String(o).trim()),t;if(W.has(n)){let r=e.prop(t,n);if(r===o||r!=null&&o!=null&&String(r)===String(o))return t;throw new z(n)}if(n==="outerHTML"){let r=o==null?"":String(o);return e.replaceWith(t,r)}if(ge.has(n)){let r=we(n,o);return e.prop(t,n)!==r&&e.prop(t,n,r),t}if(o==null)e.attr(t,n)!=null&&e.removeAttr(t,n);else{let r=String(o);e.attr(t,n)!==r&&e.attr(t,n,r)}return t}function Ie(e,t,n,o){if(t!==void 0){if(typeof e=="string"){if(P(e))return;if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,i)=>{typeof r=="object"&&r!==null&&o.push({path:Y([...n,i]),expected:"scalar",got:J(r)})}):o.push({path:Y(n),expected:"array",got:J(t)});return}t!==null&&typeof t=="object"&&o.push({path:Y(n),expected:"scalar",got:J(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:Y(n),expected:"array",got:J(t)});return}let r=e[1];t.forEach((i,s)=>Ie(r,i,[...n,s],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:Y(n),expected:"object",got:J(t)});return}for(let[r,i]of Object.entries(e))Ie(i,t[r],[...n,r],o)}}}function J(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function Y(e){return e.join(".")}function Le(e){try{return JSON.parse(e)}catch(t){throw new C(`Invalid strict JSON: ${t.message}`,t)}}function v(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 n(r){let i=[],s=0;for(;s<r.length;){let c=r[s];if(/\s/.test(c)){s++;continue}if("{}".includes(c)){i.push({type:c,value:c}),s++;continue}if(c==="["){let d=!1,h=s+1;for(;h<r.length&&/\s/.test(r[h]);)h++;if(h<r.length&&/[a-zA-Z_]/.test(r[h])&&(d=!0),!d){i.push({type:c,value:c}),s++;continue}}if(c==="]"){i.push({type:c,value:c}),s++;continue}if(c===":"){i.push({type:t.COLON,value:c}),s++;continue}if(c===","){i.push({type:t.COMMA,value:c}),s++;continue}if(c==='"'||c==="'"){let d=c,h=s+1;for(;h<r.length&&r[h]!==d;)r[h]==="\\"&&h++,h++;i.push({type:t.STRING,value:r.substring(s+1,h),quoted:!0,sourceQuote:d}),s=h+1;continue}let l=s,p;for(;l<r.length&&!/[{},]/.test(r[l]);)if(r[l]===":"){let d=[":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"],h=!1;for(let A of d){let f=A.substring(1);if(r.substring(l+1,l+1+f.length)===f){h=!0,l+=f.length;break}}if(!h)break}else if(r[l]==="["){for(l++;l<r.length&&r[l]!=="]";){if(r[l]==='"'||r[l]==="'"){let d=r[l];for(l++;l<r.length&&r[l]!==d;)r[l]==="\\"&&l++,l++}l++}l<r.length&&r[l]==="]"&&l++}else l++;p=r.substring(s,l);let u=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(p)?u=t.NUMBER:p==="true"||p==="false"||p==="null"?u=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(p)&&(u=t.SELECTOR),i.push({type:u,value:p,quoted:!1}),s=l}return i}function o(r){let i="";for(let s=0;s<r.length;s++){let c=r[s];if("{}".includes(c.type)||"[]".includes(c.type)){i+=c.value;continue}if(c.type===t.COLON){i+=c.value;continue}if(c.type===t.COMMA){let l=r[s+1];if(l&&(l.type==="}"||l.type==="]"))continue;i+=c.value;continue}if(c.type===t.STRING&&c.quoted){let l=c.value;c.sourceQuote==="'"&&(l=l.replace(/\\'/g,"'"),l=l.replace(/(\\*)"/g,(p,u)=>u.length%2===0?u+'\\"':p)),i+=`"${l}"`;continue}if(c.type===t.NUMBER||c.type===t.BOOLEAN){i+=c.value;continue}if(c.type===t.SELECTOR||c.type===t.IDENTIFIER){i+=`"${c.value}"`;continue}i+=`"${c.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new C("Invalid extraction rules syntax: "+r.message,r)}}var fe=["1","2"],it=/^[a-zA-Z0-9_-]+$/;function X(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!it.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${it})`);o=`script[data-rules-name~="${n}"]`}let r=e.find(t,o,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let i=r[0],s=e.attr(i,"data-rules-version");if(!fe.includes(s))throw new j(s);return{rules:v(e.text(i)),tagNode:i,version:s}}var ue=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"]})}),Zt=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),st=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);function G(e,t){if(!e||e.nodeType!==1)return!1;let n=e.getAttribute?.("clay");return!!(n&&n.split(/\s+/).includes(t)||e.hasAttribute?.(t))}function je(e,t){if(G(e,t))return!0;for(let[n,o]of Object.entries(Zt))if(o.includes(t)&&G(e,n))return!0;return!1}function Z(e){let t=ue[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function Qt(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let o=ue[t];if(!o)throw new Error(`Unknown region capability: ${t}`);if(o.tokens.some(r=>je(n,r))||o.bundles.some(r=>G(n,r)))return n;n=n.parentElement}return null}function ct(e,t){return!!Qt(e,t)}var en=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",...st],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 $e(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null,version:"1"};if(typeof n=="string"){let o=t&&t.ownerDocument?t.ownerDocument:t;return X(e,o,n)}return null}var on=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function sn(e,t){if(!/^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(e.tagName||""))return;let n=(e.getAttribute?.("type")||"").toLowerCase();"value"in e&&"value"in t&&e.tagName!=="OPTION"&&n!=="checkbox"&&n!=="radio"&&n!=="file"&&(t.value=e.value),e.tagName==="INPUT"&&(n==="checkbox"||n==="radio")&&(t.checked=e.checked),e.tagName==="OPTION"&&(t.selected=e.selected),"indeterminate"in e&&"indeterminate"in t&&(t.indeterminate=e.indeterminate)}function lt(e,t,n,o){if(o)return!!e.closest?.(t);let r=e;for(;r?.nodeType===1;){if(r.matches(t))return!0;if(r===n)break;r=r.parentElement}return!1}function ft(e,t,n,o,r,i){return(i?ct(e,t):lt(e,n,r,!1))||!!(o&&(i&&e!==r?e.matches(o):lt(e,o,r,i)))}function cn(e,t){let n=ue[t];return n.tokens.some(o=>je(e,o))||n.bundles.some(o=>G(e,o))}var ln=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function ut(e,t,n,o){if(e.nodeType===1&&o(e)){n.dropped.push(t);return}n.cloneToLive.set(t,e),n.liveToClone.set(e,t);let r=e,i=t;if(e.nodeType===1){if(ln.has(e.tagName)&&n.controls.push(e,t),e.tagName==="TEMPLATE"){for(;t.firstChild;)t.removeChild(t.firstChild);r=e.content,i=t.content,n.cloneToLive.set(i,r),n.liveToClone.set(r,i)}}else if(e.nodeType!==11)return;let s=i.firstChild;for(let c=r.firstChild;c&&s;c=c.nextSibling)ut(c,s,n,o),s=s.nextSibling}function Q(e,{capability:t="data",exclude:n=null,inherit:o=!0,provenance:r=null}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let i=e.nodeType===9?e:e.ownerDocument;if(!i?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let s=i.implementation.createHTMLDocument(""),c=r||new WeakMap,l=new WeakMap,p=e.nodeType===9?e.documentElement:e;n&&s.documentElement.matches(n);let u=Z(t),d=o?f=>cn(f,t)||!!(n&&f.matches(n)):f=>ft(f,t,u,n,p,!1),h=null;if(p.nodeType!==1||!ft(p,t,u,n,p,o)){h=s.importNode(p,!0);let f={cloneToLive:c,liveToClone:l,dropped:[],controls:[]};ut(p,h,f,d);for(let m of f.dropped)m.remove();for(let m=0;m<f.controls.length;m+=2)sn(f.controls[m],f.controls[m+1])}e.nodeType===9&&h&&(s.replaceChild(h,s.documentElement),l.set(e,s),c.set(s,e));let A=f=>{if(on.test(f))throw new Error(`Filtered content queries do not support stateful selector: ${f}`)};return{root:h,document:s,capability:t,selector:Z(t),cloneToLive:c,liveToClone:l,original(f){return c.get(f)||null},cloneOf(f){return l.get(f)||null},query(f,m=h){return A(f),Array.from(m.querySelectorAll(f),g=>c.get(g)||g)},text(f=h){return(f===h?h:l.get(f))?.textContent||""},html(f=h){return(f===h?h:l.get(f))?.innerHTML??""},clone(f=h){let m=f===h?h:l.get(f);return m?s.importNode(m,!0):null}}}function dt(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function fn(e){return e?(e.nodeType===9||e.nodeType===11,e):null}function at(e,t,n){!e||e.nodeType!==1||(t==="value"&&e.tagName==="INPUT"?e.value=n===null?"":n:t==="checked"&&e.tagName==="INPUT"?e.checked=n!==null:t==="selected"&&e.tagName==="OPTION"&&(e.selected=n!==null))}function pt(e,t){e&&e.tagName==="TEXTAREA"&&(e.value=t)}function ht(e){if(!e||e.nodeType!==1)return;let t=[e,...e.querySelectorAll?e.querySelectorAll("textarea, input, option"):[]];for(let n of t)if(n.tagName==="TEXTAREA")n.value=n.defaultValue;else if(n.tagName==="INPUT"){let o=n.type;o!=="file"&&o!=="checkbox"&&o!=="radio"&&(n.value=n.defaultValue),n.checked=n.defaultChecked}else n.tagName==="OPTION"&&(n.selected=n.defaultSelected)}var E={semanticExclude:!0,find(e,t,n={}){let o=fn(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(c=>!dt(c)));let i=[];n.skip&&i.push(n.skip);let s=n.templateAttr===null?null:n.templateAttr||"cms-template";if(s&&i.push("["+s+"]"),i.length){let c=i.join(", ");r=r.filter(l=>!l.closest||!l.closest(c))}return r},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,pt(e,t)},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n),at(e,t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),at(e,t,null)},prop(e,t,n){if(n===void 0){let o=e?e[t]:void 0;return o!==void 0?o:null}e[t]=n},clone(e){let t=e.cloneNode(!0);return ht(t),t},insertAt(e,t,n){let o=e.children[n]||null;e.insertBefore(t,o)},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 o=e.ownerDocument.createElement("template");o.innerHTML=t;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function ee(e,t={}){if(t.exclude===null)return E;let n=[Z("data"),t.exclude].filter(Boolean).join(", "),o=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!o?.querySelector?.(n))return E;let i=e.nodeType===9||!e.isConnected?e:e.ownerDocument,s=e.nodeType===9?e:e.ownerDocument,c=null,l=()=>c||(c=Q(i,{capability:"data",exclude:t.exclude||null})),p=f=>{let m=l();return f===e?m.cloneOf(e):m.cloneOf(f)||f},u=f=>c?.original(f)||f,d=(f,m)=>{l().liveToClone.set(f,m),l().cloneToLive.set(m,f);let g=f.childNodes||[],a=m.childNodes||[];for(let y=0;y<Math.min(g.length,a.length);y++)d(g[y],a[y])},h=(f,m,g,a)=>{let y=Array.from(f.childNodes).filter(x=>c.cloneOf(x)),T=y[0];for(;T&&y.includes(T);)T=T.nextSibling;for(let x of y)x.remove();if(g==="innerHTML"){let x=s.createElement("template");x.innerHTML=a;for(let V of Array.from(x.content.childNodes))f.insertBefore(V,T||null)}else f.insertBefore(s.createTextNode(a),T||null),pt(f,a);let S=Q(f,{capability:"data",exclude:t.exclude||null});m.replaceChildren(...Array.from(S.root?.childNodes||[]));let O=x=>{let V=S.original(x);V&&(c.liveToClone.set(V,x),c.cloneToLive.set(x,V));for(let St of Array.from(x.childNodes||[]))O(St)};for(let x of Array.from(m.childNodes))O(x)},A={...E,find(f,m,g={}){let a=p(f);if(!a?.querySelectorAll)return[];let y=l().query(m,a);g.includeRulesTag||(y=y.filter(S=>!dt(S)));let w=[];g.skip&&w.push(g.skip);let T=g.templateAttr===null?null:g.templateAttr||"cms-template";if(T&&w.push(`[${T}]`),w.length){let S=w.join(", ");y=y.filter(O=>!O.closest?.(S))}return y},parent(f){let m=p(f)?.parentElement;return m?u(m):null},children(f){return Array.from(p(f)?.children||[],u)},text(f,m){if(m===void 0){let y=u(f);return!y?.matches?.(n)&&!y?.querySelector?.(n)?E.text(y):(p(f)?.textContent||"").trim()}let g=u(f);if(!g?.matches?.(n)&&!g?.querySelector?.(n)&&!c){E.text(g,m);return}let a=l().cloneOf(g);a?h(g,a,"textContent",m):E.text(g,m)},attr(f,m,g){let a=u(f);if(g===void 0)return E.attr(a,m);E.attr(a,m,g);let y=c?.cloneOf(a);y&&(E.attr(y,m,g),Q(a,{capability:"data",exclude:t.exclude||null}).root===null&&(y.remove(),c.liveToClone.delete(a),c.cloneToLive.delete(y)))},removeAttr(f,m){let g=u(f);E.removeAttr(g,m);let a=c?.cloneOf(g);a&&E.removeAttr(a,m)},prop(f,m,g){let a=u(f);if(g===void 0)return m==="innerHTML"||m==="outerHTML"||m==="textContent"||m==="innerText"?E.prop(p(a),m):E.prop(a,m);let y=m==="innerHTML"||m==="textContent"||m==="innerText",w=y?l().cloneOf(a):c?.cloneOf(a);w&&y?h(a,w,m,g):(E.prop(a,m,g),w&&E.prop(w,m,g))},clone(f){let m=p(f);if(m===f)return E.clone(f);let g=s.importNode(m,!0);return ht(g),g},insertAt(f,m,g){let a=u(f),w=A.children(a)[g]||(()=>{for(let O=a.children.length-1;O>=0;O--){let x=a.children[O];if(l().cloneOf(x))return x.nextElementSibling}return a.firstElementChild})(),T=u(m);a.insertBefore(T,w||null);let S=l().cloneOf(a);if(S){let O=l().cloneOf(T);O||(O=s.importNode(T,!0),d(T,O));let x=Array.from(S.children);S.insertBefore(O,x[g]||null)}},insertBefore(f,m){let g=u(f),a=u(m);g.parentNode.insertBefore(a,g);let y=l().cloneOf(g.parentNode);if(y){let w=l().cloneOf(a);w||(w=s.importNode(a,!0),d(a,w));let T=l().cloneOf(g);T?T.before(w):y.appendChild(w)}},insertAfter(f,m){let g=u(f),a=u(m);g.parentNode.insertBefore(a,g.nextSibling);let y=l().cloneOf(g.parentNode);if(y){let w=l().cloneOf(a);w||(w=s.importNode(a,!0),d(a,w));let T=l().cloneOf(g);T?T.after(w):y.appendChild(w)}},identity(f){return u(f)||null},remove(f){let m=u(f),g=l().cloneOf(m);E.remove(m),g&&E.remove(g)},replaceWith(f,m){let g=u(f),a=l().cloneOf(g),y=E.replaceWith(g,m);if(a){let w=Q(y,{capability:"data",exclude:t.exclude||null});if(!w.root)a.remove();else{a.replaceWith(w.root);let T=S=>{let O=w.original(S);O&&(c.liveToClone.set(O,S),c.cloneToLive.set(S,O));for(let x of Array.from(S.childNodes||[]))T(x)};T(w.root)}}return y}};return A}var N=E;var _e=e=>({codecs:Ce(),...e}),mt={extract:(e,t,n={})=>M(ee(e,n),e,t,_e(n)),apply:(e,t,n,o={})=>D(ee(e,{...o,_write:!0}),e,t,n,_e(o)),findRulesIn:(e,t)=>X(N,e,t),findRules:(e,t)=>$e(N,e,t),bind:(e,t,n={})=>{let o=$e(N,e,t);if(!o){let i=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${i}`)}let r=_e({version:o.version,...n});return{...o,get:()=>M(ee(e,n),e,o.rules,r),set:i=>D(ee(e,{...n,_write:!0}),e,o.rules,i,r)}},codecs:{register:be,get:Re},parseStrict:Le,parseRelaxed:v,ruleAttrIndex:b,splitRule:R,errors:se,DOM_PROPERTIES:ne};var un="hha:upgrade-check:";function k(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function De(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function yt(e,t){let n=De(e),o=De(t);if(!n||!o)return!1;let r=Math.max(n.length,o.length);for(let i=0;i<r;i++){let s=n[i]||0,c=o[i]||0;if(s!==c)return s>c}return!1}function an(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function dn(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function gt({force:e=!1,doc:t,loc:n,fetchFn:o,now:r,ttlMs:i=864e5}={}){if(t=t||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(h=>fetch(h)),r=r??Date.now(),!t)return null;let s=k(t,"hyper-source");if(!s)return null;let c=k(t,"hyper-version"),l;try{l=new URL(s,n?n.href:void 0)}catch{return null}if(n&&l.origin===n.origin&&l.pathname===n.pathname)return null;let p=`${un}${l.href}:${c||"none"}`,u,d=e?null:an(p);if(d&&typeof d.checkedAt=="number"&&r-d.checkedAt<i)u=d.sourceVersion;else{try{let h=await o(l.href);if(!h.ok)throw new Error(`HTTP ${h.status}`);let A=await h.text(),f=new DOMParser().parseFromString(A,"text/html");u=k(f,"hyper-version")}catch{u=null}dn(p,{checkedAt:r,sourceVersion:u})}return u?{available:yt(u,c||"0.0.0"),currentVersion:c,sourceVersion:u,sourceUrl:l.href}:null}var pn="script[data-rules-name]";function hn(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function ae(e,t){let n=e.find(t,pn,{includeRulesTag:!0}),o=new Set,r=[];for(let i of n){let s=hn(e.attr(i,"data-rules-name"));if(!s)continue;if(o.has(s)){console.warn(`hyper-html-api: duplicate rules tag name "${s}"; using the first.`);continue}let c=e.attr(i,"data-rules-version");if(!fe.includes(c))throw new j(c);o.add(s),r.push({name:s,rules:v(e.text(i)),version:c})}return r}function de(e,t){if(t!=="2"||!e||typeof e!="object"||Array.isArray(e))return{rules:e,carried:[]};let n={},o=[];for(let[r,i]of Object.entries(e)){let s=P(i);s?o.push({key:r,selector:s.selector}):n[r]=i}return{rules:n,carried:o}}function pe(e,t,n){return e.find(t,n)[0]||null}function ve(e,t){let n={};for(let{name:o,rules:r,version:i}of ae(e,t)){let{rules:s,carried:c}=de(r,i),l=M(e,t,s,{version:i});for(let{key:p,selector:u}of c){let d=pe(e,t,u);l[p]=d?e.prop(d,"innerHTML"):null}n[o]=l}return n}function wt(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:ve(N,t),version:k(n,"hyper-version")}}var te=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},he=class extends Error{constructor(t){super(`upgrade source has no rules tags; refusing to drop all existing data: ${t}`),this.name="UpgradeSourceHasNoRules",this.sourceUrl=t}},U=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},me=class extends Error{constructor(t){super(`found ${t} script[type="text/hyper-upgrade"] tags; only one is allowed per document.`),this.name="UpgradeMultipleTransforms",this.count=t}};var mn="text/hyper-upgrade";function At(e,t){let n=e.find(t,`script[type="${mn}"]`);if(n.length===0)return null;if(n.length>1)throw new me(n.length);return e.text(n[0])||null}var yn=new Function("url","return import(url)");async function Tt(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await yn(n)}catch(r){throw new U(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new U("transform must `export default` a function");return o.default}function ye(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=Ue(t,e,n);return We(t,e,n),{data:o,summary:n}}function Ue(e,t,n,o=!1){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(n.listItems+=t.length,n.carriedOver+=t.length,t):o?[]:void 0:t==null||typeof t=="object"?o&&!gn(e)?null:void 0:(n.carriedOver++,t);if(Array.isArray(e)){let[,r]=e;return Array.isArray(t)?(n.listItems+=t.length,t.map(i=>Ue(r,i,n,!0))):o?[]:void 0}if(typeof e=="object"&&e!==null){let r={};for(let[i,s]of Object.entries(e)){let c=Ue(s,t?.[i],n,o);c!==void 0&&(r[i]=c)}return r}}function gn(e){let t=b(e);return t!==-1&&W.has(e.slice(t+1))}function We(e,t,n){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let o=new Set(Object.keys(e));for(let r of Object.keys(t))o.has(r)?We(e[r],t[r],n):n.discarded+=q(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>We(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=q(t))}}function q(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+q(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+q(n),0):1}function xt(e,t,n){let o=ae(e,t),r={carriedOver:0,discarded:0,listItems:0},i={},s=new Set;for(let{name:c,rules:l,version:p}of o){if(s.add(c),!Object.prototype.hasOwnProperty.call(n,c)){i[c]={carriedOver:0,discarded:0,listItems:0};continue}let{rules:u,carried:d}=de(l,p),h=n[c],{data:A,summary:f}=ye(wn(h,d),u);D(e,t,u,A,{templateAttr:"cms-template"});for(let{key:m,selector:g}of d){let a=Ot(h)?h[m]:void 0;if(a==null)continue;let y=pe(e,t,g);typeof a=="string"&&y?(e.prop(y,"innerHTML",a),f.carriedOver+=1):f.discarded+=1}i[c]=f,r.carriedOver+=f.carriedOver,r.discarded+=f.discarded,r.listItems+=f.listItems}for(let c of Object.keys(n))s.has(c)||(r.discarded+=q(n[c]));return{totals:r,byName:i,rulesTagCount:o.length}}function Ot(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function wn(e,t){if(!t.length||!Ot(e))return e;let n={...e};for(let{key:o}of t)delete n[o];return n}async function Et({sourceUrl:e,dataByName:t,fromVersion:n,doc:o,loc:r,fetchFn:i}={}){if(o=o||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),i=i||(a=>fetch(a)),!o)throw new Error("upgrade.run requires a document context");if(e=e||k(o,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let s=new URL(e,r?r.href:void 0);n=n!==void 0?n:k(o,"hyper-version"),t=t||ve(N,o);let c;try{c=await i(s.href)}catch(a){throw new te(s.href,a)}if(!c.ok)throw new te(s.href,new Error(`HTTP ${c.status}`));let l=await c.text(),p=new DOMParser().parseFromString(l,"text/html"),u=k(p,"hyper-version"),d=t,h=!1,A=At(N,p);if(A){let y=await(await Tt(A))(d,{fromVersion:n,toVersion:u});if(!y||typeof y!="object"||Array.isArray(y))throw new U("transform must return a plain object map of { rulesName: data }");d=y,h=!0}let{totals:f,byName:m,rulesTagCount:g}=xt(N,p,d);if(g===0&&Object.keys(d).length>0)throw new he(s.href);return{html:Tn(p),fromVersion:n,toVersion:u,summary:{transformApplied:h,totals:f,byName:m}}}function An(e){for(let t of e.querySelectorAll("input")){let n=(t.getAttribute("type")||"").toLowerCase();n!=="file"&&(n==="checkbox"||n==="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 n=[...t.options];if(!t.multiple){let o=n.findIndex(r=>r.hasAttribute("selected"));if(t.selectedIndex===o||o===-1&&t.selectedIndex<=0)continue}for(let o of n)o.selected!==o.hasAttribute("selected")&&o.toggleAttribute("selected",o.selected)}}function Tn(e){return An(e),`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
5
- `+e.documentElement.outerHTML}var xn={checkForUpdate:gt,run:Et,extractAll:wt,shapeMatch:ye};var On={engine:mt,upgrade:xn},En=On;export{En as default,mt as engine,yt as isNewerVersion,De as parseVersion,k as readMeta,xn as upgrade};
4
+ var bt=Object.defineProperty;var Rt=(e,t)=>{for(var n in t)bt(e,n,{get:t[n],enumerable:!0})};var ne=["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"],re=new Set(ne),ge=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),W=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),He=new Set(["checked","selected","disabled","readOnly","paused"]);function Ae(e,t){return t==null?He.has(e)?!1:"":He.has(e)?t==="false"?!1:!!t:t}var se={};Rt(se,{CodecRefused:()=>xe,EmptyListInsert:()=>I,MAX_RULE_DEPTH:()=>L,MaxRuleDepthExceeded:()=>$,NoRulesTag:()=>we,RuleTargetReadOnly:()=>z,RulesParseError:()=>C,ShapeMismatch:()=>B,UnknownCodec:()=>F,UnknownRulesVersion:()=>j,WriteNotRoundTripped:()=>ie,WriteRefused:()=>oe,WriteRejected:()=>Te});var C=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},j=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1" and "2".`),this.name="UnknownRulesVersion",this.version=t}},L=20,$=class extends Error{constructor(t){super(`rule depth exceeded ${L} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},B=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},I=class extends Error{constructor(t,n){super(n?`cannot add items to empty list at "${t.join(".")}" \u2014 ${n}`:`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},z=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},oe=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}};function Ct(e){return e.reduce((n,o)=>typeof o=="number"?`${n}[${o}]`:n?`${n}.${o}`:String(o),"")||"(root)"}var ie=class extends Error{constructor(t){super(`write did not round-trip at "${Ct(t)}"`),this.name="WriteNotRoundTripped",this.path=t}},we=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},Te=class extends Error{constructor(t,n){super(`write rejected: ${t.length} unknown key(s), ${n.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=t,this.unmatched=n}},F=class extends Error{constructor(t){super(`unknown codec "${t}": no codec by that name is given to this call`),this.name="UnknownCodec",this.code="unknown-codec",this.codec=t}},xe=class extends Error{constructor(t,n){super(n),this.name="CodecRefused",this.code=t}};function b(e){let t=0,n=null,o=-1;for(let r=0;r<e.length;r++){let i=e[r];i==="\\"?r++:n?i===n&&(n=null):i==='"'||i==="'"?n=i:i==="["||i==="("?t++:i==="]"||i===")"?t>0&&t--:i==="@"&&t===0&&(o=r)}return o}var qe="[*]";function R(e){let t=b(e),n=t===-1?e:e.slice(0,t),o=n.endsWith(qe),r={selector:o?n.slice(0,-qe.length):n,prop:t===-1?null:e.slice(t+1)||null};return o&&(r.all=!0),r}function Oe(e){let t=0,n=null,o=-1,r=!1;for(let i=0;i<e.length;i++){let s=e[i];s==="\\"?i++:n?s===n&&(n=null):s==='"'||s==="'"?n=s:s==="["||s==="("?t++:s==="]"||s===")"?t>0&&t--:t===0&&s===">"?o=i:t===0&&s===","&&(r=!0)}return r||o===-1||!Nt(e,o+1)?null:e.slice(0,o).trim()||null}function Nt(e,t){let n=t,o=e.replace(/\s+$/,"").length;for(;n<o&&/\s/.test(e[n]);)n++;let r=0,i=null;for(;n<o;n++){let s=e[n];if(s==="\\")n++;else if(i)s===i&&(i=null);else if(s==='"'||s==="'")i=s;else if(s==="["||s==="(")r++;else if(s==="]"||s===")")r>0&&r--;else if(r===0&&(s==="+"||s==="~"||/\s/.test(s)))return!1}return!0}var kt=/^codec\(([a-z][a-z0-9-]*)\)$/;function P(e){if(typeof e!="string")return null;let t=b(e);if(t===-1)return null;let n=kt.exec(e.slice(t+1));if(!n)return null;let{selector:o,all:r}=R(e);if(r)throw new C("A @codec(name) rule cannot use [*].");return{selector:o,name:n[1]}}var Pt=/^--[A-Za-z0-9_-]+$/;function _(e){return typeof e=="string"&&Pt.test(e)}function Ve(e){let t=[],n=[],o=null,r=0;for(let i=0;i<e.length;i++){let s=e[i];if(o){s==="\\"?i++:s===o&&(o=null);continue}if(s==="/"&&e[i+1]==="*"){let c=e.indexOf("*/",i+2);i=c===-1?e.length:c+1;continue}s==='"'||s==="'"?o=s:s==="("?n.push(")"):s==="["?n.push("]"):s==="{"?n.push("}"):(s===")"||s==="]"||s==="}")&&n[n.length-1]===s?n.pop():s===";"&&n.length===0&&(t.push(e.slice(r,i)),r=i+1)}return t.push(e.slice(r)),t}function Mt(e){let t="",n=null;for(let o=0;o<e.length;o++){let r=e[o];if(n){t+=r,r==="\\"&&o+1<e.length?t+=e[++o]:r===n&&(n=null);continue}if(r==="/"&&e[o+1]==="*"){let i=e.indexOf("*/",o+2);o=i===-1?e.length:i+1,t+=" ";continue}(r==='"'||r==="'")&&(n=r),t+=r}return t}function Be(e){e=Mt(e);let t=e.indexOf(":");if(t===-1)return null;let n=e.slice(0,t).trim(),o=e.slice(t+1).trim(),r=/!\s*important\s*$/i.exec(o);return r&&(o=o.slice(0,r.index).trim()),{name:n,value:o,important:!!r}}function K(e,t){if(e==null)return null;let n=null;for(let o of Ve(String(e))){let r=Be(o);!r||r.name!==t||(!n||r.important||!n.important)&&(n=r)}return n?n.value:null}function ze(e,t,n){let o=e==null?"":String(e),r=n==null||n==="",i=Ve(o),s=i.map(Be),c=s.some(d=>d&&d.name===t&&d.important),l=[],p=!1;i.forEach((d,h)=>{let w=s[h];if(!w||w.name!==t){l.push(d);return}if(r||p)return;let f=/^\s*/.exec(d)[0];l.push(`${f}${t}: ${n}${c?" !important":""}`),p=!0});let u=l.join(";");if(!r&&!p){let d=u.trimEnd();u=d===""?`${t}: ${n}`:`${d}${d.endsWith(";")?" ":"; "}${t}: ${n}`}return u.trim()===""?null:u}function Ee(e,t,n,o){let r=e.attr(t,"style");if((K(r,n)??"")===o)return;let i=ze(r,n,o);i==null?e.removeAttr(t,"style"):e.attr(t,"style",i)}var Fe=/^[a-z][a-z0-9-]*$/,Se=new Map;function be(e,t){if(typeof e!="string"||!Fe.test(e))throw new Error(`hyper-html-api: invalid codec name ${JSON.stringify(e)} (must match ${Fe})`);if(!t||typeof t.read!="function"||typeof t.write!="function"||typeof t.same!="function")throw new Error(`hyper-html-api: codec "${e}" needs read, write and same functions`);Se.set(e,t)}function Re(e){return Se.get(e)??null}function Ce(){return Object.fromEntries(Se)}var It='The @codec(name) rule form needs a rules tag with data-rules-version="2".',Lt="A @codec(name) rule must be the value of a top level key.";function ce(e,t){let n=P(e);return n?{...n,codec:t.codecs[n.name]}:null}function H(e,t={}){let n=t.version??"1",o=t.codecs??{};r(e,0);function r(i,s){if(!(s>L)){if(typeof i=="string"){let c=P(i);if(!c)return;if(n!=="2")throw new C(It);if(s!==1)throw new C(Lt);if(!Object.prototype.hasOwnProperty.call(o,c.name))throw new F(c.name);return}if(Array.isArray(i)){r(i[1],s+1);return}if(i&&typeof i=="object")for(let c of Object.values(i))r(c,s+1)}}}function M(e,t,n,o={}){if(Object.prototype.hasOwnProperty.call(o,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return H(n,o),ke(e,t,n,{depth:0,path:[]},o)}function ke(e,t,n,o,r){if(o.depth>L)throw new $(o.path);if(typeof n=="string")return jt(e,t,n,o,r);if(Array.isArray(n)){let[i,s]=n,c=e.find(t,i,r);return Ke(r,o,c),c.map((l,p)=>ke(e,l,s,{depth:o.depth+1,path:[...o.path,p]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[s,c]of Object.entries(n))i[s]=ke(e,t,c,{depth:o.depth+1,path:[...o.path,s]},r);return i}return null}function jt(e,t,n,o,r){if(n.endsWith("[]")){let u=n.slice(0,-2),d=e.find(t,u,r);return Ke(r,o,d),d.map(h=>e.text(h))}let i=ce(n,r);if(i)return $t(e,t,i,r);if(n.startsWith("@"))return Ne(e,t,n.slice(1));let s=b(n);if(s!==-1){let{selector:u,all:d}=R(n),h=n.slice(s+1),w=u?e.find(t,u,r):[t];return d&&r.allMatches?w.map(f=>Ne(e,f,h)):w.length===0?null:Ne(e,w[0],h)}if(n===".")return e.text(t);let{selector:c,all:l}=R(n),p=e.find(t,c,r);return l&&r.allMatches?p.map(u=>e.text(u)):p.length===0?null:e.text(p[0])}function $t(e,t,{selector:n,codec:o},r){let i=n?e.find(t,n,r):[t];return i.length===0?null:o.read(e,i[0],{query:r.query,view:r.view,region:r.region})}function Ke(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(o){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,o)}}function Ne(e,t,n){if(_(n))return K(e.attr(t,"style"),n);if(re.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o??null}function Xe(e,t,n,o){let r=e.length,i=t.length,s=new Array(r).fill(-1);if(o){let a=new Set;for(let y=0;y<r;y++){let A=o[y];!(A>=0&&A<i)||a.has(A)||(s[y]=A,a.add(A))}}if(r===0||i===0)return s;let c=e.map(a=>Je(a,n)),l=t.map(a=>Je(a,n)),p=new Array(i).fill(!1);for(let a of s)a>=0&&(p[a]=!0);let u=new Map;l.forEach((a,y)=>{p[y]||u.set(a,u.has(a)?-1:y)});let d=new Map;c.forEach((a,y)=>{s[y]>=0||d.set(a,(d.get(a)||0)+1)}),c.forEach((a,y)=>{if(s[y]>=0||d.get(a)!==1)return;let A=u.get(a);A===void 0||A===-1||p[A]||(s[y]=A,p[A]=!0)});let h=[];for(let a=0;a<r;a++)s[a]<0&&h.push(a);let w=[];for(let a=0;a<i;a++)p[a]||w.push(a);if(h.length===0||w.length===0)return s;let f=r*i+1,m=_t(e,t,n),g=(a,y)=>m(a,y)*f+Math.abs(a-y);for(let[a,y]of Dt(h,w,g))s[a]=y;return s}var Ge=e=>typeof e=="object"&&e!==null;function Je(e,t){if(!Ge(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(o=>{let r=JSON.stringify(e?.[o]);return r===void 0?" undef":r}))}function _t(e,t,n){if(!Ge(n))return(c,l)=>e[c]===t[l]?0:1;let o=Object.keys(n),r=c=>o.map(l=>JSON.stringify(c?.[l])),i=e.map(r),s=t.map(r);return(c,l)=>{let p=i[c],u=s[l],d=0;for(let h=0;h<o.length;h++)p[h]!==u[h]&&d++;return d}}function Dt(e,t,n){return e.length<=t.length?Ye(e,t,n,!1):Ye(t,e,(o,r)=>n(r,o),!0)}function Ye(e,t,n,o){let r=e.length,i=t.length,s=[];for(let d=0;d<=r;d++)s.push(new Float64Array(i+1).fill(1/0));let c=[];for(let d=0;d<=r;d++)c.push(new Uint8Array(i+1));for(let d=0;d<=i;d++)s[r][d]=0;for(let d=r-1;d>=0;d--)for(let h=i-1;h>=0;h--){let w=n(e[d],t[h])+s[d+1][h+1],f=s[d][h+1];w<=f?(s[d][h]=w,c[d][h]=1):s[d][h]=f}let l=[],p=0,u=0;for(;p<r&&u<i;)c[p][u]&&(l.push(o?[t[u],e[p]]:[e[p],t[u]]),p++),u++;return l}function Me(e,t,n,o,r,i,s,c={}){let l=e.find(t,n,c);if(r.length===0){l.forEach(T=>e.remove(T)),Pe(c,"onRowsApplied",i.path,[]);return}let p=r.length>l.length,u=l[0]||null;if(p&&!u&&(u=Ht(e,t,n,c),!u))throw new I(i.path);let d=l.map(T=>Wt(e,T,o,c)),h=null;if(p&&u){h=e.clone(u);let T=c.templateAttr&&e.attr(u,c.templateAttr)!=null;c.templateAttr&&e.removeAttr(h,c.templateAttr),T&&e.removeAttr(h,"hidden");let O=e.stripIds(h);O>0&&console.warn(`[hyper-html-api] stripped ${O} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let w=Xe(r,d,o,vt(e,l,r,i,c)),f=l.length>0?e.parent(l[0]):zt(e,t,n,u,i,c),m=l.length>0?nt(e,f,l[0]):0,g=Jt(e,l),a=new Set,y=[],A=r.map((T,O)=>{let E=w[O];if(E>=0)return a.add(E),y.push(!1),l[E];y.push(!0);let x=e.clone(h);return e.stripIds(x),x});l.forEach((T,O)=>{a.has(O)||e.remove(T)}),g?Kt(e,f,m,A,y):Yt(e,A,y,f,m),Ut(e,A,o,r,i,s,c),Pe(c,"onRowsApplied",i.path,A)}function Pe(e,t,n,o){if(typeof e[t]=="function")try{return e[t](n.slice(),o)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function vt(e,t,n,o,r){let i=Pe(r,"identifyRows",o.path,n);if(!Array.isArray(i))return null;let s=new Array(n.length).fill(-1),c=new Set,l=new Map(t.map((p,u)=>[e.identity(p),u]));for(let p=0;p<n.length;p++){if(!i[p])continue;let u=l.get(e.identity(i[p]));u===void 0||c.has(u)||(s[p]=u,c.add(u))}return s}function Ut(e,t,n,o,r,i,s){t.forEach((c,l)=>{if(n===null){let p=o[l],u=p==null?"":String(p);e.text(c)!==u&&e.text(c,u)}else{let p=i(e,c,n,o[l],{depth:r.depth+1,path:[...r.path,l]},s);p&&p!==c&&(t[l]=p)}})}function Wt(e,t,n,o){return n===null?e.text(t):M(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function nt(e,t,n){let o=e.children(t);for(let r=0;r<o.length;r++)if(e.sameNode(o[r],n))return r;return-1}function Ht(e,t,n,o){if(!o.templateAttr)return null;let r=/^\s*:scope\s*>\s*/.test(n),i=new RegExp(":not\\(\\["+o.templateAttr.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")+"\\]\\)","g"),s=n.replace(/^\s*:scope\s*>\s*/,"").replace(i,""),c=r?qt(s):0,l=Oe(s),p=t;for(;p;){let u=e.find(p,s,{includeRulesTag:!1,templateAttr:null});for(let d of u)if(e.attr(d,o.templateAttr)!=null&&!(r&&!Bt(e,t,d,c))&&!(l&&!e.matches(e.parent(d),l)))return d;p=e.parent(p)}return null}function qt(e){let t=0,n=null,o=1;for(let r=0;r<e.length;r++){let i=e[r];if(i==="\\")r++;else if(n)i===n&&(n=null);else if(i==='"'||i==="'")n=i;else if(i==="["||i==="(")t++;else if(i==="]"||i===")")t>0&&t--;else if(t===0&&i===">")o++;else{if(t===0&&(i==="+"||i==="~"))return null;if(t===0&&/\s/.test(i)){if(!Vt(e,r))return null;for(;r+1<e.length&&/\s/.test(e[r+1]);)r++}}}return o}function Vt(e,t){let n=t;for(;n<e.length&&/\s/.test(e[n]);)n++;let o=t>0?e[t-1]:"",r=n<e.length?e[n]:"";return Ze(o)||Ze(r)}function Ze(e){return e===">"||e==="+"||e==="~"}function Bt(e,t,n,o){if(o===null)return!0;let r=n;for(let l=0;l<o;l++)if(r=e.parent(r),!r)return!1;let i=e.prop(t,"tagName");if(!i)return!0;let s=e.prop(r,"tagName");if(!s||String(s).toLowerCase()!==String(i).toLowerCase())return!1;let c=new Set(Qe(e,r));return Qe(e,t).every(l=>c.has(l))}function Qe(e,t){let n=e.attr(t,"class");return n?String(n).split(/\s+/).filter(Boolean):[]}function zt(e,t,n,o,r,i){let s=e.parent(o);if(s&&Ft(e,t,s)&&!tt(e,s,i))return s;let c=Oe(n);if(!c)throw new I(r.path,`the list selector "${n}" 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 p=(c===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,c,i)).filter(u=>!tt(e,u,i));if(p.length===0)throw new I(r.path,`no container matching "${c}" inside this context to hold the new rows`);if(p.length>1)throw new I(r.path,`"${c}" matches ${p.length} containers inside this context, so the new rows have no single destination`);return p[0]}function Ft(e,t,n){let o=n;for(;o;){if(e.sameNode(o,t))return!0;o=e.parent(o)}return e.parent(t)?!1:e.find(t,"*",{includeRulesTag:!0,templateAttr:null}).some(r=>e.sameNode(r,n))}var et=["no-data","editor-ui"];function tt(e,t,n){let o=t;for(;o;){if(n.templateAttr&&e.attr(o,n.templateAttr)!=null||et.some(i=>e.attr(o,i)!=null))return!0;let r=e.attr(o,"clay");if(r&&r.split(/\s+/).some(i=>et.includes(i)))return!0;o=e.parent(o)}return!1}function Kt(e,t,n,o,r){let i=e.children(t),s=i.map(l=>e.identity(l)),c=!1;o.forEach((l,p)=>{let u=e.identity(l),d=n+p;if(s[d]===u)return;if(!r[p]){let w=s.indexOf(u);w!==-1&&(s.splice(w,1),i.splice(w,1))}let h=Math.min(d,i.length);h<i.length?e.insertBefore(i[h],l):i.length?c?e.insertAfter(i[i.length-1],l):(e.insertAt(t,l,d),c=!0):e.insertAt(t,l,0),s.splice(h,0,u),i.splice(h,0,l)})}function Jt(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let o=new Map(e.children(n).map((i,s)=>[e.identity(i),s])),r=[];for(let i of t){let s=o.get(e.identity(i));if(s===void 0)return!1;r.push(s)}return r.sort((i,s)=>i-s),r[r.length-1]-r[0]===r.length-1}function Yt(e,t,n,o,r){let i=null,s=r;for(let c=0;c<t.length;c++){if(!n[c]){i=t[c];continue}let l=i?e.parent(i):o;if(!l)continue;let p=i?nt(e,l,i)+1:s++;e.insertAt(l,t[c],p),i=t[c]}}function D(e,t,n,o,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");H(n,r);let i=[];if(Ie(n,o,[],i),i.length)throw new B(i);le(e,t,n,o,{depth:0,path:[]},r)}function le(e,t,n,o,r,i={}){if(r.depth>L)throw new $(r.path);if(o===void 0)return t;if(typeof n=="string")return Xt(e,t,n,o,r,i);if(Array.isArray(n)){let[s,c]=n;return Me(e,t,s,c,o,r,le,i),t}if(typeof n=="object"&&n!==null){for(let[s,c]of Object.entries(n)){let l=le(e,t,c,o==null?o:o[s],{depth:r.depth+1,path:[...r.path,s]},i);l&&l!==t&&(t=l)}return t}return t}function Xt(e,t,n,o,r,i){if(n.endsWith("[]")){let d=n.slice(0,-2);return Me(e,t,d,null,o,r,le,i),t}let s=ce(n,i);if(s){let d=s.selector?e.find(t,s.selector,i):[t];return d.length&&s.codec.write(e,d[0],o,{query:i.query}),t}if(n.startsWith("@"))return ot(e,t,n.slice(1),o);let c=b(n);if(c!==-1){let{selector:d,all:h}=R(n),w=n.slice(c+1),f=d?e.find(t,d,i):[t];for(let m of h?f:f.slice(0,1))ot(e,m,w,o);return t}if(n===".")return rt(e,t,o),t;let{selector:l,all:p}=R(n),u=e.find(t,l,i);for(let d of p?u:u.slice(0,1))rt(e,d,o);return t}function rt(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function Gt(e,t,n,o){if(e.styleVar){e.styleVar(t,n,o);return}Ee(e,t,n,o)}function ot(e,t,n,o){if(_(n))return Gt(e,t,n,o==null?"":String(o).trim()),t;if(W.has(n)){let r=e.prop(t,n);if(r===o||r!=null&&o!=null&&String(r)===String(o))return t;throw new z(n)}if(n==="outerHTML"){let r=o==null?"":String(o);return e.replaceWith(t,r)}if(ge.has(n)){let r=Ae(n,o);return e.prop(t,n)!==r&&e.prop(t,n,r),t}if(o==null)e.attr(t,n)!=null&&e.removeAttr(t,n);else{let r=String(o);e.attr(t,n)!==r&&e.attr(t,n,r)}return t}function Ie(e,t,n,o){if(t!==void 0){if(typeof e=="string"){if(P(e))return;if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,i)=>{typeof r=="object"&&r!==null&&o.push({path:Y([...n,i]),expected:"scalar",got:J(r)})}):o.push({path:Y(n),expected:"array",got:J(t)});return}t!==null&&typeof t=="object"&&o.push({path:Y(n),expected:"scalar",got:J(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:Y(n),expected:"array",got:J(t)});return}let r=e[1];t.forEach((i,s)=>Ie(r,i,[...n,s],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:Y(n),expected:"object",got:J(t)});return}for(let[r,i]of Object.entries(e))Ie(i,t[r],[...n,r],o)}}}function J(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function Y(e){return e.join(".")}function Le(e){try{return JSON.parse(e)}catch(t){throw new C(`Invalid strict JSON: ${t.message}`,t)}}function v(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 n(r){let i=[],s=0;for(;s<r.length;){let c=r[s];if(/\s/.test(c)){s++;continue}if("{}".includes(c)){i.push({type:c,value:c}),s++;continue}if(c==="["){let d=!1,h=s+1;for(;h<r.length&&/\s/.test(r[h]);)h++;if(h<r.length&&/[a-zA-Z_]/.test(r[h])&&(d=!0),!d){i.push({type:c,value:c}),s++;continue}}if(c==="]"){i.push({type:c,value:c}),s++;continue}if(c===":"){i.push({type:t.COLON,value:c}),s++;continue}if(c===","){i.push({type:t.COMMA,value:c}),s++;continue}if(c==='"'||c==="'"){let d=c,h=s+1;for(;h<r.length&&r[h]!==d;)r[h]==="\\"&&h++,h++;i.push({type:t.STRING,value:r.substring(s+1,h),quoted:!0,sourceQuote:d}),s=h+1;continue}let l=s,p;for(;l<r.length&&!/[{},]/.test(r[l]);)if(r[l]===":"){let d=[":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"],h=!1;for(let w of d){let f=w.substring(1);if(r.substring(l+1,l+1+f.length)===f){h=!0,l+=f.length;break}}if(!h)break}else if(r[l]==="["){for(l++;l<r.length&&r[l]!=="]";){if(r[l]==='"'||r[l]==="'"){let d=r[l];for(l++;l<r.length&&r[l]!==d;)r[l]==="\\"&&l++,l++}l++}l<r.length&&r[l]==="]"&&l++}else l++;p=r.substring(s,l);let u=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(p)?u=t.NUMBER:p==="true"||p==="false"||p==="null"?u=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(p)&&(u=t.SELECTOR),i.push({type:u,value:p,quoted:!1}),s=l}return i}function o(r){let i="";for(let s=0;s<r.length;s++){let c=r[s];if("{}".includes(c.type)||"[]".includes(c.type)){i+=c.value;continue}if(c.type===t.COLON){i+=c.value;continue}if(c.type===t.COMMA){let l=r[s+1];if(l&&(l.type==="}"||l.type==="]"))continue;i+=c.value;continue}if(c.type===t.STRING&&c.quoted){let l=c.value;c.sourceQuote==="'"&&(l=l.replace(/\\'/g,"'"),l=l.replace(/(\\*)"/g,(p,u)=>u.length%2===0?u+'\\"':p)),i+=`"${l}"`;continue}if(c.type===t.NUMBER||c.type===t.BOOLEAN){i+=c.value;continue}if(c.type===t.SELECTOR||c.type===t.IDENTIFIER){i+=`"${c.value}"`;continue}i+=`"${c.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new C("Invalid extraction rules syntax: "+r.message,r)}}var fe=["1","2"],it=/^[a-zA-Z0-9_-]+$/;function X(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!it.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${it})`);o=`script[data-rules-name~="${n}"]`}let r=e.find(t,o,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let i=r[0],s=e.attr(i,"data-rules-version");if(!fe.includes(s))throw new j(s);return{rules:v(e.text(i)),tagNode:i,version:s}}var ue=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"]})}),Zt=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),st=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);function G(e,t){if(!e||e.nodeType!==1)return!1;let n=e.getAttribute?.("clay");return!!(n&&n.split(/\s+/).includes(t)||e.hasAttribute?.(t))}function je(e,t){if(G(e,t))return!0;for(let[n,o]of Object.entries(Zt))if(o.includes(t)&&G(e,n))return!0;return!1}function Z(e){let t=ue[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function Qt(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let o=ue[t];if(!o)throw new Error(`Unknown region capability: ${t}`);if(o.tokens.some(r=>je(n,r))||o.bundles.some(r=>G(n,r)))return n;n=n.parentElement}return null}function ct(e,t){return!!Qt(e,t)}var en=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",...st],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 $e(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null,version:"1"};if(typeof n=="string"){let o=t&&t.ownerDocument?t.ownerDocument:t;return X(e,o,n)}return null}var on=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function sn(e,t){if(!/^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(e.tagName||""))return;let n=(e.getAttribute?.("type")||"").toLowerCase();"value"in e&&"value"in t&&e.tagName!=="OPTION"&&n!=="checkbox"&&n!=="radio"&&n!=="file"&&(t.value=e.value),e.tagName==="INPUT"&&(n==="checkbox"||n==="radio")&&(t.checked=e.checked),e.tagName==="OPTION"&&(t.selected=e.selected),"indeterminate"in e&&"indeterminate"in t&&(t.indeterminate=e.indeterminate)}function lt(e,t,n,o){if(o)return!!e.closest?.(t);let r=e;for(;r?.nodeType===1;){if(r.matches(t))return!0;if(r===n)break;r=r.parentElement}return!1}function ft(e,t,n,o,r,i){return(i?ct(e,t):lt(e,n,r,!1))||!!(o&&(i&&e!==r?e.matches(o):lt(e,o,r,i)))}function cn(e,t){let n=ue[t];return n.tokens.some(o=>je(e,o))||n.bundles.some(o=>G(e,o))}var ln=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function ut(e,t,n,o){if(e.nodeType===1&&o(e)){n.dropped.push(t);return}n.cloneToLive.set(t,e),n.liveToClone.set(e,t);let r=e,i=t;if(e.nodeType===1){if(ln.has(e.tagName)&&n.controls.push(e,t),e.tagName==="TEMPLATE"){for(;t.firstChild;)t.removeChild(t.firstChild);r=e.content,i=t.content,n.cloneToLive.set(i,r),n.liveToClone.set(r,i)}}else if(e.nodeType!==11)return;let s=i.firstChild;for(let c=r.firstChild;c&&s;c=c.nextSibling)ut(c,s,n,o),s=s.nextSibling}function Q(e,{capability:t="data",exclude:n=null,inherit:o=!0,provenance:r=null}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let i=e.nodeType===9?e:e.ownerDocument;if(!i?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let s=i.implementation.createHTMLDocument(""),c=r||new WeakMap,l=new WeakMap,p=e.nodeType===9?e.documentElement:e;n&&s.documentElement.matches(n);let u=Z(t),d=o?f=>cn(f,t)||!!(n&&f.matches(n)):f=>ft(f,t,u,n,p,!1),h=null;if(p.nodeType!==1||!ft(p,t,u,n,p,o)){h=s.importNode(p,!0);let f={cloneToLive:c,liveToClone:l,dropped:[],controls:[]};ut(p,h,f,d);for(let m of f.dropped)m.remove();for(let m=0;m<f.controls.length;m+=2)sn(f.controls[m],f.controls[m+1])}e.nodeType===9&&h&&(s.replaceChild(h,s.documentElement),l.set(e,s),c.set(s,e));let w=f=>{if(on.test(f))throw new Error(`Filtered content queries do not support stateful selector: ${f}`)};return{root:h,document:s,capability:t,selector:Z(t),cloneToLive:c,liveToClone:l,original(f){return c.get(f)||null},cloneOf(f){return l.get(f)||null},query(f,m=h){return w(f),Array.from(m.querySelectorAll(f),g=>c.get(g)||g)},text(f=h){return(f===h?h:l.get(f))?.textContent||""},html(f=h){return(f===h?h:l.get(f))?.innerHTML??""},clone(f=h){let m=f===h?h:l.get(f);return m?s.importNode(m,!0):null}}}function dt(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function fn(e){return e?(e.nodeType===9||e.nodeType===11,e):null}function at(e,t,n){!e||e.nodeType!==1||(t==="value"&&e.tagName==="INPUT"?e.value=n===null?"":n:t==="checked"&&e.tagName==="INPUT"?e.checked=n!==null:t==="selected"&&e.tagName==="OPTION"&&(e.selected=n!==null))}function pt(e,t){e&&e.tagName==="TEXTAREA"&&(e.value=t)}function ht(e){if(!e||e.nodeType!==1)return;let t=[e,...e.querySelectorAll?e.querySelectorAll("textarea, input, option"):[]];for(let n of t)if(n.tagName==="TEXTAREA")n.value=n.defaultValue;else if(n.tagName==="INPUT"){let o=n.type;o!=="file"&&o!=="checkbox"&&o!=="radio"&&(n.value=n.defaultValue),n.checked=n.defaultChecked}else n.tagName==="OPTION"&&(n.selected=n.defaultSelected)}var S={semanticExclude:!0,find(e,t,n={}){let o=fn(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(c=>!dt(c)));let i=[];n.skip&&i.push(n.skip);let s=n.templateAttr===null?null:n.templateAttr||"cms-template";if(s&&i.push("["+s+"]"),i.length){let c=i.join(", ");r=r.filter(l=>!l.closest||!l.closest(c))}return r},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,pt(e,t)},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n),at(e,t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),at(e,t,null)},prop(e,t,n){if(n===void 0){let o=e?e[t]:void 0;return o!==void 0?o:null}e[t]=n},clone(e){let t=e.cloneNode(!0);return ht(t),t},insertAt(e,t,n){let o=e.children[n]||null;e.insertBefore(t,o)},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 o=e.ownerDocument.createElement("template");o.innerHTML=t;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function ee(e,t={}){if(t.exclude===null)return S;let n=[Z("data"),t.exclude].filter(Boolean).join(", "),o=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!o?.querySelector?.(n))return S;let i=e.nodeType===9||!e.isConnected?e:e.ownerDocument,s=e.nodeType===9?e:e.ownerDocument,c=null,l=()=>c||(c=Q(i,{capability:"data",exclude:t.exclude||null})),p=f=>{let m=l();return f===e?m.cloneOf(e):m.cloneOf(f)||f},u=f=>c?.original(f)||f,d=(f,m)=>{l().liveToClone.set(f,m),l().cloneToLive.set(m,f);let g=f.childNodes||[],a=m.childNodes||[];for(let y=0;y<Math.min(g.length,a.length);y++)d(g[y],a[y])},h=(f,m,g,a)=>{let y=Array.from(f.childNodes).filter(x=>c.cloneOf(x)),T=y[0];for(;T&&y.includes(T);)T=T.nextSibling;for(let x of y)x.remove();if(g==="innerHTML"){let x=s.createElement("template");x.innerHTML=a;for(let V of Array.from(x.content.childNodes))f.insertBefore(V,T||null)}else f.insertBefore(s.createTextNode(a),T||null),pt(f,a);let O=Q(f,{capability:"data",exclude:t.exclude||null});m.replaceChildren(...Array.from(O.root?.childNodes||[]));let E=x=>{let V=O.original(x);V&&(c.liveToClone.set(V,x),c.cloneToLive.set(x,V));for(let St of Array.from(x.childNodes||[]))E(St)};for(let x of Array.from(m.childNodes))E(x)},w={...S,find(f,m,g={}){let a=p(f);if(!a?.querySelectorAll)return[];let y=l().query(m,a);g.includeRulesTag||(y=y.filter(O=>!dt(O)));let A=[];g.skip&&A.push(g.skip);let T=g.templateAttr===null?null:g.templateAttr||"cms-template";if(T&&A.push(`[${T}]`),A.length){let O=A.join(", ");y=y.filter(E=>!E.closest?.(O))}return y},parent(f){let m=p(f)?.parentElement;return m?u(m):null},children(f){return Array.from(p(f)?.children||[],u)},text(f,m){if(m===void 0){let y=u(f);return!y?.matches?.(n)&&!y?.querySelector?.(n)?S.text(y):(p(f)?.textContent||"").trim()}let g=u(f);if(!g?.matches?.(n)&&!g?.querySelector?.(n)&&!c){S.text(g,m);return}let a=l().cloneOf(g);a?h(g,a,"textContent",m):S.text(g,m)},attr(f,m,g){let a=u(f);if(g===void 0)return S.attr(a,m);S.attr(a,m,g);let y=c?.cloneOf(a);y&&(S.attr(y,m,g),Q(a,{capability:"data",exclude:t.exclude||null}).root===null&&(y.remove(),c.liveToClone.delete(a),c.cloneToLive.delete(y)))},removeAttr(f,m){let g=u(f);S.removeAttr(g,m);let a=c?.cloneOf(g);a&&S.removeAttr(a,m)},prop(f,m,g){let a=u(f);if(g===void 0)return m==="innerHTML"||m==="outerHTML"||m==="textContent"||m==="innerText"?S.prop(p(a),m):S.prop(a,m);let y=m==="innerHTML"||m==="textContent"||m==="innerText",A=y?l().cloneOf(a):c?.cloneOf(a);A&&y?h(a,A,m,g):(S.prop(a,m,g),A&&S.prop(A,m,g))},clone(f){let m=p(f);if(m===f)return S.clone(f);let g=s.importNode(m,!0);return ht(g),g},insertAt(f,m,g){let a=u(f),A=w.children(a)[g]||(()=>{for(let E=a.children.length-1;E>=0;E--){let x=a.children[E];if(l().cloneOf(x))return x.nextElementSibling}return a.firstElementChild})(),T=u(m);a.insertBefore(T,A||null);let O=l().cloneOf(a);if(O){let E=l().cloneOf(T);E||(E=s.importNode(T,!0),d(T,E));let x=Array.from(O.children);O.insertBefore(E,x[g]||null)}},insertBefore(f,m){let g=u(f),a=u(m);g.parentNode.insertBefore(a,g);let y=l().cloneOf(g.parentNode);if(y){let A=l().cloneOf(a);A||(A=s.importNode(a,!0),d(a,A));let T=l().cloneOf(g);T?T.before(A):y.appendChild(A)}},insertAfter(f,m){let g=u(f),a=u(m);g.parentNode.insertBefore(a,g.nextSibling);let y=l().cloneOf(g.parentNode);if(y){let A=l().cloneOf(a);A||(A=s.importNode(a,!0),d(a,A));let T=l().cloneOf(g);T?T.after(A):y.appendChild(A)}},identity(f){return u(f)||null},remove(f){let m=u(f),g=l().cloneOf(m);S.remove(m),g&&S.remove(g)},replaceWith(f,m){let g=u(f),a=l().cloneOf(g),y=S.replaceWith(g,m);if(a){let A=Q(y,{capability:"data",exclude:t.exclude||null});if(!A.root)a.remove();else{a.replaceWith(A.root);let T=O=>{let E=A.original(O);E&&(c.liveToClone.set(E,O),c.cloneToLive.set(O,E));for(let x of Array.from(O.childNodes||[]))T(x)};T(A.root)}}return y}};return w}var N=S;var _e=e=>({codecs:Ce(),...e}),mt={extract:(e,t,n={})=>M(ee(e,n),e,t,_e(n)),apply:(e,t,n,o={})=>D(ee(e,{...o,_write:!0}),e,t,n,_e(o)),findRulesIn:(e,t)=>X(N,e,t),findRules:(e,t)=>$e(N,e,t),bind:(e,t,n={})=>{let o=$e(N,e,t);if(!o){let i=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${i}`)}let r=_e({version:o.version,...n});return{...o,get:()=>M(ee(e,n),e,o.rules,r),set:i=>D(ee(e,{...n,_write:!0}),e,o.rules,i,r)}},codecs:{register:be,get:Re},parseStrict:Le,parseRelaxed:v,ruleAttrIndex:b,splitRule:R,errors:se,DOM_PROPERTIES:ne};var un="hha:upgrade-check:";function k(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function De(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function yt(e,t){let n=De(e),o=De(t);if(!n||!o)return!1;let r=Math.max(n.length,o.length);for(let i=0;i<r;i++){let s=n[i]||0,c=o[i]||0;if(s!==c)return s>c}return!1}function an(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function dn(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function gt({force:e=!1,doc:t,loc:n,fetchFn:o,now:r,ttlMs:i=864e5}={}){if(t=t||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(h=>fetch(h)),r=r??Date.now(),!t)return null;let s=k(t,"hyper-source");if(!s)return null;let c=k(t,"hyper-version"),l;try{l=new URL(s,n?n.href:void 0)}catch{return null}if(n&&l.origin===n.origin&&l.pathname===n.pathname)return null;let p=`${un}${l.href}:${c||"none"}`,u,d=e?null:an(p);if(d&&typeof d.checkedAt=="number"&&r-d.checkedAt<i)u=d.sourceVersion;else{try{let h=await o(l.href);if(!h.ok)throw new Error(`HTTP ${h.status}`);let w=await h.text(),f=new DOMParser().parseFromString(w,"text/html");u=k(f,"hyper-version")}catch{u=null}dn(p,{checkedAt:r,sourceVersion:u})}return u?{available:yt(u,c||"0.0.0"),currentVersion:c,sourceVersion:u,sourceUrl:l.href}:null}var pn="script[data-rules-name]";function hn(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function ae(e,t){let n=e.find(t,pn,{includeRulesTag:!0}),o=new Set,r=[];for(let i of n){let s=hn(e.attr(i,"data-rules-name"));if(!s)continue;if(o.has(s)){console.warn(`hyper-html-api: duplicate rules tag name "${s}"; using the first.`);continue}let c=e.attr(i,"data-rules-version");if(!fe.includes(c))throw new j(c);o.add(s),r.push({name:s,rules:v(e.text(i)),version:c})}return r}function de(e,t){if(t!=="2"||!e||typeof e!="object"||Array.isArray(e))return{rules:e,carried:[]};let n={},o=[];for(let[r,i]of Object.entries(e)){let s=P(i);s?o.push({key:r,selector:s.selector}):n[r]=i}return{rules:n,carried:o}}function pe(e,t,n){return e.find(t,n)[0]||null}function ve(e,t){let n={};for(let{name:o,rules:r,version:i}of ae(e,t)){let{rules:s,carried:c}=de(r,i),l=M(e,t,s,{version:i});for(let{key:p,selector:u}of c){let d=pe(e,t,u);l[p]=d?e.prop(d,"innerHTML"):null}n[o]=l}return n}function At(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:ve(N,t),version:k(n,"hyper-version")}}var te=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},he=class extends Error{constructor(t){super(`upgrade source has no rules tags; refusing to drop all existing data: ${t}`),this.name="UpgradeSourceHasNoRules",this.sourceUrl=t}},U=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},me=class extends Error{constructor(t){super(`found ${t} script[type="text/hyper-upgrade"] tags; only one is allowed per document.`),this.name="UpgradeMultipleTransforms",this.count=t}};var mn="text/hyper-upgrade";function wt(e,t){let n=e.find(t,`script[type="${mn}"]`);if(n.length===0)return null;if(n.length>1)throw new me(n.length);return e.text(n[0])||null}var yn=new Function("url","return import(url)");async function Tt(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await yn(n)}catch(r){throw new U(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new U("transform must `export default` a function");return o.default}function ye(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=Ue(t,e,n);return We(t,e,n),{data:o,summary:n}}function Ue(e,t,n,o=!1){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(n.listItems+=t.length,n.carriedOver+=t.length,t):o?[]:void 0:t==null||typeof t=="object"?o&&!gn(e)?null:void 0:(n.carriedOver++,t);if(Array.isArray(e)){let[,r]=e;return Array.isArray(t)?(n.listItems+=t.length,t.map(i=>Ue(r,i,n,!0))):o?[]:void 0}if(typeof e=="object"&&e!==null){let r={};for(let[i,s]of Object.entries(e)){let c=Ue(s,t?.[i],n,o);c!==void 0&&(r[i]=c)}return r}}function gn(e){let t=b(e);return t!==-1&&W.has(e.slice(t+1))}function We(e,t,n){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let o=new Set(Object.keys(e));for(let r of Object.keys(t))o.has(r)?We(e[r],t[r],n):n.discarded+=q(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>We(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=q(t))}}function q(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+q(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+q(n),0):1}function xt(e,t,n){let o=ae(e,t),r={carriedOver:0,discarded:0,listItems:0},i={},s=new Set;for(let{name:c,rules:l,version:p}of o){if(s.add(c),!Object.prototype.hasOwnProperty.call(n,c)){i[c]={carriedOver:0,discarded:0,listItems:0};continue}let{rules:u,carried:d}=de(l,p),h=n[c],{data:w,summary:f}=ye(An(h,d),u);D(e,t,u,w,{templateAttr:"cms-template"});for(let{key:m,selector:g}of d){let a=Ot(h)?h[m]:void 0;if(a==null)continue;let y=pe(e,t,g);typeof a=="string"&&y?(e.prop(y,"innerHTML",a),f.carriedOver+=1):f.discarded+=1}i[c]=f,r.carriedOver+=f.carriedOver,r.discarded+=f.discarded,r.listItems+=f.listItems}for(let c of Object.keys(n))s.has(c)||(r.discarded+=q(n[c]));return{totals:r,byName:i,rulesTagCount:o.length}}function Ot(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function An(e,t){if(!t.length||!Ot(e))return e;let n={...e};for(let{key:o}of t)delete n[o];return n}async function Et({sourceUrl:e,dataByName:t,fromVersion:n,doc:o,loc:r,fetchFn:i}={}){if(o=o||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),i=i||(a=>fetch(a)),!o)throw new Error("upgrade.run requires a document context");if(e=e||k(o,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let s=new URL(e,r?r.href:void 0);n=n!==void 0?n:k(o,"hyper-version"),t=t||ve(N,o);let c;try{c=await i(s.href)}catch(a){throw new te(s.href,a)}if(!c.ok)throw new te(s.href,new Error(`HTTP ${c.status}`));let l=await c.text(),p=new DOMParser().parseFromString(l,"text/html"),u=k(p,"hyper-version"),d=t,h=!1,w=wt(N,p);if(w){let y=await(await Tt(w))(d,{fromVersion:n,toVersion:u});if(!y||typeof y!="object"||Array.isArray(y))throw new U("transform must return a plain object map of { rulesName: data }");d=y,h=!0}let{totals:f,byName:m,rulesTagCount:g}=xt(N,p,d);if(g===0&&Object.keys(d).length>0)throw new he(s.href);return{html:Tn(p),fromVersion:n,toVersion:u,summary:{transformApplied:h,totals:f,byName:m}}}function wn(e){for(let t of e.querySelectorAll("input")){let n=(t.getAttribute("type")||"").toLowerCase();n!=="file"&&(n==="checkbox"||n==="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 n=[...t.options];if(!t.multiple){let o=n.findIndex(r=>r.hasAttribute("selected"));if(t.selectedIndex===o||o===-1&&t.selectedIndex<=0)continue}for(let o of n)o.selected!==o.hasAttribute("selected")&&o.toggleAttribute("selected",o.selected)}}function Tn(e){return wn(e),`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
5
+ `+e.documentElement.outerHTML}var xn={checkForUpdate:gt,run:Et,extractAll:At,shapeMatch:ye};var On={engine:mt,upgrade:xn},En=On;export{En as default,mt as engine,yt as isNewerVersion,De as parseVersion,k as readMeta,xn as upgrade};