customized-fabric 1.6.5 → 1.6.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -50,5 +50,6 @@ export default class ImagePlaceholder extends fabric.Group {
50
50
  setImageType?: (type: ImageFilterType) => void;
51
51
  setImageColor?: (color: string) => void;
52
52
  applyImageFilters?: (image: fabric.Image | undefined) => void;
53
+ fitImage?: (image: fabric.Image, cover?: boolean) => void;
53
54
  constructor(options?: IImagePlaceholderOptions);
54
55
  }
@@ -96,13 +96,20 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
96
96
  this.fitImage(this.imageObject);
97
97
  this.canvas?.renderAll?.();
98
98
  },
99
- fitImage: function (image) {
99
+ fitImage: function (image, cover = false) {
100
100
  if (image) {
101
101
  const imageScaleX = this.width / (image?.width ?? 1);
102
102
  const imageScaleY = this.height / (image?.height ?? 1);
103
- imageScaleX > imageScaleY
104
- ? image.set({ scaleX: imageScaleY, scaleY: imageScaleY })
105
- : image.set({ scaleX: imageScaleX, scaleY: imageScaleX });
103
+ if (cover) {
104
+ imageScaleX < imageScaleY
105
+ ? image.set({ scaleX: imageScaleY, scaleY: imageScaleY })
106
+ : image.set({ scaleX: imageScaleX, scaleY: imageScaleX });
107
+ }
108
+ else {
109
+ imageScaleX > imageScaleY
110
+ ? image.set({ scaleX: imageScaleY, scaleY: imageScaleY })
111
+ : image.set({ scaleX: imageScaleX, scaleY: imageScaleX });
112
+ }
106
113
  }
107
114
  },
108
115
  getSettings: function (attribute) {
@@ -128,7 +135,7 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
128
135
  if (index >= 0) {
129
136
  canvas.insertAt(loadedImage, index, false);
130
137
  }
131
- this.fitImage(this.uploadedImage);
138
+ this.fitImage(this.uploadedImage, true);
132
139
  this.applyImageFilters(this.uploadedImage);
133
140
  canvas?.renderAll();
134
141
  }
@@ -54,6 +54,7 @@ const TextInputClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
54
54
  });
55
55
  if (options?.isOriginal) {
56
56
  this.rectObject?.set({ strokeWidth: 0 });
57
+ this.textObject?.set({ fontFamily: text?.fontFamily });
57
58
  }
58
59
  else {
59
60
  if (options?.hideStroke) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "customized-fabric",
3
- "version": "1.6.5",
3
+ "version": "1.6.7",
4
4
  "description": "Customized fabric",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",