customized-fabric 1.2.6 → 1.2.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -56,17 +56,12 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
|
|
56
56
|
const { top, left, scaleX, width, originX, originY } = data;
|
57
57
|
const ratioWidth = (width * scaleX) / (clipPath.width * clipPath.scaleX);
|
58
58
|
const ratioPosition = this.width / clipPath.width;
|
59
|
+
const originalClipPath = await this.getClipPath(clipPath);
|
59
60
|
loadedImage.set({
|
60
61
|
...data,
|
61
62
|
top: this.top + ratioPosition * top,
|
62
63
|
left: this.left + ratioPosition * left,
|
63
|
-
clipPath:
|
64
|
-
width: this.width,
|
65
|
-
height: this.height,
|
66
|
-
top: this.top,
|
67
|
-
left: this.left,
|
68
|
-
absolutePositioned: true,
|
69
|
-
}),
|
64
|
+
clipPath: originalClipPath,
|
70
65
|
});
|
71
66
|
loadedImage.scaleToWidth(ratioWidth * this.width);
|
72
67
|
this?.canvas?.add(loadedImage);
|
@@ -220,6 +215,19 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
|
|
220
215
|
this.maskObject = undefined;
|
221
216
|
this.canvas?.renderAll();
|
222
217
|
},
|
218
|
+
getClipPath: async function (clipPath) {
|
219
|
+
if (clipPath?.url) {
|
220
|
+
}
|
221
|
+
else {
|
222
|
+
return new fabric_1.fabric.Rect({
|
223
|
+
width: this.width,
|
224
|
+
height: this.height,
|
225
|
+
top: this.top,
|
226
|
+
left: this.left,
|
227
|
+
absolutePositioned: true,
|
228
|
+
});
|
229
|
+
}
|
230
|
+
},
|
223
231
|
});
|
224
232
|
const toImagePlaceholderObject = (imagePlaceholderObject) => {
|
225
233
|
return {
|
@@ -1,4 +1,21 @@
|
|
1
1
|
import { ObjectId } from "../utils/objectId";
|
2
|
+
export interface IClipPathOptions {
|
3
|
+
url?: string;
|
4
|
+
originX: string;
|
5
|
+
originY: string;
|
6
|
+
left: number;
|
7
|
+
top: number;
|
8
|
+
width: number;
|
9
|
+
height: number;
|
10
|
+
scaleX: number;
|
11
|
+
scaleY: number;
|
12
|
+
angle: number;
|
13
|
+
flipX: boolean;
|
14
|
+
flipY: boolean;
|
15
|
+
skewX: number;
|
16
|
+
skewY: number;
|
17
|
+
opacity: number;
|
18
|
+
}
|
2
19
|
export interface IImagePlaceholderOptions extends fabric.IGroupOptions {
|
3
20
|
_id?: ObjectId;
|
4
21
|
personalizeId?: number;
|
@@ -24,22 +41,7 @@ export interface IImagePlaceholderOptions extends fabric.IGroupOptions {
|
|
24
41
|
skewY: number;
|
25
42
|
opacity: number;
|
26
43
|
};
|
27
|
-
clipPath:
|
28
|
-
originX: string;
|
29
|
-
originY: string;
|
30
|
-
left: number;
|
31
|
-
top: number;
|
32
|
-
width: number;
|
33
|
-
height: number;
|
34
|
-
scaleX: number;
|
35
|
-
scaleY: number;
|
36
|
-
angle: number;
|
37
|
-
flipX: boolean;
|
38
|
-
flipY: boolean;
|
39
|
-
skewX: number;
|
40
|
-
skewY: number;
|
41
|
-
opacity: number;
|
42
|
-
};
|
44
|
+
clipPath: IClipPathOptions;
|
43
45
|
};
|
44
46
|
maskUrl?: string;
|
45
47
|
}
|
package/lib/utils/index.d.ts
CHANGED
@@ -6,7 +6,7 @@ export declare const loadFontFromUrl: (url: string, name: string) => Promise<voi
|
|
6
6
|
export declare const isFontLoaded: (name: string) => boolean;
|
7
7
|
export declare const loadImageFromFile: (image: File) => Promise<fabric.Image>;
|
8
8
|
export declare const loadImageFromUrl: (url: string) => Promise<fabric.Image>;
|
9
|
-
export declare const loadImage: (imageInput: File | string) => Promise<fabric.Image
|
9
|
+
export declare const loadImage: (imageInput: File | string) => Promise<fabric.Image>;
|
10
10
|
export declare const lockObject: (object: fabric.Object | any, locked: boolean, selectable?: boolean) => void;
|
11
11
|
export declare const lockAllObjects: (canvas: fabric.Canvas, locked: boolean, selectable?: boolean) => void;
|
12
12
|
export declare const getObject: (object: any, options?: {
|
package/lib/utils/index.js
CHANGED
@@ -77,12 +77,12 @@ const loadImageFromUrl = (url) => {
|
|
77
77
|
exports.loadImageFromUrl = loadImageFromUrl;
|
78
78
|
const loadImage = async (imageInput) => {
|
79
79
|
let loadedImage = undefined;
|
80
|
-
if (imageInput
|
81
|
-
loadedImage = await (0, exports.loadImageFromFile)(imageInput);
|
82
|
-
}
|
83
|
-
else if (typeof imageInput == "string") {
|
80
|
+
if (typeof imageInput == "string") {
|
84
81
|
loadedImage = await (0, exports.loadImageFromUrl)(imageInput);
|
85
82
|
}
|
83
|
+
else {
|
84
|
+
loadedImage = await (0, exports.loadImageFromFile)(imageInput);
|
85
|
+
}
|
86
86
|
return loadedImage;
|
87
87
|
};
|
88
88
|
exports.loadImage = loadImage;
|