Latest repo

This commit is contained in:
Marc
2025-06-02 16:42:16 +00:00
parent 53ddf1a329
commit cde5fae175
27907 changed files with 3875388 additions and 1 deletions

16
node_modules/svg-arc-to-cubic-bezier/LICENSE.md generated vendored Normal file
View File

@@ -0,0 +1,16 @@
Internet Systems Consortium license
===================================
Copyright (c) `2017`, `Colin Meinke`
Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.
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.

75
node_modules/svg-arc-to-cubic-bezier/README.md generated vendored Normal file
View File

@@ -0,0 +1,75 @@
# SVG arc to cubic bezier
A function that takes an SVG arc curve as input, and maps it to
one or more cubic bezier curves.
I extracted the `a2c` function from
[SVG path](https://github.com/fontello/svgpath), as I wanted to use it on its own.
All credit, thanks and respect goes to:
- Sergey Batishchev [@snb2013](https://github.com/snb2013)
- Vitaly Puzrin [@puzrin](https://github.com/puzrin)
- Alex Kocharin [@rlidwka](https://github.com/rlidwka)
It blew my mind. Thank you!
## Installation
```
npm install svg-arc-to-cubic-bezier
```
## Usage
```js
import arcToBezier from 'svg-arc-to-cubic-bezier';
const previousPoint = { x: 100, y: 100 }
const currentPoint = {
x: 700,
y: 100,
curve: {
type: 'arc',
rx: 300,
ry: 200,
largeArcFlag: 30,
sweepFlag: 0,
xAxisRotation: 0,
},
};
const curves = arcToBezier({
px: previousPoint.x,
py: previousPoint.y,
cx: currentPoint.x,
cy: currentPoint.y,
rx: currentPoint.curve.rx,
ry: currentPoint.curve.ry,
xAxisRotation: currentPoint.curve.xAxisRotation,
largeArcFlag: currentPoint.curve.largeArcFlag,
sweepFlag: currentPoint.curve.sweepFlag,
});
curves.forEach( c => console.log( c ));
// [
// {
// x1: 159.7865795437111,
// y1: 244.97474575043722,
// x2: 342.5677510865157,
// y2: 362.49999701503634,
// x: 508.253174689854,
// y: 362.4999967447917,
// },
// {
// x1: 673.9385982931924,
// y1: 362.49999647454695,
// x2: 759.7865756485664,
// y2: 244.97474477179443,
// x: 699.9999995964145,
// y: 99.99999902135724,
// },
// ]
```

190
node_modules/svg-arc-to-cubic-bezier/cjs/index.js generated vendored Normal file
View File

@@ -0,0 +1,190 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var TAU = Math.PI * 2;
var mapToEllipse = function mapToEllipse(_ref, rx, ry, cosphi, sinphi, centerx, centery) {
var x = _ref.x,
y = _ref.y;
x *= rx;
y *= ry;
var xp = cosphi * x - sinphi * y;
var yp = sinphi * x + cosphi * y;
return {
x: xp + centerx,
y: yp + centery
};
};
var approxUnitArc = function approxUnitArc(ang1, ang2) {
// If 90 degree circular arc, use a constant
// as derived from http://spencermortensen.com/articles/bezier-circle
var a = ang2 === 1.5707963267948966 ? 0.551915024494 : ang2 === -1.5707963267948966 ? -0.551915024494 : 4 / 3 * Math.tan(ang2 / 4);
var x1 = Math.cos(ang1);
var y1 = Math.sin(ang1);
var x2 = Math.cos(ang1 + ang2);
var y2 = Math.sin(ang1 + ang2);
return [{
x: x1 - y1 * a,
y: y1 + x1 * a
}, {
x: x2 + y2 * a,
y: y2 - x2 * a
}, {
x: x2,
y: y2
}];
};
var vectorAngle = function vectorAngle(ux, uy, vx, vy) {
var sign = ux * vy - uy * vx < 0 ? -1 : 1;
var dot = ux * vx + uy * vy;
if (dot > 1) {
dot = 1;
}
if (dot < -1) {
dot = -1;
}
return sign * Math.acos(dot);
};
var getArcCenter = function getArcCenter(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinphi, cosphi, pxp, pyp) {
var rxsq = Math.pow(rx, 2);
var rysq = Math.pow(ry, 2);
var pxpsq = Math.pow(pxp, 2);
var pypsq = Math.pow(pyp, 2);
var radicant = rxsq * rysq - rxsq * pypsq - rysq * pxpsq;
if (radicant < 0) {
radicant = 0;
}
radicant /= rxsq * pypsq + rysq * pxpsq;
radicant = Math.sqrt(radicant) * (largeArcFlag === sweepFlag ? -1 : 1);
var centerxp = radicant * rx / ry * pyp;
var centeryp = radicant * -ry / rx * pxp;
var centerx = cosphi * centerxp - sinphi * centeryp + (px + cx) / 2;
var centery = sinphi * centerxp + cosphi * centeryp + (py + cy) / 2;
var vx1 = (pxp - centerxp) / rx;
var vy1 = (pyp - centeryp) / ry;
var vx2 = (-pxp - centerxp) / rx;
var vy2 = (-pyp - centeryp) / ry;
var ang1 = vectorAngle(1, 0, vx1, vy1);
var ang2 = vectorAngle(vx1, vy1, vx2, vy2);
if (sweepFlag === 0 && ang2 > 0) {
ang2 -= TAU;
}
if (sweepFlag === 1 && ang2 < 0) {
ang2 += TAU;
}
return [centerx, centery, ang1, ang2];
};
var arcToBezier = function arcToBezier(_ref2) {
var px = _ref2.px,
py = _ref2.py,
cx = _ref2.cx,
cy = _ref2.cy,
rx = _ref2.rx,
ry = _ref2.ry,
_ref2$xAxisRotation = _ref2.xAxisRotation,
xAxisRotation = _ref2$xAxisRotation === undefined ? 0 : _ref2$xAxisRotation,
_ref2$largeArcFlag = _ref2.largeArcFlag,
largeArcFlag = _ref2$largeArcFlag === undefined ? 0 : _ref2$largeArcFlag,
_ref2$sweepFlag = _ref2.sweepFlag,
sweepFlag = _ref2$sweepFlag === undefined ? 0 : _ref2$sweepFlag;
var curves = [];
if (rx === 0 || ry === 0) {
return [];
}
var sinphi = Math.sin(xAxisRotation * TAU / 360);
var cosphi = Math.cos(xAxisRotation * TAU / 360);
var pxp = cosphi * (px - cx) / 2 + sinphi * (py - cy) / 2;
var pyp = -sinphi * (px - cx) / 2 + cosphi * (py - cy) / 2;
if (pxp === 0 && pyp === 0) {
return [];
}
rx = Math.abs(rx);
ry = Math.abs(ry);
var lambda = Math.pow(pxp, 2) / Math.pow(rx, 2) + Math.pow(pyp, 2) / Math.pow(ry, 2);
if (lambda > 1) {
rx *= Math.sqrt(lambda);
ry *= Math.sqrt(lambda);
}
var _getArcCenter = getArcCenter(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinphi, cosphi, pxp, pyp),
_getArcCenter2 = _slicedToArray(_getArcCenter, 4),
centerx = _getArcCenter2[0],
centery = _getArcCenter2[1],
ang1 = _getArcCenter2[2],
ang2 = _getArcCenter2[3];
// If 'ang2' == 90.0000000001, then `ratio` will evaluate to
// 1.0000000001. This causes `segments` to be greater than one, which is an
// unecessary split, and adds extra points to the bezier curve. To alleviate
// this issue, we round to 1.0 when the ratio is close to 1.0.
var ratio = Math.abs(ang2) / (TAU / 4);
if (Math.abs(1.0 - ratio) < 0.0000001) {
ratio = 1.0;
}
var segments = Math.max(Math.ceil(ratio), 1);
ang2 /= segments;
for (var i = 0; i < segments; i++) {
curves.push(approxUnitArc(ang1, ang2));
ang1 += ang2;
}
return curves.map(function (curve) {
var _mapToEllipse = mapToEllipse(curve[0], rx, ry, cosphi, sinphi, centerx, centery),
x1 = _mapToEllipse.x,
y1 = _mapToEllipse.y;
var _mapToEllipse2 = mapToEllipse(curve[1], rx, ry, cosphi, sinphi, centerx, centery),
x2 = _mapToEllipse2.x,
y2 = _mapToEllipse2.y;
var _mapToEllipse3 = mapToEllipse(curve[2], rx, ry, cosphi, sinphi, centerx, centery),
x = _mapToEllipse3.x,
y = _mapToEllipse3.y;
return { x1: x1, y1: y1, x2: x2, y2: y2, x: x, y: y };
});
};
exports.default = arcToBezier;
module.exports = exports.default;

View File

@@ -0,0 +1,191 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.SVGArcToCubicBezier = factory());
}(this, function () { 'use strict';
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var TAU = Math.PI * 2;
var mapToEllipse = function mapToEllipse(_ref, rx, ry, cosphi, sinphi, centerx, centery) {
var x = _ref.x,
y = _ref.y;
x *= rx;
y *= ry;
var xp = cosphi * x - sinphi * y;
var yp = sinphi * x + cosphi * y;
return {
x: xp + centerx,
y: yp + centery
};
};
var approxUnitArc = function approxUnitArc(ang1, ang2) {
// If 90 degree circular arc, use a constant
// as derived from http://spencermortensen.com/articles/bezier-circle
var a = ang2 === 1.5707963267948966 ? 0.551915024494 : ang2 === -1.5707963267948966 ? -0.551915024494 : 4 / 3 * Math.tan(ang2 / 4);
var x1 = Math.cos(ang1);
var y1 = Math.sin(ang1);
var x2 = Math.cos(ang1 + ang2);
var y2 = Math.sin(ang1 + ang2);
return [{
x: x1 - y1 * a,
y: y1 + x1 * a
}, {
x: x2 + y2 * a,
y: y2 - x2 * a
}, {
x: x2,
y: y2
}];
};
var vectorAngle = function vectorAngle(ux, uy, vx, vy) {
var sign = ux * vy - uy * vx < 0 ? -1 : 1;
var dot = ux * vx + uy * vy;
if (dot > 1) {
dot = 1;
}
if (dot < -1) {
dot = -1;
}
return sign * Math.acos(dot);
};
var getArcCenter = function getArcCenter(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinphi, cosphi, pxp, pyp) {
var rxsq = Math.pow(rx, 2);
var rysq = Math.pow(ry, 2);
var pxpsq = Math.pow(pxp, 2);
var pypsq = Math.pow(pyp, 2);
var radicant = rxsq * rysq - rxsq * pypsq - rysq * pxpsq;
if (radicant < 0) {
radicant = 0;
}
radicant /= rxsq * pypsq + rysq * pxpsq;
radicant = Math.sqrt(radicant) * (largeArcFlag === sweepFlag ? -1 : 1);
var centerxp = radicant * rx / ry * pyp;
var centeryp = radicant * -ry / rx * pxp;
var centerx = cosphi * centerxp - sinphi * centeryp + (px + cx) / 2;
var centery = sinphi * centerxp + cosphi * centeryp + (py + cy) / 2;
var vx1 = (pxp - centerxp) / rx;
var vy1 = (pyp - centeryp) / ry;
var vx2 = (-pxp - centerxp) / rx;
var vy2 = (-pyp - centeryp) / ry;
var ang1 = vectorAngle(1, 0, vx1, vy1);
var ang2 = vectorAngle(vx1, vy1, vx2, vy2);
if (sweepFlag === 0 && ang2 > 0) {
ang2 -= TAU;
}
if (sweepFlag === 1 && ang2 < 0) {
ang2 += TAU;
}
return [centerx, centery, ang1, ang2];
};
var arcToBezier = function arcToBezier(_ref2) {
var px = _ref2.px,
py = _ref2.py,
cx = _ref2.cx,
cy = _ref2.cy,
rx = _ref2.rx,
ry = _ref2.ry,
_ref2$xAxisRotation = _ref2.xAxisRotation,
xAxisRotation = _ref2$xAxisRotation === undefined ? 0 : _ref2$xAxisRotation,
_ref2$largeArcFlag = _ref2.largeArcFlag,
largeArcFlag = _ref2$largeArcFlag === undefined ? 0 : _ref2$largeArcFlag,
_ref2$sweepFlag = _ref2.sweepFlag,
sweepFlag = _ref2$sweepFlag === undefined ? 0 : _ref2$sweepFlag;
var curves = [];
if (rx === 0 || ry === 0) {
return [];
}
var sinphi = Math.sin(xAxisRotation * TAU / 360);
var cosphi = Math.cos(xAxisRotation * TAU / 360);
var pxp = cosphi * (px - cx) / 2 + sinphi * (py - cy) / 2;
var pyp = -sinphi * (px - cx) / 2 + cosphi * (py - cy) / 2;
if (pxp === 0 && pyp === 0) {
return [];
}
rx = Math.abs(rx);
ry = Math.abs(ry);
var lambda = Math.pow(pxp, 2) / Math.pow(rx, 2) + Math.pow(pyp, 2) / Math.pow(ry, 2);
if (lambda > 1) {
rx *= Math.sqrt(lambda);
ry *= Math.sqrt(lambda);
}
var _getArcCenter = getArcCenter(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinphi, cosphi, pxp, pyp),
_getArcCenter2 = _slicedToArray(_getArcCenter, 4),
centerx = _getArcCenter2[0],
centery = _getArcCenter2[1],
ang1 = _getArcCenter2[2],
ang2 = _getArcCenter2[3];
// If 'ang2' == 90.0000000001, then `ratio` will evaluate to
// 1.0000000001. This causes `segments` to be greater than one, which is an
// unecessary split, and adds extra points to the bezier curve. To alleviate
// this issue, we round to 1.0 when the ratio is close to 1.0.
var ratio = Math.abs(ang2) / (TAU / 4);
if (Math.abs(1.0 - ratio) < 0.0000001) {
ratio = 1.0;
}
var segments = Math.max(Math.ceil(ratio), 1);
ang2 /= segments;
for (var i = 0; i < segments; i++) {
curves.push(approxUnitArc(ang1, ang2));
ang1 += ang2;
}
return curves.map(function (curve) {
var _mapToEllipse = mapToEllipse(curve[0], rx, ry, cosphi, sinphi, centerx, centery),
x1 = _mapToEllipse.x,
y1 = _mapToEllipse.y;
var _mapToEllipse2 = mapToEllipse(curve[1], rx, ry, cosphi, sinphi, centerx, centery),
x2 = _mapToEllipse2.x,
y2 = _mapToEllipse2.y;
var _mapToEllipse3 = mapToEllipse(curve[2], rx, ry, cosphi, sinphi, centerx, centery),
x = _mapToEllipse3.x,
y = _mapToEllipse3.y;
return { x1: x1, y1: y1, x2: x2, y2: y2, x: x, y: y };
});
};
return arcToBezier;
}));

View File

@@ -0,0 +1 @@
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t=t||self).SVGArcToCubicBezier=r()}(this,function(){"use strict";function O(t,r,a,n,e,o,i){var h=t.x,u=t.y;return{x:n*(h*=r)-e*(u*=a)+o,y:e*h+n*u+i}}function P(t,r,a,n){var e=t*a+r*n;return 1<e&&(e=1),e<-1&&(e=-1),(t*n-r*a<0?-1:1)*Math.acos(e)}var R=function(t,r){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,r){var a=[],n=!0,e=!1,o=void 0;try{for(var i,h=t[Symbol.iterator]();!(n=(i=h.next()).done)&&(a.push(i.value),!r||a.length!==r);n=!0);}catch(t){e=!0,o=t}finally{try{!n&&h.return&&h.return()}finally{if(e)throw o}}return a}(t,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")},V=2*Math.PI;return function(t){var r=t.px,a=t.py,n=t.cx,e=t.cy,u=t.rx,c=t.ry,o=t.xAxisRotation,i=void 0===o?0:o,h=t.largeArcFlag,f=void 0===h?0:h,s=t.sweepFlag,y=void 0===s?0:s,M=[];if(0===u||0===c)return[];var p=Math.sin(i*V/360),v=Math.cos(i*V/360),x=v*(r-n)/2+p*(a-e)/2,l=-p*(r-n)/2+v*(a-e)/2;if(0==x&&0==l)return[];u=Math.abs(u),c=Math.abs(c);var d=Math.pow(x,2)/Math.pow(u,2)+Math.pow(l,2)/Math.pow(c,2);1<d&&(u*=Math.sqrt(d),c*=Math.sqrt(d));var w=function(t,r,a,n,e,o,i,h,u,c,f,s){var y=Math.pow(e,2),M=Math.pow(o,2),p=Math.pow(f,2),v=Math.pow(s,2),x=y*M-y*v-M*p;x<0&&(x=0),x/=y*v+M*p;var l=(x=Math.sqrt(x)*(i===h?-1:1))*e/o*s,d=x*-o/e*f,w=c*l-u*d+(t+a)/2,b=u*l+c*d+(r+n)/2,m=(f-l)/e,A=(s-d)/o,g=(-f-l)/e,q=(-s-d)/o,S=P(1,0,m,A),j=P(m,A,g,q);return 0===h&&0<j&&(j-=V),1===h&&j<0&&(j+=V),[w,b,S,j]}(r,a,n,e,u,c,f,y,p,v,x,l),b=R(w,4),m=b[0],A=b[1],g=b[2],q=b[3],S=Math.abs(q)/(V/4);Math.abs(1-S)<1e-7&&(S=1);var j,F,I,T,z,B,C,E=Math.max(Math.ceil(S),1);q/=E;for(var G=0;G<E;G++)M.push((j=g,void 0,I=1.5707963267948966===(F=q)?.551915024494:-1.5707963267948966===F?-.551915024494:4/3*Math.tan(F/4),T=Math.cos(j),z=Math.sin(j),B=Math.cos(j+F),C=Math.sin(j+F),[{x:T-z*I,y:z+T*I},{x:B+C*I,y:C-B*I},{x:B,y:C}])),g+=q;return M.map(function(t){var r=O(t[0],u,c,v,p,m,A),a=r.x,n=r.y,e=O(t[1],u,c,v,p,m,A),o=e.x,i=e.y,h=O(t[2],u,c,v,p,m,A);return{x1:a,y1:n,x2:o,y2:i,x:h.x,y:h.y}})}});

183
node_modules/svg-arc-to-cubic-bezier/modules/index.js generated vendored Normal file
View File

@@ -0,0 +1,183 @@
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var TAU = Math.PI * 2;
var mapToEllipse = function mapToEllipse(_ref, rx, ry, cosphi, sinphi, centerx, centery) {
var x = _ref.x,
y = _ref.y;
x *= rx;
y *= ry;
var xp = cosphi * x - sinphi * y;
var yp = sinphi * x + cosphi * y;
return {
x: xp + centerx,
y: yp + centery
};
};
var approxUnitArc = function approxUnitArc(ang1, ang2) {
// If 90 degree circular arc, use a constant
// as derived from http://spencermortensen.com/articles/bezier-circle
var a = ang2 === 1.5707963267948966 ? 0.551915024494 : ang2 === -1.5707963267948966 ? -0.551915024494 : 4 / 3 * Math.tan(ang2 / 4);
var x1 = Math.cos(ang1);
var y1 = Math.sin(ang1);
var x2 = Math.cos(ang1 + ang2);
var y2 = Math.sin(ang1 + ang2);
return [{
x: x1 - y1 * a,
y: y1 + x1 * a
}, {
x: x2 + y2 * a,
y: y2 - x2 * a
}, {
x: x2,
y: y2
}];
};
var vectorAngle = function vectorAngle(ux, uy, vx, vy) {
var sign = ux * vy - uy * vx < 0 ? -1 : 1;
var dot = ux * vx + uy * vy;
if (dot > 1) {
dot = 1;
}
if (dot < -1) {
dot = -1;
}
return sign * Math.acos(dot);
};
var getArcCenter = function getArcCenter(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinphi, cosphi, pxp, pyp) {
var rxsq = Math.pow(rx, 2);
var rysq = Math.pow(ry, 2);
var pxpsq = Math.pow(pxp, 2);
var pypsq = Math.pow(pyp, 2);
var radicant = rxsq * rysq - rxsq * pypsq - rysq * pxpsq;
if (radicant < 0) {
radicant = 0;
}
radicant /= rxsq * pypsq + rysq * pxpsq;
radicant = Math.sqrt(radicant) * (largeArcFlag === sweepFlag ? -1 : 1);
var centerxp = radicant * rx / ry * pyp;
var centeryp = radicant * -ry / rx * pxp;
var centerx = cosphi * centerxp - sinphi * centeryp + (px + cx) / 2;
var centery = sinphi * centerxp + cosphi * centeryp + (py + cy) / 2;
var vx1 = (pxp - centerxp) / rx;
var vy1 = (pyp - centeryp) / ry;
var vx2 = (-pxp - centerxp) / rx;
var vy2 = (-pyp - centeryp) / ry;
var ang1 = vectorAngle(1, 0, vx1, vy1);
var ang2 = vectorAngle(vx1, vy1, vx2, vy2);
if (sweepFlag === 0 && ang2 > 0) {
ang2 -= TAU;
}
if (sweepFlag === 1 && ang2 < 0) {
ang2 += TAU;
}
return [centerx, centery, ang1, ang2];
};
var arcToBezier = function arcToBezier(_ref2) {
var px = _ref2.px,
py = _ref2.py,
cx = _ref2.cx,
cy = _ref2.cy,
rx = _ref2.rx,
ry = _ref2.ry,
_ref2$xAxisRotation = _ref2.xAxisRotation,
xAxisRotation = _ref2$xAxisRotation === undefined ? 0 : _ref2$xAxisRotation,
_ref2$largeArcFlag = _ref2.largeArcFlag,
largeArcFlag = _ref2$largeArcFlag === undefined ? 0 : _ref2$largeArcFlag,
_ref2$sweepFlag = _ref2.sweepFlag,
sweepFlag = _ref2$sweepFlag === undefined ? 0 : _ref2$sweepFlag;
var curves = [];
if (rx === 0 || ry === 0) {
return [];
}
var sinphi = Math.sin(xAxisRotation * TAU / 360);
var cosphi = Math.cos(xAxisRotation * TAU / 360);
var pxp = cosphi * (px - cx) / 2 + sinphi * (py - cy) / 2;
var pyp = -sinphi * (px - cx) / 2 + cosphi * (py - cy) / 2;
if (pxp === 0 && pyp === 0) {
return [];
}
rx = Math.abs(rx);
ry = Math.abs(ry);
var lambda = Math.pow(pxp, 2) / Math.pow(rx, 2) + Math.pow(pyp, 2) / Math.pow(ry, 2);
if (lambda > 1) {
rx *= Math.sqrt(lambda);
ry *= Math.sqrt(lambda);
}
var _getArcCenter = getArcCenter(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinphi, cosphi, pxp, pyp),
_getArcCenter2 = _slicedToArray(_getArcCenter, 4),
centerx = _getArcCenter2[0],
centery = _getArcCenter2[1],
ang1 = _getArcCenter2[2],
ang2 = _getArcCenter2[3];
// If 'ang2' == 90.0000000001, then `ratio` will evaluate to
// 1.0000000001. This causes `segments` to be greater than one, which is an
// unecessary split, and adds extra points to the bezier curve. To alleviate
// this issue, we round to 1.0 when the ratio is close to 1.0.
var ratio = Math.abs(ang2) / (TAU / 4);
if (Math.abs(1.0 - ratio) < 0.0000001) {
ratio = 1.0;
}
var segments = Math.max(Math.ceil(ratio), 1);
ang2 /= segments;
for (var i = 0; i < segments; i++) {
curves.push(approxUnitArc(ang1, ang2));
ang1 += ang2;
}
return curves.map(function (curve) {
var _mapToEllipse = mapToEllipse(curve[0], rx, ry, cosphi, sinphi, centerx, centery),
x1 = _mapToEllipse.x,
y1 = _mapToEllipse.y;
var _mapToEllipse2 = mapToEllipse(curve[1], rx, ry, cosphi, sinphi, centerx, centery),
x2 = _mapToEllipse2.x,
y2 = _mapToEllipse2.y;
var _mapToEllipse3 = mapToEllipse(curve[2], rx, ry, cosphi, sinphi, centerx, centery),
x = _mapToEllipse3.x,
y = _mapToEllipse3.y;
return { x1: x1, y1: y1, x2: x2, y2: y2, x: x, y: y };
});
};
export default arcToBezier;

106
node_modules/svg-arc-to-cubic-bezier/package.json generated vendored Normal file
View File

@@ -0,0 +1,106 @@
{
"author": {
"name": "Colin Meinke",
"email": "hello@colinmeinke.com",
"url": "https://colinmeinke.com"
},
"babel": {
"env": {
"cjs": {
"plugins": [
"transform-object-rest-spread",
"add-module-exports"
],
"presets": [
"es2015"
]
},
"modules": {
"plugins": [
"transform-object-rest-spread"
],
"presets": [
[
"es2015",
{
"modules": false
}
]
]
},
"umd": {
"plugins": [
"transform-object-rest-spread"
],
"presets": [
[
"es2015",
{
"modules": false
}
]
]
}
}
},
"bugs": {
"url": "https://github.com/colinmeinke/svg-arc-to-cubic-bezier/issues"
},
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
}
},
"description": "A function that takes an SVG arc curve as input, and maps it to one or more cubic bezier curves",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-plugin-add-module-exports": "^0.3.3",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"commitizen": "^3.1.1",
"cz-conventional-changelog": "^2.1.0",
"rimraf": "^2.6.3",
"rollup": "^1.16.6",
"rollup-plugin-babel": "^3.0.7",
"rollup-plugin-commonjs": "^10.0.1",
"rollup-plugin-uglify": "^6.0.2",
"snazzy": "^8.0.0",
"standard": "^12.0.1",
"travis-deploy-once": "^5.0.11",
"semantic-release": "^15.13.18"
},
"keywords": [
"arc",
"bezier",
"convert",
"cubic",
"curve",
"path",
"svg"
],
"license": "ISC",
"main": "cjs/index.js",
"module": "modules/index.js",
"name": "svg-arc-to-cubic-bezier",
"repository": {
"type": "git",
"url": "https://github.com/colinmeinke/svg-arc-to-cubic-bezier"
},
"scripts": {
"build": "npm run build:modules && npm run build:cjs && npm run build:umd",
"build:cjs": "BABEL_ENV=cjs babel src --out-dir cjs",
"build:modules": "BABEL_ENV=modules babel src --out-dir modules",
"build:umd": "npm run build:umd:dev && npm run build:umd:pro",
"build:umd:dev": "BABEL_ENV=umd rollup -c",
"build:umd:pro": "NODE_ENV=production BABEL_ENV=umd rollup -c",
"commit": "git-cz",
"fix": "standard --fix",
"lint": "standard --verbose | snazzy",
"prepublish": "npm run tidy && npm run build",
"semantic-release": "semantic-release",
"tidy": "rimraf modules cjs dist",
"travis-deploy-once": "travis-deploy-once"
},
"version": "3.2.0"
}

196
node_modules/svg-arc-to-cubic-bezier/src/index.js generated vendored Normal file
View File

@@ -0,0 +1,196 @@
const TAU = Math.PI * 2
const mapToEllipse = ({ x, y }, rx, ry, cosphi, sinphi, centerx, centery) => {
x *= rx
y *= ry
const xp = cosphi * x - sinphi * y
const yp = sinphi * x + cosphi * y
return {
x: xp + centerx,
y: yp + centery
}
}
const approxUnitArc = (ang1, ang2) => {
// If 90 degree circular arc, use a constant
// as derived from http://spencermortensen.com/articles/bezier-circle
const a = ang2 === 1.5707963267948966
? 0.551915024494
: ang2 === -1.5707963267948966
? -0.551915024494
: 4 / 3 * Math.tan(ang2 / 4)
const x1 = Math.cos(ang1)
const y1 = Math.sin(ang1)
const x2 = Math.cos(ang1 + ang2)
const y2 = Math.sin(ang1 + ang2)
return [
{
x: x1 - y1 * a,
y: y1 + x1 * a
},
{
x: x2 + y2 * a,
y: y2 - x2 * a
},
{
x: x2,
y: y2
}
]
}
const vectorAngle = (ux, uy, vx, vy) => {
const sign = (ux * vy - uy * vx < 0) ? -1 : 1
let dot = ux * vx + uy * vy
if (dot > 1) {
dot = 1
}
if (dot < -1) {
dot = -1
}
return sign * Math.acos(dot)
}
const getArcCenter = (
px,
py,
cx,
cy,
rx,
ry,
largeArcFlag,
sweepFlag,
sinphi,
cosphi,
pxp,
pyp
) => {
const rxsq = Math.pow(rx, 2)
const rysq = Math.pow(ry, 2)
const pxpsq = Math.pow(pxp, 2)
const pypsq = Math.pow(pyp, 2)
let radicant = (rxsq * rysq) - (rxsq * pypsq) - (rysq * pxpsq)
if (radicant < 0) {
radicant = 0
}
radicant /= (rxsq * pypsq) + (rysq * pxpsq)
radicant = Math.sqrt(radicant) * (largeArcFlag === sweepFlag ? -1 : 1)
const centerxp = radicant * rx / ry * pyp
const centeryp = radicant * -ry / rx * pxp
const centerx = cosphi * centerxp - sinphi * centeryp + (px + cx) / 2
const centery = sinphi * centerxp + cosphi * centeryp + (py + cy) / 2
const vx1 = (pxp - centerxp) / rx
const vy1 = (pyp - centeryp) / ry
const vx2 = (-pxp - centerxp) / rx
const vy2 = (-pyp - centeryp) / ry
let ang1 = vectorAngle(1, 0, vx1, vy1)
let ang2 = vectorAngle(vx1, vy1, vx2, vy2)
if (sweepFlag === 0 && ang2 > 0) {
ang2 -= TAU
}
if (sweepFlag === 1 && ang2 < 0) {
ang2 += TAU
}
return [ centerx, centery, ang1, ang2 ]
}
const arcToBezier = ({
px,
py,
cx,
cy,
rx,
ry,
xAxisRotation = 0,
largeArcFlag = 0,
sweepFlag = 0
}) => {
const curves = []
if (rx === 0 || ry === 0) {
return []
}
const sinphi = Math.sin(xAxisRotation * TAU / 360)
const cosphi = Math.cos(xAxisRotation * TAU / 360)
const pxp = cosphi * (px - cx) / 2 + sinphi * (py - cy) / 2
const pyp = -sinphi * (px - cx) / 2 + cosphi * (py - cy) / 2
if (pxp === 0 && pyp === 0) {
return []
}
rx = Math.abs(rx)
ry = Math.abs(ry)
const lambda =
Math.pow(pxp, 2) / Math.pow(rx, 2) +
Math.pow(pyp, 2) / Math.pow(ry, 2)
if (lambda > 1) {
rx *= Math.sqrt(lambda)
ry *= Math.sqrt(lambda)
}
let [ centerx, centery, ang1, ang2 ] = getArcCenter(
px,
py,
cx,
cy,
rx,
ry,
largeArcFlag,
sweepFlag,
sinphi,
cosphi,
pxp,
pyp
)
// If 'ang2' == 90.0000000001, then `ratio` will evaluate to
// 1.0000000001. This causes `segments` to be greater than one, which is an
// unecessary split, and adds extra points to the bezier curve. To alleviate
// this issue, we round to 1.0 when the ratio is close to 1.0.
let ratio = Math.abs(ang2) / (TAU / 4)
if (Math.abs(1.0 - ratio) < 0.0000001) {
ratio = 1.0
}
const segments = Math.max(Math.ceil(ratio), 1)
ang2 /= segments
for (let i = 0; i < segments; i++) {
curves.push(approxUnitArc(ang1, ang2))
ang1 += ang2
}
return curves.map(curve => {
const { x: x1, y: y1 } = mapToEllipse(curve[ 0 ], rx, ry, cosphi, sinphi, centerx, centery)
const { x: x2, y: y2 } = mapToEllipse(curve[ 1 ], rx, ry, cosphi, sinphi, centerx, centery)
const { x, y } = mapToEllipse(curve[ 2 ], rx, ry, cosphi, sinphi, centerx, centery)
return { x1, y1, x2, y2, x, y }
})
}
export default arcToBezier