@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,10 +1,10 @@
1
1
  /* richclay self-contained vendor build (bundles Squire + DOMPurify) for hyperclayjs. Generated; do not edit. */
2
- var richclay=(()=>{var kn=Object.defineProperty;var ds=Object.getOwnPropertyDescriptor;var fs=Object.getOwnPropertyNames;var ps=Object.prototype.hasOwnProperty;var ms=(e,t)=>{for(var n in t)kn(e,n,{get:t[n],enumerable:!0})},gs=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of fs(t))!ps.call(e,r)&&r!==n&&kn(e,r,{get:()=>t[r],enumerable:!(i=ds(t,r))||i.enumerable});return e};var ys=e=>gs(kn({},"__esModule",{value:!0}),e);var Wl={};ms(Wl,{RichClay:()=>$e,default:()=>ql,stopAutoWatch:()=>zl});var bs=()=>!0,re=class{constructor(e,t,n){this.root=e,this.currentNode=e,this.nodeType=t,this.filter=n||bs}isAcceptableNode(e){let t=e.nodeType;return!!((t===Node.ELEMENT_NODE?1:t===Node.TEXT_NODE?4:0)&this.nodeType)&&this.filter(e)}nextNode(){let e=this.root,t=this.currentNode,n;for(;;){for(n=t.firstChild;!n&&t&&t!==e;)n=t.nextSibling,n||(t=t.parentNode);if(!n)return null;if(this.isAcceptableNode(n))return this.currentNode=n,n;t=n}}previousNode(){let e=this.root,t=this.currentNode,n;for(;;){if(t===e)return null;if(n=t.previousSibling,n)for(;t=n.lastChild;)n=t;else n=t.parentNode;if(!n)return null;if(this.isAcceptableNode(n))return this.currentNode=n,n;t=n}}previousPONode(){let e=this.root,t=this.currentNode,n;for(;;){for(n=t.lastChild;!n&&t&&t!==e;)n=t.previousSibling,n||(t=t.parentNode);if(!n)return null;if(this.isAcceptableNode(n))return this.currentNode=n,n;t=n}}},ze=navigator.userAgent,Un=/Mac OS X/.test(ze),ar=/Windows NT/.test(ze),lr=/iP(?:ad|hone|od)/.test(ze)||Un&&!!navigator.maxTouchPoints,Kl=/Android/.test(ze),Ts=/Gecko\//.test(ze),zt=/Edge\//.test(ze),_s=!zt&&/WebKit\//.test(ze),te=Un||lr?"Meta-":"Ctrl-",qt=_s,Es="onbeforeinput"in document&&"inputType"in new InputEvent("input"),me=/[^ \t\r\n\u200B]/,vs=/^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:FRAME|MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|TIME|U|VAR|WBR)$/,Ss=new Set(["BR","HR","IFRAME","IMG","INPUT"]),As=0,In=1,cr=2,hr=3,Ut=new WeakMap,ur=()=>{Ut=new WeakMap},ke=e=>Ss.has(e.nodeName),zn=e=>{switch(e.nodeType){case 8:case 3:return In;case 1:case 11:if(Ut.has(e))return Ut.get(e);break;default:return As}let t;return Array.from(e.childNodes).every(L)?vs.test(e.nodeName)?t=In:t=cr:t=hr,Ut.set(e,t),t},L=e=>zn(e)===In,xe=e=>zn(e)===cr,Qe=e=>zn(e)===hr,_=(e,t,n)=>{let i=document.createElement(e);if(t instanceof Array&&(n=t,t=null),t)for(let r in t){let o=t[r];o!==void 0&&i.setAttribute(r,o)}return n&&n.forEach(r=>i.appendChild(r)),i},dr=(e,t)=>ke(e)||e.nodeType!==t.nodeType||e.nodeName!==t.nodeName?!1:e instanceof HTMLElement&&t instanceof HTMLElement?e.nodeName!=="A"&&e.className===t.className&&e.style.cssText===t.style.cssText:!0,Mn=(e,t,n)=>{if(e.nodeName!==t)return!1;for(let i in n)if(!("getAttribute"in e)||e.getAttribute(i)!==n[i])return!1;return!0},w=(e,t,n,i)=>{for(;e&&e!==t;){if(Mn(e,n,i))return e;e=e.parentNode}return null},qn=(e,t)=>{let n=e.childNodes;for(;t&&e instanceof Element;)e=n[t-1],n=e.childNodes,t=n.length;return e},fr=(e,t)=>{let n=e;if(n instanceof Element){let i=n.childNodes;if(t<i.length)n=i[t];else{for(;n&&!n.nextSibling;)n=n.parentNode;n&&(n=n.nextSibling)}}return n},se=e=>e instanceof Element||e instanceof DocumentFragment?e.childNodes.length:e instanceof CharacterData?e.length:0,D=e=>{let t=document.createDocumentFragment(),n=e.firstChild;for(;n;)t.appendChild(n),n=e.firstChild;return t},W=e=>{let t=e.parentNode;return t&&t.removeChild(e),e},Y=(e,t)=>{let n=e.parentNode;n&&n.replaceChild(t,e)},Cs=e=>e instanceof Element?e.nodeName==="BR":me.test(e.data),$t=(e,t)=>{let n=e.parentNode;for(;L(n);)n=n.parentNode;let i=new re(n,5,Cs);return i.currentNode=e,!!i.nextNode()||t&&!i.previousNode()},Ht=(e,t)=>{let n=new re(e,4),i,r;for(;i=n.nextNode();)for(;(r=i.data.indexOf("\u200B"))>-1&&(!t||i.parentNode!==t);)if(i.length===1){let o=i,s=o.parentNode;for(;s&&(s.removeChild(o),n.currentNode=s,!(!L(s)||se(s)));)o=s,s=o.parentNode;break}else i.deleteData(r,1)},Ls=0,ws=1,Ns=2,xs=3,Ne=(e,t,n)=>{let i=document.createRange();if(i.selectNode(t),n){let r=e.compareBoundaryPoints(xs,i)>-1,o=e.compareBoundaryPoints(ws,i)<1;return!r&&!o}else{let r=e.compareBoundaryPoints(Ls,i)<1,o=e.compareBoundaryPoints(Ns,i)>-1;return r&&o}},X=e=>{let{startContainer:t,startOffset:n,endContainer:i,endOffset:r}=e;for(;!(t instanceof Text);){let o=t.childNodes[n];if(!o||ke(o)){if(n&&(o=t.childNodes[n-1],o instanceof Text)){let s=o,a;for(;!s.length&&(a=s.previousSibling)&&a instanceof Text;)s.remove(),s=a;t=s,n=s.data.length}break}t=o,n=0}if(r)for(;!(i instanceof Text);){let o=i.childNodes[r-1];if(!o||ke(o)){if(o&&o.nodeName==="BR"&&!$t(o,!1)){r-=1;continue}break}i=o,r=se(i)}else for(;!(i instanceof Text);){let o=i.firstChild;if(!o||ke(o))break;i=o}e.setStart(t,n),e.setEnd(i,r)},He=(e,t,n,i)=>{let r=e.startContainer,o=e.startOffset,s=e.endContainer,a=e.endOffset,l;for(t||(t=e.commonAncestorContainer),n||(n=t);!o&&r!==t&&r!==i;)l=r.parentNode,o=Array.from(l.childNodes).indexOf(r),r=l;for(;!(s===n||s===i||(s.nodeType!==3&&s.childNodes[a]&&s.childNodes[a].nodeName==="BR"&&!$t(s.childNodes[a],!1)&&(a+=1),a!==se(s)));)l=s.parentNode,a=Array.from(l.childNodes).indexOf(s)+1,s=l;e.setStart(r,o),e.setEnd(s,a)},Ji=(e,t,n)=>{let i=w(e.endContainer,n,t);if(i&&(i=i.parentNode)){let r=e.cloneRange();He(r,i,i,n),r.endContainer===i&&(e.setStart(r.endContainer,r.endOffset),e.setEnd(r.endContainer,r.endOffset))}return e},$=e=>{let t=null;if(e instanceof Text)return e;if(L(e)){let n=e.firstChild;if(qt)for(;n&&n instanceof Text&&!n.data;)e.removeChild(n),n=e.firstChild;n||(qt?t=document.createTextNode("\u200B"):t=document.createTextNode(""))}else if((e instanceof Element||e instanceof DocumentFragment)&&!e.querySelector("BR")&&!me.test(e.textContent||"")){t=_("BR");let n=e,i;for(;(i=n.lastElementChild)&&!L(i);)n=i;e=n,e instanceof HTMLElement&&e.contentEditable==="true"&&(e=_("DIV"),n.appendChild(e))}if(t)try{e.appendChild(t)}catch{}return e},ge=(e,t)=>{let n=null;return/^(?:TABLE|TBODY|TR|TH|TD|P)/.test(e.nodeName)||(Array.from(e.childNodes).forEach(i=>{let r=i.nodeName==="BR";!r&&L(i)?(n||(n=_("DIV")),n.appendChild(i)):(r||n)&&(n||(n=_("DIV")),$(n),r?e.replaceChild(n,i):e.insertBefore(n,i),n=null),Qe(i)&&ge(i,t)}),n&&e.appendChild($(n))),e},le=(e,t,n,i)=>{if(!n.contains(e))throw new Error("split: stopNode does not contain node");if(e instanceof Text&&e!==n){if(typeof t!="number")throw new Error("Offset must be a number to split text node!");if(!e.parentNode)throw new Error("Cannot split text node with no parent!");return le(e.parentNode,e.splitText(t),n,i)}let r=typeof t=="number"?t<e.childNodes.length?e.childNodes[t]:null:t,o=e.parentNode;if(!o||e===n||!(e instanceof Element))return r;let s=e.cloneNode(!1);for(;r;){let a=r.nextSibling;s.appendChild(r),r=a}return e instanceof HTMLOListElement&&w(e,i,"BLOCKQUOTE")&&(s.start=(+e.start||1)+e.childNodes.length-1),$(e),$(s),o.insertBefore(s,e.nextSibling),le(o,s,n,i)},pr=(e,t)=>{let n=e.childNodes,i=n.length,r=[];for(;i--;){let o=n[i],s=i?n[i-1]:null;if(s&&L(o)&&dr(o,s))t.startContainer===o&&(t.startContainer=s,t.startOffset+=se(s)),t.endContainer===o&&(t.endContainer=s,t.endOffset+=se(s)),t.startContainer===e&&(t.startOffset>i?t.startOffset-=1:t.startOffset===i&&(t.startContainer=s,t.startOffset=se(s))),t.endContainer===e&&(t.endOffset>i?t.endOffset-=1:t.endOffset===i&&(t.endContainer=s,t.endOffset=se(s))),W(o),o instanceof Text?s.appendData(o.data):r.push(D(o));else if(o instanceof Element){let a;for(;a=r.pop();)o.appendChild(a);pr(o,t)}}},Xe=(e,t)=>{let n=e instanceof Text?e.parentNode:e;if(n instanceof Element){let i={startContainer:t.startContainer,startOffset:t.startOffset,endContainer:t.endContainer,endOffset:t.endOffset};pr(n,i),t.setStart(i.startContainer,i.startOffset),t.setEnd(i.endContainer,i.endOffset)}},pt=(e,t,n,i)=>{let r=t,o,s;for(;(o=r.parentNode)&&o!==i&&o instanceof Element&&o.childNodes.length===1;)r=o;W(r),s=e.childNodes.length;let a=e.lastChild;a&&a.nodeName==="BR"&&(e.removeChild(a),s-=1),e.appendChild(D(t)),n.setStart(e,s),n.collapse(!0),Xe(e,n)},Ee=(e,t)=>{let n=e.previousSibling,i=e.firstChild,r=e.nodeName==="LI";if(!(r&&(!i||!/^[OU]L$/.test(i.nodeName)))){if(n&&dr(n,e)){if(!Qe(n))if(r){let s=_("DIV");s.appendChild(D(n)),n.appendChild(s)}else return;W(e);let o=!Qe(e);n.appendChild(D(e)),o&&ge(n,t),i&&Ee(i,t)}else if(r){let o=_("DIV");e.insertBefore(o,i),$(o)}}},er={"font-weight":{regexp:/^bold|^700/i,replace(){return _("B")}},"font-style":{regexp:/^italic/i,replace(){return _("I")}},"font-family":{regexp:me,replace(e,t){let n=_("SPAN",{class:e.fontFamily});return n.style.fontFamily=t,n}},"font-size":{regexp:me,replace(e,t){let n=_("SPAN",{class:e.fontSize});return n.style.fontSize=t,n}},"text-decoration":{regexp:/^underline/i,replace(){return _("U")}}},ks=(e,t,n)=>{let i=e.style,r,o;for(let s in er){let a=er[s],l=i.getPropertyValue(s);if(l&&a.regexp.test(l)){let h=a.replace(n.classNames,l);if(h.nodeName===e.nodeName&&h.className===e.className)continue;o||(o=h),r&&r.appendChild(h),r=h,e.style.removeProperty(s)}}return o&&r&&(r.appendChild(D(e)),e.style.cssText?e.appendChild(o):Y(e,o)),r||e},Ft=e=>(t,n)=>{let i=_(e),r=t.attributes;for(let o=0,s=r.length;o<s;o+=1){let a=r[o];i.setAttribute(a.name,a.value)}return n.replaceChild(i,t),i.appendChild(D(t)),i},Rs={1:"10",2:"13",3:"16",4:"18",5:"24",6:"32",7:"48"},Os={STRONG:Ft("B"),EM:Ft("I"),INS:Ft("U"),STRIKE:Ft("S"),SPAN:ks,FONT:(e,t,n)=>{let i=e,r=i.face,o=i.size,s=i.color,a=n.classNames,l,h,d,u,p;return r&&(l=_("SPAN",{class:a.fontFamily}),l.style.fontFamily=r,p=l,u=l),o&&(h=_("SPAN",{class:a.fontSize}),h.style.fontSize=Rs[o]+"px",p||(p=h),u&&u.appendChild(h),u=h),s&&/^#?([\dA-F]{3}){1,2}$/i.test(s)&&(s.charAt(0)!=="#"&&(s="#"+s),d=_("SPAN",{class:a.color}),d.style.color=s,p||(p=d),u&&u.appendChild(d),u=d),(!p||!u)&&(p=u=_("SPAN")),t.replaceChild(p,i),u.appendChild(D(i)),u},TT:(e,t,n)=>{let i=_("SPAN",{class:n.classNames.fontFamily,style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(i,e),i.appendChild(D(e)),i}},Ds=/^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT]|IV)|F(?:IGURE|IGCAPTION|OOTER)|H[1-6]|HEADER|L(?:ABEL|EGEND|I)|O(?:L|UTPUT)|P(?:RE)?|SECTION|T(?:ABLE|BODY|D|FOOT|H|HEAD|R)|COL(?:GROUP)?|UL)$/,Is=/^(?:HEAD|META|STYLE)/,Pn=(e,t,n)=>{let i=e.childNodes,r=e;for(;L(r);)r=r.parentNode;let o=new re(r,5);for(let s=0,a=i.length;s<a;s+=1){let l=i[s],h=l.nodeName,d=Os[h];if(l instanceof HTMLElement){let u=l.childNodes.length;if(d)l=d(l,e,t);else if(Is.test(h)){e.removeChild(l),s-=1,a-=1;continue}else if(!Ds.test(h)&&!L(l)){s-=1,a+=u-1,e.replaceChild(D(l),l);continue}u&&Pn(l,t,n||h==="PRE")}else{if(l instanceof Text){let u=l.data,p=!me.test(u.charAt(0)),b=!me.test(u.charAt(u.length-1));if(n||!p&&!b)continue;if(p){o.currentNode=l;let y;for(;(y=o.previousPONode())&&!(y.nodeName==="IMG"||y instanceof Text&&me.test(y.data));)if(!L(y)){y=null;break}u=u.replace(/^[ \t\r\n]+/g,y?" ":"")}if(b){o.currentNode=l;let y;for(;(y=o.nextNode())&&!(y.nodeName==="IMG"||y instanceof Text&&me.test(y.data));)if(!L(y)){y=null;break}u=u.replace(/[ \t\r\n]+$/g,y?" ":"")}if(u){l.data=u;continue}}e.removeChild(l),s-=1,a-=1}}return e},Bn=e=>{let t=e.childNodes,n=t.length;for(;n--;){let i=t[n];i instanceof Element&&!ke(i)?(Bn(i),L(i)&&!i.firstChild&&e.removeChild(i)):i instanceof Text&&!i.data&&e.removeChild(i)}},Hn=(e,t,n)=>{let i=e.querySelectorAll("BR"),r=[],o=i.length;for(let s=0;s<o;s+=1)r[s]=$t(i[s],n);for(;o--;){let s=i[o],a=s.parentNode;a&&(r[o]?L(a)||ge(a,t):W(s))}},tr=e=>e.split("&").join("&amp;").split("<").join("&lt;").split(">").join("&gt;").split('"').join("&quot;"),Wt=(e,t)=>{let n=new re(t,1,xe);return n.currentNode=e,n},Fe=(e,t)=>{let n=Wt(e,t).previousNode();return n!==t?n:null},ve=(e,t)=>{let n=Wt(e,t).nextNode();return n!==t?n:null},Fn=e=>!e.textContent&&!e.querySelector("IMG"),oe=(e,t)=>{let n=e.startContainer,i;if(L(n))i=Fe(n,t);else if(n!==t&&n instanceof HTMLElement&&xe(n))i=n;else{let r=qn(n,e.startOffset);i=ve(r,t)}return i&&Ne(e,i,!0)?i:null},Ue=(e,t)=>{let n=e.endContainer,i;if(L(n))i=Fe(n,t);else if(n!==t&&n instanceof HTMLElement&&xe(n))i=n;else{let r=fr(n,e.endOffset);if(!r||!t.contains(r)){r=t;let o;for(;o=r.lastChild;)r=o}i=Fe(r,t)}return i&&Ne(e,i,!0)?i:null},mr=e=>e instanceof Text?me.test(e.data):e.nodeName==="IMG",mt=(e,t)=>{let n=e.startContainer,i=e.startOffset,r;if(n instanceof Text){let a=n.data;for(let l=i;l>0;l-=1)if(a.charAt(l-1)!=="\u200B")return!1;r=n}else if(r=fr(n,i),r&&!t.contains(r)&&(r=null),!r&&(r=qn(n,i),r instanceof Text&&r.length))return!1;let o=oe(e,t);if(!o)return!1;let s=new re(o,5,mr);return s.currentNode=r,!s.previousNode()},gt=(e,t)=>{let n=e.endContainer,i=e.endOffset,r;if(n instanceof Text){let a=n.data,l=a.length;for(let h=i;h<l;h+=1)if(a.charAt(h)!=="\u200B")return!1;r=n}else r=qn(n,i);let o=Ue(e,t);if(!o)return!1;let s=new re(o,5,mr);return s.currentNode=r,!s.nextNode()},nr=(e,t)=>{let n=oe(e,t),i=Ue(e,t),r;n&&i&&(r=n.parentNode,e.setStart(r,Array.from(r.childNodes).indexOf(n)),r=i.parentNode,e.setEnd(r,Array.from(r.childNodes).indexOf(i)+1))};function Be(e,t,n,i){let r=document.createRange();return r.setStart(e,t),n&&typeof i=="number"?r.setEnd(n,i):r.setEnd(e,t),r}var _e=(e,t)=>{let{startContainer:n,startOffset:i,endContainer:r,endOffset:o}=e,s;if(n instanceof Text){let l=n.parentNode;if(s=l.childNodes,i===n.length)i=Array.from(s).indexOf(n)+1,e.collapsed&&(r=l,o=i);else{if(i){let h=n.splitText(i);r===n?(o-=i,r=h):r===l&&(o+=1),n=h}i=Array.from(s).indexOf(n)}n=l}else s=n.childNodes;let a=s.length;i===a?n.appendChild(t):n.insertBefore(t,s[i]),n===r&&(o+=s.length-a),e.setStart(n,i),e.setEnd(r,o)},gr=(e,t,n)=>{let i=document.createDocumentFragment();if(e.collapsed)return i;t||(t=e.commonAncestorContainer),t instanceof Text&&(t=t.parentNode);let r=e.startContainer,o=e.startOffset,s=le(e.endContainer,e.endOffset,t,n),a=0,l=le(r,o,t,n);for(;l&&l!==s;){let h=l.nextSibling;i.appendChild(l),l=h}return l=s&&s.previousSibling,l&&l instanceof Text&&s instanceof Text&&(a=l.length,l.appendData(s.data),W(s),s=l),e.setStart(r,o),s?e.setEnd(s,a):e.setEnd(t,t.childNodes.length),$(t),i},ir=(e,t,n)=>{e.currentNode=n;let i;for(;i=e[t]();){if(i instanceof Text||ke(i))return i;if(!L(i))return null}return null},qe=(e,t)=>{let n=oe(e,t),i=Ue(e,t),r=n!==i;n&&i&&(X(e),He(e,n,i,t));let o=gr(e,null,t);X(e),r&&(i=Ue(e,t),n&&i&&n!==i&&pt(n,i,e,t)),n&&$(n);let s=t.firstChild;(!s||s.nodeName==="BR")&&($(t),t.firstChild&&e.selectNodeContents(t.firstChild)),e.collapse(!0);let a=e.startContainer,l=e.startOffset,h=new re(t,5),d=a,u=l;(!(d instanceof Text)||u===d.data.length)&&(d=ir(h,"nextNode",d),u=0);let p=a,b=l-1;(!(p instanceof Text)||b===-1)&&(p=ir(h,"previousPONode",d||(a instanceof Text?a:a.childNodes[l]||a)),p instanceof Text&&(b=p.data.length));let y=null,E=0;return d instanceof Text&&d.data.charAt(u)===" "&&mt(e,t)?(y=d,E=u):p instanceof Text&&p.data.charAt(b)===" "&&(d instanceof Text&&d.data.charAt(u)===" "||gt(e,t))&&(y=p,E=b),y&&y.replaceData(E,1,"\xA0"),e.setStart(a,l),e.collapse(!0),o},Ms=(e,t,n)=>{let i=t.firstChild&&L(t.firstChild),r;for(ge(t,n),r=t;r=ve(r,n);)$(r);e.collapsed||qe(e,n),X(e),e.collapse(!1);let o=w(e.endContainer,n,"BLOCKQUOTE")||n,s=oe(e,n),a=null,l=ve(t,t),h=!i&&!!s&&Fn(s);if(s&&l&&!h&&!w(l,t,"PRE")&&!w(l,t,"TABLE")){He(e,s,s,n),e.collapse(!0);let d=e.endContainer,u=e.endOffset;if(Hn(s,n,!1),L(d)){let p=le(d,u,Fe(d,n)||n,n);d=p.parentNode,u=Array.from(d.childNodes).indexOf(p)}if(u!==se(d))for(a=document.createDocumentFragment();r=d.childNodes[u];)a.appendChild(r);pt(d,l,e,n),d===n?e.setEnd(n,se(n)):(u=Array.from(d.parentNode.childNodes).indexOf(d)+1,d=d.parentNode,e.setEnd(d,u))}if(se(t)){h&&s&&(e.setEndBefore(s),e.collapse(!1),W(s)),o.contains(e.endContainer)||(n.contains(e.endContainer)||(e.setEnd(n,se(n)),e.collapse(!1)),o=w(e.endContainer,n,"BLOCKQUOTE")||n),He(e,o,o,n);let d=le(e.endContainer,e.endOffset,o,n),u=d?d.previousSibling:o.lastChild;o.insertBefore(t,d),d?e.setEndBefore(d):e.setEnd(o,se(o)),s=Ue(e,n),X(e);let p=e.endContainer,b=e.endOffset;d&&Qe(d)&&Ee(d,n),d=u&&u.nextSibling,d&&Qe(d)&&Ee(d,n),e.setEnd(p,b)}if(a&&s){let d=e.cloneRange();$(a),pt(s,a,d,n),e.setEnd(d.endContainer,d.endOffset)}X(e)},yr=e=>{if(e.collapsed)return"";let t=e.startContainer,n=e.endContainer,i=new re(e.commonAncestorContainer,5,l=>Ne(e,l,!0));i.currentNode=t;let r=t,o="",s=!1,a;for((!(r instanceof Element)&&!(r instanceof Text)||!i.filter(r))&&(r=i.nextNode());r;)r instanceof Text?(a=r.data,a&&/\S/.test(a)&&(r===n&&(a=a.slice(0,e.endOffset)),r===t&&(a=a.slice(e.startOffset)),o+=a,s=!0)):(r.nodeName==="BR"||s&&!L(r))&&(o+=`
3
- `,s=!1),r=i.nextNode();return o=o.replace(/ /g," "),o},Rn=Array.prototype.indexOf,br=(e,t,n,i,r)=>{let o=r?"":yr(e),s=oe(e,t),a=Ue(e,t),l=e.commonAncestorContainer,h=t;s===a&&s?.contains(l)&&(h=s);let d;for(n?(d=qe(e,t),l.isConnected||(l=e.commonAncestorContainer)):d=e.cloneContents(),l instanceof Text&&(l=l.parentNode);l&&l!==h;){let p=l.cloneNode(!1);p.appendChild(d),d=p,l=l.parentNode}let u;if(d.childNodes.length===1&&d.childNodes[0]instanceof Text)o=d.childNodes[0].data.replace(/ /g," "),u=void 0;else{let p=_("DIV");p.appendChild(d),u=p.innerHTML,i&&(u=i(u))}return r&&u!==void 0&&(o=r(u)),o===u&&(u=void 0),ar&&(o=o.replace(/\r?\n/g,`\r
4
- `)),u&&(u="<!-- squire -->"+u),[o,u]},Tr=(e,t,n,i,r,o,s)=>{let a=e.clipboardData;if(zt||!a)return!1;let[l,h]=br(t,n,i,r,o);return e.preventDefault(),!s&&h&&a.setData("text/html",h),a.setData("text/plain",l),!0},Ps=function(e){let t=this.getSelection(),n=this._root;if(t.collapsed){e.preventDefault();return}this.saveUndoState(t),Tr(e,t,n,!0,this._config.willCutCopy,this._config.toPlainText,!1)||setTimeout(()=>{try{this._ensureBottomLine()}catch(i){this._config.didError(i)}},0),this.setSelection(t)},Bs=function(e){Tr(e,this.getSelection(),this._root,!1,this._config.willCutCopy,this._config.toPlainText,!1)},rr=function(e){this._isShiftDown=e.shiftKey},Hs=function(e){let t=e.clipboardData,n=t?.items,i=this._isShiftDown,r=!1,o=!1,s=null,a=null;if(n){let S=n.length;for(;S--;){let N=n[S],P=N.type;P==="text/html"?a=N:P==="text/plain"||P==="text/uri-list"?s=N:P==="text/rtf"?r=!0:/^image\/.*/.test(P)&&(o=!0)}if(o&&!(r&&a)&&!s){e.preventDefault(),this.fireEvent("pasteImage",{clipboardData:t});return}if(!zt){e.preventDefault(),a&&(!i||!s)?a.getAsString(N=>{this.insertHTML(N,!0)}):s&&s.getAsString(N=>{let P=this.getSelection();if(!P.collapsed&&me.test(P.toString())){let J=this.linkRegExp.exec(N);if(J&&J[0].length===N.length){let U=J[1]?/^(?:ht|f)tps?:/i.test(J[1])?J[1]:"http://"+J[1]:"mailto:"+J[0];this.makeLink(U);return}}this.insertPlainText(N,!0)});return}}let l=t?.types;if(!zt&&l&&(Rn.call(l,"text/html")>-1||!Ts&&Rn.call(l,"text/plain")>-1&&Rn.call(l,"text/rtf")<0)){e.preventDefault();let S;!i&&(S=t.getData("text/html"))?this.insertHTML(S,!0):((S=t.getData("text/plain"))||(S=t.getData("text/uri-list")))&&this.insertPlainText(S,!0);return}let h=document.body,d=this.getSelection(),u=d.startContainer,p=d.startOffset,b=d.endContainer,y=d.endOffset,E=_("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});h.appendChild(E),d.selectNodeContents(E),this.setSelection(d),setTimeout(()=>{try{let S="",N=E,P;for(;E=N;)N=E.nextSibling,W(E),P=E.firstChild,P&&P===E.lastChild&&P instanceof HTMLDivElement&&(E=P),S+=E.innerHTML;this.setSelection(Be(u,p,b,y)),S&&this.insertHTML(S,!0)}catch(S){this._config.didError(S)}},0)},Fs=function(){let e=this.getSelection();e&&!e.collapsed&&this._root.contains(e.commonAncestorContainer)?this._dragRange=e.cloneRange():this._dragRange=null},Us=function(){this._dragRange=null},zs=(e,t,n)=>{let i=null,r=document;if(r.caretPositionFromPoint){let o=r.caretPositionFromPoint(e,t);o&&(i=document.createRange(),i.setStart(o.offsetNode,o.offset),i.collapse(!0))}else r.caretRangeFromPoint&&(i=r.caretRangeFromPoint(e,t));return i&&!n.contains(i.commonAncestorContainer)?null:i},qs=(e,t)=>e.compareBoundaryPoints(Range.START_TO_START,t)>=0&&e.compareBoundaryPoints(Range.END_TO_END,t)<=0,Ws=function(e){let t=e.dataTransfer;if(!t)return;let n=t.types,i=!1,r=!1;for(let d=0,u=n.length;d<u;d+=1)switch(n[d]){case"text/plain":i=!0;break;case"text/html":r=!0;break}if(!i&&!r)return;e.preventDefault();let o=this._root,s=zs(e.clientX,e.clientY,o),a=this._dragRange;if(this._dragRange=null,!s)return;let l,h;if(a){if(qs(s,a))return;this._recordUndoState(a,this._isInUndoState);let d=document.createComment("");s.insertNode(d),this._getRangeAndRemoveBookmark(a),[l,h]=br(a,o,t.dropEffect!=="copy",this._config.willCutCopy,this._config.toPlainText),d.replaceWith(_("INPUT",{id:this.startSelectionId,type:"hidden"}),_("INPUT",{id:this.endSelectionId,type:"hidden"})),this._getRangeAndRemoveBookmark(s),ur()}else this.saveUndoState(s),r?h=t.getData("text/html"):l=t.getData("text/plain");this.setSelection(s),h!==void 0?this.insertHTML(h,!0):l!==void 0&&this.insertPlainText(l,!0)},or=(e,t,n)=>{t.preventDefault(),e.splitBlock(t.shiftKey,n)},ft=(e,t)=>{try{t||(t=e.getSelection());let n=t.startContainer;n instanceof Text&&(n=n.parentNode);let i=n;for(;i!==e._root&&L(i)&&(!i.textContent||i.textContent==="\u200B");)n=i,i=n.parentNode;n!==i&&(t.setStart(i,Array.from(i.childNodes).indexOf(n)),t.collapse(!0),i.removeChild(n),xe(i)||(i=Fe(i,e._root)||e._root),$(i),X(t)),n===e._root&&(n=n.firstChild)&&n.nodeName==="BR"&&W(n),e._ensureBottomLine(),e.setSelection(t),e._updatePath(t,!0)}catch(n){e._config.didError(n)}},_r=(e,t)=>{let n;for(;(n=e.parentNode)&&!(n===t||n.isContentEditable);)e=n;W(e)},Er=(e,t,n)=>{if(w(t,e._root,"A"))return;let i=t.data||"",r=Math.max(i.lastIndexOf(" ",n-1),i.lastIndexOf("\xA0",n-1))+1,o=i.slice(r,n),s=e.linkRegExp.exec(o);if(s){let a=e.getSelection();e._docWasChanged(),e._recordUndoState(a),e._getRangeAndRemoveBookmark(a);let l=r+s.index,h=l+s[0].length,d=a.startContainer===t,u=a.startOffset-h;l&&(t=t.splitText(l));let p=e._config.tagAttributes.a,b=_("A",Object.assign({href:s[1]?/^(?:ht|f)tps?:/i.test(s[1])?s[1]:"http://"+s[1]:"mailto:"+s[0]},p));b.textContent=i.slice(l,h),t.parentNode.insertBefore(b,t),t.data=i.slice(h),d&&(a.setStart(t,u),a.setEnd(t,u)),e.setSelection(a)}},$s=(e,t,n)=>{let i=e._root;if(e._removeZWS(),e.saveUndoState(n),!n.collapsed)t.preventDefault(),qe(n,i),ft(e,n);else if(mt(n,i)){t.preventDefault();let r=oe(n,i);if(!r)return;let o=r;ge(o.parentNode,i);let s=Fe(o,i);if(s){if(!s.isContentEditable){_r(s,i);return}for(pt(s,o,n,i),o=s.parentNode;o!==i&&!o.nextSibling;)o=o.parentNode;o!==i&&(o=o.nextSibling)&&Ee(o,i),e.setSelection(n)}else if(o){if(w(o,i,"UL")||w(o,i,"OL")){e.decreaseListLevel(n);return}else if(w(o,i,"BLOCKQUOTE")){e.removeQuote(n);return}e.setSelection(n),e._updatePath(n,!0)}}else{X(n);let r=n.startContainer,o=n.startOffset,s=r.parentNode;r instanceof Text&&s instanceof HTMLAnchorElement&&o&&s.href.includes(r.data)?(r.deleteData(o-1,1),e.setSelection(n),e.removeLink(),t.preventDefault()):(e.setSelection(n),setTimeout(()=>{ft(e)},0))}},Ks=(e,t,n)=>{let i=e._root,r,o,s,a,l,h;if(e._removeZWS(),e.saveUndoState(n),!n.collapsed)t.preventDefault(),qe(n,i),ft(e,n);else if(gt(n,i)){if(t.preventDefault(),r=oe(n,i),!r)return;if(ge(r.parentNode,i),o=ve(r,i),o){if(!o.isContentEditable){_r(o,i);return}for(pt(r,o,n,i),o=r.parentNode;o!==i&&!o.nextSibling;)o=o.parentNode;o!==i&&(o=o.nextSibling)&&Ee(o,i),e.setSelection(n),e._updatePath(n,!0)}}else{if(s=n.cloneRange(),He(n,i,i,i),a=n.endContainer,l=n.endOffset,a instanceof Element&&(h=a.childNodes[l],h&&h.nodeName==="IMG")){t.preventDefault(),W(h),X(n),ft(e,n);return}e.setSelection(s),setTimeout(()=>{ft(e)},0)}},Vs=(e,t,n)=>{let i=e._root;if(e._removeZWS(),n.collapsed&&mt(n,i)){let r=oe(n,i),o;for(;o=r.parentNode;){if(o.nodeName==="UL"||o.nodeName==="OL"){t.preventDefault(),e.increaseListLevel(n);break}r=o}}},Gs=(e,t,n)=>{let i=e._root;if(e._removeZWS(),n.collapsed&&mt(n,i)){let r=n.startContainer;(w(r,i,"UL")||w(r,i,"OL"))&&(t.preventDefault(),e.decreaseListLevel(n))}},js=(e,t,n)=>{let i,r=e._root;if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),!n.collapsed)qe(n,r),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0);else if(gt(n,r)){let o=oe(n,r);if(o&&o.nodeName!=="PRE"){let s=o.textContent?.trimEnd().replace("\u200B","");if(s==="*"||s==="1."){t.preventDefault(),e.insertPlainText(" ",!1),e._docWasChanged(),e.saveUndoState(n);let a=new re(o,4),l;for(;l=a.nextNode();)W(l);s==="*"?e.makeUnorderedList():e.makeOrderedList();return}}}if(i=n.endContainer,n.endOffset===se(i))do if(i.nodeName==="A"){n.setStartAfter(i);break}while(!i.nextSibling&&(i=i.parentNode)&&i!==r);if(e._config.addLinks){let o=n.cloneRange();X(o);let s=o.startContainer,a=o.startOffset;setTimeout(()=>{Er(e,s,a)},0)}e.setSelection(n)},Zs=function(e){if(e.defaultPrevented||e.isComposing)return;let t=e.key,n="",i=e.code;/^Digit\d$/.test(i)&&(t=i.slice(-1)),t!=="Backspace"&&t!=="Delete"&&(e.altKey&&(n+="Alt-"),e.ctrlKey&&(n+="Ctrl-"),e.metaKey&&(n+="Meta-"),e.shiftKey&&(n+="Shift-")),ar&&e.shiftKey&&t==="Delete"&&(n+="Shift-"),t=n+t;let r=this.getSelection(),o=this._keyHandlers[t];o?o(this,e,r):!r.collapsed&&!e.ctrlKey&&!e.metaKey&&t.length===1&&(this.saveUndoState(r),qe(r,this._root),this._ensureBottomLine(),this.setSelection(r),this._updatePath(r,!0))},H={Backspace:$s,Delete:Ks,Tab:Vs,"Shift-Tab":Gs," ":js,ArrowLeft(e){e._removeZWS()},ArrowRight(e,t,n){e._removeZWS();let i=e.getRoot();if(gt(n,i)){X(n);let r=n.endContainer;do if(r.nodeName==="CODE"){let o=r.nextSibling;if(!(o instanceof Text)||o.length===0){let s=document.createTextNode("\xA0");r.parentNode.insertBefore(s,o),o=s}n.setStart(o,1),e.setSelection(n),t.preventDefault();break}while(!r.nextSibling&&(r=r.parentNode)&&r!==i)}}};Es||(H.Enter=or,H["Shift-Enter"]=or);!Un&&!lr&&(H.PageUp=e=>{e.moveCursorToStart()},H.PageDown=e=>{e.moveCursorToEnd()});var Je=(e,t)=>(t=t||null,(n,i)=>{i.preventDefault();let r=n.getSelection();n.hasFormat(e,null,r)?n.changeFormat(null,{tag:e},r):n.changeFormat({tag:e},t,r)});H[te+"b"]=Je("B");H[te+"i"]=Je("I");H[te+"u"]=Je("U");H[te+"Shift-7"]=Je("S");H[te+"Shift-5"]=Je("SUB",{tag:"SUP"});H[te+"Shift-6"]=Je("SUP",{tag:"SUB"});H[te+"Shift-8"]=(e,t)=>{t.preventDefault();let n=e.getPath();/(?:^|>)UL/.test(n)?e.removeList():e.makeUnorderedList()};H[te+"Shift-9"]=(e,t)=>{t.preventDefault();let n=e.getPath();/(?:^|>)OL/.test(n)?e.removeList():e.makeOrderedList()};H[te+"["]=(e,t)=>{t.preventDefault();let n=e.getPath();/(?:^|>)BLOCKQUOTE/.test(n)||!/(?:^|>)[OU]L/.test(n)?e.decreaseQuoteLevel():e.decreaseListLevel()};H[te+"]"]=(e,t)=>{t.preventDefault();let n=e.getPath();/(?:^|>)BLOCKQUOTE/.test(n)||!/(?:^|>)[OU]L/.test(n)?e.increaseQuoteLevel():e.increaseListLevel()};H[te+"d"]=(e,t)=>{t.preventDefault(),e.toggleCode()};H[te+"z"]=(e,t)=>{t.preventDefault(),e.undo()};H[te+"y"]=H[te+"Shift-z"]=H[te+"Shift-Z"]=(e,t)=>{t.preventDefault(),e.redo()};var On=8,sr=40,Dn=1200,Ys=[{pos:"nw",cursor:"nwse-resize"},{pos:"n",cursor:"ns-resize"},{pos:"ne",cursor:"nesw-resize"},{pos:"e",cursor:"ew-resize"},{pos:"se",cursor:"nwse-resize"},{pos:"s",cursor:"ns-resize"},{pos:"sw",cursor:"nesw-resize"},{pos:"w",cursor:"ew-resize"}],Xs={ArrowUp:(e,t,n)=>{let i=oe(t,n);if(i){let r=Fe(i,n);r&&(t.selectNodeContents(r),t.collapse(!1),e.setSelection(t).focus())}},ArrowDown:(e,t,n)=>{let i=oe(t,n);if(i){let r=ve(i,n);r&&(t.selectNodeContents(r),t.collapse(!0),e.setSelection(t).focus())}},Delete:(e,t)=>{e.replaceWithBlankLine(t)},Backspace:(e,t)=>{e.replaceWithBlankLine(t)}},Qs=class{constructor(e,t){this._currentImage=null,this._resizeContainer=null,this._handles=null,this._currentHandle=null,this._startX=0,this._startY=0,this._startWidth=0,this._startHeight=0,this._maxWidth=Dn,this._originalRatio=1,this._editor=t,this._root=e,document.addEventListener("click",this),t.addEventListener("drop",this)}destroy(){this._deselectImage(),this._editor.removeEventListener("drop",this),document.removeEventListener("click",this)}handleEvent(e){switch(e.type){case"click":this._onClick(e);break;case"pointerdown":this._onPointerDown(e);break;case"pointermove":this._onPointerMove(e);break;case"pointercancel":case"pointerup":this._onPointerUp(e);break;case"keydown":this._onKeyDown(e);break;case"drop":this._deselectImage();break}}_onClick(e){let t=e.target;t.nodeName==="IMG"&&this._root.contains(t)?(e.stopPropagation(),this._selectImage(t)):this._currentImage&&this._handles&&!this._handles.some(n=>n.element===t)&&this._deselectImage()}_deselectImage(){this._currentImage&&(document.removeEventListener("keydown",this,!0),this._currentHandle&&this._onPointerUp({preventDefault(){},target:this._currentHandle.element}),this._handles&&this._handles.forEach(({element:e})=>e.removeEventListener("pointerdown",this)),this._resizeContainer&&this._resizeContainer.remove(),this._currentImage.removeAttribute("tabindex"),this._handles=null,this._resizeContainer=null,this._currentImage=null)}_selectImage(e){if(this._currentImage===e)return;this._deselectImage(),this._root.blur();let t=Ys.map(({pos:r,cursor:o})=>{let s=On/2,a="";switch(r){case"nw":a=`left: -${s}px; top: -${s}px;`;break;case"n":a=`left: calc(50% - ${s}px); top: -${s}px;`;break;case"ne":a=`right: -${s}px; top: -${s}px;`;break;case"e":a=`right: -${s}px; top: calc(50% - ${s}px);`;break;case"se":a=`right: -${s}px; bottom: -${s}px;`;break;case"s":a=`left: calc(50% - ${s}px); bottom: -${s}px;`;break;case"sw":a=`left: -${s}px; bottom: -${s}px;`;break;case"w":a=`left: -${s}px; top: calc(50% - ${s}px);`;break}let l=_("div",{class:`squire-resize-handle squire-resize-handle-${r}`,style:`
2
+ var richclay=(()=>{var Dn=Object.defineProperty;var ds=Object.getOwnPropertyDescriptor;var fs=Object.getOwnPropertyNames;var ps=Object.prototype.hasOwnProperty;var ms=(e,t)=>{for(var n in t)Dn(e,n,{get:t[n],enumerable:!0})},gs=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of fs(t))!ps.call(e,r)&&r!==n&&Dn(e,r,{get:()=>t[r],enumerable:!(i=ds(t,r))||i.enumerable});return e};var ys=e=>gs(Dn({},"__esModule",{value:!0}),e);var Wl={};ms(Wl,{RichClay:()=>$e,default:()=>ql,stopAutoWatch:()=>zl});var bs=()=>!0,re=class{constructor(e,t,n){this.root=e,this.currentNode=e,this.nodeType=t,this.filter=n||bs}isAcceptableNode(e){let t=e.nodeType;return!!((t===Node.ELEMENT_NODE?1:t===Node.TEXT_NODE?4:0)&this.nodeType)&&this.filter(e)}nextNode(){let e=this.root,t=this.currentNode,n;for(;;){for(n=t.firstChild;!n&&t&&t!==e;)n=t.nextSibling,n||(t=t.parentNode);if(!n)return null;if(this.isAcceptableNode(n))return this.currentNode=n,n;t=n}}previousNode(){let e=this.root,t=this.currentNode,n;for(;;){if(t===e)return null;if(n=t.previousSibling,n)for(;t=n.lastChild;)n=t;else n=t.parentNode;if(!n)return null;if(this.isAcceptableNode(n))return this.currentNode=n,n;t=n}}previousPONode(){let e=this.root,t=this.currentNode,n;for(;;){for(n=t.lastChild;!n&&t&&t!==e;)n=t.previousSibling,n||(t=t.parentNode);if(!n)return null;if(this.isAcceptableNode(n))return this.currentNode=n,n;t=n}}},ze=navigator.userAgent,Wn=/Mac OS X/.test(ze),cr=/Windows NT/.test(ze),hr=/iP(?:ad|hone|od)/.test(ze)||Wn&&!!navigator.maxTouchPoints,$l=/Android/.test(ze),Ts=/Gecko\//.test(ze),zt=/Edge\//.test(ze),_s=!zt&&/WebKit\//.test(ze),te=Wn||hr?"Meta-":"Ctrl-",qt=_s,Es="onbeforeinput"in document&&"inputType"in new InputEvent("input"),me=/[^ \t\r\n\u200B]/,vs=/^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:FRAME|MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|TIME|U|VAR|WBR)$/,Ss=new Set(["BR","HR","IFRAME","IMG","INPUT"]),As=0,Bn=1,ur=2,dr=3,Ut=new WeakMap,fr=()=>{Ut=new WeakMap},ke=e=>Ss.has(e.nodeName),Kn=e=>{switch(e.nodeType){case 8:case 3:return Bn;case 1:case 11:if(Ut.has(e))return Ut.get(e);break;default:return As}let t;return Array.from(e.childNodes).every(L)?vs.test(e.nodeName)?t=Bn:t=ur:t=dr,Ut.set(e,t),t},L=e=>Kn(e)===Bn,xe=e=>Kn(e)===ur,Je=e=>Kn(e)===dr,_=(e,t,n)=>{let i=document.createElement(e);if(t instanceof Array&&(n=t,t=null),t)for(let r in t){let o=t[r];o!==void 0&&i.setAttribute(r,o)}return n&&n.forEach(r=>i.appendChild(r)),i},pr=(e,t)=>ke(e)||e.nodeType!==t.nodeType||e.nodeName!==t.nodeName?!1:e instanceof HTMLElement&&t instanceof HTMLElement?e.nodeName!=="A"&&e.className===t.className&&e.style.cssText===t.style.cssText:!0,Hn=(e,t,n)=>{if(e.nodeName!==t)return!1;for(let i in n)if(!("getAttribute"in e)||e.getAttribute(i)!==n[i])return!1;return!0},w=(e,t,n,i)=>{for(;e&&e!==t;){if(Hn(e,n,i))return e;e=e.parentNode}return null},$n=(e,t)=>{let n=e.childNodes;for(;t&&e instanceof Element;)e=n[t-1],n=e.childNodes,t=n.length;return e},mr=(e,t)=>{let n=e;if(n instanceof Element){let i=n.childNodes;if(t<i.length)n=i[t];else{for(;n&&!n.nextSibling;)n=n.parentNode;n&&(n=n.nextSibling)}}return n},se=e=>e instanceof Element||e instanceof DocumentFragment?e.childNodes.length:e instanceof CharacterData?e.length:0,D=e=>{let t=document.createDocumentFragment(),n=e.firstChild;for(;n;)t.appendChild(n),n=e.firstChild;return t},W=e=>{let t=e.parentNode;return t&&t.removeChild(e),e},Y=(e,t)=>{let n=e.parentNode;n&&n.replaceChild(t,e)},Cs=e=>e instanceof Element?e.nodeName==="BR":me.test(e.data),Kt=(e,t)=>{let n=e.parentNode;for(;L(n);)n=n.parentNode;let i=new re(n,5,Cs);return i.currentNode=e,!!i.nextNode()||t&&!i.previousNode()},Ht=(e,t)=>{let n=new re(e,4),i,r;for(;i=n.nextNode();)for(;(r=i.data.indexOf("\u200B"))>-1&&(!t||i.parentNode!==t);)if(i.length===1){let o=i,s=o.parentNode;for(;s&&(s.removeChild(o),n.currentNode=s,!(!L(s)||se(s)));)o=s,s=o.parentNode;break}else i.deleteData(r,1)},Ls=0,ws=1,Ns=2,xs=3,Ne=(e,t,n)=>{let i=document.createRange();if(i.selectNode(t),n){let r=e.compareBoundaryPoints(xs,i)>-1,o=e.compareBoundaryPoints(ws,i)<1;return!r&&!o}else{let r=e.compareBoundaryPoints(Ls,i)<1,o=e.compareBoundaryPoints(Ns,i)>-1;return r&&o}},X=e=>{let{startContainer:t,startOffset:n,endContainer:i,endOffset:r}=e;for(;!(t instanceof Text);){let o=t.childNodes[n];if(!o||ke(o)){if(n&&(o=t.childNodes[n-1],o instanceof Text)){let s=o,a;for(;!s.length&&(a=s.previousSibling)&&a instanceof Text;)s.remove(),s=a;t=s,n=s.data.length}break}t=o,n=0}if(r)for(;!(i instanceof Text);){let o=i.childNodes[r-1];if(!o||ke(o)){if(o&&o.nodeName==="BR"&&!Kt(o,!1)){r-=1;continue}break}i=o,r=se(i)}else for(;!(i instanceof Text);){let o=i.firstChild;if(!o||ke(o))break;i=o}e.setStart(t,n),e.setEnd(i,r)},He=(e,t,n,i)=>{let r=e.startContainer,o=e.startOffset,s=e.endContainer,a=e.endOffset,l;for(t||(t=e.commonAncestorContainer),n||(n=t);!o&&r!==t&&r!==i;)l=r.parentNode,o=Array.from(l.childNodes).indexOf(r),r=l;for(;!(s===n||s===i||(s.nodeType!==3&&s.childNodes[a]&&s.childNodes[a].nodeName==="BR"&&!Kt(s.childNodes[a],!1)&&(a+=1),a!==se(s)));)l=s.parentNode,a=Array.from(l.childNodes).indexOf(s)+1,s=l;e.setStart(r,o),e.setEnd(s,a)},tr=(e,t,n)=>{let i=w(e.endContainer,n,t);if(i&&(i=i.parentNode)){let r=e.cloneRange();He(r,i,i,n),r.endContainer===i&&(e.setStart(r.endContainer,r.endOffset),e.setEnd(r.endContainer,r.endOffset))}return e},K=e=>{let t=null;if(e instanceof Text)return e;if(L(e)){let n=e.firstChild;if(qt)for(;n&&n instanceof Text&&!n.data;)e.removeChild(n),n=e.firstChild;n||(qt?t=document.createTextNode("\u200B"):t=document.createTextNode(""))}else if((e instanceof Element||e instanceof DocumentFragment)&&!e.querySelector("BR")&&!me.test(e.textContent||"")){t=_("BR");let n=e,i;for(;(i=n.lastElementChild)&&!L(i);)n=i;e=n,e instanceof HTMLElement&&e.contentEditable==="true"&&(e=_("DIV"),n.appendChild(e))}if(t)try{e.appendChild(t)}catch{}return e},ge=(e,t)=>{let n=null;return/^(?:TABLE|TBODY|TR|TH|TD|P)/.test(e.nodeName)||(Array.from(e.childNodes).forEach(i=>{let r=i.nodeName==="BR";!r&&L(i)?(n||(n=_("DIV")),n.appendChild(i)):(r||n)&&(n||(n=_("DIV")),K(n),r?e.replaceChild(n,i):e.insertBefore(n,i),n=null),Je(i)&&ge(i,t)}),n&&e.appendChild(K(n))),e},le=(e,t,n,i)=>{if(!n.contains(e))throw new Error("split: stopNode does not contain node");if(e instanceof Text&&e!==n){if(typeof t!="number")throw new Error("Offset must be a number to split text node!");if(!e.parentNode)throw new Error("Cannot split text node with no parent!");return le(e.parentNode,e.splitText(t),n,i)}let r=typeof t=="number"?t<e.childNodes.length?e.childNodes[t]:null:t,o=e.parentNode;if(!o||e===n||!(e instanceof Element))return r;let s=e.cloneNode(!1);for(;r;){let a=r.nextSibling;s.appendChild(r),r=a}return e instanceof HTMLOListElement&&w(e,i,"BLOCKQUOTE")&&(s.start=(+e.start||1)+e.childNodes.length-1),K(e),K(s),o.insertBefore(s,e.nextSibling),le(o,s,n,i)},gr=(e,t)=>{let n=e.childNodes,i=n.length,r=[];for(;i--;){let o=n[i],s=i?n[i-1]:null;if(s&&L(o)&&pr(o,s))t.startContainer===o&&(t.startContainer=s,t.startOffset+=se(s)),t.endContainer===o&&(t.endContainer=s,t.endOffset+=se(s)),t.startContainer===e&&(t.startOffset>i?t.startOffset-=1:t.startOffset===i&&(t.startContainer=s,t.startOffset=se(s))),t.endContainer===e&&(t.endOffset>i?t.endOffset-=1:t.endOffset===i&&(t.endContainer=s,t.endOffset=se(s))),W(o),o instanceof Text?s.appendData(o.data):r.push(D(o));else if(o instanceof Element){let a;for(;a=r.pop();)o.appendChild(a);gr(o,t)}}},Qe=(e,t)=>{let n=e instanceof Text?e.parentNode:e;if(n instanceof Element){let i={startContainer:t.startContainer,startOffset:t.startOffset,endContainer:t.endContainer,endOffset:t.endOffset};gr(n,i),t.setStart(i.startContainer,i.startOffset),t.setEnd(i.endContainer,i.endOffset)}},pt=(e,t,n,i)=>{let r=t,o,s;for(;(o=r.parentNode)&&o!==i&&o instanceof Element&&o.childNodes.length===1;)r=o;W(r),s=e.childNodes.length;let a=e.lastChild;a&&a.nodeName==="BR"&&(e.removeChild(a),s-=1),e.appendChild(D(t)),n.setStart(e,s),n.collapse(!0),Qe(e,n)},ve=(e,t)=>{let n=e.previousSibling,i=e.firstChild,r=e.nodeName==="LI";if(!(r&&(!i||!/^[OU]L$/.test(i.nodeName)))){if(n&&pr(n,e)){if(!Je(n))if(r){let s=_("DIV");s.appendChild(D(n)),n.appendChild(s)}else return;W(e);let o=!Je(e);n.appendChild(D(e)),o&&ge(n,t),i&&ve(i,t)}else if(r){let o=_("DIV");e.insertBefore(o,i),K(o)}}},nr={"font-weight":{regexp:/^bold|^700/i,replace(){return _("B")}},"font-style":{regexp:/^italic/i,replace(){return _("I")}},"font-family":{regexp:me,replace(e,t){let n=_("SPAN",{class:e.fontFamily});return n.style.fontFamily=t,n}},"font-size":{regexp:me,replace(e,t){let n=_("SPAN",{class:e.fontSize});return n.style.fontSize=t,n}},"text-decoration":{regexp:/^underline/i,replace(){return _("U")}}},ks=(e,t,n)=>{let i=e.style,r,o;for(let s in nr){let a=nr[s],l=i.getPropertyValue(s);if(l&&a.regexp.test(l)){let h=a.replace(n.classNames,l);if(h.nodeName===e.nodeName&&h.className===e.className)continue;o||(o=h),r&&r.appendChild(h),r=h,e.style.removeProperty(s)}}return o&&r&&(r.appendChild(D(e)),e.style.cssText?e.appendChild(o):Y(e,o)),r||e},Ft=e=>(t,n)=>{let i=_(e),r=t.attributes;for(let o=0,s=r.length;o<s;o+=1){let a=r[o];i.setAttribute(a.name,a.value)}return n.replaceChild(i,t),i.appendChild(D(t)),i},Rs={1:"10",2:"13",3:"16",4:"18",5:"24",6:"32",7:"48"},Os={STRONG:Ft("B"),EM:Ft("I"),INS:Ft("U"),STRIKE:Ft("S"),SPAN:ks,FONT:(e,t,n)=>{let i=e,r=i.face,o=i.size,s=i.color,a=n.classNames,l,h,d,u,p;return r&&(l=_("SPAN",{class:a.fontFamily}),l.style.fontFamily=r,p=l,u=l),o&&(h=_("SPAN",{class:a.fontSize}),h.style.fontSize=Rs[o]+"px",p||(p=h),u&&u.appendChild(h),u=h),s&&/^#?([\dA-F]{3}){1,2}$/i.test(s)&&(s.charAt(0)!=="#"&&(s="#"+s),d=_("SPAN",{class:a.color}),d.style.color=s,p||(p=d),u&&u.appendChild(d),u=d),(!p||!u)&&(p=u=_("SPAN")),t.replaceChild(p,i),u.appendChild(D(i)),u},TT:(e,t,n)=>{let i=_("SPAN",{class:n.classNames.fontFamily,style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(i,e),i.appendChild(D(e)),i}},Ds=/^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT]|IV)|F(?:IGURE|IGCAPTION|OOTER)|H[1-6]|HEADER|L(?:ABEL|EGEND|I)|O(?:L|UTPUT)|P(?:RE)?|SECTION|T(?:ABLE|BODY|D|FOOT|H|HEAD|R)|COL(?:GROUP)?|UL)$/,Ms=/^(?:HEAD|META|STYLE)/,Fn=(e,t,n)=>{let i=e.childNodes,r=e;for(;L(r);)r=r.parentNode;let o=new re(r,5);for(let s=0,a=i.length;s<a;s+=1){let l=i[s],h=l.nodeName,d=Os[h];if(l instanceof HTMLElement){let u=l.childNodes.length;if(d)l=d(l,e,t);else if(Ms.test(h)){e.removeChild(l),s-=1,a-=1;continue}else if(!Ds.test(h)&&!L(l)){s-=1,a+=u-1,e.replaceChild(D(l),l);continue}u&&Fn(l,t,n||h==="PRE")}else{if(l instanceof Text){let u=l.data,p=!me.test(u.charAt(0)),b=!me.test(u.charAt(u.length-1));if(n||!p&&!b)continue;if(p){o.currentNode=l;let y;for(;(y=o.previousPONode())&&!(y.nodeName==="IMG"||y instanceof Text&&me.test(y.data));)if(!L(y)){y=null;break}u=u.replace(/^[ \t\r\n]+/g,y?" ":"")}if(b){o.currentNode=l;let y;for(;(y=o.nextNode())&&!(y.nodeName==="IMG"||y instanceof Text&&me.test(y.data));)if(!L(y)){y=null;break}u=u.replace(/[ \t\r\n]+$/g,y?" ":"")}if(u){l.data=u;continue}}e.removeChild(l),s-=1,a-=1}}return e},Un=e=>{let t=e.childNodes,n=t.length;for(;n--;){let i=t[n];i instanceof Element&&!ke(i)?(Un(i),L(i)&&!i.firstChild&&e.removeChild(i)):i instanceof Text&&!i.data&&e.removeChild(i)}},zn=(e,t,n)=>{let i=e.querySelectorAll("BR"),r=[],o=i.length;for(let s=0;s<o;s+=1)r[s]=Kt(i[s],n);for(;o--;){let s=i[o],a=s.parentNode;a&&(r[o]?L(a)||ge(a,t):W(s))}},ir=e=>e.split("&").join("&amp;").split("<").join("&lt;").split(">").join("&gt;").split('"').join("&quot;"),Wt=(e,t)=>{let n=new re(t,1,xe);return n.currentNode=e,n},Fe=(e,t)=>{let n=Wt(e,t).previousNode();return n!==t?n:null},Se=(e,t)=>{let n=Wt(e,t).nextNode();return n!==t?n:null},qn=e=>!e.textContent&&!e.querySelector("IMG"),oe=(e,t)=>{let n=e.startContainer,i;if(L(n))i=Fe(n,t);else if(n!==t&&n instanceof HTMLElement&&xe(n))i=n;else{let r=$n(n,e.startOffset);i=Se(r,t)}return i&&Ne(e,i,!0)?i:null},Ue=(e,t)=>{let n=e.endContainer,i;if(L(n))i=Fe(n,t);else if(n!==t&&n instanceof HTMLElement&&xe(n))i=n;else{let r=mr(n,e.endOffset);if(!r||!t.contains(r)){r=t;let o;for(;o=r.lastChild;)r=o}i=Fe(r,t)}return i&&Ne(e,i,!0)?i:null},yr=e=>e instanceof Text?me.test(e.data):e.nodeName==="IMG",mt=(e,t)=>{let n=e.startContainer,i=e.startOffset,r;if(n instanceof Text){let a=n.data;for(let l=i;l>0;l-=1)if(a.charAt(l-1)!=="\u200B")return!1;r=n}else if(r=mr(n,i),r&&!t.contains(r)&&(r=null),!r&&(r=$n(n,i),r instanceof Text&&r.length))return!1;let o=oe(e,t);if(!o)return!1;let s=new re(o,5,yr);return s.currentNode=r,!s.previousNode()},gt=(e,t)=>{let n=e.endContainer,i=e.endOffset,r;if(n instanceof Text){let a=n.data,l=a.length;for(let h=i;h<l;h+=1)if(a.charAt(h)!=="\u200B")return!1;r=n}else r=$n(n,i);let o=Ue(e,t);if(!o)return!1;let s=new re(o,5,yr);return s.currentNode=r,!s.nextNode()},rr=(e,t)=>{let n=oe(e,t),i=Ue(e,t),r;n&&i&&(r=n.parentNode,e.setStart(r,Array.from(r.childNodes).indexOf(n)),r=i.parentNode,e.setEnd(r,Array.from(r.childNodes).indexOf(i)+1))};function Be(e,t,n,i){let r=document.createRange();return r.setStart(e,t),n&&typeof i=="number"?r.setEnd(n,i):r.setEnd(e,t),r}var Ee=(e,t)=>{let{startContainer:n,startOffset:i,endContainer:r,endOffset:o}=e,s;if(n instanceof Text){let l=n.parentNode;if(s=l.childNodes,i===n.length)i=Array.from(s).indexOf(n)+1,e.collapsed&&(r=l,o=i);else{if(i){let h=n.splitText(i);r===n?(o-=i,r=h):r===l&&(o+=1),n=h}i=Array.from(s).indexOf(n)}n=l}else s=n.childNodes;let a=s.length;i===a?n.appendChild(t):n.insertBefore(t,s[i]),n===r&&(o+=s.length-a),e.setStart(n,i),e.setEnd(r,o)},br=(e,t,n)=>{let i=document.createDocumentFragment();if(e.collapsed)return i;t||(t=e.commonAncestorContainer),t instanceof Text&&(t=t.parentNode);let r=e.startContainer,o=e.startOffset,s=le(e.endContainer,e.endOffset,t,n),a=0,l=le(r,o,t,n);for(;l&&l!==s;){let h=l.nextSibling;i.appendChild(l),l=h}return l=s&&s.previousSibling,l&&l instanceof Text&&s instanceof Text&&(a=l.length,l.appendData(s.data),W(s),s=l),e.setStart(r,o),s?e.setEnd(s,a):e.setEnd(t,t.childNodes.length),K(t),i},or=(e,t,n)=>{e.currentNode=n;let i;for(;i=e[t]();){if(i instanceof Text||ke(i))return i;if(!L(i))return null}return null},qe=(e,t)=>{let n=oe(e,t),i=Ue(e,t),r=n!==i;n&&i&&(X(e),He(e,n,i,t));let o=br(e,null,t);X(e),r&&(i=Ue(e,t),n&&i&&n!==i&&pt(n,i,e,t)),n&&K(n);let s=t.firstChild;(!s||s.nodeName==="BR")&&(K(t),t.firstChild&&e.selectNodeContents(t.firstChild)),e.collapse(!0);let a=e.startContainer,l=e.startOffset,h=new re(t,5),d=a,u=l;(!(d instanceof Text)||u===d.data.length)&&(d=or(h,"nextNode",d),u=0);let p=a,b=l-1;(!(p instanceof Text)||b===-1)&&(p=or(h,"previousPONode",d||(a instanceof Text?a:a.childNodes[l]||a)),p instanceof Text&&(b=p.data.length));let y=null,E=0;return d instanceof Text&&d.data.charAt(u)===" "&&mt(e,t)?(y=d,E=u):p instanceof Text&&p.data.charAt(b)===" "&&(d instanceof Text&&d.data.charAt(u)===" "||gt(e,t))&&(y=p,E=b),y&&y.replaceData(E,1,"\xA0"),e.setStart(a,l),e.collapse(!0),o},Is=(e,t,n)=>{let i=t.firstChild&&L(t.firstChild),r;for(ge(t,n),r=t;r=Se(r,n);)K(r);e.collapsed||qe(e,n),X(e),e.collapse(!1);let o=w(e.endContainer,n,"BLOCKQUOTE")||n,s=oe(e,n),a=null,l=Se(t,t),h=!i&&!!s&&qn(s);if(s&&l&&!h&&!w(l,t,"PRE")&&!w(l,t,"TABLE")){He(e,s,s,n),e.collapse(!0);let d=e.endContainer,u=e.endOffset;if(zn(s,n,!1),L(d)){let p=le(d,u,Fe(d,n)||n,n);d=p.parentNode,u=Array.from(d.childNodes).indexOf(p)}if(u!==se(d))for(a=document.createDocumentFragment();r=d.childNodes[u];)a.appendChild(r);pt(d,l,e,n),d===n?e.setEnd(n,se(n)):(u=Array.from(d.parentNode.childNodes).indexOf(d)+1,d=d.parentNode,e.setEnd(d,u))}if(se(t)){h&&s&&(e.setEndBefore(s),e.collapse(!1),W(s)),o.contains(e.endContainer)||(n.contains(e.endContainer)||(e.setEnd(n,se(n)),e.collapse(!1)),o=w(e.endContainer,n,"BLOCKQUOTE")||n),He(e,o,o,n);let d=le(e.endContainer,e.endOffset,o,n),u=d?d.previousSibling:o.lastChild;o.insertBefore(t,d),d?e.setEndBefore(d):e.setEnd(o,se(o)),s=Ue(e,n),X(e);let p=e.endContainer,b=e.endOffset;d&&Je(d)&&ve(d,n),d=u&&u.nextSibling,d&&Je(d)&&ve(d,n),e.setEnd(p,b)}if(a&&s){let d=e.cloneRange();K(a),pt(s,a,d,n),e.setEnd(d.endContainer,d.endOffset)}X(e)},Tr=e=>{if(e.collapsed)return"";let t=e.startContainer,n=e.endContainer,i=new re(e.commonAncestorContainer,5,l=>Ne(e,l,!0));i.currentNode=t;let r=t,o="",s=!1,a;for((!(r instanceof Element)&&!(r instanceof Text)||!i.filter(r))&&(r=i.nextNode());r;)r instanceof Text?(a=r.data,a&&/\S/.test(a)&&(r===n&&(a=a.slice(0,e.endOffset)),r===t&&(a=a.slice(e.startOffset)),o+=a,s=!0)):(r.nodeName==="BR"||s&&!L(r))&&(o+=`
3
+ `,s=!1),r=i.nextNode();return o=o.replace(/ /g," "),o},Mn=Array.prototype.indexOf,_r=(e,t,n,i,r)=>{let o=r?"":Tr(e),s=oe(e,t),a=Ue(e,t),l=e.commonAncestorContainer,h=t;s===a&&s?.contains(l)&&(h=s);let d;for(n?(d=qe(e,t),l.isConnected||(l=e.commonAncestorContainer)):d=e.cloneContents(),l instanceof Text&&(l=l.parentNode);l&&l!==h;){let p=l.cloneNode(!1);p.appendChild(d),d=p,l=l.parentNode}let u;if(d.childNodes.length===1&&d.childNodes[0]instanceof Text)o=d.childNodes[0].data.replace(/ /g," "),u=void 0;else{let p=_("DIV");p.appendChild(d),u=p.innerHTML,i&&(u=i(u))}return r&&u!==void 0&&(o=r(u)),o===u&&(u=void 0),cr&&(o=o.replace(/\r?\n/g,`\r
4
+ `)),u&&(u="<!-- squire -->"+u),[o,u]},Er=(e,t,n,i,r,o,s)=>{let a=e.clipboardData;if(zt||!a)return!1;let[l,h]=_r(t,n,i,r,o);return e.preventDefault(),!s&&h&&a.setData("text/html",h),a.setData("text/plain",l),!0},Ps=function(e){let t=this.getSelection(),n=this._root;if(t.collapsed){e.preventDefault();return}this.saveUndoState(t),Er(e,t,n,!0,this._config.willCutCopy,this._config.toPlainText,!1)||setTimeout(()=>{try{this._ensureBottomLine()}catch(i){this._config.didError(i)}},0),this.setSelection(t)},Bs=function(e){Er(e,this.getSelection(),this._root,!1,this._config.willCutCopy,this._config.toPlainText,!1)},sr=function(e){this._isShiftDown=e.shiftKey},Hs=function(e){let t=e.clipboardData,n=t?.items,i=this._isShiftDown,r=!1,o=!1,s=null,a=null;if(n){let S=n.length;for(;S--;){let N=n[S],P=N.type;P==="text/html"?a=N:P==="text/plain"||P==="text/uri-list"?s=N:P==="text/rtf"?r=!0:/^image\/.*/.test(P)&&(o=!0)}if(o&&!(r&&a)&&!s){e.preventDefault(),this.fireEvent("pasteImage",{clipboardData:t});return}if(!zt){e.preventDefault(),a&&(!i||!s)?a.getAsString(N=>{this.insertHTML(N,!0)}):s&&s.getAsString(N=>{let P=this.getSelection();if(!P.collapsed&&me.test(P.toString())){let J=this.linkRegExp.exec(N);if(J&&J[0].length===N.length){let U=J[1]?/^(?:ht|f)tps?:/i.test(J[1])?J[1]:"http://"+J[1]:"mailto:"+J[0];this.makeLink(U);return}}this.insertPlainText(N,!0)});return}}let l=t?.types;if(!zt&&l&&(Mn.call(l,"text/html")>-1||!Ts&&Mn.call(l,"text/plain")>-1&&Mn.call(l,"text/rtf")<0)){e.preventDefault();let S;!i&&(S=t.getData("text/html"))?this.insertHTML(S,!0):((S=t.getData("text/plain"))||(S=t.getData("text/uri-list")))&&this.insertPlainText(S,!0);return}let h=document.body,d=this.getSelection(),u=d.startContainer,p=d.startOffset,b=d.endContainer,y=d.endOffset,E=_("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});h.appendChild(E),d.selectNodeContents(E),this.setSelection(d),setTimeout(()=>{try{let S="",N=E,P;for(;E=N;)N=E.nextSibling,W(E),P=E.firstChild,P&&P===E.lastChild&&P instanceof HTMLDivElement&&(E=P),S+=E.innerHTML;this.setSelection(Be(u,p,b,y)),S&&this.insertHTML(S,!0)}catch(S){this._config.didError(S)}},0)},Fs=function(){let e=this.getSelection();e&&!e.collapsed&&this._root.contains(e.commonAncestorContainer)?this._dragRange=e.cloneRange():this._dragRange=null},Us=function(){this._dragRange=null},zs=(e,t,n)=>{let i=null,r=document;if(r.caretPositionFromPoint){let o=r.caretPositionFromPoint(e,t);o&&(i=document.createRange(),i.setStart(o.offsetNode,o.offset),i.collapse(!0))}else r.caretRangeFromPoint&&(i=r.caretRangeFromPoint(e,t));return i&&!n.contains(i.commonAncestorContainer)?null:i},qs=(e,t)=>e.compareBoundaryPoints(Range.START_TO_START,t)>=0&&e.compareBoundaryPoints(Range.END_TO_END,t)<=0,Ws=function(e){let t=e.dataTransfer;if(!t)return;let n=t.types,i=!1,r=!1;for(let d=0,u=n.length;d<u;d+=1)switch(n[d]){case"text/plain":i=!0;break;case"text/html":r=!0;break}if(!i&&!r)return;e.preventDefault();let o=this._root,s=zs(e.clientX,e.clientY,o),a=this._dragRange;if(this._dragRange=null,!s)return;let l,h;if(a){if(qs(s,a))return;this._recordUndoState(a,this._isInUndoState);let d=document.createComment("");s.insertNode(d),this._getRangeAndRemoveBookmark(a),[l,h]=_r(a,o,t.dropEffect!=="copy",this._config.willCutCopy,this._config.toPlainText),d.replaceWith(_("INPUT",{id:this.startSelectionId,type:"hidden"}),_("INPUT",{id:this.endSelectionId,type:"hidden"})),this._getRangeAndRemoveBookmark(s),fr()}else this.saveUndoState(s),r?h=t.getData("text/html"):l=t.getData("text/plain");this.setSelection(s),h!==void 0?this.insertHTML(h,!0):l!==void 0&&this.insertPlainText(l,!0)},ar=(e,t,n)=>{t.preventDefault(),e.splitBlock(t.shiftKey,n)},ft=(e,t)=>{try{t||(t=e.getSelection());let n=t.startContainer;n instanceof Text&&(n=n.parentNode);let i=n;for(;i!==e._root&&L(i)&&(!i.textContent||i.textContent==="\u200B");)n=i,i=n.parentNode;n!==i&&(t.setStart(i,Array.from(i.childNodes).indexOf(n)),t.collapse(!0),i.removeChild(n),xe(i)||(i=Fe(i,e._root)||e._root),K(i),X(t)),n===e._root&&(n=n.firstChild)&&n.nodeName==="BR"&&W(n),e._ensureBottomLine(),e.setSelection(t),e._updatePath(t,!0)}catch(n){e._config.didError(n)}},vr=(e,t)=>{let n;for(;(n=e.parentNode)&&!(n===t||n.isContentEditable);)e=n;W(e)},Sr=(e,t,n)=>{if(w(t,e._root,"A"))return;let i=t.data||"",r=Math.max(i.lastIndexOf(" ",n-1),i.lastIndexOf("\xA0",n-1))+1,o=i.slice(r,n),s=e.linkRegExp.exec(o);if(s){let a=e.getSelection();e._docWasChanged(),e._recordUndoState(a),e._getRangeAndRemoveBookmark(a);let l=r+s.index,h=l+s[0].length,d=a.startContainer===t,u=a.startOffset-h;l&&(t=t.splitText(l));let p=e._config.tagAttributes.a,b=_("A",Object.assign({href:s[1]?/^(?:ht|f)tps?:/i.test(s[1])?s[1]:"http://"+s[1]:"mailto:"+s[0]},p));b.textContent=i.slice(l,h),t.parentNode.insertBefore(b,t),t.data=i.slice(h),d&&(a.setStart(t,u),a.setEnd(t,u)),e.setSelection(a)}},Ks=(e,t,n)=>{let i=e._root;if(e._removeZWS(),e.saveUndoState(n),!n.collapsed)t.preventDefault(),qe(n,i),ft(e,n);else if(mt(n,i)){t.preventDefault();let r=oe(n,i);if(!r)return;let o=r;ge(o.parentNode,i);let s=Fe(o,i);if(s){if(!s.isContentEditable){vr(s,i);return}for(pt(s,o,n,i),o=s.parentNode;o!==i&&!o.nextSibling;)o=o.parentNode;o!==i&&(o=o.nextSibling)&&ve(o,i),e.setSelection(n)}else if(o){if(w(o,i,"UL")||w(o,i,"OL")){e.decreaseListLevel(n);return}else if(w(o,i,"BLOCKQUOTE")){e.removeQuote(n);return}e.setSelection(n),e._updatePath(n,!0)}}else{X(n);let r=n.startContainer,o=n.startOffset,s=r.parentNode;r instanceof Text&&s instanceof HTMLAnchorElement&&o&&s.href.includes(r.data)?(r.deleteData(o-1,1),e.setSelection(n),e.removeLink(),t.preventDefault()):(e.setSelection(n),setTimeout(()=>{ft(e)},0))}},$s=(e,t,n)=>{let i=e._root,r,o,s,a,l,h;if(e._removeZWS(),e.saveUndoState(n),!n.collapsed)t.preventDefault(),qe(n,i),ft(e,n);else if(gt(n,i)){if(t.preventDefault(),r=oe(n,i),!r)return;if(ge(r.parentNode,i),o=Se(r,i),o){if(!o.isContentEditable){vr(o,i);return}for(pt(r,o,n,i),o=r.parentNode;o!==i&&!o.nextSibling;)o=o.parentNode;o!==i&&(o=o.nextSibling)&&ve(o,i),e.setSelection(n),e._updatePath(n,!0)}}else{if(s=n.cloneRange(),He(n,i,i,i),a=n.endContainer,l=n.endOffset,a instanceof Element&&(h=a.childNodes[l],h&&h.nodeName==="IMG")){t.preventDefault(),W(h),X(n),ft(e,n);return}e.setSelection(s),setTimeout(()=>{ft(e)},0)}},Vs=(e,t,n)=>{let i=e._root;if(e._removeZWS(),n.collapsed&&mt(n,i)){let r=oe(n,i),o;for(;o=r.parentNode;){if(o.nodeName==="UL"||o.nodeName==="OL"){t.preventDefault(),e.increaseListLevel(n);break}r=o}}},Gs=(e,t,n)=>{let i=e._root;if(e._removeZWS(),n.collapsed&&mt(n,i)){let r=n.startContainer;(w(r,i,"UL")||w(r,i,"OL"))&&(t.preventDefault(),e.decreaseListLevel(n))}},js=(e,t,n)=>{let i,r=e._root;if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),!n.collapsed)qe(n,r),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0);else if(gt(n,r)){let o=oe(n,r);if(o&&o.nodeName!=="PRE"){let s=o.textContent?.trimEnd().replace("\u200B","");if(s==="*"||s==="1."){t.preventDefault(),e.insertPlainText(" ",!1),e._docWasChanged(),e.saveUndoState(n);let a=new re(o,4),l;for(;l=a.nextNode();)W(l);s==="*"?e.makeUnorderedList():e.makeOrderedList();return}}}if(i=n.endContainer,n.endOffset===se(i))do if(i.nodeName==="A"){n.setStartAfter(i);break}while(!i.nextSibling&&(i=i.parentNode)&&i!==r);if(e._config.addLinks){let o=n.cloneRange();X(o);let s=o.startContainer,a=o.startOffset;setTimeout(()=>{Sr(e,s,a)},0)}e.setSelection(n)},Zs=function(e){if(e.defaultPrevented||e.isComposing)return;let t=e.key,n="",i=e.code;/^Digit\d$/.test(i)&&(t=i.slice(-1)),t!=="Backspace"&&t!=="Delete"&&(e.altKey&&(n+="Alt-"),e.ctrlKey&&(n+="Ctrl-"),e.metaKey&&(n+="Meta-"),e.shiftKey&&(n+="Shift-")),cr&&e.shiftKey&&t==="Delete"&&(n+="Shift-"),t=n+t;let r=this.getSelection(),o=this._keyHandlers[t];o?o(this,e,r):!r.collapsed&&!e.ctrlKey&&!e.metaKey&&t.length===1&&(this.saveUndoState(r),qe(r,this._root),this._ensureBottomLine(),this.setSelection(r),this._updatePath(r,!0))},H={Backspace:Ks,Delete:$s,Tab:Vs,"Shift-Tab":Gs," ":js,ArrowLeft(e){e._removeZWS()},ArrowRight(e,t,n){e._removeZWS();let i=e.getRoot();if(gt(n,i)){X(n);let r=n.endContainer;do if(r.nodeName==="CODE"){let o=r.nextSibling;if(!(o instanceof Text)||o.length===0){let s=document.createTextNode("\xA0");r.parentNode.insertBefore(s,o),o=s}n.setStart(o,1),e.setSelection(n),t.preventDefault();break}while(!r.nextSibling&&(r=r.parentNode)&&r!==i)}}};Es||(H.Enter=ar,H["Shift-Enter"]=ar);!Wn&&!hr&&(H.PageUp=e=>{e.moveCursorToStart()},H.PageDown=e=>{e.moveCursorToEnd()});var et=(e,t)=>(t=t||null,(n,i)=>{i.preventDefault();let r=n.getSelection();n.hasFormat(e,null,r)?n.changeFormat(null,{tag:e},r):n.changeFormat({tag:e},t,r)});H[te+"b"]=et("B");H[te+"i"]=et("I");H[te+"u"]=et("U");H[te+"Shift-7"]=et("S");H[te+"Shift-5"]=et("SUB",{tag:"SUP"});H[te+"Shift-6"]=et("SUP",{tag:"SUB"});H[te+"Shift-8"]=(e,t)=>{t.preventDefault();let n=e.getPath();/(?:^|>)UL/.test(n)?e.removeList():e.makeUnorderedList()};H[te+"Shift-9"]=(e,t)=>{t.preventDefault();let n=e.getPath();/(?:^|>)OL/.test(n)?e.removeList():e.makeOrderedList()};H[te+"["]=(e,t)=>{t.preventDefault();let n=e.getPath();/(?:^|>)BLOCKQUOTE/.test(n)||!/(?:^|>)[OU]L/.test(n)?e.decreaseQuoteLevel():e.decreaseListLevel()};H[te+"]"]=(e,t)=>{t.preventDefault();let n=e.getPath();/(?:^|>)BLOCKQUOTE/.test(n)||!/(?:^|>)[OU]L/.test(n)?e.increaseQuoteLevel():e.increaseListLevel()};H[te+"d"]=(e,t)=>{t.preventDefault(),e.toggleCode()};H[te+"z"]=(e,t)=>{t.preventDefault(),e.undo()};H[te+"y"]=H[te+"Shift-z"]=H[te+"Shift-Z"]=(e,t)=>{t.preventDefault(),e.redo()};var In=8,lr=40,Pn=1200,Ys=[{pos:"nw",cursor:"nwse-resize"},{pos:"n",cursor:"ns-resize"},{pos:"ne",cursor:"nesw-resize"},{pos:"e",cursor:"ew-resize"},{pos:"se",cursor:"nwse-resize"},{pos:"s",cursor:"ns-resize"},{pos:"sw",cursor:"nesw-resize"},{pos:"w",cursor:"ew-resize"}],Xs={ArrowUp:(e,t,n)=>{let i=oe(t,n);if(i){let r=Fe(i,n);r&&(t.selectNodeContents(r),t.collapse(!1),e.setSelection(t).focus())}},ArrowDown:(e,t,n)=>{let i=oe(t,n);if(i){let r=Se(i,n);r&&(t.selectNodeContents(r),t.collapse(!0),e.setSelection(t).focus())}},Delete:(e,t)=>{e.replaceWithBlankLine(t)},Backspace:(e,t)=>{e.replaceWithBlankLine(t)}},Qs=class{constructor(e,t){this._currentImage=null,this._resizeContainer=null,this._handles=null,this._currentHandle=null,this._startX=0,this._startY=0,this._startWidth=0,this._startHeight=0,this._maxWidth=Pn,this._originalRatio=1,this._editor=t,this._root=e,document.addEventListener("click",this),t.addEventListener("drop",this)}destroy(){this._deselectImage(),this._editor.removeEventListener("drop",this),document.removeEventListener("click",this)}handleEvent(e){switch(e.type){case"click":this._onClick(e);break;case"pointerdown":this._onPointerDown(e);break;case"pointermove":this._onPointerMove(e);break;case"pointercancel":case"pointerup":this._onPointerUp(e);break;case"keydown":this._onKeyDown(e);break;case"drop":this._deselectImage();break}}_onClick(e){let t=e.target;t.nodeName==="IMG"&&this._root.contains(t)?(e.stopPropagation(),this._selectImage(t)):this._currentImage&&this._handles&&!this._handles.some(n=>n.element===t)&&this._deselectImage()}_deselectImage(){this._currentImage&&(document.removeEventListener("keydown",this,!0),this._currentHandle&&this._onPointerUp({preventDefault(){},target:this._currentHandle.element}),this._handles&&this._handles.forEach(({element:e})=>e.removeEventListener("pointerdown",this)),this._resizeContainer&&this._resizeContainer.remove(),this._currentImage.removeAttribute("tabindex"),this._handles=null,this._resizeContainer=null,this._currentImage=null)}_selectImage(e){if(this._currentImage===e)return;this._deselectImage(),this._root.blur();let t=Ys.map(({pos:r,cursor:o})=>{let s=In/2,a="";switch(r){case"nw":a=`left: -${s}px; top: -${s}px;`;break;case"n":a=`left: calc(50% - ${s}px); top: -${s}px;`;break;case"ne":a=`right: -${s}px; top: -${s}px;`;break;case"e":a=`right: -${s}px; top: calc(50% - ${s}px);`;break;case"se":a=`right: -${s}px; bottom: -${s}px;`;break;case"s":a=`left: calc(50% - ${s}px); bottom: -${s}px;`;break;case"sw":a=`left: -${s}px; bottom: -${s}px;`;break;case"w":a=`left: -${s}px; top: calc(50% - ${s}px);`;break}let l=_("div",{class:`squire-resize-handle squire-resize-handle-${r}`,style:`
5
5
  position: absolute;
6
- width: ${On}px;
7
- height: ${On}px;
6
+ width: ${In}px;
7
+ height: ${In}px;
8
8
  background: #0067b9;
9
9
  border: 1px solid #fff;
10
10
  cursor: ${o};
@@ -12,27 +12,27 @@ var richclay=(()=>{var kn=Object.defineProperty;var ds=Object.getOwnPropertyDesc
12
12
  touch-action: none;
13
13
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
14
14
  ${a}
15
- `});return l.addEventListener("pointerdown",this),{element:l,cursor:o,position:r}}),n=_("div",{class:"squire-image-resize-container","editor-ui":"",style:"position: absolute; pointer-events: none; z-index: 1000;"},t.map(r=>r.element));this._currentImage=e,this._resizeContainer=n,this._handles=t,this._root.appendChild(this._resizeContainer);let i=e.naturalWidth;this._originalRatio=i/e.naturalHeight,this._maxWidth=Math.min(i*2,e.parentElement?e.parentElement.offsetWidth:Dn,Dn),this._positionResizeContainer(),e.tabIndex=-1,e.focus(),document.addEventListener("keydown",this,!0)}_positionResizeContainer(){let e=this._resizeContainer,t=this._root,n=this._currentImage;if(!e||!n)return;let i=t.getBoundingClientRect(),r=n.getBoundingClientRect(),o=r.top-i.top+t.scrollTop,s=r.left-i.left+t.scrollLeft,a=r.width,l=r.height;e.style.top=o+"px",e.style.left=s+"px",e.style.width=a+"px",e.style.height=l+"px"}_onPointerDown(e){if(this._currentHandle||!this._handles)return;let t=e.target,n=this._handles.find(o=>o.element===t)||null;if(!n)return;let i=this._currentImage;if(!i)return;e.preventDefault(),e.stopPropagation(),t.addEventListener("pointermove",this),t.addEventListener("pointerup",this),t.addEventListener("pointercancel",this),t.setPointerCapture(e.pointerId),this._currentHandle=n,this._startX=e.clientX,this._startY=e.clientY;let r=getComputedStyle(i);this._startWidth=parseFloat(r.width),this._startHeight=parseFloat(r.height),document.body.style.cursor=n.cursor}_onPointerMove(e){e.preventDefault();let t=this._currentHandle,n=this._currentImage;if(!t||!n)return;let i=e.clientX-this._startX,r=e.clientY-this._startY,o=this._maxWidth,s=this._originalRatio,a=this._startWidth,l=this._startHeight;switch(t.position){case"sw":case"nw":case"w":a-=2*i;break;case"se":case"ne":case"e":a+=2*i;break;case"n":l-=r,a=l*s;break;case"s":l+=r,a=l*s;break}a<sr?a=sr:a>o&&(a=o);let h=n.style;h.width=a+"px",h.height="auto",this._positionResizeContainer()}_onPointerUp(e){e.preventDefault();let t=e.target;t&&(t.removeEventListener("pointermove",this),t.removeEventListener("pointerup",this),t.removeEventListener("pointercancel",this)),this._currentHandle=null,document.body.style.cursor=""}_onKeyDown(e){e.preventDefault(),e.stopPropagation();let t=Xs[e.key];if(!t)return;let n=this._currentImage;if(!n)return;let i=this._editor,r=this._root;this._deselectImage();let o=i.getSelection();o.selectNode(n),t(i,o,r)}},Js=class{constructor(e,t){this.customEvents=new Set(["pathChange","select","input","pasteImage","undoStateChange"]),this.startSelectionId="squire-selection-start",this.endSelectionId="squire-selection-end",this.linkRegExp=/\b(?:((?:(?:ht|f)tps?:\/\/|www\d{0,3}[.]|[a-z0-9][a-z0-9.\-]*[.][a-z]{2,}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:[^\s?&`!()\[\]{};:'".,<>«»“”‘’]|\([^\s()<>]+\)))|([\w\-.%+]+@(?:[\w\-]+\.)+[a-z]{2,}\b(?:[?][^&?\s]+=[^\s?&`!()\[\]{};:'".,<>«»“”‘’]+(?:&[^&?\s]+=[^\s?&`!()\[\]{};:'".,<>«»“”‘’]+)*)?))/i,this.tagAfterSplit={DT:"DD",DD:"DT",LI:"LI",PRE:"PRE"},this._root=e,this._config=this._makeConfig(t),this._isFocused=!1,this._lastSelection=Be(e,0),this._willRestoreSelection=!1,this._mayHaveZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="",this._events=new Map,this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this._ignoreChange=!1,this._ignoreAllChanges=!1,this.addEventListener("selectionchange",this._updatePathOnEvent),this.addEventListener("blur",this._enableRestoreSelection),this.addEventListener("mousedown",this._disableRestoreSelection),this.addEventListener("touchstart",this._disableRestoreSelection),this.addEventListener("focus",this._restoreSelection),this.addEventListener("blur",this._removeZWS),this._isShiftDown=!1,this.addEventListener("cut",Ps),this.addEventListener("copy",Bs),this.addEventListener("paste",Hs),this._dragRange=null,this.addEventListener("dragstart",Fs),this.addEventListener("dragend",Us),this.addEventListener("drop",Ws),this.addEventListener("keydown",rr),this.addEventListener("keyup",rr),this.addEventListener("keydown",Zs),this._keyHandlers=Object.create(H);let n=new MutationObserver(i=>this._onMutations(i));n.observe(e,{childList:!0,attributes:!0,attributeOldValue:!0,characterData:!0,subtree:!0}),this._mutation=n,e.setAttribute("contenteditable","true"),this.addEventListener("beforeinput",this._beforeInput),this._imageResizer=new Qs(e,this),this.setHTML("")}destroy(){this._events.forEach((e,t)=>{this.removeEventListener(t)}),this._mutation.disconnect(),this._imageResizer.destroy(),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0}_makeConfig(e){let t={blockTag:"DIV",blockAttributes:null,tagAttributes:{},classNames:{color:"color",fontFamily:"font",fontSize:"size",highlight:"highlight"},undo:{documentSizeThreshold:-1,undoLimit:-1},addLinks:!0,willCutCopy:null,toPlainText:null,sanitizeToDOMFragment:n=>{let i=DOMPurify.sanitize(n,{ALLOW_UNKNOWN_PROTOCOLS:!0,WHOLE_DOCUMENT:!1,RETURN_DOM:!0,RETURN_DOM_FRAGMENT:!0,FORCE_BODY:!1});return i?document.importNode(i,!0):document.createDocumentFragment()},didError:n=>console.log(n)};return e&&(Object.assign(t,e),t.blockTag=t.blockTag.toUpperCase()),t}setKeyHandler(e,t){return this._keyHandlers[e]=t,this}_beforeInput(e){switch(e.inputType){case"insertLineBreak":e.preventDefault(),this.splitBlock(!0);break;case"insertParagraph":e.preventDefault(),this.splitBlock(!1);break;case"insertOrderedList":e.preventDefault(),this.makeOrderedList();break;case"insertUnoderedList":e.preventDefault(),this.makeUnorderedList();break;case"historyUndo":e.preventDefault(),this.undo();break;case"historyRedo":e.preventDefault(),this.redo();break;case"formatBold":e.preventDefault(),this.bold();break;case"formatItalic":e.preventDefault(),this.italic();break;case"formatUnderline":e.preventDefault(),this.underline();break;case"formatStrikeThrough":e.preventDefault(),this.strikethrough();break;case"formatSuperscript":e.preventDefault(),this.superscript();break;case"formatSubscript":e.preventDefault(),this.subscript();break;case"formatJustifyFull":case"formatJustifyCenter":case"formatJustifyRight":case"formatJustifyLeft":{e.preventDefault();let t=e.inputType.slice(13).toLowerCase();t==="full"&&(t="justify"),this.setTextAlignment(t);break}case"formatRemove":e.preventDefault(),this.removeAllFormatting();break;case"formatSetBlockTextDirection":{e.preventDefault();let t=e.data;t==="null"&&(t=null),this.setTextDirection(t);break}case"formatBackColor":e.preventDefault(),this.setHighlightColor(e.data);break;case"formatFontColor":e.preventDefault(),this.setTextColor(e.data);break;case"formatFontName":e.preventDefault(),this.setFontFace(e.data);break}}handleEvent(e){this.fireEvent(e.type,e)}fireEvent(e,t){let n=this._events.get(e);if(/^(?:focus|blur)/.test(e)){let i=this._root===document.activeElement;if(e==="focus"){if(!i||this._isFocused)return this;this._isFocused=!0}else{if(i||!this._isFocused)return this;this._isFocused=!1}}if(n){let i=t instanceof Event?t:new CustomEvent(e,{detail:t});n=n.slice();for(let r of n)try{"handleEvent"in r?r.handleEvent(i):r.call(this,i)}catch(o){this._config.didError(o)}}return this}addEventListener(e,t){let n=this._events.get(e),i=this._root;return n||(n=[],this._events.set(e,n),this.customEvents.has(e)||(e==="selectionchange"&&(i=document),i.addEventListener(e,this,!0))),n.push(t),this}removeEventListener(e,t){let n=this._events.get(e),i=this._root;if(n){if(t){let r=n.length;for(;r--;)n[r]===t&&n.splice(r,1)}else n.length=0;n.length||(this._events.delete(e),this.customEvents.has(e)||(e==="selectionchange"&&(i=document),i.removeEventListener(e,this,!0)))}return this}focus(){return this._root.focus({preventScroll:!0}),this}blur(){return this._root.blur(),this}_enableRestoreSelection(){this._willRestoreSelection=!0}_disableRestoreSelection(){this._willRestoreSelection=!1}_restoreSelection(){this._willRestoreSelection&&this.setSelection(this._lastSelection)}_removeZWS(){this._mayHaveZWS&&(Ht(this._root),this._mayHaveZWS=!1)}_saveRangeToBookmark(e){let t=_("INPUT",{id:this.startSelectionId,type:"hidden"}),n=_("INPUT",{id:this.endSelectionId,type:"hidden"}),i;_e(e,t),e.collapse(!1),_e(e,n),t.compareDocumentPosition(n)&Node.DOCUMENT_POSITION_PRECEDING&&(t.id=this.endSelectionId,n.id=this.startSelectionId,i=t,t=n,n=i),e.setStartAfter(t),e.setEndBefore(n)}_getRangeAndRemoveBookmark(e){let t=this._root,n=t.querySelectorAll("#"+this.startSelectionId),i=t.querySelectorAll("#"+this.endSelectionId),r=n[0],o=i[0];if(r&&o&&r.compareDocumentPosition(o)&Node.DOCUMENT_POSITION_FOLLOWING){let s=r.parentNode,a=o.parentNode,l=Array.from(s.childNodes).indexOf(r),h=Array.from(a.childNodes).indexOf(o);s===a&&(h-=1),r.remove(),o.remove(),e||(e=document.createRange()),e.setStart(s,l),e.setEnd(a,h),Xe(s,e),s!==a&&Xe(a,e),e.collapsed&&(s=e.startContainer,s instanceof Text&&(a=s.childNodes[e.startOffset],(!a||!(a instanceof Text))&&(a=s.childNodes[e.startOffset-1]),a&&a instanceof Text&&(e.setStart(a,0),e.collapse(!0))))}for(let s=0;s<n.length;s+=1)n[s].remove();for(let s=0;s<i.length;s+=1)i[s].remove();return e||null}getSelection(){let e=window.getSelection(),t=this._root,n=null;if(this._isFocused&&e&&e.rangeCount){n=e.getRangeAt(0).cloneRange();let i=n.startContainer,r=n.endContainer;i&&ke(i)&&n.setStartBefore(i),r&&ke(r)&&n.setEndBefore(r)}return n&&t.contains(n.commonAncestorContainer)?this._lastSelection=n:(n=this._lastSelection,document.contains(n.commonAncestorContainer)||(n=null)),n||(n=Be(t.firstElementChild||t,0)),n}setSelection(e){if(this._lastSelection=e,!this._isFocused)this._enableRestoreSelection();else{let t=window.getSelection();t&&("setBaseAndExtent"in Selection.prototype?t.setBaseAndExtent(e.startContainer,e.startOffset,e.endContainer,e.endOffset):(t.removeAllRanges(),t.addRange(e)))}return this}_moveCursorTo(e){let t=this._root,n=Be(t,e?0:t.childNodes.length);return X(n),this.setSelection(n),this}moveCursorToStart(){return this._moveCursorTo(!0)}moveCursorToEnd(){return this._moveCursorTo(!1)}getCursorPosition(){let e=this.getSelection(),t=e.getBoundingClientRect();if(t&&!t.top){this._ignoreChange=!0;let n=_("SPAN");n.textContent="\u200B",_e(e,n),t=n.getBoundingClientRect();let i=n.parentNode;i.removeChild(n),Xe(i,e)}return t}getPath(){return this._path}_updatePathOnEvent(){this._isFocused&&this._updatePath(this.getSelection())}_updatePath(e,t){let n=e.startContainer,i=e.endContainer,r;(t||n!==this._lastAnchorNode||i!==this._lastFocusNode)&&(this._lastAnchorNode=n,this._lastFocusNode=i,r=n&&i?n===i?this._getPath(i):"(selection)":"",(this._path!==r||n!==i)&&(this._path=r,this.fireEvent("pathChange",{path:r}))),this.fireEvent(e.collapsed?"cursor":"select",{range:e})}_getPath(e){let t=this._root,n=this._config,i="";if(e&&e!==t){let r=e.parentNode;if(i=r?this._getPath(r):"",e instanceof HTMLElement){let o=e.id,s=e.classList,a=Array.from(s).sort(),l=e.dir,h=n.classNames;i+=(i?">":"")+e.nodeName,o&&(i+="#"+o),a.length&&(i+=".",i+=a.join(".")),l&&(i+="[dir="+l+"]"),s.contains(h.highlight)&&(i+="[backgroundColor="+e.style.backgroundColor.replace(/ /g,"")+"]"),s.contains(h.color)&&(i+="[color="+e.style.color.replace(/ /g,"")+"]"),s.contains(h.fontFamily)&&(i+="[fontFamily="+e.style.fontFamily.replace(/ /g,"")+"]"),s.contains(h.fontSize)&&(i+="[fontSize="+e.style.fontSize+"]")}}return i}modifyDocument(e){let t=this._mutation;return t&&((()=>{let n=t.takeRecords();n.length&&this._onMutations(n)})(),t.disconnect()),this._ignoreAllChanges=!0,e(),this._ignoreAllChanges=!1,t&&(t.observe(this._root,{childList:!0,attributes:!0,attributeOldValue:!0,characterData:!0,subtree:!0}),this._ignoreChange=!1),this}_onMutations(e){let t=this._config.onMutations;return t?t(e,this):this._docWasChanged()}_docWasChanged(){if(ur(),this._mayHaveZWS=!0,!this._ignoreAllChanges){if(this._ignoreChange){this._ignoreChange=!1;return}this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}}_recordUndoState(e,t){let n=this._isInUndoState;if(!n||t){let i=this._undoIndex+1,r=this._undoStack,o=this._config.undo,s=o.documentSizeThreshold,a=o.undoLimit;if(i<this._undoStackLength&&(r.length=this._undoStackLength=i),e&&this._saveRangeToBookmark(e),n)return this;let l=this._getRawHTML();t&&(i-=1),s>-1&&l.length*2>s&&a>-1&&i>a&&(r.splice(0,i-a),i=a,this._undoStackLength=a),r[i]=l,this._undoIndex=i,this._undoStackLength+=1,this._isInUndoState=!0}return this}saveUndoState(e){let t=!1;return e||(e=this.getSelection(),t=!0),this._recordUndoState(e,this._isInUndoState),this._getRangeAndRemoveBookmark(e),t&&this.setSelection(e),this}undo(){if(this._undoIndex!==0||!this._isInUndoState){this._recordUndoState(this.getSelection(),!1),this._undoIndex-=1,this._setRawHTML(this._undoStack[this._undoIndex]);let e=this._getRangeAndRemoveBookmark();e&&this.setSelection(e),this._isInUndoState=!0,this.fireEvent("undoStateChange",{canUndo:this._undoIndex!==0,canRedo:!0}),this.fireEvent("input")}return this.focus()}redo(){let e=this._undoIndex,t=this._undoStackLength;if(e+1<t&&this._isInUndoState){this._undoIndex+=1,this._setRawHTML(this._undoStack[this._undoIndex]);let n=this._getRangeAndRemoveBookmark();n&&this.setSelection(n),this.fireEvent("undoStateChange",{canUndo:!0,canRedo:e+2<t}),this.fireEvent("input")}return this.focus()}getRoot(){return this._root}_getRawHTML(){let e=this._config.serializeRoot;return e?e(this._root,this):this._root.innerHTML}_setRawHTML(e){let t=this._root;this._config.replaceRoot?this._config.replaceRoot(t,e,this):t.innerHTML=e;let n=t,i=n.firstChild;if(!i||i.nodeName==="BR"){let r=this.createDefaultBlock();i?n.replaceChild(r,i):n.appendChild(r)}else for(;n=ve(n,t);)$(n);return this._ignoreChange=!0,this}getHTML(e){if(this._config.serializeRoot)return this._config.serializeRoot(this._root,this,e?this.getSelection():null).replace(/\u200B/g,"");let t,n="";return this.modifyDocument(()=>{e&&(t=this.getSelection(),this._saveRangeToBookmark(t)),n=this._getRawHTML().replace(/\u200B/g,""),e&&this._getRangeAndRemoveBookmark(t)}),n}setHTML(e){let t=this._config.sanitizeToDOMFragment(e,this),n=this._root;Pn(t,this._config),Hn(t,n,!1),ge(t,n);let i=t,r=i.firstChild;if(!r||r.nodeName==="BR"){let s=this.createDefaultBlock();r?i.replaceChild(s,r):i.appendChild(s)}else for(;i=ve(i,n);)$(i);for(this._ignoreChange=!0;r=n.lastChild;)n.removeChild(r);n.appendChild(t),this._undoIndex=-1,this._undoStack.length=0,this._undoStackLength=0,this._isInUndoState=!1;let o=this._getRangeAndRemoveBookmark()||Be(n.firstElementChild||n,0);return this.saveUndoState(o),this.setSelection(o),this._updatePath(o,!0),this}insertHTML(e,t){let n=this._config,i=n.sanitizeToDOMFragment(e,this),r=this.getSelection();this.saveUndoState(r);try{let o=this._root;n.addLinks&&this.addDetectedLinks(i,i),Pn(i,this._config),Hn(i,o,!1),Bn(i),i.normalize();let s=i;for(;s=ve(s,i);)$(s);let a=!0;if(t){let l=new CustomEvent("willPaste",{cancelable:!0,detail:{html:e,fragment:i}});this.fireEvent("willPaste",l),i=l.detail.fragment,a=!l.defaultPrevented}a&&(Ms(r,i,o),r.collapse(!1),Ji(r,"A",o),this._ensureBottomLine()),this.setSelection(r),this._updatePath(r,!0),t&&this.focus()}catch(o){this._config.didError(o)}return this}insertElement(e,t){if(t||(t=this.getSelection()),t.collapse(!0),L(e))_e(t,e),t.setStartAfter(e);else{let n=this._root,i=oe(t,n),r=i||n,o=null;for(;r!==n&&!r.nextSibling;)r=r.parentNode;if(r!==n){let a=r.parentNode;o=le(a,r.nextSibling,n,n)}i&&Fn(i)&&W(i),n.insertBefore(e,o);let s=this.createDefaultBlock();n.insertBefore(s,o),t.setStart(s,0),t.setEnd(s,0),X(t)}return this.focus(),this.setSelection(t),this._updatePath(t),this}insertImage(e,t){let n=_("IMG",Object.assign({src:e},t));return this.insertElement(n),n}insertPlainText(e,t){let n=this.getSelection();if(n.collapsed&&w(n.startContainer,this._root,"PRE")){let h=n.startContainer,d=n.startOffset,u;if(!h||!(h instanceof Text)){let b=document.createTextNode("");h.insertBefore(b,h.childNodes[d]),u=b,d=0}else u=h;let p=!0;if(t){let b=new CustomEvent("willPaste",{cancelable:!0,detail:{text:e}});this.fireEvent("willPaste",b),e=b.detail.text,p=!b.defaultPrevented}return p&&(this.saveUndoState(n),u.insertData(d,e),n.setStart(u,d+e.length),n.collapse(!0)),this.setSelection(n),this}let i=e.split(`
16
- `),r=this._config,o=r.blockTag,s=r.blockAttributes,a="</"+o+">",l="<"+o;for(let h in s)l+=" "+h+'="'+tr(s[h])+'"';l+=">";for(let h=0,d=i.length;h<d;h+=1){let u=i[h];u=tr(u).replace(/ (?=(?: |$))/g,"&nbsp;"),h&&(u=l+(u||"<BR>")+a),i[h]=u}return this.insertHTML(i.join(""),t)}getSelectedText(e){return yr(e||this.getSelection())}getFontInfo(e){let t={color:void 0,backgroundColor:void 0,fontFamily:void 0,fontSize:void 0};e||(e=this.getSelection()),X(e);let n=0,i=e.commonAncestorContainer;if(e.collapsed||i instanceof Text)for(i instanceof Text&&(i=i.parentNode);n<4&&i;){let r=i.style;if(r){let o=r.color;!t.color&&o&&(t.color=o,n+=1);let s=r.backgroundColor;!t.backgroundColor&&s&&(t.backgroundColor=s,n+=1);let a=r.fontFamily;!t.fontFamily&&a&&(t.fontFamily=a,n+=1);let l=r.fontSize;!t.fontSize&&l&&(t.fontSize=l,n+=1)}i=i.parentNode}return t}hasFormat(e,t,n){e=e.toUpperCase(),t||(t={}),n||(n=this.getSelection()),!n.collapsed&&n.startContainer instanceof Text&&n.startOffset===n.startContainer.length&&n.startContainer.nextSibling&&n.setStartBefore(n.startContainer.nextSibling),!n.collapsed&&n.endContainer instanceof Text&&n.endOffset===0&&n.endContainer.previousSibling&&n.setEndAfter(n.endContainer.previousSibling);let i=this._root,r=n.commonAncestorContainer;if(w(r,i,e,t))return!0;if(r instanceof Text)return!1;let o=new re(r,4,l=>Ne(n,l,!0)),s=!1,a;for(;a=o.nextNode();){if(!w(a,i,e,t))return!1;s=!0}return s}changeFormat(e,t,n,i){return n||(n=this.getSelection()),this.saveUndoState(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,i)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this.focus()}_addFormat(e,t,n){let i=this._root;if(n.collapsed){let r=$(_(e,t));_e(n,r);let o=r.firstChild||r,s=o instanceof Text?o.length:0;n.setStart(o,s),n.collapse(!0);let a=r;for(;L(a);)a=a.parentNode;Ht(a,r)}else{let r=new re(n.commonAncestorContainer,5,h=>(h instanceof Text||h.nodeName==="BR"||h.nodeName==="IMG")&&Ne(n,h,!0)),{startContainer:o,startOffset:s,endContainer:a,endOffset:l}=n;if(r.currentNode=o,!(o instanceof Element)&&!(o instanceof Text)||!r.filter(o)){let h=r.nextNode();if(!h)return n;o=h,s=0}do{let h=r.currentNode;if(!w(h,i,e,t)){h===a&&h.length>l&&h.splitText(l),h===o&&s&&(h=h.splitText(s),a===o?(a=h,l-=s):a===o.parentNode&&(l+=1),o=h,s=0);let d=_(e,t);Y(h,d),d.appendChild(h)}}while(r.nextNode());n=Be(o,s,a,l)}return n}_removeFormat(e,t,n,i){this._saveRangeToBookmark(n);let r;n.collapsed&&(qt?r=document.createTextNode("\u200B"):r=document.createTextNode(""),_e(n,r));let o=n.commonAncestorContainer;for(;o!==this._root&&L(o);)o=o.parentNode;let s=n.startContainer,a=n.startOffset,l=n.endContainer,h=n.endOffset,d=[],u=(b,y)=>{if(Ne(n,b,!1))return;let E,S;if(!Ne(n,b,!0)){!(b instanceof HTMLInputElement)&&(!(b instanceof Text)||b.data)&&d.push([y,b]);return}if(b instanceof Text)b===l&&h!==b.length&&d.push([y,b.splitText(h)]),b===s&&a&&(b.splitText(a),d.push([y,b]));else for(E=b.firstChild;E;E=S)S=E.nextSibling,u(E,y)},p=Array.from(o.getElementsByTagName(e)).filter(b=>Ne(n,b,!0)&&Mn(b,e,t));if(i||p.forEach(b=>{u(b,b)}),d.forEach(([b,y])=>{b=b.cloneNode(!1),Y(y,b),b.appendChild(y)}),p.forEach(b=>{Y(b,D(b))}),qt&&r){r=r.parentNode;let b=r;for(;b&&L(b);)b=b.parentNode;b&&Ht(b,r)}return this._getRangeAndRemoveBookmark(n),r&&n.collapse(!1),Xe(o,n),n}bold(){return this.changeFormat({tag:"B"})}removeBold(){return this.changeFormat(null,{tag:"B"})}italic(){return this.changeFormat({tag:"I"})}removeItalic(){return this.changeFormat(null,{tag:"I"})}underline(){return this.changeFormat({tag:"U"})}removeUnderline(){return this.changeFormat(null,{tag:"U"})}strikethrough(){return this.changeFormat({tag:"S"})}removeStrikethrough(){return this.changeFormat(null,{tag:"S"})}subscript(){return this.changeFormat({tag:"SUB"},{tag:"SUP"})}removeSubscript(){return this.changeFormat(null,{tag:"SUB"})}superscript(){return this.changeFormat({tag:"SUP"},{tag:"SUB"})}removeSuperscript(){return this.changeFormat(null,{tag:"SUP"})}makeLink(e,t){let n=this.getSelection();if(n.collapsed){let i=e.indexOf(":")+1;if(i)for(;e[i]==="/";)i+=1;_e(n,document.createTextNode(e.slice(i)))}return t=Object.assign({href:e},this._config.tagAttributes.a,t),this.changeFormat({tag:"A",attributes:t},{tag:"A"},n)}removeLink(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0)}addDetectedLinks(e,t){let n=new re(e,4,s=>!w(s,t||this._root,"A")),i=this.linkRegExp,r=this._config.tagAttributes.a,o;for(;o=n.nextNode();){let s=o.parentNode,a=o.data,l;for(;l=i.exec(a);){let h=l.index,d=h+l[0].length;h&&s.insertBefore(document.createTextNode(a.slice(0,h)),o);let u=_("A",Object.assign({href:l[1]?/^(?:ht|f)tps?:/i.test(l[1])?l[1]:"http://"+l[1]:"mailto:"+l[0]},r));u.textContent=a.slice(h,d),s.insertBefore(u,o),o.data=a=a.slice(d)}}return this}setFontFace(e){let t=this._config.classNames.fontFamily;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"font-family: "+e+", sans-serif;"}}:null,{tag:"SPAN",attributes:{class:t}})}setFontSize(e){let t=this._config.classNames.fontSize;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"font-size: "+(typeof e=="number"?e+"px":e)}}:null,{tag:"SPAN",attributes:{class:t}})}setTextColor(e){let t=this._config.classNames.color;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"color:"+e}}:null,{tag:"SPAN",attributes:{class:t}})}setHighlightColor(e){let t=this._config.classNames.highlight;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"background-color:"+e}}:null,{tag:"SPAN",attributes:{class:t}})}_ensureBottomLine(){let e=this._root,t=e.lastElementChild,n=null;for(;t&&(t.matches("[editor-ui],[clay~=editor-ui]")||t.closest("[editor-ui],[clay~=editor-ui]"));)n=t,t=t.previousElementSibling;(!t||t.nodeName!==this._config.blockTag||!xe(t))&&e.insertBefore(this.createDefaultBlock(),n)}createDefaultBlock(e){let t=this._config;return $(_(t.blockTag,t.blockAttributes,e))}splitBlock(e,t){t||(t=this.getSelection());let n=this._root,i,r,o,s;if(this._recordUndoState(t),this._removeZWS(),this._getRangeAndRemoveBookmark(t),t.collapsed||qe(t,n),this._config.addLinks){X(t);let u=t.startContainer,p=t.startOffset;setTimeout(()=>{Er(this,u,p)},0)}if(i=oe(t,n),i&&(r=w(i,n,"PRE"))){X(t),o=t.startContainer;let u=t.startOffset;return o instanceof Text||(o=document.createTextNode(""),r.insertBefore(o,r.firstChild),u=0),!e&&o instanceof Text&&(o.data.charAt(u-1)===`
15
+ `});return l.addEventListener("pointerdown",this),{element:l,cursor:o,position:r}}),n=_("div",{class:"squire-image-resize-container","editor-ui":"",style:"position: absolute; pointer-events: none; z-index: 1000;"},t.map(r=>r.element));this._currentImage=e,this._resizeContainer=n,this._handles=t,this._root.appendChild(this._resizeContainer);let i=e.naturalWidth;this._originalRatio=i/e.naturalHeight,this._maxWidth=Math.min(i*2,e.parentElement?e.parentElement.offsetWidth:Pn,Pn),this._positionResizeContainer(),e.tabIndex=-1,e.focus(),document.addEventListener("keydown",this,!0)}_positionResizeContainer(){let e=this._resizeContainer,t=this._root,n=this._currentImage;if(!e||!n)return;let i=t.getBoundingClientRect(),r=n.getBoundingClientRect(),o=r.top-i.top+t.scrollTop,s=r.left-i.left+t.scrollLeft,a=r.width,l=r.height;e.style.top=o+"px",e.style.left=s+"px",e.style.width=a+"px",e.style.height=l+"px"}_onPointerDown(e){if(this._currentHandle||!this._handles)return;let t=e.target,n=this._handles.find(o=>o.element===t)||null;if(!n)return;let i=this._currentImage;if(!i)return;e.preventDefault(),e.stopPropagation(),t.addEventListener("pointermove",this),t.addEventListener("pointerup",this),t.addEventListener("pointercancel",this),t.setPointerCapture(e.pointerId),this._currentHandle=n,this._startX=e.clientX,this._startY=e.clientY;let r=getComputedStyle(i);this._startWidth=parseFloat(r.width),this._startHeight=parseFloat(r.height),document.body.style.cursor=n.cursor}_onPointerMove(e){e.preventDefault();let t=this._currentHandle,n=this._currentImage;if(!t||!n)return;let i=e.clientX-this._startX,r=e.clientY-this._startY,o=this._maxWidth,s=this._originalRatio,a=this._startWidth,l=this._startHeight;switch(t.position){case"sw":case"nw":case"w":a-=2*i;break;case"se":case"ne":case"e":a+=2*i;break;case"n":l-=r,a=l*s;break;case"s":l+=r,a=l*s;break}a<lr?a=lr:a>o&&(a=o);let h=n.style;h.width=a+"px",h.height="auto",this._positionResizeContainer()}_onPointerUp(e){e.preventDefault();let t=e.target;t&&(t.removeEventListener("pointermove",this),t.removeEventListener("pointerup",this),t.removeEventListener("pointercancel",this)),this._currentHandle=null,document.body.style.cursor=""}_onKeyDown(e){e.preventDefault(),e.stopPropagation();let t=Xs[e.key];if(!t)return;let n=this._currentImage;if(!n)return;let i=this._editor,r=this._root;this._deselectImage();let o=i.getSelection();o.selectNode(n),t(i,o,r)}},Js=class{constructor(e,t){this.customEvents=new Set(["pathChange","select","input","pasteImage","undoStateChange"]),this.startSelectionId="squire-selection-start",this.endSelectionId="squire-selection-end",this.linkRegExp=/\b(?:((?:(?:ht|f)tps?:\/\/|www\d{0,3}[.]|[a-z0-9][a-z0-9.\-]*[.][a-z]{2,}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:[^\s?&`!()\[\]{};:'".,<>«»“”‘’]|\([^\s()<>]+\)))|([\w\-.%+]+@(?:[\w\-]+\.)+[a-z]{2,}\b(?:[?][^&?\s]+=[^\s?&`!()\[\]{};:'".,<>«»“”‘’]+(?:&[^&?\s]+=[^\s?&`!()\[\]{};:'".,<>«»“”‘’]+)*)?))/i,this.tagAfterSplit={DT:"DD",DD:"DT",LI:"LI",PRE:"PRE"},this._root=e,this._config=this._makeConfig(t),this._isFocused=!1,this._lastSelection=Be(e,0),this._willRestoreSelection=!1,this._mayHaveZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="",this._events=new Map,this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this._ignoreChange=!1,this._ignoreAllChanges=!1,this.addEventListener("selectionchange",this._updatePathOnEvent),this.addEventListener("blur",this._enableRestoreSelection),this.addEventListener("mousedown",this._disableRestoreSelection),this.addEventListener("touchstart",this._disableRestoreSelection),this.addEventListener("focus",this._restoreSelection),this.addEventListener("blur",this._removeZWS),this._isShiftDown=!1,this.addEventListener("cut",Ps),this.addEventListener("copy",Bs),this.addEventListener("paste",Hs),this._dragRange=null,this.addEventListener("dragstart",Fs),this.addEventListener("dragend",Us),this.addEventListener("drop",Ws),this.addEventListener("keydown",sr),this.addEventListener("keyup",sr),this.addEventListener("keydown",Zs),this._keyHandlers=Object.create(H);let n=new MutationObserver(i=>this._onMutations(i));n.observe(e,{childList:!0,attributes:!0,attributeOldValue:!0,characterData:!0,subtree:!0}),this._mutation=n,e.setAttribute("contenteditable","true"),this.addEventListener("beforeinput",this._beforeInput),this._imageResizer=new Qs(e,this),this.setHTML("")}destroy(){this._events.forEach((e,t)=>{this.removeEventListener(t)}),this._mutation.disconnect(),this._imageResizer.destroy(),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0}_makeConfig(e){let t={blockTag:"DIV",blockAttributes:null,tagAttributes:{},classNames:{color:"color",fontFamily:"font",fontSize:"size",highlight:"highlight"},undo:{documentSizeThreshold:-1,undoLimit:-1},addLinks:!0,willCutCopy:null,toPlainText:null,sanitizeToDOMFragment:n=>{let i=DOMPurify.sanitize(n,{ALLOW_UNKNOWN_PROTOCOLS:!0,WHOLE_DOCUMENT:!1,RETURN_DOM:!0,RETURN_DOM_FRAGMENT:!0,FORCE_BODY:!1});return i?document.importNode(i,!0):document.createDocumentFragment()},didError:n=>console.log(n)};return e&&(Object.assign(t,e),t.blockTag=t.blockTag.toUpperCase()),t}setKeyHandler(e,t){return this._keyHandlers[e]=t,this}_beforeInput(e){switch(e.inputType){case"insertLineBreak":e.preventDefault(),this.splitBlock(!0);break;case"insertParagraph":e.preventDefault(),this.splitBlock(!1);break;case"insertOrderedList":e.preventDefault(),this.makeOrderedList();break;case"insertUnoderedList":e.preventDefault(),this.makeUnorderedList();break;case"historyUndo":e.preventDefault(),this.undo();break;case"historyRedo":e.preventDefault(),this.redo();break;case"formatBold":e.preventDefault(),this.bold();break;case"formatItalic":e.preventDefault(),this.italic();break;case"formatUnderline":e.preventDefault(),this.underline();break;case"formatStrikeThrough":e.preventDefault(),this.strikethrough();break;case"formatSuperscript":e.preventDefault(),this.superscript();break;case"formatSubscript":e.preventDefault(),this.subscript();break;case"formatJustifyFull":case"formatJustifyCenter":case"formatJustifyRight":case"formatJustifyLeft":{e.preventDefault();let t=e.inputType.slice(13).toLowerCase();t==="full"&&(t="justify"),this.setTextAlignment(t);break}case"formatRemove":e.preventDefault(),this.removeAllFormatting();break;case"formatSetBlockTextDirection":{e.preventDefault();let t=e.data;t==="null"&&(t=null),this.setTextDirection(t);break}case"formatBackColor":e.preventDefault(),this.setHighlightColor(e.data);break;case"formatFontColor":e.preventDefault(),this.setTextColor(e.data);break;case"formatFontName":e.preventDefault(),this.setFontFace(e.data);break}}handleEvent(e){this.fireEvent(e.type,e)}fireEvent(e,t){let n=this._events.get(e);if(/^(?:focus|blur)/.test(e)){let i=this._root===document.activeElement;if(e==="focus"){if(!i||this._isFocused)return this;this._isFocused=!0}else{if(i||!this._isFocused)return this;this._isFocused=!1}}if(n){let i=t instanceof Event?t:new CustomEvent(e,{detail:t});n=n.slice();for(let r of n)try{"handleEvent"in r?r.handleEvent(i):r.call(this,i)}catch(o){this._config.didError(o)}}return this}addEventListener(e,t){let n=this._events.get(e),i=this._root;return n||(n=[],this._events.set(e,n),this.customEvents.has(e)||(e==="selectionchange"&&(i=document),i.addEventListener(e,this,!0))),n.push(t),this}removeEventListener(e,t){let n=this._events.get(e),i=this._root;if(n){if(t){let r=n.length;for(;r--;)n[r]===t&&n.splice(r,1)}else n.length=0;n.length||(this._events.delete(e),this.customEvents.has(e)||(e==="selectionchange"&&(i=document),i.removeEventListener(e,this,!0)))}return this}focus(){return this._root.focus({preventScroll:!0}),this}blur(){return this._root.blur(),this}_enableRestoreSelection(){this._willRestoreSelection=!0}_disableRestoreSelection(){this._willRestoreSelection=!1}_restoreSelection(){this._willRestoreSelection&&this.setSelection(this._lastSelection)}_removeZWS(){this._mayHaveZWS&&(Ht(this._root),this._mayHaveZWS=!1)}_saveRangeToBookmark(e){let t=_("INPUT",{id:this.startSelectionId,type:"hidden"}),n=_("INPUT",{id:this.endSelectionId,type:"hidden"}),i;Ee(e,t),e.collapse(!1),Ee(e,n),t.compareDocumentPosition(n)&Node.DOCUMENT_POSITION_PRECEDING&&(t.id=this.endSelectionId,n.id=this.startSelectionId,i=t,t=n,n=i),e.setStartAfter(t),e.setEndBefore(n)}_getRangeAndRemoveBookmark(e){let t=this._root,n=t.querySelectorAll("#"+this.startSelectionId),i=t.querySelectorAll("#"+this.endSelectionId),r=n[0],o=i[0];if(r&&o&&r.compareDocumentPosition(o)&Node.DOCUMENT_POSITION_FOLLOWING){let s=r.parentNode,a=o.parentNode,l=Array.from(s.childNodes).indexOf(r),h=Array.from(a.childNodes).indexOf(o);s===a&&(h-=1),r.remove(),o.remove(),e||(e=document.createRange()),e.setStart(s,l),e.setEnd(a,h),Qe(s,e),s!==a&&Qe(a,e),e.collapsed&&(s=e.startContainer,s instanceof Text&&(a=s.childNodes[e.startOffset],(!a||!(a instanceof Text))&&(a=s.childNodes[e.startOffset-1]),a&&a instanceof Text&&(e.setStart(a,0),e.collapse(!0))))}for(let s=0;s<n.length;s+=1)n[s].remove();for(let s=0;s<i.length;s+=1)i[s].remove();return e||null}getSelection(){let e=window.getSelection(),t=this._root,n=null;if(this._isFocused&&e&&e.rangeCount){n=e.getRangeAt(0).cloneRange();let i=n.startContainer,r=n.endContainer;i&&ke(i)&&n.setStartBefore(i),r&&ke(r)&&n.setEndBefore(r)}return n&&t.contains(n.commonAncestorContainer)?this._lastSelection=n:(n=this._lastSelection,document.contains(n.commonAncestorContainer)||(n=null)),n||(n=Be(t.firstElementChild||t,0)),n}setSelection(e){if(this._lastSelection=e,!this._isFocused)this._enableRestoreSelection();else{let t=window.getSelection();t&&("setBaseAndExtent"in Selection.prototype?t.setBaseAndExtent(e.startContainer,e.startOffset,e.endContainer,e.endOffset):(t.removeAllRanges(),t.addRange(e)))}return this}_moveCursorTo(e){let t=this._root,n=Be(t,e?0:t.childNodes.length);return X(n),this.setSelection(n),this}moveCursorToStart(){return this._moveCursorTo(!0)}moveCursorToEnd(){return this._moveCursorTo(!1)}getCursorPosition(){let e=this.getSelection(),t=e.getBoundingClientRect();if(t&&!t.top){this._ignoreChange=!0;let n=_("SPAN");n.textContent="\u200B",Ee(e,n),t=n.getBoundingClientRect();let i=n.parentNode;i.removeChild(n),Qe(i,e)}return t}getPath(){return this._path}_updatePathOnEvent(){this._isFocused&&this._updatePath(this.getSelection())}_updatePath(e,t){let n=e.startContainer,i=e.endContainer,r;(t||n!==this._lastAnchorNode||i!==this._lastFocusNode)&&(this._lastAnchorNode=n,this._lastFocusNode=i,r=n&&i?n===i?this._getPath(i):"(selection)":"",(this._path!==r||n!==i)&&(this._path=r,this.fireEvent("pathChange",{path:r}))),this.fireEvent(e.collapsed?"cursor":"select",{range:e})}_getPath(e){let t=this._root,n=this._config,i="";if(e&&e!==t){let r=e.parentNode;if(i=r?this._getPath(r):"",e instanceof HTMLElement){let o=e.id,s=e.classList,a=Array.from(s).sort(),l=e.dir,h=n.classNames;i+=(i?">":"")+e.nodeName,o&&(i+="#"+o),a.length&&(i+=".",i+=a.join(".")),l&&(i+="[dir="+l+"]"),s.contains(h.highlight)&&(i+="[backgroundColor="+e.style.backgroundColor.replace(/ /g,"")+"]"),s.contains(h.color)&&(i+="[color="+e.style.color.replace(/ /g,"")+"]"),s.contains(h.fontFamily)&&(i+="[fontFamily="+e.style.fontFamily.replace(/ /g,"")+"]"),s.contains(h.fontSize)&&(i+="[fontSize="+e.style.fontSize+"]")}}return i}modifyDocument(e){let t=this._mutation;return t&&((()=>{let n=t.takeRecords();n.length&&this._onMutations(n)})(),t.disconnect()),this._ignoreAllChanges=!0,e(),this._ignoreAllChanges=!1,t&&(t.observe(this._root,{childList:!0,attributes:!0,attributeOldValue:!0,characterData:!0,subtree:!0}),this._ignoreChange=!1),this}_onMutations(e){let t=this._config.onMutations;return t?t(e,this):this._docWasChanged()}_docWasChanged(){if(fr(),this._mayHaveZWS=!0,!this._ignoreAllChanges){if(this._ignoreChange){this._ignoreChange=!1;return}this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input")}}_recordUndoState(e,t){let n=this._isInUndoState;if(!n||t){let i=this._undoIndex+1,r=this._undoStack,o=this._config.undo,s=o.documentSizeThreshold,a=o.undoLimit;if(i<this._undoStackLength&&(r.length=this._undoStackLength=i),e&&this._saveRangeToBookmark(e),n)return this;let l=this._getRawHTML();t&&(i-=1),s>-1&&l.length*2>s&&a>-1&&i>a&&(r.splice(0,i-a),i=a,this._undoStackLength=a),r[i]=l,this._undoIndex=i,this._undoStackLength+=1,this._isInUndoState=!0}return this}saveUndoState(e){let t=!1;return e||(e=this.getSelection(),t=!0),this._recordUndoState(e,this._isInUndoState),this._getRangeAndRemoveBookmark(e),t&&this.setSelection(e),this}undo(){if(this._undoIndex!==0||!this._isInUndoState){this._recordUndoState(this.getSelection(),!1),this._undoIndex-=1,this._setRawHTML(this._undoStack[this._undoIndex]);let e=this._getRangeAndRemoveBookmark();e&&this.setSelection(e),this._isInUndoState=!0,this.fireEvent("undoStateChange",{canUndo:this._undoIndex!==0,canRedo:!0}),this.fireEvent("input")}return this.focus()}redo(){let e=this._undoIndex,t=this._undoStackLength;if(e+1<t&&this._isInUndoState){this._undoIndex+=1,this._setRawHTML(this._undoStack[this._undoIndex]);let n=this._getRangeAndRemoveBookmark();n&&this.setSelection(n),this.fireEvent("undoStateChange",{canUndo:!0,canRedo:e+2<t}),this.fireEvent("input")}return this.focus()}getRoot(){return this._root}_getRawHTML(){let e=this._config.serializeRoot;return e?e(this._root,this):this._root.innerHTML}_setRawHTML(e){let t=this._root;this._config.replaceRoot?this._config.replaceRoot(t,e,this):t.innerHTML=e;let n=t,i=n.firstChild;if(!i||i.nodeName==="BR"){let r=this.createDefaultBlock();i?n.replaceChild(r,i):n.appendChild(r)}else for(;n=Se(n,t);)K(n);return this._ignoreChange=!0,this}getHTML(e){if(this._config.serializeRoot)return this._config.serializeRoot(this._root,this,e?this.getSelection():null).replace(/\u200B/g,"");let t,n="";return this.modifyDocument(()=>{e&&(t=this.getSelection(),this._saveRangeToBookmark(t)),n=this._getRawHTML().replace(/\u200B/g,""),e&&this._getRangeAndRemoveBookmark(t)}),n}setHTML(e){let t=this._config.sanitizeToDOMFragment(e,this),n=this._root;Fn(t,this._config),zn(t,n,!1),ge(t,n);let i=t,r=i.firstChild;if(!r||r.nodeName==="BR"){let s=this.createDefaultBlock();r?i.replaceChild(s,r):i.appendChild(s)}else for(;i=Se(i,n);)K(i);for(this._ignoreChange=!0;r=n.lastChild;)n.removeChild(r);n.appendChild(t),this._undoIndex=-1,this._undoStack.length=0,this._undoStackLength=0,this._isInUndoState=!1;let o=this._getRangeAndRemoveBookmark()||Be(n.firstElementChild||n,0);return this.saveUndoState(o),this.setSelection(o),this._updatePath(o,!0),this}insertHTML(e,t){let n=this._config,i=n.sanitizeToDOMFragment(e,this),r=this.getSelection();this.saveUndoState(r);try{let o=this._root;n.addLinks&&this.addDetectedLinks(i,i),Fn(i,this._config),zn(i,o,!1),Un(i),i.normalize();let s=i;for(;s=Se(s,i);)K(s);let a=!0;if(t){let l=new CustomEvent("willPaste",{cancelable:!0,detail:{html:e,fragment:i}});this.fireEvent("willPaste",l),i=l.detail.fragment,a=!l.defaultPrevented}a&&(Is(r,i,o),r.collapse(!1),tr(r,"A",o),this._ensureBottomLine()),this.setSelection(r),this._updatePath(r,!0),t&&this.focus()}catch(o){this._config.didError(o)}return this}insertElement(e,t){if(t||(t=this.getSelection()),t.collapse(!0),L(e))Ee(t,e),t.setStartAfter(e);else{let n=this._root,i=oe(t,n),r=i||n,o=null;for(;r!==n&&!r.nextSibling;)r=r.parentNode;if(r!==n){let a=r.parentNode;o=le(a,r.nextSibling,n,n)}i&&qn(i)&&W(i),n.insertBefore(e,o);let s=this.createDefaultBlock();n.insertBefore(s,o),t.setStart(s,0),t.setEnd(s,0),X(t)}return this.focus(),this.setSelection(t),this._updatePath(t),this}insertImage(e,t){let n=_("IMG",Object.assign({src:e},t));return this.insertElement(n),n}insertPlainText(e,t){let n=this.getSelection();if(n.collapsed&&w(n.startContainer,this._root,"PRE")){let h=n.startContainer,d=n.startOffset,u;if(!h||!(h instanceof Text)){let b=document.createTextNode("");h.insertBefore(b,h.childNodes[d]),u=b,d=0}else u=h;let p=!0;if(t){let b=new CustomEvent("willPaste",{cancelable:!0,detail:{text:e}});this.fireEvent("willPaste",b),e=b.detail.text,p=!b.defaultPrevented}return p&&(this.saveUndoState(n),u.insertData(d,e),n.setStart(u,d+e.length),n.collapse(!0)),this.setSelection(n),this}let i=e.split(`
16
+ `),r=this._config,o=r.blockTag,s=r.blockAttributes,a="</"+o+">",l="<"+o;for(let h in s)l+=" "+h+'="'+ir(s[h])+'"';l+=">";for(let h=0,d=i.length;h<d;h+=1){let u=i[h];u=ir(u).replace(/ (?=(?: |$))/g,"&nbsp;"),h&&(u=l+(u||"<BR>")+a),i[h]=u}return this.insertHTML(i.join(""),t)}getSelectedText(e){return Tr(e||this.getSelection())}getFontInfo(e){let t={color:void 0,backgroundColor:void 0,fontFamily:void 0,fontSize:void 0};e||(e=this.getSelection()),X(e);let n=0,i=e.commonAncestorContainer;if(e.collapsed||i instanceof Text)for(i instanceof Text&&(i=i.parentNode);n<4&&i;){let r=i.style;if(r){let o=r.color;!t.color&&o&&(t.color=o,n+=1);let s=r.backgroundColor;!t.backgroundColor&&s&&(t.backgroundColor=s,n+=1);let a=r.fontFamily;!t.fontFamily&&a&&(t.fontFamily=a,n+=1);let l=r.fontSize;!t.fontSize&&l&&(t.fontSize=l,n+=1)}i=i.parentNode}return t}hasFormat(e,t,n){e=e.toUpperCase(),t||(t={}),n||(n=this.getSelection()),!n.collapsed&&n.startContainer instanceof Text&&n.startOffset===n.startContainer.length&&n.startContainer.nextSibling&&n.setStartBefore(n.startContainer.nextSibling),!n.collapsed&&n.endContainer instanceof Text&&n.endOffset===0&&n.endContainer.previousSibling&&n.setEndAfter(n.endContainer.previousSibling);let i=this._root,r=n.commonAncestorContainer;if(w(r,i,e,t))return!0;if(r instanceof Text)return!1;let o=new re(r,4,l=>Ne(n,l,!0)),s=!1,a;for(;a=o.nextNode();){if(!w(a,i,e,t))return!1;s=!0}return s}changeFormat(e,t,n,i){return n||(n=this.getSelection()),this.saveUndoState(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,i)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this.focus()}_addFormat(e,t,n){let i=this._root;if(n.collapsed){let r=K(_(e,t));Ee(n,r);let o=r.firstChild||r,s=o instanceof Text?o.length:0;n.setStart(o,s),n.collapse(!0);let a=r;for(;L(a);)a=a.parentNode;Ht(a,r)}else{let r=new re(n.commonAncestorContainer,5,h=>(h instanceof Text||h.nodeName==="BR"||h.nodeName==="IMG")&&Ne(n,h,!0)),{startContainer:o,startOffset:s,endContainer:a,endOffset:l}=n;if(r.currentNode=o,!(o instanceof Element)&&!(o instanceof Text)||!r.filter(o)){let h=r.nextNode();if(!h)return n;o=h,s=0}do{let h=r.currentNode;if(!w(h,i,e,t)){h===a&&h.length>l&&h.splitText(l),h===o&&s&&(h=h.splitText(s),a===o?(a=h,l-=s):a===o.parentNode&&(l+=1),o=h,s=0);let d=_(e,t);Y(h,d),d.appendChild(h)}}while(r.nextNode());n=Be(o,s,a,l)}return n}_removeFormat(e,t,n,i){this._saveRangeToBookmark(n);let r;n.collapsed&&(qt?r=document.createTextNode("\u200B"):r=document.createTextNode(""),Ee(n,r));let o=n.commonAncestorContainer;for(;o!==this._root&&L(o);)o=o.parentNode;let s=n.startContainer,a=n.startOffset,l=n.endContainer,h=n.endOffset,d=[],u=(b,y)=>{if(Ne(n,b,!1))return;let E,S;if(!Ne(n,b,!0)){!(b instanceof HTMLInputElement)&&(!(b instanceof Text)||b.data)&&d.push([y,b]);return}if(b instanceof Text)b===l&&h!==b.length&&d.push([y,b.splitText(h)]),b===s&&a&&(b.splitText(a),d.push([y,b]));else for(E=b.firstChild;E;E=S)S=E.nextSibling,u(E,y)},p=Array.from(o.getElementsByTagName(e)).filter(b=>Ne(n,b,!0)&&Hn(b,e,t));if(i||p.forEach(b=>{u(b,b)}),d.forEach(([b,y])=>{b=b.cloneNode(!1),Y(y,b),b.appendChild(y)}),p.forEach(b=>{Y(b,D(b))}),qt&&r){r=r.parentNode;let b=r;for(;b&&L(b);)b=b.parentNode;b&&Ht(b,r)}return this._getRangeAndRemoveBookmark(n),r&&n.collapse(!1),Qe(o,n),n}bold(){return this.changeFormat({tag:"B"})}removeBold(){return this.changeFormat(null,{tag:"B"})}italic(){return this.changeFormat({tag:"I"})}removeItalic(){return this.changeFormat(null,{tag:"I"})}underline(){return this.changeFormat({tag:"U"})}removeUnderline(){return this.changeFormat(null,{tag:"U"})}strikethrough(){return this.changeFormat({tag:"S"})}removeStrikethrough(){return this.changeFormat(null,{tag:"S"})}subscript(){return this.changeFormat({tag:"SUB"},{tag:"SUP"})}removeSubscript(){return this.changeFormat(null,{tag:"SUB"})}superscript(){return this.changeFormat({tag:"SUP"},{tag:"SUB"})}removeSuperscript(){return this.changeFormat(null,{tag:"SUP"})}makeLink(e,t){let n=this.getSelection();if(n.collapsed){let i=e.indexOf(":")+1;if(i)for(;e[i]==="/";)i+=1;Ee(n,document.createTextNode(e.slice(i)))}return t=Object.assign({href:e},this._config.tagAttributes.a,t),this.changeFormat({tag:"A",attributes:t},{tag:"A"},n)}removeLink(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0)}addDetectedLinks(e,t){let n=new re(e,4,s=>!w(s,t||this._root,"A")),i=this.linkRegExp,r=this._config.tagAttributes.a,o;for(;o=n.nextNode();){let s=o.parentNode,a=o.data,l;for(;l=i.exec(a);){let h=l.index,d=h+l[0].length;h&&s.insertBefore(document.createTextNode(a.slice(0,h)),o);let u=_("A",Object.assign({href:l[1]?/^(?:ht|f)tps?:/i.test(l[1])?l[1]:"http://"+l[1]:"mailto:"+l[0]},r));u.textContent=a.slice(h,d),s.insertBefore(u,o),o.data=a=a.slice(d)}}return this}setFontFace(e){let t=this._config.classNames.fontFamily;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"font-family: "+e+", sans-serif;"}}:null,{tag:"SPAN",attributes:{class:t}})}setFontSize(e){let t=this._config.classNames.fontSize;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"font-size: "+(typeof e=="number"?e+"px":e)}}:null,{tag:"SPAN",attributes:{class:t}})}setTextColor(e){let t=this._config.classNames.color;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"color:"+e}}:null,{tag:"SPAN",attributes:{class:t}})}setHighlightColor(e){let t=this._config.classNames.highlight;return this.changeFormat(e?{tag:"SPAN",attributes:{class:t,style:"background-color:"+e}}:null,{tag:"SPAN",attributes:{class:t}})}_ensureBottomLine(){let e=this._root,t=e.lastElementChild,n=null;for(;t&&(t.matches("[editor-ui],[clay~=editor-ui]")||t.closest("[editor-ui],[clay~=editor-ui]"));)n=t,t=t.previousElementSibling;(!t||t.nodeName!==this._config.blockTag||!xe(t))&&e.insertBefore(this.createDefaultBlock(),n)}createDefaultBlock(e){let t=this._config;return K(_(t.blockTag,t.blockAttributes,e))}splitBlock(e,t){t||(t=this.getSelection());let n=this._root,i,r,o,s;if(this._recordUndoState(t),this._removeZWS(),this._getRangeAndRemoveBookmark(t),t.collapsed||qe(t,n),this._config.addLinks){X(t);let u=t.startContainer,p=t.startOffset;setTimeout(()=>{Sr(this,u,p)},0)}if(i=oe(t,n),i&&(r=w(i,n,"PRE"))){X(t),o=t.startContainer;let u=t.startOffset;return o instanceof Text||(o=document.createTextNode(""),r.insertBefore(o,r.firstChild),u=0),!e&&o instanceof Text&&(o.data.charAt(u-1)===`
17
17
  `||mt(t,n))&&(o.data.charAt(u)===`
18
18
  `||gt(t,n))?(o.deleteData(u&&u-1,u?2:1),s=le(o,u&&u-1,n,n),o=s.previousSibling,o.textContent||W(o),o=this.createDefaultBlock(),s.parentNode.insertBefore(o,s),s.textContent||W(s),t.setStart(o,0)):(o.insertData(u,`
19
- `),o.nextSibling||r.appendChild(_("BR")),o.length===u+1?t.setStartAfter(o):t.setStart(o,u+1)),t.collapse(!0),this.setSelection(t),this._updatePath(t,!0),this._docWasChanged(),this}if(!i||e||/^T[HD]$/.test(i.nodeName))return Ji(t,"A",n),_e(t,_("BR")),t.collapse(!1),this.setSelection(t),this._updatePath(t,!0),this;if((r=w(i,n,"LI"))&&(i=r),Fn(i)){if(w(i,n,"UL")||w(i,n,"OL"))return this.decreaseListLevel(t),this;if(w(i,n,"BLOCKQUOTE"))return this.replaceWithBlankLine(t),this}o=t.startContainer;let a=t.startOffset,l=this.tagAfterSplit[i.nodeName];s=le(o,a,i.parentNode,this._root);let h=this._config,d=null;for(l||(l=h.blockTag,d=h.blockAttributes),Mn(s,l,d)||(i=_(l,d),s.dir&&(i.dir=s.dir),Y(s,i),i.appendChild(D(s)),s=i),Ht(i),Bn(i),$(i);s instanceof Element;){let u=s.firstChild,p;if(s.nodeName==="A"&&(!s.textContent||s.textContent==="\u200B")){u=document.createTextNode(""),Y(s,u),s=u;break}for(;u&&u instanceof Text&&!u.data&&(p=u.nextSibling,!(!p||p.nodeName==="BR"));)W(u),u=p;if(!u||u.nodeName==="BR"||u instanceof Text)break;s=u}return t=Be(s,0),this.setSelection(t),this._updatePath(t,!0),this}forEachBlock(e,t,n){n||(n=this.getSelection()),t&&this.saveUndoState(n);let i=this._root,r=oe(n,i),o=Ue(n,i);if(r&&o)do if(e(r)||r===o)break;while(r=ve(r,i));return t&&(this.setSelection(n),this._updatePath(n,!0)),this}modifyBlocks(e,t){t||(t=this.getSelection()),this._recordUndoState(t,this._isInUndoState);let n=this._root;nr(t,n),He(t,n,n,n);let i=gr(t,n,n);if(!t.collapsed){let r=t.endContainer;if(r===n)t.collapse(!1);else{for(;r.parentNode!==n;)r=r.parentNode;t.setStartBefore(r),t.collapse(!0)}}return _e(t,e.call(this,i)),t.endOffset<t.endContainer.childNodes.length&&Ee(t.endContainer.childNodes[t.endOffset],n),Ee(t.startContainer.childNodes[t.startOffset],n),this._getRangeAndRemoveBookmark(t),this.setSelection(t),this._updatePath(t,!0),this}setTextAlignment(e){return this.forEachBlock(t=>{let n=t.className.split(/\s+/).filter(i=>!!i&&!/^align/.test(i)).join(" ");e?(t.className=n+" align-"+e,t.style.textAlign=e):(t.className=n,t.style.textAlign="")},!0),this.focus()}setTextDirection(e){return this.forEachBlock(t=>{e?t.dir=e:t.removeAttribute("dir")},!0),this.focus()}_getListSelection(e,t){let n=e.commonAncestorContainer,i=e.startContainer,r=e.endContainer;for(;n&&n!==t&&!/^[OU]L$/.test(n.nodeName);)n=n.parentNode;if(!n||n===t)return null;for(i===n&&(i=i.childNodes[e.startOffset]),r===n&&(r=r.childNodes[e.endOffset]);i&&i.parentNode!==n;)i=i.parentNode;for(;r&&r.parentNode!==n;)r=r.parentNode;return[n,i,r]}increaseListLevel(e){e||(e=this.getSelection());let t=this._root,n=this._getListSelection(e,t);if(!n)return this.focus();let[i,r,o]=n;if(!r||r===i.firstChild)return this.focus();this._recordUndoState(e,this._isInUndoState);let s=i.nodeName,a=r.previousSibling,l,h;a.nodeName!==s&&(l=this._config.tagAttributes[s.toLowerCase()],a=_(s,l),i.insertBefore(a,r));do h=r===o?null:r.nextSibling,a.appendChild(r);while(r=h);return h=a.nextSibling,h&&Ee(h,t),this._getRangeAndRemoveBookmark(e),this.setSelection(e),this._updatePath(e,!0),this.focus()}decreaseListLevel(e){e||(e=this.getSelection());let t=this._root,n=this._getListSelection(e,t);if(!n)return this.focus();let[i,r,o]=n;r||(r=i.firstChild),o||(o=i.lastChild),this._recordUndoState(e,this._isInUndoState);let s,a=null;if(r){let l=i.parentNode;if(a=o.nextSibling?le(i,o.nextSibling,l,t):i.nextSibling,l!==t&&l.nodeName==="LI"){for(l=l.parentNode;a;)s=a.nextSibling,o.appendChild(a),a=s;a=i.parentNode.nextSibling}let h=!/^[OU]L$/.test(l.nodeName);do s=r===o?null:r.nextSibling,i.removeChild(r),h&&r.nodeName==="LI"&&(r=this.createDefaultBlock([D(r)])),l.insertBefore(r,a);while(r=s)}return i.firstChild||W(i),a&&Ee(a,t),this._getRangeAndRemoveBookmark(e),this.setSelection(e),this._updatePath(e,!0),this.focus()}_makeList(e,t){let n=Wt(e,this._root),i=this._config.tagAttributes,r=i[t.toLowerCase()],o=i.li,s;for(;s=n.nextNode();)if(s.parentNode instanceof HTMLLIElement&&(s=s.parentNode,n.currentNode=s.lastChild),s instanceof HTMLLIElement){s=s.parentNode;let a=s.nodeName;a!==t&&/^[OU]L$/.test(a)&&Y(s,_(t,r,[D(s)]))}else{let a=_("LI",o);s.dir&&(a.dir=s.dir);let l=s.previousSibling;l&&l.nodeName===t?(l.appendChild(a),W(s)):Y(s,_(t,r,[a])),a.appendChild(D(s)),n.currentNode=a}return e}makeUnorderedList(){return this.modifyBlocks(e=>this._makeList(e,"UL")),this.focus()}makeOrderedList(){return this.modifyBlocks(e=>this._makeList(e,"OL")),this.focus()}removeList(){return this.modifyBlocks(e=>{let t=e.querySelectorAll("UL, OL"),n=e.querySelectorAll("LI"),i=this._root;for(let r=0,o=t.length;r<o;r+=1){let s=t[r],a=D(s);ge(a,i),Y(s,a)}for(let r=0,o=n.length;r<o;r+=1){let s=n[r];xe(s)?Y(s,this.createDefaultBlock([D(s)])):(ge(s,i),Y(s,D(s)))}return e}),this.focus()}increaseQuoteLevel(e){return this.modifyBlocks(t=>_("BLOCKQUOTE",this._config.tagAttributes.blockquote,[t]),e),this.focus()}decreaseQuoteLevel(e){return this.modifyBlocks(t=>(Array.from(t.querySelectorAll("blockquote")).filter(n=>!w(n.parentNode,t,"BLOCKQUOTE")).forEach(n=>{Y(n,D(n))}),t),e),this.focus()}removeQuote(e){return this.modifyBlocks(t=>(Array.from(t.querySelectorAll("blockquote")).forEach(n=>{Y(n,D(n))}),t),e),this.focus()}replaceWithBlankLine(e){return this.modifyBlocks(()=>this.createDefaultBlock([_("INPUT",{id:this.startSelectionId,type:"hidden"}),_("INPUT",{id:this.endSelectionId,type:"hidden"})]),e),this.focus()}code(){let e=this.getSelection();return e.collapsed||Qe(e.commonAncestorContainer)?(this.modifyBlocks(t=>{let n=this._root,i=document.createDocumentFragment(),r=Wt(t,n),o;for(;o=r.nextNode();){let a=o.querySelectorAll("BR"),l=[],h=a.length;for(let d=0;d<h;d+=1)l[d]=$t(a[d],!1);for(;h--;){let d=a[h];l[h]?Y(d,document.createTextNode(`
19
+ `),o.nextSibling||r.appendChild(_("BR")),o.length===u+1?t.setStartAfter(o):t.setStart(o,u+1)),t.collapse(!0),this.setSelection(t),this._updatePath(t,!0),this._docWasChanged(),this}if(!i||e||/^T[HD]$/.test(i.nodeName))return tr(t,"A",n),Ee(t,_("BR")),t.collapse(!1),this.setSelection(t),this._updatePath(t,!0),this;if((r=w(i,n,"LI"))&&(i=r),qn(i)){if(w(i,n,"UL")||w(i,n,"OL"))return this.decreaseListLevel(t),this;if(w(i,n,"BLOCKQUOTE"))return this.replaceWithBlankLine(t),this}o=t.startContainer;let a=t.startOffset,l=this.tagAfterSplit[i.nodeName];s=le(o,a,i.parentNode,this._root);let h=this._config,d=null;for(l||(l=h.blockTag,d=h.blockAttributes),Hn(s,l,d)||(i=_(l,d),s.dir&&(i.dir=s.dir),Y(s,i),i.appendChild(D(s)),s=i),Ht(i),Un(i),K(i);s instanceof Element;){let u=s.firstChild,p;if(s.nodeName==="A"&&(!s.textContent||s.textContent==="\u200B")){u=document.createTextNode(""),Y(s,u),s=u;break}for(;u&&u instanceof Text&&!u.data&&(p=u.nextSibling,!(!p||p.nodeName==="BR"));)W(u),u=p;if(!u||u.nodeName==="BR"||u instanceof Text)break;s=u}return t=Be(s,0),this.setSelection(t),this._updatePath(t,!0),this}forEachBlock(e,t,n){n||(n=this.getSelection()),t&&this.saveUndoState(n);let i=this._root,r=oe(n,i),o=Ue(n,i);if(r&&o)do if(e(r)||r===o)break;while(r=Se(r,i));return t&&(this.setSelection(n),this._updatePath(n,!0)),this}modifyBlocks(e,t){t||(t=this.getSelection()),this._recordUndoState(t,this._isInUndoState);let n=this._root;rr(t,n),He(t,n,n,n);let i=br(t,n,n);if(!t.collapsed){let r=t.endContainer;if(r===n)t.collapse(!1);else{for(;r.parentNode!==n;)r=r.parentNode;t.setStartBefore(r),t.collapse(!0)}}return Ee(t,e.call(this,i)),t.endOffset<t.endContainer.childNodes.length&&ve(t.endContainer.childNodes[t.endOffset],n),ve(t.startContainer.childNodes[t.startOffset],n),this._getRangeAndRemoveBookmark(t),this.setSelection(t),this._updatePath(t,!0),this}setTextAlignment(e){return this.forEachBlock(t=>{let n=t.className.split(/\s+/).filter(i=>!!i&&!/^align/.test(i)).join(" ");e?(t.className=n+" align-"+e,t.style.textAlign=e):(t.className=n,t.style.textAlign="")},!0),this.focus()}setTextDirection(e){return this.forEachBlock(t=>{e?t.dir=e:t.removeAttribute("dir")},!0),this.focus()}_getListSelection(e,t){let n=e.commonAncestorContainer,i=e.startContainer,r=e.endContainer;for(;n&&n!==t&&!/^[OU]L$/.test(n.nodeName);)n=n.parentNode;if(!n||n===t)return null;for(i===n&&(i=i.childNodes[e.startOffset]),r===n&&(r=r.childNodes[e.endOffset]);i&&i.parentNode!==n;)i=i.parentNode;for(;r&&r.parentNode!==n;)r=r.parentNode;return[n,i,r]}increaseListLevel(e){e||(e=this.getSelection());let t=this._root,n=this._getListSelection(e,t);if(!n)return this.focus();let[i,r,o]=n;if(!r||r===i.firstChild)return this.focus();this._recordUndoState(e,this._isInUndoState);let s=i.nodeName,a=r.previousSibling,l,h;a.nodeName!==s&&(l=this._config.tagAttributes[s.toLowerCase()],a=_(s,l),i.insertBefore(a,r));do h=r===o?null:r.nextSibling,a.appendChild(r);while(r=h);return h=a.nextSibling,h&&ve(h,t),this._getRangeAndRemoveBookmark(e),this.setSelection(e),this._updatePath(e,!0),this.focus()}decreaseListLevel(e){e||(e=this.getSelection());let t=this._root,n=this._getListSelection(e,t);if(!n)return this.focus();let[i,r,o]=n;r||(r=i.firstChild),o||(o=i.lastChild),this._recordUndoState(e,this._isInUndoState);let s,a=null;if(r){let l=i.parentNode;if(a=o.nextSibling?le(i,o.nextSibling,l,t):i.nextSibling,l!==t&&l.nodeName==="LI"){for(l=l.parentNode;a;)s=a.nextSibling,o.appendChild(a),a=s;a=i.parentNode.nextSibling}let h=!/^[OU]L$/.test(l.nodeName);do s=r===o?null:r.nextSibling,i.removeChild(r),h&&r.nodeName==="LI"&&(r=this.createDefaultBlock([D(r)])),l.insertBefore(r,a);while(r=s)}return i.firstChild||W(i),a&&ve(a,t),this._getRangeAndRemoveBookmark(e),this.setSelection(e),this._updatePath(e,!0),this.focus()}_makeList(e,t){let n=Wt(e,this._root),i=this._config.tagAttributes,r=i[t.toLowerCase()],o=i.li,s;for(;s=n.nextNode();)if(s.parentNode instanceof HTMLLIElement&&(s=s.parentNode,n.currentNode=s.lastChild),s instanceof HTMLLIElement){s=s.parentNode;let a=s.nodeName;a!==t&&/^[OU]L$/.test(a)&&Y(s,_(t,r,[D(s)]))}else{let a=_("LI",o);s.dir&&(a.dir=s.dir);let l=s.previousSibling;l&&l.nodeName===t?(l.appendChild(a),W(s)):Y(s,_(t,r,[a])),a.appendChild(D(s)),n.currentNode=a}return e}makeUnorderedList(){return this.modifyBlocks(e=>this._makeList(e,"UL")),this.focus()}makeOrderedList(){return this.modifyBlocks(e=>this._makeList(e,"OL")),this.focus()}removeList(){return this.modifyBlocks(e=>{let t=e.querySelectorAll("UL, OL"),n=e.querySelectorAll("LI"),i=this._root;for(let r=0,o=t.length;r<o;r+=1){let s=t[r],a=D(s);ge(a,i),Y(s,a)}for(let r=0,o=n.length;r<o;r+=1){let s=n[r];xe(s)?Y(s,this.createDefaultBlock([D(s)])):(ge(s,i),Y(s,D(s)))}return e}),this.focus()}increaseQuoteLevel(e){return this.modifyBlocks(t=>_("BLOCKQUOTE",this._config.tagAttributes.blockquote,[t]),e),this.focus()}decreaseQuoteLevel(e){return this.modifyBlocks(t=>(Array.from(t.querySelectorAll("blockquote")).filter(n=>!w(n.parentNode,t,"BLOCKQUOTE")).forEach(n=>{Y(n,D(n))}),t),e),this.focus()}removeQuote(e){return this.modifyBlocks(t=>(Array.from(t.querySelectorAll("blockquote")).forEach(n=>{Y(n,D(n))}),t),e),this.focus()}replaceWithBlankLine(e){return this.modifyBlocks(()=>this.createDefaultBlock([_("INPUT",{id:this.startSelectionId,type:"hidden"}),_("INPUT",{id:this.endSelectionId,type:"hidden"})]),e),this.focus()}code(){let e=this.getSelection();return e.collapsed||Je(e.commonAncestorContainer)?(this.modifyBlocks(t=>{let n=this._root,i=document.createDocumentFragment(),r=Wt(t,n),o;for(;o=r.nextNode();){let a=o.querySelectorAll("BR"),l=[],h=a.length;for(let d=0;d<h;d+=1)l[d]=Kt(a[d],!1);for(;h--;){let d=a[h];l[h]?Y(d,document.createTextNode(`
20
20
  `)):W(d)}for(a=o.querySelectorAll("CODE"),h=a.length;h--;)Y(a[h],D(a[h]));i.childNodes.length&&i.appendChild(document.createTextNode(`
21
- `)),i.appendChild(D(o))}let s=new re(i,4);for(;o=s.nextNode();)o.data=o.data.replace(/ /g," ");return i.normalize(),$(_("PRE",this._config.tagAttributes.pre,[i]))},e),this.focus()):this.changeFormat({tag:"CODE",attributes:this._config.tagAttributes.code},null,e),this}removeCode(){let e=this.getSelection(),t=e.commonAncestorContainer;return w(t,this._root,"PRE")?(this.modifyBlocks(n=>{let i=this._root,r=n.querySelectorAll("PRE"),o=r.length;for(;o--;){let s=r[o],a=new re(s,4),l;for(;l=a.nextNode();){let h=l.data;h=h.replace(/ (?= )/g,"\xA0");let d=document.createDocumentFragment(),u;for(;(u=h.indexOf(`
22
- `))>-1;)d.appendChild(document.createTextNode(h.slice(0,u))),d.appendChild(_("BR")),h=h.slice(u+1);l.parentNode.insertBefore(d,l),l.data=h}ge(s,i),Y(s,D(s))}return n},e),this.focus()):this.changeFormat(null,{tag:"CODE"},e),this}toggleCode(){return this.hasFormat("PRE")||this.hasFormat("CODE")?this.removeCode():this.code(),this}_removeFormatting(e,t){for(let n=e.firstChild,i;n;n=i){if(i=n.nextSibling,L(n)){if(n instanceof Text||n.nodeName==="BR"||n.nodeName==="IMG"){t.appendChild(n);continue}}else if(xe(n)){t.appendChild(this.createDefaultBlock([this._removeFormatting(n,document.createDocumentFragment())]));continue}this._removeFormatting(n,t)}return t}removeAllFormatting(e){if(e||(e=this.getSelection()),e.collapsed)return this.focus();let t=this._root,n=e.commonAncestorContainer;for(;n&&n!==t&&!xe(n);)n=n.parentNode;if(n||(nr(e,t),n=t),n instanceof Text)return this.focus();this.saveUndoState(e),He(e,n,n,t);let i=e.startContainer,r=e.startOffset,o=e.endContainer,s=e.endOffset,a=document.createDocumentFragment(),l=document.createDocumentFragment(),h=le(o,s,n,t),d=le(i,r,n,t),u;for(;d!==h;)u=d.nextSibling,a.appendChild(d),d=u;if(this._removeFormatting(a,l),l.normalize(),d=l.firstChild,u=l.lastChild,d){n.insertBefore(l,h);let p=Array.from(n.childNodes);r=p.indexOf(d),s=u?p.indexOf(u)+1:0}else h&&(r=Array.from(n.childNodes).indexOf(h),s=r);return e.setStart(n,r),e.setEnd(n,s),Xe(n,e),X(e),this.setSelection(e),this._updatePath(e,!0),this.focus()}},vr=Js;function Sr(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,i=Array(t);n<t;n++)i[n]=e[n];return i}function ea(e){if(Array.isArray(e))return e}function ta(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var i,r,o,s,a=[],l=!0,h=!1;try{if(o=(n=n.call(e)).next,t!==0)for(;!(l=(i=o.call(n)).done)&&(a.push(i.value),a.length!==t);l=!0);}catch(d){h=!0,r=d}finally{try{if(!l&&n.return!=null&&(s=n.return(),Object(s)!==s))return}finally{if(h)throw r}}return a}}function na(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
23
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ia(e,t){return ea(e)||ta(e,t)||ra(e,t)||na()}function ra(e,t){if(e){if(typeof e=="string")return Sr(e,t);var n={}.toString.call(e).slice(8,-1);return n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set"?Array.from(e):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Sr(e,t):void 0}}var Br=Object.entries,Ar=Object.setPrototypeOf,oa=Object.isFrozen,sa=Object.getPrototypeOf,aa=Object.getOwnPropertyDescriptor,j=Object.freeze,Z=Object.seal,tt=Object.create,Hr=typeof Reflect<"u"&&Reflect,jn=Hr.apply,Zn=Hr.construct;j||(j=function(t){return t});Z||(Z=function(t){return t});jn||(jn=function(t,n){for(var i=arguments.length,r=new Array(i>2?i-2:0),o=2;o<i;o++)r[o-2]=arguments[o];return t.apply(n,r)});Zn||(Zn=function(t){for(var n=arguments.length,i=new Array(n>1?n-1:0),r=1;r<n;r++)i[r-1]=arguments[r];return new t(...i)});var yt=F(Array.prototype.forEach),la=F(Array.prototype.lastIndexOf),Cr=F(Array.prototype.pop),et=F(Array.prototype.push),ca=F(Array.prototype.splice),Oe=Array.isArray,_t=F(String.prototype.toLowerCase),Wn=F(String.prototype.toString),Lr=F(String.prototype.match),bt=F(String.prototype.replace),wr=F(String.prototype.indexOf),ha=F(String.prototype.trim),ua=F(Number.prototype.toString),da=F(Boolean.prototype.toString),Nr=typeof BigInt>"u"?null:F(BigInt.prototype.toString),xr=typeof Symbol>"u"?null:F(Symbol.prototype.toString),K=F(Object.prototype.hasOwnProperty),Tt=F(Object.prototype.toString),G=F(RegExp.prototype.test),We=fa(TypeError);function F(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);for(var n=arguments.length,i=new Array(n>1?n-1:0),r=1;r<n;r++)i[r-1]=arguments[r];return jn(e,t,i)}}function fa(e){return function(){for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];return Zn(e,n)}}function A(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:_t;if(Ar&&Ar(e,null),!Oe(t))return e;let i=t.length;for(;i--;){let r=t[i];if(typeof r=="string"){let o=n(r);o!==r&&(oa(t)||(t[i]=o),r=o)}e[r]=!0}return e}function pa(e){for(let t=0;t<e.length;t++)K(e,t)||(e[t]=null);return e}function ne(e){let t=tt(null);for(let i of Br(e)){var n=ia(i,2);let r=n[0],o=n[1];K(e,r)&&(Oe(o)?t[r]=pa(o):o&&typeof o=="object"&&o.constructor===Object?t[r]=ne(o):t[r]=o)}return t}function ma(e){switch(typeof e){case"string":return e;case"number":return ua(e);case"boolean":return da(e);case"bigint":return Nr?Nr(e):"0";case"symbol":return xr?xr(e):"Symbol()";case"undefined":return Tt(e);case"function":case"object":{if(e===null)return Tt(e);let t=e,n=be(t,"toString");if(typeof n=="function"){let i=n(t);return typeof i=="string"?i:Tt(i)}return Tt(e)}default:return Tt(e)}}function be(e,t){for(;e!==null;){let i=aa(e,t);if(i){if(i.get)return F(i.get);if(typeof i.value=="function")return F(i.value)}e=sa(e)}function n(){return null}return n}function ga(e){try{return G(e,""),!0}catch{return!1}}var kr=j(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),$n=j(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),Kn=j(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),ya=j(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),Vn=j(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),ba=j(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),Rr=j(["#text"]),Or=j(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","command","commandfor","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns"]),Gn=j(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),Dr=j(["accent","accentunder","align","bevelled","close","columnalign","columnlines","columnspacing","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lquote","lspace","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),Kt=j(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),Ta=Z(/{{[\w\W]*|^[\w\W]*}}/g),_a=Z(/<%[\w\W]*|^[\w\W]*%>/g),Ea=Z(/\${[\w\W]*/g),va=Z(/^data-[\-\w.\u00B7-\uFFFF]+$/),Sa=Z(/^aria-[\-\w]+$/),Ir=Z(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Aa=Z(/^(?:\w+script|data):/i),Ca=Z(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),La=Z(/^html$/i),wa=Z(/^[a-z][.\w]*(-[.\w]+)+$/i),Mr=Z(/<[/\w!]/g),Na=Z(/<[/\w]/g),xa=Z(/<\/no(script|embed|frames)/i),ka=Z(/\/>/i),ye={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},Ra=function(){return typeof window>"u"?null:window},Oa=function(t,n){if(typeof t!="object"||typeof t.createPolicy!="function")return null;let i=null,r="data-tt-policy-suffix";n&&n.hasAttribute(r)&&(i=n.getAttribute(r));let o="dompurify"+(i?"#"+i:"");try{return t.createPolicy(o,{createHTML(s){return s},createScriptURL(s){return s}})}catch{return console.warn("TrustedTypes policy "+o+" could not be created."),null}},Pr=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},Re=function(t,n,i,r){return K(t,n)&&Oe(t[n])?A(r.base?ne(r.base):{},t[n],r.transform):i};function Fr(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Ra(),t=g=>Fr(g);if(t.version="3.4.11",t.removed=[],!e||!e.document||e.document.nodeType!==ye.document||!e.Element)return t.isSupported=!1,t;let n=e.document,i=n,r=i.currentScript;e.DocumentFragment;let o=e.HTMLTemplateElement,s=e.Node,a=e.Element,l=e.NodeFilter,h=e.NamedNodeMap;h===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let d=e.DOMParser,u=e.trustedTypes,p=a.prototype,b=be(p,"cloneNode"),y=be(p,"remove"),E=be(p,"nextSibling"),S=be(p,"childNodes"),N=be(p,"parentNode"),P=be(p,"shadowRoot"),J=be(p,"attributes"),U=s&&s.prototype?be(s.prototype,"nodeType"):null,he=s&&s.prototype?be(s.prototype,"nodeName"):null;if(typeof o=="function"){let g=n.createElement("template");g.content&&g.content.ownerDocument&&(n=g.content.ownerDocument)}let ie,Ie="",un,Ai=!1,lt=0,Ci=function(){if(lt>0)throw We('A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.')},Ke=function(c){Ci(),lt++;try{return ie.createHTML(c)}finally{lt--}},Ho=function(c){Ci(),lt++;try{return ie.createScriptURL(c)}finally{lt--}},Fo=function(){return Ai||(un=Oa(u,r),Ai=!0),un},kt=n,dn=kt.implementation,Li=kt.createNodeIterator,Uo=kt.createDocumentFragment,zo=kt.getElementsByTagName,qo=i.importNode,M=Pr();t.isSupported=typeof Br=="function"&&typeof N=="function"&&dn&&dn.createHTMLDocument!==void 0;let Wo=Ta,$o=_a,Ko=Ea,Vo=va,Go=Sa,jo=Aa,wi=Ca,Zo=wa,Ni=Ir,x=null,xi=A({},[...kr,...$n,...Kn,...Vn,...Rr]),k=null,ki=A({},[...Or,...Gn,...Dr,...Kt]),R=Object.seal(tt(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),ct=null,Ri=null,Ce=Object.seal(tt(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),Oi=!0,fn=!0,Di=!1,Ii=!0,Le=!1,ht=!0,Me=!1,pn=!1,mn=null,gn=null,yn=!1,Ve=!1,Rt=!1,Ot=!1,Mi=!0,Pi=!1,Bi="user-content-",bn=!0,Tn=!1,Ge={},fe=null,_n=A({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","selectedcontent","style","svg","template","thead","title","video","xmp"]),Hi=null,Fi=A({},["audio","video","img","source","image","track"]),En=null,Ui=A({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Dt="http://www.w3.org/1998/Math/MathML",It="http://www.w3.org/2000/svg",pe="http://www.w3.org/1999/xhtml",je=pe,vn=!1,Sn=null,Yo=A({},[Dt,It,pe],Wn),zi=j(["mi","mo","mn","ms","mtext"]),An=A({},zi),qi=j(["annotation-xml"]),Cn=A({},qi),Xo=A({},["title","style","font","a","script"]),ut=null,Qo=["application/xhtml+xml","text/html"],Jo="text/html",O=null,Ze=null,es=n.createElement("form"),Wi=function(c){return c instanceof RegExp||c instanceof Function},Ln=function(){let c=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(Ze&&Ze===c)return;(!c||typeof c!="object")&&(c={}),c=ne(c),ut=Qo.indexOf(c.PARSER_MEDIA_TYPE)===-1?Jo:c.PARSER_MEDIA_TYPE,O=ut==="application/xhtml+xml"?Wn:_t,x=Re(c,"ALLOWED_TAGS",xi,{transform:O}),k=Re(c,"ALLOWED_ATTR",ki,{transform:O}),Sn=Re(c,"ALLOWED_NAMESPACES",Yo,{transform:Wn}),En=Re(c,"ADD_URI_SAFE_ATTR",Ui,{transform:O,base:Ui}),Hi=Re(c,"ADD_DATA_URI_TAGS",Fi,{transform:O,base:Fi}),fe=Re(c,"FORBID_CONTENTS",_n,{transform:O}),ct=Re(c,"FORBID_TAGS",ne({}),{transform:O}),Ri=Re(c,"FORBID_ATTR",ne({}),{transform:O}),Ge=K(c,"USE_PROFILES")?c.USE_PROFILES&&typeof c.USE_PROFILES=="object"?ne(c.USE_PROFILES):c.USE_PROFILES:!1,Oi=c.ALLOW_ARIA_ATTR!==!1,fn=c.ALLOW_DATA_ATTR!==!1,Di=c.ALLOW_UNKNOWN_PROTOCOLS||!1,Ii=c.ALLOW_SELF_CLOSE_IN_ATTR!==!1,Le=c.SAFE_FOR_TEMPLATES||!1,ht=c.SAFE_FOR_XML!==!1,Me=c.WHOLE_DOCUMENT||!1,Ve=c.RETURN_DOM||!1,Rt=c.RETURN_DOM_FRAGMENT||!1,Ot=c.RETURN_TRUSTED_TYPE||!1,yn=c.FORCE_BODY||!1,Mi=c.SANITIZE_DOM!==!1,Pi=c.SANITIZE_NAMED_PROPS||!1,bn=c.KEEP_CONTENT!==!1,Tn=c.IN_PLACE||!1,Ni=ga(c.ALLOWED_URI_REGEXP)?c.ALLOWED_URI_REGEXP:Ir,je=typeof c.NAMESPACE=="string"?c.NAMESPACE:pe,An=K(c,"MATHML_TEXT_INTEGRATION_POINTS")&&c.MATHML_TEXT_INTEGRATION_POINTS&&typeof c.MATHML_TEXT_INTEGRATION_POINTS=="object"?ne(c.MATHML_TEXT_INTEGRATION_POINTS):A({},zi),Cn=K(c,"HTML_INTEGRATION_POINTS")&&c.HTML_INTEGRATION_POINTS&&typeof c.HTML_INTEGRATION_POINTS=="object"?ne(c.HTML_INTEGRATION_POINTS):A({},qi);let f=K(c,"CUSTOM_ELEMENT_HANDLING")&&c.CUSTOM_ELEMENT_HANDLING&&typeof c.CUSTOM_ELEMENT_HANDLING=="object"?ne(c.CUSTOM_ELEMENT_HANDLING):tt(null);if(R=tt(null),K(f,"tagNameCheck")&&Wi(f.tagNameCheck)&&(R.tagNameCheck=f.tagNameCheck),K(f,"attributeNameCheck")&&Wi(f.attributeNameCheck)&&(R.attributeNameCheck=f.attributeNameCheck),K(f,"allowCustomizedBuiltInElements")&&typeof f.allowCustomizedBuiltInElements=="boolean"&&(R.allowCustomizedBuiltInElements=f.allowCustomizedBuiltInElements),Z(R),Le&&(fn=!1),Rt&&(Ve=!0),Ge&&(x=A({},Rr),k=tt(null),Ge.html===!0&&(A(x,kr),A(k,Or)),Ge.svg===!0&&(A(x,$n),A(k,Gn),A(k,Kt)),Ge.svgFilters===!0&&(A(x,Kn),A(k,Gn),A(k,Kt)),Ge.mathMl===!0&&(A(x,Vn),A(k,Dr),A(k,Kt))),Ce.tagCheck=null,Ce.attributeCheck=null,K(c,"ADD_TAGS")&&(typeof c.ADD_TAGS=="function"?Ce.tagCheck=c.ADD_TAGS:Oe(c.ADD_TAGS)&&(x===xi&&(x=ne(x)),A(x,c.ADD_TAGS,O))),K(c,"ADD_ATTR")&&(typeof c.ADD_ATTR=="function"?Ce.attributeCheck=c.ADD_ATTR:Oe(c.ADD_ATTR)&&(k===ki&&(k=ne(k)),A(k,c.ADD_ATTR,O))),K(c,"ADD_URI_SAFE_ATTR")&&Oe(c.ADD_URI_SAFE_ATTR)&&A(En,c.ADD_URI_SAFE_ATTR,O),K(c,"FORBID_CONTENTS")&&Oe(c.FORBID_CONTENTS)&&(fe===_n&&(fe=ne(fe)),A(fe,c.FORBID_CONTENTS,O)),K(c,"ADD_FORBID_CONTENTS")&&Oe(c.ADD_FORBID_CONTENTS)&&(fe===_n&&(fe=ne(fe)),A(fe,c.ADD_FORBID_CONTENTS,O)),bn&&(x["#text"]=!0),Me&&A(x,["html","head","body"]),x.table&&(A(x,["tbody"]),delete ct.tbody),c.TRUSTED_TYPES_POLICY){if(typeof c.TRUSTED_TYPES_POLICY.createHTML!="function")throw We('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof c.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw We('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');let m=ie;ie=c.TRUSTED_TYPES_POLICY;try{Ie=Ke("")}catch(T){throw ie=m,T}}else c.TRUSTED_TYPES_POLICY===null?(ie=void 0,Ie=""):(ie===void 0&&(ie=Fo()),ie&&typeof Ie=="string"&&(Ie=Ke("")));j&&j(c),Ze=c},$i=A({},[...$n,...Kn,...ya]),Ki=A({},[...Vn,...ba]),ts=function(c,f,m){return f.namespaceURI===pe?c==="svg":f.namespaceURI===Dt?c==="svg"&&(m==="annotation-xml"||An[m]):!!$i[c]},ns=function(c,f,m){return f.namespaceURI===pe?c==="math":f.namespaceURI===It?c==="math"&&Cn[m]:!!Ki[c]},is=function(c,f,m){return f.namespaceURI===It&&!Cn[m]||f.namespaceURI===Dt&&!An[m]?!1:!Ki[c]&&(Xo[c]||!$i[c])},rs=function(c){let f=N(c);(!f||!f.tagName)&&(f={namespaceURI:je,tagName:"template"});let m=_t(c.tagName),T=_t(f.tagName);return Sn[c.namespaceURI]?c.namespaceURI===It?ts(m,f,T):c.namespaceURI===Dt?ns(m,f,T):c.namespaceURI===pe?is(m,f,T):!!(ut==="application/xhtml+xml"&&Sn[c.namespaceURI]):!1},we=function(c){et(t.removed,{element:c});try{N(c).removeChild(c)}catch{if(y(c),!N(c))throw We("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},Vi=function(c){let f=S(c);if(f){let T=[];yt(f,v=>{et(T,v)}),yt(T,v=>{try{y(v)}catch{}})}let m=J(c);if(m)for(let T=m.length-1;T>=0;--T){let v=m[T],C=v&&v.name;if(typeof C=="string")try{c.removeAttribute(C)}catch{}}},Pe=function(c,f){try{et(t.removed,{attribute:f.getAttributeNode(c),from:f})}catch{et(t.removed,{attribute:null,from:f})}if(f.removeAttribute(c),c==="is")if(Ve||Rt)try{we(f)}catch{}else try{f.setAttribute(c,"")}catch{}},os=function(c){let f=J(c);if(f)for(let m=f.length-1;m>=0;--m){let T=f[m],v=T&&T.name;if(!(typeof v!="string"||k[O(v)]))try{c.removeAttribute(v)}catch{}}},ss=function(c){let f=[c];for(;f.length>0;){let m=f.pop();(U?U(m):m.nodeType)===ye.element&&os(m);let v=S(m);if(v)for(let C=v.length-1;C>=0;--C)f.push(v[C])}},Gi=function(c){let f=null,m=null;if(yn)c="<remove></remove>"+c;else{let C=Lr(c,/^[\r\n\t ]+/);m=C&&C[0]}ut==="application/xhtml+xml"&&je===pe&&(c='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+c+"</body></html>");let T=ie?Ke(c):c;if(je===pe)try{f=new d().parseFromString(T,ut)}catch{}if(!f||!f.documentElement){f=dn.createDocument(je,"template",null);try{f.documentElement.innerHTML=vn?Ie:T}catch{}}let v=f.body||f.documentElement;return c&&m&&v.insertBefore(n.createTextNode(m),v.childNodes[0]||null),je===pe?zo.call(f,Me?"html":"body")[0]:Me?f.documentElement:v},ji=function(c){return Li.call(c.ownerDocument||c,c,l.SHOW_ELEMENT|l.SHOW_COMMENT|l.SHOW_TEXT|l.SHOW_PROCESSING_INSTRUCTION|l.SHOW_CDATA_SECTION,null)},Mt=function(c){return c=bt(c,Wo," "),c=bt(c,$o," "),c=bt(c,Ko," "),c},wn=function(c){var f;c.normalize();let m=Li.call(c.ownerDocument||c,c,l.SHOW_TEXT|l.SHOW_COMMENT|l.SHOW_CDATA_SECTION|l.SHOW_PROCESSING_INSTRUCTION,null),T=m.nextNode();for(;T;)T.data=Mt(T.data),T=m.nextNode();let v=(f=c.querySelectorAll)===null||f===void 0?void 0:f.call(c,"template");v&&yt(v,C=>{Ye(C.content)&&wn(C.content)})},Pt=function(c){let f=he?he(c):null;return typeof f!="string"||O(f)!=="form"?!1:typeof c.nodeName!="string"||typeof c.textContent!="string"||typeof c.removeChild!="function"||c.attributes!==J(c)||typeof c.removeAttribute!="function"||typeof c.setAttribute!="function"||typeof c.namespaceURI!="string"||typeof c.insertBefore!="function"||typeof c.hasChildNodes!="function"||c.nodeType!==U(c)||c.childNodes!==S(c)},Ye=function(c){if(!U||typeof c!="object"||c===null)return!1;try{return U(c)===ye.documentFragment}catch{return!1}},dt=function(c){if(!U||typeof c!="object"||c===null)return!1;try{return typeof U(c)=="number"}catch{return!1}};function Te(g,c,f){g.length!==0&&yt(g,m=>{m.call(t,c,f,Ze)})}let as=function(c,f){return!!(ht&&c.hasChildNodes()&&!dt(c.firstElementChild)&&G(Mr,c.textContent)&&G(Mr,c.innerHTML)||ht&&c.namespaceURI===pe&&f==="style"&&dt(c.firstElementChild)||c.nodeType===ye.processingInstruction||ht&&c.nodeType===ye.comment&&G(Na,c.data))},ls=function(c,f){if(!ct[f]&&Xi(f)&&(R.tagNameCheck instanceof RegExp&&G(R.tagNameCheck,f)||R.tagNameCheck instanceof Function&&R.tagNameCheck(f)))return!1;if(bn&&!fe[f]){let m=N(c),T=S(c);if(T&&m){let v=T.length;for(let C=v-1;C>=0;--C){let q=Tn?T[C]:b(T[C],!0);m.insertBefore(q,E(c))}}}return we(c),!0},Zi=function(c){if(Te(M.beforeSanitizeElements,c,null),Pt(c))return we(c),!0;let f=O(he?he(c):c.nodeName);if(Te(M.uponSanitizeElement,c,{tagName:f,allowedTags:x}),as(c,f))return we(c),!0;if(ct[f]||!(Ce.tagCheck instanceof Function&&Ce.tagCheck(f))&&!x[f])return ls(c,f);if((U?U(c):c.nodeType)===ye.element&&!rs(c)||(f==="noscript"||f==="noembed"||f==="noframes")&&G(xa,c.innerHTML))return we(c),!0;if(Le&&c.nodeType===ye.text){let T=Mt(c.textContent);c.textContent!==T&&(et(t.removed,{element:c.cloneNode()}),c.textContent=T)}return Te(M.afterSanitizeElements,c,null),!1},Yi=function(c,f,m){if(Ri[f]||Mi&&(f==="id"||f==="name")&&(m in n||m in es))return!1;let T=k[f]||Ce.attributeCheck instanceof Function&&Ce.attributeCheck(f,c);if(!(fn&&G(Vo,f))){if(!(Oi&&G(Go,f))){if(T){if(!En[f]){if(!G(Ni,bt(m,wi,""))){if(!((f==="src"||f==="xlink:href"||f==="href")&&c!=="script"&&wr(m,"data:")===0&&Hi[c])){if(!(Di&&!G(jo,bt(m,wi,"")))){if(m)return!1}}}}}else if(!(Xi(c)&&(R.tagNameCheck instanceof RegExp&&G(R.tagNameCheck,c)||R.tagNameCheck instanceof Function&&R.tagNameCheck(c))&&(R.attributeNameCheck instanceof RegExp&&G(R.attributeNameCheck,f)||R.attributeNameCheck instanceof Function&&R.attributeNameCheck(f,c))||f==="is"&&R.allowCustomizedBuiltInElements&&(R.tagNameCheck instanceof RegExp&&G(R.tagNameCheck,m)||R.tagNameCheck instanceof Function&&R.tagNameCheck(m))))return!1}}return!0},cs=A({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),Xi=function(c){return!cs[_t(c)]&&G(Zo,c)},hs=function(c,f,m,T){if(ie&&typeof u=="object"&&typeof u.getAttributeType=="function"&&!m)switch(u.getAttributeType(c,f)){case"TrustedHTML":return Ke(T);case"TrustedScriptURL":return Ho(T)}return T},us=function(c,f,m,T){try{m?c.setAttributeNS(m,f,T):c.setAttribute(f,T),Pt(c)?we(c):Cr(t.removed)}catch{Pe(f,c)}},Qi=function(c){Te(M.beforeSanitizeAttributes,c,null);let f=c.attributes;if(!f||Pt(c))return;let m={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:k,forceKeepAttr:void 0},T=f.length,v=O(c.nodeName);for(;T--;){let C=f[T],q=C.name,B=C.namespaceURI,ae=C.value,ue=O(q),xn=ae,ee=q==="value"?xn:ha(xn);if(m.attrName=ue,m.attrValue=ee,m.keepAttr=!0,m.forceKeepAttr=void 0,Te(M.uponSanitizeAttribute,c,m),ee=m.attrValue,Pi&&(ue==="id"||ue==="name")&&wr(ee,Bi)!==0&&(Pe(q,c),ee=Bi+ee),ht&&G(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,ee)){Pe(q,c);continue}if(ue==="attributename"&&Lr(ee,"href")){Pe(q,c);continue}if(!m.forceKeepAttr){if(!m.keepAttr){Pe(q,c);continue}if(!Ii&&G(ka,ee)){Pe(q,c);continue}if(Le&&(ee=Mt(ee)),!Yi(v,ue,ee)){Pe(q,c);continue}ee=hs(v,ue,B,ee),ee!==xn&&us(c,q,B,ee)}}Te(M.afterSanitizeAttributes,c,null)},Bt=function(c){let f=null,m=ji(c);for(Te(M.beforeSanitizeShadowDOM,c,null);f=m.nextNode();)if(Te(M.uponSanitizeShadowNode,f,null),Zi(f),Qi(f),Ye(f.content)&&Bt(f.content),(U?U(f):f.nodeType)===ye.element){let v=P(f);Ye(v)&&(Nn(v),Bt(v))}Te(M.afterSanitizeShadowDOM,c,null)},Nn=function(c){let f=[{node:c,shadow:null}];for(;f.length>0;){let m=f.pop();if(m.shadow){Bt(m.shadow);continue}let T=m.node,C=(U?U(T):T.nodeType)===ye.element,q=S(T);if(q)for(let B=q.length-1;B>=0;--B)f.push({node:q[B],shadow:null});if(C){let B=he?he(T):null;if(typeof B=="string"&&O(B)==="template"){let ae=T.content;Ye(ae)&&f.push({node:ae,shadow:null})}}if(C){let B=P(T);Ye(B)&&f.push({node:null,shadow:B},{node:B,shadow:null})}}};return t.sanitize=function(g){let c=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},f=null,m=null,T=null,v=null;if(vn=!g,vn&&(g="<!-->"),typeof g!="string"&&!dt(g)&&(g=ma(g),typeof g!="string"))throw We("dirty is not a string, aborting");if(!t.isSupported)return g;pn?(x=mn,k=gn):Ln(c),(M.uponSanitizeElement.length>0||M.uponSanitizeAttribute.length>0)&&(x=ne(x)),M.uponSanitizeAttribute.length>0&&(k=ne(k)),t.removed=[];let C=Tn&&typeof g!="string"&&dt(g);if(C){let ae=he?he(g):g.nodeName;if(typeof ae=="string"){let ue=O(ae);if(!x[ue]||ct[ue])throw We("root node is forbidden and cannot be sanitized in-place")}if(Pt(g))throw We("root node is clobbered and cannot be sanitized in-place");try{Nn(g)}catch(ue){throw Vi(g),ue}}else if(dt(g))f=Gi("<!---->"),m=f.ownerDocument.importNode(g,!0),m.nodeType===ye.element&&m.nodeName==="BODY"||m.nodeName==="HTML"?f=m:f.appendChild(m),Nn(m);else{if(!Ve&&!Le&&!Me&&g.indexOf("<")===-1)return ie&&Ot?Ke(g):g;if(f=Gi(g),!f)return Ve?null:Ot?Ie:""}f&&yn&&we(f.firstChild);let q=ji(C?g:f);try{for(;T=q.nextNode();)Zi(T),Qi(T),Ye(T.content)&&Bt(T.content)}catch(ae){throw C&&Vi(g),ae}if(C)return yt(t.removed,ae=>{ae.element&&ss(ae.element)}),Le&&wn(g),g;if(Ve){if(Le&&wn(f),Rt)for(v=Uo.call(f.ownerDocument);f.firstChild;)v.appendChild(f.firstChild);else v=f;return(k.shadowroot||k.shadowrootmode)&&(v=qo.call(i,v,!0)),v}let B=Me?f.outerHTML:f.innerHTML;return Me&&x["!doctype"]&&f.ownerDocument&&f.ownerDocument.doctype&&f.ownerDocument.doctype.name&&G(La,f.ownerDocument.doctype.name)&&(B="<!DOCTYPE "+f.ownerDocument.doctype.name+`>
24
- `+B),Le&&(B=Mt(B)),ie&&Ot?Ke(B):B},t.setConfig=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ln(g),pn=!0,mn=x,gn=k},t.clearConfig=function(){Ze=null,pn=!1,mn=null,gn=null,ie=un,Ie=""},t.isValidAttribute=function(g,c,f){Ze||Ln({});let m=O(g),T=O(c);return Yi(m,T,f)},t.addHook=function(g,c){typeof c=="function"&&K(M,g)&&et(M[g],c)},t.removeHook=function(g,c){if(K(M,g)){if(c!==void 0){let f=la(M[g],c);return f===-1?void 0:ca(M[g],f,1)[0]}return Cr(M[g])}},t.removeHooks=function(g){K(M,g)&&(M[g]=[])},t.removeAllHooks=function(){M=Pr()},t}var Ur=Fr();var z=(e,t="0 0 18 18")=>`<svg viewBox="${t}" width="18" height="18" aria-hidden="true" focusable="false">${e}</svg>`,I={bold:z('<path fill="currentColor" d="M178.48,115.7A44,44,0,0,0,148,40H80a8,8,0,0,0-8,8V200a8,8,0,0,0,8,8h80a48,48,0,0,0,18.48-92.3ZM88,56h60a28,28,0,0,1,0,56H88Zm72,136H88V128h72a32,32,0,0,1,0,64Z"/>',"0 0 256 256"),italic:z('<path fill="currentColor" d="M200,56a8,8,0,0,1-8,8H157.77L115.1,192H144a8,8,0,0,1,0,16H64a8,8,0,0,1,0-16H98.23L140.9,64H112a8,8,0,0,1,0-16h80A8,8,0,0,1,200,56Z"/>',"0 0 256 256"),underline:z('<path fill="currentColor" d="M200,224a8,8,0,0,1-8,8H64a8,8,0,0,1,0-16H192A8,8,0,0,1,200,224Zm-72-24a64.07,64.07,0,0,0,64-64V56a8,8,0,0,0-16,0v80a48,48,0,0,1-96,0V56a8,8,0,0,0-16,0v80A64.07,64.07,0,0,0,128,200Z"/>',"0 0 256 256"),strike:z('<path fill="currentColor" d="M224,128a8,8,0,0,1-8,8H175.93c9.19,7.11,16.07,17.2,16.07,32,0,13.34-7,25.7-19.75,34.79C160.33,211.31,144.61,216,128,216s-32.33-4.69-44.25-13.21C71,193.7,64,181.34,64,168a8,8,0,0,1,16,0c0,17.35,22,32,48,32s48-14.65,48-32c0-14.85-10.54-23.58-38.77-32H40a8,8,0,0,1,0-16H216A8,8,0,0,1,224,128ZM76.33,104a8,8,0,0,0,7.61-10.49A17.3,17.3,0,0,1,83.11,88c0-18.24,19.3-32,44.89-32,18.84,0,34.16,7.42,41,19.85a8,8,0,0,0,14-7.7C173.33,50.52,152.77,40,128,40,93.29,40,67.11,60.63,67.11,88a33.73,33.73,0,0,0,1.62,10.49A8,8,0,0,0,76.33,104Z"/>',"0 0 256 256"),link:z('<path fill="currentColor" d="M240,88.23a54.43,54.43,0,0,1-16,37L189.25,160a54.27,54.27,0,0,1-38.63,16h-.05A54.63,54.63,0,0,1,96,119.84a8,8,0,0,1,16,.45A38.62,38.62,0,0,0,150.58,160h0a38.39,38.39,0,0,0,27.31-11.31l34.75-34.75a38.63,38.63,0,0,0-54.63-54.63l-11,11A8,8,0,0,1,135.7,59l11-11A54.65,54.65,0,0,1,224,48,54.86,54.86,0,0,1,240,88.23ZM109,185.66l-11,11A38.41,38.41,0,0,1,70.6,208h0a38.63,38.63,0,0,1-27.29-65.94L78,107.31A38.63,38.63,0,0,1,144,135.71a8,8,0,0,0,16,.45A54.86,54.86,0,0,0,144,96a54.65,54.65,0,0,0-77.27,0L32,130.75A54.62,54.62,0,0,0,70.56,224h0a54.28,54.28,0,0,0,38.64-16l11-11A8,8,0,0,0,109,185.66Z"/>',"0 0 256 256"),unlink:z('<path fill="currentColor" d="M198.63,57.37a32,32,0,0,0-45.19-.06L141.79,69.52a8,8,0,0,1-11.58-11l11.72-12.29a1.59,1.59,0,0,1,.13-.13,48,48,0,0,1,67.88,67.88,1.59,1.59,0,0,1-.13.13l-12.29,11.72a8,8,0,0,1-11-11.58l12.21-11.65A32,32,0,0,0,198.63,57.37ZM114.21,186.48l-11.65,12.21a32,32,0,0,1-45.25-45.25l12.21-11.65a8,8,0,0,0-11-11.58L46.19,141.93a1.59,1.59,0,0,0-.13.13,48,48,0,0,0,67.88,67.88,1.59,1.59,0,0,0,.13-.13l11.72-12.29a8,8,0,1,0-11.58-11ZM216,152H192a8,8,0,0,0,0,16h24a8,8,0,0,0,0-16ZM40,104H64a8,8,0,0,0,0-16H40a8,8,0,0,0,0,16Zm120,80a8,8,0,0,0-8,8v24a8,8,0,0,0,16,0V192A8,8,0,0,0,160,184ZM96,72a8,8,0,0,0,8-8V40a8,8,0,0,0-16,0V64A8,8,0,0,0,96,72Z"/>',"0 0 256 256"),ul:z('<path fill="currentColor" d="M80,64a8,8,0,0,1,8-8H216a8,8,0,0,1,0,16H88A8,8,0,0,1,80,64Zm136,56H88a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16Zm0,64H88a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16ZM44,52A12,12,0,1,0,56,64,12,12,0,0,0,44,52Zm0,64a12,12,0,1,0,12,12A12,12,0,0,0,44,116Zm0,64a12,12,0,1,0,12,12A12,12,0,0,0,44,180Z"/>',"0 0 256 256"),ol:z('<path fill="currentColor" d="M224,128a8,8,0,0,1-8,8H104a8,8,0,0,1,0-16H216A8,8,0,0,1,224,128ZM104,72H216a8,8,0,0,0,0-16H104a8,8,0,0,0,0,16ZM216,184H104a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16ZM43.58,55.16,48,52.94V104a8,8,0,0,0,16,0V40a8,8,0,0,0-11.58-7.16l-16,8a8,8,0,0,0,7.16,14.32ZM79.77,156.72a23.73,23.73,0,0,0-9.6-15.95,24.86,24.86,0,0,0-34.11,4.7,23.63,23.63,0,0,0-3.57,6.46,8,8,0,1,0,15,5.47,7.84,7.84,0,0,1,1.18-2.13,8.76,8.76,0,0,1,12-1.59A7.91,7.91,0,0,1,63.93,159a7.64,7.64,0,0,1-1.57,5.78,1,1,0,0,0-.08.11L33.59,203.21A8,8,0,0,0,40,216H72a8,8,0,0,0,0-16H56l19.08-25.53A23.47,23.47,0,0,0,79.77,156.72Z"/>',"0 0 256 256"),quote:z('<path fill="currentColor" d="M100,56H40A16,16,0,0,0,24,72v64a16,16,0,0,0,16,16h60v8a32,32,0,0,1-32,32,8,8,0,0,0,0,16,48.05,48.05,0,0,0,48-48V72A16,16,0,0,0,100,56Zm0,80H40V72h60ZM216,56H156a16,16,0,0,0-16,16v64a16,16,0,0,0,16,16h60v8a32,32,0,0,1-32,32,8,8,0,0,0,0,16,48.05,48.05,0,0,0,48-48V72A16,16,0,0,0,216,56Zm0,80H156V72h60Z"/>',"0 0 256 256"),undo:z('<path fill="currentColor" d="M224,128a96,96,0,0,1-94.71,96H128A95.38,95.38,0,0,1,62.1,197.8a8,8,0,0,1,11-11.63A80,80,0,1,0,71.43,71.39a3.07,3.07,0,0,1-.26.25L44.59,96H72a8,8,0,0,1,0,16H24a8,8,0,0,1-8-8V56a8,8,0,0,1,16,0V85.8L60.25,60A96,96,0,0,1,224,128Z"/>',"0 0 256 256"),redo:z('<path fill="currentColor" d="M240,56v48a8,8,0,0,1-8,8H184a8,8,0,0,1,0-16H211.4L184.81,71.64l-.25-.24a80,80,0,1,0-1.67,114.78,8,8,0,0,1,11,11.63A95.44,95.44,0,0,1,128,224h-1.32A96,96,0,1,1,195.75,60L224,85.8V56a8,8,0,1,1,16,0Z"/>',"0 0 256 256"),clear:z('<path fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="square" stroke-linejoin="miter" d="M3 3l18 18M5 5v3M9 5h10v3M12 5v3M12 12v7M8 19h8"/>',"0 0 24 24"),code:z('<path fill="currentColor" d="M69.12,94.15,28.5,128l40.62,33.85a8,8,0,1,1-10.24,12.29l-48-40a8,8,0,0,1,0-12.29l48-40a8,8,0,0,1,10.24,12.3Zm176,27.7-48-40a8,8,0,1,0-10.24,12.3L227.5,128l-40.62,33.85a8,8,0,1,0,10.24,12.29l48-40a8,8,0,0,0,0-12.29ZM162.73,32.48a8,8,0,0,0-10.25,4.79l-64,176a8,8,0,0,0,4.79,10.26A8.14,8.14,0,0,0,96,224a8,8,0,0,0,7.52-5.27l64-176A8,8,0,0,0,162.73,32.48Z"/>',"0 0 256 256"),indent:z('<path fill="currentColor" d="M224,128a8,8,0,0,1-8,8H112a8,8,0,0,1,0-16H216A8,8,0,0,1,224,128ZM112,72H216a8,8,0,0,0,0-16H112a8,8,0,0,0,0,16ZM216,184H40a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16ZM34.34,141.66a8,8,0,0,0,11.32,0l40-40a8,8,0,0,0,0-11.32l-40-40A8,8,0,0,0,34.34,61.66L68.69,96,34.34,130.34A8,8,0,0,0,34.34,141.66Z"/>',"0 0 256 256"),outdent:z('<path fill="currentColor" d="M224,128a8,8,0,0,1-8,8H112a8,8,0,0,1,0-16H216A8,8,0,0,1,224,128ZM112,72H216a8,8,0,0,0,0-16H112a8,8,0,0,0,0,16ZM216,184H40a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16ZM72,144a8,8,0,0,0,5.66-13.66L43.31,96,77.66,61.66A8,8,0,0,0,66.34,50.34l-40,40a8,8,0,0,0,0,11.32l40,40A8,8,0,0,0,72,144Z"/>',"0 0 256 256"),blocks:z('<path fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="square" stroke-linejoin="miter" d="M19 4h-9a4.5 4.5 0 0 0 0 9h3M13 4v16M17 4v16"/>',"0 0 24 24"),h1:z('<path fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" d="M3.5 5.5v12M12 5.5v12M3.5 11.5H12M17 12l3-2v10"/>',"0 0 24 24"),h2:z('<path fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" d="M3.5 5.5v12M12 5.5v12M3.5 11.5H12M16 12.5c0-3.5 6-3.5 6 0 0 2-2.5 3.5-6 7.5h6"/>',"0 0 24 24"),h3:z('<path fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" d="M3.5 5.5v12M12 5.5v12M3.5 11.5H12M16 11c1.5-1.5 6-1.5 6 1.5 0 1.5-1.5 2.5-3 2.5h-1M19 15c1.5 0 3 1 3 2.5 0 3-4.5 3-6 1.5"/>',"0 0 24 24")},Se=e=>e.blocksStayOut(),Da=e=>!!e.element.closest("a"),Et={minimal:["bold","italic","link","unorderedList"],inline:["bold","italic","underline","strikethrough","code","link","undo","redo","clearFormatting"],standard:["blockMenu","bold","italic","underline","strikethrough","code","link","unorderedList","orderedList","quote","outdent","indent","undo","redo","clearFormatting"]};function zr(){return new Map(Ia.map(e=>[e.id,e]))}function nt(e=globalThis){let t=e?.navigator;return t?/Mac|iPhone|iPad|iPod/.test(t.platform||t.userAgent||""):!1}function qr(e,t=globalThis){return e?e.replace("Mod",nt(t)?"Cmd":"Ctrl"):""}var Ia=[De("bold","Bold",I.bold,"Mod+B","inline",e=>e.toggleFormat("B","bold","removeBold")),De("italic","Italic",I.italic,"Mod+I","inline",e=>e.toggleFormat("I","italic","removeItalic")),De("underline","Underline",I.underline,"Mod+U","inline",e=>e.toggleFormat("U","underline","removeUnderline")),De("strikethrough","Strikethrough",I.strike,"Mod+Shift+7","inline",e=>e.toggleFormat("S","strikethrough","removeStrikethrough")),De("code","Code",I.code,null,"inline",e=>e.toggleCode(),e=>e.selectionHasFormat("CODE")||e.selectionHasFormat("PRE")),{id:"link",label:"Link",ariaLabel:"Insert or edit link",icon:I.link,group:"links",shortcut:"Mod+K",mutates:!1,isDisabled:Da,run:e=>e.openLinkDialog(),isActive:e=>!!e.currentLinkElement()},{id:"unlink",label:"Remove link",ariaLabel:"Remove link",icon:I.unlink,group:"links",run:e=>e.squire.removeLink()},De("unorderedList","Bulleted list",I.ul,"Mod+Shift+8","lists",e=>e.toggleList("UL"),e=>e.pathHas("UL"),Se),De("orderedList","Numbered list",I.ol,"Mod+Shift+9","lists",e=>e.toggleList("OL"),e=>e.pathHas("OL"),Se),De("quote","Quote",I.quote,null,"blocks",e=>e.pathHas("BLOCKQUOTE")?e.squire.decreaseQuoteLevel():e.squire.increaseQuoteLevel(),e=>e.pathHas("BLOCKQUOTE"),Se),{id:"outdent",label:"Outdent",ariaLabel:"Decrease indent",icon:I.outdent,group:"blocks",shortcut:"Mod+[",isDisabled:Se,run:e=>e.outdent()},{id:"indent",label:"Indent",ariaLabel:"Increase indent",icon:I.indent,group:"blocks",shortcut:"Mod+]",isDisabled:Se,run:e=>e.indent()},{id:"undo",label:"Undo",ariaLabel:"Undo",icon:I.undo,group:"history",shortcut:"Mod+Z",mutates:!1,run:e=>e.squire.undo()},{id:"redo",label:"Redo",ariaLabel:"Redo",icon:I.redo,group:"history",shortcut:"Mod+Shift+Z",mutates:!1,run:e=>e.squire.redo()},{id:"clearFormatting",label:"Clear formatting",ariaLabel:"Clear formatting",icon:I.clear,group:"cleanup",run:e=>e.squire.removeAllFormatting()},{id:"blockMenu",type:"menu",label:"Block style",ariaLabel:"Choose block style",icon:I.blocks,group:"blocks",isDisabled:Se,options:[Vt("Paragraph","P",I.blocks),Vt("Heading 1","H1",I.h1),Vt("Heading 2","H2",I.h2),Vt("Heading 3","H3",I.h3),{label:"Quote",icon:I.quote,value:"BLOCKQUOTE",isDisabled:Se,run:e=>e.squire.increaseQuoteLevel(),isActive:e=>e.pathHas("BLOCKQUOTE")},{label:"Code block",icon:I.code,value:"PRE",isDisabled:Se,run:e=>e.setBlockType("PRE"),isActive:e=>e.pathHas("PRE")}]}];function De(e,t,n,i,r,o,s=l=>l.selectionHasFormat(Ma(e)),a){return{id:e,label:t,ariaLabel:t,icon:n,group:r,shortcut:i,isDisabled:a,run:o,isActive:s}}function Ma(e){return{bold:"B",italic:"I",underline:"U",strikethrough:"S"}[e]}function Vt(e,t,n){return{label:e,icon:n,value:t,isDisabled:Se,run:i=>i.setBlockType(t),isActive:i=>i.pathHas(t)}}var Xn=/^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:FRAME|MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|TIME|U|VAR|WBR)$/,jt=/[^ \t\r\n]/;var Pa=new Set(["BR","HR","IFRAME","IMG","INPUT","WBR"]),Qn=e=>e?.nodeType===1&&e.matches('[editor-ui],[clay~="editor-ui"]'),St=new Set(["svg","math"]);function Zt(e){let t=e.nodeType;return t===3||t===8?!0:t!==1?!1:St.has(e.nodeName)?!0:Xn.test(e.nodeName)?Array.from(e.childNodes).every(Zt):!1}function At(e){return Array.from(e.childNodes).some(t=>!Zt(t))}var Yn=e=>e?.nodeType===1&&!St.has(e.nodeName)&&!Xn.test(e.nodeName);function Ct(e,t){let n=Array.from(e.childNodes),i=0;return n.forEach((r,o)=>{if(!(r.nodeType!==1||St.has(r.nodeName))&&(i+=Ct(r,t),!!Yn(r))){for(Yn(n[o-1])&&e.insertBefore(t(),r);r.firstChild;)e.insertBefore(r.firstChild,r);r.remove(),i+=1}}),i}var Jn=new Set(["TABLE","THEAD","TBODY","TFOOT","TR","COLGROUP"]);function Yt(e){return!!e.closest?.("p")||Jn.has(e.nodeName)}var Ba=new Set(["P","H1","H2","H3","H4","H5","H6","PRE","LABEL","LEGEND","LI","TD","TH","DT","DD","FIGCAPTION","SUMMARY","CAPTION"]);function Vr(e){return Ba.has(e.nodeName)||Xt(e)}var Gr=new Set(["AREA","BASE","BR","COL","EMBED","HR","IMG","INPUT","LINK","META","PARAM","SOURCE","TRACK","WBR"]),Ha=new Set(["SCRIPT","STYLE","TEXTAREA","TITLE","IFRAME","NOSCRIPT","XMP"]),jr="http://www.w3.org/1999/xhtml";function Zr(e){return Jn.has(e.nodeName)||Gr.has(e.nodeName)||Ha.has(e.nodeName)||e.nodeName==="TEMPLATE"||!!e.namespaceURI&&e.namespaceURI!==jr}function Yr(e){return Jn.has(e.nodeName)?"a table element cannot be an editable region. Move the editable attribute to a <td>, a <th>, or an element inside one.":e.namespaceURI&&e.namespaceURI!==jr?"an SVG or MathML element cannot be an editable region: an edit puts an HTML block inside it, and the next page load moves that text out of the graphic entirely. Put a <foreignObject> in the SVG and mark an HTML element inside it instead.":Gr.has(e.nodeName)?"this element cannot contain anything, so there is nothing to edit. Move the editable attribute to an element that holds text.":e.nodeName==="TEMPLATE"?"a <template> keeps its content out of the document, so edits to it are never saved.":"this element treats its content as plain text, so any edit would be saved as visible markup rather than formatting."}function Xt(e){return e.nodeType===1&&!St.has(e.nodeName)&&Xn.test(e.nodeName)}function Qt(e){return Array.from(e.querySelectorAll("*")).some(Yn)}function Xr(e,t={}){let{blockTag:n="DIV",wrapBareRoot:i=!1,onBareRootWrapped:r,blocksAllowed:o=!Yt(e)}=t;return eo(e),o&&za(e,n,i,r),e}var Fa=e=>Zt(e)&&e.nodeType!==8&&!Qn(e),Ua=e=>e.nodeType!==8&&!Qn(e)&&!(e.nodeType===3&&!jt.test(e.nodeValue));function Qr(e,{wrapBareRoot:t=!1,blocksAllowed:n=!Yt(e)}={}){return n?At(e)?Array.from(e.childNodes).some(Fa)||Jr(e):t:!1}function Jr(e){return Array.from(e.children).some(t=>At(t)?!ei(t)&&Array.from(t.childNodes).some(i=>i.nodeType===3&&!jt.test(i.nodeValue))||Jr(t):!1)}function eo(e){At(e)&&(ei(e)||Array.from(e.childNodes).forEach(t=>{t.nodeType===3&&!jt.test(t.nodeValue)&&t.remove()}),Array.from(e.children).forEach(eo))}function za(e,t,n,i){if(!At(e)){if(!n)return;let s=e.ownerDocument.createElement(t);if(!Array.from(e.childNodes).some(Ua)){s.appendChild(e.ownerDocument.createElement("BR")),e.appendChild(s);return}for(;e.firstChild;)s.appendChild(e.firstChild);e.appendChild(s),i?.(e,s);return}let r=[],o=()=>{let s=r;if(r=[],!s.some(l=>l.nodeType!==8))return;let a=e.ownerDocument.createElement(t);e.insertBefore(a,s[0]),s.forEach(l=>a.appendChild(l))};Array.from(e.childNodes).forEach(s=>{Qn(s)?o():Zt(s)?r.push(s):o()}),o()}function ei(e){return e.nodeName==="PRE"}function to(e,t){return{start:Wr(e,t.startContainer,t.startOffset),end:Wr(e,t.endContainer,t.endOffset),collapsed:t.collapsed}}function no(e,t,n){Kr(t,"setStart",e,n.start),n.collapsed?t.collapse(!0):Kr(t,"setEnd",e,n.end)}function Wr(e,t,n){if(!e.contains(t))return{scope:e,after:[],before:[]};if(t.nodeType===3){if(!qa(t))return{container:t,offset:n};let i=t.parentNode;return $r(i,Array.from(i.childNodes).indexOf(t))}return{container:t,offset:n,childCount:t.childNodes.length,...$r(t,n)}}function $r(e,t){let n=Array.from(e.childNodes),i=Math.max(0,t);return{scope:e,after:n.slice(i),before:n.slice(0,i).reverse()}}function Kr(e,t,n,i){let{container:r,childCount:o}=i;if(r&&n.contains(r)&&(o===void 0||o===r.childNodes.length)){e[t](r,Math.min(i.offset,Gt(r)));return}let s=i.after?.find(h=>n.contains(h));if(s){e[t](vt(s,!0),0);return}let a=i.before?.find(h=>n.contains(h));if(a){let h=vt(a,!1);e[t](h,Gt(h));return}let l=i.scope&&n.contains(i.scope)?i.scope:n;e[t](l,0)}function qa(e){return e.nodeType===3&&!jt.test(e.nodeValue)&&!!e.parentNode&&e.parentNode.nodeType===1&&At(e.parentNode)&&!ei(e.parentNode)}var it=e=>e.nodeType===1||e.nodeType===3;function vt(e,t=!0){let n=e;for(;n.nodeType===1&&!St.has(n.nodeName);){let i=Array.from(n.childNodes).filter(it),r=t?i[0]:i[i.length-1];if(!r||Pa.has(r.nodeName))break;n=r}return n}function Gt(e){return e.nodeType===3?e.nodeValue.length:e.childNodes.length}var de="[data-richclay], [richclay], [editable], [clay-editable]",Wa="[data-richclay], [richclay], [clay-editable]",$a=["editable","clay-editable"],ii=':is([editable~="single-line"], [clay-editable~="single-line"])';function oi(e){return!e||typeof e.matches!="function"?!1:e.tagName.includes("-")?e.matches(Wa):!0}var Ka="[data-richclay-toolbar], [data-richclay-menu], [data-richclay-dialog], [data-richclay-link-popover], [data-richclay-live], [data-richclay-float]",Va=["richclay-editor","richclay-inline","richclay-active","richclay-empty","richclay-focused"],ri=new WeakSet,io=new WeakSet,ro=["clay:ready","hyperclay:ready"];function oo(e){return[e.clay?.ready,e.hyperclay?.ready].find(t=>t&&typeof t.then=="function")||null}function so(e){return typeof e.clay?.isEditMode=="boolean"?e.clay.isEditMode:typeof e.hyperclay?.isEditMode=="boolean"?e.hyperclay.isEditMode:null}function Ga(e){let t=e.hyperclayModules,n=e.__hyperclayNoAutoExport===!1&&t&&typeof t=="object"&&typeof t.nodeType!="number";return so(e)!==null||!!oo(e)||!!n}function ja(e){return e.clay?.addDocumentTransform||e.hyperclay?.beforeSave||null}function Za(e){return e.clay?.onSnapshot||e.hyperclay?.onSnapshot||null}var Ya={boxSizing:"border-box",minWidth:"100%",overflow:"auto",width:"0"};function Jt(e={},t=window){return e.hyperclay===!1?!1:e.hyperclay===!0?!0:!!(Ga(t)||rl(t))}function si(e=window){let t=co(e);if(t!==null)return t;if(typeof e.__hyperclayEditMode=="boolean")return e.__hyperclayEditMode;let n=so(e);return n!==null?n:ol(e)}function ao(e={},t=window){return e.readOnly?!1:Jt(e,t)?si(t):!0}function lo(e){let t=$a.find(r=>e.hasAttribute(r));if(!t)return null;let n=new Set((e.getAttribute(t)||"").trim().split(/\s+/).filter(Boolean)),i={inline:!0,singleLine:n.has("single-line"),toolbarOnSelect:n.has("toolbar-on-select")};return n.has("no-toolbar")&&(i.toolbar=!1),n.has("link-label")&&(i.singleLine=!0,i.linkLabel=!0,i.toolbar=["link","undo","redo"]),i}function ai(e=window){if(ri.has(e))return;let t=Za(e)||ja(e);if(typeof t!="function"){Xa(e);return}t(n=>li(n)),ri.add(e)}function Xa(e){if(io.has(e))return;let t=e.document,n=oo(e);if(!t&&!n)return;io.add(e);let i=()=>{ai(e),ri.has(e)&&r()},r=()=>{t&&ro.forEach(o=>t.removeEventListener(o,i))};t&&ro.forEach(o=>t.addEventListener(o,i)),n&&n.then(i,()=>{})}function li(e){e.querySelectorAll?.(Ka).forEach(t=>t.remove()),e.querySelectorAll?.(de).forEach(t=>{if(t.getAttribute("data-richclay-active")!=="true")return;if(en(t,"save"),tl(t)){let i=t.ownerDocument,r=!!t.matches?.(ii);Ct(t,()=>r?i.createTextNode(" "):i.createElement("br")),t.querySelectorAll(t.localName).forEach(o=>{for(;o.firstChild;)o.parentNode.insertBefore(o.firstChild,o);o.remove()})}t.matches?.(ii)&&il(t),t.querySelectorAll("#squire-selection-start, #squire-selection-end").forEach(i=>{i.remove()}),t.querySelectorAll(".squire-image-resize-container").forEach(i=>i.remove()),nl(t),(t.matches?.("pre")?[t,...t.querySelectorAll("pre")]:Array.from(t.querySelectorAll("pre"))).filter(i=>i.hasAttribute("data-richclay-pre")).forEach(i=>{Object.entries(Ya).forEach(([r,o])=>{i.style[r]||(i.style[r]=o)}),i.removeAttribute("data-richclay-pre")})}),e.querySelectorAll?.("#squire-selection-start, #squire-selection-end").forEach(t=>t.remove())}var Qa="p, td, th, li, dl, dt, dd, table, blockquote, div, section, article, aside, main, header, footer, figure, figcaption",ti="data-richclay-measure";function Ja(e){let t=e.ownerDocument,n=e.closest(Qa)||e;e.setAttribute(ti,"");let i=t.createElement("div");try{i.innerHTML=n.outerHTML}finally{e.removeAttribute(ti)}let r=i.querySelector(`[${ti}]`);return!r||r.textContent!==e.textContent}var el=e=>!!e.querySelector(e.localName),tl=e=>!!e.matches?.(ii)||(Qt(e)||el(e))&&Ja(e);function en(e,t){let n=e.getAttribute("data-richclay-runtime-contenteditable");e.hasAttribute("contenteditable")&&(n==="true"?e.removeAttribute("contenteditable"):n?t==="destroy"?e.setAttribute("contenteditable",n):(e.setAttribute("inert-contenteditable",n),e.removeAttribute("contenteditable")):t==="save"&&(e.setAttribute("inert-contenteditable",e.getAttribute("contenteditable")),e.removeAttribute("contenteditable"))),Va.forEach(i=>e.classList.remove(i)),e.getAttribute("class")===""&&e.removeAttribute("class"),ni(e,"role","data-richclay-runtime-role"),ni(e,"aria-multiline","data-richclay-runtime-aria-multiline"),ni(e,"no-undo","data-richclay-runtime-no-undo"),e.getAttribute("data-richclay-runtime-display")==="true"&&(e.style.removeProperty("display"),e.getAttribute("style")===""&&e.removeAttribute("style")),sl(e),e.removeAttribute("data-richclay-active"),e.removeAttribute("data-richclay-placeholder"),e.removeAttribute("data-richclay-pre"),e.removeAttribute("data-richclay-runtime-role"),e.removeAttribute("data-richclay-runtime-aria-multiline"),e.removeAttribute("data-richclay-runtime-no-undo"),e.removeAttribute("data-richclay-runtime-describedby"),e.removeAttribute("data-richclay-runtime-contenteditable"),e.removeAttribute("data-richclay-runtime-display"),e.getAttribute("data-richclay-runtime-marker")==="true"&&e.removeAttribute("data-richclay"),e.removeAttribute("data-richclay-runtime-marker")}function nl(e){let n=[e];for(;n.length;)n.pop().childNodes.forEach(r=>{r.nodeType===3?r.nodeValue.includes("\u200B")&&(r.nodeValue=r.nodeValue.split("\u200B").join("")):r.nodeType===1&&n.push(r)});e.querySelectorAll("b, i, u, s, em, strong, code, sub, sup, span").forEach(i=>{i.children.length===0&&(i.textContent||"")===""&&i.attributes.length===0&&i.remove()})}function il(e){let t=Array.from(e.childNodes).filter(i=>i.nodeType!==3||(i.nodeValue||"").trim()!=="");if(t.length!==1)return;let n=t[0];if(!(n.nodeType!==1||n.nodeName!=="P"||n.attributes.length>0)){for(;n.firstChild;)e.insertBefore(n.firstChild,n);n.remove()}}function ci(e){if(!e.hasAttribute("inert-contenteditable"))return null;let t=e.getAttribute("inert-contenteditable");return["false","plaintext-only"].includes(t)||(t="true"),e.setAttribute("contenteditable",t),e.removeAttribute("inert-contenteditable"),t==="true"&&e.setAttribute("data-richclay-runtime-contenteditable","true"),t}function ce(e){return e.setAttribute("snapshot-remove",""),e.setAttribute("no-watch",""),e}function co(e){try{let t=new URLSearchParams(e.location?.search||"");if(t.get("editmode")==="true")return!0;if(t.get("editmode")==="false")return!1}catch{return null}return null}function rl(e){return co(e)!==null||typeof e.__hyperclayEditMode=="boolean"}function ol(e){let n=(e.document?.cookie||"").match(/(?:^|;\s*)isAdminOfCurrentResource=([^;]*)/);return!!(n&&n[1]!=="")}function ni(e,t,n){e.hasAttribute(n)&&e.removeAttribute(t)}function sl(e){let t=e.getAttribute("data-richclay-runtime-describedby");if(!t)return;let n=(e.getAttribute("aria-describedby")||"").split(/\s+/).filter(Boolean).filter(i=>i!==t);n.length?e.setAttribute("aria-describedby",n.join(" ")):e.removeAttribute("aria-describedby")}var al=0;function ho(e=document){let t=e.createElement("div");return t.id=`richclay-live-${++al}`,t.className="richclay-sr-only",t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),t.setAttribute("data-richclay-live",""),ce(t),e.body.appendChild(t),t}function rt(e,t){!e||!t||(e.textContent="",e.ownerDocument.defaultView.setTimeout(()=>{e.textContent=t},20))}function Lt(e){e.preventDefault()}function hi(e){try{return e?.cloneRange?.()||null}catch{return null}}function ot(e){try{return hi(e?.getSelection?.())}catch{return null}}function tn(e,t){if(!e||!t)return!1;try{return e.setSelection(t),!0}catch{return!1}}function nn(e,t,n,i){e.hasAttribute(t)||e.setAttribute(i,"true"),e.setAttribute(t,n)}function uo(e,t){let n=new Set((e.getAttribute("aria-describedby")||"").split(/\s+/).filter(Boolean));n.add(t.id),e.setAttribute("aria-describedby",Array.from(n).join(" ")),e.setAttribute("data-richclay-runtime-describedby",t.id)}var ll=0,st=class{constructor(t,n,i={}){this.editor=t,this.controls=n,this.options=i,this.id=++ll,this.items=[],this.menus=new Map,this.activeIndex=0,this.root=this.createRoot(),this.onRootKeydown=r=>this.handleRootKeydown(r),this.onRootClick=r=>this.handleRootClick(r),this.onRootPointerDown=r=>this.handleRootPointerDown(r),this.onDocumentPointerDown=r=>this.handleDocumentPointerDown(r),this.render(),this.root.addEventListener("keydown",this.onRootKeydown),this.root.addEventListener("click",this.onRootClick),this.root.addEventListener("mousedown",this.onRootPointerDown),this.root.ownerDocument.addEventListener("mousedown",this.onDocumentPointerDown)}destroy(){this.closeMenus(),this.root.removeEventListener("keydown",this.onRootKeydown),this.root.removeEventListener("click",this.onRootClick),this.root.removeEventListener("mousedown",this.onRootPointerDown),this.root.ownerDocument.removeEventListener("mousedown",this.onDocumentPointerDown),this.root.remove()}update(){this.items.forEach(t=>{let{def:n,button:i}=t;if(typeof n.isActive=="function"){let r=!!n.isActive(this.editor);i.setAttribute("aria-pressed",r?"true":"false"),i.classList.toggle("is-active",r)}typeof n.isDisabled=="function"&&(i.disabled=!!n.isDisabled(this.editor))}),this.ensureSingleTabStop()}focusFirst(){this.activeIndex=0,this.ensureSingleTabStop(),this.items[0]?.button.focus()}createRoot(){let t=this.editor.element.ownerDocument,n=t.createElement("div");n.className="richclay-toolbar",n.setAttribute("role","toolbar"),n.setAttribute("aria-label",this.options.ariaLabel||"Rich text formatting"),n.setAttribute("data-richclay-toolbar",""),ce(n);let i=cl(this.options.toolbarContainer,t);return i?i.appendChild(n):this.editor.element.insertAdjacentElement("beforebegin",n),n}render(){this.root.textContent="",this.items=[],this.menus.clear();let t=null;this.visibleControls().forEach((n,i)=>{if(n.type==="separator"){this.root.appendChild(po(this.root.ownerDocument)),t=null;return}t&&n.group&&n.group!==t&&this.root.appendChild(po(this.root.ownerDocument)),t=n.group||t,n.type==="menu"?this.renderMenu(n,i):this.renderButton(n,i)}),this.ensureSingleTabStop(),this.update()}visibleControls(){let t=this.controls.filter(i=>i.type==="separator"||!i.isDisabled?.(this.editor)),n=[];for(t.forEach(i=>{let r=n[n.length-1];i.type==="separator"&&(!r||r.type==="separator")||n.push(i)});n[n.length-1]?.type==="separator";)n.pop();return n}renderButton(t,n){let i=fo(this.root.ownerDocument,t);i.dataset.richclayControl=t.id,i.dataset.richclayIndex=String(n),typeof t.isActive=="function"&&i.setAttribute("aria-pressed","false"),this.root.appendChild(i),this.items.push({def:t,button:i,type:"button"})}renderMenu(t,n){let i=this.root.ownerDocument,r=fo(i,t),o=`richclay-menu-${this.id}-${t.id}`;r.dataset.richclayControl=t.id,r.dataset.richclayIndex=String(n),r.setAttribute("aria-haspopup","menu"),r.setAttribute("aria-expanded","false"),r.setAttribute("aria-controls",o);let s=i.createElement("div");s.id=o,s.className="richclay-menu",s.hidden=!0,s.setAttribute("role","menu"),s.setAttribute("data-richclay-menu",""),ce(s),t.options.forEach((l,h)=>{let d=i.createElement("button");d.type="button",d.className="richclay-menu-item",d.setAttribute("role","menuitemradio"),d.setAttribute("tabindex","-1"),d.dataset.richclayMenuItem=t.id,d.dataset.richclayOptionIndex=String(h),d.innerHTML=l.icon||"",d.appendChild(i.createTextNode(l.label)),d.addEventListener("mousedown",Lt),d.addEventListener("click",u=>{u.preventDefault(),this.chooseMenuItem(t,l,r)}),d.addEventListener("keydown",u=>this.handleMenuKeydown(u,t,r)),s.appendChild(d)});let a=i.createElement("span");a.className="richclay-menu-wrap",a.append(r,s),this.root.appendChild(a),this.items.push({def:t,button:r,type:"menu",menu:s}),this.menus.set(t.id,{def:t,button:r,menu:s})}handleRootPointerDown(t){let n=t.target.closest?.("[data-richclay-control]");!n||!this.root.contains(n)||(Lt(t),this.editor.saveSelection())}handleRootClick(t){let n=t.target.closest?.("[data-richclay-control]");if(!n||!this.root.contains(n))return;t.preventDefault();let i=this.items.find(r=>r.button===n);if(!(!i||n.disabled)){if(this.activeIndex=this.items.indexOf(i),this.ensureSingleTabStop(),i.type==="menu"){this.toggleMenu(i.def.id);return}this.closeMenus(),this.editor.runControl(i.def)}}handleRootKeydown(t){let n=t.key,i={ArrowRight:1,ArrowDown:1,ArrowLeft:-1,ArrowUp:-1};if(n in i){t.preventDefault(),this.moveFocus(i[n]);return}if(n==="Home"){t.preventDefault(),this.setFocusIndex(0);return}if(n==="End"){t.preventDefault(),this.setFocusIndex(this.items.length-1);return}let r=this.items[this.activeIndex];if(r&&((n==="Enter"||n===" ")&&r.type==="menu"&&(t.preventDefault(),this.openMenu(r.def.id,"first")),n==="Escape")){let o=Array.from(this.menus.values()).some(s=>!s.menu.hidden);this.closeMenus(),o?r.button.focus():this.editor.focus()}}handleMenuKeydown(t,n,i){t.stopPropagation();let r=this.menus.get(n.id)?.menu,o=Array.from(r.querySelectorAll(".richclay-menu-item")),s=o.indexOf(t.currentTarget),a=s;if(t.key==="ArrowDown"&&(a=(s+1)%o.length),t.key==="ArrowUp"&&(a=(s-1+o.length)%o.length),t.key==="Home"&&(a=0),t.key==="End"&&(a=o.length-1),a!==s){t.preventDefault(),o[a].focus();return}if(t.key==="Escape"){t.preventDefault(),this.closeMenus(),i.focus();return}if(t.key==="Enter"||t.key===" "){t.preventDefault();let l=n.options[s];this.chooseMenuItem(n,l,i)}}handleDocumentPointerDown(t){this.root.contains(t.target)||this.closeMenus()}chooseMenuItem(t,n,i){this.closeMenus(),this.editor.runControl({...n,id:`${t.id}:${n.value}`,ariaLabel:n.label}),i.focus()}toggleMenu(t){let n=this.menus.get(t);n&&(n.menu.hidden?this.openMenu(t,"first"):this.closeMenus())}openMenu(t,n="first"){this.closeMenus(t);let i=this.menus.get(t);if(!i)return;i.menu.hidden=!1,i.button.setAttribute("aria-expanded","true"),this.updateMenuState(i);let r=Array.from(i.menu.querySelectorAll(".richclay-menu-item")),o=r.find(a=>a.getAttribute("aria-checked")==="true");(n==="active"&&o||r[0])?.focus()}closeMenus(t=null){this.menus.forEach((n,i)=>{i!==t&&(n.menu.hidden=!0,n.button.setAttribute("aria-expanded","false"))})}updateMenuState(t){Array.from(t.menu.querySelectorAll(".richclay-menu-item")).forEach((i,r)=>{let s=!!t.def.options[r].isActive?.(this.editor);i.setAttribute("aria-checked",s?"true":"false"),i.classList.toggle("is-active",s)})}moveFocus(t){if(!this.items.length)return;let n=this.activeIndex;do n=(n+t+this.items.length)%this.items.length;while(this.items[n].button.disabled&&n!==this.activeIndex);this.setFocusIndex(n)}setFocusIndex(t){this.activeIndex=Math.max(0,Math.min(t,this.items.length-1)),this.ensureSingleTabStop(),this.items[this.activeIndex]?.button.focus()}ensureSingleTabStop(){let t=this.items.filter(n=>!n.button.disabled);t.length&&(t.includes(this.items[this.activeIndex])||(this.activeIndex=this.items.indexOf(t[0])),this.items.forEach((n,i)=>{n.button.tabIndex=i===this.activeIndex?0:-1}))}};function fo(e,t){let n=e.createElement("button");n.type="button",n.className="richclay-button";let i=qr(t.shortcut,e.defaultView),r=i?`${t.ariaLabel||t.label} (${i})`:t.ariaLabel||t.label;return n.setAttribute("aria-label",r),n.title=r,n.innerHTML=`${t.icon||""}<span class="richclay-sr-only">${t.label}</span>`,n}function po(e){let t=e.createElement("span");return t.className="richclay-separator",t.setAttribute("role","separator"),t.setAttribute("aria-orientation","vertical"),t}function cl(e,t){return e?typeof e=="string"?t.querySelector(e):e:null}var mo=16,hl=[16,8,0],V=8,ul=4;function dl({anchor:e,bar:t,rail:n,viewport:i,current:r=null}){let o=p=>r===p?ul:0;if(e.bottom<=0||e.top>=i.height||e.right<=0||e.left>=i.width)return{mode:"hidden",x:0,y:0};let s=p=>Math.max(V,Math.min(e.left,i.width-p-V)),a=e.top-mo-t.height;if(a>=V-o("above"))return{mode:"above",x:s(t.width),y:a};let l=e.bottom+mo;if(l+t.height<=i.height-V+o("below"))return{mode:"below",x:s(t.width),y:l};let h=i.width-e.right-V,d=e.left-V,u=h>=d?[["rail-right",h],["rail-left",d]]:[["rail-left",d],["rail-right",h]];for(let[p,b]of u)for(let y of hl){if(n.width+y>b+o(p))continue;let E=p==="rail-right"?Math.min(e.right+y,i.width-n.width-V):Math.max(e.left-y-n.width,V),S=Math.min(e.bottom,i.height-V)-n.height,N=Math.max(V,Math.min(Math.max(e.top,V),S));return{mode:p,x:E,y:N,gap:y}}return{mode:"pinned",x:s(t.width),y:V}}var fl=10,pl=28;function on({anchor:e,box:t,viewport:n,gap:i=fl}){let r=n.height-V-e.bottom-i,o=e.top-i-V,s=r>=t.height||r>=o?"below":"above",a=s==="below"?e.bottom+i:e.top-i-t.height,l=Math.max(V,Math.min(a,n.height-V-t.height)),h=(e.left+e.right)/2,d=Math.max(V,Math.min(h-pl,n.width-V-t.width)),u=Math.max(14,Math.min(h-d,t.width-14));return{side:s,x:d,y:l,arrow:u}}function Q(e,t,n){e.style.setProperty(t,n,"important")}var rn=class{constructor(t,n){this.editor=t,this.mode=null,this.hidden=!1,this.frame=0,this.bar={width:0,height:0},this.rail={width:0,height:0};let i=t.element.ownerDocument;this.doc=i,this.win=i.defaultView||globalThis,this.root=i.createElement("div"),this.root.className="richclay-float",this.root.setAttribute("data-richclay-float",""),this.root.setAttribute("save-remove",""),ce(this.root),i.body.appendChild(this.root),this.toolbar=new st(t,n,{toolbarContainer:this.root}),this.onScroll=()=>this.schedule(),this.onResize=()=>{this.measure(),this.schedule()},i.addEventListener("scroll",this.onScroll,{capture:!0,passive:!0}),this.win.addEventListener("resize",this.onResize,{passive:!0}),this.win.visualViewport?.addEventListener("resize",this.onResize,{passive:!0}),this.win.visualViewport?.addEventListener("scroll",this.onScroll,{passive:!0}),this.resizeObserver=typeof this.win.ResizeObserver=="function"?new this.win.ResizeObserver(()=>this.schedule()):null,this.resizeObserver?.observe(t.element),this.measure(),this.reposition()}measure(){let t=this.root.classList.contains("richclay-float-rail");Q(this.root,"visibility","hidden"),this.root.classList.remove("richclay-float-rail"),this.bar={width:this.root.offsetWidth||0,height:this.root.offsetHeight||0},this.root.classList.add("richclay-float-rail"),this.rail={width:this.root.offsetWidth||0,height:this.root.offsetHeight||0},this.root.classList.toggle("richclay-float-rail",t),this.root.style.removeProperty("visibility")}schedule(){if(!this.win.requestAnimationFrame){this.reposition();return}this.frame||(this.frame=this.win.requestAnimationFrame(()=>{this.frame=0,this.reposition()}))}setVisible(t){this.hidden=!t,this.reposition()}reposition(){if(this.hidden){Q(this.root,"display","none");return}let t=this.editor.element.getBoundingClientRect(),n={width:this.win.visualViewport?.width??this.win.innerWidth,height:this.win.visualViewport?.height??this.win.innerHeight},i=dl({anchor:t,bar:this.bar,rail:this.rail,viewport:n,current:this.mode});if(this.mode=i.mode,i.mode==="hidden"){Q(this.root,"display","none");return}this.root.style.removeProperty("display"),this.root.classList.toggle("richclay-float-rail",i.mode==="rail-left"||i.mode==="rail-right"),this.root.classList.toggle("richclay-float-pinned",i.mode==="pinned"),Q(this.root,"transform",`translate(${Math.round(i.x)}px, ${Math.round(i.y)}px)`)}destroy(){this.frame&&this.win.cancelAnimationFrame?.(this.frame),this.frame=0,this.doc.removeEventListener("scroll",this.onScroll,{capture:!0}),this.win.removeEventListener("resize",this.onResize),this.win.visualViewport?.removeEventListener("resize",this.onResize),this.win.visualViewport?.removeEventListener("scroll",this.onScroll),this.resizeObserver?.disconnect(),this.toolbar.destroy(),this.root.remove()}};var ml={ALLOWED_TAGS:["a","b","blockquote","br","code","div","em","h1","h2","h3","h4","h5","h6","i","li","ol","p","pre","s","span","strong","sub","sup","u","ul"],ALLOWED_ATTR:["aria-label","href","rel","target","title"],ALLOW_DATA_ATTR:!1,ALLOW_ARIA_ATTR:!0,ALLOWED_URI_REGEXP:/^(?:(?:(?:f|ht)tps?|mailto|tel):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i,FORBID_TAGS:["script","style","iframe","object","embed","form","input"],FORBID_ATTR:["style","srcset","onerror","onclick","onload"]};function bo(e={},t=document){let n=sn(t);return{sanitizeHTML(i){return ui(i,e,t,n)},sanitizeElement(i){return di(i,e,n)},sanitizeToDOMFragment(i,r){let o=r?.getRoot?.().ownerDocument||t;return gl(i,e,o,n)}}}function ui(e,t={},n=document,i=sn(n)){let r=n.createElement("template");return r.innerHTML=i.sanitize(String(e||""),fi(t)),mi(r.content),r.innerHTML}function di(e,t={},n=sn(e.ownerDocument)){let r=e.ownerDocument.createElement("div");for(;e.firstChild;)r.appendChild(e.firstChild);for(n.sanitize(r,{...fi(t),IN_PLACE:!0}),mi(r);r.firstChild;)e.appendChild(r.firstChild);return e}function gl(e,t={},n=document,i=sn(n)){let r=i.sanitize(String(e||""),{...fi(t),RETURN_DOM_FRAGMENT:!0}),o=r?.ownerDocument===n?r:n.importNode(r,!0);return mi(o),o||n.createDocumentFragment()}function fi(e){return{...ml,...e}}var yl=new Set(["http","https","mailto","tel"]),bl=new RegExp("[\\u0000-\\u0020\\u007F-\\u009F]","g");function pi(e){let n=(String(e??"").replace(bl,"").match(/^([a-z][a-z0-9+.\-]*):/i)||[])[1];return!n||yl.has(n.toLowerCase())}var Tl=/^[^\s/?#:]+\.(?:html?|pdf|txt|csv|json|xml|svg|png|jpe?g|gif|webp|docx?|xlsx?|pptx?|bib|tex|zip)(?:[?#]\S*)?$/i,_l=/^[^\s/?#:.]+\/\S*$/;function To(e){let t=String(e??"").trim();return!t||!pi(t)?"":/^(?:https?:|mailto:|tel:)/i.test(t)?t:/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)?`mailto:${t}`:/^(?:[#?]|\/|\.{1,2}\/)/.test(t)||Tl.test(t)||_l.test(t)?t:`https://${t}`}function sn(e){let t=globalThis.DOMPurify;if(t?.sanitize)return t;if(typeof t=="function")return t(e.defaultView||globalThis);throw new Error("RichClay requires DOMPurify. Load vendor/purify.min.js before richclay.js or provide globalThis.DOMPurify.")}function mi(e){e.querySelectorAll?.("a[href]").forEach(t=>{let n=t.getAttribute("href")||"";if(/^\s*javascript:/i.test(n)&&t.removeAttribute("href"),t.getAttribute("target")==="_blank"){let i=new Set((t.getAttribute("rel")||"").split(/\s+/).filter(Boolean));i.add("noopener"),i.add("noreferrer"),t.setAttribute("rel",Array.from(i).join(" "))}})}var go={ADD_TAGS:["img"],ADD_ATTR:["class","id","src","alt","width","height"]};function _o(e={}){return{...e,ADD_TAGS:[...new Set([...go.ADD_TAGS,...e.ADD_TAGS||[]])],ADD_ATTR:[...new Set([...go.ADD_ATTR,...e.ADD_ATTR||[]])],ALLOW_DATA_ATTR:e.ALLOW_DATA_ATTR??!0}}var yo="p, div, h1, h2, h3, h4, h5, h6, blockquote, pre, ul, ol, li, figure, figcaption, table, thead, tbody, tr, td, th";function Eo(e){let t=e.ownerDocument||document;e.querySelectorAll?.("br").forEach(i=>i.replaceWith(t.createTextNode(" ")));let n=e.querySelector?.(yo);for(;n;){let i=n.parentNode;for(i.insertBefore(t.createTextNode(" "),n);n.firstChild;)i.insertBefore(n.firstChild,n);i.insertBefore(t.createTextNode(" "),n),n.remove(),n=e.querySelector(yo)}return El(e,t),e}function El(e,t){e.normalize?.();let n=t.createTreeWalker(e,4),i=[];for(;n.nextNode();)i.push(n.currentNode);i.forEach(s=>{s.nodeValue=s.nodeValue.replace(/\s+/g," ")});let r=e.firstChild;r?.nodeType===3&&(r.nodeValue=r.nodeValue.replace(/^\s+/,""));let o=e.lastChild;o?.nodeType===3&&(o.nodeValue=o.nodeValue.replace(/\s+$/,""))}var vl=300,Sl=e=>e.replace(/^mailto:/i,"").replace(/^https?:\/\//i,""),an=class{constructor(t){this.editor=t,this.root=null,this.anchor=null,this.href=null,this.dismissed=null,this.hideTimer=null,this.pointerInside=!1,this.cleanup=null}currentAnchor(){let t=this.editor;if(!t.active||t.options.readOnly||t.dialog)return null;let n=t.element.ownerDocument;if(n.hidden)return null;let i=n.getSelection?.();return!i||!i.rangeCount||!t.element.contains(i.anchorNode)?null:t.currentLinkElement()}update(){let t=this.currentAnchor();if(!(t&&t===this.dismissed)){if(this.dismissed=null,!t){this.scheduleHide();return}this.cancelHide(),this.show(t)}}show(t){this.root||this.mount();let n=t.getAttribute("href")||"";if(t!==this.anchor||n!==this.href){this.anchor=t,this.href=n;let i=this.root.querySelector(".richclay-link-address");i.textContent=Sl(n)||n,i.title=n,n&&pi(n)?i.setAttribute("href",n):i.removeAttribute("href"),/^(?:mailto|tel):/i.test(n)?i.removeAttribute("target"):i.setAttribute("target","_blank")}this.position()}mount(){let t=this.editor,n=t.element.ownerDocument,i=n.defaultView||globalThis,r=n.createElement("div");r.className="richclay-dialog richclay-link-popover",r.setAttribute("role","group"),r.setAttribute("aria-label","Link"),r.setAttribute("data-richclay-link-popover",""),ce(r),r.setAttribute("save-remove",""),r.innerHTML=`
21
+ `)),i.appendChild(D(o))}let s=new re(i,4);for(;o=s.nextNode();)o.data=o.data.replace(/ /g," ");return i.normalize(),K(_("PRE",this._config.tagAttributes.pre,[i]))},e),this.focus()):this.changeFormat({tag:"CODE",attributes:this._config.tagAttributes.code},null,e),this}removeCode(){let e=this.getSelection(),t=e.commonAncestorContainer;return w(t,this._root,"PRE")?(this.modifyBlocks(n=>{let i=this._root,r=n.querySelectorAll("PRE"),o=r.length;for(;o--;){let s=r[o],a=new re(s,4),l;for(;l=a.nextNode();){let h=l.data;h=h.replace(/ (?= )/g,"\xA0");let d=document.createDocumentFragment(),u;for(;(u=h.indexOf(`
22
+ `))>-1;)d.appendChild(document.createTextNode(h.slice(0,u))),d.appendChild(_("BR")),h=h.slice(u+1);l.parentNode.insertBefore(d,l),l.data=h}ge(s,i),Y(s,D(s))}return n},e),this.focus()):this.changeFormat(null,{tag:"CODE"},e),this}toggleCode(){return this.hasFormat("PRE")||this.hasFormat("CODE")?this.removeCode():this.code(),this}_removeFormatting(e,t){for(let n=e.firstChild,i;n;n=i){if(i=n.nextSibling,L(n)){if(n instanceof Text||n.nodeName==="BR"||n.nodeName==="IMG"){t.appendChild(n);continue}}else if(xe(n)){t.appendChild(this.createDefaultBlock([this._removeFormatting(n,document.createDocumentFragment())]));continue}this._removeFormatting(n,t)}return t}removeAllFormatting(e){if(e||(e=this.getSelection()),e.collapsed)return this.focus();let t=this._root,n=e.commonAncestorContainer;for(;n&&n!==t&&!xe(n);)n=n.parentNode;if(n||(rr(e,t),n=t),n instanceof Text)return this.focus();this.saveUndoState(e),He(e,n,n,t);let i=e.startContainer,r=e.startOffset,o=e.endContainer,s=e.endOffset,a=document.createDocumentFragment(),l=document.createDocumentFragment(),h=le(o,s,n,t),d=le(i,r,n,t),u;for(;d!==h;)u=d.nextSibling,a.appendChild(d),d=u;if(this._removeFormatting(a,l),l.normalize(),d=l.firstChild,u=l.lastChild,d){n.insertBefore(l,h);let p=Array.from(n.childNodes);r=p.indexOf(d),s=u?p.indexOf(u)+1:0}else h&&(r=Array.from(n.childNodes).indexOf(h),s=r);return e.setStart(n,r),e.setEnd(n,s),Qe(n,e),X(e),this.setSelection(e),this._updatePath(e,!0),this.focus()}},Ar=Js;function Cr(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,i=Array(t);n<t;n++)i[n]=e[n];return i}function ea(e){if(Array.isArray(e))return e}function ta(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var i,r,o,s,a=[],l=!0,h=!1;try{if(o=(n=n.call(e)).next,t!==0)for(;!(l=(i=o.call(n)).done)&&(a.push(i.value),a.length!==t);l=!0);}catch(d){h=!0,r=d}finally{try{if(!l&&n.return!=null&&(s=n.return(),Object(s)!==s))return}finally{if(h)throw r}}return a}}function na(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
23
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ia(e,t){return ea(e)||ta(e,t)||ra(e,t)||na()}function ra(e,t){if(e){if(typeof e=="string")return Cr(e,t);var n={}.toString.call(e).slice(8,-1);return n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set"?Array.from(e):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Cr(e,t):void 0}}var Fr=Object.entries,Lr=Object.setPrototypeOf,oa=Object.isFrozen,sa=Object.getPrototypeOf,aa=Object.getOwnPropertyDescriptor,j=Object.freeze,Z=Object.seal,nt=Object.create,Ur=typeof Reflect<"u"&&Reflect,Xn=Ur.apply,Qn=Ur.construct;j||(j=function(t){return t});Z||(Z=function(t){return t});Xn||(Xn=function(t,n){for(var i=arguments.length,r=new Array(i>2?i-2:0),o=2;o<i;o++)r[o-2]=arguments[o];return t.apply(n,r)});Qn||(Qn=function(t){for(var n=arguments.length,i=new Array(n>1?n-1:0),r=1;r<n;r++)i[r-1]=arguments[r];return new t(...i)});var yt=F(Array.prototype.forEach),la=F(Array.prototype.lastIndexOf),wr=F(Array.prototype.pop),tt=F(Array.prototype.push),ca=F(Array.prototype.splice),Oe=Array.isArray,_t=F(String.prototype.toLowerCase),Vn=F(String.prototype.toString),Nr=F(String.prototype.match),bt=F(String.prototype.replace),xr=F(String.prototype.indexOf),ha=F(String.prototype.trim),ua=F(Number.prototype.toString),da=F(Boolean.prototype.toString),kr=typeof BigInt>"u"?null:F(BigInt.prototype.toString),Rr=typeof Symbol>"u"?null:F(Symbol.prototype.toString),$=F(Object.prototype.hasOwnProperty),Tt=F(Object.prototype.toString),G=F(RegExp.prototype.test),We=fa(TypeError);function F(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);for(var n=arguments.length,i=new Array(n>1?n-1:0),r=1;r<n;r++)i[r-1]=arguments[r];return Xn(e,t,i)}}function fa(e){return function(){for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];return Qn(e,n)}}function A(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:_t;if(Lr&&Lr(e,null),!Oe(t))return e;let i=t.length;for(;i--;){let r=t[i];if(typeof r=="string"){let o=n(r);o!==r&&(oa(t)||(t[i]=o),r=o)}e[r]=!0}return e}function pa(e){for(let t=0;t<e.length;t++)$(e,t)||(e[t]=null);return e}function ne(e){let t=nt(null);for(let i of Fr(e)){var n=ia(i,2);let r=n[0],o=n[1];$(e,r)&&(Oe(o)?t[r]=pa(o):o&&typeof o=="object"&&o.constructor===Object?t[r]=ne(o):t[r]=o)}return t}function ma(e){switch(typeof e){case"string":return e;case"number":return ua(e);case"boolean":return da(e);case"bigint":return kr?kr(e):"0";case"symbol":return Rr?Rr(e):"Symbol()";case"undefined":return Tt(e);case"function":case"object":{if(e===null)return Tt(e);let t=e,n=be(t,"toString");if(typeof n=="function"){let i=n(t);return typeof i=="string"?i:Tt(i)}return Tt(e)}default:return Tt(e)}}function be(e,t){for(;e!==null;){let i=aa(e,t);if(i){if(i.get)return F(i.get);if(typeof i.value=="function")return F(i.value)}e=sa(e)}function n(){return null}return n}function ga(e){try{return G(e,""),!0}catch{return!1}}var Or=j(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),Gn=j(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),jn=j(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),ya=j(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),Zn=j(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),ba=j(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),Dr=j(["#text"]),Mr=j(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","command","commandfor","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns"]),Yn=j(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),Ir=j(["accent","accentunder","align","bevelled","close","columnalign","columnlines","columnspacing","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lquote","lspace","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),$t=j(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),Ta=Z(/{{[\w\W]*|^[\w\W]*}}/g),_a=Z(/<%[\w\W]*|^[\w\W]*%>/g),Ea=Z(/\${[\w\W]*/g),va=Z(/^data-[\-\w.\u00B7-\uFFFF]+$/),Sa=Z(/^aria-[\-\w]+$/),Pr=Z(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Aa=Z(/^(?:\w+script|data):/i),Ca=Z(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),La=Z(/^html$/i),wa=Z(/^[a-z][.\w]*(-[.\w]+)+$/i),Br=Z(/<[/\w!]/g),Na=Z(/<[/\w]/g),xa=Z(/<\/no(script|embed|frames)/i),ka=Z(/\/>/i),ye={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},Ra=function(){return typeof window>"u"?null:window},Oa=function(t,n){if(typeof t!="object"||typeof t.createPolicy!="function")return null;let i=null,r="data-tt-policy-suffix";n&&n.hasAttribute(r)&&(i=n.getAttribute(r));let o="dompurify"+(i?"#"+i:"");try{return t.createPolicy(o,{createHTML(s){return s},createScriptURL(s){return s}})}catch{return console.warn("TrustedTypes policy "+o+" could not be created."),null}},Hr=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},Re=function(t,n,i,r){return $(t,n)&&Oe(t[n])?A(r.base?ne(r.base):{},t[n],r.transform):i};function zr(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Ra(),t=g=>zr(g);if(t.version="3.4.11",t.removed=[],!e||!e.document||e.document.nodeType!==ye.document||!e.Element)return t.isSupported=!1,t;let n=e.document,i=n,r=i.currentScript;e.DocumentFragment;let o=e.HTMLTemplateElement,s=e.Node,a=e.Element,l=e.NodeFilter,h=e.NamedNodeMap;h===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let d=e.DOMParser,u=e.trustedTypes,p=a.prototype,b=be(p,"cloneNode"),y=be(p,"remove"),E=be(p,"nextSibling"),S=be(p,"childNodes"),N=be(p,"parentNode"),P=be(p,"shadowRoot"),J=be(p,"attributes"),U=s&&s.prototype?be(s.prototype,"nodeType"):null,ue=s&&s.prototype?be(s.prototype,"nodeName"):null;if(typeof o=="function"){let g=n.createElement("template");g.content&&g.content.ownerDocument&&(n=g.content.ownerDocument)}let ie,Me="",pn,Li=!1,lt=0,wi=function(){if(lt>0)throw We('A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.')},Ve=function(c){wi(),lt++;try{return ie.createHTML(c)}finally{lt--}},Ho=function(c){wi(),lt++;try{return ie.createScriptURL(c)}finally{lt--}},Fo=function(){return Li||(pn=Oa(u,r),Li=!0),pn},kt=n,mn=kt.implementation,Ni=kt.createNodeIterator,Uo=kt.createDocumentFragment,zo=kt.getElementsByTagName,qo=i.importNode,I=Hr();t.isSupported=typeof Fr=="function"&&typeof N=="function"&&mn&&mn.createHTMLDocument!==void 0;let Wo=Ta,Ko=_a,$o=Ea,Vo=va,Go=Sa,jo=Aa,xi=Ca,Zo=wa,ki=Pr,x=null,Ri=A({},[...Or,...Gn,...jn,...Zn,...Dr]),k=null,Oi=A({},[...Mr,...Yn,...Ir,...$t]),R=Object.seal(nt(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),ct=null,Di=null,Ce=Object.seal(nt(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),Mi=!0,gn=!0,Ii=!1,Pi=!0,Le=!1,ht=!0,Ie=!1,yn=!1,bn=null,Tn=null,_n=!1,Ge=!1,Rt=!1,Ot=!1,Bi=!0,Hi=!1,Fi="user-content-",En=!0,vn=!1,je={},fe=null,Sn=A({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","selectedcontent","style","svg","template","thead","title","video","xmp"]),Ui=null,zi=A({},["audio","video","img","source","image","track"]),An=null,qi=A({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Dt="http://www.w3.org/1998/Math/MathML",Mt="http://www.w3.org/2000/svg",pe="http://www.w3.org/1999/xhtml",Ze=pe,Cn=!1,Ln=null,Yo=A({},[Dt,Mt,pe],Vn),Wi=j(["mi","mo","mn","ms","mtext"]),wn=A({},Wi),Ki=j(["annotation-xml"]),Nn=A({},Ki),Xo=A({},["title","style","font","a","script"]),ut=null,Qo=["application/xhtml+xml","text/html"],Jo="text/html",O=null,Ye=null,es=n.createElement("form"),$i=function(c){return c instanceof RegExp||c instanceof Function},xn=function(){let c=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(Ye&&Ye===c)return;(!c||typeof c!="object")&&(c={}),c=ne(c),ut=Qo.indexOf(c.PARSER_MEDIA_TYPE)===-1?Jo:c.PARSER_MEDIA_TYPE,O=ut==="application/xhtml+xml"?Vn:_t,x=Re(c,"ALLOWED_TAGS",Ri,{transform:O}),k=Re(c,"ALLOWED_ATTR",Oi,{transform:O}),Ln=Re(c,"ALLOWED_NAMESPACES",Yo,{transform:Vn}),An=Re(c,"ADD_URI_SAFE_ATTR",qi,{transform:O,base:qi}),Ui=Re(c,"ADD_DATA_URI_TAGS",zi,{transform:O,base:zi}),fe=Re(c,"FORBID_CONTENTS",Sn,{transform:O}),ct=Re(c,"FORBID_TAGS",ne({}),{transform:O}),Di=Re(c,"FORBID_ATTR",ne({}),{transform:O}),je=$(c,"USE_PROFILES")?c.USE_PROFILES&&typeof c.USE_PROFILES=="object"?ne(c.USE_PROFILES):c.USE_PROFILES:!1,Mi=c.ALLOW_ARIA_ATTR!==!1,gn=c.ALLOW_DATA_ATTR!==!1,Ii=c.ALLOW_UNKNOWN_PROTOCOLS||!1,Pi=c.ALLOW_SELF_CLOSE_IN_ATTR!==!1,Le=c.SAFE_FOR_TEMPLATES||!1,ht=c.SAFE_FOR_XML!==!1,Ie=c.WHOLE_DOCUMENT||!1,Ge=c.RETURN_DOM||!1,Rt=c.RETURN_DOM_FRAGMENT||!1,Ot=c.RETURN_TRUSTED_TYPE||!1,_n=c.FORCE_BODY||!1,Bi=c.SANITIZE_DOM!==!1,Hi=c.SANITIZE_NAMED_PROPS||!1,En=c.KEEP_CONTENT!==!1,vn=c.IN_PLACE||!1,ki=ga(c.ALLOWED_URI_REGEXP)?c.ALLOWED_URI_REGEXP:Pr,Ze=typeof c.NAMESPACE=="string"?c.NAMESPACE:pe,wn=$(c,"MATHML_TEXT_INTEGRATION_POINTS")&&c.MATHML_TEXT_INTEGRATION_POINTS&&typeof c.MATHML_TEXT_INTEGRATION_POINTS=="object"?ne(c.MATHML_TEXT_INTEGRATION_POINTS):A({},Wi),Nn=$(c,"HTML_INTEGRATION_POINTS")&&c.HTML_INTEGRATION_POINTS&&typeof c.HTML_INTEGRATION_POINTS=="object"?ne(c.HTML_INTEGRATION_POINTS):A({},Ki);let f=$(c,"CUSTOM_ELEMENT_HANDLING")&&c.CUSTOM_ELEMENT_HANDLING&&typeof c.CUSTOM_ELEMENT_HANDLING=="object"?ne(c.CUSTOM_ELEMENT_HANDLING):nt(null);if(R=nt(null),$(f,"tagNameCheck")&&$i(f.tagNameCheck)&&(R.tagNameCheck=f.tagNameCheck),$(f,"attributeNameCheck")&&$i(f.attributeNameCheck)&&(R.attributeNameCheck=f.attributeNameCheck),$(f,"allowCustomizedBuiltInElements")&&typeof f.allowCustomizedBuiltInElements=="boolean"&&(R.allowCustomizedBuiltInElements=f.allowCustomizedBuiltInElements),Z(R),Le&&(gn=!1),Rt&&(Ge=!0),je&&(x=A({},Dr),k=nt(null),je.html===!0&&(A(x,Or),A(k,Mr)),je.svg===!0&&(A(x,Gn),A(k,Yn),A(k,$t)),je.svgFilters===!0&&(A(x,jn),A(k,Yn),A(k,$t)),je.mathMl===!0&&(A(x,Zn),A(k,Ir),A(k,$t))),Ce.tagCheck=null,Ce.attributeCheck=null,$(c,"ADD_TAGS")&&(typeof c.ADD_TAGS=="function"?Ce.tagCheck=c.ADD_TAGS:Oe(c.ADD_TAGS)&&(x===Ri&&(x=ne(x)),A(x,c.ADD_TAGS,O))),$(c,"ADD_ATTR")&&(typeof c.ADD_ATTR=="function"?Ce.attributeCheck=c.ADD_ATTR:Oe(c.ADD_ATTR)&&(k===Oi&&(k=ne(k)),A(k,c.ADD_ATTR,O))),$(c,"ADD_URI_SAFE_ATTR")&&Oe(c.ADD_URI_SAFE_ATTR)&&A(An,c.ADD_URI_SAFE_ATTR,O),$(c,"FORBID_CONTENTS")&&Oe(c.FORBID_CONTENTS)&&(fe===Sn&&(fe=ne(fe)),A(fe,c.FORBID_CONTENTS,O)),$(c,"ADD_FORBID_CONTENTS")&&Oe(c.ADD_FORBID_CONTENTS)&&(fe===Sn&&(fe=ne(fe)),A(fe,c.ADD_FORBID_CONTENTS,O)),En&&(x["#text"]=!0),Ie&&A(x,["html","head","body"]),x.table&&(A(x,["tbody"]),delete ct.tbody),c.TRUSTED_TYPES_POLICY){if(typeof c.TRUSTED_TYPES_POLICY.createHTML!="function")throw We('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof c.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw We('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');let m=ie;ie=c.TRUSTED_TYPES_POLICY;try{Me=Ve("")}catch(T){throw ie=m,T}}else c.TRUSTED_TYPES_POLICY===null?(ie=void 0,Me=""):(ie===void 0&&(ie=Fo()),ie&&typeof Me=="string"&&(Me=Ve("")));j&&j(c),Ye=c},Vi=A({},[...Gn,...jn,...ya]),Gi=A({},[...Zn,...ba]),ts=function(c,f,m){return f.namespaceURI===pe?c==="svg":f.namespaceURI===Dt?c==="svg"&&(m==="annotation-xml"||wn[m]):!!Vi[c]},ns=function(c,f,m){return f.namespaceURI===pe?c==="math":f.namespaceURI===Mt?c==="math"&&Nn[m]:!!Gi[c]},is=function(c,f,m){return f.namespaceURI===Mt&&!Nn[m]||f.namespaceURI===Dt&&!wn[m]?!1:!Gi[c]&&(Xo[c]||!Vi[c])},rs=function(c){let f=N(c);(!f||!f.tagName)&&(f={namespaceURI:Ze,tagName:"template"});let m=_t(c.tagName),T=_t(f.tagName);return Ln[c.namespaceURI]?c.namespaceURI===Mt?ts(m,f,T):c.namespaceURI===Dt?ns(m,f,T):c.namespaceURI===pe?is(m,f,T):!!(ut==="application/xhtml+xml"&&Ln[c.namespaceURI]):!1},we=function(c){tt(t.removed,{element:c});try{N(c).removeChild(c)}catch{if(y(c),!N(c))throw We("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},ji=function(c){let f=S(c);if(f){let T=[];yt(f,v=>{tt(T,v)}),yt(T,v=>{try{y(v)}catch{}})}let m=J(c);if(m)for(let T=m.length-1;T>=0;--T){let v=m[T],C=v&&v.name;if(typeof C=="string")try{c.removeAttribute(C)}catch{}}},Pe=function(c,f){try{tt(t.removed,{attribute:f.getAttributeNode(c),from:f})}catch{tt(t.removed,{attribute:null,from:f})}if(f.removeAttribute(c),c==="is")if(Ge||Rt)try{we(f)}catch{}else try{f.setAttribute(c,"")}catch{}},os=function(c){let f=J(c);if(f)for(let m=f.length-1;m>=0;--m){let T=f[m],v=T&&T.name;if(!(typeof v!="string"||k[O(v)]))try{c.removeAttribute(v)}catch{}}},ss=function(c){let f=[c];for(;f.length>0;){let m=f.pop();(U?U(m):m.nodeType)===ye.element&&os(m);let v=S(m);if(v)for(let C=v.length-1;C>=0;--C)f.push(v[C])}},Zi=function(c){let f=null,m=null;if(_n)c="<remove></remove>"+c;else{let C=Nr(c,/^[\r\n\t ]+/);m=C&&C[0]}ut==="application/xhtml+xml"&&Ze===pe&&(c='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+c+"</body></html>");let T=ie?Ve(c):c;if(Ze===pe)try{f=new d().parseFromString(T,ut)}catch{}if(!f||!f.documentElement){f=mn.createDocument(Ze,"template",null);try{f.documentElement.innerHTML=Cn?Me:T}catch{}}let v=f.body||f.documentElement;return c&&m&&v.insertBefore(n.createTextNode(m),v.childNodes[0]||null),Ze===pe?zo.call(f,Ie?"html":"body")[0]:Ie?f.documentElement:v},Yi=function(c){return Ni.call(c.ownerDocument||c,c,l.SHOW_ELEMENT|l.SHOW_COMMENT|l.SHOW_TEXT|l.SHOW_PROCESSING_INSTRUCTION|l.SHOW_CDATA_SECTION,null)},It=function(c){return c=bt(c,Wo," "),c=bt(c,Ko," "),c=bt(c,$o," "),c},kn=function(c){var f;c.normalize();let m=Ni.call(c.ownerDocument||c,c,l.SHOW_TEXT|l.SHOW_COMMENT|l.SHOW_CDATA_SECTION|l.SHOW_PROCESSING_INSTRUCTION,null),T=m.nextNode();for(;T;)T.data=It(T.data),T=m.nextNode();let v=(f=c.querySelectorAll)===null||f===void 0?void 0:f.call(c,"template");v&&yt(v,C=>{Xe(C.content)&&kn(C.content)})},Pt=function(c){let f=ue?ue(c):null;return typeof f!="string"||O(f)!=="form"?!1:typeof c.nodeName!="string"||typeof c.textContent!="string"||typeof c.removeChild!="function"||c.attributes!==J(c)||typeof c.removeAttribute!="function"||typeof c.setAttribute!="function"||typeof c.namespaceURI!="string"||typeof c.insertBefore!="function"||typeof c.hasChildNodes!="function"||c.nodeType!==U(c)||c.childNodes!==S(c)},Xe=function(c){if(!U||typeof c!="object"||c===null)return!1;try{return U(c)===ye.documentFragment}catch{return!1}},dt=function(c){if(!U||typeof c!="object"||c===null)return!1;try{return typeof U(c)=="number"}catch{return!1}};function _e(g,c,f){g.length!==0&&yt(g,m=>{m.call(t,c,f,Ye)})}let as=function(c,f){return!!(ht&&c.hasChildNodes()&&!dt(c.firstElementChild)&&G(Br,c.textContent)&&G(Br,c.innerHTML)||ht&&c.namespaceURI===pe&&f==="style"&&dt(c.firstElementChild)||c.nodeType===ye.processingInstruction||ht&&c.nodeType===ye.comment&&G(Na,c.data))},ls=function(c,f){if(!ct[f]&&Ji(f)&&(R.tagNameCheck instanceof RegExp&&G(R.tagNameCheck,f)||R.tagNameCheck instanceof Function&&R.tagNameCheck(f)))return!1;if(En&&!fe[f]){let m=N(c),T=S(c);if(T&&m){let v=T.length;for(let C=v-1;C>=0;--C){let q=vn?T[C]:b(T[C],!0);m.insertBefore(q,E(c))}}}return we(c),!0},Xi=function(c){if(_e(I.beforeSanitizeElements,c,null),Pt(c))return we(c),!0;let f=O(ue?ue(c):c.nodeName);if(_e(I.uponSanitizeElement,c,{tagName:f,allowedTags:x}),as(c,f))return we(c),!0;if(ct[f]||!(Ce.tagCheck instanceof Function&&Ce.tagCheck(f))&&!x[f])return ls(c,f);if((U?U(c):c.nodeType)===ye.element&&!rs(c)||(f==="noscript"||f==="noembed"||f==="noframes")&&G(xa,c.innerHTML))return we(c),!0;if(Le&&c.nodeType===ye.text){let T=It(c.textContent);c.textContent!==T&&(tt(t.removed,{element:c.cloneNode()}),c.textContent=T)}return _e(I.afterSanitizeElements,c,null),!1},Qi=function(c,f,m){if(Di[f]||Bi&&(f==="id"||f==="name")&&(m in n||m in es))return!1;let T=k[f]||Ce.attributeCheck instanceof Function&&Ce.attributeCheck(f,c);if(!(gn&&G(Vo,f))){if(!(Mi&&G(Go,f))){if(T){if(!An[f]){if(!G(ki,bt(m,xi,""))){if(!((f==="src"||f==="xlink:href"||f==="href")&&c!=="script"&&xr(m,"data:")===0&&Ui[c])){if(!(Ii&&!G(jo,bt(m,xi,"")))){if(m)return!1}}}}}else if(!(Ji(c)&&(R.tagNameCheck instanceof RegExp&&G(R.tagNameCheck,c)||R.tagNameCheck instanceof Function&&R.tagNameCheck(c))&&(R.attributeNameCheck instanceof RegExp&&G(R.attributeNameCheck,f)||R.attributeNameCheck instanceof Function&&R.attributeNameCheck(f,c))||f==="is"&&R.allowCustomizedBuiltInElements&&(R.tagNameCheck instanceof RegExp&&G(R.tagNameCheck,m)||R.tagNameCheck instanceof Function&&R.tagNameCheck(m))))return!1}}return!0},cs=A({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),Ji=function(c){return!cs[_t(c)]&&G(Zo,c)},hs=function(c,f,m,T){if(ie&&typeof u=="object"&&typeof u.getAttributeType=="function"&&!m)switch(u.getAttributeType(c,f)){case"TrustedHTML":return Ve(T);case"TrustedScriptURL":return Ho(T)}return T},us=function(c,f,m,T){try{m?c.setAttributeNS(m,f,T):c.setAttribute(f,T),Pt(c)?we(c):wr(t.removed)}catch{Pe(f,c)}},er=function(c){_e(I.beforeSanitizeAttributes,c,null);let f=c.attributes;if(!f||Pt(c))return;let m={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:k,forceKeepAttr:void 0},T=f.length,v=O(c.nodeName);for(;T--;){let C=f[T],q=C.name,B=C.namespaceURI,ae=C.value,de=O(q),On=ae,ee=q==="value"?On:ha(On);if(m.attrName=de,m.attrValue=ee,m.keepAttr=!0,m.forceKeepAttr=void 0,_e(I.uponSanitizeAttribute,c,m),ee=m.attrValue,Hi&&(de==="id"||de==="name")&&xr(ee,Fi)!==0&&(Pe(q,c),ee=Fi+ee),ht&&G(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,ee)){Pe(q,c);continue}if(de==="attributename"&&Nr(ee,"href")){Pe(q,c);continue}if(!m.forceKeepAttr){if(!m.keepAttr){Pe(q,c);continue}if(!Pi&&G(ka,ee)){Pe(q,c);continue}if(Le&&(ee=It(ee)),!Qi(v,de,ee)){Pe(q,c);continue}ee=hs(v,de,B,ee),ee!==On&&us(c,q,B,ee)}}_e(I.afterSanitizeAttributes,c,null)},Bt=function(c){let f=null,m=Yi(c);for(_e(I.beforeSanitizeShadowDOM,c,null);f=m.nextNode();)if(_e(I.uponSanitizeShadowNode,f,null),Xi(f),er(f),Xe(f.content)&&Bt(f.content),(U?U(f):f.nodeType)===ye.element){let v=P(f);Xe(v)&&(Rn(v),Bt(v))}_e(I.afterSanitizeShadowDOM,c,null)},Rn=function(c){let f=[{node:c,shadow:null}];for(;f.length>0;){let m=f.pop();if(m.shadow){Bt(m.shadow);continue}let T=m.node,C=(U?U(T):T.nodeType)===ye.element,q=S(T);if(q)for(let B=q.length-1;B>=0;--B)f.push({node:q[B],shadow:null});if(C){let B=ue?ue(T):null;if(typeof B=="string"&&O(B)==="template"){let ae=T.content;Xe(ae)&&f.push({node:ae,shadow:null})}}if(C){let B=P(T);Xe(B)&&f.push({node:null,shadow:B},{node:B,shadow:null})}}};return t.sanitize=function(g){let c=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},f=null,m=null,T=null,v=null;if(Cn=!g,Cn&&(g="<!-->"),typeof g!="string"&&!dt(g)&&(g=ma(g),typeof g!="string"))throw We("dirty is not a string, aborting");if(!t.isSupported)return g;yn?(x=bn,k=Tn):xn(c),(I.uponSanitizeElement.length>0||I.uponSanitizeAttribute.length>0)&&(x=ne(x)),I.uponSanitizeAttribute.length>0&&(k=ne(k)),t.removed=[];let C=vn&&typeof g!="string"&&dt(g);if(C){let ae=ue?ue(g):g.nodeName;if(typeof ae=="string"){let de=O(ae);if(!x[de]||ct[de])throw We("root node is forbidden and cannot be sanitized in-place")}if(Pt(g))throw We("root node is clobbered and cannot be sanitized in-place");try{Rn(g)}catch(de){throw ji(g),de}}else if(dt(g))f=Zi("<!---->"),m=f.ownerDocument.importNode(g,!0),m.nodeType===ye.element&&m.nodeName==="BODY"||m.nodeName==="HTML"?f=m:f.appendChild(m),Rn(m);else{if(!Ge&&!Le&&!Ie&&g.indexOf("<")===-1)return ie&&Ot?Ve(g):g;if(f=Zi(g),!f)return Ge?null:Ot?Me:""}f&&_n&&we(f.firstChild);let q=Yi(C?g:f);try{for(;T=q.nextNode();)Xi(T),er(T),Xe(T.content)&&Bt(T.content)}catch(ae){throw C&&ji(g),ae}if(C)return yt(t.removed,ae=>{ae.element&&ss(ae.element)}),Le&&kn(g),g;if(Ge){if(Le&&kn(f),Rt)for(v=Uo.call(f.ownerDocument);f.firstChild;)v.appendChild(f.firstChild);else v=f;return(k.shadowroot||k.shadowrootmode)&&(v=qo.call(i,v,!0)),v}let B=Ie?f.outerHTML:f.innerHTML;return Ie&&x["!doctype"]&&f.ownerDocument&&f.ownerDocument.doctype&&f.ownerDocument.doctype.name&&G(La,f.ownerDocument.doctype.name)&&(B="<!DOCTYPE "+f.ownerDocument.doctype.name+`>
24
+ `+B),Le&&(B=It(B)),ie&&Ot?Ve(B):B},t.setConfig=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};xn(g),yn=!0,bn=x,Tn=k},t.clearConfig=function(){Ye=null,yn=!1,bn=null,Tn=null,ie=pn,Me=""},t.isValidAttribute=function(g,c,f){Ye||xn({});let m=O(g),T=O(c);return Qi(m,T,f)},t.addHook=function(g,c){typeof c=="function"&&$(I,g)&&tt(I[g],c)},t.removeHook=function(g,c){if($(I,g)){if(c!==void 0){let f=la(I[g],c);return f===-1?void 0:ca(I[g],f,1)[0]}return wr(I[g])}},t.removeHooks=function(g){$(I,g)&&(I[g]=[])},t.removeAllHooks=function(){I=Hr()},t}var qr=zr();var z=(e,t="0 0 18 18")=>`<svg viewBox="${t}" width="18" height="18" aria-hidden="true" focusable="false">${e}</svg>`,M={bold:z('<path fill="currentColor" d="M178.48,115.7A44,44,0,0,0,148,40H80a8,8,0,0,0-8,8V200a8,8,0,0,0,8,8h80a48,48,0,0,0,18.48-92.3ZM88,56h60a28,28,0,0,1,0,56H88Zm72,136H88V128h72a32,32,0,0,1,0,64Z"/>',"0 0 256 256"),italic:z('<path fill="currentColor" d="M200,56a8,8,0,0,1-8,8H157.77L115.1,192H144a8,8,0,0,1,0,16H64a8,8,0,0,1,0-16H98.23L140.9,64H112a8,8,0,0,1,0-16h80A8,8,0,0,1,200,56Z"/>',"0 0 256 256"),underline:z('<path fill="currentColor" d="M200,224a8,8,0,0,1-8,8H64a8,8,0,0,1,0-16H192A8,8,0,0,1,200,224Zm-72-24a64.07,64.07,0,0,0,64-64V56a8,8,0,0,0-16,0v80a48,48,0,0,1-96,0V56a8,8,0,0,0-16,0v80A64.07,64.07,0,0,0,128,200Z"/>',"0 0 256 256"),strike:z('<path fill="currentColor" d="M224,128a8,8,0,0,1-8,8H175.93c9.19,7.11,16.07,17.2,16.07,32,0,13.34-7,25.7-19.75,34.79C160.33,211.31,144.61,216,128,216s-32.33-4.69-44.25-13.21C71,193.7,64,181.34,64,168a8,8,0,0,1,16,0c0,17.35,22,32,48,32s48-14.65,48-32c0-14.85-10.54-23.58-38.77-32H40a8,8,0,0,1,0-16H216A8,8,0,0,1,224,128ZM76.33,104a8,8,0,0,0,7.61-10.49A17.3,17.3,0,0,1,83.11,88c0-18.24,19.3-32,44.89-32,18.84,0,34.16,7.42,41,19.85a8,8,0,0,0,14-7.7C173.33,50.52,152.77,40,128,40,93.29,40,67.11,60.63,67.11,88a33.73,33.73,0,0,0,1.62,10.49A8,8,0,0,0,76.33,104Z"/>',"0 0 256 256"),link:z('<path fill="currentColor" d="M240,88.23a54.43,54.43,0,0,1-16,37L189.25,160a54.27,54.27,0,0,1-38.63,16h-.05A54.63,54.63,0,0,1,96,119.84a8,8,0,0,1,16,.45A38.62,38.62,0,0,0,150.58,160h0a38.39,38.39,0,0,0,27.31-11.31l34.75-34.75a38.63,38.63,0,0,0-54.63-54.63l-11,11A8,8,0,0,1,135.7,59l11-11A54.65,54.65,0,0,1,224,48,54.86,54.86,0,0,1,240,88.23ZM109,185.66l-11,11A38.41,38.41,0,0,1,70.6,208h0a38.63,38.63,0,0,1-27.29-65.94L78,107.31A38.63,38.63,0,0,1,144,135.71a8,8,0,0,0,16,.45A54.86,54.86,0,0,0,144,96a54.65,54.65,0,0,0-77.27,0L32,130.75A54.62,54.62,0,0,0,70.56,224h0a54.28,54.28,0,0,0,38.64-16l11-11A8,8,0,0,0,109,185.66Z"/>',"0 0 256 256"),unlink:z('<path fill="currentColor" d="M198.63,57.37a32,32,0,0,0-45.19-.06L141.79,69.52a8,8,0,0,1-11.58-11l11.72-12.29a1.59,1.59,0,0,1,.13-.13,48,48,0,0,1,67.88,67.88,1.59,1.59,0,0,1-.13.13l-12.29,11.72a8,8,0,0,1-11-11.58l12.21-11.65A32,32,0,0,0,198.63,57.37ZM114.21,186.48l-11.65,12.21a32,32,0,0,1-45.25-45.25l12.21-11.65a8,8,0,0,0-11-11.58L46.19,141.93a1.59,1.59,0,0,0-.13.13,48,48,0,0,0,67.88,67.88,1.59,1.59,0,0,0,.13-.13l11.72-12.29a8,8,0,1,0-11.58-11ZM216,152H192a8,8,0,0,0,0,16h24a8,8,0,0,0,0-16ZM40,104H64a8,8,0,0,0,0-16H40a8,8,0,0,0,0,16Zm120,80a8,8,0,0,0-8,8v24a8,8,0,0,0,16,0V192A8,8,0,0,0,160,184ZM96,72a8,8,0,0,0,8-8V40a8,8,0,0,0-16,0V64A8,8,0,0,0,96,72Z"/>',"0 0 256 256"),ul:z('<path fill="currentColor" d="M80,64a8,8,0,0,1,8-8H216a8,8,0,0,1,0,16H88A8,8,0,0,1,80,64Zm136,56H88a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16Zm0,64H88a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16ZM44,52A12,12,0,1,0,56,64,12,12,0,0,0,44,52Zm0,64a12,12,0,1,0,12,12A12,12,0,0,0,44,116Zm0,64a12,12,0,1,0,12,12A12,12,0,0,0,44,180Z"/>',"0 0 256 256"),ol:z('<path fill="currentColor" d="M224,128a8,8,0,0,1-8,8H104a8,8,0,0,1,0-16H216A8,8,0,0,1,224,128ZM104,72H216a8,8,0,0,0,0-16H104a8,8,0,0,0,0,16ZM216,184H104a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16ZM43.58,55.16,48,52.94V104a8,8,0,0,0,16,0V40a8,8,0,0,0-11.58-7.16l-16,8a8,8,0,0,0,7.16,14.32ZM79.77,156.72a23.73,23.73,0,0,0-9.6-15.95,24.86,24.86,0,0,0-34.11,4.7,23.63,23.63,0,0,0-3.57,6.46,8,8,0,1,0,15,5.47,7.84,7.84,0,0,1,1.18-2.13,8.76,8.76,0,0,1,12-1.59A7.91,7.91,0,0,1,63.93,159a7.64,7.64,0,0,1-1.57,5.78,1,1,0,0,0-.08.11L33.59,203.21A8,8,0,0,0,40,216H72a8,8,0,0,0,0-16H56l19.08-25.53A23.47,23.47,0,0,0,79.77,156.72Z"/>',"0 0 256 256"),quote:z('<path fill="currentColor" d="M100,56H40A16,16,0,0,0,24,72v64a16,16,0,0,0,16,16h60v8a32,32,0,0,1-32,32,8,8,0,0,0,0,16,48.05,48.05,0,0,0,48-48V72A16,16,0,0,0,100,56Zm0,80H40V72h60ZM216,56H156a16,16,0,0,0-16,16v64a16,16,0,0,0,16,16h60v8a32,32,0,0,1-32,32,8,8,0,0,0,0,16,48.05,48.05,0,0,0,48-48V72A16,16,0,0,0,216,56Zm0,80H156V72h60Z"/>',"0 0 256 256"),undo:z('<path fill="currentColor" d="M224,128a96,96,0,0,1-94.71,96H128A95.38,95.38,0,0,1,62.1,197.8a8,8,0,0,1,11-11.63A80,80,0,1,0,71.43,71.39a3.07,3.07,0,0,1-.26.25L44.59,96H72a8,8,0,0,1,0,16H24a8,8,0,0,1-8-8V56a8,8,0,0,1,16,0V85.8L60.25,60A96,96,0,0,1,224,128Z"/>',"0 0 256 256"),redo:z('<path fill="currentColor" d="M240,56v48a8,8,0,0,1-8,8H184a8,8,0,0,1,0-16H211.4L184.81,71.64l-.25-.24a80,80,0,1,0-1.67,114.78,8,8,0,0,1,11,11.63A95.44,95.44,0,0,1,128,224h-1.32A96,96,0,1,1,195.75,60L224,85.8V56a8,8,0,1,1,16,0Z"/>',"0 0 256 256"),clear:z('<path fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="square" stroke-linejoin="miter" d="M3 3l18 18M5 5v3M9 5h10v3M12 5v3M12 12v7M8 19h8"/>',"0 0 24 24"),code:z('<path fill="currentColor" d="M69.12,94.15,28.5,128l40.62,33.85a8,8,0,1,1-10.24,12.29l-48-40a8,8,0,0,1,0-12.29l48-40a8,8,0,0,1,10.24,12.3Zm176,27.7-48-40a8,8,0,1,0-10.24,12.3L227.5,128l-40.62,33.85a8,8,0,1,0,10.24,12.29l48-40a8,8,0,0,0,0-12.29ZM162.73,32.48a8,8,0,0,0-10.25,4.79l-64,176a8,8,0,0,0,4.79,10.26A8.14,8.14,0,0,0,96,224a8,8,0,0,0,7.52-5.27l64-176A8,8,0,0,0,162.73,32.48Z"/>',"0 0 256 256"),indent:z('<path fill="currentColor" d="M224,128a8,8,0,0,1-8,8H112a8,8,0,0,1,0-16H216A8,8,0,0,1,224,128ZM112,72H216a8,8,0,0,0,0-16H112a8,8,0,0,0,0,16ZM216,184H40a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16ZM34.34,141.66a8,8,0,0,0,11.32,0l40-40a8,8,0,0,0,0-11.32l-40-40A8,8,0,0,0,34.34,61.66L68.69,96,34.34,130.34A8,8,0,0,0,34.34,141.66Z"/>',"0 0 256 256"),outdent:z('<path fill="currentColor" d="M224,128a8,8,0,0,1-8,8H112a8,8,0,0,1,0-16H216A8,8,0,0,1,224,128ZM112,72H216a8,8,0,0,0,0-16H112a8,8,0,0,0,0,16ZM216,184H40a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16ZM72,144a8,8,0,0,0,5.66-13.66L43.31,96,77.66,61.66A8,8,0,0,0,66.34,50.34l-40,40a8,8,0,0,0,0,11.32l40,40A8,8,0,0,0,72,144Z"/>',"0 0 256 256"),blocks:z('<path fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="square" stroke-linejoin="miter" d="M19 4h-9a4.5 4.5 0 0 0 0 9h3M13 4v16M17 4v16"/>',"0 0 24 24"),h1:z('<path fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" d="M3.5 5.5v12M12 5.5v12M3.5 11.5H12M17 12l3-2v10"/>',"0 0 24 24"),h2:z('<path fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" d="M3.5 5.5v12M12 5.5v12M3.5 11.5H12M16 12.5c0-3.5 6-3.5 6 0 0 2-2.5 3.5-6 7.5h6"/>',"0 0 24 24"),h3:z('<path fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" d="M3.5 5.5v12M12 5.5v12M3.5 11.5H12M16 11c1.5-1.5 6-1.5 6 1.5 0 1.5-1.5 2.5-3 2.5h-1M19 15c1.5 0 3 1 3 2.5 0 3-4.5 3-6 1.5"/>',"0 0 24 24")},Ae=e=>e.blocksStayOut(),Da=e=>!!e.element.closest("a"),Et={minimal:["bold","italic","link","unorderedList"],inline:["bold","italic","underline","strikethrough","code","link","undo","redo","clearFormatting"],standard:["blockMenu","bold","italic","underline","strikethrough","code","link","unorderedList","orderedList","quote","outdent","indent","undo","redo","clearFormatting"]};function Wr(){return new Map(Ma.map(e=>[e.id,e]))}function Ke(e=globalThis){let t=e?.navigator;return t?/Mac|iPhone|iPad|iPod/.test(t.platform||t.userAgent||""):!1}function Kr(e,t=globalThis){return e?e.replace("Mod",Ke(t)?"Cmd":"Ctrl"):""}var Ma=[De("bold","Bold",M.bold,"Mod+B","inline",e=>e.toggleFormat("B","bold","removeBold")),De("italic","Italic",M.italic,"Mod+I","inline",e=>e.toggleFormat("I","italic","removeItalic")),De("underline","Underline",M.underline,"Mod+U","inline",e=>e.toggleFormat("U","underline","removeUnderline")),De("strikethrough","Strikethrough",M.strike,"Mod+Shift+7","inline",e=>e.toggleFormat("S","strikethrough","removeStrikethrough")),De("code","Code",M.code,null,"inline",e=>e.toggleCode(),e=>e.selectionHasFormat("CODE")||e.selectionHasFormat("PRE")),{id:"link",label:"Link",ariaLabel:"Insert or edit link",icon:M.link,group:"links",shortcut:"Mod+K",mutates:!1,isDisabled:Da,run:e=>e.openLinkDialog(),isActive:e=>!!e.currentLinkElement()},{id:"unlink",label:"Remove link",ariaLabel:"Remove link",icon:M.unlink,group:"links",run:e=>e.squire.removeLink()},De("unorderedList","Bulleted list",M.ul,"Mod+Shift+8","lists",e=>e.toggleList("UL"),e=>e.pathHas("UL"),Ae),De("orderedList","Numbered list",M.ol,"Mod+Shift+9","lists",e=>e.toggleList("OL"),e=>e.pathHas("OL"),Ae),De("quote","Quote",M.quote,null,"blocks",e=>e.pathHas("BLOCKQUOTE")?e.squire.decreaseQuoteLevel():e.squire.increaseQuoteLevel(),e=>e.pathHas("BLOCKQUOTE"),Ae),{id:"outdent",label:"Outdent",ariaLabel:"Decrease indent",icon:M.outdent,group:"blocks",shortcut:"Mod+[",isDisabled:Ae,run:e=>e.outdent()},{id:"indent",label:"Indent",ariaLabel:"Increase indent",icon:M.indent,group:"blocks",shortcut:"Mod+]",isDisabled:Ae,run:e=>e.indent()},{id:"undo",label:"Undo",ariaLabel:"Undo",icon:M.undo,group:"history",shortcut:"Mod+Z",mutates:!1,run:e=>e.history("undo")},{id:"redo",label:"Redo",ariaLabel:"Redo",icon:M.redo,group:"history",shortcut:"Mod+Shift+Z",mutates:!1,run:e=>e.history("redo")},{id:"clearFormatting",label:"Clear formatting",ariaLabel:"Clear formatting",icon:M.clear,group:"cleanup",run:e=>e.squire.removeAllFormatting()},{id:"blockMenu",type:"menu",label:"Block style",ariaLabel:"Choose block style",icon:M.blocks,group:"blocks",isDisabled:Ae,options:[Vt("Paragraph","P",M.blocks),Vt("Heading 1","H1",M.h1),Vt("Heading 2","H2",M.h2),Vt("Heading 3","H3",M.h3),{label:"Quote",icon:M.quote,value:"BLOCKQUOTE",isDisabled:Ae,run:e=>e.squire.increaseQuoteLevel(),isActive:e=>e.pathHas("BLOCKQUOTE")},{label:"Code block",icon:M.code,value:"PRE",isDisabled:Ae,run:e=>e.setBlockType("PRE"),isActive:e=>e.pathHas("PRE")}]}];function De(e,t,n,i,r,o,s=l=>l.selectionHasFormat(Ia(e)),a){return{id:e,label:t,ariaLabel:t,icon:n,group:r,shortcut:i,isDisabled:a,run:o,isActive:s}}function Ia(e){return{bold:"B",italic:"I",underline:"U",strikethrough:"S"}[e]}function Vt(e,t,n){return{label:e,icon:n,value:t,isDisabled:Ae,run:i=>i.setBlockType(t),isActive:i=>i.pathHas(t)}}var ei=/^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:FRAME|MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|TIME|U|VAR|WBR)$/,jt=/[^ \t\r\n]/;var Pa=new Set(["BR","HR","IFRAME","IMG","INPUT","WBR"]),ti=e=>e?.nodeType===1&&e.matches('[editor-ui],[clay~="editor-ui"]'),St=new Set(["svg","math"]);function Zt(e){let t=e.nodeType;return t===3||t===8?!0:t!==1?!1:St.has(e.nodeName)?!0:ei.test(e.nodeName)?Array.from(e.childNodes).every(Zt):!1}function At(e){return Array.from(e.childNodes).some(t=>!Zt(t))}var Jn=e=>e?.nodeType===1&&!St.has(e.nodeName)&&!ei.test(e.nodeName);function Ct(e,t){let n=Array.from(e.childNodes),i=0;return n.forEach((r,o)=>{if(!(r.nodeType!==1||St.has(r.nodeName))&&(i+=Ct(r,t),!!Jn(r))){for(Jn(n[o-1])&&e.insertBefore(t(),r);r.firstChild;)e.insertBefore(r.firstChild,r);r.remove(),i+=1}}),i}var ni=new Set(["TABLE","THEAD","TBODY","TFOOT","TR","COLGROUP"]);function Yt(e){return!!e.closest?.("p")||ni.has(e.nodeName)}var Ba=new Set(["P","H1","H2","H3","H4","H5","H6","PRE","LABEL","LEGEND","LI","TD","TH","DT","DD","FIGCAPTION","SUMMARY","CAPTION"]);function jr(e){return Ba.has(e.nodeName)||Xt(e)}var Zr=new Set(["AREA","BASE","BR","COL","EMBED","HR","IMG","INPUT","LINK","META","PARAM","SOURCE","TRACK","WBR"]),Ha=new Set(["SCRIPT","STYLE","TEXTAREA","TITLE","IFRAME","NOSCRIPT","XMP"]),Yr="http://www.w3.org/1999/xhtml";function Xr(e){return ni.has(e.nodeName)||Zr.has(e.nodeName)||Ha.has(e.nodeName)||e.nodeName==="TEMPLATE"||!!e.namespaceURI&&e.namespaceURI!==Yr}function Qr(e){return ni.has(e.nodeName)?"a table element cannot be an editable region. Move the editable attribute to a <td>, a <th>, or an element inside one.":e.namespaceURI&&e.namespaceURI!==Yr?"an SVG or MathML element cannot be an editable region: an edit puts an HTML block inside it, and the next page load moves that text out of the graphic entirely. Put a <foreignObject> in the SVG and mark an HTML element inside it instead.":Zr.has(e.nodeName)?"this element cannot contain anything, so there is nothing to edit. Move the editable attribute to an element that holds text.":e.nodeName==="TEMPLATE"?"a <template> keeps its content out of the document, so edits to it are never saved.":"this element treats its content as plain text, so any edit would be saved as visible markup rather than formatting."}function Xt(e){return e.nodeType===1&&!St.has(e.nodeName)&&ei.test(e.nodeName)}function Qt(e){return Array.from(e.querySelectorAll("*")).some(Jn)}function Jr(e,t={}){let{blockTag:n="DIV",wrapBareRoot:i=!1,onBareRootWrapped:r,blocksAllowed:o=!Yt(e)}=t;return no(e),o&&za(e,n,i,r),e}var Fa=e=>Zt(e)&&e.nodeType!==8&&!ti(e),Ua=e=>e.nodeType!==8&&!ti(e)&&!(e.nodeType===3&&!jt.test(e.nodeValue));function eo(e,{wrapBareRoot:t=!1,blocksAllowed:n=!Yt(e)}={}){return n?At(e)?Array.from(e.childNodes).some(Fa)||to(e):t:!1}function to(e){return Array.from(e.children).some(t=>At(t)?!ii(t)&&Array.from(t.childNodes).some(i=>i.nodeType===3&&!jt.test(i.nodeValue))||to(t):!1)}function no(e){At(e)&&(ii(e)||Array.from(e.childNodes).forEach(t=>{t.nodeType===3&&!jt.test(t.nodeValue)&&t.remove()}),Array.from(e.children).forEach(no))}function za(e,t,n,i){if(!At(e)){if(!n)return;let s=e.ownerDocument.createElement(t);if(!Array.from(e.childNodes).some(Ua)){s.appendChild(e.ownerDocument.createElement("BR")),e.appendChild(s);return}for(;e.firstChild;)s.appendChild(e.firstChild);e.appendChild(s),i?.(e,s);return}let r=[],o=()=>{let s=r;if(r=[],!s.some(l=>l.nodeType!==8))return;let a=e.ownerDocument.createElement(t);e.insertBefore(a,s[0]),s.forEach(l=>a.appendChild(l))};Array.from(e.childNodes).forEach(s=>{ti(s)?o():Zt(s)?r.push(s):o()}),o()}function ii(e){return e.nodeName==="PRE"}function io(e,t){return{start:$r(e,t.startContainer,t.startOffset),end:$r(e,t.endContainer,t.endOffset),collapsed:t.collapsed}}function ro(e,t,n){Gr(t,"setStart",e,n.start),n.collapsed?t.collapse(!0):Gr(t,"setEnd",e,n.end)}function $r(e,t,n){if(!e.contains(t))return{scope:e,after:[],before:[]};if(t.nodeType===3){if(!qa(t))return{container:t,offset:n};let i=t.parentNode;return Vr(i,Array.from(i.childNodes).indexOf(t))}return{container:t,offset:n,childCount:t.childNodes.length,...Vr(t,n)}}function Vr(e,t){let n=Array.from(e.childNodes),i=Math.max(0,t);return{scope:e,after:n.slice(i),before:n.slice(0,i).reverse()}}function Gr(e,t,n,i){let{container:r,childCount:o}=i;if(r&&n.contains(r)&&(o===void 0||o===r.childNodes.length)){e[t](r,Math.min(i.offset,Gt(r)));return}let s=i.after?.find(h=>n.contains(h));if(s){e[t](vt(s,!0),0);return}let a=i.before?.find(h=>n.contains(h));if(a){let h=vt(a,!1);e[t](h,Gt(h));return}let l=i.scope&&n.contains(i.scope)?i.scope:n;e[t](l,0)}function qa(e){return e.nodeType===3&&!jt.test(e.nodeValue)&&!!e.parentNode&&e.parentNode.nodeType===1&&At(e.parentNode)&&!ii(e.parentNode)}var it=e=>e.nodeType===1||e.nodeType===3;function vt(e,t=!0){let n=e;for(;n.nodeType===1&&!St.has(n.nodeName);){let i=Array.from(n.childNodes).filter(it),r=t?i[0]:i[i.length-1];if(!r||Pa.has(r.nodeName))break;n=r}return n}function Gt(e){return e.nodeType===3?e.nodeValue.length:e.childNodes.length}var ce="[data-richclay], [richclay], [editable], [clay-editable]",Wa="[data-richclay], [richclay], [clay-editable]",Ka=["editable","clay-editable"],si=':is([editable~="single-line"], [clay-editable~="single-line"])';function Jt(e){return!e||typeof e.matches!="function"?!1:e.tagName.includes("-")?e.matches(Wa):!0}var $a="[data-richclay-toolbar], [data-richclay-menu], [data-richclay-dialog], [data-richclay-link-popover], [data-richclay-live], [data-richclay-float]",Va=["richclay-editor","richclay-inline","richclay-active","richclay-empty","richclay-focused"],ai=new WeakSet,oo=new WeakSet,so=["clay:ready","hyperclay:ready"];function ao(e){return[e.clay?.ready,e.hyperclay?.ready].find(t=>t&&typeof t.then=="function")||null}function lo(e){return typeof e.clay?.isEditMode=="boolean"?e.clay.isEditMode:typeof e.hyperclay?.isEditMode=="boolean"?e.hyperclay.isEditMode:null}function Ga(e){let t=e.hyperclayModules,n=e.__hyperclayNoAutoExport===!1&&t&&typeof t=="object"&&typeof t.nodeType!="number";return lo(e)!==null||!!ao(e)||!!n}function ja(e){return e.clay?.addDocumentTransform||e.hyperclay?.beforeSave||null}function Za(e){return e.clay?.onSnapshot||e.hyperclay?.onSnapshot||null}var Ya={boxSizing:"border-box",minWidth:"100%",overflow:"auto",width:"0"};function en(e={},t=window){return e.hyperclay===!1?!1:e.hyperclay===!0?!0:!!(Ga(t)||rl(t))}function li(e=window){let t=uo(e);if(t!==null)return t;if(typeof e.__hyperclayEditMode=="boolean")return e.__hyperclayEditMode;let n=lo(e);return n!==null?n:ol(e)}function co(e={},t=window){return e.readOnly?!1:en(e,t)?li(t):!0}function ho(e){let t=Ka.find(r=>e.hasAttribute(r));if(!t)return null;let n=new Set((e.getAttribute(t)||"").trim().split(/\s+/).filter(Boolean)),i={inline:!0,singleLine:n.has("single-line"),toolbarOnSelect:n.has("toolbar-on-select")};return n.has("no-toolbar")&&(i.toolbar=!1),n.has("link-label")&&(i.singleLine=!0,i.linkLabel=!0,i.toolbar=["link","undo","redo"]),i}function ci(e=window){if(ai.has(e))return;let t=Za(e)||ja(e);if(typeof t!="function"){Xa(e);return}t(n=>tn(n)),ai.add(e)}function Xa(e){if(oo.has(e))return;let t=e.document,n=ao(e);if(!t&&!n)return;oo.add(e);let i=()=>{ci(e),ai.has(e)&&r()},r=()=>{t&&so.forEach(o=>t.removeEventListener(o,i))};t&&so.forEach(o=>t.addEventListener(o,i)),n&&n.then(i,()=>{})}function tn(e){e.querySelectorAll?.($a).forEach(t=>t.remove()),e.querySelectorAll?.(ce).forEach(t=>{if(t.getAttribute("data-richclay-active")!=="true")return;if(nn(t,"save"),tl(t)){let i=t.ownerDocument,r=!!t.matches?.(si);Ct(t,()=>r?i.createTextNode(" "):i.createElement("br")),t.querySelectorAll(t.localName).forEach(o=>{for(;o.firstChild;)o.parentNode.insertBefore(o.firstChild,o);o.remove()})}t.matches?.(si)&&il(t),t.querySelectorAll("#squire-selection-start, #squire-selection-end").forEach(i=>{i.remove()}),t.querySelectorAll(".squire-image-resize-container").forEach(i=>i.remove()),nl(t),(t.matches?.("pre")?[t,...t.querySelectorAll("pre")]:Array.from(t.querySelectorAll("pre"))).filter(i=>i.hasAttribute("data-richclay-pre")).forEach(i=>{Object.entries(Ya).forEach(([r,o])=>{i.style[r]||(i.style[r]=o)}),i.removeAttribute("data-richclay-pre")})}),e.querySelectorAll?.("#squire-selection-start, #squire-selection-end").forEach(t=>t.remove())}var Qa="p, td, th, li, dl, dt, dd, table, blockquote, div, section, article, aside, main, header, footer, figure, figcaption",ri="data-richclay-measure";function Ja(e){let t=e.ownerDocument,n=e.closest(Qa)||e;e.setAttribute(ri,"");let i=t.createElement("div");try{i.innerHTML=n.outerHTML}finally{e.removeAttribute(ri)}let r=i.querySelector(`[${ri}]`);return!r||r.textContent!==e.textContent}var el=e=>!!e.querySelector(e.localName),tl=e=>!!e.matches?.(si)||(Qt(e)||el(e))&&Ja(e);function nn(e,t){let n=e.getAttribute("data-richclay-runtime-contenteditable");e.hasAttribute("contenteditable")&&(n==="true"?e.removeAttribute("contenteditable"):n?t==="destroy"?e.setAttribute("contenteditable",n):(e.setAttribute("inert-contenteditable",n),e.removeAttribute("contenteditable")):t==="save"&&(e.setAttribute("inert-contenteditable",e.getAttribute("contenteditable")),e.removeAttribute("contenteditable"))),Va.forEach(i=>e.classList.remove(i)),e.getAttribute("class")===""&&e.removeAttribute("class"),oi(e,"role","data-richclay-runtime-role"),oi(e,"aria-multiline","data-richclay-runtime-aria-multiline"),oi(e,"no-undo","data-richclay-runtime-no-undo"),e.getAttribute("data-richclay-runtime-display")==="true"&&(e.style.removeProperty("display"),e.getAttribute("style")===""&&e.removeAttribute("style")),sl(e),e.removeAttribute("data-richclay-active"),e.removeAttribute("data-richclay-placeholder"),e.removeAttribute("data-richclay-pre"),e.removeAttribute("data-richclay-runtime-role"),e.removeAttribute("data-richclay-runtime-aria-multiline"),e.removeAttribute("data-richclay-runtime-no-undo"),e.removeAttribute("data-richclay-runtime-describedby"),e.removeAttribute("data-richclay-runtime-contenteditable"),e.removeAttribute("data-richclay-runtime-display"),e.getAttribute("data-richclay-runtime-marker")==="true"&&e.removeAttribute("data-richclay"),e.removeAttribute("data-richclay-runtime-marker")}function nl(e){let n=[e];for(;n.length;)n.pop().childNodes.forEach(r=>{r.nodeType===3?r.nodeValue.includes("\u200B")&&(r.nodeValue=r.nodeValue.split("\u200B").join("")):r.nodeType===1&&n.push(r)});e.querySelectorAll("b, i, u, s, em, strong, code, sub, sup, span").forEach(i=>{i.children.length===0&&(i.textContent||"")===""&&i.attributes.length===0&&i.remove()})}function il(e){let t=Array.from(e.childNodes).filter(i=>i.nodeType!==3||(i.nodeValue||"").trim()!=="");if(t.length!==1)return;let n=t[0];if(!(n.nodeType!==1||n.nodeName!=="P"||n.attributes.length>0)){for(;n.firstChild;)e.insertBefore(n.firstChild,n);n.remove()}}function hi(e){if(!e.hasAttribute("inert-contenteditable"))return null;let t=e.getAttribute("inert-contenteditable");return["false","plaintext-only"].includes(t)||(t="true"),e.setAttribute("contenteditable",t),e.removeAttribute("inert-contenteditable"),t==="true"&&e.setAttribute("data-richclay-runtime-contenteditable","true"),t}function he(e){return e.setAttribute("snapshot-remove",""),e.setAttribute("no-watch",""),e}function uo(e){try{let t=new URLSearchParams(e.location?.search||"");if(t.get("editmode")==="true")return!0;if(t.get("editmode")==="false")return!1}catch{return null}return null}function rl(e){return uo(e)!==null||typeof e.__hyperclayEditMode=="boolean"}function ol(e){let n=(e.document?.cookie||"").match(/(?:^|;\s*)isAdminOfCurrentResource=([^;]*)/);return!!(n&&n[1]!=="")}function oi(e,t,n){e.hasAttribute(n)&&e.removeAttribute(t)}function sl(e){let t=e.getAttribute("data-richclay-runtime-describedby");if(!t)return;let n=(e.getAttribute("aria-describedby")||"").split(/\s+/).filter(Boolean).filter(i=>i!==t);n.length?e.setAttribute("aria-describedby",n.join(" ")):e.removeAttribute("aria-describedby")}var al=0;function fo(e=document){let t=e.createElement("div");return t.id=`richclay-live-${++al}`,t.className="richclay-sr-only",t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),t.setAttribute("data-richclay-live",""),he(t),e.body.appendChild(t),t}function rt(e,t){!e||!t||(e.textContent="",e.ownerDocument.defaultView.setTimeout(()=>{e.textContent=t},20))}function Lt(e){e.preventDefault()}function ui(e){try{return e?.cloneRange?.()||null}catch{return null}}function ot(e){try{return ui(e?.getSelection?.())}catch{return null}}function rn(e,t){if(!e||!t)return!1;try{return e.setSelection(t),!0}catch{return!1}}function on(e,t,n,i){e.hasAttribute(t)||e.setAttribute(i,"true"),e.setAttribute(t,n)}function po(e,t){let n=new Set((e.getAttribute("aria-describedby")||"").split(/\s+/).filter(Boolean));n.add(t.id),e.setAttribute("aria-describedby",Array.from(n).join(" ")),e.setAttribute("data-richclay-runtime-describedby",t.id)}var ll=0,st=class{constructor(t,n,i={}){this.editor=t,this.controls=n,this.options=i,this.id=++ll,this.items=[],this.menus=new Map,this.activeIndex=0,this.root=this.createRoot(),this.onRootKeydown=r=>this.handleRootKeydown(r),this.onRootClick=r=>this.handleRootClick(r),this.onRootPointerDown=r=>this.handleRootPointerDown(r),this.onDocumentPointerDown=r=>this.handleDocumentPointerDown(r),this.render(),this.root.addEventListener("keydown",this.onRootKeydown),this.root.addEventListener("click",this.onRootClick),this.root.addEventListener("mousedown",this.onRootPointerDown),this.root.ownerDocument.addEventListener("mousedown",this.onDocumentPointerDown)}destroy(){this.closeMenus(),this.root.removeEventListener("keydown",this.onRootKeydown),this.root.removeEventListener("click",this.onRootClick),this.root.removeEventListener("mousedown",this.onRootPointerDown),this.root.ownerDocument.removeEventListener("mousedown",this.onDocumentPointerDown),this.root.remove()}update(){this.items.forEach(t=>{let{def:n,button:i}=t;if(typeof n.isActive=="function"){let r=!!n.isActive(this.editor);i.setAttribute("aria-pressed",r?"true":"false"),i.classList.toggle("is-active",r)}typeof n.isDisabled=="function"&&(i.disabled=!!n.isDisabled(this.editor))}),this.ensureSingleTabStop()}focusFirst(){this.activeIndex=0,this.ensureSingleTabStop(),this.items[0]?.button.focus()}createRoot(){let t=this.editor.element.ownerDocument,n=t.createElement("div");n.className="richclay-toolbar",n.setAttribute("role","toolbar"),n.setAttribute("aria-label",this.options.ariaLabel||"Rich text formatting"),n.setAttribute("data-richclay-toolbar",""),he(n);let i=cl(this.options.toolbarContainer,t);return i?i.appendChild(n):this.editor.element.insertAdjacentElement("beforebegin",n),n}render(){this.root.textContent="",this.items=[],this.menus.clear();let t=null;this.visibleControls().forEach((n,i)=>{if(n.type==="separator"){this.root.appendChild(go(this.root.ownerDocument)),t=null;return}t&&n.group&&n.group!==t&&this.root.appendChild(go(this.root.ownerDocument)),t=n.group||t,n.type==="menu"?this.renderMenu(n,i):this.renderButton(n,i)}),this.ensureSingleTabStop(),this.update()}visibleControls(){let t=this.controls.filter(i=>i.type==="separator"||!i.isDisabled?.(this.editor)),n=[];for(t.forEach(i=>{let r=n[n.length-1];i.type==="separator"&&(!r||r.type==="separator")||n.push(i)});n[n.length-1]?.type==="separator";)n.pop();return n}renderButton(t,n){let i=mo(this.root.ownerDocument,t);i.dataset.richclayControl=t.id,i.dataset.richclayIndex=String(n),typeof t.isActive=="function"&&i.setAttribute("aria-pressed","false"),this.root.appendChild(i),this.items.push({def:t,button:i,type:"button"})}renderMenu(t,n){let i=this.root.ownerDocument,r=mo(i,t),o=`richclay-menu-${this.id}-${t.id}`;r.dataset.richclayControl=t.id,r.dataset.richclayIndex=String(n),r.setAttribute("aria-haspopup","menu"),r.setAttribute("aria-expanded","false"),r.setAttribute("aria-controls",o);let s=i.createElement("div");s.id=o,s.className="richclay-menu",s.hidden=!0,s.setAttribute("role","menu"),s.setAttribute("data-richclay-menu",""),he(s),t.options.forEach((l,h)=>{let d=i.createElement("button");d.type="button",d.className="richclay-menu-item",d.setAttribute("role","menuitemradio"),d.setAttribute("tabindex","-1"),d.dataset.richclayMenuItem=t.id,d.dataset.richclayOptionIndex=String(h),d.innerHTML=l.icon||"",d.appendChild(i.createTextNode(l.label)),d.addEventListener("mousedown",Lt),d.addEventListener("click",u=>{u.preventDefault(),this.chooseMenuItem(t,l,r)}),d.addEventListener("keydown",u=>this.handleMenuKeydown(u,t,r)),s.appendChild(d)});let a=i.createElement("span");a.className="richclay-menu-wrap",a.append(r,s),this.root.appendChild(a),this.items.push({def:t,button:r,type:"menu",menu:s}),this.menus.set(t.id,{def:t,button:r,menu:s})}handleRootPointerDown(t){let n=t.target.closest?.("[data-richclay-control]");!n||!this.root.contains(n)||(Lt(t),this.editor.saveSelection())}handleRootClick(t){let n=t.target.closest?.("[data-richclay-control]");if(!n||!this.root.contains(n))return;t.preventDefault();let i=this.items.find(r=>r.button===n);if(!(!i||n.disabled)){if(this.activeIndex=this.items.indexOf(i),this.ensureSingleTabStop(),i.type==="menu"){this.toggleMenu(i.def.id);return}this.closeMenus(),this.editor.runControl(i.def)}}handleRootKeydown(t){let n=t.key,i={ArrowRight:1,ArrowDown:1,ArrowLeft:-1,ArrowUp:-1};if(n in i){t.preventDefault(),this.moveFocus(i[n]);return}if(n==="Home"){t.preventDefault(),this.setFocusIndex(0);return}if(n==="End"){t.preventDefault(),this.setFocusIndex(this.items.length-1);return}let r=this.items[this.activeIndex];if(r&&((n==="Enter"||n===" ")&&r.type==="menu"&&(t.preventDefault(),this.openMenu(r.def.id,"first")),n==="Escape")){let o=Array.from(this.menus.values()).some(s=>!s.menu.hidden);this.closeMenus(),o?r.button.focus():this.editor.focus()}}handleMenuKeydown(t,n,i){t.stopPropagation();let r=this.menus.get(n.id)?.menu,o=Array.from(r.querySelectorAll(".richclay-menu-item")),s=o.indexOf(t.currentTarget),a=s;if(t.key==="ArrowDown"&&(a=(s+1)%o.length),t.key==="ArrowUp"&&(a=(s-1+o.length)%o.length),t.key==="Home"&&(a=0),t.key==="End"&&(a=o.length-1),a!==s){t.preventDefault(),o[a].focus();return}if(t.key==="Escape"){t.preventDefault(),this.closeMenus(),i.focus();return}if(t.key==="Enter"||t.key===" "){t.preventDefault();let l=n.options[s];this.chooseMenuItem(n,l,i)}}handleDocumentPointerDown(t){this.root.contains(t.target)||this.closeMenus()}chooseMenuItem(t,n,i){this.closeMenus(),this.editor.runControl({...n,id:`${t.id}:${n.value}`,ariaLabel:n.label}),i.focus()}toggleMenu(t){let n=this.menus.get(t);n&&(n.menu.hidden?this.openMenu(t,"first"):this.closeMenus())}openMenu(t,n="first"){this.closeMenus(t);let i=this.menus.get(t);if(!i)return;i.menu.hidden=!1,i.button.setAttribute("aria-expanded","true"),this.updateMenuState(i);let r=Array.from(i.menu.querySelectorAll(".richclay-menu-item")),o=r.find(a=>a.getAttribute("aria-checked")==="true");(n==="active"&&o||r[0])?.focus()}closeMenus(t=null){this.menus.forEach((n,i)=>{i!==t&&(n.menu.hidden=!0,n.button.setAttribute("aria-expanded","false"))})}updateMenuState(t){Array.from(t.menu.querySelectorAll(".richclay-menu-item")).forEach((i,r)=>{let s=!!t.def.options[r].isActive?.(this.editor);i.setAttribute("aria-checked",s?"true":"false"),i.classList.toggle("is-active",s)})}moveFocus(t){if(!this.items.length)return;let n=this.activeIndex;do n=(n+t+this.items.length)%this.items.length;while(this.items[n].button.disabled&&n!==this.activeIndex);this.setFocusIndex(n)}setFocusIndex(t){this.activeIndex=Math.max(0,Math.min(t,this.items.length-1)),this.ensureSingleTabStop(),this.items[this.activeIndex]?.button.focus()}ensureSingleTabStop(){let t=this.items.filter(n=>!n.button.disabled);t.length&&(t.includes(this.items[this.activeIndex])||(this.activeIndex=this.items.indexOf(t[0])),this.items.forEach((n,i)=>{n.button.tabIndex=i===this.activeIndex?0:-1}))}};function mo(e,t){let n=e.createElement("button");n.type="button",n.className="richclay-button";let i=Kr(t.shortcut,e.defaultView),r=i?`${t.ariaLabel||t.label} (${i})`:t.ariaLabel||t.label;return n.setAttribute("aria-label",r),n.title=r,n.innerHTML=`${t.icon||""}<span class="richclay-sr-only">${t.label}</span>`,n}function go(e){let t=e.createElement("span");return t.className="richclay-separator",t.setAttribute("role","separator"),t.setAttribute("aria-orientation","vertical"),t}function cl(e,t){return e?typeof e=="string"?t.querySelector(e):e:null}var yo=16,hl=[16,8,0],V=8,ul=4;function dl({anchor:e,bar:t,rail:n,viewport:i,current:r=null}){let o=p=>r===p?ul:0;if(e.bottom<=0||e.top>=i.height||e.right<=0||e.left>=i.width)return{mode:"hidden",x:0,y:0};let s=p=>Math.max(V,Math.min(e.left,i.width-p-V)),a=e.top-yo-t.height;if(a>=V-o("above"))return{mode:"above",x:s(t.width),y:a};let l=e.bottom+yo;if(l+t.height<=i.height-V+o("below"))return{mode:"below",x:s(t.width),y:l};let h=i.width-e.right-V,d=e.left-V,u=h>=d?[["rail-right",h],["rail-left",d]]:[["rail-left",d],["rail-right",h]];for(let[p,b]of u)for(let y of hl){if(n.width+y>b+o(p))continue;let E=p==="rail-right"?Math.min(e.right+y,i.width-n.width-V):Math.max(e.left-y-n.width,V),S=Math.min(e.bottom,i.height-V)-n.height,N=Math.max(V,Math.min(Math.max(e.top,V),S));return{mode:p,x:E,y:N,gap:y}}return{mode:"pinned",x:s(t.width),y:V}}var fl=10,pl=28;function an({anchor:e,box:t,viewport:n,gap:i=fl}){let r=n.height-V-e.bottom-i,o=e.top-i-V,s=r>=t.height||r>=o?"below":"above",a=s==="below"?e.bottom+i:e.top-i-t.height,l=Math.max(V,Math.min(a,n.height-V-t.height)),h=(e.left+e.right)/2,d=Math.max(V,Math.min(h-pl,n.width-V-t.width)),u=Math.max(14,Math.min(h-d,t.width-14));return{side:s,x:d,y:l,arrow:u}}function Q(e,t,n){e.style.setProperty(t,n,"important")}var sn=class{constructor(t,n){this.editor=t,this.mode=null,this.hidden=!1,this.frame=0,this.bar={width:0,height:0},this.rail={width:0,height:0};let i=t.element.ownerDocument;this.doc=i,this.win=i.defaultView||globalThis,this.root=i.createElement("div"),this.root.className="richclay-float",this.root.setAttribute("data-richclay-float",""),this.root.setAttribute("save-remove",""),he(this.root),i.body.appendChild(this.root),this.toolbar=new st(t,n,{toolbarContainer:this.root}),this.onScroll=()=>this.schedule(),this.onResize=()=>{this.measure(),this.schedule()},i.addEventListener("scroll",this.onScroll,{capture:!0,passive:!0}),this.win.addEventListener("resize",this.onResize,{passive:!0}),this.win.visualViewport?.addEventListener("resize",this.onResize,{passive:!0}),this.win.visualViewport?.addEventListener("scroll",this.onScroll,{passive:!0}),this.resizeObserver=typeof this.win.ResizeObserver=="function"?new this.win.ResizeObserver(()=>this.schedule()):null,this.resizeObserver?.observe(t.element),this.measure(),this.reposition()}measure(){let t=this.root.classList.contains("richclay-float-rail");Q(this.root,"visibility","hidden"),this.root.classList.remove("richclay-float-rail"),this.bar={width:this.root.offsetWidth||0,height:this.root.offsetHeight||0},this.root.classList.add("richclay-float-rail"),this.rail={width:this.root.offsetWidth||0,height:this.root.offsetHeight||0},this.root.classList.toggle("richclay-float-rail",t),this.root.style.removeProperty("visibility")}schedule(){if(!this.win.requestAnimationFrame){this.reposition();return}this.frame||(this.frame=this.win.requestAnimationFrame(()=>{this.frame=0,this.reposition()}))}setVisible(t){this.hidden=!t,this.reposition()}reposition(){if(this.hidden){Q(this.root,"display","none");return}let t=this.editor.element.getBoundingClientRect(),n={width:this.win.visualViewport?.width??this.win.innerWidth,height:this.win.visualViewport?.height??this.win.innerHeight},i=dl({anchor:t,bar:this.bar,rail:this.rail,viewport:n,current:this.mode});if(this.mode=i.mode,i.mode==="hidden"){Q(this.root,"display","none");return}this.root.style.removeProperty("display"),this.root.classList.toggle("richclay-float-rail",i.mode==="rail-left"||i.mode==="rail-right"),this.root.classList.toggle("richclay-float-pinned",i.mode==="pinned"),Q(this.root,"transform",`translate(${Math.round(i.x)}px, ${Math.round(i.y)}px)`)}destroy(){this.frame&&this.win.cancelAnimationFrame?.(this.frame),this.frame=0,this.doc.removeEventListener("scroll",this.onScroll,{capture:!0}),this.win.removeEventListener("resize",this.onResize),this.win.visualViewport?.removeEventListener("resize",this.onResize),this.win.visualViewport?.removeEventListener("scroll",this.onScroll),this.resizeObserver?.disconnect(),this.toolbar.destroy(),this.root.remove()}};var ml={ALLOWED_TAGS:["a","b","blockquote","br","code","div","em","h1","h2","h3","h4","h5","h6","i","li","ol","p","pre","s","span","strong","sub","sup","u","ul"],ALLOWED_ATTR:["aria-label","href","rel","target","title"],ALLOW_DATA_ATTR:!1,ALLOW_ARIA_ATTR:!0,ALLOWED_URI_REGEXP:/^(?:(?:(?:f|ht)tps?|mailto|tel):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i,FORBID_TAGS:["script","style","iframe","object","embed","form","input"],FORBID_ATTR:["style","srcset","onerror","onclick","onload"]};function di(e={},t=document){let n=ln(t);return{sanitizeHTML(i){return fi(i,e,t,n)},sanitizeElement(i){return pi(i,e,n)},sanitizeToDOMFragment(i,r){let o=r?.getRoot?.().ownerDocument||t;return gl(i,e,o,n)}}}function fi(e,t={},n=document,i=ln(n)){let r=n.createElement("template");return r.innerHTML=i.sanitize(String(e||""),mi(t)),yi(r.content),r.innerHTML}function pi(e,t={},n=ln(e.ownerDocument)){let r=e.ownerDocument.createElement("div");for(;e.firstChild;)r.appendChild(e.firstChild);for(n.sanitize(r,{...mi(t),IN_PLACE:!0}),yi(r);r.firstChild;)e.appendChild(r.firstChild);return e}function gl(e,t={},n=document,i=ln(n)){let r=i.sanitize(String(e||""),{...mi(t),RETURN_DOM_FRAGMENT:!0}),o=r?.ownerDocument===n?r:n.importNode(r,!0);return yi(o),o||n.createDocumentFragment()}function mi(e){return{...ml,...e}}var yl=new Set(["http","https","mailto","tel"]),bl=new RegExp("[\\u0000-\\u0020\\u007F-\\u009F]","g");function gi(e){let n=(String(e??"").replace(bl,"").match(/^([a-z][a-z0-9+.\-]*):/i)||[])[1];return!n||yl.has(n.toLowerCase())}var Tl=/^[^\s/?#:]+\.(?:html?|pdf|txt|csv|json|xml|svg|png|jpe?g|gif|webp|docx?|xlsx?|pptx?|bib|tex|zip)(?:[?#]\S*)?$/i,_l=/^[^\s/?#:.]+\/\S*$/;function _o(e){let t=String(e??"").trim();return!t||!gi(t)?"":/^(?:https?:|mailto:|tel:)/i.test(t)?t:/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)?`mailto:${t}`:/^(?:[#?]|\/|\.{1,2}\/)/.test(t)||Tl.test(t)||_l.test(t)?t:`https://${t}`}function ln(e){let t=globalThis.DOMPurify;if(t?.sanitize)return t;if(typeof t=="function")return t(e.defaultView||globalThis);throw new Error("RichClay requires DOMPurify. Load vendor/purify.min.js before richclay.js or provide globalThis.DOMPurify.")}function yi(e){e.querySelectorAll?.("a[href]").forEach(t=>{let n=t.getAttribute("href")||"";if(/^\s*javascript:/i.test(n)&&t.removeAttribute("href"),t.getAttribute("target")==="_blank"){let i=new Set((t.getAttribute("rel")||"").split(/\s+/).filter(Boolean));i.add("noopener"),i.add("noreferrer"),t.setAttribute("rel",Array.from(i).join(" "))}})}var bo={ADD_TAGS:["img"],ADD_ATTR:["class","id","src","alt","width","height"]};function cn(e={}){return{...e,ADD_TAGS:[...new Set([...bo.ADD_TAGS,...e.ADD_TAGS||[]])],ADD_ATTR:[...new Set([...bo.ADD_ATTR,...e.ADD_ATTR||[]])],ALLOW_DATA_ATTR:e.ALLOW_DATA_ATTR??!0}}var To="p, div, h1, h2, h3, h4, h5, h6, blockquote, pre, ul, ol, li, figure, figcaption, table, thead, tbody, tr, td, th";function Eo(e){let t=e.ownerDocument||document;e.querySelectorAll?.("br").forEach(i=>i.replaceWith(t.createTextNode(" ")));let n=e.querySelector?.(To);for(;n;){let i=n.parentNode;for(i.insertBefore(t.createTextNode(" "),n);n.firstChild;)i.insertBefore(n.firstChild,n);i.insertBefore(t.createTextNode(" "),n),n.remove(),n=e.querySelector(To)}return El(e,t),e}function El(e,t){e.normalize?.();let n=t.createTreeWalker(e,4),i=[];for(;n.nextNode();)i.push(n.currentNode);i.forEach(s=>{s.nodeValue=s.nodeValue.replace(/\s+/g," ")});let r=e.firstChild;r?.nodeType===3&&(r.nodeValue=r.nodeValue.replace(/^\s+/,""));let o=e.lastChild;o?.nodeType===3&&(o.nodeValue=o.nodeValue.replace(/\s+$/,""))}var vl=300,Sl=e=>e.replace(/^mailto:/i,"").replace(/^https?:\/\//i,""),hn=class{constructor(t){this.editor=t,this.root=null,this.anchor=null,this.href=null,this.dismissed=null,this.hideTimer=null,this.pointerInside=!1,this.cleanup=null}currentAnchor(){let t=this.editor;if(!t.active||t.options.readOnly||t.dialog)return null;let n=t.element.ownerDocument;if(n.hidden)return null;let i=n.getSelection?.();return!i||!i.rangeCount||!t.element.contains(i.anchorNode)?null:t.currentLinkElement()}update(){let t=this.currentAnchor();if(!(t&&t===this.dismissed)){if(this.dismissed=null,!t){this.scheduleHide();return}this.cancelHide(),this.show(t)}}show(t){this.root||this.mount();let n=t.getAttribute("href")||"";if(t!==this.anchor||n!==this.href){this.anchor=t,this.href=n;let i=this.root.querySelector(".richclay-link-address");i.textContent=Sl(n)||n,i.title=n,n&&gi(n)?i.setAttribute("href",n):i.removeAttribute("href"),/^(?:mailto|tel):/i.test(n)?i.removeAttribute("target"):i.setAttribute("target","_blank")}this.position()}mount(){let t=this.editor,n=t.element.ownerDocument,i=n.defaultView||globalThis,r=n.createElement("div");r.className="richclay-dialog richclay-link-popover",r.setAttribute("role","group"),r.setAttribute("aria-label","Link"),r.setAttribute("data-richclay-link-popover",""),he(r),r.setAttribute("save-remove",""),r.innerHTML=`
25
25
  <a class="richclay-link-address" rel="noopener noreferrer"></a>
26
26
  <button type="button" class="richclay-secondary" data-richclay-link-edit>Edit</button>
27
27
  <button type="button" class="richclay-secondary" data-richclay-link-remove>Remove</button>
28
- `,t.options.linkLabel&&r.querySelector("[data-richclay-link-remove]").remove(),r.addEventListener("pointerdown",Lt),r.addEventListener("pointerenter",()=>{this.pointerInside=!0,this.cancelHide()}),r.addEventListener("pointerleave",()=>{this.pointerInside=!1,this.update()}),r.querySelector("[data-richclay-link-edit]").addEventListener("click",()=>{let h=this.anchor;if(!h||!t.element.contains(h))return this.hide();t.selectElement(h),t.openLinkDialog()}),r.querySelector("[data-richclay-link-remove]")?.addEventListener("click",()=>{let h=this.anchor;this.hide(),t.removeLinkElement(h),t.focus()});let o=t.element.closest("dialog")||n.body,s=typeof r.showPopover=="function";s&&r.setAttribute("popover","manual"),Q(r,"position","fixed"),Q(r,"inset","0px auto auto 0px"),Q(r,"margin","0"),Q(r,"overflow","visible"),o.appendChild(r),s&&r.showPopover(),this.root=r;let a=()=>this.position(),l=h=>{h.key!=="Escape"||!this.root||(this.dismissed=this.anchor,this.hide())};n.addEventListener("scroll",a,{capture:!0,passive:!0}),i.addEventListener("resize",a,{passive:!0}),t.element.addEventListener("keydown",l),this.cleanup=()=>{n.removeEventListener("scroll",a,{capture:!0}),i.removeEventListener("resize",a),t.element.removeEventListener("keydown",l)}}position(){let t=this.root;if(!t||!this.anchor)return;let n=t.ownerDocument.defaultView||globalThis,i=on({anchor:this.anchor.getBoundingClientRect(),box:{width:t.offsetWidth||0,height:t.offsetHeight||0},viewport:{width:n.visualViewport?.width??n.innerWidth,height:n.visualViewport?.height??n.innerHeight}});t.setAttribute("data-richclay-side",i.side),t.style.setProperty("--richclay-dialog-arrow",`${Math.round(i.arrow)}px`),Q(t,"transform",`translate(${Math.round(i.x)}px, ${Math.round(i.y)}px)`)}scheduleHide(){if(!this.root||this.hideTimer!==null)return;let t=this.root.ownerDocument.defaultView||globalThis;this.hideTimer=t.setTimeout(()=>{this.hideTimer=null,this.pointerInside||this.hide()},vl)}cancelHide(){if(this.hideTimer===null)return;(this.editor.element.ownerDocument.defaultView||globalThis).clearTimeout(this.hideTimer),this.hideTimer=null}onEditorBlur(t){let n=t?.relatedTarget;n&&this.editor.ownsFocusTarget(n)||this.hide()}hide(){this.cancelHide(),this.cleanup?.(),this.cleanup=null,this.root?.remove(),this.root=null,this.anchor=null,this.href=null,this.pointerInside=!1}destroy(){this.hide(),this.dismissed=null}};var vo="richclay-styles",gi=new WeakSet,yi="";function So(e){yi=e||""}function Ao(e=document){if(!e||gi.has(e))return;if(e.getElementById(vo)){gi.add(e);return}if(!yi)return;let t=e.createElement("style");t.id=vo,t.setAttribute("save-remove",""),t.setAttribute("save-ignore",""),t.textContent=yi,(e.head||e.documentElement).appendChild(t),gi.add(e)}var ln=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"]})}),Al=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),bc=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);function wt(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 bi(e,t){if(wt(e,t))return!0;for(let[n,i]of Object.entries(Al))if(i.includes(t)&&wt(e,n))return!0;return!1}function Nt(e){let t=ln[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function cn(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let i=ln[t];if(!i)throw new Error(`Unknown region capability: ${t}`);if(i.tokens.some(r=>bi(n,r))||i.bundles.some(r=>wt(n,r)))return n;n=n.parentElement}return null}function Co(e,t){return!!cn(e,t)}var Cl=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function Ll(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 Lo(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 wo(e,t,n,i,r,o){return(o?Co(e,t):Lo(e,n,r,!1))||!!(i&&(o&&e!==r?e.matches(i):Lo(e,i,r,o)))}function wl(e,t){let n=ln[t];return n.tokens.some(i=>bi(e,i))||n.bundles.some(i=>wt(e,i))}var Nl=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function No(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(Nl.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 s=o.firstChild;for(let a=r.firstChild;a&&s;a=a.nextSibling)No(a,s,n,i),s=s.nextSibling}function Ti(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 s=o.implementation.createHTMLDocument(""),a=r||new WeakMap,l=new WeakMap,h=e.nodeType===9?e.documentElement:e;n&&s.documentElement.matches(n);let d=Nt(t),u=i?y=>wl(y,t)||!!(n&&y.matches(n)):y=>wo(y,t,d,n,h,!1),p=null;if(h.nodeType!==1||!wo(h,t,d,n,h,i)){p=s.importNode(h,!0);let y={cloneToLive:a,liveToClone:l,dropped:[],controls:[]};No(h,p,y,u);for(let E of y.dropped)E.remove();for(let E=0;E<y.controls.length;E+=2)Ll(y.controls[E],y.controls[E+1])}e.nodeType===9&&p&&(s.replaceChild(p,s.documentElement),l.set(e,s),a.set(s,e));let b=y=>{if(Cl.test(y))throw new Error(`Filtered content queries do not support stateful selector: ${y}`)};return{root:p,document:s,capability:t,selector:Nt(t),cloneToLive:a,liveToClone:l,original(y){return a.get(y)||null},cloneOf(y){return l.get(y)||null},query(y,E=p){return b(y),Array.from(E.querySelectorAll(y),S=>a.get(S)||S)},text(y=p){return(y===p?p:l.get(y))?.textContent||""},html(y=p){return(y===p?p:l.get(y))?.innerHTML??""},clone(y=p){let E=y===p?p:l.get(y);return E?s.importNode(E,!0):null}}}var xl=Nt("history");function Mo(e,t){let n=t.createElement("template");n.innerHTML=String(e||"");for(let i of n.content.querySelectorAll(xl))i.remove();return n.innerHTML}function Po(e,t){return Mo(e,t)}function kl(e,t){let n=t.createElement("template");n.innerHTML=Po(e,t);let i=new Set(["ADDRESS","ARTICLE","ASIDE","BLOCKQUOTE","DIV","DL","FIELDSET","FIGCAPTION","FIGURE","FOOTER","FORM","H1","H2","H3","H4","H5","H6","HEADER","HR","LI","MAIN","NAV","OL","P","PRE","SECTION","TABLE","UL"]),r="",o=s=>{if(s.nodeType===3)r+=s.data;else if(s.nodeType===1&&s.tagName==="BR")r+=`
28
+ `,t.options.linkLabel&&r.querySelector("[data-richclay-link-remove]").remove(),r.addEventListener("pointerdown",Lt),r.addEventListener("pointerenter",()=>{this.pointerInside=!0,this.cancelHide()}),r.addEventListener("pointerleave",()=>{this.pointerInside=!1,this.update()}),r.querySelector("[data-richclay-link-edit]").addEventListener("click",()=>{let h=this.anchor;if(!h||!t.element.contains(h))return this.hide();t.selectElement(h),t.openLinkDialog()}),r.querySelector("[data-richclay-link-remove]")?.addEventListener("click",()=>{let h=this.anchor;this.hide(),t.removeLinkElement(h),t.focus()});let o=t.element.closest("dialog")||n.body,s=typeof r.showPopover=="function";s&&r.setAttribute("popover","manual"),Q(r,"position","fixed"),Q(r,"inset","0px auto auto 0px"),Q(r,"margin","0"),Q(r,"overflow","visible"),o.appendChild(r),s&&r.showPopover(),this.root=r;let a=()=>this.position(),l=h=>{h.key!=="Escape"||!this.root||(this.dismissed=this.anchor,this.hide())};n.addEventListener("scroll",a,{capture:!0,passive:!0}),i.addEventListener("resize",a,{passive:!0}),t.element.addEventListener("keydown",l),this.cleanup=()=>{n.removeEventListener("scroll",a,{capture:!0}),i.removeEventListener("resize",a),t.element.removeEventListener("keydown",l)}}position(){let t=this.root;if(!t||!this.anchor)return;let n=t.ownerDocument.defaultView||globalThis,i=an({anchor:this.anchor.getBoundingClientRect(),box:{width:t.offsetWidth||0,height:t.offsetHeight||0},viewport:{width:n.visualViewport?.width??n.innerWidth,height:n.visualViewport?.height??n.innerHeight}});t.setAttribute("data-richclay-side",i.side),t.style.setProperty("--richclay-dialog-arrow",`${Math.round(i.arrow)}px`),Q(t,"transform",`translate(${Math.round(i.x)}px, ${Math.round(i.y)}px)`)}scheduleHide(){if(!this.root||this.hideTimer!==null)return;let t=this.root.ownerDocument.defaultView||globalThis;this.hideTimer=t.setTimeout(()=>{this.hideTimer=null,this.pointerInside||this.hide()},vl)}cancelHide(){if(this.hideTimer===null)return;(this.editor.element.ownerDocument.defaultView||globalThis).clearTimeout(this.hideTimer),this.hideTimer=null}onEditorBlur(t){let n=t?.relatedTarget;n&&this.editor.ownsFocusTarget(n)||this.hide()}hide(){this.cancelHide(),this.cleanup?.(),this.cleanup=null,this.root?.remove(),this.root=null,this.anchor=null,this.href=null,this.pointerInside=!1}destroy(){this.hide(),this.dismissed=null}};var vo="richclay-styles",bi=new WeakSet,Ti="";function So(e){Ti=e||""}function Ao(e=document){if(!e||bi.has(e))return;if(e.getElementById(vo)){bi.add(e);return}if(!Ti)return;let t=e.createElement("style");t.id=vo,t.setAttribute("save-remove",""),t.setAttribute("save-ignore",""),t.textContent=Ti,(e.head||e.documentElement).appendChild(t),bi.add(e)}var un=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"]})}),Al=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),bc=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);function wt(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 _i(e,t){if(wt(e,t))return!0;for(let[n,i]of Object.entries(Al))if(i.includes(t)&&wt(e,n))return!0;return!1}function Nt(e){let t=un[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function dn(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let i=un[t];if(!i)throw new Error(`Unknown region capability: ${t}`);if(i.tokens.some(r=>_i(n,r))||i.bundles.some(r=>wt(n,r)))return n;n=n.parentElement}return null}function Co(e,t){return!!dn(e,t)}var Cl=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function Ll(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 Lo(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 wo(e,t,n,i,r,o){return(o?Co(e,t):Lo(e,n,r,!1))||!!(i&&(o&&e!==r?e.matches(i):Lo(e,i,r,o)))}function wl(e,t){let n=un[t];return n.tokens.some(i=>_i(e,i))||n.bundles.some(i=>wt(e,i))}var Nl=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function No(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(Nl.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 s=o.firstChild;for(let a=r.firstChild;a&&s;a=a.nextSibling)No(a,s,n,i),s=s.nextSibling}function Ei(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 s=o.implementation.createHTMLDocument(""),a=r||new WeakMap,l=new WeakMap,h=e.nodeType===9?e.documentElement:e;n&&s.documentElement.matches(n);let d=Nt(t),u=i?y=>wl(y,t)||!!(n&&y.matches(n)):y=>wo(y,t,d,n,h,!1),p=null;if(h.nodeType!==1||!wo(h,t,d,n,h,i)){p=s.importNode(h,!0);let y={cloneToLive:a,liveToClone:l,dropped:[],controls:[]};No(h,p,y,u);for(let E of y.dropped)E.remove();for(let E=0;E<y.controls.length;E+=2)Ll(y.controls[E],y.controls[E+1])}e.nodeType===9&&p&&(s.replaceChild(p,s.documentElement),l.set(e,s),a.set(s,e));let b=y=>{if(Cl.test(y))throw new Error(`Filtered content queries do not support stateful selector: ${y}`)};return{root:p,document:s,capability:t,selector:Nt(t),cloneToLive:a,liveToClone:l,original(y){return a.get(y)||null},cloneOf(y){return l.get(y)||null},query(y,E=p){return b(y),Array.from(E.querySelectorAll(y),S=>a.get(S)||S)},text(y=p){return(y===p?p:l.get(y))?.textContent||""},html(y=p){return(y===p?p:l.get(y))?.innerHTML??""},clone(y=p){let E=y===p?p:l.get(y);return E?s.importNode(E,!0):null}}}var xl=Nt("history");function Io(e,t){let n=t.createElement("template");n.innerHTML=String(e||"");for(let i of n.content.querySelectorAll(xl))i.remove();return n.innerHTML}function Po(e,t){return Io(e,t)}function kl(e,t){let n=t.createElement("template");n.innerHTML=Po(e,t);let i=new Set(["ADDRESS","ARTICLE","ASIDE","BLOCKQUOTE","DIV","DL","FIELDSET","FIGCAPTION","FIGURE","FOOTER","FORM","H1","H2","H3","H4","H5","H6","HEADER","HR","LI","MAIN","NAV","OL","P","PRE","SECTION","TABLE","UL"]),r="",o=s=>{if(s.nodeType===3)r+=s.data;else if(s.nodeType===1&&s.tagName==="BR")r+=`
29
29
  `;else{let a=s.nodeType===1&&i.has(s.tagName);a&&r&&!r.endsWith(`
30
30
  `)&&(r+=`
31
31
  `);for(let l of s.childNodes||[])o(l);a&&r&&!r.endsWith(`
32
32
  `)&&(r+=`
33
33
  `)}};return o(n.content),r.replace(/\n{3,}/g,`
34
34
 
35
- `).replace(/^\n|\n$/g,"")}function Rl(e,t,n=null){let i=Ti(e,{capability:"history",inherit:!1}),r=i.root,o=(a,l)=>{for(;a&&!i.cloneOf(a);){let u=a.parentNode;if(!u)return{container:r,offset:0};l=Array.from(u.childNodes).indexOf(a),a=u}let h=i.cloneOf(a)||r;if(a?.nodeType===3)return{container:h,offset:Math.min(l,h.length)};let d=Array.from(a?.childNodes||[]).slice(0,l).filter(u=>i.cloneOf(u)).length;return{container:h,offset:Math.min(d,h.childNodes.length)}},s=(a,l,h)=>{let d=o(l,h),u=r.ownerDocument.createElement("input");u.id=a,u.type="hidden";let p=r.ownerDocument.createRange();p.setStart(d.container,d.offset),p.collapse(!0),p.insertNode(u)};if(n)s(t.endSelectionId,n.endContainer,n.endOffset),s(t.startSelectionId,n.startContainer,n.startOffset);else for(let a of[t.startSelectionId,t.endSelectionId]){if(r.querySelector(`#${a}`))continue;let l=e.querySelector(`#${a}`);l&&s(a,l.parentNode,Array.from(l.parentNode.childNodes).indexOf(l))}return r.innerHTML}var Ae=new WeakMap,xo=new WeakMap,hn=new WeakMap,_i=zr(),ko=Symbol("richclay-keep-focus"),Ro=["cut","paste","drop"],Ol=["Alt","Ctrl","Meta","Shift"],Oo=0;function Dl(e){return typeof e.clay?.mode=="string"}var Il={toolbar:"standard",toolbarContainer:null,sanitize:{},placeholder:"",readOnly:!1,hyperclay:"auto",onChange:null,Squire:null,inline:!1,singleLine:!1,toolbarOnSelect:!1,linkPopover:!0,linkLabel:!1},Do=["link","undo","redo"],$e=class e{static presets=Et;static selector=de;constructor(t,n={}){if(!t)throw new Error("RichClay requires an element.");let i=Ae.get(t);if(i)return i;this.element=t,this.unsupported=Ei(t)||Bl(t);let r={...lo(t),...n};this.options={...Il,...r},this.options.singleLine&&!("toolbar"in r)&&(this.options.toolbar="inline"),this._blockTag=this.options.inline?"DIV":"P",this.registry=new Map(_i),this.toolbar=null,this.float=null,this._onToolbarKey=null,this._onFloatFocusOut=null,this._onDocPointerDown=null,this.liveRegion=null,this.description=null,this.dialog=null,this.dialogCleanup=null,this.linkPopover=null,this.savedSelection=null,this.path="",this.active=!1,this._squire=null,this._squireListeners=[],this._onBeforeInput=null,this._onRootBeforeInput=null,this._onRootKeydown=null,this._onRootTransfer=null,this._shortcutKeys=[],this._appleDeleteKeys=new Set,this._authoredPres=new WeakSet,this._warnedInlineBlock=!1,this._onFocus=()=>{this.element.classList.add("richclay-focused"),this.options.inline&&this.ensureFloatingToolbar()},this._onBlur=o=>{this.element.classList.remove("richclay-focused"),this.linkPopover?.onEditorBlur(o),this.options.inline&&this.scheduleFloatTeardown(o)},this._onLinkActivation=o=>{if(!this.active||this.options.readOnly)return;let s=o.target?.nodeType===1?o.target:o.target?.parentElement,a=s?.closest("a[href]");if(!a)return;let l=cn(s,"history");l&&l!==this.element&&this.element.contains(l)&&l.contains(a)||o.preventDefault()},this._onExternalWrite=()=>{this._squire&&(this._squire._mutation?.takeRecords(),this.options.linkLabel&&(this._labelHref=this.element.querySelector("a[href]")?.getAttribute("href")??this._labelHref),this.resetSquireUndoBaseline(),this.updatePlaceholder())},this.ensureMarker(),this.hyperclay=Jt(this.options,this.window),this.hyperclay&&ai(this.window),Ae.set(t,this),this.sanitizeConfig=this.options.inline?_o(this.options.sanitize):this.options.sanitize,this.sanitizer=bo(this.sanitizeConfig,this.element.ownerDocument),this.options.inline||di(this.element,this.sanitizeConfig),ao(this.options,this.window)&&this.activate()}get squire(){return this._squire}get window(){return this.element.ownerDocument.defaultView||window}static init(t=de,n={}){let i=t===de?oi:()=>!0;return Ml(t).filter(i).filter(o=>!Ei(o)).map(o=>new e(o,n))}static autoInit(t=typeof window<"u"?window:void 0){if(!t||!t.document)return()=>{};let n=xo.get(t);if(n)return n;let i=!1,r=null,o=()=>{i||Dl(t)||Jt({},t)&&si(t)&&(e.init(),r=e.watch(t))},s=()=>{i=!0,r?.()};return xo.set(t,s),t.document.readyState==="loading"?t.document.addEventListener("DOMContentLoaded",o,{once:!0}):o(),s}static watch(t=typeof window<"u"?window:void 0,n={}){if(!t||!t.document)return()=>{};let i=hn.get(t);if(i)return i;let r=h=>{xt(h)&&!Ae.has(h)&&!Ei(h)&&new e(h,n)},o=h=>Ae.get(h)?.destroy(),s=new t.MutationObserver(h=>{h.forEach(d=>{if(d.type==="attributes"){let u=d.target;xt(u)?r(u):o(u);return}d.addedNodes.forEach(u=>{u.nodeType===1&&(u.matches?.(de)&&r(u),u.querySelectorAll?.(de).forEach(r))}),d.removedNodes.forEach(u=>{if(u.nodeType!==1)return;let p=b=>{b.isConnected||Ae.get(b)?.destroy()};u.matches?.(de)&&p(u),u.querySelectorAll?.(de).forEach(p)})})}),a=!1,l=()=>{a||(a=!0,s.disconnect(),hn.get(t)===l&&hn.delete(t))};return s.observe(t.document.documentElement||t.document,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["editable","clay-editable","data-richclay","richclay"]}),hn.set(t,l),l}static registerButton(t){return vi(t),_i.set(t.id,t),e}static unregisterButton(t){return _i.delete(t),e}static stripFromClone(t){li(t)}static stripElement(t){if(!t||typeof t.getAttribute!="function")return;let n=Ae.get(t);if(n){n.destroy();return}en(t,"destroy")}registerButton(t){return vi(t),this.registry.set(t.id,t),this.active&&this.renderToolbar(),this}unregisterButton(t){return this.registry.delete(t),this.active&&this.renderToolbar(),this}activate(){if(this.unsupported||this.active)return;this.active=!0,this.applyInlineBox(),Ao(this.element.ownerDocument),ci(this.element);let t=this.options.inline?Array.from(this.element.childNodes):null,n=this.options.inline?null:this.element.innerHTML,i=this.options.Squire||this.window.Squire||globalThis.Squire;if(!i)throw new Error("RichClay requires Squire. Load vendor/squire.js before richclay.js.");if(this.setupEditorAttributes(),this.liveRegion=ho(this.element.ownerDocument),this._squire=new i(this.element,{blockTag:this._blockTag,serializeRoot:Rl,willCutCopy:r=>Po(r,this.element.ownerDocument),toPlainText:r=>kl(r,this.element.ownerDocument),replaceRoot:(r,o,s)=>{let a=this.window.clay?.morph||this.window.hyperclay?.morph;if(typeof a!="function"){if(r.querySelector('[editor-ui], [clay~="editor-ui"]'))throw new Error("RichClay requires a retention-aware morph host to replay history containing editor-ui.");r.innerHTML=o;return}a(r,o,{morphStyle:"innerHTML",restoreFocus:!1,scripts:{handle:!1,merge:!1},policy:"history"}),s._ensureBottomLine(),s._mutation?.takeRecords()},onMutations:(r,o)=>{let s=(h,d)=>{let u=cn(h,d);return!!u&&u!==this.element&&this.element.contains(u)},a=!1,l=!1;for(let h of r){if(s(h.target,"history"))continue;let d=h.type==="childList"?[...h.addedNodes,...h.removedNodes]:[h.target];for(let u of d)s(u,"history")||(s(h.target,"undo")||s(u,"undo")?l=!0:a=!0)}if(a){let h=o._ignoreChange;o._docWasChanged(),l&&h&&o.fireEvent("input"),this.options.linkLabel&&this.keepOneLink()}else l?(o._mayHaveZWS=!0,o.fireEvent("input")):o._ignoreChange=!1},sanitizeToDOMFragment:(r,o)=>{let s=this.sanitizer.sanitizeToDOMFragment(Mo(r,this.element.ownerDocument),o);return this.options.singleLine?Eo(s):s},didError:r=>{console.error("RichClay/Squire error",r)}}),this.options.inline?(this.element.replaceChildren(...t),this.resetSquireUndoBaseline()):this._squire.setHTML(n),this.bindSquire(),this.options.singleLine&&this.installSingleLineGuards(),this.options.inline&&!this.options.singleLine&&this.installRootGuards(),this.installAppleDeleteKeys(),this.blocksStayOut()&&(this._squire._ensureBottomLine=()=>{}),this.maskSquireCodeShortcut(),this.maskSquireBlockShortcuts(),this.installShortcuts(),this.options.linkLabel&&this.maskFormattingShortcuts(),this.options.inline&&(this._onToolbarKey=r=>{r.altKey&&r.key==="F10"&&(r.preventDefault(),this.ensureFloatingToolbar(),this.float?.toolbar.focusFirst())},this.element.addEventListener("keydown",this._onToolbarKey)),this.blocksStayOut()){let r=o=>{let s=o.detail?.fragment;if(!s)return;let a=this.element.ownerDocument;Ct(s,()=>this.options.singleLine?a.createTextNode(" "):a.createElement("br"))};this._squire.addEventListener("willPaste",r),this._squireListeners.push(["willPaste",r])}if(this.options.linkLabel){let r=o=>{let s=o.detail?.fragment;if(!s)return;let a=s.textContent.replace(/\s+/g," ");s.replaceChildren(this.element.ownerDocument.createTextNode(a))};this._squire.addEventListener("willPaste",r),this._squireListeners.push(["willPaste",r]),this._labelHref=this.element.querySelector("a[href]")?.getAttribute("href")??null}this.renderToolbar(),this.updatePlaceholder(),this.warnOnBlockInInlineRegion(),this.element.querySelectorAll("pre").forEach(r=>this._authoredPres.add(r))}reattach(){return this.unsupported||!this.active||this.element.getAttribute("contenteditable")==="true"&&this.element.getAttribute("data-richclay-active")==="true"&&xt(this.element)?!1:(this.ensureMarker(),this.applyInlineBox(),ci(this.element),this.setupEditorAttributes(),!0)}applyInlineBox(){Xt(this.element)&&!this.element.style.display&&(this.element.style.display="inline-block",this.element.setAttribute("data-richclay-runtime-display","true"))}getHTML(){return this._squire?this._squire.getHTML():this.element.innerHTML}setHTML(t){return this._squire?this._squire.setHTML(String(t||"")):this.element.innerHTML=ui(t,this.sanitizeConfig,this.element.ownerDocument),this.updatePlaceholder(),this.toolbar?.update(),this.options.onChange?.(this.getHTML()),this}focus(){return this._squire?this._squire.focus():this.element.focus(),this}destroy(){this.closeLinkDialog(),this.linkPopover?.destroy(),this.linkPopover=null,this.teardownFloatingToolbar(),this.toolbar?.destroy(),this.toolbar=null,this._onToolbarKey&&(this.element.removeEventListener("keydown",this._onToolbarKey),this._onToolbarKey=null),this.liveRegion?.remove(),this.liveRegion=null,this.description?.remove(),this.description=null,this._shortcutKeys.forEach(n=>this._squire?.setKeyHandler?.(n,null)),this._squireListeners.forEach(([n,i])=>{this._squire?.removeEventListener?.(n,i)}),this._squireListeners=[],this._shortcutKeys=[],this._onBeforeInput&&(this.element.ownerDocument.removeEventListener("beforeinput",this._onBeforeInput,!0),this._onBeforeInput=null);let t=this.element.ownerDocument;this._onRootBeforeInput&&(t.removeEventListener("beforeinput",this._onRootBeforeInput,!0),this._onRootBeforeInput=null),this._onRootKeydown&&(t.removeEventListener("keydown",this._onRootKeydown,!0),this._onRootKeydown=null),this._onRootTransfer&&(Ro.forEach(n=>t.removeEventListener(n,this._onRootTransfer,!0)),this._onRootTransfer=null),this._squire?.destroy?.(),this._squire=null,this.cleanupEditorAttributes(),Ae.delete(this.element)}saveSelection(){return this.savedSelection=ot(this._squire)||this.savedSelection,this.savedSelection}restoreSelection(){return tn(this._squire,this.savedSelection)}installRootGuards(){let t=this.element.ownerDocument,n=i=>this.element.contains(i.target);this._onRootBeforeInput=i=>{!n(i)||i.isComposing||/^history/.test(i.inputType||"")||this.ensureRootIsEditable()},this._onRootKeydown=i=>{!n(i)||i.defaultPrevented||i.isComposing||this.isEditingKey(i)&&this.ensureRootIsEditable()},this._onRootTransfer=i=>{n(i)&&this.ensureRootIsEditable()},t.addEventListener("beforeinput",this._onRootBeforeInput,!0),t.addEventListener("keydown",this._onRootKeydown,!0),Ro.forEach(i=>{t.addEventListener(i,this._onRootTransfer,!0)})}ensureRootIsEditable(){if(!this._squire||this.options.singleLine)return;let t=this.options.inline,n=!this.blocksStayOut();if(!Qr(this.element,{wrapBareRoot:t,blocksAllowed:n}))return;let i=ot(this._squire),r=i?to(this.element,i):null,o=()=>{Xr(this.element,{blockTag:this._blockTag,wrapBareRoot:t,blocksAllowed:n,onBareRootWrapped:(s,a)=>{console.warn(`richclay: wrapped this region's loose text in a <div> so multi-line editing works. Wrap the content in your own block element to keep the markup you wrote, or use editable="single-line" if it is meant to be one line.`,s,a)}})};typeof this._squire.modifyDocument=="function"?this._squire.modifyDocument(o):o(),r&&(no(this.element,i,r),tn(this._squire,i),this.savedSelection=hi(i))}isEditingKey(t){return["Backspace","Delete","Enter"].includes(t.key)?!0:t.key==="Tab"?this.caretIsInList():t.key.length!==1?!1:!t.ctrlKey&&!t.metaKey&&!t.altKey?!0:t.ctrlKey&&!t.metaKey&&!t.altKey&&this._appleDeleteKeys.has(t.key.toLowerCase())}caretIsInList(){let n=this._squire?.getSelection()?.startContainer;if(!n)return!1;let i=n.nodeType===1?n:n.parentElement;return!!(i&&this.element.contains(i)&&i.closest("ul, ol"))}runControl(t){if(!this._squire||typeof t.run!="function"||t.isDisabled?.(this))return;this.restoreSelection(),t.mutates!==!1&&this.ensureRootIsEditable();let n=t.run(this);this.element.querySelectorAll("pre:not([data-richclay-pre])").forEach(i=>{this._authoredPres.has(i)||i.setAttribute("data-richclay-pre","")}),t.mutates!==!1&&(this.ensureRootIsEditable(),this.anchorSelectionInBlock()),this.saveSelection(),this.toolbar?.update(),this.updatePlaceholder(),this.announceControl(t),n!==ko&&this.focus(),this.warnOnBlockInInlineRegion()}anchorSelectionInBlock(){let t=ot(this._squire);if(!t?.collapsed||t.startContainer!==this.element)return;let n=Array.from(this.element.childNodes),i=t.startOffset>=n.length,r=i?n.filter(it).pop():n.slice(t.startOffset).find(it)||n.slice(0,t.startOffset).filter(it).pop();if(!r)return;let o=vt(r,!i);t.setStart(o,i?Gt(o):0),t.collapse(!0),tn(this._squire,t)}selectionHasFormat(t){if(!t||!this._squire?.hasFormat)return!1;try{return this._squire.hasFormat(t)}catch{return!1}}pathHas(t){let n=ot(this._squire);if(!n)return!1;let i=t.toLowerCase(),r=Io(this.element,n.startContainer,n.startOffset,!0,i);return!!r&&r===Io(this.element,n.endContainer,n.endOffset,!1,i)}blocksStayOut(){return this.options.singleLine||Yt(this.element)||Vr(this.element)}warnOnBlockInInlineRegion(){if(this._warnedInlineBlock||!Xt(this.element)||!Qt(this.element))return;this._warnedInlineBlock=!0;let t=this.element.nodeName.toLowerCase();console.warn(`richclay: a block element inside <${t} editable> is not valid HTML. It stays where it is and saves correctly, but a validator will flag it. Put the editable attribute on a block element if you want blocks here.`,this.element)}toggleFormat(t,n,i){return this.selectionHasFormat(t)?this._squire[i]():this._squire[n]()}toggleList(t){return this.pathHas(t)?this._squire.removeList():t==="UL"?this._squire.makeUnorderedList():this._squire.makeOrderedList()}indent(){return this.pathHas("UL")||this.pathHas("OL")?this._squire.increaseListLevel():this._squire.increaseQuoteLevel()}outdent(){return this.pathHas("UL")||this.pathHas("OL")?this._squire.decreaseListLevel():this._squire.decreaseQuoteLevel()}setBlockType(t){let n=t.toUpperCase();return n==="BLOCKQUOTE"?this._squire.increaseQuoteLevel():this._squire.modifyBlocks(i=>{let r=this.element.ownerDocument,o=r.createDocumentFragment();return Array.from(i.childNodes).forEach(s=>{if(s.nodeType!==1){o.appendChild(s);return}if(s.nodeName===n){o.appendChild(s);return}let a=r.createElement(n);for(;s.firstChild;)a.appendChild(s.firstChild);o.appendChild(a)}),o})}openLinkDialog(){this.saveSelection(),this.closeLinkDialog(),this.linkPopover?.hide();let t=this.element.ownerDocument,n=this.currentLinkElement(),i=n?.getAttribute("href")||"",r=t.createElement("form"),o=`richclay-link-label-${++Oo}`;r.className="richclay-dialog",r.setAttribute("role","dialog"),r.setAttribute("aria-modal","true"),r.setAttribute("aria-labelledby",o),r.setAttribute("data-richclay-dialog",""),ce(r),r.setAttribute("save-remove",""),r.innerHTML=`
35
+ `).replace(/^\n|\n$/g,"")}function Rl(e,t,n=null){let i=Ei(e,{capability:"history",inherit:!1}),r=i.root,o=(a,l)=>{for(;a&&!i.cloneOf(a);){let u=a.parentNode;if(!u)return{container:r,offset:0};l=Array.from(u.childNodes).indexOf(a),a=u}let h=i.cloneOf(a)||r;if(a?.nodeType===3)return{container:h,offset:Math.min(l,h.length)};let d=Array.from(a?.childNodes||[]).slice(0,l).filter(u=>i.cloneOf(u)).length;return{container:h,offset:Math.min(d,h.childNodes.length)}},s=(a,l,h)=>{let d=o(l,h),u=r.ownerDocument.createElement("input");u.id=a,u.type="hidden";let p=r.ownerDocument.createRange();p.setStart(d.container,d.offset),p.collapse(!0),p.insertNode(u)};if(n)s(t.endSelectionId,n.endContainer,n.endOffset),s(t.startSelectionId,n.startContainer,n.startOffset);else for(let a of[t.startSelectionId,t.endSelectionId]){if(r.querySelector(`#${a}`))continue;let l=e.querySelector(`#${a}`);l&&s(a,l.parentNode,Array.from(l.parentNode.childNodes).indexOf(l))}return r.innerHTML}var Te=new WeakMap,xo=new WeakMap,fn=new WeakMap,vi=Wr(),ko=Symbol("richclay-keep-focus"),Ro=["cut","paste","drop"],Ol=["Alt","Ctrl","Meta","Shift"],Oo=0;function Dl(e){return typeof e.clay?.mode=="string"}var Ml={toolbar:"standard",toolbarContainer:null,sanitize:{},placeholder:"",readOnly:!1,hyperclay:"auto",onChange:null,Squire:null,inline:!1,singleLine:!1,toolbarOnSelect:!1,linkPopover:!0,linkLabel:!1},Do=["link","undo","redo"],$e=class e{static presets=Et;static selector=ce;static hostHistory=!1;static keepsOwnHistory=null;constructor(t,n={}){if(!t)throw new Error("RichClay requires an element.");let i=Te.get(t);if(i)return i;this.element=t,this.unsupported=Si(t)||Bl(t);let r={...ho(t),...n};this.options={...Ml,...r},this.options.singleLine&&!("toolbar"in r)&&(this.options.toolbar="inline"),this._blockTag=this.options.inline?"DIV":"P",this.registry=new Map(vi),this.toolbar=null,this.float=null,this._onToolbarKey=null,this._onFloatFocusOut=null,this._onDocPointerDown=null,this.liveRegion=null,this.description=null,this.dialog=null,this.dialogCleanup=null,this.linkPopover=null,this.savedSelection=null,this.path="",this.active=!1,this._squire=null,this._squireHTML=null,this._squireListeners=[],this._onBeforeInput=null,this._onHistoryInput=null,this._onRootBeforeInput=null,this._onRootKeydown=null,this._onRootTransfer=null,this._shortcutKeys=[],this._appleDeleteKeys=new Set,this._authoredPres=new WeakSet,this._warnedInlineBlock=!1,this._onFocus=()=>{this.element.classList.add("richclay-focused"),this.options.inline&&this.ensureFloatingToolbar()},this._onBlur=o=>{this.element.classList.remove("richclay-focused"),this.linkPopover?.onEditorBlur(o),this.options.inline&&this.scheduleFloatTeardown(o)},this._onLinkActivation=o=>{if(!this.active||this.options.readOnly)return;let s=o.target?.nodeType===1?o.target:o.target?.parentElement,a=s?.closest("a[href]");if(!a)return;let l=dn(s,"history");l&&l!==this.element&&this.element.contains(l)&&l.contains(a)||o.preventDefault()},this._onExternalWrite=()=>{this._squire&&(this._squire._mutation?.takeRecords(),this.options.linkLabel&&(this._labelHref=this.element.querySelector("a[href]")?.getAttribute("href")??this._labelHref),this.resetSquireUndoBaseline(),this.updatePlaceholder())},this.ensureMarker(),this.hyperclay=en(this.options,this.window),this.hyperclay&&ci(this.window),Te.set(t,this),this.sanitizeConfig=this.options.inline?cn(this.options.sanitize):this.options.sanitize,this.sanitizer=di(this.sanitizeConfig,this.element.ownerDocument),this.options.inline||pi(this.element,cn(this.options.sanitize)),co(this.options,this.window)&&this.activate()}get squire(){return this._squire}get window(){return this.element.ownerDocument.defaultView||window}static init(t=ce,n={}){let i=t===ce?Jt:()=>!0;return Il(t).filter(i).filter(o=>!Si(o)).map(o=>new e(o,n))}static autoInit(t=typeof window<"u"?window:void 0){if(!t||!t.document)return()=>{};let n=xo.get(t);if(n)return n;let i=!1,r=null,o=()=>{i||Dl(t)||en({},t)&&li(t)&&(e.init(),r=e.watch(t))},s=()=>{i=!0,r?.()};return xo.set(t,s),t.document.readyState==="loading"?t.document.addEventListener("DOMContentLoaded",o,{once:!0}):o(),s}static watch(t=typeof window<"u"?window:void 0,n={}){if(!t||!t.document)return()=>{};let i=fn.get(t);if(i)return i;let r=h=>{xt(h)&&!Te.has(h)&&!Si(h)&&new e(h,n)},o=h=>Te.get(h)?.destroy(),s=new t.MutationObserver(h=>{h.forEach(d=>{if(d.type==="attributes"){let u=d.target;xt(u)?r(u):o(u);return}d.addedNodes.forEach(u=>{u.nodeType===1&&(u.matches?.(ce)&&r(u),u.querySelectorAll?.(ce).forEach(r))}),d.removedNodes.forEach(u=>{if(u.nodeType!==1)return;let p=b=>{b.isConnected||Te.get(b)?.destroy()};u.matches?.(ce)&&p(u),u.querySelectorAll?.(ce).forEach(p)})})}),a=!1,l=()=>{a||(a=!0,s.disconnect(),fn.get(t)===l&&fn.delete(t))};return s.observe(t.document.documentElement||t.document,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["editable","clay-editable","data-richclay","richclay"]}),fn.set(t,l),l}static registerButton(t){return Ai(t),vi.set(t.id,t),e}static unregisterButton(t){return vi.delete(t),e}static stripFromClone(t){tn(t)}static stripElement(t){if(!t||typeof t.getAttribute!="function")return;let n=Te.get(t);if(n){n.destroy();return}nn(t,"destroy")}static savedContent(t){if(!t||typeof t.matches!="function"||!t.matches(ce)||!Jt(t))return;let n=t.ownerDocument.createElement("div"),i=t.cloneNode(!0);return i.setAttribute("data-richclay-active","true"),n.append(i),tn(n),n.firstElementChild?n.firstElementChild.innerHTML:""}static setSavedContent(t,n,{morph:i}={}){if(typeof e.savedContent(t)!="string")return!1;let r=Te.get(t);return!r||!r.active?(t.innerHTML=n,!0):(r.replaceContent(n,i),r._onExternalWrite(),r.toolbar?.update(),!0)}registerButton(t){return Ai(t),this.registry.set(t.id,t),this.active&&this.renderToolbar(),this}unregisterButton(t){return this.registry.delete(t),this.active&&this.renderToolbar(),this}canHistory(t){let n=this._squire;return!n||e.hostHistory&&this.element.hasAttribute("data-richclay-runtime-no-undo")&&!e.keepsOwnHistory?.(this.element)?!1:t==="redo"?n._undoIndex+1<n._undoStackLength&&n._isInUndoState:n._undoIndex>0||!n._isInUndoState}history(t){return this.canHistory(t)?(t==="redo"?this._squire.redo():this._squire.undo(),this):(this.element.dispatchEvent(new this.window.CustomEvent("richclay:history-exhausted",{bubbles:!0,detail:{direction:t}})),this)}quiet(t){let n=this.window.clay?.Mutation;if(typeof n?.pause!="function"||typeof n?.resume!="function")return t();n.pause();try{return t()}finally{n.resume()}}activate(){return this.quiet(()=>this.activateNow())}destroy(){return this.quiet(()=>this.destroyNow())}reattach(){return this.quiet(()=>this.reattachNow())}activateNow(){if(this.unsupported||this.active)return;this.active=!0,this.applyInlineBox(),Ao(this.element.ownerDocument),hi(this.element);let t=this.options.inline?Array.from(this.element.childNodes):null,n=this.options.inline?null:this.element.innerHTML,i=this.options.Squire||this.window.Squire||globalThis.Squire;if(!i)throw new Error("RichClay requires Squire. Load vendor/squire.js before richclay.js.");if(this.setupEditorAttributes(),this.liveRegion=fo(this.element.ownerDocument),this._squire=new i(this.element,{blockTag:this._blockTag,serializeRoot:Rl,willCutCopy:r=>Po(r,this.element.ownerDocument),toPlainText:r=>kl(r,this.element.ownerDocument),replaceRoot:(r,o,s)=>{this.replaceContent(o)&&(s._ensureBottomLine(),s._mutation?.takeRecords())},onMutations:(r,o)=>{let s=(h,d)=>{let u=dn(h,d);return!!u&&u!==this.element&&this.element.contains(u)},a=!1,l=!1;for(let h of r){if(s(h.target,"history"))continue;let d=h.type==="childList"?[...h.addedNodes,...h.removedNodes]:[h.target];for(let u of d)s(u,"history")||(s(h.target,"undo")||s(u,"undo")?l=!0:a=!0)}if(a){let h=o._ignoreChange;o._docWasChanged(),l&&h&&o.fireEvent("input"),this.options.linkLabel&&this.keepOneLink()}else l?(o._mayHaveZWS=!0,o.fireEvent("input")):o._ignoreChange=!1},sanitizeToDOMFragment:(r,o)=>{let s=this.sanitizer.sanitizeToDOMFragment(Io(r,this.element.ownerDocument),o);return this.options.singleLine?Eo(s):s},didError:r=>{console.error("RichClay/Squire error",r)}}),this.options.inline)this.element.replaceChildren(...t),this.resetSquireUndoBaseline();else{let r=this.sanitizer;this.sanitizer=di(cn(this.options.sanitize),this.element.ownerDocument);try{this._squire.setHTML(n)}finally{this.sanitizer=r}}if(this.bindSquire(),this.options.singleLine&&this.installSingleLineGuards(),this.options.inline&&!this.options.singleLine&&this.installRootGuards(),this.installAppleDeleteKeys(),this.blocksStayOut()&&(this._squire._ensureBottomLine=()=>{}),this.maskSquireCodeShortcut(),this.maskSquireBlockShortcuts(),this.installShortcuts(),this._onHistoryInput=r=>{if(!this.element.contains(r.target)||r.inputType!=="historyUndo"&&r.inputType!=="historyRedo")return;let o=r.target;if(o!==this.element&&o.closest?.('input, textarea, select, [editor-ui], [clay~="editor-ui"]')){r.stopPropagation();return}r.preventDefault(),r.stopImmediatePropagation(),this.history(r.inputType==="historyRedo"?"redo":"undo")},this.element.ownerDocument.addEventListener("beforeinput",this._onHistoryInput,!0),this.options.linkLabel&&this.maskFormattingShortcuts(),this.options.inline&&(this._onToolbarKey=r=>{r.altKey&&r.key==="F10"&&(r.preventDefault(),this.ensureFloatingToolbar(),this.float?.toolbar.focusFirst())},this.element.addEventListener("keydown",this._onToolbarKey)),this.blocksStayOut()){let r=o=>{let s=o.detail?.fragment;if(!s)return;let a=this.element.ownerDocument;Ct(s,()=>this.options.singleLine?a.createTextNode(" "):a.createElement("br"))};this._squire.addEventListener("willPaste",r),this._squireListeners.push(["willPaste",r])}if(this.options.linkLabel){let r=o=>{let s=o.detail?.fragment;if(!s)return;let a=s.textContent.replace(/\s+/g," ");s.replaceChildren(this.element.ownerDocument.createTextNode(a))};this._squire.addEventListener("willPaste",r),this._squireListeners.push(["willPaste",r]),this._labelHref=this.element.querySelector("a[href]")?.getAttribute("href")??null}this.renderToolbar(),this.updatePlaceholder(),this.warnOnBlockInInlineRegion(),this.element.querySelectorAll("pre").forEach(r=>this._authoredPres.add(r)),this._squireHTML=this.element.innerHTML,this.element.dispatchEvent(new this.window.CustomEvent("richclay:mount",{bubbles:!0}))}reattachNow(){if(this.unsupported||!this.active)return!1;let t=this.element.getAttribute("contenteditable")==="true"&&this.element.getAttribute("data-richclay-active")==="true"&&xt(this.element);return t||(this.ensureMarker(),this.applyInlineBox(),hi(this.element),this.setupEditorAttributes()),this._squire&&this.element.innerHTML!==this._squireHTML&&this.resetSquireUndoBaseline(),!t}applyInlineBox(){Xt(this.element)&&!this.element.style.display&&(this.element.style.display="inline-block",this.element.setAttribute("data-richclay-runtime-display","true"))}replaceContent(t,n=this.window.clay?.morph||this.window.hyperclay?.morph){let i=this.element;if(typeof n!="function"){if(i.querySelector('[editor-ui], [clay~="editor-ui"]'))throw new Error("RichClay requires a retention-aware morph host to replay history containing editor-ui.");return i.innerHTML=t,!1}return n(i,t,{morphStyle:"innerHTML",restoreFocus:!1,scripts:{handle:!1,merge:!1},policy:"history"}),!0}getHTML(){return this._squire?this._squire.getHTML():this.element.innerHTML}setHTML(t){return this._squire?this._squire.setHTML(String(t||"")):this.element.innerHTML=fi(t,this.sanitizeConfig,this.element.ownerDocument),this.updatePlaceholder(),this.toolbar?.update(),this.options.onChange?.(this.getHTML()),this}focus(){return this._squire?this._squire.focus():this.element.focus(),this}destroyNow(){this.closeLinkDialog(),this.linkPopover?.destroy(),this.linkPopover=null,this.teardownFloatingToolbar(),this.toolbar?.destroy(),this.toolbar=null,this._onToolbarKey&&(this.element.removeEventListener("keydown",this._onToolbarKey),this._onToolbarKey=null),this.liveRegion?.remove(),this.liveRegion=null,this.description?.remove(),this.description=null,this._shortcutKeys.forEach(n=>this._squire?.setKeyHandler?.(n,null)),this._squireListeners.forEach(([n,i])=>{this._squire?.removeEventListener?.(n,i)}),this._squireListeners=[],this._shortcutKeys=[],this._onBeforeInput&&(this.element.ownerDocument.removeEventListener("beforeinput",this._onBeforeInput,!0),this._onBeforeInput=null),this._onHistoryInput&&(this.element.ownerDocument.removeEventListener("beforeinput",this._onHistoryInput,!0),this._onHistoryInput=null);let t=this.element.ownerDocument;this._onRootBeforeInput&&(t.removeEventListener("beforeinput",this._onRootBeforeInput,!0),this._onRootBeforeInput=null),this._onRootKeydown&&(t.removeEventListener("keydown",this._onRootKeydown,!0),this._onRootKeydown=null),this._onRootTransfer&&(Ro.forEach(n=>t.removeEventListener(n,this._onRootTransfer,!0)),this._onRootTransfer=null),this._squire?.destroy?.(),this._squire=null,this.cleanupEditorAttributes(),Te.delete(this.element)}saveSelection(){return this.savedSelection=ot(this._squire)||this.savedSelection,this.savedSelection}restoreSelection(){return rn(this._squire,this.savedSelection)}installRootGuards(){let t=this.element.ownerDocument,n=i=>this.element.contains(i.target);this._onRootBeforeInput=i=>{!n(i)||i.isComposing||/^history/.test(i.inputType||"")||this.ensureRootIsEditable()},this._onRootKeydown=i=>{!n(i)||i.defaultPrevented||i.isComposing||this.isEditingKey(i)&&this.ensureRootIsEditable()},this._onRootTransfer=i=>{n(i)&&this.ensureRootIsEditable()},t.addEventListener("beforeinput",this._onRootBeforeInput,!0),t.addEventListener("keydown",this._onRootKeydown,!0),Ro.forEach(i=>{t.addEventListener(i,this._onRootTransfer,!0)})}ensureRootIsEditable(){if(!this._squire||this.options.singleLine)return;let t=this.options.inline,n=!this.blocksStayOut();if(!eo(this.element,{wrapBareRoot:t,blocksAllowed:n}))return;let i=ot(this._squire),r=i?io(this.element,i):null,o=()=>{Jr(this.element,{blockTag:this._blockTag,wrapBareRoot:t,blocksAllowed:n,onBareRootWrapped:(s,a)=>{console.warn(`richclay: wrapped this region's loose text in a <div> so multi-line editing works. Wrap the content in your own block element to keep the markup you wrote, or use editable="single-line" if it is meant to be one line.`,s,a)}})};typeof this._squire.modifyDocument=="function"?this._squire.modifyDocument(o):o(),r&&(ro(this.element,i,r),rn(this._squire,i),this.savedSelection=ui(i))}isEditingKey(t){return["Backspace","Delete","Enter"].includes(t.key)?!0:t.key==="Tab"?this.caretIsInList():t.key.length!==1?!1:!t.ctrlKey&&!t.metaKey&&!t.altKey?!0:t.ctrlKey&&!t.metaKey&&!t.altKey&&this._appleDeleteKeys.has(t.key.toLowerCase())}caretIsInList(){let n=this._squire?.getSelection()?.startContainer;if(!n)return!1;let i=n.nodeType===1?n:n.parentElement;return!!(i&&this.element.contains(i)&&i.closest("ul, ol"))}runControl(t){if(!this._squire||typeof t.run!="function"||t.isDisabled?.(this))return;this.restoreSelection(),t.mutates!==!1&&this.ensureRootIsEditable();let n=t.run(this);this.element.querySelectorAll("pre:not([data-richclay-pre])").forEach(i=>{this._authoredPres.has(i)||i.setAttribute("data-richclay-pre","")}),t.mutates!==!1&&(this.ensureRootIsEditable(),this.anchorSelectionInBlock()),this.saveSelection(),this.toolbar?.update(),this.updatePlaceholder(),this.announceControl(t),n!==ko&&this.focus(),this.warnOnBlockInInlineRegion()}anchorSelectionInBlock(){let t=ot(this._squire);if(!t?.collapsed||t.startContainer!==this.element)return;let n=Array.from(this.element.childNodes),i=t.startOffset>=n.length,r=i?n.filter(it).pop():n.slice(t.startOffset).find(it)||n.slice(0,t.startOffset).filter(it).pop();if(!r)return;let o=vt(r,!i);t.setStart(o,i?Gt(o):0),t.collapse(!0),rn(this._squire,t)}selectionHasFormat(t){if(!t||!this._squire?.hasFormat)return!1;try{return this._squire.hasFormat(t)}catch{return!1}}pathHas(t){let n=ot(this._squire);if(!n)return!1;let i=t.toLowerCase(),r=Mo(this.element,n.startContainer,n.startOffset,!0,i);return!!r&&r===Mo(this.element,n.endContainer,n.endOffset,!1,i)}blocksStayOut(){return this.options.singleLine||Yt(this.element)||jr(this.element)}warnOnBlockInInlineRegion(){if(this._warnedInlineBlock||!Xt(this.element)||!Qt(this.element))return;this._warnedInlineBlock=!0;let t=this.element.nodeName.toLowerCase();console.warn(`richclay: a block element inside <${t} editable> is not valid HTML. It stays where it is and saves correctly, but a validator will flag it. Put the editable attribute on a block element if you want blocks here.`,this.element)}toggleFormat(t,n,i){return this.selectionHasFormat(t)?this._squire[i]():this._squire[n]()}toggleList(t){return this.pathHas(t)?this._squire.removeList():t==="UL"?this._squire.makeUnorderedList():this._squire.makeOrderedList()}indent(){return this.pathHas("UL")||this.pathHas("OL")?this._squire.increaseListLevel():this._squire.increaseQuoteLevel()}outdent(){return this.pathHas("UL")||this.pathHas("OL")?this._squire.decreaseListLevel():this._squire.decreaseQuoteLevel()}setBlockType(t){let n=t.toUpperCase();return n==="BLOCKQUOTE"?this._squire.increaseQuoteLevel():this._squire.modifyBlocks(i=>{let r=this.element.ownerDocument,o=r.createDocumentFragment();return Array.from(i.childNodes).forEach(s=>{if(s.nodeType!==1){o.appendChild(s);return}if(s.nodeName===n){o.appendChild(s);return}let a=r.createElement(n);for(;s.firstChild;)a.appendChild(s.firstChild);o.appendChild(a)}),o})}openLinkDialog(){this.saveSelection(),this.closeLinkDialog(),this.linkPopover?.hide();let t=this.element.ownerDocument,n=this.currentLinkElement(),i=n?.getAttribute("href")||"",r=t.createElement("form"),o=`richclay-link-label-${++Oo}`;r.className="richclay-dialog",r.setAttribute("role","dialog"),r.setAttribute("aria-modal","true"),r.setAttribute("aria-labelledby",o),r.setAttribute("data-richclay-dialog",""),he(r),r.setAttribute("save-remove",""),r.innerHTML=`
36
36
  <div class="richclay-dialog-title" id="${o}">${n?"Edit link":"Insert link"}</div>
37
37
  <label class="richclay-field">
38
38
  <span>URL</span>
@@ -43,7 +43,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
43
43
  <button type="button" class="richclay-secondary" data-richclay-cancel>Cancel</button>
44
44
  <button type="submit" class="richclay-primary">Apply</button>
45
45
  </div>
46
- `;let s=()=>{this.closeLinkDialog(),this.toolbar?.update(),this.focus(),this.updateLinkPopover()},a=()=>{this.restoreSelection(),this.removeLinkElement(this.currentLinkElement()),s()},l=()=>{s(),this.restoreSelection(),this.updateLinkPopover()};r.addEventListener("submit",S=>{S.preventDefault();let N=new FormData(r),P=String(N.get("url")||"").trim();if(!P&&n){a();return}let J=To(P);if(!J){rt(this.liveRegion,"Enter a valid URL");return}this.restoreSelection();let U=this.options.linkLabel?null:this.currentLinkElement();if(this.options.linkLabel){let he=this.element.ownerDocument.createRange();he.selectNodeContents(this.element),this._squire.setSelection(he)}U?(this.selectElement(U),this._squire.saveUndoState(),U.setAttribute("href",J)):this._squire.makeLink(J),rt(this.liveRegion,"Link applied"),s()}),r.querySelector("[data-richclay-remove-link]")?.addEventListener("click",a),r.querySelector("[data-richclay-cancel]").addEventListener("click",l),r.addEventListener("keydown",S=>{S.key==="Escape"?(S.preventDefault(),l()):S.key==="Tab"&&Fl(S,r)});let h=this.element.closest("dialog")||t.body,d=typeof r.showPopover=="function";d&&r.setAttribute("popover","manual"),Q(r,"position","fixed"),Q(r,"inset","0px auto auto 0px"),Q(r,"margin","0"),Q(r,"overflow","visible"),h.appendChild(r),d&&r.showPopover(),this.dialog=r;let u=t.defaultView||globalThis,p=()=>this.positionLinkDialog(),b=S=>{r.contains(S.target)||this.closeLinkDialog()},y=typeof u.ResizeObserver=="function"?new u.ResizeObserver(p):null;y?.observe(r),t.addEventListener("scroll",p,{capture:!0,passive:!0}),u.addEventListener("resize",p,{passive:!0}),u.visualViewport?.addEventListener("resize",p,{passive:!0}),u.visualViewport?.addEventListener("scroll",p,{passive:!0}),t.addEventListener("pointerdown",b,!0),this.dialogCleanup=()=>{y?.disconnect(),t.removeEventListener("scroll",p,{capture:!0}),u.removeEventListener("resize",p),u.visualViewport?.removeEventListener("resize",p),u.visualViewport?.removeEventListener("scroll",p),t.removeEventListener("pointerdown",b,!0)},this.positionLinkDialog();let E=r.querySelector("input");return E.value=i,E.focus(),E.select(),ko}removeLinkElement(t){return!t||!this.element.contains(t)?!1:(this.selectElement(t),this._squire.removeLink(),rt(this.liveRegion,"Link removed"),!0)}updateLinkPopover(){if(!(this.options.linkPopover===!1||this.options.readOnly||!this._squire)){if(!this.linkPopover){if(this.dialog||!this.currentLinkElement())return;this.linkPopover=new an(this)}this.linkPopover.update()}}currentLinkElement(){let t=ot(this._squire);if(!t||!this.element.contains(t.commonAncestorContainer))return null;if(t.collapsed){let n=t.startContainer,i=(n.nodeType===1?n:n.parentElement)?.closest("a[href]");return i&&i!==this.element&&this.element.contains(i)?i:null}for(let n of this.element.querySelectorAll("a[href]")){let i=n.ownerDocument.createRange(),r=n,o=n;for(;r.firstChild;)r=r.firstChild;for(;o.lastChild;)o=o.lastChild;if(i.setStart(r,0),i.setEnd(o,o.nodeType===3?o.length:o.childNodes.length),t.compareBoundaryPoints(t.END_TO_START,i)<0&&t.compareBoundaryPoints(t.START_TO_END,i)>0)return n}return null}currentLinkHref(){let t=this.currentLinkElement();return t&&t.getAttribute("href")||""}selectElement(t){let n=t.ownerDocument.createRange();return n.selectNode(t),this._squire.setSelection(n),this.saveSelection(),n}linkAnchorRect(){let t=this.savedSelection;if(typeof t?.getClientRects=="function"){let i=[...t.getClientRects()].filter(r=>r.width||r.height);if(i.length)return t.collapsed?i[0]:t.getBoundingClientRect()}return(this.toolbar?.items.find(i=>i.def.id==="link")?.button||this.toolbar?.root||this.element).getBoundingClientRect()}positionLinkDialog(){let t=this.dialog;if(!t)return;let n=t.ownerDocument.defaultView||globalThis,i=on({anchor:this.linkAnchorRect(),box:{width:t.offsetWidth||0,height:t.offsetHeight||0},viewport:{width:n.visualViewport?.width??n.innerWidth,height:n.visualViewport?.height??n.innerHeight}});t.setAttribute("data-richclay-side",i.side),t.style.setProperty("--richclay-dialog-arrow",`${Math.round(i.arrow)}px`),Q(t,"transform",`translate(${Math.round(i.x)}px, ${Math.round(i.y)}px)`)}closeLinkDialog(){this.dialogCleanup?.(),this.dialogCleanup=null,this.dialog?.remove(),this.dialog=null}ensureMarker(){xt(this.element)||(this.element.setAttribute("data-richclay-runtime-marker","true"),this.element.setAttribute("data-richclay",""))}setupEditorAttributes(){if(this.element.classList.add(this.options.inline?"richclay-inline":"richclay-editor","richclay-active"),this.element.setAttribute("data-richclay-active","true"),!this.element.hasAttribute("data-richclay-runtime-contenteditable")){let t=this.element.getAttribute("contenteditable");t===null?this.element.setAttribute("data-richclay-runtime-contenteditable","true"):t!=="true"&&t!==""&&this.element.setAttribute("data-richclay-runtime-contenteditable",t)}this.element.setAttribute("contenteditable","true"),this.element.hasAttribute("role")||nn(this.element,"role","textbox","data-richclay-runtime-role"),this.element.hasAttribute("aria-multiline")||nn(this.element,"aria-multiline",this.options.singleLine?"false":"true","data-richclay-runtime-aria-multiline"),this.element.hasAttribute("no-undo")||nn(this.element,"no-undo","","data-richclay-runtime-no-undo"),this.options.placeholder&&(this.element.setAttribute("data-richclay-placeholder",this.options.placeholder),this.description||(this.description=this.element.ownerDocument.createElement("div"),this.description.id=`richclay-placeholder-${++Oo}`,this.description.className="richclay-sr-only",this.description.textContent=this.options.placeholder,this.description.setAttribute("data-richclay-live",""),ce(this.description)),this.description.isConnected||this.element.insertAdjacentElement("afterend",this.description),uo(this.element,this.description)),this.element.addEventListener("focus",this._onFocus),this.element.addEventListener("blur",this._onBlur),this.element.addEventListener("click",this._onLinkActivation,!0),this.element.addEventListener("auxclick",this._onLinkActivation,!0),this.element.addEventListener("clay:external-write",this._onExternalWrite)}cleanupEditorAttributes(){en(this.element,"destroy"),this.element.removeEventListener("focus",this._onFocus),this.element.removeEventListener("blur",this._onBlur),this.element.removeEventListener("click",this._onLinkActivation,!0),this.element.removeEventListener("auxclick",this._onLinkActivation,!0),this.element.removeEventListener("clay:external-write",this._onExternalWrite)}keepOneLink(){let t=this.element,n=t.ownerDocument,i=t.querySelector("a[href]"),r=i?.getAttribute("href")??this._labelHref;if(!r)return;this._labelHref=r;let o=t.textContent.replace(/\u200B/g,"").replace(/\s*[\r\n]+\s*/g," "),s=t.childNodes.length===1&&t.firstChild===i?i:null;if(s&&[...s.childNodes].every(d=>d.nodeType===3)&&!s.textContent.includes("\u200B")||!o)return;let l=this._squire.getSelection(),h=o.length;if(l&&t.contains(l.startContainer)){let d=n.createRange();d.selectNodeContents(t),d.setEnd(l.startContainer,l.startOffset),h=d.toString().replace(/\u200B/g,"").replace(/\s*[\r\n]+\s*/g," ").length}this._squire.modifyDocument(()=>{let d=i??n.createElement("a");i||d.setAttribute("href",r),d.replaceChildren(n.createTextNode(o)),t.replaceChildren(d);let u=n.createRange();u.setStart(d.firstChild,Math.min(h,o.length)),u.collapse(!0),this._squire.setSelection(u)})}bindSquire(){let t=()=>{this.saveSelection(),this.updatePlaceholder(),this.options.onChange?.(this.getHTML()),this.toolbar?.update(),this.updateLinkPopover()},n=o=>{this.path=o.detail?.path||this._squire.getPath?.()||"",this.saveSelection(),this.toolbar?.update(),this.updateLinkPopover()},i=()=>{this.saveSelection(),this.toolbar?.update(),this.options.toolbarOnSelect&&this.updateFloatVisibility(),this.updateLinkPopover()};[["input",t],["pathChange",n],["select",i],["cursor",i],["undoStateChange",()=>this.toolbar?.update()]].forEach(([o,s])=>{this._squire.addEventListener(o,s),this._squireListeners.push([o,s])})}renderToolbar(){if(!this.active||this.options.readOnly)return;if(this.options.inline){this.float&&(this.teardownFloatingToolbar(),this.ensureFloatingToolbar());return}this.toolbar?.destroy(),this.toolbar=null;let t=this.resolveToolbarControls(this.options.toolbar);t.length&&(this.toolbar=new st(this,t,{toolbarContainer:this.options.toolbarContainer}))}ensureFloatingToolbar(){if(this.float||!this.active||this.options.readOnly)return;let t=this.resolveToolbarControls(this.options.toolbar);t.length&&(this.float=new rn(this,t),this._onFloatFocusOut=n=>this.scheduleFloatTeardown(n),this.float.root.addEventListener("focusout",this._onFloatFocusOut),this._onDocPointerDown=n=>{if(this.ownsFocusTarget(n.target))return;let i=this.element.ownerDocument;i.activeElement&&this.ownsFocusTarget(i.activeElement)&&i.activeElement.blur?.(),this.teardownFloatingToolbar()},this.element.ownerDocument.addEventListener("pointerdown",this._onDocPointerDown,!0),this.toolbar=this.float.toolbar,this.toolbar.update(),this.options.toolbarOnSelect&&this.updateFloatVisibility())}teardownFloatingToolbar(){this.float&&(this._onFloatFocusOut&&(this.float.root.removeEventListener("focusout",this._onFloatFocusOut),this._onFloatFocusOut=null),this._onDocPointerDown&&(this.element.ownerDocument.removeEventListener("pointerdown",this._onDocPointerDown,!0),this._onDocPointerDown=null),this.float.destroy(),this.float=null,this.toolbar=null)}scheduleFloatTeardown(t){let n=t?.relatedTarget;if(n&&this.ownsFocusTarget(n))return;let i=this.element.ownerDocument;(i.defaultView||globalThis).setTimeout(()=>{let o=i.activeElement;o&&this.ownsFocusTarget(o)||this.teardownFloatingToolbar()},0)}ownsFocusTarget(t){return t===this.element||this.element.contains(t)||!!this.float?.root.contains(t)||!!this.dialog?.contains(t)||!!this.linkPopover?.root?.contains(t)}updateFloatVisibility(){if(!this.float)return;let t=this.savedSelection;this.float.setVisible(!!(t&&!t.collapsed))}resolveToolbarControls(t){return t===!1||t===null||t==="none"?[]:(Array.isArray(t)?t:Et[t]||Et.standard).map(i=>{if(typeof i=="string"){let r=this.registry.get(i);if(!r)throw new Error(`Unknown RichClay toolbar control: ${i}`);return r}return i?.type==="separator"||vi(i),i})}installShortcuts(){let t=new Set,n=[...this.registry.values()].filter(r=>(!this.options.singleLine||Et.inline.includes(r.id))&&(!this.options.linkLabel||Do.includes(r.id)));[...this.resolveToolbarControls(this.options.toolbar),...n].forEach(r=>{if(r.type==="menu"||r.type==="separator"||!r.shortcut||!r.id||t.has(r.id))return;if(r.isDisabled?.(this)){let s=Si(r.shortcut,this.window);this._squire.setKeyHandler(s,null),this._shortcutKeys.push(s);return}t.add(r.id);let o=Si(r.shortcut,this.window);this._squire.setKeyHandler(o,(s,a)=>{a.preventDefault(),this.runControl(r)}),this._shortcutKeys.push(o)})}maskFormattingShortcuts(){for(let t of this.registry.values()){if(!t.shortcut||Do.includes(t.id))continue;let n=Si(t.shortcut,this.window);this._squire.setKeyHandler(n,(i,r)=>r.preventDefault()),this._shortcutKeys.push(n)}}maskSquireCodeShortcut(){let t=`${nt(this.window)?"Meta":"Ctrl"}-d`;this._squire.setKeyHandler(t,null),this._shortcutKeys.push(t)}maskSquireBlockShortcuts(){if(!this.blocksStayOut())return;let t=nt(this.window)?"Meta":"Ctrl";[`${t}-]`,`${t}-[`,`${t}-Shift-8`,`${t}-Shift-9`].forEach(n=>{this._squire.setKeyHandler(n,null),this._shortcutKeys.push(n)})}toggleCode(){return this.blocksStayOut()?this.selectionHasFormat("CODE")?this._squire.changeFormat(null,{tag:"CODE"}):this._squire.changeFormat({tag:"CODE"},null):this._squire.toggleCode()}installAppleDeleteKeys(){if(!nt(this.window))return;let t=this._squire._keyHandlers;t&&[["Ctrl-d","Delete"],["Ctrl-h","Backspace"]].forEach(([n,i])=>{typeof t[i]=="function"&&(this._squire.setKeyHandler(n,t[i]),this._shortcutKeys.push(n),this._appleDeleteKeys.add(n.slice(5)))})}installSingleLineGuards(){["Enter","Shift-Enter"].forEach(t=>{this._squire.setKeyHandler(t,(n,i)=>i.preventDefault()),this._shortcutKeys.push(t)}),this._onBeforeInput=t=>{if(!this.element.contains(t.target))return;let n=this.options.linkLabel&&t.inputType.startsWith("format");(t.inputType==="insertParagraph"||t.inputType==="insertLineBreak"||n)&&(t.preventDefault(),t.stopPropagation())},this.element.ownerDocument.addEventListener("beforeinput",this._onBeforeInput,!0)}resetSquireUndoBaseline(){let t=this._squire;!t||!Array.isArray(t._undoStack)||typeof t.saveUndoState!="function"||(t._undoStack.length=0,t._undoStackLength=0,t._undoIndex=-1,t._isInUndoState=!1,t.saveUndoState())}updatePlaceholder(){let t=Ti(this.element,{capability:"history",inherit:!1}),n=t.text().replace(/\u200B/g,"").trim(),i=t.root.querySelector("img, video, audio, iframe, table"),r=!n&&!i;this.element.classList.toggle("richclay-empty",r)}announceControl(t){if(!this.liveRegion)return;let n=t.ariaLabel||t.label;n&&(typeof t.isActive=="function"?rt(this.liveRegion,`${n} ${t.isActive(this)?"on":"off"}`):rt(this.liveRegion,`${n} applied`))}};function Ml(e){return typeof e=="string"?Array.from(document.querySelectorAll(e)):e?.nodeType===1?[e]:Array.from(e||[])}function Io(e,t,n,i,r){let o=t;if(o===e){let l=Array.from(e.childNodes).filter(it);if(!l.length)return null;let h=Math.min(i?n:Math.max(n-1,0),l.length-1);o=vt(l[h],i)}let a=(o?.nodeType===1?o:o?.parentElement)?.closest?.(r);return a&&e.contains(a)&&a!==e?a:null}function Pl(e){let t=e.parentElement;for(;t;){if(Ae.has(t)||xt(t))return t;t=t.parentElement}return null}function xt(e){return!!e.matches?.(de)&&oi(e)}function Ei(e){let t=Pl(e),n=Array.from(e.querySelectorAll?.(de)||[]).find(r=>Ae.has(r)),i=t||n;return i?(console.warn("richclay: nested editable regions are not supported, so this one was skipped. Remove the editable attribute from either it or the other region.",e,i),!0):!1}function Bl(e){return Zr(e)?(console.warn(`richclay: ${Yr(e)} This region was skipped.`,e),!0):!1}function vi(e){if(!e||!e.id)throw new Error("RichClay button definitions require an id.");if(e.type!=="menu"&&typeof e.run!="function")throw new Error(`RichClay button "${e.id}" requires a run(editor) function.`)}function Si(e,t){let n=e.split("+"),i=n[n.length-1],r=new Set(n.slice(0,-1).map(Hl));r.delete("Mod")&&r.add(nt(t)?"Meta":"Ctrl");let o=i.length===1?r.has("Shift")?i.toUpperCase():i.toLowerCase():i,s=Ol.filter(a=>r.has(a)).join("-");return`${s?`${s}-`:""}${o}`}function Hl(e){return e==="Cmd"?"Meta":e}function Fl(e,t){let n=t.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(!n.length)return;let i=n[0],r=n[n.length-1],o=t.ownerDocument.activeElement;e.shiftKey&&o===i?(e.preventDefault(),r.focus()):!e.shiftKey&&o===r&&(e.preventDefault(),i.focus())}var Bo=`:root {
46
+ `;let s=()=>{this.closeLinkDialog(),this.toolbar?.update(),this.focus(),this.updateLinkPopover()},a=()=>{this.restoreSelection(),this.removeLinkElement(this.currentLinkElement()),s()},l=()=>{s(),this.restoreSelection(),this.updateLinkPopover()};r.addEventListener("submit",S=>{S.preventDefault();let N=new FormData(r),P=String(N.get("url")||"").trim();if(!P&&n){a();return}let J=_o(P);if(!J){rt(this.liveRegion,"Enter a valid URL");return}this.restoreSelection();let U=this.options.linkLabel?null:this.currentLinkElement();if(this.options.linkLabel){let ue=this.element.ownerDocument.createRange();ue.selectNodeContents(this.element),this._squire.setSelection(ue)}U?(this.selectElement(U),this._squire.saveUndoState(),U.setAttribute("href",J)):this._squire.makeLink(J),rt(this.liveRegion,"Link applied"),s()}),r.querySelector("[data-richclay-remove-link]")?.addEventListener("click",a),r.querySelector("[data-richclay-cancel]").addEventListener("click",l),r.addEventListener("keydown",S=>{S.key==="Escape"?(S.preventDefault(),l()):S.key==="Tab"&&Fl(S,r)});let h=this.element.closest("dialog")||t.body,d=typeof r.showPopover=="function";d&&r.setAttribute("popover","manual"),Q(r,"position","fixed"),Q(r,"inset","0px auto auto 0px"),Q(r,"margin","0"),Q(r,"overflow","visible"),h.appendChild(r),d&&r.showPopover(),this.dialog=r;let u=t.defaultView||globalThis,p=()=>this.positionLinkDialog(),b=S=>{r.contains(S.target)||this.closeLinkDialog()},y=typeof u.ResizeObserver=="function"?new u.ResizeObserver(p):null;y?.observe(r),t.addEventListener("scroll",p,{capture:!0,passive:!0}),u.addEventListener("resize",p,{passive:!0}),u.visualViewport?.addEventListener("resize",p,{passive:!0}),u.visualViewport?.addEventListener("scroll",p,{passive:!0}),t.addEventListener("pointerdown",b,!0),this.dialogCleanup=()=>{y?.disconnect(),t.removeEventListener("scroll",p,{capture:!0}),u.removeEventListener("resize",p),u.visualViewport?.removeEventListener("resize",p),u.visualViewport?.removeEventListener("scroll",p),t.removeEventListener("pointerdown",b,!0)},this.positionLinkDialog();let E=r.querySelector("input");return E.value=i,E.focus(),E.select(),ko}removeLinkElement(t){return!t||!this.element.contains(t)?!1:(this.selectElement(t),this._squire.removeLink(),rt(this.liveRegion,"Link removed"),!0)}updateLinkPopover(){if(!(this.options.linkPopover===!1||this.options.readOnly||!this._squire)){if(!this.linkPopover){if(this.dialog||!this.currentLinkElement())return;this.linkPopover=new hn(this)}this.linkPopover.update()}}currentLinkElement(){let t=ot(this._squire);if(!t||!this.element.contains(t.commonAncestorContainer))return null;if(t.collapsed){let n=t.startContainer,i=(n.nodeType===1?n:n.parentElement)?.closest("a[href]");return i&&i!==this.element&&this.element.contains(i)?i:null}for(let n of this.element.querySelectorAll("a[href]")){let i=n.ownerDocument.createRange(),r=n,o=n;for(;r.firstChild;)r=r.firstChild;for(;o.lastChild;)o=o.lastChild;if(i.setStart(r,0),i.setEnd(o,o.nodeType===3?o.length:o.childNodes.length),t.compareBoundaryPoints(t.END_TO_START,i)<0&&t.compareBoundaryPoints(t.START_TO_END,i)>0)return n}return null}currentLinkHref(){let t=this.currentLinkElement();return t&&t.getAttribute("href")||""}selectElement(t){let n=t.ownerDocument.createRange();return n.selectNode(t),this._squire.setSelection(n),this.saveSelection(),n}linkAnchorRect(){let t=this.savedSelection;if(typeof t?.getClientRects=="function"){let i=[...t.getClientRects()].filter(r=>r.width||r.height);if(i.length)return t.collapsed?i[0]:t.getBoundingClientRect()}return(this.toolbar?.items.find(i=>i.def.id==="link")?.button||this.toolbar?.root||this.element).getBoundingClientRect()}positionLinkDialog(){let t=this.dialog;if(!t)return;let n=t.ownerDocument.defaultView||globalThis,i=an({anchor:this.linkAnchorRect(),box:{width:t.offsetWidth||0,height:t.offsetHeight||0},viewport:{width:n.visualViewport?.width??n.innerWidth,height:n.visualViewport?.height??n.innerHeight}});t.setAttribute("data-richclay-side",i.side),t.style.setProperty("--richclay-dialog-arrow",`${Math.round(i.arrow)}px`),Q(t,"transform",`translate(${Math.round(i.x)}px, ${Math.round(i.y)}px)`)}closeLinkDialog(){this.dialogCleanup?.(),this.dialogCleanup=null,this.dialog?.remove(),this.dialog=null}ensureMarker(){xt(this.element)||(this.element.setAttribute("data-richclay-runtime-marker","true"),this.element.setAttribute("data-richclay",""))}setupEditorAttributes(){if(this.element.classList.add(this.options.inline?"richclay-inline":"richclay-editor","richclay-active"),this.element.setAttribute("data-richclay-active","true"),!this.element.hasAttribute("data-richclay-runtime-contenteditable")){let t=this.element.getAttribute("contenteditable");t===null?this.element.setAttribute("data-richclay-runtime-contenteditable","true"):t!=="true"&&t!==""&&this.element.setAttribute("data-richclay-runtime-contenteditable",t)}this.element.setAttribute("contenteditable","true"),this.element.hasAttribute("role")||on(this.element,"role","textbox","data-richclay-runtime-role"),this.element.hasAttribute("aria-multiline")||on(this.element,"aria-multiline",this.options.singleLine?"false":"true","data-richclay-runtime-aria-multiline"),this.element.hasAttribute("no-undo")||on(this.element,"no-undo","","data-richclay-runtime-no-undo"),this.options.placeholder&&(this.element.setAttribute("data-richclay-placeholder",this.options.placeholder),this.description||(this.description=this.element.ownerDocument.createElement("div"),this.description.id=`richclay-placeholder-${++Oo}`,this.description.className="richclay-sr-only",this.description.textContent=this.options.placeholder,this.description.setAttribute("data-richclay-live",""),he(this.description)),this.description.isConnected||this.element.insertAdjacentElement("afterend",this.description),po(this.element,this.description)),this.element.addEventListener("focus",this._onFocus),this.element.addEventListener("blur",this._onBlur),this.element.addEventListener("click",this._onLinkActivation,!0),this.element.addEventListener("auxclick",this._onLinkActivation,!0),this.element.addEventListener("clay:external-write",this._onExternalWrite)}cleanupEditorAttributes(){nn(this.element,"destroy"),this.element.removeEventListener("focus",this._onFocus),this.element.removeEventListener("blur",this._onBlur),this.element.removeEventListener("click",this._onLinkActivation,!0),this.element.removeEventListener("auxclick",this._onLinkActivation,!0),this.element.removeEventListener("clay:external-write",this._onExternalWrite)}keepOneLink(){let t=this.element,n=t.ownerDocument,i=t.querySelector("a[href]"),r=i?.getAttribute("href")??this._labelHref;if(!r)return;this._labelHref=r;let o=t.textContent.replace(/\u200B/g,"").replace(/\s*[\r\n]+\s*/g," "),s=t.childNodes.length===1&&t.firstChild===i?i:null;if(s&&[...s.childNodes].every(d=>d.nodeType===3)&&!s.textContent.includes("\u200B")||!o)return;let l=this._squire.getSelection(),h=o.length;if(l&&t.contains(l.startContainer)){let d=n.createRange();d.selectNodeContents(t),d.setEnd(l.startContainer,l.startOffset),h=d.toString().replace(/\u200B/g,"").replace(/\s*[\r\n]+\s*/g," ").length}this._squire.modifyDocument(()=>{let d=i??n.createElement("a");i||d.setAttribute("href",r),d.replaceChildren(n.createTextNode(o)),t.replaceChildren(d);let u=n.createRange();u.setStart(d.firstChild,Math.min(h,o.length)),u.collapse(!0),this._squire.setSelection(u)})}bindSquire(){let t=()=>{this._squireHTML=this.element.innerHTML,this.saveSelection(),this.updatePlaceholder(),this.options.onChange?.(this.getHTML()),this.toolbar?.update(),this.updateLinkPopover()},n=o=>{this.path=o.detail?.path||this._squire.getPath?.()||"",this.saveSelection(),this.toolbar?.update(),this.updateLinkPopover()},i=()=>{this.saveSelection(),this.toolbar?.update(),this.options.toolbarOnSelect&&this.updateFloatVisibility(),this.updateLinkPopover()};[["input",t],["pathChange",n],["select",i],["cursor",i],["undoStateChange",()=>this.toolbar?.update()]].forEach(([o,s])=>{this._squire.addEventListener(o,s),this._squireListeners.push([o,s])})}renderToolbar(){if(!this.active||this.options.readOnly)return;if(this.options.inline){this.float&&(this.teardownFloatingToolbar(),this.ensureFloatingToolbar());return}this.toolbar?.destroy(),this.toolbar=null;let t=this.resolveToolbarControls(this.options.toolbar);t.length&&(this.toolbar=new st(this,t,{toolbarContainer:this.options.toolbarContainer}))}ensureFloatingToolbar(){if(this.float||!this.active||this.options.readOnly)return;let t=this.resolveToolbarControls(this.options.toolbar);t.length&&(this.float=new sn(this,t),this._onFloatFocusOut=n=>this.scheduleFloatTeardown(n),this.float.root.addEventListener("focusout",this._onFloatFocusOut),this._onDocPointerDown=n=>{if(this.ownsFocusTarget(n.target))return;let i=this.element.ownerDocument;i.activeElement&&this.ownsFocusTarget(i.activeElement)&&i.activeElement.blur?.(),this.teardownFloatingToolbar()},this.element.ownerDocument.addEventListener("pointerdown",this._onDocPointerDown,!0),this.toolbar=this.float.toolbar,this.toolbar.update(),this.options.toolbarOnSelect&&this.updateFloatVisibility())}teardownFloatingToolbar(){this.float&&(this._onFloatFocusOut&&(this.float.root.removeEventListener("focusout",this._onFloatFocusOut),this._onFloatFocusOut=null),this._onDocPointerDown&&(this.element.ownerDocument.removeEventListener("pointerdown",this._onDocPointerDown,!0),this._onDocPointerDown=null),this.float.destroy(),this.float=null,this.toolbar=null)}scheduleFloatTeardown(t){let n=t?.relatedTarget;if(n&&this.ownsFocusTarget(n))return;let i=this.element.ownerDocument;(i.defaultView||globalThis).setTimeout(()=>{let o=i.activeElement;o&&this.ownsFocusTarget(o)||this.teardownFloatingToolbar()},0)}ownsFocusTarget(t){return t===this.element||this.element.contains(t)||!!this.float?.root.contains(t)||!!this.dialog?.contains(t)||!!this.linkPopover?.root?.contains(t)}updateFloatVisibility(){if(!this.float)return;let t=this.savedSelection;this.float.setVisible(!!(t&&!t.collapsed))}resolveToolbarControls(t){return t===!1||t===null||t==="none"?[]:(Array.isArray(t)?t:Et[t]||Et.standard).map(i=>{if(typeof i=="string"){let r=this.registry.get(i);if(!r)throw new Error(`Unknown RichClay toolbar control: ${i}`);return r}return i?.type==="separator"||Ai(i),i})}installShortcuts(){let t=new Set,n=[...this.registry.values()].filter(r=>(!this.options.singleLine||Et.inline.includes(r.id))&&(!this.options.linkLabel||Do.includes(r.id))),i=[...this.resolveToolbarControls(this.options.toolbar),...n];if(i.forEach(r=>{if(r.type==="menu"||r.type==="separator"||!r.shortcut||!r.id||t.has(r.id))return;if(r.isDisabled?.(this)){let s=Ci(r.shortcut,this.window);this._squire.setKeyHandler(s,null),this._shortcutKeys.push(s);return}t.add(r.id);let o=Ci(r.shortcut,this.window);this._squire.setKeyHandler(o,(s,a)=>{a.preventDefault(),this.runControl(r)}),this._shortcutKeys.push(o)}),!Ke(this.window)){let r=i.find(o=>o.id==="redo"&&o.shortcut);r&&!r.isDisabled?.(this)&&(this._squire.setKeyHandler("Ctrl-y",(o,s)=>{s.preventDefault(),this.runControl(r)}),this._shortcutKeys.push("Ctrl-y"))}}maskFormattingShortcuts(){for(let t of this.registry.values()){if(!t.shortcut||Do.includes(t.id))continue;let n=Ci(t.shortcut,this.window);this._squire.setKeyHandler(n,(i,r)=>r.preventDefault()),this._shortcutKeys.push(n)}}maskSquireCodeShortcut(){let t=`${Ke(this.window)?"Meta":"Ctrl"}-d`;this._squire.setKeyHandler(t,null),this._shortcutKeys.push(t)}maskSquireBlockShortcuts(){if(!this.blocksStayOut())return;let t=Ke(this.window)?"Meta":"Ctrl";[`${t}-]`,`${t}-[`,`${t}-Shift-8`,`${t}-Shift-9`].forEach(n=>{this._squire.setKeyHandler(n,null),this._shortcutKeys.push(n)})}toggleCode(){return this.blocksStayOut()?this.selectionHasFormat("CODE")?this._squire.changeFormat(null,{tag:"CODE"}):this._squire.changeFormat({tag:"CODE"},null):this._squire.toggleCode()}installAppleDeleteKeys(){if(!Ke(this.window))return;let t=this._squire._keyHandlers;t&&[["Ctrl-d","Delete"],["Ctrl-h","Backspace"]].forEach(([n,i])=>{typeof t[i]=="function"&&(this._squire.setKeyHandler(n,t[i]),this._shortcutKeys.push(n),this._appleDeleteKeys.add(n.slice(5)))})}installSingleLineGuards(){["Enter","Shift-Enter"].forEach(t=>{this._squire.setKeyHandler(t,(n,i)=>i.preventDefault()),this._shortcutKeys.push(t)}),this._onBeforeInput=t=>{if(!this.element.contains(t.target))return;let n=this.options.linkLabel&&t.inputType.startsWith("format");(t.inputType==="insertParagraph"||t.inputType==="insertLineBreak"||n)&&(t.preventDefault(),t.stopPropagation())},this.element.ownerDocument.addEventListener("beforeinput",this._onBeforeInput,!0)}resetSquireUndoBaseline(){let t=this._squire;!t||!Array.isArray(t._undoStack)||typeof t.saveUndoState!="function"||(this._squireHTML=this.element.innerHTML,t._undoStack.length=0,t._undoStackLength=0,t._undoIndex=-1,t._isInUndoState=!1,t.saveUndoState())}updatePlaceholder(){let t=Ei(this.element,{capability:"history",inherit:!1}),n=t.text().replace(/\u200B/g,"").trim(),i=t.root.querySelector("img, video, audio, iframe, table"),r=!n&&!i;this.element.classList.toggle("richclay-empty",r)}announceControl(t){if(!this.liveRegion)return;let n=t.ariaLabel||t.label;n&&(typeof t.isActive=="function"?rt(this.liveRegion,`${n} ${t.isActive(this)?"on":"off"}`):rt(this.liveRegion,`${n} applied`))}};function Il(e){return typeof e=="string"?Array.from(document.querySelectorAll(e)):e?.nodeType===1?[e]:Array.from(e||[])}function Mo(e,t,n,i,r){let o=t;if(o===e){let l=Array.from(e.childNodes).filter(it);if(!l.length)return null;let h=Math.min(i?n:Math.max(n-1,0),l.length-1);o=vt(l[h],i)}let a=(o?.nodeType===1?o:o?.parentElement)?.closest?.(r);return a&&e.contains(a)&&a!==e?a:null}function Pl(e){let t=e.parentElement;for(;t;){if(Te.has(t)||xt(t))return t;t=t.parentElement}return null}function xt(e){return!!e.matches?.(ce)&&Jt(e)}function Si(e){let t=Pl(e),n=Array.from(e.querySelectorAll?.(ce)||[]).find(r=>Te.has(r)),i=t||n;return i?(console.warn("richclay: nested editable regions are not supported, so this one was skipped. Remove the editable attribute from either it or the other region.",e,i),!0):!1}function Bl(e){return Xr(e)?(console.warn(`richclay: ${Qr(e)} This region was skipped.`,e),!0):!1}function Ai(e){if(!e||!e.id)throw new Error("RichClay button definitions require an id.");if(e.type!=="menu"&&typeof e.run!="function")throw new Error(`RichClay button "${e.id}" requires a run(editor) function.`)}function Ci(e,t){let n=e.split("+"),i=n[n.length-1],r=new Set(n.slice(0,-1).map(Hl));r.delete("Mod")&&r.add(Ke(t)?"Meta":"Ctrl");let o=i.length===1?r.has("Shift")?i.toUpperCase():i.toLowerCase():i,s=Ol.filter(a=>r.has(a)).join("-");return`${s?`${s}-`:""}${o}`}function Hl(e){return e==="Cmd"?"Meta":e}function Fl(e,t){let n=t.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(!n.length)return;let i=n[0],r=n[n.length-1],o=t.ownerDocument.activeElement;e.shiftKey&&o===i?(e.preventDefault(),r.focus()):!e.shiftKey&&o===r&&(e.preventDefault(),i.focus())}var Bo=`:root {
47
47
  --richclay-surface: #ffffff;
48
48
  --richclay-surface-alt: #f6f7f9;
49
49
  --richclay-text: #0b0e14;
@@ -471,7 +471,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
471
471
  outline-color: Highlight;
472
472
  }
473
473
  }
474
- `;var at=typeof globalThis<"u"?globalThis:self;at&&!at.Squire&&(at.Squire=vr);at&&!at.DOMPurify&&(at.DOMPurify=Ur);So(Bo);var zl=$e.autoInit(),ql=$e;return ys(Wl);})();
474
+ `;var at=typeof globalThis<"u"?globalThis:self;at&&!at.Squire&&(at.Squire=Ar);at&&!at.DOMPurify&&(at.DOMPurify=qr);So(Bo);var zl=$e.autoInit(),ql=$e;return ys(Wl);})();
475
475
  /*! @license DOMPurify 3.4.11 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.11/LICENSE */
476
476
 
477
477
  // Auto-export to window unless suppressed by loader. The self-contained bundle