UNPKG

colorjs.io

Version:

Color space agnostic color manipulation library

21 lines (16 loc) 527 B
RefTest.hooks.add("reftest-testrow", function (env) { let table = this.table; if (!table.dataset.colors) { return; } let colorCols = new Set(table.dataset.colors.split(/\s*,\s*/).map(i => i - 1)); for (let i = 0; i < env.cells.length; i++) { if (!colorCols.has(i)) { continue; } let cell = env.cells[i]; let color = new Color(cell.textContent); cell.style.setProperty("--color", color.toString({fallback: true})); cell.classList.add(color.luminance > .5 || color.alpha < .5? "light" : "dark"); } });