@thi.ng/color 5.6.2 → 5.6.4
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/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/alpha.js +6 -10
- package/analog.js +35 -67
- package/api/constants.js +128 -156
- package/api/gradients.js +0 -1
- package/api/names.js +154 -151
- package/api/ranges.js +0 -1
- package/api/system.js +21 -26
- package/api.js +27 -32
- package/clamp.js +18 -29
- package/closest-hue.js +6 -12
- package/color-range.js +159 -228
- package/color.js +29 -28
- package/contrast.js +7 -17
- package/convert.js +19 -40
- package/cosine-gradients.js +177 -229
- package/css/css.js +27 -53
- package/css/parse-css.js +94 -160
- package/defcolor.js +97 -108
- package/distance.js +96 -187
- package/gradients.js +29 -37
- package/hcy/hcy-rgb.js +20 -13
- package/hcy/hcy.js +9 -11
- package/hsi/hsi-rgb.js +32 -30
- package/hsi/hsi.js +9 -11
- package/hsl/hsl-css.js +9 -10
- package/hsl/hsl-hsv.js +12 -9
- package/hsl/hsl-rgb.js +14 -6
- package/hsl/hsl.js +14 -16
- package/hsv/hsv-css.js +4 -1
- package/hsv/hsv-hsl.js +11 -8
- package/hsv/hsv-rgb.js +14 -6
- package/hsv/hsv.js +14 -16
- package/hue.js +12 -12
- package/int/int-css.js +10 -6
- package/int/int-int.js +6 -10
- package/int/int-rgb.js +16 -5
- package/int/int-srgb.js +22 -4
- package/int/int.js +136 -142
- package/internal/css.js +16 -12
- package/internal/dispatch.js +6 -2
- package/internal/ensure.js +18 -16
- package/internal/matrix-ops.js +39 -41
- package/internal/scale.js +4 -2
- package/invert.js +46 -39
- package/is-black.js +12 -5
- package/is-gamut.js +8 -13
- package/is-gray.js +12 -5
- package/is-white.js +14 -7
- package/lab/lab-css.js +4 -9
- package/lab/lab-lab.js +6 -2
- package/lab/lab-lch.js +18 -10
- package/lab/lab-rgb.js +6 -14
- package/lab/lab-xyz.js +16 -20
- package/lab/lab50.js +18 -15
- package/lab/lab65.js +18 -15
- package/lch/lch-css.js +4 -9
- package/lch/lch.js +18 -23
- package/lighten.js +13 -17
- package/linear.js +6 -16
- package/luminance-rgb.js +14 -22
- package/luminance.js +16 -14
- package/max-chroma.js +1340 -227
- package/mix.js +34 -82
- package/oklab/oklab-css.js +4 -9
- package/oklab/oklab-rgb.js +17 -23
- package/oklab/oklab-xyz.js +22 -9
- package/oklab/oklab.js +19 -22
- package/oklch/oklab-oklch.js +10 -11
- package/oklch/oklch-css.js +4 -9
- package/oklch/oklch-oklab.js +9 -9
- package/oklch/oklch.js +14 -20
- package/package.json +19 -17
- package/rgb/hue-rgb.js +14 -11
- package/rgb/kelvin-rgba.js +23 -22
- package/rgb/rgb-css.js +4 -1
- package/rgb/rgb-hcv.js +14 -15
- package/rgb/rgb-hcy.js +10 -14
- package/rgb/rgb-hsi.js +13 -8
- package/rgb/rgb-hsl.js +8 -5
- package/rgb/rgb-hsv.js +7 -4
- package/rgb/rgb-lab.js +6 -18
- package/rgb/rgb-oklab.js +13 -19
- package/rgb/rgb-srgb.js +18 -8
- package/rgb/rgb-xyz.js +6 -19
- package/rgb/rgb-ycc.js +12 -17
- package/rgb/rgb.js +25 -22
- package/rotate.js +25 -38
- package/sort.js +24 -72
- package/srgb/srgb-css.js +9 -9
- package/srgb/srgb-int.js +6 -10
- package/srgb/srgb-rgb.js +18 -8
- package/srgb/srgb.js +16 -13
- package/strategies.js +42 -112
- package/swatches.js +28 -5
- package/tint.js +27 -53
- package/transform.js +274 -149
- package/variations.js +10 -9
- package/xyy/xyy-xyz.js +12 -11
- package/xyy/xyy.js +16 -13
- package/xyz/wavelength-xyz.js +14 -28
- package/xyz/xyz-lab.js +17 -26
- package/xyz/xyz-oklab.js +4 -1
- package/xyz/xyz-rgb.js +6 -18
- package/xyz/xyz-xyy.js +13 -12
- package/xyz/xyz-xyz.js +6 -2
- package/xyz/xyz50.js +20 -17
- package/xyz/xyz65.js +20 -17
- package/ycc/ycc-rgb.js +14 -19
- package/ycc/ycc.js +12 -9
package/css/parse-css.js
CHANGED
|
@@ -12,174 +12,108 @@ import { INV8BIT } from "../api/constants.js";
|
|
|
12
12
|
import { CSS_NAMES } from "../api/names.js";
|
|
13
13
|
import { CSS_SYSTEM_COLORS } from "../api/system.js";
|
|
14
14
|
import { intArgb32Srgb } from "../int/int-srgb.js";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
__numOrPercent(c, 1, INV8BIT, true),
|
|
75
|
-
__alpha(d),
|
|
76
|
-
]);
|
|
77
|
-
case "hsl":
|
|
78
|
-
case "hsla":
|
|
79
|
-
return new ParsedColor("hsl", [
|
|
80
|
-
__hue(a),
|
|
81
|
-
__percent(b),
|
|
82
|
-
__percent(c),
|
|
83
|
-
__alpha(d),
|
|
84
|
-
]);
|
|
85
|
-
case "lab":
|
|
86
|
-
return new ParsedColor("lab50", [
|
|
87
|
-
__numOrPercent(a),
|
|
88
|
-
__numOrPercent(b, 1.25),
|
|
89
|
-
__numOrPercent(c, 1.25),
|
|
90
|
-
__alpha(d),
|
|
91
|
-
]);
|
|
92
|
-
case "lch":
|
|
93
|
-
return new ParsedColor(mode, [
|
|
94
|
-
__numOrPercent(a),
|
|
95
|
-
__numOrPercent(b, 1.5),
|
|
96
|
-
__hue(c),
|
|
97
|
-
__alpha(d),
|
|
98
|
-
]);
|
|
99
|
-
case "oklab":
|
|
100
|
-
return new ParsedColor(mode, [
|
|
101
|
-
__numOrPercent(a, 1, 1),
|
|
102
|
-
__numOrPercent(b, 0.4, 1),
|
|
103
|
-
__numOrPercent(c, 0.4, 1),
|
|
104
|
-
__alpha(d),
|
|
105
|
-
]);
|
|
106
|
-
case "oklch":
|
|
107
|
-
return new ParsedColor(mode, [
|
|
108
|
-
__numOrPercent(a, 1, 1),
|
|
109
|
-
__numOrPercent(b, 0.4, 1),
|
|
110
|
-
__hue(c),
|
|
111
|
-
__alpha(d),
|
|
112
|
-
]);
|
|
113
|
-
default:
|
|
114
|
-
unsupported(`color mode: ${mode}`);
|
|
115
|
-
}
|
|
15
|
+
const parseCss = (src) => {
|
|
16
|
+
src = (isString(src) ? src : src.deref()).toLowerCase();
|
|
17
|
+
const named = CSS_NAMES[src] || CSS_SYSTEM_COLORS[src];
|
|
18
|
+
if (named || src[0] === "#")
|
|
19
|
+
return new ParsedColor(
|
|
20
|
+
"srgb",
|
|
21
|
+
intArgb32Srgb([], parseHex(named || src))
|
|
22
|
+
);
|
|
23
|
+
const parts = src.split(/[(),/ ]+/);
|
|
24
|
+
const [mode, a, b, c, d] = parts;
|
|
25
|
+
assert(parts.length === 5 || parts.length === 6, `invalid color: ${src}`);
|
|
26
|
+
switch (mode) {
|
|
27
|
+
case "rgb":
|
|
28
|
+
case "rgba":
|
|
29
|
+
return new ParsedColor("srgb", [
|
|
30
|
+
__numOrPercent(a, 1, INV8BIT, true),
|
|
31
|
+
__numOrPercent(b, 1, INV8BIT, true),
|
|
32
|
+
__numOrPercent(c, 1, INV8BIT, true),
|
|
33
|
+
__alpha(d)
|
|
34
|
+
]);
|
|
35
|
+
case "hsl":
|
|
36
|
+
case "hsla":
|
|
37
|
+
return new ParsedColor("hsl", [
|
|
38
|
+
__hue(a),
|
|
39
|
+
__percent(b),
|
|
40
|
+
__percent(c),
|
|
41
|
+
__alpha(d)
|
|
42
|
+
]);
|
|
43
|
+
case "lab":
|
|
44
|
+
return new ParsedColor("lab50", [
|
|
45
|
+
__numOrPercent(a),
|
|
46
|
+
__numOrPercent(b, 1.25),
|
|
47
|
+
__numOrPercent(c, 1.25),
|
|
48
|
+
__alpha(d)
|
|
49
|
+
]);
|
|
50
|
+
case "lch":
|
|
51
|
+
return new ParsedColor(mode, [
|
|
52
|
+
__numOrPercent(a),
|
|
53
|
+
__numOrPercent(b, 1.5),
|
|
54
|
+
__hue(c),
|
|
55
|
+
__alpha(d)
|
|
56
|
+
]);
|
|
57
|
+
case "oklab":
|
|
58
|
+
return new ParsedColor(mode, [
|
|
59
|
+
__numOrPercent(a, 1, 1),
|
|
60
|
+
__numOrPercent(b, 0.4, 1),
|
|
61
|
+
__numOrPercent(c, 0.4, 1),
|
|
62
|
+
__alpha(d)
|
|
63
|
+
]);
|
|
64
|
+
case "oklch":
|
|
65
|
+
return new ParsedColor(mode, [
|
|
66
|
+
__numOrPercent(a, 1, 1),
|
|
67
|
+
__numOrPercent(b, 0.4, 1),
|
|
68
|
+
__hue(c),
|
|
69
|
+
__alpha(d)
|
|
70
|
+
]);
|
|
71
|
+
default:
|
|
72
|
+
unsupported(`color mode: ${mode}`);
|
|
73
|
+
}
|
|
116
74
|
};
|
|
117
|
-
/**
|
|
118
|
-
* Scale factors for various CSS angle units
|
|
119
|
-
*
|
|
120
|
-
* @remarks
|
|
121
|
-
* Reference:
|
|
122
|
-
* - https://www.w3.org/TR/css-values-4/#angle-value
|
|
123
|
-
*
|
|
124
|
-
* @internal
|
|
125
|
-
*/
|
|
126
75
|
const HUE_NORMS = {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
76
|
+
rad: TAU,
|
|
77
|
+
grad: 400,
|
|
78
|
+
turn: 1,
|
|
79
|
+
deg: 360
|
|
131
80
|
};
|
|
132
|
-
/** @internal */
|
|
133
81
|
const __hue = (x) => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
82
|
+
const match = /^(-?[0-9.]+)(deg|rad|grad|turn)?$/.exec(x);
|
|
83
|
+
assert(!!match, `expected hue, got: ${x}`);
|
|
84
|
+
return fract(parseFloat(match[1]) / (HUE_NORMS[match[2]] || 360));
|
|
137
85
|
};
|
|
138
|
-
|
|
139
|
-
const __alpha = (x) => (x ? __numOrPercent(x, 1, 1, true) : 1);
|
|
140
|
-
/** @internal */
|
|
86
|
+
const __alpha = (x) => x ? __numOrPercent(x, 1, 1, true) : 1;
|
|
141
87
|
const __percent = (x, clamp = true) => {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
88
|
+
assert(/^([0-9.]+)%$/.test(x), `expected percentage, got: ${x}`);
|
|
89
|
+
const res = parseFloat(x) / 100;
|
|
90
|
+
return clamp ? clamp01(res) : res;
|
|
145
91
|
};
|
|
146
|
-
/** @internal */
|
|
147
92
|
const __numOrPercent = (x, scalePerc = 1, scale = 0.01, clamp = false) => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
93
|
+
assert(/^-?[0-9.]+%?$/.test(x), `expected number or percentage, got: ${x}`);
|
|
94
|
+
const res = parseFloat(x) * (x.endsWith("%") ? 0.01 * scalePerc : scale);
|
|
95
|
+
return clamp ? clamp01(res) : res;
|
|
151
96
|
};
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
export const parseHex = (src) => {
|
|
168
|
-
const match = /^#?([0-9a-f]{3,8})$/i.exec(src);
|
|
169
|
-
if (match) {
|
|
170
|
-
const hex = match[1];
|
|
171
|
-
const val = parseInt(hex, 16);
|
|
172
|
-
switch (hex.length) {
|
|
173
|
-
case 3:
|
|
174
|
-
return (interleave4_12_24(val) | 0xff000000) >>> 0;
|
|
175
|
-
case 4:
|
|
176
|
-
return rotateRight(interleave4_16_32(val), 8);
|
|
177
|
-
case 6:
|
|
178
|
-
return (val | 0xff000000) >>> 0;
|
|
179
|
-
case 8:
|
|
180
|
-
return rotateRight(val, 8);
|
|
181
|
-
default:
|
|
182
|
-
}
|
|
97
|
+
const parseHex = (src) => {
|
|
98
|
+
const match = /^#?([0-9a-f]{3,8})$/i.exec(src);
|
|
99
|
+
if (match) {
|
|
100
|
+
const hex = match[1];
|
|
101
|
+
const val = parseInt(hex, 16);
|
|
102
|
+
switch (hex.length) {
|
|
103
|
+
case 3:
|
|
104
|
+
return (interleave4_12_24(val) | 4278190080) >>> 0;
|
|
105
|
+
case 4:
|
|
106
|
+
return rotateRight(interleave4_16_32(val), 8);
|
|
107
|
+
case 6:
|
|
108
|
+
return (val | 4278190080) >>> 0;
|
|
109
|
+
case 8:
|
|
110
|
+
return rotateRight(val, 8);
|
|
111
|
+
default:
|
|
183
112
|
}
|
|
184
|
-
|
|
113
|
+
}
|
|
114
|
+
return illegalArgs(`invalid hex color: "${src}"`);
|
|
115
|
+
};
|
|
116
|
+
export {
|
|
117
|
+
parseCss,
|
|
118
|
+
parseHex
|
|
185
119
|
};
|
package/defcolor.js
CHANGED
|
@@ -17,113 +17,102 @@ import { convert, defConversions } from "./convert.js";
|
|
|
17
17
|
import { parseCss } from "./css/parse-css.js";
|
|
18
18
|
import { intArgb32Rgb } from "./int/int-rgb.js";
|
|
19
19
|
import { __ensureArgs } from "./internal/ensure.js";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
return acc;
|
|
30
|
-
}, channels);
|
|
31
|
-
const min = Object.freeze(order.map((id) => channels[id].range[0]));
|
|
32
|
-
const max = Object.freeze(order.map((id) => channels[id].range[1]));
|
|
33
|
-
// fix alpha channel for randomize()
|
|
34
|
-
const minR = set4([], min);
|
|
35
|
-
const maxR = set4([], max);
|
|
36
|
-
minR[numChannels - 1] = 1;
|
|
37
|
-
const hueChanID = order.findIndex((id) => !!channels[id].hue);
|
|
38
|
-
const $Color = class {
|
|
39
|
-
offset;
|
|
40
|
-
stride;
|
|
41
|
-
buf;
|
|
42
|
-
constructor(buf, offset = 0, stride = 1) {
|
|
43
|
-
this.offset = offset;
|
|
44
|
-
this.stride = stride;
|
|
45
|
-
this.buf = buf || [0, 0, 0, 0];
|
|
46
|
-
this.offset = offset;
|
|
47
|
-
this.stride = stride;
|
|
48
|
-
}
|
|
49
|
-
get mode() {
|
|
50
|
-
return spec.mode;
|
|
51
|
-
}
|
|
52
|
-
get length() {
|
|
53
|
-
return numChannels;
|
|
54
|
-
}
|
|
55
|
-
get range() {
|
|
56
|
-
return [min, max];
|
|
57
|
-
}
|
|
58
|
-
get [Symbol.toStringTag]() {
|
|
59
|
-
return spec.mode;
|
|
60
|
-
}
|
|
61
|
-
get xyz() {
|
|
62
|
-
return [this[0], this[1], this[2]];
|
|
63
|
-
}
|
|
64
|
-
[Symbol.iterator]() {
|
|
65
|
-
return stridedValues(this.buf, this.length, this.offset, this.stride);
|
|
66
|
-
}
|
|
67
|
-
copy() {
|
|
68
|
-
return new $Color(this.deref());
|
|
69
|
-
}
|
|
70
|
-
copyView() {
|
|
71
|
-
return new $Color(this.buf, this.offset, this.stride);
|
|
72
|
-
}
|
|
73
|
-
empty() {
|
|
74
|
-
return new $Color();
|
|
75
|
-
}
|
|
76
|
-
deref() {
|
|
77
|
-
return [this[0], this[1], this[2], this[3]];
|
|
78
|
-
}
|
|
79
|
-
set(src) {
|
|
80
|
-
return set4(this, src);
|
|
81
|
-
}
|
|
82
|
-
clamp() {
|
|
83
|
-
hueChanID >= 0 && (this[hueChanID] = fract(this[hueChanID]));
|
|
84
|
-
clamp4(null, this, min, max);
|
|
85
|
-
return this;
|
|
86
|
-
}
|
|
87
|
-
eqDelta(o, eps = EPS) {
|
|
88
|
-
return eqDelta4(this, o, eps);
|
|
89
|
-
}
|
|
90
|
-
randomize(rnd) {
|
|
91
|
-
return randMinMax(this, minR, maxR, rnd);
|
|
92
|
-
}
|
|
93
|
-
toJSON() {
|
|
94
|
-
return this.deref();
|
|
95
|
-
}
|
|
96
|
-
toString() {
|
|
97
|
-
return vector(4, 4)(this);
|
|
98
|
-
}
|
|
20
|
+
const defColor = (spec) => {
|
|
21
|
+
const channels = spec.channels || {};
|
|
22
|
+
const order = spec.order;
|
|
23
|
+
const numChannels = order.length;
|
|
24
|
+
order.reduce((acc, id) => {
|
|
25
|
+
acc[id] = {
|
|
26
|
+
range: [0, 1],
|
|
27
|
+
...channels[id]
|
|
99
28
|
};
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
29
|
+
return acc;
|
|
30
|
+
}, channels);
|
|
31
|
+
const min = Object.freeze(order.map((id) => channels[id].range[0]));
|
|
32
|
+
const max = Object.freeze(order.map((id) => channels[id].range[1]));
|
|
33
|
+
const minR = set4([], min);
|
|
34
|
+
const maxR = set4([], max);
|
|
35
|
+
minR[numChannels - 1] = 1;
|
|
36
|
+
const hueChanID = order.findIndex((id) => !!channels[id].hue);
|
|
37
|
+
const $Color = class {
|
|
38
|
+
constructor(buf, offset = 0, stride = 1) {
|
|
39
|
+
this.offset = offset;
|
|
40
|
+
this.stride = stride;
|
|
41
|
+
this.buf = buf || [0, 0, 0, 0];
|
|
42
|
+
this.offset = offset;
|
|
43
|
+
this.stride = stride;
|
|
44
|
+
}
|
|
45
|
+
buf;
|
|
46
|
+
get mode() {
|
|
47
|
+
return spec.mode;
|
|
48
|
+
}
|
|
49
|
+
get length() {
|
|
50
|
+
return numChannels;
|
|
51
|
+
}
|
|
52
|
+
get range() {
|
|
53
|
+
return [min, max];
|
|
54
|
+
}
|
|
55
|
+
get [Symbol.toStringTag]() {
|
|
56
|
+
return spec.mode;
|
|
57
|
+
}
|
|
58
|
+
get xyz() {
|
|
59
|
+
return [this[0], this[1], this[2]];
|
|
60
|
+
}
|
|
61
|
+
[Symbol.iterator]() {
|
|
62
|
+
return stridedValues(
|
|
63
|
+
this.buf,
|
|
64
|
+
this.length,
|
|
65
|
+
this.offset,
|
|
66
|
+
this.stride
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
copy() {
|
|
70
|
+
return new $Color(this.deref());
|
|
71
|
+
}
|
|
72
|
+
copyView() {
|
|
73
|
+
return new $Color(this.buf, this.offset, this.stride);
|
|
74
|
+
}
|
|
75
|
+
empty() {
|
|
76
|
+
return new $Color();
|
|
77
|
+
}
|
|
78
|
+
deref() {
|
|
79
|
+
return [this[0], this[1], this[2], this[3]];
|
|
80
|
+
}
|
|
81
|
+
set(src) {
|
|
82
|
+
return set4(this, src);
|
|
83
|
+
}
|
|
84
|
+
clamp() {
|
|
85
|
+
hueChanID >= 0 && (this[hueChanID] = fract(this[hueChanID]));
|
|
86
|
+
clamp4(null, this, min, max);
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
eqDelta(o, eps = EPS) {
|
|
90
|
+
return eqDelta4(this, o, eps);
|
|
91
|
+
}
|
|
92
|
+
randomize(rnd) {
|
|
93
|
+
return randMinMax(this, minR, maxR, rnd);
|
|
94
|
+
}
|
|
95
|
+
toJSON() {
|
|
96
|
+
return this.deref();
|
|
97
|
+
}
|
|
98
|
+
toString() {
|
|
99
|
+
return vector(4, 4)(this);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
declareIndices($Color.prototype, order);
|
|
103
|
+
defConversions(spec.mode, spec.from);
|
|
104
|
+
defConversions("rgb", { [spec.mode]: spec.toRgb });
|
|
105
|
+
const fromColor = (src, mode, xs) => {
|
|
106
|
+
const res = new $Color(...xs);
|
|
107
|
+
return mode !== spec.mode ? convert(res, src, spec.mode, mode) : res.set(src);
|
|
108
|
+
};
|
|
109
|
+
const factory = (src, ...xs) => src == null ? new $Color() : isString(src) ? factory(parseCss(src), ...xs) : isArrayLike(src) ? isString(src.mode) ? fromColor(src, src.mode, xs) : new $Color(src, ...xs) : implementsFunction(src, "deref") ? fromColor(src.deref(), src.mode, xs) : isNumber(src) ? xs.length && xs.every(isNumber) ? new $Color(...__ensureArgs([src, ...xs])) : fromColor(intArgb32Rgb([], src), "rgb", xs) : illegalArgs(`can't create a ${spec.mode} color from: ${src}`);
|
|
110
|
+
factory.class = $Color;
|
|
111
|
+
factory.range = [min, max];
|
|
112
|
+
factory.random = (rnd, buf, idx, stride) => new $Color(buf, idx, stride).randomize(rnd);
|
|
113
|
+
factory.mapBuffer = (buf, num = buf.length / numChannels | 0, start = 0, cstride = 1, estride = numChannels) => mapStridedBuffer($Color, buf, num, start, cstride, estride);
|
|
114
|
+
return factory;
|
|
115
|
+
};
|
|
116
|
+
export {
|
|
117
|
+
defColor
|
|
129
118
|
};
|