| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.Cardinal = Cardinal;
|
|---|
| 7 | exports.default = void 0;
|
|---|
| 8 | exports.point = point;
|
|---|
| 9 | function point(that, x, y) {
|
|---|
| 10 | that._context.bezierCurveTo(that._x1 + that._k * (that._x2 - that._x0), that._y1 + that._k * (that._y2 - that._y0), that._x2 + that._k * (that._x1 - x), that._y2 + that._k * (that._y1 - y), that._x2, that._y2);
|
|---|
| 11 | }
|
|---|
| 12 | function Cardinal(context, tension) {
|
|---|
| 13 | this._context = context;
|
|---|
| 14 | this._k = (1 - tension) / 6;
|
|---|
| 15 | }
|
|---|
| 16 | Cardinal.prototype = {
|
|---|
| 17 | areaStart: function () {
|
|---|
| 18 | this._line = 0;
|
|---|
| 19 | },
|
|---|
| 20 | areaEnd: function () {
|
|---|
| 21 | this._line = NaN;
|
|---|
| 22 | },
|
|---|
| 23 | lineStart: function () {
|
|---|
| 24 | this._x0 = this._x1 = this._x2 = this._y0 = this._y1 = this._y2 = NaN;
|
|---|
| 25 | this._point = 0;
|
|---|
| 26 | },
|
|---|
| 27 | lineEnd: function () {
|
|---|
| 28 | switch (this._point) {
|
|---|
| 29 | case 2:
|
|---|
| 30 | this._context.lineTo(this._x2, this._y2);
|
|---|
| 31 | break;
|
|---|
| 32 | case 3:
|
|---|
| 33 | point(this, this._x1, this._y1);
|
|---|
| 34 | break;
|
|---|
| 35 | }
|
|---|
| 36 | if (this._line || this._line !== 0 && this._point === 1) this._context.closePath();
|
|---|
| 37 | this._line = 1 - this._line;
|
|---|
| 38 | },
|
|---|
| 39 | point: function (x, y) {
|
|---|
| 40 | x = +x, y = +y;
|
|---|
| 41 | switch (this._point) {
|
|---|
| 42 | case 0:
|
|---|
| 43 | this._point = 1;
|
|---|
| 44 | this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y);
|
|---|
| 45 | break;
|
|---|
| 46 | case 1:
|
|---|
| 47 | this._point = 2;
|
|---|
| 48 | this._x1 = x, this._y1 = y;
|
|---|
| 49 | break;
|
|---|
| 50 | case 2:
|
|---|
| 51 | this._point = 3;
|
|---|
| 52 | // falls through
|
|---|
| 53 | default:
|
|---|
| 54 | point(this, x, y);
|
|---|
| 55 | break;
|
|---|
| 56 | }
|
|---|
| 57 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
|---|
| 58 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
|---|
| 59 | }
|
|---|
| 60 | };
|
|---|
| 61 | var _default = exports.default = function custom(tension) {
|
|---|
| 62 | function cardinal(context) {
|
|---|
| 63 | return new Cardinal(context, tension);
|
|---|
| 64 | }
|
|---|
| 65 | cardinal.tension = function (tension) {
|
|---|
| 66 | return custom(+tension);
|
|---|
| 67 | };
|
|---|
| 68 | return cardinal;
|
|---|
| 69 | }(0); |
|---|