path2d-polyfill 1.1.8 → 1.2.2

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/CHANGELOG.md ADDED
@@ -0,0 +1,77 @@
1
+ ## [1.2.2](https://github.com/nilzona/path2d-polyfill/compare/v1.2.1...v1.2.2) (2022-07-23)
2
+
3
+ undefined
4
+
5
+ ### [1.2.1](https://github.com/nilzona/path2d-polyfill/compare/v1.2.0...v1.2.1) (2022-03-06)## [1.2.0](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2021-10-30)
6
+
7
+ ### Bug Fixes
8
+
9
+ - fixup lint and build ([94be3cd](https://github.com/nilzona/path2d-polyfill/commit/94be3cd38a58f83efc403a58380ff3c23b4f18bf))
10
+ - sync version in package.json with tags ([e12e852](https://github.com/nilzona/path2d-polyfill/commit/e12e852ffb13034fa13efd5112c59b6b13a46013))
11
+
12
+ ### [1.1.2](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2021-05-04)
13
+
14
+ ### [1.1.1](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2020-11-16)
15
+
16
+ ### Features
17
+
18
+ - support for isPointInPath ([605f5d1](https://github.com/nilzona/path2d-polyfill/commit/605f5d188812e472575ccbaba351b9bbc58d3677))
19
+
20
+ ### Bug Fixes
21
+
22
+ - documentation readme ([5a0abaa](https://github.com/nilzona/path2d-polyfill/commit/5a0abaab6976f10c57ac83e6f6481ed425ac940e))
23
+
24
+ ### [1.0.2](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2020-08-27)
25
+
26
+ ### Bug Fixes
27
+
28
+ - remove unused css rule ([54e5174](https://github.com/nilzona/path2d-polyfill/commit/54e5174c64f6e84ef891d8830c828efc45c73b93))
29
+ - update badge in README.md ([483afe2](https://github.com/nilzona/path2d-polyfill/commit/483afe2b3440083bbb0c3dae74510959055d0f86))
30
+
31
+ ## [1.0.0](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2020-05-27)
32
+
33
+ ### [0.4.2](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2019-08-28)
34
+
35
+ ### [0.4.1](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2019-04-15)
36
+
37
+ ## [0.4.0](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2019-04-12)
38
+
39
+ ### Features
40
+
41
+ - support ellipse commands ([#7](https://github.com/nilzona/path2d-polyfill/issues/7)) ([02af6d5](https://github.com/nilzona/path2d-polyfill/commit/02af6d55365b8ef70b8eecad88b913e71ae191b2))
42
+
43
+ ### Bug Fixes
44
+
45
+ - move current position when a path is closed ([#9](https://github.com/nilzona/path2d-polyfill/issues/9)) ([ff6d2f7](https://github.com/nilzona/path2d-polyfill/commit/ff6d2f770f9895be2ac2e947697b8f76e488cb37))
46
+
47
+ ### [0.3.1](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2018-09-26)
48
+
49
+ ### Bug Fixes
50
+
51
+ - better checks if polyfill is needed ([bd65468](https://github.com/nilzona/path2d-polyfill/commit/bd654681662530d19a0958db22c5990424fb77f2))
52
+
53
+ ## [0.3.0](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2018-09-25)
54
+
55
+ ### [0.2.2](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2018-09-04)
56
+
57
+ ### [0.2.1](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2018-06-05)
58
+
59
+ ## [0.2.0](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2018-06-04)
60
+
61
+ ### [0.1.3](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2018-05-22)
62
+
63
+ ### Bug Fixes
64
+
65
+ - Avoid reference to global window ([9d3e742](https://github.com/nilzona/path2d-polyfill/commit/9d3e74241eb0652afe22d34523f10f3a3837e179))
66
+ - Remove wrong removeChild call ([123db85](https://github.com/nilzona/path2d-polyfill/commit/123db8571ff8b1b6c2fa917b513c74f8215acc37))
67
+ - Update README.md ([bcb01e1](https://github.com/nilzona/path2d-polyfill/commit/bcb01e153add2dccf95adaced13646e871086a3a))
68
+
69
+ ### [0.1.1](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2018-05-18)
70
+
71
+ ## [0.1.0](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2018-05-18)
72
+
73
+ ### Features
74
+
75
+ - Added examples ([261165c](https://github.com/nilzona/path2d-polyfill/commit/261165cfb0ea3a9910624f719a34a3596f1791d0))
76
+ - First version of Path2D polyfill ([a660f19](https://github.com/nilzona/path2d-polyfill/commit/a660f194f416785a40d8d7f5ad451bb54cec15c3))
77
+ - Implement addPath ([72d4228](https://github.com/nilzona/path2d-polyfill/commit/72d4228bd6c4dda64fa957ab80e49bd7c7677d8f))
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # path2d-polyfill
2
2
 
3
- ![master](https://github.com/nilzona/path2d-polyfill/workflows/Build,%20Test%20and%20maybe%20Publish/badge.svg)
3
+ [![validate](https://github.com/nilzona/path2d-polyfill/actions/workflows/validate.yaml/badge.svg)](https://github.com/nilzona/path2d-polyfill/actions/workflows/validate.yaml)
4
4
 
5
5
  Polyfills Path2D api for rendering SVG paths in canvas
6
6
 
@@ -10,42 +10,26 @@ Use this to enable Path2D features in e.g. Internet Explorer.
10
10
 
11
11
  Load from cdn
12
12
 
13
- ```
13
+ ```html
14
14
  <script lang="javascript" src="https://unpkg.com/path2d-polyfill"></script>
15
15
  ```
16
16
 
17
17
  or install from npm
18
18
 
19
- ```
19
+ ```shell
20
20
  npm install --save path2d-polyfill
21
21
  ```
22
22
 
23
- include directly in html-page
24
-
25
- ```html
26
- <html>
27
- <head>
28
- ...
29
- </head>
30
- <body>
31
- <script
32
- lang="javascript"
33
- src="node_modules/path2d-polyfill/path2d-polyfill.js"
34
- ></script>
35
- </body>
36
- </html>
37
- ```
38
-
39
- or import with module bundler e.g. webpack _before_ you try to use the feature
23
+ and import with module bundler e.g. webpack _before_ you try to use the feature
40
24
 
41
25
  ```javascript
42
- require('path2d-polyfill');
26
+ require("path2d-polyfill");
43
27
  ```
44
28
 
45
- or if you use transpiler to support es2015+ modules
29
+ or with es2015+ modules
46
30
 
47
31
  ```javascript
48
- import 'path2d-polyfill';
32
+ import "path2d-polyfill";
49
33
  ```
50
34
 
51
35
  ## Support table
@@ -66,20 +50,20 @@ import 'path2d-polyfill';
66
50
  Example of usage
67
51
 
68
52
  ```javascript
69
- ctx.fill(new Path2D('M 80 80 A 45 45 0 0 0 125 125 L 125 80 Z'));
70
- ctx.stroke(new Path2D('M 80 80 A 45 45 0 0 0 125 125 L 125 80 Z'));
53
+ ctx.fill(new Path2D("M 80 80 A 45 45 0 0 0 125 125 L 125 80 Z"));
54
+ ctx.stroke(new Path2D("M 80 80 A 45 45 0 0 0 125 125 L 125 80 Z"));
71
55
  ```
72
56
 
73
57
  ## See it in action
74
58
 
75
59
  Clone this repo and run the following
76
60
 
77
- ```
61
+ ```shell
78
62
  yarn
79
63
  yarn start
80
64
  ```
81
65
 
82
- open http://localhost:10001 to see the example page.
66
+ open <http://localhost:10001> to see the example page.
83
67
 
84
68
  ## Contributing
85
69
 
package/dist/index.esm.js CHANGED
@@ -34,7 +34,7 @@ function parse(path) {
34
34
  var data = [];
35
35
  var p = String(path).trim(); // A path data segment (if there is one) must begin with a "moveto" command
36
36
 
37
- if (p[0] !== 'M' && p[0] !== 'm') {
37
+ if (p[0] !== "M" && p[0] !== "m") {
38
38
  return data;
39
39
  }
40
40
 
@@ -43,15 +43,15 @@ function parse(path) {
43
43
  var theArgs = parseValues(args);
44
44
  var theCommand = command; // overloaded moveTo
45
45
 
46
- if (type === 'm' && theArgs.length > 2) {
46
+ if (type === "m" && theArgs.length > 2) {
47
47
  data.push([theCommand].concat(theArgs.splice(0, 2)));
48
- type = 'l';
49
- theCommand = theCommand === 'm' ? 'l' : 'L';
48
+ type = "l";
49
+ theCommand = theCommand === "m" ? "l" : "L";
50
50
  } // Ignore invalid commands
51
51
 
52
52
 
53
53
  if (theArgs.length < ARG_LENGTH[type]) {
54
- return '';
54
+ return "";
55
55
  }
56
56
 
57
57
  data.push([theCommand].concat(theArgs.splice(0, ARG_LENGTH[type]))); // The command letter can be eliminated on subsequent commands if the
@@ -63,12 +63,12 @@ function parse(path) {
63
63
  data.push([theCommand].concat(theArgs.splice(0, ARG_LENGTH[type])));
64
64
  }
65
65
 
66
- return '';
66
+ return "";
67
67
  });
68
68
  return data;
69
69
  }
70
70
 
71
- var parsePath = parse;
71
+ var parsePath$2 = parse;
72
72
 
73
73
  function _classCallCheck(instance, Constructor) {
74
74
  if (!(instance instanceof Constructor)) {
@@ -89,6 +89,9 @@ function _defineProperties(target, props) {
89
89
  function _createClass(Constructor, protoProps, staticProps) {
90
90
  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
91
91
  if (staticProps) _defineProperties(Constructor, staticProps);
92
+ Object.defineProperty(Constructor, "prototype", {
93
+ writable: false
94
+ });
92
95
  return Constructor;
93
96
  }
94
97
 
@@ -125,16 +128,17 @@ function _nonIterableSpread() {
125
128
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
126
129
  }
127
130
 
131
+ var parsePath$1 = parsePath$2;
128
132
  /**
129
133
  * Work around for https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8438884/
130
134
  * @ignore
131
135
  */
132
136
 
133
137
  function supportsSvgPathArgument(window) {
134
- var canvas = window.document.createElement('canvas');
135
- var g = canvas.getContext('2d');
136
- var p = new window.Path2D('M0 0 L1 1');
137
- g.strokeStyle = 'red';
138
+ var canvas = window.document.createElement("canvas");
139
+ var g = canvas.getContext("2d");
140
+ var p = new window.Path2D("M0 0 L1 1");
141
+ g.strokeStyle = "red";
138
142
  g.lineWidth = 1;
139
143
  g.stroke(p);
140
144
  var imgData = g.getImageData(0, 0, 1, 1);
@@ -159,7 +163,7 @@ function scalePoint(point, s) {
159
163
  }
160
164
 
161
165
  function polyFillPath2D(window) {
162
- if (typeof window === 'undefined' || !window.CanvasRenderingContext2D) {
166
+ if (typeof window === "undefined" || !window.CanvasRenderingContext2D) {
163
167
  return;
164
168
  }
165
169
 
@@ -185,7 +189,7 @@ function polyFillPath2D(window) {
185
189
 
186
190
  (_this$segments = this.segments).push.apply(_this$segments, _toConsumableArray(path.segments));
187
191
  } else if (path) {
188
- this.segments = parsePath(path);
192
+ this.segments = parsePath$1(path);
189
193
  }
190
194
  }
191
195
 
@@ -201,47 +205,47 @@ function polyFillPath2D(window) {
201
205
  }, {
202
206
  key: "moveTo",
203
207
  value: function moveTo(x, y) {
204
- this.segments.push(['M', x, y]);
208
+ this.segments.push(["M", x, y]);
205
209
  }
206
210
  }, {
207
211
  key: "lineTo",
208
212
  value: function lineTo(x, y) {
209
- this.segments.push(['L', x, y]);
213
+ this.segments.push(["L", x, y]);
210
214
  }
211
215
  }, {
212
216
  key: "arc",
213
217
  value: function arc(x, y, r, start, end, ccw) {
214
- this.segments.push(['AC', x, y, r, start, end, !!ccw]);
218
+ this.segments.push(["AC", x, y, r, start, end, !!ccw]);
215
219
  }
216
220
  }, {
217
221
  key: "arcTo",
218
222
  value: function arcTo(x1, y1, x2, y2, r) {
219
- this.segments.push(['AT', x1, y1, x2, y2, r]);
223
+ this.segments.push(["AT", x1, y1, x2, y2, r]);
220
224
  }
221
225
  }, {
222
226
  key: "ellipse",
223
227
  value: function ellipse(x, y, rx, ry, angle, start, end, ccw) {
224
- this.segments.push(['E', x, y, rx, ry, angle, start, end, !!ccw]);
228
+ this.segments.push(["E", x, y, rx, ry, angle, start, end, !!ccw]);
225
229
  }
226
230
  }, {
227
231
  key: "closePath",
228
232
  value: function closePath() {
229
- this.segments.push(['Z']);
233
+ this.segments.push(["Z"]);
230
234
  }
231
235
  }, {
232
236
  key: "bezierCurveTo",
233
237
  value: function bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
234
- this.segments.push(['C', cp1x, cp1y, cp2x, cp2y, x, y]);
238
+ this.segments.push(["C", cp1x, cp1y, cp2x, cp2y, x, y]);
235
239
  }
236
240
  }, {
237
241
  key: "quadraticCurveTo",
238
242
  value: function quadraticCurveTo(cpx, cpy, x, y) {
239
- this.segments.push(['Q', cpx, cpy, x, y]);
243
+ this.segments.push(["Q", cpx, cpy, x, y]);
240
244
  }
241
245
  }, {
242
246
  key: "rect",
243
247
  value: function rect(x, y, width, height) {
244
- this.segments.push(['R', x, y, width, height]);
248
+ this.segments.push(["R", x, y, width, height]);
245
249
  }
246
250
  }]);
247
251
 
@@ -289,20 +293,20 @@ function polyFillPath2D(window) {
289
293
  var s = segments[i];
290
294
  pathType = s[0]; // Reset control point if command is not cubic
291
295
 
292
- if (pathType !== 'S' && pathType !== 's' && pathType !== 'C' && pathType !== 'c') {
296
+ if (pathType !== "S" && pathType !== "s" && pathType !== "C" && pathType !== "c") {
293
297
  cpx = null;
294
298
  cpy = null;
295
299
  }
296
300
 
297
- if (pathType !== 'T' && pathType !== 't' && pathType !== 'Q' && pathType !== 'q') {
301
+ if (pathType !== "T" && pathType !== "t" && pathType !== "Q" && pathType !== "q") {
298
302
  qcpx = null;
299
303
  qcpy = null;
300
304
  }
301
305
 
302
306
  switch (pathType) {
303
- case 'm':
304
- case 'M':
305
- if (pathType === 'm') {
307
+ case "m":
308
+ case "M":
309
+ if (pathType === "m") {
306
310
  x += s[1];
307
311
  y += s[2];
308
312
  } else {
@@ -310,7 +314,7 @@ function polyFillPath2D(window) {
310
314
  y = s[2];
311
315
  }
312
316
 
313
- if (pathType === 'M' || !startPoint) {
317
+ if (pathType === "M" || !startPoint) {
314
318
  startPoint = {
315
319
  x: x,
316
320
  y: y
@@ -320,41 +324,41 @@ function polyFillPath2D(window) {
320
324
  canvas.moveTo(x, y);
321
325
  break;
322
326
 
323
- case 'l':
327
+ case "l":
324
328
  x += s[1];
325
329
  y += s[2];
326
330
  canvas.lineTo(x, y);
327
331
  break;
328
332
 
329
- case 'L':
333
+ case "L":
330
334
  x = s[1];
331
335
  y = s[2];
332
336
  canvas.lineTo(x, y);
333
337
  break;
334
338
 
335
- case 'H':
339
+ case "H":
336
340
  x = s[1];
337
341
  canvas.lineTo(x, y);
338
342
  break;
339
343
 
340
- case 'h':
344
+ case "h":
341
345
  x += s[1];
342
346
  canvas.lineTo(x, y);
343
347
  break;
344
348
 
345
- case 'V':
349
+ case "V":
346
350
  y = s[1];
347
351
  canvas.lineTo(x, y);
348
352
  break;
349
353
 
350
- case 'v':
354
+ case "v":
351
355
  y += s[1];
352
356
  canvas.lineTo(x, y);
353
357
  break;
354
358
 
355
- case 'a':
356
- case 'A':
357
- if (pathType === 'a') {
359
+ case "a":
360
+ case "A":
361
+ if (pathType === "a") {
358
362
  x += s[6];
359
363
  y += s[7];
360
364
  } else {
@@ -413,7 +417,7 @@ function polyFillPath2D(window) {
413
417
  canvas.restore();
414
418
  break;
415
419
 
416
- case 'C':
420
+ case "C":
417
421
  cpx = s[3]; // Last control point
418
422
 
419
423
  cpy = s[4];
@@ -422,7 +426,7 @@ function polyFillPath2D(window) {
422
426
  canvas.bezierCurveTo(s[1], s[2], cpx, cpy, x, y);
423
427
  break;
424
428
 
425
- case 'c':
429
+ case "c":
426
430
  canvas.bezierCurveTo(s[1] + x, s[2] + y, s[3] + x, s[4] + y, s[5] + x, s[6] + y);
427
431
  cpx = s[3] + x; // Last control point
428
432
 
@@ -431,7 +435,7 @@ function polyFillPath2D(window) {
431
435
  y += s[6];
432
436
  break;
433
437
 
434
- case 'S':
438
+ case "S":
435
439
  if (cpx === null || cpy === null) {
436
440
  cpx = x;
437
441
  cpy = y;
@@ -445,7 +449,7 @@ function polyFillPath2D(window) {
445
449
  y = s[4];
446
450
  break;
447
451
 
448
- case 's':
452
+ case "s":
449
453
  if (cpx === null || cpy === null) {
450
454
  cpx = x;
451
455
  cpy = y;
@@ -459,7 +463,7 @@ function polyFillPath2D(window) {
459
463
  y += s[4];
460
464
  break;
461
465
 
462
- case 'Q':
466
+ case "Q":
463
467
  qcpx = s[1]; // last control point
464
468
 
465
469
  qcpy = s[2];
@@ -468,7 +472,7 @@ function polyFillPath2D(window) {
468
472
  canvas.quadraticCurveTo(qcpx, qcpy, x, y);
469
473
  break;
470
474
 
471
- case 'q':
475
+ case "q":
472
476
  qcpx = s[1] + x; // last control point
473
477
 
474
478
  qcpy = s[2] + y;
@@ -477,7 +481,7 @@ function polyFillPath2D(window) {
477
481
  canvas.quadraticCurveTo(qcpx, qcpy, x, y);
478
482
  break;
479
483
 
480
- case 'T':
484
+ case "T":
481
485
  if (qcpx === null || qcpy === null) {
482
486
  qcpx = x;
483
487
  qcpy = y;
@@ -491,7 +495,7 @@ function polyFillPath2D(window) {
491
495
  canvas.quadraticCurveTo(qcpx, qcpy, x, y);
492
496
  break;
493
497
 
494
- case 't':
498
+ case "t":
495
499
  if (qcpx === null || qcpy === null) {
496
500
  qcpx = x;
497
501
  qcpy = y;
@@ -505,15 +509,15 @@ function polyFillPath2D(window) {
505
509
  canvas.quadraticCurveTo(qcpx, qcpy, x, y);
506
510
  break;
507
511
 
508
- case 'z':
509
- case 'Z':
512
+ case "z":
513
+ case "Z":
510
514
  x = startPoint.x;
511
515
  y = startPoint.y;
512
516
  startPoint = undefined;
513
517
  canvas.closePath();
514
518
  break;
515
519
 
516
- case 'AC':
520
+ case "AC":
517
521
  // arc
518
522
  x = s[1];
519
523
  y = s[2];
@@ -524,7 +528,7 @@ function polyFillPath2D(window) {
524
528
  canvas.arc(x, y, r, startAngle, endAngle, ccw);
525
529
  break;
526
530
 
527
- case 'AT':
531
+ case "AT":
528
532
  // arcTo
529
533
  x1 = s[1];
530
534
  y1 = s[2];
@@ -534,7 +538,7 @@ function polyFillPath2D(window) {
534
538
  canvas.arcTo(x1, y1, x, y, r);
535
539
  break;
536
540
 
537
- case 'E':
541
+ case "E":
538
542
  // ellipse
539
543
  x = s[1];
540
544
  y = s[2];
@@ -552,7 +556,7 @@ function polyFillPath2D(window) {
552
556
  canvas.restore();
553
557
  break;
554
558
 
555
- case 'R':
559
+ case "R":
556
560
  // rect
557
561
  x = s[1];
558
562
  y = s[2];
@@ -580,9 +584,9 @@ function polyFillPath2D(window) {
580
584
  args[_key] = arguments[_key];
581
585
  }
582
586
 
583
- var fillRule = 'nonzero';
587
+ var fillRule = "nonzero";
584
588
 
585
- if (args.length === 0 || args.length === 1 && typeof args[0] === 'string') {
589
+ if (args.length === 0 || args.length === 1 && typeof args[0] === "string") {
586
590
  cFill.apply(this, args);
587
591
  return;
588
592
  }
@@ -614,11 +618,11 @@ function polyFillPath2D(window) {
614
618
  }
615
619
 
616
620
  // let fillRule = 'nonzero';
617
- if (args[0].constructor.name === 'Path2D') {
621
+ if (args[0].constructor.name === "Path2D") {
618
622
  // first argument is a Path2D object
619
623
  var x = args[1];
620
624
  var y = args[2];
621
- var fillRule = args[3] || 'nonzero';
625
+ var fillRule = args[3] || "nonzero";
622
626
  var path = args[0];
623
627
  buildPath(this, path.segments);
624
628
  return cIsPointInPath.apply(this, [x, y, fillRule]);
@@ -630,9 +634,12 @@ function polyFillPath2D(window) {
630
634
  window.Path2D = Path2D;
631
635
  }
632
636
 
633
- var path2dPolyfill = polyFillPath2D;
637
+ var path2dPolyfill$1 = polyFillPath2D;
638
+
639
+ var parsePath = parsePath$2;
640
+ var path2dPolyfill = path2dPolyfill$1;
634
641
 
635
- if (typeof window !== 'undefined') {
642
+ if (typeof window !== "undefined") {
636
643
  path2dPolyfill(window);
637
644
  }
638
645
 
@@ -641,5 +648,5 @@ var src = {
641
648
  parsePath: parsePath
642
649
  };
643
650
 
644
- export default src;
651
+ export { src as default };
645
652
  //# sourceMappingURL=index.esm.js.map