plotboilerplate 1.12.9 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/changelog.md +34 -0
- package/dist/index.esm.js +435 -92
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/plotboilerplate.browser.min.js +1 -1
- package/dist/plotboilerplate.browser.min.js.map +1 -1
- package/dist/plotboilerplate.js +449 -91
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +1 -1
- package/src/cjs/BezierPath.d.ts +12 -1
- package/src/cjs/BezierPath.js +34 -5
- package/src/cjs/BezierPath.js.map +1 -1
- package/src/cjs/PBText.d.ts +116 -0
- package/src/cjs/PBText.js +66 -0
- package/src/cjs/PBText.js.map +1 -0
- package/src/cjs/PlotBoilerplate.d.ts +2 -1
- package/src/cjs/PlotBoilerplate.js +43 -15
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +22 -1
- package/src/cjs/Polygon.js +102 -39
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Vertex.d.ts +42 -4
- package/src/cjs/Vertex.js +62 -7
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/draw.d.ts +30 -2
- package/src/cjs/draw.js +51 -6
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawgl.d.ts +29 -2
- package/src/cjs/drawgl.js +21 -4
- package/src/cjs/drawgl.js.map +1 -1
- package/src/cjs/drawutilssvg.d.ts +25 -7
- package/src/cjs/drawutilssvg.js +62 -14
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/entry.js +1 -0
- package/src/cjs/index.d.ts +1 -0
- package/src/cjs/index.js +1 -0
- package/src/cjs/index.js.map +1 -1
- package/src/cjs/interfaces/DrawLib.d.ts +27 -6
- package/src/cjs/interfaces/DrawLib.js +3 -0
- package/src/cjs/interfaces/DrawLib.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +9 -1
- package/src/cjs/interfaces/core.js +1 -0
- package/src/cjs/interfaces/core.js.map +1 -1
- package/src/cjs/utils/datastructures/Color.d.ts +28 -15
- package/src/cjs/utils/datastructures/Color.js +276 -88
- package/src/cjs/utils/datastructures/Color.js.map +1 -1
- package/src/cjs/utils/findInVertexArray.d.ts +19 -0
- package/src/cjs/utils/findInVertexArray.js +29 -0
- package/src/cjs/utils/findInVertexArray.js.map +1 -0
- package/src/esm/BezierPath.d.ts +12 -1
- package/src/esm/BezierPath.js +34 -5
- package/src/esm/BezierPath.js.map +1 -1
- package/src/esm/PBText.d.ts +116 -0
- package/src/esm/PBText.js +61 -0
- package/src/esm/PBText.js.map +1 -0
- package/src/esm/PlotBoilerplate.d.ts +2 -1
- package/src/esm/PlotBoilerplate.js +43 -15
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +22 -1
- package/src/esm/Polygon.js +102 -39
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Vertex.d.ts +42 -4
- package/src/esm/Vertex.js +62 -7
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/draw.d.ts +30 -2
- package/src/esm/draw.js +51 -6
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawgl.d.ts +29 -2
- package/src/esm/drawgl.js +21 -4
- package/src/esm/drawgl.js.map +1 -1
- package/src/esm/drawutilssvg.d.ts +25 -7
- package/src/esm/drawutilssvg.js +62 -14
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/entry.js +1 -0
- package/src/esm/index.d.ts +1 -0
- package/src/esm/index.js +1 -0
- package/src/esm/index.js.map +1 -1
- package/src/esm/interfaces/DrawLib.d.ts +27 -6
- package/src/esm/interfaces/DrawLib.js +3 -0
- package/src/esm/interfaces/DrawLib.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +9 -1
- package/src/esm/interfaces/core.js +1 -0
- package/src/esm/interfaces/core.js.map +1 -1
- package/src/esm/utils/datastructures/Color.d.ts +28 -15
- package/src/esm/utils/datastructures/Color.js +277 -89
- package/src/esm/utils/datastructures/Color.js.map +1 -1
- package/src/esm/utils/findInVertexArray.d.ts +19 -0
- package/src/esm/utils/findInVertexArray.js +25 -0
- package/src/esm/utils/findInVertexArray.js.map +1 -0
- package/src/ts/BezierPath.ts +37 -5
- package/src/ts/PBText.ts +147 -0
- package/src/ts/PlotBoilerplate.ts +47 -19
- package/src/ts/Polygon.ts +493 -451
- package/src/ts/Vertex.ts +66 -7
- package/src/ts/draw.ts +71 -8
- package/src/ts/drawgl.ts +48 -8
- package/src/ts/drawutilssvg.ts +94 -17
- package/src/ts/index.ts +1 -0
- package/src/ts/interfaces/DrawLib.ts +30 -4
- package/src/ts/interfaces/core.ts +9 -0
- package/src/ts/utils/datastructures/Color.ts +695 -508
- package/src/ts/utils/findInVertexArray.ts +28 -0
- package/dist/plotboilerplate.browser.min.js.LICENSE.txt +0 -8
- package/src/ts/utils/algorithms/clearPolygonDuplicateVertices.ts~ +0 -5
- package/src/ts/utils/algorithms/findPolygonSelfIntersections.ts~ +0 -45
- package/src/ts/utils/algorithms/sh-tmp.ts~ +0 -59
- package/src/ts/utils/algorithms/splitPolygonToNonIntersecting.ts~ +0 -113
- package/src/ts/utils/algorithms/sutherlandHodgman.ts~ +0 -88
- package/src/ts/utils/datastructures/Color.ts~ +0 -331
- package/src/ts/utils/datastructures/Girih.ts~ +0 -151
- package/src/ts/utils/datastructures/GirihTile.ts~ +0 -419
|
@@ -8,7 +8,13 @@
|
|
|
8
8
|
* @modified 2020-10-23 Ported to Typescript.
|
|
9
9
|
* @modified 2021-02-08 Fixed a lot of es2015 compatibility issues.
|
|
10
10
|
* @modified 2021-02-08 Added basic tsdoc/jsdoc comments.
|
|
11
|
-
* @
|
|
11
|
+
* @modified 2021-11-05 Fixing the regex to parse rgba-strings.
|
|
12
|
+
* @modified 2021-11-05 Added return value `this` to all modifier functions (for chaining).
|
|
13
|
+
* @modified 2021-11-07 Changed the behavior of `darken` and `lighten`: the passed value is handled relative now which makes values much easier predictable and makes the change feel more 'natural'.
|
|
14
|
+
* @modified 2021-11-07 Did the same with `saturate` and `desaturate`.
|
|
15
|
+
* @modified 2021-11-07 Did the same with the `fadein` and `fadeout` functions.
|
|
16
|
+
* @modified 2021-11-07 Added setRed, setGreen, setBlue, setHue, setSaturation, setLiminance functions.
|
|
17
|
+
* @version 0.0.10
|
|
12
18
|
**/
|
|
13
19
|
/**
|
|
14
20
|
* @classdesc A color class, inspired by neolitec's Javascript class.
|
|
@@ -101,13 +107,13 @@ export declare class Color {
|
|
|
101
107
|
*/
|
|
102
108
|
red(): number;
|
|
103
109
|
/**
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
* Get the green component of this RGB(A) color. This method just returns the `g` color attribute.
|
|
111
|
+
*
|
|
112
|
+
* @method green
|
|
113
|
+
* @instance
|
|
114
|
+
* @memberof Color
|
|
115
|
+
* @return {number} A value between 0.0 and 1.0.
|
|
116
|
+
*/
|
|
111
117
|
green(): number;
|
|
112
118
|
/**
|
|
113
119
|
* Get the blue component of this RGB(A) color. This method just returns the `b` color attribute.
|
|
@@ -118,6 +124,13 @@ export declare class Color {
|
|
|
118
124
|
* @return {number} A value between 0.0 and 1.0.
|
|
119
125
|
*/
|
|
120
126
|
blue(): number;
|
|
127
|
+
setRed(r: number): this;
|
|
128
|
+
setBlue(b: number): this;
|
|
129
|
+
setAlpha(a: number): this;
|
|
130
|
+
setGreen(g: number): this;
|
|
131
|
+
setHue(h: number): this;
|
|
132
|
+
setSaturation(s: number): this;
|
|
133
|
+
setLuminance(l: number): this;
|
|
121
134
|
/**
|
|
122
135
|
* Get this color as a CSS `hsl` string.
|
|
123
136
|
*
|
|
@@ -181,13 +194,13 @@ export declare class Color {
|
|
|
181
194
|
* @return {number} A value between 0.0 and 1.0.
|
|
182
195
|
*/
|
|
183
196
|
alpha(): number;
|
|
184
|
-
saturate(v: string | number):
|
|
185
|
-
desaturate(v: string | number):
|
|
186
|
-
lighten(v: string | number):
|
|
187
|
-
darken(v: string | number):
|
|
188
|
-
fadein(v: string | number):
|
|
189
|
-
fadeout(v: string | number):
|
|
190
|
-
spin(v: string | number):
|
|
197
|
+
saturate(v: string | number): Color;
|
|
198
|
+
desaturate(v: string | number): Color;
|
|
199
|
+
lighten(v: string | number): Color;
|
|
200
|
+
darken(v: string | number): Color;
|
|
201
|
+
fadein(v: string | number): Color;
|
|
202
|
+
fadeout(v: string | number): Color;
|
|
203
|
+
spin(v: string | number): Color;
|
|
191
204
|
static makeRGB(...args: any[]): Color;
|
|
192
205
|
static makeHSL(...args: Array<number | string>): Color;
|
|
193
206
|
static makeHEX(value: string): Color;
|
|
@@ -9,7 +9,13 @@
|
|
|
9
9
|
* @modified 2020-10-23 Ported to Typescript.
|
|
10
10
|
* @modified 2021-02-08 Fixed a lot of es2015 compatibility issues.
|
|
11
11
|
* @modified 2021-02-08 Added basic tsdoc/jsdoc comments.
|
|
12
|
-
* @
|
|
12
|
+
* @modified 2021-11-05 Fixing the regex to parse rgba-strings.
|
|
13
|
+
* @modified 2021-11-05 Added return value `this` to all modifier functions (for chaining).
|
|
14
|
+
* @modified 2021-11-07 Changed the behavior of `darken` and `lighten`: the passed value is handled relative now which makes values much easier predictable and makes the change feel more 'natural'.
|
|
15
|
+
* @modified 2021-11-07 Did the same with `saturate` and `desaturate`.
|
|
16
|
+
* @modified 2021-11-07 Did the same with the `fadein` and `fadeout` functions.
|
|
17
|
+
* @modified 2021-11-07 Added setRed, setGreen, setBlue, setHue, setSaturation, setLiminance functions.
|
|
18
|
+
* @version 0.0.10
|
|
13
19
|
**/
|
|
14
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
21
|
exports.Color = void 0;
|
|
@@ -34,8 +40,7 @@ var Color = /** @class */ (function () {
|
|
|
34
40
|
this.h = this.s = this.l = 0;
|
|
35
41
|
this.a = 1;
|
|
36
42
|
}
|
|
37
|
-
|
|
38
|
-
// --- RGB ----------------------------------
|
|
43
|
+
// --- RGB ----------------------------------
|
|
39
44
|
/**
|
|
40
45
|
* Get this color as a CSS `rgb` string.
|
|
41
46
|
*
|
|
@@ -49,7 +54,6 @@ var Color = /** @class */ (function () {
|
|
|
49
54
|
Color.prototype.cssRGB = function () {
|
|
50
55
|
return "rgb(" + Math.round(255 * this.r) + "," + Math.round(255 * this.g) + "," + Math.round(255 * this.b) + ")";
|
|
51
56
|
};
|
|
52
|
-
;
|
|
53
57
|
/**
|
|
54
58
|
* Get this color as a CSS `rgba` string.
|
|
55
59
|
*
|
|
@@ -63,7 +67,6 @@ var Color = /** @class */ (function () {
|
|
|
63
67
|
Color.prototype.cssRGBA = function () {
|
|
64
68
|
return "rgba(" + Math.round(255 * this.r) + "," + Math.round(255 * this.g) + "," + Math.round(255 * this.b) + "," + this.a + ")";
|
|
65
69
|
};
|
|
66
|
-
;
|
|
67
70
|
/**
|
|
68
71
|
* Get the red component of this RGB(A)color. This method just returns the `r` color attribute.
|
|
69
72
|
*
|
|
@@ -72,18 +75,20 @@ var Color = /** @class */ (function () {
|
|
|
72
75
|
* @memberof Color
|
|
73
76
|
* @return {number} A value between 0.0 and 1.0.
|
|
74
77
|
*/
|
|
75
|
-
Color.prototype.red = function () {
|
|
76
|
-
|
|
78
|
+
Color.prototype.red = function () {
|
|
79
|
+
return this.r;
|
|
80
|
+
};
|
|
77
81
|
/**
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
Color.prototype.green = function () {
|
|
86
|
-
|
|
82
|
+
* Get the green component of this RGB(A) color. This method just returns the `g` color attribute.
|
|
83
|
+
*
|
|
84
|
+
* @method green
|
|
85
|
+
* @instance
|
|
86
|
+
* @memberof Color
|
|
87
|
+
* @return {number} A value between 0.0 and 1.0.
|
|
88
|
+
*/
|
|
89
|
+
Color.prototype.green = function () {
|
|
90
|
+
return this.g;
|
|
91
|
+
};
|
|
87
92
|
/**
|
|
88
93
|
* Get the blue component of this RGB(A) color. This method just returns the `b` color attribute.
|
|
89
94
|
*
|
|
@@ -92,9 +97,44 @@ var Color = /** @class */ (function () {
|
|
|
92
97
|
* @memberof Color
|
|
93
98
|
* @return {number} A value between 0.0 and 1.0.
|
|
94
99
|
*/
|
|
95
|
-
Color.prototype.blue = function () {
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
Color.prototype.blue = function () {
|
|
101
|
+
return this.b;
|
|
102
|
+
};
|
|
103
|
+
Color.prototype.setRed = function (r) {
|
|
104
|
+
this.r = r;
|
|
105
|
+
return this;
|
|
106
|
+
};
|
|
107
|
+
Color.prototype.setBlue = function (b) {
|
|
108
|
+
this.b = b;
|
|
109
|
+
Color.Converter.RGBToHSL(this);
|
|
110
|
+
return this;
|
|
111
|
+
};
|
|
112
|
+
Color.prototype.setAlpha = function (a) {
|
|
113
|
+
this.a = a;
|
|
114
|
+
Color.Converter.RGBToHSL(this);
|
|
115
|
+
return this;
|
|
116
|
+
};
|
|
117
|
+
Color.prototype.setGreen = function (g) {
|
|
118
|
+
this.g = g;
|
|
119
|
+
Color.Converter.RGBToHSL(this);
|
|
120
|
+
return this;
|
|
121
|
+
};
|
|
122
|
+
Color.prototype.setHue = function (h) {
|
|
123
|
+
this.h = h;
|
|
124
|
+
Color.Converter.HSLToRGB(this);
|
|
125
|
+
return this;
|
|
126
|
+
};
|
|
127
|
+
Color.prototype.setSaturation = function (s) {
|
|
128
|
+
this.s = s;
|
|
129
|
+
Color.Converter.HSLToRGB(this);
|
|
130
|
+
return this;
|
|
131
|
+
};
|
|
132
|
+
Color.prototype.setLuminance = function (l) {
|
|
133
|
+
this.l = l;
|
|
134
|
+
Color.Converter.HSLToRGB(this);
|
|
135
|
+
return this;
|
|
136
|
+
};
|
|
137
|
+
// --- HSL ----------------------------------
|
|
98
138
|
/**
|
|
99
139
|
* Get this color as a CSS `hsl` string.
|
|
100
140
|
*
|
|
@@ -106,7 +146,6 @@ var Color = /** @class */ (function () {
|
|
|
106
146
|
Color.prototype.cssHSL = function () {
|
|
107
147
|
return "hsl(" + Math.round(360 * this.h) + "," + Math.round(100 * this.s) + "%," + Math.round(100 * this.l) + "%)";
|
|
108
148
|
};
|
|
109
|
-
;
|
|
110
149
|
/**
|
|
111
150
|
* Get this color as a CSS `hsla` string.
|
|
112
151
|
*
|
|
@@ -116,9 +155,16 @@ var Color = /** @class */ (function () {
|
|
|
116
155
|
* @return {string} This color as a CSS hsla string.
|
|
117
156
|
*/
|
|
118
157
|
Color.prototype.cssHSLA = function () {
|
|
119
|
-
return "hsla(" +
|
|
158
|
+
return ("hsla(" +
|
|
159
|
+
Math.round(360 * this.h) +
|
|
160
|
+
"," +
|
|
161
|
+
Math.round(100 * this.s) +
|
|
162
|
+
"%," +
|
|
163
|
+
Math.round(100 * this.l) +
|
|
164
|
+
"%," +
|
|
165
|
+
Math.round(this.a) +
|
|
166
|
+
")");
|
|
120
167
|
};
|
|
121
|
-
;
|
|
122
168
|
/**
|
|
123
169
|
* Get the hue component of this HSL(A) color. This method just returns the `h` color attribute.
|
|
124
170
|
*
|
|
@@ -127,8 +173,9 @@ var Color = /** @class */ (function () {
|
|
|
127
173
|
* @memberof Color
|
|
128
174
|
* @return {number} A value between 0.0 and 1.0.
|
|
129
175
|
*/
|
|
130
|
-
Color.prototype.hue = function () {
|
|
131
|
-
|
|
176
|
+
Color.prototype.hue = function () {
|
|
177
|
+
return this.h;
|
|
178
|
+
};
|
|
132
179
|
/**
|
|
133
180
|
* Get the saturation component of this HSL(A) color. This method just returns the `s` color attribute.
|
|
134
181
|
*
|
|
@@ -137,8 +184,9 @@ var Color = /** @class */ (function () {
|
|
|
137
184
|
* @memberof Color
|
|
138
185
|
* @return {number} A value between 0.0 and 1.0.
|
|
139
186
|
*/
|
|
140
|
-
Color.prototype.saturation = function () {
|
|
141
|
-
|
|
187
|
+
Color.prototype.saturation = function () {
|
|
188
|
+
return this.s;
|
|
189
|
+
};
|
|
142
190
|
/**
|
|
143
191
|
* Get the lightness component of this HSL(A) color. This method just returns the `l` color attribute.
|
|
144
192
|
*
|
|
@@ -147,8 +195,9 @@ var Color = /** @class */ (function () {
|
|
|
147
195
|
* @memberof Color
|
|
148
196
|
* @return {number} A value between 0.0 and 1.0.
|
|
149
197
|
*/
|
|
150
|
-
Color.prototype.lightness = function () {
|
|
151
|
-
|
|
198
|
+
Color.prototype.lightness = function () {
|
|
199
|
+
return this.l;
|
|
200
|
+
};
|
|
152
201
|
// --- HEX ----------------------------------
|
|
153
202
|
/**
|
|
154
203
|
* Get this color as a CSS-HEX string (non-alpha): #rrggbb
|
|
@@ -159,13 +208,15 @@ var Color = /** @class */ (function () {
|
|
|
159
208
|
* @return {string} This color as a CSS-HEX string.
|
|
160
209
|
*/
|
|
161
210
|
Color.prototype.cssHEX = function () {
|
|
162
|
-
return "#" +
|
|
163
|
-
(255 * this.r < 16 ? "0" : "") +
|
|
164
|
-
|
|
165
|
-
(255 * this.
|
|
211
|
+
return ("#" +
|
|
212
|
+
(255 * this.r < 16 ? "0" : "") +
|
|
213
|
+
Math.round(255 * this.r).toString(16) +
|
|
214
|
+
(255 * this.g < 16 ? "0" : "") +
|
|
215
|
+
Math.round(255 * this.g).toString(16) +
|
|
216
|
+
(255 * this.b < 16 ? "0" : "") +
|
|
217
|
+
Math.round(255 * this.b).toString(16));
|
|
166
218
|
};
|
|
167
|
-
|
|
168
|
-
// --- Transparency ----------------------------------
|
|
219
|
+
// --- Transparency ----------------------------------
|
|
169
220
|
/**
|
|
170
221
|
* Get the alpha channel (transparency) of this color.
|
|
171
222
|
*
|
|
@@ -174,67 +225,193 @@ var Color = /** @class */ (function () {
|
|
|
174
225
|
* @memberof Color
|
|
175
226
|
* @return {number} A value between 0.0 and 1.0.
|
|
176
227
|
*/
|
|
177
|
-
Color.prototype.alpha = function () {
|
|
178
|
-
|
|
179
|
-
|
|
228
|
+
Color.prototype.alpha = function () {
|
|
229
|
+
return this.a;
|
|
230
|
+
};
|
|
231
|
+
// --- Modifiers ----------------------------------
|
|
232
|
+
// saturate(v: string | number): Color {
|
|
233
|
+
// if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
|
|
234
|
+
// this.s += v / 100;
|
|
235
|
+
// } else if ("number" == typeof v) {
|
|
236
|
+
// // range 255
|
|
237
|
+
// this.s += v / 255;
|
|
238
|
+
// } else {
|
|
239
|
+
// throw new Error("error: bad modifier format (percent or number)");
|
|
240
|
+
// }
|
|
241
|
+
// if (this.s > 1) this.s = 1;
|
|
242
|
+
// else if (this.s < 0) this.s = 0;
|
|
243
|
+
// Color.Converter.HSLToRGB(this);
|
|
244
|
+
// return this;
|
|
245
|
+
// }
|
|
180
246
|
Color.prototype.saturate = function (v) {
|
|
181
|
-
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN)
|
|
182
|
-
this.s += v / 100;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
247
|
+
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
|
|
248
|
+
this.s += (1 - this.s) * (v / 100);
|
|
249
|
+
}
|
|
250
|
+
else if ("number" == typeof v) {
|
|
251
|
+
if (v >= -0.0 && v <= 1.0) {
|
|
252
|
+
// range 255
|
|
253
|
+
this.s += (1 - this.s) * v;
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
// range 0-1
|
|
257
|
+
this.s += (1 - this.s) * (v / 255);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
186
261
|
throw new Error("error: bad modifier format (percent or number)");
|
|
262
|
+
}
|
|
187
263
|
if (this.s > 1)
|
|
188
264
|
this.s = 1;
|
|
189
265
|
else if (this.s < 0)
|
|
190
266
|
this.s = 0;
|
|
191
267
|
Color.Converter.HSLToRGB(this);
|
|
268
|
+
return this;
|
|
192
269
|
};
|
|
193
|
-
;
|
|
194
270
|
Color.prototype.desaturate = function (v) {
|
|
195
|
-
|
|
271
|
+
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
|
|
272
|
+
this.s -= v / 100;
|
|
273
|
+
}
|
|
274
|
+
else if ("number" == typeof v) {
|
|
275
|
+
if (v >= 0.0 && v <= 1.0) {
|
|
276
|
+
// range 255
|
|
277
|
+
this.s -= this.s * v;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
// range 0-1
|
|
281
|
+
this.s -= this.s * (v / 255);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
throw new Error("error: bad modifier format (percent or number)");
|
|
286
|
+
}
|
|
287
|
+
if (this.s > 1)
|
|
288
|
+
this.s = 1;
|
|
289
|
+
else if (this.s < 0)
|
|
290
|
+
this.s = 0;
|
|
291
|
+
Color.Converter.HSLToRGB(this);
|
|
292
|
+
return this;
|
|
196
293
|
};
|
|
197
|
-
|
|
294
|
+
// lighten(v: string | number): Color {
|
|
295
|
+
// if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
|
|
296
|
+
// this.l += v / 100;
|
|
297
|
+
// } else if ("number" == typeof v) {
|
|
298
|
+
// if (v >= -1.0 && v <= 1.0) {
|
|
299
|
+
// // range 0.0...1.0
|
|
300
|
+
// this.l += v;
|
|
301
|
+
// } else {
|
|
302
|
+
// // range 255
|
|
303
|
+
// this.l += v / 255;
|
|
304
|
+
// }
|
|
305
|
+
// } else {
|
|
306
|
+
// throw new Error("error: bad modifier format (percent or number)");
|
|
307
|
+
// }
|
|
308
|
+
// if (this.l > 1) this.l = 1;
|
|
309
|
+
// else if (this.l < 0) this.l = 0;
|
|
310
|
+
// Color.Converter.HSLToRGB(this);
|
|
311
|
+
// return this;
|
|
312
|
+
// }
|
|
198
313
|
Color.prototype.lighten = function (v) {
|
|
199
|
-
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN)
|
|
200
|
-
this.l += v / 100;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
314
|
+
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
|
|
315
|
+
this.l += (1 - this.l) * (v / 100);
|
|
316
|
+
}
|
|
317
|
+
else if ("number" == typeof v) {
|
|
318
|
+
if (v >= 0.0 && v <= 1.0) {
|
|
319
|
+
// range 0.0...1.0
|
|
320
|
+
this.l += (1 - this.l) * v;
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
// range 255
|
|
324
|
+
this.l += (1 - this.l) * (v / 255);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
204
328
|
throw new Error("error: bad modifier format (percent or number)");
|
|
329
|
+
}
|
|
205
330
|
if (this.l > 1)
|
|
206
331
|
this.l = 1;
|
|
207
332
|
else if (this.l < 0)
|
|
208
333
|
this.l = 0;
|
|
209
334
|
Color.Converter.HSLToRGB(this);
|
|
335
|
+
return this;
|
|
210
336
|
};
|
|
211
|
-
;
|
|
212
337
|
Color.prototype.darken = function (v) {
|
|
213
|
-
|
|
338
|
+
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
|
|
339
|
+
this.l -= this.l * (v / 100);
|
|
340
|
+
}
|
|
341
|
+
else if ("number" == typeof v) {
|
|
342
|
+
if (v >= 0.0 && v <= 1.0) {
|
|
343
|
+
// range 0.0...1.0
|
|
344
|
+
this.l -= this.l * v;
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
// range 255
|
|
348
|
+
this.l -= this.l * (v / 255);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
throw new Error("error: bad modifier format (percent or number)");
|
|
353
|
+
}
|
|
354
|
+
if (this.l > 1)
|
|
355
|
+
this.l = 1;
|
|
356
|
+
else if (this.l < 0)
|
|
357
|
+
this.l = 0;
|
|
358
|
+
Color.Converter.HSLToRGB(this);
|
|
359
|
+
return this;
|
|
214
360
|
};
|
|
215
|
-
;
|
|
216
361
|
Color.prototype.fadein = function (v) {
|
|
217
|
-
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN)
|
|
218
|
-
this.a += v / 100;
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
362
|
+
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
|
|
363
|
+
this.a += (1 - this.a) * (v / 100);
|
|
364
|
+
}
|
|
365
|
+
else if ("number" == typeof v) {
|
|
366
|
+
if (v >= 0.0 && v <= 1.0) {
|
|
367
|
+
// range 0-1
|
|
368
|
+
this.a += (1 - this.a) * v;
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
// range 255
|
|
372
|
+
this.a += (1 - this.a) * (v / 255);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
222
376
|
throw new Error("error: bad modifier format (percent or number)");
|
|
377
|
+
}
|
|
378
|
+
console.log("New alpha", this.a);
|
|
223
379
|
if (this.a > 1)
|
|
224
380
|
this.a = 1;
|
|
225
381
|
else if (this.a < 0)
|
|
226
382
|
this.a = 0;
|
|
227
383
|
Color.Converter.HSLToRGB(this);
|
|
384
|
+
return this;
|
|
228
385
|
};
|
|
229
|
-
;
|
|
230
386
|
Color.prototype.fadeout = function (v) {
|
|
231
|
-
|
|
387
|
+
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
|
|
388
|
+
this.a -= v / 100;
|
|
389
|
+
}
|
|
390
|
+
else if ("number" == typeof v) {
|
|
391
|
+
if (v >= 0.0 && v <= 1.0) {
|
|
392
|
+
// range 0-1
|
|
393
|
+
this.a -= v;
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
// range 255
|
|
397
|
+
this.a -= v / 255;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
throw new Error("error: bad modifier format (percent or number)");
|
|
402
|
+
}
|
|
403
|
+
if (this.a > 1)
|
|
404
|
+
this.a = 1;
|
|
405
|
+
else if (this.a < 0)
|
|
406
|
+
this.a = 0;
|
|
407
|
+
Color.Converter.HSLToRGB(this);
|
|
408
|
+
return this;
|
|
232
409
|
};
|
|
233
|
-
;
|
|
234
410
|
Color.prototype.spin = function (v) {
|
|
235
411
|
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN)
|
|
236
412
|
this.h += v / 100;
|
|
237
|
-
else if ("number" == typeof v)
|
|
413
|
+
else if ("number" == typeof v)
|
|
414
|
+
// range 360
|
|
238
415
|
this.h += v / 360;
|
|
239
416
|
else
|
|
240
417
|
throw new Error("error: bad modifier format (percent or number)");
|
|
@@ -243,8 +420,8 @@ var Color = /** @class */ (function () {
|
|
|
243
420
|
else if (this.h < 0)
|
|
244
421
|
this.h = 0;
|
|
245
422
|
Color.Converter.HSLToRGB(this);
|
|
423
|
+
return this;
|
|
246
424
|
};
|
|
247
|
-
;
|
|
248
425
|
Color.makeRGB = function () {
|
|
249
426
|
var args = [];
|
|
250
427
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -258,12 +435,15 @@ var Color = /** @class */ (function () {
|
|
|
258
435
|
c.r = sanitized[0];
|
|
259
436
|
c.g = sanitized[1];
|
|
260
437
|
c.b = sanitized[2];
|
|
261
|
-
if (arguments.length == 4)
|
|
438
|
+
if (arguments.length == 4) {
|
|
262
439
|
c.a = arguments[3];
|
|
440
|
+
}
|
|
441
|
+
else {
|
|
442
|
+
c.a = 1.0;
|
|
443
|
+
}
|
|
263
444
|
Color.Converter.RGBToHSL(c);
|
|
264
445
|
return c;
|
|
265
446
|
};
|
|
266
|
-
;
|
|
267
447
|
Color.makeHSL = function () {
|
|
268
448
|
var args = [];
|
|
269
449
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -279,15 +459,16 @@ var Color = /** @class */ (function () {
|
|
|
279
459
|
c.l = sanitized[2];
|
|
280
460
|
if (arguments.length == 4)
|
|
281
461
|
c.a = arguments[3];
|
|
462
|
+
else
|
|
463
|
+
c.a = 1.0;
|
|
282
464
|
Color.Converter.HSLToRGB(c);
|
|
283
465
|
return c;
|
|
284
466
|
};
|
|
285
|
-
;
|
|
286
467
|
Color.makeHEX = function (value) {
|
|
287
468
|
var c = new Color(), sanitized;
|
|
288
469
|
// Edit Ika 2018-0308
|
|
289
470
|
// Allow leading '#'
|
|
290
|
-
if (value && value.startsWith(
|
|
471
|
+
if (value && value.startsWith("#"))
|
|
291
472
|
value = value.substr(1);
|
|
292
473
|
Color.Validator.checkHEX(value);
|
|
293
474
|
if (value.length == 3) {
|
|
@@ -301,10 +482,10 @@ var Color = /** @class */ (function () {
|
|
|
301
482
|
c.r = sanitized[0];
|
|
302
483
|
c.g = sanitized[1];
|
|
303
484
|
c.b = sanitized[2];
|
|
485
|
+
c.a = 1.0; // TODO: Accept #xxxxxxxx (8 chars, too, for alpha)
|
|
304
486
|
Color.Converter.RGBToHSL(c);
|
|
305
487
|
return c;
|
|
306
488
|
};
|
|
307
|
-
;
|
|
308
489
|
/**
|
|
309
490
|
* Parse the given color string. Currently only these formate are recognized: hex, rgb, rgba.
|
|
310
491
|
*
|
|
@@ -315,24 +496,30 @@ var Color = /** @class */ (function () {
|
|
|
315
496
|
* @return {Color} The color instance that's represented by the given string.
|
|
316
497
|
*/
|
|
317
498
|
Color.parse = function (str) {
|
|
318
|
-
if (typeof str ==
|
|
499
|
+
if (typeof str == "undefined")
|
|
319
500
|
return null;
|
|
320
501
|
if ((str = str.trim().toLowerCase()).length == 0)
|
|
321
502
|
return null;
|
|
322
|
-
if (str.startsWith(
|
|
503
|
+
if (str.startsWith("#"))
|
|
323
504
|
return Color.makeHEX(str.substring(1, str.length));
|
|
324
|
-
if (str.startsWith(
|
|
325
|
-
var parts = /^rgba?\((\d
|
|
505
|
+
if (str.startsWith("rgb")) {
|
|
506
|
+
var parts = str.match(/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,?\s*(\d*(?:\.\d+\s*)?)\)$/);
|
|
507
|
+
if (!parts) {
|
|
508
|
+
throw "Unrecognized color format (2): " + str;
|
|
509
|
+
}
|
|
326
510
|
// [ str, r, g, b, a|undefined ]
|
|
327
|
-
|
|
511
|
+
// console.log("parts", parts);
|
|
512
|
+
if (parts.length <= 4 || typeof parts[4] == "undefined" || parts[4] == "") {
|
|
328
513
|
return Color.makeRGB(parts[1], parts[2], parts[3]);
|
|
329
|
-
|
|
330
|
-
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
return Color.makeRGB(parts[1], parts[2], parts[3], Number(parts[4]));
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
throw "Unrecognized color format (1): " + str;
|
|
331
521
|
}
|
|
332
|
-
else
|
|
333
|
-
throw "Unrecognized color format: " + str;
|
|
334
522
|
};
|
|
335
|
-
;
|
|
336
523
|
/**
|
|
337
524
|
* Create a clone of this color (RGB).
|
|
338
525
|
*
|
|
@@ -344,7 +531,6 @@ var Color = /** @class */ (function () {
|
|
|
344
531
|
Color.prototype.clone = function () {
|
|
345
532
|
return Color.makeRGB(this.r, this.g, this.b, this.a);
|
|
346
533
|
};
|
|
347
|
-
;
|
|
348
534
|
/**
|
|
349
535
|
* Interpolate this color on the RGB scale.
|
|
350
536
|
*
|
|
@@ -362,7 +548,6 @@ var Color = /** @class */ (function () {
|
|
|
362
548
|
this.a += (c.a - c.a) * t;
|
|
363
549
|
return this;
|
|
364
550
|
};
|
|
365
|
-
;
|
|
366
551
|
Color.Sanitizer = {
|
|
367
552
|
RGB: function () {
|
|
368
553
|
var args = [];
|
|
@@ -384,17 +569,21 @@ var Color = /** @class */ (function () {
|
|
|
384
569
|
o[i] = c / 100;
|
|
385
570
|
}
|
|
386
571
|
else {
|
|
387
|
-
|
|
388
|
-
if ("string" == typeof c && (c = parseInt(c)) == NaN)
|
|
572
|
+
if ("string" == typeof c && (c = parseInt(c)) == NaN) {
|
|
389
573
|
throw new Error("Bad format");
|
|
390
|
-
|
|
574
|
+
}
|
|
575
|
+
if (c < 0) {
|
|
391
576
|
throw new Error("Bad format");
|
|
577
|
+
}
|
|
392
578
|
//else if( allAreFrac ) o[i] = c; // c >= 0 && c <= 1 (all)
|
|
393
|
-
else if (c >= 0 && c < 1)
|
|
579
|
+
else if (c >= 0 && c < 1) {
|
|
394
580
|
o[i] = c;
|
|
581
|
+
}
|
|
395
582
|
// else if(c >= 0.0 && c <= 1.0) o[i] = c;
|
|
396
|
-
else if (c >= 1 && c < 256)
|
|
397
|
-
o[i] = c / 255;
|
|
583
|
+
else if (c >= 1 && c < 256) {
|
|
584
|
+
o[i] = c / 255;
|
|
585
|
+
}
|
|
586
|
+
// ???
|
|
398
587
|
// else if(c >= 0 && c < 256) o[i] = c/255;
|
|
399
588
|
else
|
|
400
589
|
throw new Error("Bad format (" + c + ")");
|
|
@@ -522,7 +711,6 @@ var Color = /** @class */ (function () {
|
|
|
522
711
|
}
|
|
523
712
|
};
|
|
524
713
|
return Color;
|
|
525
|
-
}());
|
|
714
|
+
}()); // END class
|
|
526
715
|
exports.Color = Color;
|
|
527
|
-
; // END class
|
|
528
716
|
//# sourceMappingURL=Color.js.map
|