customized-fabric 2.0.2 → 2.0.4
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/CurvedTextObject/index.d.ts +2 -3
- package/lib/CurvedTextObject/index.js +8 -9
- package/lib/CurvedTextObject/interfaces.d.ts +1 -1
- package/lib/utils/svg.util.d.ts +1 -0
- package/lib/utils/svg.util.js +5 -1
- package/package.json +1 -1
- package/lib/GroupLayoutObject/constants.d.ts +0 -4
- package/lib/GroupLayoutObject/constants.js +0 -7
- package/lib/GroupLayoutObject/index.d.ts +0 -19
- package/lib/GroupLayoutObject/index.js +0 -26
- package/lib/GroupLayoutObject/interfaces.d.ts +0 -3
- package/lib/GroupLayoutObject/interfaces.js +0 -2
- package/lib/constants/index.d.ts +0 -6
- package/lib/constants/index.js +0 -12
@@ -29,7 +29,7 @@ export declare const toCurvedTextObject: (object: CurvedText) => {
|
|
29
29
|
prefix: any;
|
30
30
|
infix: any;
|
31
31
|
suffix: any;
|
32
|
-
|
32
|
+
curvedLengthRatio: any;
|
33
33
|
pathSide: any;
|
34
34
|
pathStartOffset: any;
|
35
35
|
isAllCapital: any;
|
@@ -52,8 +52,7 @@ export default class CurvedText extends fabric.Group {
|
|
52
52
|
setSuffix?: (text: string) => void;
|
53
53
|
setMaxFontSize?: (fontSize: string) => void;
|
54
54
|
setFontFamily?: (fontName: string, fontUrl?: string) => void;
|
55
|
-
setTextAttributes?: (options:
|
56
|
-
setTextWidth?: (width: number) => void;
|
55
|
+
setTextAttributes?: (options: any) => void;
|
57
56
|
getTextAttribute?: (attribute: string) => any;
|
58
57
|
getSettings?: (attribute: string) => any;
|
59
58
|
setSizes?: (options: {
|
@@ -27,6 +27,7 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
|
|
27
27
|
objectCaching: false,
|
28
28
|
fontFamily: "",
|
29
29
|
paintFirst: "stroke",
|
30
|
+
curvedLengthRatio: 0.3,
|
30
31
|
...text,
|
31
32
|
text: isAllCapital ? fullText.toUpperCase() : fullText,
|
32
33
|
});
|
@@ -67,11 +68,13 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
|
|
67
68
|
}
|
68
69
|
this.fire("scaling");
|
69
70
|
},
|
70
|
-
autoChangeFontSize: function (changeSpeed) {
|
71
|
-
let {
|
71
|
+
autoChangeFontSize: function (changeSpeed = 0.1) {
|
72
|
+
let { curvedLengthRatio, fontSize = 0, maxFontSize } = this.textObject;
|
73
|
+
const circumference = (0, svg_util_1.getEllipseCircumference)(this.width / 2, this.height / 2);
|
74
|
+
const curvedLength = circumference * curvedLengthRatio;
|
72
75
|
let maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
73
76
|
fontSize = Number(fontSize);
|
74
|
-
while (
|
77
|
+
while (curvedLength <= maxLineWidth) {
|
75
78
|
fontSize -= changeSpeed;
|
76
79
|
this.textObject.set({
|
77
80
|
fontSize,
|
@@ -79,7 +82,7 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
|
|
79
82
|
this.canvas?.renderAll?.();
|
80
83
|
maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
81
84
|
}
|
82
|
-
while (maxFontSize > fontSize.toFixed(1) &&
|
85
|
+
while (maxFontSize > fontSize.toFixed(1) && curvedLength > maxLineWidth) {
|
83
86
|
fontSize += changeSpeed;
|
84
87
|
this.textObject.set({
|
85
88
|
fontSize,
|
@@ -145,10 +148,6 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
|
|
145
148
|
this.textObject.set(options);
|
146
149
|
this.fire("scaling");
|
147
150
|
},
|
148
|
-
setTextWidth: function (width) {
|
149
|
-
this.textObject.set({ curvedWidth: width });
|
150
|
-
this.fire("scaling");
|
151
|
-
},
|
152
151
|
getTextAttribute: function (attribute) {
|
153
152
|
return this.textObject.get(attribute);
|
154
153
|
},
|
@@ -212,7 +211,7 @@ const toCurvedTextObject = (object) => {
|
|
212
211
|
prefix: textObject?.prefix,
|
213
212
|
infix: textObject?.infix,
|
214
213
|
suffix: textObject?.suffix,
|
215
|
-
|
214
|
+
curvedLengthRatio: textObject?.curvedLengthRatio,
|
216
215
|
pathSide: textObject?.pathSide,
|
217
216
|
pathStartOffset: textObject?.pathStartOffset,
|
218
217
|
isAllCapital: textObject?.isAllCapital,
|
package/lib/utils/svg.util.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
1
|
import { fabric } from "fabric";
|
2
2
|
export declare const getEllipsePath: (rx: number, ry: number, side?: "left" | "right") => string;
|
3
3
|
export declare const getPathLength: (path: fabric.Path) => any;
|
4
|
+
export declare const getEllipseCircumference: (a: number, b: number) => number;
|
package/lib/utils/svg.util.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getPathLength = exports.getEllipsePath = void 0;
|
3
|
+
exports.getEllipseCircumference = exports.getPathLength = exports.getEllipsePath = void 0;
|
4
4
|
const fabric_1 = require("fabric");
|
5
5
|
const getEllipsePath = (rx, ry, side = "left") => {
|
6
6
|
const sideFactor = side == "left" ? -1 : 1;
|
@@ -17,3 +17,7 @@ const getPathLength = (path) => {
|
|
17
17
|
return pathLength;
|
18
18
|
};
|
19
19
|
exports.getPathLength = getPathLength;
|
20
|
+
const getEllipseCircumference = (a, b) => {
|
21
|
+
return Math.PI * (3 * (a + b) - Math.sqrt((3 * a + b) * (a + 3 * b)));
|
22
|
+
};
|
23
|
+
exports.getEllipseCircumference = getEllipseCircumference;
|
package/package.json
CHANGED
@@ -1,19 +0,0 @@
|
|
1
|
-
import { fabric } from "fabric";
|
2
|
-
import { ObjectId } from "../utils/objectId";
|
3
|
-
import { IGroupLayoutOptions } from "./interfaces";
|
4
|
-
export declare const toGroupLayoutObject: (groupLayoutObject: GroupLayout) => {
|
5
|
-
_id: ObjectId | undefined;
|
6
|
-
id: ObjectId | undefined;
|
7
|
-
personalizeId: number | undefined;
|
8
|
-
layerId: number | undefined;
|
9
|
-
name: string | undefined;
|
10
|
-
locked: boolean | undefined;
|
11
|
-
isAdditional: boolean | undefined;
|
12
|
-
};
|
13
|
-
export default class GroupLayout extends fabric.ActiveSelection {
|
14
|
-
_id?: ObjectId;
|
15
|
-
layerId?: number;
|
16
|
-
locked?: boolean;
|
17
|
-
isAdditional?: boolean;
|
18
|
-
constructor(options?: IGroupLayoutOptions);
|
19
|
-
}
|
@@ -1,26 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.toGroupLayoutObject = void 0;
|
4
|
-
const fabric_1 = require("fabric");
|
5
|
-
const GroupLayoutClass = fabric_1.fabric.util.createClass(fabric_1.fabric.ActiveSelection, {
|
6
|
-
initialize: async function (options) { },
|
7
|
-
});
|
8
|
-
const toGroupLayoutObject = (groupLayoutObject) => {
|
9
|
-
return {
|
10
|
-
_id: groupLayoutObject._id,
|
11
|
-
id: groupLayoutObject._id,
|
12
|
-
personalizeId: groupLayoutObject.layerId,
|
13
|
-
layerId: groupLayoutObject.layerId,
|
14
|
-
name: groupLayoutObject.name,
|
15
|
-
locked: groupLayoutObject.locked,
|
16
|
-
isAdditional: groupLayoutObject?.isAdditional,
|
17
|
-
};
|
18
|
-
};
|
19
|
-
exports.toGroupLayoutObject = toGroupLayoutObject;
|
20
|
-
class GroupLayout extends fabric_1.fabric.ActiveSelection {
|
21
|
-
constructor(options) {
|
22
|
-
super();
|
23
|
-
return new GroupLayoutClass(options);
|
24
|
-
}
|
25
|
-
}
|
26
|
-
exports.default = GroupLayout;
|
package/lib/constants/index.d.ts
DELETED
package/lib/constants/index.js
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.OBJECT_TYPES = void 0;
|
4
|
-
const constants_1 = require("../ClipartObject/constants");
|
5
|
-
const constants_2 = require("../ImagePlaceholderObject/constants");
|
6
|
-
const constants_3 = require("../TextInputObject/constants");
|
7
|
-
exports.OBJECT_TYPES = {
|
8
|
-
textInput: constants_3.TEXT_INPUT_OBJECT_ATTRIBUTES.type,
|
9
|
-
clipart: constants_1.CLIPART_OBJECT_ATTRIBUTES.type,
|
10
|
-
imagePlaceHolder: constants_2.IMAGE_PLACEHOLDER_OBJECT_ATTRIBUTES.type,
|
11
|
-
activeSelection: "activeSelection",
|
12
|
-
};
|