1 | const p = Math.PI, v = 2 * p, c = 1e-6, q = v - c;
|
2 | function y() {
|
3 | this._x0 = this._y0 =
|
4 | this._x1 = this._y1 = null, this._ = "";
|
5 | }
|
6 | function C() {
|
7 | return new y();
|
8 | }
|
9 | y.prototype = C.prototype = {
|
10 | constructor: y,
|
11 | moveTo: function(i, s) {
|
12 | this._ += "M" + (this._x0 = this._x1 = +i) + "," + (this._y0 = this._y1 = +s);
|
13 | },
|
14 | closePath: function() {
|
15 | this._x1 !== null && (this._x1 = this._x0, this._y1 = this._y0, this._ += "Z");
|
16 | },
|
17 | lineTo: function(i, s) {
|
18 | this._ += "L" + (this._x1 = +i) + "," + (this._y1 = +s);
|
19 | },
|
20 | quadraticCurveTo: function(i, s, t, h) {
|
21 | this._ += "Q" + +i + "," + +s + "," + (this._x1 = +t) + "," + (this._y1 = +h);
|
22 | },
|
23 | bezierCurveTo: function(i, s, t, h, _, e) {
|
24 | this._ += "C" + +i + "," + +s + "," + +t + "," + +h + "," + (this._x1 = +_) + "," + (this._y1 = +e);
|
25 | },
|
26 | arcTo: function(i, s, t, h, _) {
|
27 | i = +i, s = +s, t = +t, h = +h, _ = +_;
|
28 | var e = this._x1, r = this._y1, f = t - i, a = h - s, n = e - i, u = r - s, o = n * n + u * u;
|
29 | if (_ < 0)
|
30 | throw new Error("negative radius: " + _);
|
31 | if (this._x1 === null)
|
32 | this._ += "M" + (this._x1 = i) + "," + (this._y1 = s);
|
33 | else if (o > c)
|
34 | if (!(Math.abs(u * f - a * n) > c) || !_)
|
35 | this._ += "L" + (this._x1 = i) + "," + (this._y1 = s);
|
36 | else {
|
37 | var M = t - e, l = h - r, d = f * f + a * a, g = M * M + l * l, b = Math.sqrt(d), T = Math.sqrt(o), A = _ * Math.tan((p - Math.acos((d + o - g) / (2 * b * T))) / 2), x = A / T, L = A / b;
|
38 | Math.abs(x - 1) > c && (this._ += "L" + (i + x * n) + "," + (s + x * u)), this._ += "A" + _ + "," + _ + ",0,0," + +(u * M > n * l) + "," + (this._x1 = i + L * f) + "," + (this._y1 = s + L * a);
|
39 | }
|
40 | },
|
41 | arc: function(i, s, t, h, _, e) {
|
42 | i = +i, s = +s, t = +t, e = !!e;
|
43 | var r = t * Math.cos(h), f = t * Math.sin(h), a = i + r, n = s + f, u = 1 ^ e, o = e ? h - _ : _ - h;
|
44 | if (t < 0)
|
45 | throw new Error("negative radius: " + t);
|
46 | this._x1 === null ? this._ += "M" + a + "," + n : (Math.abs(this._x1 - a) > c || Math.abs(this._y1 - n) > c) && (this._ += "L" + a + "," + n), t && (o < 0 && (o = o % v + v), o > q ? this._ += "A" + t + "," + t + ",0,1," + u + "," + (i - r) + "," + (s - f) + "A" + t + "," + t + ",0,1," + u + "," + (this._x1 = a) + "," + (this._y1 = n) : o > c && (this._ += "A" + t + "," + t + ",0," + +(o >= p) + "," + u + "," + (this._x1 = i + t * Math.cos(_)) + "," + (this._y1 = s + t * Math.sin(_))));
|
47 | },
|
48 | rect: function(i, s, t, h) {
|
49 | this._ += "M" + (this._x0 = this._x1 = +i) + "," + (this._y0 = this._y1 = +s) + "h" + +t + "v" + +h + "h" + -t + "Z";
|
50 | },
|
51 | toString: function() {
|
52 | return this._;
|
53 | }
|
54 | };
|
55 | function E(i) {
|
56 | return function() {
|
57 | return i;
|
58 | };
|
59 | }
|
60 | export {
|
61 | E as c,
|
62 | C as p
|
63 | };
|