Launch Week Day 2: Introducing Reports: An Extensible Reporting Framework for Socket Data.Learn More
Socket
Book a DemoSign in
Socket

path2d-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

path2d-polyfill - npm Package Compare versions

Comparing version
1.2.3
to
2.0.0-beta.0
+596
dist/path2d-polyfill.cjs.js
'use strict';
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
var ARG_LENGTH = {
a: 7,
c: 6,
h: 1,
l: 2,
m: 2,
q: 4,
s: 4,
t: 2,
v: 1,
z: 0
};
var SEGMENT_PATTERN = /([astvzqmhlc])([^astvzqmhlc]*)/gi;
var NUMBER = /-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;
function parseValues(args) {
var numbers = args.match(NUMBER);
return numbers ? numbers.map(Number) : [];
}
/**
* parse an svg path data string. Generates an Array
* of commands where each command is an Array of the
* form `[command, arg1, arg2, ...]`
*
* https://www.w3.org/TR/SVG/paths.html#PathDataGeneralInformation
* @ignore
*
* @param {string} path
* @returns {array}
*/
function parsePath(path) {
var data = [];
var p = String(path).trim();
// A path data segment (if there is one) must begin with a "moveto" command
if (p[0] !== "M" && p[0] !== "m") {
return data;
}
p.replace(SEGMENT_PATTERN, function (_, command, args) {
var theArgs = parseValues(args);
var type = command.toLowerCase();
var theCommand = command;
// overloaded moveTo
if (type === "m" && theArgs.length > 2) {
data.push(__spreadArray([theCommand], theArgs.splice(0, 2), true));
type = "l";
theCommand = theCommand === "m" ? "l" : "L";
}
// Ignore invalid commands
if (theArgs.length < ARG_LENGTH[type]) {
return "";
}
data.push(__spreadArray([theCommand], theArgs.splice(0, ARG_LENGTH[type]), true));
// The command letter can be eliminated on subsequent commands if the
// same command is used multiple times in a row (e.g., you can drop the
// second "L" in "M 100 200 L 200 100 L -100 -200" and use
// "M 100 200 L 200 100 -100 -200" instead).
while (theArgs.length >= ARG_LENGTH[type] && theArgs.length && ARG_LENGTH[type]) {
data.push(__spreadArray([theCommand], theArgs.splice(0, ARG_LENGTH[type]), true));
}
return "";
});
return data;
}
function rotatePoint(point, angle) {
var nx = point.x * Math.cos(angle) - point.y * Math.sin(angle);
var ny = point.y * Math.cos(angle) + point.x * Math.sin(angle);
point.x = nx;
point.y = ny;
}
function translatePoint(point, dx, dy) {
point.x += dx;
point.y += dy;
}
function scalePoint(point, s) {
point.x *= s;
point.y *= s;
}
/**
* Implements a browser's Path2D api
*/
var Path2D = /** @class */ (function () {
function Path2D(path) {
var _a;
this.commands = [];
if (path && path instanceof Path2D) {
(_a = this.commands).push.apply(_a, path.commands);
}
else if (path) {
this.commands = parsePath(path);
}
}
Path2D.prototype.addPath = function (path) {
var _a;
if (path && path instanceof Path2D) {
(_a = this.commands).push.apply(_a, path.commands);
}
};
Path2D.prototype.moveTo = function (x, y) {
this.commands.push(["M", x, y]);
};
Path2D.prototype.lineTo = function (x, y) {
this.commands.push(["L", x, y]);
};
Path2D.prototype.arc = function (x, y, r, start, end, ccw) {
this.commands.push(["AC", x, y, r, start, end, !!ccw]);
};
Path2D.prototype.arcTo = function (x1, y1, x2, y2, r) {
this.commands.push(["AT", x1, y1, x2, y2, r]);
};
Path2D.prototype.ellipse = function (x, y, rx, ry, angle, start, end, ccw) {
this.commands.push(["E", x, y, rx, ry, angle, start, end, !!ccw]);
};
Path2D.prototype.closePath = function () {
this.commands.push(["Z"]);
};
Path2D.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
this.commands.push(["C", cp1x, cp1y, cp2x, cp2y, x, y]);
};
Path2D.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
this.commands.push(["Q", cpx, cpy, x, y]);
};
Path2D.prototype.rect = function (x, y, width, height) {
this.commands.push(["R", x, y, width, height]);
};
Path2D.prototype.roundRect = function (x, y, width, height, radii) {
if (typeof radii === "undefined") {
this.commands.push(["RR", x, y, width, height, 0]);
}
else {
this.commands.push(["RR", x, y, width, height, radii]);
}
};
return Path2D;
}());
function buildPath(ctx, commands) {
var x = 0;
var y = 0;
var endAngle;
var startAngle;
var largeArcFlag;
var sweepFlag;
var endPoint;
var midPoint;
var angle;
var lambda;
var t1;
var t2;
var x1;
var y1;
var r;
var rx;
var ry;
var w;
var h;
var pathType;
var centerPoint;
var ccw;
var radii;
var cpx = null;
var cpy = null;
var qcpx = null;
var qcpy = null;
var startPoint = null;
var currentPoint = null;
ctx.beginPath();
for (var i = 0; i < commands.length; ++i) {
pathType = commands[i][0];
// Reset control point if command is not cubic
if (pathType !== "S" && pathType !== "s" && pathType !== "C" && pathType !== "c") {
cpx = null;
cpy = null;
}
if (pathType !== "T" && pathType !== "t" && pathType !== "Q" && pathType !== "q") {
qcpx = null;
qcpy = null;
}
var c = void 0;
switch (pathType) {
case "m":
case "M":
c = commands[i];
if (pathType === "m") {
x += c[1];
y += c[2];
}
else {
x = c[1];
y = c[2];
}
if (pathType === "M" || !startPoint) {
startPoint = { x: x, y: y };
}
ctx.moveTo(x, y);
break;
case "l":
c = commands[i];
x += c[1];
y += c[2];
ctx.lineTo(x, y);
break;
case "L":
c = commands[i];
x = c[1];
y = c[2];
ctx.lineTo(x, y);
break;
case "H":
c = commands[i];
x = c[1];
ctx.lineTo(x, y);
break;
case "h":
c = commands[i];
x += c[1];
ctx.lineTo(x, y);
break;
case "V":
c = commands[i];
y = c[1];
ctx.lineTo(x, y);
break;
case "v":
c = commands[i];
y += c[1];
ctx.lineTo(x, y);
break;
case "a":
case "A":
c = commands[i];
if (currentPoint === null) {
throw new Error("This should never happen");
}
if (pathType === "a") {
x += c[6];
y += c[7];
}
else {
x = c[6];
y = c[7];
}
rx = c[1]; // rx
ry = c[2]; // ry
angle = (c[3] * Math.PI) / 180;
largeArcFlag = !!c[4];
sweepFlag = !!c[5];
endPoint = { x: x, y: y };
// https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
midPoint = {
x: (currentPoint.x - endPoint.x) / 2,
y: (currentPoint.y - endPoint.y) / 2
};
rotatePoint(midPoint, -angle);
// radius correction
lambda = (midPoint.x * midPoint.x) / (rx * rx) + (midPoint.y * midPoint.y) / (ry * ry);
if (lambda > 1) {
lambda = Math.sqrt(lambda);
rx *= lambda;
ry *= lambda;
}
centerPoint = {
x: (rx * midPoint.y) / ry,
y: -(ry * midPoint.x) / rx
};
t1 = rx * rx * ry * ry;
t2 = rx * rx * midPoint.y * midPoint.y + ry * ry * midPoint.x * midPoint.x;
if (sweepFlag !== largeArcFlag) {
scalePoint(centerPoint, Math.sqrt((t1 - t2) / t2) || 0);
}
else {
scalePoint(centerPoint, -Math.sqrt((t1 - t2) / t2) || 0);
}
startAngle = Math.atan2((midPoint.y - centerPoint.y) / ry, (midPoint.x - centerPoint.x) / rx);
endAngle = Math.atan2(-(midPoint.y + centerPoint.y) / ry, -(midPoint.x + centerPoint.x) / rx);
rotatePoint(centerPoint, angle);
translatePoint(centerPoint, (endPoint.x + currentPoint.x) / 2, (endPoint.y + currentPoint.y) / 2);
ctx.save();
ctx.translate(centerPoint.x, centerPoint.y);
ctx.rotate(angle);
ctx.scale(rx, ry);
ctx.arc(0, 0, 1, startAngle, endAngle, !sweepFlag);
ctx.restore();
break;
case "C":
c = commands[i];
cpx = c[3]; // Last control point
cpy = c[4];
x = c[5];
y = c[6];
ctx.bezierCurveTo(c[1], c[2], cpx, cpy, x, y);
break;
case "c":
c = commands[i];
ctx.bezierCurveTo(c[1] + x, c[2] + y, c[3] + x, c[4] + y, c[5] + x, c[6] + y);
cpx = c[3] + x; // Last control point
cpy = c[4] + y;
x += c[5];
y += c[6];
break;
case "S":
c = commands[i];
if (cpx === null || cpy === null) {
cpx = x;
cpy = y;
}
ctx.bezierCurveTo(2 * x - cpx, 2 * y - cpy, c[1], c[2], c[3], c[4]);
cpx = c[1]; // last control point
cpy = c[2];
x = c[3];
y = c[4];
break;
case "s":
c = commands[i];
if (cpx === null || cpy === null) {
cpx = x;
cpy = y;
}
ctx.bezierCurveTo(2 * x - cpx, 2 * y - cpy, c[1] + x, c[2] + y, c[3] + x, c[4] + y);
cpx = c[1] + x; // last control point
cpy = c[2] + y;
x += c[3];
y += c[4];
break;
case "Q":
c = commands[i];
qcpx = c[1]; // last control point
qcpy = c[2];
x = c[3];
y = c[4];
ctx.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "q":
c = commands[i];
qcpx = c[1] + x; // last control point
qcpy = c[2] + y;
x += c[3];
y += c[4];
ctx.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "T":
c = commands[i];
if (qcpx === null || qcpy === null) {
qcpx = x;
qcpy = y;
}
qcpx = 2 * x - qcpx; // last control point
qcpy = 2 * y - qcpy;
x = c[1];
y = c[2];
ctx.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "t":
c = commands[i];
if (qcpx === null || qcpy === null) {
qcpx = x;
qcpy = y;
}
qcpx = 2 * x - qcpx; // last control point
qcpy = 2 * y - qcpy;
x += c[1];
y += c[2];
ctx.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "z":
case "Z":
if (startPoint) {
x = startPoint.x;
y = startPoint.y;
}
startPoint = null;
ctx.closePath();
break;
case "AC": // arc
c = commands[i];
x = c[1];
y = c[2];
r = c[3];
startAngle = c[4];
endAngle = c[5];
ccw = c[6];
ctx.arc(x, y, r, startAngle, endAngle, ccw);
break;
case "AT": // arcTo
c = commands[i];
x1 = c[1];
y1 = c[2];
x = c[3];
y = c[4];
r = c[5];
ctx.arcTo(x1, y1, x, y, r);
break;
case "E": // ellipse
c = commands[i];
x = c[1];
y = c[2];
rx = c[3];
ry = c[4];
angle = c[5];
startAngle = c[6];
endAngle = c[7];
ccw = c[8];
ctx.save();
ctx.translate(x, y);
ctx.rotate(angle);
ctx.scale(rx, ry);
ctx.arc(0, 0, 1, startAngle, endAngle, ccw);
ctx.restore();
break;
case "R": // rect
c = commands[i];
x = c[1];
y = c[2];
w = c[3];
h = c[4];
startPoint = { x: x, y: y };
ctx.rect(x, y, w, h);
break;
case "RR": // roundedRect
c = commands[i];
x = c[1];
y = c[2];
w = c[3];
h = c[4];
radii = c[5];
startPoint = { x: x, y: y };
ctx.roundRect(x, y, w, h, radii);
break;
}
if (!currentPoint) {
currentPoint = { x: x, y: y };
}
else {
currentPoint.x = x;
currentPoint.y = y;
}
}
}
/**
* Polyfills CanvasRenderingContext2D stroke, fill and isPointInPath so that they support Path2D objects.
* @param {WindowLike} window - window like object containing a CanvasRenderingContext2D constructor
*/
function polyfillPath2D(window) {
if (!window || !window.CanvasRenderingContext2D || window.Path2D)
return;
var CanvasRenderingContext2D = window.CanvasRenderingContext2D;
/* eslint-disable @typescript-eslint/unbound-method */
// setting unbound functions here. Make sure this is set in function call later
var cFill = CanvasRenderingContext2D.prototype.fill;
var cStroke = CanvasRenderingContext2D.prototype.stroke;
var cIsPointInPath = CanvasRenderingContext2D.prototype.isPointInPath;
/* eslint-enable @typescript-eslint/unbound-method */
CanvasRenderingContext2D.prototype.fill = function fill() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (args[0] instanceof Path2D) {
var path = args[0];
var fillRule = args[1] || "nonzero";
buildPath(this, path.commands);
cFill.apply(this, [fillRule]);
}
else {
var fillRule = args[0] || "nonzero";
return cFill.apply(this, [fillRule]);
}
};
CanvasRenderingContext2D.prototype.stroke = function stroke(path) {
if (path) {
buildPath(this, path.commands);
}
cStroke.apply(this);
};
CanvasRenderingContext2D.prototype.isPointInPath = function isPointInPath() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (args[0] instanceof Path2D) {
// first argument is a Path2D object
var path = args[0];
var x = args[1];
var y = args[2];
var fillRule = args[3] || "nonzero";
buildPath(this, path.commands);
return cIsPointInPath.apply(this, [x, y, fillRule]);
}
else {
return cIsPointInPath.apply(this, args);
}
};
window.Path2D = Path2D;
}
function roundRect(x, y, width, height, radii) {
var _this = this;
if (radii === void 0) { radii = 0; }
if (typeof radii === "number") {
// eslint-disable-next-line no-param-reassign
radii = [radii];
}
// check for range error
if (Array.isArray(radii)) {
if (radii.length === 0 || radii.length > 4) {
throw new RangeError("Failed to execute 'roundRect' on '".concat(this.constructor.name, "': ").concat(radii.length, " radii provided. Between one and four radii are necessary."));
}
radii.forEach(function (v) {
if (v < 0) {
throw new RangeError("Failed to execute 'roundRect' on '".concat(_this.constructor.name, "': Radius value ").concat(v, " is negative."));
}
});
}
else {
return;
}
if (radii.length === 1 && radii[0] === 0) {
return this.rect(x, y, width, height);
}
// set the corners
// tl = top left radius
// tr = top right radius
// br = bottom right radius
// bl = bottom left radius
var minRadius = Math.min(width, height) / 2;
var tr, br, bl;
var tl = (tr = br = bl = Math.min(minRadius, radii[0]));
if (radii.length === 2) {
tr = bl = Math.min(minRadius, radii[1]);
}
if (radii.length === 3) {
tr = bl = Math.min(minRadius, radii[1]);
br = Math.min(minRadius, radii[2]);
}
if (radii.length === 4) {
tr = Math.min(minRadius, radii[1]);
br = Math.min(minRadius, radii[2]);
bl = Math.min(minRadius, radii[3]);
}
// begin with closing current path
// this.closePath();
// let's draw the rounded rectangle
this.moveTo(x, y + height - bl);
this.arcTo(x, y, x + tl, y, tl);
this.arcTo(x + width, y, x + width, y + tr, tr);
this.arcTo(x + width, y + height, x + width - br, y + height, br);
this.arcTo(x, y + height, x, y + height - bl, bl);
// and move to rects control point for further path drawing
this.moveTo(x, y);
}
/**
* Polyfills roundRect on CanvasRenderingContext2D and Path2D
* @param {WindowLike} window - window like object containing both CanvasRenderingContext2D and Path2D constructor
*/
function polyfillRoundRect(window) {
if (!window || !window.CanvasRenderingContext2D)
return;
var CanvasRenderingContext2D = window.CanvasRenderingContext2D, Path2D = window.Path2D;
// polyfill unsupported roundRect for e.g. firefox https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/roundRect#browser_compatibility
if (CanvasRenderingContext2D && !CanvasRenderingContext2D.prototype.roundRect) {
CanvasRenderingContext2D.prototype.roundRect = roundRect;
}
if (Path2D && !Path2D.prototype.roundRect) {
Path2D.prototype.roundRect = roundRect;
}
}
exports.Path2D = Path2D;
exports.parsePath = parsePath;
exports.polyfillPath2D = polyfillPath2D;
exports.polyfillRoundRect = polyfillRoundRect;
(function () {
'use strict';
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
var ARG_LENGTH = {
a: 7,
c: 6,
h: 1,
l: 2,
m: 2,
q: 4,
s: 4,
t: 2,
v: 1,
z: 0
};
var SEGMENT_PATTERN = /([astvzqmhlc])([^astvzqmhlc]*)/gi;
var NUMBER = /-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;
function parseValues(args) {
var numbers = args.match(NUMBER);
return numbers ? numbers.map(Number) : [];
}
/**
* parse an svg path data string. Generates an Array
* of commands where each command is an Array of the
* form `[command, arg1, arg2, ...]`
*
* https://www.w3.org/TR/SVG/paths.html#PathDataGeneralInformation
* @ignore
*
* @param {string} path
* @returns {array}
*/
function parsePath(path) {
var data = [];
var p = String(path).trim();
// A path data segment (if there is one) must begin with a "moveto" command
if (p[0] !== "M" && p[0] !== "m") {
return data;
}
p.replace(SEGMENT_PATTERN, function (_, command, args) {
var theArgs = parseValues(args);
var type = command.toLowerCase();
var theCommand = command;
// overloaded moveTo
if (type === "m" && theArgs.length > 2) {
data.push(__spreadArray([theCommand], theArgs.splice(0, 2), true));
type = "l";
theCommand = theCommand === "m" ? "l" : "L";
}
// Ignore invalid commands
if (theArgs.length < ARG_LENGTH[type]) {
return "";
}
data.push(__spreadArray([theCommand], theArgs.splice(0, ARG_LENGTH[type]), true));
// The command letter can be eliminated on subsequent commands if the
// same command is used multiple times in a row (e.g., you can drop the
// second "L" in "M 100 200 L 200 100 L -100 -200" and use
// "M 100 200 L 200 100 -100 -200" instead).
while (theArgs.length >= ARG_LENGTH[type] && theArgs.length && ARG_LENGTH[type]) {
data.push(__spreadArray([theCommand], theArgs.splice(0, ARG_LENGTH[type]), true));
}
return "";
});
return data;
}
function rotatePoint(point, angle) {
var nx = point.x * Math.cos(angle) - point.y * Math.sin(angle);
var ny = point.y * Math.cos(angle) + point.x * Math.sin(angle);
point.x = nx;
point.y = ny;
}
function translatePoint(point, dx, dy) {
point.x += dx;
point.y += dy;
}
function scalePoint(point, s) {
point.x *= s;
point.y *= s;
}
/**
* Implements a browser's Path2D api
*/
var Path2D = /** @class */ (function () {
function Path2D(path) {
var _a;
this.commands = [];
if (path && path instanceof Path2D) {
(_a = this.commands).push.apply(_a, path.commands);
}
else if (path) {
this.commands = parsePath(path);
}
}
Path2D.prototype.addPath = function (path) {
var _a;
if (path && path instanceof Path2D) {
(_a = this.commands).push.apply(_a, path.commands);
}
};
Path2D.prototype.moveTo = function (x, y) {
this.commands.push(["M", x, y]);
};
Path2D.prototype.lineTo = function (x, y) {
this.commands.push(["L", x, y]);
};
Path2D.prototype.arc = function (x, y, r, start, end, ccw) {
this.commands.push(["AC", x, y, r, start, end, !!ccw]);
};
Path2D.prototype.arcTo = function (x1, y1, x2, y2, r) {
this.commands.push(["AT", x1, y1, x2, y2, r]);
};
Path2D.prototype.ellipse = function (x, y, rx, ry, angle, start, end, ccw) {
this.commands.push(["E", x, y, rx, ry, angle, start, end, !!ccw]);
};
Path2D.prototype.closePath = function () {
this.commands.push(["Z"]);
};
Path2D.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
this.commands.push(["C", cp1x, cp1y, cp2x, cp2y, x, y]);
};
Path2D.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
this.commands.push(["Q", cpx, cpy, x, y]);
};
Path2D.prototype.rect = function (x, y, width, height) {
this.commands.push(["R", x, y, width, height]);
};
Path2D.prototype.roundRect = function (x, y, width, height, radii) {
if (typeof radii === "undefined") {
this.commands.push(["RR", x, y, width, height, 0]);
}
else {
this.commands.push(["RR", x, y, width, height, radii]);
}
};
return Path2D;
}());
function buildPath(ctx, commands) {
var x = 0;
var y = 0;
var endAngle;
var startAngle;
var largeArcFlag;
var sweepFlag;
var endPoint;
var midPoint;
var angle;
var lambda;
var t1;
var t2;
var x1;
var y1;
var r;
var rx;
var ry;
var w;
var h;
var pathType;
var centerPoint;
var ccw;
var radii;
var cpx = null;
var cpy = null;
var qcpx = null;
var qcpy = null;
var startPoint = null;
var currentPoint = null;
ctx.beginPath();
for (var i = 0; i < commands.length; ++i) {
pathType = commands[i][0];
// Reset control point if command is not cubic
if (pathType !== "S" && pathType !== "s" && pathType !== "C" && pathType !== "c") {
cpx = null;
cpy = null;
}
if (pathType !== "T" && pathType !== "t" && pathType !== "Q" && pathType !== "q") {
qcpx = null;
qcpy = null;
}
var c = void 0;
switch (pathType) {
case "m":
case "M":
c = commands[i];
if (pathType === "m") {
x += c[1];
y += c[2];
}
else {
x = c[1];
y = c[2];
}
if (pathType === "M" || !startPoint) {
startPoint = { x: x, y: y };
}
ctx.moveTo(x, y);
break;
case "l":
c = commands[i];
x += c[1];
y += c[2];
ctx.lineTo(x, y);
break;
case "L":
c = commands[i];
x = c[1];
y = c[2];
ctx.lineTo(x, y);
break;
case "H":
c = commands[i];
x = c[1];
ctx.lineTo(x, y);
break;
case "h":
c = commands[i];
x += c[1];
ctx.lineTo(x, y);
break;
case "V":
c = commands[i];
y = c[1];
ctx.lineTo(x, y);
break;
case "v":
c = commands[i];
y += c[1];
ctx.lineTo(x, y);
break;
case "a":
case "A":
c = commands[i];
if (currentPoint === null) {
throw new Error("This should never happen");
}
if (pathType === "a") {
x += c[6];
y += c[7];
}
else {
x = c[6];
y = c[7];
}
rx = c[1]; // rx
ry = c[2]; // ry
angle = (c[3] * Math.PI) / 180;
largeArcFlag = !!c[4];
sweepFlag = !!c[5];
endPoint = { x: x, y: y };
// https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
midPoint = {
x: (currentPoint.x - endPoint.x) / 2,
y: (currentPoint.y - endPoint.y) / 2
};
rotatePoint(midPoint, -angle);
// radius correction
lambda = (midPoint.x * midPoint.x) / (rx * rx) + (midPoint.y * midPoint.y) / (ry * ry);
if (lambda > 1) {
lambda = Math.sqrt(lambda);
rx *= lambda;
ry *= lambda;
}
centerPoint = {
x: (rx * midPoint.y) / ry,
y: -(ry * midPoint.x) / rx
};
t1 = rx * rx * ry * ry;
t2 = rx * rx * midPoint.y * midPoint.y + ry * ry * midPoint.x * midPoint.x;
if (sweepFlag !== largeArcFlag) {
scalePoint(centerPoint, Math.sqrt((t1 - t2) / t2) || 0);
}
else {
scalePoint(centerPoint, -Math.sqrt((t1 - t2) / t2) || 0);
}
startAngle = Math.atan2((midPoint.y - centerPoint.y) / ry, (midPoint.x - centerPoint.x) / rx);
endAngle = Math.atan2(-(midPoint.y + centerPoint.y) / ry, -(midPoint.x + centerPoint.x) / rx);
rotatePoint(centerPoint, angle);
translatePoint(centerPoint, (endPoint.x + currentPoint.x) / 2, (endPoint.y + currentPoint.y) / 2);
ctx.save();
ctx.translate(centerPoint.x, centerPoint.y);
ctx.rotate(angle);
ctx.scale(rx, ry);
ctx.arc(0, 0, 1, startAngle, endAngle, !sweepFlag);
ctx.restore();
break;
case "C":
c = commands[i];
cpx = c[3]; // Last control point
cpy = c[4];
x = c[5];
y = c[6];
ctx.bezierCurveTo(c[1], c[2], cpx, cpy, x, y);
break;
case "c":
c = commands[i];
ctx.bezierCurveTo(c[1] + x, c[2] + y, c[3] + x, c[4] + y, c[5] + x, c[6] + y);
cpx = c[3] + x; // Last control point
cpy = c[4] + y;
x += c[5];
y += c[6];
break;
case "S":
c = commands[i];
if (cpx === null || cpy === null) {
cpx = x;
cpy = y;
}
ctx.bezierCurveTo(2 * x - cpx, 2 * y - cpy, c[1], c[2], c[3], c[4]);
cpx = c[1]; // last control point
cpy = c[2];
x = c[3];
y = c[4];
break;
case "s":
c = commands[i];
if (cpx === null || cpy === null) {
cpx = x;
cpy = y;
}
ctx.bezierCurveTo(2 * x - cpx, 2 * y - cpy, c[1] + x, c[2] + y, c[3] + x, c[4] + y);
cpx = c[1] + x; // last control point
cpy = c[2] + y;
x += c[3];
y += c[4];
break;
case "Q":
c = commands[i];
qcpx = c[1]; // last control point
qcpy = c[2];
x = c[3];
y = c[4];
ctx.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "q":
c = commands[i];
qcpx = c[1] + x; // last control point
qcpy = c[2] + y;
x += c[3];
y += c[4];
ctx.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "T":
c = commands[i];
if (qcpx === null || qcpy === null) {
qcpx = x;
qcpy = y;
}
qcpx = 2 * x - qcpx; // last control point
qcpy = 2 * y - qcpy;
x = c[1];
y = c[2];
ctx.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "t":
c = commands[i];
if (qcpx === null || qcpy === null) {
qcpx = x;
qcpy = y;
}
qcpx = 2 * x - qcpx; // last control point
qcpy = 2 * y - qcpy;
x += c[1];
y += c[2];
ctx.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "z":
case "Z":
if (startPoint) {
x = startPoint.x;
y = startPoint.y;
}
startPoint = null;
ctx.closePath();
break;
case "AC": // arc
c = commands[i];
x = c[1];
y = c[2];
r = c[3];
startAngle = c[4];
endAngle = c[5];
ccw = c[6];
ctx.arc(x, y, r, startAngle, endAngle, ccw);
break;
case "AT": // arcTo
c = commands[i];
x1 = c[1];
y1 = c[2];
x = c[3];
y = c[4];
r = c[5];
ctx.arcTo(x1, y1, x, y, r);
break;
case "E": // ellipse
c = commands[i];
x = c[1];
y = c[2];
rx = c[3];
ry = c[4];
angle = c[5];
startAngle = c[6];
endAngle = c[7];
ccw = c[8];
ctx.save();
ctx.translate(x, y);
ctx.rotate(angle);
ctx.scale(rx, ry);
ctx.arc(0, 0, 1, startAngle, endAngle, ccw);
ctx.restore();
break;
case "R": // rect
c = commands[i];
x = c[1];
y = c[2];
w = c[3];
h = c[4];
startPoint = { x: x, y: y };
ctx.rect(x, y, w, h);
break;
case "RR": // roundedRect
c = commands[i];
x = c[1];
y = c[2];
w = c[3];
h = c[4];
radii = c[5];
startPoint = { x: x, y: y };
ctx.roundRect(x, y, w, h, radii);
break;
}
if (!currentPoint) {
currentPoint = { x: x, y: y };
}
else {
currentPoint.x = x;
currentPoint.y = y;
}
}
}
/**
* Polyfills CanvasRenderingContext2D stroke, fill and isPointInPath so that they support Path2D objects.
* @param {WindowLike} window - window like object containing a CanvasRenderingContext2D constructor
*/
function polyfillPath2D(window) {
if (!window || !window.CanvasRenderingContext2D || window.Path2D)
return;
var CanvasRenderingContext2D = window.CanvasRenderingContext2D;
/* eslint-disable @typescript-eslint/unbound-method */
// setting unbound functions here. Make sure this is set in function call later
var cFill = CanvasRenderingContext2D.prototype.fill;
var cStroke = CanvasRenderingContext2D.prototype.stroke;
var cIsPointInPath = CanvasRenderingContext2D.prototype.isPointInPath;
/* eslint-enable @typescript-eslint/unbound-method */
CanvasRenderingContext2D.prototype.fill = function fill() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (args[0] instanceof Path2D) {
var path = args[0];
var fillRule = args[1] || "nonzero";
buildPath(this, path.commands);
cFill.apply(this, [fillRule]);
}
else {
var fillRule = args[0] || "nonzero";
return cFill.apply(this, [fillRule]);
}
};
CanvasRenderingContext2D.prototype.stroke = function stroke(path) {
if (path) {
buildPath(this, path.commands);
}
cStroke.apply(this);
};
CanvasRenderingContext2D.prototype.isPointInPath = function isPointInPath() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (args[0] instanceof Path2D) {
// first argument is a Path2D object
var path = args[0];
var x = args[1];
var y = args[2];
var fillRule = args[3] || "nonzero";
buildPath(this, path.commands);
return cIsPointInPath.apply(this, [x, y, fillRule]);
}
else {
return cIsPointInPath.apply(this, args);
}
};
window.Path2D = Path2D;
}
function roundRect(x, y, width, height, radii) {
var _this = this;
if (radii === void 0) { radii = 0; }
if (typeof radii === "number") {
// eslint-disable-next-line no-param-reassign
radii = [radii];
}
// check for range error
if (Array.isArray(radii)) {
if (radii.length === 0 || radii.length > 4) {
throw new RangeError("Failed to execute 'roundRect' on '".concat(this.constructor.name, "': ").concat(radii.length, " radii provided. Between one and four radii are necessary."));
}
radii.forEach(function (v) {
if (v < 0) {
throw new RangeError("Failed to execute 'roundRect' on '".concat(_this.constructor.name, "': Radius value ").concat(v, " is negative."));
}
});
}
else {
return;
}
if (radii.length === 1 && radii[0] === 0) {
return this.rect(x, y, width, height);
}
// set the corners
// tl = top left radius
// tr = top right radius
// br = bottom right radius
// bl = bottom left radius
var minRadius = Math.min(width, height) / 2;
var tr, br, bl;
var tl = (tr = br = bl = Math.min(minRadius, radii[0]));
if (radii.length === 2) {
tr = bl = Math.min(minRadius, radii[1]);
}
if (radii.length === 3) {
tr = bl = Math.min(minRadius, radii[1]);
br = Math.min(minRadius, radii[2]);
}
if (radii.length === 4) {
tr = Math.min(minRadius, radii[1]);
br = Math.min(minRadius, radii[2]);
bl = Math.min(minRadius, radii[3]);
}
// begin with closing current path
// this.closePath();
// let's draw the rounded rectangle
this.moveTo(x, y + height - bl);
this.arcTo(x, y, x + tl, y, tl);
this.arcTo(x + width, y, x + width, y + tr, tr);
this.arcTo(x + width, y + height, x + width - br, y + height, br);
this.arcTo(x, y + height, x, y + height - bl, bl);
// and move to rects control point for further path drawing
this.moveTo(x, y);
}
/**
* Polyfills roundRect on CanvasRenderingContext2D and Path2D
* @param {WindowLike} window - window like object containing both CanvasRenderingContext2D and Path2D constructor
*/
function polyfillRoundRect(window) {
if (!window || !window.CanvasRenderingContext2D)
return;
var CanvasRenderingContext2D = window.CanvasRenderingContext2D, Path2D = window.Path2D;
// polyfill unsupported roundRect for e.g. firefox https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/roundRect#browser_compatibility
if (CanvasRenderingContext2D && !CanvasRenderingContext2D.prototype.roundRect) {
CanvasRenderingContext2D.prototype.roundRect = roundRect;
}
if (Path2D && !Path2D.prototype.roundRect) {
Path2D.prototype.roundRect = roundRect;
}
}
polyfillPath2D(window);
polyfillRoundRect(window);
})();
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
var ARG_LENGTH = {
a: 7,
c: 6,
h: 1,
l: 2,
m: 2,
q: 4,
s: 4,
t: 2,
v: 1,
z: 0
};
var SEGMENT_PATTERN = /([astvzqmhlc])([^astvzqmhlc]*)/gi;
var NUMBER = /-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;
function parseValues(args) {
var numbers = args.match(NUMBER);
return numbers ? numbers.map(Number) : [];
}
/**
* parse an svg path data string. Generates an Array
* of commands where each command is an Array of the
* form `[command, arg1, arg2, ...]`
*
* https://www.w3.org/TR/SVG/paths.html#PathDataGeneralInformation
* @ignore
*
* @param {string} path
* @returns {array}
*/
function parsePath(path) {
var data = [];
var p = String(path).trim();
// A path data segment (if there is one) must begin with a "moveto" command
if (p[0] !== "M" && p[0] !== "m") {
return data;
}
p.replace(SEGMENT_PATTERN, function (_, command, args) {
var theArgs = parseValues(args);
var type = command.toLowerCase();
var theCommand = command;
// overloaded moveTo
if (type === "m" && theArgs.length > 2) {
data.push(__spreadArray([theCommand], theArgs.splice(0, 2), true));
type = "l";
theCommand = theCommand === "m" ? "l" : "L";
}
// Ignore invalid commands
if (theArgs.length < ARG_LENGTH[type]) {
return "";
}
data.push(__spreadArray([theCommand], theArgs.splice(0, ARG_LENGTH[type]), true));
// The command letter can be eliminated on subsequent commands if the
// same command is used multiple times in a row (e.g., you can drop the
// second "L" in "M 100 200 L 200 100 L -100 -200" and use
// "M 100 200 L 200 100 -100 -200" instead).
while (theArgs.length >= ARG_LENGTH[type] && theArgs.length && ARG_LENGTH[type]) {
data.push(__spreadArray([theCommand], theArgs.splice(0, ARG_LENGTH[type]), true));
}
return "";
});
return data;
}
function rotatePoint(point, angle) {
var nx = point.x * Math.cos(angle) - point.y * Math.sin(angle);
var ny = point.y * Math.cos(angle) + point.x * Math.sin(angle);
point.x = nx;
point.y = ny;
}
function translatePoint(point, dx, dy) {
point.x += dx;
point.y += dy;
}
function scalePoint(point, s) {
point.x *= s;
point.y *= s;
}
/**
* Implements a browser's Path2D api
*/
var Path2D = /** @class */ (function () {
function Path2D(path) {
var _a;
this.commands = [];
if (path && path instanceof Path2D) {
(_a = this.commands).push.apply(_a, path.commands);
}
else if (path) {
this.commands = parsePath(path);
}
}
Path2D.prototype.addPath = function (path) {
var _a;
if (path && path instanceof Path2D) {
(_a = this.commands).push.apply(_a, path.commands);
}
};
Path2D.prototype.moveTo = function (x, y) {
this.commands.push(["M", x, y]);
};
Path2D.prototype.lineTo = function (x, y) {
this.commands.push(["L", x, y]);
};
Path2D.prototype.arc = function (x, y, r, start, end, ccw) {
this.commands.push(["AC", x, y, r, start, end, !!ccw]);
};
Path2D.prototype.arcTo = function (x1, y1, x2, y2, r) {
this.commands.push(["AT", x1, y1, x2, y2, r]);
};
Path2D.prototype.ellipse = function (x, y, rx, ry, angle, start, end, ccw) {
this.commands.push(["E", x, y, rx, ry, angle, start, end, !!ccw]);
};
Path2D.prototype.closePath = function () {
this.commands.push(["Z"]);
};
Path2D.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
this.commands.push(["C", cp1x, cp1y, cp2x, cp2y, x, y]);
};
Path2D.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
this.commands.push(["Q", cpx, cpy, x, y]);
};
Path2D.prototype.rect = function (x, y, width, height) {
this.commands.push(["R", x, y, width, height]);
};
Path2D.prototype.roundRect = function (x, y, width, height, radii) {
if (typeof radii === "undefined") {
this.commands.push(["RR", x, y, width, height, 0]);
}
else {
this.commands.push(["RR", x, y, width, height, radii]);
}
};
return Path2D;
}());
function buildPath(ctx, commands) {
var x = 0;
var y = 0;
var endAngle;
var startAngle;
var largeArcFlag;
var sweepFlag;
var endPoint;
var midPoint;
var angle;
var lambda;
var t1;
var t2;
var x1;
var y1;
var r;
var rx;
var ry;
var w;
var h;
var pathType;
var centerPoint;
var ccw;
var radii;
var cpx = null;
var cpy = null;
var qcpx = null;
var qcpy = null;
var startPoint = null;
var currentPoint = null;
ctx.beginPath();
for (var i = 0; i < commands.length; ++i) {
pathType = commands[i][0];
// Reset control point if command is not cubic
if (pathType !== "S" && pathType !== "s" && pathType !== "C" && pathType !== "c") {
cpx = null;
cpy = null;
}
if (pathType !== "T" && pathType !== "t" && pathType !== "Q" && pathType !== "q") {
qcpx = null;
qcpy = null;
}
var c = void 0;
switch (pathType) {
case "m":
case "M":
c = commands[i];
if (pathType === "m") {
x += c[1];
y += c[2];
}
else {
x = c[1];
y = c[2];
}
if (pathType === "M" || !startPoint) {
startPoint = { x: x, y: y };
}
ctx.moveTo(x, y);
break;
case "l":
c = commands[i];
x += c[1];
y += c[2];
ctx.lineTo(x, y);
break;
case "L":
c = commands[i];
x = c[1];
y = c[2];
ctx.lineTo(x, y);
break;
case "H":
c = commands[i];
x = c[1];
ctx.lineTo(x, y);
break;
case "h":
c = commands[i];
x += c[1];
ctx.lineTo(x, y);
break;
case "V":
c = commands[i];
y = c[1];
ctx.lineTo(x, y);
break;
case "v":
c = commands[i];
y += c[1];
ctx.lineTo(x, y);
break;
case "a":
case "A":
c = commands[i];
if (currentPoint === null) {
throw new Error("This should never happen");
}
if (pathType === "a") {
x += c[6];
y += c[7];
}
else {
x = c[6];
y = c[7];
}
rx = c[1]; // rx
ry = c[2]; // ry
angle = (c[3] * Math.PI) / 180;
largeArcFlag = !!c[4];
sweepFlag = !!c[5];
endPoint = { x: x, y: y };
// https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
midPoint = {
x: (currentPoint.x - endPoint.x) / 2,
y: (currentPoint.y - endPoint.y) / 2
};
rotatePoint(midPoint, -angle);
// radius correction
lambda = (midPoint.x * midPoint.x) / (rx * rx) + (midPoint.y * midPoint.y) / (ry * ry);
if (lambda > 1) {
lambda = Math.sqrt(lambda);
rx *= lambda;
ry *= lambda;
}
centerPoint = {
x: (rx * midPoint.y) / ry,
y: -(ry * midPoint.x) / rx
};
t1 = rx * rx * ry * ry;
t2 = rx * rx * midPoint.y * midPoint.y + ry * ry * midPoint.x * midPoint.x;
if (sweepFlag !== largeArcFlag) {
scalePoint(centerPoint, Math.sqrt((t1 - t2) / t2) || 0);
}
else {
scalePoint(centerPoint, -Math.sqrt((t1 - t2) / t2) || 0);
}
startAngle = Math.atan2((midPoint.y - centerPoint.y) / ry, (midPoint.x - centerPoint.x) / rx);
endAngle = Math.atan2(-(midPoint.y + centerPoint.y) / ry, -(midPoint.x + centerPoint.x) / rx);
rotatePoint(centerPoint, angle);
translatePoint(centerPoint, (endPoint.x + currentPoint.x) / 2, (endPoint.y + currentPoint.y) / 2);
ctx.save();
ctx.translate(centerPoint.x, centerPoint.y);
ctx.rotate(angle);
ctx.scale(rx, ry);
ctx.arc(0, 0, 1, startAngle, endAngle, !sweepFlag);
ctx.restore();
break;
case "C":
c = commands[i];
cpx = c[3]; // Last control point
cpy = c[4];
x = c[5];
y = c[6];
ctx.bezierCurveTo(c[1], c[2], cpx, cpy, x, y);
break;
case "c":
c = commands[i];
ctx.bezierCurveTo(c[1] + x, c[2] + y, c[3] + x, c[4] + y, c[5] + x, c[6] + y);
cpx = c[3] + x; // Last control point
cpy = c[4] + y;
x += c[5];
y += c[6];
break;
case "S":
c = commands[i];
if (cpx === null || cpy === null) {
cpx = x;
cpy = y;
}
ctx.bezierCurveTo(2 * x - cpx, 2 * y - cpy, c[1], c[2], c[3], c[4]);
cpx = c[1]; // last control point
cpy = c[2];
x = c[3];
y = c[4];
break;
case "s":
c = commands[i];
if (cpx === null || cpy === null) {
cpx = x;
cpy = y;
}
ctx.bezierCurveTo(2 * x - cpx, 2 * y - cpy, c[1] + x, c[2] + y, c[3] + x, c[4] + y);
cpx = c[1] + x; // last control point
cpy = c[2] + y;
x += c[3];
y += c[4];
break;
case "Q":
c = commands[i];
qcpx = c[1]; // last control point
qcpy = c[2];
x = c[3];
y = c[4];
ctx.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "q":
c = commands[i];
qcpx = c[1] + x; // last control point
qcpy = c[2] + y;
x += c[3];
y += c[4];
ctx.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "T":
c = commands[i];
if (qcpx === null || qcpy === null) {
qcpx = x;
qcpy = y;
}
qcpx = 2 * x - qcpx; // last control point
qcpy = 2 * y - qcpy;
x = c[1];
y = c[2];
ctx.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "t":
c = commands[i];
if (qcpx === null || qcpy === null) {
qcpx = x;
qcpy = y;
}
qcpx = 2 * x - qcpx; // last control point
qcpy = 2 * y - qcpy;
x += c[1];
y += c[2];
ctx.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "z":
case "Z":
if (startPoint) {
x = startPoint.x;
y = startPoint.y;
}
startPoint = null;
ctx.closePath();
break;
case "AC": // arc
c = commands[i];
x = c[1];
y = c[2];
r = c[3];
startAngle = c[4];
endAngle = c[5];
ccw = c[6];
ctx.arc(x, y, r, startAngle, endAngle, ccw);
break;
case "AT": // arcTo
c = commands[i];
x1 = c[1];
y1 = c[2];
x = c[3];
y = c[4];
r = c[5];
ctx.arcTo(x1, y1, x, y, r);
break;
case "E": // ellipse
c = commands[i];
x = c[1];
y = c[2];
rx = c[3];
ry = c[4];
angle = c[5];
startAngle = c[6];
endAngle = c[7];
ccw = c[8];
ctx.save();
ctx.translate(x, y);
ctx.rotate(angle);
ctx.scale(rx, ry);
ctx.arc(0, 0, 1, startAngle, endAngle, ccw);
ctx.restore();
break;
case "R": // rect
c = commands[i];
x = c[1];
y = c[2];
w = c[3];
h = c[4];
startPoint = { x: x, y: y };
ctx.rect(x, y, w, h);
break;
case "RR": // roundedRect
c = commands[i];
x = c[1];
y = c[2];
w = c[3];
h = c[4];
radii = c[5];
startPoint = { x: x, y: y };
ctx.roundRect(x, y, w, h, radii);
break;
}
if (!currentPoint) {
currentPoint = { x: x, y: y };
}
else {
currentPoint.x = x;
currentPoint.y = y;
}
}
}
/**
* Polyfills CanvasRenderingContext2D stroke, fill and isPointInPath so that they support Path2D objects.
* @param {WindowLike} window - window like object containing a CanvasRenderingContext2D constructor
*/
function polyfillPath2D(window) {
if (!window || !window.CanvasRenderingContext2D || window.Path2D)
return;
var CanvasRenderingContext2D = window.CanvasRenderingContext2D;
/* eslint-disable @typescript-eslint/unbound-method */
// setting unbound functions here. Make sure this is set in function call later
var cFill = CanvasRenderingContext2D.prototype.fill;
var cStroke = CanvasRenderingContext2D.prototype.stroke;
var cIsPointInPath = CanvasRenderingContext2D.prototype.isPointInPath;
/* eslint-enable @typescript-eslint/unbound-method */
CanvasRenderingContext2D.prototype.fill = function fill() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (args[0] instanceof Path2D) {
var path = args[0];
var fillRule = args[1] || "nonzero";
buildPath(this, path.commands);
cFill.apply(this, [fillRule]);
}
else {
var fillRule = args[0] || "nonzero";
return cFill.apply(this, [fillRule]);
}
};
CanvasRenderingContext2D.prototype.stroke = function stroke(path) {
if (path) {
buildPath(this, path.commands);
}
cStroke.apply(this);
};
CanvasRenderingContext2D.prototype.isPointInPath = function isPointInPath() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (args[0] instanceof Path2D) {
// first argument is a Path2D object
var path = args[0];
var x = args[1];
var y = args[2];
var fillRule = args[3] || "nonzero";
buildPath(this, path.commands);
return cIsPointInPath.apply(this, [x, y, fillRule]);
}
else {
return cIsPointInPath.apply(this, args);
}
};
window.Path2D = Path2D;
}
function roundRect(x, y, width, height, radii) {
var _this = this;
if (radii === void 0) { radii = 0; }
if (typeof radii === "number") {
// eslint-disable-next-line no-param-reassign
radii = [radii];
}
// check for range error
if (Array.isArray(radii)) {
if (radii.length === 0 || radii.length > 4) {
throw new RangeError("Failed to execute 'roundRect' on '".concat(this.constructor.name, "': ").concat(radii.length, " radii provided. Between one and four radii are necessary."));
}
radii.forEach(function (v) {
if (v < 0) {
throw new RangeError("Failed to execute 'roundRect' on '".concat(_this.constructor.name, "': Radius value ").concat(v, " is negative."));
}
});
}
else {
return;
}
if (radii.length === 1 && radii[0] === 0) {
return this.rect(x, y, width, height);
}
// set the corners
// tl = top left radius
// tr = top right radius
// br = bottom right radius
// bl = bottom left radius
var minRadius = Math.min(width, height) / 2;
var tr, br, bl;
var tl = (tr = br = bl = Math.min(minRadius, radii[0]));
if (radii.length === 2) {
tr = bl = Math.min(minRadius, radii[1]);
}
if (radii.length === 3) {
tr = bl = Math.min(minRadius, radii[1]);
br = Math.min(minRadius, radii[2]);
}
if (radii.length === 4) {
tr = Math.min(minRadius, radii[1]);
br = Math.min(minRadius, radii[2]);
bl = Math.min(minRadius, radii[3]);
}
// begin with closing current path
// this.closePath();
// let's draw the rounded rectangle
this.moveTo(x, y + height - bl);
this.arcTo(x, y, x + tl, y, tl);
this.arcTo(x + width, y, x + width, y + tr, tr);
this.arcTo(x + width, y + height, x + width - br, y + height, br);
this.arcTo(x, y + height, x, y + height - bl, bl);
// and move to rects control point for further path drawing
this.moveTo(x, y);
}
/**
* Polyfills roundRect on CanvasRenderingContext2D and Path2D
* @param {WindowLike} window - window like object containing both CanvasRenderingContext2D and Path2D constructor
*/
function polyfillRoundRect(window) {
if (!window || !window.CanvasRenderingContext2D)
return;
var CanvasRenderingContext2D = window.CanvasRenderingContext2D, Path2D = window.Path2D;
// polyfill unsupported roundRect for e.g. firefox https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/roundRect#browser_compatibility
if (CanvasRenderingContext2D && !CanvasRenderingContext2D.prototype.roundRect) {
CanvasRenderingContext2D.prototype.roundRect = roundRect;
}
if (Path2D && !Path2D.prototype.roundRect) {
Path2D.prototype.roundRect = roundRect;
}
}
export { Path2D, parsePath, polyfillPath2D, polyfillRoundRect };
!function(){"use strict";function t(t,e,n){if(n||2===arguments.length)for(var a,o=0,r=e.length;o<r;o++)!a&&o in e||(a||(a=Array.prototype.slice.call(e,0,o)),a[o]=e[o]);return t.concat(a||Array.prototype.slice.call(e))}var e={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},n=/([astvzqmhlc])([^astvzqmhlc]*)/gi,a=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;function o(o){var r=[],s=String(o).trim();return"M"!==s[0]&&"m"!==s[0]||s.replace(n,(function(n,o,s){var c=function(t){var e=t.match(a);return e?e.map(Number):[]}(s),i=o.toLowerCase(),u=o;if("m"===i&&c.length>2&&(r.push(t([u],c.splice(0,2),!0)),i="l",u="m"===u?"l":"L"),c.length<e[i])return"";for(r.push(t([u],c.splice(0,e[i]),!0));c.length>=e[i]&&c.length&&e[i];)r.push(t([u],c.splice(0,e[i]),!0));return""})),r}function r(t,e){var n=t.x*Math.cos(e)-t.y*Math.sin(e),a=t.y*Math.cos(e)+t.x*Math.sin(e);t.x=n,t.y=a}function s(t,e){t.x*=e,t.y*=e}var c=function(){function t(e){var n;this.commands=[],e&&e instanceof t?(n=this.commands).push.apply(n,e.commands):e&&(this.commands=o(e))}return t.prototype.addPath=function(e){var n;e&&e instanceof t&&(n=this.commands).push.apply(n,e.commands)},t.prototype.moveTo=function(t,e){this.commands.push(["M",t,e])},t.prototype.lineTo=function(t,e){this.commands.push(["L",t,e])},t.prototype.arc=function(t,e,n,a,o,r){this.commands.push(["AC",t,e,n,a,o,!!r])},t.prototype.arcTo=function(t,e,n,a,o){this.commands.push(["AT",t,e,n,a,o])},t.prototype.ellipse=function(t,e,n,a,o,r,s,c){this.commands.push(["E",t,e,n,a,o,r,s,!!c])},t.prototype.closePath=function(){this.commands.push(["Z"])},t.prototype.bezierCurveTo=function(t,e,n,a,o,r){this.commands.push(["C",t,e,n,a,o,r])},t.prototype.quadraticCurveTo=function(t,e,n,a){this.commands.push(["Q",t,e,n,a])},t.prototype.rect=function(t,e,n,a){this.commands.push(["R",t,e,n,a])},t.prototype.roundRect=function(t,e,n,a,o){void 0===o?this.commands.push(["RR",t,e,n,a,0]):this.commands.push(["RR",t,e,n,a,o])},t}();function i(t,e){var n,a,o,c,i,u,h,l,p,m,y,d,f,v,x,T,b,g,C,k,R,M,q,w,z=0,P=0,A=null,D=null,E=null,L=null,I=null,Q=null;t.beginPath();for(var S=0;S<e.length;++S){"S"!==(g=e[S][0])&&"s"!==g&&"C"!==g&&"c"!==g&&(A=null,D=null),"T"!==g&&"t"!==g&&"Q"!==g&&"q"!==g&&(E=null,L=null);var F=void 0;switch(g){case"m":case"M":F=e[S],"m"===g?(z+=F[1],P+=F[2]):(z=F[1],P=F[2]),"M"!==g&&I||(I={x:z,y:P}),t.moveTo(z,P);break;case"l":z+=(F=e[S])[1],P+=F[2],t.lineTo(z,P);break;case"L":z=(F=e[S])[1],P=F[2],t.lineTo(z,P);break;case"H":z=(F=e[S])[1],t.lineTo(z,P);break;case"h":z+=(F=e[S])[1],t.lineTo(z,P);break;case"V":P=(F=e[S])[1],t.lineTo(z,P);break;case"v":P+=(F=e[S])[1],t.lineTo(z,P);break;case"a":case"A":if(F=e[S],null===Q)throw new Error("This should never happen");"a"===g?(z+=F[6],P+=F[7]):(z=F[6],P=F[7]),v=F[1],x=F[2],h=F[3]*Math.PI/180,o=!!F[4],c=!!F[5],i={x:z,y:P},r(u={x:(Q.x-i.x)/2,y:(Q.y-i.y)/2},-h),(l=u.x*u.x/(v*v)+u.y*u.y/(x*x))>1&&(v*=l=Math.sqrt(l),x*=l),p=v*v*x*x,m=v*v*u.y*u.y+x*x*u.x*u.x,s(C={x:v*u.y/x,y:-x*u.x/v},c!==o?Math.sqrt((p-m)/m)||0:-Math.sqrt((p-m)/m)||0),a=Math.atan2((u.y-C.y)/x,(u.x-C.x)/v),n=Math.atan2(-(u.y+C.y)/x,-(u.x+C.x)/v),r(C,h),M=C,q=(i.x+Q.x)/2,w=(i.y+Q.y)/2,M.x+=q,M.y+=w,t.save(),t.translate(C.x,C.y),t.rotate(h),t.scale(v,x),t.arc(0,0,1,a,n,!c),t.restore();break;case"C":A=(F=e[S])[3],D=F[4],z=F[5],P=F[6],t.bezierCurveTo(F[1],F[2],A,D,z,P);break;case"c":F=e[S],t.bezierCurveTo(F[1]+z,F[2]+P,F[3]+z,F[4]+P,F[5]+z,F[6]+P),A=F[3]+z,D=F[4]+P,z+=F[5],P+=F[6];break;case"S":F=e[S],null!==A&&null!==D||(A=z,D=P),t.bezierCurveTo(2*z-A,2*P-D,F[1],F[2],F[3],F[4]),A=F[1],D=F[2],z=F[3],P=F[4];break;case"s":F=e[S],null!==A&&null!==D||(A=z,D=P),t.bezierCurveTo(2*z-A,2*P-D,F[1]+z,F[2]+P,F[3]+z,F[4]+P),A=F[1]+z,D=F[2]+P,z+=F[3],P+=F[4];break;case"Q":E=(F=e[S])[1],L=F[2],z=F[3],P=F[4],t.quadraticCurveTo(E,L,z,P);break;case"q":E=(F=e[S])[1]+z,L=F[2]+P,z+=F[3],P+=F[4],t.quadraticCurveTo(E,L,z,P);break;case"T":null!==E&&null!==L||(E=z,L=P),E=2*z-E,L=2*P-L,z=(F=e[S])[1],P=F[2],t.quadraticCurveTo(E,L,z,P);break;case"t":null!==E&&null!==L||(E=z,L=P),E=2*z-E,L=2*P-L,z+=(F=e[S])[1],P+=F[2],t.quadraticCurveTo(E,L,z,P);break;case"z":case"Z":I&&(z=I.x,P=I.y),I=null,t.closePath();break;case"AC":z=(F=e[S])[1],P=F[2],f=F[3],a=F[4],n=F[5],k=F[6],t.arc(z,P,f,a,n,k);break;case"AT":y=(F=e[S])[1],d=F[2],z=F[3],P=F[4],f=F[5],t.arcTo(y,d,z,P,f);break;case"E":z=(F=e[S])[1],P=F[2],v=F[3],x=F[4],h=F[5],a=F[6],n=F[7],k=F[8],t.save(),t.translate(z,P),t.rotate(h),t.scale(v,x),t.arc(0,0,1,a,n,k),t.restore();break;case"R":z=(F=e[S])[1],P=F[2],T=F[3],b=F[4],I={x:z,y:P},t.rect(z,P,T,b);break;case"RR":z=(F=e[S])[1],P=F[2],T=F[3],b=F[4],R=F[5],I={x:z,y:P},t.roundRect(z,P,T,b,R)}Q?(Q.x=z,Q.y=P):Q={x:z,y:P}}}function u(t,e,n,a,o){var r=this;if(void 0===o&&(o=0),"number"==typeof o&&(o=[o]),Array.isArray(o)){if(0===o.length||o.length>4)throw new RangeError("Failed to execute 'roundRect' on '".concat(this.constructor.name,"': ").concat(o.length," radii provided. Between one and four radii are necessary."));if(o.forEach((function(t){if(t<0)throw new RangeError("Failed to execute 'roundRect' on '".concat(r.constructor.name,"': Radius value ").concat(t," is negative."))})),1===o.length&&0===o[0])return this.rect(t,e,n,a);var s,c,i,u=Math.min(n,a)/2,h=s=c=i=Math.min(u,o[0]);2===o.length&&(s=i=Math.min(u,o[1])),3===o.length&&(s=i=Math.min(u,o[1]),c=Math.min(u,o[2])),4===o.length&&(s=Math.min(u,o[1]),c=Math.min(u,o[2]),i=Math.min(u,o[3])),this.moveTo(t,e+a-i),this.arcTo(t,e,t+h,e,h),this.arcTo(t+n,e,t+n,e+s,s),this.arcTo(t+n,e+a,t+n-c,e+a,c),this.arcTo(t,e+a,t,e+a-i,i),this.moveTo(t,e)}}!function(t){if(t&&t.CanvasRenderingContext2D&&!t.Path2D){var e=t.CanvasRenderingContext2D,n=e.prototype.fill,a=e.prototype.stroke,o=e.prototype.isPointInPath;e.prototype.fill=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(!(t[0]instanceof c)){o=t[0]||"nonzero";return n.apply(this,[o])}var a=t[0],o=t[1]||"nonzero";i(this,a.commands),n.apply(this,[o])},e.prototype.stroke=function(t){t&&i(this,t.commands),a.apply(this)},e.prototype.isPointInPath=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(t[0]instanceof c){var n=t[0],a=t[1],r=t[2],s=t[3]||"nonzero";return i(this,n.commands),o.apply(this,[a,r,s])}return o.apply(this,t)},t.Path2D=c}}(window),function(t){if(t&&t.CanvasRenderingContext2D){var e=t.CanvasRenderingContext2D,n=t.Path2D;e&&!e.prototype.roundRect&&(e.prototype.roundRect=u),n&&!n.prototype.roundRect&&(n.prototype.roundRect=u)}}(window)}();
+43
-31
{
"name": "path2d-polyfill",
"version": "1.2.3",
"version": "2.0.0-beta.0",
"description": "Polyfills Path2D api for canvas rendering",

@@ -8,4 +8,7 @@ "scripts": {

"start": "rollup -c -w",
"lint": "eslint src test",
"test": "nyc --reporter=html --reporter=text mocha",
"lint": "eslint .",
"check-types": "tsc --noEmit",
"test": "ts-mocha test/*.spec.ts",
"test:watch": "ts-mocha --watch test/*.spec.ts",
"test:coverage": "nyc --reporter=html --reporter=text --reporter=text-summary yarn test",
"format:check": "prettier --check \"./**\"",

@@ -16,8 +19,8 @@ "format:write": "prettier --write \"./**\"",

},
"browser": "dist/path2d-polyfill.min.js",
"module": "dist/path2d-polyfill.esm.js",
"main": "dist/path2d-polyfill.cjs.js",
"files": [
"/dist",
"/src"
"dist"
],
"main": "dist/index.js",
"module": "dist/index.esm.js",
"repository": {

@@ -39,27 +42,36 @@ "type": "git",

"devDependencies": {
"@babel/core": "^7.19.3",
"@babel/preset-env": "^7.19.4",
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@release-it/conventional-changelog": "^5.1.1",
"@rollup/plugin-babel": "^6.0.0",
"@rollup/plugin-commonjs": "^23.0.0",
"chai": "^4.3.6",
"eslint": "^8.25.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"prettier": "^2.7.1",
"release-it": "^15.5.0",
"rollup": "^2.79.1",
"rollup-plugin-livereload": "^2.0.5",
"rollup-plugin-serve": "^2.0.1",
"rollup-plugin-terser": "7.0.2",
"sinon": "^14.0.1",
"sinon-chai": "^3.7.0"
"@babel/core": "7.20.7",
"@babel/preset-env": "7.20.2",
"@commitlint/cli": "17.3.0",
"@commitlint/config-conventional": "17.3.0",
"@release-it/conventional-changelog": "5.1.1",
"@rollup/plugin-terser": "0.2.1",
"@rollup/plugin-typescript": "10.0.1",
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
"@types/sinon": "^10.0.13",
"@types/sinon-chai": "^3.2.9",
"@typescript-eslint/eslint-plugin": "5.48.0",
"@typescript-eslint/parser": "5.48.0",
"chai": "4.3.7",
"eslint": "8.31.0",
"eslint-config-prettier": "8.6.0",
"husky": "8.0.2",
"lint-staged": "13.1.0",
"mocha": "10.2.0",
"nyc": "15.1.0",
"prettier": "2.8.1",
"release-it": "15.6.0",
"rollup": "3.9.1",
"rollup-plugin-livereload": "2.0.5",
"rollup-plugin-serve": "2.0.2",
"sinon": "15.0.1",
"sinon-chai": "3.7.0",
"ts-mocha": "^10.0.0",
"typescript": "^4.9.4"
},
"dependencies": {}
"dependencies": {},
"engines": {
"node": ">=8"
}
}
+50
-13

@@ -5,6 +5,4 @@ # path2d-polyfill

Polyfills Path2D api for rendering SVG paths in canvas
Polyfills `Path2D` api and `roundRect` for CanvasRenderingContext2D
Use this to enable Path2D features in e.g. Internet Explorer.
## Usage

@@ -27,11 +25,56 @@

```javascript
require("path2d-polyfill");
import "path2d-polyfill";
```
or with es2015+ modules
This will polyfill the browser's window object with Path2D features and it will also polyfill roundRect if they are missing in both CanvasRenderingContexst and Path2D.
Example of usage
```javascript
import "path2d-polyfill";
ctx.fill(new Path2D("M 80 80 A 45 45 0 0 0 125 125 L 125 80 Z"));
ctx.stroke(new Path2D("M 80 80 A 45 45 0 0 0 125 125 L 125 80 Z"));
```
## Usage in a node environment
It is possible to use this library in a node environment as well. The package exports a few functions that can be used:
- `Path2D` - class to create Path2D objects used by the polyfill methods
- `polyfillPath2D` - function that adds Path2D to a "window like" object and polyfills CanvasRenderingContext2D to use Path2D
- `polyfillRoundRect` - polyfills roundRect function on Path2D and CanvasRenderingContext2D (missing in firefox)
- `parsePath` - function for parsing an SVG path string into canvas commands
use any of these functions like:
```js
const { polyfillRoundRect } = require "path2d-polyfill";
const windowlike = { CanvasRenderingContext2D, Path2D };
polyfillRoundRect(windowLike);
// roundRect functions has now been added if they were missing
```
### usage with node-canvas
To get Path2D features with the [node-canvas library](https://github.com/Automattic/node-canvas) use the following pattern:
```js
const { createCanvas, CanvasRenderingContext2D } = require("canvas");
const { polyfillPath2D } = require("path2d-polyfill/path2d");
let polyfilled = { CanvasRenderingContext2D, Path2D: null };
polyfillPath2D(polyfilled);
const Path2D = polyfilled.Path2D;
const canvas = createCanvas(200, 200);
const ctx = canvas.getContext("2d");
const p = new Path2D("M10 10 l 20 0 l 0 20 Z");
ctx.fillStyle = "green";
ctx.fill(p);
```
A working example of a node express server that serves an image drawn with canvas can be seen [here](https://gist.github.com/nilzona/e611c99336d8ea1f645bd391a459c24f)
## Support table

@@ -51,10 +94,4 @@

| rect() | Yes |
| roundRect() | Yes |
Example of usage
```javascript
ctx.fill(new Path2D("M 80 80 A 45 45 0 0 0 125 125 L 125 80 Z"));
ctx.stroke(new Path2D("M 80 80 A 45 45 0 0 0 125 125 L 125 80 Z"));
```
## See it in action

@@ -61,0 +98,0 @@

## [1.2.3](https://github.com/nilzona/path2d-polyfill/compare/v1.2.2...v1.2.3) (2022-10-11)
## [1.2.2](https://github.com/nilzona/path2d-polyfill/compare/v1.2.1...v1.2.2) (2022-07-23)
undefined
### [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)
### Bug Fixes
- fixup lint and build ([94be3cd](https://github.com/nilzona/path2d-polyfill/commit/94be3cd38a58f83efc403a58380ff3c23b4f18bf))
- sync version in package.json with tags ([e12e852](https://github.com/nilzona/path2d-polyfill/commit/e12e852ffb13034fa13efd5112c59b6b13a46013))
### [1.1.2](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2021-05-04)
### [1.1.1](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2020-11-16)
### Features
- support for isPointInPath ([605f5d1](https://github.com/nilzona/path2d-polyfill/commit/605f5d188812e472575ccbaba351b9bbc58d3677))
### Bug Fixes
- documentation readme ([5a0abaa](https://github.com/nilzona/path2d-polyfill/commit/5a0abaab6976f10c57ac83e6f6481ed425ac940e))
### [1.0.2](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2020-08-27)
### Bug Fixes
- remove unused css rule ([54e5174](https://github.com/nilzona/path2d-polyfill/commit/54e5174c64f6e84ef891d8830c828efc45c73b93))
- update badge in README.md ([483afe2](https://github.com/nilzona/path2d-polyfill/commit/483afe2b3440083bbb0c3dae74510959055d0f86))
## [1.0.0](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2020-05-27)
### [0.4.2](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2019-08-28)
### [0.4.1](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2019-04-15)
## [0.4.0](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2019-04-12)
### Features
- support ellipse commands ([#7](https://github.com/nilzona/path2d-polyfill/issues/7)) ([02af6d5](https://github.com/nilzona/path2d-polyfill/commit/02af6d55365b8ef70b8eecad88b913e71ae191b2))
### Bug Fixes
- 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))
### [0.3.1](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2018-09-26)
### Bug Fixes
- better checks if polyfill is needed ([bd65468](https://github.com/nilzona/path2d-polyfill/commit/bd654681662530d19a0958db22c5990424fb77f2))
## [0.3.0](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2018-09-25)
### [0.2.2](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2018-09-04)
### [0.2.1](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2018-06-05)
## [0.2.0](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2018-06-04)
### [0.1.3](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2018-05-22)
### Bug Fixes
- Avoid reference to global window ([9d3e742](https://github.com/nilzona/path2d-polyfill/commit/9d3e74241eb0652afe22d34523f10f3a3837e179))
- Remove wrong removeChild call ([123db85](https://github.com/nilzona/path2d-polyfill/commit/123db8571ff8b1b6c2fa917b513c74f8215acc37))
- Update README.md ([bcb01e1](https://github.com/nilzona/path2d-polyfill/commit/bcb01e153add2dccf95adaced13646e871086a3a))
### [0.1.1](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2018-05-18)
## [0.1.0](https://github.com/nilzona/path2d-polyfill/compare/v1.1.8...v1.2.0) (2018-05-18)
### Features
- Added examples ([261165c](https://github.com/nilzona/path2d-polyfill/commit/261165cfb0ea3a9910624f719a34a3596f1791d0))
- First version of Path2D polyfill ([a660f19](https://github.com/nilzona/path2d-polyfill/commit/a660f194f416785a40d8d7f5ad451bb54cec15c3))
- Implement addPath ([72d4228](https://github.com/nilzona/path2d-polyfill/commit/72d4228bd6c4dda64fa957ab80e49bd7c7677d8f))
var ARG_LENGTH = {
a: 7,
c: 6,
h: 1,
l: 2,
m: 2,
q: 4,
s: 4,
t: 2,
v: 1,
z: 0
};
var SEGMENT_PATTERN = /([astvzqmhlc])([^astvzqmhlc]*)/gi;
var NUMBER = /-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;
function parseValues(args) {
var numbers = args.match(NUMBER);
return numbers ? numbers.map(Number) : [];
}
/**
* parse an svg path data string. Generates an Array
* of commands where each command is an Array of the
* form `[command, arg1, arg2, ...]`
*
* https://www.w3.org/TR/SVG/paths.html#PathDataGeneralInformation
* @ignore
*
* @param {string} path
* @returns {array}
*/
function parse(path) {
var data = [];
var p = String(path).trim();
// A path data segment (if there is one) must begin with a "moveto" command
if (p[0] !== "M" && p[0] !== "m") {
return data;
}
p.replace(SEGMENT_PATTERN, function (_, command, args) {
var type = command.toLowerCase();
var theArgs = parseValues(args);
var theCommand = command;
// overloaded moveTo
if (type === "m" && theArgs.length > 2) {
data.push([theCommand].concat(theArgs.splice(0, 2)));
type = "l";
theCommand = theCommand === "m" ? "l" : "L";
}
// Ignore invalid commands
if (theArgs.length < ARG_LENGTH[type]) {
return "";
}
data.push([theCommand].concat(theArgs.splice(0, ARG_LENGTH[type])));
// The command letter can be eliminated on subsequent commands if the
// same command is used multiple times in a row (e.g., you can drop the
// second "L" in "M 100 200 L 200 100 L -100 -200" and use
// "M 100 200 L 200 100 -100 -200" instead).
while (theArgs.length >= ARG_LENGTH[type] && theArgs.length && ARG_LENGTH[type]) {
data.push([theCommand].concat(theArgs.splice(0, ARG_LENGTH[type])));
}
return "";
});
return data;
}
var parsePath$2 = parse;
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var parsePath$1 = parsePath$2;
/**
* Work around for https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8438884/
* @ignore
*/
function supportsSvgPathArgument(window) {
var canvas = window.document.createElement("canvas");
var g = canvas.getContext("2d");
var p = new window.Path2D("M0 0 L1 1");
g.strokeStyle = "red";
g.lineWidth = 1;
g.stroke(p);
var imgData = g.getImageData(0, 0, 1, 1);
return imgData.data[0] === 255; // Check if pixel is red
}
function rotatePoint(point, angle) {
var nx = point.x * Math.cos(angle) - point.y * Math.sin(angle);
var ny = point.y * Math.cos(angle) + point.x * Math.sin(angle);
point.x = nx;
point.y = ny;
}
function translatePoint(point, dx, dy) {
point.x += dx;
point.y += dy;
}
function scalePoint(point, s) {
point.x *= s;
point.y *= s;
}
function polyFillPath2D(window) {
if (typeof window === "undefined" || !window.CanvasRenderingContext2D) {
return;
}
if (window.Path2D && supportsSvgPathArgument(window)) {
return;
}
/**
* Crates a Path2D polyfill object
* @constructor
* @ignore
* @param {String} path
*/
var Path2D = /*#__PURE__*/function () {
function Path2D(path) {
_classCallCheck(this, Path2D);
this.segments = [];
if (path && path instanceof Path2D) {
var _this$segments;
(_this$segments = this.segments).push.apply(_this$segments, _toConsumableArray(path.segments));
} else if (path) {
this.segments = parsePath$1(path);
}
}
_createClass(Path2D, [{
key: "addPath",
value: function addPath(path) {
if (path && path instanceof Path2D) {
var _this$segments2;
(_this$segments2 = this.segments).push.apply(_this$segments2, _toConsumableArray(path.segments));
}
}
}, {
key: "moveTo",
value: function moveTo(x, y) {
this.segments.push(["M", x, y]);
}
}, {
key: "lineTo",
value: function lineTo(x, y) {
this.segments.push(["L", x, y]);
}
}, {
key: "arc",
value: function arc(x, y, r, start, end, ccw) {
this.segments.push(["AC", x, y, r, start, end, !!ccw]);
}
}, {
key: "arcTo",
value: function arcTo(x1, y1, x2, y2, r) {
this.segments.push(["AT", x1, y1, x2, y2, r]);
}
}, {
key: "ellipse",
value: function ellipse(x, y, rx, ry, angle, start, end, ccw) {
this.segments.push(["E", x, y, rx, ry, angle, start, end, !!ccw]);
}
}, {
key: "closePath",
value: function closePath() {
this.segments.push(["Z"]);
}
}, {
key: "bezierCurveTo",
value: function bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
this.segments.push(["C", cp1x, cp1y, cp2x, cp2y, x, y]);
}
}, {
key: "quadraticCurveTo",
value: function quadraticCurveTo(cpx, cpy, x, y) {
this.segments.push(["Q", cpx, cpy, x, y]);
}
}, {
key: "rect",
value: function rect(x, y, width, height) {
this.segments.push(["R", x, y, width, height]);
}
}]);
return Path2D;
}();
function buildPath(canvas, segments) {
var endAngle;
var startAngle;
var largeArcFlag;
var sweepFlag;
var endPoint;
var midPoint;
var angle;
var lambda;
var t1;
var t2;
var x;
var x1;
var y;
var y1;
var r;
var rx;
var ry;
var w;
var h;
var pathType;
var centerPoint;
var cpx;
var cpy;
var qcpx;
var qcpy;
var ccw;
var startPoint = {
x: 0,
y: 0
};
var currentPoint = {
x: 0,
y: 0
};
canvas.beginPath();
for (var i = 0; i < segments.length; ++i) {
var s = segments[i];
pathType = s[0];
// Reset control point if command is not cubic
if (pathType !== "S" && pathType !== "s" && pathType !== "C" && pathType !== "c") {
cpx = null;
cpy = null;
}
if (pathType !== "T" && pathType !== "t" && pathType !== "Q" && pathType !== "q") {
qcpx = null;
qcpy = null;
}
switch (pathType) {
case "m":
case "M":
if (pathType === "m") {
x += s[1];
y += s[2];
} else {
x = s[1];
y = s[2];
}
if (pathType === "M" || !startPoint) {
startPoint = {
x: x,
y: y
};
}
canvas.moveTo(x, y);
break;
case "l":
x += s[1];
y += s[2];
canvas.lineTo(x, y);
break;
case "L":
x = s[1];
y = s[2];
canvas.lineTo(x, y);
break;
case "H":
x = s[1];
canvas.lineTo(x, y);
break;
case "h":
x += s[1];
canvas.lineTo(x, y);
break;
case "V":
y = s[1];
canvas.lineTo(x, y);
break;
case "v":
y += s[1];
canvas.lineTo(x, y);
break;
case "a":
case "A":
if (pathType === "a") {
x += s[6];
y += s[7];
} else {
x = s[6];
y = s[7];
}
rx = s[1]; // rx
ry = s[2]; // ry
angle = s[3] * Math.PI / 180;
largeArcFlag = !!s[4];
sweepFlag = !!s[5];
endPoint = {
x: x,
y: y
};
// https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
midPoint = {
x: (currentPoint.x - endPoint.x) / 2,
y: (currentPoint.y - endPoint.y) / 2
};
rotatePoint(midPoint, -angle);
// radius correction
lambda = midPoint.x * midPoint.x / (rx * rx) + midPoint.y * midPoint.y / (ry * ry);
if (lambda > 1) {
lambda = Math.sqrt(lambda);
rx *= lambda;
ry *= lambda;
}
centerPoint = {
x: rx * midPoint.y / ry,
y: -(ry * midPoint.x) / rx
};
t1 = rx * rx * ry * ry;
t2 = rx * rx * midPoint.y * midPoint.y + ry * ry * midPoint.x * midPoint.x;
if (sweepFlag !== largeArcFlag) {
scalePoint(centerPoint, Math.sqrt((t1 - t2) / t2) || 0);
} else {
scalePoint(centerPoint, -Math.sqrt((t1 - t2) / t2) || 0);
}
startAngle = Math.atan2((midPoint.y - centerPoint.y) / ry, (midPoint.x - centerPoint.x) / rx);
endAngle = Math.atan2(-(midPoint.y + centerPoint.y) / ry, -(midPoint.x + centerPoint.x) / rx);
rotatePoint(centerPoint, angle);
translatePoint(centerPoint, (endPoint.x + currentPoint.x) / 2, (endPoint.y + currentPoint.y) / 2);
canvas.save();
canvas.translate(centerPoint.x, centerPoint.y);
canvas.rotate(angle);
canvas.scale(rx, ry);
canvas.arc(0, 0, 1, startAngle, endAngle, !sweepFlag);
canvas.restore();
break;
case "C":
cpx = s[3]; // Last control point
cpy = s[4];
x = s[5];
y = s[6];
canvas.bezierCurveTo(s[1], s[2], cpx, cpy, x, y);
break;
case "c":
canvas.bezierCurveTo(s[1] + x, s[2] + y, s[3] + x, s[4] + y, s[5] + x, s[6] + y);
cpx = s[3] + x; // Last control point
cpy = s[4] + y;
x += s[5];
y += s[6];
break;
case "S":
if (cpx === null || cpy === null) {
cpx = x;
cpy = y;
}
canvas.bezierCurveTo(2 * x - cpx, 2 * y - cpy, s[1], s[2], s[3], s[4]);
cpx = s[1]; // last control point
cpy = s[2];
x = s[3];
y = s[4];
break;
case "s":
if (cpx === null || cpy === null) {
cpx = x;
cpy = y;
}
canvas.bezierCurveTo(2 * x - cpx, 2 * y - cpy, s[1] + x, s[2] + y, s[3] + x, s[4] + y);
cpx = s[1] + x; // last control point
cpy = s[2] + y;
x += s[3];
y += s[4];
break;
case "Q":
qcpx = s[1]; // last control point
qcpy = s[2];
x = s[3];
y = s[4];
canvas.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "q":
qcpx = s[1] + x; // last control point
qcpy = s[2] + y;
x += s[3];
y += s[4];
canvas.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "T":
if (qcpx === null || qcpy === null) {
qcpx = x;
qcpy = y;
}
qcpx = 2 * x - qcpx; // last control point
qcpy = 2 * y - qcpy;
x = s[1];
y = s[2];
canvas.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "t":
if (qcpx === null || qcpy === null) {
qcpx = x;
qcpy = y;
}
qcpx = 2 * x - qcpx; // last control point
qcpy = 2 * y - qcpy;
x += s[1];
y += s[2];
canvas.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "z":
case "Z":
x = startPoint.x;
y = startPoint.y;
startPoint = undefined;
canvas.closePath();
break;
case "AC":
// arc
x = s[1];
y = s[2];
r = s[3];
startAngle = s[4];
endAngle = s[5];
ccw = s[6];
canvas.arc(x, y, r, startAngle, endAngle, ccw);
break;
case "AT":
// arcTo
x1 = s[1];
y1 = s[2];
x = s[3];
y = s[4];
r = s[5];
canvas.arcTo(x1, y1, x, y, r);
break;
case "E":
// ellipse
x = s[1];
y = s[2];
rx = s[3];
ry = s[4];
angle = s[5];
startAngle = s[6];
endAngle = s[7];
ccw = s[8];
canvas.save();
canvas.translate(x, y);
canvas.rotate(angle);
canvas.scale(rx, ry);
canvas.arc(0, 0, 1, startAngle, endAngle, ccw);
canvas.restore();
break;
case "R":
// rect
x = s[1];
y = s[2];
w = s[3];
h = s[4];
startPoint = {
x: x,
y: y
};
canvas.rect(x, y, w, h);
break;
// throw new Error(`${pathType} is not implemented`); ?
}
currentPoint.x = x;
currentPoint.y = y;
}
}
var cFill = window.CanvasRenderingContext2D.prototype.fill;
var cStroke = window.CanvasRenderingContext2D.prototype.stroke;
window.CanvasRenderingContext2D.prototype.fill = function fill() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var fillRule = "nonzero";
if (args.length === 0 || args.length === 1 && typeof args[0] === "string") {
cFill.apply(this, args);
return;
}
if (arguments.length === 2) {
fillRule = args[1];
}
var path = args[0];
buildPath(this, path.segments);
cFill.call(this, fillRule);
};
window.CanvasRenderingContext2D.prototype.stroke = function stroke(path) {
if (!path) {
cStroke.call(this);
return;
}
buildPath(this, path.segments);
cStroke.call(this);
};
var cIsPointInPath = window.CanvasRenderingContext2D.prototype.isPointInPath;
window.CanvasRenderingContext2D.prototype.isPointInPath = function isPointInPath() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
// let fillRule = 'nonzero';
if (args[0].constructor.name === "Path2D") {
// first argument is a Path2D object
var x = args[1];
var y = args[2];
var fillRule = args[3] || "nonzero";
var path = args[0];
buildPath(this, path.segments);
return cIsPointInPath.apply(this, [x, y, fillRule]);
} else {
return cIsPointInPath.apply(this, args);
}
};
window.Path2D = Path2D;
}
var path2dPolyfill$1 = polyFillPath2D;
var parsePath = parsePath$2;
var path2dPolyfill = path2dPolyfill$1;
if (typeof window !== "undefined") {
path2dPolyfill(window);
}
var src = {
path2dPolyfill: path2dPolyfill,
parsePath: parsePath
};
export { src as default };
//# sourceMappingURL=index.esm.js.map
{"version":3,"file":"index.esm.js","sources":["../src/parse-path.js","../src/path2d-polyfill.js","../src/index.js"],"sourcesContent":["const ARG_LENGTH = {\n a: 7,\n c: 6,\n h: 1,\n l: 2,\n m: 2,\n q: 4,\n s: 4,\n t: 2,\n v: 1,\n z: 0,\n};\n\nconst SEGMENT_PATTERN = /([astvzqmhlc])([^astvzqmhlc]*)/gi;\n\nconst NUMBER = /-?[0-9]*\\.?[0-9]+(?:e[-+]?\\d+)?/gi;\n\nfunction parseValues(args) {\n const numbers = args.match(NUMBER);\n return numbers ? numbers.map(Number) : [];\n}\n\n/**\n * parse an svg path data string. Generates an Array\n * of commands where each command is an Array of the\n * form `[command, arg1, arg2, ...]`\n *\n * https://www.w3.org/TR/SVG/paths.html#PathDataGeneralInformation\n * @ignore\n *\n * @param {string} path\n * @returns {array}\n */\nfunction parse(path) {\n const data = [];\n const p = String(path).trim();\n\n // A path data segment (if there is one) must begin with a \"moveto\" command\n if (p[0] !== \"M\" && p[0] !== \"m\") {\n return data;\n }\n\n p.replace(SEGMENT_PATTERN, (_, command, args) => {\n let type = command.toLowerCase();\n let theArgs = parseValues(args);\n let theCommand = command;\n // overloaded moveTo\n if (type === \"m\" && theArgs.length > 2) {\n data.push([theCommand].concat(theArgs.splice(0, 2)));\n type = \"l\";\n theCommand = theCommand === \"m\" ? \"l\" : \"L\";\n }\n\n // Ignore invalid commands\n if (theArgs.length < ARG_LENGTH[type]) {\n return \"\";\n }\n\n data.push([theCommand].concat(theArgs.splice(0, ARG_LENGTH[type])));\n\n // The command letter can be eliminated on subsequent commands if the\n // same command is used multiple times in a row (e.g., you can drop the\n // second \"L\" in \"M 100 200 L 200 100 L -100 -200\" and use\n // \"M 100 200 L 200 100 -100 -200\" instead).\n while (theArgs.length >= ARG_LENGTH[type] && theArgs.length && ARG_LENGTH[type]) {\n data.push([theCommand].concat(theArgs.splice(0, ARG_LENGTH[type])));\n }\n\n return \"\";\n });\n return data;\n}\n\nmodule.exports = parse;\n","const parsePath = require(\"./parse-path\");\n\n/**\n * Work around for https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8438884/\n * @ignore\n */\nfunction supportsSvgPathArgument(window) {\n const canvas = window.document.createElement(\"canvas\");\n const g = canvas.getContext(\"2d\");\n const p = new window.Path2D(\"M0 0 L1 1\");\n g.strokeStyle = \"red\";\n g.lineWidth = 1;\n g.stroke(p);\n const imgData = g.getImageData(0, 0, 1, 1);\n return imgData.data[0] === 255; // Check if pixel is red\n}\n\nfunction rotatePoint(point, angle) {\n const nx = point.x * Math.cos(angle) - point.y * Math.sin(angle);\n const ny = point.y * Math.cos(angle) + point.x * Math.sin(angle);\n point.x = nx;\n point.y = ny;\n}\n\nfunction translatePoint(point, dx, dy) {\n point.x += dx;\n point.y += dy;\n}\n\nfunction scalePoint(point, s) {\n point.x *= s;\n point.y *= s;\n}\n\nfunction polyFillPath2D(window) {\n if (typeof window === \"undefined\" || !window.CanvasRenderingContext2D) {\n return;\n }\n if (window.Path2D && supportsSvgPathArgument(window)) {\n return;\n }\n\n /**\n * Crates a Path2D polyfill object\n * @constructor\n * @ignore\n * @param {String} path\n */\n class Path2D {\n constructor(path) {\n this.segments = [];\n if (path && path instanceof Path2D) {\n this.segments.push(...path.segments);\n } else if (path) {\n this.segments = parsePath(path);\n }\n }\n\n addPath(path) {\n if (path && path instanceof Path2D) {\n this.segments.push(...path.segments);\n }\n }\n\n moveTo(x, y) {\n this.segments.push([\"M\", x, y]);\n }\n\n lineTo(x, y) {\n this.segments.push([\"L\", x, y]);\n }\n\n arc(x, y, r, start, end, ccw) {\n this.segments.push([\"AC\", x, y, r, start, end, !!ccw]);\n }\n\n arcTo(x1, y1, x2, y2, r) {\n this.segments.push([\"AT\", x1, y1, x2, y2, r]);\n }\n\n ellipse(x, y, rx, ry, angle, start, end, ccw) {\n this.segments.push([\"E\", x, y, rx, ry, angle, start, end, !!ccw]);\n }\n\n closePath() {\n this.segments.push([\"Z\"]);\n }\n\n bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {\n this.segments.push([\"C\", cp1x, cp1y, cp2x, cp2y, x, y]);\n }\n\n quadraticCurveTo(cpx, cpy, x, y) {\n this.segments.push([\"Q\", cpx, cpy, x, y]);\n }\n\n rect(x, y, width, height) {\n this.segments.push([\"R\", x, y, width, height]);\n }\n }\n\n function buildPath(canvas, segments) {\n let endAngle;\n let startAngle;\n let largeArcFlag;\n let sweepFlag;\n let endPoint;\n let midPoint;\n let angle;\n let lambda;\n let t1;\n let t2;\n let x;\n let x1;\n let y;\n let y1;\n let r;\n let rx;\n let ry;\n let w;\n let h;\n let pathType;\n let centerPoint;\n let cpx;\n let cpy;\n let qcpx;\n let qcpy;\n let ccw;\n let startPoint = { x: 0, y: 0 };\n const currentPoint = { x: 0, y: 0 };\n\n canvas.beginPath();\n for (let i = 0; i < segments.length; ++i) {\n const s = segments[i];\n pathType = s[0];\n\n // Reset control point if command is not cubic\n if (pathType !== \"S\" && pathType !== \"s\" && pathType !== \"C\" && pathType !== \"c\") {\n cpx = null;\n cpy = null;\n }\n\n if (pathType !== \"T\" && pathType !== \"t\" && pathType !== \"Q\" && pathType !== \"q\") {\n qcpx = null;\n qcpy = null;\n }\n\n switch (pathType) {\n case \"m\":\n case \"M\":\n if (pathType === \"m\") {\n x += s[1];\n y += s[2];\n } else {\n x = s[1];\n y = s[2];\n }\n\n if (pathType === \"M\" || !startPoint) {\n startPoint = { x, y };\n }\n\n canvas.moveTo(x, y);\n break;\n case \"l\":\n x += s[1];\n y += s[2];\n canvas.lineTo(x, y);\n break;\n case \"L\":\n x = s[1];\n y = s[2];\n canvas.lineTo(x, y);\n break;\n case \"H\":\n x = s[1];\n canvas.lineTo(x, y);\n break;\n case \"h\":\n x += s[1];\n canvas.lineTo(x, y);\n break;\n case \"V\":\n y = s[1];\n canvas.lineTo(x, y);\n break;\n case \"v\":\n y += s[1];\n canvas.lineTo(x, y);\n break;\n case \"a\":\n case \"A\":\n if (pathType === \"a\") {\n x += s[6];\n y += s[7];\n } else {\n x = s[6];\n y = s[7];\n }\n\n rx = s[1]; // rx\n ry = s[2]; // ry\n angle = (s[3] * Math.PI) / 180;\n largeArcFlag = !!s[4];\n sweepFlag = !!s[5];\n endPoint = { x, y };\n\n // https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes\n\n midPoint = {\n x: (currentPoint.x - endPoint.x) / 2,\n y: (currentPoint.y - endPoint.y) / 2,\n };\n rotatePoint(midPoint, -angle);\n\n // radius correction\n lambda = (midPoint.x * midPoint.x) / (rx * rx) + (midPoint.y * midPoint.y) / (ry * ry);\n if (lambda > 1) {\n lambda = Math.sqrt(lambda);\n rx *= lambda;\n ry *= lambda;\n }\n\n centerPoint = {\n x: (rx * midPoint.y) / ry,\n y: -(ry * midPoint.x) / rx,\n };\n t1 = rx * rx * ry * ry;\n t2 = rx * rx * midPoint.y * midPoint.y + ry * ry * midPoint.x * midPoint.x;\n if (sweepFlag !== largeArcFlag) {\n scalePoint(centerPoint, Math.sqrt((t1 - t2) / t2) || 0);\n } else {\n scalePoint(centerPoint, -Math.sqrt((t1 - t2) / t2) || 0);\n }\n\n startAngle = Math.atan2((midPoint.y - centerPoint.y) / ry, (midPoint.x - centerPoint.x) / rx);\n endAngle = Math.atan2(-(midPoint.y + centerPoint.y) / ry, -(midPoint.x + centerPoint.x) / rx);\n\n rotatePoint(centerPoint, angle);\n translatePoint(centerPoint, (endPoint.x + currentPoint.x) / 2, (endPoint.y + currentPoint.y) / 2);\n\n canvas.save();\n canvas.translate(centerPoint.x, centerPoint.y);\n canvas.rotate(angle);\n canvas.scale(rx, ry);\n canvas.arc(0, 0, 1, startAngle, endAngle, !sweepFlag);\n canvas.restore();\n break;\n case \"C\":\n cpx = s[3]; // Last control point\n cpy = s[4];\n x = s[5];\n y = s[6];\n canvas.bezierCurveTo(s[1], s[2], cpx, cpy, x, y);\n break;\n case \"c\":\n canvas.bezierCurveTo(s[1] + x, s[2] + y, s[3] + x, s[4] + y, s[5] + x, s[6] + y);\n cpx = s[3] + x; // Last control point\n cpy = s[4] + y;\n x += s[5];\n y += s[6];\n break;\n case \"S\":\n if (cpx === null || cpy === null) {\n cpx = x;\n cpy = y;\n }\n\n canvas.bezierCurveTo(2 * x - cpx, 2 * y - cpy, s[1], s[2], s[3], s[4]);\n cpx = s[1]; // last control point\n cpy = s[2];\n x = s[3];\n y = s[4];\n break;\n case \"s\":\n if (cpx === null || cpy === null) {\n cpx = x;\n cpy = y;\n }\n\n canvas.bezierCurveTo(2 * x - cpx, 2 * y - cpy, s[1] + x, s[2] + y, s[3] + x, s[4] + y);\n cpx = s[1] + x; // last control point\n cpy = s[2] + y;\n x += s[3];\n y += s[4];\n break;\n case \"Q\":\n qcpx = s[1]; // last control point\n qcpy = s[2];\n x = s[3];\n y = s[4];\n canvas.quadraticCurveTo(qcpx, qcpy, x, y);\n break;\n case \"q\":\n qcpx = s[1] + x; // last control point\n qcpy = s[2] + y;\n x += s[3];\n y += s[4];\n canvas.quadraticCurveTo(qcpx, qcpy, x, y);\n break;\n case \"T\":\n if (qcpx === null || qcpy === null) {\n qcpx = x;\n qcpy = y;\n }\n qcpx = 2 * x - qcpx; // last control point\n qcpy = 2 * y - qcpy;\n x = s[1];\n y = s[2];\n canvas.quadraticCurveTo(qcpx, qcpy, x, y);\n break;\n case \"t\":\n if (qcpx === null || qcpy === null) {\n qcpx = x;\n qcpy = y;\n }\n qcpx = 2 * x - qcpx; // last control point\n qcpy = 2 * y - qcpy;\n x += s[1];\n y += s[2];\n canvas.quadraticCurveTo(qcpx, qcpy, x, y);\n break;\n case \"z\":\n case \"Z\":\n x = startPoint.x;\n y = startPoint.y;\n startPoint = undefined;\n canvas.closePath();\n break;\n case \"AC\": // arc\n x = s[1];\n y = s[2];\n r = s[3];\n startAngle = s[4];\n endAngle = s[5];\n ccw = s[6];\n canvas.arc(x, y, r, startAngle, endAngle, ccw);\n break;\n case \"AT\": // arcTo\n x1 = s[1];\n y1 = s[2];\n x = s[3];\n y = s[4];\n r = s[5];\n canvas.arcTo(x1, y1, x, y, r);\n break;\n case \"E\": // ellipse\n x = s[1];\n y = s[2];\n rx = s[3];\n ry = s[4];\n angle = s[5];\n startAngle = s[6];\n endAngle = s[7];\n ccw = s[8];\n canvas.save();\n canvas.translate(x, y);\n canvas.rotate(angle);\n canvas.scale(rx, ry);\n canvas.arc(0, 0, 1, startAngle, endAngle, ccw);\n canvas.restore();\n break;\n case \"R\": // rect\n x = s[1];\n y = s[2];\n w = s[3];\n h = s[4];\n startPoint = { x, y };\n canvas.rect(x, y, w, h);\n break;\n default:\n // throw new Error(`${pathType} is not implemented`); ?\n }\n\n currentPoint.x = x;\n currentPoint.y = y;\n }\n }\n\n const cFill = window.CanvasRenderingContext2D.prototype.fill;\n const cStroke = window.CanvasRenderingContext2D.prototype.stroke;\n\n window.CanvasRenderingContext2D.prototype.fill = function fill(...args) {\n let fillRule = \"nonzero\";\n if (args.length === 0 || (args.length === 1 && typeof args[0] === \"string\")) {\n cFill.apply(this, args);\n return;\n }\n if (arguments.length === 2) {\n fillRule = args[1];\n }\n const path = args[0];\n buildPath(this, path.segments);\n cFill.call(this, fillRule);\n };\n\n window.CanvasRenderingContext2D.prototype.stroke = function stroke(path) {\n if (!path) {\n cStroke.call(this);\n return;\n }\n buildPath(this, path.segments);\n cStroke.call(this);\n };\n\n const cIsPointInPath = window.CanvasRenderingContext2D.prototype.isPointInPath;\n\n window.CanvasRenderingContext2D.prototype.isPointInPath = function isPointInPath(...args) {\n // let fillRule = 'nonzero';\n if (args[0].constructor.name === \"Path2D\") {\n // first argument is a Path2D object\n const x = args[1];\n const y = args[2];\n const fillRule = args[3] || \"nonzero\";\n const path = args[0];\n buildPath(this, path.segments);\n return cIsPointInPath.apply(this, [x, y, fillRule]);\n } else {\n return cIsPointInPath.apply(this, args);\n }\n };\n\n window.Path2D = Path2D;\n}\n\nmodule.exports = polyFillPath2D;\n","const parsePath = require(\"./parse-path\");\nconst path2dPolyfill = require(\"./path2d-polyfill\");\n\nif (typeof window !== \"undefined\") {\n path2dPolyfill(window);\n}\n\nmodule.exports = {\n path2dPolyfill,\n parsePath,\n};\n"],"names":["ARG_LENGTH","a","c","h","l","m","q","s","t","v","z","SEGMENT_PATTERN","NUMBER","parseValues","args","numbers","match","map","Number","parse","path","data","p","String","trim","replace","_","command","type","toLowerCase","theArgs","theCommand","length","push","concat","splice","parsePath","require$$0","supportsSvgPathArgument","window","canvas","document","createElement","g","getContext","Path2D","strokeStyle","lineWidth","stroke","imgData","getImageData","rotatePoint","point","angle","nx","x","Math","cos","y","sin","ny","translatePoint","dx","dy","scalePoint","polyFillPath2D","CanvasRenderingContext2D","segments","r","start","end","ccw","x1","y1","x2","y2","rx","ry","cp1x","cp1y","cp2x","cp2y","cpx","cpy","width","height","buildPath","endAngle","startAngle","largeArcFlag","sweepFlag","endPoint","midPoint","lambda","t1","t2","w","pathType","centerPoint","qcpx","qcpy","startPoint","currentPoint","beginPath","i","moveTo","lineTo","PI","sqrt","atan2","save","translate","rotate","scale","arc","restore","bezierCurveTo","quadraticCurveTo","undefined","closePath","arcTo","rect","cFill","prototype","fill","cStroke","fillRule","apply","arguments","call","cIsPointInPath","isPointInPath","constructor","name","path2dPolyfill","require$$1","src"],"mappings":"AAAA,IAAMA,UAAU,GAAG;AACjBC,EAAAA,CAAC,EAAE,CAAC;AACJC,EAAAA,CAAC,EAAE,CAAC;AACJC,EAAAA,CAAC,EAAE,CAAC;AACJC,EAAAA,CAAC,EAAE,CAAC;AACJC,EAAAA,CAAC,EAAE,CAAC;AACJC,EAAAA,CAAC,EAAE,CAAC;AACJC,EAAAA,CAAC,EAAE,CAAC;AACJC,EAAAA,CAAC,EAAE,CAAC;AACJC,EAAAA,CAAC,EAAE,CAAC;AACJC,EAAAA,CAAC,EAAE,CAAA;AACL,CAAC,CAAA;AAED,IAAMC,eAAe,GAAG,kCAAkC,CAAA;AAE1D,IAAMC,MAAM,GAAG,mCAAmC,CAAA;AAElD,SAASC,WAAW,CAACC,IAAI,EAAE;AACzB,EAAA,IAAMC,OAAO,GAAGD,IAAI,CAACE,KAAK,CAACJ,MAAM,CAAC,CAAA;EAClC,OAAOG,OAAO,GAAGA,OAAO,CAACE,GAAG,CAACC,MAAM,CAAC,GAAG,EAAE,CAAA;AAC3C,CAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,KAAK,CAACC,IAAI,EAAE;EACnB,IAAMC,IAAI,GAAG,EAAE,CAAA;EACf,IAAMC,CAAC,GAAGC,MAAM,CAACH,IAAI,CAAC,CAACI,IAAI,EAAE,CAAA;;AAE/B;AACE,EAAA,IAAIF,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,IAAIA,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;AAChC,IAAA,O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EAAE,CAACxE,CAAC,EAAEG,CAAC,EAAEoE,QAAQ,CAAC,CAAC,CAAA;AACzD,KAAK,MAAM;AACL,MAAA,OAAOI,cAAc,CAACH,KAAK,CAAC,IAAI,EAAEjH,IAAI,CAAC,CAAA;AACxC,KAAA;GACF,CAAA;EAEDyB,MAAM,CAACM,MAAM,GAAGA,MAAM,CAAA;AACxB,CAAA;AAEA,IAAAyF,gBAAc,GAAGrE,cAAc;;ACza/B,IAAM7B,SAAS,GAAGC,WAAuB,CAAA;AACzC,IAAMiG,cAAc,GAAGC,gBAA4B,CAAA;AAEnD,IAAI,OAAOhG,MAAM,KAAK,WAAW,EAAE;EACjC+F,cAAc,CAAC/F,MAAM,CAAC,CAAA;AACxB,CAAA;AAEA,IAAAiG,GAAc,GAAG;AACfF,EAAAA,cAAc,EAAdA,cAAc;AACdlG,EAAAA,SAAS,EAATA,SAAAA;AACF;;;;"}
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).path2dPolyfill={})}(this,(function(e){"use strict";var t={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},n=/([astvzqmhlc])([^astvzqmhlc]*)/gi,a=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;var r=function(e){var r=[],o=String(e).trim();return"M"!==o[0]&&"m"!==o[0]||o.replace(n,(function(e,n,o){var s=n.toLowerCase(),i=function(e){var t=e.match(a);return t?t.map(Number):[]}(o),l=n;if("m"===s&&i.length>2&&(r.push([l].concat(i.splice(0,2))),s="l",l="m"===l?"l":"L"),i.length<t[s])return"";for(r.push([l].concat(i.splice(0,t[s])));i.length>=t[s]&&i.length&&t[s];)r.push([l].concat(i.splice(0,t[s])));return""})),r};function o(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function s(e){return function(e){if(Array.isArray(e))return i(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return i(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=e[n];return a}var l=r;function u(e,t){var n=e.x*Math.cos(t)-e.y*Math.sin(t),a=e.y*Math.cos(t)+e.x*Math.sin(t);e.x=n,e.y=a}function c(e,t){e.x*=t,e.y*=t}var h=function(e){if(void 0!==e&&e.CanvasRenderingContext2D&&(!e.Path2D||!function(e){var t=e.document.createElement("canvas").getContext("2d"),n=new e.Path2D("M0 0 L1 1");return t.strokeStyle="red",t.lineWidth=1,t.stroke(n),255===t.getImageData(0,0,1,1).data[0]}(e))){var t=function(){function e(t){var n;(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.segments=[],t&&t instanceof e)?(n=this.segments).push.apply(n,s(t.segments)):t&&(this.segments=l(t))}var t,n,a;return t=e,(n=[{key:"addPath",value:function(t){var n;t&&t instanceof e&&(n=this.segments).push.apply(n,s(t.segments))}},{key:"moveTo",value:function(e,t){this.segments.push(["M",e,t])}},{key:"lineTo",value:function(e,t){this.segments.push(["L",e,t])}},{key:"arc",value:function(e,t,n,a,r,o){this.segments.push(["AC",e,t,n,a,r,!!o])}},{key:"arcTo",value:function(e,t,n,a,r){this.segments.push(["AT",e,t,n,a,r])}},{key:"ellipse",value:function(e,t,n,a,r,o,s,i){this.segments.push(["E",e,t,n,a,r,o,s,!!i])}},{key:"closePath",value:function(){this.segments.push(["Z"])}},{key:"bezierCurveTo",value:function(e,t,n,a,r,o){this.segments.push(["C",e,t,n,a,r,o])}},{key:"quadraticCurveTo",value:function(e,t,n,a){this.segments.push(["Q",e,t,n,a])}},{key:"rect",value:function(e,t,n,a){this.segments.push(["R",e,t,n,a])}}])&&o(t.prototype,n),a&&o(t,a),Object.defineProperty(t,"prototype",{writable:!1}),e}(),n=e.CanvasRenderingContext2D.prototype.fill,a=e.CanvasRenderingContext2D.prototype.stroke;e.CanvasRenderingContext2D.prototype.fill=function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];var r="nonzero";if(0===t.length||1===t.length&&"string"==typeof t[0])n.apply(this,t);else{2===arguments.length&&(r=t[1]);var o=t[0];i(this,o.segments),n.call(this,r)}},e.CanvasRenderingContext2D.prototype.stroke=function(e){e?(i(this,e.segments),a.call(this)):a.call(this)};var r=e.CanvasRenderingContext2D.prototype.isPointInPath;e.CanvasRenderingContext2D.prototype.isPointInPath=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];if("Path2D"===t[0].constructor.name){var a=t[1],o=t[2],s=t[3]||"nonzero",l=t[0];return i(this,l.segments),r.apply(this,[a,o,s])}return r.apply(this,t)},e.Path2D=t}function i(e,t){var n,a,r,o,s,i,l,h,f,y,p,v,g,m,d,b,x,k,C,T,P,M,w,A,q,D,z,R,S,j={x:0,y:0},I={x:0,y:0};e.beginPath();for(var E=0;E<t.length;++E){var L=t[E];switch("S"!==(T=L[0])&&"s"!==T&&"C"!==T&&"c"!==T&&(M=null,w=null),"T"!==T&&"t"!==T&&"Q"!==T&&"q"!==T&&(A=null,q=null),T){case"m":case"M":"m"===T?(p+=L[1],g+=L[2]):(p=L[1],g=L[2]),"M"!==T&&j||(j={x:p,y:g}),e.moveTo(p,g);break;case"l":p+=L[1],g+=L[2],e.lineTo(p,g);break;case"L":p=L[1],g=L[2],e.lineTo(p,g);break;case"H":p=L[1],e.lineTo(p,g);break;case"h":p+=L[1],e.lineTo(p,g);break;case"V":g=L[1],e.lineTo(p,g);break;case"v":g+=L[1],e.lineTo(p,g);break;case"a":case"A":"a"===T?(p+=L[6],g+=L[7]):(p=L[6],g=L[7]),b=L[1],x=L[2],l=L[3]*Math.PI/180,r=!!L[4],o=!!L[5],s={x:p,y:g},u(i={x:(I.x-s.x)/2,y:(I.y-s.y)/2},-l),(h=i.x*i.x/(b*b)+i.y*i.y/(x*x))>1&&(b*=h=Math.sqrt(h),x*=h),f=b*b*x*x,y=b*b*i.y*i.y+x*x*i.x*i.x,c(P={x:b*i.y/x,y:-x*i.x/b},o!==r?Math.sqrt((f-y)/y)||0:-Math.sqrt((f-y)/y)||0),a=Math.atan2((i.y-P.y)/x,(i.x-P.x)/b),n=Math.atan2(-(i.y+P.y)/x,-(i.x+P.x)/b),u(P,l),z=P,R=(s.x+I.x)/2,S=(s.y+I.y)/2,z.x+=R,z.y+=S,e.save(),e.translate(P.x,P.y),e.rotate(l),e.scale(b,x),e.arc(0,0,1,a,n,!o),e.restore();break;case"C":M=L[3],w=L[4],p=L[5],g=L[6],e.bezierCurveTo(L[1],L[2],M,w,p,g);break;case"c":e.bezierCurveTo(L[1]+p,L[2]+g,L[3]+p,L[4]+g,L[5]+p,L[6]+g),M=L[3]+p,w=L[4]+g,p+=L[5],g+=L[6];break;case"S":null!==M&&null!==w||(M=p,w=g),e.bezierCurveTo(2*p-M,2*g-w,L[1],L[2],L[3],L[4]),M=L[1],w=L[2],p=L[3],g=L[4];break;case"s":null!==M&&null!==w||(M=p,w=g),e.bezierCurveTo(2*p-M,2*g-w,L[1]+p,L[2]+g,L[3]+p,L[4]+g),M=L[1]+p,w=L[2]+g,p+=L[3],g+=L[4];break;case"Q":A=L[1],q=L[2],p=L[3],g=L[4],e.quadraticCurveTo(A,q,p,g);break;case"q":A=L[1]+p,q=L[2]+g,p+=L[3],g+=L[4],e.quadraticCurveTo(A,q,p,g);break;case"T":null!==A&&null!==q||(A=p,q=g),A=2*p-A,q=2*g-q,p=L[1],g=L[2],e.quadraticCurveTo(A,q,p,g);break;case"t":null!==A&&null!==q||(A=p,q=g),A=2*p-A,q=2*g-q,p+=L[1],g+=L[2],e.quadraticCurveTo(A,q,p,g);break;case"z":case"Z":p=j.x,g=j.y,j=void 0,e.closePath();break;case"AC":p=L[1],g=L[2],d=L[3],a=L[4],n=L[5],D=L[6],e.arc(p,g,d,a,n,D);break;case"AT":v=L[1],m=L[2],p=L[3],g=L[4],d=L[5],e.arcTo(v,m,p,g,d);break;case"E":p=L[1],g=L[2],b=L[3],x=L[4],l=L[5],a=L[6],n=L[7],D=L[8],e.save(),e.translate(p,g),e.rotate(l),e.scale(b,x),e.arc(0,0,1,a,n,D),e.restore();break;case"R":p=L[1],g=L[2],k=L[3],C=L[4],j={x:p,y:g},e.rect(p,g,k,C)}I.x=p,I.y=g}}},f=r,y=h;"undefined"!=typeof window&&y(window);var p={path2dPolyfill:y,parsePath:f};e.default=p,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.js.map
{"version":3,"file":"index.js","sources":["../src/parse-path.js","../src/path2d-polyfill.js","../src/index.js"],"sourcesContent":["const ARG_LENGTH = {\n a: 7,\n c: 6,\n h: 1,\n l: 2,\n m: 2,\n q: 4,\n s: 4,\n t: 2,\n v: 1,\n z: 0,\n};\n\nconst SEGMENT_PATTERN = /([astvzqmhlc])([^astvzqmhlc]*)/gi;\n\nconst NUMBER = /-?[0-9]*\\.?[0-9]+(?:e[-+]?\\d+)?/gi;\n\nfunction parseValues(args) {\n const numbers = args.match(NUMBER);\n return numbers ? numbers.map(Number) : [];\n}\n\n/**\n * parse an svg path data string. Generates an Array\n * of commands where each command is an Array of the\n * form `[command, arg1, arg2, ...]`\n *\n * https://www.w3.org/TR/SVG/paths.html#PathDataGeneralInformation\n * @ignore\n *\n * @param {string} path\n * @returns {array}\n */\nfunction parse(path) {\n const data = [];\n const p = String(path).trim();\n\n // A path data segment (if there is one) must begin with a \"moveto\" command\n if (p[0] !== \"M\" && p[0] !== \"m\") {\n return data;\n }\n\n p.replace(SEGMENT_PATTERN, (_, command, args) => {\n let type = command.toLowerCase();\n let theArgs = parseValues(args);\n let theCommand = command;\n // overloaded moveTo\n if (type === \"m\" && theArgs.length > 2) {\n data.push([theCommand].concat(theArgs.splice(0, 2)));\n type = \"l\";\n theCommand = theCommand === \"m\" ? \"l\" : \"L\";\n }\n\n // Ignore invalid commands\n if (theArgs.length < ARG_LENGTH[type]) {\n return \"\";\n }\n\n data.push([theCommand].concat(theArgs.splice(0, ARG_LENGTH[type])));\n\n // The command letter can be eliminated on subsequent commands if the\n // same command is used multiple times in a row (e.g., you can drop the\n // second \"L\" in \"M 100 200 L 200 100 L -100 -200\" and use\n // \"M 100 200 L 200 100 -100 -200\" instead).\n while (theArgs.length >= ARG_LENGTH[type] && theArgs.length && ARG_LENGTH[type]) {\n data.push([theCommand].concat(theArgs.splice(0, ARG_LENGTH[type])));\n }\n\n return \"\";\n });\n return data;\n}\n\nmodule.exports = parse;\n","const parsePath = require(\"./parse-path\");\n\n/**\n * Work around for https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8438884/\n * @ignore\n */\nfunction supportsSvgPathArgument(window) {\n const canvas = window.document.createElement(\"canvas\");\n const g = canvas.getContext(\"2d\");\n const p = new window.Path2D(\"M0 0 L1 1\");\n g.strokeStyle = \"red\";\n g.lineWidth = 1;\n g.stroke(p);\n const imgData = g.getImageData(0, 0, 1, 1);\n return imgData.data[0] === 255; // Check if pixel is red\n}\n\nfunction rotatePoint(point, angle) {\n const nx = point.x * Math.cos(angle) - point.y * Math.sin(angle);\n const ny = point.y * Math.cos(angle) + point.x * Math.sin(angle);\n point.x = nx;\n point.y = ny;\n}\n\nfunction translatePoint(point, dx, dy) {\n point.x += dx;\n point.y += dy;\n}\n\nfunction scalePoint(point, s) {\n point.x *= s;\n point.y *= s;\n}\n\nfunction polyFillPath2D(window) {\n if (typeof window === \"undefined\" || !window.CanvasRenderingContext2D) {\n return;\n }\n if (window.Path2D && supportsSvgPathArgument(window)) {\n return;\n }\n\n /**\n * Crates a Path2D polyfill object\n * @constructor\n * @ignore\n * @param {String} path\n */\n class Path2D {\n constructor(path) {\n this.segments = [];\n if (path && path instanceof Path2D) {\n this.segments.push(...path.segments);\n } else if (path) {\n this.segments = parsePath(path);\n }\n }\n\n addPath(path) {\n if (path && path instanceof Path2D) {\n this.segments.push(...path.segments);\n }\n }\n\n moveTo(x, y) {\n this.segments.push([\"M\", x, y]);\n }\n\n lineTo(x, y) {\n this.segments.push([\"L\", x, y]);\n }\n\n arc(x, y, r, start, end, ccw) {\n this.segments.push([\"AC\", x, y, r, start, end, !!ccw]);\n }\n\n arcTo(x1, y1, x2, y2, r) {\n this.segments.push([\"AT\", x1, y1, x2, y2, r]);\n }\n\n ellipse(x, y, rx, ry, angle, start, end, ccw) {\n this.segments.push([\"E\", x, y, rx, ry, angle, start, end, !!ccw]);\n }\n\n closePath() {\n this.segments.push([\"Z\"]);\n }\n\n bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {\n this.segments.push([\"C\", cp1x, cp1y, cp2x, cp2y, x, y]);\n }\n\n quadraticCurveTo(cpx, cpy, x, y) {\n this.segments.push([\"Q\", cpx, cpy, x, y]);\n }\n\n rect(x, y, width, height) {\n this.segments.push([\"R\", x, y, width, height]);\n }\n }\n\n function buildPath(canvas, segments) {\n let endAngle;\n let startAngle;\n let largeArcFlag;\n let sweepFlag;\n let endPoint;\n let midPoint;\n let angle;\n let lambda;\n let t1;\n let t2;\n let x;\n let x1;\n let y;\n let y1;\n let r;\n let rx;\n let ry;\n let w;\n let h;\n let pathType;\n let centerPoint;\n let cpx;\n let cpy;\n let qcpx;\n let qcpy;\n let ccw;\n let startPoint = { x: 0, y: 0 };\n const currentPoint = { x: 0, y: 0 };\n\n canvas.beginPath();\n for (let i = 0; i < segments.length; ++i) {\n const s = segments[i];\n pathType = s[0];\n\n // Reset control point if command is not cubic\n if (pathType !== \"S\" && pathType !== \"s\" && pathType !== \"C\" && pathType !== \"c\") {\n cpx = null;\n cpy = null;\n }\n\n if (pathType !== \"T\" && pathType !== \"t\" && pathType !== \"Q\" && pathType !== \"q\") {\n qcpx = null;\n qcpy = null;\n }\n\n switch (pathType) {\n case \"m\":\n case \"M\":\n if (pathType === \"m\") {\n x += s[1];\n y += s[2];\n } else {\n x = s[1];\n y = s[2];\n }\n\n if (pathType === \"M\" || !startPoint) {\n startPoint = { x, y };\n }\n\n canvas.moveTo(x, y);\n break;\n case \"l\":\n x += s[1];\n y += s[2];\n canvas.lineTo(x, y);\n break;\n case \"L\":\n x = s[1];\n y = s[2];\n canvas.lineTo(x, y);\n break;\n case \"H\":\n x = s[1];\n canvas.lineTo(x, y);\n break;\n case \"h\":\n x += s[1];\n canvas.lineTo(x, y);\n break;\n case \"V\":\n y = s[1];\n canvas.lineTo(x, y);\n break;\n case \"v\":\n y += s[1];\n canvas.lineTo(x, y);\n break;\n case \"a\":\n case \"A\":\n if (pathType === \"a\") {\n x += s[6];\n y += s[7];\n } else {\n x = s[6];\n y = s[7];\n }\n\n rx = s[1]; // rx\n ry = s[2]; // ry\n angle = (s[3] * Math.PI) / 180;\n largeArcFlag = !!s[4];\n sweepFlag = !!s[5];\n endPoint = { x, y };\n\n // https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes\n\n midPoint = {\n x: (currentPoint.x - endPoint.x) / 2,\n y: (currentPoint.y - endPoint.y) / 2,\n };\n rotatePoint(midPoint, -angle);\n\n // radius correction\n lambda = (midPoint.x * midPoint.x) / (rx * rx) + (midPoint.y * midPoint.y) / (ry * ry);\n if (lambda > 1) {\n lambda = Math.sqrt(lambda);\n rx *= lambda;\n ry *= lambda;\n }\n\n centerPoint = {\n x: (rx * midPoint.y) / ry,\n y: -(ry * midPoint.x) / rx,\n };\n t1 = rx * rx * ry * ry;\n t2 = rx * rx * midPoint.y * midPoint.y + ry * ry * midPoint.x * midPoint.x;\n if (sweepFlag !== largeArcFlag) {\n scalePoint(centerPoint, Math.sqrt((t1 - t2) / t2) || 0);\n } else {\n scalePoint(centerPoint, -Math.sqrt((t1 - t2) / t2) || 0);\n }\n\n startAngle = Math.atan2((midPoint.y - centerPoint.y) / ry, (midPoint.x - centerPoint.x) / rx);\n endAngle = Math.atan2(-(midPoint.y + centerPoint.y) / ry, -(midPoint.x + centerPoint.x) / rx);\n\n rotatePoint(centerPoint, angle);\n translatePoint(centerPoint, (endPoint.x + currentPoint.x) / 2, (endPoint.y + currentPoint.y) / 2);\n\n canvas.save();\n canvas.translate(centerPoint.x, centerPoint.y);\n canvas.rotate(angle);\n canvas.scale(rx, ry);\n canvas.arc(0, 0, 1, startAngle, endAngle, !sweepFlag);\n canvas.restore();\n break;\n case \"C\":\n cpx = s[3]; // Last control point\n cpy = s[4];\n x = s[5];\n y = s[6];\n canvas.bezierCurveTo(s[1], s[2], cpx, cpy, x, y);\n break;\n case \"c\":\n canvas.bezierCurveTo(s[1] + x, s[2] + y, s[3] + x, s[4] + y, s[5] + x, s[6] + y);\n cpx = s[3] + x; // Last control point\n cpy = s[4] + y;\n x += s[5];\n y += s[6];\n break;\n case \"S\":\n if (cpx === null || cpy === null) {\n cpx = x;\n cpy = y;\n }\n\n canvas.bezierCurveTo(2 * x - cpx, 2 * y - cpy, s[1], s[2], s[3], s[4]);\n cpx = s[1]; // last control point\n cpy = s[2];\n x = s[3];\n y = s[4];\n break;\n case \"s\":\n if (cpx === null || cpy === null) {\n cpx = x;\n cpy = y;\n }\n\n canvas.bezierCurveTo(2 * x - cpx, 2 * y - cpy, s[1] + x, s[2] + y, s[3] + x, s[4] + y);\n cpx = s[1] + x; // last control point\n cpy = s[2] + y;\n x += s[3];\n y += s[4];\n break;\n case \"Q\":\n qcpx = s[1]; // last control point\n qcpy = s[2];\n x = s[3];\n y = s[4];\n canvas.quadraticCurveTo(qcpx, qcpy, x, y);\n break;\n case \"q\":\n qcpx = s[1] + x; // last control point\n qcpy = s[2] + y;\n x += s[3];\n y += s[4];\n canvas.quadraticCurveTo(qcpx, qcpy, x, y);\n break;\n case \"T\":\n if (qcpx === null || qcpy === null) {\n qcpx = x;\n qcpy = y;\n }\n qcpx = 2 * x - qcpx; // last control point\n qcpy = 2 * y - qcpy;\n x = s[1];\n y = s[2];\n canvas.quadraticCurveTo(qcpx, qcpy, x, y);\n break;\n case \"t\":\n if (qcpx === null || qcpy === null) {\n qcpx = x;\n qcpy = y;\n }\n qcpx = 2 * x - qcpx; // last control point\n qcpy = 2 * y - qcpy;\n x += s[1];\n y += s[2];\n canvas.quadraticCurveTo(qcpx, qcpy, x, y);\n break;\n case \"z\":\n case \"Z\":\n x = startPoint.x;\n y = startPoint.y;\n startPoint = undefined;\n canvas.closePath();\n break;\n case \"AC\": // arc\n x = s[1];\n y = s[2];\n r = s[3];\n startAngle = s[4];\n endAngle = s[5];\n ccw = s[6];\n canvas.arc(x, y, r, startAngle, endAngle, ccw);\n break;\n case \"AT\": // arcTo\n x1 = s[1];\n y1 = s[2];\n x = s[3];\n y = s[4];\n r = s[5];\n canvas.arcTo(x1, y1, x, y, r);\n break;\n case \"E\": // ellipse\n x = s[1];\n y = s[2];\n rx = s[3];\n ry = s[4];\n angle = s[5];\n startAngle = s[6];\n endAngle = s[7];\n ccw = s[8];\n canvas.save();\n canvas.translate(x, y);\n canvas.rotate(angle);\n canvas.scale(rx, ry);\n canvas.arc(0, 0, 1, startAngle, endAngle, ccw);\n canvas.restore();\n break;\n case \"R\": // rect\n x = s[1];\n y = s[2];\n w = s[3];\n h = s[4];\n startPoint = { x, y };\n canvas.rect(x, y, w, h);\n break;\n default:\n // throw new Error(`${pathType} is not implemented`); ?\n }\n\n currentPoint.x = x;\n currentPoint.y = y;\n }\n }\n\n const cFill = window.CanvasRenderingContext2D.prototype.fill;\n const cStroke = window.CanvasRenderingContext2D.prototype.stroke;\n\n window.CanvasRenderingContext2D.prototype.fill = function fill(...args) {\n let fillRule = \"nonzero\";\n if (args.length === 0 || (args.length === 1 && typeof args[0] === \"string\")) {\n cFill.apply(this, args);\n return;\n }\n if (arguments.length === 2) {\n fillRule = args[1];\n }\n const path = args[0];\n buildPath(this, path.segments);\n cFill.call(this, fillRule);\n };\n\n window.CanvasRenderingContext2D.prototype.stroke = function stroke(path) {\n if (!path) {\n cStroke.call(this);\n return;\n }\n buildPath(this, path.segments);\n cStroke.call(this);\n };\n\n const cIsPointInPath = window.CanvasRenderingContext2D.prototype.isPointInPath;\n\n window.CanvasRenderingContext2D.prototype.isPointInPath = function isPointInPath(...args) {\n // let fillRule = 'nonzero';\n if (args[0].constructor.name === \"Path2D\") {\n // first argument is a Path2D object\n const x = args[1];\n const y = args[2];\n const fillRule = args[3] || \"nonzero\";\n const path = args[0];\n buildPath(this, path.segments);\n return cIsPointInPath.apply(this, [x, y, fillRule]);\n } else {\n return cIsPointInPath.apply(this, args);\n }\n };\n\n window.Path2D = Path2D;\n}\n\nmodule.exports = polyFillPath2D;\n","const parsePath = require(\"./parse-path\");\nconst path2dPolyfill = require(\"./path2d-polyfill\");\n\nif (typeof window !== \"undefined\") {\n path2dPolyfill(window);\n}\n\nmodule.exports = {\n path2dPolyfill,\n parsePath,\n};\n"],"names":["ARG_LENGTH","a","c","h","l","m","q","s","t","v","z","SEGMENT_PATTERN","NUMBER","parsePath","path","data","p","String","trim","replace","_","command","args","type","toLowerCase","theArgs","numbers","match","map","Number","parseValues","theCommand","length","push","concat","splice","require$$0","rotatePoint","point","angle","nx","x","Math","cos","y","sin","ny","scalePoint","path2dPolyfill","window","CanvasRenderingContext2D","Path2D","g","document","createElement","getContext","strokeStyle","lineWidth","stroke","getImageData","supportsSvgPathArgument","_this$segments","_classCallCheck","this","segments","key","value","_this$segments2","r","start","end","ccw","x1","y1","x2","y2","rx","ry","cp1x","cp1y","cp2x","cp2y","cpx","cpy","width","height","cFill","prototype","fill","cStroke","_len","arguments","Array","_key","fillRule","apply","buildPath","call","cIsPointInPath","isPointInPath","_len2","_key2","constructor","name","canvas","endAngle","startAngle","largeArcFlag","sweepFlag","endPoint","midPoint","lambda","t1","t2","w","pathType","centerPoint","qcpx","qcpy","dx","dy","startPoint","currentPoint","beginPath","i","moveTo","lineTo","PI","sqrt","atan2","save","translate","rotate","scale","arc","restore","bezierCurveTo","quadraticCurveTo","undefined","closePath","arcTo","rect","require$$1","src"],"mappings":"sPAAA,IAAMA,EAAa,CACjBC,EAAG,EACHC,EAAG,EACHC,EAAG,EACHC,EAAG,EACHC,EAAG,EACHC,EAAG,EACHC,EAAG,EACHC,EAAG,EACHC,EAAG,EACHC,EAAG,GAGCC,EAAkB,mCAElBC,EAAS,oCA0Df,IAAAC,EAxCA,SAAeC,GACb,IAAMC,EAAO,GACPC,EAAIC,OAAOH,GAAMI,OAGvB,MAAa,MAATF,EAAE,IAAuB,MAATA,EAAE,IAItBA,EAAEG,QAAQR,GAAiB,SAACS,EAAGC,EAASC,GACtC,IAAIC,EAAOF,EAAQG,cACfC,EA3BR,SAAqBH,GACnB,IAAMI,EAAUJ,EAAKK,MAAMf,GAC3B,OAAOc,EAAUA,EAAQE,IAAIC,QAAU,EACzC,CAwBkBC,CAAYR,GACtBS,EAAaV,EASjB,GAPa,MAATE,GAAgBE,EAAQO,OAAS,IACnCjB,EAAKkB,KAAK,CAACF,GAAYG,OAAOT,EAAQU,OAAO,EAAG,KAChDZ,EAAO,IACPQ,EAA4B,MAAfA,EAAqB,IAAM,KAItCN,EAAQO,OAAShC,EAAWuB,GAC9B,MAAO,GAST,IANAR,EAAKkB,KAAK,CAACF,GAAYG,OAAOT,EAAQU,OAAO,EAAGnC,EAAWuB,MAMpDE,EAAQO,QAAUhC,EAAWuB,IAASE,EAAQO,QAAUhC,EAAWuB,IACxER,EAAKkB,KAAK,CAACF,GAAYG,OAAOT,EAAQU,OAAO,EAAGnC,EAAWuB,MAG7D,MAAO,EACX,IA9BWR,CAgCX,q6BCvEA,IAAMF,EAAYuB,EAiBlB,SAASC,EAAYC,EAAOC,GAC1B,IAAMC,EAAKF,EAAM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C,EAAGG,EAAGwB,GAC3B,MACF,IAAK,IACH3B,EAAIlC,EAAE,GACNqC,EAAIrC,EAAE,GACNqE,EAAKrE,EAAE,GACPsE,EAAKtE,EAAE,GACPgC,EAAQhC,EAAE,GACVmG,EAAanG,EAAE,GACfkG,EAAWlG,EAAE,GACbgE,EAAMhE,EAAE,GACRiG,EAAO0B,OACP1B,EAAO2B,UAAU1F,EAAGG,GACpB4D,EAAO4B,OAAO7F,GACdiE,EAAO6B,MAAMzD,EAAIC,GACjB2B,EAAO8B,IAAI,EAAG,EAAG,EAAG5B,EAAYD,EAAUlC,GAC1CiC,EAAO+B,UACP,MACF,IAAK,IACH9F,EAAIlC,EAAE,GACNqC,EAAIrC,EAAE,GACN2G,EAAI3G,EAAE,GACNJ,EAAII,EAAE,GACNkH,EAAa,CAAEhF,EAAAA,EAAGG,EAAAA,GAClB4D,EAAOqC,KAAKpG,EAAGG,EAAGsE,EAAG/G,GAMzBuH,EAAajF,EAAIA,EACjBiF,EAAa9E,EAAIA,CAClB,CACF,CA8CH,ECvaM/B,EAAYuB,EACZY,EAAiB8F,EAED,oBAAX7F,QACTD,EAAeC,QAGjB,IAAA8F,EAAiB,CACf/F,eAAAA,EACAnC,UAAAA"}
const parsePath = require("./parse-path");
const path2dPolyfill = require("./path2d-polyfill");
if (typeof window !== "undefined") {
path2dPolyfill(window);
}
module.exports = {
path2dPolyfill,
parsePath,
};
const ARG_LENGTH = {
a: 7,
c: 6,
h: 1,
l: 2,
m: 2,
q: 4,
s: 4,
t: 2,
v: 1,
z: 0,
};
const SEGMENT_PATTERN = /([astvzqmhlc])([^astvzqmhlc]*)/gi;
const NUMBER = /-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;
function parseValues(args) {
const numbers = args.match(NUMBER);
return numbers ? numbers.map(Number) : [];
}
/**
* parse an svg path data string. Generates an Array
* of commands where each command is an Array of the
* form `[command, arg1, arg2, ...]`
*
* https://www.w3.org/TR/SVG/paths.html#PathDataGeneralInformation
* @ignore
*
* @param {string} path
* @returns {array}
*/
function parse(path) {
const data = [];
const p = String(path).trim();
// A path data segment (if there is one) must begin with a "moveto" command
if (p[0] !== "M" && p[0] !== "m") {
return data;
}
p.replace(SEGMENT_PATTERN, (_, command, args) => {
let type = command.toLowerCase();
let theArgs = parseValues(args);
let theCommand = command;
// overloaded moveTo
if (type === "m" && theArgs.length > 2) {
data.push([theCommand].concat(theArgs.splice(0, 2)));
type = "l";
theCommand = theCommand === "m" ? "l" : "L";
}
// Ignore invalid commands
if (theArgs.length < ARG_LENGTH[type]) {
return "";
}
data.push([theCommand].concat(theArgs.splice(0, ARG_LENGTH[type])));
// The command letter can be eliminated on subsequent commands if the
// same command is used multiple times in a row (e.g., you can drop the
// second "L" in "M 100 200 L 200 100 L -100 -200" and use
// "M 100 200 L 200 100 -100 -200" instead).
while (theArgs.length >= ARG_LENGTH[type] && theArgs.length && ARG_LENGTH[type]) {
data.push([theCommand].concat(theArgs.splice(0, ARG_LENGTH[type])));
}
return "";
});
return data;
}
module.exports = parse;
const parsePath = require("./parse-path");
/**
* Work around for https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8438884/
* @ignore
*/
function supportsSvgPathArgument(window) {
const canvas = window.document.createElement("canvas");
const g = canvas.getContext("2d");
const p = new window.Path2D("M0 0 L1 1");
g.strokeStyle = "red";
g.lineWidth = 1;
g.stroke(p);
const imgData = g.getImageData(0, 0, 1, 1);
return imgData.data[0] === 255; // Check if pixel is red
}
function rotatePoint(point, angle) {
const nx = point.x * Math.cos(angle) - point.y * Math.sin(angle);
const ny = point.y * Math.cos(angle) + point.x * Math.sin(angle);
point.x = nx;
point.y = ny;
}
function translatePoint(point, dx, dy) {
point.x += dx;
point.y += dy;
}
function scalePoint(point, s) {
point.x *= s;
point.y *= s;
}
function polyFillPath2D(window) {
if (typeof window === "undefined" || !window.CanvasRenderingContext2D) {
return;
}
if (window.Path2D && supportsSvgPathArgument(window)) {
return;
}
/**
* Crates a Path2D polyfill object
* @constructor
* @ignore
* @param {String} path
*/
class Path2D {
constructor(path) {
this.segments = [];
if (path && path instanceof Path2D) {
this.segments.push(...path.segments);
} else if (path) {
this.segments = parsePath(path);
}
}
addPath(path) {
if (path && path instanceof Path2D) {
this.segments.push(...path.segments);
}
}
moveTo(x, y) {
this.segments.push(["M", x, y]);
}
lineTo(x, y) {
this.segments.push(["L", x, y]);
}
arc(x, y, r, start, end, ccw) {
this.segments.push(["AC", x, y, r, start, end, !!ccw]);
}
arcTo(x1, y1, x2, y2, r) {
this.segments.push(["AT", x1, y1, x2, y2, r]);
}
ellipse(x, y, rx, ry, angle, start, end, ccw) {
this.segments.push(["E", x, y, rx, ry, angle, start, end, !!ccw]);
}
closePath() {
this.segments.push(["Z"]);
}
bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
this.segments.push(["C", cp1x, cp1y, cp2x, cp2y, x, y]);
}
quadraticCurveTo(cpx, cpy, x, y) {
this.segments.push(["Q", cpx, cpy, x, y]);
}
rect(x, y, width, height) {
this.segments.push(["R", x, y, width, height]);
}
}
function buildPath(canvas, segments) {
let endAngle;
let startAngle;
let largeArcFlag;
let sweepFlag;
let endPoint;
let midPoint;
let angle;
let lambda;
let t1;
let t2;
let x;
let x1;
let y;
let y1;
let r;
let rx;
let ry;
let w;
let h;
let pathType;
let centerPoint;
let cpx;
let cpy;
let qcpx;
let qcpy;
let ccw;
let startPoint = { x: 0, y: 0 };
const currentPoint = { x: 0, y: 0 };
canvas.beginPath();
for (let i = 0; i < segments.length; ++i) {
const s = segments[i];
pathType = s[0];
// Reset control point if command is not cubic
if (pathType !== "S" && pathType !== "s" && pathType !== "C" && pathType !== "c") {
cpx = null;
cpy = null;
}
if (pathType !== "T" && pathType !== "t" && pathType !== "Q" && pathType !== "q") {
qcpx = null;
qcpy = null;
}
switch (pathType) {
case "m":
case "M":
if (pathType === "m") {
x += s[1];
y += s[2];
} else {
x = s[1];
y = s[2];
}
if (pathType === "M" || !startPoint) {
startPoint = { x, y };
}
canvas.moveTo(x, y);
break;
case "l":
x += s[1];
y += s[2];
canvas.lineTo(x, y);
break;
case "L":
x = s[1];
y = s[2];
canvas.lineTo(x, y);
break;
case "H":
x = s[1];
canvas.lineTo(x, y);
break;
case "h":
x += s[1];
canvas.lineTo(x, y);
break;
case "V":
y = s[1];
canvas.lineTo(x, y);
break;
case "v":
y += s[1];
canvas.lineTo(x, y);
break;
case "a":
case "A":
if (pathType === "a") {
x += s[6];
y += s[7];
} else {
x = s[6];
y = s[7];
}
rx = s[1]; // rx
ry = s[2]; // ry
angle = (s[3] * Math.PI) / 180;
largeArcFlag = !!s[4];
sweepFlag = !!s[5];
endPoint = { x, y };
// https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
midPoint = {
x: (currentPoint.x - endPoint.x) / 2,
y: (currentPoint.y - endPoint.y) / 2,
};
rotatePoint(midPoint, -angle);
// radius correction
lambda = (midPoint.x * midPoint.x) / (rx * rx) + (midPoint.y * midPoint.y) / (ry * ry);
if (lambda > 1) {
lambda = Math.sqrt(lambda);
rx *= lambda;
ry *= lambda;
}
centerPoint = {
x: (rx * midPoint.y) / ry,
y: -(ry * midPoint.x) / rx,
};
t1 = rx * rx * ry * ry;
t2 = rx * rx * midPoint.y * midPoint.y + ry * ry * midPoint.x * midPoint.x;
if (sweepFlag !== largeArcFlag) {
scalePoint(centerPoint, Math.sqrt((t1 - t2) / t2) || 0);
} else {
scalePoint(centerPoint, -Math.sqrt((t1 - t2) / t2) || 0);
}
startAngle = Math.atan2((midPoint.y - centerPoint.y) / ry, (midPoint.x - centerPoint.x) / rx);
endAngle = Math.atan2(-(midPoint.y + centerPoint.y) / ry, -(midPoint.x + centerPoint.x) / rx);
rotatePoint(centerPoint, angle);
translatePoint(centerPoint, (endPoint.x + currentPoint.x) / 2, (endPoint.y + currentPoint.y) / 2);
canvas.save();
canvas.translate(centerPoint.x, centerPoint.y);
canvas.rotate(angle);
canvas.scale(rx, ry);
canvas.arc(0, 0, 1, startAngle, endAngle, !sweepFlag);
canvas.restore();
break;
case "C":
cpx = s[3]; // Last control point
cpy = s[4];
x = s[5];
y = s[6];
canvas.bezierCurveTo(s[1], s[2], cpx, cpy, x, y);
break;
case "c":
canvas.bezierCurveTo(s[1] + x, s[2] + y, s[3] + x, s[4] + y, s[5] + x, s[6] + y);
cpx = s[3] + x; // Last control point
cpy = s[4] + y;
x += s[5];
y += s[6];
break;
case "S":
if (cpx === null || cpy === null) {
cpx = x;
cpy = y;
}
canvas.bezierCurveTo(2 * x - cpx, 2 * y - cpy, s[1], s[2], s[3], s[4]);
cpx = s[1]; // last control point
cpy = s[2];
x = s[3];
y = s[4];
break;
case "s":
if (cpx === null || cpy === null) {
cpx = x;
cpy = y;
}
canvas.bezierCurveTo(2 * x - cpx, 2 * y - cpy, s[1] + x, s[2] + y, s[3] + x, s[4] + y);
cpx = s[1] + x; // last control point
cpy = s[2] + y;
x += s[3];
y += s[4];
break;
case "Q":
qcpx = s[1]; // last control point
qcpy = s[2];
x = s[3];
y = s[4];
canvas.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "q":
qcpx = s[1] + x; // last control point
qcpy = s[2] + y;
x += s[3];
y += s[4];
canvas.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "T":
if (qcpx === null || qcpy === null) {
qcpx = x;
qcpy = y;
}
qcpx = 2 * x - qcpx; // last control point
qcpy = 2 * y - qcpy;
x = s[1];
y = s[2];
canvas.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "t":
if (qcpx === null || qcpy === null) {
qcpx = x;
qcpy = y;
}
qcpx = 2 * x - qcpx; // last control point
qcpy = 2 * y - qcpy;
x += s[1];
y += s[2];
canvas.quadraticCurveTo(qcpx, qcpy, x, y);
break;
case "z":
case "Z":
x = startPoint.x;
y = startPoint.y;
startPoint = undefined;
canvas.closePath();
break;
case "AC": // arc
x = s[1];
y = s[2];
r = s[3];
startAngle = s[4];
endAngle = s[5];
ccw = s[6];
canvas.arc(x, y, r, startAngle, endAngle, ccw);
break;
case "AT": // arcTo
x1 = s[1];
y1 = s[2];
x = s[3];
y = s[4];
r = s[5];
canvas.arcTo(x1, y1, x, y, r);
break;
case "E": // ellipse
x = s[1];
y = s[2];
rx = s[3];
ry = s[4];
angle = s[5];
startAngle = s[6];
endAngle = s[7];
ccw = s[8];
canvas.save();
canvas.translate(x, y);
canvas.rotate(angle);
canvas.scale(rx, ry);
canvas.arc(0, 0, 1, startAngle, endAngle, ccw);
canvas.restore();
break;
case "R": // rect
x = s[1];
y = s[2];
w = s[3];
h = s[4];
startPoint = { x, y };
canvas.rect(x, y, w, h);
break;
default:
// throw new Error(`${pathType} is not implemented`); ?
}
currentPoint.x = x;
currentPoint.y = y;
}
}
const cFill = window.CanvasRenderingContext2D.prototype.fill;
const cStroke = window.CanvasRenderingContext2D.prototype.stroke;
window.CanvasRenderingContext2D.prototype.fill = function fill(...args) {
let fillRule = "nonzero";
if (args.length === 0 || (args.length === 1 && typeof args[0] === "string")) {
cFill.apply(this, args);
return;
}
if (arguments.length === 2) {
fillRule = args[1];
}
const path = args[0];
buildPath(this, path.segments);
cFill.call(this, fillRule);
};
window.CanvasRenderingContext2D.prototype.stroke = function stroke(path) {
if (!path) {
cStroke.call(this);
return;
}
buildPath(this, path.segments);
cStroke.call(this);
};
const cIsPointInPath = window.CanvasRenderingContext2D.prototype.isPointInPath;
window.CanvasRenderingContext2D.prototype.isPointInPath = function isPointInPath(...args) {
// let fillRule = 'nonzero';
if (args[0].constructor.name === "Path2D") {
// first argument is a Path2D object
const x = args[1];
const y = args[2];
const fillRule = args[3] || "nonzero";
const path = args[0];
buildPath(this, path.segments);
return cIsPointInPath.apply(this, [x, y, fillRule]);
} else {
return cIsPointInPath.apply(this, args);
}
};
window.Path2D = Path2D;
}
module.exports = polyFillPath2D;