API / Minn\Blocks / Duotone

Duotone final class

Minn\Blocks\Duotone · public/minn/src/Minn/Blocks/Duotone.php · 79 lines

Duotone filters (probe block-supports): a CSS color read into its red, green, blue (0 to 255) and alpha (0 to 1, to two places) channels, and the hidden SVG filter that maps an image's shades onto a list of colors, one table of values per channel.

Uses 1

Constants and properties

privateSVG = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 0 0" width="0" height="0" focusable="false" role="none" style="visibility: hidden; position: absolute; left: -9999px; overflow: hidden;" ><defs><filter id="%s"><feColorMatrix color-interpolation-filters="sRGB" type="matrix" values=" .299 .587 .114 0 0 .299 .587 .114 0 0 .299 .587 .114 0 0 .299 .587 .114 0 0 " /><feComponentTransfer color-interpolation-filters="sRGB" ><feFuncR type="table" tableValues="%s" /><feFuncG type="table" tableValues="%s" /><feFuncB type="table" tableValues="%s" /><feFuncA type="table" tableValues="%s" /></feComponentTransfer><feComposite in2="SourceGraphic" operator="in" /></filter></defs></svg>'

Public

staticsvg(string $filterId, array $colors): string#

The filter for a list of colors; colors that do not parse are left out.

$colorslist<string>
staticparse(string $input): ?array#

A color's channels: hex (3, 4, 6 or 8 digits), rgb()/rgba() and hsl()/hsla().

@return array{r: float, g: float, b: float, a: float}|null

Internals 2

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatealpha(?string $value, string $pct): float#
privatehsl(float $hue, float $saturation, float $lightness): array#
@return array{r: float, g: float, b: float} hue in degrees, saturation and lightness in percent