customized-fabric 1.4.8 → 1.4.9

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.
@@ -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: (imagePlaceholderObject: ImagePlaceholder) => {
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
- imageType: string | undefined;
14
- imageColor: string | undefined;
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?.imageType) {
53
- this.setImageType(options?.imageType);
54
- }
55
- if (options?.imageColor) {
56
- this.setImageColor(options?.imageColor);
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
- type: this.imageType,
155
- color: this.imageColor,
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: undefined });
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, color, type, flipX, flipY } = data;
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 = (imagePlaceholderObject) => {
279
+ const toImagePlaceholderObject = (object) => {
271
280
  return {
272
- _id: imagePlaceholderObject?._id,
273
- id: imagePlaceholderObject?._id,
274
- personalizeId: imagePlaceholderObject?.layerId,
275
- layerId: imagePlaceholderObject?.layerId,
276
- name: imagePlaceholderObject?.name,
277
- locked: imagePlaceholderObject?.locked,
278
- isAdditional: imagePlaceholderObject?.isAdditional,
279
- maskUrl: imagePlaceholderObject?.maskUrl,
280
- imageType: imagePlaceholderObject?.imageType,
281
- imageColor: imagePlaceholderObject?.imageColor,
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
- color?: string;
37
- type?: ImageFilterType;
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";
@@ -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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "customized-fabric",
3
- "version": "1.4.8",
3
+ "version": "1.4.9",
4
4
  "description": "Customized fabric",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",