Skip to content

Commit

Permalink
update: naming
Browse files Browse the repository at this point in the history
  • Loading branch information
saashapina committed Jun 6, 2024
1 parent ed4ce4b commit c9df3f5
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions libs/features/spectrum2-styles/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const transformRgbProperties = (rule) => {
Object.keys(properties).forEach((prop) => rule.append({ prop, value: properties[prop] }));
};

const extractAndTransformCustomProperties = (css, prefix) => {
const extractAndTransform = (css, prefix) => {
const customProperties = {};
postcss.parse(css).walkRules((rule) => {
const { selector } = rule;
Expand All @@ -62,21 +62,21 @@ const extractAndTransformCustomProperties = (css, prefix) => {
return customProperties;
};

const spectrumCustomProperties = extractAndTransformCustomProperties(spectrumCSS, '--spectrum');
const miloCustomProperties = extractAndTransformCustomProperties(miloCSS, '--s2');
const spectrumProperties = extractAndTransform(spectrumCSS, '--spectrum');
const miloProperties = extractAndTransform(miloCSS, '--s2');

const updateCustomPropertiesInMiloCSS = (css) => {
const updateMiloCSS = (css) => {
const root = postcss.parse(css);

root.walkRules((rule) => {
const { selector } = rule;
if (miloCustomProperties[selector]) {
if (miloProperties[selector]) {
rule.walkDecls((decl) => {
const { prop } = decl;
if (prop.startsWith('--s2')) {
const spectrumProp = `--spectrum${prop.slice(4)}`;
if (spectrumCustomProperties[selector][spectrumProp] !== undefined) {
decl.value = spectrumCustomProperties[selector][spectrumProp];
if (spectrumProperties[selector][spectrumProp] !== undefined) {
decl.value = spectrumProperties[selector][spectrumProp];
}
}
});
Expand All @@ -86,9 +86,9 @@ const updateCustomPropertiesInMiloCSS = (css) => {
return root.toString();
};

const updatedCustomCSS = updateCustomPropertiesInMiloCSS(miloCSS);
const updatedMiloCSS = updateMiloCSS(miloCSS);

fs.writeFileSync(miloCSSPath, updatedCustomCSS, 'utf8');
fs.writeFileSync(miloCSSPath, updatedMiloCSS, 'utf8');
console.log(`Updated custom properties written to ${miloCSSPath}`);

logFileSize(miloCSSPath, 'updated');

0 comments on commit c9df3f5

Please sign in to comment.