@editora/plugins 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +57 -4
  2. package/dist/_commonjsHelpers-BH3jXuIh.js +1 -0
  3. package/dist/_commonjsHelpers-ByX85dGu.mjs +33 -0
  4. package/dist/anchor.cjs.js +11 -11
  5. package/dist/anchor.esm.js +130 -107
  6. package/dist/anchoredPopover-BzqGPOAE.js +1 -0
  7. package/dist/anchoredPopover-Dts0IrgU.mjs +106 -0
  8. package/dist/background-color.cjs.js +3 -3
  9. package/dist/background-color.esm.js +116 -119
  10. package/dist/code.cjs.js +82 -102
  11. package/dist/code.esm.js +1172 -662
  12. package/dist/comments.cjs.js +10 -10
  13. package/dist/comments.esm.js +195 -177
  14. package/dist/document-manager.cjs.js +1 -1
  15. package/dist/document-manager.esm.js +1 -1
  16. package/dist/documentManager-CTqRftU8.mjs +8369 -0
  17. package/dist/documentManager-Jf0RbSks.js +17 -0
  18. package/dist/embed-iframe.cjs.js +2 -2
  19. package/dist/embed-iframe.esm.js +8 -5
  20. package/dist/emojis.cjs.js +64 -39
  21. package/dist/emojis.esm.js +133 -104
  22. package/dist/html2canvas.esm-B5qzocYs.js +5 -0
  23. package/dist/html2canvas.esm-BWVIUcAF.mjs +4802 -0
  24. package/dist/{index-Bskk414V.mjs → index-BFsKNTTj.mjs} +50 -50
  25. package/dist/index-CvJk4DKa.js +221 -0
  26. package/dist/index-D3CycEFU.mjs +16543 -0
  27. package/dist/index-tqLTHcO6.js +1 -0
  28. package/dist/index.cjs.js +1 -1
  29. package/dist/{index.es-Cz1qItab.js → index.es-CE_A4QSm.js} +5 -5
  30. package/dist/{index.es-DEcRmSTY.mjs → index.es-DQ78mYYo.mjs} +4 -3
  31. package/dist/index.esm.js +87 -79
  32. package/dist/jspdf.es.min-BoS80556.js +77 -0
  33. package/dist/jspdf.es.min-DQCoX5yh.mjs +7889 -0
  34. package/dist/link.cjs.js +6 -6
  35. package/dist/link.esm.js +41 -39
  36. package/dist/math.cjs.js +21 -21
  37. package/dist/math.esm.js +151 -112
  38. package/dist/media-manager.cjs.js +15 -15
  39. package/dist/media-manager.esm.js +227 -206
  40. package/dist/merge-tag.cjs.js +44 -12
  41. package/dist/merge-tag.esm.js +368 -241
  42. package/dist/page-break.cjs.js +2 -2
  43. package/dist/page-break.esm.js +77 -69
  44. package/dist/special-characters.cjs.js +83 -45
  45. package/dist/special-characters.esm.js +149 -100
  46. package/dist/spell-check.cjs.js +9 -9
  47. package/dist/spell-check.esm.js +235 -216
  48. package/dist/template.cjs.js +14 -14
  49. package/dist/template.esm.js +157 -131
  50. package/dist/text-color.cjs.js +9 -9
  51. package/dist/text-color.esm.js +131 -115
  52. package/index.d.ts +51 -1
  53. package/package.json +6 -4
  54. package/dist/colorSelectionApply-C0iOfMWb.js +0 -1
  55. package/dist/colorSelectionApply-D8r_gV32.mjs +0 -63
  56. package/dist/documentManager-DRUc1-Cs.mjs +0 -37581
  57. package/dist/documentManager-_tQQfQi9.js +0 -317
  58. package/dist/index-D3pJyAsj.js +0 -1
@@ -1,6 +1,6 @@
1
- import { a as h } from "./colorSelectionApply-D8r_gV32.mjs";
2
- let o = null, p = null, f = null, i = "#000000";
3
- const s = '[data-theme="dark"], .dark, .editora-theme-dark', k = [
1
+ import { a as y, b as w } from "./anchoredPopover-Dts0IrgU.mjs";
2
+ let n = null, d = null, g = null, i = "#000000";
3
+ const u = '[data-theme="dark"], .dark, .editora-theme-dark', C = [
4
4
  "#000000",
5
5
  "#ffffff",
6
6
  "#808080",
@@ -14,79 +14,95 @@ const s = '[data-theme="dark"], .dark, .editora-theme-dark', k = [
14
14
  "#800080",
15
15
  "#ffc0cb"
16
16
  ];
17
- function m() {
17
+ function v() {
18
18
  const e = window.getSelection();
19
19
  if (e && e.rangeCount > 0) {
20
- const l = e.getRangeAt(0).startContainer, c = l.nodeType === Node.ELEMENT_NODE ? l : l.parentElement;
21
- if (c) {
22
- const n = c.closest(
20
+ const c = e.getRangeAt(0).startContainer, l = c.nodeType === Node.ELEMENT_NODE ? c : c.parentElement;
21
+ if (l) {
22
+ const r = l.closest(
23
23
  '[data-editora-editor="true"], .rte-editor, .editora-editor'
24
24
  );
25
- if (n) return n;
25
+ if (r) return r;
26
26
  }
27
27
  }
28
- const t = document.activeElement;
29
- return t ? t.closest(
28
+ const o = document.activeElement;
29
+ return o ? o.closest(
30
30
  '[data-editora-editor="true"], .rte-editor, .editora-editor'
31
31
  ) : null;
32
32
  }
33
- function v(e) {
34
- const t = m();
35
- if (t) {
36
- const r = t.querySelector(
37
- `[data-command="${e}"]`
38
- );
39
- if (r) return r;
33
+ function E(e) {
34
+ const o = window.__editoraLastCommand, t = window.__editoraLastCommandButton;
35
+ if (o === e && t && t.isConnected) {
36
+ const a = window.getComputedStyle(t), s = t.getBoundingClientRect();
37
+ if (a.display !== "none" && a.visibility !== "hidden" && a.pointerEvents !== "none" && !(s.width === 0 && s.height === 0))
38
+ return t;
39
+ }
40
+ const c = (a) => {
41
+ for (const s of a) {
42
+ const b = window.getComputedStyle(s), h = s.getBoundingClientRect();
43
+ if (!(b.display === "none" || b.visibility === "hidden" || b.pointerEvents === "none") && !(h.width === 0 && h.height === 0))
44
+ return s;
45
+ }
46
+ return null;
47
+ }, l = v();
48
+ if (l) {
49
+ const a = Array.from(
50
+ l.querySelectorAll(`[data-command="${e}"]`)
51
+ ), s = c(a);
52
+ if (s) return s;
40
53
  }
41
- return document.querySelector(`[data-command="${e}"]`);
54
+ const r = Array.from(
55
+ document.querySelectorAll(`[data-command="${e}"]`)
56
+ );
57
+ return c(r);
42
58
  }
43
- function y(e) {
44
- if (e?.closest(s)) return !0;
45
- const t = window.getSelection();
46
- if (t && t.rangeCount > 0) {
47
- const l = t.getRangeAt(0).startContainer;
48
- if ((l.nodeType === Node.ELEMENT_NODE ? l : l.parentElement)?.closest(s)) return !0;
59
+ function S(e) {
60
+ if (e?.closest(u)) return !0;
61
+ const o = window.getSelection();
62
+ if (o && o.rangeCount > 0) {
63
+ const c = o.getRangeAt(0).startContainer;
64
+ if ((c.nodeType === Node.ELEMENT_NODE ? c : c.parentElement)?.closest(u)) return !0;
49
65
  }
50
- return document.activeElement?.closest(s) ? !0 : document.body.matches(s) || document.documentElement.matches(s);
66
+ return document.activeElement?.closest(u) ? !0 : document.body.matches(u) || document.documentElement.matches(u);
51
67
  }
52
- function d(e) {
53
- return h({
68
+ function f(e) {
69
+ return y({
54
70
  color: e,
55
71
  className: "rte-text-color",
56
72
  styleProperty: "color",
57
73
  commands: ["foreColor"],
58
- savedRange: f,
59
- getActiveEditorRoot: m,
74
+ savedRange: g,
75
+ getActiveEditorRoot: v,
60
76
  warnMessage: "[TextColor] Could not apply color for current selection"
61
77
  });
62
78
  }
63
- function w() {
79
+ function T() {
64
80
  const e = window.getSelection();
65
81
  if (!e || e.rangeCount === 0) return "#000000";
66
- let r = e.getRangeAt(0).startContainer;
67
- for (; r && r !== document.body; ) {
68
- if (r.nodeType === Node.ELEMENT_NODE) {
69
- const l = r, c = l.style.color || window.getComputedStyle(l).color;
70
- if (c && c !== "rgb(0, 0, 0)")
71
- return C(c);
82
+ let t = e.getRangeAt(0).startContainer;
83
+ for (; t && t !== document.body; ) {
84
+ if (t.nodeType === Node.ELEMENT_NODE) {
85
+ const c = t, l = c.style.color || window.getComputedStyle(c).color;
86
+ if (l && l !== "rgb(0, 0, 0)")
87
+ return A(l);
72
88
  }
73
- r = r.parentNode;
89
+ t = t.parentNode;
74
90
  }
75
91
  return "#000000";
76
92
  }
77
- function C(e) {
93
+ function A(e) {
78
94
  if (e.startsWith("#")) return e;
79
- const t = e.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
80
- if (!t) return "#000000";
81
- const r = parseInt(t[1]), l = parseInt(t[2]), c = parseInt(t[3]);
82
- return "#" + [r, l, c].map((n) => {
83
- const u = n.toString(16);
84
- return u.length === 1 ? "0" + u : u;
95
+ const o = e.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
96
+ if (!o) return "#000000";
97
+ const t = parseInt(o[1]), c = parseInt(o[2]), l = parseInt(o[3]);
98
+ return "#" + [t, c, l].map((r) => {
99
+ const a = r.toString(16);
100
+ return a.length === 1 ? "0" + a : a;
85
101
  }).join("");
86
102
  }
87
- function E(e) {
88
- const t = window.getSelection();
89
- t && t.rangeCount > 0 && (f = t.getRangeAt(0).cloneRange()), i = w(), o = document.createElement("div"), o.className = "rte-inline-color-picker", y(e) && o.classList.add("rte-theme-dark"), o.addEventListener("click", (l) => l.stopPropagation()), o.innerHTML = `
103
+ function L(e) {
104
+ const o = window.getSelection();
105
+ o && o.rangeCount > 0 && (g = o.getRangeAt(0).cloneRange()), i = T(), n = document.createElement("div"), n.className = "rte-inline-color-picker", S(e) && n.classList.add("rte-theme-dark"), n.addEventListener("click", (t) => t.stopPropagation()), n.innerHTML = `
90
106
  <div class="rte-color-picker-header">
91
107
  <span class="rte-color-picker-title">Text Color</span>
92
108
  <button class="rte-color-picker-close" aria-label="Close">×</button>
@@ -103,13 +119,13 @@ function E(e) {
103
119
  <div class="rte-color-section">
104
120
  <label class="rte-color-section-label">Colors</label>
105
121
  <div class="rte-color-palette">
106
- ${k.map((l) => `
122
+ ${C.map((t) => `
107
123
  <button
108
- class="rte-color-swatch ${i === l ? "selected" : ""}"
109
- style="background-color: ${l}; ${l === "#ffffff" ? "border: 1px solid #ccc;" : ""}"
110
- data-color="${l}"
111
- title="${l.toUpperCase()}"
112
- aria-label="${l.toUpperCase()}"
124
+ class="rte-color-swatch ${i === t ? "selected" : ""}"
125
+ style="background-color: ${t}; ${t === "#ffffff" ? "border: 1px solid #ccc;" : ""}"
126
+ data-color="${t}"
127
+ title="${t.toUpperCase()}"
128
+ aria-label="${t.toUpperCase()}"
113
129
  ></button>
114
130
  `).join("")}
115
131
  </div>
@@ -136,72 +152,72 @@ function E(e) {
136
152
  </div>
137
153
  </div>
138
154
  </div>
139
- `;
140
- const r = e.getBoundingClientRect();
141
- o.style.position = "absolute", o.style.top = `${r.bottom + window.scrollY + 4}px`, o.style.left = `${r.left + window.scrollX}px`, o.style.zIndex = "10000", document.body.appendChild(o), p = e, T();
155
+ `, document.body.appendChild(n), d && (d.destroy(), d = null), d = w({
156
+ popover: n,
157
+ anchor: e,
158
+ onClose: p,
159
+ gap: 4,
160
+ margin: 8,
161
+ zIndex: 1e4
162
+ }), P();
142
163
  }
143
- function T() {
144
- if (!o) return;
145
- o.querySelector(".rte-color-picker-close")?.addEventListener("click", () => a()), o.querySelectorAll(".rte-color-swatch").forEach((c) => {
146
- c.addEventListener("click", () => {
147
- const n = c.getAttribute("data-color");
148
- n && (i = n, d(n), a());
164
+ function P() {
165
+ if (!n) return;
166
+ n.querySelector(".rte-color-picker-close")?.addEventListener("click", () => p()), n.querySelectorAll(".rte-color-swatch").forEach((l) => {
167
+ l.addEventListener("click", () => {
168
+ const r = l.getAttribute("data-color");
169
+ r && (i = r, f(r), p());
149
170
  });
150
171
  });
151
- const r = o.querySelector(".rte-color-input-native");
152
- r?.addEventListener("change", (c) => {
153
- const n = c.target.value;
154
- i = n, d(n), a();
172
+ const t = n.querySelector(".rte-color-input-native");
173
+ t?.addEventListener("change", (l) => {
174
+ const r = l.target.value;
175
+ i = r, f(r), p();
155
176
  });
156
- const l = o.querySelector(".rte-color-input-text");
157
- l?.addEventListener("change", (c) => {
158
- const n = c.target.value;
159
- /^#[0-9A-Fa-f]{6}$/.test(n) && (i = n, d(n), a());
160
- }), r?.addEventListener("input", (c) => {
161
- const n = c.target.value;
162
- i = n, x(n), b(n), L(n);
163
- }), l?.addEventListener("input", (c) => {
164
- const n = c.target.value;
165
- /^#[0-9A-Fa-f]{6}$/.test(n) && (i = n, x(n), b(n), S(n));
177
+ const c = n.querySelector(".rte-color-input-text");
178
+ c?.addEventListener("change", (l) => {
179
+ const r = l.target.value;
180
+ /^#[0-9A-Fa-f]{6}$/.test(r) && (i = r, f(r), p());
181
+ }), t?.addEventListener("input", (l) => {
182
+ const r = l.target.value;
183
+ i = r, m(r), k(r), _(r);
184
+ }), c?.addEventListener("input", (l) => {
185
+ const r = l.target.value;
186
+ /^#[0-9A-Fa-f]{6}$/.test(r) && (i = r, m(r), k(r), $(r));
166
187
  });
167
188
  }
168
- function x(e) {
169
- if (!o) return;
170
- const t = o.querySelector(".rte-color-preview-box"), r = o.querySelector(".rte-color-preview-label");
171
- t && (t.style.backgroundColor = e, t.style.border = e === "#ffffff" ? "1px solid #ccc" : "none"), r && (r.textContent = e.toUpperCase());
189
+ function m(e) {
190
+ if (!n) return;
191
+ const o = n.querySelector(".rte-color-preview-box"), t = n.querySelector(".rte-color-preview-label");
192
+ o && (o.style.backgroundColor = e, o.style.border = e === "#ffffff" ? "1px solid #ccc" : "none"), t && (t.textContent = e.toUpperCase());
172
193
  }
173
- function b(e) {
174
- if (!o) return;
175
- o.querySelectorAll(".rte-color-swatch").forEach((r) => {
176
- r.getAttribute("data-color") === e ? r.classList.add("selected") : r.classList.remove("selected");
194
+ function k(e) {
195
+ if (!n) return;
196
+ n.querySelectorAll(".rte-color-swatch").forEach((t) => {
197
+ t.getAttribute("data-color") === e ? t.classList.add("selected") : t.classList.remove("selected");
177
198
  });
178
199
  }
179
- function S(e) {
180
- if (!o) return;
181
- const t = o.querySelector(".rte-color-input-native");
182
- t && (t.value = e);
200
+ function $(e) {
201
+ if (!n) return;
202
+ const o = n.querySelector(".rte-color-input-native");
203
+ o && (o.value = e);
183
204
  }
184
- function L(e) {
185
- if (!o) return;
186
- const t = o.querySelector(".rte-color-input-text");
187
- t && (t.value = e);
205
+ function _(e) {
206
+ if (!n) return;
207
+ const o = n.querySelector(".rte-color-input-text");
208
+ o && (o.value = e);
188
209
  }
189
- function a() {
190
- o && (o.remove(), o = null), p = null, f = null;
210
+ function p() {
211
+ d && (d.destroy(), d = null), n && (n.remove(), n = null), g = null;
191
212
  }
192
- function $() {
193
- if (o)
194
- return a(), !0;
195
- const e = v("openTextColorPicker");
196
- return e ? (E(e), !0) : !1;
213
+ function R() {
214
+ if (x(), n)
215
+ return p(), !0;
216
+ const e = E("openTextColorPicker");
217
+ return e ? (L(e), !0) : !1;
197
218
  }
198
- function g() {
199
- if (!window.__textColorPluginInitialized && (window.__textColorPluginInitialized = !0, document.addEventListener("click", (e) => {
200
- if (o && p) {
201
- const t = e.target;
202
- !o.contains(t) && !p.contains(t) && a();
203
- }
204
- }), !document.getElementById("text-color-plugin-styles"))) {
219
+ function x() {
220
+ if (!window.__textColorPluginInitialized && (window.__textColorPluginInitialized = !0, !document.getElementById("text-color-plugin-styles"))) {
205
221
  const e = document.createElement("style");
206
222
  e.id = "text-color-plugin-styles", e.textContent = `
207
223
  .rte-inline-color-picker {
@@ -455,8 +471,8 @@ function g() {
455
471
  `, document.head.appendChild(e);
456
472
  }
457
473
  }
458
- document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", g) : setTimeout(g, 100);
459
- const A = () => ({
474
+ document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", x) : setTimeout(x, 100);
475
+ const N = () => ({
460
476
  name: "textColor",
461
477
  marks: {
462
478
  textColor: {
@@ -467,15 +483,15 @@ const A = () => ({
467
483
  {
468
484
  tag: "span[style*=color]",
469
485
  getAttrs: (e) => {
470
- const r = (e.getAttribute("style") || "").match(/color:\s*([^;]+)/);
471
- return r ? { color: r[1] } : null;
486
+ const t = (e.getAttribute("style") || "").match(/color:\s*([^;]+)/);
487
+ return t ? { color: t[1] } : null;
472
488
  }
473
489
  },
474
490
  {
475
491
  tag: "font[color]",
476
492
  getAttrs: (e) => {
477
- const t = e.getAttribute("color");
478
- return t ? { color: t } : null;
493
+ const o = e.getAttribute("color");
494
+ return o ? { color: o } : null;
479
495
  }
480
496
  }
481
497
  ],
@@ -497,11 +513,11 @@ const A = () => ({
497
513
  }
498
514
  ],
499
515
  commands: {
500
- openTextColorPicker: () => $(),
501
- setTextColor: (e) => e ? d(e) : !1
516
+ openTextColorPicker: () => R(),
517
+ setTextColor: (e) => e ? f(e) : !1
502
518
  },
503
519
  keymap: {}
504
520
  });
505
521
  export {
506
- A as TextColorPlugin
522
+ N as TextColorPlugin
507
523
  };
package/index.d.ts CHANGED
@@ -8,6 +8,48 @@ export interface ApiConfig {
8
8
  export type MediaManagerConfig = Record<string, unknown>;
9
9
  export type DocumentManagerConfig = Record<string, unknown>;
10
10
 
11
+ export interface MergeTagItem {
12
+ key?: string;
13
+ label: string;
14
+ category?: string;
15
+ preview?: string;
16
+ description?: string;
17
+ value?: string;
18
+ }
19
+
20
+ export interface MergeTagCategory {
21
+ id?: string;
22
+ name: string;
23
+ tags: MergeTagItem[];
24
+ }
25
+
26
+ export interface MergeTagDialogOptions {
27
+ title?: string;
28
+ searchPlaceholder?: string;
29
+ emptyStateText?: string;
30
+ cancelText?: string;
31
+ insertText?: string;
32
+ showPreview?: boolean;
33
+ }
34
+
35
+ export interface MergeTagPluginOptions {
36
+ tags?: MergeTagItem[];
37
+ categories?: MergeTagCategory[];
38
+ defaultCategory?: string;
39
+ dialog?: MergeTagDialogOptions;
40
+ tokenTemplate?: string | ((tag: MergeTagItem & { key: string; category: string }) => string);
41
+ }
42
+
43
+ export interface Template {
44
+ id: string;
45
+ name: string;
46
+ category: string;
47
+ html: string;
48
+ description?: string;
49
+ preview?: string;
50
+ tags?: string[];
51
+ }
52
+
11
53
  export function HeadingPlugin(): Plugin;
12
54
  export function BoldPlugin(): Plugin;
13
55
  export function ItalicPlugin(): Plugin;
@@ -50,8 +92,16 @@ export function PrintPlugin(): Plugin;
50
92
  export function PageBreakPlugin(): Plugin;
51
93
  export function FootnotePlugin(): Plugin;
52
94
  export function CodeSamplePlugin(): Plugin;
53
- export function MergeTagPlugin(): Plugin;
95
+ export function MergeTagPlugin(options?: MergeTagPluginOptions): Plugin;
54
96
  export function TemplatePlugin(): Plugin;
97
+ export const PREDEFINED_TEMPLATES: Template[];
98
+ export function addCustomTemplate(template: Template): boolean;
99
+ export function getAllTemplates(): Template[];
100
+ export function getTemplatesByCategory(category: string): Template[];
101
+ export function getTemplateCategories(): string[];
102
+ export function searchTemplates(query: string): Template[];
103
+ export function sanitizeTemplate(html: string): string;
104
+ export function validateTemplate(template: Template): boolean;
55
105
  export function CommentsPlugin(): Plugin;
56
106
  export function SpellCheckPlugin(): Plugin;
57
107
  export function A11yCheckerPlugin(): Plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@editora/plugins",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "40+ Free Premium Plugins for Editora Rich Text Editor. Table editor, code formatting, accessibility, math, media, and more. Free enterprise plugin collection.",
5
5
  "author": "Ajay Kumar <ajaykr089@gmail.com>",
6
6
  "license": "MIT",
@@ -40,6 +40,7 @@
40
40
  "main": "dist/index.cjs.js",
41
41
  "module": "dist/index.esm.js",
42
42
  "types": "index.d.ts",
43
+ "style": "dist/plugins.css",
43
44
  "exports": {
44
45
  ".": {
45
46
  "types": "./index.d.ts",
@@ -298,7 +299,8 @@
298
299
  "import": "./dist/underline.esm.js",
299
300
  "require": "./dist/underline.cjs.js",
300
301
  "default": "./dist/underline.esm.js"
301
- }
302
+ },
303
+ "./styles.css": "./dist/plugins.css"
302
304
  },
303
305
  "files": [
304
306
  "dist",
@@ -315,14 +317,14 @@
315
317
  "prepublishOnly": "npm run typecheck:build && npm run build"
316
318
  },
317
319
  "peerDependencies": {
318
- "@editora/core": "^1.0.6"
320
+ "@editora/core": "^1.0.7"
319
321
  },
320
322
  "dependencies": {
321
323
  "katex": "^0.16.27",
322
324
  "mathjax": "^3.2.2"
323
325
  },
324
326
  "devDependencies": {
325
- "@editora/core": "^1.0.6",
327
+ "@editora/core": "^1.0.7",
326
328
  "@types/katex": "^0.16.8",
327
329
  "typescript": "^5.0.0",
328
330
  "vite": "^7.3.1"
@@ -1 +0,0 @@
1
- "use strict";const u="p,div,li,ul,ol,table,thead,tbody,tfoot,tr,td,th,h1,h2,h3,h4,h5,h6,blockquote,pre";function i(e){return!!e.cloneContents().querySelector(u)}function s(e,t){return(e?.nodeType===Node.ELEMENT_NODE?e:e?.parentElement??null)?.closest('[contenteditable="true"]')||t()?.querySelector('[contenteditable="true"]')||document.querySelector('[contenteditable="true"]')}function c(e,t){const n=s(e,t);n&&n.dispatchEvent(new Event("input",{bubbles:!0}))}function f(e,t){let o=e.startContainer.nodeType===Node.TEXT_NODE?e.startContainer.parentElement:e.startContainer;for(;o&&o!==document.body;){if(o.classList.contains(t)){const a=document.createRange();if(a.selectNodeContents(o),a.compareBoundaryPoints(Range.START_TO_START,e)<=0&&a.compareBoundaryPoints(Range.END_TO_END,e)>=0)return o}o=o.parentElement}return null}function m(e){try{if(e.savedRange){const r=window.getSelection();r&&(r.removeAllRanges(),r.addRange(e.savedRange.cloneRange()))}const t=window.getSelection();if(!t||t.rangeCount===0||t.isCollapsed)return!1;const n=t.getRangeAt(0);if(n.collapsed)return!1;const o=f(n,e.className);if(o)return e.styleProperty==="backgroundColor"?o.style.backgroundColor=e.color:o.style.color=e.color,c(o,e.getActiveEditorRoot),!0;s(n.commonAncestorContainer,e.getActiveEditorRoot)?.focus({preventScroll:!0});try{document.execCommand("styleWithCSS",!1,"true")}catch{}let l=!1;if(e.commands.forEach(r=>{l||(l=document.execCommand(r,!1,e.color))}),!l&&!i(n)){const r=document.createElement("span");e.styleProperty==="backgroundColor"?r.style.backgroundColor=e.color:r.style.color=e.color,r.className=e.className;const d=n.extractContents();r.appendChild(d),n.insertNode(r),n.setStartAfter(r),n.collapse(!0),t.removeAllRanges(),t.addRange(n),l=!0}return l?(c(n.commonAncestorContainer,e.getActiveEditorRoot),!0):(e.warnMessage&&console.warn(e.warnMessage),!1)}catch(t){return e.warnMessage?console.error(e.warnMessage,t):console.error("[ColorApply] Failed to apply color",t),!1}}exports.applyColorToSelection=m;
@@ -1,63 +0,0 @@
1
- const u = "p,div,li,ul,ol,table,thead,tbody,tfoot,tr,td,th,h1,h2,h3,h4,h5,h6,blockquote,pre";
2
- function i(e) {
3
- return !!e.cloneContents().querySelector(u);
4
- }
5
- function s(e, t) {
6
- return (e?.nodeType === Node.ELEMENT_NODE ? e : e?.parentElement ?? null)?.closest('[contenteditable="true"]') || t()?.querySelector('[contenteditable="true"]') || document.querySelector('[contenteditable="true"]');
7
- }
8
- function c(e, t) {
9
- const n = s(e, t);
10
- n && n.dispatchEvent(new Event("input", { bubbles: !0 }));
11
- }
12
- function f(e, t) {
13
- let o = e.startContainer.nodeType === Node.TEXT_NODE ? e.startContainer.parentElement : e.startContainer;
14
- for (; o && o !== document.body; ) {
15
- if (o.classList.contains(t)) {
16
- const l = document.createRange();
17
- if (l.selectNodeContents(o), l.compareBoundaryPoints(Range.START_TO_START, e) <= 0 && l.compareBoundaryPoints(Range.END_TO_END, e) >= 0)
18
- return o;
19
- }
20
- o = o.parentElement;
21
- }
22
- return null;
23
- }
24
- function m(e) {
25
- try {
26
- if (e.savedRange) {
27
- const r = window.getSelection();
28
- r && (r.removeAllRanges(), r.addRange(e.savedRange.cloneRange()));
29
- }
30
- const t = window.getSelection();
31
- if (!t || t.rangeCount === 0 || t.isCollapsed)
32
- return !1;
33
- const n = t.getRangeAt(0);
34
- if (n.collapsed)
35
- return !1;
36
- const o = f(n, e.className);
37
- if (o)
38
- return e.styleProperty === "backgroundColor" ? o.style.backgroundColor = e.color : o.style.color = e.color, c(o, e.getActiveEditorRoot), !0;
39
- s(
40
- n.commonAncestorContainer,
41
- e.getActiveEditorRoot
42
- )?.focus({ preventScroll: !0 });
43
- try {
44
- document.execCommand("styleWithCSS", !1, "true");
45
- } catch {
46
- }
47
- let a = !1;
48
- if (e.commands.forEach((r) => {
49
- a || (a = document.execCommand(r, !1, e.color));
50
- }), !a && !i(n)) {
51
- const r = document.createElement("span");
52
- e.styleProperty === "backgroundColor" ? r.style.backgroundColor = e.color : r.style.color = e.color, r.className = e.className;
53
- const d = n.extractContents();
54
- r.appendChild(d), n.insertNode(r), n.setStartAfter(r), n.collapse(!0), t.removeAllRanges(), t.addRange(n), a = !0;
55
- }
56
- return a ? (c(n.commonAncestorContainer, e.getActiveEditorRoot), !0) : (e.warnMessage && console.warn(e.warnMessage), !1);
57
- } catch (t) {
58
- return e.warnMessage ? console.error(e.warnMessage, t) : console.error("[ColorApply] Failed to apply color", t), !1;
59
- }
60
- }
61
- export {
62
- m as a
63
- };