@bavuchoko/js-editor 0.1.0

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/dist/index.js ADDED
@@ -0,0 +1,2343 @@
1
+ import { forwardRef as e, useEffect as t, useImperativeHandle as n, useRef as r, useState as i } from "react";
2
+ import { jsx as a, jsxs as o } from "react/jsx-runtime";
3
+ //#region src/editor/selection.ts
4
+ var s = /* @__PURE__ */ new Set([
5
+ "P",
6
+ "H1",
7
+ "H2",
8
+ "H3",
9
+ "BLOCKQUOTE",
10
+ "PRE",
11
+ "UL",
12
+ "OL",
13
+ "LI",
14
+ "DIV",
15
+ "TD",
16
+ "TH",
17
+ "TABLE"
18
+ ]), c = null;
19
+ function l(e) {
20
+ let t = window.getSelection();
21
+ return !t || t.rangeCount === 0 || !e.contains(t.anchorNode) ? null : t;
22
+ }
23
+ function u(e) {
24
+ let t = l(e);
25
+ if (!(!t || t.rangeCount === 0)) try {
26
+ c = t.getRangeAt(0).cloneRange();
27
+ } catch {}
28
+ }
29
+ function d(e) {
30
+ if (!c || !e.contains(c.commonAncestorContainer)) return !1;
31
+ let t = window.getSelection();
32
+ if (!t) return !1;
33
+ try {
34
+ return t.removeAllRanges(), t.addRange(c), !0;
35
+ } catch {
36
+ return !1;
37
+ }
38
+ }
39
+ function f(e) {
40
+ let t = l(e);
41
+ if (t && t.rangeCount > 0) {
42
+ let e = t.getRangeAt(0);
43
+ try {
44
+ c = e.cloneRange();
45
+ } catch {}
46
+ return e;
47
+ }
48
+ return c && e.contains(c.commonAncestorContainer) ? c.cloneRange() : null;
49
+ }
50
+ function p(e) {
51
+ return e !== null && e.nodeType === Node.ELEMENT_NODE;
52
+ }
53
+ function m(e, t, n) {
54
+ let r = e;
55
+ for (; r && r !== n;) {
56
+ if (p(r) && t(r)) return r;
57
+ r = r.parentNode;
58
+ }
59
+ return null;
60
+ }
61
+ function h(e, t, n) {
62
+ let r = (Array.isArray(t) ? t : [t]).map((e) => e.toUpperCase());
63
+ return m(e, (e) => r.includes(e.tagName), n);
64
+ }
65
+ function g(e, t) {
66
+ let n = m(e, (e) => s.has(e.tagName) && e !== t, t);
67
+ return n ? n.tagName === "LI" ? n : n.tagName === "UL" || n.tagName === "OL" ? h(e, "LI", t) ?? n : n : null;
68
+ }
69
+ function _(e, t = !1) {
70
+ let n = window.getSelection();
71
+ if (!n) return;
72
+ let r = document.createRange();
73
+ r.selectNodeContents(e), t && r.collapse(!1), n.removeAllRanges(), n.addRange(r);
74
+ }
75
+ function v(e) {
76
+ let t = window.getSelection();
77
+ if (!t) return;
78
+ let n = document.createRange();
79
+ n.setStartAfter(e), n.collapse(!0), t.removeAllRanges(), t.addRange(n);
80
+ }
81
+ function y(e, t = !1) {
82
+ let n = window.getSelection();
83
+ if (!n) return;
84
+ let r = document.createRange();
85
+ r.selectNodeContents(e), r.collapse(t), n.removeAllRanges(), n.addRange(r);
86
+ }
87
+ function b(e) {
88
+ !e.textContent?.replace(/\u200B/g, "").trim() && !e.querySelector("br, img") && e.appendChild(document.createElement("br")), y(e, !0);
89
+ }
90
+ function ee(e) {
91
+ if (!e) return "left";
92
+ let t = (e.style.textAlign || "").toLowerCase();
93
+ return t === "center" || t === "right" || t === "left" ? t : "left";
94
+ }
95
+ function x(e) {
96
+ return e.tagName === "UL" && (e.classList.contains("editor-checklist") || e.getAttribute("data-list") === "checklist");
97
+ }
98
+ function S(e, t) {
99
+ return e ? m(e, (e) => x(e), t) ? "checklist" : h(e, "OL", t) ? "ol" : m(e, (e) => e.tagName === "UL" && !x(e), t) ? "ul" : null : null;
100
+ }
101
+ function te(e) {
102
+ let t = f(e), n = t?.startContainer ?? null, r = t?.endContainer ?? null, i = g(n, e), a = S(n, e), o = S(r, e), s = a === "checklist" || o === "checklist" ? "checklist" : a ?? o, c = "p";
103
+ i && (i.tagName === "LI" ? c = s === "checklist" ? "checklist" : s === "ol" ? "ol" : "ul" : i.tagName === "PRE" ? c = "pre" : i.tagName === "TD" || i.tagName === "TH" ? c = "table" : x(i) ? c = "checklist" : i.tagName !== "TABLE" && (c = i.tagName.toLowerCase()));
104
+ let l = m(n, (e) => e.tagName === "SPAN" && !!e.style.color, e), u = m(n, (e) => e.tagName === "SPAN" && !!e.style.backgroundColor, e), d = h(n, ["TD", "TH"], e);
105
+ return {
106
+ bold: !!h(n, ["STRONG", "B"], e),
107
+ italic: !!h(n, ["EM", "I"], e),
108
+ underline: !!h(n, "U", e),
109
+ block: c,
110
+ align: ee(i),
111
+ inList: s,
112
+ textColor: l?.style.color || d?.style.color || null,
113
+ highlightColor: u?.style.backgroundColor || d?.style.backgroundColor || null,
114
+ inTable: !!h(n, "TABLE", e)
115
+ };
116
+ }
117
+ function C(e) {
118
+ let t = f(e);
119
+ if (!t || !t.collapsed) return null;
120
+ let n = g(t.startContainer, e);
121
+ if (!n) return null;
122
+ let r = t.cloneRange();
123
+ return r.selectNodeContents(n), r.setEnd(t.startContainer, t.startOffset), {
124
+ block: n,
125
+ text: r.toString(),
126
+ range: t
127
+ };
128
+ }
129
+ //#endregion
130
+ //#region src/editor/commands.ts
131
+ var w = {
132
+ bold: "STRONG",
133
+ italic: "EM",
134
+ underline: "U"
135
+ };
136
+ function T(e) {
137
+ let t = e.parentNode;
138
+ if (t) {
139
+ for (; e.firstChild;) t.insertBefore(e.firstChild, e);
140
+ t.removeChild(e), t.normalize();
141
+ }
142
+ }
143
+ function E(e, t) {
144
+ let n = document.createElement(t);
145
+ if (e.collapsed) {
146
+ n.appendChild(document.createTextNode("​")), e.insertNode(n), _(n.firstChild, !1);
147
+ let t = window.getSelection();
148
+ if (t) {
149
+ let e = document.createRange();
150
+ e.setStart(n.firstChild, 1), e.collapse(!0), t.removeAllRanges(), t.addRange(e);
151
+ }
152
+ return n;
153
+ }
154
+ try {
155
+ e.surroundContents(n);
156
+ } catch {
157
+ let t = e.extractContents();
158
+ n.appendChild(t), e.insertNode(n);
159
+ }
160
+ return _(n), n;
161
+ }
162
+ function D(e, t, n) {
163
+ return h(e, t === "STRONG" ? ["STRONG", "B"] : t === "EM" ? ["EM", "I"] : [t], n);
164
+ }
165
+ function O(e, t) {
166
+ let n = f(e);
167
+ if (!n) return !1;
168
+ let r = w[t], i = D(n.commonAncestorContainer, r, e);
169
+ return i ? (T(i), !0) : (E(n, r.toLowerCase()), !0);
170
+ }
171
+ function k() {
172
+ let e = document.createElement("p");
173
+ return e.appendChild(document.createElement("br")), e;
174
+ }
175
+ function A(e) {
176
+ e.firstChild || e.appendChild(k());
177
+ }
178
+ function ne(e, t) {
179
+ if (e.tagName === t.toUpperCase()) return e;
180
+ let n = document.createElement(t);
181
+ for (; e.firstChild;) n.appendChild(e.firstChild);
182
+ return e.style.textAlign && (n.style.textAlign = e.style.textAlign), e.replaceWith(n), n.textContent || n.appendChild(document.createElement("br")), n;
183
+ }
184
+ function j(e) {
185
+ return !!(e && e.tagName === "UL" && (e.classList.contains("editor-checklist") || e.dataset.list === "checklist"));
186
+ }
187
+ function M(e) {
188
+ if (e.tagName === "LI") {
189
+ let t = e.querySelector(":scope > .checklist-content");
190
+ if (t instanceof HTMLElement) return t;
191
+ }
192
+ return e;
193
+ }
194
+ function N(e, t) {
195
+ let n = e.parentElement, r = document.createElement("p"), i = M(e);
196
+ if (i !== e) for (; i.firstChild;) r.appendChild(i.firstChild);
197
+ else for (; e.firstChild;) {
198
+ let t = e.firstChild;
199
+ if (p(t) && t.classList.contains("checklist-box")) {
200
+ t.remove();
201
+ continue;
202
+ }
203
+ r.appendChild(t);
204
+ }
205
+ if (!r.textContent?.replace(/\u200B/g, "").trim() && !r.querySelector("img") && (r.querySelector("br") || r.appendChild(document.createElement("br"))), n && (n.tagName === "UL" || n.tagName === "OL")) {
206
+ let i = n.parentNode ?? t;
207
+ if (e.nextSibling) {
208
+ let t = document.createElement(n.tagName);
209
+ for (; e.nextSibling;) t.appendChild(e.nextSibling);
210
+ i.insertBefore(t, n.nextSibling), i.insertBefore(r, t);
211
+ } else i.insertBefore(r, n.nextSibling);
212
+ e.remove(), n.children.length || n.remove();
213
+ } else e.replaceWith(r);
214
+ return r;
215
+ }
216
+ function re(e, t) {
217
+ try {
218
+ let n = document.createRange();
219
+ return n.selectNode(t), e.compareBoundaryPoints(Range.END_TO_START, n) < 0 && e.compareBoundaryPoints(Range.START_TO_END, n) > 0;
220
+ } catch {
221
+ return !1;
222
+ }
223
+ }
224
+ function P(e) {
225
+ return !e.textContent?.replace(/\u200B/g, "").trim() && !e.querySelector("img");
226
+ }
227
+ function ie(e) {
228
+ if (e.tagName === "PRE") return (e.querySelector("code")?.textContent ?? e.textContent ?? "").split("\n").map((e) => {
229
+ let t = document.createElement("div");
230
+ return e && (t.textContent = e), t;
231
+ });
232
+ let t = [], n = document.createElement("div"), r = () => {
233
+ t.push(n), n = document.createElement("div");
234
+ };
235
+ for (let t of Array.from(e.childNodes)) {
236
+ if (p(t) && t.tagName === "BR") {
237
+ t.remove(), r();
238
+ continue;
239
+ }
240
+ if (t.nodeType === Node.TEXT_NODE && (t.textContent ?? "").includes("\n")) {
241
+ let e = t.textContent ?? "";
242
+ t.remove();
243
+ let i = e.split("\n");
244
+ i.forEach((e, t) => {
245
+ e && n.appendChild(document.createTextNode(e)), t < i.length - 1 && r();
246
+ });
247
+ continue;
248
+ }
249
+ n.appendChild(t);
250
+ }
251
+ for (r(); t.length > 1 && P(t[t.length - 1]);) t.pop();
252
+ return t.length ? t : [document.createElement("div")];
253
+ }
254
+ function ae(e, t) {
255
+ let n = [];
256
+ for (let r of Array.from(e.children)) if (p(r)) {
257
+ if (r.tagName === "UL" || r.tagName === "OL") {
258
+ for (let e of Array.from(r.children)) p(e) && e.tagName === "LI" && re(t, e) && n.push(e);
259
+ continue;
260
+ }
261
+ [
262
+ "P",
263
+ "H1",
264
+ "H2",
265
+ "H3",
266
+ "BLOCKQUOTE",
267
+ "PRE",
268
+ "DIV"
269
+ ].includes(r.tagName) && re(t, r) && n.push(r);
270
+ }
271
+ if (n.length === 0) {
272
+ let r = g(t.startContainer, e);
273
+ r && r.tagName !== "TABLE" && r.tagName !== "TD" && r.tagName !== "TH" && n.push(r);
274
+ }
275
+ return n;
276
+ }
277
+ function oe(e) {
278
+ let t = document.createElement("li");
279
+ for (; e.firstChild;) t.appendChild(e.firstChild);
280
+ return P(t) && t.appendChild(document.createElement("br")), t;
281
+ }
282
+ function F(e, t = !1) {
283
+ let n = document.createElement("li");
284
+ n.dataset.checked = t ? "true" : "false";
285
+ let r = document.createElement("span");
286
+ r.className = "checklist-box", r.contentEditable = "false", r.setAttribute("role", "checkbox"), r.setAttribute("aria-checked", t ? "true" : "false"), r.tabIndex = -1;
287
+ let i = document.createElement("span");
288
+ for (i.className = "checklist-content"; e.firstChild;) i.appendChild(e.firstChild);
289
+ return P(i) && i.appendChild(document.createElement("br")), n.appendChild(r), n.appendChild(i), n;
290
+ }
291
+ function se() {
292
+ let e = document.createElement("ul");
293
+ return e.className = "editor-checklist", e.dataset.list = "checklist", e;
294
+ }
295
+ function ce(e, t) {
296
+ let n = window.getSelection();
297
+ if (!n) return;
298
+ let r = document.createRange();
299
+ try {
300
+ r.setStartBefore(e), r.setEndAfter(t);
301
+ } catch {
302
+ r.selectNodeContents(e);
303
+ }
304
+ n.removeAllRanges(), n.addRange(r);
305
+ }
306
+ function le(e, t) {
307
+ if (e.tagName !== "LI" || !e.parentElement) return !1;
308
+ let n = e.parentElement;
309
+ return t === "checklist" ? j(n) : t === "ol" ? n.tagName === "OL" : n.tagName === "UL" && !j(n);
310
+ }
311
+ function ue(e, t) {
312
+ let n = f(e);
313
+ if (!n) return !1;
314
+ let r = !n.collapsed, i = ae(e, n);
315
+ if (i.length === 0) return !1;
316
+ if (i.every((e) => le(e, t))) {
317
+ let t = [];
318
+ for (let n of [...i].reverse()) t.unshift(N(n, e));
319
+ return t.length === 0 || (r ? ce(t[0], t[t.length - 1]) : y(t[0])), !0;
320
+ }
321
+ let a = t === "checklist" ? se() : document.createElement(t);
322
+ for (let e of i) {
323
+ let n = e.tagName === "LI" && e.dataset.checked === "true", r = M(e);
324
+ for (let e of ie(r)) t === "checklist" ? a.appendChild(F(e, n)) : a.appendChild(oe(e));
325
+ }
326
+ a.children.length || a.appendChild(t === "checklist" ? F(document.createElement("div")) : oe(document.createElement("div"))), i[0].before(a);
327
+ for (let e of i) {
328
+ let t = e.parentElement;
329
+ e.remove(), t && (t.tagName === "UL" || t.tagName === "OL") && !t.children.length && t.remove();
330
+ }
331
+ let o = Array.from(a.children), s = o[0], c = o[o.length - 1];
332
+ return s && (r ? ce(s, c) : y(s.querySelector(".checklist-content") ?? s)), !0;
333
+ }
334
+ function de(e, t) {
335
+ let n = t.target;
336
+ if (!(n instanceof Element)) return !1;
337
+ let r = n.closest(".checklist-box");
338
+ if (!r || !e.contains(r)) return !1;
339
+ let i = r.closest("li");
340
+ if (!i || !j(i.parentElement)) return !1;
341
+ t.preventDefault();
342
+ let a = i.dataset.checked === "true" ? "false" : "true";
343
+ return i.dataset.checked = a, r.setAttribute("aria-checked", a), !0;
344
+ }
345
+ function fe(e, t) {
346
+ A(e);
347
+ let n = f(e);
348
+ if (!n) return !1;
349
+ let r = g(n.startContainer, e);
350
+ if (r ||= (e.appendChild(k()), e.firstElementChild), t === "ul" || t === "ol" || t === "checklist") return ue(e, t);
351
+ if (r.tagName === "LI" && (r = N(r, e)), t === "pre") {
352
+ let e = r.textContent ?? "", t = document.createElement("pre"), n = document.createElement("code");
353
+ return n.textContent = e === "\n" ? "" : e, n.textContent || n.appendChild(document.createTextNode("")), t.appendChild(n), r.replaceWith(t), y(n), !0;
354
+ }
355
+ if (r.tagName === "PRE") {
356
+ let e = r.querySelector("code")?.textContent ?? r.textContent ?? "", n = document.createElement(t);
357
+ return n.textContent = e, n.textContent || n.appendChild(document.createElement("br")), r.replaceWith(n), y(n), !0;
358
+ }
359
+ return y(ne(r, t)), !0;
360
+ }
361
+ function pe(e, t) {
362
+ let n = f(e);
363
+ if (!n) return !1;
364
+ let r = g(n.startContainer, e);
365
+ if (!r) return !1;
366
+ let i = r.tagName === "LI" ? r.parentElement : r;
367
+ return i.style.textAlign = t === "left" ? "" : t, !0;
368
+ }
369
+ function me(e, t, n) {
370
+ return m(e, (e) => e.tagName === "SPAN" && !!e.style[t], n);
371
+ }
372
+ function he(e) {
373
+ !e.getAttribute("style")?.trim() && !e.className && T(e);
374
+ }
375
+ function ge(e) {
376
+ return Array.from(e.querySelectorAll("td.is-cell-selected, th.is-cell-selected"));
377
+ }
378
+ function _e(e, t, n) {
379
+ for (let r of e) r.style[t] = n ?? "";
380
+ return !0;
381
+ }
382
+ function ve(e, t, n) {
383
+ let r = ge(e);
384
+ if (r.length > 0) return _e(r, t, n);
385
+ let i = f(e);
386
+ if (!i) return !1;
387
+ let a = h(i.startContainer, ["TD", "TH"], e);
388
+ if (a && i.collapsed) return a.style[t] = n ?? "", !0;
389
+ if (a && !i.collapsed) {
390
+ if (!n) {
391
+ let e = E(i, "span");
392
+ return t === "color" ? e.style.color = "inherit" : e.style.backgroundColor = "transparent", !0;
393
+ }
394
+ let e = E(i, "span");
395
+ return e.style[t] = n, !0;
396
+ }
397
+ let o = me(i.commonAncestorContainer, t, e);
398
+ if (!n) {
399
+ if (!o) return !0;
400
+ if (i.collapsed && o.contains(i.startContainer)) return o.style[t] = "", he(o), !0;
401
+ if (!i.collapsed) {
402
+ let e = E(i, "span");
403
+ return t === "color" ? e.style.color = "inherit" : e.style.backgroundColor = "transparent", !0;
404
+ }
405
+ return !0;
406
+ }
407
+ let s = E(i, "span");
408
+ return s.style[t] = n, !0;
409
+ }
410
+ function ye(e, t) {
411
+ return ve(e, "color", t);
412
+ }
413
+ function be(e, t) {
414
+ return ve(e, "backgroundColor", t);
415
+ }
416
+ function xe(e, t) {
417
+ let n = f(e);
418
+ if (!n) return !1;
419
+ n.deleteContents();
420
+ let r = document.createElement("template");
421
+ r.innerHTML = t;
422
+ let i = r.content, a = i.lastChild;
423
+ return n.insertNode(i), a && v(a), !0;
424
+ }
425
+ function Se(e = "td") {
426
+ let t = document.createElement(e);
427
+ return t.appendChild(document.createElement("br")), t;
428
+ }
429
+ function Ce(e, t = 3, n = 3) {
430
+ let r = f(e);
431
+ if (!r) return !1;
432
+ let i = Math.min(Math.max(t, 1), 20), a = Math.min(Math.max(n, 1), 20), o = document.createElement("table");
433
+ o.className = "editor-table";
434
+ let s = document.createElement("tbody");
435
+ for (let e = 0; e < i; e++) {
436
+ let e = document.createElement("tr");
437
+ for (let t = 0; t < a; t++) e.appendChild(Se("td"));
438
+ s.appendChild(e);
439
+ }
440
+ o.appendChild(s);
441
+ let c = g(r.startContainer, e);
442
+ c && c.tagName !== "TD" && c.tagName !== "TH" ? !c.textContent?.replace(/\u200B/g, "").trim() && !c.querySelector("img, table") ? c.replaceWith(o) : c.after(o) : (r.collapse(!0), r.insertNode(o));
443
+ let l = k();
444
+ o.after(l);
445
+ let u = o.querySelector("th, td");
446
+ return u && b(u), !0;
447
+ }
448
+ function we(e) {
449
+ return Array.from(e.querySelectorAll("th, td"));
450
+ }
451
+ function Te(e) {
452
+ return e.textContent?.replace(/\u200B/g, "").trim() ?? "" ? !0 : !!e.querySelector("img");
453
+ }
454
+ function Ee(e) {
455
+ return !Te(e);
456
+ }
457
+ function De(e) {
458
+ return Array.from(e.querySelectorAll("tr"));
459
+ }
460
+ function I(e) {
461
+ return Array.from(e.children).filter((e) => e.tagName === "TD" || e.tagName === "TH");
462
+ }
463
+ function Oe(e) {
464
+ let t = e.parentElement, n = e.closest("table");
465
+ if (!t || !n) return null;
466
+ let r = De(n).indexOf(t), i = I(t).indexOf(e);
467
+ return r < 0 || i < 0 ? null : {
468
+ table: n,
469
+ row: r,
470
+ col: i
471
+ };
472
+ }
473
+ function ke(e, t) {
474
+ if (Te(t)) for (Ee(e) ? e.innerHTML = "" : e.appendChild(document.createElement("br")); t.firstChild;) e.appendChild(t.firstChild);
475
+ }
476
+ function Ae(e) {
477
+ if (e.length < 2) return !1;
478
+ let t = e.map((e) => Oe(e));
479
+ if (t.some((e) => !e)) return !1;
480
+ let n = t[0].table;
481
+ if (!t.every((e) => e.table === n)) return !1;
482
+ let r = t.map((e) => e.row), i = t.map((e) => e.col), a = Math.min(...r), o = Math.max(...r), s = Math.min(...i), c = Math.max(...i);
483
+ if (e.some((e) => (e.colSpan || 1) > 1 || (e.rowSpan || 1) > 1)) return !1;
484
+ let l = De(n), u = [];
485
+ for (let e = a; e <= o; e++) {
486
+ let t = I(l[e]);
487
+ for (let e = s; e <= c; e++) {
488
+ let n = t[e];
489
+ if (!n) return !1;
490
+ u.push(n);
491
+ }
492
+ }
493
+ let d = new Set(e);
494
+ if (u.length !== e.length || !u.every((e) => d.has(e))) return !1;
495
+ let f = I(l[a])[s];
496
+ if (!f) return !1;
497
+ f.colSpan = c - s + 1, f.rowSpan = o - a + 1;
498
+ for (let e of u) e !== f && (ke(f, e), e.remove());
499
+ return y(f), !0;
500
+ }
501
+ function je(e, t) {
502
+ if (t.key !== "Tab") return !1;
503
+ let n = f(e);
504
+ if (!n) return !1;
505
+ let r = h(n.startContainer, ["TD", "TH"], e);
506
+ if (!r) return !1;
507
+ let i = h(r, "TABLE", e);
508
+ if (!i) return !1;
509
+ t.preventDefault();
510
+ let a = we(i), o = a.indexOf(r);
511
+ if (o < 0) return !0;
512
+ let s = t.shiftKey ? o - 1 : o + 1;
513
+ if (s < 0 || s >= a.length) {
514
+ if (!t.shiftKey) {
515
+ let e = i.querySelector("tr:last-child")?.children.length ?? 1, t = document.createElement("tr");
516
+ for (let n = 0; n < e; n++) t.appendChild(Se("td"));
517
+ (i.tBodies[0] ?? i).appendChild(t), b(t.cells[0]);
518
+ }
519
+ return !0;
520
+ }
521
+ return b(a[s]), !0;
522
+ }
523
+ function Me(e, t) {
524
+ let n = f(e);
525
+ if (!n || !n.collapsed) return !1;
526
+ if (h(n.startContainer, ["TD", "TH"], e)) {
527
+ t.preventDefault();
528
+ let e = document.createElement("br");
529
+ return n.insertNode(e), v(e), !0;
530
+ }
531
+ if (h(n.startContainer, "PRE", e)) {
532
+ t.preventDefault();
533
+ let e = document.createTextNode("\n");
534
+ return n.insertNode(e), v(e), !0;
535
+ }
536
+ let r = h(n.startContainer, "LI", e);
537
+ if (r) {
538
+ if ((r.textContent?.replace(/\u200B/g, "").trim() ?? "") === "") return t.preventDefault(), b(N(r, e)), !0;
539
+ t.preventDefault();
540
+ let i = j(r.parentElement), a = M(r), o = n.cloneRange();
541
+ o.selectNodeContents(a), o.setStart(n.startContainer, n.startOffset);
542
+ let s = o.extractContents(), c;
543
+ if (i) {
544
+ let e = document.createElement("div");
545
+ (s.textContent || s.querySelector?.("img, br")) && e.appendChild(s), c = F(e, !1);
546
+ } else c = document.createElement("li"), s.textContent || s.querySelector?.("img, br") ? c.appendChild(s) : c.appendChild(document.createElement("br"));
547
+ return r.after(c), y(c.querySelector(".checklist-content") ?? c, !0), !0;
548
+ }
549
+ let i = h(n.startContainer, "BLOCKQUOTE", e);
550
+ if (i && (i.textContent?.replace(/\u200B/g, "").trim() ?? "") === "") {
551
+ t.preventDefault();
552
+ let e = k();
553
+ return i.replaceWith(e), b(e), !0;
554
+ }
555
+ return !1;
556
+ }
557
+ function Ne(e) {
558
+ e.focus();
559
+ let t = window.getSelection();
560
+ if (!t || t.rangeCount > 0 && t.anchorNode && e.contains(t.anchorNode) || d(e)) return;
561
+ let n = e.lastElementChild;
562
+ n ? y(n) : (A(e), y(e.firstElementChild));
563
+ }
564
+ //#endregion
565
+ //#region src/editor/history.ts
566
+ function Pe(e, t) {
567
+ let n = [], r = t;
568
+ for (; r && r !== e;) {
569
+ let e = r.parentNode;
570
+ if (!e) break;
571
+ n.unshift(Array.prototype.indexOf.call(e.childNodes, r)), r = e;
572
+ }
573
+ return n;
574
+ }
575
+ function Fe(e, t) {
576
+ let n = e;
577
+ for (let e of t) {
578
+ if (!n.childNodes[e]) return null;
579
+ n = n.childNodes[e];
580
+ }
581
+ return n;
582
+ }
583
+ function Ie(e) {
584
+ let t = window.getSelection();
585
+ if (!(!t || t.rangeCount === 0) && !(!e.contains(t.anchorNode) || !t.focusNode)) try {
586
+ let n = t.getRangeAt(0);
587
+ return {
588
+ startPath: Pe(e, n.startContainer),
589
+ startOffset: n.startOffset,
590
+ endPath: Pe(e, n.endContainer),
591
+ endOffset: n.endOffset
592
+ };
593
+ } catch {
594
+ return;
595
+ }
596
+ }
597
+ function Le(e) {
598
+ return e.nodeType === Node.TEXT_NODE ? e.data.length : e.childNodes.length;
599
+ }
600
+ function Re(e, t) {
601
+ if (!t) return;
602
+ let n = Fe(e, t.startPath), r = Fe(e, t.endPath);
603
+ if (!(!n || !r)) try {
604
+ let e = document.createRange();
605
+ e.setStart(n, Math.min(t.startOffset, Le(n))), e.setEnd(r, Math.min(t.endOffset, Le(r)));
606
+ let i = window.getSelection();
607
+ i?.removeAllRanges(), i?.addRange(e);
608
+ } catch {}
609
+ }
610
+ var ze = class {
611
+ undoStack = [];
612
+ redoStack = [];
613
+ lastPush = 0;
614
+ debounceMs;
615
+ maxSize;
616
+ constructor(e = 300, t = 100) {
617
+ this.debounceMs = e, this.maxSize = t;
618
+ }
619
+ reset(e) {
620
+ this.undoStack = [{ html: e }], this.redoStack = [], this.lastPush = Date.now();
621
+ }
622
+ push(e, t = !1) {
623
+ let n = e.innerHTML, r = Date.now(), i = this.undoStack[this.undoStack.length - 1];
624
+ if (!(i && i.html === n)) {
625
+ if (!t && i && r - this.lastPush < this.debounceMs) {
626
+ this.undoStack[this.undoStack.length - 1] = {
627
+ html: n,
628
+ selection: Ie(e)
629
+ };
630
+ return;
631
+ }
632
+ this.undoStack.push({
633
+ html: n,
634
+ selection: Ie(e)
635
+ }), this.undoStack.length > this.maxSize && this.undoStack.shift(), this.redoStack = [], this.lastPush = r;
636
+ }
637
+ }
638
+ undo(e) {
639
+ if (this.undoStack.length <= 1) return !1;
640
+ let t = this.undoStack.pop();
641
+ this.redoStack.push(t);
642
+ let n = this.undoStack[this.undoStack.length - 1];
643
+ return e.innerHTML = n.html, Re(e, n.selection), !0;
644
+ }
645
+ redo(e) {
646
+ let t = this.redoStack.pop();
647
+ return t ? (this.undoStack.push(t), e.innerHTML = t.html, Re(e, t.selection), !0) : !1;
648
+ }
649
+ canUndo() {
650
+ return this.undoStack.length > 1;
651
+ }
652
+ canRedo() {
653
+ return this.redoStack.length > 0;
654
+ }
655
+ };
656
+ //#endregion
657
+ //#region src/editor/markdown.ts
658
+ function Be(e, t) {
659
+ let n = document.createTreeWalker(e, NodeFilter.SHOW_TEXT), r = t, i = n.nextNode();
660
+ for (; i && r > 0;) {
661
+ let e = i.data;
662
+ if (e.length <= r) {
663
+ r -= e.length;
664
+ let t = n.nextNode();
665
+ i.remove(), i = t;
666
+ } else i.data = e.slice(r), r = 0;
667
+ }
668
+ e.textContent || e.appendChild(document.createElement("br"));
669
+ }
670
+ function L(e, t, n) {
671
+ let r = C(e);
672
+ if (!r) return !1;
673
+ let i = t.exec(r.text);
674
+ return i ? (Be(r.block, i[0].length), fe(e, n), !0) : !1;
675
+ }
676
+ function Ve(e, t, n) {
677
+ let r = document.createRange(), i = document.createTreeWalker(e, NodeFilter.SHOW_TEXT), a = 0, o = null, s = 0, c = null, l = 0, u = i.nextNode();
678
+ for (; u;) {
679
+ let e = a + u.data.length;
680
+ if (!o && t >= a && t <= e && (o = u, s = t - a), n >= a && n <= e) {
681
+ c = u, l = n - a;
682
+ break;
683
+ }
684
+ a = e, u = i.nextNode();
685
+ }
686
+ return !o || !c ? null : (r.setStart(o, s), r.setEnd(c, l), r);
687
+ }
688
+ function He(e, t, n) {
689
+ let r = C(e);
690
+ if (!r) return !1;
691
+ let i = t.exec(r.text);
692
+ if (!i) return !1;
693
+ let a = i[0], o = i[1], s = r.text.length - a.length, c = Ve(r.block, s, r.text.length);
694
+ if (!c) return !1;
695
+ c.deleteContents();
696
+ let l = n === "bold" ? "strong" : "em", u = document.createElement(l);
697
+ u.textContent = o, c.insertNode(u);
698
+ let d = document.createTextNode(" ");
699
+ u.after(d);
700
+ let f = window.getSelection();
701
+ if (f) {
702
+ let e = document.createRange();
703
+ e.setStart(d, 1), e.collapse(!0), f.removeAllRanges(), f.addRange(e);
704
+ }
705
+ return !0;
706
+ }
707
+ var Ue = [
708
+ (e) => L(e, /^### $/, "h3"),
709
+ (e) => L(e, /^## $/, "h2"),
710
+ (e) => L(e, /^# $/, "h1"),
711
+ (e) => L(e, /^> $/, "blockquote"),
712
+ (e) => L(e, /^(-|\*) $/, "ul"),
713
+ (e) => L(e, /^\d+\. $/, "ol"),
714
+ (e) => L(e, /^``` $/, "pre"),
715
+ (e) => He(e, /\*\*(.+?)\*\* $/, "bold"),
716
+ (e) => He(e, /(?<!\*)\*([^*\n]+)\* $/, "italic")
717
+ ];
718
+ function We(e) {
719
+ for (let t of Ue) if (t(e)) return !0;
720
+ return !1;
721
+ }
722
+ //#endregion
723
+ //#region src/editor/document.ts
724
+ function R(e) {
725
+ return e.nodeType === Node.ELEMENT_NODE;
726
+ }
727
+ function Ge(e) {
728
+ let t = (e || "").match(/text-align:\s*(left|center|right)/i)?.[1];
729
+ if (t === "left" || t === "center" || t === "right") return t;
730
+ }
731
+ function z(e, t = []) {
732
+ if (e.nodeType === Node.TEXT_NODE) {
733
+ let n = e.textContent?.replace(/\u200B/g, "") ?? "";
734
+ return n ? [t.length ? {
735
+ type: "text",
736
+ text: n,
737
+ marks: t
738
+ } : {
739
+ type: "text",
740
+ text: n
741
+ }] : [];
742
+ }
743
+ if (!R(e)) return [];
744
+ let n = e;
745
+ if (n.tagName === "BR") return [{ type: "hardBreak" }];
746
+ let r = [], i = n.tagName;
747
+ i === "STRONG" || i === "B" ? r.push({ type: "bold" }) : i === "EM" || i === "I" ? r.push({ type: "italic" }) : i === "U" ? r.push({ type: "underline" }) : i === "CODE" ? r.push({ type: "code" }) : i === "SPAN" && (n.style.color && r.push({
748
+ type: "textStyle",
749
+ attrs: { color: n.style.color }
750
+ }), n.style.backgroundColor && r.push({
751
+ type: "highlight",
752
+ attrs: { color: n.style.backgroundColor }
753
+ }));
754
+ let a = [...t, ...r], o = [];
755
+ return n.childNodes.forEach((e) => {
756
+ o.push(...z(e, a));
757
+ }), o;
758
+ }
759
+ function B(e) {
760
+ let t = [];
761
+ return e.childNodes.forEach((e) => {
762
+ t.push(...z(e));
763
+ }), t;
764
+ }
765
+ function Ke(e) {
766
+ let t = [], n = [], r = () => {
767
+ n.length && (t.push({
768
+ type: "paragraph",
769
+ content: n
770
+ }), n = []);
771
+ };
772
+ return e.childNodes.forEach((e) => {
773
+ if (R(e) && (e.tagName === "UL" || e.tagName === "OL")) {
774
+ r();
775
+ let n = Je(e);
776
+ n && t.push(n);
777
+ return;
778
+ }
779
+ if (R(e) && e.tagName === "P") {
780
+ r(), t.push({
781
+ type: "paragraph",
782
+ attrs: V(e),
783
+ content: B(e)
784
+ });
785
+ return;
786
+ }
787
+ n.push(...z(e));
788
+ }), r(), {
789
+ type: "listItem",
790
+ content: t.length ? t : [{ type: "paragraph" }]
791
+ };
792
+ }
793
+ function V(e) {
794
+ let t = Ge(e.getAttribute("style") || e.style.textAlign);
795
+ return t ? { textAlign: t } : void 0;
796
+ }
797
+ function qe(e) {
798
+ let t = {}, n = e.colSpan || 1, r = e.rowSpan || 1;
799
+ return n > 1 && (t.colspan = n), r > 1 && (t.rowspan = r), e.style.color && (t.color = e.style.color), e.style.backgroundColor && (t.backgroundColor = e.style.backgroundColor), Object.keys(t).length ? t : void 0;
800
+ }
801
+ function Je(e) {
802
+ let t = e.tagName;
803
+ if (t === "P") return {
804
+ type: "paragraph",
805
+ attrs: V(e),
806
+ content: B(e)
807
+ };
808
+ if (t === "H1" || t === "H2" || t === "H3") return {
809
+ type: "heading",
810
+ attrs: {
811
+ level: Number(t[1]),
812
+ ...V(e)
813
+ },
814
+ content: B(e)
815
+ };
816
+ if (t === "BLOCKQUOTE") return {
817
+ type: "blockquote",
818
+ attrs: V(e),
819
+ content: B(e)
820
+ };
821
+ if (t === "PRE") {
822
+ let t = e.textContent ?? "";
823
+ return {
824
+ type: "codeBlock",
825
+ content: t ? [{
826
+ type: "text",
827
+ text: t
828
+ }] : []
829
+ };
830
+ }
831
+ return t === "UL" ? e.classList.contains("editor-checklist") || e.getAttribute("data-list") === "checklist" ? {
832
+ type: "taskList",
833
+ content: Array.from(e.children).filter((e) => e.tagName === "LI").map((e) => {
834
+ let t = e.querySelector(":scope > .checklist-content") ?? e;
835
+ return {
836
+ type: "taskItem",
837
+ attrs: { checked: e.dataset.checked === "true" },
838
+ content: B(t)
839
+ };
840
+ })
841
+ } : {
842
+ type: "bulletList",
843
+ content: Array.from(e.children).filter((e) => e.tagName === "LI").map(Ke)
844
+ } : t === "OL" ? {
845
+ type: "orderedList",
846
+ content: Array.from(e.children).filter((e) => e.tagName === "LI").map(Ke)
847
+ } : t === "TABLE" ? {
848
+ type: "table",
849
+ content: Array.from(e.querySelectorAll(":scope > tbody > tr, :scope > tr")).map((e) => ({
850
+ type: "tableRow",
851
+ content: Array.from(e.children).filter((e) => e.tagName === "TD" || e.tagName === "TH").map((e) => ({
852
+ type: "tableCell",
853
+ attrs: qe(e),
854
+ content: B(e)
855
+ }))
856
+ }))
857
+ } : t === "DIV" ? {
858
+ type: "paragraph",
859
+ content: B(e)
860
+ } : null;
861
+ }
862
+ function H(e) {
863
+ let t = [];
864
+ return e.childNodes.forEach((e) => {
865
+ if (!R(e)) {
866
+ let n = e.textContent?.replace(/\u200B/g, "").trim();
867
+ n && t.push({
868
+ type: "paragraph",
869
+ content: [{
870
+ type: "text",
871
+ text: n
872
+ }]
873
+ });
874
+ return;
875
+ }
876
+ let n = Je(e);
877
+ n && t.push(n);
878
+ }), {
879
+ type: "doc",
880
+ content: t.length ? t : [{ type: "paragraph" }]
881
+ };
882
+ }
883
+ function Ye(e) {
884
+ let t = document.createElement("template");
885
+ t.innerHTML = e;
886
+ let n = document.createElement("div");
887
+ return n.append(...Array.from(t.content.childNodes)), H(n);
888
+ }
889
+ function Xe(e) {
890
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
891
+ }
892
+ function Ze(e, t) {
893
+ let n = Xe(e);
894
+ if (!t?.length) return n;
895
+ for (let e of t) switch (e.type) {
896
+ case "bold":
897
+ n = `<strong>${n}</strong>`;
898
+ break;
899
+ case "italic":
900
+ n = `<em>${n}</em>`;
901
+ break;
902
+ case "underline":
903
+ n = `<u>${n}</u>`;
904
+ break;
905
+ case "code":
906
+ n = `<code>${n}</code>`;
907
+ break;
908
+ case "textStyle":
909
+ e.attrs?.color && (n = `<span style="color: ${e.attrs.color}">${n}</span>`);
910
+ break;
911
+ case "highlight":
912
+ e.attrs?.color && (n = `<span style="background-color: ${e.attrs.color}">${n}</span>`);
913
+ break;
914
+ }
915
+ return n;
916
+ }
917
+ function U(e) {
918
+ return e?.length && e.map((e) => e.type === "hardBreak" ? "<br>" : Ze(e.text, e.marks)).join("") || "<br>";
919
+ }
920
+ function W(e, t) {
921
+ let n = [];
922
+ return e && e !== "left" && n.push(`text-align: ${e}`), t && n.push(t), n.length ? ` style="${n.join("; ")}"` : "";
923
+ }
924
+ function Qe(e) {
925
+ switch (e.type) {
926
+ case "paragraph": return `<p${W(e.attrs?.textAlign)}>${U(e.content)}</p>`;
927
+ case "heading": {
928
+ let t = `h${e.attrs.level}`;
929
+ return `<${t}${W(e.attrs.textAlign)}>${U(e.content)}</${t}>`;
930
+ }
931
+ case "blockquote": return `<blockquote${W(e.attrs?.textAlign)}>${U(e.content)}</blockquote>`;
932
+ case "codeBlock": return `<pre><code>${Xe(e.content?.map((e) => e.text).join("") ?? "")}</code></pre>`;
933
+ case "bulletList": return `<ul>${(e.content ?? []).map($e).join("")}</ul>`;
934
+ case "orderedList": return `<ol>${(e.content ?? []).map($e).join("")}</ol>`;
935
+ case "taskList": return `<ul class="editor-checklist" data-list="checklist">${(e.content ?? []).map((e) => {
936
+ let t = e.attrs?.checked ? "true" : "false";
937
+ return `<li data-checked="${t}"><span class="checklist-box" contenteditable="false" role="checkbox" aria-checked="${t}" tabindex="-1"></span><span class="checklist-content">${U(e.content)}</span></li>`;
938
+ }).join("")}</ul>`;
939
+ case "table": return `<table class="editor-table"><tbody>${(e.content ?? []).map((e) => `<tr>${(e.content ?? []).map((e) => {
940
+ let t = [];
941
+ e.attrs?.colspan && e.attrs.colspan > 1 && t.push(`colspan="${e.attrs.colspan}"`), e.attrs?.rowspan && e.attrs.rowspan > 1 && t.push(`rowspan="${e.attrs.rowspan}"`);
942
+ let n = [];
943
+ e.attrs?.color && n.push(`color: ${e.attrs.color}`), e.attrs?.backgroundColor && n.push(`background-color: ${e.attrs.backgroundColor}`);
944
+ let r = n.length ? ` style="${n.join("; ")}"` : "";
945
+ return `<td${t.length ? ` ${t.join(" ")}` : ""}${r}>${U(e.content)}</td>`;
946
+ }).join("")}</tr>`).join("")}</tbody></table>`;
947
+ default: return "";
948
+ }
949
+ }
950
+ function $e(e) {
951
+ return `<li>${(e.content ?? []).map((e) => e.type === "paragraph" ? U(e.content) : Qe(e)).join("") || "<br>"}</li>`;
952
+ }
953
+ function et(e) {
954
+ return !e || e.type !== "doc" || !Array.isArray(e.content) ? "<p><br></p>" : e.content.map(Qe).join("") || "<p><br></p>";
955
+ }
956
+ function tt(e) {
957
+ return e && typeof e == "object" && e.type === "doc" && Array.isArray(e.content) ? e : {
958
+ type: "doc",
959
+ content: [{ type: "paragraph" }]
960
+ };
961
+ }
962
+ //#endregion
963
+ //#region src/editor/sanitize.ts
964
+ var nt = /* @__PURE__ */ new Set([
965
+ "P",
966
+ "BR",
967
+ "STRONG",
968
+ "B",
969
+ "EM",
970
+ "I",
971
+ "U",
972
+ "CODE",
973
+ "PRE",
974
+ "H1",
975
+ "H2",
976
+ "H3",
977
+ "UL",
978
+ "OL",
979
+ "LI",
980
+ "BLOCKQUOTE",
981
+ "SPAN",
982
+ "DIV",
983
+ "TABLE",
984
+ "THEAD",
985
+ "TBODY",
986
+ "TR",
987
+ "TH",
988
+ "TD"
989
+ ]), rt = {
990
+ SPAN: /* @__PURE__ */ new Set([
991
+ "style",
992
+ "class",
993
+ "contenteditable",
994
+ "role",
995
+ "aria-checked",
996
+ "tabindex"
997
+ ]),
998
+ DIV: /* @__PURE__ */ new Set([]),
999
+ P: /* @__PURE__ */ new Set(["style"]),
1000
+ H1: /* @__PURE__ */ new Set(["style"]),
1001
+ H2: /* @__PURE__ */ new Set(["style"]),
1002
+ H3: /* @__PURE__ */ new Set(["style"]),
1003
+ BLOCKQUOTE: /* @__PURE__ */ new Set(["style"]),
1004
+ UL: /* @__PURE__ */ new Set([
1005
+ "style",
1006
+ "class",
1007
+ "data-list"
1008
+ ]),
1009
+ OL: /* @__PURE__ */ new Set(["style"]),
1010
+ LI: /* @__PURE__ */ new Set([
1011
+ "style",
1012
+ "class",
1013
+ "data-checked"
1014
+ ]),
1015
+ TABLE: /* @__PURE__ */ new Set(["class"]),
1016
+ TH: /* @__PURE__ */ new Set([
1017
+ "style",
1018
+ "colspan",
1019
+ "rowspan"
1020
+ ]),
1021
+ TD: /* @__PURE__ */ new Set([
1022
+ "style",
1023
+ "colspan",
1024
+ "rowspan"
1025
+ ])
1026
+ }, it = /* @__PURE__ */ new Set([
1027
+ "editor-table",
1028
+ "editor-checklist",
1029
+ "checklist-box",
1030
+ "checklist-content"
1031
+ ]), at = /#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})\b/i, ot = /rgba?\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}(?:\s*,\s*(?:0|1|0?\.\d+))?\s*\)/i;
1032
+ function st(e, t = !1) {
1033
+ let n = [], r = /text-align\s*:\s*(left|center|right)/i.exec(e);
1034
+ if (r && n.push(`text-align: ${r[1].toLowerCase()}`), t) {
1035
+ let t = /(?:^|;)\s*color\s*:\s*([^;]+)/i.exec(e);
1036
+ if (t) {
1037
+ let e = t[1].trim();
1038
+ (at.test(e) || ot.test(e)) && n.push(`color: ${e}`);
1039
+ }
1040
+ let r = /(?:^|;)\s*background-color\s*:\s*([^;]+)/i.exec(e);
1041
+ if (r) {
1042
+ let e = r[1].trim();
1043
+ (at.test(e) || ot.test(e) || e.toLowerCase() === "transparent") && n.push(`background-color: ${e}`);
1044
+ }
1045
+ }
1046
+ return n.join("; ");
1047
+ }
1048
+ function G(e, t) {
1049
+ if (e.nodeType === Node.TEXT_NODE) {
1050
+ t.appendChild(document.createTextNode(e.textContent ?? ""));
1051
+ return;
1052
+ }
1053
+ if (e.nodeType !== Node.ELEMENT_NODE) return;
1054
+ let n = e, r = n.tagName;
1055
+ if (r === "A" || r === "IMG" || r === "FIGURE") {
1056
+ n.childNodes.forEach((e) => G(e, t));
1057
+ return;
1058
+ }
1059
+ if (!nt.has(r)) {
1060
+ n.childNodes.forEach((e) => G(e, t));
1061
+ return;
1062
+ }
1063
+ if (r === "DIV") {
1064
+ let e = document.createElement("p");
1065
+ n.childNodes.forEach((t) => G(t, e)), e.childNodes.length && t.appendChild(e);
1066
+ return;
1067
+ }
1068
+ let i = document.createElement(r.toLowerCase()), a = rt[r] ?? /* @__PURE__ */ new Set();
1069
+ for (let e of Array.from(n.attributes)) {
1070
+ let t = e.name.toLowerCase();
1071
+ if (!(!a.has(t) && !a.has(e.name))) {
1072
+ if (t === "style") {
1073
+ let t = st(e.value, r === "SPAN" || r === "TD" || r === "TH");
1074
+ t && i.setAttribute("style", t);
1075
+ continue;
1076
+ }
1077
+ if (t === "colspan" || t === "rowspan") {
1078
+ let n = Number.parseInt(e.value, 10);
1079
+ Number.isFinite(n) && n >= 1 && n <= 100 && i.setAttribute(t, String(n));
1080
+ continue;
1081
+ }
1082
+ if (t === "class") {
1083
+ let t = e.value.split(/\s+/).filter((e) => it.has(e));
1084
+ t.length && i.setAttribute("class", t.join(" "));
1085
+ continue;
1086
+ }
1087
+ if (t === "data-list") {
1088
+ e.value === "checklist" && i.setAttribute(t, e.value);
1089
+ continue;
1090
+ }
1091
+ if (t === "data-checked") {
1092
+ (e.value === "true" || e.value === "false") && i.setAttribute(t, e.value);
1093
+ continue;
1094
+ }
1095
+ if (t === "contenteditable") {
1096
+ e.value === "false" && i.setAttribute(t, "false");
1097
+ continue;
1098
+ }
1099
+ if (t === "role") {
1100
+ e.value === "checkbox" && i.setAttribute(t, e.value);
1101
+ continue;
1102
+ }
1103
+ if (t === "aria-checked") {
1104
+ (e.value === "true" || e.value === "false") && i.setAttribute(t, e.value);
1105
+ continue;
1106
+ }
1107
+ if (t === "tabindex") {
1108
+ e.value === "-1" && i.setAttribute(t, e.value);
1109
+ continue;
1110
+ }
1111
+ i.setAttribute(t, e.value);
1112
+ }
1113
+ }
1114
+ if (n.childNodes.forEach((e) => G(e, i)), r === "PRE" && !i.querySelector("code")) {
1115
+ let e = document.createElement("code");
1116
+ for (; i.firstChild;) e.appendChild(i.firstChild);
1117
+ i.appendChild(e);
1118
+ }
1119
+ t.appendChild(i);
1120
+ }
1121
+ function K(e) {
1122
+ let t = document.createElement("template");
1123
+ t.innerHTML = e;
1124
+ let n = document.createElement("div");
1125
+ if (t.content.childNodes.forEach((e) => G(e, n)), !n.innerHTML.trim()) return "";
1126
+ if (!Array.from(n.childNodes).some((e) => e.nodeType === Node.ELEMENT_NODE && [
1127
+ "P",
1128
+ "H1",
1129
+ "H2",
1130
+ "H3",
1131
+ "UL",
1132
+ "OL",
1133
+ "PRE",
1134
+ "BLOCKQUOTE",
1135
+ "TABLE"
1136
+ ].includes(e.tagName))) {
1137
+ let e = document.createElement("p");
1138
+ for (; n.firstChild;) e.appendChild(n.firstChild);
1139
+ n.appendChild(e);
1140
+ }
1141
+ return n.innerHTML;
1142
+ }
1143
+ function ct(e) {
1144
+ return e.split(/\n{2,}/).map((e) => `<p>${e.split("\n").map((e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")).join("<br>") || "<br>"}</p>`).join("");
1145
+ }
1146
+ //#endregion
1147
+ //#region src/editor/TableSelection.tsx
1148
+ function lt(e) {
1149
+ return e instanceof Element ? e.closest("td, th") : null;
1150
+ }
1151
+ function q(e) {
1152
+ return Array.from(e.rows);
1153
+ }
1154
+ function J(e) {
1155
+ return Array.from(e.children).filter((e) => e.tagName === "TD" || e.tagName === "TH");
1156
+ }
1157
+ function ut(e) {
1158
+ let t = e.parentElement, n = e.closest("table");
1159
+ if (!t || !n) return null;
1160
+ let r = q(n).indexOf(t), i = J(t).indexOf(e);
1161
+ return r < 0 || i < 0 ? null : {
1162
+ table: n,
1163
+ row: r,
1164
+ col: i
1165
+ };
1166
+ }
1167
+ function dt(e, t, n) {
1168
+ let r = n.querySelectorAll("td, th"), i = null, a = Infinity;
1169
+ for (let n of r) {
1170
+ let r = n.getBoundingClientRect();
1171
+ if (e >= r.left && e <= r.right && t >= r.top && t <= r.bottom) {
1172
+ let e = r.width * r.height;
1173
+ e < a && (i = n, a = e);
1174
+ }
1175
+ }
1176
+ if (i) return i;
1177
+ let o = q(n);
1178
+ if (o.length === 0) return null;
1179
+ let s = 0;
1180
+ for (let e = 0; e < o.length; e++) {
1181
+ let n = o[e].getBoundingClientRect(), r = (n.top + n.bottom) / 2;
1182
+ if (t >= n.top && (s = e), t <= r) {
1183
+ s = e;
1184
+ break;
1185
+ }
1186
+ if (t <= n.bottom) {
1187
+ s = e;
1188
+ break;
1189
+ }
1190
+ }
1191
+ let c = J(o[s]);
1192
+ if (c.length === 0) return null;
1193
+ let l = 0;
1194
+ for (let t = 0; t < c.length; t++) {
1195
+ let n = c[t].getBoundingClientRect();
1196
+ if (e >= n.left && (l = t), e <= n.right) {
1197
+ l = t;
1198
+ break;
1199
+ }
1200
+ }
1201
+ return c[l] ?? null;
1202
+ }
1203
+ function ft(e, t) {
1204
+ let n = ut(e), r = ut(t);
1205
+ if (!n || !r || n.table !== r.table) return [e];
1206
+ let i = Math.min(n.row, r.row), a = Math.max(n.row, r.row), o = Math.min(n.col, r.col), s = Math.max(n.col, r.col), c = q(n.table), l = [];
1207
+ for (let e = i; e <= a; e++) {
1208
+ let t = J(c[e]);
1209
+ for (let e = o; e <= s; e++) t[e] && l.push(t[e]);
1210
+ }
1211
+ return l.length ? l : [e];
1212
+ }
1213
+ function Y(e) {
1214
+ let t = e.map((e) => e.getBoundingClientRect()), n = Math.min(...t.map((e) => e.top)), r = Math.min(...t.map((e) => e.left)), i = Math.max(...t.map((e) => e.right));
1215
+ return {
1216
+ top: n - 40,
1217
+ left: (r + i) / 2
1218
+ };
1219
+ }
1220
+ function pt(e, t) {
1221
+ if (e.rangeCount === 0 || e.isCollapsed) return !1;
1222
+ let n = e.getRangeAt(0), r = (n.commonAncestorContainer.nodeType === Node.ELEMENT_NODE ? n.commonAncestorContainer : n.commonAncestorContainer.parentElement)?.closest?.("td, th");
1223
+ if (!r || !t.contains(r)) return !1;
1224
+ let i = document.createRange();
1225
+ return i.selectNodeContents(r), n.compareBoundaryPoints(Range.START_TO_START, i) <= 0 && n.compareBoundaryPoints(Range.END_TO_END, i) >= 0;
1226
+ }
1227
+ function mt({ editorRef: e, onMerge: n }) {
1228
+ let [o, s] = i([]), [c, l] = i(null), u = r([]), d = r(null), f = r(!1), p = r(!1), m = r({
1229
+ x: 0,
1230
+ y: 0
1231
+ }), h = (e) => {
1232
+ if (u.current.forEach((e) => e.classList.remove("is-cell-selected")), e.length < 2) {
1233
+ u.current = [], s([]), l(null);
1234
+ return;
1235
+ }
1236
+ e.forEach((e) => e.classList.add("is-cell-selected")), u.current = e, s(e), l(Y(e));
1237
+ }, g = () => {
1238
+ u.current.forEach((e) => e.classList.remove("is-cell-selected")), u.current = [], s([]), l(null), d.current = null, f.current = !1, p.current = !1, e.current?.classList.remove("is-table-cell-selecting");
1239
+ };
1240
+ return t(() => {
1241
+ let t = e.current;
1242
+ if (!t) return;
1243
+ let n = (e, n) => {
1244
+ let r = window.getSelection();
1245
+ if (!r) return;
1246
+ let i = document, a = null;
1247
+ if (typeof i.caretRangeFromPoint == "function") a = i.caretRangeFromPoint(e, n);
1248
+ else if (typeof i.caretPositionFromPoint == "function") {
1249
+ let t = i.caretPositionFromPoint(e, n);
1250
+ t && (a = document.createRange(), a.setStart(t.offsetNode, t.offset), a.collapse(!0));
1251
+ }
1252
+ !a || !t.contains(a.commonAncestorContainer) || (r.removeAllRanges(), r.addRange(a));
1253
+ }, r = (e) => {
1254
+ p.current || (p.current = !0, e.classList.add("is-table-cell-selecting"), window.getSelection()?.removeAllRanges());
1255
+ }, i = (e) => {
1256
+ if (e.button !== 0 || e.target?.closest?.(".table-selection-float")) return;
1257
+ let n = lt(e.target);
1258
+ if (!n || !t.contains(n)) {
1259
+ g();
1260
+ return;
1261
+ }
1262
+ u.current.forEach((e) => e.classList.remove("is-cell-selected")), u.current = [], s([]), l(null), t.classList.remove("is-table-cell-selecting"), d.current = n, f.current = !0, p.current = !1, m.current = {
1263
+ x: e.clientX,
1264
+ y: e.clientY
1265
+ };
1266
+ }, a = (e) => {
1267
+ let n = d.current;
1268
+ if (!f.current || !n) return;
1269
+ m.current = {
1270
+ x: e.clientX,
1271
+ y: e.clientY
1272
+ };
1273
+ let i = n.closest("table");
1274
+ if (!i || !t.contains(i)) return;
1275
+ let a = dt(e.clientX, e.clientY, i);
1276
+ if (!p.current) if (a && a !== n) r(t);
1277
+ else return;
1278
+ e.preventDefault(), a && h(ft(n, a));
1279
+ }, o = () => {
1280
+ if (!f.current) return;
1281
+ let e = p.current && u.current.length >= 2;
1282
+ if (f.current = !1, t.classList.remove("is-table-cell-selecting"), !e) {
1283
+ u.current.forEach((e) => e.classList.remove("is-cell-selected")), u.current = [], s([]), l(null);
1284
+ let e = window.getSelection();
1285
+ e && !e.isCollapsed && t.contains(e.anchorNode) && !pt(e, t) || n(m.current.x, m.current.y);
1286
+ }
1287
+ d.current = null, p.current = !1;
1288
+ }, c = (e) => {
1289
+ p.current && f.current && e.preventDefault();
1290
+ }, _ = (e) => {
1291
+ e.key === "Escape" && g();
1292
+ };
1293
+ return t.addEventListener("pointerdown", i), document.addEventListener("pointermove", a, { passive: !1 }), document.addEventListener("pointerup", o), document.addEventListener("selectstart", c), document.addEventListener("keydown", _), () => {
1294
+ t.removeEventListener("pointerdown", i), document.removeEventListener("pointermove", a), document.removeEventListener("pointerup", o), document.removeEventListener("selectstart", c), document.removeEventListener("keydown", _), t.classList.remove("is-table-cell-selecting"), u.current.forEach((e) => e.classList.remove("is-cell-selected"));
1295
+ };
1296
+ }, [e]), t(() => {
1297
+ if (o.length < 2) return;
1298
+ let e = () => l(Y(o));
1299
+ return window.addEventListener("scroll", e, !0), window.addEventListener("resize", e), () => {
1300
+ window.removeEventListener("scroll", e, !0), window.removeEventListener("resize", e);
1301
+ };
1302
+ }, [o]), !c || o.length < 2 ? null : /* @__PURE__ */ a("button", {
1303
+ type: "button",
1304
+ className: "table-selection-float",
1305
+ style: {
1306
+ top: c.top,
1307
+ left: c.left
1308
+ },
1309
+ title: "셀 병합",
1310
+ "aria-label": "셀 병합",
1311
+ onMouseDown: (e) => e.preventDefault(),
1312
+ onClick: () => {
1313
+ n(o), g();
1314
+ },
1315
+ children: /* @__PURE__ */ a(ht, {})
1316
+ });
1317
+ }
1318
+ function ht() {
1319
+ return /* @__PURE__ */ o("svg", {
1320
+ xmlns: "http://www.w3.org/2000/svg",
1321
+ width: "18",
1322
+ height: "18",
1323
+ viewBox: "0 0 24 24",
1324
+ fill: "none",
1325
+ stroke: "currentColor",
1326
+ strokeWidth: "2",
1327
+ strokeLinecap: "round",
1328
+ strokeLinejoin: "round",
1329
+ "aria-hidden": "true",
1330
+ children: [
1331
+ /* @__PURE__ */ a("path", {
1332
+ stroke: "none",
1333
+ d: "M0 0h24v24H0z",
1334
+ fill: "none"
1335
+ }),
1336
+ /* @__PURE__ */ a("path", { d: "M4 6h16" }),
1337
+ /* @__PURE__ */ a("path", { d: "M4 18h16" }),
1338
+ /* @__PURE__ */ a("path", { d: "M4 12h4" }),
1339
+ /* @__PURE__ */ a("path", { d: "M16 12h4" }),
1340
+ /* @__PURE__ */ a("path", { d: "M10 9l-3 3l3 3" }),
1341
+ /* @__PURE__ */ a("path", { d: "M14 9l3 3l-3 3" })
1342
+ ]
1343
+ });
1344
+ }
1345
+ //#endregion
1346
+ //#region src/editor/Toolbar.tsx
1347
+ function gt() {
1348
+ return /* @__PURE__ */ o("svg", {
1349
+ xmlns: "http://www.w3.org/2000/svg",
1350
+ width: "18",
1351
+ height: "18",
1352
+ viewBox: "0 0 24 24",
1353
+ fill: "none",
1354
+ stroke: "currentColor",
1355
+ strokeWidth: "2",
1356
+ strokeLinecap: "round",
1357
+ strokeLinejoin: "round",
1358
+ "aria-hidden": "true",
1359
+ children: [
1360
+ /* @__PURE__ */ a("path", {
1361
+ stroke: "none",
1362
+ d: "M0 0h24v24H0z",
1363
+ fill: "none"
1364
+ }),
1365
+ /* @__PURE__ */ a("path", { d: "M3 7v-2h13v2" }),
1366
+ /* @__PURE__ */ a("path", { d: "M10 5v14" }),
1367
+ /* @__PURE__ */ a("path", { d: "M12 19h-4" }),
1368
+ /* @__PURE__ */ a("path", { d: "M15 13v-1h6v1" }),
1369
+ /* @__PURE__ */ a("path", { d: "M18 12v7" }),
1370
+ /* @__PURE__ */ a("path", { d: "M17 19h2" })
1371
+ ]
1372
+ });
1373
+ }
1374
+ function _t() {
1375
+ return /* @__PURE__ */ o("svg", {
1376
+ xmlns: "http://www.w3.org/2000/svg",
1377
+ width: "18",
1378
+ height: "18",
1379
+ viewBox: "0 0 24 24",
1380
+ fill: "none",
1381
+ stroke: "currentColor",
1382
+ strokeWidth: "2",
1383
+ strokeLinecap: "round",
1384
+ strokeLinejoin: "round",
1385
+ "aria-hidden": "true",
1386
+ children: [
1387
+ /* @__PURE__ */ a("path", {
1388
+ stroke: "none",
1389
+ d: "M0 0h24v24H0z",
1390
+ fill: "none"
1391
+ }),
1392
+ /* @__PURE__ */ a("path", { d: "M19 18v-8l-2 2" }),
1393
+ /* @__PURE__ */ a("path", { d: "M4 6v12" }),
1394
+ /* @__PURE__ */ a("path", { d: "M12 6v12" }),
1395
+ /* @__PURE__ */ a("path", { d: "M11 18h2" }),
1396
+ /* @__PURE__ */ a("path", { d: "M3 18h2" }),
1397
+ /* @__PURE__ */ a("path", { d: "M4 12h8" }),
1398
+ /* @__PURE__ */ a("path", { d: "M3 6h2" }),
1399
+ /* @__PURE__ */ a("path", { d: "M11 6h2" })
1400
+ ]
1401
+ });
1402
+ }
1403
+ function vt() {
1404
+ return /* @__PURE__ */ o("svg", {
1405
+ xmlns: "http://www.w3.org/2000/svg",
1406
+ width: "18",
1407
+ height: "18",
1408
+ viewBox: "0 0 24 24",
1409
+ fill: "none",
1410
+ stroke: "currentColor",
1411
+ strokeWidth: "2",
1412
+ strokeLinecap: "round",
1413
+ strokeLinejoin: "round",
1414
+ "aria-hidden": "true",
1415
+ children: [
1416
+ /* @__PURE__ */ a("path", {
1417
+ stroke: "none",
1418
+ d: "M0 0h24v24H0z",
1419
+ fill: "none"
1420
+ }),
1421
+ /* @__PURE__ */ a("path", { d: "M17 12a2 2 0 1 1 4 0c0 .591 -.417 1.318 -.816 1.858l-3.184 4.143l4 0" }),
1422
+ /* @__PURE__ */ a("path", { d: "M4 6v12" }),
1423
+ /* @__PURE__ */ a("path", { d: "M12 6v12" }),
1424
+ /* @__PURE__ */ a("path", { d: "M11 18h2" }),
1425
+ /* @__PURE__ */ a("path", { d: "M3 18h2" }),
1426
+ /* @__PURE__ */ a("path", { d: "M4 12h8" }),
1427
+ /* @__PURE__ */ a("path", { d: "M3 6h2" }),
1428
+ /* @__PURE__ */ a("path", { d: "M11 6h2" })
1429
+ ]
1430
+ });
1431
+ }
1432
+ function yt() {
1433
+ return /* @__PURE__ */ o("svg", {
1434
+ xmlns: "http://www.w3.org/2000/svg",
1435
+ width: "18",
1436
+ height: "18",
1437
+ viewBox: "0 0 24 24",
1438
+ fill: "none",
1439
+ stroke: "currentColor",
1440
+ strokeWidth: "2",
1441
+ strokeLinecap: "round",
1442
+ strokeLinejoin: "round",
1443
+ "aria-hidden": "true",
1444
+ children: [
1445
+ /* @__PURE__ */ a("path", {
1446
+ stroke: "none",
1447
+ d: "M0 0h24v24H0z",
1448
+ fill: "none"
1449
+ }),
1450
+ /* @__PURE__ */ a("path", { d: "M19 14a2 2 0 1 0 -2 -2" }),
1451
+ /* @__PURE__ */ a("path", { d: "M17 16a2 2 0 1 0 2 -2" }),
1452
+ /* @__PURE__ */ a("path", { d: "M4 6v12" }),
1453
+ /* @__PURE__ */ a("path", { d: "M12 6v12" }),
1454
+ /* @__PURE__ */ a("path", { d: "M11 18h2" }),
1455
+ /* @__PURE__ */ a("path", { d: "M3 18h2" }),
1456
+ /* @__PURE__ */ a("path", { d: "M4 12h8" }),
1457
+ /* @__PURE__ */ a("path", { d: "M3 6h2" }),
1458
+ /* @__PURE__ */ a("path", { d: "M11 6h2" })
1459
+ ]
1460
+ });
1461
+ }
1462
+ var X = [
1463
+ {
1464
+ value: "p",
1465
+ label: "본문",
1466
+ icon: /* @__PURE__ */ a(gt, {}),
1467
+ previewClass: "heading-option-preview--p"
1468
+ },
1469
+ {
1470
+ value: "h1",
1471
+ label: "Heading 1",
1472
+ icon: /* @__PURE__ */ a(_t, {}),
1473
+ previewClass: "heading-option-preview--h1"
1474
+ },
1475
+ {
1476
+ value: "h2",
1477
+ label: "Heading 2",
1478
+ icon: /* @__PURE__ */ a(vt, {}),
1479
+ previewClass: "heading-option-preview--h2"
1480
+ },
1481
+ {
1482
+ value: "h3",
1483
+ label: "Heading 3",
1484
+ icon: /* @__PURE__ */ a(yt, {}),
1485
+ previewClass: "heading-option-preview--h3"
1486
+ }
1487
+ ];
1488
+ function bt(e) {
1489
+ return e === "h1" || e === "h2" || e === "h3" || e === "p" ? e : "p";
1490
+ }
1491
+ var xt = [
1492
+ "#000000",
1493
+ "#6b7280",
1494
+ "#9f1239",
1495
+ "#c2410c",
1496
+ "#a16207",
1497
+ "#15803d",
1498
+ "#1d4ed8",
1499
+ "#7c3aed",
1500
+ "#db2777",
1501
+ "#dc2626"
1502
+ ], St = [
1503
+ null,
1504
+ "#f3f4f6",
1505
+ "#fce7f3",
1506
+ "#ffedd5",
1507
+ "#fef9c3",
1508
+ "#dcfce7",
1509
+ "#dbeafe",
1510
+ "#ede9fe",
1511
+ "#fbcfe8",
1512
+ "#fee2e2"
1513
+ ];
1514
+ function Ct(e, t) {
1515
+ if (!e && !t) return !0;
1516
+ if (!e || !t) return !1;
1517
+ let n = (e) => {
1518
+ let t = document.createElement("span");
1519
+ return t.style.color = e, t.style.color;
1520
+ };
1521
+ try {
1522
+ return n(e) === n(t);
1523
+ } catch {
1524
+ return e.toLowerCase() === t.toLowerCase();
1525
+ }
1526
+ }
1527
+ function wt() {
1528
+ return /* @__PURE__ */ o("svg", {
1529
+ xmlns: "http://www.w3.org/2000/svg",
1530
+ width: "24",
1531
+ height: "24",
1532
+ viewBox: "0 0 24 24",
1533
+ fill: "currentColor",
1534
+ "aria-hidden": "true",
1535
+ children: [
1536
+ /* @__PURE__ */ a("path", {
1537
+ stroke: "none",
1538
+ d: "M0 0h24v24H0z",
1539
+ fill: "none"
1540
+ }),
1541
+ /* @__PURE__ */ a("path", { d: "M21 6a1 1 0 0 1 -1 1h-10a1 1 0 1 1 0 -2h10a1 1 0 0 1 1 1" }),
1542
+ /* @__PURE__ */ a("path", { d: "M21 12a1 1 0 0 1 -1 1h-10a1 1 0 0 1 0 -2h10a1 1 0 0 1 1 1" }),
1543
+ /* @__PURE__ */ a("path", { d: "M21 18a1 1 0 0 1 -1 1h-10a1 1 0 0 1 0 -2h10a1 1 0 0 1 1 1" }),
1544
+ /* @__PURE__ */ a("path", { d: "M7 5.995v.02c0 1.099 -.895 1.99 -2 1.99s-2 -.891 -2 -1.99v-.02c0 -1.099 .895 -1.99 2 -1.99s2 .891 2 1.99" }),
1545
+ /* @__PURE__ */ a("path", { d: "M7 11.995v.02c0 1.099 -.895 1.99 -2 1.99s-2 -.891 -2 -1.99v-.02c0 -1.099 .895 -1.99 2 -1.99s2 .891 2 1.99" }),
1546
+ /* @__PURE__ */ a("path", { d: "M7 17.995v.02c0 1.099 -.895 1.99 -2 1.99s-2 -.891 -2 -1.99v-.02c0 -1.099 .895 -1.99 2 -1.99s2 .891 2 1.99" })
1547
+ ]
1548
+ });
1549
+ }
1550
+ function Tt() {
1551
+ return /* @__PURE__ */ o("svg", {
1552
+ xmlns: "http://www.w3.org/2000/svg",
1553
+ width: "24",
1554
+ height: "24",
1555
+ viewBox: "0 0 24 24",
1556
+ fill: "none",
1557
+ stroke: "currentColor",
1558
+ strokeWidth: "2",
1559
+ strokeLinecap: "round",
1560
+ strokeLinejoin: "round",
1561
+ "aria-hidden": "true",
1562
+ children: [
1563
+ /* @__PURE__ */ a("path", {
1564
+ stroke: "none",
1565
+ d: "M0 0h24v24H0z",
1566
+ fill: "none"
1567
+ }),
1568
+ /* @__PURE__ */ a("path", { d: "M11 6h9" }),
1569
+ /* @__PURE__ */ a("path", { d: "M11 12h9" }),
1570
+ /* @__PURE__ */ a("path", { d: "M12 18h8" }),
1571
+ /* @__PURE__ */ a("path", { d: "M4 16a2 2 0 1 1 4 0c0 .591 -.5 1 -1 1.5l-3 2.5h4" }),
1572
+ /* @__PURE__ */ a("path", { d: "M6 10v-6l-2 2" })
1573
+ ]
1574
+ });
1575
+ }
1576
+ function Et() {
1577
+ return /* @__PURE__ */ o("svg", {
1578
+ xmlns: "http://www.w3.org/2000/svg",
1579
+ width: "16",
1580
+ height: "16",
1581
+ fill: "currentColor",
1582
+ viewBox: "0 0 16 16",
1583
+ "aria-hidden": "true",
1584
+ children: [/* @__PURE__ */ a("path", {
1585
+ fillRule: "evenodd",
1586
+ d: "M4.54 2.981h-2a.5.5 0 0 0-.5.5v2a.5.5 0 0 0 .5.5h2a.5.5 0 0 0 .5-.5v-2a.5.5 0 0 0-.5-.5Zm-2-1a1.5 1.5 0 0 0-1.5 1.5v2a1.5 1.5 0 0 0 1.5 1.5h2a1.5 1.5 0 0 0 1.5-1.5v-2a1.5 1.5 0 0 0-1.5-1.5h-2Zm2 8.015h-2a.5.5 0 0 0-.5.5v2a.5.5 0 0 0 .5.5h2a.5.5 0 0 0 .5-.5v-2a.5.5 0 0 0-.5-.5Zm-2-1a1.5 1.5 0 0 0-1.5 1.5v2a1.5 1.5 0 0 0 1.5 1.5h2a1.5 1.5 0 0 0 1.5-1.5v-2a1.5 1.5 0 0 0-1.5-1.5h-2Z",
1587
+ clipRule: "evenodd"
1588
+ }), /* @__PURE__ */ a("path", { d: "M8.007 4.481c0-.345.28-.625.625-.625h5.739a.625.625 0 1 1 0 1.25H8.63a.625.625 0 0 1-.624-.625Zm0 7.015c0-.346.28-.625.625-.625h5.739a.625.625 0 1 1 0 1.25H8.63a.625.625 0 0 1-.624-.625Z" })]
1589
+ });
1590
+ }
1591
+ function Dt() {
1592
+ return /* @__PURE__ */ a("svg", {
1593
+ width: "18",
1594
+ height: "18",
1595
+ viewBox: "0 0 24 24",
1596
+ fill: "currentColor",
1597
+ xmlns: "http://www.w3.org/2000/svg",
1598
+ "aria-hidden": "true",
1599
+ children: /* @__PURE__ */ a("path", {
1600
+ fillRule: "evenodd",
1601
+ clipRule: "evenodd",
1602
+ d: "M6 2.5C5.17157 2.5 4.5 3.17157 4.5 4V20C4.5 20.8284 5.17157 21.5 6 21.5H15C16.4587 21.5 17.8576 20.9205 18.8891 19.8891C19.9205 18.8576 20.5 17.4587 20.5 16C20.5 14.5413 19.9205 13.1424 18.8891 12.1109C18.6781 11.9 18.4518 11.7079 18.2128 11.5359C19.041 10.5492 19.5 9.29829 19.5 8C19.5 6.54131 18.9205 5.14236 17.8891 4.11091C16.8576 3.07946 15.4587 2.5 14 2.5H6ZM14 10.5C14.663 10.5 15.2989 10.2366 15.7678 9.76777C16.2366 9.29893 16.5 8.66304 16.5 8C16.5 7.33696 16.2366 6.70107 15.7678 6.23223C15.2989 5.76339 14.663 5.5 14 5.5H7.5V10.5H14ZM7.5 18.5V13.5H15C15.663 13.5 16.2989 13.7634 16.7678 14.2322C17.2366 14.7011 17.5 15.337 17.5 16C17.5 16.663 17.2366 17.2989 16.7678 17.7678C16.2989 18.2366 15.663 18.5 15 18.5H7.5Z",
1603
+ fill: "currentColor"
1604
+ })
1605
+ });
1606
+ }
1607
+ function Ot() {
1608
+ return /* @__PURE__ */ a("svg", {
1609
+ width: "18",
1610
+ height: "18",
1611
+ viewBox: "0 0 24 24",
1612
+ fill: "currentColor",
1613
+ xmlns: "http://www.w3.org/2000/svg",
1614
+ "aria-hidden": "true",
1615
+ children: /* @__PURE__ */ a("path", {
1616
+ fillRule: "evenodd",
1617
+ clipRule: "evenodd",
1618
+ d: "M15 20H7V18H9.92661L12.0425 6H9V4H17V6H14.0734L11.9575 18H15V20Z",
1619
+ fill: "currentColor"
1620
+ })
1621
+ });
1622
+ }
1623
+ function kt() {
1624
+ return /* @__PURE__ */ a("svg", {
1625
+ width: "18",
1626
+ height: "18",
1627
+ viewBox: "0 0 24 24",
1628
+ fill: "currentColor",
1629
+ xmlns: "http://www.w3.org/2000/svg",
1630
+ "aria-hidden": "true",
1631
+ children: /* @__PURE__ */ a("path", {
1632
+ fillRule: "evenodd",
1633
+ clipRule: "evenodd",
1634
+ d: "M7 4C7 3.44772 6.55228 3 6 3C5.44772 3 5 3.44772 5 4V10C5 11.8565 5.7375 13.637 7.05025 14.9497C8.36301 16.2625 10.1435 17 12 17C13.8565 17 15.637 16.2625 16.9497 14.9497C18.2625 13.637 19 11.8565 19 10V4C19 3.44772 18.5523 3 18 3C17.4477 3 17 3.44772 17 4V10C17 11.3261 16.4732 12.5979 15.5355 13.5355C14.5979 14.4732 13.3261 15 12 15C10.6739 15 9.40215 14.4732 8.46447 13.5355C7.52678 12.5979 7 11.3261 7 10V4ZM4 19C3.44772 19 3 19.4477 3 20C3 20.5523 3.44772 21 4 21H20C20.5523 21 21 20.5523 21 20C21 19.4477 20.5523 19 20 19H4Z",
1635
+ fill: "currentColor"
1636
+ })
1637
+ });
1638
+ }
1639
+ function At() {
1640
+ return /* @__PURE__ */ o("svg", {
1641
+ width: "18",
1642
+ height: "18",
1643
+ viewBox: "0 0 24 24",
1644
+ fill: "currentColor",
1645
+ xmlns: "http://www.w3.org/2000/svg",
1646
+ "aria-hidden": "true",
1647
+ children: [
1648
+ /* @__PURE__ */ a("path", {
1649
+ d: "M15.4545 4.2983C15.6192 3.77115 15.3254 3.21028 14.7983 3.04554C14.2712 2.88081 13.7103 3.1746 13.5455 3.70175L8.54554 19.7017C8.38081 20.2289 8.6746 20.7898 9.20175 20.9545C9.72889 21.1192 10.2898 20.8254 10.4545 20.2983L15.4545 4.2983Z",
1650
+ fill: "currentColor"
1651
+ }),
1652
+ /* @__PURE__ */ a("path", {
1653
+ d: "M6.70711 7.29289C7.09763 7.68342 7.09763 8.31658 6.70711 8.70711L3.41421 12L6.70711 15.2929C7.09763 15.6834 7.09763 16.3166 6.70711 16.7071C6.31658 17.0976 5.68342 17.0976 5.29289 16.7071L1.29289 12.7071C0.902369 12.3166 0.902369 11.6834 1.29289 11.2929L5.29289 7.29289C5.68342 6.90237 6.31658 6.90237 6.70711 7.29289Z",
1654
+ fill: "currentColor"
1655
+ }),
1656
+ /* @__PURE__ */ a("path", {
1657
+ d: "M17.2929 7.29289C17.6834 6.90237 18.3166 6.90237 18.7071 7.29289L22.7071 11.2929C23.0976 11.6834 23.0976 12.3166 22.7071 12.7071L18.7071 16.7071C18.3166 17.0976 17.6834 17.0976 17.2929 16.7071C16.9024 16.3166 16.9024 15.6834 17.2929 15.2929L20.5858 12L17.2929 8.70711C16.9024 8.31658 16.9024 7.68342 17.2929 7.29289Z",
1658
+ fill: "currentColor"
1659
+ })
1660
+ ]
1661
+ });
1662
+ }
1663
+ function jt() {
1664
+ return /* @__PURE__ */ o("svg", {
1665
+ xmlns: "http://www.w3.org/2000/svg",
1666
+ width: "18",
1667
+ height: "18",
1668
+ viewBox: "0 0 24 24",
1669
+ fill: "none",
1670
+ stroke: "currentColor",
1671
+ strokeWidth: "2",
1672
+ strokeLinecap: "round",
1673
+ strokeLinejoin: "round",
1674
+ "aria-hidden": "true",
1675
+ children: [
1676
+ /* @__PURE__ */ a("path", {
1677
+ stroke: "none",
1678
+ d: "M0 0h24v24H0z",
1679
+ fill: "none"
1680
+ }),
1681
+ /* @__PURE__ */ a("path", { d: "M3 5a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-14z" }),
1682
+ /* @__PURE__ */ a("path", { d: "M3 10h18" }),
1683
+ /* @__PURE__ */ a("path", { d: "M10 3v18" })
1684
+ ]
1685
+ });
1686
+ }
1687
+ var Z = 10;
1688
+ function Mt({ active: e, onInsert: n }) {
1689
+ let [s, c] = i(!1), [l, u] = i(0), [d, f] = i(0), [p, m] = i(!1), h = r(null);
1690
+ t(() => {
1691
+ if (!s) return;
1692
+ let e = (e) => {
1693
+ h.current?.contains(e.target) || (c(!1), m(!1), u(0), f(0));
1694
+ }, t = (e) => {
1695
+ e.key === "Escape" && (c(!1), m(!1), u(0), f(0));
1696
+ }, n = () => m(!1), r = window.setTimeout(() => {
1697
+ document.addEventListener("pointerdown", e);
1698
+ }, 0);
1699
+ return document.addEventListener("keydown", t), document.addEventListener("pointerup", n), () => {
1700
+ window.clearTimeout(r), document.removeEventListener("pointerdown", e), document.removeEventListener("keydown", t), document.removeEventListener("pointerup", n);
1701
+ };
1702
+ }, [s]);
1703
+ let g = (e, t) => {
1704
+ u(e), f(t);
1705
+ }, _ = (e, t) => {
1706
+ e < 1 || t < 1 || (n(e, t), c(!1), m(!1), u(0), f(0));
1707
+ }, v = l > 0 && d > 0 ? `${l} × ${d}` : "테이블 크기 선택";
1708
+ return /* @__PURE__ */ o("div", {
1709
+ className: "toolbar-dropdown table-picker",
1710
+ ref: h,
1711
+ children: [/* @__PURE__ */ a("button", {
1712
+ type: "button",
1713
+ className: `toolbar-btn${s || e ? " is-active" : ""}`,
1714
+ title: "테이블 삽입",
1715
+ "aria-label": "테이블 삽입",
1716
+ "aria-haspopup": "dialog",
1717
+ "aria-expanded": s,
1718
+ onMouseDown: (e) => e.preventDefault(),
1719
+ onClick: () => {
1720
+ c((e) => !e), u(0), f(0), m(!1);
1721
+ },
1722
+ children: /* @__PURE__ */ a(jt, {})
1723
+ }), s && /* @__PURE__ */ o("div", {
1724
+ className: "table-picker-menu",
1725
+ role: "dialog",
1726
+ "aria-label": "테이블 크기 선택",
1727
+ onMouseDown: (e) => e.preventDefault(),
1728
+ children: [/* @__PURE__ */ a("p", {
1729
+ className: "table-picker-label",
1730
+ children: v
1731
+ }), /* @__PURE__ */ a("div", {
1732
+ className: "table-picker-grid",
1733
+ onPointerLeave: () => {
1734
+ p || (u(0), f(0));
1735
+ },
1736
+ children: Array.from({ length: Z * Z }, (e, t) => {
1737
+ let n = Math.floor(t / Z) + 1, r = t % Z + 1;
1738
+ return /* @__PURE__ */ a("button", {
1739
+ type: "button",
1740
+ className: `table-picker-cell${n <= l && r <= d ? " is-selected" : ""}`,
1741
+ "aria-label": `${n}행 ${r}열`,
1742
+ onPointerEnter: () => g(n, r),
1743
+ onPointerDown: (e) => {
1744
+ e.preventDefault(), m(!0), g(n, r);
1745
+ },
1746
+ onPointerUp: (e) => {
1747
+ e.preventDefault(), _(n, r);
1748
+ }
1749
+ }, `${n}-${r}`);
1750
+ })
1751
+ })]
1752
+ })]
1753
+ });
1754
+ }
1755
+ function Nt() {
1756
+ return /* @__PURE__ */ o("svg", {
1757
+ xmlns: "http://www.w3.org/2000/svg",
1758
+ width: "18",
1759
+ height: "18",
1760
+ viewBox: "0 0 24 24",
1761
+ fill: "none",
1762
+ stroke: "currentColor",
1763
+ strokeWidth: "2",
1764
+ strokeLinecap: "round",
1765
+ strokeLinejoin: "round",
1766
+ "aria-hidden": "true",
1767
+ children: [
1768
+ /* @__PURE__ */ a("path", {
1769
+ stroke: "none",
1770
+ d: "M0 0h24v24H0z",
1771
+ fill: "none"
1772
+ }),
1773
+ /* @__PURE__ */ a("path", { d: "M4 6l16 0" }),
1774
+ /* @__PURE__ */ a("path", { d: "M4 12l10 0" }),
1775
+ /* @__PURE__ */ a("path", { d: "M4 18l14 0" })
1776
+ ]
1777
+ });
1778
+ }
1779
+ function Pt() {
1780
+ return /* @__PURE__ */ o("svg", {
1781
+ xmlns: "http://www.w3.org/2000/svg",
1782
+ width: "18",
1783
+ height: "18",
1784
+ viewBox: "0 0 24 24",
1785
+ fill: "none",
1786
+ stroke: "currentColor",
1787
+ strokeWidth: "2",
1788
+ strokeLinecap: "round",
1789
+ strokeLinejoin: "round",
1790
+ "aria-hidden": "true",
1791
+ children: [
1792
+ /* @__PURE__ */ a("path", {
1793
+ stroke: "none",
1794
+ d: "M0 0h24v24H0z",
1795
+ fill: "none"
1796
+ }),
1797
+ /* @__PURE__ */ a("path", { d: "M4 6l16 0" }),
1798
+ /* @__PURE__ */ a("path", { d: "M8 12l8 0" }),
1799
+ /* @__PURE__ */ a("path", { d: "M6 18l12 0" })
1800
+ ]
1801
+ });
1802
+ }
1803
+ function Ft() {
1804
+ return /* @__PURE__ */ o("svg", {
1805
+ xmlns: "http://www.w3.org/2000/svg",
1806
+ width: "18",
1807
+ height: "18",
1808
+ viewBox: "0 0 24 24",
1809
+ fill: "none",
1810
+ stroke: "currentColor",
1811
+ strokeWidth: "2",
1812
+ strokeLinecap: "round",
1813
+ strokeLinejoin: "round",
1814
+ "aria-hidden": "true",
1815
+ children: [
1816
+ /* @__PURE__ */ a("path", {
1817
+ stroke: "none",
1818
+ d: "M0 0h24v24H0z",
1819
+ fill: "none"
1820
+ }),
1821
+ /* @__PURE__ */ a("path", { d: "M4 6l16 0" }),
1822
+ /* @__PURE__ */ a("path", { d: "M10 12l10 0" }),
1823
+ /* @__PURE__ */ a("path", { d: "M6 18l14 0" })
1824
+ ]
1825
+ });
1826
+ }
1827
+ function Q({ label: e, title: t, active: n, disabled: r, onClick: i }) {
1828
+ return /* @__PURE__ */ a("button", {
1829
+ type: "button",
1830
+ className: `toolbar-btn${typeof e == "string" ? " toolbar-btn--text" : ""}${n ? " is-active" : ""}`,
1831
+ title: t,
1832
+ "aria-label": t,
1833
+ "aria-pressed": n,
1834
+ disabled: r,
1835
+ onMouseDown: (e) => e.preventDefault(),
1836
+ onClick: i,
1837
+ children: e
1838
+ });
1839
+ }
1840
+ function $() {
1841
+ return /* @__PURE__ */ a("span", {
1842
+ className: "toolbar-sep",
1843
+ "aria-hidden": "true"
1844
+ });
1845
+ }
1846
+ function It({ color: e }) {
1847
+ return /* @__PURE__ */ o("span", {
1848
+ className: "color-trigger-icon",
1849
+ children: [/* @__PURE__ */ a("span", {
1850
+ className: "color-trigger-letter",
1851
+ children: "A"
1852
+ }), /* @__PURE__ */ a("span", {
1853
+ className: "color-trigger-bar",
1854
+ style: { background: e || "currentColor" }
1855
+ })]
1856
+ });
1857
+ }
1858
+ function Lt({ textColor: e, highlightColor: n, onTextColor: s, onHighlightColor: c }) {
1859
+ let [l, u] = i(!1), d = r(null);
1860
+ return t(() => {
1861
+ if (!l) return;
1862
+ let e = (e) => {
1863
+ d.current?.contains(e.target) || u(!1);
1864
+ }, t = (e) => {
1865
+ e.key === "Escape" && u(!1);
1866
+ }, n = window.setTimeout(() => {
1867
+ document.addEventListener("pointerdown", e);
1868
+ }, 0);
1869
+ return document.addEventListener("keydown", t), () => {
1870
+ window.clearTimeout(n), document.removeEventListener("pointerdown", e), document.removeEventListener("keydown", t);
1871
+ };
1872
+ }, [l]), /* @__PURE__ */ o("div", {
1873
+ className: "toolbar-dropdown color-picker",
1874
+ ref: d,
1875
+ children: [/* @__PURE__ */ o("button", {
1876
+ type: "button",
1877
+ className: `toolbar-btn toolbar-dropdown-trigger${l ? " is-active" : ""}`,
1878
+ title: "텍스트 색상",
1879
+ "aria-label": "텍스트 색상",
1880
+ "aria-haspopup": "dialog",
1881
+ "aria-expanded": l,
1882
+ onMouseDown: (e) => e.preventDefault(),
1883
+ onClick: () => u((e) => !e),
1884
+ children: [/* @__PURE__ */ a(It, { color: e }), /* @__PURE__ */ a("svg", {
1885
+ width: "14",
1886
+ height: "14",
1887
+ viewBox: "0 0 24 24",
1888
+ fill: "none",
1889
+ stroke: "currentColor",
1890
+ strokeWidth: "2",
1891
+ strokeLinecap: "round",
1892
+ strokeLinejoin: "round",
1893
+ "aria-hidden": "true",
1894
+ children: /* @__PURE__ */ a("path", { d: "M6 9l6 6l6 -6" })
1895
+ })]
1896
+ }), l && /* @__PURE__ */ o("div", {
1897
+ className: "color-picker-menu",
1898
+ role: "dialog",
1899
+ "aria-label": "색상 선택",
1900
+ children: [/* @__PURE__ */ o("div", {
1901
+ className: "color-picker-section",
1902
+ children: [/* @__PURE__ */ a("p", {
1903
+ className: "color-picker-title",
1904
+ children: "글자색"
1905
+ }), /* @__PURE__ */ a("div", {
1906
+ className: "color-picker-grid",
1907
+ children: xt.map((t) => /* @__PURE__ */ a("button", {
1908
+ type: "button",
1909
+ className: `color-swatch color-swatch--text${Ct(e, t) ? " is-active" : ""}`,
1910
+ title: t,
1911
+ "aria-label": `글자색 ${t}`,
1912
+ onMouseDown: (e) => e.preventDefault(),
1913
+ onClick: () => {
1914
+ s(t), u(!1);
1915
+ },
1916
+ children: /* @__PURE__ */ a("span", {
1917
+ className: "color-swatch-face",
1918
+ style: {
1919
+ color: t,
1920
+ "--swatch-color": t
1921
+ },
1922
+ children: "A"
1923
+ })
1924
+ }, t))
1925
+ })]
1926
+ }), /* @__PURE__ */ o("div", {
1927
+ className: "color-picker-section",
1928
+ children: [/* @__PURE__ */ a("p", {
1929
+ className: "color-picker-title",
1930
+ children: "배경색"
1931
+ }), /* @__PURE__ */ a("div", {
1932
+ className: "color-picker-grid",
1933
+ children: St.map((e, t) => /* @__PURE__ */ a("button", {
1934
+ type: "button",
1935
+ className: `color-swatch color-swatch--highlight${Ct(n, e) || !n && t === 0 ? " is-active" : ""}`,
1936
+ title: e ?? "없음",
1937
+ "aria-label": e ? `배경색 ${e}` : "배경색 없음",
1938
+ onMouseDown: (e) => e.preventDefault(),
1939
+ onClick: () => {
1940
+ c(e), u(!1);
1941
+ },
1942
+ children: /* @__PURE__ */ a("span", {
1943
+ className: "color-swatch-face",
1944
+ style: {
1945
+ background: e ?? "#ffffff",
1946
+ "--swatch-color": e ?? "#d1d5db"
1947
+ }
1948
+ })
1949
+ }, e ?? "none"))
1950
+ })]
1951
+ })]
1952
+ })]
1953
+ });
1954
+ }
1955
+ function Rt({ block: e, onSelect: n }) {
1956
+ let [s, c] = i(!1), l = r(null), u = bt(e), d = X.find((e) => e.value === u) ?? X[0];
1957
+ return t(() => {
1958
+ if (!s) return;
1959
+ let e = (e) => {
1960
+ l.current?.contains(e.target) || c(!1);
1961
+ }, t = (e) => {
1962
+ e.key === "Escape" && c(!1);
1963
+ }, n = window.setTimeout(() => {
1964
+ document.addEventListener("pointerdown", e);
1965
+ }, 0);
1966
+ return document.addEventListener("keydown", t), () => {
1967
+ window.clearTimeout(n), document.removeEventListener("pointerdown", e), document.removeEventListener("keydown", t);
1968
+ };
1969
+ }, [s]), /* @__PURE__ */ o("div", {
1970
+ className: "toolbar-dropdown",
1971
+ ref: l,
1972
+ children: [/* @__PURE__ */ o("button", {
1973
+ type: "button",
1974
+ className: `toolbar-btn toolbar-dropdown-trigger heading-dropdown-trigger${s ? " is-active" : ""}`,
1975
+ title: "문단 스타일",
1976
+ "aria-label": `문단 스타일: ${d.label}`,
1977
+ "aria-haspopup": "listbox",
1978
+ "aria-expanded": s,
1979
+ onMouseDown: (e) => e.preventDefault(),
1980
+ onClick: () => c((e) => !e),
1981
+ children: [
1982
+ /* @__PURE__ */ a("span", {
1983
+ className: "heading-dropdown-trigger-icon",
1984
+ "aria-hidden": "true",
1985
+ children: d.icon
1986
+ }),
1987
+ /* @__PURE__ */ a("span", {
1988
+ className: "heading-dropdown-value",
1989
+ children: d.label
1990
+ }),
1991
+ /* @__PURE__ */ a("svg", {
1992
+ width: "14",
1993
+ height: "14",
1994
+ viewBox: "0 0 24 24",
1995
+ fill: "none",
1996
+ stroke: "currentColor",
1997
+ strokeWidth: "2",
1998
+ strokeLinecap: "round",
1999
+ strokeLinejoin: "round",
2000
+ "aria-hidden": "true",
2001
+ children: /* @__PURE__ */ a("path", { d: "M6 9l6 6l6 -6" })
2002
+ })
2003
+ ]
2004
+ }), s && /* @__PURE__ */ a("ul", {
2005
+ className: "toolbar-dropdown-menu heading-dropdown-menu",
2006
+ role: "listbox",
2007
+ "aria-label": "문단 스타일",
2008
+ children: X.map((e) => /* @__PURE__ */ a("li", {
2009
+ role: "option",
2010
+ "aria-selected": u === e.value,
2011
+ children: /* @__PURE__ */ o("button", {
2012
+ type: "button",
2013
+ className: `toolbar-dropdown-item heading-dropdown-item${u === e.value ? " is-active" : ""}`,
2014
+ title: e.label,
2015
+ "aria-label": e.label,
2016
+ onMouseDown: (e) => e.preventDefault(),
2017
+ onClick: () => {
2018
+ n(e.value), c(!1);
2019
+ },
2020
+ children: [/* @__PURE__ */ a("span", {
2021
+ className: "heading-option-icon",
2022
+ "aria-hidden": "true",
2023
+ children: e.icon
2024
+ }), /* @__PURE__ */ a("span", {
2025
+ className: `heading-option-preview ${e.previewClass}`,
2026
+ children: e.label
2027
+ })]
2028
+ })
2029
+ }, e.value))
2030
+ })]
2031
+ });
2032
+ }
2033
+ function zt({ active: e, onCommand: t }) {
2034
+ return /* @__PURE__ */ o("div", {
2035
+ className: "toolbar",
2036
+ role: "toolbar",
2037
+ "aria-label": "서식 도구",
2038
+ children: [
2039
+ /* @__PURE__ */ a(Rt, {
2040
+ block: e.block,
2041
+ onSelect: (e) => t({
2042
+ type: "block",
2043
+ format: e
2044
+ })
2045
+ }),
2046
+ /* @__PURE__ */ a($, {}),
2047
+ /* @__PURE__ */ a(Q, {
2048
+ label: /* @__PURE__ */ a(Dt, {}),
2049
+ title: "굵게",
2050
+ active: e.bold,
2051
+ onClick: () => t({
2052
+ type: "inline",
2053
+ mark: "bold"
2054
+ })
2055
+ }),
2056
+ /* @__PURE__ */ a(Q, {
2057
+ label: /* @__PURE__ */ a(Ot, {}),
2058
+ title: "기울임",
2059
+ active: e.italic,
2060
+ onClick: () => t({
2061
+ type: "inline",
2062
+ mark: "italic"
2063
+ })
2064
+ }),
2065
+ /* @__PURE__ */ a(Q, {
2066
+ label: /* @__PURE__ */ a(kt, {}),
2067
+ title: "밑줄",
2068
+ active: e.underline,
2069
+ onClick: () => t({
2070
+ type: "inline",
2071
+ mark: "underline"
2072
+ })
2073
+ }),
2074
+ /* @__PURE__ */ a(Lt, {
2075
+ textColor: e.textColor,
2076
+ highlightColor: e.highlightColor,
2077
+ onTextColor: (e) => t({
2078
+ type: "textColor",
2079
+ color: e
2080
+ }),
2081
+ onHighlightColor: (e) => t({
2082
+ type: "highlightColor",
2083
+ color: e
2084
+ })
2085
+ }),
2086
+ /* @__PURE__ */ a($, {}),
2087
+ /* @__PURE__ */ a(Q, {
2088
+ label: /* @__PURE__ */ a(wt, {}),
2089
+ title: "글머리 기호 목록",
2090
+ active: e.inList === "ul",
2091
+ onClick: () => t({
2092
+ type: "block",
2093
+ format: "ul"
2094
+ })
2095
+ }),
2096
+ /* @__PURE__ */ a(Q, {
2097
+ label: /* @__PURE__ */ a(Tt, {}),
2098
+ title: "번호 매기기 목록",
2099
+ active: e.inList === "ol",
2100
+ onClick: () => t({
2101
+ type: "block",
2102
+ format: "ol"
2103
+ })
2104
+ }),
2105
+ /* @__PURE__ */ a(Q, {
2106
+ label: /* @__PURE__ */ a(Et, {}),
2107
+ title: "체크리스트",
2108
+ active: e.inList === "checklist",
2109
+ onClick: () => t({
2110
+ type: "block",
2111
+ format: "checklist"
2112
+ })
2113
+ }),
2114
+ /* @__PURE__ */ a(Q, {
2115
+ label: /* @__PURE__ */ a(At, {}),
2116
+ title: "코드 블록",
2117
+ active: e.block === "pre",
2118
+ onClick: () => t({
2119
+ type: "block",
2120
+ format: "pre"
2121
+ })
2122
+ }),
2123
+ /* @__PURE__ */ a(Mt, {
2124
+ active: e.inTable,
2125
+ onInsert: (e, n) => t({
2126
+ type: "insertTable",
2127
+ rows: e,
2128
+ cols: n
2129
+ })
2130
+ }),
2131
+ /* @__PURE__ */ a($, {}),
2132
+ /* @__PURE__ */ a(Q, {
2133
+ label: /* @__PURE__ */ a(Nt, {}),
2134
+ title: "왼쪽 정렬",
2135
+ active: e.align === "left",
2136
+ onClick: () => t({
2137
+ type: "align",
2138
+ align: "left"
2139
+ })
2140
+ }),
2141
+ /* @__PURE__ */ a(Q, {
2142
+ label: /* @__PURE__ */ a(Pt, {}),
2143
+ title: "가운데 정렬",
2144
+ active: e.align === "center",
2145
+ onClick: () => t({
2146
+ type: "align",
2147
+ align: "center"
2148
+ })
2149
+ }),
2150
+ /* @__PURE__ */ a(Q, {
2151
+ label: /* @__PURE__ */ a(Ft, {}),
2152
+ title: "오른쪽 정렬",
2153
+ active: e.align === "right",
2154
+ onClick: () => t({
2155
+ type: "align",
2156
+ align: "right"
2157
+ })
2158
+ })
2159
+ ]
2160
+ });
2161
+ }
2162
+ //#endregion
2163
+ //#region src/editor/Editor.tsx
2164
+ var Bt = "<p><br></p>";
2165
+ function Vt(e) {
2166
+ return e.textContent?.replace(/\u200B/g, "").trim() ?? "" ? !1 : !e.querySelector("table, img, pre, ul, ol, blockquote, h1, h2, h3");
2167
+ }
2168
+ var Ht = {
2169
+ bold: !1,
2170
+ italic: !1,
2171
+ underline: !1,
2172
+ block: "p",
2173
+ align: "left",
2174
+ inList: null,
2175
+ textColor: null,
2176
+ highlightColor: null,
2177
+ inTable: !1
2178
+ }, Ut = e(function({ initialHTML: e = Bt, className: s, style: c, theme: l, toolbarClassName: d, toolbarStyle: f, contentClassName: p, contentStyle: m }, h) {
2179
+ let g = r(null), _ = r(new ze()), [v, y] = i(Ht), [b, ee] = i(!0), x = () => {
2180
+ let e = g.current;
2181
+ e && ee(Vt(e));
2182
+ }, S = () => {
2183
+ let e = g.current;
2184
+ e && (y(te(e)), x());
2185
+ }, C = (e) => {
2186
+ let t = g.current;
2187
+ t && (t.innerHTML = K(e) || Bt, _.current.reset(t.innerHTML), S());
2188
+ }, w = (e = !1) => {
2189
+ let t = g.current;
2190
+ t && (_.current.push(t, e), S());
2191
+ };
2192
+ n(h, () => ({
2193
+ getHtml: () => g.current?.innerHTML ?? "",
2194
+ setHtml: (e) => C(e),
2195
+ getJson: () => {
2196
+ let e = g.current;
2197
+ return e ? H(e) : {
2198
+ type: "doc",
2199
+ content: [{ type: "paragraph" }]
2200
+ };
2201
+ },
2202
+ setJson: (e) => {
2203
+ C(et(tt(e)));
2204
+ },
2205
+ getText: () => g.current?.innerText ?? "",
2206
+ focus: () => {
2207
+ let e = g.current;
2208
+ e && Ne(e);
2209
+ }
2210
+ })), t(() => {
2211
+ C(e);
2212
+ }, [e]), t(() => {
2213
+ let e = () => {
2214
+ let e = g.current;
2215
+ e && (u(e), y(te(e)));
2216
+ };
2217
+ return document.addEventListener("selectionchange", e), () => document.removeEventListener("selectionchange", e);
2218
+ }, []);
2219
+ let T = (e) => {
2220
+ let t = g.current;
2221
+ if (t) {
2222
+ switch (Ne(t), e.type) {
2223
+ case "inline":
2224
+ O(t, e.mark);
2225
+ break;
2226
+ case "block":
2227
+ fe(t, e.format);
2228
+ break;
2229
+ case "align":
2230
+ pe(t, e.align);
2231
+ break;
2232
+ case "textColor":
2233
+ ye(t, e.color);
2234
+ break;
2235
+ case "highlightColor":
2236
+ be(t, e.color);
2237
+ break;
2238
+ case "insertTable":
2239
+ Ce(t, e.rows ?? 3, e.cols ?? 3);
2240
+ break;
2241
+ case "undo":
2242
+ _.current.undo(t), S();
2243
+ return;
2244
+ case "redo":
2245
+ _.current.redo(t), S();
2246
+ return;
2247
+ }
2248
+ w(!0);
2249
+ }
2250
+ }, E = () => {
2251
+ w(!1);
2252
+ }, D = (e) => {
2253
+ let t = g.current;
2254
+ if (!t) return;
2255
+ let n = e.metaKey || e.ctrlKey;
2256
+ if (n && e.key.toLowerCase() === "z") {
2257
+ e.preventDefault(), e.shiftKey ? _.current.redo(t) : _.current.undo(t), S();
2258
+ return;
2259
+ }
2260
+ if (n && e.key.toLowerCase() === "y") {
2261
+ e.preventDefault(), _.current.redo(t), S();
2262
+ return;
2263
+ }
2264
+ if (n && e.key.toLowerCase() === "b") {
2265
+ e.preventDefault(), O(t, "bold"), w(!0);
2266
+ return;
2267
+ }
2268
+ if (n && e.key.toLowerCase() === "i") {
2269
+ e.preventDefault(), O(t, "italic"), w(!0);
2270
+ return;
2271
+ }
2272
+ if (n && e.key.toLowerCase() === "u") {
2273
+ e.preventDefault(), O(t, "underline"), w(!0);
2274
+ return;
2275
+ }
2276
+ if (je(t, e.nativeEvent)) {
2277
+ w(!0);
2278
+ return;
2279
+ }
2280
+ if (e.key === "Enter" && !e.shiftKey && Me(t, e.nativeEvent)) {
2281
+ w(!0);
2282
+ return;
2283
+ }
2284
+ e.key === " " && requestAnimationFrame(() => {
2285
+ We(t) && w(!0);
2286
+ });
2287
+ }, k = (e) => {
2288
+ let t = g.current;
2289
+ if (!t) return;
2290
+ e.preventDefault();
2291
+ let n = e.clipboardData.getData("text/html"), r = e.clipboardData.getData("text/plain"), i = n ? K(n) : ct(r);
2292
+ i && (xe(t, i), w(!0));
2293
+ }, A = (e) => {
2294
+ let t = g.current;
2295
+ t && de(t, e.nativeEvent) && w(!0);
2296
+ }, ne = {
2297
+ ...l?.toolbar,
2298
+ ...f
2299
+ }, j = {
2300
+ ...l?.content,
2301
+ ...m
2302
+ };
2303
+ return /* @__PURE__ */ o("div", {
2304
+ className: ["wysiwyg", s].filter(Boolean).join(" "),
2305
+ style: c,
2306
+ children: [/* @__PURE__ */ a("div", {
2307
+ className: ["toolbar-shell", d].filter(Boolean).join(" "),
2308
+ style: ne,
2309
+ children: /* @__PURE__ */ a(zt, {
2310
+ active: v,
2311
+ onCommand: T
2312
+ })
2313
+ }), /* @__PURE__ */ o("div", {
2314
+ className: ["editor-paper", p].filter(Boolean).join(" "),
2315
+ style: j,
2316
+ children: [/* @__PURE__ */ a("div", {
2317
+ ref: g,
2318
+ className: ["editor-surface", b ? "is-empty" : ""].filter(Boolean).join(" "),
2319
+ contentEditable: !0,
2320
+ role: "textbox",
2321
+ "aria-multiline": "true",
2322
+ "aria-label": "편집 영역",
2323
+ "data-placeholder": "내용을 입력하세요",
2324
+ spellCheck: !0,
2325
+ suppressContentEditableWarning: !0,
2326
+ onInput: E,
2327
+ onKeyDown: D,
2328
+ onPaste: k,
2329
+ onMouseDown: A,
2330
+ onBlur: S
2331
+ }), /* @__PURE__ */ a(mt, {
2332
+ editorRef: g,
2333
+ onMerge: (e) => {
2334
+ Ae(e) && w(!0);
2335
+ }
2336
+ })]
2337
+ })]
2338
+ });
2339
+ });
2340
+ //#endregion
2341
+ export { Ut as Editor, H as domToJson, Ye as htmlToJson, et as jsonToHtml, tt as normalizeDoc, K as sanitizeHTML, ct as sanitizePlainText };
2342
+
2343
+ //# sourceMappingURL=index.js.map