mirror of
https://github.com/nunocoracao/blowfish.git
synced 2026-01-30 16:31:52 +01:00
config redirect
This commit is contained in:
13
node_modules/d3-path/LICENSE
generated
vendored
Normal file
13
node_modules/d3-path/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
Copyright 2015-2021 Mike Bostock
|
||||
|
||||
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.
|
||||
90
node_modules/d3-path/README.md
generated
vendored
Normal file
90
node_modules/d3-path/README.md
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
# d3-path
|
||||
|
||||
Say you have some code that draws to a 2D canvas:
|
||||
|
||||
```js
|
||||
function drawCircle(context, radius) {
|
||||
context.moveTo(radius, 0);
|
||||
context.arc(0, 0, radius, 0, 2 * Math.PI);
|
||||
}
|
||||
```
|
||||
|
||||
The d3-path module lets you take this exact code and additionally render to [SVG](http://www.w3.org/TR/SVG/paths.html). It works by [serializing](#path_toString) [CanvasPathMethods](http://www.w3.org/TR/2dcontext/#canvaspathmethods) calls to [SVG path data](http://www.w3.org/TR/SVG/paths.html#PathData). For example:
|
||||
|
||||
```js
|
||||
const context = d3.path();
|
||||
drawCircle(context, 40);
|
||||
pathElement.setAttribute("d", context.toString());
|
||||
```
|
||||
|
||||
Now code you write once can be used with both Canvas (for performance) and SVG (for convenience). For a practical example, see [d3-shape](https://github.com/d3/d3-shape).
|
||||
|
||||
## Installing
|
||||
|
||||
If you use npm, `npm install d3-path`. You can also download the [latest release on GitHub](https://github.com/d3/d3-path/releases/latest). In modern browsers, you can import d3-path from Skypack:
|
||||
|
||||
```html
|
||||
<script type="module">
|
||||
|
||||
import {path} from "https://cdn.skypack.dev/d3-path@3";
|
||||
|
||||
const p = path();
|
||||
p.moveTo(1, 2);
|
||||
p.lineTo(3, 4);
|
||||
p.closePath();
|
||||
|
||||
</script>
|
||||
```
|
||||
|
||||
For legacy environments, you can load d3-path’s UMD bundle from an npm-based CDN such as jsDelivr; a `d3` global is exported:
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/d3-path@3"></script>
|
||||
<script>
|
||||
|
||||
const path = d3.path();
|
||||
|
||||
</script>
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
<a name="path" href="#path">#</a> d3.<b>path</b>() · [Source](https://github.com/d3/d3-path/blob/master/src/path.js), [Examples](https://observablehq.com/@d3/d3-path)
|
||||
|
||||
Constructs a new path serializer that implements [CanvasPathMethods](http://www.w3.org/TR/2dcontext/#canvaspathmethods).
|
||||
|
||||
<a name="path_moveTo" href="#path_moveTo">#</a> <i>path</i>.<b>moveTo</b>(<i>x</i>, <i>y</i>)
|
||||
|
||||
Move to the specified point ⟨*x*, *y*⟩. Equivalent to [*context*.moveTo](http://www.w3.org/TR/2dcontext/#dom-context-2d-moveto) and SVG’s [“moveto” command](http://www.w3.org/TR/SVG/paths.html#PathDataMovetoCommands).
|
||||
|
||||
<a name="path_closePath" href="#path_closePath">#</a> <i>path</i>.<b>closePath</b>()
|
||||
|
||||
Ends the current subpath and causes an automatic straight line to be drawn from the current point to the initial point of the current subpath. Equivalent to [*context*.closePath](http://www.w3.org/TR/2dcontext/#dom-context-2d-closepath) and SVG’s [“closepath” command](http://www.w3.org/TR/SVG/paths.html#PathDataClosePathCommand).
|
||||
|
||||
<a name="path_lineTo" href="#path_lineTo">#</a> <i>path</i>.<b>lineTo</b>(<i>x</i>, <i>y</i>)
|
||||
|
||||
Draws a straight line from the current point to the specified point ⟨*x*, *y*⟩. Equivalent to [*context*.lineTo](http://www.w3.org/TR/2dcontext/#dom-context-2d-lineto) and SVG’s [“lineto” command](http://www.w3.org/TR/SVG/paths.html#PathDataLinetoCommands).
|
||||
|
||||
<a name="path_quadraticCurveTo" href="#path_quadraticCurveTo">#</a> <i>path</i>.<b>quadraticCurveTo</b>(<i>cpx</i>, <i>cpy</i>, <i>x</i>, <i>y</i>)
|
||||
|
||||
Draws a quadratic Bézier segment from the current point to the specified point ⟨*x*, *y*⟩, with the specified control point ⟨*cpx*, *cpy*⟩. Equivalent to [*context*.quadraticCurveTo](http://www.w3.org/TR/2dcontext/#dom-context-2d-quadraticcurveto) and SVG’s [quadratic Bézier curve commands](http://www.w3.org/TR/SVG/paths.html#PathDataQuadraticBezierCommands).
|
||||
|
||||
<a name="path_bezierCurveTo" href="#path_bezierCurveTo">#</a> <i>path</i>.<b>bezierCurveTo</b>(<i>cpx1</i>, <i>cpy1</i>, <i>cpx2</i>, <i>cpy2</i>, <i>x</i>, <i>y</i>)
|
||||
|
||||
Draws a cubic Bézier segment from the current point to the specified point ⟨*x*, *y*⟩, with the specified control points ⟨*cpx1*, *cpy1*⟩ and ⟨*cpx2*, *cpy2*⟩. Equivalent to [*context*.bezierCurveTo](http://www.w3.org/TR/2dcontext/#dom-context-2d-beziercurveto) and SVG’s [cubic Bézier curve commands](http://www.w3.org/TR/SVG/paths.html#PathDataCubicBezierCommands).
|
||||
|
||||
<a name="path_arcTo" href="#path_arcTo">#</a> <i>path</i>.<b>arcTo</b>(<i>x1</i>, <i>y1</i>, <i>x2</i>, <i>y2</i>, <i>radius</i>)
|
||||
|
||||
Draws a circular arc segment with the specified *radius* that starts tangent to the line between the current point and the specified point ⟨*x1*, *y1*⟩ and ends tangent to the line between the specified points ⟨*x1*, *y1*⟩ and ⟨*x2*, *y2*⟩. If the first tangent point is not equal to the current point, a straight line is drawn between the current point and the first tangent point. Equivalent to [*context*.arcTo](http://www.w3.org/TR/2dcontext/#dom-context-2d-arcto) and uses SVG’s [elliptical arc curve commands](http://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands).
|
||||
|
||||
<a name="path_arc" href="#path_arc">#</a> <i>path</i>.<b>arc</b>(<i>x</i>, <i>y</i>, <i>radius</i>, <i>startAngle</i>, <i>endAngle</i>[, <i>anticlockwise</i>])
|
||||
|
||||
Draws a circular arc segment with the specified center ⟨*x*, *y*⟩, *radius*, *startAngle* and *endAngle*. If *anticlockwise* is true, the arc is drawn in the anticlockwise direction; otherwise, it is drawn in the clockwise direction. If the current point is not equal to the starting point of the arc, a straight line is drawn from the current point to the start of the arc. Equivalent to [*context*.arc](http://www.w3.org/TR/2dcontext/#dom-context-2d-arc) and uses SVG’s [elliptical arc curve commands](http://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands).
|
||||
|
||||
<a name="path_rect" href="#path_rect">#</a> <i>path</i>.<b>rect</b>(<i>x</i>, <i>y</i>, <i>w</i>, <i>h</i>)
|
||||
|
||||
Creates a new subpath containing just the four points ⟨*x*, *y*⟩, ⟨*x* + *w*, *y*⟩, ⟨*x* + *w*, *y* + *h*⟩, ⟨*x*, *y* + *h*⟩, with those four points connected by straight lines, and then marks the subpath as closed. Equivalent to [*context*.rect](http://www.w3.org/TR/2dcontext/#dom-context-2d-rect) and uses SVG’s [“lineto” commands](http://www.w3.org/TR/SVG/paths.html#PathDataLinetoCommands).
|
||||
|
||||
<a name="path_toString" href="#path_toString">#</a> <i>path</i>.<b>toString</b>()
|
||||
|
||||
Returns the string representation of this *path* according to SVG’s [path data specification](http://www.w3.org/TR/SVG/paths.html#PathData).
|
||||
141
node_modules/d3-path/dist/d3-path.js
generated
vendored
Normal file
141
node_modules/d3-path/dist/d3-path.js
generated
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
// https://d3js.org/d3-path/ v3.0.1 Copyright 2015-2021 Mike Bostock
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
||||
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}));
|
||||
}(this, (function (exports) { 'use strict';
|
||||
|
||||
const pi = Math.PI,
|
||||
tau = 2 * pi,
|
||||
epsilon = 1e-6,
|
||||
tauEpsilon = tau - epsilon;
|
||||
|
||||
function Path() {
|
||||
this._x0 = this._y0 = // start of current subpath
|
||||
this._x1 = this._y1 = null; // end of current subpath
|
||||
this._ = "";
|
||||
}
|
||||
|
||||
function path() {
|
||||
return new Path;
|
||||
}
|
||||
|
||||
Path.prototype = path.prototype = {
|
||||
constructor: Path,
|
||||
moveTo: function(x, y) {
|
||||
this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
|
||||
},
|
||||
closePath: function() {
|
||||
if (this._x1 !== null) {
|
||||
this._x1 = this._x0, this._y1 = this._y0;
|
||||
this._ += "Z";
|
||||
}
|
||||
},
|
||||
lineTo: function(x, y) {
|
||||
this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
|
||||
},
|
||||
quadraticCurveTo: function(x1, y1, x, y) {
|
||||
this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
|
||||
},
|
||||
bezierCurveTo: function(x1, y1, x2, y2, x, y) {
|
||||
this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
|
||||
},
|
||||
arcTo: function(x1, y1, x2, y2, r) {
|
||||
x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
|
||||
var x0 = this._x1,
|
||||
y0 = this._y1,
|
||||
x21 = x2 - x1,
|
||||
y21 = y2 - y1,
|
||||
x01 = x0 - x1,
|
||||
y01 = y0 - y1,
|
||||
l01_2 = x01 * x01 + y01 * y01;
|
||||
|
||||
// Is the radius negative? Error.
|
||||
if (r < 0) throw new Error("negative radius: " + r);
|
||||
|
||||
// Is this path empty? Move to (x1,y1).
|
||||
if (this._x1 === null) {
|
||||
this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
|
||||
}
|
||||
|
||||
// Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
|
||||
else if (!(l01_2 > epsilon));
|
||||
|
||||
// Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
|
||||
// Equivalently, is (x1,y1) coincident with (x2,y2)?
|
||||
// Or, is the radius zero? Line to (x1,y1).
|
||||
else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon) || !r) {
|
||||
this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
|
||||
}
|
||||
|
||||
// Otherwise, draw an arc!
|
||||
else {
|
||||
var x20 = x2 - x0,
|
||||
y20 = y2 - y0,
|
||||
l21_2 = x21 * x21 + y21 * y21,
|
||||
l20_2 = x20 * x20 + y20 * y20,
|
||||
l21 = Math.sqrt(l21_2),
|
||||
l01 = Math.sqrt(l01_2),
|
||||
l = r * Math.tan((pi - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
|
||||
t01 = l / l01,
|
||||
t21 = l / l21;
|
||||
|
||||
// If the start tangent is not coincident with (x0,y0), line to.
|
||||
if (Math.abs(t01 - 1) > epsilon) {
|
||||
this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
|
||||
}
|
||||
|
||||
this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
|
||||
}
|
||||
},
|
||||
arc: function(x, y, r, a0, a1, ccw) {
|
||||
x = +x, y = +y, r = +r, ccw = !!ccw;
|
||||
var dx = r * Math.cos(a0),
|
||||
dy = r * Math.sin(a0),
|
||||
x0 = x + dx,
|
||||
y0 = y + dy,
|
||||
cw = 1 ^ ccw,
|
||||
da = ccw ? a0 - a1 : a1 - a0;
|
||||
|
||||
// Is the radius negative? Error.
|
||||
if (r < 0) throw new Error("negative radius: " + r);
|
||||
|
||||
// Is this path empty? Move to (x0,y0).
|
||||
if (this._x1 === null) {
|
||||
this._ += "M" + x0 + "," + y0;
|
||||
}
|
||||
|
||||
// Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
|
||||
else if (Math.abs(this._x1 - x0) > epsilon || Math.abs(this._y1 - y0) > epsilon) {
|
||||
this._ += "L" + x0 + "," + y0;
|
||||
}
|
||||
|
||||
// Is this arc empty? We’re done.
|
||||
if (!r) return;
|
||||
|
||||
// Does the angle go the wrong way? Flip the direction.
|
||||
if (da < 0) da = da % tau + tau;
|
||||
|
||||
// Is this a complete circle? Draw two arcs to complete the circle.
|
||||
if (da > tauEpsilon) {
|
||||
this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
|
||||
}
|
||||
|
||||
// Is this arc non-empty? Draw an arc!
|
||||
else if (da > epsilon) {
|
||||
this._ += "A" + r + "," + r + ",0," + (+(da >= pi)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
|
||||
}
|
||||
},
|
||||
rect: function(x, y, w, h) {
|
||||
this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
|
||||
},
|
||||
toString: function() {
|
||||
return this._;
|
||||
}
|
||||
};
|
||||
|
||||
exports.path = path;
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
})));
|
||||
2
node_modules/d3-path/dist/d3-path.min.js
generated
vendored
Normal file
2
node_modules/d3-path/dist/d3-path.min.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
// https://d3js.org/d3-path/ v3.0.1 Copyright 2015-2021 Mike Bostock
|
||||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).d3=t.d3||{})}(this,(function(t){"use strict";const i=Math.PI,s=2*i,h=1e-6,_=s-h;function e(){this._x0=this._y0=this._x1=this._y1=null,this._=""}function n(){return new e}e.prototype=n.prototype={constructor:e,moveTo:function(t,i){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+i)},closePath:function(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")},lineTo:function(t,i){this._+="L"+(this._x1=+t)+","+(this._y1=+i)},quadraticCurveTo:function(t,i,s,h){this._+="Q"+ +t+","+ +i+","+(this._x1=+s)+","+(this._y1=+h)},bezierCurveTo:function(t,i,s,h,_,e){this._+="C"+ +t+","+ +i+","+ +s+","+ +h+","+(this._x1=+_)+","+(this._y1=+e)},arcTo:function(t,s,_,e,n){t=+t,s=+s,_=+_,e=+e,n=+n;var o=this._x1,r=this._y1,a=_-t,u=e-s,f=o-t,c=r-s,y=f*f+c*c;if(n<0)throw new Error("negative radius: "+n);if(null===this._x1)this._+="M"+(this._x1=t)+","+(this._y1=s);else if(y>h)if(Math.abs(c*a-u*f)>h&&n){var x=_-o,l=e-r,M=a*a+u*u,d=x*x+l*l,p=Math.sqrt(M),v=Math.sqrt(y),b=n*Math.tan((i-Math.acos((M+y-d)/(2*p*v)))/2),T=b/v,g=b/p;Math.abs(T-1)>h&&(this._+="L"+(t+T*f)+","+(s+T*c)),this._+="A"+n+","+n+",0,0,"+ +(c*x>f*l)+","+(this._x1=t+g*a)+","+(this._y1=s+g*u)}else this._+="L"+(this._x1=t)+","+(this._y1=s);else;},arc:function(t,e,n,o,r,a){t=+t,e=+e,a=!!a;var u=(n=+n)*Math.cos(o),f=n*Math.sin(o),c=t+u,y=e+f,x=1^a,l=a?o-r:r-o;if(n<0)throw new Error("negative radius: "+n);null===this._x1?this._+="M"+c+","+y:(Math.abs(this._x1-c)>h||Math.abs(this._y1-y)>h)&&(this._+="L"+c+","+y),n&&(l<0&&(l=l%s+s),l>_?this._+="A"+n+","+n+",0,1,"+x+","+(t-u)+","+(e-f)+"A"+n+","+n+",0,1,"+x+","+(this._x1=c)+","+(this._y1=y):l>h&&(this._+="A"+n+","+n+",0,"+ +(l>=i)+","+x+","+(this._x1=t+n*Math.cos(r))+","+(this._y1=e+n*Math.sin(r))))},rect:function(t,i,s,h){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+i)+"h"+ +s+"v"+ +h+"h"+-s+"Z"},toString:function(){return this._}},t.path=n,Object.defineProperty(t,"__esModule",{value:!0})}));
|
||||
54
node_modules/d3-path/package.json
generated
vendored
Normal file
54
node_modules/d3-path/package.json
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"name": "d3-path",
|
||||
"version": "3.0.1",
|
||||
"description": "Serialize Canvas path commands to SVG.",
|
||||
"homepage": "https://d3js.org/d3-path/",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/d3/d3-path.git"
|
||||
},
|
||||
"keywords": [
|
||||
"d3",
|
||||
"d3-module",
|
||||
"canvas",
|
||||
"path",
|
||||
"svg",
|
||||
"graphics",
|
||||
"CanvasRenderingContext2D",
|
||||
"CanvasPathMethods",
|
||||
"Path2D"
|
||||
],
|
||||
"license": "ISC",
|
||||
"author": {
|
||||
"name": "Mike Bostock",
|
||||
"url": "http://bost.ocks.org/mike"
|
||||
},
|
||||
"type": "module",
|
||||
"files": [
|
||||
"dist/**/*.js",
|
||||
"src/**/*.js"
|
||||
],
|
||||
"module": "src/index.js",
|
||||
"main": "src/index.js",
|
||||
"jsdelivr": "dist/d3-path.min.js",
|
||||
"unpkg": "dist/d3-path.min.js",
|
||||
"exports": {
|
||||
"umd": "./dist/d3-path.min.js",
|
||||
"default": "./src/index.js"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"devDependencies": {
|
||||
"eslint": "7",
|
||||
"mocha": "8",
|
||||
"rollup": "2",
|
||||
"rollup-plugin-terser": "7"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha 'test/**/*-test.js' && eslint src test",
|
||||
"prepublishOnly": "rm -rf dist && yarn test && rollup -c",
|
||||
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../${npm_package_name}/dist/${npm_package_name}.js ${npm_package_name}.v${npm_package_version%%.*}.js && cp ../${npm_package_name}/dist/${npm_package_name}.min.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git add ${npm_package_name}.v${npm_package_version%%.*}.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git commit -m \"${npm_package_name} ${npm_package_version}\" && git push && cd -"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
}
|
||||
1
node_modules/d3-path/src/index.js
generated
vendored
Normal file
1
node_modules/d3-path/src/index.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {default as path} from "./path.js";
|
||||
130
node_modules/d3-path/src/path.js
generated
vendored
Normal file
130
node_modules/d3-path/src/path.js
generated
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
const pi = Math.PI,
|
||||
tau = 2 * pi,
|
||||
epsilon = 1e-6,
|
||||
tauEpsilon = tau - epsilon;
|
||||
|
||||
function Path() {
|
||||
this._x0 = this._y0 = // start of current subpath
|
||||
this._x1 = this._y1 = null; // end of current subpath
|
||||
this._ = "";
|
||||
}
|
||||
|
||||
function path() {
|
||||
return new Path;
|
||||
}
|
||||
|
||||
Path.prototype = path.prototype = {
|
||||
constructor: Path,
|
||||
moveTo: function(x, y) {
|
||||
this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
|
||||
},
|
||||
closePath: function() {
|
||||
if (this._x1 !== null) {
|
||||
this._x1 = this._x0, this._y1 = this._y0;
|
||||
this._ += "Z";
|
||||
}
|
||||
},
|
||||
lineTo: function(x, y) {
|
||||
this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
|
||||
},
|
||||
quadraticCurveTo: function(x1, y1, x, y) {
|
||||
this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
|
||||
},
|
||||
bezierCurveTo: function(x1, y1, x2, y2, x, y) {
|
||||
this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
|
||||
},
|
||||
arcTo: function(x1, y1, x2, y2, r) {
|
||||
x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
|
||||
var x0 = this._x1,
|
||||
y0 = this._y1,
|
||||
x21 = x2 - x1,
|
||||
y21 = y2 - y1,
|
||||
x01 = x0 - x1,
|
||||
y01 = y0 - y1,
|
||||
l01_2 = x01 * x01 + y01 * y01;
|
||||
|
||||
// Is the radius negative? Error.
|
||||
if (r < 0) throw new Error("negative radius: " + r);
|
||||
|
||||
// Is this path empty? Move to (x1,y1).
|
||||
if (this._x1 === null) {
|
||||
this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
|
||||
}
|
||||
|
||||
// Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
|
||||
else if (!(l01_2 > epsilon));
|
||||
|
||||
// Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
|
||||
// Equivalently, is (x1,y1) coincident with (x2,y2)?
|
||||
// Or, is the radius zero? Line to (x1,y1).
|
||||
else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon) || !r) {
|
||||
this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
|
||||
}
|
||||
|
||||
// Otherwise, draw an arc!
|
||||
else {
|
||||
var x20 = x2 - x0,
|
||||
y20 = y2 - y0,
|
||||
l21_2 = x21 * x21 + y21 * y21,
|
||||
l20_2 = x20 * x20 + y20 * y20,
|
||||
l21 = Math.sqrt(l21_2),
|
||||
l01 = Math.sqrt(l01_2),
|
||||
l = r * Math.tan((pi - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
|
||||
t01 = l / l01,
|
||||
t21 = l / l21;
|
||||
|
||||
// If the start tangent is not coincident with (x0,y0), line to.
|
||||
if (Math.abs(t01 - 1) > epsilon) {
|
||||
this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
|
||||
}
|
||||
|
||||
this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
|
||||
}
|
||||
},
|
||||
arc: function(x, y, r, a0, a1, ccw) {
|
||||
x = +x, y = +y, r = +r, ccw = !!ccw;
|
||||
var dx = r * Math.cos(a0),
|
||||
dy = r * Math.sin(a0),
|
||||
x0 = x + dx,
|
||||
y0 = y + dy,
|
||||
cw = 1 ^ ccw,
|
||||
da = ccw ? a0 - a1 : a1 - a0;
|
||||
|
||||
// Is the radius negative? Error.
|
||||
if (r < 0) throw new Error("negative radius: " + r);
|
||||
|
||||
// Is this path empty? Move to (x0,y0).
|
||||
if (this._x1 === null) {
|
||||
this._ += "M" + x0 + "," + y0;
|
||||
}
|
||||
|
||||
// Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
|
||||
else if (Math.abs(this._x1 - x0) > epsilon || Math.abs(this._y1 - y0) > epsilon) {
|
||||
this._ += "L" + x0 + "," + y0;
|
||||
}
|
||||
|
||||
// Is this arc empty? We’re done.
|
||||
if (!r) return;
|
||||
|
||||
// Does the angle go the wrong way? Flip the direction.
|
||||
if (da < 0) da = da % tau + tau;
|
||||
|
||||
// Is this a complete circle? Draw two arcs to complete the circle.
|
||||
if (da > tauEpsilon) {
|
||||
this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
|
||||
}
|
||||
|
||||
// Is this arc non-empty? Draw an arc!
|
||||
else if (da > epsilon) {
|
||||
this._ += "A" + r + "," + r + ",0," + (+(da >= pi)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
|
||||
}
|
||||
},
|
||||
rect: function(x, y, w, h) {
|
||||
this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
|
||||
},
|
||||
toString: function() {
|
||||
return this._;
|
||||
}
|
||||
};
|
||||
|
||||
export default path;
|
||||
Reference in New Issue
Block a user