customized-fabric 2.0.18 → 2.0.20

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.
@@ -35,14 +35,27 @@ const TextInputClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
35
35
  const group = new fabric_1.fabric.Group([this.rectObject, this.textObject]);
36
36
  this.set(group);
37
37
  this.on("scaling", () => {
38
- let width = this.width * this.scaleX;
39
- let height = this.height * this.scaleY;
38
+ const { width, height, scaleX, scaleY } = this;
40
39
  const attributes = {
41
40
  scaleX: 1,
42
41
  scaleY: 1,
43
- width,
44
- height,
42
+ width: width * scaleX,
43
+ height: height * scaleY,
45
44
  };
45
+ const { fontSize, maxFontSize, fontSizeScalable, strokeWidth } = this.textObject;
46
+ if (fontSizeScalable) {
47
+ // font scaling
48
+ const fontSizeRatio = maxFontSize / Math.min(width, height);
49
+ const newMaxFontSize = fontSizeRatio * Math.min(attributes.width, attributes.height);
50
+ // stroke width scaling
51
+ const strokeWidthRatio = strokeWidth / Math.min(width, height);
52
+ const newStrokeWidth = strokeWidthRatio * Math.min(attributes.width, attributes.height);
53
+ this.textObject.set({
54
+ maxFontSize: newMaxFontSize,
55
+ fontSize: Math.min(fontSize, newMaxFontSize),
56
+ strokeWidth: newStrokeWidth,
57
+ });
58
+ }
46
59
  this.set(attributes);
47
60
  this.rectObject.set(attributes);
48
61
  this.autoChangeFontSize(0.1);
@@ -69,9 +82,6 @@ const TextInputClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
69
82
  this.fire("scaling");
70
83
  },
71
84
  autoChangeFontSize: function (changeSpeed) {
72
- if (this.textObject.fontSizeScalable) {
73
- this.textObject.set({ maxFontSize: Math.min(this.width, this.height) });
74
- }
75
85
  let maxLineWidth = Math.max(...this.textObject.__lineWidths);
76
86
  let fontSize = this.textObject.fontSize ?? 0;
77
87
  while (this.width - fontSize / 4 < maxLineWidth ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "customized-fabric",
3
- "version": "2.0.18",
3
+ "version": "2.0.20",
4
4
  "description": "Customized fabric",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",