Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(color): major restructure, new types/conversions
BREAKING CHANGE: replace color classes w/ dynamically generated impls - add ColorSpec, ColorType, ColorFactory types - add defColor() color type factory based on declarative ColorSpec - all color types now based on defColor() - remove obsolete AColor class - color factories now also act as converters - add color() factory to wrap color in class for given mode - remove CSS and Int types (use plain strings/ints now, and use css() or resolveAsCss() to convert to CSS strings) - parseCss() now returns ParsedColor (circumvents circular deps) - replace convert() w/ new simplified version - add/update generic isGray(), isBlack(), isWhite(), luminance()
- Loading branch information
1 parent
97dda16
commit 6389f7c
Showing
102 changed files
with
1,280 additions
and
1,226 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
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
File renamed without changes.
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
2 changes: 1 addition & 1 deletion
2
packages/color/src/system.ts → packages/color/src/api/system.ts
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { isString } from "@thi.ng/checks"; | ||
import type { | ||
Color, | ||
ColorFactory, | ||
ColorMode, | ||
ColorType, | ||
ParsedColor, | ||
} from "./api"; | ||
import { hcy } from "./hcy/hcy"; | ||
import { hsi } from "./hsi/hsi"; | ||
import { hsl } from "./hsl/hsl"; | ||
import { hsv } from "./hsv/hsv"; | ||
import { lab } from "./lab/lab"; | ||
import { lch } from "./lch/lch"; | ||
import { oklab } from "./oklab/oklab"; | ||
import { rgb } from "./rgb/rgb"; | ||
import { srgb } from "./srgb/srgb"; | ||
import { xyy } from "./xyy/xyy"; | ||
import { xyz } from "./xyz/xyz"; | ||
import { ycc } from "./ycc/ycc"; | ||
|
||
const FACTORIES: Record<ColorMode, ColorFactory<any>> = { | ||
hcy, | ||
hsi, | ||
hsl: hsl, | ||
hsv: hsv, | ||
lab, | ||
lch, | ||
oklab, | ||
rgb, | ||
srgb, | ||
xyy, | ||
xyz, | ||
ycc, | ||
}; | ||
|
||
export function color( | ||
src: ParsedColor, | ||
buf?: Color, | ||
idx?: number, | ||
stride?: number | ||
): ColorType<any>; | ||
export function color( | ||
mode: ColorMode, | ||
buf: Color, | ||
idx?: number, | ||
stride?: number | ||
): ColorType<any>; | ||
export function color( | ||
src: any, | ||
buf?: any, | ||
idx?: number, | ||
stride?: number | ||
): ColorType<any> { | ||
if (isString(src)) { | ||
return FACTORIES[<ColorMode>src](buf, idx, stride); | ||
} | ||
if (buf) { | ||
const res = FACTORIES[(<ParsedColor>src).mode](buf, idx, stride); | ||
res.set(src.deref()); | ||
return res; | ||
} | ||
return FACTORIES[(<ParsedColor>src).mode](src.deref()); | ||
} |
Oops, something went wrong.