Skip to content

Commit

Permalink
Add colord package to block editor; Replace tinycolor2 with colord on…
Browse files Browse the repository at this point in the history
… duotone hook.
  • Loading branch information
jorgefilipecosta committed Sep 6, 2021
1 parent bd8da40 commit 0942d43
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/block-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@wordpress/wordcount": "file:../wordcount",
"classnames": "^2.3.1",
"css-mediaquery": "^0.1.2",
"colord": "^2.7.0",
"diff": "^4.0.2",
"dom-scroll-into-view": "^1.2.1",
"inherits": "^2.0.3",
Expand Down
14 changes: 8 additions & 6 deletions packages/block-editor/src/hooks/duotone.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* External dependencies
*/
import classnames from 'classnames';
import tinycolor from 'tinycolor2';
import { colord, extend } from 'colord';
import namesPlugin from 'colord/plugins/names';

/**
* WordPress dependencies
Expand All @@ -25,6 +26,8 @@ import BlockList from '../components/block-list';

const EMPTY_ARRAY = [];

extend( [ namesPlugin ] );

/**
* Convert a list of colors to an object of R, G, and B values.
*
Expand All @@ -36,11 +39,10 @@ export function getValuesFromColors( colors = [] ) {
const values = { r: [], g: [], b: [] };

colors.forEach( ( color ) => {
// Access values directly to skip extra rounding that tinycolor.toRgb() does.
const tcolor = tinycolor( color );
values.r.push( tcolor._r / 255 );
values.g.push( tcolor._g / 255 );
values.b.push( tcolor._b / 255 );
const rgbColor = colord( color ).toRgb();
values.r.push( rgbColor.r / 255 );
values.g.push( rgbColor.g / 255 );
values.b.push( rgbColor.b / 255 );
} );

return values;
Expand Down

0 comments on commit 0942d43

Please sign in to comment.