customized-fabric 2.0.7 → 2.0.8

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.
@@ -6,9 +6,10 @@ const constants_1 = require("./constants");
6
6
  const utils_1 = require("../utils");
7
7
  const objectId_1 = require("../utils/objectId");
8
8
  const svg_util_1 = require("../utils/svg.util");
9
+ const common_util_1 = require("../utils/common.util");
9
10
  const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
10
11
  initialize: function (options) {
11
- const { text, ...rest } = options ?? {};
12
+ let { text, ...rest } = options ?? {};
12
13
  this.rectObject = new fabric_1.fabric.Rect({
13
14
  width: options?.width,
14
15
  height: options?.height,
@@ -18,6 +19,7 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
18
19
  objectCaching: false,
19
20
  ...constants_1.CURVED_TEXT_OBJECT_ATTRIBUTES.stroke,
20
21
  });
22
+ text = (0, common_util_1.removeValueKeys)(text);
21
23
  const { prefix = "", infix = "", suffix = "", isAllCapital } = text ?? {};
22
24
  const fullText = prefix + infix + suffix;
23
25
  this.textObject = new fabric_1.fabric.IText("", {
@@ -27,8 +29,9 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
27
29
  objectCaching: false,
28
30
  fontFamily: "",
29
31
  paintFirst: "stroke",
30
- lengthRatio: 0.3,
32
+ lengthRatio: 0.4,
31
33
  positionAngle: 0,
34
+ maxFontSize: 200,
32
35
  ...text,
33
36
  text: isAllCapital ? fullText.toUpperCase() : fullText,
34
37
  });
@@ -54,8 +57,8 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
54
57
  };
55
58
  this.set(attributes);
56
59
  this.rectObject.set(attributes);
57
- this.autoChangeFontSize(0.1);
58
60
  this.calculateTextPath(width, height);
61
+ this.autoChangeFontSize(0.1);
59
62
  this.canvas?.renderAll?.();
60
63
  });
61
64
  if (options?.isOriginal) {
@@ -70,10 +73,10 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
70
73
  this.fire("scaling");
71
74
  },
72
75
  autoChangeFontSize: function (changeSpeed = 0.1) {
73
- let { fontSize = 0, lengthRatio = 0.3, maxFontSize } = this.textObject;
74
- fontSize = Number(fontSize);
75
- lengthRatio = Number(lengthRatio);
76
- maxFontSize = Number(maxFontSize);
76
+ let { fontSize, lengthRatio, maxFontSize } = this.textObject;
77
+ fontSize = Number(fontSize || 0);
78
+ lengthRatio = Number(lengthRatio || 0.4);
79
+ maxFontSize = Number(maxFontSize || 200);
77
80
  const length = (0, svg_util_1.getEllipseCircumference)(this.width / 2, this.height / 2) * lengthRatio;
78
81
  let maxLineWidth = Math.max(...this.textObject.__lineWidths);
79
82
  while (length <= maxLineWidth) {
@@ -160,7 +163,8 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
160
163
  return this.textObject.get(attribute);
161
164
  },
162
165
  calculateTextPath: function (width, height) {
163
- const { pathSide, positionAngle } = this.textObject;
166
+ let { pathSide, positionAngle } = this.textObject;
167
+ positionAngle = Number(positionAngle || 0);
164
168
  const textHeight = 0;
165
169
  const rx = (width - textHeight) / 2;
166
170
  const ry = (height - textHeight) / 2;
@@ -0,0 +1 @@
1
+ export declare const removeValueKeys: (object: any, value?: any) => any;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeValueKeys = void 0;
4
+ const removeValueKeys = (object, value = null) => {
5
+ const newObject = {};
6
+ for (const key in object) {
7
+ if (!(object[key] === null)) {
8
+ newObject[key] = object[key];
9
+ }
10
+ }
11
+ return newObject;
12
+ };
13
+ exports.removeValueKeys = removeValueKeys;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "customized-fabric",
3
- "version": "2.0.7",
3
+ "version": "2.0.8",
4
4
  "description": "Customized fabric",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",