drwpow / better-color-tools

Better color tools for JS, TS, and Sass. Supports Oklab and CSS Color Module 4.
https://better-color-tools.pages.dev/
MIT License
78 stars 7 forks source link

contrast algorithm: APCA #35

Closed rsek closed 1 year ago

rsek commented 1 year ago

Long term, APCA should probably replace WCAG2 contrast calculation entirely. But with WCAG3 still being a draft (and WCAG2 being enshrined in law in many places), it might be more practical to provide them both for a time.

drwpow commented 1 year ago

This is a great idea. It does look like there’s some optional font size/weight components to APCA like WCAG3 has, which I’m torn on because while it is absolutely the right approach, measuring accurate font rendering is beyond the means of what CSS/JS can do (referring to actual pixel rendering that differ across browser + OS beyond mere font properties). I’d love to add APCA support (as well as WCAG3) support if the utility without font properties would be of use. The color contrast algorithm is a vast improvement over WCAG2.

rsek commented 1 year ago

FWIW, Myndex appears to have an implementation that brings font size into the mix, but I haven't taken the time to examine the source code (or its methodology) closely. But even if it's a (scientifically-informed) "best guess", I think getting people within spitting distance of the standard (while making them aware of significant caveats, to avoid a footgun situation) has utility.

Otherwise -- I think a sparse color contrast function would be useful as a dependency for a more complete solution... but I'm also biased, as it would take care of the use cases I have it in mind for :wink:

Whatever approach is taken, I think it'd be good for any documentation to make it clear that "hey, you need to take other factors into account too, so here's a WCAG link for more details". Preferably with a TSDoc annotation, as that makes it more discoverable when dealing with it in an IDE.

drwpow commented 1 year ago

I looked into this a bit more, and there is the apca-w3 package which is on npm. But the license seems to only extend to the W3C, and it doesn’t seem like the code available is able to be used by anyone? So I think the only way to use this legally is via the website you linked (and not even through npm—that seems to only be for the purposes of the W3C).

It seems like APCA is an attempt to get passed as a standard, at which point I assume it will be permissible for public use. Until then, looks like it’s not implementable :/

drwpow commented 1 year ago

That said, I’ll take a look at where the WCAG 3 contrast guidelines are, and see if there’s some useful tool that can implement some or all of that standard. I imagine that will see more and more traction over the coming years.

rsek commented 1 year ago

@drwpow hmm. https://github.com/Myndex/SAPC-APCA/discussions/51 includes a list of 3rd party tools that implement the algorithm. since that's a post by the maintainer, i'd take to mean that 3rd party tools are kosher, or at least permissable on a case-by-case basis.

might be worth opening a discussion thread on that repo, or see if someone else has asked a similar question about licensing. my gut feeling here is that it's just a case of a developer being overly cautious with their license text; a WCAG proposal seems like it'd get more traction if people are widely using/testing the implementation, and forbidding other people from using it would get in the way of that. :)

drwpow commented 1 year ago

Licensing in OSS has to be pretty cut-and-dry “free for use and reuse” because every OSS package is only as permissible as its strictest license. As someone that’s worked in security-focused companies that do auditing, licensing does matter for literally every line of code used. A great story on this is You May Finally Use JSHint for Evil, a tale of how ambiguous licensing can come back to bite you, even if it’s well-intentioned and permitted in a case-by-case basis.

my gut feeling here is that it's just a case of a developer being overly cautious with their license text … and forbidding other people from using it would get in the way of that.

Yeah I’d agree with that, too. I’m a huge fan of his work, and he has given so many things that do have open licensing, and I hope this does become a standard so we all get a better web! But again, for this project, for now, I’d only include code and algorithms that have clear licensing so it doesn’t impede others from using this library however they want to.