// Name: Replace Colors with Hex
// Description: Finds colors in text (rgb, rgba, hsl, lab, lch, oklab, oklch, color(), hex) and replaces them with closest #RRGGBB.
// Author: ScottGuthart
// GitHub: ScottGuthart
import "@johnlindquist/kit"
import Color from "colorjs.io"
const compositeOnWhite = (srgb: Color) => {
// srgb coords in [0..1]
const a = typeof srgb.alpha === "number" ? srgb.alpha : 1
const c = srgb.to("srgb").toGamut({ space: "srgb" })
const [r, g, b] = c.coords as [number, number, number]
const blend = (v: number) => Math.max(0, Math.min(1, a * v + (1 - a) * 1))
const toHex = (v: number) => {
const i = Math.round(blend(v) * 255)
return i.toString(16).padStart(2, "0")
}
return `#${toHex(r)}${toHex(g)}${toHex(b)}`.toLowerCase()
}