plotboilerplate 1.19.0 → 1.20.1

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.
Files changed (94) hide show
  1. package/README.md +2 -1
  2. package/dist/index.esm.js +81 -27
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.esm.min.js +1 -1
  5. package/dist/index.esm.min.js.map +1 -1
  6. package/dist/plotboilerplate.browser.min.js +1 -1
  7. package/dist/plotboilerplate.browser.min.js.map +1 -1
  8. package/dist/plotboilerplate.js +81 -39
  9. package/dist/plotboilerplate.min.js +1 -1
  10. package/package.json +1 -1
  11. package/src/cjs/Bounds.d.ts +4 -5
  12. package/src/cjs/Bounds.js +6 -8
  13. package/src/cjs/Bounds.js.map +1 -1
  14. package/src/cjs/PlotBoilerplate.d.ts +2 -1
  15. package/src/cjs/PlotBoilerplate.js +9 -3
  16. package/src/cjs/PlotBoilerplate.js.map +1 -1
  17. package/src/cjs/VEllipseSector.d.ts +4 -3
  18. package/src/cjs/VEllipseSector.js +15 -8
  19. package/src/cjs/VEllipseSector.js.map +1 -1
  20. package/src/cjs/Vertex.d.ts +33 -1
  21. package/src/cjs/Vertex.js +43 -1
  22. package/src/cjs/Vertex.js.map +1 -1
  23. package/src/cjs/drawutilssvg.d.ts +2 -1
  24. package/src/cjs/drawutilssvg.js +7 -19
  25. package/src/cjs/drawutilssvg.js.map +1 -1
  26. package/src/cjs/entry.js +1 -0
  27. package/src/cjs/interfaces/core.d.ts +3 -0
  28. package/src/cjs/interfaces/core.js +1 -0
  29. package/src/cjs/interfaces/core.js.map +1 -1
  30. package/src/cjs/utils/algorithms/detectPaths.d.ts +3 -2
  31. package/src/cjs/utils/creategui.js +7 -0
  32. package/src/cjs/utils/datastructures/Color.d.ts +1 -1
  33. package/src/cjs/utils/datastructures/Color.js +4 -2
  34. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  35. package/src/cjs/utils/io/FileDrop.d.ts +11 -1
  36. package/src/cjs/utils/io/FileDrop.js +41 -10
  37. package/src/cjs/utils/io/FileDrop.js.map +1 -1
  38. package/src/cjs/utils/parsers/svg/parseSVGPathData.d.ts +27 -0
  39. package/src/cjs/utils/parsers/svg/parseSVGPathData.js +486 -0
  40. package/src/cjs/utils/parsers/svg/parseSVGPathData.js.map +1 -0
  41. package/src/cjs/utils/parsers/svg/splitSVGPathData.d.ts +20 -0
  42. package/src/cjs/utils/parsers/svg/splitSVGPathData.js +53 -0
  43. package/src/cjs/utils/parsers/svg/splitSVGPathData.js.map +1 -0
  44. package/src/cjs/utils/parsers/svg/types.d.ts +63 -0
  45. package/src/cjs/utils/parsers/svg/types.js +17 -0
  46. package/src/cjs/utils/parsers/svg/types.js.map +1 -0
  47. package/src/esm/Bounds.d.ts +4 -5
  48. package/src/esm/Bounds.js +6 -8
  49. package/src/esm/Bounds.js.map +1 -1
  50. package/src/esm/PlotBoilerplate.d.ts +2 -1
  51. package/src/esm/PlotBoilerplate.js +10 -4
  52. package/src/esm/PlotBoilerplate.js.map +1 -1
  53. package/src/esm/VEllipseSector.d.ts +4 -3
  54. package/src/esm/VEllipseSector.js +15 -8
  55. package/src/esm/VEllipseSector.js.map +1 -1
  56. package/src/esm/Vertex.d.ts +33 -1
  57. package/src/esm/Vertex.js +43 -1
  58. package/src/esm/Vertex.js.map +1 -1
  59. package/src/esm/drawutilssvg.d.ts +2 -1
  60. package/src/esm/drawutilssvg.js +7 -19
  61. package/src/esm/drawutilssvg.js.map +1 -1
  62. package/src/esm/entry.js +1 -0
  63. package/src/esm/interfaces/core.d.ts +3 -0
  64. package/src/esm/interfaces/core.js +1 -0
  65. package/src/esm/interfaces/core.js.map +1 -1
  66. package/src/esm/utils/algorithms/detectPaths.d.ts +3 -2
  67. package/src/esm/utils/algorithms/detectPaths.js.map +1 -1
  68. package/src/esm/utils/datastructures/Color.d.ts +1 -1
  69. package/src/esm/utils/datastructures/Color.js +4 -2
  70. package/src/esm/utils/datastructures/Color.js.map +1 -1
  71. package/src/esm/utils/io/FileDrop.d.ts +11 -1
  72. package/src/esm/utils/io/FileDrop.js +41 -10
  73. package/src/esm/utils/io/FileDrop.js.map +1 -1
  74. package/src/esm/utils/parsers/svg/parseSVGPathData.d.ts +27 -0
  75. package/src/esm/utils/parsers/svg/parseSVGPathData.js +482 -0
  76. package/src/esm/utils/parsers/svg/parseSVGPathData.js.map +1 -0
  77. package/src/esm/utils/parsers/svg/splitSVGPathData.d.ts +20 -0
  78. package/src/esm/utils/parsers/svg/splitSVGPathData.js +49 -0
  79. package/src/esm/utils/parsers/svg/splitSVGPathData.js.map +1 -0
  80. package/src/esm/utils/parsers/svg/types.d.ts +63 -0
  81. package/src/esm/utils/parsers/svg/types.js +16 -0
  82. package/src/esm/utils/parsers/svg/types.js.map +1 -0
  83. package/src/ts/Bounds.ts +6 -8
  84. package/src/ts/PlotBoilerplate.ts +11 -4
  85. package/src/ts/VEllipseSector.ts +22 -15
  86. package/src/ts/Vertex.ts +46 -1
  87. package/src/ts/drawutilssvg.ts +8 -19
  88. package/src/ts/interfaces/core.ts +3 -0
  89. package/src/ts/utils/algorithms/detectPaths.ts +1 -1
  90. package/src/ts/utils/datastructures/Color.ts +8 -4
  91. package/src/ts/utils/io/FileDrop.ts +51 -10
  92. package/src/ts/utils/parsers/svg/parseSVGPathData.ts +631 -0
  93. package/src/ts/utils/parsers/svg/splitSVGPathData.ts +54 -0
  94. package/src/ts/utils/parsers/svg/types.ts +90 -0
@@ -14,7 +14,8 @@
14
14
  * @author Ikaros Kappler
15
15
  * @date 2021-10-13
16
16
  * @modified 2022-01-31 (ported from the ngdg project, then generalized)
17
- * @version 2.0.0
17
+ * @modified 2023-01-03 Fixing some minor type issues and adding SVG reading capabilities.
18
+ * @version 2.1.0
18
19
  */
19
20
  Object.defineProperty(exports, "__esModule", { value: true });
20
21
  exports.FileDrop = void 0;
@@ -35,7 +36,7 @@ var FileDrop = /** @class */ (function () {
35
36
  event.preventDefault();
36
37
  event.stopPropagation();
37
38
  _this.element.style.opacity = "1.0";
38
- if (!event.dataTransfer.files || event.dataTransfer.files.length === 0) {
39
+ if (!event.dataTransfer || !event.dataTransfer.files || event.dataTransfer.files.length === 0) {
39
40
  // No files were dropped
40
41
  return;
41
42
  }
@@ -43,39 +44,66 @@ var FileDrop = /** @class */ (function () {
43
44
  // Multiple file drop is not nupported
44
45
  return;
45
46
  }
46
- if (!_this.fileDroppedCallbackJSON) {
47
- // No handling callback defined.
48
- return;
49
- }
47
+ // if (!this.fileDroppedCallbackJSON) {
48
+ // // No handling callback defined.
49
+ // return;
50
+ // }
50
51
  if (event.dataTransfer.files[0]) {
51
52
  var file_1 = event.dataTransfer.files[0];
52
53
  // console.log("file", file);
53
- if (file_1.type.match(/json.*/) && _this.fileDroppedCallbackJSON) {
54
+ if (file_1.type.match(/json.*/) && _this.fileDroppedCallbackJSON !== null) {
54
55
  var reader = new FileReader();
55
56
  reader.onload = function (readEvent) {
57
+ if (!readEvent.target) {
58
+ console.warn("Cannot process JSON ProgressEvent data: target is null.");
59
+ return;
60
+ }
56
61
  // Finished reading file data.
57
62
  var jsonObject = JSON.parse(readEvent.target.result);
58
63
  // TODO: what happens on fail?
59
- _this.fileDroppedCallbackJSON(jsonObject);
64
+ _this.fileDroppedCallbackJSON && _this.fileDroppedCallbackJSON(jsonObject);
60
65
  };
61
66
  reader.readAsText(file_1); // start reading the file data.
62
67
  }
63
68
  else if (file_1.type.match(/text\/plain.*/) && _this.fileDroppedCallbackText) {
64
69
  var reader = new FileReader();
65
70
  reader.onload = function (readEvent) {
71
+ if (!readEvent.target) {
72
+ console.warn("Cannot process Text ProgressEvent data: target is null.");
73
+ return;
74
+ }
66
75
  // Finished reading file data.
67
- _this.fileDroppedCallbackText(readEvent.target.result);
76
+ _this.fileDroppedCallbackText && _this.fileDroppedCallbackText(readEvent.target.result);
68
77
  };
69
78
  reader.readAsText(file_1); // start reading the file data.
70
79
  }
71
80
  else if (_this.fileDroppedCallbackBinary) {
72
81
  var reader = new FileReader();
73
82
  reader.onload = function (readEvent) {
83
+ if (!readEvent.target) {
84
+ console.warn("Cannot process Binary ProgressEvent data: target is null.");
85
+ return;
86
+ }
74
87
  // Finished reading file data.
75
- _this.fileDroppedCallbackBinary(new Blob([readEvent.target.result]), file_1);
88
+ _this.fileDroppedCallbackBinary &&
89
+ _this.fileDroppedCallbackBinary(new Blob([readEvent.target.result]), file_1);
76
90
  };
77
91
  reader.readAsBinaryString(file_1); // start reading the file data.
78
92
  }
93
+ else if (_this.fileDroppedCallbackSVG) {
94
+ var reader = new FileReader();
95
+ reader.onload = function (readEvent) {
96
+ if (!readEvent.target) {
97
+ console.warn("Cannot process SVG ProgressEvent data: target is null.");
98
+ return;
99
+ }
100
+ var parser = new DOMParser();
101
+ var doc = parser.parseFromString(readEvent.target.result, "image/svg+xml");
102
+ // Finished reading file data.
103
+ _this.fileDroppedCallbackSVG && _this.fileDroppedCallbackSVG(doc);
104
+ };
105
+ reader.readAsText(file_1); // start reading the file data.
106
+ }
79
107
  }
80
108
  };
81
109
  /**
@@ -128,6 +156,9 @@ var FileDrop = /** @class */ (function () {
128
156
  FileDrop.prototype.onFileTextDropped = function (callback) {
129
157
  this.fileDroppedCallbackText = callback;
130
158
  };
159
+ FileDrop.prototype.onFileSVGDropped = function (callback) {
160
+ this.fileDroppedCallbackSVG = callback;
161
+ };
131
162
  /**
132
163
  * Removes all listeners (drop, dragover and dragleave).
133
164
  */
@@ -1 +1 @@
1
- {"version":3,"file":"FileDrop.js","sourceRoot":"","sources":["../../../ts/utils/io/FileDrop.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAMH;IAiCE;;;OAGG;IACH,kBAAY,OAAoB;QAAhC,iBAOC;QA4BD;;;;;WAKG;QACK,oBAAe,GAAG,UAAC,KAAgB;YACzC,KAAK,CAAC,cAAc,EAAE,CAAC;YACvB,KAAK,CAAC,eAAe,EAAE,CAAC;YACxB,KAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG,K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QACE,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,MAAM,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAC/D,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,UAAU,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACvE,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,WAAW,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAC3E,CAAC;IACH,eAAC;AAAD,CAAC,AAlMD,IAkMC;AAlMY,4BAAQ"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Parse SVG path data strings and convert to PlotBoilerplate path objects.
3
+ *
4
+ * As this parser function does not detect all possible path data strings it should cover the most daily use-cases.
5
+ *
6
+ * For more insight see
7
+ * https://www.w3.org/TR/SVG/paths.html
8
+ *
9
+ * @author Ikaros Kappler
10
+ * @date 2022-11-06
11
+ * @modified 2022-12-21 (winter solstice) Porting this to Typescript.
12
+ * @modified 2023-01-17 Handling multiple parameter sets now.
13
+ * @version 0.0.2-alpha
14
+ **/
15
+ import { CubicBezierCurve } from "../../../CubicBezierCurve";
16
+ import { Line } from "../../../Line";
17
+ /**
18
+ * Transform the given path data (translate and scale. rotating is not intended here).
19
+ *
20
+ * @date 2022-11-06
21
+ *
22
+ * @name parseSVGPathData
23
+ * @static
24
+ * @param {string} data - The data to parse.
25
+ * @return An array of straight line segments (Line) or curve segments (CubicBezierCurve) representing the path.
26
+ */
27
+ export declare const parseSVGPathData: (dataString: string) => Array<Line | CubicBezierCurve> | null;
@@ -0,0 +1,486 @@
1
+ "use strict";
2
+ /**
3
+ * Parse SVG path data strings and convert to PlotBoilerplate path objects.
4
+ *
5
+ * As this parser function does not detect all possible path data strings it should cover the most daily use-cases.
6
+ *
7
+ * For more insight see
8
+ * https://www.w3.org/TR/SVG/paths.html
9
+ *
10
+ * @author Ikaros Kappler
11
+ * @date 2022-11-06
12
+ * @modified 2022-12-21 (winter solstice) Porting this to Typescript.
13
+ * @modified 2023-01-17 Handling multiple parameter sets now.
14
+ * @version 0.0.2-alpha
15
+ **/
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.parseSVGPathData = void 0;
18
+ var CubicBezierCurve_1 = require("../../../CubicBezierCurve");
19
+ var Line_1 = require("../../../Line");
20
+ var VEllipseSector_1 = require("../../../VEllipseSector");
21
+ var Vertex_1 = require("../../../Vertex");
22
+ var splitSVGPathData_1 = require("./splitSVGPathData");
23
+ var DEG_TO_RAD = Math.PI / 180;
24
+ /**
25
+ * Transform the given path data (translate and scale. rotating is not intended here).
26
+ *
27
+ * @date 2022-11-06
28
+ *
29
+ * @name parseSVGPathData
30
+ * @static
31
+ * @param {string} data - The data to parse.
32
+ * @return An array of straight line segments (Line) or curve segments (CubicBezierCurve) representing the path.
33
+ */
34
+ var parseSVGPathData = function (dataString) {
35
+ var dataElements = splitSVGPathData_1.splitSVGPathData(dataString);
36
+ if (!dataElements) {
37
+ return null;
38
+ }
39
+ // Array<PathSegments>
40
+ var result = [];
41
+ var i = 0;
42
+ var firstPoint = { x: NaN, y: NaN };
43
+ var lastPoint = { x: NaN, y: NaN };
44
+ var lastControlPoint = { x: NaN, y: NaN };
45
+ var lastQuadraticControlPoint = { x: NaN, y: NaN };
46
+ while (i < dataElements.length) {
47
+ // Could this also be SVGPathShorthandQuadraticCurveToCommand?
48
+ var data = dataElements[i];
49
+ var cmd = data[0];
50
+ // console.log("cmd", cmd, "data", data);
51
+ switch (data[0]) {
52
+ case "M":
53
+ // MoveTo: M|m x y
54
+ _handleMove(data, false, firstPoint, lastPoint, lastControlPoint, result);
55
+ break;
56
+ case "m":
57
+ // MoveTo: M|m x y
58
+ _handleMove(data, true, firstPoint, lastPoint, lastControlPoint, result);
59
+ break;
60
+ case "L":
61
+ // LineTo L|l x y
62
+ _handleLineTo(data, false, firstPoint, lastPoint, lastControlPoint, result);
63
+ break;
64
+ case "l":
65
+ // LineTo L|l x y
66
+ _handleLineTo(data, true, firstPoint, lastPoint, lastControlPoint, result);
67
+ break;
68
+ case "H":
69
+ // HorizontalLineTo: H|h x
70
+ _handleHorizontalLineTo(data, false, firstPoint, lastPoint, lastControlPoint, result);
71
+ break;
72
+ case "h":
73
+ // HorizontalLineTo: H|h x
74
+ _handleHorizontalLineTo(data, true, firstPoint, lastPoint, lastControlPoint, result);
75
+ break;
76
+ case "V":
77
+ // VerticalLineTo: V|v y
78
+ _handleVerticalLineTo(data, false, firstPoint, lastPoint, lastControlPoint, result);
79
+ break;
80
+ case "v":
81
+ // VerticalLineTo: V|v y
82
+ _handleVerticalLineTo(data, true, firstPoint, lastPoint, lastControlPoint, result);
83
+ break;
84
+ case "C":
85
+ // CurveTo: C|c x1 y1 x2 y2 x y
86
+ _handleCubicBezierTo(data, false, firstPoint, lastPoint, lastControlPoint, result);
87
+ break;
88
+ case "c":
89
+ // CurveTo: C|c x1 y1 x2 y2 x y
90
+ _handleCubicBezierTo(data, true, firstPoint, lastPoint, lastControlPoint, result);
91
+ break;
92
+ case "S":
93
+ _handleShorthandCubicCurveTo(data, false, firstPoint, lastPoint, lastControlPoint, result);
94
+ break;
95
+ case "s":
96
+ _handleShorthandCubicCurveTo(data, true, firstPoint, lastPoint, lastControlPoint, result);
97
+ break;
98
+ case "Q":
99
+ // QuadraticCurveTo: Q|q x1 y1 x y
100
+ _handleQuadraticCurveTo(data, false, firstPoint, lastPoint, lastControlPoint, result);
101
+ break;
102
+ case "q":
103
+ // QuadraticCurveTo: Q|q x1 y1 x y
104
+ _handleQuadraticCurveTo(data, true, firstPoint, lastPoint, lastControlPoint, result);
105
+ break;
106
+ case "A":
107
+ // EllipticalArcTo: A|a rx ry x-axis-rotation large-arc-flag sweep-flag x y
108
+ _handleArcTo(data, false, firstPoint, lastPoint, lastControlPoint, result);
109
+ break;
110
+ case "a":
111
+ // EllipticalArcTo: A|a rx ry x-axis-rotation large-arc-flag sweep-flag x y
112
+ _handleArcTo(data, true, firstPoint, lastPoint, lastControlPoint, result);
113
+ break;
114
+ case "z":
115
+ _handleClosePath(data, false, firstPoint, lastPoint, lastControlPoint, result);
116
+ break;
117
+ case "Z":
118
+ // ClosePath: Z|z (no arguments)
119
+ _handleClosePath(data, true, firstPoint, lastPoint, lastControlPoint, result);
120
+ // i++;
121
+ break;
122
+ default:
123
+ if (cmd === "T") {
124
+ throw "T command only allowed after q command.";
125
+ }
126
+ if (cmd === "t") {
127
+ throw "t command only allowed after q command.";
128
+ }
129
+ throw "Unknown SVG path command found: " + cmd + ".";
130
+ }
131
+ // Safepoint: continue reading token by token until something is recognized again
132
+ i++;
133
+ } // END while
134
+ return result;
135
+ }; // END parseSVGPathData
136
+ exports.parseSVGPathData = parseSVGPathData;
137
+ // Just update the current position
138
+ var _handleMove = function (data, isRelative, firstPoint, lastPoint, lastControlPoint, _result) {
139
+ if (data.length < 3) {
140
+ throw "Unsufficient params for MOVE";
141
+ }
142
+ // result.push( new)
143
+ if (isRelative && !isNaN(lastPoint.x) && !isNaN(lastPoint.y)) {
144
+ lastPoint.x += Number(data[1]);
145
+ lastPoint.y += Number(data[2]);
146
+ lastControlPoint.x = lastPoint.x;
147
+ lastControlPoint.y = lastPoint.y;
148
+ }
149
+ else {
150
+ lastPoint.x = Number(data[1]);
151
+ lastPoint.y = Number(data[2]);
152
+ lastControlPoint.x = lastPoint.x;
153
+ lastControlPoint.y = lastPoint.y;
154
+ }
155
+ // console.log("AFTER MOVE", lastPoint);
156
+ if (isNaN(firstPoint.y)) {
157
+ firstPoint.x = lastPoint.x;
158
+ firstPoint.y = lastPoint.y;
159
+ }
160
+ };
161
+ // Draw a line segment from the current position
162
+ var _handleLineTo = function (data, isRelative, firstPoint, lastPoint, lastControlPoint, result) {
163
+ if (data.length < 3) {
164
+ throw "Unsufficient params for LINETO";
165
+ }
166
+ for (var i = 1; i + 1 < data.length; i += 2) {
167
+ var line = new Line_1.Line(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
168
+ if (isRelative) {
169
+ line.b.x += Number(data[i]);
170
+ line.b.y += Number(data[i + 1]);
171
+ }
172
+ else {
173
+ line.b.x = Number(data[i]);
174
+ line.b.y = Number(data[i + 1]);
175
+ }
176
+ result.push(line);
177
+ lastPoint.x = line.b.x;
178
+ lastPoint.y = line.b.y;
179
+ lastControlPoint.x = line.b.x;
180
+ lastControlPoint.y = line.b.y;
181
+ if (isNaN(firstPoint.y)) {
182
+ firstPoint.x = line.a.x;
183
+ firstPoint.y = line.a.y;
184
+ }
185
+ console.log("LINETO LINE", i, line.toString());
186
+ }
187
+ };
188
+ var _handleHorizontalLineTo = function (data, isRelative, firstPoint, lastPoint, lastControlPoint, result) {
189
+ // console.log("Handle HORIZONTALLINETO", data);
190
+ if (data.length < 2) {
191
+ throw "Unsufficient params for HORIZONTALLINETO";
192
+ }
193
+ for (var i = 1; i < data.length; i++) {
194
+ var line = new Line_1.Line(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
195
+ if (isRelative) {
196
+ line.b.x += Number(data[i]);
197
+ // line.b.y += Number(data[2]);
198
+ }
199
+ else {
200
+ line.b.x = Number(data[i]);
201
+ // line.b.y = Number(data[2]);
202
+ }
203
+ result.push(line);
204
+ lastPoint.x = line.b.x;
205
+ // lastPoint.y = line.b.y;
206
+ lastControlPoint.x = line.b.x;
207
+ if (isNaN(firstPoint.y)) {
208
+ firstPoint.x = line.a.x;
209
+ firstPoint.y = line.a.y;
210
+ }
211
+ }
212
+ };
213
+ var _handleVerticalLineTo = function (data, isRelative, firstPoint, lastPoint, lastControlPoint, result) {
214
+ if (data.length < 2) {
215
+ throw "Unsufficient params for VERTICALLINETO";
216
+ }
217
+ for (var i = 1; i < data.length; i++) {
218
+ var line = new Line_1.Line(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
219
+ if (isRelative) {
220
+ line.b.y += Number(data[i]);
221
+ }
222
+ else {
223
+ line.b.y = Number(data[i]);
224
+ }
225
+ result.push(line);
226
+ // lastPoint.x = line.b.x;
227
+ lastPoint.y = line.b.y;
228
+ lastControlPoint.y = line.b.y;
229
+ if (isNaN(firstPoint.y)) {
230
+ firstPoint.x = line.a.x;
231
+ firstPoint.y = line.a.y;
232
+ }
233
+ }
234
+ };
235
+ // CurveTo: C|c x1 y1 x2 y2 x y
236
+ var _handleCubicBezierTo = function (data, isRelative, firstPoint, lastPoint, lastControlPoint, result) {
237
+ // console.log("Handle CUBICBEZIERTO", data);
238
+ if (data.length < 7) {
239
+ throw "Unsufficient params for CUBICBEZIERTO";
240
+ }
241
+ for (var i = 1; i + 5 < data.length; i += 6) {
242
+ var curve = new CubicBezierCurve_1.CubicBezierCurve(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
243
+ if (isRelative) {
244
+ curve.startControlPoint.x += Number(data[i]);
245
+ curve.startControlPoint.y += Number(data[i + 1]);
246
+ curve.endControlPoint.x += Number(data[i + 2]);
247
+ curve.endControlPoint.y += Number(data[i + 3]);
248
+ curve.endPoint.x += Number(data[i + 4]);
249
+ curve.endPoint.y += Number(data[i + 5]);
250
+ }
251
+ else {
252
+ curve.startControlPoint.x = Number(data[i]);
253
+ curve.startControlPoint.y = Number(data[i + 1]);
254
+ curve.endControlPoint.x = Number(data[i + 2]);
255
+ curve.endControlPoint.y = Number(data[i + 3]);
256
+ curve.endPoint.x = Number(data[i + 4]);
257
+ curve.endPoint.y = Number(data[i + 5]);
258
+ }
259
+ result.push(curve);
260
+ lastPoint.x = curve.endPoint.x;
261
+ lastPoint.y = curve.endPoint.y;
262
+ lastControlPoint.x = curve.endControlPoint.x;
263
+ lastControlPoint.y = curve.endControlPoint.y;
264
+ if (isNaN(firstPoint.x)) {
265
+ firstPoint.x = curve.startPoint.x;
266
+ firstPoint.y = curve.startPoint.y;
267
+ }
268
+ }
269
+ };
270
+ // QuadraticCurveTo: Q|q x1 y1 x y
271
+ var _handleQuadraticCurveTo = function (data, isRelative, firstPoint, lastPoint, lastControlPoint, result) {
272
+ // console.log("Handle QUADRATICBEZIERTO", data);
273
+ if (data.length < 5) {
274
+ throw "Unsufficient params for QUADRATICBEZIERTO";
275
+ }
276
+ var i = 1;
277
+ var localLastQuadraticControlPoint = { x: 0, y: 0 };
278
+ // This loops runs at least once
279
+ while (i + 3 < data.length && data[i] !== "t" && data[i] !== "T") {
280
+ var curve = new CubicBezierCurve_1.CubicBezierCurve(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
281
+ if (isRelative) {
282
+ curve.startControlPoint.x += curve.startPoint.x + (Number(data[i]) - curve.startControlPoint.x); // * 0.666;
283
+ curve.startControlPoint.y += curve.startPoint.y + (Number(data[i + 1]) - curve.startControlPoint.y); // * 0.666;
284
+ curve.endPoint.x += Number(data[i + 2]);
285
+ curve.endPoint.y += Number(data[i + 3]);
286
+ curve.endControlPoint.x = curve.startControlPoint.x;
287
+ curve.endControlPoint.y = curve.startControlPoint.y;
288
+ }
289
+ else {
290
+ curve.startControlPoint.x = curve.startPoint.x + (Number(data[i]) - curve.startControlPoint.x); // * 0.666;
291
+ curve.startControlPoint.y = curve.startPoint.y + (Number(data[i + 1]) - curve.startControlPoint.y); // * 0.666;
292
+ curve.endPoint.x = Number(data[i + 2]);
293
+ curve.endPoint.y = Number(data[i + 3]);
294
+ curve.endControlPoint.x = curve.startControlPoint.x;
295
+ curve.endControlPoint.y = curve.startControlPoint.y;
296
+ }
297
+ // var lastQuadraticControlPoint = { x: Number(data[1]), y: Number(data[2]) };
298
+ localLastQuadraticControlPoint = { x: curve.endControlPoint.x, y: curve.endControlPoint.y };
299
+ // Convert quadratic curve to cubic curve
300
+ curve.startControlPoint.x = curve.startPoint.x + (curve.startControlPoint.x - curve.startPoint.x) * 0.666;
301
+ curve.startControlPoint.y = curve.startPoint.y + (curve.startControlPoint.y - curve.startPoint.y) * 0.666;
302
+ curve.endControlPoint.x = curve.endPoint.x + (curve.endControlPoint.x - curve.endPoint.x) * 0.666;
303
+ curve.endControlPoint.y = curve.endPoint.y + (curve.endControlPoint.y - curve.endPoint.y) * 0.666;
304
+ result.push(curve);
305
+ lastPoint.x = curve.endPoint.x;
306
+ lastPoint.y = curve.endPoint.y;
307
+ lastControlPoint.x = curve.endControlPoint.x;
308
+ lastControlPoint.y = curve.endControlPoint.y;
309
+ if (isNaN(firstPoint.x)) {
310
+ firstPoint.x = curve.startPoint.x;
311
+ firstPoint.y = curve.startPoint.y;
312
+ }
313
+ i += 4;
314
+ } // END while
315
+ // 'T' or 't' command may follow
316
+ // if (data.length >= 8) {
317
+ if (i < data.length && (data[i] == "t" || data[i] === "T")) {
318
+ // TODO: think about this type cast!
319
+ var subData = data.slice(5);
320
+ // var lastQuadraticControlPoint = { x: Number(data[1]), y: Number(data[2]) };
321
+ if (subData[0] === "T") {
322
+ // _handleShorthandQuadraticCurveTo(subData, false, firstPoint, lastPoint, lastControlPoint, lastQuadraticControlPoint, result);
323
+ _handleShorthandQuadraticCurveTo(subData, false, firstPoint, lastPoint, lastControlPoint, localLastQuadraticControlPoint, result);
324
+ }
325
+ else if (subData[0] === "t") {
326
+ // _handleShorthandQuadraticCurveTo(subData, true, firstPoint, lastPoint, lastControlPoint, lastQuadraticControlPoint, result);
327
+ _handleShorthandQuadraticCurveTo(subData, true, firstPoint, lastPoint, lastControlPoint, localLastQuadraticControlPoint, result);
328
+ }
329
+ }
330
+ };
331
+ // This is a helper function and works only in combination with Quadratic Bézier Curves
332
+ // T|t (x y)+
333
+ var _handleShorthandQuadraticCurveTo = function (data, isRelative, firstPoint, lastPoint, lastControlPoint, lastQuadraticControlPoint, result) {
334
+ if (data.length < 3) {
335
+ throw "Unsufficient params for SHORTHANDQUADRATICCURVETO";
336
+ }
337
+ var i = 1;
338
+ while (i + 1 < data.length) {
339
+ // Respect multiple 'T|t' commands here
340
+ if (data[i] === "T" || data[i] === "t") {
341
+ i++;
342
+ continue;
343
+ }
344
+ var curve = new CubicBezierCurve_1.CubicBezierCurve(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
345
+ if (isRelative) {
346
+ curve.endPoint.x += Number(data[i]);
347
+ curve.endPoint.y += Number(data[i + 1]);
348
+ curve.startControlPoint.x += curve.startPoint.x - (lastQuadraticControlPoint.x - lastPoint.x);
349
+ curve.startControlPoint.y += curve.startPoint.y - (lastQuadraticControlPoint.y - lastPoint.y);
350
+ }
351
+ else {
352
+ curve.endPoint.x = Number(data[i]);
353
+ curve.endPoint.y = Number(data[i + 1]);
354
+ curve.startControlPoint.x = curve.startPoint.x - (lastQuadraticControlPoint.x - lastPoint.x);
355
+ curve.startControlPoint.y = curve.startPoint.y - (lastQuadraticControlPoint.y - lastPoint.y);
356
+ }
357
+ // First handle as symmetrical cubic curve
358
+ curve.endControlPoint.x = curve.startControlPoint.x;
359
+ curve.endControlPoint.y = curve.startControlPoint.y;
360
+ lastQuadraticControlPoint.y = curve.endControlPoint.y;
361
+ lastQuadraticControlPoint.x = curve.endControlPoint.x;
362
+ // Convert quadratic curve to cubic curve
363
+ var scaleFactor = 0.666; // i === 1 ? 0.666 : 1.0;
364
+ curve.startControlPoint.x = curve.startPoint.x + (curve.startControlPoint.x - curve.startPoint.x) * scaleFactor;
365
+ curve.startControlPoint.y = curve.startPoint.y + (curve.startControlPoint.y - curve.startPoint.y) * scaleFactor;
366
+ curve.endControlPoint.x = curve.endPoint.x + (curve.endControlPoint.x - curve.endPoint.x) * scaleFactor;
367
+ curve.endControlPoint.y = curve.endPoint.y + (curve.endControlPoint.y - curve.endPoint.y) * scaleFactor;
368
+ // console.log("ADDING T CURVE", curve);
369
+ result.push(curve);
370
+ lastPoint.x = curve.endPoint.x;
371
+ lastPoint.y = curve.endPoint.y;
372
+ lastControlPoint.x = curve.endControlPoint.x;
373
+ lastControlPoint.y = curve.endControlPoint.y;
374
+ if (isNaN(firstPoint.x)) {
375
+ firstPoint.x = curve.startPoint.x;
376
+ firstPoint.y = curve.startPoint.y;
377
+ }
378
+ i += 2;
379
+ }
380
+ };
381
+ // The S|s x2 y2 x y
382
+ var _handleShorthandCubicCurveTo = function (data, isRelative, firstPoint, lastPoint, lastControlPoint, result) {
383
+ // console.log("Handle SHORTHANDCUBICBEZIERTO", data);
384
+ if (data.length < 5) {
385
+ throw "Unsufficient params for SHORTHANDCUBICBEZIERTO";
386
+ }
387
+ var curve = new CubicBezierCurve_1.CubicBezierCurve(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(lastPoint));
388
+ if (isRelative) {
389
+ curve.startControlPoint.x = lastPoint.x - (lastControlPoint.x - lastPoint.x);
390
+ curve.startControlPoint.y = lastPoint.y - (lastControlPoint.y - lastPoint.y);
391
+ curve.endControlPoint.x += Number(data[1]);
392
+ curve.endControlPoint.y += Number(data[2]);
393
+ curve.endPoint.x += Number(data[3]);
394
+ curve.endPoint.y += Number(data[4]);
395
+ }
396
+ else {
397
+ curve.startControlPoint.x = lastPoint.x - (lastControlPoint.x - lastPoint.x);
398
+ curve.startControlPoint.y = lastPoint.y - (lastControlPoint.y - lastPoint.y);
399
+ curve.endControlPoint.x = Number(data[1]);
400
+ curve.endControlPoint.y = Number(data[2]);
401
+ curve.endPoint.x = Number(data[3]);
402
+ curve.endPoint.y = Number(data[4]);
403
+ }
404
+ result.push(curve);
405
+ lastPoint.x = curve.endPoint.x;
406
+ lastPoint.y = curve.endPoint.y;
407
+ lastControlPoint.x = curve.endControlPoint.x;
408
+ lastControlPoint.y = curve.endControlPoint.y;
409
+ if (isNaN(firstPoint.x)) {
410
+ firstPoint.x = curve.startPoint.x;
411
+ firstPoint.y = curve.startPoint.y;
412
+ }
413
+ };
414
+ // EllipticalArcTo: A|a rx ry x-axis-rotation large-arc-flag sweep-flag x y
415
+ var _handleArcTo = function (data, isRelative, firstPoint, lastPoint, lastControlPoint, result) {
416
+ if (data.length < 8) {
417
+ throw "Unsufficient params for ARCTO";
418
+ }
419
+ for (var i = 1; i + 6 < data.length; i += 7) {
420
+ var arcEndPoint = { x: Number(data[i + 5]), y: Number(data[i + 6]) };
421
+ if (isRelative) {
422
+ arcEndPoint.x += lastPoint.x;
423
+ arcEndPoint.y += lastPoint.y;
424
+ }
425
+ // console.log(
426
+ // "ARC",
427
+ // "data.length",
428
+ // data.length,
429
+ // "i",
430
+ // i,
431
+ // "lastPoint.x",
432
+ // lastPoint.x, // x1
433
+ // "lastPoint.y",
434
+ // lastPoint.y, // y1
435
+ // "data[i]",
436
+ // Number(data[i]), // rx
437
+ // "data[i+1]",
438
+ // Number(data[i + 1]), // ry
439
+ // "data[i+2]",
440
+ // Number(data[i + 2]), // phi: number,
441
+ // "data[i+3]",
442
+ // Boolean(data[i + 3]), // fa: boolean,
443
+ // "data[i+4]",
444
+ // Boolean(data[i + 4]), // fs: boolean,
445
+ // "data[i+5]",
446
+ // arcEndPoint.x, // Number(data[6]), // x2: number,
447
+ // "data[i+6]",
448
+ // arcEndPoint.y // Number(data[7]) // y2: number
449
+ // );
450
+ // A 5 4 0 1 1 -10 -5
451
+ // TODO: respect relative/absolute here
452
+ var ellipseSector = VEllipseSector_1.VEllipseSector.ellipseSectorUtils.endpointToCenterParameters(lastPoint.x, lastPoint.y, Number(data[i]), Number(data[i + 1]), Number(data[i + 2]) * DEG_TO_RAD, Boolean(data[i + 3]), Boolean(data[i + 4]), arcEndPoint.x, arcEndPoint.y // Number(data[7]) // y2: number
453
+ );
454
+ // console.log("ellipseSector", ellipseSector);
455
+ var curves = ellipseSector.toCubicBezier(4); // 4 segments already seems to be a good approximation
456
+ for (var j = 0; j < curves.length; j++) {
457
+ result.push(curves[j]); // Destruct!
458
+ }
459
+ // result.push(ellipseSector.ellipse);
460
+ if (curves.length > 0) {
461
+ // console.log("curves", curves);
462
+ var lastCurve = curves[curves.length - 1];
463
+ // lastPoint.x = lastCurve.endPoint.x;
464
+ // lastPoint.y = lastCurve.endPoint.y;
465
+ lastControlPoint.x = lastCurve.endControlPoint.x;
466
+ lastControlPoint.y = lastCurve.endControlPoint.y;
467
+ if (isNaN(firstPoint.x)) {
468
+ firstPoint.x = curves[0].startPoint.x;
469
+ firstPoint.y = curves[0].startPoint.y;
470
+ }
471
+ }
472
+ lastPoint.x = arcEndPoint.x;
473
+ lastPoint.y = arcEndPoint.y;
474
+ } // END for
475
+ // TODO: track first/last/control point
476
+ };
477
+ var _handleClosePath = function (_data, _isRelative, firstPoint, lastPoint, lastControlPoint, result) {
478
+ // console.log("Handle CLOSEPATH", "lastPoint", lastPoint, "firstPoint", firstPoint);
479
+ var line = new Line_1.Line(new Vertex_1.Vertex(lastPoint), new Vertex_1.Vertex(firstPoint));
480
+ result.push(line);
481
+ lastPoint.x = line.b.x;
482
+ lastPoint.y = line.b.y;
483
+ lastControlPoint.x = line.b.x;
484
+ lastControlPoint.y = line.b.y;
485
+ };
486
+ //# sourceMappingURL=parseSVGPathData.js.map