customized-fabric 1.9.1 → 1.9.2
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.
- package/lib/TextInputObject/index.js +22 -50
- package/package.json +1 -1
@@ -45,9 +45,6 @@ const TextInputClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
|
|
45
45
|
this.set(attributes);
|
46
46
|
this.rectObject.set(attributes);
|
47
47
|
this.autoChangeFontSize(0.1);
|
48
|
-
this.textObject.set({
|
49
|
-
width: width,
|
50
|
-
});
|
51
48
|
this.canvas?.renderAll?.();
|
52
49
|
});
|
53
50
|
this.set({
|
@@ -72,35 +69,30 @@ const TextInputClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
|
|
72
69
|
},
|
73
70
|
autoChangeFontSize: function (changeSpeed) {
|
74
71
|
let maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
72
|
+
let fontSize = this.textObject.fontSize;
|
73
|
+
while (this.width - fontSize / 4 < maxLineWidth ||
|
74
|
+
this.height < this.textObject.height) {
|
75
|
+
fontSize -= changeSpeed;
|
76
|
+
this.textObject.set({
|
77
|
+
fontSize,
|
78
|
+
});
|
79
|
+
maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
83
80
|
}
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
}
|
81
|
+
while (this.textObject.maxFontSize > fontSize.toFixed(1) &&
|
82
|
+
this.width - fontSize / 4 > maxLineWidth &&
|
83
|
+
this.height > this.textObject.height) {
|
84
|
+
fontSize += changeSpeed;
|
85
|
+
this.textObject.set({
|
86
|
+
fontSize,
|
87
|
+
});
|
88
|
+
maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
93
89
|
}
|
94
90
|
},
|
95
91
|
setText: function (text) {
|
96
92
|
this.textObject.set({
|
97
93
|
text,
|
98
94
|
});
|
99
|
-
this.
|
100
|
-
this.textObject.set({
|
101
|
-
width: this.width,
|
102
|
-
});
|
103
|
-
this.canvas?.renderAll?.();
|
95
|
+
this.fire("scaling");
|
104
96
|
},
|
105
97
|
setPrefix: function (text) {
|
106
98
|
this.textObject.set({
|
@@ -126,34 +118,17 @@ const TextInputClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
|
|
126
118
|
const text = prefix + infix + suffix;
|
127
119
|
this.setText(infix?.length > 0 ? (isAllCapital ? text.toUpperCase() : text) : "");
|
128
120
|
},
|
129
|
-
setMaxFontSize: function (
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
const maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
134
|
-
if (maxLineWidth < this.width && this.textObject.height < this.height) {
|
135
|
-
}
|
136
|
-
else {
|
137
|
-
this.autoChangeFontSize(1);
|
138
|
-
}
|
139
|
-
this.textObject.set({
|
140
|
-
width: this.width,
|
141
|
-
});
|
142
|
-
this.textObject.set({
|
143
|
-
maxFontSize: fontSize,
|
144
|
-
});
|
145
|
-
this.canvas?.renderAll?.();
|
121
|
+
setMaxFontSize: function (size) {
|
122
|
+
const fontSize = Number(size);
|
123
|
+
this.textObject.set({ fontSize, maxFontSize: fontSize });
|
124
|
+
this.fire("scaling");
|
146
125
|
},
|
147
126
|
setFontFamily: async function (fontName, fontUrl) {
|
148
127
|
if (!(0, utils_1.isFontLoaded)(fontName)) {
|
149
128
|
await (0, utils_1.loadFontFromUrl)(fontUrl ?? "", fontName);
|
150
129
|
}
|
151
130
|
this.textObject.set({ fontFamily: fontName });
|
152
|
-
this.
|
153
|
-
this.textObject.set({
|
154
|
-
width: this.width,
|
155
|
-
});
|
156
|
-
this.canvas?.renderAll?.();
|
131
|
+
this.fire("scaling");
|
157
132
|
},
|
158
133
|
setSizes: function (options) {
|
159
134
|
const { width, height } = options;
|
@@ -167,9 +142,6 @@ const TextInputClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
|
|
167
142
|
},
|
168
143
|
setTextAttributes: function (options) {
|
169
144
|
this.textObject.set(options);
|
170
|
-
this.textObject.set({
|
171
|
-
width: this.width,
|
172
|
-
});
|
173
145
|
this.canvas?.renderAll?.();
|
174
146
|
},
|
175
147
|
getTextAttribute: function (attribute) {
|