Skip to content

Commit

Permalink
add color() function to color tool (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
estelle authored Apr 18, 2024
1 parent 4f67fbe commit c0bf2b2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions modules/colors.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
<th>HWB</th>
<td></td>
</tr>
<tr id="colorfunc">
<th>color()</th>
<td></td>
</tr>
</tbody>
</table>

Expand Down Expand Up @@ -144,6 +148,19 @@
cell.textContent = `rgb(${R} ${G} ${B} / ${opacity})`;
}
createHSL(R, G, B, opacity);
createColorFunc(R, G, B, opacity);
}

function createColorFunc(r, g, b, opacity) {
const cell = document.querySelector("#colorfunc td");
const R = Number((r / 255).toFixed(2));
const G = Number((g / 255).toFixed(2));
const B = Number((b / 255).toFixed(2));
if (opacity === 1) {
cell.textContent = `color(srgb ${R} ${G} ${B})`;
} else {
cell.textContent = `color(srgb ${R} ${G} ${B} / ${opacity})`;
}
}

function createHSL(r, g, b, opacity) {
Expand Down

0 comments on commit c0bf2b2

Please sign in to comment.