@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.
- package/README.md +57 -4
- package/dist/_commonjsHelpers-BH3jXuIh.js +1 -0
- package/dist/_commonjsHelpers-ByX85dGu.mjs +33 -0
- package/dist/anchor.cjs.js +11 -11
- package/dist/anchor.esm.js +130 -107
- package/dist/anchoredPopover-BzqGPOAE.js +1 -0
- package/dist/anchoredPopover-Dts0IrgU.mjs +106 -0
- package/dist/background-color.cjs.js +3 -3
- package/dist/background-color.esm.js +116 -119
- package/dist/code.cjs.js +82 -102
- package/dist/code.esm.js +1172 -662
- package/dist/comments.cjs.js +10 -10
- package/dist/comments.esm.js +195 -177
- package/dist/document-manager.cjs.js +1 -1
- package/dist/document-manager.esm.js +1 -1
- package/dist/documentManager-CTqRftU8.mjs +8369 -0
- package/dist/documentManager-Jf0RbSks.js +17 -0
- package/dist/embed-iframe.cjs.js +2 -2
- package/dist/embed-iframe.esm.js +8 -5
- package/dist/emojis.cjs.js +64 -39
- package/dist/emojis.esm.js +133 -104
- package/dist/html2canvas.esm-B5qzocYs.js +5 -0
- package/dist/html2canvas.esm-BWVIUcAF.mjs +4802 -0
- package/dist/{index-Bskk414V.mjs → index-BFsKNTTj.mjs} +50 -50
- package/dist/index-CvJk4DKa.js +221 -0
- package/dist/index-D3CycEFU.mjs +16543 -0
- package/dist/index-tqLTHcO6.js +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/{index.es-Cz1qItab.js → index.es-CE_A4QSm.js} +5 -5
- package/dist/{index.es-DEcRmSTY.mjs → index.es-DQ78mYYo.mjs} +4 -3
- package/dist/index.esm.js +87 -79
- package/dist/jspdf.es.min-BoS80556.js +77 -0
- package/dist/jspdf.es.min-DQCoX5yh.mjs +7889 -0
- package/dist/link.cjs.js +6 -6
- package/dist/link.esm.js +41 -39
- package/dist/math.cjs.js +21 -21
- package/dist/math.esm.js +151 -112
- package/dist/media-manager.cjs.js +15 -15
- package/dist/media-manager.esm.js +227 -206
- package/dist/merge-tag.cjs.js +44 -12
- package/dist/merge-tag.esm.js +368 -241
- package/dist/page-break.cjs.js +2 -2
- package/dist/page-break.esm.js +77 -69
- package/dist/special-characters.cjs.js +83 -45
- package/dist/special-characters.esm.js +149 -100
- package/dist/spell-check.cjs.js +9 -9
- package/dist/spell-check.esm.js +235 -216
- package/dist/template.cjs.js +14 -14
- package/dist/template.esm.js +157 -131
- package/dist/text-color.cjs.js +9 -9
- package/dist/text-color.esm.js +131 -115
- package/index.d.ts +51 -1
- package/package.json +6 -4
- package/dist/colorSelectionApply-C0iOfMWb.js +0 -1
- package/dist/colorSelectionApply-D8r_gV32.mjs +0 -63
- package/dist/documentManager-DRUc1-Cs.mjs +0 -37581
- package/dist/documentManager-_tQQfQi9.js +0 -317
- package/dist/index-D3pJyAsj.js +0 -1
package/README.md
CHANGED
|
@@ -17,6 +17,12 @@ Comprehensive plugin collection for Editora Rich Text Editor with 40+ plugins fo
|
|
|
17
17
|
npm install @editora/plugins @editora/core @editora/themes
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
+
When using plugin UI features (table toolbar, pickers, dialogs), also import:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import "@editora/plugins/styles.css";
|
|
24
|
+
```
|
|
25
|
+
|
|
20
26
|
## 🎯 Overview
|
|
21
27
|
|
|
22
28
|
This package provides a complete set of plugins for building feature-rich text editors. Each plugin is modular, tree-shakeable, and can be used independently.
|
|
@@ -109,6 +115,7 @@ import {
|
|
|
109
115
|
StrikethroughPlugin
|
|
110
116
|
} from '@editora/plugins';
|
|
111
117
|
|
|
118
|
+
import "@editora/plugins/styles.css";
|
|
112
119
|
import "@editora/themes/themes/default.css";
|
|
113
120
|
const plugins = [
|
|
114
121
|
BoldPlugin(),
|
|
@@ -588,15 +595,61 @@ const collaborativePlugins = [
|
|
|
588
595
|
}),
|
|
589
596
|
MergeTagPlugin({
|
|
590
597
|
tags: [
|
|
591
|
-
{ label: 'First Name', value: '{{firstName}}' },
|
|
592
|
-
{ label: 'Last Name', value: '{{lastName}}' },
|
|
593
|
-
{ label: 'Email', value: '{{email}}' }
|
|
594
|
-
]
|
|
598
|
+
{ label: 'First Name', value: '{{firstName}}', category: 'User' },
|
|
599
|
+
{ label: 'Last Name', value: '{{lastName}}', category: 'User' },
|
|
600
|
+
{ label: 'Email', value: '{{email}}', category: 'User' }
|
|
601
|
+
],
|
|
602
|
+
defaultCategory: 'User',
|
|
603
|
+
dialog: {
|
|
604
|
+
title: 'Insert Variable',
|
|
605
|
+
searchPlaceholder: 'Search variables...',
|
|
606
|
+
showPreview: true
|
|
607
|
+
},
|
|
608
|
+
tokenTemplate: '{value}'
|
|
595
609
|
}),
|
|
596
610
|
HistoryPlugin()
|
|
597
611
|
];
|
|
598
612
|
```
|
|
599
613
|
|
|
614
|
+
`MergeTagPlugin` supports functional customization:
|
|
615
|
+
|
|
616
|
+
- `tags`: flat list of tags (auto-grouped by `category`)
|
|
617
|
+
- `categories`: explicit grouped categories with custom order
|
|
618
|
+
- `defaultCategory`: initial tab
|
|
619
|
+
- `dialog`: labels/placeholders/preview toggle
|
|
620
|
+
- `tokenTemplate`: string template (`{key}`, `{label}`, `{category}`, `{value}`) or formatter function
|
|
621
|
+
|
|
622
|
+
### Custom Templates
|
|
623
|
+
|
|
624
|
+
You can register your own templates before initializing the editor:
|
|
625
|
+
|
|
626
|
+
```typescript
|
|
627
|
+
import { TemplatePlugin, addCustomTemplate } from '@editora/plugins';
|
|
628
|
+
|
|
629
|
+
addCustomTemplate({
|
|
630
|
+
id: 'invoice-basic',
|
|
631
|
+
name: 'Invoice (Basic)',
|
|
632
|
+
category: 'Billing',
|
|
633
|
+
description: 'Simple invoice template',
|
|
634
|
+
html: `
|
|
635
|
+
<h1>Invoice</h1>
|
|
636
|
+
<p><strong>Customer:</strong> {{customer.name}}</p>
|
|
637
|
+
<p><strong>Date:</strong> {{today}}</p>
|
|
638
|
+
<p><strong>Total:</strong> {{invoice.total}}</p>
|
|
639
|
+
`,
|
|
640
|
+
tags: ['invoice', 'billing']
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
const plugins = [
|
|
644
|
+
TemplatePlugin()
|
|
645
|
+
];
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
Notes:
|
|
649
|
+
- `id` must be unique.
|
|
650
|
+
- HTML is sanitized on insertion.
|
|
651
|
+
- Use `validateTemplate(template)` if you want to pre-check templates before registering.
|
|
652
|
+
|
|
600
653
|
## 🔧 TypeScript Support
|
|
601
654
|
|
|
602
655
|
All plugins include full TypeScript definitions:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var u=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function f(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function l(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var n=e.default;if(typeof n=="function"){var t=function o(){var r=!1;try{r=this instanceof o}catch{}return r?Reflect.construct(n,arguments,this.constructor):n.apply(this,arguments)};t.prototype=n.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(e).forEach(function(o){var r=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,r.get?r:{enumerable:!0,get:function(){return e[o]}})}),t}exports.commonjsGlobal=u;exports.getAugmentedNamespace=l;exports.getDefaultExportFromCjs=f;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var u = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
2
|
+
function a(e) {
|
|
3
|
+
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
4
|
+
}
|
|
5
|
+
function f(e) {
|
|
6
|
+
if (Object.prototype.hasOwnProperty.call(e, "__esModule")) return e;
|
|
7
|
+
var n = e.default;
|
|
8
|
+
if (typeof n == "function") {
|
|
9
|
+
var t = function r() {
|
|
10
|
+
var o = !1;
|
|
11
|
+
try {
|
|
12
|
+
o = this instanceof r;
|
|
13
|
+
} catch {
|
|
14
|
+
}
|
|
15
|
+
return o ? Reflect.construct(n, arguments, this.constructor) : n.apply(this, arguments);
|
|
16
|
+
};
|
|
17
|
+
t.prototype = n.prototype;
|
|
18
|
+
} else t = {};
|
|
19
|
+
return Object.defineProperty(t, "__esModule", { value: !0 }), Object.keys(e).forEach(function(r) {
|
|
20
|
+
var o = Object.getOwnPropertyDescriptor(e, r);
|
|
21
|
+
Object.defineProperty(t, r, o.get ? o : {
|
|
22
|
+
enumerable: !0,
|
|
23
|
+
get: function() {
|
|
24
|
+
return e[r];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}), t;
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
f as a,
|
|
31
|
+
u as c,
|
|
32
|
+
a as g
|
|
33
|
+
};
|
package/dist/anchor.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const w=require("./editorContainerHelpers-CFbfiOJI.js"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const w=require("./editorContainerHelpers-CFbfiOJI.js"),b=new Set,x='[data-theme="dark"], .dark, .editora-theme-dark';function $(t,c){if(c===t.innerHTML)return;const i=window.execEditorCommand||window.executeEditorCommand;if(typeof i=="function")try{i("recordDomTransaction",t,c,t.innerHTML)}catch{}}function z(){if(typeof window>"u"||window.__anchorObserverInitialized)return;window.__anchorObserverInitialized=!0,new MutationObserver(c=>{c.forEach(i=>{i.removedNodes.forEach(r=>{if(r.nodeType===Node.ELEMENT_NODE){const d=r;if(d.classList?.contains("rte-anchor")){const n=d.id;n&&b.delete(n)}d.querySelectorAll?.(".rte-anchor")?.forEach(n=>{const u=n.id;u&&b.delete(u)})}})})}).observe(document.body,{childList:!0,subtree:!0})}function S(t){return!t||t.trim().length===0?{valid:!1,error:"Anchor ID cannot be empty"}:t.length>256?{valid:!1,error:"Anchor ID must be less than 256 characters"}:/^[a-z_]/.test(t)?/^[a-z0-9\-_]+$/.test(t)?{valid:!0,error:""}:{valid:!1,error:"Anchor ID can only contain letters, numbers, hyphens, and underscores"}:{valid:!1,error:"Anchor ID must start with a letter or underscore"}}function M(){const t=w.findEditorContainerFromSelection();if(!t)return;const c=w.getContentElement(t);if(!c)return;const i=c.querySelectorAll(".rte-anchor"),r=new Set;i.forEach(d=>{const e=d.id;e&&r.add(e)}),b.clear(),r.forEach(d=>b.add(d))}function R(t){if(t){const r=t.startContainer;if((r.nodeType===Node.ELEMENT_NODE?r:r.parentElement)?.closest(x))return!0}const c=window.getSelection();if(c&&c.rangeCount>0){const r=c.getRangeAt(0).startContainer;if((r.nodeType===Node.ELEMENT_NODE?r:r.parentElement)?.closest(x))return!0}return document.activeElement?.closest(x)?!0:document.body.matches(x)||document.documentElement.matches(x)}function H(t,c,i,r){M();const d=R(r),e=d?{overlay:"rgba(0, 0, 0, 0.62)",dialogBg:"#1f2937",panelBg:"#222d3a",border:"#3b4657",text:"#e2e8f0",muted:"#94a3b8",closeHoverBg:"#334155",fieldBg:"#111827",fieldFocusBg:"#111827",fieldBorder:"#4b5563",fieldText:"#e2e8f0",fieldErrorBg:"#3f2124",fieldErrorBorder:"#ef4444",cancelBg:"#334155",cancelHover:"#475569",cancelText:"#e2e8f0",saveBg:"#3b82f6",saveHover:"#2563eb",saveDisabledBg:"#374151",saveDisabledText:"#7f8ca1",help:"#9fb0c6",focusRing:"rgba(88, 166, 255, 0.25)",errorRing:"rgba(239, 68, 68, 0.25)"}:{overlay:"rgba(0, 0, 0, 0.5)",dialogBg:"#ffffff",panelBg:"#f9f9f9",border:"#e0e0e0",text:"#333333",muted:"#999999",closeHoverBg:"#e0e0e0",fieldBg:"#ffffff",fieldFocusBg:"#f9f9ff",fieldBorder:"#d0d0d0",fieldText:"#333333",fieldErrorBg:"#ffebee",fieldErrorBorder:"#d32f2f",cancelBg:"#f0f0f0",cancelHover:"#e0e0e0",cancelText:"#333333",saveBg:"#0066cc",saveHover:"#0052a3",saveDisabledBg:"#d0d0d0",saveDisabledText:"#999999",help:"#999999",focusRing:"rgba(0, 102, 204, 0.1)",errorRing:"rgba(211, 47, 47, 0.1)"},n=document.createElement("div");n.className="rte-anchor-dialog-overlay",n.style.cssText=`
|
|
2
2
|
position: fixed;
|
|
3
3
|
top: 0;
|
|
4
4
|
left: 0;
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
max-width: 450px;
|
|
20
20
|
overflow: hidden;
|
|
21
21
|
animation: rte-anchor-dialog-appear 0.2s ease;
|
|
22
|
-
`,!document.getElementById("rte-anchor-dialog-styles")){const
|
|
22
|
+
`,!document.getElementById("rte-anchor-dialog-styles")){const s=document.createElement("style");s.id="rte-anchor-dialog-styles",s.textContent=`
|
|
23
23
|
@keyframes rte-anchor-dialog-appear {
|
|
24
24
|
from { opacity: 0; transform: scale(0.95); }
|
|
25
25
|
to { opacity: 1; transform: scale(1); }
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
.rte-anchor-dialog input:focus {
|
|
28
28
|
outline: none !important;
|
|
29
29
|
}
|
|
30
|
-
`,document.head.appendChild(
|
|
30
|
+
`,document.head.appendChild(s)}let l="";const h=document.createElement("div");h.style.cssText=`
|
|
31
31
|
display: flex;
|
|
32
32
|
align-items: center;
|
|
33
33
|
justify-content: space-between;
|
|
34
34
|
padding: 16px 20px;
|
|
35
35
|
border-bottom: 1px solid ${e.border};
|
|
36
36
|
background: ${e.panelBg};
|
|
37
|
-
`;const C=document.createElement("h3");C.style.cssText=`margin: 0; font-size: 18px; font-weight: 600; color: ${e.text};`,C.textContent="Add Anchor";const
|
|
37
|
+
`;const C=document.createElement("h3");C.style.cssText=`margin: 0; font-size: 18px; font-weight: 600; color: ${e.text};`,C.textContent="Add Anchor";const f=document.createElement("button");f.textContent="✕",f.style.cssText=`
|
|
38
38
|
background: none;
|
|
39
39
|
border: none;
|
|
40
40
|
font-size: 24px;
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
justify-content: center;
|
|
49
49
|
border-radius: 4px;
|
|
50
50
|
transition: all 0.2s ease;
|
|
51
|
-
`,
|
|
51
|
+
`,f.onmouseover=()=>{f.style.background=e.closeHoverBg,f.style.color="#f8fafc"},f.onmouseout=()=>{f.style.background="none",f.style.color=e.muted},h.appendChild(C),h.appendChild(f);const B=document.createElement("div");B.style.cssText="padding: 20px;";const m=document.createElement("div");m.style.cssText="margin-bottom: 0;";const y=document.createElement("label");y.textContent="Anchor ID",y.style.cssText=`display: block; font-size: 14px; font-weight: 500; color: ${e.text}; margin-bottom: 8px;`,y.setAttribute("for","anchor-id-input");const o=document.createElement("input");o.id="anchor-id-input",o.type="text",o.placeholder="e.g., section-introduction",o.value="",o.style.cssText=`
|
|
52
52
|
width: 100%;
|
|
53
53
|
padding: 10px 12px;
|
|
54
54
|
font-size: 14px;
|
|
@@ -59,12 +59,12 @@
|
|
|
59
59
|
background: ${e.fieldBg};
|
|
60
60
|
transition: all 0.2s ease;
|
|
61
61
|
box-sizing: border-box;
|
|
62
|
-
`,
|
|
62
|
+
`,o.style.setProperty("caret-color",e.fieldText);const p=document.createElement("div");p.style.cssText=`
|
|
63
63
|
color: #d32f2f;
|
|
64
64
|
font-size: 12px;
|
|
65
65
|
margin-top: 6px;
|
|
66
66
|
display: none;
|
|
67
|
-
`;const k=document.createElement("div");k.textContent="URL-safe ID (letters, numbers, hyphens, underscores). Must start with letter or underscore.",k.style.cssText=`color: ${e.help}; font-size: 12px; margin-top: 8px; line-height: 1.4;`,
|
|
67
|
+
`;const k=document.createElement("div");k.textContent="URL-safe ID (letters, numbers, hyphens, underscores). Must start with letter or underscore.",k.style.cssText=`color: ${e.help}; font-size: 12px; margin-top: 8px; line-height: 1.4;`,m.appendChild(y),m.appendChild(o),m.appendChild(p),m.appendChild(k),B.appendChild(m);const v=document.createElement("div");v.style.cssText=`
|
|
68
68
|
display: flex;
|
|
69
69
|
gap: 12px;
|
|
70
70
|
padding: 16px 20px;
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
transition: all 0.2s ease;
|
|
82
82
|
background: ${e.cancelBg};
|
|
83
83
|
color: ${e.cancelText};
|
|
84
|
-
`,g.onmouseover=()=>g.style.background=e.cancelHover,g.onmouseout=()=>g.style.background=e.cancelBg;const
|
|
84
|
+
`,g.onmouseover=()=>g.style.background=e.cancelHover,g.onmouseout=()=>g.style.background=e.cancelBg;const a=document.createElement("button");a.textContent="Add Anchor",a.style.cssText=`
|
|
85
85
|
padding: 8px 16px;
|
|
86
86
|
font-size: 14px;
|
|
87
87
|
font-weight: 500;
|
|
@@ -91,11 +91,11 @@
|
|
|
91
91
|
transition: all 0.2s ease;
|
|
92
92
|
background: ${e.saveBg};
|
|
93
93
|
color: white;
|
|
94
|
-
`,
|
|
94
|
+
`,a.disabled=!o.value.trim();const N=()=>{o.value.trim()?(a.disabled=!1,a.style.background=e.saveBg,a.style.color="white",a.style.cursor="pointer"):(a.disabled=!0,a.style.background=e.saveDisabledBg,a.style.color=e.saveDisabledText,a.style.cursor="not-allowed")};a.onmouseover=()=>{a.disabled||(a.style.background=e.saveHover,a.style.boxShadow=d?"0 2px 8px rgba(59, 130, 246, 0.35)":"0 2px 8px rgba(0, 102, 204, 0.3)")},a.onmouseout=()=>{a.disabled||(a.style.background=e.saveBg,a.style.boxShadow="none")},v.appendChild(g),v.appendChild(a),o.oninput=()=>{const s=o.value;if(N(),s.trim()){const T=S(s);T.valid?b.has(s)?(l=`Anchor ID already exists: ${s}`,p.textContent="⚠ "+l,p.style.display="block",o.style.borderColor=e.fieldErrorBorder,o.style.background=e.fieldErrorBg):(l="",p.style.display="none",o.style.borderColor=e.fieldBorder,o.style.background=e.fieldBg):(l=T.error,p.textContent="⚠ "+l,p.style.display="block",o.style.borderColor=e.fieldErrorBorder,o.style.background=e.fieldErrorBg)}else p.style.display="none",o.style.borderColor=e.fieldBorder,o.style.background=e.fieldBg},o.onfocus=()=>{o.style.borderColor=l?e.fieldErrorBorder:e.saveBg,o.style.boxShadow=l?`0 0 0 3px ${e.errorRing}`:`0 0 0 3px ${e.focusRing}`,o.style.background=l?e.fieldErrorBg:e.fieldFocusBg},o.onblur=()=>{o.style.boxShadow="none",l||(o.style.background=e.fieldBg)};const A=()=>{const s=o.value.trim();!s||!S(s).valid||b.has(s)||(i&&i(s),n.remove())},E=()=>{n.remove()};a.onclick=A,g.onclick=E,f.onclick=E,o.onkeydown=s=>{s.key==="Enter"?(s.preventDefault(),A()):s.key==="Escape"&&(s.preventDefault(),E())},n.onclick=s=>{s.target===n&&E()},u.appendChild(h),u.appendChild(B),u.appendChild(v),n.appendChild(u),document.body.appendChild(n),setTimeout(()=>o.focus(),100)}function _(t,c){let i;if(c)i=c;else{const l=window.getSelection();if(!l||l.rangeCount===0)return;i=l.getRangeAt(0)}let r=null,d=i.startContainer;for(;d&&d!==document.body;){if(d.nodeType===Node.ELEMENT_NODE){const l=d;if(l.getAttribute("contenteditable")==="true"){r=l;break}}d=d.parentNode}const e=r?.innerHTML??"",n=document.createElement("span");n.id=t,n.className="rte-anchor",n.setAttribute("data-type","anchor"),n.setAttribute("data-anchor-id",t),n.setAttribute("title",`Anchor: ${t}`),n.style.cssText=`
|
|
95
95
|
display: inline;
|
|
96
96
|
position: relative;
|
|
97
97
|
cursor: pointer;
|
|
98
|
-
`,
|
|
98
|
+
`,i.insertNode(n),b.add(t),i.setStart(n.nextSibling||n.parentNode,0),i.collapse(!0);const u=window.getSelection();if(u&&(u.removeAllRanges(),u.addRange(i)),r)$(r,e),r.dispatchEvent(new Event("input",{bubbles:!0}));else{const l=w.findEditorContainerFromSelection();if(l){const h=w.getContentElement(l);h&&h.dispatchEvent(new Event("input",{bubbles:!0}))}}D()}function D(){if(document.getElementById("rte-anchor-styles"))return;const t=document.createElement("style");t.id="rte-anchor-styles",t.textContent=`
|
|
99
99
|
.rte-anchor {
|
|
100
100
|
display: inline;
|
|
101
101
|
position: relative;
|
|
@@ -173,4 +173,4 @@
|
|
|
173
173
|
outline: 2px solid #0066cc;
|
|
174
174
|
outline-offset: 2px;
|
|
175
175
|
}
|
|
176
|
-
`,document.head.appendChild(
|
|
176
|
+
`,document.head.appendChild(t)}const I=()=>(typeof window<"u"&&(z(),D()),{name:"anchor",toolbar:[{label:"Anchor",command:"insertAnchor",icon:'<svg width="24px" height="24px" viewBox="0 0 24 24" fill="none" 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="M12 8.4C13.4912 8.4 14.7 7.19117 14.7 5.7C14.7 4.20883 13.4912 3 12 3C10.5088 3 9.3 4.20883 9.3 5.7C9.3 7.19117 10.5088 8.4 12 8.4ZM12 8.4V20.9999M12 20.9999C9.61305 20.9999 7.32387 20.0518 5.63604 18.364C3.94821 16.6761 3 14.3869 3 12H5M12 20.9999C14.3869 20.9999 16.6761 20.0518 18.364 18.364C20.0518 16.6761 21 14.3869 21 12H19" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>',shortcut:"Mod-Shift-k"}],commands:{insertAnchor:()=>{try{const t=window.getSelection();if(!t||t.rangeCount===0)return alert("Please place your cursor where you want to insert the anchor."),!1;const c=t.getRangeAt(0).cloneRange();return H("add","",i=>{_(i,c)},c),!0}catch(t){return console.error("Failed to insert anchor:",t),!1}}},keymap:{"Mod-Shift-k":"insertAnchor"}});exports.AnchorPlugin=I;
|
package/dist/anchor.esm.js
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
|
-
import { f as
|
|
2
|
-
const
|
|
1
|
+
import { f as D, g as S } from "./editorContainerHelpers-C7kdWnS0.mjs";
|
|
2
|
+
const b = /* @__PURE__ */ new Set(), x = '[data-theme="dark"], .dark, .editora-theme-dark';
|
|
3
|
+
function z(t, c) {
|
|
4
|
+
if (c === t.innerHTML) return;
|
|
5
|
+
const i = window.execEditorCommand || window.executeEditorCommand;
|
|
6
|
+
if (typeof i == "function")
|
|
7
|
+
try {
|
|
8
|
+
i("recordDomTransaction", t, c, t.innerHTML);
|
|
9
|
+
} catch {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
3
12
|
function R() {
|
|
4
13
|
if (typeof window > "u" || window.__anchorObserverInitialized) return;
|
|
5
|
-
window.__anchorObserverInitialized = !0, new MutationObserver((
|
|
6
|
-
|
|
7
|
-
i.removedNodes.forEach((
|
|
8
|
-
if (
|
|
9
|
-
const d =
|
|
14
|
+
window.__anchorObserverInitialized = !0, new MutationObserver((c) => {
|
|
15
|
+
c.forEach((i) => {
|
|
16
|
+
i.removedNodes.forEach((n) => {
|
|
17
|
+
if (n.nodeType === Node.ELEMENT_NODE) {
|
|
18
|
+
const d = n;
|
|
10
19
|
if (d.classList?.contains("rte-anchor")) {
|
|
11
|
-
const
|
|
12
|
-
|
|
20
|
+
const r = d.id;
|
|
21
|
+
r && b.delete(r);
|
|
13
22
|
}
|
|
14
|
-
d.querySelectorAll?.(".rte-anchor")?.forEach((
|
|
15
|
-
const u =
|
|
16
|
-
u &&
|
|
23
|
+
d.querySelectorAll?.(".rte-anchor")?.forEach((r) => {
|
|
24
|
+
const u = r.id;
|
|
25
|
+
u && b.delete(u);
|
|
17
26
|
});
|
|
18
27
|
}
|
|
19
28
|
});
|
|
@@ -23,35 +32,35 @@ function R() {
|
|
|
23
32
|
subtree: !0
|
|
24
33
|
});
|
|
25
34
|
}
|
|
26
|
-
function A(
|
|
27
|
-
return !
|
|
35
|
+
function A(t) {
|
|
36
|
+
return !t || t.trim().length === 0 ? { valid: !1, error: "Anchor ID cannot be empty" } : t.length > 256 ? { valid: !1, error: "Anchor ID must be less than 256 characters" } : /^[a-z_]/.test(t) ? /^[a-z0-9\-_]+$/.test(t) ? { valid: !0, error: "" } : { valid: !1, error: "Anchor ID can only contain letters, numbers, hyphens, and underscores" } : { valid: !1, error: "Anchor ID must start with a letter or underscore" };
|
|
28
37
|
}
|
|
29
|
-
function
|
|
30
|
-
const
|
|
31
|
-
if (!
|
|
32
|
-
const
|
|
33
|
-
if (!
|
|
34
|
-
const i =
|
|
38
|
+
function M() {
|
|
39
|
+
const t = D();
|
|
40
|
+
if (!t) return;
|
|
41
|
+
const c = S(t);
|
|
42
|
+
if (!c) return;
|
|
43
|
+
const i = c.querySelectorAll(".rte-anchor"), n = /* @__PURE__ */ new Set();
|
|
35
44
|
i.forEach((d) => {
|
|
36
45
|
const e = d.id;
|
|
37
|
-
e &&
|
|
38
|
-
}),
|
|
46
|
+
e && n.add(e);
|
|
47
|
+
}), b.clear(), n.forEach((d) => b.add(d));
|
|
39
48
|
}
|
|
40
|
-
function
|
|
41
|
-
if (
|
|
42
|
-
const
|
|
43
|
-
if ((
|
|
49
|
+
function H(t) {
|
|
50
|
+
if (t) {
|
|
51
|
+
const n = t.startContainer;
|
|
52
|
+
if ((n.nodeType === Node.ELEMENT_NODE ? n : n.parentElement)?.closest(x)) return !0;
|
|
44
53
|
}
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
47
|
-
const
|
|
48
|
-
if ((
|
|
54
|
+
const c = window.getSelection();
|
|
55
|
+
if (c && c.rangeCount > 0) {
|
|
56
|
+
const n = c.getRangeAt(0).startContainer;
|
|
57
|
+
if ((n.nodeType === Node.ELEMENT_NODE ? n : n.parentElement)?.closest(x)) return !0;
|
|
49
58
|
}
|
|
50
|
-
return document.activeElement?.closest(
|
|
59
|
+
return document.activeElement?.closest(x) ? !0 : document.body.matches(x) || document.documentElement.matches(x);
|
|
51
60
|
}
|
|
52
|
-
function _(
|
|
53
|
-
|
|
54
|
-
const d =
|
|
61
|
+
function _(t, c, i, n) {
|
|
62
|
+
M();
|
|
63
|
+
const d = H(n), e = d ? {
|
|
55
64
|
overlay: "rgba(0, 0, 0, 0.62)",
|
|
56
65
|
dialogBg: "#1f2937",
|
|
57
66
|
panelBg: "#222d3a",
|
|
@@ -99,8 +108,8 @@ function _(o, l, i, r) {
|
|
|
99
108
|
help: "#999999",
|
|
100
109
|
focusRing: "rgba(0, 102, 204, 0.1)",
|
|
101
110
|
errorRing: "rgba(211, 47, 47, 0.1)"
|
|
102
|
-
},
|
|
103
|
-
|
|
111
|
+
}, r = document.createElement("div");
|
|
112
|
+
r.className = "rte-anchor-dialog-overlay", r.style.cssText = `
|
|
104
113
|
position: fixed;
|
|
105
114
|
top: 0;
|
|
106
115
|
left: 0;
|
|
@@ -135,9 +144,9 @@ function _(o, l, i, r) {
|
|
|
135
144
|
}
|
|
136
145
|
`, document.head.appendChild(s);
|
|
137
146
|
}
|
|
138
|
-
let
|
|
139
|
-
const
|
|
140
|
-
|
|
147
|
+
let l = "";
|
|
148
|
+
const h = document.createElement("div");
|
|
149
|
+
h.style.cssText = `
|
|
141
150
|
display: flex;
|
|
142
151
|
align-items: center;
|
|
143
152
|
justify-content: space-between;
|
|
@@ -147,8 +156,8 @@ function _(o, l, i, r) {
|
|
|
147
156
|
`;
|
|
148
157
|
const w = document.createElement("h3");
|
|
149
158
|
w.style.cssText = `margin: 0; font-size: 18px; font-weight: 600; color: ${e.text};`, w.textContent = "Add Anchor";
|
|
150
|
-
const
|
|
151
|
-
|
|
159
|
+
const f = document.createElement("button");
|
|
160
|
+
f.textContent = "✕", f.style.cssText = `
|
|
152
161
|
background: none;
|
|
153
162
|
border: none;
|
|
154
163
|
font-size: 24px;
|
|
@@ -162,19 +171,19 @@ function _(o, l, i, r) {
|
|
|
162
171
|
justify-content: center;
|
|
163
172
|
border-radius: 4px;
|
|
164
173
|
transition: all 0.2s ease;
|
|
165
|
-
`,
|
|
166
|
-
|
|
167
|
-
},
|
|
168
|
-
|
|
169
|
-
},
|
|
174
|
+
`, f.onmouseover = () => {
|
|
175
|
+
f.style.background = e.closeHoverBg, f.style.color = "#f8fafc";
|
|
176
|
+
}, f.onmouseout = () => {
|
|
177
|
+
f.style.background = "none", f.style.color = e.muted;
|
|
178
|
+
}, h.appendChild(w), h.appendChild(f);
|
|
170
179
|
const C = document.createElement("div");
|
|
171
180
|
C.style.cssText = "padding: 20px;";
|
|
172
|
-
const
|
|
173
|
-
|
|
181
|
+
const m = document.createElement("div");
|
|
182
|
+
m.style.cssText = "margin-bottom: 0;";
|
|
174
183
|
const y = document.createElement("label");
|
|
175
184
|
y.textContent = "Anchor ID", y.style.cssText = `display: block; font-size: 14px; font-weight: 500; color: ${e.text}; margin-bottom: 8px;`, y.setAttribute("for", "anchor-id-input");
|
|
176
|
-
const
|
|
177
|
-
|
|
185
|
+
const o = document.createElement("input");
|
|
186
|
+
o.id = "anchor-id-input", o.type = "text", o.placeholder = "e.g., section-introduction", o.value = "", o.style.cssText = `
|
|
178
187
|
width: 100%;
|
|
179
188
|
padding: 10px 12px;
|
|
180
189
|
font-size: 14px;
|
|
@@ -185,16 +194,16 @@ function _(o, l, i, r) {
|
|
|
185
194
|
background: ${e.fieldBg};
|
|
186
195
|
transition: all 0.2s ease;
|
|
187
196
|
box-sizing: border-box;
|
|
188
|
-
`,
|
|
189
|
-
const
|
|
190
|
-
|
|
197
|
+
`, o.style.setProperty("caret-color", e.fieldText);
|
|
198
|
+
const p = document.createElement("div");
|
|
199
|
+
p.style.cssText = `
|
|
191
200
|
color: #d32f2f;
|
|
192
201
|
font-size: 12px;
|
|
193
202
|
margin-top: 6px;
|
|
194
203
|
display: none;
|
|
195
204
|
`;
|
|
196
205
|
const B = document.createElement("div");
|
|
197
|
-
B.textContent = "URL-safe ID (letters, numbers, hyphens, underscores). Must start with letter or underscore.", B.style.cssText = `color: ${e.help}; font-size: 12px; margin-top: 8px; line-height: 1.4;`,
|
|
206
|
+
B.textContent = "URL-safe ID (letters, numbers, hyphens, underscores). Must start with letter or underscore.", B.style.cssText = `color: ${e.help}; font-size: 12px; margin-top: 8px; line-height: 1.4;`, m.appendChild(y), m.appendChild(o), m.appendChild(p), m.appendChild(B), C.appendChild(m);
|
|
198
207
|
const v = document.createElement("div");
|
|
199
208
|
v.style.cssText = `
|
|
200
209
|
display: flex;
|
|
@@ -216,8 +225,8 @@ function _(o, l, i, r) {
|
|
|
216
225
|
background: ${e.cancelBg};
|
|
217
226
|
color: ${e.cancelText};
|
|
218
227
|
`, g.onmouseover = () => g.style.background = e.cancelHover, g.onmouseout = () => g.style.background = e.cancelBg;
|
|
219
|
-
const
|
|
220
|
-
|
|
228
|
+
const a = document.createElement("button");
|
|
229
|
+
a.textContent = "Add Anchor", a.style.cssText = `
|
|
221
230
|
padding: 8px 16px;
|
|
222
231
|
font-size: 14px;
|
|
223
232
|
font-weight: 500;
|
|
@@ -227,66 +236,80 @@ function _(o, l, i, r) {
|
|
|
227
236
|
transition: all 0.2s ease;
|
|
228
237
|
background: ${e.saveBg};
|
|
229
238
|
color: white;
|
|
230
|
-
`,
|
|
231
|
-
const
|
|
232
|
-
|
|
239
|
+
`, a.disabled = !o.value.trim();
|
|
240
|
+
const $ = () => {
|
|
241
|
+
o.value.trim() ? (a.disabled = !1, a.style.background = e.saveBg, a.style.color = "white", a.style.cursor = "pointer") : (a.disabled = !0, a.style.background = e.saveDisabledBg, a.style.color = e.saveDisabledText, a.style.cursor = "not-allowed");
|
|
233
242
|
};
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
},
|
|
237
|
-
|
|
238
|
-
}, v.appendChild(g), v.appendChild(
|
|
239
|
-
const s =
|
|
240
|
-
if (
|
|
243
|
+
a.onmouseover = () => {
|
|
244
|
+
a.disabled || (a.style.background = e.saveHover, a.style.boxShadow = d ? "0 2px 8px rgba(59, 130, 246, 0.35)" : "0 2px 8px rgba(0, 102, 204, 0.3)");
|
|
245
|
+
}, a.onmouseout = () => {
|
|
246
|
+
a.disabled || (a.style.background = e.saveBg, a.style.boxShadow = "none");
|
|
247
|
+
}, v.appendChild(g), v.appendChild(a), o.oninput = () => {
|
|
248
|
+
const s = o.value;
|
|
249
|
+
if ($(), s.trim()) {
|
|
241
250
|
const k = A(s);
|
|
242
|
-
k.valid ?
|
|
251
|
+
k.valid ? b.has(s) ? (l = `Anchor ID already exists: ${s}`, p.textContent = "⚠ " + l, p.style.display = "block", o.style.borderColor = e.fieldErrorBorder, o.style.background = e.fieldErrorBg) : (l = "", p.style.display = "none", o.style.borderColor = e.fieldBorder, o.style.background = e.fieldBg) : (l = k.error, p.textContent = "⚠ " + l, p.style.display = "block", o.style.borderColor = e.fieldErrorBorder, o.style.background = e.fieldErrorBg);
|
|
243
252
|
} else
|
|
244
|
-
|
|
245
|
-
},
|
|
246
|
-
|
|
247
|
-
},
|
|
248
|
-
|
|
253
|
+
p.style.display = "none", o.style.borderColor = e.fieldBorder, o.style.background = e.fieldBg;
|
|
254
|
+
}, o.onfocus = () => {
|
|
255
|
+
o.style.borderColor = l ? e.fieldErrorBorder : e.saveBg, o.style.boxShadow = l ? `0 0 0 3px ${e.errorRing}` : `0 0 0 3px ${e.focusRing}`, o.style.background = l ? e.fieldErrorBg : e.fieldFocusBg;
|
|
256
|
+
}, o.onblur = () => {
|
|
257
|
+
o.style.boxShadow = "none", l || (o.style.background = e.fieldBg);
|
|
249
258
|
};
|
|
250
259
|
const T = () => {
|
|
251
|
-
const s =
|
|
252
|
-
!s || !A(s).valid ||
|
|
260
|
+
const s = o.value.trim();
|
|
261
|
+
!s || !A(s).valid || b.has(s) || (i && i(s), r.remove());
|
|
253
262
|
}, E = () => {
|
|
254
|
-
|
|
263
|
+
r.remove();
|
|
255
264
|
};
|
|
256
|
-
|
|
265
|
+
a.onclick = T, g.onclick = E, f.onclick = E, o.onkeydown = (s) => {
|
|
257
266
|
s.key === "Enter" ? (s.preventDefault(), T()) : s.key === "Escape" && (s.preventDefault(), E());
|
|
258
|
-
},
|
|
259
|
-
s.target ===
|
|
260
|
-
}, u.appendChild(
|
|
267
|
+
}, r.onclick = (s) => {
|
|
268
|
+
s.target === r && E();
|
|
269
|
+
}, u.appendChild(h), u.appendChild(C), u.appendChild(v), r.appendChild(u), document.body.appendChild(r), setTimeout(() => o.focus(), 100);
|
|
261
270
|
}
|
|
262
|
-
function
|
|
271
|
+
function I(t, c) {
|
|
263
272
|
let i;
|
|
264
|
-
if (
|
|
265
|
-
i =
|
|
273
|
+
if (c)
|
|
274
|
+
i = c;
|
|
266
275
|
else {
|
|
267
|
-
const
|
|
268
|
-
if (!
|
|
269
|
-
i =
|
|
276
|
+
const l = window.getSelection();
|
|
277
|
+
if (!l || l.rangeCount === 0) return;
|
|
278
|
+
i = l.getRangeAt(0);
|
|
270
279
|
}
|
|
271
|
-
|
|
272
|
-
|
|
280
|
+
let n = null, d = i.startContainer;
|
|
281
|
+
for (; d && d !== document.body; ) {
|
|
282
|
+
if (d.nodeType === Node.ELEMENT_NODE) {
|
|
283
|
+
const l = d;
|
|
284
|
+
if (l.getAttribute("contenteditable") === "true") {
|
|
285
|
+
n = l;
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
d = d.parentNode;
|
|
290
|
+
}
|
|
291
|
+
const e = n?.innerHTML ?? "", r = document.createElement("span");
|
|
292
|
+
r.id = t, r.className = "rte-anchor", r.setAttribute("data-type", "anchor"), r.setAttribute("data-anchor-id", t), r.setAttribute("title", `Anchor: ${t}`), r.style.cssText = `
|
|
273
293
|
display: inline;
|
|
274
294
|
position: relative;
|
|
275
295
|
cursor: pointer;
|
|
276
|
-
`, i.insertNode(r),
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const
|
|
282
|
-
|
|
296
|
+
`, i.insertNode(r), b.add(t), i.setStart(r.nextSibling || r.parentNode, 0), i.collapse(!0);
|
|
297
|
+
const u = window.getSelection();
|
|
298
|
+
if (u && (u.removeAllRanges(), u.addRange(i)), n)
|
|
299
|
+
z(n, e), n.dispatchEvent(new Event("input", { bubbles: !0 }));
|
|
300
|
+
else {
|
|
301
|
+
const l = D();
|
|
302
|
+
if (l) {
|
|
303
|
+
const h = S(l);
|
|
304
|
+
h && h.dispatchEvent(new Event("input", { bubbles: !0 }));
|
|
305
|
+
}
|
|
283
306
|
}
|
|
284
|
-
|
|
307
|
+
N();
|
|
285
308
|
}
|
|
286
|
-
function
|
|
309
|
+
function N() {
|
|
287
310
|
if (document.getElementById("rte-anchor-styles")) return;
|
|
288
|
-
const
|
|
289
|
-
|
|
311
|
+
const t = document.createElement("style");
|
|
312
|
+
t.id = "rte-anchor-styles", t.textContent = `
|
|
290
313
|
.rte-anchor {
|
|
291
314
|
display: inline;
|
|
292
315
|
position: relative;
|
|
@@ -364,9 +387,9 @@ function $() {
|
|
|
364
387
|
outline: 2px solid #0066cc;
|
|
365
388
|
outline-offset: 2px;
|
|
366
389
|
}
|
|
367
|
-
`, document.head.appendChild(
|
|
390
|
+
`, document.head.appendChild(t);
|
|
368
391
|
}
|
|
369
|
-
const O = () => (typeof window < "u" && (R(),
|
|
392
|
+
const O = () => (typeof window < "u" && (R(), N()), {
|
|
370
393
|
name: "anchor",
|
|
371
394
|
toolbar: [
|
|
372
395
|
{
|
|
@@ -379,15 +402,15 @@ const O = () => (typeof window < "u" && (R(), $()), {
|
|
|
379
402
|
commands: {
|
|
380
403
|
insertAnchor: () => {
|
|
381
404
|
try {
|
|
382
|
-
const
|
|
383
|
-
if (!
|
|
405
|
+
const t = window.getSelection();
|
|
406
|
+
if (!t || t.rangeCount === 0)
|
|
384
407
|
return alert("Please place your cursor where you want to insert the anchor."), !1;
|
|
385
|
-
const
|
|
408
|
+
const c = t.getRangeAt(0).cloneRange();
|
|
386
409
|
return _("add", "", (i) => {
|
|
387
|
-
|
|
388
|
-
},
|
|
389
|
-
} catch (
|
|
390
|
-
return console.error("Failed to insert anchor:",
|
|
410
|
+
I(i, c);
|
|
411
|
+
}, c), !0;
|
|
412
|
+
} catch (t) {
|
|
413
|
+
return console.error("Failed to insert anchor:", t), !1;
|
|
391
414
|
}
|
|
392
415
|
}
|
|
393
416
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const b="p,div,li,ul,ol,table,thead,tbody,tfoot,tr,td,th,h1,h2,h3,h4,h5,h6,blockquote,pre";function p(e){return!!e.cloneContents().querySelector(b)}function v(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=v(e,t);n&&n.dispatchEvent(new Event("input",{bubbles:!0}))}function A(e,t){let r=e.startContainer.nodeType===Node.TEXT_NODE?e.startContainer.parentElement:e.startContainer;for(;r&&r!==document.body;){if(r.classList.contains(t)){const c=document.createRange();if(c.selectNodeContents(r),c.compareBoundaryPoints(Range.START_TO_START,e)<=0&&c.compareBoundaryPoints(Range.END_TO_END,e)>=0)return r}r=r.parentElement}return null}function S(e){try{if(e.savedRange){const o=window.getSelection();o&&(o.removeAllRanges(),o.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 r=A(n,e.className);if(r)return e.styleProperty==="backgroundColor"?r.style.backgroundColor=e.color:r.style.color=e.color,C(r,e.getActiveEditorRoot),!0;v(n.commonAncestorContainer,e.getActiveEditorRoot)?.focus({preventScroll:!0});try{document.execCommand("styleWithCSS",!1,"true")}catch{}let l=!1;if(e.commands.forEach(o=>{l||(l=document.execCommand(o,!1,e.color))}),!l&&!p(n)){const o=document.createElement("span");e.styleProperty==="backgroundColor"?o.style.backgroundColor=e.color:o.style.color=e.color,o.className=e.className;const a=n.extractContents();o.appendChild(a),n.insertNode(o),n.setStartAfter(o),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}}function T({popover:e,anchor:t,onClose:n,gap:r=6,margin:c=8,zIndex:l=1e4}){e.style.position="fixed",e.style.zIndex=`${l}`,e.style.visibility="hidden";const o=()=>{if(!e.isConnected||!t.isConnected){n();return}const s=t.getBoundingClientRect();if(s.width===0&&s.height===0){n();return}const i=e.getBoundingClientRect(),y=i.width||e.offsetWidth||220,f=i.height||e.offsetHeight||260,w=window.innerWidth,E=window.innerHeight;let u=s.left,d=s.bottom+r;if(u+y>w-c&&(u=w-y-c),u=Math.max(c,u),d+f>E-c){const g=s.top-f-r;g>=c?d=g:d=Math.max(c,E-f-c)}d<c&&(d=c),e.style.left=`${Math.round(u)}px`,e.style.top=`${Math.round(d)}px`,e.style.visibility="visible"},a=()=>{o()},m=s=>{const i=s.target;i&&(e.contains(i)||t.contains(i)||n())},h=s=>{s.key==="Escape"&&n()};window.addEventListener("resize",a),window.addEventListener("scroll",a,!0),document.addEventListener("keydown",h);const R=window.requestAnimationFrame(()=>{document.addEventListener("mousedown",m,!0)});return o(),{reposition:o,destroy:()=>{window.cancelAnimationFrame(R),window.removeEventListener("resize",a),window.removeEventListener("scroll",a,!0),document.removeEventListener("keydown",h),document.removeEventListener("mousedown",m,!0)}}}exports.applyColorToSelection=S;exports.attachAnchoredPopover=T;
|