Skip to content

Commit 9048298

Browse files
committed
fix: add oklch() color support for html2canvas compatibility
Tailwind v4 uses oklch() colors by default that causes the html2canvas to throws an error when it encounters oklch() because it does not support that color function. Fix: before passing the container to html2canvas, walk all elements and resolve any oklch() computed style values to rgb using a canvas 2D context (native browser color conversion), then write them back as inline styles
1 parent 4c74600 commit 9048298

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function resolveOklchColors(container) {
2323
var computed = getComputedStyle(el);
2424
colorProps.forEach(function (prop) {
2525
var val = computed.getPropertyValue(prop);
26-
if (val && val.indexOf('oklch') !== -1) {
26+
if (val && val.toLowerCase().indexOf('oklch') !== -1) {
2727
ctx.fillStyle = val;
2828
el.style.setProperty(prop, ctx.fillStyle);
2929
}

0 commit comments

Comments
 (0)