noteloom 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +344 -53
- package/bin/noteloom.mjs +139 -0
- package/dist/canvas.cjs +2 -0
- package/dist/canvas.cjs.map +1 -0
- package/dist/canvas.d.ts +2 -0
- package/dist/canvas.js +5 -0
- package/dist/canvas.js.map +1 -0
- package/dist/collab.cjs +2 -0
- package/dist/collab.cjs.map +1 -0
- package/dist/collab.d.ts +19 -0
- package/dist/collab.js +379 -0
- package/dist/collab.js.map +1 -0
- package/dist/comments.cjs +2 -0
- package/dist/comments.cjs.map +1 -0
- package/dist/comments.d.ts +17 -0
- package/dist/comments.js +19 -0
- package/dist/comments.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +392 -32
- package/dist/index.js +3983 -0
- package/dist/index.js.map +1 -0
- package/dist/persistence.cjs +2 -0
- package/dist/persistence.cjs.map +1 -0
- package/dist/persistence.d.ts +11 -0
- package/dist/persistence.js +12 -0
- package/dist/persistence.js.map +1 -0
- package/dist/shared/CommentAvatar-TKqsM8vG.js +53 -0
- package/dist/shared/CommentAvatar-TKqsM8vG.js.map +1 -0
- package/dist/shared/CommentAvatar-V457IgoQ.cjs +2 -0
- package/dist/shared/CommentAvatar-V457IgoQ.cjs.map +1 -0
- package/dist/shared/CommentThreadCard-CAJ3oPdr.cjs +2 -0
- package/dist/shared/CommentThreadCard-CAJ3oPdr.cjs.map +1 -0
- package/dist/shared/CommentThreadCard-Cxf8GwHJ.js +213 -0
- package/dist/shared/CommentThreadCard-Cxf8GwHJ.js.map +1 -0
- package/dist/shared/CommentsPanel-BwVVyMOC.js +76 -0
- package/dist/shared/CommentsPanel-BwVVyMOC.js.map +1 -0
- package/dist/shared/CommentsPanel-CES4uzye.cjs +2 -0
- package/dist/shared/CommentsPanel-CES4uzye.cjs.map +1 -0
- package/dist/shared/VersionHistory-Bg6fufP5.js +1120 -0
- package/dist/shared/VersionHistory-Bg6fufP5.js.map +1 -0
- package/dist/shared/VersionHistory-DELa2Wbq.cjs +12 -0
- package/dist/shared/VersionHistory-DELa2Wbq.cjs.map +1 -0
- package/dist/shared/VoiceListeningIndicator-BOfVmLK0.js +338 -0
- package/dist/shared/VoiceListeningIndicator-BOfVmLK0.js.map +1 -0
- package/dist/shared/VoiceListeningIndicator-DNX8JlQM.cjs +2 -0
- package/dist/shared/VoiceListeningIndicator-DNX8JlQM.cjs.map +1 -0
- package/dist/shared/fieldRegistry-BoYyW3GH.cjs +2 -0
- package/dist/shared/fieldRegistry-BoYyW3GH.cjs.map +1 -0
- package/dist/shared/fieldRegistry-PjJWXFoB.js +223 -0
- package/dist/shared/fieldRegistry-PjJWXFoB.js.map +1 -0
- package/dist/shared/icons-C1_s0jKK.js +4269 -0
- package/dist/shared/icons-C1_s0jKK.js.map +1 -0
- package/dist/shared/icons-DtCsXuU6.cjs +3531 -0
- package/dist/shared/icons-DtCsXuU6.cjs.map +1 -0
- package/dist/shared/index-B9jyyL8u.js +2145 -0
- package/dist/shared/index-B9jyyL8u.js.map +1 -0
- package/dist/shared/index-D9WEXpYM.cjs +2 -0
- package/dist/shared/index-D9WEXpYM.cjs.map +1 -0
- package/dist/shared/indexedDbPersistence-BKlGPFTP.js +112 -0
- package/dist/shared/indexedDbPersistence-BKlGPFTP.js.map +1 -0
- package/dist/shared/indexedDbPersistence-BWJ1h5Vp.cjs +2 -0
- package/dist/shared/indexedDbPersistence-BWJ1h5Vp.cjs.map +1 -0
- package/dist/shared/leafBlockFactory-A9eUhSe-.js +335 -0
- package/dist/shared/leafBlockFactory-A9eUhSe-.js.map +1 -0
- package/dist/shared/leafBlockFactory-Dp382eP8.cjs +2 -0
- package/dist/shared/leafBlockFactory-Dp382eP8.cjs.map +1 -0
- package/dist/shared/serialize-DWEfk0vU.cjs +3 -0
- package/dist/shared/serialize-DWEfk0vU.cjs.map +1 -0
- package/dist/shared/serialize-T9Odwx24.js +86 -0
- package/dist/shared/serialize-T9Odwx24.js.map +1 -0
- package/dist/shared/starter-kit-CY5wzYDf.js +4980 -0
- package/dist/shared/starter-kit-CY5wzYDf.js.map +1 -0
- package/dist/shared/starter-kit-lPN-NpJ5.cjs +27 -0
- package/dist/shared/starter-kit-lPN-NpJ5.cjs.map +1 -0
- package/dist/shared/usePopoverEdgeClamp-CDG26jBM.cjs +2 -0
- package/dist/shared/usePopoverEdgeClamp-CDG26jBM.cjs.map +1 -0
- package/dist/shared/usePopoverEdgeClamp-gmFm0CnI.js +109 -0
- package/dist/shared/usePopoverEdgeClamp-gmFm0CnI.js.map +1 -0
- package/dist/shared/useServiceWorkerUpdate-BduabXv6.js +94 -0
- package/dist/shared/useServiceWorkerUpdate-BduabXv6.js.map +1 -0
- package/dist/shared/useServiceWorkerUpdate-DQboGesi.cjs +2 -0
- package/dist/shared/useServiceWorkerUpdate-DQboGesi.cjs.map +1 -0
- package/dist/starter-kit.cjs +2 -0
- package/dist/starter-kit.cjs.map +1 -0
- package/dist/starter-kit.d.ts +9 -0
- package/dist/starter-kit.js +10 -0
- package/dist/starter-kit.js.map +1 -0
- package/dist/style.css +3529 -3200
- package/dist/versions.cjs +2 -0
- package/dist/versions.cjs.map +1 -0
- package/dist/versions.d.ts +11 -0
- package/dist/versions.js +13 -0
- package/dist/versions.js.map +1 -0
- package/dist/voice.cjs +2 -0
- package/dist/voice.cjs.map +1 -0
- package/dist/voice.d.ts +7 -0
- package/dist/voice.js +8 -0
- package/dist/voice.js.map +1 -0
- package/package.json +159 -92
- package/dist/noteloom.cjs +0 -3209
- package/dist/noteloom.cjs.map +0 -1
- package/dist/noteloom.es.js +0 -14622
- package/dist/noteloom.es.js.map +0 -1
|
@@ -0,0 +1,2145 @@
|
|
|
1
|
+
import { jsxs as _, jsx as p, Fragment as Br } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback as b, useSyncExternalStore as Xn, useEffect as Yn, useState as T, useRef as I, useMemo as vt } from "react";
|
|
3
|
+
import { a as De, g as Rt, E as Hr, j as U, P as Ur, F as Ln, X as Zr, G as jr, H as Kr, I as Vr, J as Gr, K as Fn, L as Wr, N as qr, Q as Jr, U as Qr, V as to, W as eo, Y as no, Z as ro, l as oo } from "./icons-C1_s0jKK.js";
|
|
4
|
+
import { d as so, i as io, c as ao } from "./leafBlockFactory-A9eUhSe-.js";
|
|
5
|
+
function co(t) {
|
|
6
|
+
const r = De(), e = b((s) => r.subscribe(t, s), [r, t]), o = b(() => r.getBlock(t), [r, t]);
|
|
7
|
+
return Xn(e, o);
|
|
8
|
+
}
|
|
9
|
+
function hs(t) {
|
|
10
|
+
const r = De(), e = b((s) => r.subscribe(t, s), [r, t]), o = b(() => r.getRun(t), [r, t]);
|
|
11
|
+
return Xn(e, o);
|
|
12
|
+
}
|
|
13
|
+
function Mt(t, r, e) {
|
|
14
|
+
Yn(() => {
|
|
15
|
+
if (!r) return;
|
|
16
|
+
const o = Array.isArray(t) ? t : [t], s = (u) => {
|
|
17
|
+
var x, m;
|
|
18
|
+
o.some((E) => E.current && E.current.contains(u.target)) || ((m = (x = u.target).closest) == null ? void 0 : m.call(x, ".be-select-popover")) != null || e();
|
|
19
|
+
}, i = (u) => {
|
|
20
|
+
u.key === "Escape" && e();
|
|
21
|
+
};
|
|
22
|
+
return document.addEventListener("mousedown", s), document.addEventListener("keydown", i), () => {
|
|
23
|
+
document.removeEventListener("mousedown", s), document.removeEventListener("keydown", i);
|
|
24
|
+
};
|
|
25
|
+
}, [r, e, t]);
|
|
26
|
+
}
|
|
27
|
+
const Bn = 8, Hn = 0.5, lo = 0.5, uo = 4, Ie = 0.15, fo = 8;
|
|
28
|
+
function Un(t, r) {
|
|
29
|
+
return Math.hypot(t[0] - r[0], t[1] - r[1]);
|
|
30
|
+
}
|
|
31
|
+
function Qt(t, r, e) {
|
|
32
|
+
return Math.min(e, Math.max(r, t));
|
|
33
|
+
}
|
|
34
|
+
function Kt(t) {
|
|
35
|
+
return Math.round(t * 100) / 100;
|
|
36
|
+
}
|
|
37
|
+
const Zn = 0.5;
|
|
38
|
+
function ho(t) {
|
|
39
|
+
return t.some(([, , r]) => r !== void 0 && r !== Zn);
|
|
40
|
+
}
|
|
41
|
+
function po(t, { size: r = Bn, thinning: e = Hn } = {}) {
|
|
42
|
+
const o = r / 2, s = t.length;
|
|
43
|
+
if (!ho(t)) return new Array(s).fill(o);
|
|
44
|
+
const u = new Array(s);
|
|
45
|
+
let f = 0;
|
|
46
|
+
for (let m = 0; m < s; m += 1) {
|
|
47
|
+
if (m > 0) {
|
|
48
|
+
const B = Un(t[m], t[m - 1]);
|
|
49
|
+
f = f * 0.8 + B * 0.2;
|
|
50
|
+
}
|
|
51
|
+
const E = Qt(f / fo, 0, 1), S = t[m][2] ?? Zn, H = 0.4 + 0.6 * Qt(S, 0, 1), z = Qt(
|
|
52
|
+
o * H * (1 - e * E),
|
|
53
|
+
o * Ie,
|
|
54
|
+
o
|
|
55
|
+
);
|
|
56
|
+
u[m] = z;
|
|
57
|
+
}
|
|
58
|
+
const x = Math.min(uo, Math.floor(s / 2));
|
|
59
|
+
for (let m = 0; m < x; m += 1) {
|
|
60
|
+
const E = (m + 1) / (x + 1), S = Ie + (1 - Ie) * E;
|
|
61
|
+
u[m] *= S, u[s - 1 - m] *= S;
|
|
62
|
+
}
|
|
63
|
+
return u;
|
|
64
|
+
}
|
|
65
|
+
function mo(t, r) {
|
|
66
|
+
const e = t.length;
|
|
67
|
+
if (e < 3 || r <= 0) return t;
|
|
68
|
+
const o = new Array(e);
|
|
69
|
+
o[0] = t[0], o[e - 1] = t[e - 1];
|
|
70
|
+
for (let s = 1; s < e - 1; s += 1) {
|
|
71
|
+
const i = (t[s - 1][0] + t[s + 1][0]) / 2, u = (t[s - 1][1] + t[s + 1][1]) / 2, f = t[s][0] + (i - t[s][0]) * r, x = t[s][1] + (u - t[s][1]) * r;
|
|
72
|
+
o[s] = [f, x, t[s][2]];
|
|
73
|
+
}
|
|
74
|
+
return o;
|
|
75
|
+
}
|
|
76
|
+
function yo(t, r) {
|
|
77
|
+
const e = t.length, o = new Array(e), s = new Array(e);
|
|
78
|
+
for (let i = 0; i < e; i += 1) {
|
|
79
|
+
const u = t[Math.max(0, i - 1)], f = t[Math.min(e - 1, i + 1)];
|
|
80
|
+
let x = f[0] - u[0], m = f[1] - u[1];
|
|
81
|
+
const E = Math.hypot(x, m) || 1;
|
|
82
|
+
x /= E, m /= E;
|
|
83
|
+
const S = -m, H = x, z = r[i];
|
|
84
|
+
o[i] = [t[i][0] + S * z, t[i][1] + H * z], s[i] = [t[i][0] - S * z, t[i][1] - H * z];
|
|
85
|
+
}
|
|
86
|
+
return { left: o, right: s };
|
|
87
|
+
}
|
|
88
|
+
function jn(t) {
|
|
89
|
+
if (t.length === 0) return "";
|
|
90
|
+
let r = `M${Kt(t[0][0])},${Kt(t[0][1])}`;
|
|
91
|
+
for (let e = 1; e < t.length; e += 1) r += ` L${Kt(t[e][0])},${Kt(t[e][1])}`;
|
|
92
|
+
return r;
|
|
93
|
+
}
|
|
94
|
+
function xo([t, r], e) {
|
|
95
|
+
const s = [];
|
|
96
|
+
for (let i = 0; i < 12; i += 1) {
|
|
97
|
+
const u = i / 12 * Math.PI * 2;
|
|
98
|
+
s.push([t + Math.cos(u) * e, r + Math.sin(u) * e]);
|
|
99
|
+
}
|
|
100
|
+
return `${jn(s)} Z`;
|
|
101
|
+
}
|
|
102
|
+
function ee(t, r = {}) {
|
|
103
|
+
const {
|
|
104
|
+
size: e = Bn,
|
|
105
|
+
thinning: o = Hn,
|
|
106
|
+
smoothing: s = lo
|
|
107
|
+
} = r;
|
|
108
|
+
if (!t || t.length === 0) return "";
|
|
109
|
+
const i = [t[0]];
|
|
110
|
+
for (let S = 1; S < t.length; S += 1)
|
|
111
|
+
Un(t[S], i[i.length - 1]) > 0.1 && i.push(t[S]);
|
|
112
|
+
if (i.length === 1) {
|
|
113
|
+
const S = i[0][2] ?? 0.5, H = e / 2 * (0.4 + 0.6 * Qt(S, 0, 1));
|
|
114
|
+
return xo(i[0], H);
|
|
115
|
+
}
|
|
116
|
+
const u = po(i, { size: e, thinning: o }), f = mo(i, s), { left: x, right: m } = yo(f, u), E = [...x, ...m.slice().reverse()];
|
|
117
|
+
return `${jn(E)} Z`;
|
|
118
|
+
}
|
|
119
|
+
function te(t) {
|
|
120
|
+
if (!t || t.length === 0) return { minX: 0, minY: 0, maxX: 0, maxY: 0 };
|
|
121
|
+
let r = 1 / 0, e = 1 / 0, o = -1 / 0, s = -1 / 0;
|
|
122
|
+
for (const [i, u] of t)
|
|
123
|
+
i < r && (r = i), u < e && (e = u), i > o && (o = i), u > s && (s = u);
|
|
124
|
+
return { minX: r, minY: e, maxX: o, maxY: s };
|
|
125
|
+
}
|
|
126
|
+
function _e(t, r) {
|
|
127
|
+
const e = t.getBoundingClientRect(), o = e.width || 1, s = e.height || 1, i = Math.min(o / r, s / r), u = (o - r * i) / 2, f = (s - r * i) / 2;
|
|
128
|
+
return { rect: e, scale: i, offsetX: u, offsetY: f };
|
|
129
|
+
}
|
|
130
|
+
function J(t, r, e = { x: 0, y: 0, size: 1e3 }) {
|
|
131
|
+
const { rect: o, scale: s, offsetX: i, offsetY: u } = _e(r, e.size), f = e.x + (t.clientX - o.left - i) / s, x = e.y + (t.clientY - o.top - u) / s;
|
|
132
|
+
return [f, x];
|
|
133
|
+
}
|
|
134
|
+
function ze(t, r) {
|
|
135
|
+
return _e(t, r).scale;
|
|
136
|
+
}
|
|
137
|
+
function go(t, r, e, o) {
|
|
138
|
+
const [s, i] = J(t, r, e), { rect: u, scale: f, offsetX: x, offsetY: m } = _e(r, o), E = s - (t.clientX - u.left - x) / f, S = i - (t.clientY - u.top - m) / f;
|
|
139
|
+
return { x: E, y: S };
|
|
140
|
+
}
|
|
141
|
+
function zn(t, r) {
|
|
142
|
+
const e = t.x + t.size / 2, o = t.y + t.size / 2;
|
|
143
|
+
return { x: e - r / 2, y: o - r / 2 };
|
|
144
|
+
}
|
|
145
|
+
function Pt(t, r, e, o) {
|
|
146
|
+
if (e <= o) return { x: t, y: r };
|
|
147
|
+
const s = (o - e) / 2;
|
|
148
|
+
return { x: s, y: s };
|
|
149
|
+
}
|
|
150
|
+
function _t(t, r, e = 0) {
|
|
151
|
+
return t.minX - e <= r.maxX && t.maxX + e >= r.minX && t.minY - e <= r.maxY && t.maxY + e >= r.minY;
|
|
152
|
+
}
|
|
153
|
+
function Lt(t, r, e, o) {
|
|
154
|
+
const s = Math.min(t, e), i = Math.min(r, o), u = Math.abs(e - t), f = Math.abs(o - r);
|
|
155
|
+
return { x: s, y: i, width: u, height: f };
|
|
156
|
+
}
|
|
157
|
+
function Kn(t, r, e, o, s) {
|
|
158
|
+
const i = s * Math.PI / 180, u = Math.cos(i), f = Math.sin(i), x = t - e, m = r - o;
|
|
159
|
+
return [e + x * u - m * f, o + x * f + m * u];
|
|
160
|
+
}
|
|
161
|
+
function Vn(t, r, e) {
|
|
162
|
+
return t >= e.x && t <= e.x + e.width && r >= e.y && r <= e.y + e.height;
|
|
163
|
+
}
|
|
164
|
+
function bo(t, r, e) {
|
|
165
|
+
const o = e.width / 2, s = e.height / 2;
|
|
166
|
+
if (o === 0 || s === 0) return !1;
|
|
167
|
+
const i = e.x + o, u = e.y + s, f = (t - i) / o, x = (r - u) / s;
|
|
168
|
+
return f * f + x * x <= 1;
|
|
169
|
+
}
|
|
170
|
+
function wo(t, r, e, o, s, i) {
|
|
171
|
+
const u = s - e, f = i - o, x = u * u + f * f;
|
|
172
|
+
if (x === 0) return Math.hypot(t - e, r - o);
|
|
173
|
+
let m = ((t - e) * u + (r - o) * f) / x;
|
|
174
|
+
m = Math.min(1, Math.max(0, m));
|
|
175
|
+
const E = e + m * u, S = o + m * f;
|
|
176
|
+
return Math.hypot(t - E, r - S);
|
|
177
|
+
}
|
|
178
|
+
function Gn(t, r, e, o, s, i, u) {
|
|
179
|
+
return wo(t, r, e, o, s, i) <= u;
|
|
180
|
+
}
|
|
181
|
+
function Wn(t) {
|
|
182
|
+
const { x: r, y: e, width: o, height: s } = t;
|
|
183
|
+
return [
|
|
184
|
+
[r + o / 2, e],
|
|
185
|
+
[r + o, e + s / 2],
|
|
186
|
+
[r + o / 2, e + s],
|
|
187
|
+
[r, e + s / 2]
|
|
188
|
+
];
|
|
189
|
+
}
|
|
190
|
+
function qn(t) {
|
|
191
|
+
const { x: r, y: e, width: o, height: s } = t;
|
|
192
|
+
return [
|
|
193
|
+
[r + o / 2, e],
|
|
194
|
+
[r + o, e + s],
|
|
195
|
+
[r, e + s]
|
|
196
|
+
];
|
|
197
|
+
}
|
|
198
|
+
function Jn(t, r = 5) {
|
|
199
|
+
const { x: e, y: o, width: s, height: i } = t, u = e + s / 2, f = o + i / 2, x = s / 2, m = i / 2, E = 0.4, S = [], H = Math.PI / r;
|
|
200
|
+
let z = -Math.PI / 2;
|
|
201
|
+
for (let B = 0; B < r * 2; B += 1) {
|
|
202
|
+
const A = B % 2 === 0, ae = A ? x : x * E, et = A ? m : m * E;
|
|
203
|
+
S.push([u + Math.cos(z) * ae, f + Math.sin(z) * et]), z += H;
|
|
204
|
+
}
|
|
205
|
+
return S;
|
|
206
|
+
}
|
|
207
|
+
function So(t, r, e) {
|
|
208
|
+
let o = !1;
|
|
209
|
+
for (let s = 0, i = e.length - 1; s < e.length; i = s, s += 1) {
|
|
210
|
+
const [u, f] = e[s], [x, m] = e[i];
|
|
211
|
+
f > r != m > r && t < (x - u) * (r - f) / (m - f) + u && (o = !o);
|
|
212
|
+
}
|
|
213
|
+
return o;
|
|
214
|
+
}
|
|
215
|
+
function Qn(t, r, e, o, s = 24) {
|
|
216
|
+
const i = e - t, u = o - r, f = Math.hypot(i, u), [x, m] = f === 0 ? [1, 0] : [i / f, u / f], E = e - x * s, S = o - m * s, H = -m, z = x, B = s / 2;
|
|
217
|
+
return [
|
|
218
|
+
[e, o],
|
|
219
|
+
[E + H * B, S + z * B],
|
|
220
|
+
[E - H * B, S - z * B]
|
|
221
|
+
];
|
|
222
|
+
}
|
|
223
|
+
function ko({ compute: t, onCommit: r }) {
|
|
224
|
+
const [e, o] = T(null), s = b(
|
|
225
|
+
(i, u) => {
|
|
226
|
+
i.preventDefault();
|
|
227
|
+
const f = (m) => o(t(m, u)), x = (m) => {
|
|
228
|
+
document.removeEventListener("mousemove", f), document.removeEventListener("mouseup", x), r(t(m, u)), o(null);
|
|
229
|
+
};
|
|
230
|
+
document.addEventListener("mousemove", f), document.addEventListener("mouseup", x);
|
|
231
|
+
},
|
|
232
|
+
[t, r]
|
|
233
|
+
);
|
|
234
|
+
return { dragValue: e, startDrag: s };
|
|
235
|
+
}
|
|
236
|
+
const ne = 480, re = 320;
|
|
237
|
+
function Eo({
|
|
238
|
+
strokes: t = [],
|
|
239
|
+
shapes: r = [],
|
|
240
|
+
width: e = ne,
|
|
241
|
+
height: o = re
|
|
242
|
+
} = {}) {
|
|
243
|
+
return function(i) {
|
|
244
|
+
return {
|
|
245
|
+
block: {
|
|
246
|
+
id: Rt(),
|
|
247
|
+
type: "canvas",
|
|
248
|
+
parentId: i,
|
|
249
|
+
contentIds: [],
|
|
250
|
+
props: { strokes: t, shapes: r, width: e, height: o }
|
|
251
|
+
},
|
|
252
|
+
runs: []
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function oe(t) {
|
|
257
|
+
return t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
258
|
+
}
|
|
259
|
+
function ct(t) {
|
|
260
|
+
return oe(t).replace(/"/g, """);
|
|
261
|
+
}
|
|
262
|
+
function Io(t, r) {
|
|
263
|
+
var s, i;
|
|
264
|
+
if (!t) return "";
|
|
265
|
+
if (t.type !== "text") {
|
|
266
|
+
const u = (s = r == null ? void 0 : r.inlineRegistry) == null ? void 0 : s.get(t.type);
|
|
267
|
+
return u ? u.toHTML(t, r) : oe(t.value ?? "");
|
|
268
|
+
}
|
|
269
|
+
const e = t.marks ?? {};
|
|
270
|
+
let o = oe(t.value ?? "");
|
|
271
|
+
if (e.code && (o = `<code>${o}</code>`), e.bold && (o = `<strong>${o}</strong>`), e.italic && (o = `<em>${o}</em>`), e.underline && (o = `<u>${o}</u>`), e.strike && (o = `<s>${o}</s>`), e.subscript && (o = `<sub>${o}</sub>`), e.superscript && (o = `<sup>${o}</sup>`), e.color && (o = `<span style="color:${ct(e.color)}">${o}</span>`), e.highlight && (o = `<span style="background-color:${ct(e.highlight)}">${o}</span>`), (i = e.link) != null && i.href) {
|
|
272
|
+
const u = e.link.target === "_blank" ? ' target="_blank" rel="noopener noreferrer"' : "";
|
|
273
|
+
o = `<a href="${ct(e.link.href)}"${u}>${o}</a>`;
|
|
274
|
+
}
|
|
275
|
+
return o;
|
|
276
|
+
}
|
|
277
|
+
function ps(t, r) {
|
|
278
|
+
return (t ?? []).map((e) => Io(e, r)).join("");
|
|
279
|
+
}
|
|
280
|
+
function ms(t, r) {
|
|
281
|
+
var e;
|
|
282
|
+
if (!t) return "";
|
|
283
|
+
if (t.type !== "text") {
|
|
284
|
+
const o = (e = r == null ? void 0 : r.inlineRegistry) == null ? void 0 : e.get(t.type);
|
|
285
|
+
return o ? o.toPlainText(t, r) : t.value ?? "";
|
|
286
|
+
}
|
|
287
|
+
return t.value ?? "";
|
|
288
|
+
}
|
|
289
|
+
function zo(t) {
|
|
290
|
+
return (t ?? "").replace(/[\\`*_[\]]/g, (r) => `\\${r}`);
|
|
291
|
+
}
|
|
292
|
+
function $o(t, r) {
|
|
293
|
+
var i, u;
|
|
294
|
+
if (!t) return "";
|
|
295
|
+
if (t.type !== "text") {
|
|
296
|
+
const f = (i = r == null ? void 0 : r.inlineRegistry) == null ? void 0 : i.get(t.type);
|
|
297
|
+
return f ? f.toPlainText(t, r) : t.value ?? "";
|
|
298
|
+
}
|
|
299
|
+
const e = t.marks ?? {}, o = t.value ?? "";
|
|
300
|
+
let s = e.code ? o : zo(o);
|
|
301
|
+
return e.code && (s = `\`${s}\``), e.bold && (s = `**${s}**`), e.italic && (s = `*${s}*`), e.strike && (s = `~~${s}~~`), e.underline && (s = `<u>${s}</u>`), e.subscript && (s = `<sub>${s}</sub>`), e.superscript && (s = `<sup>${s}</sup>`), e.color && (s = `<span style="color:${ct(e.color)}">${s}</span>`), e.highlight && (s = `<span style="background-color:${ct(e.highlight)}">${s}</span>`), (u = e.link) != null && u.href && (s = `[${s}](${e.link.href})`), s;
|
|
302
|
+
}
|
|
303
|
+
function ys(t, r) {
|
|
304
|
+
return (t ?? []).map((e) => $o(e, r)).join("");
|
|
305
|
+
}
|
|
306
|
+
const No = 1e6;
|
|
307
|
+
function Ct(t, r, e) {
|
|
308
|
+
return typeof t.z == "number" ? t.z : r ? No + e : e;
|
|
309
|
+
}
|
|
310
|
+
function se(t, r) {
|
|
311
|
+
const e = [
|
|
312
|
+
...t.map((o, s) => ({ kind: "stroke", item: o, z: Ct(o, !1, s) })),
|
|
313
|
+
...r.map((o, s) => ({ kind: "shape", item: o, z: Ct(o, !0, s) }))
|
|
314
|
+
];
|
|
315
|
+
return e.sort((o, s) => o.z - s.z), e;
|
|
316
|
+
}
|
|
317
|
+
function Vt(t, r) {
|
|
318
|
+
let e = -1;
|
|
319
|
+
return t.forEach((o, s) => {
|
|
320
|
+
e = Math.max(e, Ct(o, !1, s));
|
|
321
|
+
}), r.forEach((o, s) => {
|
|
322
|
+
e = Math.max(e, Ct(o, !0, s));
|
|
323
|
+
}), e + 1;
|
|
324
|
+
}
|
|
325
|
+
function To(t, r) {
|
|
326
|
+
let e = 1 / 0;
|
|
327
|
+
return t.forEach((o, s) => {
|
|
328
|
+
e = Math.min(e, Ct(o, !1, s));
|
|
329
|
+
}), r.forEach((o, s) => {
|
|
330
|
+
e = Math.min(e, Ct(o, !0, s));
|
|
331
|
+
}), e === 1 / 0 ? 0 : e - 1;
|
|
332
|
+
}
|
|
333
|
+
const vo = {
|
|
334
|
+
diamond: Wn,
|
|
335
|
+
triangle: qn,
|
|
336
|
+
star: Jn
|
|
337
|
+
};
|
|
338
|
+
function Mo(t) {
|
|
339
|
+
const r = t.strokeWidth ?? 8, e = ct(t.color);
|
|
340
|
+
if (t.type === "arrow") {
|
|
341
|
+
const f = Math.max(16, r * 3), m = Qn(t.x1, t.y1, t.x2, t.y2, f).map(([E, S]) => `${E},${S}`).join(" ");
|
|
342
|
+
return `<line x1="${t.x1}" y1="${t.y1}" x2="${t.x2}" y2="${t.y2}" stroke="${e}" stroke-width="${r}"></line><polygon points="${m}" fill="${e}"></polygon>`;
|
|
343
|
+
}
|
|
344
|
+
const o = t.fillColor ? ct(t.fillColor) : "none";
|
|
345
|
+
let s;
|
|
346
|
+
if (t.type === "rectangle")
|
|
347
|
+
s = `<rect x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}" fill="${o}" stroke="${e}" stroke-width="${r}"></rect>`;
|
|
348
|
+
else if (t.type === "ellipse") {
|
|
349
|
+
const f = t.x + t.width / 2, x = t.y + t.height / 2;
|
|
350
|
+
s = `<ellipse cx="${f}" cy="${x}" rx="${t.width / 2}" ry="${t.height / 2}" fill="${o}" stroke="${e}" stroke-width="${r}"></ellipse>`;
|
|
351
|
+
} else if (t.type === "text") {
|
|
352
|
+
const f = t.fontSize ?? 28, x = oe(t.text ?? "");
|
|
353
|
+
s = `<foreignObject x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}"><div xmlns="http://www.w3.org/1999/xhtml" style="width:100%;height:100%;overflow:hidden;color:${e};font-size:${f}px;line-height:1.3;white-space:pre-wrap;word-break:break-word;">${x}</div></foreignObject>`;
|
|
354
|
+
} else {
|
|
355
|
+
const f = vo[t.type];
|
|
356
|
+
if (!f) return "";
|
|
357
|
+
const x = { x: t.x, y: t.y, width: t.width, height: t.height };
|
|
358
|
+
s = `<polygon points="${f(x).map(([E, S]) => `${E},${S}`).join(" ")}" fill="${o}" stroke="${e}" stroke-width="${r}"></polygon>`;
|
|
359
|
+
}
|
|
360
|
+
if (!t.rotation) return s;
|
|
361
|
+
const i = t.x + t.width / 2, u = t.y + t.height / 2;
|
|
362
|
+
return `<g transform="rotate(${t.rotation} ${i} ${u})">${s}</g>`;
|
|
363
|
+
}
|
|
364
|
+
function tr(t) {
|
|
365
|
+
const { strokes: r = [], shapes: e = [], width: o, height: s } = t.props, i = se(r, e).map(
|
|
366
|
+
({ kind: u, item: f }) => u === "stroke" ? `<path fill="${ct(f.color)}" d="${ee(f.points, { size: f.size })}"></path>` : Mo(f)
|
|
367
|
+
).join("");
|
|
368
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 1000" width="${o}" height="${s}">${i}</svg>`;
|
|
369
|
+
}
|
|
370
|
+
const Z = 1e3, $n = "#1a1a1a", er = 8, Nn = ["#1a1a1a", "#e03131", "#2f9e44", "#1971c2", "#f08c00"], Po = 2, Ro = 40, Co = 24, Ao = 6, Gt = 160, $e = 120, Ne = 0.5, Te = 4, Wt = 1.1, Tn = 4, qt = 24, Do = 1, _o = 10, vn = {
|
|
371
|
+
ArrowUp: [0, -1],
|
|
372
|
+
ArrowDown: [0, 1],
|
|
373
|
+
ArrowLeft: [-1, 0],
|
|
374
|
+
ArrowRight: [1, 0]
|
|
375
|
+
}, Oo = 220, Xo = 60, Re = 28, Yo = 12, Lo = 96, Ce = 10, Mn = 15, Pn = Ce * 5;
|
|
376
|
+
function K(t) {
|
|
377
|
+
return Math.round(t / Ce) * Ce;
|
|
378
|
+
}
|
|
379
|
+
function Fo(t) {
|
|
380
|
+
return Math.round(t / Mn) * Mn;
|
|
381
|
+
}
|
|
382
|
+
function Bo() {
|
|
383
|
+
const t = I(/* @__PURE__ */ new WeakMap());
|
|
384
|
+
return (r) => {
|
|
385
|
+
const e = t.current;
|
|
386
|
+
let o = e.get(r);
|
|
387
|
+
return o === void 0 && (o = ee(r.points, { size: r.size }), e.set(r, o)), o;
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function Ho(t, r, e) {
|
|
391
|
+
return { minX: t - e, minY: r - e, maxX: t + e, maxY: r + e };
|
|
392
|
+
}
|
|
393
|
+
function Rn(t) {
|
|
394
|
+
let r = 0, e = 0;
|
|
395
|
+
for (const s of t.values())
|
|
396
|
+
r += s.x, e += s.y;
|
|
397
|
+
const o = t.size || 1;
|
|
398
|
+
return { x: r / o, y: e / o };
|
|
399
|
+
}
|
|
400
|
+
function Uo(t, r, e, o) {
|
|
401
|
+
const s = t.points;
|
|
402
|
+
if (s.length === 1) {
|
|
403
|
+
const [i, u] = s[0];
|
|
404
|
+
return Math.hypot(r - i, e - u) <= o;
|
|
405
|
+
}
|
|
406
|
+
for (let i = 0; i < s.length - 1; i += 1) {
|
|
407
|
+
const [u, f] = s[i], [x, m] = s[i + 1];
|
|
408
|
+
if (Gn(r, e, u, f, x, m, o)) return !0;
|
|
409
|
+
}
|
|
410
|
+
return !1;
|
|
411
|
+
}
|
|
412
|
+
const ve = /* @__PURE__ */ new Set(["rectangle", "ellipse", "arrow", "diamond", "triangle", "star"]), nr = {
|
|
413
|
+
diamond: Wn,
|
|
414
|
+
triangle: qn,
|
|
415
|
+
star: Jn
|
|
416
|
+
}, Cn = [
|
|
417
|
+
{ type: "rectangle", label: "Rectangle", Icon: Fn },
|
|
418
|
+
{ type: "ellipse", label: "Ellipse", Icon: Wr },
|
|
419
|
+
{ type: "arrow", label: "Arrow", Icon: qr },
|
|
420
|
+
{ type: "diamond", label: "Diamond", Icon: Jr },
|
|
421
|
+
{ type: "triangle", label: "Triangle", Icon: Qr },
|
|
422
|
+
{ type: "star", label: "Star", Icon: to }
|
|
423
|
+
], An = [
|
|
424
|
+
{ mode: "object", label: "Object Eraser", Icon: Ln },
|
|
425
|
+
{ mode: "precise", label: "Precise Eraser", Icon: Zr }
|
|
426
|
+
];
|
|
427
|
+
function Me(t, r, e, o) {
|
|
428
|
+
return t.type === "arrow" ? {
|
|
429
|
+
type: "arrow",
|
|
430
|
+
x1: t.x1,
|
|
431
|
+
y1: t.y1,
|
|
432
|
+
x2: t.x2,
|
|
433
|
+
y2: t.y2,
|
|
434
|
+
color: r,
|
|
435
|
+
strokeWidth: e
|
|
436
|
+
} : {
|
|
437
|
+
type: t.type,
|
|
438
|
+
...Lt(t.x1, t.y1, t.x2, t.y2),
|
|
439
|
+
color: r,
|
|
440
|
+
strokeWidth: e,
|
|
441
|
+
fillColor: o
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
const Zo = 16;
|
|
445
|
+
function rr(t, r, e) {
|
|
446
|
+
if (t.type === "arrow")
|
|
447
|
+
return Gn(r, e, t.x1, t.y1, t.x2, t.y2, Zo);
|
|
448
|
+
const o = { x: t.x, y: t.y, width: t.width, height: t.height };
|
|
449
|
+
let [s, i] = [r, e];
|
|
450
|
+
if (t.rotation) {
|
|
451
|
+
const { cx: f, cy: x } = ie(t);
|
|
452
|
+
[s, i] = Kn(r, e, f, x, -t.rotation);
|
|
453
|
+
}
|
|
454
|
+
const u = nr[t.type];
|
|
455
|
+
return u ? So(s, i, u(o)) : t.type === "ellipse" ? bo(s, i, o) : Vn(s, i, o);
|
|
456
|
+
}
|
|
457
|
+
function jo(t, r, e) {
|
|
458
|
+
for (let o = e.length - 1; o >= 0; o -= 1)
|
|
459
|
+
if (rr(e[o], t, r)) return e[o].id;
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
462
|
+
function Ot(t, r, e) {
|
|
463
|
+
return t.type === "arrow" ? { ...t, x1: t.x1 + r, y1: t.y1 + e, x2: t.x2 + r, y2: t.y2 + e } : { ...t, x: t.x + r, y: t.y + e };
|
|
464
|
+
}
|
|
465
|
+
function Ft(t) {
|
|
466
|
+
return t.type === "arrow" ? {
|
|
467
|
+
x: Math.min(t.x1, t.x2),
|
|
468
|
+
y: Math.min(t.y1, t.y2),
|
|
469
|
+
width: Math.abs(t.x2 - t.x1),
|
|
470
|
+
height: Math.abs(t.y2 - t.y1)
|
|
471
|
+
} : { x: t.x, y: t.y, width: t.width, height: t.height };
|
|
472
|
+
}
|
|
473
|
+
function ie(t) {
|
|
474
|
+
const r = Ft(t);
|
|
475
|
+
return { cx: r.x + r.width / 2, cy: r.y + r.height / 2 };
|
|
476
|
+
}
|
|
477
|
+
function Xt(t, r, e) {
|
|
478
|
+
return { ...t, points: t.points.map(([o, s, i]) => [o + r, s + e, i]) };
|
|
479
|
+
}
|
|
480
|
+
function Ko(t, r) {
|
|
481
|
+
const e = [];
|
|
482
|
+
let o = [];
|
|
483
|
+
for (let s = 0; s < t.length; s += 1)
|
|
484
|
+
r.has(s) ? (o.length > 0 && e.push(o), o = []) : o.push(t[s]);
|
|
485
|
+
return o.length > 0 && e.push(o), e;
|
|
486
|
+
}
|
|
487
|
+
function or(t) {
|
|
488
|
+
const r = te(t.points);
|
|
489
|
+
return { x: r.minX, y: r.minY, width: r.maxX - r.minX, height: r.maxY - r.minY };
|
|
490
|
+
}
|
|
491
|
+
function Vo(t, r) {
|
|
492
|
+
return t === "stroke" ? or(r) : Ft(r);
|
|
493
|
+
}
|
|
494
|
+
function Dn(t, r) {
|
|
495
|
+
var u, f;
|
|
496
|
+
const e = ((u = t == null ? void 0 : t.props) == null ? void 0 : u.strokes) ?? [], o = ((f = t == null ? void 0 : t.props) == null ? void 0 : f.shapes) ?? [], s = e.find((x) => x.id === r);
|
|
497
|
+
if (s) return { kind: "stroke", item: s };
|
|
498
|
+
const i = o.find((x) => x.id === r);
|
|
499
|
+
return i ? { kind: "shape", item: i } : null;
|
|
500
|
+
}
|
|
501
|
+
function Go(t, r, e, o) {
|
|
502
|
+
const s = se(e, o);
|
|
503
|
+
for (let i = s.length - 1; i >= 0; i -= 1) {
|
|
504
|
+
const { kind: u, item: f } = s[i];
|
|
505
|
+
if (u === "shape") {
|
|
506
|
+
if (rr(f, t, r)) return { kind: "shape", id: f.id };
|
|
507
|
+
} else if (Vn(t, r, or(f)))
|
|
508
|
+
return { kind: "stroke", id: f.id };
|
|
509
|
+
}
|
|
510
|
+
return null;
|
|
511
|
+
}
|
|
512
|
+
const Jt = 24, Yt = 14;
|
|
513
|
+
function Ae(t) {
|
|
514
|
+
return {
|
|
515
|
+
nw: [t.x, t.y],
|
|
516
|
+
ne: [t.x + t.width, t.y],
|
|
517
|
+
sw: [t.x, t.y + t.height],
|
|
518
|
+
se: [t.x + t.width, t.y + t.height]
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
const Wo = { nw: "se", ne: "sw", sw: "ne", se: "nw" }, qo = 32;
|
|
522
|
+
function sr(t) {
|
|
523
|
+
const r = Ft(t), e = r.x + r.width / 2, o = r.y - qo;
|
|
524
|
+
if (!t.rotation) return [e, o];
|
|
525
|
+
const { cx: s, cy: i } = ie(t);
|
|
526
|
+
return Kn(e, o, s, i, t.rotation);
|
|
527
|
+
}
|
|
528
|
+
function Jo(t, r, e) {
|
|
529
|
+
if (!e) return null;
|
|
530
|
+
if (e.type === "arrow")
|
|
531
|
+
return Math.hypot(t - e.x1, r - e.y1) <= Jt ? "start" : Math.hypot(t - e.x2, r - e.y2) <= Jt ? "end" : null;
|
|
532
|
+
const [o, s] = sr(e);
|
|
533
|
+
if (Math.hypot(t - o, r - s) <= Jt) return "rotate";
|
|
534
|
+
if (e.rotation) return null;
|
|
535
|
+
for (const [i, [u, f]] of Object.entries(Ae(e)))
|
|
536
|
+
if (Math.hypot(t - u, r - f) <= Jt) return i;
|
|
537
|
+
return null;
|
|
538
|
+
}
|
|
539
|
+
function Pe(t, r) {
|
|
540
|
+
return r.mode === "arrow-endpoint" ? r.endpoint === "start" ? { ...t, x1: r.x, y1: r.y } : { ...t, x2: r.x, y2: r.y } : r.mode === "rotate" ? { ...t, rotation: r.rotation } : { ...t, ...Lt(r.fixedX, r.fixedY, r.x, r.y) };
|
|
541
|
+
}
|
|
542
|
+
function _n({ shape: t, opacity: r = 1 }) {
|
|
543
|
+
const e = t.strokeWidth ?? er;
|
|
544
|
+
let o;
|
|
545
|
+
if (t.type === "rectangle")
|
|
546
|
+
o = /* @__PURE__ */ p(
|
|
547
|
+
"rect",
|
|
548
|
+
{
|
|
549
|
+
x: t.x,
|
|
550
|
+
y: t.y,
|
|
551
|
+
width: t.width,
|
|
552
|
+
height: t.height,
|
|
553
|
+
fill: t.fillColor ?? "none",
|
|
554
|
+
stroke: t.color,
|
|
555
|
+
strokeWidth: e,
|
|
556
|
+
opacity: r
|
|
557
|
+
}
|
|
558
|
+
);
|
|
559
|
+
else if (t.type === "ellipse")
|
|
560
|
+
o = /* @__PURE__ */ p(
|
|
561
|
+
"ellipse",
|
|
562
|
+
{
|
|
563
|
+
cx: t.x + t.width / 2,
|
|
564
|
+
cy: t.y + t.height / 2,
|
|
565
|
+
rx: t.width / 2,
|
|
566
|
+
ry: t.height / 2,
|
|
567
|
+
fill: t.fillColor ?? "none",
|
|
568
|
+
stroke: t.color,
|
|
569
|
+
strokeWidth: e,
|
|
570
|
+
opacity: r
|
|
571
|
+
}
|
|
572
|
+
);
|
|
573
|
+
else if (t.type === "arrow") {
|
|
574
|
+
const u = Math.max(16, e * 3), f = Qn(t.x1, t.y1, t.x2, t.y2, u);
|
|
575
|
+
return /* @__PURE__ */ _("g", { opacity: r, children: [
|
|
576
|
+
/* @__PURE__ */ p(
|
|
577
|
+
"line",
|
|
578
|
+
{
|
|
579
|
+
x1: t.x1,
|
|
580
|
+
y1: t.y1,
|
|
581
|
+
x2: t.x2,
|
|
582
|
+
y2: t.y2,
|
|
583
|
+
stroke: t.color,
|
|
584
|
+
strokeWidth: e
|
|
585
|
+
}
|
|
586
|
+
),
|
|
587
|
+
/* @__PURE__ */ p("polygon", { points: f.map(([x, m]) => `${x},${m}`).join(" "), fill: t.color })
|
|
588
|
+
] });
|
|
589
|
+
} else if (t.type === "text")
|
|
590
|
+
o = /* @__PURE__ */ p(
|
|
591
|
+
"foreignObject",
|
|
592
|
+
{
|
|
593
|
+
x: t.x,
|
|
594
|
+
y: t.y,
|
|
595
|
+
width: t.width,
|
|
596
|
+
height: t.height,
|
|
597
|
+
opacity: r,
|
|
598
|
+
children: /* @__PURE__ */ p(
|
|
599
|
+
"div",
|
|
600
|
+
{
|
|
601
|
+
xmlns: "http://www.w3.org/1999/xhtml",
|
|
602
|
+
style: {
|
|
603
|
+
width: "100%",
|
|
604
|
+
height: "100%",
|
|
605
|
+
overflow: "hidden",
|
|
606
|
+
color: t.color,
|
|
607
|
+
fontSize: t.fontSize ?? Re,
|
|
608
|
+
lineHeight: 1.3,
|
|
609
|
+
whiteSpace: "pre-wrap",
|
|
610
|
+
wordBreak: "break-word",
|
|
611
|
+
fontFamily: "inherit"
|
|
612
|
+
},
|
|
613
|
+
children: t.text
|
|
614
|
+
}
|
|
615
|
+
)
|
|
616
|
+
}
|
|
617
|
+
);
|
|
618
|
+
else {
|
|
619
|
+
const u = nr[t.type];
|
|
620
|
+
if (!u) return null;
|
|
621
|
+
const f = { x: t.x, y: t.y, width: t.width, height: t.height }, x = u(f).map(([m, E]) => `${m},${E}`).join(" ");
|
|
622
|
+
o = /* @__PURE__ */ p(
|
|
623
|
+
"polygon",
|
|
624
|
+
{
|
|
625
|
+
points: x,
|
|
626
|
+
fill: t.fillColor ?? "none",
|
|
627
|
+
stroke: t.color,
|
|
628
|
+
strokeWidth: e,
|
|
629
|
+
opacity: r
|
|
630
|
+
}
|
|
631
|
+
);
|
|
632
|
+
}
|
|
633
|
+
if (!t.rotation) return o;
|
|
634
|
+
const { cx: s, cy: i } = ie(t);
|
|
635
|
+
return /* @__PURE__ */ p("g", { transform: `rotate(${t.rotation} ${s} ${i})`, children: o });
|
|
636
|
+
}
|
|
637
|
+
function Qo({ id: t }) {
|
|
638
|
+
const r = De(), e = co(t), o = Hr("be-canvas", e), s = Bo(), [i, u] = T("pen"), [f, x] = T("object"), [m, E] = T($n), [S, H] = T(er), [z, B] = T(null), [A, ae] = T(!0), [et, lr] = T(Re), [ur, fr] = T("rectangle"), [ce, Oe] = T(!1), [le, Xe] = T(!1), [ue, Ye] = T(!1), [fe, Le] = T(!1), [de, Fe] = T(!1), [he, Be] = T(!1), He = I(null), Ue = I(null), Ze = I(null), je = I(null), Ke = I(null), Ve = I(null), Ge = I(null), We = I(null), qe = I(null), Je = I(null), Qe = I(null), tn = I(null), dr = vt(() => [He, Ue], []), hr = vt(() => [Ze, je], []), pr = vt(() => [Ke, Ve], []), mr = vt(() => [Ge, We], []), yr = vt(() => [qe, Je], []), xr = vt(() => [Qe, tn], []), en = b(() => Oe(!1), []), pe = b(() => Xe(!1), []), gr = b(() => Ye(!1), []), nn = b(() => Le(!1), []), br = b(() => Fe(!1), []), rn = b(() => Be(!1), []);
|
|
639
|
+
Mt(dr, ce, en), Mt(hr, le, pe), Mt(pr, ue, gr), Mt(mr, fe, nn), Mt(yr, de, br), Mt(xr, he, rn);
|
|
640
|
+
const q = I(null), At = I([]), dt = I(!1), ht = I(null), [on, sn] = T(null), nt = I(/* @__PURE__ */ new Set()), lt = I(/* @__PURE__ */ new Set()), pt = I(/* @__PURE__ */ new Map()), mt = I(!1), yt = I(null), [wr, an] = T(() => /* @__PURE__ */ new Set()), [Sr, cn] = T(() => /* @__PURE__ */ new Set()), V = I(null), [ln, me] = T(null), [N, Q] = T(() => /* @__PURE__ */ new Set()), rt = I(null), [X, un] = T(null), ot = I(null), [Dt, fn] = T(null), ye = I([]), [P, xt] = T(null), G = I(null), [st, xe] = T(null), [M, ut] = T({ x: 0, y: 0, zoom: 1 }), Y = Z / M.zoom, ft = I(null), W = I(/* @__PURE__ */ new Map()), it = I(null), { dragValue: gt, startDrag: dn } = ko({
|
|
641
|
+
compute: (n, a) => ({
|
|
642
|
+
width: Math.max(
|
|
643
|
+
Gt,
|
|
644
|
+
Math.round(a.startWidth + (n.clientX - a.startX))
|
|
645
|
+
),
|
|
646
|
+
height: Math.max(
|
|
647
|
+
$e,
|
|
648
|
+
Math.round(a.startHeight + (n.clientY - a.startY))
|
|
649
|
+
)
|
|
650
|
+
}),
|
|
651
|
+
onCommit: (n) => r.applyOperation(U(t, n))
|
|
652
|
+
}), hn = b((n) => {
|
|
653
|
+
ht.current == null && (ht.current = requestAnimationFrame(() => {
|
|
654
|
+
ht.current = null, sn(ee(At.current, { size: n }));
|
|
655
|
+
}));
|
|
656
|
+
}, []), bt = b(() => {
|
|
657
|
+
dt.current = !1, ht.current != null && (cancelAnimationFrame(ht.current), ht.current = null), At.current = [], sn(null);
|
|
658
|
+
}, []), pn = b(() => {
|
|
659
|
+
var h, d;
|
|
660
|
+
const n = At.current;
|
|
661
|
+
if (n.length === 0) return;
|
|
662
|
+
const a = ((h = e == null ? void 0 : e.props) == null ? void 0 : h.strokes) ?? [], c = ((d = e == null ? void 0 : e.props) == null ? void 0 : d.shapes) ?? [], l = {
|
|
663
|
+
id: Rt(),
|
|
664
|
+
points: n,
|
|
665
|
+
color: m,
|
|
666
|
+
size: S,
|
|
667
|
+
z: Vt(a, c)
|
|
668
|
+
};
|
|
669
|
+
r.applyOperation(U(t, { strokes: [...a, l] }));
|
|
670
|
+
}, [r, t, e, m, S]), mn = b(() => {
|
|
671
|
+
yt.current == null && (yt.current = requestAnimationFrame(() => {
|
|
672
|
+
yt.current = null, an(new Set(nt.current)), cn(new Set(lt.current));
|
|
673
|
+
}));
|
|
674
|
+
}, []), Bt = b(
|
|
675
|
+
(n, a) => {
|
|
676
|
+
var g, w;
|
|
677
|
+
const c = f === "precise" ? Ao : Co, l = Ho(n, a, c), h = ((g = e == null ? void 0 : e.props) == null ? void 0 : g.strokes) ?? [];
|
|
678
|
+
for (const y of h) {
|
|
679
|
+
if (f === "precise") {
|
|
680
|
+
const v = te(y.points);
|
|
681
|
+
if (!_t(v, l, y.size / 2)) continue;
|
|
682
|
+
let R = pt.current.get(y.id);
|
|
683
|
+
y.points.forEach(([F, L], C) => {
|
|
684
|
+
R != null && R.has(C) || Math.hypot(F - n, L - a) > c || (R || (R = /* @__PURE__ */ new Set(), pt.current.set(y.id, R)), R.add(C));
|
|
685
|
+
}), R != null && R.size && nt.current.add(y.id);
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
if (nt.current.has(y.id)) continue;
|
|
689
|
+
const k = y.size / 2, $ = te(y.points);
|
|
690
|
+
_t($, l, k) && Uo(y, n, a, c + k) && nt.current.add(y.id);
|
|
691
|
+
}
|
|
692
|
+
const d = ((w = e == null ? void 0 : e.props) == null ? void 0 : w.shapes) ?? [];
|
|
693
|
+
for (const y of d) {
|
|
694
|
+
if (lt.current.has(y.id)) continue;
|
|
695
|
+
const k = Ft(y), $ = {
|
|
696
|
+
minX: k.x,
|
|
697
|
+
minY: k.y,
|
|
698
|
+
maxX: k.x + k.width,
|
|
699
|
+
maxY: k.y + k.height
|
|
700
|
+
};
|
|
701
|
+
_t($, l) && lt.current.add(y.id);
|
|
702
|
+
}
|
|
703
|
+
mn();
|
|
704
|
+
},
|
|
705
|
+
[e, f, mn]
|
|
706
|
+
), wt = b(() => {
|
|
707
|
+
mt.current = !1, yt.current != null && (cancelAnimationFrame(yt.current), yt.current = null), nt.current = /* @__PURE__ */ new Set(), lt.current = /* @__PURE__ */ new Set(), pt.current = /* @__PURE__ */ new Map(), an(/* @__PURE__ */ new Set()), cn(/* @__PURE__ */ new Set());
|
|
708
|
+
}, []), yn = b(() => {
|
|
709
|
+
var d, g;
|
|
710
|
+
const n = f !== "precise" && nt.current.size > 0, a = f === "precise" && pt.current.size > 0;
|
|
711
|
+
if (!n && !a && lt.current.size === 0) return;
|
|
712
|
+
const c = ((d = e == null ? void 0 : e.props) == null ? void 0 : d.strokes) ?? [], l = ((g = e == null ? void 0 : e.props) == null ? void 0 : g.shapes) ?? [];
|
|
713
|
+
let h;
|
|
714
|
+
if (n)
|
|
715
|
+
h = c.filter((w) => !nt.current.has(w.id));
|
|
716
|
+
else if (a) {
|
|
717
|
+
h = [];
|
|
718
|
+
for (const w of c) {
|
|
719
|
+
const y = pt.current.get(w.id);
|
|
720
|
+
if (!y || y.size === 0) {
|
|
721
|
+
h.push(w);
|
|
722
|
+
continue;
|
|
723
|
+
}
|
|
724
|
+
Ko(w.points, y).forEach((k, $) => {
|
|
725
|
+
h.push({ ...w, id: $ === 0 ? w.id : Rt(), points: k });
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
} else
|
|
729
|
+
h = c;
|
|
730
|
+
r.applyOperation(
|
|
731
|
+
U(t, {
|
|
732
|
+
strokes: h,
|
|
733
|
+
shapes: l.filter((w) => !lt.current.has(w.id))
|
|
734
|
+
})
|
|
735
|
+
);
|
|
736
|
+
}, [r, t, e, f]), St = b(() => {
|
|
737
|
+
V.current = null, me(null);
|
|
738
|
+
}, []), xn = b(() => {
|
|
739
|
+
var h, d;
|
|
740
|
+
const n = V.current;
|
|
741
|
+
if (!n) return;
|
|
742
|
+
if (n.type === "arrow") {
|
|
743
|
+
if (n.x1 === n.x2 && n.y1 === n.y2) return;
|
|
744
|
+
} else {
|
|
745
|
+
const g = Lt(n.x1, n.y1, n.x2, n.y2);
|
|
746
|
+
if (g.width === 0 || g.height === 0) return;
|
|
747
|
+
}
|
|
748
|
+
const a = ((h = e == null ? void 0 : e.props) == null ? void 0 : h.strokes) ?? [], c = ((d = e == null ? void 0 : e.props) == null ? void 0 : d.shapes) ?? [], l = {
|
|
749
|
+
id: Rt(),
|
|
750
|
+
...Me(n, m, S, z),
|
|
751
|
+
z: Vt(a, c)
|
|
752
|
+
};
|
|
753
|
+
r.applyOperation(U(t, { shapes: [...c, l] }));
|
|
754
|
+
}, [r, t, e, m, S, z]), kt = b(() => {
|
|
755
|
+
rt.current = null, un(null);
|
|
756
|
+
}, []), gn = b(() => {
|
|
757
|
+
var g, w;
|
|
758
|
+
const n = rt.current;
|
|
759
|
+
if (!n || n.dx === 0 && n.dy === 0) return;
|
|
760
|
+
const a = new Set(n.ids), c = ((g = e == null ? void 0 : e.props) == null ? void 0 : g.strokes) ?? [], l = ((w = e == null ? void 0 : e.props) == null ? void 0 : w.shapes) ?? [], h = c.map(
|
|
761
|
+
(y) => a.has(y.id) ? Xt(y, n.dx, n.dy) : y
|
|
762
|
+
), d = l.map(
|
|
763
|
+
(y) => a.has(y.id) ? Ot(y, n.dx, n.dy) : y
|
|
764
|
+
);
|
|
765
|
+
r.applyOperation(U(t, { strokes: h, shapes: d }));
|
|
766
|
+
}, [r, t, e]), Et = b(() => {
|
|
767
|
+
ot.current = null, fn(null);
|
|
768
|
+
}, []), bn = b(() => {
|
|
769
|
+
var g, w;
|
|
770
|
+
const n = ot.current;
|
|
771
|
+
if (!n) return;
|
|
772
|
+
const a = Lt(n.startX, n.startY, n.x, n.y);
|
|
773
|
+
if (a.width < Tn && a.height < Tn) {
|
|
774
|
+
Q(/* @__PURE__ */ new Set());
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
const c = {
|
|
778
|
+
minX: a.x,
|
|
779
|
+
minY: a.y,
|
|
780
|
+
maxX: a.x + a.width,
|
|
781
|
+
maxY: a.y + a.height
|
|
782
|
+
}, l = ((g = e == null ? void 0 : e.props) == null ? void 0 : g.strokes) ?? [], h = ((w = e == null ? void 0 : e.props) == null ? void 0 : w.shapes) ?? [], d = [];
|
|
783
|
+
for (const y of l)
|
|
784
|
+
_t(te(y.points), c) && d.push(y.id);
|
|
785
|
+
for (const y of h) {
|
|
786
|
+
const k = Ft(y), $ = {
|
|
787
|
+
minX: k.x,
|
|
788
|
+
minY: k.y,
|
|
789
|
+
maxX: k.x + k.width,
|
|
790
|
+
maxY: k.y + k.height
|
|
791
|
+
};
|
|
792
|
+
_t($, c) && d.push(y.id);
|
|
793
|
+
}
|
|
794
|
+
Q(new Set(d));
|
|
795
|
+
}, [e]), ge = b(() => {
|
|
796
|
+
N.size !== 0 && (ye.current = [...N].map((n) => Dn(e, n)).filter(Boolean));
|
|
797
|
+
}, [e, N]), be = b(() => {
|
|
798
|
+
var w, y;
|
|
799
|
+
const n = ye.current;
|
|
800
|
+
if (n.length === 0) return;
|
|
801
|
+
const a = ((w = e == null ? void 0 : e.props) == null ? void 0 : w.strokes) ?? [], c = ((y = e == null ? void 0 : e.props) == null ? void 0 : y.shapes) ?? [];
|
|
802
|
+
let l = Vt(a, c);
|
|
803
|
+
const h = [], d = [], g = [];
|
|
804
|
+
for (const { kind: k, item: $ } of n) {
|
|
805
|
+
const v = Rt();
|
|
806
|
+
g.push(v);
|
|
807
|
+
const R = l;
|
|
808
|
+
l += 1, k === "stroke" ? h.push({ ...Xt($, qt, qt), id: v, z: R }) : d.push({ ...Ot($, qt, qt), id: v, z: R });
|
|
809
|
+
}
|
|
810
|
+
r.applyOperation(
|
|
811
|
+
U(t, {
|
|
812
|
+
strokes: [...a, ...h],
|
|
813
|
+
shapes: [...c, ...d]
|
|
814
|
+
})
|
|
815
|
+
), Q(new Set(g)), u("select");
|
|
816
|
+
}, [r, t, e]), It = b(
|
|
817
|
+
(n) => {
|
|
818
|
+
var k, $;
|
|
819
|
+
if (N.size === 0) return;
|
|
820
|
+
const a = ((k = e == null ? void 0 : e.props) == null ? void 0 : k.strokes) ?? [], c = (($ = e == null ? void 0 : e.props) == null ? void 0 : $.shapes) ?? [], l = a.filter((v) => N.has(v.id)), h = c.filter((v) => N.has(v.id)), d = se(l, h);
|
|
821
|
+
if (d.length === 0) return;
|
|
822
|
+
const g = n ? Vt(a, c) : To(a, c) - d.length, w = new Map(d.map(({ item: v }, R) => [v.id, g + R])), y = (v) => w.has(v.id) ? { ...v, z: w.get(v.id) } : v;
|
|
823
|
+
r.applyOperation(
|
|
824
|
+
U(t, {
|
|
825
|
+
strokes: a.map(y),
|
|
826
|
+
shapes: c.map(y)
|
|
827
|
+
})
|
|
828
|
+
);
|
|
829
|
+
},
|
|
830
|
+
[r, t, e, N]
|
|
831
|
+
), kr = b(() => It(!0), [It]), Er = b(() => It(!1), [It]), we = b(
|
|
832
|
+
(n, a) => {
|
|
833
|
+
xt({
|
|
834
|
+
id: null,
|
|
835
|
+
x: n,
|
|
836
|
+
y: a,
|
|
837
|
+
width: Oo,
|
|
838
|
+
height: Xo,
|
|
839
|
+
text: "",
|
|
840
|
+
color: m,
|
|
841
|
+
fontSize: et
|
|
842
|
+
});
|
|
843
|
+
},
|
|
844
|
+
[m, et]
|
|
845
|
+
), Ht = b((n) => {
|
|
846
|
+
xt({
|
|
847
|
+
id: n.id,
|
|
848
|
+
x: n.x,
|
|
849
|
+
y: n.y,
|
|
850
|
+
width: n.width,
|
|
851
|
+
height: n.height,
|
|
852
|
+
text: n.text,
|
|
853
|
+
color: n.color,
|
|
854
|
+
fontSize: n.fontSize ?? Re
|
|
855
|
+
});
|
|
856
|
+
}, []), Ir = b(() => {
|
|
857
|
+
xt(null);
|
|
858
|
+
}, []), zr = b(() => {
|
|
859
|
+
var g, w, y;
|
|
860
|
+
const n = P;
|
|
861
|
+
if (!n) return;
|
|
862
|
+
xt(null);
|
|
863
|
+
const a = ((g = e == null ? void 0 : e.props) == null ? void 0 : g.shapes) ?? [], c = n.text;
|
|
864
|
+
if (!c.trim()) {
|
|
865
|
+
n.id && (r.applyOperation(
|
|
866
|
+
U(t, { shapes: a.filter((k) => k.id !== n.id) })
|
|
867
|
+
), Q(/* @__PURE__ */ new Set())), (w = q.current) == null || w.focus();
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
const l = n.id ?? Rt(), h = {
|
|
871
|
+
id: l,
|
|
872
|
+
type: "text",
|
|
873
|
+
x: n.x,
|
|
874
|
+
y: n.y,
|
|
875
|
+
width: n.width,
|
|
876
|
+
height: n.height,
|
|
877
|
+
text: c,
|
|
878
|
+
color: n.color,
|
|
879
|
+
fontSize: n.fontSize
|
|
880
|
+
}, d = n.id ? a.map((k) => k.id === n.id ? h : k) : [...a, h];
|
|
881
|
+
r.applyOperation(U(t, { shapes: d })), Q(/* @__PURE__ */ new Set([l])), u("select"), (y = q.current) == null || y.focus();
|
|
882
|
+
}, [r, t, e, P]), zt = b(() => {
|
|
883
|
+
G.current = null, xe(null);
|
|
884
|
+
}, []), wn = b(() => {
|
|
885
|
+
var d;
|
|
886
|
+
const n = G.current;
|
|
887
|
+
if (!n) return;
|
|
888
|
+
const a = ((d = e == null ? void 0 : e.props) == null ? void 0 : d.shapes) ?? [], c = a.find((g) => g.id === n.shapeId);
|
|
889
|
+
if (!c) return;
|
|
890
|
+
const l = Pe(c, n);
|
|
891
|
+
if (l.type !== "arrow" && (l.width === 0 || l.height === 0)) return;
|
|
892
|
+
const h = a.map((g) => g.id === n.shapeId ? l : g);
|
|
893
|
+
r.applyOperation(U(t, { shapes: h }));
|
|
894
|
+
}, [r, t, e]), Sn = b(
|
|
895
|
+
(n) => {
|
|
896
|
+
var c;
|
|
897
|
+
const a = q.current;
|
|
898
|
+
if ((c = a == null ? void 0 : a.hasPointerCapture) != null && c.call(a, n) && a.releasePointerCapture(n), V.current) {
|
|
899
|
+
St();
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
if (rt.current) {
|
|
903
|
+
kt();
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
if (ot.current) {
|
|
907
|
+
Et();
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
if (G.current) {
|
|
911
|
+
zt();
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
if (dt.current) {
|
|
915
|
+
bt();
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
918
|
+
mt.current && wt();
|
|
919
|
+
},
|
|
920
|
+
[St, kt, Et, zt, bt, wt]
|
|
921
|
+
), $r = b(
|
|
922
|
+
(n) => {
|
|
923
|
+
var l, h, d, g, w;
|
|
924
|
+
if (n.key === "Backspace" || n.key === "Delete") {
|
|
925
|
+
if (N.size === 0) return;
|
|
926
|
+
n.preventDefault();
|
|
927
|
+
const y = ((l = e == null ? void 0 : e.props) == null ? void 0 : l.strokes) ?? [], k = ((h = e == null ? void 0 : e.props) == null ? void 0 : h.shapes) ?? [];
|
|
928
|
+
r.applyOperation(
|
|
929
|
+
U(t, {
|
|
930
|
+
strokes: y.filter(($) => !N.has($.id)),
|
|
931
|
+
shapes: k.filter(($) => !N.has($.id))
|
|
932
|
+
})
|
|
933
|
+
), Q(/* @__PURE__ */ new Set());
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
if (vn[n.key] && !n.ctrlKey && !n.metaKey) {
|
|
937
|
+
if (N.size === 0) return;
|
|
938
|
+
n.preventDefault();
|
|
939
|
+
const y = n.shiftKey ? _o : Do, [k, $] = vn[n.key], v = k * y, R = $ * y, F = ((d = e == null ? void 0 : e.props) == null ? void 0 : d.strokes) ?? [], L = ((g = e == null ? void 0 : e.props) == null ? void 0 : g.shapes) ?? [];
|
|
940
|
+
r.applyOperation(
|
|
941
|
+
U(t, {
|
|
942
|
+
strokes: F.map(
|
|
943
|
+
(C) => N.has(C.id) ? Xt(C, v, R) : C
|
|
944
|
+
),
|
|
945
|
+
shapes: L.map(
|
|
946
|
+
(C) => N.has(C.id) ? Ot(C, v, R) : C
|
|
947
|
+
)
|
|
948
|
+
})
|
|
949
|
+
);
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
if (n.key === "Enter" && !n.ctrlKey && !n.metaKey) {
|
|
953
|
+
if (N.size !== 1) return;
|
|
954
|
+
const [y] = N, k = (((w = e == null ? void 0 : e.props) == null ? void 0 : w.shapes) ?? []).find(($) => $.id === y && $.type === "text");
|
|
955
|
+
if (!k) return;
|
|
956
|
+
n.preventDefault(), Ht(k);
|
|
957
|
+
return;
|
|
958
|
+
}
|
|
959
|
+
if (!(n.ctrlKey || n.metaKey)) return;
|
|
960
|
+
const c = n.key.toLowerCase();
|
|
961
|
+
if (c === "c") {
|
|
962
|
+
if (N.size === 0) return;
|
|
963
|
+
n.preventDefault(), ge();
|
|
964
|
+
} else if (c === "v") {
|
|
965
|
+
if (ye.current.length === 0) return;
|
|
966
|
+
n.preventDefault(), be();
|
|
967
|
+
} else if (c === "d") {
|
|
968
|
+
if (N.size === 0) return;
|
|
969
|
+
n.preventDefault(), ge(), be();
|
|
970
|
+
} else if (n.shiftKey && (c === "]" || c === "[")) {
|
|
971
|
+
if (N.size === 0) return;
|
|
972
|
+
n.preventDefault(), It(c === "]");
|
|
973
|
+
}
|
|
974
|
+
},
|
|
975
|
+
[
|
|
976
|
+
r,
|
|
977
|
+
t,
|
|
978
|
+
e,
|
|
979
|
+
N,
|
|
980
|
+
ge,
|
|
981
|
+
be,
|
|
982
|
+
It,
|
|
983
|
+
Ht
|
|
984
|
+
]
|
|
985
|
+
), at = { x: M.x, y: M.y, size: Y }, Se = b(
|
|
986
|
+
(n) => {
|
|
987
|
+
const a = q.current;
|
|
988
|
+
if (!a) return;
|
|
989
|
+
if (n.preventDefault(), n.ctrlKey || n.metaKey) {
|
|
990
|
+
ut((l) => {
|
|
991
|
+
const h = n.deltaY < 0 ? Wt : 1 / Wt, d = Math.min(Te, Math.max(Ne, l.zoom * h)), g = Z / d, { x: w, y } = go(
|
|
992
|
+
n,
|
|
993
|
+
a,
|
|
994
|
+
{ x: l.x, y: l.y, size: Z / l.zoom },
|
|
995
|
+
g
|
|
996
|
+
);
|
|
997
|
+
return { ...Pt(w, y, g, Z), zoom: d };
|
|
998
|
+
});
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
const c = ze(a, Y);
|
|
1002
|
+
ut((l) => ({
|
|
1003
|
+
...l,
|
|
1004
|
+
...Pt(
|
|
1005
|
+
l.x + n.deltaX / c,
|
|
1006
|
+
l.y + n.deltaY / c,
|
|
1007
|
+
Y,
|
|
1008
|
+
Z
|
|
1009
|
+
)
|
|
1010
|
+
}));
|
|
1011
|
+
},
|
|
1012
|
+
[Y]
|
|
1013
|
+
);
|
|
1014
|
+
Yn(() => {
|
|
1015
|
+
const n = q.current;
|
|
1016
|
+
if (n)
|
|
1017
|
+
return n.addEventListener("wheel", Se, { passive: !1 }), () => n.removeEventListener("wheel", Se);
|
|
1018
|
+
}, [Se]);
|
|
1019
|
+
const Nr = b(() => {
|
|
1020
|
+
ut((n) => {
|
|
1021
|
+
const a = Math.min(Te, n.zoom * Wt), c = Z / a, { x: l, y: h } = zn(
|
|
1022
|
+
{ x: n.x, y: n.y, size: Z / n.zoom },
|
|
1023
|
+
c
|
|
1024
|
+
);
|
|
1025
|
+
return { ...Pt(l, h, c, Z), zoom: a };
|
|
1026
|
+
});
|
|
1027
|
+
}, []), Tr = b(() => {
|
|
1028
|
+
ut((n) => {
|
|
1029
|
+
const a = Math.max(Ne, n.zoom / Wt), c = Z / a, { x: l, y: h } = zn(
|
|
1030
|
+
{ x: n.x, y: n.y, size: Z / n.zoom },
|
|
1031
|
+
c
|
|
1032
|
+
);
|
|
1033
|
+
return { ...Pt(l, h, c, Z), zoom: a };
|
|
1034
|
+
});
|
|
1035
|
+
}, []), vr = b(() => {
|
|
1036
|
+
ut({ x: 0, y: 0, zoom: 1 });
|
|
1037
|
+
}, []), Mr = b(() => {
|
|
1038
|
+
if (!e) return;
|
|
1039
|
+
const n = tr(e), a = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`, c = new Image();
|
|
1040
|
+
c.onload = () => {
|
|
1041
|
+
const l = document.createElement("canvas");
|
|
1042
|
+
l.width = e.props.width, l.height = e.props.height;
|
|
1043
|
+
const h = l.getContext("2d");
|
|
1044
|
+
if (!h) return;
|
|
1045
|
+
h.drawImage(c, 0, 0, l.width, l.height);
|
|
1046
|
+
const d = document.createElement("a");
|
|
1047
|
+
d.href = l.toDataURL("image/png"), d.download = "canvas.png", document.body.appendChild(d), d.click(), document.body.removeChild(d);
|
|
1048
|
+
}, c.src = a;
|
|
1049
|
+
}, [e]), Pr = b(
|
|
1050
|
+
(n) => {
|
|
1051
|
+
var w;
|
|
1052
|
+
if (i !== "select") return;
|
|
1053
|
+
const a = q.current;
|
|
1054
|
+
if (!a) return;
|
|
1055
|
+
const [c, l] = J(n, a, { x: M.x, y: M.y, size: Y }), h = ((w = e == null ? void 0 : e.props) == null ? void 0 : w.shapes) ?? [], d = jo(c, l, h), g = h.find((y) => y.id === d);
|
|
1056
|
+
(g == null ? void 0 : g.type) === "text" && (Q(/* @__PURE__ */ new Set([g.id])), Ht(g));
|
|
1057
|
+
},
|
|
1058
|
+
[i, M.x, M.y, Y, e, Ht]
|
|
1059
|
+
), Rr = b(
|
|
1060
|
+
(n) => {
|
|
1061
|
+
var h, d, g, w, y, k, $, v, R;
|
|
1062
|
+
const a = q.current;
|
|
1063
|
+
if (!a) return;
|
|
1064
|
+
if (n.pointerType === "touch" && (W.current.set(n.pointerId, { x: n.clientX, y: n.clientY }), W.current.size >= 2)) {
|
|
1065
|
+
if (n.preventDefault(), (h = a.setPointerCapture) == null || h.call(a, n.pointerId), !it.current) {
|
|
1066
|
+
for (const L of W.current.keys())
|
|
1067
|
+
L !== n.pointerId && Sn(L);
|
|
1068
|
+
const F = Rn(W.current);
|
|
1069
|
+
it.current = {
|
|
1070
|
+
startCenterX: F.x,
|
|
1071
|
+
startCenterY: F.y,
|
|
1072
|
+
startViewX: M.x,
|
|
1073
|
+
startViewY: M.y
|
|
1074
|
+
};
|
|
1075
|
+
}
|
|
1076
|
+
return;
|
|
1077
|
+
}
|
|
1078
|
+
if (P) {
|
|
1079
|
+
if ((g = (d = n.target) == null ? void 0 : d.closest) != null && g.call(d, ".be-canvas-text-editor")) return;
|
|
1080
|
+
if ((y = (w = document.activeElement) == null ? void 0 : w.blur) == null || y.call(w), i === "text") {
|
|
1081
|
+
let [F, L] = J(n, a, at);
|
|
1082
|
+
A && ([F, L] = [K(F), K(L)]), we(F, L), u("text");
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
if (n.button === 1) {
|
|
1087
|
+
n.preventDefault(), (k = a.setPointerCapture) == null || k.call(a, n.pointerId), ft.current = {
|
|
1088
|
+
startClientX: n.clientX,
|
|
1089
|
+
startClientY: n.clientY,
|
|
1090
|
+
startViewX: M.x,
|
|
1091
|
+
startViewY: M.y
|
|
1092
|
+
};
|
|
1093
|
+
return;
|
|
1094
|
+
}
|
|
1095
|
+
if (!n.isPrimary || n.button !== void 0 && n.button !== 0) return;
|
|
1096
|
+
n.preventDefault(), ($ = a.setPointerCapture) == null || $.call(a, n.pointerId);
|
|
1097
|
+
const [c, l] = J(n, a, at);
|
|
1098
|
+
if (i === "eraser")
|
|
1099
|
+
nt.current = /* @__PURE__ */ new Set(), lt.current = /* @__PURE__ */ new Set(), pt.current = /* @__PURE__ */ new Map(), mt.current = !0, Bt(c, l);
|
|
1100
|
+
else if (ve.has(i)) {
|
|
1101
|
+
const F = A ? K(c) : c, L = A ? K(l) : l;
|
|
1102
|
+
V.current = { type: i, x1: F, y1: L, x2: F, y2: L }, me(Me(V.current, m, S, z));
|
|
1103
|
+
} else if (i === "select") {
|
|
1104
|
+
const F = ((v = e == null ? void 0 : e.props) == null ? void 0 : v.strokes) ?? [], L = ((R = e == null ? void 0 : e.props) == null ? void 0 : R.shapes) ?? [], C = N.size === 1 ? L.find((tt) => N.has(tt.id)) ?? null : null, jt = Jo(c, l, C);
|
|
1105
|
+
if (jt) {
|
|
1106
|
+
if (jt === "rotate") {
|
|
1107
|
+
const { cx: tt, cy: Nt } = ie(C), Tt = Math.atan2(l - Nt, c - tt) * 180 / Math.PI;
|
|
1108
|
+
G.current = {
|
|
1109
|
+
mode: "rotate",
|
|
1110
|
+
shapeId: C.id,
|
|
1111
|
+
cx: tt,
|
|
1112
|
+
cy: Nt,
|
|
1113
|
+
startAngle: Tt,
|
|
1114
|
+
startRotation: C.rotation ?? 0,
|
|
1115
|
+
rotation: C.rotation ?? 0
|
|
1116
|
+
};
|
|
1117
|
+
} else if (C.type === "arrow")
|
|
1118
|
+
G.current = {
|
|
1119
|
+
mode: "arrow-endpoint",
|
|
1120
|
+
shapeId: C.id,
|
|
1121
|
+
endpoint: jt,
|
|
1122
|
+
x: c,
|
|
1123
|
+
y: l
|
|
1124
|
+
};
|
|
1125
|
+
else {
|
|
1126
|
+
const [tt, Nt] = Ae(C)[Wo[jt]];
|
|
1127
|
+
G.current = {
|
|
1128
|
+
mode: "rect-corner",
|
|
1129
|
+
shapeId: C.id,
|
|
1130
|
+
fixedX: tt,
|
|
1131
|
+
fixedY: Nt,
|
|
1132
|
+
x: c,
|
|
1133
|
+
y: l
|
|
1134
|
+
};
|
|
1135
|
+
}
|
|
1136
|
+
xe(Pe(C, G.current));
|
|
1137
|
+
return;
|
|
1138
|
+
}
|
|
1139
|
+
const $t = Go(c, l, F, L);
|
|
1140
|
+
if ($t) {
|
|
1141
|
+
if (n.shiftKey) {
|
|
1142
|
+
Q((Nt) => {
|
|
1143
|
+
const Tt = new Set(Nt);
|
|
1144
|
+
return Tt.has($t.id) ? Tt.delete($t.id) : Tt.add($t.id), Tt;
|
|
1145
|
+
});
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
const tt = N.has($t.id) ? N : /* @__PURE__ */ new Set([$t.id]);
|
|
1149
|
+
Q(tt), rt.current = { ids: [...tt], startX: c, startY: l, dx: 0, dy: 0 }, a.focus();
|
|
1150
|
+
} else
|
|
1151
|
+
ot.current = { startX: c, startY: l, x: c, y: l };
|
|
1152
|
+
} else i === "text" ? we(A ? K(c) : c, A ? K(l) : l) : i === "pen" && (At.current = [[c, l, n.pressure || 0.5]], dt.current = !0);
|
|
1153
|
+
},
|
|
1154
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1155
|
+
[
|
|
1156
|
+
i,
|
|
1157
|
+
Bt,
|
|
1158
|
+
M.x,
|
|
1159
|
+
M.y,
|
|
1160
|
+
Y,
|
|
1161
|
+
m,
|
|
1162
|
+
S,
|
|
1163
|
+
z,
|
|
1164
|
+
A,
|
|
1165
|
+
e,
|
|
1166
|
+
N,
|
|
1167
|
+
we,
|
|
1168
|
+
P,
|
|
1169
|
+
Sn
|
|
1170
|
+
]
|
|
1171
|
+
), Cr = b(
|
|
1172
|
+
(n) => {
|
|
1173
|
+
var c;
|
|
1174
|
+
const a = q.current;
|
|
1175
|
+
if (a) {
|
|
1176
|
+
if (n.pointerType === "touch" && W.current.has(n.pointerId) && (W.current.set(n.pointerId, { x: n.clientX, y: n.clientY }), it.current)) {
|
|
1177
|
+
n.preventDefault();
|
|
1178
|
+
const l = ze(a, Y), h = Rn(W.current), { startCenterX: d, startCenterY: g, startViewX: w, startViewY: y } = it.current, k = (h.x - d) / l, $ = (h.y - g) / l;
|
|
1179
|
+
ut((v) => ({
|
|
1180
|
+
...v,
|
|
1181
|
+
...Pt(w - k, y - $, Y, Z)
|
|
1182
|
+
}));
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1185
|
+
if (ft.current) {
|
|
1186
|
+
const l = ze(a, Y), { startClientX: h, startClientY: d, startViewX: g, startViewY: w } = ft.current, y = (n.clientX - h) / l, k = (n.clientY - d) / l;
|
|
1187
|
+
ut(($) => ({
|
|
1188
|
+
...$,
|
|
1189
|
+
...Pt(g - y, w - k, Y, Z)
|
|
1190
|
+
}));
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
if (V.current) {
|
|
1194
|
+
let [l, h] = J(n, a, at);
|
|
1195
|
+
A && ([l, h] = [K(l), K(h)]), V.current = { ...V.current, x2: l, y2: h }, me(Me(V.current, m, S, z));
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
1198
|
+
if (rt.current) {
|
|
1199
|
+
const [l, h] = J(n, a, at), d = rt.current;
|
|
1200
|
+
d.dx = A ? K(l - d.startX) : l - d.startX, d.dy = A ? K(h - d.startY) : h - d.startY, un({ ids: d.ids, dx: d.dx, dy: d.dy });
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
if (ot.current) {
|
|
1204
|
+
const [l, h] = J(n, a, at), d = ot.current;
|
|
1205
|
+
d.x = l, d.y = h, fn(Lt(d.startX, d.startY, d.x, d.y));
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
if (G.current) {
|
|
1209
|
+
let [l, h] = J(n, a, at);
|
|
1210
|
+
const d = G.current;
|
|
1211
|
+
if (d.mode === "rotate") {
|
|
1212
|
+
const y = Math.atan2(h - d.cy, l - d.cx) * 180 / Math.PI, k = d.startRotation + (y - d.startAngle);
|
|
1213
|
+
d.rotation = A ? Fo(k) : k;
|
|
1214
|
+
} else
|
|
1215
|
+
A && ([l, h] = [K(l), K(h)]), d.x = l, d.y = h;
|
|
1216
|
+
const w = (((c = e == null ? void 0 : e.props) == null ? void 0 : c.shapes) ?? []).find((y) => y.id === d.shapeId);
|
|
1217
|
+
w && xe(Pe(w, d));
|
|
1218
|
+
return;
|
|
1219
|
+
}
|
|
1220
|
+
if (dt.current) {
|
|
1221
|
+
const [l, h] = J(n, a, at);
|
|
1222
|
+
At.current.push([l, h, n.pressure || 0.5]), hn(S);
|
|
1223
|
+
} else if (mt.current) {
|
|
1224
|
+
const [l, h] = J(n, a, at);
|
|
1225
|
+
Bt(l, h);
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
},
|
|
1229
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1230
|
+
[
|
|
1231
|
+
hn,
|
|
1232
|
+
Bt,
|
|
1233
|
+
M.x,
|
|
1234
|
+
M.y,
|
|
1235
|
+
Y,
|
|
1236
|
+
S,
|
|
1237
|
+
m,
|
|
1238
|
+
z,
|
|
1239
|
+
A,
|
|
1240
|
+
e
|
|
1241
|
+
]
|
|
1242
|
+
), D = b((n) => {
|
|
1243
|
+
var c;
|
|
1244
|
+
const a = q.current;
|
|
1245
|
+
(c = a == null ? void 0 : a.hasPointerCapture) != null && c.call(a, n.pointerId) && a.releasePointerCapture(n.pointerId);
|
|
1246
|
+
}, []), Ar = b(
|
|
1247
|
+
(n) => {
|
|
1248
|
+
if (n.pointerType === "touch" && (W.current.delete(n.pointerId), it.current)) {
|
|
1249
|
+
D(n), W.current.size < 2 && (it.current = null);
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
if (ft.current) {
|
|
1253
|
+
D(n), ft.current = null;
|
|
1254
|
+
return;
|
|
1255
|
+
}
|
|
1256
|
+
if (V.current) {
|
|
1257
|
+
D(n), xn(), St();
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
if (rt.current) {
|
|
1261
|
+
D(n), gn(), kt();
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1264
|
+
if (ot.current) {
|
|
1265
|
+
D(n), bn(), Et();
|
|
1266
|
+
return;
|
|
1267
|
+
}
|
|
1268
|
+
if (G.current) {
|
|
1269
|
+
D(n), wn(), zt();
|
|
1270
|
+
return;
|
|
1271
|
+
}
|
|
1272
|
+
dt.current ? (D(n), pn(), bt()) : mt.current && (D(n), yn(), wt());
|
|
1273
|
+
},
|
|
1274
|
+
[
|
|
1275
|
+
D,
|
|
1276
|
+
xn,
|
|
1277
|
+
St,
|
|
1278
|
+
gn,
|
|
1279
|
+
kt,
|
|
1280
|
+
bn,
|
|
1281
|
+
Et,
|
|
1282
|
+
wn,
|
|
1283
|
+
zt,
|
|
1284
|
+
pn,
|
|
1285
|
+
bt,
|
|
1286
|
+
yn,
|
|
1287
|
+
wt
|
|
1288
|
+
]
|
|
1289
|
+
), Dr = b(
|
|
1290
|
+
(n) => {
|
|
1291
|
+
if (n.pointerType === "touch" && (W.current.delete(n.pointerId), it.current)) {
|
|
1292
|
+
D(n), W.current.size < 2 && (it.current = null);
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
if (ft.current) {
|
|
1296
|
+
D(n), ft.current = null;
|
|
1297
|
+
return;
|
|
1298
|
+
}
|
|
1299
|
+
if (V.current) {
|
|
1300
|
+
D(n), St();
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
if (rt.current) {
|
|
1304
|
+
D(n), kt();
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
if (ot.current) {
|
|
1308
|
+
D(n), Et();
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
if (G.current) {
|
|
1312
|
+
D(n), zt();
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
dt.current ? (D(n), bt()) : mt.current && (D(n), wt());
|
|
1316
|
+
},
|
|
1317
|
+
[D, St, kt, Et, zt, bt, wt]
|
|
1318
|
+
), _r = b(
|
|
1319
|
+
(n) => {
|
|
1320
|
+
var a, c;
|
|
1321
|
+
dn(n, {
|
|
1322
|
+
startX: n.clientX,
|
|
1323
|
+
startY: n.clientY,
|
|
1324
|
+
startWidth: ((a = e == null ? void 0 : e.props) == null ? void 0 : a.width) ?? ne,
|
|
1325
|
+
startHeight: ((c = e == null ? void 0 : e.props) == null ? void 0 : c.height) ?? re
|
|
1326
|
+
});
|
|
1327
|
+
},
|
|
1328
|
+
[dn, e]
|
|
1329
|
+
), Or = b(
|
|
1330
|
+
(n) => {
|
|
1331
|
+
var d, g;
|
|
1332
|
+
const a = ((d = e == null ? void 0 : e.props) == null ? void 0 : d.width) ?? ne, c = ((g = e == null ? void 0 : e.props) == null ? void 0 : g.height) ?? re, l = n.shiftKey ? 4 : 24;
|
|
1333
|
+
let h;
|
|
1334
|
+
if (n.key === "ArrowLeft")
|
|
1335
|
+
h = { width: Math.max(Gt, a - l) };
|
|
1336
|
+
else if (n.key === "ArrowRight") h = { width: a + l };
|
|
1337
|
+
else if (n.key === "ArrowUp")
|
|
1338
|
+
h = { height: Math.max($e, c - l) };
|
|
1339
|
+
else if (n.key === "ArrowDown") h = { height: c + l };
|
|
1340
|
+
else if (n.key === "Home") h = { width: Gt, height: $e };
|
|
1341
|
+
else return;
|
|
1342
|
+
n.preventDefault(), r.applyOperation(U(t, h));
|
|
1343
|
+
},
|
|
1344
|
+
[r, t, e]
|
|
1345
|
+
);
|
|
1346
|
+
if (!e) return null;
|
|
1347
|
+
const { strokes: kn = [], shapes: En = [], width: Xr, height: Yr } = e.props, In = (gt == null ? void 0 : gt.width) ?? Xr, Lr = (gt == null ? void 0 : gt.height) ?? Yr, Ut = 6, Zt = [...N].map((n) => {
|
|
1348
|
+
var h;
|
|
1349
|
+
const a = Dn(e, n);
|
|
1350
|
+
if (!a) return null;
|
|
1351
|
+
let { kind: c, item: l } = a;
|
|
1352
|
+
return (h = X == null ? void 0 : X.ids) != null && h.includes(n) ? l = c === "stroke" ? Xt(l, X.dx, X.dy) : Ot(l, X.dx, X.dy) : c === "shape" && (st == null ? void 0 : st.id) === n && (l = st), {
|
|
1353
|
+
id: n,
|
|
1354
|
+
kind: c,
|
|
1355
|
+
item: l,
|
|
1356
|
+
box: Vo(c, l),
|
|
1357
|
+
rotation: c === "shape" ? l.rotation : 0
|
|
1358
|
+
};
|
|
1359
|
+
}).filter(Boolean), ke = Zt.length === 1 && Zt[0].kind === "shape" ? Zt[0] : null, j = (ke == null ? void 0 : ke.item) ?? null, Fr = j && j.type === "arrow" ? [
|
|
1360
|
+
["start", j.x1, j.y1],
|
|
1361
|
+
["end", j.x2, j.y2]
|
|
1362
|
+
] : j && !j.rotation ? Object.entries(Ae(j)).map(([n, [a, c]]) => [
|
|
1363
|
+
n,
|
|
1364
|
+
a,
|
|
1365
|
+
c
|
|
1366
|
+
]) : [], Ee = j && j.type !== "arrow" ? sr(j) : null;
|
|
1367
|
+
return /* @__PURE__ */ _(
|
|
1368
|
+
"div",
|
|
1369
|
+
{
|
|
1370
|
+
className: o,
|
|
1371
|
+
"data-block-id": t,
|
|
1372
|
+
"data-tool": i,
|
|
1373
|
+
contentEditable: !1,
|
|
1374
|
+
tabIndex: -1,
|
|
1375
|
+
children: [
|
|
1376
|
+
/* @__PURE__ */ _("div", { className: "be-canvas-toolbar", contentEditable: !1, children: [
|
|
1377
|
+
/* @__PURE__ */ p(
|
|
1378
|
+
"button",
|
|
1379
|
+
{
|
|
1380
|
+
type: "button",
|
|
1381
|
+
className: `be-canvas-toolbar-btn${i === "pen" ? " be-canvas-toolbar-btn-active" : ""}`,
|
|
1382
|
+
"aria-pressed": i === "pen",
|
|
1383
|
+
"aria-label": "Pen",
|
|
1384
|
+
title: "Pen",
|
|
1385
|
+
onClick: () => u("pen"),
|
|
1386
|
+
children: /* @__PURE__ */ p(Ur, { size: 14 })
|
|
1387
|
+
}
|
|
1388
|
+
),
|
|
1389
|
+
/* @__PURE__ */ _("div", { className: "be-canvas-picker-wrap", children: [
|
|
1390
|
+
/* @__PURE__ */ p(
|
|
1391
|
+
"button",
|
|
1392
|
+
{
|
|
1393
|
+
ref: Qe,
|
|
1394
|
+
type: "button",
|
|
1395
|
+
className: `be-canvas-toolbar-btn${i === "eraser" ? " be-canvas-toolbar-btn-active" : ""}`,
|
|
1396
|
+
"aria-haspopup": "true",
|
|
1397
|
+
"aria-expanded": he,
|
|
1398
|
+
"aria-pressed": i === "eraser",
|
|
1399
|
+
"aria-label": "Eraser",
|
|
1400
|
+
title: "Eraser",
|
|
1401
|
+
onClick: () => Be((n) => !n),
|
|
1402
|
+
children: (() => {
|
|
1403
|
+
var a;
|
|
1404
|
+
const n = ((a = An.find((c) => c.mode === f)) == null ? void 0 : a.Icon) ?? Ln;
|
|
1405
|
+
return /* @__PURE__ */ p(n, { size: 14 });
|
|
1406
|
+
})()
|
|
1407
|
+
}
|
|
1408
|
+
),
|
|
1409
|
+
he && /* @__PURE__ */ p(
|
|
1410
|
+
"div",
|
|
1411
|
+
{
|
|
1412
|
+
ref: tn,
|
|
1413
|
+
className: "be-canvas-picker be-canvas-shape-picker",
|
|
1414
|
+
role: "menu",
|
|
1415
|
+
"aria-label": "Eraser",
|
|
1416
|
+
children: An.map(({ mode: n, label: a, Icon: c }) => /* @__PURE__ */ p(
|
|
1417
|
+
"button",
|
|
1418
|
+
{
|
|
1419
|
+
type: "button",
|
|
1420
|
+
role: "menuitem",
|
|
1421
|
+
className: `be-canvas-toolbar-btn${i === "eraser" && f === n ? " be-canvas-toolbar-btn-active" : ""}`,
|
|
1422
|
+
"aria-pressed": i === "eraser" && f === n,
|
|
1423
|
+
"aria-label": a,
|
|
1424
|
+
title: a,
|
|
1425
|
+
onClick: () => {
|
|
1426
|
+
u("eraser"), x(n), rn();
|
|
1427
|
+
},
|
|
1428
|
+
children: /* @__PURE__ */ p(c, { size: 14 })
|
|
1429
|
+
},
|
|
1430
|
+
n
|
|
1431
|
+
))
|
|
1432
|
+
}
|
|
1433
|
+
)
|
|
1434
|
+
] }),
|
|
1435
|
+
/* @__PURE__ */ p(
|
|
1436
|
+
"button",
|
|
1437
|
+
{
|
|
1438
|
+
type: "button",
|
|
1439
|
+
className: `be-canvas-toolbar-btn${i === "select" ? " be-canvas-toolbar-btn-active" : ""}`,
|
|
1440
|
+
"aria-pressed": i === "select",
|
|
1441
|
+
"aria-label": "Select",
|
|
1442
|
+
title: "Select",
|
|
1443
|
+
onClick: () => u("select"),
|
|
1444
|
+
children: /* @__PURE__ */ p(jr, { size: 14 })
|
|
1445
|
+
}
|
|
1446
|
+
),
|
|
1447
|
+
/* @__PURE__ */ p(
|
|
1448
|
+
"button",
|
|
1449
|
+
{
|
|
1450
|
+
type: "button",
|
|
1451
|
+
className: `be-canvas-toolbar-btn${i === "text" ? " be-canvas-toolbar-btn-active" : ""}`,
|
|
1452
|
+
"aria-pressed": i === "text",
|
|
1453
|
+
"aria-label": "Text",
|
|
1454
|
+
title: "Text",
|
|
1455
|
+
onClick: () => u("text"),
|
|
1456
|
+
children: /* @__PURE__ */ p(Kr, { size: 14 })
|
|
1457
|
+
}
|
|
1458
|
+
),
|
|
1459
|
+
/* @__PURE__ */ _("div", { className: "be-canvas-picker-wrap", children: [
|
|
1460
|
+
/* @__PURE__ */ p(
|
|
1461
|
+
"button",
|
|
1462
|
+
{
|
|
1463
|
+
ref: qe,
|
|
1464
|
+
type: "button",
|
|
1465
|
+
className: "be-canvas-toolbar-btn",
|
|
1466
|
+
"aria-haspopup": "true",
|
|
1467
|
+
"aria-expanded": de,
|
|
1468
|
+
"aria-label": `Font size: ${P ? P.fontSize : et}`,
|
|
1469
|
+
title: "Font size",
|
|
1470
|
+
onClick: () => Fe((n) => !n),
|
|
1471
|
+
children: /* @__PURE__ */ p("span", { className: "be-canvas-font-size-trigger", children: "A" })
|
|
1472
|
+
}
|
|
1473
|
+
),
|
|
1474
|
+
de && /* @__PURE__ */ _(
|
|
1475
|
+
"div",
|
|
1476
|
+
{
|
|
1477
|
+
ref: Je,
|
|
1478
|
+
className: "be-canvas-picker be-canvas-size-picker",
|
|
1479
|
+
role: "dialog",
|
|
1480
|
+
"aria-label": "Font size",
|
|
1481
|
+
children: [
|
|
1482
|
+
/* @__PURE__ */ p("span", { className: "be-canvas-size-preview", "aria-hidden": "true", children: /* @__PURE__ */ p(
|
|
1483
|
+
"span",
|
|
1484
|
+
{
|
|
1485
|
+
className: "be-canvas-font-size-preview-letter",
|
|
1486
|
+
style: { fontSize: P ? P.fontSize : et },
|
|
1487
|
+
children: "A"
|
|
1488
|
+
}
|
|
1489
|
+
) }),
|
|
1490
|
+
/* @__PURE__ */ p(
|
|
1491
|
+
"input",
|
|
1492
|
+
{
|
|
1493
|
+
type: "range",
|
|
1494
|
+
className: "be-canvas-size-slider",
|
|
1495
|
+
min: Yo,
|
|
1496
|
+
max: Lo,
|
|
1497
|
+
value: P ? P.fontSize : et,
|
|
1498
|
+
onChange: (n) => {
|
|
1499
|
+
const a = Number(n.target.value);
|
|
1500
|
+
lr(a), P && xt((c) => c && { ...c, fontSize: a });
|
|
1501
|
+
},
|
|
1502
|
+
"aria-label": "Font size"
|
|
1503
|
+
}
|
|
1504
|
+
),
|
|
1505
|
+
/* @__PURE__ */ _("span", { className: "be-canvas-size-value", children: [
|
|
1506
|
+
P ? P.fontSize : et,
|
|
1507
|
+
"px"
|
|
1508
|
+
] })
|
|
1509
|
+
]
|
|
1510
|
+
}
|
|
1511
|
+
)
|
|
1512
|
+
] }),
|
|
1513
|
+
/* @__PURE__ */ p(
|
|
1514
|
+
"button",
|
|
1515
|
+
{
|
|
1516
|
+
type: "button",
|
|
1517
|
+
className: "be-canvas-toolbar-btn",
|
|
1518
|
+
"aria-label": "Bring to front",
|
|
1519
|
+
title: "Bring to front",
|
|
1520
|
+
onClick: kr,
|
|
1521
|
+
disabled: N.size === 0,
|
|
1522
|
+
children: /* @__PURE__ */ p(Vr, { size: 14 })
|
|
1523
|
+
}
|
|
1524
|
+
),
|
|
1525
|
+
/* @__PURE__ */ p(
|
|
1526
|
+
"button",
|
|
1527
|
+
{
|
|
1528
|
+
type: "button",
|
|
1529
|
+
className: "be-canvas-toolbar-btn",
|
|
1530
|
+
"aria-label": "Send to back",
|
|
1531
|
+
title: "Send to back",
|
|
1532
|
+
onClick: Er,
|
|
1533
|
+
disabled: N.size === 0,
|
|
1534
|
+
children: /* @__PURE__ */ p(Gr, { size: 14 })
|
|
1535
|
+
}
|
|
1536
|
+
),
|
|
1537
|
+
/* @__PURE__ */ p("span", { className: "be-canvas-toolbar-divider" }),
|
|
1538
|
+
/* @__PURE__ */ _("div", { className: "be-canvas-picker-wrap", children: [
|
|
1539
|
+
/* @__PURE__ */ p(
|
|
1540
|
+
"button",
|
|
1541
|
+
{
|
|
1542
|
+
ref: Ge,
|
|
1543
|
+
type: "button",
|
|
1544
|
+
className: `be-canvas-toolbar-btn${ve.has(i) ? " be-canvas-toolbar-btn-active" : ""}`,
|
|
1545
|
+
"aria-haspopup": "true",
|
|
1546
|
+
"aria-expanded": fe,
|
|
1547
|
+
"aria-label": "Shape",
|
|
1548
|
+
title: "Shape",
|
|
1549
|
+
onClick: () => Le((n) => !n),
|
|
1550
|
+
children: (() => {
|
|
1551
|
+
var a;
|
|
1552
|
+
const n = ((a = Cn.find(
|
|
1553
|
+
(c) => c.type === (ve.has(i) ? i : ur)
|
|
1554
|
+
)) == null ? void 0 : a.Icon) ?? Fn;
|
|
1555
|
+
return /* @__PURE__ */ p(n, { size: 14 });
|
|
1556
|
+
})()
|
|
1557
|
+
}
|
|
1558
|
+
),
|
|
1559
|
+
fe && /* @__PURE__ */ p(
|
|
1560
|
+
"div",
|
|
1561
|
+
{
|
|
1562
|
+
ref: We,
|
|
1563
|
+
className: "be-canvas-picker be-canvas-shape-picker",
|
|
1564
|
+
role: "menu",
|
|
1565
|
+
"aria-label": "Shape",
|
|
1566
|
+
children: Cn.map(({ type: n, label: a, Icon: c }) => /* @__PURE__ */ p(
|
|
1567
|
+
"button",
|
|
1568
|
+
{
|
|
1569
|
+
type: "button",
|
|
1570
|
+
role: "menuitem",
|
|
1571
|
+
className: `be-canvas-toolbar-btn${i === n ? " be-canvas-toolbar-btn-active" : ""}`,
|
|
1572
|
+
"aria-pressed": i === n,
|
|
1573
|
+
"aria-label": a,
|
|
1574
|
+
title: a,
|
|
1575
|
+
onClick: () => {
|
|
1576
|
+
u(n), fr(n), nn();
|
|
1577
|
+
},
|
|
1578
|
+
children: /* @__PURE__ */ p(c, { size: 14 })
|
|
1579
|
+
},
|
|
1580
|
+
n
|
|
1581
|
+
))
|
|
1582
|
+
}
|
|
1583
|
+
)
|
|
1584
|
+
] }),
|
|
1585
|
+
/* @__PURE__ */ p("span", { className: "be-canvas-toolbar-divider" }),
|
|
1586
|
+
/* @__PURE__ */ _("div", { className: "be-canvas-picker-wrap", children: [
|
|
1587
|
+
/* @__PURE__ */ p(
|
|
1588
|
+
"button",
|
|
1589
|
+
{
|
|
1590
|
+
ref: He,
|
|
1591
|
+
type: "button",
|
|
1592
|
+
className: "be-canvas-toolbar-btn",
|
|
1593
|
+
"aria-haspopup": "true",
|
|
1594
|
+
"aria-expanded": ce,
|
|
1595
|
+
"aria-label": `Color: ${m}`,
|
|
1596
|
+
title: "Color",
|
|
1597
|
+
onClick: () => Oe((n) => !n),
|
|
1598
|
+
children: /* @__PURE__ */ p("span", { className: "be-canvas-color-trigger-dot", style: { backgroundColor: m } })
|
|
1599
|
+
}
|
|
1600
|
+
),
|
|
1601
|
+
ce && /* @__PURE__ */ _(
|
|
1602
|
+
"div",
|
|
1603
|
+
{
|
|
1604
|
+
ref: Ue,
|
|
1605
|
+
className: "be-canvas-picker be-canvas-color-picker",
|
|
1606
|
+
role: "menu",
|
|
1607
|
+
"aria-label": "Pen color",
|
|
1608
|
+
children: [
|
|
1609
|
+
Nn.map((n) => /* @__PURE__ */ p(
|
|
1610
|
+
"button",
|
|
1611
|
+
{
|
|
1612
|
+
type: "button",
|
|
1613
|
+
role: "menuitem",
|
|
1614
|
+
className: `be-canvas-toolbar-swatch${m === n ? " be-canvas-toolbar-swatch-active" : ""}`,
|
|
1615
|
+
style: { backgroundColor: n },
|
|
1616
|
+
"aria-pressed": m === n,
|
|
1617
|
+
"aria-label": `Color ${n}`,
|
|
1618
|
+
title: `Color ${n}`,
|
|
1619
|
+
onClick: () => {
|
|
1620
|
+
E(n), en();
|
|
1621
|
+
}
|
|
1622
|
+
},
|
|
1623
|
+
n
|
|
1624
|
+
)),
|
|
1625
|
+
/* @__PURE__ */ p(
|
|
1626
|
+
"label",
|
|
1627
|
+
{
|
|
1628
|
+
className: "be-canvas-custom-swatch",
|
|
1629
|
+
title: "Custom color",
|
|
1630
|
+
"aria-label": "Custom color",
|
|
1631
|
+
children: /* @__PURE__ */ p(
|
|
1632
|
+
"input",
|
|
1633
|
+
{
|
|
1634
|
+
type: "color",
|
|
1635
|
+
value: m,
|
|
1636
|
+
onChange: (n) => E(n.target.value)
|
|
1637
|
+
}
|
|
1638
|
+
)
|
|
1639
|
+
}
|
|
1640
|
+
)
|
|
1641
|
+
]
|
|
1642
|
+
}
|
|
1643
|
+
)
|
|
1644
|
+
] }),
|
|
1645
|
+
/* @__PURE__ */ p("span", { className: "be-canvas-toolbar-divider" }),
|
|
1646
|
+
/* @__PURE__ */ _("div", { className: "be-canvas-picker-wrap", children: [
|
|
1647
|
+
/* @__PURE__ */ p(
|
|
1648
|
+
"button",
|
|
1649
|
+
{
|
|
1650
|
+
ref: Ze,
|
|
1651
|
+
type: "button",
|
|
1652
|
+
className: "be-canvas-toolbar-btn",
|
|
1653
|
+
"aria-haspopup": "true",
|
|
1654
|
+
"aria-expanded": le,
|
|
1655
|
+
"aria-label": `Fill: ${z ?? "none"}`,
|
|
1656
|
+
title: "Fill",
|
|
1657
|
+
onClick: () => Xe((n) => !n),
|
|
1658
|
+
children: /* @__PURE__ */ p(
|
|
1659
|
+
"span",
|
|
1660
|
+
{
|
|
1661
|
+
className: `be-canvas-fill-trigger-dot${z ? "" : " be-canvas-fill-trigger-dot-none"}`,
|
|
1662
|
+
style: z ? { backgroundColor: z } : void 0
|
|
1663
|
+
}
|
|
1664
|
+
)
|
|
1665
|
+
}
|
|
1666
|
+
),
|
|
1667
|
+
le && /* @__PURE__ */ _(
|
|
1668
|
+
"div",
|
|
1669
|
+
{
|
|
1670
|
+
ref: je,
|
|
1671
|
+
className: "be-canvas-picker be-canvas-color-picker",
|
|
1672
|
+
role: "menu",
|
|
1673
|
+
"aria-label": "Shape fill",
|
|
1674
|
+
children: [
|
|
1675
|
+
/* @__PURE__ */ p(
|
|
1676
|
+
"button",
|
|
1677
|
+
{
|
|
1678
|
+
type: "button",
|
|
1679
|
+
role: "menuitem",
|
|
1680
|
+
className: `be-canvas-toolbar-swatch be-canvas-fill-swatch-none${z === null ? " be-canvas-toolbar-swatch-active" : ""}`,
|
|
1681
|
+
"aria-pressed": z === null,
|
|
1682
|
+
"aria-label": "No fill",
|
|
1683
|
+
title: "No fill",
|
|
1684
|
+
onClick: () => {
|
|
1685
|
+
B(null), pe();
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
),
|
|
1689
|
+
Nn.map((n) => /* @__PURE__ */ p(
|
|
1690
|
+
"button",
|
|
1691
|
+
{
|
|
1692
|
+
type: "button",
|
|
1693
|
+
role: "menuitem",
|
|
1694
|
+
className: `be-canvas-toolbar-swatch${z === n ? " be-canvas-toolbar-swatch-active" : ""}`,
|
|
1695
|
+
style: { backgroundColor: n },
|
|
1696
|
+
"aria-pressed": z === n,
|
|
1697
|
+
"aria-label": `Fill ${n}`,
|
|
1698
|
+
title: `Fill ${n}`,
|
|
1699
|
+
onClick: () => {
|
|
1700
|
+
B(n), pe();
|
|
1701
|
+
}
|
|
1702
|
+
},
|
|
1703
|
+
n
|
|
1704
|
+
)),
|
|
1705
|
+
/* @__PURE__ */ p(
|
|
1706
|
+
"label",
|
|
1707
|
+
{
|
|
1708
|
+
className: "be-canvas-custom-swatch",
|
|
1709
|
+
title: "Custom fill",
|
|
1710
|
+
"aria-label": "Custom fill",
|
|
1711
|
+
children: /* @__PURE__ */ p(
|
|
1712
|
+
"input",
|
|
1713
|
+
{
|
|
1714
|
+
type: "color",
|
|
1715
|
+
value: z ?? $n,
|
|
1716
|
+
onChange: (n) => B(n.target.value)
|
|
1717
|
+
}
|
|
1718
|
+
)
|
|
1719
|
+
}
|
|
1720
|
+
)
|
|
1721
|
+
]
|
|
1722
|
+
}
|
|
1723
|
+
)
|
|
1724
|
+
] }),
|
|
1725
|
+
/* @__PURE__ */ p("span", { className: "be-canvas-toolbar-divider" }),
|
|
1726
|
+
/* @__PURE__ */ _("div", { className: "be-canvas-picker-wrap", children: [
|
|
1727
|
+
/* @__PURE__ */ p(
|
|
1728
|
+
"button",
|
|
1729
|
+
{
|
|
1730
|
+
ref: Ke,
|
|
1731
|
+
type: "button",
|
|
1732
|
+
className: "be-canvas-toolbar-btn",
|
|
1733
|
+
"aria-haspopup": "true",
|
|
1734
|
+
"aria-expanded": ue,
|
|
1735
|
+
"aria-label": `Stroke size: ${S}`,
|
|
1736
|
+
title: "Stroke size",
|
|
1737
|
+
onClick: () => Ye((n) => !n),
|
|
1738
|
+
children: /* @__PURE__ */ p(
|
|
1739
|
+
"span",
|
|
1740
|
+
{
|
|
1741
|
+
className: "be-canvas-size-trigger-dot",
|
|
1742
|
+
style: { width: Math.min(S, 16), height: Math.min(S, 16) }
|
|
1743
|
+
}
|
|
1744
|
+
)
|
|
1745
|
+
}
|
|
1746
|
+
),
|
|
1747
|
+
ue && /* @__PURE__ */ _(
|
|
1748
|
+
"div",
|
|
1749
|
+
{
|
|
1750
|
+
ref: Ve,
|
|
1751
|
+
className: "be-canvas-picker be-canvas-size-picker",
|
|
1752
|
+
role: "dialog",
|
|
1753
|
+
"aria-label": "Stroke size",
|
|
1754
|
+
children: [
|
|
1755
|
+
/* @__PURE__ */ p("span", { className: "be-canvas-size-preview", "aria-hidden": "true", children: /* @__PURE__ */ p(
|
|
1756
|
+
"span",
|
|
1757
|
+
{
|
|
1758
|
+
className: "be-canvas-size-preview-dot",
|
|
1759
|
+
style: { width: S, height: S }
|
|
1760
|
+
}
|
|
1761
|
+
) }),
|
|
1762
|
+
/* @__PURE__ */ p(
|
|
1763
|
+
"input",
|
|
1764
|
+
{
|
|
1765
|
+
type: "range",
|
|
1766
|
+
className: "be-canvas-size-slider",
|
|
1767
|
+
min: Po,
|
|
1768
|
+
max: Ro,
|
|
1769
|
+
value: S,
|
|
1770
|
+
onChange: (n) => H(Number(n.target.value)),
|
|
1771
|
+
"aria-label": "Stroke size"
|
|
1772
|
+
}
|
|
1773
|
+
),
|
|
1774
|
+
/* @__PURE__ */ _("span", { className: "be-canvas-size-value", children: [
|
|
1775
|
+
S,
|
|
1776
|
+
"px"
|
|
1777
|
+
] })
|
|
1778
|
+
]
|
|
1779
|
+
}
|
|
1780
|
+
)
|
|
1781
|
+
] }),
|
|
1782
|
+
/* @__PURE__ */ p("span", { className: "be-canvas-toolbar-divider" }),
|
|
1783
|
+
/* @__PURE__ */ p(
|
|
1784
|
+
"button",
|
|
1785
|
+
{
|
|
1786
|
+
type: "button",
|
|
1787
|
+
className: `be-canvas-toolbar-btn${A ? " be-canvas-toolbar-btn-active" : ""}`,
|
|
1788
|
+
"aria-pressed": A,
|
|
1789
|
+
"aria-label": "Snap to grid",
|
|
1790
|
+
title: A ? "Snap to grid: ON — drawing, moving, resizing and rotating align to the dotted grid. Click to turn off." : "Snap to grid: OFF — click to turn on (aligns drawing, moving, resizing and rotating to a grid)",
|
|
1791
|
+
onClick: () => ae((n) => !n),
|
|
1792
|
+
children: /* @__PURE__ */ p(eo, { size: 14 })
|
|
1793
|
+
}
|
|
1794
|
+
),
|
|
1795
|
+
/* @__PURE__ */ p("span", { className: "be-canvas-toolbar-divider" }),
|
|
1796
|
+
/* @__PURE__ */ p(
|
|
1797
|
+
"button",
|
|
1798
|
+
{
|
|
1799
|
+
type: "button",
|
|
1800
|
+
className: "be-canvas-toolbar-btn",
|
|
1801
|
+
"aria-label": "Zoom out",
|
|
1802
|
+
title: "Zoom out",
|
|
1803
|
+
onClick: Tr,
|
|
1804
|
+
disabled: M.zoom <= Ne,
|
|
1805
|
+
children: "−"
|
|
1806
|
+
}
|
|
1807
|
+
),
|
|
1808
|
+
/* @__PURE__ */ _(
|
|
1809
|
+
"button",
|
|
1810
|
+
{
|
|
1811
|
+
type: "button",
|
|
1812
|
+
className: "be-canvas-zoom-label",
|
|
1813
|
+
"aria-label": `Zoom: ${Math.round(M.zoom * 100)}%. Click to reset to 100%.`,
|
|
1814
|
+
title: "Reset zoom to 100%",
|
|
1815
|
+
onClick: vr,
|
|
1816
|
+
children: [
|
|
1817
|
+
Math.round(M.zoom * 100),
|
|
1818
|
+
"%"
|
|
1819
|
+
]
|
|
1820
|
+
}
|
|
1821
|
+
),
|
|
1822
|
+
/* @__PURE__ */ p(
|
|
1823
|
+
"button",
|
|
1824
|
+
{
|
|
1825
|
+
type: "button",
|
|
1826
|
+
className: "be-canvas-toolbar-btn",
|
|
1827
|
+
"aria-label": "Zoom in",
|
|
1828
|
+
title: "Zoom in",
|
|
1829
|
+
onClick: Nr,
|
|
1830
|
+
disabled: M.zoom >= Te,
|
|
1831
|
+
children: "+"
|
|
1832
|
+
}
|
|
1833
|
+
),
|
|
1834
|
+
/* @__PURE__ */ p("span", { className: "be-canvas-toolbar-divider" }),
|
|
1835
|
+
/* @__PURE__ */ p(
|
|
1836
|
+
"button",
|
|
1837
|
+
{
|
|
1838
|
+
type: "button",
|
|
1839
|
+
className: "be-canvas-toolbar-btn",
|
|
1840
|
+
"aria-label": "Export PNG",
|
|
1841
|
+
title: "Export as PNG",
|
|
1842
|
+
onClick: Mr,
|
|
1843
|
+
disabled: kn.length === 0 && En.length === 0,
|
|
1844
|
+
children: /* @__PURE__ */ p(no, { size: 14 })
|
|
1845
|
+
}
|
|
1846
|
+
)
|
|
1847
|
+
] }),
|
|
1848
|
+
/* @__PURE__ */ _(
|
|
1849
|
+
"svg",
|
|
1850
|
+
{
|
|
1851
|
+
ref: q,
|
|
1852
|
+
className: "be-canvas-surface",
|
|
1853
|
+
viewBox: `${M.x} ${M.y} ${Y} ${Y}`,
|
|
1854
|
+
width: In,
|
|
1855
|
+
height: Lr,
|
|
1856
|
+
tabIndex: -1,
|
|
1857
|
+
onPointerDown: Rr,
|
|
1858
|
+
onPointerMove: Cr,
|
|
1859
|
+
onPointerUp: Ar,
|
|
1860
|
+
onPointerCancel: Dr,
|
|
1861
|
+
onDoubleClick: Pr,
|
|
1862
|
+
onKeyDown: $r,
|
|
1863
|
+
children: [
|
|
1864
|
+
A && /* @__PURE__ */ _(Br, { children: [
|
|
1865
|
+
/* @__PURE__ */ p("defs", { children: /* @__PURE__ */ p(
|
|
1866
|
+
"pattern",
|
|
1867
|
+
{
|
|
1868
|
+
id: `be-canvas-grid-${t}`,
|
|
1869
|
+
width: Pn,
|
|
1870
|
+
height: Pn,
|
|
1871
|
+
patternUnits: "userSpaceOnUse",
|
|
1872
|
+
children: /* @__PURE__ */ p("circle", { cx: 1, cy: 1, r: 1.5, className: "be-canvas-grid-dot" })
|
|
1873
|
+
}
|
|
1874
|
+
) }),
|
|
1875
|
+
/* @__PURE__ */ p(
|
|
1876
|
+
"rect",
|
|
1877
|
+
{
|
|
1878
|
+
className: "be-canvas-grid-background",
|
|
1879
|
+
x: M.x,
|
|
1880
|
+
y: M.y,
|
|
1881
|
+
width: Y,
|
|
1882
|
+
height: Y,
|
|
1883
|
+
fill: `url(#be-canvas-grid-${t})`
|
|
1884
|
+
}
|
|
1885
|
+
)
|
|
1886
|
+
] }),
|
|
1887
|
+
se(kn, En).map(({ kind: n, item: a }) => {
|
|
1888
|
+
var h, d;
|
|
1889
|
+
if (n === "stroke") {
|
|
1890
|
+
const g = a, y = ((h = X == null ? void 0 : X.ids) == null ? void 0 : h.includes(g.id)) ? ee(
|
|
1891
|
+
Xt(g, X.dx, X.dy).points,
|
|
1892
|
+
{ size: g.size }
|
|
1893
|
+
) : s(g);
|
|
1894
|
+
return /* @__PURE__ */ p(
|
|
1895
|
+
"path",
|
|
1896
|
+
{
|
|
1897
|
+
d: y,
|
|
1898
|
+
fill: g.color,
|
|
1899
|
+
fillRule: "nonzero",
|
|
1900
|
+
opacity: wr.has(g.id) ? 0.25 : 1
|
|
1901
|
+
},
|
|
1902
|
+
g.id
|
|
1903
|
+
);
|
|
1904
|
+
}
|
|
1905
|
+
const c = a;
|
|
1906
|
+
let l = c;
|
|
1907
|
+
return (d = X == null ? void 0 : X.ids) != null && d.includes(c.id) ? l = Ot(c, X.dx, X.dy) : (st == null ? void 0 : st.id) === c.id && (l = st), /* @__PURE__ */ p(
|
|
1908
|
+
_n,
|
|
1909
|
+
{
|
|
1910
|
+
shape: l,
|
|
1911
|
+
opacity: Sr.has(c.id) ? 0.25 : 1
|
|
1912
|
+
},
|
|
1913
|
+
c.id
|
|
1914
|
+
);
|
|
1915
|
+
}),
|
|
1916
|
+
on && /* @__PURE__ */ p("path", { d: on, fill: m, fillRule: "nonzero" }),
|
|
1917
|
+
ln && /* @__PURE__ */ p(_n, { shape: ln, opacity: 0.6 }),
|
|
1918
|
+
Zt.map(({ id: n, box: a, rotation: c }) => /* @__PURE__ */ p(
|
|
1919
|
+
"g",
|
|
1920
|
+
{
|
|
1921
|
+
transform: c ? `rotate(${c} ${a.x + a.width / 2} ${a.y + a.height / 2})` : void 0,
|
|
1922
|
+
children: /* @__PURE__ */ p(
|
|
1923
|
+
"rect",
|
|
1924
|
+
{
|
|
1925
|
+
className: "be-canvas-selection-box",
|
|
1926
|
+
x: a.x - Ut,
|
|
1927
|
+
y: a.y - Ut,
|
|
1928
|
+
width: a.width + Ut * 2,
|
|
1929
|
+
height: a.height + Ut * 2,
|
|
1930
|
+
fill: "none"
|
|
1931
|
+
}
|
|
1932
|
+
)
|
|
1933
|
+
},
|
|
1934
|
+
n
|
|
1935
|
+
)),
|
|
1936
|
+
Fr.map(([n, a, c]) => /* @__PURE__ */ p(
|
|
1937
|
+
"rect",
|
|
1938
|
+
{
|
|
1939
|
+
className: "be-canvas-selection-handle",
|
|
1940
|
+
x: a - Yt / 2,
|
|
1941
|
+
y: c - Yt / 2,
|
|
1942
|
+
width: Yt,
|
|
1943
|
+
height: Yt
|
|
1944
|
+
},
|
|
1945
|
+
n
|
|
1946
|
+
)),
|
|
1947
|
+
Ee && /* @__PURE__ */ p(
|
|
1948
|
+
"circle",
|
|
1949
|
+
{
|
|
1950
|
+
className: "be-canvas-rotate-handle",
|
|
1951
|
+
cx: Ee[0],
|
|
1952
|
+
cy: Ee[1],
|
|
1953
|
+
r: Yt / 2
|
|
1954
|
+
}
|
|
1955
|
+
),
|
|
1956
|
+
Dt && /* @__PURE__ */ p(
|
|
1957
|
+
"rect",
|
|
1958
|
+
{
|
|
1959
|
+
className: "be-canvas-marquee",
|
|
1960
|
+
x: Dt.x,
|
|
1961
|
+
y: Dt.y,
|
|
1962
|
+
width: Dt.width,
|
|
1963
|
+
height: Dt.height
|
|
1964
|
+
}
|
|
1965
|
+
),
|
|
1966
|
+
P && /* @__PURE__ */ p(
|
|
1967
|
+
"foreignObject",
|
|
1968
|
+
{
|
|
1969
|
+
x: P.x,
|
|
1970
|
+
y: P.y,
|
|
1971
|
+
width: P.width,
|
|
1972
|
+
height: P.height,
|
|
1973
|
+
children: /* @__PURE__ */ p(
|
|
1974
|
+
"textarea",
|
|
1975
|
+
{
|
|
1976
|
+
xmlns: "http://www.w3.org/1999/xhtml",
|
|
1977
|
+
ref: (n) => n == null ? void 0 : n.focus(),
|
|
1978
|
+
className: "be-canvas-text-editor",
|
|
1979
|
+
value: P.text,
|
|
1980
|
+
style: { color: P.color, fontSize: P.fontSize },
|
|
1981
|
+
onChange: (n) => xt((a) => a && { ...a, text: n.target.value }),
|
|
1982
|
+
onBlur: () => zr(),
|
|
1983
|
+
onKeyDown: (n) => {
|
|
1984
|
+
n.key === "Escape" && (n.preventDefault(), Ir()), n.stopPropagation();
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
)
|
|
1988
|
+
}
|
|
1989
|
+
)
|
|
1990
|
+
]
|
|
1991
|
+
}
|
|
1992
|
+
),
|
|
1993
|
+
/* @__PURE__ */ p(
|
|
1994
|
+
"div",
|
|
1995
|
+
{
|
|
1996
|
+
className: "be-canvas-resize-handle",
|
|
1997
|
+
onMouseDown: _r,
|
|
1998
|
+
onKeyDown: Or,
|
|
1999
|
+
role: "slider",
|
|
2000
|
+
tabIndex: 0,
|
|
2001
|
+
"aria-label": "Resize canvas (Left/Right for width, Up/Down for height)",
|
|
2002
|
+
"aria-valuemin": Gt,
|
|
2003
|
+
"aria-valuenow": In,
|
|
2004
|
+
contentEditable: !1
|
|
2005
|
+
}
|
|
2006
|
+
)
|
|
2007
|
+
]
|
|
2008
|
+
}
|
|
2009
|
+
);
|
|
2010
|
+
}
|
|
2011
|
+
const ir = "block", ar = "inline", cr = "extension", On = { blocks: !1, runs: !0, void: !0 };
|
|
2012
|
+
function O(t, r) {
|
|
2013
|
+
throw new TypeError(`${t}: ${r}`);
|
|
2014
|
+
}
|
|
2015
|
+
function ts(t) {
|
|
2016
|
+
(!t || typeof t != "object") && O("defineBlock", "config must be an object");
|
|
2017
|
+
const { name: r, component: e, contentModel: o, isLeaf: s, ...i } = t;
|
|
2018
|
+
(typeof r != "string" || !r.trim()) && O("defineBlock", "`name` must be a non-empty string"), typeof e != "function" && O("defineBlock", `block "${r}": \`component\` must be a React component`), o !== void 0 && !(o in On) && O(
|
|
2019
|
+
"defineBlock",
|
|
2020
|
+
`block "${r}": \`contentModel\` must be 'blocks', 'runs', or 'void' (got ${JSON.stringify(o)})`
|
|
2021
|
+
);
|
|
2022
|
+
const u = s !== void 0 ? !!s : o === void 0 ? !1 : On[o];
|
|
2023
|
+
return {
|
|
2024
|
+
...i,
|
|
2025
|
+
...o !== void 0 ? { contentModel: o } : {},
|
|
2026
|
+
name: r,
|
|
2027
|
+
kind: ir,
|
|
2028
|
+
component: e,
|
|
2029
|
+
isLeaf: u
|
|
2030
|
+
};
|
|
2031
|
+
}
|
|
2032
|
+
function xs(t) {
|
|
2033
|
+
(!t || typeof t != "object") && O("defineInline", "config must be an object");
|
|
2034
|
+
const { name: r, component: e, atomic: o, isAtomic: s, ...i } = t;
|
|
2035
|
+
return (typeof r != "string" || !r.trim()) && O("defineInline", "`name` must be a non-empty string"), typeof e != "function" && O("defineInline", `inline "${r}": \`component\` must be a React component`), (o !== void 0 ? !!o : s !== void 0 ? !!s : !0) !== !0 && O("defineInline", `inline "${r}": only atomic inline types are supported today`), {
|
|
2036
|
+
...i,
|
|
2037
|
+
name: r,
|
|
2038
|
+
kind: ar,
|
|
2039
|
+
component: e,
|
|
2040
|
+
isAtomic: !0
|
|
2041
|
+
};
|
|
2042
|
+
}
|
|
2043
|
+
function gs(t) {
|
|
2044
|
+
(!t || typeof t != "object") && O("defineExtension", "config must be an object");
|
|
2045
|
+
const {
|
|
2046
|
+
name: r,
|
|
2047
|
+
blocks: e = [],
|
|
2048
|
+
inlineTypes: o = [],
|
|
2049
|
+
keymap: s,
|
|
2050
|
+
onBeforeInput: i,
|
|
2051
|
+
onPaste: u,
|
|
2052
|
+
setup: f,
|
|
2053
|
+
...x
|
|
2054
|
+
} = t;
|
|
2055
|
+
(typeof r != "string" || !r.trim()) && O("defineExtension", "`name` must be a non-empty string"), Array.isArray(e) || O("defineExtension", `extension "${r}": \`blocks\` must be an array`), Array.isArray(o) || O("defineExtension", `extension "${r}": \`inlineTypes\` must be an array`), s !== void 0 && (typeof s != "object" || s === null) && O("defineExtension", `extension "${r}": \`keymap\` must be an object`);
|
|
2056
|
+
for (const [m, E] of [
|
|
2057
|
+
["onBeforeInput", i],
|
|
2058
|
+
["onPaste", u],
|
|
2059
|
+
["setup", f]
|
|
2060
|
+
])
|
|
2061
|
+
E !== void 0 && typeof E != "function" && O("defineExtension", `extension "${r}": \`${m}\` must be a function`);
|
|
2062
|
+
return {
|
|
2063
|
+
...x,
|
|
2064
|
+
name: r,
|
|
2065
|
+
kind: cr,
|
|
2066
|
+
blocks: e,
|
|
2067
|
+
inlineTypes: o,
|
|
2068
|
+
...s !== void 0 ? { keymap: s } : {},
|
|
2069
|
+
...i !== void 0 ? { onBeforeInput: i } : {},
|
|
2070
|
+
...u !== void 0 ? { onPaste: u } : {},
|
|
2071
|
+
...f !== void 0 ? { setup: f } : {}
|
|
2072
|
+
};
|
|
2073
|
+
}
|
|
2074
|
+
function es(t) {
|
|
2075
|
+
return !!t && t.kind === ir;
|
|
2076
|
+
}
|
|
2077
|
+
function ns(t) {
|
|
2078
|
+
return !!t && t.kind === ar;
|
|
2079
|
+
}
|
|
2080
|
+
function rs(t) {
|
|
2081
|
+
return !!t && t.kind === cr;
|
|
2082
|
+
}
|
|
2083
|
+
function os(t, { registry: r, inlineRegistry: e }) {
|
|
2084
|
+
Array.isArray(t) || O("registerExtensions", "`extensions` must be an array");
|
|
2085
|
+
for (const o of t.flat(1 / 0))
|
|
2086
|
+
rs(o) ? os([...o.blocks, ...o.inlineTypes], { registry: r, inlineRegistry: e }) : es(o) ? (r || O("registerExtensions", `no block registry given for "${o.name}"`), r.register(o.name, o)) : ns(o) ? (e || O("registerExtensions", `no inline registry given for "${o.name}"`), e.register(o.name, o)) : O(
|
|
2087
|
+
"registerExtensions",
|
|
2088
|
+
"each item must be a defineBlock() / defineInline() result or a defineExtension() bundle (missing `kind`)"
|
|
2089
|
+
);
|
|
2090
|
+
}
|
|
2091
|
+
function ss(t) {
|
|
2092
|
+
const { strokes: r = [], shapes: e = [] } = t.props;
|
|
2093
|
+
return !r.length && !e.length ? "<p></p>" : tr(t);
|
|
2094
|
+
}
|
|
2095
|
+
function is() {
|
|
2096
|
+
return "";
|
|
2097
|
+
}
|
|
2098
|
+
function as() {
|
|
2099
|
+
return null;
|
|
2100
|
+
}
|
|
2101
|
+
function cs(t, { blockId: r, runId: e, sliceStart: o, sliceEnd: s }) {
|
|
2102
|
+
const i = t.getRun(e), u = (i == null ? void 0 : i.value) ?? "";
|
|
2103
|
+
t.applyOperation(
|
|
2104
|
+
oo(e, { value: u.slice(0, o) + u.slice(s) })
|
|
2105
|
+
);
|
|
2106
|
+
const f = so(t, r, Eo());
|
|
2107
|
+
return io(t, f, ao("paragraph")), f;
|
|
2108
|
+
}
|
|
2109
|
+
const bs = ts({
|
|
2110
|
+
name: "canvas",
|
|
2111
|
+
contentModel: "void",
|
|
2112
|
+
component: Qo,
|
|
2113
|
+
defaultProps: {
|
|
2114
|
+
strokes: [],
|
|
2115
|
+
shapes: [],
|
|
2116
|
+
width: ne,
|
|
2117
|
+
height: re
|
|
2118
|
+
},
|
|
2119
|
+
toHTML: ss,
|
|
2120
|
+
toPlainText: is,
|
|
2121
|
+
fromHTML: as,
|
|
2122
|
+
slashCommand: {
|
|
2123
|
+
label: "Canvas",
|
|
2124
|
+
icon: ro,
|
|
2125
|
+
keywords: ["canvas", "draw", "drawing", "sketch", "freehand"],
|
|
2126
|
+
run: cs
|
|
2127
|
+
}
|
|
2128
|
+
});
|
|
2129
|
+
export {
|
|
2130
|
+
os as a,
|
|
2131
|
+
ts as b,
|
|
2132
|
+
bs as c,
|
|
2133
|
+
gs as d,
|
|
2134
|
+
xs as e,
|
|
2135
|
+
co as f,
|
|
2136
|
+
ys as g,
|
|
2137
|
+
ms as h,
|
|
2138
|
+
Io as i,
|
|
2139
|
+
Mt as j,
|
|
2140
|
+
oe as k,
|
|
2141
|
+
ct as l,
|
|
2142
|
+
ps as r,
|
|
2143
|
+
hs as u
|
|
2144
|
+
};
|
|
2145
|
+
//# sourceMappingURL=index-B9jyyL8u.js.map
|