@zag-js/color-utils 0.22.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/color-format-gradient.ts","../src/area-gradient.ts","../src/color.ts","../src/utils.ts","../src/rgb-color.ts","../src/hsl-color.ts","../src/hsb-color.ts","../src/native-color.ts","../src/parse-color.ts"],"sourcesContent":["export const generateRGB_R = (orientation: [string, string], dir: boolean, zValue: number) => {\n const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`\n const result = {\n areaStyles: {\n backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,0),rgb(${zValue},255,0))`,\n },\n areaGradientStyles: {\n backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,255),rgb(${zValue},255,255))`,\n WebkitMaskImage: maskImage,\n maskImage,\n },\n }\n return result\n}\n\nexport const generateRGB_G = (orientation: [string, string], dir: boolean, zValue: number) => {\n const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`\n const result = {\n areaStyles: {\n backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},0),rgb(255,${zValue},0))`,\n },\n areaGradientStyles: {\n backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},255),rgb(255,${zValue},255))`,\n WebkitMaskImage: maskImage,\n maskImage,\n },\n }\n return result\n}\n\nexport const generateRGB_B = (orientation: [string, string], dir: boolean, zValue: number) => {\n const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`\n const result = {\n areaStyles: {\n backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,0,${zValue}),rgb(255,0,${zValue}))`,\n },\n areaGradientStyles: {\n backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,255,${zValue}),rgb(255,255,${zValue}))`,\n WebkitMaskImage: maskImage,\n maskImage,\n },\n }\n return result\n}\n\nexport const generateHSL_H = (orientation: [string, string], dir: boolean, zValue: number) => {\n const result = {\n areaStyles: {},\n areaGradientStyles: {\n background: [\n `linear-gradient(to ${\n orientation[Number(dir)]\n }, hsla(0,0%,0%,1) 0%, hsla(0,0%,0%,0) 50%, hsla(0,0%,100%,0) 50%, hsla(0,0%,100%,1) 100%)`,\n `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,50%),hsla(0,0%,50%,0))`,\n `hsl(${zValue}, 100%, 50%)`,\n ].join(\",\"),\n },\n }\n return result\n}\n\nexport const generateHSL_S = (orientation: [string, string], dir: boolean, alphaValue: number) => {\n const result = {\n areaStyles: {},\n areaGradientStyles: {\n background: [\n `linear-gradient(to ${\n orientation[Number(!dir)]\n }, hsla(0,0%,0%,${alphaValue}) 0%, hsla(0,0%,0%,0) 50%, hsla(0,0%,100%,0) 50%, hsla(0,0%,100%,${alphaValue}) 100%)`,\n `linear-gradient(to ${\n orientation[Number(dir)]\n },hsla(0,100%,50%,${alphaValue}),hsla(60,100%,50%,${alphaValue}),hsla(120,100%,50%,${alphaValue}),hsla(180,100%,50%,${alphaValue}),hsla(240,100%,50%,${alphaValue}),hsla(300,100%,50%,${alphaValue}),hsla(359,100%,50%,${alphaValue}))`,\n \"hsl(0, 0%, 50%)\",\n ].join(\",\"),\n },\n }\n return result\n}\n\nexport const generateHSL_L = (orientation: [string, string], dir: boolean, zValue: number) => {\n const result = {\n areaStyles: {},\n areaGradientStyles: {\n backgroundImage: [\n `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,${zValue}%),hsla(0,0%,${zValue}%,0))`,\n `linear-gradient(to ${\n orientation[Number(dir)]\n },hsl(0,100%,${zValue}%),hsl(60,100%,${zValue}%),hsl(120,100%,${zValue}%),hsl(180,100%,${zValue}%),hsl(240,100%,${zValue}%),hsl(300,100%,${zValue}%),hsl(360,100%,${zValue}%))`,\n ].join(\",\"),\n },\n }\n return result\n}\n\nexport const generateHSB_H = (orientation: [string, string], dir: boolean, zValue: number) => {\n const result = {\n areaStyles: {},\n areaGradientStyles: {\n background: [\n `linear-gradient(to ${orientation[Number(dir)]},hsl(0,0%,0%),hsla(0,0%,0%,0))`,\n `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,100%),hsla(0,0%,100%,0))`,\n `hsl(${zValue}, 100%, 50%)`,\n ].join(\",\"),\n },\n }\n return result\n}\n\nexport const generateHSB_S = (orientation: [string, string], dir: boolean, alphaValue: number) => {\n const result = {\n areaStyles: {},\n areaGradientStyles: {\n background: [\n `linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,0%,${alphaValue}),hsla(0,0%,0%,0))`,\n `linear-gradient(to ${\n orientation[Number(dir)]\n },hsla(0,100%,50%,${alphaValue}),hsla(60,100%,50%,${alphaValue}),hsla(120,100%,50%,${alphaValue}),hsla(180,100%,50%,${alphaValue}),hsla(240,100%,50%,${alphaValue}),hsla(300,100%,50%,${alphaValue}),hsla(359,100%,50%,${alphaValue}))`,\n `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,0%),hsl(0,0%,100%))`,\n ].join(\",\"),\n },\n }\n return result\n}\n\nexport const generateHSB_B = (orientation: [string, string], dir: boolean, alphaValue: number) => {\n const result = {\n areaStyles: {},\n areaGradientStyles: {\n background: [\n `linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,100%,${alphaValue}),hsla(0,0%,100%,0))`,\n `linear-gradient(to ${\n orientation[Number(dir)]\n },hsla(0,100%,50%,${alphaValue}),hsla(60,100%,50%,${alphaValue}),hsla(120,100%,50%,${alphaValue}),hsla(180,100%,50%,${alphaValue}),hsla(240,100%,50%,${alphaValue}),hsla(300,100%,50%,${alphaValue}),hsla(359,100%,50%,${alphaValue}))`,\n \"#000\",\n ].join(\",\"),\n },\n }\n return result\n}\n","import type { Color } from \"./color\"\nimport {\n generateRGB_R,\n generateRGB_G,\n generateRGB_B,\n generateHSL_H,\n generateHSB_H,\n generateHSL_S,\n generateHSB_S,\n generateHSB_B,\n generateHSL_L,\n} from \"./color-format-gradient\"\nimport type { ColorChannel } from \"./types\"\n\ninterface GradientOptions {\n xChannel: ColorChannel\n yChannel: ColorChannel\n dir: \"rtl\" | \"ltr\"\n}\n\ninterface GradientStyles {\n areaStyles: Record<string, string>\n areaGradientStyles: Record<string, string>\n}\n\nexport function getColorAreaGradient(color: Color, options: GradientOptions): GradientStyles {\n const { xChannel, yChannel, dir: dirProp } = options\n\n const { zChannel } = color.getColorSpaceAxes({ xChannel, yChannel })\n const zValue = color.getChannelValue(zChannel)\n\n const { minValue: zMin, maxValue: zMax } = color.getChannelRange(zChannel)\n const orientation: [string, string] = [\"top\", dirProp === \"rtl\" ? \"left\" : \"right\"]\n\n let dir = false\n\n let background = { areaStyles: {}, areaGradientStyles: {} }\n\n let alphaValue = (zValue - zMin) / (zMax - zMin)\n let isHSL = color.getColorFormat() === \"hsl\"\n\n switch (zChannel) {\n case \"red\": {\n dir = xChannel === \"green\"\n background = generateRGB_R(orientation, dir, zValue)\n break\n }\n\n case \"green\": {\n dir = xChannel === \"red\"\n background = generateRGB_G(orientation, dir, zValue)\n break\n }\n\n case \"blue\": {\n dir = xChannel === \"red\"\n background = generateRGB_B(orientation, dir, zValue)\n break\n }\n\n case \"hue\": {\n dir = xChannel !== \"saturation\"\n if (isHSL) {\n background = generateHSL_H(orientation, dir, zValue)\n } else {\n background = generateHSB_H(orientation, dir, zValue)\n }\n break\n }\n\n case \"saturation\": {\n dir = xChannel === \"hue\"\n if (isHSL) {\n background = generateHSL_S(orientation, dir, alphaValue)\n } else {\n background = generateHSB_S(orientation, dir, alphaValue)\n }\n break\n }\n\n case \"brightness\": {\n dir = xChannel === \"hue\"\n background = generateHSB_B(orientation, dir, alphaValue)\n break\n }\n\n case \"lightness\": {\n dir = xChannel === \"hue\"\n background = generateHSL_L(orientation, dir, zValue)\n break\n }\n }\n\n return background\n}\n","import type { ColorType, ColorFormat, ColorChannel, ColorChannelRange, ColorAxes } from \"./types\"\n\nexport abstract class Color implements ColorType {\n abstract toFormat(format: ColorFormat): ColorType\n abstract toString(format: ColorFormat | \"css\"): string\n abstract clone(): ColorType\n abstract getChannelRange(channel: ColorChannel): ColorChannelRange\n abstract getColorFormat(): ColorFormat\n abstract getColorChannels(): [ColorChannel, ColorChannel, ColorChannel]\n\n hasColorChannel(channel: ColorChannel): boolean {\n return this.getColorChannels().includes(channel)\n }\n\n toHexInt(): number {\n return this.toFormat(\"rgb\").toHexInt()\n }\n\n getChannelValue(channel: ColorChannel): number {\n if (channel in this) {\n return this[channel]\n }\n\n throw new Error(\"Unsupported color channel: \" + channel)\n }\n\n withChannelValue(channel: ColorChannel, value: number): ColorType {\n if (channel in this) {\n let clone = this.clone()\n clone[channel] = value\n return clone\n }\n\n throw new Error(\"Unsupported color channel: \" + channel)\n }\n\n getColorSpaceAxes(xyChannels: { xChannel?: ColorChannel; yChannel?: ColorChannel }): ColorAxes {\n let { xChannel, yChannel } = xyChannels\n let xCh = xChannel || this.getColorChannels().find((c) => c !== yChannel)\n let yCh = yChannel || this.getColorChannels().find((c) => c !== xCh)\n let zCh = this.getColorChannels().find((c) => c !== xCh && c !== yCh)\n return { xChannel: xCh!, yChannel: yCh!, zChannel: zCh! }\n }\n\n isEqual(color: ColorType): boolean {\n return this.toHexInt() === color.toHexInt() && this.getChannelValue(\"alpha\") === color.getChannelValue(\"alpha\")\n }\n}\n","export function mod(n: number, m: number) {\n return ((n % m) + m) % m\n}\n\nexport function toFixedNumber(num: number, digits: number) {\n return Math.round(Math.pow(10, digits) * num) / Math.pow(10, digits)\n}\n\nexport function clampValue(value: number, min: number, max: number) {\n return Math.min(Math.max(value, min), max)\n}\n","import { Color } from \"./color\"\nimport { HSBColor } from \"./hsb-color\"\nimport { HSLColor } from \"./hsl-color\"\nimport type { ColorChannel, ColorChannelRange, ColorFormat, ColorType } from \"./types\"\nimport { clampValue, toFixedNumber } from \"./utils\"\n\nexport class RGBColor extends Color {\n constructor(\n private red: number,\n private green: number,\n private blue: number,\n private alpha: number,\n ) {\n super()\n }\n\n static parse(value: string) {\n let colors: (number | undefined)[] = []\n\n // matching #rgb, #rgba, #rrggbb, #rrggbbaa\n if (/^#[\\da-f]+$/i.test(value) && [4, 5, 7, 9].includes(value.length)) {\n const values = (value.length < 6 ? value.replace(/[^#]/gi, \"$&$&\") : value).slice(1).split(\"\")\n while (values.length > 0) {\n colors.push(parseInt(values.splice(0, 2).join(\"\"), 16))\n }\n colors[3] = colors[3] !== undefined ? colors[3] / 255 : undefined\n }\n\n // matching rgb(rrr, ggg, bbb), rgba(rrr, ggg, bbb, 0.a)\n const match = value.match(/^rgba?\\((.*)\\)$/)\n\n if (match?.[1]) {\n colors = match[1]\n .split(\",\")\n .map((value) => Number(value.trim()))\n .map((num, i) => clampValue(num, 0, i < 3 ? 255 : 1))\n }\n\n //@ts-expect-error\n return colors.length < 3 ? undefined : new RGBColor(colors[0], colors[1], colors[2], colors[3] ?? 1)\n }\n\n toString(format: ColorFormat | \"css\") {\n switch (format) {\n case \"hex\":\n return (\n \"#\" +\n (\n this.red.toString(16).padStart(2, \"0\") +\n this.green.toString(16).padStart(2, \"0\") +\n this.blue.toString(16).padStart(2, \"0\")\n ).toUpperCase()\n )\n case \"hexa\":\n return (\n \"#\" +\n (\n this.red.toString(16).padStart(2, \"0\") +\n this.green.toString(16).padStart(2, \"0\") +\n this.blue.toString(16).padStart(2, \"0\") +\n Math.round(this.alpha * 255)\n .toString(16)\n .padStart(2, \"0\")\n ).toUpperCase()\n )\n case \"rgb\":\n return `rgb(${this.red}, ${this.green}, ${this.blue})`\n case \"css\":\n case \"rgba\":\n return `rgba(${this.red}, ${this.green}, ${this.blue}, ${this.alpha})`\n default:\n return this.toFormat(format).toString(format)\n }\n }\n\n toFormat(format: ColorFormat): ColorType {\n switch (format) {\n case \"hex\":\n case \"hexa\":\n case \"rgb\":\n case \"rgba\":\n return this\n case \"hsb\":\n case \"hsba\":\n return this.toHSB()\n case \"hsl\":\n case \"hsla\":\n return this.toHSL()\n default:\n throw new Error(\"Unsupported color conversion: rgb -> \" + format)\n }\n }\n\n toHexInt(): number {\n return (this.red << 16) | (this.green << 8) | this.blue\n }\n\n /**\n * Converts an RGB color value to HSB.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.\n * @returns An HSBColor object.\n */\n private toHSB(): ColorType {\n const red = this.red / 255\n const green = this.green / 255\n const blue = this.blue / 255\n const min = Math.min(red, green, blue)\n const brightness = Math.max(red, green, blue)\n const chroma = brightness - min\n const saturation = brightness === 0 ? 0 : chroma / brightness\n let hue = 0 // achromatic\n\n if (chroma !== 0) {\n switch (brightness) {\n case red:\n hue = (green - blue) / chroma + (green < blue ? 6 : 0)\n break\n case green:\n hue = (blue - red) / chroma + 2\n break\n case blue:\n hue = (red - green) / chroma + 4\n break\n }\n\n hue /= 6\n }\n\n return new HSBColor(\n toFixedNumber(hue * 360, 2),\n toFixedNumber(saturation * 100, 2),\n toFixedNumber(brightness * 100, 2),\n this.alpha,\n )\n }\n\n /**\n * Converts an RGB color value to HSL.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.\n * @returns An HSLColor object.\n */\n private toHSL(): ColorType {\n const red = this.red / 255\n const green = this.green / 255\n const blue = this.blue / 255\n const min = Math.min(red, green, blue)\n const max = Math.max(red, green, blue)\n const lightness = (max + min) / 2\n const chroma = max - min\n\n let hue = -1\n let saturation = -1\n\n if (chroma === 0) {\n hue = saturation = 0 // achromatic\n } else {\n saturation = chroma / (lightness < 0.5 ? max + min : 2 - max - min)\n\n switch (max) {\n case red:\n hue = (green - blue) / chroma + (green < blue ? 6 : 0)\n break\n case green:\n hue = (blue - red) / chroma + 2\n break\n case blue:\n hue = (red - green) / chroma + 4\n break\n }\n\n hue /= 6\n }\n\n return new HSLColor(\n toFixedNumber(hue * 360, 2),\n toFixedNumber(saturation * 100, 2),\n toFixedNumber(lightness * 100, 2),\n this.alpha,\n )\n }\n\n clone(): ColorType {\n return new RGBColor(this.red, this.green, this.blue, this.alpha)\n }\n\n getChannelRange(channel: ColorChannel): ColorChannelRange {\n switch (channel) {\n case \"red\":\n case \"green\":\n case \"blue\":\n return { minValue: 0x0, maxValue: 0xff, step: 0x1, pageSize: 0x11 }\n case \"alpha\":\n return { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 }\n default:\n throw new Error(\"Unknown color channel: \" + channel)\n }\n }\n\n getColorFormat(): ColorFormat {\n return \"rgb\"\n }\n\n private static colorChannels: [ColorChannel, ColorChannel, ColorChannel] = [\"red\", \"green\", \"blue\"]\n\n getColorChannels(): [ColorChannel, ColorChannel, ColorChannel] {\n return RGBColor.colorChannels\n }\n}\n","import { Color } from \"./color\"\nimport { HSBColor } from \"./hsb-color\"\nimport { RGBColor } from \"./rgb-color\"\nimport type { ColorChannel, ColorChannelRange, ColorFormat, ColorType } from \"./types\"\nimport { clampValue, mod, toFixedNumber } from \"./utils\"\n\nexport const HSL_REGEX =\n /hsl\\(([-+]?\\d+(?:.\\d+)?\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d+(?:.\\d+)?%)\\)|hsla\\(([-+]?\\d+(?:.\\d+)?\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d(.\\d+)?)\\)/\n\nexport class HSLColor extends Color {\n constructor(\n private hue: number,\n private saturation: number,\n private lightness: number,\n private alpha: number,\n ) {\n super()\n }\n\n static parse(value: string): HSLColor | void {\n let m: RegExpMatchArray | null\n if ((m = value.match(HSL_REGEX))) {\n const [h, s, l, a] = (m[1] ?? m[2]).split(\",\").map((n) => Number(n.trim().replace(\"%\", \"\")))\n return new HSLColor(mod(h, 360), clampValue(s, 0, 100), clampValue(l, 0, 100), clampValue(a ?? 1, 0, 1))\n }\n }\n\n toString(format: ColorFormat | \"css\") {\n switch (format) {\n case \"hex\":\n return this.toRGB().toString(\"hex\")\n case \"hexa\":\n return this.toRGB().toString(\"hexa\")\n case \"hsl\":\n return `hsl(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.lightness, 2)}%)`\n case \"css\":\n case \"hsla\":\n return `hsla(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.lightness, 2)}%, ${\n this.alpha\n })`\n default:\n return this.toFormat(format).toString(format)\n }\n }\n toFormat(format: ColorFormat): ColorType {\n switch (format) {\n case \"hsl\":\n case \"hsla\":\n return this\n case \"hsb\":\n case \"hsba\":\n return this.toHSB()\n case \"rgb\":\n case \"rgba\":\n return this.toRGB()\n default:\n throw new Error(\"Unsupported color conversion: hsl -> \" + format)\n }\n }\n\n /**\n * Converts a HSL color to HSB.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_HSV.\n * @returns An HSBColor object.\n */\n private toHSB(): ColorType {\n let saturation = this.saturation / 100\n let lightness = this.lightness / 100\n let brightness = lightness + saturation * Math.min(lightness, 1 - lightness)\n saturation = brightness === 0 ? 0 : 2 * (1 - lightness / brightness)\n return new HSBColor(\n toFixedNumber(this.hue, 2),\n toFixedNumber(saturation * 100, 2),\n toFixedNumber(brightness * 100, 2),\n this.alpha,\n )\n }\n\n /**\n * Converts a HSL color to RGB.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative.\n * @returns An RGBColor object.\n */\n private toRGB(): ColorType {\n let hue = this.hue\n let saturation = this.saturation / 100\n let lightness = this.lightness / 100\n let a = saturation * Math.min(lightness, 1 - lightness)\n let fn = (n: number, k = (n + hue / 30) % 12) => lightness - a * Math.max(Math.min(k - 3, 9 - k, 1), -1)\n return new RGBColor(Math.round(fn(0) * 255), Math.round(fn(8) * 255), Math.round(fn(4) * 255), this.alpha)\n }\n\n clone(): ColorType {\n return new HSLColor(this.hue, this.saturation, this.lightness, this.alpha)\n }\n\n getChannelRange(channel: ColorChannel): ColorChannelRange {\n switch (channel) {\n case \"hue\":\n return { minValue: 0, maxValue: 360, step: 1, pageSize: 15 }\n case \"saturation\":\n case \"lightness\":\n return { minValue: 0, maxValue: 100, step: 1, pageSize: 10 }\n case \"alpha\":\n return { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 }\n default:\n throw new Error(\"Unknown color channel: \" + channel)\n }\n }\n\n getColorFormat(): ColorFormat {\n return \"hsl\"\n }\n\n private static colorChannels: [ColorChannel, ColorChannel, ColorChannel] = [\"hue\", \"saturation\", \"lightness\"]\n\n getColorChannels(): [ColorChannel, ColorChannel, ColorChannel] {\n return HSLColor.colorChannels\n }\n}\n","import { Color } from \"./color\"\nimport { HSLColor } from \"./hsl-color\"\nimport { RGBColor } from \"./rgb-color\"\nimport type { ColorChannel, ColorChannelRange, ColorFormat, ColorType } from \"./types\"\nimport { clampValue, mod, toFixedNumber } from \"./utils\"\n\nconst HSB_REGEX =\n /hsb\\(([-+]?\\d+(?:.\\d+)?\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d+(?:.\\d+)?%)\\)|hsba\\(([-+]?\\d+(?:.\\d+)?\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d(.\\d+)?)\\)/\n\nexport class HSBColor extends Color {\n constructor(\n private hue: number,\n private saturation: number,\n private brightness: number,\n private alpha: number,\n ) {\n super()\n }\n\n static parse(value: string): HSBColor | void {\n let m: RegExpMatchArray | null\n if ((m = value.match(HSB_REGEX))) {\n const [h, s, b, a] = (m[1] ?? m[2]).split(\",\").map((n) => Number(n.trim().replace(\"%\", \"\")))\n return new HSBColor(mod(h, 360), clampValue(s, 0, 100), clampValue(b, 0, 100), clampValue(a ?? 1, 0, 1))\n }\n }\n\n toString(format: ColorFormat | \"css\") {\n switch (format) {\n case \"css\":\n return this.toHSL().toString(\"css\")\n case \"hex\":\n return this.toRGB().toString(\"hex\")\n case \"hexa\":\n return this.toRGB().toString(\"hexa\")\n case \"hsb\":\n return `hsb(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.brightness, 2)}%)`\n case \"hsba\":\n return `hsba(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.brightness, 2)}%, ${\n this.alpha\n })`\n default:\n return this.toFormat(format).toString(format)\n }\n }\n\n toFormat(format: ColorFormat): ColorType {\n switch (format) {\n case \"hsb\":\n case \"hsba\":\n return this\n case \"hsl\":\n case \"hsla\":\n return this.toHSL()\n case \"rgb\":\n case \"rgba\":\n return this.toRGB()\n default:\n throw new Error(\"Unsupported color conversion: hsb -> \" + format)\n }\n }\n\n /**\n * Converts a HSB color to HSL.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.\n * @returns An HSLColor object.\n */\n private toHSL(): ColorType {\n let saturation = this.saturation / 100\n let brightness = this.brightness / 100\n let lightness = brightness * (1 - saturation / 2)\n saturation = lightness === 0 || lightness === 1 ? 0 : (brightness - lightness) / Math.min(lightness, 1 - lightness)\n\n return new HSLColor(\n toFixedNumber(this.hue, 2),\n toFixedNumber(saturation * 100, 2),\n toFixedNumber(lightness * 100, 2),\n this.alpha,\n )\n }\n\n /**\n * Converts a HSV color value to RGB.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.\n * @returns An RGBColor object.\n */\n private toRGB(): ColorType {\n let hue = this.hue\n let saturation = this.saturation / 100\n let brightness = this.brightness / 100\n\n let fn = (n: number, k = (n + hue / 60) % 6) =>\n brightness - saturation * brightness * Math.max(Math.min(k, 4 - k, 1), 0)\n\n return new RGBColor(Math.round(fn(5) * 255), Math.round(fn(3) * 255), Math.round(fn(1) * 255), this.alpha)\n }\n\n clone(): ColorType {\n return new HSBColor(this.hue, this.saturation, this.brightness, this.alpha)\n }\n\n getChannelRange(channel: ColorChannel): ColorChannelRange {\n switch (channel) {\n case \"hue\":\n return { minValue: 0, maxValue: 360, step: 1, pageSize: 15 }\n case \"saturation\":\n case \"brightness\":\n return { minValue: 0, maxValue: 100, step: 1, pageSize: 10 }\n case \"alpha\":\n return { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 }\n default:\n throw new Error(\"Unknown color channel: \" + channel)\n }\n }\n\n getColorFormat(): ColorFormat {\n return \"hsb\"\n }\n\n private static colorChannels: [ColorChannel, ColorChannel, ColorChannel] = [\"hue\", \"saturation\", \"brightness\"]\n\n getColorChannels(): [ColorChannel, ColorChannel, ColorChannel] {\n return HSBColor.colorChannels\n }\n}\n","const nativeColors /* @__PURE__ */ =\n \"aliceblue:f0f8ff,antiquewhite:faebd7,aqua:00ffff,aquamarine:7fffd4,azure:f0ffff,beige:f5f5dc,bisque:ffe4c4,black:000000,blanchedalmond:ffebcd,blue:0000ff,blueviolet:8a2be2,brown:a52a2a,burlywood:deb887,cadetblue:5f9ea0,chartreuse:7fff00,chocolate:d2691e,coral:ff7f50,cornflowerblue:6495ed,cornsilk:fff8dc,crimson:dc143c,cyan:00ffff,darkblue:00008b,darkcyan:008b8b,darkgoldenrod:b8860b,darkgray:a9a9a9,darkgreen:006400,darkkhaki:bdb76b,darkmagenta:8b008b,darkolivegreen:556b2f,darkorange:ff8c00,darkorchid:9932cc,darkred:8b0000,darksalmon:e9967a,darkseagreen:8fbc8f,darkslateblue:483d8b,darkslategray:2f4f4f,darkturquoise:00ced1,darkviolet:9400d3,deeppink:ff1493,deepskyblue:00bfff,dimgray:696969,dodgerblue:1e90ff,firebrick:b22222,floralwhite:fffaf0,forestgreen:228b22,fuchsia:ff00ff,gainsboro:dcdcdc,ghostwhite:f8f8ff,gold:ffd700,goldenrod:daa520,gray:808080,green:008000,greenyellow:adff2f,honeydew:f0fff0,hotpink:ff69b4,indianred:cd5c5c,indigo:4b0082,ivory:fffff0,khaki:f0e68c,lavender:e6e6fa,lavenderblush:fff0f5,lawngreen:7cfc00,lemonchiffon:fffacd,lightblue:add8e6,lightcoral:f08080,lightcyan:e0ffff,lightgoldenrodyellow:fafad2,lightgrey:d3d3d3,lightgreen:90ee90,lightpink:ffb6c1,lightsalmon:ffa07a,lightseagreen:20b2aa,lightskyblue:87cefa,lightslategray:778899,lightsteelblue:b0c4de,lightyellow:ffffe0,lime:00ff00,limegreen:32cd32,linen:faf0e6,magenta:ff00ff,maroon:800000,mediumaquamarine:66cdaa,mediumblue:0000cd,mediumorchid:ba55d3,mediumpurple:9370d8,mediumseagreen:3cb371,mediumslateblue:7b68ee,mediumspringgreen:00fa9a,mediumturquoise:48d1cc,mediumvioletred:c71585,midnightblue:191970,mintcream:f5fffa,mistyrose:ffe4e1,moccasin:ffe4b5,navajowhite:ffdead,navy:000080,oldlace:fdf5e6,olive:808000,olivedrab:6b8e23,orange:ffa500,orangered:ff4500,orchid:da70d6,palegoldenrod:eee8aa,palegreen:98fb98,paleturquoise:afeeee,palevioletred:d87093,papayawhip:ffefd5,peachpuff:ffdab9,peru:cd853f,pink:ffc0cb,plum:dda0dd,powderblue:b0e0e6,purple:800080,red:ff0000,rosybrown:bc8f8f,royalblue:4169e1,saddlebrown:8b4513,salmon:fa8072,sandybrown:f4a460,seagreen:2e8b57,seashell:fff5ee,sienna:a0522d,silver:c0c0c0,skyblue:87ceeb,slateblue:6a5acd,slategray:708090,snow:fffafa,springgreen:00ff7f,steelblue:4682b4,tan:d2b48c,teal:008080,thistle:d8bfd8,tomato:ff6347,turquoise:40e0d0,violet:ee82ee,wheat:f5deb3,white:ffffff,whitesmoke:f5f5f5,yellow:ffff00,yellowgreen:9acd32\"\n\nconst makeMap = (str: string) => {\n const map = new Map<string, string>()\n const list = str.split(\",\")\n for (let i = 0; i < list.length; i++) {\n const [key, val] = list[i].split(\":\")\n map.set(key, `#${val}`)\n }\n return map\n}\n\nexport const nativeColorMap /* @__PURE__ */ = makeMap(nativeColors)\n","import { HSBColor } from \"./hsb-color\"\nimport { HSLColor } from \"./hsl-color\"\nimport { nativeColorMap } from \"./native-color\"\nimport { RGBColor } from \"./rgb-color\"\nimport type { ColorType } from \"./types\"\n\nexport const parseColor = (value: string): ColorType => {\n if (nativeColorMap.has(value)) {\n return parseColor(nativeColorMap.get(value)!)\n }\n\n const result = RGBColor.parse(value) || HSBColor.parse(value) || HSLColor.parse(value)\n\n if (!result) {\n const error = new Error(\"Invalid color value: \" + value)\n Error.captureStackTrace?.(error, parseColor)\n throw error\n }\n\n return result\n}\n\nexport const normalizeColor = (v: string | ColorType) => {\n return typeof v === \"string\" ? parseColor(v) : v\n}\n"],"mappings":";;;;;;;;AAAO,IAAM,gBAAgB,CAAC,aAA+B,KAAc,WAAmB;AAC5F,QAAM,YAAY,sBAAsB,YAAY,OAAO,CAAC,GAAG,CAAC,CAAC;AACjE,QAAM,SAAS;AAAA,IACb,YAAY;AAAA,MACV,iBAAiB,sBAAsB,YAAY,OAAO,GAAG,CAAC,CAAC,QAAQ,MAAM,aAAa,MAAM;AAAA,IAClG;AAAA,IACA,oBAAoB;AAAA,MAClB,iBAAiB,sBAAsB,YAAY,OAAO,GAAG,CAAC,CAAC,QAAQ,MAAM,eAAe,MAAM;AAAA,MAClG,iBAAiB;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,IAAM,gBAAgB,CAAC,aAA+B,KAAc,WAAmB;AAC5F,QAAM,YAAY,sBAAsB,YAAY,OAAO,CAAC,GAAG,CAAC,CAAC;AACjE,QAAM,SAAS;AAAA,IACb,YAAY;AAAA,MACV,iBAAiB,sBAAsB,YAAY,OAAO,GAAG,CAAC,CAAC,UAAU,MAAM,eAAe,MAAM;AAAA,IACtG;AAAA,IACA,oBAAoB;AAAA,MAClB,iBAAiB,sBAAsB,YAAY,OAAO,GAAG,CAAC,CAAC,UAAU,MAAM,iBAAiB,MAAM;AAAA,MACtG,iBAAiB;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,IAAM,gBAAgB,CAAC,aAA+B,KAAc,WAAmB;AAC5F,QAAM,YAAY,sBAAs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CAAC,UAA6B;AACtD,MAAI,eAAe,IAAI,KAAK,GAAG;AAC7B,WAAO,WAAW,eAAe,IAAI,KAAK,CAAE;AAAA,EAC9C;AAEA,QAAM,SAAS,SAAS,MAAM,KAAK,KAAK,SAAS,MAAM,KAAK,KAAK,SAAS,MAAM,KAAK;AAErF,MAAI,CAAC,QAAQ;AACX,UAAM,QAAQ,IAAI,MAAM,0BAA0B,KAAK;AACvD,UAAM,oBAAoB,OAAO,UAAU;AAC3C,UAAM;AAAA,EACR;AAEA,SAAO;AACT;AAEO,IAAM,iBAAiB,CAAC,MAA0B;AACvD,SAAO,OAAO,MAAM,WAAW,WAAW,CAAC,IAAI;AACjD;","names":["value"]}
1
+ {"version":3,"sources":["../src/color-format-gradient.ts","../src/area-gradient.ts","../src/color.ts","../src/hsb-color.ts","../src/hsl-color.ts","../src/rgb-color.ts","../src/native-color.ts","../src/parse-color.ts"],"sourcesContent":["export const generateRGB_R = (orientation: [string, string], dir: boolean, zValue: number) => {\n const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`\n const result = {\n areaStyles: {\n backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,0),rgb(${zValue},255,0))`,\n },\n areaGradientStyles: {\n backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,255),rgb(${zValue},255,255))`,\n WebkitMaskImage: maskImage,\n maskImage,\n },\n }\n return result\n}\n\nexport const generateRGB_G = (orientation: [string, string], dir: boolean, zValue: number) => {\n const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`\n const result = {\n areaStyles: {\n backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},0),rgb(255,${zValue},0))`,\n },\n areaGradientStyles: {\n backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},255),rgb(255,${zValue},255))`,\n WebkitMaskImage: maskImage,\n maskImage,\n },\n }\n return result\n}\n\nexport const generateRGB_B = (orientation: [string, string], dir: boolean, zValue: number) => {\n const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`\n const result = {\n areaStyles: {\n backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,0,${zValue}),rgb(255,0,${zValue}))`,\n },\n areaGradientStyles: {\n backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,255,${zValue}),rgb(255,255,${zValue}))`,\n WebkitMaskImage: maskImage,\n maskImage,\n },\n }\n return result\n}\n\nexport const generateHSL_H = (orientation: [string, string], dir: boolean, zValue: number) => {\n const result = {\n areaStyles: {},\n areaGradientStyles: {\n background: [\n `linear-gradient(to ${\n orientation[Number(dir)]\n }, hsla(0,0%,0%,1) 0%, hsla(0,0%,0%,0) 50%, hsla(0,0%,100%,0) 50%, hsla(0,0%,100%,1) 100%)`,\n `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,50%),hsla(0,0%,50%,0))`,\n `hsl(${zValue}, 100%, 50%)`,\n ].join(\",\"),\n },\n }\n return result\n}\n\nexport const generateHSL_S = (orientation: [string, string], dir: boolean, alphaValue: number) => {\n const result = {\n areaStyles: {},\n areaGradientStyles: {\n background: [\n `linear-gradient(to ${\n orientation[Number(!dir)]\n }, hsla(0,0%,0%,${alphaValue}) 0%, hsla(0,0%,0%,0) 50%, hsla(0,0%,100%,0) 50%, hsla(0,0%,100%,${alphaValue}) 100%)`,\n `linear-gradient(to ${\n orientation[Number(dir)]\n },hsla(0,100%,50%,${alphaValue}),hsla(60,100%,50%,${alphaValue}),hsla(120,100%,50%,${alphaValue}),hsla(180,100%,50%,${alphaValue}),hsla(240,100%,50%,${alphaValue}),hsla(300,100%,50%,${alphaValue}),hsla(359,100%,50%,${alphaValue}))`,\n \"hsl(0, 0%, 50%)\",\n ].join(\",\"),\n },\n }\n return result\n}\n\nexport const generateHSL_L = (orientation: [string, string], dir: boolean, zValue: number) => {\n const result = {\n areaStyles: {},\n areaGradientStyles: {\n backgroundImage: [\n `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,${zValue}%),hsla(0,0%,${zValue}%,0))`,\n `linear-gradient(to ${\n orientation[Number(dir)]\n },hsl(0,100%,${zValue}%),hsl(60,100%,${zValue}%),hsl(120,100%,${zValue}%),hsl(180,100%,${zValue}%),hsl(240,100%,${zValue}%),hsl(300,100%,${zValue}%),hsl(360,100%,${zValue}%))`,\n ].join(\",\"),\n },\n }\n return result\n}\n\nexport const generateHSB_H = (orientation: [string, string], dir: boolean, zValue: number) => {\n const result = {\n areaStyles: {},\n areaGradientStyles: {\n background: [\n `linear-gradient(to ${orientation[Number(dir)]},hsl(0,0%,0%),hsla(0,0%,0%,0))`,\n `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,100%),hsla(0,0%,100%,0))`,\n `hsl(${zValue}, 100%, 50%)`,\n ].join(\",\"),\n },\n }\n return result\n}\n\nexport const generateHSB_S = (orientation: [string, string], dir: boolean, alphaValue: number) => {\n const result = {\n areaStyles: {},\n areaGradientStyles: {\n background: [\n `linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,0%,${alphaValue}),hsla(0,0%,0%,0))`,\n `linear-gradient(to ${\n orientation[Number(dir)]\n },hsla(0,100%,50%,${alphaValue}),hsla(60,100%,50%,${alphaValue}),hsla(120,100%,50%,${alphaValue}),hsla(180,100%,50%,${alphaValue}),hsla(240,100%,50%,${alphaValue}),hsla(300,100%,50%,${alphaValue}),hsla(359,100%,50%,${alphaValue}))`,\n `linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,0%),hsl(0,0%,100%))`,\n ].join(\",\"),\n },\n }\n return result\n}\n\nexport const generateHSB_B = (orientation: [string, string], dir: boolean, alphaValue: number) => {\n const result = {\n areaStyles: {},\n areaGradientStyles: {\n background: [\n `linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,100%,${alphaValue}),hsla(0,0%,100%,0))`,\n `linear-gradient(to ${\n orientation[Number(dir)]\n },hsla(0,100%,50%,${alphaValue}),hsla(60,100%,50%,${alphaValue}),hsla(120,100%,50%,${alphaValue}),hsla(180,100%,50%,${alphaValue}),hsla(240,100%,50%,${alphaValue}),hsla(300,100%,50%,${alphaValue}),hsla(359,100%,50%,${alphaValue}))`,\n \"#000\",\n ].join(\",\"),\n },\n }\n return result\n}\n","import type { Color } from \"./color\"\nimport {\n generateRGB_R,\n generateRGB_G,\n generateRGB_B,\n generateHSL_H,\n generateHSB_H,\n generateHSL_S,\n generateHSB_S,\n generateHSB_B,\n generateHSL_L,\n} from \"./color-format-gradient\"\nimport type { ColorChannel } from \"./types\"\n\ninterface GradientOptions {\n xChannel: ColorChannel\n yChannel: ColorChannel\n dir: \"rtl\" | \"ltr\"\n}\n\ninterface GradientStyles {\n areaStyles: Record<string, string>\n areaGradientStyles: Record<string, string>\n}\n\nexport function getColorAreaGradient(color: Color, options: GradientOptions): GradientStyles {\n const { xChannel, yChannel, dir: dirProp } = options\n\n const { zChannel } = color.getColorAxes({ xChannel, yChannel })\n const zValue = color.getChannelValue(zChannel)\n\n const { minValue: zMin, maxValue: zMax } = color.getChannelRange(zChannel)\n const orientation: [string, string] = [\"top\", dirProp === \"rtl\" ? \"left\" : \"right\"]\n\n let dir = false\n\n let background = { areaStyles: {}, areaGradientStyles: {} }\n\n let alphaValue = (zValue - zMin) / (zMax - zMin)\n let isHSL = color.getFormat() === \"hsl\"\n\n switch (zChannel) {\n case \"red\": {\n dir = xChannel === \"green\"\n background = generateRGB_R(orientation, dir, zValue)\n break\n }\n\n case \"green\": {\n dir = xChannel === \"red\"\n background = generateRGB_G(orientation, dir, zValue)\n break\n }\n\n case \"blue\": {\n dir = xChannel === \"red\"\n background = generateRGB_B(orientation, dir, zValue)\n break\n }\n\n case \"hue\": {\n dir = xChannel !== \"saturation\"\n if (isHSL) {\n background = generateHSL_H(orientation, dir, zValue)\n } else {\n background = generateHSB_H(orientation, dir, zValue)\n }\n break\n }\n\n case \"saturation\": {\n dir = xChannel === \"hue\"\n if (isHSL) {\n background = generateHSL_S(orientation, dir, alphaValue)\n } else {\n background = generateHSB_S(orientation, dir, alphaValue)\n }\n break\n }\n\n case \"brightness\": {\n dir = xChannel === \"hue\"\n background = generateHSB_B(orientation, dir, alphaValue)\n break\n }\n\n case \"lightness\": {\n dir = xChannel === \"hue\"\n background = generateHSL_L(orientation, dir, zValue)\n break\n }\n }\n\n return background\n}\n","import { clampValue, getPercentValue, getValuePercent, snapValueToStep } from \"@zag-js/numeric-range\"\nimport type { Color2DAxes, ColorAxes, ColorChannel, ColorChannelRange, ColorFormat, ColorType } from \"./types\"\n\nconst isEqualObject = (a: Record<string, number>, b: Record<string, number>): boolean => {\n if (Object.keys(a).length !== Object.keys(b).length) return false\n for (let key in a) if (a[key] !== b[key]) return false\n return true\n}\n\nexport abstract class Color implements ColorType {\n abstract toFormat(format: ColorFormat): ColorType\n abstract toJSON(): Record<string, number>\n abstract toString(format: ColorFormat | \"css\"): string\n abstract clone(): ColorType\n abstract getChannelRange(channel: ColorChannel): ColorChannelRange\n abstract getFormat(): ColorFormat\n abstract getChannels(): [ColorChannel, ColorChannel, ColorChannel]\n\n toHexInt(): number {\n return this.toFormat(\"rgb\").toHexInt()\n }\n\n getChannelValue(channel: ColorChannel): number {\n if (channel in this) return this[channel]\n throw new Error(\"Unsupported color channel: \" + channel)\n }\n\n getChannelValuePercent(channel: ColorChannel, valueToCheck?: number): number {\n const value = valueToCheck ?? this.getChannelValue(channel)\n const { minValue, maxValue } = this.getChannelRange(channel)\n return getValuePercent(value, minValue, maxValue)\n }\n\n getChannelPercentValue(channel: ColorChannel, percentToCheck: number): number {\n const { minValue, maxValue, step } = this.getChannelRange(channel)\n const percentValue = getPercentValue(percentToCheck, minValue, maxValue, step)\n return snapValueToStep(percentValue, minValue, maxValue, step)\n }\n\n withChannelValue(channel: ColorChannel, value: number): ColorType {\n if (channel in this) {\n let clone = this.clone()\n clone[channel] = value\n return clone\n }\n\n throw new Error(\"Unsupported color channel: \" + channel)\n }\n\n getColorAxes(xyChannels: Color2DAxes): ColorAxes {\n let { xChannel, yChannel } = xyChannels\n let xCh = xChannel || this.getChannels().find((c) => c !== yChannel)\n let yCh = yChannel || this.getChannels().find((c) => c !== xCh)\n let zCh = this.getChannels().find((c) => c !== xCh && c !== yCh)\n return { xChannel: xCh!, yChannel: yCh!, zChannel: zCh! }\n }\n\n incrementChannel(channel: ColorChannel, stepSize: number): ColorType {\n const { minValue, maxValue, step } = this.getChannelRange(channel)\n const value = snapValueToStep(\n clampValue(this.getChannelValue(channel) + stepSize, minValue, maxValue),\n minValue,\n maxValue,\n step,\n )\n return this.withChannelValue(channel, value)\n }\n\n decrementChannel(channel: ColorChannel, stepSize: number): ColorType {\n return this.incrementChannel(channel, -stepSize)\n }\n\n isEqual(color: ColorType): boolean {\n const isSame = isEqualObject(this.toJSON(), color.toJSON())\n return isSame && this.getChannelValue(\"alpha\") === color.getChannelValue(\"alpha\")\n }\n}\n","import { mod, clampValue, toFixedNumber } from \"@zag-js/numeric-range\"\nimport { Color } from \"./color\"\nimport { HSLColor } from \"./hsl-color\"\nimport { RGBColor } from \"./rgb-color\"\nimport type { ColorChannel, ColorChannelRange, ColorFormat, ColorType } from \"./types\"\n\nconst HSB_REGEX =\n /hsb\\(([-+]?\\d+(?:.\\d+)?\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d+(?:.\\d+)?%)\\)|hsba\\(([-+]?\\d+(?:.\\d+)?\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d(.\\d+)?)\\)/\n\nexport class HSBColor extends Color {\n constructor(\n private hue: number,\n private saturation: number,\n private brightness: number,\n private alpha: number,\n ) {\n super()\n }\n\n static parse(value: string): HSBColor | void {\n let m: RegExpMatchArray | null\n if ((m = value.match(HSB_REGEX))) {\n const [h, s, b, a] = (m[1] ?? m[2]).split(\",\").map((n) => Number(n.trim().replace(\"%\", \"\")))\n return new HSBColor(mod(h, 360), clampValue(s, 0, 100), clampValue(b, 0, 100), clampValue(a ?? 1, 0, 1))\n }\n }\n\n toString(format: ColorFormat | \"css\") {\n switch (format) {\n case \"css\":\n return this.toHSL().toString(\"css\")\n case \"hex\":\n return this.toRGB().toString(\"hex\")\n case \"hexa\":\n return this.toRGB().toString(\"hexa\")\n case \"hsb\":\n return `hsb(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.brightness, 2)}%)`\n case \"hsba\":\n return `hsba(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.brightness, 2)}%, ${\n this.alpha\n })`\n default:\n return this.toFormat(format).toString(format)\n }\n }\n\n toFormat(format: ColorFormat): ColorType {\n switch (format) {\n case \"hsb\":\n case \"hsba\":\n return this\n case \"hsl\":\n case \"hsla\":\n return this.toHSL()\n case \"rgb\":\n case \"rgba\":\n return this.toRGB()\n default:\n throw new Error(\"Unsupported color conversion: hsb -> \" + format)\n }\n }\n\n /**\n * Converts a HSB color to HSL.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.\n * @returns An HSLColor object.\n */\n private toHSL(): ColorType {\n let saturation = this.saturation / 100\n let brightness = this.brightness / 100\n let lightness = brightness * (1 - saturation / 2)\n saturation = lightness === 0 || lightness === 1 ? 0 : (brightness - lightness) / Math.min(lightness, 1 - lightness)\n\n return new HSLColor(\n toFixedNumber(this.hue, 2),\n toFixedNumber(saturation * 100, 2),\n toFixedNumber(lightness * 100, 2),\n toFixedNumber(this.alpha, 2),\n )\n }\n\n /**\n * Converts a HSV color value to RGB.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.\n * @returns An RGBColor object.\n */\n private toRGB(): ColorType {\n let hue = this.hue\n let saturation = this.saturation / 100\n let brightness = this.brightness / 100\n\n let fn = (n: number, k = (n + hue / 60) % 6) =>\n brightness - saturation * brightness * Math.max(Math.min(k, 4 - k, 1), 0)\n\n return new RGBColor(\n Math.round(fn(5) * 255),\n Math.round(fn(3) * 255),\n Math.round(fn(1) * 255),\n toFixedNumber(this.alpha, 2),\n )\n }\n\n clone(): ColorType {\n return new HSBColor(this.hue, this.saturation, this.brightness, this.alpha)\n }\n\n getChannelRange(channel: ColorChannel): ColorChannelRange {\n switch (channel) {\n case \"hue\":\n return { minValue: 0, maxValue: 360, step: 1, pageSize: 15 }\n case \"saturation\":\n case \"brightness\":\n return { minValue: 0, maxValue: 100, step: 1, pageSize: 10 }\n case \"alpha\":\n return { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 }\n default:\n throw new Error(\"Unknown color channel: \" + channel)\n }\n }\n\n toJSON(): Record<string, number> {\n return { h: this.hue, s: this.saturation, b: this.brightness }\n }\n\n getFormat(): ColorFormat {\n return \"hsb\"\n }\n\n private static colorChannels: [ColorChannel, ColorChannel, ColorChannel] = [\"hue\", \"saturation\", \"brightness\"]\n\n getChannels(): [ColorChannel, ColorChannel, ColorChannel] {\n return HSBColor.colorChannels\n }\n}\n","import { clampValue, mod, toFixedNumber } from \"@zag-js/numeric-range\"\nimport { Color } from \"./color\"\nimport { HSBColor } from \"./hsb-color\"\nimport { RGBColor } from \"./rgb-color\"\nimport type { ColorChannel, ColorChannelRange, ColorFormat, ColorType } from \"./types\"\n\nexport const HSL_REGEX =\n /hsl\\(([-+]?\\d+(?:.\\d+)?\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d+(?:.\\d+)?%)\\)|hsla\\(([-+]?\\d+(?:.\\d+)?\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d(.\\d+)?)\\)/\n\nexport class HSLColor extends Color {\n constructor(\n private hue: number,\n private saturation: number,\n private lightness: number,\n private alpha: number,\n ) {\n super()\n }\n\n static parse(value: string): HSLColor | void {\n let m: RegExpMatchArray | null\n if ((m = value.match(HSL_REGEX))) {\n const [h, s, l, a] = (m[1] ?? m[2]).split(\",\").map((n) => Number(n.trim().replace(\"%\", \"\")))\n return new HSLColor(mod(h, 360), clampValue(s, 0, 100), clampValue(l, 0, 100), clampValue(a ?? 1, 0, 1))\n }\n }\n\n toString(format: ColorFormat | \"css\") {\n switch (format) {\n case \"hex\":\n return this.toRGB().toString(\"hex\")\n case \"hexa\":\n return this.toRGB().toString(\"hexa\")\n case \"hsl\":\n return `hsl(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.lightness, 2)}%)`\n case \"css\":\n case \"hsla\":\n return `hsla(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.lightness, 2)}%, ${\n this.alpha\n })`\n default:\n return this.toFormat(format).toString(format)\n }\n }\n toFormat(format: ColorFormat): ColorType {\n switch (format) {\n case \"hsl\":\n case \"hsla\":\n return this\n case \"hsb\":\n case \"hsba\":\n return this.toHSB()\n case \"rgb\":\n case \"rgba\":\n return this.toRGB()\n default:\n throw new Error(\"Unsupported color conversion: hsl -> \" + format)\n }\n }\n\n /**\n * Converts a HSL color to HSB.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_HSV.\n * @returns An HSBColor object.\n */\n private toHSB(): ColorType {\n let saturation = this.saturation / 100\n let lightness = this.lightness / 100\n let brightness = lightness + saturation * Math.min(lightness, 1 - lightness)\n saturation = brightness === 0 ? 0 : 2 * (1 - lightness / brightness)\n return new HSBColor(\n toFixedNumber(this.hue, 2),\n toFixedNumber(saturation * 100, 2),\n toFixedNumber(brightness * 100, 2),\n toFixedNumber(this.alpha, 2),\n )\n }\n\n /**\n * Converts a HSL color to RGB.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative.\n * @returns An RGBColor object.\n */\n private toRGB(): ColorType {\n let hue = this.hue\n let saturation = this.saturation / 100\n let lightness = this.lightness / 100\n let a = saturation * Math.min(lightness, 1 - lightness)\n let fn = (n: number, k = (n + hue / 30) % 12) => lightness - a * Math.max(Math.min(k - 3, 9 - k, 1), -1)\n return new RGBColor(\n Math.round(fn(0) * 255),\n Math.round(fn(8) * 255),\n Math.round(fn(4) * 255),\n toFixedNumber(this.alpha, 2),\n )\n }\n\n clone(): ColorType {\n return new HSLColor(this.hue, this.saturation, this.lightness, this.alpha)\n }\n\n getChannelRange(channel: ColorChannel): ColorChannelRange {\n switch (channel) {\n case \"hue\":\n return { minValue: 0, maxValue: 360, step: 1, pageSize: 15 }\n case \"saturation\":\n case \"lightness\":\n return { minValue: 0, maxValue: 100, step: 1, pageSize: 10 }\n case \"alpha\":\n return { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 }\n default:\n throw new Error(\"Unknown color channel: \" + channel)\n }\n }\n\n toJSON(): Record<string, number> {\n return { h: this.hue, s: this.saturation, l: this.lightness }\n }\n\n getFormat(): ColorFormat {\n return \"hsl\"\n }\n\n private static colorChannels: [ColorChannel, ColorChannel, ColorChannel] = [\"hue\", \"saturation\", \"lightness\"]\n\n getChannels(): [ColorChannel, ColorChannel, ColorChannel] {\n return HSLColor.colorChannels\n }\n}\n","import { clampValue, toFixedNumber } from \"@zag-js/numeric-range\"\nimport { Color } from \"./color\"\nimport { HSBColor } from \"./hsb-color\"\nimport { HSLColor } from \"./hsl-color\"\nimport type { ColorChannel, ColorChannelRange, ColorFormat, ColorType } from \"./types\"\n\nexport class RGBColor extends Color {\n constructor(\n private red: number,\n private green: number,\n private blue: number,\n private alpha: number,\n ) {\n super()\n }\n\n static parse(value: string) {\n let colors: (number | undefined)[] = []\n\n // matching #rgb, #rgba, #rrggbb, #rrggbbaa\n if (/^#[\\da-f]+$/i.test(value) && [4, 5, 7, 9].includes(value.length)) {\n const values = (value.length < 6 ? value.replace(/[^#]/gi, \"$&$&\") : value).slice(1).split(\"\")\n while (values.length > 0) {\n colors.push(parseInt(values.splice(0, 2).join(\"\"), 16))\n }\n colors[3] = colors[3] !== undefined ? colors[3] / 255 : undefined\n }\n\n // matching rgb(rrr, ggg, bbb), rgba(rrr, ggg, bbb, 0.a)\n const match = value.match(/^rgba?\\((.*)\\)$/)\n\n if (match?.[1]) {\n colors = match[1]\n .split(\",\")\n .map((value) => Number(value.trim()))\n .map((num, i) => clampValue(num, 0, i < 3 ? 255 : 1))\n }\n\n //@ts-expect-error\n return colors.length < 3 ? undefined : new RGBColor(colors[0], colors[1], colors[2], colors[3] ?? 1)\n }\n\n toString(format: ColorFormat | \"css\") {\n switch (format) {\n case \"hex\":\n return (\n \"#\" +\n (\n this.red.toString(16).padStart(2, \"0\") +\n this.green.toString(16).padStart(2, \"0\") +\n this.blue.toString(16).padStart(2, \"0\")\n ).toUpperCase()\n )\n case \"hexa\":\n return (\n \"#\" +\n (\n this.red.toString(16).padStart(2, \"0\") +\n this.green.toString(16).padStart(2, \"0\") +\n this.blue.toString(16).padStart(2, \"0\") +\n Math.round(this.alpha * 255)\n .toString(16)\n .padStart(2, \"0\")\n ).toUpperCase()\n )\n case \"rgb\":\n return `rgb(${this.red}, ${this.green}, ${this.blue})`\n case \"css\":\n case \"rgba\":\n return `rgba(${this.red}, ${this.green}, ${this.blue}, ${this.alpha})`\n default:\n return this.toFormat(format).toString(format)\n }\n }\n\n toFormat(format: ColorFormat): ColorType {\n switch (format) {\n case \"hex\":\n case \"hexa\":\n case \"rgb\":\n case \"rgba\":\n return this\n case \"hsb\":\n case \"hsba\":\n return this.toHSB()\n case \"hsl\":\n case \"hsla\":\n return this.toHSL()\n default:\n throw new Error(\"Unsupported color conversion: rgb -> \" + format)\n }\n }\n\n toHexInt(): number {\n return (this.red << 16) | (this.green << 8) | this.blue\n }\n\n /**\n * Converts an RGB color value to HSB.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.\n * @returns An HSBColor object.\n */\n private toHSB(): ColorType {\n const red = this.red / 255\n const green = this.green / 255\n const blue = this.blue / 255\n const min = Math.min(red, green, blue)\n const brightness = Math.max(red, green, blue)\n const chroma = brightness - min\n const saturation = brightness === 0 ? 0 : chroma / brightness\n let hue = 0 // achromatic\n\n if (chroma !== 0) {\n switch (brightness) {\n case red:\n hue = (green - blue) / chroma + (green < blue ? 6 : 0)\n break\n case green:\n hue = (blue - red) / chroma + 2\n break\n case blue:\n hue = (red - green) / chroma + 4\n break\n }\n\n hue /= 6\n }\n\n return new HSBColor(\n toFixedNumber(hue * 360, 2),\n toFixedNumber(saturation * 100, 2),\n toFixedNumber(brightness * 100, 2),\n toFixedNumber(this.alpha, 2),\n )\n }\n\n /**\n * Converts an RGB color value to HSL.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.\n * @returns An HSLColor object.\n */\n private toHSL(): ColorType {\n const red = this.red / 255\n const green = this.green / 255\n const blue = this.blue / 255\n const min = Math.min(red, green, blue)\n const max = Math.max(red, green, blue)\n const lightness = (max + min) / 2\n const chroma = max - min\n\n let hue = -1\n let saturation = -1\n\n if (chroma === 0) {\n hue = saturation = 0 // achromatic\n } else {\n saturation = chroma / (lightness < 0.5 ? max + min : 2 - max - min)\n\n switch (max) {\n case red:\n hue = (green - blue) / chroma + (green < blue ? 6 : 0)\n break\n case green:\n hue = (blue - red) / chroma + 2\n break\n case blue:\n hue = (red - green) / chroma + 4\n break\n }\n\n hue /= 6\n }\n\n return new HSLColor(\n toFixedNumber(hue * 360, 2),\n toFixedNumber(saturation * 100, 2),\n toFixedNumber(lightness * 100, 2),\n toFixedNumber(this.alpha, 2),\n )\n }\n\n clone(): ColorType {\n return new RGBColor(this.red, this.green, this.blue, this.alpha)\n }\n\n getChannelRange(channel: ColorChannel): ColorChannelRange {\n switch (channel) {\n case \"red\":\n case \"green\":\n case \"blue\":\n return { minValue: 0x0, maxValue: 0xff, step: 0x1, pageSize: 0x11 }\n case \"alpha\":\n return { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 }\n default:\n throw new Error(\"Unknown color channel: \" + channel)\n }\n }\n\n toJSON(): Record<string, number> {\n return { r: this.red, g: this.green, b: this.blue }\n }\n\n getFormat(): ColorFormat {\n return \"rgb\"\n }\n\n private static colorChannels: [ColorChannel, ColorChannel, ColorChannel] = [\"red\", \"green\", \"blue\"]\n\n getChannels(): [ColorChannel, ColorChannel, ColorChannel] {\n return RGBColor.colorChannels\n }\n}\n","const nativeColors /* @__PURE__ */ =\n \"aliceblue:f0f8ff,antiquewhite:faebd7,aqua:00ffff,aquamarine:7fffd4,azure:f0ffff,beige:f5f5dc,bisque:ffe4c4,black:000000,blanchedalmond:ffebcd,blue:0000ff,blueviolet:8a2be2,brown:a52a2a,burlywood:deb887,cadetblue:5f9ea0,chartreuse:7fff00,chocolate:d2691e,coral:ff7f50,cornflowerblue:6495ed,cornsilk:fff8dc,crimson:dc143c,cyan:00ffff,darkblue:00008b,darkcyan:008b8b,darkgoldenrod:b8860b,darkgray:a9a9a9,darkgreen:006400,darkkhaki:bdb76b,darkmagenta:8b008b,darkolivegreen:556b2f,darkorange:ff8c00,darkorchid:9932cc,darkred:8b0000,darksalmon:e9967a,darkseagreen:8fbc8f,darkslateblue:483d8b,darkslategray:2f4f4f,darkturquoise:00ced1,darkviolet:9400d3,deeppink:ff1493,deepskyblue:00bfff,dimgray:696969,dodgerblue:1e90ff,firebrick:b22222,floralwhite:fffaf0,forestgreen:228b22,fuchsia:ff00ff,gainsboro:dcdcdc,ghostwhite:f8f8ff,gold:ffd700,goldenrod:daa520,gray:808080,green:008000,greenyellow:adff2f,honeydew:f0fff0,hotpink:ff69b4,indianred:cd5c5c,indigo:4b0082,ivory:fffff0,khaki:f0e68c,lavender:e6e6fa,lavenderblush:fff0f5,lawngreen:7cfc00,lemonchiffon:fffacd,lightblue:add8e6,lightcoral:f08080,lightcyan:e0ffff,lightgoldenrodyellow:fafad2,lightgrey:d3d3d3,lightgreen:90ee90,lightpink:ffb6c1,lightsalmon:ffa07a,lightseagreen:20b2aa,lightskyblue:87cefa,lightslategray:778899,lightsteelblue:b0c4de,lightyellow:ffffe0,lime:00ff00,limegreen:32cd32,linen:faf0e6,magenta:ff00ff,maroon:800000,mediumaquamarine:66cdaa,mediumblue:0000cd,mediumorchid:ba55d3,mediumpurple:9370d8,mediumseagreen:3cb371,mediumslateblue:7b68ee,mediumspringgreen:00fa9a,mediumturquoise:48d1cc,mediumvioletred:c71585,midnightblue:191970,mintcream:f5fffa,mistyrose:ffe4e1,moccasin:ffe4b5,navajowhite:ffdead,navy:000080,oldlace:fdf5e6,olive:808000,olivedrab:6b8e23,orange:ffa500,orangered:ff4500,orchid:da70d6,palegoldenrod:eee8aa,palegreen:98fb98,paleturquoise:afeeee,palevioletred:d87093,papayawhip:ffefd5,peachpuff:ffdab9,peru:cd853f,pink:ffc0cb,plum:dda0dd,powderblue:b0e0e6,purple:800080,red:ff0000,rosybrown:bc8f8f,royalblue:4169e1,saddlebrown:8b4513,salmon:fa8072,sandybrown:f4a460,seagreen:2e8b57,seashell:fff5ee,sienna:a0522d,silver:c0c0c0,skyblue:87ceeb,slateblue:6a5acd,slategray:708090,snow:fffafa,springgreen:00ff7f,steelblue:4682b4,tan:d2b48c,teal:008080,thistle:d8bfd8,tomato:ff6347,turquoise:40e0d0,violet:ee82ee,wheat:f5deb3,white:ffffff,whitesmoke:f5f5f5,yellow:ffff00,yellowgreen:9acd32\"\n\nconst makeMap = (str: string) => {\n const map = new Map<string, string>()\n const list = str.split(\",\")\n for (let i = 0; i < list.length; i++) {\n const [key, val] = list[i].split(\":\")\n map.set(key, `#${val}`)\n }\n return map\n}\n\nexport const nativeColorMap /* @__PURE__ */ = makeMap(nativeColors)\n","import { HSBColor } from \"./hsb-color\"\nimport { HSLColor } from \"./hsl-color\"\nimport { nativeColorMap } from \"./native-color\"\nimport { RGBColor } from \"./rgb-color\"\nimport type { ColorType } from \"./types\"\n\nexport const parseColor = (value: string): ColorType => {\n if (nativeColorMap.has(value)) {\n return parseColor(nativeColorMap.get(value)!)\n }\n\n const result = RGBColor.parse(value) || HSBColor.parse(value) || HSLColor.parse(value)\n\n if (!result) {\n const error = new Error(\"Invalid color value: \" + value)\n Error.captureStackTrace?.(error, parseColor)\n throw error\n }\n\n return result\n}\n\nexport const normalizeColor = (v: string | ColorType) => {\n return typeof v === \"string\" ? parseColor(v) : v\n}\n"],"mappings":";;;;;;;;AAAO,IAAM,gBAAgB,CAAC,aAA+B,KAAc,WAAmB;AAC5F,QAAM,YAAY,sBAAsB,YAAY,OAAO,CAAC,GAAG,CAAC,CAAC;AACjE,QAAM,SAAS;AAAA,IACb,YAAY;AAAA,MACV,iBAAiB,sBAAsB,YAAY,OAAO,GAAG,CAAC,CAAC,QAAQ,MAAM,aAAa,MAAM;AAAA,IAClG;AAAA,IACA,oBAAoB;AAAA,MAClB,iBAAiB,sBAAsB,YAAY,OAAO,GAAG,CAAC,CAAC,QAAQ,MAAM,eAAe,MAAM;AAAA,MAClG,iBAAiB;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,IAAM,gBAAgB,CAAC,aAA+B,KAAc,WAAmB;AAC5F,QAAM,YAAY,sBAAsB,YAAY,OAAO,CAAC,GAAG,CAAC,CAAC;AACjE,QAAM,SAAS;AAAA,IACb,YAAY;AAAA,MACV,iBAAiB,sBAAsB,YAAY,OAAO,GAAG,CAAC,CAAC,UAAU,MAAM,eAAe,MAAM;AAAA,IACtG;AAAA,IACA,oBAAoB;AAAA,MAClB,iBAAiB,sBAAsB,YAAY,OAAO,GAAG,CAAC,CAAC,UAAU,MAAM,iBAAiB,MAAM;AAAA,MACtG,iBAAiB;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,IAAM,gBAAgB,CAAC,aAA+B,KAAc,WAAmB;AAC5F,QAAM,YAAY,sBAAsB,YAAY,OAAO,CAAC,GAAG,CAAC,CAAC;AACjE,QAAM,SAAS;AAAA,IACb,YAAY;AAAA,MACV,iBAAiB,sBAAsB,YAAY,OAAO,GAAG,CAAC,CAAC,YAAY,MAAM,eAAe,MAAM;AAAA,IACxG;AAAA,IACA,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A,QAAM,SAAS,SAAS,MAAM,KAAK,KAAK,SAAS,MAAM,KAAK,KAAK,SAAS,MAAM,KAAK;AAErF,MAAI,CAAC,QAAQ;AACX,UAAM,QAAQ,IAAI,MAAM,0BAA0B,KAAK;AACvD,UAAM,oBAAoB,OAAO,UAAU;AAC3C,UAAM;AAAA,EACR;AAEA,SAAO;AACT;AAEO,IAAM,iBAAiB,CAAC,MAA0B;AACvD,SAAO,OAAO,MAAM,WAAW,WAAW,CAAC,IAAI;AACjD;","names":["mod","clampValue","toFixedNumber","clampValue","toFixedNumber","clampValue","value","clampValue","clampValue","toFixedNumber","mod","clampValue","toFixedNumber"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/color-utils",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "Color utilities for zag.js",
5
5
  "keywords": [
6
6
  "js",
@@ -24,6 +24,9 @@
24
24
  "url": "https://github.com/chakra-ui/zag/issues"
25
25
  },
26
26
  "clean-package": "../../../clean-package.config.json",
27
+ "dependencies": {
28
+ "@zag-js/numeric-range": "0.24.0"
29
+ },
27
30
  "devDependencies": {
28
31
  "clean-package": "2.2.0"
29
32
  },
@@ -26,7 +26,7 @@ interface GradientStyles {
26
26
  export function getColorAreaGradient(color: Color, options: GradientOptions): GradientStyles {
27
27
  const { xChannel, yChannel, dir: dirProp } = options
28
28
 
29
- const { zChannel } = color.getColorSpaceAxes({ xChannel, yChannel })
29
+ const { zChannel } = color.getColorAxes({ xChannel, yChannel })
30
30
  const zValue = color.getChannelValue(zChannel)
31
31
 
32
32
  const { minValue: zMin, maxValue: zMax } = color.getChannelRange(zChannel)
@@ -37,7 +37,7 @@ export function getColorAreaGradient(color: Color, options: GradientOptions): Gr
37
37
  let background = { areaStyles: {}, areaGradientStyles: {} }
38
38
 
39
39
  let alphaValue = (zValue - zMin) / (zMax - zMin)
40
- let isHSL = color.getColorFormat() === "hsl"
40
+ let isHSL = color.getFormat() === "hsl"
41
41
 
42
42
  switch (zChannel) {
43
43
  case "red": {
package/src/color.ts CHANGED
@@ -1,29 +1,42 @@
1
- import type { ColorType, ColorFormat, ColorChannel, ColorChannelRange, ColorAxes } from "./types"
1
+ import { clampValue, getPercentValue, getValuePercent, snapValueToStep } from "@zag-js/numeric-range"
2
+ import type { Color2DAxes, ColorAxes, ColorChannel, ColorChannelRange, ColorFormat, ColorType } from "./types"
3
+
4
+ const isEqualObject = (a: Record<string, number>, b: Record<string, number>): boolean => {
5
+ if (Object.keys(a).length !== Object.keys(b).length) return false
6
+ for (let key in a) if (a[key] !== b[key]) return false
7
+ return true
8
+ }
2
9
 
3
10
  export abstract class Color implements ColorType {
4
11
  abstract toFormat(format: ColorFormat): ColorType
12
+ abstract toJSON(): Record<string, number>
5
13
  abstract toString(format: ColorFormat | "css"): string
6
14
  abstract clone(): ColorType
7
15
  abstract getChannelRange(channel: ColorChannel): ColorChannelRange
8
- abstract getColorFormat(): ColorFormat
9
- abstract getColorChannels(): [ColorChannel, ColorChannel, ColorChannel]
10
-
11
- hasColorChannel(channel: ColorChannel): boolean {
12
- return this.getColorChannels().includes(channel)
13
- }
16
+ abstract getFormat(): ColorFormat
17
+ abstract getChannels(): [ColorChannel, ColorChannel, ColorChannel]
14
18
 
15
19
  toHexInt(): number {
16
20
  return this.toFormat("rgb").toHexInt()
17
21
  }
18
22
 
19
23
  getChannelValue(channel: ColorChannel): number {
20
- if (channel in this) {
21
- return this[channel]
22
- }
23
-
24
+ if (channel in this) return this[channel]
24
25
  throw new Error("Unsupported color channel: " + channel)
25
26
  }
26
27
 
28
+ getChannelValuePercent(channel: ColorChannel, valueToCheck?: number): number {
29
+ const value = valueToCheck ?? this.getChannelValue(channel)
30
+ const { minValue, maxValue } = this.getChannelRange(channel)
31
+ return getValuePercent(value, minValue, maxValue)
32
+ }
33
+
34
+ getChannelPercentValue(channel: ColorChannel, percentToCheck: number): number {
35
+ const { minValue, maxValue, step } = this.getChannelRange(channel)
36
+ const percentValue = getPercentValue(percentToCheck, minValue, maxValue, step)
37
+ return snapValueToStep(percentValue, minValue, maxValue, step)
38
+ }
39
+
27
40
  withChannelValue(channel: ColorChannel, value: number): ColorType {
28
41
  if (channel in this) {
29
42
  let clone = this.clone()
@@ -34,15 +47,31 @@ export abstract class Color implements ColorType {
34
47
  throw new Error("Unsupported color channel: " + channel)
35
48
  }
36
49
 
37
- getColorSpaceAxes(xyChannels: { xChannel?: ColorChannel; yChannel?: ColorChannel }): ColorAxes {
50
+ getColorAxes(xyChannels: Color2DAxes): ColorAxes {
38
51
  let { xChannel, yChannel } = xyChannels
39
- let xCh = xChannel || this.getColorChannels().find((c) => c !== yChannel)
40
- let yCh = yChannel || this.getColorChannels().find((c) => c !== xCh)
41
- let zCh = this.getColorChannels().find((c) => c !== xCh && c !== yCh)
52
+ let xCh = xChannel || this.getChannels().find((c) => c !== yChannel)
53
+ let yCh = yChannel || this.getChannels().find((c) => c !== xCh)
54
+ let zCh = this.getChannels().find((c) => c !== xCh && c !== yCh)
42
55
  return { xChannel: xCh!, yChannel: yCh!, zChannel: zCh! }
43
56
  }
44
57
 
58
+ incrementChannel(channel: ColorChannel, stepSize: number): ColorType {
59
+ const { minValue, maxValue, step } = this.getChannelRange(channel)
60
+ const value = snapValueToStep(
61
+ clampValue(this.getChannelValue(channel) + stepSize, minValue, maxValue),
62
+ minValue,
63
+ maxValue,
64
+ step,
65
+ )
66
+ return this.withChannelValue(channel, value)
67
+ }
68
+
69
+ decrementChannel(channel: ColorChannel, stepSize: number): ColorType {
70
+ return this.incrementChannel(channel, -stepSize)
71
+ }
72
+
45
73
  isEqual(color: ColorType): boolean {
46
- return this.toHexInt() === color.toHexInt() && this.getChannelValue("alpha") === color.getChannelValue("alpha")
74
+ const isSame = isEqualObject(this.toJSON(), color.toJSON())
75
+ return isSame && this.getChannelValue("alpha") === color.getChannelValue("alpha")
47
76
  }
48
77
  }
package/src/hsb-color.ts CHANGED
@@ -1,8 +1,8 @@
1
+ import { mod, clampValue, toFixedNumber } from "@zag-js/numeric-range"
1
2
  import { Color } from "./color"
2
3
  import { HSLColor } from "./hsl-color"
3
4
  import { RGBColor } from "./rgb-color"
4
5
  import type { ColorChannel, ColorChannelRange, ColorFormat, ColorType } from "./types"
5
- import { clampValue, mod, toFixedNumber } from "./utils"
6
6
 
7
7
  const HSB_REGEX =
8
8
  /hsb\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%)\)|hsba\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d(.\d+)?)\)/
@@ -75,7 +75,7 @@ export class HSBColor extends Color {
75
75
  toFixedNumber(this.hue, 2),
76
76
  toFixedNumber(saturation * 100, 2),
77
77
  toFixedNumber(lightness * 100, 2),
78
- this.alpha,
78
+ toFixedNumber(this.alpha, 2),
79
79
  )
80
80
  }
81
81
 
@@ -92,7 +92,12 @@ export class HSBColor extends Color {
92
92
  let fn = (n: number, k = (n + hue / 60) % 6) =>
93
93
  brightness - saturation * brightness * Math.max(Math.min(k, 4 - k, 1), 0)
94
94
 
95
- return new RGBColor(Math.round(fn(5) * 255), Math.round(fn(3) * 255), Math.round(fn(1) * 255), this.alpha)
95
+ return new RGBColor(
96
+ Math.round(fn(5) * 255),
97
+ Math.round(fn(3) * 255),
98
+ Math.round(fn(1) * 255),
99
+ toFixedNumber(this.alpha, 2),
100
+ )
96
101
  }
97
102
 
98
103
  clone(): ColorType {
@@ -113,13 +118,17 @@ export class HSBColor extends Color {
113
118
  }
114
119
  }
115
120
 
116
- getColorFormat(): ColorFormat {
121
+ toJSON(): Record<string, number> {
122
+ return { h: this.hue, s: this.saturation, b: this.brightness }
123
+ }
124
+
125
+ getFormat(): ColorFormat {
117
126
  return "hsb"
118
127
  }
119
128
 
120
129
  private static colorChannels: [ColorChannel, ColorChannel, ColorChannel] = ["hue", "saturation", "brightness"]
121
130
 
122
- getColorChannels(): [ColorChannel, ColorChannel, ColorChannel] {
131
+ getChannels(): [ColorChannel, ColorChannel, ColorChannel] {
123
132
  return HSBColor.colorChannels
124
133
  }
125
134
  }
package/src/hsl-color.ts CHANGED
@@ -1,8 +1,8 @@
1
+ import { clampValue, mod, toFixedNumber } from "@zag-js/numeric-range"
1
2
  import { Color } from "./color"
2
3
  import { HSBColor } from "./hsb-color"
3
4
  import { RGBColor } from "./rgb-color"
4
5
  import type { ColorChannel, ColorChannelRange, ColorFormat, ColorType } from "./types"
5
- import { clampValue, mod, toFixedNumber } from "./utils"
6
6
 
7
7
  export const HSL_REGEX =
8
8
  /hsl\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%)\)|hsla\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d(.\d+)?)\)/
@@ -72,7 +72,7 @@ export class HSLColor extends Color {
72
72
  toFixedNumber(this.hue, 2),
73
73
  toFixedNumber(saturation * 100, 2),
74
74
  toFixedNumber(brightness * 100, 2),
75
- this.alpha,
75
+ toFixedNumber(this.alpha, 2),
76
76
  )
77
77
  }
78
78
 
@@ -87,7 +87,12 @@ export class HSLColor extends Color {
87
87
  let lightness = this.lightness / 100
88
88
  let a = saturation * Math.min(lightness, 1 - lightness)
89
89
  let fn = (n: number, k = (n + hue / 30) % 12) => lightness - a * Math.max(Math.min(k - 3, 9 - k, 1), -1)
90
- return new RGBColor(Math.round(fn(0) * 255), Math.round(fn(8) * 255), Math.round(fn(4) * 255), this.alpha)
90
+ return new RGBColor(
91
+ Math.round(fn(0) * 255),
92
+ Math.round(fn(8) * 255),
93
+ Math.round(fn(4) * 255),
94
+ toFixedNumber(this.alpha, 2),
95
+ )
91
96
  }
92
97
 
93
98
  clone(): ColorType {
@@ -108,13 +113,17 @@ export class HSLColor extends Color {
108
113
  }
109
114
  }
110
115
 
111
- getColorFormat(): ColorFormat {
116
+ toJSON(): Record<string, number> {
117
+ return { h: this.hue, s: this.saturation, l: this.lightness }
118
+ }
119
+
120
+ getFormat(): ColorFormat {
112
121
  return "hsl"
113
122
  }
114
123
 
115
124
  private static colorChannels: [ColorChannel, ColorChannel, ColorChannel] = ["hue", "saturation", "lightness"]
116
125
 
117
- getColorChannels(): [ColorChannel, ColorChannel, ColorChannel] {
126
+ getChannels(): [ColorChannel, ColorChannel, ColorChannel] {
118
127
  return HSLColor.colorChannels
119
128
  }
120
129
  }
package/src/rgb-color.ts CHANGED
@@ -1,8 +1,8 @@
1
+ import { clampValue, toFixedNumber } from "@zag-js/numeric-range"
1
2
  import { Color } from "./color"
2
3
  import { HSBColor } from "./hsb-color"
3
4
  import { HSLColor } from "./hsl-color"
4
5
  import type { ColorChannel, ColorChannelRange, ColorFormat, ColorType } from "./types"
5
- import { clampValue, toFixedNumber } from "./utils"
6
6
 
7
7
  export class RGBColor extends Color {
8
8
  constructor(
@@ -130,7 +130,7 @@ export class RGBColor extends Color {
130
130
  toFixedNumber(hue * 360, 2),
131
131
  toFixedNumber(saturation * 100, 2),
132
132
  toFixedNumber(brightness * 100, 2),
133
- this.alpha,
133
+ toFixedNumber(this.alpha, 2),
134
134
  )
135
135
  }
136
136
 
@@ -175,7 +175,7 @@ export class RGBColor extends Color {
175
175
  toFixedNumber(hue * 360, 2),
176
176
  toFixedNumber(saturation * 100, 2),
177
177
  toFixedNumber(lightness * 100, 2),
178
- this.alpha,
178
+ toFixedNumber(this.alpha, 2),
179
179
  )
180
180
  }
181
181
 
@@ -196,13 +196,17 @@ export class RGBColor extends Color {
196
196
  }
197
197
  }
198
198
 
199
- getColorFormat(): ColorFormat {
199
+ toJSON(): Record<string, number> {
200
+ return { r: this.red, g: this.green, b: this.blue }
201
+ }
202
+
203
+ getFormat(): ColorFormat {
200
204
  return "rgb"
201
205
  }
202
206
 
203
207
  private static colorChannels: [ColorChannel, ColorChannel, ColorChannel] = ["red", "green", "blue"]
204
208
 
205
- getColorChannels(): [ColorChannel, ColorChannel, ColorChannel] {
209
+ getChannels(): [ColorChannel, ColorChannel, ColorChannel] {
206
210
  return RGBColor.colorChannels
207
211
  }
208
212
  }
package/src/types.ts CHANGED
@@ -2,7 +2,14 @@ export type ColorFormat = "hex" | "hexa" | "rgb" | "rgba" | "hsl" | "hsla" | "hs
2
2
 
3
3
  export type ColorChannel = "hue" | "saturation" | "brightness" | "lightness" | "red" | "green" | "blue" | "alpha"
4
4
 
5
- export type ColorAxes = { xChannel: ColorChannel; yChannel: ColorChannel; zChannel: ColorChannel }
5
+ export interface Color2DAxes {
6
+ xChannel: ColorChannel
7
+ yChannel: ColorChannel
8
+ }
9
+
10
+ export interface ColorAxes extends Color2DAxes {
11
+ zChannel: ColorChannel
12
+ }
6
13
 
7
14
  export interface ColorChannelRange {
8
15
  /** The minimum value of the color channel. */
@@ -18,6 +25,8 @@ export interface ColorChannelRange {
18
25
  export interface ColorType {
19
26
  /** Converts the color to the given color format, and returns a new Color object. */
20
27
  toFormat(format: ColorFormat): ColorType
28
+ /** Converts the color to a JSON object. */
29
+ toJSON(): Record<string, number>
21
30
  /** Converts the color to a string in the given format. */
22
31
  toString(format: ColorFormat | "css"): string
23
32
  /** Converts the color to hex, and returns an integer representation. */
@@ -39,15 +48,15 @@ export interface ColorType {
39
48
  /**
40
49
  * Returns the color space, 'rgb', 'hsb' or 'hsl', for the current color.
41
50
  */
42
- getColorFormat(): ColorFormat
51
+ getFormat(): ColorFormat
43
52
  /**
44
53
  * Returns the color space axes, xChannel, yChannel, zChannel.
45
54
  */
46
- getColorSpaceAxes(xyChannels: { xChannel?: ColorChannel; yChannel?: ColorChannel }): ColorAxes
55
+ getColorAxes(xyChannels: Color2DAxes): ColorAxes
47
56
  /**
48
57
  * Returns an array of the color channels within the current color space space.
49
58
  */
50
- getColorChannels(): [ColorChannel, ColorChannel, ColorChannel]
59
+ getChannels(): [ColorChannel, ColorChannel, ColorChannel]
51
60
  /**
52
61
  * Returns a new Color object with the same values as the current color.
53
62
  */
@@ -56,4 +65,20 @@ export interface ColorType {
56
65
  * Whether the color is equal to another color.
57
66
  */
58
67
  isEqual(color: ColorType): boolean
68
+ /**
69
+ * Increments the color channel by the given step size, and returns a new Color object.
70
+ */
71
+ incrementChannel(channel: ColorChannel, stepSize: number): ColorType
72
+ /**
73
+ * Decrements the color channel by the given step size, and returns a new Color object.
74
+ */
75
+ decrementChannel(channel: ColorChannel, stepSize: number): ColorType
76
+ /**
77
+ * Returns the color channel value as a percentage of the channel range.
78
+ */
79
+ getChannelValuePercent(channel: ColorChannel, value?: number): number
80
+ /**
81
+ * Returns the color channel value for a given percentage of the channel range.
82
+ */
83
+ getChannelPercentValue(channel: ColorChannel, percent: number): number
59
84
  }
package/src/utils.ts DELETED
@@ -1,11 +0,0 @@
1
- export function mod(n: number, m: number) {
2
- return ((n % m) + m) % m
3
- }
4
-
5
- export function toFixedNumber(num: number, digits: number) {
6
- return Math.round(Math.pow(10, digits) * num) / Math.pow(10, digits)
7
- }
8
-
9
- export function clampValue(value: number, min: number, max: number) {
10
- return Math.min(Math.max(value, min), max)
11
- }