postcss-preset-mantine
Advanced tools
Comparing version 1.0.7 to 1.0.8
{ | ||
"name": "postcss-preset-mantine", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "PostCSS preset for Mantine (7.0+) applications", | ||
@@ -5,0 +5,0 @@ "main": "preset.js", |
const postcss = require('postcss'); | ||
const re = /light-dark\(([^,]+),([^)]+)\)/; | ||
const FUNCTION = 'light-dark('; | ||
function getValue(index) { | ||
function extractValue(input) { | ||
const match = input.match(re); | ||
function splitStringAtCharacter(character, search) { | ||
let characterIndex = 0; | ||
let openedParentheses = 0; | ||
if (match) { | ||
const value = match[index]; | ||
const replaced = input.replace(re, value.trim()); | ||
return extractValue(replaced); | ||
while ( | ||
characterIndex < search.length && | ||
(search[characterIndex] !== character || openedParentheses) | ||
) { | ||
if (search[characterIndex] === '(') { | ||
openedParentheses += 1; | ||
} | ||
if (search[characterIndex] === ')') { | ||
openedParentheses -= 1; | ||
} | ||
characterIndex += 1; | ||
} | ||
return input; | ||
return [search.slice(0, characterIndex), search.slice(characterIndex + 1)]; | ||
} | ||
function getLightDarkValue(value) { | ||
const [prefix, ...search] = value.split(FUNCTION); | ||
if (!search.length) { | ||
return { light: value, dark: value }; | ||
} | ||
return extractValue; | ||
const [macro, suffix] = splitStringAtCharacter(')', search.join(FUNCTION)); | ||
const [light, dark] = splitStringAtCharacter(',', macro); | ||
const parsedSuffix = getLightDarkValue(suffix); | ||
return { | ||
light: prefix + getLightDarkValue(light.trim()).light + parsedSuffix.light, | ||
dark: prefix + getLightDarkValue(dark.trim()).dark + parsedSuffix.dark, | ||
}; | ||
} | ||
const getLightValue = getValue(1); | ||
const getDarkValue = getValue(2); | ||
module.exports = () => { | ||
@@ -33,4 +51,3 @@ return { | ||
if (value.includes('light-dark')) { | ||
const lightVal = getLightValue(value); | ||
const darkVal = getDarkValue(value); | ||
const { light: lightVal, dark: darkVal } = getLightDarkValue(value); | ||
@@ -37,0 +54,0 @@ const lightRule = postcss.rule({ |
@@ -7,3 +7,3 @@ const postcss = require('postcss'); | ||
( | ||
await postcss([preset]).process('a { border: 1rem solid light-dark(red, blue) }', { | ||
await postcss([preset]).process('a { border: 1rem solid light-dark(red, var(--blue)); }', { | ||
from: undefined, | ||
@@ -10,0 +10,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7168
182