What is the issue with the HTML Standard?
When colors (i.e. fillStyle, strokeStyle and shadowColor) are set on a canvas the spec says:
"If the value of other properties on the element a is on is required to do the resolution (such as resolving a currentcolor or system color), use element if it was passed, or the initial values of the properties if not."
This implies font-relative lengths (e.g. em) should be relative to the font of the element (or the initial font in the case of OffscreenCanvas) but this differs from how they are handled on other values (e.g. letterSpacing) which resolve them relative to the canvas' font (this is unspecified and in discussion in #10893 but consistent across browsers).
It also doesn't specify how values dependent on context other than the properties of the context element, such as root-font/viewport relative lengths (e.g. rem or vw) or light-dark(), should be resolved.
Existing implementations aren't consistent in how they handle these values:
| Value |
Chromium |
Gecko |
WebKit |
rgb(calc(7px / 1px) 1 0) |
accepted |
rejected |
accepted |
rgb(calc(1em / 1px) 1 0) |
resolves as though em was 0px |
rejected |
rejected |
rgb(calc(1rem / 1px) 1 0) |
resolves as though rem was 0px |
rejected |
rejected |
rgb(calc(1vw / 1px) 1 0) |
resolves as though vw was 0px |
rejected |
rejected |
currentColor |
resolves to #000000 |
resolves to element color (black for OffscreenCanvas) |
resolves to #000000 |
light-dark(red, green) |
rejected |
always resolves to light option for <canvas>, rejected for OffscreenCanvas |
rejected |
What is the issue with the HTML Standard?
When colors (i.e.
fillStyle,strokeStyleandshadowColor) are set on a canvas the spec says:This implies font-relative lengths (e.g.
em) should be relative to thefontof the element (or the initial font in the case of OffscreenCanvas) but this differs from how they are handled on other values (e.g.letterSpacing) which resolve them relative to the canvas' font (this is unspecified and in discussion in #10893 but consistent across browsers).It also doesn't specify how values dependent on context other than the properties of the context element, such as root-font/viewport relative lengths (e.g.
remorvw) orlight-dark(), should be resolved.Existing implementations aren't consistent in how they handle these values:
rgb(calc(7px / 1px) 1 0)rgb(calc(1em / 1px) 1 0)emwas0pxrgb(calc(1rem / 1px) 1 0)remwas0pxrgb(calc(1vw / 1px) 1 0)vwwas0pxcurrentColorlight-dark(red, green)<canvas>, rejected for OffscreenCanvas