@8btc/whiteboard 0.0.20-alpha.4 → 0.0.20-alpha.40

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,2 +1,43 @@
1
1
  export * from '../app/adapter/maze'
2
2
  export {}
3
+
4
+
5
+ declare module "@tiptap/core" {
6
+ interface Commands<ReturnType> {
7
+ fontSize: {
8
+ setFontSize: (size: string) => ReturnType;
9
+ unsetFontSize: () => ReturnType;
10
+ };
11
+ }
12
+ }
13
+
14
+
15
+ declare module "@tiptap/core" {
16
+ interface Commands<ReturnType> {
17
+ lineHeight: {
18
+ setLineHeight: (lineHeight: string) => ReturnType;
19
+ unsetLineHeight: () => ReturnType;
20
+ };
21
+ }
22
+ }
23
+
24
+
25
+ declare module "@tiptap/core" {
26
+ interface Commands<ReturnType> {
27
+ letterSpacing: {
28
+ setLetterSpacing: (spacing: string) => ReturnType;
29
+ unsetLetterSpacing: () => ReturnType;
30
+ };
31
+ }
32
+ }
33
+
34
+
35
+ declare module "@tiptap/core" {
36
+ interface Commands<ReturnType> {
37
+ nodeBackground: {
38
+ setNodeBackgroundColor: (backgroundColor: string) => ReturnType;
39
+ unsetNodeBackgroundColor: () => ReturnType;
40
+ toggleNodeBackgroundColor: (backgroundColor: string) => ReturnType;
41
+ };
42
+ }
43
+ }
@@ -1,213 +1,302 @@
1
- import { v4 as C } from "uuid";
2
- import { N as p } from "../const-CNw7pZuI.js";
3
- async function v(t) {
4
- return new Promise((o, n) => {
1
+ import { v4 as w } from "uuid";
2
+ import { N as B } from "../const-B6DtCQRi.js";
3
+ async function N(t) {
4
+ return new Promise((n, o) => {
5
5
  const e = new Image();
6
6
  e.onload = () => {
7
- o({ width: e.naturalWidth, height: e.naturalHeight });
7
+ n({ width: e.naturalWidth, height: e.naturalHeight });
8
8
  }, e.onerror = () => {
9
- n(new Error(`Failed to load image: ${t}`));
9
+ o(new Error(`Failed to load image: ${t}`));
10
10
  }, e.src = t;
11
11
  });
12
12
  }
13
- function E(t) {
13
+ function v(t) {
14
14
  if (!t) return { x: 0, y: 0 };
15
15
  if ((t.getState().nodes || []).length > 0) {
16
16
  const e = t.getMainLayer();
17
- let i = 1 / 0, r = -1 / 0;
17
+ let r = 1 / 0, i = -1 / 0;
18
18
  if (e.children.forEach((s) => {
19
- if (s.visible() && s.getClassName() !== "Transformer" && s.hasName(p.selectable)) {
20
- const a = s.getAttrs(), c = a.x || 0, g = a.y || 0, l = a.height || 0;
21
- i = Math.min(i, c), r = Math.max(r, g + l);
19
+ if (s.visible() && s.getClassName() !== "Transformer" && s.hasName(B.selectable)) {
20
+ const l = s.getAttrs(), a = l.x || 0, d = l.y || 0, c = l.height || 0;
21
+ r = Math.min(r, a), i = Math.max(i, d + c);
22
22
  }
23
- }), i !== 1 / 0 && r !== -1 / 0)
24
- return { x: i, y: r };
23
+ }), r !== 1 / 0 && i !== -1 / 0)
24
+ return { x: r, y: i };
25
25
  }
26
- const n = t.getState().viewport;
26
+ const o = t.getState().viewport;
27
27
  return {
28
- x: n.x,
29
- y: n.y
28
+ x: o.x,
29
+ y: o.y
30
30
  };
31
31
  }
32
- async function S(t, o, n, e) {
32
+ async function S(t, n, o, e) {
33
33
  if (!t) return;
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, g = /* @__PURE__ */ new Map();
37
- c && (t.getState().nodes || []).forEach((y) => {
38
- y.$_type === "image" && y.$_imageUrl && g.set(y.$_imageUrl, y.id);
34
+ const r = Array.isArray(n) ? n : [n];
35
+ if (r.length === 0) return;
36
+ const i = e?.spacing ?? 20, s = e?.scrollToView ?? !0, l = e?.direction ?? "horizontal", a = e?.reuseExisting ?? !0, d = /* @__PURE__ */ new Map();
37
+ a && (t.getState().nodes || []).forEach((m) => {
38
+ m.$_type === "image" && m.$_imageUrl && d.set(m.$_imageUrl, m.id);
39
39
  });
40
- const l = await Promise.all(i.map((u) => v(u))), f = [], h = [];
41
- let m = n.x, d = n.y;
42
- return i.forEach((u, y) => {
43
- if (c && g.has(u)) {
44
- const I = g.get(u);
45
- h.push(I);
40
+ const c = await Promise.all(r.map((f) => N(f))), h = [], g = [];
41
+ let u = o.x, y = o.y;
42
+ return r.forEach((f, m) => {
43
+ if (a && d.has(f)) {
44
+ const _ = d.get(f);
45
+ g.push(_);
46
46
  return;
47
47
  }
48
- const { width: w, height: $ } = l[y], x = C();
49
- f.push({
50
- id: x,
48
+ const { width: x, height: $ } = c[m], I = w();
49
+ h.push({
50
+ id: I,
51
51
  $_type: "image",
52
- x: m,
53
- y: d,
54
- width: w,
52
+ x: u,
53
+ y,
54
+ width: x,
55
55
  height: $,
56
- $_imageUrl: u
57
- }), h.push(x), a === "horizontal" ? m += w + r : d += $ + r;
58
- }), f.length > 0 && t.createNodes(f, !0), s && t.scrollToContent({ scale: !1, nodeIds: h }), h;
56
+ $_imageUrl: f
57
+ }), g.push(I), l === "horizontal" ? u += x + i : y += $ + i;
58
+ }), h.length > 0 && t.createNodes(h, !0), s && t.scrollToContent({ scale: !1, nodeIds: g }), g;
59
59
  }
60
- async function L(t, o) {
60
+ async function H(t, n) {
61
61
  if (!t) return;
62
- const n = E(t);
63
- return S(t, o, {
64
- x: n.x,
65
- y: n.y + 20
62
+ const o = v(t);
63
+ return S(t, n, {
64
+ x: o.x,
65
+ y: o.y + 20
66
66
  });
67
67
  }
68
- function X(t, o) {
68
+ function L(t, n) {
69
69
  if (!t) return;
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((l) => {
74
- if (l.visible() && l.getClassName() !== "Transformer" && n.includes(l.id())) {
75
- const f = l.getAttrs(), h = f.x || 0, m = f.y || 0, d = f.width || 0, u = f.height || 0;
76
- e = Math.min(e, h), i = Math.min(i, m), r = Math.max(r, h + d), s = Math.max(s, m + u);
70
+ const o = t.getState().selectedNodeIds || [];
71
+ if (o.length === 0) return;
72
+ let e = 1 / 0, r = 1 / 0, i = -1 / 0, s = -1 / 0;
73
+ if (t.getMainLayer().children.forEach((c) => {
74
+ if (c.visible() && c.getClassName() !== "Transformer" && o.includes(c.id())) {
75
+ const h = c.getAttrs(), g = h.x || 0, u = h.y || 0, y = h.width || 0, f = h.height || 0;
76
+ e = Math.min(e, g), r = Math.min(r, u), i = Math.max(i, g + y), s = Math.max(s, u + f);
77
77
  }
78
- }), e === 1 / 0 || i === 1 / 0 || r === -1 / 0 || s === -1 / 0)
78
+ }), e === 1 / 0 || r === 1 / 0 || i === -1 / 0 || s === -1 / 0)
79
79
  return;
80
- const c = {
81
- x: r + 20,
82
- y: i,
83
- width: r - e,
84
- height: s - i
85
- }, g = {
86
- id: C(),
80
+ const a = {
81
+ x: i + 20,
82
+ y: r,
83
+ width: i - e,
84
+ height: s - r
85
+ }, d = {
86
+ id: w(),
87
87
  $_type: "html",
88
88
  $_actualType: "loading",
89
- x: c.x,
90
- y: c.y,
91
- width: c.width,
92
- height: c.height,
93
- $_imageUrl: o,
89
+ x: a.x,
90
+ y: a.y,
91
+ width: a.width,
92
+ height: a.height,
93
+ $_imageUrl: n,
94
94
  // 示例 loading 图片 URL
95
95
  $_htmlContent: `
96
- <img alt="loading" src="${o}" style="width: 100%; height: 100%; object-fit: contain;" />
96
+ <img alt="loading" src="${n}" style="width: 100%; height: 100%; object-fit: contain;" />
97
97
  `
98
98
  };
99
- return t.createNodes([g], !0), g.id;
99
+ return t.createNodes([d], !0), d.id;
100
100
  }
101
- function Y(t, o, n) {
101
+ function R(t, n, o) {
102
102
  if (!t) return;
103
- const e = t.getCanvasNodeById(o);
103
+ const e = t.getCanvasNodeById(n);
104
104
  if (!e) return;
105
- const i = e.getConfig();
106
- if (i.$_type !== "html") return;
107
- const r = Array.isArray(n) ? n : [n];
108
- if (r.length === 0) return;
109
- const s = i.x, a = i.y;
110
- S(t, r, { x: s, y: a }, { scrollToView: !1 }), t.deleteNodes([o]);
105
+ const r = e.getConfig();
106
+ if (r.$_type !== "html") return;
107
+ const i = Array.isArray(o) ? o : [o];
108
+ if (i.length === 0) return;
109
+ const s = r.x, l = r.y;
110
+ S(t, i, { x: s, y: l }, { scrollToView: !1 }), t.deleteNodes([n]);
111
111
  }
112
- async function A(t, o, n, e, i) {
112
+ async function T(t, n, o, e, r) {
113
113
  if (!t) return;
114
- const r = i?.scrollToView ?? !0;
115
- if (i?.reuseExisting ?? !0) {
116
- const g = t.getState().nodes || [];
117
- for (const l of g)
118
- if (l.$_type === "video" && l.$_videoUrl === o)
119
- return r && t.scrollToContent({ scale: !1, nodeIds: [l.id] }), l.id;
114
+ const i = r?.scrollToView ?? !0;
115
+ if (r?.reuseExisting ?? !0) {
116
+ const d = t.getState().nodes || [];
117
+ for (const c of d)
118
+ if (c.$_type === "video" && c.$_videoUrl === n)
119
+ return i && t.scrollToContent({ scale: !1, nodeIds: [c.id] }), c.id;
120
120
  }
121
- let a = { width: 320, height: 180 };
121
+ let l = { width: 320, height: 180 };
122
122
  try {
123
- a = await v(n);
124
- } catch (g) {
125
- console.warn("Failed to load cover image, using default size:", g);
123
+ l = await N(o);
124
+ } catch (d) {
125
+ console.warn("Failed to load cover image, using default size:", d);
126
126
  }
127
- const c = {
128
- id: C(),
127
+ const a = {
128
+ id: w(),
129
129
  $_type: "video",
130
130
  x: e.x,
131
131
  y: e.y,
132
- width: a.width,
132
+ width: l.width,
133
133
  // 使用封面图片的宽度
134
- height: a.height,
134
+ height: l.height,
135
135
  // 使用封面图片的高度
136
- $_videoUrl: o,
137
- $_coverUrl: n
136
+ $_videoUrl: n,
137
+ $_coverUrl: o
138
138
  };
139
- return t.createNodes([c], !0), r && t.scrollToContent({ scale: !1, nodeIds: [c.id] }), c.id;
139
+ return t.createNodes([a], !0), i && t.scrollToContent({ scale: !1, nodeIds: [a.id] }), a.id;
140
140
  }
141
- async function V(t, o, n) {
141
+ async function k(t, n, o) {
142
142
  if (!t) return;
143
- const e = E(t);
144
- return A(t, o, n, {
143
+ const e = v(t);
144
+ return T(t, n, o, {
145
145
  x: e.x,
146
146
  y: e.y + 20
147
147
  });
148
148
  }
149
- async function z(t, o) {
149
+ async function F(t, n) {
150
150
  if (!t) return null;
151
- const n = t.getCanvasNodeById(o);
152
- if (!n) return null;
153
- const e = n.getConfig();
151
+ const o = t.getCanvasNodeById(n);
152
+ if (!o) return null;
153
+ const e = o.getConfig();
154
154
  if (e.$_type !== "image-marker" || !e.$_relativeBox)
155
155
  return null;
156
- const i = e.$_parentId;
157
- if (!i) return null;
158
- const r = t.getCanvasNodeById(i);
156
+ const r = e.$_parentId;
159
157
  if (!r) return null;
160
- const s = r.getConfig();
161
- if (s.$_type !== "image" || !s.$_imageUrl) return null;
162
- const { start: a, end: c } = e.$_relativeBox, g = a.ratioX, l = a.ratioY, f = c.ratioX - a.ratioX, h = c.ratioY - a.ratioY;
163
- return new Promise((m) => {
164
- const d = new Image();
165
- d.crossOrigin = "anonymous", d.onload = () => {
166
- const u = d.naturalWidth, y = d.naturalHeight, w = g * u, $ = l * y, x = f * u, I = h * y, _ = document.createElement("canvas");
167
- _.width = x, _.height = I;
168
- const N = _.getContext("2d");
169
- if (!N) {
170
- m(null);
158
+ const i = t.getNodeConfigById(r);
159
+ if (!i || i.$_type !== "image" || !i.$_imageUrl) return null;
160
+ const { start: s, end: l } = e.$_relativeBox, a = s.ratioX, d = s.ratioY, c = l.ratioX - s.ratioX, h = l.ratioY - s.ratioY;
161
+ return new Promise((g) => {
162
+ const u = new Image();
163
+ u.crossOrigin = "anonymous", u.onload = () => {
164
+ const y = u.naturalWidth, f = u.naturalHeight, m = a * y, x = d * f, $ = c * y, I = h * f, _ = document.createElement("canvas");
165
+ _.width = $, _.height = I;
166
+ const p = _.getContext("2d");
167
+ if (!p) {
168
+ g(null);
171
169
  return;
172
170
  }
173
- N.drawImage(
174
- d,
175
- w,
176
- $,
171
+ p.drawImage(
172
+ u,
173
+ m,
177
174
  x,
175
+ $,
178
176
  I,
179
177
  0,
180
178
  0,
181
- x,
179
+ $,
182
180
  I
183
181
  );
184
- const M = _.toDataURL("image/png");
185
- m(M);
186
- }, d.onerror = () => {
187
- console.error("Failed to load image:", s.$_imageUrl), m(null);
188
- }, d.src = s.$_imageUrl;
182
+ const E = _.toDataURL("image/png");
183
+ g(E);
184
+ }, u.onerror = () => {
185
+ console.error("Failed to load image:", i.$_imageUrl), g(null);
186
+ }, u.src = i.$_imageUrl;
189
187
  });
190
188
  }
191
- function R(t) {
189
+ function W(t, n) {
192
190
  if (!t) return null;
193
191
  const o = t.getState().selectedNodeIds || [];
194
192
  if (o.length === 0) return null;
195
193
  if (o.length === 1) {
196
- const n = t.getCanvasNodeById(o[0]);
197
- if (!n) return null;
198
- if (n.getConfig().$_type === "image")
199
- return n.getConfig().$_imageUrl || null;
194
+ const e = t.getCanvasNodeById(o[0]);
195
+ if (!e) return null;
196
+ if (e.getConfig().$_type === "image")
197
+ return e.getConfig().$_imageUrl || null;
200
198
  }
201
- return t.exportSelectionAsImage();
199
+ return t.exportSelectionAsImage(n);
200
+ }
201
+ function U(t) {
202
+ return t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
203
+ }
204
+ function M(t, n, o, e, r, i, s) {
205
+ return `<p><span style="${[
206
+ `font-family: ${n}`,
207
+ `font-size: ${o}px`,
208
+ `letter-spacing: ${e}px`,
209
+ `font-weight: ${r}`,
210
+ `color: ${i}`,
211
+ `line-height: ${s}`
212
+ ].join("; ")}">${U(t)}</span></p>`;
213
+ }
214
+ const C = /* @__PURE__ */ new Set();
215
+ function X(t, n, o) {
216
+ const e = `${n}-${o || "all"}`;
217
+ if (C.has(e)) return;
218
+ C.add(e);
219
+ const r = o ? `:wght@${o}` : "", i = `https://fonts.googleapis.com/css2?family=${encodeURIComponent(t)}${r}&display=swap`, s = document.createElement("link");
220
+ s.rel = "stylesheet", s.href = i, s.onerror = () => {
221
+ const l = `https://cdn.jsdelivr.net/fontsource/fonts/${n}@latest/index.css`, a = document.createElement("link");
222
+ a.rel = "stylesheet", a.href = l, document.head.appendChild(a);
223
+ }, document.head.appendChild(s);
224
+ }
225
+ function b(t, n) {
226
+ if (!t) return;
227
+ X(n.fontFamily, n.fontId, n.fontWeight);
228
+ const o = w(), e = M(
229
+ n.text,
230
+ n.fontFamily,
231
+ n.fontSize,
232
+ n.letterSpacing,
233
+ n.fontWeight,
234
+ n.fontColor,
235
+ n.lineHeight
236
+ ), r = {
237
+ id: o,
238
+ $_type: "rich-text",
239
+ x: n.position.x,
240
+ y: n.position.y,
241
+ $_htmlContent: e,
242
+ scaleWhenCreate: 1,
243
+ image: void 0
244
+ };
245
+ return t.createNodes([r], !0), o;
246
+ }
247
+ function z(t, n, o) {
248
+ t && t.updateNodes([n], { $_imageUrl: o });
249
+ }
250
+ async function P(t, n) {
251
+ if (!t) return null;
252
+ const o = t.getCanvasNodeById(n);
253
+ if (!o) return null;
254
+ const e = o.getConfig();
255
+ if (e.$_type !== "font-replace" || !e.$_relativeBox) return null;
256
+ const r = e.$_parentId;
257
+ if (!r) return null;
258
+ const i = t.getNodeConfigById(r);
259
+ if (!i || i.$_type !== "image" || !i.$_imageUrl)
260
+ return null;
261
+ const { start: s, end: l } = e.$_relativeBox, a = await new Promise((d) => {
262
+ const c = new window.Image();
263
+ c.crossOrigin = "anonymous", c.onload = () => {
264
+ const h = c.naturalWidth, g = c.naturalHeight, u = s.ratioX * h, y = s.ratioY * g, f = (l.ratioX - s.ratioX) * h, m = (l.ratioY - s.ratioY) * g, x = document.createElement("canvas");
265
+ x.width = f, x.height = m;
266
+ const $ = x.getContext("2d");
267
+ if (!$) {
268
+ d(null);
269
+ return;
270
+ }
271
+ $.drawImage(c, u, y, f, m, 0, 0, f, m), d({
272
+ regionImage: x.toDataURL("image/png"),
273
+ naturalWidth: h,
274
+ naturalHeight: g
275
+ });
276
+ }, c.onerror = () => d(null), c.src = i.$_imageUrl;
277
+ });
278
+ return a ? {
279
+ region_image: a.regionImage,
280
+ edit_urls: [i.$_imageUrl],
281
+ prompt: "去掉选区内的文字,保持背景完整",
282
+ relative_box: { start: s, end: l },
283
+ image_node_id: r,
284
+ font_replace_node_id: n,
285
+ natural_width: a.naturalWidth,
286
+ natural_height: a.naturalHeight
287
+ } : null;
202
288
  }
203
289
  export {
204
- E as calculateBottomLeftOfCanvasContent,
205
- z as exportMarkedRegion,
206
- R as exportSelectionAsImage,
207
- L as insertImageBesideContent,
290
+ v as calculateBottomLeftOfCanvasContent,
291
+ b as createRichTextFromFontReplace,
292
+ P as exportFontReplaceRegion,
293
+ F as exportMarkedRegion,
294
+ W as exportSelectionAsImage,
295
+ H as insertImageBesideContent,
208
296
  S as insertImagesAtPosition,
209
- X as insertLoadingImageBesideSelection,
210
- A as insertVideoAtPosition,
211
- V as insertVideoBesideContent,
212
- Y as replaceLoadingImageNode
297
+ L as insertLoadingImageBesideSelection,
298
+ T as insertVideoAtPosition,
299
+ k as insertVideoBesideContent,
300
+ z as replaceImageUrl,
301
+ R as replaceLoadingImageNode
213
302
  };
@@ -7,15 +7,22 @@ const i = {
7
7
  html: "html_intrinsic",
8
8
  text: "text_intrinsic",
9
9
  richText: "rich_text_intrinsic",
10
- video: "video_intrinsic"
11
- }, t = {
10
+ video: "video_intrinsic",
11
+ star: "star_intrinsic",
12
+ ellipse: "ellipse_intrinsic",
13
+ polygon: "polygon_intrinsic",
14
+ arrow: "arrow_intrinsic",
15
+ brush: "brush_intrinsic",
16
+ imageBrush: "image_brush_intrinsic",
17
+ fontReplace: "font_replace_intrinsic"
18
+ }, n = {
12
19
  CORNER_RADIUS: 6,
13
20
  MIN_SIZE: 10
14
- }, e = {
21
+ }, t = {
15
22
  MIN_SIZE: 10
16
23
  };
17
24
  export {
18
- e as I,
25
+ t as I,
19
26
  i as N,
20
- t as R
27
+ n as R
21
28
  };