@editora/plugins 1.0.13 → 1.0.15

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/code.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- class z {
1
+ class V {
2
2
  constructor(e = "") {
3
3
  this._lines = [], this._version = 0, this.setText(e);
4
4
  }
@@ -84,7 +84,7 @@ class z {
84
84
  }
85
85
  // Clone the model
86
86
  clone() {
87
- const e = new z();
87
+ const e = new V();
88
88
  return e._lines = [...this._lines], e._version = this._version, e;
89
89
  }
90
90
  normalizeRange(e) {
@@ -99,7 +99,7 @@ class z {
99
99
  }
100
100
  class Q {
101
101
  constructor(e) {
102
- this.gutterWidth = 50, this.lineHeight = 21, this.trailingNewlineMarkerAttr = "data-lce-trailing-newline-marker", this.foldPlaceholderAttr = "data-lce-fold-placeholder", this.virtualMarkerRegex = /[\u200B\uE000]/, this.virtualMarkerGlobalRegex = /[\u200B\uE000]/g, this.lastLineCount = 0, this.lastHighlightHTML = "", this.highlightOverlayActive = !1, this.lastLineDecorationSnapshot = "", this.lastGutterDecorationSnapshot = "", this.container = e, this.createDOM();
102
+ this.gutterWidth = 50, this.gutterFoldColumnWidth = 20, this.gutterFoldColumnGap = 4, this.gutterLineNumberPaddingLeft = 8, this.gutterLineNumberPaddingRight = 4, this.gutterDigitWidth = 9, this.lineHeight = 21, this.trailingNewlineMarkerAttr = "data-lce-trailing-newline-marker", this.foldPlaceholderAttr = "data-lce-fold-placeholder", this.virtualMarkerRegex = /[\u200B\uE000]/, this.virtualMarkerGlobalRegex = /[\u200B\uE000]/g, this.lastLineCount = 0, this.lastHighlightHTML = "", this.highlightOverlayActive = !1, this.lastLineDecorationSnapshot = "", this.lastGutterDecorationSnapshot = "", this.container = e, this.createDOM();
103
103
  }
104
104
  createDOM() {
105
105
  this.container.innerHTML = "";
@@ -114,20 +114,20 @@ class Q {
114
114
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
115
115
  font-size: 14px;
116
116
  line-height: ${this.lineHeight}px;
117
- /* vertical scrolling is shared; horizontal scrolling belongs to the code pane */
118
- overflow-x: hidden;
119
- overflow-y: auto;
117
+ overflow: auto;
120
118
  `, this.lineNumbersElement = document.createElement("div"), this.lineNumbersElement.setAttribute("data-editor-gutter", "true"), this.lineNumbersElement.style.cssText = `
121
119
  display: table-cell;
122
120
  vertical-align: top;
123
121
  position: sticky;
124
122
  left: 0;
125
123
  width: ${this.gutterWidth}px;
124
+ min-width: ${this.gutterWidth}px;
126
125
  background: var(--editor-gutter-background, #252526);
127
126
  color: var(--editor-gutter-foreground, #858585);
128
- padding: 0 8px 0 0;
127
+ padding: 0;
129
128
  text-align: right;
130
129
  border-right: 1px solid var(--editor-gutter-border, #3e3e42);
130
+ box-sizing: border-box;
131
131
  background-clip: padding-box;
132
132
  user-select: none;
133
133
  overflow: hidden;
@@ -135,6 +135,8 @@ class Q {
135
135
  `, this.lineNumbersContentElement = document.createElement("div"), this.lineNumbersContentElement.setAttribute("data-editor-gutter-content", "true"), this.lineNumbersContentElement.style.cssText = `
136
136
  position: relative;
137
137
  z-index: 1;
138
+ box-sizing: border-box;
139
+ padding: 0 ${this.gutterFoldColumnWidth + this.gutterFoldColumnGap}px 0 ${this.gutterLineNumberPaddingLeft}px;
138
140
  `, this.gutterDecorationsElement = document.createElement("div"), this.gutterDecorationsElement.setAttribute("data-editor-gutter-decorations", "true"), this.gutterDecorationsElement.setAttribute("aria-hidden", "true"), this.gutterDecorationsElement.style.cssText = `
139
141
  position: absolute;
140
142
  inset: 0;
@@ -147,6 +149,7 @@ class Q {
147
149
  vertical-align: top;
148
150
  position: relative;
149
151
  width: 100%;
152
+ min-width: max-content;
150
153
  min-height: 400px;
151
154
  `, this.highlightElement = document.createElement("div"), this.highlightElement.setAttribute("data-editor-highlight", "true"), this.highlightElement.setAttribute("aria-hidden", "true"), this.highlightElement.style.cssText = `
152
155
  position: absolute;
@@ -170,14 +173,16 @@ class Q {
170
173
  `, this.contentElement = document.createElement("div"), this.contentElement.style.cssText = `
171
174
  position: relative;
172
175
  z-index: 1;
176
+ display: block;
177
+ box-sizing: border-box;
173
178
  padding: 0 12px;
174
179
  background: transparent;
175
180
  border: none;
176
181
  outline: none;
177
182
  white-space: pre;
178
- overflow-x: auto;
179
- overflow-y: visible;
183
+ overflow: visible;
180
184
  width: 100%;
185
+ min-width: max-content;
181
186
  min-height: 400px;
182
187
  font-family: inherit;
183
188
  font-size: inherit;
@@ -191,18 +196,25 @@ class Q {
191
196
  this.scrollWrapper = i, i.setAttribute("data-editora-editor", "true"), i.style.cssText = `
192
197
  position: relative;
193
198
  display: table;
194
- table-layout: fixed;
199
+ table-layout: auto;
195
200
  width: 100%;
201
+ min-width: 100%;
196
202
  height: 100%;
197
203
  `, this.lineNumbersElement.appendChild(this.lineNumbersContentElement), this.lineNumbersElement.appendChild(this.gutterDecorationsElement), i.appendChild(this.lineNumbersElement), t.appendChild(this.lineDecorationsElement), t.appendChild(this.highlightElement), t.appendChild(this.contentElement), i.appendChild(t), e.appendChild(i), this.container.appendChild(e), this.updateLineNumbers(1);
198
204
  }
199
205
  // Update line numbers
200
206
  updateLineNumbers(e) {
201
- if (e === this.lastLineCount)
207
+ if (this.updateGutterWidth(e), e === this.lastLineCount)
202
208
  return;
203
209
  this.lastLineCount = e;
204
210
  const t = Math.max(e, 1), i = Array.from({ length: t }, (s, n) => n + 1);
205
- this.lineNumbersContentElement.innerHTML = i.map((s) => `<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${s}</div>`).join("");
211
+ this.lineNumbersContentElement.innerHTML = i.map((s) => `<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px;">${s}</div>`).join("");
212
+ }
213
+ updateGutterWidth(e) {
214
+ const t = String(Math.max(e, 1)).length * this.gutterDigitWidth + this.gutterLineNumberPaddingLeft + this.gutterLineNumberPaddingRight, i = Math.ceil(
215
+ t + this.gutterFoldColumnGap + this.gutterFoldColumnWidth
216
+ );
217
+ i !== this.gutterWidth && (this.gutterWidth = i, this.lineNumbersElement.style.display !== "none" && (this.lineNumbersElement.style.width = `${this.gutterWidth}px`, this.lineNumbersElement.style.minWidth = `${this.gutterWidth}px`));
206
218
  }
207
219
  setDecorations(e, t) {
208
220
  this.renderLineDecorations(e), this.renderGutterDecorations(t);
@@ -246,10 +258,10 @@ class Q {
246
258
  this.updateLineNumbers(t);
247
259
  }
248
260
  setLineWrapping(e) {
249
- this.contentElement.style.whiteSpace = e ? "pre-wrap" : "pre", this.contentElement.style.overflowX = e ? "hidden" : "auto", this.contentElement.style.overflowY = "visible", this.contentElement.style.wordBreak = "normal", this.contentElement.style.overflowWrap = e ? "anywhere" : "normal", this.highlightElement.style.whiteSpace = e ? "pre-wrap" : "pre", this.highlightElement.style.wordBreak = "normal", this.highlightElement.style.overflowWrap = e ? "anywhere" : "normal";
261
+ this.contentElement.style.whiteSpace = e ? "pre-wrap" : "pre", this.contentElement.style.overflow = "visible", this.contentElement.style.minWidth = e ? "100%" : "max-content", this.contentSurface.style.minWidth = e ? "100%" : "max-content", this.contentElement.style.wordBreak = "normal", this.contentElement.style.overflowWrap = e ? "anywhere" : "normal", this.highlightElement.style.whiteSpace = e ? "pre-wrap" : "pre", this.highlightElement.style.wordBreak = "normal", this.highlightElement.style.overflowWrap = e ? "anywhere" : "normal";
250
262
  }
251
263
  setLineNumbersVisible(e) {
252
- this.lineNumbersElement.style.display = e ? "table-cell" : "none", this.lineNumbersElement.style.width = e ? `${this.gutterWidth}px` : "0", this.lineNumbersElement.style.paddingRight = e ? "8px" : "0", this.lineNumbersElement.style.borderRightWidth = e ? "1px" : "0", this.scrollWrapper.style.width = e ? "100%" : "auto";
264
+ this.lineNumbersElement.style.display = e ? "table-cell" : "none", this.lineNumbersElement.style.width = e ? `${this.gutterWidth}px` : "0", this.lineNumbersElement.style.minWidth = e ? `${this.gutterWidth}px` : "0", this.lineNumbersElement.style.borderRightWidth = e ? "1px" : "0", this.scrollWrapper.style.width = "100%", this.scrollWrapper.style.minWidth = "100%";
253
265
  }
254
266
  setTabSize(e) {
255
267
  const t = Math.max(1, Math.floor(e) || 2);
@@ -446,8 +458,8 @@ class Q {
446
458
  }
447
459
  // Scroll to position
448
460
  scrollToPosition(e) {
449
- const t = this.lineNumbersElement.children[e.line];
450
- t && t.scrollIntoView({ block: "center", behavior: "smooth" });
461
+ const t = Math.max(0, Math.floor(e.line) || 0) * this.lineHeight - this.editorContainer.clientHeight / 2 + this.lineHeight / 2;
462
+ this.editorContainer.scrollTop = Math.max(0, t);
451
463
  }
452
464
  // Get scroll position
453
465
  getScrollTop() {
@@ -479,7 +491,7 @@ class Q {
479
491
  const t = this.getCaretClientRect(e);
480
492
  if (!t) return;
481
493
  const i = this.editorContainer.getBoundingClientRect(), s = 12;
482
- t.bottom > i.bottom - s ? this.editorContainer.scrollTop += t.bottom - (i.bottom - s) : t.top < i.top + s && (this.editorContainer.scrollTop -= i.top + s - t.top);
494
+ t.bottom > i.bottom - s ? this.editorContainer.scrollTop += t.bottom - (i.bottom - s) : t.top < i.top + s && (this.editorContainer.scrollTop -= i.top + s - t.top), t.right > i.right - s ? this.editorContainer.scrollLeft += t.right - (i.right - s) : t.left < i.left + s && (this.editorContainer.scrollLeft -= i.left + s - t.left);
483
495
  }
484
496
  // Destroy the view
485
497
  destroy() {
@@ -807,7 +819,7 @@ class Q {
807
819
  }
808
820
  }
809
821
  let X = 0;
810
- const U = class O {
822
+ const W = class O {
811
823
  constructor(e, t = {}) {
812
824
  this.extensions = /* @__PURE__ */ new Map(), this.commands = /* @__PURE__ */ new Map(), this.eventListeners = /* @__PURE__ */ new Map(), this.folds = [], this.currentTheme = "default", this.isDestroyed = !1, this.undoStack = [], this.redoStack = [], this.suppressHistory = !1, this.highlightTimeout = null, this.expectingProgrammaticCursor = !1, this.lastKnownCursor = { line: 0, column: 0 }, this.editorInstanceId = ++X, this.decorationHighlightStyleId = `editora-decoration-style-${this.editorInstanceId}`, this.decorationHighlightLimit = 1e3, this.decorationLayers = /* @__PURE__ */ new Map(), this.inlineDecorationHighlightNames = /* @__PURE__ */ new Set(), this.decorationRenderRaf = null, this.decorationMutationObserver = null, this.hasCustomDecorationHighlightSupport = !1, this.lastProgrammaticClipboardInsertAt = 0, this.config = {
813
825
  value: "",
@@ -817,7 +829,7 @@ const U = class O {
817
829
  lineWrapping: !1,
818
830
  lineNumbers: !0,
819
831
  ...t
820
- }, this.textModel = new z(this.config.value), this.view = new Q(e), this.view.setTabSize(this.config.tabSize || 2), this.view.setLineWrapping(!!this.config.lineWrapping), this.view.setLineNumbersVisible(this.config.lineNumbers !== !1), this.hasCustomDecorationHighlightSupport = this.detectCustomHighlightSupport(), this.observeDecorationRelevantMutations(), this.setupEventHandlers(), this.config.extensions && this.config.extensions.forEach((i) => this.addExtension(i)), this.setTheme(this.config.theme), this.view.setReadOnly(this.config.readOnly || !1), this.renderTextWithHighlight(this.textModel.getText()), this.registerBuiltInCommands();
832
+ }, this.textModel = new V(this.config.value), this.view = new Q(e), this.view.setTabSize(this.config.tabSize || 2), this.view.setLineWrapping(!!this.config.lineWrapping), this.view.setLineNumbersVisible(this.config.lineNumbers !== !1), this.hasCustomDecorationHighlightSupport = this.detectCustomHighlightSupport(), this.observeDecorationRelevantMutations(), this.setupEventHandlers(), this.config.extensions && this.config.extensions.forEach((i) => this.addExtension(i)), this.setTheme(this.config.theme), this.view.setReadOnly(this.config.readOnly || !1), this.renderTextWithHighlight(this.textModel.getText()), this.registerBuiltInCommands();
821
833
  }
822
834
  // Public accessors for extensions
823
835
  getTextModel() {
@@ -1740,8 +1752,8 @@ const U = class O {
1740
1752
  };
1741
1753
  }
1742
1754
  };
1743
- U.CURSOR_SENTINEL = "";
1744
- let Y = U;
1755
+ W.CURSOR_SENTINEL = "";
1756
+ let Y = W;
1745
1757
  class J {
1746
1758
  constructor(e) {
1747
1759
  this.name = "keymap", this.editor = null, this.keymap = {}, this.isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0, this.keymap = e || this.getDefaultKeymap();
@@ -1816,7 +1828,7 @@ class J {
1816
1828
  this.keymap = {}, this.editor = null;
1817
1829
  }
1818
1830
  }
1819
- const W = class V {
1831
+ const U = class z {
1820
1832
  constructor() {
1821
1833
  this.name = "transaction", this.transactions = [];
1822
1834
  }
@@ -1828,9 +1840,9 @@ const W = class V {
1828
1840
  effects: [],
1829
1841
  annotations: []
1830
1842
  };
1831
- this.transactions.push(i), this.transactions.length > V.MAX_TRANSACTIONS && this.transactions.splice(
1843
+ this.transactions.push(i), this.transactions.length > z.MAX_TRANSACTIONS && this.transactions.splice(
1832
1844
  0,
1833
- this.transactions.length - V.MAX_TRANSACTIONS
1845
+ this.transactions.length - z.MAX_TRANSACTIONS
1834
1846
  );
1835
1847
  });
1836
1848
  }
@@ -1841,8 +1853,8 @@ const W = class V {
1841
1853
  this.transactions = [];
1842
1854
  }
1843
1855
  };
1844
- W.MAX_TRANSACTIONS = 200;
1845
- let ee = W;
1856
+ U.MAX_TRANSACTIONS = 200;
1857
+ let ee = U;
1846
1858
  class te {
1847
1859
  constructor() {
1848
1860
  this.name = "line-numbers", this.editor = null, this.lineNumbersElement = null, this.isEnabled = !0;
@@ -2736,12 +2748,10 @@ class ae {
2736
2748
  }
2737
2749
  createFoldingUI() {
2738
2750
  if (!this.editor) return;
2739
- const e = this.editor.getView().getContentElement().closest(
2740
- '[data-lce-editor-container="true"]'
2741
- );
2751
+ const e = this.editor.getView().getLineNumbersElement();
2742
2752
  e && (this.foldingUI = document.createElement("div"), this.foldingUI.setAttribute("data-lce-folding-ui", "true"), this.foldingUI.style.cssText = `
2743
2753
  position: absolute;
2744
- left: 0;
2754
+ right: 0;
2745
2755
  top: 0;
2746
2756
  bottom: 0;
2747
2757
  width: 20px;
@@ -2990,31 +3000,50 @@ class ae {
2990
3000
  }), s;
2991
3001
  }
2992
3002
  toggleFold(e) {
2993
- this.editor && (this.isFoldActive(e) ? this.editor.unfold(e) : this.editor.fold(e), this.syncFoldingState());
3003
+ this.editor && (this.isFoldActive(e) ? this.editor.unfold(e) : this.editor.fold(e), this.syncFoldingStatePreservingScroll());
2994
3004
  }
2995
3005
  foldAtCursor() {
2996
3006
  if (!this.editor) return;
2997
3007
  const e = this.editor.getCursor().position.line, t = this.findBestRegionForLine(e, !1);
2998
- t && (this.editor.fold(t), this.syncFoldingState());
3008
+ t && (this.editor.fold(t), this.syncFoldingStatePreservingScroll());
2999
3009
  }
3000
3010
  unfoldAtCursor() {
3001
3011
  if (!this.editor) return;
3002
3012
  const e = this.editor.getCursor().position.line, t = this.findBestRegionForLine(e, !0);
3003
- t && (this.editor.unfold(t), this.syncFoldingState());
3013
+ t && (this.editor.unfold(t), this.syncFoldingStatePreservingScroll());
3004
3014
  }
3005
3015
  foldAll() {
3006
3016
  if (!this.editor) return;
3007
3017
  const e = this.getTopLevelFoldRegions(this.foldRegions);
3008
3018
  for (const t of e)
3009
3019
  this.editor.fold(t);
3010
- this.syncFoldingState();
3020
+ this.syncFoldingStatePreservingScroll();
3011
3021
  }
3012
3022
  unfoldAll() {
3013
3023
  if (!this.editor) return;
3014
3024
  const e = this.getActiveFolds();
3015
3025
  for (const t of e)
3016
3026
  this.editor.unfold(t);
3017
- this.syncFoldingState();
3027
+ this.syncFoldingStatePreservingScroll();
3028
+ }
3029
+ syncFoldingStatePreservingScroll() {
3030
+ this.withPreservedScroll(() => {
3031
+ this.syncFoldingState();
3032
+ });
3033
+ }
3034
+ withPreservedScroll(e) {
3035
+ const t = this.editor?.getView().getScrollElement();
3036
+ if (!t) {
3037
+ e();
3038
+ return;
3039
+ }
3040
+ const i = t.scrollLeft, s = t.scrollTop;
3041
+ e(), this.restoreScrollPosition(t, i, s);
3042
+ }
3043
+ restoreScrollPosition(e, t, i) {
3044
+ e.scrollLeft = t, e.scrollTop = i, requestAnimationFrame(() => {
3045
+ e.isConnected && (e.scrollLeft = t, e.scrollTop = i);
3046
+ });
3018
3047
  }
3019
3048
  applyFoldedDisplay() {
3020
3049
  if (!this.editor) return;
@@ -3550,7 +3579,7 @@ class he {
3550
3579
  v.startsWith("&quot;") && v.endsWith("&quot;") ? (I = v.slice(6, -6), S = "&quot;") : v.startsWith("&#39;") && v.endsWith("&#39;") && (I = v.slice(5, -5), S = "&#39;");
3551
3580
  let w = v;
3552
3581
  if (L === "style") {
3553
- const D = I.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, (N, M, A, $) => `<span style="color: ${i.styleProp};">${M}</span>:<span style="color: ${i.styleVal};">${A}</span>${$}`);
3582
+ const D = I.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, (N, M, F, $) => `<span style="color: ${i.styleProp};">${M}</span>:<span style="color: ${i.styleVal};">${F}</span>${$}`);
3554
3583
  S ? w = `${S}${D}${S}` : w = D, w = `<span style="color: ${i.attrValue};">${w}</span>`;
3555
3584
  } else
3556
3585
  S && (w = `${S}${I}${S}`), w = `<span style="color: ${i.attrValue};">${w}</span>`;
@@ -4409,11 +4438,11 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
4409
4438
  ".rte-source-editor-btn-save"
4410
4439
  ), D = R.querySelector(
4411
4440
  ".unsaved-changes"
4412
- ), N = [], M = (y, k, P, F) => {
4413
- y.addEventListener(k, P, F), N.push(
4414
- () => y.removeEventListener(k, P, F)
4441
+ ), N = [], M = (y, k, P, A) => {
4442
+ y.addEventListener(k, P, A), N.push(
4443
+ () => y.removeEventListener(k, P, A)
4415
4444
  );
4416
- }, A = (y) => {
4445
+ }, F = (y) => {
4417
4446
  d !== y && (d = y, D && (D.style.display = d ? "inline" : "none"));
4418
4447
  }, $ = () => {
4419
4448
  if (!c) {
@@ -4469,7 +4498,7 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
4469
4498
  const y = o?.getValue() || "", k = document.createElement("div");
4470
4499
  k.innerHTML = y, k.querySelectorAll(
4471
4500
  'script, iframe[src^="javascript:"], object, embed'
4472
- ).forEach((F) => F.remove()), e.innerHTML = k.innerHTML;
4501
+ ).forEach((A) => A.remove()), e.innerHTML = k.innerHTML;
4473
4502
  try {
4474
4503
  e.dispatchEvent(
4475
4504
  new InputEvent("input", {
@@ -4485,7 +4514,7 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
4485
4514
  }
4486
4515
  e.dispatchEvent(
4487
4516
  new Event("change", { bubbles: !0 })
4488
- ), A(!1), $();
4517
+ ), F(!1), $();
4489
4518
  } catch (y) {
4490
4519
  alert("Failed to update HTML. Please check your syntax."), console.error("HTML update error:", y);
4491
4520
  }
@@ -4513,7 +4542,7 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
4513
4542
  ]
4514
4543
  }), o.on("change", () => {
4515
4544
  const y = o?.getValue() || "";
4516
- A(y !== r);
4545
+ F(y !== r);
4517
4546
  }), requestAnimationFrame(() => o?.focus());
4518
4547
  } catch (y) {
4519
4548
  console.error("Failed to initialize code editor:", y);
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const E='.rte-content, .editora-content, [contenteditable="true"]',st="[data-editora-editor], .rte-editor, .editora-editor, editora-editor",N="p,div,li,h1,h2,h3,h4,h5,h6,blockquote,pre,td,th",_="ul,ol",y="b,strong,i,em,u,s,strike,font,span",w="td,th",d="data-editora-format-painter-bookmark",O=["link","address","comments","citations","track-changes"],L=["fontFamily","fontSize","color","backgroundColor","textTransform"],at=["textAlign","lineHeight","marginLeft","marginRight"],lt=["listStyleType"],ct=["borderCollapse","borderSpacing","width"],ut=["backgroundColor","textAlign","verticalAlign","borderTopColor","borderRightColor","borderBottomColor","borderLeftColor","borderTopStyle","borderRightStyle","borderBottomStyle","borderLeftStyle","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","paddingTop","paddingRight","paddingBottom","paddingLeft"],X={background:"backgroundcolor",bgcolor:"backgroundcolor",blockquote:"block",blocks:"block",font:"fontfamily",fontname:"fontfamily",fontsize:"fontsize",foreground:"color",forecolor:"color",heading:"block",headings:"block",liststyle:"list",lists:"list",strike:"strikethrough",tablecell:"table",tablecells:"table",textcolor:"color",texttransform:"texttransform"},ft='<svg width="24" height="24" focusable="false" viewBox="0 0 24 24"><path d="M17.8 3.2a2.8 2.8 0 0 1 4 4L14 15l-4-4 7.8-7.8Zm-1.4 4.2L19 10l1.4-1.4-2.6-2.6-1.4 1.4Zm-7.8 5 3 3-1.4 1.4c-.5.5-1.2.8-1.9.8H7.2l-1.6 1.6a2.7 2.7 0 0 1-3.8 0 1 1 0 0 1 0-1.4l6.8-5.4Zm-.2 3.2H9l-4.6 3.7c.2 0 .5-.2.7-.4l1.9-1.9c.2-.2.4-.3.7-.3h1.1c.2 0 .5-.1.6-.3l.2-.2-1.2-1.3ZM5.5 3l.7 1.8L8 5.5l-1.8.7L5.5 8l-.7-1.8L3 5.5l1.8-.7L5.5 3Zm3.8 4.4.5 1.2 1.2.5-1.2.5-.5 1.2-.5-1.2-1.2-.5 1.2-.5.5-1.2Z" fill-rule="evenodd"></path></svg>',v=new WeakMap;let I=null,P=!1,p={ignoredFormats:O,keepActiveAfterMouseApply:!1};const dt=(t={})=>{const e={ignoredFormats:t.ignoredFormats??O,keepActiveAfterMouseApply:t.keepActiveAfterMouseApply??!1};return p=e,{name:"formatPainter",toolbar:[{label:"Format Painter",command:"toggleFormatPainter",icon:ft,shortcut:"Ctrl+Alt+C / Ctrl+Alt+V"}],commands:{retrieveFormats:(n,r)=>Y(r,e),paintFormats:(n,r)=>J(r,e),toggleFormatPainter:(n,r)=>mt(r,e),cancelFormatPainter:(n,r)=>j(r)},initialize:()=>{gt()}}};function Y(t,e=p){const n=C(t);if(!n)return!1;const r=U(n,e);if(!r)return!1;const o=g(n);return o.options=e,o.snapshot=r,I=r,M(n,!1),!0}function J(t,e=p){const n=C(t);if(!n)return!1;const r=g(n);r.options=e;const o=r.snapshot||I;return o?Q(n,o):!1}function mt(t,e=p){const n=C(t);if(!n)return!1;const r=g(n);if(r.options=e,r.active)return h(n,!1),!0;const o=U(n,e);return o?(r.snapshot=o,I=o,h(n,!0),!0):!1}function j(t){const e=C(t);return e?(h(e,!1),!0):(document.querySelectorAll(`${E}.rte-format-painter-active`).forEach(n=>{h(n,!1)}),!0)}function gt(){P||typeof document>"u"||(P=!0,document.addEventListener("keydown",Et,!0),document.addEventListener("mouseup",ht,!0))}function Et(t){const e=t.key.toLowerCase(),n=t.ctrlKey||t.metaKey;if(t.key==="Escape"){j();return}if(!n||!t.altKey||t.shiftKey)return;const r=G()||C();if(r){if(e==="c"){Y({contentElement:r},g(r).options)&&t.preventDefault();return}e==="v"&&J({contentElement:r},g(r).options)&&t.preventDefault()}}function ht(t){const e=t.target;if(e?.closest(".rte-toolbar-wrapper, .editora-toolbar-container"))return;const n=e?.closest(E);if(!(n instanceof HTMLElement))return;const r=g(n);if(!r.active||!r.snapshot)return;const o=window.getSelection();if(!o||o.rangeCount===0||o.getRangeAt(0).collapsed)return;Q(n,r.snapshot)&&!r.options.keepActiveAfterMouseApply&&h(n,!1)}function g(t){let e=v.get(t);return e||(e={snapshot:null,active:!1,options:p},v.set(t,e)),e}function C(t){if(t?.contentElement instanceof HTMLElement)return t.contentElement;const e=D(t?.editorElement??null);if(e)return e;const n=typeof window<"u"?window.__editoraCommandEditorRoot:null,r=D(n);return r||G()||pt()}function D(t){return t?t.matches(E)?t:t.querySelector(E):null}function G(){const t=window.getSelection();if(!t||t.rangeCount===0)return null;const e=t.getRangeAt(0),r=f(e.commonAncestorContainer)?.closest(E);return r instanceof HTMLElement?r:null}function pt(){const t=document.activeElement;if(!(t instanceof HTMLElement))return null;const e=t.closest(E);return e instanceof HTMLElement?e:null}function f(t){return t?t.nodeType===Node.ELEMENT_NODE?t:t.parentElement:null}function U(t,e){const n=window.getSelection(),r=n&&n.rangeCount>0?n.getRangeAt(0):null,o=r?r.collapsed?r.startContainer:r.commonAncestorContainer:null,i=f(o)||t;if(!t.contains(i))return null;const s=ne(e.ignoredFormats),a=nt(i,t),l=i.closest("li"),u=l?.closest(_),m=i.closest(w),it=m?.closest("table");return{inline:Ct(r,i,t,s),block:!c(s,"block")&&a?Nt(a,s):null,list:!c(s,"list")&&u?St(u,l):null,table:c(s,"table")?null:kt(it,m,s),ignoredFormats:s}}function Ct(t,e,n,r){if(!t||t.collapsed)return H(e,r);const i=Tt(t,e,n).map(s=>H(s,r));return bt(i)}function Tt(t,e,n){const r=[],o=document.createTreeWalker(t.commonAncestorContainer,NodeFilter.SHOW_TEXT,{acceptNode:s=>!n.contains(s)||!t.intersectsNode(s)?NodeFilter.FILTER_REJECT:(s.textContent||"").trim()?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});let i=o.nextNode();for(;i&&r.length<64;){const s=f(i);s&&!r.includes(s)&&r.push(s),i=o.nextNode()}return r.length>0?r:[e]}function H(t,e){const n=window.getComputedStyle(t),r={};c(e,"bold")||(r.bold=At(t,n)),c(e,"italic")||(r.italic=yt(t,n)),c(e,"underline")||(r.underline=$(t,n,"underline")),c(e,"strikethrough")||(r.strikethrough=$(t,n,"line-through"));const o={};return L.forEach(i=>{if(c(e,i))return;const s=n[i];Lt(i,s)&&(o[i]=s)}),{marks:r,styles:o}}function bt(t){const e={};["bold","italic","underline","strikethrough"].forEach(o=>{const i=t.map(s=>s.marks[o]).filter(s=>s!=null);i.length!==0&&(e[o]=i.every(Boolean))});const r={};return L.forEach(o=>{const i=t.map(s=>s.styles[o]).filter(s=>!!s);i.length===t.length&&i.every(s=>s===i[0])&&(r[o]=i[0])}),{marks:e,styles:r}}function Nt(t,e){const n=window.getComputedStyle(t),r={};at.forEach(s=>{if(c(e,s))return;const l=t.style[s]||n[s];Rt(s,l)&&(r[s]=l)});const o={},i=t.getAttribute("dir")||t.style.direction;return(i==="ltr"||i==="rtl"||i==="auto")&&(o.dir=i),{tagName:rt(t),styles:r,attrs:o}}function St(t,e){const n={};lt.forEach(i=>{const s=t.style[i]||window.getComputedStyle(t)[i];s&&s!=="disc"&&s!=="decimal"&&(n[i]=s)});const r={};b(t,r,"data-type"),b(t,r,"type");const o={};return e&&(b(e,o,"data-type"),b(e,o,"data-checked")),{tagName:t.tagName.toLowerCase()==="ol"?"ol":"ul",styles:n,attrs:r,itemAttrs:o}}function kt(t,e,n){return!t&&!e?null:{table:t?W(t,ct,n):null,cell:e?W(e,ut,n):null}}function W(t,e,n){const r=window.getComputedStyle(t),o={};return e.forEach(i=>{if(c(n,i))return;const a=t.style[i]||r[i];wt(i,a)&&(o[i]=a)}),{styles:o,attrs:{}}}function At(t,e){if(t.closest("b,strong"))return!0;const n=e.fontWeight;return/^(bold|bolder|[5-9]\d{2,})$/.test(n)}function yt(t,e){return!!t.closest("i,em")||e.fontStyle==="italic"}function $(t,e,n){const r=n==="underline"?"u":"s,strike";return!!t.closest(r)||e.textDecorationLine.includes(n)}function Lt(t,e){return!(!e||t==="backgroundColor"&&(e==="rgba(0, 0, 0, 0)"||e==="transparent")||t==="textTransform"&&e==="none")}function Rt(t,e){return!(!e||t==="textAlign"&&e==="start"||t==="lineHeight"&&e==="normal"||(t==="marginLeft"||t==="marginRight")&&e==="0px")}function wt(t,e){return!(!e||(t==="backgroundColor"||t.endsWith("Color"))&&(e==="rgba(0, 0, 0, 0)"||e==="transparent")||t==="textAlign"&&e==="start"||t==="verticalAlign"&&e==="middle"||t.endsWith("Width")&&e==="0px"||t.endsWith("Style")&&e==="none"||t.startsWith("padding")&&e==="0px"||t==="borderSpacing"&&e==="0px"||t==="width"&&e==="auto")}function Q(t,e){const n=window.getSelection();if(!n||n.rangeCount===0)return!1;const r=n.getRangeAt(0);if(!t.contains(r.startContainer)||!t.contains(r.endContainer))return!1;const o=t.innerHTML,i=!r.collapsed,s=jt(t);Mt(t,r,e.table),Ft(t,r,e),s?.();const a=window.getSelection(),l=a&&a.rangeCount>0?a.getRangeAt(0):null;i&&a&&l&&t.contains(l.startContainer)&&t.contains(l.endContainer)&&_t(l,a,e),Qt(t),te(t);const u=t.innerHTML;return o===u?!1:(ee(t,o,u),t.dispatchEvent(new Event("input",{bubbles:!0})),!0)}function Ft(t,e,n){const r=Yt(t,e);n.list&&Kt(r,n.list),n.block&&r.forEach(o=>{const i=o.isConnected?o:null;if(!i)return;const s=Zt(i,n.block.tagName);S(s,n.block.styles),n.block.attrs.dir?s.setAttribute("dir",n.block.attrs.dir):s.removeAttribute("dir")})}function Mt(t,e,n){if(!n)return;const r=Vt(t,e);if(n.cell&&r.forEach(i=>{S(i,n.cell.styles)}),!n.table)return;const o=new Set;if(r.forEach(i=>{const s=i.closest("table");s instanceof HTMLElement&&o.add(s)}),o.size===0){const i=f(e.startContainer)?.closest("table");i instanceof HTMLElement&&t.contains(i)&&o.add(i)}o.forEach(i=>{S(i,n.table.styles)})}function _t(t,e,n){Pt(t);const r=n.inline,o=t.cloneContents();if(Jt(o)){Ot(t,e,n);return}const i=t.extractContents();zt(i,n);const s=document.createDocumentFragment(),a=K("start"),l=K("end");s.appendChild(a),s.appendChild(et(i,r)),s.appendChild(l),t.insertNode(s),Ht(a,l,n);const u=document.createRange();u.setStartAfter(a),u.setEndBefore(l),e.removeAllRanges(),e.addRange(u)}function Ot(t,e,n){const r=It(t),o=[];if(r.forEach(s=>{let a=xt(s,t);if(!a||!a.data.trim()||qt(a))return;a=Bt(a,n);const l=et(document.createTextNode(a.data),n.inline);a.parentNode?.replaceChild(l,a),o.push(l)}),o.length===0)return;const i=document.createRange();i.setStartBefore(o[0]),i.setEndAfter(o[o.length-1]),e.removeAllRanges(),e.addRange(i)}function It(t){if(t.startContainer===t.endContainer&&t.startContainer.nodeType===Node.TEXT_NODE)return[t.startContainer];const e=[],n=document.createTreeWalker(t.commonAncestorContainer,NodeFilter.SHOW_TEXT,{acceptNode:o=>!o.textContent||!o.textContent.trim()||!t.intersectsNode(o)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT});let r=n.nextNode();for(;r;)e.push(r),r=n.nextNode();return e}function xt(t,e){const n=t.data.length;let r=0,o=n;if(t===e.startContainer&&(r=Math.max(0,Math.min(e.startOffset,n))),t===e.endContainer&&(o=Math.max(0,Math.min(e.endOffset,n))),r>=o)return null;let i=t;return o<i.data.length&&i.splitText(o),r>0&&(i=i.splitText(r)),i}function Bt(t,e){let n=t,r=n.parentElement;for(;r&&r.matches(y)&&!x(r,e)&&tt(r,e);)vt(r,n),r=n.parentElement;return n}function vt(t,e){const n=t.parentNode;if(!n||e.parentNode!==t)return;const r=t.cloneNode(!1),o=t.cloneNode(!1);for(;t.firstChild&&t.firstChild!==e;)r.appendChild(t.firstChild);for(;e.nextSibling;)o.appendChild(e.nextSibling);q(r)&&n.insertBefore(r,t),n.insertBefore(e,t),q(o)&&n.insertBefore(o,t),n.removeChild(t)}function q(t){return Array.from(t.childNodes).some(e=>e.nodeType!==Node.TEXT_NODE?!0:!!(e.textContent||"").trim())}function Pt(t){let e=f(t.startContainer),n=f(t.endContainer);for(;e&&e===n&&e.matches(y);){if(!Dt(t,e))return;t.selectNode(e),e=e.parentElement,n=f(t.endContainer)}}function Dt(t,e){const n=document.createRange();return n.selectNodeContents(e),t.compareBoundaryPoints(Range.START_TO_START,n)===0&&t.compareBoundaryPoints(Range.END_TO_END,n)===0}function Ht(t,e,n){let r=f(t.parentNode);for(;r&&r.contains(e);){const o=r.parentElement;r.matches(y)&&!x(r,n)&&Wt(r,t,e)&&tt(r,n)&&k(r),r=o}}function Wt(t,e,n){let r="before";for(const o of Array.from(t.childNodes)){if(o===e){r="inside";continue}if(o===n){r="after";continue}if(r!=="inside"&&!$t(o))return!1}return r==="after"}function $t(t){return t.nodeType===Node.TEXT_NODE?!(t.textContent||"").replace(/\uFEFF/g,"").trim():t.nodeType===Node.COMMENT_NODE?ot(t):t.nodeType!==Node.ELEMENT_NODE?!0:t.hasAttribute(d)}function tt(t,e){return t.matches("span")?L.some(n=>!c(e.ignoredFormats,n)):t.matches("b,strong")?!c(e.ignoredFormats,"bold"):t.matches("i,em")?!c(e.ignoredFormats,"italic"):t.matches("u")?!c(e.ignoredFormats,"underline"):t.matches("s,strike")?!c(e.ignoredFormats,"strikethrough"):!0}function qt(t){return t.nodeType!==Node.TEXT_NODE||(t.textContent||"").trim()?!1:!!t.parentElement?.matches(_)}function et(t,e){let n=t;const r=Object.entries(e.styles);if(r.length>0){const o=document.createElement("span");o.classList.add("rte-format-painted"),r.forEach(([i,s])=>{o.style.setProperty(B(i),s)}),o.appendChild(n),n=o}return e.marks.strikethrough&&(n=T("s",n)),e.marks.underline&&(n=T("u",n)),e.marks.italic&&(n=T("i",n)),e.marks.bold&&(n=T("b",n)),n}function T(t,e){const n=document.createElement(t);return n.appendChild(e),n}function zt(t,e){Array.from(t.querySelectorAll(y)).forEach(n=>{if(n instanceof HTMLElement&&!x(n,e)){if(n.matches("span")){if(L.forEach(r=>{c(e.ignoredFormats,r)||n.style.removeProperty(B(r))}),n.getAttribute("style")||n.attributes.length>0)return;k(n);return}n.matches("b,strong")&&c(e.ignoredFormats,"bold")||n.matches("i,em")&&c(e.ignoredFormats,"italic")||n.matches("u")&&c(e.ignoredFormats,"underline")||n.matches("s,strike")&&c(e.ignoredFormats,"strikethrough")||k(n)}})}function x(t,e){return!!(t.matches("a")&&c(e.ignoredFormats,"link")||R(t,"comment")&&c(e.ignoredFormats,"comments")||R(t,"citation")&&c(e.ignoredFormats,"citations")||R(t,"track")&&c(e.ignoredFormats,"trackchanges"))}function R(t,e){const n=e.toLowerCase();return t.className.toString().toLowerCase().includes(n)?!0:Array.from(t.attributes).some(o=>{const i=A(o.name),s=o.value.toLowerCase();return i.includes(n)||s.includes(n)})}function Kt(t,e){t.filter(r=>r.tagName.toLowerCase()==="li").forEach(r=>{const o=r.closest(_);if(!o)return;const i=Xt(o,e.tagName);S(i,e.styles),Z(i,e.attrs),Z(r,e.itemAttrs)})}function Vt(t,e){const n=Array.from(t.querySelectorAll(w)).filter(o=>o instanceof HTMLElement&&e.intersectsNode(o));if(n.length>0)return n;const r=f(e.startContainer)?.closest(w);return r instanceof HTMLElement&&t.contains(r)?[r]:[]}function S(t,e){Object.entries(e).forEach(([n,r])=>{t.style.setProperty(B(n),r)})}function Zt(t,e){const n=rt(t);if(n===e||n==="li"||n==="td"||n==="th")return t;if(e==="blockquote"){const o=document.createElement("blockquote");for(;t.firstChild;)o.appendChild(t.firstChild);return F(t,o),t.parentNode?.replaceChild(o,t),o}if(!/^(p|div|h[1-6]|pre)$/.test(e))return t;const r=document.createElement(e);for(;t.firstChild;)r.appendChild(t.firstChild);return F(t,r),t.parentNode?.replaceChild(r,t),r}function Xt(t,e){if(t.tagName.toLowerCase()===e)return t;const n=document.createElement(e);for(;t.firstChild;)n.appendChild(t.firstChild);return F(t,n),t.parentNode?.replaceChild(n,t),n}function Yt(t,e){const n=Array.from(t.querySelectorAll(N)).filter(o=>o instanceof HTMLElement&&e.intersectsNode(o));if(n.length>0)return n.filter(o=>!n.some(i=>i!==o&&i.contains(o)));const r=nt(f(e.startContainer),t);return r?[r]:[]}function nt(t,e){const n=t?.closest(N);return n instanceof HTMLElement&&e.contains(n)?n:null}function rt(t){const e=t.tagName.toLowerCase();return e==="blockquote"||/^h[1-6]$/.test(e)||e==="pre"||e==="li"||e==="td"||e==="th"?e:"p"}function Jt(t){return Array.from(t.childNodes).some(e=>{if(e.nodeType!==Node.ELEMENT_NODE)return!1;const n=e;return n.matches(N)||!!n.querySelector(N)})}function jt(t){const e=window.getSelection();if(!e||e.rangeCount===0)return null;const n=e.getRangeAt(0);if(!t.contains(n.startContainer)||!t.contains(n.endContainer))return null;const r=n.collapsed,o=z("start"),i=z("end"),s=n.cloneRange();if(!r){const l=s.cloneRange();l.collapse(!1),l.insertNode(i)}const a=s.cloneRange();return a.collapse(!0),a.insertNode(o),()=>{const l=V(t,"start"),u=V(t,"end");if(!l)return;const m=document.createRange();r||!u?(m.setStartAfter(l),m.collapse(!0)):(m.setStartAfter(l),m.setEndBefore(u)),e.removeAllRanges(),e.addRange(m)}}function z(t){return document.createComment(`${d}:selection:${t}`)}function K(t){return document.createComment(`${d}:inline:${t}`)}function ot(t){return Gt(t)||Ut(t)}function Gt(t){return t.nodeType===Node.COMMENT_NODE&&(t.nodeValue===`${d}:selection:start`||t.nodeValue===`${d}:selection:end`)}function Ut(t){return t.nodeType===Node.COMMENT_NODE&&(t.nodeValue===`${d}:inline:start`||t.nodeValue===`${d}:inline:end`)}function V(t,e){const n=`${d}:selection:${e}`,r=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT);let o=r.nextNode();for(;o;){if(o.nodeValue===n)return o;o=r.nextNode()}return null}function Qt(t){t.querySelectorAll(`[${d}]`).forEach(o=>o.remove());const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];let r=e.nextNode();for(;r;)ot(r)&&n.push(r),r=e.nextNode();n.forEach(o=>o.remove())}function te(t){t.querySelectorAll("span").forEach(e=>{e instanceof HTMLElement&&(e.attributes.length>0||k(e))})}function k(t){const e=t.parentNode;if(e){for(;t.firstChild;)e.insertBefore(t.firstChild,t);e.removeChild(t)}}function b(t,e,n){const r=t.getAttribute(n);r!=null&&(e[n]=r)}function Z(t,e){["data-type","data-checked","type"].forEach(n=>{e[n]!=null&&t.setAttribute(n,e[n])})}function F(t,e){Array.from(t.attributes).forEach(n=>{n.name!=="style"&&e.setAttribute(n.name,n.value)})}function h(t,e){const n=g(t);if(n.active===e&&t.classList.contains("rte-format-painter-active")===e){M(t,e);return}n.active=e,t.classList.toggle("rte-format-painter-active",e),M(t,e)}function M(t,e){const n=t.closest(st)||document;n.querySelectorAll('[data-command="toggleFormatPainter"], [data-command="formatPainter"]').forEach(o=>{o instanceof HTMLElement&&(o.classList.toggle("active",e),o.setAttribute("data-active",e?"true":"false"),o.setAttribute("aria-pressed",e?"true":"false"))}),n.dispatchEvent(new CustomEvent("editora:format-painter-toggle",{bubbles:!0,detail:{active:e}}))}function ee(t,e,n){if(e===n)return;const r=window.execEditorCommand||window.executeEditorCommand;if(typeof r=="function")try{r("recordDomTransaction",{editor:t,beforeHTML:e,afterHTML:n})}catch{try{r("recordDomTransaction",t,e,n)}catch{}}}function ne(t){return(t??O).map(A).map(e=>X[e]||e).filter(Boolean)}function c(t,e){const n=X[A(e)]||A(e);return t.includes(n)}function A(t){return t.toLowerCase().replace(/[^a-z0-9]/g,"")}function B(t){return t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}exports.FormatPainterPlugin=dt;