@tbela99/css-parser 1.3.4 → 1.4.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.
- package/CHANGELOG.md +37 -0
- package/README.md +44 -31
- package/dist/config.json.js +3 -0
- package/dist/index-umd-web.js +1247 -72
- package/dist/index.cjs +1258 -72
- package/dist/index.d.ts +282 -17
- package/dist/lib/ast/features/type.js +1 -1
- package/dist/lib/ast/minify.js +1 -1
- package/dist/lib/ast/types.js +62 -3
- package/dist/lib/ast/walk.js +16 -9
- package/dist/lib/fs/resolve.js +63 -7
- package/dist/lib/parser/declaration/list.js +4 -1
- package/dist/lib/parser/parse.js +830 -13
- package/dist/lib/parser/tokenize.js +22 -7
- package/dist/lib/parser/utils/declaration.js +54 -0
- package/dist/lib/parser/utils/hash.js +86 -0
- package/dist/lib/parser/utils/text.js +8 -0
- package/dist/lib/renderer/render.js +25 -6
- package/dist/lib/syntax/color/relativecolor.js +0 -3
- package/dist/lib/validation/config.json.js +15 -3
- package/dist/lib/validation/syntax.js +6 -1
- package/dist/lib/validation/syntaxes/compound-selector.js +1 -2
- package/dist/lib/validation/syntaxes/relative-selector-list.js +2 -5
- package/dist/node.js +48 -11
- package/dist/types.d.ts +17 -0
- package/dist/types.js +20 -0
- package/dist/web.js +35 -9
- package/package.json +16 -16
package/dist/lib/fs/resolve.js
CHANGED
|
@@ -10,6 +10,9 @@ function dirname(path) {
|
|
|
10
10
|
//
|
|
11
11
|
// return path;
|
|
12
12
|
// }
|
|
13
|
+
if (path === '') {
|
|
14
|
+
return '';
|
|
15
|
+
}
|
|
13
16
|
let i = 0;
|
|
14
17
|
let parts = [''];
|
|
15
18
|
for (; i < path.length; i++) {
|
|
@@ -34,6 +37,12 @@ function dirname(path) {
|
|
|
34
37
|
* @private
|
|
35
38
|
*/
|
|
36
39
|
function splitPath(result) {
|
|
40
|
+
if (result.length == 0) {
|
|
41
|
+
return { parts: [], i: 0 };
|
|
42
|
+
}
|
|
43
|
+
if (result === '/') {
|
|
44
|
+
return { parts: ['/'], i: 0 };
|
|
45
|
+
}
|
|
37
46
|
const parts = [''];
|
|
38
47
|
let i = 0;
|
|
39
48
|
for (; i < result.length; i++) {
|
|
@@ -77,6 +86,21 @@ function resolve(url, currentDirectory, cwd) {
|
|
|
77
86
|
}
|
|
78
87
|
cwd ??= '';
|
|
79
88
|
currentDirectory ??= '';
|
|
89
|
+
if (currentDirectory !== '' && url.startsWith(currentDirectory + '/')) {
|
|
90
|
+
return {
|
|
91
|
+
absolute: url,
|
|
92
|
+
relative: url.slice(currentDirectory.length + 1)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (currentDirectory === '' && cwd !== '' && url.startsWith(cwd == '/' ? cwd : cwd + '/')) {
|
|
96
|
+
cwd = normalize(cwd);
|
|
97
|
+
const absolute = normalize(url);
|
|
98
|
+
const prefix = cwd == '/' ? cwd : cwd + '/';
|
|
99
|
+
return {
|
|
100
|
+
absolute,
|
|
101
|
+
relative: absolute.startsWith(prefix) ? absolute.slice(prefix.length) : diff(absolute, cwd)
|
|
102
|
+
};
|
|
103
|
+
}
|
|
80
104
|
if (matchUrl.test(currentDirectory)) {
|
|
81
105
|
const path = new URL(url, currentDirectory).href;
|
|
82
106
|
return {
|
|
@@ -91,9 +115,15 @@ function resolve(url, currentDirectory, cwd) {
|
|
|
91
115
|
else if (currentDirectory.charAt(0) == '/') {
|
|
92
116
|
result = dirname(currentDirectory) + '/' + url;
|
|
93
117
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
118
|
+
const absolute = normalize(result);
|
|
119
|
+
return {
|
|
120
|
+
absolute,
|
|
121
|
+
relative: absolute === '' ? '' : diff(absolute, cwd ?? currentDirectory),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function diff(path1, path2) {
|
|
125
|
+
let { parts } = splitPath(path1);
|
|
126
|
+
const { parts: dirs } = splitPath(path2);
|
|
97
127
|
for (const p of dirs) {
|
|
98
128
|
if (parts[0] == p) {
|
|
99
129
|
parts.shift();
|
|
@@ -102,10 +132,36 @@ function resolve(url, currentDirectory, cwd) {
|
|
|
102
132
|
parts.unshift('..');
|
|
103
133
|
}
|
|
104
134
|
}
|
|
105
|
-
return
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
135
|
+
return parts.join('/');
|
|
136
|
+
}
|
|
137
|
+
function normalize(path) {
|
|
138
|
+
let parts = [];
|
|
139
|
+
let i = 0;
|
|
140
|
+
for (; i < path.length; i++) {
|
|
141
|
+
const chr = path.charAt(i);
|
|
142
|
+
if (chr == '/') {
|
|
143
|
+
if (parts.length == 0 || parts[parts.length - 1] !== '') {
|
|
144
|
+
parts.push('');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else if (chr == '?' || chr == '#') {
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
parts[parts.length - 1] += chr;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
let k = -1;
|
|
155
|
+
while (++k < parts.length) {
|
|
156
|
+
if (parts[k] == '.') {
|
|
157
|
+
parts.splice(k--, 1);
|
|
158
|
+
}
|
|
159
|
+
else if (parts[k] == '..') {
|
|
160
|
+
parts.splice(k - 1, 2);
|
|
161
|
+
k -= 2;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return (path.charAt(0) == '/' ? '/' : '') + parts.join('/');
|
|
109
165
|
}
|
|
110
166
|
|
|
111
167
|
export { dirname, matchUrl, resolve };
|
|
@@ -25,9 +25,12 @@ class PropertyList {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
add(...declarations) {
|
|
28
|
+
let name;
|
|
28
29
|
for (const declaration of declarations) {
|
|
30
|
+
name = declaration.typ != EnumToken.DeclarationNodeType ? null : declaration.nam.toLowerCase();
|
|
29
31
|
if (declaration.typ != EnumToken.DeclarationNodeType ||
|
|
30
|
-
|
|
32
|
+
'composes' === name ||
|
|
33
|
+
(typeof this.options.removeDuplicateDeclarations === 'string' && this.options.removeDuplicateDeclarations === name) ||
|
|
31
34
|
(Array.isArray(this.options.removeDuplicateDeclarations) ? this.options.removeDuplicateDeclarations.includes(declaration.nam) : !this.options.removeDuplicateDeclarations)) {
|
|
32
35
|
this.declarations.set(Number(Math.random().toString().slice(2)).toString(36), declaration);
|
|
33
36
|
continue;
|