Skip to content

Commit 9bb897c

Browse files
committed
fix: try something (please work)
1 parent f3f322c commit 9bb897c

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

resources/scripts/blueprint/css/BlueprintStylesheet.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import url('./extensions.css');
2+
13
:root {
24
--blueprint-white: 255 255 255;
35
--blueprint-black: 19 26 32;

tailwind.config.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,41 @@
11
const postcss = require('postcss');
22
const fs = require('fs');
3+
const path = require('path');
4+
5+
function extractCssVars(cssFilePath, processedFiles = new Set()) {
6+
// avoid infinite recursion by tracking processed files
7+
const absolutePath = path.resolve(cssFilePath);
8+
if (processedFiles.has(absolutePath)) {
9+
return {};
10+
}
11+
processedFiles.add(absolutePath);
312

4-
function extractCssVars(cssFilePath) {
513
const cssContent = fs.readFileSync(cssFilePath, 'utf8');
614
const root = postcss.parse(cssContent);
7-
const vars = {};
15+
let vars = {};
16+
17+
// process @import rules first
18+
root.walkAtRules('import', (rule) => {
19+
let importPath = rule.params.replace(/['"]/g, ''); // remove quotes
20+
21+
// handle url() syntax
22+
if (importPath.startsWith('url(')) {
23+
importPath = importPath.slice(4, -1).replace(/['"]/g, '');
24+
}
25+
26+
// resolve relative paths
27+
if (!path.isAbsolute(importPath)) {
28+
importPath = path.resolve(path.dirname(cssFilePath), importPath);
29+
}
830

31+
// check if file exists before trying to process it
32+
if (fs.existsSync(importPath)) {
33+
const importedVars = extractCssVars(importPath, processedFiles);
34+
vars = mergeVars(vars, importedVars);
35+
}
36+
});
37+
38+
// process css variables in this file
939
root.walkRules((rule) => {
1040
if (rule.selector === ':root') {
1141
rule.walkDecls((decl) => {
@@ -38,6 +68,18 @@ function extractCssVars(cssFilePath) {
3868
return vars;
3969
}
4070

71+
function mergeVars(target, source) {
72+
for (const [key, value] of Object.entries(source)) {
73+
if (typeof value === 'object' && !Array.isArray(value)) {
74+
if (!target[key]) target[key] = {};
75+
target[key] = { ...target[key], ...value };
76+
} else {
77+
target[key] = value;
78+
}
79+
}
80+
return target;
81+
}
82+
4183
const cssVars = extractCssVars('./resources/scripts/blueprint/css/BlueprintStylesheet.css');
4284

4385
module.exports = {

0 commit comments

Comments
 (0)