plotboilerplate 1.12.7 → 1.13.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 +4 -1
- package/changelog.md +25 -0
- package/dist/index.esm.js +259 -44
- 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 +273 -43
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +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 +66 -19
- package/src/cjs/PlotBoilerplate.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 +12 -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/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 +66 -19
- package/src/esm/PlotBoilerplate.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 +12 -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/ts/PBText.ts +147 -0
- package/src/ts/PlotBoilerplate.ts +74 -23
- 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 +12 -0
- package/src/ts/utils/datastructures/Color.ts +695 -508
- package/src/ts/utils/algorithms/clearPolygonDuplicateVertices.ts~ +0 -5
- package/src/ts/utils/algorithms/findPolygonSelfIntersections.ts~ +0 -45
- 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;
|
|
@@ -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.
|
|
@@ -31,8 +37,7 @@ export class Color {
|
|
|
31
37
|
this.h = this.s = this.l = 0;
|
|
32
38
|
this.a = 1;
|
|
33
39
|
}
|
|
34
|
-
|
|
35
|
-
// --- RGB ----------------------------------
|
|
40
|
+
// --- RGB ----------------------------------
|
|
36
41
|
/**
|
|
37
42
|
* Get this color as a CSS `rgb` string.
|
|
38
43
|
*
|
|
@@ -46,7 +51,6 @@ export class Color {
|
|
|
46
51
|
cssRGB() {
|
|
47
52
|
return "rgb(" + Math.round(255 * this.r) + "," + Math.round(255 * this.g) + "," + Math.round(255 * this.b) + ")";
|
|
48
53
|
}
|
|
49
|
-
;
|
|
50
54
|
/**
|
|
51
55
|
* Get this color as a CSS `rgba` string.
|
|
52
56
|
*
|
|
@@ -58,9 +62,8 @@ export class Color {
|
|
|
58
62
|
* @return {string} This color as a CSS rgba string.
|
|
59
63
|
*/
|
|
60
64
|
cssRGBA() {
|
|
61
|
-
return
|
|
65
|
+
return `rgba(${Math.round(255 * this.r)},${Math.round(255 * this.g)},${Math.round(255 * this.b)},${this.a})`;
|
|
62
66
|
}
|
|
63
|
-
;
|
|
64
67
|
/**
|
|
65
68
|
* Get the red component of this RGB(A)color. This method just returns the `r` color attribute.
|
|
66
69
|
*
|
|
@@ -69,18 +72,20 @@ export class Color {
|
|
|
69
72
|
* @memberof Color
|
|
70
73
|
* @return {number} A value between 0.0 and 1.0.
|
|
71
74
|
*/
|
|
72
|
-
red() {
|
|
73
|
-
|
|
75
|
+
red() {
|
|
76
|
+
return this.r;
|
|
77
|
+
}
|
|
74
78
|
/**
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
green() {
|
|
83
|
-
|
|
79
|
+
* Get the green component of this RGB(A) color. This method just returns the `g` color attribute.
|
|
80
|
+
*
|
|
81
|
+
* @method green
|
|
82
|
+
* @instance
|
|
83
|
+
* @memberof Color
|
|
84
|
+
* @return {number} A value between 0.0 and 1.0.
|
|
85
|
+
*/
|
|
86
|
+
green() {
|
|
87
|
+
return this.g;
|
|
88
|
+
}
|
|
84
89
|
/**
|
|
85
90
|
* Get the blue component of this RGB(A) color. This method just returns the `b` color attribute.
|
|
86
91
|
*
|
|
@@ -89,9 +94,44 @@ export class Color {
|
|
|
89
94
|
* @memberof Color
|
|
90
95
|
* @return {number} A value between 0.0 and 1.0.
|
|
91
96
|
*/
|
|
92
|
-
blue() {
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
blue() {
|
|
98
|
+
return this.b;
|
|
99
|
+
}
|
|
100
|
+
setRed(r) {
|
|
101
|
+
this.r = r;
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
setBlue(b) {
|
|
105
|
+
this.b = b;
|
|
106
|
+
Color.Converter.RGBToHSL(this);
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
setAlpha(a) {
|
|
110
|
+
this.a = a;
|
|
111
|
+
Color.Converter.RGBToHSL(this);
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
setGreen(g) {
|
|
115
|
+
this.g = g;
|
|
116
|
+
Color.Converter.RGBToHSL(this);
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
setHue(h) {
|
|
120
|
+
this.h = h;
|
|
121
|
+
Color.Converter.HSLToRGB(this);
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
setSaturation(s) {
|
|
125
|
+
this.s = s;
|
|
126
|
+
Color.Converter.HSLToRGB(this);
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
setLuminance(l) {
|
|
130
|
+
this.l = l;
|
|
131
|
+
Color.Converter.HSLToRGB(this);
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
// --- HSL ----------------------------------
|
|
95
135
|
/**
|
|
96
136
|
* Get this color as a CSS `hsl` string.
|
|
97
137
|
*
|
|
@@ -103,7 +143,6 @@ export class Color {
|
|
|
103
143
|
cssHSL() {
|
|
104
144
|
return "hsl(" + Math.round(360 * this.h) + "," + Math.round(100 * this.s) + "%," + Math.round(100 * this.l) + "%)";
|
|
105
145
|
}
|
|
106
|
-
;
|
|
107
146
|
/**
|
|
108
147
|
* Get this color as a CSS `hsla` string.
|
|
109
148
|
*
|
|
@@ -113,9 +152,16 @@ export class Color {
|
|
|
113
152
|
* @return {string} This color as a CSS hsla string.
|
|
114
153
|
*/
|
|
115
154
|
cssHSLA() {
|
|
116
|
-
return "hsla(" +
|
|
155
|
+
return ("hsla(" +
|
|
156
|
+
Math.round(360 * this.h) +
|
|
157
|
+
"," +
|
|
158
|
+
Math.round(100 * this.s) +
|
|
159
|
+
"%," +
|
|
160
|
+
Math.round(100 * this.l) +
|
|
161
|
+
"%," +
|
|
162
|
+
Math.round(this.a) +
|
|
163
|
+
")");
|
|
117
164
|
}
|
|
118
|
-
;
|
|
119
165
|
/**
|
|
120
166
|
* Get the hue component of this HSL(A) color. This method just returns the `h` color attribute.
|
|
121
167
|
*
|
|
@@ -124,8 +170,9 @@ export class Color {
|
|
|
124
170
|
* @memberof Color
|
|
125
171
|
* @return {number} A value between 0.0 and 1.0.
|
|
126
172
|
*/
|
|
127
|
-
hue() {
|
|
128
|
-
|
|
173
|
+
hue() {
|
|
174
|
+
return this.h;
|
|
175
|
+
}
|
|
129
176
|
/**
|
|
130
177
|
* Get the saturation component of this HSL(A) color. This method just returns the `s` color attribute.
|
|
131
178
|
*
|
|
@@ -134,8 +181,9 @@ export class Color {
|
|
|
134
181
|
* @memberof Color
|
|
135
182
|
* @return {number} A value between 0.0 and 1.0.
|
|
136
183
|
*/
|
|
137
|
-
saturation() {
|
|
138
|
-
|
|
184
|
+
saturation() {
|
|
185
|
+
return this.s;
|
|
186
|
+
}
|
|
139
187
|
/**
|
|
140
188
|
* Get the lightness component of this HSL(A) color. This method just returns the `l` color attribute.
|
|
141
189
|
*
|
|
@@ -144,8 +192,9 @@ export class Color {
|
|
|
144
192
|
* @memberof Color
|
|
145
193
|
* @return {number} A value between 0.0 and 1.0.
|
|
146
194
|
*/
|
|
147
|
-
lightness() {
|
|
148
|
-
|
|
195
|
+
lightness() {
|
|
196
|
+
return this.l;
|
|
197
|
+
}
|
|
149
198
|
// --- HEX ----------------------------------
|
|
150
199
|
/**
|
|
151
200
|
* Get this color as a CSS-HEX string (non-alpha): #rrggbb
|
|
@@ -156,13 +205,15 @@ export class Color {
|
|
|
156
205
|
* @return {string} This color as a CSS-HEX string.
|
|
157
206
|
*/
|
|
158
207
|
cssHEX() {
|
|
159
|
-
return "#" +
|
|
160
|
-
(255 * this.r < 16 ? "0" : "") +
|
|
161
|
-
|
|
162
|
-
(255 * this.
|
|
208
|
+
return ("#" +
|
|
209
|
+
(255 * this.r < 16 ? "0" : "") +
|
|
210
|
+
Math.round(255 * this.r).toString(16) +
|
|
211
|
+
(255 * this.g < 16 ? "0" : "") +
|
|
212
|
+
Math.round(255 * this.g).toString(16) +
|
|
213
|
+
(255 * this.b < 16 ? "0" : "") +
|
|
214
|
+
Math.round(255 * this.b).toString(16));
|
|
163
215
|
}
|
|
164
|
-
|
|
165
|
-
// --- Transparency ----------------------------------
|
|
216
|
+
// --- Transparency ----------------------------------
|
|
166
217
|
/**
|
|
167
218
|
* Get the alpha channel (transparency) of this color.
|
|
168
219
|
*
|
|
@@ -171,67 +222,193 @@ export class Color {
|
|
|
171
222
|
* @memberof Color
|
|
172
223
|
* @return {number} A value between 0.0 and 1.0.
|
|
173
224
|
*/
|
|
174
|
-
alpha() {
|
|
175
|
-
|
|
176
|
-
|
|
225
|
+
alpha() {
|
|
226
|
+
return this.a;
|
|
227
|
+
}
|
|
228
|
+
// --- Modifiers ----------------------------------
|
|
229
|
+
// saturate(v: string | number): Color {
|
|
230
|
+
// if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
|
|
231
|
+
// this.s += v / 100;
|
|
232
|
+
// } else if ("number" == typeof v) {
|
|
233
|
+
// // range 255
|
|
234
|
+
// this.s += v / 255;
|
|
235
|
+
// } else {
|
|
236
|
+
// throw new Error("error: bad modifier format (percent or number)");
|
|
237
|
+
// }
|
|
238
|
+
// if (this.s > 1) this.s = 1;
|
|
239
|
+
// else if (this.s < 0) this.s = 0;
|
|
240
|
+
// Color.Converter.HSLToRGB(this);
|
|
241
|
+
// return this;
|
|
242
|
+
// }
|
|
177
243
|
saturate(v) {
|
|
178
|
-
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN)
|
|
179
|
-
this.s += v / 100;
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
244
|
+
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
|
|
245
|
+
this.s += (1 - this.s) * (v / 100);
|
|
246
|
+
}
|
|
247
|
+
else if ("number" == typeof v) {
|
|
248
|
+
if (v >= -0.0 && v <= 1.0) {
|
|
249
|
+
// range 255
|
|
250
|
+
this.s += (1 - this.s) * v;
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
// range 0-1
|
|
254
|
+
this.s += (1 - this.s) * (v / 255);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
183
258
|
throw new Error("error: bad modifier format (percent or number)");
|
|
259
|
+
}
|
|
184
260
|
if (this.s > 1)
|
|
185
261
|
this.s = 1;
|
|
186
262
|
else if (this.s < 0)
|
|
187
263
|
this.s = 0;
|
|
188
264
|
Color.Converter.HSLToRGB(this);
|
|
265
|
+
return this;
|
|
189
266
|
}
|
|
190
|
-
;
|
|
191
267
|
desaturate(v) {
|
|
192
|
-
|
|
268
|
+
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
|
|
269
|
+
this.s -= v / 100;
|
|
270
|
+
}
|
|
271
|
+
else if ("number" == typeof v) {
|
|
272
|
+
if (v >= 0.0 && v <= 1.0) {
|
|
273
|
+
// range 255
|
|
274
|
+
this.s -= this.s * v;
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
// range 0-1
|
|
278
|
+
this.s -= this.s * (v / 255);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
throw new Error("error: bad modifier format (percent or number)");
|
|
283
|
+
}
|
|
284
|
+
if (this.s > 1)
|
|
285
|
+
this.s = 1;
|
|
286
|
+
else if (this.s < 0)
|
|
287
|
+
this.s = 0;
|
|
288
|
+
Color.Converter.HSLToRGB(this);
|
|
289
|
+
return this;
|
|
193
290
|
}
|
|
194
|
-
|
|
291
|
+
// lighten(v: string | number): Color {
|
|
292
|
+
// if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
|
|
293
|
+
// this.l += v / 100;
|
|
294
|
+
// } else if ("number" == typeof v) {
|
|
295
|
+
// if (v >= -1.0 && v <= 1.0) {
|
|
296
|
+
// // range 0.0...1.0
|
|
297
|
+
// this.l += v;
|
|
298
|
+
// } else {
|
|
299
|
+
// // range 255
|
|
300
|
+
// this.l += v / 255;
|
|
301
|
+
// }
|
|
302
|
+
// } else {
|
|
303
|
+
// throw new Error("error: bad modifier format (percent or number)");
|
|
304
|
+
// }
|
|
305
|
+
// if (this.l > 1) this.l = 1;
|
|
306
|
+
// else if (this.l < 0) this.l = 0;
|
|
307
|
+
// Color.Converter.HSLToRGB(this);
|
|
308
|
+
// return this;
|
|
309
|
+
// }
|
|
195
310
|
lighten(v) {
|
|
196
|
-
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN)
|
|
197
|
-
this.l += v / 100;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
311
|
+
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
|
|
312
|
+
this.l += (1 - this.l) * (v / 100);
|
|
313
|
+
}
|
|
314
|
+
else if ("number" == typeof v) {
|
|
315
|
+
if (v >= 0.0 && v <= 1.0) {
|
|
316
|
+
// range 0.0...1.0
|
|
317
|
+
this.l += (1 - this.l) * v;
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
// range 255
|
|
321
|
+
this.l += (1 - this.l) * (v / 255);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
201
325
|
throw new Error("error: bad modifier format (percent or number)");
|
|
326
|
+
}
|
|
202
327
|
if (this.l > 1)
|
|
203
328
|
this.l = 1;
|
|
204
329
|
else if (this.l < 0)
|
|
205
330
|
this.l = 0;
|
|
206
331
|
Color.Converter.HSLToRGB(this);
|
|
332
|
+
return this;
|
|
207
333
|
}
|
|
208
|
-
;
|
|
209
334
|
darken(v) {
|
|
210
|
-
|
|
335
|
+
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
|
|
336
|
+
this.l -= this.l * (v / 100);
|
|
337
|
+
}
|
|
338
|
+
else if ("number" == typeof v) {
|
|
339
|
+
if (v >= 0.0 && v <= 1.0) {
|
|
340
|
+
// range 0.0...1.0
|
|
341
|
+
this.l -= this.l * v;
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
// range 255
|
|
345
|
+
this.l -= this.l * (v / 255);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
throw new Error("error: bad modifier format (percent or number)");
|
|
350
|
+
}
|
|
351
|
+
if (this.l > 1)
|
|
352
|
+
this.l = 1;
|
|
353
|
+
else if (this.l < 0)
|
|
354
|
+
this.l = 0;
|
|
355
|
+
Color.Converter.HSLToRGB(this);
|
|
356
|
+
return this;
|
|
211
357
|
}
|
|
212
|
-
;
|
|
213
358
|
fadein(v) {
|
|
214
|
-
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN)
|
|
215
|
-
this.a += v / 100;
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
359
|
+
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
|
|
360
|
+
this.a += (1 - this.a) * (v / 100);
|
|
361
|
+
}
|
|
362
|
+
else if ("number" == typeof v) {
|
|
363
|
+
if (v >= 0.0 && v <= 1.0) {
|
|
364
|
+
// range 0-1
|
|
365
|
+
this.a += (1 - this.a) * v;
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
// range 255
|
|
369
|
+
this.a += (1 - this.a) * (v / 255);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
219
373
|
throw new Error("error: bad modifier format (percent or number)");
|
|
374
|
+
}
|
|
375
|
+
console.log("New alpha", this.a);
|
|
220
376
|
if (this.a > 1)
|
|
221
377
|
this.a = 1;
|
|
222
378
|
else if (this.a < 0)
|
|
223
379
|
this.a = 0;
|
|
224
380
|
Color.Converter.HSLToRGB(this);
|
|
381
|
+
return this;
|
|
225
382
|
}
|
|
226
|
-
;
|
|
227
383
|
fadeout(v) {
|
|
228
|
-
|
|
384
|
+
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
|
|
385
|
+
this.a -= v / 100;
|
|
386
|
+
}
|
|
387
|
+
else if ("number" == typeof v) {
|
|
388
|
+
if (v >= 0.0 && v <= 1.0) {
|
|
389
|
+
// range 0-1
|
|
390
|
+
this.a -= v;
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
// range 255
|
|
394
|
+
this.a -= v / 255;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
throw new Error("error: bad modifier format (percent or number)");
|
|
399
|
+
}
|
|
400
|
+
if (this.a > 1)
|
|
401
|
+
this.a = 1;
|
|
402
|
+
else if (this.a < 0)
|
|
403
|
+
this.a = 0;
|
|
404
|
+
Color.Converter.HSLToRGB(this);
|
|
405
|
+
return this;
|
|
229
406
|
}
|
|
230
|
-
;
|
|
231
407
|
spin(v) {
|
|
232
408
|
if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN)
|
|
233
409
|
this.h += v / 100;
|
|
234
|
-
else if ("number" == typeof v)
|
|
410
|
+
else if ("number" == typeof v)
|
|
411
|
+
// range 360
|
|
235
412
|
this.h += v / 360;
|
|
236
413
|
else
|
|
237
414
|
throw new Error("error: bad modifier format (percent or number)");
|
|
@@ -240,8 +417,8 @@ export class Color {
|
|
|
240
417
|
else if (this.h < 0)
|
|
241
418
|
this.h = 0;
|
|
242
419
|
Color.Converter.HSLToRGB(this);
|
|
420
|
+
return this;
|
|
243
421
|
}
|
|
244
|
-
;
|
|
245
422
|
static makeRGB(...args) {
|
|
246
423
|
const c = new Color();
|
|
247
424
|
let sanitized;
|
|
@@ -251,12 +428,15 @@ export class Color {
|
|
|
251
428
|
c.r = sanitized[0];
|
|
252
429
|
c.g = sanitized[1];
|
|
253
430
|
c.b = sanitized[2];
|
|
254
|
-
if (arguments.length == 4)
|
|
431
|
+
if (arguments.length == 4) {
|
|
255
432
|
c.a = arguments[3];
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
c.a = 1.0;
|
|
436
|
+
}
|
|
256
437
|
Color.Converter.RGBToHSL(c);
|
|
257
438
|
return c;
|
|
258
439
|
}
|
|
259
|
-
;
|
|
260
440
|
static makeHSL(...args) {
|
|
261
441
|
const c = new Color();
|
|
262
442
|
let sanitized;
|
|
@@ -268,15 +448,16 @@ export class Color {
|
|
|
268
448
|
c.l = sanitized[2];
|
|
269
449
|
if (arguments.length == 4)
|
|
270
450
|
c.a = arguments[3];
|
|
451
|
+
else
|
|
452
|
+
c.a = 1.0;
|
|
271
453
|
Color.Converter.HSLToRGB(c);
|
|
272
454
|
return c;
|
|
273
455
|
}
|
|
274
|
-
;
|
|
275
456
|
static makeHEX(value) {
|
|
276
457
|
var c = new Color(), sanitized;
|
|
277
458
|
// Edit Ika 2018-0308
|
|
278
459
|
// Allow leading '#'
|
|
279
|
-
if (value && value.startsWith(
|
|
460
|
+
if (value && value.startsWith("#"))
|
|
280
461
|
value = value.substr(1);
|
|
281
462
|
Color.Validator.checkHEX(value);
|
|
282
463
|
if (value.length == 3) {
|
|
@@ -290,10 +471,10 @@ export class Color {
|
|
|
290
471
|
c.r = sanitized[0];
|
|
291
472
|
c.g = sanitized[1];
|
|
292
473
|
c.b = sanitized[2];
|
|
474
|
+
c.a = 1.0; // TODO: Accept #xxxxxxxx (8 chars, too, for alpha)
|
|
293
475
|
Color.Converter.RGBToHSL(c);
|
|
294
476
|
return c;
|
|
295
477
|
}
|
|
296
|
-
;
|
|
297
478
|
/**
|
|
298
479
|
* Parse the given color string. Currently only these formate are recognized: hex, rgb, rgba.
|
|
299
480
|
*
|
|
@@ -304,24 +485,30 @@ export class Color {
|
|
|
304
485
|
* @return {Color} The color instance that's represented by the given string.
|
|
305
486
|
*/
|
|
306
487
|
static parse(str) {
|
|
307
|
-
if (typeof str ==
|
|
488
|
+
if (typeof str == "undefined")
|
|
308
489
|
return null;
|
|
309
490
|
if ((str = str.trim().toLowerCase()).length == 0)
|
|
310
491
|
return null;
|
|
311
|
-
if (str.startsWith(
|
|
492
|
+
if (str.startsWith("#"))
|
|
312
493
|
return Color.makeHEX(str.substring(1, str.length));
|
|
313
|
-
if (str.startsWith(
|
|
314
|
-
var parts = /^rgba?\((\d
|
|
494
|
+
if (str.startsWith("rgb")) {
|
|
495
|
+
var parts = str.match(/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,?\s*(\d*(?:\.\d+\s*)?)\)$/);
|
|
496
|
+
if (!parts) {
|
|
497
|
+
throw "Unrecognized color format (2): " + str;
|
|
498
|
+
}
|
|
315
499
|
// [ str, r, g, b, a|undefined ]
|
|
316
|
-
|
|
500
|
+
// console.log("parts", parts);
|
|
501
|
+
if (parts.length <= 4 || typeof parts[4] == "undefined" || parts[4] == "") {
|
|
317
502
|
return Color.makeRGB(parts[1], parts[2], parts[3]);
|
|
318
|
-
|
|
319
|
-
|
|
503
|
+
}
|
|
504
|
+
else {
|
|
505
|
+
return Color.makeRGB(parts[1], parts[2], parts[3], Number(parts[4]));
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
else {
|
|
509
|
+
throw "Unrecognized color format (1): " + str;
|
|
320
510
|
}
|
|
321
|
-
else
|
|
322
|
-
throw "Unrecognized color format: " + str;
|
|
323
511
|
}
|
|
324
|
-
;
|
|
325
512
|
/**
|
|
326
513
|
* Create a clone of this color (RGB).
|
|
327
514
|
*
|
|
@@ -333,7 +520,6 @@ export class Color {
|
|
|
333
520
|
clone() {
|
|
334
521
|
return Color.makeRGB(this.r, this.g, this.b, this.a);
|
|
335
522
|
}
|
|
336
|
-
;
|
|
337
523
|
/**
|
|
338
524
|
* Interpolate this color on the RGB scale.
|
|
339
525
|
*
|
|
@@ -351,8 +537,7 @@ export class Color {
|
|
|
351
537
|
this.a += (c.a - c.a) * t;
|
|
352
538
|
return this;
|
|
353
539
|
}
|
|
354
|
-
|
|
355
|
-
}
|
|
540
|
+
} // END class
|
|
356
541
|
Color.Sanitizer = {
|
|
357
542
|
RGB: function (...args) {
|
|
358
543
|
var o = [];
|
|
@@ -370,17 +555,21 @@ Color.Sanitizer = {
|
|
|
370
555
|
o[i] = c / 100;
|
|
371
556
|
}
|
|
372
557
|
else {
|
|
373
|
-
|
|
374
|
-
if ("string" == typeof c && (c = parseInt(c)) == NaN)
|
|
558
|
+
if ("string" == typeof c && (c = parseInt(c)) == NaN) {
|
|
375
559
|
throw new Error("Bad format");
|
|
376
|
-
|
|
560
|
+
}
|
|
561
|
+
if (c < 0) {
|
|
377
562
|
throw new Error("Bad format");
|
|
563
|
+
}
|
|
378
564
|
//else if( allAreFrac ) o[i] = c; // c >= 0 && c <= 1 (all)
|
|
379
|
-
else if (c >= 0 && c < 1)
|
|
565
|
+
else if (c >= 0 && c < 1) {
|
|
380
566
|
o[i] = c;
|
|
567
|
+
}
|
|
381
568
|
// else if(c >= 0.0 && c <= 1.0) o[i] = c;
|
|
382
|
-
else if (c >= 1 && c < 256)
|
|
383
|
-
o[i] = c / 255;
|
|
569
|
+
else if (c >= 1 && c < 256) {
|
|
570
|
+
o[i] = c / 255;
|
|
571
|
+
}
|
|
572
|
+
// ???
|
|
384
573
|
// else if(c >= 0 && c < 256) o[i] = c/255;
|
|
385
574
|
else
|
|
386
575
|
throw new Error("Bad format (" + c + ")");
|
|
@@ -503,5 +692,4 @@ Color.Converter = {
|
|
|
503
692
|
return p;
|
|
504
693
|
}
|
|
505
694
|
};
|
|
506
|
-
; // END class
|
|
507
695
|
//# sourceMappingURL=Color.js.map
|