Skip to content

5.0.0

Latest

Choose a tag to compare

@ozdemirburak ozdemirburak released this 23 Oct 00:45

Iris 5.0.0 fixes the PHP 8.5 deprecations, fixes a set of long-standing bugs, reads modern CSS color syntax, and adds alpha to OKLCH.

It is a major release, please read Breaking changes before you upgrade.

Requirements

  • PHP 8.4 or later. Projects on older PHP versions stay on 4.x.

Highlights

  • No more PHP 8.5 deprecations: Non-canonical cast (double) in Rgba and Hsla is fixed. (#54)
  • CSS Color Level 4 syntax for all color functions:
    Factory::init('rgb(10 20 30 / 50%)');       // Rgba
    Factory::init('hsl(0.5turn 50% 50% / .3)'); // Hsla
    Factory::init('oklch(62.8% 0.2577 29.23 / 0.5)');
    Factory::init('#f0f8');                     // Hexa
    Factory::init('transparent');               // Rgba
  • WCAG contrast: luminance(), contrast($background), isReadable($background) and mostReadable() pick an accessible text color.
  • Color difference: distance($other) (deltaE OK) and equals($other, $tolerance) compare colors in any model.
  • Helpers: toName(), invert(), complement(), json_encode() support, and Factory::tryInit() / Factory::isValid().
  • Alpha for OKLCH: oklch(... / 0.5) keeps the alpha through conversions and operations.
  • Operations keep the alpha: lighten(), spin(), mix(), gradient() and the others no longer drop the alpha of Rgba, Hsla, Hexa and Oklch.
  • Safer API: operations return a new color and never change the original, setters clamp out-of-range values, and the whole library passes PHPStan at the max level.

Breaking changes

  • Minimum PHP version is 8.4. The development dependencies are PHPUnit ^13.4 and PHPStan ^2.3.
  • Manipulations and conversions return a new object; before, some manipulations changed the original object, and toHex() on a Hex (and so on) returned the object itself.
  • Setters clamp out-of-range values (red(300) sets 255) and the hue wraps around 360 (hue(400) sets 40); a value that is not a number is ignored and the setter returns the color. Hex/Hexa setters take hex digits, as before.
  • Blending a color with alpha onto its background rounds each channel instead of rounding down, so some results are 1 higher (rgba(0,0,0,0.3) gives rgb(179,179,179)).
  • mix(), tint(), shade() and gradient() mix the alpha and weight the channels by alpha, like less.js and Sass.
  • fade(), fadeIn() and fadeOut() return Hexa for Hex/Hexa and Oklch for Oklch (before: Rgba).
  • Oklch keeps the alpha of oklch(... / a), so conversions to opaque models blend it onto white; Oklch::values() includes the alpha; a lightness without % that is not greater than 1 is a fraction (oklch(0.7 0.1 120) is 70%).
  • Conversions to HSV and CMYK keep one decimal, e.g. hsv(303.5,96.7%,96.5%); Hsv::value() returns a float.
  • Factory::init() throws InvalidColorException for an empty string and unsupported functions (e.g. hwb()), and reads 4 hex digits only with a #.
  • For subclasses: Hex/Hexa use the new HexTrait, Rgb/Rgba use RgbTrait with int channels, $castsInteger and some protected helpers are removed, BaseColor has new protected methods, and the method signatures have native types.

The README has an Upgrading from 4.x section, and CHANGELOG.md has the full list.

Fixed

  • Rgba setters read integers as hex: red(100) was ignored and red(5) set 55.
  • spin() triggered "Implicit conversion from float to int" deprecations and lost the hue decimals.
  • Factory::init() could not read space-separated oklch(), also not the output of Oklch::__toString().
  • Round trips through HSV changed colors by up to 5 units.
  • fade() on Hsla returned Rgba; gradient() crashed on an empty array and lost colors with few steps.
  • The parser could not read very small values in the form that PHP prints them (1.0E-5), so some operations threw an exception.
  • Malformed strings such as ##fff and hsl(120,1%00,50) were accepted.
  • Color names in Hsl, Hsla, Hsv and Cmyk were up to 2 units wrong (new Hsl('coral') gave #ff8052).
  • spin(0), lighten(0) and other operations with 0 changed Hsv, Cmyk and Oklch colors.

Full changelog: https://github.com/ozdemirburak/iris/blob/5.0.0/CHANGELOG.md