@pooder/vue 4.2.6 → 4.2.7

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/index.es.js CHANGED
@@ -1,106 +1,234 @@
1
- import { defineComponent as O, ref as M, onMounted as K, onUnmounted as Y, createElementBlock as R, openBlock as X, createElementVNode as Q, provide as Z, createVNode as ee } from "vue";
2
- import { Pooder as te } from "@pooder/core";
1
+ import { defineComponent as J, ref as H, onMounted as he, onUnmounted as G, createElementBlock as $, openBlock as q, createElementVNode as fe, provide as pe, createVNode as we } from "vue";
2
+ import { Pooder as ye } from "@pooder/core";
3
3
  export * from "@pooder/core";
4
- import { CanvasService as ne, SceneLayoutService as ie, SceneVisibilityService as oe, BackgroundTool as ae, SizeTool as re, ImageTool as ce, WhiteInkTool as se, MirrorTool as de, DielineTool as ue, RulerTool as me, FeatureTool as ge } from "@pooder/kit";
4
+ import { CanvasService as ve, SceneLayoutService as be, SceneVisibilityService as xe, BackgroundTool as Se, SizeTool as Ce, ImageTool as Ne, WhiteInkTool as Ie, MirrorTool as Fe, DielineTool as Be, RulerTool as Me, FeatureTool as De } from "@pooder/kit";
5
5
  export * from "@pooder/kit";
6
- const le = /* @__PURE__ */ O({
6
+ const Ee = /* @__PURE__ */ J({
7
7
  __name: "CanvasArea",
8
8
  emits: ["canvas-ready", "resize"],
9
- setup(p, { emit: v }) {
10
- const g = v, a = M(null), c = M(null);
11
- let d = null;
12
- return K(() => {
13
- if (a.value && c.value) {
14
- const { clientWidth: f, clientHeight: C } = a.value;
15
- c.value.width = f, c.value.height = C, g("canvas-ready", c.value), d = new ResizeObserver((w) => {
16
- for (const b of w) {
17
- const { width: S, height: x } = b.contentRect;
18
- g("resize", S, x);
9
+ setup(I, { emit: N }) {
10
+ const C = N, u = H(null), g = H(null);
11
+ let c = null;
12
+ return he(() => {
13
+ if (u.value && g.value) {
14
+ const { clientWidth: S, clientHeight: F } = u.value;
15
+ g.value.width = S, g.value.height = F, C("canvas-ready", g.value), c = new ResizeObserver((z) => {
16
+ for (const _ of z) {
17
+ const { width: Y, height: X } = _.contentRect;
18
+ C("resize", Y, X);
19
19
  }
20
- }), d.observe(a.value);
20
+ }), c.observe(u.value);
21
21
  }
22
- }), Y(() => {
23
- d && d.disconnect();
24
- }), (f, C) => (X(), R("div", {
22
+ }), G(() => {
23
+ c && c.disconnect();
24
+ }), (S, F) => (q(), $("div", {
25
25
  ref_key: "container",
26
- ref: a,
26
+ ref: u,
27
27
  class: "pooder-canvas-area"
28
28
  }, [
29
- Q("canvas", {
29
+ fe("canvas", {
30
30
  ref_key: "canvas",
31
- ref: c
31
+ ref: g
32
32
  }, null, 512)
33
33
  ], 512));
34
34
  }
35
- }), A = (p, v) => {
36
- const g = p.__vccOpts || p;
37
- for (const [a, c] of v)
38
- g[a] = c;
39
- return g;
40
- }, he = /* @__PURE__ */ A(le, [["__scopeId", "data-v-203ff8d9"]]), fe = { class: "pooder-editor" }, T = "SceneLayoutService", B = "SceneVisibilityService", ve = "image.user", pe = /* @__PURE__ */ O({
35
+ }), K = (I, N) => {
36
+ const C = I.__vccOpts || I;
37
+ for (const [u, g] of N)
38
+ C[u] = g;
39
+ return C;
40
+ }, ze = /* @__PURE__ */ K(Ee, [["__scopeId", "data-v-9668bbd7"]]), _e = { class: "pooder-editor" }, j = "SceneLayoutService", V = "SceneVisibilityService", Ye = "image.user", Xe = "pooder.kit.image", Pe = /* @__PURE__ */ J({
41
41
  __name: "PooderEditor",
42
42
  emits: ["image-change"],
43
- setup(p, { expose: v, emit: g }) {
44
- const a = new te();
45
- Z("pooder", a);
46
- const c = a.getService("CommandService"), d = a.getService("ConfigurationService"), f = a.getService("WorkbenchService"), C = g, w = d.onAnyChange((e) => {
47
- e.key === "image.items" && C("image-change", e.value);
48
- }), b = (e) => {
49
- d.import(e);
50
- }, S = () => d.export(), x = () => d.get("image.items", []), k = async (e) => {
43
+ setup(I, { expose: N, emit: C }) {
44
+ const u = new ye();
45
+ pe("pooder", u);
46
+ const g = u.getService("CommandService"), c = u.getService("ConfigurationService"), S = u.getService("WorkbenchService"), F = C, z = c.onAnyChange((e) => {
47
+ e.key === "image.items" && F("image-change", e.value);
48
+ }), _ = (e) => {
49
+ c.import(e);
50
+ }, Y = () => c.export(), X = () => c.get("image.items", []), Q = async (e) => {
51
51
  try {
52
- const t = await c.executeCommand(
52
+ const t = await g.executeCommand(
53
53
  "exportCutImage",
54
54
  e
55
55
  );
56
56
  return t || console.warn("[PooderEditor] generateCutImage returned null", {
57
57
  options: e,
58
- imageCount: (d.get("image.items") || []).length,
59
- hasCanvasService: !!a.getService("CanvasService")
58
+ imageCount: (c.get("image.items") || []).length,
59
+ hasCanvasService: !!u.getService("CanvasService")
60
60
  }), t;
61
61
  } catch (t) {
62
62
  throw console.error("[PooderEditor] generateCutImage failed", t), t;
63
63
  }
64
- }, _ = async (e, t) => await c.executeCommand("upsertImage", e, {
64
+ }, O = async (e, t) => await g.executeCommand("upsertImage", e, {
65
65
  id: t?.id,
66
66
  mode: t?.mode,
67
67
  addOptions: t?.addOptions,
68
68
  fitOnAdd: t?.fitOnAdd
69
- }), I = async (e, t) => (await _(e, {
69
+ }), U = async (e, t) => (await O(e, {
70
70
  mode: "add",
71
71
  addOptions: t,
72
72
  fitOnAdd: !0
73
- })).id, W = async (e, t) => await c.executeCommand("updateImage", e, t), z = async () => await c.executeCommand("clearImages"), N = async (e) => await c.executeCommand(
73
+ })).id, Z = async (e, t) => await g.executeCommand("updateImage", e, t), ee = async () => await g.executeCommand("clearImages"), B = async (e) => await g.executeCommand(
74
74
  "exportUserCroppedImage",
75
75
  e
76
- ), P = async (e, t) => await c.executeCommand("focusImage", e, t), D = (e) => Math.max(-1, Math.min(2, e)), H = (e) => {
76
+ ), te = async (e, t) => await g.executeCommand("focusImage", e, t), M = (e) => Math.max(-1, Math.min(2, e)), k = (e) => {
77
77
  const t = e?.cutRect;
78
78
  if (!t) return null;
79
- const n = Number(t.width), i = Number(t.height), r = Number(t.left), o = Number(t.top);
80
- return !Number.isFinite(n) || !Number.isFinite(i) || !Number.isFinite(r) || !Number.isFinite(o) || n <= 0 || i <= 0 ? null : { left: r, top: o, width: n, height: i };
81
- }, E = (e) => {
79
+ const i = Number(t.width), n = Number(t.height), d = Number(t.left), r = Number(t.top);
80
+ return !Number.isFinite(i) || !Number.isFinite(n) || !Number.isFinite(d) || !Number.isFinite(r) || i <= 0 || n <= 0 ? null : { left: d, top: r, width: i, height: n };
81
+ }, D = (e) => {
82
82
  if (!e) return [];
83
- const t = e.canvas.getObjects(), n = [];
84
- for (const i of t) {
85
- if (i?.data?.layerId !== ve) continue;
86
- const r = i?.data?.id;
87
- if (typeof r != "string") continue;
88
- const o = i.getCenterPoint ? i.getCenterPoint() : null, s = Number(o?.x ?? i.left), u = Number(o?.y ?? i.top), m = Number(i.scaleX), l = Number(i.width), h = Number(i.height);
89
- !Number.isFinite(s) || !Number.isFinite(u) || !Number.isFinite(m) || !Number.isFinite(l) || !Number.isFinite(h) || l <= 0 || h <= 0 || n.push({
90
- id: r,
91
- centerX: s,
92
- centerY: u,
93
- objectScale: m,
94
- sourceWidth: l,
83
+ const t = e.canvas.getObjects(), i = [];
84
+ for (const n of t) {
85
+ if (n?.data?.layerId !== Ye) continue;
86
+ const d = n?.data?.id;
87
+ if (typeof d != "string") continue;
88
+ const r = n.getCenterPoint ? n.getCenterPoint() : null, m = Number(r?.x ?? n.left), s = Number(r?.y ?? n.top), a = Number(n.scaleX), o = Number(n.width), h = Number(n.height);
89
+ !Number.isFinite(m) || !Number.isFinite(s) || !Number.isFinite(a) || !Number.isFinite(o) || !Number.isFinite(h) || o <= 0 || h <= 0 || i.push({
90
+ id: d,
91
+ centerX: m,
92
+ centerY: s,
93
+ objectScale: a,
94
+ sourceWidth: o,
95
95
  sourceHeight: h
96
96
  });
97
97
  }
98
- return n;
99
- }, y = (e) => {
100
- d.update("dieline.shape", "custom"), d.update("dieline.pathData", e.pathData), d.update("dieline.features", []), d.update("size.cutMode", "trim"), d.update("size.cutMarginMm", 0);
101
- }, j = (e, t) => {
102
- const n = e.rawBounds || e.baseBounds || null;
103
- if (!n)
98
+ return i;
99
+ }, A = (e, t) => {
100
+ if (!t || t.length === 0) return e;
101
+ const i = new Set(t);
102
+ return e.filter((n) => i.has(n.id));
103
+ }, P = (e) => {
104
+ c.update("dieline.shape", "custom"), c.update("dieline.pathData", e.pathData), c.update("dieline.features", []), c.update("size.cutMode", "trim"), c.update("size.cutMarginMm", 0);
105
+ }, E = (e) => !!e && Number.isFinite(e.x) && Number.isFinite(e.y) && Number.isFinite(e.width) && Number.isFinite(e.height) && e.width > 0 && e.height > 0, ie = (e) => {
106
+ const t = e.baseBounds || e.rawBounds, i = e.rawBounds || e.baseBounds;
107
+ if (!E(t) || !E(i)) return null;
108
+ const n = Number(c.get("size.actualWidthMm", 0)), d = Number(c.get("size.actualHeightMm", 0)), r = Math.max(n, d), m = Math.max(t.width, t.height), s = Math.max(i.width, i.height);
109
+ if (!Number.isFinite(r) || !Number.isFinite(m) || !Number.isFinite(s) || r <= 0 || m <= 0 || s <= 0)
110
+ return null;
111
+ const a = r / s, o = i.width * a, h = i.height * a;
112
+ return !Number.isFinite(o) || !Number.isFinite(h) || o <= 0 || h <= 0 ? null : {
113
+ widthMm: o,
114
+ heightMm: h,
115
+ scale: a,
116
+ sizeLongEdgeMm: r,
117
+ baseLongEdge: m,
118
+ appliedBounds: i,
119
+ baseBounds: t
120
+ };
121
+ }, ne = (e, t = !1) => {
122
+ const i = ie(e);
123
+ return i ? (c.update("size.actualWidthMm", i.widthMm), c.update("size.actualHeightMm", i.heightMm), c.update(
124
+ "size.aspectRatio",
125
+ i.widthMm / Math.max(1e-3, i.heightMm)
126
+ ), t && console.info("[PooderEditor] detectDielineFromFrame size mapping", {
127
+ mappedSize: i,
128
+ rawBounds: e.rawBounds,
129
+ baseBounds: e.baseBounds
130
+ }), i) : null;
131
+ }, R = (e) => {
132
+ if (!e) return null;
133
+ const t = Number(e.left), i = Number(e.top), n = Number(e.width), d = Number(e.height), r = Number(e.centerX), m = Number(e.centerY);
134
+ return !Number.isFinite(t) || !Number.isFinite(i) || !Number.isFinite(n) || !Number.isFinite(d) || !Number.isFinite(r) || !Number.isFinite(m) ? null : { left: t, top: i, width: n, height: d, centerX: r, centerY: m };
135
+ }, W = (e) => {
136
+ if (!e) return null;
137
+ const t = Number(e.scale), i = Number(e.canvasWidth), n = Number(e.canvasHeight);
138
+ return !Number.isFinite(t) || !Number.isFinite(i) || !Number.isFinite(n) ? null : {
139
+ scale: t,
140
+ canvasWidth: i,
141
+ canvasHeight: n,
142
+ viewPadding: c.get("size.viewPadding"),
143
+ trimRect: R(e.trimRect),
144
+ cutRect: R(e.cutRect),
145
+ bleedRect: R(e.bleedRect)
146
+ };
147
+ }, re = (e, t, i) => {
148
+ const n = e.rawBounds || e.baseBounds;
149
+ return !E(n) || !Number.isFinite(t) || !Number.isFinite(i) || t <= 0 || i <= 0 ? null : {
150
+ bounds: n,
151
+ offsetX: n.x + n.width / 2 - t / 2,
152
+ offsetY: n.y + n.height / 2 - i / 2
153
+ };
154
+ }, L = (e) => (e || []).map((t) => ({
155
+ id: String(t?.id ?? ""),
156
+ left: Number(t?.left ?? 0),
157
+ top: Number(t?.top ?? 0),
158
+ scale: Number(t?.scale ?? 1),
159
+ angle: Number(t?.angle ?? 0),
160
+ url: typeof t?.url == "string" ? t.url : "",
161
+ sourceUrl: typeof t?.sourceUrl == "string" ? t.sourceUrl : "",
162
+ committedUrl: typeof t?.committedUrl == "string" ? t.committedUrl : ""
163
+ })), oe = async () => {
164
+ try {
165
+ const e = await g.executeCommand("getWorkingImages") || [], t = c.get("image.items", []) || [], i = L(e), n = L(t);
166
+ return JSON.stringify(i) !== JSON.stringify(n);
167
+ } catch {
168
+ return !1;
169
+ }
170
+ }, ae = async (e = !1) => {
171
+ const t = typeof S?.activeToolId == "string" ? String(S.activeToolId) : null;
172
+ if (t !== Xe)
173
+ return e && console.info("[PooderEditor] detectDielineFromFrame image update target", {
174
+ activeToolId: t,
175
+ target: "config",
176
+ reason: "image-tool-inactive"
177
+ }), "config";
178
+ const i = await oe(), n = i ? "working" : "config";
179
+ return e && console.info("[PooderEditor] detectDielineFromFrame image update target", {
180
+ activeToolId: t,
181
+ workingDirty: i,
182
+ target: n,
183
+ reason: i ? "working-session-dirty-follow-working" : "working-session-clean-update-config"
184
+ }), n;
185
+ }, se = async (e, t, i = !1) => {
186
+ const n = [...new Set(e)].filter(
187
+ (a) => typeof a == "string" && a.length > 0
188
+ );
189
+ if (!n.length) return [];
190
+ const d = /* @__PURE__ */ new Map();
191
+ for (const a of n) {
192
+ const o = await B({
193
+ multiplier: t?.multiplier ?? 2,
194
+ format: t?.format ?? "png",
195
+ imageIds: [a]
196
+ });
197
+ o?.url && d.set(a, {
198
+ url: o.url,
199
+ width: o.width,
200
+ height: o.height
201
+ });
202
+ }
203
+ if (!d.size) return [];
204
+ const m = (Array.isArray(c.get("image.items", [])) ? c.get("image.items", []) : []).map((a) => {
205
+ const o = typeof a?.id == "string" ? a.id : "", h = d.get(o);
206
+ if (!h) return a;
207
+ const b = typeof a?.sourceUrl == "string" && a.sourceUrl.length > 0 ? a.sourceUrl : typeof a?.url == "string" ? a.url : "";
208
+ return {
209
+ ...a,
210
+ url: h.url,
211
+ sourceUrl: b,
212
+ committedUrl: h.url
213
+ };
214
+ });
215
+ c.update("image.items", m);
216
+ const s = n.map((a) => {
217
+ const o = d.get(a);
218
+ return o ? {
219
+ id: a,
220
+ width: o.width,
221
+ height: o.height
222
+ } : null;
223
+ }).filter((a) => !!a);
224
+ return i && console.info("[PooderEditor] detectDieline committed image sync", {
225
+ imageIds: n,
226
+ synced: s,
227
+ count: s.length
228
+ }), s;
229
+ }, ce = (e, t) => {
230
+ const i = e.rawBounds || e.baseBounds || null;
231
+ if (!i)
104
232
  return {
105
233
  sourceWidth: t.width,
106
234
  sourceHeight: t.height,
@@ -110,76 +238,171 @@ const le = /* @__PURE__ */ O({
110
238
  coverageX: 0,
111
239
  coverageY: 0
112
240
  };
113
- const i = t.width / 2, r = t.height / 2, o = n.x + n.width / 2, s = n.y + n.height / 2;
241
+ const n = t.width / 2, d = t.height / 2, r = i.x + i.width / 2, m = i.y + i.height / 2;
114
242
  return {
115
243
  sourceWidth: t.width,
116
244
  sourceHeight: t.height,
117
- detectedBounds: n,
118
- centerOffsetX: o - i,
119
- centerOffsetY: s - r,
120
- coverageX: t.width > 0 ? n.width / t.width : 0,
121
- coverageY: t.height > 0 ? n.height / t.height : 0
245
+ detectedBounds: i,
246
+ centerOffsetX: r - n,
247
+ centerOffsetY: m - d,
248
+ coverageX: t.width > 0 ? i.width / t.width : 0,
249
+ coverageY: t.height > 0 ? i.height / t.height : 0
122
250
  };
123
- }, L = (e, t) => {
124
- const n = e.rawBounds || e.baseBounds, i = Number(e.imageWidth ?? 0), r = Number(e.imageHeight ?? 0);
125
- if (!n || !Number.isFinite(n.x) || !Number.isFinite(n.y) || !Number.isFinite(n.width) || !Number.isFinite(n.height) || n.width <= 0 || n.height <= 0 || i <= 0 || r <= 0)
251
+ }, de = (e, t) => {
252
+ const i = e.rawBounds || e.baseBounds, n = Number(e.imageWidth ?? 0), d = Number(e.imageHeight ?? 0);
253
+ if (!i || !Number.isFinite(i.x) || !Number.isFinite(i.y) || !Number.isFinite(i.width) || !Number.isFinite(i.height) || i.width <= 0 || i.height <= 0 || n <= 0 || d <= 0)
126
254
  return { shiftX: 0, shiftY: 0 };
127
- const o = t.width / n.width, s = t.height / n.height, u = n.x + n.width / 2, m = n.y + n.height / 2, l = i / 2, h = r / 2;
255
+ const r = t.width / i.width, m = t.height / i.height, s = i.x + i.width / 2, a = i.y + i.height / 2, o = n / 2, h = d / 2;
128
256
  return {
129
- shiftX: (u - l) * o,
130
- shiftY: (m - h) * s
257
+ shiftX: (s - o) * r,
258
+ shiftY: (a - h) * m
131
259
  };
132
- }, F = async (e, t, n = !1, i = "auto") => {
260
+ }, T = async (e, t, i = !1, n = "auto") => {
133
261
  if (!t.length) return;
134
- const r = await c.executeCommand("getSceneLayout"), o = H(r);
262
+ const d = await g.executeCommand("getSceneLayout"), r = k(d);
263
+ if (!r) return;
264
+ const { shiftX: m, shiftY: s } = de(e, r), a = e.rawBounds, o = e.baseBounds, h = Number(e.imageWidth ?? 0), b = Number(e.imageHeight ?? 0);
265
+ if (i) {
266
+ const l = (f) => {
267
+ if (!E(f) || h <= 0 || b <= 0)
268
+ return null;
269
+ const v = f.x + f.width / 2 - h / 2, p = f.y + f.height / 2 - b / 2;
270
+ return {
271
+ dx: v,
272
+ dy: p,
273
+ byBounds: {
274
+ shiftX: v * (r.width / Math.max(1, f.width)),
275
+ shiftY: p * (r.height / Math.max(1, f.height))
276
+ },
277
+ byImage: {
278
+ shiftX: v * (r.width / Math.max(1, h)),
279
+ shiftY: p * (r.height / Math.max(1, b))
280
+ }
281
+ };
282
+ }, w = l(a), y = l(o);
283
+ console.info("[PooderEditor] detectDieline alignment", {
284
+ frame: r,
285
+ shiftX: m,
286
+ shiftY: s,
287
+ shiftNormalized: {
288
+ x: r.width > 0 ? m / r.width : 0,
289
+ y: r.height > 0 ? s / r.height : 0
290
+ },
291
+ snapshotCount: t.length,
292
+ baseBounds: o,
293
+ rawBounds: a,
294
+ imageWidth: h,
295
+ imageHeight: b,
296
+ shiftCandidates: {
297
+ raw: w,
298
+ base: y
299
+ },
300
+ shiftRawByBoundsX: w?.byBounds?.shiftX,
301
+ shiftRawByBoundsY: w?.byBounds?.shiftY,
302
+ shiftRawByImageX: w?.byImage?.shiftX,
303
+ shiftRawByImageY: w?.byImage?.shiftY,
304
+ shiftBaseByBoundsX: y?.byBounds?.shiftX,
305
+ shiftBaseByBoundsY: y?.byBounds?.shiftY,
306
+ shiftBaseByImageX: y?.byImage?.shiftX,
307
+ shiftBaseByImageY: y?.byImage?.shiftY
308
+ });
309
+ }
310
+ for (const l of t) {
311
+ const w = Math.max(
312
+ r.width / Math.max(1, l.sourceWidth),
313
+ r.height / Math.max(1, l.sourceHeight)
314
+ ), y = Math.max(0.05, l.objectScale / w), f = l.centerX - m, v = l.centerY - s, p = M(
315
+ (f - r.left) / Math.max(1, r.width)
316
+ ), x = M(
317
+ (v - r.top) / Math.max(1, r.height)
318
+ );
319
+ i && console.info("[PooderEditor] detectDieline alignment item", {
320
+ id: l.id,
321
+ target: n,
322
+ frame: r,
323
+ sourceSize: {
324
+ width: l.sourceWidth,
325
+ height: l.sourceHeight
326
+ },
327
+ objectScale: l.objectScale,
328
+ coverScale: w,
329
+ targetScale: y,
330
+ centerBefore: { x: l.centerX, y: l.centerY },
331
+ centerAfter: { x: f, y: v },
332
+ normalizedAfter: { left: p, top: x }
333
+ }), await g.executeCommand(
334
+ "updateImage",
335
+ l.id,
336
+ {
337
+ scale: y,
338
+ left: p,
339
+ top: x
340
+ },
341
+ {
342
+ target: n
343
+ }
344
+ );
345
+ }
346
+ }, me = async (e, t, i, n, d, r = !1, m = "auto", s = "offset") => {
347
+ if (!d.length || !Number.isFinite(e) || !Number.isFinite(t) || !Number.isFinite(i) || !Number.isFinite(n) || i <= 0 || n <= 0)
348
+ return;
349
+ const a = await g.executeCommand("getSceneLayout"), o = k(a);
135
350
  if (!o) return;
136
- const { shiftX: s, shiftY: u } = L(e, o);
137
- n && console.info("[PooderEditor] detectDieline alignment", {
351
+ const h = e * o.width / i, b = t * o.height / n;
352
+ r && console.info("[PooderEditor] detectDieline direct compensation", {
353
+ label: s,
354
+ target: m,
355
+ sourceWidth: i,
356
+ sourceHeight: n,
357
+ offsetX: e,
358
+ offsetY: t,
138
359
  frame: o,
139
- shiftX: s,
140
- shiftY: u,
141
- snapshotCount: t.length,
142
- baseBounds: e.baseBounds,
143
- rawBounds: e.rawBounds,
144
- imageWidth: e.imageWidth,
145
- imageHeight: e.imageHeight
360
+ shiftX: h,
361
+ shiftY: b,
362
+ shiftNormalized: {
363
+ x: o.width > 0 ? h / o.width : 0,
364
+ y: o.height > 0 ? b / o.height : 0
365
+ },
366
+ snapshotCount: d.length
146
367
  });
147
- for (const m of t) {
148
- const l = Math.max(
149
- o.width / Math.max(1, m.sourceWidth),
150
- o.height / Math.max(1, m.sourceHeight)
151
- ), h = Math.max(0.05, m.objectScale / l), q = m.centerX - s, G = m.centerY - u, J = D(
152
- (q - o.left) / Math.max(1, o.width)
153
- ), $ = D(
154
- (G - o.top) / Math.max(1, o.height)
368
+ for (const l of d) {
369
+ const w = l.centerX - h, y = l.centerY - b, f = M(
370
+ (w - o.left) / Math.max(1, o.width)
371
+ ), v = M(
372
+ (y - o.top) / Math.max(1, o.height)
155
373
  );
156
- await c.executeCommand(
374
+ r && console.info("[PooderEditor] detectDieline direct compensation item", {
375
+ label: s,
376
+ id: l.id,
377
+ centerBefore: { x: l.centerX, y: l.centerY },
378
+ centerAfter: { x: w, y },
379
+ normalizedAfter: { left: f, top: v }
380
+ }), await g.executeCommand(
157
381
  "updateImage",
158
- m.id,
382
+ l.id,
159
383
  {
160
- scale: h,
161
- left: J,
162
- top: $
384
+ left: f,
385
+ top: v
163
386
  },
164
387
  {
165
- target: i
388
+ target: m
166
389
  }
167
390
  );
168
391
  }
169
392
  };
170
- v({
171
- importConfig: b,
172
- exportConfig: S,
173
- getImages: x,
174
- generateCutImage: k,
175
- addImage: I,
176
- upsertImage: _,
177
- updateImage: W,
178
- clearImages: z,
179
- exportUserCroppedImage: N,
180
- focusImage: P,
393
+ N({
394
+ importConfig: _,
395
+ exportConfig: Y,
396
+ getImages: X,
397
+ generateCutImage: Q,
398
+ addImage: U,
399
+ upsertImage: O,
400
+ updateImage: Z,
401
+ clearImages: ee,
402
+ exportUserCroppedImage: B,
403
+ focusImage: te,
181
404
  detectDieline: async (e) => {
182
- const t = a.getService("CanvasService"), n = E(t), i = await c.executeCommand("detectEdge", e, {
405
+ const t = u.getService("CanvasService"), i = D(t), n = await g.executeCommand("detectEdge", e, {
183
406
  expand: 10,
184
407
  // 安全距离(像素)
185
408
  smoothing: !0,
@@ -187,126 +410,226 @@ const le = /* @__PURE__ */ O({
187
410
  simplifyTolerance: 2
188
411
  // 平滑度容差,值越大越圆润
189
412
  });
190
- if (i) {
191
- y(i);
192
- const o = (d.get("image.items") || []).find((s) => s.url === e);
193
- if (o?.id) {
194
- const s = n.filter(
195
- (u) => u.id === o.id
413
+ if (n) {
414
+ P(n);
415
+ const r = (c.get("image.items") || []).find((m) => m.url === e);
416
+ if (r?.id) {
417
+ const m = i.filter(
418
+ (s) => s.id === r.id
196
419
  );
197
- await F(i, s);
420
+ await T(n, m);
198
421
  }
199
- return i.pathData;
422
+ return n.pathData;
200
423
  }
201
424
  return null;
202
425
  },
203
426
  detectDielineFromFrame: async (e) => {
204
- const t = e?.detect?.debug === !0, n = e?.inspect?.includeCroppedImage === !0, i = e?.inspect?.includeDiagnostics === !0, r = await N({
427
+ const t = e?.detect?.debug === !0, i = e?.inspect?.includeCroppedImage === !0, n = e?.inspect?.includeDiagnostics === !0, d = u.getService("CanvasService"), r = D(d);
428
+ let m = null;
429
+ if (t)
430
+ try {
431
+ m = await g.executeCommand("getSceneLayout");
432
+ } catch (o) {
433
+ console.warn("[PooderEditor] detectDielineFromFrame layout(before) failed", {
434
+ error: o
435
+ });
436
+ }
437
+ const s = await B({
205
438
  multiplier: e?.export?.multiplier ?? 2,
206
439
  format: e?.export?.format ?? "png",
207
440
  imageIds: e?.export?.imageIds
208
- }), o = r?.url;
209
- if (!o) return null;
441
+ }), a = s?.url;
442
+ if (!a) return null;
210
443
  try {
211
444
  t && console.info("[PooderEditor] detectDielineFromFrame sourceImage", {
212
- width: r.width,
213
- height: r.height,
214
- format: r.format,
215
- multiplier: r.multiplier,
216
- imageCount: r.imageIds.length
445
+ width: s.width,
446
+ height: s.height,
447
+ format: s.format,
448
+ multiplier: s.multiplier,
449
+ imageCount: s.imageIds.length,
450
+ size: {
451
+ actualWidthMm: c.get("size.actualWidthMm"),
452
+ actualHeightMm: c.get("size.actualHeightMm"),
453
+ viewPadding: c.get("size.viewPadding")
454
+ },
455
+ layoutBeforeCommit: W(m),
456
+ imageSnapshots: r.map((p) => ({
457
+ id: p.id,
458
+ centerX: p.centerX,
459
+ centerY: p.centerY,
460
+ objectScale: p.objectScale,
461
+ sourceWidth: p.sourceWidth,
462
+ sourceHeight: p.sourceHeight
463
+ }))
217
464
  });
218
- const s = await c.executeCommand("detectEdge", o, {
465
+ const o = await g.executeCommand("detectEdge", a, {
219
466
  expand: e?.detect?.expand ?? 0,
220
467
  smoothing: e?.detect?.smoothing ?? !0,
221
468
  simplifyTolerance: e?.detect?.simplifyTolerance ?? 2,
222
469
  threshold: e?.detect?.threshold,
223
- morphologyRadius: e?.detect?.morphologyRadius,
224
- connectRadiusMax: e?.detect?.connectRadiusMax,
225
- maskMode: e?.detect?.maskMode,
226
- whiteThreshold: e?.detect?.whiteThreshold,
227
- alphaOpaqueCutoff: e?.detect?.alphaOpaqueCutoff,
228
- noChannels: e?.detect?.noChannels,
229
- componentMode: e?.detect?.componentMode ?? "all",
230
- minComponentArea: e?.detect?.minComponentArea,
231
- forceConnected: e?.detect?.forceConnected ?? !0,
232
470
  debug: t
233
471
  });
234
- if (!s) return null;
235
- const u = j(s, r);
236
- return t && console.info(
472
+ if (!o) return null;
473
+ const h = ce(o, s);
474
+ if (t && console.info(
237
475
  "[PooderEditor] detectDielineFromFrame diagnostics",
238
- u
239
- ), e?.commit === !1 ? {
240
- ...s,
241
- ...n ? { sourceImage: r } : {},
242
- ...i ? { diagnostics: u } : {}
243
- } : (y(s), {
244
- ...s,
245
- ...n ? { sourceImage: r } : {},
246
- ...i ? { diagnostics: u } : {}
247
- });
476
+ h
477
+ ), e?.commit === !1)
478
+ return {
479
+ ...o,
480
+ ...i ? { sourceImage: s } : {},
481
+ ...n ? { diagnostics: h } : {}
482
+ };
483
+ P(o);
484
+ const b = ne(o, t), l = await ae(t);
485
+ let w = [];
486
+ const y = A(r, s.imageIds);
487
+ await T(
488
+ o,
489
+ y,
490
+ t,
491
+ l
492
+ );
493
+ const f = await B({
494
+ multiplier: e?.export?.multiplier ?? 2,
495
+ format: e?.export?.format ?? "png",
496
+ imageIds: s.imageIds
497
+ }), v = f?.url;
498
+ if (v)
499
+ try {
500
+ const p = await g.executeCommand("detectEdge", v, {
501
+ expand: e?.detect?.expand ?? 0,
502
+ smoothing: e?.detect?.smoothing ?? !0,
503
+ simplifyTolerance: e?.detect?.simplifyTolerance ?? 2,
504
+ threshold: e?.detect?.threshold,
505
+ debug: t
506
+ });
507
+ if (p) {
508
+ const x = re(
509
+ p,
510
+ f.width,
511
+ f.height
512
+ );
513
+ if (t && console.info("[PooderEditor] detectDieline verify pass", {
514
+ sourceWidth: f.width,
515
+ sourceHeight: f.height,
516
+ offset: x,
517
+ imageIds: s.imageIds
518
+ }), x && (Math.abs(x.offsetX) > 0.01 || Math.abs(x.offsetY) > 0.01)) {
519
+ const le = A(
520
+ D(d),
521
+ s.imageIds
522
+ );
523
+ await me(
524
+ x.offsetX,
525
+ x.offsetY,
526
+ f.width,
527
+ f.height,
528
+ le,
529
+ t,
530
+ l,
531
+ "verify-pass"
532
+ );
533
+ }
534
+ }
535
+ } finally {
536
+ URL.revokeObjectURL(v);
537
+ }
538
+ if (l === "config" && s.imageIds.length > 0 && (w = await se(
539
+ s.imageIds,
540
+ {
541
+ multiplier: e?.export?.multiplier ?? 2,
542
+ format: e?.export?.format ?? "png"
543
+ },
544
+ t
545
+ )), t) {
546
+ let p = null;
547
+ try {
548
+ p = await g.executeCommand("getSceneLayout");
549
+ } catch (x) {
550
+ console.warn("[PooderEditor] detectDielineFromFrame layout(after) failed", {
551
+ error: x
552
+ });
553
+ }
554
+ console.info("[PooderEditor] detectDielineFromFrame commit result", {
555
+ mappedSize: b,
556
+ imageUpdateTarget: l,
557
+ committedSync: w,
558
+ sizeAfter: {
559
+ actualWidthMm: c.get("size.actualWidthMm"),
560
+ actualHeightMm: c.get("size.actualHeightMm"),
561
+ viewPadding: c.get("size.viewPadding")
562
+ },
563
+ layoutAfterCommit: W(p)
564
+ });
565
+ }
566
+ return {
567
+ ...o,
568
+ ...i ? { sourceImage: s } : {},
569
+ ...n ? { diagnostics: h } : {}
570
+ };
248
571
  } finally {
249
- o && !n && URL.revokeObjectURL(o);
572
+ a && !i && URL.revokeObjectURL(a);
250
573
  }
251
574
  },
252
575
  uploadAndDetectEdge: async (e, t) => {
253
- const n = a.getService("CanvasService"), i = await I(e), r = E(n).filter(
254
- (s) => s.id === i
255
- ), o = await c.executeCommand("detectEdge", e, {
576
+ const i = u.getService("CanvasService"), n = await U(e), d = D(i).filter(
577
+ (m) => m.id === n
578
+ ), r = await g.executeCommand("detectEdge", e, {
256
579
  expand: t?.expand ?? 10,
257
580
  smoothing: t?.smoothing ?? !0,
258
581
  simplifyTolerance: t?.simplifyTolerance ?? 2
259
582
  });
260
- return o ? (y(o), await F(o, r), { imageId: i, url: e, pathData: o.pathData }) : null;
583
+ return r ? (P(r), await T(r, d), { imageId: n, url: e, pathData: r.pathData }) : null;
261
584
  },
262
- activateTool: async (e) => await f.switchTool(e),
263
- deactivateTool: async () => await f.deactivate(),
264
- on: (e, t) => a.eventBus.on(e, t),
265
- off: (e, t) => a.eventBus.off(e, t),
266
- emit: (e, t) => a.eventBus.emit(e, t),
267
- executeCommand: (e, ...t) => c.executeCommand(e, ...t),
268
- getConfig: (e) => d.get(e),
269
- updateConfig: (e, t) => d.update(e, t),
585
+ activateTool: async (e) => await S.switchTool(e),
586
+ deactivateTool: async () => await S.deactivate(),
587
+ on: (e, t) => u.eventBus.on(e, t),
588
+ off: (e, t) => u.eventBus.off(e, t),
589
+ emit: (e, t) => u.eventBus.emit(e, t),
590
+ executeCommand: (e, ...t) => g.executeCommand(e, ...t),
591
+ getConfig: (e) => c.get(e),
592
+ updateConfig: (e, t) => c.update(e, t),
270
593
  services: {
271
- workbench: f,
272
- command: c,
273
- config: d
594
+ workbench: S,
595
+ command: g,
596
+ config: c
274
597
  }
275
598
  });
276
- const U = (e) => {
277
- const t = new ne(e, {
278
- eventBus: a.eventBus
599
+ const ue = (e) => {
600
+ const t = new ve(e, {
601
+ eventBus: u.eventBus
279
602
  });
280
- a.registerService(t, "CanvasService"), a.registerService(new ie(), T), a.registerService(
281
- new oe(),
282
- B
603
+ u.registerService(t, "CanvasService"), u.registerService(new be(), j), u.registerService(
604
+ new xe(),
605
+ V
283
606
  ), [
284
- new ae(),
285
- new re(),
286
- new ce(),
607
+ new Se(),
608
+ new Ce(),
609
+ new Ne(),
287
610
  // new FilmTool(),
288
- new se(),
289
- new de(),
290
- new ue(),
291
- new me(),
292
- new ge()
293
- ].forEach((i) => {
294
- a.extensionManager.register(i);
611
+ new Ie(),
612
+ new Fe(),
613
+ new Be(),
614
+ new Me(),
615
+ new De()
616
+ ].forEach((n) => {
617
+ u.extensionManager.register(n);
295
618
  });
296
- }, V = (e, t) => {
297
- const n = a.getService("CanvasService");
298
- n && n.resize(e, t);
619
+ }, ge = (e, t) => {
620
+ const i = u.getService("CanvasService");
621
+ i && i.resize(e, t);
299
622
  };
300
- return Y(() => {
301
- w.dispose(), a.extensionManager.destroy(), a.unregisterService(B), a.unregisterService(T), a.unregisterService("CanvasService");
302
- }), (e, t) => (X(), R("div", fe, [
303
- ee(he, {
304
- onCanvasReady: U,
305
- onResize: V
623
+ return G(() => {
624
+ z.dispose(), u.extensionManager.destroy(), u.unregisterService(V), u.unregisterService(j), u.unregisterService("CanvasService");
625
+ }), (e, t) => (q(), $("div", _e, [
626
+ we(ze, {
627
+ onCanvasReady: ue,
628
+ onResize: ge
306
629
  })
307
630
  ]));
308
631
  }
309
- }), _e = /* @__PURE__ */ A(pe, [["__scopeId", "data-v-2149abdf"]]);
632
+ }), We = /* @__PURE__ */ K(Pe, [["__scopeId", "data-v-7e138562"]]);
310
633
  export {
311
- _e as PooderEditor
634
+ We as PooderEditor
312
635
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(l,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("vue"),require("@pooder/core"),require("@pooder/kit")):typeof define=="function"&&define.amd?define(["exports","vue","@pooder/core","@pooder/kit"],u):(l=typeof globalThis<"u"?globalThis:l||self,u(l.PooderVue={},l.Vue,l.PooderCore,l.PooderKit))})(this,(function(l,u,S,h){"use strict";const j=u.defineComponent({__name:"CanvasArea",emits:["canvas-ready","resize"],setup(m,{emit:b}){const p=b,r=u.ref(null),c=u.ref(null);let d=null;return u.onMounted(()=>{if(r.value&&c.value){const{clientWidth:w,clientHeight:y}=r.value;c.value.width=w,c.value.height=y,p("canvas-ready",c.value),d=new ResizeObserver(x=>{for(const _ of x){const{width:I,height:E}=_.contentRect;p("resize",I,E)}}),d.observe(r.value)}}),u.onUnmounted(()=>{d&&d.disconnect()}),(w,y)=>(u.openBlock(),u.createElementBlock("div",{ref_key:"container",ref:r,class:"pooder-canvas-area"},[u.createElementVNode("canvas",{ref_key:"canvas",ref:c},null,512)],512))}}),D=(m,b)=>{const p=m.__vccOpts||m;for(const[r,c]of b)p[r]=c;return p},X=D(j,[["__scopeId","data-v-203ff8d9"]]),A={class:"pooder-editor"},O="SceneLayoutService",F="SceneVisibilityService",W="image.user",z=D(u.defineComponent({__name:"PooderEditor",emits:["image-change"],setup(m,{expose:b,emit:p}){const r=new S.Pooder;u.provide("pooder",r);const c=r.getService("CommandService"),d=r.getService("ConfigurationService"),w=r.getService("WorkbenchService"),y=p,x=d.onAnyChange(e=>{e.key==="image.items"&&y("image-change",e.value)}),_=e=>{d.import(e)},I=()=>d.export(),E=()=>d.get("image.items",[]),H=async e=>{try{const t=await c.executeCommand("exportCutImage",e);return t||console.warn("[PooderEditor] generateCutImage returned null",{options:e,imageCount:(d.get("image.items")||[]).length,hasCanvasService:!!r.getService("CanvasService")}),t}catch(t){throw console.error("[PooderEditor] generateCutImage failed",t),t}},T=async(e,t)=>await c.executeCommand("upsertImage",e,{id:t?.id,mode:t?.mode,addOptions:t?.addOptions,fitOnAdd:t?.fitOnAdd}),M=async(e,t)=>(await T(e,{mode:"add",addOptions:t,fitOnAdd:!0})).id,V=async(e,t)=>await c.executeCommand("updateImage",e,t),L=async()=>await c.executeCommand("clearImages"),B=async e=>await c.executeCommand("exportUserCroppedImage",e),U=async(e,t)=>await c.executeCommand("focusImage",e,t),P=e=>Math.max(-1,Math.min(2,e)),q=e=>{const t=e?.cutRect;if(!t)return null;const n=Number(t.width),o=Number(t.height),a=Number(t.left),i=Number(t.top);return!Number.isFinite(n)||!Number.isFinite(o)||!Number.isFinite(a)||!Number.isFinite(i)||n<=0||o<=0?null:{left:a,top:i,width:n,height:o}},Y=e=>{if(!e)return[];const t=e.canvas.getObjects(),n=[];for(const o of t){if(o?.data?.layerId!==W)continue;const a=o?.data?.id;if(typeof a!="string")continue;const i=o.getCenterPoint?o.getCenterPoint():null,s=Number(i?.x??o.left),g=Number(i?.y??o.top),f=Number(o.scaleX),v=Number(o.width),C=Number(o.height);!Number.isFinite(s)||!Number.isFinite(g)||!Number.isFinite(f)||!Number.isFinite(v)||!Number.isFinite(C)||v<=0||C<=0||n.push({id:a,centerX:s,centerY:g,objectScale:f,sourceWidth:v,sourceHeight:C})}return n},N=e=>{d.update("dieline.shape","custom"),d.update("dieline.pathData",e.pathData),d.update("dieline.features",[]),d.update("size.cutMode","trim"),d.update("size.cutMarginMm",0)},k=(e,t)=>{const n=e.rawBounds||e.baseBounds||null;if(!n)return{sourceWidth:t.width,sourceHeight:t.height,detectedBounds:null,centerOffsetX:0,centerOffsetY:0,coverageX:0,coverageY:0};const o=t.width/2,a=t.height/2,i=n.x+n.width/2,s=n.y+n.height/2;return{sourceWidth:t.width,sourceHeight:t.height,detectedBounds:n,centerOffsetX:i-o,centerOffsetY:s-a,coverageX:t.width>0?n.width/t.width:0,coverageY:t.height>0?n.height/t.height:0}},G=(e,t)=>{const n=e.rawBounds||e.baseBounds,o=Number(e.imageWidth??0),a=Number(e.imageHeight??0);if(!n||!Number.isFinite(n.x)||!Number.isFinite(n.y)||!Number.isFinite(n.width)||!Number.isFinite(n.height)||n.width<=0||n.height<=0||o<=0||a<=0)return{shiftX:0,shiftY:0};const i=t.width/n.width,s=t.height/n.height,g=n.x+n.width/2,f=n.y+n.height/2,v=o/2,C=a/2;return{shiftX:(g-v)*i,shiftY:(f-C)*s}},R=async(e,t,n=!1,o="auto")=>{if(!t.length)return;const a=await c.executeCommand("getSceneLayout"),i=q(a);if(!i)return;const{shiftX:s,shiftY:g}=G(e,i);n&&console.info("[PooderEditor] detectDieline alignment",{frame:i,shiftX:s,shiftY:g,snapshotCount:t.length,baseBounds:e.baseBounds,rawBounds:e.rawBounds,imageWidth:e.imageWidth,imageHeight:e.imageHeight});for(const f of t){const v=Math.max(i.width/Math.max(1,f.sourceWidth),i.height/Math.max(1,f.sourceHeight)),C=Math.max(.05,f.objectScale/v),$=f.centerX-s,Q=f.centerY-g,Z=P(($-i.left)/Math.max(1,i.width)),ee=P((Q-i.top)/Math.max(1,i.height));await c.executeCommand("updateImage",f.id,{scale:C,left:Z,top:ee},{target:o})}};b({importConfig:_,exportConfig:I,getImages:E,generateCutImage:H,addImage:M,upsertImage:T,updateImage:V,clearImages:L,exportUserCroppedImage:B,focusImage:U,detectDieline:async e=>{const t=r.getService("CanvasService"),n=Y(t),o=await c.executeCommand("detectEdge",e,{expand:10,smoothing:!0,simplifyTolerance:2});if(o){N(o);const i=(d.get("image.items")||[]).find(s=>s.url===e);if(i?.id){const s=n.filter(g=>g.id===i.id);await R(o,s)}return o.pathData}return null},detectDielineFromFrame:async e=>{const t=e?.detect?.debug===!0,n=e?.inspect?.includeCroppedImage===!0,o=e?.inspect?.includeDiagnostics===!0,a=await B({multiplier:e?.export?.multiplier??2,format:e?.export?.format??"png",imageIds:e?.export?.imageIds}),i=a?.url;if(!i)return null;try{t&&console.info("[PooderEditor] detectDielineFromFrame sourceImage",{width:a.width,height:a.height,format:a.format,multiplier:a.multiplier,imageCount:a.imageIds.length});const s=await c.executeCommand("detectEdge",i,{expand:e?.detect?.expand??0,smoothing:e?.detect?.smoothing??!0,simplifyTolerance:e?.detect?.simplifyTolerance??2,threshold:e?.detect?.threshold,morphologyRadius:e?.detect?.morphologyRadius,connectRadiusMax:e?.detect?.connectRadiusMax,maskMode:e?.detect?.maskMode,whiteThreshold:e?.detect?.whiteThreshold,alphaOpaqueCutoff:e?.detect?.alphaOpaqueCutoff,noChannels:e?.detect?.noChannels,componentMode:e?.detect?.componentMode??"all",minComponentArea:e?.detect?.minComponentArea,forceConnected:e?.detect?.forceConnected??!0,debug:t});if(!s)return null;const g=k(s,a);return t&&console.info("[PooderEditor] detectDielineFromFrame diagnostics",g),e?.commit===!1?{...s,...n?{sourceImage:a}:{},...o?{diagnostics:g}:{}}:(N(s),{...s,...n?{sourceImage:a}:{},...o?{diagnostics:g}:{}})}finally{i&&!n&&URL.revokeObjectURL(i)}},uploadAndDetectEdge:async(e,t)=>{const n=r.getService("CanvasService"),o=await M(e),a=Y(n).filter(s=>s.id===o),i=await c.executeCommand("detectEdge",e,{expand:t?.expand??10,smoothing:t?.smoothing??!0,simplifyTolerance:t?.simplifyTolerance??2});return i?(N(i),await R(i,a),{imageId:o,url:e,pathData:i.pathData}):null},activateTool:async e=>await w.switchTool(e),deactivateTool:async()=>await w.deactivate(),on:(e,t)=>r.eventBus.on(e,t),off:(e,t)=>r.eventBus.off(e,t),emit:(e,t)=>r.eventBus.emit(e,t),executeCommand:(e,...t)=>c.executeCommand(e,...t),getConfig:e=>d.get(e),updateConfig:(e,t)=>d.update(e,t),services:{workbench:w,command:c,config:d}});const J=e=>{const t=new h.CanvasService(e,{eventBus:r.eventBus});r.registerService(t,"CanvasService"),r.registerService(new h.SceneLayoutService,O),r.registerService(new h.SceneVisibilityService,F),[new h.BackgroundTool,new h.SizeTool,new h.ImageTool,new h.WhiteInkTool,new h.MirrorTool,new h.DielineTool,new h.RulerTool,new h.FeatureTool].forEach(o=>{r.extensionManager.register(o)})},K=(e,t)=>{const n=r.getService("CanvasService");n&&n.resize(e,t)};return u.onUnmounted(()=>{x.dispose(),r.extensionManager.destroy(),r.unregisterService(F),r.unregisterService(O),r.unregisterService("CanvasService")}),(e,t)=>(u.openBlock(),u.createElementBlock("div",A,[u.createVNode(X,{onCanvasReady:J,onResize:K})]))}}),[["__scopeId","data-v-2149abdf"]]);l.PooderEditor=z,Object.keys(S).forEach(m=>{m!=="default"&&!Object.prototype.hasOwnProperty.call(l,m)&&Object.defineProperty(l,m,{enumerable:!0,get:()=>S[m]})}),Object.keys(h).forEach(m=>{m!=="default"&&!Object.prototype.hasOwnProperty.call(l,m)&&Object.defineProperty(l,m,{enumerable:!0,get:()=>h[m]})}),Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(v,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("vue"),require("@pooder/core"),require("@pooder/kit")):typeof define=="function"&&define.amd?define(["exports","vue","@pooder/core","@pooder/kit"],w):(v=typeof globalThis<"u"?globalThis:v||self,w(v.PooderVue={},v.Vue,v.PooderCore,v.PooderKit))})(this,(function(v,w,P,S){"use strict";const $=w.defineComponent({__name:"CanvasArea",emits:["canvas-ready","resize"],setup(y,{emit:M}){const F=M,u=w.ref(null),l=w.ref(null);let c=null;return w.onMounted(()=>{if(u.value&&l.value){const{clientWidth:B,clientHeight:D}=u.value;l.value.width=B,l.value.height=D,F("canvas-ready",l.value),c=new ResizeObserver(X=>{for(const O of X){const{width:T,height:R}=O.contentRect;F("resize",T,R)}}),c.observe(u.value)}}),w.onUnmounted(()=>{c&&c.disconnect()}),(B,D)=>(w.openBlock(),w.createElementBlock("div",{ref_key:"container",ref:u,class:"pooder-canvas-area"},[w.createElementVNode("canvas",{ref_key:"canvas",ref:l},null,512)],512))}}),W=(y,M)=>{const F=y.__vccOpts||y;for(const[u,l]of M)F[u]=l;return F},Q=W($,[["__scopeId","data-v-9668bbd7"]]),Z={class:"pooder-editor"},L="SceneLayoutService",H="SceneVisibilityService",ee="image.user",te="pooder.kit.image",ie=W(w.defineComponent({__name:"PooderEditor",emits:["image-change"],setup(y,{expose:M,emit:F}){const u=new P.Pooder;w.provide("pooder",u);const l=u.getService("CommandService"),c=u.getService("ConfigurationService"),B=u.getService("WorkbenchService"),D=F,X=c.onAnyChange(e=>{e.key==="image.items"&&D("image-change",e.value)}),O=e=>{c.import(e)},T=()=>c.export(),R=()=>c.get("image.items",[]),ne=async e=>{try{const t=await l.executeCommand("exportCutImage",e);return t||console.warn("[PooderEditor] generateCutImage returned null",{options:e,imageCount:(c.get("image.items")||[]).length,hasCanvasService:!!u.getService("CanvasService")}),t}catch(t){throw console.error("[PooderEditor] generateCutImage failed",t),t}},k=async(e,t)=>await l.executeCommand("upsertImage",e,{id:t?.id,mode:t?.mode,addOptions:t?.addOptions,fitOnAdd:t?.fitOnAdd}),V=async(e,t)=>(await k(e,{mode:"add",addOptions:t,fitOnAdd:!0})).id,oe=async(e,t)=>await l.executeCommand("updateImage",e,t),re=async()=>await l.executeCommand("clearImages"),E=async e=>await l.executeCommand("exportUserCroppedImage",e),ae=async(e,t)=>await l.executeCommand("focusImage",e,t),z=e=>Math.max(-1,Math.min(2,e)),q=e=>{const t=e?.cutRect;if(!t)return null;const i=Number(t.width),n=Number(t.height),d=Number(t.left),o=Number(t.top);return!Number.isFinite(i)||!Number.isFinite(n)||!Number.isFinite(d)||!Number.isFinite(o)||i<=0||n<=0?null:{left:d,top:o,width:i,height:n}},_=e=>{if(!e)return[];const t=e.canvas.getObjects(),i=[];for(const n of t){if(n?.data?.layerId!==ee)continue;const d=n?.data?.id;if(typeof d!="string")continue;const o=n.getCenterPoint?n.getCenterPoint():null,m=Number(o?.x??n.left),s=Number(o?.y??n.top),a=Number(n.scaleX),r=Number(n.width),h=Number(n.height);!Number.isFinite(m)||!Number.isFinite(s)||!Number.isFinite(a)||!Number.isFinite(r)||!Number.isFinite(h)||r<=0||h<=0||i.push({id:d,centerX:m,centerY:s,objectScale:a,sourceWidth:r,sourceHeight:h})}return i},J=(e,t)=>{if(!t||t.length===0)return e;const i=new Set(t);return e.filter(n=>i.has(n.id))},U=e=>{c.update("dieline.shape","custom"),c.update("dieline.pathData",e.pathData),c.update("dieline.features",[]),c.update("size.cutMode","trim"),c.update("size.cutMarginMm",0)},Y=e=>!!e&&Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.width)&&Number.isFinite(e.height)&&e.width>0&&e.height>0,se=e=>{const t=e.baseBounds||e.rawBounds,i=e.rawBounds||e.baseBounds;if(!Y(t)||!Y(i))return null;const n=Number(c.get("size.actualWidthMm",0)),d=Number(c.get("size.actualHeightMm",0)),o=Math.max(n,d),m=Math.max(t.width,t.height),s=Math.max(i.width,i.height);if(!Number.isFinite(o)||!Number.isFinite(m)||!Number.isFinite(s)||o<=0||m<=0||s<=0)return null;const a=o/s,r=i.width*a,h=i.height*a;return!Number.isFinite(r)||!Number.isFinite(h)||r<=0||h<=0?null:{widthMm:r,heightMm:h,scale:a,sizeLongEdgeMm:o,baseLongEdge:m,appliedBounds:i,baseBounds:t}},ce=(e,t=!1)=>{const i=se(e);return i?(c.update("size.actualWidthMm",i.widthMm),c.update("size.actualHeightMm",i.heightMm),c.update("size.aspectRatio",i.widthMm/Math.max(.001,i.heightMm)),t&&console.info("[PooderEditor] detectDielineFromFrame size mapping",{mappedSize:i,rawBounds:e.rawBounds,baseBounds:e.baseBounds}),i):null},A=e=>{if(!e)return null;const t=Number(e.left),i=Number(e.top),n=Number(e.width),d=Number(e.height),o=Number(e.centerX),m=Number(e.centerY);return!Number.isFinite(t)||!Number.isFinite(i)||!Number.isFinite(n)||!Number.isFinite(d)||!Number.isFinite(o)||!Number.isFinite(m)?null:{left:t,top:i,width:n,height:d,centerX:o,centerY:m}},G=e=>{if(!e)return null;const t=Number(e.scale),i=Number(e.canvasWidth),n=Number(e.canvasHeight);return!Number.isFinite(t)||!Number.isFinite(i)||!Number.isFinite(n)?null:{scale:t,canvasWidth:i,canvasHeight:n,viewPadding:c.get("size.viewPadding"),trimRect:A(e.trimRect),cutRect:A(e.cutRect),bleedRect:A(e.bleedRect)}},de=(e,t,i)=>{const n=e.rawBounds||e.baseBounds;return!Y(n)||!Number.isFinite(t)||!Number.isFinite(i)||t<=0||i<=0?null:{bounds:n,offsetX:n.x+n.width/2-t/2,offsetY:n.y+n.height/2-i/2}},K=e=>(e||[]).map(t=>({id:String(t?.id??""),left:Number(t?.left??0),top:Number(t?.top??0),scale:Number(t?.scale??1),angle:Number(t?.angle??0),url:typeof t?.url=="string"?t.url:"",sourceUrl:typeof t?.sourceUrl=="string"?t.sourceUrl:"",committedUrl:typeof t?.committedUrl=="string"?t.committedUrl:""})),me=async()=>{try{const e=await l.executeCommand("getWorkingImages")||[],t=c.get("image.items",[])||[],i=K(e),n=K(t);return JSON.stringify(i)!==JSON.stringify(n)}catch{return!1}},ue=async(e=!1)=>{const t=typeof B?.activeToolId=="string"?String(B.activeToolId):null;if(t!==te)return e&&console.info("[PooderEditor] detectDielineFromFrame image update target",{activeToolId:t,target:"config",reason:"image-tool-inactive"}),"config";const i=await me(),n=i?"working":"config";return e&&console.info("[PooderEditor] detectDielineFromFrame image update target",{activeToolId:t,workingDirty:i,target:n,reason:i?"working-session-dirty-follow-working":"working-session-clean-update-config"}),n},le=async(e,t,i=!1)=>{const n=[...new Set(e)].filter(a=>typeof a=="string"&&a.length>0);if(!n.length)return[];const d=new Map;for(const a of n){const r=await E({multiplier:t?.multiplier??2,format:t?.format??"png",imageIds:[a]});r?.url&&d.set(a,{url:r.url,width:r.width,height:r.height})}if(!d.size)return[];const m=(Array.isArray(c.get("image.items",[]))?c.get("image.items",[]):[]).map(a=>{const r=typeof a?.id=="string"?a.id:"",h=d.get(r);if(!h)return a;const N=typeof a?.sourceUrl=="string"&&a.sourceUrl.length>0?a.sourceUrl:typeof a?.url=="string"?a.url:"";return{...a,url:h.url,sourceUrl:N,committedUrl:h.url}});c.update("image.items",m);const s=n.map(a=>{const r=d.get(a);return r?{id:a,width:r.width,height:r.height}:null}).filter(a=>!!a);return i&&console.info("[PooderEditor] detectDieline committed image sync",{imageIds:n,synced:s,count:s.length}),s},ge=(e,t)=>{const i=e.rawBounds||e.baseBounds||null;if(!i)return{sourceWidth:t.width,sourceHeight:t.height,detectedBounds:null,centerOffsetX:0,centerOffsetY:0,coverageX:0,coverageY:0};const n=t.width/2,d=t.height/2,o=i.x+i.width/2,m=i.y+i.height/2;return{sourceWidth:t.width,sourceHeight:t.height,detectedBounds:i,centerOffsetX:o-n,centerOffsetY:m-d,coverageX:t.width>0?i.width/t.width:0,coverageY:t.height>0?i.height/t.height:0}},he=(e,t)=>{const i=e.rawBounds||e.baseBounds,n=Number(e.imageWidth??0),d=Number(e.imageHeight??0);if(!i||!Number.isFinite(i.x)||!Number.isFinite(i.y)||!Number.isFinite(i.width)||!Number.isFinite(i.height)||i.width<=0||i.height<=0||n<=0||d<=0)return{shiftX:0,shiftY:0};const o=t.width/i.width,m=t.height/i.height,s=i.x+i.width/2,a=i.y+i.height/2,r=n/2,h=d/2;return{shiftX:(s-r)*o,shiftY:(a-h)*m}},j=async(e,t,i=!1,n="auto")=>{if(!t.length)return;const d=await l.executeCommand("getSceneLayout"),o=q(d);if(!o)return;const{shiftX:m,shiftY:s}=he(e,o),a=e.rawBounds,r=e.baseBounds,h=Number(e.imageWidth??0),N=Number(e.imageHeight??0);if(i){const g=f=>{if(!Y(f)||h<=0||N<=0)return null;const x=f.x+f.width/2-h/2,p=f.y+f.height/2-N/2;return{dx:x,dy:p,byBounds:{shiftX:x*(o.width/Math.max(1,f.width)),shiftY:p*(o.height/Math.max(1,f.height))},byImage:{shiftX:x*(o.width/Math.max(1,h)),shiftY:p*(o.height/Math.max(1,N))}}},b=g(a),C=g(r);console.info("[PooderEditor] detectDieline alignment",{frame:o,shiftX:m,shiftY:s,shiftNormalized:{x:o.width>0?m/o.width:0,y:o.height>0?s/o.height:0},snapshotCount:t.length,baseBounds:r,rawBounds:a,imageWidth:h,imageHeight:N,shiftCandidates:{raw:b,base:C},shiftRawByBoundsX:b?.byBounds?.shiftX,shiftRawByBoundsY:b?.byBounds?.shiftY,shiftRawByImageX:b?.byImage?.shiftX,shiftRawByImageY:b?.byImage?.shiftY,shiftBaseByBoundsX:C?.byBounds?.shiftX,shiftBaseByBoundsY:C?.byBounds?.shiftY,shiftBaseByImageX:C?.byImage?.shiftX,shiftBaseByImageY:C?.byImage?.shiftY})}for(const g of t){const b=Math.max(o.width/Math.max(1,g.sourceWidth),o.height/Math.max(1,g.sourceHeight)),C=Math.max(.05,g.objectScale/b),f=g.centerX-m,x=g.centerY-s,p=z((f-o.left)/Math.max(1,o.width)),I=z((x-o.top)/Math.max(1,o.height));i&&console.info("[PooderEditor] detectDieline alignment item",{id:g.id,target:n,frame:o,sourceSize:{width:g.sourceWidth,height:g.sourceHeight},objectScale:g.objectScale,coverScale:b,targetScale:C,centerBefore:{x:g.centerX,y:g.centerY},centerAfter:{x:f,y:x},normalizedAfter:{left:p,top:I}}),await l.executeCommand("updateImage",g.id,{scale:C,left:p,top:I},{target:n})}},fe=async(e,t,i,n,d,o=!1,m="auto",s="offset")=>{if(!d.length||!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(i)||!Number.isFinite(n)||i<=0||n<=0)return;const a=await l.executeCommand("getSceneLayout"),r=q(a);if(!r)return;const h=e*r.width/i,N=t*r.height/n;o&&console.info("[PooderEditor] detectDieline direct compensation",{label:s,target:m,sourceWidth:i,sourceHeight:n,offsetX:e,offsetY:t,frame:r,shiftX:h,shiftY:N,shiftNormalized:{x:r.width>0?h/r.width:0,y:r.height>0?N/r.height:0},snapshotCount:d.length});for(const g of d){const b=g.centerX-h,C=g.centerY-N,f=z((b-r.left)/Math.max(1,r.width)),x=z((C-r.top)/Math.max(1,r.height));o&&console.info("[PooderEditor] detectDieline direct compensation item",{label:s,id:g.id,centerBefore:{x:g.centerX,y:g.centerY},centerAfter:{x:b,y:C},normalizedAfter:{left:f,top:x}}),await l.executeCommand("updateImage",g.id,{left:f,top:x},{target:m})}};M({importConfig:O,exportConfig:T,getImages:R,generateCutImage:ne,addImage:V,upsertImage:k,updateImage:oe,clearImages:re,exportUserCroppedImage:E,focusImage:ae,detectDieline:async e=>{const t=u.getService("CanvasService"),i=_(t),n=await l.executeCommand("detectEdge",e,{expand:10,smoothing:!0,simplifyTolerance:2});if(n){U(n);const o=(c.get("image.items")||[]).find(m=>m.url===e);if(o?.id){const m=i.filter(s=>s.id===o.id);await j(n,m)}return n.pathData}return null},detectDielineFromFrame:async e=>{const t=e?.detect?.debug===!0,i=e?.inspect?.includeCroppedImage===!0,n=e?.inspect?.includeDiagnostics===!0,d=u.getService("CanvasService"),o=_(d);let m=null;if(t)try{m=await l.executeCommand("getSceneLayout")}catch(r){console.warn("[PooderEditor] detectDielineFromFrame layout(before) failed",{error:r})}const s=await E({multiplier:e?.export?.multiplier??2,format:e?.export?.format??"png",imageIds:e?.export?.imageIds}),a=s?.url;if(!a)return null;try{t&&console.info("[PooderEditor] detectDielineFromFrame sourceImage",{width:s.width,height:s.height,format:s.format,multiplier:s.multiplier,imageCount:s.imageIds.length,size:{actualWidthMm:c.get("size.actualWidthMm"),actualHeightMm:c.get("size.actualHeightMm"),viewPadding:c.get("size.viewPadding")},layoutBeforeCommit:G(m),imageSnapshots:o.map(p=>({id:p.id,centerX:p.centerX,centerY:p.centerY,objectScale:p.objectScale,sourceWidth:p.sourceWidth,sourceHeight:p.sourceHeight}))});const r=await l.executeCommand("detectEdge",a,{expand:e?.detect?.expand??0,smoothing:e?.detect?.smoothing??!0,simplifyTolerance:e?.detect?.simplifyTolerance??2,threshold:e?.detect?.threshold,debug:t});if(!r)return null;const h=ge(r,s);if(t&&console.info("[PooderEditor] detectDielineFromFrame diagnostics",h),e?.commit===!1)return{...r,...i?{sourceImage:s}:{},...n?{diagnostics:h}:{}};U(r);const N=ce(r,t),g=await ue(t);let b=[];const C=J(o,s.imageIds);await j(r,C,t,g);const f=await E({multiplier:e?.export?.multiplier??2,format:e?.export?.format??"png",imageIds:s.imageIds}),x=f?.url;if(x)try{const p=await l.executeCommand("detectEdge",x,{expand:e?.detect?.expand??0,smoothing:e?.detect?.smoothing??!0,simplifyTolerance:e?.detect?.simplifyTolerance??2,threshold:e?.detect?.threshold,debug:t});if(p){const I=de(p,f.width,f.height);if(t&&console.info("[PooderEditor] detectDieline verify pass",{sourceWidth:f.width,sourceHeight:f.height,offset:I,imageIds:s.imageIds}),I&&(Math.abs(I.offsetX)>.01||Math.abs(I.offsetY)>.01)){const ye=J(_(d),s.imageIds);await fe(I.offsetX,I.offsetY,f.width,f.height,ye,t,g,"verify-pass")}}}finally{URL.revokeObjectURL(x)}if(g==="config"&&s.imageIds.length>0&&(b=await le(s.imageIds,{multiplier:e?.export?.multiplier??2,format:e?.export?.format??"png"},t)),t){let p=null;try{p=await l.executeCommand("getSceneLayout")}catch(I){console.warn("[PooderEditor] detectDielineFromFrame layout(after) failed",{error:I})}console.info("[PooderEditor] detectDielineFromFrame commit result",{mappedSize:N,imageUpdateTarget:g,committedSync:b,sizeAfter:{actualWidthMm:c.get("size.actualWidthMm"),actualHeightMm:c.get("size.actualHeightMm"),viewPadding:c.get("size.viewPadding")},layoutAfterCommit:G(p)})}return{...r,...i?{sourceImage:s}:{},...n?{diagnostics:h}:{}}}finally{a&&!i&&URL.revokeObjectURL(a)}},uploadAndDetectEdge:async(e,t)=>{const i=u.getService("CanvasService"),n=await V(e),d=_(i).filter(m=>m.id===n),o=await l.executeCommand("detectEdge",e,{expand:t?.expand??10,smoothing:t?.smoothing??!0,simplifyTolerance:t?.simplifyTolerance??2});return o?(U(o),await j(o,d),{imageId:n,url:e,pathData:o.pathData}):null},activateTool:async e=>await B.switchTool(e),deactivateTool:async()=>await B.deactivate(),on:(e,t)=>u.eventBus.on(e,t),off:(e,t)=>u.eventBus.off(e,t),emit:(e,t)=>u.eventBus.emit(e,t),executeCommand:(e,...t)=>l.executeCommand(e,...t),getConfig:e=>c.get(e),updateConfig:(e,t)=>c.update(e,t),services:{workbench:B,command:l,config:c}});const pe=e=>{const t=new S.CanvasService(e,{eventBus:u.eventBus});u.registerService(t,"CanvasService"),u.registerService(new S.SceneLayoutService,L),u.registerService(new S.SceneVisibilityService,H),[new S.BackgroundTool,new S.SizeTool,new S.ImageTool,new S.WhiteInkTool,new S.MirrorTool,new S.DielineTool,new S.RulerTool,new S.FeatureTool].forEach(n=>{u.extensionManager.register(n)})},we=(e,t)=>{const i=u.getService("CanvasService");i&&i.resize(e,t)};return w.onUnmounted(()=>{X.dispose(),u.extensionManager.destroy(),u.unregisterService(H),u.unregisterService(L),u.unregisterService("CanvasService")}),(e,t)=>(w.openBlock(),w.createElementBlock("div",Z,[w.createVNode(Q,{onCanvasReady:pe,onResize:we})]))}}),[["__scopeId","data-v-7e138562"]]);v.PooderEditor=ie,Object.keys(P).forEach(y=>{y!=="default"&&!Object.prototype.hasOwnProperty.call(v,y)&&Object.defineProperty(v,y,{enumerable:!0,get:()=>P[y]})}),Object.keys(S).forEach(y=>{y!=="default"&&!Object.prototype.hasOwnProperty.call(v,y)&&Object.defineProperty(v,y,{enumerable:!0,get:()=>S[y]})}),Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
@@ -53,15 +53,6 @@ declare const _default: import('vue').DefineComponent<{}, {
53
53
  smoothing?: boolean;
54
54
  simplifyTolerance?: number;
55
55
  threshold?: number;
56
- morphologyRadius?: number;
57
- connectRadiusMax?: number;
58
- maskMode?: "auto" | "alpha" | "whitebg";
59
- whiteThreshold?: number;
60
- alphaOpaqueCutoff?: number;
61
- noChannels?: boolean;
62
- componentMode?: "largest" | "all";
63
- minComponentArea?: number;
64
- forceConnected?: boolean;
65
56
  debug?: boolean;
66
57
  };
67
58
  export?: {
package/dist/vue.css CHANGED
@@ -1 +1 @@
1
- .pooder-canvas-area[data-v-203ff8d9]{flex:1;width:100%;height:100%;min-height:650px;min-width:650px;overflow:hidden;background:#ececec;position:relative}canvas[data-v-203ff8d9]{display:block}.pooder-editor[data-v-2149abdf]{display:flex;width:100%;height:100%;overflow:hidden}
1
+ .pooder-canvas-area[data-v-9668bbd7]{flex:1;width:100%;height:100%;min-height:650px;min-width:650px;overflow:hidden;background:#ececec;position:relative}canvas[data-v-9668bbd7]{display:block}.pooder-editor[data-v-7e138562]{display:flex;width:100%;height:100%;overflow:hidden}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pooder/vue",
3
- "version": "4.2.6",
3
+ "version": "4.2.7",
4
4
  "main": "./dist/index.umd.js",
5
5
  "module": "./dist/index.es.js",
6
6
  "types": "./dist/index.d.ts",
@@ -19,8 +19,8 @@
19
19
  "access": "public"
20
20
  },
21
21
  "dependencies": {
22
- "@pooder/core": "2.2.0",
23
- "@pooder/kit": "5.2.0"
22
+ "@pooder/kit": "5.3.0",
23
+ "@pooder/core": "2.2.0"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "vue": "^3.0.0"