@editora/plugins 1.0.2 → 1.0.4
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/README.md +30 -5
- package/dist/a11y-checker.cjs.js +109 -0
- package/dist/a11y-checker.esm.js +509 -0
- package/dist/anchor.cjs.js +176 -0
- package/dist/anchor.esm.js +400 -0
- package/dist/background-color.cjs.js +218 -0
- package/dist/background-color.esm.js +482 -0
- package/dist/blockquote.cjs.js +1 -0
- package/dist/blockquote.esm.js +47 -0
- package/dist/bold.cjs.js +1 -0
- package/dist/bold.esm.js +44 -0
- package/dist/capitalization.cjs.js +1 -0
- package/dist/capitalization.esm.js +78 -0
- package/dist/checklist.cjs.js +1 -0
- package/dist/checklist.esm.js +305 -0
- package/dist/clear-formatting.cjs.js +1 -0
- package/dist/clear-formatting.esm.js +138 -0
- package/dist/code-sample.cjs.js +161 -0
- package/dist/code-sample.esm.js +381 -0
- package/dist/code.cjs.js +598 -0
- package/dist/code.esm.js +2034 -0
- package/dist/colorSelectionApply-C0iOfMWb.js +1 -0
- package/dist/colorSelectionApply-D8r_gV32.mjs +63 -0
- package/dist/comments.cjs.js +354 -0
- package/dist/comments.esm.js +692 -0
- package/dist/direction.cjs.js +1 -0
- package/dist/direction.esm.js +129 -0
- package/dist/document-manager.cjs.js +1 -0
- package/dist/document-manager.esm.js +6 -0
- package/dist/{documentManager-CYC9totK.mjs → documentManager-DRUc1-Cs.mjs} +3 -3
- package/dist/{documentManager-BGlu3WRB.js → documentManager-_tQQfQi9.js} +3 -3
- package/dist/editorContainerHelpers-C7kdWnS0.mjs +26 -0
- package/dist/editorContainerHelpers-CFbfiOJI.js +1 -0
- package/dist/embed-iframe.cjs.js +361 -0
- package/dist/embed-iframe.esm.js +556 -0
- package/dist/emojis.cjs.js +284 -0
- package/dist/emojis.esm.js +1080 -0
- package/dist/font-family.cjs.js +1 -0
- package/dist/font-family.esm.js +152 -0
- package/dist/font-size.cjs.js +1 -0
- package/dist/font-size.esm.js +278 -0
- package/dist/footnote.cjs.js +85 -0
- package/dist/footnote.esm.js +397 -0
- package/dist/fullscreen.cjs.js +1 -0
- package/dist/fullscreen.esm.js +73 -0
- package/dist/heading.cjs.js +1 -0
- package/dist/heading.esm.js +63 -0
- package/dist/history.cjs.js +1 -0
- package/dist/history.esm.js +246 -0
- package/dist/indent.cjs.js +1 -0
- package/dist/indent.esm.js +146 -0
- package/dist/index-Bskk414V.mjs +145 -0
- package/dist/index-D3pJyAsj.js +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/{index.es-B-to-4j4.js → index.es-Cz1qItab.js} +1 -1
- package/dist/{index.es-BbXJ7tyO.mjs → index.es-DEcRmSTY.mjs} +1 -1
- package/dist/index.esm.js +89 -49
- package/dist/italic.cjs.js +1 -0
- package/dist/italic.esm.js +40 -0
- package/dist/line-height.cjs.js +1 -0
- package/dist/line-height.esm.js +145 -0
- package/dist/link.cjs.js +138 -0
- package/dist/link.esm.js +276 -0
- package/dist/list.cjs.js +1 -0
- package/dist/list.esm.js +102 -0
- package/dist/lite.cjs.js +1 -0
- package/dist/lite.esm.js +61 -0
- package/dist/math.cjs.js +45 -0
- package/dist/math.esm.js +249 -0
- package/dist/media-manager.cjs.js +619 -0
- package/dist/media-manager.esm.js +994 -0
- package/dist/merge-tag.cjs.js +93 -0
- package/dist/merge-tag.esm.js +412 -0
- package/dist/page-break.cjs.js +72 -0
- package/dist/page-break.esm.js +295 -0
- package/dist/plugins.css +1 -1
- package/dist/preview.cjs.js +230 -0
- package/dist/preview.esm.js +321 -0
- package/dist/print.cjs.js +254 -0
- package/dist/print.esm.js +309 -0
- package/dist/purify.es-DHhaBdbu.mjs +470 -0
- package/dist/purify.es-T2a3nLiC.js +3 -0
- package/dist/shared-config.cjs.js +1 -0
- package/dist/shared-config.esm.js +30 -0
- package/dist/special-characters.cjs.js +257 -0
- package/dist/special-characters.esm.js +772 -0
- package/dist/spell-check.cjs.js +512 -0
- package/dist/spell-check.esm.js +1013 -0
- package/dist/strikethrough.cjs.js +1 -0
- package/dist/strikethrough.esm.js +71 -0
- package/dist/table.cjs.js +35 -0
- package/dist/table.esm.js +477 -0
- package/dist/template.cjs.js +356 -0
- package/dist/template.esm.js +560 -0
- package/dist/text-alignment.cjs.js +1 -0
- package/dist/text-alignment.esm.js +105 -0
- package/dist/text-color.cjs.js +300 -0
- package/dist/text-color.esm.js +507 -0
- package/dist/underline.cjs.js +1 -0
- package/dist/underline.esm.js +34 -0
- package/index.d.ts +62 -0
- package/package.json +218 -6
- package/LICENSE +0 -21
- package/dist/index-BbORIHoM.mjs +0 -11763
- package/dist/index-C-OCBS_6.js +0 -3753
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=()=>({name:"fontFamily",marks:{fontFamily:{attrs:{family:{default:null}},parseDOM:[{tag:'span[style*="font-family"]',getAttrs:e=>{const t=e.style.fontFamily;return t?{family:t}:!1}},{tag:"font[face]",getAttrs:e=>{const t=e.getAttribute("face");return t?{family:t}:!1}}],toDOM:e=>["span",{style:`font-family: ${e.attrs?.family}`},0]}},toolbar:[{label:"Font Family",command:"setFontFamily",type:"inline-menu",options:[{label:"Arial",value:"Arial, sans-serif"},{label:"Times New Roman",value:"Times New Roman, serif"},{label:"Courier New",value:"Courier New, monospace"},{label:"Georgia",value:"Georgia, serif"},{label:"Verdana",value:"Verdana, sans-serif"},{label:"Helvetica",value:"Helvetica, Arial, sans-serif"},{label:"Trebuchet MS",value:"Trebuchet MS, sans-serif"},{label:"Impact",value:"Impact, sans-serif"}],icon:'<svg fill="#000000" width="24px" height="24px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path d="M15 4h7v2h-7zm1 4h6v2h-6zm2 4h4v2h-4zM9.307 4l-6 16h2.137l1.875-5h6.363l1.875 5h2.137l-6-16H9.307zm-1.239 9L10.5 6.515 12.932 13H8.068z"></path></g></svg>'}],commands:{setFontFamily:e=>{if(!e)return!1;try{return b(e),!0}catch(n){return console.error("Failed to set font family:",n),!1}}},keymap:{"Mod-Shift-f":"setFontFamily"}}),p="p,div,li,ul,ol,table,thead,tbody,tfoot,tr,td,th,h1,h2,h3,h4,h5,h6,blockquote,pre";function h(e){return!!e.cloneContents().querySelector(p)}function g(e){return(e.nodeType===Node.ELEMENT_NODE?e:e.parentElement)?.closest('[contenteditable="true"]')||document.querySelector('[contenteditable="true"]')}function f(e){e&&e.dispatchEvent(new Event("input",{bubbles:!0}))}function S(e,n){const t=document.createElement("span");for(const a of Array.from(e.attributes))a.name==="face"||a.name==="style"||t.setAttribute(a.name,a.value);const o=e.getAttribute("style");for(o&&t.setAttribute("style",o),t.style.fontFamily=n,t.classList.add("rte-font-family");e.firstChild;)t.appendChild(e.firstChild);e.parentNode?.replaceChild(t,e)}function A(e){e.querySelectorAll("span").forEach(t=>{t.childElementCount>0||(t.textContent||"").trim().length>0||t.remove()})}function C(e,n,t){if(h(e))return!1;const o=document.createElement("span");o.style.fontFamily=t,o.className="rte-font-family";try{e.surroundContents(o)}catch{const l=e.extractContents();o.appendChild(l),e.insertNode(o)}const a=document.createRange();return a.selectNodeContents(o),n.removeAllRanges(),n.addRange(a),!0}function b(e){const n=window.getSelection();if(!n||n.rangeCount===0)return;const t=n.getRangeAt(0),o=t.cloneRange(),a=g(t.commonAncestorContainer);if(t.collapsed)return;const l=t.commonAncestorContainer,i=F(l);if(i&&v(t,i)){i.style.fontFamily=e,i.classList.add("rte-font-family");const r=document.createRange();r.selectNodeContents(i),n.removeAllRanges(),n.addRange(r),f(a);return}if(!a)return;const m=new Set(Array.from(a.querySelectorAll("font[face]"))),u=new Set(Array.from(a.querySelectorAll("span[style*='font-family']")));a.focus({preventScroll:!0});try{document.execCommand("styleWithCSS",!1,"true")}catch{}const d=e.split(",").map(r=>r.trim().replace(/^['"]|['"]$/g,"")).filter(Boolean)[0]||"Arial";let s=document.execCommand("fontName",!1,d),c=!1;Array.from(a.querySelectorAll("font[face]")).forEach(r=>{m.has(r)||(S(r,e),c=!0)}),Array.from(a.querySelectorAll("span[style*='font-family']")).forEach(r=>{u.has(r)||(r.style.fontFamily=e,r.classList.add("rte-font-family"),c=!0)}),s||(s=C(o,n,e)),(s||c)&&(A(a),f(a))}function F(e){let n=e;for(;n;){if(n.nodeType===Node.ELEMENT_NODE){const t=n;if(t.tagName==="SPAN"&&t.style.fontFamily)return t}n=n.parentNode}return null}function v(e,n){const t=e.startContainer,o=e.endContainer,a=n.contains(t)||t.nodeType===Node.TEXT_NODE&&t.parentElement===n,l=n.contains(o)||o.nodeType===Node.TEXT_NODE&&o.parentElement===n;return a&&l}exports.FontFamilyPlugin=y;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
const E = () => ({
|
|
2
|
+
name: "fontFamily",
|
|
3
|
+
marks: {
|
|
4
|
+
fontFamily: {
|
|
5
|
+
attrs: {
|
|
6
|
+
family: { default: null }
|
|
7
|
+
},
|
|
8
|
+
parseDOM: [
|
|
9
|
+
{
|
|
10
|
+
tag: 'span[style*="font-family"]',
|
|
11
|
+
getAttrs: (e) => {
|
|
12
|
+
const t = e.style.fontFamily;
|
|
13
|
+
return t ? { family: t } : !1;
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
tag: "font[face]",
|
|
18
|
+
getAttrs: (e) => {
|
|
19
|
+
const t = e.getAttribute("face");
|
|
20
|
+
return t ? { family: t } : !1;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
toDOM: (e) => ["span", { style: `font-family: ${e.attrs?.family}` }, 0]
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
toolbar: [
|
|
28
|
+
{
|
|
29
|
+
label: "Font Family",
|
|
30
|
+
command: "setFontFamily",
|
|
31
|
+
type: "inline-menu",
|
|
32
|
+
options: [
|
|
33
|
+
{ label: "Arial", value: "Arial, sans-serif" },
|
|
34
|
+
{ label: "Times New Roman", value: "Times New Roman, serif" },
|
|
35
|
+
{ label: "Courier New", value: "Courier New, monospace" },
|
|
36
|
+
{ label: "Georgia", value: "Georgia, serif" },
|
|
37
|
+
{ label: "Verdana", value: "Verdana, sans-serif" },
|
|
38
|
+
{ label: "Helvetica", value: "Helvetica, Arial, sans-serif" },
|
|
39
|
+
{ label: "Trebuchet MS", value: "Trebuchet MS, sans-serif" },
|
|
40
|
+
{ label: "Impact", value: "Impact, sans-serif" }
|
|
41
|
+
],
|
|
42
|
+
icon: '<svg fill="#000000" width="24px" height="24px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path d="M15 4h7v2h-7zm1 4h6v2h-6zm2 4h4v2h-4zM9.307 4l-6 16h2.137l1.875-5h6.363l1.875 5h2.137l-6-16H9.307zm-1.239 9L10.5 6.515 12.932 13H8.068z"></path></g></svg>'
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
commands: {
|
|
46
|
+
setFontFamily: (e) => {
|
|
47
|
+
if (!e) return !1;
|
|
48
|
+
try {
|
|
49
|
+
return C(e), !0;
|
|
50
|
+
} catch (n) {
|
|
51
|
+
return console.error("Failed to set font family:", n), !1;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
keymap: {
|
|
56
|
+
"Mod-Shift-f": "setFontFamily"
|
|
57
|
+
}
|
|
58
|
+
}), y = "p,div,li,ul,ol,table,thead,tbody,tfoot,tr,td,th,h1,h2,h3,h4,h5,h6,blockquote,pre";
|
|
59
|
+
function p(e) {
|
|
60
|
+
return !!e.cloneContents().querySelector(y);
|
|
61
|
+
}
|
|
62
|
+
function h(e) {
|
|
63
|
+
return (e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement)?.closest('[contenteditable="true"]') || document.querySelector('[contenteditable="true"]');
|
|
64
|
+
}
|
|
65
|
+
function f(e) {
|
|
66
|
+
e && e.dispatchEvent(new Event("input", { bubbles: !0 }));
|
|
67
|
+
}
|
|
68
|
+
function g(e, n) {
|
|
69
|
+
const t = document.createElement("span");
|
|
70
|
+
for (const a of Array.from(e.attributes))
|
|
71
|
+
a.name === "face" || a.name === "style" || t.setAttribute(a.name, a.value);
|
|
72
|
+
const r = e.getAttribute("style");
|
|
73
|
+
for (r && t.setAttribute("style", r), t.style.fontFamily = n, t.classList.add("rte-font-family"); e.firstChild; )
|
|
74
|
+
t.appendChild(e.firstChild);
|
|
75
|
+
e.parentNode?.replaceChild(t, e);
|
|
76
|
+
}
|
|
77
|
+
function S(e) {
|
|
78
|
+
e.querySelectorAll("span").forEach((t) => {
|
|
79
|
+
t.childElementCount > 0 || (t.textContent || "").trim().length > 0 || t.remove();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function A(e, n, t) {
|
|
83
|
+
if (p(e))
|
|
84
|
+
return !1;
|
|
85
|
+
const r = document.createElement("span");
|
|
86
|
+
r.style.fontFamily = t, r.className = "rte-font-family";
|
|
87
|
+
try {
|
|
88
|
+
e.surroundContents(r);
|
|
89
|
+
} catch {
|
|
90
|
+
const l = e.extractContents();
|
|
91
|
+
r.appendChild(l), e.insertNode(r);
|
|
92
|
+
}
|
|
93
|
+
const a = document.createRange();
|
|
94
|
+
return a.selectNodeContents(r), n.removeAllRanges(), n.addRange(a), !0;
|
|
95
|
+
}
|
|
96
|
+
function C(e) {
|
|
97
|
+
const n = window.getSelection();
|
|
98
|
+
if (!n || n.rangeCount === 0) return;
|
|
99
|
+
const t = n.getRangeAt(0), r = t.cloneRange(), a = h(t.commonAncestorContainer);
|
|
100
|
+
if (t.collapsed)
|
|
101
|
+
return;
|
|
102
|
+
const l = t.commonAncestorContainer, s = b(l);
|
|
103
|
+
if (s && F(t, s)) {
|
|
104
|
+
s.style.fontFamily = e, s.classList.add("rte-font-family");
|
|
105
|
+
const o = document.createRange();
|
|
106
|
+
o.selectNodeContents(s), n.removeAllRanges(), n.addRange(o), f(a);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (!a) return;
|
|
110
|
+
const m = new Set(
|
|
111
|
+
Array.from(a.querySelectorAll("font[face]"))
|
|
112
|
+
), u = new Set(
|
|
113
|
+
Array.from(
|
|
114
|
+
a.querySelectorAll("span[style*='font-family']")
|
|
115
|
+
)
|
|
116
|
+
);
|
|
117
|
+
a.focus({ preventScroll: !0 });
|
|
118
|
+
try {
|
|
119
|
+
document.execCommand("styleWithCSS", !1, "true");
|
|
120
|
+
} catch {
|
|
121
|
+
}
|
|
122
|
+
const d = e.split(",").map((o) => o.trim().replace(/^['"]|['"]$/g, "")).filter(Boolean)[0] || "Arial";
|
|
123
|
+
let i = document.execCommand("fontName", !1, d), c = !1;
|
|
124
|
+
Array.from(
|
|
125
|
+
a.querySelectorAll("font[face]")
|
|
126
|
+
).forEach((o) => {
|
|
127
|
+
m.has(o) || (g(o, e), c = !0);
|
|
128
|
+
}), Array.from(
|
|
129
|
+
a.querySelectorAll("span[style*='font-family']")
|
|
130
|
+
).forEach((o) => {
|
|
131
|
+
u.has(o) || (o.style.fontFamily = e, o.classList.add("rte-font-family"), c = !0);
|
|
132
|
+
}), i || (i = A(r, n, e)), (i || c) && (S(a), f(a));
|
|
133
|
+
}
|
|
134
|
+
function b(e) {
|
|
135
|
+
let n = e;
|
|
136
|
+
for (; n; ) {
|
|
137
|
+
if (n.nodeType === Node.ELEMENT_NODE) {
|
|
138
|
+
const t = n;
|
|
139
|
+
if (t.tagName === "SPAN" && t.style.fontFamily)
|
|
140
|
+
return t;
|
|
141
|
+
}
|
|
142
|
+
n = n.parentNode;
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
function F(e, n) {
|
|
147
|
+
const t = e.startContainer, r = e.endContainer, a = n.contains(t) || t.nodeType === Node.TEXT_NODE && t.parentElement === n, l = n.contains(r) || r.nodeType === Node.TEXT_NODE && r.parentElement === n;
|
|
148
|
+
return a && l;
|
|
149
|
+
}
|
|
150
|
+
export {
|
|
151
|
+
E as FontFamilyPlugin
|
|
152
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=()=>({name:"fontSize",marks:{fontSize:{attrs:{size:{default:null}},parseDOM:[{tag:'span[style*="font-size"]',getAttrs:e=>{const t=e.style.fontSize;return t?{size:t}:!1}},{tag:"font[size]",getAttrs:e=>{const t=e.getAttribute("size");return t?{size:t}:!1}}],toDOM:e=>["span",{style:`font-size: ${e.attrs?.size}`},0]}},toolbar:[{label:"Font Size",command:"fontSize",type:"group",items:[{label:"Decrease Font Size",command:"decreaseFontSize",icon:"−",type:"button"},{label:"Font Size",command:"setFontSize",type:"input",placeholder:"14"},{label:"Increase Font Size",command:"increaseFontSize",icon:"+",type:"button"}]}],commands:{decreaseFontSize:()=>{try{return g(-2),y(),!0}catch(e){return console.error("Failed to decrease font size:",e),!1}},increaseFontSize:()=>{try{return g(2),y(),!0}catch(e){return console.error("Failed to increase font size:",e),!1}},setFontSize:e=>{if(!e)return!1;try{const t=e.trim().match(/^(\d+(?:\.\d+)?)(px|em|rem)?$/i);if(!t)return!1;const n=parseFloat(t[1]),i=t[2]?.toLowerCase()||"px";return i==="px"&&(n<8||n>72)||(i==="em"||i==="rem")&&(n<.5||n>5)?!1:(C(n,i),!0)}catch(o){return console.error("Failed to set font size:",o),!1}}},keymap:{}}),A="p,div,li,ul,ol,table,thead,tbody,tfoot,tr,td,th,h1,h2,h3,h4,h5,h6,blockquote,pre",z={"xx-small":9,"x-small":10,small:13,medium:16,large:18,"x-large":24,"xx-large":32,"xxx-large":48,smaller:13,larger:18};function p(e){const o=e.trim().toLowerCase(),t=o.match(/^(\d+(?:\.\d+)?)(px|em|rem)$/i);if(t)return{value:parseFloat(t[1]),unit:t[2].toLowerCase()};const n=z[o];return n?{value:n,unit:"px"}:null}function N(e){return e.trim().toLowerCase()in z}function x(e){return!!e.cloneContents().querySelector(A)}function w(e){return(e.nodeType===Node.ELEMENT_NODE?e:e.parentElement)?.closest('[contenteditable="true"]')||document.querySelector('[contenteditable="true"]')}function m(e){e&&e.dispatchEvent(new Event("input",{bubbles:!0}))}function E(e,o){const t=document.createElement("span");for(const i of Array.from(e.attributes))i.name==="size"||i.name==="style"||t.setAttribute(i.name,i.value);const n=e.getAttribute("style");for(n&&t.setAttribute("style",n),t.style.fontSize=o;e.firstChild;)t.appendChild(e.firstChild);e.parentNode?.replaceChild(t,e)}function T(e,o,t,n){const i=Array.from(e.querySelectorAll("font[size], [style*='font-size']")),r=s=>{if(!n||!s.isConnected)return!1;try{if(typeof n.intersectsNode=="function")return n.intersectsNode(s)}catch{}const a=document.createRange();return a.selectNodeContents(s),n.compareBoundaryPoints(Range.END_TO_START,a)>0&&n.compareBoundaryPoints(Range.START_TO_END,a)<0};let c=!1;return i.forEach(s=>{const a=!o.has(s),u=s.tagName==="FONT",l=N(s.style.fontSize||""),f=r(s);if(!(!a&&!f)&&!(!a&&!u&&!l)){if(c=!0,s.tagName==="FONT"){E(s,t);return}s.style.fontSize=t}}),c}function S(e){e.querySelectorAll("span").forEach(t=>{t.childElementCount>0||(t.textContent||"").trim().length>0||t.remove()})}function R(e,o,t){if(x(e))return!1;const n=document.createElement("span");n.style.fontSize=t;try{e.surroundContents(n)}catch{const r=e.extractContents();n.appendChild(r),e.insertNode(n)}const i=document.createRange();return i.selectNodeContents(n),o.removeAllRanges(),o.addRange(i),!0}function g(e){const o=window.getSelection();if(!o||o.rangeCount===0)return;const{value:t,unit:n}=h();let i=e;(n==="em"||n==="rem")&&(i=e*.125);let r;n==="px"?r=e<0?Math.max(8,t+e):Math.min(72,t+e):r=e<0?Math.max(.5,t+i):Math.min(5,t+i),C(r,n)}function h(){const e=window.getSelection();if(!e||e.rangeCount===0)return{value:14,unit:"px"};const t=e.getRangeAt(0).startContainer,n=t.nodeType===Node.TEXT_NODE?t.parentElement:t;if(n){const i=n.style?.fontSize;if(i){const a=p(i);if(a)return a}const c=window.getComputedStyle(n).fontSize,s=p(c);if(s)return s}return{value:14,unit:"px"}}function C(e,o="px"){const t=window.getSelection();if(!t||t.rangeCount===0)return;const n=t.getRangeAt(0),i=n.cloneRange(),r=w(n.commonAncestorContainer);if(n.collapsed)return;const c=`${e}${o}`,s=n.commonAncestorContainer,a=v(s);if(a&&O(n,a)){a.style.fontSize=c,m(r);const d=document.createRange();d.selectNodeContents(a),t.removeAllRanges(),t.addRange(d);return}if(!r)return;const u=new Set(Array.from(r.querySelectorAll("font[size], [style*='font-size']")));r.focus({preventScroll:!0});try{document.execCommand("styleWithCSS",!1,"true")}catch{}let l=document.execCommand("fontSize",!1,"7");const f=t.rangeCount>0?t.getRangeAt(0).cloneRange():i,F=T(r,u,c,f);if(l&&F){S(r),m(r);return}l=R(i,t,c),l&&(S(r),m(r))}function v(e){let o=e;for(;o&&o!==document.body;){if(o.nodeType===Node.ELEMENT_NODE){const t=o;if(t.tagName==="SPAN"&&t.style.fontSize)return t}o=o.parentNode}return null}function O(e,o){const t=e.startContainer,n=e.endContainer;return o.contains(t)&&o.contains(n)}function y(){setTimeout(()=>{const{value:e,unit:o}=h(),t=window.getSelection();if(!t||t.rangeCount===0)return;let n=null,r=t.getRangeAt(0).startContainer;for(;r;){if(r instanceof HTMLElement&&(r.classList.contains("rte-editor")||r.classList.contains("editora-editor")||r.hasAttribute("data-editora-editor"))){n=r;break}r=r.parentNode}if(!n)return;const c=n.querySelector(".rte-toolbar-wrapper, .editora-toolbar-container")||n,s=Array.from(c.querySelectorAll('input[data-command="setFontSize"], input.editora-toolbar-input.font-size, input.rte-toolbar-input.font-size, input[title="Font Size"]'));if(s.length===0)return;const u=`${e%1===0?e.toString():e.toFixed(2).replace(/\.?0+$/,"")}${o}`;s.forEach(l=>{l.value=u})},10)}exports.FontSizePlugin=b;
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
const O = () => ({
|
|
2
|
+
name: "fontSize",
|
|
3
|
+
marks: {
|
|
4
|
+
fontSize: {
|
|
5
|
+
attrs: {
|
|
6
|
+
size: { default: null }
|
|
7
|
+
},
|
|
8
|
+
parseDOM: [
|
|
9
|
+
{
|
|
10
|
+
tag: 'span[style*="font-size"]',
|
|
11
|
+
getAttrs: (e) => {
|
|
12
|
+
const t = e.style.fontSize;
|
|
13
|
+
return t ? { size: t } : !1;
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
tag: "font[size]",
|
|
18
|
+
getAttrs: (e) => {
|
|
19
|
+
const t = e.getAttribute("size");
|
|
20
|
+
return t ? { size: t } : !1;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
toDOM: (e) => ["span", { style: `font-size: ${e.attrs?.size}` }, 0]
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
toolbar: [
|
|
28
|
+
{
|
|
29
|
+
label: "Font Size",
|
|
30
|
+
command: "fontSize",
|
|
31
|
+
type: "group",
|
|
32
|
+
items: [
|
|
33
|
+
{
|
|
34
|
+
label: "Decrease Font Size",
|
|
35
|
+
command: "decreaseFontSize",
|
|
36
|
+
icon: "−",
|
|
37
|
+
type: "button"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
label: "Font Size",
|
|
41
|
+
command: "setFontSize",
|
|
42
|
+
type: "input",
|
|
43
|
+
placeholder: "14"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
label: "Increase Font Size",
|
|
47
|
+
command: "increaseFontSize",
|
|
48
|
+
icon: "+",
|
|
49
|
+
type: "button"
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
commands: {
|
|
55
|
+
decreaseFontSize: () => {
|
|
56
|
+
try {
|
|
57
|
+
return y(-2), z(), !0;
|
|
58
|
+
} catch (e) {
|
|
59
|
+
return console.error("Failed to decrease font size:", e), !1;
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
increaseFontSize: () => {
|
|
63
|
+
try {
|
|
64
|
+
return y(2), z(), !0;
|
|
65
|
+
} catch (e) {
|
|
66
|
+
return console.error("Failed to increase font size:", e), !1;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
setFontSize: (e) => {
|
|
70
|
+
if (!e) return !1;
|
|
71
|
+
try {
|
|
72
|
+
const t = e.trim().match(/^(\d+(?:\.\d+)?)(px|em|rem)?$/i);
|
|
73
|
+
if (!t) return !1;
|
|
74
|
+
const n = parseFloat(t[1]), i = t[2]?.toLowerCase() || "px";
|
|
75
|
+
return i === "px" && (n < 8 || n > 72) || (i === "em" || i === "rem") && (n < 0.5 || n > 5) ? !1 : (C(n, i), !0);
|
|
76
|
+
} catch (o) {
|
|
77
|
+
return console.error("Failed to set font size:", o), !1;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
keymap: {}
|
|
82
|
+
}), A = "p,div,li,ul,ol,table,thead,tbody,tfoot,tr,td,th,h1,h2,h3,h4,h5,h6,blockquote,pre", g = {
|
|
83
|
+
"xx-small": 9,
|
|
84
|
+
"x-small": 10,
|
|
85
|
+
small: 13,
|
|
86
|
+
medium: 16,
|
|
87
|
+
large: 18,
|
|
88
|
+
"x-large": 24,
|
|
89
|
+
"xx-large": 32,
|
|
90
|
+
"xxx-large": 48,
|
|
91
|
+
smaller: 13,
|
|
92
|
+
larger: 18
|
|
93
|
+
};
|
|
94
|
+
function p(e) {
|
|
95
|
+
const o = e.trim().toLowerCase(), t = o.match(/^(\d+(?:\.\d+)?)(px|em|rem)$/i);
|
|
96
|
+
if (t)
|
|
97
|
+
return {
|
|
98
|
+
value: parseFloat(t[1]),
|
|
99
|
+
unit: t[2].toLowerCase()
|
|
100
|
+
};
|
|
101
|
+
const n = g[o];
|
|
102
|
+
return n ? { value: n, unit: "px" } : null;
|
|
103
|
+
}
|
|
104
|
+
function N(e) {
|
|
105
|
+
return e.trim().toLowerCase() in g;
|
|
106
|
+
}
|
|
107
|
+
function b(e) {
|
|
108
|
+
return !!e.cloneContents().querySelector(A);
|
|
109
|
+
}
|
|
110
|
+
function x(e) {
|
|
111
|
+
return (e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement)?.closest('[contenteditable="true"]') || document.querySelector('[contenteditable="true"]');
|
|
112
|
+
}
|
|
113
|
+
function m(e) {
|
|
114
|
+
e && e.dispatchEvent(new Event("input", { bubbles: !0 }));
|
|
115
|
+
}
|
|
116
|
+
function w(e, o) {
|
|
117
|
+
const t = document.createElement("span");
|
|
118
|
+
for (const i of Array.from(e.attributes))
|
|
119
|
+
i.name === "size" || i.name === "style" || t.setAttribute(i.name, i.value);
|
|
120
|
+
const n = e.getAttribute("style");
|
|
121
|
+
for (n && t.setAttribute("style", n), t.style.fontSize = o; e.firstChild; )
|
|
122
|
+
t.appendChild(e.firstChild);
|
|
123
|
+
e.parentNode?.replaceChild(t, e);
|
|
124
|
+
}
|
|
125
|
+
function E(e, o, t, n) {
|
|
126
|
+
const i = Array.from(
|
|
127
|
+
e.querySelectorAll("font[size], [style*='font-size']")
|
|
128
|
+
), r = (s) => {
|
|
129
|
+
if (!n || !s.isConnected) return !1;
|
|
130
|
+
try {
|
|
131
|
+
if (typeof n.intersectsNode == "function")
|
|
132
|
+
return n.intersectsNode(s);
|
|
133
|
+
} catch {
|
|
134
|
+
}
|
|
135
|
+
const a = document.createRange();
|
|
136
|
+
return a.selectNodeContents(s), n.compareBoundaryPoints(Range.END_TO_START, a) > 0 && n.compareBoundaryPoints(Range.START_TO_END, a) < 0;
|
|
137
|
+
};
|
|
138
|
+
let c = !1;
|
|
139
|
+
return i.forEach((s) => {
|
|
140
|
+
const a = !o.has(s), u = s.tagName === "FONT", l = N(s.style.fontSize || ""), f = r(s);
|
|
141
|
+
if (!(!a && !f) && !(!a && !u && !l)) {
|
|
142
|
+
if (c = !0, s.tagName === "FONT") {
|
|
143
|
+
w(s, t);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
s.style.fontSize = t;
|
|
147
|
+
}
|
|
148
|
+
}), c;
|
|
149
|
+
}
|
|
150
|
+
function S(e) {
|
|
151
|
+
e.querySelectorAll("span").forEach((t) => {
|
|
152
|
+
t.childElementCount > 0 || (t.textContent || "").trim().length > 0 || t.remove();
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function T(e, o, t) {
|
|
156
|
+
if (b(e))
|
|
157
|
+
return !1;
|
|
158
|
+
const n = document.createElement("span");
|
|
159
|
+
n.style.fontSize = t;
|
|
160
|
+
try {
|
|
161
|
+
e.surroundContents(n);
|
|
162
|
+
} catch {
|
|
163
|
+
const r = e.extractContents();
|
|
164
|
+
n.appendChild(r), e.insertNode(n);
|
|
165
|
+
}
|
|
166
|
+
const i = document.createRange();
|
|
167
|
+
return i.selectNodeContents(n), o.removeAllRanges(), o.addRange(i), !0;
|
|
168
|
+
}
|
|
169
|
+
function y(e) {
|
|
170
|
+
const o = window.getSelection();
|
|
171
|
+
if (!o || o.rangeCount === 0) return;
|
|
172
|
+
const { value: t, unit: n } = h();
|
|
173
|
+
let i = e;
|
|
174
|
+
(n === "em" || n === "rem") && (i = e * 0.125);
|
|
175
|
+
let r;
|
|
176
|
+
n === "px" ? r = e < 0 ? Math.max(8, t + e) : Math.min(72, t + e) : r = e < 0 ? Math.max(0.5, t + i) : Math.min(5, t + i), C(r, n);
|
|
177
|
+
}
|
|
178
|
+
function h() {
|
|
179
|
+
const e = window.getSelection();
|
|
180
|
+
if (!e || e.rangeCount === 0)
|
|
181
|
+
return { value: 14, unit: "px" };
|
|
182
|
+
const t = e.getRangeAt(0).startContainer, n = t.nodeType === Node.TEXT_NODE ? t.parentElement : t;
|
|
183
|
+
if (n) {
|
|
184
|
+
const i = n.style?.fontSize;
|
|
185
|
+
if (i) {
|
|
186
|
+
const a = p(i);
|
|
187
|
+
if (a)
|
|
188
|
+
return a;
|
|
189
|
+
}
|
|
190
|
+
const c = window.getComputedStyle(n).fontSize, s = p(c);
|
|
191
|
+
if (s)
|
|
192
|
+
return s;
|
|
193
|
+
}
|
|
194
|
+
return { value: 14, unit: "px" };
|
|
195
|
+
}
|
|
196
|
+
function C(e, o = "px") {
|
|
197
|
+
const t = window.getSelection();
|
|
198
|
+
if (!t || t.rangeCount === 0) return;
|
|
199
|
+
const n = t.getRangeAt(0), i = n.cloneRange(), r = x(n.commonAncestorContainer);
|
|
200
|
+
if (n.collapsed)
|
|
201
|
+
return;
|
|
202
|
+
const c = `${e}${o}`, s = n.commonAncestorContainer, a = R(s);
|
|
203
|
+
if (a && v(n, a)) {
|
|
204
|
+
a.style.fontSize = c, m(r);
|
|
205
|
+
const d = document.createRange();
|
|
206
|
+
d.selectNodeContents(a), t.removeAllRanges(), t.addRange(d);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (!r) return;
|
|
210
|
+
const u = new Set(
|
|
211
|
+
Array.from(
|
|
212
|
+
r.querySelectorAll("font[size], [style*='font-size']")
|
|
213
|
+
)
|
|
214
|
+
);
|
|
215
|
+
r.focus({ preventScroll: !0 });
|
|
216
|
+
try {
|
|
217
|
+
document.execCommand("styleWithCSS", !1, "true");
|
|
218
|
+
} catch {
|
|
219
|
+
}
|
|
220
|
+
let l = document.execCommand("fontSize", !1, "7");
|
|
221
|
+
const f = t.rangeCount > 0 ? t.getRangeAt(0).cloneRange() : i, F = E(
|
|
222
|
+
r,
|
|
223
|
+
u,
|
|
224
|
+
c,
|
|
225
|
+
f
|
|
226
|
+
);
|
|
227
|
+
if (l && F) {
|
|
228
|
+
S(r), m(r);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
l = T(i, t, c), l && (S(r), m(r));
|
|
232
|
+
}
|
|
233
|
+
function R(e) {
|
|
234
|
+
let o = e;
|
|
235
|
+
for (; o && o !== document.body; ) {
|
|
236
|
+
if (o.nodeType === Node.ELEMENT_NODE) {
|
|
237
|
+
const t = o;
|
|
238
|
+
if (t.tagName === "SPAN" && t.style.fontSize)
|
|
239
|
+
return t;
|
|
240
|
+
}
|
|
241
|
+
o = o.parentNode;
|
|
242
|
+
}
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
function v(e, o) {
|
|
246
|
+
const t = e.startContainer, n = e.endContainer;
|
|
247
|
+
return o.contains(t) && o.contains(n);
|
|
248
|
+
}
|
|
249
|
+
function z() {
|
|
250
|
+
setTimeout(() => {
|
|
251
|
+
const { value: e, unit: o } = h(), t = window.getSelection();
|
|
252
|
+
if (!t || t.rangeCount === 0) return;
|
|
253
|
+
let n = null, r = t.getRangeAt(0).startContainer;
|
|
254
|
+
for (; r; ) {
|
|
255
|
+
if (r instanceof HTMLElement && (r.classList.contains("rte-editor") || r.classList.contains("editora-editor") || r.hasAttribute("data-editora-editor"))) {
|
|
256
|
+
n = r;
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
r = r.parentNode;
|
|
260
|
+
}
|
|
261
|
+
if (!n) return;
|
|
262
|
+
const c = n.querySelector(
|
|
263
|
+
".rte-toolbar-wrapper, .editora-toolbar-container"
|
|
264
|
+
) || n, s = Array.from(
|
|
265
|
+
c.querySelectorAll(
|
|
266
|
+
'input[data-command="setFontSize"], input.editora-toolbar-input.font-size, input.rte-toolbar-input.font-size, input[title="Font Size"]'
|
|
267
|
+
)
|
|
268
|
+
);
|
|
269
|
+
if (s.length === 0) return;
|
|
270
|
+
const u = `${e % 1 === 0 ? e.toString() : e.toFixed(2).replace(/\.?0+$/, "")}${o}`;
|
|
271
|
+
s.forEach((l) => {
|
|
272
|
+
l.value = u;
|
|
273
|
+
});
|
|
274
|
+
}, 10);
|
|
275
|
+
}
|
|
276
|
+
export {
|
|
277
|
+
O as FontSizePlugin
|
|
278
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=".rte-content, .editora-content",C='.rte-footnotes[data-type="footnotes"]',m=".rte-footnote-ref[data-footnote-id]",g='li.rte-footnote-item[data-type="footnote"]',x="__editoraCommandEditorRoot";let y=!1,S=!1,A=0;function M(){if(y||typeof document>"u")return;y=!0;const t=document.createElement("style");t.id="editora-footnote-plugin-styles",t.textContent=`
|
|
2
|
+
.rte-footnote-ref {
|
|
3
|
+
display: inline-block;
|
|
4
|
+
font-size: 0.72em;
|
|
5
|
+
line-height: 1;
|
|
6
|
+
vertical-align: super;
|
|
7
|
+
margin-left: 1px;
|
|
8
|
+
color: #1f4dbd;
|
|
9
|
+
cursor: pointer;
|
|
10
|
+
user-select: none;
|
|
11
|
+
border-radius: 4px;
|
|
12
|
+
padding: 0 2px;
|
|
13
|
+
outline: none;
|
|
14
|
+
font-weight: 600;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.rte-footnote-ref:focus,
|
|
18
|
+
.rte-footnote-ref:focus-visible,
|
|
19
|
+
.rte-footnote-ref.rte-footnote-selected {
|
|
20
|
+
background: rgba(31, 77, 189, 0.12);
|
|
21
|
+
box-shadow: 0 0 0 2px rgba(31, 77, 189, 0.24);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.rte-footnotes {
|
|
25
|
+
margin-top: 16px;
|
|
26
|
+
padding-top: 10px;
|
|
27
|
+
border-top: 1px solid #d1d5db;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.rte-footnotes ol {
|
|
31
|
+
margin: 0;
|
|
32
|
+
padding-left: 24px;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.rte-footnote-item {
|
|
36
|
+
margin: 0 0 8px;
|
|
37
|
+
color: inherit;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.rte-footnote-content {
|
|
41
|
+
display: inline;
|
|
42
|
+
outline: none;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.rte-footnote-backref {
|
|
46
|
+
margin-left: 8px;
|
|
47
|
+
color: #1f4dbd;
|
|
48
|
+
text-decoration: none;
|
|
49
|
+
font-size: 0.9em;
|
|
50
|
+
user-select: none;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.rte-footnote-backref:hover,
|
|
54
|
+
.rte-footnote-backref:focus {
|
|
55
|
+
text-decoration: underline;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.rte-footnote-highlighted {
|
|
59
|
+
animation: rte-footnote-flash 1s ease;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@keyframes rte-footnote-flash {
|
|
63
|
+
0% { background-color: rgba(255, 234, 143, 0.9); }
|
|
64
|
+
100% { background-color: transparent; }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
:is([data-theme="dark"], .dark, .editora-theme-dark) .rte-footnote-ref {
|
|
68
|
+
color: #8ab4ff;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
:is([data-theme="dark"], .dark, .editora-theme-dark) .rte-footnote-ref:focus,
|
|
72
|
+
:is([data-theme="dark"], .dark, .editora-theme-dark) .rte-footnote-ref:focus-visible,
|
|
73
|
+
:is([data-theme="dark"], .dark, .editora-theme-dark) .rte-footnote-ref.rte-footnote-selected {
|
|
74
|
+
background: rgba(138, 180, 255, 0.16);
|
|
75
|
+
box-shadow: 0 0 0 2px rgba(138, 180, 255, 0.3);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
:is([data-theme="dark"], .dark, .editora-theme-dark) .rte-footnotes {
|
|
79
|
+
border-top-color: #4b5563;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
:is([data-theme="dark"], .dark, .editora-theme-dark) .rte-footnote-backref {
|
|
83
|
+
color: #8ab4ff;
|
|
84
|
+
}
|
|
85
|
+
`,document.head.appendChild(t)}function v(t){return t?t.nodeType===Node.ELEMENT_NODE?t:t.parentElement:null}function _(t){if(!t)return null;const e=t.querySelector('[contenteditable="true"]');return e instanceof HTMLElement?e:null}function q(){if(typeof window>"u")return null;const t=window[x];if(!(t instanceof HTMLElement))return null;window[x]=null;const e=t.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor")||(t.matches("[data-editora-editor], .rte-editor, .editora-editor, editora-editor")?t:null);if(e){const o=_(e);if(o)return o;if(e.getAttribute("contenteditable")==="true")return e}if(t.getAttribute("contenteditable")==="true")return t;const n=t.closest('[contenteditable="true"]');return n instanceof HTMLElement?n:null}function $(t){const e=t.closest('[contenteditable="true"]');if(!e)return null;let n=e,o=n.parentElement;for(;o;)o.getAttribute("contenteditable")==="true"&&(n=o),o=o.parentElement;return n}function u(t){const e=v(t);if(!e)return null;const n=e.closest(R);return n||$(e)}function B(){const t=window.getSelection();return!t||t.rangeCount===0?null:u(t.getRangeAt(0).startContainer)}function H(){const t=q();if(t&&document.contains(t))return t;const e=B();if(e)return e;const n=document.activeElement,o=n?u(n):null;if(o)return o;const r=document.querySelector(R);return r||document.querySelector('[contenteditable="true"]')}function P(){const t=document.createElement("section");t.className="rte-footnotes",t.setAttribute("data-type","footnotes"),t.setAttribute("contenteditable","false");const e=document.createElement("ol");return t.appendChild(e),t}function b(t,e){let n=t.querySelector(C);return!n&&e&&(n=P(),t.appendChild(n)),n?(n.querySelector("ol")||n.appendChild(document.createElement("ol")),n):null}function O(t){let e=t.querySelector("ol");return e||(e=document.createElement("ol"),t.appendChild(e)),e}function z(t){const e=document.createElement("sup");return e.className="rte-footnote-ref",e.setAttribute("data-footnote-id",t),e.setAttribute("data-number","0"),e.setAttribute("contenteditable","false"),e.setAttribute("tabindex","0"),e.setAttribute("role","doc-noteref"),e.id=`ref-${t}`,e.textContent="0",e}function F(t,e){const n=document.createElement("li");n.id=t,n.className="rte-footnote-item",n.setAttribute("data-type","footnote"),n.setAttribute("data-number","0"),n.setAttribute("contenteditable","false");const o=document.createElement("div");o.className="rte-footnote-content",o.setAttribute("contenteditable","true"),o.textContent=e;const r=document.createElement("a");return r.className="rte-footnote-backref",r.href=`#ref-${t}`,r.setAttribute("aria-label","Back to reference"),r.setAttribute("contenteditable","false"),r.textContent="↩",n.appendChild(o),n.appendChild(r),n}function j(t){let e="";do A+=1,e=`fn-${Date.now().toString(36)}-${A.toString(36)}`;while(t.querySelector(`#${CSS.escape(e)}`));return e}function k(t){t.classList.remove("rte-footnote-highlighted"),t.classList.add("rte-footnote-highlighted"),window.setTimeout(()=>{t.classList.remove("rte-footnote-highlighted")},1e3)}function L(t){t&&t.dispatchEvent(new Event("input",{bubbles:!0}))}function I(t,e){if(!t||e===t.innerHTML)return;const n=window.execEditorCommand||window.executeEditorCommand;if(typeof n=="function")try{n("recordDomTransaction",t,e,t.innerHTML)}catch{}}function X(t,e){return Array.from(t.querySelectorAll(m)).find(o=>o.getAttribute("data-footnote-id")===e)||null}function V(t){const e=window.getSelection();if(!e)throw new Error("Selection unavailable");let n=null;if(e.rangeCount>0){const r=e.getRangeAt(0);t.contains(r.commonAncestorContainer)&&(n=r.cloneRange())}if(!n){n=document.createRange();const r=b(t,!1);r?(n.setStartBefore(r),n.collapse(!0)):(n.selectNodeContents(t),n.collapse(!1))}if(v(n.commonAncestorContainer)?.closest(C)){const r=b(t,!0);r&&(n.setStartBefore(r),n.collapse(!0))}return e.removeAllRanges(),e.addRange(n),n}function w(t){const e=t.parentNode;if(!e)return;const n=Array.from(e.childNodes).indexOf(t);if(n<0)return;const o=window.getSelection();if(!o)return;const r=document.createRange();r.setStart(e,n),r.setEnd(e,n+1),o.removeAllRanges(),o.addRange(r),t.focus({preventScroll:!0})}function T(t,e){const n=window.getSelection();if(!n)return;const o=Math.max(0,Math.min(e,t.childNodes.length)),r=document.createRange();r.setStart(t,o),r.collapse(!0),n.removeAllRanges(),n.addRange(r)}function K(t){if(t.collapsed||t.startContainer!==t.endContainer||t.endOffset!==t.startOffset+1||!(t.startContainer instanceof Element||t.startContainer instanceof DocumentFragment))return null;const e=t.startContainer.childNodes[t.startOffset];return!(e instanceof HTMLElement)||!e.matches(m)?null:e}function p(t,e,n){const{startContainer:o,startOffset:r}=t;if(o.nodeType===Node.ELEMENT_NODE){const i=o;if(n==="previous"){if(r>0)return i.childNodes[r-1]||null}else if(r<i.childNodes.length)return i.childNodes[r]||null}if(o.nodeType===Node.TEXT_NODE&&(n==="previous"&&r<o.data.length||n==="next"&&r>0))return null;let c=o;for(;c&&c!==e;){const i=n==="previous"?c.previousSibling:c.nextSibling;if(i)return i;c=c.parentNode}return null}function Y(t,e,n){if(!t.collapsed)return null;const o=i=>i instanceof HTMLElement&&i.matches(m)?i:null,{startContainer:r,startOffset:c}=t;if(r.nodeType===Node.ELEMENT_NODE){const i=r;return n==="Backspace"&&c>0?o(i.childNodes[c-1]||null):n==="Delete"?o(i.childNodes[c]||null):null}if(r.nodeType===Node.TEXT_NODE){const i=r;if(n==="Backspace"&&c===0){const a=o(i.previousSibling);return a||o(p(t,e,"previous"))}if(n==="Delete"&&c===i.data.length){const a=o(i.nextSibling);return a||o(p(t,e,"next"))}}return o(n==="Backspace"?p(t,e,"previous"):p(t,e,"next"))}function D(t){const e=Array.from(t.querySelectorAll(m)).filter(a=>!a.closest(C)),n=b(t,e.length>0);if(!n)return;const o=O(n),r=Array.from(o.querySelectorAll(g)),c=new Map;r.forEach(a=>c.set(a.id,a));const i=[];e.forEach((a,f)=>{const l=a.getAttribute("data-footnote-id");if(!l)return;const s=f+1;a.setAttribute("data-number",String(s)),a.id=`ref-${l}`,a.textContent=String(s);let d=c.get(l);d||(d=F(l,`Footnote ${s}`)),d.setAttribute("data-number",String(s));const h=d.querySelector(".rte-footnote-content");h&&!(h.textContent||"").trim()&&(h.textContent=`Footnote ${s}`);const E=d.querySelector(".rte-footnote-backref");E&&(E.href=`#ref-${l}`,E.setAttribute("aria-label",`Back to reference ${s}`)),i.push(d)}),o.innerHTML="",i.forEach(a=>o.appendChild(a)),i.length===0&&n.remove()}function N(t,e){const n=u(t),o=t.parentNode;if(!n||!o)return!1;const r=n.innerHTML,c=Array.from(o.childNodes).indexOf(t);if(c<0)return!1;const i=t.getAttribute("data-footnote-id")||"";return t.remove(),i&&n.querySelector(`${g}#${CSS.escape(i)}`)?.remove(),T(o,c),D(n),I(n,r),L(n),!0}function G(){S||typeof document>"u"||(S=!0,document.addEventListener("click",t=>{const e=t.target;if(!e)return;const n=e.closest(m);if(n){const f=u(n);if(!f||!f.contains(n))return;t.preventDefault(),t.stopPropagation(),w(n),n.classList.add("rte-footnote-selected"),window.setTimeout(()=>n.classList.remove("rte-footnote-selected"),1200);const l=n.getAttribute("data-footnote-id");if(!l)return;const s=f.querySelector(`${g}#${CSS.escape(l)}`);if(!s)return;s.scrollIntoView({behavior:"smooth",block:"center"}),k(s);return}const o=e.closest(".rte-footnote-backref");if(!o)return;const r=o.closest(g);if(!r)return;const c=u(r);if(!c||!c.contains(r))return;t.preventDefault(),t.stopPropagation();const i=r.id;if(!i)return;const a=X(c,i);a&&(a.scrollIntoView({behavior:"smooth",block:"center"}),k(a),w(a))}),document.addEventListener("keydown",t=>{if(t.key!=="Backspace"&&t.key!=="Delete")return;const e=window.getSelection();if(!e||e.rangeCount===0)return;const n=e.getRangeAt(0),o=u(n.commonAncestorContainer);if(!o||!o.contains(n.commonAncestorContainer))return;const r=K(n);if(r){t.preventDefault(),t.stopPropagation(),N(r,t.key);return}const c=Y(n,o,t.key);c&&(t.preventDefault(),t.stopPropagation(),N(c,t.key))}))}const J=(t="")=>{const e=H();if(!e)return!1;const n=e.innerHTML,o=window.getSelection();if(!o)return!1;let r;try{r=V(e)}catch{return!1}r.collapsed||(r.collapse(!1),o.removeAllRanges(),o.addRange(r));const c=j(e),i=z(c);try{r.insertNode(i)}catch{return!1}const a=document.createRange();a.setStartAfter(i),a.collapse(!0),o.removeAllRanges(),o.addRange(a);const f=b(e,!0);if(!f)return!1;const l=O(f),s=t.trim()||"Footnote";return l.appendChild(F(c,s)),D(e),I(e,n),L(e),!0},Q=()=>(M(),G(),{name:"footnote",toolbar:[{label:"Footnote",command:"insertFootnote",icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><rect x="3" y="4" width="14" height="2" rx="1"></rect><rect x="3" y="8" width="18" height="2" rx="1"></rect><rect x="3" y="12" width="16" height="2" rx="1"></rect><rect x="3" y="16" width="10" height="1.5" rx="0.75"></rect><text x="19" y="11" font-size="9" font-weight="600" fill="currentColor" font-family="system-ui, sans-serif">1</text></svg>'}],commands:{insertFootnote:()=>J()},keymap:{}});exports.FootnotePlugin=Q;
|