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