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