@pooder/vue 4.1.0 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +67 -53
- package/dist/index.umd.js +1 -1
- package/dist/vue.css +1 -1
- package/package.json +3 -3
package/dist/index.es.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { Pooder as
|
|
1
|
+
import { defineComponent as T, ref as b, onMounted as F, onUnmounted as k, createElementBlock as B, openBlock as D, createElementVNode as L, provide as U, createVNode as $ } from "vue";
|
|
2
|
+
import { Pooder as q } from "@pooder/core";
|
|
3
3
|
export * from "@pooder/core";
|
|
4
|
-
import { CanvasService as
|
|
4
|
+
import { CanvasService as J, BackgroundTool as K, ImageTool as Q, MirrorTool as Z, DielineTool as ee, RulerTool as te, FeatureTool as ne } from "@pooder/kit";
|
|
5
5
|
export * from "@pooder/kit";
|
|
6
|
-
const
|
|
6
|
+
const ae = /* @__PURE__ */ T({
|
|
7
7
|
__name: "CanvasArea",
|
|
8
8
|
emits: ["canvas-ready", "resize"],
|
|
9
|
-
setup(
|
|
10
|
-
const
|
|
9
|
+
setup(f, { emit: v }) {
|
|
10
|
+
const d = v, t = b(null), a = b(null);
|
|
11
11
|
let o = null;
|
|
12
|
-
return
|
|
12
|
+
return F(() => {
|
|
13
13
|
if (t.value && a.value) {
|
|
14
|
-
const { clientWidth:
|
|
15
|
-
a.value.width =
|
|
16
|
-
for (const
|
|
17
|
-
const { width:
|
|
18
|
-
|
|
14
|
+
const { clientWidth: u, clientHeight: h } = t.value;
|
|
15
|
+
a.value.width = u, a.value.height = h, d("canvas-ready", a.value), o = new ResizeObserver((w) => {
|
|
16
|
+
for (const _ of w) {
|
|
17
|
+
const { width: S, height: I } = _.contentRect;
|
|
18
|
+
d("resize", S, I);
|
|
19
19
|
}
|
|
20
20
|
}), o.observe(t.value);
|
|
21
21
|
}
|
|
22
|
-
}),
|
|
22
|
+
}), k(() => {
|
|
23
23
|
o && o.disconnect();
|
|
24
|
-
}), (
|
|
24
|
+
}), (u, h) => (D(), B("div", {
|
|
25
25
|
ref_key: "container",
|
|
26
26
|
ref: t,
|
|
27
27
|
class: "pooder-canvas-area"
|
|
28
28
|
}, [
|
|
29
|
-
|
|
29
|
+
L("canvas", {
|
|
30
30
|
ref_key: "canvas",
|
|
31
31
|
ref: a
|
|
32
32
|
}, null, 512)
|
|
33
33
|
], 512));
|
|
34
34
|
}
|
|
35
|
-
}),
|
|
36
|
-
const
|
|
37
|
-
for (const [t, a] of
|
|
38
|
-
|
|
39
|
-
return
|
|
40
|
-
},
|
|
35
|
+
}), E = (f, v) => {
|
|
36
|
+
const d = f.__vccOpts || f;
|
|
37
|
+
for (const [t, a] of v)
|
|
38
|
+
d[t] = a;
|
|
39
|
+
return d;
|
|
40
|
+
}, oe = /* @__PURE__ */ E(ae, [["__scopeId", "data-v-ba73979d"]]), ce = { class: "pooder-editor" }, ie = /* @__PURE__ */ T({
|
|
41
41
|
__name: "PooderEditor",
|
|
42
42
|
emits: ["image-change"],
|
|
43
|
-
setup(
|
|
44
|
-
const t = new
|
|
45
|
-
|
|
46
|
-
const a = t.getService("CommandService"), o = t.getService("ConfigurationService"),
|
|
47
|
-
e.key === "image.items" &&
|
|
43
|
+
setup(f, { expose: v, emit: d }) {
|
|
44
|
+
const t = new q();
|
|
45
|
+
U("pooder", t);
|
|
46
|
+
const a = t.getService("CommandService"), o = t.getService("ConfigurationService"), u = t.getService("WorkbenchService"), h = d, w = o.onAnyChange((e) => {
|
|
47
|
+
e.key === "image.items" && h("image-change", e.value);
|
|
48
48
|
});
|
|
49
|
-
|
|
49
|
+
v({
|
|
50
50
|
importConfig: (e) => {
|
|
51
51
|
o.import(e);
|
|
52
52
|
},
|
|
@@ -56,12 +56,12 @@ const $ = /* @__PURE__ */ w({
|
|
|
56
56
|
addImage: async (e, n) => {
|
|
57
57
|
const c = await a.executeCommand("addImage", e, n), i = await a.executeCommand("getGeometry"), s = t.getService("CanvasService");
|
|
58
58
|
if (i && s) {
|
|
59
|
-
const
|
|
59
|
+
const r = s.canvas.width, p = s.canvas.height, m = (o.get("dieline.offset") || 0) * i.scale, y = i.width + 2 * m, C = i.height + 2 * m, g = i.x / r, l = i.y / p;
|
|
60
60
|
await a.executeCommand("fitImageToArea", c, {
|
|
61
|
-
width:
|
|
62
|
-
height:
|
|
63
|
-
left:
|
|
64
|
-
top:
|
|
61
|
+
width: y,
|
|
62
|
+
height: C,
|
|
63
|
+
left: g,
|
|
64
|
+
top: l
|
|
65
65
|
});
|
|
66
66
|
} else s && await a.executeCommand("fitImageToArea", c, {
|
|
67
67
|
width: s.canvas.width,
|
|
@@ -83,12 +83,26 @@ const $ = /* @__PURE__ */ w({
|
|
|
83
83
|
// 平滑度容差,值越大越圆润
|
|
84
84
|
});
|
|
85
85
|
if (n) {
|
|
86
|
-
const { pathData: c, width: i, height: s } = n;
|
|
87
|
-
|
|
86
|
+
const { pathData: c, width: i, height: s, rawBounds: r, imageWidth: p, imageHeight: x } = n;
|
|
87
|
+
if (o.update("dieline.shape", "custom"), o.update("dieline.pathData", c), o.update("dieline.width", i), o.update("dieline.height", s), o.update("dieline.offset", 0), r && p && x) {
|
|
88
|
+
const m = t.getService("CanvasService"), C = (o.get("image.items") || []).find((g) => g.url === e);
|
|
89
|
+
if (m && C) {
|
|
90
|
+
const g = await a.executeCommand("getGeometry");
|
|
91
|
+
if (g) {
|
|
92
|
+
const l = g.width / r.width, z = p / 2, A = x / 2, H = r.x + r.width / 2, R = r.y + r.height / 2, M = H - z, X = R - A, Y = M * l, P = X * l, j = m.canvas.width, G = m.canvas.height, N = 0.5 - Y / j, V = 0.5 - P / G;
|
|
93
|
+
await a.executeCommand("updateImage", C.id, {
|
|
94
|
+
scale: l,
|
|
95
|
+
left: N,
|
|
96
|
+
top: V
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return c;
|
|
88
102
|
}
|
|
89
103
|
return null;
|
|
90
104
|
},
|
|
91
|
-
activateTool: (e) =>
|
|
105
|
+
activateTool: (e) => u.activate(e),
|
|
92
106
|
on: (e, n) => t.eventBus.on(e, n),
|
|
93
107
|
off: (e, n) => t.eventBus.off(e, n),
|
|
94
108
|
emit: (e, n) => t.eventBus.emit(e, n),
|
|
@@ -96,42 +110,42 @@ const $ = /* @__PURE__ */ w({
|
|
|
96
110
|
getConfig: (e) => o.get(e),
|
|
97
111
|
updateConfig: (e, n) => o.update(e, n),
|
|
98
112
|
services: {
|
|
99
|
-
workbench:
|
|
113
|
+
workbench: u,
|
|
100
114
|
command: a,
|
|
101
115
|
config: o
|
|
102
116
|
}
|
|
103
117
|
});
|
|
104
|
-
const
|
|
105
|
-
const n = new
|
|
118
|
+
const O = (e) => {
|
|
119
|
+
const n = new J(e, {
|
|
106
120
|
eventBus: t.eventBus
|
|
107
121
|
});
|
|
108
122
|
t.registerService(n, "CanvasService"), [
|
|
109
|
-
new
|
|
110
|
-
new
|
|
123
|
+
new K(),
|
|
124
|
+
new Q(),
|
|
111
125
|
// new FilmTool(),
|
|
112
126
|
// new WhiteInkTool(),
|
|
113
|
-
new
|
|
114
|
-
new
|
|
115
|
-
new
|
|
116
|
-
new
|
|
127
|
+
new Z(),
|
|
128
|
+
new ee(),
|
|
129
|
+
new te(),
|
|
130
|
+
new ne()
|
|
117
131
|
].forEach((i) => {
|
|
118
132
|
t.extensionManager.register(i);
|
|
119
133
|
});
|
|
120
|
-
},
|
|
134
|
+
}, W = (e, n) => {
|
|
121
135
|
const c = t.getService("CanvasService");
|
|
122
136
|
c && c.canvas.setDimensions({ width: e, height: n });
|
|
123
137
|
};
|
|
124
|
-
return
|
|
138
|
+
return k(() => {
|
|
125
139
|
const e = t.getService("CanvasService");
|
|
126
|
-
e && e.dispose(),
|
|
127
|
-
}), (e, n) => (
|
|
128
|
-
|
|
129
|
-
onCanvasReady:
|
|
130
|
-
onResize:
|
|
140
|
+
e && e.dispose(), w.dispose(), t.extensionManager.destroy();
|
|
141
|
+
}), (e, n) => (D(), B("div", ce, [
|
|
142
|
+
$(oe, {
|
|
143
|
+
onCanvasReady: O,
|
|
144
|
+
onResize: W
|
|
131
145
|
})
|
|
132
146
|
]));
|
|
133
147
|
}
|
|
134
|
-
}),
|
|
148
|
+
}), fe = /* @__PURE__ */ E(ie, [["__scopeId", "data-v-51bac65f"]]);
|
|
135
149
|
export {
|
|
136
|
-
|
|
150
|
+
fe as PooderEditor
|
|
137
151
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("vue"),require("@pooder/core"),require("@pooder/kit")):typeof define=="function"&&define.amd?define(["exports","vue","@pooder/core","@pooder/kit"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.PooderVue={},s.Vue,s.PooderCore,s.PooderKit))})(this,(function(s,c,S,m){"use strict";const j=c.defineComponent({__name:"CanvasArea",emits:["canvas-ready","resize"],setup(i,{emit:p}){const u=p,t=c.ref(null),o=c.ref(null);let a=null;return c.onMounted(()=>{if(t.value&&o.value){const{clientWidth:h,clientHeight:w}=t.value;o.value.width=h,o.value.height=w,u("canvas-ready",o.value),a=new ResizeObserver(x=>{for(const O of x){const{width:T,height:P}=O.contentRect;u("resize",T,P)}}),a.observe(t.value)}}),c.onUnmounted(()=>{a&&a.disconnect()}),(h,w)=>(c.openBlock(),c.createElementBlock("div",{ref_key:"container",ref:t,class:"pooder-canvas-area"},[c.createElementVNode("canvas",{ref_key:"canvas",ref:o},null,512)],512))}}),b=(i,p)=>{const u=i.__vccOpts||i;for(const[t,o]of p)u[t]=o;return u},E=b(j,[["__scopeId","data-v-ba73979d"]]),D={class:"pooder-editor"},W=b(c.defineComponent({__name:"PooderEditor",emits:["image-change"],setup(i,{expose:p,emit:u}){const t=new S.Pooder;c.provide("pooder",t);const o=t.getService("CommandService"),a=t.getService("ConfigurationService"),h=t.getService("WorkbenchService"),w=u,x=a.onAnyChange(e=>{e.key==="image.items"&&w("image-change",e.value)});p({importConfig:e=>{a.import(e)},exportConfig:()=>a.export(),getImages:()=>a.get("image.items",[]),generateCutImage:async()=>await o.executeCommand("exportCutImage"),addImage:async(e,n)=>{const r=await o.executeCommand("addImage",e,n),d=await o.executeCommand("getGeometry"),g=t.getService("CanvasService");if(d&&g){const f=g.canvas.width,y=g.canvas.height,l=(a.get("dieline.offset")||0)*d.scale,B=d.width+2*l,_=d.height+2*l,v=d.x/f,C=d.y/y;await o.executeCommand("fitImageToArea",r,{width:B,height:_,left:v,top:C})}else g&&await o.executeCommand("fitImageToArea",r,{width:g.canvas.width,height:g.canvas.height,left:.5,top:.5});return r},updateImage:async(e,n)=>await o.executeCommand("updateImage",e,n),clearImages:async()=>await o.executeCommand("clearImages"),detectDieline:async e=>{const n=await o.executeCommand("detectEdge",e,{expand:10,smoothing:!0,simplifyTolerance:2});if(n){const{pathData:r,width:d,height:g,rawBounds:f,imageWidth:y,imageHeight:I}=n;if(a.update("dieline.shape","custom"),a.update("dieline.pathData",r),a.update("dieline.width",d),a.update("dieline.height",g),a.update("dieline.offset",0),f&&y&&I){const l=t.getService("CanvasService"),_=(a.get("image.items")||[]).find(v=>v.url===e);if(l&&_){const v=await o.executeCommand("getGeometry");if(v){const C=v.width/f.width,H=y/2,M=I/2,R=f.x+f.width/2,V=f.y+f.height/2,X=R-H,Y=V-M,q=X*C,G=Y*C,N=l.canvas.width,U=l.canvas.height,k=.5-q/N,F=.5-G/U;await o.executeCommand("updateImage",_.id,{scale:C,left:k,top:F})}}}return r}return null},activateTool:e=>h.activate(e),on:(e,n)=>t.eventBus.on(e,n),off:(e,n)=>t.eventBus.off(e,n),emit:(e,n)=>t.eventBus.emit(e,n),executeCommand:(e,...n)=>o.executeCommand(e,...n),getConfig:e=>a.get(e),updateConfig:(e,n)=>a.update(e,n),services:{workbench:h,command:o,config:a}});const z=e=>{const n=new m.CanvasService(e,{eventBus:t.eventBus});t.registerService(n,"CanvasService"),[new m.BackgroundTool,new m.ImageTool,new m.MirrorTool,new m.DielineTool,new m.RulerTool,new m.FeatureTool].forEach(d=>{t.extensionManager.register(d)})},A=(e,n)=>{const r=t.getService("CanvasService");r&&r.canvas.setDimensions({width:e,height:n})};return c.onUnmounted(()=>{const e=t.getService("CanvasService");e&&e.dispose(),x.dispose(),t.extensionManager.destroy()}),(e,n)=>(c.openBlock(),c.createElementBlock("div",D,[c.createVNode(E,{onCanvasReady:z,onResize:A})]))}}),[["__scopeId","data-v-51bac65f"]]);s.PooderEditor=W,Object.keys(S).forEach(i=>{i!=="default"&&!Object.prototype.hasOwnProperty.call(s,i)&&Object.defineProperty(s,i,{enumerable:!0,get:()=>S[i]})}),Object.keys(m).forEach(i=>{i!=="default"&&!Object.prototype.hasOwnProperty.call(s,i)&&Object.defineProperty(s,i,{enumerable:!0,get:()=>m[i]})}),Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/vue.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.pooder-canvas-area[data-v-
|
|
1
|
+
.pooder-canvas-area[data-v-ba73979d]{flex:1;width:100%;height:100%;min-height:650px;min-width:650px;overflow:hidden;background:#f5f5f5;position:relative}canvas[data-v-ba73979d]{display:block}.pooder-editor[data-v-51bac65f]{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.1.2",
|
|
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/kit": "4.3.1",
|
|
23
|
+
"@pooder/core": "2.0.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"vue": "^3.0.0"
|