Skip to content

Commit

Permalink
Fix some color space types
Browse files Browse the repository at this point in the history
  • Loading branch information
Remiscan committed Nov 3, 2022
1 parent 8f8c063 commit dea2625
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions dist/colori.js

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

2 changes: 1 addition & 1 deletion dist/colori.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/ts/color-spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ interface ColorSpaceBase {
links: string[],
};

interface ColorSpaceWithGamut extends ColorSpaceBase {
export interface ColorSpaceWithGamut extends ColorSpaceBase {
gamut: Array<number[]>,
black?: number[],
white?: number[]
}

interface ColorSpaceWithoutGamut extends ColorSpaceBase {
export interface ColorSpaceWithoutGamut extends ColorSpaceBase {
gamutSpace: string,
}

Expand Down
15 changes: 11 additions & 4 deletions src/ts/couleur.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import colorSpaces, { colorProperty, ColorSpace } from './color-spaces.js';
import colorSpaces, { colorProperty, ColorSpace, ColorSpaceWithGamut, ColorSpaceWithoutGamut } from './color-spaces.js';
import * as Contrasts from './contrasts.js';
import * as Conversions from './conversion.js';
import { Format as CSSFormat, Formats, RegExps as ValueRegExps } from './css-formats.js';
Expand Down Expand Up @@ -884,7 +884,11 @@ export default class Couleur {
*/
public static inGamut(destinationSpaceID: colorSpaceOrID, values: number[] | Couleur, sourceSpaceID: colorSpaceOrID = 'srgb', { tolerance = .0001 } = {}): boolean {
const destinationSpace = Couleur.getSpace(destinationSpaceID);
const gamutSpace = destinationSpace.gamutSpace ? Couleur.getSpace(destinationSpace.gamutSpace) : destinationSpace;
const gamutSpace = (
(destinationSpace as ColorSpaceWithoutGamut).gamutSpace
? Couleur.getSpace((destinationSpace as ColorSpaceWithoutGamut).gamutSpace)
: destinationSpace
) as ColorSpaceWithGamut;
const convertedValues = values instanceof Couleur ? values.valuesTo(gamutSpace)
: Couleur.convert(sourceSpaceID, gamutSpace, values);
return convertedValues.every((v, k) => v >= (gamutSpace.gamut[k][0] - tolerance) && v <= (gamutSpace.gamut[k][1] + tolerance));
Expand All @@ -902,7 +906,11 @@ export default class Couleur {
*/
public static toGamut(destinationSpaceID: colorSpaceOrID, values: number[] | Couleur, sourceSpaceID: colorSpaceOrID = 'srgb', { method = 'okchroma' }: toGamutOptions = {}): number[] {
const destinationSpace = Couleur.getSpace(destinationSpaceID);
const gamutSpace = destinationSpace.gamutSpace ? Couleur.getSpace(destinationSpace.gamutSpace) : destinationSpace;
const gamutSpace = (
(destinationSpace as ColorSpaceWithoutGamut).gamutSpace
? Couleur.getSpace((destinationSpace as ColorSpaceWithoutGamut).gamutSpace)
: destinationSpace
) as ColorSpaceWithGamut;
const sourceSpace = Couleur.getSpace(sourceSpaceID);
const _method = method.toLowerCase();

Expand Down Expand Up @@ -976,7 +984,6 @@ export default class Couleur {
public toGamut(destinationSpaceID: colorSpaceOrID): Couleur {
const destinationSpace = Couleur.getSpace(destinationSpaceID);
const rgbClampedValues = Couleur.toGamut(destinationSpace, this, undefined);
//const rgbClampedValues = Couleur.convert(destinationSpace, 'srgb', destinationClampedValues);
return new Couleur([...rgbClampedValues, this.a]);
}

Expand Down

0 comments on commit dea2625

Please sign in to comment.