monobill-mintui 0.6.736 → 0.6.737
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.
- package/dist/components/editor/Editor.d.ts +2 -0
- package/dist/components/editor/Editor.d.ts.map +1 -1
- package/dist/components/editor/browser.js +52 -48
- package/dist/components/editor/index.cjs +2 -2
- package/dist/components/editor/index.js +52 -48
- package/dist/index.cjs +2 -2
- package/dist/index.js +52 -48
- package/package.json +1 -1
|
@@ -10,6 +10,8 @@ declare class MintEditor extends HTMLElement {
|
|
|
10
10
|
private editor;
|
|
11
11
|
private editorFrame;
|
|
12
12
|
private pendingValue;
|
|
13
|
+
/** Content to restore if the host is re-rendered before its iframe is ready. */
|
|
14
|
+
private preservedContent;
|
|
13
15
|
private source;
|
|
14
16
|
private toolbar;
|
|
15
17
|
private count;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Editor.d.ts","sourceRoot":"","sources":["../../../src/components/editor/Editor.ts"],"names":[],"mappings":"AAEA,KAAK,cAAc,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AA6ElG,cAAM,UAAW,SAAQ,WAAW;IAClC,MAAM,KAAK,kBAAkB,IAAI,MAAM,EAAE,CAExC;IAED,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,WAAW,CAAiC;IACpD,OAAO,CAAC,YAAY,CAAsB;IAC1C,OAAO,CAAC,MAAM,CAAmC;IACjD,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,aAAa,CAA2B;IAChD,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,mBAAmB,CAA8B;IACzD,OAAO,CAAC,WAAW,CAA6F;IAChH,OAAO,CAAC,gBAAgB,CAA8F;IACtH,OAAO,CAAC,YAAY,CAAsB;IAC1C,OAAO,CAAC,YAAY,CAAiC;IACrD,OAAO,CAAC,WAAW,CAAiC;IACpD,OAAO,CAAC,YAAY,CAA2B;IAC/C,OAAO,CAAC,YAAY,CAA2B;IAC/C,OAAO,CAAC,YAAY,CAAiC;IACrD,OAAO,CAAC,oBAAoB,CAAgC;IAC5D,OAAO,CAAC,gBAAgB,CAA2B;IACnD,OAAO,CAAC,iBAAiB,CAAiC;IAC1D,OAAO,CAAC,gBAAgB,CAAuI;IAC/J,OAAO,CAAC,eAAe,CAAkI;IACzJ,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,aAAa,CAAuC;IAI5D,OAAO,CAAC,eAAe,CAA6B;IACpD,OAAO,CAAC,oBAAoB,CAA4B;IACxD,OAAO,CAAC,wCAAwC,CAAQ;IACxD,OAAO,CAAC,qBAAqB,CAA8B;IAC3D,OAAO,CAAC,eAAe,CAA2B;IAClD,OAAO,CAAC,eAAe,CAAiC;IACxD,OAAO,CAAC,cAAc,CAAsB;IAC5C,OAAO,CAAC,YAAY,CAA2B;IAC/C,OAAO,CAAC,eAAe,CAA2B;IAClD,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,mBAAmB,CAAY;IACvC,OAAO,CAAC,aAAa,CAAuC;IAC5D,OAAO,CAAC,mBAAmB,CAAuC;IAClE,OAAO,CAAC,gBAAgB,CAAiC;IAEzD,iBAAiB,IAAI,IAAI;IAOzB,oBAAoB,IAAI,IAAI;IAoB5B,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAmB9F,IAAI,MAAM,IAAI,MAAM,GAAG,UAAU,CAA4E;IAC7G,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,EAA6E;IAElH,IAAI,KAAK,IAAI,MAAM,CAKlB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAAgC;IAEvD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"Editor.d.ts","sourceRoot":"","sources":["../../../src/components/editor/Editor.ts"],"names":[],"mappings":"AAEA,KAAK,cAAc,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AA6ElG,cAAM,UAAW,SAAQ,WAAW;IAClC,MAAM,KAAK,kBAAkB,IAAI,MAAM,EAAE,CAExC;IAED,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,WAAW,CAAiC;IACpD,OAAO,CAAC,YAAY,CAAsB;IAC1C,gFAAgF;IAChF,OAAO,CAAC,gBAAgB,CAAsB;IAC9C,OAAO,CAAC,MAAM,CAAmC;IACjD,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,aAAa,CAA2B;IAChD,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,mBAAmB,CAA8B;IACzD,OAAO,CAAC,WAAW,CAA6F;IAChH,OAAO,CAAC,gBAAgB,CAA8F;IACtH,OAAO,CAAC,YAAY,CAAsB;IAC1C,OAAO,CAAC,YAAY,CAAiC;IACrD,OAAO,CAAC,WAAW,CAAiC;IACpD,OAAO,CAAC,YAAY,CAA2B;IAC/C,OAAO,CAAC,YAAY,CAA2B;IAC/C,OAAO,CAAC,YAAY,CAAiC;IACrD,OAAO,CAAC,oBAAoB,CAAgC;IAC5D,OAAO,CAAC,gBAAgB,CAA2B;IACnD,OAAO,CAAC,iBAAiB,CAAiC;IAC1D,OAAO,CAAC,gBAAgB,CAAuI;IAC/J,OAAO,CAAC,eAAe,CAAkI;IACzJ,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,aAAa,CAAuC;IAI5D,OAAO,CAAC,eAAe,CAA6B;IACpD,OAAO,CAAC,oBAAoB,CAA4B;IACxD,OAAO,CAAC,wCAAwC,CAAQ;IACxD,OAAO,CAAC,qBAAqB,CAA8B;IAC3D,OAAO,CAAC,eAAe,CAA2B;IAClD,OAAO,CAAC,eAAe,CAAiC;IACxD,OAAO,CAAC,cAAc,CAAsB;IAC5C,OAAO,CAAC,YAAY,CAA2B;IAC/C,OAAO,CAAC,eAAe,CAA2B;IAClD,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,mBAAmB,CAAY;IACvC,OAAO,CAAC,aAAa,CAAuC;IAC5D,OAAO,CAAC,mBAAmB,CAAuC;IAClE,OAAO,CAAC,gBAAgB,CAAiC;IAEzD,iBAAiB,IAAI,IAAI;IAOzB,oBAAoB,IAAI,IAAI;IAoB5B,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAmB9F,IAAI,MAAM,IAAI,MAAM,GAAG,UAAU,CAA4E;IAC7G,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,EAA6E;IAElH,IAAI,KAAK,IAAI,MAAM,CAKlB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAAgC;IAEvD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAc7B,kFAAkF;IAClF,cAAc,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,GAAG,IAAI;IAgCvD,OAAO,CAAC,MAAM;IA4Md,OAAO,CAAC,kBAAkB,CAczB;IAED,OAAO,CAAC,iBAAiB,CAQxB;IAED,OAAO,CAAC,gBAAgB,CAIvB;IAED,OAAO,CAAC,0BAA0B;IAQlC,OAAO,CAAC,eAAe;IA6GvB,OAAO,CAAC,YAAY;IA2MpB,OAAO,CAAC,iBAAiB;IAoFzB,OAAO,CAAC,gBAAgB;IAkCxB,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,aAAa;IA6BrB,OAAO,CAAC,eAAe;IA0BvB,OAAO,CAAC,cAAc;IAqBtB,OAAO,CAAC,eAAe;IA+CvB,OAAO,CAAC,aAAa;IA6CrB,OAAO,CAAC,sBAAsB;IA4C9B,OAAO,CAAC,eAAe;IAYvB,OAAO,CAAC,YAAY;IA6BpB,OAAO,CAAC,gBAAgB;IA4CxB,OAAO,CAAC,aAAa;IAsBrB,OAAO,CAAC,qBAAqB;IAoC7B,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,UAAU;IASlB,OAAO,CAAC,kBAAkB;IAQ1B,OAAO,CAAC,WAAW;IAkCnB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,mBAAmB;IAM3B,OAAO,CAAC,gBAAgB;IAoBxB,OAAO,CAAC,cAAc;IAEtB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,YAAY;IA0BpB,OAAO,CAAC,sBAAsB;IAkC9B,OAAO,CAAC,sBAAsB;IAyE9B,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,aAAa;IA0CrB,OAAO,CAAC,eAAe;IACvB,OAAO,KAAK,SAAS,GAAiF;IACtG,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,sBAAsB;IAC9B,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,gBAAgB;IA8DxB,OAAO,CAAC,qBAAqB;IAK7B,OAAO,CAAC,4BAA4B;IAWpC,OAAO,CAAC,kBAAkB;IAgM1B,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,eAAe;IAEvB,OAAO,CAAC,iBAAiB;IAyDzB,OAAO,CAAC,WAAW;IA2BnB,OAAO,CAAC,cAAc;IAatB,OAAO,CAAC,aAAa;IAUrB,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,kBAAkB;IAoB1B,OAAO,CAAC,gBAAgB;IAUxB,OAAO,CAAC,iBAAiB,CAOxB;IAED,OAAO,CAAC,gBAAgB,CAMvB;IAED,OAAO,CAAC,eAAe;IA0BvB,OAAO,CAAC,sBAAsB;IAY9B,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,gBAAgB,CAYvB;IAED,OAAO,CAAC,eAAe,CAQtB;IAED,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,YAAY,CAAwU;IAC5V,OAAO,CAAC,WAAW,CAA4V;IAC/W,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,mBAAmB;CAC5B;AAGD,eAAe,UAAU,CAAA"}
|
|
@@ -91,7 +91,7 @@ function i(e) {
|
|
|
91
91
|
}
|
|
92
92
|
var a = class extends HTMLElement {
|
|
93
93
|
constructor(...e) {
|
|
94
|
-
super(...e), this.editor = null, this.editorFrame = null, this.pendingValue = null, this.source = null, this.toolbar = null, this.count = null, this.selectedImage = null, this.sourceMode = !1, this.observer = null, this.frameResizeObserver = null, this.resizeState = null, this.stageResizeState = null, this.editorHeight = null, this.sourceButton = null, this.blockButton = null, this.blockPopover = null, this.tablePopover = null, this.tableTrigger = null, this.selectedTableElement = null, this.inlineTableTools = null, this.tableResizeHandle = null, this.tableResizeState = null, this.gridResizeState = null, this.footerMode = null, this.inlineButtons = /* @__PURE__ */ new Map(), this.inlineOverrides = /* @__PURE__ */ new Map(), this.inlineStyleOverrides = /* @__PURE__ */ new Map(), this.preserveInlineOverridesOnNextEditorClick = !1, this.toolbarResizeObserver = null, this.overflowPopover = null, this.overflowTrigger = null, this.overflowGroups = [], this.tooltipPopup = null, this.fontSizeDisplay = null, this.lastTextColor = "#202833", this.lastBackgroundColor = "#fff2a8", this.colorTriggers = /* @__PURE__ */ new Map(), this.colorRecentSwatches = /* @__PURE__ */ new Map(), this.alignmentTrigger = null, this.onStageResizeStart = (e, t) => {
|
|
94
|
+
super(...e), this.editor = null, this.editorFrame = null, this.pendingValue = null, this.preservedContent = null, this.source = null, this.toolbar = null, this.count = null, this.selectedImage = null, this.sourceMode = !1, this.observer = null, this.frameResizeObserver = null, this.resizeState = null, this.stageResizeState = null, this.editorHeight = null, this.sourceButton = null, this.blockButton = null, this.blockPopover = null, this.tablePopover = null, this.tableTrigger = null, this.selectedTableElement = null, this.inlineTableTools = null, this.tableResizeHandle = null, this.tableResizeState = null, this.gridResizeState = null, this.footerMode = null, this.inlineButtons = /* @__PURE__ */ new Map(), this.inlineOverrides = /* @__PURE__ */ new Map(), this.inlineStyleOverrides = /* @__PURE__ */ new Map(), this.preserveInlineOverridesOnNextEditorClick = !1, this.toolbarResizeObserver = null, this.overflowPopover = null, this.overflowTrigger = null, this.overflowGroups = [], this.tooltipPopup = null, this.fontSizeDisplay = null, this.lastTextColor = "#202833", this.lastBackgroundColor = "#fff2a8", this.colorTriggers = /* @__PURE__ */ new Map(), this.colorRecentSwatches = /* @__PURE__ */ new Map(), this.alignmentTrigger = null, this.onStageResizeStart = (e, t) => {
|
|
95
95
|
if (e.button !== 0) return;
|
|
96
96
|
e.preventDefault(), e.stopPropagation(), this.stageResizeState = {
|
|
97
97
|
stage: t,
|
|
@@ -197,10 +197,10 @@ var a = class extends HTMLElement {
|
|
|
197
197
|
}
|
|
198
198
|
setValue(e) {
|
|
199
199
|
if (!this.editor) {
|
|
200
|
-
this.pendingValue = e, this.getAttribute("value") !== e && this.setAttribute("value", e);
|
|
200
|
+
this.pendingValue = e, this.preservedContent = e, this.getAttribute("value") !== e && this.setAttribute("value", e);
|
|
201
201
|
return;
|
|
202
202
|
}
|
|
203
|
-
this.editor.innerHTML = this.format === "markdown" ? n(e) : e, this.clearInlineTypingState(), this.source && (this.source.value = e), this.updateWordCount();
|
|
203
|
+
this.editor.innerHTML = this.format === "markdown" ? n(e) : e, this.preservedContent = e, this.clearInlineTypingState(), this.source && (this.source.value = e), this.updateWordCount();
|
|
204
204
|
}
|
|
205
205
|
insertResource(e) {
|
|
206
206
|
let t = typeof e == "string" ? { url: e } : e, n = t.url || t.src;
|
|
@@ -218,21 +218,23 @@ var a = class extends HTMLElement {
|
|
|
218
218
|
this.selectImage(i), this.emitChange();
|
|
219
219
|
}
|
|
220
220
|
render() {
|
|
221
|
-
let e = this.
|
|
221
|
+
let e = this.getAttribute("value"), r = this.editor?.innerHTML ?? this.pendingValue ?? e ?? this.preservedContent ?? this.innerHTML;
|
|
222
|
+
this.editor ? this.preservedContent = this.format === "markdown" && this.source ? this.source.value : this.editor.innerHTML : this.pendingValue === null ? e === null ? this.preservedContent === null && (this.preservedContent = r) : this.preservedContent = e : this.preservedContent = this.pendingValue;
|
|
223
|
+
let i = this.editor ? r : this.format === "markdown" ? n(r) : r;
|
|
222
224
|
this.observer?.disconnect(), this.inlineButtons.clear(), this.colorTriggers.clear(), this.colorRecentSwatches.clear(), this.clearInlineTypingState(), this.editor = null, this.selectedImage = null;
|
|
223
|
-
let
|
|
225
|
+
let a = this.hasAttribute("disabled") && this.getAttribute("disabled") !== "false", o = this.editorHeight === null ? this.getAttribute("height") || "300px" : `${this.editorHeight}px`, s = this.getAttribute("label") || "";
|
|
224
226
|
this.innerHTML = "";
|
|
225
|
-
let
|
|
226
|
-
if (
|
|
227
|
+
let c = document.createElement("div");
|
|
228
|
+
if (c.className = "mint-editor-root", this.hasAttribute("error") && c.classList.add("mint-editor-has-error"), this.hasAttribute("compact") && c.classList.add("mint-editor-compact"), s) {
|
|
227
229
|
let e = document.createElement("label");
|
|
228
|
-
e.className = "mint-editor-label", e.textContent =
|
|
230
|
+
e.className = "mint-editor-label", e.textContent = s, e.id = `${this.id || "mint-editor"}-label`, c.append(e);
|
|
229
231
|
}
|
|
230
|
-
let c = document.createElement("div");
|
|
231
|
-
c.className = "mint-editor-shell";
|
|
232
232
|
let l = document.createElement("div");
|
|
233
|
-
l.className = "mint-editor-
|
|
233
|
+
l.className = "mint-editor-shell";
|
|
234
234
|
let u = document.createElement("div");
|
|
235
|
-
u.className = "mint-editor-
|
|
235
|
+
u.className = "mint-editor-toolbar", u.setAttribute("role", "toolbar"), u.setAttribute("aria-label", "Text formatting"), this.toolbar = u, this.buildToolbar(u);
|
|
236
|
+
let d = document.createElement("div");
|
|
237
|
+
d.className = "mint-editor-inline-table-tools", d.setAttribute("role", "toolbar"), d.setAttribute("aria-label", "Table tools"), d.hidden = !0;
|
|
236
238
|
for (let [e, t] of [
|
|
237
239
|
["Add row above", "arrow-up"],
|
|
238
240
|
["Add row below", "arrow-down"],
|
|
@@ -245,12 +247,12 @@ var a = class extends HTMLElement {
|
|
|
245
247
|
let n = document.createElement("button");
|
|
246
248
|
n.type = "button", n.className = "mint-editor-table-tool-button", this.setTooltip(n, e), n.append(this.icon(t)), n.addEventListener("pointerdown", (e) => {
|
|
247
249
|
e.preventDefault(), this.saveSelection();
|
|
248
|
-
}), n.addEventListener("click", () => this.applyTableAction(e)),
|
|
250
|
+
}), n.addEventListener("click", () => this.applyTableAction(e)), d.append(n);
|
|
249
251
|
}
|
|
250
|
-
let
|
|
251
|
-
|
|
252
|
-
let
|
|
253
|
-
|
|
252
|
+
let f = document.createElement("button");
|
|
253
|
+
f.type = "button", f.className = "mint-editor-table-resize-handle", this.setTooltip(f, "Resize table"), f.addEventListener("pointerdown", (e) => this.startTableResize(e)), this.inlineTableTools = d, this.tableResizeHandle = f;
|
|
254
|
+
let p = document.createElement("iframe");
|
|
255
|
+
p.className = "mint-editor-frame", p.title = s ? `${s} editor` : "Rich text editor", p.setAttribute("sandbox", "allow-same-origin"), p.style.height = "100%", p.srcdoc = `<!doctype html><html><head><meta charset="utf-8"><style>
|
|
254
256
|
html,body{box-sizing:border-box;width:100%;height:100%;min-width:0;margin:0;overflow:hidden}
|
|
255
257
|
.editor{box-sizing:border-box;width:100%;height:100%;min-width:0;min-height:0;overflow:auto;overflow-wrap:anywhere;padding:1rem;outline:0;color:var(--mint-color-text,#202833);background:var(--mint-color-surface,#fff);font:inherit;line-height:1.55}
|
|
256
258
|
.editor:empty:before{content:attr(data-placeholder);color:var(--mint-color-text-muted,#7b8492);pointer-events:none}
|
|
@@ -263,52 +265,54 @@ var a = class extends HTMLElement {
|
|
|
263
265
|
.mint-editor-image-frame{position:relative;display:inline-block;max-width:100%;margin:.5rem 0;vertical-align:middle}.mint-editor-image-frame img{display:block;width:100%;height:auto;max-height:none;border-radius:.25rem;object-fit:contain}.mint-editor-image-frame.is-selected{outline:2px solid var(--mint-color-primary,#1e5bff);outline-offset:2px}
|
|
264
266
|
.mint-editor-resize-handle{position:absolute;right:-.45rem;bottom:-.45rem;width:.9rem;height:.9rem;padding:0;border:2px solid var(--mint-color-surface,#fff);border-radius:50%;background:var(--mint-color-primary,#1e5bff);cursor:nwse-resize;touch-action:none}
|
|
265
267
|
@media(max-width:640px){.editor{padding:.75rem}}
|
|
266
|
-
</style></head><body><div class="editor" contenteditable="${!
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
let h =
|
|
268
|
+
</style></head><body><div class="editor" contenteditable="${!a}" role="textbox" aria-multiline="true" aria-label="${t(s || "Rich text editor")}" data-placeholder="${t(this.getAttribute("placeholder") || "Start writing…")}"></div></body></html>`, p.addEventListener("load", () => {
|
|
269
|
+
!this.isConnected || this.editorFrame !== p || this.bindEditorFrame(i, a);
|
|
270
|
+
}), this.editorFrame = p;
|
|
271
|
+
let m = document.createElement("textarea");
|
|
272
|
+
m.className = "mint-editor-source", m.style.height = "100%", m.setAttribute("aria-label", `Editor ${this.format.toUpperCase()} source`), m.hidden = !0, m.value = this.format === "markdown" ? r : i, m.addEventListener("input", () => {
|
|
273
|
+
this.editor && (this.editor.innerHTML = this.format === "markdown" ? n(m.value) : m.value), this.updateWordCount(), this.emitChange();
|
|
274
|
+
}), this.source = m;
|
|
275
|
+
let h = document.createElement("div");
|
|
276
|
+
h.className = "mint-editor-stage", h.style.height = o, h.append(p, m);
|
|
277
|
+
let g = null;
|
|
274
278
|
[
|
|
275
279
|
"false",
|
|
276
280
|
"0",
|
|
277
281
|
"off",
|
|
278
282
|
"no"
|
|
279
|
-
].includes((this.getAttribute("resizable") || "").trim().toLowerCase()) || (
|
|
280
|
-
let
|
|
281
|
-
|
|
282
|
-
let
|
|
283
|
-
|
|
283
|
+
].includes((this.getAttribute("resizable") || "").trim().toLowerCase()) || (g = document.createElement("button"), g.type = "button", g.className = "mint-editor-stage-resize-handle", this.setTooltip(g, "Resize editor"), g.addEventListener("pointerdown", (e) => this.onStageResizeStart(e, h))), l.append(u, h, d, f);
|
|
284
|
+
let _ = document.createElement("div");
|
|
285
|
+
_.className = "mint-editor-image-tools", _.hidden = !0, _.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>", _.querySelectorAll("[data-align]").forEach((e) => this.setTooltip(e, `Align image ${e.dataset.align}`));
|
|
286
|
+
let v = _.querySelector("[data-remove=\"image\"]");
|
|
287
|
+
v && this.setTooltip(v, "Remove image"), _.querySelector("mint-input")?.addEventListener("input", (e) => {
|
|
284
288
|
if (!this.selectedImage) return;
|
|
285
289
|
let t = Number(e.target.value);
|
|
286
290
|
this.selectedImage.style.width = `${Math.max(10, Math.min(100, t))}%`, this.emitChange();
|
|
287
|
-
}),
|
|
291
|
+
}), _.querySelectorAll("[data-align]").forEach((e) => e.addEventListener("click", () => {
|
|
288
292
|
this.selectedImage && (this.selectedImage.style.marginLeft = e.dataset.align === "right" || e.dataset.align === "center" ? "auto" : "0", this.selectedImage.style.marginRight = e.dataset.align === "left" || e.dataset.align === "center" ? "auto" : "0", this.emitChange());
|
|
289
|
-
})),
|
|
293
|
+
})), _.querySelector("[data-remove=\"image\"]")?.addEventListener("click", () => {
|
|
290
294
|
this.selectedImage?.remove(), this.selectImage(null), this.emitChange();
|
|
291
|
-
}),
|
|
292
|
-
let
|
|
293
|
-
|
|
294
|
-
let y = document.createElement("span");
|
|
295
|
-
y.className = "mint-editor-mode", y.textContent = "p";
|
|
295
|
+
}), c.append(l, _);
|
|
296
|
+
let y = document.createElement("div");
|
|
297
|
+
y.className = "mint-editor-footer";
|
|
296
298
|
let b = document.createElement("span");
|
|
297
|
-
b.className = "mint-editor-
|
|
298
|
-
let x = document.createElement("
|
|
299
|
-
x.className = "mint-editor-
|
|
300
|
-
let S =
|
|
301
|
-
|
|
299
|
+
b.className = "mint-editor-mode", b.textContent = "p";
|
|
300
|
+
let x = document.createElement("span");
|
|
301
|
+
x.className = "mint-editor-word-count", this.count = x;
|
|
302
|
+
let S = document.createElement("div");
|
|
303
|
+
S.className = "mint-editor-footer-end", S.append(x), g && S.append(g), y.append(b, S), this.footerMode = b, l.append(y);
|
|
304
|
+
let C = this.getAttribute("error");
|
|
305
|
+
if (C) {
|
|
302
306
|
let e = document.createElement("div");
|
|
303
|
-
e.className = "mint-editor-error", e.textContent =
|
|
307
|
+
e.className = "mint-editor-error", e.textContent = C, c.append(e);
|
|
304
308
|
}
|
|
305
|
-
this.append(
|
|
306
|
-
let
|
|
307
|
-
if (
|
|
309
|
+
this.append(c);
|
|
310
|
+
let w = this.querySelector(".mint-editor-stage");
|
|
311
|
+
if (w && typeof ResizeObserver < "u" && (this.frameResizeObserver?.disconnect(), this.frameResizeObserver = new ResizeObserver(([e]) => {
|
|
308
312
|
if (!e || !this.editorFrame) return;
|
|
309
313
|
let t = Math.max(0, e.contentRect.width), n = Math.max(0, e.contentRect.height);
|
|
310
314
|
this.editorFrame.style.width = `${t}px`, this.editorFrame.style.height = `${n}px`;
|
|
311
|
-
}), this.frameResizeObserver.observe(
|
|
315
|
+
}), this.frameResizeObserver.observe(w)), this.toolbar && typeof ResizeObserver < "u") {
|
|
312
316
|
this.toolbarResizeObserver?.disconnect(), this.toolbarResizeObserver = new ResizeObserver(() => this.updateToolbarOverflow()), this.toolbarResizeObserver.observe(this.toolbar);
|
|
313
317
|
let e = this.toolbar.querySelector(".mint-editor-toolbar-actions");
|
|
314
318
|
e && this.toolbarResizeObserver.observe(e), requestAnimationFrame(() => this.updateToolbarOverflow());
|
|
@@ -1273,7 +1277,7 @@ var a = class extends HTMLElement {
|
|
|
1273
1277
|
syncSource() {
|
|
1274
1278
|
if (this.source && this.editor) {
|
|
1275
1279
|
let e = this.cleanEditorCopy();
|
|
1276
|
-
this.source.value = this.format === "markdown" ? i(e) : e.innerHTML;
|
|
1280
|
+
this.source.value = this.format === "markdown" ? i(e) : e.innerHTML, this.preservedContent = this.format === "markdown" ? this.source.value : this.editor.innerHTML;
|
|
1277
1281
|
}
|
|
1278
1282
|
this.updateWordCount();
|
|
1279
1283
|
}
|
|
@@ -13,7 +13,7 @@ const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/ico
|
|
|
13
13
|
`}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(`
|
|
14
14
|
`)+`
|
|
15
15
|
|
|
16
|
-
`:i===`span`&&n.classList.contains(`mint-editor-image-frame`)?t(n.querySelector(`img`)||n):r};return Array.from(e.childNodes).map(t).join(``).trim()}var a=class extends HTMLElement{constructor(...e){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=new Map,this.inlineOverrides=new Map,this.inlineStyleOverrides=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=new Map,this.colorRecentSwatches=new Map,this.alignmentTrigger=null,this.onStageResizeStart=(e,t)=>{if(e.button!==0)return;e.preventDefault(),e.stopPropagation(),this.stageResizeState={stage:t,startY:e.clientY,startHeight:t.getBoundingClientRect().height,pointerId:e.pointerId};let n=this.ownerDocument.defaultView;n?.addEventListener(`pointermove`,this.onStageResizeMove),n?.addEventListener(`pointerup`,this.onStageResizeEnd),n?.addEventListener(`pointercancel`,this.onStageResizeEnd)},this.onStageResizeMove=e=>{let t=this.stageResizeState;if(!t||e.pointerId!==t.pointerId)return;e.preventDefault();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)));t.stage.style.height=`${r}px`,this.editorHeight=r},this.onStageResizeEnd=e=>{!this.stageResizeState||e.pointerId!==this.stageResizeState.pointerId||(this.stageResizeState=null,this.removeStageResizeListeners())},this.onTableResizeMove=e=>{let t=this.tableResizeState;if(!t||e.pointerId!==t.pointerId)return;let n=this.editor?.clientWidth||t.startWidth+300;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()},this.onTableResizeEnd=e=>{!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())},this.onGridResizeMove=e=>{let t=this.gridResizeState;if(!(!t||e.pointerId!==t.pointerId)){if(t.kind===`row`){let n=t.table.rows[t.index];n&&(n.style.height=`${Math.max(28,t.size+e.clientY-t.start)}px`)}else{this.ensureTableColumns(t.table);let n=t.table.querySelectorAll(`col`)[t.index];n&&(n.style.width=`${Math.max(48,t.size+e.clientX-t.start)}px`)}this.positionTableTools()}},this.onGridResizeEnd=e=>{if(!this.gridResizeState||e.pointerId!==this.gridResizeState.pointerId)return;this.gridResizeState=null;let t=this.editor?.ownerDocument.defaultView;t?.removeEventListener(`pointermove`,this.onGridResizeMove),t?.removeEventListener(`pointerup`,this.onGridResizeEnd),t?.removeEventListener(`pointercancel`,this.onGridResizeEnd),this.emitChange()},this.onResizeMove=e=>{if(!this.resizeState||e.pointerId!==this.resizeState.pointerId)return;let t=this.editor?.clientWidth||1e3,n=Math.max(80,Math.min(t,this.resizeState.startWidth+e.clientX-this.resizeState.startX));this.resizeState.frame.style.width=`${n}px`},this.onResizeEnd=e=>{!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())}}static get observedAttributes(){return[`label`,`placeholder`,`disabled`,`error`,`height`,`compact`,`format`,`value`,`resizable`]}connectedCallback(){this.editor||this.render(),this.observer=new MutationObserver(()=>this.updateWordCount()),this.editor&&this.observer.observe(this.editor,{childList:!0,subtree:!0,characterData:!0}),this.ownerDocument.defaultView?.addEventListener(`resize`,this.positionTableTools)}disconnectedCallback(){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);let e=this.editor?.ownerDocument.defaultView;e?.removeEventListener(`pointermove`,this.onGridResizeMove),e?.removeEventListener(`pointerup`,this.onGridResizeEnd),this.removeStageResizeListeners()}attributeChangedCallback(e,t,r){if(this.isConnected){if(e===`format`){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());return}if(e===`value`){this.setValue(r||``);return}e===`height`&&(this.editorHeight=null),this.render()}}get format(){return this.getAttribute(`format`)===`markdown`?`markdown`:`html`}set format(e){this.setAttribute(`format`,e===`markdown`?`markdown`:`html`)}get value(){if(this.sourceMode&&this.source)return this.source.value;if(!this.editor)return``;let e=this.cleanEditorCopy();return this.format===`markdown`?i(e):e.innerHTML}set value(e){this.setValue(e||``)}setValue(e){if(!this.editor){this.pendingValue=e,this.getAttribute(`value`)!==e&&this.setAttribute(`value`,e);return}this.editor.innerHTML=this.format===`markdown`?n(e):e,this.clearInlineTypingState(),this.source&&(this.source.value=e),this.updateWordCount()}insertResource(e){let t=typeof e==`string`?{url:e}:e,n=t.url||t.src;if(!n||!this.editor)return;this.editor.focus(),this.restoreSelection();let r=this.editor.ownerDocument,i=r.createElement(`span`);i.className=`mint-editor-image-frame`,i.contentEditable=`false`,i.style.width=`min(100%, 420px)`;let a=r.createElement(`img`);a.src=n,a.alt=t.alt||t.label||``,a.draggable=!1,i.append(a,this.createResizeHandle());let o=this.selection;if(o?.rangeCount&&this.editor.contains(o.anchorNode)){let e=o.getRangeAt(0);e.deleteContents(),e.insertNode(i),e.setStartAfter(i),e.collapse(!0),o.removeAllRanges(),o.addRange(e)}else this.editor.append(i,r.createElement(`br`));this.selectImage(i),this.emitChange()}render(){let e=this.
|
|
16
|
+
`:i===`span`&&n.classList.contains(`mint-editor-image-frame`)?t(n.querySelector(`img`)||n):r};return Array.from(e.childNodes).map(t).join(``).trim()}var a=class extends HTMLElement{constructor(...e){super(...e),this.editor=null,this.editorFrame=null,this.pendingValue=null,this.preservedContent=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=new Map,this.inlineOverrides=new Map,this.inlineStyleOverrides=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=new Map,this.colorRecentSwatches=new Map,this.alignmentTrigger=null,this.onStageResizeStart=(e,t)=>{if(e.button!==0)return;e.preventDefault(),e.stopPropagation(),this.stageResizeState={stage:t,startY:e.clientY,startHeight:t.getBoundingClientRect().height,pointerId:e.pointerId};let n=this.ownerDocument.defaultView;n?.addEventListener(`pointermove`,this.onStageResizeMove),n?.addEventListener(`pointerup`,this.onStageResizeEnd),n?.addEventListener(`pointercancel`,this.onStageResizeEnd)},this.onStageResizeMove=e=>{let t=this.stageResizeState;if(!t||e.pointerId!==t.pointerId)return;e.preventDefault();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)));t.stage.style.height=`${r}px`,this.editorHeight=r},this.onStageResizeEnd=e=>{!this.stageResizeState||e.pointerId!==this.stageResizeState.pointerId||(this.stageResizeState=null,this.removeStageResizeListeners())},this.onTableResizeMove=e=>{let t=this.tableResizeState;if(!t||e.pointerId!==t.pointerId)return;let n=this.editor?.clientWidth||t.startWidth+300;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()},this.onTableResizeEnd=e=>{!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())},this.onGridResizeMove=e=>{let t=this.gridResizeState;if(!(!t||e.pointerId!==t.pointerId)){if(t.kind===`row`){let n=t.table.rows[t.index];n&&(n.style.height=`${Math.max(28,t.size+e.clientY-t.start)}px`)}else{this.ensureTableColumns(t.table);let n=t.table.querySelectorAll(`col`)[t.index];n&&(n.style.width=`${Math.max(48,t.size+e.clientX-t.start)}px`)}this.positionTableTools()}},this.onGridResizeEnd=e=>{if(!this.gridResizeState||e.pointerId!==this.gridResizeState.pointerId)return;this.gridResizeState=null;let t=this.editor?.ownerDocument.defaultView;t?.removeEventListener(`pointermove`,this.onGridResizeMove),t?.removeEventListener(`pointerup`,this.onGridResizeEnd),t?.removeEventListener(`pointercancel`,this.onGridResizeEnd),this.emitChange()},this.onResizeMove=e=>{if(!this.resizeState||e.pointerId!==this.resizeState.pointerId)return;let t=this.editor?.clientWidth||1e3,n=Math.max(80,Math.min(t,this.resizeState.startWidth+e.clientX-this.resizeState.startX));this.resizeState.frame.style.width=`${n}px`},this.onResizeEnd=e=>{!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())}}static get observedAttributes(){return[`label`,`placeholder`,`disabled`,`error`,`height`,`compact`,`format`,`value`,`resizable`]}connectedCallback(){this.editor||this.render(),this.observer=new MutationObserver(()=>this.updateWordCount()),this.editor&&this.observer.observe(this.editor,{childList:!0,subtree:!0,characterData:!0}),this.ownerDocument.defaultView?.addEventListener(`resize`,this.positionTableTools)}disconnectedCallback(){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);let e=this.editor?.ownerDocument.defaultView;e?.removeEventListener(`pointermove`,this.onGridResizeMove),e?.removeEventListener(`pointerup`,this.onGridResizeEnd),this.removeStageResizeListeners()}attributeChangedCallback(e,t,r){if(this.isConnected){if(e===`format`){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());return}if(e===`value`){this.setValue(r||``);return}e===`height`&&(this.editorHeight=null),this.render()}}get format(){return this.getAttribute(`format`)===`markdown`?`markdown`:`html`}set format(e){this.setAttribute(`format`,e===`markdown`?`markdown`:`html`)}get value(){if(this.sourceMode&&this.source)return this.source.value;if(!this.editor)return``;let e=this.cleanEditorCopy();return this.format===`markdown`?i(e):e.innerHTML}set value(e){this.setValue(e||``)}setValue(e){if(!this.editor){this.pendingValue=e,this.preservedContent=e,this.getAttribute(`value`)!==e&&this.setAttribute(`value`,e);return}this.editor.innerHTML=this.format===`markdown`?n(e):e,this.preservedContent=e,this.clearInlineTypingState(),this.source&&(this.source.value=e),this.updateWordCount()}insertResource(e){let t=typeof e==`string`?{url:e}:e,n=t.url||t.src;if(!n||!this.editor)return;this.editor.focus(),this.restoreSelection();let r=this.editor.ownerDocument,i=r.createElement(`span`);i.className=`mint-editor-image-frame`,i.contentEditable=`false`,i.style.width=`min(100%, 420px)`;let a=r.createElement(`img`);a.src=n,a.alt=t.alt||t.label||``,a.draggable=!1,i.append(a,this.createResizeHandle());let o=this.selection;if(o?.rangeCount&&this.editor.contains(o.anchorNode)){let e=o.getRangeAt(0);e.deleteContents(),e.insertNode(i),e.setStartAfter(i),e.collapse(!0),o.removeAllRanges(),o.addRange(e)}else this.editor.append(i,r.createElement(`br`));this.selectImage(i),this.emitChange()}render(){let e=this.getAttribute(`value`),r=this.editor?.innerHTML??this.pendingValue??e??this.preservedContent??this.innerHTML;this.editor?this.preservedContent=this.format===`markdown`&&this.source?this.source.value:this.editor.innerHTML:this.pendingValue===null?e===null?this.preservedContent===null&&(this.preservedContent=r):this.preservedContent=e:this.preservedContent=this.pendingValue;let i=this.editor?r:this.format===`markdown`?n(r):r;this.observer?.disconnect(),this.inlineButtons.clear(),this.colorTriggers.clear(),this.colorRecentSwatches.clear(),this.clearInlineTypingState(),this.editor=null,this.selectedImage=null;let a=this.hasAttribute(`disabled`)&&this.getAttribute(`disabled`)!==`false`,o=this.editorHeight===null?this.getAttribute(`height`)||`300px`:`${this.editorHeight}px`,s=this.getAttribute(`label`)||``;this.innerHTML=``;let c=document.createElement(`div`);if(c.className=`mint-editor-root`,this.hasAttribute(`error`)&&c.classList.add(`mint-editor-has-error`),this.hasAttribute(`compact`)&&c.classList.add(`mint-editor-compact`),s){let e=document.createElement(`label`);e.className=`mint-editor-label`,e.textContent=s,e.id=`${this.id||`mint-editor`}-label`,c.append(e)}let l=document.createElement(`div`);l.className=`mint-editor-shell`;let u=document.createElement(`div`);u.className=`mint-editor-toolbar`,u.setAttribute(`role`,`toolbar`),u.setAttribute(`aria-label`,`Text formatting`),this.toolbar=u,this.buildToolbar(u);let d=document.createElement(`div`);d.className=`mint-editor-inline-table-tools`,d.setAttribute(`role`,`toolbar`),d.setAttribute(`aria-label`,`Table tools`),d.hidden=!0;for(let[e,t]of[[`Add row above`,`arrow-up`],[`Add row below`,`arrow-down`],[`Delete row`,`remove`],[`Add column left`,`arrow-left`],[`Add column right`,`arrow-right`],[`Delete column`,`remove`],[`Delete table`,`trash`]]){let n=document.createElement(`button`);n.type=`button`,n.className=`mint-editor-table-tool-button`,this.setTooltip(n,e),n.append(this.icon(t)),n.addEventListener(`pointerdown`,e=>{e.preventDefault(),this.saveSelection()}),n.addEventListener(`click`,()=>this.applyTableAction(e)),d.append(n)}let f=document.createElement(`button`);f.type=`button`,f.className=`mint-editor-table-resize-handle`,this.setTooltip(f,`Resize table`),f.addEventListener(`pointerdown`,e=>this.startTableResize(e)),this.inlineTableTools=d,this.tableResizeHandle=f;let p=document.createElement(`iframe`);p.className=`mint-editor-frame`,p.title=s?`${s} editor`:`Rich text editor`,p.setAttribute(`sandbox`,`allow-same-origin`),p.style.height=`100%`,p.srcdoc=`<!doctype html><html><head><meta charset="utf-8"><style>
|
|
17
17
|
html,body{box-sizing:border-box;width:100%;height:100%;min-width:0;margin:0;overflow:hidden}
|
|
18
18
|
.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}
|
|
19
19
|
.editor:empty:before{content:attr(data-placeholder);color:var(--mint-color-text-muted,#7b8492);pointer-events:none}
|
|
@@ -26,4 +26,4 @@ const e=require(`../chunks/register-element-tCL_F1YI.js`);require(`../chunks/ico
|
|
|
26
26
|
.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}
|
|
27
27
|
.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}
|
|
28
28
|
@media(max-width:640px){.editor{padding:.75rem}}
|
|
29
|
-
</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;let p=document.createElement(`textarea`);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`,()=>{this.editor&&(this.editor.innerHTML=this.format===`markdown`?n(p.value):p.value),this.updateWordCount(),this.emitChange()}),this.source=p;let m=document.createElement(`div`);m.className=`mint-editor-stage`,m.style.height=a,m.append(f,p);let h=null;[`false`,`0`,`off`,`no`].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);let g=document.createElement(`div`);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}`));let _=g.querySelector(`[data-remove="image"]`);_&&this.setTooltip(_,`Remove image`),g.querySelector(`mint-input`)?.addEventListener(`input`,e=>{if(!this.selectedImage)return;let t=Number(e.target.value);this.selectedImage.style.width=`${Math.max(10,Math.min(100,t))}%`,this.emitChange()}),g.querySelectorAll(`[data-align]`).forEach(e=>e.addEventListener(`click`,()=>{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())})),g.querySelector(`[data-remove="image"]`)?.addEventListener(`click`,()=>{this.selectedImage?.remove(),this.selectImage(null),this.emitChange()}),s.append(c,g);let v=document.createElement(`div`);v.className=`mint-editor-footer`;let y=document.createElement(`span`);y.className=`mint-editor-mode`,y.textContent=`p`;let b=document.createElement(`span`);b.className=`mint-editor-word-count`,this.count=b;let x=document.createElement(`div`);x.className=`mint-editor-footer-end`,x.append(b),h&&x.append(h),v.append(y,x),this.footerMode=y,c.append(v);let S=this.getAttribute(`error`);if(S){let e=document.createElement(`div`);e.className=`mint-editor-error`,e.textContent=S,s.append(e)}this.append(s);let C=this.querySelector(`.mint-editor-stage`);if(C&&typeof ResizeObserver<`u`&&(this.frameResizeObserver?.disconnect(),this.frameResizeObserver=new ResizeObserver(([e])=>{if(!e||!this.editorFrame)return;let t=Math.max(0,e.contentRect.width),n=Math.max(0,e.contentRect.height);this.editorFrame.style.width=`${t}px`,this.editorFrame.style.height=`${n}px`}),this.frameResizeObserver.observe(C)),this.toolbar&&typeof ResizeObserver<`u`){this.toolbarResizeObserver?.disconnect(),this.toolbarResizeObserver=new ResizeObserver(()=>this.updateToolbarOverflow()),this.toolbarResizeObserver.observe(this.toolbar);let e=this.toolbar.querySelector(`.mint-editor-toolbar-actions`);e&&this.toolbarResizeObserver.observe(e),requestAnimationFrame(()=>this.updateToolbarOverflow())}this.sourceMode=!1,this.observer&&this.editor&&this.observer.observe(this.editor,{childList:!0,subtree:!0,characterData:!0}),this.updateWordCount(),this.updateFormatUI()}removeStageResizeListeners(){let e=this.ownerDocument.defaultView;e?.removeEventListener(`pointermove`,this.onStageResizeMove),e?.removeEventListener(`pointerup`,this.onStageResizeEnd),e?.removeEventListener(`pointercancel`,this.onStageResizeEnd),this.stageResizeState=null}bindEditorFrame(e,t){let r=this.editorFrame?.contentDocument,i=r?.querySelector(`.editor`);if(!r||!i)return;i.contentEditable=String(!t),i.innerHTML=this.pendingValue===null?e:this.format===`markdown`?n(this.pendingValue):this.pendingValue,this.pendingValue=null;let a=getComputedStyle(this),o=r.body;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,[`text`,`text-muted`,`surface`,`surface-subtle`,`border`,`primary`,`focus`].forEach(e=>{let t=a.getPropertyValue(`--mint-color-${e}`).trim();t&&i.style.setProperty(`--mint-color-${e}`,t)}),this.editor=i,i.addEventListener(`input`,()=>{this.normalizeTaskListItems(),this.syncSource(),this.emitChange(),this.updateSelectionUI()}),i.addEventListener(`change`,e=>{let t=e.target;t.matches(`ul[data-mint-task-list] input[type="checkbox"]`)&&(t.toggleAttribute(`checked`,t.checked),this.emitChange())}),i.addEventListener(`paste`,e=>{let t=e.clipboardData?.getData(`text/html`)||``;if(!t||!this.editor?.contains(this.selection?.anchorNode||null))return;let n=this.sanitizePastedHtml(t);n&&(e.preventDefault(),this.clearInlineTypingState(),this.insertPastedHtml(n),this.normalizeTaskListItems(),this.emitChange(),this.updateSelectionUI())}),i.addEventListener(`beforeinput`,e=>{let t=e;t.inputType.startsWith(`insert`)&&(this.preserveInlineOverridesOnNextEditorClick=!1);let n=t.shiftKey;if((t.inputType===`insertParagraph`||t.inputType===`insertLineBreak`&&!n)&&!t.isComposing){let e=this.selection?.anchorNode,n=(e?.nodeType===Node.ELEMENT_NODE?e:e?.parentElement)?.closest(`li`),r=n?.parentElement;if(n&&r?.tagName===`UL`&&r.hasAttribute(`data-mint-task-list`)&&this.editor?.contains(n)){t.preventDefault(),this.isEmptyTaskItem(n)?this.exitTaskList(n,r):this.splitTaskItem(n,r);return}}this.applyInlineTypingState(t)}),i.addEventListener(`keyup`,e=>{[`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`,`PageUp`,`PageDown`].includes(e.key)&&this.clearInlineTypingState(),this.updateSelectedImage(),this.updateSelectionUI()}),i.addEventListener(`mouseup`,()=>{this.updateSelectedImage(),this.updateSelectionUI()}),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=>{this.closeEditorPopovers(),this.preserveInlineOverridesOnNextEditorClick?this.preserveInlineOverridesOnNextEditorClick=!1:this.clearInlineTypingState();let t=e.target,n=t.closest(`.mint-editor-image-frame`);n?this.selectImage(n):t.closest(`.mint-editor-image-tools`)||this.selectImage(null);let r=t.closest(`table`);this.selectTable(r),t.closest(`a`)&&e.preventDefault()}),i.addEventListener(`keydown`,e=>{if(e.key===`Enter`&&!e.shiftKey&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.isComposing){let t=this.selection,n=t?.anchorNode,r=(n?.nodeType===Node.ELEMENT_NODE?n:n?.parentElement)?.closest(`li`),i=r?.parentElement;if(t?.isCollapsed&&r&&i?.tagName===`UL`&&i.hasAttribute(`data-mint-task-list`)&&this.editor?.contains(r)){e.preventDefault(),this.isEmptyTaskItem(r)?this.exitTaskList(r,i):this.splitTaskItem(r,i);return}}(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`))}),this.observer&&this.observer.observe(i,{childList:!0,subtree:!0,characterData:!0}),this.updateWordCount(),this.updateSelectionUI()}buildToolbar(e){let t=(t,n,r,i=e)=>{let a=document.createElement(`button`);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=>{e.preventDefault(),r()}),i.append(a),a},n=(e,t,n)=>{let r=document.createElement(`mint-popover`);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},r=(e,t,n,r)=>{let i=this.createMenuOption(t,n);return i.addEventListener(`click`,r),e.append(i),i};t(`Undo`,`undo`,()=>this.command(`undo`)),t(`Redo`,`redo`,()=>this.command(`redo`));let i=document.createElement(`button`);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`;let a=document.createElement(`span`);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);let o=n(i,`mint-editor-block-popover`,e);[[`p`,`Paragraph`,`paragraph`],[`h1`,`Heading 1`,`heading`],[`h2`,`Heading 2`,`heading`],[`h3`,`Heading 3`,`heading`],[`blockquote`,`Quote`,`quote`],[`div`,`Div`,`code`]].forEach(([e,t,n])=>{let r=this.createMenuOption(t,n);r.dataset.blockTag=e,r.addEventListener(`click`,()=>{this.command(`formatBlock`,e),o.close(),this.updateSelectionUI()}),o.append(r)}),this.blockPopover=o;let s=document.createElement(`div`);s.className=`mint-editor-font-size-control`,t(`Decrease font size`,`minus`,()=>this.applyFontSize(this.readFontSize()-1),s);let c=document.createElement(`button`);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`);let l=document.createElement(`span`);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;let u=document.createElement(`div`);u.className=`mint-editor-toolbar-actions`,e.append(u),u.append(s);let d=n(c,`mint-editor-font-size-popover`,u),f=[[s,d]];[8,9,10,11,12,14,16,18,20,24,28,32,36,48,72].forEach(e=>{let t=document.createElement(`button`);t.type=`button`,t.className=`mint-editor-menu-option mint-editor-font-size-option`,t.textContent=`${e}px`,t.addEventListener(`click`,()=>{this.applyFontSize(e),d.close()}),d.append(t)});let p=(e,n,r)=>{let i=t(e,n,r,u);return[`bold`,`italic`,`underline`].includes(n)&&(i.setAttribute(`aria-pressed`,`false`),this.inlineButtons.set(n,i)),i},m=e=>{let t=e.querySelector(`:scope > mint-icon`);if(!t)return;let n=document.createElement(`span`);n.className=`mint-editor-color-icon`,e.insertBefore(n,t),n.append(t)},h=()=>{let e=this.separator();return u.append(e),f.push([e]),e},g=p(`Bold`,`bold`,()=>this.toggleInline(`bold`)),_=p(`Italic`,`italic`,()=>this.toggleInline(`italic`)),v=p(`Underline`,`underline`,()=>this.toggleInline(`underline`));f.push([g],[_],[v]);let y=this.separator();u.append(y);let b=p(`Text color`,`text-color`,()=>{});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);let x=n(b,`mint-editor-color-popover`,u);this.buildColorPopover(x,`text`,b),this.colorTriggers.set(`text`,b);let S=p(`Highlight color`,`highlight`,()=>{});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);let C=n(S,`mint-editor-color-popover`,u);this.buildColorPopover(C,`background`,S),this.colorTriggers.set(`background`,S),f.push([y,b,x,S,C]);let w=p(`Font family`,`font-family`,()=>{});w.id=`${this.id||`mint-editor-${Math.random().toString(36).slice(2)}`}-font-family-trigger`,w.append(this.icon(`caret-down`));let T=n(w,`mint-editor-font-family-popover`,u);[[`Arial`,`Arial, sans-serif`],[`Helvetica`,`Helvetica, sans-serif`],[`Georgia`,`Georgia, serif`],[`Times New Roman`,`"Times New Roman", serif`],[`Courier New`,`"Courier New", monospace`],[`System UI`,`system-ui, sans-serif`]].forEach(([e,t])=>{r(T,e,`font-family`,()=>{this.applyFontFamily(t),T.close()})}),f.push([w,T]),h();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`);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);let A=n(k,``,u);this.tablePopover=A,[[`Add row below`,`table-row`],[`Add column right`,`table-column`],[`Delete row`,`table-row-delete`],[`Delete column`,`table-column-delete`],[`Delete table`,`trash`]].forEach(([e,t])=>{let n=this.createMenuOption(e,t);n.addEventListener(`click`,()=>{this.applyTableAction(e),A.close()}),A.append(n)}),k.addEventListener(`pointerdown`,()=>this.saveSelection()),this.tableTrigger=k,f.push([E],[D],[O,k,A]);let j=p(`Add comment`,`comment-plus`,()=>this.openCommentModal());f.push([j]),h();let M=p(`Text alignment`,`align-left`,()=>{});M.id=`${this.id||`mint-editor-${Math.random().toString(36).slice(2)}`}-alignment-trigger`,M.append(this.icon(`caret-down`)),this.alignmentTrigger=M;let N=n(M,`mint-editor-alignment-popover`,u);[[`Align left`,`align-left`,`justifyLeft`],[`Align center`,`align-center`,`justifyCenter`],[`Align right`,`align-right`,`justifyRight`],[`Justify`,`align-justify`,`justifyFull`]].forEach(([e,t,n])=>{r(N,e,t,()=>{this.command(n),N.close(),this.updateTooltipLabel(M,`Text alignment: ${e}`)})}),f.push([M,N]),h();let P=p(`Bulleted list`,`list`,()=>this.command(`insertUnorderedList`)),F=document.createElement(`button`);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);let I=n(F,`mint-editor-list-popover`,u);[[`Disc`,`disc`],[`Circle`,`circle`],[`Square`,`square`]].forEach(([e,t])=>r(I,e,`list`,()=>{this.applyListStyle(`ul`,t),I.close()}));let L=p(`Numbered list`,`numbered-list`,()=>this.command(`insertOrderedList`)),R=document.createElement(`button`);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);let z=n(R,`mint-editor-list-popover`,u);[[`Numbers`,`decimal`],[`Lowercase letters`,`lower-alpha`],[`Uppercase letters`,`upper-alpha`],[`Lowercase Roman numerals`,`lower-roman`],[`Uppercase Roman numerals`,`upper-roman`]].forEach(([e,t])=>r(z,e,`numbered-list`,()=>{this.applyListStyle(`ol`,t),z.close()}));let B=p(`Checklist`,`checklist`,()=>this.toggleChecklist());f.push([P,F,I],[L,R,z],[B]),h();let V=p(`HTML source`,`code`,()=>this.toggleSource());f.push([V]),this.sourceButton=e.querySelector(`.mint-editor-toolbar-code`);let H=p(`Clear formatting`,`clear-formatting`,()=>this.clearFormatting());f.push([H]);let U=document.createElement(`button`);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`));let W=document.createElement(`mint-popover`);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}buildColorPopover(e,t,n){let r=[`#bcebd1`,`#fff0b3`,`#f7c9c9`,`#e9c8f5`,`#c4e1f2`,`#20bd70`,`#f1c40f`,`#e33b2e`,`#b65bd0`,`#3298d4`,`#168f77`,`#e77d1e`,`#b9372b`,`#823a9d`,`#2874a6`,`#edf0f2`,`#cfd5d8`,`#9eadae`,`#7e8d8f`,`#35495e`],i=document.createElement(`div`);i.className=`mint-editor-color-grid`,i.setAttribute(`role`,`group`),i.setAttribute(`aria-label`,t===`text`?`Text colors`:`Highlight colors`);let a=()=>t===`text`?this.lastTextColor:this.lastBackgroundColor,o=(r,o=!0)=>{this.applyEditorColor(t,r);let s=this.colorRecentSwatches.get(t);s&&(s.style.backgroundColor=a(),s.dataset.color=a());let c=e.querySelector(`input[type="color"]`);c&&document.activeElement!==c&&(c.value=a()),n.style.setProperty(`--editor-color`,a()),i.querySelectorAll(`.mint-editor-color-swatch`).forEach(e=>{let t=!!e.dataset.color&&e.dataset.color.toLowerCase()===a().toLowerCase();e.toggleAttribute(`data-selected`,t),e.setAttribute(`aria-pressed`,String(t))}),o&&e.close()},s=(e,t,n=``)=>{let r=document.createElement(`button`);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=>{e.preventDefault(),this.saveSelection()}),r.addEventListener(`click`,e=>{e.preventDefault(),o(t)}),i.append(r),r};r.forEach((e,t)=>s(`Color ${t+1}: ${e}`,e)),s(`Black`,`#000000`,`is-utility-swatch`),s(`White`,`#ffffff`,`is-utility-swatch`);let c=s(`Last used color`,a(),`is-utility-swatch is-recent-swatch`);this.colorRecentSwatches.set(t,c);let l=document.createElement(`button`);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=>{e.preventDefault(),this.saveSelection()}),l.addEventListener(`click`,e=>{e.preventDefault(),o(null)}),i.append(l);let u=document.createElement(`input`);u.type=`color`,u.className=`mint-editor-native-color-picker`,u.value=a(),u.setAttribute(`aria-label`,`Choose a custom color`);let d=document.createElement(`button`);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=>{e.preventDefault(),this.saveSelection()}),d.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),u.click()}),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));let f=document.createElement(`div`);f.className=`mint-editor-custom-color-cell`,f.append(d,u),i.append(f),e.append(i)}applyEditorColor(e,t){if(!this.editor||this.sourceMode)return;this.editor.focus(),this.restoreSelection();let n=this.editor.ownerDocument,r=this.selection,i=e===`text`?t||getComputedStyle(this.editor).color||`#202833`:t||getComputedStyle(this.editor).backgroundColor||`transparent`;if(r?.isCollapsed){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();return}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()}readFontSize(){let e=this.selection,t=e?.isCollapsed?Number.parseFloat(this.inlineStyleOverrides.get(`fontSize`)||``):NaN;if(Number.isFinite(t)&&t>0)return Math.round(t);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;return Number.isFinite(a)&&a>0?Math.round(a):16}applyFontSize(e){if(!this.editor||this.sourceMode)return;let t=Math.max(8,Math.min(96,Math.round(e)));this.editor.focus(),this.restoreSelection();let n=this.editor.ownerDocument;if(this.selection?.isCollapsed){this.inlineStyleOverrides.set(`fontSize`,`${t}px`),this.preserveInlineOverridesOnNextEditorClick=!0,this.emitChange(),this.updateSelectionUI();return}this.inlineStyleOverrides.delete(`fontSize`);let r=new Set(Array.from(this.editor.querySelectorAll(`font[size="7"]`)));n.execCommand(`fontSize`,!1,`7`),this.editor.querySelectorAll(`font[size="7"]`).forEach(e=>{if(r.has(e))return;let i=n.createElement(`span`);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)}),this.emitChange(),this.updateSelectionUI()}applyFontFamily(e){if(!this.editor||this.sourceMode)return;if(this.editor.focus(),this.restoreSelection(),this.selection?.isCollapsed){this.inlineStyleOverrides.set(`fontFamily`,e),this.preserveInlineOverridesOnNextEditorClick=!0,this.emitChange(),this.updateSelectionUI();return}this.inlineStyleOverrides.delete(`fontFamily`);let t=this.editor.ownerDocument,n=new Set(Array.from(this.editor.querySelectorAll(`font[face]`)));t.execCommand(`fontName`,!1,e),this.editor.querySelectorAll(`font[face]`).forEach(r=>{if(n.has(r))return;let i=t.createElement(`span`);i.style.fontFamily=r.getAttribute(`face`)||e,i.append(...Array.from(r.childNodes)),r.replaceWith(i)}),this.emitChange(),this.updateSelectionUI()}applyListStyle(e,t){if(!this.editor||this.sourceMode)return;this.editor.focus(),this.restoreSelection();let n=this.selection?.anchorNode,r=(n?.nodeType===Node.ELEMENT_NODE?n:n?.parentElement)?.closest(e),i=r&&this.editor.contains(r)?r:null;if(!i){this.editor.ownerDocument.execCommand(e===`ul`?`insertUnorderedList`:`insertOrderedList`,!1);let t=this.selection?.anchorNode,n=(t?.nodeType===Node.ELEMENT_NODE?t:t?.parentElement)?.closest(e);i=n&&this.editor.contains(n)?n:null}i&&(i.style.listStyleType=t),this.emitChange(),this.updateSelectionUI()}toggleChecklist(){if(!this.editor||this.sourceMode)return;this.editor.focus(),this.restoreSelection();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`);if(r)r.removeAttribute(`data-mint-task-list`),r.querySelectorAll(`input[type="checkbox"]`).forEach(e=>e.remove());else{i||(n?.closest(`h1,h2,h3,h4,h5,h6`)&&e.execCommand(`formatBlock`,!1,`p`),e.execCommand(`insertUnorderedList`,!1));let t=this.selection?.anchorNode,r=t?.nodeType===Node.ELEMENT_NODE?t:t?.parentElement,a=i||r?.closest(`ul`);if(a&&this.editor.contains(a)){a.setAttribute(`data-mint-task-list`,`true`),a.querySelectorAll(`li`).forEach((t,n)=>{if(t.querySelector(`input[type="checkbox"]`))return;let r=e.createElement(`input`);r.type=`checkbox`,r.setAttribute(`contenteditable`,`false`),r.setAttribute(`aria-label`,`Task ${n+1} complete`),t.insertBefore(r,t.firstChild)});let t=a.parentElement;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))}}this.emitChange(),this.updateSelectionUI()}splitTaskItem(e,t){if(!this.editor)return;let n=this.editor.ownerDocument,r=this.selection,i=r?.anchorNode,a=Array.from(e.children).find(e=>e.matches(`input[type="checkbox"]`));if(a)e.firstChild!==a&&(a.remove(),e.insertBefore(a,e.firstChild));else{let r=n.createElement(`input`);r.type=`checkbox`,r.setAttribute(`contenteditable`,`false`),r.setAttribute(`aria-label`,`Task ${t.children.length} complete`),e.insertBefore(r,e.firstChild)}let o=n.createRange();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);let s=o.extractContents(),c=n.createElement(`li`),l=n.createElement(`input`);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);let u=n.createRange();u.setStart(c,1),u.collapse(!0),r?.removeAllRanges(),r?.addRange(u),this.syncSource(),this.emitChange(),this.updateSelectionUI()}normalizeTaskListItems(){if(!this.editor)return;let e=this.selection,t=e?.anchorNode,n=t?.nodeType===Node.ELEMENT_NODE?t.closest(`li`):t?.parentElement?.closest(`li`);for(let r of this.editor.querySelectorAll(`ul[data-mint-task-list]`))Array.from(r.children).forEach((r,i)=>{if(r.tagName!==`LI`)return;let a=r,o=Array.from(a.children).find(e=>e.matches(`input[type="checkbox"]`));if(!o){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){let t=this.editor.ownerDocument.createRange();t.setStart(a,1),t.collapse(!0),e.removeAllRanges(),e.addRange(t)}}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)){let t=this.editor.ownerDocument.createRange();t.setStart(a,1),t.collapse(!0),e.removeAllRanges(),e.addRange(t)}})}isEmptyTaskItem(e){let t=e=>{if(e.nodeType===Node.TEXT_NODE)return!!e.textContent?.trim();if(e.nodeType!==Node.ELEMENT_NODE)return!1;let n=e;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)};return!Array.from(e.childNodes).some(t)}exitTaskList(e,t){if(!this.editor||!t.parentNode)return;let n=t.parentNode,r=t.cloneNode(!1);for(;e.nextElementSibling;)r.append(e.nextElementSibling);e.remove();let i=this.editor.ownerDocument.createElement(`p`);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();let a=this.selection,o=this.editor.ownerDocument.createRange();o.setStart(i,0),o.collapse(!0),a?.removeAllRanges(),a?.addRange(o),this.syncSource(),this.emitChange(),this.updateSelectionUI()}openCommentModal(){this.saveSelection();let e=this._savedRange?.toString()||``,t=document.createElement(`mint-modal`);t.setAttribute(`heading`,`Add comment`),t.setAttribute(`size`,`small`);let n=document.createElement(`div`);n.setAttribute(`slot`,`body`),n.className=`mint-editor-modal-fields`;let r=document.createElement(`p`);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.`;let i=document.createElement(`textarea`);i.className=`mint-editor-comment-input`,i.setAttribute(`aria-label`,`Comment`),i.setAttribute(`placeholder`,`Write a comment…`),i.rows=4,n.append(r,i);let a=document.createElement(`div`);a.setAttribute(`slot`,`actions`),a.className=`mint-editor-modal-actions`;let o=document.createElement(`mint-button`);o.textContent=`Cancel`,o.setAttribute(`variant`,`ghost`),this.setTooltip(o,`Cancel`),o.addEventListener(`click`,()=>t.close());let s=document.createElement(`mint-button`);s.textContent=`Add comment`,s.setAttribute(`tone`,`action`),s.toggleAttribute(`disabled`,!e),this.setTooltip(s,`Add comment`),s.addEventListener(`click`,()=>{let n=i.value.trim();!n||!e||(this.insertComment(n,e),t.close())}),a.append(o,s),t.append(n,a),this.append(t),t.open()}insertComment(e,t){let n=this._savedRange;if(this.editor&&n&&!n.collapsed&&this.editor.contains(n.commonAncestorContainer)&&this.format===`html`){let t=this.editor.ownerDocument.createElement(`span`);t.className=`mint-editor-comment`,t.setAttribute(`data-mint-comment`,e),t.title=`Comment: ${e}`,t.append(n.extractContents()),n.insertNode(t);let r=this.selection;n.selectNodeContents(t),r?.removeAllRanges(),r?.addRange(n)}this.dispatchEvent(new CustomEvent(`mint-editor-comment-request`,{bubbles:!0,composed:!0,detail:{selectedText:t,comment:e,format:this.format}})),this.emitChange()}updateToolbarOverflow(){let e=this.toolbar,t=this.overflowTrigger,n=this.overflowPopover;if(!e||!t||!n)return;let r=e.querySelector(`.mint-editor-toolbar-actions`),i=this.blockButton;if(!r||!i)return;for(let e of this.overflowGroups)for(let t of e)r.append(t);t.hidden=!1;let a=this.overflowGroups.length-1,o=()=>{let e=[...r.children].filter(e=>e instanceof HTMLElement&&!e.matches(`mint-popover`)&&!e.hidden),t=Number.parseFloat(getComputedStyle(r).columnGap)||0;return e.reduce((e,t)=>e+t.getBoundingClientRect().width,0)+Math.max(0,e.length-1)*t};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--;t.hidden=n.childElementCount===0}clearFormatting(){!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())}icon(e){let t=document.createElement(`mint-icon`);return t.setAttribute(`name`,e),t.setAttribute(`aria-hidden`,`true`),t}setTooltip(e,t){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()))}updateTooltipLabel(e,t){e.setAttribute(`data-editor-tooltip`,t);let n=t.indexOf(`:`),r=n<0?t:`${t.slice(0,n+1)}\n${t.slice(n+1).trim()}`;e.setAttribute(`data-editor-overflow-label`,r),e.setAttribute(`aria-label`,t),e.removeAttribute(`title`)}showTooltip(e){if(e.closest(`.mint-editor-overflow-popover`)){this.hideTooltip();return}let t=e.getAttribute(`data-editor-tooltip`);if(!t||e.matches(`:disabled,[hidden]`))return;let n=this.tooltipPopup;if(!n){n=document.createElement(`div`),n.className=`mint-editor-tooltip-popup`,n.setAttribute(`role`,`tooltip`),n.setAttribute(`aria-hidden`,`true`);let e=getComputedStyle(this);[`text`,`surface`,`border`].forEach(t=>{let r=e.getPropertyValue(`--mint-color-${t}`).trim();r&&n.style.setProperty(`--mint-color-${t}`,r)}),document.body.append(n),this.tooltipPopup=n}n.textContent=t,n.setAttribute(`aria-hidden`,`false`),n.style.visibility=`hidden`,n.style.display=`block`;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);n.style.left=`${a}px`,n.style.top=`${o}px`,n.style.visibility=`visible`}hideTooltip(){this.tooltipPopup&&(this.tooltipPopup.style.display=`none`,this.tooltipPopup.setAttribute(`aria-hidden`,`true`))}closeEditorPopovers(){this.querySelectorAll(`mint-popover`).forEach(e=>{e.close?.call(e)})}createMenuOption(e,t){let n={"table-row":`table`,"table-column":`columns`,"table-row-delete":`remove`,"table-column-delete":`remove`,paragraph:`file-alt`,heading:`heading`},r=document.createElement(`button`);r.type=`button`,r.className=`mint-editor-menu-option`;let i=this.icon(n[t]||t);i.classList.add(`mint-editor-menu-icon`);let a=document.createElement(`span`);return a.className=`mint-editor-menu-label`,a.textContent=e,r.append(i,a),r}updateFormatUI(){if(this.source&&this.source.setAttribute(`aria-label`,`Editor ${this.format.toUpperCase()} source`),this.sourceButton){let e=`${this.format.toUpperCase()} source`,t=this.sourceButton.querySelector(`.mint-editor-button-label`);t&&(t.textContent=e),this.updateTooltipLabel(this.sourceButton,e)}}separator(){let e=document.createElement(`span`);return e.className=`mint-editor-separator`,e.setAttribute(`aria-hidden`,`true`),e}command(e,t){!this.editor||this.sourceMode||(this.editor.focus(),this.restoreSelection(),this.editor.ownerDocument.execCommand(e,!1,t),this.clearInlineTypingState(),this.emitChange(),this.updateSelectionUI())}toggleInline(e){if(!this.editor||this.sourceMode)return;this.editor.focus(),this.restoreSelection();let t=this.selection;if(!t?.rangeCount||!this.editor.contains(t.anchorNode))return;let n=t.getRangeAt(0),r=!this.inlineStateAtSelection(e,n),i=this.editor.ownerDocument;if(n.collapsed){this.inlineOverrides.set(e,r),this.preserveInlineOverridesOnNextEditorClick=!0,this.emitChange(),this.updateSelectionUI();return}this.clearInlineTypingState(),i.execCommand(e,!1),this.emitChange(),this.updateSelectionUI()}inlineStateAtSelection(e,t){let n=this.selection,r=this.inlineOverrides.get(e);if(t.collapsed&&r!==void 0)return r;let i=this.formatAtCaret(e,t);if(i||!t.collapsed)return i;let a=t.cloneRange(),o=t.startContainer,s=t.startOffset;if(o.nodeType!==Node.TEXT_NODE||s===0){let e=o.nodeType===Node.ELEMENT_NODE?o.childNodes[s-1]:null;if(e){for(o=e;o.lastChild;)o=o.lastChild;o.nodeType===Node.TEXT_NODE&&(s=o.textContent?.length||0)}}if(o.nodeType===Node.TEXT_NODE&&s>0)try{a.setStart(o,s-1),a.setEnd(o,s),n?.removeAllRanges(),n?.addRange(a),i=this.formatAtCaret(e,a)}catch{}finally{n?.removeAllRanges(),n?.addRange(t)}return i}applyInlineTypingState(e){if(e.inputType.startsWith(`insert`)&&(this.preserveInlineOverridesOnNextEditorClick=!1),e.inputType.startsWith(`delete`)){this.clearInlineTypingState();return}if(!this.editor||this.sourceMode||e.inputType!==`insertText`||!e.data||this.inlineOverrides.size===0&&this.inlineStyleOverrides.size===0)return;let t=this.selection;if(!t?.rangeCount||!t.isCollapsed||!this.editor.contains(t.anchorNode))return;let n=t.getRangeAt(0),r=this.editor.ownerDocument;e.preventDefault();let i=r.createTextNode(e.data),a=[`bold`,`italic`,`underline`].map(e=>{let t=this.formatAtCaret(e,n);return[e,this.inlineOverrides.has(e)?this.inlineOverrides.get(e):t,t]}),o=a.some(([e,t,n])=>e===`underline`&&!t&&n)?(n.startContainer.nodeType===Node.ELEMENT_NODE?n.startContainer:n.startContainer.parentElement)?.closest(`u`):null;for(let[e,t,n]of a.reverse()){if(t===n)continue;let a=t?e===`bold`?`strong`:e===`italic`?`em`:`u`:`span`,o=r.createElement(a);t||(e===`bold`?o.style.fontWeight=`normal`:e===`italic`?o.style.fontStyle=`normal`:o.style.textDecoration=`none`),o.append(i),i=o}if(this.inlineStyleOverrides.size){let e=r.createElement(`span`);this.inlineStyleOverrides.forEach((t,n)=>{e.style[n]=t}),e.append(i),i=e}if(n.deleteContents(),n.insertNode(i),o&&o.parentNode&&this.isAtEndOfInlineRun(i,o)){o.parentNode.insertBefore(i,o.nextSibling);for(let e=i.parentNode;e&&e!==o;){let t=e.parentNode;e instanceof HTMLElement&&!e.textContent?.length&&!e.querySelector(`img,br,table,hr,iframe,video,audio`)&&e.remove(),e=t}!o.textContent?.length&&!o.querySelector(`img,br,table,hr,iframe,video,audio`)&&o.remove()}let s=i;for(;s.lastChild;)s=s.lastChild;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`,{bubbles:!0,inputType:`insertText`,data:e.data}))}isAtEndOfInlineRun(e,t){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;return!0}formatAtCaret(e,t){let n=t.startContainer,r=n.nodeType===Node.ELEMENT_NODE?n:n.parentElement;if(t.collapsed&&n.nodeType===Node.ELEMENT_NODE&&t.startOffset>0){let e=n.childNodes[t.startOffset-1];for(;e?.lastChild;)e=e.lastChild;e?.nodeType===Node.TEXT_NODE?r=e.parentElement:e?.nodeType===Node.ELEMENT_NODE&&(r=e)}if(!r)return!1;let i=[];for(let e=r;e&&e!==this.editor;e=e.parentElement)i.push(e);for(let t of i){let n=t.style;if(e===`bold`){if(n.fontWeight){let e=Number.parseInt(n.fontWeight,10);return Number.isFinite(e)?e>=600:n.fontWeight===`bold`||n.fontWeight===`bolder`}if([`B`,`STRONG`].includes(t.tagName))return!0}else if(e===`italic`){if(n.fontStyle)return[`italic`,`oblique`].includes(n.fontStyle);if([`I`,`EM`].includes(t.tagName))return!0}else{if(n.textDecorationLine||n.textDecoration)return(n.textDecorationLine||n.textDecoration).includes(`underline`);if(t.tagName===`U`)return!0}}let a=getComputedStyle(r);if(e===`bold`){let e=Number.parseInt(a.fontWeight,10);return Number.isFinite(e)&&e>=600}return e===`italic`?[`italic`,`oblique`].includes(a.fontStyle):a.textDecorationLine.includes(`underline`)}requestResource(){this.saveSelection(),this.dispatchEvent(new CustomEvent(`mint-editor-resource-request`,{bubbles:!0,composed:!0,detail:{resourceType:`media`}}))}get selection(){return this.editor?.ownerDocument.getSelection()||null}saveSelection(){let e=this.selection;e?.rangeCount&&this.editor?.contains(e.anchorNode)&&(this._savedRange=e.getRangeAt(0).cloneRange())}restoreSelection(){let e=this._savedRange;if(!e)return;let t=this.selection;t?.removeAllRanges(),t?.addRange(e),this._savedRange=void 0}clearInlineTypingState(){this.inlineOverrides.clear(),this.inlineStyleOverrides.clear(),this.preserveInlineOverridesOnNextEditorClick=!1}cleanEditorCopy(){let e=this.editor?.cloneNode(!0);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`)}insertPastedHtml(e){let t=this.editor,n=this.selection;if(!t||!n?.rangeCount)return;let r=t.ownerDocument,i=n.getRangeAt(0);if(!t.contains(i.startContainer)||!t.contains(i.endContainer))return;let a=r.createElement(`div`);a.innerHTML=e;let o=r.createDocumentFragment();for(;a.firstChild;)o.append(a.firstChild);if(!o.hasChildNodes())return;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;if(c||l){t.replaceChildren(o),this.placeCaretAfterPastedContent(t.lastChild,n);return}i.deleteContents(),i.collapse(!0);let u=i.startContainer;if(u.nodeType!==Node.ELEMENT_NODE&&(u=u.parentNode||t),s){let e=(u.nodeType===Node.ELEMENT_NODE?u:u.parentElement)?.closest(`p,h1,h2,h3,h4,h5,h6,pre`);if(e&&t.contains(e)&&e.parentNode){let t=r.createRange();t.selectNodeContents(e),t.setStart(i.startContainer,i.startOffset);let a=t.extractContents(),s=e.parentNode,c=e.nextSibling,l=e.cloneNode(!1);l.append(a);let u=this.hasPastedBlockContent(e),d=this.hasPastedBlockContent(l);u||s.removeChild(e);let f=o.lastChild;s.insertBefore(o,c),d?s.insertBefore(l,c):l.remove(),this.placeCaretAfterPastedContent(f,n);return}}let d=o.lastChild;i.insertNode(o),this.placeCaretAfterPastedContent(d,n)}hasPastedBlockContent(e){return(e.textContent||``).replace(/\u00a0/g,` `).trim()?!0:!!e.querySelector(`img,table,hr,ul,ol,iframe,video,audio`)}placeCaretAfterPastedContent(e,t){if(!e?.parentNode)return;let n=this.editor?.ownerDocument.createRange();n&&(n.selectNodeContents(e),n.collapse(!1),t.removeAllRanges(),t.addRange(n),this.saveSelection())}sanitizePastedHtml(e){let t=this.editor?.ownerDocument,n=t?.defaultView?.DOMParser;if(!t||!n)return``;let r=new n().parseFromString(e,`text/html`),i=r.body,a=`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=>{let t=r.createElement(`span`);t.setAttribute(`style`,e);let n=new Map;for(let e of a){let r=t.style.getPropertyValue(e).trim();!r||/url\s*\(|expression\s*\(/i.test(r)||e.startsWith(`margin-`)&&Number.parseFloat(r)===0||n.set(e,r)}let i=e.match(/(?:^|;)\s*mso-(?:ansi|bidi)-font-size\s*:\s*([^;]+)/i)?.[1]?.trim();if(!n.has(`font-size`)&&i){t.style.setProperty(`font-size`,i);let e=t.style.getPropertyValue(`font-size`).trim();e&&!/url\s*\(|expression\s*\(/i.test(e)&&n.set(`font-size`,e)}let o=e.match(/(?:^|;)\s*mso-(?:ansi|bidi)-font-family\s*:\s*([^;]+)/i)?.[1]?.trim();if(!n.has(`font-family`)&&o){t.style.setProperty(`font-family`,o);let e=t.style.getPropertyValue(`font-family`).trim();e&&!/url\s*\(|expression\s*\(/i.test(e)&&n.set(`font-family`,e)}let s=e.match(/(?:^|;)\s*mso-highlight\s*:\s*([^;]+)/i)?.[1]?.trim();if(!n.has(`background-color`)&&s){t.style.backgroundColor=s;let e=t.style.backgroundColor.trim();e&&n.set(`background-color`,e)}return!n.has(`background-color`)&&t.style.backgroundColor&&n.set(`background-color`,t.style.backgroundColor),Array.from(n,([e,t])=>`${e}:${t}`).join(`;`)},s=(e,t)=>{let n=o([t,e.getAttribute(`style`)||``].filter(Boolean).join(`;`));n&&e.setAttribute(`style`,n)};for(let e of Array.from(r.querySelectorAll(`style`))){let t=e.textContent||``;for(let e of t.matchAll(/([^{}]+)\{([^{}]*)\}/g)){let t=e[2].trim();if(!(!t||!/\.(?:Mso|WordSection)/i.test(e[1])))for(let n of e[1].split(`,`)){let e=n.trim();if(/^(?:[a-z][\w-]*)?(?:\.[\w-]+)+$/i.test(e))try{r.querySelectorAll(e).forEach(e=>s(e,t))}catch{}}}}r.querySelectorAll(`style,script,iframe,object,embed,form,input,button,select,textarea,link,meta,base,svg,math,canvas,video,audio`).forEach(e=>e.remove());for(let e of Array.from(i.querySelectorAll(`font`))){let t=r.createElement(`span`),n=[],i=e.getAttribute(`face`),a=e.getAttribute(`color`),s=e.getAttribute(`size`),c={1:`8pt`,2:`10pt`,3:`12pt`,4:`14pt`,5:`18pt`,6:`24pt`,7:`36pt`};i&&n.push(`font-family:${i}`),a&&n.push(`color:${a}`),s&&c[s]&&n.push(`font-size:${c[s]}`);let l=e.getAttribute(`style`)||``,u=o([n.join(`;`),l].filter(Boolean).join(`;`));for(u&&t.setAttribute(`style`,u);e.firstChild;)t.append(e.firstChild);e.replaceWith(t)}for(let e of Array.from(i.querySelectorAll(`p,div`))){let t=e.getAttribute(`class`)||``,n=t.match(/MsoHeading([1-6])/i)?.[1]||(/MsoTitle/i.test(t)?`1`:/MsoSubtitle/i.test(t)?`2`:``);if(!n)continue;let i=r.createElement(`h${n}`);for(let t of Array.from(e.attributes))i.setAttribute(t.name,t.value);for(;e.firstChild;)i.append(e.firstChild);e.replaceWith(i)}let c=e=>{let t=r.createDocumentFragment(),n=null,i=``;for(let a of Array.from(e.childNodes))if(a.nodeType===Node.ELEMENT_NODE){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;if([`P`,`DIV`].includes(e.tagName)&&(/mso-list\s*:/i.test(l)||/MsoListParagraph/i.test(s)||u)){let a=(u?.textContent||e.textContent||``).replace(/\u00a0/g,` `).trim();u?.remove();let s=/^(?:\d+|[a-z]|[ivxlcdm]+)[.)]/i.test(a)?`ol`:`ul`;(!n||i!==s)&&(n=r.createElement(s),i=s,t.append(n));let c=r.createElement(`li`),d=o(l.replace(/(?:^|;)\s*mso-list\s*:[^;]*/gi,``));for(d&&c.setAttribute(`style`,d);e.firstChild;)c.append(e.firstChild);n.append(c);continue}if(n=null,i=``,c(e),e.tagName===`DIV`&&/WordSection/i.test(s))for(;e.firstChild;)t.append(e.firstChild);else t.append(e)}else a.nodeType===Node.TEXT_NODE&&!(a.textContent||``).trim()?n||t.append(a):(n=null,i=``,a.nodeType!==Node.COMMENT_NODE&&t.append(a));e.replaceChildren(t)};c(i);let l=e=>{e.replaceWith(...Array.from(e.childNodes))};for(let e of Array.from(i.querySelectorAll(`*`)))e.tagName.includes(`:`)&&l(e);let u=new Set([`href`,`src`,`alt`,`title`,`colspan`,`rowspan`,`start`,`value`,`type`,`width`,`height`,`border`,`cellpadding`,`cellspacing`,`scope`,`dir`]),d=(e,t=!1)=>{let n=e.trim();if(/^#[-\w:.]+$/.test(n)||t&&/^data:image\/(?:png|gif|jpe?g|webp);base64,/i.test(n))return!0;try{return[`http:`,`https:`,`mailto:`,`tel:`].includes(new URL(n,`https://mint.invalid`).protocol)}catch{return!1}};for(let e of Array.from(i.querySelectorAll(`*`)))for(let t of Array.from(e.attributes)){let n=t.name.toLowerCase();if(n===`style`){let n=o(t.value);n?e.setAttribute(`style`,n):e.removeAttribute(t.name)}else u.has(n)?((n===`href`||n===`src`)&&!d(t.value,n===`src`)||[`colspan`,`rowspan`,`start`,`value`,`width`,`height`,`border`,`cellpadding`,`cellspacing`].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)}for(let e of Array.from(i.querySelectorAll(`span`)))e.attributes.length||l(e);return i.innerHTML.trim()}syncSource(){if(this.source&&this.editor){let e=this.cleanEditorCopy();this.source.value=this.format===`markdown`?i(e):e.innerHTML}this.updateWordCount()}emitChange(){this.syncSource();let e=this.value;this.dispatchEvent(new CustomEvent(`input`,{bubbles:!0,composed:!0,detail:{value:e}})),this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,composed:!0,detail:{value:e}}))}updateWordCount(){if(!this.editor||!this.count)return;let e=(this.editor.innerText||``).trim().split(/\s+/).filter(Boolean).length;this.count.textContent=`${e} ${e===1?`word`:`words`}`}updateSelectionUI(){if(!this.editor)return;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;this.selectTable(i&&this.editor.contains(i)?i:null);let a=this.sourceMode||!i;if(this.tableTrigger?.hidden!==a&&(this.tableTrigger?.toggleAttribute(`hidden`,a),this.updateToolbarOverflow()),this.sourceMode||!n)return;let o=r?.closest(`h1,h2,h3,h4,h5,h6,p,blockquote,div,li,td,th,pre`),s=o?.tagName.toLowerCase()||`p`,c={p:`Paragraph`,h1:`Heading 1`,h2:`Heading 2`,h3:`Heading 3`,h4:`Heading 4`,h5:`Heading 5`,h6:`Heading 6`,blockquote:`Quote`,div:`Div`,li:`List item`,td:`Table cell`,th:`Table header`,pre:`Code block`},l=[`h1`,`h2`,`h3`,`h4`,`h5`,`h6`,`blockquote`,`div`,`li`,`td`,`th`,`pre`].includes(s)?s:`p`;this.fontSizeDisplay&&(this.fontSizeDisplay.textContent=`${this.readFontSize()}px`);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`);p&&p.setAttribute(`name`,d),this.alignmentTrigger&&this.updateTooltipLabel(this.alignmentTrigger,`Text alignment: ${f}`);let m=this.toolbar?.querySelector(`.mint-editor-toolbar-checklist`);m?.classList.toggle(`is-active`,!!r?.closest(`ul[data-mint-task-list]`)),m?.setAttribute(`aria-pressed`,String(!!r?.closest(`ul[data-mint-task-list]`)));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`);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){let e=this.blockButton.querySelector(`.mint-editor-block-label`),t=c[l]||`Paragraph`;e&&(e.textContent=t),this.updateTooltipLabel(this.blockButton,`Text style: ${t}`)}this.footerMode&&(this.footerMode.textContent=s),this.blockPopover?.querySelectorAll(`[data-block-tag]`).forEach(e=>{let t=e.dataset.blockTag===l;e.toggleAttribute(`data-active`,t),e.setAttribute(`aria-pressed`,String(t))});for(let[t,n]of this.inlineButtons){let r=e?.rangeCount?e.getRangeAt(0):null,i=r?this.inlineStateAtSelection(t,r):!1;n.classList.toggle(`is-active`,i),n.setAttribute(`aria-pressed`,String(i))}}insertTable(e,t){if(!this.editor)return;let n=this.editor.ownerDocument,r=n.createElement(`table`);r.className=`mint-editor-table`;let i=n.createElement(`tbody`);for(let r=0;r<e;r++){let e=n.createElement(`tr`);for(let i=0;i<t;i++){let t=n.createElement(r===0?`th`:`td`);t.innerHTML=`<br>`,e.append(t)}i.append(e)}r.append(i),this.editor.focus(),this.restoreSelection();let a=this.selection;if(a?.rangeCount&&this.editor.contains(a.anchorNode)){let e=a.getRangeAt(0),t=(e.startContainer.nodeType===Node.ELEMENT_NODE?e.startContainer:e.startContainer.parentElement)?.closest(`a`);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)}else this.editor.append(r);this.emitChange()}openTableModal(){this.saveSelection();let e=document.createElement(`mint-modal`);e.setAttribute(`heading`,`Insert table`),e.setAttribute(`size`,`small`);let t=document.createElement(`div`);t.setAttribute(`slot`,`body`),t.className=`mint-editor-modal-fields`;let n=document.createElement(`mint-input`);n.setAttribute(`type`,`number`),n.setAttribute(`label`,`Rows`),n.setAttribute(`min`,`1`),n.setAttribute(`max`,`12`),n.setAttribute(`value`,`3`);let r=document.createElement(`mint-input`);r.setAttribute(`type`,`number`),r.setAttribute(`label`,`Columns`),r.setAttribute(`min`,`1`),r.setAttribute(`max`,`10`),r.setAttribute(`value`,`3`),t.append(n,r);let i=document.createElement(`div`);i.setAttribute(`slot`,`actions`),i.className=`mint-editor-modal-actions`;let a=document.createElement(`mint-button`);a.textContent=`Cancel`,a.setAttribute(`variant`,`ghost`),this.setTooltip(a,`Cancel`),a.addEventListener(`click`,()=>e.close());let o=document.createElement(`mint-button`);o.textContent=`Insert table`,o.setAttribute(`tone`,`action`),this.setTooltip(o,`Insert table`),o.addEventListener(`click`,()=>{let t=Math.max(1,Math.min(12,Number(n.value)||3)),i=Math.max(1,Math.min(10,Number(r.value)||3));e.close(),this.insertTable(t,i)}),i.append(a,o),e.append(t,i),this.append(e),e.open()}openLinkModal(){this.saveSelection();let e=document.createElement(`mint-modal`);e.setAttribute(`heading`,`Insert link`),e.setAttribute(`size`,`small`);let t=document.createElement(`div`);t.setAttribute(`slot`,`body`);let n=document.createElement(`mint-input`);n.setAttribute(`type`,`url`),n.setAttribute(`label`,`Link URL`),n.setAttribute(`placeholder`,`https://example.com`),t.append(n);let r=document.createElement(`div`);r.setAttribute(`slot`,`actions`),r.className=`mint-editor-modal-actions`;let i=document.createElement(`mint-button`);i.textContent=`Cancel`,i.setAttribute(`variant`,`ghost`),this.setTooltip(i,`Cancel`),i.addEventListener(`click`,()=>e.close());let a=document.createElement(`mint-button`);a.textContent=`Insert link`,a.setAttribute(`tone`,`action`),this.setTooltip(a,`Insert link`),a.addEventListener(`click`,()=>{let t=String(n.value||``).trim();t&&(this.command(`createLink`,t),e.close())}),r.append(i,a),e.append(t,r),this.append(e),e.open()}selectedTable(){let e=this._savedRange?.startContainer||this.selection?.anchorNode,t=(e?.nodeType===Node.ELEMENT_NODE?e:e?.parentElement)?.closest(`table`);return t&&this.editor?.contains(t)?t:null}applyTableAction(e){let t=this.selectedTable();if(!t)return;let n=this._savedRange,r=(n?.startContainer.nodeType===Node.ELEMENT_NODE?n.startContainer:n?.startContainer.parentElement)?.closest(`td,th`),i=r?.parentElement;if(e===`Add row below`||e===`Add row above`){let n=i?.cloneNode(!0);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))}if(e===`Add column right`||e===`Add column left`){let n=(r?Array.from(r.parentElement.children).indexOf(r):(t.querySelector(`tr`)?.children.length||1)-1)+(e===`Add column right`?1:0);t.querySelectorAll(`tr`).forEach(e=>{let r=e.querySelector(`th`)?`th`:`td`,i=t.ownerDocument.createElement(r);i.innerHTML=`<br>`,e.insertBefore(i,e.children[n]||null)})}if(e===`Delete row`&&i&&t.querySelectorAll(`tr`).length>1&&i.remove(),e===`Delete column`&&r&&r.parentElement.children.length>1){let e=Array.from(r.parentElement.children).indexOf(r);t.querySelectorAll(`tr`).forEach(t=>t.children[e]?.remove())}e===`Delete table`&&t.remove(),this.emitChange(),this.updateSelectionUI()}selectTable(e){this.selectedTableElement!==e&&this.selectedTableElement?.classList.remove(`is-selected`),this.selectedTableElement=e,e?.classList.add(`is-selected`);let t=!!e&&!this.sourceMode;this.inlineTableTools&&(this.inlineTableTools.hidden=!t),this.tableResizeHandle&&(this.tableResizeHandle.hidden=!t),t&&this.positionTableTools()}positionTableTools(){let e=this.selectedTableElement,t=this.querySelector(`.mint-editor-shell`),n=this.editorFrame;if(!e||!t||!n||!this.inlineTableTools||!this.tableResizeHandle||this.sourceMode)return;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);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`}startTableResize(e){let t=this.selectedTableElement;if(!t)return;e.preventDefault(),e.stopPropagation();let n=t.getBoundingClientRect();this.tableResizeState={table:t,startX:e.clientX,startY:e.clientY,startWidth:n.width,startHeight:n.height,pointerId:e.pointerId},this.ownerDocument.defaultView?.addEventListener(`pointermove`,this.onTableResizeMove),this.ownerDocument.defaultView?.addEventListener(`pointerup`,this.onTableResizeEnd)}startGridResize(e){let t=e.target?.closest(`td,th`),n=t?.closest(`table`);if(!t||!n||!this.editor?.contains(n))return;let r=t.getBoundingClientRect(),i=Math.abs(e.clientX-r.right)<=7,a=Math.abs(e.clientY-r.bottom)<=7;if(!i&&!a)return;let o=t.parentElement,s=Array.from(n.rows).indexOf(o);if(a)this.gridResizeState={table:n,kind:`row`,index:s,start:e.clientY,size:o.getBoundingClientRect().height,pointerId:e.pointerId};else{let i=Array.from(o.cells).indexOf(t);this.ensureTableColumns(n);let a=n.querySelectorAll(`col`)[i];this.gridResizeState={table:n,kind:`column`,index:i,start:e.clientX,size:a?.getBoundingClientRect().width||r.width,pointerId:e.pointerId}}e.preventDefault(),e.stopPropagation();let c=this.editor?.ownerDocument.defaultView;c?.addEventListener(`pointermove`,this.onGridResizeMove),c?.addEventListener(`pointerup`,this.onGridResizeEnd),c?.addEventListener(`pointercancel`,this.onGridResizeEnd)}updateGridResizeCursor(e){let t=this.editor;if(!t||this.gridResizeState)return;let n=e.target?.closest(`td,th`);if(!n){t.style.cursor=``;return}let r=n.getBoundingClientRect(),i=Math.abs(e.clientX-r.right)<=7,a=Math.abs(e.clientY-r.bottom)<=7;t.style.cursor=i&&a?`nwse-resize`:i?`col-resize`:a?`row-resize`:``}ensureTableColumns(e){let t=e.querySelector(`colgroup`);t||(t=e.ownerDocument.createElement(`colgroup`),e.insertBefore(t,e.firstChild));let n=Math.max(1,...Array.from(e.rows,e=>e.cells.length));for(;t.children.length<n;)t.append(e.ownerDocument.createElement(`col`))}toggleSource(){if(!(!this.editor||!this.source)){if(this.sourceMode=!this.sourceMode,this.clearInlineTypingState(),this.source.hidden=!this.sourceMode,this.editor.hidden=this.sourceMode,this.sourceMode){let e=this.cleanEditorCopy();this.source.value=this.format===`markdown`?i(e):e.innerHTML}else this.editor.innerHTML=this.format===`markdown`?n(this.source.value):this.source.value;this.toolbar?.classList.toggle(`mint-editor-source-active`,this.sourceMode),this.updateWordCount(),this.sourceMode?this.selectTable(null):this.updateSelectionUI()}}createResizeHandle(){let e=(this.editor?.ownerDocument||document).createElement(`button`);return e.type=`button`,e.className=`mint-editor-resize-handle`,this.setTooltip(e,`Resize image`),e.addEventListener(`pointerdown`,t=>{t.preventDefault(),t.stopPropagation();let n=e.parentElement;this.resizeState={frame:n,startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},this.editor?.ownerDocument.defaultView?.addEventListener(`pointermove`,this.onResizeMove),this.editor?.ownerDocument.defaultView?.addEventListener(`pointerup`,this.onResizeEnd)}),e}selectImage(e){this.selectedImage?.classList.remove(`is-selected`),this.selectedImage=e,e?.classList.add(`is-selected`);let t=this.querySelector(`.mint-editor-image-tools`);t&&(t.hidden=!e);let n=t?.querySelector(`mint-input`);e&&n&&(n.value=`${Math.round(e.getBoundingClientRect().width/Math.max(1,this.editor?.clientWidth||e.getBoundingClientRect().width)*100)}`)}updateSelectedImage(){let e=this.selection?.anchorNode,t=e?.nodeType===Node.ELEMENT_NODE?e.closest(`.mint-editor-image-frame`):e?.parentElement?.closest(`.mint-editor-image-frame`);t&&this.selectImage(t)}};customElements.get(`mint-editor`)||e.t(`mint-editor`,a),module.exports=a;
|
|
29
|
+
</style></head><body><div class="editor" contenteditable="${!a}" role="textbox" aria-multiline="true" aria-label="${t(s||`Rich text editor`)}" data-placeholder="${t(this.getAttribute(`placeholder`)||`Start writing…`)}"></div></body></html>`,p.addEventListener(`load`,()=>{!this.isConnected||this.editorFrame!==p||this.bindEditorFrame(i,a)}),this.editorFrame=p;let m=document.createElement(`textarea`);m.className=`mint-editor-source`,m.style.height=`100%`,m.setAttribute(`aria-label`,`Editor ${this.format.toUpperCase()} source`),m.hidden=!0,m.value=this.format===`markdown`?r:i,m.addEventListener(`input`,()=>{this.editor&&(this.editor.innerHTML=this.format===`markdown`?n(m.value):m.value),this.updateWordCount(),this.emitChange()}),this.source=m;let h=document.createElement(`div`);h.className=`mint-editor-stage`,h.style.height=o,h.append(p,m);let g=null;[`false`,`0`,`off`,`no`].includes((this.getAttribute(`resizable`)||``).trim().toLowerCase())||(g=document.createElement(`button`),g.type=`button`,g.className=`mint-editor-stage-resize-handle`,this.setTooltip(g,`Resize editor`),g.addEventListener(`pointerdown`,e=>this.onStageResizeStart(e,h))),l.append(u,h,d,f);let _=document.createElement(`div`);_.className=`mint-editor-image-tools`,_.hidden=!0,_.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>`,_.querySelectorAll(`[data-align]`).forEach(e=>this.setTooltip(e,`Align image ${e.dataset.align}`));let v=_.querySelector(`[data-remove="image"]`);v&&this.setTooltip(v,`Remove image`),_.querySelector(`mint-input`)?.addEventListener(`input`,e=>{if(!this.selectedImage)return;let t=Number(e.target.value);this.selectedImage.style.width=`${Math.max(10,Math.min(100,t))}%`,this.emitChange()}),_.querySelectorAll(`[data-align]`).forEach(e=>e.addEventListener(`click`,()=>{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())})),_.querySelector(`[data-remove="image"]`)?.addEventListener(`click`,()=>{this.selectedImage?.remove(),this.selectImage(null),this.emitChange()}),c.append(l,_);let y=document.createElement(`div`);y.className=`mint-editor-footer`;let b=document.createElement(`span`);b.className=`mint-editor-mode`,b.textContent=`p`;let x=document.createElement(`span`);x.className=`mint-editor-word-count`,this.count=x;let S=document.createElement(`div`);S.className=`mint-editor-footer-end`,S.append(x),g&&S.append(g),y.append(b,S),this.footerMode=b,l.append(y);let C=this.getAttribute(`error`);if(C){let e=document.createElement(`div`);e.className=`mint-editor-error`,e.textContent=C,c.append(e)}this.append(c);let w=this.querySelector(`.mint-editor-stage`);if(w&&typeof ResizeObserver<`u`&&(this.frameResizeObserver?.disconnect(),this.frameResizeObserver=new ResizeObserver(([e])=>{if(!e||!this.editorFrame)return;let t=Math.max(0,e.contentRect.width),n=Math.max(0,e.contentRect.height);this.editorFrame.style.width=`${t}px`,this.editorFrame.style.height=`${n}px`}),this.frameResizeObserver.observe(w)),this.toolbar&&typeof ResizeObserver<`u`){this.toolbarResizeObserver?.disconnect(),this.toolbarResizeObserver=new ResizeObserver(()=>this.updateToolbarOverflow()),this.toolbarResizeObserver.observe(this.toolbar);let e=this.toolbar.querySelector(`.mint-editor-toolbar-actions`);e&&this.toolbarResizeObserver.observe(e),requestAnimationFrame(()=>this.updateToolbarOverflow())}this.sourceMode=!1,this.observer&&this.editor&&this.observer.observe(this.editor,{childList:!0,subtree:!0,characterData:!0}),this.updateWordCount(),this.updateFormatUI()}removeStageResizeListeners(){let e=this.ownerDocument.defaultView;e?.removeEventListener(`pointermove`,this.onStageResizeMove),e?.removeEventListener(`pointerup`,this.onStageResizeEnd),e?.removeEventListener(`pointercancel`,this.onStageResizeEnd),this.stageResizeState=null}bindEditorFrame(e,t){let r=this.editorFrame?.contentDocument,i=r?.querySelector(`.editor`);if(!r||!i)return;i.contentEditable=String(!t),i.innerHTML=this.pendingValue===null?e:this.format===`markdown`?n(this.pendingValue):this.pendingValue,this.pendingValue=null;let a=getComputedStyle(this),o=r.body;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,[`text`,`text-muted`,`surface`,`surface-subtle`,`border`,`primary`,`focus`].forEach(e=>{let t=a.getPropertyValue(`--mint-color-${e}`).trim();t&&i.style.setProperty(`--mint-color-${e}`,t)}),this.editor=i,i.addEventListener(`input`,()=>{this.normalizeTaskListItems(),this.syncSource(),this.emitChange(),this.updateSelectionUI()}),i.addEventListener(`change`,e=>{let t=e.target;t.matches(`ul[data-mint-task-list] input[type="checkbox"]`)&&(t.toggleAttribute(`checked`,t.checked),this.emitChange())}),i.addEventListener(`paste`,e=>{let t=e.clipboardData?.getData(`text/html`)||``;if(!t||!this.editor?.contains(this.selection?.anchorNode||null))return;let n=this.sanitizePastedHtml(t);n&&(e.preventDefault(),this.clearInlineTypingState(),this.insertPastedHtml(n),this.normalizeTaskListItems(),this.emitChange(),this.updateSelectionUI())}),i.addEventListener(`beforeinput`,e=>{let t=e;t.inputType.startsWith(`insert`)&&(this.preserveInlineOverridesOnNextEditorClick=!1);let n=t.shiftKey;if((t.inputType===`insertParagraph`||t.inputType===`insertLineBreak`&&!n)&&!t.isComposing){let e=this.selection?.anchorNode,n=(e?.nodeType===Node.ELEMENT_NODE?e:e?.parentElement)?.closest(`li`),r=n?.parentElement;if(n&&r?.tagName===`UL`&&r.hasAttribute(`data-mint-task-list`)&&this.editor?.contains(n)){t.preventDefault(),this.isEmptyTaskItem(n)?this.exitTaskList(n,r):this.splitTaskItem(n,r);return}}this.applyInlineTypingState(t)}),i.addEventListener(`keyup`,e=>{[`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`,`PageUp`,`PageDown`].includes(e.key)&&this.clearInlineTypingState(),this.updateSelectedImage(),this.updateSelectionUI()}),i.addEventListener(`mouseup`,()=>{this.updateSelectedImage(),this.updateSelectionUI()}),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=>{this.closeEditorPopovers(),this.preserveInlineOverridesOnNextEditorClick?this.preserveInlineOverridesOnNextEditorClick=!1:this.clearInlineTypingState();let t=e.target,n=t.closest(`.mint-editor-image-frame`);n?this.selectImage(n):t.closest(`.mint-editor-image-tools`)||this.selectImage(null);let r=t.closest(`table`);this.selectTable(r),t.closest(`a`)&&e.preventDefault()}),i.addEventListener(`keydown`,e=>{if(e.key===`Enter`&&!e.shiftKey&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.isComposing){let t=this.selection,n=t?.anchorNode,r=(n?.nodeType===Node.ELEMENT_NODE?n:n?.parentElement)?.closest(`li`),i=r?.parentElement;if(t?.isCollapsed&&r&&i?.tagName===`UL`&&i.hasAttribute(`data-mint-task-list`)&&this.editor?.contains(r)){e.preventDefault(),this.isEmptyTaskItem(r)?this.exitTaskList(r,i):this.splitTaskItem(r,i);return}}(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`))}),this.observer&&this.observer.observe(i,{childList:!0,subtree:!0,characterData:!0}),this.updateWordCount(),this.updateSelectionUI()}buildToolbar(e){let t=(t,n,r,i=e)=>{let a=document.createElement(`button`);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=>{e.preventDefault(),r()}),i.append(a),a},n=(e,t,n)=>{let r=document.createElement(`mint-popover`);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},r=(e,t,n,r)=>{let i=this.createMenuOption(t,n);return i.addEventListener(`click`,r),e.append(i),i};t(`Undo`,`undo`,()=>this.command(`undo`)),t(`Redo`,`redo`,()=>this.command(`redo`));let i=document.createElement(`button`);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`;let a=document.createElement(`span`);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);let o=n(i,`mint-editor-block-popover`,e);[[`p`,`Paragraph`,`paragraph`],[`h1`,`Heading 1`,`heading`],[`h2`,`Heading 2`,`heading`],[`h3`,`Heading 3`,`heading`],[`blockquote`,`Quote`,`quote`],[`div`,`Div`,`code`]].forEach(([e,t,n])=>{let r=this.createMenuOption(t,n);r.dataset.blockTag=e,r.addEventListener(`click`,()=>{this.command(`formatBlock`,e),o.close(),this.updateSelectionUI()}),o.append(r)}),this.blockPopover=o;let s=document.createElement(`div`);s.className=`mint-editor-font-size-control`,t(`Decrease font size`,`minus`,()=>this.applyFontSize(this.readFontSize()-1),s);let c=document.createElement(`button`);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`);let l=document.createElement(`span`);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;let u=document.createElement(`div`);u.className=`mint-editor-toolbar-actions`,e.append(u),u.append(s);let d=n(c,`mint-editor-font-size-popover`,u),f=[[s,d]];[8,9,10,11,12,14,16,18,20,24,28,32,36,48,72].forEach(e=>{let t=document.createElement(`button`);t.type=`button`,t.className=`mint-editor-menu-option mint-editor-font-size-option`,t.textContent=`${e}px`,t.addEventListener(`click`,()=>{this.applyFontSize(e),d.close()}),d.append(t)});let p=(e,n,r)=>{let i=t(e,n,r,u);return[`bold`,`italic`,`underline`].includes(n)&&(i.setAttribute(`aria-pressed`,`false`),this.inlineButtons.set(n,i)),i},m=e=>{let t=e.querySelector(`:scope > mint-icon`);if(!t)return;let n=document.createElement(`span`);n.className=`mint-editor-color-icon`,e.insertBefore(n,t),n.append(t)},h=()=>{let e=this.separator();return u.append(e),f.push([e]),e},g=p(`Bold`,`bold`,()=>this.toggleInline(`bold`)),_=p(`Italic`,`italic`,()=>this.toggleInline(`italic`)),v=p(`Underline`,`underline`,()=>this.toggleInline(`underline`));f.push([g],[_],[v]);let y=this.separator();u.append(y);let b=p(`Text color`,`text-color`,()=>{});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);let x=n(b,`mint-editor-color-popover`,u);this.buildColorPopover(x,`text`,b),this.colorTriggers.set(`text`,b);let S=p(`Highlight color`,`highlight`,()=>{});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);let C=n(S,`mint-editor-color-popover`,u);this.buildColorPopover(C,`background`,S),this.colorTriggers.set(`background`,S),f.push([y,b,x,S,C]);let w=p(`Font family`,`font-family`,()=>{});w.id=`${this.id||`mint-editor-${Math.random().toString(36).slice(2)}`}-font-family-trigger`,w.append(this.icon(`caret-down`));let T=n(w,`mint-editor-font-family-popover`,u);[[`Arial`,`Arial, sans-serif`],[`Helvetica`,`Helvetica, sans-serif`],[`Georgia`,`Georgia, serif`],[`Times New Roman`,`"Times New Roman", serif`],[`Courier New`,`"Courier New", monospace`],[`System UI`,`system-ui, sans-serif`]].forEach(([e,t])=>{r(T,e,`font-family`,()=>{this.applyFontFamily(t),T.close()})}),f.push([w,T]),h();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`);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);let A=n(k,``,u);this.tablePopover=A,[[`Add row below`,`table-row`],[`Add column right`,`table-column`],[`Delete row`,`table-row-delete`],[`Delete column`,`table-column-delete`],[`Delete table`,`trash`]].forEach(([e,t])=>{let n=this.createMenuOption(e,t);n.addEventListener(`click`,()=>{this.applyTableAction(e),A.close()}),A.append(n)}),k.addEventListener(`pointerdown`,()=>this.saveSelection()),this.tableTrigger=k,f.push([E],[D],[O,k,A]);let j=p(`Add comment`,`comment-plus`,()=>this.openCommentModal());f.push([j]),h();let M=p(`Text alignment`,`align-left`,()=>{});M.id=`${this.id||`mint-editor-${Math.random().toString(36).slice(2)}`}-alignment-trigger`,M.append(this.icon(`caret-down`)),this.alignmentTrigger=M;let N=n(M,`mint-editor-alignment-popover`,u);[[`Align left`,`align-left`,`justifyLeft`],[`Align center`,`align-center`,`justifyCenter`],[`Align right`,`align-right`,`justifyRight`],[`Justify`,`align-justify`,`justifyFull`]].forEach(([e,t,n])=>{r(N,e,t,()=>{this.command(n),N.close(),this.updateTooltipLabel(M,`Text alignment: ${e}`)})}),f.push([M,N]),h();let P=p(`Bulleted list`,`list`,()=>this.command(`insertUnorderedList`)),F=document.createElement(`button`);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);let I=n(F,`mint-editor-list-popover`,u);[[`Disc`,`disc`],[`Circle`,`circle`],[`Square`,`square`]].forEach(([e,t])=>r(I,e,`list`,()=>{this.applyListStyle(`ul`,t),I.close()}));let L=p(`Numbered list`,`numbered-list`,()=>this.command(`insertOrderedList`)),R=document.createElement(`button`);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);let z=n(R,`mint-editor-list-popover`,u);[[`Numbers`,`decimal`],[`Lowercase letters`,`lower-alpha`],[`Uppercase letters`,`upper-alpha`],[`Lowercase Roman numerals`,`lower-roman`],[`Uppercase Roman numerals`,`upper-roman`]].forEach(([e,t])=>r(z,e,`numbered-list`,()=>{this.applyListStyle(`ol`,t),z.close()}));let B=p(`Checklist`,`checklist`,()=>this.toggleChecklist());f.push([P,F,I],[L,R,z],[B]),h();let V=p(`HTML source`,`code`,()=>this.toggleSource());f.push([V]),this.sourceButton=e.querySelector(`.mint-editor-toolbar-code`);let H=p(`Clear formatting`,`clear-formatting`,()=>this.clearFormatting());f.push([H]);let U=document.createElement(`button`);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`));let W=document.createElement(`mint-popover`);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}buildColorPopover(e,t,n){let r=[`#bcebd1`,`#fff0b3`,`#f7c9c9`,`#e9c8f5`,`#c4e1f2`,`#20bd70`,`#f1c40f`,`#e33b2e`,`#b65bd0`,`#3298d4`,`#168f77`,`#e77d1e`,`#b9372b`,`#823a9d`,`#2874a6`,`#edf0f2`,`#cfd5d8`,`#9eadae`,`#7e8d8f`,`#35495e`],i=document.createElement(`div`);i.className=`mint-editor-color-grid`,i.setAttribute(`role`,`group`),i.setAttribute(`aria-label`,t===`text`?`Text colors`:`Highlight colors`);let a=()=>t===`text`?this.lastTextColor:this.lastBackgroundColor,o=(r,o=!0)=>{this.applyEditorColor(t,r);let s=this.colorRecentSwatches.get(t);s&&(s.style.backgroundColor=a(),s.dataset.color=a());let c=e.querySelector(`input[type="color"]`);c&&document.activeElement!==c&&(c.value=a()),n.style.setProperty(`--editor-color`,a()),i.querySelectorAll(`.mint-editor-color-swatch`).forEach(e=>{let t=!!e.dataset.color&&e.dataset.color.toLowerCase()===a().toLowerCase();e.toggleAttribute(`data-selected`,t),e.setAttribute(`aria-pressed`,String(t))}),o&&e.close()},s=(e,t,n=``)=>{let r=document.createElement(`button`);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=>{e.preventDefault(),this.saveSelection()}),r.addEventListener(`click`,e=>{e.preventDefault(),o(t)}),i.append(r),r};r.forEach((e,t)=>s(`Color ${t+1}: ${e}`,e)),s(`Black`,`#000000`,`is-utility-swatch`),s(`White`,`#ffffff`,`is-utility-swatch`);let c=s(`Last used color`,a(),`is-utility-swatch is-recent-swatch`);this.colorRecentSwatches.set(t,c);let l=document.createElement(`button`);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=>{e.preventDefault(),this.saveSelection()}),l.addEventListener(`click`,e=>{e.preventDefault(),o(null)}),i.append(l);let u=document.createElement(`input`);u.type=`color`,u.className=`mint-editor-native-color-picker`,u.value=a(),u.setAttribute(`aria-label`,`Choose a custom color`);let d=document.createElement(`button`);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=>{e.preventDefault(),this.saveSelection()}),d.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),u.click()}),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));let f=document.createElement(`div`);f.className=`mint-editor-custom-color-cell`,f.append(d,u),i.append(f),e.append(i)}applyEditorColor(e,t){if(!this.editor||this.sourceMode)return;this.editor.focus(),this.restoreSelection();let n=this.editor.ownerDocument,r=this.selection,i=e===`text`?t||getComputedStyle(this.editor).color||`#202833`:t||getComputedStyle(this.editor).backgroundColor||`transparent`;if(r?.isCollapsed){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();return}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()}readFontSize(){let e=this.selection,t=e?.isCollapsed?Number.parseFloat(this.inlineStyleOverrides.get(`fontSize`)||``):NaN;if(Number.isFinite(t)&&t>0)return Math.round(t);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;return Number.isFinite(a)&&a>0?Math.round(a):16}applyFontSize(e){if(!this.editor||this.sourceMode)return;let t=Math.max(8,Math.min(96,Math.round(e)));this.editor.focus(),this.restoreSelection();let n=this.editor.ownerDocument;if(this.selection?.isCollapsed){this.inlineStyleOverrides.set(`fontSize`,`${t}px`),this.preserveInlineOverridesOnNextEditorClick=!0,this.emitChange(),this.updateSelectionUI();return}this.inlineStyleOverrides.delete(`fontSize`);let r=new Set(Array.from(this.editor.querySelectorAll(`font[size="7"]`)));n.execCommand(`fontSize`,!1,`7`),this.editor.querySelectorAll(`font[size="7"]`).forEach(e=>{if(r.has(e))return;let i=n.createElement(`span`);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)}),this.emitChange(),this.updateSelectionUI()}applyFontFamily(e){if(!this.editor||this.sourceMode)return;if(this.editor.focus(),this.restoreSelection(),this.selection?.isCollapsed){this.inlineStyleOverrides.set(`fontFamily`,e),this.preserveInlineOverridesOnNextEditorClick=!0,this.emitChange(),this.updateSelectionUI();return}this.inlineStyleOverrides.delete(`fontFamily`);let t=this.editor.ownerDocument,n=new Set(Array.from(this.editor.querySelectorAll(`font[face]`)));t.execCommand(`fontName`,!1,e),this.editor.querySelectorAll(`font[face]`).forEach(r=>{if(n.has(r))return;let i=t.createElement(`span`);i.style.fontFamily=r.getAttribute(`face`)||e,i.append(...Array.from(r.childNodes)),r.replaceWith(i)}),this.emitChange(),this.updateSelectionUI()}applyListStyle(e,t){if(!this.editor||this.sourceMode)return;this.editor.focus(),this.restoreSelection();let n=this.selection?.anchorNode,r=(n?.nodeType===Node.ELEMENT_NODE?n:n?.parentElement)?.closest(e),i=r&&this.editor.contains(r)?r:null;if(!i){this.editor.ownerDocument.execCommand(e===`ul`?`insertUnorderedList`:`insertOrderedList`,!1);let t=this.selection?.anchorNode,n=(t?.nodeType===Node.ELEMENT_NODE?t:t?.parentElement)?.closest(e);i=n&&this.editor.contains(n)?n:null}i&&(i.style.listStyleType=t),this.emitChange(),this.updateSelectionUI()}toggleChecklist(){if(!this.editor||this.sourceMode)return;this.editor.focus(),this.restoreSelection();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`);if(r)r.removeAttribute(`data-mint-task-list`),r.querySelectorAll(`input[type="checkbox"]`).forEach(e=>e.remove());else{i||(n?.closest(`h1,h2,h3,h4,h5,h6`)&&e.execCommand(`formatBlock`,!1,`p`),e.execCommand(`insertUnorderedList`,!1));let t=this.selection?.anchorNode,r=t?.nodeType===Node.ELEMENT_NODE?t:t?.parentElement,a=i||r?.closest(`ul`);if(a&&this.editor.contains(a)){a.setAttribute(`data-mint-task-list`,`true`),a.querySelectorAll(`li`).forEach((t,n)=>{if(t.querySelector(`input[type="checkbox"]`))return;let r=e.createElement(`input`);r.type=`checkbox`,r.setAttribute(`contenteditable`,`false`),r.setAttribute(`aria-label`,`Task ${n+1} complete`),t.insertBefore(r,t.firstChild)});let t=a.parentElement;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))}}this.emitChange(),this.updateSelectionUI()}splitTaskItem(e,t){if(!this.editor)return;let n=this.editor.ownerDocument,r=this.selection,i=r?.anchorNode,a=Array.from(e.children).find(e=>e.matches(`input[type="checkbox"]`));if(a)e.firstChild!==a&&(a.remove(),e.insertBefore(a,e.firstChild));else{let r=n.createElement(`input`);r.type=`checkbox`,r.setAttribute(`contenteditable`,`false`),r.setAttribute(`aria-label`,`Task ${t.children.length} complete`),e.insertBefore(r,e.firstChild)}let o=n.createRange();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);let s=o.extractContents(),c=n.createElement(`li`),l=n.createElement(`input`);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);let u=n.createRange();u.setStart(c,1),u.collapse(!0),r?.removeAllRanges(),r?.addRange(u),this.syncSource(),this.emitChange(),this.updateSelectionUI()}normalizeTaskListItems(){if(!this.editor)return;let e=this.selection,t=e?.anchorNode,n=t?.nodeType===Node.ELEMENT_NODE?t.closest(`li`):t?.parentElement?.closest(`li`);for(let r of this.editor.querySelectorAll(`ul[data-mint-task-list]`))Array.from(r.children).forEach((r,i)=>{if(r.tagName!==`LI`)return;let a=r,o=Array.from(a.children).find(e=>e.matches(`input[type="checkbox"]`));if(!o){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){let t=this.editor.ownerDocument.createRange();t.setStart(a,1),t.collapse(!0),e.removeAllRanges(),e.addRange(t)}}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)){let t=this.editor.ownerDocument.createRange();t.setStart(a,1),t.collapse(!0),e.removeAllRanges(),e.addRange(t)}})}isEmptyTaskItem(e){let t=e=>{if(e.nodeType===Node.TEXT_NODE)return!!e.textContent?.trim();if(e.nodeType!==Node.ELEMENT_NODE)return!1;let n=e;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)};return!Array.from(e.childNodes).some(t)}exitTaskList(e,t){if(!this.editor||!t.parentNode)return;let n=t.parentNode,r=t.cloneNode(!1);for(;e.nextElementSibling;)r.append(e.nextElementSibling);e.remove();let i=this.editor.ownerDocument.createElement(`p`);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();let a=this.selection,o=this.editor.ownerDocument.createRange();o.setStart(i,0),o.collapse(!0),a?.removeAllRanges(),a?.addRange(o),this.syncSource(),this.emitChange(),this.updateSelectionUI()}openCommentModal(){this.saveSelection();let e=this._savedRange?.toString()||``,t=document.createElement(`mint-modal`);t.setAttribute(`heading`,`Add comment`),t.setAttribute(`size`,`small`);let n=document.createElement(`div`);n.setAttribute(`slot`,`body`),n.className=`mint-editor-modal-fields`;let r=document.createElement(`p`);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.`;let i=document.createElement(`textarea`);i.className=`mint-editor-comment-input`,i.setAttribute(`aria-label`,`Comment`),i.setAttribute(`placeholder`,`Write a comment…`),i.rows=4,n.append(r,i);let a=document.createElement(`div`);a.setAttribute(`slot`,`actions`),a.className=`mint-editor-modal-actions`;let o=document.createElement(`mint-button`);o.textContent=`Cancel`,o.setAttribute(`variant`,`ghost`),this.setTooltip(o,`Cancel`),o.addEventListener(`click`,()=>t.close());let s=document.createElement(`mint-button`);s.textContent=`Add comment`,s.setAttribute(`tone`,`action`),s.toggleAttribute(`disabled`,!e),this.setTooltip(s,`Add comment`),s.addEventListener(`click`,()=>{let n=i.value.trim();!n||!e||(this.insertComment(n,e),t.close())}),a.append(o,s),t.append(n,a),this.append(t),t.open()}insertComment(e,t){let n=this._savedRange;if(this.editor&&n&&!n.collapsed&&this.editor.contains(n.commonAncestorContainer)&&this.format===`html`){let t=this.editor.ownerDocument.createElement(`span`);t.className=`mint-editor-comment`,t.setAttribute(`data-mint-comment`,e),t.title=`Comment: ${e}`,t.append(n.extractContents()),n.insertNode(t);let r=this.selection;n.selectNodeContents(t),r?.removeAllRanges(),r?.addRange(n)}this.dispatchEvent(new CustomEvent(`mint-editor-comment-request`,{bubbles:!0,composed:!0,detail:{selectedText:t,comment:e,format:this.format}})),this.emitChange()}updateToolbarOverflow(){let e=this.toolbar,t=this.overflowTrigger,n=this.overflowPopover;if(!e||!t||!n)return;let r=e.querySelector(`.mint-editor-toolbar-actions`),i=this.blockButton;if(!r||!i)return;for(let e of this.overflowGroups)for(let t of e)r.append(t);t.hidden=!1;let a=this.overflowGroups.length-1,o=()=>{let e=[...r.children].filter(e=>e instanceof HTMLElement&&!e.matches(`mint-popover`)&&!e.hidden),t=Number.parseFloat(getComputedStyle(r).columnGap)||0;return e.reduce((e,t)=>e+t.getBoundingClientRect().width,0)+Math.max(0,e.length-1)*t};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--;t.hidden=n.childElementCount===0}clearFormatting(){!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())}icon(e){let t=document.createElement(`mint-icon`);return t.setAttribute(`name`,e),t.setAttribute(`aria-hidden`,`true`),t}setTooltip(e,t){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()))}updateTooltipLabel(e,t){e.setAttribute(`data-editor-tooltip`,t);let n=t.indexOf(`:`),r=n<0?t:`${t.slice(0,n+1)}\n${t.slice(n+1).trim()}`;e.setAttribute(`data-editor-overflow-label`,r),e.setAttribute(`aria-label`,t),e.removeAttribute(`title`)}showTooltip(e){if(e.closest(`.mint-editor-overflow-popover`)){this.hideTooltip();return}let t=e.getAttribute(`data-editor-tooltip`);if(!t||e.matches(`:disabled,[hidden]`))return;let n=this.tooltipPopup;if(!n){n=document.createElement(`div`),n.className=`mint-editor-tooltip-popup`,n.setAttribute(`role`,`tooltip`),n.setAttribute(`aria-hidden`,`true`);let e=getComputedStyle(this);[`text`,`surface`,`border`].forEach(t=>{let r=e.getPropertyValue(`--mint-color-${t}`).trim();r&&n.style.setProperty(`--mint-color-${t}`,r)}),document.body.append(n),this.tooltipPopup=n}n.textContent=t,n.setAttribute(`aria-hidden`,`false`),n.style.visibility=`hidden`,n.style.display=`block`;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);n.style.left=`${a}px`,n.style.top=`${o}px`,n.style.visibility=`visible`}hideTooltip(){this.tooltipPopup&&(this.tooltipPopup.style.display=`none`,this.tooltipPopup.setAttribute(`aria-hidden`,`true`))}closeEditorPopovers(){this.querySelectorAll(`mint-popover`).forEach(e=>{e.close?.call(e)})}createMenuOption(e,t){let n={"table-row":`table`,"table-column":`columns`,"table-row-delete":`remove`,"table-column-delete":`remove`,paragraph:`file-alt`,heading:`heading`},r=document.createElement(`button`);r.type=`button`,r.className=`mint-editor-menu-option`;let i=this.icon(n[t]||t);i.classList.add(`mint-editor-menu-icon`);let a=document.createElement(`span`);return a.className=`mint-editor-menu-label`,a.textContent=e,r.append(i,a),r}updateFormatUI(){if(this.source&&this.source.setAttribute(`aria-label`,`Editor ${this.format.toUpperCase()} source`),this.sourceButton){let e=`${this.format.toUpperCase()} source`,t=this.sourceButton.querySelector(`.mint-editor-button-label`);t&&(t.textContent=e),this.updateTooltipLabel(this.sourceButton,e)}}separator(){let e=document.createElement(`span`);return e.className=`mint-editor-separator`,e.setAttribute(`aria-hidden`,`true`),e}command(e,t){!this.editor||this.sourceMode||(this.editor.focus(),this.restoreSelection(),this.editor.ownerDocument.execCommand(e,!1,t),this.clearInlineTypingState(),this.emitChange(),this.updateSelectionUI())}toggleInline(e){if(!this.editor||this.sourceMode)return;this.editor.focus(),this.restoreSelection();let t=this.selection;if(!t?.rangeCount||!this.editor.contains(t.anchorNode))return;let n=t.getRangeAt(0),r=!this.inlineStateAtSelection(e,n),i=this.editor.ownerDocument;if(n.collapsed){this.inlineOverrides.set(e,r),this.preserveInlineOverridesOnNextEditorClick=!0,this.emitChange(),this.updateSelectionUI();return}this.clearInlineTypingState(),i.execCommand(e,!1),this.emitChange(),this.updateSelectionUI()}inlineStateAtSelection(e,t){let n=this.selection,r=this.inlineOverrides.get(e);if(t.collapsed&&r!==void 0)return r;let i=this.formatAtCaret(e,t);if(i||!t.collapsed)return i;let a=t.cloneRange(),o=t.startContainer,s=t.startOffset;if(o.nodeType!==Node.TEXT_NODE||s===0){let e=o.nodeType===Node.ELEMENT_NODE?o.childNodes[s-1]:null;if(e){for(o=e;o.lastChild;)o=o.lastChild;o.nodeType===Node.TEXT_NODE&&(s=o.textContent?.length||0)}}if(o.nodeType===Node.TEXT_NODE&&s>0)try{a.setStart(o,s-1),a.setEnd(o,s),n?.removeAllRanges(),n?.addRange(a),i=this.formatAtCaret(e,a)}catch{}finally{n?.removeAllRanges(),n?.addRange(t)}return i}applyInlineTypingState(e){if(e.inputType.startsWith(`insert`)&&(this.preserveInlineOverridesOnNextEditorClick=!1),e.inputType.startsWith(`delete`)){this.clearInlineTypingState();return}if(!this.editor||this.sourceMode||e.inputType!==`insertText`||!e.data||this.inlineOverrides.size===0&&this.inlineStyleOverrides.size===0)return;let t=this.selection;if(!t?.rangeCount||!t.isCollapsed||!this.editor.contains(t.anchorNode))return;let n=t.getRangeAt(0),r=this.editor.ownerDocument;e.preventDefault();let i=r.createTextNode(e.data),a=[`bold`,`italic`,`underline`].map(e=>{let t=this.formatAtCaret(e,n);return[e,this.inlineOverrides.has(e)?this.inlineOverrides.get(e):t,t]}),o=a.some(([e,t,n])=>e===`underline`&&!t&&n)?(n.startContainer.nodeType===Node.ELEMENT_NODE?n.startContainer:n.startContainer.parentElement)?.closest(`u`):null;for(let[e,t,n]of a.reverse()){if(t===n)continue;let a=t?e===`bold`?`strong`:e===`italic`?`em`:`u`:`span`,o=r.createElement(a);t||(e===`bold`?o.style.fontWeight=`normal`:e===`italic`?o.style.fontStyle=`normal`:o.style.textDecoration=`none`),o.append(i),i=o}if(this.inlineStyleOverrides.size){let e=r.createElement(`span`);this.inlineStyleOverrides.forEach((t,n)=>{e.style[n]=t}),e.append(i),i=e}if(n.deleteContents(),n.insertNode(i),o&&o.parentNode&&this.isAtEndOfInlineRun(i,o)){o.parentNode.insertBefore(i,o.nextSibling);for(let e=i.parentNode;e&&e!==o;){let t=e.parentNode;e instanceof HTMLElement&&!e.textContent?.length&&!e.querySelector(`img,br,table,hr,iframe,video,audio`)&&e.remove(),e=t}!o.textContent?.length&&!o.querySelector(`img,br,table,hr,iframe,video,audio`)&&o.remove()}let s=i;for(;s.lastChild;)s=s.lastChild;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`,{bubbles:!0,inputType:`insertText`,data:e.data}))}isAtEndOfInlineRun(e,t){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;return!0}formatAtCaret(e,t){let n=t.startContainer,r=n.nodeType===Node.ELEMENT_NODE?n:n.parentElement;if(t.collapsed&&n.nodeType===Node.ELEMENT_NODE&&t.startOffset>0){let e=n.childNodes[t.startOffset-1];for(;e?.lastChild;)e=e.lastChild;e?.nodeType===Node.TEXT_NODE?r=e.parentElement:e?.nodeType===Node.ELEMENT_NODE&&(r=e)}if(!r)return!1;let i=[];for(let e=r;e&&e!==this.editor;e=e.parentElement)i.push(e);for(let t of i){let n=t.style;if(e===`bold`){if(n.fontWeight){let e=Number.parseInt(n.fontWeight,10);return Number.isFinite(e)?e>=600:n.fontWeight===`bold`||n.fontWeight===`bolder`}if([`B`,`STRONG`].includes(t.tagName))return!0}else if(e===`italic`){if(n.fontStyle)return[`italic`,`oblique`].includes(n.fontStyle);if([`I`,`EM`].includes(t.tagName))return!0}else{if(n.textDecorationLine||n.textDecoration)return(n.textDecorationLine||n.textDecoration).includes(`underline`);if(t.tagName===`U`)return!0}}let a=getComputedStyle(r);if(e===`bold`){let e=Number.parseInt(a.fontWeight,10);return Number.isFinite(e)&&e>=600}return e===`italic`?[`italic`,`oblique`].includes(a.fontStyle):a.textDecorationLine.includes(`underline`)}requestResource(){this.saveSelection(),this.dispatchEvent(new CustomEvent(`mint-editor-resource-request`,{bubbles:!0,composed:!0,detail:{resourceType:`media`}}))}get selection(){return this.editor?.ownerDocument.getSelection()||null}saveSelection(){let e=this.selection;e?.rangeCount&&this.editor?.contains(e.anchorNode)&&(this._savedRange=e.getRangeAt(0).cloneRange())}restoreSelection(){let e=this._savedRange;if(!e)return;let t=this.selection;t?.removeAllRanges(),t?.addRange(e),this._savedRange=void 0}clearInlineTypingState(){this.inlineOverrides.clear(),this.inlineStyleOverrides.clear(),this.preserveInlineOverridesOnNextEditorClick=!1}cleanEditorCopy(){let e=this.editor?.cloneNode(!0);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`)}insertPastedHtml(e){let t=this.editor,n=this.selection;if(!t||!n?.rangeCount)return;let r=t.ownerDocument,i=n.getRangeAt(0);if(!t.contains(i.startContainer)||!t.contains(i.endContainer))return;let a=r.createElement(`div`);a.innerHTML=e;let o=r.createDocumentFragment();for(;a.firstChild;)o.append(a.firstChild);if(!o.hasChildNodes())return;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;if(c||l){t.replaceChildren(o),this.placeCaretAfterPastedContent(t.lastChild,n);return}i.deleteContents(),i.collapse(!0);let u=i.startContainer;if(u.nodeType!==Node.ELEMENT_NODE&&(u=u.parentNode||t),s){let e=(u.nodeType===Node.ELEMENT_NODE?u:u.parentElement)?.closest(`p,h1,h2,h3,h4,h5,h6,pre`);if(e&&t.contains(e)&&e.parentNode){let t=r.createRange();t.selectNodeContents(e),t.setStart(i.startContainer,i.startOffset);let a=t.extractContents(),s=e.parentNode,c=e.nextSibling,l=e.cloneNode(!1);l.append(a);let u=this.hasPastedBlockContent(e),d=this.hasPastedBlockContent(l);u||s.removeChild(e);let f=o.lastChild;s.insertBefore(o,c),d?s.insertBefore(l,c):l.remove(),this.placeCaretAfterPastedContent(f,n);return}}let d=o.lastChild;i.insertNode(o),this.placeCaretAfterPastedContent(d,n)}hasPastedBlockContent(e){return(e.textContent||``).replace(/\u00a0/g,` `).trim()?!0:!!e.querySelector(`img,table,hr,ul,ol,iframe,video,audio`)}placeCaretAfterPastedContent(e,t){if(!e?.parentNode)return;let n=this.editor?.ownerDocument.createRange();n&&(n.selectNodeContents(e),n.collapse(!1),t.removeAllRanges(),t.addRange(n),this.saveSelection())}sanitizePastedHtml(e){let t=this.editor?.ownerDocument,n=t?.defaultView?.DOMParser;if(!t||!n)return``;let r=new n().parseFromString(e,`text/html`),i=r.body,a=`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=>{let t=r.createElement(`span`);t.setAttribute(`style`,e);let n=new Map;for(let e of a){let r=t.style.getPropertyValue(e).trim();!r||/url\s*\(|expression\s*\(/i.test(r)||e.startsWith(`margin-`)&&Number.parseFloat(r)===0||n.set(e,r)}let i=e.match(/(?:^|;)\s*mso-(?:ansi|bidi)-font-size\s*:\s*([^;]+)/i)?.[1]?.trim();if(!n.has(`font-size`)&&i){t.style.setProperty(`font-size`,i);let e=t.style.getPropertyValue(`font-size`).trim();e&&!/url\s*\(|expression\s*\(/i.test(e)&&n.set(`font-size`,e)}let o=e.match(/(?:^|;)\s*mso-(?:ansi|bidi)-font-family\s*:\s*([^;]+)/i)?.[1]?.trim();if(!n.has(`font-family`)&&o){t.style.setProperty(`font-family`,o);let e=t.style.getPropertyValue(`font-family`).trim();e&&!/url\s*\(|expression\s*\(/i.test(e)&&n.set(`font-family`,e)}let s=e.match(/(?:^|;)\s*mso-highlight\s*:\s*([^;]+)/i)?.[1]?.trim();if(!n.has(`background-color`)&&s){t.style.backgroundColor=s;let e=t.style.backgroundColor.trim();e&&n.set(`background-color`,e)}return!n.has(`background-color`)&&t.style.backgroundColor&&n.set(`background-color`,t.style.backgroundColor),Array.from(n,([e,t])=>`${e}:${t}`).join(`;`)},s=(e,t)=>{let n=o([t,e.getAttribute(`style`)||``].filter(Boolean).join(`;`));n&&e.setAttribute(`style`,n)};for(let e of Array.from(r.querySelectorAll(`style`))){let t=e.textContent||``;for(let e of t.matchAll(/([^{}]+)\{([^{}]*)\}/g)){let t=e[2].trim();if(!(!t||!/\.(?:Mso|WordSection)/i.test(e[1])))for(let n of e[1].split(`,`)){let e=n.trim();if(/^(?:[a-z][\w-]*)?(?:\.[\w-]+)+$/i.test(e))try{r.querySelectorAll(e).forEach(e=>s(e,t))}catch{}}}}r.querySelectorAll(`style,script,iframe,object,embed,form,input,button,select,textarea,link,meta,base,svg,math,canvas,video,audio`).forEach(e=>e.remove());for(let e of Array.from(i.querySelectorAll(`font`))){let t=r.createElement(`span`),n=[],i=e.getAttribute(`face`),a=e.getAttribute(`color`),s=e.getAttribute(`size`),c={1:`8pt`,2:`10pt`,3:`12pt`,4:`14pt`,5:`18pt`,6:`24pt`,7:`36pt`};i&&n.push(`font-family:${i}`),a&&n.push(`color:${a}`),s&&c[s]&&n.push(`font-size:${c[s]}`);let l=e.getAttribute(`style`)||``,u=o([n.join(`;`),l].filter(Boolean).join(`;`));for(u&&t.setAttribute(`style`,u);e.firstChild;)t.append(e.firstChild);e.replaceWith(t)}for(let e of Array.from(i.querySelectorAll(`p,div`))){let t=e.getAttribute(`class`)||``,n=t.match(/MsoHeading([1-6])/i)?.[1]||(/MsoTitle/i.test(t)?`1`:/MsoSubtitle/i.test(t)?`2`:``);if(!n)continue;let i=r.createElement(`h${n}`);for(let t of Array.from(e.attributes))i.setAttribute(t.name,t.value);for(;e.firstChild;)i.append(e.firstChild);e.replaceWith(i)}let c=e=>{let t=r.createDocumentFragment(),n=null,i=``;for(let a of Array.from(e.childNodes))if(a.nodeType===Node.ELEMENT_NODE){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;if([`P`,`DIV`].includes(e.tagName)&&(/mso-list\s*:/i.test(l)||/MsoListParagraph/i.test(s)||u)){let a=(u?.textContent||e.textContent||``).replace(/\u00a0/g,` `).trim();u?.remove();let s=/^(?:\d+|[a-z]|[ivxlcdm]+)[.)]/i.test(a)?`ol`:`ul`;(!n||i!==s)&&(n=r.createElement(s),i=s,t.append(n));let c=r.createElement(`li`),d=o(l.replace(/(?:^|;)\s*mso-list\s*:[^;]*/gi,``));for(d&&c.setAttribute(`style`,d);e.firstChild;)c.append(e.firstChild);n.append(c);continue}if(n=null,i=``,c(e),e.tagName===`DIV`&&/WordSection/i.test(s))for(;e.firstChild;)t.append(e.firstChild);else t.append(e)}else a.nodeType===Node.TEXT_NODE&&!(a.textContent||``).trim()?n||t.append(a):(n=null,i=``,a.nodeType!==Node.COMMENT_NODE&&t.append(a));e.replaceChildren(t)};c(i);let l=e=>{e.replaceWith(...Array.from(e.childNodes))};for(let e of Array.from(i.querySelectorAll(`*`)))e.tagName.includes(`:`)&&l(e);let u=new Set([`href`,`src`,`alt`,`title`,`colspan`,`rowspan`,`start`,`value`,`type`,`width`,`height`,`border`,`cellpadding`,`cellspacing`,`scope`,`dir`]),d=(e,t=!1)=>{let n=e.trim();if(/^#[-\w:.]+$/.test(n)||t&&/^data:image\/(?:png|gif|jpe?g|webp);base64,/i.test(n))return!0;try{return[`http:`,`https:`,`mailto:`,`tel:`].includes(new URL(n,`https://mint.invalid`).protocol)}catch{return!1}};for(let e of Array.from(i.querySelectorAll(`*`)))for(let t of Array.from(e.attributes)){let n=t.name.toLowerCase();if(n===`style`){let n=o(t.value);n?e.setAttribute(`style`,n):e.removeAttribute(t.name)}else u.has(n)?((n===`href`||n===`src`)&&!d(t.value,n===`src`)||[`colspan`,`rowspan`,`start`,`value`,`width`,`height`,`border`,`cellpadding`,`cellspacing`].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)}for(let e of Array.from(i.querySelectorAll(`span`)))e.attributes.length||l(e);return i.innerHTML.trim()}syncSource(){if(this.source&&this.editor){let e=this.cleanEditorCopy();this.source.value=this.format===`markdown`?i(e):e.innerHTML,this.preservedContent=this.format===`markdown`?this.source.value:this.editor.innerHTML}this.updateWordCount()}emitChange(){this.syncSource();let e=this.value;this.dispatchEvent(new CustomEvent(`input`,{bubbles:!0,composed:!0,detail:{value:e}})),this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,composed:!0,detail:{value:e}}))}updateWordCount(){if(!this.editor||!this.count)return;let e=(this.editor.innerText||``).trim().split(/\s+/).filter(Boolean).length;this.count.textContent=`${e} ${e===1?`word`:`words`}`}updateSelectionUI(){if(!this.editor)return;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;this.selectTable(i&&this.editor.contains(i)?i:null);let a=this.sourceMode||!i;if(this.tableTrigger?.hidden!==a&&(this.tableTrigger?.toggleAttribute(`hidden`,a),this.updateToolbarOverflow()),this.sourceMode||!n)return;let o=r?.closest(`h1,h2,h3,h4,h5,h6,p,blockquote,div,li,td,th,pre`),s=o?.tagName.toLowerCase()||`p`,c={p:`Paragraph`,h1:`Heading 1`,h2:`Heading 2`,h3:`Heading 3`,h4:`Heading 4`,h5:`Heading 5`,h6:`Heading 6`,blockquote:`Quote`,div:`Div`,li:`List item`,td:`Table cell`,th:`Table header`,pre:`Code block`},l=[`h1`,`h2`,`h3`,`h4`,`h5`,`h6`,`blockquote`,`div`,`li`,`td`,`th`,`pre`].includes(s)?s:`p`;this.fontSizeDisplay&&(this.fontSizeDisplay.textContent=`${this.readFontSize()}px`);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`);p&&p.setAttribute(`name`,d),this.alignmentTrigger&&this.updateTooltipLabel(this.alignmentTrigger,`Text alignment: ${f}`);let m=this.toolbar?.querySelector(`.mint-editor-toolbar-checklist`);m?.classList.toggle(`is-active`,!!r?.closest(`ul[data-mint-task-list]`)),m?.setAttribute(`aria-pressed`,String(!!r?.closest(`ul[data-mint-task-list]`)));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`);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){let e=this.blockButton.querySelector(`.mint-editor-block-label`),t=c[l]||`Paragraph`;e&&(e.textContent=t),this.updateTooltipLabel(this.blockButton,`Text style: ${t}`)}this.footerMode&&(this.footerMode.textContent=s),this.blockPopover?.querySelectorAll(`[data-block-tag]`).forEach(e=>{let t=e.dataset.blockTag===l;e.toggleAttribute(`data-active`,t),e.setAttribute(`aria-pressed`,String(t))});for(let[t,n]of this.inlineButtons){let r=e?.rangeCount?e.getRangeAt(0):null,i=r?this.inlineStateAtSelection(t,r):!1;n.classList.toggle(`is-active`,i),n.setAttribute(`aria-pressed`,String(i))}}insertTable(e,t){if(!this.editor)return;let n=this.editor.ownerDocument,r=n.createElement(`table`);r.className=`mint-editor-table`;let i=n.createElement(`tbody`);for(let r=0;r<e;r++){let e=n.createElement(`tr`);for(let i=0;i<t;i++){let t=n.createElement(r===0?`th`:`td`);t.innerHTML=`<br>`,e.append(t)}i.append(e)}r.append(i),this.editor.focus(),this.restoreSelection();let a=this.selection;if(a?.rangeCount&&this.editor.contains(a.anchorNode)){let e=a.getRangeAt(0),t=(e.startContainer.nodeType===Node.ELEMENT_NODE?e.startContainer:e.startContainer.parentElement)?.closest(`a`);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)}else this.editor.append(r);this.emitChange()}openTableModal(){this.saveSelection();let e=document.createElement(`mint-modal`);e.setAttribute(`heading`,`Insert table`),e.setAttribute(`size`,`small`);let t=document.createElement(`div`);t.setAttribute(`slot`,`body`),t.className=`mint-editor-modal-fields`;let n=document.createElement(`mint-input`);n.setAttribute(`type`,`number`),n.setAttribute(`label`,`Rows`),n.setAttribute(`min`,`1`),n.setAttribute(`max`,`12`),n.setAttribute(`value`,`3`);let r=document.createElement(`mint-input`);r.setAttribute(`type`,`number`),r.setAttribute(`label`,`Columns`),r.setAttribute(`min`,`1`),r.setAttribute(`max`,`10`),r.setAttribute(`value`,`3`),t.append(n,r);let i=document.createElement(`div`);i.setAttribute(`slot`,`actions`),i.className=`mint-editor-modal-actions`;let a=document.createElement(`mint-button`);a.textContent=`Cancel`,a.setAttribute(`variant`,`ghost`),this.setTooltip(a,`Cancel`),a.addEventListener(`click`,()=>e.close());let o=document.createElement(`mint-button`);o.textContent=`Insert table`,o.setAttribute(`tone`,`action`),this.setTooltip(o,`Insert table`),o.addEventListener(`click`,()=>{let t=Math.max(1,Math.min(12,Number(n.value)||3)),i=Math.max(1,Math.min(10,Number(r.value)||3));e.close(),this.insertTable(t,i)}),i.append(a,o),e.append(t,i),this.append(e),e.open()}openLinkModal(){this.saveSelection();let e=document.createElement(`mint-modal`);e.setAttribute(`heading`,`Insert link`),e.setAttribute(`size`,`small`);let t=document.createElement(`div`);t.setAttribute(`slot`,`body`);let n=document.createElement(`mint-input`);n.setAttribute(`type`,`url`),n.setAttribute(`label`,`Link URL`),n.setAttribute(`placeholder`,`https://example.com`),t.append(n);let r=document.createElement(`div`);r.setAttribute(`slot`,`actions`),r.className=`mint-editor-modal-actions`;let i=document.createElement(`mint-button`);i.textContent=`Cancel`,i.setAttribute(`variant`,`ghost`),this.setTooltip(i,`Cancel`),i.addEventListener(`click`,()=>e.close());let a=document.createElement(`mint-button`);a.textContent=`Insert link`,a.setAttribute(`tone`,`action`),this.setTooltip(a,`Insert link`),a.addEventListener(`click`,()=>{let t=String(n.value||``).trim();t&&(this.command(`createLink`,t),e.close())}),r.append(i,a),e.append(t,r),this.append(e),e.open()}selectedTable(){let e=this._savedRange?.startContainer||this.selection?.anchorNode,t=(e?.nodeType===Node.ELEMENT_NODE?e:e?.parentElement)?.closest(`table`);return t&&this.editor?.contains(t)?t:null}applyTableAction(e){let t=this.selectedTable();if(!t)return;let n=this._savedRange,r=(n?.startContainer.nodeType===Node.ELEMENT_NODE?n.startContainer:n?.startContainer.parentElement)?.closest(`td,th`),i=r?.parentElement;if(e===`Add row below`||e===`Add row above`){let n=i?.cloneNode(!0);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))}if(e===`Add column right`||e===`Add column left`){let n=(r?Array.from(r.parentElement.children).indexOf(r):(t.querySelector(`tr`)?.children.length||1)-1)+(e===`Add column right`?1:0);t.querySelectorAll(`tr`).forEach(e=>{let r=e.querySelector(`th`)?`th`:`td`,i=t.ownerDocument.createElement(r);i.innerHTML=`<br>`,e.insertBefore(i,e.children[n]||null)})}if(e===`Delete row`&&i&&t.querySelectorAll(`tr`).length>1&&i.remove(),e===`Delete column`&&r&&r.parentElement.children.length>1){let e=Array.from(r.parentElement.children).indexOf(r);t.querySelectorAll(`tr`).forEach(t=>t.children[e]?.remove())}e===`Delete table`&&t.remove(),this.emitChange(),this.updateSelectionUI()}selectTable(e){this.selectedTableElement!==e&&this.selectedTableElement?.classList.remove(`is-selected`),this.selectedTableElement=e,e?.classList.add(`is-selected`);let t=!!e&&!this.sourceMode;this.inlineTableTools&&(this.inlineTableTools.hidden=!t),this.tableResizeHandle&&(this.tableResizeHandle.hidden=!t),t&&this.positionTableTools()}positionTableTools(){let e=this.selectedTableElement,t=this.querySelector(`.mint-editor-shell`),n=this.editorFrame;if(!e||!t||!n||!this.inlineTableTools||!this.tableResizeHandle||this.sourceMode)return;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);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`}startTableResize(e){let t=this.selectedTableElement;if(!t)return;e.preventDefault(),e.stopPropagation();let n=t.getBoundingClientRect();this.tableResizeState={table:t,startX:e.clientX,startY:e.clientY,startWidth:n.width,startHeight:n.height,pointerId:e.pointerId},this.ownerDocument.defaultView?.addEventListener(`pointermove`,this.onTableResizeMove),this.ownerDocument.defaultView?.addEventListener(`pointerup`,this.onTableResizeEnd)}startGridResize(e){let t=e.target?.closest(`td,th`),n=t?.closest(`table`);if(!t||!n||!this.editor?.contains(n))return;let r=t.getBoundingClientRect(),i=Math.abs(e.clientX-r.right)<=7,a=Math.abs(e.clientY-r.bottom)<=7;if(!i&&!a)return;let o=t.parentElement,s=Array.from(n.rows).indexOf(o);if(a)this.gridResizeState={table:n,kind:`row`,index:s,start:e.clientY,size:o.getBoundingClientRect().height,pointerId:e.pointerId};else{let i=Array.from(o.cells).indexOf(t);this.ensureTableColumns(n);let a=n.querySelectorAll(`col`)[i];this.gridResizeState={table:n,kind:`column`,index:i,start:e.clientX,size:a?.getBoundingClientRect().width||r.width,pointerId:e.pointerId}}e.preventDefault(),e.stopPropagation();let c=this.editor?.ownerDocument.defaultView;c?.addEventListener(`pointermove`,this.onGridResizeMove),c?.addEventListener(`pointerup`,this.onGridResizeEnd),c?.addEventListener(`pointercancel`,this.onGridResizeEnd)}updateGridResizeCursor(e){let t=this.editor;if(!t||this.gridResizeState)return;let n=e.target?.closest(`td,th`);if(!n){t.style.cursor=``;return}let r=n.getBoundingClientRect(),i=Math.abs(e.clientX-r.right)<=7,a=Math.abs(e.clientY-r.bottom)<=7;t.style.cursor=i&&a?`nwse-resize`:i?`col-resize`:a?`row-resize`:``}ensureTableColumns(e){let t=e.querySelector(`colgroup`);t||(t=e.ownerDocument.createElement(`colgroup`),e.insertBefore(t,e.firstChild));let n=Math.max(1,...Array.from(e.rows,e=>e.cells.length));for(;t.children.length<n;)t.append(e.ownerDocument.createElement(`col`))}toggleSource(){if(!(!this.editor||!this.source)){if(this.sourceMode=!this.sourceMode,this.clearInlineTypingState(),this.source.hidden=!this.sourceMode,this.editor.hidden=this.sourceMode,this.sourceMode){let e=this.cleanEditorCopy();this.source.value=this.format===`markdown`?i(e):e.innerHTML}else this.editor.innerHTML=this.format===`markdown`?n(this.source.value):this.source.value;this.toolbar?.classList.toggle(`mint-editor-source-active`,this.sourceMode),this.updateWordCount(),this.sourceMode?this.selectTable(null):this.updateSelectionUI()}}createResizeHandle(){let e=(this.editor?.ownerDocument||document).createElement(`button`);return e.type=`button`,e.className=`mint-editor-resize-handle`,this.setTooltip(e,`Resize image`),e.addEventListener(`pointerdown`,t=>{t.preventDefault(),t.stopPropagation();let n=e.parentElement;this.resizeState={frame:n,startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},this.editor?.ownerDocument.defaultView?.addEventListener(`pointermove`,this.onResizeMove),this.editor?.ownerDocument.defaultView?.addEventListener(`pointerup`,this.onResizeEnd)}),e}selectImage(e){this.selectedImage?.classList.remove(`is-selected`),this.selectedImage=e,e?.classList.add(`is-selected`);let t=this.querySelector(`.mint-editor-image-tools`);t&&(t.hidden=!e);let n=t?.querySelector(`mint-input`);e&&n&&(n.value=`${Math.round(e.getBoundingClientRect().width/Math.max(1,this.editor?.clientWidth||e.getBoundingClientRect().width)*100)}`)}updateSelectedImage(){let e=this.selection?.anchorNode,t=e?.nodeType===Node.ELEMENT_NODE?e.closest(`.mint-editor-image-frame`):e?.parentElement?.closest(`.mint-editor-image-frame`);t&&this.selectImage(t)}};customElements.get(`mint-editor`)||e.t(`mint-editor`,a),module.exports=a;
|