customized-fabric 1.7.3 → 1.7.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,6 +18,7 @@ export declare const toImagePlaceholderObject: (object: ImagePlaceholder) => {
18
18
  removeBackground: boolean | undefined;
19
19
  faceCutout: boolean | undefined;
20
20
  advancedFilter: string | undefined;
21
+ objectFit: string | undefined;
21
22
  };
22
23
  };
23
24
  export default class ImagePlaceholder extends fabric.Group {
@@ -37,6 +38,7 @@ export default class ImagePlaceholder extends fabric.Group {
37
38
  layoutGroupId?: string;
38
39
  layoutGroupName?: string;
39
40
  advancedFilter?: string;
41
+ objectFit?: string;
40
42
  getSettings?: (attribute: string) => any;
41
43
  setSizes?: (options: {
42
44
  width?: number;
@@ -32,6 +32,8 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
32
32
  layerId: options?.personalizeId ?? options?.layerId,
33
33
  imageType: "Full color",
34
34
  objectCaching: false,
35
+ objectFit: "cover",
36
+ clipPath: this.rectObject,
35
37
  });
36
38
  if (options?.isOriginal) {
37
39
  this.rectObject?.set({ strokeWidth: 0 });
@@ -50,14 +52,14 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
50
52
  }
51
53
  }
52
54
  if (options?.imageSettings) {
53
- const { type, color, removeBackground, faceCutout, advancedFilter } = options?.imageSettings;
55
+ const { type, color, removeBackground, faceCutout, advancedFilter, objectFit, } = options?.imageSettings;
54
56
  if (type) {
55
57
  this.setImageType(type);
56
58
  }
57
59
  if (color) {
58
60
  this.setImageColor(color);
59
61
  }
60
- this.set({ removeBackground, faceCutout, advancedFilter });
62
+ this.set({ removeBackground, faceCutout, advancedFilter, objectFit });
61
63
  }
62
64
  },
63
65
  loadImage: async function (image) {
@@ -70,7 +72,7 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
70
72
  this.remove(this.imageObject);
71
73
  this.imageObject = loadedImage;
72
74
  this.add(this.imageObject);
73
- this.fitImage(this.imageObject);
75
+ this.fitImage(this.imageObject, this.objectFit == "cover");
74
76
  this.applyImageFilters(this.imageObject);
75
77
  this.canvas?.renderAll();
76
78
  }
@@ -93,7 +95,7 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
93
95
  scaleX: this.width / this.maskObject.width,
94
96
  scaleY: this.height / this.maskObject.height,
95
97
  });
96
- this.fitImage(this.imageObject);
98
+ this.fitImage(this.imageObject, this.objectFit == "cover");
97
99
  this.canvas?.renderAll?.();
98
100
  },
99
101
  fitImage: function (image, cover = false) {
@@ -125,6 +127,7 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
125
127
  top: this.top,
126
128
  left: this.left,
127
129
  clipPath: mask,
130
+ angle: this.angle,
128
131
  });
129
132
  const canvas = this?.canvas;
130
133
  canvas?.remove(this.uploadedImage);
@@ -135,7 +138,7 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
135
138
  if (index >= 0) {
136
139
  canvas.insertAt(loadedImage, index, false);
137
140
  }
138
- this.fitImage(this.uploadedImage, true);
141
+ this.fitImage(this.uploadedImage, this.objectFit == "cover");
139
142
  this.applyImageFilters(this.uploadedImage);
140
143
  canvas?.renderAll();
141
144
  }
@@ -199,7 +202,7 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
199
202
  }
200
203
  },
201
204
  removeMask: async function () {
202
- this.set({ clipPath: undefined, maskUrl: undefined });
205
+ this.set({ clipPath: this.rectObject, maskUrl: undefined });
203
206
  this.remove(this.maskObject);
204
207
  this.maskObject = undefined;
205
208
  this.canvas?.renderAll();
@@ -306,6 +309,7 @@ const toImagePlaceholderObject = (object) => {
306
309
  removeBackground: object?.removeBackground,
307
310
  faceCutout: object?.faceCutout,
308
311
  advancedFilter: object?.advancedFilter,
312
+ objectFit: object?.objectFit,
309
313
  },
310
314
  };
311
315
  };
@@ -58,6 +58,7 @@ export interface IImagePlaceholderOptions extends fabric.IGroupOptions {
58
58
  removeBackground?: boolean;
59
59
  faceCutout?: boolean;
60
60
  advancedFilter?: string;
61
+ objectFit?: string;
61
62
  };
62
63
  }
63
64
  export declare type ImageFilterType = "Full color" | "Grayscale" | "Blend color";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fabric_1 = require("fabric");
4
+ const constants_1 = require("../constants");
5
+ fabric_1.fabric.Object.prototype.transparentCorners = false;
6
+ fabric_1.fabric.Object.prototype.cornerColor = "transparent";
7
+ fabric_1.fabric.Object.prototype.cornerStyle = "circle";
8
+ fabric_1.fabric.Object.prototype.cornerStrokeColor = "#3b75cf";
9
+ fabric_1.fabric.Object.prototype.borderColor = "#3b75cf";
10
+ fabric_1.fabric.Group.prototype.originX = "center";
11
+ fabric_1.fabric.Group.prototype.originY = "center";
12
+ fabric_1.fabric.ActiveSelection.prototype.originX = "center";
13
+ fabric_1.fabric.ActiveSelection.prototype.originY = "center";
14
+ fabric_1.fabric.textureSize = constants_1.MAX_TEXTURE_SIZE;
@@ -4,6 +4,7 @@ import ImagePlaceholder from "../ImagePlaceholderObject";
4
4
  import TextInput from "../TextInputObject";
5
5
  import { ImageFilterType } from "../ImagePlaceholderObject/interfaces";
6
6
  import CurvedText from "../CurvedTextObject";
7
+ import "./control.util";
7
8
  export declare const loadFontFromUrl: (url: string, name: string) => Promise<void>;
8
9
  export declare const isFontLoaded: (name: string) => boolean;
9
10
  export declare const loadImageFromFile: (image: File) => Promise<fabric.Image>;
@@ -30,6 +30,7 @@ const ClipartObject_1 = __importStar(require("../ClipartObject"));
30
30
  const ImagePlaceholderObject_1 = __importStar(require("../ImagePlaceholderObject"));
31
31
  const TextInputObject_1 = __importStar(require("../TextInputObject"));
32
32
  const CurvedTextObject_1 = __importStar(require("../CurvedTextObject"));
33
+ require("./control.util");
33
34
  const loadFontFromUrl = async (url, name) => {
34
35
  if (!name || !url)
35
36
  return;
@@ -205,16 +206,6 @@ const asyncGetObject = async (object, options) => {
205
206
  }
206
207
  };
207
208
  exports.asyncGetObject = asyncGetObject;
208
- fabric_1.fabric.Object.prototype.transparentCorners = false;
209
- fabric_1.fabric.Object.prototype.cornerColor = "transparent";
210
- fabric_1.fabric.Object.prototype.cornerStyle = "circle";
211
- fabric_1.fabric.Object.prototype.cornerStrokeColor = "#3b75cf";
212
- fabric_1.fabric.Object.prototype.borderColor = "#3b75cf";
213
- fabric_1.fabric.Group.prototype.originX = "center";
214
- fabric_1.fabric.Group.prototype.originY = "center";
215
- fabric_1.fabric.ActiveSelection.prototype.originX = "center";
216
- fabric_1.fabric.ActiveSelection.prototype.originY = "center";
217
- fabric_1.fabric.textureSize = constants_1.MAX_TEXTURE_SIZE;
218
209
  fabric_1.fabric.Object.prototype.toObject = (function (toObject) {
219
210
  return function () {
220
211
  switch (this.type) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "customized-fabric",
3
- "version": "1.7.3",
3
+ "version": "1.7.5",
4
4
  "description": "Customized fabric",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",