Skip to content

Commit

Permalink
fix multiple colors in one declaration case
Browse files Browse the repository at this point in the history
  • Loading branch information
fpetrakov committed Nov 26, 2022
1 parent 70283a3 commit 698c791
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "convert-to-oklch",
"version": "1.1.2",
"version": "1.1.3",
"description": "CLI tool that converts rgb(), rgba(), hex, hsl() and hsla() colors to oklch() in specified CSS files.",
"main": "./src/index.js",
"bin": {
Expand Down
6 changes: 4 additions & 2 deletions src/plugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Color = require("colorjs.io").default;
const colorsRegex = new RegExp(/(^#[0-9a-f]{3,8}$|(hsla?|rgba?)\([^)]+\))/gi);
const colorsRegex = new RegExp(/(#[0-9a-f]{3,8}|(hsla?|rgba?)\([^)]+\))/gi);
const pc = require("picocolors");

module.exports = () => ({
Expand All @@ -11,6 +11,7 @@ module.exports = () => ({
const colorsToConvert = originalColors.filter(
(originalColor) => !originalColor.includes("var(--"),
);
if (!colorsToConvert.length) return;

const convertedAndOriginalColors = colorsToConvert.map(
(originalColor) => {
Expand All @@ -26,10 +27,11 @@ module.exports = () => ({
}
},
);
if (!convertedAndOriginalColors.length) return;

convertedAndOriginalColors.forEach(({ converted, original }) => {
try {
decl.value = decl.value.replace(original, converted);
decl.value = decl.value.replaceAll(original, converted);
} catch (e) {
console.error(
pc.bgRed(
Expand Down

0 comments on commit 698c791

Please sign in to comment.