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