@pooder/vue 4.1.2 → 4.2.1
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 +203 -107
- package/dist/index.umd.js +1 -1
- package/dist/vue/src/PooderEditor.vue.d.ts +44 -3
- package/dist/vue.css +1 -1
- package/package.json +3 -3
package/dist/index.es.js
CHANGED
|
@@ -1,80 +1,152 @@
|
|
|
1
|
-
import { defineComponent as T, ref as
|
|
2
|
-
import { Pooder as
|
|
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";
|
|
3
3
|
export * from "@pooder/core";
|
|
4
|
-
import { CanvasService as
|
|
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";
|
|
5
5
|
export * from "@pooder/kit";
|
|
6
|
-
const
|
|
6
|
+
const re = /* @__PURE__ */ T({
|
|
7
7
|
__name: "CanvasArea",
|
|
8
8
|
emits: ["canvas-ready", "resize"],
|
|
9
|
-
setup(
|
|
10
|
-
const
|
|
11
|
-
let
|
|
12
|
-
return
|
|
13
|
-
if (
|
|
14
|
-
const { clientWidth:
|
|
15
|
-
|
|
16
|
-
for (const
|
|
17
|
-
const { width: S, height:
|
|
18
|
-
|
|
9
|
+
setup(p, { emit: v }) {
|
|
10
|
+
const u = v, o = M(null), r = M(null);
|
|
11
|
+
let s = null;
|
|
12
|
+
return U(() => {
|
|
13
|
+
if (o.value && r.value) {
|
|
14
|
+
const { clientWidth: h, clientHeight: w } = o.value;
|
|
15
|
+
r.value.width = h, r.value.height = w, u("canvas-ready", r.value), s = new ResizeObserver((C) => {
|
|
16
|
+
for (const b of C) {
|
|
17
|
+
const { width: S, height: x } = b.contentRect;
|
|
18
|
+
u("resize", S, x);
|
|
19
19
|
}
|
|
20
|
-
}),
|
|
20
|
+
}), s.observe(o.value);
|
|
21
21
|
}
|
|
22
|
-
}),
|
|
23
|
-
|
|
24
|
-
}), (
|
|
22
|
+
}), E(() => {
|
|
23
|
+
s && s.disconnect();
|
|
24
|
+
}), (h, w) => (O(), B("div", {
|
|
25
25
|
ref_key: "container",
|
|
26
|
-
ref:
|
|
26
|
+
ref: o,
|
|
27
27
|
class: "pooder-canvas-area"
|
|
28
28
|
}, [
|
|
29
|
-
|
|
29
|
+
V("canvas", {
|
|
30
30
|
ref_key: "canvas",
|
|
31
|
-
ref:
|
|
31
|
+
ref: r
|
|
32
32
|
}, null, 512)
|
|
33
33
|
], 512));
|
|
34
34
|
}
|
|
35
|
-
}),
|
|
36
|
-
const
|
|
37
|
-
for (const [
|
|
38
|
-
|
|
39
|
-
return
|
|
40
|
-
},
|
|
35
|
+
}), k = (p, v) => {
|
|
36
|
+
const u = p.__vccOpts || p;
|
|
37
|
+
for (const [o, r] of v)
|
|
38
|
+
u[o] = r;
|
|
39
|
+
return u;
|
|
40
|
+
}, se = /* @__PURE__ */ k(re, [["__scopeId", "data-v-dc60e8d6"]]), de = { class: "pooder-editor" }, me = "image.user", ue = /* @__PURE__ */ T({
|
|
41
41
|
__name: "PooderEditor",
|
|
42
42
|
emits: ["image-change"],
|
|
43
|
-
setup(
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
e.key === "image.items" &&
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
43
|
+
setup(p, { expose: v, emit: u }) {
|
|
44
|
+
const o = new $();
|
|
45
|
+
G("pooder", o);
|
|
46
|
+
const r = o.getService("CommandService"), s = o.getService("ConfigurationService"), h = o.getService("WorkbenchService"), w = u, C = s.onAnyChange((e) => {
|
|
47
|
+
e.key === "image.items" && w("image-change", e.value);
|
|
48
|
+
}), b = (e) => {
|
|
49
|
+
s.import(e);
|
|
50
|
+
}, S = () => s.export(), x = () => s.get("image.items", []), A = async (e) => {
|
|
51
|
+
try {
|
|
52
|
+
const t = await r.executeCommand(
|
|
53
|
+
"exportCutImage",
|
|
54
|
+
e
|
|
55
|
+
);
|
|
56
|
+
return t || console.warn("[PooderEditor] generateCutImage returned null", {
|
|
57
|
+
options: e,
|
|
58
|
+
imageCount: (s.get("image.items") || []).length,
|
|
59
|
+
hasCanvasService: !!o.getService("CanvasService")
|
|
60
|
+
}), t;
|
|
61
|
+
} catch (t) {
|
|
62
|
+
throw console.error("[PooderEditor] generateCutImage failed", t), t;
|
|
63
|
+
}
|
|
64
|
+
}, N = async (e, t) => await r.executeCommand("upsertImage", e, {
|
|
65
|
+
id: t?.id,
|
|
66
|
+
mode: t?.mode,
|
|
67
|
+
createIfMissing: t?.createIfMissing,
|
|
68
|
+
addOptions: t?.addOptions,
|
|
69
|
+
fitOnAdd: t?.fitOnAdd
|
|
70
|
+
}), F = async (e, t) => (await N(e, {
|
|
71
|
+
mode: "add",
|
|
72
|
+
addOptions: t,
|
|
73
|
+
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) => {
|
|
75
|
+
const t = e?.cutRect;
|
|
76
|
+
if (!t) return null;
|
|
77
|
+
const n = Number(t.width), a = Number(t.height), i = Number(t.left), c = Number(t.top);
|
|
78
|
+
return !Number.isFinite(n) || !Number.isFinite(a) || !Number.isFinite(i) || !Number.isFinite(c) || n <= 0 || a <= 0 ? null : { left: i, top: c, width: n, height: a };
|
|
79
|
+
}, y = (e) => {
|
|
80
|
+
if (!e) return [];
|
|
81
|
+
const t = e.canvas.getObjects(), n = [];
|
|
82
|
+
for (const a of t) {
|
|
83
|
+
if (a?.data?.layerId !== me) continue;
|
|
84
|
+
const i = a?.data?.id;
|
|
85
|
+
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({
|
|
88
|
+
id: i,
|
|
89
|
+
centerX: d,
|
|
90
|
+
centerY: m,
|
|
91
|
+
objectScale: f,
|
|
92
|
+
sourceWidth: g,
|
|
93
|
+
sourceHeight: l
|
|
71
94
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
95
|
+
}
|
|
96
|
+
return n;
|
|
97
|
+
}, _ = (e) => {
|
|
98
|
+
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) => {
|
|
100
|
+
const n = e.rawBounds || e.baseBounds, a = Number(e.imageWidth ?? 0), i = Number(e.imageHeight ?? 0);
|
|
101
|
+
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
|
+
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;
|
|
104
|
+
return {
|
|
105
|
+
shiftX: (m - g) * c,
|
|
106
|
+
shiftY: (f - l) * d
|
|
107
|
+
};
|
|
108
|
+
}, I = async (e, t, n = !1) => {
|
|
109
|
+
if (!t.length) return;
|
|
110
|
+
const a = await r.executeCommand("getSceneLayout"), i = X(a);
|
|
111
|
+
if (!i) return;
|
|
112
|
+
const { shiftX: c, shiftY: d } = Y(e, i);
|
|
113
|
+
n && console.info("[PooderEditor] detectDieline alignment", {
|
|
114
|
+
frame: i,
|
|
115
|
+
shiftX: c,
|
|
116
|
+
shiftY: d,
|
|
117
|
+
snapshotCount: t.length,
|
|
118
|
+
baseBounds: e.baseBounds,
|
|
119
|
+
rawBounds: e.rawBounds,
|
|
120
|
+
imageWidth: e.imageWidth,
|
|
121
|
+
imageHeight: e.imageHeight
|
|
122
|
+
});
|
|
123
|
+
for (const m of t) {
|
|
124
|
+
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(
|
|
128
|
+
(l - i.left) / Math.max(1, i.width)
|
|
129
|
+
), L = D(
|
|
130
|
+
(P - i.top) / Math.max(1, i.height)
|
|
131
|
+
);
|
|
132
|
+
await r.executeCommand("updateImage", m.id, {
|
|
133
|
+
scale: g,
|
|
134
|
+
left: H,
|
|
135
|
+
top: L
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
v({
|
|
140
|
+
importConfig: b,
|
|
141
|
+
exportConfig: S,
|
|
142
|
+
getImages: x,
|
|
143
|
+
generateCutImage: A,
|
|
144
|
+
addImage: F,
|
|
145
|
+
upsertImage: N,
|
|
146
|
+
updateImage: R,
|
|
147
|
+
clearImages: z,
|
|
76
148
|
detectDieline: async (e) => {
|
|
77
|
-
const n = await
|
|
149
|
+
const t = o.getService("CanvasService"), n = y(t), a = await r.executeCommand("detectEdge", e, {
|
|
78
150
|
expand: 10,
|
|
79
151
|
// 安全距离(像素)
|
|
80
152
|
smoothing: !0,
|
|
@@ -82,70 +154,94 @@ const ae = /* @__PURE__ */ T({
|
|
|
82
154
|
simplifyTolerance: 2
|
|
83
155
|
// 平滑度容差,值越大越圆润
|
|
84
156
|
});
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
await a.executeCommand("updateImage", C.id, {
|
|
94
|
-
scale: l,
|
|
95
|
-
left: N,
|
|
96
|
-
top: V
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}
|
|
157
|
+
if (a) {
|
|
158
|
+
_(a);
|
|
159
|
+
const c = (s.get("image.items") || []).find((d) => d.url === e);
|
|
160
|
+
if (c?.id) {
|
|
161
|
+
const d = n.filter(
|
|
162
|
+
(m) => m.id === c.id
|
|
163
|
+
);
|
|
164
|
+
await I(a, d);
|
|
100
165
|
}
|
|
101
|
-
return
|
|
166
|
+
return a.pathData;
|
|
102
167
|
}
|
|
103
168
|
return null;
|
|
104
169
|
},
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
170
|
+
detectDielineFromFrame: async (e) => {
|
|
171
|
+
const t = e?.detect?.debug === !0, n = o.getService("CanvasService"), a = y(n), { url: i } = await r.executeCommand("exportImageFrameUrl", {
|
|
172
|
+
multiplier: 2,
|
|
173
|
+
format: "png"
|
|
174
|
+
});
|
|
175
|
+
try {
|
|
176
|
+
const c = await r.executeCommand("detectEdge", i, {
|
|
177
|
+
expand: e?.detect?.expand ?? 30,
|
|
178
|
+
smoothing: e?.detect?.smoothing ?? !0,
|
|
179
|
+
simplifyTolerance: e?.detect?.simplifyTolerance ?? 2,
|
|
180
|
+
debug: t
|
|
181
|
+
});
|
|
182
|
+
return c ? (e?.commit === !1 || (_(c), await I(c, a, t)), c) : null;
|
|
183
|
+
} finally {
|
|
184
|
+
i && URL.revokeObjectURL(i);
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
uploadAndDetectEdge: async (e, t) => {
|
|
188
|
+
const n = o.getService("CanvasService"), a = await F(e), i = y(n).filter(
|
|
189
|
+
(d) => d.id === a
|
|
190
|
+
), c = await r.executeCommand("detectEdge", e, {
|
|
191
|
+
expand: t?.expand ?? 10,
|
|
192
|
+
smoothing: t?.smoothing ?? !0,
|
|
193
|
+
simplifyTolerance: t?.simplifyTolerance ?? 2
|
|
194
|
+
});
|
|
195
|
+
return c ? (_(c), await I(c, i), { imageId: a, url: e, pathData: c.pathData }) : null;
|
|
196
|
+
},
|
|
197
|
+
activateTool: async (e) => await h.switchTool(e),
|
|
198
|
+
deactivateTool: async () => await h.deactivate(),
|
|
199
|
+
on: (e, t) => o.eventBus.on(e, t),
|
|
200
|
+
off: (e, t) => o.eventBus.off(e, t),
|
|
201
|
+
emit: (e, t) => o.eventBus.emit(e, t),
|
|
202
|
+
executeCommand: (e, ...t) => r.executeCommand(e, ...t),
|
|
203
|
+
getConfig: (e) => s.get(e),
|
|
204
|
+
updateConfig: (e, t) => s.update(e, t),
|
|
112
205
|
services: {
|
|
113
|
-
workbench:
|
|
114
|
-
command:
|
|
115
|
-
config:
|
|
206
|
+
workbench: h,
|
|
207
|
+
command: r,
|
|
208
|
+
config: s
|
|
116
209
|
}
|
|
117
210
|
});
|
|
118
|
-
const
|
|
119
|
-
const
|
|
120
|
-
eventBus:
|
|
211
|
+
const W = (e) => {
|
|
212
|
+
const t = new q(e, {
|
|
213
|
+
eventBus: o.eventBus
|
|
121
214
|
});
|
|
122
|
-
|
|
215
|
+
o.registerService(t, "CanvasService"), [
|
|
123
216
|
new K(),
|
|
124
217
|
new Q(),
|
|
125
|
-
// new FilmTool(),
|
|
126
|
-
// new WhiteInkTool(),
|
|
127
218
|
new Z(),
|
|
128
219
|
new ee(),
|
|
129
220
|
new te(),
|
|
130
|
-
new
|
|
131
|
-
|
|
132
|
-
|
|
221
|
+
// new FilmTool(),
|
|
222
|
+
new ne(),
|
|
223
|
+
new ae(),
|
|
224
|
+
new ie(),
|
|
225
|
+
new oe(),
|
|
226
|
+
new ce()
|
|
227
|
+
].forEach((a) => {
|
|
228
|
+
o.extensionManager.register(a);
|
|
133
229
|
});
|
|
134
|
-
},
|
|
135
|
-
const
|
|
136
|
-
|
|
230
|
+
}, j = (e, t) => {
|
|
231
|
+
const n = o.getService("CanvasService");
|
|
232
|
+
n && n.resize(e, t);
|
|
137
233
|
};
|
|
138
|
-
return
|
|
139
|
-
const e =
|
|
140
|
-
e && e.dispose(),
|
|
141
|
-
}), (e,
|
|
142
|
-
|
|
143
|
-
onCanvasReady:
|
|
144
|
-
onResize:
|
|
234
|
+
return E(() => {
|
|
235
|
+
const e = o.getService("CanvasService");
|
|
236
|
+
e && e.dispose(), C.dispose(), o.extensionManager.destroy();
|
|
237
|
+
}), (e, t) => (O(), B("div", de, [
|
|
238
|
+
J(se, {
|
|
239
|
+
onCanvasReady: W,
|
|
240
|
+
onResize: j
|
|
145
241
|
})
|
|
146
242
|
]));
|
|
147
243
|
}
|
|
148
|
-
}),
|
|
244
|
+
}), we = /* @__PURE__ */ k(ue, [["__scopeId", "data-v-234847f9"]]);
|
|
149
245
|
export {
|
|
150
|
-
|
|
246
|
+
we as PooderEditor
|
|
151
247
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s
|
|
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,14 +1,55 @@
|
|
|
1
1
|
import { CommandService, ConfigurationService, WorkbenchService } from '../../core/src/index.ts';
|
|
2
|
+
interface DetectBounds {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
interface DetectEdgeResult {
|
|
9
|
+
pathData: string;
|
|
10
|
+
rawBounds?: DetectBounds;
|
|
11
|
+
baseBounds?: DetectBounds;
|
|
12
|
+
imageWidth?: number;
|
|
13
|
+
imageHeight?: number;
|
|
14
|
+
}
|
|
2
15
|
declare const _default: import('vue').DefineComponent<{}, {
|
|
3
16
|
importConfig: (config: Record<string, any>) => void;
|
|
4
17
|
exportConfig: () => Record<string, any>;
|
|
5
18
|
getImages: () => never[];
|
|
6
|
-
generateCutImage: (
|
|
19
|
+
generateCutImage: (options?: {
|
|
20
|
+
debug?: boolean;
|
|
21
|
+
}) => Promise<string | null>;
|
|
7
22
|
addImage: (url: string, options?: any) => Promise<any>;
|
|
23
|
+
upsertImage: (url: string, options?: {
|
|
24
|
+
id?: string;
|
|
25
|
+
mode?: "auto" | "replace" | "add";
|
|
26
|
+
createIfMissing?: boolean;
|
|
27
|
+
addOptions?: any;
|
|
28
|
+
fitOnAdd?: boolean;
|
|
29
|
+
}) => Promise<any>;
|
|
8
30
|
updateImage: (id: string, options?: any) => Promise<any>;
|
|
9
31
|
clearImages: () => Promise<any>;
|
|
10
|
-
detectDieline: (url: string) => Promise<
|
|
11
|
-
|
|
32
|
+
detectDieline: (url: string) => Promise<string | null>;
|
|
33
|
+
detectDielineFromFrame: (options?: {
|
|
34
|
+
detect?: {
|
|
35
|
+
expand?: number;
|
|
36
|
+
smoothing?: boolean;
|
|
37
|
+
simplifyTolerance?: number;
|
|
38
|
+
debug?: boolean;
|
|
39
|
+
};
|
|
40
|
+
commit?: boolean;
|
|
41
|
+
}) => Promise<DetectEdgeResult | null>;
|
|
42
|
+
uploadAndDetectEdge: (url: string, options?: {
|
|
43
|
+
expand?: number;
|
|
44
|
+
smoothing?: boolean;
|
|
45
|
+
simplifyTolerance?: number;
|
|
46
|
+
}) => Promise<{
|
|
47
|
+
imageId: any;
|
|
48
|
+
url: string;
|
|
49
|
+
pathData: string;
|
|
50
|
+
} | null>;
|
|
51
|
+
activateTool: (id: string | null) => Promise<import('../../core/src/index.ts/src/services/WorkbenchService').ToolSwitchResult>;
|
|
52
|
+
deactivateTool: () => Promise<import('../../core/src/index.ts/src/services/WorkbenchService').ToolSwitchResult>;
|
|
12
53
|
on: (event: string, handler: any) => void;
|
|
13
54
|
off: (event: string, handler: any) => void;
|
|
14
55
|
emit: (event: string, data: any) => void;
|
package/dist/vue.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.pooder-canvas-area[data-v-
|
|
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}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pooder/vue",
|
|
3
|
-
"version": "4.1
|
|
3
|
+
"version": "4.2.1",
|
|
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/
|
|
23
|
-
"@pooder/
|
|
22
|
+
"@pooder/core": "2.1.0",
|
|
23
|
+
"@pooder/kit": "5.0.1"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"vue": "^3.0.0"
|