customized-fabric 2.0.7 → 2.0.9
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/AdvancedText/constants.d.ts +11 -0
- package/lib/AdvancedText/constants.js +14 -0
- package/lib/AdvancedText/index.d.ts +5 -0
- package/lib/AdvancedText/index.js +198 -0
- package/lib/AdvancedText/interfaces.d.ts +29 -0
- package/lib/AdvancedText/interfaces.js +2 -0
- package/lib/CurvedTextObject/index.js +23 -20
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +2 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/lib/utils/common.util.d.ts +1 -0
- package/lib/utils/common.util.js +13 -0
- package/lib/utils/svg.util.d.ts +5 -2
- package/lib/utils/svg.util.js +32 -11
- package/package.json +1 -1
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.PARENT_ATTRIBUTES = exports.ADVANCED_TEXT_OBJECT_ATTRIBUTES = void 0;
|
4
|
+
exports.ADVANCED_TEXT_OBJECT_ATTRIBUTES = {
|
5
|
+
name: "Advanced text",
|
6
|
+
type: "ADVANCED_TEXT",
|
7
|
+
maxFontSize: 200,
|
8
|
+
stroke: {
|
9
|
+
stroke: "#333",
|
10
|
+
strokeDashArray: [5, 5],
|
11
|
+
strokeWidth: 1,
|
12
|
+
},
|
13
|
+
};
|
14
|
+
exports.PARENT_ATTRIBUTES = ["top", "left", "width", "height", "angle"];
|
@@ -0,0 +1,198 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const fabric_1 = require("fabric");
|
4
|
+
const constants_1 = require("./constants");
|
5
|
+
const utils_1 = require("../utils");
|
6
|
+
const objectId_1 = require("../utils/objectId");
|
7
|
+
const svg_util_1 = require("../utils/svg.util");
|
8
|
+
const common_util_1 = require("../utils/common.util");
|
9
|
+
const AdvancedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
|
10
|
+
initialize: function (options) {
|
11
|
+
let { text, ...rest } = options ?? {};
|
12
|
+
this.rectObject = new fabric_1.fabric.Rect({
|
13
|
+
width: options?.width,
|
14
|
+
height: options?.height,
|
15
|
+
fill: undefined,
|
16
|
+
originX: "center",
|
17
|
+
originY: "center",
|
18
|
+
objectCaching: false,
|
19
|
+
...constants_1.ADVANCED_TEXT_OBJECT_ATTRIBUTES.stroke,
|
20
|
+
});
|
21
|
+
text = (0, common_util_1.removeValueKeys)(text);
|
22
|
+
const { prefix = "", infix = "", suffix = "", isAllCapital } = text ?? {};
|
23
|
+
const fullText = prefix + infix + suffix;
|
24
|
+
this.textObject = new fabric_1.fabric.IText("", {
|
25
|
+
originX: "center",
|
26
|
+
originY: "center",
|
27
|
+
textAlign: "center",
|
28
|
+
objectCaching: false,
|
29
|
+
fontFamily: "",
|
30
|
+
paintFirst: "stroke",
|
31
|
+
lengthRatio: 0.4,
|
32
|
+
positionAngle: 0,
|
33
|
+
maxFontSize: 200,
|
34
|
+
pathType: "parabola",
|
35
|
+
...text,
|
36
|
+
text: isAllCapital ? fullText.toUpperCase() : fullText,
|
37
|
+
});
|
38
|
+
const group = new fabric_1.fabric.Group([this.rectObject, this.textObject]);
|
39
|
+
this.set({
|
40
|
+
...group,
|
41
|
+
_id: new objectId_1.ObjectId().toString(),
|
42
|
+
name: constants_1.ADVANCED_TEXT_OBJECT_ATTRIBUTES.name,
|
43
|
+
type: constants_1.ADVANCED_TEXT_OBJECT_ATTRIBUTES.type,
|
44
|
+
...rest,
|
45
|
+
layerId: options?.personalizeId ?? options?.layerId,
|
46
|
+
objectCaching: false,
|
47
|
+
pathVisible: !(options?.isOriginal || options?.hideStroke),
|
48
|
+
});
|
49
|
+
this.on("scaling", () => {
|
50
|
+
let width = this.width * this.scaleX;
|
51
|
+
let height = this.height * this.scaleY;
|
52
|
+
const attributes = {
|
53
|
+
scaleX: 1,
|
54
|
+
scaleY: 1,
|
55
|
+
width,
|
56
|
+
height,
|
57
|
+
};
|
58
|
+
this.set(attributes);
|
59
|
+
this.rectObject.set(attributes);
|
60
|
+
this.calculateTextPath(width, height);
|
61
|
+
this.autoChangeFontSize();
|
62
|
+
this.canvas?.renderAll?.();
|
63
|
+
});
|
64
|
+
if (options?.isOriginal) {
|
65
|
+
this.rectObject?.set({ strokeWidth: 0 });
|
66
|
+
}
|
67
|
+
else {
|
68
|
+
if (options?.hideStroke) {
|
69
|
+
this.rectObject?.set({ strokeWidth: 0 });
|
70
|
+
}
|
71
|
+
this.setFontFamily(text?.fontFamily ?? "", options?.fontUrl);
|
72
|
+
}
|
73
|
+
this.fire("scaling");
|
74
|
+
},
|
75
|
+
autoChangeFontSize: function (changeSpeed = 0.1) {
|
76
|
+
let { fontSize, maxFontSize, pathLength } = this.textObject;
|
77
|
+
fontSize = Number(fontSize || 0);
|
78
|
+
maxFontSize = Number(maxFontSize || 200);
|
79
|
+
const length = pathLength - 10;
|
80
|
+
let maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
81
|
+
const ratio = length / maxLineWidth;
|
82
|
+
fontSize = Math.min(maxFontSize, fontSize * ratio);
|
83
|
+
this.textObject.set({ fontSize });
|
84
|
+
this.canvas?.renderAll?.();
|
85
|
+
maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
86
|
+
while (length <= maxLineWidth) {
|
87
|
+
fontSize -= changeSpeed;
|
88
|
+
this.textObject.set({ fontSize });
|
89
|
+
this.canvas?.renderAll?.();
|
90
|
+
maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
91
|
+
}
|
92
|
+
while (maxFontSize > fontSize.toFixed(1) && length > maxLineWidth) {
|
93
|
+
fontSize += changeSpeed;
|
94
|
+
this.textObject.set({ fontSize });
|
95
|
+
this.canvas?.renderAll?.();
|
96
|
+
maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
97
|
+
}
|
98
|
+
},
|
99
|
+
setText: function (text) {
|
100
|
+
this.textObject.set({
|
101
|
+
text,
|
102
|
+
});
|
103
|
+
this.fire("scaling");
|
104
|
+
},
|
105
|
+
setPrefix: function (text) {
|
106
|
+
this.textObject.set({
|
107
|
+
prefix: text,
|
108
|
+
});
|
109
|
+
this.getText();
|
110
|
+
},
|
111
|
+
setInfix: function (text) {
|
112
|
+
this.textObject.set({
|
113
|
+
infix: text,
|
114
|
+
});
|
115
|
+
this.getText();
|
116
|
+
},
|
117
|
+
setSuffix: function (text) {
|
118
|
+
this.textObject.set({
|
119
|
+
suffix: text,
|
120
|
+
});
|
121
|
+
this.getText();
|
122
|
+
},
|
123
|
+
getText: function () {
|
124
|
+
const { prefix = "", infix = "", suffix = "", isAllCapital, } = this.textObject;
|
125
|
+
const text = prefix + infix + suffix;
|
126
|
+
this.setText(infix?.length > 0 ? (isAllCapital ? text.toUpperCase() : text) : "");
|
127
|
+
},
|
128
|
+
setMaxFontSize: function (fontSize) {
|
129
|
+
this.textObject.set({
|
130
|
+
fontSize,
|
131
|
+
maxFontSize: fontSize,
|
132
|
+
});
|
133
|
+
this.fire("scaling");
|
134
|
+
},
|
135
|
+
setFontFamily: async function (fontName, fontUrl) {
|
136
|
+
if (!(0, utils_1.isFontLoaded)(fontName)) {
|
137
|
+
await (0, utils_1.loadFontFromUrl)(fontUrl ?? "", fontName);
|
138
|
+
}
|
139
|
+
this.textObject.set({ fontFamily: fontName });
|
140
|
+
this.fire("scaling");
|
141
|
+
},
|
142
|
+
setSizes: function (options) {
|
143
|
+
const { width, height } = options;
|
144
|
+
if (width) {
|
145
|
+
this.set({ width });
|
146
|
+
}
|
147
|
+
if (height) {
|
148
|
+
this.set({ height });
|
149
|
+
}
|
150
|
+
this.fire("scaling");
|
151
|
+
},
|
152
|
+
setTextAttributes: function (options) {
|
153
|
+
this.textObject.set(options);
|
154
|
+
this.fire("scaling");
|
155
|
+
},
|
156
|
+
getTextAttribute: function (attribute) {
|
157
|
+
return this.textObject.get(attribute);
|
158
|
+
},
|
159
|
+
getSettings: function (attribute) {
|
160
|
+
if (constants_1.PARENT_ATTRIBUTES.includes(attribute)) {
|
161
|
+
return this.get(attribute);
|
162
|
+
}
|
163
|
+
return this.textObject.get(attribute);
|
164
|
+
},
|
165
|
+
calculateTextPath: function (width, height) {
|
166
|
+
const { pathSide, pathType = "parabola" } = this.textObject;
|
167
|
+
const pathSvg = (0, svg_util_1.getPath)(width, height, pathType);
|
168
|
+
const sideFactor = pathSide == "left" ? -1 : 1;
|
169
|
+
const pathProperties = {
|
170
|
+
top: pathType == "parabola" ? (sideFactor * height) / 4 : 0,
|
171
|
+
angle: (pathSide == "left" ? 0 : 1) * 180,
|
172
|
+
};
|
173
|
+
const path = new fabric_1.fabric.Path(pathSvg, {
|
174
|
+
fill: undefined,
|
175
|
+
stroke: "black",
|
176
|
+
objectCaching: false,
|
177
|
+
originX: "center",
|
178
|
+
originY: "center",
|
179
|
+
visible: this.pathVisible,
|
180
|
+
});
|
181
|
+
this.pathObject = path;
|
182
|
+
const pathInfo = fabric_1.fabric.util?.getPathSegmentsInfo?.(path.path);
|
183
|
+
const pathLength = pathInfo.pop().length;
|
184
|
+
this.textObject.set({
|
185
|
+
...pathProperties,
|
186
|
+
path,
|
187
|
+
pathLength,
|
188
|
+
});
|
189
|
+
this?.canvas?.renderAll();
|
190
|
+
},
|
191
|
+
});
|
192
|
+
class AdvancedText extends fabric_1.fabric.Group {
|
193
|
+
constructor(options) {
|
194
|
+
super();
|
195
|
+
return new AdvancedTextClass(options);
|
196
|
+
}
|
197
|
+
}
|
198
|
+
exports.default = AdvancedText;
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { ObjectId } from "../utils/objectId";
|
2
|
+
export interface IAdvancedTextOptions extends fabric.IObjectOptions {
|
3
|
+
_id?: ObjectId;
|
4
|
+
personalizeId?: string;
|
5
|
+
layerId: number;
|
6
|
+
text: {
|
7
|
+
fontSize?: number;
|
8
|
+
fill?: string;
|
9
|
+
width?: number;
|
10
|
+
height?: number;
|
11
|
+
textAlign?: string;
|
12
|
+
fontWeight?: string;
|
13
|
+
text?: string;
|
14
|
+
fontFamily?: string;
|
15
|
+
maxFontSize: number;
|
16
|
+
stroke?: string;
|
17
|
+
strokeWidth?: number;
|
18
|
+
prefix?: string;
|
19
|
+
infix?: string;
|
20
|
+
suffix?: string;
|
21
|
+
lengthRatio?: number;
|
22
|
+
positionAngle?: number;
|
23
|
+
isAllCapital?: boolean;
|
24
|
+
};
|
25
|
+
fontUrl?: string;
|
26
|
+
isOriginal?: boolean;
|
27
|
+
isAdditional?: boolean;
|
28
|
+
hideStroke?: boolean;
|
29
|
+
}
|
@@ -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
|
-
|
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.
|
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,25 +73,26 @@ 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
|
74
|
-
fontSize = Number(fontSize);
|
75
|
-
lengthRatio = Number(lengthRatio);
|
76
|
-
maxFontSize = Number(maxFontSize);
|
77
|
-
const length =
|
76
|
+
let { fontSize, lengthRatio, maxFontSize, pathLength } = this.textObject;
|
77
|
+
fontSize = Number(fontSize || 0);
|
78
|
+
lengthRatio = Number(lengthRatio || 0.4);
|
79
|
+
maxFontSize = Number(maxFontSize || 200);
|
80
|
+
const length = pathLength * lengthRatio;
|
78
81
|
let maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
82
|
+
const ratio = length / maxLineWidth;
|
83
|
+
fontSize = Math.min(maxFontSize, fontSize * ratio);
|
84
|
+
this.textObject.set({ fontSize });
|
85
|
+
this.canvas?.renderAll?.();
|
86
|
+
maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
79
87
|
while (length <= maxLineWidth) {
|
80
88
|
fontSize -= changeSpeed;
|
81
|
-
this.textObject.set({
|
82
|
-
fontSize,
|
83
|
-
});
|
89
|
+
this.textObject.set({ fontSize });
|
84
90
|
this.canvas?.renderAll?.();
|
85
91
|
maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
86
92
|
}
|
87
93
|
while (maxFontSize > fontSize.toFixed(1) && length > maxLineWidth) {
|
88
94
|
fontSize += changeSpeed;
|
89
|
-
this.textObject.set({
|
90
|
-
fontSize,
|
91
|
-
});
|
95
|
+
this.textObject.set({ fontSize });
|
92
96
|
this.canvas?.renderAll?.();
|
93
97
|
maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
94
98
|
}
|
@@ -160,11 +164,9 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
|
|
160
164
|
return this.textObject.get(attribute);
|
161
165
|
},
|
162
166
|
calculateTextPath: function (width, height) {
|
163
|
-
|
164
|
-
|
165
|
-
const
|
166
|
-
const ry = (height - textHeight) / 2;
|
167
|
-
const path = new fabric_1.fabric.Path((0, svg_util_1.getEllipsePath)(rx, ry, pathSide), {
|
167
|
+
let { pathSide, positionAngle } = this.textObject;
|
168
|
+
positionAngle = Number(positionAngle || 0);
|
169
|
+
const path = new fabric_1.fabric.Path((0, svg_util_1.getEllipsePath)(width, height), {
|
168
170
|
fill: undefined,
|
169
171
|
stroke: "black",
|
170
172
|
objectCaching: false,
|
@@ -174,12 +176,13 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
|
|
174
176
|
});
|
175
177
|
this.pathObject = path;
|
176
178
|
const pathInfo = fabric_1.fabric.util?.getPathSegmentsInfo?.(path.path);
|
177
|
-
const pathLength = pathInfo
|
179
|
+
const pathLength = pathInfo.pop().length;
|
178
180
|
const pathStartOffset = ((positionAngle % 360) * pathLength) / 360;
|
179
181
|
this.textObject.set({
|
180
182
|
path,
|
181
183
|
pathLength,
|
182
184
|
pathStartOffset,
|
185
|
+
angle: (pathSide == "left" ? 0 : 1) * 180,
|
183
186
|
});
|
184
187
|
this?.canvas?.renderAll();
|
185
188
|
},
|
package/lib/constants.d.ts
CHANGED
package/lib/constants.js
CHANGED
@@ -8,6 +8,7 @@ const constants_4 = require("./ImagePlaceholderObject/constants");
|
|
8
8
|
const constants_5 = require("./LayoutGroupObject/constants");
|
9
9
|
const constants_6 = require("./QRCodeObject/constants");
|
10
10
|
const constants_7 = require("./TextInputObject/constants");
|
11
|
+
const constants_8 = require("./AdvancedText/constants");
|
11
12
|
exports.OBJECT_TYPES = {
|
12
13
|
textInput: constants_7.TEXT_INPUT_OBJECT_ATTRIBUTES.type,
|
13
14
|
curvedText: constants_3.CURVED_TEXT_OBJECT_ATTRIBUTES.type,
|
@@ -17,5 +18,6 @@ exports.OBJECT_TYPES = {
|
|
17
18
|
layoutGroup: constants_5.LAYOUT_GROUP_OBJECT_ATTRIBUTES.type,
|
18
19
|
calendar: constants_1.CALENDAR_OBJECT_ATTRIBUTES.type,
|
19
20
|
qrCode: constants_6.QR_CODE_OBJECT_ATTRIBUTES.type,
|
21
|
+
advancedText: constants_8.ADVANCED_TEXT_OBJECT_ATTRIBUTES.type,
|
20
22
|
};
|
21
23
|
exports.MAX_TEXTURE_SIZE = 20000;
|
package/lib/index.d.ts
CHANGED
@@ -5,8 +5,9 @@ import ImagePlaceholder from "./ImagePlaceholderObject";
|
|
5
5
|
import LayoutGroup from "./LayoutGroupObject";
|
6
6
|
import Calendar from "./CalendarObject";
|
7
7
|
import QRCode from "./QRCodeObject";
|
8
|
+
import AdvancedText from "./AdvancedText";
|
8
9
|
import fabric, { lockObject, lockAllObjects, loadImageFromFile, loadImageFromUrl, getObject, asyncGetObject } from "./utils";
|
9
10
|
import { OBJECT_TYPES } from "./constants";
|
10
11
|
import { IMAGE_FILTER_TYPES } from "./ImagePlaceholderObject/constants";
|
11
12
|
import { IMAGE_PLACEHOLDER_OBJECT_ATTRIBUTES } from "./ImagePlaceholderObject/constants";
|
12
|
-
export { fabric, TextInput, Clipart, ImagePlaceholder, LayoutGroup, CurvedText, Calendar, QRCode, lockObject, lockAllObjects, loadImageFromFile, loadImageFromUrl, getObject, asyncGetObject, OBJECT_TYPES, IMAGE_PLACEHOLDER_OBJECT_ATTRIBUTES, IMAGE_FILTER_TYPES, };
|
13
|
+
export { fabric, TextInput, Clipart, ImagePlaceholder, LayoutGroup, CurvedText, Calendar, QRCode, AdvancedText, lockObject, lockAllObjects, loadImageFromFile, loadImageFromUrl, getObject, asyncGetObject, OBJECT_TYPES, IMAGE_PLACEHOLDER_OBJECT_ATTRIBUTES, IMAGE_FILTER_TYPES, };
|
package/lib/index.js
CHANGED
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
27
|
};
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
exports.IMAGE_FILTER_TYPES = exports.IMAGE_PLACEHOLDER_OBJECT_ATTRIBUTES = exports.OBJECT_TYPES = exports.asyncGetObject = exports.getObject = exports.loadImageFromUrl = exports.loadImageFromFile = exports.lockAllObjects = exports.lockObject = exports.QRCode = exports.Calendar = exports.CurvedText = exports.LayoutGroup = exports.ImagePlaceholder = exports.Clipart = exports.TextInput = exports.fabric = void 0;
|
29
|
+
exports.IMAGE_FILTER_TYPES = exports.IMAGE_PLACEHOLDER_OBJECT_ATTRIBUTES = exports.OBJECT_TYPES = exports.asyncGetObject = exports.getObject = exports.loadImageFromUrl = exports.loadImageFromFile = exports.lockAllObjects = exports.lockObject = exports.AdvancedText = exports.QRCode = exports.Calendar = exports.CurvedText = exports.LayoutGroup = exports.ImagePlaceholder = exports.Clipart = exports.TextInput = exports.fabric = void 0;
|
30
30
|
const TextInputObject_1 = __importDefault(require("./TextInputObject"));
|
31
31
|
exports.TextInput = TextInputObject_1.default;
|
32
32
|
const CurvedTextObject_1 = __importDefault(require("./CurvedTextObject"));
|
@@ -41,6 +41,8 @@ const CalendarObject_1 = __importDefault(require("./CalendarObject"));
|
|
41
41
|
exports.Calendar = CalendarObject_1.default;
|
42
42
|
const QRCodeObject_1 = __importDefault(require("./QRCodeObject"));
|
43
43
|
exports.QRCode = QRCodeObject_1.default;
|
44
|
+
const AdvancedText_1 = __importDefault(require("./AdvancedText"));
|
45
|
+
exports.AdvancedText = AdvancedText_1.default;
|
44
46
|
const utils_1 = __importStar(require("./utils"));
|
45
47
|
exports.fabric = utils_1.default;
|
46
48
|
Object.defineProperty(exports, "lockObject", { enumerable: true, get: function () { return utils_1.lockObject; } });
|
@@ -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/lib/utils/svg.util.d.ts
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
import { fabric } from "fabric";
|
2
|
-
export
|
2
|
+
export type PathType = "parabola" | "ellipse" | "half-ellipse";
|
3
|
+
export declare const getEllipsePath: (width: number, height: number) => string;
|
3
4
|
export declare const getPathLength: (path: fabric.Path) => any;
|
4
|
-
export declare const
|
5
|
+
export declare const getParabolaPath: (width: number, height: number) => string;
|
6
|
+
export declare const getHalfEllipsePath: (width: number, height: number) => string;
|
7
|
+
export declare const getPath: (width: number, height: number, type: PathType) => string;
|
package/lib/utils/svg.util.js
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.getPath = exports.getHalfEllipsePath = exports.getParabolaPath = exports.getPathLength = exports.getEllipsePath = void 0;
|
4
4
|
const fabric_1 = require("fabric");
|
5
|
-
const getEllipsePath = (
|
6
|
-
const
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
output += `a ${rx},${ry} 0 0,1 0,${ry * -2 * sideFactor}`;
|
11
|
-
return output;
|
5
|
+
const getEllipsePath = (width, height) => {
|
6
|
+
const start = `${0} ${height / 2}`;
|
7
|
+
const rxy = `${width / 2} ${height / 2}`;
|
8
|
+
const end = `${0} ${-height / 2}`;
|
9
|
+
return `M ${start} A ${rxy} 0 0 1 ${end} A ${rxy} 0 0 1 ${start}`;
|
12
10
|
};
|
13
11
|
exports.getEllipsePath = getEllipsePath;
|
14
12
|
const getPathLength = (path) => {
|
@@ -17,7 +15,30 @@ const getPathLength = (path) => {
|
|
17
15
|
return pathLength;
|
18
16
|
};
|
19
17
|
exports.getPathLength = getPathLength;
|
20
|
-
const
|
21
|
-
|
18
|
+
const getParabolaPath = (width, height) => {
|
19
|
+
const start = `-${width / 2} -${height}`;
|
20
|
+
const peak = `${0} -${height * 3}`;
|
21
|
+
const end = `${width / 2} -${height}`;
|
22
|
+
return `M ${start} Q ${peak} ${end}`;
|
22
23
|
};
|
23
|
-
exports.
|
24
|
+
exports.getParabolaPath = getParabolaPath;
|
25
|
+
const getHalfEllipsePath = (width, height) => {
|
26
|
+
const start = `-${width / 2} ${0}`;
|
27
|
+
const rxy = `${width / 2} ${height}`;
|
28
|
+
const end = `${width / 2} ${0}`;
|
29
|
+
return `M ${start} A ${rxy} 0 0 1 ${end}`;
|
30
|
+
};
|
31
|
+
exports.getHalfEllipsePath = getHalfEllipsePath;
|
32
|
+
const getPath = (width, height, type) => {
|
33
|
+
switch (type) {
|
34
|
+
case "ellipse":
|
35
|
+
return (0, exports.getEllipsePath)(width, height);
|
36
|
+
case "half-ellipse":
|
37
|
+
return (0, exports.getHalfEllipsePath)(width, height);
|
38
|
+
case "parabola":
|
39
|
+
return (0, exports.getParabolaPath)(width, height);
|
40
|
+
default:
|
41
|
+
return "";
|
42
|
+
}
|
43
|
+
};
|
44
|
+
exports.getPath = getPath;
|