Skip to content

Commit

Permalink
Fix types and type tests (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydk authored Jun 26, 2024
1 parent bfb5203 commit f7c2c35
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 163 deletions.
7 changes: 5 additions & 2 deletions src/color.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import hooks from "./hooks.js";
import * as util from "./util.js";
import ColorSpace, { Ref } from "./ColorSpace.js";
import SpaceAccessors from "./space-coord-accessors.js";
import { ToGamutOptions } from "./types.js";

import {
to as toFn,
Expand Down Expand Up @@ -86,7 +87,6 @@ declare namespace Color {
export const to: ToColorNamespace<typeof toFn>;
export const equals: ToColorNamespace<typeof equalsFn>;
export const inGamut: ToColorNamespace<typeof inGamutFn>;
export const toGamut: ToColorNamespace<typeof toGamutFn>;
export const distance: ToColorNamespace<typeof distanceFn>;
// `get` is defined below as a static method on the Class,
// and `toString` is intentionally not overridden for the namespace
Expand All @@ -100,6 +100,8 @@ declare namespace Color {
export function set (color: ColorTypes, props: Record<string, number | ((coord: number) => number)>): Color;
export function setAll (color: ColorTypes, coords: Coords, alpha?: number): Color;
export function setAll (color: ColorTypes, space: string | ColorSpace, coords: Coords, alpha?: number): Color;
export function toGamut (color: ColorTypes, options?: ToGamutOptions): Color;
export function toGamut (color: ColorTypes, space?: string): Color;
}

/**
Expand Down Expand Up @@ -155,7 +157,6 @@ declare class Color extends SpaceAccessors implements PlainColorObject {
to: ToColorPrototype<typeof toFn>;
equals: ToColorPrototype<typeof equalsFn>;
inGamut: ToColorPrototype<typeof inGamutFn>;
toGamut: ToColorPrototype<typeof toGamutFn>;
distance: ToColorPrototype<typeof distanceFn>;
toString: ToColorPrototype<typeof serialize>;

Expand All @@ -165,6 +166,8 @@ declare class Color extends SpaceAccessors implements PlainColorObject {
set (props: Record<string, number | ((coord: number) => number)>): Color;
setAll (coords: Coords, alpha?: number): Color;
setAll (space: string | ColorSpace, coords: Coords, alpha?: number): Color;
toGamut (options?: ToGamutOptions): Color;
toGamut (space?: string): Color;
}

export default Color;
2 changes: 1 addition & 1 deletion src/deltaE.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import deltaEMethods from "./deltaE/index.js";
*
* @param {ColorTypes} c1
* @param {ColorTypes} c2
* @param {Methods | ({ method: Methods } & Record<string, any>} o
* @param {Methods | ({ method: Methods } & Record<string, any>)} o
* deltaE method to use as well as any other options to pass to the deltaE function
* @returns {number}
* @throws {TypeError} Unknown or unspecified method
Expand Down
7 changes: 5 additions & 2 deletions src/deltas.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import to from "./to.js";
import { adjust } from "./angles.js";
import { isNone } from "./util.js";

// Type "imports"
/** @typedef {import("./types.js").ColorTypes} ColorTypes */

/**
* Get color differences per-component, on any color space
* @param {Color} c1
* @param {Color} c2
* @param {ColorTypes} c1
* @param {ColorTypes} c2
* @param {object} options
* @param {string | ColorSpace} [options.space=c1.space] - The color space to use for the delta calculation. Defaults to the color space of the first color.
* @param {string} [options.hue="shorter"] - How to handle hue differences. Same as hue interpolation option.
Expand Down
1 change: 1 addition & 0 deletions src/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import sRGB from "./spaces/srgb.js";
// Type "imports"
/** @typedef {import("./types.js").ColorTypes} ColorTypes */
/** @typedef {import("./types.js").Display} Display */
/** @typedef {import("./ColorSpace.js").default} ColorSpace */

// Default space for CSS output. Code in Color.js makes this wider if there's a DOM available
defaults.display_space = sRGB;
Expand Down
4 changes: 2 additions & 2 deletions src/inGamut.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const ε = .000075;
/**
* Check if a color is in gamut of either its own or another color space
* @param {ColorTypes} color
* @param {string | ColorSpace} space
* @param {{ epsilon?: number | undefined }} param2
* @param {string | ColorSpace} [space]
* @param {{ epsilon?: number | undefined }} [param2]
* @returns {boolean}
*/
export default function inGamut (color, space, {epsilon = ε} = {}) {
Expand Down
150 changes: 0 additions & 150 deletions src/space.d.ts

This file was deleted.

10 changes: 8 additions & 2 deletions src/toGamut.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ const GMAPPRESET = {
/**
* Force coordinates to be in gamut of a certain color space.
* Mutates the color it is passed.
* @overload
* @param {ColorTypes} color
* @param {ToGamutOptions | string} param1
* @param {ToGamutOptions} [options]
* @returns {PlainColorObject}
*/
/**
* @overload
* @param {ColorTypes} color
* @param {string} [space]
* @returns {PlainColorObject}
*/

export default function toGamut (
color,
{
Expand Down
6 changes: 3 additions & 3 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ export interface SerializeOptions {
}

// space.js
import type ColorSpace from "./space.js";
import type { Format, Ref, SpaceOptions } from "./space.js";
import type ColorSpace from "./ColorSpace.js";
import type { Format, Ref, SpaceOptions } from "./ColorSpace.js";
export type { ColorSpace };
export type * from "./space.js";
export type * from "./ColorSpace.js";

// toGamut.js
export interface ToGamutOptions {
Expand Down
2 changes: 1 addition & 1 deletion types/test/spaces.ts → types/test/ColorSpace.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Color from "colorjs.io/src";
import ColorSpace from "colorjs.io/src/space";
import ColorSpace from "colorjs.io/src/ColorSpace";

// @ts-expect-error
new ColorSpace();
Expand Down

0 comments on commit f7c2c35

Please sign in to comment.