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

colord - npm Package Compare versions

Comparing version 0.9.2 to 0.9.3

plugins/hwb.d.ts

5

CHANGELOG.md

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

### 0.9.3
- New plugin: HWB color model
- More accurate HSL and HSV conversions
### 0.9.2

@@ -2,0 +7,0 @@

2

index.js

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

Object.defineProperty(exports,"__esModule",{value:!0});var r=function(r){return"string"==typeof r?r.length>0:"number"==typeof r},t=function(r,t,n){return void 0===t&&(t=0),void 0===n&&(n=Math.pow(10,t)),Math.round(n*r)/n},n=function(r,t,n){return void 0===t&&(t=0),void 0===n&&(n=1),r>n?n:r<t?t:r},e=function(r){var t=r.g,e=r.b,u=r.a;return{r:n(r.r,0,255),g:n(t,0,255),b:n(e,0,255),a:n(u)}},u=function(r){return{r:t(r.r),g:t(r.g),b:t(r.b),a:t(r.a,2)}},o=/^\s*#?([0-9A-F]{3,4}){1,2}\s*$/i,a=function(r){var t=r.toString(16);return t.length<2?"0"+t:t},i=function(r){var n=r.r,e=r.g,u=r.b,o=r.a,a=Math.max(n,e,u),i=a-Math.min(n,e,u),s=i?a===n?(e-u)/i:a===e?2+(u-n)/i:4+(n-e)/i:0;return{h:t(60*(s<0?s+6:s)),s:t(a?i/a*100:0),v:t(a/255*100),a:o}},s=function(r){var t=r.h,n=r.s,e=r.v,u=r.a;t=t/360*6,n/=100,e/=100;var o=Math.floor(t),a=e*(1-n),i=e*(1-(t-o)*n),s=e*(1-(1-t+o)*n),b=o%6;return{r:255*[e,i,a,a,s,e][b],g:255*[s,e,e,i,a,a][b],b:255*[a,a,s,e,e,i][b],a:u}},b=function(r){var t=r.s,e=r.l,u=r.a;return{h:n(r.h,0,360),s:n(t,0,100),l:n(e,0,100),a:n(u)}},f=function(r){return s((n=(t=r).s,{h:t.h,s:(n*=((e=t.l)<50?e:100-e)/100)>0?2*n/(e+n)*100:0,v:e+n,a:t.a}));var t,n,e},g=function(r){return n=i(r),o=n.a,a=(200-(e=n.s))*(u=n.v)/100,{h:t(n.h),s:t(a>0&&a<200?e*u/100/(a<=100?a:200-a)*100:0),l:t(a/2),a:t(o,2)};var n,e,u,o,a},h=/hsla?\(?s*(-?\d+\.?\d*),?\s*(-?\d+\.?\d*)%?,?\s*(-?\d+\.?\d*)%?,?\s*(-?\d*\.?\d+)?s*\)?/i,c=/rgba?\(?\s*(-?\d+),?\s*(-?\d+),?\s*(-?\d+),?\s*(-?\d*\.?\d+)?\s*\)?/i,p={string:[function(r){return o.test(r)?(r=r.replace("#","").trim()).length<=4?{r:parseInt(r[0]+r[0],16),g:parseInt(r[1]+r[1],16),b:parseInt(r[2]+r[2],16),a:4===r.length?parseInt(r[3]+r[3],16)/255:1}:{r:parseInt(r.substr(0,2),16),g:parseInt(r.substr(2,2),16),b:parseInt(r.substr(4,2),16),a:8===r.length?parseInt(r.substr(6,2),16)/255:1}:null},function(r){var t=c.exec(r);return t?e({r:Number(t[1]),g:Number(t[2]),b:Number(t[3]),a:void 0===t[4]?1:Number(t[4])}):null},function(r){var t=h.exec(r);if(!t)return null;var n=b({h:Number(t[1]),s:Number(t[2]),l:Number(t[3]),a:void 0===t[4]?1:Number(t[4])});return f(n)}],object:[function(t){var n=t.r,u=t.g,o=t.b,a=t.a,i=void 0===a?1:a;return r(n)&&r(u)&&r(o)?e({r:Number(n),g:Number(u),b:Number(o),a:Number(i)}):null},function(t){var n=t.h,e=t.s,u=t.l,o=t.a,a=void 0===o?1:o;if(!r(n)||!r(e)||!r(u))return null;var i=b({h:Number(n),s:Number(e),l:Number(u),a:Number(a)});return f(i)},function(t){var e=t.h,u=t.s,o=t.v,a=t.a,i=void 0===a?1:a;if(!r(e)||!r(u)||!r(o))return null;var b=function(r){var t=r.s,e=r.v,u=r.a;return{h:n(r.h,0,360),s:n(t,0,100),v:n(e,0,100),a:n(u)}}({h:Number(e),s:Number(u),v:Number(o),a:Number(i)});return s(b)}]},v=function(r,t){for(var n=0;n<t.length;n++){var e=t[n](r);if(e)return e}return null},l=function(r,t){var e=g(r),u=e.l,o=e.a;return{h:e.h,s:n(e.s+100*t,0,100),l:u,a:o}},d=function(r){return(299*r.r+587*r.g+114*r.b)/1e3/255},m=function(r,t){var e=g(r),u=e.a;return{h:e.h,s:e.s,l:n(e.l+100*t,0,100),a:u}},y=function(){function r(r){this.rgba=function(r){return"string"==typeof r?v(r,p.string):"object"==typeof r?v(r,p.object):null}(r)||{r:0,g:0,b:0,a:1}}return r.prototype.brightness=function(){return t(d(this.rgba),2)},r.prototype.isDark=function(){return d(this.rgba)<.5},r.prototype.isLight=function(){return d(this.rgba)>=.5},r.prototype.toHex=function(){return r=u(this.rgba),n=r.r,e=r.g,o=r.b,s=(i=r.a)<1?a(t(255*i)):"","#"+a(n)+a(e)+a(o)+s;var r,n,e,o,i,s},r.prototype.toRgba=function(){return u(this.rgba)},r.prototype.toRgbaString=function(){return r=u(this.rgba),t=r.r,n=r.g,e=r.b,(o=r.a)<1?"rgba("+t+", "+n+", "+e+", "+o+")":"rgb("+t+", "+n+", "+e+")";var r,t,n,e,o},r.prototype.toHsla=function(){return g(this.rgba)},r.prototype.toHslaString=function(){return r=g(this.rgba),t=r.h,n=r.s,e=r.l,(u=r.a)<1?"hsla("+t+", "+n+"%, "+e+"%, "+u+")":"hsl("+t+", "+n+"%, "+e+"%)";var r,t,n,e,u},r.prototype.toHsva=function(){return i(this.rgba)},r.prototype.invert=function(){return N({r:255-(r=this.rgba).r,g:255-r.g,b:255-r.b,a:r.a});var r},r.prototype.saturate=function(r){return void 0===r&&(r=.1),N(l(this.rgba,r))},r.prototype.desaturate=function(r){return void 0===r&&(r=.1),N(l(this.rgba,-r))},r.prototype.grayscale=function(){return N(l(this.rgba,-1))},r.prototype.lighten=function(r){return void 0===r&&(r=.1),N(m(this.rgba,r))},r.prototype.darken=function(r){return void 0===r&&(r=.1),N(m(this.rgba,-r))},r.prototype.alpha=function(r){return"number"==typeof r?N({r:(n=this.rgba).r,g:n.g,b:n.b,a:r}):t(this.rgba.a,2);var n},r}(),N=function(r){return r instanceof y?r:new y(r)},x=[];exports.Colord=y,exports.colord=N,exports.extend=function(r){r.forEach(function(r){x.indexOf(r)<0&&(r(y,p),x.push(r))})};
Object.defineProperty(exports,"__esModule",{value:!0});var r=function(r){return"string"==typeof r?r.length>0:"number"==typeof r},t=function(r,t,n){return void 0===t&&(t=0),void 0===n&&(n=Math.pow(10,t)),Math.round(n*r)/n},n=function(r,t,n){return void 0===t&&(t=0),void 0===n&&(n=1),r>n?n:r<t?t:r},e=function(r){var t=r.g,e=r.b,u=r.a;return{r:n(r.r,0,255),g:n(t,0,255),b:n(e,0,255),a:n(u)}},u=function(r){return{r:t(r.r),g:t(r.g),b:t(r.b),a:t(r.a,2)}},a=/^\s*#?([0-9A-F]{3,4}){1,2}\s*$/i,o=function(r){var t=r.toString(16);return t.length<2?"0"+t:t},i=function(r){var t=r.r,n=r.g,e=r.b,u=r.a,a=Math.max(t,n,e),o=a-Math.min(t,n,e),i=o?a===t?(n-e)/o:a===n?2+(e-t)/o:4+(t-n)/o:0;return{h:60*(i<0?i+6:i),s:a?o/a*100:0,v:a/255*100,a:u}},s=function(r){var t=r.h,n=r.s,e=r.v,u=r.a;t=t/360*6,n/=100,e/=100;var a=Math.floor(t),o=e*(1-n),i=e*(1-(t-a)*n),s=e*(1-(1-t+a)*n),b=a%6;return{r:255*[e,i,o,o,s,e][b],g:255*[s,e,e,i,o,o][b],b:255*[o,o,s,e,e,i][b],a:u}},b=function(r){var t=r.s,e=r.l,u=r.a;return{h:n(r.h,0,360),s:n(t,0,100),l:n(e,0,100),a:n(u)}},h=function(r){var n=r.s,e=r.l,u=r.a;return{h:t(r.h),s:t(n),l:t(e),a:t(u,2)}},f=function(r){return s((n=(t=r).s,{h:t.h,s:(n*=((e=t.l)<50?e:100-e)/100)>0?2*n/(e+n)*100:0,v:e+n,a:t.a}));var t,n,e},g=function(r){return{h:(t=i(r)).h,s:(u=(200-(n=t.s))*(e=t.v)/100)>0&&u<200?n*e/100/(u<=100?u:200-u)*100:0,l:u/2,a:t.a};var t,n,e,u},c=/hsla?\(?s*(-?\d+\.?\d*),?\s*(-?\d+\.?\d*)%?,?\s*(-?\d+\.?\d*)%?,?\s*(-?\d*\.?\d+)?s*\)?/i,v=/rgba?\(?\s*(-?\d+),?\s*(-?\d+),?\s*(-?\d+),?\s*(-?\d*\.?\d+)?\s*\)?/i,p={string:[function(r){return a.test(r)?(r=r.replace("#","").trim()).length<=4?{r:parseInt(r[0]+r[0],16),g:parseInt(r[1]+r[1],16),b:parseInt(r[2]+r[2],16),a:4===r.length?parseInt(r[3]+r[3],16)/255:1}:{r:parseInt(r.substr(0,2),16),g:parseInt(r.substr(2,2),16),b:parseInt(r.substr(4,2),16),a:8===r.length?parseInt(r.substr(6,2),16)/255:1}:null},function(r){var t=v.exec(r);return t?e({r:Number(t[1]),g:Number(t[2]),b:Number(t[3]),a:void 0===t[4]?1:Number(t[4])}):null},function(r){var t=c.exec(r);if(!t)return null;var n=b({h:Number(t[1]),s:Number(t[2]),l:Number(t[3]),a:void 0===t[4]?1:Number(t[4])});return f(n)}],object:[function(t){var n=t.r,u=t.g,a=t.b,o=t.a,i=void 0===o?1:o;return r(n)&&r(u)&&r(a)?e({r:Number(n),g:Number(u),b:Number(a),a:Number(i)}):null},function(t){var n=t.h,e=t.s,u=t.l,a=t.a,o=void 0===a?1:a;if(!r(n)||!r(e)||!r(u))return null;var i=b({h:Number(n),s:Number(e),l:Number(u),a:Number(o)});return f(i)},function(t){var e=t.h,u=t.s,a=t.v,o=t.a,i=void 0===o?1:o;if(!r(e)||!r(u)||!r(a))return null;var b=function(r){var t=r.s,e=r.v,u=r.a;return{h:n(r.h,0,360),s:n(t,0,100),v:n(e,0,100),a:n(u)}}({h:Number(e),s:Number(u),v:Number(a),a:Number(i)});return s(b)}]},l=function(r,t){for(var n=0;n<t.length;n++){var e=t[n](r);if(e)return e}return null},d=function(r,t){var e=g(r),u=e.l,a=e.a;return{h:e.h,s:n(e.s+100*t,0,100),l:u,a:a}},m=function(r){return(299*r.r+587*r.g+114*r.b)/1e3/255},y=function(r,t){var e=g(r),u=e.a;return{h:e.h,s:e.s,l:n(e.l+100*t,0,100),a:u}},N=function(){function r(r){this.rgba=function(r){return"string"==typeof r?l(r,p.string):"object"==typeof r?l(r,p.object):null}(r)||{r:0,g:0,b:0,a:1}}return r.prototype.brightness=function(){return t(m(this.rgba),2)},r.prototype.isDark=function(){return m(this.rgba)<.5},r.prototype.isLight=function(){return m(this.rgba)>=.5},r.prototype.toHex=function(){return r=u(this.rgba),n=r.r,e=r.g,a=r.b,s=(i=r.a)<1?o(t(255*i)):"","#"+o(n)+o(e)+o(a)+s;var r,n,e,a,i,s},r.prototype.toRgba=function(){return u(this.rgba)},r.prototype.toRgbaString=function(){return r=u(this.rgba),t=r.r,n=r.g,e=r.b,(a=r.a)<1?"rgba("+t+", "+n+", "+e+", "+a+")":"rgb("+t+", "+n+", "+e+")";var r,t,n,e,a},r.prototype.toHsla=function(){return h(g(this.rgba))},r.prototype.toHslaString=function(){return r=h(g(this.rgba)),t=r.h,n=r.s,e=r.l,(u=r.a)<1?"hsla("+t+", "+n+"%, "+e+"%, "+u+")":"hsl("+t+", "+n+"%, "+e+"%)";var r,t,n,e,u},r.prototype.toHsva=function(){return r=i(this.rgba),n=r.s,e=r.v,u=r.a,{h:t(r.h),s:t(n),v:t(e),a:t(u,2)};var r,n,e,u},r.prototype.invert=function(){return x({r:255-(r=this.rgba).r,g:255-r.g,b:255-r.b,a:r.a});var r},r.prototype.saturate=function(r){return void 0===r&&(r=.1),x(d(this.rgba,r))},r.prototype.desaturate=function(r){return void 0===r&&(r=.1),x(d(this.rgba,-r))},r.prototype.grayscale=function(){return x(d(this.rgba,-1))},r.prototype.lighten=function(r){return void 0===r&&(r=.1),x(y(this.rgba,r))},r.prototype.darken=function(r){return void 0===r&&(r=.1),x(y(this.rgba,-r))},r.prototype.alpha=function(r){return"number"==typeof r?x({r:(n=this.rgba).r,g:n.g,b:n.b,a:r}):t(this.rgba.a,2);var n},r}(),x=function(r){return r instanceof N?r:new N(r)},I=[];exports.Colord=N,exports.colord=x,exports.extend=function(r){r.forEach(function(r){I.indexOf(r)<0&&(r(N,p),I.push(r))})};
{
"name": "colord",
"version": "0.9.2",
"version": "0.9.3",
"description": "👑 A tiny yet powerful tool for high-performance color manipulations and conversions",

@@ -109,2 +109,6 @@ "keywords": [

{
"path": "dist/plugins/hwb.mjs",
"limit": "1 KB"
},
{
"path": "dist/plugins/names.mjs",

@@ -111,0 +115,0 @@ "limit": "1.5 KB"

@@ -80,6 +80,7 @@ <div align="center">

- Hexadecimal strings (including 3, 4 and 8 digit notations)
- RGB(A) strings and objects
- HSL(A) strings and objects
- HSV(A) objects
- RGB strings and objects
- HSL strings and objects
- HSV objects
- Color names ([via plugin](#plugins))
- HWB objects ([via plugin](#plugins))
- XYZ objects ([via plugin](#plugins))

@@ -209,2 +210,19 @@ - LCH (coming soon)

<details>
<summary><b><code>toHwb()</code></b> (<b>hwb</b> plugin)</summary>
Converts a color to [HWB (Hue-Whiteness-Blackness)](https://en.wikipedia.org/wiki/HWB_color_model) color space.
```js
import { colord, extend } from "colord";
import hwbPlugin from "colord/plugins/hwb";
extend([hwbPlugin]);
colord("#ffffff").toHwb(); // { h: 0, w: 100, b: 0, a: 1 }
colord("#555aaa").toHwb(); // { h: 236, w: 33, b: 33, a: 1 }
```
</details>
<details>
<summary><b><code>toXyz()</code></b> (<b>xyz</b> plugin)</summary>

@@ -444,2 +462,22 @@

<details>
<summary><b><code>hwb</code> (Hue-Whiteness-Blackness color model)</b></summary>
Adds support of [HWB (Hue-Whiteness-Blackness)](https://en.wikipedia.org/wiki/HWB_color_model) color model.
```js
import { colord, extend } from "colord";
import hwbPlugin from "colord/plugins/hwb";
extend([hwbPlugin]);
colord("#ffffff").toHwb(); // { h: 0, w: 100, b: 0, a: 1 }
colord("#555aaa").toHwb(); // { h: 236, w: 33, b: 33, a: 1 }
colord({ h: 0, w: 0, b: 100 }).toHex(); // "#000000"
colord({ h: 0, w: 100, b: 0, a: 1 }).toHex(); // "#ffffff"
```
</details>
<details>
<summary><b><code>names</code> (CSS color keywords)</b></summary>

@@ -512,3 +550,3 @@

- [x] XYZ color space (via plugin)
- [ ] [HWB](https://drafts.csswg.org/css-color/#the-hwb-notation) color space (via plugin)
- [x] [HWB](https://drafts.csswg.org/css-color/#the-hwb-notation) color space (via plugin)
- [ ] [LAB](https://www.w3.org/TR/css-color-4/#resolving-lab-lch-values) color space (via plugin)

@@ -515,0 +553,0 @@ - [ ] [LCH](https://lea.verou.me/2020/04/lch-colors-in-css-what-why-and-how/) color space (via plugin)

@@ -1,26 +0,21 @@

export interface RgbColor {
export declare type RgbColor = {
r: number;
g: number;
b: number;
}
export interface RgbaColor extends RgbColor {
a: number;
}
export interface HslColor {
};
export declare type HslColor = {
h: number;
s: number;
l: number;
}
export interface HslaColor extends HslColor {
a: number;
}
export interface HsvColor {
};
export declare type HsvColor = {
h: number;
s: number;
v: number;
}
export interface HsvaColor extends HsvColor {
a: number;
}
/** CIE XYZ color space https://www.sttmedia.com/colormodel-xyz */
};
export declare type HwbColor = {
h: number;
w: number;
b: number;
};
export interface XyzColor {

@@ -31,7 +26,11 @@ x: number;

}
/** CIE XYZ with and an alpha channel. Naming is the hardest part: https://stackoverflow.com/a/2464027 */
export interface XyzaColor extends XyzColor {
declare type WithAlpha<O> = O & {
a: number;
}
export declare type ObjectColor = RgbColor | RgbaColor | HslColor | HslaColor | HsvColor | HsvaColor | XyzColor | XyzaColor;
};
export declare type RgbaColor = WithAlpha<RgbColor>;
export declare type HslaColor = WithAlpha<HslColor>;
export declare type HsvaColor = WithAlpha<HsvColor>;
export declare type HwbaColor = WithAlpha<HwbColor>;
export declare type XyzaColor = WithAlpha<XyzColor>;
export declare type ObjectColor = RgbColor | RgbaColor | HslColor | HslaColor | HsvColor | HsvaColor | HwbColor | HwbaColor | XyzColor | XyzaColor;
export declare type AnyColor = string | ObjectColor;

@@ -45,1 +44,2 @@ export declare type InputObject = Record<string, unknown>;

};
export {};

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