Automattic / Automattic/node-canvas
RGB functions do not support real numbers
- Dominant language
- JavaScript
- Stars
- 10.7k
- Forks
- 1.2k
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 1
Description
## Issue
RGB colors that contain a real number are not supported, while in browsers this works.
The [official spec](https://drafts.csswg.org/css-color/#rgb-functions) defines real numbers as a valid argument for the modern spec and browsers have [supported](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/rgb#browser_compatibility) this for several years so it would be nice to have consistency.
## Steps to Reproduce
```js
const { Canvas } = require('canvas');
const canvas = new Canvas();
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'rgb(127,127.0,255)';
console.log(ctx.fillStyle); // output: #000000
ctx.fillStyle = 'rgb(127,127,255)';
console.log(ctx.fillStyle); // output: #7f7fff
```
I think [this parsing](https://github.com/Automattic/node-canvas/blob/93749430f49f506d4917129ed6cc3d7939b946f1/src/color.cc#L163) may just have to be changed to floats?
## Your Environment
* Version of node-canvas: canvas@2.11.2
* Environment: node v20.2.0 on macOS 14.2.1 (e.g. node 20.9.0 on macOS 14.1.1):
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.