monobill-mintui 0.6.734 → 0.6.736

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 (216) hide show
  1. package/bin/component-dependencies.json +10 -0
  2. package/dist/back-button.css +1 -1
  3. package/dist/card.css +1 -1
  4. package/dist/components/alert/browser.js +4 -4
  5. package/dist/components/alert/index.cjs +1 -1
  6. package/dist/components/alert/index.js +4 -4
  7. package/dist/components/back-button/browser.js +1 -1
  8. package/dist/components/back-button/index.cjs +1 -1
  9. package/dist/components/back-button/index.js +1 -1
  10. package/dist/components/bottom-navigation/browser.js +2 -2
  11. package/dist/components/bottom-navigation/index.cjs +1 -1
  12. package/dist/components/bottom-navigation/index.js +2 -2
  13. package/dist/components/button/Button.d.ts.map +1 -1
  14. package/dist/components/button/browser.js +1 -1
  15. package/dist/components/button/index.cjs +1 -1
  16. package/dist/components/button/index.js +1 -1
  17. package/dist/components/checkbox/browser.js +1 -1
  18. package/dist/components/checkbox/index.cjs +1 -1
  19. package/dist/components/checkbox/index.js +1 -1
  20. package/dist/components/chip/browser.js +1 -1
  21. package/dist/components/chip/index.cjs +1 -1
  22. package/dist/components/chip/index.js +1 -1
  23. package/dist/components/chunks/ScrollFade-DOnPtfC2.js +85 -0
  24. package/dist/components/chunks/ScrollFade-FBvsnQ1i.js +1 -0
  25. package/dist/components/chunks/{back-button-CC-TMsIw.js → back-button-CMZR-p_D.js} +2 -2
  26. package/dist/components/chunks/{back-button-Cwznte3M.js → back-button-C_aLMNZE.js} +1 -1
  27. package/dist/components/chunks/{button-DFoOu1dY.js → button-CELyLLtj.js} +1 -1
  28. package/dist/components/chunks/{button-p4PvDgg3.js → button-THsh4Svz.js} +3 -3
  29. package/dist/components/chunks/caret-down-BiAVkpX7.js +1 -0
  30. package/dist/components/chunks/{caret-down-Re0eHop6.js → caret-down-DUfiCBEs.js} +1 -1
  31. package/dist/components/chunks/caret-right-8n-rhz51.js +1 -0
  32. package/dist/components/chunks/{caret-right-pQsg_Tvf.js → caret-right-CppgjbLX.js} +1 -1
  33. package/dist/components/chunks/{checkbox-DKKOOaAA.js → checkbox-CZViKLNo.js} +2 -2
  34. package/dist/components/chunks/{checkbox-al-mdHK7.js → checkbox-d5UlscqI.js} +1 -1
  35. package/dist/components/chunks/{chip-BhhRXO_g.js → chip-DJ_kZURn.js} +1 -1
  36. package/dist/components/chunks/{chip-WYtVlBo_.js → chip-G6SRCgLq.js} +3 -3
  37. package/dist/components/chunks/{close-DfFS9Iww.js → close-ChHICicN.js} +1 -1
  38. package/dist/components/chunks/close-CuYimzX0.js +1 -0
  39. package/dist/components/chunks/{confirm-action-kvEHHFbd.js → confirm-action-BSHfjDfA.js} +1 -1
  40. package/dist/components/chunks/{confirm-action-CLs_pBDb.js → confirm-action-CRZMTjpd.js} +2 -2
  41. package/dist/components/chunks/{date-picker-BxAHKxaJ.js → date-picker-CTtYAkmM.js} +1 -1
  42. package/dist/components/chunks/{date-picker-COWiQYAf.js → date-picker-CUf5eJR3.js} +5 -5
  43. package/dist/components/chunks/{icon-BTPOIKHZ.js → icon-1cs-hcBy.js} +308 -240
  44. package/dist/components/chunks/{icon-C7YkjDlz.js → icon-Bv1J3LwC.js} +7 -7
  45. package/dist/components/chunks/icon-C-6HOPtI.js +1 -0
  46. package/dist/components/chunks/icon-aNwWb0hA.js +1 -0
  47. package/dist/components/chunks/{input-DfadWNai.js → input-Bu4xPosP.js} +3 -3
  48. package/dist/components/chunks/{input-9ZDaMAQH.js → input-Zqw53jts.js} +1 -1
  49. package/dist/components/chunks/{modal-C3gfernp.js → modal-CL5EStu0.js} +1 -1
  50. package/dist/components/chunks/{modal-CITn4Kxv.js → modal-ss_OTDJJ.js} +2 -2
  51. package/dist/components/chunks/popover-2Cnva3AN.js +1 -0
  52. package/dist/components/chunks/{popover-DPNBidSz.js → popover-DD7uyRXy.js} +3 -3
  53. package/dist/components/chunks/search-BXku4V9r.js +1 -0
  54. package/dist/components/chunks/{search-CKDqbJNo.js → search-DKHcIR2F.js} +1 -1
  55. package/dist/components/chunks/{select-DzapiRgp.js → select-CX9oOwl5.js} +1 -1
  56. package/dist/components/chunks/{select-FAoUWWgL.js → select-DOMW7Plx.js} +3 -3
  57. package/dist/components/chunks/{table-BNZVNp5g.js → table-HnSpIfny.js} +1 -1
  58. package/dist/components/chunks/{table-BNNRNEZ9.js → table-IU2Vmjwk.js} +1 -1
  59. package/dist/components/chunks/{time-picker-CllURo12.js → time-picker-BaoT0NtA.js} +1 -1
  60. package/dist/components/chunks/{time-picker-Cfza0IJy.js → time-picker-C7pJvGSM.js} +3 -3
  61. package/dist/components/chunks/{warning-CAvTb3wK.js → warning-Cf8ePVsQ.js} +1 -1
  62. package/dist/components/chunks/{warning-aKvCzp6B.js → warning-gkij2FhS.js} +1 -1
  63. package/dist/components/confirm-action/browser.js +1 -1
  64. package/dist/components/confirm-action/index.cjs +1 -1
  65. package/dist/components/confirm-action/index.js +1 -1
  66. package/dist/components/date-picker/browser.js +1 -1
  67. package/dist/components/date-picker/index.cjs +1 -1
  68. package/dist/components/date-picker/index.js +1 -1
  69. package/dist/components/datetime-picker/browser.js +3 -3
  70. package/dist/components/datetime-picker/index.cjs +1 -1
  71. package/dist/components/datetime-picker/index.js +3 -3
  72. package/dist/components/dropzone/browser.js +4 -4
  73. package/dist/components/dropzone/index.cjs +1 -1
  74. package/dist/components/dropzone/index.js +4 -4
  75. package/dist/components/editor/Editor.d.ts +133 -0
  76. package/dist/components/editor/Editor.d.ts.map +1 -0
  77. package/dist/components/editor/browser.js +1544 -0
  78. package/dist/components/editor/index.cjs +29 -0
  79. package/dist/components/editor/index.d.ts +9 -0
  80. package/dist/components/editor/index.d.ts.map +1 -0
  81. package/dist/components/editor/index.js +1532 -0
  82. package/dist/components/icon/browser.js +1 -1
  83. package/dist/components/icon/icons/bold.d.ts +3 -0
  84. package/dist/components/icon/icons/bold.d.ts.map +1 -0
  85. package/dist/components/icon/icons/clear-formatting.d.ts +3 -0
  86. package/dist/components/icon/icons/clear-formatting.d.ts.map +1 -0
  87. package/dist/components/icon/icons/index.d.ts +7 -0
  88. package/dist/components/icon/icons/index.d.ts.map +1 -1
  89. package/dist/components/icon/icons/italic.d.ts +3 -0
  90. package/dist/components/icon/icons/italic.d.ts.map +1 -0
  91. package/dist/components/icon/icons/numbered-list.d.ts +3 -0
  92. package/dist/components/icon/icons/numbered-list.d.ts.map +1 -0
  93. package/dist/components/icon/icons/quote.d.ts +3 -0
  94. package/dist/components/icon/icons/quote.d.ts.map +1 -0
  95. package/dist/components/icon/icons/toolbar-icons.d.ts +13 -0
  96. package/dist/components/icon/icons/toolbar-icons.d.ts.map +1 -0
  97. package/dist/components/icon/icons/underline.d.ts +3 -0
  98. package/dist/components/icon/icons/underline.d.ts.map +1 -0
  99. package/dist/components/icon/index.cjs +1 -1
  100. package/dist/components/icon/index.js +1 -1
  101. package/dist/components/input/browser.js +1 -1
  102. package/dist/components/input/index.cjs +1 -1
  103. package/dist/components/input/index.js +1 -1
  104. package/dist/components/modal/browser.js +1 -1
  105. package/dist/components/modal/index.cjs +1 -1
  106. package/dist/components/modal/index.js +1 -1
  107. package/dist/components/navigation/browser.js +3 -3
  108. package/dist/components/navigation/index.cjs +1 -1
  109. package/dist/components/navigation/index.js +3 -3
  110. package/dist/components/off-canvas/browser.js +2 -2
  111. package/dist/components/off-canvas/index.cjs +1 -1
  112. package/dist/components/off-canvas/index.js +2 -2
  113. package/dist/components/page/browser.js +4 -4
  114. package/dist/components/page/index.cjs +1 -1
  115. package/dist/components/page/index.js +4 -4
  116. package/dist/components/popover/Popover.d.ts.map +1 -1
  117. package/dist/components/popover/browser.js +1 -1
  118. package/dist/components/popover/index.cjs +1 -1
  119. package/dist/components/popover/index.js +1 -1
  120. package/dist/components/resource-table/browser.js +11 -11
  121. package/dist/components/resource-table/index.cjs +1 -1
  122. package/dist/components/resource-table/index.js +11 -11
  123. package/dist/components/scroll-fade/ScrollFade.d.ts +2 -1
  124. package/dist/components/scroll-fade/ScrollFade.d.ts.map +1 -1
  125. package/dist/components/scroll-fade/browser.js +1 -1
  126. package/dist/components/scroll-fade/index.cjs +1 -1
  127. package/dist/components/scroll-fade/index.js +1 -1
  128. package/dist/components/search/browser.js +7 -7
  129. package/dist/components/search/index.cjs +1 -1
  130. package/dist/components/search/index.js +7 -7
  131. package/dist/components/select/browser.js +1 -1
  132. package/dist/components/select/index.cjs +1 -1
  133. package/dist/components/select/index.js +1 -1
  134. package/dist/components/side-navigation/browser.js +6 -6
  135. package/dist/components/side-navigation/index.cjs +1 -1
  136. package/dist/components/side-navigation/index.js +6 -6
  137. package/dist/components/switch/browser.js +2 -2
  138. package/dist/components/switch/index.cjs +1 -1
  139. package/dist/components/switch/index.js +2 -2
  140. package/dist/components/table/browser.js +1 -1
  141. package/dist/components/table/index.cjs +1 -1
  142. package/dist/components/table/index.js +1 -1
  143. package/dist/components/tabs/browser.js +1 -1
  144. package/dist/components/tabs/index.cjs +1 -1
  145. package/dist/components/tabs/index.js +1 -1
  146. package/dist/components/tags/browser.js +4 -4
  147. package/dist/components/tags/index.cjs +1 -1
  148. package/dist/components/tags/index.js +4 -4
  149. package/dist/components/time-picker/browser.js +1 -1
  150. package/dist/components/time-picker/index.cjs +1 -1
  151. package/dist/components/time-picker/index.js +1 -1
  152. package/dist/components/tree/browser.js +4 -4
  153. package/dist/components/tree/index.cjs +1 -1
  154. package/dist/components/tree/index.js +4 -4
  155. package/dist/editor.css +2 -0
  156. package/dist/icon.css +1 -1
  157. package/dist/icons/bank.svg +1 -1
  158. package/dist/icons/basket.svg +1 -1
  159. package/dist/icons/bold.svg +3 -0
  160. package/dist/icons/building.svg +1 -1
  161. package/dist/icons/buildings.svg +1 -1
  162. package/dist/icons/cash.svg +1 -1
  163. package/dist/icons/clear-formatting.svg +1 -0
  164. package/dist/icons/coupon.svg +1 -1
  165. package/dist/icons/delivery-location.svg +1 -1
  166. package/dist/icons/dollar-sign.svg +1 -1
  167. package/dist/icons/dress.svg +1 -1
  168. package/dist/icons/gift.svg +1 -1
  169. package/dist/icons/heart.svg +1 -1
  170. package/dist/icons/installments.svg +1 -1
  171. package/dist/icons/inventory.svg +1 -1
  172. package/dist/icons/invoice.svg +1 -1
  173. package/dist/icons/italic.svg +3 -0
  174. package/dist/icons/jacket.svg +1 -1
  175. package/dist/icons/loyalty-points.svg +1 -1
  176. package/dist/icons/membership.svg +1 -1
  177. package/dist/icons/numbered-list.svg +3 -0
  178. package/dist/icons/out-of-stock.svg +1 -1
  179. package/dist/icons/package.svg +1 -1
  180. package/dist/icons/percent-discount.svg +1 -1
  181. package/dist/icons/pickup.svg +1 -1
  182. package/dist/icons/price-label.svg +1 -1
  183. package/dist/icons/product-review.svg +1 -1
  184. package/dist/icons/quote.svg +3 -0
  185. package/dist/icons/receipt.svg +1 -1
  186. package/dist/icons/refund.svg +1 -1
  187. package/dist/icons/return.svg +1 -1
  188. package/dist/icons/sale-burst.svg +1 -1
  189. package/dist/icons/secure-checkout.svg +1 -1
  190. package/dist/icons/shirt.svg +1 -1
  191. package/dist/icons/shoe.svg +1 -1
  192. package/dist/icons/shopping-bag.svg +1 -1
  193. package/dist/icons/shopping-cart.svg +1 -1
  194. package/dist/icons/storefront.svg +1 -1
  195. package/dist/icons/support.svg +1 -1
  196. package/dist/icons/underline.svg +3 -0
  197. package/dist/icons/wallet.svg +1 -1
  198. package/dist/icons/warehouse.svg +1 -1
  199. package/dist/index.cjs +39 -11
  200. package/dist/index.css +11 -5
  201. package/dist/index.d.ts +1 -0
  202. package/dist/index.js +2130 -544
  203. package/dist/navigation-search.json +49 -0
  204. package/dist/navigation.css +1 -1
  205. package/dist/popover.css +1 -1
  206. package/dist/theme.css +3 -0
  207. package/package.json +10 -1
  208. package/dist/components/chunks/ScrollFade-Cg9fVO0V.js +0 -82
  209. package/dist/components/chunks/ScrollFade-Dfq2B1Hm.js +0 -1
  210. package/dist/components/chunks/caret-down-CpUOfgtN.js +0 -1
  211. package/dist/components/chunks/caret-right-CFbw7Ckp.js +0 -1
  212. package/dist/components/chunks/close-DljmolQP.js +0 -1
  213. package/dist/components/chunks/icon-BBZaAS5t.js +0 -1
  214. package/dist/components/chunks/icon-DgYUbNhm.js +0 -1
  215. package/dist/components/chunks/popover-CWWKb7L1.js +0 -1
  216. package/dist/components/chunks/search-BL-fP9qz.js +0 -1
@@ -0,0 +1,1544 @@
1
+
2
+ const __mintLoadStyle = (key, url) => {
3
+ if (typeof document === 'undefined') return
4
+ const href = new URL(url, import.meta.url).href
5
+ if ([...document.querySelectorAll('link[rel="stylesheet"]')].some(link => link.href === href)) return
6
+ if (document.querySelector('style[data-mint-ui-style="' + key + '"]') || document.querySelector('link[data-mint-ui-style="' + key + '"]')) return
7
+ const link = document.createElement('link')
8
+ link.rel = 'stylesheet'
9
+ link.href = href
10
+ link.dataset.mintUiStyle = key
11
+ document.head.append(link)
12
+ }
13
+ __mintLoadStyle('theme', '../../theme.css')
14
+ __mintLoadStyle('button', '../../button.css')
15
+ __mintLoadStyle('spinner', '../../spinner.css')
16
+ __mintLoadStyle('icon', '../../icon.css')
17
+ __mintLoadStyle('popover', '../../popover.css')
18
+ __mintLoadStyle('stack', '../../stack.css')
19
+ __mintLoadStyle('modal', '../../modal.css')
20
+ __mintLoadStyle('text', '../../text.css')
21
+ __mintLoadStyle('input', '../../input.css')
22
+ __mintLoadStyle('editor', '../../editor.css')
23
+ import { t as e } from "../chunks/register-element-BFYmIynH.js";
24
+ import "../chunks/icon-aNwWb0hA.js";
25
+ import "../chunks/button-THsh4Svz.js";
26
+ import "../chunks/modal-ss_OTDJJ.js";
27
+ import "../chunks/input-Bu4xPosP.js";
28
+ import "../chunks/popover-DD7uyRXy.js";
29
+ //#region src/components/editor/Editor.ts
30
+ function t(e) {
31
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\"/g, "&quot;");
32
+ }
33
+ function n(e) {
34
+ return e.replace(/\r\n?/g, "\n").split(/\n{2,}/).map((e) => {
35
+ let n = e.trim();
36
+ if (!n) return "";
37
+ let i = n.match(/^```(\w*)\n([\s\S]*?)\n```$/);
38
+ if (i) return `<pre><code${i[1] ? ` class=\"language-${t(i[1])}\"` : ""}>${t(i[2])}</code></pre>`;
39
+ let a = n.match(/^(#{1,6})\s+([\s\S]+)$/);
40
+ if (a) return `<h${a[1].length}>${r(a[2])}</h${a[1].length}>`;
41
+ if (/^>\s?/.test(n)) return `<blockquote><p>${r(n.replace(/^>\s?/gm, "").replace(/\n/g, " "))}</p></blockquote>`;
42
+ let o = n.split("\n").map((e) => e.trim()).filter(Boolean);
43
+ if (o.length >= 2 && /^\|?\s*:?-{3,}/.test(o[1]) && o[0].includes("|")) {
44
+ let e = [o[0], ...o.slice(2)].map((e) => e.replace(/^\|/, "").replace(/\|$/, "").split("|").map((e) => e.trim()));
45
+ return `<table><thead><tr>${(e.shift() || []).map((e) => `<th>${r(e)}</th>`).join("")}</tr></thead><tbody>${e.map((e) => `<tr>${e.map((e) => `<td>${r(e)}</td>`).join("")}</tr>`).join("")}</tbody></table>`;
46
+ }
47
+ if (/^[-*+]\s+\[[ xX]\]\s/.test(n)) return `<ul data-mint-task-list="true">${n.split("\n").map((e) => {
48
+ let t = e.match(/^[-*+]\s+\[([ xX])\]\s+(.*)$/);
49
+ return t ? `<li><input type="checkbox"${t[1].toLowerCase() === "x" ? " checked" : ""} contenteditable="false"><span>${r(t[2])}</span></li>` : "";
50
+ }).join("")}</ul>`;
51
+ if (/^([-*+]\s|\d+\.\s)/.test(n)) {
52
+ let e = n.split("\n"), t = /^\d+\./.test(e[0]);
53
+ return `<${t ? "ol" : "ul"}>${e.map((e) => `<li>${r(e.replace(/^(?:[-*+]\s|\d+\.\s)/, ""))}</li>`).join("")}</${t ? "ol" : "ul"}>`;
54
+ }
55
+ return `<p>${r(n.replace(/\n/g, " "))}</p>`;
56
+ }).join("");
57
+ }
58
+ function r(e) {
59
+ return t(e).replace(/`([^`]+)`/g, "<code>$1</code>").replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>").replace(/__(.+?)__/g, "<strong>$1</strong>").replace(/\*(.+?)\*/g, "<em>$1</em>").replace(/_(.+?)_/g, "<em>$1</em>").replace(/~~(.+?)~~/g, "<s>$1</s>").replace(/!\[([^\]]*)\]\(([^)]+)\)/g, "<img alt=\"$1\" src=\"$2\">").replace(/\[([^\]]+)\]\(([^)]+)\)/g, "<a href=\"$2\">$1</a>");
60
+ }
61
+ function i(e) {
62
+ let t = (e) => {
63
+ if (e.nodeType === Node.TEXT_NODE) return e.textContent || "";
64
+ if (e.nodeType !== Node.ELEMENT_NODE) return "";
65
+ let n = e, r = Array.from(n.childNodes).map(t).join(""), i = n.tagName.toLowerCase();
66
+ if (/^h[1-6]$/.test(i)) return `${"#".repeat(Number(i[1]))} ${r.trim()}\n\n`;
67
+ if (i === "p" || i === "div") return `${r.trim()}\n\n`;
68
+ if (i === "strong" || i === "b") return `**${r}**`;
69
+ if (i === "em" || i === "i") return `*${r}*`;
70
+ if (i === "u") return `<u>${r}</u>`;
71
+ if (i === "s" || i === "del") return `~~${r}~~`;
72
+ if (i === "code") return `\`${r}\``;
73
+ if (i === "pre") return `\`\`\`\n${n.textContent || ""}\n\`\`\`\n\n`;
74
+ if (i === "a") return `[${r}](${n.getAttribute("href") || ""})`;
75
+ if (i === "img") return `![${n.getAttribute("alt") || ""}](${n.getAttribute("src") || ""})`;
76
+ if (i === "br") return " \n";
77
+ if (i === "blockquote") return r.trim().split("\n").map((e) => `> ${e}`).join("\n") + "\n\n";
78
+ if (i === "ul" || i === "ol") {
79
+ let e = i === "ul" && n.hasAttribute("data-mint-task-list");
80
+ return Array.from(n.children).map((n, r) => {
81
+ if (e) {
82
+ let e = n.querySelector("input[type=\"checkbox\"]"), r = Array.from(n.childNodes).filter((e) => !(e.nodeType === Node.ELEMENT_NODE && e.tagName === "INPUT")).map(t).join("").trim();
83
+ return `- [${e?.checked ? "x" : " "}] ${r}`;
84
+ }
85
+ return `${i === "ol" ? `${r + 1}.` : "-"} ${t(n).trim()}`;
86
+ }).join("\n") + "\n\n";
87
+ }
88
+ return i === "input" && n.type === "checkbox" ? "" : i === "li" ? r : i === "table" ? Array.from(n.querySelectorAll("tr")).map((e) => `| ${Array.from(e.children).map((e) => (e.textContent || "").trim()).join(" | ")} |`).join("\n") + "\n\n" : i === "span" && n.classList.contains("mint-editor-image-frame") ? t(n.querySelector("img") || n) : r;
89
+ };
90
+ return Array.from(e.childNodes).map(t).join("").trim();
91
+ }
92
+ var a = class extends HTMLElement {
93
+ constructor(...e) {
94
+ super(...e), this.editor = null, this.editorFrame = null, this.pendingValue = null, this.source = null, this.toolbar = null, this.count = null, this.selectedImage = null, this.sourceMode = !1, this.observer = null, this.frameResizeObserver = null, this.resizeState = null, this.stageResizeState = null, this.editorHeight = null, this.sourceButton = null, this.blockButton = null, this.blockPopover = null, this.tablePopover = null, this.tableTrigger = null, this.selectedTableElement = null, this.inlineTableTools = null, this.tableResizeHandle = null, this.tableResizeState = null, this.gridResizeState = null, this.footerMode = null, this.inlineButtons = /* @__PURE__ */ new Map(), this.inlineOverrides = /* @__PURE__ */ new Map(), this.inlineStyleOverrides = /* @__PURE__ */ new Map(), this.preserveInlineOverridesOnNextEditorClick = !1, this.toolbarResizeObserver = null, this.overflowPopover = null, this.overflowTrigger = null, this.overflowGroups = [], this.tooltipPopup = null, this.fontSizeDisplay = null, this.lastTextColor = "#202833", this.lastBackgroundColor = "#fff2a8", this.colorTriggers = /* @__PURE__ */ new Map(), this.colorRecentSwatches = /* @__PURE__ */ new Map(), this.alignmentTrigger = null, this.onStageResizeStart = (e, t) => {
95
+ if (e.button !== 0) return;
96
+ e.preventDefault(), e.stopPropagation(), this.stageResizeState = {
97
+ stage: t,
98
+ startY: e.clientY,
99
+ startHeight: t.getBoundingClientRect().height,
100
+ pointerId: e.pointerId
101
+ };
102
+ let n = this.ownerDocument.defaultView;
103
+ n?.addEventListener("pointermove", this.onStageResizeMove), n?.addEventListener("pointerup", this.onStageResizeEnd), n?.addEventListener("pointercancel", this.onStageResizeEnd);
104
+ }, this.onStageResizeMove = (e) => {
105
+ let t = this.stageResizeState;
106
+ if (!t || e.pointerId !== t.pointerId) return;
107
+ e.preventDefault();
108
+ let n = Math.max(320, Math.min(1600, (this.ownerDocument.defaultView?.innerHeight || 900) * .9)), r = Math.round(Math.max(160, Math.min(n, t.startHeight + e.clientY - t.startY)));
109
+ t.stage.style.height = `${r}px`, this.editorHeight = r;
110
+ }, this.onStageResizeEnd = (e) => {
111
+ !this.stageResizeState || e.pointerId !== this.stageResizeState.pointerId || (this.stageResizeState = null, this.removeStageResizeListeners());
112
+ }, this.onTableResizeMove = (e) => {
113
+ let t = this.tableResizeState;
114
+ if (!t || e.pointerId !== t.pointerId) return;
115
+ let n = this.editor?.clientWidth || t.startWidth + 300;
116
+ t.table.style.width = `${Math.max(160, Math.min(n, t.startWidth + e.clientX - t.startX))}px`, t.table.style.height = `${Math.max(60, t.startHeight + e.clientY - t.startY)}px`, this.positionTableTools();
117
+ }, this.onTableResizeEnd = (e) => {
118
+ !this.tableResizeState || e.pointerId !== this.tableResizeState.pointerId || (this.tableResizeState = null, this.ownerDocument.defaultView?.removeEventListener("pointermove", this.onTableResizeMove), this.ownerDocument.defaultView?.removeEventListener("pointerup", this.onTableResizeEnd), this.emitChange());
119
+ }, this.onGridResizeMove = (e) => {
120
+ let t = this.gridResizeState;
121
+ if (!(!t || e.pointerId !== t.pointerId)) {
122
+ if (t.kind === "row") {
123
+ let n = t.table.rows[t.index];
124
+ n && (n.style.height = `${Math.max(28, t.size + e.clientY - t.start)}px`);
125
+ } else {
126
+ this.ensureTableColumns(t.table);
127
+ let n = t.table.querySelectorAll("col")[t.index];
128
+ n && (n.style.width = `${Math.max(48, t.size + e.clientX - t.start)}px`);
129
+ }
130
+ this.positionTableTools();
131
+ }
132
+ }, this.onGridResizeEnd = (e) => {
133
+ if (!this.gridResizeState || e.pointerId !== this.gridResizeState.pointerId) return;
134
+ this.gridResizeState = null;
135
+ let t = this.editor?.ownerDocument.defaultView;
136
+ t?.removeEventListener("pointermove", this.onGridResizeMove), t?.removeEventListener("pointerup", this.onGridResizeEnd), t?.removeEventListener("pointercancel", this.onGridResizeEnd), this.emitChange();
137
+ }, this.onResizeMove = (e) => {
138
+ if (!this.resizeState || e.pointerId !== this.resizeState.pointerId) return;
139
+ let t = this.editor?.clientWidth || 1e3, n = Math.max(80, Math.min(t, this.resizeState.startWidth + e.clientX - this.resizeState.startX));
140
+ this.resizeState.frame.style.width = `${n}px`;
141
+ }, this.onResizeEnd = (e) => {
142
+ !this.resizeState || e.pointerId !== this.resizeState.pointerId || (this.resizeState = null, this.editor?.ownerDocument.defaultView?.removeEventListener("pointermove", this.onResizeMove), this.editor?.ownerDocument.defaultView?.removeEventListener("pointerup", this.onResizeEnd), this.emitChange());
143
+ };
144
+ }
145
+ static get observedAttributes() {
146
+ return [
147
+ "label",
148
+ "placeholder",
149
+ "disabled",
150
+ "error",
151
+ "height",
152
+ "compact",
153
+ "format",
154
+ "value",
155
+ "resizable"
156
+ ];
157
+ }
158
+ connectedCallback() {
159
+ this.editor || this.render(), this.observer = new MutationObserver(() => this.updateWordCount()), this.editor && this.observer.observe(this.editor, {
160
+ childList: !0,
161
+ subtree: !0,
162
+ characterData: !0
163
+ }), this.ownerDocument.defaultView?.addEventListener("resize", this.positionTableTools);
164
+ }
165
+ disconnectedCallback() {
166
+ this.toolbarResizeObserver?.disconnect(), this.toolbarResizeObserver = null, this.tooltipPopup?.remove(), this.tooltipPopup = null, this.frameResizeObserver?.disconnect(), this.frameResizeObserver = null, this.observer?.disconnect(), this.observer = null, this.ownerDocument.defaultView?.removeEventListener("resize", this.positionTableTools), this.editor?.ownerDocument.defaultView?.removeEventListener("pointermove", this.onResizeMove), this.editor?.ownerDocument.defaultView?.removeEventListener("pointerup", this.onResizeEnd), this.ownerDocument.defaultView?.removeEventListener("pointermove", this.onTableResizeMove), this.ownerDocument.defaultView?.removeEventListener("pointerup", this.onTableResizeEnd);
167
+ let e = this.editor?.ownerDocument.defaultView;
168
+ e?.removeEventListener("pointermove", this.onGridResizeMove), e?.removeEventListener("pointerup", this.onGridResizeEnd), this.removeStageResizeListeners();
169
+ }
170
+ attributeChangedCallback(e, t, r) {
171
+ if (this.isConnected) {
172
+ if (e === "format") {
173
+ t !== r && (this.updateFormatUI(), this.sourceMode && this.source && this.editor ? this.editor.innerHTML = r === "markdown" ? n(this.source.value) : this.source.value : r === "markdown" && t !== "markdown" && this.editor && (this.editor.innerHTML = n(this.editor.innerHTML)), this.syncSource());
174
+ return;
175
+ }
176
+ if (e === "value") {
177
+ this.setValue(r || "");
178
+ return;
179
+ }
180
+ e === "height" && (this.editorHeight = null), this.render();
181
+ }
182
+ }
183
+ get format() {
184
+ return this.getAttribute("format") === "markdown" ? "markdown" : "html";
185
+ }
186
+ set format(e) {
187
+ this.setAttribute("format", e === "markdown" ? "markdown" : "html");
188
+ }
189
+ get value() {
190
+ if (this.sourceMode && this.source) return this.source.value;
191
+ if (!this.editor) return "";
192
+ let e = this.cleanEditorCopy();
193
+ return this.format === "markdown" ? i(e) : e.innerHTML;
194
+ }
195
+ set value(e) {
196
+ this.setValue(e || "");
197
+ }
198
+ setValue(e) {
199
+ if (!this.editor) {
200
+ this.pendingValue = e, this.getAttribute("value") !== e && this.setAttribute("value", e);
201
+ return;
202
+ }
203
+ this.editor.innerHTML = this.format === "markdown" ? n(e) : e, this.clearInlineTypingState(), this.source && (this.source.value = e), this.updateWordCount();
204
+ }
205
+ insertResource(e) {
206
+ let t = typeof e == "string" ? { url: e } : e, n = t.url || t.src;
207
+ if (!n || !this.editor) return;
208
+ this.editor.focus(), this.restoreSelection();
209
+ let r = this.editor.ownerDocument, i = r.createElement("span");
210
+ i.className = "mint-editor-image-frame", i.contentEditable = "false", i.style.width = "min(100%, 420px)";
211
+ let a = r.createElement("img");
212
+ a.src = n, a.alt = t.alt || t.label || "", a.draggable = !1, i.append(a, this.createResizeHandle());
213
+ let o = this.selection;
214
+ if (o?.rangeCount && this.editor.contains(o.anchorNode)) {
215
+ let e = o.getRangeAt(0);
216
+ e.deleteContents(), e.insertNode(i), e.setStartAfter(i), e.collapse(!0), o.removeAllRanges(), o.addRange(e);
217
+ } else this.editor.append(i, r.createElement("br"));
218
+ this.selectImage(i), this.emitChange();
219
+ }
220
+ render() {
221
+ let e = this.editor?.innerHTML ?? this.getAttribute("value") ?? this.innerHTML, r = this.editor ? e : this.format === "markdown" ? n(e) : e;
222
+ this.observer?.disconnect(), this.inlineButtons.clear(), this.colorTriggers.clear(), this.colorRecentSwatches.clear(), this.clearInlineTypingState(), this.editor = null, this.selectedImage = null;
223
+ let i = this.hasAttribute("disabled") && this.getAttribute("disabled") !== "false", a = this.editorHeight === null ? this.getAttribute("height") || "300px" : `${this.editorHeight}px`, o = this.getAttribute("label") || "";
224
+ this.innerHTML = "";
225
+ let s = document.createElement("div");
226
+ if (s.className = "mint-editor-root", this.hasAttribute("error") && s.classList.add("mint-editor-has-error"), this.hasAttribute("compact") && s.classList.add("mint-editor-compact"), o) {
227
+ let e = document.createElement("label");
228
+ e.className = "mint-editor-label", e.textContent = o, e.id = `${this.id || "mint-editor"}-label`, s.append(e);
229
+ }
230
+ let c = document.createElement("div");
231
+ c.className = "mint-editor-shell";
232
+ let l = document.createElement("div");
233
+ l.className = "mint-editor-toolbar", l.setAttribute("role", "toolbar"), l.setAttribute("aria-label", "Text formatting"), this.toolbar = l, this.buildToolbar(l);
234
+ let u = document.createElement("div");
235
+ u.className = "mint-editor-inline-table-tools", u.setAttribute("role", "toolbar"), u.setAttribute("aria-label", "Table tools"), u.hidden = !0;
236
+ for (let [e, t] of [
237
+ ["Add row above", "arrow-up"],
238
+ ["Add row below", "arrow-down"],
239
+ ["Delete row", "remove"],
240
+ ["Add column left", "arrow-left"],
241
+ ["Add column right", "arrow-right"],
242
+ ["Delete column", "remove"],
243
+ ["Delete table", "trash"]
244
+ ]) {
245
+ let n = document.createElement("button");
246
+ n.type = "button", n.className = "mint-editor-table-tool-button", this.setTooltip(n, e), n.append(this.icon(t)), n.addEventListener("pointerdown", (e) => {
247
+ e.preventDefault(), this.saveSelection();
248
+ }), n.addEventListener("click", () => this.applyTableAction(e)), u.append(n);
249
+ }
250
+ let d = document.createElement("button");
251
+ d.type = "button", d.className = "mint-editor-table-resize-handle", this.setTooltip(d, "Resize table"), d.addEventListener("pointerdown", (e) => this.startTableResize(e)), this.inlineTableTools = u, this.tableResizeHandle = d;
252
+ let f = document.createElement("iframe");
253
+ f.className = "mint-editor-frame", f.title = o ? `${o} editor` : "Rich text editor", f.setAttribute("sandbox", "allow-same-origin"), f.style.height = "100%", f.srcdoc = `<!doctype html><html><head><meta charset="utf-8"><style>
254
+ html,body{box-sizing:border-box;width:100%;height:100%;min-width:0;margin:0;overflow:hidden}
255
+ .editor{box-sizing:border-box;width:100%;height:100%;min-width:0;min-height:0;overflow:auto;overflow-wrap:anywhere;padding:1rem;outline:0;color:var(--mint-color-text,#202833);background:var(--mint-color-surface,#fff);font:inherit;line-height:1.55}
256
+ .editor:empty:before{content:attr(data-placeholder);color:var(--mint-color-text-muted,#7b8492);pointer-events:none}
257
+ .editor :where(img,video,iframe,table,pre){max-width:100%}.editor img,.editor video{height:auto}.editor pre,.editor table{overflow:auto}
258
+ .editor :where(h1,h2,h3){max-width:100%;overflow-wrap:anywhere;line-height:1.2}.editor h1{font-size:2em}.editor h2{font-size:1.5em}.editor h3{font-size:1.2em}
259
+ .editor :where(p,ul,ol,blockquote,table){max-width:100%;overflow-wrap:anywhere;margin:.65em 0}.editor a{color:var(--mint-color-primary,#1e5bff);text-decoration:underline}
260
+ .editor table{width:100%;border-collapse:collapse;table-layout:fixed}.editor table.is-selected{outline:2px solid var(--mint-color-primary,#1e5bff);outline-offset:2px}.editor :where(td,th){box-sizing:border-box;min-width:3rem;max-width:none;overflow-wrap:anywhere;padding:.5rem;border:1px solid var(--mint-color-border,#dfe3e9);text-align:left;vertical-align:top}.editor th{background:var(--mint-color-surface-subtle,#f8f9fb);font-weight:600}
261
+ .editor ul[data-mint-task-list]{padding-left:1.6rem;list-style:none}.editor ul[data-mint-task-list] li{display:flex;align-items:flex-start;gap:.5rem}.editor ul[data-mint-task-list] input[type=checkbox]{flex:0 0 auto;margin:.45em 0 0;accent-color:var(--mint-color-primary,#1e5bff)}
262
+ .editor .mint-editor-comment{border-radius:.15rem;background:rgb(255 224 130 / 45%);box-shadow:0 1px 0 rgb(198 120 0 / 65%);cursor:help}
263
+ .mint-editor-image-frame{position:relative;display:inline-block;max-width:100%;margin:.5rem 0;vertical-align:middle}.mint-editor-image-frame img{display:block;width:100%;height:auto;max-height:none;border-radius:.25rem;object-fit:contain}.mint-editor-image-frame.is-selected{outline:2px solid var(--mint-color-primary,#1e5bff);outline-offset:2px}
264
+ .mint-editor-resize-handle{position:absolute;right:-.45rem;bottom:-.45rem;width:.9rem;height:.9rem;padding:0;border:2px solid var(--mint-color-surface,#fff);border-radius:50%;background:var(--mint-color-primary,#1e5bff);cursor:nwse-resize;touch-action:none}
265
+ @media(max-width:640px){.editor{padding:.75rem}}
266
+ </style></head><body><div class="editor" contenteditable="${!i}" role="textbox" aria-multiline="true" aria-label="${t(o || "Rich text editor")}" data-placeholder="${t(this.getAttribute("placeholder") || "Start writing…")}"></div></body></html>`, f.addEventListener("load", () => this.bindEditorFrame(r, i)), this.editorFrame = f;
267
+ let p = document.createElement("textarea");
268
+ p.className = "mint-editor-source", p.style.height = "100%", p.setAttribute("aria-label", `Editor ${this.format.toUpperCase()} source`), p.hidden = !0, p.value = this.format === "markdown" ? e : r, p.addEventListener("input", () => {
269
+ this.editor && (this.editor.innerHTML = this.format === "markdown" ? n(p.value) : p.value), this.updateWordCount(), this.emitChange();
270
+ }), this.source = p;
271
+ let m = document.createElement("div");
272
+ m.className = "mint-editor-stage", m.style.height = a, m.append(f, p);
273
+ let h = null;
274
+ [
275
+ "false",
276
+ "0",
277
+ "off",
278
+ "no"
279
+ ].includes((this.getAttribute("resizable") || "").trim().toLowerCase()) || (h = document.createElement("button"), h.type = "button", h.className = "mint-editor-stage-resize-handle", this.setTooltip(h, "Resize editor"), h.addEventListener("pointerdown", (e) => this.onStageResizeStart(e, m))), c.append(l, m, u, d);
280
+ let g = document.createElement("div");
281
+ g.className = "mint-editor-image-tools", g.hidden = !0, g.innerHTML = "<span>Image width</span><mint-input type=\"number\" min=\"10\" max=\"100\" value=\"100\" aria-label=\"Image width percent\"></mint-input><span>%</span><mint-button variant=\"ghost\" data-align=\"left\">Left</mint-button><mint-button variant=\"ghost\" data-align=\"center\">Center</mint-button><mint-button variant=\"ghost\" data-align=\"right\">Right</mint-button><mint-button variant=\"ghost\" data-remove=\"image\">Remove</mint-button>", g.querySelectorAll("[data-align]").forEach((e) => this.setTooltip(e, `Align image ${e.dataset.align}`));
282
+ let _ = g.querySelector("[data-remove=\"image\"]");
283
+ _ && this.setTooltip(_, "Remove image"), g.querySelector("mint-input")?.addEventListener("input", (e) => {
284
+ if (!this.selectedImage) return;
285
+ let t = Number(e.target.value);
286
+ this.selectedImage.style.width = `${Math.max(10, Math.min(100, t))}%`, this.emitChange();
287
+ }), g.querySelectorAll("[data-align]").forEach((e) => e.addEventListener("click", () => {
288
+ this.selectedImage && (this.selectedImage.style.marginLeft = e.dataset.align === "right" || e.dataset.align === "center" ? "auto" : "0", this.selectedImage.style.marginRight = e.dataset.align === "left" || e.dataset.align === "center" ? "auto" : "0", this.emitChange());
289
+ })), g.querySelector("[data-remove=\"image\"]")?.addEventListener("click", () => {
290
+ this.selectedImage?.remove(), this.selectImage(null), this.emitChange();
291
+ }), s.append(c, g);
292
+ let v = document.createElement("div");
293
+ v.className = "mint-editor-footer";
294
+ let y = document.createElement("span");
295
+ y.className = "mint-editor-mode", y.textContent = "p";
296
+ let b = document.createElement("span");
297
+ b.className = "mint-editor-word-count", this.count = b;
298
+ let x = document.createElement("div");
299
+ x.className = "mint-editor-footer-end", x.append(b), h && x.append(h), v.append(y, x), this.footerMode = y, c.append(v);
300
+ let S = this.getAttribute("error");
301
+ if (S) {
302
+ let e = document.createElement("div");
303
+ e.className = "mint-editor-error", e.textContent = S, s.append(e);
304
+ }
305
+ this.append(s);
306
+ let C = this.querySelector(".mint-editor-stage");
307
+ if (C && typeof ResizeObserver < "u" && (this.frameResizeObserver?.disconnect(), this.frameResizeObserver = new ResizeObserver(([e]) => {
308
+ if (!e || !this.editorFrame) return;
309
+ let t = Math.max(0, e.contentRect.width), n = Math.max(0, e.contentRect.height);
310
+ this.editorFrame.style.width = `${t}px`, this.editorFrame.style.height = `${n}px`;
311
+ }), this.frameResizeObserver.observe(C)), this.toolbar && typeof ResizeObserver < "u") {
312
+ this.toolbarResizeObserver?.disconnect(), this.toolbarResizeObserver = new ResizeObserver(() => this.updateToolbarOverflow()), this.toolbarResizeObserver.observe(this.toolbar);
313
+ let e = this.toolbar.querySelector(".mint-editor-toolbar-actions");
314
+ e && this.toolbarResizeObserver.observe(e), requestAnimationFrame(() => this.updateToolbarOverflow());
315
+ }
316
+ this.sourceMode = !1, this.observer && this.editor && this.observer.observe(this.editor, {
317
+ childList: !0,
318
+ subtree: !0,
319
+ characterData: !0
320
+ }), this.updateWordCount(), this.updateFormatUI();
321
+ }
322
+ removeStageResizeListeners() {
323
+ let e = this.ownerDocument.defaultView;
324
+ e?.removeEventListener("pointermove", this.onStageResizeMove), e?.removeEventListener("pointerup", this.onStageResizeEnd), e?.removeEventListener("pointercancel", this.onStageResizeEnd), this.stageResizeState = null;
325
+ }
326
+ bindEditorFrame(e, t) {
327
+ let r = this.editorFrame?.contentDocument, i = r?.querySelector(".editor");
328
+ if (!r || !i) return;
329
+ i.contentEditable = String(!t), i.innerHTML = this.pendingValue === null ? e : this.format === "markdown" ? n(this.pendingValue) : this.pendingValue, this.pendingValue = null;
330
+ let a = getComputedStyle(this), o = r.body;
331
+ o.style.font = a.font, o.style.color = a.color, o.style.background = a.backgroundColor, getComputedStyle(i), i.style.font = a.font, i.style.background = a.backgroundColor, [
332
+ "text",
333
+ "text-muted",
334
+ "surface",
335
+ "surface-subtle",
336
+ "border",
337
+ "primary",
338
+ "focus"
339
+ ].forEach((e) => {
340
+ let t = a.getPropertyValue(`--mint-color-${e}`).trim();
341
+ t && i.style.setProperty(`--mint-color-${e}`, t);
342
+ }), this.editor = i, i.addEventListener("input", () => {
343
+ this.normalizeTaskListItems(), this.syncSource(), this.emitChange(), this.updateSelectionUI();
344
+ }), i.addEventListener("change", (e) => {
345
+ let t = e.target;
346
+ t.matches("ul[data-mint-task-list] input[type=\"checkbox\"]") && (t.toggleAttribute("checked", t.checked), this.emitChange());
347
+ }), i.addEventListener("paste", (e) => {
348
+ let t = e.clipboardData?.getData("text/html") || "";
349
+ if (!t || !this.editor?.contains(this.selection?.anchorNode || null)) return;
350
+ let n = this.sanitizePastedHtml(t);
351
+ n && (e.preventDefault(), this.clearInlineTypingState(), this.insertPastedHtml(n), this.normalizeTaskListItems(), this.emitChange(), this.updateSelectionUI());
352
+ }), i.addEventListener("beforeinput", (e) => {
353
+ let t = e;
354
+ t.inputType.startsWith("insert") && (this.preserveInlineOverridesOnNextEditorClick = !1);
355
+ let n = t.shiftKey;
356
+ if ((t.inputType === "insertParagraph" || t.inputType === "insertLineBreak" && !n) && !t.isComposing) {
357
+ let e = this.selection?.anchorNode, n = (e?.nodeType === Node.ELEMENT_NODE ? e : e?.parentElement)?.closest("li"), r = n?.parentElement;
358
+ if (n && r?.tagName === "UL" && r.hasAttribute("data-mint-task-list") && this.editor?.contains(n)) {
359
+ t.preventDefault(), this.isEmptyTaskItem(n) ? this.exitTaskList(n, r) : this.splitTaskItem(n, r);
360
+ return;
361
+ }
362
+ }
363
+ this.applyInlineTypingState(t);
364
+ }), i.addEventListener("keyup", (e) => {
365
+ [
366
+ "ArrowLeft",
367
+ "ArrowRight",
368
+ "ArrowUp",
369
+ "ArrowDown",
370
+ "Home",
371
+ "End",
372
+ "PageUp",
373
+ "PageDown"
374
+ ].includes(e.key) && this.clearInlineTypingState(), this.updateSelectedImage(), this.updateSelectionUI();
375
+ }), i.addEventListener("mouseup", () => {
376
+ this.updateSelectedImage(), this.updateSelectionUI();
377
+ }), r.addEventListener("selectionchange", () => this.updateSelectionUI()), i.addEventListener("scroll", () => this.positionTableTools()), i.addEventListener("pointermove", (e) => this.updateGridResizeCursor(e)), r.addEventListener("pointerdown", (e) => this.startGridResize(e), !0), i.addEventListener("click", (e) => {
378
+ this.closeEditorPopovers(), this.preserveInlineOverridesOnNextEditorClick ? this.preserveInlineOverridesOnNextEditorClick = !1 : this.clearInlineTypingState();
379
+ let t = e.target, n = t.closest(".mint-editor-image-frame");
380
+ n ? this.selectImage(n) : t.closest(".mint-editor-image-tools") || this.selectImage(null);
381
+ let r = t.closest("table");
382
+ this.selectTable(r), t.closest("a") && e.preventDefault();
383
+ }), i.addEventListener("keydown", (e) => {
384
+ if (e.key === "Enter" && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey && !e.isComposing) {
385
+ let t = this.selection, n = t?.anchorNode, r = (n?.nodeType === Node.ELEMENT_NODE ? n : n?.parentElement)?.closest("li"), i = r?.parentElement;
386
+ if (t?.isCollapsed && r && i?.tagName === "UL" && i.hasAttribute("data-mint-task-list") && this.editor?.contains(r)) {
387
+ e.preventDefault(), this.isEmptyTaskItem(r) ? this.exitTaskList(r, i) : this.splitTaskItem(r, i);
388
+ return;
389
+ }
390
+ }
391
+ (e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "b" && (e.preventDefault(), this.toggleInline("bold")), (e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "i" && (e.preventDefault(), this.toggleInline("italic")), (e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "u" && (e.preventDefault(), this.toggleInline("underline"));
392
+ }), this.observer && this.observer.observe(i, {
393
+ childList: !0,
394
+ subtree: !0,
395
+ characterData: !0
396
+ }), this.updateWordCount(), this.updateSelectionUI();
397
+ }
398
+ buildToolbar(e) {
399
+ let t = (t, n, r, i = e) => {
400
+ let a = document.createElement("button");
401
+ return a.type = "button", a.className = `mint-editor-tool-button mint-editor-toolbar-${n}`, this.setTooltip(a, t), a.append(this.icon(n)), a.addEventListener("pointerdown", () => this.saveSelection()), a.addEventListener("click", (e) => {
402
+ e.preventDefault(), r();
403
+ }), i.append(a), a;
404
+ }, n = (e, t, n) => {
405
+ let r = document.createElement("mint-popover");
406
+ return r.id = `${e.id}-menu`, r.setAttribute("trigger-id", e.id), r.setAttribute("padding", "0.25rem"), r.setAttribute("direction", "down"), r.className = `mint-editor-menu-popover ${t}`, n.append(r), r;
407
+ }, r = (e, t, n, r) => {
408
+ let i = this.createMenuOption(t, n);
409
+ return i.addEventListener("click", r), e.append(i), i;
410
+ };
411
+ t("Undo", "undo", () => this.command("undo")), t("Redo", "redo", () => this.command("redo"));
412
+ let i = document.createElement("button");
413
+ i.type = "button", i.className = "mint-editor-tool-button mint-editor-block-trigger", this.setTooltip(i, "Text style"), i.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-block-trigger`;
414
+ let a = document.createElement("span");
415
+ a.className = "mint-editor-block-label", a.textContent = "Paragraph", i.append(a, this.icon("caret-down")), i.addEventListener("pointerdown", () => this.saveSelection()), this.blockButton = i, e.append(i);
416
+ let o = n(i, "mint-editor-block-popover", e);
417
+ [
418
+ [
419
+ "p",
420
+ "Paragraph",
421
+ "paragraph"
422
+ ],
423
+ [
424
+ "h1",
425
+ "Heading 1",
426
+ "heading"
427
+ ],
428
+ [
429
+ "h2",
430
+ "Heading 2",
431
+ "heading"
432
+ ],
433
+ [
434
+ "h3",
435
+ "Heading 3",
436
+ "heading"
437
+ ],
438
+ [
439
+ "blockquote",
440
+ "Quote",
441
+ "quote"
442
+ ],
443
+ [
444
+ "div",
445
+ "Div",
446
+ "code"
447
+ ]
448
+ ].forEach(([e, t, n]) => {
449
+ let r = this.createMenuOption(t, n);
450
+ r.dataset.blockTag = e, r.addEventListener("click", () => {
451
+ this.command("formatBlock", e), o.close(), this.updateSelectionUI();
452
+ }), o.append(r);
453
+ }), this.blockPopover = o;
454
+ let s = document.createElement("div");
455
+ s.className = "mint-editor-font-size-control", t("Decrease font size", "minus", () => this.applyFontSize(this.readFontSize() - 1), s);
456
+ let c = document.createElement("button");
457
+ c.type = "button", c.className = "mint-editor-tool-button mint-editor-font-size-value", c.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-font-size-trigger`, c.setAttribute("aria-label", "Font size");
458
+ let l = document.createElement("span");
459
+ l.textContent = "16px", c.append(l, this.icon("caret-down")), c.addEventListener("pointerdown", () => this.saveSelection()), s.append(c), t("Increase font size", "plus", () => this.applyFontSize(this.readFontSize() + 1), s), this.fontSizeDisplay = l;
460
+ let u = document.createElement("div");
461
+ u.className = "mint-editor-toolbar-actions", e.append(u), u.append(s);
462
+ let d = n(c, "mint-editor-font-size-popover", u), f = [[s, d]];
463
+ [
464
+ 8,
465
+ 9,
466
+ 10,
467
+ 11,
468
+ 12,
469
+ 14,
470
+ 16,
471
+ 18,
472
+ 20,
473
+ 24,
474
+ 28,
475
+ 32,
476
+ 36,
477
+ 48,
478
+ 72
479
+ ].forEach((e) => {
480
+ let t = document.createElement("button");
481
+ t.type = "button", t.className = "mint-editor-menu-option mint-editor-font-size-option", t.textContent = `${e}px`, t.addEventListener("click", () => {
482
+ this.applyFontSize(e), d.close();
483
+ }), d.append(t);
484
+ });
485
+ let p = (e, n, r) => {
486
+ let i = t(e, n, r, u);
487
+ return [
488
+ "bold",
489
+ "italic",
490
+ "underline"
491
+ ].includes(n) && (i.setAttribute("aria-pressed", "false"), this.inlineButtons.set(n, i)), i;
492
+ }, m = (e) => {
493
+ let t = e.querySelector(":scope > mint-icon");
494
+ if (!t) return;
495
+ let n = document.createElement("span");
496
+ n.className = "mint-editor-color-icon", e.insertBefore(n, t), n.append(t);
497
+ }, h = () => {
498
+ let e = this.separator();
499
+ return u.append(e), f.push([e]), e;
500
+ }, g = p("Bold", "bold", () => this.toggleInline("bold")), _ = p("Italic", "italic", () => this.toggleInline("italic")), v = p("Underline", "underline", () => this.toggleInline("underline"));
501
+ f.push([g], [_], [v]);
502
+ let y = this.separator();
503
+ u.append(y);
504
+ let b = p("Text color", "text-color", () => {});
505
+ b.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-text-color-trigger`, b.append(this.icon("caret-down")), b.classList.add("mint-editor-color-trigger"), m(b), b.style.setProperty("--editor-color", this.lastTextColor);
506
+ let x = n(b, "mint-editor-color-popover", u);
507
+ this.buildColorPopover(x, "text", b), this.colorTriggers.set("text", b);
508
+ let S = p("Highlight color", "highlight", () => {});
509
+ S.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-highlight-trigger`, S.append(this.icon("caret-down")), S.classList.add("mint-editor-color-trigger"), m(S), S.style.setProperty("--editor-color", this.lastBackgroundColor);
510
+ let C = n(S, "mint-editor-color-popover", u);
511
+ this.buildColorPopover(C, "background", S), this.colorTriggers.set("background", S), f.push([
512
+ y,
513
+ b,
514
+ x,
515
+ S,
516
+ C
517
+ ]);
518
+ let w = p("Font family", "font-family", () => {});
519
+ w.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-font-family-trigger`, w.append(this.icon("caret-down"));
520
+ let T = n(w, "mint-editor-font-family-popover", u);
521
+ [
522
+ ["Arial", "Arial, sans-serif"],
523
+ ["Helvetica", "Helvetica, sans-serif"],
524
+ ["Georgia", "Georgia, serif"],
525
+ ["Times New Roman", "\"Times New Roman\", serif"],
526
+ ["Courier New", "\"Courier New\", monospace"],
527
+ ["System UI", "system-ui, sans-serif"]
528
+ ].forEach(([e, t]) => {
529
+ r(T, e, "font-family", () => {
530
+ this.applyFontFamily(t), T.close();
531
+ });
532
+ }), f.push([w, T]), h();
533
+ let E = p("Insert link", "link", () => this.openLinkModal()), D = p("Insert image", "image", () => this.requestResource()), O = p("Insert table", "table", () => this.openTableModal()), k = document.createElement("button");
534
+ k.type = "button", k.className = "mint-editor-tool-button", this.setTooltip(k, "Table options"), k.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-table-trigger`, k.append(this.icon("caret-down")), k.hidden = !0, u.append(k);
535
+ let A = n(k, "", u);
536
+ this.tablePopover = A, [
537
+ ["Add row below", "table-row"],
538
+ ["Add column right", "table-column"],
539
+ ["Delete row", "table-row-delete"],
540
+ ["Delete column", "table-column-delete"],
541
+ ["Delete table", "trash"]
542
+ ].forEach(([e, t]) => {
543
+ let n = this.createMenuOption(e, t);
544
+ n.addEventListener("click", () => {
545
+ this.applyTableAction(e), A.close();
546
+ }), A.append(n);
547
+ }), k.addEventListener("pointerdown", () => this.saveSelection()), this.tableTrigger = k, f.push([E], [D], [
548
+ O,
549
+ k,
550
+ A
551
+ ]);
552
+ let j = p("Add comment", "comment-plus", () => this.openCommentModal());
553
+ f.push([j]), h();
554
+ let M = p("Text alignment", "align-left", () => {});
555
+ M.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-alignment-trigger`, M.append(this.icon("caret-down")), this.alignmentTrigger = M;
556
+ let N = n(M, "mint-editor-alignment-popover", u);
557
+ [
558
+ [
559
+ "Align left",
560
+ "align-left",
561
+ "justifyLeft"
562
+ ],
563
+ [
564
+ "Align center",
565
+ "align-center",
566
+ "justifyCenter"
567
+ ],
568
+ [
569
+ "Align right",
570
+ "align-right",
571
+ "justifyRight"
572
+ ],
573
+ [
574
+ "Justify",
575
+ "align-justify",
576
+ "justifyFull"
577
+ ]
578
+ ].forEach(([e, t, n]) => {
579
+ r(N, e, t, () => {
580
+ this.command(n), N.close(), this.updateTooltipLabel(M, `Text alignment: ${e}`);
581
+ });
582
+ }), f.push([M, N]), h();
583
+ let P = p("Bulleted list", "list", () => this.command("insertUnorderedList")), F = document.createElement("button");
584
+ F.type = "button", F.className = "mint-editor-tool-button mint-editor-list-options-trigger", F.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-bullet-options-trigger`, this.setTooltip(F, "Bulleted list style"), F.append(this.icon("caret-down")), F.addEventListener("pointerdown", () => this.saveSelection()), u.append(F);
585
+ let I = n(F, "mint-editor-list-popover", u);
586
+ [
587
+ ["Disc", "disc"],
588
+ ["Circle", "circle"],
589
+ ["Square", "square"]
590
+ ].forEach(([e, t]) => r(I, e, "list", () => {
591
+ this.applyListStyle("ul", t), I.close();
592
+ }));
593
+ let L = p("Numbered list", "numbered-list", () => this.command("insertOrderedList")), R = document.createElement("button");
594
+ R.type = "button", R.className = "mint-editor-tool-button mint-editor-list-options-trigger", R.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-numbered-options-trigger`, this.setTooltip(R, "Numbered list style"), R.append(this.icon("caret-down")), R.addEventListener("pointerdown", () => this.saveSelection()), u.append(R);
595
+ let z = n(R, "mint-editor-list-popover", u);
596
+ [
597
+ ["Numbers", "decimal"],
598
+ ["Lowercase letters", "lower-alpha"],
599
+ ["Uppercase letters", "upper-alpha"],
600
+ ["Lowercase Roman numerals", "lower-roman"],
601
+ ["Uppercase Roman numerals", "upper-roman"]
602
+ ].forEach(([e, t]) => r(z, e, "numbered-list", () => {
603
+ this.applyListStyle("ol", t), z.close();
604
+ }));
605
+ let B = p("Checklist", "checklist", () => this.toggleChecklist());
606
+ f.push([
607
+ P,
608
+ F,
609
+ I
610
+ ], [
611
+ L,
612
+ R,
613
+ z
614
+ ], [B]), h();
615
+ let V = p("HTML source", "code", () => this.toggleSource());
616
+ f.push([V]), this.sourceButton = e.querySelector(".mint-editor-toolbar-code");
617
+ let H = p("Clear formatting", "clear-formatting", () => this.clearFormatting());
618
+ f.push([H]);
619
+ let U = document.createElement("button");
620
+ U.type = "button", U.className = "mint-editor-tool-button mint-editor-overflow-trigger", this.setTooltip(U, "More formatting options"), U.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-overflow-trigger`, U.append(this.icon("ellipsis"));
621
+ let W = document.createElement("mint-popover");
622
+ W.setAttribute("trigger-id", U.id), W.setAttribute("padding", "0.25rem"), W.setAttribute("direction", "down"), W.className = "mint-editor-menu-popover mint-editor-overflow-popover", e.append(U, W), this.overflowTrigger = U, this.overflowPopover = W, this.overflowGroups = f;
623
+ }
624
+ buildColorPopover(e, t, n) {
625
+ let r = [
626
+ "#bcebd1",
627
+ "#fff0b3",
628
+ "#f7c9c9",
629
+ "#e9c8f5",
630
+ "#c4e1f2",
631
+ "#20bd70",
632
+ "#f1c40f",
633
+ "#e33b2e",
634
+ "#b65bd0",
635
+ "#3298d4",
636
+ "#168f77",
637
+ "#e77d1e",
638
+ "#b9372b",
639
+ "#823a9d",
640
+ "#2874a6",
641
+ "#edf0f2",
642
+ "#cfd5d8",
643
+ "#9eadae",
644
+ "#7e8d8f",
645
+ "#35495e"
646
+ ], i = document.createElement("div");
647
+ i.className = "mint-editor-color-grid", i.setAttribute("role", "group"), i.setAttribute("aria-label", t === "text" ? "Text colors" : "Highlight colors");
648
+ let a = () => t === "text" ? this.lastTextColor : this.lastBackgroundColor, o = (r, o = !0) => {
649
+ this.applyEditorColor(t, r);
650
+ let s = this.colorRecentSwatches.get(t);
651
+ s && (s.style.backgroundColor = a(), s.dataset.color = a());
652
+ let c = e.querySelector("input[type=\"color\"]");
653
+ c && document.activeElement !== c && (c.value = a()), n.style.setProperty("--editor-color", a()), i.querySelectorAll(".mint-editor-color-swatch").forEach((e) => {
654
+ let t = !!e.dataset.color && e.dataset.color.toLowerCase() === a().toLowerCase();
655
+ e.toggleAttribute("data-selected", t), e.setAttribute("aria-pressed", String(t));
656
+ }), o && e.close();
657
+ }, s = (e, t, n = "") => {
658
+ let r = document.createElement("button");
659
+ return r.type = "button", r.className = `mint-editor-color-swatch ${n}`.trim(), r.dataset.color = t, r.style.backgroundColor = t, r.setAttribute("aria-label", e), r.setAttribute("aria-pressed", String(t.toLowerCase() === a().toLowerCase())), r.toggleAttribute("data-selected", t.toLowerCase() === a().toLowerCase()), this.setTooltip(r, e), r.addEventListener("pointerdown", (e) => {
660
+ e.preventDefault(), this.saveSelection();
661
+ }), r.addEventListener("click", (e) => {
662
+ e.preventDefault(), o(t);
663
+ }), i.append(r), r;
664
+ };
665
+ r.forEach((e, t) => s(`Color ${t + 1}: ${e}`, e)), s("Black", "#000000", "is-utility-swatch"), s("White", "#ffffff", "is-utility-swatch");
666
+ let c = s("Last used color", a(), "is-utility-swatch is-recent-swatch");
667
+ this.colorRecentSwatches.set(t, c);
668
+ let l = document.createElement("button");
669
+ l.type = "button", l.className = "mint-editor-color-swatch mint-editor-no-color", l.setAttribute("aria-label", t === "text" ? "Reset text color" : "Remove highlight"), l.textContent = "/", this.setTooltip(l, t === "text" ? "Reset text color" : "Remove highlight"), l.addEventListener("pointerdown", (e) => {
670
+ e.preventDefault(), this.saveSelection();
671
+ }), l.addEventListener("click", (e) => {
672
+ e.preventDefault(), o(null);
673
+ }), i.append(l);
674
+ let u = document.createElement("input");
675
+ u.type = "color", u.className = "mint-editor-native-color-picker", u.value = a(), u.setAttribute("aria-label", "Choose a custom color");
676
+ let d = document.createElement("button");
677
+ d.type = "button", d.className = "mint-editor-color-swatch mint-editor-custom-color", d.setAttribute("aria-label", "Choose custom color"), d.append(this.icon("palette")), this.setTooltip(d, "Choose custom color"), d.addEventListener("pointerdown", (e) => {
678
+ e.preventDefault(), this.saveSelection();
679
+ }), d.addEventListener("click", (e) => {
680
+ e.preventDefault(), e.stopPropagation(), u.click();
681
+ }), u.addEventListener("pointerdown", () => this.saveSelection()), u.addEventListener("click", (e) => e.stopPropagation()), u.addEventListener("input", () => n.style.setProperty("--editor-color", u.value)), u.addEventListener("change", () => o(u.value));
682
+ let f = document.createElement("div");
683
+ f.className = "mint-editor-custom-color-cell", f.append(d, u), i.append(f), e.append(i);
684
+ }
685
+ applyEditorColor(e, t) {
686
+ if (!this.editor || this.sourceMode) return;
687
+ this.editor.focus(), this.restoreSelection();
688
+ let n = this.editor.ownerDocument, r = this.selection, i = e === "text" ? t || getComputedStyle(this.editor).color || "#202833" : t || getComputedStyle(this.editor).backgroundColor || "transparent";
689
+ if (r?.isCollapsed) {
690
+ this.inlineStyleOverrides.set(e === "text" ? "color" : "backgroundColor", i), this.preserveInlineOverridesOnNextEditorClick = !0, e === "text" && t && (this.lastTextColor = t), e === "background" && t && (this.lastBackgroundColor = t), this.colorTriggers.get(e)?.style.setProperty("--editor-color", e === "text" ? this.lastTextColor : this.lastBackgroundColor), this.emitChange(), this.updateSelectionUI();
691
+ return;
692
+ }
693
+ this.inlineStyleOverrides.delete(e === "text" ? "color" : "backgroundColor"), e === "text" ? (n.execCommand("foreColor", !1, i), t && (this.lastTextColor = t), this.colorTriggers.get("text")?.style.setProperty("--editor-color", this.lastTextColor)) : (n.execCommand("hiliteColor", !1, i) || n.execCommand("backColor", !1, i), t && (this.lastBackgroundColor = t), this.colorTriggers.get("background")?.style.setProperty("--editor-color", this.lastBackgroundColor)), this.emitChange(), this.updateSelectionUI();
694
+ }
695
+ readFontSize() {
696
+ let e = this.selection, t = e?.isCollapsed ? Number.parseFloat(this.inlineStyleOverrides.get("fontSize") || "") : NaN;
697
+ if (Number.isFinite(t) && t > 0) return Math.round(t);
698
+ let n = this._savedRange, r = e?.anchorNode && this.editor?.contains(e.anchorNode) ? e.anchorNode : n?.startContainer, i = r?.nodeType === Node.ELEMENT_NODE ? r : r?.parentElement, a = i ? Number.parseFloat(getComputedStyle(i).fontSize) : 16;
699
+ return Number.isFinite(a) && a > 0 ? Math.round(a) : 16;
700
+ }
701
+ applyFontSize(e) {
702
+ if (!this.editor || this.sourceMode) return;
703
+ let t = Math.max(8, Math.min(96, Math.round(e)));
704
+ this.editor.focus(), this.restoreSelection();
705
+ let n = this.editor.ownerDocument;
706
+ if (this.selection?.isCollapsed) {
707
+ this.inlineStyleOverrides.set("fontSize", `${t}px`), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
708
+ return;
709
+ }
710
+ this.inlineStyleOverrides.delete("fontSize");
711
+ let r = new Set(Array.from(this.editor.querySelectorAll("font[size=\"7\"]")));
712
+ n.execCommand("fontSize", !1, "7"), this.editor.querySelectorAll("font[size=\"7\"]").forEach((e) => {
713
+ if (r.has(e)) return;
714
+ let i = n.createElement("span");
715
+ i.style.fontSize = `${t}px`, e.getAttribute("face") && (i.style.fontFamily = e.getAttribute("face") || ""), e.getAttribute("color") && (i.style.color = e.getAttribute("color") || ""), i.append(...Array.from(e.childNodes)), e.replaceWith(i);
716
+ }), this.emitChange(), this.updateSelectionUI();
717
+ }
718
+ applyFontFamily(e) {
719
+ if (!this.editor || this.sourceMode) return;
720
+ if (this.editor.focus(), this.restoreSelection(), this.selection?.isCollapsed) {
721
+ this.inlineStyleOverrides.set("fontFamily", e), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
722
+ return;
723
+ }
724
+ this.inlineStyleOverrides.delete("fontFamily");
725
+ let t = this.editor.ownerDocument, n = new Set(Array.from(this.editor.querySelectorAll("font[face]")));
726
+ t.execCommand("fontName", !1, e), this.editor.querySelectorAll("font[face]").forEach((r) => {
727
+ if (n.has(r)) return;
728
+ let i = t.createElement("span");
729
+ i.style.fontFamily = r.getAttribute("face") || e, i.append(...Array.from(r.childNodes)), r.replaceWith(i);
730
+ }), this.emitChange(), this.updateSelectionUI();
731
+ }
732
+ applyListStyle(e, t) {
733
+ if (!this.editor || this.sourceMode) return;
734
+ this.editor.focus(), this.restoreSelection();
735
+ let n = this.selection?.anchorNode, r = (n?.nodeType === Node.ELEMENT_NODE ? n : n?.parentElement)?.closest(e), i = r && this.editor.contains(r) ? r : null;
736
+ if (!i) {
737
+ this.editor.ownerDocument.execCommand(e === "ul" ? "insertUnorderedList" : "insertOrderedList", !1);
738
+ let t = this.selection?.anchorNode, n = (t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement)?.closest(e);
739
+ i = n && this.editor.contains(n) ? n : null;
740
+ }
741
+ i && (i.style.listStyleType = t), this.emitChange(), this.updateSelectionUI();
742
+ }
743
+ toggleChecklist() {
744
+ if (!this.editor || this.sourceMode) return;
745
+ this.editor.focus(), this.restoreSelection();
746
+ let e = this.editor.ownerDocument, t = this.selection?.anchorNode, n = t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement, r = n?.closest("ul[data-mint-task-list]"), i = n?.closest("ul");
747
+ if (r) r.removeAttribute("data-mint-task-list"), r.querySelectorAll("input[type=\"checkbox\"]").forEach((e) => e.remove());
748
+ else {
749
+ i || (n?.closest("h1,h2,h3,h4,h5,h6") && e.execCommand("formatBlock", !1, "p"), e.execCommand("insertUnorderedList", !1));
750
+ let t = this.selection?.anchorNode, r = t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement, a = i || r?.closest("ul");
751
+ if (a && this.editor.contains(a)) {
752
+ a.setAttribute("data-mint-task-list", "true"), a.querySelectorAll("li").forEach((t, n) => {
753
+ if (t.querySelector("input[type=\"checkbox\"]")) return;
754
+ let r = e.createElement("input");
755
+ r.type = "checkbox", r.setAttribute("contenteditable", "false"), r.setAttribute("aria-label", `Task ${n + 1} complete`), t.insertBefore(r, t.firstChild);
756
+ });
757
+ let t = a.parentElement;
758
+ t && t !== this.editor && /^(P|H[1-6])$/.test(t.tagName) && t.parentElement === this.editor && (Array.from(t.childNodes).filter((e) => e === a ? !1 : e.nodeType === Node.TEXT_NODE ? !!e.textContent?.trim() : e.nodeType === Node.ELEMENT_NODE && !e.matches("br")).length === 0 ? t.replaceWith(a) : t.parentNode?.insertBefore(a, t.nextSibling));
759
+ }
760
+ }
761
+ this.emitChange(), this.updateSelectionUI();
762
+ }
763
+ splitTaskItem(e, t) {
764
+ if (!this.editor) return;
765
+ let n = this.editor.ownerDocument, r = this.selection, i = r?.anchorNode, a = Array.from(e.children).find((e) => e.matches("input[type=\"checkbox\"]"));
766
+ if (a) e.firstChild !== a && (a.remove(), e.insertBefore(a, e.firstChild));
767
+ else {
768
+ let r = n.createElement("input");
769
+ r.type = "checkbox", r.setAttribute("contenteditable", "false"), r.setAttribute("aria-label", `Task ${t.children.length} complete`), e.insertBefore(r, e.firstChild);
770
+ }
771
+ let o = n.createRange();
772
+ r?.isCollapsed && i && (i === e || e.contains(i)) ? o.setStart(i, r.anchorOffset) : o.setStart(e, e.childNodes.length), o.setEnd(e, e.childNodes.length);
773
+ let s = o.extractContents(), c = n.createElement("li"), l = n.createElement("input");
774
+ l.type = "checkbox", l.setAttribute("contenteditable", "false"), l.setAttribute("aria-label", `Task ${t.children.length + 1} complete`), c.append(l, s), this.isEmptyTaskItem(c) && c.append(n.createElement("br")), this.isEmptyTaskItem(e) && e.append(n.createElement("br")), t.insertBefore(c, e.nextSibling);
775
+ let u = n.createRange();
776
+ u.setStart(c, 1), u.collapse(!0), r?.removeAllRanges(), r?.addRange(u), this.syncSource(), this.emitChange(), this.updateSelectionUI();
777
+ }
778
+ normalizeTaskListItems() {
779
+ if (!this.editor) return;
780
+ let e = this.selection, t = e?.anchorNode, n = t?.nodeType === Node.ELEMENT_NODE ? t.closest("li") : t?.parentElement?.closest("li");
781
+ for (let r of this.editor.querySelectorAll("ul[data-mint-task-list]")) Array.from(r.children).forEach((r, i) => {
782
+ if (r.tagName !== "LI") return;
783
+ let a = r, o = Array.from(a.children).find((e) => e.matches("input[type=\"checkbox\"]"));
784
+ if (!o) {
785
+ if (o = this.editor.ownerDocument.createElement("input"), o.type = "checkbox", o.setAttribute("contenteditable", "false"), o.setAttribute("aria-label", `Task ${i + 1} complete`), a.insertBefore(o, a.firstChild), e?.isCollapsed && n === a && t === a) {
786
+ let t = this.editor.ownerDocument.createRange();
787
+ t.setStart(a, 1), t.collapse(!0), e.removeAllRanges(), e.addRange(t);
788
+ }
789
+ } else if (o.setAttribute("contenteditable", "false"), o.hasAttribute("aria-label") || o.setAttribute("aria-label", `Task ${i + 1} complete`), a.firstChild !== o && (o.remove(), a.insertBefore(o, a.firstChild), e?.isCollapsed && n === a && t === a)) {
790
+ let t = this.editor.ownerDocument.createRange();
791
+ t.setStart(a, 1), t.collapse(!0), e.removeAllRanges(), e.addRange(t);
792
+ }
793
+ });
794
+ }
795
+ isEmptyTaskItem(e) {
796
+ let t = (e) => {
797
+ if (e.nodeType === Node.TEXT_NODE) return !!e.textContent?.trim();
798
+ if (e.nodeType !== Node.ELEMENT_NODE) return !1;
799
+ let n = e;
800
+ return n.matches("input[type=\"checkbox\"], br") ? !1 : n.matches("img, video, audio, iframe, table, hr, pre, canvas, object, embed") ? !0 : Array.from(n.childNodes).some(t);
801
+ };
802
+ return !Array.from(e.childNodes).some(t);
803
+ }
804
+ exitTaskList(e, t) {
805
+ if (!this.editor || !t.parentNode) return;
806
+ let n = t.parentNode, r = t.cloneNode(!1);
807
+ for (; e.nextElementSibling;) r.append(e.nextElementSibling);
808
+ e.remove();
809
+ let i = this.editor.ownerDocument.createElement("p");
810
+ i.append(this.editor.ownerDocument.createElement("br")), t.children.length > 0 ? n.insertBefore(i, t.nextSibling) : (n.insertBefore(i, t), t.remove()), r.children.length && n.insertBefore(r, i.nextSibling), this.editor.focus();
811
+ let a = this.selection, o = this.editor.ownerDocument.createRange();
812
+ o.setStart(i, 0), o.collapse(!0), a?.removeAllRanges(), a?.addRange(o), this.syncSource(), this.emitChange(), this.updateSelectionUI();
813
+ }
814
+ openCommentModal() {
815
+ this.saveSelection();
816
+ let e = this._savedRange?.toString() || "", t = document.createElement("mint-modal");
817
+ t.setAttribute("heading", "Add comment"), t.setAttribute("size", "small");
818
+ let n = document.createElement("div");
819
+ n.setAttribute("slot", "body"), n.className = "mint-editor-modal-fields";
820
+ let r = document.createElement("p");
821
+ r.className = "mint-editor-comment-hint", r.textContent = e ? `Comment on: “${e.slice(0, 120)}${e.length > 120 ? "…" : ""}”` : "Select some text in the document before adding a comment.";
822
+ let i = document.createElement("textarea");
823
+ i.className = "mint-editor-comment-input", i.setAttribute("aria-label", "Comment"), i.setAttribute("placeholder", "Write a comment…"), i.rows = 4, n.append(r, i);
824
+ let a = document.createElement("div");
825
+ a.setAttribute("slot", "actions"), a.className = "mint-editor-modal-actions";
826
+ let o = document.createElement("mint-button");
827
+ o.textContent = "Cancel", o.setAttribute("variant", "ghost"), this.setTooltip(o, "Cancel"), o.addEventListener("click", () => t.close());
828
+ let s = document.createElement("mint-button");
829
+ s.textContent = "Add comment", s.setAttribute("tone", "action"), s.toggleAttribute("disabled", !e), this.setTooltip(s, "Add comment"), s.addEventListener("click", () => {
830
+ let n = i.value.trim();
831
+ !n || !e || (this.insertComment(n, e), t.close());
832
+ }), a.append(o, s), t.append(n, a), this.append(t), t.open();
833
+ }
834
+ insertComment(e, t) {
835
+ let n = this._savedRange;
836
+ if (this.editor && n && !n.collapsed && this.editor.contains(n.commonAncestorContainer) && this.format === "html") {
837
+ let t = this.editor.ownerDocument.createElement("span");
838
+ t.className = "mint-editor-comment", t.setAttribute("data-mint-comment", e), t.title = `Comment: ${e}`, t.append(n.extractContents()), n.insertNode(t);
839
+ let r = this.selection;
840
+ n.selectNodeContents(t), r?.removeAllRanges(), r?.addRange(n);
841
+ }
842
+ this.dispatchEvent(new CustomEvent("mint-editor-comment-request", {
843
+ bubbles: !0,
844
+ composed: !0,
845
+ detail: {
846
+ selectedText: t,
847
+ comment: e,
848
+ format: this.format
849
+ }
850
+ })), this.emitChange();
851
+ }
852
+ updateToolbarOverflow() {
853
+ let e = this.toolbar, t = this.overflowTrigger, n = this.overflowPopover;
854
+ if (!e || !t || !n) return;
855
+ let r = e.querySelector(".mint-editor-toolbar-actions"), i = this.blockButton;
856
+ if (!r || !i) return;
857
+ for (let e of this.overflowGroups) for (let t of e) r.append(t);
858
+ t.hidden = !1;
859
+ let a = this.overflowGroups.length - 1, o = () => {
860
+ let e = [...r.children].filter((e) => e instanceof HTMLElement && !e.matches("mint-popover") && !e.hidden), t = Number.parseFloat(getComputedStyle(r).columnGap) || 0;
861
+ return e.reduce((e, t) => e + t.getBoundingClientRect().width, 0) + Math.max(0, e.length - 1) * t;
862
+ };
863
+ for (; o() > r.clientWidth + 1 && a >= 0;) [...this.overflowGroups[a]].reverse().filter((e) => !e.matches("mint-popover")).forEach((e) => n.insertBefore(e, n.firstChild)), a--;
864
+ t.hidden = n.childElementCount === 0;
865
+ }
866
+ clearFormatting() {
867
+ !this.editor || this.sourceMode || (this.editor.focus(), this.restoreSelection(), this.editor.ownerDocument.execCommand("removeFormat", !1), this.editor.ownerDocument.execCommand("formatBlock", !1, "p"), this.clearInlineTypingState(), this.emitChange(), this.updateSelectionUI());
868
+ }
869
+ icon(e) {
870
+ let t = document.createElement("mint-icon");
871
+ return t.setAttribute("name", e), t.setAttribute("aria-hidden", "true"), t;
872
+ }
873
+ setTooltip(e, t) {
874
+ this.updateTooltipLabel(e, t), e.dataset.editorTooltipBound !== "true" && (e.dataset.editorTooltipBound = "true", e.addEventListener("pointerenter", () => this.showTooltip(e)), e.addEventListener("pointerleave", () => this.hideTooltip()), e.addEventListener("focus", () => this.showTooltip(e)), e.addEventListener("blur", () => this.hideTooltip()));
875
+ }
876
+ updateTooltipLabel(e, t) {
877
+ e.setAttribute("data-editor-tooltip", t);
878
+ let n = t.indexOf(":"), r = n < 0 ? t : `${t.slice(0, n + 1)}\n${t.slice(n + 1).trim()}`;
879
+ e.setAttribute("data-editor-overflow-label", r), e.setAttribute("aria-label", t), e.removeAttribute("title");
880
+ }
881
+ showTooltip(e) {
882
+ if (e.closest(".mint-editor-overflow-popover")) {
883
+ this.hideTooltip();
884
+ return;
885
+ }
886
+ let t = e.getAttribute("data-editor-tooltip");
887
+ if (!t || e.matches(":disabled,[hidden]")) return;
888
+ let n = this.tooltipPopup;
889
+ if (!n) {
890
+ n = document.createElement("div"), n.className = "mint-editor-tooltip-popup", n.setAttribute("role", "tooltip"), n.setAttribute("aria-hidden", "true");
891
+ let e = getComputedStyle(this);
892
+ [
893
+ "text",
894
+ "surface",
895
+ "border"
896
+ ].forEach((t) => {
897
+ let r = e.getPropertyValue(`--mint-color-${t}`).trim();
898
+ r && n.style.setProperty(`--mint-color-${t}`, r);
899
+ }), document.body.append(n), this.tooltipPopup = n;
900
+ }
901
+ n.textContent = t, n.setAttribute("aria-hidden", "false"), n.style.visibility = "hidden", n.style.display = "block";
902
+ let r = e.getBoundingClientRect(), i = n.getBoundingClientRect(), a = Math.max(8, Math.min(window.innerWidth - i.width - 8, r.left + r.width / 2 - i.width / 2)), o = r.top >= i.height + 6 + 8 ? r.top - i.height - 6 : Math.min(window.innerHeight - i.height - 8, r.bottom + 6);
903
+ n.style.left = `${a}px`, n.style.top = `${o}px`, n.style.visibility = "visible";
904
+ }
905
+ hideTooltip() {
906
+ this.tooltipPopup && (this.tooltipPopup.style.display = "none", this.tooltipPopup.setAttribute("aria-hidden", "true"));
907
+ }
908
+ closeEditorPopovers() {
909
+ this.querySelectorAll("mint-popover").forEach((e) => {
910
+ e.close?.call(e);
911
+ });
912
+ }
913
+ createMenuOption(e, t) {
914
+ let n = {
915
+ "table-row": "table",
916
+ "table-column": "columns",
917
+ "table-row-delete": "remove",
918
+ "table-column-delete": "remove",
919
+ paragraph: "file-alt",
920
+ heading: "heading"
921
+ }, r = document.createElement("button");
922
+ r.type = "button", r.className = "mint-editor-menu-option";
923
+ let i = this.icon(n[t] || t);
924
+ i.classList.add("mint-editor-menu-icon");
925
+ let a = document.createElement("span");
926
+ return a.className = "mint-editor-menu-label", a.textContent = e, r.append(i, a), r;
927
+ }
928
+ updateFormatUI() {
929
+ if (this.source && this.source.setAttribute("aria-label", `Editor ${this.format.toUpperCase()} source`), this.sourceButton) {
930
+ let e = `${this.format.toUpperCase()} source`, t = this.sourceButton.querySelector(".mint-editor-button-label");
931
+ t && (t.textContent = e), this.updateTooltipLabel(this.sourceButton, e);
932
+ }
933
+ }
934
+ separator() {
935
+ let e = document.createElement("span");
936
+ return e.className = "mint-editor-separator", e.setAttribute("aria-hidden", "true"), e;
937
+ }
938
+ command(e, t) {
939
+ !this.editor || this.sourceMode || (this.editor.focus(), this.restoreSelection(), this.editor.ownerDocument.execCommand(e, !1, t), this.clearInlineTypingState(), this.emitChange(), this.updateSelectionUI());
940
+ }
941
+ toggleInline(e) {
942
+ if (!this.editor || this.sourceMode) return;
943
+ this.editor.focus(), this.restoreSelection();
944
+ let t = this.selection;
945
+ if (!t?.rangeCount || !this.editor.contains(t.anchorNode)) return;
946
+ let n = t.getRangeAt(0), r = !this.inlineStateAtSelection(e, n), i = this.editor.ownerDocument;
947
+ if (n.collapsed) {
948
+ this.inlineOverrides.set(e, r), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
949
+ return;
950
+ }
951
+ this.clearInlineTypingState(), i.execCommand(e, !1), this.emitChange(), this.updateSelectionUI();
952
+ }
953
+ inlineStateAtSelection(e, t) {
954
+ let n = this.selection, r = this.inlineOverrides.get(e);
955
+ if (t.collapsed && r !== void 0) return r;
956
+ let i = this.formatAtCaret(e, t);
957
+ if (i || !t.collapsed) return i;
958
+ let a = t.cloneRange(), o = t.startContainer, s = t.startOffset;
959
+ if (o.nodeType !== Node.TEXT_NODE || s === 0) {
960
+ let e = o.nodeType === Node.ELEMENT_NODE ? o.childNodes[s - 1] : null;
961
+ if (e) {
962
+ for (o = e; o.lastChild;) o = o.lastChild;
963
+ o.nodeType === Node.TEXT_NODE && (s = o.textContent?.length || 0);
964
+ }
965
+ }
966
+ if (o.nodeType === Node.TEXT_NODE && s > 0) try {
967
+ a.setStart(o, s - 1), a.setEnd(o, s), n?.removeAllRanges(), n?.addRange(a), i = this.formatAtCaret(e, a);
968
+ } catch {} finally {
969
+ n?.removeAllRanges(), n?.addRange(t);
970
+ }
971
+ return i;
972
+ }
973
+ applyInlineTypingState(e) {
974
+ if (e.inputType.startsWith("insert") && (this.preserveInlineOverridesOnNextEditorClick = !1), e.inputType.startsWith("delete")) {
975
+ this.clearInlineTypingState();
976
+ return;
977
+ }
978
+ if (!this.editor || this.sourceMode || e.inputType !== "insertText" || !e.data || this.inlineOverrides.size === 0 && this.inlineStyleOverrides.size === 0) return;
979
+ let t = this.selection;
980
+ if (!t?.rangeCount || !t.isCollapsed || !this.editor.contains(t.anchorNode)) return;
981
+ let n = t.getRangeAt(0), r = this.editor.ownerDocument;
982
+ e.preventDefault();
983
+ let i = r.createTextNode(e.data), a = [
984
+ "bold",
985
+ "italic",
986
+ "underline"
987
+ ].map((e) => {
988
+ let t = this.formatAtCaret(e, n);
989
+ return [
990
+ e,
991
+ this.inlineOverrides.has(e) ? this.inlineOverrides.get(e) : t,
992
+ t
993
+ ];
994
+ }), o = a.some(([e, t, n]) => e === "underline" && !t && n) ? (n.startContainer.nodeType === Node.ELEMENT_NODE ? n.startContainer : n.startContainer.parentElement)?.closest("u") : null;
995
+ for (let [e, t, n] of a.reverse()) {
996
+ if (t === n) continue;
997
+ let a = t ? e === "bold" ? "strong" : e === "italic" ? "em" : "u" : "span", o = r.createElement(a);
998
+ t || (e === "bold" ? o.style.fontWeight = "normal" : e === "italic" ? o.style.fontStyle = "normal" : o.style.textDecoration = "none"), o.append(i), i = o;
999
+ }
1000
+ if (this.inlineStyleOverrides.size) {
1001
+ let e = r.createElement("span");
1002
+ this.inlineStyleOverrides.forEach((t, n) => {
1003
+ e.style[n] = t;
1004
+ }), e.append(i), i = e;
1005
+ }
1006
+ if (n.deleteContents(), n.insertNode(i), o && o.parentNode && this.isAtEndOfInlineRun(i, o)) {
1007
+ o.parentNode.insertBefore(i, o.nextSibling);
1008
+ for (let e = i.parentNode; e && e !== o;) {
1009
+ let t = e.parentNode;
1010
+ e instanceof HTMLElement && !e.textContent?.length && !e.querySelector("img,br,table,hr,iframe,video,audio") && e.remove(), e = t;
1011
+ }
1012
+ !o.textContent?.length && !o.querySelector("img,br,table,hr,iframe,video,audio") && o.remove();
1013
+ }
1014
+ let s = i;
1015
+ for (; s.lastChild;) s = s.lastChild;
1016
+ s.nodeType === Node.TEXT_NODE ? n.setStart(s, s.textContent?.length || 0) : n.setStartAfter(s), n.collapse(!0), t.removeAllRanges(), t.addRange(n), this.editor.dispatchEvent(new InputEvent("input", {
1017
+ bubbles: !0,
1018
+ inputType: "insertText",
1019
+ data: e.data
1020
+ }));
1021
+ }
1022
+ isAtEndOfInlineRun(e, t) {
1023
+ for (let n = e; n && n !== t; n = n.parentNode) for (let e = n.nextSibling; e; e = e.nextSibling) if (!(e.nodeType === Node.TEXT_NODE && !e.textContent?.trim())) return !1;
1024
+ return !0;
1025
+ }
1026
+ formatAtCaret(e, t) {
1027
+ let n = t.startContainer, r = n.nodeType === Node.ELEMENT_NODE ? n : n.parentElement;
1028
+ if (t.collapsed && n.nodeType === Node.ELEMENT_NODE && t.startOffset > 0) {
1029
+ let e = n.childNodes[t.startOffset - 1];
1030
+ for (; e?.lastChild;) e = e.lastChild;
1031
+ e?.nodeType === Node.TEXT_NODE ? r = e.parentElement : e?.nodeType === Node.ELEMENT_NODE && (r = e);
1032
+ }
1033
+ if (!r) return !1;
1034
+ let i = [];
1035
+ for (let e = r; e && e !== this.editor; e = e.parentElement) i.push(e);
1036
+ for (let t of i) {
1037
+ let n = t.style;
1038
+ if (e === "bold") {
1039
+ if (n.fontWeight) {
1040
+ let e = Number.parseInt(n.fontWeight, 10);
1041
+ return Number.isFinite(e) ? e >= 600 : n.fontWeight === "bold" || n.fontWeight === "bolder";
1042
+ }
1043
+ if (["B", "STRONG"].includes(t.tagName)) return !0;
1044
+ } else if (e === "italic") {
1045
+ if (n.fontStyle) return ["italic", "oblique"].includes(n.fontStyle);
1046
+ if (["I", "EM"].includes(t.tagName)) return !0;
1047
+ } else {
1048
+ if (n.textDecorationLine || n.textDecoration) return (n.textDecorationLine || n.textDecoration).includes("underline");
1049
+ if (t.tagName === "U") return !0;
1050
+ }
1051
+ }
1052
+ let a = getComputedStyle(r);
1053
+ if (e === "bold") {
1054
+ let e = Number.parseInt(a.fontWeight, 10);
1055
+ return Number.isFinite(e) && e >= 600;
1056
+ }
1057
+ return e === "italic" ? ["italic", "oblique"].includes(a.fontStyle) : a.textDecorationLine.includes("underline");
1058
+ }
1059
+ requestResource() {
1060
+ this.saveSelection(), this.dispatchEvent(new CustomEvent("mint-editor-resource-request", {
1061
+ bubbles: !0,
1062
+ composed: !0,
1063
+ detail: { resourceType: "media" }
1064
+ }));
1065
+ }
1066
+ get selection() {
1067
+ return this.editor?.ownerDocument.getSelection() || null;
1068
+ }
1069
+ saveSelection() {
1070
+ let e = this.selection;
1071
+ e?.rangeCount && this.editor?.contains(e.anchorNode) && (this._savedRange = e.getRangeAt(0).cloneRange());
1072
+ }
1073
+ restoreSelection() {
1074
+ let e = this._savedRange;
1075
+ if (!e) return;
1076
+ let t = this.selection;
1077
+ t?.removeAllRanges(), t?.addRange(e), this._savedRange = void 0;
1078
+ }
1079
+ clearInlineTypingState() {
1080
+ this.inlineOverrides.clear(), this.inlineStyleOverrides.clear(), this.preserveInlineOverridesOnNextEditorClick = !1;
1081
+ }
1082
+ cleanEditorCopy() {
1083
+ let e = this.editor?.cloneNode(!0);
1084
+ return e ? (e.querySelectorAll(".mint-editor-resize-handle").forEach((e) => e.remove()), e.querySelectorAll(".mint-editor-image-frame,table").forEach((e) => e.classList.remove("is-selected")), e) : document.createElement("div");
1085
+ }
1086
+ insertPastedHtml(e) {
1087
+ let t = this.editor, n = this.selection;
1088
+ if (!t || !n?.rangeCount) return;
1089
+ let r = t.ownerDocument, i = n.getRangeAt(0);
1090
+ if (!t.contains(i.startContainer) || !t.contains(i.endContainer)) return;
1091
+ let a = r.createElement("div");
1092
+ a.innerHTML = e;
1093
+ let o = r.createDocumentFragment();
1094
+ for (; a.firstChild;) o.append(a.firstChild);
1095
+ if (!o.hasChildNodes()) return;
1096
+ let s = !!o.querySelector?.("p,h1,h2,h3,h4,h5,h6,blockquote,pre,div,ul,ol,table"), c = !i.collapsed && i.toString() === t.textContent, l = i.startContainer === t && i.startOffset === 0 && i.endContainer === t && i.endOffset === t.childNodes.length;
1097
+ if (c || l) {
1098
+ t.replaceChildren(o), this.placeCaretAfterPastedContent(t.lastChild, n);
1099
+ return;
1100
+ }
1101
+ i.deleteContents(), i.collapse(!0);
1102
+ let u = i.startContainer;
1103
+ if (u.nodeType !== Node.ELEMENT_NODE && (u = u.parentNode || t), s) {
1104
+ let e = (u.nodeType === Node.ELEMENT_NODE ? u : u.parentElement)?.closest("p,h1,h2,h3,h4,h5,h6,pre");
1105
+ if (e && t.contains(e) && e.parentNode) {
1106
+ let t = r.createRange();
1107
+ t.selectNodeContents(e), t.setStart(i.startContainer, i.startOffset);
1108
+ let a = t.extractContents(), s = e.parentNode, c = e.nextSibling, l = e.cloneNode(!1);
1109
+ l.append(a);
1110
+ let u = this.hasPastedBlockContent(e), d = this.hasPastedBlockContent(l);
1111
+ u || s.removeChild(e);
1112
+ let f = o.lastChild;
1113
+ s.insertBefore(o, c), d ? s.insertBefore(l, c) : l.remove(), this.placeCaretAfterPastedContent(f, n);
1114
+ return;
1115
+ }
1116
+ }
1117
+ let d = o.lastChild;
1118
+ i.insertNode(o), this.placeCaretAfterPastedContent(d, n);
1119
+ }
1120
+ hasPastedBlockContent(e) {
1121
+ return (e.textContent || "").replace(/\u00a0/g, " ").trim() ? !0 : !!e.querySelector("img,table,hr,ul,ol,iframe,video,audio");
1122
+ }
1123
+ placeCaretAfterPastedContent(e, t) {
1124
+ if (!e?.parentNode) return;
1125
+ let n = this.editor?.ownerDocument.createRange();
1126
+ n && (n.selectNodeContents(e), n.collapse(!1), t.removeAllRanges(), t.addRange(n), this.saveSelection());
1127
+ }
1128
+ sanitizePastedHtml(e) {
1129
+ let t = this.editor?.ownerDocument, n = t?.defaultView?.DOMParser;
1130
+ if (!t || !n) return "";
1131
+ let r = new n().parseFromString(e, "text/html"), i = r.body, a = /* @__PURE__ */ "color.background-color.font-family.font-size.font-weight.font-style.text-decoration.text-decoration-line.text-align.vertical-align.line-height.text-indent.list-style-type.margin-top.margin-right.margin-bottom.margin-left.padding-top.padding-right.padding-bottom.padding-left.border.border-top.border-right.border-bottom.border-left.border-collapse.width.height".split("."), o = (e) => {
1132
+ let t = r.createElement("span");
1133
+ t.setAttribute("style", e);
1134
+ let n = /* @__PURE__ */ new Map();
1135
+ for (let e of a) {
1136
+ let r = t.style.getPropertyValue(e).trim();
1137
+ !r || /url\s*\(|expression\s*\(/i.test(r) || e.startsWith("margin-") && Number.parseFloat(r) === 0 || n.set(e, r);
1138
+ }
1139
+ let i = e.match(/(?:^|;)\s*mso-(?:ansi|bidi)-font-size\s*:\s*([^;]+)/i)?.[1]?.trim();
1140
+ if (!n.has("font-size") && i) {
1141
+ t.style.setProperty("font-size", i);
1142
+ let e = t.style.getPropertyValue("font-size").trim();
1143
+ e && !/url\s*\(|expression\s*\(/i.test(e) && n.set("font-size", e);
1144
+ }
1145
+ let o = e.match(/(?:^|;)\s*mso-(?:ansi|bidi)-font-family\s*:\s*([^;]+)/i)?.[1]?.trim();
1146
+ if (!n.has("font-family") && o) {
1147
+ t.style.setProperty("font-family", o);
1148
+ let e = t.style.getPropertyValue("font-family").trim();
1149
+ e && !/url\s*\(|expression\s*\(/i.test(e) && n.set("font-family", e);
1150
+ }
1151
+ let s = e.match(/(?:^|;)\s*mso-highlight\s*:\s*([^;]+)/i)?.[1]?.trim();
1152
+ if (!n.has("background-color") && s) {
1153
+ t.style.backgroundColor = s;
1154
+ let e = t.style.backgroundColor.trim();
1155
+ e && n.set("background-color", e);
1156
+ }
1157
+ return !n.has("background-color") && t.style.backgroundColor && n.set("background-color", t.style.backgroundColor), Array.from(n, ([e, t]) => `${e}:${t}`).join(";");
1158
+ }, s = (e, t) => {
1159
+ let n = o([t, e.getAttribute("style") || ""].filter(Boolean).join(";"));
1160
+ n && e.setAttribute("style", n);
1161
+ };
1162
+ for (let e of Array.from(r.querySelectorAll("style"))) {
1163
+ let t = e.textContent || "";
1164
+ for (let e of t.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
1165
+ let t = e[2].trim();
1166
+ if (!(!t || !/\.(?:Mso|WordSection)/i.test(e[1]))) for (let n of e[1].split(",")) {
1167
+ let e = n.trim();
1168
+ if (/^(?:[a-z][\w-]*)?(?:\.[\w-]+)+$/i.test(e)) try {
1169
+ r.querySelectorAll(e).forEach((e) => s(e, t));
1170
+ } catch {}
1171
+ }
1172
+ }
1173
+ }
1174
+ r.querySelectorAll("style,script,iframe,object,embed,form,input,button,select,textarea,link,meta,base,svg,math,canvas,video,audio").forEach((e) => e.remove());
1175
+ for (let e of Array.from(i.querySelectorAll("font"))) {
1176
+ let t = r.createElement("span"), n = [], i = e.getAttribute("face"), a = e.getAttribute("color"), s = e.getAttribute("size"), c = {
1177
+ 1: "8pt",
1178
+ 2: "10pt",
1179
+ 3: "12pt",
1180
+ 4: "14pt",
1181
+ 5: "18pt",
1182
+ 6: "24pt",
1183
+ 7: "36pt"
1184
+ };
1185
+ i && n.push(`font-family:${i}`), a && n.push(`color:${a}`), s && c[s] && n.push(`font-size:${c[s]}`);
1186
+ let l = e.getAttribute("style") || "", u = o([n.join(";"), l].filter(Boolean).join(";"));
1187
+ for (u && t.setAttribute("style", u); e.firstChild;) t.append(e.firstChild);
1188
+ e.replaceWith(t);
1189
+ }
1190
+ for (let e of Array.from(i.querySelectorAll("p,div"))) {
1191
+ let t = e.getAttribute("class") || "", n = t.match(/MsoHeading([1-6])/i)?.[1] || (/MsoTitle/i.test(t) ? "1" : /MsoSubtitle/i.test(t) ? "2" : "");
1192
+ if (!n) continue;
1193
+ let i = r.createElement(`h${n}`);
1194
+ for (let t of Array.from(e.attributes)) i.setAttribute(t.name, t.value);
1195
+ for (; e.firstChild;) i.append(e.firstChild);
1196
+ e.replaceWith(i);
1197
+ }
1198
+ let c = (e) => {
1199
+ let t = r.createDocumentFragment(), n = null, i = "";
1200
+ for (let a of Array.from(e.childNodes)) if (a.nodeType === Node.ELEMENT_NODE) {
1201
+ let e = a, s = e.getAttribute("class") || "", l = e.getAttribute("style") || "", u = ["P", "DIV"].includes(e.tagName) && Array.from(e.children).find((e) => e.tagName === "SPAN" && /mso-list\s*:\s*ignore/i.test(e.getAttribute("style") || "")) || null;
1202
+ if (["P", "DIV"].includes(e.tagName) && (/mso-list\s*:/i.test(l) || /MsoListParagraph/i.test(s) || u)) {
1203
+ let a = (u?.textContent || e.textContent || "").replace(/\u00a0/g, " ").trim();
1204
+ u?.remove();
1205
+ let s = /^(?:\d+|[a-z]|[ivxlcdm]+)[.)]/i.test(a) ? "ol" : "ul";
1206
+ (!n || i !== s) && (n = r.createElement(s), i = s, t.append(n));
1207
+ let c = r.createElement("li"), d = o(l.replace(/(?:^|;)\s*mso-list\s*:[^;]*/gi, ""));
1208
+ for (d && c.setAttribute("style", d); e.firstChild;) c.append(e.firstChild);
1209
+ n.append(c);
1210
+ continue;
1211
+ }
1212
+ if (n = null, i = "", c(e), e.tagName === "DIV" && /WordSection/i.test(s)) for (; e.firstChild;) t.append(e.firstChild);
1213
+ else t.append(e);
1214
+ } else a.nodeType === Node.TEXT_NODE && !(a.textContent || "").trim() ? n || t.append(a) : (n = null, i = "", a.nodeType !== Node.COMMENT_NODE && t.append(a));
1215
+ e.replaceChildren(t);
1216
+ };
1217
+ c(i);
1218
+ let l = (e) => {
1219
+ e.replaceWith(...Array.from(e.childNodes));
1220
+ };
1221
+ for (let e of Array.from(i.querySelectorAll("*"))) e.tagName.includes(":") && l(e);
1222
+ let u = new Set([
1223
+ "href",
1224
+ "src",
1225
+ "alt",
1226
+ "title",
1227
+ "colspan",
1228
+ "rowspan",
1229
+ "start",
1230
+ "value",
1231
+ "type",
1232
+ "width",
1233
+ "height",
1234
+ "border",
1235
+ "cellpadding",
1236
+ "cellspacing",
1237
+ "scope",
1238
+ "dir"
1239
+ ]), d = (e, t = !1) => {
1240
+ let n = e.trim();
1241
+ if (/^#[-\w:.]+$/.test(n) || t && /^data:image\/(?:png|gif|jpe?g|webp);base64,/i.test(n)) return !0;
1242
+ try {
1243
+ return [
1244
+ "http:",
1245
+ "https:",
1246
+ "mailto:",
1247
+ "tel:"
1248
+ ].includes(new URL(n, "https://mint.invalid").protocol);
1249
+ } catch {
1250
+ return !1;
1251
+ }
1252
+ };
1253
+ for (let e of Array.from(i.querySelectorAll("*"))) for (let t of Array.from(e.attributes)) {
1254
+ let n = t.name.toLowerCase();
1255
+ if (n === "style") {
1256
+ let n = o(t.value);
1257
+ n ? e.setAttribute("style", n) : e.removeAttribute(t.name);
1258
+ } else u.has(n) ? ((n === "href" || n === "src") && !d(t.value, n === "src") || [
1259
+ "colspan",
1260
+ "rowspan",
1261
+ "start",
1262
+ "value",
1263
+ "width",
1264
+ "height",
1265
+ "border",
1266
+ "cellpadding",
1267
+ "cellspacing"
1268
+ ].includes(n) && !/^\d+(?:%|px)?$/i.test(t.value.trim()) || n === "scope" && !/^(row|col|rowgroup|colgroup)$/i.test(t.value) || n === "dir" && !/^(ltr|rtl|auto)$/i.test(t.value) || n === "type" && !/^(1|a|A|i|I)$/i.test(t.value)) && e.removeAttribute(t.name) : e.removeAttribute(t.name);
1269
+ }
1270
+ for (let e of Array.from(i.querySelectorAll("span"))) e.attributes.length || l(e);
1271
+ return i.innerHTML.trim();
1272
+ }
1273
+ syncSource() {
1274
+ if (this.source && this.editor) {
1275
+ let e = this.cleanEditorCopy();
1276
+ this.source.value = this.format === "markdown" ? i(e) : e.innerHTML;
1277
+ }
1278
+ this.updateWordCount();
1279
+ }
1280
+ emitChange() {
1281
+ this.syncSource();
1282
+ let e = this.value;
1283
+ this.dispatchEvent(new CustomEvent("input", {
1284
+ bubbles: !0,
1285
+ composed: !0,
1286
+ detail: { value: e }
1287
+ })), this.dispatchEvent(new CustomEvent("change", {
1288
+ bubbles: !0,
1289
+ composed: !0,
1290
+ detail: { value: e }
1291
+ }));
1292
+ }
1293
+ updateWordCount() {
1294
+ if (!this.editor || !this.count) return;
1295
+ let e = (this.editor.innerText || "").trim().split(/\s+/).filter(Boolean).length;
1296
+ this.count.textContent = `${e} ${e === 1 ? "word" : "words"}`;
1297
+ }
1298
+ updateSelectionUI() {
1299
+ if (!this.editor) return;
1300
+ let e = this.selection, t = e?.anchorNode, n = !!t && this.editor.contains(t), r = n ? t.nodeType === Node.ELEMENT_NODE ? t : t.parentElement : null, i = !this.sourceMode && n ? r?.closest("table") : null;
1301
+ this.selectTable(i && this.editor.contains(i) ? i : null);
1302
+ let a = this.sourceMode || !i;
1303
+ if (this.tableTrigger?.hidden !== a && (this.tableTrigger?.toggleAttribute("hidden", a), this.updateToolbarOverflow()), this.sourceMode || !n) return;
1304
+ let o = r?.closest("h1,h2,h3,h4,h5,h6,p,blockquote,div,li,td,th,pre"), s = o?.tagName.toLowerCase() || "p", c = {
1305
+ p: "Paragraph",
1306
+ h1: "Heading 1",
1307
+ h2: "Heading 2",
1308
+ h3: "Heading 3",
1309
+ h4: "Heading 4",
1310
+ h5: "Heading 5",
1311
+ h6: "Heading 6",
1312
+ blockquote: "Quote",
1313
+ div: "Div",
1314
+ li: "List item",
1315
+ td: "Table cell",
1316
+ th: "Table header",
1317
+ pre: "Code block"
1318
+ }, l = [
1319
+ "h1",
1320
+ "h2",
1321
+ "h3",
1322
+ "h4",
1323
+ "h5",
1324
+ "h6",
1325
+ "blockquote",
1326
+ "div",
1327
+ "li",
1328
+ "td",
1329
+ "th",
1330
+ "pre"
1331
+ ].includes(s) ? s : "p";
1332
+ this.fontSizeDisplay && (this.fontSizeDisplay.textContent = `${this.readFontSize()}px`);
1333
+ let u = o ? getComputedStyle(o).textAlign : "left", d = u === "center" ? "align-center" : u === "right" || u === "end" ? "align-right" : u === "justify" ? "align-justify" : "align-left", f = d === "align-center" ? "Align center" : d === "align-right" ? "Align right" : d === "align-justify" ? "Justify" : "Align left", p = this.alignmentTrigger?.querySelector("mint-icon");
1334
+ p && p.setAttribute("name", d), this.alignmentTrigger && this.updateTooltipLabel(this.alignmentTrigger, `Text alignment: ${f}`);
1335
+ let m = this.toolbar?.querySelector(".mint-editor-toolbar-checklist");
1336
+ m?.classList.toggle("is-active", !!r?.closest("ul[data-mint-task-list]")), m?.setAttribute("aria-pressed", String(!!r?.closest("ul[data-mint-task-list]")));
1337
+ let h = r?.closest("ul,ol"), g = h?.tagName === "UL" && !h.hasAttribute("data-mint-task-list"), _ = h?.tagName === "OL", v = this.toolbar?.querySelector(".mint-editor-toolbar-list"), y = this.toolbar?.querySelector(".mint-editor-toolbar-numbered-list");
1338
+ if (v?.classList.toggle("is-active", !!g), v?.setAttribute("aria-pressed", String(!!g)), y?.classList.toggle("is-active", !!_), y?.setAttribute("aria-pressed", String(!!_)), this.blockButton) {
1339
+ let e = this.blockButton.querySelector(".mint-editor-block-label"), t = c[l] || "Paragraph";
1340
+ e && (e.textContent = t), this.updateTooltipLabel(this.blockButton, `Text style: ${t}`);
1341
+ }
1342
+ this.footerMode && (this.footerMode.textContent = s), this.blockPopover?.querySelectorAll("[data-block-tag]").forEach((e) => {
1343
+ let t = e.dataset.blockTag === l;
1344
+ e.toggleAttribute("data-active", t), e.setAttribute("aria-pressed", String(t));
1345
+ });
1346
+ for (let [t, n] of this.inlineButtons) {
1347
+ let r = e?.rangeCount ? e.getRangeAt(0) : null, i = r ? this.inlineStateAtSelection(t, r) : !1;
1348
+ n.classList.toggle("is-active", i), n.setAttribute("aria-pressed", String(i));
1349
+ }
1350
+ }
1351
+ insertTable(e, t) {
1352
+ if (!this.editor) return;
1353
+ let n = this.editor.ownerDocument, r = n.createElement("table");
1354
+ r.className = "mint-editor-table";
1355
+ let i = n.createElement("tbody");
1356
+ for (let r = 0; r < e; r++) {
1357
+ let e = n.createElement("tr");
1358
+ for (let i = 0; i < t; i++) {
1359
+ let t = n.createElement(r === 0 ? "th" : "td");
1360
+ t.innerHTML = "<br>", e.append(t);
1361
+ }
1362
+ i.append(e);
1363
+ }
1364
+ r.append(i), this.editor.focus(), this.restoreSelection();
1365
+ let a = this.selection;
1366
+ if (a?.rangeCount && this.editor.contains(a.anchorNode)) {
1367
+ let e = a.getRangeAt(0), t = (e.startContainer.nodeType === Node.ELEMENT_NODE ? e.startContainer : e.startContainer.parentElement)?.closest("a");
1368
+ t && this.editor.contains(t) && (e.setStartAfter(t), e.collapse(!0)), e.deleteContents(), e.insertNode(r), e.setStartAfter(r), e.collapse(!0), a.removeAllRanges(), a.addRange(e);
1369
+ } else this.editor.append(r);
1370
+ this.emitChange();
1371
+ }
1372
+ openTableModal() {
1373
+ this.saveSelection();
1374
+ let e = document.createElement("mint-modal");
1375
+ e.setAttribute("heading", "Insert table"), e.setAttribute("size", "small");
1376
+ let t = document.createElement("div");
1377
+ t.setAttribute("slot", "body"), t.className = "mint-editor-modal-fields";
1378
+ let n = document.createElement("mint-input");
1379
+ n.setAttribute("type", "number"), n.setAttribute("label", "Rows"), n.setAttribute("min", "1"), n.setAttribute("max", "12"), n.setAttribute("value", "3");
1380
+ let r = document.createElement("mint-input");
1381
+ r.setAttribute("type", "number"), r.setAttribute("label", "Columns"), r.setAttribute("min", "1"), r.setAttribute("max", "10"), r.setAttribute("value", "3"), t.append(n, r);
1382
+ let i = document.createElement("div");
1383
+ i.setAttribute("slot", "actions"), i.className = "mint-editor-modal-actions";
1384
+ let a = document.createElement("mint-button");
1385
+ a.textContent = "Cancel", a.setAttribute("variant", "ghost"), this.setTooltip(a, "Cancel"), a.addEventListener("click", () => e.close());
1386
+ let o = document.createElement("mint-button");
1387
+ o.textContent = "Insert table", o.setAttribute("tone", "action"), this.setTooltip(o, "Insert table"), o.addEventListener("click", () => {
1388
+ let t = Math.max(1, Math.min(12, Number(n.value) || 3)), i = Math.max(1, Math.min(10, Number(r.value) || 3));
1389
+ e.close(), this.insertTable(t, i);
1390
+ }), i.append(a, o), e.append(t, i), this.append(e), e.open();
1391
+ }
1392
+ openLinkModal() {
1393
+ this.saveSelection();
1394
+ let e = document.createElement("mint-modal");
1395
+ e.setAttribute("heading", "Insert link"), e.setAttribute("size", "small");
1396
+ let t = document.createElement("div");
1397
+ t.setAttribute("slot", "body");
1398
+ let n = document.createElement("mint-input");
1399
+ n.setAttribute("type", "url"), n.setAttribute("label", "Link URL"), n.setAttribute("placeholder", "https://example.com"), t.append(n);
1400
+ let r = document.createElement("div");
1401
+ r.setAttribute("slot", "actions"), r.className = "mint-editor-modal-actions";
1402
+ let i = document.createElement("mint-button");
1403
+ i.textContent = "Cancel", i.setAttribute("variant", "ghost"), this.setTooltip(i, "Cancel"), i.addEventListener("click", () => e.close());
1404
+ let a = document.createElement("mint-button");
1405
+ a.textContent = "Insert link", a.setAttribute("tone", "action"), this.setTooltip(a, "Insert link"), a.addEventListener("click", () => {
1406
+ let t = String(n.value || "").trim();
1407
+ t && (this.command("createLink", t), e.close());
1408
+ }), r.append(i, a), e.append(t, r), this.append(e), e.open();
1409
+ }
1410
+ selectedTable() {
1411
+ let e = this._savedRange?.startContainer || this.selection?.anchorNode, t = (e?.nodeType === Node.ELEMENT_NODE ? e : e?.parentElement)?.closest("table");
1412
+ return t && this.editor?.contains(t) ? t : null;
1413
+ }
1414
+ applyTableAction(e) {
1415
+ let t = this.selectedTable();
1416
+ if (!t) return;
1417
+ let n = this._savedRange, r = (n?.startContainer.nodeType === Node.ELEMENT_NODE ? n.startContainer : n?.startContainer.parentElement)?.closest("td,th"), i = r?.parentElement;
1418
+ if (e === "Add row below" || e === "Add row above") {
1419
+ let n = i?.cloneNode(!0);
1420
+ n && (n.querySelectorAll("th,td").forEach((e) => e.innerHTML = "<br>"), (i?.parentElement || t.querySelector("tbody") || t).insertBefore(n, e === "Add row above" ? i : i?.nextSibling || null));
1421
+ }
1422
+ if (e === "Add column right" || e === "Add column left") {
1423
+ let n = (r ? Array.from(r.parentElement.children).indexOf(r) : (t.querySelector("tr")?.children.length || 1) - 1) + (e === "Add column right" ? 1 : 0);
1424
+ t.querySelectorAll("tr").forEach((e) => {
1425
+ let r = e.querySelector("th") ? "th" : "td", i = t.ownerDocument.createElement(r);
1426
+ i.innerHTML = "<br>", e.insertBefore(i, e.children[n] || null);
1427
+ });
1428
+ }
1429
+ if (e === "Delete row" && i && t.querySelectorAll("tr").length > 1 && i.remove(), e === "Delete column" && r && r.parentElement.children.length > 1) {
1430
+ let e = Array.from(r.parentElement.children).indexOf(r);
1431
+ t.querySelectorAll("tr").forEach((t) => t.children[e]?.remove());
1432
+ }
1433
+ e === "Delete table" && t.remove(), this.emitChange(), this.updateSelectionUI();
1434
+ }
1435
+ selectTable(e) {
1436
+ this.selectedTableElement !== e && this.selectedTableElement?.classList.remove("is-selected"), this.selectedTableElement = e, e?.classList.add("is-selected");
1437
+ let t = !!e && !this.sourceMode;
1438
+ this.inlineTableTools && (this.inlineTableTools.hidden = !t), this.tableResizeHandle && (this.tableResizeHandle.hidden = !t), t && this.positionTableTools();
1439
+ }
1440
+ positionTableTools() {
1441
+ let e = this.selectedTableElement, t = this.querySelector(".mint-editor-shell"), n = this.editorFrame;
1442
+ if (!e || !t || !n || !this.inlineTableTools || !this.tableResizeHandle || this.sourceMode) return;
1443
+ let r = t.getBoundingClientRect(), i = n.getBoundingClientRect(), a = e.getBoundingClientRect(), o = i.left + a.left - r.left, s = i.top + a.top - r.top, c = this.inlineTableTools.offsetWidth || 280, l = Math.max(6, Math.min(t.clientWidth - c - 6, o + a.width / 2 - c / 2)), u = Math.max(6, s - this.inlineTableTools.offsetHeight - 10);
1444
+ this.inlineTableTools.style.left = `${l}px`, this.inlineTableTools.style.top = `${u}px`, this.tableResizeHandle.style.left = `${Math.max(0, o + a.width - 18)}px`, this.tableResizeHandle.style.top = `${Math.max(0, s + a.height - 18)}px`;
1445
+ }
1446
+ startTableResize(e) {
1447
+ let t = this.selectedTableElement;
1448
+ if (!t) return;
1449
+ e.preventDefault(), e.stopPropagation();
1450
+ let n = t.getBoundingClientRect();
1451
+ this.tableResizeState = {
1452
+ table: t,
1453
+ startX: e.clientX,
1454
+ startY: e.clientY,
1455
+ startWidth: n.width,
1456
+ startHeight: n.height,
1457
+ pointerId: e.pointerId
1458
+ }, this.ownerDocument.defaultView?.addEventListener("pointermove", this.onTableResizeMove), this.ownerDocument.defaultView?.addEventListener("pointerup", this.onTableResizeEnd);
1459
+ }
1460
+ startGridResize(e) {
1461
+ let t = e.target?.closest("td,th"), n = t?.closest("table");
1462
+ if (!t || !n || !this.editor?.contains(n)) return;
1463
+ let r = t.getBoundingClientRect(), i = Math.abs(e.clientX - r.right) <= 7, a = Math.abs(e.clientY - r.bottom) <= 7;
1464
+ if (!i && !a) return;
1465
+ let o = t.parentElement, s = Array.from(n.rows).indexOf(o);
1466
+ if (a) this.gridResizeState = {
1467
+ table: n,
1468
+ kind: "row",
1469
+ index: s,
1470
+ start: e.clientY,
1471
+ size: o.getBoundingClientRect().height,
1472
+ pointerId: e.pointerId
1473
+ };
1474
+ else {
1475
+ let i = Array.from(o.cells).indexOf(t);
1476
+ this.ensureTableColumns(n);
1477
+ let a = n.querySelectorAll("col")[i];
1478
+ this.gridResizeState = {
1479
+ table: n,
1480
+ kind: "column",
1481
+ index: i,
1482
+ start: e.clientX,
1483
+ size: a?.getBoundingClientRect().width || r.width,
1484
+ pointerId: e.pointerId
1485
+ };
1486
+ }
1487
+ e.preventDefault(), e.stopPropagation();
1488
+ let c = this.editor?.ownerDocument.defaultView;
1489
+ c?.addEventListener("pointermove", this.onGridResizeMove), c?.addEventListener("pointerup", this.onGridResizeEnd), c?.addEventListener("pointercancel", this.onGridResizeEnd);
1490
+ }
1491
+ updateGridResizeCursor(e) {
1492
+ let t = this.editor;
1493
+ if (!t || this.gridResizeState) return;
1494
+ let n = e.target?.closest("td,th");
1495
+ if (!n) {
1496
+ t.style.cursor = "";
1497
+ return;
1498
+ }
1499
+ let r = n.getBoundingClientRect(), i = Math.abs(e.clientX - r.right) <= 7, a = Math.abs(e.clientY - r.bottom) <= 7;
1500
+ t.style.cursor = i && a ? "nwse-resize" : i ? "col-resize" : a ? "row-resize" : "";
1501
+ }
1502
+ ensureTableColumns(e) {
1503
+ let t = e.querySelector("colgroup");
1504
+ t || (t = e.ownerDocument.createElement("colgroup"), e.insertBefore(t, e.firstChild));
1505
+ let n = Math.max(1, ...Array.from(e.rows, (e) => e.cells.length));
1506
+ for (; t.children.length < n;) t.append(e.ownerDocument.createElement("col"));
1507
+ }
1508
+ toggleSource() {
1509
+ if (!(!this.editor || !this.source)) {
1510
+ if (this.sourceMode = !this.sourceMode, this.clearInlineTypingState(), this.source.hidden = !this.sourceMode, this.editor.hidden = this.sourceMode, this.sourceMode) {
1511
+ let e = this.cleanEditorCopy();
1512
+ this.source.value = this.format === "markdown" ? i(e) : e.innerHTML;
1513
+ } else this.editor.innerHTML = this.format === "markdown" ? n(this.source.value) : this.source.value;
1514
+ this.toolbar?.classList.toggle("mint-editor-source-active", this.sourceMode), this.updateWordCount(), this.sourceMode ? this.selectTable(null) : this.updateSelectionUI();
1515
+ }
1516
+ }
1517
+ createResizeHandle() {
1518
+ let e = (this.editor?.ownerDocument || document).createElement("button");
1519
+ return e.type = "button", e.className = "mint-editor-resize-handle", this.setTooltip(e, "Resize image"), e.addEventListener("pointerdown", (t) => {
1520
+ t.preventDefault(), t.stopPropagation();
1521
+ let n = e.parentElement;
1522
+ this.resizeState = {
1523
+ frame: n,
1524
+ startX: t.clientX,
1525
+ startWidth: n.getBoundingClientRect().width,
1526
+ pointerId: t.pointerId
1527
+ }, this.editor?.ownerDocument.defaultView?.addEventListener("pointermove", this.onResizeMove), this.editor?.ownerDocument.defaultView?.addEventListener("pointerup", this.onResizeEnd);
1528
+ }), e;
1529
+ }
1530
+ selectImage(e) {
1531
+ this.selectedImage?.classList.remove("is-selected"), this.selectedImage = e, e?.classList.add("is-selected");
1532
+ let t = this.querySelector(".mint-editor-image-tools");
1533
+ t && (t.hidden = !e);
1534
+ let n = t?.querySelector("mint-input");
1535
+ e && n && (n.value = `${Math.round(e.getBoundingClientRect().width / Math.max(1, this.editor?.clientWidth || e.getBoundingClientRect().width) * 100)}`);
1536
+ }
1537
+ updateSelectedImage() {
1538
+ let e = this.selection?.anchorNode, t = e?.nodeType === Node.ELEMENT_NODE ? e.closest(".mint-editor-image-frame") : e?.parentElement?.closest(".mint-editor-image-frame");
1539
+ t && this.selectImage(t);
1540
+ }
1541
+ };
1542
+ customElements.get("mint-editor") || e("mint-editor", a);
1543
+ //#endregion
1544
+ export { a as default };