dopecanvas 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/dopecanvas.cjs +10 -3
- package/dist/dopecanvas.cjs.map +1 -1
- package/dist/dopecanvas.js +1301 -474
- package/dist/dopecanvas.js.map +1 -1
- package/dist/index.d.ts +82 -12
- package/package.json +2 -2
package/dist/dopecanvas.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { jsxs as k, jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import qe, { useState as $, forwardRef as Be, useRef as I, useCallback as x, useEffect as Y, useImperativeHandle as Pe, useMemo as Te } from "react";
|
|
3
|
+
import { createPortal as je } from "react-dom";
|
|
4
|
+
const Me = ({
|
|
4
5
|
dimensions: i,
|
|
5
6
|
margins: e,
|
|
6
7
|
pageNumber: t,
|
|
7
|
-
totalPages:
|
|
8
|
+
totalPages: o,
|
|
8
9
|
children: n
|
|
9
|
-
}) => /* @__PURE__ */
|
|
10
|
+
}) => /* @__PURE__ */ k(
|
|
10
11
|
"div",
|
|
11
12
|
{
|
|
12
13
|
className: "dopecanvas-page",
|
|
@@ -20,7 +21,7 @@ const G = ({
|
|
|
20
21
|
flexShrink: 0
|
|
21
22
|
},
|
|
22
23
|
children: [
|
|
23
|
-
/* @__PURE__ */
|
|
24
|
+
/* @__PURE__ */ r(
|
|
24
25
|
"div",
|
|
25
26
|
{
|
|
26
27
|
className: "dopecanvas-page-content",
|
|
@@ -36,7 +37,7 @@ const G = ({
|
|
|
36
37
|
children: n
|
|
37
38
|
}
|
|
38
39
|
),
|
|
39
|
-
/* @__PURE__ */
|
|
40
|
+
/* @__PURE__ */ k(
|
|
40
41
|
"div",
|
|
41
42
|
{
|
|
42
43
|
className: "dopecanvas-page-number",
|
|
@@ -55,209 +56,853 @@ const G = ({
|
|
|
55
56
|
children: [
|
|
56
57
|
t,
|
|
57
58
|
" / ",
|
|
58
|
-
|
|
59
|
+
o
|
|
59
60
|
]
|
|
60
61
|
}
|
|
61
62
|
)
|
|
62
63
|
]
|
|
63
64
|
}
|
|
64
|
-
),
|
|
65
|
+
), We = ({
|
|
66
|
+
visible: i,
|
|
67
|
+
onAddBelow: e,
|
|
68
|
+
onEditHTML: t,
|
|
69
|
+
onDelete: o
|
|
70
|
+
}) => /* @__PURE__ */ k(
|
|
71
|
+
"div",
|
|
72
|
+
{
|
|
73
|
+
className: "dopecanvas-block-toolbar",
|
|
74
|
+
style: {
|
|
75
|
+
...Ue,
|
|
76
|
+
display: i ? "flex" : "none"
|
|
77
|
+
},
|
|
78
|
+
onMouseDown: (n) => n.preventDefault(),
|
|
79
|
+
children: [
|
|
80
|
+
/* @__PURE__ */ r(xe, { onClick: e, title: "Add block below", children: /* @__PURE__ */ r(Oe, {}) }),
|
|
81
|
+
/* @__PURE__ */ r(xe, { onClick: t, title: "Edit HTML", children: /* @__PURE__ */ r($e, {}) }),
|
|
82
|
+
/* @__PURE__ */ r(xe, { onClick: o, title: "Delete block", danger: !0, children: /* @__PURE__ */ r(Ve, {}) })
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
), Oe = () => /* @__PURE__ */ k("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", children: [
|
|
86
|
+
/* @__PURE__ */ r("line", { x1: "7", y1: "3", x2: "7", y2: "11" }),
|
|
87
|
+
/* @__PURE__ */ r("line", { x1: "3", y1: "7", x2: "11", y2: "7" })
|
|
88
|
+
] }), $e = () => /* @__PURE__ */ k("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
89
|
+
/* @__PURE__ */ r("polyline", { points: "4.5,3 1.5,7 4.5,11" }),
|
|
90
|
+
/* @__PURE__ */ r("polyline", { points: "9.5,3 12.5,7 9.5,11" })
|
|
91
|
+
] }), Ve = () => /* @__PURE__ */ r("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ r("path", { d: "M2.5 4h9M5 4V2.5h4V4M3.5 4l.5 8h6l.5-8" }) }), xe = ({ onClick: i, title: e, children: t, danger: o }) => {
|
|
92
|
+
const [n, a] = $(!1);
|
|
93
|
+
return /* @__PURE__ */ r(
|
|
94
|
+
"button",
|
|
95
|
+
{
|
|
96
|
+
onClick: i,
|
|
97
|
+
title: e,
|
|
98
|
+
onMouseEnter: () => a(!0),
|
|
99
|
+
onMouseLeave: () => a(!1),
|
|
100
|
+
style: {
|
|
101
|
+
...Ge,
|
|
102
|
+
background: n ? o ? "#fff0f0" : "#f0f0f0" : "transparent",
|
|
103
|
+
color: n && o ? "#d32f2f" : "#666"
|
|
104
|
+
},
|
|
105
|
+
children: t
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}, Ue = {
|
|
109
|
+
position: "absolute",
|
|
110
|
+
top: 0,
|
|
111
|
+
left: -40,
|
|
112
|
+
flexDirection: "column",
|
|
113
|
+
gap: "1px",
|
|
114
|
+
zIndex: 100,
|
|
115
|
+
background: "#fff",
|
|
116
|
+
borderRadius: "6px",
|
|
117
|
+
boxShadow: "0 1px 5px rgba(0,0,0,0.12)",
|
|
118
|
+
padding: "3px",
|
|
119
|
+
paddingRight: "6px"
|
|
120
|
+
}, Ge = {
|
|
121
|
+
width: "30px",
|
|
122
|
+
height: "26px",
|
|
123
|
+
border: "none",
|
|
124
|
+
cursor: "pointer",
|
|
125
|
+
borderRadius: "4px",
|
|
126
|
+
fontSize: "13px",
|
|
127
|
+
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
128
|
+
display: "flex",
|
|
129
|
+
alignItems: "center",
|
|
130
|
+
justifyContent: "center",
|
|
131
|
+
padding: 0,
|
|
132
|
+
transition: "background 0.1s, color 0.1s"
|
|
133
|
+
}, Ke = ({
|
|
134
|
+
html: i,
|
|
135
|
+
onSave: e,
|
|
136
|
+
onCancel: t
|
|
137
|
+
}) => {
|
|
138
|
+
const [o, n] = $(i);
|
|
139
|
+
return je(
|
|
140
|
+
/* @__PURE__ */ r("div", { style: Xe, onClick: t, children: /* @__PURE__ */ k("div", { style: Je, onClick: (s) => s.stopPropagation(), children: [
|
|
141
|
+
/* @__PURE__ */ k("div", { style: Ze, children: [
|
|
142
|
+
/* @__PURE__ */ r("span", { style: { fontWeight: 600, fontSize: "14px" }, children: "Edit Block HTML" }),
|
|
143
|
+
/* @__PURE__ */ r("span", { style: { fontSize: "11px", color: "#888" }, children: "⌘Enter to save · Escape to cancel" })
|
|
144
|
+
] }),
|
|
145
|
+
/* @__PURE__ */ r(
|
|
146
|
+
"textarea",
|
|
147
|
+
{
|
|
148
|
+
style: Qe,
|
|
149
|
+
value: o,
|
|
150
|
+
onChange: (s) => n(s.target.value),
|
|
151
|
+
onKeyDown: (s) => {
|
|
152
|
+
if (s.key === "Enter" && (s.metaKey || s.ctrlKey) && (s.preventDefault(), e(o)), s.key === "Escape" && (s.preventDefault(), t()), s.key === "Tab") {
|
|
153
|
+
s.preventDefault();
|
|
154
|
+
const d = s.target, c = d.selectionStart, g = d.selectionEnd, f = o.substring(0, c) + " " + o.substring(g);
|
|
155
|
+
n(f), requestAnimationFrame(() => {
|
|
156
|
+
d.selectionStart = d.selectionEnd = c + 2;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
spellCheck: !1,
|
|
161
|
+
autoFocus: !0
|
|
162
|
+
}
|
|
163
|
+
),
|
|
164
|
+
/* @__PURE__ */ k("div", { style: Ye, children: [
|
|
165
|
+
/* @__PURE__ */ r(
|
|
166
|
+
"button",
|
|
167
|
+
{
|
|
168
|
+
style: et,
|
|
169
|
+
onClick: t,
|
|
170
|
+
onMouseEnter: (s) => {
|
|
171
|
+
s.target.style.borderColor = "#888";
|
|
172
|
+
},
|
|
173
|
+
onMouseLeave: (s) => {
|
|
174
|
+
s.target.style.borderColor = "#555";
|
|
175
|
+
},
|
|
176
|
+
children: "Cancel"
|
|
177
|
+
}
|
|
178
|
+
),
|
|
179
|
+
/* @__PURE__ */ r(
|
|
180
|
+
"button",
|
|
181
|
+
{
|
|
182
|
+
style: tt,
|
|
183
|
+
onClick: () => e(o),
|
|
184
|
+
onMouseEnter: (s) => {
|
|
185
|
+
s.target.style.background = "#0055dd";
|
|
186
|
+
},
|
|
187
|
+
onMouseLeave: (s) => {
|
|
188
|
+
s.target.style.background = "#0066ff";
|
|
189
|
+
},
|
|
190
|
+
children: "Save"
|
|
191
|
+
}
|
|
192
|
+
)
|
|
193
|
+
] })
|
|
194
|
+
] }) }),
|
|
195
|
+
document.body
|
|
196
|
+
);
|
|
197
|
+
}, Xe = {
|
|
198
|
+
position: "fixed",
|
|
199
|
+
inset: 0,
|
|
200
|
+
background: "rgba(0, 0, 0, 0.5)",
|
|
201
|
+
display: "flex",
|
|
202
|
+
alignItems: "center",
|
|
203
|
+
justifyContent: "center",
|
|
204
|
+
zIndex: 1e4
|
|
205
|
+
}, Je = {
|
|
206
|
+
width: "min(800px, 90vw)",
|
|
207
|
+
height: "min(600px, 80vh)",
|
|
208
|
+
background: "#1e1e1e",
|
|
209
|
+
borderRadius: "10px",
|
|
210
|
+
display: "flex",
|
|
211
|
+
flexDirection: "column",
|
|
212
|
+
overflow: "hidden",
|
|
213
|
+
boxShadow: "0 20px 60px rgba(0, 0, 0, 0.4)"
|
|
214
|
+
}, Ze = {
|
|
215
|
+
display: "flex",
|
|
216
|
+
justifyContent: "space-between",
|
|
217
|
+
alignItems: "center",
|
|
218
|
+
padding: "12px 16px",
|
|
219
|
+
background: "#2d2d2d",
|
|
220
|
+
color: "#ccc",
|
|
221
|
+
borderBottom: "1px solid #444"
|
|
222
|
+
}, Qe = {
|
|
223
|
+
flex: 1,
|
|
224
|
+
background: "#1e1e1e",
|
|
225
|
+
color: "#d4d4d4",
|
|
226
|
+
border: "none",
|
|
227
|
+
padding: "16px",
|
|
228
|
+
fontFamily: "'SF Mono', 'Fira Code', 'Consolas', 'Monaco', monospace",
|
|
229
|
+
fontSize: "13px",
|
|
230
|
+
lineHeight: "1.6",
|
|
231
|
+
resize: "none",
|
|
232
|
+
outline: "none",
|
|
233
|
+
tabSize: 2
|
|
234
|
+
}, Ye = {
|
|
235
|
+
display: "flex",
|
|
236
|
+
justifyContent: "flex-end",
|
|
237
|
+
gap: "8px",
|
|
238
|
+
padding: "12px 16px",
|
|
239
|
+
background: "#2d2d2d",
|
|
240
|
+
borderTop: "1px solid #444"
|
|
241
|
+
}, et = {
|
|
242
|
+
padding: "6px 16px",
|
|
243
|
+
border: "1px solid #555",
|
|
244
|
+
borderRadius: "6px",
|
|
245
|
+
background: "transparent",
|
|
246
|
+
color: "#ccc",
|
|
247
|
+
cursor: "pointer",
|
|
248
|
+
fontSize: "13px",
|
|
249
|
+
transition: "border-color 0.15s"
|
|
250
|
+
}, tt = {
|
|
251
|
+
padding: "6px 16px",
|
|
252
|
+
border: "none",
|
|
253
|
+
borderRadius: "6px",
|
|
254
|
+
background: "#0066ff",
|
|
255
|
+
color: "#fff",
|
|
256
|
+
cursor: "pointer",
|
|
257
|
+
fontSize: "13px",
|
|
258
|
+
fontWeight: 500,
|
|
259
|
+
transition: "background 0.15s"
|
|
260
|
+
}, _e = {
|
|
65
261
|
letter: { width: 816, height: 1056 },
|
|
66
262
|
// 8.5 x 11 inches
|
|
67
263
|
a4: { width: 794, height: 1123 },
|
|
68
264
|
// 210 x 297 mm
|
|
69
265
|
legal: { width: 816, height: 1344 }
|
|
70
266
|
// 8.5 x 14 inches
|
|
71
|
-
},
|
|
267
|
+
}, nt = {
|
|
72
268
|
top: 96,
|
|
73
269
|
right: 96,
|
|
74
270
|
bottom: 96,
|
|
75
271
|
left: 96
|
|
76
|
-
},
|
|
272
|
+
}, fe = {
|
|
77
273
|
size: "letter",
|
|
78
|
-
margins: { ...
|
|
274
|
+
margins: { ...nt }
|
|
79
275
|
};
|
|
80
|
-
|
|
276
|
+
let ot = 0;
|
|
277
|
+
function De() {
|
|
278
|
+
return `split-${++ot}-${Date.now()}`;
|
|
279
|
+
}
|
|
280
|
+
const rt = 40, it = /* @__PURE__ */ new Set([
|
|
281
|
+
"script",
|
|
282
|
+
"style",
|
|
283
|
+
"img",
|
|
284
|
+
"video",
|
|
285
|
+
"canvas",
|
|
286
|
+
"svg",
|
|
287
|
+
"hr",
|
|
288
|
+
"iframe",
|
|
289
|
+
"object",
|
|
290
|
+
"embed",
|
|
291
|
+
"audio",
|
|
292
|
+
"picture",
|
|
293
|
+
"figure"
|
|
294
|
+
]), st = /* @__PURE__ */ new Set([
|
|
295
|
+
"p",
|
|
296
|
+
"h1",
|
|
297
|
+
"h2",
|
|
298
|
+
"h3",
|
|
299
|
+
"h4",
|
|
300
|
+
"h5",
|
|
301
|
+
"h6",
|
|
302
|
+
"blockquote",
|
|
303
|
+
"div",
|
|
304
|
+
"li",
|
|
305
|
+
"span",
|
|
306
|
+
"td",
|
|
307
|
+
"th",
|
|
308
|
+
"pre",
|
|
309
|
+
"code"
|
|
310
|
+
]);
|
|
311
|
+
function ge(i, e) {
|
|
312
|
+
const t = i.tagName.toLowerCase();
|
|
313
|
+
if (it.has(t) || e < rt) return null;
|
|
314
|
+
const o = window.getComputedStyle(i);
|
|
315
|
+
if (o.getPropertyValue("break-before") === "page" || o.getPropertyValue("page-break-before") === "always")
|
|
316
|
+
return null;
|
|
317
|
+
const n = Array.from(i.children);
|
|
318
|
+
if (n.length > 1) {
|
|
319
|
+
const a = lt(i, n, e);
|
|
320
|
+
if (a) return a;
|
|
321
|
+
}
|
|
322
|
+
if (st.has(t) || i.childNodes.length > 0) {
|
|
323
|
+
const a = ct(i, e);
|
|
324
|
+
if (a) return a;
|
|
325
|
+
}
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
function at(i) {
|
|
329
|
+
if (i.length === 0) return i;
|
|
330
|
+
const e = [];
|
|
331
|
+
let t = 0;
|
|
332
|
+
for (; t < i.length; ) {
|
|
333
|
+
const o = i[t], n = we(o);
|
|
334
|
+
if (!n) {
|
|
335
|
+
e.push(o), t++;
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
const a = [o];
|
|
339
|
+
let s = t + 1;
|
|
340
|
+
for (; s < i.length && we(i[s]) === n; )
|
|
341
|
+
a.push(i[s]), s++;
|
|
342
|
+
e.push(ut(a)), t = s;
|
|
343
|
+
}
|
|
344
|
+
return e;
|
|
345
|
+
}
|
|
346
|
+
function lt(i, e, t) {
|
|
347
|
+
const o = i.getBoundingClientRect().top;
|
|
348
|
+
let n = -1;
|
|
349
|
+
for (let c = 0; c < e.length; c++) {
|
|
350
|
+
const g = e[c].getBoundingClientRect(), f = window.getComputedStyle(e[c]), P = parseFloat(f.marginBottom) || 0;
|
|
351
|
+
if (g.bottom + P - o > t && c > 0) {
|
|
352
|
+
n = c;
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (n <= 0) return null;
|
|
357
|
+
const a = i.cloneNode(!1), s = i.cloneNode(!1);
|
|
358
|
+
for (let c = 0; c < e.length; c++)
|
|
359
|
+
c < n ? a.appendChild(e[c].cloneNode(!0)) : s.appendChild(e[c].cloneNode(!0));
|
|
360
|
+
const d = De();
|
|
361
|
+
return a.setAttribute("data-dopecanvas-split-id", d), a.setAttribute("data-dopecanvas-split-part", "0"), s.setAttribute("data-dopecanvas-split-id", d), s.setAttribute("data-dopecanvas-split-part", "1"), {
|
|
362
|
+
firstHTML: a.outerHTML,
|
|
363
|
+
secondHTML: s.outerHTML
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function ct(i, e) {
|
|
367
|
+
const t = i.getBoundingClientRect().top, o = [], n = document.createTreeWalker(i, NodeFilter.SHOW_TEXT);
|
|
368
|
+
for (; n.nextNode(); )
|
|
369
|
+
o.push(n.currentNode);
|
|
370
|
+
if (o.length === 0) return null;
|
|
371
|
+
let a = null, s = 0;
|
|
372
|
+
for (const g of o) {
|
|
373
|
+
const f = document.createRange();
|
|
374
|
+
f.selectNodeContents(g);
|
|
375
|
+
const P = f.getBoundingClientRect();
|
|
376
|
+
if (P.bottom - t <= e) continue;
|
|
377
|
+
if (P.top - t >= e) {
|
|
378
|
+
a = g, s = 0;
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
let S = 0, E = g.length;
|
|
382
|
+
for (; S < E; ) {
|
|
383
|
+
const y = Math.floor((S + E) / 2), L = document.createRange();
|
|
384
|
+
L.setStart(g, y), L.collapse(!0), L.getBoundingClientRect().top - t >= e ? E = y : S = y + 1;
|
|
385
|
+
}
|
|
386
|
+
a = g, s = S;
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
if (!a) return null;
|
|
390
|
+
const d = a.textContent || "";
|
|
391
|
+
let c = s;
|
|
392
|
+
for (; c > 0 && d[c - 1] !== " " && d[c - 1] !== `
|
|
393
|
+
`; )
|
|
394
|
+
c--;
|
|
395
|
+
if (c > 0 && (s = c), s === 0 && a === o[0] || s >= d.length && a === o[o.length - 1]) return null;
|
|
396
|
+
try {
|
|
397
|
+
const g = document.createRange();
|
|
398
|
+
g.setStart(i, 0), g.setEnd(a, s);
|
|
399
|
+
const f = document.createRange();
|
|
400
|
+
f.setStart(a, s), f.setEndAfter(i.lastChild);
|
|
401
|
+
const P = g.cloneContents(), S = f.cloneContents(), E = Le(P), y = Le(S);
|
|
402
|
+
if (E.trim().length === 0 || y.trim().length === 0)
|
|
403
|
+
return null;
|
|
404
|
+
const L = i.cloneNode(!1);
|
|
405
|
+
L.appendChild(P);
|
|
406
|
+
const F = i.cloneNode(!1);
|
|
407
|
+
F.appendChild(S);
|
|
408
|
+
const Q = De();
|
|
409
|
+
return L.setAttribute("data-dopecanvas-split-id", Q), L.setAttribute("data-dopecanvas-split-part", "0"), F.setAttribute("data-dopecanvas-split-id", Q), F.setAttribute("data-dopecanvas-split-part", "1"), {
|
|
410
|
+
firstHTML: L.outerHTML,
|
|
411
|
+
secondHTML: F.outerHTML
|
|
412
|
+
};
|
|
413
|
+
} catch {
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function we(i) {
|
|
418
|
+
const e = i.match(/data-dopecanvas-split-id="([^"]+)"/);
|
|
419
|
+
return e ? e[1] : null;
|
|
420
|
+
}
|
|
421
|
+
function ut(i) {
|
|
422
|
+
const e = document.createElement("div"), t = [];
|
|
423
|
+
let o = "", n = "";
|
|
424
|
+
for (const a of i) {
|
|
425
|
+
e.innerHTML = a;
|
|
426
|
+
const s = e.firstElementChild;
|
|
427
|
+
if (s) {
|
|
428
|
+
if (!o) {
|
|
429
|
+
o = s.tagName.toLowerCase();
|
|
430
|
+
const d = s.cloneNode(!1);
|
|
431
|
+
d.removeAttribute("data-dopecanvas-split-id"), d.removeAttribute("data-dopecanvas-split-part");
|
|
432
|
+
const c = document.createElement("div");
|
|
433
|
+
c.appendChild(d);
|
|
434
|
+
const g = c.innerHTML, f = g.lastIndexOf("</");
|
|
435
|
+
n = f >= 0 ? g.substring(0, f) : g;
|
|
436
|
+
}
|
|
437
|
+
t.push(s.innerHTML);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return o ? `${n}${t.join("")}</${o}>` : i[0];
|
|
441
|
+
}
|
|
442
|
+
function Le(i) {
|
|
443
|
+
const e = document.createElement("div");
|
|
444
|
+
return e.appendChild(i.cloneNode(!0)), e.textContent || "";
|
|
445
|
+
}
|
|
446
|
+
function dt(i) {
|
|
81
447
|
const e = [];
|
|
82
448
|
return i.querySelectorAll("script").forEach((t) => {
|
|
83
|
-
const
|
|
449
|
+
const o = document.createElement("script");
|
|
84
450
|
Array.from(t.attributes).forEach(
|
|
85
|
-
(n) =>
|
|
86
|
-
),
|
|
451
|
+
(n) => o.setAttribute(n.name, n.value)
|
|
452
|
+
), o.textContent = t.textContent || "", t.parentNode?.replaceChild(o, t), e.push(o);
|
|
87
453
|
}), e;
|
|
88
454
|
}
|
|
89
|
-
function
|
|
455
|
+
function ht(i) {
|
|
90
456
|
const e = window.getSelection();
|
|
91
457
|
if (!e || e.rangeCount === 0) return null;
|
|
92
|
-
const t = e.getRangeAt(0),
|
|
93
|
-
i.querySelectorAll(".dopecanvas-block-
|
|
94
|
-
),
|
|
95
|
-
if (
|
|
458
|
+
const t = e.getRangeAt(0), o = t.startContainer, n = Array.from(
|
|
459
|
+
i.querySelectorAll(".dopecanvas-block-content")
|
|
460
|
+
), a = n.findIndex((s) => s.contains(o));
|
|
461
|
+
if (a === -1) return null;
|
|
96
462
|
try {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
return { blockIndex:
|
|
463
|
+
const s = document.createRange();
|
|
464
|
+
s.selectNodeContents(n[a]), s.setEnd(t.startContainer, t.startOffset);
|
|
465
|
+
const d = s.toString().length;
|
|
466
|
+
return { blockIndex: a, textOffset: d };
|
|
101
467
|
} catch {
|
|
102
468
|
return null;
|
|
103
469
|
}
|
|
104
470
|
}
|
|
105
|
-
function
|
|
106
|
-
const t = i.querySelectorAll(".dopecanvas-block-
|
|
471
|
+
function gt(i, e) {
|
|
472
|
+
const t = i.querySelectorAll(".dopecanvas-block-content");
|
|
107
473
|
if (e.blockIndex >= t.length) return;
|
|
108
|
-
const
|
|
109
|
-
let
|
|
474
|
+
const o = t[e.blockIndex], n = document.createTreeWalker(o, NodeFilter.SHOW_TEXT);
|
|
475
|
+
let a = e.textOffset;
|
|
110
476
|
for (; n.nextNode(); ) {
|
|
111
|
-
const
|
|
112
|
-
if (
|
|
477
|
+
const s = n.currentNode;
|
|
478
|
+
if (a <= s.length) {
|
|
113
479
|
try {
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
480
|
+
const d = document.createRange();
|
|
481
|
+
d.setStart(s, a), d.collapse(!0);
|
|
482
|
+
const c = window.getSelection();
|
|
483
|
+
c?.removeAllRanges(), c?.addRange(d);
|
|
118
484
|
} catch {
|
|
119
485
|
}
|
|
120
486
|
return;
|
|
121
487
|
}
|
|
122
|
-
|
|
488
|
+
a -= s.length;
|
|
123
489
|
}
|
|
124
490
|
try {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
|
|
491
|
+
const s = document.createRange();
|
|
492
|
+
s.selectNodeContents(o), s.collapse(!1);
|
|
493
|
+
const d = window.getSelection();
|
|
494
|
+
d?.removeAllRanges(), d?.addRange(s);
|
|
129
495
|
} catch {
|
|
130
496
|
}
|
|
131
497
|
}
|
|
132
|
-
const
|
|
498
|
+
const pt = qe.memo(({ html: i, isEditable: e, isTable: t }) => /* @__PURE__ */ r(
|
|
499
|
+
"div",
|
|
500
|
+
{
|
|
501
|
+
className: "dopecanvas-block-content",
|
|
502
|
+
contentEditable: e && !t ? !0 : void 0,
|
|
503
|
+
suppressContentEditableWarning: !0,
|
|
504
|
+
dangerouslySetInnerHTML: { __html: i }
|
|
505
|
+
}
|
|
506
|
+
));
|
|
507
|
+
function ft(i) {
|
|
508
|
+
const e = i.replace(/\s+/g, " ").toLowerCase();
|
|
509
|
+
return e.includes("break-before") && e.includes("page") || e.includes("page-break-before") && e.includes("always");
|
|
510
|
+
}
|
|
511
|
+
const mt = Be(({
|
|
133
512
|
html: i,
|
|
134
513
|
css: e,
|
|
135
514
|
pageConfig: t,
|
|
136
|
-
layoutEngine:
|
|
515
|
+
layoutEngine: o,
|
|
137
516
|
editableManager: n,
|
|
138
|
-
onContentChange:
|
|
139
|
-
onPaginationChange:
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
517
|
+
onContentChange: a,
|
|
518
|
+
onPaginationChange: s,
|
|
519
|
+
showPageBreaks: d = !1
|
|
520
|
+
}, c) => {
|
|
521
|
+
const g = I(null), f = I(null), P = I(null), S = I(a);
|
|
522
|
+
S.current = a;
|
|
523
|
+
const [E, y] = $([]), L = I(null), F = I(!1), Q = I([]), [re, D] = $(null), [G, K] = $(null), [me, ie] = $(""), se = I(null), h = typeof t.size == "string" ? _e[t.size] : t.size, T = x(() => {
|
|
524
|
+
if (!f.current) return;
|
|
525
|
+
const m = f.current.querySelectorAll(
|
|
526
|
+
".dopecanvas-block-content"
|
|
527
|
+
), u = [];
|
|
528
|
+
m.forEach((C) => {
|
|
529
|
+
const w = C, R = w.children;
|
|
530
|
+
if (R.length !== 0)
|
|
531
|
+
if (R.length === 1)
|
|
532
|
+
u.push(R[0].outerHTML);
|
|
533
|
+
else {
|
|
534
|
+
const v = document.createElement("div");
|
|
535
|
+
v.innerHTML = w.innerHTML, u.push(v.outerHTML);
|
|
536
|
+
}
|
|
151
537
|
});
|
|
152
|
-
const
|
|
538
|
+
const q = u.join(`
|
|
153
539
|
`);
|
|
154
|
-
|
|
155
|
-
}, []),
|
|
156
|
-
if (!
|
|
157
|
-
const
|
|
158
|
-
if (
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
540
|
+
S.current?.(q);
|
|
541
|
+
}, []), H = x((m) => {
|
|
542
|
+
if (!g.current) return;
|
|
543
|
+
const u = g.current, q = o.getContentAreaWidth(), C = o.getContentAreaHeight();
|
|
544
|
+
if (u.style.width = `${q}px`, u.style.position = "absolute", u.style.left = "-9999px", u.style.top = "0", u.style.visibility = "hidden", u.innerHTML = "", e) {
|
|
545
|
+
const l = document.createElement("style");
|
|
546
|
+
l.textContent = e, u.appendChild(l);
|
|
547
|
+
}
|
|
548
|
+
const w = document.createElement("div");
|
|
549
|
+
w.innerHTML = m, u.appendChild(w);
|
|
550
|
+
const v = o.measureBlocks(w).map((l) => {
|
|
551
|
+
const B = l.element;
|
|
552
|
+
return {
|
|
553
|
+
html: B.cloneNode(!0).outerHTML,
|
|
554
|
+
height: l.height,
|
|
555
|
+
element: B,
|
|
556
|
+
breakBefore: l.breakBefore,
|
|
557
|
+
breakAfter: l.breakAfter
|
|
558
|
+
};
|
|
559
|
+
}), M = [];
|
|
560
|
+
let b = [], A = 0, X = 0;
|
|
561
|
+
for (; X < v.length; ) {
|
|
562
|
+
const l = v[X];
|
|
563
|
+
l.breakBefore && b.length > 0 && (M.push(b), b = [], A = 0);
|
|
564
|
+
const B = C - A;
|
|
565
|
+
if (l.height <= B)
|
|
566
|
+
b.push(l.html), A += l.height;
|
|
567
|
+
else if (b.length > 0 && B >= 60) {
|
|
568
|
+
const j = ge(l.element, B);
|
|
569
|
+
if (j) {
|
|
570
|
+
b.push(j.firstHTML), M.push(b), b = [], A = 0;
|
|
571
|
+
const V = document.createElement("div");
|
|
572
|
+
V.innerHTML = j.secondHTML;
|
|
573
|
+
const W = V.firstElementChild;
|
|
574
|
+
w.appendChild(W);
|
|
575
|
+
const ae = W.getBoundingClientRect(), le = window.getComputedStyle(W), p = parseFloat(le.marginTop) || 0, U = parseFloat(le.marginBottom) || 0;
|
|
576
|
+
v.splice(X + 1, 0, {
|
|
577
|
+
html: W.outerHTML,
|
|
578
|
+
height: ae.height + p + U,
|
|
579
|
+
element: W,
|
|
580
|
+
breakBefore: !1,
|
|
581
|
+
breakAfter: l.breakAfter
|
|
582
|
+
});
|
|
583
|
+
} else
|
|
584
|
+
M.push(b), b = [l.html], A = l.height;
|
|
585
|
+
} else if (b.length > 0)
|
|
586
|
+
M.push(b), b = [l.html], A = l.height;
|
|
587
|
+
else {
|
|
588
|
+
const j = ge(l.element, C);
|
|
589
|
+
if (j) {
|
|
590
|
+
b.push(j.firstHTML), M.push(b), b = [], A = 0;
|
|
591
|
+
const V = document.createElement("div");
|
|
592
|
+
V.innerHTML = j.secondHTML;
|
|
593
|
+
const W = V.firstElementChild;
|
|
594
|
+
w.appendChild(W);
|
|
595
|
+
const ae = W.getBoundingClientRect(), le = window.getComputedStyle(W), p = parseFloat(le.marginTop) || 0, U = parseFloat(le.marginBottom) || 0;
|
|
596
|
+
v.splice(X + 1, 0, {
|
|
597
|
+
html: W.outerHTML,
|
|
598
|
+
height: ae.height + p + U,
|
|
599
|
+
element: W,
|
|
600
|
+
breakBefore: !1,
|
|
601
|
+
breakAfter: l.breakAfter
|
|
602
|
+
});
|
|
603
|
+
} else
|
|
604
|
+
b.push(l.html), M.push(b), b = [], A = 0;
|
|
605
|
+
}
|
|
606
|
+
l.breakAfter && b.length > 0 && (M.push(b), b = [], A = 0), X++;
|
|
166
607
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
),
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
608
|
+
b.length > 0 && M.push(b), M.length === 0 && M.push([]), u.innerHTML = "";
|
|
609
|
+
const oe = M.map((l) => ({ blocks: l })), N = {
|
|
610
|
+
pages: M.map((l, B) => ({ blockIndices: Array.from({ length: M[B].length }, (j, V) => V) })),
|
|
611
|
+
pageCount: M.length
|
|
612
|
+
};
|
|
613
|
+
Q.current = oe, y(oe), s?.(N), S.current?.(m);
|
|
614
|
+
}, [e, o, s]), O = x(() => {
|
|
615
|
+
if (!f.current || !g.current) return;
|
|
616
|
+
const m = f.current, u = ht(m), q = m.querySelectorAll(".dopecanvas-block-content"), C = [];
|
|
617
|
+
if (q.forEach((p) => {
|
|
618
|
+
const U = p, J = U.children;
|
|
619
|
+
if (J.length !== 0)
|
|
620
|
+
if (J.length === 1)
|
|
621
|
+
C.push(J[0].outerHTML);
|
|
622
|
+
else {
|
|
623
|
+
const ne = document.createElement("div");
|
|
624
|
+
ne.innerHTML = U.innerHTML, C.push(ne.outerHTML);
|
|
625
|
+
}
|
|
626
|
+
}), C.length === 0) return;
|
|
627
|
+
const R = at(C).join(`
|
|
628
|
+
`), v = g.current, M = o.getContentAreaWidth(), b = o.getContentAreaHeight();
|
|
629
|
+
if (v.style.width = `${M}px`, v.style.position = "absolute", v.style.left = "-9999px", v.style.top = "0", v.style.visibility = "hidden", v.innerHTML = "", e) {
|
|
630
|
+
const p = document.createElement("style");
|
|
631
|
+
p.textContent = e, v.appendChild(p);
|
|
186
632
|
}
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
633
|
+
const A = document.createElement("div");
|
|
634
|
+
A.innerHTML = R, v.appendChild(A);
|
|
635
|
+
const oe = o.measureBlocks(A).map((p) => ({
|
|
636
|
+
html: p.element.cloneNode(!0).outerHTML,
|
|
637
|
+
height: p.height,
|
|
638
|
+
element: p.element,
|
|
639
|
+
breakBefore: p.breakBefore,
|
|
640
|
+
breakAfter: p.breakAfter
|
|
641
|
+
})), N = [];
|
|
642
|
+
let l = [], B = 0, j = 0;
|
|
643
|
+
for (; j < oe.length; ) {
|
|
644
|
+
const p = oe[j];
|
|
645
|
+
p.breakBefore && l.length > 0 && (N.push(l), l = [], B = 0);
|
|
646
|
+
const U = b - B;
|
|
647
|
+
if (p.height <= U)
|
|
648
|
+
l.push(p.html), B += p.height;
|
|
649
|
+
else if (l.length > 0 && U >= 60) {
|
|
650
|
+
const J = ge(p.element, U);
|
|
651
|
+
if (J) {
|
|
652
|
+
l.push(J.firstHTML), N.push(l), l = [], B = 0;
|
|
653
|
+
const ne = document.createElement("div");
|
|
654
|
+
ne.innerHTML = J.secondHTML;
|
|
655
|
+
const Z = ne.firstElementChild;
|
|
656
|
+
A.appendChild(Z);
|
|
657
|
+
const be = Z.getBoundingClientRect(), ue = window.getComputedStyle(Z), Ce = parseFloat(ue.marginTop) || 0, ye = parseFloat(ue.marginBottom) || 0;
|
|
658
|
+
oe.splice(j + 1, 0, {
|
|
659
|
+
html: Z.outerHTML,
|
|
660
|
+
height: be.height + Ce + ye,
|
|
661
|
+
element: Z,
|
|
662
|
+
breakBefore: !1,
|
|
663
|
+
breakAfter: p.breakAfter
|
|
664
|
+
});
|
|
665
|
+
} else
|
|
666
|
+
N.push(l), l = [p.html], B = p.height;
|
|
667
|
+
} else if (l.length > 0)
|
|
668
|
+
N.push(l), l = [p.html], B = p.height;
|
|
669
|
+
else {
|
|
670
|
+
const J = ge(p.element, b);
|
|
671
|
+
if (J) {
|
|
672
|
+
l.push(J.firstHTML), N.push(l), l = [], B = 0;
|
|
673
|
+
const ne = document.createElement("div");
|
|
674
|
+
ne.innerHTML = J.secondHTML;
|
|
675
|
+
const Z = ne.firstElementChild;
|
|
676
|
+
A.appendChild(Z);
|
|
677
|
+
const be = Z.getBoundingClientRect(), ue = window.getComputedStyle(Z), Ce = parseFloat(ue.marginTop) || 0, ye = parseFloat(ue.marginBottom) || 0;
|
|
678
|
+
oe.splice(j + 1, 0, {
|
|
679
|
+
html: Z.outerHTML,
|
|
680
|
+
height: be.height + Ce + ye,
|
|
681
|
+
element: Z,
|
|
682
|
+
breakBefore: !1,
|
|
683
|
+
breakAfter: p.breakAfter
|
|
684
|
+
});
|
|
685
|
+
} else
|
|
686
|
+
l.push(p.html), N.push(l), l = [], B = 0;
|
|
687
|
+
}
|
|
688
|
+
p.breakAfter && l.length > 0 && (N.push(l), l = [], B = 0), j++;
|
|
689
|
+
}
|
|
690
|
+
l.length > 0 && N.push(l), N.length === 0 && N.push([]), v.innerHTML = "";
|
|
691
|
+
const V = N.map((p) => ({ blocks: p })), W = Q.current.map((p) => p.blocks.length), ae = V.map((p) => p.blocks.length);
|
|
692
|
+
W.length !== ae.length || W.some((p, U) => p !== ae[U]) ? (F.current = !0, L.current = u, Q.current = V, y(V), s?.({
|
|
693
|
+
pages: N.map(() => ({ blockIndices: [] })),
|
|
694
|
+
pageCount: N.length
|
|
695
|
+
})) : Q.current = V;
|
|
696
|
+
}, [e, o, s]), ee = I(O);
|
|
697
|
+
ee.current = O;
|
|
698
|
+
const te = x(() => {
|
|
699
|
+
const m = new DOMParser().parseFromString(i, "text/html");
|
|
700
|
+
m.head.querySelectorAll('style, link[rel="stylesheet"]').forEach((u) => {
|
|
701
|
+
m.body.insertBefore(u, m.body.firstChild);
|
|
702
|
+
}), H(m.body.innerHTML);
|
|
703
|
+
}, [i, H]);
|
|
704
|
+
Y(() => {
|
|
705
|
+
te();
|
|
706
|
+
}, [te]);
|
|
707
|
+
const z = x(() => {
|
|
708
|
+
if (!f.current) return [];
|
|
709
|
+
const m = f.current.querySelectorAll(
|
|
710
|
+
".dopecanvas-block-content"
|
|
711
|
+
), u = [];
|
|
712
|
+
return m.forEach((q) => {
|
|
713
|
+
const C = q.firstElementChild;
|
|
714
|
+
C && u.push(C.outerHTML);
|
|
715
|
+
}), u;
|
|
716
|
+
}, []), he = x(
|
|
717
|
+
(m) => {
|
|
718
|
+
const u = z();
|
|
719
|
+
u.splice(
|
|
720
|
+
m + 1,
|
|
721
|
+
0,
|
|
722
|
+
'<p style="min-height: 1.5em; line-height: 1.6;"> </p>'
|
|
723
|
+
), D(null), H(u.join(`
|
|
724
|
+
`));
|
|
725
|
+
},
|
|
726
|
+
[z, H]
|
|
727
|
+
), Se = x(
|
|
728
|
+
(m) => {
|
|
729
|
+
const u = z();
|
|
730
|
+
u.length <= 1 || (u.splice(m, 1), D(null), H(u.join(`
|
|
731
|
+
`)));
|
|
732
|
+
},
|
|
733
|
+
[z, H]
|
|
734
|
+
), Ne = x(
|
|
735
|
+
(m) => {
|
|
736
|
+
const u = z();
|
|
737
|
+
m < u.length && (K(m), ie(u[m]));
|
|
738
|
+
},
|
|
739
|
+
[z]
|
|
740
|
+
), Fe = x(
|
|
741
|
+
(m) => {
|
|
742
|
+
if (G === null) return;
|
|
743
|
+
const u = z();
|
|
744
|
+
G < u.length && (u[G] = m), K(null), ie(""), D(null), H(u.join(`
|
|
745
|
+
`));
|
|
746
|
+
},
|
|
747
|
+
[G, z, H]
|
|
748
|
+
), ze = x(() => {
|
|
749
|
+
K(null), ie("");
|
|
750
|
+
}, []), ke = x(() => {
|
|
751
|
+
const m = '<div style="break-before: page;"></div>', u = z();
|
|
752
|
+
let q = u.length;
|
|
753
|
+
const C = window.getSelection();
|
|
754
|
+
if (C && C.rangeCount > 0 && f.current) {
|
|
755
|
+
const w = C.getRangeAt(0).startContainer, v = Array.from(
|
|
756
|
+
f.current.querySelectorAll(".dopecanvas-block-content")
|
|
757
|
+
).findIndex((M) => M.contains(w));
|
|
758
|
+
v !== -1 && (q = v + 1);
|
|
759
|
+
}
|
|
760
|
+
u.splice(q, 0, m), D(null), H(u.join(`
|
|
761
|
+
`));
|
|
762
|
+
}, [z, H]);
|
|
763
|
+
return Pe(c, () => ({
|
|
764
|
+
insertPageBreak: ke
|
|
765
|
+
}), [ke]), Y(() => {
|
|
766
|
+
const m = f.current;
|
|
767
|
+
if (!m) return;
|
|
768
|
+
P.current && P.current.disconnect(), m.querySelectorAll(".dopecanvas-block-content").forEach((R) => {
|
|
769
|
+
const v = R.firstElementChild;
|
|
770
|
+
v && v.tagName === "TABLE" && v.querySelectorAll("td, th").forEach((b) => {
|
|
771
|
+
b.contentEditable = "true";
|
|
772
|
+
});
|
|
210
773
|
});
|
|
211
|
-
const
|
|
212
|
-
let
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
},
|
|
774
|
+
const q = dt(m);
|
|
775
|
+
let C = null;
|
|
776
|
+
const w = new MutationObserver(() => {
|
|
777
|
+
F.current || (C && clearTimeout(C), C = setTimeout(() => {
|
|
778
|
+
T(), ee.current();
|
|
779
|
+
}, 800));
|
|
217
780
|
});
|
|
218
|
-
return
|
|
781
|
+
return w.observe(m, {
|
|
219
782
|
childList: !0,
|
|
220
783
|
subtree: !0,
|
|
221
784
|
characterData: !0,
|
|
222
785
|
attributes: !1
|
|
223
|
-
}),
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
),
|
|
228
|
-
}) :
|
|
229
|
-
|
|
786
|
+
}), P.current = w, L.current ? requestAnimationFrame(() => {
|
|
787
|
+
L.current && f.current && (gt(
|
|
788
|
+
f.current,
|
|
789
|
+
L.current
|
|
790
|
+
), L.current = null), F.current = !1;
|
|
791
|
+
}) : F.current = !1, () => {
|
|
792
|
+
w.disconnect(), q.forEach((R) => R.remove()), C && clearTimeout(C);
|
|
230
793
|
};
|
|
231
|
-
}, [
|
|
232
|
-
/* @__PURE__ */
|
|
233
|
-
/* @__PURE__ */
|
|
234
|
-
e && /* @__PURE__ */
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
{
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
794
|
+
}, [E, T]), /* @__PURE__ */ k("div", { className: "dopecanvas-paged-view", style: bt, children: [
|
|
795
|
+
/* @__PURE__ */ r("div", { ref: g, "aria-hidden": "true" }),
|
|
796
|
+
/* @__PURE__ */ k("div", { ref: f, style: Ct, children: [
|
|
797
|
+
e && /* @__PURE__ */ r("style", { dangerouslySetInnerHTML: { __html: e } }),
|
|
798
|
+
E.map((m, u) => {
|
|
799
|
+
const q = E.slice(0, u).reduce((C, w) => C + w.blocks.length, 0);
|
|
800
|
+
return /* @__PURE__ */ r(
|
|
801
|
+
Me,
|
|
802
|
+
{
|
|
803
|
+
dimensions: h,
|
|
804
|
+
margins: t.margins,
|
|
805
|
+
pageNumber: u + 1,
|
|
806
|
+
totalPages: E.length,
|
|
807
|
+
children: m.blocks.map((C, w) => {
|
|
808
|
+
const R = q + w, v = C.trim().toLowerCase(), M = !v.startsWith("<script") && !v.startsWith("<style"), b = v.startsWith("<table"), A = ft(C);
|
|
809
|
+
return A && d ? /* @__PURE__ */ k(
|
|
810
|
+
"div",
|
|
811
|
+
{
|
|
812
|
+
className: "dopecanvas-block-wrapper",
|
|
813
|
+
style: { position: "relative" },
|
|
814
|
+
children: [
|
|
815
|
+
/* @__PURE__ */ r(
|
|
816
|
+
"div",
|
|
817
|
+
{
|
|
818
|
+
className: "dopecanvas-block-content",
|
|
819
|
+
style: { display: "none" },
|
|
820
|
+
dangerouslySetInnerHTML: { __html: C }
|
|
821
|
+
}
|
|
822
|
+
),
|
|
823
|
+
/* @__PURE__ */ k("div", { style: yt, children: [
|
|
824
|
+
/* @__PURE__ */ r("span", { style: He }),
|
|
825
|
+
/* @__PURE__ */ r("span", { style: xt, children: "Page Break" }),
|
|
826
|
+
/* @__PURE__ */ r("span", { style: He }),
|
|
827
|
+
/* @__PURE__ */ r(
|
|
828
|
+
"button",
|
|
829
|
+
{
|
|
830
|
+
type: "button",
|
|
831
|
+
title: "Remove page break",
|
|
832
|
+
onClick: () => Se(R),
|
|
833
|
+
onMouseDown: (X) => X.preventDefault(),
|
|
834
|
+
style: vt,
|
|
835
|
+
children: "✕"
|
|
836
|
+
}
|
|
837
|
+
)
|
|
838
|
+
] })
|
|
839
|
+
]
|
|
840
|
+
},
|
|
841
|
+
`${u}-${w}`
|
|
842
|
+
) : A ? /* @__PURE__ */ r(
|
|
843
|
+
"div",
|
|
844
|
+
{
|
|
845
|
+
className: "dopecanvas-block-wrapper",
|
|
846
|
+
style: { position: "relative" },
|
|
847
|
+
children: /* @__PURE__ */ r(
|
|
848
|
+
"div",
|
|
849
|
+
{
|
|
850
|
+
className: "dopecanvas-block-content",
|
|
851
|
+
dangerouslySetInnerHTML: { __html: C }
|
|
852
|
+
}
|
|
853
|
+
)
|
|
854
|
+
},
|
|
855
|
+
`${u}-${w}`
|
|
856
|
+
) : /* @__PURE__ */ k(
|
|
857
|
+
"div",
|
|
858
|
+
{
|
|
859
|
+
className: "dopecanvas-block-wrapper",
|
|
860
|
+
style: { position: "relative" },
|
|
861
|
+
onMouseEnter: () => {
|
|
862
|
+
M && (se.current && (clearTimeout(se.current), se.current = null), D(R));
|
|
863
|
+
},
|
|
864
|
+
onMouseLeave: () => {
|
|
865
|
+
se.current = setTimeout(() => {
|
|
866
|
+
D(
|
|
867
|
+
(X) => X === R ? null : X
|
|
868
|
+
);
|
|
869
|
+
}, 250);
|
|
870
|
+
},
|
|
871
|
+
children: [
|
|
872
|
+
/* @__PURE__ */ r(
|
|
873
|
+
pt,
|
|
874
|
+
{
|
|
875
|
+
html: C,
|
|
876
|
+
isEditable: M,
|
|
877
|
+
isTable: b
|
|
878
|
+
}
|
|
879
|
+
),
|
|
880
|
+
M && /* @__PURE__ */ r(
|
|
881
|
+
We,
|
|
882
|
+
{
|
|
883
|
+
visible: re === R,
|
|
884
|
+
onAddBelow: () => he(R),
|
|
885
|
+
onEditHTML: () => Ne(R),
|
|
886
|
+
onDelete: () => Se(R)
|
|
887
|
+
}
|
|
888
|
+
)
|
|
889
|
+
]
|
|
890
|
+
},
|
|
891
|
+
`${u}-${w}`
|
|
892
|
+
);
|
|
893
|
+
})
|
|
894
|
+
},
|
|
895
|
+
u
|
|
896
|
+
);
|
|
897
|
+
}),
|
|
898
|
+
E.length === 0 && /* @__PURE__ */ r(
|
|
899
|
+
Me,
|
|
255
900
|
{
|
|
256
|
-
dimensions:
|
|
901
|
+
dimensions: h,
|
|
257
902
|
margins: t.margins,
|
|
258
903
|
pageNumber: 1,
|
|
259
904
|
totalPages: 1,
|
|
260
|
-
children: /* @__PURE__ */
|
|
905
|
+
children: /* @__PURE__ */ r(
|
|
261
906
|
"div",
|
|
262
907
|
{
|
|
263
908
|
contentEditable: "true",
|
|
@@ -267,25 +912,66 @@ const le = ({
|
|
|
267
912
|
)
|
|
268
913
|
}
|
|
269
914
|
)
|
|
270
|
-
] })
|
|
915
|
+
] }),
|
|
916
|
+
G !== null && /* @__PURE__ */ r(
|
|
917
|
+
Ke,
|
|
918
|
+
{
|
|
919
|
+
html: me,
|
|
920
|
+
onSave: Fe,
|
|
921
|
+
onCancel: ze
|
|
922
|
+
}
|
|
923
|
+
)
|
|
271
924
|
] });
|
|
272
|
-
},
|
|
925
|
+
}), bt = {
|
|
273
926
|
flex: 1,
|
|
274
927
|
overflow: "auto",
|
|
275
928
|
backgroundColor: "#e8e8e8",
|
|
276
929
|
display: "flex",
|
|
277
930
|
flexDirection: "column",
|
|
278
931
|
alignItems: "center"
|
|
279
|
-
},
|
|
932
|
+
}, Ct = {
|
|
280
933
|
display: "flex",
|
|
281
934
|
flexDirection: "column",
|
|
282
935
|
alignItems: "center",
|
|
283
936
|
gap: "24px",
|
|
284
937
|
padding: "24px 0"
|
|
938
|
+
}, yt = {
|
|
939
|
+
display: "flex",
|
|
940
|
+
alignItems: "center",
|
|
941
|
+
gap: 8,
|
|
942
|
+
padding: "6px 0",
|
|
943
|
+
userSelect: "none"
|
|
944
|
+
}, He = {
|
|
945
|
+
flex: 1,
|
|
946
|
+
height: 0,
|
|
947
|
+
borderTop: "2px dashed #b0b0b0"
|
|
948
|
+
}, xt = {
|
|
949
|
+
fontSize: 11,
|
|
950
|
+
fontWeight: 600,
|
|
951
|
+
color: "#888",
|
|
952
|
+
textTransform: "uppercase",
|
|
953
|
+
letterSpacing: "0.05em",
|
|
954
|
+
whiteSpace: "nowrap",
|
|
955
|
+
fontFamily: "system-ui, -apple-system, sans-serif"
|
|
956
|
+
}, vt = {
|
|
957
|
+
width: 20,
|
|
958
|
+
height: 20,
|
|
959
|
+
border: "1px solid #ccc",
|
|
960
|
+
borderRadius: 4,
|
|
961
|
+
backgroundColor: "#fff",
|
|
962
|
+
cursor: "pointer",
|
|
963
|
+
display: "flex",
|
|
964
|
+
alignItems: "center",
|
|
965
|
+
justifyContent: "center",
|
|
966
|
+
fontSize: 11,
|
|
967
|
+
color: "#999",
|
|
968
|
+
padding: 0,
|
|
969
|
+
flexShrink: 0,
|
|
970
|
+
lineHeight: 1
|
|
285
971
|
};
|
|
286
|
-
class
|
|
972
|
+
class Ie {
|
|
287
973
|
config;
|
|
288
|
-
constructor(e =
|
|
974
|
+
constructor(e = fe) {
|
|
289
975
|
this.config = { ...e };
|
|
290
976
|
}
|
|
291
977
|
// ----------------------------------------------------------
|
|
@@ -299,7 +985,7 @@ class te {
|
|
|
299
985
|
}
|
|
300
986
|
/** Resolve page size name to pixel dimensions */
|
|
301
987
|
getPageDimensions() {
|
|
302
|
-
return typeof this.config.size == "string" ?
|
|
988
|
+
return typeof this.config.size == "string" ? _e[this.config.size] : this.config.size;
|
|
303
989
|
}
|
|
304
990
|
/** Usable content area height (page height minus top+bottom margins) */
|
|
305
991
|
getContentAreaHeight() {
|
|
@@ -318,18 +1004,18 @@ class te {
|
|
|
318
1004
|
* so that measurements reflect actual rendered heights.
|
|
319
1005
|
*/
|
|
320
1006
|
measureBlocks(e) {
|
|
321
|
-
const t = Array.from(e.children),
|
|
1007
|
+
const t = Array.from(e.children), o = [];
|
|
322
1008
|
for (let n = 0; n < t.length; n++) {
|
|
323
|
-
const
|
|
324
|
-
|
|
1009
|
+
const a = t[n], s = window.getComputedStyle(a), d = s.getPropertyValue("break-before") === "page" || s.getPropertyValue("page-break-before") === "always", c = s.getPropertyValue("break-after") === "page" || s.getPropertyValue("page-break-after") === "always", g = a.getBoundingClientRect(), f = parseFloat(s.marginTop) || 0, P = parseFloat(s.marginBottom) || 0, S = g.height + f + P;
|
|
1010
|
+
o.push({
|
|
325
1011
|
index: n,
|
|
326
|
-
height:
|
|
327
|
-
element:
|
|
328
|
-
breakBefore:
|
|
329
|
-
breakAfter:
|
|
1012
|
+
height: S,
|
|
1013
|
+
element: a,
|
|
1014
|
+
breakBefore: d,
|
|
1015
|
+
breakAfter: c
|
|
330
1016
|
});
|
|
331
1017
|
}
|
|
332
|
-
return
|
|
1018
|
+
return o;
|
|
333
1019
|
}
|
|
334
1020
|
// ----------------------------------------------------------
|
|
335
1021
|
// Pagination
|
|
@@ -347,19 +1033,19 @@ class te {
|
|
|
347
1033
|
paginate(e) {
|
|
348
1034
|
if (e.length === 0)
|
|
349
1035
|
return { pages: [{ blockIndices: [] }], pageCount: 1 };
|
|
350
|
-
const t = this.getContentAreaHeight(),
|
|
351
|
-
let n = [],
|
|
352
|
-
for (let
|
|
353
|
-
const
|
|
354
|
-
|
|
1036
|
+
const t = this.getContentAreaHeight(), o = [];
|
|
1037
|
+
let n = [], a = 0;
|
|
1038
|
+
for (let s = 0; s < e.length; s++) {
|
|
1039
|
+
const d = e[s];
|
|
1040
|
+
d.breakBefore && n.length > 0 && (o.push({ blockIndices: n }), n = [], a = 0), a + d.height > t && n.length > 0 && (o.push({ blockIndices: n }), n = [], a = 0), n.push(d.index), a += d.height, d.breakAfter && (o.push({ blockIndices: n }), n = [], a = 0);
|
|
355
1041
|
}
|
|
356
|
-
return n.length > 0 &&
|
|
357
|
-
pages:
|
|
358
|
-
pageCount:
|
|
1042
|
+
return n.length > 0 && o.push({ blockIndices: n }), o.length === 0 && o.push({ blockIndices: [] }), {
|
|
1043
|
+
pages: o,
|
|
1044
|
+
pageCount: o.length
|
|
359
1045
|
};
|
|
360
1046
|
}
|
|
361
1047
|
}
|
|
362
|
-
class
|
|
1048
|
+
class de {
|
|
363
1049
|
observer = null;
|
|
364
1050
|
changeCallbacks = /* @__PURE__ */ new Set();
|
|
365
1051
|
contextCallbacks = /* @__PURE__ */ new Set();
|
|
@@ -402,12 +1088,12 @@ class z {
|
|
|
402
1088
|
*/
|
|
403
1089
|
makeChildrenEditable(e) {
|
|
404
1090
|
const t = Array.from(e.children);
|
|
405
|
-
for (const
|
|
406
|
-
|
|
1091
|
+
for (const o of t)
|
|
1092
|
+
o.tagName === "TABLE" ? this.makeTableCellsEditable(o) : o.contentEditable = "true";
|
|
407
1093
|
}
|
|
408
1094
|
makeTableCellsEditable(e) {
|
|
409
|
-
e.querySelectorAll("td, th").forEach((
|
|
410
|
-
|
|
1095
|
+
e.querySelectorAll("td, th").forEach((o) => {
|
|
1096
|
+
o.contentEditable = "true";
|
|
411
1097
|
});
|
|
412
1098
|
}
|
|
413
1099
|
// ----------------------------------------------------------
|
|
@@ -416,7 +1102,7 @@ class z {
|
|
|
416
1102
|
handleMutations = (e) => {
|
|
417
1103
|
this.debounceTimer && clearTimeout(this.debounceTimer), this.debounceTimer = setTimeout(() => {
|
|
418
1104
|
this.pushUndoSnapshot(), this.notifyChange();
|
|
419
|
-
},
|
|
1105
|
+
}, de.DEBOUNCE_MS);
|
|
420
1106
|
};
|
|
421
1107
|
// ----------------------------------------------------------
|
|
422
1108
|
// Selection / context detection
|
|
@@ -427,16 +1113,16 @@ class z {
|
|
|
427
1113
|
this.setContext("none");
|
|
428
1114
|
return;
|
|
429
1115
|
}
|
|
430
|
-
const
|
|
431
|
-
let n =
|
|
1116
|
+
const o = e.getRangeAt(0).startContainer;
|
|
1117
|
+
let n = o;
|
|
432
1118
|
for (; n && n !== this.container; ) {
|
|
433
1119
|
if (n instanceof HTMLElement) {
|
|
434
|
-
const
|
|
435
|
-
if (
|
|
1120
|
+
const a = n.tagName;
|
|
1121
|
+
if (a === "TD" || a === "TH" || a === "TABLE") {
|
|
436
1122
|
this.setContext("table");
|
|
437
1123
|
return;
|
|
438
1124
|
}
|
|
439
|
-
if (
|
|
1125
|
+
if (a === "IMG") {
|
|
440
1126
|
this.setContext("image");
|
|
441
1127
|
return;
|
|
442
1128
|
}
|
|
@@ -447,7 +1133,7 @@ class z {
|
|
|
447
1133
|
}
|
|
448
1134
|
n = n.parentNode;
|
|
449
1135
|
}
|
|
450
|
-
this.container.contains(
|
|
1136
|
+
this.container.contains(o) ? this.setContext("text") : this.setContext("none");
|
|
451
1137
|
}
|
|
452
1138
|
setContext(e) {
|
|
453
1139
|
e !== this.currentContext && (this.currentContext = e, this.contextCallbacks.forEach((t) => t(e)));
|
|
@@ -461,7 +1147,7 @@ class z {
|
|
|
461
1147
|
pushUndoSnapshot() {
|
|
462
1148
|
if (!this.container) return;
|
|
463
1149
|
const e = this.container.innerHTML, t = this.undoStack[this.undoStack.length - 1];
|
|
464
|
-
t && t.html === e || (this.undoStack.push({ html: e, timestamp: Date.now() }), this.redoStack = [], this.undoStack.length >
|
|
1150
|
+
t && t.html === e || (this.undoStack.push({ html: e, timestamp: Date.now() }), this.redoStack = [], this.undoStack.length > de.MAX_UNDO_STACK && this.undoStack.shift());
|
|
465
1151
|
}
|
|
466
1152
|
undo() {
|
|
467
1153
|
if (!this.container || this.undoStack.length <= 1) return !1;
|
|
@@ -533,65 +1219,132 @@ class z {
|
|
|
533
1219
|
return this.container && (this.container.innerText || this.container.textContent) || "";
|
|
534
1220
|
}
|
|
535
1221
|
}
|
|
536
|
-
const
|
|
1222
|
+
const Ot = Be(({
|
|
537
1223
|
html: i = "",
|
|
538
1224
|
css: e,
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
1225
|
+
renderMode: t = "paged",
|
|
1226
|
+
pageConfig: o,
|
|
1227
|
+
onContentChange: n,
|
|
1228
|
+
onPageConfigChange: a,
|
|
542
1229
|
style: s
|
|
543
|
-
},
|
|
544
|
-
const [
|
|
545
|
-
|
|
546
|
-
), [
|
|
1230
|
+
}, d) => {
|
|
1231
|
+
const [c, g] = $(
|
|
1232
|
+
o || fe
|
|
1233
|
+
), [f, P] = $({
|
|
547
1234
|
pages: [],
|
|
548
1235
|
pageCount: 0
|
|
549
|
-
}),
|
|
550
|
-
|
|
551
|
-
const
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
}, [
|
|
555
|
-
const
|
|
556
|
-
(
|
|
557
|
-
|
|
1236
|
+
}), S = I(i), E = I(null), y = I(null), L = I(null), [F, Q] = $(!1), re = I(n);
|
|
1237
|
+
re.current = n;
|
|
1238
|
+
const D = o || c, G = Te(() => new Ie(D), []), K = Te(() => new de(), []);
|
|
1239
|
+
Y(() => {
|
|
1240
|
+
G.setConfig(D);
|
|
1241
|
+
}, [D, G]);
|
|
1242
|
+
const me = x(
|
|
1243
|
+
(h) => {
|
|
1244
|
+
S.current = h, re.current?.(h);
|
|
558
1245
|
},
|
|
559
1246
|
[]
|
|
560
|
-
),
|
|
561
|
-
(
|
|
562
|
-
const
|
|
563
|
-
...
|
|
564
|
-
...
|
|
1247
|
+
), ie = x(
|
|
1248
|
+
(h) => {
|
|
1249
|
+
const T = {
|
|
1250
|
+
...D,
|
|
1251
|
+
...h,
|
|
565
1252
|
margins: {
|
|
566
|
-
...
|
|
567
|
-
...
|
|
1253
|
+
...D.margins,
|
|
1254
|
+
...h.margins || {}
|
|
568
1255
|
}
|
|
569
1256
|
};
|
|
570
|
-
|
|
1257
|
+
g(T), G.setConfig(T), a?.(T);
|
|
571
1258
|
},
|
|
572
|
-
[
|
|
573
|
-
),
|
|
574
|
-
|
|
1259
|
+
[D, G, a]
|
|
1260
|
+
), se = x((h) => {
|
|
1261
|
+
P(h);
|
|
575
1262
|
}, []);
|
|
576
|
-
return
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
1263
|
+
return Y(() => {
|
|
1264
|
+
if (t !== "flow" || !y.current) return;
|
|
1265
|
+
const h = S.current || i;
|
|
1266
|
+
y.current.innerHTML = h, S.current = h;
|
|
1267
|
+
}, [i, t]), Pe(d, () => ({
|
|
1268
|
+
execCommand: (h, T) => K.execCommand(h, T),
|
|
1269
|
+
queryCommandState: (h) => K.queryCommandState(h),
|
|
1270
|
+
queryCommandValue: (h) => K.queryCommandValue(h),
|
|
1271
|
+
getPageConfig: () => ({ ...D }),
|
|
1272
|
+
setPageConfig: (h) => {
|
|
1273
|
+
ie(h);
|
|
1274
|
+
},
|
|
1275
|
+
getPageCount: () => f.pageCount,
|
|
1276
|
+
getHTML: () => {
|
|
1277
|
+
if (t === "flow" && y.current) {
|
|
1278
|
+
const h = y.current.innerHTML;
|
|
1279
|
+
return S.current = h, h;
|
|
1280
|
+
}
|
|
1281
|
+
if (E.current) {
|
|
1282
|
+
const h = E.current.querySelectorAll(
|
|
1283
|
+
".dopecanvas-block-content"
|
|
1284
|
+
);
|
|
1285
|
+
if (h.length > 0) {
|
|
1286
|
+
const T = [];
|
|
1287
|
+
if (h.forEach((H) => {
|
|
1288
|
+
const O = H, ee = O.children;
|
|
1289
|
+
if (ee.length !== 0)
|
|
1290
|
+
if (ee.length === 1)
|
|
1291
|
+
T.push(ee[0].outerHTML);
|
|
1292
|
+
else {
|
|
1293
|
+
const te = document.createElement("div");
|
|
1294
|
+
te.innerHTML = O.innerHTML, T.push(te.outerHTML);
|
|
1295
|
+
}
|
|
1296
|
+
}), T.length > 0) {
|
|
1297
|
+
const H = T.join(`
|
|
1298
|
+
`);
|
|
1299
|
+
return S.current = H, H;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
return S.current;
|
|
583
1304
|
},
|
|
584
|
-
getPageCount: () => v.pageCount,
|
|
585
|
-
getHTML: () => d.current,
|
|
586
1305
|
getPlainText: () => {
|
|
587
|
-
|
|
588
|
-
|
|
1306
|
+
if (t === "flow" && y.current)
|
|
1307
|
+
return y.current.innerText || y.current.textContent || "";
|
|
1308
|
+
const h = E.current ? (() => {
|
|
1309
|
+
const H = E.current.querySelectorAll(".dopecanvas-block-content"), O = [];
|
|
1310
|
+
return H.forEach((ee) => {
|
|
1311
|
+
const te = ee, z = te.children;
|
|
1312
|
+
if (z.length !== 0)
|
|
1313
|
+
if (z.length === 1)
|
|
1314
|
+
O.push(z[0].outerHTML);
|
|
1315
|
+
else {
|
|
1316
|
+
const he = document.createElement("div");
|
|
1317
|
+
he.innerHTML = te.innerHTML, O.push(he.outerHTML);
|
|
1318
|
+
}
|
|
1319
|
+
}), O.length > 0 ? O.join(`
|
|
1320
|
+
`) : S.current;
|
|
1321
|
+
})() : S.current, T = document.createElement("div");
|
|
1322
|
+
return T.innerHTML = h, T.innerText || T.textContent || "";
|
|
1323
|
+
},
|
|
1324
|
+
undo: () => K.undo(),
|
|
1325
|
+
redo: () => K.redo(),
|
|
1326
|
+
insertPageBreak: () => {
|
|
1327
|
+
if (t === "flow" && y.current) {
|
|
1328
|
+
const h = window.getSelection();
|
|
1329
|
+
if (!h || h.rangeCount === 0) return;
|
|
1330
|
+
const T = h.getRangeAt(0);
|
|
1331
|
+
if (!y.current.contains(T.startContainer)) return;
|
|
1332
|
+
const H = document.createElement("div");
|
|
1333
|
+
H.style.breakBefore = "page", T.insertNode(H), T.setStartAfter(H), T.collapse(!0), h.removeAllRanges(), h.addRange(T);
|
|
1334
|
+
const O = y.current.innerHTML;
|
|
1335
|
+
S.current = O, re.current?.(O);
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
L.current?.insertPageBreak();
|
|
589
1339
|
},
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
1340
|
+
setShowPageBreaks: (h) => {
|
|
1341
|
+
Q(h);
|
|
1342
|
+
},
|
|
1343
|
+
getShowPageBreaks: () => F
|
|
1344
|
+
}), [K, D, f.pageCount, ie, F, t]), /* @__PURE__ */ r(
|
|
593
1345
|
"div",
|
|
594
1346
|
{
|
|
1347
|
+
ref: E,
|
|
595
1348
|
className: "dopecanvas-root",
|
|
596
1349
|
style: {
|
|
597
1350
|
display: "flex",
|
|
@@ -601,22 +1354,53 @@ const Me = ne(({
|
|
|
601
1354
|
fontFamily: "system-ui, -apple-system, BlinkMacSystemFont, sans-serif",
|
|
602
1355
|
...s
|
|
603
1356
|
},
|
|
604
|
-
children: /* @__PURE__ */
|
|
605
|
-
|
|
1357
|
+
children: t === "paged" ? /* @__PURE__ */ r(
|
|
1358
|
+
mt,
|
|
606
1359
|
{
|
|
1360
|
+
ref: L,
|
|
607
1361
|
html: i,
|
|
608
1362
|
css: e,
|
|
609
|
-
pageConfig:
|
|
610
|
-
layoutEngine:
|
|
611
|
-
editableManager:
|
|
612
|
-
onContentChange:
|
|
613
|
-
onPaginationChange:
|
|
1363
|
+
pageConfig: D,
|
|
1364
|
+
layoutEngine: G,
|
|
1365
|
+
editableManager: K,
|
|
1366
|
+
onContentChange: me,
|
|
1367
|
+
onPaginationChange: se,
|
|
1368
|
+
showPageBreaks: F
|
|
614
1369
|
}
|
|
615
|
-
)
|
|
1370
|
+
) : /* @__PURE__ */ k("div", { style: St, children: [
|
|
1371
|
+
e && /* @__PURE__ */ r("style", { dangerouslySetInnerHTML: { __html: e } }),
|
|
1372
|
+
/* @__PURE__ */ r(
|
|
1373
|
+
"div",
|
|
1374
|
+
{
|
|
1375
|
+
ref: y,
|
|
1376
|
+
className: "dopecanvas-flow-content",
|
|
1377
|
+
contentEditable: !0,
|
|
1378
|
+
suppressContentEditableWarning: !0,
|
|
1379
|
+
style: kt,
|
|
1380
|
+
onInput: () => {
|
|
1381
|
+
if (!y.current) return;
|
|
1382
|
+
const h = y.current.innerHTML;
|
|
1383
|
+
S.current = h, re.current?.(h);
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
)
|
|
1387
|
+
] })
|
|
616
1388
|
}
|
|
617
1389
|
);
|
|
618
|
-
})
|
|
619
|
-
|
|
1390
|
+
}), St = {
|
|
1391
|
+
flex: 1,
|
|
1392
|
+
overflow: "auto",
|
|
1393
|
+
backgroundColor: "#f7f7f5",
|
|
1394
|
+
padding: "24px"
|
|
1395
|
+
}, kt = {
|
|
1396
|
+
minHeight: "100%",
|
|
1397
|
+
outline: "none",
|
|
1398
|
+
backgroundColor: "#fff",
|
|
1399
|
+
border: "1px solid #e5e7eb",
|
|
1400
|
+
borderRadius: 8,
|
|
1401
|
+
padding: "20px 24px"
|
|
1402
|
+
};
|
|
1403
|
+
class Tt {
|
|
620
1404
|
layoutEngine;
|
|
621
1405
|
editableManager;
|
|
622
1406
|
sourceHTML = "";
|
|
@@ -626,8 +1410,8 @@ class he {
|
|
|
626
1410
|
paginationResult = { pages: [], pageCount: 0 };
|
|
627
1411
|
paginationCallbacks = /* @__PURE__ */ new Set();
|
|
628
1412
|
changeCallbacks = /* @__PURE__ */ new Set();
|
|
629
|
-
constructor(e =
|
|
630
|
-
this.layoutEngine = new
|
|
1413
|
+
constructor(e = fe) {
|
|
1414
|
+
this.layoutEngine = new Ie(e), this.editableManager = new de();
|
|
631
1415
|
}
|
|
632
1416
|
// ----------------------------------------------------------
|
|
633
1417
|
// Accessors
|
|
@@ -695,10 +1479,10 @@ class he {
|
|
|
695
1479
|
this.measureContainer.style.width = `${e}px`, this.measureContainer.style.position = "absolute", this.measureContainer.style.left = "-9999px", this.measureContainer.style.top = "0", this.measureContainer.style.visibility = "hidden";
|
|
696
1480
|
let t = null;
|
|
697
1481
|
this.sourceCSS && (t = document.createElement("style"), t.textContent = this.sourceCSS, this.measureContainer.appendChild(t));
|
|
698
|
-
const
|
|
699
|
-
|
|
700
|
-
const n = this.layoutEngine.measureBlocks(
|
|
701
|
-
return this.paginationResult = this.layoutEngine.paginate(n), this.measureContainer.innerHTML = "", this.paginationCallbacks.forEach((
|
|
1482
|
+
const o = document.createElement("div");
|
|
1483
|
+
o.innerHTML = this.sourceHTML, this.measureContainer.appendChild(o);
|
|
1484
|
+
const n = this.layoutEngine.measureBlocks(o);
|
|
1485
|
+
return this.paginationResult = this.layoutEngine.paginate(n), this.measureContainer.innerHTML = "", this.paginationCallbacks.forEach((a) => a(this.paginationResult)), { result: this.paginationResult, measurements: n };
|
|
702
1486
|
}
|
|
703
1487
|
/**
|
|
704
1488
|
* Re-paginate using the current content container's live DOM.
|
|
@@ -757,7 +1541,7 @@ class he {
|
|
|
757
1541
|
this.editableManager.detach(), this.paginationCallbacks.clear(), this.changeCallbacks.clear(), this.measureContainer = null, this.contentContainer = null;
|
|
758
1542
|
}
|
|
759
1543
|
}
|
|
760
|
-
class
|
|
1544
|
+
class $t {
|
|
761
1545
|
_html = "";
|
|
762
1546
|
_css = "";
|
|
763
1547
|
_pageConfig = null;
|
|
@@ -777,7 +1561,7 @@ class Le {
|
|
|
777
1561
|
* Optionally provide CSS to inject alongside.
|
|
778
1562
|
*/
|
|
779
1563
|
loadHTML(e, t) {
|
|
780
|
-
this._html = e, this._css = t || "", this._loadCallbacks.forEach((
|
|
1564
|
+
this._html = e, this._css = t || "", this._loadCallbacks.forEach((o) => o(e, t));
|
|
781
1565
|
}
|
|
782
1566
|
/**
|
|
783
1567
|
* Get the current document HTML content.
|
|
@@ -869,18 +1653,18 @@ class Le {
|
|
|
869
1653
|
getElementContent(e) {
|
|
870
1654
|
const t = document.createElement("div");
|
|
871
1655
|
t.innerHTML = this.getHTML();
|
|
872
|
-
const
|
|
873
|
-
return
|
|
1656
|
+
const o = t.querySelector(`#${e}`);
|
|
1657
|
+
return o ? o.innerHTML : null;
|
|
874
1658
|
}
|
|
875
1659
|
/**
|
|
876
1660
|
* Set the innerHTML of a specific element by its ID.
|
|
877
1661
|
* Re-loads the full document with the modification.
|
|
878
1662
|
*/
|
|
879
1663
|
setElementContent(e, t) {
|
|
880
|
-
const
|
|
881
|
-
|
|
882
|
-
const n =
|
|
883
|
-
n && (n.innerHTML = t, this.loadHTML(
|
|
1664
|
+
const o = document.createElement("div");
|
|
1665
|
+
o.innerHTML = this.getHTML();
|
|
1666
|
+
const n = o.querySelector(`#${e}`);
|
|
1667
|
+
n && (n.innerHTML = t, this.loadHTML(o.innerHTML, this._css));
|
|
884
1668
|
}
|
|
885
1669
|
// ----------------------------------------------------------
|
|
886
1670
|
// Internal connectors (used by DopeCanvas component)
|
|
@@ -906,174 +1690,196 @@ class Le {
|
|
|
906
1690
|
this._pageConfig = e;
|
|
907
1691
|
}
|
|
908
1692
|
}
|
|
909
|
-
function
|
|
910
|
-
const [e, t] =
|
|
911
|
-
return
|
|
1693
|
+
function Vt(i) {
|
|
1694
|
+
const [e, t] = $("none");
|
|
1695
|
+
return Y(() => i ? i.onContextChange((n) => {
|
|
912
1696
|
t(n);
|
|
913
1697
|
}) : void 0, [i]), e;
|
|
914
1698
|
}
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
1699
|
+
const Mt = {
|
|
1700
|
+
bold: !1,
|
|
1701
|
+
italic: !1,
|
|
1702
|
+
underline: !1,
|
|
1703
|
+
strikethrough: !1,
|
|
1704
|
+
justifyLeft: !1,
|
|
1705
|
+
justifyCenter: !1,
|
|
1706
|
+
justifyRight: !1,
|
|
1707
|
+
justifyFull: !1,
|
|
1708
|
+
orderedList: !1,
|
|
1709
|
+
unorderedList: !1,
|
|
1710
|
+
superscript: !1,
|
|
1711
|
+
subscript: !1,
|
|
1712
|
+
fontName: "",
|
|
1713
|
+
fontSize: "3",
|
|
1714
|
+
foreColor: "#000000",
|
|
1715
|
+
backColor: "",
|
|
1716
|
+
formatBlock: "p"
|
|
1717
|
+
};
|
|
1718
|
+
function wt() {
|
|
1719
|
+
const [i, e] = $(Mt), t = x(() => {
|
|
1720
|
+
try {
|
|
1721
|
+
let o = document.queryCommandValue("formatBlock") || "";
|
|
1722
|
+
o = o.replace(/^<|>$/g, "").toLowerCase(), (!o || o === "div") && (o = "p"), e({
|
|
1723
|
+
// Toggle states
|
|
1724
|
+
bold: document.queryCommandState("bold"),
|
|
1725
|
+
italic: document.queryCommandState("italic"),
|
|
1726
|
+
underline: document.queryCommandState("underline"),
|
|
1727
|
+
strikethrough: document.queryCommandState("strikethrough"),
|
|
1728
|
+
justifyLeft: document.queryCommandState("justifyLeft"),
|
|
1729
|
+
justifyCenter: document.queryCommandState("justifyCenter"),
|
|
1730
|
+
justifyRight: document.queryCommandState("justifyRight"),
|
|
1731
|
+
justifyFull: document.queryCommandState("justifyFull"),
|
|
1732
|
+
orderedList: document.queryCommandState("insertOrderedList"),
|
|
1733
|
+
unorderedList: document.queryCommandState("insertUnorderedList"),
|
|
1734
|
+
superscript: document.queryCommandState("superscript"),
|
|
1735
|
+
subscript: document.queryCommandState("subscript"),
|
|
1736
|
+
// Value states
|
|
1737
|
+
fontName: document.queryCommandValue("fontName") || "",
|
|
1738
|
+
fontSize: document.queryCommandValue("fontSize") || "3",
|
|
1739
|
+
foreColor: document.queryCommandValue("foreColor") || "#000000",
|
|
1740
|
+
backColor: document.queryCommandValue("backColor") || "",
|
|
1741
|
+
formatBlock: o
|
|
1742
|
+
});
|
|
1743
|
+
} catch {
|
|
1744
|
+
}
|
|
936
1745
|
}, []);
|
|
937
|
-
return
|
|
1746
|
+
return Y(() => (document.addEventListener("selectionchange", t), () => {
|
|
938
1747
|
document.removeEventListener("selectionchange", t);
|
|
939
1748
|
}), [t]), i;
|
|
940
1749
|
}
|
|
941
|
-
|
|
942
|
-
const
|
|
943
|
-
const
|
|
944
|
-
|
|
945
|
-
}, []),
|
|
946
|
-
const
|
|
947
|
-
if (!
|
|
948
|
-
const
|
|
949
|
-
|
|
950
|
-
}, []),
|
|
951
|
-
(
|
|
952
|
-
|
|
1750
|
+
function Lt() {
|
|
1751
|
+
const i = I(null), e = x(() => {
|
|
1752
|
+
const n = window.getSelection();
|
|
1753
|
+
n && n.rangeCount > 0 && (i.current = n.getRangeAt(0).cloneRange());
|
|
1754
|
+
}, []), t = x(() => {
|
|
1755
|
+
const n = i.current;
|
|
1756
|
+
if (!n) return;
|
|
1757
|
+
const a = window.getSelection();
|
|
1758
|
+
a && (a.removeAllRanges(), a.addRange(n));
|
|
1759
|
+
}, []), o = x(
|
|
1760
|
+
(n) => {
|
|
1761
|
+
t(), n();
|
|
953
1762
|
},
|
|
954
|
-
[
|
|
955
|
-
)
|
|
956
|
-
|
|
957
|
-
|
|
1763
|
+
[t]
|
|
1764
|
+
);
|
|
1765
|
+
return { saveSelection: e, restoreSelection: t, restoreAndExec: o };
|
|
1766
|
+
}
|
|
1767
|
+
const Ht = ({ onExecCommand: i }) => {
|
|
1768
|
+
const e = wt(), { saveSelection: t, restoreAndExec: o } = Lt(), n = x(
|
|
1769
|
+
(c, g) => (f) => {
|
|
1770
|
+
f.preventDefault(), i(c, g);
|
|
958
1771
|
},
|
|
959
|
-
[i
|
|
960
|
-
),
|
|
961
|
-
(c) => {
|
|
962
|
-
|
|
963
|
-
const d = c.target.value;
|
|
964
|
-
d === "p" ? i("formatBlock", "p") : i("formatBlock", d);
|
|
1772
|
+
[i]
|
|
1773
|
+
), a = x(
|
|
1774
|
+
(c) => (g) => {
|
|
1775
|
+
o(() => i(c, g.target.value));
|
|
965
1776
|
},
|
|
966
|
-
[i,
|
|
967
|
-
),
|
|
968
|
-
(c) => {
|
|
969
|
-
|
|
1777
|
+
[i, o]
|
|
1778
|
+
), s = x(
|
|
1779
|
+
(c) => (g) => {
|
|
1780
|
+
o(() => i(c, g.target.value));
|
|
970
1781
|
},
|
|
971
|
-
[i,
|
|
972
|
-
),
|
|
1782
|
+
[i, o]
|
|
1783
|
+
), d = x(
|
|
973
1784
|
(c) => {
|
|
974
|
-
|
|
1785
|
+
c.preventDefault();
|
|
1786
|
+
const g = prompt("Enter URL:");
|
|
1787
|
+
g && i("createLink", g);
|
|
975
1788
|
},
|
|
976
|
-
[i
|
|
1789
|
+
[i]
|
|
977
1790
|
);
|
|
978
|
-
return /* @__PURE__ */
|
|
979
|
-
/* @__PURE__ */
|
|
1791
|
+
return /* @__PURE__ */ k("div", { style: Et, children: [
|
|
1792
|
+
/* @__PURE__ */ k(
|
|
980
1793
|
"select",
|
|
981
1794
|
{
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
style:
|
|
1795
|
+
value: e.formatBlock,
|
|
1796
|
+
onChange: a("formatBlock"),
|
|
1797
|
+
style: ve,
|
|
985
1798
|
title: "Block Format",
|
|
986
|
-
onMouseDown:
|
|
1799
|
+
onMouseDown: t,
|
|
987
1800
|
children: [
|
|
988
|
-
/* @__PURE__ */
|
|
989
|
-
/* @__PURE__ */
|
|
990
|
-
/* @__PURE__ */
|
|
991
|
-
/* @__PURE__ */
|
|
992
|
-
/* @__PURE__ */
|
|
993
|
-
/* @__PURE__ */
|
|
994
|
-
/* @__PURE__ */
|
|
1801
|
+
/* @__PURE__ */ r("option", { value: "p", children: "Paragraph" }),
|
|
1802
|
+
/* @__PURE__ */ r("option", { value: "h1", children: "Heading 1" }),
|
|
1803
|
+
/* @__PURE__ */ r("option", { value: "h2", children: "Heading 2" }),
|
|
1804
|
+
/* @__PURE__ */ r("option", { value: "h3", children: "Heading 3" }),
|
|
1805
|
+
/* @__PURE__ */ r("option", { value: "h4", children: "Heading 4" }),
|
|
1806
|
+
/* @__PURE__ */ r("option", { value: "h5", children: "Heading 5" }),
|
|
1807
|
+
/* @__PURE__ */ r("option", { value: "h6", children: "Heading 6" })
|
|
995
1808
|
]
|
|
996
1809
|
}
|
|
997
1810
|
),
|
|
998
|
-
/* @__PURE__ */
|
|
999
|
-
/* @__PURE__ */
|
|
1811
|
+
/* @__PURE__ */ r(ce, {}),
|
|
1812
|
+
/* @__PURE__ */ k(
|
|
1000
1813
|
"select",
|
|
1001
1814
|
{
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
style:
|
|
1005
|
-
title: "Font
|
|
1006
|
-
onMouseDown:
|
|
1815
|
+
value: e.fontName.replace(/['"]/g, ""),
|
|
1816
|
+
onChange: a("fontName"),
|
|
1817
|
+
style: { ...ve, width: 110 },
|
|
1818
|
+
title: "Font Family",
|
|
1819
|
+
onMouseDown: t,
|
|
1007
1820
|
children: [
|
|
1008
|
-
/* @__PURE__ */
|
|
1009
|
-
/* @__PURE__ */
|
|
1010
|
-
/* @__PURE__ */
|
|
1011
|
-
/* @__PURE__ */
|
|
1012
|
-
/* @__PURE__ */
|
|
1013
|
-
/* @__PURE__ */
|
|
1014
|
-
/* @__PURE__ */
|
|
1821
|
+
/* @__PURE__ */ r("option", { value: "Arial", children: "Arial" }),
|
|
1822
|
+
/* @__PURE__ */ r("option", { value: "Georgia", children: "Georgia" }),
|
|
1823
|
+
/* @__PURE__ */ r("option", { value: "Times New Roman", children: "Times New Roman" }),
|
|
1824
|
+
/* @__PURE__ */ r("option", { value: "Courier New", children: "Courier New" }),
|
|
1825
|
+
/* @__PURE__ */ r("option", { value: "Verdana", children: "Verdana" }),
|
|
1826
|
+
/* @__PURE__ */ r("option", { value: "Trebuchet MS", children: "Trebuchet MS" }),
|
|
1827
|
+
/* @__PURE__ */ r("option", { value: "Comic Sans MS", children: "Comic Sans MS" }),
|
|
1828
|
+
/* @__PURE__ */ r("option", { value: "Impact", children: "Impact" }),
|
|
1829
|
+
/* @__PURE__ */ r("option", { value: "system-ui", children: "System UI" })
|
|
1015
1830
|
]
|
|
1016
1831
|
}
|
|
1017
1832
|
),
|
|
1018
|
-
/* @__PURE__ */
|
|
1019
|
-
|
|
1020
|
-
X,
|
|
1021
|
-
{
|
|
1022
|
-
icon: "B",
|
|
1023
|
-
title: "Bold (Ctrl+B)",
|
|
1024
|
-
active: e.bold,
|
|
1025
|
-
onMouseDown: s("bold"),
|
|
1026
|
-
extraStyle: { fontWeight: "bold" }
|
|
1027
|
-
}
|
|
1028
|
-
),
|
|
1029
|
-
/* @__PURE__ */ o(
|
|
1030
|
-
X,
|
|
1833
|
+
/* @__PURE__ */ k(
|
|
1834
|
+
"select",
|
|
1031
1835
|
{
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1836
|
+
value: e.fontSize,
|
|
1837
|
+
onChange: a("fontSize"),
|
|
1838
|
+
style: { ...ve, width: 56 },
|
|
1839
|
+
title: "Font Size",
|
|
1840
|
+
onMouseDown: t,
|
|
1841
|
+
children: [
|
|
1842
|
+
/* @__PURE__ */ r("option", { value: "1", children: "8" }),
|
|
1843
|
+
/* @__PURE__ */ r("option", { value: "2", children: "10" }),
|
|
1844
|
+
/* @__PURE__ */ r("option", { value: "3", children: "12" }),
|
|
1845
|
+
/* @__PURE__ */ r("option", { value: "4", children: "14" }),
|
|
1846
|
+
/* @__PURE__ */ r("option", { value: "5", children: "18" }),
|
|
1847
|
+
/* @__PURE__ */ r("option", { value: "6", children: "24" }),
|
|
1848
|
+
/* @__PURE__ */ r("option", { value: "7", children: "36" })
|
|
1849
|
+
]
|
|
1037
1850
|
}
|
|
1038
1851
|
),
|
|
1039
|
-
/* @__PURE__ */
|
|
1040
|
-
/* @__PURE__ */
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
/* @__PURE__ */
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
] })
|
|
1852
|
+
/* @__PURE__ */ r(ce, {}),
|
|
1853
|
+
/* @__PURE__ */ r(_, { icon: "B", title: "Bold (Ctrl+B)", active: e.bold, onMouseDown: n("bold"), extraStyle: { fontWeight: 700 } }),
|
|
1854
|
+
/* @__PURE__ */ r(_, { icon: "I", title: "Italic (Ctrl+I)", active: e.italic, onMouseDown: n("italic"), extraStyle: { fontStyle: "italic" } }),
|
|
1855
|
+
/* @__PURE__ */ r(_, { icon: "U", title: "Underline (Ctrl+U)", active: e.underline, onMouseDown: n("underline"), extraStyle: { textDecoration: "underline" } }),
|
|
1856
|
+
/* @__PURE__ */ r(_, { icon: "S", title: "Strikethrough", active: e.strikethrough, onMouseDown: n("strikethrough"), extraStyle: { textDecoration: "line-through" } }),
|
|
1857
|
+
/* @__PURE__ */ r(_, { icon: "x²", title: "Superscript", active: e.superscript, onMouseDown: n("superscript") }),
|
|
1858
|
+
/* @__PURE__ */ r(_, { icon: "x₂", title: "Subscript", active: e.subscript, onMouseDown: n("subscript") }),
|
|
1859
|
+
/* @__PURE__ */ r(ce, {}),
|
|
1860
|
+
/* @__PURE__ */ r(Ee, { label: "A", title: "Text Color", defaultValue: "#000000", onChange: s("foreColor"), onMouseDown: t }),
|
|
1861
|
+
/* @__PURE__ */ r(Ee, { label: "A", title: "Highlight Color", defaultValue: "#ffff00", onChange: s("hiliteColor"), onMouseDown: t, highlight: !0 }),
|
|
1862
|
+
/* @__PURE__ */ r(ce, {}),
|
|
1863
|
+
/* @__PURE__ */ r(_, { icon: "≡", title: "Align Left", active: e.justifyLeft, onMouseDown: n("justifyLeft") }),
|
|
1864
|
+
/* @__PURE__ */ r(_, { icon: "≣", title: "Align Center", active: e.justifyCenter, onMouseDown: n("justifyCenter") }),
|
|
1865
|
+
/* @__PURE__ */ r(_, { icon: "≢", title: "Align Right", active: e.justifyRight, onMouseDown: n("justifyRight") }),
|
|
1866
|
+
/* @__PURE__ */ r(_, { icon: "☰", title: "Justify", active: e.justifyFull, onMouseDown: n("justifyFull") }),
|
|
1867
|
+
/* @__PURE__ */ r(ce, {}),
|
|
1868
|
+
/* @__PURE__ */ r(_, { icon: "•", title: "Bullet List", active: e.unorderedList, onMouseDown: n("insertUnorderedList") }),
|
|
1869
|
+
/* @__PURE__ */ r(_, { icon: "1.", title: "Numbered List", active: e.orderedList, onMouseDown: n("insertOrderedList"), extraStyle: { fontSize: "11px", fontWeight: 600 } }),
|
|
1870
|
+
/* @__PURE__ */ r(_, { icon: "⇤", title: "Decrease Indent", onMouseDown: n("outdent") }),
|
|
1871
|
+
/* @__PURE__ */ r(_, { icon: "⇥", title: "Increase Indent", onMouseDown: n("indent") }),
|
|
1872
|
+
/* @__PURE__ */ r(ce, {}),
|
|
1873
|
+
/* @__PURE__ */ r(_, { icon: "🔗", title: "Insert Link", onMouseDown: d }),
|
|
1874
|
+
/* @__PURE__ */ r(_, { icon: "—", title: "Horizontal Rule", onMouseDown: n("insertHorizontalRule") }),
|
|
1875
|
+
/* @__PURE__ */ r(_, { icon: "T̸", title: "Clear Formatting", onMouseDown: n("removeFormat") })
|
|
1064
1876
|
] });
|
|
1065
|
-
},
|
|
1066
|
-
icon: i,
|
|
1067
|
-
title: e,
|
|
1068
|
-
active: t,
|
|
1069
|
-
onMouseDown: r,
|
|
1070
|
-
extraStyle: n
|
|
1071
|
-
}) => /* @__PURE__ */ o(
|
|
1877
|
+
}, _ = ({ icon: i, title: e, active: t, onMouseDown: o, extraStyle: n }) => /* @__PURE__ */ r(
|
|
1072
1878
|
"button",
|
|
1073
1879
|
{
|
|
1074
1880
|
type: "button",
|
|
1075
1881
|
title: e,
|
|
1076
|
-
onMouseDown:
|
|
1882
|
+
onMouseDown: o,
|
|
1077
1883
|
style: {
|
|
1078
1884
|
width: "28px",
|
|
1079
1885
|
height: "28px",
|
|
@@ -1094,12 +1900,30 @@ const ge = ({ onExecCommand: i }) => {
|
|
|
1094
1900
|
},
|
|
1095
1901
|
dangerouslySetInnerHTML: { __html: i }
|
|
1096
1902
|
}
|
|
1097
|
-
),
|
|
1903
|
+
), ce = () => /* @__PURE__ */ r("div", { style: Rt }), Ee = ({
|
|
1904
|
+
label: i,
|
|
1905
|
+
title: e,
|
|
1906
|
+
defaultValue: t,
|
|
1907
|
+
onChange: o,
|
|
1908
|
+
onMouseDown: n,
|
|
1909
|
+
highlight: a
|
|
1910
|
+
}) => /* @__PURE__ */ k("label", { style: At, title: e, onMouseDown: n, children: [
|
|
1911
|
+
a ? /* @__PURE__ */ r("span", { style: { backgroundColor: "#ffff00", padding: "0 2px" }, children: i }) : i,
|
|
1912
|
+
/* @__PURE__ */ r(
|
|
1913
|
+
"input",
|
|
1914
|
+
{
|
|
1915
|
+
type: "color",
|
|
1916
|
+
defaultValue: t,
|
|
1917
|
+
onChange: o,
|
|
1918
|
+
style: Bt
|
|
1919
|
+
}
|
|
1920
|
+
)
|
|
1921
|
+
] }), Et = {
|
|
1098
1922
|
display: "flex",
|
|
1099
1923
|
alignItems: "center",
|
|
1100
1924
|
gap: "2px",
|
|
1101
1925
|
flexWrap: "wrap"
|
|
1102
|
-
},
|
|
1926
|
+
}, ve = {
|
|
1103
1927
|
height: "28px",
|
|
1104
1928
|
borderWidth: "1px",
|
|
1105
1929
|
borderStyle: "solid",
|
|
@@ -1109,12 +1933,12 @@ const ge = ({ onExecCommand: i }) => {
|
|
|
1109
1933
|
padding: "0 4px",
|
|
1110
1934
|
cursor: "pointer",
|
|
1111
1935
|
backgroundColor: "#fff"
|
|
1112
|
-
},
|
|
1936
|
+
}, Rt = {
|
|
1113
1937
|
width: "1px",
|
|
1114
1938
|
height: "20px",
|
|
1115
1939
|
backgroundColor: "#ddd",
|
|
1116
1940
|
margin: "0 4px"
|
|
1117
|
-
},
|
|
1941
|
+
}, At = {
|
|
1118
1942
|
position: "relative",
|
|
1119
1943
|
width: "28px",
|
|
1120
1944
|
height: "28px",
|
|
@@ -1124,7 +1948,7 @@ const ge = ({ onExecCommand: i }) => {
|
|
|
1124
1948
|
cursor: "pointer",
|
|
1125
1949
|
fontSize: "13px",
|
|
1126
1950
|
fontWeight: "bold"
|
|
1127
|
-
},
|
|
1951
|
+
}, Bt = {
|
|
1128
1952
|
position: "absolute",
|
|
1129
1953
|
bottom: 0,
|
|
1130
1954
|
left: 0,
|
|
@@ -1134,114 +1958,114 @@ const ge = ({ onExecCommand: i }) => {
|
|
|
1134
1958
|
borderWidth: 0,
|
|
1135
1959
|
borderStyle: "none",
|
|
1136
1960
|
cursor: "pointer"
|
|
1137
|
-
},
|
|
1961
|
+
}, Pt = ({
|
|
1138
1962
|
pageConfig: i,
|
|
1139
1963
|
pageCount: e,
|
|
1140
1964
|
onPageConfigChange: t
|
|
1141
1965
|
}) => {
|
|
1142
|
-
const
|
|
1143
|
-
(
|
|
1144
|
-
const
|
|
1145
|
-
t({ size:
|
|
1966
|
+
const o = x(
|
|
1967
|
+
(s) => {
|
|
1968
|
+
const d = s.target.value;
|
|
1969
|
+
t({ size: d });
|
|
1146
1970
|
},
|
|
1147
1971
|
[t]
|
|
1148
|
-
), n =
|
|
1149
|
-
(
|
|
1150
|
-
const
|
|
1972
|
+
), n = x(
|
|
1973
|
+
(s) => (d) => {
|
|
1974
|
+
const c = Math.max(0, parseInt(d.target.value) || 0);
|
|
1151
1975
|
t({
|
|
1152
1976
|
margins: {
|
|
1153
1977
|
...i.margins,
|
|
1154
|
-
[
|
|
1978
|
+
[s]: c
|
|
1155
1979
|
}
|
|
1156
1980
|
});
|
|
1157
1981
|
},
|
|
1158
1982
|
[i.margins, t]
|
|
1159
|
-
),
|
|
1160
|
-
return /* @__PURE__ */
|
|
1161
|
-
/* @__PURE__ */
|
|
1983
|
+
), a = typeof i.size == "string" ? i.size : "custom";
|
|
1984
|
+
return /* @__PURE__ */ k("div", { style: _t, children: [
|
|
1985
|
+
/* @__PURE__ */ k("label", { style: Dt, children: [
|
|
1162
1986
|
"Page:",
|
|
1163
|
-
/* @__PURE__ */
|
|
1987
|
+
/* @__PURE__ */ k(
|
|
1164
1988
|
"select",
|
|
1165
1989
|
{
|
|
1166
|
-
value:
|
|
1167
|
-
onChange:
|
|
1168
|
-
style:
|
|
1990
|
+
value: a,
|
|
1991
|
+
onChange: o,
|
|
1992
|
+
style: It,
|
|
1169
1993
|
children: [
|
|
1170
|
-
/* @__PURE__ */
|
|
1171
|
-
/* @__PURE__ */
|
|
1172
|
-
/* @__PURE__ */
|
|
1994
|
+
/* @__PURE__ */ r("option", { value: "letter", children: "Letter (8.5 x 11)" }),
|
|
1995
|
+
/* @__PURE__ */ r("option", { value: "a4", children: "A4 (210 x 297mm)" }),
|
|
1996
|
+
/* @__PURE__ */ r("option", { value: "legal", children: "Legal (8.5 x 14)" })
|
|
1173
1997
|
]
|
|
1174
1998
|
}
|
|
1175
1999
|
)
|
|
1176
2000
|
] }),
|
|
1177
|
-
/* @__PURE__ */
|
|
1178
|
-
/* @__PURE__ */
|
|
1179
|
-
/* @__PURE__ */
|
|
1180
|
-
|
|
2001
|
+
/* @__PURE__ */ r("div", { style: Re }),
|
|
2002
|
+
/* @__PURE__ */ r("span", { style: { fontSize: "12px", color: "#666" }, children: "Margins (px):" }),
|
|
2003
|
+
/* @__PURE__ */ r(
|
|
2004
|
+
pe,
|
|
1181
2005
|
{
|
|
1182
2006
|
label: "T",
|
|
1183
2007
|
value: i.margins.top,
|
|
1184
2008
|
onChange: n("top")
|
|
1185
2009
|
}
|
|
1186
2010
|
),
|
|
1187
|
-
/* @__PURE__ */
|
|
1188
|
-
|
|
2011
|
+
/* @__PURE__ */ r(
|
|
2012
|
+
pe,
|
|
1189
2013
|
{
|
|
1190
2014
|
label: "R",
|
|
1191
2015
|
value: i.margins.right,
|
|
1192
2016
|
onChange: n("right")
|
|
1193
2017
|
}
|
|
1194
2018
|
),
|
|
1195
|
-
/* @__PURE__ */
|
|
1196
|
-
|
|
2019
|
+
/* @__PURE__ */ r(
|
|
2020
|
+
pe,
|
|
1197
2021
|
{
|
|
1198
2022
|
label: "B",
|
|
1199
2023
|
value: i.margins.bottom,
|
|
1200
2024
|
onChange: n("bottom")
|
|
1201
2025
|
}
|
|
1202
2026
|
),
|
|
1203
|
-
/* @__PURE__ */
|
|
1204
|
-
|
|
2027
|
+
/* @__PURE__ */ r(
|
|
2028
|
+
pe,
|
|
1205
2029
|
{
|
|
1206
2030
|
label: "L",
|
|
1207
2031
|
value: i.margins.left,
|
|
1208
2032
|
onChange: n("left")
|
|
1209
2033
|
}
|
|
1210
2034
|
),
|
|
1211
|
-
/* @__PURE__ */
|
|
1212
|
-
/* @__PURE__ */
|
|
2035
|
+
/* @__PURE__ */ r("div", { style: Re }),
|
|
2036
|
+
/* @__PURE__ */ k("span", { style: { fontSize: "12px", color: "#666" }, children: [
|
|
1213
2037
|
e,
|
|
1214
2038
|
" ",
|
|
1215
2039
|
e === 1 ? "page" : "pages"
|
|
1216
2040
|
] })
|
|
1217
2041
|
] });
|
|
1218
|
-
},
|
|
2042
|
+
}, pe = ({ label: i, value: e, onChange: t }) => /* @__PURE__ */ k("label", { style: Nt, title: `${i} margin`, children: [
|
|
1219
2043
|
i,
|
|
1220
2044
|
":",
|
|
1221
|
-
/* @__PURE__ */
|
|
2045
|
+
/* @__PURE__ */ r(
|
|
1222
2046
|
"input",
|
|
1223
2047
|
{
|
|
1224
2048
|
type: "number",
|
|
1225
2049
|
value: e,
|
|
1226
2050
|
onChange: t,
|
|
1227
|
-
style:
|
|
2051
|
+
style: Ft,
|
|
1228
2052
|
min: 0,
|
|
1229
2053
|
max: 300,
|
|
1230
2054
|
step: 12
|
|
1231
2055
|
}
|
|
1232
2056
|
)
|
|
1233
|
-
] }),
|
|
2057
|
+
] }), _t = {
|
|
1234
2058
|
display: "flex",
|
|
1235
2059
|
alignItems: "center",
|
|
1236
2060
|
gap: "6px",
|
|
1237
2061
|
flexWrap: "wrap"
|
|
1238
|
-
},
|
|
2062
|
+
}, Dt = {
|
|
1239
2063
|
display: "flex",
|
|
1240
2064
|
alignItems: "center",
|
|
1241
2065
|
gap: "4px",
|
|
1242
2066
|
fontSize: "12px",
|
|
1243
2067
|
color: "#666"
|
|
1244
|
-
},
|
|
2068
|
+
}, It = {
|
|
1245
2069
|
height: "26px",
|
|
1246
2070
|
borderWidth: "1px",
|
|
1247
2071
|
borderStyle: "solid",
|
|
@@ -1251,18 +2075,18 @@ const ge = ({ onExecCommand: i }) => {
|
|
|
1251
2075
|
padding: "0 4px",
|
|
1252
2076
|
cursor: "pointer",
|
|
1253
2077
|
backgroundColor: "#fff"
|
|
1254
|
-
},
|
|
2078
|
+
}, Re = {
|
|
1255
2079
|
width: "1px",
|
|
1256
2080
|
height: "20px",
|
|
1257
2081
|
backgroundColor: "#ddd",
|
|
1258
2082
|
margin: "0 4px"
|
|
1259
|
-
},
|
|
2083
|
+
}, Nt = {
|
|
1260
2084
|
display: "flex",
|
|
1261
2085
|
alignItems: "center",
|
|
1262
2086
|
gap: "2px",
|
|
1263
2087
|
fontSize: "11px",
|
|
1264
2088
|
color: "#666"
|
|
1265
|
-
},
|
|
2089
|
+
}, Ft = {
|
|
1266
2090
|
width: "44px",
|
|
1267
2091
|
height: "24px",
|
|
1268
2092
|
borderWidth: "1px",
|
|
@@ -1272,22 +2096,22 @@ const ge = ({ onExecCommand: i }) => {
|
|
|
1272
2096
|
fontSize: "11px",
|
|
1273
2097
|
textAlign: "center",
|
|
1274
2098
|
padding: "0 2px"
|
|
1275
|
-
},
|
|
2099
|
+
}, Ut = ({
|
|
1276
2100
|
pageConfig: i,
|
|
1277
2101
|
pageCount: e,
|
|
1278
2102
|
onExecCommand: t,
|
|
1279
|
-
onPageConfigChange:
|
|
1280
|
-
}) => /* @__PURE__ */
|
|
1281
|
-
/* @__PURE__ */
|
|
1282
|
-
/* @__PURE__ */
|
|
1283
|
-
|
|
2103
|
+
onPageConfigChange: o
|
|
2104
|
+
}) => /* @__PURE__ */ k("div", { style: zt, children: [
|
|
2105
|
+
/* @__PURE__ */ r("div", { style: Ae, children: /* @__PURE__ */ r(Ht, { onExecCommand: t }) }),
|
|
2106
|
+
/* @__PURE__ */ r("div", { style: Ae, children: /* @__PURE__ */ r(
|
|
2107
|
+
Pt,
|
|
1284
2108
|
{
|
|
1285
2109
|
pageConfig: i,
|
|
1286
2110
|
pageCount: e,
|
|
1287
|
-
onPageConfigChange:
|
|
2111
|
+
onPageConfigChange: o
|
|
1288
2112
|
}
|
|
1289
2113
|
) })
|
|
1290
|
-
] }),
|
|
2114
|
+
] }), zt = {
|
|
1291
2115
|
borderBottomWidth: "1px",
|
|
1292
2116
|
borderBottomStyle: "solid",
|
|
1293
2117
|
borderBottomColor: "#d0d0d0",
|
|
@@ -1298,59 +2122,62 @@ const ge = ({ onExecCommand: i }) => {
|
|
|
1298
2122
|
gap: "4px",
|
|
1299
2123
|
flexShrink: 0,
|
|
1300
2124
|
zIndex: 10
|
|
1301
|
-
},
|
|
2125
|
+
}, Ae = {
|
|
1302
2126
|
display: "flex",
|
|
1303
2127
|
alignItems: "center",
|
|
1304
2128
|
gap: "4px",
|
|
1305
2129
|
minHeight: "32px"
|
|
1306
2130
|
};
|
|
1307
|
-
function
|
|
2131
|
+
function Gt(i = {}) {
|
|
1308
2132
|
const {
|
|
1309
2133
|
initialHTML: e = "",
|
|
1310
2134
|
initialCSS: t = "",
|
|
1311
|
-
initialConfig:
|
|
1312
|
-
} = i, n =
|
|
2135
|
+
initialConfig: o = fe
|
|
2136
|
+
} = i, n = I(new Tt(o)), [a, s] = $({
|
|
1313
2137
|
pages: [{ blockIndices: [] }],
|
|
1314
2138
|
pageCount: 1
|
|
1315
|
-
}), [
|
|
1316
|
-
n.current.loadHTML(
|
|
1317
|
-
}, []),
|
|
1318
|
-
n.current.setPageConfig(
|
|
1319
|
-
}, []),
|
|
1320
|
-
const { result:
|
|
1321
|
-
|
|
1322
|
-
}, []),
|
|
1323
|
-
return
|
|
2139
|
+
}), [d, c] = $(o), g = x((y, L) => {
|
|
2140
|
+
n.current.loadHTML(y, L);
|
|
2141
|
+
}, []), f = x((y) => {
|
|
2142
|
+
n.current.setPageConfig(y), c(n.current.getPageConfig());
|
|
2143
|
+
}, []), P = x(() => {
|
|
2144
|
+
const { result: y } = n.current.runPagination();
|
|
2145
|
+
s(y);
|
|
2146
|
+
}, []), S = x(() => n.current.getHTML(), []), E = x(() => n.current.getPlainText(), []);
|
|
2147
|
+
return Y(() => {
|
|
1324
2148
|
e && n.current.loadHTML(e, t);
|
|
1325
|
-
}, [e, t]),
|
|
1326
|
-
|
|
1327
|
-
}), []),
|
|
2149
|
+
}, [e, t]), Y(() => n.current.onPagination((L) => {
|
|
2150
|
+
s(L);
|
|
2151
|
+
}), []), Y(() => () => {
|
|
1328
2152
|
n.current.destroy();
|
|
1329
2153
|
}, []), {
|
|
1330
2154
|
engine: n.current,
|
|
1331
|
-
paginationResult:
|
|
1332
|
-
pageConfig:
|
|
1333
|
-
loadHTML:
|
|
1334
|
-
setPageConfig:
|
|
1335
|
-
triggerPagination:
|
|
1336
|
-
getHTML:
|
|
1337
|
-
getPlainText:
|
|
2155
|
+
paginationResult: a,
|
|
2156
|
+
pageConfig: d,
|
|
2157
|
+
loadHTML: g,
|
|
2158
|
+
setPageConfig: f,
|
|
2159
|
+
triggerPagination: P,
|
|
2160
|
+
getHTML: S,
|
|
2161
|
+
getPlainText: E
|
|
1338
2162
|
};
|
|
1339
2163
|
}
|
|
1340
2164
|
export {
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
2165
|
+
nt as DEFAULT_MARGINS,
|
|
2166
|
+
fe as DEFAULT_PAGE_CONFIG,
|
|
2167
|
+
$t as DocumentAPI,
|
|
2168
|
+
Tt as DocumentEngine,
|
|
2169
|
+
Ot as DopeCanvas,
|
|
2170
|
+
de as EditableManager,
|
|
2171
|
+
_e as PAGE_SIZE_PRESETS,
|
|
2172
|
+
Ie as PageLayoutEngine,
|
|
2173
|
+
Pt as PageSetupToolbar,
|
|
2174
|
+
Ht as TextToolbar,
|
|
2175
|
+
Ut as Toolbar,
|
|
2176
|
+
at as recombineSplitBlocks,
|
|
2177
|
+
ge as trySplitBlock,
|
|
2178
|
+
Gt as useDocumentEngine,
|
|
2179
|
+
wt as useFormattingState,
|
|
2180
|
+
Vt as useSelectionContext,
|
|
2181
|
+
Lt as useSelectionSaver
|
|
1355
2182
|
};
|
|
1356
2183
|
//# sourceMappingURL=dopecanvas.js.map
|