customized-fabric 2.0.8 → 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 +12 -13
- 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/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
|
+
}
|
@@ -73,25 +73,26 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
|
|
73
73
|
this.fire("scaling");
|
74
74
|
},
|
75
75
|
autoChangeFontSize: function (changeSpeed = 0.1) {
|
76
|
-
let { fontSize, lengthRatio, maxFontSize } = this.textObject;
|
76
|
+
let { fontSize, lengthRatio, maxFontSize, pathLength } = this.textObject;
|
77
77
|
fontSize = Number(fontSize || 0);
|
78
78
|
lengthRatio = Number(lengthRatio || 0.4);
|
79
79
|
maxFontSize = Number(maxFontSize || 200);
|
80
|
-
const length =
|
80
|
+
const length = pathLength * lengthRatio;
|
81
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);
|
82
87
|
while (length <= maxLineWidth) {
|
83
88
|
fontSize -= changeSpeed;
|
84
|
-
this.textObject.set({
|
85
|
-
fontSize,
|
86
|
-
});
|
89
|
+
this.textObject.set({ fontSize });
|
87
90
|
this.canvas?.renderAll?.();
|
88
91
|
maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
89
92
|
}
|
90
93
|
while (maxFontSize > fontSize.toFixed(1) && length > maxLineWidth) {
|
91
94
|
fontSize += changeSpeed;
|
92
|
-
this.textObject.set({
|
93
|
-
fontSize,
|
94
|
-
});
|
95
|
+
this.textObject.set({ fontSize });
|
95
96
|
this.canvas?.renderAll?.();
|
96
97
|
maxLineWidth = Math.max(...this.textObject.__lineWidths);
|
97
98
|
}
|
@@ -165,10 +166,7 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
|
|
165
166
|
calculateTextPath: function (width, height) {
|
166
167
|
let { pathSide, positionAngle } = this.textObject;
|
167
168
|
positionAngle = Number(positionAngle || 0);
|
168
|
-
const
|
169
|
-
const rx = (width - textHeight) / 2;
|
170
|
-
const ry = (height - textHeight) / 2;
|
171
|
-
const path = new fabric_1.fabric.Path((0, svg_util_1.getEllipsePath)(rx, ry, pathSide), {
|
169
|
+
const path = new fabric_1.fabric.Path((0, svg_util_1.getEllipsePath)(width, height), {
|
172
170
|
fill: undefined,
|
173
171
|
stroke: "black",
|
174
172
|
objectCaching: false,
|
@@ -178,12 +176,13 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group,
|
|
178
176
|
});
|
179
177
|
this.pathObject = path;
|
180
178
|
const pathInfo = fabric_1.fabric.util?.getPathSegmentsInfo?.(path.path);
|
181
|
-
const pathLength = pathInfo
|
179
|
+
const pathLength = pathInfo.pop().length;
|
182
180
|
const pathStartOffset = ((positionAngle % 360) * pathLength) / 360;
|
183
181
|
this.textObject.set({
|
184
182
|
path,
|
185
183
|
pathLength,
|
186
184
|
pathStartOffset,
|
185
|
+
angle: (pathSide == "left" ? 0 : 1) * 180,
|
187
186
|
});
|
188
187
|
this?.canvas?.renderAll();
|
189
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; } });
|
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;
|