customized-fabric 1.8.6 → 1.8.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,6 +30,8 @@ export declare const toTextInputObject: (object: TextInput) => {
30
30
  infix: any;
31
31
  suffix: any;
32
32
  isAllCapital: any;
33
+ lineHeight: number | undefined;
34
+ charSpacing: number | undefined;
33
35
  };
34
36
  };
35
37
  export default class TextInput extends fabric.Group {
@@ -17,7 +17,7 @@ const TextInputClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
17
17
  objectCaching: false,
18
18
  ...constants_1.TEXT_INPUT_OBJECT_ATTRIBUTES.stroke,
19
19
  });
20
- const { prefix = "", infix = "A", suffix = "", isAllCapital } = text ?? {};
20
+ const { prefix = "", infix = "A", suffix = "", isAllCapital, lineHeight = 1, charSpacing = 0, } = text ?? {};
21
21
  const fullText = prefix + infix + suffix;
22
22
  this.textObject = new fabric_1.fabric.IText("", {
23
23
  originX: "center",
@@ -28,6 +28,8 @@ const TextInputClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
28
28
  text: isAllCapital ? fullText.toUpperCase() : fullText,
29
29
  fontFamily: "",
30
30
  paintFirst: "stroke",
31
+ lineHeight,
32
+ charSpacing,
31
33
  });
32
34
  const group = new fabric_1.fabric.Group([this.rectObject, this.textObject]);
33
35
  this.set(group);
@@ -69,22 +71,24 @@ const TextInputClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
69
71
  this.fire("scaling");
70
72
  },
71
73
  autoChangeFontSize: function (changeSpeed) {
72
- if (this.width <= this.textObject.__lineWidths ||
73
- this.height <= this.textObject.height) {
74
- while (this.width <= this.textObject.__lineWidths ||
74
+ let maxLineWidth = Math.max(...this.textObject.__lineWidths);
75
+ if (this.width <= maxLineWidth || this.height <= this.textObject.height) {
76
+ while (this.width <= maxLineWidth ||
75
77
  this.height <= this.textObject.height) {
76
78
  this.textObject.set({
77
79
  fontSize: this.textObject.fontSize - changeSpeed,
78
80
  });
81
+ maxLineWidth = Math.max(...this.textObject.__lineWidths);
79
82
  }
80
83
  }
81
84
  else {
82
85
  while (this.textObject.maxFontSize > this.textObject.fontSize &&
83
- this.width > this.textObject.__lineWidths &&
86
+ this.width > maxLineWidth &&
84
87
  this.height > this.textObject.height) {
85
88
  this.textObject.set({
86
89
  fontSize: this.textObject.fontSize + changeSpeed,
87
90
  });
91
+ maxLineWidth = Math.max(...this.textObject.__lineWidths);
88
92
  }
89
93
  }
90
94
  },
@@ -126,8 +130,8 @@ const TextInputClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
126
130
  this.textObject.set({
127
131
  fontSize,
128
132
  });
129
- if (this.textObject.__lineWidths < this.width &&
130
- this.textObject.height < this.height) {
133
+ const maxLineWidth = Math.max(...this.textObject.__lineWidths);
134
+ if (maxLineWidth < this.width && this.textObject.height < this.height) {
131
135
  }
132
136
  else {
133
137
  this.autoChangeFontSize(1);
@@ -209,6 +213,8 @@ const toTextInputObject = (object) => {
209
213
  infix: textObject?.infix,
210
214
  suffix: textObject?.suffix,
211
215
  isAllCapital: textObject?.isAllCapital,
216
+ lineHeight: textObject?.lineHeight,
217
+ charSpacing: textObject?.charSpacing,
212
218
  },
213
219
  };
214
220
  };
@@ -19,6 +19,8 @@ export interface ITextInputOptions extends fabric.IGroupOptions {
19
19
  infix?: string;
20
20
  suffix?: string;
21
21
  isAllCapital?: boolean;
22
+ lineHeight?: number;
23
+ charSpacing?: number;
22
24
  };
23
25
  fontUrl?: string;
24
26
  isOriginal?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "customized-fabric",
3
- "version": "1.8.6",
3
+ "version": "1.8.8",
4
4
  "description": "Customized fabric",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",