@8btc/whiteboard 0.0.19-beta.1 → 0.0.19-beta.2

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.
@@ -1,5 +1,5 @@
1
- import { v4 as _ } from "uuid";
2
- import { N as M } from "../const-Das6lRi-.js";
1
+ import { v4 as $ } from "uuid";
2
+ import { N as M } from "../const-CpLk0Av6.js";
3
3
  async function A(t) {
4
4
  return new Promise((o, e) => {
5
5
  const n = new Image();
@@ -17,8 +17,8 @@ function B(t) {
17
17
  let r = 1 / 0, i = -1 / 0;
18
18
  if (n.children.forEach((a) => {
19
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);
20
+ const s = a.getAttrs(), l = s.x || 0, f = s.y || 0, c = s.height || 0;
21
+ r = Math.min(r, l), i = Math.max(i, f + c);
22
22
  }
23
23
  }), r !== 1 / 0 && i !== -1 / 0)
24
24
  return { x: r, y: i };
@@ -29,29 +29,29 @@ function B(t) {
29
29
  y: e.y
30
30
  };
31
31
  }
32
- async function $(t, o, e, n) {
32
+ async function _(t, o, e, n) {
33
33
  if (!t) return;
34
34
  const r = Array.isArray(o) ? o : [o];
35
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 = [];
36
+ const i = n?.spacing ?? 20, a = n?.scrollToView ?? !0, s = n?.direction ?? "vertical", l = await Promise.all(r.map((d) => A(d))), f = [], c = [];
37
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({
38
+ return r.forEach((d, g) => {
39
+ const { width: h, height: y } = l[g], I = $();
40
+ f.push({
41
41
  id: I,
42
42
  $_type: "image",
43
43
  x: u,
44
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;
45
+ width: h,
46
+ height: y,
47
+ $_imageUrl: d
48
+ }), c.push(I), s === "horizontal" ? u += h + i : m += y + i;
49
+ }), t.createNodes(f, !0), t.getMainLayer().draw(), a && t.scrollToContent({ scale: !1, nodeIds: c }), c;
50
50
  }
51
51
  async function X(t, o) {
52
52
  if (!t) return;
53
53
  const e = B(t);
54
- return $(t, o, {
54
+ return _(t, o, {
55
55
  x: e.x,
56
56
  y: e.y + 20
57
57
  });
@@ -63,8 +63,8 @@ function Y(t, o) {
63
63
  let n = 1 / 0, r = 1 / 0, i = -1 / 0, a = -1 / 0;
64
64
  if (t.getMainLayer().children.forEach((c) => {
65
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);
66
+ const u = c.getAttrs(), m = u.x || 0, d = u.y || 0, g = u.width || 0, h = u.height || 0;
67
+ n = Math.min(n, m), r = Math.min(r, d), i = Math.max(i, m + g), a = Math.max(a, d + h);
68
68
  }
69
69
  }), n === 1 / 0 || r === 1 / 0 || i === -1 / 0 || a === -1 / 0)
70
70
  return;
@@ -73,30 +73,33 @@ function Y(t, o) {
73
73
  y: r,
74
74
  width: i - n,
75
75
  height: a - r
76
- }, d = {
77
- id: _(),
78
- $_type: "image",
76
+ }, f = {
77
+ id: $(),
78
+ $_type: "html",
79
79
  x: l.x,
80
80
  y: l.y,
81
81
  width: l.width,
82
82
  height: l.height,
83
- $_imageUrl: o
83
+ $_imageUrl: o,
84
84
  // 示例 loading 图片 URL
85
+ $_htmlContent: `
86
+ <img alt="loading" src="${o}" style="width: 100%; height: 100%; object-fit: contain;" />
87
+ `
85
88
  };
86
- return t.createNodes([d], !0), t.scrollToContent({ scale: !1, nodeIds: [d.id] }), d.id;
89
+ return t.createNodes([f], !0), f.id;
87
90
  }
88
91
  function E(t, o, e) {
89
92
  if (!t) return;
90
93
  const n = t.getCanvasNodeById(o);
91
94
  if (!n) return;
92
95
  const r = n.getConfig();
93
- if (r.$_type !== "image") return;
96
+ if (r.$_type !== "html") return;
94
97
  const i = Array.isArray(e) ? e : [e];
95
98
  if (i.length === 0) return;
96
99
  const a = r.x, s = r.y;
97
- $(t, i, { x: a, y: s }), t.deleteNodes([o]);
100
+ _(t, i, { x: a, y: s }), t.deleteNodes([o]);
98
101
  }
99
- async function T(t, o) {
102
+ async function H(t, o) {
100
103
  if (!t) return null;
101
104
  const e = t.getCanvasNodeById(o);
102
105
  if (!e) return null;
@@ -109,15 +112,15 @@ async function T(t, o) {
109
112
  if (!i) return null;
110
113
  const a = i.getConfig();
111
114
  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) => {
115
+ const { start: s, end: l } = n.$_relativeBox, f = s.ratioX, c = s.ratioY, u = l.ratioX - s.ratioX, m = l.ratioY - s.ratioY;
116
+ return new Promise((d) => {
114
117
  const g = new Image();
115
118
  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");
119
+ const h = g.naturalWidth, y = g.naturalHeight, I = f * h, v = c * y, w = u * h, C = m * y, x = document.createElement("canvas");
117
120
  x.width = w, x.height = C;
118
121
  const N = x.getContext("2d");
119
122
  if (!N) {
120
- f(null);
123
+ d(null);
121
124
  return;
122
125
  }
123
126
  N.drawImage(
@@ -132,13 +135,13 @@ async function T(t, o) {
132
135
  C
133
136
  );
134
137
  const p = x.toDataURL("image/png");
135
- f(p);
138
+ d(p);
136
139
  }, g.onerror = () => {
137
- console.error("Failed to load image:", a.$_imageUrl), f(null);
140
+ console.error("Failed to load image:", a.$_imageUrl), d(null);
138
141
  }, g.src = a.$_imageUrl;
139
142
  });
140
143
  }
141
- function H(t) {
144
+ function R(t) {
142
145
  if (!t) return null;
143
146
  const o = t.getState().selectedNodeIds || [];
144
147
  if (o.length === 0) return null;
@@ -152,10 +155,10 @@ function H(t) {
152
155
  }
153
156
  export {
154
157
  B as calculateBottomLeftOfCanvasContent,
155
- T as cropImageBaseOnImageMarker,
156
- H as exportSelectionAsImage,
158
+ H as cropImageBaseOnImageMarker,
159
+ R as exportSelectionAsImage,
157
160
  X as insertImageBesideContent,
158
- $ as insertImagesAtPosition,
161
+ _ as insertImagesAtPosition,
159
162
  Y as insertLoadingImageBesideSelection,
160
163
  E as replaceLoadingImageNode
161
164
  };
@@ -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
- }, e = {
6
+ imageMarker: "image_marker_intrinsic",
7
+ html: "html_intrinsic"
8
+ }, t = {
8
9
  CORNER_RADIUS: 6,
9
10
  MIN_SIZE: 10
10
- }, n = {
11
+ }, e = {
11
12
  MIN_SIZE: 10
12
13
  };
13
14
  export {
14
- n as I,
15
+ e as I,
15
16
  i as N,
16
- e as R
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;