plotboilerplate 1.24.0 → 1.26.0
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/README.md +14 -1
- package/dist/index.esm.js +433 -162
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/plotboilerplate.browser.min.js +1 -1
- package/dist/plotboilerplate.browser.min.js.map +1 -1
- package/dist/plotboilerplate.js +12312 -12041
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +9 -5
- package/src/cjs/Bounds.d.ts +79 -25
- package/src/cjs/Bounds.js +102 -29
- package/src/cjs/Bounds.js.map +1 -1
- package/src/cjs/CircleSector.d.ts +3 -0
- package/src/cjs/CircleSector.js +28 -1
- package/src/cjs/CircleSector.js.map +1 -1
- package/src/cjs/PlotBoilerplate.d.ts +37 -6
- package/src/cjs/PlotBoilerplate.js +222 -116
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +26 -7
- package/src/cjs/Polygon.js +56 -10
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Triangle.js +2 -2
- package/src/cjs/Triangle.js.map +1 -1
- package/src/cjs/Vertex.d.ts +15 -3
- package/src/cjs/Vertex.js +18 -1
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/drawutilssvg.d.ts +2 -1
- package/src/cjs/drawutilssvg.js +9 -3
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +28 -0
- package/src/cjs/interfaces/core.js +2 -0
- package/src/cjs/interfaces/core.js.map +1 -1
- package/src/cjs/utils/LissajousFigure.d.ts +34 -0
- package/src/cjs/utils/LissajousFigure.js +100 -0
- package/src/cjs/utils/LissajousFigure.js.map +1 -0
- package/src/cjs/utils/PerlinNoise.d.ts +19 -0
- package/src/cjs/utils/PerlinNoise.js +352 -0
- package/src/cjs/utils/PerlinNoise.js.map +1 -0
- package/src/cjs/utils/SVGPathUtils.d.ts +22 -0
- package/src/cjs/utils/SVGPathUtils.js +45 -0
- package/src/cjs/utils/SVGPathUtils.js.map +1 -0
- package/src/cjs/utils/algorithms/pixelCornersToRoundPaths.d.ts +23 -0
- package/src/cjs/utils/algorithms/pixelCornersToRoundPaths.js +270 -0
- package/src/cjs/utils/algorithms/pixelCornersToRoundPaths.js.map +1 -0
- package/src/cjs/utils/datastructures/Color.d.ts +147 -1
- package/src/cjs/utils/datastructures/Color.js +385 -41
- package/src/cjs/utils/datastructures/Color.js.map +1 -1
- package/src/cjs/utils/datastructures/ColorGradient.d.ts +79 -0
- package/src/cjs/utils/datastructures/ColorGradient.js +171 -0
- package/src/cjs/utils/datastructures/ColorGradient.js.map +1 -0
- package/src/cjs/utils/datastructures/DataGrid2d.d.ts +6 -0
- package/src/cjs/utils/datastructures/DataGrid2dArrayMatrix.d.ts +88 -0
- package/src/cjs/utils/datastructures/DataGrid2dArrayMatrix.js +155 -0
- package/src/cjs/utils/datastructures/DataGrid2dArrayMatrix.js.map +1 -0
- package/src/cjs/utils/datastructures/DataGrid2dListAdapter.d.ts +1 -7
- package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js +3 -3
- package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js.map +1 -1
- package/src/cjs/utils/datastructures/GeometryMesh.d.ts +49 -0
- package/src/cjs/utils/datastructures/GeometryMesh.js +58 -0
- package/src/cjs/utils/datastructures/GeometryMesh.js.map +1 -0
- package/src/cjs/utils/detectDarkMode.js +16 -7
- package/src/cjs/utils/detectDarkMode.js.map +1 -1
- package/src/cjs/utils/dom/components/ColorGradientPicker.d.ts +246 -0
- package/src/cjs/utils/dom/components/ColorGradientPicker.js +667 -0
- package/src/cjs/utils/dom/components/ColorGradientPicker.js.map +1 -0
- package/src/cjs/utils/dom/components/ColorGradientPickerJSX.d.ts +129 -0
- package/src/cjs/utils/dom/components/ColorGradientPickerJSX.js +520 -0
- package/src/cjs/utils/dom/components/ColorGradientPickerJSX.js.map +1 -0
- package/src/cjs/utils/dom/components/ColorGradientSelector.d.ts +118 -0
- package/src/cjs/utils/dom/components/ColorGradientSelector.js +327 -0
- package/src/cjs/utils/dom/components/ColorGradientSelector.js.map +1 -0
- package/src/cjs/utils/dom/components/Test.d.ts +7 -0
- package/src/cjs/utils/dom/components/Test.js +30 -0
- package/src/cjs/utils/dom/components/Test.js.map +1 -0
- package/src/cjs/utils/dom/guiSizeToggler.js +1 -1
- package/src/cjs/utils/dom/guiSizeToggler.js.map +1 -1
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +9 -3
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +20 -13
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/cjs/utils/helpers/CircleHelper.d.ts +10 -1
- package/src/cjs/utils/helpers/CircleHelper.js +13 -2
- package/src/cjs/utils/helpers/CircleHelper.js.map +1 -1
- package/src/cjs/utils/helpers/CircleSectorHelper.d.ts +2 -2
- package/src/cjs/utils/helpers/CircleSectorHelper.js +1 -0
- package/src/cjs/utils/helpers/CircleSectorHelper.js.map +1 -1
- package/src/cjs/utils/helpers/TriangleHelper.d.ts +57 -0
- package/src/cjs/utils/helpers/TriangleHelper.js +83 -0
- package/src/cjs/utils/helpers/TriangleHelper.js.map +1 -0
- package/src/cjs/utils/helpers/VEllipseHelper.d.ts +6 -4
- package/src/cjs/utils/helpers/VEllipseHelper.js +4 -2
- package/src/cjs/utils/helpers/VEllipseHelper.js.map +1 -1
- package/src/cjs/utils/helpers/VEllipseSectorHelper.d.ts +3 -2
- package/src/cjs/utils/helpers/VEllipseSectorHelper.js +1 -0
- package/src/cjs/utils/helpers/VEllipseSectorHelper.js.map +1 -1
- package/src/cjs/utils/parsers/LinearColorGradientParser.d.ts +78 -0
- package/src/cjs/utils/parsers/LinearColorGradientParser.js +224 -0
- package/src/cjs/utils/parsers/LinearColorGradientParser.js.map +1 -0
- package/src/cjs/utils/parsers/svg/types.d.ts +8 -8
- package/src/createDemoDrawables.js +1 -0
- package/src/esm/Bounds.d.ts +79 -25
- package/src/esm/Bounds.js +102 -29
- package/src/esm/Bounds.js.map +1 -1
- package/src/esm/CircleSector.d.ts +3 -0
- package/src/esm/CircleSector.js +28 -1
- package/src/esm/CircleSector.js.map +1 -1
- package/src/esm/PlotBoilerplate.d.ts +37 -6
- package/src/esm/PlotBoilerplate.js +222 -116
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +26 -7
- package/src/esm/Polygon.js +53 -10
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Triangle.js +2 -2
- package/src/esm/Triangle.js.map +1 -1
- package/src/esm/Vertex.d.ts +15 -3
- package/src/esm/Vertex.js +18 -1
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/drawutilssvg.d.ts +2 -1
- package/src/esm/drawutilssvg.js +9 -3
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +28 -0
- package/src/esm/interfaces/core.js +2 -0
- package/src/esm/interfaces/core.js.map +1 -1
- package/src/esm/utils/LissajousFigure.d.ts +34 -0
- package/src/esm/utils/LissajousFigure.js +95 -0
- package/src/esm/utils/LissajousFigure.js.map +1 -0
- package/src/esm/utils/PerlinNoise.d.ts +19 -0
- package/src/esm/utils/PerlinNoise.js +346 -0
- package/src/esm/utils/PerlinNoise.js.map +1 -0
- package/src/esm/utils/SVGPathUtils.d.ts +22 -0
- package/src/esm/utils/SVGPathUtils.js +42 -0
- package/src/esm/utils/SVGPathUtils.js.map +1 -0
- package/src/esm/utils/algorithms/pixelCornersToRoundPaths.d.ts +23 -0
- package/src/esm/utils/algorithms/pixelCornersToRoundPaths.js +266 -0
- package/src/esm/utils/algorithms/pixelCornersToRoundPaths.js.map +1 -0
- package/src/esm/utils/datastructures/Color.d.ts +147 -1
- package/src/esm/utils/datastructures/Color.js +386 -42
- package/src/esm/utils/datastructures/Color.js.map +1 -1
- package/src/esm/utils/datastructures/ColorGradient.d.ts +79 -0
- package/src/esm/utils/datastructures/ColorGradient.js +166 -0
- package/src/esm/utils/datastructures/ColorGradient.js.map +1 -0
- package/src/esm/utils/datastructures/DataGrid2d.d.ts +6 -0
- package/src/esm/utils/datastructures/DataGrid2dArrayMatrix.d.ts +88 -0
- package/src/esm/utils/datastructures/DataGrid2dArrayMatrix.js +150 -0
- package/src/esm/utils/datastructures/DataGrid2dArrayMatrix.js.map +1 -0
- package/src/esm/utils/datastructures/DataGrid2dListAdapter.d.ts +1 -7
- package/src/esm/utils/datastructures/DataGrid2dListAdapter.js +3 -3
- package/src/esm/utils/datastructures/DataGrid2dListAdapter.js.map +1 -1
- package/src/esm/utils/datastructures/GeometryMesh.d.ts +49 -0
- package/src/esm/utils/datastructures/GeometryMesh.js +53 -0
- package/src/esm/utils/datastructures/GeometryMesh.js.map +1 -0
- package/src/esm/utils/detectDarkMode.js +16 -7
- package/src/esm/utils/detectDarkMode.js.map +1 -1
- package/src/esm/utils/dom/components/ColorGradientPicker.d.ts +246 -0
- package/src/esm/utils/dom/components/ColorGradientPicker.js +743 -0
- package/src/esm/utils/dom/components/ColorGradientPicker.js.map +1 -0
- package/src/esm/utils/dom/components/ColorGradientPickerJSX.d.ts +129 -0
- package/src/esm/utils/dom/components/ColorGradientPickerJSX.js +582 -0
- package/src/esm/utils/dom/components/ColorGradientPickerJSX.js.map +1 -0
- package/src/esm/utils/dom/components/ColorGradientSelector.d.ts +118 -0
- package/src/esm/utils/dom/components/ColorGradientSelector.js +339 -0
- package/src/esm/utils/dom/components/ColorGradientSelector.js.map +1 -0
- package/src/esm/utils/dom/components/Test.d.ts +7 -0
- package/src/esm/utils/dom/components/Test.js +26 -0
- package/src/esm/utils/dom/components/Test.js.map +1 -0
- package/src/esm/utils/dom/guiSizeToggler.js +1 -1
- package/src/esm/utils/dom/guiSizeToggler.js.map +1 -1
- package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +9 -3
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js +20 -13
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/esm/utils/helpers/CircleHelper.d.ts +10 -1
- package/src/esm/utils/helpers/CircleHelper.js +13 -2
- package/src/esm/utils/helpers/CircleHelper.js.map +1 -1
- package/src/esm/utils/helpers/CircleSectorHelper.d.ts +2 -2
- package/src/esm/utils/helpers/CircleSectorHelper.js +1 -0
- package/src/esm/utils/helpers/CircleSectorHelper.js.map +1 -1
- package/src/esm/utils/helpers/TriangleHelper.d.ts +57 -0
- package/src/esm/utils/helpers/TriangleHelper.js +78 -0
- package/src/esm/utils/helpers/TriangleHelper.js.map +1 -0
- package/src/esm/utils/helpers/VEllipseHelper.d.ts +6 -4
- package/src/esm/utils/helpers/VEllipseHelper.js +4 -2
- package/src/esm/utils/helpers/VEllipseHelper.js.map +1 -1
- package/src/esm/utils/helpers/VEllipseSectorHelper.d.ts +3 -2
- package/src/esm/utils/helpers/VEllipseSectorHelper.js +1 -0
- package/src/esm/utils/helpers/VEllipseSectorHelper.js.map +1 -1
- package/src/esm/utils/parsers/LinearColorGradientParser.d.ts +78 -0
- package/src/esm/utils/parsers/LinearColorGradientParser.js +217 -0
- package/src/esm/utils/parsers/LinearColorGradientParser.js.map +1 -0
- package/src/esm/utils/parsers/svg/types.d.ts +8 -8
- package/src/external.d.ts +9 -0
- package/src/ts/Bounds.ts +107 -22
- package/src/ts/CircleSector.ts +39 -6
- package/src/ts/PlotBoilerplate.ts +233 -105
- package/src/ts/Polygon.ts +68 -14
- package/src/ts/Triangle.ts +2 -2
- package/src/ts/Vertex.ts +21 -3
- package/src/ts/drawutilssvg.ts +8 -3
- package/src/ts/interfaces/core.ts +31 -0
- package/src/ts/utils/LissajousFigure.ts +110 -0
- package/src/ts/utils/PerlinNoise.ts +368 -0
- package/src/ts/utils/SVGPathUtils.ts +55 -0
- package/src/ts/utils/algorithms/pixelCornersToRoundPaths.ts +379 -0
- package/src/ts/utils/datastructures/Color.ts +423 -44
- package/src/ts/utils/datastructures/ColorGradient.ts +196 -0
- package/src/ts/utils/datastructures/DataGrid2d.ts +7 -0
- package/src/ts/utils/datastructures/DataGrid2dArrayMatrix.ts +182 -0
- package/src/ts/utils/datastructures/DataGrid2dListAdapter.ts +4 -11
- package/src/ts/utils/datastructures/GeometryMesh.ts +79 -0
- package/src/ts/utils/detectDarkMode.ts +17 -8
- package/src/ts/utils/dom/components/ColorGradientPicker.tsx +889 -0
- package/src/ts/utils/dom/components/ColorGradientSelector.tsx +452 -0
- package/src/ts/utils/dom/components/Test.tsx +44 -0
- package/src/ts/utils/dom/components/_ColorGradientPicker_raw.ts_ +392 -0
- package/src/ts/utils/dom/guiSizeToggler.ts +1 -1
- package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +25 -15
- package/src/ts/utils/helpers/CircleHelper.ts +17 -3
- package/src/ts/utils/helpers/CircleSectorHelper.ts +4 -2
- package/src/ts/utils/helpers/TriangleHelper.ts +102 -0
- package/src/ts/utils/helpers/VEllipseHelper.ts +6 -4
- package/src/ts/utils/helpers/VEllipseSectorHelper.ts +3 -2
- package/src/ts/utils/parsers/LinearColorGradientParser.ts +297 -0
- package/src/ts/utils/parsers/svg/types.ts +8 -8
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A CSS gradient string parser.
|
|
3
|
+
*
|
|
4
|
+
* Source:
|
|
5
|
+
* https://stackoverflow.com/questions/20215440/parse-css-gradient-rule-with-javascript-regex
|
|
6
|
+
* Thanks to Dean Taylor
|
|
7
|
+
*
|
|
8
|
+
* @date 2025-09-04
|
|
9
|
+
* @OriginalAuthor Dean Taylor
|
|
10
|
+
* @RefactoredBy Ikaros Kappler, ported to Typescript.
|
|
11
|
+
* @version 1.0.0
|
|
12
|
+
*/
|
|
13
|
+
import { Color } from "../datastructures/Color";
|
|
14
|
+
import { ColorGradient } from "../datastructures/ColorGradient";
|
|
15
|
+
/**
|
|
16
|
+
* The default implementation of `PositionToRatioConverter`.
|
|
17
|
+
* @param positionString
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export const DefaultPositionConverter = (positionString) => {
|
|
21
|
+
if (typeof positionString === "undefined") {
|
|
22
|
+
throw new Error("Cannot parse positioning string `null`.");
|
|
23
|
+
}
|
|
24
|
+
const tmp = positionString.trim();
|
|
25
|
+
if (tmp.length === 0) {
|
|
26
|
+
throw new Error('Cannot parse empty positioning string "".');
|
|
27
|
+
}
|
|
28
|
+
if (!tmp.endsWith("%")) {
|
|
29
|
+
throw new Error(`Cannot parse positioning string, must end with '%': '${tmp}'`);
|
|
30
|
+
}
|
|
31
|
+
return Number.parseFloat(tmp) / 100.0;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Utility combine multiple regular expressions.
|
|
35
|
+
*
|
|
36
|
+
* Source:
|
|
37
|
+
* https://stackoverflow.com/questions/20215440/parse-css-gradient-rule-with-javascript-regex
|
|
38
|
+
* Thanks to Dean Taylor
|
|
39
|
+
*
|
|
40
|
+
* @param {Array<RegExp | string>} regexpList List of regular expressions or strings.
|
|
41
|
+
* @param {string} flags Normal RegExp flags.
|
|
42
|
+
*/
|
|
43
|
+
const __combineRegExp = (regexpList, flags) => {
|
|
44
|
+
var source = "";
|
|
45
|
+
for (var i = 0; i < regexpList.length; i++) {
|
|
46
|
+
const regex = regexpList[i];
|
|
47
|
+
if (typeof regex === "string") {
|
|
48
|
+
source += regex;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
source += regex.source;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return new RegExp(source, flags);
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Generate the required regular expressions once.
|
|
58
|
+
*
|
|
59
|
+
* Regular Expressions are easier to manage this way and can be well described.
|
|
60
|
+
*
|
|
61
|
+
* @result {object} Object containing regular expressions.
|
|
62
|
+
*/
|
|
63
|
+
const __generateDefaultRegExpLib = () => {
|
|
64
|
+
// Note any variables with "Capture" in name include capturing bracket set(s).
|
|
65
|
+
const searchFlags = "gi", // ignore case for angles, "rgb" etc
|
|
66
|
+
rAngle = /(?:[+-]?\d*\.?\d+)(?:deg|grad|rad|turn)/, // Angle +ive, -ive and angle types
|
|
67
|
+
rSideCornerCapture = /to\s+((?:(?:left|right)(?:\s+(?:top|bottom))?))/, // optional 2nd part
|
|
68
|
+
rComma = /\s*,\s*/, // Allow space around comma.
|
|
69
|
+
rColorHex = /\#(?:[a-f0-9]{6}|[a-f0-9]{3})/, // 3 or 6 character form
|
|
70
|
+
rDigits3 = /\(\s*(?:\d{1,3}\s*,\s*){2}\d{1,3}\s*\)/, // "(1, 2, 3)"
|
|
71
|
+
rDigits4 = /\(\s*(?:\d{1,3}\s*,\s*){2}\d{1,3}\s*,\s*\d*\.?\d+\)/, // "(1, 2, 3, 4)"
|
|
72
|
+
rValue = /(?:[+-]?\d*\.?\d+)(?:%|[a-z]+)?/, // ".9", "-5px", "100%".
|
|
73
|
+
rKeyword = /[_a-z-][_a-z0-9-]*/, // "red", "transparent", "border-collapse".
|
|
74
|
+
rColor = __combineRegExp(["(?:", rColorHex, "|", "(?:rgb|hsl)", rDigits3, "|", "(?:rgba|hsla)", rDigits4, "|", rKeyword, ")"], ""), rColorStop = __combineRegExp([rColor, "(?:\\s+", rValue, "(?:\\s+", rValue, ")?)?"], ""), // Single Color Stop, optional %, optional length.
|
|
75
|
+
rColorStopList = __combineRegExp(["(?:", rColorStop, rComma, ")*", rColorStop], ""), // List of color stops min 1.
|
|
76
|
+
rLineCapture = __combineRegExp(["(?:(", rAngle, ")|", rSideCornerCapture, ")"], ""), // Angle or SideCorner
|
|
77
|
+
rGradientSearch = __combineRegExp(["(?:(", rLineCapture, ")", rComma, ")?(", rColorStopList, ")"], searchFlags), // Capture 1:"line", 2:"angle" (optional), 3:"side corner" (optional) and 4:"stop list".
|
|
78
|
+
rColorStopSearch = __combineRegExp(["\\s*(", rColor, ")", "(?:\\s+", "(", rValue, "))?", "(?:", rComma, "\\s*)?"], searchFlags); // Capture 1:"color" and 2:"position" (optional).
|
|
79
|
+
return {
|
|
80
|
+
gradientSearch: rGradientSearch,
|
|
81
|
+
colorStopSearch: rColorStopSearch
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Actually parse the input gradient parameters string into an object for reusability.
|
|
86
|
+
*
|
|
87
|
+
*
|
|
88
|
+
* @note Really this only supports the standard syntax not historical versions, see MDN for details
|
|
89
|
+
* https://developer.mozilla.org/en-US/docs/Web/CSS/linear-gradient
|
|
90
|
+
*
|
|
91
|
+
* @param {ColorGradientParserRegExpLib} regExpLib
|
|
92
|
+
* @param {string} input Input string in the form "to right bottom, #FF0 0%, red 20px, rgb(0, 0, 255) 100%"
|
|
93
|
+
* @returns {object|undefined} Object containing break down of input string including array of stop points.
|
|
94
|
+
*/
|
|
95
|
+
export var __parseGradient = (regExpLib, input) => {
|
|
96
|
+
var result;
|
|
97
|
+
var matchGradient, matchColorStop, stopResult;
|
|
98
|
+
// reset search position, because we reuse regex.
|
|
99
|
+
regExpLib.gradientSearch.lastIndex = 0;
|
|
100
|
+
matchGradient = regExpLib.gradientSearch.exec(input);
|
|
101
|
+
if (matchGradient !== null) {
|
|
102
|
+
result = {
|
|
103
|
+
original: matchGradient[0],
|
|
104
|
+
colorStopList: [],
|
|
105
|
+
line: null,
|
|
106
|
+
angle: null,
|
|
107
|
+
sideCorner: null
|
|
108
|
+
};
|
|
109
|
+
// Line (Angle or Side-Corner).
|
|
110
|
+
if (!!matchGradient[1]) {
|
|
111
|
+
result.line = matchGradient[1];
|
|
112
|
+
}
|
|
113
|
+
// Angle or undefined if side-corner.
|
|
114
|
+
if (!!matchGradient[2]) {
|
|
115
|
+
result.angle = matchGradient[2];
|
|
116
|
+
}
|
|
117
|
+
// Side-corner or undefined if angle.
|
|
118
|
+
if (!!matchGradient[3]) {
|
|
119
|
+
result.sideCorner = matchGradient[3];
|
|
120
|
+
}
|
|
121
|
+
// reset search position, because we reuse regex.
|
|
122
|
+
regExpLib.colorStopSearch.lastIndex = 0;
|
|
123
|
+
// Loop though all the color-stops.
|
|
124
|
+
matchColorStop = regExpLib.colorStopSearch.exec(matchGradient[4]);
|
|
125
|
+
while (matchColorStop !== null) {
|
|
126
|
+
stopResult = {
|
|
127
|
+
color: matchColorStop[1],
|
|
128
|
+
position: null
|
|
129
|
+
};
|
|
130
|
+
// Position (optional).
|
|
131
|
+
if (!!matchColorStop[2]) {
|
|
132
|
+
stopResult.position = matchColorStop[2];
|
|
133
|
+
}
|
|
134
|
+
result.colorStopList.push(stopResult);
|
|
135
|
+
// Continue searching from previous position.
|
|
136
|
+
matchColorStop = regExpLib.colorStopSearch.exec(matchGradient[4]);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// Can be undefined if match not found.
|
|
140
|
+
return result;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* The actual parser class.
|
|
144
|
+
*/
|
|
145
|
+
export class LinearColorGradientParser {
|
|
146
|
+
constructor(regExpLib) {
|
|
147
|
+
this.regExpLib = regExpLib || __generateDefaultRegExpLib();
|
|
148
|
+
}
|
|
149
|
+
parse(input, positionConverter) {
|
|
150
|
+
const result = this.parseRaw(input);
|
|
151
|
+
return LinearColorGradientParser.parseResultToColorGradient(result, positionConverter);
|
|
152
|
+
}
|
|
153
|
+
parseRaw(input) {
|
|
154
|
+
var result;
|
|
155
|
+
const rGradientEnclosedInBrackets = /.*gradient\s*\(((?:\([^\)]*\)|[^\)\(]*)*)\)/; // Captures inside brackets - max one additional inner set.
|
|
156
|
+
const match = rGradientEnclosedInBrackets.exec(input);
|
|
157
|
+
const bracketPos = input.indexOf("(");
|
|
158
|
+
const gradientType = bracketPos === -1 ? null : input.substring(0, bracketPos).toLowerCase();
|
|
159
|
+
if (match !== null) {
|
|
160
|
+
// Get the parameters for the gradient
|
|
161
|
+
result = __parseGradient(this.regExpLib, match[1]);
|
|
162
|
+
result.gradientType = gradientType;
|
|
163
|
+
if (result.original.trim() !== match[1].trim()) {
|
|
164
|
+
// Did not match the input exactly - possible parsing error.
|
|
165
|
+
result.parseWarning = true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
// result = new Error("Failed to find gradient");
|
|
170
|
+
throw new Error("Failed to find gradient");
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
static parseResultToColorGradient(result, positionConverter) {
|
|
175
|
+
if (!result.gradientType || result.gradientType.toLowerCase() != "linear-gradient") {
|
|
176
|
+
throw new Error(`Cannot create linear gradient from type '${result.gradientType}'.`);
|
|
177
|
+
}
|
|
178
|
+
if (!result.colorStopList || result.colorStopList.length <= 1) {
|
|
179
|
+
throw new Error(`Cannot create linear gradient from color stop list of length '${result.colorStopList.length}'. Too few elements.`);
|
|
180
|
+
}
|
|
181
|
+
const colorStops = [];
|
|
182
|
+
const converter = positionConverter !== null && positionConverter !== void 0 ? positionConverter : DefaultPositionConverter;
|
|
183
|
+
for (var i = 0; i < result.colorStopList.length; i++) {
|
|
184
|
+
const stopListItem = result.colorStopList[i];
|
|
185
|
+
console.log(stopListItem);
|
|
186
|
+
const color = Color.parse(stopListItem.color);
|
|
187
|
+
// var position: number = LinearColorGradientParser.parsePosition(stopListItem.position);
|
|
188
|
+
var ratio;
|
|
189
|
+
if (typeof stopListItem.position === "undefined") {
|
|
190
|
+
// Try to auto-fill undefined positions by their index in the list.
|
|
191
|
+
ratio = i / (result.colorStopList.length - 1);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
ratio = converter(stopListItem.position);
|
|
195
|
+
}
|
|
196
|
+
colorStops.push({ color: color, ratio: ratio });
|
|
197
|
+
}
|
|
198
|
+
return new ColorGradient(colorStops, result.line);
|
|
199
|
+
}
|
|
200
|
+
} // END class
|
|
201
|
+
// var test_this_one = function (regExpLib, input) {
|
|
202
|
+
// var result,
|
|
203
|
+
// rGradientEnclosedInBrackets = /.*gradient\s*\(((?:\([^\)]*\)|[^\)\(]*)*)\)/, // Captures inside brackets - max one additional inner set.
|
|
204
|
+
// match = rGradientEnclosedInBrackets.exec(input);
|
|
205
|
+
// if (match !== null) {
|
|
206
|
+
// // Get the parameters for the gradient
|
|
207
|
+
// result = parseGradient(regExpLib, match[1]);
|
|
208
|
+
// if (result.original.trim() !== match[1].trim()) {
|
|
209
|
+
// // Did not match the input exactly - possible parsing error.
|
|
210
|
+
// result.parseWarning = true;
|
|
211
|
+
// }
|
|
212
|
+
// } else {
|
|
213
|
+
// result = "Failed to find gradient";
|
|
214
|
+
// }
|
|
215
|
+
// return result;
|
|
216
|
+
// };
|
|
217
|
+
//# sourceMappingURL=LinearColorGradientParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinearColorGradientParser.js","sourceRoot":"","sources":["../../../ts/utils/parsers/LinearColorGradientParser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,aAAa,EAA4C,MAAM,iCAAiC,CAAC;AA2C1G;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAA6B,CAAC,cAA8B,EAAU,EAAE;IAC3G,IAAI,OAAO,cAAc,KAAK,WAAW,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IACD,MAAM,GAAG,GAAW,cAAc,CAAC,IAAI,EAAE,CAAC;IAC1C,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,wDAAwD,GAAG,GAAG,CAAC,CAAC;IAClF,CAAC;IACD,OAAO,MAAM,CAAC,UAAU,CAAC,GAAG,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,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAClD,CAAC;QAED,OAAO,IAAI,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,IAA6B,CAAC,CAAC;IAC7E,CAAC;CACF,CAAC,YAAY;AAEd,oDAAoD;AACpD,gBAAgB;AAChB,+IAA+I;AAC/I,uDAAuD;AAEvD,0BAA0B;AAC1B,6CAA6C;AAC7C,mDAAmD;AACnD,wDAAwD;AACxD,qEAAqE;AACrE,oCAAoC;AACpC,QAAQ;AACR,aAAa;AACb,0CAA0C;AAC1C,MAAM;AAEN,mBAAmB;AACnB,KAAK"}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
export type NumericString = `${number}`;
|
|
16
16
|
export type BooleanString = "0" | "1" | `${boolean}`;
|
|
17
|
-
export type SVGPathMoveToCommand = ["M" | "m", NumericString, NumericString];
|
|
17
|
+
export type SVGPathMoveToCommand = ["M" | "m", NumericString | number, NumericString | number];
|
|
18
18
|
export type SVGPathLineToCommand = ["L" | "l", NumericString, NumericString, ...Array<NumericString>];
|
|
19
19
|
export type SVGPathVerticalLineToCommand = ["V" | "v", NumericString];
|
|
20
20
|
export type SVGPathHorizontalLineToCommand = ["H" | "h", NumericString];
|
|
@@ -31,13 +31,13 @@ export type SVGPathQuadraticCurveToCommand = ["Q" | "q", NumericString, NumericS
|
|
|
31
31
|
];
|
|
32
32
|
export type SVGPathCubicCurveToCommand = [
|
|
33
33
|
"C" | "c",
|
|
34
|
-
NumericString,
|
|
35
|
-
NumericString,
|
|
36
|
-
NumericString,
|
|
37
|
-
NumericString,
|
|
38
|
-
NumericString,
|
|
39
|
-
NumericString,
|
|
40
|
-
...Array<NumericString>
|
|
34
|
+
NumericString | number,
|
|
35
|
+
NumericString | number,
|
|
36
|
+
NumericString | number,
|
|
37
|
+
NumericString | number,
|
|
38
|
+
NumericString | number,
|
|
39
|
+
NumericString | number,
|
|
40
|
+
...Array<NumericString | number>
|
|
41
41
|
];
|
|
42
42
|
export type SVGPathShorthandCubicCurveToCommand = [
|
|
43
43
|
"S" | "s",
|
package/src/ts/Bounds.ts
CHANGED
|
@@ -13,7 +13,11 @@
|
|
|
13
13
|
* @modified 2025-04-18 Change parameter type in `Bounds.computeFromVertices` from `Vertex` to more general `XYCoords`.
|
|
14
14
|
* @modified 2025-04-19 Added methods to `Bounds` class: `getNorthPoint`, `getSouthPoint`, `getEastPoint` and `getWestPoint`.
|
|
15
15
|
* @modified 2025-04-26 Added static method `Bounds.computeFromBoundsSet` to calculate containing bounds for a set of bounding boxes.
|
|
16
|
-
* @
|
|
16
|
+
* @modified 2025-10-17 Added the methods `Bounds.getSouthWestPoint`, `getNorthWestPoint`, `getNorthEastPoint` and `getSouthEastPoint`.
|
|
17
|
+
* @modified 2025-10-18 Added method `Bounds.containsVert(XYCoords)`.
|
|
18
|
+
* @modified 2025-10-28 Added the `Bounds.getWidth()` and `Bounds.getHeight()`.
|
|
19
|
+
* @modified 2025-11-12 Added the `Bounds.getMoved()` method.
|
|
20
|
+
* @version 1.11.0
|
|
17
21
|
**/
|
|
18
22
|
|
|
19
23
|
import { Polygon } from "./Polygon";
|
|
@@ -75,54 +79,135 @@ export class Bounds implements IBounds, XYDimension {
|
|
|
75
79
|
this.height = max.y - min.y;
|
|
76
80
|
}
|
|
77
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Check if the given vertex is inside this bounds.
|
|
84
|
+
*
|
|
85
|
+
* @method containsVert
|
|
86
|
+
* @param {XYCoords} vert - The vertex to check.
|
|
87
|
+
* @return {boolean} True if the passed vertex is inside this bounds.
|
|
88
|
+
* @instance
|
|
89
|
+
* @memberof Bounds
|
|
90
|
+
**/
|
|
91
|
+
containsVert(vert: XYCoords): boolean {
|
|
92
|
+
return this.min.x <= vert.x && vert.x < this.max.x && this.min.y <= vert.y && vert.y < this.max.y;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
getWidth(): number {
|
|
96
|
+
return this.max.x - this.min.x;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
getHeight(): number {
|
|
100
|
+
return this.max.y - this.min.y;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
getScaled(scaleFactor: number): Bounds {
|
|
104
|
+
const center = this.getCenter();
|
|
105
|
+
const newMin = new Vertex(this.min).scale(scaleFactor, center);
|
|
106
|
+
const newMax = new Vertex(this.max).scale(scaleFactor, center);
|
|
107
|
+
return new Bounds(newMin, newMax);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
getMoved(moveAmount: XYCoords): Bounds {
|
|
111
|
+
const newMin = new Vertex(this.min).move(moveAmount);
|
|
112
|
+
const newMax = new Vertex(this.max).move(moveAmount);
|
|
113
|
+
return new Bounds(newMin, newMax);
|
|
114
|
+
}
|
|
115
|
+
|
|
78
116
|
/**
|
|
79
117
|
* Get the center point of the north bound.
|
|
80
|
-
*
|
|
118
|
+
*
|
|
81
119
|
* @method getNorthPoint
|
|
82
120
|
* @instance
|
|
83
121
|
* @memberof Bounds
|
|
84
122
|
* @return {Vertex} The "northmost" centered point of this bounding box.
|
|
85
123
|
*/
|
|
86
|
-
getNorthPoint()
|
|
87
|
-
return new Vertex(this.min.x + this.width/2.0,
|
|
88
|
-
}
|
|
124
|
+
getNorthPoint(): Vertex {
|
|
125
|
+
return new Vertex(this.min.x + this.width / 2.0, this.min.y);
|
|
126
|
+
}
|
|
89
127
|
|
|
90
128
|
/**
|
|
91
129
|
* Get the center point of the south bound.
|
|
92
|
-
*
|
|
130
|
+
*
|
|
93
131
|
* @method getNorthPoint
|
|
94
132
|
* @instance
|
|
95
133
|
* @memberof Bounds
|
|
96
134
|
* @return {Vertex} The "southhmost" centered point of this bounding box.
|
|
97
135
|
*/
|
|
98
|
-
getSouthPoint()
|
|
99
|
-
return new Vertex(
|
|
100
|
-
}
|
|
136
|
+
getSouthPoint(): Vertex {
|
|
137
|
+
return new Vertex(this.min.x + this.width / 2.0, this.max.y);
|
|
138
|
+
}
|
|
101
139
|
|
|
102
|
-
|
|
140
|
+
/**
|
|
103
141
|
* Get the center point of the west bound.
|
|
104
|
-
*
|
|
142
|
+
*
|
|
105
143
|
* @method getWestPoint
|
|
106
144
|
* @instance
|
|
107
145
|
* @memberof Bounds
|
|
108
146
|
* @return {Vertex} The "westhmost" centered point of this bounding box.
|
|
109
147
|
*/
|
|
110
|
-
|
|
111
|
-
return new Vertex(
|
|
112
|
-
}
|
|
148
|
+
getWestPoint(): Vertex {
|
|
149
|
+
return new Vertex(this.min.x, this.min.y + this.height / 2.0);
|
|
150
|
+
}
|
|
113
151
|
|
|
114
|
-
|
|
152
|
+
/**
|
|
115
153
|
* Get the center point of the east bound.
|
|
116
|
-
*
|
|
154
|
+
*
|
|
117
155
|
* @method getEastPoint
|
|
118
156
|
* @instance
|
|
119
157
|
* @memberof Bounds
|
|
120
158
|
* @return {Vertex} The "easthmost" centered point of this bounding box.
|
|
121
159
|
*/
|
|
122
|
-
|
|
123
|
-
return new Vertex(
|
|
124
|
-
}
|
|
160
|
+
getEastPoint(): Vertex {
|
|
161
|
+
return new Vertex(this.max.x, this.min.y + this.height / 2.0);
|
|
162
|
+
}
|
|
125
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Get the upper left corner point these bounds box.
|
|
166
|
+
*
|
|
167
|
+
* @method getNorthWestPoint
|
|
168
|
+
* @instance
|
|
169
|
+
* @memberof Bounds
|
|
170
|
+
* @return {Vertex} The "northwestmost" point of this bounding box.
|
|
171
|
+
*/
|
|
172
|
+
getNorthWestPoint(): Vertex {
|
|
173
|
+
return new Vertex(this.min.x, this.min.y);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Get the upper right corner point these bounds box.
|
|
178
|
+
*
|
|
179
|
+
* @method getNorthEastPoint
|
|
180
|
+
* @instance
|
|
181
|
+
* @memberof Bounds
|
|
182
|
+
* @return {Vertex} The "northeastmost" point of this bounding box.
|
|
183
|
+
*/
|
|
184
|
+
getNorthEastPoint(): Vertex {
|
|
185
|
+
return new Vertex(this.max.x, this.min.y);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Get the lower right corner point these bounds box.
|
|
190
|
+
*
|
|
191
|
+
* @method getSouthEastPoint
|
|
192
|
+
* @instance
|
|
193
|
+
* @memberof Bounds
|
|
194
|
+
* @return {Vertex} The "southeastmost" point of this bounding box.
|
|
195
|
+
*/
|
|
196
|
+
getSouthEastPoint(): Vertex {
|
|
197
|
+
return new Vertex(this.max.x, this.max.y);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Get the lower left corner point these bounds box.
|
|
202
|
+
*
|
|
203
|
+
* @method getSouthWestPoint
|
|
204
|
+
* @instance
|
|
205
|
+
* @memberof Bounds
|
|
206
|
+
* @return {Vertex} The "southwestmost" point of this bounding box.
|
|
207
|
+
*/
|
|
208
|
+
getSouthWestPoint(): Vertex {
|
|
209
|
+
return new Vertex(this.min.x, this.max.y);
|
|
210
|
+
}
|
|
126
211
|
|
|
127
212
|
/**
|
|
128
213
|
* Convert this rectangular bounding box to a polygon with four vertices.
|
|
@@ -230,7 +315,7 @@ export class Bounds implements IBounds, XYDimension {
|
|
|
230
315
|
* @return The minimal Bounds for the given vertices.
|
|
231
316
|
**/
|
|
232
317
|
static computeFromVertices(vertices: Array<XYCoords>): Bounds {
|
|
233
|
-
if (vertices.length == 0) {
|
|
318
|
+
if (vertices.length == 0) {
|
|
234
319
|
return new Bounds(new Vertex(0, 0), new Vertex(0, 0));
|
|
235
320
|
}
|
|
236
321
|
|
|
@@ -250,7 +335,7 @@ export class Bounds implements IBounds, XYDimension {
|
|
|
250
335
|
return new Bounds(new Vertex(xMin, yMin), new Vertex(xMax, yMax));
|
|
251
336
|
}
|
|
252
337
|
|
|
253
|
-
|
|
338
|
+
/**
|
|
254
339
|
* Compute the minimal bounding box for a given set of existing bounding boxes.
|
|
255
340
|
*
|
|
256
341
|
* An empty vertex array will return an empty bounding box located at (0,0).
|
|
@@ -261,7 +346,7 @@ export class Bounds implements IBounds, XYDimension {
|
|
|
261
346
|
* @param {Array<IBounds>} boundingBoxes - The set of existing bounding boxes to get the containing bounding box for.
|
|
262
347
|
* @return The minimal Bounds for the given bounds instances.
|
|
263
348
|
**/
|
|
264
|
-
static computeFromBoundsSet(boundingBoxes:Array<IBounds>)
|
|
349
|
+
static computeFromBoundsSet(boundingBoxes: Array<IBounds>): Bounds {
|
|
265
350
|
if (boundingBoxes.length == 0) {
|
|
266
351
|
return new Bounds(new Vertex(0, 0), new Vertex(0, 0));
|
|
267
352
|
}
|
package/src/ts/CircleSector.ts
CHANGED
|
@@ -109,16 +109,16 @@ export class CircleSector implements IBounded, Intersectable, SVGSerializable {
|
|
|
109
109
|
**/
|
|
110
110
|
getBounds(): Bounds {
|
|
111
111
|
const _self = this;
|
|
112
|
-
const circleBounds
|
|
112
|
+
const circleBounds: Bounds = this.circle.getBounds();
|
|
113
113
|
// Calculage angles from east, west, north and south box points and check if they are inside
|
|
114
|
-
const candidates
|
|
114
|
+
const candidates: Array<Vertex> = [
|
|
115
115
|
circleBounds.getNorthPoint(),
|
|
116
116
|
circleBounds.getSouthPoint(),
|
|
117
117
|
circleBounds.getWestPoint(),
|
|
118
118
|
circleBounds.getEastPoint()
|
|
119
|
-
].filter(
|
|
119
|
+
].filter((point: Vertex) => {
|
|
120
120
|
// Check for each candidate points if they are contained in this sector. Drop if not.
|
|
121
|
-
const angle
|
|
121
|
+
const angle: number = new Line(_self.circle.center, point).angle();
|
|
122
122
|
return _self.containsAngle(angle);
|
|
123
123
|
});
|
|
124
124
|
// Compute bounds and inlcude start end end point (they are definitely part of the bounds)
|
|
@@ -126,7 +126,6 @@ export class CircleSector implements IBounded, Intersectable, SVGSerializable {
|
|
|
126
126
|
}
|
|
127
127
|
//--- BEGIN --- Implement interface `IBounded`
|
|
128
128
|
|
|
129
|
-
|
|
130
129
|
/**
|
|
131
130
|
* Move the circle sector by the given amount.
|
|
132
131
|
*
|
|
@@ -316,6 +315,38 @@ export class CircleSector implements IBounded, Intersectable, SVGSerializable {
|
|
|
316
315
|
}
|
|
317
316
|
//--- END --- Implement interface `Intersectable`
|
|
318
317
|
|
|
318
|
+
describeSVGPath(options?: { moveToStart: boolean }): SVGPathParams {
|
|
319
|
+
// const buffer: SVGPathParams = [];
|
|
320
|
+
// const start = this.getStartPoint();
|
|
321
|
+
// const end = this.getEndPoint();
|
|
322
|
+
// // describeSVGArc
|
|
323
|
+
// // x: number,
|
|
324
|
+
// // y: number,
|
|
325
|
+
// // radius: number,
|
|
326
|
+
// // startAngle: number,
|
|
327
|
+
// // endAngle: number,
|
|
328
|
+
// // options?: { moveToStart: boolean }
|
|
329
|
+
// // ): SVGPathParams => {
|
|
330
|
+
// var arcRotation = 0.0;
|
|
331
|
+
// var largeArcFlag = 1;
|
|
332
|
+
// var sweepFlag = 0;
|
|
333
|
+
// if (options && options.moveToStart) {
|
|
334
|
+
// buffer.push("M", start.x, start.y);
|
|
335
|
+
// }
|
|
336
|
+
// buffer.push("A", cSector.circle.radius, cSector.circle.radius, arcRotation, largeArcFlag, sweepFlag, end.x, end.y);
|
|
337
|
+
// return buffer;
|
|
338
|
+
|
|
339
|
+
const arc = CircleSector.circleSectorUtils.describeSVGArc(
|
|
340
|
+
this.circle.center.x, // end.x,
|
|
341
|
+
this.circle.center.y, // end.y,
|
|
342
|
+
this.circle.radius,
|
|
343
|
+
this.startAngle,
|
|
344
|
+
this.endAngle,
|
|
345
|
+
options // options?: { moveToStart: boolean }
|
|
346
|
+
);
|
|
347
|
+
return arc;
|
|
348
|
+
}
|
|
349
|
+
|
|
319
350
|
/**
|
|
320
351
|
* This function should invalidate any installed listeners and invalidate this object.
|
|
321
352
|
* After calling this function the object might not hold valid data any more and
|
|
@@ -363,7 +394,9 @@ export class CircleSector implements IBounded, Intersectable, SVGSerializable {
|
|
|
363
394
|
endAngle: number,
|
|
364
395
|
options?: { moveToStart: boolean }
|
|
365
396
|
): SVGPathParams => {
|
|
366
|
-
if (typeof options === "undefined")
|
|
397
|
+
if (typeof options === "undefined") {
|
|
398
|
+
options = { moveToStart: true };
|
|
399
|
+
}
|
|
367
400
|
|
|
368
401
|
const end: XYCoords = CircleSector.circleSectorUtils.polarToCartesian(x, y, radius, endAngle);
|
|
369
402
|
const start: XYCoords = CircleSector.circleSectorUtils.polarToCartesian(x, y, radius, startAngle);
|