css4j v3.4.0
Support for lab()
and lch()
color functions
The lab()
and lch()
functions are finally landing in Webkit, and the other major browsers have shown interest in implementing them (although it may still take some time).
The usage of these functions in a toolchain with the typical Java open source tools (which tend to use the sRGB default color space) could be problematic, as lab()
and lch()
are often specified out of that gamut, but an accurate RGB clamping method is provided.
Customizable serialization of computed styles
Now you can control the serialization of computed styles thanks to a new factory method: StyleFormattingFactory.createComputedStyleFormattingContext()
, which returns a DeclarationFormattingContext
.
A non-default implementation of that interface, called RGBStyleFormattingFactory
, is provided for the convenience of users that can only deal with RGB colors in computed styles (for example those feeding CSS4J computed styles into Apache FOP). Basically, it allows to use modern CSS with Lab, LCh or Hsl colors and then convert them to RGB at the computed-style stage.
CSSOM: make the old rgb(a) color functional serialization with commas the default for color conversions to RGB
When parsing, the library uses the same RGB format that was specified. That is, if the input was a rgba()
function with commas, it serialized that way. However, when other types of colors were converted to RGB, it defaulted to the modern format without the commas. That default was not the most adequate though:
-
According to the 2020 Web Almanac, "99.89% of functionally specified sRGB colors are using the since-forever legacy format with commas [...] rather than the new comma-less form".
-
XSL:FO uses the old format with commas, see https://www.w3.org/TR/xsl/#expr-color-functions
So the default format for values converted to RGB now has commas.
Added method match(CSSValueSyntax)
to both LexicalUnit
and CSSValue
This allows checking the grammar of values against specific syntaxes like <length>+
, <string>#
, <transform-function>
or <unicode-range>#
.
Support registered custom properties (including @property
rules) from CSS Properties and Values API Level 1
The rule (that currently only works in Chrome/Blink) allows to customize the behaviour of custom properties. The direct setting of property syntax through DOM is also supported.
DOM: add the DOMNode.removeAllChild()
convenience method
AFAIK no other DOM implementation contains this useful method.