| 1 | import define, {extend} from "./define.js";
|
|---|
| 2 |
|
|---|
| 3 | export function Color() {}
|
|---|
| 4 |
|
|---|
| 5 | export var darker = 0.7;
|
|---|
| 6 | export var brighter = 1 / darker;
|
|---|
| 7 |
|
|---|
| 8 | var reI = "\\s*([+-]?\\d+)\\s*",
|
|---|
| 9 | reN = "\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",
|
|---|
| 10 | reP = "\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
|
|---|
| 11 | reHex = /^#([0-9a-f]{3,8})$/,
|
|---|
| 12 | reRgbInteger = new RegExp(`^rgb\\(${reI},${reI},${reI}\\)$`),
|
|---|
| 13 | reRgbPercent = new RegExp(`^rgb\\(${reP},${reP},${reP}\\)$`),
|
|---|
| 14 | reRgbaInteger = new RegExp(`^rgba\\(${reI},${reI},${reI},${reN}\\)$`),
|
|---|
| 15 | reRgbaPercent = new RegExp(`^rgba\\(${reP},${reP},${reP},${reN}\\)$`),
|
|---|
| 16 | reHslPercent = new RegExp(`^hsl\\(${reN},${reP},${reP}\\)$`),
|
|---|
| 17 | reHslaPercent = new RegExp(`^hsla\\(${reN},${reP},${reP},${reN}\\)$`);
|
|---|
| 18 |
|
|---|
| 19 | var named = {
|
|---|
| 20 | aliceblue: 0xf0f8ff,
|
|---|
| 21 | antiquewhite: 0xfaebd7,
|
|---|
| 22 | aqua: 0x00ffff,
|
|---|
| 23 | aquamarine: 0x7fffd4,
|
|---|
| 24 | azure: 0xf0ffff,
|
|---|
| 25 | beige: 0xf5f5dc,
|
|---|
| 26 | bisque: 0xffe4c4,
|
|---|
| 27 | black: 0x000000,
|
|---|
| 28 | blanchedalmond: 0xffebcd,
|
|---|
| 29 | blue: 0x0000ff,
|
|---|
| 30 | blueviolet: 0x8a2be2,
|
|---|
| 31 | brown: 0xa52a2a,
|
|---|
| 32 | burlywood: 0xdeb887,
|
|---|
| 33 | cadetblue: 0x5f9ea0,
|
|---|
| 34 | chartreuse: 0x7fff00,
|
|---|
| 35 | chocolate: 0xd2691e,
|
|---|
| 36 | coral: 0xff7f50,
|
|---|
| 37 | cornflowerblue: 0x6495ed,
|
|---|
| 38 | cornsilk: 0xfff8dc,
|
|---|
| 39 | crimson: 0xdc143c,
|
|---|
| 40 | cyan: 0x00ffff,
|
|---|
| 41 | darkblue: 0x00008b,
|
|---|
| 42 | darkcyan: 0x008b8b,
|
|---|
| 43 | darkgoldenrod: 0xb8860b,
|
|---|
| 44 | darkgray: 0xa9a9a9,
|
|---|
| 45 | darkgreen: 0x006400,
|
|---|
| 46 | darkgrey: 0xa9a9a9,
|
|---|
| 47 | darkkhaki: 0xbdb76b,
|
|---|
| 48 | darkmagenta: 0x8b008b,
|
|---|
| 49 | darkolivegreen: 0x556b2f,
|
|---|
| 50 | darkorange: 0xff8c00,
|
|---|
| 51 | darkorchid: 0x9932cc,
|
|---|
| 52 | darkred: 0x8b0000,
|
|---|
| 53 | darksalmon: 0xe9967a,
|
|---|
| 54 | darkseagreen: 0x8fbc8f,
|
|---|
| 55 | darkslateblue: 0x483d8b,
|
|---|
| 56 | darkslategray: 0x2f4f4f,
|
|---|
| 57 | darkslategrey: 0x2f4f4f,
|
|---|
| 58 | darkturquoise: 0x00ced1,
|
|---|
| 59 | darkviolet: 0x9400d3,
|
|---|
| 60 | deeppink: 0xff1493,
|
|---|
| 61 | deepskyblue: 0x00bfff,
|
|---|
| 62 | dimgray: 0x696969,
|
|---|
| 63 | dimgrey: 0x696969,
|
|---|
| 64 | dodgerblue: 0x1e90ff,
|
|---|
| 65 | firebrick: 0xb22222,
|
|---|
| 66 | floralwhite: 0xfffaf0,
|
|---|
| 67 | forestgreen: 0x228b22,
|
|---|
| 68 | fuchsia: 0xff00ff,
|
|---|
| 69 | gainsboro: 0xdcdcdc,
|
|---|
| 70 | ghostwhite: 0xf8f8ff,
|
|---|
| 71 | gold: 0xffd700,
|
|---|
| 72 | goldenrod: 0xdaa520,
|
|---|
| 73 | gray: 0x808080,
|
|---|
| 74 | green: 0x008000,
|
|---|
| 75 | greenyellow: 0xadff2f,
|
|---|
| 76 | grey: 0x808080,
|
|---|
| 77 | honeydew: 0xf0fff0,
|
|---|
| 78 | hotpink: 0xff69b4,
|
|---|
| 79 | indianred: 0xcd5c5c,
|
|---|
| 80 | indigo: 0x4b0082,
|
|---|
| 81 | ivory: 0xfffff0,
|
|---|
| 82 | khaki: 0xf0e68c,
|
|---|
| 83 | lavender: 0xe6e6fa,
|
|---|
| 84 | lavenderblush: 0xfff0f5,
|
|---|
| 85 | lawngreen: 0x7cfc00,
|
|---|
| 86 | lemonchiffon: 0xfffacd,
|
|---|
| 87 | lightblue: 0xadd8e6,
|
|---|
| 88 | lightcoral: 0xf08080,
|
|---|
| 89 | lightcyan: 0xe0ffff,
|
|---|
| 90 | lightgoldenrodyellow: 0xfafad2,
|
|---|
| 91 | lightgray: 0xd3d3d3,
|
|---|
| 92 | lightgreen: 0x90ee90,
|
|---|
| 93 | lightgrey: 0xd3d3d3,
|
|---|
| 94 | lightpink: 0xffb6c1,
|
|---|
| 95 | lightsalmon: 0xffa07a,
|
|---|
| 96 | lightseagreen: 0x20b2aa,
|
|---|
| 97 | lightskyblue: 0x87cefa,
|
|---|
| 98 | lightslategray: 0x778899,
|
|---|
| 99 | lightslategrey: 0x778899,
|
|---|
| 100 | lightsteelblue: 0xb0c4de,
|
|---|
| 101 | lightyellow: 0xffffe0,
|
|---|
| 102 | lime: 0x00ff00,
|
|---|
| 103 | limegreen: 0x32cd32,
|
|---|
| 104 | linen: 0xfaf0e6,
|
|---|
| 105 | magenta: 0xff00ff,
|
|---|
| 106 | maroon: 0x800000,
|
|---|
| 107 | mediumaquamarine: 0x66cdaa,
|
|---|
| 108 | mediumblue: 0x0000cd,
|
|---|
| 109 | mediumorchid: 0xba55d3,
|
|---|
| 110 | mediumpurple: 0x9370db,
|
|---|
| 111 | mediumseagreen: 0x3cb371,
|
|---|
| 112 | mediumslateblue: 0x7b68ee,
|
|---|
| 113 | mediumspringgreen: 0x00fa9a,
|
|---|
| 114 | mediumturquoise: 0x48d1cc,
|
|---|
| 115 | mediumvioletred: 0xc71585,
|
|---|
| 116 | midnightblue: 0x191970,
|
|---|
| 117 | mintcream: 0xf5fffa,
|
|---|
| 118 | mistyrose: 0xffe4e1,
|
|---|
| 119 | moccasin: 0xffe4b5,
|
|---|
| 120 | navajowhite: 0xffdead,
|
|---|
| 121 | navy: 0x000080,
|
|---|
| 122 | oldlace: 0xfdf5e6,
|
|---|
| 123 | olive: 0x808000,
|
|---|
| 124 | olivedrab: 0x6b8e23,
|
|---|
| 125 | orange: 0xffa500,
|
|---|
| 126 | orangered: 0xff4500,
|
|---|
| 127 | orchid: 0xda70d6,
|
|---|
| 128 | palegoldenrod: 0xeee8aa,
|
|---|
| 129 | palegreen: 0x98fb98,
|
|---|
| 130 | paleturquoise: 0xafeeee,
|
|---|
| 131 | palevioletred: 0xdb7093,
|
|---|
| 132 | papayawhip: 0xffefd5,
|
|---|
| 133 | peachpuff: 0xffdab9,
|
|---|
| 134 | peru: 0xcd853f,
|
|---|
| 135 | pink: 0xffc0cb,
|
|---|
| 136 | plum: 0xdda0dd,
|
|---|
| 137 | powderblue: 0xb0e0e6,
|
|---|
| 138 | purple: 0x800080,
|
|---|
| 139 | rebeccapurple: 0x663399,
|
|---|
| 140 | red: 0xff0000,
|
|---|
| 141 | rosybrown: 0xbc8f8f,
|
|---|
| 142 | royalblue: 0x4169e1,
|
|---|
| 143 | saddlebrown: 0x8b4513,
|
|---|
| 144 | salmon: 0xfa8072,
|
|---|
| 145 | sandybrown: 0xf4a460,
|
|---|
| 146 | seagreen: 0x2e8b57,
|
|---|
| 147 | seashell: 0xfff5ee,
|
|---|
| 148 | sienna: 0xa0522d,
|
|---|
| 149 | silver: 0xc0c0c0,
|
|---|
| 150 | skyblue: 0x87ceeb,
|
|---|
| 151 | slateblue: 0x6a5acd,
|
|---|
| 152 | slategray: 0x708090,
|
|---|
| 153 | slategrey: 0x708090,
|
|---|
| 154 | snow: 0xfffafa,
|
|---|
| 155 | springgreen: 0x00ff7f,
|
|---|
| 156 | steelblue: 0x4682b4,
|
|---|
| 157 | tan: 0xd2b48c,
|
|---|
| 158 | teal: 0x008080,
|
|---|
| 159 | thistle: 0xd8bfd8,
|
|---|
| 160 | tomato: 0xff6347,
|
|---|
| 161 | turquoise: 0x40e0d0,
|
|---|
| 162 | violet: 0xee82ee,
|
|---|
| 163 | wheat: 0xf5deb3,
|
|---|
| 164 | white: 0xffffff,
|
|---|
| 165 | whitesmoke: 0xf5f5f5,
|
|---|
| 166 | yellow: 0xffff00,
|
|---|
| 167 | yellowgreen: 0x9acd32
|
|---|
| 168 | };
|
|---|
| 169 |
|
|---|
| 170 | define(Color, color, {
|
|---|
| 171 | copy(channels) {
|
|---|
| 172 | return Object.assign(new this.constructor, this, channels);
|
|---|
| 173 | },
|
|---|
| 174 | displayable() {
|
|---|
| 175 | return this.rgb().displayable();
|
|---|
| 176 | },
|
|---|
| 177 | hex: color_formatHex, // Deprecated! Use color.formatHex.
|
|---|
| 178 | formatHex: color_formatHex,
|
|---|
| 179 | formatHex8: color_formatHex8,
|
|---|
| 180 | formatHsl: color_formatHsl,
|
|---|
| 181 | formatRgb: color_formatRgb,
|
|---|
| 182 | toString: color_formatRgb
|
|---|
| 183 | });
|
|---|
| 184 |
|
|---|
| 185 | function color_formatHex() {
|
|---|
| 186 | return this.rgb().formatHex();
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | function color_formatHex8() {
|
|---|
| 190 | return this.rgb().formatHex8();
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | function color_formatHsl() {
|
|---|
| 194 | return hslConvert(this).formatHsl();
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | function color_formatRgb() {
|
|---|
| 198 | return this.rgb().formatRgb();
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | export default function color(format) {
|
|---|
| 202 | var m, l;
|
|---|
| 203 | format = (format + "").trim().toLowerCase();
|
|---|
| 204 | return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m) // #ff0000
|
|---|
| 205 | : l === 3 ? new Rgb((m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1) // #f00
|
|---|
| 206 | : l === 8 ? rgba(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff) // #ff000000
|
|---|
| 207 | : l === 4 ? rgba((m >> 12 & 0xf) | (m >> 8 & 0xf0), (m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), (((m & 0xf) << 4) | (m & 0xf)) / 0xff) // #f000
|
|---|
| 208 | : null) // invalid hex
|
|---|
| 209 | : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
|
|---|
| 210 | : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
|
|---|
| 211 | : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
|
|---|
| 212 | : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
|
|---|
| 213 | : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
|
|---|
| 214 | : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
|
|---|
| 215 | : named.hasOwnProperty(format) ? rgbn(named[format]) // eslint-disable-line no-prototype-builtins
|
|---|
| 216 | : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
|
|---|
| 217 | : null;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | function rgbn(n) {
|
|---|
| 221 | return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | function rgba(r, g, b, a) {
|
|---|
| 225 | if (a <= 0) r = g = b = NaN;
|
|---|
| 226 | return new Rgb(r, g, b, a);
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | export function rgbConvert(o) {
|
|---|
| 230 | if (!(o instanceof Color)) o = color(o);
|
|---|
| 231 | if (!o) return new Rgb;
|
|---|
| 232 | o = o.rgb();
|
|---|
| 233 | return new Rgb(o.r, o.g, o.b, o.opacity);
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | export function rgb(r, g, b, opacity) {
|
|---|
| 237 | return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | export function Rgb(r, g, b, opacity) {
|
|---|
| 241 | this.r = +r;
|
|---|
| 242 | this.g = +g;
|
|---|
| 243 | this.b = +b;
|
|---|
| 244 | this.opacity = +opacity;
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | define(Rgb, rgb, extend(Color, {
|
|---|
| 248 | brighter(k) {
|
|---|
| 249 | k = k == null ? brighter : Math.pow(brighter, k);
|
|---|
| 250 | return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
|
|---|
| 251 | },
|
|---|
| 252 | darker(k) {
|
|---|
| 253 | k = k == null ? darker : Math.pow(darker, k);
|
|---|
| 254 | return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
|
|---|
| 255 | },
|
|---|
| 256 | rgb() {
|
|---|
| 257 | return this;
|
|---|
| 258 | },
|
|---|
| 259 | clamp() {
|
|---|
| 260 | return new Rgb(clampi(this.r), clampi(this.g), clampi(this.b), clampa(this.opacity));
|
|---|
| 261 | },
|
|---|
| 262 | displayable() {
|
|---|
| 263 | return (-0.5 <= this.r && this.r < 255.5)
|
|---|
| 264 | && (-0.5 <= this.g && this.g < 255.5)
|
|---|
| 265 | && (-0.5 <= this.b && this.b < 255.5)
|
|---|
| 266 | && (0 <= this.opacity && this.opacity <= 1);
|
|---|
| 267 | },
|
|---|
| 268 | hex: rgb_formatHex, // Deprecated! Use color.formatHex.
|
|---|
| 269 | formatHex: rgb_formatHex,
|
|---|
| 270 | formatHex8: rgb_formatHex8,
|
|---|
| 271 | formatRgb: rgb_formatRgb,
|
|---|
| 272 | toString: rgb_formatRgb
|
|---|
| 273 | }));
|
|---|
| 274 |
|
|---|
| 275 | function rgb_formatHex() {
|
|---|
| 276 | return `#${hex(this.r)}${hex(this.g)}${hex(this.b)}`;
|
|---|
| 277 | }
|
|---|
| 278 |
|
|---|
| 279 | function rgb_formatHex8() {
|
|---|
| 280 | return `#${hex(this.r)}${hex(this.g)}${hex(this.b)}${hex((isNaN(this.opacity) ? 1 : this.opacity) * 255)}`;
|
|---|
| 281 | }
|
|---|
| 282 |
|
|---|
| 283 | function rgb_formatRgb() {
|
|---|
| 284 | const a = clampa(this.opacity);
|
|---|
| 285 | return `${a === 1 ? "rgb(" : "rgba("}${clampi(this.r)}, ${clampi(this.g)}, ${clampi(this.b)}${a === 1 ? ")" : `, ${a})`}`;
|
|---|
| 286 | }
|
|---|
| 287 |
|
|---|
| 288 | function clampa(opacity) {
|
|---|
| 289 | return isNaN(opacity) ? 1 : Math.max(0, Math.min(1, opacity));
|
|---|
| 290 | }
|
|---|
| 291 |
|
|---|
| 292 | function clampi(value) {
|
|---|
| 293 | return Math.max(0, Math.min(255, Math.round(value) || 0));
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | function hex(value) {
|
|---|
| 297 | value = clampi(value);
|
|---|
| 298 | return (value < 16 ? "0" : "") + value.toString(16);
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|
| 301 | function hsla(h, s, l, a) {
|
|---|
| 302 | if (a <= 0) h = s = l = NaN;
|
|---|
| 303 | else if (l <= 0 || l >= 1) h = s = NaN;
|
|---|
| 304 | else if (s <= 0) h = NaN;
|
|---|
| 305 | return new Hsl(h, s, l, a);
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | export function hslConvert(o) {
|
|---|
| 309 | if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
|
|---|
| 310 | if (!(o instanceof Color)) o = color(o);
|
|---|
| 311 | if (!o) return new Hsl;
|
|---|
| 312 | if (o instanceof Hsl) return o;
|
|---|
| 313 | o = o.rgb();
|
|---|
| 314 | var r = o.r / 255,
|
|---|
| 315 | g = o.g / 255,
|
|---|
| 316 | b = o.b / 255,
|
|---|
| 317 | min = Math.min(r, g, b),
|
|---|
| 318 | max = Math.max(r, g, b),
|
|---|
| 319 | h = NaN,
|
|---|
| 320 | s = max - min,
|
|---|
| 321 | l = (max + min) / 2;
|
|---|
| 322 | if (s) {
|
|---|
| 323 | if (r === max) h = (g - b) / s + (g < b) * 6;
|
|---|
| 324 | else if (g === max) h = (b - r) / s + 2;
|
|---|
| 325 | else h = (r - g) / s + 4;
|
|---|
| 326 | s /= l < 0.5 ? max + min : 2 - max - min;
|
|---|
| 327 | h *= 60;
|
|---|
| 328 | } else {
|
|---|
| 329 | s = l > 0 && l < 1 ? 0 : h;
|
|---|
| 330 | }
|
|---|
| 331 | return new Hsl(h, s, l, o.opacity);
|
|---|
| 332 | }
|
|---|
| 333 |
|
|---|
| 334 | export function hsl(h, s, l, opacity) {
|
|---|
| 335 | return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
|
|---|
| 336 | }
|
|---|
| 337 |
|
|---|
| 338 | function Hsl(h, s, l, opacity) {
|
|---|
| 339 | this.h = +h;
|
|---|
| 340 | this.s = +s;
|
|---|
| 341 | this.l = +l;
|
|---|
| 342 | this.opacity = +opacity;
|
|---|
| 343 | }
|
|---|
| 344 |
|
|---|
| 345 | define(Hsl, hsl, extend(Color, {
|
|---|
| 346 | brighter(k) {
|
|---|
| 347 | k = k == null ? brighter : Math.pow(brighter, k);
|
|---|
| 348 | return new Hsl(this.h, this.s, this.l * k, this.opacity);
|
|---|
| 349 | },
|
|---|
| 350 | darker(k) {
|
|---|
| 351 | k = k == null ? darker : Math.pow(darker, k);
|
|---|
| 352 | return new Hsl(this.h, this.s, this.l * k, this.opacity);
|
|---|
| 353 | },
|
|---|
| 354 | rgb() {
|
|---|
| 355 | var h = this.h % 360 + (this.h < 0) * 360,
|
|---|
| 356 | s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
|
|---|
| 357 | l = this.l,
|
|---|
| 358 | m2 = l + (l < 0.5 ? l : 1 - l) * s,
|
|---|
| 359 | m1 = 2 * l - m2;
|
|---|
| 360 | return new Rgb(
|
|---|
| 361 | hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
|
|---|
| 362 | hsl2rgb(h, m1, m2),
|
|---|
| 363 | hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
|
|---|
| 364 | this.opacity
|
|---|
| 365 | );
|
|---|
| 366 | },
|
|---|
| 367 | clamp() {
|
|---|
| 368 | return new Hsl(clamph(this.h), clampt(this.s), clampt(this.l), clampa(this.opacity));
|
|---|
| 369 | },
|
|---|
| 370 | displayable() {
|
|---|
| 371 | return (0 <= this.s && this.s <= 1 || isNaN(this.s))
|
|---|
| 372 | && (0 <= this.l && this.l <= 1)
|
|---|
| 373 | && (0 <= this.opacity && this.opacity <= 1);
|
|---|
| 374 | },
|
|---|
| 375 | formatHsl() {
|
|---|
| 376 | const a = clampa(this.opacity);
|
|---|
| 377 | return `${a === 1 ? "hsl(" : "hsla("}${clamph(this.h)}, ${clampt(this.s) * 100}%, ${clampt(this.l) * 100}%${a === 1 ? ")" : `, ${a})`}`;
|
|---|
| 378 | }
|
|---|
| 379 | }));
|
|---|
| 380 |
|
|---|
| 381 | function clamph(value) {
|
|---|
| 382 | value = (value || 0) % 360;
|
|---|
| 383 | return value < 0 ? value + 360 : value;
|
|---|
| 384 | }
|
|---|
| 385 |
|
|---|
| 386 | function clampt(value) {
|
|---|
| 387 | return Math.max(0, Math.min(1, value || 0));
|
|---|
| 388 | }
|
|---|
| 389 |
|
|---|
| 390 | /* From FvD 13.37, CSS Color Module Level 3 */
|
|---|
| 391 | function hsl2rgb(h, m1, m2) {
|
|---|
| 392 | return (h < 60 ? m1 + (m2 - m1) * h / 60
|
|---|
| 393 | : h < 180 ? m2
|
|---|
| 394 | : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
|
|---|
| 395 | : m1) * 255;
|
|---|
| 396 | }
|
|---|