yurich 0.1.0 → 0.1.1
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 +24 -12
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +1161 -857
- package/package.json +15 -8
package/dist/index.mjs
CHANGED
|
@@ -1,863 +1,1167 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { jsx as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
1
|
+
import { createContext as e, useContext as t, useEffect as n, useRef as r, useState as i, useSyncExternalStore as a } from "react";
|
|
2
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
3
|
+
// src/core/html-policy.ts
|
|
4
|
+
var s = /* @__PURE__ */ new Set([
|
|
5
|
+
"applet",
|
|
6
|
+
"audio",
|
|
7
|
+
"base",
|
|
8
|
+
"embed",
|
|
9
|
+
"fencedframe",
|
|
10
|
+
"frame",
|
|
11
|
+
"frameset",
|
|
12
|
+
"iframe",
|
|
13
|
+
"link",
|
|
14
|
+
"math",
|
|
15
|
+
"meta",
|
|
16
|
+
"noembed",
|
|
17
|
+
"noframes",
|
|
18
|
+
"noscript",
|
|
19
|
+
"object",
|
|
20
|
+
"plaintext",
|
|
21
|
+
"portal",
|
|
22
|
+
"script",
|
|
23
|
+
"style",
|
|
24
|
+
"svg",
|
|
25
|
+
"template",
|
|
26
|
+
"textarea",
|
|
27
|
+
"title",
|
|
28
|
+
"video",
|
|
29
|
+
"xmp"
|
|
30
|
+
]), c = /* @__PURE__ */ new Set([
|
|
31
|
+
"action",
|
|
32
|
+
"background",
|
|
33
|
+
"cite",
|
|
34
|
+
"classid",
|
|
35
|
+
"codebase",
|
|
36
|
+
"data",
|
|
37
|
+
"dynsrc",
|
|
38
|
+
"formaction",
|
|
39
|
+
"href",
|
|
40
|
+
"icon",
|
|
41
|
+
"itemid",
|
|
42
|
+
"longdesc",
|
|
43
|
+
"lowsrc",
|
|
44
|
+
"manifest",
|
|
45
|
+
"poster",
|
|
46
|
+
"profile",
|
|
47
|
+
"src",
|
|
48
|
+
"usemap",
|
|
49
|
+
"xlink:href"
|
|
50
|
+
]), l = /* @__PURE__ */ new Set([
|
|
51
|
+
"archive",
|
|
52
|
+
"attributionsrc",
|
|
53
|
+
"imagesrcset",
|
|
54
|
+
"is",
|
|
55
|
+
"ping",
|
|
56
|
+
"srcdoc",
|
|
57
|
+
"srcset"
|
|
58
|
+
]), u = (e) => s.has(e), d = (e) => /^[a-z][a-z0-9-]*$/.test(e), f = (e) => d(e) && !u(e) && e !== "form" && !e.includes("-"), p = (e, t) => {
|
|
59
|
+
if (!/^(https?:\/\/|mailto:)/i.test(t)) return !1;
|
|
60
|
+
try {
|
|
61
|
+
let { protocol: n } = new URL(t);
|
|
62
|
+
return n === "http:" || n === "https:" || e === "href" && n === "mailto:";
|
|
63
|
+
} catch {
|
|
64
|
+
return !1;
|
|
65
|
+
}
|
|
66
|
+
}, m = (e) => /^[a-z][a-z0-9_.:-]*$/.test(e) && !e.startsWith("on") && !l.has(e), h = (e, t) => {
|
|
67
|
+
let n = [];
|
|
68
|
+
for (let [r, i] of Object.entries(t.attrs ?? {})) {
|
|
69
|
+
let t = r.toLowerCase();
|
|
70
|
+
if (!m(t)) continue;
|
|
71
|
+
let a = i(e.getAttribute(t), e);
|
|
72
|
+
a !== null && (!c.has(t) || p(t, a)) && n.push([t, a]);
|
|
73
|
+
}
|
|
74
|
+
return n;
|
|
75
|
+
}, g = {
|
|
76
|
+
tag: "p",
|
|
77
|
+
type: "paragraph",
|
|
78
|
+
aliases: ["div"]
|
|
79
|
+
}, _ = (e) => {
|
|
80
|
+
let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = (e, t) => {
|
|
81
|
+
if (!f(t.tag)) return;
|
|
82
|
+
let n = t.aliases?.filter((e) => d(e) && !u(e) && e !== "form"), r = {
|
|
83
|
+
...t,
|
|
84
|
+
aliases: n
|
|
85
|
+
};
|
|
86
|
+
for (let t of [r.tag, ...n ?? []]) e.set(t, r);
|
|
87
|
+
};
|
|
88
|
+
i(n, g);
|
|
89
|
+
for (let a of e) {
|
|
90
|
+
a.marks?.forEach((e) => i(t, e)), a.blocks?.forEach((e) => i(n, e));
|
|
91
|
+
for (let [e, t] of Object.entries(a.blockStyles ?? {})) r.set(e, new Set(t));
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
marks: t,
|
|
95
|
+
blocks: n,
|
|
96
|
+
blockStyles: r,
|
|
97
|
+
blockSelector: Array.from(n.keys()).join(",")
|
|
98
|
+
};
|
|
99
|
+
}, v = (e, t) => e instanceof HTMLElement && t.blocks.has(e.localName), ee = 300, te = (e) => {
|
|
100
|
+
let t = [], n = [], r = {
|
|
101
|
+
blocks: [],
|
|
102
|
+
before: null,
|
|
103
|
+
after: null
|
|
104
|
+
}, i = null, a = null, o = () => {
|
|
105
|
+
a !== null && (clearTimeout(a), a = null), i && (t.push(r), t.length > e && t.shift(), r = i, i = null, n = []);
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
reset(e) {
|
|
109
|
+
t = [], n = [], i = null, r = {
|
|
110
|
+
blocks: e,
|
|
111
|
+
before: null,
|
|
112
|
+
after: null
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
record(e, t) {
|
|
116
|
+
t ? (i = i ? {
|
|
117
|
+
...e,
|
|
118
|
+
before: i.before
|
|
119
|
+
} : e, a !== null && clearTimeout(a), a = setTimeout(o, ee)) : (o(), i = e, o());
|
|
120
|
+
},
|
|
121
|
+
undo() {
|
|
122
|
+
o();
|
|
123
|
+
let e = t.pop();
|
|
124
|
+
if (!e) return null;
|
|
125
|
+
let i = r;
|
|
126
|
+
return n.push(i), r = e, {
|
|
127
|
+
blocks: e.blocks,
|
|
128
|
+
selection: i.before
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
redo() {
|
|
132
|
+
o();
|
|
133
|
+
let e = n.pop();
|
|
134
|
+
return e ? (t.push(r), r = e, {
|
|
135
|
+
blocks: e.blocks,
|
|
136
|
+
selection: e.after
|
|
137
|
+
}) : null;
|
|
138
|
+
},
|
|
139
|
+
canUndo: () => t.length > 0 || i !== null,
|
|
140
|
+
canRedo: () => n.length > 0 && i === null,
|
|
141
|
+
cancelTimer() {
|
|
142
|
+
a !== null && (clearTimeout(a), a = null);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}, y = (e) => {
|
|
146
|
+
let t = window.getSelection();
|
|
147
|
+
if (!t || t.rangeCount === 0) return null;
|
|
148
|
+
let n = t.getRangeAt(0);
|
|
149
|
+
return e.contains(n.commonAncestorContainer) ? n : null;
|
|
150
|
+
}, b = (e) => {
|
|
151
|
+
let t = window.getSelection();
|
|
152
|
+
t && (t.removeAllRanges(), t.addRange(e));
|
|
153
|
+
}, x = (e, t) => {
|
|
154
|
+
let n = document.createRange();
|
|
155
|
+
n.setStart(e, 0), n.setEnd(t, t.length), b(n);
|
|
156
|
+
}, S = (e) => {
|
|
157
|
+
let t = e;
|
|
158
|
+
for (; t.lastChild;) t = t.lastChild;
|
|
159
|
+
let n = document.createRange();
|
|
160
|
+
t.nodeType === Node.TEXT_NODE ? n.setStart(t, t.length) : t === e ? n.setStart(e, 0) : n.setStartAfter(t), n.collapse(!0), b(n);
|
|
53
161
|
}, C = (e) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
},
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
])
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
v !== null && (y[p] = v);
|
|
260
|
-
}
|
|
261
|
-
return Object.keys(y).length > 0 && (m.attrs = y), r(e.childNodes, [...t, m]);
|
|
262
|
-
}
|
|
263
|
-
const u = n.blocks.get(l);
|
|
264
|
-
if (!u)
|
|
265
|
-
return r(e.childNodes, t);
|
|
266
|
-
const h = { type: u.type }, g = { ...u.attrs };
|
|
267
|
-
for (const m of ke(e.getAttribute("style"), n).split("; ")) {
|
|
268
|
-
const [y, p] = m.split(": ");
|
|
269
|
-
p && (g[Ye(y)] = p);
|
|
270
|
-
}
|
|
271
|
-
Object.keys(g).length > 0 && (h.attrs = g);
|
|
272
|
-
const E = r(e.childNodes, t);
|
|
273
|
-
return E.length > 0 && (h.content = E), [h];
|
|
274
|
-
}, Ee = (e, t) => be(e, [], t, !0), vt = (e, t) => Y(e.childNodes, P(t)), At = (e, t) => {
|
|
275
|
-
const n = P(t);
|
|
276
|
-
return { type: "doc", content: Array.from(e.childNodes).flatMap((s) => Ee(s, n)) };
|
|
277
|
-
}, k = (e) => {
|
|
278
|
-
const t = window.getSelection();
|
|
279
|
-
if (!t || t.rangeCount === 0) return null;
|
|
280
|
-
const n = t.getRangeAt(0);
|
|
281
|
-
return e.contains(n.commonAncestorContainer) ? n : null;
|
|
282
|
-
}, Se = (e) => {
|
|
283
|
-
const t = window.getSelection();
|
|
284
|
-
t && (t.removeAllRanges(), t.addRange(e));
|
|
285
|
-
}, ve = (e, t) => {
|
|
286
|
-
const n = document.createRange();
|
|
287
|
-
n.setStart(e, 0), n.setEnd(t, t.length), Se(n);
|
|
288
|
-
}, Q = (e) => {
|
|
289
|
-
let t = e;
|
|
290
|
-
for (; t.lastChild; ) t = t.lastChild;
|
|
291
|
-
const n = document.createRange();
|
|
292
|
-
t.nodeType === Node.TEXT_NODE ? n.setStart(t, t.length) : t === e ? n.setStart(e, 0) : n.setStartAfter(t), n.collapse(!0), Se(n);
|
|
293
|
-
}, Qe = (e) => {
|
|
294
|
-
let t = e;
|
|
295
|
-
for (; t.lastChild; ) t = t.lastChild;
|
|
296
|
-
const n = window.getSelection();
|
|
297
|
-
t.nodeType === Node.TEXT_NODE ? n?.collapse(t, t.length) : t === e ? n?.collapse(e, 0) : n?.collapse(t.parentNode, Array.prototype.indexOf.call(t.parentNode.childNodes, t));
|
|
298
|
-
}, ae = (e, t, n) => {
|
|
299
|
-
if (t === e)
|
|
300
|
-
return n < e.childNodes.length ? [n, 0] : [Math.max(n - 1, 0), 1 / 0];
|
|
301
|
-
let s = t;
|
|
302
|
-
for (; s.parentNode !== e; ) s = s.parentNode;
|
|
303
|
-
const o = document.createRange();
|
|
304
|
-
return o.setStart(s, 0), o.setEnd(t, n), [Array.prototype.indexOf.call(e.childNodes, s), o.toString().length];
|
|
305
|
-
}, ue = (e, [t, n]) => {
|
|
306
|
-
const s = e.childNodes[Math.min(t, e.childNodes.length - 1)];
|
|
307
|
-
if (!s) return [e, 0];
|
|
308
|
-
const o = document.createTreeWalker(s, NodeFilter.SHOW_TEXT);
|
|
309
|
-
let r = n, l = null;
|
|
310
|
-
for (let i = o.nextNode(); i; i = o.nextNode()) {
|
|
311
|
-
if (r <= i.length) return [i, r];
|
|
312
|
-
r -= i.length, l = i;
|
|
313
|
-
}
|
|
314
|
-
return l ? [l, l.length] : [s, 0];
|
|
315
|
-
}, K = (e) => {
|
|
316
|
-
const t = window.getSelection();
|
|
317
|
-
return !t?.anchorNode || !t.focusNode || !e.contains(t.anchorNode) || !e.contains(t.focusNode) ? null : {
|
|
318
|
-
anchor: ae(e, t.anchorNode, t.anchorOffset),
|
|
319
|
-
focus: ae(e, t.focusNode, t.focusOffset)
|
|
320
|
-
};
|
|
321
|
-
}, Ze = (e, t) => {
|
|
322
|
-
const n = window.getSelection();
|
|
323
|
-
if (!(!n || !e.isConnected)) {
|
|
324
|
-
if (!t) {
|
|
325
|
-
Q(e);
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
n.setBaseAndExtent(...ue(e, t.anchor), ...ue(e, t.focus));
|
|
329
|
-
}
|
|
330
|
-
}, T = (e, t, n) => {
|
|
331
|
-
for (let s = e; s && s !== n; s = s.parentNode)
|
|
332
|
-
if (s instanceof HTMLElement && (s.localName === t.tag || t.aliases?.includes(s.localName)))
|
|
333
|
-
return s;
|
|
334
|
-
return null;
|
|
335
|
-
}, Z = (e, t) => {
|
|
336
|
-
const n = t.commonAncestorContainer, s = n.nodeType === Node.TEXT_NODE ? n.parentNode : n, o = document.createTreeWalker(s, NodeFilter.SHOW_TEXT), r = [];
|
|
337
|
-
for (let l = o.nextNode(); l; l = o.nextNode()) {
|
|
338
|
-
if (!t.intersectsNode(l) || l.parentNode === e || w(l.parentNode)) continue;
|
|
339
|
-
const i = l === t.startContainer ? t.startOffset : 0, u = l === t.endContainer ? t.endOffset : l.length;
|
|
340
|
-
i < u && r.push({ node: l, start: i, end: u });
|
|
341
|
-
}
|
|
342
|
-
return r;
|
|
343
|
-
}, Ae = (e) => e.map(({ node: t, start: n, end: s }) => (s < t.length && t.splitText(s), n > 0 ? t.splitText(n) : t)), de = (e, t) => {
|
|
344
|
-
for (const [n, s] of Object.entries(t ?? {})) e.setAttribute(n, s);
|
|
345
|
-
}, Te = (e, t, n) => {
|
|
346
|
-
if (t.collapsed) return T(t.startContainer, n, e) !== null;
|
|
347
|
-
const s = Z(e, t);
|
|
348
|
-
return s.length > 0 && s.every((o) => T(o.node, n, e));
|
|
349
|
-
}, xe = (e, t, n, s, o) => {
|
|
350
|
-
if (t.collapsed) {
|
|
351
|
-
if (!o) return;
|
|
352
|
-
t.insertNode(document.createTextNode(o));
|
|
353
|
-
}
|
|
354
|
-
const r = Ae(Z(e, t));
|
|
355
|
-
if (r.length !== 0) {
|
|
356
|
-
for (const l of r) {
|
|
357
|
-
const i = T(l, n, e);
|
|
358
|
-
if (i) {
|
|
359
|
-
de(i, s);
|
|
360
|
-
continue;
|
|
361
|
-
}
|
|
362
|
-
const u = document.createElement(n.tag);
|
|
363
|
-
de(u, s), l.replaceWith(u), u.append(l);
|
|
364
|
-
}
|
|
365
|
-
ve(r[0], r[r.length - 1]);
|
|
366
|
-
}
|
|
367
|
-
}, et = (e, t) => {
|
|
368
|
-
const n = document.createRange();
|
|
369
|
-
n.setStart(e, 0), n.setEndBefore(t);
|
|
370
|
-
const s = document.createRange();
|
|
371
|
-
s.setStartAfter(t), s.setEnd(e, e.childNodes.length);
|
|
372
|
-
for (const [o, r] of [[n, "before"], [s, "after"]]) {
|
|
373
|
-
const l = o.extractContents();
|
|
374
|
-
if (!l.textContent && !l.querySelector("br")) continue;
|
|
375
|
-
const i = e.cloneNode(!1);
|
|
376
|
-
i.append(l), e[r](i);
|
|
377
|
-
}
|
|
378
|
-
C(e);
|
|
162
|
+
let t = e;
|
|
163
|
+
for (; t.lastChild;) t = t.lastChild;
|
|
164
|
+
let n = window.getSelection();
|
|
165
|
+
t.nodeType === Node.TEXT_NODE ? n?.collapse(t, t.length) : t === e ? n?.collapse(e, 0) : n?.collapse(t.parentNode, Array.prototype.indexOf.call(t.parentNode.childNodes, t));
|
|
166
|
+
}, w = (e, t, n) => {
|
|
167
|
+
let r = [];
|
|
168
|
+
for (let n = t; n !== e; n = n.parentNode) r.push(Array.prototype.indexOf.call(n.parentNode.childNodes, n));
|
|
169
|
+
return [r.reverse(), n];
|
|
170
|
+
}, T = (e, [t, n]) => {
|
|
171
|
+
let r = e;
|
|
172
|
+
for (let e of t) {
|
|
173
|
+
let t = r.childNodes.item(e);
|
|
174
|
+
if (!t) return [r, r.childNodes.length];
|
|
175
|
+
r = t;
|
|
176
|
+
}
|
|
177
|
+
let i = r.nodeType === Node.TEXT_NODE ? r.length : r.childNodes.length;
|
|
178
|
+
return [r, Math.min(n, i)];
|
|
179
|
+
}, ne = (e, t) => {
|
|
180
|
+
let n = e.firstChild, r = t.firstChild;
|
|
181
|
+
for (; n && r;) {
|
|
182
|
+
if (n.nodeName !== r.nodeName || n.nodeValue !== r.nodeValue || !ne(n, r)) return !1;
|
|
183
|
+
n = n.nextSibling, r = r.nextSibling;
|
|
184
|
+
}
|
|
185
|
+
return n === r;
|
|
186
|
+
}, re = (e, t, n) => {
|
|
187
|
+
let [r, i] = T(e, n), a = document.createRange();
|
|
188
|
+
a.setStart(e, 0), a.setEnd(r, i);
|
|
189
|
+
let o = a.cloneContents(), s = (o.textContent?.length ?? 0) + o.querySelectorAll("br").length, c = r.nodeType === Node.TEXT_NODE ? i === 0 : i < r.childNodes.length, l = document.createTreeWalker(t, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, { acceptNode: (e) => e.nodeType === Node.TEXT_NODE || e.nodeName === "BR" ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP }), u = [t, 0];
|
|
190
|
+
for (let e = l.nextNode(); e; e = l.nextNode()) if (e.nodeType === Node.TEXT_NODE) {
|
|
191
|
+
let t = e.length;
|
|
192
|
+
if (s < t || s === t && !c) return [e, s];
|
|
193
|
+
s -= t, u = [e, t];
|
|
194
|
+
} else {
|
|
195
|
+
let t = e.parentNode, n = Array.prototype.indexOf.call(t.childNodes, e);
|
|
196
|
+
if (s === 0) return [t, n];
|
|
197
|
+
if (s--, u = [t, n + 1], s === 0 && !c) return u;
|
|
198
|
+
}
|
|
199
|
+
return u;
|
|
200
|
+
}, E = (e) => {
|
|
201
|
+
let t = window.getSelection();
|
|
202
|
+
if (!t?.anchorNode || !t.focusNode || !e.contains(t.anchorNode) || !e.contains(t.focusNode)) return null;
|
|
203
|
+
let n = w(e, t.anchorNode, t.anchorOffset);
|
|
204
|
+
return {
|
|
205
|
+
anchor: n,
|
|
206
|
+
focus: t.isCollapsed ? n : w(e, t.focusNode, t.focusOffset)
|
|
207
|
+
};
|
|
208
|
+
}, ie = (e, t, n) => {
|
|
209
|
+
let r = window.getSelection();
|
|
210
|
+
if (r && e.isConnected) {
|
|
211
|
+
if (!t) S(e);
|
|
212
|
+
else {
|
|
213
|
+
if (n !== void 0) {
|
|
214
|
+
let i = e.ownerDocument.createElement("template");
|
|
215
|
+
if (i.innerHTML = n, !ne(i.content, e)) {
|
|
216
|
+
let n = re(i.content, e, t.anchor), a = t.focus === t.anchor ? n : re(i.content, e, t.focus);
|
|
217
|
+
r.setBaseAndExtent(...n, ...a);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
r.setBaseAndExtent(...T(e, t.anchor), ...T(e, t.focus));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}, D = (e, t, n = Array.from(e.attributes, ({ name: e, value: t }) => [e, t])) => {
|
|
225
|
+
let r = e.ownerDocument.createElement(t);
|
|
226
|
+
for (let [e, t] of n) r.setAttribute(e, t);
|
|
227
|
+
return r.append(...e.childNodes), e.replaceWith(r), r;
|
|
228
|
+
}, O = (e) => {
|
|
229
|
+
e.replaceWith(...e.childNodes);
|
|
230
|
+
}, ae = (e, t) => {
|
|
231
|
+
let n = t;
|
|
232
|
+
for (; n && n !== e && n.parentNode !== e;) n = n.parentNode;
|
|
233
|
+
return n === e ? null : n;
|
|
234
|
+
}, k = (e) => e instanceof HTMLElement && (e.localName === "ul" || e.localName === "ol"), oe = (e, t) => e.attributes.length === t.attributes.length && Array.from(e.attributes).every((e) => t.getAttribute(e.name) === e.value), se = (e) => {
|
|
235
|
+
let t = window.getSelection(), n = t?.anchorNode ?? null, r = t?.focusNode ?? null, i = t?.anchorOffset ?? 0, a = t?.focusOffset ?? 0;
|
|
236
|
+
e(), t && n && r && n.nodeType === Node.TEXT_NODE && r.nodeType === Node.TEXT_NODE && n.isConnected && r.isConnected && (t.anchorNode !== n || t.anchorOffset !== i || t.focusNode !== r || t.focusOffset !== a) && t.setBaseAndExtent(n, Math.min(i, n.length), r, Math.min(a, r.length));
|
|
237
|
+
}, A = (e, t, n) => {
|
|
238
|
+
for (let r = e; r && r !== n; r = r.parentNode) if (r instanceof HTMLElement && (r.localName === t.tag || t.aliases?.includes(r.localName))) return r;
|
|
239
|
+
return null;
|
|
240
|
+
}, j = (e, t) => {
|
|
241
|
+
let n = t.commonAncestorContainer, r = n.nodeType === Node.TEXT_NODE ? n.parentNode : n, i = document.createTreeWalker(r, NodeFilter.SHOW_TEXT), a = [];
|
|
242
|
+
for (let n = i.nextNode(); n; n = i.nextNode()) {
|
|
243
|
+
if (!t.intersectsNode(n) || n.parentNode === e || k(n.parentNode)) continue;
|
|
244
|
+
let r = n === t.startContainer ? t.startOffset : 0, i = n === t.endContainer ? t.endOffset : n.length;
|
|
245
|
+
r < i && a.push({
|
|
246
|
+
node: n,
|
|
247
|
+
start: r,
|
|
248
|
+
end: i
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
return a;
|
|
252
|
+
}, ce = (e) => e.map(({ node: e, start: t, end: n }) => (n < e.length && e.splitText(n), t > 0 ? e.splitText(t) : e)), le = (e, t, n, r) => {
|
|
253
|
+
let i = e.ownerDocument.createElement("template").content.ownerDocument.createElement(t.tag);
|
|
254
|
+
i.textContent = r;
|
|
255
|
+
for (let { name: t, value: n } of Array.from(e.attributes)) m(t) && i.setAttribute(t, n);
|
|
256
|
+
for (let [e, t] of Object.entries(n)) m(e.toLowerCase()) && i.setAttribute(e, t);
|
|
257
|
+
let a = new Map(h(i, t));
|
|
258
|
+
for (let t of e.getAttributeNames()) a.has(t) || e.removeAttribute(t);
|
|
259
|
+
for (let [t, n] of a) e.getAttribute(t) !== n && e.setAttribute(t, n);
|
|
260
|
+
}, ue = (e, t, n) => {
|
|
261
|
+
if (t.collapsed) return A(t.startContainer, n, e) !== null;
|
|
262
|
+
let r = j(e, t);
|
|
263
|
+
return r.length > 0 && r.every((t) => A(t.node, n, e));
|
|
264
|
+
}, de = (e, t, n, r, i) => {
|
|
265
|
+
if (t.collapsed) {
|
|
266
|
+
if (!i) return;
|
|
267
|
+
t.insertNode(document.createTextNode(i));
|
|
268
|
+
}
|
|
269
|
+
let a = ce(j(e, t));
|
|
270
|
+
if (a.length !== 0) {
|
|
271
|
+
for (let t of a) {
|
|
272
|
+
let i = A(t, n, e);
|
|
273
|
+
if (i) {
|
|
274
|
+
r && le(i, n, r, i.textContent ?? "");
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
let a = document.createElement(n.tag);
|
|
278
|
+
r && le(a, n, r, t.data), t.replaceWith(a), a.append(t);
|
|
279
|
+
}
|
|
280
|
+
x(a[0], a[a.length - 1]);
|
|
281
|
+
}
|
|
282
|
+
}, fe = (e, t) => {
|
|
283
|
+
let n = document.createRange();
|
|
284
|
+
n.setStart(e, 0), n.setEndBefore(t);
|
|
285
|
+
let r = document.createRange();
|
|
286
|
+
r.setStartAfter(t), r.setEnd(e, e.childNodes.length);
|
|
287
|
+
for (let [t, i] of [[n, "before"], [r, "after"]]) {
|
|
288
|
+
let n = t.extractContents();
|
|
289
|
+
if (!n.textContent && !n.querySelector("br")) continue;
|
|
290
|
+
let r = e.cloneNode(!1);
|
|
291
|
+
r.append(n), e[i](r);
|
|
292
|
+
}
|
|
293
|
+
O(e);
|
|
294
|
+
}, pe = (e, t, n) => {
|
|
295
|
+
if (t.collapsed) {
|
|
296
|
+
let r = A(t.startContainer, n, e);
|
|
297
|
+
r && se(() => O(r));
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
let r = ce(j(e, t));
|
|
301
|
+
if (r.length !== 0) {
|
|
302
|
+
for (let t of r) for (let r = A(t, n, e); r; r = A(t, n, e)) fe(r, t);
|
|
303
|
+
x(r[0], r[r.length - 1]);
|
|
304
|
+
}
|
|
305
|
+
}, me = (e, t, n) => {
|
|
306
|
+
t.collapsed || (ue(e, t, n) ? pe(e, t, n) : de(e, t, n));
|
|
307
|
+
}, M = (e) => e.nodeType === Node.TEXT_NODE && /^[\t\n\f\r ]*$/.test(e.textContent ?? ""), he = (e) => Array.from(e.childNodes).some((e) => !M(e)), ge = (e, t) => {
|
|
308
|
+
let n = [], r = null;
|
|
309
|
+
for (let i of e.childNodes) v(i, t) ? (n.push({
|
|
310
|
+
nodes: [i],
|
|
311
|
+
block: i
|
|
312
|
+
}), r = null) : (r || n.push(r = {
|
|
313
|
+
nodes: [],
|
|
314
|
+
block: null
|
|
315
|
+
}), r.nodes.push(i));
|
|
316
|
+
return n;
|
|
317
|
+
}, _e = (e, t, n) => {
|
|
318
|
+
for (let r of n.blockStyles.keys()) {
|
|
319
|
+
let n = e.style.getPropertyValue(r);
|
|
320
|
+
n && !t.style.getPropertyValue(r) && t.style.setProperty(r, n);
|
|
321
|
+
}
|
|
322
|
+
}, N = (e) => {
|
|
323
|
+
e.firstChild || e.append(e.ownerDocument.createElement("br"));
|
|
324
|
+
}, P = (e, t) => {
|
|
325
|
+
let n = e.ownerDocument.createElement("p");
|
|
326
|
+
return n.append(...t), N(n), n;
|
|
327
|
+
}, ve = (e) => {
|
|
328
|
+
let t = P(e, Array.from(e.childNodes));
|
|
329
|
+
for (let { name: n, value: r } of e.attributes) t.setAttribute(n, r);
|
|
330
|
+
return t;
|
|
331
|
+
}, ye = (e, t, n, r, i) => {
|
|
332
|
+
let a = t.findIndex(n);
|
|
333
|
+
if (a < 0) return null;
|
|
334
|
+
let o = e.ownerDocument.createDocumentFragment(), s = null, c = null, l = () => {
|
|
335
|
+
s && he(s) && o.append(s), s = null;
|
|
336
|
+
};
|
|
337
|
+
for (let u of t.slice(a)) if (n(u)) {
|
|
338
|
+
l();
|
|
339
|
+
let e = i(u);
|
|
340
|
+
o.append(...e), c = e.at(-1) ?? c;
|
|
341
|
+
} else s ??= e.cloneNode(!1), s.append(...r(u));
|
|
342
|
+
return l(), e.after(o), he(e) || e.remove(), c;
|
|
343
|
+
}, be = (e, t) => {
|
|
344
|
+
let n = t;
|
|
345
|
+
for (; n.parentNode && n.parentNode !== e;) n = n.parentNode;
|
|
346
|
+
return n.parentNode === e ? n : null;
|
|
347
|
+
}, xe = (e, t, n) => {
|
|
348
|
+
let r = ge(e, n);
|
|
349
|
+
if (!r.some((e) => e.block)) {
|
|
350
|
+
let t = ve(e);
|
|
351
|
+
return e.replaceWith(t), t;
|
|
352
|
+
}
|
|
353
|
+
return ye(e, r, (e) => e.nodes.some((e) => t.has(e)), (e) => e.nodes, (t) => {
|
|
354
|
+
let r = t.block ?? P(e, t.nodes);
|
|
355
|
+
return _e(e, r, n), N(r), [r];
|
|
356
|
+
});
|
|
357
|
+
}, Se = (e, t) => {
|
|
358
|
+
let n = ge(e, t);
|
|
359
|
+
if (!n.some((e) => e.block)) return [ve(e)];
|
|
360
|
+
let r = [];
|
|
361
|
+
for (let i of n) {
|
|
362
|
+
if (!i.block && i.nodes.every(M)) continue;
|
|
363
|
+
let n = i.block ?? P(e, i.nodes);
|
|
364
|
+
_e(e, n, t), N(n), r.push(n);
|
|
365
|
+
}
|
|
366
|
+
return r;
|
|
379
367
|
}, Ce = (e, t, n) => {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
368
|
+
let r = e.ownerDocument.createDocumentFragment(), i = null, a = null;
|
|
369
|
+
for (let t of Array.from(e.childNodes)) t instanceof HTMLElement && n.has(t) ? (N(t), r.append(t), i = t, a = null) : i && (a || (a = e.cloneNode(!1), i.append(a)), a.append(t));
|
|
370
|
+
if (!i) return null;
|
|
371
|
+
for (; e.nextSibling;) i.append(e.nextSibling);
|
|
372
|
+
return t.after(r), e.firstChild || e.remove(), i;
|
|
373
|
+
}, we = (e, t, n) => {
|
|
374
|
+
let r = /* @__PURE__ */ new Map(), i = new Set(e), a = null;
|
|
375
|
+
for (let e of i) {
|
|
376
|
+
let n = e.parentElement;
|
|
377
|
+
if (!k(n)) {
|
|
378
|
+
let n = Se(e, t);
|
|
379
|
+
e.replaceWith(...n), a = n[0];
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
let o = n.closest("li");
|
|
383
|
+
for (; o && !i.has(o);) o = o.parentElement?.closest("li") ?? null;
|
|
384
|
+
if (o) continue;
|
|
385
|
+
let s = r.get(n);
|
|
386
|
+
s || r.set(n, s = /* @__PURE__ */ new Set()), s.add(e);
|
|
387
|
+
}
|
|
388
|
+
let o = null;
|
|
389
|
+
for (let [e, i] of r) {
|
|
390
|
+
let r = e.parentElement;
|
|
391
|
+
a = r?.localName === "li" ? Ce(e, r, i) ?? a : ye(e, Array.from(e.children), (e) => i.has(e), (e) => [e], (e) => {
|
|
392
|
+
let r = e.contains(n ?? null), i = Se(e, t);
|
|
393
|
+
return e.remove(), r && (o = i.find((e) => e.contains(n ?? null)) ?? i[0]), i;
|
|
394
|
+
}) ?? a;
|
|
395
|
+
}
|
|
396
|
+
return o ?? a;
|
|
397
|
+
}, Te = (e, t) => {
|
|
398
|
+
let n = e.parentElement;
|
|
399
|
+
if (k(n)) {
|
|
400
|
+
let t = n.cloneNode(!1);
|
|
401
|
+
for (; e.nextSibling;) t.append(e.nextSibling);
|
|
402
|
+
n.after(e), t.firstChild && e.after(t), n.firstChild || n.remove();
|
|
403
|
+
}
|
|
404
|
+
return D(e, t);
|
|
405
|
+
}, Ee = (e, t) => v(e, t) && !k(e), F = (e, t, n) => {
|
|
406
|
+
for (let r = e; r && r !== t; r = r.parentNode) if (Ee(r, n)) return r;
|
|
407
|
+
return null;
|
|
408
|
+
}, De = (e, t) => {
|
|
409
|
+
let n = document.createRange();
|
|
410
|
+
return n.selectNodeContents(t), e.compareBoundaryPoints(Range.START_TO_START, n) > 0 && n.setStart(e.startContainer, e.startOffset), e.compareBoundaryPoints(Range.END_TO_END, n) < 0 && n.setEnd(e.endContainer, e.endOffset), n.toString() !== "";
|
|
411
|
+
}, I = (e, t) => e.childNodes[t] ?? e.lastChild ?? e, L = (e, t, n) => {
|
|
412
|
+
let r = F(I(t.startContainer, t.startOffset), e, n), i = F(I(t.endContainer, t.endOffset), e, n);
|
|
413
|
+
if (!r) return [];
|
|
414
|
+
if (!i || r === i) return [r];
|
|
415
|
+
let a = Array.from(e.querySelectorAll(n.blockSelector)).filter((e) => Ee(e, n) && !e.querySelector(n.blockSelector) && t.intersectsNode(e));
|
|
416
|
+
return a.length > 1 && !De(t, a[a.length - 1]) && a.pop(), a;
|
|
417
|
+
}, R = (e) => {
|
|
418
|
+
if (!y(e)) return null;
|
|
419
|
+
if (e.childNodes.length === 0) {
|
|
420
|
+
let t = document.createElement("p");
|
|
421
|
+
t.append(document.createElement("br")), e.append(t), window.getSelection()?.collapse(t, 0);
|
|
422
|
+
}
|
|
423
|
+
return y(e);
|
|
424
|
+
}, Oe = (e, t, n) => {
|
|
425
|
+
let r = window.getSelection(), i = y(e);
|
|
426
|
+
if (!r || !i) return;
|
|
427
|
+
let a = (n, r, i = r > 0 && r === n.childNodes.length) => {
|
|
428
|
+
let a = n.childNodes[r - Number(i)];
|
|
429
|
+
return () => {
|
|
430
|
+
if (a && e.contains(a)) {
|
|
431
|
+
let e = a.parentNode;
|
|
432
|
+
return e !== n && v(a, t) ? [a, i ? a.childNodes.length : 0] : e !== n && a.nodeName === "BR" && e.childNodes.length === 1 ? [e, 0] : [e, Array.prototype.indexOf.call(e.childNodes, a) + Number(i)];
|
|
433
|
+
}
|
|
434
|
+
if (n === e || !e.contains(n)) return null;
|
|
435
|
+
let o = n.nodeType === Node.TEXT_NODE ? n.length : n.childNodes.length;
|
|
436
|
+
return [n, Math.min(r, o)];
|
|
437
|
+
};
|
|
438
|
+
}, { startContainer: o, startOffset: s, endContainer: c, endOffset: l, collapsed: u } = i, d = !u && r.anchorNode === c && r.anchorOffset === l, f = a(o, s), p = u ? f : a(c, l, !0), m = n();
|
|
439
|
+
if (!m) return;
|
|
440
|
+
let h = d ? p() : f(), g = u ? h : d ? f() : p();
|
|
441
|
+
h && g ? (r.anchorNode !== h[0] || r.anchorOffset !== h[1] || r.focusNode !== g[0] || r.focusOffset !== g[1]) && r.setBaseAndExtent(...h, ...g) : u && s === 0 ? r.collapse(m, 0) : (u || !e.contains(r.anchorNode) || r.anchorNode === e) && C(m);
|
|
442
|
+
}, z = (e, t, n) => {
|
|
443
|
+
let r = (e instanceof Element ? e : e.parentElement)?.closest(n) ?? null;
|
|
444
|
+
return r !== t && t.contains(r) ? r : null;
|
|
445
|
+
}, ke = (e, t, n) => {
|
|
446
|
+
if (!t.collapsed || t.startContainer === e) return null;
|
|
447
|
+
let { startContainer: r, startOffset: i } = t;
|
|
448
|
+
if (i && r.nodeType === Node.TEXT_NODE) return null;
|
|
449
|
+
let a = r.childNodes[i], o = z(r, e, "li, blockquote");
|
|
450
|
+
if (!o || !v(o, n)) return null;
|
|
451
|
+
let s = a ?? r, c = o.localName === "blockquote", l = be(o, s), u = c && l && v(l, n) ? l : o;
|
|
452
|
+
if (!a && i !== 0) {
|
|
453
|
+
let t = F(s, e, n);
|
|
454
|
+
if (i !== 1 || r.firstChild?.nodeName !== "BR" || !t || t.textContent || t.querySelectorAll("br").length !== 1) return null;
|
|
455
|
+
}
|
|
456
|
+
for (let e = s; e !== u; e = e.parentNode) {
|
|
457
|
+
let t = e.previousSibling, r = e.parentNode === o;
|
|
458
|
+
for (; r && t && M(t) && (v(e, n) || c && /[\n\r]/.test(t.textContent ?? ""));) t = t.previousSibling;
|
|
459
|
+
if (t) {
|
|
460
|
+
if (c && r && v(t, n)) break;
|
|
461
|
+
return null;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return c ? () => xe(o, /* @__PURE__ */ new Set([l ?? o]), n) : () => we([o], n, s);
|
|
465
|
+
}, Ae = (e, t, n, r) => {
|
|
466
|
+
let i = /* @__PURE__ */ new Map();
|
|
467
|
+
for (let r of e) {
|
|
468
|
+
let e = z(r, t, "blockquote");
|
|
469
|
+
if (!e) continue;
|
|
470
|
+
let a = i.get(e);
|
|
471
|
+
a || i.set(e, a = /* @__PURE__ */ new Set());
|
|
472
|
+
let o = be(e, r === e && n.collapsed ? I(n.startContainer, n.startOffset) : r);
|
|
473
|
+
o && a.add(o);
|
|
474
|
+
}
|
|
475
|
+
if (!n.collapsed) for (let [e, t] of i) for (let i of e.childNodes) v(i, r) || M(i) || !n.intersectsNode(i) || n.endContainer === i && n.endOffset === 0 || t.add(i);
|
|
476
|
+
let a = null;
|
|
477
|
+
for (let [e, t] of i) a = xe(e, t, r) ?? a;
|
|
478
|
+
return a;
|
|
479
|
+
}, B = (e, t, n) => e.localName === t || t === "blockquote" && z(e, n, t) !== null, je = (e, t, n, r = !1) => {
|
|
480
|
+
let i = t.blocks.get(n);
|
|
481
|
+
if (!i || i.tag !== n || n === "li" || n === "ul" || n === "ol") return;
|
|
482
|
+
let a = R(e);
|
|
483
|
+
if (!a) return;
|
|
484
|
+
let o = L(e, a, t), s = r && o.every((t) => B(t, n, e)), c = s ? "p" : n;
|
|
485
|
+
Oe(e, t, () => {
|
|
486
|
+
if (s && n === "blockquote") return Ae(o, e, a, t);
|
|
487
|
+
let r = null;
|
|
488
|
+
for (let t of o) r = B(t, c, e) ? t : t.localName === "li" ? Te(t, c) : D(t, c);
|
|
489
|
+
return r;
|
|
490
|
+
});
|
|
491
|
+
}, Me = (e, t, n) => {
|
|
492
|
+
let r = y(e);
|
|
493
|
+
if (!r) return !1;
|
|
494
|
+
let i = L(e, r, t);
|
|
495
|
+
return i.length > 0 && i.every((t) => B(t, n, e));
|
|
496
|
+
}, Ne = (e, t, n, r) => {
|
|
497
|
+
if (!t.blockStyles.get(n)?.has(r)) return;
|
|
498
|
+
let i = R(e);
|
|
499
|
+
if (i) for (let a of L(e, i, t)) a.style.setProperty(n, r);
|
|
500
|
+
}, Pe = (e, t, n) => {
|
|
501
|
+
let r = y(e);
|
|
502
|
+
if (!r) return null;
|
|
503
|
+
let [i] = L(e, r, t);
|
|
504
|
+
return i?.style.getPropertyValue(n) || null;
|
|
505
|
+
}, V = (e, t) => e.localName === "li" && e.parentElement?.localName === t, Fe = (e, t, n) => Array.from(new Set(L(e, t, n).map((t) => z(t, e, "li") ?? t))), Ie = (e, t, n) => {
|
|
506
|
+
let r = y(e);
|
|
507
|
+
if (!r) return !1;
|
|
508
|
+
let i = Fe(e, r, t);
|
|
509
|
+
return i.length > 0 && i.every((e) => V(e, n));
|
|
510
|
+
}, Le = (e, t) => {
|
|
511
|
+
let n = document.createElement(t), r = document.createElement("li"), i = e.getAttribute("style");
|
|
512
|
+
return i && r.setAttribute("style", i), r.append(...e.childNodes), n.append(r), e.replaceWith(n), r;
|
|
513
|
+
}, Re = (e, t, n) => {
|
|
514
|
+
if (!t.blocks.has(n)) return;
|
|
515
|
+
let r = R(e);
|
|
516
|
+
if (!r) return;
|
|
517
|
+
let i = Fe(e, r, t), a = i.every((e) => V(e, n));
|
|
518
|
+
Oe(e, t, () => {
|
|
519
|
+
if (a) return we(i, t, r.collapsed ? r.startContainer : void 0);
|
|
520
|
+
let e = null;
|
|
521
|
+
for (let t of i) e = V(t, n) ? t : Le(t.localName === "li" ? Te(t, "p") : t, n);
|
|
522
|
+
return e;
|
|
523
|
+
});
|
|
524
|
+
}, ze = (/* @__PURE__ */ "address.article.aside.blockquote.dd.details.div.dl.dt.fieldset.figcaption.figure.footer.h1.h2.h3.h4.h5.h6.header.hr.li.main.nav.ol.p.pre.section.summary.table.tbody.td.tfoot.th.thead.tr.ul".split(".")).join(","), Be = (e) => {
|
|
525
|
+
let t = document.createRange();
|
|
526
|
+
return t.selectNodeContents(e), Array.from(t.cloneContents().childNodes);
|
|
527
|
+
}, H = (e, t) => {
|
|
528
|
+
let n = [];
|
|
529
|
+
for (let r of (e ?? "").split(";")) {
|
|
530
|
+
let e = r.indexOf(":");
|
|
531
|
+
if (e === -1) continue;
|
|
532
|
+
let i = r.slice(0, e).trim().toLowerCase(), a = r.slice(e + 1).trim().toLowerCase();
|
|
533
|
+
t.blockStyles.get(i)?.has(a) && n.push(`${i}: ${a}`);
|
|
534
|
+
}
|
|
535
|
+
return n.join("; ");
|
|
536
|
+
}, U = null, W = (e, t, n) => {
|
|
537
|
+
for (let r of e) {
|
|
538
|
+
let e = Ve(r, n);
|
|
539
|
+
e && t.appendChild(e);
|
|
540
|
+
}
|
|
541
|
+
}, Ve = (e, t) => {
|
|
542
|
+
let n = U, r = (e) => {
|
|
543
|
+
let r = n.createDocumentFragment();
|
|
544
|
+
return W(e, r, t), r;
|
|
545
|
+
};
|
|
546
|
+
if (e instanceof HTMLFormElement) return r(Be(e));
|
|
547
|
+
if (e.nodeType === Node.TEXT_NODE) return n.createTextNode(e.textContent ?? "");
|
|
548
|
+
if (!(e instanceof Element)) return null;
|
|
549
|
+
let i = e.localName;
|
|
550
|
+
if (u(i)) return null;
|
|
551
|
+
if (i === "br") return n.createElement("br");
|
|
552
|
+
let a = t.marks.get(i);
|
|
553
|
+
if (a) {
|
|
554
|
+
let r = n.createElement(a.tag);
|
|
555
|
+
for (let [t, n] of h(e, a)) r.setAttribute(t, n);
|
|
556
|
+
return W(e.childNodes, r, t), r;
|
|
557
|
+
}
|
|
558
|
+
let o = e.matches(ze), s = e.querySelector(ze) !== null, c = t.blocks.get(i);
|
|
559
|
+
if ((c?.tag === "p" || !c && o) && s) return r(e.childNodes);
|
|
560
|
+
if (c || o) {
|
|
561
|
+
let r = n.createElement(c?.tag ?? "p"), i = H(e.getAttribute("style"), t);
|
|
562
|
+
return i && r.setAttribute("style", i), W(e.childNodes, r, t), c || r.childNodes.length > 0 ? r : null;
|
|
563
|
+
}
|
|
564
|
+
return r(e.childNodes);
|
|
565
|
+
}, G = (e, t) => {
|
|
566
|
+
U ??= document.implementation.createHTMLDocument("");
|
|
567
|
+
let n = U.createElement("div");
|
|
568
|
+
return W(e, n, t), n.innerHTML;
|
|
569
|
+
}, K = (e, t) => e ? G(new DOMParser().parseFromString(e, "text/html").body.childNodes, t) : "", He = (e, t) => {
|
|
570
|
+
let n = Array.from(e.childNodes), r = n.some((e) => v(e, t)), i = [], a = [], o = () => {
|
|
571
|
+
if (a.length !== 0) {
|
|
572
|
+
if (a.some((e) => e.nodeType === Node.ELEMENT_NODE || e.textContent?.trim()) || !r) {
|
|
573
|
+
let t = (e.ownerDocument ?? document).createElement("p");
|
|
574
|
+
e.insertBefore(t, a[0]), t.append(...a), i.push(t);
|
|
575
|
+
} else a.forEach((t) => e.removeChild(t));
|
|
576
|
+
a = [];
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
for (let r of n) v(r, t) ? o() : r.nodeType === Node.ELEMENT_NODE || r.nodeType === Node.TEXT_NODE ? a.push(r) : e.removeChild(r);
|
|
580
|
+
return o(), i;
|
|
581
|
+
}, Ue = (e) => {
|
|
582
|
+
let t = e.nextSibling;
|
|
583
|
+
for (; t instanceof Element && t.localName === e.localName;) e.append(...t.childNodes), t.remove(), t = e.nextSibling;
|
|
584
|
+
}, We = (e) => {
|
|
585
|
+
for (let t of Array.from(e.childNodes)) {
|
|
586
|
+
if (t instanceof Element && t.localName === "li") continue;
|
|
587
|
+
if (t.nodeType === Node.TEXT_NODE && !t.textContent?.trim()) {
|
|
588
|
+
t.remove();
|
|
589
|
+
continue;
|
|
590
|
+
}
|
|
591
|
+
let n = e.ownerDocument.createElement("li");
|
|
592
|
+
t.replaceWith(n), n.append(t);
|
|
593
|
+
}
|
|
594
|
+
e.children.length === 0 ? e.remove() : Ue(e);
|
|
595
|
+
}, Ge = (e, t, n) => {
|
|
596
|
+
let r = t;
|
|
597
|
+
for (let i of [t, ...t.querySelectorAll("*")]) {
|
|
598
|
+
if (!e.contains(i)) continue;
|
|
599
|
+
let t = i.localName;
|
|
600
|
+
if (t === "br") continue;
|
|
601
|
+
let a = n.marks.get(t), o = a ?? n.blocks.get(t);
|
|
602
|
+
if (!o) {
|
|
603
|
+
O(i);
|
|
604
|
+
continue;
|
|
605
|
+
}
|
|
606
|
+
let s = i;
|
|
607
|
+
if (o.tag !== t) {
|
|
608
|
+
let e = !a && H(i.getAttribute("style"), n), t = a ? h(i, a) : [];
|
|
609
|
+
e && t.push(["style", e]), s = D(i, o.tag, t);
|
|
610
|
+
}
|
|
611
|
+
if (i === r && (r = s), a) {
|
|
612
|
+
let t = s.parentElement?.closest(o.tag);
|
|
613
|
+
s.childNodes.length === 0 ? s.remove() : t && t !== e && e.contains(t) && O(s);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
r.normalize();
|
|
617
|
+
for (let t of Array.from(r.querySelectorAll("*"))) {
|
|
618
|
+
if (!n.marks.has(t.localName) || !e.contains(t)) continue;
|
|
619
|
+
let r = t.nextSibling;
|
|
620
|
+
for (; r instanceof Element && r.localName === t.localName && oe(t, r);) t.append(...r.childNodes), r.remove(), r = t.nextSibling;
|
|
621
|
+
}
|
|
622
|
+
r.normalize();
|
|
623
|
+
for (let t of [r, ...r.querySelectorAll("ul, ol")]) k(t) && e.contains(t) && We(t);
|
|
624
|
+
}, Ke = (e, t, n) => {
|
|
625
|
+
se(() => {
|
|
626
|
+
let r = new Set(He(e, t));
|
|
627
|
+
for (let t of n) t instanceof Element && t.parentNode === e && r.add(t);
|
|
628
|
+
for (let n of r) n.parentNode === e && Ge(e, n, t);
|
|
629
|
+
for (let t of Array.from(e.children)) k(t) && t.parentNode === e && Ue(t);
|
|
630
|
+
});
|
|
631
|
+
}, qe = (e) => e.replace(/-([a-z])/g, (e, t) => t.toUpperCase()), Je = (e, t, n, r = !1) => {
|
|
632
|
+
let i = (e) => {
|
|
633
|
+
let n = {
|
|
634
|
+
type: "text",
|
|
635
|
+
text: e
|
|
636
|
+
};
|
|
637
|
+
return t.length > 0 && (n.marks = [...t]), [n];
|
|
638
|
+
}, a = (e, t) => Array.from(e).flatMap((e) => Je(e, t, n));
|
|
639
|
+
if (e instanceof HTMLFormElement) return a(Be(e), t);
|
|
640
|
+
if (e.nodeType === Node.TEXT_NODE) {
|
|
641
|
+
let t = e.textContent ?? "";
|
|
642
|
+
return (r ? t.trim() : t) ? i(t) : [];
|
|
643
|
+
}
|
|
644
|
+
if (!(e instanceof Element)) return [];
|
|
645
|
+
let o = e.localName;
|
|
646
|
+
if (u(o)) return [];
|
|
647
|
+
if (o === "br") return r ? [] : i("\n");
|
|
648
|
+
let s = n.marks.get(o);
|
|
649
|
+
if (s) {
|
|
650
|
+
let n = { type: s.type }, r = Object.fromEntries(h(e, s));
|
|
651
|
+
return Object.keys(r).length > 0 && (n.attrs = r), a(e.childNodes, [...t, n]);
|
|
652
|
+
}
|
|
653
|
+
let c = n.blocks.get(o);
|
|
654
|
+
if (!c) return a(e.childNodes, t);
|
|
655
|
+
let l = { type: c.type }, d = { ...c.attrs };
|
|
656
|
+
for (let t of H(e.getAttribute("style"), n).split("; ")) {
|
|
657
|
+
let [e, n] = t.split(": ");
|
|
658
|
+
n && (d[qe(e)] = n);
|
|
659
|
+
}
|
|
660
|
+
Object.keys(d).length > 0 && (l.attrs = d);
|
|
661
|
+
let f = a(e.childNodes, t);
|
|
662
|
+
return f.length > 0 && (l.content = f), [l];
|
|
663
|
+
}, Ye = (e, t) => Je(e, [], t, !0), Xe = (e, t) => G(e.childNodes, _(t)), Ze = (e, t) => {
|
|
664
|
+
let n = _(t);
|
|
665
|
+
return {
|
|
666
|
+
type: "doc",
|
|
667
|
+
content: Array.from(e.childNodes).flatMap((e) => Ye(e, n))
|
|
668
|
+
};
|
|
669
|
+
}, Qe = (e, t) => {
|
|
670
|
+
let n = /* @__PURE__ */ new WeakMap(), r = /* @__PURE__ */ new Set(), i = !1, a = (e) => {
|
|
671
|
+
let t = n.get(e);
|
|
672
|
+
return t || (t = {}, n.set(e, t)), t;
|
|
673
|
+
}, o = (t) => {
|
|
674
|
+
for (let a of t) {
|
|
675
|
+
if (i = !0, a.target === e) {
|
|
676
|
+
a.addedNodes.forEach((e) => r.add(e));
|
|
677
|
+
continue;
|
|
678
|
+
}
|
|
679
|
+
let t = ae(e, a.target);
|
|
680
|
+
t && (r.add(t), n.delete(t));
|
|
681
|
+
}
|
|
682
|
+
}, s = new MutationObserver((e) => {
|
|
683
|
+
o(e), t();
|
|
684
|
+
}), c = () => {
|
|
685
|
+
r.clear(), i = !1;
|
|
686
|
+
}, l = (t, n) => {
|
|
687
|
+
e.innerHTML = K(t, n);
|
|
688
|
+
};
|
|
689
|
+
return {
|
|
690
|
+
root: e,
|
|
691
|
+
observe() {
|
|
692
|
+
s.observe(e, {
|
|
693
|
+
childList: !0,
|
|
694
|
+
subtree: !0,
|
|
695
|
+
characterData: !0,
|
|
696
|
+
attributes: !0
|
|
697
|
+
});
|
|
698
|
+
},
|
|
699
|
+
normalizeChanges(t, n) {
|
|
700
|
+
return o(s.takeRecords()), !i || n ? !1 : (Ke(e, t, r), o(s.takeRecords()), c(), !0);
|
|
701
|
+
},
|
|
702
|
+
discardChanges() {
|
|
703
|
+
s.takeRecords(), c();
|
|
704
|
+
},
|
|
705
|
+
invalidateCache() {
|
|
706
|
+
n = /* @__PURE__ */ new WeakMap();
|
|
707
|
+
},
|
|
708
|
+
rawBlocks() {
|
|
709
|
+
return Array.from(e.children, (e) => a(e).raw ??= e.outerHTML);
|
|
710
|
+
},
|
|
711
|
+
getHTML(t, n) {
|
|
712
|
+
return n ? Array.from(e.children, (e) => a(e).html ??= G([e], t)).join("") : e.innerHTML;
|
|
713
|
+
},
|
|
714
|
+
getJSON(t) {
|
|
715
|
+
return {
|
|
716
|
+
type: "doc",
|
|
717
|
+
content: Array.from(e.children).flatMap((e) => a(e).json ??= Ye(e, t))
|
|
718
|
+
};
|
|
719
|
+
},
|
|
720
|
+
replaceHTML: l,
|
|
721
|
+
loadHTML(t, n) {
|
|
722
|
+
l(t, n), Ke(e, n, Array.from(e.childNodes));
|
|
723
|
+
},
|
|
724
|
+
replaceBlocks(t, n, r) {
|
|
725
|
+
let i = 0;
|
|
726
|
+
for (; i < t.length && i < n.length && t[i] === n[i];) i++;
|
|
727
|
+
let a = t.length, l = n.length;
|
|
728
|
+
for (; a > i && l > i && t[a - 1] === n[l - 1];) a--, l--;
|
|
729
|
+
let u = Array.from(e.children), d = e.ownerDocument.createElement("template");
|
|
730
|
+
d.innerHTML = K(n.slice(i, l).join(""), r), u.slice(i, a).forEach((e) => e.remove()), e.insertBefore(d.content, u[a] ?? null), o(s.takeRecords()), c();
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
}, q = (e, t) => {
|
|
734
|
+
e.deleteContents();
|
|
735
|
+
let n = t.lastChild;
|
|
736
|
+
if (e.insertNode(t), !n) return;
|
|
737
|
+
let r = n.nextSibling;
|
|
738
|
+
r?.nodeName === "BR" && !r.nextSibling && r.remove(), S(n);
|
|
739
|
+
}, $e = (e, t, n, r) => {
|
|
740
|
+
t.deleteContents();
|
|
741
|
+
let i = ae(e, t.startContainer);
|
|
742
|
+
if (!i || !v(i, r)) {
|
|
743
|
+
q(t, n);
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
He(n, r);
|
|
747
|
+
let a = n.lastChild;
|
|
748
|
+
if (!a) return;
|
|
749
|
+
let o = document.createRange();
|
|
750
|
+
o.selectNodeContents(i), o.setStart(t.startContainer, t.startOffset);
|
|
751
|
+
let s = i.cloneNode(!1);
|
|
752
|
+
s.append(o.extractContents()), i.after(n, s);
|
|
753
|
+
for (let e of [i, s]) e.textContent?.trim() || e.remove();
|
|
754
|
+
S(a);
|
|
755
|
+
}, et = (e, t, n, r) => {
|
|
756
|
+
let i = document.createElement("template");
|
|
757
|
+
i.innerHTML = n;
|
|
758
|
+
let a = i.content, o = a.childNodes.length === 1 ? a.firstChild : null;
|
|
759
|
+
o instanceof HTMLElement && o.localName === "p" && !o.querySelector(r.blockSelector) && O(o), a.querySelector(r.blockSelector) ? $e(e, t, a, r) : q(t, a);
|
|
392
760
|
}, tt = (e, t, n) => {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
t.append(document.createElement("br")), e.append(t), window.getSelection()?.collapse(t, 0);
|
|
412
|
-
}
|
|
413
|
-
return k(e);
|
|
414
|
-
}, Me = (e, t) => {
|
|
415
|
-
let n = null;
|
|
416
|
-
G(() => {
|
|
417
|
-
n = t();
|
|
418
|
-
});
|
|
419
|
-
const s = k(e);
|
|
420
|
-
n && (!s || s.startContainer === e) && Qe(n);
|
|
421
|
-
}, J = (e, t) => {
|
|
422
|
-
const n = e.parentElement;
|
|
423
|
-
if (!w(n)) return I(e, t);
|
|
424
|
-
const s = n.cloneNode(!1);
|
|
425
|
-
for (; e.nextSibling; ) s.append(e.nextSibling);
|
|
426
|
-
return n.after(e), s.childNodes.length > 0 && e.after(s), n.childNodes.length === 0 && n.remove(), I(e, t);
|
|
761
|
+
let r = document.createDocumentFragment(), i = t.startContainer, a = (i instanceof Element ? i : i.parentElement)?.closest("pre");
|
|
762
|
+
a && e.contains(a) ? r.append(n) : n.split(/\r\n?|\n/).forEach((e, t) => {
|
|
763
|
+
t > 0 && r.append(document.createElement("br")), e && r.append(e);
|
|
764
|
+
}), q(t, r);
|
|
765
|
+
}, nt = typeof navigator < "u" && /Mac|iPhone|iPad|iPod/.test(navigator.userAgent), rt = /* @__PURE__ */ new Set([
|
|
766
|
+
"Control",
|
|
767
|
+
"Shift",
|
|
768
|
+
"Alt",
|
|
769
|
+
"Meta"
|
|
770
|
+
]), it = (e) => {
|
|
771
|
+
let t = [];
|
|
772
|
+
return (nt ? e.metaKey : e.ctrlKey) && t.push("Mod"), e.shiftKey && t.push("Shift"), e.altKey && t.push("Alt"), rt.has(e.key) || t.push(e.key.length === 1 ? e.key.toUpperCase() : e.key), t.join("+");
|
|
773
|
+
}, at = (e, t) => {
|
|
774
|
+
for (let n of e) {
|
|
775
|
+
let e = n.keyboardShortcuts?.[t];
|
|
776
|
+
if (e) return e;
|
|
777
|
+
}
|
|
778
|
+
return null;
|
|
427
779
|
}, ot = (e, t, n) => {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
},
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
c();
|
|
679
|
-
return;
|
|
680
|
-
}
|
|
681
|
-
b(), i++;
|
|
682
|
-
try {
|
|
683
|
-
c();
|
|
684
|
-
} finally {
|
|
685
|
-
i--;
|
|
686
|
-
}
|
|
687
|
-
b();
|
|
688
|
-
}
|
|
689
|
-
},
|
|
690
|
-
toggleMark(c) {
|
|
691
|
-
const a = O(c);
|
|
692
|
-
a && z((d, f) => tt(d, f, a));
|
|
693
|
-
},
|
|
694
|
-
setMark(c, a, d) {
|
|
695
|
-
const f = O(c);
|
|
696
|
-
f && z((A, B) => xe(A, B, f, a, d));
|
|
697
|
-
},
|
|
698
|
-
removeMark(c) {
|
|
699
|
-
const a = O(c);
|
|
700
|
-
a && z((d, f) => Ce(d, f, a));
|
|
701
|
-
},
|
|
702
|
-
isMarkActive(c) {
|
|
703
|
-
const a = O(c);
|
|
704
|
-
return a ? Pe(!1, (d, f) => Te(d, f, a)) : !1;
|
|
705
|
-
},
|
|
706
|
-
setBlock(c) {
|
|
707
|
-
N.change(() => o && ot(o, n, c));
|
|
708
|
-
},
|
|
709
|
-
toggleBlock(c) {
|
|
710
|
-
N.setBlock(N.isBlockActive(c) ? "p" : c);
|
|
711
|
-
},
|
|
712
|
-
isBlockActive(c) {
|
|
713
|
-
return o ? st(o, n, c) : !1;
|
|
714
|
-
},
|
|
715
|
-
toggleList(c) {
|
|
716
|
-
N.change(() => o && at(o, n, c));
|
|
717
|
-
},
|
|
718
|
-
isListActive(c) {
|
|
719
|
-
return o ? lt(o, n, c) : !1;
|
|
720
|
-
},
|
|
721
|
-
setBlockStyle(c, a) {
|
|
722
|
-
N.change(() => o && rt(o, n, c, a));
|
|
723
|
-
},
|
|
724
|
-
getBlockStyle(c) {
|
|
725
|
-
return o ? ct(o, n, c) : null;
|
|
726
|
-
}
|
|
727
|
-
};
|
|
728
|
-
return N;
|
|
729
|
-
}, Tt = (e) => {
|
|
730
|
-
const [t] = Ie(() => Nt(e)), { extensions: n, onChange: s, onChangeJSON: o } = e;
|
|
731
|
-
return _(() => {
|
|
732
|
-
t.setOptions({ extensions: n, onChange: s, onChangeJSON: o });
|
|
733
|
-
}), _(() => () => t.destroy(), [t]), t;
|
|
734
|
-
}, Le = Fe(null), kt = () => {
|
|
735
|
-
const e = qe(Le);
|
|
736
|
-
if (!e)
|
|
737
|
-
throw new Error(
|
|
738
|
-
"useEditorContext must be used within an EditorProvider"
|
|
739
|
-
);
|
|
740
|
-
return e;
|
|
741
|
-
}, xt = ({ editor: e, children: t }) => /* @__PURE__ */ pe(Le.Provider, { value: e, children: t }), W = (e, t, n) => {
|
|
742
|
-
n === void 0 ? e.removeAttribute(t) : e.setAttribute(t, n);
|
|
743
|
-
}, bt = ({ className: e, ariaLabel: t, ariaDescribedBy: n }) => {
|
|
744
|
-
const s = kt(), o = he(null);
|
|
745
|
-
return _(() => {
|
|
746
|
-
if (o.current)
|
|
747
|
-
return s.mount(o.current), () => s.unmount();
|
|
748
|
-
}, [s]), _(() => {
|
|
749
|
-
const r = s.el;
|
|
750
|
-
r && (W(r, "class", e), W(r, "aria-label", t), W(r, "aria-describedby", n));
|
|
751
|
-
}, [s, e, t, n]), /* @__PURE__ */ pe("div", { ref: o, style: { display: "contents" } });
|
|
752
|
-
};
|
|
753
|
-
bt.displayName = "EditorContent";
|
|
754
|
-
const ne = (e, t) => {
|
|
755
|
-
const n = he(null), s = () => {
|
|
756
|
-
const o = n.current;
|
|
757
|
-
if (o && o.revision === e.revision && o.selector === t)
|
|
758
|
-
return o.value;
|
|
759
|
-
const r = t(e);
|
|
760
|
-
return n.current = { revision: e.revision, selector: t, value: r }, r;
|
|
761
|
-
};
|
|
762
|
-
return Ue(e.subscribe, s, s);
|
|
763
|
-
}, Ct = (e, t, n) => ne(e, (s) => s.isActive(t, n)), wt = (e) => ne(e, (t) => t.history.canUndo()), Mt = (e) => ne(e, (t) => t.history.canRedo()), Oe = (e) => `toggle${e[0].toUpperCase()}${e.slice(1)}`, M = (e) => {
|
|
764
|
-
const { name: t, tag: n, aliases: s, shortcut: o } = e, r = Oe(t);
|
|
765
|
-
return {
|
|
766
|
-
name: t,
|
|
767
|
-
marks: [{ tag: n, type: t, aliases: s }],
|
|
768
|
-
commands: { [r]: (l) => l.toggleMark(n) },
|
|
769
|
-
keyboardShortcuts: o ? { [o]: r } : void 0,
|
|
770
|
-
isActive: (l) => l.isMarkActive(n)
|
|
771
|
-
};
|
|
772
|
-
}, Be = (e) => {
|
|
773
|
-
const { name: t, tag: n, shortcut: s } = e, o = Oe(t);
|
|
774
|
-
return {
|
|
775
|
-
name: t,
|
|
776
|
-
blocks: [{ tag: n, type: t }],
|
|
777
|
-
commands: { [o]: (r) => r.toggleBlock(n) },
|
|
778
|
-
keyboardShortcuts: s ? { [s]: o } : void 0,
|
|
779
|
-
isActive: (r) => r.isBlockActive(n)
|
|
780
|
-
};
|
|
781
|
-
}, Lt = M({ name: "bold", tag: "strong", aliases: ["b"], shortcut: "Mod+B" }), Ot = M({ name: "italic", tag: "em", aliases: ["i"], shortcut: "Mod+I" }), Bt = M({ name: "underline", tag: "u", shortcut: "Mod+U" }), Rt = M({ name: "strikethrough", tag: "s", aliases: ["del"], shortcut: "Mod+Shift+S" }), Dt = M({ name: "code", tag: "code" }), Ht = Be({ name: "blockquote", tag: "blockquote" }), _t = Be({ name: "codeBlock", tag: "pre" }), D = [1, 2, 3, 4, 5, 6], Pt = {
|
|
782
|
-
name: "heading",
|
|
783
|
-
blocks: D.map((e) => ({ tag: `h${e}`, type: "heading", attrs: { level: e } })),
|
|
784
|
-
commands: {
|
|
785
|
-
setHeading: (e, t) => {
|
|
786
|
-
D.includes(t) && e.setBlock(`h${t}`);
|
|
787
|
-
},
|
|
788
|
-
removeHeading: (e) => e.setBlock("p")
|
|
789
|
-
},
|
|
790
|
-
isActive: (e, t, n) => {
|
|
791
|
-
if (t === "setHeading") return D.includes(n) && e.isBlockActive(`h${n}`);
|
|
792
|
-
const s = D.some((o) => e.isBlockActive(`h${o}`));
|
|
793
|
-
return t === "removeHeading" ? !s : s;
|
|
794
|
-
}
|
|
795
|
-
}, Re = (e, t) => {
|
|
796
|
-
const n = `toggle${e[0].toUpperCase()}${e.slice(1)}`;
|
|
797
|
-
return {
|
|
798
|
-
name: e,
|
|
799
|
-
blocks: [{ tag: t, type: e }, { tag: "li", type: "listItem" }],
|
|
800
|
-
commands: { [n]: (s) => s.toggleList(t) },
|
|
801
|
-
isActive: (s) => s.isListActive(t)
|
|
802
|
-
};
|
|
803
|
-
}, jt = Re("orderedList", "ol"), It = Re("unorderedList", "ul"), X = {
|
|
804
|
-
alignLeft: "left",
|
|
805
|
-
alignCenter: "center",
|
|
806
|
-
alignRight: "right",
|
|
807
|
-
alignJustify: "justify"
|
|
808
|
-
}, qt = {
|
|
809
|
-
name: "textAlign",
|
|
810
|
-
blockStyles: { "text-align": Object.values(X) },
|
|
811
|
-
commands: Object.fromEntries(
|
|
812
|
-
Object.entries(X).map(([e, t]) => [
|
|
813
|
-
e,
|
|
814
|
-
(n) => n.setBlockStyle("text-align", t)
|
|
815
|
-
])
|
|
816
|
-
),
|
|
817
|
-
isActive: (e, t) => t !== void 0 && (e.getBlockStyle("text-align") ?? "left") === X[t]
|
|
818
|
-
}, me = (e) => /^(https?:\/\/|mailto:)/i.test(e), Ft = {
|
|
819
|
-
name: "link",
|
|
820
|
-
marks: [{
|
|
821
|
-
tag: "a",
|
|
822
|
-
type: "link",
|
|
823
|
-
attrs: {
|
|
824
|
-
href: (e) => e && me(e) ? e : null,
|
|
825
|
-
target: (e) => e === "_blank" ? e : null,
|
|
826
|
-
rel: (e, t) => t.getAttribute("target") === "_blank" ? "noopener noreferrer" : null
|
|
827
|
-
}
|
|
828
|
-
}],
|
|
829
|
-
commands: {
|
|
830
|
-
setLink: (e, t) => {
|
|
831
|
-
const n = t?.href;
|
|
832
|
-
n && me(n) && e.setMark("a", { href: n }, n);
|
|
833
|
-
},
|
|
834
|
-
removeLink: (e) => e.removeMark("a")
|
|
835
|
-
},
|
|
836
|
-
isActive: (e) => e.isMarkActive("a")
|
|
780
|
+
e.addEventListener("keydown", (e) => {
|
|
781
|
+
if (e.isComposing) return;
|
|
782
|
+
let n = e.metaKey || e.ctrlKey, r = e.key.toLowerCase();
|
|
783
|
+
if (n && (r === "z" || r === "y")) {
|
|
784
|
+
e.preventDefault(), r === "z" && !e.shiftKey ? t.history.undo() : t.history.redo();
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
let i = at(t.extensions, it(e));
|
|
788
|
+
i && (e.preventDefault(), t.execute(i));
|
|
789
|
+
}), e.addEventListener("beforeinput", (r) => {
|
|
790
|
+
if (r.inputType !== "deleteContentBackward" || !r.cancelable || r.defaultPrevented || n.composing || r.isComposing) return;
|
|
791
|
+
n.flushTyping();
|
|
792
|
+
let i = y(e);
|
|
793
|
+
if (!i) return;
|
|
794
|
+
let a = ke(e, i, n.schema);
|
|
795
|
+
if (!a) return;
|
|
796
|
+
let o = i.startContainer;
|
|
797
|
+
r.preventDefault(), t.change(() => {
|
|
798
|
+
let e = a();
|
|
799
|
+
e && window.getSelection()?.collapse(e.contains(o) ? o : e, 0);
|
|
800
|
+
});
|
|
801
|
+
}), e.addEventListener("paste", (r) => {
|
|
802
|
+
r.preventDefault();
|
|
803
|
+
let i = r.clipboardData?.getData("text/html"), a = r.clipboardData?.getData("text/plain");
|
|
804
|
+
t.change(() => {
|
|
805
|
+
let t = y(e);
|
|
806
|
+
if (t) {
|
|
807
|
+
if (i) {
|
|
808
|
+
let r = n.schema;
|
|
809
|
+
et(e, t, K(i, r), r);
|
|
810
|
+
} else a && tt(e, t, a);
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
}), e.addEventListener("drop", (e) => e.preventDefault()), e.addEventListener("compositionstart", () => n.setComposing(!0)), e.addEventListener("compositionend", () => {
|
|
814
|
+
n.setComposing(!1), n.flushTyping();
|
|
815
|
+
});
|
|
816
|
+
}, st = (e, t) => e.length === t.length && e.every((e, n) => e === t[n]), ct = (e) => {
|
|
817
|
+
let t = e, n = _(t.extensions), r = te(t.historyLimit ?? 100), i = null, a = !1, o = 0, s = 0, c = null, l = /* @__PURE__ */ new Set(), u = [], d = null, f = () => {
|
|
818
|
+
s++, l.forEach((e) => e());
|
|
819
|
+
}, p = () => {
|
|
820
|
+
c === null && (c = requestAnimationFrame(() => {
|
|
821
|
+
c = null, t.onChange?.(w.getHTML()), t.onChangeJSON?.(w.getJSON());
|
|
822
|
+
}));
|
|
823
|
+
}, m = (e = !1) => {
|
|
824
|
+
if (!i?.normalizeChanges(n, a)) return;
|
|
825
|
+
let { root: t } = i, o = i.rawBlocks(), s = E(t);
|
|
826
|
+
st(o, u) || (r.record({
|
|
827
|
+
blocks: o,
|
|
828
|
+
before: d,
|
|
829
|
+
after: s
|
|
830
|
+
}, e), u = o, p()), d = s ?? d, f();
|
|
831
|
+
}, h = (e) => {
|
|
832
|
+
if (!e || !i) return;
|
|
833
|
+
let { root: t } = i, { blocks: r } = e;
|
|
834
|
+
i.replaceBlocks(u, r, n), u = i.rawBlocks(), ie(t, e.selection, st(u, r) ? void 0 : r.join("")), d = E(t), f(), p();
|
|
835
|
+
}, g = (() => {
|
|
836
|
+
let e = !1;
|
|
837
|
+
return () => {
|
|
838
|
+
let t = i?.root, n = !!t && y(t) !== null;
|
|
839
|
+
t && n && (d = E(t)), (n || e) && f(), e = n;
|
|
840
|
+
};
|
|
841
|
+
})(), v = (e, t) => {
|
|
842
|
+
e.loadHTML(t, n), u = e.rawBlocks(), r.reset(u), d = null;
|
|
843
|
+
}, ee = () => {
|
|
844
|
+
let e = document.createElement("div");
|
|
845
|
+
e.contentEditable = "true", e.setAttribute("role", "textbox"), e.setAttribute("aria-multiline", "true"), e.tabIndex = 0;
|
|
846
|
+
let r = Qe(e, () => m(!0));
|
|
847
|
+
return v(r, t.initialValue ?? ""), ot(e, w, {
|
|
848
|
+
get schema() {
|
|
849
|
+
return n;
|
|
850
|
+
},
|
|
851
|
+
get composing() {
|
|
852
|
+
return a;
|
|
853
|
+
},
|
|
854
|
+
setComposing(e) {
|
|
855
|
+
a = e;
|
|
856
|
+
},
|
|
857
|
+
flushTyping: () => m(!0)
|
|
858
|
+
}), r.observe(), r;
|
|
859
|
+
}, b = (e) => {
|
|
860
|
+
let t = n.marks.get(e);
|
|
861
|
+
return t && t.tag === e ? t : null;
|
|
862
|
+
}, x = (e) => {
|
|
863
|
+
w.change(() => {
|
|
864
|
+
let t = i?.root, n = t && y(t);
|
|
865
|
+
t && n && e(t, n);
|
|
866
|
+
});
|
|
867
|
+
}, S = (e, t) => {
|
|
868
|
+
let n = i?.root, r = n && y(n);
|
|
869
|
+
return n && r ? t(n, r) : e;
|
|
870
|
+
}, C = (e) => {
|
|
871
|
+
w.change(() => {
|
|
872
|
+
i && e(i.root);
|
|
873
|
+
});
|
|
874
|
+
}, w = {
|
|
875
|
+
get el() {
|
|
876
|
+
return i?.root ?? null;
|
|
877
|
+
},
|
|
878
|
+
get extensions() {
|
|
879
|
+
return t.extensions;
|
|
880
|
+
},
|
|
881
|
+
get revision() {
|
|
882
|
+
return s;
|
|
883
|
+
},
|
|
884
|
+
history: {
|
|
885
|
+
undo: () => {
|
|
886
|
+
m(), h(r.undo());
|
|
887
|
+
},
|
|
888
|
+
redo: () => {
|
|
889
|
+
m(), h(r.redo());
|
|
890
|
+
},
|
|
891
|
+
canUndo: () => r.canUndo(),
|
|
892
|
+
canRedo: () => r.canRedo()
|
|
893
|
+
},
|
|
894
|
+
mount(e) {
|
|
895
|
+
i ??= ee(), e.append(i.root), document.addEventListener("selectionchange", g);
|
|
896
|
+
},
|
|
897
|
+
unmount() {
|
|
898
|
+
i?.root.remove(), document.removeEventListener("selectionchange", g);
|
|
899
|
+
},
|
|
900
|
+
destroy() {
|
|
901
|
+
r.cancelTimer(), c !== null && (cancelAnimationFrame(c), c = null);
|
|
902
|
+
},
|
|
903
|
+
setOptions(e) {
|
|
904
|
+
let r = e.extensions !== void 0 && (e.extensions.length !== t.extensions.length || e.extensions.some((e, n) => e !== t.extensions[n]));
|
|
905
|
+
t = {
|
|
906
|
+
...t,
|
|
907
|
+
...e
|
|
908
|
+
}, r && (n = _(t.extensions), i?.invalidateCache());
|
|
909
|
+
},
|
|
910
|
+
subscribe(e) {
|
|
911
|
+
return l.add(e), () => {
|
|
912
|
+
l.delete(e);
|
|
913
|
+
};
|
|
914
|
+
},
|
|
915
|
+
execute(e, n) {
|
|
916
|
+
for (let r of t.extensions) {
|
|
917
|
+
let t = r.commands?.[e];
|
|
918
|
+
if (t) {
|
|
919
|
+
w.change(() => t(w, n));
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
throw Error(`Command not found: ${e}`);
|
|
924
|
+
},
|
|
925
|
+
isActive(e, n) {
|
|
926
|
+
return !i || !y(i.root) ? !1 : (t.extensions.find((t) => t.commands?.[e] && t.isActive) ?? t.extensions.find((t) => t.name === e && t.isActive))?.isActive?.(w, e, n) ?? !1;
|
|
927
|
+
},
|
|
928
|
+
getHTML() {
|
|
929
|
+
return i ? (m(), i.getHTML(n, t.sanitize !== !1)) : "";
|
|
930
|
+
},
|
|
931
|
+
getJSON() {
|
|
932
|
+
return i ? (m(), i.getJSON(n)) : {
|
|
933
|
+
type: "doc",
|
|
934
|
+
content: []
|
|
935
|
+
};
|
|
936
|
+
},
|
|
937
|
+
setHTML(e, { history: r = !0 } = {}) {
|
|
938
|
+
i ? (m(), r ? (i.replaceHTML(e, n), m()) : (v(i, e), i.discardChanges(), f(), p())) : t = {
|
|
939
|
+
...t,
|
|
940
|
+
initialValue: e
|
|
941
|
+
};
|
|
942
|
+
},
|
|
943
|
+
change(e) {
|
|
944
|
+
if (i && !a) {
|
|
945
|
+
if (o > 0) e();
|
|
946
|
+
else {
|
|
947
|
+
m(), d = E(i.root) ?? d, o++;
|
|
948
|
+
try {
|
|
949
|
+
e();
|
|
950
|
+
} finally {
|
|
951
|
+
o--;
|
|
952
|
+
}
|
|
953
|
+
m();
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
},
|
|
957
|
+
toggleMark(e) {
|
|
958
|
+
let t = b(e);
|
|
959
|
+
t && x((e, n) => me(e, n, t));
|
|
960
|
+
},
|
|
961
|
+
setMark(e, t, n) {
|
|
962
|
+
let r = b(e);
|
|
963
|
+
r && x((e, i) => de(e, i, r, t, n));
|
|
964
|
+
},
|
|
965
|
+
removeMark(e) {
|
|
966
|
+
let t = b(e);
|
|
967
|
+
t && x((e, n) => pe(e, n, t));
|
|
968
|
+
},
|
|
969
|
+
isMarkActive(e) {
|
|
970
|
+
let t = b(e);
|
|
971
|
+
return t ? S(!1, (e, n) => ue(e, n, t)) : !1;
|
|
972
|
+
},
|
|
973
|
+
setBlock(e) {
|
|
974
|
+
C((t) => je(t, n, e));
|
|
975
|
+
},
|
|
976
|
+
toggleBlock(e) {
|
|
977
|
+
C((t) => je(t, n, e, !0));
|
|
978
|
+
},
|
|
979
|
+
isBlockActive(e) {
|
|
980
|
+
return i ? Me(i.root, n, e) : !1;
|
|
981
|
+
},
|
|
982
|
+
toggleList(e) {
|
|
983
|
+
C((t) => Re(t, n, e));
|
|
984
|
+
},
|
|
985
|
+
isListActive(e) {
|
|
986
|
+
return i ? Ie(i.root, n, e) : !1;
|
|
987
|
+
},
|
|
988
|
+
setBlockStyle(e, t) {
|
|
989
|
+
C((r) => Ne(r, n, e, t));
|
|
990
|
+
},
|
|
991
|
+
getBlockStyle(e) {
|
|
992
|
+
return i ? Pe(i.root, n, e) : null;
|
|
993
|
+
}
|
|
994
|
+
};
|
|
995
|
+
return w;
|
|
996
|
+
}, lt = (e) => {
|
|
997
|
+
let [t] = i(() => ct(e)), { extensions: r, onChange: a, onChangeJSON: o } = e;
|
|
998
|
+
return n(() => {
|
|
999
|
+
t.setOptions({
|
|
1000
|
+
extensions: r,
|
|
1001
|
+
onChange: a,
|
|
1002
|
+
onChangeJSON: o
|
|
1003
|
+
});
|
|
1004
|
+
}), n(() => () => t.destroy(), [t]), t;
|
|
1005
|
+
}, ut = e(null), dt = () => {
|
|
1006
|
+
let e = t(ut);
|
|
1007
|
+
if (!e) throw Error("useEditorContext must be used within an EditorProvider");
|
|
1008
|
+
return e;
|
|
1009
|
+
}, ft = ({ editor: e, children: t }) => /* @__PURE__ */ o(ut.Provider, {
|
|
1010
|
+
value: e,
|
|
1011
|
+
children: t
|
|
1012
|
+
}), J = (e, t, n) => {
|
|
1013
|
+
n === void 0 ? e.removeAttribute(t) : e.setAttribute(t, n);
|
|
1014
|
+
}, pt = ({ className: e, ariaLabel: t, ariaDescribedBy: i }) => {
|
|
1015
|
+
let a = dt(), s = r(null);
|
|
1016
|
+
return n(() => {
|
|
1017
|
+
if (s.current) return a.mount(s.current), () => a.unmount();
|
|
1018
|
+
}, [a]), n(() => {
|
|
1019
|
+
let n = a.el;
|
|
1020
|
+
n && (J(n, "class", e), J(n, "aria-label", t), J(n, "aria-describedby", i));
|
|
1021
|
+
}, [
|
|
1022
|
+
a,
|
|
1023
|
+
e,
|
|
1024
|
+
t,
|
|
1025
|
+
i
|
|
1026
|
+
]), /* @__PURE__ */ o("div", {
|
|
1027
|
+
ref: s,
|
|
1028
|
+
style: { display: "contents" }
|
|
1029
|
+
});
|
|
837
1030
|
};
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
1031
|
+
pt.displayName = "EditorContent";
|
|
1032
|
+
// src/react/hooks.ts
|
|
1033
|
+
var Y = (e, t) => {
|
|
1034
|
+
let n = r(null), i = () => {
|
|
1035
|
+
let r = n.current;
|
|
1036
|
+
if (r && r.revision === e.revision && r.selector === t) return r.value;
|
|
1037
|
+
let i = t(e);
|
|
1038
|
+
return n.current = {
|
|
1039
|
+
revision: e.revision,
|
|
1040
|
+
selector: t,
|
|
1041
|
+
value: i
|
|
1042
|
+
}, i;
|
|
1043
|
+
};
|
|
1044
|
+
return a(e.subscribe, i, i);
|
|
1045
|
+
}, mt = (e, t, n) => Y(e, (e) => e.isActive(t, n)), ht = (e) => Y(e, (e) => e.history.canUndo()), gt = (e) => Y(e, (e) => e.history.canRedo()), _t = (e) => `toggle${e[0].toUpperCase()}${e.slice(1)}`, X = (e) => {
|
|
1046
|
+
let { name: t, tag: n, aliases: r, shortcut: i } = e, a = _t(t);
|
|
1047
|
+
return {
|
|
1048
|
+
name: t,
|
|
1049
|
+
marks: [{
|
|
1050
|
+
tag: n,
|
|
1051
|
+
type: t,
|
|
1052
|
+
aliases: r
|
|
1053
|
+
}],
|
|
1054
|
+
commands: { [a]: (e) => e.toggleMark(n) },
|
|
1055
|
+
keyboardShortcuts: i ? { [i]: a } : void 0,
|
|
1056
|
+
isActive: (e) => e.isMarkActive(n)
|
|
1057
|
+
};
|
|
1058
|
+
}, Z = (e) => {
|
|
1059
|
+
let { name: t, tag: n, shortcut: r } = e, i = _t(t);
|
|
1060
|
+
return {
|
|
1061
|
+
name: t,
|
|
1062
|
+
blocks: [{
|
|
1063
|
+
tag: n,
|
|
1064
|
+
type: t
|
|
1065
|
+
}],
|
|
1066
|
+
commands: { [i]: (e) => e.toggleBlock(n) },
|
|
1067
|
+
keyboardShortcuts: r ? { [r]: i } : void 0,
|
|
1068
|
+
isActive: (e) => e.isBlockActive(n)
|
|
1069
|
+
};
|
|
1070
|
+
}, vt = X({
|
|
1071
|
+
name: "bold",
|
|
1072
|
+
tag: "strong",
|
|
1073
|
+
aliases: ["b"],
|
|
1074
|
+
shortcut: "Mod+B"
|
|
1075
|
+
}), yt = X({
|
|
1076
|
+
name: "italic",
|
|
1077
|
+
tag: "em",
|
|
1078
|
+
aliases: ["i"],
|
|
1079
|
+
shortcut: "Mod+I"
|
|
1080
|
+
}), bt = X({
|
|
1081
|
+
name: "underline",
|
|
1082
|
+
tag: "u",
|
|
1083
|
+
shortcut: "Mod+U"
|
|
1084
|
+
}), xt = X({
|
|
1085
|
+
name: "strikethrough",
|
|
1086
|
+
tag: "s",
|
|
1087
|
+
aliases: ["del"],
|
|
1088
|
+
shortcut: "Mod+Shift+S"
|
|
1089
|
+
}), St = X({
|
|
1090
|
+
name: "code",
|
|
1091
|
+
tag: "code"
|
|
1092
|
+
}), Ct = Z({
|
|
1093
|
+
name: "blockquote",
|
|
1094
|
+
tag: "blockquote"
|
|
1095
|
+
}), wt = Z({
|
|
1096
|
+
name: "codeBlock",
|
|
1097
|
+
tag: "pre"
|
|
1098
|
+
}), Q = [
|
|
1099
|
+
1,
|
|
1100
|
+
2,
|
|
1101
|
+
3,
|
|
1102
|
+
4,
|
|
1103
|
+
5,
|
|
1104
|
+
6
|
|
1105
|
+
], Tt = {
|
|
1106
|
+
name: "heading",
|
|
1107
|
+
blocks: Q.map((e) => ({
|
|
1108
|
+
tag: `h${e}`,
|
|
1109
|
+
type: "heading",
|
|
1110
|
+
attrs: { level: e }
|
|
1111
|
+
})),
|
|
1112
|
+
commands: {
|
|
1113
|
+
setHeading: (e, t) => {
|
|
1114
|
+
Q.includes(t) && e.setBlock(`h${t}`);
|
|
1115
|
+
},
|
|
1116
|
+
removeHeading: (e) => e.setBlock("p")
|
|
1117
|
+
},
|
|
1118
|
+
isActive: (e, t, n) => {
|
|
1119
|
+
if (t === "setHeading") return Q.includes(n) && e.isBlockActive(`h${n}`);
|
|
1120
|
+
let r = Q.some((t) => e.isBlockActive(`h${t}`));
|
|
1121
|
+
return t === "removeHeading" ? !r : r;
|
|
1122
|
+
}
|
|
1123
|
+
}, Et = (e, t) => {
|
|
1124
|
+
let n = `toggle${e[0].toUpperCase()}${e.slice(1)}`;
|
|
1125
|
+
return {
|
|
1126
|
+
name: e,
|
|
1127
|
+
blocks: [{
|
|
1128
|
+
tag: t,
|
|
1129
|
+
type: e
|
|
1130
|
+
}, {
|
|
1131
|
+
tag: "li",
|
|
1132
|
+
type: "listItem"
|
|
1133
|
+
}],
|
|
1134
|
+
commands: { [n]: (e) => e.toggleList(t) },
|
|
1135
|
+
isActive: (e) => e.isListActive(t)
|
|
1136
|
+
};
|
|
1137
|
+
}, Dt = Et("orderedList", "ol"), Ot = Et("unorderedList", "ul"), $ = {
|
|
1138
|
+
alignLeft: "left",
|
|
1139
|
+
alignCenter: "center",
|
|
1140
|
+
alignRight: "right",
|
|
1141
|
+
alignJustify: "justify"
|
|
1142
|
+
}, kt = {
|
|
1143
|
+
name: "textAlign",
|
|
1144
|
+
blockStyles: { "text-align": Object.values($) },
|
|
1145
|
+
commands: Object.fromEntries(Object.entries($).map(([e, t]) => [e, (e) => e.setBlockStyle("text-align", t)])),
|
|
1146
|
+
isActive: (e, t) => t !== void 0 && (e.getBlockStyle("text-align") ?? "left") === $[t]
|
|
1147
|
+
}, At = {
|
|
1148
|
+
name: "link",
|
|
1149
|
+
marks: [{
|
|
1150
|
+
tag: "a",
|
|
1151
|
+
type: "link",
|
|
1152
|
+
attrs: {
|
|
1153
|
+
href: (e) => e && p("href", e) ? e : null,
|
|
1154
|
+
target: (e) => e === "_blank" ? e : null,
|
|
1155
|
+
rel: (e, t) => t.getAttribute("target") === "_blank" ? "noopener noreferrer" : null
|
|
1156
|
+
}
|
|
1157
|
+
}],
|
|
1158
|
+
commands: {
|
|
1159
|
+
setLink: (e, t) => {
|
|
1160
|
+
let n = t?.href;
|
|
1161
|
+
n && p("href", n) && e.setMark("a", { href: n }, n);
|
|
1162
|
+
},
|
|
1163
|
+
removeLink: (e) => e.removeMark("a")
|
|
1164
|
+
},
|
|
1165
|
+
isActive: (e) => e.isMarkActive("a")
|
|
863
1166
|
};
|
|
1167
|
+
export { Ct as Blockquote, vt as Bold, St as Code, wt as CodeBlock, pt as EditorContent, ft as EditorProvider, Tt as Heading, yt as Italic, At as Link, Dt as OrderedList, xt as Strikethrough, kt as TextAlign, bt as Underline, Ot as UnorderedList, Z as block, X as mark, Xe as toHTML, Ze as toJSON, gt as useCanRedo, ht as useCanUndo, lt as useEditor, dt as useEditorContext, Y as useEditorState, mt as useIsActive };
|