-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a PlainColorObject type for functions that return color objects
The ColorObject type has optional properties and doesn't accurately reflect the color object type returned by functions such as getColor() which ensures that the object returned has space, coords and alpha properties that are not undefined. A new interface called PlainColorObject has been introduced to represent fully formed color objects. The Color class implements the PlainColorObject interface so the Color class was removed from list of types in the ColorTypes type.
- Loading branch information
Showing
13 changed files
with
60 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import Color from "./color"; | ||
import { PlainColorObject } from "./color"; | ||
|
||
export default function clone(color: Color): Color; | ||
export default function clone(color: PlainColorObject): PlainColorObject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { ColorObject, ColorTypes } from "./color"; | ||
import { PlainColorObject, ColorTypes } from "./color"; | ||
|
||
export default function getColor(color: ColorTypes): ColorObject; | ||
export default function getColor(color: ColorTypes): PlainColorObject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import Color, { ColorObject } from "./color"; | ||
import { ColorTypes, PlainColorObject } from "./color"; | ||
import ColorSpace from "./space"; | ||
|
||
declare namespace toGamut { | ||
let returns: "color"; | ||
} | ||
|
||
declare function toGamut<T extends Color | ColorObject>( | ||
color: T, | ||
declare function toGamut( | ||
color: ColorTypes, | ||
options?: { | ||
method?: string | undefined; | ||
space?: string | ColorSpace | undefined; | ||
} | ||
): T; | ||
): PlainColorObject; | ||
|
||
export default toGamut; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import Color, { ColorTypes } from "./color"; | ||
import { PlainColorObject, ColorTypes } from "./color"; | ||
|
||
export function lighten(color: ColorTypes, amount?: number): Color; | ||
export function lighten(color: ColorTypes, amount?: number): PlainColorObject; | ||
|
||
export function darken(color: ColorTypes, amount?: number): Color; | ||
export function darken(color: ColorTypes, amount?: number): PlainColorObject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
import Color from "colorjs.io/src/color"; | ||
import clone from "colorjs.io/src/clone"; | ||
import { sRGB } from "colorjs.io/src/spaces/index-fn"; | ||
|
||
// @ts-expect-error | ||
clone(); | ||
|
||
clone(new Color("red")); // $ExpectType Color | ||
clone(new Color("red")); // $ExpectType PlainColorObject | ||
// $ExpectType PlainColorObject | ||
clone({ | ||
space: sRGB, | ||
coords: [0, 0, 0], | ||
alpha: 1, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters