customized-fabric 1.4.8 → 1.4.9
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
|
|
1
1
|
import { fabric } from "fabric";
|
2
2
|
import { IImageOptions, IImagePlaceholderOptions, ImageFilterType } from "./interfaces";
|
3
3
|
import { ObjectId } from "../utils/objectId";
|
4
|
-
export declare const toImagePlaceholderObject: (
|
4
|
+
export declare const toImagePlaceholderObject: (object: ImagePlaceholder) => {
|
5
5
|
_id: ObjectId | undefined;
|
6
6
|
id: ObjectId | undefined;
|
7
7
|
personalizeId: number | undefined;
|
@@ -10,8 +10,12 @@ export declare const toImagePlaceholderObject: (imagePlaceholderObject: ImagePla
|
|
10
10
|
locked: boolean | undefined;
|
11
11
|
isAdditional: boolean | undefined;
|
12
12
|
maskUrl: string | undefined;
|
13
|
-
|
14
|
-
|
13
|
+
imageSettings: {
|
14
|
+
type: string | undefined;
|
15
|
+
color: string | undefined;
|
16
|
+
removeBackground: boolean | undefined;
|
17
|
+
faceCutout: boolean | undefined;
|
18
|
+
};
|
15
19
|
};
|
16
20
|
export default class ImagePlaceholder extends fabric.Group {
|
17
21
|
_id?: ObjectId;
|
@@ -23,6 +27,8 @@ export default class ImagePlaceholder extends fabric.Group {
|
|
23
27
|
isAdditional?: boolean;
|
24
28
|
imageColor?: string;
|
25
29
|
imageType?: string;
|
30
|
+
removeBackground?: boolean;
|
31
|
+
faceCutout?: boolean;
|
26
32
|
imageObject?: fabric.Image;
|
27
33
|
uploadedImage?: fabric.Image;
|
28
34
|
getSettings?: (attribute: string) => any;
|
@@ -49,11 +49,15 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
|
|
49
49
|
this.loadImage(options?.imageFile);
|
50
50
|
}
|
51
51
|
}
|
52
|
-
if (options?.
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
if (options?.imageSettings) {
|
53
|
+
const { type, color, removeBackground, faceCutout } = options?.imageSettings;
|
54
|
+
if (type) {
|
55
|
+
this.setImageType(type);
|
56
|
+
}
|
57
|
+
if (color) {
|
58
|
+
this.setImageColor(color);
|
59
|
+
}
|
60
|
+
this.set({ removeBackground, faceCutout });
|
57
61
|
}
|
58
62
|
},
|
59
63
|
loadImage: async function (image) {
|
@@ -151,8 +155,12 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
|
|
151
155
|
skewX,
|
152
156
|
skewY,
|
153
157
|
opacity,
|
154
|
-
|
155
|
-
|
158
|
+
settings: {
|
159
|
+
type: this?.imageType,
|
160
|
+
color: this?.imageColor,
|
161
|
+
removeBackground: this?.removeBackground,
|
162
|
+
faceCutout: this?.faceCutout,
|
163
|
+
},
|
156
164
|
};
|
157
165
|
}
|
158
166
|
else {
|
@@ -179,7 +187,7 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
|
|
179
187
|
}
|
180
188
|
},
|
181
189
|
removeMask: async function () {
|
182
|
-
this.set({ clipPath: undefined, maskUrl:
|
190
|
+
this.set({ clipPath: undefined, maskUrl: "" });
|
183
191
|
this.remove(this.maskObject);
|
184
192
|
this.maskObject = undefined;
|
185
193
|
this.canvas?.renderAll();
|
@@ -227,7 +235,8 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
|
|
227
235
|
const loadedImage = await (0, utils_1.loadImageFromUrl)(url);
|
228
236
|
if (loadedImage) {
|
229
237
|
const mask = await this.getMask();
|
230
|
-
const { top, left, scaleX, width, angle,
|
238
|
+
const { top, left, scaleX, width, angle, flipX, flipY, settings = {}, } = data;
|
239
|
+
const { color, type } = settings;
|
231
240
|
const ratioWidth = (width * scaleX) / (clipPath.width * clipPath.scaleX);
|
232
241
|
const ratioPosition = this.width / clipPath.width;
|
233
242
|
loadedImage.scaleToWidth(ratioWidth * this.width);
|
@@ -267,18 +276,22 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
|
|
267
276
|
}
|
268
277
|
},
|
269
278
|
});
|
270
|
-
const toImagePlaceholderObject = (
|
279
|
+
const toImagePlaceholderObject = (object) => {
|
271
280
|
return {
|
272
|
-
_id:
|
273
|
-
id:
|
274
|
-
personalizeId:
|
275
|
-
layerId:
|
276
|
-
name:
|
277
|
-
locked:
|
278
|
-
isAdditional:
|
279
|
-
maskUrl:
|
280
|
-
|
281
|
-
|
281
|
+
_id: object?._id,
|
282
|
+
id: object?._id,
|
283
|
+
personalizeId: object?.layerId,
|
284
|
+
layerId: object?.layerId,
|
285
|
+
name: object?.name,
|
286
|
+
locked: object?.locked,
|
287
|
+
isAdditional: object?.isAdditional,
|
288
|
+
maskUrl: object?.maskUrl,
|
289
|
+
imageSettings: {
|
290
|
+
type: object?.imageType,
|
291
|
+
color: object?.imageColor,
|
292
|
+
removeBackground: object?.removeBackground,
|
293
|
+
faceCutout: object?.faceCutout,
|
294
|
+
},
|
282
295
|
};
|
283
296
|
};
|
284
297
|
exports.toImagePlaceholderObject = toImagePlaceholderObject;
|
@@ -33,8 +33,10 @@ export interface IImageOptions {
|
|
33
33
|
skewX: number;
|
34
34
|
skewY: number;
|
35
35
|
opacity: number;
|
36
|
-
|
37
|
-
|
36
|
+
settings: {
|
37
|
+
color?: string;
|
38
|
+
type?: ImageFilterType;
|
39
|
+
};
|
38
40
|
};
|
39
41
|
clipPath: IClipPathOptions;
|
40
42
|
}
|
@@ -43,13 +45,17 @@ export interface IImagePlaceholderOptions extends fabric.IGroupOptions {
|
|
43
45
|
personalizeId?: number;
|
44
46
|
layerId: number;
|
45
47
|
imageFile?: File;
|
46
|
-
imageType?: string;
|
47
|
-
imageColor?: string;
|
48
48
|
isOriginal?: boolean;
|
49
49
|
isAdditional?: boolean;
|
50
50
|
image?: IImageOptions;
|
51
51
|
maskUrl?: string;
|
52
52
|
maskFile?: File;
|
53
53
|
hideStroke?: boolean;
|
54
|
+
imageSettings?: {
|
55
|
+
type?: string;
|
56
|
+
color?: string;
|
57
|
+
removeBackground?: boolean;
|
58
|
+
faceCutout?: boolean;
|
59
|
+
};
|
54
60
|
}
|
55
61
|
export declare type ImageFilterType = "Full color" | "Grayscale" | "Blend color";
|
package/lib/utils/index.js
CHANGED
@@ -202,6 +202,9 @@ fabric_1.fabric.Group.prototype.originX = "center";
|
|
202
202
|
fabric_1.fabric.Group.prototype.originY = "center";
|
203
203
|
fabric_1.fabric.ActiveSelection.prototype.originX = "center";
|
204
204
|
fabric_1.fabric.ActiveSelection.prototype.originY = "center";
|
205
|
+
if (fabric_1.fabric.isWebglSupported()) {
|
206
|
+
fabric_1.fabric.textureSize = fabric_1.fabric.maxTextureSize;
|
207
|
+
}
|
205
208
|
fabric_1.fabric.Object.prototype.toObject = (function (toObject) {
|
206
209
|
return function () {
|
207
210
|
switch (this.type) {
|