Changeset 0c6b92a for imaps-frontend/node_modules/color-convert
- Timestamp:
- 12/12/24 17:06:06 (5 weeks ago)
- Branches:
- main
- Parents:
- d565449
- Location:
- imaps-frontend/node_modules/color-convert
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/color-convert/conversions.js
rd565449 r0c6b92a 1 1 /* MIT license */ 2 var cssKeywords = require('color-name'); 2 /* eslint-disable no-mixed-operators */ 3 const cssKeywords = require('color-name'); 3 4 4 5 // NOTE: conversions should only return primitive values (i.e. arrays, or … … 6 7 // do not use box values types (i.e. Number(), String(), etc.) 7 8 8 var reverseKeywords = {}; 9 for (var key in cssKeywords) { 10 if (cssKeywords.hasOwnProperty(key)) { 11 reverseKeywords[cssKeywords[key]] = key; 12 } 9 const reverseKeywords = {}; 10 for (const key of Object.keys(cssKeywords)) { 11 reverseKeywords[cssKeywords[key]] = key; 13 12 } 14 13 15 var convert = module.exports= {14 const convert = { 16 15 rgb: {channels: 3, labels: 'rgb'}, 17 16 hsl: {channels: 3, labels: 'hsl'}, … … 31 30 }; 32 31 33 // hide .channels and .labels properties 34 for (var model in convert) { 35 if (convert.hasOwnProperty(model)) { 36 if (!('channels' in convert[model])) { 37 throw new Error('missing channels property: ' + model); 38 } 39 40 if (!('labels' in convert[model])) { 41 throw new Error('missing channel labels property: ' + model); 42 } 43 44 if (convert[model].labels.length !== convert[model].channels) { 45 throw new Error('channel and label counts mismatch: ' + model); 46 } 47 48 var channels = convert[model].channels; 49 var labels = convert[model].labels; 50 delete convert[model].channels; 51 delete convert[model].labels; 52 Object.defineProperty(convert[model], 'channels', {value: channels}); 53 Object.defineProperty(convert[model], 'labels', {value: labels}); 54 } 32 module.exports = convert; 33 34 // Hide .channels and .labels properties 35 for (const model of Object.keys(convert)) { 36 if (!('channels' in convert[model])) { 37 throw new Error('missing channels property: ' + model); 38 } 39 40 if (!('labels' in convert[model])) { 41 throw new Error('missing channel labels property: ' + model); 42 } 43 44 if (convert[model].labels.length !== convert[model].channels) { 45 throw new Error('channel and label counts mismatch: ' + model); 46 } 47 48 const {channels, labels} = convert[model]; 49 delete convert[model].channels; 50 delete convert[model].labels; 51 Object.defineProperty(convert[model], 'channels', {value: channels}); 52 Object.defineProperty(convert[model], 'labels', {value: labels}); 55 53 } 56 54 57 55 convert.rgb.hsl = function (rgb) { 58 var r = rgb[0] / 255; 59 var g = rgb[1] / 255; 60 var b = rgb[2] / 255; 61 var min = Math.min(r, g, b); 62 var max = Math.max(r, g, b); 63 var delta = max - min; 64 var h; 65 var s; 66 var l; 56 const r = rgb[0] / 255; 57 const g = rgb[1] / 255; 58 const b = rgb[2] / 255; 59 const min = Math.min(r, g, b); 60 const max = Math.max(r, g, b); 61 const delta = max - min; 62 let h; 63 let s; 67 64 68 65 if (max === min) { … … 82 79 } 83 80 84 l = (min + max) / 2;81 const l = (min + max) / 2; 85 82 86 83 if (max === min) { … … 96 93 97 94 convert.rgb.hsv = function (rgb) { 98 varrdif;99 vargdif;100 varbdif;101 varh;102 vars;103 104 varr = rgb[0] / 255;105 varg = rgb[1] / 255;106 varb = rgb[2] / 255;107 varv = Math.max(r, g, b);108 vardiff = v - Math.min(r, g, b);109 vardiffc = function (c) {95 let rdif; 96 let gdif; 97 let bdif; 98 let h; 99 let s; 100 101 const r = rgb[0] / 255; 102 const g = rgb[1] / 255; 103 const b = rgb[2] / 255; 104 const v = Math.max(r, g, b); 105 const diff = v - Math.min(r, g, b); 106 const diffc = function (c) { 110 107 return (v - c) / 6 / diff + 1 / 2; 111 108 }; 112 109 113 110 if (diff === 0) { 114 h = s = 0; 111 h = 0; 112 s = 0; 115 113 } else { 116 114 s = diff / v; … … 126 124 h = (2 / 3) + gdif - rdif; 127 125 } 126 128 127 if (h < 0) { 129 128 h += 1; … … 141 140 142 141 convert.rgb.hwb = function (rgb) { 143 varr = rgb[0];144 varg = rgb[1];145 varb = rgb[2];146 varh = convert.rgb.hsl(rgb)[0];147 varw = 1 / 255 * Math.min(r, Math.min(g, b));142 const r = rgb[0]; 143 const g = rgb[1]; 144 let b = rgb[2]; 145 const h = convert.rgb.hsl(rgb)[0]; 146 const w = 1 / 255 * Math.min(r, Math.min(g, b)); 148 147 149 148 b = 1 - 1 / 255 * Math.max(r, Math.max(g, b)); … … 153 152 154 153 convert.rgb.cmyk = function (rgb) { 155 var r = rgb[0] / 255; 156 var g = rgb[1] / 255; 157 var b = rgb[2] / 255; 158 var c; 159 var m; 160 var y; 161 var k; 162 163 k = Math.min(1 - r, 1 - g, 1 - b); 164 c = (1 - r - k) / (1 - k) || 0; 165 m = (1 - g - k) / (1 - k) || 0; 166 y = (1 - b - k) / (1 - k) || 0; 154 const r = rgb[0] / 255; 155 const g = rgb[1] / 255; 156 const b = rgb[2] / 255; 157 158 const k = Math.min(1 - r, 1 - g, 1 - b); 159 const c = (1 - r - k) / (1 - k) || 0; 160 const m = (1 - g - k) / (1 - k) || 0; 161 const y = (1 - b - k) / (1 - k) || 0; 167 162 168 163 return [c * 100, m * 100, y * 100, k * 100]; 169 164 }; 170 165 171 /**172 * See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance173 * */174 166 function comparativeDistance(x, y) { 167 /* 168 See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance 169 */ 175 170 return ( 176 Math.pow(x[0] - y[0],2) +177 Math.pow(x[1] - y[1],2) +178 Math.pow(x[2] - y[2],2)171 ((x[0] - y[0]) ** 2) + 172 ((x[1] - y[1]) ** 2) + 173 ((x[2] - y[2]) ** 2) 179 174 ); 180 175 } 181 176 182 177 convert.rgb.keyword = function (rgb) { 183 varreversed = reverseKeywords[rgb];178 const reversed = reverseKeywords[rgb]; 184 179 if (reversed) { 185 180 return reversed; 186 181 } 187 182 188 var currentClosestDistance = Infinity; 189 var currentClosestKeyword; 190 191 for (var keyword in cssKeywords) { 192 if (cssKeywords.hasOwnProperty(keyword)) { 193 var value = cssKeywords[keyword]; 194 195 // Compute comparative distance 196 var distance = comparativeDistance(rgb, value); 197 198 // Check if its less, if so set as closest 199 if (distance < currentClosestDistance) { 200 currentClosestDistance = distance; 201 currentClosestKeyword = keyword; 202 } 183 let currentClosestDistance = Infinity; 184 let currentClosestKeyword; 185 186 for (const keyword of Object.keys(cssKeywords)) { 187 const value = cssKeywords[keyword]; 188 189 // Compute comparative distance 190 const distance = comparativeDistance(rgb, value); 191 192 // Check if its less, if so set as closest 193 if (distance < currentClosestDistance) { 194 currentClosestDistance = distance; 195 currentClosestKeyword = keyword; 203 196 } 204 197 } … … 212 205 213 206 convert.rgb.xyz = function (rgb) { 214 varr = rgb[0] / 255;215 varg = rgb[1] / 255;216 varb = rgb[2] / 255;217 218 // assume sRGB219 r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055),2.4) : (r / 12.92);220 g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055),2.4) : (g / 12.92);221 b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055),2.4) : (b / 12.92);222 223 varx = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);224 vary = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);225 varz = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);207 let r = rgb[0] / 255; 208 let g = rgb[1] / 255; 209 let b = rgb[2] / 255; 210 211 // Assume sRGB 212 r = r > 0.04045 ? (((r + 0.055) / 1.055) ** 2.4) : (r / 12.92); 213 g = g > 0.04045 ? (((g + 0.055) / 1.055) ** 2.4) : (g / 12.92); 214 b = b > 0.04045 ? (((b + 0.055) / 1.055) ** 2.4) : (b / 12.92); 215 216 const x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805); 217 const y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722); 218 const z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505); 226 219 227 220 return [x * 100, y * 100, z * 100]; … … 229 222 230 223 convert.rgb.lab = function (rgb) { 231 var xyz = convert.rgb.xyz(rgb); 232 var x = xyz[0]; 233 var y = xyz[1]; 234 var z = xyz[2]; 235 var l; 236 var a; 237 var b; 224 const xyz = convert.rgb.xyz(rgb); 225 let x = xyz[0]; 226 let y = xyz[1]; 227 let z = xyz[2]; 238 228 239 229 x /= 95.047; … … 241 231 z /= 108.883; 242 232 243 x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + (16 / 116);244 y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + (16 / 116);245 z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + (16 / 116);246 247 l = (116 * y) - 16;248 a = 500 * (x - y);249 b = 200 * (y - z);233 x = x > 0.008856 ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116); 234 y = y > 0.008856 ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116); 235 z = z > 0.008856 ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116); 236 237 const l = (116 * y) - 16; 238 const a = 500 * (x - y); 239 const b = 200 * (y - z); 250 240 251 241 return [l, a, b]; … … 253 243 254 244 convert.hsl.rgb = function (hsl) { 255 var h = hsl[0] / 360; 256 var s = hsl[1] / 100; 257 var l = hsl[2] / 100; 258 var t1; 259 var t2; 260 var t3; 261 var rgb; 262 var val; 245 const h = hsl[0] / 360; 246 const s = hsl[1] / 100; 247 const l = hsl[2] / 100; 248 let t2; 249 let t3; 250 let val; 263 251 264 252 if (s === 0) { … … 273 261 } 274 262 275 t1 = 2 * l - t2;276 277 rgb = [0, 0, 0];278 for ( vari = 0; i < 3; i++) {263 const t1 = 2 * l - t2; 264 265 const rgb = [0, 0, 0]; 266 for (let i = 0; i < 3; i++) { 279 267 t3 = h + 1 / 3 * -(i - 1); 280 268 if (t3 < 0) { 281 269 t3++; 282 270 } 271 283 272 if (t3 > 1) { 284 273 t3--; … … 302 291 303 292 convert.hsl.hsv = function (hsl) { 304 var h = hsl[0]; 305 var s = hsl[1] / 100; 306 var l = hsl[2] / 100; 307 var smin = s; 308 var lmin = Math.max(l, 0.01); 309 var sv; 310 var v; 293 const h = hsl[0]; 294 let s = hsl[1] / 100; 295 let l = hsl[2] / 100; 296 let smin = s; 297 const lmin = Math.max(l, 0.01); 311 298 312 299 l *= 2; 313 300 s *= (l <= 1) ? l : 2 - l; 314 301 smin *= lmin <= 1 ? lmin : 2 - lmin; 315 v = (l + s) / 2;316 sv = l === 0 ? (2 * smin) / (lmin + smin) : (2 * s) / (l + s);302 const v = (l + s) / 2; 303 const sv = l === 0 ? (2 * smin) / (lmin + smin) : (2 * s) / (l + s); 317 304 318 305 return [h, sv * 100, v * 100]; … … 320 307 321 308 convert.hsv.rgb = function (hsv) { 322 varh = hsv[0] / 60;323 vars = hsv[1] / 100;324 varv = hsv[2] / 100;325 varhi = Math.floor(h) % 6;326 327 varf = h - Math.floor(h);328 varp = 255 * v * (1 - s);329 varq = 255 * v * (1 - (s * f));330 vart = 255 * v * (1 - (s * (1 - f)));309 const h = hsv[0] / 60; 310 const s = hsv[1] / 100; 311 let v = hsv[2] / 100; 312 const hi = Math.floor(h) % 6; 313 314 const f = h - Math.floor(h); 315 const p = 255 * v * (1 - s); 316 const q = 255 * v * (1 - (s * f)); 317 const t = 255 * v * (1 - (s * (1 - f))); 331 318 v *= 255; 332 319 … … 348 335 349 336 convert.hsv.hsl = function (hsv) { 350 var h = hsv[0]; 351 var s = hsv[1] / 100; 352 var v = hsv[2] / 100; 353 var vmin = Math.max(v, 0.01); 354 var lmin; 355 var sl; 356 var l; 337 const h = hsv[0]; 338 const s = hsv[1] / 100; 339 const v = hsv[2] / 100; 340 const vmin = Math.max(v, 0.01); 341 let sl; 342 let l; 357 343 358 344 l = (2 - s) * v; 359 lmin = (2 - s) * vmin;345 const lmin = (2 - s) * vmin; 360 346 sl = s * vmin; 361 347 sl /= (lmin <= 1) ? lmin : 2 - lmin; … … 368 354 // http://dev.w3.org/csswg/css-color/#hwb-to-rgb 369 355 convert.hwb.rgb = function (hwb) { 370 var h = hwb[0] / 360; 371 var wh = hwb[1] / 100; 372 var bl = hwb[2] / 100; 373 var ratio = wh + bl; 374 var i; 375 var v; 376 var f; 377 var n; 378 379 // wh + bl cant be > 1 356 const h = hwb[0] / 360; 357 let wh = hwb[1] / 100; 358 let bl = hwb[2] / 100; 359 const ratio = wh + bl; 360 let f; 361 362 // Wh + bl cant be > 1 380 363 if (ratio > 1) { 381 364 wh /= ratio; … … 383 366 } 384 367 385 i = Math.floor(6 * h);386 v = 1 - bl;368 const i = Math.floor(6 * h); 369 const v = 1 - bl; 387 370 f = 6 * h - i; 388 371 … … 391 374 } 392 375 393 n = wh + f * (v - wh); // linear interpolation 394 395 var r; 396 var g; 397 var b; 376 const n = wh + f * (v - wh); // Linear interpolation 377 378 let r; 379 let g; 380 let b; 381 /* eslint-disable max-statements-per-line,no-multi-spaces */ 398 382 switch (i) { 399 383 default: 400 384 case 6: 401 case 0: r = v; g = n; b = wh; break; 402 case 1: r = n; g = v; b = wh; break; 403 case 2: r = wh; g = v; b = n; break; 404 case 3: r = wh; g = n; b = v; break; 405 case 4: r = n; g = wh; b = v; break; 406 case 5: r = v; g = wh; b = n; break; 407 } 385 case 0: r = v; g = n; b = wh; break; 386 case 1: r = n; g = v; b = wh; break; 387 case 2: r = wh; g = v; b = n; break; 388 case 3: r = wh; g = n; b = v; break; 389 case 4: r = n; g = wh; b = v; break; 390 case 5: r = v; g = wh; b = n; break; 391 } 392 /* eslint-enable max-statements-per-line,no-multi-spaces */ 408 393 409 394 return [r * 255, g * 255, b * 255]; … … 411 396 412 397 convert.cmyk.rgb = function (cmyk) { 413 var c = cmyk[0] / 100; 414 var m = cmyk[1] / 100; 415 var y = cmyk[2] / 100; 416 var k = cmyk[3] / 100; 417 var r; 418 var g; 419 var b; 420 421 r = 1 - Math.min(1, c * (1 - k) + k); 422 g = 1 - Math.min(1, m * (1 - k) + k); 423 b = 1 - Math.min(1, y * (1 - k) + k); 398 const c = cmyk[0] / 100; 399 const m = cmyk[1] / 100; 400 const y = cmyk[2] / 100; 401 const k = cmyk[3] / 100; 402 403 const r = 1 - Math.min(1, c * (1 - k) + k); 404 const g = 1 - Math.min(1, m * (1 - k) + k); 405 const b = 1 - Math.min(1, y * (1 - k) + k); 424 406 425 407 return [r * 255, g * 255, b * 255]; … … 427 409 428 410 convert.xyz.rgb = function (xyz) { 429 varx = xyz[0] / 100;430 vary = xyz[1] / 100;431 varz = xyz[2] / 100;432 varr;433 varg;434 varb;411 const x = xyz[0] / 100; 412 const y = xyz[1] / 100; 413 const z = xyz[2] / 100; 414 let r; 415 let g; 416 let b; 435 417 436 418 r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986); … … 438 420 b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570); 439 421 440 // assume sRGB422 // Assume sRGB 441 423 r = r > 0.0031308 442 ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)424 ? ((1.055 * (r ** (1.0 / 2.4))) - 0.055) 443 425 : r * 12.92; 444 426 445 427 g = g > 0.0031308 446 ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055)428 ? ((1.055 * (g ** (1.0 / 2.4))) - 0.055) 447 429 : g * 12.92; 448 430 449 431 b = b > 0.0031308 450 ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055)432 ? ((1.055 * (b ** (1.0 / 2.4))) - 0.055) 451 433 : b * 12.92; 452 434 … … 459 441 460 442 convert.xyz.lab = function (xyz) { 461 var x = xyz[0]; 462 var y = xyz[1]; 463 var z = xyz[2]; 464 var l; 465 var a; 466 var b; 443 let x = xyz[0]; 444 let y = xyz[1]; 445 let z = xyz[2]; 467 446 468 447 x /= 95.047; … … 470 449 z /= 108.883; 471 450 472 x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + (16 / 116);473 y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + (16 / 116);474 z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + (16 / 116);475 476 l = (116 * y) - 16;477 a = 500 * (x - y);478 b = 200 * (y - z);451 x = x > 0.008856 ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116); 452 y = y > 0.008856 ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116); 453 z = z > 0.008856 ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116); 454 455 const l = (116 * y) - 16; 456 const a = 500 * (x - y); 457 const b = 200 * (y - z); 479 458 480 459 return [l, a, b]; … … 482 461 483 462 convert.lab.xyz = function (lab) { 484 varl = lab[0];485 vara = lab[1];486 varb = lab[2];487 varx;488 vary;489 varz;463 const l = lab[0]; 464 const a = lab[1]; 465 const b = lab[2]; 466 let x; 467 let y; 468 let z; 490 469 491 470 y = (l + 16) / 116; … … 493 472 z = y - b / 200; 494 473 495 var y2 = Math.pow(y, 3);496 var x2 = Math.pow(x, 3);497 var z2 = Math.pow(z, 3);474 const y2 = y ** 3; 475 const x2 = x ** 3; 476 const z2 = z ** 3; 498 477 y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787; 499 478 x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787; … … 508 487 509 488 convert.lab.lch = function (lab) { 510 var l = lab[0]; 511 var a = lab[1]; 512 var b = lab[2]; 513 var hr; 514 var h; 515 var c; 516 517 hr = Math.atan2(b, a); 489 const l = lab[0]; 490 const a = lab[1]; 491 const b = lab[2]; 492 let h; 493 494 const hr = Math.atan2(b, a); 518 495 h = hr * 360 / 2 / Math.PI; 519 496 … … 522 499 } 523 500 524 c = Math.sqrt(a * a + b * b);501 const c = Math.sqrt(a * a + b * b); 525 502 526 503 return [l, c, h]; … … 528 505 529 506 convert.lch.lab = function (lch) { 530 var l = lch[0]; 531 var c = lch[1]; 532 var h = lch[2]; 533 var a; 534 var b; 535 var hr; 536 537 hr = h / 360 * 2 * Math.PI; 538 a = c * Math.cos(hr); 539 b = c * Math.sin(hr); 507 const l = lch[0]; 508 const c = lch[1]; 509 const h = lch[2]; 510 511 const hr = h / 360 * 2 * Math.PI; 512 const a = c * Math.cos(hr); 513 const b = c * Math.sin(hr); 540 514 541 515 return [l, a, b]; 542 516 }; 543 517 544 convert.rgb.ansi16 = function (args) { 545 var r = args[0]; 546 var g = args[1]; 547 var b = args[2]; 548 var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2]; // hsv -> ansi16 optimization 518 convert.rgb.ansi16 = function (args, saturation = null) { 519 const [r, g, b] = args; 520 let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation; // Hsv -> ansi16 optimization 549 521 550 522 value = Math.round(value / 50); … … 554 526 } 555 527 556 varansi = 30528 let ansi = 30 557 529 + ((Math.round(b / 255) << 2) 558 530 | (Math.round(g / 255) << 1) … … 567 539 568 540 convert.hsv.ansi16 = function (args) { 569 // optimization here; we already know the value and don't need to get541 // Optimization here; we already know the value and don't need to get 570 542 // it converted for us. 571 543 return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]); … … 573 545 574 546 convert.rgb.ansi256 = function (args) { 575 varr = args[0];576 varg = args[1];577 varb = args[2];578 579 // we use the extended greyscale palette here, with the exception of547 const r = args[0]; 548 const g = args[1]; 549 const b = args[2]; 550 551 // We use the extended greyscale palette here, with the exception of 580 552 // black and white. normal palette only has 4 greyscale shades. 581 553 if (r === g && g === b) { … … 591 563 } 592 564 593 varansi = 16565 const ansi = 16 594 566 + (36 * Math.round(r / 255 * 5)) 595 567 + (6 * Math.round(g / 255 * 5)) … … 600 572 601 573 convert.ansi16.rgb = function (args) { 602 varcolor = args % 10;603 604 // handle greyscale574 let color = args % 10; 575 576 // Handle greyscale 605 577 if (color === 0 || color === 7) { 606 578 if (args > 50) { … … 613 585 } 614 586 615 varmult = (~~(args > 50) + 1) * 0.5;616 varr = ((color & 1) * mult) * 255;617 varg = (((color >> 1) & 1) * mult) * 255;618 varb = (((color >> 2) & 1) * mult) * 255;587 const mult = (~~(args > 50) + 1) * 0.5; 588 const r = ((color & 1) * mult) * 255; 589 const g = (((color >> 1) & 1) * mult) * 255; 590 const b = (((color >> 2) & 1) * mult) * 255; 619 591 620 592 return [r, g, b]; … … 622 594 623 595 convert.ansi256.rgb = function (args) { 624 // handle greyscale596 // Handle greyscale 625 597 if (args >= 232) { 626 varc = (args - 232) * 10 + 8;598 const c = (args - 232) * 10 + 8; 627 599 return [c, c, c]; 628 600 } … … 630 602 args -= 16; 631 603 632 varrem;633 varr = Math.floor(args / 36) / 5 * 255;634 varg = Math.floor((rem = args % 36) / 6) / 5 * 255;635 varb = (rem % 6) / 5 * 255;604 let rem; 605 const r = Math.floor(args / 36) / 5 * 255; 606 const g = Math.floor((rem = args % 36) / 6) / 5 * 255; 607 const b = (rem % 6) / 5 * 255; 636 608 637 609 return [r, g, b]; … … 639 611 640 612 convert.rgb.hex = function (args) { 641 varinteger = ((Math.round(args[0]) & 0xFF) << 16)613 const integer = ((Math.round(args[0]) & 0xFF) << 16) 642 614 + ((Math.round(args[1]) & 0xFF) << 8) 643 615 + (Math.round(args[2]) & 0xFF); 644 616 645 varstring = integer.toString(16).toUpperCase();617 const string = integer.toString(16).toUpperCase(); 646 618 return '000000'.substring(string.length) + string; 647 619 }; 648 620 649 621 convert.hex.rgb = function (args) { 650 varmatch = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);622 const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i); 651 623 if (!match) { 652 624 return [0, 0, 0]; 653 625 } 654 626 655 varcolorString = match[0];627 let colorString = match[0]; 656 628 657 629 if (match[0].length === 3) { 658 colorString = colorString.split('').map( function (char){630 colorString = colorString.split('').map(char => { 659 631 return char + char; 660 632 }).join(''); 661 633 } 662 634 663 varinteger = parseInt(colorString, 16);664 varr = (integer >> 16) & 0xFF;665 varg = (integer >> 8) & 0xFF;666 varb = integer & 0xFF;635 const integer = parseInt(colorString, 16); 636 const r = (integer >> 16) & 0xFF; 637 const g = (integer >> 8) & 0xFF; 638 const b = integer & 0xFF; 667 639 668 640 return [r, g, b]; … … 670 642 671 643 convert.rgb.hcg = function (rgb) { 672 varr = rgb[0] / 255;673 varg = rgb[1] / 255;674 varb = rgb[2] / 255;675 varmax = Math.max(Math.max(r, g), b);676 varmin = Math.min(Math.min(r, g), b);677 varchroma = (max - min);678 vargrayscale;679 varhue;644 const r = rgb[0] / 255; 645 const g = rgb[1] / 255; 646 const b = rgb[2] / 255; 647 const max = Math.max(Math.max(r, g), b); 648 const min = Math.min(Math.min(r, g), b); 649 const chroma = (max - min); 650 let grayscale; 651 let hue; 680 652 681 653 if (chroma < 1) { … … 694 666 hue = 2 + (b - r) / chroma; 695 667 } else { 696 hue = 4 + (r - g) / chroma + 4;668 hue = 4 + (r - g) / chroma; 697 669 } 698 670 … … 704 676 705 677 convert.hsl.hcg = function (hsl) { 706 var s = hsl[1] / 100; 707 var l = hsl[2] / 100; 708 var c = 1; 709 var f = 0; 710 711 if (l < 0.5) { 712 c = 2.0 * s * l; 713 } else { 714 c = 2.0 * s * (1.0 - l); 715 } 716 678 const s = hsl[1] / 100; 679 const l = hsl[2] / 100; 680 681 const c = l < 0.5 ? (2.0 * s * l) : (2.0 * s * (1.0 - l)); 682 683 let f = 0; 717 684 if (c < 1.0) { 718 685 f = (l - 0.5 * c) / (1.0 - c); … … 723 690 724 691 convert.hsv.hcg = function (hsv) { 725 vars = hsv[1] / 100;726 varv = hsv[2] / 100;727 728 varc = s * v;729 varf = 0;692 const s = hsv[1] / 100; 693 const v = hsv[2] / 100; 694 695 const c = s * v; 696 let f = 0; 730 697 731 698 if (c < 1.0) { … … 737 704 738 705 convert.hcg.rgb = function (hcg) { 739 varh = hcg[0] / 360;740 varc = hcg[1] / 100;741 varg = hcg[2] / 100;706 const h = hcg[0] / 360; 707 const c = hcg[1] / 100; 708 const g = hcg[2] / 100; 742 709 743 710 if (c === 0.0) { … … 745 712 } 746 713 747 var pure = [0, 0, 0]; 748 var hi = (h % 1) * 6; 749 var v = hi % 1; 750 var w = 1 - v; 751 var mg = 0; 752 714 const pure = [0, 0, 0]; 715 const hi = (h % 1) * 6; 716 const v = hi % 1; 717 const w = 1 - v; 718 let mg = 0; 719 720 /* eslint-disable max-statements-per-line */ 753 721 switch (Math.floor(hi)) { 754 722 case 0: … … 765 733 pure[0] = 1; pure[1] = 0; pure[2] = w; 766 734 } 735 /* eslint-enable max-statements-per-line */ 767 736 768 737 mg = (1.0 - c) * g; … … 776 745 777 746 convert.hcg.hsv = function (hcg) { 778 varc = hcg[1] / 100;779 varg = hcg[2] / 100;780 781 varv = c + g * (1.0 - c);782 varf = 0;747 const c = hcg[1] / 100; 748 const g = hcg[2] / 100; 749 750 const v = c + g * (1.0 - c); 751 let f = 0; 783 752 784 753 if (v > 0.0) { … … 790 759 791 760 convert.hcg.hsl = function (hcg) { 792 varc = hcg[1] / 100;793 varg = hcg[2] / 100;794 795 varl = g * (1.0 - c) + 0.5 * c;796 vars = 0;761 const c = hcg[1] / 100; 762 const g = hcg[2] / 100; 763 764 const l = g * (1.0 - c) + 0.5 * c; 765 let s = 0; 797 766 798 767 if (l > 0.0 && l < 0.5) { … … 807 776 808 777 convert.hcg.hwb = function (hcg) { 809 varc = hcg[1] / 100;810 varg = hcg[2] / 100;811 varv = c + g * (1.0 - c);778 const c = hcg[1] / 100; 779 const g = hcg[2] / 100; 780 const v = c + g * (1.0 - c); 812 781 return [hcg[0], (v - c) * 100, (1 - v) * 100]; 813 782 }; 814 783 815 784 convert.hwb.hcg = function (hwb) { 816 varw = hwb[1] / 100;817 varb = hwb[2] / 100;818 varv = 1 - b;819 varc = v - w;820 varg = 0;785 const w = hwb[1] / 100; 786 const b = hwb[2] / 100; 787 const v = 1 - b; 788 const c = v - w; 789 let g = 0; 821 790 822 791 if (c < 1) { … … 839 808 }; 840 809 841 convert.gray.hsl = convert.gray.hsv =function (args) {810 convert.gray.hsl = function (args) { 842 811 return [0, 0, args[0]]; 843 812 }; 813 814 convert.gray.hsv = convert.gray.hsl; 844 815 845 816 convert.gray.hwb = function (gray) { … … 856 827 857 828 convert.gray.hex = function (gray) { 858 varval = Math.round(gray[0] / 100 * 255) & 0xFF;859 varinteger = (val << 16) + (val << 8) + val;860 861 varstring = integer.toString(16).toUpperCase();829 const val = Math.round(gray[0] / 100 * 255) & 0xFF; 830 const integer = (val << 16) + (val << 8) + val; 831 832 const string = integer.toString(16).toUpperCase(); 862 833 return '000000'.substring(string.length) + string; 863 834 }; 864 835 865 836 convert.rgb.gray = function (rgb) { 866 varval = (rgb[0] + rgb[1] + rgb[2]) / 3;837 const val = (rgb[0] + rgb[1] + rgb[2]) / 3; 867 838 return [val / 255 * 100]; 868 839 }; -
imaps-frontend/node_modules/color-convert/index.js
rd565449 r0c6b92a 1 varconversions = require('./conversions');2 varroute = require('./route');1 const conversions = require('./conversions'); 2 const route = require('./route'); 3 3 4 varconvert = {};4 const convert = {}; 5 5 6 varmodels = Object.keys(conversions);6 const models = Object.keys(conversions); 7 7 8 8 function wrapRaw(fn) { 9 var wrappedFn = function (args) { 10 if (args === undefined || args === null) { 11 return args; 9 const wrappedFn = function (...args) { 10 const arg0 = args[0]; 11 if (arg0 === undefined || arg0 === null) { 12 return arg0; 12 13 } 13 14 14 if (arg uments.length > 1) {15 args = Array.prototype.slice.call(arguments);15 if (arg0.length > 1) { 16 args = arg0; 16 17 } 17 18 … … 19 20 }; 20 21 21 // preserve .conversion property if there is one22 // Preserve .conversion property if there is one 22 23 if ('conversion' in fn) { 23 24 wrappedFn.conversion = fn.conversion; … … 28 29 29 30 function wrapRounded(fn) { 30 var wrappedFn = function (args) { 31 if (args === undefined || args === null) { 32 return args; 31 const wrappedFn = function (...args) { 32 const arg0 = args[0]; 33 34 if (arg0 === undefined || arg0 === null) { 35 return arg0; 33 36 } 34 37 35 if (arg uments.length > 1) {36 args = Array.prototype.slice.call(arguments);38 if (arg0.length > 1) { 39 args = arg0; 37 40 } 38 41 39 varresult = fn(args);42 const result = fn(args); 40 43 41 // we're assuming the result is an array here.44 // We're assuming the result is an array here. 42 45 // see notice in conversions.js; don't use box types 43 46 // in conversion functions. 44 47 if (typeof result === 'object') { 45 for ( varlen = result.length, i = 0; i < len; i++) {48 for (let len = result.length, i = 0; i < len; i++) { 46 49 result[i] = Math.round(result[i]); 47 50 } … … 51 54 }; 52 55 53 // preserve .conversion property if there is one56 // Preserve .conversion property if there is one 54 57 if ('conversion' in fn) { 55 58 wrappedFn.conversion = fn.conversion; … … 59 62 } 60 63 61 models.forEach(f unction (fromModel){64 models.forEach(fromModel => { 62 65 convert[fromModel] = {}; 63 66 … … 65 68 Object.defineProperty(convert[fromModel], 'labels', {value: conversions[fromModel].labels}); 66 69 67 varroutes = route(fromModel);68 varrouteModels = Object.keys(routes);70 const routes = route(fromModel); 71 const routeModels = Object.keys(routes); 69 72 70 routeModels.forEach( function (toModel){71 varfn = routes[toModel];73 routeModels.forEach(toModel => { 74 const fn = routes[toModel]; 72 75 73 76 convert[fromModel][toModel] = wrapRounded(fn); -
imaps-frontend/node_modules/color-convert/package.json
rd565449 r0c6b92a 2 2 "name": "color-convert", 3 3 "description": "Plain color conversion functions", 4 "version": " 1.9.3",4 "version": "2.0.1", 5 5 "author": "Heather Arthur <fayearthur@gmail.com>", 6 6 "license": "MIT", … … 9 9 "pretest": "xo", 10 10 "test": "node test/basic.js" 11 }, 12 "engines": { 13 "node": ">=7.0.0" 11 14 }, 12 15 "keywords": [ … … 27 30 "index.js", 28 31 "conversions.js", 29 "css-keywords.js",30 32 "route.js" 31 33 ], … … 38 40 }, 39 41 "devDependencies": { 40 "chalk": " 1.1.1",41 "xo": " 0.11.2"42 "chalk": "^2.4.2", 43 "xo": "^0.24.0" 42 44 }, 43 45 "dependencies": { 44 "color-name": " 1.1.3"46 "color-name": "~1.1.4" 45 47 } 46 48 } -
imaps-frontend/node_modules/color-convert/route.js
rd565449 r0c6b92a 1 varconversions = require('./conversions');1 const conversions = require('./conversions'); 2 2 3 3 /* 4 this function routes a model to all other models.4 This function routes a model to all other models. 5 5 6 6 all functions that are routed have a property `.conversion` attached … … 13 13 14 14 function buildGraph() { 15 vargraph = {};15 const graph = {}; 16 16 // https://jsperf.com/object-keys-vs-for-in-with-closure/3 17 varmodels = Object.keys(conversions);17 const models = Object.keys(conversions); 18 18 19 for ( varlen = models.length, i = 0; i < len; i++) {19 for (let len = models.length, i = 0; i < len; i++) { 20 20 graph[models[i]] = { 21 21 // http://jsperf.com/1-vs-infinity … … 31 31 // https://en.wikipedia.org/wiki/Breadth-first_search 32 32 function deriveBFS(fromModel) { 33 vargraph = buildGraph();34 var queue = [fromModel]; // unshift -> queue -> pop33 const graph = buildGraph(); 34 const queue = [fromModel]; // Unshift -> queue -> pop 35 35 36 36 graph[fromModel].distance = 0; 37 37 38 38 while (queue.length) { 39 varcurrent = queue.pop();40 varadjacents = Object.keys(conversions[current]);39 const current = queue.pop(); 40 const adjacents = Object.keys(conversions[current]); 41 41 42 for ( varlen = adjacents.length, i = 0; i < len; i++) {43 varadjacent = adjacents[i];44 varnode = graph[adjacent];42 for (let len = adjacents.length, i = 0; i < len; i++) { 43 const adjacent = adjacents[i]; 44 const node = graph[adjacent]; 45 45 46 46 if (node.distance === -1) { … … 62 62 63 63 function wrapConversion(toModel, graph) { 64 varpath = [graph[toModel].parent, toModel];65 varfn = conversions[graph[toModel].parent][toModel];64 const path = [graph[toModel].parent, toModel]; 65 let fn = conversions[graph[toModel].parent][toModel]; 66 66 67 varcur = graph[toModel].parent;67 let cur = graph[toModel].parent; 68 68 while (graph[cur].parent) { 69 69 path.unshift(graph[cur].parent); … … 77 77 78 78 module.exports = function (fromModel) { 79 vargraph = deriveBFS(fromModel);80 varconversion = {};79 const graph = deriveBFS(fromModel); 80 const conversion = {}; 81 81 82 varmodels = Object.keys(graph);83 for ( varlen = models.length, i = 0; i < len; i++) {84 vartoModel = models[i];85 varnode = graph[toModel];82 const models = Object.keys(graph); 83 for (let len = models.length, i = 0; i < len; i++) { 84 const toModel = models[i]; 85 const node = graph[toModel]; 86 86 87 87 if (node.parent === null) { 88 // no possible conversion, or this node is the source model.88 // No possible conversion, or this node is the source model. 89 89 continue; 90 90 }
Note:
See TracChangeset
for help on using the changeset viewer.