Skip to content

Commit

Permalink
Merge branch 'main' into types/generate-declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
MysteryBlokHed committed Jun 27, 2024
2 parents d040420 + f7c2c35 commit 369b075
Show file tree
Hide file tree
Showing 11 changed files with 101 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
38 changes: 38 additions & 0 deletions src/index-fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,41 @@ export {default as deltaEMethods} from "./deltaE/index.js";
export * from "./variations.js";
export { mix, steps, range, isRange } from "./interpolation.js";
export * from "./spaces/index-fn.js";

// Type re-exports
// Re-exported from src/color.d.ts
/** @typedef {import("./types.js").ColorConstructor} ColorConstructor */
/** @typedef {import("./types.js").ColorObject} ColorObject */
/** @typedef {import("./types.js").ColorTypes} ColorTypes */
/** @typedef {import("./types.js").Coords} Coords */
/** @typedef {import("./types.js").DefineFunctionCode} DefineFunctionCode */
/** @typedef {import("./types.js").DefineFunctionOptions} DefineFunctionOptions */
/** @typedef {import("./types.js").DefineFunctionHybrid} DefineFunctionHybrid */
/** @typedef {import("./types.js").PlainColorObject} PlainColorObject */
/** @typedef {import("./types.js").SpaceAccessor} SpaceAccessor */
/**
* @typedef {import("./types.js").ToColorPrototype<T>} ToColorPrototype
* @template {(...args: any[]) => any} T
*/
// Re-exported from src/adapt.d.ts
/** @typedef {import("./types.js").White} White */
// Re-exported from src/CATs.d.ts
/** @typedef {import("./types.js").CAT} CAT */
// Re-exported from src/display.d.ts
/** @typedef {import("./types.js").Display} Display */
// Re-exported from src/interpolation.d.ts
/** @typedef {import("./types.js").Range} Range */
/** @typedef {import("./types.js").RangeOptions} RangeOptions */
/** @typedef {import("./types.js").MixOptions} MixOptions */
/** @typedef {import("./types.js").StepsOptions} StepsOptions */
// Re-exported from src/parse.d.ts
/** @typedef {import("./types.js").ParseOptions} ParseOptions */
// Re-exported from src/rgbspace.d.ts
/** @typedef {import("./types.js").RGBOptions} RGBOptions */
// Re-exported from src/serialize.d.ts
/** @typedef {import("./types.js").SerializeOptions} SerializeOptions */
// Re-exported from src/space.d.ts
/** @typedef {import("./types.js").Format} SpaceFormat */
/** @typedef {import("./types.js").CoordMeta} CoordMeta */
/** @typedef {import("./types.js").Ref} Ref */
/** @typedef {import("./types.js").SpaceOptions} SpaceOptions */
37 changes: 37 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,43 @@ import { range, Range, MixOptions, StepsOptions } from "./interpolation.js";
import { getLuminance } from "./luminance.js";
import { lighten, darken } from "./variations.js";

// Type re-exports
export {
// Re-exported from src/color.d.ts
ColorConstructor,
ColorObject,
ColorTypes,
Coords,
DefineFunctionCode,
DefineFunctionOptions,
DefineFunctionHybrid,
PlainColorObject,
SpaceAccessor,
ToColorPrototype,
// Re-exported from src/adapt.d.ts
White,
// Re-exported from src/CATs.d.ts
CAT,
// Re-exported from src/display.d.ts
Display,
// Re-exported from src/interpolation.d.ts
Range,
RangeOptions,
MixOptions,
StepsOptions,
// Re-exported from src/parse.d.ts
ParseOptions,
// Re-exported from src/rgbspace.d.ts
RGBOptions,
// Re-exported from src/serialize.d.ts
SerializeOptions,
// Re-exported from src/space.d.ts
Format as SpaceFormat,
CoordMeta,
Ref,
SpaceOptions,
} from "./types.js";

// Augment existing Color object
declare module "./color" {
export default class Color {
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 369b075

Please sign in to comment.