@editora/plugins 1.0.7 → 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 +50 -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 +3 -3
  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
@@ -0,0 +1,106 @@
1
+ const b = "p,div,li,ul,ol,table,thead,tbody,tfoot,tr,td,th,h1,h2,h3,h4,h5,h6,blockquote,pre";
2
+ function p(e) {
3
+ return !!e.cloneContents().querySelector(b);
4
+ }
5
+ function v(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 = v(e, t);
10
+ n && n.dispatchEvent(new Event("input", { bubbles: !0 }));
11
+ }
12
+ function A(e, t) {
13
+ let r = e.startContainer.nodeType === Node.TEXT_NODE ? e.startContainer.parentElement : e.startContainer;
14
+ for (; r && r !== document.body; ) {
15
+ if (r.classList.contains(t)) {
16
+ const c = document.createRange();
17
+ if (c.selectNodeContents(r), c.compareBoundaryPoints(Range.START_TO_START, e) <= 0 && c.compareBoundaryPoints(Range.END_TO_END, e) >= 0)
18
+ return r;
19
+ }
20
+ r = r.parentElement;
21
+ }
22
+ return null;
23
+ }
24
+ function N(e) {
25
+ try {
26
+ if (e.savedRange) {
27
+ const o = window.getSelection();
28
+ o && (o.removeAllRanges(), o.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 r = A(n, e.className);
37
+ if (r)
38
+ return e.styleProperty === "backgroundColor" ? r.style.backgroundColor = e.color : r.style.color = e.color, C(r, e.getActiveEditorRoot), !0;
39
+ v(
40
+ n.commonAncestorContainer,
41
+ e.getActiveEditorRoot
42
+ )?.focus({ preventScroll: !0 });
43
+ try {
44
+ document.execCommand("styleWithCSS", !1, "true");
45
+ } catch {
46
+ }
47
+ let l = !1;
48
+ if (e.commands.forEach((o) => {
49
+ l || (l = document.execCommand(o, !1, e.color));
50
+ }), !l && !p(n)) {
51
+ const o = document.createElement("span");
52
+ e.styleProperty === "backgroundColor" ? o.style.backgroundColor = e.color : o.style.color = e.color, o.className = e.className;
53
+ const a = n.extractContents();
54
+ o.appendChild(a), n.insertNode(o), n.setStartAfter(o), n.collapse(!0), t.removeAllRanges(), t.addRange(n), l = !0;
55
+ }
56
+ return l ? (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
+ function T({
62
+ popover: e,
63
+ anchor: t,
64
+ onClose: n,
65
+ gap: r = 6,
66
+ margin: c = 8,
67
+ zIndex: l = 1e4
68
+ }) {
69
+ e.style.position = "fixed", e.style.zIndex = `${l}`, e.style.visibility = "hidden";
70
+ const o = () => {
71
+ if (!e.isConnected || !t.isConnected) {
72
+ n();
73
+ return;
74
+ }
75
+ const s = t.getBoundingClientRect();
76
+ if (s.width === 0 && s.height === 0) {
77
+ n();
78
+ return;
79
+ }
80
+ const i = e.getBoundingClientRect(), w = i.width || e.offsetWidth || 220, f = i.height || e.offsetHeight || 260, y = window.innerWidth, E = window.innerHeight;
81
+ let u = s.left, d = s.bottom + r;
82
+ if (u + w > y - c && (u = y - w - c), u = Math.max(c, u), d + f > E - c) {
83
+ const g = s.top - f - r;
84
+ g >= c ? d = g : d = Math.max(c, E - f - c);
85
+ }
86
+ d < c && (d = c), e.style.left = `${Math.round(u)}px`, e.style.top = `${Math.round(d)}px`, e.style.visibility = "visible";
87
+ }, a = () => {
88
+ o();
89
+ }, m = (s) => {
90
+ const i = s.target;
91
+ i && (e.contains(i) || t.contains(i) || n());
92
+ }, h = (s) => {
93
+ s.key === "Escape" && n();
94
+ };
95
+ window.addEventListener("resize", a), window.addEventListener("scroll", a, !0), document.addEventListener("keydown", h);
96
+ const R = window.requestAnimationFrame(() => {
97
+ document.addEventListener("mousedown", m, !0);
98
+ });
99
+ return o(), { reposition: o, destroy: () => {
100
+ window.cancelAnimationFrame(R), window.removeEventListener("resize", a), window.removeEventListener("scroll", a, !0), document.removeEventListener("keydown", h), document.removeEventListener("mousedown", m, !0);
101
+ } };
102
+ }
103
+ export {
104
+ N as a,
105
+ T as b
106
+ };
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const P=require("./colorSelectionApply-C0iOfMWb.js");let l=null,k=null,L=null,s="#ffff00";const h='[data-theme="dark"], .dark, .editora-theme-dark',A=["#000000","#ffffff","#808080","#ff0000","#00ff00","#0000ff","#ffff00","#ff00ff","#00ffff","#ffa500","#800080","#ffc0cb"];function M(){const e=window.getSelection();if(e&&e.rangeCount>0){const r=e.getRangeAt(0).startContainer,a=r.nodeType===Node.ELEMENT_NODE?r:r.parentElement;if(a){const n=a.closest('[data-editora-editor="true"], .rte-editor, .editora-editor');if(n)return n}}const t=document.activeElement;return t?t.closest('[data-editora-editor="true"], .rte-editor, .editora-editor'):null}function R(e){const t=M();if(t){const c=t.querySelector(`[data-command="${e}"]`);if(c)return c}return document.querySelector(`[data-command="${e}"]`)}function T(e){if(e?.closest(h))return!0;const t=window.getSelection();if(t&&t.rangeCount>0){const r=t.getRangeAt(0).startContainer;if((r.nodeType===Node.ELEMENT_NODE?r:r.parentElement)?.closest(h))return!0}return document.activeElement?.closest(h)?!0:document.body.matches(h)||document.documentElement.matches(h)}function q(){if(document.getElementById("rte-bg-color-picker-styles"))return;const e=document.createElement("style");e.id="rte-bg-color-picker-styles",e.textContent=`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const A=require("./anchoredPopover-BzqGPOAE.js");let a=null,N=null,g=null,L=null,i="#ffff00";const k='[data-theme="dark"], .dark, .editora-theme-dark',R=["#000000","#ffffff","#808080","#ff0000","#00ff00","#0000ff","#ffff00","#ff00ff","#00ffff","#ffa500","#800080","#ffc0cb"];function P(){const e=window.getSelection();if(e&&e.rangeCount>0){const r=e.getRangeAt(0).startContainer,n=r.nodeType===Node.ELEMENT_NODE?r:r.parentElement;if(n){const o=n.closest('[data-editora-editor="true"], .rte-editor, .editora-editor');if(o)return o}}const t=document.activeElement;return t?t.closest('[data-editora-editor="true"], .rte-editor, .editora-editor'):null}function M(e){const t=window.__editoraLastCommand,c=window.__editoraLastCommandButton;if(t===e&&c&&c.isConnected){const l=window.getComputedStyle(c),s=c.getBoundingClientRect();if(l.display!=="none"&&l.visibility!=="hidden"&&l.pointerEvents!=="none"&&!(s.width===0&&s.height===0))return c}const r=l=>{for(const s of l){const d=window.getComputedStyle(s),p=s.getBoundingClientRect();if(!(d.display==="none"||d.visibility==="hidden"||d.pointerEvents==="none")&&!(p.width===0&&p.height===0))return s}return null},n=P();if(n){const l=Array.from(n.querySelectorAll(`[data-command="${e}"]`)),s=r(l);if(s)return s}const o=Array.from(document.querySelectorAll(`[data-command="${e}"]`));return r(o)}function T(e){if(e?.closest(k))return!0;const t=window.getSelection();if(t&&t.rangeCount>0){const r=t.getRangeAt(0).startContainer;if((r.nodeType===Node.ELEMENT_NODE?r:r.parentElement)?.closest(k))return!0}return document.activeElement?.closest(k)?!0:document.body.matches(k)||document.documentElement.matches(k)}function _(){if(document.getElementById("rte-bg-color-picker-styles"))return;const e=document.createElement("style");e.id="rte-bg-color-picker-styles",e.textContent=`
2
2
  .rte-bg-color-picker {
3
- position: absolute;
3
+ position: fixed;
4
4
  background: white;
5
5
  border-radius: 8px;
6
6
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
@@ -215,4 +215,4 @@
215
215
  .rte-bg-color-picker.rte-theme-dark .rte-bg-color-text-input:focus {
216
216
  border-color: #58a6ff;
217
217
  }
218
- `,document.head.appendChild(e)}function H(){const e=document.createElement("div");e.className="rte-bg-color-picker",T(k)&&e.classList.add("rte-theme-dark"),e.addEventListener("click",m=>m.stopPropagation());const t=document.createElement("div");t.className="rte-bg-color-picker-header";const c=document.createElement("span");c.className="rte-bg-color-picker-title",c.textContent="Background Color";const r=document.createElement("button");r.type="button",r.className="rte-bg-color-picker-close",r.id="rte-bg-color-close",r.setAttribute("aria-label","Close"),r.textContent="×",t.appendChild(c),t.appendChild(r);const a=document.createElement("div");a.className="rte-bg-color-picker-body";const n=document.createElement("div");n.className="rte-bg-color-section";const o=document.createElement("div");o.className="rte-bg-color-section-label",o.textContent="Current Color";const i=document.createElement("div");i.className="rte-bg-color-preview";const d=document.createElement("div");d.className="rte-bg-color-preview-swatch",d.id="rte-bg-color-preview-swatch";const u=document.createElement("span");u.className="rte-bg-color-preview-hex",u.id="rte-bg-color-preview-hex",i.appendChild(d),i.appendChild(u),n.appendChild(o),n.appendChild(i);const x=document.createElement("div");x.className="rte-bg-color-section";const E=document.createElement("div");E.className="rte-bg-color-section-label",E.textContent="Colors";const C=document.createElement("div");C.className="rte-bg-color-grid",C.id="rte-bg-color-grid",A.forEach(m=>{const g=document.createElement("button");g.type="button",g.className="rte-bg-color-swatch",g.style.backgroundColor=m,g.dataset.color=m,g.title=m,C.appendChild(g)}),x.appendChild(E),x.appendChild(C);const w=document.createElement("div");w.className="rte-bg-color-section";const S=document.createElement("div");S.className="rte-bg-color-section-label",S.textContent="Custom";const v=document.createElement("div");v.className="rte-bg-color-custom";const f=document.createElement("input");f.type="color",f.className="rte-bg-color-input",f.id="rte-bg-color-input",f.value=s;const p=document.createElement("input");return p.type="text",p.className="rte-bg-color-text-input",p.id="rte-bg-color-text-input",p.placeholder="#FFFF00",p.value=s.toUpperCase(),p.maxLength=7,v.appendChild(f),v.appendChild(p),w.appendChild(S),w.appendChild(v),a.appendChild(n),a.appendChild(x),a.appendChild(w),e.appendChild(t),e.appendChild(a),e}function U(){if(!l)return;l.querySelector("#rte-bg-color-close")?.addEventListener("click",()=>b());const t=l.querySelector("#rte-bg-color-grid");t&&t.addEventListener("click",n=>{const o=n.target;if(o.classList.contains("rte-bg-color-swatch")){const i=o.dataset.color;i&&(s=i,y(i),b())}});const c=l.querySelector("#rte-bg-color-input");c&&(c.addEventListener("change",n=>{const o=n.target.value.toUpperCase();s=o,y(o),b()}),c.addEventListener("input",n=>{s=n.target.value.toUpperCase(),N(),B()}));const r=l.querySelector("#rte-bg-color-text-input");r&&(r.addEventListener("change",n=>{let o=n.target.value.trim();o&&!o.startsWith("#")&&(o="#"+o),/^#[0-9A-F]{6}$/i.test(o)&&(s=o.toUpperCase(),y(s),b())}),r.addEventListener("input",n=>{let o=n.target.value.trim();o&&!o.startsWith("#")&&(o="#"+o,r.value=o),/^#[0-9A-F]{6}$/i.test(o)&&(s=o.toUpperCase(),N(),B())}));const a=n=>{if(l&&k){const o=n.target;!l.contains(o)&&!k.contains(o)&&b()}};setTimeout(()=>{document.addEventListener("click",a)},100),l._clickOutsideHandler=a}function N(){if(!l)return;const e=l.querySelector("#rte-bg-color-preview-swatch"),t=l.querySelector("#rte-bg-color-preview-hex"),c=l.querySelector("#rte-bg-color-input"),r=l.querySelector("#rte-bg-color-text-input");e&&(e.style.backgroundColor=s),t&&(t.textContent=s.toUpperCase()),c&&(c.value=s),r&&(r.value=s.toUpperCase())}function B(){if(!l)return;l.querySelectorAll(".rte-bg-color-swatch").forEach(t=>{t.dataset.color?.toUpperCase()===s.toUpperCase()?t.classList.add("selected"):t.classList.remove("selected")})}function I(){try{const e=window.getSelection();if(!e||e.rangeCount===0)return"#ffff00";const c=e.getRangeAt(0).commonAncestorContainer,r=c.nodeType===1?c:c.parentElement;if(r){const a=r.closest('[style*="background-color"]');if(a){const n=a.style.backgroundColor;if(n)return O(n)}}return"#ffff00"}catch{return"#ffff00"}}function O(e){if(e.startsWith("#"))return e.toUpperCase();const t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);if(t){const c=parseInt(t[1]),r=parseInt(t[2]),a=parseInt(t[3]);return"#"+[c,r,a].map(n=>{const o=n.toString(16);return o.length===1?"0"+o:o}).join("").toUpperCase()}return"#ffff00"}function y(e){const t=P.applyColorToSelection({color:e,className:"rte-bg-color",styleProperty:"backgroundColor",commands:["hiliteColor","backColor"],savedRange:L,getActiveEditorRoot:M,warnMessage:"[BackgroundColor] Could not apply highlight for current selection"});return t&&console.log("[BackgroundColor] Applied color:",e),t}function b(){if(l){const e=l._clickOutsideHandler;e&&document.removeEventListener("click",e),l.remove(),l=null}k=null,L=null}function _(e,t){const c=e.getBoundingClientRect(),r=t.getBoundingClientRect(),a=r.width||220,n=r.height||320,o=8;let i=c.left;i+a>window.innerWidth-o&&(i=window.innerWidth-a-o),i=Math.max(o,i);let d=c.bottom+o;if(d+n>window.innerHeight-o){const u=c.top-n-o;u>=o?d=u:d=Math.max(o,window.innerHeight-n-o)}t.style.top=`${Math.round(d+window.scrollY)}px`,t.style.left=`${Math.round(i+window.scrollX)}px`}function z(){if(q(),l)return b(),!0;const e=R("openBackgroundColorPicker");if(!e)return!1;const t=window.getSelection();return!t||t.isCollapsed?(alert("Please select text to apply background color"),!1):(t.rangeCount>0&&(L=t.getRangeAt(0).cloneRange()),s=I(),l=H(),document.body.appendChild(l),k=e,_(e,l),N(),B(),U(),!0)}const D=()=>({name:"backgroundColor",marks:{backgroundColor:{attrs:{color:{default:"#ffffff"}},parseDOM:[{tag:'span[style*="background-color"]',getAttrs:e=>{const r=(e.getAttribute("style")||"").match(/background-color:\s*([^;]+)/);return r?{color:r[1]}:null}},{tag:"mark",getAttrs:e=>({color:e.style.backgroundColor||"#ffff00"})}],toDOM:e=>["span",{style:`background-color: ${e.attrs?.color||"#ffffff"}`,class:"rte-bg-color"},0]}},toolbar:[{label:"Background Color",command:"openBackgroundColorPicker",icon:'<svg width="24" height="24" focusable="false"><g fill-rule="evenodd"><path class="tox-icon-highlight-bg-color__color" d="M3 18h18v3H3z" fill="#000000"></path><path fill-rule="nonzero" d="M7.7 16.7H3l3.3-3.3-.7-.8L10.2 8l4 4.1-4 4.2c-.2.2-.6.2-.8 0l-.6-.7-1.1 1.1zm5-7.5L11 7.4l3-2.9a2 2 0 0 1 2.6 0L18 6c.7.7.7 2 0 2.7l-2.9 2.9-1.8-1.8-.5-.6"></path></g></svg>',shortcut:"Mod-Shift-h"}],commands:{openBackgroundColorPicker:()=>z(),setBackgroundColor:e=>e?y(e):!1},keymap:{"Mod-Shift-h":"openBackgroundColorPicker"}});exports.BackgroundColorPlugin=D;
218
+ `,document.head.appendChild(e)}function q(){const e=document.createElement("div");e.className="rte-bg-color-picker",T(N)&&e.classList.add("rte-theme-dark"),e.addEventListener("click",h=>h.stopPropagation());const t=document.createElement("div");t.className="rte-bg-color-picker-header";const c=document.createElement("span");c.className="rte-bg-color-picker-title",c.textContent="Background Color";const r=document.createElement("button");r.type="button",r.className="rte-bg-color-picker-close",r.id="rte-bg-color-close",r.setAttribute("aria-label","Close"),r.textContent="×",t.appendChild(c),t.appendChild(r);const n=document.createElement("div");n.className="rte-bg-color-picker-body";const o=document.createElement("div");o.className="rte-bg-color-section";const l=document.createElement("div");l.className="rte-bg-color-preview";const s=document.createElement("div");s.className="rte-bg-color-preview-swatch",s.id="rte-bg-color-preview-swatch";const d=document.createElement("span");d.className="rte-bg-color-preview-hex",d.id="rte-bg-color-preview-hex",l.appendChild(s),l.appendChild(d),o.appendChild(l);const p=document.createElement("div");p.className="rte-bg-color-section";const y=document.createElement("div");y.className="rte-bg-color-section-label",y.textContent="Colors";const x=document.createElement("div");x.className="rte-bg-color-grid",x.id="rte-bg-color-grid",R.forEach(h=>{const b=document.createElement("button");b.type="button",b.className="rte-bg-color-swatch",b.style.backgroundColor=h,b.dataset.color=h,b.title=h,x.appendChild(b)}),p.appendChild(y),p.appendChild(x);const C=document.createElement("div");C.className="rte-bg-color-section";const E=document.createElement("div");E.className="rte-bg-color-section-label",E.textContent="Custom";const v=document.createElement("div");v.className="rte-bg-color-custom";const m=document.createElement("input");m.type="color",m.className="rte-bg-color-input",m.id="rte-bg-color-input",m.value=i;const u=document.createElement("input");return u.type="text",u.className="rte-bg-color-text-input",u.id="rte-bg-color-text-input",u.placeholder="#FFFF00",u.value=i.toUpperCase(),u.maxLength=7,v.appendChild(m),v.appendChild(u),C.appendChild(E),C.appendChild(v),n.appendChild(o),n.appendChild(p),n.appendChild(C),e.appendChild(t),e.appendChild(n),e}function I(){if(!a)return;a.querySelector("#rte-bg-color-close")?.addEventListener("click",()=>f());const t=a.querySelector("#rte-bg-color-grid");t&&t.addEventListener("click",n=>{const o=n.target;if(o.classList.contains("rte-bg-color-swatch")){const l=o.dataset.color;l&&(i=l,w(l),f())}});const c=a.querySelector("#rte-bg-color-input");c&&(c.addEventListener("change",n=>{const o=n.target.value.toUpperCase();i=o,w(o),f()}),c.addEventListener("input",n=>{i=n.target.value.toUpperCase(),S(),B()}));const r=a.querySelector("#rte-bg-color-text-input");r&&(r.addEventListener("change",n=>{let o=n.target.value.trim();o&&!o.startsWith("#")&&(o="#"+o),/^#[0-9A-F]{6}$/i.test(o)&&(i=o.toUpperCase(),w(i),f())}),r.addEventListener("input",n=>{let o=n.target.value.trim();o&&!o.startsWith("#")&&(o="#"+o,r.value=o),/^#[0-9A-F]{6}$/i.test(o)&&(i=o.toUpperCase(),S(),B())}))}function S(){if(!a)return;const e=a.querySelector("#rte-bg-color-preview-swatch"),t=a.querySelector("#rte-bg-color-preview-hex"),c=a.querySelector("#rte-bg-color-input"),r=a.querySelector("#rte-bg-color-text-input");e&&(e.style.backgroundColor=i),t&&(t.textContent=i.toUpperCase()),c&&(c.value=i),r&&(r.value=i.toUpperCase())}function B(){if(!a)return;a.querySelectorAll(".rte-bg-color-swatch").forEach(t=>{t.dataset.color?.toUpperCase()===i.toUpperCase()?t.classList.add("selected"):t.classList.remove("selected")})}function U(){try{const e=window.getSelection();if(!e||e.rangeCount===0)return"#ffff00";const c=e.getRangeAt(0).commonAncestorContainer,r=c.nodeType===1?c:c.parentElement;if(r){const n=r.closest('[style*="background-color"]');if(n){const o=n.style.backgroundColor;if(o)return z(o)}}return"#ffff00"}catch{return"#ffff00"}}function z(e){if(e.startsWith("#"))return e.toUpperCase();const t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);if(t){const c=parseInt(t[1]),r=parseInt(t[2]),n=parseInt(t[3]);return"#"+[c,r,n].map(o=>{const l=o.toString(16);return l.length===1?"0"+l:l}).join("").toUpperCase()}return"#ffff00"}function w(e){const t=A.applyColorToSelection({color:e,className:"rte-bg-color",styleProperty:"backgroundColor",commands:["hiliteColor","backColor"],savedRange:L,getActiveEditorRoot:P,warnMessage:"[BackgroundColor] Could not apply highlight for current selection"});return t&&console.log("[BackgroundColor] Applied color:",e),t}function f(){g&&(g.destroy(),g=null),a&&(a.remove(),a=null),N=null,L=null}function H(){if(_(),a)return f(),!0;const e=M("openBackgroundColorPicker");if(!e)return!1;const t=window.getSelection();return!t||t.isCollapsed?(alert("Please select text to apply background color"),!1):(t.rangeCount>0&&(L=t.getRangeAt(0).cloneRange()),i=U(),a=q(),document.body.appendChild(a),N=e,g&&(g.destroy(),g=null),g=A.attachAnchoredPopover({popover:a,anchor:e,onClose:f,gap:8,margin:8,zIndex:1e4}),S(),B(),I(),!0)}const O=()=>({name:"backgroundColor",marks:{backgroundColor:{attrs:{color:{default:"#ffffff"}},parseDOM:[{tag:'span[style*="background-color"]',getAttrs:e=>{const r=(e.getAttribute("style")||"").match(/background-color:\s*([^;]+)/);return r?{color:r[1]}:null}},{tag:"mark",getAttrs:e=>({color:e.style.backgroundColor||"#ffff00"})}],toDOM:e=>["span",{style:`background-color: ${e.attrs?.color||"#ffffff"}`,class:"rte-bg-color"},0]}},toolbar:[{label:"Background Color",command:"openBackgroundColorPicker",icon:'<svg width="24" height="24" focusable="false"><g fill-rule="evenodd"><path class="tox-icon-highlight-bg-color__color" d="M3 18h18v3H3z" fill="#000000"></path><path fill-rule="nonzero" d="M7.7 16.7H3l3.3-3.3-.7-.8L10.2 8l4 4.1-4 4.2c-.2.2-.6.2-.8 0l-.6-.7-1.1 1.1zm5-7.5L11 7.4l3-2.9a2 2 0 0 1 2.6 0L18 6c.7.7.7 2 0 2.7l-2.9 2.9-1.8-1.8-.5-.6"></path></g></svg>',shortcut:"Mod-Shift-h"}],commands:{openBackgroundColorPicker:()=>H(),setBackgroundColor:e=>e?w(e):!1},keymap:{"Mod-Shift-h":"openBackgroundColorPicker"}});exports.BackgroundColorPlugin=O;
@@ -1,6 +1,6 @@
1
- import { a as A } from "./colorSelectionApply-D8r_gV32.mjs";
2
- let l = null, k = null, B = null, s = "#ffff00";
3
- const h = '[data-theme="dark"], .dark, .editora-theme-dark', M = [
1
+ import { a as P, b as R } from "./anchoredPopover-Dts0IrgU.mjs";
2
+ let a = null, N = null, g = null, L = null, i = "#ffff00";
3
+ const k = '[data-theme="dark"], .dark, .editora-theme-dark', I = [
4
4
  "#000000",
5
5
  "#ffffff",
6
6
  "#808080",
@@ -14,15 +14,15 @@ const h = '[data-theme="dark"], .dark, .editora-theme-dark', M = [
14
14
  "#800080",
15
15
  "#ffc0cb"
16
16
  ];
17
- function R() {
17
+ function A() {
18
18
  const e = window.getSelection();
19
19
  if (e && e.rangeCount > 0) {
20
- const r = e.getRangeAt(0).startContainer, a = r.nodeType === Node.ELEMENT_NODE ? r : r.parentElement;
21
- if (a) {
22
- const n = a.closest(
20
+ const r = e.getRangeAt(0).startContainer, n = r.nodeType === Node.ELEMENT_NODE ? r : r.parentElement;
21
+ if (n) {
22
+ const o = n.closest(
23
23
  '[data-editora-editor="true"], .rte-editor, .editora-editor'
24
24
  );
25
- if (n) return n;
25
+ if (o) return o;
26
26
  }
27
27
  }
28
28
  const t = document.activeElement;
@@ -30,32 +30,48 @@ function R() {
30
30
  '[data-editora-editor="true"], .rte-editor, .editora-editor'
31
31
  ) : null;
32
32
  }
33
- function P(e) {
34
- const t = R();
35
- if (t) {
36
- const c = t.querySelector(
37
- `[data-command="${e}"]`
38
- );
39
- if (c) return c;
33
+ function M(e) {
34
+ const t = window.__editoraLastCommand, c = window.__editoraLastCommandButton;
35
+ if (t === e && c && c.isConnected) {
36
+ const l = window.getComputedStyle(c), s = c.getBoundingClientRect();
37
+ if (l.display !== "none" && l.visibility !== "hidden" && l.pointerEvents !== "none" && !(s.width === 0 && s.height === 0))
38
+ return c;
39
+ }
40
+ const r = (l) => {
41
+ for (const s of l) {
42
+ const d = window.getComputedStyle(s), p = s.getBoundingClientRect();
43
+ if (!(d.display === "none" || d.visibility === "hidden" || d.pointerEvents === "none") && !(p.width === 0 && p.height === 0))
44
+ return s;
45
+ }
46
+ return null;
47
+ }, n = A();
48
+ if (n) {
49
+ const l = Array.from(
50
+ n.querySelectorAll(`[data-command="${e}"]`)
51
+ ), s = r(l);
52
+ if (s) return s;
40
53
  }
41
- return document.querySelector(`[data-command="${e}"]`);
54
+ const o = Array.from(
55
+ document.querySelectorAll(`[data-command="${e}"]`)
56
+ );
57
+ return r(o);
42
58
  }
43
59
  function T(e) {
44
- if (e?.closest(h)) return !0;
60
+ if (e?.closest(k)) return !0;
45
61
  const t = window.getSelection();
46
62
  if (t && t.rangeCount > 0) {
47
63
  const r = t.getRangeAt(0).startContainer;
48
- if ((r.nodeType === Node.ELEMENT_NODE ? r : r.parentElement)?.closest(h)) return !0;
64
+ if ((r.nodeType === Node.ELEMENT_NODE ? r : r.parentElement)?.closest(k)) return !0;
49
65
  }
50
- return document.activeElement?.closest(h) ? !0 : document.body.matches(h) || document.documentElement.matches(h);
66
+ return document.activeElement?.closest(k) ? !0 : document.body.matches(k) || document.documentElement.matches(k);
51
67
  }
52
- function H() {
68
+ function U() {
53
69
  if (document.getElementById("rte-bg-color-picker-styles"))
54
70
  return;
55
71
  const e = document.createElement("style");
56
72
  e.id = "rte-bg-color-picker-styles", e.textContent = `
57
73
  .rte-bg-color-picker {
58
- position: absolute;
74
+ position: fixed;
59
75
  background: white;
60
76
  border-radius: 8px;
61
77
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
@@ -272,106 +288,95 @@ function H() {
272
288
  }
273
289
  `, document.head.appendChild(e);
274
290
  }
275
- function U() {
291
+ function q() {
276
292
  const e = document.createElement("div");
277
- e.className = "rte-bg-color-picker", T(k) && e.classList.add("rte-theme-dark"), e.addEventListener("click", (m) => m.stopPropagation());
293
+ e.className = "rte-bg-color-picker", T(N) && e.classList.add("rte-theme-dark"), e.addEventListener("click", (h) => h.stopPropagation());
278
294
  const t = document.createElement("div");
279
295
  t.className = "rte-bg-color-picker-header";
280
296
  const c = document.createElement("span");
281
297
  c.className = "rte-bg-color-picker-title", c.textContent = "Background Color";
282
298
  const r = document.createElement("button");
283
299
  r.type = "button", r.className = "rte-bg-color-picker-close", r.id = "rte-bg-color-close", r.setAttribute("aria-label", "Close"), r.textContent = "×", t.appendChild(c), t.appendChild(r);
284
- const a = document.createElement("div");
285
- a.className = "rte-bg-color-picker-body";
286
300
  const n = document.createElement("div");
287
- n.className = "rte-bg-color-section";
301
+ n.className = "rte-bg-color-picker-body";
288
302
  const o = document.createElement("div");
289
- o.className = "rte-bg-color-section-label", o.textContent = "Current Color";
290
- const i = document.createElement("div");
291
- i.className = "rte-bg-color-preview";
292
- const d = document.createElement("div");
293
- d.className = "rte-bg-color-preview-swatch", d.id = "rte-bg-color-preview-swatch";
294
- const u = document.createElement("span");
295
- u.className = "rte-bg-color-preview-hex", u.id = "rte-bg-color-preview-hex", i.appendChild(d), i.appendChild(u), n.appendChild(o), n.appendChild(i);
303
+ o.className = "rte-bg-color-section";
304
+ const l = document.createElement("div");
305
+ l.className = "rte-bg-color-preview";
306
+ const s = document.createElement("div");
307
+ s.className = "rte-bg-color-preview-swatch", s.id = "rte-bg-color-preview-swatch";
308
+ const d = document.createElement("span");
309
+ d.className = "rte-bg-color-preview-hex", d.id = "rte-bg-color-preview-hex", l.appendChild(s), l.appendChild(d), o.appendChild(l);
310
+ const p = document.createElement("div");
311
+ p.className = "rte-bg-color-section";
312
+ const y = document.createElement("div");
313
+ y.className = "rte-bg-color-section-label", y.textContent = "Colors";
296
314
  const x = document.createElement("div");
297
- x.className = "rte-bg-color-section";
298
- const E = document.createElement("div");
299
- E.className = "rte-bg-color-section-label", E.textContent = "Colors";
315
+ x.className = "rte-bg-color-grid", x.id = "rte-bg-color-grid", I.forEach((h) => {
316
+ const b = document.createElement("button");
317
+ b.type = "button", b.className = "rte-bg-color-swatch", b.style.backgroundColor = h, b.dataset.color = h, b.title = h, x.appendChild(b);
318
+ }), p.appendChild(y), p.appendChild(x);
300
319
  const C = document.createElement("div");
301
- C.className = "rte-bg-color-grid", C.id = "rte-bg-color-grid", M.forEach((m) => {
302
- const g = document.createElement("button");
303
- g.type = "button", g.className = "rte-bg-color-swatch", g.style.backgroundColor = m, g.dataset.color = m, g.title = m, C.appendChild(g);
304
- }), x.appendChild(E), x.appendChild(C);
320
+ C.className = "rte-bg-color-section";
321
+ const E = document.createElement("div");
322
+ E.className = "rte-bg-color-section-label", E.textContent = "Custom";
305
323
  const w = document.createElement("div");
306
- w.className = "rte-bg-color-section";
307
- const S = document.createElement("div");
308
- S.className = "rte-bg-color-section-label", S.textContent = "Custom";
309
- const v = document.createElement("div");
310
- v.className = "rte-bg-color-custom";
311
- const f = document.createElement("input");
312
- f.type = "color", f.className = "rte-bg-color-input", f.id = "rte-bg-color-input", f.value = s;
313
- const p = document.createElement("input");
314
- return p.type = "text", p.className = "rte-bg-color-text-input", p.id = "rte-bg-color-text-input", p.placeholder = "#FFFF00", p.value = s.toUpperCase(), p.maxLength = 7, v.appendChild(f), v.appendChild(p), w.appendChild(S), w.appendChild(v), a.appendChild(n), a.appendChild(x), a.appendChild(w), e.appendChild(t), e.appendChild(a), e;
324
+ w.className = "rte-bg-color-custom";
325
+ const m = document.createElement("input");
326
+ m.type = "color", m.className = "rte-bg-color-input", m.id = "rte-bg-color-input", m.value = i;
327
+ const u = document.createElement("input");
328
+ return u.type = "text", u.className = "rte-bg-color-text-input", u.id = "rte-bg-color-text-input", u.placeholder = "#FFFF00", u.value = i.toUpperCase(), u.maxLength = 7, w.appendChild(m), w.appendChild(u), C.appendChild(E), C.appendChild(w), n.appendChild(o), n.appendChild(p), n.appendChild(C), e.appendChild(t), e.appendChild(n), e;
315
329
  }
316
- function q() {
317
- if (!l) return;
318
- l.querySelector("#rte-bg-color-close")?.addEventListener("click", () => b());
319
- const t = l.querySelector("#rte-bg-color-grid");
330
+ function _() {
331
+ if (!a) return;
332
+ a.querySelector("#rte-bg-color-close")?.addEventListener("click", () => f());
333
+ const t = a.querySelector("#rte-bg-color-grid");
320
334
  t && t.addEventListener("click", (n) => {
321
335
  const o = n.target;
322
336
  if (o.classList.contains("rte-bg-color-swatch")) {
323
- const i = o.dataset.color;
324
- i && (s = i, y(i), b());
337
+ const l = o.dataset.color;
338
+ l && (i = l, v(l), f());
325
339
  }
326
340
  });
327
- const c = l.querySelector("#rte-bg-color-input");
341
+ const c = a.querySelector("#rte-bg-color-input");
328
342
  c && (c.addEventListener("change", (n) => {
329
343
  const o = n.target.value.toUpperCase();
330
- s = o, y(o), b();
344
+ i = o, v(o), f();
331
345
  }), c.addEventListener("input", (n) => {
332
- s = n.target.value.toUpperCase(), N(), L();
346
+ i = n.target.value.toUpperCase(), S(), B();
333
347
  }));
334
- const r = l.querySelector("#rte-bg-color-text-input");
348
+ const r = a.querySelector("#rte-bg-color-text-input");
335
349
  r && (r.addEventListener("change", (n) => {
336
350
  let o = n.target.value.trim();
337
- o && !o.startsWith("#") && (o = "#" + o), /^#[0-9A-F]{6}$/i.test(o) && (s = o.toUpperCase(), y(s), b());
351
+ o && !o.startsWith("#") && (o = "#" + o), /^#[0-9A-F]{6}$/i.test(o) && (i = o.toUpperCase(), v(i), f());
338
352
  }), r.addEventListener("input", (n) => {
339
353
  let o = n.target.value.trim();
340
- o && !o.startsWith("#") && (o = "#" + o, r.value = o), /^#[0-9A-F]{6}$/i.test(o) && (s = o.toUpperCase(), N(), L());
354
+ o && !o.startsWith("#") && (o = "#" + o, r.value = o), /^#[0-9A-F]{6}$/i.test(o) && (i = o.toUpperCase(), S(), B());
341
355
  }));
342
- const a = (n) => {
343
- if (l && k) {
344
- const o = n.target;
345
- !l.contains(o) && !k.contains(o) && b();
346
- }
347
- };
348
- setTimeout(() => {
349
- document.addEventListener("click", a);
350
- }, 100), l._clickOutsideHandler = a;
351
356
  }
352
- function N() {
353
- if (!l) return;
354
- const e = l.querySelector("#rte-bg-color-preview-swatch"), t = l.querySelector("#rte-bg-color-preview-hex"), c = l.querySelector("#rte-bg-color-input"), r = l.querySelector("#rte-bg-color-text-input");
355
- e && (e.style.backgroundColor = s), t && (t.textContent = s.toUpperCase()), c && (c.value = s), r && (r.value = s.toUpperCase());
357
+ function S() {
358
+ if (!a) return;
359
+ const e = a.querySelector("#rte-bg-color-preview-swatch"), t = a.querySelector("#rte-bg-color-preview-hex"), c = a.querySelector("#rte-bg-color-input"), r = a.querySelector("#rte-bg-color-text-input");
360
+ e && (e.style.backgroundColor = i), t && (t.textContent = i.toUpperCase()), c && (c.value = i), r && (r.value = i.toUpperCase());
356
361
  }
357
- function L() {
358
- if (!l) return;
359
- l.querySelectorAll(".rte-bg-color-swatch").forEach((t) => {
360
- t.dataset.color?.toUpperCase() === s.toUpperCase() ? t.classList.add("selected") : t.classList.remove("selected");
362
+ function B() {
363
+ if (!a) return;
364
+ a.querySelectorAll(".rte-bg-color-swatch").forEach((t) => {
365
+ t.dataset.color?.toUpperCase() === i.toUpperCase() ? t.classList.add("selected") : t.classList.remove("selected");
361
366
  });
362
367
  }
363
- function I() {
368
+ function z() {
364
369
  try {
365
370
  const e = window.getSelection();
366
371
  if (!e || e.rangeCount === 0)
367
372
  return "#ffff00";
368
373
  const c = e.getRangeAt(0).commonAncestorContainer, r = c.nodeType === 1 ? c : c.parentElement;
369
374
  if (r) {
370
- const a = r.closest('[style*="background-color"]');
371
- if (a) {
372
- const n = a.style.backgroundColor;
373
- if (n)
374
- return O(n);
375
+ const n = r.closest('[style*="background-color"]');
376
+ if (n) {
377
+ const o = n.style.backgroundColor;
378
+ if (o)
379
+ return H(o);
375
380
  }
376
381
  }
377
382
  return "#ffff00";
@@ -379,59 +384,51 @@ function I() {
379
384
  return "#ffff00";
380
385
  }
381
386
  }
382
- function O(e) {
387
+ function H(e) {
383
388
  if (e.startsWith("#"))
384
389
  return e.toUpperCase();
385
390
  const t = e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
386
391
  if (t) {
387
- const c = parseInt(t[1]), r = parseInt(t[2]), a = parseInt(t[3]);
388
- return "#" + [c, r, a].map((n) => {
389
- const o = n.toString(16);
390
- return o.length === 1 ? "0" + o : o;
392
+ const c = parseInt(t[1]), r = parseInt(t[2]), n = parseInt(t[3]);
393
+ return "#" + [c, r, n].map((o) => {
394
+ const l = o.toString(16);
395
+ return l.length === 1 ? "0" + l : l;
391
396
  }).join("").toUpperCase();
392
397
  }
393
398
  return "#ffff00";
394
399
  }
395
- function y(e) {
396
- const t = A({
400
+ function v(e) {
401
+ const t = P({
397
402
  color: e,
398
403
  className: "rte-bg-color",
399
404
  styleProperty: "backgroundColor",
400
405
  commands: ["hiliteColor", "backColor"],
401
- savedRange: B,
402
- getActiveEditorRoot: R,
406
+ savedRange: L,
407
+ getActiveEditorRoot: A,
403
408
  warnMessage: "[BackgroundColor] Could not apply highlight for current selection"
404
409
  });
405
410
  return t && console.log("[BackgroundColor] Applied color:", e), t;
406
411
  }
407
- function b() {
408
- if (l) {
409
- const e = l._clickOutsideHandler;
410
- e && document.removeEventListener("click", e), l.remove(), l = null;
411
- }
412
- k = null, B = null;
413
- }
414
- function z(e, t) {
415
- const c = e.getBoundingClientRect(), r = t.getBoundingClientRect(), a = r.width || 220, n = r.height || 320, o = 8;
416
- let i = c.left;
417
- i + a > window.innerWidth - o && (i = window.innerWidth - a - o), i = Math.max(o, i);
418
- let d = c.bottom + o;
419
- if (d + n > window.innerHeight - o) {
420
- const u = c.top - n - o;
421
- u >= o ? d = u : d = Math.max(o, window.innerHeight - n - o);
422
- }
423
- t.style.top = `${Math.round(d + window.scrollY)}px`, t.style.left = `${Math.round(i + window.scrollX)}px`;
412
+ function f() {
413
+ g && (g.destroy(), g = null), a && (a.remove(), a = null), N = null, L = null;
424
414
  }
425
- function _() {
426
- if (H(), l)
427
- return b(), !0;
428
- const e = P("openBackgroundColorPicker");
415
+ function D() {
416
+ if (U(), a)
417
+ return f(), !0;
418
+ const e = M("openBackgroundColorPicker");
429
419
  if (!e)
430
420
  return !1;
431
421
  const t = window.getSelection();
432
- return !t || t.isCollapsed ? (alert("Please select text to apply background color"), !1) : (t.rangeCount > 0 && (B = t.getRangeAt(0).cloneRange()), s = I(), l = U(), document.body.appendChild(l), k = e, z(e, l), N(), L(), q(), !0);
422
+ return !t || t.isCollapsed ? (alert("Please select text to apply background color"), !1) : (t.rangeCount > 0 && (L = t.getRangeAt(0).cloneRange()), i = z(), a = q(), document.body.appendChild(a), N = e, g && (g.destroy(), g = null), g = R({
423
+ popover: a,
424
+ anchor: e,
425
+ onClose: f,
426
+ gap: 8,
427
+ margin: 8,
428
+ zIndex: 1e4
429
+ }), S(), B(), _(), !0);
433
430
  }
434
- const F = () => ({
431
+ const O = () => ({
435
432
  name: "backgroundColor",
436
433
  marks: {
437
434
  backgroundColor: {
@@ -470,13 +467,13 @@ const F = () => ({
470
467
  }
471
468
  ],
472
469
  commands: {
473
- openBackgroundColorPicker: () => _(),
474
- setBackgroundColor: (e) => e ? y(e) : !1
470
+ openBackgroundColorPicker: () => D(),
471
+ setBackgroundColor: (e) => e ? v(e) : !1
475
472
  },
476
473
  keymap: {
477
474
  "Mod-Shift-h": "openBackgroundColorPicker"
478
475
  }
479
476
  });
480
477
  export {
481
- F as BackgroundColorPlugin
478
+ O as BackgroundColorPlugin
482
479
  };