dopecanvas 0.1.2 → 0.1.3
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/dopecanvas.cjs +8 -3
- package/dist/dopecanvas.cjs.map +1 -1
- package/dist/dopecanvas.js +777 -458
- package/dist/dopecanvas.js.map +1 -1
- package/package.json +1 -1
package/dist/dopecanvas.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { jsxs as C, jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import be, { useState as R, useRef as H, useCallback as h, useEffect as F, forwardRef as Ce, useMemo as ne, useImperativeHandle as ye } from "react";
|
|
3
|
+
import { createPortal as xe } from "react-dom";
|
|
4
|
+
const oe = ({
|
|
5
|
+
dimensions: s,
|
|
5
6
|
margins: e,
|
|
6
7
|
pageNumber: t,
|
|
7
|
-
totalPages:
|
|
8
|
-
children:
|
|
9
|
-
}) => /* @__PURE__ */
|
|
8
|
+
totalPages: n,
|
|
9
|
+
children: o
|
|
10
|
+
}) => /* @__PURE__ */ C(
|
|
10
11
|
"div",
|
|
11
12
|
{
|
|
12
13
|
className: "dopecanvas-page",
|
|
13
14
|
style: {
|
|
14
|
-
width: `${
|
|
15
|
-
height: `${
|
|
15
|
+
width: `${s.width}px`,
|
|
16
|
+
height: `${s.height}px`,
|
|
16
17
|
backgroundColor: "#ffffff",
|
|
17
18
|
boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15), 0 0 1px rgba(0, 0, 0, 0.1)",
|
|
18
19
|
position: "relative",
|
|
@@ -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",
|
|
@@ -33,10 +34,10 @@ const G = ({
|
|
|
33
34
|
boxSizing: "border-box",
|
|
34
35
|
overflow: "hidden"
|
|
35
36
|
},
|
|
36
|
-
children:
|
|
37
|
+
children: o
|
|
37
38
|
}
|
|
38
39
|
),
|
|
39
|
-
/* @__PURE__ */
|
|
40
|
+
/* @__PURE__ */ C(
|
|
40
41
|
"div",
|
|
41
42
|
{
|
|
42
43
|
className: "dopecanvas-page-number",
|
|
@@ -55,209 +56,493 @@ const G = ({
|
|
|
55
56
|
children: [
|
|
56
57
|
t,
|
|
57
58
|
" / ",
|
|
58
|
-
|
|
59
|
+
n
|
|
59
60
|
]
|
|
60
61
|
}
|
|
61
62
|
)
|
|
62
63
|
]
|
|
63
64
|
}
|
|
64
|
-
),
|
|
65
|
+
), ve = ({
|
|
66
|
+
visible: s,
|
|
67
|
+
onAddBelow: e,
|
|
68
|
+
onEditHTML: t,
|
|
69
|
+
onDelete: n
|
|
70
|
+
}) => /* @__PURE__ */ C(
|
|
71
|
+
"div",
|
|
72
|
+
{
|
|
73
|
+
className: "dopecanvas-block-toolbar",
|
|
74
|
+
style: {
|
|
75
|
+
...Me,
|
|
76
|
+
display: s ? "flex" : "none"
|
|
77
|
+
},
|
|
78
|
+
onMouseDown: (o) => o.preventDefault(),
|
|
79
|
+
children: [
|
|
80
|
+
/* @__PURE__ */ r(X, { onClick: e, title: "Add block below", children: /* @__PURE__ */ r(Se, {}) }),
|
|
81
|
+
/* @__PURE__ */ r(X, { onClick: t, title: "Edit HTML", children: /* @__PURE__ */ r(ke, {}) }),
|
|
82
|
+
/* @__PURE__ */ r(X, { onClick: n, title: "Delete block", danger: !0, children: /* @__PURE__ */ r(Te, {}) })
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
), Se = () => /* @__PURE__ */ C("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
|
+
] }), ke = () => /* @__PURE__ */ C("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
|
+
] }), Te = () => /* @__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" }) }), X = ({ onClick: s, title: e, children: t, danger: n }) => {
|
|
92
|
+
const [o, a] = R(!1);
|
|
93
|
+
return /* @__PURE__ */ r(
|
|
94
|
+
"button",
|
|
95
|
+
{
|
|
96
|
+
onClick: s,
|
|
97
|
+
title: e,
|
|
98
|
+
onMouseEnter: () => a(!0),
|
|
99
|
+
onMouseLeave: () => a(!1),
|
|
100
|
+
style: {
|
|
101
|
+
...Le,
|
|
102
|
+
background: o ? n ? "#fff0f0" : "#f0f0f0" : "transparent",
|
|
103
|
+
color: o && n ? "#d32f2f" : "#666"
|
|
104
|
+
},
|
|
105
|
+
children: t
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}, Me = {
|
|
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
|
+
}, Le = {
|
|
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
|
+
}, He = ({
|
|
134
|
+
html: s,
|
|
135
|
+
onSave: e,
|
|
136
|
+
onCancel: t
|
|
137
|
+
}) => {
|
|
138
|
+
const [n, o] = R(s);
|
|
139
|
+
return xe(
|
|
140
|
+
/* @__PURE__ */ r("div", { style: Ee, onClick: t, children: /* @__PURE__ */ C("div", { style: we, onClick: (i) => i.stopPropagation(), children: [
|
|
141
|
+
/* @__PURE__ */ C("div", { style: Re, 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: Pe,
|
|
149
|
+
value: n,
|
|
150
|
+
onChange: (i) => o(i.target.value),
|
|
151
|
+
onKeyDown: (i) => {
|
|
152
|
+
if (i.key === "Enter" && (i.metaKey || i.ctrlKey) && (i.preventDefault(), e(n)), i.key === "Escape" && (i.preventDefault(), t()), i.key === "Tab") {
|
|
153
|
+
i.preventDefault();
|
|
154
|
+
const c = i.target, g = c.selectionStart, S = c.selectionEnd, d = n.substring(0, g) + " " + n.substring(S);
|
|
155
|
+
o(d), requestAnimationFrame(() => {
|
|
156
|
+
c.selectionStart = c.selectionEnd = g + 2;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
spellCheck: !1,
|
|
161
|
+
autoFocus: !0
|
|
162
|
+
}
|
|
163
|
+
),
|
|
164
|
+
/* @__PURE__ */ C("div", { style: _e, children: [
|
|
165
|
+
/* @__PURE__ */ r(
|
|
166
|
+
"button",
|
|
167
|
+
{
|
|
168
|
+
style: Ae,
|
|
169
|
+
onClick: t,
|
|
170
|
+
onMouseEnter: (i) => {
|
|
171
|
+
i.target.style.borderColor = "#888";
|
|
172
|
+
},
|
|
173
|
+
onMouseLeave: (i) => {
|
|
174
|
+
i.target.style.borderColor = "#555";
|
|
175
|
+
},
|
|
176
|
+
children: "Cancel"
|
|
177
|
+
}
|
|
178
|
+
),
|
|
179
|
+
/* @__PURE__ */ r(
|
|
180
|
+
"button",
|
|
181
|
+
{
|
|
182
|
+
style: De,
|
|
183
|
+
onClick: () => e(n),
|
|
184
|
+
onMouseEnter: (i) => {
|
|
185
|
+
i.target.style.background = "#0055dd";
|
|
186
|
+
},
|
|
187
|
+
onMouseLeave: (i) => {
|
|
188
|
+
i.target.style.background = "#0066ff";
|
|
189
|
+
},
|
|
190
|
+
children: "Save"
|
|
191
|
+
}
|
|
192
|
+
)
|
|
193
|
+
] })
|
|
194
|
+
] }) }),
|
|
195
|
+
document.body
|
|
196
|
+
);
|
|
197
|
+
}, Ee = {
|
|
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
|
+
}, we = {
|
|
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
|
+
}, Re = {
|
|
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
|
+
}, Pe = {
|
|
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
|
+
}, _e = {
|
|
235
|
+
display: "flex",
|
|
236
|
+
justifyContent: "flex-end",
|
|
237
|
+
gap: "8px",
|
|
238
|
+
padding: "12px 16px",
|
|
239
|
+
background: "#2d2d2d",
|
|
240
|
+
borderTop: "1px solid #444"
|
|
241
|
+
}, Ae = {
|
|
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
|
+
}, De = {
|
|
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
|
+
}, ue = {
|
|
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
|
+
}, Ie = {
|
|
72
268
|
top: 96,
|
|
73
269
|
right: 96,
|
|
74
270
|
bottom: 96,
|
|
75
271
|
left: 96
|
|
76
|
-
},
|
|
272
|
+
}, G = {
|
|
77
273
|
size: "letter",
|
|
78
|
-
margins: { ...
|
|
274
|
+
margins: { ...Ie }
|
|
79
275
|
};
|
|
80
|
-
function
|
|
276
|
+
function Be(s) {
|
|
81
277
|
const e = [];
|
|
82
|
-
return
|
|
83
|
-
const
|
|
278
|
+
return s.querySelectorAll("script").forEach((t) => {
|
|
279
|
+
const n = document.createElement("script");
|
|
84
280
|
Array.from(t.attributes).forEach(
|
|
85
|
-
(
|
|
86
|
-
),
|
|
281
|
+
(o) => n.setAttribute(o.name, o.value)
|
|
282
|
+
), n.textContent = t.textContent || "", t.parentNode?.replaceChild(n, t), e.push(n);
|
|
87
283
|
}), e;
|
|
88
284
|
}
|
|
89
|
-
function
|
|
285
|
+
function ze(s) {
|
|
90
286
|
const e = window.getSelection();
|
|
91
287
|
if (!e || e.rangeCount === 0) return null;
|
|
92
|
-
const t = e.getRangeAt(0),
|
|
93
|
-
|
|
94
|
-
),
|
|
95
|
-
if (
|
|
288
|
+
const t = e.getRangeAt(0), n = t.startContainer, o = Array.from(
|
|
289
|
+
s.querySelectorAll(".dopecanvas-block-content")
|
|
290
|
+
), a = o.findIndex((i) => i.contains(n));
|
|
291
|
+
if (a === -1) return null;
|
|
96
292
|
try {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
return { blockIndex:
|
|
293
|
+
const i = document.createRange();
|
|
294
|
+
i.selectNodeContents(o[a]), i.setEnd(t.startContainer, t.startOffset);
|
|
295
|
+
const c = i.toString().length;
|
|
296
|
+
return { blockIndex: a, textOffset: c };
|
|
101
297
|
} catch {
|
|
102
298
|
return null;
|
|
103
299
|
}
|
|
104
300
|
}
|
|
105
|
-
function
|
|
106
|
-
const t =
|
|
301
|
+
function Fe(s, e) {
|
|
302
|
+
const t = s.querySelectorAll(".dopecanvas-block-content");
|
|
107
303
|
if (e.blockIndex >= t.length) return;
|
|
108
|
-
const
|
|
109
|
-
let
|
|
110
|
-
for (;
|
|
111
|
-
const
|
|
112
|
-
if (
|
|
304
|
+
const n = t[e.blockIndex], o = document.createTreeWalker(n, NodeFilter.SHOW_TEXT);
|
|
305
|
+
let a = e.textOffset;
|
|
306
|
+
for (; o.nextNode(); ) {
|
|
307
|
+
const i = o.currentNode;
|
|
308
|
+
if (a <= i.length) {
|
|
113
309
|
try {
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
310
|
+
const c = document.createRange();
|
|
311
|
+
c.setStart(i, a), c.collapse(!0);
|
|
312
|
+
const g = window.getSelection();
|
|
313
|
+
g?.removeAllRanges(), g?.addRange(c);
|
|
118
314
|
} catch {
|
|
119
315
|
}
|
|
120
316
|
return;
|
|
121
317
|
}
|
|
122
|
-
|
|
318
|
+
a -= i.length;
|
|
123
319
|
}
|
|
124
320
|
try {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
|
|
321
|
+
const i = document.createRange();
|
|
322
|
+
i.selectNodeContents(n), i.collapse(!1);
|
|
323
|
+
const c = window.getSelection();
|
|
324
|
+
c?.removeAllRanges(), c?.addRange(i);
|
|
129
325
|
} catch {
|
|
130
326
|
}
|
|
131
327
|
}
|
|
132
|
-
const
|
|
133
|
-
|
|
328
|
+
const qe = be.memo(({ html: s, isEditable: e, isTable: t }) => /* @__PURE__ */ r(
|
|
329
|
+
"div",
|
|
330
|
+
{
|
|
331
|
+
className: "dopecanvas-block-content",
|
|
332
|
+
contentEditable: e && !t ? !0 : void 0,
|
|
333
|
+
suppressContentEditableWarning: !0,
|
|
334
|
+
dangerouslySetInnerHTML: { __html: s }
|
|
335
|
+
}
|
|
336
|
+
)), Ne = ({
|
|
337
|
+
html: s,
|
|
134
338
|
css: e,
|
|
135
339
|
pageConfig: t,
|
|
136
|
-
layoutEngine:
|
|
137
|
-
editableManager:
|
|
138
|
-
onContentChange:
|
|
139
|
-
onPaginationChange:
|
|
340
|
+
layoutEngine: n,
|
|
341
|
+
editableManager: o,
|
|
342
|
+
onContentChange: a,
|
|
343
|
+
onPaginationChange: i
|
|
140
344
|
}) => {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
const [
|
|
144
|
-
if (!
|
|
145
|
-
const
|
|
146
|
-
".dopecanvas-block-
|
|
147
|
-
),
|
|
148
|
-
|
|
149
|
-
const f =
|
|
150
|
-
f &&
|
|
345
|
+
const c = H(null), g = H(null), S = H(null), d = H(a);
|
|
346
|
+
d.current = a;
|
|
347
|
+
const [p, k] = R([]), A = H(null), y = H(!1), E = H([]), [D, q] = R(null), [B, j] = R(null), [m, x] = R(""), P = H(null), I = typeof t.size == "string" ? ue[t.size] : t.size, V = h(() => {
|
|
348
|
+
if (!g.current) return;
|
|
349
|
+
const u = g.current.querySelectorAll(
|
|
350
|
+
".dopecanvas-block-content"
|
|
351
|
+
), l = [];
|
|
352
|
+
u.forEach((b) => {
|
|
353
|
+
const f = b.firstElementChild;
|
|
354
|
+
f && l.push(f.outerHTML);
|
|
151
355
|
});
|
|
152
|
-
const
|
|
356
|
+
const w = l.join(`
|
|
153
357
|
`);
|
|
154
|
-
|
|
155
|
-
}, []),
|
|
156
|
-
if (!
|
|
157
|
-
const
|
|
158
|
-
if (
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
}), y.length === 0) return;
|
|
162
|
-
const f = l.current, P = r.getContentAreaWidth();
|
|
163
|
-
if (f.style.width = `${P}px`, f.style.position = "absolute", f.style.left = "-9999px", f.style.top = "0", f.style.visibility = "hidden", f.innerHTML = "", e) {
|
|
164
|
-
const S = document.createElement("style");
|
|
165
|
-
S.textContent = e, f.appendChild(S);
|
|
166
|
-
}
|
|
167
|
-
const k = document.createElement("div");
|
|
168
|
-
k.innerHTML = y.join(`
|
|
169
|
-
`), f.appendChild(k);
|
|
170
|
-
const A = r.measureBlocks(k), I = A.map(
|
|
171
|
-
(S) => S.element.cloneNode(!0).outerHTML
|
|
172
|
-
), w = r.paginate(A);
|
|
173
|
-
f.innerHTML = "";
|
|
174
|
-
const q = w.pages.map((S) => ({
|
|
175
|
-
blocks: S.blockIndices.map((D) => I[D])
|
|
176
|
-
})), $ = b.current.map((S) => S.blocks.length), V = q.map((S) => S.blocks.length);
|
|
177
|
-
($.length !== V.length || $.some((S, D) => S !== V[D])) && (C.current = !0, m.current = H, b.current = q, L(q), a?.(w));
|
|
178
|
-
}, [e, r, a]), u = M(N);
|
|
179
|
-
u.current = N;
|
|
180
|
-
const E = p(() => {
|
|
181
|
-
if (!l.current) return;
|
|
182
|
-
const g = l.current, H = r.getContentAreaWidth();
|
|
183
|
-
if (g.style.width = `${H}px`, g.style.position = "absolute", g.style.left = "-9999px", g.style.top = "0", g.style.visibility = "hidden", g.innerHTML = "", e) {
|
|
184
|
-
const w = document.createElement("style");
|
|
185
|
-
w.textContent = e, g.appendChild(w);
|
|
358
|
+
d.current?.(w);
|
|
359
|
+
}, []), _ = h((u) => {
|
|
360
|
+
if (!c.current) return;
|
|
361
|
+
const l = c.current;
|
|
362
|
+
if (l.style.width = `${n.getContentAreaWidth()}px`, l.style.position = "absolute", l.style.left = "-9999px", l.style.top = "0", l.style.visibility = "hidden", l.innerHTML = "", e) {
|
|
363
|
+
const M = document.createElement("style");
|
|
364
|
+
M.textContent = e, l.appendChild(M);
|
|
186
365
|
}
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const P = r.measureBlocks(f), k = P.map(
|
|
194
|
-
(w) => w.element.cloneNode(!0).outerHTML
|
|
195
|
-
), A = r.paginate(P), I = A.pages.map((w) => ({
|
|
196
|
-
blocks: w.blockIndices.map((q) => k[q])
|
|
366
|
+
const w = document.createElement("div");
|
|
367
|
+
w.innerHTML = u, l.appendChild(w);
|
|
368
|
+
const b = n.measureBlocks(w), f = b.map(
|
|
369
|
+
(M) => M.element.cloneNode(!0).outerHTML
|
|
370
|
+
), v = n.paginate(b), T = v.pages.map((M) => ({
|
|
371
|
+
blocks: M.blockIndices.map((N) => f[N])
|
|
197
372
|
}));
|
|
198
|
-
|
|
199
|
-
}, [
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
373
|
+
l.innerHTML = "", E.current = T, k(T), i?.(v), d.current?.(u);
|
|
374
|
+
}, [e, n, i]), J = h(() => {
|
|
375
|
+
if (!g.current || !c.current) return;
|
|
376
|
+
const u = g.current, l = ze(u), w = u.querySelectorAll(".dopecanvas-block-content"), b = [];
|
|
377
|
+
if (w.forEach((L) => {
|
|
378
|
+
const W = L.firstElementChild;
|
|
379
|
+
W && b.push(W.outerHTML);
|
|
380
|
+
}), b.length === 0) return;
|
|
381
|
+
const f = c.current, v = n.getContentAreaWidth();
|
|
382
|
+
if (f.style.width = `${v}px`, f.style.position = "absolute", f.style.left = "-9999px", f.style.top = "0", f.style.visibility = "hidden", f.innerHTML = "", e) {
|
|
383
|
+
const L = document.createElement("style");
|
|
384
|
+
L.textContent = e, f.appendChild(L);
|
|
385
|
+
}
|
|
386
|
+
const T = document.createElement("div");
|
|
387
|
+
T.innerHTML = b.join(`
|
|
388
|
+
`), f.appendChild(T);
|
|
389
|
+
const M = n.measureBlocks(T), N = M.map(
|
|
390
|
+
(L) => L.element.cloneNode(!0).outerHTML
|
|
391
|
+
), O = n.paginate(M);
|
|
392
|
+
f.innerHTML = "";
|
|
393
|
+
const K = O.pages.map((L) => ({
|
|
394
|
+
blocks: L.blockIndices.map((W) => N[W])
|
|
395
|
+
})), ee = E.current.map((L) => L.blocks.length), te = K.map((L) => L.blocks.length);
|
|
396
|
+
(ee.length !== te.length || ee.some((L, W) => L !== te[W])) && (y.current = !0, A.current = l, E.current = K, k(K), i?.(O));
|
|
397
|
+
}, [e, n, i]), Q = H(J);
|
|
398
|
+
Q.current = J;
|
|
399
|
+
const Y = h(() => {
|
|
400
|
+
const u = new DOMParser().parseFromString(s, "text/html");
|
|
401
|
+
u.head.querySelectorAll('style, link[rel="stylesheet"]').forEach((l) => {
|
|
402
|
+
u.body.insertBefore(l, u.body.firstChild);
|
|
403
|
+
}), _(u.body.innerHTML);
|
|
404
|
+
}, [s, _]);
|
|
405
|
+
F(() => {
|
|
406
|
+
Y();
|
|
407
|
+
}, [Y]);
|
|
408
|
+
const z = h(() => {
|
|
409
|
+
if (!g.current) return [];
|
|
410
|
+
const u = g.current.querySelectorAll(
|
|
411
|
+
".dopecanvas-block-content"
|
|
412
|
+
), l = [];
|
|
413
|
+
return u.forEach((w) => {
|
|
414
|
+
const b = w.firstElementChild;
|
|
415
|
+
b && l.push(b.outerHTML);
|
|
416
|
+
}), l;
|
|
417
|
+
}, []), he = h(
|
|
418
|
+
(u) => {
|
|
419
|
+
const l = z();
|
|
420
|
+
l.splice(
|
|
421
|
+
u + 1,
|
|
422
|
+
0,
|
|
423
|
+
'<p style="min-height: 1.5em; line-height: 1.6;"> </p>'
|
|
424
|
+
), q(null), _(l.join(`
|
|
425
|
+
`));
|
|
426
|
+
},
|
|
427
|
+
[z, _]
|
|
428
|
+
), ge = h(
|
|
429
|
+
(u) => {
|
|
430
|
+
const l = z();
|
|
431
|
+
l.length <= 1 || (l.splice(u, 1), q(null), _(l.join(`
|
|
432
|
+
`)));
|
|
433
|
+
},
|
|
434
|
+
[z, _]
|
|
435
|
+
), pe = h(
|
|
436
|
+
(u) => {
|
|
437
|
+
const l = z();
|
|
438
|
+
u < l.length && (j(u), x(l[u]));
|
|
439
|
+
},
|
|
440
|
+
[z]
|
|
441
|
+
), fe = h(
|
|
442
|
+
(u) => {
|
|
443
|
+
if (B === null) return;
|
|
444
|
+
const l = z();
|
|
445
|
+
B < l.length && (l[B] = u), j(null), x(""), q(null), _(l.join(`
|
|
446
|
+
`));
|
|
447
|
+
},
|
|
448
|
+
[B, z, _]
|
|
449
|
+
), me = h(() => {
|
|
450
|
+
j(null), x("");
|
|
451
|
+
}, []);
|
|
452
|
+
return F(() => {
|
|
453
|
+
const u = g.current;
|
|
454
|
+
if (!u) return;
|
|
455
|
+
S.current && S.current.disconnect(), u.querySelectorAll(".dopecanvas-block-content").forEach((v) => {
|
|
456
|
+
const T = v.firstElementChild;
|
|
457
|
+
T && T.tagName === "TABLE" && T.querySelectorAll("td, th").forEach((N) => {
|
|
458
|
+
N.contentEditable = "true";
|
|
459
|
+
});
|
|
210
460
|
});
|
|
211
|
-
const
|
|
212
|
-
let
|
|
461
|
+
const w = Be(u);
|
|
462
|
+
let b = null;
|
|
213
463
|
const f = new MutationObserver(() => {
|
|
214
|
-
|
|
215
|
-
|
|
464
|
+
y.current || (b && clearTimeout(b), b = setTimeout(() => {
|
|
465
|
+
V(), Q.current();
|
|
216
466
|
}, 300));
|
|
217
467
|
});
|
|
218
|
-
return f.observe(
|
|
468
|
+
return f.observe(u, {
|
|
219
469
|
childList: !0,
|
|
220
470
|
subtree: !0,
|
|
221
471
|
characterData: !0,
|
|
222
472
|
attributes: !1
|
|
223
|
-
}),
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
),
|
|
228
|
-
}) :
|
|
229
|
-
f.disconnect(),
|
|
473
|
+
}), S.current = f, A.current ? requestAnimationFrame(() => {
|
|
474
|
+
A.current && g.current && (Fe(
|
|
475
|
+
g.current,
|
|
476
|
+
A.current
|
|
477
|
+
), A.current = null), y.current = !1;
|
|
478
|
+
}) : y.current = !1, () => {
|
|
479
|
+
f.disconnect(), w.forEach((v) => v.remove()), b && clearTimeout(b);
|
|
230
480
|
};
|
|
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
|
-
|
|
481
|
+
}, [p, V]), /* @__PURE__ */ C("div", { className: "dopecanvas-paged-view", style: We, children: [
|
|
482
|
+
/* @__PURE__ */ r("div", { ref: c, "aria-hidden": "true" }),
|
|
483
|
+
/* @__PURE__ */ C("div", { ref: g, style: je, children: [
|
|
484
|
+
e && /* @__PURE__ */ r("style", { dangerouslySetInnerHTML: { __html: e } }),
|
|
485
|
+
p.map((u, l) => {
|
|
486
|
+
const w = p.slice(0, l).reduce((b, f) => b + f.blocks.length, 0);
|
|
487
|
+
return /* @__PURE__ */ r(
|
|
488
|
+
oe,
|
|
489
|
+
{
|
|
490
|
+
dimensions: I,
|
|
491
|
+
margins: t.margins,
|
|
492
|
+
pageNumber: l + 1,
|
|
493
|
+
totalPages: p.length,
|
|
494
|
+
children: u.blocks.map((b, f) => {
|
|
495
|
+
const v = w + f, T = b.trim().toLowerCase(), M = !T.startsWith("<script") && !T.startsWith("<style"), N = T.startsWith("<table");
|
|
496
|
+
return /* @__PURE__ */ C(
|
|
497
|
+
"div",
|
|
498
|
+
{
|
|
499
|
+
className: "dopecanvas-block-wrapper",
|
|
500
|
+
style: { position: "relative" },
|
|
501
|
+
onMouseEnter: () => {
|
|
502
|
+
M && (P.current && (clearTimeout(P.current), P.current = null), q(v));
|
|
503
|
+
},
|
|
504
|
+
onMouseLeave: () => {
|
|
505
|
+
P.current = setTimeout(() => {
|
|
506
|
+
q(
|
|
507
|
+
(O) => O === v ? null : O
|
|
508
|
+
);
|
|
509
|
+
}, 250);
|
|
510
|
+
},
|
|
511
|
+
children: [
|
|
512
|
+
/* @__PURE__ */ r(
|
|
513
|
+
qe,
|
|
514
|
+
{
|
|
515
|
+
html: b,
|
|
516
|
+
isEditable: M,
|
|
517
|
+
isTable: N
|
|
518
|
+
}
|
|
519
|
+
),
|
|
520
|
+
M && /* @__PURE__ */ r(
|
|
521
|
+
ve,
|
|
522
|
+
{
|
|
523
|
+
visible: D === v,
|
|
524
|
+
onAddBelow: () => he(v),
|
|
525
|
+
onEditHTML: () => pe(v),
|
|
526
|
+
onDelete: () => ge(v)
|
|
527
|
+
}
|
|
528
|
+
)
|
|
529
|
+
]
|
|
530
|
+
},
|
|
531
|
+
`${l}-${f}`
|
|
532
|
+
);
|
|
533
|
+
})
|
|
534
|
+
},
|
|
535
|
+
l
|
|
536
|
+
);
|
|
537
|
+
}),
|
|
538
|
+
p.length === 0 && /* @__PURE__ */ r(
|
|
539
|
+
oe,
|
|
255
540
|
{
|
|
256
|
-
dimensions:
|
|
541
|
+
dimensions: I,
|
|
257
542
|
margins: t.margins,
|
|
258
543
|
pageNumber: 1,
|
|
259
544
|
totalPages: 1,
|
|
260
|
-
children: /* @__PURE__ */
|
|
545
|
+
children: /* @__PURE__ */ r(
|
|
261
546
|
"div",
|
|
262
547
|
{
|
|
263
548
|
contentEditable: "true",
|
|
@@ -267,25 +552,33 @@ const le = ({
|
|
|
267
552
|
)
|
|
268
553
|
}
|
|
269
554
|
)
|
|
270
|
-
] })
|
|
555
|
+
] }),
|
|
556
|
+
B !== null && /* @__PURE__ */ r(
|
|
557
|
+
He,
|
|
558
|
+
{
|
|
559
|
+
html: m,
|
|
560
|
+
onSave: fe,
|
|
561
|
+
onCancel: me
|
|
562
|
+
}
|
|
563
|
+
)
|
|
271
564
|
] });
|
|
272
|
-
},
|
|
565
|
+
}, We = {
|
|
273
566
|
flex: 1,
|
|
274
567
|
overflow: "auto",
|
|
275
568
|
backgroundColor: "#e8e8e8",
|
|
276
569
|
display: "flex",
|
|
277
570
|
flexDirection: "column",
|
|
278
571
|
alignItems: "center"
|
|
279
|
-
},
|
|
572
|
+
}, je = {
|
|
280
573
|
display: "flex",
|
|
281
574
|
flexDirection: "column",
|
|
282
575
|
alignItems: "center",
|
|
283
576
|
gap: "24px",
|
|
284
577
|
padding: "24px 0"
|
|
285
578
|
};
|
|
286
|
-
class
|
|
579
|
+
class de {
|
|
287
580
|
config;
|
|
288
|
-
constructor(e =
|
|
581
|
+
constructor(e = G) {
|
|
289
582
|
this.config = { ...e };
|
|
290
583
|
}
|
|
291
584
|
// ----------------------------------------------------------
|
|
@@ -299,7 +592,7 @@ class te {
|
|
|
299
592
|
}
|
|
300
593
|
/** Resolve page size name to pixel dimensions */
|
|
301
594
|
getPageDimensions() {
|
|
302
|
-
return typeof this.config.size == "string" ?
|
|
595
|
+
return typeof this.config.size == "string" ? ue[this.config.size] : this.config.size;
|
|
303
596
|
}
|
|
304
597
|
/** Usable content area height (page height minus top+bottom margins) */
|
|
305
598
|
getContentAreaHeight() {
|
|
@@ -318,18 +611,18 @@ class te {
|
|
|
318
611
|
* so that measurements reflect actual rendered heights.
|
|
319
612
|
*/
|
|
320
613
|
measureBlocks(e) {
|
|
321
|
-
const t = Array.from(e.children),
|
|
322
|
-
for (let
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
index:
|
|
326
|
-
height:
|
|
327
|
-
element:
|
|
328
|
-
breakBefore:
|
|
329
|
-
breakAfter:
|
|
614
|
+
const t = Array.from(e.children), n = [];
|
|
615
|
+
for (let o = 0; o < t.length; o++) {
|
|
616
|
+
const a = t[o], i = window.getComputedStyle(a), c = i.getPropertyValue("break-before") === "page" || i.getPropertyValue("page-break-before") === "always", g = i.getPropertyValue("break-after") === "page" || i.getPropertyValue("page-break-after") === "always", S = a.getBoundingClientRect(), d = parseFloat(i.marginTop) || 0, p = parseFloat(i.marginBottom) || 0, k = S.height + d + p;
|
|
617
|
+
n.push({
|
|
618
|
+
index: o,
|
|
619
|
+
height: k,
|
|
620
|
+
element: a,
|
|
621
|
+
breakBefore: c,
|
|
622
|
+
breakAfter: g
|
|
330
623
|
});
|
|
331
624
|
}
|
|
332
|
-
return
|
|
625
|
+
return n;
|
|
333
626
|
}
|
|
334
627
|
// ----------------------------------------------------------
|
|
335
628
|
// Pagination
|
|
@@ -347,19 +640,19 @@ class te {
|
|
|
347
640
|
paginate(e) {
|
|
348
641
|
if (e.length === 0)
|
|
349
642
|
return { pages: [{ blockIndices: [] }], pageCount: 1 };
|
|
350
|
-
const t = this.getContentAreaHeight(),
|
|
351
|
-
let
|
|
352
|
-
for (let
|
|
353
|
-
const
|
|
354
|
-
|
|
643
|
+
const t = this.getContentAreaHeight(), n = [];
|
|
644
|
+
let o = [], a = 0;
|
|
645
|
+
for (let i = 0; i < e.length; i++) {
|
|
646
|
+
const c = e[i];
|
|
647
|
+
c.breakBefore && o.length > 0 && (n.push({ blockIndices: o }), o = [], a = 0), a + c.height > t && o.length > 0 && (n.push({ blockIndices: o }), o = [], a = 0), o.push(c.index), a += c.height, c.breakAfter && (n.push({ blockIndices: o }), o = [], a = 0);
|
|
355
648
|
}
|
|
356
|
-
return
|
|
357
|
-
pages:
|
|
358
|
-
pageCount:
|
|
649
|
+
return o.length > 0 && n.push({ blockIndices: o }), n.length === 0 && n.push({ blockIndices: [] }), {
|
|
650
|
+
pages: n,
|
|
651
|
+
pageCount: n.length
|
|
359
652
|
};
|
|
360
653
|
}
|
|
361
654
|
}
|
|
362
|
-
class
|
|
655
|
+
class $ {
|
|
363
656
|
observer = null;
|
|
364
657
|
changeCallbacks = /* @__PURE__ */ new Set();
|
|
365
658
|
contextCallbacks = /* @__PURE__ */ new Set();
|
|
@@ -402,12 +695,12 @@ class z {
|
|
|
402
695
|
*/
|
|
403
696
|
makeChildrenEditable(e) {
|
|
404
697
|
const t = Array.from(e.children);
|
|
405
|
-
for (const
|
|
406
|
-
|
|
698
|
+
for (const n of t)
|
|
699
|
+
n.tagName === "TABLE" ? this.makeTableCellsEditable(n) : n.contentEditable = "true";
|
|
407
700
|
}
|
|
408
701
|
makeTableCellsEditable(e) {
|
|
409
|
-
e.querySelectorAll("td, th").forEach((
|
|
410
|
-
|
|
702
|
+
e.querySelectorAll("td, th").forEach((n) => {
|
|
703
|
+
n.contentEditable = "true";
|
|
411
704
|
});
|
|
412
705
|
}
|
|
413
706
|
// ----------------------------------------------------------
|
|
@@ -416,7 +709,7 @@ class z {
|
|
|
416
709
|
handleMutations = (e) => {
|
|
417
710
|
this.debounceTimer && clearTimeout(this.debounceTimer), this.debounceTimer = setTimeout(() => {
|
|
418
711
|
this.pushUndoSnapshot(), this.notifyChange();
|
|
419
|
-
},
|
|
712
|
+
}, $.DEBOUNCE_MS);
|
|
420
713
|
};
|
|
421
714
|
// ----------------------------------------------------------
|
|
422
715
|
// Selection / context detection
|
|
@@ -427,27 +720,27 @@ class z {
|
|
|
427
720
|
this.setContext("none");
|
|
428
721
|
return;
|
|
429
722
|
}
|
|
430
|
-
const
|
|
431
|
-
let
|
|
432
|
-
for (;
|
|
433
|
-
if (
|
|
434
|
-
const
|
|
435
|
-
if (
|
|
723
|
+
const n = e.getRangeAt(0).startContainer;
|
|
724
|
+
let o = n;
|
|
725
|
+
for (; o && o !== this.container; ) {
|
|
726
|
+
if (o instanceof HTMLElement) {
|
|
727
|
+
const a = o.tagName;
|
|
728
|
+
if (a === "TD" || a === "TH" || a === "TABLE") {
|
|
436
729
|
this.setContext("table");
|
|
437
730
|
return;
|
|
438
731
|
}
|
|
439
|
-
if (
|
|
732
|
+
if (a === "IMG") {
|
|
440
733
|
this.setContext("image");
|
|
441
734
|
return;
|
|
442
735
|
}
|
|
443
|
-
if (
|
|
736
|
+
if (o.dataset?.dopecanvasChart) {
|
|
444
737
|
this.setContext("chart");
|
|
445
738
|
return;
|
|
446
739
|
}
|
|
447
740
|
}
|
|
448
|
-
|
|
741
|
+
o = o.parentNode;
|
|
449
742
|
}
|
|
450
|
-
this.container.contains(
|
|
743
|
+
this.container.contains(n) ? this.setContext("text") : this.setContext("none");
|
|
451
744
|
}
|
|
452
745
|
setContext(e) {
|
|
453
746
|
e !== this.currentContext && (this.currentContext = e, this.contextCallbacks.forEach((t) => t(e)));
|
|
@@ -461,7 +754,7 @@ class z {
|
|
|
461
754
|
pushUndoSnapshot() {
|
|
462
755
|
if (!this.container) return;
|
|
463
756
|
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 >
|
|
757
|
+
t && t.html === e || (this.undoStack.push({ html: e, timestamp: Date.now() }), this.redoStack = [], this.undoStack.length > $.MAX_UNDO_STACK && this.undoStack.shift());
|
|
465
758
|
}
|
|
466
759
|
undo() {
|
|
467
760
|
if (!this.container || this.undoStack.length <= 1) return !1;
|
|
@@ -533,65 +826,91 @@ class z {
|
|
|
533
826
|
return this.container && (this.container.innerText || this.container.textContent) || "";
|
|
534
827
|
}
|
|
535
828
|
}
|
|
536
|
-
const
|
|
537
|
-
html:
|
|
829
|
+
const rt = Ce(({
|
|
830
|
+
html: s = "",
|
|
538
831
|
css: e,
|
|
539
832
|
pageConfig: t,
|
|
540
|
-
onContentChange:
|
|
541
|
-
onPageConfigChange:
|
|
542
|
-
style:
|
|
543
|
-
},
|
|
544
|
-
const [
|
|
545
|
-
t ||
|
|
546
|
-
), [
|
|
833
|
+
onContentChange: n,
|
|
834
|
+
onPageConfigChange: o,
|
|
835
|
+
style: a
|
|
836
|
+
}, i) => {
|
|
837
|
+
const [c, g] = R(
|
|
838
|
+
t || G
|
|
839
|
+
), [S, d] = R({
|
|
547
840
|
pages: [],
|
|
548
841
|
pageCount: 0
|
|
549
|
-
}),
|
|
550
|
-
|
|
551
|
-
const
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
}, [
|
|
555
|
-
const
|
|
556
|
-
(
|
|
557
|
-
|
|
842
|
+
}), p = H(s), k = H(null), A = H(n);
|
|
843
|
+
A.current = n;
|
|
844
|
+
const y = t || c, E = ne(() => new de(y), []), D = ne(() => new $(), []);
|
|
845
|
+
F(() => {
|
|
846
|
+
E.setConfig(y);
|
|
847
|
+
}, [y, E]);
|
|
848
|
+
const q = h(
|
|
849
|
+
(m) => {
|
|
850
|
+
p.current = m, A.current?.(m);
|
|
558
851
|
},
|
|
559
852
|
[]
|
|
560
|
-
),
|
|
561
|
-
(
|
|
562
|
-
const
|
|
853
|
+
), B = h(
|
|
854
|
+
(m) => {
|
|
855
|
+
const x = {
|
|
856
|
+
...y,
|
|
563
857
|
...m,
|
|
564
|
-
...u,
|
|
565
858
|
margins: {
|
|
566
|
-
...
|
|
567
|
-
...
|
|
859
|
+
...y.margins,
|
|
860
|
+
...m.margins || {}
|
|
568
861
|
}
|
|
569
862
|
};
|
|
570
|
-
|
|
863
|
+
g(x), E.setConfig(x), o?.(x);
|
|
571
864
|
},
|
|
572
|
-
[
|
|
573
|
-
),
|
|
574
|
-
|
|
865
|
+
[y, E, o]
|
|
866
|
+
), j = h((m) => {
|
|
867
|
+
d(m);
|
|
575
868
|
}, []);
|
|
576
|
-
return
|
|
577
|
-
execCommand: (
|
|
578
|
-
queryCommandState: (
|
|
579
|
-
queryCommandValue: (
|
|
580
|
-
getPageConfig: () => ({ ...
|
|
581
|
-
setPageConfig: (
|
|
582
|
-
|
|
869
|
+
return ye(i, () => ({
|
|
870
|
+
execCommand: (m, x) => D.execCommand(m, x),
|
|
871
|
+
queryCommandState: (m) => D.queryCommandState(m),
|
|
872
|
+
queryCommandValue: (m) => D.queryCommandValue(m),
|
|
873
|
+
getPageConfig: () => ({ ...y }),
|
|
874
|
+
setPageConfig: (m) => {
|
|
875
|
+
B(m);
|
|
876
|
+
},
|
|
877
|
+
getPageCount: () => S.pageCount,
|
|
878
|
+
getHTML: () => {
|
|
879
|
+
if (k.current) {
|
|
880
|
+
const m = k.current.querySelectorAll(
|
|
881
|
+
".dopecanvas-block-content"
|
|
882
|
+
);
|
|
883
|
+
if (m.length > 0) {
|
|
884
|
+
const x = [];
|
|
885
|
+
if (m.forEach((P) => {
|
|
886
|
+
const I = P.firstElementChild;
|
|
887
|
+
I && x.push(I.outerHTML);
|
|
888
|
+
}), x.length > 0) {
|
|
889
|
+
const P = x.join(`
|
|
890
|
+
`);
|
|
891
|
+
return p.current = P, P;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
return p.current;
|
|
583
896
|
},
|
|
584
|
-
getPageCount: () => v.pageCount,
|
|
585
|
-
getHTML: () => d.current,
|
|
586
897
|
getPlainText: () => {
|
|
587
|
-
const
|
|
588
|
-
|
|
898
|
+
const m = k.current ? (() => {
|
|
899
|
+
const P = k.current.querySelectorAll(".dopecanvas-block-content"), I = [];
|
|
900
|
+
return P.forEach((V) => {
|
|
901
|
+
const _ = V.firstElementChild;
|
|
902
|
+
_ && I.push(_.outerHTML);
|
|
903
|
+
}), I.length > 0 ? I.join(`
|
|
904
|
+
`) : p.current;
|
|
905
|
+
})() : p.current, x = document.createElement("div");
|
|
906
|
+
return x.innerHTML = m, x.innerText || x.textContent || "";
|
|
589
907
|
},
|
|
590
|
-
undo: () =>
|
|
591
|
-
redo: () =>
|
|
592
|
-
}), [
|
|
908
|
+
undo: () => D.undo(),
|
|
909
|
+
redo: () => D.redo()
|
|
910
|
+
}), [D, y, S.pageCount, B]), /* @__PURE__ */ r(
|
|
593
911
|
"div",
|
|
594
912
|
{
|
|
913
|
+
ref: k,
|
|
595
914
|
className: "dopecanvas-root",
|
|
596
915
|
style: {
|
|
597
916
|
display: "flex",
|
|
@@ -599,24 +918,24 @@ const Me = ne(({
|
|
|
599
918
|
height: "100%",
|
|
600
919
|
width: "100%",
|
|
601
920
|
fontFamily: "system-ui, -apple-system, BlinkMacSystemFont, sans-serif",
|
|
602
|
-
...
|
|
921
|
+
...a
|
|
603
922
|
},
|
|
604
|
-
children: /* @__PURE__ */
|
|
605
|
-
|
|
923
|
+
children: /* @__PURE__ */ r(
|
|
924
|
+
Ne,
|
|
606
925
|
{
|
|
607
|
-
html:
|
|
926
|
+
html: s,
|
|
608
927
|
css: e,
|
|
609
|
-
pageConfig:
|
|
610
|
-
layoutEngine:
|
|
611
|
-
editableManager:
|
|
612
|
-
onContentChange:
|
|
613
|
-
onPaginationChange:
|
|
928
|
+
pageConfig: y,
|
|
929
|
+
layoutEngine: E,
|
|
930
|
+
editableManager: D,
|
|
931
|
+
onContentChange: q,
|
|
932
|
+
onPaginationChange: j
|
|
614
933
|
}
|
|
615
934
|
)
|
|
616
935
|
}
|
|
617
936
|
);
|
|
618
937
|
});
|
|
619
|
-
class
|
|
938
|
+
class Oe {
|
|
620
939
|
layoutEngine;
|
|
621
940
|
editableManager;
|
|
622
941
|
sourceHTML = "";
|
|
@@ -626,8 +945,8 @@ class he {
|
|
|
626
945
|
paginationResult = { pages: [], pageCount: 0 };
|
|
627
946
|
paginationCallbacks = /* @__PURE__ */ new Set();
|
|
628
947
|
changeCallbacks = /* @__PURE__ */ new Set();
|
|
629
|
-
constructor(e =
|
|
630
|
-
this.layoutEngine = new
|
|
948
|
+
constructor(e = G) {
|
|
949
|
+
this.layoutEngine = new de(e), this.editableManager = new $();
|
|
631
950
|
}
|
|
632
951
|
// ----------------------------------------------------------
|
|
633
952
|
// Accessors
|
|
@@ -695,10 +1014,10 @@ class he {
|
|
|
695
1014
|
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
1015
|
let t = null;
|
|
697
1016
|
this.sourceCSS && (t = document.createElement("style"), t.textContent = this.sourceCSS, this.measureContainer.appendChild(t));
|
|
698
|
-
const
|
|
699
|
-
|
|
700
|
-
const
|
|
701
|
-
return this.paginationResult = this.layoutEngine.paginate(
|
|
1017
|
+
const n = document.createElement("div");
|
|
1018
|
+
n.innerHTML = this.sourceHTML, this.measureContainer.appendChild(n);
|
|
1019
|
+
const o = this.layoutEngine.measureBlocks(n);
|
|
1020
|
+
return this.paginationResult = this.layoutEngine.paginate(o), this.measureContainer.innerHTML = "", this.paginationCallbacks.forEach((a) => a(this.paginationResult)), { result: this.paginationResult, measurements: o };
|
|
702
1021
|
}
|
|
703
1022
|
/**
|
|
704
1023
|
* Re-paginate using the current content container's live DOM.
|
|
@@ -757,7 +1076,7 @@ class he {
|
|
|
757
1076
|
this.editableManager.detach(), this.paginationCallbacks.clear(), this.changeCallbacks.clear(), this.measureContainer = null, this.contentContainer = null;
|
|
758
1077
|
}
|
|
759
1078
|
}
|
|
760
|
-
class
|
|
1079
|
+
class it {
|
|
761
1080
|
_html = "";
|
|
762
1081
|
_css = "";
|
|
763
1082
|
_pageConfig = null;
|
|
@@ -777,7 +1096,7 @@ class Le {
|
|
|
777
1096
|
* Optionally provide CSS to inject alongside.
|
|
778
1097
|
*/
|
|
779
1098
|
loadHTML(e, t) {
|
|
780
|
-
this._html = e, this._css = t || "", this._loadCallbacks.forEach((
|
|
1099
|
+
this._html = e, this._css = t || "", this._loadCallbacks.forEach((n) => n(e, t));
|
|
781
1100
|
}
|
|
782
1101
|
/**
|
|
783
1102
|
* Get the current document HTML content.
|
|
@@ -869,18 +1188,18 @@ class Le {
|
|
|
869
1188
|
getElementContent(e) {
|
|
870
1189
|
const t = document.createElement("div");
|
|
871
1190
|
t.innerHTML = this.getHTML();
|
|
872
|
-
const
|
|
873
|
-
return
|
|
1191
|
+
const n = t.querySelector(`#${e}`);
|
|
1192
|
+
return n ? n.innerHTML : null;
|
|
874
1193
|
}
|
|
875
1194
|
/**
|
|
876
1195
|
* Set the innerHTML of a specific element by its ID.
|
|
877
1196
|
* Re-loads the full document with the modification.
|
|
878
1197
|
*/
|
|
879
1198
|
setElementContent(e, t) {
|
|
880
|
-
const
|
|
881
|
-
|
|
882
|
-
const
|
|
883
|
-
|
|
1199
|
+
const n = document.createElement("div");
|
|
1200
|
+
n.innerHTML = this.getHTML();
|
|
1201
|
+
const o = n.querySelector(`#${e}`);
|
|
1202
|
+
o && (o.innerHTML = t, this.loadHTML(n.innerHTML, this._css));
|
|
884
1203
|
}
|
|
885
1204
|
// ----------------------------------------------------------
|
|
886
1205
|
// Internal connectors (used by DopeCanvas component)
|
|
@@ -906,14 +1225,14 @@ class Le {
|
|
|
906
1225
|
this._pageConfig = e;
|
|
907
1226
|
}
|
|
908
1227
|
}
|
|
909
|
-
function
|
|
1228
|
+
function st(s) {
|
|
910
1229
|
const [e, t] = R("none");
|
|
911
|
-
return
|
|
912
|
-
t(
|
|
913
|
-
}) : void 0, [
|
|
1230
|
+
return F(() => s ? s.onContextChange((o) => {
|
|
1231
|
+
t(o);
|
|
1232
|
+
}) : void 0, [s]), e;
|
|
914
1233
|
}
|
|
915
|
-
function
|
|
916
|
-
const [
|
|
1234
|
+
function $e() {
|
|
1235
|
+
const [s, e] = R({
|
|
917
1236
|
bold: !1,
|
|
918
1237
|
italic: !1,
|
|
919
1238
|
underline: !1,
|
|
@@ -922,7 +1241,7 @@ function de() {
|
|
|
922
1241
|
justifyCenter: !1,
|
|
923
1242
|
justifyRight: !1,
|
|
924
1243
|
justifyFull: !1
|
|
925
|
-
}), t =
|
|
1244
|
+
}), t = h(() => {
|
|
926
1245
|
e({
|
|
927
1246
|
bold: document.queryCommandState("bold"),
|
|
928
1247
|
italic: document.queryCommandState("italic"),
|
|
@@ -934,146 +1253,146 @@ function de() {
|
|
|
934
1253
|
justifyFull: document.queryCommandState("justifyFull")
|
|
935
1254
|
});
|
|
936
1255
|
}, []);
|
|
937
|
-
return
|
|
1256
|
+
return F(() => (document.addEventListener("selectionchange", t), () => {
|
|
938
1257
|
document.removeEventListener("selectionchange", t);
|
|
939
|
-
}), [t]),
|
|
1258
|
+
}), [t]), s;
|
|
940
1259
|
}
|
|
941
|
-
const
|
|
942
|
-
const e =
|
|
943
|
-
const c = window.getSelection();
|
|
944
|
-
c && c.rangeCount > 0 && (t.current = c.getRangeAt(0).cloneRange());
|
|
945
|
-
}, []), n = p(() => {
|
|
946
|
-
const c = t.current;
|
|
947
|
-
if (!c) return;
|
|
1260
|
+
const Ve = ({ onExecCommand: s }) => {
|
|
1261
|
+
const e = $e(), t = H(null), n = h(() => {
|
|
948
1262
|
const d = window.getSelection();
|
|
949
|
-
d &&
|
|
950
|
-
}, []),
|
|
951
|
-
|
|
952
|
-
|
|
1263
|
+
d && d.rangeCount > 0 && (t.current = d.getRangeAt(0).cloneRange());
|
|
1264
|
+
}, []), o = h(() => {
|
|
1265
|
+
const d = t.current;
|
|
1266
|
+
if (!d) return;
|
|
1267
|
+
const p = window.getSelection();
|
|
1268
|
+
p && (p.removeAllRanges(), p.addRange(d));
|
|
1269
|
+
}, []), a = h(
|
|
1270
|
+
(d, p) => (k) => {
|
|
1271
|
+
k.preventDefault(), s(d, p);
|
|
953
1272
|
},
|
|
954
|
-
[
|
|
955
|
-
),
|
|
956
|
-
(
|
|
957
|
-
|
|
1273
|
+
[s]
|
|
1274
|
+
), i = h(
|
|
1275
|
+
(d) => {
|
|
1276
|
+
o(), s("fontSize", d.target.value);
|
|
958
1277
|
},
|
|
959
|
-
[
|
|
960
|
-
),
|
|
961
|
-
(
|
|
962
|
-
|
|
963
|
-
const
|
|
964
|
-
|
|
1278
|
+
[s, o]
|
|
1279
|
+
), c = h(
|
|
1280
|
+
(d) => {
|
|
1281
|
+
o();
|
|
1282
|
+
const p = d.target.value;
|
|
1283
|
+
p === "p" ? s("formatBlock", "p") : s("formatBlock", p);
|
|
965
1284
|
},
|
|
966
|
-
[
|
|
967
|
-
),
|
|
968
|
-
(
|
|
969
|
-
|
|
1285
|
+
[s, o]
|
|
1286
|
+
), g = h(
|
|
1287
|
+
(d) => {
|
|
1288
|
+
o(), s("foreColor", d.target.value);
|
|
970
1289
|
},
|
|
971
|
-
[
|
|
972
|
-
),
|
|
973
|
-
(
|
|
974
|
-
|
|
1290
|
+
[s, o]
|
|
1291
|
+
), S = h(
|
|
1292
|
+
(d) => {
|
|
1293
|
+
o(), s("hiliteColor", d.target.value);
|
|
975
1294
|
},
|
|
976
|
-
[
|
|
1295
|
+
[s, o]
|
|
977
1296
|
);
|
|
978
|
-
return /* @__PURE__ */
|
|
979
|
-
/* @__PURE__ */
|
|
1297
|
+
return /* @__PURE__ */ C("div", { style: Ue, children: [
|
|
1298
|
+
/* @__PURE__ */ C(
|
|
980
1299
|
"select",
|
|
981
1300
|
{
|
|
982
|
-
onChange:
|
|
1301
|
+
onChange: c,
|
|
983
1302
|
defaultValue: "p",
|
|
984
|
-
style:
|
|
1303
|
+
style: ie,
|
|
985
1304
|
title: "Block Format",
|
|
986
|
-
onMouseDown:
|
|
1305
|
+
onMouseDown: n,
|
|
987
1306
|
children: [
|
|
988
|
-
/* @__PURE__ */
|
|
989
|
-
/* @__PURE__ */
|
|
990
|
-
/* @__PURE__ */
|
|
991
|
-
/* @__PURE__ */
|
|
992
|
-
/* @__PURE__ */
|
|
993
|
-
/* @__PURE__ */
|
|
994
|
-
/* @__PURE__ */
|
|
1307
|
+
/* @__PURE__ */ r("option", { value: "p", children: "Paragraph" }),
|
|
1308
|
+
/* @__PURE__ */ r("option", { value: "h1", children: "Heading 1" }),
|
|
1309
|
+
/* @__PURE__ */ r("option", { value: "h2", children: "Heading 2" }),
|
|
1310
|
+
/* @__PURE__ */ r("option", { value: "h3", children: "Heading 3" }),
|
|
1311
|
+
/* @__PURE__ */ r("option", { value: "h4", children: "Heading 4" }),
|
|
1312
|
+
/* @__PURE__ */ r("option", { value: "h5", children: "Heading 5" }),
|
|
1313
|
+
/* @__PURE__ */ r("option", { value: "h6", children: "Heading 6" })
|
|
995
1314
|
]
|
|
996
1315
|
}
|
|
997
1316
|
),
|
|
998
|
-
/* @__PURE__ */
|
|
999
|
-
/* @__PURE__ */
|
|
1317
|
+
/* @__PURE__ */ r("div", { style: Z }),
|
|
1318
|
+
/* @__PURE__ */ C(
|
|
1000
1319
|
"select",
|
|
1001
1320
|
{
|
|
1002
|
-
onChange:
|
|
1321
|
+
onChange: i,
|
|
1003
1322
|
defaultValue: "3",
|
|
1004
|
-
style:
|
|
1323
|
+
style: ie,
|
|
1005
1324
|
title: "Font Size",
|
|
1006
|
-
onMouseDown:
|
|
1325
|
+
onMouseDown: n,
|
|
1007
1326
|
children: [
|
|
1008
|
-
/* @__PURE__ */
|
|
1009
|
-
/* @__PURE__ */
|
|
1010
|
-
/* @__PURE__ */
|
|
1011
|
-
/* @__PURE__ */
|
|
1012
|
-
/* @__PURE__ */
|
|
1013
|
-
/* @__PURE__ */
|
|
1014
|
-
/* @__PURE__ */
|
|
1327
|
+
/* @__PURE__ */ r("option", { value: "1", children: "8pt" }),
|
|
1328
|
+
/* @__PURE__ */ r("option", { value: "2", children: "10pt" }),
|
|
1329
|
+
/* @__PURE__ */ r("option", { value: "3", children: "12pt" }),
|
|
1330
|
+
/* @__PURE__ */ r("option", { value: "4", children: "14pt" }),
|
|
1331
|
+
/* @__PURE__ */ r("option", { value: "5", children: "18pt" }),
|
|
1332
|
+
/* @__PURE__ */ r("option", { value: "6", children: "24pt" }),
|
|
1333
|
+
/* @__PURE__ */ r("option", { value: "7", children: "36pt" })
|
|
1015
1334
|
]
|
|
1016
1335
|
}
|
|
1017
1336
|
),
|
|
1018
|
-
/* @__PURE__ */
|
|
1019
|
-
/* @__PURE__ */
|
|
1020
|
-
|
|
1337
|
+
/* @__PURE__ */ r("div", { style: Z }),
|
|
1338
|
+
/* @__PURE__ */ r(
|
|
1339
|
+
re,
|
|
1021
1340
|
{
|
|
1022
1341
|
icon: "B",
|
|
1023
1342
|
title: "Bold (Ctrl+B)",
|
|
1024
1343
|
active: e.bold,
|
|
1025
|
-
onMouseDown:
|
|
1344
|
+
onMouseDown: a("bold"),
|
|
1026
1345
|
extraStyle: { fontWeight: "bold" }
|
|
1027
1346
|
}
|
|
1028
1347
|
),
|
|
1029
|
-
/* @__PURE__ */
|
|
1030
|
-
|
|
1348
|
+
/* @__PURE__ */ r(
|
|
1349
|
+
re,
|
|
1031
1350
|
{
|
|
1032
1351
|
icon: "I",
|
|
1033
1352
|
title: "Italic (Ctrl+I)",
|
|
1034
1353
|
active: e.italic,
|
|
1035
|
-
onMouseDown:
|
|
1354
|
+
onMouseDown: a("italic"),
|
|
1036
1355
|
extraStyle: { fontStyle: "italic" }
|
|
1037
1356
|
}
|
|
1038
1357
|
),
|
|
1039
|
-
/* @__PURE__ */
|
|
1040
|
-
/* @__PURE__ */
|
|
1358
|
+
/* @__PURE__ */ r("div", { style: Z }),
|
|
1359
|
+
/* @__PURE__ */ C("label", { style: se, title: "Text Color", onMouseDown: n, children: [
|
|
1041
1360
|
"A",
|
|
1042
|
-
/* @__PURE__ */
|
|
1361
|
+
/* @__PURE__ */ r(
|
|
1043
1362
|
"input",
|
|
1044
1363
|
{
|
|
1045
1364
|
type: "color",
|
|
1046
1365
|
defaultValue: "#000000",
|
|
1047
|
-
onChange:
|
|
1048
|
-
style:
|
|
1366
|
+
onChange: g,
|
|
1367
|
+
style: ae
|
|
1049
1368
|
}
|
|
1050
1369
|
)
|
|
1051
1370
|
] }),
|
|
1052
|
-
/* @__PURE__ */
|
|
1053
|
-
/* @__PURE__ */
|
|
1054
|
-
/* @__PURE__ */
|
|
1371
|
+
/* @__PURE__ */ C("label", { style: se, title: "Highlight Color", onMouseDown: n, children: [
|
|
1372
|
+
/* @__PURE__ */ r("span", { style: { backgroundColor: "#ffff00", padding: "0 2px" }, children: "A" }),
|
|
1373
|
+
/* @__PURE__ */ r(
|
|
1055
1374
|
"input",
|
|
1056
1375
|
{
|
|
1057
1376
|
type: "color",
|
|
1058
1377
|
defaultValue: "#ffff00",
|
|
1059
|
-
onChange:
|
|
1060
|
-
style:
|
|
1378
|
+
onChange: S,
|
|
1379
|
+
style: ae
|
|
1061
1380
|
}
|
|
1062
1381
|
)
|
|
1063
1382
|
] })
|
|
1064
1383
|
] });
|
|
1065
|
-
},
|
|
1066
|
-
icon:
|
|
1384
|
+
}, re = ({
|
|
1385
|
+
icon: s,
|
|
1067
1386
|
title: e,
|
|
1068
1387
|
active: t,
|
|
1069
|
-
onMouseDown:
|
|
1070
|
-
extraStyle:
|
|
1071
|
-
}) => /* @__PURE__ */
|
|
1388
|
+
onMouseDown: n,
|
|
1389
|
+
extraStyle: o
|
|
1390
|
+
}) => /* @__PURE__ */ r(
|
|
1072
1391
|
"button",
|
|
1073
1392
|
{
|
|
1074
1393
|
type: "button",
|
|
1075
1394
|
title: e,
|
|
1076
|
-
onMouseDown:
|
|
1395
|
+
onMouseDown: n,
|
|
1077
1396
|
style: {
|
|
1078
1397
|
width: "28px",
|
|
1079
1398
|
height: "28px",
|
|
@@ -1090,16 +1409,16 @@ const ge = ({ onExecCommand: i }) => {
|
|
|
1090
1409
|
color: "#333",
|
|
1091
1410
|
padding: 0,
|
|
1092
1411
|
fontFamily: "inherit",
|
|
1093
|
-
...
|
|
1412
|
+
...o
|
|
1094
1413
|
},
|
|
1095
|
-
dangerouslySetInnerHTML: { __html:
|
|
1414
|
+
dangerouslySetInnerHTML: { __html: s }
|
|
1096
1415
|
}
|
|
1097
|
-
),
|
|
1416
|
+
), Ue = {
|
|
1098
1417
|
display: "flex",
|
|
1099
1418
|
alignItems: "center",
|
|
1100
1419
|
gap: "2px",
|
|
1101
1420
|
flexWrap: "wrap"
|
|
1102
|
-
},
|
|
1421
|
+
}, ie = {
|
|
1103
1422
|
height: "28px",
|
|
1104
1423
|
borderWidth: "1px",
|
|
1105
1424
|
borderStyle: "solid",
|
|
@@ -1109,12 +1428,12 @@ const ge = ({ onExecCommand: i }) => {
|
|
|
1109
1428
|
padding: "0 4px",
|
|
1110
1429
|
cursor: "pointer",
|
|
1111
1430
|
backgroundColor: "#fff"
|
|
1112
|
-
},
|
|
1431
|
+
}, Z = {
|
|
1113
1432
|
width: "1px",
|
|
1114
1433
|
height: "20px",
|
|
1115
1434
|
backgroundColor: "#ddd",
|
|
1116
1435
|
margin: "0 4px"
|
|
1117
|
-
},
|
|
1436
|
+
}, se = {
|
|
1118
1437
|
position: "relative",
|
|
1119
1438
|
width: "28px",
|
|
1120
1439
|
height: "28px",
|
|
@@ -1124,7 +1443,7 @@ const ge = ({ onExecCommand: i }) => {
|
|
|
1124
1443
|
cursor: "pointer",
|
|
1125
1444
|
fontSize: "13px",
|
|
1126
1445
|
fontWeight: "bold"
|
|
1127
|
-
},
|
|
1446
|
+
}, ae = {
|
|
1128
1447
|
position: "absolute",
|
|
1129
1448
|
bottom: 0,
|
|
1130
1449
|
left: 0,
|
|
@@ -1134,114 +1453,114 @@ const ge = ({ onExecCommand: i }) => {
|
|
|
1134
1453
|
borderWidth: 0,
|
|
1135
1454
|
borderStyle: "none",
|
|
1136
1455
|
cursor: "pointer"
|
|
1137
|
-
},
|
|
1138
|
-
pageConfig:
|
|
1456
|
+
}, Ge = ({
|
|
1457
|
+
pageConfig: s,
|
|
1139
1458
|
pageCount: e,
|
|
1140
1459
|
onPageConfigChange: t
|
|
1141
1460
|
}) => {
|
|
1142
|
-
const
|
|
1143
|
-
(
|
|
1144
|
-
const
|
|
1145
|
-
t({ size:
|
|
1461
|
+
const n = h(
|
|
1462
|
+
(i) => {
|
|
1463
|
+
const c = i.target.value;
|
|
1464
|
+
t({ size: c });
|
|
1146
1465
|
},
|
|
1147
1466
|
[t]
|
|
1148
|
-
),
|
|
1149
|
-
(
|
|
1150
|
-
const
|
|
1467
|
+
), o = h(
|
|
1468
|
+
(i) => (c) => {
|
|
1469
|
+
const g = Math.max(0, parseInt(c.target.value) || 0);
|
|
1151
1470
|
t({
|
|
1152
1471
|
margins: {
|
|
1153
|
-
...
|
|
1154
|
-
[
|
|
1472
|
+
...s.margins,
|
|
1473
|
+
[i]: g
|
|
1155
1474
|
}
|
|
1156
1475
|
});
|
|
1157
1476
|
},
|
|
1158
|
-
[
|
|
1159
|
-
),
|
|
1160
|
-
return /* @__PURE__ */
|
|
1161
|
-
/* @__PURE__ */
|
|
1477
|
+
[s.margins, t]
|
|
1478
|
+
), a = typeof s.size == "string" ? s.size : "custom";
|
|
1479
|
+
return /* @__PURE__ */ C("div", { style: Ke, children: [
|
|
1480
|
+
/* @__PURE__ */ C("label", { style: Xe, children: [
|
|
1162
1481
|
"Page:",
|
|
1163
|
-
/* @__PURE__ */
|
|
1482
|
+
/* @__PURE__ */ C(
|
|
1164
1483
|
"select",
|
|
1165
1484
|
{
|
|
1166
|
-
value:
|
|
1167
|
-
onChange:
|
|
1168
|
-
style:
|
|
1485
|
+
value: a,
|
|
1486
|
+
onChange: n,
|
|
1487
|
+
style: Ze,
|
|
1169
1488
|
children: [
|
|
1170
|
-
/* @__PURE__ */
|
|
1171
|
-
/* @__PURE__ */
|
|
1172
|
-
/* @__PURE__ */
|
|
1489
|
+
/* @__PURE__ */ r("option", { value: "letter", children: "Letter (8.5 x 11)" }),
|
|
1490
|
+
/* @__PURE__ */ r("option", { value: "a4", children: "A4 (210 x 297mm)" }),
|
|
1491
|
+
/* @__PURE__ */ r("option", { value: "legal", children: "Legal (8.5 x 14)" })
|
|
1173
1492
|
]
|
|
1174
1493
|
}
|
|
1175
1494
|
)
|
|
1176
1495
|
] }),
|
|
1177
|
-
/* @__PURE__ */
|
|
1178
|
-
/* @__PURE__ */
|
|
1179
|
-
/* @__PURE__ */
|
|
1180
|
-
|
|
1496
|
+
/* @__PURE__ */ r("div", { style: le }),
|
|
1497
|
+
/* @__PURE__ */ r("span", { style: { fontSize: "12px", color: "#666" }, children: "Margins (px):" }),
|
|
1498
|
+
/* @__PURE__ */ r(
|
|
1499
|
+
U,
|
|
1181
1500
|
{
|
|
1182
1501
|
label: "T",
|
|
1183
|
-
value:
|
|
1184
|
-
onChange:
|
|
1502
|
+
value: s.margins.top,
|
|
1503
|
+
onChange: o("top")
|
|
1185
1504
|
}
|
|
1186
1505
|
),
|
|
1187
|
-
/* @__PURE__ */
|
|
1188
|
-
|
|
1506
|
+
/* @__PURE__ */ r(
|
|
1507
|
+
U,
|
|
1189
1508
|
{
|
|
1190
1509
|
label: "R",
|
|
1191
|
-
value:
|
|
1192
|
-
onChange:
|
|
1510
|
+
value: s.margins.right,
|
|
1511
|
+
onChange: o("right")
|
|
1193
1512
|
}
|
|
1194
1513
|
),
|
|
1195
|
-
/* @__PURE__ */
|
|
1196
|
-
|
|
1514
|
+
/* @__PURE__ */ r(
|
|
1515
|
+
U,
|
|
1197
1516
|
{
|
|
1198
1517
|
label: "B",
|
|
1199
|
-
value:
|
|
1200
|
-
onChange:
|
|
1518
|
+
value: s.margins.bottom,
|
|
1519
|
+
onChange: o("bottom")
|
|
1201
1520
|
}
|
|
1202
1521
|
),
|
|
1203
|
-
/* @__PURE__ */
|
|
1204
|
-
|
|
1522
|
+
/* @__PURE__ */ r(
|
|
1523
|
+
U,
|
|
1205
1524
|
{
|
|
1206
1525
|
label: "L",
|
|
1207
|
-
value:
|
|
1208
|
-
onChange:
|
|
1526
|
+
value: s.margins.left,
|
|
1527
|
+
onChange: o("left")
|
|
1209
1528
|
}
|
|
1210
1529
|
),
|
|
1211
|
-
/* @__PURE__ */
|
|
1212
|
-
/* @__PURE__ */
|
|
1530
|
+
/* @__PURE__ */ r("div", { style: le }),
|
|
1531
|
+
/* @__PURE__ */ C("span", { style: { fontSize: "12px", color: "#666" }, children: [
|
|
1213
1532
|
e,
|
|
1214
1533
|
" ",
|
|
1215
1534
|
e === 1 ? "page" : "pages"
|
|
1216
1535
|
] })
|
|
1217
1536
|
] });
|
|
1218
|
-
},
|
|
1219
|
-
|
|
1537
|
+
}, U = ({ label: s, value: e, onChange: t }) => /* @__PURE__ */ C("label", { style: Je, title: `${s} margin`, children: [
|
|
1538
|
+
s,
|
|
1220
1539
|
":",
|
|
1221
|
-
/* @__PURE__ */
|
|
1540
|
+
/* @__PURE__ */ r(
|
|
1222
1541
|
"input",
|
|
1223
1542
|
{
|
|
1224
1543
|
type: "number",
|
|
1225
1544
|
value: e,
|
|
1226
1545
|
onChange: t,
|
|
1227
|
-
style:
|
|
1546
|
+
style: Qe,
|
|
1228
1547
|
min: 0,
|
|
1229
1548
|
max: 300,
|
|
1230
1549
|
step: 12
|
|
1231
1550
|
}
|
|
1232
1551
|
)
|
|
1233
|
-
] }),
|
|
1552
|
+
] }), Ke = {
|
|
1234
1553
|
display: "flex",
|
|
1235
1554
|
alignItems: "center",
|
|
1236
1555
|
gap: "6px",
|
|
1237
1556
|
flexWrap: "wrap"
|
|
1238
|
-
},
|
|
1557
|
+
}, Xe = {
|
|
1239
1558
|
display: "flex",
|
|
1240
1559
|
alignItems: "center",
|
|
1241
1560
|
gap: "4px",
|
|
1242
1561
|
fontSize: "12px",
|
|
1243
1562
|
color: "#666"
|
|
1244
|
-
},
|
|
1563
|
+
}, Ze = {
|
|
1245
1564
|
height: "26px",
|
|
1246
1565
|
borderWidth: "1px",
|
|
1247
1566
|
borderStyle: "solid",
|
|
@@ -1251,18 +1570,18 @@ const ge = ({ onExecCommand: i }) => {
|
|
|
1251
1570
|
padding: "0 4px",
|
|
1252
1571
|
cursor: "pointer",
|
|
1253
1572
|
backgroundColor: "#fff"
|
|
1254
|
-
},
|
|
1573
|
+
}, le = {
|
|
1255
1574
|
width: "1px",
|
|
1256
1575
|
height: "20px",
|
|
1257
1576
|
backgroundColor: "#ddd",
|
|
1258
1577
|
margin: "0 4px"
|
|
1259
|
-
},
|
|
1578
|
+
}, Je = {
|
|
1260
1579
|
display: "flex",
|
|
1261
1580
|
alignItems: "center",
|
|
1262
1581
|
gap: "2px",
|
|
1263
1582
|
fontSize: "11px",
|
|
1264
1583
|
color: "#666"
|
|
1265
|
-
},
|
|
1584
|
+
}, Qe = {
|
|
1266
1585
|
width: "44px",
|
|
1267
1586
|
height: "24px",
|
|
1268
1587
|
borderWidth: "1px",
|
|
@@ -1272,22 +1591,22 @@ const ge = ({ onExecCommand: i }) => {
|
|
|
1272
1591
|
fontSize: "11px",
|
|
1273
1592
|
textAlign: "center",
|
|
1274
1593
|
padding: "0 2px"
|
|
1275
|
-
},
|
|
1276
|
-
pageConfig:
|
|
1594
|
+
}, at = ({
|
|
1595
|
+
pageConfig: s,
|
|
1277
1596
|
pageCount: e,
|
|
1278
1597
|
onExecCommand: t,
|
|
1279
|
-
onPageConfigChange:
|
|
1280
|
-
}) => /* @__PURE__ */
|
|
1281
|
-
/* @__PURE__ */
|
|
1282
|
-
/* @__PURE__ */
|
|
1283
|
-
|
|
1598
|
+
onPageConfigChange: n
|
|
1599
|
+
}) => /* @__PURE__ */ C("div", { style: Ye, children: [
|
|
1600
|
+
/* @__PURE__ */ r("div", { style: ce, children: /* @__PURE__ */ r(Ve, { onExecCommand: t }) }),
|
|
1601
|
+
/* @__PURE__ */ r("div", { style: ce, children: /* @__PURE__ */ r(
|
|
1602
|
+
Ge,
|
|
1284
1603
|
{
|
|
1285
|
-
pageConfig:
|
|
1604
|
+
pageConfig: s,
|
|
1286
1605
|
pageCount: e,
|
|
1287
|
-
onPageConfigChange:
|
|
1606
|
+
onPageConfigChange: n
|
|
1288
1607
|
}
|
|
1289
1608
|
) })
|
|
1290
|
-
] }),
|
|
1609
|
+
] }), Ye = {
|
|
1291
1610
|
borderBottomWidth: "1px",
|
|
1292
1611
|
borderBottomStyle: "solid",
|
|
1293
1612
|
borderBottomColor: "#d0d0d0",
|
|
@@ -1298,59 +1617,59 @@ const ge = ({ onExecCommand: i }) => {
|
|
|
1298
1617
|
gap: "4px",
|
|
1299
1618
|
flexShrink: 0,
|
|
1300
1619
|
zIndex: 10
|
|
1301
|
-
},
|
|
1620
|
+
}, ce = {
|
|
1302
1621
|
display: "flex",
|
|
1303
1622
|
alignItems: "center",
|
|
1304
1623
|
gap: "4px",
|
|
1305
1624
|
minHeight: "32px"
|
|
1306
1625
|
};
|
|
1307
|
-
function
|
|
1626
|
+
function lt(s = {}) {
|
|
1308
1627
|
const {
|
|
1309
1628
|
initialHTML: e = "",
|
|
1310
1629
|
initialCSS: t = "",
|
|
1311
|
-
initialConfig:
|
|
1312
|
-
} =
|
|
1630
|
+
initialConfig: n = G
|
|
1631
|
+
} = s, o = H(new Oe(n)), [a, i] = R({
|
|
1313
1632
|
pages: [{ blockIndices: [] }],
|
|
1314
1633
|
pageCount: 1
|
|
1315
|
-
}), [
|
|
1316
|
-
|
|
1317
|
-
}, []),
|
|
1318
|
-
|
|
1319
|
-
}, []),
|
|
1320
|
-
const { result:
|
|
1321
|
-
|
|
1322
|
-
}, []),
|
|
1323
|
-
return
|
|
1324
|
-
e &&
|
|
1325
|
-
}, [e, t]),
|
|
1326
|
-
|
|
1327
|
-
}), []),
|
|
1328
|
-
|
|
1634
|
+
}), [c, g] = R(n), S = h((y, E) => {
|
|
1635
|
+
o.current.loadHTML(y, E);
|
|
1636
|
+
}, []), d = h((y) => {
|
|
1637
|
+
o.current.setPageConfig(y), g(o.current.getPageConfig());
|
|
1638
|
+
}, []), p = h(() => {
|
|
1639
|
+
const { result: y } = o.current.runPagination();
|
|
1640
|
+
i(y);
|
|
1641
|
+
}, []), k = h(() => o.current.getHTML(), []), A = h(() => o.current.getPlainText(), []);
|
|
1642
|
+
return F(() => {
|
|
1643
|
+
e && o.current.loadHTML(e, t);
|
|
1644
|
+
}, [e, t]), F(() => o.current.onPagination((E) => {
|
|
1645
|
+
i(E);
|
|
1646
|
+
}), []), F(() => () => {
|
|
1647
|
+
o.current.destroy();
|
|
1329
1648
|
}, []), {
|
|
1330
|
-
engine:
|
|
1331
|
-
paginationResult:
|
|
1332
|
-
pageConfig:
|
|
1333
|
-
loadHTML:
|
|
1334
|
-
setPageConfig:
|
|
1335
|
-
triggerPagination:
|
|
1336
|
-
getHTML:
|
|
1337
|
-
getPlainText:
|
|
1649
|
+
engine: o.current,
|
|
1650
|
+
paginationResult: a,
|
|
1651
|
+
pageConfig: c,
|
|
1652
|
+
loadHTML: S,
|
|
1653
|
+
setPageConfig: d,
|
|
1654
|
+
triggerPagination: p,
|
|
1655
|
+
getHTML: k,
|
|
1656
|
+
getPlainText: A
|
|
1338
1657
|
};
|
|
1339
1658
|
}
|
|
1340
1659
|
export {
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1660
|
+
Ie as DEFAULT_MARGINS,
|
|
1661
|
+
G as DEFAULT_PAGE_CONFIG,
|
|
1662
|
+
it as DocumentAPI,
|
|
1663
|
+
Oe as DocumentEngine,
|
|
1664
|
+
rt as DopeCanvas,
|
|
1665
|
+
$ as EditableManager,
|
|
1666
|
+
ue as PAGE_SIZE_PRESETS,
|
|
1667
|
+
de as PageLayoutEngine,
|
|
1668
|
+
Ge as PageSetupToolbar,
|
|
1669
|
+
Ve as TextToolbar,
|
|
1670
|
+
at as Toolbar,
|
|
1671
|
+
lt as useDocumentEngine,
|
|
1672
|
+
$e as useFormattingState,
|
|
1673
|
+
st as useSelectionContext
|
|
1355
1674
|
};
|
|
1356
1675
|
//# sourceMappingURL=dopecanvas.js.map
|