@pooder/vue 4.2.3 → 4.2.4

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,15 +1,15 @@
1
- import { defineComponent as T, ref as M, onMounted as U, onUnmounted as E, createElementBlock as B, openBlock as O, createElementVNode as V, provide as G, createVNode as J } from "vue";
2
- import { Pooder as $ } from "@pooder/core";
1
+ import { defineComponent as E, ref as T, onMounted as V, onUnmounted as M, createElementBlock as B, openBlock as O, createElementVNode as G, provide as J, createVNode as $ } from "vue";
2
+ import { Pooder as q } from "@pooder/core";
3
3
  export * from "@pooder/core";
4
- import { CanvasService as q, BackgroundTool as K, SizeTool as Q, SceneLayoutService as Z, SceneVisibilityService as ee, ImageTool as te, WhiteInkTool as ne, MirrorTool as ae, DielineTool as ie, RulerTool as oe, FeatureTool as ce } from "@pooder/kit";
4
+ import { CanvasService as K, BackgroundTool as Q, SizeTool as Z, SceneLayoutService as ee, SceneVisibilityService as te, ImageTool as ne, WhiteInkTool as ae, MirrorTool as ie, DielineTool as oe, RulerTool as ce, FeatureTool as re } from "@pooder/kit";
5
5
  export * from "@pooder/kit";
6
- const re = /* @__PURE__ */ T({
6
+ const se = /* @__PURE__ */ E({
7
7
  __name: "CanvasArea",
8
8
  emits: ["canvas-ready", "resize"],
9
9
  setup(p, { emit: v }) {
10
- const u = v, o = M(null), r = M(null);
10
+ const u = v, o = T(null), r = T(null);
11
11
  let s = null;
12
- return U(() => {
12
+ return V(() => {
13
13
  if (o.value && r.value) {
14
14
  const { clientWidth: h, clientHeight: w } = o.value;
15
15
  r.value.width = h, r.value.height = w, u("canvas-ready", r.value), s = new ResizeObserver((C) => {
@@ -19,14 +19,14 @@ const re = /* @__PURE__ */ T({
19
19
  }
20
20
  }), s.observe(o.value);
21
21
  }
22
- }), E(() => {
22
+ }), M(() => {
23
23
  s && s.disconnect();
24
24
  }), (h, w) => (O(), B("div", {
25
25
  ref_key: "container",
26
26
  ref: o,
27
27
  class: "pooder-canvas-area"
28
28
  }, [
29
- V("canvas", {
29
+ G("canvas", {
30
30
  ref_key: "canvas",
31
31
  ref: r
32
32
  }, null, 512)
@@ -37,12 +37,12 @@ const re = /* @__PURE__ */ T({
37
37
  for (const [o, r] of v)
38
38
  u[o] = r;
39
39
  return u;
40
- }, se = /* @__PURE__ */ k(re, [["__scopeId", "data-v-dc60e8d6"]]), de = { class: "pooder-editor" }, me = "image.user", ue = /* @__PURE__ */ T({
40
+ }, me = /* @__PURE__ */ k(se, [["__scopeId", "data-v-dc60e8d6"]]), de = { class: "pooder-editor" }, ue = "image.user", ge = /* @__PURE__ */ E({
41
41
  __name: "PooderEditor",
42
42
  emits: ["image-change"],
43
43
  setup(p, { expose: v, emit: u }) {
44
- const o = new $();
45
- G("pooder", o);
44
+ const o = new q();
45
+ J("pooder", o);
46
46
  const r = o.getService("CommandService"), s = o.getService("ConfigurationService"), h = o.getService("WorkbenchService"), w = u, C = s.onAnyChange((e) => {
47
47
  e.key === "image.items" && w("image-change", e.value);
48
48
  }), b = (e) => {
@@ -64,14 +64,13 @@ const re = /* @__PURE__ */ T({
64
64
  }, N = async (e, t) => await r.executeCommand("upsertImage", e, {
65
65
  id: t?.id,
66
66
  mode: t?.mode,
67
- createIfMissing: t?.createIfMissing,
68
67
  addOptions: t?.addOptions,
69
68
  fitOnAdd: t?.fitOnAdd
70
69
  }), F = async (e, t) => (await N(e, {
71
70
  mode: "add",
72
71
  addOptions: t,
73
72
  fitOnAdd: !0
74
- })).id, R = async (e, t) => await r.executeCommand("updateImage", e, t), z = async () => await r.executeCommand("clearImages"), D = (e) => Math.max(-1, Math.min(2, e)), X = (e) => {
73
+ })).id, R = async (e, t) => await r.executeCommand("updateImage", e, t), z = async () => await r.executeCommand("clearImages"), X = async (e, t) => await r.executeCommand("focusImage", e, t), D = (e) => Math.max(-1, Math.min(2, e)), Y = (e) => {
75
74
  const t = e?.cutRect;
76
75
  if (!t) return null;
77
76
  const n = Number(t.width), a = Number(t.height), i = Number(t.left), c = Number(t.top);
@@ -80,14 +79,14 @@ const re = /* @__PURE__ */ T({
80
79
  if (!e) return [];
81
80
  const t = e.canvas.getObjects(), n = [];
82
81
  for (const a of t) {
83
- if (a?.data?.layerId !== me) continue;
82
+ if (a?.data?.layerId !== ue) continue;
84
83
  const i = a?.data?.id;
85
84
  if (typeof i != "string") continue;
86
- const c = a.getCenterPoint ? a.getCenterPoint() : null, d = Number(c?.x ?? a.left), m = Number(c?.y ?? a.top), f = Number(a.scaleX), g = Number(a.width), l = Number(a.height);
87
- !Number.isFinite(d) || !Number.isFinite(m) || !Number.isFinite(f) || !Number.isFinite(g) || !Number.isFinite(l) || g <= 0 || l <= 0 || n.push({
85
+ const c = a.getCenterPoint ? a.getCenterPoint() : null, m = Number(c?.x ?? a.left), d = Number(c?.y ?? a.top), f = Number(a.scaleX), g = Number(a.width), l = Number(a.height);
86
+ !Number.isFinite(m) || !Number.isFinite(d) || !Number.isFinite(f) || !Number.isFinite(g) || !Number.isFinite(l) || g <= 0 || l <= 0 || n.push({
88
87
  id: i,
89
- centerX: d,
90
- centerY: m,
88
+ centerX: m,
89
+ centerY: d,
91
90
  objectScale: f,
92
91
  sourceWidth: g,
93
92
  sourceHeight: l
@@ -96,43 +95,43 @@ const re = /* @__PURE__ */ T({
96
95
  return n;
97
96
  }, _ = (e) => {
98
97
  s.update("dieline.shape", "custom"), s.update("dieline.pathData", e.pathData), s.update("size.cutMode", "trim"), s.update("size.cutMarginMm", 0);
99
- }, Y = (e, t) => {
98
+ }, W = (e, t) => {
100
99
  const n = e.rawBounds || e.baseBounds, a = Number(e.imageWidth ?? 0), i = Number(e.imageHeight ?? 0);
101
100
  if (!n || !Number.isFinite(n.x) || !Number.isFinite(n.y) || !Number.isFinite(n.width) || !Number.isFinite(n.height) || n.width <= 0 || n.height <= 0 || a <= 0 || i <= 0)
102
101
  return { shiftX: 0, shiftY: 0 };
103
- const c = t.width / n.width, d = t.height / n.height, m = n.x + n.width / 2, f = n.y + n.height / 2, g = a / 2, l = i / 2;
102
+ const c = t.width / n.width, m = t.height / n.height, d = n.x + n.width / 2, f = n.y + n.height / 2, g = a / 2, l = i / 2;
104
103
  return {
105
- shiftX: (m - g) * c,
106
- shiftY: (f - l) * d
104
+ shiftX: (d - g) * c,
105
+ shiftY: (f - l) * m
107
106
  };
108
107
  }, I = async (e, t, n = !1) => {
109
108
  if (!t.length) return;
110
- const a = await r.executeCommand("getSceneLayout"), i = X(a);
109
+ const a = await r.executeCommand("getSceneLayout"), i = Y(a);
111
110
  if (!i) return;
112
- const { shiftX: c, shiftY: d } = Y(e, i);
111
+ const { shiftX: c, shiftY: m } = W(e, i);
113
112
  n && console.info("[PooderEditor] detectDieline alignment", {
114
113
  frame: i,
115
114
  shiftX: c,
116
- shiftY: d,
115
+ shiftY: m,
117
116
  snapshotCount: t.length,
118
117
  baseBounds: e.baseBounds,
119
118
  rawBounds: e.rawBounds,
120
119
  imageWidth: e.imageWidth,
121
120
  imageHeight: e.imageHeight
122
121
  });
123
- for (const m of t) {
122
+ for (const d of t) {
124
123
  const f = Math.max(
125
- i.width / Math.max(1, m.sourceWidth),
126
- i.height / Math.max(1, m.sourceHeight)
127
- ), g = Math.max(0.05, m.objectScale / f), l = m.centerX - c, P = m.centerY - d, H = D(
124
+ i.width / Math.max(1, d.sourceWidth),
125
+ i.height / Math.max(1, d.sourceHeight)
126
+ ), g = Math.max(0.05, d.objectScale / f), l = d.centerX - c, H = d.centerY - m, L = D(
128
127
  (l - i.left) / Math.max(1, i.width)
129
- ), L = D(
130
- (P - i.top) / Math.max(1, i.height)
128
+ ), U = D(
129
+ (H - i.top) / Math.max(1, i.height)
131
130
  );
132
- await r.executeCommand("updateImage", m.id, {
131
+ await r.executeCommand("updateImage", d.id, {
133
132
  scale: g,
134
- left: H,
135
- top: L
133
+ left: L,
134
+ top: U
136
135
  });
137
136
  }
138
137
  };
@@ -145,6 +144,7 @@ const re = /* @__PURE__ */ T({
145
144
  upsertImage: N,
146
145
  updateImage: R,
147
146
  clearImages: z,
147
+ focusImage: X,
148
148
  detectDieline: async (e) => {
149
149
  const t = o.getService("CanvasService"), n = y(t), a = await r.executeCommand("detectEdge", e, {
150
150
  expand: 10,
@@ -156,12 +156,12 @@ const re = /* @__PURE__ */ T({
156
156
  });
157
157
  if (a) {
158
158
  _(a);
159
- const c = (s.get("image.items") || []).find((d) => d.url === e);
159
+ const c = (s.get("image.items") || []).find((m) => m.url === e);
160
160
  if (c?.id) {
161
- const d = n.filter(
162
- (m) => m.id === c.id
161
+ const m = n.filter(
162
+ (d) => d.id === c.id
163
163
  );
164
- await I(a, d);
164
+ await I(a, m);
165
165
  }
166
166
  return a.pathData;
167
167
  }
@@ -186,7 +186,7 @@ const re = /* @__PURE__ */ T({
186
186
  },
187
187
  uploadAndDetectEdge: async (e, t) => {
188
188
  const n = o.getService("CanvasService"), a = await F(e), i = y(n).filter(
189
- (d) => d.id === a
189
+ (m) => m.id === a
190
190
  ), c = await r.executeCommand("detectEdge", e, {
191
191
  expand: t?.expand ?? 10,
192
192
  smoothing: t?.smoothing ?? !0,
@@ -208,40 +208,40 @@ const re = /* @__PURE__ */ T({
208
208
  config: s
209
209
  }
210
210
  });
211
- const W = (e) => {
212
- const t = new q(e, {
211
+ const j = (e) => {
212
+ const t = new K(e, {
213
213
  eventBus: o.eventBus
214
214
  });
215
215
  o.registerService(t, "CanvasService"), [
216
- new K(),
217
216
  new Q(),
218
217
  new Z(),
219
218
  new ee(),
220
219
  new te(),
221
- // new FilmTool(),
222
220
  new ne(),
221
+ // new FilmTool(),
223
222
  new ae(),
224
223
  new ie(),
225
224
  new oe(),
226
- new ce()
225
+ new ce(),
226
+ new re()
227
227
  ].forEach((a) => {
228
228
  o.extensionManager.register(a);
229
229
  });
230
- }, j = (e, t) => {
230
+ }, P = (e, t) => {
231
231
  const n = o.getService("CanvasService");
232
232
  n && n.resize(e, t);
233
233
  };
234
- return E(() => {
234
+ return M(() => {
235
235
  const e = o.getService("CanvasService");
236
236
  e && e.dispose(), C.dispose(), o.extensionManager.destroy();
237
237
  }), (e, t) => (O(), B("div", de, [
238
- J(se, {
239
- onCanvasReady: W,
240
- onResize: j
238
+ $(me, {
239
+ onCanvasReady: j,
240
+ onResize: P
241
241
  })
242
242
  ]));
243
243
  }
244
- }), we = /* @__PURE__ */ k(ue, [["__scopeId", "data-v-234847f9"]]);
244
+ }), Ce = /* @__PURE__ */ k(ge, [["__scopeId", "data-v-522d075c"]]);
245
245
  export {
246
- we as PooderEditor
246
+ Ce as PooderEditor
247
247
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(u,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("vue"),require("@pooder/core"),require("@pooder/kit")):typeof define=="function"&&define.amd?define(["exports","vue","@pooder/core","@pooder/kit"],s):(u=typeof globalThis<"u"?globalThis:u||self,s(u.PooderVue={},u.Vue,u.PooderCore,u.PooderKit))})(this,(function(u,s,S,g){"use strict";const P=s.defineComponent({__name:"CanvasArea",emits:["canvas-ready","resize"],setup(m,{emit:y}){const h=y,i=s.ref(null),c=s.ref(null);let d=null;return s.onMounted(()=>{if(i.value&&c.value){const{clientWidth:b,clientHeight:C}=i.value;c.value.width=b,c.value.height=C,h("canvas-ready",c.value),d=new ResizeObserver(x=>{for(const _ of x){const{width:I,height:N}=_.contentRect;h("resize",I,N)}}),d.observe(i.value)}}),s.onUnmounted(()=>{d&&d.disconnect()}),(b,C)=>(s.openBlock(),s.createElementBlock("div",{ref_key:"container",ref:i,class:"pooder-canvas-area"},[s.createElementVNode("canvas",{ref_key:"canvas",ref:c},null,512)],512))}}),E=(m,y)=>{const h=m.__vccOpts||m;for(const[i,c]of y)h[i]=c;return h},j=E(P,[["__scopeId","data-v-dc60e8d6"]]),A={class:"pooder-editor"},R="image.user",z=E(s.defineComponent({__name:"PooderEditor",emits:["image-change"],setup(m,{expose:y,emit:h}){const i=new S.Pooder;s.provide("pooder",i);const c=i.getService("CommandService"),d=i.getService("ConfigurationService"),b=i.getService("WorkbenchService"),C=h,x=d.onAnyChange(e=>{e.key==="image.items"&&C("image-change",e.value)}),_=e=>{d.import(e)},I=()=>d.export(),N=()=>d.get("image.items",[]),X=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:!!i.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,createIfMissing:t?.createIfMissing,addOptions:t?.addOptions,fitOnAdd:t?.fitOnAdd}),M=async(e,t)=>(await T(e,{mode:"add",addOptions:t,fitOnAdd:!0})).id,Y=async(e,t)=>await c.executeCommand("updateImage",e,t),W=async()=>await c.executeCommand("clearImages"),B=e=>Math.max(-1,Math.min(2,e)),H=e=>{const t=e?.cutRect;if(!t)return null;const n=Number(t.width),o=Number(t.height),a=Number(t.left),r=Number(t.top);return!Number.isFinite(n)||!Number.isFinite(o)||!Number.isFinite(a)||!Number.isFinite(r)||n<=0||o<=0?null:{left:a,top:r,width:n,height:o}},F=e=>{if(!e)return[];const t=e.canvas.getObjects(),n=[];for(const o of t){if(o?.data?.layerId!==R)continue;const a=o?.data?.id;if(typeof a!="string")continue;const r=o.getCenterPoint?o.getCenterPoint():null,l=Number(r?.x??o.left),f=Number(r?.y??o.top),w=Number(o.scaleX),p=Number(o.width),v=Number(o.height);!Number.isFinite(l)||!Number.isFinite(f)||!Number.isFinite(w)||!Number.isFinite(p)||!Number.isFinite(v)||p<=0||v<=0||n.push({id:a,centerX:l,centerY:f,objectScale:w,sourceWidth:p,sourceHeight:v})}return n},O=e=>{d.update("dieline.shape","custom"),d.update("dieline.pathData",e.pathData),d.update("size.cutMode","trim"),d.update("size.cutMarginMm",0)},L=(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 r=t.width/n.width,l=t.height/n.height,f=n.x+n.width/2,w=n.y+n.height/2,p=o/2,v=a/2;return{shiftX:(f-p)*r,shiftY:(w-v)*l}},D=async(e,t,n=!1)=>{if(!t.length)return;const o=await c.executeCommand("getSceneLayout"),a=H(o);if(!a)return;const{shiftX:r,shiftY:l}=L(e,a);n&&console.info("[PooderEditor] detectDieline alignment",{frame:a,shiftX:r,shiftY:l,snapshotCount:t.length,baseBounds:e.baseBounds,rawBounds:e.rawBounds,imageWidth:e.imageWidth,imageHeight:e.imageHeight});for(const f of t){const w=Math.max(a.width/Math.max(1,f.sourceWidth),a.height/Math.max(1,f.sourceHeight)),p=Math.max(.05,f.objectScale/w),v=f.centerX-r,q=f.centerY-l,G=B((v-a.left)/Math.max(1,a.width)),J=B((q-a.top)/Math.max(1,a.height));await c.executeCommand("updateImage",f.id,{scale:p,left:G,top:J})}};y({importConfig:_,exportConfig:I,getImages:N,generateCutImage:X,addImage:M,upsertImage:T,updateImage:Y,clearImages:W,detectDieline:async e=>{const t=i.getService("CanvasService"),n=F(t),o=await c.executeCommand("detectEdge",e,{expand:10,smoothing:!0,simplifyTolerance:2});if(o){O(o);const r=(d.get("image.items")||[]).find(l=>l.url===e);if(r?.id){const l=n.filter(f=>f.id===r.id);await D(o,l)}return o.pathData}return null},detectDielineFromFrame:async e=>{const t=e?.detect?.debug===!0,n=i.getService("CanvasService"),o=F(n),{url:a}=await c.executeCommand("exportImageFrameUrl",{multiplier:2,format:"png"});try{const r=await c.executeCommand("detectEdge",a,{expand:e?.detect?.expand??30,smoothing:e?.detect?.smoothing??!0,simplifyTolerance:e?.detect?.simplifyTolerance??2,debug:t});return r?(e?.commit===!1||(O(r),await D(r,o,t)),r):null}finally{a&&URL.revokeObjectURL(a)}},uploadAndDetectEdge:async(e,t)=>{const n=i.getService("CanvasService"),o=await M(e),a=F(n).filter(l=>l.id===o),r=await c.executeCommand("detectEdge",e,{expand:t?.expand??10,smoothing:t?.smoothing??!0,simplifyTolerance:t?.simplifyTolerance??2});return r?(O(r),await D(r,a),{imageId:o,url:e,pathData:r.pathData}):null},activateTool:async e=>await b.switchTool(e),deactivateTool:async()=>await b.deactivate(),on:(e,t)=>i.eventBus.on(e,t),off:(e,t)=>i.eventBus.off(e,t),emit:(e,t)=>i.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:b,command:c,config:d}});const U=e=>{const t=new g.CanvasService(e,{eventBus:i.eventBus});i.registerService(t,"CanvasService"),[new g.BackgroundTool,new g.SizeTool,new g.SceneLayoutService,new g.SceneVisibilityService,new g.ImageTool,new g.WhiteInkTool,new g.MirrorTool,new g.DielineTool,new g.RulerTool,new g.FeatureTool].forEach(o=>{i.extensionManager.register(o)})},V=(e,t)=>{const n=i.getService("CanvasService");n&&n.resize(e,t)};return s.onUnmounted(()=>{const e=i.getService("CanvasService");e&&e.dispose(),x.dispose(),i.extensionManager.destroy()}),(e,t)=>(s.openBlock(),s.createElementBlock("div",A,[s.createVNode(j,{onCanvasReady:U,onResize:V})]))}}),[["__scopeId","data-v-234847f9"]]);u.PooderEditor=z,Object.keys(S).forEach(m=>{m!=="default"&&!Object.prototype.hasOwnProperty.call(u,m)&&Object.defineProperty(u,m,{enumerable:!0,get:()=>S[m]})}),Object.keys(g).forEach(m=>{m!=="default"&&!Object.prototype.hasOwnProperty.call(u,m)&&Object.defineProperty(u,m,{enumerable:!0,get:()=>g[m]})}),Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(u,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("vue"),require("@pooder/core"),require("@pooder/kit")):typeof define=="function"&&define.amd?define(["exports","vue","@pooder/core","@pooder/kit"],s):(u=typeof globalThis<"u"?globalThis:u||self,s(u.PooderVue={},u.Vue,u.PooderCore,u.PooderKit))})(this,(function(u,s,S,g){"use strict";const P=s.defineComponent({__name:"CanvasArea",emits:["canvas-ready","resize"],setup(m,{emit:y}){const h=y,i=s.ref(null),r=s.ref(null);let d=null;return s.onMounted(()=>{if(i.value&&r.value){const{clientWidth:b,clientHeight:C}=i.value;r.value.width=b,r.value.height=C,h("canvas-ready",r.value),d=new ResizeObserver(x=>{for(const _ of x){const{width:I,height:N}=_.contentRect;h("resize",I,N)}}),d.observe(i.value)}}),s.onUnmounted(()=>{d&&d.disconnect()}),(b,C)=>(s.openBlock(),s.createElementBlock("div",{ref_key:"container",ref:i,class:"pooder-canvas-area"},[s.createElementVNode("canvas",{ref_key:"canvas",ref:r},null,512)],512))}}),E=(m,y)=>{const h=m.__vccOpts||m;for(const[i,r]of y)h[i]=r;return h},j=E(P,[["__scopeId","data-v-dc60e8d6"]]),A={class:"pooder-editor"},R="image.user",z=E(s.defineComponent({__name:"PooderEditor",emits:["image-change"],setup(m,{expose:y,emit:h}){const i=new S.Pooder;s.provide("pooder",i);const r=i.getService("CommandService"),d=i.getService("ConfigurationService"),b=i.getService("WorkbenchService"),C=h,x=d.onAnyChange(e=>{e.key==="image.items"&&C("image-change",e.value)}),_=e=>{d.import(e)},I=()=>d.export(),N=()=>d.get("image.items",[]),X=async e=>{try{const t=await r.executeCommand("exportCutImage",e);return t||console.warn("[PooderEditor] generateCutImage returned null",{options:e,imageCount:(d.get("image.items")||[]).length,hasCanvasService:!!i.getService("CanvasService")}),t}catch(t){throw console.error("[PooderEditor] generateCutImage failed",t),t}},T=async(e,t)=>await r.executeCommand("upsertImage",e,{id:t?.id,mode:t?.mode,addOptions:t?.addOptions,fitOnAdd:t?.fitOnAdd}),B=async(e,t)=>(await T(e,{mode:"add",addOptions:t,fitOnAdd:!0})).id,Y=async(e,t)=>await r.executeCommand("updateImage",e,t),W=async()=>await r.executeCommand("clearImages"),H=async(e,t)=>await r.executeCommand("focusImage",e,t),M=e=>Math.max(-1,Math.min(2,e)),L=e=>{const t=e?.cutRect;if(!t)return null;const n=Number(t.width),o=Number(t.height),a=Number(t.left),c=Number(t.top);return!Number.isFinite(n)||!Number.isFinite(o)||!Number.isFinite(a)||!Number.isFinite(c)||n<=0||o<=0?null:{left:a,top:c,width:n,height:o}},F=e=>{if(!e)return[];const t=e.canvas.getObjects(),n=[];for(const o of t){if(o?.data?.layerId!==R)continue;const a=o?.data?.id;if(typeof a!="string")continue;const c=o.getCenterPoint?o.getCenterPoint():null,l=Number(c?.x??o.left),f=Number(c?.y??o.top),w=Number(o.scaleX),p=Number(o.width),v=Number(o.height);!Number.isFinite(l)||!Number.isFinite(f)||!Number.isFinite(w)||!Number.isFinite(p)||!Number.isFinite(v)||p<=0||v<=0||n.push({id:a,centerX:l,centerY:f,objectScale:w,sourceWidth:p,sourceHeight:v})}return n},O=e=>{d.update("dieline.shape","custom"),d.update("dieline.pathData",e.pathData),d.update("size.cutMode","trim"),d.update("size.cutMarginMm",0)},U=(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 c=t.width/n.width,l=t.height/n.height,f=n.x+n.width/2,w=n.y+n.height/2,p=o/2,v=a/2;return{shiftX:(f-p)*c,shiftY:(w-v)*l}},D=async(e,t,n=!1)=>{if(!t.length)return;const o=await r.executeCommand("getSceneLayout"),a=L(o);if(!a)return;const{shiftX:c,shiftY:l}=U(e,a);n&&console.info("[PooderEditor] detectDieline alignment",{frame:a,shiftX:c,shiftY:l,snapshotCount:t.length,baseBounds:e.baseBounds,rawBounds:e.rawBounds,imageWidth:e.imageWidth,imageHeight:e.imageHeight});for(const f of t){const w=Math.max(a.width/Math.max(1,f.sourceWidth),a.height/Math.max(1,f.sourceHeight)),p=Math.max(.05,f.objectScale/w),v=f.centerX-c,G=f.centerY-l,J=M((v-a.left)/Math.max(1,a.width)),K=M((G-a.top)/Math.max(1,a.height));await r.executeCommand("updateImage",f.id,{scale:p,left:J,top:K})}};y({importConfig:_,exportConfig:I,getImages:N,generateCutImage:X,addImage:B,upsertImage:T,updateImage:Y,clearImages:W,focusImage:H,detectDieline:async e=>{const t=i.getService("CanvasService"),n=F(t),o=await r.executeCommand("detectEdge",e,{expand:10,smoothing:!0,simplifyTolerance:2});if(o){O(o);const c=(d.get("image.items")||[]).find(l=>l.url===e);if(c?.id){const l=n.filter(f=>f.id===c.id);await D(o,l)}return o.pathData}return null},detectDielineFromFrame:async e=>{const t=e?.detect?.debug===!0,n=i.getService("CanvasService"),o=F(n),{url:a}=await r.executeCommand("exportImageFrameUrl",{multiplier:2,format:"png"});try{const c=await r.executeCommand("detectEdge",a,{expand:e?.detect?.expand??30,smoothing:e?.detect?.smoothing??!0,simplifyTolerance:e?.detect?.simplifyTolerance??2,debug:t});return c?(e?.commit===!1||(O(c),await D(c,o,t)),c):null}finally{a&&URL.revokeObjectURL(a)}},uploadAndDetectEdge:async(e,t)=>{const n=i.getService("CanvasService"),o=await B(e),a=F(n).filter(l=>l.id===o),c=await r.executeCommand("detectEdge",e,{expand:t?.expand??10,smoothing:t?.smoothing??!0,simplifyTolerance:t?.simplifyTolerance??2});return c?(O(c),await D(c,a),{imageId:o,url:e,pathData:c.pathData}):null},activateTool:async e=>await b.switchTool(e),deactivateTool:async()=>await b.deactivate(),on:(e,t)=>i.eventBus.on(e,t),off:(e,t)=>i.eventBus.off(e,t),emit:(e,t)=>i.eventBus.emit(e,t),executeCommand:(e,...t)=>r.executeCommand(e,...t),getConfig:e=>d.get(e),updateConfig:(e,t)=>d.update(e,t),services:{workbench:b,command:r,config:d}});const V=e=>{const t=new g.CanvasService(e,{eventBus:i.eventBus});i.registerService(t,"CanvasService"),[new g.BackgroundTool,new g.SizeTool,new g.SceneLayoutService,new g.SceneVisibilityService,new g.ImageTool,new g.WhiteInkTool,new g.MirrorTool,new g.DielineTool,new g.RulerTool,new g.FeatureTool].forEach(o=>{i.extensionManager.register(o)})},q=(e,t)=>{const n=i.getService("CanvasService");n&&n.resize(e,t)};return s.onUnmounted(()=>{const e=i.getService("CanvasService");e&&e.dispose(),x.dispose(),i.extensionManager.destroy()}),(e,t)=>(s.openBlock(),s.createElementBlock("div",A,[s.createVNode(j,{onCanvasReady:V,onResize:q})]))}}),[["__scopeId","data-v-522d075c"]]);u.PooderEditor=z,Object.keys(S).forEach(m=>{m!=="default"&&!Object.prototype.hasOwnProperty.call(u,m)&&Object.defineProperty(u,m,{enumerable:!0,get:()=>S[m]})}),Object.keys(g).forEach(m=>{m!=="default"&&!Object.prototype.hasOwnProperty.call(u,m)&&Object.defineProperty(u,m,{enumerable:!0,get:()=>g[m]})}),Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
@@ -22,13 +22,15 @@ declare const _default: import('vue').DefineComponent<{}, {
22
22
  addImage: (url: string, options?: any) => Promise<any>;
23
23
  upsertImage: (url: string, options?: {
24
24
  id?: string;
25
- mode?: "auto" | "replace" | "add";
26
- createIfMissing?: boolean;
25
+ mode?: "replace" | "add";
27
26
  addOptions?: any;
28
27
  fitOnAdd?: boolean;
29
28
  }) => Promise<any>;
30
29
  updateImage: (id: string, options?: any) => Promise<any>;
31
30
  clearImages: () => Promise<any>;
31
+ focusImage: (id: string | null, options?: {
32
+ syncCanvasSelection?: boolean;
33
+ }) => Promise<any>;
32
34
  detectDieline: (url: string) => Promise<string | null>;
33
35
  detectDielineFromFrame: (options?: {
34
36
  detect?: {
package/dist/vue.css CHANGED
@@ -1 +1 @@
1
- .pooder-canvas-area[data-v-dc60e8d6]{flex:1;width:100%;height:100%;min-height:650px;min-width:650px;overflow:hidden;background:#f5f5f5;position:relative}canvas[data-v-dc60e8d6]{display:block}.pooder-editor[data-v-234847f9]{display:flex;width:100%;height:100%;overflow:hidden}
1
+ .pooder-canvas-area[data-v-dc60e8d6]{flex:1;width:100%;height:100%;min-height:650px;min-width:650px;overflow:hidden;background:#f5f5f5;position:relative}canvas[data-v-dc60e8d6]{display:block}.pooder-editor[data-v-522d075c]{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.3",
3
+ "version": "4.2.4",
4
4
  "main": "./dist/index.umd.js",
5
5
  "module": "./dist/index.es.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@pooder/core": "2.1.0",
23
- "@pooder/kit": "5.0.3"
23
+ "@pooder/kit": "5.0.4"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "vue": "^3.0.0"