@visulima/colorize 1.4.23 → 1.4.24
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 +27 -0
- package/dist/gradient.cjs +3 -62
- package/dist/gradient.d.cts +2 -2
- package/dist/gradient.d.mts +2 -2
- package/dist/gradient.d.ts +2 -2
- package/dist/gradient.mjs +3 -56
- package/dist/index.browser.mjs +1 -63
- package/dist/index.server.cjs +2 -266
- package/dist/index.server.d.cts +72 -71
- package/dist/index.server.mjs +1 -63
- package/dist/packem_shared/Colorize-Bn8gI3ME.mjs +1 -0
- package/dist/packem_shared/Colorize-CfIXnDUD.mjs +2 -0
- package/dist/packem_shared/GradientBuilder-C2IS34v_.cjs +1 -0
- package/dist/packem_shared/GradientBuilder-I_j6wpvU.mjs +1 -0
- package/dist/packem_shared/ansi256To16--f09kvlF.cjs +1 -0
- package/dist/packem_shared/ansi256To16-YETEPW8R.mjs +1 -0
- package/dist/packem_shared/colorize.server-9hV-s1hY.mjs +2 -0
- package/dist/packem_shared/colorize.server-B0BWdm8_.cjs +2 -0
- package/dist/packem_shared/convertHexToRgb-BEnfEytq.cjs +1 -0
- package/dist/packem_shared/convertHexToRgb-DGcGUKnj.mjs +1 -0
- package/dist/template.cjs +2 -158
- package/dist/template.d.cts +10 -8
- package/dist/template.d.mts +1 -1
- package/dist/template.d.ts +10 -8
- package/dist/template.mjs +2 -152
- package/dist/utils.cjs +1 -13
- package/dist/utils.mjs +1 -2
- package/package.json +19 -19
- package/dist/packem_shared/Colorize-B2nGcFjg.mjs +0 -417
- package/dist/packem_shared/Colorize-BihiZiAf.mjs +0 -258
- package/dist/packem_shared/GradientBuilder-Cn2sQ1aK.cjs +0 -505
- package/dist/packem_shared/GradientBuilder-Dy53F9zB.mjs +0 -501
- package/dist/packem_shared/colorize.server-0LnwnixR.cjs +0 -205
- package/dist/packem_shared/colorize.server-DSyvWqmN.mjs +0 -203
- package/dist/packem_shared/convertHexToRgb-DDy3Eccg.cjs +0 -19
- package/dist/packem_shared/convertHexToRgb-DOIRmKxM.mjs +0 -15
- package/dist/packem_shared/rgbToAnsi256-Cakhu-n9.cjs +0 -50
- package/dist/packem_shared/rgbToAnsi256-DcQVMIqi.mjs +0 -44
|
@@ -1,505 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
-
|
|
5
|
-
const convertHexToRgb = require('./convertHexToRgb-DDy3Eccg.cjs');
|
|
6
|
-
|
|
7
|
-
const colorNames = {
|
|
8
|
-
aliceblue: [240, 248, 255],
|
|
9
|
-
antiquewhite: [250, 235, 215],
|
|
10
|
-
aqua: [0, 255, 255],
|
|
11
|
-
aquamarine: [127, 255, 212],
|
|
12
|
-
azure: [240, 255, 255],
|
|
13
|
-
beige: [245, 245, 220],
|
|
14
|
-
bisque: [255, 228, 196],
|
|
15
|
-
black: [0, 0, 0],
|
|
16
|
-
blanchedalmond: [255, 235, 205],
|
|
17
|
-
blue: [0, 0, 255],
|
|
18
|
-
blueviolet: [138, 43, 226],
|
|
19
|
-
brown: [165, 42, 42],
|
|
20
|
-
burlywood: [222, 184, 135],
|
|
21
|
-
cadetblue: [95, 158, 160],
|
|
22
|
-
chartreuse: [127, 255, 0],
|
|
23
|
-
chocolate: [210, 105, 30],
|
|
24
|
-
coral: [255, 127, 80],
|
|
25
|
-
cornflowerblue: [100, 149, 237],
|
|
26
|
-
cornsilk: [255, 248, 220],
|
|
27
|
-
crimson: [220, 20, 60],
|
|
28
|
-
cyan: [0, 255, 255],
|
|
29
|
-
darkblue: [0, 0, 139],
|
|
30
|
-
darkcyan: [0, 139, 139],
|
|
31
|
-
darkgoldenrod: [184, 134, 11],
|
|
32
|
-
darkgray: [169, 169, 169],
|
|
33
|
-
darkgreen: [0, 100, 0],
|
|
34
|
-
darkgrey: [169, 169, 169],
|
|
35
|
-
darkkhaki: [189, 183, 107],
|
|
36
|
-
darkmagenta: [139, 0, 139],
|
|
37
|
-
darkolivegreen: [85, 107, 47],
|
|
38
|
-
darkorange: [255, 140, 0],
|
|
39
|
-
darkorchid: [153, 50, 204],
|
|
40
|
-
darkred: [139, 0, 0],
|
|
41
|
-
darksalmon: [233, 150, 122],
|
|
42
|
-
darkseagreen: [143, 188, 143],
|
|
43
|
-
darkslateblue: [72, 61, 139],
|
|
44
|
-
darkslategray: [47, 79, 79],
|
|
45
|
-
darkslategrey: [47, 79, 79],
|
|
46
|
-
darkturquoise: [0, 206, 209],
|
|
47
|
-
darkviolet: [148, 0, 211],
|
|
48
|
-
deeppink: [255, 20, 147],
|
|
49
|
-
deepskyblue: [0, 191, 255],
|
|
50
|
-
dimgray: [105, 105, 105],
|
|
51
|
-
dimgrey: [105, 105, 105],
|
|
52
|
-
dodgerblue: [30, 144, 255],
|
|
53
|
-
firebrick: [178, 34, 34],
|
|
54
|
-
floralwhite: [255, 250, 240],
|
|
55
|
-
forestgreen: [34, 139, 34],
|
|
56
|
-
fuchsia: [255, 0, 255],
|
|
57
|
-
gainsboro: [220, 220, 220],
|
|
58
|
-
ghostwhite: [248, 248, 255],
|
|
59
|
-
gold: [255, 215, 0],
|
|
60
|
-
goldenrod: [218, 165, 32],
|
|
61
|
-
gray: [128, 128, 128],
|
|
62
|
-
green: [0, 128, 0],
|
|
63
|
-
greenyellow: [173, 255, 47],
|
|
64
|
-
grey: [128, 128, 128],
|
|
65
|
-
honeydew: [240, 255, 240],
|
|
66
|
-
hotpink: [255, 105, 180],
|
|
67
|
-
indianred: [205, 92, 92],
|
|
68
|
-
indigo: [75, 0, 130],
|
|
69
|
-
ivory: [255, 255, 240],
|
|
70
|
-
khaki: [240, 230, 140],
|
|
71
|
-
lavender: [230, 230, 250],
|
|
72
|
-
lavenderblush: [255, 240, 245],
|
|
73
|
-
lawngreen: [124, 252, 0],
|
|
74
|
-
lemonchiffon: [255, 250, 205],
|
|
75
|
-
lightblue: [173, 216, 230],
|
|
76
|
-
lightcoral: [240, 128, 128],
|
|
77
|
-
lightcyan: [224, 255, 255],
|
|
78
|
-
lightgoldenrodyellow: [250, 250, 210],
|
|
79
|
-
lightgray: [211, 211, 211],
|
|
80
|
-
lightgreen: [144, 238, 144],
|
|
81
|
-
lightgrey: [211, 211, 211],
|
|
82
|
-
lightpink: [255, 182, 193],
|
|
83
|
-
lightsalmon: [255, 160, 122],
|
|
84
|
-
lightseagreen: [32, 178, 170],
|
|
85
|
-
lightskyblue: [135, 206, 250],
|
|
86
|
-
lightslategray: [119, 136, 153],
|
|
87
|
-
lightslategrey: [119, 136, 153],
|
|
88
|
-
lightsteelblue: [176, 196, 222],
|
|
89
|
-
lightyellow: [255, 255, 224],
|
|
90
|
-
lime: [0, 255, 0],
|
|
91
|
-
limegreen: [50, 205, 50],
|
|
92
|
-
linen: [250, 240, 230],
|
|
93
|
-
magenta: [255, 0, 255],
|
|
94
|
-
maroon: [128, 0, 0],
|
|
95
|
-
mediumaquamarine: [102, 205, 170],
|
|
96
|
-
mediumblue: [0, 0, 205],
|
|
97
|
-
mediumorchid: [186, 85, 211],
|
|
98
|
-
mediumpurple: [147, 112, 219],
|
|
99
|
-
mediumseagreen: [60, 179, 113],
|
|
100
|
-
mediumslateblue: [123, 104, 238],
|
|
101
|
-
mediumspringgreen: [0, 250, 154],
|
|
102
|
-
mediumturquoise: [72, 209, 204],
|
|
103
|
-
mediumvioletred: [199, 21, 133],
|
|
104
|
-
midnightblue: [25, 25, 112],
|
|
105
|
-
mintcream: [245, 255, 250],
|
|
106
|
-
mistyrose: [255, 228, 225],
|
|
107
|
-
moccasin: [255, 228, 181],
|
|
108
|
-
navajowhite: [255, 222, 173],
|
|
109
|
-
navy: [0, 0, 128],
|
|
110
|
-
oldlace: [253, 245, 230],
|
|
111
|
-
olive: [128, 128, 0],
|
|
112
|
-
olivedrab: [107, 142, 35],
|
|
113
|
-
orange: [255, 165, 0],
|
|
114
|
-
orangered: [255, 69, 0],
|
|
115
|
-
orchid: [218, 112, 214],
|
|
116
|
-
palegoldenrod: [238, 232, 170],
|
|
117
|
-
palegreen: [152, 251, 152],
|
|
118
|
-
paleturquoise: [175, 238, 238],
|
|
119
|
-
palevioletred: [219, 112, 147],
|
|
120
|
-
papayawhip: [255, 239, 213],
|
|
121
|
-
peachpuff: [255, 218, 185],
|
|
122
|
-
peru: [205, 133, 63],
|
|
123
|
-
pink: [255, 192, 203],
|
|
124
|
-
plum: [221, 160, 221],
|
|
125
|
-
powderblue: [176, 224, 230],
|
|
126
|
-
purple: [128, 0, 128],
|
|
127
|
-
rebeccapurple: [102, 51, 153],
|
|
128
|
-
red: [255, 0, 0],
|
|
129
|
-
rosybrown: [188, 143, 143],
|
|
130
|
-
royalblue: [65, 105, 225],
|
|
131
|
-
saddlebrown: [139, 69, 19],
|
|
132
|
-
salmon: [250, 128, 114],
|
|
133
|
-
sandybrown: [244, 164, 96],
|
|
134
|
-
seagreen: [46, 139, 87],
|
|
135
|
-
seashell: [255, 245, 238],
|
|
136
|
-
sienna: [160, 82, 45],
|
|
137
|
-
silver: [192, 192, 192],
|
|
138
|
-
skyblue: [135, 206, 235],
|
|
139
|
-
slateblue: [106, 90, 205],
|
|
140
|
-
slategray: [112, 128, 144],
|
|
141
|
-
slategrey: [112, 128, 144],
|
|
142
|
-
snow: [255, 250, 250],
|
|
143
|
-
springgreen: [0, 255, 127],
|
|
144
|
-
steelblue: [70, 130, 180],
|
|
145
|
-
tan: [210, 180, 140],
|
|
146
|
-
teal: [0, 128, 128],
|
|
147
|
-
thistle: [216, 191, 216],
|
|
148
|
-
tomato: [255, 99, 71],
|
|
149
|
-
turquoise: [64, 224, 208],
|
|
150
|
-
violet: [238, 130, 238],
|
|
151
|
-
wheat: [245, 222, 179],
|
|
152
|
-
white: [255, 255, 255],
|
|
153
|
-
whitesmoke: [245, 245, 245],
|
|
154
|
-
yellow: [255, 255, 0],
|
|
155
|
-
yellowgreen: [154, 205, 50]
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
var __defProp$4 = Object.defineProperty;
|
|
159
|
-
var __name$4 = (target, value) => __defProp$4(target, "name", { value, configurable: true });
|
|
160
|
-
const computeSubSteps = /* @__PURE__ */ __name$4((stops, steps) => {
|
|
161
|
-
const l = stops.length;
|
|
162
|
-
steps = Number.parseInt(steps.toString(), 10);
|
|
163
|
-
if (Number.isNaN(steps) || steps < 2) {
|
|
164
|
-
throw new Error("Invalid number of steps (< 2)");
|
|
165
|
-
}
|
|
166
|
-
if (steps < l) {
|
|
167
|
-
throw new Error("Number of steps cannot be inferior to number of stops");
|
|
168
|
-
}
|
|
169
|
-
const substeps = [];
|
|
170
|
-
for (let index = 1; index < l; index++) {
|
|
171
|
-
const step = (steps - 1) * (stops[index].position - stops[index - 1].position);
|
|
172
|
-
substeps.push(Math.max(1, Math.round(step)));
|
|
173
|
-
}
|
|
174
|
-
let totalSubsteps = 1;
|
|
175
|
-
for (let n = l - 1; n--; ) {
|
|
176
|
-
totalSubsteps += substeps[n];
|
|
177
|
-
}
|
|
178
|
-
while (totalSubsteps !== steps) {
|
|
179
|
-
if (totalSubsteps < steps) {
|
|
180
|
-
const min = Math.min(...substeps);
|
|
181
|
-
substeps[substeps.indexOf(min)]++;
|
|
182
|
-
totalSubsteps++;
|
|
183
|
-
} else {
|
|
184
|
-
const max = Math.max(...substeps);
|
|
185
|
-
substeps[substeps.indexOf(max)]--;
|
|
186
|
-
totalSubsteps--;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return substeps;
|
|
190
|
-
}, "computeSubSteps");
|
|
191
|
-
|
|
192
|
-
var __defProp$3 = Object.defineProperty;
|
|
193
|
-
var __name$3 = (target, value) => __defProp$3(target, "name", { value, configurable: true });
|
|
194
|
-
const hsvToRgb = /* @__PURE__ */ __name$3((h, s, v) => {
|
|
195
|
-
let r = 0;
|
|
196
|
-
let g = 0;
|
|
197
|
-
let b = 0;
|
|
198
|
-
const index = Math.floor(h / 60);
|
|
199
|
-
const f = h / 60 - index;
|
|
200
|
-
const p = v * (1 - s);
|
|
201
|
-
const q = v * (1 - f * s);
|
|
202
|
-
const t = v * (1 - (1 - f) * s);
|
|
203
|
-
if (index % 6 === 0) {
|
|
204
|
-
r = v;
|
|
205
|
-
g = t;
|
|
206
|
-
b = p;
|
|
207
|
-
} else if (index % 6 === 1) {
|
|
208
|
-
r = q;
|
|
209
|
-
g = v;
|
|
210
|
-
b = p;
|
|
211
|
-
} else if (index % 6 === 2) {
|
|
212
|
-
r = p;
|
|
213
|
-
g = v;
|
|
214
|
-
b = t;
|
|
215
|
-
} else if (index % 6 === 3) {
|
|
216
|
-
r = p;
|
|
217
|
-
g = q;
|
|
218
|
-
b = v;
|
|
219
|
-
} else if (index % 6 === 4) {
|
|
220
|
-
r = t;
|
|
221
|
-
g = p;
|
|
222
|
-
b = v;
|
|
223
|
-
} else if (index % 6 === 5) {
|
|
224
|
-
r = v;
|
|
225
|
-
g = p;
|
|
226
|
-
b = q;
|
|
227
|
-
}
|
|
228
|
-
return { b: Math.round(b * 255), g: Math.round(g * 255), r: Math.round(r * 255) };
|
|
229
|
-
}, "hsvToRgb");
|
|
230
|
-
|
|
231
|
-
var __defProp$2 = Object.defineProperty;
|
|
232
|
-
var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
|
|
233
|
-
const rgbToHsv = /* @__PURE__ */ __name$2(({ b, g, r }) => {
|
|
234
|
-
let rdif;
|
|
235
|
-
let gdif;
|
|
236
|
-
let bdif;
|
|
237
|
-
let h = 0;
|
|
238
|
-
let s = 0;
|
|
239
|
-
r /= 255;
|
|
240
|
-
g /= 255;
|
|
241
|
-
b /= 255;
|
|
242
|
-
const v = Math.max(r, g, b);
|
|
243
|
-
const diff = v - Math.min(r, g, b);
|
|
244
|
-
const diffc = /* @__PURE__ */ __name$2((c) => (v - c) / 6 / diff + 1 / 2, "diffc");
|
|
245
|
-
if (diff !== 0) {
|
|
246
|
-
s = diff / v;
|
|
247
|
-
rdif = diffc(r);
|
|
248
|
-
gdif = diffc(g);
|
|
249
|
-
bdif = diffc(b);
|
|
250
|
-
if (v === r) {
|
|
251
|
-
h = bdif - gdif;
|
|
252
|
-
} else if (v === g) {
|
|
253
|
-
h = 1 / 3 + rdif - bdif;
|
|
254
|
-
} else if (v === b) {
|
|
255
|
-
h = 2 / 3 + gdif - rdif;
|
|
256
|
-
}
|
|
257
|
-
if (h < 0) {
|
|
258
|
-
h += 1;
|
|
259
|
-
} else if (h > 1) {
|
|
260
|
-
h -= 1;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return {
|
|
264
|
-
h: h * 360,
|
|
265
|
-
s,
|
|
266
|
-
v
|
|
267
|
-
};
|
|
268
|
-
}, "rgbToHsv");
|
|
269
|
-
|
|
270
|
-
var __defProp$1 = Object.defineProperty;
|
|
271
|
-
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
272
|
-
const RGBA_MAX = { b: 256, g: 256, r: 256 };
|
|
273
|
-
const HSV_MAX = { h: 360, s: 1, v: 1 };
|
|
274
|
-
const calculateStepSize = /* @__PURE__ */ __name$1((start, end, steps) => {
|
|
275
|
-
const step = {};
|
|
276
|
-
for (const k in start) {
|
|
277
|
-
if (Object.prototype.hasOwnProperty.call(start, k)) {
|
|
278
|
-
step[k] = steps === 0 ? 0 : (end[k] - start[k]) / steps;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
return step;
|
|
282
|
-
}, "calculateStepSize");
|
|
283
|
-
const interpolate = /* @__PURE__ */ __name$1((step, start, index, max) => {
|
|
284
|
-
const color = {};
|
|
285
|
-
for (const k in start) {
|
|
286
|
-
if (Object.prototype.hasOwnProperty.call(start, k)) {
|
|
287
|
-
color[k] = step[k] * index + start[k];
|
|
288
|
-
color[k] = // eslint-disable-next-line security/detect-object-injection
|
|
289
|
-
color[k] < 0 ? (
|
|
290
|
-
// eslint-disable-next-line security/detect-object-injection
|
|
291
|
-
color[k] + max[k]
|
|
292
|
-
) : (
|
|
293
|
-
// eslint-disable-next-line security/detect-object-injection
|
|
294
|
-
max[k] === 1 ? (
|
|
295
|
-
// eslint-disable-next-line security/detect-object-injection
|
|
296
|
-
color[k]
|
|
297
|
-
) : (
|
|
298
|
-
// eslint-disable-next-line security/detect-object-injection
|
|
299
|
-
color[k] % max[k]
|
|
300
|
-
)
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
return color;
|
|
305
|
-
}, "interpolate");
|
|
306
|
-
const interpolateRgb = /* @__PURE__ */ __name$1((stop1, stop2, steps) => {
|
|
307
|
-
const start = { b: stop1.color[2], g: stop1.color[1], r: stop1.color[0] };
|
|
308
|
-
const end = { b: stop2.color[2], g: stop2.color[1], r: stop2.color[0] };
|
|
309
|
-
const step = calculateStepSize(start, end, steps);
|
|
310
|
-
const gradient = [{ ...start }];
|
|
311
|
-
for (let index = 1; index < steps; index++) {
|
|
312
|
-
const color = interpolate(step, start, index, RGBA_MAX);
|
|
313
|
-
gradient.push({
|
|
314
|
-
b: Math.floor(color.b),
|
|
315
|
-
g: Math.floor(color.g),
|
|
316
|
-
r: Math.floor(color.r)
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
return gradient;
|
|
320
|
-
}, "interpolateRgb");
|
|
321
|
-
const interpolateHsv = /* @__PURE__ */ __name$1((stop1, stop2, steps, mode) => {
|
|
322
|
-
const start = rgbToHsv({ b: stop1.color[2], g: stop1.color[1], r: stop1.color[0] });
|
|
323
|
-
const end = rgbToHsv({ b: stop2.color[2], g: stop2.color[1], r: stop2.color[0] });
|
|
324
|
-
if (start.s === 0 || end.s === 0) {
|
|
325
|
-
return interpolateRgb(stop1, stop2, steps);
|
|
326
|
-
}
|
|
327
|
-
let trigonometric;
|
|
328
|
-
if (typeof mode === "boolean") {
|
|
329
|
-
trigonometric = mode;
|
|
330
|
-
} else {
|
|
331
|
-
const trigShortest = start.h < end.h && end.h - start.h < 180 || start.h > end.h && start.h - end.h > 180;
|
|
332
|
-
trigonometric = mode === "long" && trigShortest || mode === "short" && !trigShortest;
|
|
333
|
-
}
|
|
334
|
-
const step = calculateStepSize(start, end, steps);
|
|
335
|
-
const gradient = [
|
|
336
|
-
{
|
|
337
|
-
b: stop1.color[2],
|
|
338
|
-
g: stop1.color[1],
|
|
339
|
-
r: stop1.color[0]
|
|
340
|
-
}
|
|
341
|
-
];
|
|
342
|
-
let diff;
|
|
343
|
-
if (start.h <= end.h && !trigonometric || start.h >= end.h && trigonometric) {
|
|
344
|
-
diff = end.h - start.h;
|
|
345
|
-
} else if (trigonometric) {
|
|
346
|
-
diff = 360 - end.h + start.h;
|
|
347
|
-
} else {
|
|
348
|
-
diff = 360 - start.h + end.h;
|
|
349
|
-
}
|
|
350
|
-
step.h = (-1) ** (trigonometric ? 1 : 0) * Math.abs(diff) / steps;
|
|
351
|
-
for (let index = 1; index < steps; index++) {
|
|
352
|
-
const color = interpolate(step, start, index, HSV_MAX);
|
|
353
|
-
gradient.push(hsvToRgb(color.h, color.s, color.v));
|
|
354
|
-
}
|
|
355
|
-
return gradient;
|
|
356
|
-
}, "interpolateHsv");
|
|
357
|
-
|
|
358
|
-
var __defProp = Object.defineProperty;
|
|
359
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
360
|
-
class GradientBuilder {
|
|
361
|
-
static {
|
|
362
|
-
__name(this, "GradientBuilder");
|
|
363
|
-
}
|
|
364
|
-
#colorize;
|
|
365
|
-
stops;
|
|
366
|
-
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
367
|
-
constructor(colorize, stops) {
|
|
368
|
-
this.#colorize = colorize;
|
|
369
|
-
this.stops = [];
|
|
370
|
-
if (stops.length < 2) {
|
|
371
|
-
throw new Error("Invalid number of stops (< 2)");
|
|
372
|
-
}
|
|
373
|
-
const havingPositions = stops[0].position !== void 0;
|
|
374
|
-
let l = stops.length;
|
|
375
|
-
let p = -1;
|
|
376
|
-
let lastColorLess = false;
|
|
377
|
-
for (const [index, stop_] of stops.entries()) {
|
|
378
|
-
let stop = {};
|
|
379
|
-
const hasPosition = stop_.position !== void 0;
|
|
380
|
-
if (havingPositions !== hasPosition) {
|
|
381
|
-
throw new Error("Cannot mix positioned and non-positioned color stops");
|
|
382
|
-
}
|
|
383
|
-
if (hasPosition) {
|
|
384
|
-
const stopInput = stop_;
|
|
385
|
-
const hasColor = stopInput.color !== void 0;
|
|
386
|
-
if (!hasColor && (lastColorLess || index === 0 || index === l - 1)) {
|
|
387
|
-
throw new Error("Cannot define two consecutive position-only stops");
|
|
388
|
-
}
|
|
389
|
-
lastColorLess = !hasColor;
|
|
390
|
-
let color;
|
|
391
|
-
if (hasColor) {
|
|
392
|
-
if (Array.isArray(stopInput.color)) {
|
|
393
|
-
color = stopInput.color;
|
|
394
|
-
} else if (typeof stopInput.color === "string") {
|
|
395
|
-
color = stopInput.color.includes("#") ? convertHexToRgb.convertHexToRgb(stopInput.color) : colorNames[stopInput.color];
|
|
396
|
-
} else if (stopInput.color.r !== void 0 && stopInput.color.g !== void 0 && stopInput.color.b) {
|
|
397
|
-
color = [stopInput.color.r, stopInput.color.g, stopInput.color.b];
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
stop = {
|
|
401
|
-
color,
|
|
402
|
-
colorLess: !hasColor,
|
|
403
|
-
position: stopInput.position
|
|
404
|
-
};
|
|
405
|
-
if (stop.position < 0 || stop.position > 1) {
|
|
406
|
-
throw new Error("Color stops positions must be between 0 and 1");
|
|
407
|
-
} else if (stop.position < p) {
|
|
408
|
-
throw new Error("Color stops positions are not ordered");
|
|
409
|
-
}
|
|
410
|
-
p = stop.position;
|
|
411
|
-
} else if (Array.isArray(stop_)) {
|
|
412
|
-
stop = {
|
|
413
|
-
color: stop_,
|
|
414
|
-
position: index / (l - 1)
|
|
415
|
-
};
|
|
416
|
-
} else if (typeof stop_ === "string") {
|
|
417
|
-
stop = {
|
|
418
|
-
color: stop_.includes("#") ? convertHexToRgb.convertHexToRgb(stop_) : colorNames[stop_],
|
|
419
|
-
position: index / (l - 1)
|
|
420
|
-
};
|
|
421
|
-
} else if (stop_.r !== void 0 && stop_.g !== void 0 && stop_.b !== void 0) {
|
|
422
|
-
stop = {
|
|
423
|
-
color: [stop_.r, stop_.g, stop_.b],
|
|
424
|
-
position: index / (l - 1)
|
|
425
|
-
};
|
|
426
|
-
} else {
|
|
427
|
-
throw new Error("Invalid color stop");
|
|
428
|
-
}
|
|
429
|
-
this.stops.push(stop);
|
|
430
|
-
}
|
|
431
|
-
if (this.stops[0].position !== 0) {
|
|
432
|
-
this.stops.unshift({
|
|
433
|
-
color: this.stops[0].color,
|
|
434
|
-
position: 0
|
|
435
|
-
});
|
|
436
|
-
l++;
|
|
437
|
-
}
|
|
438
|
-
if (this.stops[l - 1].position !== 1) {
|
|
439
|
-
this.stops.push({
|
|
440
|
-
color: this.stops[l - 1].color,
|
|
441
|
-
position: 1
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
reverse() {
|
|
446
|
-
const stops = [];
|
|
447
|
-
for (const stop of this.stops) {
|
|
448
|
-
const stop_ = { ...stop };
|
|
449
|
-
stop_.position = 1 - stop.position;
|
|
450
|
-
stops.push(stop_);
|
|
451
|
-
}
|
|
452
|
-
return new GradientBuilder(this.#colorize, stops.reverse());
|
|
453
|
-
}
|
|
454
|
-
loop() {
|
|
455
|
-
const stops1 = [];
|
|
456
|
-
const stops2 = [];
|
|
457
|
-
for (const stop of this.stops) {
|
|
458
|
-
stops1.push({
|
|
459
|
-
color: stop.color,
|
|
460
|
-
position: (stop.position || 0) / 2
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
for (const stop of this.stops.slice(0, -1)) {
|
|
464
|
-
stops2.push({
|
|
465
|
-
color: stop.color,
|
|
466
|
-
position: 1 - (stop.position || 0) / 2
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
return new GradientBuilder(this.#colorize, [...stops1, ...stops2.reverse()]);
|
|
470
|
-
}
|
|
471
|
-
rgb(steps) {
|
|
472
|
-
const subSteps = computeSubSteps(this.stops, steps);
|
|
473
|
-
const gradient = [];
|
|
474
|
-
this.stops.forEach((stop, index) => {
|
|
475
|
-
if (stop.colorLess) {
|
|
476
|
-
const rgbs = interpolateRgb(this.stops[index - 1], this.stops[index + 1], 2);
|
|
477
|
-
stop.color = [rgbs[1].r, rgbs[1].g, rgbs[1].b];
|
|
478
|
-
}
|
|
479
|
-
});
|
|
480
|
-
for (let index = 0, l = this.stops.length; index < l - 1; index++) {
|
|
481
|
-
const rgbs = interpolateRgb(this.stops[index], this.stops[index + 1], subSteps[index]);
|
|
482
|
-
gradient.splice(gradient.length, 0, ...rgbs.map((rgb) => this.#colorize.rgb(rgb.r, rgb.g, rgb.b)));
|
|
483
|
-
}
|
|
484
|
-
gradient.push(this.#colorize.rgb(...this.stops.at(-1).color));
|
|
485
|
-
return gradient;
|
|
486
|
-
}
|
|
487
|
-
hsv(steps, mode = false) {
|
|
488
|
-
const subSteps = computeSubSteps(this.stops, steps);
|
|
489
|
-
const gradient = [];
|
|
490
|
-
this.stops.forEach((stop, index) => {
|
|
491
|
-
if (stop.colorLess) {
|
|
492
|
-
const rgbs = interpolateHsv(this.stops[index - 1], this.stops[index + 1], 2, mode);
|
|
493
|
-
stop.color = [rgbs[1].r, rgbs[1].g, rgbs[1].b];
|
|
494
|
-
}
|
|
495
|
-
});
|
|
496
|
-
for (let index = 0, l = this.stops.length; index < l - 1; index++) {
|
|
497
|
-
const rgbs = interpolateHsv(this.stops[index], this.stops[index + 1], subSteps[index], mode);
|
|
498
|
-
gradient.splice(gradient.length, 0, ...rgbs.map((rgb) => this.#colorize.rgb(rgb.r, rgb.g, rgb.b)));
|
|
499
|
-
}
|
|
500
|
-
gradient.push(this.#colorize.rgb(...this.stops.at(-1).color));
|
|
501
|
-
return gradient;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
exports.GradientBuilder = GradientBuilder;
|