@pooder/vue 3.3.0 → 4.0.0
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 +97 -68
- package/dist/index.umd.js +1 -1
- package/dist/vue/src/PooderEditor.vue.d.ts +14 -0
- package/dist/vue.css +1 -1
- package/package.json +3 -3
package/dist/index.es.js
CHANGED
|
@@ -1,108 +1,137 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { Pooder as
|
|
1
|
+
import { defineComponent as w, ref as C, onMounted as z, onUnmounted as _, createElementBlock as x, openBlock as S, createElementVNode as A, provide as R, createVNode as M } from "vue";
|
|
2
|
+
import { Pooder as W } from "@pooder/core";
|
|
3
3
|
export * from "@pooder/core";
|
|
4
|
-
import { CanvasService as
|
|
4
|
+
import { CanvasService as H, BackgroundTool as P, ImageTool as N, MirrorTool as V, DielineTool as F, RulerTool as G, FeatureTool as U } from "@pooder/kit";
|
|
5
5
|
export * from "@pooder/kit";
|
|
6
|
-
const
|
|
6
|
+
const $ = /* @__PURE__ */ w({
|
|
7
7
|
__name: "CanvasArea",
|
|
8
8
|
emits: ["canvas-ready", "resize"],
|
|
9
|
-
setup(
|
|
10
|
-
const
|
|
11
|
-
let
|
|
12
|
-
return
|
|
13
|
-
if (
|
|
14
|
-
const { clientWidth:
|
|
15
|
-
a.value.width =
|
|
16
|
-
for (const
|
|
17
|
-
const { width:
|
|
18
|
-
|
|
9
|
+
setup(v, { emit: d }) {
|
|
10
|
+
const r = d, t = C(null), a = C(null);
|
|
11
|
+
let o = null;
|
|
12
|
+
return z(() => {
|
|
13
|
+
if (t.value && a.value) {
|
|
14
|
+
const { clientWidth: m, clientHeight: g } = t.value;
|
|
15
|
+
a.value.width = m, a.value.height = g, r("canvas-ready", a.value), o = new ResizeObserver((u) => {
|
|
16
|
+
for (const l of u) {
|
|
17
|
+
const { width: f, height: p } = l.contentRect;
|
|
18
|
+
r("resize", f, p);
|
|
19
19
|
}
|
|
20
|
-
}),
|
|
20
|
+
}), o.observe(t.value);
|
|
21
21
|
}
|
|
22
|
-
}),
|
|
23
|
-
|
|
24
|
-
}), (
|
|
22
|
+
}), _(() => {
|
|
23
|
+
o && o.disconnect();
|
|
24
|
+
}), (m, g) => (S(), x("div", {
|
|
25
25
|
ref_key: "container",
|
|
26
|
-
ref:
|
|
26
|
+
ref: t,
|
|
27
27
|
class: "pooder-canvas-area"
|
|
28
28
|
}, [
|
|
29
|
-
|
|
29
|
+
A("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 [
|
|
38
|
-
|
|
39
|
-
return
|
|
40
|
-
},
|
|
35
|
+
}), I = (v, d) => {
|
|
36
|
+
const r = v.__vccOpts || v;
|
|
37
|
+
for (const [t, a] of d)
|
|
38
|
+
r[t] = a;
|
|
39
|
+
return r;
|
|
40
|
+
}, j = /* @__PURE__ */ I($, [["__scopeId", "data-v-ba73979d"]]), q = { class: "pooder-editor" }, J = /* @__PURE__ */ w({
|
|
41
41
|
__name: "PooderEditor",
|
|
42
42
|
emits: ["image-change"],
|
|
43
|
-
setup(
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const a =
|
|
47
|
-
|
|
43
|
+
setup(v, { expose: d, emit: r }) {
|
|
44
|
+
const t = new W();
|
|
45
|
+
R("pooder", t);
|
|
46
|
+
const a = t.getService("CommandService"), o = t.getService("ConfigurationService"), m = t.getService("WorkbenchService"), g = r, u = o.onAnyChange((e) => {
|
|
47
|
+
e.key === "image.items" && g("image-change", e.value);
|
|
48
48
|
});
|
|
49
|
-
|
|
50
|
-
importConfig: (
|
|
51
|
-
|
|
49
|
+
d({
|
|
50
|
+
importConfig: (e) => {
|
|
51
|
+
o.import(e);
|
|
52
52
|
},
|
|
53
|
-
exportConfig: () =>
|
|
54
|
-
getImages: () =>
|
|
53
|
+
exportConfig: () => o.export(),
|
|
54
|
+
getImages: () => o.get("image.items", []),
|
|
55
55
|
generateCutImage: async () => await a.executeCommand("exportCutImage"),
|
|
56
|
-
addImage: async (
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
const
|
|
60
|
-
await a.executeCommand("fitImageToArea",
|
|
61
|
-
width:
|
|
62
|
-
height:
|
|
56
|
+
addImage: async (e, n) => {
|
|
57
|
+
const c = await a.executeCommand("addImage", e, n), i = await a.executeCommand("getGeometry"), s = t.getService("CanvasService");
|
|
58
|
+
if (i && s) {
|
|
59
|
+
const b = s.canvas.width, k = s.canvas.height, h = (o.get("dieline.offset") || 0) * i.scale, B = i.width + 2 * h, D = i.height + 2 * h, E = i.x / b, O = i.y / k;
|
|
60
|
+
await a.executeCommand("fitImageToArea", c, {
|
|
61
|
+
width: B,
|
|
62
|
+
height: D,
|
|
63
63
|
left: E,
|
|
64
|
-
top:
|
|
64
|
+
top: O
|
|
65
65
|
});
|
|
66
|
-
} else
|
|
67
|
-
width:
|
|
68
|
-
height:
|
|
66
|
+
} else s && await a.executeCommand("fitImageToArea", c, {
|
|
67
|
+
width: s.canvas.width,
|
|
68
|
+
height: s.canvas.height,
|
|
69
69
|
left: 0.5,
|
|
70
70
|
top: 0.5
|
|
71
71
|
});
|
|
72
|
-
return
|
|
72
|
+
return c;
|
|
73
73
|
},
|
|
74
|
-
updateImage: async (
|
|
75
|
-
clearImages: async () => await a.executeCommand("clearImages")
|
|
74
|
+
updateImage: async (e, n) => await a.executeCommand("updateImage", e, n),
|
|
75
|
+
clearImages: async () => await a.executeCommand("clearImages"),
|
|
76
|
+
detectDieline: async (e) => {
|
|
77
|
+
const n = await a.executeCommand("detectEdge", e, {
|
|
78
|
+
expand: 10,
|
|
79
|
+
// 安全距离(像素)
|
|
80
|
+
smoothing: !0,
|
|
81
|
+
// 是否平滑
|
|
82
|
+
simplifyTolerance: 2
|
|
83
|
+
// 平滑度容差,值越大越圆润
|
|
84
|
+
});
|
|
85
|
+
if (n) {
|
|
86
|
+
const { pathData: c, width: i, height: s } = n;
|
|
87
|
+
return 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), c;
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
},
|
|
91
|
+
activateTool: (e) => m.activate(e),
|
|
92
|
+
on: (e, n) => t.eventBus.on(e, n),
|
|
93
|
+
off: (e, n) => t.eventBus.off(e, n),
|
|
94
|
+
emit: (e, n) => t.eventBus.emit(e, n),
|
|
95
|
+
executeCommand: (e, ...n) => a.executeCommand(e, ...n),
|
|
96
|
+
getConfig: (e) => o.get(e),
|
|
97
|
+
updateConfig: (e, n) => o.update(e, n),
|
|
98
|
+
services: {
|
|
99
|
+
workbench: m,
|
|
100
|
+
command: a,
|
|
101
|
+
config: o
|
|
102
|
+
}
|
|
76
103
|
});
|
|
77
|
-
const y = (
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
104
|
+
const y = (e) => {
|
|
105
|
+
const n = new H(e, {
|
|
106
|
+
eventBus: t.eventBus
|
|
107
|
+
});
|
|
108
|
+
t.registerService(n, "CanvasService"), [
|
|
109
|
+
new P(),
|
|
81
110
|
new N(),
|
|
82
111
|
// new FilmTool(),
|
|
83
112
|
// new WhiteInkTool(),
|
|
84
113
|
new V(),
|
|
114
|
+
new F(),
|
|
85
115
|
new G(),
|
|
86
|
-
new U()
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
e.extensionManager.register(c);
|
|
116
|
+
new U()
|
|
117
|
+
].forEach((i) => {
|
|
118
|
+
t.extensionManager.register(i);
|
|
90
119
|
});
|
|
91
|
-
}, T = (
|
|
92
|
-
const
|
|
93
|
-
|
|
120
|
+
}, T = (e, n) => {
|
|
121
|
+
const c = t.getService("CanvasService");
|
|
122
|
+
c && c.canvas.setDimensions({ width: e, height: n });
|
|
94
123
|
};
|
|
95
|
-
return
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
}), (
|
|
99
|
-
|
|
124
|
+
return _(() => {
|
|
125
|
+
const e = t.getService("CanvasService");
|
|
126
|
+
e && e.dispose(), u.dispose(), t.extensionManager.destroy();
|
|
127
|
+
}), (e, n) => (S(), x("div", q, [
|
|
128
|
+
M(j, {
|
|
100
129
|
onCanvasReady: y,
|
|
101
130
|
onResize: T
|
|
102
131
|
})
|
|
103
132
|
]));
|
|
104
133
|
}
|
|
105
|
-
}),
|
|
134
|
+
}), ae = /* @__PURE__ */ I(J, [["__scopeId", "data-v-fe0feb51"]]);
|
|
106
135
|
export {
|
|
107
|
-
|
|
136
|
+
ae as PooderEditor
|
|
108
137
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(r,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue"),require("@pooder/core"),require("@pooder/kit")):typeof define=="function"&&define.amd?define(["exports","vue","@pooder/core","@pooder/kit"],o):(r=typeof globalThis<"u"?globalThis:r||self,o(r.PooderVue={},r.Vue,r.PooderCore,r.PooderKit))})(this,(function(r,o,p,m){"use strict";const x=o.defineComponent({__name:"CanvasArea",emits:["canvas-ready","resize"],setup(i,{emit:g}){const f=g,t=o.ref(null),a=o.ref(null);let c=null;return o.onMounted(()=>{if(t.value&&a.value){const{clientWidth:l,clientHeight:v}=t.value;a.value.width=l,a.value.height=v,f("canvas-ready",a.value),c=new ResizeObserver(h=>{for(const w of h){const{width:y,height:_}=w.contentRect;f("resize",y,_)}}),c.observe(t.value)}}),o.onUnmounted(()=>{c&&c.disconnect()}),(l,v)=>(o.openBlock(),o.createElementBlock("div",{ref_key:"container",ref:t,class:"pooder-canvas-area"},[o.createElementVNode("canvas",{ref_key:"canvas",ref:a},null,512)],512))}}),C=(i,g)=>{const f=i.__vccOpts||i;for(const[t,a]of g)f[t]=a;return f},I=C(x,[["__scopeId","data-v-ba73979d"]]),b={class:"pooder-editor"},O=C(o.defineComponent({__name:"PooderEditor",emits:["image-change"],setup(i,{expose:g,emit:f}){const t=new p.Pooder;o.provide("pooder",t);const a=t.getService("CommandService"),c=t.getService("ConfigurationService"),l=t.getService("WorkbenchService"),v=f,h=c.onAnyChange(e=>{e.key==="image.items"&&v("image-change",e.value)});g({importConfig:e=>{c.import(e)},exportConfig:()=>c.export(),getImages:()=>c.get("image.items",[]),generateCutImage:async()=>await a.executeCommand("exportCutImage"),addImage:async(e,n)=>{const s=await a.executeCommand("addImage",e,n),d=await a.executeCommand("getGeometry"),u=t.getService("CanvasService");if(d&&u){const B=u.canvas.width,E=u.canvas.height,S=(c.get("dieline.offset")||0)*d.scale,j=d.width+2*S,D=d.height+2*S,z=d.x/B,A=d.y/E;await a.executeCommand("fitImageToArea",s,{width:j,height:D,left:z,top:A})}else u&&await a.executeCommand("fitImageToArea",s,{width:u.canvas.width,height:u.canvas.height,left:.5,top:.5});return s},updateImage:async(e,n)=>await a.executeCommand("updateImage",e,n),clearImages:async()=>await a.executeCommand("clearImages"),detectDieline:async e=>{const n=await a.executeCommand("detectEdge",e,{expand:10,smoothing:!0,simplifyTolerance:2});if(n){const{pathData:s,width:d,height:u}=n;return c.update("dieline.shape","custom"),c.update("dieline.pathData",s),c.update("dieline.width",d),c.update("dieline.height",u),c.update("dieline.offset",0),s}return null},activateTool:e=>l.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)=>a.executeCommand(e,...n),getConfig:e=>c.get(e),updateConfig:(e,n)=>c.update(e,n),services:{workbench:l,command:a,config:c}});const T=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)})},P=(e,n)=>{const s=t.getService("CanvasService");s&&s.canvas.setDimensions({width:e,height:n})};return o.onUnmounted(()=>{const e=t.getService("CanvasService");e&&e.dispose(),h.dispose(),t.extensionManager.destroy()}),(e,n)=>(o.openBlock(),o.createElementBlock("div",b,[o.createVNode(I,{onCanvasReady:T,onResize:P})]))}}),[["__scopeId","data-v-fe0feb51"]]);r.PooderEditor=O,Object.keys(p).forEach(i=>{i!=="default"&&!Object.prototype.hasOwnProperty.call(r,i)&&Object.defineProperty(r,i,{enumerable:!0,get:()=>p[i]})}),Object.keys(m).forEach(i=>{i!=="default"&&!Object.prototype.hasOwnProperty.call(r,i)&&Object.defineProperty(r,i,{enumerable:!0,get:()=>m[i]})}),Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CommandService, ConfigurationService, WorkbenchService } from '../../core/src/index.ts';
|
|
1
2
|
declare const _default: import('vue').DefineComponent<{}, {
|
|
2
3
|
importConfig: (config: Record<string, any>) => void;
|
|
3
4
|
exportConfig: () => Record<string, any>;
|
|
@@ -6,6 +7,19 @@ declare const _default: import('vue').DefineComponent<{}, {
|
|
|
6
7
|
addImage: (url: string, options?: any) => Promise<any>;
|
|
7
8
|
updateImage: (id: string, options?: any) => Promise<any>;
|
|
8
9
|
clearImages: () => Promise<any>;
|
|
10
|
+
detectDieline: (url: string) => Promise<any>;
|
|
11
|
+
activateTool: (id: string) => void;
|
|
12
|
+
on: (event: string, handler: any) => void;
|
|
13
|
+
off: (event: string, handler: any) => void;
|
|
14
|
+
emit: (event: string, data: any) => void;
|
|
15
|
+
executeCommand: (id: string, ...args: any[]) => Promise<any>;
|
|
16
|
+
getConfig: (key: string) => any;
|
|
17
|
+
updateConfig: (key: string, val: any) => void;
|
|
18
|
+
services: {
|
|
19
|
+
workbench: WorkbenchService;
|
|
20
|
+
command: CommandService;
|
|
21
|
+
config: ConfigurationService;
|
|
22
|
+
};
|
|
9
23
|
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
|
|
10
24
|
"image-change": (images: any[]) => any;
|
|
11
25
|
}, string, import('vue').PublicProps, Readonly<{}> & Readonly<{
|
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-fe0feb51]{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": "
|
|
3
|
+
"version": "4.0.0",
|
|
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.0.0",
|
|
23
|
+
"@pooder/kit": "4.0.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"vue": "^3.0.0"
|