@8btc/whiteboard 0.0.18 → 0.0.19-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/maze.d.ts +2 -0
- package/dist/adapter/maze.js +161 -0
- package/dist/const-Das6lRi-.js +17 -0
- package/dist/index.css +1 -1320
- package/dist/index.d.ts +99 -62
- package/dist/index.js +1096 -1565
- package/dist/maze.d.ts +538 -0
- package/package.json +8 -4
- package/dist/index.umd.js +0 -3574
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { v4 as _ } from "uuid";
|
|
2
|
+
import { N as M } from "../const-Das6lRi-.js";
|
|
3
|
+
async function A(t) {
|
|
4
|
+
return new Promise((o, e) => {
|
|
5
|
+
const n = new Image();
|
|
6
|
+
n.onload = () => {
|
|
7
|
+
o({ width: n.naturalWidth, height: n.naturalHeight });
|
|
8
|
+
}, n.onerror = () => {
|
|
9
|
+
e(new Error(`Failed to load image: ${t}`));
|
|
10
|
+
}, n.src = t;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
function B(t) {
|
|
14
|
+
if (!t) return { x: 0, y: 0 };
|
|
15
|
+
if ((t.getState().nodes || []).length > 0) {
|
|
16
|
+
const n = t.getMainLayer();
|
|
17
|
+
let r = 1 / 0, i = -1 / 0;
|
|
18
|
+
if (n.children.forEach((a) => {
|
|
19
|
+
if (a.visible() && a.getClassName() !== "Transformer" && a.hasName(M.selectable)) {
|
|
20
|
+
const s = a.getAttrs(), l = s.x || 0, d = s.y || 0, c = s.height || 0;
|
|
21
|
+
r = Math.min(r, l), i = Math.max(i, d + c);
|
|
22
|
+
}
|
|
23
|
+
}), r !== 1 / 0 && i !== -1 / 0)
|
|
24
|
+
return { x: r, y: i };
|
|
25
|
+
}
|
|
26
|
+
const e = t.getState().viewport;
|
|
27
|
+
return {
|
|
28
|
+
x: e.x,
|
|
29
|
+
y: e.y
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
async function $(t, o, e, n) {
|
|
33
|
+
if (!t) return;
|
|
34
|
+
const r = Array.isArray(o) ? o : [o];
|
|
35
|
+
if (r.length === 0) return;
|
|
36
|
+
const i = n?.spacing ?? 20, a = n?.scrollToView ?? !0, s = n?.direction ?? "vertical", l = await Promise.all(r.map((f) => A(f))), d = [], c = [];
|
|
37
|
+
let u = e.x, m = e.y;
|
|
38
|
+
return r.forEach((f, g) => {
|
|
39
|
+
const { width: y, height: h } = l[g], I = _();
|
|
40
|
+
d.push({
|
|
41
|
+
id: I,
|
|
42
|
+
$_type: "image",
|
|
43
|
+
x: u,
|
|
44
|
+
y: m,
|
|
45
|
+
width: y,
|
|
46
|
+
height: h,
|
|
47
|
+
$_imageUrl: f
|
|
48
|
+
}), c.push(I), s === "horizontal" ? u += y + i : m += h + i;
|
|
49
|
+
}), t.createNodes(d, !0), t.getMainLayer().draw(), a && t.scrollToContent({ scale: !1, nodeIds: c }), c;
|
|
50
|
+
}
|
|
51
|
+
async function X(t, o) {
|
|
52
|
+
if (!t) return;
|
|
53
|
+
const e = B(t);
|
|
54
|
+
return $(t, o, {
|
|
55
|
+
x: e.x,
|
|
56
|
+
y: e.y + 20
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function Y(t, o) {
|
|
60
|
+
if (!t) return;
|
|
61
|
+
const e = t.getState().selectedNodeIds || [];
|
|
62
|
+
if (e.length === 0) return;
|
|
63
|
+
let n = 1 / 0, r = 1 / 0, i = -1 / 0, a = -1 / 0;
|
|
64
|
+
if (t.getMainLayer().children.forEach((c) => {
|
|
65
|
+
if (c.visible() && c.getClassName() !== "Transformer" && e.includes(c.id())) {
|
|
66
|
+
const u = c.getAttrs(), m = u.x || 0, f = u.y || 0, g = u.width || 0, y = u.height || 0;
|
|
67
|
+
n = Math.min(n, m), r = Math.min(r, f), i = Math.max(i, m + g), a = Math.max(a, f + y);
|
|
68
|
+
}
|
|
69
|
+
}), n === 1 / 0 || r === 1 / 0 || i === -1 / 0 || a === -1 / 0)
|
|
70
|
+
return;
|
|
71
|
+
const l = {
|
|
72
|
+
x: i + 20,
|
|
73
|
+
y: r,
|
|
74
|
+
width: i - n,
|
|
75
|
+
height: a - r
|
|
76
|
+
}, d = {
|
|
77
|
+
id: _(),
|
|
78
|
+
$_type: "image",
|
|
79
|
+
x: l.x,
|
|
80
|
+
y: l.y,
|
|
81
|
+
width: l.width,
|
|
82
|
+
height: l.height,
|
|
83
|
+
$_imageUrl: o
|
|
84
|
+
// 示例 loading 图片 URL
|
|
85
|
+
};
|
|
86
|
+
return t.createNodes([d], !0), t.scrollToContent({ scale: !1, nodeIds: [d.id] }), d.id;
|
|
87
|
+
}
|
|
88
|
+
function E(t, o, e) {
|
|
89
|
+
if (!t) return;
|
|
90
|
+
const n = t.getCanvasNodeById(o);
|
|
91
|
+
if (!n) return;
|
|
92
|
+
const r = n.getConfig();
|
|
93
|
+
if (r.$_type !== "image") return;
|
|
94
|
+
const i = Array.isArray(e) ? e : [e];
|
|
95
|
+
if (i.length === 0) return;
|
|
96
|
+
const a = r.x, s = r.y;
|
|
97
|
+
$(t, i, { x: a, y: s }), t.deleteNodes([o]);
|
|
98
|
+
}
|
|
99
|
+
async function T(t, o) {
|
|
100
|
+
if (!t) return null;
|
|
101
|
+
const e = t.getCanvasNodeById(o);
|
|
102
|
+
if (!e) return null;
|
|
103
|
+
const n = e.getConfig();
|
|
104
|
+
if (n.$_type !== "image-marker" || !n.$_relativeBox)
|
|
105
|
+
return null;
|
|
106
|
+
const r = n.$_parentId;
|
|
107
|
+
if (!r) return null;
|
|
108
|
+
const i = t.getCanvasNodeById(r);
|
|
109
|
+
if (!i) return null;
|
|
110
|
+
const a = i.getConfig();
|
|
111
|
+
if (a.$_type !== "image" || !a.$_imageUrl) return null;
|
|
112
|
+
const { start: s, end: l } = n.$_relativeBox, d = s.ratioX, c = s.ratioY, u = l.ratioX - s.ratioX, m = l.ratioY - s.ratioY;
|
|
113
|
+
return new Promise((f) => {
|
|
114
|
+
const g = new Image();
|
|
115
|
+
g.crossOrigin = "anonymous", g.onload = () => {
|
|
116
|
+
const y = g.naturalWidth, h = g.naturalHeight, I = d * y, v = c * h, w = u * y, C = m * h, x = document.createElement("canvas");
|
|
117
|
+
x.width = w, x.height = C;
|
|
118
|
+
const N = x.getContext("2d");
|
|
119
|
+
if (!N) {
|
|
120
|
+
f(null);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
N.drawImage(
|
|
124
|
+
g,
|
|
125
|
+
I,
|
|
126
|
+
v,
|
|
127
|
+
w,
|
|
128
|
+
C,
|
|
129
|
+
0,
|
|
130
|
+
0,
|
|
131
|
+
w,
|
|
132
|
+
C
|
|
133
|
+
);
|
|
134
|
+
const p = x.toDataURL("image/png");
|
|
135
|
+
f(p);
|
|
136
|
+
}, g.onerror = () => {
|
|
137
|
+
console.error("Failed to load image:", a.$_imageUrl), f(null);
|
|
138
|
+
}, g.src = a.$_imageUrl;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function H(t) {
|
|
142
|
+
if (!t) return null;
|
|
143
|
+
const o = t.getState().selectedNodeIds || [];
|
|
144
|
+
if (o.length === 0) return null;
|
|
145
|
+
if (o.length === 1) {
|
|
146
|
+
const e = t.getCanvasNodeById(o[0]);
|
|
147
|
+
if (!e) return null;
|
|
148
|
+
if (e.getConfig().$_type === "image")
|
|
149
|
+
return e.getConfig().$_imageUrl || null;
|
|
150
|
+
}
|
|
151
|
+
return t.exportSelectionAsImage();
|
|
152
|
+
}
|
|
153
|
+
export {
|
|
154
|
+
B as calculateBottomLeftOfCanvasContent,
|
|
155
|
+
T as cropImageBaseOnImageMarker,
|
|
156
|
+
H as exportSelectionAsImage,
|
|
157
|
+
X as insertImageBesideContent,
|
|
158
|
+
$ as insertImagesAtPosition,
|
|
159
|
+
Y as insertLoadingImageBesideSelection,
|
|
160
|
+
E as replaceLoadingImageNode
|
|
161
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const i = {
|
|
2
|
+
nodeRoot: "nodeRoot_intrinsic",
|
|
3
|
+
selectable: "selectable_intrinsic",
|
|
4
|
+
rect: "rect_intrinsic",
|
|
5
|
+
image: "image_intrinsic",
|
|
6
|
+
imageMarker: "image_marker_intrinsic"
|
|
7
|
+
}, e = {
|
|
8
|
+
CORNER_RADIUS: 6,
|
|
9
|
+
MIN_SIZE: 10
|
|
10
|
+
}, n = {
|
|
11
|
+
MIN_SIZE: 10
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
n as I,
|
|
15
|
+
i as N,
|
|
16
|
+
e as R
|
|
17
|
+
};
|