Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

color-diff

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

color-diff - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0-beta.1

5

CHANGELOG.md
# Changelog
## 1.4.0
* Use ESM modules. Backwards compatible with CJS using rollup.
* Replaced nyc with c8 (nyc does not support esm).
## 1.3.0

@@ -4,0 +9,0 @@

14

index.js

@@ -1,3 +0,1 @@

"use strict";
// Types

@@ -24,5 +22,5 @@

// Imports
const { rgbaToLab } = require("./lib/convert");
const { ciede2000 } = require("./lib/diff");
const {
import { rgbaToLab } from "./lib/convert.js";
import { ciede2000 } from "./lib/diff.js";
import {
mapPalette,

@@ -33,6 +31,6 @@ paletteMapKey,

labPaletteMapKey,
} = require("./lib/palette");
} from "./lib/palette.js";
// Exports
module.exports = {
export {
closest,

@@ -47,3 +45,3 @@ closestLab,

labPaletteMapKey,
diff: ciede2000,
ciede2000 as diff,
rgbaToLab,

@@ -50,0 +48,0 @@ // eslint-disable-next-line camelcase

@@ -1,3 +0,1 @@

"use strict";
/**

@@ -34,10 +32,5 @@ * @author Markus Ekholm

*/
module.exports = { rgbaToLab, normalize };
export { rgbaToLab, normalize };
/**
* IMPORTS
*/
const pow = Math.pow;
/**
* TYPES

@@ -94,7 +87,7 @@ */

if (R > 0.04045) R = pow(((R + 0.055) / 1.055), 2.4);
if (R > 0.04045) R = Math.pow(((R + 0.055) / 1.055), 2.4);
else R = R / 12.92;
if (G > 0.04045) G = pow(((G + 0.055) / 1.055), 2.4);
if (G > 0.04045) G = Math.pow(((G + 0.055) / 1.055), 2.4);
else G = G / 12.92;
if (B > 0.04045) B = pow(((B + 0.055) / 1.055), 2.4);
if (B > 0.04045) B = Math.pow(((B + 0.055) / 1.055), 2.4);
else B = B / 12.92;

@@ -126,7 +119,7 @@

let X = c.X / refX;
if (X > 0.008856) X = pow(X, 1 / 3);
if (X > 0.008856) X = Math.pow(X, 1 / 3);
else X = (7.787 * X) + (16 / 116);
if (Y > 0.008856) Y = pow(Y, 1 / 3);
if (Y > 0.008856) Y = Math.pow(Y, 1 / 3);
else Y = (7.787 * Y) + (16 / 116);
if (Z > 0.008856) Z = pow(Z, 1 / 3);
if (Z > 0.008856) Z = Math.pow(Z, 1 / 3);
else Z = (7.787 * Z) + (16 / 116);

@@ -133,0 +126,0 @@ const L = (116 * Y) - 16;

@@ -1,3 +0,1 @@

"use strict";
/**

@@ -32,21 +30,11 @@ * @author Markus Ekholm

/**
* EXPORTS
* IMPORTS
*/
import { rgbaToLab } from "./convert.js";
module.exports = { ciede2000 };
/**
* IMPORTS
* EXPORTS
*/
const sqrt = Math.sqrt;
const pow = Math.pow;
const cos = Math.cos;
const atan2 = Math.atan2;
const sin = Math.sin;
const abs = Math.abs;
const exp = Math.exp;
const PI = Math.PI;
export { ciede2000 };
const { rgbaToLab } = require("./convert");
/**

@@ -105,9 +93,9 @@ * TYPES

*/
const C1 = sqrt(pow(a1, 2) + pow(b1, 2)); // (2)
const C2 = sqrt(pow(a2, 2) + pow(b2, 2)); // (2)
const C1 = Math.sqrt(Math.pow(a1, 2) + Math.pow(b1, 2)); // (2)
const C2 = Math.sqrt(Math.pow(a2, 2) + Math.pow(b2, 2)); // (2)
const aC1C2 = (C1 + C2) / 2.0; // (3)
const G = 0.5 * (1 - sqrt(pow(aC1C2, 7.0) /
(pow(aC1C2, 7.0) + pow(25.0, 7.0)))); // (4)
const G = 0.5 * (1 - Math.sqrt(Math.pow(aC1C2, 7.0) /
(Math.pow(aC1C2, 7.0) + Math.pow(25.0, 7.0)))); // (4)

@@ -117,4 +105,4 @@ const a1p = (1.0 + G) * a1; // (5)

const C1p = sqrt(pow(a1p, 2) + pow(b1, 2)); // (6)
const C2p = sqrt(pow(a2p, 2) + pow(b2, 2)); // (6)
const C1p = Math.sqrt(Math.pow(a1p, 2) + Math.pow(b1, 2)); // (6)
const C2p = Math.sqrt(Math.pow(a2p, 2) + Math.pow(b2, 2)); // (6)

@@ -131,3 +119,3 @@ const h1p = hpF(b1, a1p); // (7)

const dhp = dhpF(C1, C2, h1p, h2p); // (10)
const dHp = 2 * sqrt(C1p * C2p) * sin(radians(dhp) / 2.0); // (11)
const dHp = 2 * Math.sqrt(C1p * C2p) * Math.sin(radians(dhp) / 2.0); // (11)

@@ -141,13 +129,13 @@ /**

const aHp = aHpF(C1, C2, h1p, h2p); // (14)
const T = 1 - 0.17 * cos(radians(aHp - 30)) + 0.24 * cos(radians(2 * aHp)) +
0.32 * cos(radians(3 * aHp + 6)) - 0.20 * cos(radians(4 * aHp - 63)); // (15)
const dRo = 30 * exp(-(pow((aHp - 275) / 25, 2))); // (16)
const RC = sqrt((pow(aCp, 7.0)) / (pow(aCp, 7.0) + pow(25.0, 7.0)));// (17)
const SL = 1 + ((0.015 * pow(aL - 50, 2)) /
sqrt(20 + pow(aL - 50, 2.0)));// (18)
const T = 1 - 0.17 * Math.cos(radians(aHp - 30)) + 0.24 * Math.cos(radians(2 * aHp)) +
0.32 * Math.cos(radians(3 * aHp + 6)) - 0.20 * Math.cos(radians(4 * aHp - 63)); // (15)
const dRo = 30 * Math.exp(-(Math.pow((aHp - 275) / 25, 2))); // (16)
const RC = Math.sqrt((Math.pow(aCp, 7.0)) / (Math.pow(aCp, 7.0) + Math.pow(25.0, 7.0)));// (17)
const SL = 1 + ((0.015 * Math.pow(aL - 50, 2)) /
Math.sqrt(20 + Math.pow(aL - 50, 2.0)));// (18)
const SC = 1 + 0.045 * aCp;// (19)
const SH = 1 + 0.015 * aCp * T;// (20)
const RT = -2 * RC * sin(radians(2 * dRo));// (21)
const dE = sqrt(pow(dLp / (SL * kL), 2) + pow(dCp / (SC * kC), 2) +
pow(dHp / (SH * kH), 2) + RT * (dCp / (SC * kC)) *
const RT = -2 * RC * Math.sin(radians(2 * dRo));// (21)
const dE = Math.sqrt(Math.pow(dLp / (SL * kL), 2) + Math.pow(dCp / (SC * kC), 2) +
Math.pow(dHp / (SH * kH), 2) + RT * (dCp / (SC * kC)) *
(dHp / (SH * kH))); // (22)

@@ -167,3 +155,3 @@ return dE;

function degrees(n) {
return n * (180 / PI);
return n * (180 / Math.PI);
}

@@ -177,3 +165,3 @@

function radians(n) {
return n * (PI / 180);
return n * (Math.PI / 180);
}

@@ -190,3 +178,3 @@

else {
const tmphp = degrees(atan2(x, y));
const tmphp = degrees(Math.atan2(x, y));
if (tmphp >= 0) return tmphp;

@@ -207,3 +195,3 @@ else return tmphp + 360;

if (C1 * C2 === 0) return 0;
else if (abs(h2p - h1p) <= 180) return h2p - h1p;
else if (Math.abs(h2p - h1p) <= 180) return h2p - h1p;
else if ((h2p - h1p) > 180) return (h2p - h1p) - 360;

@@ -224,6 +212,6 @@ else if ((h2p - h1p) < -180) return (h2p - h1p) + 360;

if (C1 * C2 === 0) return h1p + h2p;
else if (abs(h1p - h2p) <= 180) return (h1p + h2p) / 2.0;
else if ((abs(h1p - h2p) > 180) && ((h1p + h2p) < 360)) return (h1p + h2p + 360) / 2.0;
else if ((abs(h1p - h2p) > 180) && ((h1p + h2p) >= 360)) return (h1p + h2p - 360) / 2.0;
else if (Math.abs(h1p - h2p) <= 180) return (h1p + h2p) / 2.0;
else if ((Math.abs(h1p - h2p) > 180) && ((h1p + h2p) < 360)) return (h1p + h2p + 360) / 2.0;
else if ((Math.abs(h1p - h2p) > 180) && ((h1p + h2p) >= 360)) return (h1p + h2p - 360) / 2.0;
else throw (new Error());
}

@@ -1,3 +0,1 @@

"use strict";
/**

@@ -32,5 +30,11 @@ * @author Markus Ekholm

/**
* IMPORTS
*/
import { ciede2000 } from "./diff.js";
import { normalize } from "./convert.js";
/**
* EXPORTS
*/
module.exports = {
export {
mapPalette,

@@ -44,8 +48,2 @@ mapPaletteLab,

/**
* IMPORTS
*/
const { ciede2000 } = require("./diff");
const { normalize } = require("./convert");
/**
* TYPES

@@ -52,0 +50,0 @@ */

{
"name": "color-diff",
"version": "1.3.0",
"version": "1.4.0-beta.1",
"description": "Implemets the CIEDE2000 color difference algorithm, conversion between RGB and LAB color and mapping all colors in palette X to the closest or most different color in palette Y based on the CIEDE2000 difference.",
"main": "index.js",
"exports": {
"import": "./index.js",
"require": "./index.cjs"
},
"scripts": {
"test": "nyc --reporter=lcov mocha && eslint . --cache && tsc"
"test": "c8 --reporter=lcov mocha && eslint . --cache && tsc",
"dist": "rollup index.js --format cjs --file index.cjs"
},

@@ -13,2 +18,3 @@ "repository": {

},
"type": "module",
"keywords": [

@@ -35,6 +41,7 @@ "color",

"@types/node": "^18.15.13",
"c8": "^7.14.0",
"eslint": "^8.24.0",
"eslint-config-exp": "^0.5.0",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"rollup": "^3.23.0",
"typescript": "^5.0.4"

@@ -49,4 +56,5 @@ },

"index.js",
"index.cjs",
"lib/"
]
}
# color-diff
[![Build Status](https://github.com/markusn/color-diff/actions/workflows/build-latest.yaml/badge.svg?branch=master)](https://github.com/markusn/color-diff/actions/workflows/build-latest.yaml)

@@ -26,2 +27,3 @@ [![Coverage Status](https://coveralls.io/repos/markusn/color-diff/badge.png?branch=master)](https://coveralls.io/r/markusn/color-diff?branch=master)

```js
// CommonJS
const {

@@ -36,3 +38,15 @@ closest,

labPaletteMapKey,
} = require('color-diff');
} = require("color-diff");
// ESM
import {
closest,
furthest,
diff,
mapPalette,
paletteMapKey,
rgbaToLab,
mapPaletteLab,
labPaletteMapKey,
} from "color-diff";
```

@@ -39,0 +53,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc