zcw-shared 1.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import type { DesignToken } from '../../../types/design-system.d';
|
|
2
|
-
export declare function extractCssVariables(text: string, filePath: string
|
|
3
|
-
|
|
2
|
+
export declare function extractCssVariables(text: string, filePath: string, options?: {
|
|
3
|
+
includeCss?: boolean;
|
|
4
|
+
includeScss?: boolean;
|
|
5
|
+
includeLess?: boolean;
|
|
6
|
+
}): DesignToken[];
|
|
7
|
+
export declare function extractCssVariableDefinitions(text: string, options?: {
|
|
8
|
+
includeCss?: boolean;
|
|
9
|
+
includeScss?: boolean;
|
|
10
|
+
includeLess?: boolean;
|
|
11
|
+
}): Array<{
|
|
4
12
|
variableName: string;
|
|
5
13
|
value: string;
|
|
6
14
|
line: number;
|
|
7
15
|
context: string;
|
|
16
|
+
type: 'css' | 'scss' | 'less';
|
|
8
17
|
}>;
|
|
@@ -1,46 +1,121 @@
|
|
|
1
|
-
export function extractCssVariables(text, filePath
|
|
1
|
+
export function extractCssVariables(text, filePath, options = {
|
|
2
|
+
includeCss: true,
|
|
3
|
+
includeScss: true,
|
|
4
|
+
includeLess: true
|
|
5
|
+
}) {
|
|
2
6
|
if (!text || typeof text !== 'string') {
|
|
3
7
|
return [];
|
|
4
8
|
}
|
|
5
9
|
const variables = [];
|
|
6
10
|
const lines = text.split('\n');
|
|
7
|
-
const cssVarPattern = /var\(\s*(--[\w-]+)(?:\s*,\s*([^)]*))?\s*\)/g;
|
|
8
11
|
lines.forEach((line, lineIndex) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
if (options.includeCss !== false) {
|
|
13
|
+
const cssVarPattern = /var\(\s*(--[\w-]+)(?:\s*,\s*([^)]*))?\s*\)/g;
|
|
14
|
+
let match;
|
|
15
|
+
while ((match = cssVarPattern.exec(line)) !== null) {
|
|
16
|
+
const [fullMatch, variableName] = match;
|
|
17
|
+
variables.push({
|
|
18
|
+
name: variableName,
|
|
19
|
+
value: fullMatch,
|
|
20
|
+
type: 'color',
|
|
21
|
+
line: lineIndex + 1,
|
|
22
|
+
file: filePath,
|
|
23
|
+
context: line.trim()
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (options.includeScss !== false) {
|
|
28
|
+
const scssVarPattern = /\$([a-zA-Z_][\w-]*)/g;
|
|
29
|
+
let match;
|
|
30
|
+
while ((match = scssVarPattern.exec(line)) !== null) {
|
|
31
|
+
const [fullMatch, variableName] = match;
|
|
32
|
+
variables.push({
|
|
33
|
+
name: `$${variableName}`,
|
|
34
|
+
value: fullMatch,
|
|
35
|
+
type: 'color',
|
|
36
|
+
line: lineIndex + 1,
|
|
37
|
+
file: filePath,
|
|
38
|
+
context: line.trim()
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (options.includeLess !== false) {
|
|
43
|
+
const lessVarPattern = /@([a-zA-Z_][\w-]*)/g;
|
|
44
|
+
let match;
|
|
45
|
+
while ((match = lessVarPattern.exec(line)) !== null) {
|
|
46
|
+
const [fullMatch, variableName] = match;
|
|
47
|
+
const atRules = ['media', 'import', 'keyframes', 'supports', 'charset', 'namespace', 'page', 'font-face', 'counter-style'];
|
|
48
|
+
if (!atRules.includes(variableName.toLowerCase())) {
|
|
49
|
+
variables.push({
|
|
50
|
+
name: `@${variableName}`,
|
|
51
|
+
value: fullMatch,
|
|
52
|
+
type: 'color',
|
|
53
|
+
line: lineIndex + 1,
|
|
54
|
+
file: filePath,
|
|
55
|
+
context: line.trim()
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
20
59
|
}
|
|
21
|
-
cssVarPattern.lastIndex = 0;
|
|
22
60
|
});
|
|
23
61
|
return variables;
|
|
24
62
|
}
|
|
25
|
-
export function extractCssVariableDefinitions(text
|
|
63
|
+
export function extractCssVariableDefinitions(text, options = {
|
|
64
|
+
includeCss: true,
|
|
65
|
+
includeScss: true,
|
|
66
|
+
includeLess: true
|
|
67
|
+
}) {
|
|
26
68
|
if (!text || typeof text !== 'string') {
|
|
27
69
|
return [];
|
|
28
70
|
}
|
|
29
71
|
const definitions = [];
|
|
30
72
|
const lines = text.split('\n');
|
|
31
|
-
const cssVarDefPattern = /^\s*--((?:[a-zA-Z_\u0080-\uFFFF])(?:[a-zA-Z0-9_\u0080-\uFFFF-])*)\s*:\s*([^;}]+);?/gm;
|
|
32
73
|
lines.forEach((line, lineIndex) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
variableName
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
74
|
+
if (options.includeCss !== false) {
|
|
75
|
+
const cssVarDefPattern = /^\s*--((?:[a-zA-Z_\u0080-\uFFFF])(?:[a-zA-Z0-9_\u0080-\uFFFF-])*)\s*:\s*([^;}]+);?/;
|
|
76
|
+
const match = cssVarDefPattern.exec(line);
|
|
77
|
+
if (match) {
|
|
78
|
+
const [, variableName, value] = match;
|
|
79
|
+
definitions.push({
|
|
80
|
+
variableName: `--${variableName}`,
|
|
81
|
+
value: value.trim(),
|
|
82
|
+
line: lineIndex + 1,
|
|
83
|
+
context: line.trim(),
|
|
84
|
+
type: 'css'
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (options.includeScss !== false) {
|
|
89
|
+
const scssVarDefPattern = /^\s*\$([a-zA-Z_][\w-]*)\s*:\s*([^;]+);?/;
|
|
90
|
+
const match = scssVarDefPattern.exec(line);
|
|
91
|
+
if (match) {
|
|
92
|
+
const [, variableName, value] = match;
|
|
93
|
+
definitions.push({
|
|
94
|
+
variableName: `$${variableName}`,
|
|
95
|
+
value: value.trim(),
|
|
96
|
+
line: lineIndex + 1,
|
|
97
|
+
context: line.trim(),
|
|
98
|
+
type: 'scss'
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (options.includeLess !== false) {
|
|
103
|
+
const lessVarDefPattern = /^\s*@([a-zA-Z_][\w-]*)\s*:\s*([^;]+);?/;
|
|
104
|
+
const match = lessVarDefPattern.exec(line);
|
|
105
|
+
if (match) {
|
|
106
|
+
const [, variableName, value] = match;
|
|
107
|
+
const atRules = ['media', 'import', 'keyframes', 'supports', 'charset', 'namespace', 'page', 'font-face', 'counter-style'];
|
|
108
|
+
if (!atRules.includes(variableName.toLowerCase())) {
|
|
109
|
+
definitions.push({
|
|
110
|
+
variableName: `@${variableName}`,
|
|
111
|
+
value: value.trim(),
|
|
112
|
+
line: lineIndex + 1,
|
|
113
|
+
context: line.trim(),
|
|
114
|
+
type: 'less'
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
42
118
|
}
|
|
43
|
-
cssVarDefPattern.lastIndex = 0;
|
|
44
119
|
});
|
|
45
120
|
return definitions;
|
|
46
121
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractCssVariables.js","sourceRoot":"","sources":["../../../src/functions/css/extractCssVariables.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extractCssVariables.js","sourceRoot":"","sources":["../../../src/functions/css/extractCssVariables.ts"],"names":[],"mappings":"AAiBA,MAAM,UAAU,mBAAmB,CACjC,IAAY,EACZ,QAAgB,EAChB,UAII;IACF,UAAU,EAAE,IAAI;IAChB,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;CAClB;IAED,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtC,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,SAAS,GAAkB,EAAE,CAAA;IACnC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,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