You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

colord

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.7.0 to 2.8.0

4

CHANGELOG.md

@@ -0,1 +1,5 @@

### 2.8.0
- New `delta` method to calculate the perceived color difference between two colors ❤️ [@EricRovell](https://github.com/EricRovell)
### 2.7.0

@@ -2,0 +6,0 @@

4

package.json
{
"name": "colord",
"version": "2.7.0",
"version": "2.8.0",
"description": "👑 A tiny yet powerful tool for high-performance color manipulations and conversions",

@@ -169,3 +169,3 @@ "keywords": [

"path": "dist/plugins/lab.mjs",
"limit": "1 KB"
"limit": "1.5 KB"
},

@@ -172,0 +172,0 @@ {

@@ -1,2 +0,2 @@

import { LabaColor } from "../types";
import { LabaColor, AnyColor } from "../types";
import { Plugin } from "../extend";

@@ -7,5 +7,11 @@ declare module "../colord" {

* Converts a color to CIELAB color space and returns an object.
* The object always includes `alpha` value [0—1].
* The object always includes `alpha` value [0, 1].
*/
toLab(): LabaColor;
/**
* Calculates the perceived color difference for two colors according to
* [Delta E2000](https://en.wikipedia.org/wiki/Color_difference#CIEDE2000).
* Returns a value in [0, 1] range.
*/
delta(color?: AnyColor | Colord): number;
}

@@ -12,0 +18,0 @@ }

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

var a=function(a){return"string"==typeof a?a.length>0:"number"==typeof a},r=function(a,r,t){return void 0===r&&(r=0),void 0===t&&(t=Math.pow(10,r)),Math.round(t*a)/t+0},t=function(a,r,t){return void 0===r&&(r=0),void 0===t&&(t=1),a>t?t:a>r?a:r},n=function(a){var r=a/255;return r<.04045?r/12.92:Math.pow((r+.055)/1.055,2.4)},u=function(a){return 255*(a>.0031308?1.055*Math.pow(a,1/2.4)-.055:12.92*a)},o=96.422,e=100,b=82.521,l=function(a){var r,n,o={x:.9555766*(r=a).x+-.0230393*r.y+.0631636*r.z,y:-.0282895*r.x+1.0099416*r.y+.0210077*r.z,z:.0122982*r.x+-.020483*r.y+1.3299098*r.z};return n={r:u(.032404542*o.x-.015371385*o.y-.004985314*o.z),g:u(-.00969266*o.x+.018760108*o.y+41556e-8*o.z),b:u(556434e-9*o.x-.002040259*o.y+.010572252*o.z),a:a.a},{r:t(n.r,0,255),g:t(n.g,0,255),b:t(n.b,0,255),a:t(n.a)}},h=function(a){var r=n(a.r),u=n(a.g),l=n(a.b);return function(a){return{x:t(a.x,0,o),y:t(a.y,0,e),z:t(a.z,0,b),a:t(a.a)}}(function(a){return{x:1.0478112*a.x+.0228866*a.y+-.050127*a.z,y:.0295424*a.x+.9904844*a.y+-.0170491*a.z,z:-.0092345*a.x+.0150436*a.y+.7521316*a.z,a:a.a}}({x:100*(.4124564*r+.3575761*u+.1804375*l),y:100*(.2126729*r+.7151522*u+.072175*l),z:100*(.0193339*r+.119192*u+.9503041*l),a:a.a}))},i=216/24389,p=24389/27,y=function(r){var n=r.l,u=r.a,o=r.b,e=r.alpha,b=void 0===e?1:e;if(!a(n)||!a(u)||!a(o))return null;var l=function(a){return{l:t(a.l,0,400),a:a.a,b:a.b,alpha:t(a.alpha)}}({l:Number(n),a:Number(u),b:Number(o),alpha:Number(b)});return c(l)},c=function(a){var r=(a.l+16)/116,t=a.a/500+r,n=r-a.b/200;return l({x:(Math.pow(t,3)>i?Math.pow(t,3):(116*t-16)/p)*o,y:(a.l>8?Math.pow((a.l+16)/116,3):a.l/p)*e,z:(Math.pow(n,3)>i?Math.pow(n,3):(116*n-16)/p)*b,a:a.alpha})};module.exports=function(a,t){a.prototype.toLab=function(){return t=h(this.rgba),u=t.y/e,l=t.z/b,n=(n=t.x/o)>i?Math.cbrt(n):(p*n+16)/116,a={l:116*(u=u>i?Math.cbrt(u):(p*u+16)/116)-16,a:500*(n-u),b:200*(u-(l=l>i?Math.cbrt(l):(p*l+16)/116)),alpha:t.a},{l:r(a.l,2),a:r(a.a,2),b:r(a.b,2),alpha:r(a.alpha,3)};var a,t,n,u,l},t.object.push([y,"lab"])};
var a=function(a){return"string"==typeof a?a.length>0:"number"==typeof a},t=function(a,t,o){return void 0===t&&(t=0),void 0===o&&(o=Math.pow(10,t)),Math.round(o*a)/o+0},o=function(a,t,o){return void 0===t&&(t=0),void 0===o&&(o=1),a>o?o:a>t?a:t},r=function(a){var t=a/255;return t<.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)},h=function(a){return 255*(a>.0031308?1.055*Math.pow(a,1/2.4)-.055:12.92*a)},n=96.422,p=100,M=82.521,u=function(a){var t,r,n={x:.9555766*(t=a).x+-.0230393*t.y+.0631636*t.z,y:-.0282895*t.x+1.0099416*t.y+.0210077*t.z,z:.0122982*t.x+-.020483*t.y+1.3299098*t.z};return r={r:h(.032404542*n.x-.015371385*n.y-.004985314*n.z),g:h(-.00969266*n.x+.018760108*n.y+41556e-8*n.z),b:h(556434e-9*n.x-.002040259*n.y+.010572252*n.z),a:a.a},{r:o(r.r,0,255),g:o(r.g,0,255),b:o(r.b,0,255),a:o(r.a)}},e=function(a){var t=r(a.r),h=r(a.g),u=r(a.b);return function(a){return{x:o(a.x,0,n),y:o(a.y,0,p),z:o(a.z,0,M),a:o(a.a)}}(function(a){return{x:1.0478112*a.x+.0228866*a.y+-.050127*a.z,y:.0295424*a.x+.9904844*a.y+-.0170491*a.z,z:-.0092345*a.x+.0150436*a.y+.7521316*a.z,a:a.a}}({x:100*(.4124564*t+.3575761*h+.1804375*u),y:100*(.2126729*t+.7151522*h+.072175*u),z:100*(.0193339*t+.119192*h+.9503041*u),a:a.a}))},w=216/24389,b=24389/27,i=function(t){var r=t.l,h=t.a,n=t.b,p=t.alpha,M=void 0===p?1:p;if(!a(r)||!a(h)||!a(n))return null;var u=function(a){return{l:o(a.l,0,400),a:a.a,b:a.b,alpha:o(a.alpha)}}({l:Number(r),a:Number(h),b:Number(n),alpha:Number(M)});return l(u)},l=function(a){var t=(a.l+16)/116,o=a.a/500+t,r=t-a.b/200;return u({x:(Math.pow(o,3)>w?Math.pow(o,3):(116*o-16)/b)*n,y:(a.l>8?Math.pow((a.l+16)/116,3):a.l/b)*p,z:(Math.pow(r,3)>w?Math.pow(r,3):(116*r-16)/b)*M,a:a.alpha})};module.exports=function(a,r){a.prototype.toLab=function(){return o=e(this.rgba),h=o.y/p,u=o.z/M,r=(r=o.x/n)>w?Math.cbrt(r):(b*r+16)/116,a={l:116*(h=h>w?Math.cbrt(h):(b*h+16)/116)-16,a:500*(r-h),b:200*(h-(u=u>w?Math.cbrt(u):(b*u+16)/116)),alpha:o.a},{l:t(a.l,2),a:t(a.a,2),b:t(a.b,2),alpha:t(a.alpha,3)};var a,o,r,h,u},a.prototype.delta=function(r){void 0===r&&(r="#FFF");var h=r instanceof a?r:new a(r),n=function(a,t){var o=a.l,r=a.a,h=a.b,n=t.l,p=t.a,M=t.b,u=180/Math.PI,e=Math.PI/180,w=Math.pow(Math.pow(r,2)+Math.pow(h,2),.5),b=Math.pow(Math.pow(p,2)+Math.pow(M,2),.5),i=(o+n)/2,l=Math.pow((w+b)/2,7),c=.5*(1-Math.pow(l/(l+Math.pow(25,7)),.5)),f=r*(1+c),y=p*(1+c),v=Math.pow(Math.pow(f,2)+Math.pow(h,2),.5),x=Math.pow(Math.pow(y,2)+Math.pow(M,2),.5),z=(v+x)/2,s=0===f&&0===h?0:Math.atan2(h,f)*u,d=0===y&&0===M?0:Math.atan2(M,y)*u;s<0&&(s+=360),d<0&&(d+=360);var g=d-s,m=Math.abs(d-s);m>180&&d<=s?g+=360:m>180&&d>s&&(g-=360);var N=s+d;m<=180?N/=2:N=(s+d<360?N+360:N-360)/2;var F=1-.17*Math.cos(e*(N-30))+.24*Math.cos(2*e*N)+.32*Math.cos(e*(3*N+6))-.2*Math.cos(e*(4*N-63)),L=n-o,I=x-v,P=2*Math.sin(e*g/2)*Math.pow(v*x,.5),j=1+.015*Math.pow(i-50,2)/Math.pow(20+Math.pow(i-50,2),.5),k=1+.045*z,q=1+.015*z*F,A=30*Math.exp(-1*Math.pow((N-275)/25,2)),B=-2*Math.pow(l/(l+Math.pow(25,7)),.5)*Math.sin(2*e*A);return Math.pow(Math.pow(L/1/j,2)+Math.pow(I/1/k,2)+Math.pow(P/1/q,2)+B*I*P/(1*k*1*q),.5)}(this.toLab(),h.toLab())/100;return o(t(n,3))},r.object.push([i,"lab"])};

@@ -512,3 +512,3 @@ <div align="center">

```js
import { colord, extends } from "colord";
import { colord, extend } from "colord";
import mixPlugin from "colord/plugins/mix";

@@ -530,3 +530,3 @@

```js
import { colord, extends } from "colord";
import { colord, extend } from "colord";
import mixPlugin from "colord/plugins/mix";

@@ -548,3 +548,3 @@

```js
import { colord, extends } from "colord";
import { colord, extend } from "colord";
import mixPlugin from "colord/plugins/mix";

@@ -566,3 +566,3 @@

```js
import { colord, extends } from "colord";
import { colord, extend } from "colord";
import harmoniesPlugin from "colord/plugins/harmonies";

@@ -718,2 +718,18 @@

<details>
<summary><b><code>.delta(color2 = "#FFF")</code></b> (<b>lab</b> plugin)</summary>
Calculates the perceived color difference between two colors.
The difference calculated according to [Delta E2000](https://en.wikipedia.org/wiki/Color_difference#CIEDE2000).
The return value is `0` if the colors are equal, `1` if they are entirely different.
```js
colord("#3296fa").delta("#197dc8"); // 0.099
colord("#faf0c8").delta("#ffffff"); // 0.148
colord("#afafaf").delta("#b4b4b4"); // 0.014
colord("#000000").delta("#ffffff"); // 1
```
</details>
### Color utilities

@@ -795,3 +811,3 @@

```js
import { colord, extends } from "colord";
import { colord, extend } from "colord";
import harmonies from "colord/plugins/harmonies";

@@ -834,6 +850,8 @@

<details>
<summary><b><code>lab</code> (CIE LAB color space)</b> <i>0.9 KB</i></summary>
<summary><b><code>lab</code> (CIE LAB color space)</b> <i>1.4 KB</i></summary>
Adds support of [CIE LAB](https://en.wikipedia.org/wiki/CIELAB_color_space) color model. The conversion logic is ported from [CSS Color Module Level 4 Specification](https://www.w3.org/TR/css-color-4/#color-conversion-code).
Also plugin provides `.delta` method for [perceived color difference calculations](https://en.wikipedia.org/wiki/Color_difference#CIEDE2000).
```js

@@ -847,2 +865,5 @@ import { colord, extend } from "colord";

colord("#ffffff").toLab(); // { l: 100, a: 0, b: 0, alpha: 1 }
colord("#afafaf").delta("#b4b4b4"); // 0.014
colord("#000000").delta("#ffffff"); // 1
```

@@ -849,0 +870,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc